Die4Ever / unreal-map-flipper

Unreal Map Flipper
https://discord.gg/daQVyAp2ds
GNU Affero General Public License v3.0
1 stars 0 forks source link

03_nyc_airfield fix hole in wall #10

Closed Die4Ever closed 1 year ago

Die4Ever commented 1 year ago

image

Die4Ever commented 1 year ago

idk if I need to convert vertices to world space before transforming them, but something here might be useful


def quaternion_from_euler(pitch, yaw, roll) -> tuple:
    RADIANS_TO_UU = 65535 / math.pi / 2
    #URotToRadian = 0.000095873799
    roll = float(roll) / RADIANS_TO_UU / 2
    pitch = float(pitch) / RADIANS_TO_UU / 2
    yaw = float(yaw) / RADIANS_TO_UU / 2

    qx = math.sin(roll) * math.cos(pitch) * math.cos(yaw) - math.cos(roll) * math.sin(pitch) * math.sin(yaw)
    qy = math.cos(roll) * math.sin(pitch) * math.cos(yaw) + math.sin(roll) * math.cos(pitch) * math.sin(yaw)
    qz = math.cos(roll) * math.cos(pitch) * math.sin(yaw) - math.sin(roll) * math.sin(pitch) * math.cos(yaw)
    qw = math.cos(roll) * math.cos(pitch) * math.cos(yaw) + math.sin(roll) * math.sin(pitch) * math.sin(yaw)
    return (qx, qy, qz, qw)

def euler_from_quaternion(x, y, z, w) -> tuple:
    RADIANS_TO_UU = 65535 / math.pi / 2

    t0 = +2.0 * (w * x + y * z)
    t1 = +1.0 - 2.0 * (x * x + y * y)
    roll_x = int(math.atan2(t0, t1) * RADIANS_TO_UU)

    t2 = +2.0 * (w * y - z * x)
    t2 = +1.0 if t2 > +1.0 else t2
    t2 = -1.0 if t2 < -1.0 else t2
    pitch_y = int(math.asin(t2) * RADIANS_TO_UU)

    t3 = +2.0 * (w * z + x * y)
    t4 = +1.0 - 2.0 * (y * y + z * z)
    yaw_z = int(math.atan2(t3, t4) * RADIANS_TO_UU)

    return pitch_y, yaw_z, roll_x # use unrealscript ordering

def quaternion_rotation_matrix(q0, q1, q2, q3) -> np.array:
    # First row of the rotation matrix
    r00 = 2 * (q0 * q0 + q1 * q1) - 1
    r01 = 2 * (q1 * q2 - q0 * q3)
    r02 = 2 * (q1 * q3 + q0 * q2)

    # Second row of the rotation matrix
    r10 = 2 * (q1 * q2 + q0 * q3)
    r11 = 2 * (q0 * q0 + q2 * q2) - 1
    r12 = 2 * (q2 * q3 - q0 * q1)

    # Third row of the rotation matrix
    r20 = 2 * (q1 * q3 - q0 * q2)
    r21 = 2 * (q2 * q3 + q0 * q1)
    r22 = 2 * (q0 * q0 + q3 * q3) - 1

    # 3x3 rotation matrix
    rot_matrix = np.array([[r00, r01, r02],
                           [r10, r11, r12],
                           [r20, r21, r22]])

    return rot_matrix

import numpy as np

def rotation_matrix(x, y, z):
    RADIANS_TO_UU = 65535 / math.pi / 2
    x = float(x) / RADIANS_TO_UU
    y = float(y) / RADIANS_TO_UU
    z = float(z) / RADIANS_TO_UU

    c1 = np.cos(x * np.pi / 180)
    s1 = np.sin(x * np.pi / 180)
    c2 = np.cos(y * np.pi / 180)
    s2 = np.sin(y * np.pi / 180)
    c3 = np.cos(z * np.pi / 180)
    s3 = np.sin(z * np.pi / 180)

    matrix=np.array([[c2*c3, -c2*s3, s2],
                        [c1*s3+c3*s1*s2, c1*c3-s1*s2*s3, -c2*s1],
                        [s1*s3-c1*c3*s2, c3*s1+c1*s2*s3, c1*c2]])

    return matrix

def rotation_angles(matrix):
    RADIANS_TO_UU = 65535 / math.pi / 2
    r11, r12, r13 = matrix[0]
    r21, r22, r23 = matrix[1]
    r31, r32, r33 = matrix[2]

    theta1 = np.arctan(-r23 / r33)
    theta2 = np.arctan(r13 * np.cos(theta1) / r33)
    theta3 = np.arctan(-r12 / r11)

    theta1 = theta1 * 180 / np.pi
    theta2 = theta2 * 180 / np.pi
    theta3 = theta3 * 180 / np.pi

    theta1 = (theta1 * RADIANS_TO_UU)
    theta2 = (theta2 * RADIANS_TO_UU)
    theta3 = (theta3 * RADIANS_TO_UU)

    return (theta1, theta2, theta3)
Die4Ever commented 1 year ago

was fixed by using these BSP settings

image

Optimization: Optimal, and Minimize cuts