Skip to content

Transform Utilities

Swifter edited this page Nov 5, 2024 · 12 revisions

Transform

The rm.Transform type in ReMapper is used to represent a position, rotation, and scale.

type Transform = {
    position?: rm.Vec3,
    rotation?: rm.Vec3,
    scale?: rm.Vec3
}

All properties are optional. The default values for each property are:

  • position: [0, 0, 0]
  • rotation: [0, 0, 0]
  • scale: [1, 1, 1]

There's also rm.AnimatedTransform which is structured similarly, but allows points. (See What are points?)

type AnimatedTransform = {
    position?: rm.RawPointsVec3,
    rotation?: rm.RawPointsVec3,
    scale?: rm.RawPointsVec3
}

Utilities

  • rm.combineTransforms takes in a child and parent transform and returns the result of applying the parent to the child.
rm.combineTransforms({
    position: [0, 10, 0]
}, {
    scale: [2, 2, 2]
})
/*
{
    position: [0, 20, 0],
    rotation: [0, 0, 0],
    scale: [2, 2, 2]
}
*/

You also have the option to pass in an anchor value. This will perform the transformation as though this position was the origin.

rm.combineTransforms({
    position: [0, 10, 0]
}, {
    scale: [2, 2, 2]
}, [0, 10, 0])
/*
{
    position: [0, 10, 0],
    rotation: [0, 0, 0],
    scale: [2, 2, 2]
}
*/
  • rm.emulateParent works much like rm.combineTransforms, but it allows animated transforms as well. It will attempt to use rm.combineTransforms, unless one of the transforms are animated. In that case, it will use the baking system.
rm.emulateParent({
    position: [0, 10, 0],
}, {
    scale: [
        [1, 1, 1, 0],
        [2, 2, 2, 1],
    ],
})
/*
{
    position: [
        [0, 10, 0, 0],
        [0, 20, 0, 1]
    ],
    rotation: [
        [0, 0, 0, 0],
        [0, 0, 0, 1]
    ],
    scale: [
        [1, 1, 1, 0],
        [2, 2, 2, 1],
    ],
}
*/
  • rm.applyTransformToPoint takes in a point and a transform and returns the result of applying the transform to the point.
rm.applyTransformToPoint([0, 0, 10], {
    position: [0, 20, 0],
    rotation: [0, 90, 0]
}) // ~ [10, 20, 0]

Similarly to rm.combineTransforms, you can provide an anchor value. This will perform the transformation as though this position was the origin.

rm.applyTransformToPoint([0, 0, 10], {
    position: [0, 20, 0],
    rotation: [0, 90, 0]
}, [0, 0, 10]) // ~ [0, 20, 10]

Clone this wiki locally