@babylonjs/loaders 5.0.0-rc.7 → 5.0.0-rc.9
Sign up to get free protection for your applications and to get access to all the features.
- package/OBJ/index.d.ts +4 -4
- package/OBJ/index.js +4 -4
- package/OBJ/mtlFileLoader.d.ts +41 -41
- package/OBJ/mtlFileLoader.js +232 -232
- package/OBJ/objFileLoader.d.ts +126 -126
- package/OBJ/objFileLoader.js +296 -296
- package/OBJ/objLoadingOptions.d.ts +43 -43
- package/OBJ/objLoadingOptions.js +1 -1
- package/OBJ/solidParser.d.ts +154 -154
- package/OBJ/solidParser.js +693 -693
- package/STL/index.d.ts +1 -1
- package/STL/index.js +1 -1
- package/STL/stlFileLoader.d.ts +64 -64
- package/STL/stlFileLoader.js +233 -233
- package/glTF/1.0/glTFBinaryExtension.d.ts +13 -13
- package/glTF/1.0/glTFBinaryExtension.js +60 -60
- package/glTF/1.0/glTFLoader.d.ts +136 -136
- package/glTF/1.0/glTFLoader.js +1815 -1815
- package/glTF/1.0/glTFLoaderInterfaces.d.ts +412 -412
- package/glTF/1.0/glTFLoaderInterfaces.js +95 -95
- package/glTF/1.0/glTFLoaderUtils.d.ts +62 -62
- package/glTF/1.0/glTFLoaderUtils.js +250 -250
- package/glTF/1.0/glTFMaterialsCommonExtension.d.ts +10 -10
- package/glTF/1.0/glTFMaterialsCommonExtension.js +129 -129
- package/glTF/1.0/index.d.ts +5 -5
- package/glTF/1.0/index.js +5 -5
- package/glTF/2.0/Extensions/EXT_lights_image_based.d.ts +43 -43
- package/glTF/2.0/Extensions/EXT_lights_image_based.js +117 -117
- package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.d.ts +36 -36
- package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js +88 -88
- package/glTF/2.0/Extensions/EXT_meshopt_compression.d.ts +34 -34
- package/glTF/2.0/Extensions/EXT_meshopt_compression.js +49 -49
- package/glTF/2.0/Extensions/EXT_texture_webp.d.ts +29 -29
- package/glTF/2.0/Extensions/EXT_texture_webp.js +40 -40
- package/glTF/2.0/Extensions/ExtrasAsMetadata.d.ts +50 -50
- package/glTF/2.0/Extensions/ExtrasAsMetadata.js +73 -73
- package/glTF/2.0/Extensions/KHR_draco_mesh_compression.d.ts +39 -39
- package/glTF/2.0/Extensions/KHR_draco_mesh_compression.js +112 -112
- package/glTF/2.0/Extensions/KHR_lights_punctual.d.ts +36 -36
- package/glTF/2.0/Extensions/KHR_lights_punctual.js +89 -89
- package/glTF/2.0/Extensions/KHR_materials_clearcoat.d.ts +39 -39
- package/glTF/2.0/Extensions/KHR_materials_clearcoat.js +94 -94
- package/glTF/2.0/Extensions/KHR_materials_emissive_strength.d.ts +38 -38
- package/glTF/2.0/Extensions/KHR_materials_emissive_strength.js +53 -53
- package/glTF/2.0/Extensions/KHR_materials_ior.d.ts +42 -42
- package/glTF/2.0/Extensions/KHR_materials_ior.js +62 -62
- package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.d.ts +38 -38
- package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.js +80 -80
- package/glTF/2.0/Extensions/KHR_materials_sheen.d.ts +39 -39
- package/glTF/2.0/Extensions/KHR_materials_sheen.js +84 -84
- package/glTF/2.0/Extensions/KHR_materials_specular.d.ts +38 -38
- package/glTF/2.0/Extensions/KHR_materials_specular.js +74 -74
- package/glTF/2.0/Extensions/KHR_materials_translucency.d.ts +39 -39
- package/glTF/2.0/Extensions/KHR_materials_translucency.js +83 -83
- package/glTF/2.0/Extensions/KHR_materials_transmission.d.ts +38 -38
- package/glTF/2.0/Extensions/KHR_materials_transmission.js +288 -288
- package/glTF/2.0/Extensions/KHR_materials_unlit.d.ts +38 -38
- package/glTF/2.0/Extensions/KHR_materials_unlit.js +73 -73
- package/glTF/2.0/Extensions/KHR_materials_variants.d.ts +87 -87
- package/glTF/2.0/Extensions/KHR_materials_variants.js +254 -254
- package/glTF/2.0/Extensions/KHR_materials_volume.d.ts +39 -39
- package/glTF/2.0/Extensions/KHR_materials_volume.js +85 -85
- package/glTF/2.0/Extensions/KHR_mesh_quantization.d.ts +22 -22
- package/glTF/2.0/Extensions/KHR_mesh_quantization.js +23 -23
- package/glTF/2.0/Extensions/KHR_texture_basisu.d.ts +29 -29
- package/glTF/2.0/Extensions/KHR_texture_basisu.js +40 -40
- package/glTF/2.0/Extensions/KHR_texture_transform.d.ts +33 -33
- package/glTF/2.0/Extensions/KHR_texture_transform.js +61 -61
- package/glTF/2.0/Extensions/KHR_xmp_json_ld.d.ts +32 -32
- package/glTF/2.0/Extensions/KHR_xmp_json_ld.js +49 -49
- package/glTF/2.0/Extensions/MSFT_audio_emitter.d.ts +54 -54
- package/glTF/2.0/Extensions/MSFT_audio_emitter.js +240 -240
- package/glTF/2.0/Extensions/MSFT_lod.d.ts +109 -109
- package/glTF/2.0/Extensions/MSFT_lod.js +369 -369
- package/glTF/2.0/Extensions/MSFT_minecraftMesh.d.ts +14 -14
- package/glTF/2.0/Extensions/MSFT_minecraftMesh.js +36 -36
- package/glTF/2.0/Extensions/MSFT_sRGBFactors.d.ts +14 -14
- package/glTF/2.0/Extensions/MSFT_sRGBFactors.js +36 -36
- package/glTF/2.0/Extensions/index.d.ts +26 -26
- package/glTF/2.0/Extensions/index.js +26 -26
- package/glTF/2.0/glTFLoader.d.ts +405 -405
- package/glTF/2.0/glTFLoader.js +2366 -2366
- package/glTF/2.0/glTFLoaderExtension.d.ts +152 -152
- package/glTF/2.0/glTFLoaderExtension.js +1 -1
- package/glTF/2.0/glTFLoaderInterfaces.d.ts +211 -211
- package/glTF/2.0/glTFLoaderInterfaces.js +1 -1
- package/glTF/2.0/index.d.ts +4 -4
- package/glTF/2.0/index.js +4 -4
- package/glTF/glTFFileLoader.d.ts +433 -433
- package/glTF/glTFFileLoader.js +927 -927
- package/glTF/glTFValidation.d.ts +29 -29
- package/glTF/glTFValidation.js +123 -123
- package/glTF/index.d.ts +5 -5
- package/glTF/index.js +5 -5
- package/index.d.ts +3 -3
- package/index.js +3 -3
- package/legacy/legacy-glTF.d.ts +2 -2
- package/legacy/legacy-glTF.js +18 -18
- package/legacy/legacy-glTF1.d.ts +2 -2
- package/legacy/legacy-glTF1.js +14 -14
- package/legacy/legacy-glTF1FileLoader.d.ts +2 -2
- package/legacy/legacy-glTF1FileLoader.js +3 -3
- package/legacy/legacy-glTF2.d.ts +2 -2
- package/legacy/legacy-glTF2.js +32 -32
- package/legacy/legacy-glTF2FileLoader.d.ts +2 -2
- package/legacy/legacy-glTF2FileLoader.js +3 -3
- package/legacy/legacy-glTFFileLoader.d.ts +3 -3
- package/legacy/legacy-glTFFileLoader.js +4 -4
- package/legacy/legacy-objFileLoader.d.ts +1 -1
- package/legacy/legacy-objFileLoader.js +12 -12
- package/legacy/legacy-stlFileLoader.d.ts +1 -1
- package/legacy/legacy-stlFileLoader.js +12 -12
- package/legacy/legacy.d.ts +6 -6
- package/legacy/legacy.js +7 -7
- package/package.json +3 -3
@@ -1,251 +1,251 @@
|
|
1
|
-
import { EParameterType, ETextureWrapMode, ETextureFilterType, EComponentType, } from "./glTFLoaderInterfaces
|
2
|
-
import { Vector2, Vector3, Vector4, Matrix } from "@babylonjs/core/Maths/math.vector.js";
|
3
|
-
import { Color4 } from "@babylonjs/core/Maths/math.color.js";
|
4
|
-
import { Effect } from "@babylonjs/core/Materials/effect.js";
|
5
|
-
import { ShaderMaterial } from "@babylonjs/core/Materials/shaderMaterial.js";
|
6
|
-
import { Texture } from "@babylonjs/core/Materials/Textures/texture.js";
|
7
|
-
/**
|
8
|
-
* Utils functions for GLTF
|
9
|
-
* @hidden
|
10
|
-
*/
|
11
|
-
var GLTFUtils = /** @class */ (function () {
|
12
|
-
function GLTFUtils() {
|
13
|
-
}
|
14
|
-
/**
|
15
|
-
* Sets the given "parameter" matrix
|
16
|
-
* @param scene the Scene object
|
17
|
-
* @param source the source node where to pick the matrix
|
18
|
-
* @param parameter the GLTF technique parameter
|
19
|
-
* @param uniformName the name of the shader's uniform
|
20
|
-
* @param shaderMaterial the shader material
|
21
|
-
*/
|
22
|
-
GLTFUtils.SetMatrix = function (scene, source, parameter, uniformName, shaderMaterial) {
|
23
|
-
var mat = null;
|
24
|
-
if (parameter.semantic === "MODEL") {
|
25
|
-
mat = source.getWorldMatrix();
|
26
|
-
}
|
27
|
-
else if (parameter.semantic === "PROJECTION") {
|
28
|
-
mat = scene.getProjectionMatrix();
|
29
|
-
}
|
30
|
-
else if (parameter.semantic === "VIEW") {
|
31
|
-
mat = scene.getViewMatrix();
|
32
|
-
}
|
33
|
-
else if (parameter.semantic === "MODELVIEWINVERSETRANSPOSE") {
|
34
|
-
mat = Matrix.Transpose(source.getWorldMatrix().multiply(scene.getViewMatrix()).invert());
|
35
|
-
}
|
36
|
-
else if (parameter.semantic === "MODELVIEW") {
|
37
|
-
mat = source.getWorldMatrix().multiply(scene.getViewMatrix());
|
38
|
-
}
|
39
|
-
else if (parameter.semantic === "MODELVIEWPROJECTION") {
|
40
|
-
mat = source.getWorldMatrix().multiply(scene.getTransformMatrix());
|
41
|
-
}
|
42
|
-
else if (parameter.semantic === "MODELINVERSE") {
|
43
|
-
mat = source.getWorldMatrix().invert();
|
44
|
-
}
|
45
|
-
else if (parameter.semantic === "VIEWINVERSE") {
|
46
|
-
mat = scene.getViewMatrix().invert();
|
47
|
-
}
|
48
|
-
else if (parameter.semantic === "PROJECTIONINVERSE") {
|
49
|
-
mat = scene.getProjectionMatrix().invert();
|
50
|
-
}
|
51
|
-
else if (parameter.semantic === "MODELVIEWINVERSE") {
|
52
|
-
mat = source.getWorldMatrix().multiply(scene.getViewMatrix()).invert();
|
53
|
-
}
|
54
|
-
else if (parameter.semantic === "MODELVIEWPROJECTIONINVERSE") {
|
55
|
-
mat = source.getWorldMatrix().multiply(scene.getTransformMatrix()).invert();
|
56
|
-
}
|
57
|
-
else if (parameter.semantic === "MODELINVERSETRANSPOSE") {
|
58
|
-
mat = Matrix.Transpose(source.getWorldMatrix().invert());
|
59
|
-
}
|
60
|
-
if (mat) {
|
61
|
-
switch (parameter.type) {
|
62
|
-
case EParameterType.FLOAT_MAT2:
|
63
|
-
shaderMaterial.setMatrix2x2(uniformName, Matrix.GetAsMatrix2x2(mat));
|
64
|
-
break;
|
65
|
-
case EParameterType.FLOAT_MAT3:
|
66
|
-
shaderMaterial.setMatrix3x3(uniformName, Matrix.GetAsMatrix3x3(mat));
|
67
|
-
break;
|
68
|
-
case EParameterType.FLOAT_MAT4:
|
69
|
-
shaderMaterial.setMatrix(uniformName, mat);
|
70
|
-
break;
|
71
|
-
default:
|
72
|
-
break;
|
73
|
-
}
|
74
|
-
}
|
75
|
-
};
|
76
|
-
/**
|
77
|
-
* Sets the given "parameter" matrix
|
78
|
-
* @param shaderMaterial the shader material
|
79
|
-
* @param uniform the name of the shader's uniform
|
80
|
-
* @param value the value of the uniform
|
81
|
-
* @param type the uniform's type (EParameterType FLOAT, VEC2, VEC3 or VEC4)
|
82
|
-
*/
|
83
|
-
GLTFUtils.SetUniform = function (shaderMaterial, uniform, value, type) {
|
84
|
-
switch (type) {
|
85
|
-
case EParameterType.FLOAT:
|
86
|
-
shaderMaterial.setFloat(uniform, value);
|
87
|
-
return true;
|
88
|
-
case EParameterType.FLOAT_VEC2:
|
89
|
-
shaderMaterial.setVector2(uniform, Vector2.FromArray(value));
|
90
|
-
return true;
|
91
|
-
case EParameterType.FLOAT_VEC3:
|
92
|
-
shaderMaterial.setVector3(uniform, Vector3.FromArray(value));
|
93
|
-
return true;
|
94
|
-
case EParameterType.FLOAT_VEC4:
|
95
|
-
shaderMaterial.setVector4(uniform, Vector4.FromArray(value));
|
96
|
-
return true;
|
97
|
-
default:
|
98
|
-
return false;
|
99
|
-
}
|
100
|
-
};
|
101
|
-
/**
|
102
|
-
* Returns the wrap mode of the texture
|
103
|
-
* @param mode the mode value
|
104
|
-
*/
|
105
|
-
GLTFUtils.GetWrapMode = function (mode) {
|
106
|
-
switch (mode) {
|
107
|
-
case ETextureWrapMode.CLAMP_TO_EDGE:
|
108
|
-
return Texture.CLAMP_ADDRESSMODE;
|
109
|
-
case ETextureWrapMode.MIRRORED_REPEAT:
|
110
|
-
return Texture.MIRROR_ADDRESSMODE;
|
111
|
-
case ETextureWrapMode.REPEAT:
|
112
|
-
return Texture.WRAP_ADDRESSMODE;
|
113
|
-
default:
|
114
|
-
return Texture.WRAP_ADDRESSMODE;
|
115
|
-
}
|
116
|
-
};
|
117
|
-
/**
|
118
|
-
* Returns the byte stride giving an accessor
|
119
|
-
* @param accessor the GLTF accessor objet
|
120
|
-
*/
|
121
|
-
GLTFUtils.GetByteStrideFromType = function (accessor) {
|
122
|
-
// Needs this function since "byteStride" isn't requiered in glTF format
|
123
|
-
var type = accessor.type;
|
124
|
-
switch (type) {
|
125
|
-
case "VEC2":
|
126
|
-
return 2;
|
127
|
-
case "VEC3":
|
128
|
-
return 3;
|
129
|
-
case "VEC4":
|
130
|
-
return 4;
|
131
|
-
case "MAT2":
|
132
|
-
return 4;
|
133
|
-
case "MAT3":
|
134
|
-
return 9;
|
135
|
-
case "MAT4":
|
136
|
-
return 16;
|
137
|
-
default:
|
138
|
-
return 1;
|
139
|
-
}
|
140
|
-
};
|
141
|
-
/**
|
142
|
-
* Returns the texture filter mode giving a mode value
|
143
|
-
* @param mode the filter mode value
|
144
|
-
*/
|
145
|
-
GLTFUtils.GetTextureFilterMode = function (mode) {
|
146
|
-
switch (mode) {
|
147
|
-
case ETextureFilterType.LINEAR:
|
148
|
-
case ETextureFilterType.LINEAR_MIPMAP_NEAREST:
|
149
|
-
case ETextureFilterType.LINEAR_MIPMAP_LINEAR:
|
150
|
-
return Texture.TRILINEAR_SAMPLINGMODE;
|
151
|
-
case ETextureFilterType.NEAREST:
|
152
|
-
case ETextureFilterType.NEAREST_MIPMAP_NEAREST:
|
153
|
-
return Texture.NEAREST_SAMPLINGMODE;
|
154
|
-
default:
|
155
|
-
return Texture.BILINEAR_SAMPLINGMODE;
|
156
|
-
}
|
157
|
-
};
|
158
|
-
GLTFUtils.GetBufferFromBufferView = function (gltfRuntime, bufferView, byteOffset, byteLength, componentType) {
|
159
|
-
byteOffset = bufferView.byteOffset + byteOffset;
|
160
|
-
var loadedBufferView = gltfRuntime.loadedBufferViews[bufferView.buffer];
|
161
|
-
if (byteOffset + byteLength > loadedBufferView.byteLength) {
|
162
|
-
throw new Error("Buffer access is out of range");
|
163
|
-
}
|
164
|
-
var buffer = loadedBufferView.buffer;
|
165
|
-
byteOffset += loadedBufferView.byteOffset;
|
166
|
-
switch (componentType) {
|
167
|
-
case EComponentType.BYTE:
|
168
|
-
return new Int8Array(buffer, byteOffset, byteLength);
|
169
|
-
case EComponentType.UNSIGNED_BYTE:
|
170
|
-
return new Uint8Array(buffer, byteOffset, byteLength);
|
171
|
-
case EComponentType.SHORT:
|
172
|
-
return new Int16Array(buffer, byteOffset, byteLength);
|
173
|
-
case EComponentType.UNSIGNED_SHORT:
|
174
|
-
return new Uint16Array(buffer, byteOffset, byteLength);
|
175
|
-
default:
|
176
|
-
return new Float32Array(buffer, byteOffset, byteLength);
|
177
|
-
}
|
178
|
-
};
|
179
|
-
/**
|
180
|
-
* Returns a buffer from its accessor
|
181
|
-
* @param gltfRuntime the GLTF runtime
|
182
|
-
* @param accessor the GLTF accessor
|
183
|
-
*/
|
184
|
-
GLTFUtils.GetBufferFromAccessor = function (gltfRuntime, accessor) {
|
185
|
-
var bufferView = gltfRuntime.bufferViews[accessor.bufferView];
|
186
|
-
var byteLength = accessor.count * GLTFUtils.GetByteStrideFromType(accessor);
|
187
|
-
return GLTFUtils.GetBufferFromBufferView(gltfRuntime, bufferView, accessor.byteOffset, byteLength, accessor.componentType);
|
188
|
-
};
|
189
|
-
/**
|
190
|
-
* Decodes a buffer view into a string
|
191
|
-
* @param view the buffer view
|
192
|
-
*/
|
193
|
-
GLTFUtils.DecodeBufferToText = function (view) {
|
194
|
-
var result = "";
|
195
|
-
var length = view.byteLength;
|
196
|
-
for (var i = 0; i < length; ++i) {
|
197
|
-
result += String.fromCharCode(view[i]);
|
198
|
-
}
|
199
|
-
return result;
|
200
|
-
};
|
201
|
-
/**
|
202
|
-
* Returns the default material of gltf. Related to
|
203
|
-
* https://github.com/KhronosGroup/glTF/tree/master/specification/1.0#appendix-a-default-material
|
204
|
-
* @param scene the Babylon.js scene
|
205
|
-
*/
|
206
|
-
GLTFUtils.GetDefaultMaterial = function (scene) {
|
207
|
-
if (!GLTFUtils._DefaultMaterial) {
|
208
|
-
Effect.ShadersStore["GLTFDefaultMaterialVertexShader"] = [
|
209
|
-
"precision highp float;",
|
210
|
-
"",
|
211
|
-
"uniform mat4 worldView;",
|
212
|
-
"uniform mat4 projection;",
|
213
|
-
"",
|
214
|
-
"attribute vec3 position;",
|
215
|
-
"",
|
216
|
-
"void main(void)",
|
217
|
-
"{",
|
218
|
-
" gl_Position = projection * worldView * vec4(position, 1.0);",
|
219
|
-
"}",
|
220
|
-
].join("\n");
|
221
|
-
Effect.ShadersStore["GLTFDefaultMaterialPixelShader"] = [
|
222
|
-
"precision highp float;",
|
223
|
-
"",
|
224
|
-
"uniform vec4 u_emission;",
|
225
|
-
"",
|
226
|
-
"void main(void)",
|
227
|
-
"{",
|
228
|
-
" gl_FragColor = u_emission;",
|
229
|
-
"}",
|
230
|
-
].join("\n");
|
231
|
-
var shaderPath = {
|
232
|
-
vertex: "GLTFDefaultMaterial",
|
233
|
-
fragment: "GLTFDefaultMaterial",
|
234
|
-
};
|
235
|
-
var options = {
|
236
|
-
attributes: ["position"],
|
237
|
-
uniforms: ["worldView", "projection", "u_emission"],
|
238
|
-
samplers: new Array(),
|
239
|
-
needAlphaBlending: false,
|
240
|
-
};
|
241
|
-
GLTFUtils._DefaultMaterial = new ShaderMaterial("GLTFDefaultMaterial", scene, shaderPath, options);
|
242
|
-
GLTFUtils._DefaultMaterial.setColor4("u_emission", new Color4(0.5, 0.5, 0.5, 1.0));
|
243
|
-
}
|
244
|
-
return GLTFUtils._DefaultMaterial;
|
245
|
-
};
|
246
|
-
// The GLTF default material
|
247
|
-
GLTFUtils._DefaultMaterial = null;
|
248
|
-
return GLTFUtils;
|
249
|
-
}());
|
250
|
-
export { GLTFUtils };
|
1
|
+
import { EParameterType, ETextureWrapMode, ETextureFilterType, EComponentType, } from "./glTFLoaderInterfaces";
|
2
|
+
import { Vector2, Vector3, Vector4, Matrix } from "@babylonjs/core/Maths/math.vector.js";
|
3
|
+
import { Color4 } from "@babylonjs/core/Maths/math.color.js";
|
4
|
+
import { Effect } from "@babylonjs/core/Materials/effect.js";
|
5
|
+
import { ShaderMaterial } from "@babylonjs/core/Materials/shaderMaterial.js";
|
6
|
+
import { Texture } from "@babylonjs/core/Materials/Textures/texture.js";
|
7
|
+
/**
|
8
|
+
* Utils functions for GLTF
|
9
|
+
* @hidden
|
10
|
+
*/
|
11
|
+
var GLTFUtils = /** @class */ (function () {
|
12
|
+
function GLTFUtils() {
|
13
|
+
}
|
14
|
+
/**
|
15
|
+
* Sets the given "parameter" matrix
|
16
|
+
* @param scene the Scene object
|
17
|
+
* @param source the source node where to pick the matrix
|
18
|
+
* @param parameter the GLTF technique parameter
|
19
|
+
* @param uniformName the name of the shader's uniform
|
20
|
+
* @param shaderMaterial the shader material
|
21
|
+
*/
|
22
|
+
GLTFUtils.SetMatrix = function (scene, source, parameter, uniformName, shaderMaterial) {
|
23
|
+
var mat = null;
|
24
|
+
if (parameter.semantic === "MODEL") {
|
25
|
+
mat = source.getWorldMatrix();
|
26
|
+
}
|
27
|
+
else if (parameter.semantic === "PROJECTION") {
|
28
|
+
mat = scene.getProjectionMatrix();
|
29
|
+
}
|
30
|
+
else if (parameter.semantic === "VIEW") {
|
31
|
+
mat = scene.getViewMatrix();
|
32
|
+
}
|
33
|
+
else if (parameter.semantic === "MODELVIEWINVERSETRANSPOSE") {
|
34
|
+
mat = Matrix.Transpose(source.getWorldMatrix().multiply(scene.getViewMatrix()).invert());
|
35
|
+
}
|
36
|
+
else if (parameter.semantic === "MODELVIEW") {
|
37
|
+
mat = source.getWorldMatrix().multiply(scene.getViewMatrix());
|
38
|
+
}
|
39
|
+
else if (parameter.semantic === "MODELVIEWPROJECTION") {
|
40
|
+
mat = source.getWorldMatrix().multiply(scene.getTransformMatrix());
|
41
|
+
}
|
42
|
+
else if (parameter.semantic === "MODELINVERSE") {
|
43
|
+
mat = source.getWorldMatrix().invert();
|
44
|
+
}
|
45
|
+
else if (parameter.semantic === "VIEWINVERSE") {
|
46
|
+
mat = scene.getViewMatrix().invert();
|
47
|
+
}
|
48
|
+
else if (parameter.semantic === "PROJECTIONINVERSE") {
|
49
|
+
mat = scene.getProjectionMatrix().invert();
|
50
|
+
}
|
51
|
+
else if (parameter.semantic === "MODELVIEWINVERSE") {
|
52
|
+
mat = source.getWorldMatrix().multiply(scene.getViewMatrix()).invert();
|
53
|
+
}
|
54
|
+
else if (parameter.semantic === "MODELVIEWPROJECTIONINVERSE") {
|
55
|
+
mat = source.getWorldMatrix().multiply(scene.getTransformMatrix()).invert();
|
56
|
+
}
|
57
|
+
else if (parameter.semantic === "MODELINVERSETRANSPOSE") {
|
58
|
+
mat = Matrix.Transpose(source.getWorldMatrix().invert());
|
59
|
+
}
|
60
|
+
if (mat) {
|
61
|
+
switch (parameter.type) {
|
62
|
+
case EParameterType.FLOAT_MAT2:
|
63
|
+
shaderMaterial.setMatrix2x2(uniformName, Matrix.GetAsMatrix2x2(mat));
|
64
|
+
break;
|
65
|
+
case EParameterType.FLOAT_MAT3:
|
66
|
+
shaderMaterial.setMatrix3x3(uniformName, Matrix.GetAsMatrix3x3(mat));
|
67
|
+
break;
|
68
|
+
case EParameterType.FLOAT_MAT4:
|
69
|
+
shaderMaterial.setMatrix(uniformName, mat);
|
70
|
+
break;
|
71
|
+
default:
|
72
|
+
break;
|
73
|
+
}
|
74
|
+
}
|
75
|
+
};
|
76
|
+
/**
|
77
|
+
* Sets the given "parameter" matrix
|
78
|
+
* @param shaderMaterial the shader material
|
79
|
+
* @param uniform the name of the shader's uniform
|
80
|
+
* @param value the value of the uniform
|
81
|
+
* @param type the uniform's type (EParameterType FLOAT, VEC2, VEC3 or VEC4)
|
82
|
+
*/
|
83
|
+
GLTFUtils.SetUniform = function (shaderMaterial, uniform, value, type) {
|
84
|
+
switch (type) {
|
85
|
+
case EParameterType.FLOAT:
|
86
|
+
shaderMaterial.setFloat(uniform, value);
|
87
|
+
return true;
|
88
|
+
case EParameterType.FLOAT_VEC2:
|
89
|
+
shaderMaterial.setVector2(uniform, Vector2.FromArray(value));
|
90
|
+
return true;
|
91
|
+
case EParameterType.FLOAT_VEC3:
|
92
|
+
shaderMaterial.setVector3(uniform, Vector3.FromArray(value));
|
93
|
+
return true;
|
94
|
+
case EParameterType.FLOAT_VEC4:
|
95
|
+
shaderMaterial.setVector4(uniform, Vector4.FromArray(value));
|
96
|
+
return true;
|
97
|
+
default:
|
98
|
+
return false;
|
99
|
+
}
|
100
|
+
};
|
101
|
+
/**
|
102
|
+
* Returns the wrap mode of the texture
|
103
|
+
* @param mode the mode value
|
104
|
+
*/
|
105
|
+
GLTFUtils.GetWrapMode = function (mode) {
|
106
|
+
switch (mode) {
|
107
|
+
case ETextureWrapMode.CLAMP_TO_EDGE:
|
108
|
+
return Texture.CLAMP_ADDRESSMODE;
|
109
|
+
case ETextureWrapMode.MIRRORED_REPEAT:
|
110
|
+
return Texture.MIRROR_ADDRESSMODE;
|
111
|
+
case ETextureWrapMode.REPEAT:
|
112
|
+
return Texture.WRAP_ADDRESSMODE;
|
113
|
+
default:
|
114
|
+
return Texture.WRAP_ADDRESSMODE;
|
115
|
+
}
|
116
|
+
};
|
117
|
+
/**
|
118
|
+
* Returns the byte stride giving an accessor
|
119
|
+
* @param accessor the GLTF accessor objet
|
120
|
+
*/
|
121
|
+
GLTFUtils.GetByteStrideFromType = function (accessor) {
|
122
|
+
// Needs this function since "byteStride" isn't requiered in glTF format
|
123
|
+
var type = accessor.type;
|
124
|
+
switch (type) {
|
125
|
+
case "VEC2":
|
126
|
+
return 2;
|
127
|
+
case "VEC3":
|
128
|
+
return 3;
|
129
|
+
case "VEC4":
|
130
|
+
return 4;
|
131
|
+
case "MAT2":
|
132
|
+
return 4;
|
133
|
+
case "MAT3":
|
134
|
+
return 9;
|
135
|
+
case "MAT4":
|
136
|
+
return 16;
|
137
|
+
default:
|
138
|
+
return 1;
|
139
|
+
}
|
140
|
+
};
|
141
|
+
/**
|
142
|
+
* Returns the texture filter mode giving a mode value
|
143
|
+
* @param mode the filter mode value
|
144
|
+
*/
|
145
|
+
GLTFUtils.GetTextureFilterMode = function (mode) {
|
146
|
+
switch (mode) {
|
147
|
+
case ETextureFilterType.LINEAR:
|
148
|
+
case ETextureFilterType.LINEAR_MIPMAP_NEAREST:
|
149
|
+
case ETextureFilterType.LINEAR_MIPMAP_LINEAR:
|
150
|
+
return Texture.TRILINEAR_SAMPLINGMODE;
|
151
|
+
case ETextureFilterType.NEAREST:
|
152
|
+
case ETextureFilterType.NEAREST_MIPMAP_NEAREST:
|
153
|
+
return Texture.NEAREST_SAMPLINGMODE;
|
154
|
+
default:
|
155
|
+
return Texture.BILINEAR_SAMPLINGMODE;
|
156
|
+
}
|
157
|
+
};
|
158
|
+
GLTFUtils.GetBufferFromBufferView = function (gltfRuntime, bufferView, byteOffset, byteLength, componentType) {
|
159
|
+
byteOffset = bufferView.byteOffset + byteOffset;
|
160
|
+
var loadedBufferView = gltfRuntime.loadedBufferViews[bufferView.buffer];
|
161
|
+
if (byteOffset + byteLength > loadedBufferView.byteLength) {
|
162
|
+
throw new Error("Buffer access is out of range");
|
163
|
+
}
|
164
|
+
var buffer = loadedBufferView.buffer;
|
165
|
+
byteOffset += loadedBufferView.byteOffset;
|
166
|
+
switch (componentType) {
|
167
|
+
case EComponentType.BYTE:
|
168
|
+
return new Int8Array(buffer, byteOffset, byteLength);
|
169
|
+
case EComponentType.UNSIGNED_BYTE:
|
170
|
+
return new Uint8Array(buffer, byteOffset, byteLength);
|
171
|
+
case EComponentType.SHORT:
|
172
|
+
return new Int16Array(buffer, byteOffset, byteLength);
|
173
|
+
case EComponentType.UNSIGNED_SHORT:
|
174
|
+
return new Uint16Array(buffer, byteOffset, byteLength);
|
175
|
+
default:
|
176
|
+
return new Float32Array(buffer, byteOffset, byteLength);
|
177
|
+
}
|
178
|
+
};
|
179
|
+
/**
|
180
|
+
* Returns a buffer from its accessor
|
181
|
+
* @param gltfRuntime the GLTF runtime
|
182
|
+
* @param accessor the GLTF accessor
|
183
|
+
*/
|
184
|
+
GLTFUtils.GetBufferFromAccessor = function (gltfRuntime, accessor) {
|
185
|
+
var bufferView = gltfRuntime.bufferViews[accessor.bufferView];
|
186
|
+
var byteLength = accessor.count * GLTFUtils.GetByteStrideFromType(accessor);
|
187
|
+
return GLTFUtils.GetBufferFromBufferView(gltfRuntime, bufferView, accessor.byteOffset, byteLength, accessor.componentType);
|
188
|
+
};
|
189
|
+
/**
|
190
|
+
* Decodes a buffer view into a string
|
191
|
+
* @param view the buffer view
|
192
|
+
*/
|
193
|
+
GLTFUtils.DecodeBufferToText = function (view) {
|
194
|
+
var result = "";
|
195
|
+
var length = view.byteLength;
|
196
|
+
for (var i = 0; i < length; ++i) {
|
197
|
+
result += String.fromCharCode(view[i]);
|
198
|
+
}
|
199
|
+
return result;
|
200
|
+
};
|
201
|
+
/**
|
202
|
+
* Returns the default material of gltf. Related to
|
203
|
+
* https://github.com/KhronosGroup/glTF/tree/master/specification/1.0#appendix-a-default-material
|
204
|
+
* @param scene the Babylon.js scene
|
205
|
+
*/
|
206
|
+
GLTFUtils.GetDefaultMaterial = function (scene) {
|
207
|
+
if (!GLTFUtils._DefaultMaterial) {
|
208
|
+
Effect.ShadersStore["GLTFDefaultMaterialVertexShader"] = [
|
209
|
+
"precision highp float;",
|
210
|
+
"",
|
211
|
+
"uniform mat4 worldView;",
|
212
|
+
"uniform mat4 projection;",
|
213
|
+
"",
|
214
|
+
"attribute vec3 position;",
|
215
|
+
"",
|
216
|
+
"void main(void)",
|
217
|
+
"{",
|
218
|
+
" gl_Position = projection * worldView * vec4(position, 1.0);",
|
219
|
+
"}",
|
220
|
+
].join("\n");
|
221
|
+
Effect.ShadersStore["GLTFDefaultMaterialPixelShader"] = [
|
222
|
+
"precision highp float;",
|
223
|
+
"",
|
224
|
+
"uniform vec4 u_emission;",
|
225
|
+
"",
|
226
|
+
"void main(void)",
|
227
|
+
"{",
|
228
|
+
" gl_FragColor = u_emission;",
|
229
|
+
"}",
|
230
|
+
].join("\n");
|
231
|
+
var shaderPath = {
|
232
|
+
vertex: "GLTFDefaultMaterial",
|
233
|
+
fragment: "GLTFDefaultMaterial",
|
234
|
+
};
|
235
|
+
var options = {
|
236
|
+
attributes: ["position"],
|
237
|
+
uniforms: ["worldView", "projection", "u_emission"],
|
238
|
+
samplers: new Array(),
|
239
|
+
needAlphaBlending: false,
|
240
|
+
};
|
241
|
+
GLTFUtils._DefaultMaterial = new ShaderMaterial("GLTFDefaultMaterial", scene, shaderPath, options);
|
242
|
+
GLTFUtils._DefaultMaterial.setColor4("u_emission", new Color4(0.5, 0.5, 0.5, 1.0));
|
243
|
+
}
|
244
|
+
return GLTFUtils._DefaultMaterial;
|
245
|
+
};
|
246
|
+
// The GLTF default material
|
247
|
+
GLTFUtils._DefaultMaterial = null;
|
248
|
+
return GLTFUtils;
|
249
|
+
}());
|
250
|
+
export { GLTFUtils };
|
251
251
|
//# sourceMappingURL=glTFLoaderUtils.js.map
|
@@ -1,10 +1,10 @@
|
|
1
|
-
import { GLTFLoaderExtension } from "./glTFLoader";
|
2
|
-
import { IGLTFRuntime } from "./glTFLoaderInterfaces";
|
3
|
-
import { Material } from "@babylonjs/core/Materials/material.js";
|
4
|
-
/** @hidden */
|
5
|
-
export declare class GLTFMaterialsCommonExtension extends GLTFLoaderExtension {
|
6
|
-
constructor();
|
7
|
-
loadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime): boolean;
|
8
|
-
loadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): boolean;
|
9
|
-
private _loadTexture;
|
10
|
-
}
|
1
|
+
import { GLTFLoaderExtension } from "./glTFLoader";
|
2
|
+
import { IGLTFRuntime } from "./glTFLoaderInterfaces";
|
3
|
+
import { Material } from "@babylonjs/core/Materials/material.js";
|
4
|
+
/** @hidden */
|
5
|
+
export declare class GLTFMaterialsCommonExtension extends GLTFLoaderExtension {
|
6
|
+
constructor();
|
7
|
+
loadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime): boolean;
|
8
|
+
loadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): boolean;
|
9
|
+
private _loadTexture;
|
10
|
+
}
|