FERRETGame engine over Babylon.js
Ferret

@ferret/view

Presentation views of a scene: section (cutaway) planes cut meshes on the GPU, with hatched caps on the cut faces.

6 exports · source in packages/view/src

Classes

SectionView class

class SectionView

A section (cutaway) view: meshes are cut by up to six planes in the material, on the GPU, and the cut faces are filled with a flat, hatched colour (the inside faces of a closed solid show through the cut, and they are drawn as the cap). Works with standard and PBR materials, instances and skinned meshes. The cut materials are copies, so a material shared with meshes that are not cut stays as it was; dispose() gives every mesh its own material back. Shadows and picking still see the whole mesh.

mode: 'any' | 'all'
capColor: [number, number, number] | null
hatch: number
worldPlanes: [number, number, number, number][]the current plane equations in world space (refreshed every frame when the planes follow a frame)
constructor(readonly scene: BABYLON.Scene, private readonly o: SectionOptions)
get active()
set active(on: boolean)
get meshes(): BABYLON.AbstractMesh[]The meshes now cut.
setPlanes(planes: SectionPlane[], mode?: 'any' | 'all')
isCut(p: V3): booleanWhether a world point is cut away now (for picking, labels, or placing things in the open part).
add(targets: (BABYLON.AbstractMesh | BABYLON.TransformNode)[])Cut more meshes (or every mesh under a node).
remove(meshes: BABYLON.AbstractMesh[])Stop cutting these meshes: they get their own material back.
dispose()

packages/view/src/section.ts:113

Functions

isCut function

function isCut(planes: [number, number, number, number][], mode: 'any' | 'all', p: V3): boolean

Whether a world point is cut away by these plane equations in this mode (the same test as the shader).

packages/view/src/section.ts:44

planeEquation function

function planeEquation(p: SectionPlane, frame?: BABYLON.Matrix): [number, number, number, number]

The plane equation (a, b, c, d) with a x + b y + c z + d > 0 on the side that is cut away.

packages/view/src/section.ts:34

Interfaces

SectionOptions interface

interface SectionOptions
targets: (BABYLON.AbstractMesh | BABYLON.TransformNode)[]what is cut: these meshes, or every mesh under these nodes (a model's root)
exclude?: (mesh: BABYLON.AbstractMesh) => booleanmeshes under the targets that stay whole (a part shown in full inside a cut housing)
planes: SectionPlane[]1 to 6 planes
mode?: 'any' | 'all'any: cut away what is beyond any plane (a slice, a box); all: cut away only what is beyond every plane (one plane is a half cut; two planes take out a quarter, the classic cutaway). Default all.
frame?: BABYLON.TransformNodethe planes are in this node's frame and move with it (default: world space)
capColor?: [number, number, number] | nullcolour of the cut faces, linear RGB 0..1 (default a light grey); null leaves the inside faces as they are
hatch?: numberhatch of the cut faces: line spacing in pixels, 0 for none (default 8)
active?: booleanstart cutting at once (default true)

packages/view/src/section.ts:9

SectionPlane interface

interface SectionPlane

A cutting plane: through point, normal pointing to the side that is cut away.

point: V3
normal: V3

packages/view/src/section.ts:4

Types

V3 type

type V3 = [number, number, number] | BABYLON.Vector3

packages/view/src/section.ts:1