@automovie/render 0.3.0 → 0.3.2

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 (110) hide show
  1. package/lib/AutoMovieFrameGrid.d.ts +54 -0
  2. package/lib/AutoMovieFrameGrid.js +71 -0
  3. package/lib/AutoMovieFrameGrid.js.map +1 -0
  4. package/lib/AutoMovieFrameGrid.mjs +20 -0
  5. package/lib/AutoMovieFrameGrid.mjs.map +1 -0
  6. package/lib/caption/canonicalProductionWebVtt.d.ts +5 -3
  7. package/lib/caption/canonicalProductionWebVtt.js +19 -4
  8. package/lib/caption/canonicalProductionWebVtt.js.map +1 -1
  9. package/lib/caption/canonicalProductionWebVtt.mjs +15 -4
  10. package/lib/caption/canonicalProductionWebVtt.mjs.map +1 -1
  11. package/lib/draw/bindAutoMovieDrawSceneSoftProps.d.ts +15 -0
  12. package/lib/draw/bindAutoMovieDrawSceneSoftProps.js +41 -0
  13. package/lib/draw/bindAutoMovieDrawSceneSoftProps.js.map +1 -0
  14. package/lib/draw/bindAutoMovieDrawSceneSoftProps.mjs +36 -0
  15. package/lib/draw/bindAutoMovieDrawSceneSoftProps.mjs.map +1 -0
  16. package/lib/draw/index.d.ts +1 -0
  17. package/lib/draw/index.js +1 -0
  18. package/lib/draw/index.js.map +1 -1
  19. package/lib/draw/index.mjs +2 -1
  20. package/lib/index.d.ts +1 -0
  21. package/lib/index.js +1 -0
  22. package/lib/index.js.map +1 -1
  23. package/lib/index.mjs +12 -7
  24. package/lib/planSequenceRender.d.ts +5 -5
  25. package/lib/planSequenceRender.js +12 -6
  26. package/lib/planSequenceRender.js.map +1 -1
  27. package/lib/planSequenceRender.mjs +12 -8
  28. package/lib/planSequenceRender.mjs.map +1 -1
  29. package/lib/scene/IAutoMovieSceneObject.d.ts +4 -1
  30. package/lib/scene/IAutoMovieSceneSoftProps.d.ts +36 -0
  31. package/lib/scene/IAutoMovieSceneSoftProps.js +3 -0
  32. package/lib/scene/IAutoMovieSceneSoftProps.js.map +1 -0
  33. package/lib/scene/IAutoMovieSceneSoftProps.mjs +0 -0
  34. package/lib/scene/IChunkObject.d.ts +7 -3
  35. package/lib/scene/applyPracticalSurfaceMaterials.d.ts +31 -0
  36. package/lib/scene/applyPracticalSurfaceMaterials.js +87 -0
  37. package/lib/scene/applyPracticalSurfaceMaterials.js.map +1 -0
  38. package/lib/scene/applyPracticalSurfaceMaterials.mjs +47 -0
  39. package/lib/scene/applyPracticalSurfaceMaterials.mjs.map +1 -0
  40. package/lib/scene/buildInstancedFormation.d.ts +1 -1
  41. package/lib/scene/buildInstancedFormation.js +44 -19
  42. package/lib/scene/buildInstancedFormation.js.map +1 -1
  43. package/lib/scene/buildInstancedFormation.mjs +30 -13
  44. package/lib/scene/buildInstancedFormation.mjs.map +1 -1
  45. package/lib/scene/buildScene.d.ts +10 -7
  46. package/lib/scene/buildScene.js +21 -7
  47. package/lib/scene/buildScene.js.map +1 -1
  48. package/lib/scene/buildScene.mjs +27 -9
  49. package/lib/scene/buildScene.mjs.map +1 -1
  50. package/lib/scene/buildSceneSoftProps.d.ts +15 -0
  51. package/lib/scene/buildSceneSoftProps.js +71 -0
  52. package/lib/scene/buildSceneSoftProps.js.map +1 -0
  53. package/lib/scene/buildSceneSoftProps.mjs +67 -0
  54. package/lib/scene/buildSceneSoftProps.mjs.map +1 -0
  55. package/lib/scene/human-polygon/AutoMovieHumanPolygon.d.ts +52 -1
  56. package/lib/scene/human-polygon/buildHumanPolygon.d.ts +3 -1
  57. package/lib/scene/human-polygon/buildHumanPolygon.js +14 -2
  58. package/lib/scene/human-polygon/buildHumanPolygon.js.map +1 -1
  59. package/lib/scene/human-polygon/buildHumanPolygon.mjs +11 -2
  60. package/lib/scene/human-polygon/buildHumanPolygon.mjs.map +1 -1
  61. package/lib/scene/human-polygon/buildPolygonShotActor.d.ts +40 -0
  62. package/lib/scene/human-polygon/buildPolygonShotActor.js +69 -0
  63. package/lib/scene/human-polygon/buildPolygonShotActor.js.map +1 -0
  64. package/lib/scene/human-polygon/buildPolygonShotActor.mjs +74 -0
  65. package/lib/scene/human-polygon/buildPolygonShotActor.mjs.map +1 -0
  66. package/lib/scene/human-polygon/index.d.ts +1 -0
  67. package/lib/scene/human-polygon/index.js +3 -1
  68. package/lib/scene/human-polygon/index.js.map +1 -1
  69. package/lib/scene/human-polygon/index.mjs +2 -1
  70. package/lib/scene/human-polygon/prepareHumanPolygonPresentation.d.ts +17 -0
  71. package/lib/scene/human-polygon/prepareHumanPolygonPresentation.js +231 -0
  72. package/lib/scene/human-polygon/prepareHumanPolygonPresentation.js.map +1 -0
  73. package/lib/scene/human-polygon/prepareHumanPolygonPresentation.mjs +189 -0
  74. package/lib/scene/human-polygon/prepareHumanPolygonPresentation.mjs.map +1 -0
  75. package/lib/scene/index.d.ts +3 -0
  76. package/lib/scene/index.js +3 -0
  77. package/lib/scene/index.js.map +1 -1
  78. package/lib/scene/index.mjs +45 -42
  79. package/lib/scene/renderAutoMovieFilmFrame.d.ts +6 -4
  80. package/lib/scene/renderAutoMovieFilmFrame.js +12 -8
  81. package/lib/scene/renderAutoMovieFilmFrame.js.map +1 -1
  82. package/lib/scene/renderAutoMovieFilmFrame.mjs +12 -8
  83. package/lib/scene/renderAutoMovieFilmFrame.mjs.map +1 -1
  84. package/lib/scene/softPropCordSurface.d.ts +14 -0
  85. package/lib/scene/softPropCordSurface.js +128 -0
  86. package/lib/scene/softPropCordSurface.js.map +1 -0
  87. package/lib/scene/softPropCordSurface.mjs +88 -0
  88. package/lib/scene/softPropCordSurface.mjs.map +1 -0
  89. package/package.json +4 -4
  90. package/src/AutoMovieFrameGrid.ts +70 -0
  91. package/src/caption/canonicalProductionWebVtt.ts +20 -4
  92. package/src/draw/bindAutoMovieDrawSceneSoftProps.ts +43 -0
  93. package/src/draw/index.ts +1 -0
  94. package/src/index.ts +1 -0
  95. package/src/planSequenceRender.ts +21 -10
  96. package/src/scene/IAutoMovieSceneObject.ts +6 -1
  97. package/src/scene/IAutoMovieSceneSoftProps.ts +38 -0
  98. package/src/scene/IChunkObject.ts +10 -3
  99. package/src/scene/applyPracticalSurfaceMaterials.ts +79 -0
  100. package/src/scene/buildInstancedFormation.ts +86 -55
  101. package/src/scene/buildScene.ts +22 -6
  102. package/src/scene/buildSceneSoftProps.ts +83 -0
  103. package/src/scene/human-polygon/AutoMovieHumanPolygon.ts +61 -1
  104. package/src/scene/human-polygon/buildHumanPolygon.ts +22 -2
  105. package/src/scene/human-polygon/buildPolygonShotActor.ts +112 -0
  106. package/src/scene/human-polygon/index.ts +1 -0
  107. package/src/scene/human-polygon/prepareHumanPolygonPresentation.ts +328 -0
  108. package/src/scene/index.ts +3 -0
  109. package/src/scene/renderAutoMovieFilmFrame.ts +14 -9
  110. package/src/scene/softPropCordSurface.ts +132 -0
@@ -1,11 +1,13 @@
1
1
  import type * as THREE from "three";
2
2
 
3
+ import type { IAutoMovieSceneSoftProps } from "./IAutoMovieSceneSoftProps.js";
4
+
3
5
  /**
4
6
  * Result of building a scene: the `three.js` scene, its cameras (first is
5
7
  * default), and its lights indexed by id.
6
8
  *
7
9
  * @evidence contracts/development/design.md#principled-representation Keeps the built scene with ordered cameras and an id-keyed light map; leading node-child order preserves mask addressing while light motion resolves semantic ids independently of child position.
8
- * @evidence contracts/development/design.md#minimal-and-owned-surface Scene mounting, default camera selection and light animation each receive the lookup form their existing consumer needs.
10
+ * @evidence contracts/development/design.md#minimal-and-owned-surface Scene mounting, default camera selection and light animation each receive their existing lookup. The optional soft-prop handle owns further updates and retirement of the opted-in layer.
9
11
  * @evidence contracts/development/design.md#prohibited-design-shortcuts Lights are never found by counting scene children, and authored camera order remains intact rather than selecting a preferred fixture camera.
10
12
  * @evidence contracts/development/common.md#meaningful-documentation Documents leading compiled node order, first-camera default and id-based light animation lookup rationale.
11
13
  */
@@ -26,4 +28,7 @@ export interface IAutoMovieSceneObject {
26
28
  * counting.
27
29
  */
28
30
  lights: Map<string, THREE.Light>;
31
+
32
+ /** Present when a caller supplies soft props to buildScene, including an empty initial frame. */
33
+ softProps?: IAutoMovieSceneSoftProps;
29
34
  }
@@ -0,0 +1,38 @@
1
+ import type { IAutoMovieRenderSoftPropFrame } from "@automovie/interface";
2
+
3
+ /**
4
+ * The soft meshes one scene projection owns for its current film instant.
5
+ *
6
+ * @evidence contracts/development/common.md#meaningful-documentation Documents full-frame replacement, subject identity and the release boundary.
7
+ * @evidence contracts/development/design.md#principled-representation One owner updates from world-metre frame data and handles geometry and material lifetimes.
8
+ * @evidence contracts/development/design.md#minimal-and-owned-surface buildScene and draw subjects call the same update and release operations.
9
+ * @evidence contracts/development/design.md#prohibited-design-shortcuts The caller supplies the whole frame and producer status. The handle neither samples time nor owns the scene's other objects.
10
+ */
11
+ export interface IAutoMovieSceneSoftProps {
12
+ /**
13
+ * Replace the projected set from the given film instant. Existing subjects
14
+ * keep their mesh identity, and omitted subjects are removed.
15
+ *
16
+ * @evidence contracts/development/common.md#meaningful-documentation States the full-frame input, retained identity and omitted-subject outcome.
17
+ * @evidenceExclude contracts/development/implementation.md#principled-implementation The signature has no algorithm; buildSceneSoftProps provides it.
18
+ * @evidenceExclude contracts/development/implementation.md#clear-and-simple-structure The signature has no body; buildSceneSoftProps supplies the decomposition.
19
+ * @evidenceExclude contracts/development/implementation.md#prohibited-implementation-shortcuts The signature defines the replacement boundary; buildSceneSoftProps owns admission and projection.
20
+ * @evidenceExclude contracts/development/implementation.md#efficient-algorithms The signature chooses no traversal or allocation strategy.
21
+ * @evidenceExclude contracts/development/implementation.md#reuse-equivalent-work The signature establishes subject identity; buildSceneSoftProps owns reuse.
22
+ * @evidenceExclude contracts/development/implementation.md#bound-retention-and-release-resources The signature acquires no resources; buildSceneSoftProps owns their lifetime.
23
+ */
24
+ update(frames: readonly IAutoMovieRenderSoftPropFrame[]): void;
25
+
26
+ /**
27
+ * Remove and release the meshes held by the projection, then close updates.
28
+ *
29
+ * @evidence contracts/development/common.md#meaningful-documentation States the resources released and the closed lifetime.
30
+ * @evidenceExclude contracts/development/implementation.md#principled-implementation The signature has no algorithm; buildSceneSoftProps provides it.
31
+ * @evidenceExclude contracts/development/implementation.md#clear-and-simple-structure The signature has no body; buildSceneSoftProps supplies the decomposition.
32
+ * @evidenceExclude contracts/development/implementation.md#prohibited-implementation-shortcuts The signature defines a lifetime boundary; buildSceneSoftProps owns independent release attempts.
33
+ * @evidenceExclude contracts/development/implementation.md#efficient-algorithms The signature chooses no traversal or allocation strategy.
34
+ * @evidenceExclude contracts/development/implementation.md#reuse-equivalent-work The signature starts no new operation after closure; buildSceneSoftProps supplies the guard.
35
+ * @evidenceExclude contracts/development/implementation.md#bound-retention-and-release-resources The signature acquires no resources; buildSceneSoftProps owns their release.
36
+ */
37
+ dispose(): void;
38
+ }
@@ -19,11 +19,18 @@ export interface IChunkObject {
19
19
  */
20
20
  runtime: IAutoMovieCompiledFormation["chunks"][number];
21
21
 
22
- /**
23
- * Stores the metre-space chunk radius used with the model projection radius in frustum admission.
24
- */
22
+ /** Group-local metre center of the current base arrangement. */
23
+ center: THREE.Vector3;
24
+
25
+ /** Conservative radius of the compiled rest placement bounds, in metres. */
26
+ restRadius: number;
27
+
28
+ /** Group-local radius of the base arrangement, before sparse offsets and model extent. */
25
29
  radius: number;
26
30
 
31
+ /** Greatest distance from center among the present sparse exceptions at the current time. */
32
+ exceptionRadius: number;
33
+
27
34
  /**
28
35
  * Retains exact compiled placements for the anonymous members represented by this chunk.
29
36
  */
@@ -0,0 +1,79 @@
1
+ import { samplePracticalSurfaceTrackMaterial } from "@automovie/engine";
2
+ import type { IAutoMovieShot } from "@automovie/interface";
3
+ import * as THREE from "three";
4
+
5
+ import type { IAutoMovieModelObject } from "./IAutoMovieModelObject.js";
6
+
7
+ /**
8
+ * Apply an admitted shot's practical surface cues to built prop instances.
9
+ *
10
+ * Before drawing a frame of the shot, call this with its shot-local seconds in
11
+ * [0, duration). Resolve scene node ids to the distinct model objects mounted
12
+ * for those placements, for example by keeping the results supplied to
13
+ * buildScene. Resolve each model-scoped material id to a prepared, geometry-
14
+ * compatible material for that node and part. The host can use buildMaterial
15
+ * with its existing texture resolver and retains ownership of those materials
16
+ * and textures. An initial key can select the part's original material by
17
+ * supplying that same reference.
18
+ *
19
+ * This updates only tracked parts. When reusing a mounted scene across shots,
20
+ * restore its staged materials or author opening tracks for parts whose prior
21
+ * shot changed their material.
22
+ *
23
+ * @throws {RangeError} The tracked shot sample is outside its local interval.
24
+ * @throws {Error} A target has no distinct single-material mesh, or its selected variant is unavailable.
25
+ *
26
+ * @evidence contracts/development/common.md#meaningful-documentation States the frame clock, caller's mounting and resolution roles, failure conditions, original material path and reused-scene reset requirement.
27
+ * @evidence contracts/development/implementation.md#principled-implementation Samples each track independently, resolves the exact built node-part mesh and material, then swaps pointers only after complete frame preflight.
28
+ * @evidence contracts/development/implementation.md#clear-and-simple-structure Engine owns the discrete key rule. Render resolves and validates target and variant references before applying the resulting assignments.
29
+ * @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts No lookup by display name, mesh traversal, material mutation, shared model rewrite or previous-frame dependency. Missing and aliased targets fail before any assignments.
30
+ * @evidence contracts/development/implementation.md#efficient-algorithms One target lookup, logarithmic key selection and one variant resolution per track, with one temporary assignment per target. Untracked shots return immediately.
31
+ * @evidence contracts/development/implementation.md#reuse-equivalent-work All frames use the caller's prepared references. Reapplying a selected material requires no conversion or copy.
32
+ * @evidence contracts/development/implementation.md#bound-retention-and-release-resources No geometry, material or texture is allocated or disposed. Assignments borrow already-owned materials for live mesh slots and no auxiliary state persists.
33
+ */
34
+ export function applyPracticalSurfaceMaterials(
35
+ shot: IAutoMovieShot,
36
+ seconds: number,
37
+ resolveNode: (node: string) => IAutoMovieModelObject | undefined,
38
+ resolveMaterial: (
39
+ node: string,
40
+ part: string,
41
+ material: string,
42
+ ) => THREE.Material | undefined,
43
+ ): void {
44
+ if (!shot.practicalSurfaces?.length) return;
45
+ if (!Number.isFinite(seconds) || seconds < 0 || seconds >= shot.duration)
46
+ throw new RangeError("Practical surface sample must be inside the shot");
47
+
48
+ const assignments: Map<THREE.Mesh, THREE.Material> = new Map();
49
+ for (const track of shot.practicalSurfaces) {
50
+ const target: THREE.Object3D | undefined = resolveNode(
51
+ track.node,
52
+ )?.parts.get(track.part);
53
+ if (
54
+ !(target instanceof THREE.Mesh) ||
55
+ Array.isArray(target.material) ||
56
+ assignments.has(target)
57
+ )
58
+ throw new Error(
59
+ `Practical surface "${track.node}" part "${track.part}" has no distinct single-material mesh`,
60
+ );
61
+
62
+ const selected: string = samplePracticalSurfaceTrackMaterial(
63
+ track,
64
+ seconds,
65
+ );
66
+ const material: THREE.Material | undefined = resolveMaterial(
67
+ track.node,
68
+ track.part,
69
+ selected,
70
+ );
71
+ if (material === undefined)
72
+ throw new Error(
73
+ `Practical surface "${track.node}" part "${track.part}" has no prepared material "${selected}"`,
74
+ );
75
+ assignments.set(target, material);
76
+ }
77
+
78
+ for (const [target, material] of assignments) target.material = material;
79
+ }
@@ -59,7 +59,7 @@ import { vector } from "./vector.js";
59
59
  *
60
60
  * @evidence contracts/development/implementation.md#principled-implementation Uses engine compact slot regeneration, cue sampling, cadence integration and hysteretic LOD, projecting metre placements into chunk InstancedMeshes and baked Float32 part tables; admitted models/anchors/tiers are premises, stride is heuristic and cadence matrix interpolation is approximate, while anonymous and caller-supplied hero ownership stay distinct.
61
61
  * @evidence contracts/development/implementation.md#clear-and-simple-structure Builds shared tier resources once and per-chunk matrix/phase buffers separately, with sparse slot exception lookup and hero rest snapshots for updates; no in-tree production shot host consumes this producer, and that unresolved wiring is not repaired by another runtime layer.
62
- * @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts Regenerates authored seeded slots and actual cues without fixture frames or per-member surrogate nodes. The 0.01 chunk-radius and 0.001 distance/depth floors are numerical conventions; culling uses original chunk bounds and supplied projection radius, without recomputing bounds for reform or sparse offsets. Containment of the current deformed arrangement is therefore a remaining premise, not an independently established visibility guarantee.
62
+ * @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts Regenerates authored seeded slots and actual cues without fixture frames or per-member surrogate nodes. Culling encloses current placements through base arrangement bounds and sparse member distances. Enclosure of displayed geometry depends on the supplied model projection radius.
63
63
  * @evidence contracts/development/common.md#meaningful-documentation States anonymous versus promoted members, metre/phase buffer roles, shared gait repertoire and cadence approximation, update work beyond uniform writes and the currently absent production consumer.
64
64
  * @evidence contracts/development/implementation.md#efficient-algorithms Construction regenerates N anonymous slots and fills each resident tier, bakes each tier once and locates E exceptions by scanning C chunks then the matching chunk's slots. Updates visit chunks/tiers and heroes, sample cue lists for each exception, and rewrite N matrices when spacing/reform changes. Cue sampling and native graph updates add their actual costs; retained buffers scale with N times resident tiers rather than one Object3D per member.
65
65
  * @evidence contracts/development/implementation.md#reuse-equivalent-work Shares tier geometry/material/cycle textures across chunk meshes, retains tier hysteresis and only rewrites arrangement when spacing/reform inputs change; absolute cue/cadence inputs drive updates, and failed/successful disposal completion is reused without physical retries.
@@ -178,25 +178,29 @@ export const buildInstancedFormation: (
178
178
  root.add(mesh);
179
179
  tiers.set(lod.tier, mesh);
180
180
  }
181
+ const restRadius: number = Math.max(
182
+ 0.01,
183
+ ...[chunk.bounds.min.x, chunk.bounds.max.x].flatMap(
184
+ (x: number): number[] =>
185
+ [chunk.bounds.min.y, chunk.bounds.max.y].flatMap(
186
+ (y: number): number[] =>
187
+ [chunk.bounds.min.z, chunk.bounds.max.z].map(
188
+ (z: number): number =>
189
+ Math.hypot(
190
+ x - chunk.centroid.x,
191
+ y - chunk.centroid.y,
192
+ z - chunk.centroid.z,
193
+ ),
194
+ ),
195
+ ),
196
+ ),
197
+ );
181
198
  return {
182
199
  runtime: chunk,
183
- radius: Math.max(
184
- 0.01,
185
- ...[chunk.bounds.min.x, chunk.bounds.max.x].flatMap(
186
- (x: number): number[] =>
187
- [chunk.bounds.min.y, chunk.bounds.max.y].flatMap(
188
- (y: number): number[] =>
189
- [chunk.bounds.min.z, chunk.bounds.max.z].map(
190
- (z: number): number =>
191
- Math.hypot(
192
- x - chunk.centroid.x,
193
- y - chunk.centroid.y,
194
- z - chunk.centroid.z,
195
- ),
196
- ),
197
- ),
198
- ),
199
- ),
200
+ center: vector(chunk.centroid).sub(root.position),
201
+ restRadius,
202
+ radius: restRadius,
203
+ exceptionRadius: 0,
200
204
  slots,
201
205
  tiers,
202
206
  selected: null,
@@ -368,36 +372,59 @@ export const buildInstancedFormation: (
368
372
  sampled.spacingScale.lateral !== spacing.lateral ||
369
373
  sampled.spacingScale.depth !== spacing.depth ||
370
374
  sampled.reform?.layout !== reform?.layout ||
375
+ sampled.reform?.fromLayout !== reform?.fromLayout ||
371
376
  sampled.reform?.progress !== reform?.progress
372
377
  ) {
373
378
  spacing = { ...sampled.spacingScale };
374
379
  reform = sampled.reform;
375
- for (const chunk of chunks)
376
- for (const mesh of chunk.tiers.values()) {
377
- chunk.slots.forEach(
378
- (slot: IAutoMovieFormationSlot, index: number): void => {
379
- mesh.setMatrixAt(
380
- index,
381
- slotMatrix(
382
- reform === null
383
- ? slot
384
- : {
385
- ...slot,
386
- position: formationSlotPosition(
387
- input.formation,
388
- slot.slot,
389
- reform,
390
- ),
391
- },
392
- input.formation.anchor,
393
- spacing,
394
- input.formation.facingDeg,
395
- ),
380
+ for (const chunk of chunks) {
381
+ const bounds: THREE.Box3 = new THREE.Box3();
382
+ const position: THREE.Vector3 = new THREE.Vector3();
383
+ chunk.slots.forEach(
384
+ (slot: IAutoMovieFormationSlot, index: number): void => {
385
+ const matrix: THREE.Matrix4 = slotMatrix(
386
+ reform === null
387
+ ? slot
388
+ : {
389
+ ...slot,
390
+ position: formationSlotPosition(
391
+ input.formation,
392
+ slot.slot,
393
+ reform,
394
+ ),
395
+ },
396
+ input.formation.anchor,
397
+ spacing,
398
+ input.formation.facingDeg,
399
+ );
400
+ if (reform !== null)
401
+ bounds.expandByPoint(
402
+ position.setFromMatrixPosition(matrix),
396
403
  );
397
- },
404
+ for (const mesh of chunk.tiers.values())
405
+ mesh.setMatrixAt(index, matrix);
406
+ },
407
+ );
408
+ if (reform === null) {
409
+ chunk.center.copy(
410
+ formationSpacingOffset(
411
+ chunk.runtime.centroid,
412
+ input.formation.anchor,
413
+ spacing,
414
+ input.formation.facingDeg,
415
+ ),
398
416
  );
417
+ chunk.radius =
418
+ chunk.restRadius *
419
+ Math.max(1, spacing.lateral, spacing.depth);
420
+ } else if (bounds.isEmpty() === false) {
421
+ bounds.getCenter(chunk.center);
422
+ chunk.radius = bounds.max.distanceTo(chunk.center);
423
+ }
424
+ for (const mesh of chunk.tiers.values()) {
399
425
  mesh.instanceMatrix.needsUpdate = true;
400
426
  }
427
+ }
401
428
  }
402
429
  // The members singled out, written after the unit-wide pass so a spacing
403
430
  // rewrite cannot undo them. Only the exceptions are touched, so this costs
@@ -408,7 +435,10 @@ export const buildInstancedFormation: (
408
435
  // carries the cue's own turn and its travel. That is the same composition
409
436
  // the engine's placement performs in one step for a gate that has no
410
437
  // scene graph to carry half of it.
411
- for (const exception of exceptions) exception.chunk.removed = 0;
438
+ for (const { chunk } of exceptions) {
439
+ chunk.removed = 0;
440
+ chunk.exceptionRadius = 0;
441
+ }
412
442
  for (const exception of exceptions) {
413
443
  const state: IAutoMovieFormationSlotState =
414
444
  sampleFormationSlotMotion(
@@ -422,7 +452,13 @@ export const buildInstancedFormation: (
422
452
  input.formation.facingDeg,
423
453
  );
424
454
  const position: THREE.Vector3 = formationSpacingOffset(
425
- exception.designed.position,
455
+ reform === null
456
+ ? exception.designed.position
457
+ : formationSlotPosition(
458
+ input.formation,
459
+ exception.slot,
460
+ reform,
461
+ ),
426
462
  input.formation.anchor,
427
463
  spacing,
428
464
  input.formation.facingDeg,
@@ -453,7 +489,11 @@ export const buildInstancedFormation: (
453
489
  if (state.present === false) {
454
490
  ++exception.chunk.removed;
455
491
  ++stats.removed;
456
- }
492
+ } else
493
+ exception.chunk.exceptionRadius = Math.max(
494
+ exception.chunk.exceptionRadius,
495
+ position.distanceTo(exception.chunk.center),
496
+ );
457
497
  }
458
498
  root.updateMatrixWorld(true);
459
499
  camera.updateMatrixWorld(true);
@@ -546,21 +586,12 @@ export const buildInstancedFormation: (
546
586
  if (object.visible) ++stats.visible.hero;
547
587
  }
548
588
  for (const chunk of chunks) {
549
- const localCenter: THREE.Vector3 = formationSpacingOffset(
550
- chunk.runtime.centroid,
551
- input.formation.anchor,
552
- spacing,
553
- input.formation.facingDeg,
589
+ const center: THREE.Vector3 = root.localToWorld(
590
+ chunk.center.clone(),
554
591
  );
555
- const center: THREE.Vector3 = root.localToWorld(localCenter);
556
592
  const sphere: THREE.Sphere = new THREE.Sphere(
557
593
  center,
558
- chunk.radius *
559
- Math.max(
560
- sampled.spacingScale.lateral,
561
- sampled.spacingScale.depth,
562
- ) +
563
- selectionRadius,
594
+ Math.max(chunk.radius, chunk.exceptionRadius) + selectionRadius,
564
595
  );
565
596
  if (frustum.intersectsSphere(sphere) === false) {
566
597
  for (const mesh of chunk.tiers.values()) mesh.visible = false;
@@ -1,6 +1,7 @@
1
1
  import { resolveAutoMovieShadowProfile } from "@automovie/engine";
2
2
  import type {
3
3
  IAutoMovieCamera,
4
+ IAutoMovieRenderSoftPropFrame,
4
5
  IAutoMovieScene,
5
6
  IAutoMovieSpace,
6
7
  } from "@automovie/interface";
@@ -8,12 +9,15 @@ import * as THREE from "three";
8
9
 
9
10
  import type { IAutoMovieModelObject } from "./IAutoMovieModelObject.js";
10
11
  import type { IAutoMovieSceneObject } from "./IAutoMovieSceneObject.js";
12
+ import type { IAutoMovieSceneSoftProps } from "./IAutoMovieSceneSoftProps.js";
11
13
  import { applyAutoMovieShadowParticipation } from "./applyAutoMovieShadowParticipation.js";
12
14
  import { applySceneEnvironment } from "./applySceneEnvironment.js";
13
15
  import { applySceneFog } from "./applySceneFog.js";
14
16
  import { applyTransform } from "./applyTransform.js";
15
17
  import { buildLight } from "./buildLight.js";
18
+ import { buildSceneSoftProps } from "./buildSceneSoftProps.js";
16
19
  import { buildSpaceObject } from "./buildSpace.js";
20
+ import { restoreAutoMovieRenderModeState } from "./restoreAutoMovieRenderModeState.js";
17
21
 
18
22
  /**
19
23
  * Build a `three.js` scene from an {@link IAutoMovieScene}.
@@ -40,28 +44,33 @@ import { buildSpaceObject } from "./buildSpace.js";
40
44
  * {@link buildSpaceObject}), so guide passes describe a world instead of actors
41
45
  * floating in a void. Their ordinary material writes no beauty colour or depth,
42
46
  * because a semantic support declaration is not evidence that physical floor
43
- * geometry exists. The group is added LAST, after the nodes and lights, for
44
- * that reason, and so the whole ground reads as one mask colour rather than one
45
- * per surface.
47
+ * geometry exists. The group follows the nodes and lights so the whole
48
+ * ground reads as one mask colour rather than one per surface.
49
+ *
50
+ * An optional frame of soft props follows the designed scene objects.
51
+ * Its returned handle updates plain surfaces at later times and releases
52
+ * the meshes. Pass an empty frame to opt in before the first prop appears.
46
53
  *
47
54
  * The cited refusal contribution covers the supplied shadow profile and unresolved node model. Complete hierarchy, material and numeric admission, lowering receipts and structured safe-retry policy remain with their corresponding owners.
48
55
  *
49
56
  * @evidence contracts/development/implementation.md#principled-implementation Preserves authored node order under placement groups, admits the shadow profile, builds native lights/cameras, optional semantic support, fog and environment; each resolver call must supply a distinct mutable model object and valid admitted TRS. Static pose/props/compiled populations are not lowered here and current production pages assemble their own graph rather than calling this producer.
50
- * @evidence contracts/development/implementation.md#clear-and-simple-structure Owns the scene graph join and camera/light lookup result while model loading/building, articulation, temporal sampling and rendering remain external; leading node-child order exposes the existing positional semantic-mask dependency.
57
+ * @evidence contracts/development/implementation.md#clear-and-simple-structure Owns the scene graph join and camera/light lookup while model loading, articulation, temporal sampling and rendering remain external. The soft layer uses its own owner and follows the designed children.
51
58
  * @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts Refuses unresolved models rather than dropping an authored child and shifting mask indices; no fixture nodes/lights are invented, but complete admission and partial-construction rollback are not supplied by this scene wrapper.
52
59
  * @evidence contracts/development/common.md#meaningful-documentation States resolver uniqueness, authored node order, placement/root composition, semantic-ground beauty exclusion, static-pose caller duty and explicit refusal/admission ownership boundary.
53
60
  * @evidence contracts/development/implementation.md#efficient-algorithms Builds N placement groups, L lights and C cameras with id maps plus support tessellation and shadow participation traversal; dominant memory follows actual model/support resources returned by producers, and no anonymous member runtime is created here.
54
61
  * @evidence contracts/development/implementation.md#reuse-equivalent-work Reuses canonical transform/light/fog/environment/space adapters and maps lights by semantic id; model object reuse across placements is invalid because native parenting is exclusive, and scene-level effectful construction is not cached.
55
- * @evidence contracts/development/implementation.md#bound-retention-and-release-resources Transfers new scene/group/light/camera/support references and adopts resolver model objects into the result; environment texture handoff has its separate exclusive owner. No universal scene disposer or late-refusal rollback is returned, so callers must own both retirement and partially assembled graph recovery rather than assuming this wrapper frees them.
62
+ * @evidence contracts/development/implementation.md#bound-retention-and-release-resources Transfers new scene, group, light, camera and support references and adopts resolver model objects. Failed soft-prop mounting retires that layer. The caller otherwise owns retirement and partial graph recovery; environment texture handoff has a separate owner.
56
63
  */
57
64
  export const buildScene: (
58
65
  scene: IAutoMovieScene,
59
66
  getModelObject: (modelId: string) => IAutoMovieModelObject | undefined,
60
67
  environmentTexture?: THREE.Texture,
68
+ softFrame?: readonly IAutoMovieRenderSoftPropFrame[],
61
69
  ) => IAutoMovieSceneObject = (
62
70
  scene: IAutoMovieScene,
63
71
  getModelObject: (modelId: string) => IAutoMovieModelObject | undefined,
64
72
  environmentTexture?: THREE.Texture,
73
+ softFrame?: readonly IAutoMovieRenderSoftPropFrame[],
65
74
  ): IAutoMovieSceneObject => {
66
75
  const shadowProfile: ReturnType<typeof resolveAutoMovieShadowProfile> =
67
76
  resolveAutoMovieShadowProfile({
@@ -119,7 +128,14 @@ export const buildScene: (
119
128
  applyAutoMovieShadowParticipation(root);
120
129
 
121
130
  const cameras: THREE.PerspectiveCamera[] = scene.cameras.map(buildCamera);
122
- return { scene: root, cameras, lights };
131
+ if (softFrame === undefined) return { scene: root, cameras, lights };
132
+ const softProps: IAutoMovieSceneSoftProps = buildSceneSoftProps(root);
133
+ try {
134
+ softProps.update(softFrame);
135
+ } catch (error) {
136
+ restoreAutoMovieRenderModeState([softProps.dispose], { error });
137
+ }
138
+ return { scene: root, cameras, lights, softProps };
123
139
  };
124
140
 
125
141
  const buildCamera: (cam: IAutoMovieCamera) => THREE.PerspectiveCamera = (
@@ -0,0 +1,83 @@
1
+ import type {
2
+ IAutoMovieRenderSoftPropFrame,
3
+ IAutoMovieSoftBodySurface,
4
+ } from "@automovie/interface";
5
+ import type * as THREE from "three";
6
+
7
+ import type { IAutoMovieSceneSoftProps } from "./IAutoMovieSceneSoftProps.js";
8
+ import type { IAutoMovieSoftBodyObject } from "./IAutoMovieSoftBodyObject.js";
9
+ import { applyAutoMovieShadowParticipation } from "./applyAutoMovieShadowParticipation.js";
10
+ import { buildSoftBodyObject } from "./buildSoftBodyObject.js";
11
+ import { restoreAutoMovieRenderModeOnce } from "./restoreAutoMovieRenderModeOnce.js";
12
+ import { restoreAutoMovieRenderModeState } from "./restoreAutoMovieRenderModeState.js";
13
+ import { softPropCordSurface } from "./softPropCordSurface.js";
14
+
15
+ /**
16
+ * Own a scene's soft props without retaining film samples. Each update supplies
17
+ * the already evaluated world-space surfaces for one instant.
18
+ *
19
+ * @evidence contracts/development/common.md#meaningful-documentation Documents the scene owner, film-time boundary, replacement and cleanup.
20
+ * @evidence contracts/development/implementation.md#principled-implementation A map by performance subject updates one mesh per supplied frame. Common cloth projection owns Float32 geometry and material; a cord first acquires a tube through its particles.
21
+ * @evidence contracts/development/implementation.md#clear-and-simple-structure Admit unique subjects and project their geometry before changing the scene, then update retained meshes and withdraw absent meshes.
22
+ * @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts Accepts producer status verbatim and adds no solve or interpolation. An effectful mesh update can fail after another mesh has already advanced.
23
+ * @evidence contracts/development/implementation.md#efficient-algorithms Map work is linear in incoming and currently mounted subjects, with additional projection work linear in their buffers.
24
+ * @evidence contracts/development/implementation.md#reuse-equivalent-work A subject present in successive frames retains its projection and uses compatible buffers through buildSoftBodyObject.
25
+ * @evidence contracts/development/implementation.md#bound-retention-and-release-resources Holds one projection per mounted subject. Dropped meshes are detached and independently retired, and explicit disposal closes updates and retires all remaining meshes.
26
+ */
27
+ export function buildSceneSoftProps(
28
+ scene: THREE.Scene,
29
+ ): IAutoMovieSceneSoftProps {
30
+ const mounted: Map<string, IAutoMovieSoftBodyObject> = new Map();
31
+ let closed: boolean = false;
32
+ return {
33
+ update: (frames: readonly IAutoMovieRenderSoftPropFrame[]): void => {
34
+ if (closed) throw new Error("The scene's soft props are closed.");
35
+ const incoming: Map<string, IAutoMovieRenderSoftPropFrame> = new Map();
36
+ for (const frame of frames) {
37
+ if (frame.subject.trim() === "" || incoming.has(frame.subject))
38
+ throw new Error(
39
+ `Invalid or repeated soft prop subject "${frame.subject}".`,
40
+ );
41
+ const surface: IAutoMovieSoftBodySurface =
42
+ frame.cordRadius === undefined
43
+ ? frame.surface
44
+ : softPropCordSurface(frame.surface, frame.cordRadius);
45
+ incoming.set(frame.subject, { ...frame, surface });
46
+ }
47
+
48
+ for (const [subject, frame] of incoming) {
49
+ const previous: IAutoMovieSoftBodyObject | undefined =
50
+ mounted.get(subject);
51
+ if (previous !== undefined) previous.update(frame);
52
+ else {
53
+ const projection: IAutoMovieSoftBodyObject =
54
+ buildSoftBodyObject(frame);
55
+ projection.object.name = `soft:${subject}`;
56
+ mounted.set(subject, projection);
57
+ applyAutoMovieShadowParticipation(projection.object);
58
+ scene.add(projection.object);
59
+ }
60
+ }
61
+
62
+ const removals: (() => void)[] = [];
63
+ for (const [subject, projection] of mounted)
64
+ if (!incoming.has(subject)) {
65
+ mounted.delete(subject);
66
+ removals.push((): void => {
67
+ scene.remove(projection.object);
68
+ }, projection.dispose);
69
+ }
70
+ restoreAutoMovieRenderModeState(removals);
71
+ },
72
+ dispose: restoreAutoMovieRenderModeOnce((): void => {
73
+ closed = true;
74
+ const removals: (() => void)[] = [];
75
+ for (const projection of mounted.values())
76
+ removals.push((): void => {
77
+ scene.remove(projection.object);
78
+ }, projection.dispose);
79
+ mounted.clear();
80
+ restoreAutoMovieRenderModeState(removals);
81
+ }),
82
+ };
83
+ }
@@ -1,4 +1,8 @@
1
- import type { IAutoMovieHumanSkeleton } from "@automovie/interface";
1
+ import type {
2
+ IAutoMovieHumanSkeleton,
3
+ IAutoMoviePolygonBodyCue,
4
+ IAutoMovieRigidTransform,
5
+ } from "@automovie/interface";
2
6
  import type * as THREE from "three";
3
7
 
4
8
  /**
@@ -16,6 +20,48 @@ import type * as THREE from "three";
16
20
  * @evidence contracts/development/design.md#prohibited-design-shortcuts Scanning the declaration finds no `any`, no `unknown`, no index signature and no cast; the native drawing handle borrows canonical Human placements rather than restating their shape.
17
21
  */
18
22
  export namespace AutoMovieHumanPolygon {
23
+ /**
24
+ * Source-clock readers and authored cues for one actor's visible drawing.
25
+ *
26
+ * @evidence contracts/development/common.md#meaningful-documentation Names the subject filter, source clock and body-to-world frame convention.
27
+ * @evidence contracts/development/design.md#principled-representation Shares canonical authored cues, placements and rigid transforms at the drawing boundary.
28
+ * @evidence contracts/development/design.md#minimal-and-owned-surface Render receives the existing source pose and optional staging reader without owning either timeline.
29
+ * @evidence contracts/development/design.md#prohibited-design-shortcuts Actor staging remains caller-owned and the pose contains the original evaluated bones.
30
+ */
31
+ export interface IPresentation {
32
+ /** Exact staged actor identity. Only matching cues apply to this drawing. */
33
+ subject: string;
34
+
35
+ /** Cues in shot-local source seconds. Selected bone subtrees must be disjoint. */
36
+ cues: readonly IAutoMoviePolygonBodyCue[];
37
+
38
+ /**
39
+ * Read the complete deterministic pose in Human body coordinates at shot-local source seconds.
40
+ *
41
+ * @evidence contracts/development/common.md#meaningful-documentation Reads evaluated bone placements for an arbitrary source second. Source errors propagate to the builder or drawing.
42
+ * @evidence contracts/development/implementation.md#principled-implementation Preparation samples detach boundaries once and the prepared sampler reads the requested pose per seek. The drawing admits resulting placements before writing groups.
43
+ * @evidence contracts/development/implementation.md#clear-and-simple-structure The callback owns source pose evaluation and the presentation adapter owns cue deltas.
44
+ * @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts Reads the complete source pose even when a cue replaces some of it. A release admits replaced live placements before writing its own values.
45
+ * @evidence contracts/development/implementation.md#efficient-algorithms One source pose read per seek plus one per detach cue at preparation. The host determines the cost of each read.
46
+ * @evidence contracts/development/implementation.md#reuse-equivalent-work Captured release placements serve later seeks. Arbitrary live poses are read at the requested time.
47
+ * @evidence contracts/development/implementation.md#bound-retention-and-release-resources The sampler borrows the reader for the drawing lifetime and keeps only selected release frames. Disposal drops its sampler reference.
48
+ */
49
+ poseAt: (seconds: number) => Pick<IAutoMovieHumanSkeleton.IOutput, "posed">;
50
+
51
+ /**
52
+ * Read the actor-local to shot-world rigid frame at shot-local source seconds. Omission means identity. The host applies this frame through the drawing's parent.
53
+ *
54
+ * @evidence contracts/development/common.md#meaningful-documentation Returns metre translation and an x-y-z-w unit rotation synchronously. Invalid frames and reader errors propagate.
55
+ * @evidence contracts/development/implementation.md#principled-implementation Preparation moves detached source joints into the release world frame. Active samples cancel the current actor frame so the parent transform applies once.
56
+ * @evidence contracts/development/implementation.md#clear-and-simple-structure The host owns the source and parent placement. The presentation adapter admits and converts the returned rigid transform.
57
+ * @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts Finite translation and squared quaternion norm within 1e-6 are checked before use. Identity is the specified behavior for an omitted reader.
58
+ * @evidence contracts/development/implementation.md#efficient-algorithms Calls once per detach cue at preparation and at most once per seek. The host determines the cost of each read.
59
+ * @evidence contracts/development/implementation.md#reuse-equivalent-work The first active detach cue per seek reads the live frame and its inverse for reuse by all active detach cues.
60
+ * @evidence contracts/development/implementation.md#bound-retention-and-release-resources The drawing drops its borrowed reader with the sampler at disposal. Converted live frames are local to each seek.
61
+ */
62
+ actorFrameAt?: (seconds: number) => IAutoMovieRigidTransform;
63
+ }
64
+
19
65
  /**
20
66
  * Actual rigid polygon drawing and its owned resource lifetime.
21
67
  *
@@ -71,6 +117,20 @@ export namespace AutoMovieHumanPolygon {
71
117
  */
72
118
  setPose: (output: Pick<IAutoMovieHumanSkeleton.IOutput, "posed">) => void;
73
119
 
120
+ /**
121
+ * Draw the source pose with authored polygon cues at the given shot-local seconds.
122
+ * Present when the drawing was built with a presentation.
123
+ *
124
+ * @evidence contracts/development/common.md#meaningful-documentation Specifies availability, units and source clock.
125
+ * @evidence contracts/development/implementation.md#principled-implementation Samples visual poses from the requested time and applies them through setPose.
126
+ * @evidence contracts/development/implementation.md#clear-and-simple-structure The prepared sampler owns cue arithmetic and setPose owns graphics updates.
127
+ * @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts The source pose and graphics inventory are reused for each seek.
128
+ * @evidence contracts/development/implementation.md#efficient-algorithms Sampling and applying a complete pose are both linear in the skeletal drawing size.
129
+ * @evidence contracts/development/implementation.md#reuse-equivalent-work Release frames are captured once and reused by any ordering of seeks.
130
+ * @evidence contracts/development/implementation.md#bound-retention-and-release-resources The drawing releases its sampler at disposal and refuses drawing after retirement.
131
+ */
132
+ drawAt?: (seconds: number) => void;
133
+
74
134
  /**
75
135
  * Replace emitted-part RGB overrides; undefined restores the borrowed clay material.
76
136
  *