glTF: Fixed when a sub graph is ttached to a bone. Fixed a crash with animation resampling

empirephoenix-patch-1
Nehon 7 years ago
parent 683bf632f6
commit f47f865d1d
  1. 14
      jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/GltfLoader.java
  2. 27
      jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/TrackData.java

@ -1033,12 +1033,14 @@ public class GltfLoader implements AssetLoader {
bw.bone.addChild(cbw.bone);
bw.children.add(childIndex);
} else {
JsonObject childNode = nodes.get(childIndex).getAsJsonObject();
//The child might be a Geom
if (getAsInteger(childNode, "mesh") != null) {
//this is a geometry, let's load it as a spatial
bw.attachedSpatial = (Spatial) readNode(childIndex);
}
//The child might be a Node
//Creating a dummy node to reed the subgraph
Node n = new Node();
readChild(n, child);
Spatial s = n.getChild(0);
//removing the spatial from the dummy node, it will be attached to the attachment node of the bone
s.removeFromParent();
bw.attachedSpatial = s;
}
}

@ -1,5 +1,6 @@
package com.jme3.scene.plugins.gltf;
import com.jme3.asset.AssetLoadException;
import com.jme3.math.*;
import java.util.*;
@ -119,9 +120,19 @@ public class TrackData {
}
}
checkTimesConsistantcy();
length = times[times.length - 1];
}
public void checkTimesConsistantcy() {
if ((translations != null && times.length != translations.length)
|| (rotations != null && times.length != rotations.length)
|| (scales != null && times.length != scales.length)) {
throw new AssetLoadException("Inconsistent animation sampling ");
}
}
private void populateTransform(Type type, int index, List<KeyFrame> keyFrames, KeyFrame currentKeyFrame, TransformIndices transformIndices) {
Object transform = getTransform(type, currentKeyFrame);
if (transform != null) {
@ -178,14 +189,8 @@ public class TrackData {
}
public int getNbKeyFrames(){
if(translations != null){
return translations.length;
}
if(rotations != null){
return rotations.length;
}
if(scales != null){
return scales.length;
if (times != null) {
return times.length;
}
return 0;
}
@ -234,13 +239,13 @@ public class TrackData {
}
private void ensureArraysLength() {
if (translations != null && translations.length < times.length) {
if (translations != null && translations.length != times.length) {
translations = new Vector3f[times.length];
}
if (rotations != null && rotations.length < times.length) {
if (rotations != null && rotations.length != times.length) {
rotations = new Quaternion[times.length];
}
if (scales != null && scales.length < times.length) {
if (scales != null && scales.length != times.length) {
scales = new Vector3f[times.length];
}
}

Loading…
Cancel
Save