forked from KhronosGroup/glTF-Asset-Generator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTexture_Sampler.cs
165 lines (152 loc) · 6.74 KB
/
Texture_Sampler.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
using System;
using System.Collections.Generic;
using System.Numerics;
namespace AssetGenerator.ModelGroups
{
internal class Texture_Sampler : ModelGroup
{
public override ModelGroupId Id => ModelGroupId.Texture_Sampler;
public Texture_Sampler(List<string> imageList)
{
var baseColorImage = UseTexture(imageList, "BaseColor_Plane");
// Track the common properties for use in the readme.
CommonProperties.Add(new Property(PropertyName.BaseColorTexture, baseColorImage.ToReadmeString()));
Model CreateModel(Action<List<Property>, Runtime.Sampler> setProperties)
{
var properties = new List<Property>();
Runtime.MeshPrimitive meshPrimitive = MeshPrimitive.CreateSinglePlane();
meshPrimitive.Material = new Runtime.Material
{
PbrMetallicRoughness = new Runtime.PbrMetallicRoughness
{
BaseColorTexture = new Runtime.TextureInfo
{
Texture = new Runtime.Texture
{
Source = baseColorImage,
Sampler = new Runtime.Sampler()
}
},
},
};
// Apply the common properties to the gltf.
meshPrimitive.TexCoords0 = Runtime.Data.Create
(
new[]
{
new Vector2( 1.3f, 1.3f),
new Vector2(-0.3f, 1.3f),
new Vector2(-0.3f, -0.3f),
new Vector2( 1.3f, -0.3f)
}
);
// Apply the properties that are specific to this gltf.
setProperties(properties, meshPrimitive.Material.PbrMetallicRoughness.BaseColorTexture.Texture.Sampler);
// Create the gltf object.
return new Model
{
Properties = properties,
GLTF = CreateGLTF(() => new Runtime.Scene
{
Nodes = new List<Runtime.Node>
{
new Runtime.Node
{
Mesh = new Runtime.Mesh
{
MeshPrimitives = new List<Runtime.MeshPrimitive>
{
meshPrimitive
}
},
},
},
}),
};
}
void SetWrapT(List<Property> properties, Runtime.Sampler sampler, Runtime.SamplerWrap enumValue)
{
sampler.WrapT = enumValue;
properties.Add(new Property(PropertyName.WrapT, enumValue.ToReadmeString()));
}
void SetWrapS(List<Property> properties, Runtime.Sampler sampler, Runtime.SamplerWrap enumValue)
{
sampler.WrapS = enumValue;
properties.Add(new Property(PropertyName.WrapS, sampler.WrapS.ToReadmeString()));
}
void SetMagFilter(List<Property> properties, Runtime.Sampler sampler, Runtime.SamplerMagFilter enumValue)
{
sampler.MagFilter = enumValue;
properties.Add(new Property(PropertyName.MagFilter, enumValue.ToReadmeString()));
}
void SetMinFilter(List<Property> properties, Runtime.Sampler sampler, Runtime.SamplerMinFilter enumValue)
{
sampler.MinFilter = enumValue;
properties.Add(new Property(PropertyName.MinFilter, enumValue.ToReadmeString()));
}
Models = new List<Model>
{
CreateModel((properties, sampler) =>
{
// There are no properties set on this model.
}),
CreateModel((properties, sampler) =>
{
SetWrapT(properties, sampler, Runtime.SamplerWrap.ClampToEdge);
}),
CreateModel((properties, sampler) =>
{
SetWrapT(properties, sampler, Runtime.SamplerWrap.MirroredRepeat);
}),
CreateModel((properties, sampler) =>
{
SetWrapS(properties, sampler, Runtime.SamplerWrap.ClampToEdge);
}),
CreateModel((properties, sampler) =>
{
SetWrapS(properties, sampler, Runtime.SamplerWrap.MirroredRepeat);
}),
CreateModel((properties, sampler) =>
{
SetMagFilter(properties, sampler, Runtime.SamplerMagFilter.Nearest);
}),
CreateModel((properties, sampler) =>
{
SetMagFilter(properties, sampler, Runtime.SamplerMagFilter.Linear);
}),
CreateModel((properties, sampler) =>
{
SetMinFilter(properties, sampler, Runtime.SamplerMinFilter.Nearest);
}),
CreateModel((properties, sampler) =>
{
SetMinFilter(properties, sampler, Runtime.SamplerMinFilter.Linear);
}),
CreateModel((properties, sampler) =>
{
SetMinFilter(properties, sampler, Runtime.SamplerMinFilter.NearestMipmapNearest);
}),
CreateModel((properties, sampler) =>
{
SetMinFilter(properties, sampler, Runtime.SamplerMinFilter.LinearMipmapNearest);
}),
CreateModel((properties, sampler) =>
{
SetMinFilter(properties, sampler, Runtime.SamplerMinFilter.NearestMipmapLinear);
}),
CreateModel((properties, sampler) =>
{
SetMinFilter(properties, sampler, Runtime.SamplerMinFilter.LinearMipmapLinear);
}),
CreateModel((properties, sampler) =>
{
SetWrapT(properties, sampler, Runtime.SamplerWrap.ClampToEdge);
SetWrapS(properties, sampler, Runtime.SamplerWrap.ClampToEdge);
SetMagFilter(properties, sampler, Runtime.SamplerMagFilter.Nearest);
SetMinFilter(properties, sampler, Runtime.SamplerMinFilter.Nearest);
}),
};
GenerateUsedPropertiesList();
}
}
}