Skip to content

@orillusion/core


Class: MirrorComponent

Defined in: src/components/MirrorComponent.ts:68

One-stop planar mirror component. Attach to an Object3D that already carries a MeshRenderer with a MirrorMaterial (any geometry — plane, terrain patch, irregular puddle) and the component sets up the rest:

  1. Spawns an off-screen Camera3D at the plane-mirror of the main camera (refreshed every frame from MirrorComponent.onUpdate).
  2. Attaches a SceneCaptureCameraComponent so that camera renders the scene into a render target every frame.
  3. Tags the host renderer with MirrorComponent.MIRROR_MASK and configures the capture's excludeMask so the mirror surface does not capture itself (avoids feedback / "mirror in mirror" recursion artefacts).
  4. Binds the capture RT into the host's MirrorMaterial as soon as the capture pass has produced a texture (lazy — runs once on the first frame the RT becomes non-null).

Usage

ts
const floor = new Object3D();
const mr = floor.addComponent(MeshRenderer);
mr.geometry = new PlaneGeometry(40, 40);
mr.material = new MirrorMaterial();
const mirror = floor.addComponent(MirrorComponent);
mirror.mainTarget = new Vector3(0, 1, 0);  // what the main camera looks at
scene.addChild(floor);

The component reads mainCamera from View3D.camera on enable when not explicitly set, so a single-camera scene needs no other configuration. The mirror plane (point + normal) is also snapshot from the host's world transform on first start — so a tilted/rotated host produces a correctly oriented mirror without any manual plane setup.

Limits

  • The mirror plane is snapshot once at start from the host transform. If the host moves or rotates afterwards, update mirrorPlanePoint / mirrorPlaneNormal explicitly.
  • Multiple mirrors in the same scene all share MIRROR_MASK — that means no mirror captures any other mirror surface (good — prevents feedback) but it also means a mirror can not appear in another mirror's reflection. If you need cross-mirror reflections, give each mirror a unique bit on MeshRenderer.rendererMask + a matching excludeMask set on its captureComponent manually.

Extends

Constructors

Constructor

new MirrorComponent(): MirrorComponent

Returns

MirrorComponent

Inherited from

ComponentBase.constructor

Properties

MIRROR_MASK

readonly static MIRROR_MASK: number

Defined in: src/components/MirrorComponent.ts:76

Custom RendererMask bit reserved for "this is a mirror surface and should not appear in other mirrors". Bit 11 is unclaimed by the engine's built-in mask values (highest is RendererMask.Graphic3D = 1 << 10). Exposed so user code can check / clear it on hand-managed renderers.


object3D

object3D: Object3D = null

Defined in: src/components/ComponentBase.ts:29

owner object3D

Inherited from

ComponentBase.object3D


isDestroyed

isDestroyed: boolean = false

Defined in: src/components/ComponentBase.ts:77

Inherited from

ComponentBase.isDestroyed


width

width: number = 1024

Defined in: src/components/MirrorComponent.ts:81

Capture render-target width in pixels. Forwarded to SceneCaptureCameraComponent.width. Setting this after enable triggers an RT reallocation on the next frame.


height

height: number = 1024

Defined in: src/components/MirrorComponent.ts:84

Capture render-target height in pixels.


mirrorPlanePoint

mirrorPlanePoint: Vector3

Defined in: src/components/MirrorComponent.ts:90

A world-space point lying on the mirror plane. Defaults to the host Object3D's world position on first start, so a flat floor needs no manual setup. Override before/after start to move the reflection plane independently of the host.


mirrorPlaneNormal

mirrorPlaneNormal: Vector3

Defined in: src/components/MirrorComponent.ts:96

Unit normal of the mirror plane in world space. Defaults to the host Object3D's world-space +Y axis (i.e. transform.up) on first start — matching a PlaneGeometry whose face is up. Override for tilted glass, vertical mirrors, etc.


mainCamera

mainCamera: Camera3D = null

Defined in: src/components/MirrorComponent.ts:101

The scene's main camera that this mirror reflects. When left null, resolves to View3D.camera on enable. Set explicitly if your scene swaps cameras at runtime.


mainTarget

mainTarget: Vector3

Defined in: src/components/MirrorComponent.ts:108

World-space point the main camera looks at — the mirror camera is aimed at the reflection of this point across the mirror plane. Default is the world origin; override to match your camera controller's pivot (e.g. HoverCameraController.setCamera's target argument).

Accessors

visibleLayer

Get Signature

get visibleLayer(): number

Defined in: src/components/ComponentBase.ts:46

Composition-layer membership bitmask. The pass / camera / collector filters via

(component.visibleLayer & pass.layerMask & camera.cullingMask) !== 0

Defaults to VisibleLayer.Default (bit 0) so a fresh subclass is visible to passes whose layerMask is VisibleLayer.All (which includes bit 0). Application code can assign project-specific bits (1..31) to organise the scene into composition layers.

Returns

number

Set Signature

set visibleLayer(value): void

Defined in: src/components/ComponentBase.ts:50

Parameters
value

number

Returns

void

Inherited from

ComponentBase.visibleLayer


eventDispatcher

Get Signature

get eventDispatcher(): CEventDispatcher

Defined in: src/components/ComponentBase.ts:63

Returns

CEventDispatcher

Set Signature

set eventDispatcher(value): void

Defined in: src/components/ComponentBase.ts:68

Parameters
value

CEventDispatcher

Returns

void

Inherited from

ComponentBase.eventDispatcher


isStart

Get Signature

get isStart(): boolean

Defined in: src/components/ComponentBase.ts:79

Returns

boolean

Inherited from

ComponentBase.isStart


transform

Get Signature

get transform(): Transform

Defined in: src/components/ComponentBase.ts:89

Return the Transform component attached to the Object3D. Null before the component is attached — addComponent assigns object3D only after construction — so constructor-time callers can probe safely via this.transform?..

Returns

Transform

Inherited from

ComponentBase.transform


enable

Get Signature

get enable(): boolean

Defined in: src/components/ComponentBase.ts:113

Enable/disable components. The enabled components can be updated, while the disabled components cannot be updated.

Returns

boolean

Set Signature

set enable(value): void

Defined in: src/components/ComponentBase.ts:96

Enable/disable components. The enabled components can be updated, while the disabled components cannot be updated.

Parameters
value

boolean

Returns

void

Inherited from

ComponentBase.enable


captureComponent

Get Signature

get captureComponent(): SceneCaptureCameraComponent

Defined in: src/components/MirrorComponent.ts:124

Live reference to the auto-created scene-capture component, in case advanced users want to tweak its properties (clearColor, includeSky, updateMode, …). Null until enable.

Returns

SceneCaptureCameraComponent


material

Get Signature

get material(): MirrorMaterial

Defined in: src/components/MirrorComponent.ts:132

The MirrorMaterial the component bound. Resolved from the host MeshRenderer on enable. Null if no MirrorMaterial was found (the component logs a warning and no-ops in that case).

Returns

MirrorMaterial

Methods

init()

init(param?): void

Defined in: src/components/ComponentBase.ts:161

Parameters

param?

any

Returns

void

Inherited from

ComponentBase.init


stop()

stop(): void

Defined in: src/components/ComponentBase.ts:163

Returns

void

Inherited from

ComponentBase.stop


onLateUpdate()?

optional onLateUpdate(view?): any

Defined in: src/components/ComponentBase.ts:167

Parameters

view?

View3D

Returns

any

Inherited from

ComponentBase.onLateUpdate


onBeforeUpdate()?

optional onBeforeUpdate(view?): any

Defined in: src/components/ComponentBase.ts:168

Parameters

view?

View3D

Returns

any

Inherited from

ComponentBase.onBeforeUpdate


onCompute()?

optional onCompute(view?, command?): any

Defined in: src/components/ComponentBase.ts:169

Parameters

view?

View3D

command?

GPUCommandEncoder

Returns

any

Inherited from

ComponentBase.onCompute


onGraphic()?

optional onGraphic(view?): any

Defined in: src/components/ComponentBase.ts:170

Parameters

view?

View3D

Returns

any

Inherited from

ComponentBase.onGraphic


onParentChange()?

optional onParentChange(lastParent?, currentParent?): any

Defined in: src/components/ComponentBase.ts:171

Parameters

lastParent?

Object3D

currentParent?

Object3D

Returns

any

Inherited from

ComponentBase.onParentChange


onAddChild()?

optional onAddChild(child): any

Defined in: src/components/ComponentBase.ts:172

Parameters

child

Object3D

Returns

any

Inherited from

ComponentBase.onAddChild


onRemoveChild()?

optional onRemoveChild(child): any

Defined in: src/components/ComponentBase.ts:173

Parameters

child

Object3D

Returns

any

Inherited from

ComponentBase.onRemoveChild


cloneTo()

cloneTo(obj): void

Defined in: src/components/ComponentBase.ts:180

clone component data to target object3D

Parameters

obj

Object3D

target object3D

Returns

void

Inherited from

ComponentBase.cloneTo


copyComponent()

copyComponent(from): this

Defined in: src/components/ComponentBase.ts:182

Parameters

from

this

Returns

this

Inherited from

ComponentBase.copyComponent


beforeDestroy()

beforeDestroy(force?): void

Defined in: src/components/ComponentBase.ts:249

before release this component, object refrences are not be set null now.

Parameters

force?

boolean

Returns

void

Inherited from

ComponentBase.beforeDestroy


start()

start(): void

Defined in: src/components/MirrorComponent.ts:136

Returns

void

Overrides

ComponentBase.start


onEnable()

onEnable(_view?): void

Defined in: src/components/MirrorComponent.ts:153

Parameters

_view?

View3D

Returns

void

Overrides

ComponentBase.onEnable


onDisable()

onDisable(_view?): void

Defined in: src/components/MirrorComponent.ts:160

Parameters

_view?

View3D

Returns

void

Overrides

ComponentBase.onDisable


onUpdate()

onUpdate(_view?): void

Defined in: src/components/MirrorComponent.ts:169

Parameters

_view?

View3D

Returns

void

Overrides

ComponentBase.onUpdate


destroy()

destroy(force?): void

Defined in: src/components/MirrorComponent.ts:292

release this component

Parameters

force?

boolean

Returns

void

Overrides

ComponentBase.destroy