forked from KhronosGroup/glTF-Asset-Generator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMesh_PrimitiveAttribute.cs
144 lines (129 loc) · 6.12 KB
/
Mesh_PrimitiveAttribute.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
using AssetGenerator.Runtime;
using System;
using System.Collections.Generic;
using System.Numerics;
namespace AssetGenerator.ModelGroups
{
internal class Mesh_PrimitiveAttribute : ModelGroup
{
public override ModelGroupId Id => ModelGroupId.Mesh_PrimitiveAttribute;
public Mesh_PrimitiveAttribute(List<string> imageList)
{
var baseColorTexture = new Texture { Source = UseTexture(imageList, "BaseColor_Plane") };
var normalTexture = new Texture { Source = UseTexture(imageList, "Normal_Plane") };
// Track the common properties for use in the readme.
CommonProperties.Add(new Property(PropertyName.BaseColorTexture, baseColorTexture.Source.ToReadmeString()));
Model CreateModel(Action<List<Property>, Runtime.MeshPrimitive> setProperties)
{
var properties = new List<Property>();
var meshPrimitive = MeshPrimitive.CreateSinglePlane();
meshPrimitive.Material = new Runtime.Material();
// Apply the common properties to the gltf.
meshPrimitive.Material.PbrMetallicRoughness = new PbrMetallicRoughness
{
BaseColorTexture = new TextureInfo { Texture = baseColorTexture },
};
// Apply the properties that are specific to this gltf.
setProperties(properties, meshPrimitive);
// Create the gltf object.
return new Model
{
Properties = properties,
GLTF = CreateGLTF(() => new Scene
{
Nodes = new List<Node>
{
new Node
{
Mesh = new Runtime.Mesh
{
MeshPrimitives = new List<Runtime.MeshPrimitive>
{
meshPrimitive
}
},
},
},
}),
};
}
void SetVertexUVFloat(List<Property> properties, Runtime.MeshPrimitive meshPrimitive)
{
meshPrimitive.TexCoords0.OutputType = DataType.Float;
properties.Add(new Property(PropertyName.VertexUV0, meshPrimitive.TexCoords0.OutputType.ToReadmeString()));
}
void SetVertexUVByte(List<Property> properties, Runtime.MeshPrimitive meshPrimitive)
{
meshPrimitive.TexCoords0.OutputType = DataType.NormalizedUnsignedByte;
properties.Add(new Property(PropertyName.VertexUV0, meshPrimitive.TexCoords0.OutputType.ToReadmeString()));
}
void SetVertexUVShort(List<Property> properties, Runtime.MeshPrimitive meshPrimitive)
{
meshPrimitive.TexCoords0.OutputType = DataType.NormalizedUnsignedShort;
properties.Add(new Property(PropertyName.VertexUV0, meshPrimitive.TexCoords0.OutputType.ToReadmeString()));
}
void SetVertexNormal(List<Property> properties, Runtime.MeshPrimitive meshPrimitive)
{
var normals = MeshPrimitive.GetSinglePlaneNormals();
meshPrimitive.Normals = Data.Create(normals);
properties.Add(new Property(PropertyName.VertexNormal, normals.ToReadmeString()));
}
void SetVertexTangent(List<Property> properties, Runtime.MeshPrimitive meshPrimitive)
{
var tangents = new[]
{
new Vector4(1.0f, 0.0f, 0.0f, 1.0f),
new Vector4(1.0f, 0.0f, 0.0f, 1.0f),
new Vector4(1.0f, 0.0f, 0.0f, 1.0f),
new Vector4(1.0f, 0.0f, 0.0f, 1.0f)
};
meshPrimitive.Tangents = Data.Create(tangents);
properties.Add(new Property(PropertyName.VertexTangent, tangents.ToReadmeString()));
}
void SetNormalTexture(List<Property> properties, Runtime.MeshPrimitive meshPrimitive)
{
meshPrimitive.Material.NormalTexture = new NormalTextureInfo { Texture = normalTexture };
properties.Add(new Property(PropertyName.NormalTexture, normalTexture.Source.ToReadmeString()));
}
Models = new List<Model>
{
CreateModel((properties, meshPrimitive) =>
{
SetVertexUVFloat(properties, meshPrimitive);
}),
CreateModel((properties, meshPrimitive) =>
{
SetVertexUVByte(properties, meshPrimitive);
}),
CreateModel((properties, meshPrimitive) =>
{
SetVertexUVShort(properties, meshPrimitive);
}),
CreateModel((properties, meshPrimitive) =>
{
SetVertexUVFloat(properties, meshPrimitive);
SetVertexNormal(properties, meshPrimitive);
}),
CreateModel((properties, meshPrimitive) =>
{
SetVertexUVFloat(properties, meshPrimitive);
SetNormalTexture(properties, meshPrimitive);
}),
CreateModel((properties, meshPrimitive) =>
{
SetVertexUVFloat(properties, meshPrimitive);
SetVertexNormal(properties, meshPrimitive);
SetNormalTexture(properties, meshPrimitive);
}),
CreateModel((properties, meshPrimitive) =>
{
SetVertexUVFloat(properties, meshPrimitive);
SetVertexNormal(properties, meshPrimitive);
SetVertexTangent(properties, meshPrimitive);
SetNormalTexture(properties, meshPrimitive);
}),
};
GenerateUsedPropertiesList();
}
}
}