forked from KhronosGroup/glTF-Asset-Generator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNode_NegativeScale.cs
190 lines (172 loc) · 8.35 KB
/
Node_NegativeScale.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
using AssetGenerator.Runtime;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
namespace AssetGenerator.ModelGroups
{
internal class Node_NegativeScale : ModelGroup
{
public override ModelGroupId Id => ModelGroupId.Node_NegativeScale;
public Node_NegativeScale(List<string> imageList)
{
var baseColorTexture = new Texture { Source = UseTexture(imageList, "BaseColor_Nodes") };
var normalTexture = new Texture { Source = UseTexture(imageList, "Normal_Nodes") };
var metallicRoughnessTexture = new Texture { Source = UseTexture(imageList, "MetallicRoughness_Nodes") };
// Track the common properties for use in the readme.
var translationValue = new Vector3(0, 2, 0);
Matrix4x4 matrixTranslationValue = Matrix4x4.CreateTranslation(translationValue);
CommonProperties.Add(new Property(PropertyName.Translation, translationValue.ToReadmeString()));
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>, Node, Node> setProperties)
{
var properties = new List<Property>();
List<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 NormalTextureInfo { Texture = normalTexture },
PbrMetallicRoughness = new PbrMetallicRoughness
{
BaseColorTexture = new TextureInfo { Texture = baseColorTexture },
MetallicRoughnessTexture = new TextureInfo { Texture = metallicRoughnessTexture },
},
};
}
// Apply the properties that are specific to this gltf.
setProperties(properties, nodes[0], nodes[1]);
// Applies a translation to avoid clipping the other node.
// Models with a matrix applied have the translation applied in that matrix.
if (properties.Find(e => e.Name == PropertyName.Matrix) == null)
{
nodes[1].Translation = translationValue;
}
// Create the gltf object.
return new Model
{
Properties = properties,
GLTF = CreateGLTF(() => new Scene
{
Nodes = new[]
{
nodes[0]
}
})
};
}
void SetMatrixScaleX(List<Property> properties, Node node)
{
node.Matrix = Matrix4x4.Multiply(Matrix4x4.CreateScale(new Vector3(-1.0f, 1.0f, 1.0f)), matrixTranslationValue);
properties.Add(new Property(PropertyName.Matrix, node.Matrix.ToReadmeString()));
}
void SetMatrixScaleXY(List<Property> properties, Node node)
{
node.Matrix = Matrix4x4.Multiply(Matrix4x4.CreateScale(new Vector3(-1.0f, -1.0f, 1.0f)), matrixTranslationValue);
properties.Add(new Property(PropertyName.Matrix, node.Matrix.ToReadmeString()));
}
void SetMatrixScaleXYZ(List<Property> properties, Node node)
{
node.Matrix = Matrix4x4.Multiply(Matrix4x4.CreateScale(new Vector3(-1.0f, -1.0f, -1.0f)), matrixTranslationValue);
properties.Add(new Property(PropertyName.Matrix, node.Matrix.ToReadmeString()));
}
void SetScaleX(List<Property> properties, Node node)
{
node.Scale = new Vector3(-1.0f, 1.0f, 1.0f);
properties.Add(new Property(PropertyName.Scale, node.Scale.ToReadmeString()));
}
void SetScaleXY(List<Property> properties, Node node)
{
node.Scale = new Vector3(-1.0f, -1.0f, 1.0f);
properties.Add(new Property(PropertyName.Scale, node.Scale.ToReadmeString()));
}
void SetScaleXYZ(List<Property> properties, Node node)
{
node.Scale = new Vector3(-1.0f, -1.0f, -1.0f);
properties.Add(new Property(PropertyName.Scale, node.Scale.ToReadmeString()));
}
void SetVertexNormal(List<Property> properties, Node nodeZero, Node nodeOne)
{
var normals = Data.Create(Nodes.GetMultiNodeNormals());
nodeZero.Mesh.MeshPrimitives.First().Normals = normals;
nodeOne.Mesh.MeshPrimitives.First().Normals = normals;
properties.Add(new Property(PropertyName.VertexNormal, ":white_check_mark:"));
}
void SetVertexTangent(List<Property> properties, Node nodeZero, Node nodeOne)
{
var tangents = Data.Create(Nodes.GetMultiNodeTangents());
nodeZero.Mesh.MeshPrimitives.First().Tangents = tangents;
nodeOne.Mesh.MeshPrimitives.First().Tangents = tangents;
properties.Add(new Property(PropertyName.VertexTangent, ":white_check_mark:"));
}
Models = new List<Model>
{
CreateModel((properties, nodeZero, nodeOne) =>
{
// There are no properties set on this model.
}),
CreateModel((properties, nodeZero, nodeOne) =>
{
SetMatrixScaleX(properties, nodeOne);
}),
CreateModel((properties, nodeZero, nodeOne) =>
{
SetMatrixScaleXY(properties, nodeOne);
}),
CreateModel((properties, nodeZero, nodeOne) =>
{
SetMatrixScaleXYZ(properties, nodeOne);
}),
CreateModel((properties, nodeZero, nodeOne) =>
{
SetScaleX(properties, nodeOne);
}),
CreateModel((properties, nodeZero, nodeOne) =>
{
SetScaleXY(properties, nodeOne);
}),
CreateModel((properties, nodeZero, nodeOne) =>
{
SetScaleXYZ(properties, nodeOne);
}),
CreateModel((properties, nodeZero, nodeOne) =>
{
SetScaleX(properties, nodeOne);
SetVertexNormal(properties, nodeZero, nodeOne);
}),
CreateModel((properties, nodeZero, nodeOne) =>
{
SetScaleXY(properties, nodeOne);
SetVertexNormal(properties, nodeZero, nodeOne);
}),
CreateModel((properties, nodeZero, nodeOne) =>
{
SetScaleXYZ(properties, nodeOne);
SetVertexNormal(properties, nodeZero, nodeOne);
}),
CreateModel((properties, nodeZero, nodeOne) =>
{
SetScaleX(properties, nodeOne);
SetVertexNormal(properties, nodeZero, nodeOne);
SetVertexTangent(properties, nodeZero, nodeOne);
}),
CreateModel((properties, nodeZero, nodeOne) =>
{
SetScaleXY(properties, nodeOne);
SetVertexNormal(properties, nodeZero, nodeOne);
SetVertexTangent(properties, nodeZero, nodeOne);
}),
CreateModel((properties, nodeZero, nodeOne) =>
{
SetScaleXYZ(properties, nodeOne);
SetVertexNormal(properties, nodeZero, nodeOne);
SetVertexTangent(properties, nodeZero, nodeOne);
}),
};
GenerateUsedPropertiesList();
}
}
}