Skip to main content

Transform

TypeNameInterface Description
VariableslocalPosition: Vector3fFunction: Defines the local position of an object.
VariableslocalScale: Vector3fFunction: Defines the local scaling of an object.
VariableslocalRotation: QuaternionfFunction: Defines the local rotation of an object.

Examples

localPosition: Vector3f

trans.localPosition = new APJS.Vector3f(1,0,0);

localScale: Vector3f

trans.localScale = new APJS.Vector3f(2,2,2);

localRotation: Quaternionf

trans.localRotation = APJS.Quaternionf.makeFromAngleAxis(
0.2, new APJS.Vector3f(0, 1, 0));

Use Case

@component()
export class NewBehaviourScript extends APJS.BasicScriptComponent {
private firstFrame = true;
private time = 0.0;
onStart() {
}
onUpdate(deltaTime: number) {
if (this.firstFrame) {
this.firstFrame = false;
}
let child = this.getSceneObject().getChild('Cube');
let trans = child?.getTransform();
if(!trans) return;

this.time += deltaTime;

var radius = 10;
trans.localPosition = new APJS.Vector3f(
radius * Math.cos(this.time),
radius * Math.sin(this.time),
0);

trans.localRotation = APJS.Quaternionf.makeFromAngleAxis(
this.time, new APJS.Vector3f(0, 1, 0));

var scale = 0.5 + (Math.sin(this.time) + 1) * 0.5;
trans.localScale = new APJS.Vector3f(scale, scale, scale);
}
}

DemoTransformTSROpt.zip

TypeNameInterface Description
FunctionslocalMatrix: Matrix4x4fFunction: Obtain the world transformation matrix of an object, which is used to convert local coordinates to world coordinates.

Example

 trans.localMatrix =  APJS.Matrix4x4f.makeFromRotation(rot);
TypeNameInterface DescriptionExample
FunctionssetWorldMatrix(matrix: Matrix4x4f): voidFunction: Sets the world position of the object.Code block

1 trans.setWorldMatrix([

2 API.Matrix4x4f.makeTransform(

3 position: { };

Example

 trans.setWorldMatrix( APJS.Matrix4x4f.makeFromRotation(rot) );

Use Case

@component()
export class NewBehaviourScript extends APJS.BasicScriptComponent {
private firstFrame = true;
private time = 0.0;
onStart() {
}
onUpdate(deltaTime: number) {
if (this.firstFrame) {
this.firstFrame = false;
}
let child = this.getSceneObject().getChild('Cube');
let trans = child?.getTransform();
if(!trans) return;

this.time += deltaTime;

var radius = 10;

const rot = APJS.Quaternionf.makeFromAngleAxis(
this.time, new APJS.Vector3f(0, 1, 0));

trans.setWorldMatrix( APJS.Matrix4x4f.makeFromRotation(rot) );
}
}
TypeNameInterface Description
FunctionsgetWorldMatrix(): Matrix4x4fFunction: Get the world position of the object.

Example

let worldMatrix = transform.getWorldMatrix();
TypeNameInterface DescriptionExample
FunctionssetWorldPosition(pos: Vector3f): voidFunction: Sets the world position of the object.Code block

1 trans.setWorldPosition(new

2 API.Vector3f(1,0,0));

FunctionsgetWorldPosition(): Vector3fFunction: Get the world rotation of the object.Code block

1 let worldPosition =

2 transform.getWorldPosition();

FunctionssetWorldRotation(rotation: Quaternionf): voidFunction: Sets the world scale of the object.Code block

1 transform.setWorldRotation(ne

2 w Quaternionf(0, 0, 0, 1));

FunctionsgetWorldRotation(): QuaternionfFunction: Get the world scale of the object.Code block

1 let worldRotation =

2 transform.getWorldRotation();

FunctionssetWorldScale(scale: Vector3f): voidFunction: Sets the world scale of the object.Code block

1 transform.setWorldScale(new

2 Vector3f(2, 2, 2));

FunctionsgetWorldScale(): Vector3fFunction: Get the world scale of the object.Code block

1 let worldScale =

2 transform.getWorldScale();

Use Case

@component()
export class NewBehaviourScript extends APJS.BasicScriptComponent {
private firstFrame = true;
private time = 0.0;
onStart() {
}
onUpdate(deltaTime: number) {
if (this.firstFrame) {
this.firstFrame = false;
}
let child = this.getSceneObject().getChild('Cube');
let trans = child?.getTransform();
if(!trans) return;

this.time += deltaTime;

var radius = 10;
trans.setWorldPosition(new APJS.Vector3f(
radius * Math.cos(this.time),
radius * Math.sin(this.time),
0));

trans.setWorldRotation(APJS.Quaternionf.makeFromAngleAxis(
this.time, new APJS.Vector3f(0, 1, 0)));

var scale = 0.5 + (Math.sin(this.time) + 1) * 0.5;
trans.setWorldScale(new APJS.Vector3f(scale, scale, scale));
}
}

Scenario Example

Achieve object rotation by modifying rotation

      let rotation = sceneObject.getTransform().localRotation;
let r = new APJS.Quaternionf();
r.x = 0;
r.y = Math.sin(5);
r.z = 0;
r.w = Math.cos(5);
rotation = rotation.multiply(r);
sceneObject.getTransform().localRotation = rotation;
Copyright © 2025 TikTok. All rights reserved.
About TikTokHelp CenterCareersContactLegalCookies