Exemple #1
0
    def test_cap_nohit(self):
        # check to see if we handle capping with
        # non-intersecting planes well

        try:
            from triangle import triangulate  # NOQA
        except BaseException as E:
            if g.all_dep:
                raise E
            else:
                return

        for i in range(100):
            from trimesh.transformations import random_rotation_matrix
            box1 = g.trimesh.primitives.Box(extents=[10, 20, 30],
                                            transform=random_rotation_matrix())
            box2 = g.trimesh.primitives.Box(extents=[10, 20, 30],
                                            transform=random_rotation_matrix())

            result = g.trimesh.intersections.slice_mesh_plane(
                mesh=box2,
                plane_normal=-box1.face_normals,
                plane_origin=box1.vertices[box1.faces[:, 1]],
                cap=True)
            assert len(result.faces) > 0
 def setUp(self):
     self.points = tf.random_vector((128, 3)).astype(np.float32)
     self.T1 = tf.random_rotation_matrix()
     self.T1[:3, 3] = tf.random_vector((3, ))
     self.T1 = self.T1.astype(np.float32)
     self.T2 = np.asarray([tf.random_rotation_matrix() for _ in range(5)])
     self.T2[:, :3, 3] = tf.random_vector((5, 3))
     self.T2 = self.T2.astype(np.float32)
Exemple #3
0
def rotate(obj_path, out_path, angle_list, base=False, random=False):
    mesh = load_mesh(obj_path)
    mesh.vertices -= mesh.center_mass

    # Calculate the momentum and principal axes
    inertia = mesh.moment_inertia

    if base == True:
        p_axis = Principal_Axes(inertia)
        p_R = np.concatenate((np.concatenate(p_axis, axis=0).reshape(
            -1, 3), np.array([[0., 0., 0.]])),
                             axis=0)
        R = np.concatenate((p_R, np.array([[0.], [0.], [0.], [1]])), axis=1)

    else:
        if random == False:
            alpha, beta, gamma = np.radians(angle_list[0]), np.radians(angle_list[1]),\
                                 np.radians(angle_list[2])

            Rx = transform.rotation_matrix(alpha, [1, 0, 0])
            Ry = transform.rotation_matrix(beta, [0, 1, 0])
            Rz = transform.rotation_matrix(gamma, [0, 0, 1])
            R = transform.concatenate_matrices(Rx, Ry, Rz)

        else:
            # Random Rotation Matrix
            R = transform.random_rotation_matrix()

    # Rotation
    mesh.apply_transform(R)
    mesh.export(out_path)
Exemple #4
0
def create_scene2():
    scene = trimesh.Scene()
    for _ in range(5):
        geom = trimesh.load('models/fuze.obj')
        R = tf.random_rotation_matrix()
        T = tf.translation_matrix(np.random.uniform(-0.3, 0.3, (3, )))
        scene.add_geometry(geom, transform=T @ R)
    return scene
Exemple #5
0
def create_scene1():
    scene = trimesh.Scene()
    for _ in range(20):
        geom = trimesh.creation.axis(0.02)
        R = tf.random_rotation_matrix()
        T = tf.translation_matrix(np.random.uniform(-1, 1, (3, )))
        scene.add_geometry(geom, transform=T @ R)
    return scene
 def setUp(self):
     batch_size = 5
     self.Rs = np.asarray(
         [tf.random_rotation_matrix() for _ in range(batch_size)],
         dtype=np.float32,
     )[:, :3, :3]
     self.ts = np.asarray(
         [tf.random_vector((3, )) for _ in range(batch_size)],
         dtype=np.float32,
     )
     self.gTs = np.random.uniform(-1, 1,
                                  (batch_size, 4, 4)).astype(np.float32)
     self.check_backward_options = {"atol": 5e-4, "rtol": 5e-3}
 def setUp(self):
     self.R = tf.random_rotation_matrix()
     self.t = tf.random_vector((3, ))