Skip to content

Commit

Permalink
feat: fix ply
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Pollind <[email protected]>
  • Loading branch information
pollend committed Aug 13, 2024
1 parent 2b98d24 commit f84c6c0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Forge/Formats/ply/TF_ply.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ bool tfPlyFindAttrib(FileStream* stream, struct TPlyReader* reader, size_t curso
for (size_t i = 0; i < arrlen(element->mAttributes); i++) {
struct TPlyAttribute* attrib = &element->mAttributes[i];
size_t numElements = 0;
offset += tfPlyReadAttribCount(stream, reader, offset, attrib, &numElements);
offset += tfPlyReadAttribCount(stream, reader, cursor, attrib, &numElements);
if(tfStrEqual(attrib->mName, attribName)) {
result->mType = attrib->attributeType;
result->mNumElement = numElements;
Expand Down
43 changes: 30 additions & 13 deletions Forge/tests/TF_PlyTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,49 +57,66 @@ end_header\n\
struct TPlyElement* element;
EXPECT_TRUE(tfPlySeekElementStream(&stream, &reader, tfCToStrRef("vertex"), &element, &cursor));

EXPECT_TRUE(tfPlyFindAttrib(&stream, &reader, cursor, &reader.mElements[0], tfCToStrRef("x"), &findAttrib));
EXPECT_TRUE(tfPlyFindAttrib(&stream, &reader, cursor, element, tfCToStrRef("x"), &findAttrib));
EXPECT_TRUE(tfPlyDecodeNumber(&stream, findAttrib.mCursor, reader.mFormat, findAttrib.mType, &number));
EXPECT_NEAR(number.flt, 0.0f, 0.0001f);

EXPECT_TRUE(tfPlyFindAttrib(&stream, &reader, cursor, &reader.mElements[0], tfCToStrRef("y"), &findAttrib));
EXPECT_TRUE(tfPlyFindAttrib(&stream, &reader, cursor, element, tfCToStrRef("y"), &findAttrib));
EXPECT_TRUE(tfPlyDecodeNumber(&stream, findAttrib.mCursor, reader.mFormat, findAttrib.mType, &number));
EXPECT_NEAR(number.flt, 0.0f, 0.0001f);

EXPECT_TRUE(tfPlyFindAttrib(&stream, &reader, cursor, &reader.mElements[0], tfCToStrRef("z"), &findAttrib));
EXPECT_TRUE(tfPlyFindAttrib(&stream, &reader, cursor, element, tfCToStrRef("z"), &findAttrib));
EXPECT_TRUE(tfPlyDecodeNumber(&stream, findAttrib.mCursor, reader.mFormat, findAttrib.mType, &number));
EXPECT_NEAR(number.flt, 0.0f, 0.0001f);

cursor += tfPlyNextElement(&stream, &reader, cursor, &reader.mElements[0]);
cursor += tfPlyNextElement(&stream, &reader, cursor, element);

EXPECT_TRUE(tfPlyFindAttrib(&stream, &reader, cursor, &reader.mElements[0], tfCToStrRef("x"), &findAttrib));
EXPECT_TRUE(tfPlyFindAttrib(&stream, &reader, cursor, element, tfCToStrRef("x"), &findAttrib));
EXPECT_TRUE(tfPlyDecodeNumber(&stream, findAttrib.mCursor, reader.mFormat, findAttrib.mType, &number));
EXPECT_NEAR(number.flt, 0.0f, 0.0001f);

EXPECT_TRUE(tfPlyFindAttrib(&stream, &reader, cursor, &reader.mElements[0], tfCToStrRef("y"), &findAttrib));
EXPECT_TRUE(tfPlyFindAttrib(&stream, &reader, cursor, element, tfCToStrRef("y"), &findAttrib));
EXPECT_TRUE(tfPlyDecodeNumber(&stream, findAttrib.mCursor, reader.mFormat, findAttrib.mType, &number));
EXPECT_NEAR(number.flt, 1.0f, 0.0001f);

EXPECT_TRUE(tfPlyFindAttrib(&stream, &reader, cursor, &reader.mElements[0], tfCToStrRef("z"), &findAttrib));
EXPECT_TRUE(tfPlyFindAttrib(&stream, &reader, cursor, element, tfCToStrRef("z"), &findAttrib));
EXPECT_TRUE(tfPlyDecodeNumber(&stream, findAttrib.mCursor, reader.mFormat, findAttrib.mType, &number));
EXPECT_NEAR(number.flt, 1.0f, 0.0001f);

cursor += tfPlyNextElement(&stream, &reader, cursor, &reader.mElements[0]);
cursor += tfPlyNextElement(&stream, &reader, cursor, element);

EXPECT_TRUE(tfPlyFindAttrib(&stream, &reader, cursor, &reader.mElements[0], tfCToStrRef("x"), &findAttrib));
EXPECT_TRUE(tfPlyFindAttrib(&stream, &reader, cursor, element, tfCToStrRef("x"), &findAttrib));
EXPECT_TRUE(tfPlyDecodeNumber(&stream, findAttrib.mCursor, reader.mFormat, findAttrib.mType, &number));
EXPECT_NEAR(number.flt, 1.0f, 0.0001f);

EXPECT_TRUE(tfPlyFindAttrib(&stream, &reader, cursor, &reader.mElements[0], tfCToStrRef("y"), &findAttrib));
EXPECT_TRUE(tfPlyFindAttrib(&stream, &reader, cursor, element, tfCToStrRef("y"), &findAttrib));
EXPECT_TRUE(tfPlyDecodeNumber(&stream, findAttrib.mCursor, reader.mFormat, findAttrib.mType, &number));
EXPECT_NEAR(number.flt, 0.0f, 0.0001f);

EXPECT_TRUE(tfPlyFindAttrib(&stream, &reader, cursor, &reader.mElements[0], tfCToStrRef("z"), &findAttrib));
EXPECT_TRUE(tfPlyFindAttrib(&stream, &reader, cursor, element, tfCToStrRef("z"), &findAttrib));
EXPECT_TRUE(tfPlyDecodeNumber(&stream, findAttrib.mCursor, reader.mFormat, findAttrib.mType, &number));
EXPECT_NEAR(number.flt, 1.0f, 0.0001f);

EXPECT_TRUE(tfPlySeekElementStream(&stream, &reader, tfCToStrRef("face"), &element, &cursor));
EXPECT_TRUE(tfPlyFindAttrib(&stream, &reader, cursor, &reader.mElements[0], tfCToStrRef("vertex_indices"), &findAttrib));

EXPECT_TRUE(tfPlyFindAttrib(&stream, &reader, cursor, element, tfCToStrRef("vertex_indices"), &findAttrib));
EXPECT_EQ(findAttrib.mNumElement, 3);
EXPECT_TRUE(tfPlyDecodeNumber(&stream, findAttrib.mCursor, reader.mFormat, findAttrib.mType, &number));
EXPECT_EQ(number.i32, 0);
EXPECT_TRUE(tfPlyDecodeNumber(&stream, findAttrib.mCursor + findAttrib.mStride, reader.mFormat, findAttrib.mType, &number));
EXPECT_EQ(number.i32, 1);
EXPECT_TRUE(tfPlyDecodeNumber(&stream, findAttrib.mCursor + (findAttrib.mStride * 2), reader.mFormat, findAttrib.mType, &number));
EXPECT_EQ(number.i32, 2);

cursor += tfPlyNextElement(&stream, &reader, cursor, element);

EXPECT_TRUE(tfPlyFindAttrib(&stream, &reader, cursor, element, tfCToStrRef("vertex_indices"), &findAttrib));
EXPECT_EQ(findAttrib.mNumElement, 3);
EXPECT_TRUE(tfPlyDecodeNumber(&stream, findAttrib.mCursor, reader.mFormat, findAttrib.mType, &number));
EXPECT_EQ(number.i32, 0);
EXPECT_TRUE(tfPlyDecodeNumber(&stream, findAttrib.mCursor + findAttrib.mStride, reader.mFormat, findAttrib.mType, &number));
EXPECT_EQ(number.i32, 2);
EXPECT_TRUE(tfPlyDecodeNumber(&stream, findAttrib.mCursor + (findAttrib.mStride * 2), reader.mFormat, findAttrib.mType, &number));
EXPECT_EQ(number.i32, 3);

fsCloseStream(&stream);
tfFreePlyFileReader(&reader);
Expand Down

0 comments on commit f84c6c0

Please sign in to comment.