glTF: fixed crashes with some models structure

empirephoenix-patch-1
Nehon 7 years ago
parent 1b2cc6a63b
commit a741dc66f4
  1. 70
      jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/GltfLoader.java

@ -127,6 +127,13 @@ public class GltfLoader implements AssetLoader {
rootNode = customContentManager.readExtensionAndExtras("root", docRoot, rootNode); rootNode = customContentManager.readExtensionAndExtras("root", docRoot, rootNode);
//Loading animations
if (animations != null) {
for (int i = 0; i < animations.size(); i++) {
readAnimation(i);
}
}
setupControls(); setupControls();
//only one scene let's not return the root. //only one scene let's not return the root.
@ -177,13 +184,6 @@ public class GltfLoader implements AssetLoader {
} }
//Loading animations
if (animations != null) {
for (int i = 0; i < animations.size(); i++) {
readAnimation(i);
}
}
//Setting the default scene cul hint to inherit. //Setting the default scene cul hint to inherit.
int activeChild = 0; int activeChild = 0;
if (defaultScene != null) { if (defaultScene != null) {
@ -278,7 +278,10 @@ public class GltfLoader implements AssetLoader {
BoneWrapper bw = (BoneWrapper) loaded; BoneWrapper bw = (BoneWrapper) loaded;
bw.isRoot = true; bw.isRoot = true;
SkinData skinData = fetchFromCache("skins", bw.skinIndex, SkinData.class); SkinData skinData = fetchFromCache("skins", bw.skinIndex, SkinData.class);
skinData.armatureTransforms = parent.getLocalTransform(); if (skinData == null) {
return;
}
skinData.parent = parent;
} }
} }
@ -1086,15 +1089,13 @@ public class GltfLoader implements AssetLoader {
private void setupControls() { private void setupControls() {
for (SkinData skinData : skinnedSpatials.keySet()) { for (SkinData skinData : skinnedSpatials.keySet()) {
List<Spatial> spatials = skinnedSpatials.get(skinData); List<Spatial> spatials = skinnedSpatials.get(skinData);
Spatial spatial;
if (spatials.isEmpty()) { if (spatials.isEmpty()) {
//can happen when a file contains a skin that is not used by any mesh... //can happen when a file contains a skin that is not used by any mesh...
continue; continue;
} }
Spatial spatial = skinData.parent;
if (spatials.size() >= 1) { if (spatials.size() >= 1) {
spatial = findCommonAncestor(spatials); spatial = findCommonAncestor(spatials);
} else {
spatial = spatials.get(0);
} }
AnimControl animControl = spatial.getControl(AnimControl.class); AnimControl animControl = spatial.getControl(AnimControl.class);
@ -1220,7 +1221,7 @@ public class GltfLoader implements AssetLoader {
Transform t = new Transform(translation, rotation, scale); Transform t = new Transform(translation, rotation, scale);
if (isRoot) { if (isRoot) {
//Apply the armature transforms to the root bone anim track. //Apply the armature transforms to the root bone anim track.
t.combineWithParent(skinData.armatureTransforms); t.combineWithParent(skinData.parent.getLocalTransform());
} }
reverseBlendAnimTransforms(t, bindTransforms); reverseBlendAnimTransforms(t, bindTransforms);
@ -1285,50 +1286,11 @@ public class GltfLoader implements AssetLoader {
private class SkinData { private class SkinData {
SkeletonControl skeletonControl; SkeletonControl skeletonControl;
AnimControl animControl; AnimControl animControl;
Transform armatureTransforms; Spatial parent;
Bone[] bones; Bone[] bones;
boolean used = false; boolean used = false;
} }
private class PartialTransforms {
Vector3f translation;
Quaternion rotation;
Vector3f scale;
Transform transform;
Transform getTransforms() {
if (transform == null) {
if (translation == null) {
translation = new Vector3f();
}
if (rotation == null) {
rotation = new Quaternion();
}
if (scale == null) {
scale = new Vector3f(1, 1, 1);
}
transform = new Transform(translation, rotation, scale);
}
return transform;
}
Transform getTransforms(Transform bindTransforms) {
if (transform == null) {
if (translation == null) {
translation = bindTransforms.getTranslation();
}
if (rotation == null) {
rotation = bindTransforms.getRotation();
}
if (scale == null) {
scale = bindTransforms.getScale();
}
transform = new Transform(translation, rotation, scale);
}
return transform;
}
}
public static class SkinBuffers { public static class SkinBuffers {
short[] joints; short[] joints;
float[] weights; float[] weights;
@ -1343,10 +1305,6 @@ public class GltfLoader implements AssetLoader {
} }
} }
private class TextureData {
byte[] data;
}
private interface Populator<T> { private interface Populator<T> {
T populate(Integer bufferViewIndex, int componentType, String type, int count, int byteOffset, boolean normalized) throws IOException; T populate(Integer bufferViewIndex, int componentType, String type, int count, int byteOffset, boolean normalized) throws IOException;
} }

Loading…
Cancel
Save