1#include "Core/Geometry/StandardAttribNames.hpp"
2#include <Core/Asset/GeometryData.hpp>
3#include <catch2/catch_test_macros.hpp>
5TEST_CASE(
"Core/Asset/GeometryData",
"[unittests][Core][Core/Asset][GeometryData]" ) {
7 using namespace Ra::Core::Asset;
8 using namespace Ra::Core::Geometry;
10 SECTION(
"Normal test" ) {
12 auto& coreGeom = geom->getGeometry();
13 auto& normal = coreGeom.normalsWithLock();
14 auto& name = Ra::Core::Geometry::getAttribName( MeshAttrib::VERTEX_NORMAL );
16 REQUIRE( normal.empty() );
17 REQUIRE( coreGeom.vertexAttribs().getAttribBase( name )->isLocked() );
19 normal.resize( 1, Ra::Core::Vector3::Zero() );
20 normal[0] = Ra::Core::Vector3().setRandom();
21 auto save = normal[0];
22 coreGeom.normalsUnlock();
24 REQUIRE( !normal.empty() );
25 REQUIRE( !coreGeom.vertexAttribs().getAttribBase( name )->isLocked() );
27 auto attriHandler = coreGeom.vertexAttribs().findAttrib<Ra::Core::Vector3>( name );
28 const auto& data = coreGeom.vertexAttribs().getData( attriHandler );
29 REQUIRE( save == data[0] );
32 auto& coreGeom2 = geometry2->getGeometry();
33 coreGeom2.setNormals( normal );
34 auto attriHandler2 = coreGeom2.vertexAttribs().findAttrib<Ra::Core::Vector3>( name );
35 const auto& d = coreGeom2.vertexAttribs().getData( attriHandler2 );
36 REQUIRE( d.size() == 1 );
37 REQUIRE( d[0] == save );
40 SECTION(
"Vertices test" ) {
42 auto& coreGeom = geom->getGeometry();
43 auto& vertex = coreGeom.verticesWithLock();
44 auto& name = Ra::Core::Geometry::getAttribName( MeshAttrib::VERTEX_POSITION );
46 REQUIRE( vertex.empty() );
47 REQUIRE( coreGeom.vertexAttribs().getAttribBase( name )->isLocked() );
49 vertex.resize( 1, Ra::Core::Vector3::Zero() );
50 vertex[0] = Ra::Core::Vector3().setRandom();
51 auto save = vertex[0];
52 coreGeom.verticesUnlock();
54 REQUIRE( !vertex.empty() );
55 REQUIRE( !coreGeom.vertexAttribs().getAttribBase( name )->isLocked() );
57 auto attriHandle = coreGeom.vertexAttribs().findAttrib<Ra::Core::Vector3>( name );
58 const auto& data = coreGeom.vertexAttribs().getData( attriHandle );
59 REQUIRE( save == data[0] );
62 auto& coreGeom2 = geom2->getGeometry();
63 coreGeom2.setVertices( geom->getGeometry().vertices() );
64 auto attriHandle2 = coreGeom2.vertexAttribs().findAttrib<Ra::Core::Vector3>( name );
65 const auto& d = coreGeom2.vertexAttribs().getData( attriHandle2 );
66 REQUIRE( d.size() == 1 );
67 REQUIRE( d[0] == save );
70 SECTION(
"Custom Attrib" ) {
72 auto& coreGeom = geom->getGeometry();
73 auto& vertAttrib = coreGeom.vertexAttribs();
75 auto intHandle = vertAttrib.addAttrib<
int>(
"testInt" );
76 auto longHandle = vertAttrib.addAttrib<
long>(
"testLong" );
77 auto longlongHandle = vertAttrib.addAttrib<
long long>(
"testLongLong" );
78 auto charHandle = vertAttrib.addAttrib<
char>(
"testChar" );
79 auto stringHandle = vertAttrib.addAttrib<
std::string>(
"testString" );
84 auto& intData = vertAttrib.getDataWithLock( intHandle );
85 auto& longData = vertAttrib.getDataWithLock( longHandle );
86 auto& longlongData = vertAttrib.getDataWithLock( longlongHandle );
87 auto& charData = vertAttrib.getDataWithLock( charHandle );
88 auto& stringData = vertAttrib.getDataWithLock( stringHandle );
89 intData.resize( ssize );
90 longData.resize( ssize );
91 longlongData.resize( ssize );
92 charData.resize( ssize );
93 stringData.resize( ssize );
96 longlongData[2] = 2ll;
98 stringData[4] =
"foo";
99 vertAttrib.unlock( intHandle );
100 vertAttrib.unlock( longHandle );
101 vertAttrib.unlock( longlongHandle );
102 vertAttrib.unlock( charHandle );
103 vertAttrib.unlock( stringHandle );
104 REQUIRE( vertAttrib.getAttrib<
int>(
"testInt" ).getSize() == ssize );
105 REQUIRE( vertAttrib.getAttrib<
long>(
"testLong" ).getSize() == ssize );
106 REQUIRE( vertAttrib.getAttrib<
long long>(
"testLongLong" ).getSize() == ssize );
107 REQUIRE( vertAttrib.getAttrib<
char>(
"testChar" ).getSize() == ssize );
108 REQUIRE( vertAttrib.getAttrib<
std::string>(
"testString" ).getSize() == ssize );
110 REQUIRE( vertAttrib.getAttrib<
int>(
"testInt" ).data()[0] == 0 );
111 REQUIRE( vertAttrib.getAttrib<
long>(
"testLong" ).data()[1] == 1l );
112 REQUIRE( vertAttrib.getAttrib<
long long>(
"testLongLong" ).data()[2] == 2ll );
113 REQUIRE( vertAttrib.getAttrib<
char>(
"testChar" ).data()[3] ==
'f' );
114 REQUIRE( vertAttrib.getAttrib<
std::string>(
"testString" ).
data()[4] ==
"foo" );
118 SECTION(
"Tangent, BiTangent, TexCoord tests" ) {
120 auto& coreGeom = geom->getGeometry();
121 auto& name = getAttribName( Ra::Core::Geometry::MeshAttrib::VERTEX_TANGENT );
122 auto attribHandle = coreGeom.addAttrib<Ra::Core::Vector3>( name );
123 auto& attribData = coreGeom.vertexAttribs().getDataWithLock( attribHandle );
125 REQUIRE( attribData.empty() );
126 REQUIRE( coreGeom.vertexAttribs().getAttribBase( name )->isLocked() );
128 attribData.resize( 1, Ra::Core::Vector3::Zero() );
129 attribData[0] = Ra::Core::Vector3().setRandom();
130 auto saveTan = attribData[0];
131 coreGeom.vertexAttribs().getAttribBase( name )->unlock();
133 REQUIRE( !attribData.empty() );
134 REQUIRE( !coreGeom.vertexAttribs().getAttribBase( name )->isLocked() );
136 auto tangentAttribHandle2 = coreGeom.vertexAttribs().findAttrib<Ra::Core::Vector3>( name );
137 const auto& dataTan = coreGeom.vertexAttribs().getData( tangentAttribHandle2 );
138 REQUIRE( saveTan == dataTan[0] );
141 auto& coreGeom2 = geom2->getGeometry();
142 auto attribHandle2 = coreGeom2.addAttrib<Ra::Core::Vector3>( name );
143 coreGeom2.getAttrib<Ra::Core::Vector3>( attribHandle2 ).setData( dataTan );
145 auto attribHandle3 = coreGeom2.vertexAttribs().findAttrib<Ra::Core::Vector3>( name );
146 const auto& d = coreGeom2.vertexAttribs().getData( attribHandle3 );
148 REQUIRE( d.size() == 1 );
149 REQUIRE( d[0] == saveTan );
152 SECTION(
"Type test " ) {
155 geometry.setType( GeometryData::GeometryType::LINE_MESH );
156 REQUIRE( geometry.isLineMesh() );
158 geometry.setType( GeometryData::GeometryType::TRI_MESH );
159 REQUIRE( geometry.isTriMesh() );
161 geometry.setType( GeometryData::GeometryType::QUAD_MESH );
162 REQUIRE( geometry.isQuadMesh() );
164 geometry.setType( GeometryData::GeometryType::POLY_MESH );
165 REQUIRE( geometry.isPolyMesh() );
167 geometry.setType( GeometryData::GeometryType::HEX_MESH );
168 REQUIRE( geometry.isHexMesh() );
170 geometry.setType( GeometryData::GeometryType::TETRA_MESH );
171 REQUIRE( geometry.isTetraMesh() );
173 geometry.setType( GeometryData::GeometryType::POINT_CLOUD );
174 REQUIRE( geometry.isPointCloud() );
176 geometry.setType( GeometryData::GeometryType::UNKNOWN );
177 REQUIRE( !geometry.isLineMesh() );
178 REQUIRE( !geometry.isTriMesh() );
179 REQUIRE( !geometry.isQuadMesh() );
180 REQUIRE( !geometry.isPolyMesh() );
181 REQUIRE( !geometry.isHexMesh() );
182 REQUIRE( !geometry.isTetraMesh() );
183 REQUIRE( !geometry.isPointCloud() );