Browse Source

viewer add model on init, remove from scene when disposed.

Raanan Weber 7 năm trước cách đây
mục cha
commit
9f960836fa

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

@@ -3,6 +3,7 @@ import { IModelConfiguration } from "../configuration/configuration";
 import { IModelAnimation, GroupModelAnimation, AnimationPlayMode } from "./modelAnimation";
 import { IModelAnimation, GroupModelAnimation, AnimationPlayMode } from "./modelAnimation";
 
 
 import * as deepmerge from '../../assets/deepmerge.min.js';
 import * as deepmerge from '../../assets/deepmerge.min.js';
+import { AbstractViewer } from "..";
 
 
 
 
 export enum ModelState {
 export enum ModelState {
@@ -78,7 +79,7 @@ export class ViewerModel implements IDisposable {
     private _loadedUrl: string;
     private _loadedUrl: string;
     private _modelConfiguration: IModelConfiguration;
     private _modelConfiguration: IModelConfiguration;
 
 
-    constructor(private _scene: Scene, modelConfiguration: IModelConfiguration) {
+    constructor(private _viewer: AbstractViewer, modelConfiguration: IModelConfiguration) {
         this.onLoadedObservable = new Observable();
         this.onLoadedObservable = new Observable();
         this.onLoadErrorObservable = new Observable();
         this.onLoadErrorObservable = new Observable();
         this.onLoadProgressObservable = new Observable();
         this.onLoadProgressObservable = new Observable();
@@ -89,6 +90,8 @@ export class ViewerModel implements IDisposable {
         this._animations = [];
         this._animations = [];
         //create a copy of the configuration to make sure it doesn't change even after it is changed in the viewer
         //create a copy of the configuration to make sure it doesn't change even after it is changed in the viewer
         this._modelConfiguration = deepmerge({}, modelConfiguration);
         this._modelConfiguration = deepmerge({}, modelConfiguration);
+
+        this._viewer.models.push(this);
     }
     }
 
 
     /**
     /**
@@ -128,7 +131,7 @@ export class ViewerModel implements IDisposable {
         // check if this is not a gltf loader and init the animations
         // check if this is not a gltf loader and init the animations
         if (this.loader.name !== 'gltf') {
         if (this.loader.name !== 'gltf') {
             this.skeletons.forEach((skeleton, idx) => {
             this.skeletons.forEach((skeleton, idx) => {
-                let ag = new AnimationGroup("animation-" + idx, this._scene);
+                let ag = new AnimationGroup("animation-" + idx, this._viewer.scene);
                 skeleton.getAnimatables().forEach(a => {
                 skeleton.getAnimatables().forEach(a => {
                     if (a.animations[0]) {
                     if (a.animations[0]) {
                         ag.addTargetedAnimation(a.animations[0], a);
                         ag.addTargetedAnimation(a.animations[0], a);
@@ -327,5 +330,6 @@ export class ViewerModel implements IDisposable {
         this._animations.length = 0;
         this._animations.length = 0;
         this.meshes.forEach(m => m.dispose());
         this.meshes.forEach(m => m.dispose());
         this.meshes.length = 0;
         this.meshes.length = 0;
+        this._viewer.models.splice(this._viewer.models.indexOf(this), 1);
     }
     }
 }
 }

+ 0 - 1
Viewer/src/viewer/viewer.ts

@@ -845,7 +845,6 @@ export abstract class AbstractViewer {
             this.models.length = 0;
             this.models.length = 0;
         }
         }
 
 
-        this.models.push(model);
         this.lastUsedLoader = model.loader;
         this.lastUsedLoader = model.loader;
         model.onLoadErrorObservable.add((errorObject) => {
         model.onLoadErrorObservable.add((errorObject) => {
             this.onModelLoadErrorObservable.notifyObserversWithPromise(errorObject);
             this.onModelLoadErrorObservable.notifyObserversWithPromise(errorObject);