@babylonjs/loaders 5.0.0-rc.1 → 5.0.0-rc.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (174) hide show
  1. package/OBJ/index.d.ts +4 -4
  2. package/OBJ/index.js +4 -4
  3. package/OBJ/index.js.map +1 -1
  4. package/OBJ/mtlFileLoader.d.ts +41 -40
  5. package/OBJ/mtlFileLoader.js +232 -231
  6. package/OBJ/mtlFileLoader.js.map +1 -1
  7. package/OBJ/objFileLoader.d.ts +126 -133
  8. package/OBJ/objFileLoader.js +296 -300
  9. package/OBJ/objFileLoader.js.map +1 -1
  10. package/OBJ/objLoadingOptions.d.ts +43 -43
  11. package/OBJ/objLoadingOptions.js +1 -1
  12. package/OBJ/objLoadingOptions.js.map +1 -1
  13. package/OBJ/solidParser.d.ts +154 -153
  14. package/OBJ/solidParser.js +693 -699
  15. package/OBJ/solidParser.js.map +1 -1
  16. package/STL/index.d.ts +1 -1
  17. package/STL/index.js +1 -1
  18. package/STL/index.js.map +1 -1
  19. package/STL/stlFileLoader.d.ts +64 -71
  20. package/STL/stlFileLoader.js +233 -239
  21. package/STL/stlFileLoader.js.map +1 -1
  22. package/glTF/1.0/glTFBinaryExtension.d.ts +13 -13
  23. package/glTF/1.0/glTFBinaryExtension.js +60 -61
  24. package/glTF/1.0/glTFBinaryExtension.js.map +1 -1
  25. package/glTF/1.0/glTFLoader.d.ts +136 -106
  26. package/glTF/1.0/glTFLoader.js +1814 -1696
  27. package/glTF/1.0/glTFLoader.js.map +1 -1
  28. package/glTF/1.0/glTFLoaderInterfaces.d.ts +412 -412
  29. package/glTF/1.0/glTFLoaderInterfaces.js +95 -95
  30. package/glTF/1.0/glTFLoaderInterfaces.js.map +1 -1
  31. package/glTF/1.0/glTFLoaderUtils.d.ts +63 -62
  32. package/glTF/1.0/glTFLoaderUtils.js +250 -232
  33. package/glTF/1.0/glTFLoaderUtils.js.map +1 -1
  34. package/glTF/1.0/glTFMaterialsCommonExtension.d.ts +10 -10
  35. package/glTF/1.0/glTFMaterialsCommonExtension.js +129 -127
  36. package/glTF/1.0/glTFMaterialsCommonExtension.js.map +1 -1
  37. package/glTF/1.0/index.d.ts +5 -5
  38. package/glTF/1.0/index.js +5 -5
  39. package/glTF/1.0/index.js.map +1 -1
  40. package/glTF/2.0/Extensions/EXT_lights_image_based.d.ts +43 -36
  41. package/glTF/2.0/Extensions/EXT_lights_image_based.js +117 -110
  42. package/glTF/2.0/Extensions/EXT_lights_image_based.js.map +1 -1
  43. package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.d.ts +36 -28
  44. package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js +88 -80
  45. package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js.map +1 -1
  46. package/glTF/2.0/Extensions/EXT_meshopt_compression.d.ts +34 -27
  47. package/glTF/2.0/Extensions/EXT_meshopt_compression.js +49 -42
  48. package/glTF/2.0/Extensions/EXT_meshopt_compression.js.map +1 -1
  49. package/glTF/2.0/Extensions/EXT_texture_webp.d.ts +29 -21
  50. package/glTF/2.0/Extensions/EXT_texture_webp.js +40 -32
  51. package/glTF/2.0/Extensions/EXT_texture_webp.js.map +1 -1
  52. package/glTF/2.0/Extensions/ExtrasAsMetadata.d.ts +50 -32
  53. package/glTF/2.0/Extensions/ExtrasAsMetadata.js +73 -55
  54. package/glTF/2.0/Extensions/ExtrasAsMetadata.js.map +1 -1
  55. package/glTF/2.0/Extensions/KHR_draco_mesh_compression.d.ts +39 -31
  56. package/glTF/2.0/Extensions/KHR_draco_mesh_compression.js +112 -101
  57. package/glTF/2.0/Extensions/KHR_draco_mesh_compression.js.map +1 -1
  58. package/glTF/2.0/Extensions/KHR_lights_punctual.d.ts +36 -28
  59. package/glTF/2.0/Extensions/KHR_lights_punctual.js +89 -81
  60. package/glTF/2.0/Extensions/KHR_lights_punctual.js.map +1 -1
  61. package/glTF/2.0/Extensions/KHR_materials_clearcoat.d.ts +39 -31
  62. package/glTF/2.0/Extensions/KHR_materials_clearcoat.js +94 -86
  63. package/glTF/2.0/Extensions/KHR_materials_clearcoat.js.map +1 -1
  64. package/glTF/2.0/Extensions/KHR_materials_emissive_strength.d.ts +38 -30
  65. package/glTF/2.0/Extensions/KHR_materials_emissive_strength.js +53 -45
  66. package/glTF/2.0/Extensions/KHR_materials_emissive_strength.js.map +1 -1
  67. package/glTF/2.0/Extensions/KHR_materials_ior.d.ts +42 -34
  68. package/glTF/2.0/Extensions/KHR_materials_ior.js +62 -54
  69. package/glTF/2.0/Extensions/KHR_materials_ior.js.map +1 -1
  70. package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.d.ts +38 -30
  71. package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.js +80 -72
  72. package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.js.map +1 -1
  73. package/glTF/2.0/Extensions/KHR_materials_sheen.d.ts +39 -31
  74. package/glTF/2.0/Extensions/KHR_materials_sheen.js +84 -76
  75. package/glTF/2.0/Extensions/KHR_materials_sheen.js.map +1 -1
  76. package/glTF/2.0/Extensions/KHR_materials_specular.d.ts +38 -30
  77. package/glTF/2.0/Extensions/KHR_materials_specular.js +74 -66
  78. package/glTF/2.0/Extensions/KHR_materials_specular.js.map +1 -1
  79. package/glTF/2.0/Extensions/KHR_materials_translucency.d.ts +39 -31
  80. package/glTF/2.0/Extensions/KHR_materials_translucency.js +83 -76
  81. package/glTF/2.0/Extensions/KHR_materials_translucency.js.map +1 -1
  82. package/glTF/2.0/Extensions/KHR_materials_transmission.d.ts +38 -30
  83. package/glTF/2.0/Extensions/KHR_materials_transmission.js +288 -277
  84. package/glTF/2.0/Extensions/KHR_materials_transmission.js.map +1 -1
  85. package/glTF/2.0/Extensions/KHR_materials_unlit.d.ts +38 -30
  86. package/glTF/2.0/Extensions/KHR_materials_unlit.js +73 -65
  87. package/glTF/2.0/Extensions/KHR_materials_unlit.js.map +1 -1
  88. package/glTF/2.0/Extensions/KHR_materials_variants.d.ts +87 -76
  89. package/glTF/2.0/Extensions/KHR_materials_variants.js +254 -243
  90. package/glTF/2.0/Extensions/KHR_materials_variants.js.map +1 -1
  91. package/glTF/2.0/Extensions/KHR_materials_volume.d.ts +39 -31
  92. package/glTF/2.0/Extensions/KHR_materials_volume.js +85 -78
  93. package/glTF/2.0/Extensions/KHR_materials_volume.js.map +1 -1
  94. package/glTF/2.0/Extensions/KHR_mesh_quantization.d.ts +22 -19
  95. package/glTF/2.0/Extensions/KHR_mesh_quantization.js +23 -21
  96. package/glTF/2.0/Extensions/KHR_mesh_quantization.js.map +1 -1
  97. package/glTF/2.0/Extensions/KHR_texture_basisu.d.ts +29 -21
  98. package/glTF/2.0/Extensions/KHR_texture_basisu.js +40 -32
  99. package/glTF/2.0/Extensions/KHR_texture_basisu.js.map +1 -1
  100. package/glTF/2.0/Extensions/KHR_texture_transform.d.ts +33 -25
  101. package/glTF/2.0/Extensions/KHR_texture_transform.js +61 -53
  102. package/glTF/2.0/Extensions/KHR_texture_transform.js.map +1 -1
  103. package/glTF/2.0/Extensions/KHR_xmp_json_ld.d.ts +32 -29
  104. package/glTF/2.0/Extensions/KHR_xmp_json_ld.js +49 -46
  105. package/glTF/2.0/Extensions/KHR_xmp_json_ld.js.map +1 -1
  106. package/glTF/2.0/Extensions/MSFT_audio_emitter.d.ts +54 -38
  107. package/glTF/2.0/Extensions/MSFT_audio_emitter.js +240 -216
  108. package/glTF/2.0/Extensions/MSFT_audio_emitter.js.map +1 -1
  109. package/glTF/2.0/Extensions/MSFT_lod.d.ts +109 -75
  110. package/glTF/2.0/Extensions/MSFT_lod.js +369 -333
  111. package/glTF/2.0/Extensions/MSFT_lod.js.map +1 -1
  112. package/glTF/2.0/Extensions/MSFT_minecraftMesh.d.ts +14 -14
  113. package/glTF/2.0/Extensions/MSFT_minecraftMesh.js +36 -36
  114. package/glTF/2.0/Extensions/MSFT_minecraftMesh.js.map +1 -1
  115. package/glTF/2.0/Extensions/MSFT_sRGBFactors.d.ts +14 -14
  116. package/glTF/2.0/Extensions/MSFT_sRGBFactors.js +36 -36
  117. package/glTF/2.0/Extensions/MSFT_sRGBFactors.js.map +1 -1
  118. package/glTF/2.0/Extensions/index.d.ts +26 -26
  119. package/glTF/2.0/Extensions/index.js +26 -26
  120. package/glTF/2.0/Extensions/index.js.map +1 -1
  121. package/glTF/2.0/glTFLoader.d.ts +406 -357
  122. package/glTF/2.0/glTFLoader.js +2366 -2266
  123. package/glTF/2.0/glTFLoader.js.map +1 -1
  124. package/glTF/2.0/glTFLoaderExtension.d.ts +152 -152
  125. package/glTF/2.0/glTFLoaderExtension.js +1 -1
  126. package/glTF/2.0/glTFLoaderExtension.js.map +1 -1
  127. package/glTF/2.0/glTFLoaderInterfaces.d.ts +211 -209
  128. package/glTF/2.0/glTFLoaderInterfaces.js +1 -1
  129. package/glTF/2.0/glTFLoaderInterfaces.js.map +1 -1
  130. package/glTF/2.0/index.d.ts +4 -4
  131. package/glTF/2.0/index.js +5 -4
  132. package/glTF/2.0/index.js.map +1 -1
  133. package/glTF/glTFFileLoader.d.ts +433 -373
  134. package/glTF/glTFFileLoader.js +927 -870
  135. package/glTF/glTFFileLoader.js.map +1 -1
  136. package/glTF/glTFValidation.d.ts +29 -29
  137. package/glTF/glTFValidation.js +123 -121
  138. package/glTF/glTFValidation.js.map +1 -1
  139. package/glTF/index.d.ts +5 -5
  140. package/glTF/index.js +6 -5
  141. package/glTF/index.js.map +1 -1
  142. package/index.d.ts +3 -3
  143. package/index.js +4 -3
  144. package/index.js.map +1 -1
  145. package/legacy/legacy-glTF.d.ts +2 -2
  146. package/legacy/legacy-glTF.js +18 -18
  147. package/legacy/legacy-glTF.js.map +1 -1
  148. package/legacy/legacy-glTF1.d.ts +2 -2
  149. package/legacy/legacy-glTF1.js +15 -14
  150. package/legacy/legacy-glTF1.js.map +1 -1
  151. package/legacy/legacy-glTF1FileLoader.d.ts +2 -2
  152. package/legacy/legacy-glTF1FileLoader.js +3 -2
  153. package/legacy/legacy-glTF1FileLoader.js.map +1 -1
  154. package/legacy/legacy-glTF2.d.ts +2 -2
  155. package/legacy/legacy-glTF2.js +33 -32
  156. package/legacy/legacy-glTF2.js.map +1 -1
  157. package/legacy/legacy-glTF2FileLoader.d.ts +2 -2
  158. package/legacy/legacy-glTF2FileLoader.js +3 -2
  159. package/legacy/legacy-glTF2FileLoader.js.map +1 -1
  160. package/legacy/legacy-glTFFileLoader.d.ts +3 -3
  161. package/legacy/legacy-glTFFileLoader.js +4 -3
  162. package/legacy/legacy-glTFFileLoader.js.map +1 -1
  163. package/legacy/legacy-objFileLoader.d.ts +1 -1
  164. package/legacy/legacy-objFileLoader.js +13 -12
  165. package/legacy/legacy-objFileLoader.js.map +1 -1
  166. package/legacy/legacy-stlFileLoader.d.ts +1 -1
  167. package/legacy/legacy-stlFileLoader.js +13 -12
  168. package/legacy/legacy-stlFileLoader.js.map +1 -1
  169. package/legacy/legacy.d.ts +6 -6
  170. package/legacy/legacy.js +8 -6
  171. package/legacy/legacy.js.map +1 -1
  172. package/license.md +71 -0
  173. package/package.json +37 -193
  174. package/readme.md +2 -2
@@ -1,233 +1,251 @@
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
- else {
61
- debugger;
62
- }
63
- if (mat) {
64
- switch (parameter.type) {
65
- case EParameterType.FLOAT_MAT2:
66
- shaderMaterial.setMatrix2x2(uniformName, Matrix.GetAsMatrix2x2(mat));
67
- break;
68
- case EParameterType.FLOAT_MAT3:
69
- shaderMaterial.setMatrix3x3(uniformName, Matrix.GetAsMatrix3x3(mat));
70
- break;
71
- case EParameterType.FLOAT_MAT4:
72
- shaderMaterial.setMatrix(uniformName, mat);
73
- break;
74
- default: break;
75
- }
76
- }
77
- };
78
- /**
79
- * Sets the given "parameter" matrix
80
- * @param shaderMaterial: the shader material
81
- * @param uniform: the name of the shader's uniform
82
- * @param value: the value of the uniform
83
- * @param type: the uniform's type (EParameterType FLOAT, VEC2, VEC3 or VEC4)
84
- */
85
- GLTFUtils.SetUniform = function (shaderMaterial, uniform, value, type) {
86
- switch (type) {
87
- case EParameterType.FLOAT:
88
- shaderMaterial.setFloat(uniform, value);
89
- return true;
90
- case EParameterType.FLOAT_VEC2:
91
- shaderMaterial.setVector2(uniform, Vector2.FromArray(value));
92
- return true;
93
- case EParameterType.FLOAT_VEC3:
94
- shaderMaterial.setVector3(uniform, Vector3.FromArray(value));
95
- return true;
96
- case EParameterType.FLOAT_VEC4:
97
- shaderMaterial.setVector4(uniform, Vector4.FromArray(value));
98
- return true;
99
- default: return false;
100
- }
101
- };
102
- /**
103
- * Returns the wrap mode of the texture
104
- * @param mode: the mode value
105
- */
106
- GLTFUtils.GetWrapMode = function (mode) {
107
- switch (mode) {
108
- case ETextureWrapMode.CLAMP_TO_EDGE: return Texture.CLAMP_ADDRESSMODE;
109
- case ETextureWrapMode.MIRRORED_REPEAT: return Texture.MIRROR_ADDRESSMODE;
110
- case ETextureWrapMode.REPEAT: return Texture.WRAP_ADDRESSMODE;
111
- default: return Texture.WRAP_ADDRESSMODE;
112
- }
113
- };
114
- /**
115
- * Returns the byte stride giving an accessor
116
- * @param accessor: the GLTF accessor objet
117
- */
118
- GLTFUtils.GetByteStrideFromType = function (accessor) {
119
- // Needs this function since "byteStride" isn't requiered in glTF format
120
- var type = accessor.type;
121
- switch (type) {
122
- case "VEC2": return 2;
123
- case "VEC3": return 3;
124
- case "VEC4": return 4;
125
- case "MAT2": return 4;
126
- case "MAT3": return 9;
127
- case "MAT4": return 16;
128
- default: return 1;
129
- }
130
- };
131
- /**
132
- * Returns the texture filter mode giving a mode value
133
- * @param mode: the filter mode value
134
- */
135
- GLTFUtils.GetTextureFilterMode = function (mode) {
136
- switch (mode) {
137
- case ETextureFilterType.LINEAR:
138
- case ETextureFilterType.LINEAR_MIPMAP_NEAREST:
139
- case ETextureFilterType.LINEAR_MIPMAP_LINEAR: return Texture.TRILINEAR_SAMPLINGMODE;
140
- case ETextureFilterType.NEAREST:
141
- case ETextureFilterType.NEAREST_MIPMAP_NEAREST: return Texture.NEAREST_SAMPLINGMODE;
142
- default: return Texture.BILINEAR_SAMPLINGMODE;
143
- }
144
- };
145
- GLTFUtils.GetBufferFromBufferView = function (gltfRuntime, bufferView, byteOffset, byteLength, componentType) {
146
- var byteOffset = bufferView.byteOffset + byteOffset;
147
- var loadedBufferView = gltfRuntime.loadedBufferViews[bufferView.buffer];
148
- if (byteOffset + byteLength > loadedBufferView.byteLength) {
149
- throw new Error("Buffer access is out of range");
150
- }
151
- var buffer = loadedBufferView.buffer;
152
- byteOffset += loadedBufferView.byteOffset;
153
- switch (componentType) {
154
- case EComponentType.BYTE: return new Int8Array(buffer, byteOffset, byteLength);
155
- case EComponentType.UNSIGNED_BYTE: return new Uint8Array(buffer, byteOffset, byteLength);
156
- case EComponentType.SHORT: return new Int16Array(buffer, byteOffset, byteLength);
157
- case EComponentType.UNSIGNED_SHORT: return new Uint16Array(buffer, byteOffset, byteLength);
158
- default: return new Float32Array(buffer, byteOffset, byteLength);
159
- }
160
- };
161
- /**
162
- * Returns a buffer from its accessor
163
- * @param gltfRuntime: the GLTF runtime
164
- * @param accessor: the GLTF accessor
165
- */
166
- GLTFUtils.GetBufferFromAccessor = function (gltfRuntime, accessor) {
167
- var bufferView = gltfRuntime.bufferViews[accessor.bufferView];
168
- var byteLength = accessor.count * GLTFUtils.GetByteStrideFromType(accessor);
169
- return GLTFUtils.GetBufferFromBufferView(gltfRuntime, bufferView, accessor.byteOffset, byteLength, accessor.componentType);
170
- };
171
- /**
172
- * Decodes a buffer view into a string
173
- * @param view: the buffer view
174
- */
175
- GLTFUtils.DecodeBufferToText = function (view) {
176
- var result = "";
177
- var length = view.byteLength;
178
- for (var i = 0; i < length; ++i) {
179
- result += String.fromCharCode(view[i]);
180
- }
181
- return result;
182
- };
183
- /**
184
- * Returns the default material of gltf. Related to
185
- * https://github.com/KhronosGroup/glTF/tree/master/specification/1.0#appendix-a-default-material
186
- * @param scene: the Babylon.js scene
187
- */
188
- GLTFUtils.GetDefaultMaterial = function (scene) {
189
- if (!GLTFUtils._DefaultMaterial) {
190
- Effect.ShadersStore["GLTFDefaultMaterialVertexShader"] = [
191
- "precision highp float;",
192
- "",
193
- "uniform mat4 worldView;",
194
- "uniform mat4 projection;",
195
- "",
196
- "attribute vec3 position;",
197
- "",
198
- "void main(void)",
199
- "{",
200
- " gl_Position = projection * worldView * vec4(position, 1.0);",
201
- "}"
202
- ].join("\n");
203
- Effect.ShadersStore["GLTFDefaultMaterialPixelShader"] = [
204
- "precision highp float;",
205
- "",
206
- "uniform vec4 u_emission;",
207
- "",
208
- "void main(void)",
209
- "{",
210
- " gl_FragColor = u_emission;",
211
- "}"
212
- ].join("\n");
213
- var shaderPath = {
214
- vertex: "GLTFDefaultMaterial",
215
- fragment: "GLTFDefaultMaterial"
216
- };
217
- var options = {
218
- attributes: ["position"],
219
- uniforms: ["worldView", "projection", "u_emission"],
220
- samplers: new Array(),
221
- needAlphaBlending: false
222
- };
223
- GLTFUtils._DefaultMaterial = new ShaderMaterial("GLTFDefaultMaterial", scene, shaderPath, options);
224
- GLTFUtils._DefaultMaterial.setColor4("u_emission", new Color4(0.5, 0.5, 0.5, 1.0));
225
- }
226
- return GLTFUtils._DefaultMaterial;
227
- };
228
- // The GLTF default material
229
- GLTFUtils._DefaultMaterial = null;
230
- return GLTFUtils;
231
- }());
232
- 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 };
233
251
  //# sourceMappingURL=glTFLoaderUtils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"glTFLoaderUtils.js","sourceRoot":"","sources":["../../../../sourceES6/loaders/src/glTF/1.0/glTFLoaderUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2B,cAAc,EAAE,gBAAgB,EAAiB,kBAAkB,EAAiC,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAGrL,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAC;AACtF,OAAO,EAAE,MAAM,EAAE,MAAM,kCAAkC,CAAC;AAC1D,OAAO,EAAE,MAAM,EAAE,MAAM,kCAAkC,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,0CAA0C,CAAC;AAC1E,OAAO,EAAE,OAAO,EAAE,MAAM,4CAA4C,CAAC;AAIrE;;;EAGE;AACF;IAAA;IAiOA,CAAC;IAhOG;;;;;;;OAOG;IACW,mBAAS,GAAvB,UAAwB,KAAY,EAAE,MAAY,EAAE,SAAkC,EAAE,WAAmB,EAAE,cAAuC;QAChJ,IAAI,G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B;gBACxB,EAAE;gBACF,yBAAyB;gBACzB,0BAA0B;gBAC1B,EAAE;gBACF,0BAA0B;gBAC1B,EAAE;gBACF,iBAAiB;gBACjB,GAAG;gBACH,iEAAiE;gBACjE,GAAG;aACN,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAEb,MAAM,CAAC,YAAY,CAAC,gCAAgC,CAAC,GAAG;gBACpD,wBAAwB;gBACxB,EAAE;gBACF,0BAA0B;gBAC1B,EAAE;gBACF,iBAAiB;gBACjB,GAAG;gBACH,gCAAgC;gBAChC,GAAG;aACN,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAEb,IAAI,UAAU,GAAG;gBACb,MAAM,EAAE,qBAAqB;gBAC7B,QAAQ,EAAE,qBAAqB;aAClC,CAAC;YAEF,IAAI,OAAO,GAAG;gBACV,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,AAjOD,IAiOC;SAjOY,SAAS","sourcesContent":["import { IGLTFTechniqueParameter, EParameterType, ETextureWrapMode, IGLTFAccessor, ETextureFilterType, IGLTFRuntime, IGLTFBufferView, EComponentType } from \"./glTFLoaderInterfaces\";\r\n\r\nimport { Nullable } from \"@babylonjs/core/types\";\r\nimport { Vector2, Vector3, Vector4, Matrix } from \"@babylonjs/core/Maths/math.vector\";\r\nimport { Color4 } from '@babylonjs/core/Maths/math.color';\r\nimport { Effect } from \"@babylonjs/core/Materials/effect\";\r\nimport { ShaderMaterial } from \"@babylonjs/core/Materials/shaderMaterial\";\r\nimport { Texture } from \"@babylonjs/core/Materials/Textures/texture\";\r\nimport { Node } from \"@babylonjs/core/node\";\r\nimport { Scene } from \"@babylonjs/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 var mat: Nullable<Matrix> = null;\r\n\r\n if (parameter.semantic === \"MODEL\") {\r\n mat = source.getWorldMatrix();\r\n }\r\n else if (parameter.semantic === \"PROJECTION\") {\r\n mat = scene.getProjectionMatrix();\r\n }\r\n else if (parameter.semantic === \"VIEW\") {\r\n mat = scene.getViewMatrix();\r\n }\r\n else if (parameter.semantic === \"MODELVIEWINVERSETRANSPOSE\") {\r\n mat = Matrix.Transpose(source.getWorldMatrix().multiply(scene.getViewMatrix()).invert());\r\n }\r\n else if (parameter.semantic === \"MODELVIEW\") {\r\n mat = source.getWorldMatrix().multiply(scene.getViewMatrix());\r\n }\r\n else if (parameter.semantic === \"MODELVIEWPROJECTION\") {\r\n mat = source.getWorldMatrix().multiply(scene.getTransformMatrix());\r\n }\r\n else if (parameter.semantic === \"MODELINVERSE\") {\r\n mat = source.getWorldMatrix().invert();\r\n }\r\n else if (parameter.semantic === \"VIEWINVERSE\") {\r\n mat = scene.getViewMatrix().invert();\r\n }\r\n else if (parameter.semantic === \"PROJECTIONINVERSE\") {\r\n mat = scene.getProjectionMatrix().invert();\r\n }\r\n else if (parameter.semantic === \"MODELVIEWINVERSE\") {\r\n mat = source.getWorldMatrix().multiply(scene.getViewMatrix()).invert();\r\n }\r\n else if (parameter.semantic === \"MODELVIEWPROJECTIONINVERSE\") {\r\n mat = source.getWorldMatrix().multiply(scene.getTransformMatrix()).invert();\r\n }\r\n else if (parameter.semantic === \"MODELINVERSETRANSPOSE\") {\r\n mat = Matrix.Transpose(source.getWorldMatrix().invert());\r\n }\r\n else {\r\n debugger;\r\n }\r\n\r\n if (mat) {\r\n switch (parameter.type) {\r\n case EParameterType.FLOAT_MAT2: shaderMaterial.setMatrix2x2(uniformName, Matrix.GetAsMatrix2x2(mat)); break;\r\n case EParameterType.FLOAT_MAT3: shaderMaterial.setMatrix3x3(uniformName, Matrix.GetAsMatrix3x3(mat)); break;\r\n case EParameterType.FLOAT_MAT4: shaderMaterial.setMatrix(uniformName, mat); break;\r\n default: 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: shaderMaterial.setFloat(uniform, value); return true;\r\n case EParameterType.FLOAT_VEC2: shaderMaterial.setVector2(uniform, Vector2.FromArray(value)); return true;\r\n case EParameterType.FLOAT_VEC3: shaderMaterial.setVector3(uniform, Vector3.FromArray(value)); return true;\r\n case EParameterType.FLOAT_VEC4: shaderMaterial.setVector4(uniform, Vector4.FromArray(value)); return true;\r\n default: 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: return Texture.CLAMP_ADDRESSMODE;\r\n case ETextureWrapMode.MIRRORED_REPEAT: return Texture.MIRROR_ADDRESSMODE;\r\n case ETextureWrapMode.REPEAT: return Texture.WRAP_ADDRESSMODE;\r\n default: 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 var type = accessor.type;\r\n\r\n switch (type) {\r\n case \"VEC2\": return 2;\r\n case \"VEC3\": return 3;\r\n case \"VEC4\": return 4;\r\n case \"MAT2\": return 4;\r\n case \"MAT3\": return 9;\r\n case \"MAT4\": return 16;\r\n default: 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: return Texture.TRILINEAR_SAMPLINGMODE;\r\n case ETextureFilterType.NEAREST:\r\n case ETextureFilterType.NEAREST_MIPMAP_NEAREST: return Texture.NEAREST_SAMPLINGMODE;\r\n default: return Texture.BILINEAR_SAMPLINGMODE;\r\n }\r\n }\r\n\r\n public static GetBufferFromBufferView(gltfRuntime: IGLTFRuntime, bufferView: IGLTFBufferView, byteOffset: number, byteLength: number, componentType: EComponentType): ArrayBufferView {\r\n var byteOffset = bufferView.byteOffset + byteOffset;\r\n\r\n var 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 var buffer = loadedBufferView.buffer;\r\n byteOffset += loadedBufferView.byteOffset;\r\n\r\n switch (componentType) {\r\n case EComponentType.BYTE: return new Int8Array(buffer, byteOffset, byteLength);\r\n case EComponentType.UNSIGNED_BYTE: return new Uint8Array(buffer, byteOffset, byteLength);\r\n case EComponentType.SHORT: return new Int16Array(buffer, byteOffset, byteLength);\r\n case EComponentType.UNSIGNED_SHORT: return new Uint16Array(buffer, byteOffset, byteLength);\r\n default: 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 var bufferView: IGLTFBufferView = gltfRuntime.bufferViews[accessor.bufferView];\r\n var 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 var result = \"\";\r\n var length = view.byteLength;\r\n\r\n for (var 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 var shaderPath = {\r\n vertex: \"GLTFDefaultMaterial\",\r\n fragment: \"GLTFDefaultMaterial\"\r\n };\r\n\r\n var 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}"]}
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,cAAu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,IAAI,CAAC,IAAI,CAAC,CAAC;YAEb,MAAM,CAAC,YAAY,CAAC,gCAAgC,CAAC,GAAG;gBACpD,wBAAwB;gBACxB,EAAE;gBACF,0BAA0B;gBAC1B,EAAE;gBACF,iBAAiB;gBACjB,GAAG;gBACH,gCAAgC;gBAChC,GAAG;aACN,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAEb,IAAM,UAAU,GAAG;gBACf,MAAM,EAAE,qBAAqB;gBAC7B,QAAQ,EAAE,qBAAqB;aAClC,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 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";
4
- /** @hidden */
5
- export declare class GLTFMaterialsCommonExtension extends GLTFLoaderExtension {
6
- constructor();
7
- loadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError: (message: string) => void): 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
+ }