@babylonjs/loaders 5.0.0-alpha.5 → 5.0.0-alpha.53
Sign up to get free protection for your applications and to get access to all the features.
- package/OBJ/index.d.ts +2 -0
- package/OBJ/index.js +4 -2
- package/OBJ/index.js.map +1 -1
- package/OBJ/mtlFileLoader.d.ts +4 -2
- package/OBJ/mtlFileLoader.js +7 -6
- package/OBJ/mtlFileLoader.js.map +1 -1
- package/OBJ/objFileLoader.d.ts +17 -78
- package/OBJ/objFileLoader.js +55 -619
- package/OBJ/objFileLoader.js.map +1 -1
- package/OBJ/objLoadingOptions.d.ts +43 -0
- package/OBJ/objLoadingOptions.js +2 -0
- package/OBJ/objLoadingOptions.js.map +1 -0
- package/OBJ/solidParser.d.ts +153 -0
- package/OBJ/solidParser.js +700 -0
- package/OBJ/solidParser.js.map +1 -0
- package/STL/index.js +1 -1
- package/STL/stlFileLoader.d.ts +6 -0
- package/STL/stlFileLoader.js +38 -11
- package/STL/stlFileLoader.js.map +1 -1
- package/glTF/1.0/glTFBinaryExtension.js +4 -4
- package/glTF/1.0/glTFLoader.d.ts +4 -4
- package/glTF/1.0/glTFLoader.js +60 -55
- package/glTF/1.0/glTFLoader.js.map +1 -1
- package/glTF/1.0/glTFLoaderInterfaces.d.ts +3 -1
- package/glTF/1.0/glTFLoaderInterfaces.js.map +1 -1
- package/glTF/1.0/glTFLoaderUtils.js +6 -6
- package/glTF/1.0/glTFMaterialsCommonExtension.js +12 -12
- package/glTF/1.0/index.js +5 -5
- package/glTF/2.0/Extensions/EXT_lights_image_based.js +8 -5
- package/glTF/2.0/Extensions/EXT_lights_image_based.js.map +1 -1
- package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js +3 -3
- package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js.map +1 -1
- package/glTF/2.0/Extensions/EXT_meshopt_compression.d.ts +1 -5
- package/glTF/2.0/Extensions/EXT_meshopt_compression.js +5 -21
- package/glTF/2.0/Extensions/EXT_meshopt_compression.js.map +1 -1
- package/glTF/2.0/Extensions/EXT_texture_webp.js +2 -2
- package/glTF/2.0/Extensions/EXT_texture_webp.js.map +1 -1
- package/glTF/2.0/Extensions/ExtrasAsMetadata.js +1 -1
- package/glTF/2.0/Extensions/KHR_draco_mesh_compression.js +8 -4
- package/glTF/2.0/Extensions/KHR_draco_mesh_compression.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_lights_punctual.js +9 -8
- package/glTF/2.0/Extensions/KHR_lights_punctual.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_clearcoat.js +2 -2
- package/glTF/2.0/Extensions/KHR_materials_ior.d.ts +1 -2
- package/glTF/2.0/Extensions/KHR_materials_ior.js +3 -4
- package/glTF/2.0/Extensions/KHR_materials_ior.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.js +3 -4
- package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_sheen.d.ts +0 -1
- package/glTF/2.0/Extensions/KHR_materials_sheen.js +3 -4
- package/glTF/2.0/Extensions/KHR_materials_sheen.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_specular.d.ts +1 -2
- package/glTF/2.0/Extensions/KHR_materials_specular.js +12 -6
- package/glTF/2.0/Extensions/KHR_materials_specular.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_translucency.js +6 -6
- package/glTF/2.0/Extensions/KHR_materials_translucency.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_transmission.js +92 -84
- package/glTF/2.0/Extensions/KHR_materials_transmission.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_unlit.js +3 -3
- package/glTF/2.0/Extensions/KHR_materials_variants.js +86 -22
- package/glTF/2.0/Extensions/KHR_materials_variants.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_volume.d.ts +31 -0
- package/glTF/2.0/Extensions/KHR_materials_volume.js +79 -0
- package/glTF/2.0/Extensions/KHR_materials_volume.js.map +1 -0
- package/glTF/2.0/Extensions/KHR_mesh_quantization.js +1 -1
- package/glTF/2.0/Extensions/KHR_texture_basisu.d.ts +1 -2
- package/glTF/2.0/Extensions/KHR_texture_basisu.js +3 -4
- package/glTF/2.0/Extensions/KHR_texture_basisu.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_texture_transform.js +2 -2
- package/glTF/2.0/Extensions/KHR_xmp_json_ld.d.ts +2 -2
- package/glTF/2.0/Extensions/KHR_xmp_json_ld.js +3 -3
- package/glTF/2.0/Extensions/KHR_xmp_json_ld.js.map +1 -1
- package/glTF/2.0/Extensions/MSFT_audio_emitter.js +6 -7
- package/glTF/2.0/Extensions/MSFT_audio_emitter.js.map +1 -1
- package/glTF/2.0/Extensions/MSFT_lod.d.ts +2 -1
- package/glTF/2.0/Extensions/MSFT_lod.js +48 -8
- package/glTF/2.0/Extensions/MSFT_lod.js.map +1 -1
- package/glTF/2.0/Extensions/MSFT_minecraftMesh.js +2 -2
- package/glTF/2.0/Extensions/MSFT_sRGBFactors.js +2 -2
- package/glTF/2.0/Extensions/index.d.ts +1 -0
- package/glTF/2.0/Extensions/index.js +25 -24
- package/glTF/2.0/Extensions/index.js.map +1 -1
- package/glTF/2.0/glTFLoader.d.ts +5 -10
- package/glTF/2.0/glTFLoader.js +125 -92
- package/glTF/2.0/glTFLoader.js.map +1 -1
- package/glTF/2.0/glTFLoaderInterfaces.d.ts +4 -2
- package/glTF/2.0/glTFLoaderInterfaces.js.map +1 -1
- package/glTF/2.0/index.d.ts +1 -1
- package/glTF/2.0/index.js +4 -4
- package/glTF/2.0/index.js.map +1 -1
- package/glTF/glTFFileLoader.d.ts +15 -9
- package/glTF/glTFFileLoader.js +62 -76
- package/glTF/glTFFileLoader.js.map +1 -1
- package/glTF/glTFValidation.js +1 -1
- package/glTF/glTFValidation.js.map +1 -1
- package/glTF/index.d.ts +2 -2
- package/glTF/index.js +4 -4
- package/glTF/index.js.map +1 -1
- package/index.d.ts +3 -3
- package/index.js +3 -3
- package/index.js.map +1 -1
- package/legacy/legacy-glTF.js +4 -4
- package/legacy/legacy-glTF1.d.ts +1 -1
- package/legacy/legacy-glTF1.js +1 -1
- package/legacy/legacy-glTF1.js.map +1 -1
- package/legacy/legacy-glTF1FileLoader.js +2 -2
- package/legacy/legacy-glTF2.d.ts +1 -1
- package/legacy/legacy-glTF2.js +3 -3
- package/legacy/legacy-glTF2.js.map +1 -1
- package/legacy/legacy-glTF2FileLoader.js +2 -2
- package/legacy/legacy-glTFFileLoader.js +3 -3
- package/legacy/legacy-objFileLoader.d.ts +1 -1
- package/legacy/legacy-objFileLoader.js +2 -2
- package/legacy/legacy-objFileLoader.js.map +1 -1
- package/legacy/legacy-stlFileLoader.d.ts +1 -1
- package/legacy/legacy-stlFileLoader.js +2 -2
- package/legacy/legacy-stlFileLoader.js.map +1 -1
- package/legacy/legacy.js +6 -6
- package/package.json +13 -4
package/glTF/2.0/glTFLoader.js
CHANGED
@@ -1,29 +1,29 @@
|
|
1
|
-
import { Deferred } from "@babylonjs/core/Misc/deferred";
|
2
|
-
import { Quaternion, Vector3, Matrix } from "@babylonjs/core/Maths/math.vector";
|
3
|
-
import { Color3 } from '@babylonjs/core/Maths/math.color';
|
4
|
-
import { Tools } from "@babylonjs/core/Misc/tools";
|
5
|
-
import { Camera } from "@babylonjs/core/Cameras/camera";
|
6
|
-
import { FreeCamera } from "@babylonjs/core/Cameras/freeCamera";
|
7
|
-
import { AnimationGroup } from "@babylonjs/core/Animations/animationGroup";
|
8
|
-
import { Animation } from "@babylonjs/core/Animations/animation";
|
9
|
-
import { Bone } from "@babylonjs/core/Bones/bone";
|
10
|
-
import { Skeleton } from "@babylonjs/core/Bones/skeleton";
|
11
|
-
import { Material } from "@babylonjs/core/Materials/material";
|
12
|
-
import { PBRMaterial } from "@babylonjs/core/Materials/PBR/pbrMaterial";
|
13
|
-
import { Texture } from "@babylonjs/core/Materials/Textures/texture";
|
14
|
-
import { TransformNode } from "@babylonjs/core/Meshes/transformNode";
|
15
|
-
import { Buffer, VertexBuffer } from "@babylonjs/core/
|
16
|
-
import { Geometry } from "@babylonjs/core/Meshes/geometry";
|
17
|
-
import { Mesh } from "@babylonjs/core/Meshes/mesh";
|
18
|
-
import { MorphTarget } from "@babylonjs/core/Morph/morphTarget";
|
19
|
-
import { MorphTargetManager } from "@babylonjs/core/Morph/morphTargetManager";
|
20
|
-
import { GLTFFileLoader, GLTFLoaderState, GLTFLoaderCoordinateSystemMode, GLTFLoaderAnimationStartMode } from "../glTFFileLoader";
|
21
|
-
import { AnimationKeyInterpolation } from '@babylonjs/core/Animations/animationKey';
|
22
|
-
import { LoadFileError } from '@babylonjs/core/Misc/fileTools';
|
23
|
-
import { Logger } from '@babylonjs/core/Misc/logger';
|
24
|
-
import { TmpVectors } from '@babylonjs/core/Maths/math.vector';
|
25
|
-
import { BoundingInfo } from '@babylonjs/core/Culling/boundingInfo';
|
26
|
-
import { StringTools } from '@babylonjs/core/Misc/stringTools';
|
1
|
+
import { Deferred } from "@babylonjs/core/Misc/deferred.js";
|
2
|
+
import { Quaternion, Vector3, Matrix } from "@babylonjs/core/Maths/math.vector.js";
|
3
|
+
import { Color3 } from '@babylonjs/core/Maths/math.color.js';
|
4
|
+
import { Tools } from "@babylonjs/core/Misc/tools.js";
|
5
|
+
import { Camera } from "@babylonjs/core/Cameras/camera.js";
|
6
|
+
import { FreeCamera } from "@babylonjs/core/Cameras/freeCamera.js";
|
7
|
+
import { AnimationGroup } from "@babylonjs/core/Animations/animationGroup.js";
|
8
|
+
import { Animation } from "@babylonjs/core/Animations/animation.js";
|
9
|
+
import { Bone } from "@babylonjs/core/Bones/bone.js";
|
10
|
+
import { Skeleton } from "@babylonjs/core/Bones/skeleton.js";
|
11
|
+
import { Material } from "@babylonjs/core/Materials/material.js";
|
12
|
+
import { PBRMaterial } from "@babylonjs/core/Materials/PBR/pbrMaterial.js";
|
13
|
+
import { Texture } from "@babylonjs/core/Materials/Textures/texture.js";
|
14
|
+
import { TransformNode } from "@babylonjs/core/Meshes/transformNode.js";
|
15
|
+
import { Buffer, VertexBuffer } from "@babylonjs/core/Buffers/buffer.js";
|
16
|
+
import { Geometry } from "@babylonjs/core/Meshes/geometry.js";
|
17
|
+
import { Mesh } from "@babylonjs/core/Meshes/mesh.js";
|
18
|
+
import { MorphTarget } from "@babylonjs/core/Morph/morphTarget.js";
|
19
|
+
import { MorphTargetManager } from "@babylonjs/core/Morph/morphTargetManager.js";
|
20
|
+
import { GLTFFileLoader, GLTFLoaderState, GLTFLoaderCoordinateSystemMode, GLTFLoaderAnimationStartMode } from "../glTFFileLoader.js";
|
21
|
+
import { AnimationKeyInterpolation } from '@babylonjs/core/Animations/animationKey.js';
|
22
|
+
import { DecodeBase64UrlToBinary, IsBase64DataUrl, LoadFileError } from '@babylonjs/core/Misc/fileTools.js';
|
23
|
+
import { Logger } from '@babylonjs/core/Misc/logger.js';
|
24
|
+
import { TmpVectors } from '@babylonjs/core/Maths/math.vector.js';
|
25
|
+
import { BoundingInfo } from '@babylonjs/core/Culling/boundingInfo.js';
|
26
|
+
import { StringTools } from '@babylonjs/core/Misc/stringTools.js';
|
27
27
|
/**
|
28
28
|
* Helper class for working with arrays when loading the glTF asset
|
29
29
|
*/
|
@@ -66,13 +66,12 @@ var GLTFLoader = /** @class */ (function () {
|
|
66
66
|
/** @hidden */
|
67
67
|
this._completePromises = new Array();
|
68
68
|
/** @hidden */
|
69
|
-
this.
|
69
|
+
this._assetContainer = null;
|
70
70
|
/** Storage */
|
71
71
|
this._babylonLights = [];
|
72
72
|
/** @hidden */
|
73
73
|
this._disableInstancedMesh = 0;
|
74
74
|
this._disposed = false;
|
75
|
-
this._state = null;
|
76
75
|
this._extensions = new Array();
|
77
76
|
this._defaultBabylonMaterialData = {};
|
78
77
|
this._parent = parent;
|
@@ -102,16 +101,6 @@ var GLTFLoader = /** @class */ (function () {
|
|
102
101
|
delete GLTFLoader._RegisteredExtensions[name];
|
103
102
|
return true;
|
104
103
|
};
|
105
|
-
Object.defineProperty(GLTFLoader.prototype, "state", {
|
106
|
-
/**
|
107
|
-
* The loader state.
|
108
|
-
*/
|
109
|
-
get: function () {
|
110
|
-
return this._state;
|
111
|
-
},
|
112
|
-
enumerable: false,
|
113
|
-
configurable: true
|
114
|
-
});
|
115
104
|
Object.defineProperty(GLTFLoader.prototype, "gltf", {
|
116
105
|
/**
|
117
106
|
* The object that represents the glTF JSON.
|
@@ -180,12 +169,12 @@ var GLTFLoader = /** @class */ (function () {
|
|
180
169
|
this._parent.dispose();
|
181
170
|
};
|
182
171
|
/** @hidden */
|
183
|
-
GLTFLoader.prototype.importMeshAsync = function (meshesNames, scene,
|
172
|
+
GLTFLoader.prototype.importMeshAsync = function (meshesNames, scene, container, data, rootUrl, onProgress, fileName) {
|
184
173
|
var _this = this;
|
185
174
|
if (fileName === void 0) { fileName = ""; }
|
186
175
|
return Promise.resolve().then(function () {
|
187
176
|
_this._babylonScene = scene;
|
188
|
-
_this.
|
177
|
+
_this._assetContainer = container;
|
189
178
|
_this._loadData(data);
|
190
179
|
var nodes = null;
|
191
180
|
if (meshesNames) {
|
@@ -242,7 +231,7 @@ var GLTFLoader = /** @class */ (function () {
|
|
242
231
|
var loadingToCompleteCounterName = GLTFLoaderState[GLTFLoaderState.LOADING] + " => " + GLTFLoaderState[GLTFLoaderState.COMPLETE];
|
243
232
|
_this._parent._startPerformanceCounter(loadingToReadyCounterName);
|
244
233
|
_this._parent._startPerformanceCounter(loadingToCompleteCounterName);
|
245
|
-
_this._setState(GLTFLoaderState.LOADING);
|
234
|
+
_this._parent._setState(GLTFLoaderState.LOADING);
|
246
235
|
_this._extensionsOnLoading();
|
247
236
|
var promises = new Array();
|
248
237
|
// Block the marking of materials dirty until the scene is loaded.
|
@@ -276,7 +265,7 @@ var GLTFLoader = /** @class */ (function () {
|
|
276
265
|
_this._rootBabylonMesh.setEnabled(true);
|
277
266
|
}
|
278
267
|
_this._extensionsOnReady();
|
279
|
-
_this._setState(GLTFLoaderState.READY);
|
268
|
+
_this._parent._setState(GLTFLoaderState.READY);
|
280
269
|
_this._startAnimations();
|
281
270
|
return resultFunc();
|
282
271
|
});
|
@@ -286,7 +275,7 @@ var GLTFLoader = /** @class */ (function () {
|
|
286
275
|
if (!_this._disposed) {
|
287
276
|
Promise.all(_this._completePromises).then(function () {
|
288
277
|
_this._parent._endPerformanceCounter(loadingToCompleteCounterName);
|
289
|
-
_this._setState(GLTFLoaderState.COMPLETE);
|
278
|
+
_this._parent._setState(GLTFLoaderState.COMPLETE);
|
290
279
|
_this._parent.onCompleteObservable.notifyObservers(undefined);
|
291
280
|
_this._parent.onCompleteObservable.clear();
|
292
281
|
_this.dispose();
|
@@ -385,13 +374,10 @@ var GLTFLoader = /** @class */ (function () {
|
|
385
374
|
}
|
386
375
|
}
|
387
376
|
};
|
388
|
-
GLTFLoader.prototype._setState = function (state) {
|
389
|
-
this._state = state;
|
390
|
-
this.log(GLTFLoaderState[this._state]);
|
391
|
-
};
|
392
377
|
GLTFLoader.prototype._createRootNode = function () {
|
393
|
-
this._babylonScene._blockEntityCollection = this.
|
378
|
+
this._babylonScene._blockEntityCollection = !!this._assetContainer;
|
394
379
|
this._rootBabylonMesh = new Mesh("__root__", this._babylonScene);
|
380
|
+
this._rootBabylonMesh._parentContainer = this._assetContainer;
|
395
381
|
this._babylonScene._blockEntityCollection = false;
|
396
382
|
this._rootBabylonMesh.setEnabled(false);
|
397
383
|
var rootNode = {
|
@@ -604,8 +590,9 @@ var GLTFLoader = /** @class */ (function () {
|
|
604
590
|
};
|
605
591
|
if (node.mesh == undefined) {
|
606
592
|
var nodeName = node.name || "node" + node.index;
|
607
|
-
this._babylonScene._blockEntityCollection = this.
|
593
|
+
this._babylonScene._blockEntityCollection = !!this._assetContainer;
|
608
594
|
node._babylonTransformNode = new TransformNode(nodeName, this._babylonScene);
|
595
|
+
node._babylonTransformNode._parentContainer = this._assetContainer;
|
609
596
|
this._babylonScene._blockEntityCollection = false;
|
610
597
|
loadNode(node._babylonTransformNode);
|
611
598
|
}
|
@@ -646,8 +633,9 @@ var GLTFLoader = /** @class */ (function () {
|
|
646
633
|
}));
|
647
634
|
}
|
648
635
|
else {
|
649
|
-
this._babylonScene._blockEntityCollection = this.
|
636
|
+
this._babylonScene._blockEntityCollection = !!this._assetContainer;
|
650
637
|
node._babylonTransformNode = new TransformNode(name, this._babylonScene);
|
638
|
+
node._babylonTransformNode._parentContainer = this._assetContainer;
|
651
639
|
this._babylonScene._blockEntityCollection = false;
|
652
640
|
node._primitiveBabylonMeshes = [];
|
653
641
|
for (var _i = 0, primitives_1 = primitives; _i < primitives_1.length; _i++) {
|
@@ -689,20 +677,25 @@ var GLTFLoader = /** @class */ (function () {
|
|
689
677
|
var babylonAbstractMesh;
|
690
678
|
var promise;
|
691
679
|
if (shouldInstance && primitive._instanceData) {
|
680
|
+
this._babylonScene._blockEntityCollection = !!this._assetContainer;
|
692
681
|
babylonAbstractMesh = primitive._instanceData.babylonSourceMesh.createInstance(name);
|
682
|
+
babylonAbstractMesh._parentContainer = this._assetContainer;
|
683
|
+
this._babylonScene._blockEntityCollection = false;
|
693
684
|
promise = primitive._instanceData.promise;
|
694
685
|
}
|
695
686
|
else {
|
696
687
|
var promises = new Array();
|
697
|
-
this._babylonScene._blockEntityCollection = this.
|
688
|
+
this._babylonScene._blockEntityCollection = !!this._assetContainer;
|
698
689
|
var babylonMesh_1 = new Mesh(name, this._babylonScene);
|
690
|
+
babylonMesh_1._parentContainer = this._assetContainer;
|
699
691
|
this._babylonScene._blockEntityCollection = false;
|
700
692
|
babylonMesh_1.overrideMaterialSideOrientation = this._babylonScene.useRightHandedSystem ? Material.CounterClockWiseSideOrientation : Material.ClockWiseSideOrientation;
|
701
693
|
this._createMorphTargets(context, node, mesh, primitive, babylonMesh_1);
|
702
694
|
promises.push(this._loadVertexDataAsync(context, primitive, babylonMesh_1).then(function (babylonGeometry) {
|
703
695
|
return _this._loadMorphTargetsAsync(context, primitive, babylonMesh_1, babylonGeometry).then(function () {
|
704
|
-
_this._babylonScene._blockEntityCollection = _this.
|
696
|
+
_this._babylonScene._blockEntityCollection = !!_this._assetContainer;
|
705
697
|
babylonGeometry.applyToMesh(babylonMesh_1);
|
698
|
+
babylonGeometry._parentContainer = _this._assetContainer;
|
706
699
|
_this._babylonScene._blockEntityCollection = false;
|
707
700
|
});
|
708
701
|
}));
|
@@ -773,6 +766,27 @@ var GLTFLoader = /** @class */ (function () {
|
|
773
766
|
if (babylonVertexBuffer.getKind() === VertexBuffer.PositionKind && !_this.parent.alwaysComputeBoundingBox && !babylonMesh.skeleton) {
|
774
767
|
var mmin = accessor.min, mmax = accessor.max;
|
775
768
|
if (mmin !== undefined && mmax !== undefined) {
|
769
|
+
if (accessor.normalized && accessor.componentType !== 5126 /* FLOAT */) {
|
770
|
+
var divider = 1;
|
771
|
+
switch (accessor.componentType) {
|
772
|
+
case 5120 /* BYTE */:
|
773
|
+
divider = 127.0;
|
774
|
+
break;
|
775
|
+
case 5121 /* UNSIGNED_BYTE */:
|
776
|
+
divider = 255.0;
|
777
|
+
break;
|
778
|
+
case 5122 /* SHORT */:
|
779
|
+
divider = 32767.0;
|
780
|
+
break;
|
781
|
+
case 5123 /* UNSIGNED_SHORT */:
|
782
|
+
divider = 65535.0;
|
783
|
+
break;
|
784
|
+
}
|
785
|
+
for (var i = 0; i < 3; ++i) {
|
786
|
+
mmin[i] = Math.max(mmin[i] / divider, -1.0);
|
787
|
+
mmax[i] = Math.max(mmax[i] / divider, -1.0);
|
788
|
+
}
|
789
|
+
}
|
776
790
|
var min = TmpVectors.Vector3[0], max = TmpVectors.Vector3[1];
|
777
791
|
min.copyFromFloats.apply(min, mmin);
|
778
792
|
max.copyFromFloats.apply(max, mmax);
|
@@ -794,6 +808,10 @@ var GLTFLoader = /** @class */ (function () {
|
|
794
808
|
loadAttribute("TANGENT", VertexBuffer.TangentKind);
|
795
809
|
loadAttribute("TEXCOORD_0", VertexBuffer.UVKind);
|
796
810
|
loadAttribute("TEXCOORD_1", VertexBuffer.UV2Kind);
|
811
|
+
loadAttribute("TEXCOORD_2", VertexBuffer.UV3Kind);
|
812
|
+
loadAttribute("TEXCOORD_3", VertexBuffer.UV4Kind);
|
813
|
+
loadAttribute("TEXCOORD_4", VertexBuffer.UV5Kind);
|
814
|
+
loadAttribute("TEXCOORD_5", VertexBuffer.UV6Kind);
|
797
815
|
loadAttribute("JOINTS_0", VertexBuffer.MatricesIndicesKind);
|
798
816
|
loadAttribute("WEIGHTS_0", VertexBuffer.MatricesWeightsKind);
|
799
817
|
loadAttribute("JOINTS_1", VertexBuffer.MatricesIndicesExtraKind);
|
@@ -819,6 +837,7 @@ var GLTFLoader = /** @class */ (function () {
|
|
819
837
|
}
|
820
838
|
var targetNames = mesh.extras ? mesh.extras.targetNames : null;
|
821
839
|
babylonMesh.morphTargetManager = new MorphTargetManager(babylonMesh.getScene());
|
840
|
+
babylonMesh.morphTargetManager.areUpdatesFrozen = true;
|
822
841
|
for (var index = 0; index < primitive.targets.length; index++) {
|
823
842
|
var weight = node.weights ? node.weights[index] : mesh.weights ? mesh.weights[index] : 0;
|
824
843
|
var name_4 = targetNames ? targetNames[index] : "morphTarget" + index;
|
@@ -836,7 +855,9 @@ var GLTFLoader = /** @class */ (function () {
|
|
836
855
|
var babylonMorphTarget = morphTargetManager.getTarget(index);
|
837
856
|
promises.push(this._loadMorphTargetVertexDataAsync(context + "/targets/" + index, babylonGeometry, primitive.targets[index], babylonMorphTarget));
|
838
857
|
}
|
839
|
-
return Promise.all(promises).then(function () {
|
858
|
+
return Promise.all(promises).then(function () {
|
859
|
+
morphTargetManager.areUpdatesFrozen = false;
|
860
|
+
});
|
840
861
|
};
|
841
862
|
GLTFLoader.prototype._loadMorphTargetVertexDataAsync = function (context, babylonGeometry, attributes, babylonMorphTarget) {
|
842
863
|
var _this = this;
|
@@ -928,8 +949,9 @@ var GLTFLoader = /** @class */ (function () {
|
|
928
949
|
return skin._data.promise;
|
929
950
|
}
|
930
951
|
var skeletonId = "skeleton" + skin.index;
|
931
|
-
this._babylonScene._blockEntityCollection = this.
|
952
|
+
this._babylonScene._blockEntityCollection = !!this._assetContainer;
|
932
953
|
var babylonSkeleton = new Skeleton(skin.name || skeletonId, skeletonId, this._babylonScene);
|
954
|
+
babylonSkeleton._parentContainer = this._assetContainer;
|
933
955
|
this._babylonScene._blockEntityCollection = false;
|
934
956
|
// See https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#skins (second implementation note)
|
935
957
|
babylonSkeleton.overrideMesh = this._rootBabylonMesh;
|
@@ -988,7 +1010,6 @@ var GLTFLoader = /** @class */ (function () {
|
|
988
1010
|
if (babylonParentBone) {
|
989
1011
|
baseMatrix.multiplyToRef(babylonParentBone.getInvertedAbsoluteTransform(), baseMatrix);
|
990
1012
|
}
|
991
|
-
babylonBone.setBindPose(baseMatrix);
|
992
1013
|
babylonBone.updateMatrix(baseMatrix, false, false);
|
993
1014
|
babylonBone._updateDifferenceMatrix(undefined, false);
|
994
1015
|
}
|
@@ -1013,8 +1034,9 @@ var GLTFLoader = /** @class */ (function () {
|
|
1013
1034
|
}
|
1014
1035
|
var promises = new Array();
|
1015
1036
|
this.logOpen(context + " " + (camera.name || ""));
|
1016
|
-
this._babylonScene._blockEntityCollection = this.
|
1037
|
+
this._babylonScene._blockEntityCollection = !!this._assetContainer;
|
1017
1038
|
var babylonCamera = new FreeCamera(camera.name || "camera" + camera.index, Vector3.Zero(), this._babylonScene, false);
|
1039
|
+
babylonCamera._parentContainer = this._assetContainer;
|
1018
1040
|
this._babylonScene._blockEntityCollection = false;
|
1019
1041
|
babylonCamera.ignoreParentScaling = true;
|
1020
1042
|
babylonCamera.rotation = new Vector3(0, Math.PI, 0);
|
@@ -1082,8 +1104,9 @@ var GLTFLoader = /** @class */ (function () {
|
|
1082
1104
|
if (promise) {
|
1083
1105
|
return promise;
|
1084
1106
|
}
|
1085
|
-
this._babylonScene._blockEntityCollection = this.
|
1107
|
+
this._babylonScene._blockEntityCollection = !!this._assetContainer;
|
1086
1108
|
var babylonAnimationGroup = new AnimationGroup(animation.name || "animation" + animation.index, this._babylonScene);
|
1109
|
+
babylonAnimationGroup._parentContainer = this._assetContainer;
|
1087
1110
|
this._babylonScene._blockEntityCollection = false;
|
1088
1111
|
animation._babylonAnimationGroup = babylonAnimationGroup;
|
1089
1112
|
var promises = new Array();
|
@@ -1439,36 +1462,33 @@ var GLTFLoader = /** @class */ (function () {
|
|
1439
1462
|
};
|
1440
1463
|
GLTFLoader.prototype._loadVertexAccessorAsync = function (context, accessor, kind) {
|
1441
1464
|
var _this = this;
|
1442
|
-
|
1443
|
-
|
1465
|
+
var _a;
|
1466
|
+
if ((_a = accessor._babylonVertexBuffer) === null || _a === void 0 ? void 0 : _a[kind]) {
|
1467
|
+
return accessor._babylonVertexBuffer[kind];
|
1444
1468
|
}
|
1445
|
-
if (accessor.
|
1446
|
-
accessor._babylonVertexBuffer =
|
1447
|
-
return new VertexBuffer(_this._babylonScene.getEngine(), data, kind, false);
|
1448
|
-
});
|
1469
|
+
if (!accessor._babylonVertexBuffer) {
|
1470
|
+
accessor._babylonVertexBuffer = {};
|
1449
1471
|
}
|
1450
|
-
|
1451
|
-
|
1452
|
-
Logger.Warn("Accessor byte offset is not a multiple of component type byte length");
|
1453
|
-
accessor._babylonVertexBuffer = this._loadFloatAccessorAsync("/accessors/" + accessor.index, accessor).then(function (data) {
|
1472
|
+
if (accessor.sparse) {
|
1473
|
+
accessor._babylonVertexBuffer[kind] = this._loadFloatAccessorAsync(context, accessor).then(function (data) {
|
1454
1474
|
return new VertexBuffer(_this._babylonScene.getEngine(), data, kind, false);
|
1455
1475
|
});
|
1456
1476
|
}
|
1457
1477
|
// Load joint indices as a float array since the shaders expect float data but glTF uses unsigned byte/short.
|
1458
1478
|
// This prevents certain platforms (e.g. D3D) from having to convert the data to float on the fly.
|
1459
1479
|
else if (kind === VertexBuffer.MatricesIndicesKind || kind === VertexBuffer.MatricesIndicesExtraKind) {
|
1460
|
-
accessor._babylonVertexBuffer = this._loadFloatAccessorAsync(
|
1480
|
+
accessor._babylonVertexBuffer[kind] = this._loadFloatAccessorAsync(context, accessor).then(function (data) {
|
1461
1481
|
return new VertexBuffer(_this._babylonScene.getEngine(), data, kind, false);
|
1462
1482
|
});
|
1463
1483
|
}
|
1464
1484
|
else {
|
1465
1485
|
var bufferView_2 = ArrayItem.Get(context + "/bufferView", this._gltf.bufferViews, accessor.bufferView);
|
1466
|
-
accessor._babylonVertexBuffer = this._loadVertexBufferViewAsync(bufferView_2, kind).then(function (babylonBuffer) {
|
1486
|
+
accessor._babylonVertexBuffer[kind] = this._loadVertexBufferViewAsync(bufferView_2, kind).then(function (babylonBuffer) {
|
1467
1487
|
var size = GLTFLoader._GetNumComponents(context, accessor.type);
|
1468
1488
|
return new VertexBuffer(_this._babylonScene.getEngine(), babylonBuffer, kind, false, false, bufferView_2.byteStride, false, accessor.byteOffset, size, accessor.componentType, accessor.normalized, true, 1, true);
|
1469
1489
|
});
|
1470
1490
|
}
|
1471
|
-
return accessor._babylonVertexBuffer;
|
1491
|
+
return accessor._babylonVertexBuffer[kind];
|
1472
1492
|
};
|
1473
1493
|
GLTFLoader.prototype._loadMaterialMetallicRoughnessPropertiesAsync = function (context, properties, babylonMaterial) {
|
1474
1494
|
if (!(babylonMaterial instanceof PBRMaterial)) {
|
@@ -1541,8 +1561,9 @@ var GLTFLoader = /** @class */ (function () {
|
|
1541
1561
|
});
|
1542
1562
|
};
|
1543
1563
|
GLTFLoader.prototype._createDefaultMaterial = function (name, babylonDrawMode) {
|
1544
|
-
this._babylonScene._blockEntityCollection = this.
|
1564
|
+
this._babylonScene._blockEntityCollection = !!this._assetContainer;
|
1545
1565
|
var babylonMaterial = new PBRMaterial(name, this._babylonScene);
|
1566
|
+
babylonMaterial._parentContainer = this._assetContainer;
|
1546
1567
|
this._babylonScene._blockEntityCollection = false;
|
1547
1568
|
// Moved to mesh so user can change materials on gltf meshes: babylonMaterial.sideOrientation = this._babylonScene.useRightHandedSystem ? Material.CounterClockWiseSideOrientation : Material.ClockWiseSideOrientation;
|
1548
1569
|
babylonMaterial.fillMode = babylonDrawMode;
|
@@ -1692,7 +1713,7 @@ var GLTFLoader = /** @class */ (function () {
|
|
1692
1713
|
return extensionPromise;
|
1693
1714
|
}
|
1694
1715
|
this.logOpen("" + context);
|
1695
|
-
if (textureInfo.texCoord >=
|
1716
|
+
if (textureInfo.texCoord >= 6) {
|
1696
1717
|
throw new Error(context + "/texCoord: Invalid value (" + textureInfo.texCoord + ")");
|
1697
1718
|
}
|
1698
1719
|
var texture = ArrayItem.Get(context + "/index", this._gltf.textures, textureInfo.index);
|
@@ -1716,27 +1737,38 @@ var GLTFLoader = /** @class */ (function () {
|
|
1716
1737
|
this.logOpen(context + " " + (texture.name || ""));
|
1717
1738
|
var sampler = (texture.sampler == undefined ? GLTFLoader.DefaultSampler : ArrayItem.Get(context + "/sampler", this._gltf.samplers, texture.sampler));
|
1718
1739
|
var image = ArrayItem.Get(context + "/source", this._gltf.images, texture.source);
|
1719
|
-
var promise = this._createTextureAsync(context, sampler, image, assign);
|
1740
|
+
var promise = this._createTextureAsync(context, sampler, image, assign, undefined, !texture._textureInfo.nonColorData);
|
1720
1741
|
this.logClose();
|
1721
1742
|
return promise;
|
1722
1743
|
};
|
1723
1744
|
/** @hidden */
|
1724
|
-
GLTFLoader.prototype._createTextureAsync = function (context, sampler, image, assign, textureLoaderOptions) {
|
1745
|
+
GLTFLoader.prototype._createTextureAsync = function (context, sampler, image, assign, textureLoaderOptions, useSRGBBuffer) {
|
1725
1746
|
var _this = this;
|
1726
1747
|
if (assign === void 0) { assign = function () { }; }
|
1727
1748
|
var samplerData = this._loadSampler("/samplers/" + sampler.index, sampler);
|
1728
1749
|
var promises = new Array();
|
1729
1750
|
var deferred = new Deferred();
|
1730
|
-
this._babylonScene._blockEntityCollection = this.
|
1731
|
-
var
|
1732
|
-
|
1733
|
-
|
1734
|
-
|
1735
|
-
|
1736
|
-
|
1737
|
-
|
1738
|
-
|
1739
|
-
|
1751
|
+
this._babylonScene._blockEntityCollection = !!this._assetContainer;
|
1752
|
+
var textureCreationOptions = {
|
1753
|
+
noMipmap: samplerData.noMipMaps,
|
1754
|
+
invertY: false,
|
1755
|
+
samplingMode: samplerData.samplingMode,
|
1756
|
+
onLoad: function () {
|
1757
|
+
if (!_this._disposed) {
|
1758
|
+
deferred.resolve();
|
1759
|
+
}
|
1760
|
+
},
|
1761
|
+
onError: function (message, exception) {
|
1762
|
+
if (!_this._disposed) {
|
1763
|
+
deferred.reject(new Error(context + ": " + ((exception && exception.message) ? exception.message : message || "Failed to load texture")));
|
1764
|
+
}
|
1765
|
+
},
|
1766
|
+
mimeType: image.mimeType,
|
1767
|
+
loaderOptions: textureLoaderOptions,
|
1768
|
+
useSRGBBuffer: !!useSRGBBuffer && this._parent.useSRGBBuffers,
|
1769
|
+
};
|
1770
|
+
var babylonTexture = new Texture(null, this._babylonScene, textureCreationOptions);
|
1771
|
+
babylonTexture._parentContainer = this._assetContainer;
|
1740
1772
|
this._babylonScene._blockEntityCollection = false;
|
1741
1773
|
promises.push(deferred.promise);
|
1742
1774
|
promises.push(this.loadImageAsync("/images/" + image.index, image).then(function (data) {
|
@@ -1798,15 +1830,15 @@ var GLTFLoader = /** @class */ (function () {
|
|
1798
1830
|
if (!GLTFLoader._ValidateUri(uri)) {
|
1799
1831
|
throw new Error(context + ": '" + uri + "' is invalid");
|
1800
1832
|
}
|
1801
|
-
if (
|
1802
|
-
var data = new Uint8Array(
|
1833
|
+
if (IsBase64DataUrl(uri)) {
|
1834
|
+
var data = new Uint8Array(DecodeBase64UrlToBinary(uri));
|
1803
1835
|
this.log(context + ": Decoded " + uri.substr(0, 64) + "... (" + data.length + " bytes)");
|
1804
1836
|
return Promise.resolve(data);
|
1805
1837
|
}
|
1806
1838
|
this.log(context + ": Loading " + uri);
|
1807
1839
|
return this._parent.preprocessUrlAsync(this._rootUrl + uri).then(function (url) {
|
1808
1840
|
return new Promise(function (resolve, reject) {
|
1809
|
-
_this._parent._loadFile(
|
1841
|
+
_this._parent._loadFile(_this._babylonScene, url, function (data) {
|
1810
1842
|
if (!_this._disposed) {
|
1811
1843
|
_this.log(context + ": Loaded " + uri + " (" + data.byteLength + " bytes)");
|
1812
1844
|
resolve(new Uint8Array(data));
|
@@ -1889,12 +1921,13 @@ var GLTFLoader = /** @class */ (function () {
|
|
1889
1921
|
var buffer = bufferView.buffer;
|
1890
1922
|
byteOffset = bufferView.byteOffset + (byteOffset || 0);
|
1891
1923
|
var constructor = GLTFLoader._GetTypedArrayConstructor(context + "/componentType", componentType);
|
1892
|
-
|
1893
|
-
|
1894
|
-
|
1895
|
-
|
1896
|
-
|
1924
|
+
var componentTypeLength = VertexBuffer.GetTypeByteLength(componentType);
|
1925
|
+
if (byteOffset % componentTypeLength !== 0) {
|
1926
|
+
// HACK: Copy the buffer if byte offset is not a multiple of component type byte length.
|
1927
|
+
Logger.Warn(context + ": Copying buffer as byte offset (" + byteOffset + ") is not a multiple of component type byte length (" + componentTypeLength + ")");
|
1928
|
+
return new constructor(buffer.slice(byteOffset, byteOffset + length * componentTypeLength), 0);
|
1897
1929
|
}
|
1930
|
+
return new constructor(buffer, byteOffset, length);
|
1898
1931
|
};
|
1899
1932
|
GLTFLoader._GetNumComponents = function (context, type) {
|
1900
1933
|
switch (type) {
|