Mesh Transformations
Position, rotate, and scale meshes to arrange your scene:
// Position (translation)
box.position = new BABYLON.Vector3(0, 2, 0); // Set absolute position
box.position.y += 1; // Relative position change
// Rotation (in radians)
cylinder.rotation = new BABYLON.Vector3(
0, // X-axis rotation (pitch)
Math.PI / 4, // Y-axis rotation (yaw)
0 // Z-axis rotation (roll)
);
// Alternative rotation with Quaternions (better for complex rotations)
const quaternion = BABYLON.Quaternion.RotationAxis(
new BABYLON.Vector3(1, 1, 0).normalize(), // Axis to rotate around
Math.PI / 3 // Angle in radians
);
sphere.rotationQuaternion = quaternion;
// Scaling
torus.scaling = new BABYLON.Vector3(1.5, 1.5, 1.5); // Uniform scaling
plane.scaling = new BABYLON.Vector3(2, 1, 1); // Non-uniform scaling
// Apply multiple transformations with a matrix
const matrix = BABYLON.Matrix.Compose(
new BABYLON.Vector3(1.2, 0.8, 1.2), // Scaling
BABYLON.Quaternion.RotationYawPitchRoll(0.3, 0, 0), // Rotation
new BABYLON.Vector3(2, 0, -3) // Translation
);
ground.setPivotMatrix(matrix);