Skip to content

Commit

Permalink
Replace models in integration tests, fix ASCII writer for UB4 attributes
Browse files Browse the repository at this point in the history
- Remove models with unclear license
- Use test CMOD file with a wider selection of attributes
- Use simple icosphere model to test 3DS loader
  • Loading branch information
ajtribick committed Jun 7, 2024
1 parent 2b3ec56 commit 2c9c78e
Show file tree
Hide file tree
Showing 13 changed files with 76 additions and 17 deletions.
3 changes: 2 additions & 1 deletion src/celmodel/modelfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1012,6 +1012,7 @@ AsciiModelWriter::writeVertex(const cmod::VWord* vertexData,
}

const VWord* data = vertexData + attr.offsetWords;
auto databytes = reinterpret_cast<const unsigned char*>(data); //NOSONAR
std::array<float, 4> fdata;

switch (attr.format)
Expand All @@ -1033,7 +1034,7 @@ AsciiModelWriter::writeVertex(const cmod::VWord* vertexData,
fmt::print(*out, "{} {} {} {}", fdata[0], fdata[1], fdata[2], fdata[3]);
break;
case VertexAttributeFormat::UByte4:
fmt::print(*out, "{} {} {} {}", +data[0], +data[1], +data[2], +data[3]);
fmt::print(*out, "{} {} {} {}", +databytes[0], +databytes[1], +databytes[2], +databytes[3]);
break;
default:
assert(0);
Expand Down
Binary file removed test/data/huygens.3ds
Binary file not shown.
Binary file added test/data/icosphere.3ds
Binary file not shown.
3 changes: 3 additions & 0 deletions test/data/icosphere.3ds.license
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SPDX-FileCopyrightText: 2024 Andrew Tribick

SPDX-License-Identifier: CC0-1.0
7 changes: 0 additions & 7 deletions test/data/iss/iss.ssc

This file was deleted.

Binary file removed test/data/iss/models/iss.cmod
Binary file not shown.
Binary file added test/data/testmodel.cmod
Binary file not shown.
3 changes: 3 additions & 0 deletions test/data/testmodel.cmod.license
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SPDX-FileCopyrightText: 2024 Andrew Tribick

SPDX-License-Identifier: CC0-1.0
56 changes: 56 additions & 0 deletions test/data/testmodel.cmod.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#celmodel__ascii

material
diffuse 0.0 0.25 0.75
emissive 1.0 0.50 0.0
opacity 0.5
specpower 0.3
opacity 0.25
texture0 "abc.jpeg"
normalmap "def.png"
specularmap "ghi.jpg"
emissivemap "zyx.png"
end_material

material
diffuse 0.5 0.25 0.625
end_material

mesh

vertexdesc
position f3
normal f3
color0 ub4
color1 ub4
tangent f3
texcoord0 f2
texcoord1 f2
texcoord2 f2
texcoord3 f2
end_vertexdesc

vertices 3
7.296079 11.248578 9.22705 5.2277236 -10.1726 -8.392048 45 109 146 226 71 44 179 211 -0 5.5343466 -9.530685 -0.3390279 4.252959 -7.28864 8.539534 -6.3209734 0 6.382264 -10.71377
1.6738018 1.8557296 -11.874223 11.38663 0.19100569 0.58637905 59 93 244 125 213 24 135 182 15.036114 -1.141086 12.600051 2.1498501 2.9668765 -15.088427 -12.589463 12.911113 -6.021534 11.512148 -15.626732
-9.80907 11.435033 9.9803095 -11.550884 -2.126639 -9.997762 55 126 178 225 249 69 173 11 -5.527182 -15.229529 -5.2998743 6.1232743 5.819463 -0.08893819 -1.8737017 13.035601 -0.87161326 10.813936 -10.861176

trilist 0 3
0 1 2

tristrip 1 3
1 2 0

trifan 0 3
2 1 0

linelist 0 3
0 2 1

linestrip 1 3
1 0 2

points 1 3
2 0 1

end_mesh
3 changes: 3 additions & 0 deletions test/data/testmodel.cmod.txt.license
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SPDX-FileCopyrightText: 2024 Andrew Tribick

SPDX-License-Identifier: CC0-1.0
12 changes: 6 additions & 6 deletions test/integration/3ds_load_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ TEST_SUITE_BEGIN("3ds integration");

TEST_CASE("Load a 3DS file")
{
std::unique_ptr<M3DScene> scene = Read3DSFile("huygens.3ds");
std::unique_ptr<M3DScene> scene = Read3DSFile("icosphere.3ds");
REQUIRE(scene != nullptr);
REQUIRE(scene->getMaterialCount() == 4);
REQUIRE(scene->getMaterialCount() == 1);

REQUIRE(scene->getModelCount() == UINT32_C(8));
REQUIRE(scene->getModelCount() == UINT32_C(1));

std::uint32_t meshCount = 0;
std::uint32_t faceCount = 0;
Expand All @@ -33,9 +33,9 @@ TEST_CASE("Load a 3DS file")
}
}

REQUIRE(meshCount == 8);
REQUIRE(faceCount == 6098);
REQUIRE(vertexCount == 3263);
REQUIRE(meshCount == 1);
REQUIRE(faceCount == 80);
REQUIRE(vertexCount == 63);
}

TEST_SUITE_END();
4 changes: 2 additions & 2 deletions test/integration/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set(INTEGRATION_TEST_SOURCES

test_case(integration "${INTEGRATION_TEST_SOURCES}")

file(COPY "${CMAKE_SOURCE_DIR}/test/data/huygens.3ds"
file(COPY "${CMAKE_SOURCE_DIR}/test/data/icosphere.3ds"
DESTINATION "${CMAKE_CURRENT_BINARY_DIR}")
file(COPY "${CMAKE_SOURCE_DIR}/test/data/iss/models/iss.cmod"
file(COPY "${CMAKE_SOURCE_DIR}/test/data/testmodel.cmod"
DESTINATION "${CMAKE_CURRENT_BINARY_DIR}")
2 changes: 1 addition & 1 deletion test/integration/cmod_bin_ascii_roundtrip_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ TEST_CASE("CMOD binary to ASCII roundtrip")
};
cmod::SourceGetter sourceGetter = [&](ResourceHandle handle) { return paths[handle]; };

std::ifstream f("iss.cmod", std::ios::in | std::ios::binary);
std::ifstream f("testmodel.cmod", std::ios::in | std::ios::binary);
REQUIRE(f.good());
std::stringstream sourceData;
sourceData << f.rdbuf();
Expand Down

0 comments on commit 2c9c78e

Please sign in to comment.