aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulien Gouesse <[email protected]>2016-08-20 17:05:04 +0200
committerJulien Gouesse <[email protected]>2016-08-20 17:05:04 +0200
commit0a07ac2f112dea679de95ac4a352a02bd663ea36 (patch)
tree185bebe4a5d00c9fcf745204608b07b901142651
parent4edc4e55928c3d91e177eceda4179609456c1f2e (diff)
Adds the support of edges into the PLY importer
-rw-r--r--ardor3d-extras/src/main/java/com/ardor3d/extension/model/ply/PlyGeometryStore.java49
1 files changed, 46 insertions, 3 deletions
diff --git a/ardor3d-extras/src/main/java/com/ardor3d/extension/model/ply/PlyGeometryStore.java b/ardor3d-extras/src/main/java/com/ardor3d/extension/model/ply/PlyGeometryStore.java
index a488823..6f5273c 100644
--- a/ardor3d-extras/src/main/java/com/ardor3d/extension/model/ply/PlyGeometryStore.java
+++ b/ardor3d-extras/src/main/java/com/ardor3d/extension/model/ply/PlyGeometryStore.java
@@ -21,9 +21,11 @@ import java.util.logging.Logger;
import com.ardor3d.image.Texture;
import com.ardor3d.math.ColorRGBA;
import com.ardor3d.math.Vector3;
+import com.ardor3d.math.type.ReadOnlyColorRGBA;
import com.ardor3d.renderer.IndexMode;
import com.ardor3d.renderer.state.TextureState;
import com.ardor3d.scenegraph.IndexBufferData;
+import com.ardor3d.scenegraph.Line;
import com.ardor3d.scenegraph.Mesh;
import com.ardor3d.scenegraph.Node;
import com.ardor3d.util.geom.BufferUtils;
@@ -36,6 +38,8 @@ public class PlyGeometryStore {
private int _totalMeshes = 0;
+ private int _totalLines = 0;
+
private final PlyDataStore _dataStore;
private final Node _root;
@@ -118,7 +122,47 @@ public class PlyGeometryStore {
@SuppressWarnings("null")
void commitObjects() {
if (_plyEdgeInfoList != null) {
- // TODO
+ final String name = "ply_line" + _totalLines;
+ boolean hasColors = false;
+ final boolean hasNormals = _dataStore.getNormals() != null && !_dataStore.getNormals().isEmpty();
+ final int vertexCount = _plyEdgeInfoList.size() * 2;
+ final Vector3[] vertices = new Vector3[vertexCount];
+ final Vector3[] normals = hasNormals ? null : new Vector3[vertexCount];
+ ReadOnlyColorRGBA[] colors = null;
+ final IndexBufferData<? extends Buffer> indices = BufferUtils.createIndexBufferData(vertexCount,
+ vertexCount - 1);
+ int edgeVertexIndex = 0;
+ for (final PlyEdgeInfo plyEdgeInfo : _plyEdgeInfoList) {
+ indices.put(edgeVertexIndex).put(edgeVertexIndex + 1);
+ vertices[edgeVertexIndex] = _dataStore.getVertices().get(plyEdgeInfo.getIndex1());
+ vertices[edgeVertexIndex + 1] = _dataStore.getVertices().get(plyEdgeInfo.getIndex2());
+ if (hasNormals) {
+ normals[edgeVertexIndex] = _dataStore.getNormals().get(plyEdgeInfo.getIndex1());
+ normals[edgeVertexIndex + 1] = _dataStore.getNormals().get(plyEdgeInfo.getIndex2());
+ }
+ if (plyEdgeInfo.getColor() != null) {
+ if (colors == null) {
+ colors = new ReadOnlyColorRGBA[vertexCount];
+ }
+ colors[edgeVertexIndex] = plyEdgeInfo.getColor();
+ colors[edgeVertexIndex + 1] = plyEdgeInfo.getColor();
+ hasColors = true;
+ }
+ edgeVertexIndex += 2;
+ }
+ final Line line = new Line(name, vertices, normals, colors, null);
+ indices.rewind();
+ line.getMeshData().setIndices(indices);
+ final EnumSet<MatchCondition> matchConditions = EnumSet.noneOf(MatchCondition.class);
+ if (hasNormals) {
+ matchConditions.add(MatchCondition.Normal);
+ }
+ if (hasColors) {
+ matchConditions.add(MatchCondition.Color);
+ }
+ _geometryTool.minimizeVerts(line, matchConditions);
+ line.updateModelBound();
+ _totalLines++;
_plyEdgeInfoList = null;
}
if (_plyFaceInfoList != null) {
@@ -127,7 +171,6 @@ public class PlyGeometryStore {
boolean hasTexCoords = false;
final boolean hasNormals = _dataStore.getNormals() != null && !_dataStore.getNormals().isEmpty();
final boolean hasColors = _dataStore.getColors() != null && !_dataStore.getColors().isEmpty();
- // FIXME sort the faces by vertex count per face, puts them into distinct regions
int vertexCount = 0;
for (final PlyFaceInfo plyFaceInfo : _plyFaceInfoList) {
vertexCount += plyFaceInfo.getVertexIndices().size();
@@ -144,7 +187,6 @@ public class PlyGeometryStore {
final FloatBuffer uvs = hasTexCoords ? BufferUtils.createFloatBuffer(vertexCount * 2) : null;
// FIXME handle material indices if any
- final EnumSet<MatchCondition> matchConditions = EnumSet.noneOf(MatchCondition.class);
int dummyVertexIndex = 0;
final List<IndexMode> indexModeList = new ArrayList<>();
final List<Integer> indexLengthList = new ArrayList<>();
@@ -216,6 +258,7 @@ public class PlyGeometryStore {
}
mesh.getMeshData().setIndexLengths(indexLengths);
}
+ final EnumSet<MatchCondition> matchConditions = EnumSet.noneOf(MatchCondition.class);
if (hasNormals) {
normals.rewind();
mesh.getMeshData().setNormalBuffer(normals);