Contains a model's geometry and materials.

See @xeokit/sdk/scene for usage.

Properties

coordinateSystem: CoordinateSystem

Configures the SceneModel's local coordinate system.

Internally, a matrix is created to transform coordinates between SceneModel and Scene CoordinateSystems. The matrix of each SceneMesh is premultiplied by that matrix, effectively transforming the SceneModel into the global coordinate system.

coordinateSystemMatrix: Mat4

Caches a matrix used to transform positions between SceneModel and Scene CoordinateSystems. Each SceneMesh's matrix is pre-multiplied by this matrix to effectively move the vertex positions from the SceneModel CoordinateSystem to the Scene CoordinateSystem within.

destroyed: boolean = false

Indicates if this SceneModel has been destroyed.

  • Set true by SceneModel.destroy.
  • Don't create anything more in this SceneModel once it's destroyed.
geometries: { [key: string]: SceneGeometry }

Geometries within this SceneModel, each mapped to SceneGeometry.id.

globalizedIds: boolean

Whether IDs of SceneObjects are globalized.

When globalized, the IDs are prefixed with the value of SceneModel.id

This is false by default.

id: string

Unique ID of this SceneModel.

SceneModel are stored against this ID in Scene.models.

layerId?: string

If we want to view this SceneModel with a Viewer, an optional ID of a ViewLayer to view it in.

meshes: { [key: string]: SceneMesh }

SceneMeshes within this SceneModel, each mapped to SceneMesh.id.

objects: { [key: string]: SceneObject }

SceneObjects within this SceneModel, each mapped to SceneObject.id.

scene: Scene

The Scene that contains this SceneModel.

Statistics on this SceneModel.

Values are updated as content is created/destroyed:

  • numTransforms, numGeometries, numMeshes, numObjects
  • numVertices, numTriangles, numLines, numPoints
  • numTextures, numTextureSets, textureBytes
textures: { [key: string]: SceneTexture }

Textures within this SceneModel, each mapped to SceneTexture.id.

textureSets: { [key: string]: SceneTextureSet }

TextureSets within this SceneModel, each mapped to SceneTextureSet.id.

transforms: { [key: string]: SceneTransform }

SceneTransform | SceneTransforms within this SceneModel, each mapped to SceneTransform.id | SceneTransform.id.

Methods

  • Creates a new SceneGeometry within this SceneModel, from non-compressed geometry parameters.

    const boxGeometryResult = sceneModel.createGeometry({
    id: "boxGeometry",
    primitive: TrianglesPrimitive, // @xeokit/constants
    positions: [
    1, 1, 1, -1, 1, 1, -1, -1, 1, 1, -1, 1, // v0-v1-v2-v3 front
    1, 1, 1, 1, -1, 1, 1, -1, -1, 1, 1, -1, // v0-v3-v4-v1 right
    1, 1, 1, 1, 1, -1, -1, 1, -1, -1, 1, 1, // v0-v1-v6-v1 top
    -1, 1, 1, -1, 1, -1, -1, -1, -1, -1, -1, 1, // v1-v6-v7-v2 left
    -1, -1, -1, 1, -1, -1, 1, -1, 1, -1, -1, 1,// v7-v4-v3-v2 bottom
    1, -1, -1, -1, -1, -1, -1, 1, -1, 1, 1, -1 // v4-v7-v6-v1 back
    ],
    indices: [
    0, 1, 2, 0, 2, 3, 4, 5, 6, 4, 6, 7, 8, 9, 10, 8, 10, 11, 12, 13, 14, 12, 14, 15,
    16, 17, 18, 16, 18, 19, 20, 21, 22, 20, 22, 23
    ]
    });

    if (!boxGeometryResult.ok) {
    console.error(boxGeometryResult.error);
    return;
    } else {
    const boxGeometry = boxGeometryResult.value;
    }

    const boxGeometryAgain = sceneModel.geometries["boxGeometry"];

    See @xeokit/sdk/scene for more usage info.

    Parameters

    Returns SDKResult<SceneGeometry>

    SDKResult with:

    • On success, the created SceneGeometry.
    • On failure, an error message. Reasons for failure include:
      • If this SceneModel has already been destroyed.
      • Invalid SceneGeometryParams were given.
      • A SceneGeometry with the given ID already exists in this SceneModel.
      • Unsupported primitive type was provided.
      • Mandatory vertex positions were not provided. Vertex positions are required for all primitive types.
      • Mandatory indices were not provided for primitive types other than constants!PointsPrimitive.
      • Indices are out of range of vertex positions.
      • Indices are out of range of vertex UVs.
      • Mismatch between the quantities of vertex positions and UVs.
  • Creates a new SceneGeometry within this SceneModel, from pre-compressed geometry parameters.

    const boxGeometryResult = sceneModel.createGeometryCompressed({
    id: "boxGeometry",
    primitive: TrianglesPrimitive, // @xeokit/constants
    aabb: [-1,-1,-1, 1,1,1],
    positionsCompressed: [
    65525, 65525, 65525, 0, 65525, 65525, 0, 0,
    65525, 65525, 0, 65525, 65525, 0, 0, 65525,
    65525, 0, 0, 65525, 0, 0, 0, 0
    ],
    indices: [
    0, 1, 2, 0, 2, 3, 0, 3, 4, 0, 4, 5, 0, 5, 6,
    0, 6, 1, 1, 6, 7, 1, 7, 2, 7, 4, 3, 7, 3, 2,
    4, 7, 6, 4, 6, 5
    ]
    });

    if (!boxGeometryResult.ok) {
    console.error(boxGeometryResult.error);
    return;
    } else {
    const boxGeometry = boxGeometryResult.value;
    }

    See @xeokit/sdk/scene for more usage info.

    Parameters

    Returns SDKResult<SceneGeometry>

    SDKResult with:

      • On failure, an error message. Reasons for failure include:
      • If this SceneModel has already been destroyed.
      • Invalid SceneGeometryParams were given.
      • SceneGeometry of given ID already exists in this SceneModel.
      • Unsupported primitive type given.
      • Mandatory vertex positions were not given. Vertex positions are mandatory for all primitive types.
      • Mandatory indices were not given for primitive type that is not constants!PointsPrimitive. Indices are mandatory for all primitive types except PointsPrimitive.
      • Indices out of range of vertex positions.
      • Indices out of range of vertex UVs.
      • Mismatch between given quantities of vertex positions and UVs.
  • Creates a new SceneTexture within this SceneModel.

    const textureResult = sceneModel.createTexture({
    id: "myColorTexture",
    src: // Path to JPEG, PNG, KTX2,
    image: // HTMLImageElement,
    buffers: // ArrayBuffer[] containing KTX2 MIP levels
    preloadColor: [1,0,0,1],
    flipY: false,
    encoding: LinearEncoding, // @xeokit/constants
    magFilter: LinearFilter,
    minFilter: LinearFilter,
    wrapR: ClampToEdgeWrapping,
    wrapS: ClampToEdgeWrapping,
    wrapT: ClampToEdgeWrapping,
    });

    if (!textureResult.ok) {
    console.error(textureResult.error);
    return;
    } else {
    const texture = textureResult.value;
    }

    const textureAgain = sceneModel.textures["myColorTexture"];

    See @xeokit/sdk/scene for more usage info.

    Parameters

    Returns SDKResult<SceneTexture>

    SDKResult with:

    • On success, the created SceneTexture.
    • On failure, an error message. Reasons for failure include:
      • SceneModel already destroyed.
      • Missing required parameter: textureParams.imageData, textureParams.src or textureParams.buffers.
      • Texture already exists with the given ID.
      • Unsupported image extension.
  • Creates a new SceneTransform within this SceneModel.

    • Stores the transform in SceneModel.transforms.
    • Optionally attaches it under a parent transform using SceneTransform.setParentTransform.
    • The final transform matrix can be supplied directly via matrix or composed from position, scale and rotation (Euler) or quaternion.
    • Fires Scene.events.onSceneTransformCreated | Scene.events.onSceneTransformCreated event.

    Parameters

    • transformParams: SceneTransformParams

      Parameters describing the transform to create.

    Returns SDKResult<SceneTransform>

    An SDKResult with:

    • On success, the created SceneTransform.
    • On failure, an error message. Reasons for failure include:
      • SceneModel already destroyed.
      • SceneTransform already exists with the given ID.
      • Parent SceneTransform not found with the given parentTransformId.
    const rootTransformResult = sceneModel.createTransform({
    id: "root",
    position: [10, 0, 0]
    });

    if (!rootTransformResult.ok) {
    console.error(rootTransformResult.error);
    return;
    }

    const rootTransform = rootTransformResult.value;

    sceneModel.createTransform({
    id: "child",
    parentTransformId: "root",
    rotation: [0, Math.PI * 0.5, 0]
    });