fast-mesh-wasm
    Preparing search index...

    Class WorkerScene

    A scene whose engine runs in a Worker, from createWorkerScene. It mirrors Scene (always "eager") with these differences:

    • Handles are returned synchronously; the Worker catches up in order.
    • State changes return void and are tracked by key through WorkerScene.status; calls that return data return promises.
    • Requests are sent once per frame by WorkerScene.commitFrame, in call order, and "last wins" changes (colouring, section plane/meshes/fill, drag moves) superseded within the batch are dropped. Calls returning a promise wait for the next commitFrame() too, or are sent on their own after 100 ms when no frame comes; before the first commitFrame() (no frame loop) they are sent on the next microtask.
    • views, placement, matrix4, section and sectionPlane read main-thread mirrors, updated as results arrive and reported by the next commitFrame(). Views follow the same fresh-view rule as Scene: get them right before use. A mesh has 0 slots until its add is processed.
    • Drags are optimistic: move shows the pose at once, end and cancel are synchronous here, and the pose is held until the Worker has the drag.
    • WorkerScene.restart replaces the Worker and replays the scene into it (the way back from INSTANCE_POISONED); handles keep working. Unlike other promise calls, its replay is sent at once, not with the next commitFrame().

    Implements

    Index
    • Adds a mesh from world positions and returns its handle at once. The origin defaults to the bounding-box centre, computed here. The mesh has no slots until the Worker has added it; a failed add shows as an error on status("mesh:<id>"), and later calls on it fail with UNKNOWN_MESH.

      A mesh of WorkerSceneOptions.backgroundAddTriangles triangles or more (65,536 by default) is added in the background: requests sent after it that do not need it run meanwhile, so a reply to one of them can arrive before the mesh. Until it lands, status("mesh:<id>") reads "computing" and its views are empty; its buffers arrive with that status turning "ready".

      Parameters

      Returns MeshHandle

    • The rule the mirrored colours and values are made by (a frozen copy of the one given to setColoring, the same object until another rule is applied), or null without colouring. It follows the results: a new rule shows with the batch that applies it, a rejected one never, and a removed field's colouring goes when the removal is applied.

      Parameters

      Returns ColorRule | null

    • Call once per animation frame. Sends this frame's requests to the Worker as one batch, then delivers to every listener, and returns, the change records of the results received since the last call (already applied to the mirrors) plus the drags' pose changes made here. Every listener runs even if one throws; the first error is rethrown afterwards.

      Returns MeshChange[]

    • The field's nearest-target indices as of its last update (the index in its to, 0xffffffff for none); see Scene.fieldNearest. A target removed since shifts the later indices down.

      Parameters

      Returns Promise<Uint32Array<ArrayBufferLike>>

    • What the sign data found out about each of the field's targets; see Scene.fieldTargetStatus.

      Parameters

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

    • Registers a listener called (on a microtask) when any status or the undo/redo state changes; returns the function that removes it.

      Parameters

      • listener: () => void

      Returns () => void

    • The nearest hit of a world ray over every mesh, or null; see Scene.raycast.

      Parameters

      • origin: readonly [number, number, number]
      • direction: readonly [number, number, number]
      • Optionaloptions: RaycastOptions

      Returns Promise<RayHit | null>

    • Stops the Worker, starts a new one and replays the scene into it; this is how a scene recovers after INSTANCE_POISONED. Resolves once the replay's results are applied (reported by the next commitFrame()).

      The replay is built here, from what the main thread has:

      • every mesh the engine had, re-added from its mirrors: live triangles only, compacted (slot ids change; handles do not), with its origin;
      • meshes whose add was never sent (still queued, or failed here after a poisoning), from their own data;
      • placements: the engine's, or, when the scene was not poisoned, the latest requested one (a setPlacement or drag not acknowledged yet);
      • fields, colourings and sections as last requested (removed ones are not re-created).

      History is cleared (canUndo/canRedo are false). The replay is sent at once, not with the next frame. Every replayed key is "computing" until the replay's results arrive, and so is the key of every pending declarative request (placement, drag, colouring, field, section), also one that failed after a poisoning (its call was rejected then): it settles with the replay ("ready", or "error" when the replay failed for it), which applies the newest value; after a poisoning, placements replay the engine's pose. A colouring whose field cannot be replayed (its mesh was lost) is dropped, with UNKNOWN_FIELD on its display key. Removals count as done: field and section removal keys read "idle" at once (their state is forgotten), mesh removal keys after the next commitFrame() delivers the removal. When the replay fails as a whole (no Worker, it could not be posted, a trap), the scene is poisoned and the next restart() replays the same intent and settles those keys.

      What cannot be replayed surfaces as errors (INSTANCE_POISONED): edits, repairs, compaction, undo/redo and queries sent and not answered, or not sent yet (their promises reject), and meshes whose add was sent but never acknowledged (their buffers went to the old Worker: they stay failed, and calls on them give UNKNOWN_MESH). An active drag ends. Mirrors, section results included, stay readable throughout. Calling it again before it settles returns the same promise. When no Worker can be created, the promise rejects and the scene stays poisoned (a later restart() tries again).

      Returns Promise<void>

    • The state of a request key: mesh:<id>, placement:<id>, edit:<id>, display:<id>, field:<id>, section:<id> (add and remove), section:<id>:plane / :meshes / :fill, history. A result sets "ready" or "error" only when no newer request for the key is pending. A status covers only requests made under its key: a drag or edit does not mark the display: or section: keys of the colours and sections that catch up after it. Returns a copy.

      Parameters

      • key: string

      Returns KeyStatus