Skip to content

Commit f47f865

Browse files
committed
glTF: Fixed when a sub graph is ttached to a bone. Fixed a crash with animation resampling
1 parent 683bf63 commit f47f865

File tree

2 files changed

+24
-17
lines changed

2 files changed

+24
-17
lines changed

jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/GltfLoader.java

+8-6
Original file line numberDiff line numberDiff line change
@@ -1033,12 +1033,14 @@ private void findChildren(int nodeIndex) throws IOException {
10331033
bw.bone.addChild(cbw.bone);
10341034
bw.children.add(childIndex);
10351035
} else {
1036-
JsonObject childNode = nodes.get(childIndex).getAsJsonObject();
1037-
//The child might be a Geom
1038-
if (getAsInteger(childNode, "mesh") != null) {
1039-
//this is a geometry, let's load it as a spatial
1040-
bw.attachedSpatial = (Spatial) readNode(childIndex);
1041-
}
1036+
//The child might be a Node
1037+
//Creating a dummy node to reed the subgraph
1038+
Node n = new Node();
1039+
readChild(n, child);
1040+
Spatial s = n.getChild(0);
1041+
//removing the spatial from the dummy node, it will be attached to the attachment node of the bone
1042+
s.removeFromParent();
1043+
bw.attachedSpatial = s;
10421044
}
10431045
}
10441046

jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/TrackData.java

+16-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.jme3.scene.plugins.gltf;
22

3+
import com.jme3.asset.AssetLoadException;
34
import com.jme3.math.*;
45

56
import java.util.*;
@@ -119,9 +120,19 @@ public void update() {
119120
}
120121
}
121122

123+
checkTimesConsistantcy();
124+
122125
length = times[times.length - 1];
123126
}
124127

128+
public void checkTimesConsistantcy() {
129+
if ((translations != null && times.length != translations.length)
130+
|| (rotations != null && times.length != rotations.length)
131+
|| (scales != null && times.length != scales.length)) {
132+
throw new AssetLoadException("Inconsistent animation sampling ");
133+
}
134+
}
135+
125136
private void populateTransform(Type type, int index, List<KeyFrame> keyFrames, KeyFrame currentKeyFrame, TransformIndices transformIndices) {
126137
Object transform = getTransform(type, currentKeyFrame);
127138
if (transform != null) {
@@ -178,14 +189,8 @@ private int findNext(List<KeyFrame> keyFrames, Type type, int fromIndex) {
178189
}
179190

180191
public int getNbKeyFrames(){
181-
if(translations != null){
182-
return translations.length;
183-
}
184-
if(rotations != null){
185-
return rotations.length;
186-
}
187-
if(scales != null){
188-
return scales.length;
192+
if (times != null) {
193+
return times.length;
189194
}
190195
return 0;
191196
}
@@ -234,13 +239,13 @@ private Object getTransform(Type type, KeyFrame kf) {
234239
}
235240

236241
private void ensureArraysLength() {
237-
if (translations != null && translations.length < times.length) {
242+
if (translations != null && translations.length != times.length) {
238243
translations = new Vector3f[times.length];
239244
}
240-
if (rotations != null && rotations.length < times.length) {
245+
if (rotations != null && rotations.length != times.length) {
241246
rotations = new Quaternion[times.length];
242247
}
243-
if (scales != null && scales.length < times.length) {
248+
if (scales != null && scales.length != times.length) {
244249
scales = new Vector3f[times.length];
245250
}
246251
}

0 commit comments

Comments
 (0)