Skip to content

WasmGPU.createTransform().setParent

Summary

WasmGPU.createTransform().setParent reparents a transform under another transform, or detaches it when null is passed. The method updates both the JavaScript hierarchy (parent and children) and the backing transform-store parent index. It rejects invalid operations like self-parenting and ancestor cycles. Use this when assembling scene hierarchies dynamically or attaching objects to moving reference frames.

Syntax

WasmGPU.createTransform().setParent(parent: Transform | null): this
const result = child.setParent(parent);

Parameters

Name Type Required Description
parent Transform \| null Yes New parent transform, or null to make the node a root transform.

Returns

this - Returns the child transform after reparenting.

Type Details

type Transform = {
    parent: Transform | null;
    children: readonly Transform[];
    setParent(parent: Transform | null): Transform;
};

Example

const canvas = document.querySelector("canvas");
const wgpu = await WasmGPU.create(canvas);

const solarSystem = wgpu.createTransform();
const earth = wgpu.createTransform().setPosition(10, 0, 0);
const moon = wgpu.createTransform().setPosition(2, 0, 0);

earth.setParent(solarSystem);
moon.setParent(earth);
console.log(moon.parent === earth, moon.root === solarSystem);

See Also