Skip to content

Commit c0efec4

Browse files
authored
solve issue #1932 (class cast exceptions in FBX importer) (#1934)
1 parent d313a32 commit c0efec4

File tree

2 files changed

+74
-15
lines changed

2 files changed

+74
-15
lines changed

jme3-plugins/src/fbx/java/com/jme3/scene/plugins/fbx/anim/FbxBindPose.java

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2009-2021 jMonkeyEngine
2+
* Copyright (c) 2009-2023 jMonkeyEngine
33
* All rights reserved.
44
*
55
* Redistribution and use in source and binary forms, with or without
@@ -62,18 +62,43 @@ public void fromElement(FbxElement element) {
6262
if (e.id.equals("Node")) {
6363
node = FbxId.create(e.properties.get(0));
6464
} else if (e.id.equals("Matrix")) {
65-
double[] matDataDoubles = (double[]) e.properties.get(0);
66-
67-
if (matDataDoubles.length != 16) {
68-
// corrupt
69-
throw new UnsupportedOperationException("Bind pose matrix "
70-
+ "must have 16 doubles, but it has "
71-
+ matDataDoubles.length + ". Data is corrupt");
72-
}
73-
7465
matData = new float[16];
75-
for (int i = 0; i < matDataDoubles.length; i++) {
76-
matData[i] = (float) matDataDoubles[i];
66+
int numProperties = e.propertiesTypes.length;
67+
if (numProperties == 1) {
68+
char propertyType = e.propertiesTypes[0];
69+
if (propertyType != 'd') {
70+
throw new UnsupportedOperationException(
71+
"Bind-pose matrix should have property type 'd',"
72+
+ "but found '" + propertyType + "'");
73+
}
74+
double[] array = (double[]) e.properties.get(0);
75+
int length = array.length;
76+
if (length != 16) {
77+
throw new UnsupportedOperationException(
78+
"Bind-pose matrix should have 16 elements,"
79+
+ "but found " + length);
80+
}
81+
for (int i = 0; i < length; ++i) {
82+
matData[i] = (float) array[i];
83+
}
84+
85+
} else if (numProperties == 16) {
86+
for (int i = 0; i < numProperties; ++i) {
87+
char propertyType = e.propertiesTypes[i];
88+
if (propertyType != 'D') {
89+
throw new UnsupportedOperationException(
90+
"Bind-pose matrix should have properties of type 'D',"
91+
+ "but found '" + propertyType + "'");
92+
}
93+
double d = (Double) e.properties.get(i);
94+
matData[i] = (float) d;
95+
}
96+
97+
} else {
98+
throw new UnsupportedOperationException(
99+
"Bind pose matrix should have either "
100+
+ "1 or 16 properties, but found "
101+
+ numProperties);
77102
}
78103
}
79104
}

jme3-plugins/src/fbx/java/com/jme3/scene/plugins/fbx/anim/FbxCluster.java

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2009-2015 jMonkeyEngine
2+
* Copyright (c) 2009-2023 jMonkeyEngine
33
* All rights reserved.
44
*
55
* Redistribution and use in source and binary forms, with or without
@@ -54,9 +54,43 @@ public void fromElement(FbxElement element) {
5454
super.fromElement(element);
5555
for (FbxElement e : element.children) {
5656
if (e.id.equals("Indexes")) {
57-
indexes = (int[]) e.properties.get(0);
57+
int numProperties = e.propertiesTypes.length;
58+
if (numProperties == 1 && e.propertiesTypes[0] == 'i') {
59+
this.indexes = (int[]) e.properties.get(0);
60+
61+
} else {
62+
this.indexes = new int[numProperties];
63+
for (int i = 0; i < numProperties; ++i) {
64+
char propertyType = e.propertiesTypes[i];
65+
if (propertyType != 'I') {
66+
throw new UnsupportedOperationException(
67+
"Indexes should have properties of type 'I',"
68+
+ "but found '" + propertyType + "'");
69+
}
70+
int index = (Integer) e.properties.get(i);
71+
this.indexes[i] = index;
72+
}
73+
}
74+
5875
} else if (e.id.equals("Weights")) {
59-
weights = (double[]) e.properties.get(0);
76+
int numTypes = e.propertiesTypes.length;
77+
if (numTypes == 1 && e.propertiesTypes[0] == 'd') {
78+
this.weights = (double[]) e.properties.get(0);
79+
80+
} else {
81+
int numElements = numTypes;
82+
this.weights = new double[numElements];
83+
for (int i = 0; i < numElements; ++i) {
84+
int propertyType = e.propertiesTypes[i];
85+
if (propertyType != 'D') {
86+
throw new UnsupportedOperationException(
87+
"Weights should have properties of type 'D',"
88+
+ "but found '" + propertyType + "'");
89+
}
90+
double weight = (Double) e.properties.get(i);
91+
this.weights[i] = weight;
92+
}
93+
}
6094
}
6195
}
6296
}

0 commit comments

Comments
 (0)