Skip to main content

Transform

Class

Controls the position, rotation, and scale of a SceneObject.

  • Available on all platforms
Platform details: Snapchat, SPECS, Camera Kit Web, Camera Kit Mobile fully supported.

Platform details

  • Snapchat — Fully supported.

  • SPECS — Fully supported.

  • Camera Kit Web — Fully supported.

  • Camera Kit Mobile — Fully supported.

Controls the position, rotation, and scale of a SceneObject. Every SceneObject automatically has a Transform attached.

Index

Example

// Move attached Transform 1 unit up
var transform = script.getTransform();
var pos = transform.getWorldPosition();
pos.y += 1;
transform.setWorldPosition(pos);
// Bind to "Frame Updated" to rotate the object every frame
var transform = script.getTransform();
var rotation = transform.getLocalRotation();
var rotateBy = quat.angleAxis(Math.PI*getDeltaTime(), vec3.up());
rotation = rotation.multiply(rotateBy);
transform.setLocalRotation(rotation);

Extends

Properties

back

readonly back: vec3

Returns the Transform's back directional vector.


down

readonly down: vec3

Returns the Transform's down directional vector.


forward

readonly forward: vec3

Returns the Transform's forward directional vector.


left

readonly left: vec3

Returns the Transform's left directional vector.


readonly right: vec3

Returns the Transform's right directional vector.


segmentScaleCompensate

segmentScaleCompensate: boolean

When scaling a parent with segment scale enabled, instead of scaling child objects, it creates position offsets. This setting is used when exporting from certain 3d authoring tools.

Default Value

false

up

readonly up: vec3

Returns the Transform's up directional vector.

Methods

getInvertedWorldTransform()

getInvertedWorldTransform(): mat4

Returns the Transform's world-to-local transformation matrix.

Returns

mat4


getLocalPosition()

getLocalPosition(): vec3

Returns the Transform's position relative to its parent.

Returns

vec3


getLocalRotation()

getLocalRotation(): quat

Returns the Transform's rotation relative to its parent.

Returns

quat


getLocalScale()

getLocalScale(): vec3

Returns the Transform's scale relative to its parent.

Returns

vec3


getSceneObject()

getSceneObject(): SceneObject

Returns the SceneObject the Transform is attached to.

Returns

SceneObject


getTypeName()

static getTypeName(): TypeName<Transform>

Returns the fully-qualified JavaScript type name for this class (for example, "Component.Camera"). This is a static accessor (no instance required) and returns the same value as the instance getTypeName().

Returns

TypeName<Transform>

Overrides

ScriptObject.getTypeName


getTypeName()

getTypeName(): string

Returns the name of this object's type.

Returns

string

Inherited from

ScriptObject.getTypeName


getWorldPosition()

getWorldPosition(): vec3

Returns the Transform's position relative to the world.

Returns

vec3


getWorldRotation()

getWorldRotation(): quat

Returns the Transform's rotation relative to the world.

Returns

quat


getWorldScale()

getWorldScale(): vec3

Returns the Transform's scale relative to the world.

Returns

vec3


getWorldTransform()

getWorldTransform(): mat4

Returns the Transform's local-to-world transformation matrix.

Returns

mat4


isOfType()

isOfType(type): boolean

Returns true if the object matches or derives from the passed in type.

Parameters

ParameterType
typestring

Returns

boolean

Inherited from

ScriptObject.isOfType


isSame()

isSame(other): boolean

Returns true if this object is the same as other. Useful for checking if two references point to the same thing.

Parameters

ParameterType
otherScriptObject

Returns

boolean

Inherited from

ScriptObject.isSame


setLocalPosition()

setLocalPosition(pos): void

Sets the Transform's position relative to its parent.

Parameters

ParameterType
posvec3

Returns

void


setLocalRotation()

setLocalRotation(rotation): void

Sets the Transform's rotation relative to its parent.

Parameters

ParameterType
rotationquat

Returns

void


setLocalScale()

setLocalScale(scale): void

Sets the Transform's scale relative to its parent.

Parameters

ParameterType
scalevec3

Returns

void


setLocalTransform()

setLocalTransform(transformMat): void

Sets the Transform's local transformation matrix.

Parameters

ParameterType
transformMatmat4

Returns

void

Since

Lens Scripting Version 148


setWorldPosition()

setWorldPosition(pos): void

Sets the Transform's position relative to the world.

Parameters

ParameterType
posvec3

Returns

void


setWorldRotation()

setWorldRotation(rotation): void

Sets the Transform's rotation relative to the world.

Parameters

ParameterType
rotationquat

Returns

void


setWorldScale()

setWorldScale(scale): void

Sets the Transform's scale relative to the world. This may produce lossy results when parent objects are rotated, so use setLocalScale() instead if possible.

Parameters

ParameterType
scalevec3

Returns

void


setWorldTransform()

setWorldTransform(transformMat): void

Sets the Transform's transformation matrix.

Parameters

ParameterType
transformMatmat4

Returns

void

Since

Lens Scripting Version 148