Skip to content

Commit b7e5319

Browse files
stephengoldAli-RS
authored andcommitted
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
1 parent 4e8374c commit b7e5319

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

jme3-plugins/src/fbx/java/com/jme3/scene/plugins/fbx/FbxLoader.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,9 @@ private void constructAnimations() {
343343

344344
// At this point we can construct the animation for all pairs ...
345345
for (FbxToJmeTrack pair : pairs.values()) {
346+
if (pair.countKeyframes() == 0) {
347+
continue;
348+
}
346349
String animName = pair.animStack.getName();
347350
float duration = pair.animStack.getDuration();
348351

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@ public void fromElement(FbxElement element) {
9393
}
9494
}
9595
}
96+
97+
if (indexes == null && weights == null) {
98+
// The cluster doesn't contain any keyframes!
99+
this.indexes = new int[0];
100+
this.weights = new double[0];
101+
}
96102
}
97103

98104
public int[] getVertexIndices() {
@@ -129,4 +135,4 @@ public void connectObject(FbxObject object) {
129135
public void connectObjectProperty(FbxObject object, String property) {
130136
unsupportedConnectObjectProperty(object, property);
131137
}
132-
}
138+
}

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2009-2021 jMonkeyEngine
2+
* Copyright (c) 2009-2023 jMonkeyEngine
33
* All rights reserved.
44
*
55
* Redistribution and use in source and binary forms, with or without
@@ -91,7 +91,23 @@ public BoneTrack toJmeBoneTrack(int boneIndex, Transform inverseBindPose) {
9191
public SpatialTrack toJmeSpatialTrack() {
9292
return (SpatialTrack) toJmeTrackInternal(-1, null);
9393
}
94-
94+
95+
/**
96+
* Counts how many keyframes there are in the included curves.
97+
*
98+
* @return the total number of keyframes (≥0)
99+
*/
100+
public int countKeyframes() {
101+
int count = 0;
102+
for (FbxAnimCurveNode curveNode : animCurves.values()) {
103+
for (FbxAnimCurve curve : curveNode.getCurves()) {
104+
count += curve.getKeyTimes().length;
105+
}
106+
}
107+
108+
return count;
109+
}
110+
95111
public float getDuration() {
96112
long[] keyframes = getKeyTimes();
97113
return (float) (keyframes[keyframes.length - 1] * FbxAnimUtil.SECONDS_PER_UNIT);

0 commit comments

Comments
 (0)