Skip to content

Commit

Permalink
glTF: fixed crashes with some models structure
Browse files Browse the repository at this point in the history
  • Loading branch information
Nehon committed Dec 10, 2017
1 parent 1b2cc6a commit a741dc6
Showing 1 changed file with 14 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,13 @@ protected Object loadFromStream(AssetInfo assetInfo, InputStream stream) throws

rootNode = customContentManager.readExtensionAndExtras("root", docRoot, rootNode);

//Loading animations
if (animations != null) {
for (int i = 0; i < animations.size(); i++) {
readAnimation(i);
}
}

setupControls();

//only one scene let's not return the root.
Expand Down Expand Up @@ -177,13 +184,6 @@ public void readScenes(JsonPrimitive defaultScene, Node rootNode) throws IOExcep

}

//Loading animations
if (animations != null) {
for (int i = 0; i < animations.size(); i++) {
readAnimation(i);
}
}

//Setting the default scene cul hint to inherit.
int activeChild = 0;
if (defaultScene != null) {
Expand Down Expand Up @@ -278,7 +278,10 @@ private void readChild(Spatial parent, JsonElement nodeIndex) throws IOException
BoneWrapper bw = (BoneWrapper) loaded;
bw.isRoot = true;
SkinData skinData = fetchFromCache("skins", bw.skinIndex, SkinData.class);
skinData.armatureTransforms = parent.getLocalTransform();
if (skinData == null) {
return;
}
skinData.parent = parent;
}

}
Expand Down Expand Up @@ -1086,15 +1089,13 @@ private void findChildren(int nodeIndex) throws IOException {
private void setupControls() {
for (SkinData skinData : skinnedSpatials.keySet()) {
List<Spatial> spatials = skinnedSpatials.get(skinData);
Spatial spatial;
if (spatials.isEmpty()) {
//can happen when a file contains a skin that is not used by any mesh...
continue;
}
Spatial spatial = skinData.parent;
if (spatials.size() >= 1) {
spatial = findCommonAncestor(spatials);
} else {
spatial = spatials.get(0);
}

AnimControl animControl = spatial.getControl(AnimControl.class);
Expand Down Expand Up @@ -1220,7 +1221,7 @@ public void update(TrackData data) {
Transform t = new Transform(translation, rotation, scale);
if (isRoot) {
//Apply the armature transforms to the root bone anim track.
t.combineWithParent(skinData.armatureTransforms);
t.combineWithParent(skinData.parent.getLocalTransform());
}

reverseBlendAnimTransforms(t, bindTransforms);
Expand Down Expand Up @@ -1285,50 +1286,11 @@ private Vector3f getScale(TrackData data, int i) {
private class SkinData {
SkeletonControl skeletonControl;
AnimControl animControl;
Transform armatureTransforms;
Spatial parent;
Bone[] bones;
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 {
short[] joints;
float[] weights;
Expand All @@ -1343,10 +1305,6 @@ public SkinBuffers() {
}
}

private class TextureData {
byte[] data;
}

private interface Populator<T> {
T populate(Integer bufferViewIndex, int componentType, String type, int count, int byteOffset, boolean normalized) throws IOException;
}
Expand Down

0 comments on commit a741dc6

Please sign in to comment.