forked from KhronosGroup/glTF-Asset-Generator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBuffer_Misc.cs
107 lines (95 loc) · 3.35 KB
/
Buffer_Misc.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
using System;
using System.Numerics;
using AssetGenerator.Runtime;
using System.Collections.Generic;
namespace AssetGenerator.ModelGroups
{
internal class Buffer_Misc : ModelGroup
{
public override ModelGroupId Id => ModelGroupId.Buffer_Misc;
public Buffer_Misc(List<string> imageList)
{
Model CreateModel(Action<List<Property>, AnimationChannel, Node> setProperties)
{
var properties = new List<Property>();
// Apply the common properties to the glTF.
var node = new Node
{
Mesh = new Runtime.Mesh
{
MeshPrimitives = new[]
{
MeshPrimitive.CreateSinglePlane(includeTextureCoords: false)
}
},
Scale = new Vector3(0.8f)
};
var channel = new AnimationChannel();
// Apply the proerties that are specific to this glTF
setProperties(properties, channel, node);
// Create the glTF object
GLTF gltf = CreateGLTF(() => new Scene
{
Nodes = new[]
{
node
},
});
gltf.Animations = new[]
{
new Animation
{
Channels = new List<AnimationChannel>
{
channel
}
}
};
return new Model
{
Properties = properties,
GLTF = gltf,
Animated = true,
SeparateBuffers = true,
};
}
void setTranslationChanneltarget(AnimationChannel channel, Node node)
{
channel.Target = new AnimationChannelTarget
{
Node = node,
Path = AnimationChannelTargetPath.Translation,
};
}
void SetLinearSamplerForTranslation(AnimationChannel channel)
{
channel.Sampler = new AnimationSampler
{
Interpolation = AnimationSamplerInterpolation.Linear,
Input = Data.Create(new[]
{
0.0f,
2.0f,
4.0f,
}),
Output = Data.Create(new[]
{
new Vector3(-0.1f, 0.0f, 0.0f),
new Vector3(0.1f, 0.0f, 0.0f),
new Vector3(-0.1f, 0.0f, 0.0f),
}),
};
}
Models = new List<Model>
{
CreateModel((properties, channel, node) =>
{
setTranslationChanneltarget(channel, node);
SetLinearSamplerForTranslation(channel);
properties.Add(new Property(PropertyName.Description, "The mesh primitive and animation data are stored in separate buffers."));
})
};
GenerateUsedPropertiesList();
}
}
}