aboutsummaryrefslogtreecommitdiffstats
path: root/ardor3d-extras
diff options
context:
space:
mode:
authorJulien Gouesse <[email protected]>2016-08-23 01:26:53 +0200
committerJulien Gouesse <[email protected]>2016-08-23 01:26:53 +0200
commitd1d551c39aa821bc3b35231151551590128d18a3 (patch)
tree578b04b7fc09918d879b0f4cad32ea82f8a638ec /ardor3d-extras
parentfaa8e2d970e22a516f818eb20a8e69f919c323e8 (diff)
Adds the support of texture coordinates contained by the vertices into the PLY importer
Diffstat (limited to 'ardor3d-extras')
-rw-r--r--ardor3d-extras/src/main/java/com/ardor3d/extension/model/ply/PlyDataStore.java7
-rw-r--r--ardor3d-extras/src/main/java/com/ardor3d/extension/model/ply/PlyGeometryStore.java18
-rw-r--r--ardor3d-extras/src/main/java/com/ardor3d/extension/model/ply/PlyImporter.java22
3 files changed, 42 insertions, 5 deletions
diff --git a/ardor3d-extras/src/main/java/com/ardor3d/extension/model/ply/PlyDataStore.java b/ardor3d-extras/src/main/java/com/ardor3d/extension/model/ply/PlyDataStore.java
index 8f184a4..14cd03b 100644
--- a/ardor3d-extras/src/main/java/com/ardor3d/extension/model/ply/PlyDataStore.java
+++ b/ardor3d-extras/src/main/java/com/ardor3d/extension/model/ply/PlyDataStore.java
@@ -14,6 +14,7 @@ import java.util.ArrayList;
import java.util.List;
import com.ardor3d.math.ColorRGBA;
+import com.ardor3d.math.Vector2;
import com.ardor3d.math.Vector3;
public class PlyDataStore {
@@ -21,12 +22,14 @@ public class PlyDataStore {
private final List<Vector3> _vertices;
private final List<Vector3> _normals;
private final List<ColorRGBA> _colors;
+ private final List<Vector2> _textureCoordinates;
public PlyDataStore() {
super();
_vertices = new ArrayList<>();
_normals = new ArrayList<>();
_colors = new ArrayList<>();
+ _textureCoordinates = new ArrayList<>();
}
public List<Vector3> getVertices() {
@@ -40,4 +43,8 @@ public class PlyDataStore {
public List<ColorRGBA> getColors() {
return _colors;
}
+
+ public List<Vector2> getTextureCoordinates() {
+ return _textureCoordinates;
+ }
}
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 f09364f..624665d 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
@@ -20,6 +20,7 @@ import java.util.logging.Logger;
import com.ardor3d.image.Texture;
import com.ardor3d.math.ColorRGBA;
+import com.ardor3d.math.Vector2;
import com.ardor3d.math.Vector3;
import com.ardor3d.math.type.ReadOnlyColorRGBA;
import com.ardor3d.renderer.IndexMode;
@@ -174,14 +175,16 @@ public class PlyGeometryStore {
if (_plyFaceInfoList != null) {
final String name = "ply_mesh" + _totalMeshes;
final Mesh mesh = new Mesh(name);
- boolean hasTexCoords = false;
+ boolean hasTexCoordsInFaces = false;
+ final boolean hasTexCoordsInVertices = _dataStore.getTextureCoordinates() != null
+ && !_dataStore.getTextureCoordinates().isEmpty();
final boolean hasNormals = _dataStore.getNormals() != null && !_dataStore.getNormals().isEmpty();
final boolean hasColors = _dataStore.getColors() != null && !_dataStore.getColors().isEmpty();
int vertexCount = 0;
for (final PlyFaceInfo plyFaceInfo : _plyFaceInfoList) {
vertexCount += plyFaceInfo.getVertexIndices().size();
if (plyFaceInfo.getTextureCoordinates() != null && !plyFaceInfo.getTextureCoordinates().isEmpty()) {
- hasTexCoords = true;
+ hasTexCoordsInFaces = true;
}
}
final FloatBuffer vertices = BufferUtils.createVector3Buffer(vertexCount);
@@ -190,7 +193,8 @@ public class PlyGeometryStore {
final FloatBuffer normals = hasNormals ? BufferUtils.createFloatBuffer(vertices.capacity()) : null;
final FloatBuffer colors = hasColors ? BufferUtils.createFloatBuffer(vertexCount * 4) : null;
- final FloatBuffer uvs = hasTexCoords ? BufferUtils.createFloatBuffer(vertexCount * 2) : null;
+ final FloatBuffer uvs = hasTexCoordsInFaces || hasTexCoordsInVertices
+ ? BufferUtils.createFloatBuffer(vertexCount * 2) : null;
int dummyVertexIndex = 0;
final List<IndexMode> indexModeList = new ArrayList<>();
@@ -238,9 +242,13 @@ public class PlyGeometryStore {
final ColorRGBA color = _dataStore.getColors().get(vertexIndex.intValue());
colors.put(color.getRed()).put(color.getGreen()).put(color.getBlue()).put(color.getAlpha());
}
+ if (hasTexCoordsInVertices) {
+ final Vector2 texCoords = _dataStore.getTextureCoordinates().get(vertexIndex.intValue());
+ uvs.put(texCoords.getXf()).put(texCoords.getYf());
+ }
dummyVertexIndex++;
}
- if (hasTexCoords) {
+ if (hasTexCoordsInFaces) {
for (final Float texCoord : plyFaceInfo.getTextureCoordinates()) {
uvs.put(texCoord);
}
@@ -274,7 +282,7 @@ public class PlyGeometryStore {
mesh.getMeshData().setColorBuffer(colors);
matchConditions.add(MatchCondition.Color);
}
- if (hasTexCoords) {
+ if (hasTexCoordsInFaces || hasTexCoordsInVertices) {
uvs.rewind();
mesh.getMeshData().setTextureBuffer(uvs, 0);
matchConditions.add(MatchCondition.UVs);
diff --git a/ardor3d-extras/src/main/java/com/ardor3d/extension/model/ply/PlyImporter.java b/ardor3d-extras/src/main/java/com/ardor3d/extension/model/ply/PlyImporter.java
index d0df119..bd4d7c8 100644
--- a/ardor3d-extras/src/main/java/com/ardor3d/extension/model/ply/PlyImporter.java
+++ b/ardor3d-extras/src/main/java/com/ardor3d/extension/model/ply/PlyImporter.java
@@ -41,6 +41,7 @@ import com.ardor3d.image.Texture;
import com.ardor3d.image.Texture.MinificationFilter;
import com.ardor3d.image.TextureStoreFormat;
import com.ardor3d.math.ColorRGBA;
+import com.ardor3d.math.Vector2;
import com.ardor3d.math.Vector3;
import com.ardor3d.util.TextureManager;
import com.ardor3d.util.geom.GeometryTool;
@@ -131,6 +132,10 @@ public class PlyImporter {
NY(Element.VERTEX, Element.CUSTOM),
/** normal z vector coordinate */
NZ(Element.VERTEX, Element.CUSTOM),
+ /** u texture coordinate */
+ S(Element.VERTEX, Element.CUSTOM),
+ /** v texture coordinate */
+ T(Element.VERTEX, Element.CUSTOM),
/** first vertex */
VERTEX1(Element.EDGE, Element.CUSTOM),
/** second vertex */
@@ -1086,6 +1091,7 @@ public class PlyImporter {
Vector3 vertex = null;
Vector3 normal = null;
ColorRGBA color = null;
+ Vector2 texCoords = null;
PlyMaterial material = null;
PlyEdgeInfo edgeInfo = null;
PlyFaceInfo faceInfo = null;
@@ -1480,6 +1486,22 @@ public class PlyImporter {
normal.setZ(value);
break;
}
+ case S: {
+ if (texCoords == null) {
+ texCoords = new Vector2();
+ store.getDataStore().getTextureCoordinates().add(texCoords);
+ }
+ texCoords.setX(value);
+ break;
+ }
+ case T: {
+ if (texCoords == null) {
+ texCoords = new Vector2();
+ store.getDataStore().getTextureCoordinates().add(texCoords);
+ }
+ texCoords.setY(value);
+ break;
+ }
case RED: {
if (color == null) {
color = new ColorRGBA();