소스 검색

Merge pull request #4508 from bghgary/gltf-lod-fix

Fix issue with MSFT_lod where node LODs show at the same time
David Catuhe 7 년 전
부모
커밋
425d2ba030
2개의 변경된 파일14개의 추가작업 그리고 19개의 파일을 삭제
  1. 4 6
      loaders/src/glTF/2.0/babylon.glTFLoader.ts
  2. 10 13
      tests/unit/babylon/src/Loading/babylon.sceneLoader.tests.ts

+ 4 - 6
loaders/src/glTF/2.0/babylon.glTFLoader.ts

@@ -189,10 +189,6 @@ module BABYLON.GLTF2 {
                 resultPromise.then(() => {
                     this._parent._endPerformanceCounter("Loading => Ready");
 
-                    if (this._rootBabylonMesh) {
-                        this._rootBabylonMesh.setEnabled(true);
-                    }
-
                     Tools.SetImmediate(() => {
                         if (!this._disposed) {
                             Promise.all(this._completePromises).then(() => {
@@ -299,7 +295,6 @@ module BABYLON.GLTF2 {
 
         private _createRootNode(): _ILoaderNode {
             this._rootBabylonMesh = new Mesh("__root__", this._babylonScene);
-            this._rootBabylonMesh.setEnabled(false);
 
             const rootNode = { _babylonMesh: this._rootBabylonMesh } as _ILoaderNode;
             switch (this._parent.coordinateSystemMode) {
@@ -457,6 +452,7 @@ module BABYLON.GLTF2 {
             const babylonMesh = new Mesh(node.name || `node${node._index}`, this._babylonScene, node._parent ? node._parent._babylonMesh : null);
             node._babylonMesh = babylonMesh;
 
+            babylonMesh.setEnabled(false);
             GLTFLoader._LoadTransform(node, babylonMesh);
 
             if (node.mesh != undefined) {
@@ -480,7 +476,9 @@ module BABYLON.GLTF2 {
 
             this._parent._logClose();
 
-            return Promise.all(promises).then(() => {});
+            return Promise.all(promises).then(() => {
+                babylonMesh.setEnabled(true);
+            });
         }
 
         private _loadMeshAsync(context: string, node: _ILoaderNode, mesh: _ILoaderMesh, babylonMesh: Mesh): Promise<void> {

+ 10 - 13
tests/unit/babylon/src/Loading/babylon.sceneLoader.tests.ts

@@ -161,28 +161,25 @@ describe('Babylon Scene Loader', function () {
             return Promise.race(promises);
         });
 
-        it('Load BoomBox with rootMesh.isEnabled check', () => {
+        it('Load BoomBox with mesh.isEnabled check', () => {
             const scene = new BABYLON.Scene(subject);
-            let rootMesh: BABYLON.AbstractMesh;
 
             subject.runRenderLoop(() => {
-                if (!rootMesh) {
-                    for (const mesh of scene.meshes) {
-                        if (!mesh.parent) {
-                            rootMesh = mesh;
-                            break;
-                        }
+                for (const mesh of scene.meshes) {
+                    if (mesh.getTotalVertices() !== 0) {
+                        expect(mesh.isEnabled(), "mesh.isEnabled").to.be.false;
                     }
                 }
-
-                if (rootMesh) {
-                    expect(rootMesh.isEnabled(), "rootMesh.isEnabled").to.be.false;
-                }
             });
 
             return BABYLON.SceneLoader.AppendAsync("/Playground/scenes/BoomBox/", "BoomBox.gltf", scene).then(scene => {
-                expect(rootMesh.isEnabled(), "rootMesh.isEnabled").to.be.true;
                 subject.stopRenderLoop();
+
+                for (const mesh of scene.meshes) {
+                    if (mesh.getTotalVertices() !== 0) {
+                        expect(mesh.isEnabled(), "mesh.isEnabled").to.be.true;
+                    }
+                }
             });
         });