glTF: Fixed when a sub graph is ttached to a bone. Fixed a crash with animation resampling
This commit is contained in:
parent
683bf632f6
commit
f47f865d1d
jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf
@ -1033,12 +1033,14 @@ public class GltfLoader implements AssetLoader {
|
|||||||
bw.bone.addChild(cbw.bone);
|
bw.bone.addChild(cbw.bone);
|
||||||
bw.children.add(childIndex);
|
bw.children.add(childIndex);
|
||||||
} else {
|
} else {
|
||||||
JsonObject childNode = nodes.get(childIndex).getAsJsonObject();
|
//The child might be a Node
|
||||||
//The child might be a Geom
|
//Creating a dummy node to reed the subgraph
|
||||||
if (getAsInteger(childNode, "mesh") != null) {
|
Node n = new Node();
|
||||||
//this is a geometry, let's load it as a spatial
|
readChild(n, child);
|
||||||
bw.attachedSpatial = (Spatial) readNode(childIndex);
|
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;
|
package com.jme3.scene.plugins.gltf;
|
||||||
|
|
||||||
|
import com.jme3.asset.AssetLoadException;
|
||||||
import com.jme3.math.*;
|
import com.jme3.math.*;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@ -119,9 +120,19 @@ public class TrackData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
checkTimesConsistantcy();
|
||||||
|
|
||||||
length = times[times.length - 1];
|
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) {
|
private void populateTransform(Type type, int index, List<KeyFrame> keyFrames, KeyFrame currentKeyFrame, TransformIndices transformIndices) {
|
||||||
Object transform = getTransform(type, currentKeyFrame);
|
Object transform = getTransform(type, currentKeyFrame);
|
||||||
if (transform != null) {
|
if (transform != null) {
|
||||||
@ -178,14 +189,8 @@ public class TrackData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int getNbKeyFrames(){
|
public int getNbKeyFrames(){
|
||||||
if(translations != null){
|
if (times != null) {
|
||||||
return translations.length;
|
return times.length;
|
||||||
}
|
|
||||||
if(rotations != null){
|
|
||||||
return rotations.length;
|
|
||||||
}
|
|
||||||
if(scales != null){
|
|
||||||
return scales.length;
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -234,13 +239,13 @@ public class TrackData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void ensureArraysLength() {
|
private void ensureArraysLength() {
|
||||||
if (translations != null && translations.length < times.length) {
|
if (translations != null && translations.length != times.length) {
|
||||||
translations = new Vector3f[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];
|
rotations = new Quaternion[times.length];
|
||||||
}
|
}
|
||||||
if (scales != null && scales.length < times.length) {
|
if (scales != null && scales.length != times.length) {
|
||||||
scales = new Vector3f[times.length];
|
scales = new Vector3f[times.length];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user