Skip to content

Commit

Permalink
PLY
Browse files Browse the repository at this point in the history
- Fixed endian issue when reading/writing polyline
  • Loading branch information
lessthanoptimal committed Dec 21, 2023
1 parent bb75cb1 commit 06c01de
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ public static void saveBinary( PlyWriter data, ByteOrder order, boolean saveAsFl

var indexes = new int[100];
bytes = ByteBuffer.allocate(1 + indexes.length*4);
bytes.order(order);
for (int i = 0; i < data.getPolygonCount(); i++) {
int size = data.getIndexes(i, indexes);
bytes.position(0);
Expand Down Expand Up @@ -467,6 +468,7 @@ private static void readCloudBinary( PlyReader output, InputStream reader, List<

final var polygonLine = new byte[4*10];
final ByteBuffer polygonBB = ByteBuffer.wrap(polygonLine);
polygonBB.order(order);
int[] indexes = new int[100];
for (int i = 0; i < triangleCount; i++) {
if (1 != reader.read(line, 0, 1))
Expand All @@ -482,7 +484,10 @@ private static void readCloudBinary( PlyReader output, InputStream reader, List<
throw new IOException("Read unexpected number of bytes. " + found + " vs " + lineLength);

for (int wordIndex = 0; wordIndex < count; wordIndex++) {
indexes[wordIndex] = polygonBB.getInt(wordIndex*4);
int foundIndex = polygonBB.getInt(wordIndex*4);
if (foundIndex < 0 || foundIndex > vertexCount)
throw new IOException("Negative index. word: " + wordIndex + " value: " + foundIndex + " count: " + vertexCount);
indexes[wordIndex] = foundIndex;
}

output.addPolygon(indexes, 0, count);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,14 @@ class TestPlyCodec extends BoofStandardJUnit {
for (var endian : new ByteOrder[]{ByteOrder.LITTLE_ENDIAN, ByteOrder.BIG_ENDIAN}) {
var mesh = new VertexMesh();
mesh.offsets.add(0);
for (int i = 0; i < 10; i++) {
int numVertexes = 10;
for (int i = 0; i < numVertexes; i++) {
mesh.vertexes.append(i, 2, 3);
mesh.indexes.add(i*3);
mesh.indexes.add(i*3 + 1);
mesh.indexes.add(i*3 + 2);

// bound indexes to ensure they are in the valid range
mesh.indexes.add((i*3)%numVertexes);
mesh.indexes.add((i*3 + 1)%numVertexes);
mesh.indexes.add((i*3 + 2)%numVertexes);
mesh.offsets.add(mesh.indexes.size);
}
var colors = new DogArray_I32();
Expand Down

0 comments on commit 06c01de

Please sign in to comment.