API

Transform Node

A TransformNode

A TransformNode is an object that is not rendered but can be used as a center of transformation. This can decrease memory usage and increase rendering speed compared to using an empty mesh as a parent, and it is less complicated than using a pivot matrix.

The TransformNode can be used as a center of transformation (CoT) for a mesh and some lights and cameras by acting as a parent to them, which increases its versatility.

Remember that, as with any parent, transformations are relative to the frame of reference of the parent. In all of the following Playgrounds, the purple sphere is created only to show the TransformNode position.

As a Center of Rotation

Set a TransformNode as a parent, then rotate the TransformNode.

Mesh

import { TransformNode } from "@babylonjs/core/Meshes/transformNode";
//create a Center of Transformation
var CoT = new TransformNode("root");
box.parent = CoT; //apply to Box
Center of Transform At Box Center Center of Transform Offset Box Rotating about its Local Axes

Camera

The light blue cylinder is an additional stationary object to show that the camera is moving.

For those examples that mention a dummy camera, a black sphere is used to show the intended path of the camera in the Playground that follows it. The purple ray shows the camera's viewing direction, and the tube indicates the area covered by the camera's view.

Arc Rotate Camera

The center of transformation is placed at the target position of the arc rotation camera.

Rotating Dummy Camera Rotating Arc Camera

Target position moved by moving center of transformation.

Rotating Dummy Camera Rotating Arc Camera

Moving the camera position relative to the center of transformation simply changes the distance between the camera and target.

Rotating Dummy Camera Rotating Arc Camera

Universal Camera

The arrow keys allow you to move the camera position (remember to click on the canvas area before using the keys).

Rotating Universal Camera 1

You can also have a universal camera rotate in orbit around a target and move it with the keys.

Rotating Universal Camera 2

Lights

Those lights that have a position can use a TransformNode.

Point Light

Rotating Point Light Rotating Spot Light

As a Center of Translation or Position

When you move a center of transformation, anything parented to it will move with it.

When you transform an object with a center of transformation as its parent, that transformation takes place relative to the center of transformation's frame of reference.

In the example below you can see that the simple movement given by

box.position.x += 0.01;

takes place along the rotating x axis of the center of transformation.

Box Translation

Moving cameras and lights work in the same way.

As a Center of Enlargement

Obviously scaling has no effect on lights or cameras. Scaling takes place relative to the frame of reference of the center of enlargement.

Box Scaling

Further reading

Rotating Around Axis
Learn how to rotate around an axis in Babylon.js.
Rotating Around Axis