@babylonjs/loaders 5.0.0-rc.6 → 5.0.0
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/mtlFileLoader.js.map +1 -1
- package/OBJ/objFileLoader.d.ts +126 -126
- package/OBJ/objFileLoader.js +296 -296
- package/OBJ/objFileLoader.js.map +1 -1
- package/OBJ/objLoadingOptions.d.ts +43 -43
- package/OBJ/objLoadingOptions.js +1 -1
- package/OBJ/objLoadingOptions.js.map +1 -1
- package/OBJ/solidParser.d.ts +154 -154
- package/OBJ/solidParser.js +693 -693
- package/OBJ/solidParser.js.map +1 -1
- 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/STL/stlFileLoader.js.map +1 -1
- package/glTF/1.0/glTFBinaryExtension.d.ts +13 -13
- package/glTF/1.0/glTFBinaryExtension.js +60 -60
- package/glTF/1.0/glTFBinaryExtension.js.map +1 -1
- package/glTF/1.0/glTFLoader.d.ts +136 -136
- package/glTF/1.0/glTFLoader.js +1814 -1815
- package/glTF/1.0/glTFLoader.js.map +1 -1
- package/glTF/1.0/glTFLoaderInterfaces.d.ts +412 -412
- package/glTF/1.0/glTFLoaderInterfaces.js +95 -95
- package/glTF/1.0/glTFLoaderInterfaces.js.map +1 -1
- package/glTF/1.0/glTFLoaderUtils.d.ts +63 -62
- package/glTF/1.0/glTFLoaderUtils.js +250 -250
- package/glTF/1.0/glTFLoaderUtils.js.map +1 -1
- package/glTF/1.0/glTFMaterialsCommonExtension.d.ts +10 -10
- package/glTF/1.0/glTFMaterialsCommonExtension.js +129 -129
- package/glTF/1.0/glTFMaterialsCommonExtension.js.map +1 -1
- 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_lights_image_based.js.map +1 -1
- 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_mesh_gpu_instancing.js.map +1 -1
- 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_meshopt_compression.js.map +1 -1
- 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/EXT_texture_webp.js.map +1 -1
- package/glTF/2.0/Extensions/ExtrasAsMetadata.d.ts +50 -50
- package/glTF/2.0/Extensions/ExtrasAsMetadata.js +73 -73
- package/glTF/2.0/Extensions/ExtrasAsMetadata.js.map +1 -1
- 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_draco_mesh_compression.js.map +1 -1
- 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_lights_punctual.js.map +1 -1
- 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_clearcoat.js.map +1 -1
- 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_emissive_strength.js.map +1 -1
- 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_ior.js.map +1 -1
- 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_pbrSpecularGlossiness.js.map +1 -1
- 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_sheen.js.map +1 -1
- 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_specular.js.map +1 -1
- 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_translucency.js.map +1 -1
- 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_transmission.js.map +1 -1
- 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_unlit.js.map +1 -1
- 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_variants.js.map +1 -1
- 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_materials_volume.js.map +1 -1
- 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_mesh_quantization.js.map +1 -1
- 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_basisu.js.map +1 -1
- 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_texture_transform.js.map +1 -1
- 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/KHR_xmp_json_ld.js.map +1 -1
- 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_audio_emitter.js.map +1 -1
- 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_lod.js.map +1 -1
- 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_minecraftMesh.js.map +1 -1
- 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/MSFT_sRGBFactors.js.map +1 -1
- 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 +406 -405
- package/glTF/2.0/glTFLoader.js +2366 -2366
- package/glTF/2.0/glTFLoader.js.map +1 -1
- package/glTF/2.0/glTFLoaderExtension.d.ts +152 -152
- package/glTF/2.0/glTFLoaderExtension.js +1 -1
- package/glTF/2.0/glTFLoaderExtension.js.map +1 -1
- package/glTF/2.0/glTFLoaderInterfaces.d.ts +211 -211
- package/glTF/2.0/glTFLoaderInterfaces.js +1 -1
- package/glTF/2.0/glTFLoaderInterfaces.js.map +1 -1
- package/glTF/2.0/index.d.ts +4 -4
- package/glTF/2.0/index.js +5 -4
- package/glTF/2.0/index.js.map +1 -1
- package/glTF/glTFFileLoader.d.ts +433 -433
- package/glTF/glTFFileLoader.js +927 -927
- package/glTF/glTFFileLoader.js.map +1 -1
- package/glTF/glTFValidation.d.ts +29 -29
- package/glTF/glTFValidation.js +123 -123
- package/glTF/glTFValidation.js.map +1 -1
- package/glTF/index.d.ts +5 -5
- package/glTF/index.js +6 -5
- package/glTF/index.js.map +1 -1
- package/index.d.ts +3 -3
- package/index.js +4 -3
- package/index.js.map +1 -1
- package/legacy/legacy-glTF.d.ts +2 -2
- package/legacy/legacy-glTF.js +18 -18
- package/legacy/legacy-glTF.js.map +1 -1
- package/legacy/legacy-glTF1.d.ts +2 -2
- package/legacy/legacy-glTF1.js +15 -14
- package/legacy/legacy-glTF1.js.map +1 -1
- package/legacy/legacy-glTF1FileLoader.d.ts +2 -2
- package/legacy/legacy-glTF1FileLoader.js +3 -3
- package/legacy/legacy-glTF1FileLoader.js.map +1 -1
- package/legacy/legacy-glTF2.d.ts +2 -2
- package/legacy/legacy-glTF2.js +33 -32
- package/legacy/legacy-glTF2.js.map +1 -1
- package/legacy/legacy-glTF2FileLoader.d.ts +2 -2
- package/legacy/legacy-glTF2FileLoader.js +3 -3
- package/legacy/legacy-glTF2FileLoader.js.map +1 -1
- package/legacy/legacy-glTFFileLoader.d.ts +3 -3
- package/legacy/legacy-glTFFileLoader.js +4 -4
- package/legacy/legacy-glTFFileLoader.js.map +1 -1
- package/legacy/legacy-objFileLoader.d.ts +1 -1
- package/legacy/legacy-objFileLoader.js +13 -12
- package/legacy/legacy-objFileLoader.js.map +1 -1
- package/legacy/legacy-stlFileLoader.d.ts +1 -1
- package/legacy/legacy-stlFileLoader.js +13 -12
- package/legacy/legacy-stlFileLoader.js.map +1 -1
- package/legacy/legacy.d.ts +6 -6
- package/legacy/legacy.js +8 -7
- package/legacy/legacy.js.map +1 -1
- package/license.md +71 -0
- package/package.json +25 -6
@@ -1,251 +1,251 @@
|
|
1
|
-
import { EParameterType, ETextureWrapMode, ETextureFilterType, EComponentType
|
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.js";
|
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 +1 @@
|
|
1
|
-
{"version":3,"file":"glTFLoaderUtils.js","sourceRoot":"","sources":["../../../../../../lts/loaders/generated/glTF/1.0/glTFLoaderUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAEH,cAAc,EACd,gBAAgB,EAEhB,kBAAkB,EAGlB,cAAc,GACjB,MAAM,wBAAwB,CAAC;AAGhC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,6CAA+B;AAC3E,OAAO,EAAE,MAAM,EAAE,4CAA8B;AAC/C,OAAO,EAAE,MAAM,EAAE,4CAA8B;AAC/C,OAAO,EAAE,cAAc,EAAE,oDAAsC;AAC/D,OAAO,EAAE,OAAO,EAAE,sDAAwC;AAI1D;;;GAGG;AACH;IAAA;IA4PA,CAAC;IA3PG;;;;;;;OAOG;IACW,mBAAS,GAAvB,UAAwB,KAAY,EAAE,MAAY,EAAE,SAAkC,EAAE,WAAmB,EAAE,cAAuC;QAChJ,IAAI,GAAG,GAAqB,IAAI,CAAC;QAEjC,IAAI,SAAS,CAAC,QAAQ,KAAK,OAAO,EAAE;YAChC,GAAG,GAAG,MAAM,CAAC,cAAc,EAAE,CAAC;SACjC;aAAM,IAAI,SAAS,CAAC,QAAQ,KAAK,YAAY,EAAE;YAC5C,GAAG,GAAG,KAAK,CAAC,mBAAmB,EAAE,CAAC;SACrC;aAAM,IAAI,SAAS,CAAC,QAAQ,KAAK,MAAM,EAAE;YACtC,GAAG,GAAG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ClC,CAAC;YAEF,IAAM,OAAO,GAAG;gBACZ,UAAU,EAAE,CAAC,UAAU,CAAC;gBACxB,QAAQ,EAAE,CAAC,WAAW,EAAE,YAAY,EAAE,YAAY,CAAC;gBACnD,QAAQ,EAAE,IAAI,KAAK,EAAU;gBAC7B,iBAAiB,EAAE,KAAK;aAC3B,CAAC;YAEF,SAAS,CAAC,gBAAgB,GAAG,IAAI,cAAc,CAAC,qBAAqB,EAAE,KAAK,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;YACnG,SAAS,CAAC,gBAAgB,CAAC,SAAS,CAAC,YAAY,EAAE,IAAI,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;SACtF;QAED,OAAO,SAAS,CAAC,gBAAgB,CAAC;IACtC,CAAC;IAED,4BAA4B;IACb,0BAAgB,GAA6B,IAAI,CAAC;IACrE,gBAAC;CAAA,AA5PD,IA4PC;SA5PY,SAAS","sourcesContent":["import {\r\n IGLTFTechniqueParameter,\r\n EParameterType,\r\n ETextureWrapMode,\r\n IGLTFAccessor,\r\n ETextureFilterType,\r\n IGLTFRuntime,\r\n IGLTFBufferView,\r\n EComponentType,\r\n} from \"./glTFLoaderInterfaces\";\r\n\r\nimport { Nullable } from \"core/types\";\r\nimport { Vector2, Vector3, Vector4, Matrix } from \"core/Maths/math.vector\";\r\nimport { Color4 } from \"core/Maths/math.color\";\r\nimport { Effect } from \"core/Materials/effect\";\r\nimport { ShaderMaterial } from \"core/Materials/shaderMaterial\";\r\nimport { Texture } from \"core/Materials/Textures/texture\";\r\nimport { Node } from \"core/node\";\r\nimport { Scene } from \"core/scene\";\r\n\r\n/**\r\n * Utils functions for GLTF\r\n * @hidden\r\n */\r\nexport class GLTFUtils {\r\n /**\r\n * Sets the given \"parameter\" matrix\r\n * @param scene the Scene object\r\n * @param source the source node where to pick the matrix\r\n * @param parameter the GLTF technique parameter\r\n * @param uniformName the name of the shader's uniform\r\n * @param shaderMaterial the shader material\r\n */\r\n public static SetMatrix(scene: Scene, source: Node, parameter: IGLTFTechniqueParameter, uniformName: string, shaderMaterial: ShaderMaterial | Effect): void {\r\n let mat: Nullable<Matrix> = null;\r\n\r\n if (parameter.semantic === \"MODEL\") {\r\n mat = source.getWorldMatrix();\r\n } else if (parameter.semantic === \"PROJECTION\") {\r\n mat = scene.getProjectionMatrix();\r\n } else if (parameter.semantic === \"VIEW\") {\r\n mat = scene.getViewMatrix();\r\n } else if (parameter.semantic === \"MODELVIEWINVERSETRANSPOSE\") {\r\n mat = Matrix.Transpose(source.getWorldMatrix().multiply(scene.getViewMatrix()).invert());\r\n } else if (parameter.semantic === \"MODELVIEW\") {\r\n mat = source.getWorldMatrix().multiply(scene.getViewMatrix());\r\n } else if (parameter.semantic === \"MODELVIEWPROJECTION\") {\r\n mat = source.getWorldMatrix().multiply(scene.getTransformMatrix());\r\n } else if (parameter.semantic === \"MODELINVERSE\") {\r\n mat = source.getWorldMatrix().invert();\r\n } else if (parameter.semantic === \"VIEWINVERSE\") {\r\n mat = scene.getViewMatrix().invert();\r\n } else if (parameter.semantic === \"PROJECTIONINVERSE\") {\r\n mat = scene.getProjectionMatrix().invert();\r\n } else if (parameter.semantic === \"MODELVIEWINVERSE\") {\r\n mat = source.getWorldMatrix().multiply(scene.getViewMatrix()).invert();\r\n } else if (parameter.semantic === \"MODELVIEWPROJECTIONINVERSE\") {\r\n mat = source.getWorldMatrix().multiply(scene.getTransformMatrix()).invert();\r\n } else if (parameter.semantic === \"MODELINVERSETRANSPOSE\") {\r\n mat = Matrix.Transpose(source.getWorldMatrix().invert());\r\n }\r\n\r\n if (mat) {\r\n switch (parameter.type) {\r\n case EParameterType.FLOAT_MAT2:\r\n shaderMaterial.setMatrix2x2(uniformName, Matrix.GetAsMatrix2x2(mat));\r\n break;\r\n case EParameterType.FLOAT_MAT3:\r\n shaderMaterial.setMatrix3x3(uniformName, Matrix.GetAsMatrix3x3(mat));\r\n break;\r\n case EParameterType.FLOAT_MAT4:\r\n shaderMaterial.setMatrix(uniformName, mat);\r\n break;\r\n default:\r\n break;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Sets the given \"parameter\" matrix\r\n * @param shaderMaterial the shader material\r\n * @param uniform the name of the shader's uniform\r\n * @param value the value of the uniform\r\n * @param type the uniform's type (EParameterType FLOAT, VEC2, VEC3 or VEC4)\r\n */\r\n public static SetUniform(shaderMaterial: ShaderMaterial | Effect, uniform: string, value: any, type: number): boolean {\r\n switch (type) {\r\n case EParameterType.FLOAT:\r\n shaderMaterial.setFloat(uniform, value);\r\n return true;\r\n case EParameterType.FLOAT_VEC2:\r\n shaderMaterial.setVector2(uniform, Vector2.FromArray(value));\r\n return true;\r\n case EParameterType.FLOAT_VEC3:\r\n shaderMaterial.setVector3(uniform, Vector3.FromArray(value));\r\n return true;\r\n case EParameterType.FLOAT_VEC4:\r\n shaderMaterial.setVector4(uniform, Vector4.FromArray(value));\r\n return true;\r\n default:\r\n return false;\r\n }\r\n }\r\n\r\n /**\r\n * Returns the wrap mode of the texture\r\n * @param mode the mode value\r\n */\r\n public static GetWrapMode(mode: number): number {\r\n switch (mode) {\r\n case ETextureWrapMode.CLAMP_TO_EDGE:\r\n return Texture.CLAMP_ADDRESSMODE;\r\n case ETextureWrapMode.MIRRORED_REPEAT:\r\n return Texture.MIRROR_ADDRESSMODE;\r\n case ETextureWrapMode.REPEAT:\r\n return Texture.WRAP_ADDRESSMODE;\r\n default:\r\n return Texture.WRAP_ADDRESSMODE;\r\n }\r\n }\r\n\r\n /**\r\n * Returns the byte stride giving an accessor\r\n * @param accessor the GLTF accessor objet\r\n */\r\n public static GetByteStrideFromType(accessor: IGLTFAccessor): number {\r\n // Needs this function since \"byteStride\" isn't requiered in glTF format\r\n const type = accessor.type;\r\n\r\n switch (type) {\r\n case \"VEC2\":\r\n return 2;\r\n case \"VEC3\":\r\n return 3;\r\n case \"VEC4\":\r\n return 4;\r\n case \"MAT2\":\r\n return 4;\r\n case \"MAT3\":\r\n return 9;\r\n case \"MAT4\":\r\n return 16;\r\n default:\r\n return 1;\r\n }\r\n }\r\n\r\n /**\r\n * Returns the texture filter mode giving a mode value\r\n * @param mode the filter mode value\r\n */\r\n public static GetTextureFilterMode(mode: number): ETextureFilterType {\r\n switch (mode) {\r\n case ETextureFilterType.LINEAR:\r\n case ETextureFilterType.LINEAR_MIPMAP_NEAREST:\r\n case ETextureFilterType.LINEAR_MIPMAP_LINEAR:\r\n return Texture.TRILINEAR_SAMPLINGMODE;\r\n case ETextureFilterType.NEAREST:\r\n case ETextureFilterType.NEAREST_MIPMAP_NEAREST:\r\n return Texture.NEAREST_SAMPLINGMODE;\r\n default:\r\n return Texture.BILINEAR_SAMPLINGMODE;\r\n }\r\n }\r\n\r\n public static GetBufferFromBufferView(\r\n gltfRuntime: IGLTFRuntime,\r\n bufferView: IGLTFBufferView,\r\n byteOffset: number,\r\n byteLength: number,\r\n componentType: EComponentType\r\n ): ArrayBufferView {\r\n byteOffset = bufferView.byteOffset + byteOffset;\r\n\r\n const loadedBufferView = gltfRuntime.loadedBufferViews[bufferView.buffer];\r\n if (byteOffset + byteLength > loadedBufferView.byteLength) {\r\n throw new Error(\"Buffer access is out of range\");\r\n }\r\n\r\n const buffer = loadedBufferView.buffer;\r\n byteOffset += loadedBufferView.byteOffset;\r\n\r\n switch (componentType) {\r\n case EComponentType.BYTE:\r\n return new Int8Array(buffer, byteOffset, byteLength);\r\n case EComponentType.UNSIGNED_BYTE:\r\n return new Uint8Array(buffer, byteOffset, byteLength);\r\n case EComponentType.SHORT:\r\n return new Int16Array(buffer, byteOffset, byteLength);\r\n case EComponentType.UNSIGNED_SHORT:\r\n return new Uint16Array(buffer, byteOffset, byteLength);\r\n default:\r\n return new Float32Array(buffer, byteOffset, byteLength);\r\n }\r\n }\r\n\r\n /**\r\n * Returns a buffer from its accessor\r\n * @param gltfRuntime the GLTF runtime\r\n * @param accessor the GLTF accessor\r\n */\r\n public static GetBufferFromAccessor(gltfRuntime: IGLTFRuntime, accessor: IGLTFAccessor): any {\r\n const bufferView: IGLTFBufferView = gltfRuntime.bufferViews[accessor.bufferView];\r\n const byteLength = accessor.count * GLTFUtils.GetByteStrideFromType(accessor);\r\n return GLTFUtils.GetBufferFromBufferView(gltfRuntime, bufferView, accessor.byteOffset, byteLength, accessor.componentType);\r\n }\r\n\r\n /**\r\n * Decodes a buffer view into a string\r\n * @param view the buffer view\r\n */\r\n public static DecodeBufferToText(view: ArrayBufferView): string {\r\n let result = \"\";\r\n const length = view.byteLength;\r\n\r\n for (let i = 0; i < length; ++i) {\r\n result += String.fromCharCode((<any>view)[i]);\r\n }\r\n\r\n return result;\r\n }\r\n\r\n /**\r\n * Returns the default material of gltf. Related to\r\n * https://github.com/KhronosGroup/glTF/tree/master/specification/1.0#appendix-a-default-material\r\n * @param scene the Babylon.js scene\r\n */\r\n public static GetDefaultMaterial(scene: Scene): ShaderMaterial {\r\n if (!GLTFUtils._DefaultMaterial) {\r\n Effect.ShadersStore[\"GLTFDefaultMaterialVertexShader\"] = [\r\n \"precision highp float;\",\r\n \"\",\r\n \"uniform mat4 worldView;\",\r\n \"uniform mat4 projection;\",\r\n \"\",\r\n \"attribute vec3 position;\",\r\n \"\",\r\n \"void main(void)\",\r\n \"{\",\r\n \" gl_Position = projection * worldView * vec4(position, 1.0);\",\r\n \"}\",\r\n ].join(\"\\n\");\r\n\r\n Effect.ShadersStore[\"GLTFDefaultMaterialPixelShader\"] = [\r\n \"precision highp float;\",\r\n \"\",\r\n \"uniform vec4 u_emission;\",\r\n \"\",\r\n \"void main(void)\",\r\n \"{\",\r\n \" gl_FragColor = u_emission;\",\r\n \"}\",\r\n ].join(\"\\n\");\r\n\r\n const shaderPath = {\r\n vertex: \"GLTFDefaultMaterial\",\r\n fragment: \"GLTFDefaultMaterial\",\r\n };\r\n\r\n const options = {\r\n attributes: [\"position\"],\r\n uniforms: [\"worldView\", \"projection\", \"u_emission\"],\r\n samplers: new Array<string>(),\r\n needAlphaBlending: false,\r\n };\r\n\r\n GLTFUtils._DefaultMaterial = new ShaderMaterial(\"GLTFDefaultMaterial\", scene, shaderPath, options);\r\n GLTFUtils._DefaultMaterial.setColor4(\"u_emission\", new Color4(0.5, 0.5, 0.5, 1.0));\r\n }\r\n\r\n return GLTFUtils._DefaultMaterial;\r\n }\r\n\r\n // The GLTF default material\r\n private static _DefaultMaterial: Nullable<ShaderMaterial> = null;\r\n}\r\n"]}
|
1
|
+
{"version":3,"file":"glTFLoaderUtils.js","sourceRoot":"","sources":["../../../../../../lts/loaders/generated/glTF/1.0/glTFLoaderUtils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAG9G,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,6CAA+B;AAC3E,OAAO,EAAE,MAAM,EAAE,4CAA8B;AAC/C,OAAO,EAAE,MAAM,EAAE,4CAA8B;AAC/C,OAAO,EAAE,cAAc,EAAE,oDAAsC;AAC/D,OAAO,EAAE,OAAO,EAAE,sDAAwC;AAI1D;;;GAGG;AACH;IAAA;IA4PA,CAAC;IA3PG;;;;;;;OAOG;IACW,mBAAS,GAAvB,UAAwB,KAAY,EAAE,MAAY,EAAE,SAAkC,EAAE,WAAmB,EAAE,cAAuC;QAChJ,IAAI,GAAG,GAAqB,IAAI,CAAC;QAEjC,IAAI,SAAS,CAAC,QAAQ,KAAK,OAAO,EAAE;YAChC,GAAG,GAAG,MAAM,CAAC,cAAc,EAAE,CAAC;SACjC;aAAM,IAAI,SAAS,CAAC,QAAQ,KAAK,YAAY,EAAE;YAC5C,GAAG,GAAG,KAAK,CAAC,mBAAmB,EAAE,CAAC;SACrC;aAAM,IAAI,SAAS,CAAC,QAAQ,KAAK,MAAM,EAAE;YACtC,GAAG,GAAG,KAAK,CAAC,aAAa,EAAE,CAAC;SAC/B;aAAM,IAAI,SAAS,CAAC,QAAQ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AC;gBACxB,QAAQ,EAAE,CAAC,WAAW,EAAE,YAAY,EAAE,YAAY,CAAC;gBACnD,QAAQ,EAAE,IAAI,KAAK,EAAU;gBAC7B,iBAAiB,EAAE,KAAK;aAC3B,CAAC;YAEF,SAAS,CAAC,gBAAgB,GAAG,IAAI,cAAc,CAAC,qBAAqB,EAAE,KAAK,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;YACnG,SAAS,CAAC,gBAAgB,CAAC,SAAS,CAAC,YAAY,EAAE,IAAI,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;SACtF;QAED,OAAO,SAAS,CAAC,gBAAgB,CAAC;IACtC,CAAC;IAED,4BAA4B;IACb,0BAAgB,GAA6B,IAAI,CAAC;IACrE,gBAAC;CAAA,AA5PD,IA4PC;SA5PY,SAAS","sourcesContent":["import type { IGLTFTechniqueParameter, IGLTFAccessor, IGLTFRuntime, IGLTFBufferView } from \"./glTFLoaderInterfaces\";\r\nimport { EParameterType, ETextureWrapMode, ETextureFilterType, EComponentType } from \"./glTFLoaderInterfaces\";\r\n\r\nimport type { Nullable } from \"core/types\";\r\nimport { Vector2, Vector3, Vector4, Matrix } from \"core/Maths/math.vector\";\r\nimport { Color4 } from \"core/Maths/math.color\";\r\nimport { Effect } from \"core/Materials/effect\";\r\nimport { ShaderMaterial } from \"core/Materials/shaderMaterial\";\r\nimport { Texture } from \"core/Materials/Textures/texture\";\r\nimport type { Node } from \"core/node\";\r\nimport type { Scene } from \"core/scene\";\r\n\r\n/**\r\n * Utils functions for GLTF\r\n * @hidden\r\n */\r\nexport class GLTFUtils {\r\n /**\r\n * Sets the given \"parameter\" matrix\r\n * @param scene the Scene object\r\n * @param source the source node where to pick the matrix\r\n * @param parameter the GLTF technique parameter\r\n * @param uniformName the name of the shader's uniform\r\n * @param shaderMaterial the shader material\r\n */\r\n public static SetMatrix(scene: Scene, source: Node, parameter: IGLTFTechniqueParameter, uniformName: string, shaderMaterial: ShaderMaterial | Effect): void {\r\n let mat: Nullable<Matrix> = null;\r\n\r\n if (parameter.semantic === \"MODEL\") {\r\n mat = source.getWorldMatrix();\r\n } else if (parameter.semantic === \"PROJECTION\") {\r\n mat = scene.getProjectionMatrix();\r\n } else if (parameter.semantic === \"VIEW\") {\r\n mat = scene.getViewMatrix();\r\n } else if (parameter.semantic === \"MODELVIEWINVERSETRANSPOSE\") {\r\n mat = Matrix.Transpose(source.getWorldMatrix().multiply(scene.getViewMatrix()).invert());\r\n } else if (parameter.semantic === \"MODELVIEW\") {\r\n mat = source.getWorldMatrix().multiply(scene.getViewMatrix());\r\n } else if (parameter.semantic === \"MODELVIEWPROJECTION\") {\r\n mat = source.getWorldMatrix().multiply(scene.getTransformMatrix());\r\n } else if (parameter.semantic === \"MODELINVERSE\") {\r\n mat = source.getWorldMatrix().invert();\r\n } else if (parameter.semantic === \"VIEWINVERSE\") {\r\n mat = scene.getViewMatrix().invert();\r\n } else if (parameter.semantic === \"PROJECTIONINVERSE\") {\r\n mat = scene.getProjectionMatrix().invert();\r\n } else if (parameter.semantic === \"MODELVIEWINVERSE\") {\r\n mat = source.getWorldMatrix().multiply(scene.getViewMatrix()).invert();\r\n } else if (parameter.semantic === \"MODELVIEWPROJECTIONINVERSE\") {\r\n mat = source.getWorldMatrix().multiply(scene.getTransformMatrix()).invert();\r\n } else if (parameter.semantic === \"MODELINVERSETRANSPOSE\") {\r\n mat = Matrix.Transpose(source.getWorldMatrix().invert());\r\n }\r\n\r\n if (mat) {\r\n switch (parameter.type) {\r\n case EParameterType.FLOAT_MAT2:\r\n shaderMaterial.setMatrix2x2(uniformName, Matrix.GetAsMatrix2x2(mat));\r\n break;\r\n case EParameterType.FLOAT_MAT3:\r\n shaderMaterial.setMatrix3x3(uniformName, Matrix.GetAsMatrix3x3(mat));\r\n break;\r\n case EParameterType.FLOAT_MAT4:\r\n shaderMaterial.setMatrix(uniformName, mat);\r\n break;\r\n default:\r\n break;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Sets the given \"parameter\" matrix\r\n * @param shaderMaterial the shader material\r\n * @param uniform the name of the shader's uniform\r\n * @param value the value of the uniform\r\n * @param type the uniform's type (EParameterType FLOAT, VEC2, VEC3 or VEC4)\r\n */\r\n public static SetUniform(shaderMaterial: ShaderMaterial | Effect, uniform: string, value: any, type: number): boolean {\r\n switch (type) {\r\n case EParameterType.FLOAT:\r\n shaderMaterial.setFloat(uniform, value);\r\n return true;\r\n case EParameterType.FLOAT_VEC2:\r\n shaderMaterial.setVector2(uniform, Vector2.FromArray(value));\r\n return true;\r\n case EParameterType.FLOAT_VEC3:\r\n shaderMaterial.setVector3(uniform, Vector3.FromArray(value));\r\n return true;\r\n case EParameterType.FLOAT_VEC4:\r\n shaderMaterial.setVector4(uniform, Vector4.FromArray(value));\r\n return true;\r\n default:\r\n return false;\r\n }\r\n }\r\n\r\n /**\r\n * Returns the wrap mode of the texture\r\n * @param mode the mode value\r\n */\r\n public static GetWrapMode(mode: number): number {\r\n switch (mode) {\r\n case ETextureWrapMode.CLAMP_TO_EDGE:\r\n return Texture.CLAMP_ADDRESSMODE;\r\n case ETextureWrapMode.MIRRORED_REPEAT:\r\n return Texture.MIRROR_ADDRESSMODE;\r\n case ETextureWrapMode.REPEAT:\r\n return Texture.WRAP_ADDRESSMODE;\r\n default:\r\n return Texture.WRAP_ADDRESSMODE;\r\n }\r\n }\r\n\r\n /**\r\n * Returns the byte stride giving an accessor\r\n * @param accessor the GLTF accessor objet\r\n */\r\n public static GetByteStrideFromType(accessor: IGLTFAccessor): number {\r\n // Needs this function since \"byteStride\" isn't requiered in glTF format\r\n const type = accessor.type;\r\n\r\n switch (type) {\r\n case \"VEC2\":\r\n return 2;\r\n case \"VEC3\":\r\n return 3;\r\n case \"VEC4\":\r\n return 4;\r\n case \"MAT2\":\r\n return 4;\r\n case \"MAT3\":\r\n return 9;\r\n case \"MAT4\":\r\n return 16;\r\n default:\r\n return 1;\r\n }\r\n }\r\n\r\n /**\r\n * Returns the texture filter mode giving a mode value\r\n * @param mode the filter mode value\r\n */\r\n public static GetTextureFilterMode(mode: number): ETextureFilterType {\r\n switch (mode) {\r\n case ETextureFilterType.LINEAR:\r\n case ETextureFilterType.LINEAR_MIPMAP_NEAREST:\r\n case ETextureFilterType.LINEAR_MIPMAP_LINEAR:\r\n return Texture.TRILINEAR_SAMPLINGMODE;\r\n case ETextureFilterType.NEAREST:\r\n case ETextureFilterType.NEAREST_MIPMAP_NEAREST:\r\n return Texture.NEAREST_SAMPLINGMODE;\r\n default:\r\n return Texture.BILINEAR_SAMPLINGMODE;\r\n }\r\n }\r\n\r\n public static GetBufferFromBufferView(\r\n gltfRuntime: IGLTFRuntime,\r\n bufferView: IGLTFBufferView,\r\n byteOffset: number,\r\n byteLength: number,\r\n componentType: EComponentType\r\n ): ArrayBufferView {\r\n byteOffset = bufferView.byteOffset + byteOffset;\r\n\r\n const loadedBufferView = gltfRuntime.loadedBufferViews[bufferView.buffer];\r\n if (byteOffset + byteLength > loadedBufferView.byteLength) {\r\n throw new Error(\"Buffer access is out of range\");\r\n }\r\n\r\n const buffer = loadedBufferView.buffer;\r\n byteOffset += loadedBufferView.byteOffset;\r\n\r\n switch (componentType) {\r\n case EComponentType.BYTE:\r\n return new Int8Array(buffer, byteOffset, byteLength);\r\n case EComponentType.UNSIGNED_BYTE:\r\n return new Uint8Array(buffer, byteOffset, byteLength);\r\n case EComponentType.SHORT:\r\n return new Int16Array(buffer, byteOffset, byteLength);\r\n case EComponentType.UNSIGNED_SHORT:\r\n return new Uint16Array(buffer, byteOffset, byteLength);\r\n default:\r\n return new Float32Array(buffer, byteOffset, byteLength);\r\n }\r\n }\r\n\r\n /**\r\n * Returns a buffer from its accessor\r\n * @param gltfRuntime the GLTF runtime\r\n * @param accessor the GLTF accessor\r\n */\r\n public static GetBufferFromAccessor(gltfRuntime: IGLTFRuntime, accessor: IGLTFAccessor): any {\r\n const bufferView: IGLTFBufferView = gltfRuntime.bufferViews[accessor.bufferView];\r\n const byteLength = accessor.count * GLTFUtils.GetByteStrideFromType(accessor);\r\n return GLTFUtils.GetBufferFromBufferView(gltfRuntime, bufferView, accessor.byteOffset, byteLength, accessor.componentType);\r\n }\r\n\r\n /**\r\n * Decodes a buffer view into a string\r\n * @param view the buffer view\r\n */\r\n public static DecodeBufferToText(view: ArrayBufferView): string {\r\n let result = \"\";\r\n const length = view.byteLength;\r\n\r\n for (let i = 0; i < length; ++i) {\r\n result += String.fromCharCode((<any>view)[i]);\r\n }\r\n\r\n return result;\r\n }\r\n\r\n /**\r\n * Returns the default material of gltf. Related to\r\n * https://github.com/KhronosGroup/glTF/tree/master/specification/1.0#appendix-a-default-material\r\n * @param scene the Babylon.js scene\r\n */\r\n public static GetDefaultMaterial(scene: Scene): ShaderMaterial {\r\n if (!GLTFUtils._DefaultMaterial) {\r\n Effect.ShadersStore[\"GLTFDefaultMaterialVertexShader\"] = [\r\n \"precision highp float;\",\r\n \"\",\r\n \"uniform mat4 worldView;\",\r\n \"uniform mat4 projection;\",\r\n \"\",\r\n \"attribute vec3 position;\",\r\n \"\",\r\n \"void main(void)\",\r\n \"{\",\r\n \" gl_Position = projection * worldView * vec4(position, 1.0);\",\r\n \"}\",\r\n ].join(\"\\n\");\r\n\r\n Effect.ShadersStore[\"GLTFDefaultMaterialPixelShader\"] = [\r\n \"precision highp float;\",\r\n \"\",\r\n \"uniform vec4 u_emission;\",\r\n \"\",\r\n \"void main(void)\",\r\n \"{\",\r\n \" gl_FragColor = u_emission;\",\r\n \"}\",\r\n ].join(\"\\n\");\r\n\r\n const shaderPath = {\r\n vertex: \"GLTFDefaultMaterial\",\r\n fragment: \"GLTFDefaultMaterial\",\r\n };\r\n\r\n const options = {\r\n attributes: [\"position\"],\r\n uniforms: [\"worldView\", \"projection\", \"u_emission\"],\r\n samplers: new Array<string>(),\r\n needAlphaBlending: false,\r\n };\r\n\r\n GLTFUtils._DefaultMaterial = new ShaderMaterial(\"GLTFDefaultMaterial\", scene, shaderPath, options);\r\n GLTFUtils._DefaultMaterial.setColor4(\"u_emission\", new Color4(0.5, 0.5, 0.5, 1.0));\r\n }\r\n\r\n return GLTFUtils._DefaultMaterial;\r\n }\r\n\r\n // The GLTF default material\r\n private static _DefaultMaterial: Nullable<ShaderMaterial> = null;\r\n}\r\n"]}
|
@@ -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 type { 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
|
+
}
|