@@ -296,6 +296,81 @@ TEST(TesseractGeometryUnit, LoadMeshUnit) // NOLINT
296
296
EXPECT_TRUE (convex_meshes[0 ]->getVerticeCount () == 8 );
297
297
}
298
298
299
+ #ifdef TESSERACT_ASSIMP_USE_PBRMATERIAL
300
+
301
+ TEST (TesseractGeometryUnit, LoadMeshWithMaterialGltf2Unit) // NOLINT
302
+ {
303
+ using namespace tesseract_geometry ;
304
+
305
+ std::string mesh_file = std::string (TESSERACT_SUPPORT_DIR) + " /meshes/tesseract_material_mesh.glb" ;
306
+ std::vector<Mesh::Ptr> meshes =
307
+ createMeshFromPath<Mesh>(mesh_file, Eigen::Vector3d (1 , 1 , 1 ), true , true , true , true , true );
308
+ ASSERT_TRUE (meshes.size () == 4 );
309
+
310
+ auto & mesh0 = meshes[0 ];
311
+ auto & mesh1 = meshes[1 ];
312
+ auto & mesh2 = meshes[2 ];
313
+ auto & mesh3 = meshes[3 ];
314
+
315
+ EXPECT_EQ (mesh0->getTriangleCount (), 34 );
316
+ EXPECT_EQ (mesh0->getVerticeCount (), 68 );
317
+ EXPECT_EQ (mesh1->getTriangleCount (), 15 );
318
+ EXPECT_EQ (mesh1->getVerticeCount (), 17 );
319
+ EXPECT_EQ (mesh2->getTriangleCount (), 15 );
320
+ EXPECT_EQ (mesh2->getVerticeCount (), 17 );
321
+ EXPECT_EQ (mesh3->getTriangleCount (), 2 );
322
+ EXPECT_EQ (mesh3->getVerticeCount (), 4 );
323
+
324
+ auto mesh0_normals = mesh0->getNormals ();
325
+ ASSERT_TRUE (mesh0_normals != nullptr );
326
+ EXPECT_EQ (mesh0_normals->size (), 68 );
327
+ auto mesh1_normals = mesh1->getNormals ();
328
+ ASSERT_TRUE (mesh1_normals != nullptr );
329
+ EXPECT_EQ (mesh1_normals->size (), 17 );
330
+ auto mesh2_normals = mesh2->getNormals ();
331
+ ASSERT_TRUE (mesh2_normals != nullptr );
332
+ EXPECT_EQ (mesh2_normals->size (), 17 );
333
+ auto mesh3_normals = mesh3->getNormals ();
334
+ ASSERT_TRUE (mesh3_normals != nullptr );
335
+ EXPECT_EQ (mesh3_normals->size (), 4 );
336
+
337
+ auto mesh0_material = mesh0->getMaterial ();
338
+ EXPECT_TRUE (mesh0_material->getBaseColorFactor ().isApprox (Eigen::Vector4d (0.7 , 0.7 , 0.7 , 1 ), 0.01 ));
339
+ EXPECT_NEAR (mesh0_material->getMetallicFactor (), 0.0 , 0.01 );
340
+ EXPECT_NEAR (mesh0_material->getRoughnessFactor (), 0.5 , 0.01 );
341
+ EXPECT_TRUE (mesh0_material->getEmissiveFactor ().isApprox (Eigen::Vector4d (0 , 0 , 0 , 1 ), 0.01 ));
342
+
343
+ auto mesh1_material = mesh1->getMaterial ();
344
+ EXPECT_TRUE (mesh1_material->getBaseColorFactor ().isApprox (Eigen::Vector4d (0.8 , 0 , 0 , 1 ), 0.01 ));
345
+ EXPECT_NEAR (mesh1_material->getMetallicFactor (), 0.8 , 0.01 );
346
+ EXPECT_NEAR (mesh1_material->getRoughnessFactor (), 0.1 , 0.01 );
347
+ EXPECT_TRUE (mesh1_material->getEmissiveFactor ().isApprox (Eigen::Vector4d (0 , 0 , 0 , 1 ), 0.01 ));
348
+
349
+ auto mesh2_material = mesh2->getMaterial ();
350
+ EXPECT_TRUE (mesh2_material->getBaseColorFactor ().isApprox (Eigen::Vector4d (0.05 , 0.8 , 0.05 , 1 ), 0.01 ));
351
+ EXPECT_NEAR (mesh2_material->getMetallicFactor (), 0.9 , 0.01 );
352
+ EXPECT_NEAR (mesh2_material->getRoughnessFactor (), 0.7 , 0.01 );
353
+ EXPECT_TRUE (mesh2_material->getEmissiveFactor ().isApprox (Eigen::Vector4d (0.1 , 0.1 , 0.5 , 1 ), 0.01 ));
354
+
355
+ auto mesh3_material = mesh3->getMaterial ();
356
+ EXPECT_TRUE (mesh3_material->getBaseColorFactor ().isApprox (Eigen::Vector4d (1 , 1 , 1 , 1 ), 0.01 ));
357
+ EXPECT_NEAR (mesh3_material->getMetallicFactor (), 0 , 0.01 );
358
+ EXPECT_NEAR (mesh3_material->getRoughnessFactor (), 0.5 , 0.01 );
359
+ EXPECT_TRUE (mesh3_material->getEmissiveFactor ().isApprox (Eigen::Vector4d (0 , 0 , 0 , 1 ), 0.01 ));
360
+
361
+ EXPECT_TRUE (mesh0->getTextures () == nullptr );
362
+ EXPECT_TRUE (mesh1->getTextures () == nullptr );
363
+ EXPECT_TRUE (mesh2->getTextures () == nullptr );
364
+
365
+ ASSERT_TRUE (mesh3->getTextures () != nullptr );
366
+ ASSERT_EQ (mesh3->getTextures ()->size (), 1 );
367
+
368
+ auto texture = mesh3->getTextures ()->at (0 );
369
+ EXPECT_EQ (texture->getTextureImage ()->getResourceContents ().size (), 38212 );
370
+ EXPECT_EQ (texture->getUVs ()->size (), 4 );
371
+ }
372
+ #endif
373
+
299
374
int main (int argc, char ** argv)
300
375
{
301
376
testing::InitGoogleTest (&argc, argv);
0 commit comments