Browse Source

viewer model should trigger "on loaded" in specific cases

Raanan Weber 7 năm trước cách đây
mục cha
commit
9aa720ce77
2 tập tin đã thay đổi với 8 bổ sung4 xóa
  1. 2 1
      Viewer/src/model/modelLoader.ts
  2. 6 3
      Viewer/src/model/viewerModel.ts

+ 2 - 1
Viewer/src/model/modelLoader.ts

@@ -34,6 +34,8 @@ export class ModelLoader {
 
         const model = new ViewerModel(this._viewer, modelConfiguration);
 
+        model.loadId = this._loadId++;
+
         if (!modelConfiguration.url) {
             model.state = ModelState.ERROR;
             Tools.Error("No URL provided");
@@ -71,7 +73,6 @@ export class ModelLoader {
             gltfLoader.animationStartMode = BABYLON.GLTFLoaderAnimationStartMode.NONE;
         }
 
-        model.loadId = this._loadId++;
         this._loaders.push(model.loader);
 
         return model;

+ 6 - 3
Viewer/src/model/viewerModel.ts

@@ -98,8 +98,7 @@ export class ViewerModel implements IDisposable {
         this._viewer.onModelAddedObservable.notifyObservers(this);
         this.onLoadedObservable.add(() => {
             this._configureModel();
-        })
-
+        });
     }
 
     /**
@@ -107,13 +106,17 @@ export class ViewerModel implements IDisposable {
      * Any mesh that has no parent will be provided with the root mesh as its new parent.
      * 
      * @param mesh the new mesh to add
+     * @param triggerLoaded should this mesh trigger the onLoaded observable. Used when adding meshes manually.
      */
-    public addMesh(mesh: AbstractMesh) {
+    public addMesh(mesh: AbstractMesh, triggerLoaded?: boolean) {
         if (!mesh.parent) {
             mesh.parent = this.rootMesh;
         }
         mesh.receiveShadows = !!this.configuration.receiveShadows;
         this._meshes.push(mesh);
+        if (triggerLoaded) {
+            this.onLoadedObservable.notifyObservers(this);
+        }
     }
 
     /**