Class SceneTransform

Represents a spatial transform within a SceneModel.

A SceneTransform defines a local coordinate space using position, rotation, and scale, and can be composed into a hierarchy of transforms. SceneMesh instances are typically attached to transforms, allowing geometry to inherit transforms from parent nodes.

  • Transforms form a tree (scene graph) within a SceneModel
  • Each transform has an optional parent transform
  • Child transforms and meshes inherit the parent’s transform
  • Transforms can be authored using TRS (position / rotation / scale) or a matrix

Transforms are created via SceneModel.createTransform and referenced by ID. Meshes are attached to transforms, and meshes can then be grouped into SceneObjects for selection, visibility, and interaction.

// Create a root transform positioned in world space
sceneModel.createTransform({
id: "rootTransform",
position: [100000, 0, 0]
});

// Create a child transform for a table leg
sceneModel.createTransform({
id: "childTransform",
parentTransformId: "rootTransform",
position: [-4, -6, -4],
scale: [1, 3, 1]
});

// Create geometry
sceneModel.createGeometry({
id: "demoGeometry",
//...
});

// Attach a mesh to the transform
sceneModel.createMesh({
id: "redLegMesh",
geometryId: "demoGeometry",
parentTransformId: "childTransform",
color: [1, 0, 0]
});

// Group the mesh into a scene object
sceneModel.createObject({
id: "redLegObject",
meshIds: ["redLegMesh"]
});

// Update transforms dynamically (eg. animation)
const root = sceneModel.transforms["rootTransform"];
root.rotation = [0, performance.now() / 40, 0];
  • Setting position, rotation, quaternion, or scale updates the local transform.
  • Setting matrix directly replaces the local transform and updates TRS values.
  • Destroying a transform automatically detaches it from the hierarchy.

See @xeokit/sdk/scene for more complete examples.

Properties

destroyed: boolean = false

True once destroy has been called.

id: string

Unique identifier for this transform within the SceneModel.

model: SceneModel

The SceneModel this transform belongs to.

Accessors

Methods

  • Adds a child mesh to this transform by ID.

    This resolves the mesh from the owning SceneModel and then parents it under this transform.

    When destroyed, logs an error and returns a failed result.

    Parameters

    • childMeshId: string

      ID of the mesh to add.

    Returns SDKResult<any>

  • Adds a child transform to this transform by ID.

    This resolves the transform from the owning SceneModel and then parents it under this transform (equivalent to child.setParentTransform(this, opts)).

    Parameters

    • childTransformId: string

      ID of the child transform to add.

    • Optionalopts: { preserveWorld?: boolean }

      Options forwarded to setParentTransform.

    Returns SDKResult<any>

  • Removes a child transform from this transform by ID (if it is currently parented here).

    When destroyed, logs an error and returns a failed result.

    Parameters

    • childTransformId: string

      ID of the child transform to remove.

    Returns SDKResult<any>

  • Sets the parent transform for this transform.

    Parameters

    • parentTransformId: string

      ID of the new parent transform, or null/undefined to unparent.

    • Optionalopts: { preserveWorld?: boolean }

      Options.

      • OptionalpreserveWorld?: boolean

        When true, keeps the world transform unchanged.

    Returns SDKResult<any>