Skip to content

NgtsMeshPortalMaterial

NgtsMeshPortalMaterial is a port of Drei’s MeshPortalMaterial that creates a portal effect, rendering a separate scene inside a mesh. It supports smooth blending between the portal scene and the world scene, edge blur, and automatic visibility culling.

Usage

import { NgtsMeshPortalMaterial } from 'angular-three-soba/materials';
<ngt-mesh>
<ngt-plane-geometry />
<ngts-mesh-portal-material [options]="{ blend: 1, blur: 0.5 }">
<ng-template>
<!-- Portal scene content -->
<ngt-mesh>
<ngt-box-geometry />
<ngt-mesh-basic-material color="red" />
</ngt-mesh>
</ng-template>
</ngts-mesh-portal-material>
</ngt-mesh>

Example with Animated Blend

@Component({
template: `
<ngt-mesh (pointerenter)="hovered.set(true)" (pointerleave)="hovered.set(false)">
<ngt-plane-geometry *args="[2, 3]" />
<ngts-mesh-portal-material [options]="{ blend: hovered() ? 1 : 0, blur: 0.2 }">
<ng-template>
<ngt-ambient-light [intensity]="0.5" />
<ngt-mesh>
<ngt-sphere-geometry />
<ngt-mesh-standard-material color="orange" />
</ngt-mesh>
</ng-template>
</ngts-mesh-portal-material>
</ngt-mesh>
`
})
export class PortalScene {
hovered = signal(false);
}

The portal creates an isolated scene that can have its own lighting, objects, and environment. Use blend to smoothly transition between seeing the world and seeing the portal contents.

Options

Properties

name type description
blend number Mix the portal's own scene with the world scene. 0 = world only, 0.5 = both, 1 = portal only.
blur number Edge fade blur using signed distance field (SDF).
resolution number SDF resolution. Smaller values result in faster start-up time.
worldUnits boolean Whether portal contents use world-space coordinates.
eventPriority number Event priority for the portal's raycasting.
renderPriority number Render priority for the portal scene.
events boolean Whether to enable events inside the portal.