File size: 1,548 Bytes
ce91ea1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import numpy as np

def rotate(mesh):
    # Extract vertices and normals
    vertices = mesh.vertices

    # Define rotation matrices
    def rotate_y(vertices, angle):
        angle_rad = np.radians(angle)
        rotation_matrix = np.array([
            [np.cos(angle_rad), 0, np.sin(angle_rad)],
            [0, 1, 0],
            [-np.sin(angle_rad), 0, np.cos(angle_rad)]
        ])
        return np.dot(vertices, rotation_matrix.T)

    def rotate_x(vertices, angle):
        angle_rad = np.radians(angle)
        rotation_matrix = np.array([
            [1, 0, 0],
            [0, np.cos(angle_rad), -np.sin(angle_rad)],
            [0, np.sin(angle_rad), np.cos(angle_rad)]
        ])
        return np.dot(vertices, rotation_matrix.T)
    
    def rotate_z(vertices, angle):
        angle_rad = np.radians(angle)
        rotation_matrix = np.array([
            [np.cos(angle_rad), -np.sin(angle_rad), 0],
            [np.sin(angle_rad), np.cos(angle_rad), 0],
            [0, 0, 1]
        ])
        return np.dot(vertices, rotation_matrix.T)

    # Rotate vertices to right orientation
    vertices = rotate_y(vertices, 225)
    vertices = rotate_x(vertices, 90)
    vertices = rotate_z(vertices, -90)
    vertices = rotate_y(vertices, 45)
    vertices = rotate_z(vertices, 45)
    vertices = rotate_x(vertices, 45)
    vertices = rotate_y(vertices, 20)
    vertices = rotate_x(vertices, -10)

    # Update the mesh with the modified vertices
    mesh.vertices = vertices
    return mesh