How to use the generic.trimesh.util function in generic

To help you get started, we’ve selected a few generic examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mikedh / trimesh / tests / test_creation.py View on Github external
def check_triangulation(v, f, true_area):
    assert g.trimesh.util.is_shape(v, (-1, 2))
    assert v.dtype.kind == 'f'
    assert g.trimesh.util.is_shape(f, (-1, 3))
    assert f.dtype.kind == 'i'

    tri = g.trimesh.util.stack_3D(v)[f]
    area = g.trimesh.triangles.area(tri).sum()
    assert g.np.isclose(area, true_area)
github mikedh / trimesh / tests / test_simplify.py View on Github external
path_3D = m.outline(m.facets[m.facets_area.argmax()])
        path_2D, to_3D = path_3D.to_planar()

        simple = g.trimesh.path.simplify.simplify_spline(path_2D,
                                                         smooth=.01,
                                                         verbose=True)
        assert g.np.isclose(path_2D.area, simple.area, rtol=.01)

        # check the kwargs
        simple = path_2D.simplify_spline(smooth=0.01)
        assert g.np.isclose(path_2D.area, simple.area, rtol=.01)


if __name__ == '__main__':
    g.trimesh.util.attach_to_log()
    g.unittest.main()
github mikedh / trimesh / tests / test_identifier.py View on Github external
continue

                    m = s.geometry[geo].copy()
                    m.apply_transform(T)
                    meshes.append(m)
                if not all(meshes[0].identifier_md5 == i.identifier_md5
                           for i in meshes):
                    raise ValueError(
                        '{} differs after transform!'.format(geom_name))

        assert (scenes[0].geometry['disc_cam_B'].identifier_md5 !=
                scenes[0].geometry['disc_cam_A'].identifier_md5)


if __name__ == '__main__':
    g.trimesh.util.attach_to_log()
    g.unittest.main()
github mikedh / trimesh / tests / test_section.py View on Github external
origin = bunny.bounds.mean(axis=0)
        normal = g.trimesh.unitize([1, 1, 2])

        sliced = bunny.slice_plane(plane_origin=origin,
                                   plane_normal=normal)
        assert len(sliced.faces) > 0

        # check the projections manually
        dot = g.np.dot(normal, (sliced.vertices - origin).T)
        # should be lots of stuff at the plane and nothing behind
        assert g.np.isclose(dot.min(), 0.0)


if __name__ == '__main__':
    g.trimesh.util.attach_to_log()
    g.unittest.main()
github mikedh / trimesh / tests / test_arc.py View on Github external
def test_center(self):

        from trimesh.path.arc import arc_center
        test_points = [[[0, 0], [1.0, 1], [2, 0]]]
        test_results = [[[1, 0], 1.0]]
        points = test_points[0]
        res_center, res_radius = test_results[0]
        center_info = arc_center(points)
        C, R, N, angle = (center_info['center'],  # NOQA
                          center_info['radius'],
                          center_info['normal'],
                          center_info['span'])

        assert abs(R - res_radius) < g.tol_path.zero
        assert g.trimesh.util.euclidean(C, res_center) < g.tol_path.zero
github mikedh / trimesh / tests / test_dae.py View on Github external
assert len(scene.geometry) == 1
        assert len(scene.graph.nodes_geometry) == 1

    def test_shoulder(self):
        if collada is None:
            g.log.error('no pycollada to test!')
            return

        scene = g.get_mesh('shoulder.zae')
        assert len(scene.geometry) == 3
        assert len(scene.graph.nodes_geometry) == 3


if __name__ == '__main__':
    g.trimesh.util.attach_to_log()
    g.unittest.main()
github mikedh / trimesh / tests / test_primitives.py View on Github external
c = g.trimesh.primitives.Cylinder(
            radius=1.0,
            height=10.0,
            transform=g.trimesh.transformations.random_rotation_matrix())
        # inflate cylinder
        b = c.buffer(1.0)
        assert g.np.isclose(b.primitive.height, 12.0)
        assert g.np.isclose(b.primitive.radius, 2.0)
        # should contain all vertices of source mesh
        assert b.contains(c.vertices).all()
        # should contain line segment
        assert b.contains(c.segment).all()


if __name__ == '__main__':
    g.trimesh.util.attach_to_log()
    g.unittest.main()
github mikedh / trimesh / tests / test_sample.py View on Github external
m = g.get_mesh('featuretype.STL')

        samples = m.sample(1000)

        # check to make sure all samples are on the mesh surface
        distance = m.nearest.signed_distance(samples)
        assert g.np.abs(distance).max() < 1e-4

        even, index = g.trimesh.sample.sample_surface_even(m, 1000)
        # check to make sure all samples are on the mesh surface
        distance = m.nearest.signed_distance(even)
        assert g.np.abs(distance).max() < 1e-4


if __name__ == '__main__':
    g.trimesh.util.attach_to_log()
    g.unittest.main()
github mikedh / trimesh / tests / test_util.py View on Github external
def test_file_hash(self):
        data = g.np.random.random(10).tostring()
        path = g.os.path.join(g.dir_data, 'nestable.json')

        for file_obj in [g.trimesh.util.wrap_as_stream(data),
                         open(path, 'rb')]:
            start = file_obj.tell()

            hashed = g.trimesh.util.hash_file(file_obj)

            self.assertTrue(file_obj.tell() == start)
            self.assertTrue(hashed is not None)
            self.assertTrue(len(hashed) > 5)

            file_obj.close()