Exemple #1
0
    def test_ply(self):
        m = g.get_mesh('machinist.XAML')

        assert m.visual.kind == 'face'
        assert m.visual.face_colors.ptp(axis=0).max() > 0

        export = m.export(file_type='ply')
        reconstructed = g.wrapload(export, file_type='ply')

        assert reconstructed.visual.kind == 'face'

        assert g.np.allclose(reconstructed.visual.face_colors,
                             m.visual.face_colors)

        m = g.get_mesh('reference.ply')

        assert m.visual.kind == 'vertex'
        assert m.visual.vertex_colors.ptp(axis=0).max() > 0

        export = m.export(file_type='ply')
        reconstructed = g.wrapload(export, file_type='ply')
        assert reconstructed.visual.kind == 'vertex'

        assert g.np.allclose(reconstructed.visual.vertex_colors,
                             m.visual.vertex_colors)
Exemple #2
0
 def test_trailing(self):
     # test files with texture and trailing slashes
     m = g.get_mesh('jacked.obj')
     assert len(m.visual.uv) == len(m.vertices)
     rec = g.wrapload(
         m.export(file_type='obj'), file_type='obj')
     assert g.np.isclose(m.area, rec.area)
Exemple #3
0
    def test_empty_or_pointcloud(self):
        # demo files to check
        empty_files = ['obj_empty.obj', 'obj_points.obj', 'obj_wireframe.obj']

        for empty_file in empty_files:
            e = g.get_mesh('emptyIO/' + empty_file)

            # create export
            export = e.export(file_type='ply')
            reconstructed = g.wrapload(export, file_type='ply')

            if 'empty' in empty_file:
                # result should be an empty scene without vertices
                assert isinstance(e, g.trimesh.Scene)
                assert not hasattr(e, 'vertices')
                # export should not contain geometry
                assert isinstance(reconstructed, g.trimesh.Scene)
                assert not hasattr(reconstructed, 'vertices')
            elif 'points' in empty_file:
                # result should be a point cloud instance
                assert isinstance(e, g.trimesh.PointCloud)
                assert hasattr(e, 'vertices')
                # point cloud export should contain vertices
                assert isinstance(reconstructed, g.trimesh.PointCloud)
                assert hasattr(reconstructed, 'vertices')
Exemple #4
0
    def test_empty_or_pointcloud(self):
        # demo files to check
        empty_files = [
            'ply_empty_ascii.ply', 'ply_empty_bin.ply', 'ply_empty_header.ply',
            'ply_points_ascii.ply', 'ply_points_bin.ply'
        ]

        for empty_file in empty_files:
            e = g.get_mesh('emptyIO/' + empty_file)
            if 'empty' in empty_file:
                # result should be an empty scene
                try:
                    e.export(file_type='ply')
                except BaseException:
                    continue
                raise ValueError('should not export empty')
            elif 'points' in empty_file:
                # create export
                export = e.export(file_type='ply')
                reconstructed = g.wrapload(export, file_type='ply')

                # result should be a point cloud instance
                assert isinstance(e, g.trimesh.PointCloud)
                assert hasattr(e, 'vertices')
                # point cloud export should contain vertices
                assert isinstance(reconstructed, g.trimesh.PointCloud)
                assert hasattr(reconstructed, 'vertices')
Exemple #5
0
 def test_rabbit(self):
     # A BSD-licensed test model from pyglet
     # it has mixed triangles, quads, and 16 element faces -_-
     # this should test the non-vectorized load path
     m = g.get_mesh('rabbit.obj')
     assert len(m.faces) == 1252
     rec = g.wrapload(m.export(file_type='obj'), file_type='obj')
     assert g.np.isclose(m.area, rec.area)
Exemple #6
0
 def test_obj(self):
     m = g.get_mesh('textured_tetrahedron.obj', process=False)
     export = m.export(file_type='obj')
     reconstructed = g.wrapload(export, file_type='obj', process=False)
     # test that we get at least the same number of normals and texcoords out;
     # the loader may reorder vertices, so we shouldn't check direct
     # equality
     assert m.vertex_normals.shape == reconstructed.vertex_normals.shape
Exemple #7
0
    def test_obj_quad(self):
        mesh = g.get_mesh('quadknot.obj')
        # make sure some data got loaded
        assert g.trimesh.util.is_shape(mesh.faces, (-1, 3))
        assert g.trimesh.util.is_shape(mesh.vertices, (-1, 3))

        assert mesh.is_watertight
        assert mesh.is_winding_consistent
        rec = g.wrapload(mesh.export(file_type='obj'), file_type='obj')
        assert g.np.isclose(mesh.area, rec.area)
Exemple #8
0
    def test_ascii_color(self):
        mesh = g.trimesh.creation.box()
        en = g.wrapload(mesh.export(file_type='ply', encoding="ascii"),
                        file_type='ply')
        assert en.visual.kind is None

        color = [255, 0, 0, 255]
        mesh.visual.vertex_colors = color

        # try exporting and reloading raw
        eb = g.wrapload(mesh.export(file_type='ply'), file_type='ply')

        assert g.np.allclose(eb.visual.vertex_colors[0], color)
        assert eb.visual.kind == 'vertex'

        ea = g.wrapload(mesh.export(file_type='ply', encoding='ascii'),
                        file_type='ply')
        assert g.np.allclose(ea.visual.vertex_colors, color)
        assert ea.visual.kind == 'vertex'
Exemple #9
0
 def test_no_img(self):
     # sometimes people use the `vt` parameter for arbitrary
     # vertex attributes and thus want UV coordinates even
     # if there is no texture image
     m = g.get_mesh('noimg.obj')
     assert m.visual.uv.shape == (len(m.vertices), 2)
     # make sure UV coordinates are in range 0.0 - 1.0
     assert m.visual.uv.max() < (1 + 1e-5)
     assert m.visual.uv.min() > -1e-5
     # check to make sure it's not all zeros
     assert m.visual.uv.ptp() > 0.5
     rec = g.wrapload(m.export(file_type='obj'), file_type='obj')
     assert g.np.isclose(m.area, rec.area)
Exemple #10
0
    def test_scene(self):
        # get a multi- mesh scene with a transform tree
        source = g.get_mesh('cycloidal.3DXML')
        # add a transform to zero scene before exporting
        source.rezero()
        # export the file as a binary GLTF file, GLB
        export = source.export(file_type='glb')

        # re- load the file as a trimesh.Scene object again
        loaded = g.wrapload(export, file_type='glb')

        # the scene should be identical after export-> import cycle
        assert g.np.allclose(loaded.extents / source.extents, 1.0)
Exemple #11
0
    def test_ply(self):
        p = g.get_mesh('points_agisoft.xyz')
        assert isinstance(p, g.trimesh.PointCloud)
        assert len(p.vertices) > 0

        # initial color CRC
        initial = p.visual.crc()
        # set to random colors
        p.colors = g.np.random.random((len(p.vertices), 4))
        # visual CRC should have changed
        assert p.visual.crc() != initial

        # test exporting a pointcloud to a PLY file
        r = g.wrapload(p.export(file_type='ply'), file_type='ply')
        assert r.vertices.shape == p.vertices.shape
        # make sure colors survived the round trip
        assert g.np.allclose(r.colors, p.colors)
Exemple #12
0
    def test_vertex_attributes(self):
        """
        Test writing vertex attributes to a ply, by reading them back and asserting the
        written attributes array matches
        """

        m = g.get_mesh('box.STL')
        test_1d_attribute = g.np.copy(m.vertices[:, 0])
        test_nd_attribute = g.np.copy(m.vertices)
        m.vertex_attributes['test_1d_attribute'] = test_1d_attribute
        m.vertex_attributes['test_nd_attribute'] = test_nd_attribute

        export = m.export(file_type='ply')
        reconstructed = g.wrapload(export, file_type='ply')

        vertex_attributes = reconstructed.metadata['ply_raw']['vertex']['data']
        result_1d = vertex_attributes['test_1d_attribute']
        result_nd = vertex_attributes['test_nd_attribute']['f1']

        g.np.testing.assert_almost_equal(result_1d, test_1d_attribute)
        g.np.testing.assert_almost_equal(result_nd, test_nd_attribute)
Exemple #13
0
    def test_face_attributes(self):
        # Test writing face attributes to a ply, by reading
        # them back and asserting the written attributes array matches

        m = g.get_mesh('box.STL')
        test_1d_attribute = g.np.copy(m.face_angles[:, 0])
        test_nd_attribute = g.np.copy(m.face_angles)
        m.face_attributes['test_1d_attribute'] = test_1d_attribute
        m.face_attributes['test_nd_attribute'] = test_nd_attribute

        export = m.export(file_type='ply')
        reconstructed = g.wrapload(export, file_type='ply')

        face_attributes = reconstructed.metadata['ply_raw']['face']['data']
        result_1d = face_attributes['test_1d_attribute']
        result_nd = face_attributes['test_nd_attribute']['f1']

        g.np.testing.assert_almost_equal(result_1d, test_1d_attribute)
        g.np.testing.assert_almost_equal(result_nd, test_nd_attribute)

        no_attr = m.export(file_type='ply', include_attributes=False)
        assert len(no_attr) < len(export)
Exemple #14
0
    def test_empty_or_pointcloud(self):
        # demo files to check
        empty_files = ['obj_empty.obj', 'obj_points.obj', 'obj_wireframe.obj']

        for empty_file in empty_files:
            e = g.get_mesh('emptyIO/' + empty_file)

            # create export
            if 'empty' in empty_file:
                try:
                    export = e.export(file_type='ply')
                except BaseException:
                    continue
                raise ValueError('cannot export empty')
            elif 'points' in empty_file:
                export = e.export(file_type='ply')
                reconstructed = g.wrapload(export, file_type='ply')

                # result should be a point cloud instance
                assert isinstance(e, g.trimesh.PointCloud)
                assert hasattr(e, 'vertices')
                # point cloud export should contain vertices
                assert isinstance(reconstructed, g.trimesh.PointCloud)
                assert hasattr(reconstructed, 'vertices')
Exemple #15
0
 def test_no_uv(self):
     mesh = g.get_mesh('box.obj')
     rec = g.wrapload(mesh.export(file_type='obj'), file_type='obj')
     assert g.np.isclose(mesh.area, rec.area)