-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
extensions.go
218 lines (169 loc) · 6.62 KB
/
extensions.go
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
package gltf
import "image/color"
type MaterialExtension interface {
ExtensionID() string
ToExtensionData(w *Writer) map[string]any
}
// https://kcoley.github.io/glTF/extensions/2.0/Khronos/KHR_materials_pbrSpecularGlossiness/
type PolyformPbrSpecularGlossiness struct {
// The RGBA components of the reflected diffuse color of the material.
// Metals have a diffuse value of [0.0, 0.0, 0.0]. The fourth component (A)
// is the opacity of the material. The values are linear.
DiffuseFactor color.Color
// The diffuse texture. This texture contains RGB(A) components of the
// reflected diffuse color of the material in sRGB color space. If the
// fourth component (A) is present, it represents the alpha coverage of the
// material. Otherwise, an alpha of 1.0 is assumed. The alphaMode property
// specifies how alpha is interpreted. The stored texels must not be
// premultiplied.
DiffuseTexture *PolyformTexture
// The specular RGB color of the material. This value is linear.
SpecularFactor color.Color
// The glossiness or smoothness of the material. A value of 1.0 means the
// material has full glossiness or is perfectly smooth. A value of 0.0
// means the material has no glossiness or is perfectly rough. This value
// is linear.
// Default value is 1.0
GlossinessFactor float64
// The specular-glossiness texture is a RGBA texture, containing the
// specular color (RGB) in sRGB space and the glossiness value (A) in
// linear space.
SpecularGlossinessTexture *PolyformTexture
}
func (ppsg PolyformPbrSpecularGlossiness) ExtensionID() string {
return "KHR_materials_pbrSpecularGlossiness"
}
func (sg PolyformPbrSpecularGlossiness) ToExtensionData(w *Writer) map[string]any {
metadata := make(map[string]any)
if sg.DiffuseFactor != nil {
metadata["diffuseFactor"] = rgbaToFloatArr(sg.DiffuseFactor)
}
if sg.DiffuseTexture != nil {
metadata["diffuseTexture"] = w.AddTexture(*sg.DiffuseTexture)
}
if sg.SpecularFactor != nil {
metadata["specularFactor"] = rgbToFloatArr(sg.SpecularFactor)
}
metadata["glossinessFactor"] = sg.GlossinessFactor
if sg.SpecularGlossinessTexture != nil {
metadata["specularGlossinessTexture"] = w.AddTexture(*sg.SpecularGlossinessTexture)
}
return metadata
}
// https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_materials_transmission/README.md
type PolyformTransmission struct {
// The base percentage of light that is transmitted through the surface.
// Default: 0.0
TransmissionFactor float64
// A texture that defines the transmission percentage of the surface,
// stored in the R channel. This will be multiplied by transmissionFactor.
TransmissionTexture *PolyformTexture
}
func (tr PolyformTransmission) ExtensionID() string {
return "KHR_materials_transmission"
}
func (tr PolyformTransmission) ToExtensionData(w *Writer) map[string]any {
metadata := make(map[string]any)
metadata["transmissionFactor"] = tr.TransmissionFactor
if tr.TransmissionTexture != nil {
metadata["transmissionTexture"] = w.AddTexture(*tr.TransmissionTexture)
}
return metadata
}
// https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_materials_volume/README.md
type PolyformVolume struct {
// The thickness of the volume beneath the surface. The value is given in
// the coordinate space of the mesh. If the value is 0 the material is
// thin-walled. Otherwise the material is a volume boundary. The
// doubleSided property has no effect on volume boundaries. Range is
// [0, +inf).
// Default: 0
ThicknessFactor float64
// A texture that defines the thickness, stored in the G channel. This will
// be multiplied by thicknessFactor. Range is [0, 1].
ThicknessTexture *PolyformTexture
// Density of the medium given as the average distance that light travels
// in the medium before interacting with a particle. The value is given in
// world space. Range is (0, +inf).
// Default: +Infinity
AttenuationDistance *float64
// The color that white light turns into due to absorption when reaching
// the attenuation distance.
AttenuationColor color.Color
}
func (v PolyformVolume) ExtensionID() string {
return "KHR_materials_volume"
}
func (v PolyformVolume) ToExtensionData(w *Writer) map[string]any {
metadata := make(map[string]any)
metadata["thicknessFactor"] = v.ThicknessFactor
if v.ThicknessTexture != nil {
metadata["thicknessTexture"] = w.AddTexture(*v.ThicknessTexture)
}
if v.AttenuationDistance != nil {
metadata["attenuationDistance"] = *v.AttenuationDistance
}
if v.AttenuationColor != nil {
metadata["attenuationColor"] = rgbToFloatArr(v.AttenuationColor)
}
return metadata
}
// https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_materials_ior/README.md
type PolyformIndexOfRefraction struct {
// The index of refraction
// Air 1.0
// Water 1.33
// Eyes 1.38
// Window Glass 1.52
// Sapphire 1.76
// Diamond 2.42
IOR float64
}
func (sg PolyformIndexOfRefraction) ExtensionID() string {
return "KHR_materials_ior"
}
func (sg PolyformIndexOfRefraction) ToExtensionData(w *Writer) map[string]any {
return map[string]any{
"ior": sg.IOR,
}
}
// https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_materials_specular/README.md
type PolyformSpecular struct {
// The strength of the specular reflection.
// Default: 1.0
SpecularFactor float64
// A texture that defines the strength of the specular reflection, stored
// in the alpha (A) channel. This will be multiplied by specularFactor.
SpecularTexture *PolyformTexture
// The F0 color of the specular reflection (linear RGB).
SpecularColorFactor color.Color
// A texture that defines the F0 color of the specular reflection, stored
// in the RGB channels and encoded in sRGB. This texture will be multiplied
// by specularColorFactor.
SpecularColorTexture *PolyformTexture
}
func (ps PolyformSpecular) ExtensionID() string {
return "KHR_materials_specular"
}
func (ps PolyformSpecular) ToExtensionData(w *Writer) map[string]any {
metadata := make(map[string]any)
metadata["specularFactor"] = ps.SpecularFactor
if ps.SpecularTexture != nil {
metadata["specularTexture"] = w.AddTexture(*ps.SpecularTexture)
}
if ps.SpecularColorFactor != nil {
metadata["specularColorFactor"] = rgbToFloatArr(ps.SpecularColorFactor)
}
if ps.SpecularColorTexture != nil {
metadata["specularColorTexture"] = w.AddTexture(*ps.SpecularColorTexture)
}
return metadata
}
type PolyformMaterialsUnlit struct {
}
func (ps PolyformMaterialsUnlit) ExtensionID() string {
return "KHR_materials_unlit"
}
func (ps PolyformMaterialsUnlit) ToExtensionData(w *Writer) map[string]any {
return make(map[string]any)
}