diff options
author | Julien Gouesse <[email protected]> | 2023-03-09 20:32:03 +0100 |
---|---|---|
committer | Julien Gouesse <[email protected]> | 2023-03-09 20:32:03 +0100 |
commit | 35f8ba658f9ac71f1971b27ca7f667fa74dceb6b (patch) | |
tree | 1850800a701f90121a68e5c894045525010621a2 | |
parent | cd411ffb5f093d1caed80af9df734f6af7f12126 (diff) |
Supports a map of indexed colors in the OFF importer
-rw-r--r-- | ardor3d-examples/src/main/java/com/ardor3d/example/pipeline/SimpleOffExample.java | 2 | ||||
-rw-r--r-- | ardor3d-extras/src/main/java/com/ardor3d/extension/model/off/OffImporter.java | 39 |
2 files changed, 38 insertions, 3 deletions
diff --git a/ardor3d-examples/src/main/java/com/ardor3d/example/pipeline/SimpleOffExample.java b/ardor3d-examples/src/main/java/com/ardor3d/example/pipeline/SimpleOffExample.java index 7ba4d2f..4f27d40 100644 --- a/ardor3d-examples/src/main/java/com/ardor3d/example/pipeline/SimpleOffExample.java +++ b/ardor3d-examples/src/main/java/com/ardor3d/example/pipeline/SimpleOffExample.java @@ -36,7 +36,7 @@ public class SimpleOffExample extends ExampleBase { // Load the OFF scene final long time = System.currentTimeMillis(); final OffImporter importer = new OffImporter(); - final OffGeometryStore storage = importer.load("off/socket.off"); + final OffGeometryStore storage = importer.load("off/mushroom.off"); System.out.println("Importing Took " + (System.currentTimeMillis() - time) + " ms"); final Node model = storage.getScene(); 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 ca2fcb3..77a8484 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 @@ -19,6 +19,7 @@ import java.io.StreamTokenizer; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; +import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; import java.util.stream.Collectors; @@ -84,10 +85,20 @@ public class OffImporter { private ResourceLocator _modelLocator; /** + * optional indexed color map + */ + private final Map<Integer, ColorRGBA> _colorMap; + + /** * Constructor. */ public OffImporter() { + this(null); + } + + public OffImporter(final Map<Integer, ColorRGBA> colorMap) { super(); + _colorMap = colorMap; } /** @@ -359,7 +370,19 @@ public class OffImporter { // nothing to do break; case 1: - // TODO store the color index somewhere + 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(), @@ -439,7 +462,19 @@ public class OffImporter { // no declared color break; case 1: - // TODO store the color index somewhere + final int colorIndex = valueList.get(vertexIndexCount + 1).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 { + faceInfo.setColor(indexedRgba); + } + } break; case 3: final ColorRGBA rgb = new ColorRGBA( |