Skip to content

Commit

Permalink
solve issue jMonkeyEngine#1939 [NPE in FbxMesh.applyCluster()] (jMonk…
Browse files Browse the repository at this point in the history
…eyEngine#1940)

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

* FbxLoader:  don't construct an animation if there are no keyframes
  • Loading branch information
stephengold committed Feb 3, 2023
1 parent 18fa6be commit aaabd10
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,9 @@ private void constructAnimations() {

// 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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ public void fromElement(FbxElement element) {
}
}
}

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() {
Expand Down Expand Up @@ -129,4 +135,4 @@ public void connectObject(FbxObject object) {
public void connectObjectProperty(FbxObject object, String property) {
unsupportedConnectObjectProperty(object, property);
}
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -91,7 +91,23 @@ public BoneTrack toJmeBoneTrack(int boneIndex, Transform inverseBindPose) {
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);
Expand Down

0 comments on commit aaabd10

Please sign in to comment.