Skip to content

Commit

Permalink
solve issue #1932 (class cast exceptions in FBX importer) (#1934)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold authored Jan 31, 2023
1 parent d313a32 commit c0efec4
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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;
}
}
}
}
}
Expand Down

0 comments on commit c0efec4

Please sign in to comment.