Meshed

View source

Associates an entity with a Mesh asset through an ECS component handle.

Use Meshed with a material component such as BasicMaterialInstance when an entity should use a mesh with a material. This component supplies the mesh reference; the entity’s transform and material are separate components.

Examples

import { Assets } from '@wimaengine/asset'
import { World } from '@wimaengine/ecs'
import {
  BasicMaterial,
  BasicMaterialInstance,
  Mesh,
  Meshed
} from '@wimaengine/render-core'
import { createTransform3D } from '@wimaengine/transform'

const meshes = new Assets(Mesh)
const materials = new Assets(BasicMaterial)
const mesh = meshes.add(Mesh.triangle3D())
const material = materials.add(BasicMaterial.default())

const world = new World()
const entity = world.spawn([
  ...createTransform3D(),
  new Meshed(mesh),
  new BasicMaterialInstance(material)
])

Constructor


constructor(handle: Handle<Mesh>)

View source

Creates a mesh component from an asset handle.

The supplied handle is stored as-is. A registered remove hook releases the handle when the component is removed from an entity.

Parameters

NameDescriptionDefault
handle

Handle to the mesh asset for the entity.

—

Properties


handle: Handle<Mesh>

View source

Mesh asset handle held by the component.

The handle identifies the Mesh asset without copying its data into the entity.

Methods


staticcopy(source: Meshed, target?: Meshed): Meshed

View source

Copies a mesh component and acquires another handle to the same mesh asset.

When target is omitted, a new Meshed component is returned. In either case, the target receives an independent handle from Handle#clone, so the copied component refers to the same asset and can be released independently.

Parameters

NameDescriptionDefault
source

Component whose mesh handle should be copied.

—
target?

Component to populate.

...

Returns

The populated target component.

staticclone(target: Meshed): Meshed

View source

Creates a mesh component with an independent handle reference to the same mesh asset as target.

This delegates to Meshed.copy.

Parameters

NameDescriptionDefault
target

Component to clone.

—

Returns

A new component with a cloned mesh handle.

statictoSnapshot(meshed: Meshed, world: World): MeshedSnapshot

View source

Creates persistence data for this component’s mesh handle.

This delegates to Handle#toSnapshot. The nested HandleSnapshot stores an asset-server path when the world has path metadata for this handle. Otherwise it stores the mesh’s scene-local asset-pool index for restoration with the owning scene asset ID.

Parameters

NameDescriptionDefault
meshed

Live mesh component being snapshotted.

—
world

World used to resolve asset metadata.

—

Returns

Snapshot containing the mesh handle reference.