示例#1
0
    def test_mesh_roundtrip(self):
        """Check that we can save then read a textured mesh."""
        mesh = TexturedMesh.example()
        expected_color = mesh.base_color()[0, 0, :]
        expected_mr = mesh.metallic_roughness()[0, 0, :]

        model = GltfModel.from_textured_mesh(mesh)
        model.save_as_gltf(self.temp_directory, "dummy")

        # now load...
        input_path = os.path.join(self.temp_directory, "dummy.gltf")
        model2 = GltfModel.load_from_gltf(input_path)
        self.assertEqual(model2.num_images(), 2)
        self.assertEqual(model.image_size(0), 288)
        self.assertEqual(model.image_size(1), 72)
        self.assertEqual(model.image_uri(0), "0.png")
        self.assertEqual(model.image_uri(1), "1.png")

        # ...and check mesh.
        mesh2 = model2.extract_textured_primitive_mesh()
        self.assertEqual(mesh2.num_vertices(), 24)
        self.assertTrue(mesh.has_dual_texture_material())
        np.testing.assert_array_equal(mesh2.base_color()[0, 0, :],
                                      expected_color)
        np.testing.assert_array_equal(mesh2.metallic_roughness()[0, 0, :],
                                      expected_mr)
示例#2
0
 def test_add_mesh(self):
     """Test python wrapper to go from TexturedMesh to GltfModel."""
     model = GltfModel()
     mesh = TexturedMesh.example()
     model.add_textured_primitive_mesh(mesh)
     self.assertEqual(model.num_primitive_meshes(), 1)
     self.assertEqual(model.num_nodes(), 1)
     self.assertEqual(model.num_buffers(), 1)
示例#3
0
 def test_save_textured_mesh_as_glb(self):
     """Check that we can save a textured mesh directly to glb."""
     mesh = TexturedMesh.example()
     model = GltfModel.from_textured_mesh(mesh)
     path = os.path.join(self.temp_directory, "dummy.glb")
     model.save_as_glb(path)
     # Check the existence of glb
     self.assertTrue(os.path.isfile(path))
示例#4
0
 def test_update_textured_material(self):
     mesh = TexturedMesh.example()
     model = GltfModel.from_textured_mesh(mesh)
     self.assertEqual(model.num_images(), 2)
     uri = "Cube_BaseColor.png"
     base_dir = TEST_PATH
     material = {"color": Vector3(0, 0, 0), "uri": uri}
     model.update_materials(base_dir, [material])
     self.assertEqual(model.num_images(), 3)
示例#5
0
 def test_add_colored_material(self):
     mesh = TexturedMesh.example()
     model = GltfModel.from_textured_mesh(mesh)
     index = model.add_colored_material("my_material",
                                        Vector3f(0.5, 0.5, 0.5), 0.0, 0.95)
     self.assertEqual(index, 1)
     index = model.add_colored_material("another_material",
                                        Vector3f(0.75, 0.75, 0.75), 0.1,
                                        0.7)
     self.assertEqual(index, 2)
示例#6
0
 def test_update_material(self):
     mesh = TexturedMesh.example()
     model = GltfModel.from_textured_mesh(mesh)
     material = {"color": Vector3(0.5, 0.5, 0.5), "uri": ""}
     model.update_materials("", [material])