aboutsummaryrefslogtreecommitdiffstats
path: root/ardor3d-extras
diff options
context:
space:
mode:
authorJulien Gouesse <[email protected]>2023-03-09 20:45:55 +0100
committerJulien Gouesse <[email protected]>2023-03-09 20:45:55 +0100
commit30b3a2915914c7776b1722423cb3005f6b2c7dfc (patch)
tree92f29add56800c04ec7eeecb7a8f85f7f754d9b0 /ardor3d-extras
parent35f8ba658f9ac71f1971b27ca7f667fa74dceb6b (diff)
Supports the vertex data in all known orders in the OFF importer
Diffstat (limited to 'ardor3d-extras')
-rw-r--r--ardor3d-extras/src/main/java/com/ardor3d/extension/model/off/OffDimensionInfo.java4
-rw-r--r--ardor3d-extras/src/main/java/com/ardor3d/extension/model/off/OffImporter.java144
2 files changed, 83 insertions, 65 deletions
diff --git a/ardor3d-extras/src/main/java/com/ardor3d/extension/model/off/OffDimensionInfo.java b/ardor3d-extras/src/main/java/com/ardor3d/extension/model/off/OffDimensionInfo.java
index 1bc3db0..b3382f1 100644
--- a/ardor3d-extras/src/main/java/com/ardor3d/extension/model/off/OffDimensionInfo.java
+++ b/ardor3d-extras/src/main/java/com/ardor3d/extension/model/off/OffDimensionInfo.java
@@ -611,4 +611,8 @@ final class OffDimensionInfo {
boolean hasHomogeneousComponent() {
return offKeyword.hasHomogeneousComponent();
}
+
+ LinkedHashSet<OffKeywordVertexDataComponentId> getComponentSet() {
+ return offKeyword.getComponentSet();
+ }
}
diff --git a/ardor3d-extras/src/main/java/com/ardor3d/extension/model/off/OffImporter.java b/ardor3d-extras/src/main/java/com/ardor3d/extension/model/off/OffImporter.java
index 77a8484..59d28d4 100644
--- a/ardor3d-extras/src/main/java/com/ardor3d/extension/model/off/OffImporter.java
+++ b/ardor3d-extras/src/main/java/com/ardor3d/extension/model/off/OffImporter.java
@@ -25,6 +25,7 @@ import java.util.logging.Logger;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
+import com.ardor3d.extension.model.off.OffDimensionInfo.OffKeywordVertexDataComponentId;
import com.ardor3d.math.ColorRGBA;
import com.ardor3d.math.Vector2;
import com.ardor3d.math.Vector3;
@@ -344,72 +345,85 @@ public class OffImporter {
break;
}
int nextIndex = offDimensionInfo.getVertexValuesPerTuple();
- switch (offDimensionInfo.getNormalValuesPerTuple()) {
- case 0:
- // nothing to do
- break;
- case 1:
- store.getDataStore().getNormals()
- .add(new Vector3(valueList.get(nextIndex).doubleValue(), 0.0d, 0.0d));
- break;
- case 2:
- store.getDataStore().getNormals()
- .add(new Vector3(valueList.get(nextIndex).doubleValue(),
- valueList.get(nextIndex + 1).doubleValue(), 0.0d));
- break;
- case 3:
- store.getDataStore().getNormals()
- .add(new Vector3(valueList.get(nextIndex).doubleValue(),
- valueList.get(nextIndex + 1).doubleValue(),
- valueList.get(nextIndex + 2).doubleValue()));
- break;
- }
- nextIndex += offDimensionInfo.getNormalValuesPerTuple();
- switch (colorValuesPerTuple) {
- case 0:
- // nothing to do
- break;
- case 1:
- final int colorIndex = valueList.get(nextIndex).intValue();
- if (_colorMap == null) {
- OffImporter.LOGGER.log(Level.WARNING,
- "Color index found but no color map passed to the importer");
- } else {
- final ColorRGBA indexedRgba = _colorMap.get(Integer.valueOf(colorIndex));
- if (indexedRgba == null) {
- OffImporter.LOGGER.log(Level.WARNING,
- "No color found at the index " + colorIndex + " in the color map");
- } else {
- store.getDataStore().getColors().add(indexedRgba);
+ for (final OffKeywordVertexDataComponentId vertexDataComponentId : offDimensionInfo
+ .getComponentSet()) {
+ switch (vertexDataComponentId) {
+ case NORMAL:
+ switch (offDimensionInfo.getNormalValuesPerTuple()) {
+ case 0:
+ // nothing to do
+ break;
+ case 1:
+ store.getDataStore().getNormals().add(
+ new Vector3(valueList.get(nextIndex).doubleValue(), 0.0d, 0.0d));
+ break;
+ case 2:
+ store.getDataStore().getNormals()
+ .add(new Vector3(valueList.get(nextIndex).doubleValue(),
+ valueList.get(nextIndex + 1).doubleValue(), 0.0d));
+ break;
+ case 3:
+ store.getDataStore().getNormals()
+ .add(new Vector3(valueList.get(nextIndex).doubleValue(),
+ valueList.get(nextIndex + 1).doubleValue(),
+ valueList.get(nextIndex + 2).doubleValue()));
+ break;
}
- }
- break;
- case 3:
- final ColorRGBA rgb = new ColorRGBA(valueList.get(nextIndex).floatValue(),
- valueList.get(nextIndex + 1).floatValue(),
- valueList.get(nextIndex + 2).floatValue(), 0.0f);
- if (valueList.get(nextIndex) instanceof Integer) {
- rgb.divideLocal(255.0f);
- }
- rgb.setAlpha(1.0f);
- store.getDataStore().getColors().add(rgb);
- break;
- case 4:
- final ColorRGBA rgba = new ColorRGBA(valueList.get(nextIndex).floatValue(),
- valueList.get(nextIndex + 1).floatValue(),
- valueList.get(nextIndex + 2).floatValue(),
- valueList.get(nextIndex + 3).floatValue());
- if (valueList.get(nextIndex) instanceof Integer) {
- rgba.divideLocal(255.0f);
- }
- store.getDataStore().getColors().add(rgba);
- break;
- }
- nextIndex += colorValuesPerTuple;
- if (offDimensionInfo.getTextureValuesPerTuple() == 2) {
- store.getDataStore().getTextureCoordinates()
- .add(new Vector2(valueList.get(nextIndex).doubleValue(),
- valueList.get(nextIndex + 1).doubleValue()));
+ nextIndex += offDimensionInfo.getNormalValuesPerTuple();
+ break;
+ case COLOR:
+ switch (colorValuesPerTuple) {
+ case 0:
+ // nothing to do
+ break;
+ case 1:
+ final int colorIndex = valueList.get(nextIndex).intValue();
+ if (_colorMap == null) {
+ OffImporter.LOGGER.log(Level.WARNING,
+ "Color index found but no color map passed to the importer");
+ } else {
+ final ColorRGBA indexedRgba = _colorMap
+ .get(Integer.valueOf(colorIndex));
+ if (indexedRgba == null) {
+ OffImporter.LOGGER.log(Level.WARNING, "No color found at the index "
+ + colorIndex + " in the color map");
+ } else {
+ store.getDataStore().getColors().add(indexedRgba);
+ }
+ }
+ break;
+ case 3:
+ final ColorRGBA rgb = new ColorRGBA(valueList.get(nextIndex).floatValue(),
+ valueList.get(nextIndex + 1).floatValue(),
+ valueList.get(nextIndex + 2).floatValue(), 0.0f);
+ if (valueList.get(nextIndex) instanceof Integer) {
+ rgb.divideLocal(255.0f);
+ }
+ rgb.setAlpha(1.0f);
+ store.getDataStore().getColors().add(rgb);
+ break;
+ case 4:
+ final ColorRGBA rgba = new ColorRGBA(valueList.get(nextIndex).floatValue(),
+ valueList.get(nextIndex + 1).floatValue(),
+ valueList.get(nextIndex + 2).floatValue(),
+ valueList.get(nextIndex + 3).floatValue());
+ if (valueList.get(nextIndex) instanceof Integer) {
+ rgba.divideLocal(255.0f);
+ }
+ store.getDataStore().getColors().add(rgba);
+ break;
+ }
+ nextIndex += colorValuesPerTuple;
+ break;
+ case TEXTURE:
+ if (offDimensionInfo.getTextureValuesPerTuple() == 2) {
+ store.getDataStore().getTextureCoordinates()
+ .add(new Vector2(valueList.get(nextIndex).doubleValue(),
+ valueList.get(nextIndex + 1).doubleValue()));
+ }
+ nextIndex += offDimensionInfo.getTextureValuesPerTuple();
+ break;
+ }
}
}
for (int faceIndex = 0; faceIndex < numberOfFaces.intValue(); faceIndex++) {