@babylonjs/loaders 5.0.0-beta.8 → 5.0.0-beta.8-snapshot

Sign up to get free protection for your applications and to get access to all the features.
Files changed (172) hide show
  1. package/package.json +20 -198
  2. package/OBJ/index.d.ts +0 -4
  3. package/OBJ/index.js +0 -5
  4. package/OBJ/index.js.map +0 -1
  5. package/OBJ/mtlFileLoader.d.ts +0 -40
  6. package/OBJ/mtlFileLoader.js +0 -222
  7. package/OBJ/mtlFileLoader.js.map +0 -1
  8. package/OBJ/objFileLoader.d.ts +0 -133
  9. package/OBJ/objFileLoader.js +0 -301
  10. package/OBJ/objFileLoader.js.map +0 -1
  11. package/OBJ/objLoadingOptions.d.ts +0 -43
  12. package/OBJ/objLoadingOptions.js +0 -2
  13. package/OBJ/objLoadingOptions.js.map +0 -1
  14. package/OBJ/solidParser.d.ts +0 -153
  15. package/OBJ/solidParser.js +0 -700
  16. package/OBJ/solidParser.js.map +0 -1
  17. package/STL/index.d.ts +0 -1
  18. package/STL/index.js +0 -2
  19. package/STL/index.js.map +0 -1
  20. package/STL/stlFileLoader.d.ts +0 -71
  21. package/STL/stlFileLoader.js +0 -240
  22. package/STL/stlFileLoader.js.map +0 -1
  23. package/glTF/1.0/glTFBinaryExtension.d.ts +0 -13
  24. package/glTF/1.0/glTFBinaryExtension.js +0 -62
  25. package/glTF/1.0/glTFBinaryExtension.js.map +0 -1
  26. package/glTF/1.0/glTFLoader.d.ts +0 -106
  27. package/glTF/1.0/glTFLoader.js +0 -1697
  28. package/glTF/1.0/glTFLoader.js.map +0 -1
  29. package/glTF/1.0/glTFLoaderInterfaces.d.ts +0 -412
  30. package/glTF/1.0/glTFLoaderInterfaces.js +0 -96
  31. package/glTF/1.0/glTFLoaderInterfaces.js.map +0 -1
  32. package/glTF/1.0/glTFLoaderUtils.d.ts +0 -62
  33. package/glTF/1.0/glTFLoaderUtils.js +0 -233
  34. package/glTF/1.0/glTFLoaderUtils.js.map +0 -1
  35. package/glTF/1.0/glTFMaterialsCommonExtension.d.ts +0 -10
  36. package/glTF/1.0/glTFMaterialsCommonExtension.js +0 -128
  37. package/glTF/1.0/glTFMaterialsCommonExtension.js.map +0 -1
  38. package/glTF/1.0/index.d.ts +0 -5
  39. package/glTF/1.0/index.js +0 -6
  40. package/glTF/1.0/index.js.map +0 -1
  41. package/glTF/2.0/Extensions/EXT_lights_image_based.d.ts +0 -36
  42. package/glTF/2.0/Extensions/EXT_lights_image_based.js +0 -111
  43. package/glTF/2.0/Extensions/EXT_lights_image_based.js.map +0 -1
  44. package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.d.ts +0 -27
  45. package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js +0 -80
  46. package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js.map +0 -1
  47. package/glTF/2.0/Extensions/EXT_meshopt_compression.d.ts +0 -27
  48. package/glTF/2.0/Extensions/EXT_meshopt_compression.js +0 -43
  49. package/glTF/2.0/Extensions/EXT_meshopt_compression.js.map +0 -1
  50. package/glTF/2.0/Extensions/EXT_texture_webp.d.ts +0 -21
  51. package/glTF/2.0/Extensions/EXT_texture_webp.js +0 -33
  52. package/glTF/2.0/Extensions/EXT_texture_webp.js.map +0 -1
  53. package/glTF/2.0/Extensions/ExtrasAsMetadata.d.ts +0 -32
  54. package/glTF/2.0/Extensions/ExtrasAsMetadata.js +0 -56
  55. package/glTF/2.0/Extensions/ExtrasAsMetadata.js.map +0 -1
  56. package/glTF/2.0/Extensions/KHR_draco_mesh_compression.d.ts +0 -31
  57. package/glTF/2.0/Extensions/KHR_draco_mesh_compression.js +0 -102
  58. package/glTF/2.0/Extensions/KHR_draco_mesh_compression.js.map +0 -1
  59. package/glTF/2.0/Extensions/KHR_lights_punctual.d.ts +0 -28
  60. package/glTF/2.0/Extensions/KHR_lights_punctual.js +0 -82
  61. package/glTF/2.0/Extensions/KHR_lights_punctual.js.map +0 -1
  62. package/glTF/2.0/Extensions/KHR_materials_clearcoat.d.ts +0 -31
  63. package/glTF/2.0/Extensions/KHR_materials_clearcoat.js +0 -87
  64. package/glTF/2.0/Extensions/KHR_materials_clearcoat.js.map +0 -1
  65. package/glTF/2.0/Extensions/KHR_materials_emissive_strength.d.ts +0 -30
  66. package/glTF/2.0/Extensions/KHR_materials_emissive_strength.js +0 -46
  67. package/glTF/2.0/Extensions/KHR_materials_emissive_strength.js.map +0 -1
  68. package/glTF/2.0/Extensions/KHR_materials_ior.d.ts +0 -34
  69. package/glTF/2.0/Extensions/KHR_materials_ior.js +0 -55
  70. package/glTF/2.0/Extensions/KHR_materials_ior.js.map +0 -1
  71. package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.d.ts +0 -30
  72. package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.js +0 -73
  73. package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.js.map +0 -1
  74. package/glTF/2.0/Extensions/KHR_materials_sheen.d.ts +0 -31
  75. package/glTF/2.0/Extensions/KHR_materials_sheen.js +0 -77
  76. package/glTF/2.0/Extensions/KHR_materials_sheen.js.map +0 -1
  77. package/glTF/2.0/Extensions/KHR_materials_specular.d.ts +0 -30
  78. package/glTF/2.0/Extensions/KHR_materials_specular.js +0 -67
  79. package/glTF/2.0/Extensions/KHR_materials_specular.js.map +0 -1
  80. package/glTF/2.0/Extensions/KHR_materials_translucency.d.ts +0 -31
  81. package/glTF/2.0/Extensions/KHR_materials_translucency.js +0 -77
  82. package/glTF/2.0/Extensions/KHR_materials_translucency.js.map +0 -1
  83. package/glTF/2.0/Extensions/KHR_materials_transmission.d.ts +0 -30
  84. package/glTF/2.0/Extensions/KHR_materials_transmission.js +0 -278
  85. package/glTF/2.0/Extensions/KHR_materials_transmission.js.map +0 -1
  86. package/glTF/2.0/Extensions/KHR_materials_unlit.d.ts +0 -30
  87. package/glTF/2.0/Extensions/KHR_materials_unlit.js +0 -66
  88. package/glTF/2.0/Extensions/KHR_materials_unlit.js.map +0 -1
  89. package/glTF/2.0/Extensions/KHR_materials_variants.d.ts +0 -76
  90. package/glTF/2.0/Extensions/KHR_materials_variants.js +0 -244
  91. package/glTF/2.0/Extensions/KHR_materials_variants.js.map +0 -1
  92. package/glTF/2.0/Extensions/KHR_materials_volume.d.ts +0 -31
  93. package/glTF/2.0/Extensions/KHR_materials_volume.js +0 -79
  94. package/glTF/2.0/Extensions/KHR_materials_volume.js.map +0 -1
  95. package/glTF/2.0/Extensions/KHR_mesh_quantization.d.ts +0 -19
  96. package/glTF/2.0/Extensions/KHR_mesh_quantization.js +0 -22
  97. package/glTF/2.0/Extensions/KHR_mesh_quantization.js.map +0 -1
  98. package/glTF/2.0/Extensions/KHR_texture_basisu.d.ts +0 -21
  99. package/glTF/2.0/Extensions/KHR_texture_basisu.js +0 -33
  100. package/glTF/2.0/Extensions/KHR_texture_basisu.js.map +0 -1
  101. package/glTF/2.0/Extensions/KHR_texture_transform.d.ts +0 -25
  102. package/glTF/2.0/Extensions/KHR_texture_transform.js +0 -54
  103. package/glTF/2.0/Extensions/KHR_texture_transform.js.map +0 -1
  104. package/glTF/2.0/Extensions/KHR_xmp_json_ld.d.ts +0 -29
  105. package/glTF/2.0/Extensions/KHR_xmp_json_ld.js +0 -47
  106. package/glTF/2.0/Extensions/KHR_xmp_json_ld.js.map +0 -1
  107. package/glTF/2.0/Extensions/MSFT_audio_emitter.d.ts +0 -38
  108. package/glTF/2.0/Extensions/MSFT_audio_emitter.js +0 -217
  109. package/glTF/2.0/Extensions/MSFT_audio_emitter.js.map +0 -1
  110. package/glTF/2.0/Extensions/MSFT_lod.d.ts +0 -75
  111. package/glTF/2.0/Extensions/MSFT_lod.js +0 -334
  112. package/glTF/2.0/Extensions/MSFT_lod.js.map +0 -1
  113. package/glTF/2.0/Extensions/MSFT_minecraftMesh.d.ts +0 -14
  114. package/glTF/2.0/Extensions/MSFT_minecraftMesh.js +0 -37
  115. package/glTF/2.0/Extensions/MSFT_minecraftMesh.js.map +0 -1
  116. package/glTF/2.0/Extensions/MSFT_sRGBFactors.d.ts +0 -14
  117. package/glTF/2.0/Extensions/MSFT_sRGBFactors.js +0 -37
  118. package/glTF/2.0/Extensions/MSFT_sRGBFactors.js.map +0 -1
  119. package/glTF/2.0/Extensions/index.d.ts +0 -26
  120. package/glTF/2.0/Extensions/index.js +0 -27
  121. package/glTF/2.0/Extensions/index.js.map +0 -1
  122. package/glTF/2.0/glTFLoader.d.ts +0 -357
  123. package/glTF/2.0/glTFLoader.js +0 -2249
  124. package/glTF/2.0/glTFLoader.js.map +0 -1
  125. package/glTF/2.0/glTFLoaderExtension.d.ts +0 -152
  126. package/glTF/2.0/glTFLoaderExtension.js +0 -2
  127. package/glTF/2.0/glTFLoaderExtension.js.map +0 -1
  128. package/glTF/2.0/glTFLoaderInterfaces.d.ts +0 -209
  129. package/glTF/2.0/glTFLoaderInterfaces.js +0 -2
  130. package/glTF/2.0/glTFLoaderInterfaces.js.map +0 -1
  131. package/glTF/2.0/index.d.ts +0 -4
  132. package/glTF/2.0/index.js +0 -5
  133. package/glTF/2.0/index.js.map +0 -1
  134. package/glTF/glTFFileLoader.d.ts +0 -368
  135. package/glTF/glTFFileLoader.js +0 -869
  136. package/glTF/glTFFileLoader.js.map +0 -1
  137. package/glTF/glTFValidation.d.ts +0 -29
  138. package/glTF/glTFValidation.js +0 -122
  139. package/glTF/glTFValidation.js.map +0 -1
  140. package/glTF/index.d.ts +0 -5
  141. package/glTF/index.js +0 -6
  142. package/glTF/index.js.map +0 -1
  143. package/index.d.ts +0 -3
  144. package/index.js.map +0 -1
  145. package/legacy/legacy-glTF.d.ts +0 -2
  146. package/legacy/legacy-glTF.js +0 -19
  147. package/legacy/legacy-glTF.js.map +0 -1
  148. package/legacy/legacy-glTF1.d.ts +0 -2
  149. package/legacy/legacy-glTF1.js +0 -15
  150. package/legacy/legacy-glTF1.js.map +0 -1
  151. package/legacy/legacy-glTF1FileLoader.d.ts +0 -2
  152. package/legacy/legacy-glTF1FileLoader.js +0 -3
  153. package/legacy/legacy-glTF1FileLoader.js.map +0 -1
  154. package/legacy/legacy-glTF2.d.ts +0 -2
  155. package/legacy/legacy-glTF2.js +0 -33
  156. package/legacy/legacy-glTF2.js.map +0 -1
  157. package/legacy/legacy-glTF2FileLoader.d.ts +0 -2
  158. package/legacy/legacy-glTF2FileLoader.js +0 -3
  159. package/legacy/legacy-glTF2FileLoader.js.map +0 -1
  160. package/legacy/legacy-glTFFileLoader.d.ts +0 -3
  161. package/legacy/legacy-glTFFileLoader.js +0 -4
  162. package/legacy/legacy-glTFFileLoader.js.map +0 -1
  163. package/legacy/legacy-objFileLoader.d.ts +0 -1
  164. package/legacy/legacy-objFileLoader.js +0 -13
  165. package/legacy/legacy-objFileLoader.js.map +0 -1
  166. package/legacy/legacy-stlFileLoader.d.ts +0 -1
  167. package/legacy/legacy-stlFileLoader.js +0 -13
  168. package/legacy/legacy-stlFileLoader.js.map +0 -1
  169. package/legacy/legacy.d.ts +0 -6
  170. package/legacy/legacy.js +0 -7
  171. package/legacy/legacy.js.map +0 -1
  172. package/readme.md +0 -24
@@ -1,233 +0,0 @@
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 };
233
- //# sourceMappingURL=glTFLoaderUtils.js.map
@@ -1 +0,0 @@
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,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AK,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,10 +0,0 @@
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,128 +0,0 @@
1
- import { __extends } from "tslib";
2
- import { GLTFLoaderExtension } from "./glTFLoader.js";
3
- import { GLTFLoaderBase } from "./glTFLoader.js";
4
- import { Vector3 } from "@babylonjs/core/Maths/math.vector.js";
5
- import { Color3 } from '@babylonjs/core/Maths/math.color.js';
6
- import { Tools } from "@babylonjs/core/Misc/tools.js";
7
- import { Material } from "@babylonjs/core/Materials/material.js";
8
- import { StandardMaterial } from "@babylonjs/core/Materials/standardMaterial.js";
9
- import { HemisphericLight } from "@babylonjs/core/Lights/hemisphericLight.js";
10
- import { DirectionalLight } from "@babylonjs/core/Lights/directionalLight.js";
11
- import { PointLight } from "@babylonjs/core/Lights/pointLight.js";
12
- import { SpotLight } from "@babylonjs/core/Lights/spotLight.js";
13
- import { GLTFLoader } from "./glTFLoader.js";
14
- /** @hidden */
15
- var GLTFMaterialsCommonExtension = /** @class */ (function (_super) {
16
- __extends(GLTFMaterialsCommonExtension, _super);
17
- function GLTFMaterialsCommonExtension() {
18
- return _super.call(this, "KHR_materials_common") || this;
19
- }
20
- GLTFMaterialsCommonExtension.prototype.loadRuntimeExtensionsAsync = function (gltfRuntime, onSuccess, onError) {
21
- if (!gltfRuntime.extensions) {
22
- return false;
23
- }
24
- var extension = gltfRuntime.extensions[this.name];
25
- if (!extension) {
26
- return false;
27
- }
28
- // Create lights
29
- var lights = extension.lights;
30
- if (lights) {
31
- for (var thing in lights) {
32
- var light = lights[thing];
33
- switch (light.type) {
34
- case "ambient":
35
- var ambientLight = new HemisphericLight(light.name, new Vector3(0, 1, 0), gltfRuntime.scene);
36
- var ambient = light.ambient;
37
- if (ambient) {
38
- ambientLight.diffuse = Color3.FromArray(ambient.color || [1, 1, 1]);
39
- }
40
- break;
41
- case "point":
42
- var pointLight = new PointLight(light.name, new Vector3(10, 10, 10), gltfRuntime.scene);
43
- var point = light.point;
44
- if (point) {
45
- pointLight.diffuse = Color3.FromArray(point.color || [1, 1, 1]);
46
- }
47
- break;
48
- case "directional":
49
- var dirLight = new DirectionalLight(light.name, new Vector3(0, -1, 0), gltfRuntime.scene);
50
- var directional = light.directional;
51
- if (directional) {
52
- dirLight.diffuse = Color3.FromArray(directional.color || [1, 1, 1]);
53
- }
54
- break;
55
- case "spot":
56
- var spot = light.spot;
57
- if (spot) {
58
- var spotLight = new SpotLight(light.name, new Vector3(0, 10, 0), new Vector3(0, -1, 0), spot.fallOffAngle || Math.PI, spot.fallOffExponent || 0.0, gltfRuntime.scene);
59
- spotLight.diffuse = Color3.FromArray(spot.color || [1, 1, 1]);
60
- }
61
- break;
62
- default:
63
- Tools.Warn("GLTF Material Common extension: light type \"" + light.type + "\” not supported");
64
- break;
65
- }
66
- }
67
- }
68
- return false;
69
- };
70
- GLTFMaterialsCommonExtension.prototype.loadMaterialAsync = function (gltfRuntime, id, onSuccess, onError) {
71
- var material = gltfRuntime.materials[id];
72
- if (!material || !material.extensions) {
73
- return false;
74
- }
75
- var extension = material.extensions[this.name];
76
- if (!extension) {
77
- return false;
78
- }
79
- var standardMaterial = new StandardMaterial(id, gltfRuntime.scene);
80
- standardMaterial.sideOrientation = Material.CounterClockWiseSideOrientation;
81
- if (extension.technique === "CONSTANT") {
82
- standardMaterial.disableLighting = true;
83
- }
84
- standardMaterial.backFaceCulling = extension.doubleSided === undefined ? false : !extension.doubleSided;
85
- standardMaterial.alpha = extension.values.transparency === undefined ? 1.0 : extension.values.transparency;
86
- standardMaterial.specularPower = extension.values.shininess === undefined ? 0.0 : extension.values.shininess;
87
- // Ambient
88
- if (typeof extension.values.ambient === "string") {
89
- this._loadTexture(gltfRuntime, extension.values.ambient, standardMaterial, "ambientTexture", onError);
90
- }
91
- else {
92
- standardMaterial.ambientColor = Color3.FromArray(extension.values.ambient || [0, 0, 0]);
93
- }
94
- // Diffuse
95
- if (typeof extension.values.diffuse === "string") {
96
- this._loadTexture(gltfRuntime, extension.values.diffuse, standardMaterial, "diffuseTexture", onError);
97
- }
98
- else {
99
- standardMaterial.diffuseColor = Color3.FromArray(extension.values.diffuse || [0, 0, 0]);
100
- }
101
- // Emission
102
- if (typeof extension.values.emission === "string") {
103
- this._loadTexture(gltfRuntime, extension.values.emission, standardMaterial, "emissiveTexture", onError);
104
- }
105
- else {
106
- standardMaterial.emissiveColor = Color3.FromArray(extension.values.emission || [0, 0, 0]);
107
- }
108
- // Specular
109
- if (typeof extension.values.specular === "string") {
110
- this._loadTexture(gltfRuntime, extension.values.specular, standardMaterial, "specularTexture", onError);
111
- }
112
- else {
113
- standardMaterial.specularColor = Color3.FromArray(extension.values.specular || [0, 0, 0]);
114
- }
115
- return true;
116
- };
117
- GLTFMaterialsCommonExtension.prototype._loadTexture = function (gltfRuntime, id, material, propertyPath, onError) {
118
- // Create buffer from texture url
119
- GLTFLoaderBase.LoadTextureBufferAsync(gltfRuntime, id, function (buffer) {
120
- // Create texture from buffer
121
- GLTFLoaderBase.CreateTextureAsync(gltfRuntime, id, buffer, function (texture) { return material[propertyPath] = texture; }, onError);
122
- }, onError);
123
- };
124
- return GLTFMaterialsCommonExtension;
125
- }(GLTFLoaderExtension));
126
- export { GLTFMaterialsCommonExtension };
127
- GLTFLoader.RegisterExtension(new GLTFMaterialsCommonExtension());
128
- //# sourceMappingURL=glTFMaterialsCommonExtension.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"glTFMaterialsCommonExtension.js","sourceRoot":"","sources":["../../../../sourceES6/loaders/src/glTF/1.0/glTFMaterialsCommonExtension.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACnD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IAAI,4BAA4B,EAAE,CAAC,CAAC","sourcesContent":["import { GLTFLoaderExtension } from \"./glTFLoader\";\nimport { GLTFLoaderBase } from \"./glTFLoader\";\n\nimport { IGLTFRuntime, IGLTFMaterial } from \"./glTFLoaderInterfaces\";\n\nimport { Vector3 } from \"@babylonjs/core/Maths/math.vector\";\nimport { Color3 } from '@babylonjs/core/Maths/math.color';\nimport { Tools } from \"@babylonjs/core/Misc/tools\";\nimport { Material } from \"@babylonjs/core/Materials/material\";\nimport { StandardMaterial } from \"@babylonjs/core/Materials/standardMaterial\";\nimport { HemisphericLight } from \"@babylonjs/core/Lights/hemisphericLight\";\nimport { DirectionalLight } from \"@babylonjs/core/Lights/directionalLight\";\nimport { PointLight } from \"@babylonjs/core/Lights/pointLight\";\nimport { SpotLight } from \"@babylonjs/core/Lights/spotLight\";\n\nimport { GLTFLoader } from \"./glTFLoader\";\n\ninterface IGLTFMaterialsCommonExtensionValues {\n ambient?: number[] | string;\n diffuse?: number[] | string;\n emission?: number[] | string;\n specular?: number[] | string;\n shininess?: number;\n transparency?: number;\n}\n\ninterface IGLTFMaterialsCommonExtension {\n technique: string;\n transparent?: number;\n doubleSided?: boolean;\n values: IGLTFMaterialsCommonExtensionValues;\n}\n\ninterface IGLTFRuntimeCommonExtension {\n lights: { [key: string]: IGLTFLightCommonExtension };\n}\n\ninterface IGLTFLightCommonExtension {\n name: string;\n type: string;\n\n ambient?: IGLTFAmbientLightCommonExtension;\n point?: IGLTFPointLightCommonExtension;\n directional?: IGLTFDirectionalLightCommonExtension;\n spot?: IGLTFSpotLightCommonExtension;\n}\n\ninterface IGLTFPointLightCommonExtension {\n color: number[];\n constantAttenuation: number;\n linearAttenuation: number;\n quadraticAttenuation: number;\n}\n\ninterface IGLTFAmbientLightCommonExtension {\n color: number[];\n}\n\ninterface IGLTFDirectionalLightCommonExtension {\n color: number[];\n}\n\ninterface IGLTFSpotLightCommonExtension {\n color: number[];\n constantAttenuation: number;\n fallOffAngle: number;\n fallOffExponent: number;\n linearAttenuation: number;\n quadraticAttenuation: number;\n}\n\n/** @hidden */\nexport class GLTFMaterialsCommonExtension extends GLTFLoaderExtension {\n\n constructor() {\n super(\"KHR_materials_common\");\n }\n\n public loadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError: (message: string) => void): boolean {\n if (!gltfRuntime.extensions) { return false; }\n\n var extension: IGLTFRuntimeCommonExtension = gltfRuntime.extensions[this.name];\n if (!extension) { return false; }\n\n // Create lights\n var lights = extension.lights;\n if (lights) {\n for (var thing in lights) {\n var light: IGLTFLightCommonExtension = lights[thing];\n\n switch (light.type) {\n case \"ambient\":\n var ambientLight = new HemisphericLight(light.name, new Vector3(0, 1, 0), gltfRuntime.scene);\n var ambient = light.ambient;\n if (ambient) {\n ambientLight.diffuse = Color3.FromArray(ambient.color || [1, 1, 1]);\n }\n break;\n case \"point\":\n var pointLight = new PointLight(light.name, new Vector3(10, 10, 10), gltfRuntime.scene);\n var point = light.point;\n if (point) {\n pointLight.diffuse = Color3.FromArray(point.color || [1, 1, 1]);\n }\n break;\n case \"directional\":\n var dirLight = new DirectionalLight(light.name, new Vector3(0, -1, 0), gltfRuntime.scene);\n var directional = light.directional;\n if (directional) {\n dirLight.diffuse = Color3.FromArray(directional.color || [1, 1, 1]);\n }\n break;\n case \"spot\":\n var spot = light.spot;\n if (spot) {\n var spotLight = new SpotLight(light.name, new Vector3(0, 10, 0), new Vector3(0, -1, 0),\n spot.fallOffAngle || Math.PI,\n spot.fallOffExponent || 0.0,\n gltfRuntime.scene);\n spotLight.diffuse = Color3.FromArray(spot.color || [1, 1, 1]);\n }\n break;\n default: Tools.Warn(\"GLTF Material Common extension: light type \\\"\" + light.type + \"\\” not supported\"); break;\n }\n }\n }\n\n return false;\n }\n\n public loadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: (message: string) => void): boolean {\n var material: IGLTFMaterial = gltfRuntime.materials[id];\n if (!material || !material.extensions) { return false; }\n\n var extension: IGLTFMaterialsCommonExtension = material.extensions[this.name];\n if (!extension) { return false; }\n\n var standardMaterial = new StandardMaterial(id, gltfRuntime.scene);\n standardMaterial.sideOrientation = Material.CounterClockWiseSideOrientation;\n\n if (extension.technique === \"CONSTANT\") {\n standardMaterial.disableLighting = true;\n }\n\n standardMaterial.backFaceCulling = extension.doubleSided === undefined ? false : !extension.doubleSided;\n standardMaterial.alpha = extension.values.transparency === undefined ? 1.0 : extension.values.transparency;\n standardMaterial.specularPower = extension.values.shininess === undefined ? 0.0 : extension.values.shininess;\n\n // Ambient\n if (typeof extension.values.ambient === \"string\") {\n this._loadTexture(gltfRuntime, extension.values.ambient, standardMaterial, \"ambientTexture\", onError);\n }\n else {\n standardMaterial.ambientColor = Color3.FromArray(extension.values.ambient || [0, 0, 0]);\n }\n\n // Diffuse\n if (typeof extension.values.diffuse === \"string\") {\n this._loadTexture(gltfRuntime, extension.values.diffuse, standardMaterial, \"diffuseTexture\", onError);\n }\n else {\n standardMaterial.diffuseColor = Color3.FromArray(extension.values.diffuse || [0, 0, 0]);\n }\n\n // Emission\n if (typeof extension.values.emission === \"string\") {\n this._loadTexture(gltfRuntime, extension.values.emission, standardMaterial, \"emissiveTexture\", onError);\n }\n else {\n standardMaterial.emissiveColor = Color3.FromArray(extension.values.emission || [0, 0, 0]);\n }\n\n // Specular\n if (typeof extension.values.specular === \"string\") {\n this._loadTexture(gltfRuntime, extension.values.specular, standardMaterial, \"specularTexture\", onError);\n }\n else {\n standardMaterial.specularColor = Color3.FromArray(extension.values.specular || [0, 0, 0]);\n }\n\n return true;\n }\n\n private _loadTexture(gltfRuntime: IGLTFRuntime, id: string, material: StandardMaterial, propertyPath: string, onError: (message: string) => void): void {\n // Create buffer from texture url\n GLTFLoaderBase.LoadTextureBufferAsync(gltfRuntime, id, (buffer) => {\n // Create texture from buffer\n GLTFLoaderBase.CreateTextureAsync(gltfRuntime, id, buffer, (texture) => (<any>material)[propertyPath] = texture, onError);\n }, onError);\n }\n}\n\nGLTFLoader.RegisterExtension(new GLTFMaterialsCommonExtension());\n"]}
@@ -1,5 +0,0 @@
1
- export * from "./glTFBinaryExtension";
2
- export * from "./glTFLoader";
3
- export * from "./glTFLoaderInterfaces";
4
- export * from "./glTFLoaderUtils";
5
- export * from "./glTFMaterialsCommonExtension";
package/glTF/1.0/index.js DELETED
@@ -1,6 +0,0 @@
1
- export * from "./glTFBinaryExtension.js";
2
- export * from "./glTFLoader.js";
3
- export * from "./glTFLoaderInterfaces.js";
4
- export * from "./glTFLoaderUtils.js";
5
- export * from "./glTFMaterialsCommonExtension.js";
6
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../sourceES6/loaders/src/glTF/1.0/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,cAAc,CAAC;AAC7B,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,gCAAgC,CAAC","sourcesContent":["export * from \"./glTFBinaryExtension\";\r\nexport * from \"./glTFLoader\";\r\nexport * from \"./glTFLoaderInterfaces\";\r\nexport * from \"./glTFLoaderUtils\";\r\nexport * from \"./glTFMaterialsCommonExtension\";"]}
@@ -1,36 +0,0 @@
1
- import { Nullable } from "@babylonjs/core/types";
2
- import { BaseTexture } from "@babylonjs/core/Materials/Textures/baseTexture";
3
- import { IScene } from "../glTFLoaderInterfaces";
4
- import { IGLTFLoaderExtension } from "../glTFLoaderExtension";
5
- import { GLTFLoader } from "../glTFLoader";
6
- declare module "babylonjs-gltf2interface" {
7
- /** @hidden */
8
- interface IEXTLightsImageBased_LightImageBased {
9
- _babylonTexture?: BaseTexture;
10
- _loaded?: Promise<void>;
11
- }
12
- }
13
- /**
14
- * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Vendor/EXT_lights_image_based/README.md)
15
- */
16
- export declare class EXT_lights_image_based implements IGLTFLoaderExtension {
17
- /**
18
- * The name of this extension.
19
- */
20
- readonly name = "EXT_lights_image_based";
21
- /**
22
- * Defines whether this extension is enabled.
23
- */
24
- enabled: boolean;
25
- private _loader;
26
- private _lights?;
27
- /** @hidden */
28
- constructor(loader: GLTFLoader);
29
- /** @hidden */
30
- dispose(): void;
31
- /** @hidden */
32
- onLoading(): void;
33
- /** @hidden */
34
- loadSceneAsync(context: string, scene: IScene): Nullable<Promise<void>>;
35
- private _loadLightAsync;
36
- }
@@ -1,111 +0,0 @@
1
- import { Scalar } from "@babylonjs/core/Maths/math.scalar.js";
2
- import { SphericalHarmonics, SphericalPolynomial } from "@babylonjs/core/Maths/sphericalPolynomial.js";
3
- import { Quaternion, Matrix } from "@babylonjs/core/Maths/math.vector.js";
4
- import { RawCubeTexture } from "@babylonjs/core/Materials/Textures/rawCubeTexture.js";
5
- import { GLTFLoader, ArrayItem } from "../glTFLoader.js";
6
- var NAME = "EXT_lights_image_based";
7
- /**
8
- * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Vendor/EXT_lights_image_based/README.md)
9
- */
10
- var EXT_lights_image_based = /** @class */ (function () {
11
- /** @hidden */
12
- function EXT_lights_image_based(loader) {
13
- /**
14
- * The name of this extension.
15
- */
16
- this.name = NAME;
17
- this._loader = loader;
18
- this.enabled = this._loader.isExtensionUsed(NAME);
19
- }
20
- /** @hidden */
21
- EXT_lights_image_based.prototype.dispose = function () {
22
- this._loader = null;
23
- delete this._lights;
24
- };
25
- /** @hidden */
26
- EXT_lights_image_based.prototype.onLoading = function () {
27
- var extensions = this._loader.gltf.extensions;
28
- if (extensions && extensions[this.name]) {
29
- var extension = extensions[this.name];
30
- this._lights = extension.lights;
31
- }
32
- };
33
- /** @hidden */
34
- EXT_lights_image_based.prototype.loadSceneAsync = function (context, scene) {
35
- var _this = this;
36
- return GLTFLoader.LoadExtensionAsync(context, scene, this.name, function (extensionContext, extension) {
37
- var promises = new Array();
38
- promises.push(_this._loader.loadSceneAsync(context, scene));
39
- _this._loader.logOpen("".concat(extensionContext));
40
- var light = ArrayItem.Get("".concat(extensionContext, "/light"), _this._lights, extension.light);
41
- promises.push(_this._loadLightAsync("/extensions/".concat(_this.name, "/lights/").concat(extension.light), light).then(function (texture) {
42
- _this._loader.babylonScene.environmentTexture = texture;
43
- }));
44
- _this._loader.logClose();
45
- return Promise.all(promises).then(function () { });
46
- });
47
- };
48
- EXT_lights_image_based.prototype._loadLightAsync = function (context, light) {
49
- var _this = this;
50
- if (!light._loaded) {
51
- var promises = new Array();
52
- this._loader.logOpen("".concat(context));
53
- var imageData_1 = new Array(light.specularImages.length);
54
- var _loop_1 = function (mipmap) {
55
- var faces = light.specularImages[mipmap];
56
- imageData_1[mipmap] = new Array(faces.length);
57
- var _loop_2 = function (face) {
58
- var specularImageContext = "".concat(context, "/specularImages/").concat(mipmap, "/").concat(face);
59
- this_1._loader.logOpen("".concat(specularImageContext));
60
- var index = faces[face];
61
- var image = ArrayItem.Get(specularImageContext, this_1._loader.gltf.images, index);
62
- promises.push(this_1._loader.loadImageAsync("/images/".concat(index), image).then(function (data) {
63
- imageData_1[mipmap][face] = data;
64
- }));
65
- this_1._loader.logClose();
66
- };
67
- for (var face = 0; face < faces.length; face++) {
68
- _loop_2(face);
69
- }
70
- };
71
- var this_1 = this;
72
- for (var mipmap = 0; mipmap < light.specularImages.length; mipmap++) {
73
- _loop_1(mipmap);
74
- }
75
- this._loader.logClose();
76
- light._loaded = Promise.all(promises).then(function () {
77
- var babylonTexture = new RawCubeTexture(_this._loader.babylonScene, null, light.specularImageSize);
78
- babylonTexture.name = light.name || "environment";
79
- light._babylonTexture = babylonTexture;
80
- if (light.intensity != undefined) {
81
- babylonTexture.level = light.intensity;
82
- }
83
- if (light.rotation) {
84
- var rotation = Quaternion.FromArray(light.rotation);
85
- // Invert the rotation so that positive rotation is counter-clockwise.
86
- if (!_this._loader.babylonScene.useRightHandedSystem) {
87
- rotation = Quaternion.Inverse(rotation);
88
- }
89
- Matrix.FromQuaternionToRef(rotation, babylonTexture.getReflectionTextureMatrix());
90
- }
91
- if (!light.irradianceCoefficients) {
92
- throw new Error("".concat(context, ": Irradiance coefficients are missing"));
93
- }
94
- var sphericalHarmonics = SphericalHarmonics.FromArray(light.irradianceCoefficients);
95
- sphericalHarmonics.scaleInPlace(light.intensity);
96
- sphericalHarmonics.convertIrradianceToLambertianRadiance();
97
- var sphericalPolynomial = SphericalPolynomial.FromHarmonics(sphericalHarmonics);
98
- // Compute the lod generation scale to fit exactly to the number of levels available.
99
- var lodGenerationScale = (imageData_1.length - 1) / Scalar.Log2(light.specularImageSize);
100
- return babylonTexture.updateRGBDAsync(imageData_1, sphericalPolynomial, lodGenerationScale);
101
- });
102
- }
103
- return light._loaded.then(function () {
104
- return light._babylonTexture;
105
- });
106
- };
107
- return EXT_lights_image_based;
108
- }());
109
- export { EXT_lights_image_based };
110
- GLTFLoader.RegisterExtension(NAME, function (loader) { return new EXT_lights_image_based(loader); });
111
- //# sourceMappingURL=EXT_lights_image_based.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"EXT_lights_image_based.js","sourceRoot":"","sources":["../../../../../sourceES6/loaders/src/glTF/2.0/Extensions/EXT_lights_image_based.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,2CAA2C,CAAC;AACpG,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAC;AAEvE,OAAO,EAAE,cAAc,EAAE,MAAM,mDAAmD,CAAC;AAKnF,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAEtD,IAAM,IAAI,GAAG,wBAAwB,CAAC;AAUtC;;GAEG;AACH;IAcI,cAAc;IACd,gCAAY,MAAkB;QAd9B;;WAEG;QACa,SAAI,GAAG,IAAI,CAAC;QAYxB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACt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gBAED,IAAI,CAAC,KAAK,CAAC,sBAAsB,EAAE;oBAC/B,MAAM,IAAI,KAAK,CAAC,UAAG,OAAO,0CAAuC,CAAC,CAAC;iBACtE;gBAED,IAAM,kBAAkB,GAAG,kBAAkB,CAAC,SAAS,CAAC,KAAK,CAAC,sBAAsB,CAAC,CAAC;gBACtF,kBAAkB,CAAC,YAAY,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;gBAEjD,kBAAkB,CAAC,qCAAqC,EAAE,CAAC;gBAC3D,IAAM,mBAAmB,GAAG,mBAAmB,CAAC,aAAa,CAAC,kBAAkB,CAAC,CAAC;gBAElF,qFAAqF;gBACrF,IAAM,kBAAkB,GAAG,CAAC,WAAS,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC;gBACzF,OAAO,cAAc,CAAC,eAAe,CAAC,WAAS,EAAE,mBAAmB,EAAE,kBAAkB,CAAC,CAAC;YAC9F,CAAC,CAAC,CAAC;SACN;QAED,OAAO,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC;YACtB,OAAO,KAAK,CAAC,eAAgB,CAAC;QAClC,CAAC,CAAC,CAAC;IACP,CAAC;IACL,6BAAC;AAAD,CAAC,AAzHD,IAyHC;;AAED,UAAU,CAAC,iBAAiB,CAAC,IAAI,EAAE,UAAC,MAAM,IAAK,OAAA,IAAI,sBAAsB,CAAC,MAAM,CAAC,EAAlC,CAAkC,CAAC,CAAC","sourcesContent":["import { Nullable } from \"@babylonjs/core/types\";\r\nimport { Scalar } from \"@babylonjs/core/Maths/math.scalar\";\r\nimport { SphericalHarmonics, SphericalPolynomial } from \"@babylonjs/core/Maths/sphericalPolynomial\";\r\nimport { Quaternion, Matrix } from \"@babylonjs/core/Maths/math.vector\";\r\nimport { BaseTexture } from \"@babylonjs/core/Materials/Textures/baseTexture\";\r\nimport { RawCubeTexture } from \"@babylonjs/core/Materials/Textures/rawCubeTexture\";\r\n\r\nimport { IEXTLightsImageBased_LightReferenceImageBased, IEXTLightsImageBased_LightImageBased, IEXTLightsImageBased } from \"babylonjs-gltf2interface\";\r\nimport { IScene } from \"../glTFLoaderInterfaces\";\r\nimport { IGLTFLoaderExtension } from \"../glTFLoaderExtension\";\r\nimport { GLTFLoader, ArrayItem } from \"../glTFLoader\";\r\n\r\nconst NAME = \"EXT_lights_image_based\";\r\n\r\ndeclare module \"babylonjs-gltf2interface\" {\r\n /** @hidden */\r\n interface IEXTLightsImageBased_LightImageBased {\r\n _babylonTexture?: BaseTexture;\r\n _loaded?: Promise<void>;\r\n }\r\n}\r\n\r\n/**\r\n * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Vendor/EXT_lights_image_based/README.md)\r\n */\r\nexport class EXT_lights_image_based implements IGLTFLoaderExtension {\r\n /**\r\n * The name of this extension.\r\n */\r\n public readonly name = NAME;\r\n\r\n /**\r\n * Defines whether this extension is enabled.\r\n */\r\n public enabled: boolean;\r\n\r\n private _loader: GLTFLoader;\r\n private _lights?: IEXTLightsImageBased_LightImageBased[];\r\n\r\n /** @hidden */\r\n constructor(loader: GLTFLoader) {\r\n this._loader = loader;\r\n this.enabled = this._loader.isExtensionUsed(NAME);\r\n }\r\n\r\n /** @hidden */\r\n public dispose() {\r\n (this._loader as any) = null;\r\n delete this._lights;\r\n }\r\n\r\n /** @hidden */\r\n public onLoading(): void {\r\n const extensions = this._loader.gltf.extensions;\r\n if (extensions && extensions[this.name]) {\r\n const extension = extensions[this.name] as IEXTLightsImageBased;\r\n this._lights = extension.lights;\r\n }\r\n }\r\n\r\n /** @hidden */\r\n public loadSceneAsync(context: string, scene: IScene): Nullable<Promise<void>> {\r\n return GLTFLoader.LoadExtensionAsync<IEXTLightsImageBased_LightReferenceImageBased>(context, scene, this.name, (extensionContext, extension) => {\r\n const promises = new Array<Promise<any>>();\r\n\r\n promises.push(this._loader.loadSceneAsync(context, scene));\r\n\r\n this._loader.logOpen(`${extensionContext}`);\r\n\r\n const light = ArrayItem.Get(`${extensionContext}/light`, this._lights, extension.light);\r\n promises.push(this._loadLightAsync(`/extensions/${this.name}/lights/${extension.light}`, light).then((texture) => {\r\n this._loader.babylonScene.environmentTexture = texture;\r\n }));\r\n\r\n this._loader.logClose();\r\n\r\n return Promise.all(promises).then(() => { });\r\n });\r\n }\r\n\r\n private _loadLightAsync(context: string, light: IEXTLightsImageBased_LightImageBased): Promise<BaseTexture> {\r\n if (!light._loaded) {\r\n const promises = new Array<Promise<any>>();\r\n\r\n this._loader.logOpen(`${context}`);\r\n\r\n const imageData = new Array<Array<ArrayBufferView>>(light.specularImages.length);\r\n for (let mipmap = 0; mipmap < light.specularImages.length; mipmap++) {\r\n const faces = light.specularImages[mipmap];\r\n imageData[mipmap] = new Array<ArrayBufferView>(faces.length);\r\n for (let face = 0; face < faces.length; face++) {\r\n const specularImageContext = `${context}/specularImages/${mipmap}/${face}`;\r\n this._loader.logOpen(`${specularImageContext}`);\r\n\r\n const index = faces[face];\r\n const image = ArrayItem.Get(specularImageContext, this._loader.gltf.images, index);\r\n promises.push(this._loader.loadImageAsync(`/images/${index}`, image).then((data) => {\r\n imageData[mipmap][face] = data;\r\n }));\r\n\r\n this._loader.logClose();\r\n }\r\n }\r\n\r\n this._loader.logClose();\r\n\r\n light._loaded = Promise.all(promises).then(() => {\r\n const babylonTexture = new RawCubeTexture(this._loader.babylonScene, null, light.specularImageSize);\r\n babylonTexture.name = light.name || \"environment\";\r\n light._babylonTexture = babylonTexture;\r\n\r\n if (light.intensity != undefined) {\r\n babylonTexture.level = light.intensity;\r\n }\r\n\r\n if (light.rotation) {\r\n let rotation = Quaternion.FromArray(light.rotation);\r\n\r\n // Invert the rotation so that positive rotation is counter-clockwise.\r\n if (!this._loader.babylonScene.useRightHandedSystem) {\r\n rotation = Quaternion.Inverse(rotation);\r\n }\r\n\r\n Matrix.FromQuaternionToRef(rotation, babylonTexture.getReflectionTextureMatrix());\r\n }\r\n\r\n if (!light.irradianceCoefficients) {\r\n throw new Error(`${context}: Irradiance coefficients are missing`);\r\n }\r\n\r\n const sphericalHarmonics = SphericalHarmonics.FromArray(light.irradianceCoefficients);\r\n sphericalHarmonics.scaleInPlace(light.intensity);\r\n\r\n sphericalHarmonics.convertIrradianceToLambertianRadiance();\r\n const sphericalPolynomial = SphericalPolynomial.FromHarmonics(sphericalHarmonics);\r\n\r\n // Compute the lod generation scale to fit exactly to the number of levels available.\r\n const lodGenerationScale = (imageData.length - 1) / Scalar.Log2(light.specularImageSize);\r\n return babylonTexture.updateRGBDAsync(imageData, sphericalPolynomial, lodGenerationScale);\r\n });\r\n }\r\n\r\n return light._loaded.then(() => {\r\n return light._babylonTexture!;\r\n });\r\n }\r\n}\r\n\r\nGLTFLoader.RegisterExtension(NAME, (loader) => new EXT_lights_image_based(loader));"]}