Search
Loading...
Skip to content

Rotate Videos

Rotate video elements to any angle using radians or degrees, with precise programmatic control and UI rotation handles.

Rotate videos example showing videos at different rotation angles

8 mins
estimated time
Download
StackBlitz
GitHub

Rotation in CE.SDK occurs around the block’s center point. All rotation values use radians, where Math.PI equals 180 degrees. Positive values rotate counterclockwise, negative values rotate clockwise.

This guide covers rotating videos programmatically, converting between degrees and radians, grouping blocks for collective rotation, and locking rotation permissions.

Rotating Videos#

Rotate videos using engine.block.setRotation() with the angle in radians. Convert from degrees using the formula radians = degrees * Math.PI / 180:

// Rotate the video 45 degrees (in radians)
const toRadians = (degrees: number) => (degrees * Math.PI) / 180;
engine.block.setRotation(rotatedVideo, toRadians(45));

Getting Current Rotation#

Read the current rotation value using engine.block.getRotation(). The value is returned in radians. Convert to degrees with degrees = radians * 180 / Math.PI:

// Get current rotation value
const currentRotation = engine.block.getRotation(rotatedVideo);
const toDegrees = (radians: number) => (radians * 180) / Math.PI;
console.log('Current rotation:', toDegrees(currentRotation), 'degrees');

Common Rotation Angles#

For 90-degree rotations, use Math.PI / 2. For 180 degrees, use Math.PI. For 270 degrees, use 3 * Math.PI / 2:

// Rotate 90 degrees using Math.PI / 2
engine.block.setRotation(rotatedVideo90, Math.PI / 2);

Locking Rotation#

Disable rotation for specific blocks using engine.block.setScopeEnabled() with the 'layer/rotate' scope set to false:

// Disable rotation for this specific block
engine.block.setScopeEnabled(lockedVideo, 'layer/rotate', false);

Checking Rotation Permissions#

Check if rotation is enabled for a block using engine.block.isScopeEnabled():

// Check if rotation is enabled for a block
const canRotate = engine.block.isScopeEnabled(lockedVideo, 'layer/rotate');
console.log('Rotation enabled:', canRotate);

Troubleshooting#

Rotation Has No Effect#

Verify the block exists in the scene and is not a page block. Check if rotation is locked using engine.block.isScopeEnabled(block, 'layer/rotate').

Rotation Handle Missing#

Check if rotation handles are hidden globally via controlGizmo/showRotateHandles setting. Verify the 'layer/rotate' scope is enabled for the block.

Unexpected Rotation Direction#

Remember that positive values rotate counterclockwise in CE.SDK. To rotate clockwise, use negative radian values.

API Reference#

MethodDescription
engine.block.setRotation()Set block rotation in radians
engine.block.getRotation()Get current rotation in radians
engine.block.setScopeEnabled()Enable/disable 'layer/rotate' scope
engine.block.isScopeEnabled()Check if rotation is allowed
engine.block.setTransformLocked()Lock all transforms including rotation