BasicMaterialInstance

View source

Component that associates an entity with a BasicMaterial asset. It specializes MaterialInstance for basic materials, providing the material-instance value used to identify that asset for the entity.

Examples

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

const world = new World()
const materials = new Assets(BasicMaterial)
const material = materials.add(new BasicMaterial())
const entity = world.spawn([new BasicMaterialInstance(material)])

// With the render-core material plugin registered, pair this component with
// a mesh and transform to include the entity in a camera render pass.
console.log(world.get(entity, BasicMaterialInstance).handle.id())

Constructor


constructor(handle: Handle<BasicMaterial>)

View source

Creates a material component from a typed material handle.

The supplied handle is stored directly and is not copied or resolved. Concrete material components pass their material handle to super.

Parameters

NameDescriptionDefault
handle——

Methods


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

View source

Copies a basic material component and acquires an independent handle for the same material asset.

When target is omitted, a new component is created. In either case, the target receives source.handle.clone() and the source handle is not reused as the target’s handle.

Parameters

NameDescriptionDefault
source——
target?—...

Returns

The populated target component.

statictoSnapshot(instance: BasicMaterialInstance, world: World): BasicMaterialInstanceSnapshot

View source

Creates persistence data for this component’s material handle.

The snapshot does not retain the live handle. A path-backed snapshot uses the world’s asset server when restored; an index-backed snapshot requires the owning scene asset ID when BasicMaterialInstance.fromSnapshot is called.

Parameters

NameDescriptionDefault
instance

Live component being snapshotted.

—
world

World used to resolve asset metadata.

—

Returns

Snapshot of the material handle.