Raanan Weber 7 anni fa
parent
commit
5bea1fbb85

+ 1 - 0
dist/preview release/viewer/babylon.viewer.d.ts

@@ -462,6 +462,7 @@ declare module BabylonViewer {
         state: ModelState;
         state: ModelState;
         loadId: number;
         loadId: number;
         load(): void;
         load(): void;
+        initAnimations(): void;
         getAnimations(): Array<IModelAnimation>;
         getAnimations(): Array<IModelAnimation>;
         getAnimationNames(): string[];
         getAnimationNames(): string[];
         playAnimation(name: string): IModelAnimation;
         playAnimation(name: string): IModelAnimation;

File diff suppressed because it is too large
+ 8 - 8
dist/preview release/viewer/babylon.viewer.js


+ 43 - 33
dist/preview release/viewer/babylon.viewer.max.js

@@ -94581,6 +94581,9 @@ var ViewerModel = (function () {
         if (disableAutoLoad === void 0) { disableAutoLoad = false; }
         if (disableAutoLoad === void 0) { disableAutoLoad = false; }
         this._scene = _scene;
         this._scene = _scene;
         this._modelConfiguration = _modelConfiguration;
         this._modelConfiguration = _modelConfiguration;
+        this.meshes = [];
+        this.particleSystems = [];
+        this.skeletons = [];
         this._loaderDisposed = false;
         this._loaderDisposed = false;
         this.onLoadedObservable = new babylonjs_1.Observable();
         this.onLoadedObservable = new babylonjs_1.Observable();
         this.onLoadErrorObservable = new babylonjs_1.Observable();
         this.onLoadErrorObservable = new babylonjs_1.Observable();
@@ -94622,6 +94625,38 @@ var ViewerModel = (function () {
         this._modelConfiguration = deepmerge(this._modelConfiguration, newConfiguration);
         this._modelConfiguration = deepmerge(this._modelConfiguration, newConfiguration);
         this._configureModel();
         this._configureModel();
     };
     };
+    ViewerModel.prototype.initAnimations = function () {
+        var _this = this;
+        this._animations.forEach(function (a) {
+            a.dispose();
+        });
+        this._animations.length = 0;
+        if (this.loader.name !== 'gltf') {
+            this.skeletons.forEach(function (skeleton, idx) {
+                var ag = new babylonjs_1.AnimationGroup("animation-" + idx, _this._scene);
+                skeleton.getAnimatables().forEach(function (a) {
+                    if (a.animations[0]) {
+                        ag.addTargetedAnimation(a.animations[0], a);
+                    }
+                });
+                _this._animations.push(new modelAnimation_1.GroupModelAnimation(ag));
+            });
+        }
+        if (!this._modelConfiguration)
+            return;
+        if (this._modelConfiguration.animation) {
+            if (this._modelConfiguration.animation.playOnce) {
+                this._animations.forEach(function (a) {
+                    a.playMode = modelAnimation_1.AnimationPlayMode.ONCE;
+                });
+            }
+            if (this._modelConfiguration.animation.autoStart && this._animations.length) {
+                var animationName = this._modelConfiguration.animation.autoStart === true ?
+                    this._animations[0].name : this._modelConfiguration.animation.autoStart;
+                this.playAnimation(animationName);
+            }
+        }
+    };
     ViewerModel.prototype.getAnimations = function () {
     ViewerModel.prototype.getAnimations = function () {
         return this._animations;
         return this._animations;
     };
     };
@@ -94753,7 +94788,6 @@ var ViewerModel = (function () {
         var base = this._modelConfiguration.root || babylonjs_1.Tools.GetFolderPath(this._modelConfiguration.url);
         var base = this._modelConfiguration.root || babylonjs_1.Tools.GetFolderPath(this._modelConfiguration.url);
         var plugin = this._modelConfiguration.loader;
         var plugin = this._modelConfiguration.loader;
         this._loadedUrl = this._modelConfiguration.url;
         this._loadedUrl = this._modelConfiguration.url;
-        var animationsArray = this._scene.animationGroups.slice();
         this.loader = babylonjs_1.SceneLoader.ImportMesh(undefined, base, filename, this._scene, function (meshes, particleSystems, skeletons) {
         this.loader = babylonjs_1.SceneLoader.ImportMesh(undefined, base, filename, this._scene, function (meshes, particleSystems, skeletons) {
             meshes.forEach(function (mesh) {
             meshes.forEach(function (mesh) {
                 babylonjs_1.Tags.AddTagsTo(mesh, "viewerMesh");
                 babylonjs_1.Tags.AddTagsTo(mesh, "viewerMesh");
@@ -94761,38 +94795,7 @@ var ViewerModel = (function () {
             _this.meshes = meshes;
             _this.meshes = meshes;
             _this.particleSystems = particleSystems;
             _this.particleSystems = particleSystems;
             _this.skeletons = skeletons;
             _this.skeletons = skeletons;
-            if (_this.loader.name === 'gltf') {
-                _this._scene.animationGroups.forEach(function (ag) {
-                    if (animationsArray.indexOf(ag) === -1) {
-                        _this._animations.push(new modelAnimation_1.GroupModelAnimation(ag));
-                    }
-                });
-            }
-            else {
-                skeletons.forEach(function (skeleton, idx) {
-                    var ag = new babylonjs_1.AnimationGroup("animation-" + idx, _this._scene);
-                    skeleton.getAnimatables().forEach(function (a) {
-                        if (a.animations[0]) {
-                            ag.addTargetedAnimation(a.animations[0], a);
-                        }
-                    });
-                    _this._animations.push(new modelAnimation_1.GroupModelAnimation(ag));
-                });
-            }
-            if (!_this._modelConfiguration)
-                return;
-            if (_this._modelConfiguration.animation) {
-                if (_this._modelConfiguration.animation.playOnce) {
-                    _this._animations.forEach(function (a) {
-                        a.playMode = modelAnimation_1.AnimationPlayMode.ONCE;
-                    });
-                }
-                if (_this._modelConfiguration.animation.autoStart && _this._animations.length) {
-                    var animationName = _this._modelConfiguration.animation.autoStart === true ?
-                        _this._animations[0].name : _this._modelConfiguration.animation.autoStart;
-                    _this.playAnimation(animationName);
-                }
-            }
+            _this.initAnimations();
             _this.onLoadedObservable.notifyObserversWithPromise(_this);
             _this.onLoadedObservable.notifyObserversWithPromise(_this);
         }, function (progressEvent) {
         }, function (progressEvent) {
             _this.onLoadProgressObservable.notifyObserversWithPromise(progressEvent);
             _this.onLoadProgressObservable.notifyObserversWithPromise(progressEvent);
@@ -94807,6 +94810,9 @@ var ViewerModel = (function () {
             gltfLoader.onDispose = function () {
             gltfLoader.onDispose = function () {
                 _this._loaderDisposed = true;
                 _this._loaderDisposed = true;
             };
             };
+            gltfLoader.onAnimationGroupLoaded = function (ag) {
+                _this._animations.push(new modelAnimation_1.GroupModelAnimation(ag));
+            };
         }
         }
     };
     };
     ViewerModel.prototype.dispose = function () {
     ViewerModel.prototype.dispose = function () {
@@ -94818,9 +94824,13 @@ var ViewerModel = (function () {
             this.loader.dispose();
             this.loader.dispose();
         }
         }
         this.particleSystems.forEach(function (ps) { return ps.dispose(); });
         this.particleSystems.forEach(function (ps) { return ps.dispose(); });
+        this.particleSystems.length = 0;
         this.skeletons.forEach(function (s) { return s.dispose(); });
         this.skeletons.forEach(function (s) { return s.dispose(); });
+        this.skeletons.length = 0;
         this._animations.forEach(function (ag) { return ag.dispose(); });
         this._animations.forEach(function (ag) { return ag.dispose(); });
+        this._animations.length = 0;
         this.meshes.forEach(function (m) { return m.dispose(); });
         this.meshes.forEach(function (m) { return m.dispose(); });
+        this.meshes.length = 0;
     };
     };
     return ViewerModel;
     return ViewerModel;
 }());
 }());