forked from KhronosGroup/glTF-Asset-Generator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNode_Attribute.cs
151 lines (135 loc) · 6.23 KB
/
Node_Attribute.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
namespace AssetGenerator.ModelGroups
{
internal class Node_Attribute : ModelGroup
{
public override ModelGroupId Id => ModelGroupId.Node_Attribute;
public Node_Attribute(List<string> imageList)
{
var baseColorTexture = new Runtime.Texture { Source = UseTexture(imageList, "BaseColor_Nodes") };
var normalTexture = new Runtime.Texture { Source = UseTexture(imageList, "Normal_Nodes") };
var metallicRoughnessTexture = new Runtime.Texture { Source = UseTexture(imageList, "MetallicRoughness_Nodes") };
// Track the common properties for use in the readme.
CommonProperties.Add(new Property(PropertyName.BaseColorTexture, baseColorTexture.Source.ToReadmeString()));
CommonProperties.Add(new Property(PropertyName.NormalTexture, normalTexture.Source.ToReadmeString()));
CommonProperties.Add(new Property(PropertyName.MetallicRoughnessTexture, metallicRoughnessTexture.Source.ToReadmeString()));
Model CreateModel(Action<List<Property>, Runtime.Node> setProperties)
{
var properties = new List<Property>();
List<Runtime.Node> nodes = Nodes.CreateMultiNode();
// Apply the common properties to the gltf.
foreach (var node in nodes)
{
node.Mesh.MeshPrimitives.First().Material = new Runtime.Material
{
NormalTexture = new Runtime.NormalTextureInfo { Texture = normalTexture },
PbrMetallicRoughness = new Runtime.PbrMetallicRoughness
{
BaseColorTexture = new Runtime.TextureInfo { Texture = baseColorTexture },
MetallicRoughnessTexture = new Runtime.TextureInfo { Texture = metallicRoughnessTexture },
},
};
}
// Apply the properties that are specific to this gltf.
setProperties(properties, nodes[1]);
// Create the gltf object.
return new Model
{
Properties = properties,
GLTF = CreateGLTF(() => new Runtime.Scene
{
Nodes = new[]
{
nodes[0]
}
})
};
}
void SetTranslation(List<Property> properties, Runtime.Node node)
{
node.Translation = new Vector3(-2.0f, 2.0f, -2.0f);
properties.Add(new Property(PropertyName.Translation, node.Translation.ToReadmeString()));
}
void SetTranslationX(List<Property> properties, Runtime.Node node)
{
node.Translation = new Vector3(-2.0f, 0.0f, 0.0f);
properties.Add(new Property(PropertyName.Translation, node.Translation.ToReadmeString()));
}
void SetTranslationY(List<Property> properties, Runtime.Node node)
{
node.Translation = new Vector3(0.0f, 2.0f, 0.0f);
properties.Add(new Property(PropertyName.Translation, node.Translation.ToReadmeString()));
}
void SetTranslationZ(List<Property> properties, Runtime.Node node)
{
node.Translation = new Vector3(0.0f, 0.0f, -2.0f);
properties.Add(new Property(PropertyName.Translation, node.Translation.ToReadmeString()));
}
void SetRotation(List<Property> properties, Runtime.Node node)
{
var rotation = new Quaternion(0.0f, 1.0f, 0.0f, 0.0f);
node.Rotation = rotation;
properties.Add(new Property(PropertyName.Rotation, rotation.ToReadmeString()));
}
void SetScale(List<Property> properties, Runtime.Node node)
{
node.Scale = new Vector3(1.2f, 1.2f, 1.2f);
properties.Add(new Property(PropertyName.Scale, node.Scale.ToReadmeString()));
}
void SetMatrix(List<Property> properties, Runtime.Node node)
{
Matrix4x4 matrixT = Matrix4x4.CreateTranslation(new Vector3(-2.0f, 2.0f, -2.0f));
Matrix4x4 matrixR = Matrix4x4.CreateRotationY(FloatMath.Pi);
Matrix4x4 matrixS = Matrix4x4.CreateScale(1.2f);
Matrix4x4 matrixTRS = Matrix4x4.Multiply(Matrix4x4.Multiply(matrixS, matrixR), matrixT);
node.Matrix = matrixTRS;
properties.Add(new Property(PropertyName.Matrix, matrixTRS.ToReadmeString()));
}
Models = new List<Model>
{
CreateModel((properties, node) =>
{
// There are no properties set on this model.
}),
CreateModel((properties, node) =>
{
SetTranslation(properties, node);
}),
CreateModel((properties, node) =>
{
SetTranslationX(properties, node);
}),
CreateModel((properties, node) =>
{
SetTranslationY(properties, node);
}),
CreateModel((properties, node) =>
{
SetTranslationZ(properties, node);
}),
CreateModel((properties, node) =>
{
SetRotation(properties, node);
}),
CreateModel((properties, node) =>
{
SetScale(properties, node);
}),
CreateModel((properties, node) =>
{
SetTranslation(properties, node);
SetRotation(properties, node);
SetScale(properties, node);
}),
CreateModel((properties, node) =>
{
SetMatrix(properties, node);
}),
};
GenerateUsedPropertiesList();
}
}
}