Selaa lähdekoodia

api improvement for fps and currentFrame

Raanan Weber 7 vuotta sitten
vanhempi
commit
2f368921f6
2 muutettua tiedostoa jossa 28 lisäystä ja 7 poistoa
  1. 28 2
      Viewer/src/model/modelAnimation.ts
  2. 0 5
      Viewer/src/model/viewerModel.ts

+ 28 - 2
Viewer/src/model/modelAnimation.ts

@@ -75,11 +75,37 @@ export class GroupModelAnimation implements IModelAnimation {
     }
 
     public get currentFrame(): number {
-        return this._animationGroup['_animatables'][0].getAnimations()[0].currentFrame;
+        // get the first currentFrame found
+        for (let i = 0; i < this._animationGroup['_animatables'].length; ++i) {
+            let animatable: Animatable = this._animationGroup['_animatables'][i];
+            let animations = animatable.getAnimations();
+            if (!animations || !animations.length) {
+                continue;
+            }
+            for (let idx = 0; idx < animations.length; ++idx) {
+                if (animations[idx].currentFrame) {
+                    return animations[idx].currentFrame;
+                }
+            }
+        }
+        return 0;
     }
 
     public get fps(): number {
-        return this._animationGroup['_animatables'][0].getAnimations()[0].animation.framePerSecond;
+        // get the first currentFrame found
+        for (let i = 0; i < this._animationGroup['_animatables'].length; ++i) {
+            let animatable: Animatable = this._animationGroup['_animatables'][i];
+            let animations = animatable.getAnimations();
+            if (!animations || !animations.length) {
+                continue;
+            }
+            for (let idx = 0; idx < animations.length; ++idx) {
+                if (animations[idx].animation && animations[idx].animation.framePerSecond) {
+                    return animations[idx].animation.framePerSecond;
+                }
+            }
+        }
+        return 0;
     }
 
     public get playMode(): AnimationPlayMode {

+ 0 - 5
Viewer/src/model/viewerModel.ts

@@ -91,11 +91,6 @@ export class ViewerModel implements IDisposable {
             this.skeletons = skeletons;
 
             // check if this is a gltf loader and load the animations
-            /*if (this.loader['_loader'] && this.loader['_loader']['_gltf'] && this.loader['_loader']['_gltf'].animations) {
-                this.loader['_loader']['_gltf'].animations.forEach(animation => {
-                    this._animations.push(new GroupModelAnimation(animation._babylonAnimationGroup));
-                });
-            }*/
             if (this.loader.name === 'gltf') {
                 this._scene.animationGroups.forEach(ag => {
                     // add animations that didn't exist before