diff --git a/jme3-plugins/src/fbx/java/com/jme3/scene/plugins/fbx/anim/FbxBindPose.java b/jme3-plugins/src/fbx/java/com/jme3/scene/plugins/fbx/anim/FbxBindPose.java index cd701e5066..45b71b224a 100644 --- a/jme3-plugins/src/fbx/java/com/jme3/scene/plugins/fbx/anim/FbxBindPose.java +++ b/jme3-plugins/src/fbx/java/com/jme3/scene/plugins/fbx/anim/FbxBindPose.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009-2021 jMonkeyEngine + * Copyright (c) 2009-2023 jMonkeyEngine * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -62,18 +62,43 @@ public void fromElement(FbxElement element) { if (e.id.equals("Node")) { node = FbxId.create(e.properties.get(0)); } else if (e.id.equals("Matrix")) { - double[] matDataDoubles = (double[]) e.properties.get(0); - - if (matDataDoubles.length != 16) { - // corrupt - throw new UnsupportedOperationException("Bind pose matrix " - + "must have 16 doubles, but it has " - + matDataDoubles.length + ". Data is corrupt"); - } - matData = new float[16]; - for (int i = 0; i < matDataDoubles.length; i++) { - matData[i] = (float) matDataDoubles[i]; + int numProperties = e.propertiesTypes.length; + if (numProperties == 1) { + char propertyType = e.propertiesTypes[0]; + if (propertyType != 'd') { + throw new UnsupportedOperationException( + "Bind-pose matrix should have property type 'd'," + + "but found '" + propertyType + "'"); + } + double[] array = (double[]) e.properties.get(0); + int length = array.length; + if (length != 16) { + throw new UnsupportedOperationException( + "Bind-pose matrix should have 16 elements," + + "but found " + length); + } + for (int i = 0; i < length; ++i) { + matData[i] = (float) array[i]; + } + + } else if (numProperties == 16) { + for (int i = 0; i < numProperties; ++i) { + char propertyType = e.propertiesTypes[i]; + if (propertyType != 'D') { + throw new UnsupportedOperationException( + "Bind-pose matrix should have properties of type 'D'," + + "but found '" + propertyType + "'"); + } + double d = (Double) e.properties.get(i); + matData[i] = (float) d; + } + + } else { + throw new UnsupportedOperationException( + "Bind pose matrix should have either " + + "1 or 16 properties, but found " + + numProperties); } } } diff --git a/jme3-plugins/src/fbx/java/com/jme3/scene/plugins/fbx/anim/FbxCluster.java b/jme3-plugins/src/fbx/java/com/jme3/scene/plugins/fbx/anim/FbxCluster.java index 3065ce88c3..45801fc353 100644 --- a/jme3-plugins/src/fbx/java/com/jme3/scene/plugins/fbx/anim/FbxCluster.java +++ b/jme3-plugins/src/fbx/java/com/jme3/scene/plugins/fbx/anim/FbxCluster.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009-2015 jMonkeyEngine + * Copyright (c) 2009-2023 jMonkeyEngine * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -54,9 +54,43 @@ public void fromElement(FbxElement element) { super.fromElement(element); for (FbxElement e : element.children) { if (e.id.equals("Indexes")) { - indexes = (int[]) e.properties.get(0); + int numProperties = e.propertiesTypes.length; + if (numProperties == 1 && e.propertiesTypes[0] == 'i') { + this.indexes = (int[]) e.properties.get(0); + + } else { + this.indexes = new int[numProperties]; + for (int i = 0; i < numProperties; ++i) { + char propertyType = e.propertiesTypes[i]; + if (propertyType != 'I') { + throw new UnsupportedOperationException( + "Indexes should have properties of type 'I'," + + "but found '" + propertyType + "'"); + } + int index = (Integer) e.properties.get(i); + this.indexes[i] = index; + } + } + } else if (e.id.equals("Weights")) { - weights = (double[]) e.properties.get(0); + int numTypes = e.propertiesTypes.length; + if (numTypes == 1 && e.propertiesTypes[0] == 'd') { + this.weights = (double[]) e.properties.get(0); + + } else { + int numElements = numTypes; + this.weights = new double[numElements]; + for (int i = 0; i < numElements; ++i) { + int propertyType = e.propertiesTypes[i]; + if (propertyType != 'D') { + throw new UnsupportedOperationException( + "Weights should have properties of type 'D'," + + "but found '" + propertyType + "'"); + } + double weight = (Double) e.properties.get(i); + this.weights[i] = weight; + } + } } } }