@lovelace_lol/embody 0.0.13 → 0.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/README.md +94 -23
  2. package/dist/index.js +1617 -5898
  3. package/dist/index.js.map +1 -1
  4. package/dist/three/annotations/DOMControls.d.ts +5 -1
  5. package/dist/three/annotations/HtmlAnnotationMarkers.d.ts +5 -0
  6. package/dist/three/annotations/OverlayAnnotationMarkers.d.ts +1 -0
  7. package/dist/three/annotations/ThreeAnnotationController.d.ts +145 -0
  8. package/dist/three/annotations/ThreeAnnotationControls.d.ts +42 -0
  9. package/dist/three/annotations/ThreeAnnotationMarkers.d.ts +42 -0
  10. package/dist/three/annotations/ThreeAnnotationRenderer.d.ts +35 -0
  11. package/dist/three/annotations/{DPthree.d.ts → ThreeAnnotations.d.ts} +18 -27
  12. package/dist/three/annotations/adapter.d.ts +2 -8
  13. package/dist/three/annotations/annotationAnchorModel.d.ts +0 -4
  14. package/dist/three/annotations/index.d.ts +9 -8
  15. package/dist/three/annotations/lifecycleBridge.d.ts +26 -0
  16. package/dist/three/annotations/markerVisibilityLifecycle.d.ts +8 -7
  17. package/dist/three/annotations/modelObservation.d.ts +44 -0
  18. package/dist/three/annotations/runtime.d.ts +46 -0
  19. package/dist/three/annotations/runtimeAnnotationPreview.d.ts +2 -2
  20. package/dist/three/annotations/runtimeAnnotationPreviewSide.d.ts +0 -4
  21. package/dist/three/annotations/runtimeAnnotationSidePreview.d.ts +2 -1
  22. package/dist/three/annotations/types.d.ts +7 -8
  23. package/dist/three/characterHost.d.ts +5 -5
  24. package/dist/three.js +1617 -5898
  25. package/dist/three.js.map +1 -1
  26. package/dist/wasm/README.md +94 -23
  27. package/dist/wasm/embody_wasm.d.ts +191 -85
  28. package/dist/wasm/embody_wasm.js +455 -2
  29. package/dist/wasm/embody_wasm_bg.wasm +0 -0
  30. package/dist/wasm/embody_wasm_bg.wasm.d.ts +116 -83
  31. package/dist/wasm/index.d.ts +1 -1
  32. package/dist/wasm.js.map +1 -1
  33. package/package.json +2 -2
  34. package/dist/three/annotations/DPthree3DMarkers.d.ts +0 -320
  35. package/dist/three/annotations/DPthreeCameraController.d.ts +0 -415
  36. package/dist/three/annotations/DPthreeHTMLMarkers.d.ts +0 -131
  37. package/dist/three/annotations/DPthreeMarkers.d.ts +0 -52
  38. package/dist/three/annotations/animationFrameTaskScheduler.d.ts +0 -18
package/README.md CHANGED
@@ -33,7 +33,8 @@ The Rust core owns:
33
33
  (`morphTarget` / `boneTransform` tracks) for the host mixer to schedule
34
34
  - mesh-category routing and material profile data
35
35
  - hair curves, hair physics, and appearance normalization
36
- - annotation camera/marker math and humanoid template fitting
36
+ - annotation regions, camera gestures/flights/orbits, marker placement and visibility,
37
+ preview/reveal lifecycles, and humanoid template fitting
37
38
  - profile-aware screen-space gaze geometry for eye/head AU trajectories
38
39
  - renderer-neutral model analysis and packed live frame generation
39
40
 
@@ -53,9 +54,9 @@ disable the AU's mapped morphs or the viseme shapes.
53
54
  The TypeScript adapter is intentionally limited to operations that require
54
55
  Three.js objects: scene traversal, ClipIR ↔ `AnimationClip` conversion, frame
55
56
  application, material writes, model loading/disposal, and default scene
56
- construction. The annotation adapter also owns camera controls, marker scene
57
- objects, labels, selection, and their browser lifecycle; applications provide
58
- the scene/camera/DOM inputs and render controls through the public API.
57
+ construction. Annotation adapters capture DOM input, observe native geometry,
58
+ apply Rust camera/marker frames, render labels and release native resources.
59
+ Camera integration, region selection and marker state belong to Rust.
59
60
 
60
61
  `ThreeFrameApplier.applyMeshMaterialConfigs(model, profile.meshes)` replays named
61
62
  mesh visibility and material overrides when a host binds or replaces a profile.
@@ -67,31 +68,95 @@ do not need a separate mesh-visibility replay loop.
67
68
 
68
69
  ### Annotation runtime
69
70
 
70
- `DPthreeCameraController` and the `DPthree` convenience facade from
71
- `@lovelace_lol/embody/three` own the complete camera and annotation runtime.
72
- `DPthree3DMarkers`, `DPthreeHTMLMarkers`, and the legacy `DPthreeMarkers` adapter
73
- are available for hosts that need a marker-only layer. Rust owns camera
74
- framing/flights/orbits, viewport clipping, curves, visibility factors and
75
- endpoint separation. The Three adapter owns native model inspection,
76
- raycasting, labels, DOM controls, marker expansion/solo/style state and disposal.
71
+ `AnnotationRuntime` in `src/annotation_runtime/` owns the annotation behavior
72
+ and mutable state in Rust/Wasm: camera input and damping, framing and intro
73
+ transitions, authored/runtime regions, AU/bone target selection, laterality,
74
+ anchors, surface-query planning, expansion, solo, styles, visibility and layout.
75
+ `AnnotationLifecycle` owns preview/reveal deadlines and the effects they emit.
76
+ There is no TypeScript annotation state machine or OrbitControls dependency.
77
+
78
+ `ThreeAnnotationController` and the `ThreeAnnotations` convenience facade from
79
+ `@lovelace_lol/embody/three` provide native adapters. `ThreeAnnotationMarkers`,
80
+ `HtmlAnnotationMarkers`, and its `OverlayAnnotationMarkers` alias provide
81
+ marker-only views of the same Rust runtime. Their TypeScript code captures input,
82
+ serializes model observations, calls native raycasts and skinned-vertex evaluation,
83
+ applies packed Rust frames, creates labels, and owns renderer resources. Three
84
+ continues to own scene objects and GPU operations; those APIs cannot be replaced
85
+ by renderer-neutral Rust. Both marker styles share the same state and selection
86
+ rules. HTML occlusion uses Rust-planned rays evaluated by Three.
87
+
88
+ Rust fits marker endpoints before marker loading returns and on each update,
89
+ including additions, endpoint separation and reveal overshoot. Clipping uses
90
+ the displayed label dimensions and preserves the minimum leader-line length;
91
+ temporary overshoot clipping does not restart the reveal. Sphere sizing retains
92
+ the close-up scale and clamped distance scaling outside that range. Explicit
93
+ `markerAnchor.projectToSurface: false` also applies to `objects: ['*']` anchors.
94
+ HTML overlays align with the canvas rectangle inside its container, update on
95
+ resize/rebind, and restore borrowed parent positioning when the final view is
96
+ disposed. These coordinates assume axis-aligned CSS boxes without transforms.
97
+
98
+ AU morph anchors currently sample native deformed vertices during marker
99
+ preparation, then follow the selected object's transform. They do not yet
100
+ resample morph weights or skinning on subsequent frames. Animated surface
101
+ tracking requires cached vertex candidates and per-frame pose observations;
102
+ ordinary object-transform tracking does not provide that behavior.
103
+
104
+ This is a breaking replacement of the DPthree exports. Use
105
+ `ThreeAnnotationController.create(options)` or `ThreeAnnotations.create(options)`
106
+ to await Wasm initialization; synchronous constructors require an already initialized
107
+ core. Replace DPthree-prefixed types with `AnnotationCharacterConfig`,
108
+ `AnnotationRegion`, `AnnotationRegistry`, and the corresponding callback types.
109
+ The `controls` bridge retains `target`, `enabled`, damping/distance settings,
110
+ `update()`, and `change`/`start`/`end` listeners, but is not a Three `OrbitControls`
111
+ instance. Region and camera snapshots are observations; mutate through controller
112
+ methods. Explicit `undefined` fields in `updateAnnotationRegion` remove overrides.
113
+ `getCharacterConfig()` retains snapshot identity until configuration content or
114
+ the model changes; selection, visibility and camera input do not replace it.
115
+ Call `clearModel()` before releasing a removed model's native resources. The
116
+ controller retains renderer rebinding, canvas input reconnect and resource-drain
117
+ support through the scene's rendering controller.
118
+ Runtime preview region IDs retain the `runtime:annotation:` namespace.
119
+
120
+ When the annotation controller owns the renderer loop, it advances registered
121
+ native character mixers before observing annotation transforms and drawing the
122
+ scene. The first frame establishes the timer origin; skipped asynchronous draws
123
+ do not accumulate playback time. External render loops use the existing
124
+ `createScenePlaybackFrame` integration to advance character playback.
125
+
126
+ ```ts
127
+ import { ThreeAnnotations } from '@lovelace_lol/embody/three';
128
+
129
+ const annotations = await ThreeAnnotations.create({ scene, camera, domElement: canvas });
130
+ annotations.setModel(model);
131
+ await annotations.loadCharacter({ characterId: 'character', profilePresetId: 'cc4' });
132
+ // Host-owned render loop: call annotations.update() before renderer.render(...).
133
+ ```
77
134
 
78
135
  Applications pass `AnnotationCharacterConfig`; storage, agency, editor and
79
136
  character-asset metadata remain host concerns. `loadRegions` defaults to
80
137
  `resolveAnnotationCharacterConfig`, which resolves annotation and AU mapping
81
138
  fields from an Embody preset without serializing unrelated host metadata.
82
139
  An optional `resolveCharacterConfig` callback supports host profile intake.
140
+ `prepareRegionsForReveal` defers native marker construction until the first
141
+ `setMarkersVisible(true)` call. Later visibility changes reuse those resources;
142
+ Rust's loaded state resets when the model or configuration is replaced.
83
143
  `prepareRegionsAndMarkersForReveal` accepts an already-resolved profile and
84
144
  prepares native surface queries while the model pose is still stable.
85
145
  Initial queries yield to a browser paint between meshes once a 4 ms slice is
86
- spent. Each native mesh raycast is indivisible; a large mesh can still cause a
87
- frame drop, and slicing does not reduce total raycast CPU time. Interactive
88
- annotation changes retain synchronous queries so a marker samples one pose.
89
- Replacement, clearing and disposal cancel stale loads before scene commits.
90
- New 3D markers and separated endpoints invalidate the cached camera layout.
91
- Visible markers receive the current zoom sizing and Rust viewport constraints
92
- before paint; hidden markers receive that layout before reveal captures label
93
- scales. Viewport clipping also follows the animated label size during reveal
94
- overshoot. Markers added during a reveal stay hidden until its layout pass resumes.
146
+ spent. Each native mesh raycast is indivisible; slicing does not reduce total
147
+ raycast CPU time. Interactive edits retain synchronous queries so a marker samples
148
+ one pose. Rust generations reject stale profile, surface and reveal completions
149
+ after replacement, clearing, region edits or disposal. Camera requests settle when
150
+ completed or cancelled, including controller disposal.
151
+
152
+ The direct Wasm boundary uses JSON commands/snapshots for configuration and
153
+ primitive model observations with stable object IDs. Frames, vertex candidates,
154
+ transform observations and ray results use packed typed arrays; coordinates are
155
+ world-space, camera/visibility angles are degrees, durations are milliseconds,
156
+ and viewport dimensions are CSS pixels. The layouts and operations are maintained
157
+ in [the Rust runtime](src/annotation_runtime/mod.rs) and
158
+ [marker frames](src/annotation_runtime/markers.rs); generated Wasm declarations
159
+ remain the ABI type source. IDs are scoped to one model lifetime.
95
160
 
96
161
  For first reveal, call `controller.prepareModelForRender(model, { signal })`
97
162
  from the existing `beforeReveal` callback (or directly before attaching the
@@ -103,8 +168,14 @@ it settles, even after `controller.dispose()`. This prepares visible variants,
103
168
  not every future hidden material or animation state. See the
104
169
  [model readiness contract](docs/SCENE_READINESS.md#model-readiness).
105
170
 
106
- `createMarkerVisibilityLifecycle` owns automatic reveal/hide timers;
107
- `createRuntimeAnnotationPreviewLifecycle` owns temporary authoring previews.
171
+ `createMarkerVisibilityLifecycle` and `createRuntimeAnnotationPreviewLifecycle`
172
+ transport host events to `AnnotationLifecycle`; browser timers only wake Rust at
173
+ its next deadline. Factories can queue input while Wasm initializes; `ready`
174
+ reports the current initialization attempt. After an initialization failure,
175
+ the next command retries or adopts a core initialized by another scene. Failed
176
+ attempts discard their queued input. `dispose()` also discards pending input,
177
+ cancels timers and frees the runtime, so cleanup before readiness cannot replay
178
+ callbacks. Later calls create a fresh runtime, preserving host effect-replay cleanup.
108
179
  React hosts forward user events and subscribe to controller state. They do not
109
180
  need local copies of the camera, marker, placement or timer algorithms.
110
181
  The convenience facade delegates to one controller-owned marker layer.
@@ -177,7 +248,7 @@ controller immediately. `ready` reports the initial attempt; failure retains the
177
248
  controller for recovery through `setSettings`. `getSettings`, `getSnapshot` and
178
249
  `subscribe` expose the requested preference, actual backend, status and errors.
179
250
  Live changes prepare and replace only backend resources, preserving the character,
180
- scene, camera, lighting and marker state. `DPthreeCameraController({ rendering,
251
+ scene, camera, lighting and marker state. `ThreeAnnotationController({ rendering,
181
252
  scene, camera, domElement: container })` retargets its existing loop and controls;
182
253
  hosts persist settings and display status without recreating the scene.
183
254