# CFrame stuff

X = Left / Right
Y = Up / Down
Z = Forward / Backward

R0_ = Right Vector (Object's local +X direction)
R1_ = Up Vector (Object's local +Y direction)
R2_ = Look Vector (Object's local -Z direction, so "Back" Vector)

R_0, R_1, R_2 = X Y and Z direction of each Vectors

# Roblox R6 Rig Motor6D

```
Left Hip {
	C0 {
		Position {
			X -1
			Y -1
			Z 0
		}
		Orientation {
			X 0
			Y -90
			Z 0
		}
	}
	C1 {
		Position {
			X -0.5
			Y 1
			Z 0
		}
		Orientation {
			X 0
			Y -90
			Z 0
		}
	}
}
Left Shoulder {
	C0 {
		Position {
			X -1
			Y 0.5
			Z 0
		}
		Orientation {
			X 0
			Y -90
			Z 0
		}
	}
	C1 {
		Position {
			X 0.5
			Y 0.5
			Z 0
		}
		Orientation {
			X 0
			Y -90
			Z 0
		}
	}
}
Neck {
	C0 {
		Position {
			X 0
			Y 1
			Z 0
		}
		Orientation {
			X -90
			Y -180
			Z 0
		}
	}
	C1 {
		Position {
			X 0
			Y -0.5
			Z 0
		}
		Orientation {
			X -90
			Y -180
			Z 0
		}
	}
}
Right Hip {
	C0 {
		Position {
			X 1
			Y -1
			Z 0
		}
		Orientation {
			X 0
			Y 90
			Z 0
		}
	}
	C1 {
		Position {
			X 0.5
			Y 1
			Z 0
		}
		Orientation {
			X 0
			Y 90
			Z 0
		}
	}
}
Right Shoulder {
	C0 {
		Position {
			X 1
			Y 0.5
			Z 0
		}
		Orientation {
			X 0
			Y 90
			Z 0
		}
	}
	C1 {
		Position {
			X -0.5
			Y 0.5
			Z 0
		}
		Orientation {
			X 0
			Y 90
			Z 0
		}
	}
}
```

# Roblox Axis and Blender Axis
Format: Roblox -> Blender

Position:
+X Right -> +X Right
+Y Up -> +Z Up
+Z Backward -> -Y Backward
-Z Forward -> +Y Forward

Formula?: `(X, Y, Z) = (X, -Z, Y)"

random:
```
from mathutils import Matrix


# Roblox:
#   +X = Right
#   +Y = Up
#   -Z = Forward
#
# Blender:
#   +X = Right
#   +Z = Up
#   +Y = Forward
#
# Therefore:
#   Roblox X -> Blender X
#   Roblox Y -> Blender Z
#   Roblox Z -> Blender -Y

AXIS_CONVERSION = Matrix((
    (1,  0,  0),
    (0,  0, -1),
    (0,  1,  0),
))


def cframe_to_matrix(
    x: float,
    y: float,
    z: float,
    r00: float,
    r01: float,
    r02: float,
    r10: float,
    r11: float,
    r12: float,
    r20: float,
    r21: float,
    r22: float,
) -> Matrix:
    """Convert a Roblox CFrame into a Blender-space Matrix."""

    # Roblox CFrame
    roblox_rotation = Matrix((
        (r00, r01, r02),
        (r10, r11, r12),
        (r20, r21, r22),
    ))

    roblox_position = Matrix.Translation((x, y, z))

    # Convert rotation basis
    blender_rotation = (
        AXIS_CONVERSION
        @ roblox_rotation
        @ AXIS_CONVERSION.inverted()
    )

    # Convert position
    blender_position = AXIS_CONVERSION @ Matrix.Translation(
        (x, y, z)
    ) @ AXIS_CONVERSION.inverted()

    # Actually construct the transformed matrix.
    #
    # For a homogeneous transform, the simpler equivalent is:
    roblox_matrix = Matrix((
        (r00, r01, r02, x),
        (r10, r11, r12, y),
        (r20, r21, r22, z),
        (0.0, 0.0, 0.0, 1.0),
    ))

    conversion = AXIS_CONVERSION.to_4x4()

    return conversion @ roblox_matrix @ conversion.inverted()
```

```
from mathutils import Matrix


ROBLOX_TO_BLENDER = Matrix((
    (1,  0,  0),
    (0,  0, -1),
    (0,  1,  0),
))


def cframe_to_matrix(
    x: float,
    y: float,
    z: float,
    r00: float,
    r01: float,
    r02: float,
    r10: float,
    r11: float,
    r12: float,
    r20: float,
    r21: float,
    r22: float,
) -> Matrix:
    """Convert Roblox CFrame:GetComponents() to Blender coordinates."""

    roblox = Matrix((
        (r00, r01, r02, x),
        (r10, r11, r12, y),
        (r20, r21, r22, z),
        (0.0, 0.0, 0.0, 1.0),
    ))

    conversion = ROBLOX_TO_BLENDER.to_4x4()

    return conversion @ roblox @ conversion.inverted()
```