fast-mesh-wasm
    Preparing search index...

    Class Scene

    A scene of editable meshes. Create it after await init(); release it with Scene.free or a using declaration (otherwise it is freed when garbage collected).

    Render views (Scene.views) point into WebAssembly memory and are only valid until the next scene call that may allocate or move buffers: a kept view may read other data or be empty. Re-acquire them after every scene call; see MeshViews.

    Implements

    Index
    • Adds a signed distance field: one value per vertex slot of on, the distance to to as placed (negative inside), Infinity beyond maxDistance, NaN for dead or unused vertices. With several meshes in to, the smallest over them, ties going to the earliest. It follows edits and placements by the mesh modes, like normals. Removing a mesh of to removes it from the field, or the field with its last target.

      Parameters

      Returns FieldHandle

      INVALID_ARGUMENT when to is empty, holds on or a mesh twice, maxDistance is negative or NaN, or the name is taken.

    • Adds a per-vertex wall-thickness field: one value per vertex slot of on, the distance to the opposite surface along the vertex's smooth normal, in world units. Open sheets and rims read NaN, hits beyond maxDistance read Infinity. It follows edits and placements by the mesh modes, like normals, and colours like any field.

      Parameters

      Returns FieldHandle

      INVALID_ARGUMENT when maxDistance is negative or NaN, or the name is taken.

    • Combines source into target in the world: the union, subtraction (target minus source) or intersection. Returns target, now holding the result with its placement; source is unchanged.

      Both meshes must be closed and manifold. The boolean undoes in one step. Combining a mesh with itself is a no-op for "union" and "intersect", and clears it for "subtract".

      Parameters

      Returns MeshHandle

      UNKNOWN_MESH for a removed handle; INVALID_ARGUMENT for an input that is not closed, manifold and consistently wound. A failed boolean changes nothing.

    • Removes the mesh's dead slots and renumbers the rest. Its next change record has every buffer "all" and capacityChanged when the slot counts shrank. The mesh's earlier edits leave the history (its placement changes stay undoable).

      Parameters

      Returns void

    • Cuts mesh with a world plane: the + side (signedDistance >= 0) stays on the mesh and the - side is added as a new mesh with the same placement, so the world shape is kept. Cutting a closed mesh with cap (the default) yields two closed meshes, capped with flat, unfaired patches.

      The cut undoes in one step; the added mesh stays, like the removed source of Scene.join.

      Parameters

      Returns CutReport

      UNKNOWN_MESH for a removed handle; INVALID_ARGUMENT when the plane does not cut the mesh or a rim cannot be capped. A failed cut changes nothing.

    • Edits a mesh's geometry with a list of ops, run in Rust as one transaction: one undo step (or part of the open step), and when any op fails nothing changes and nothing is recorded. Positions are world coordinates, mapped to local with the mesh's placement and origin. Ids may be EditRefs to ids added by earlier ops of the list; every ref is checked before anything is written. Normals, colours, fields, sections and the BVH follow by the mesh's mode.

      Parameters

      Returns EditResult

      INVALID_INDEX for a bad ref or an id that is not alive; INVALID_ARGUMENT for a malformed op, positions not 3 per vertex or not finite in local f32, or removing a vertex still in use.

    • What the sign data found out about each of the field's targets, in the order of Scene.fieldTargets.

      Parameters

      Returns {
          closed: boolean;
          consistentOrientation: boolean;
          degenerateTriangles: number;
          mode: "pseudonormal" | "winding";
          nonManifoldVertices: number;
      }[]

      • closed: boolean

        No boundary or non-manifold edge.

      • consistentOrientation: boolean
      • degenerateTriangles: number
      • mode: "pseudonormal" | "winding"

        The mode in use (never "auto").

      • nonManifoldVertices: number
    • A zero-copy view of the field's values as of its last update, one per vertex slot. Like render views, it is only valid until the next call that may allocate (a kept one may read other data or be empty): get it right before use.

      Parameters

      Returns Float32Array

    • Joins source into target: copies the source's geometry into the target (keeping its world shape), bridges options.loopA to the copied options.loopB, and removes the source. The copy and the bridge undo as one step; the removal is permanent. A drag of the source ends first, recording its moves as one step, so they survive a failed join.

      Parameters

      Returns JoinReport

      UNKNOWN_MESH for a removed handle; INVALID_ARGUMENT for one mesh twice or loops that cannot bridge; STALE_LOOPS for a loop that is not there. A failed join changes nothing.

    • The column-major world matrix of the local render coordinates, placement · translate(origin), ready for renderers (convert to f32 yourself). The rotation columns carry the scale; normals need the inverse-transpose (three.js' normal matrix does this from the matrix).

      Parameters

      Returns Float64Array

    • The nearest hit of a world ray over every mesh, or null. direction need not be unit length; distance is in world units. Lazy meshes are brought up to date first.

      Parameters

      • origin: readonly [number, number, number]
      • direction: readonly [number, number, number]
      • options: RaycastOptions = {}

      Returns RayHit | null

      INVALID_ARGUMENT for a non-finite origin or a zero direction; STALE_BVH for a stale "manual" mesh.

    • Rigidly aligns the mesh moving to the mesh fixed by point-to-plane ICP, with the closest points found through fixed's BVH and trimmed by options.overlap. A drag of either mesh ends first, recording its moves as one step, once the arguments have been checked.

      The initial guess is the current placements. ICP finds the nearest fit, so put the meshes roughly in place first with setPlacement.

      Applying. By default a good result becomes moving's placement as one undo step (applied in the result): converged, with rmse within maxRmse and enough points in range. Otherwise nothing moves, and notApplied says why; placement still holds the estimate, for setPlacement if it will do. apply: false only returns it.

      Undetermined poses. A plane's slide and a sphere's or a cylinder's spin are not fixed by the data, though facets or noise can let the iteration settle with a tiny rmse. These report "underconstrained" and list the motions in undetermined. So do coarse regular meshes with exact fits close by: a 16-sided sphere fits every 22.5 degrees. The check is local, so a cube's 90-degree symmetry does not count. It adds a bounded cost: up to 12 restarts of up to 12 steps on at most 10,000 points.

      Scales. Only rotation and translation are solved. moving's scale is applied to its points and kept. fixed's scale, uniform or not, is followed exactly on a copy baked through it, so each such call costs a BVH build. All distances are in world units.

      Parameters

      Returns RegisterResult

      UNKNOWN_MESH for a removed handle; INVALID_ARGUMENT for one mesh twice, a mesh without triangles or an invalid option; STALE_BVH for a stale Manual fixed. Bad options and one mesh twice change nothing, and a drag keeps running. The other errors come after a drag has ended, and change nothing else.

    • Removes a mesh. Its handle then gives UNKNOWN_MESH. An active drag of the mesh is ended first, closing its step; the mesh's history entries (the drag's included) are then dropped with it.

      Parameters

      Returns void

    • Runs one repair operation and returns its report, or a list of them in order and returns their reports. A list is one transaction: one undo step, and when any operation fails nothing changes and nothing is recorded. { kind: "auto" } runs the standard cleanup pipeline the same way and returns a report per stage; see AutoRepairRequest.

      Parameters

      Returns AutoRepairReport

      INVALID_ARGUMENT for invalid options (fillHoles needs a bound or loops); STALE_LOOPS when a loop id of fillHoles no longer matches a loop of the mesh.

    • Runs one repair operation and returns its report, or a list of them in order and returns their reports. A list is one transaction: one undo step, and when any operation fails nothing changes and nothing is recorded. { kind: "auto" } runs the standard cleanup pipeline the same way and returns a report per stage; see AutoRepairRequest.

      Type Parameters

      Parameters

      Returns RepairReportOf<O>

      INVALID_ARGUMENT for invalid options (fillHoles needs a bound or loops); STALE_LOOPS when a loop id of fillHoles no longer matches a loop of the mesh.

    • Runs one repair operation and returns its report, or a list of them in order and returns their reports. A list is one transaction: one undo step, and when any operation fails nothing changes and nothing is recorded. { kind: "auto" } runs the standard cleanup pipeline the same way and returns a report per stage; see AutoRepairRequest.

      Type Parameters

      Parameters

      Returns { -readonly [K in string | number | symbol]: RepairReportOf<O[K]> }

      INVALID_ARGUMENT for invalid options (fillHoles needs a bound or loops); STALE_LOOPS when a loop id of fillHoles no longer matches a loop of the mesh.

    • Selects vertices of a mesh: a sphere brush, a lasso polygon, or the connected component holding a seed vertex. The result is a snapshot (ascending ids plus the mesh's content stamp); any edit, repair, compact, undo or redo of the mesh invalidates it, and the selection methods then throw STALE_SELECTION instead of silently remapping ids. Placement changes keep selections valid. Only vertices a live triangle uses can be selected (dead or never-used slots never are).

      Parameters

      Returns VertexSelection

      UNKNOWN_MESH for a removed mesh; INVALID_ARGUMENT for a bad spec; INVALID_INDEX for an out-of-range component seed.

    • Shrinks a selection by steps rings, dropping the members with a live neighbour outside the set. Interior selections (no boundary) survive unchanged; shrinking past the core gives an empty (still valid) selection.

      Parameters

      Returns VertexSelection

      STALE_SELECTION when the mesh changed since the selection; UNKNOWN_MESH for a removed mesh.

    • Colours a mesh from one of its fields (views(mesh).colors()), or turns colouring off with null, after which colors() returns null. Every vertex is recoloured and reported as "all"; later field updates (edits, drags) report only the vertices whose colour may change. A display setting: never recorded in history.

      Parameters

      Returns void

      INVALID_ARGUMENT when the field is not on mesh or the rule is invalid; UNKNOWN_FIELD.

    • Sets a mesh's placement: world = rotation · (scale · local) + translation, where local is relative to the mesh origin. A quaternion is normalised and converted in double precision. The scale defaults to [1, 1, 1] (rigid) and must be 3 finite positive numbers.

      Parameters

      Returns void

      INVALID_ARGUMENT when the rotation is not a proper rotation, the scale is not 3 finite positive numbers, or a quaternion is zero.

    • Undoes the latest step; an active drag is ended first. Without an open step around the drag, the drag is what gets undone; inside a caller's open step, that whole step (drag included) is closed and undone. Returns false when there is nothing to undo.

      Returns boolean