Просмотр исходного кода

solve issue #1939 [NPE in FbxMesh.applyCluster()] (#1940)

* FBXCluster:  create empty arrays if the cluster contains no keyframes

* FbxLoader:  don't construct an animation if there are no keyframes
Stephen Gold 2 лет назад
Родитель
Сommit
aaabd10477

+ 3 - 0
jme3-plugins/src/fbx/java/com/jme3/scene/plugins/fbx/FbxLoader.java

@@ -343,6 +343,9 @@ public class FbxLoader implements AssetLoader {
         
         // At this point we can construct the animation for all pairs ...
         for (FbxToJmeTrack pair : pairs.values()) {
+            if (pair.countKeyframes() == 0) {
+                continue;
+            }
             String animName = pair.animStack.getName();
             float duration    = pair.animStack.getDuration();
             

+ 7 - 1
jme3-plugins/src/fbx/java/com/jme3/scene/plugins/fbx/anim/FbxCluster.java

@@ -93,6 +93,12 @@ public class FbxCluster extends FbxObject {
                 }
             }
         }
+
+        if (indexes == null && weights == null) {
+            // The cluster doesn't contain any keyframes!
+            this.indexes = new int[0];
+            this.weights = new double[0];
+        }
     }
 
     public int[] getVertexIndices() {
@@ -129,4 +135,4 @@ public class FbxCluster extends FbxObject {
     public void connectObjectProperty(FbxObject object, String property) {
         unsupportedConnectObjectProperty(object, property);
     }
-}
+}

+ 18 - 2
jme3-plugins/src/fbx/java/com/jme3/scene/plugins/fbx/anim/FbxToJmeTrack.java

@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009-2021 jMonkeyEngine
+ * Copyright (c) 2009-2023 jMonkeyEngine
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -91,7 +91,23 @@ public final class FbxToJmeTrack {
     public SpatialTrack toJmeSpatialTrack() {
         return (SpatialTrack) toJmeTrackInternal(-1, null);
     }
-    
+
+    /**
+     * Counts how many keyframes there are in the included curves.
+     *
+     * @return the total number of keyframes (≥0)
+     */
+    public int countKeyframes() {
+        int count = 0;
+        for (FbxAnimCurveNode curveNode : animCurves.values()) {
+            for (FbxAnimCurve curve : curveNode.getCurves()) {
+                count += curve.getKeyTimes().length;
+            }
+        }
+
+        return count;
+    }
+
     public float getDuration() {
         long[] keyframes = getKeyTimes();
         return (float) (keyframes[keyframes.length - 1] * FbxAnimUtil.SECONDS_PER_UNIT);