forked from KhronosGroup/glTF-Asset-Generator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBuffer_Interleaved.cs
138 lines (123 loc) · 5.71 KB
/
Buffer_Interleaved.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
using AssetGenerator.Runtime;
using System;
using System.Collections.Generic;
using System.Numerics;
namespace AssetGenerator.ModelGroups
{
internal class Buffer_Interleaved : ModelGroup
{
public override ModelGroupId Id => ModelGroupId.Buffer_Interleaved;
public Buffer_Interleaved(List<string> imageList)
{
var baseColorTexture = new Texture { Source = UseTexture(imageList, "BaseColor_Grey") };
// 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>();
Runtime.MeshPrimitive meshPrimitive = MeshPrimitive.CreateSinglePlane();
// Apply the common properties to the gltf.
meshPrimitive.Interleave = true;
meshPrimitive.Colors = Data.Create
(
new[]
{
new Vector3(0.0f, 1.0f, 0.0f),
new Vector3(1.0f, 0.0f, 0.0f),
new Vector3(1.0f, 1.0f, 0.0f),
new Vector3(0.0f, 0.0f, 1.0f),
}
);
meshPrimitive.Material = new Runtime.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[]
{
new Node
{
Mesh = new Runtime.Mesh
{
MeshPrimitives = new[]
{
meshPrimitive
}
},
},
},
}),
};
}
void SetUvTypeFloat(List<Property> properties, Runtime.MeshPrimitive meshPrimitive)
{
meshPrimitive.TexCoords0.OutputType = DataType.Float;
properties.Add(new Property(PropertyName.VertexUV0, meshPrimitive.TexCoords0.OutputType.ToReadmeString()));
}
void SetUvTypeByte(List<Property> properties, Runtime.MeshPrimitive meshPrimitive)
{
meshPrimitive.TexCoords0.OutputType = DataType.NormalizedUnsignedByte;
properties.Add(new Property(PropertyName.VertexUV0, meshPrimitive.TexCoords0.OutputType.ToReadmeString()));
}
void SetUvTypeShort(List<Property> properties, Runtime.MeshPrimitive meshPrimitive)
{
meshPrimitive.TexCoords0.OutputType = DataType.NormalizedUnsignedShort;
properties.Add(new Property(PropertyName.VertexUV0, meshPrimitive.TexCoords0.OutputType.ToReadmeString()));
}
void SetColorTypeFloat(List<Property> properties, Runtime.MeshPrimitive meshPrimitive)
{
meshPrimitive.Colors.OutputType = DataType.Float;
properties.Add(new Property(PropertyName.VertexColor, $"Vector3 {meshPrimitive.Colors.OutputType.ToReadmeString()}"));
}
void SetColorTypeByte(List<Property> properties, Runtime.MeshPrimitive meshPrimitive)
{
meshPrimitive.Colors.OutputType = DataType.NormalizedUnsignedByte;
properties.Add(new Property(PropertyName.VertexColor, $"Vector3 {meshPrimitive.Colors.OutputType.ToReadmeString()}"));
}
void SetColorTypeShort(List<Property> properties, Runtime.MeshPrimitive meshPrimitive)
{
meshPrimitive.Colors.OutputType = DataType.NormalizedUnsignedShort;
properties.Add(new Property(PropertyName.VertexColor, $"Vector3 {meshPrimitive.Colors.OutputType.ToReadmeString()}"));
}
Models = new List<Model>
{
CreateModel((properties, meshPrimitive) =>
{
SetUvTypeFloat(properties, meshPrimitive);
SetColorTypeFloat(properties, meshPrimitive);
}),
CreateModel((properties, meshPrimitive) =>
{
SetUvTypeFloat(properties, meshPrimitive);
SetColorTypeByte(properties, meshPrimitive);
}),
CreateModel((properties, meshPrimitive) =>
{
SetUvTypeFloat(properties, meshPrimitive);
SetColorTypeShort(properties, meshPrimitive);
}),
CreateModel((properties, meshPrimitive) =>
{
SetUvTypeByte(properties, meshPrimitive);
SetColorTypeFloat(properties, meshPrimitive);
}),
CreateModel((properties, meshPrimitive) =>
{
SetUvTypeShort(properties, meshPrimitive);
SetColorTypeFloat(properties, meshPrimitive);
}),
};
GenerateUsedPropertiesList();
}
}
}