@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.
- package/lib/AutoMovieFrameGrid.d.ts +54 -0
- package/lib/AutoMovieFrameGrid.js +71 -0
- package/lib/AutoMovieFrameGrid.js.map +1 -0
- package/lib/AutoMovieFrameGrid.mjs +20 -0
- package/lib/AutoMovieFrameGrid.mjs.map +1 -0
- package/lib/caption/canonicalProductionWebVtt.d.ts +5 -3
- package/lib/caption/canonicalProductionWebVtt.js +19 -4
- package/lib/caption/canonicalProductionWebVtt.js.map +1 -1
- package/lib/caption/canonicalProductionWebVtt.mjs +15 -4
- package/lib/caption/canonicalProductionWebVtt.mjs.map +1 -1
- package/lib/draw/bindAutoMovieDrawSceneSoftProps.d.ts +15 -0
- package/lib/draw/bindAutoMovieDrawSceneSoftProps.js +41 -0
- package/lib/draw/bindAutoMovieDrawSceneSoftProps.js.map +1 -0
- package/lib/draw/bindAutoMovieDrawSceneSoftProps.mjs +36 -0
- package/lib/draw/bindAutoMovieDrawSceneSoftProps.mjs.map +1 -0
- package/lib/draw/index.d.ts +1 -0
- package/lib/draw/index.js +1 -0
- package/lib/draw/index.js.map +1 -1
- package/lib/draw/index.mjs +2 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +12 -7
- package/lib/planSequenceRender.d.ts +5 -5
- package/lib/planSequenceRender.js +12 -6
- package/lib/planSequenceRender.js.map +1 -1
- package/lib/planSequenceRender.mjs +12 -8
- package/lib/planSequenceRender.mjs.map +1 -1
- package/lib/scene/IAutoMovieSceneObject.d.ts +4 -1
- package/lib/scene/IAutoMovieSceneSoftProps.d.ts +36 -0
- package/lib/scene/IAutoMovieSceneSoftProps.js +3 -0
- package/lib/scene/IAutoMovieSceneSoftProps.js.map +1 -0
- package/lib/scene/IAutoMovieSceneSoftProps.mjs +0 -0
- package/lib/scene/IChunkObject.d.ts +7 -3
- package/lib/scene/applyPracticalSurfaceMaterials.d.ts +31 -0
- package/lib/scene/applyPracticalSurfaceMaterials.js +87 -0
- package/lib/scene/applyPracticalSurfaceMaterials.js.map +1 -0
- package/lib/scene/applyPracticalSurfaceMaterials.mjs +47 -0
- package/lib/scene/applyPracticalSurfaceMaterials.mjs.map +1 -0
- package/lib/scene/buildInstancedFormation.d.ts +1 -1
- package/lib/scene/buildInstancedFormation.js +44 -19
- package/lib/scene/buildInstancedFormation.js.map +1 -1
- package/lib/scene/buildInstancedFormation.mjs +30 -13
- package/lib/scene/buildInstancedFormation.mjs.map +1 -1
- package/lib/scene/buildScene.d.ts +10 -7
- package/lib/scene/buildScene.js +21 -7
- package/lib/scene/buildScene.js.map +1 -1
- package/lib/scene/buildScene.mjs +27 -9
- package/lib/scene/buildScene.mjs.map +1 -1
- package/lib/scene/buildSceneSoftProps.d.ts +15 -0
- package/lib/scene/buildSceneSoftProps.js +71 -0
- package/lib/scene/buildSceneSoftProps.js.map +1 -0
- package/lib/scene/buildSceneSoftProps.mjs +67 -0
- package/lib/scene/buildSceneSoftProps.mjs.map +1 -0
- package/lib/scene/human-polygon/AutoMovieHumanPolygon.d.ts +52 -1
- package/lib/scene/human-polygon/buildHumanPolygon.d.ts +3 -1
- package/lib/scene/human-polygon/buildHumanPolygon.js +14 -2
- package/lib/scene/human-polygon/buildHumanPolygon.js.map +1 -1
- package/lib/scene/human-polygon/buildHumanPolygon.mjs +11 -2
- package/lib/scene/human-polygon/buildHumanPolygon.mjs.map +1 -1
- package/lib/scene/human-polygon/buildPolygonShotActor.d.ts +40 -0
- package/lib/scene/human-polygon/buildPolygonShotActor.js +69 -0
- package/lib/scene/human-polygon/buildPolygonShotActor.js.map +1 -0
- package/lib/scene/human-polygon/buildPolygonShotActor.mjs +74 -0
- package/lib/scene/human-polygon/buildPolygonShotActor.mjs.map +1 -0
- package/lib/scene/human-polygon/index.d.ts +1 -0
- package/lib/scene/human-polygon/index.js +3 -1
- package/lib/scene/human-polygon/index.js.map +1 -1
- package/lib/scene/human-polygon/index.mjs +2 -1
- package/lib/scene/human-polygon/prepareHumanPolygonPresentation.d.ts +17 -0
- package/lib/scene/human-polygon/prepareHumanPolygonPresentation.js +231 -0
- package/lib/scene/human-polygon/prepareHumanPolygonPresentation.js.map +1 -0
- package/lib/scene/human-polygon/prepareHumanPolygonPresentation.mjs +189 -0
- package/lib/scene/human-polygon/prepareHumanPolygonPresentation.mjs.map +1 -0
- package/lib/scene/index.d.ts +3 -0
- package/lib/scene/index.js +3 -0
- package/lib/scene/index.js.map +1 -1
- package/lib/scene/index.mjs +45 -42
- package/lib/scene/renderAutoMovieFilmFrame.d.ts +6 -4
- package/lib/scene/renderAutoMovieFilmFrame.js +12 -8
- package/lib/scene/renderAutoMovieFilmFrame.js.map +1 -1
- package/lib/scene/renderAutoMovieFilmFrame.mjs +12 -8
- package/lib/scene/renderAutoMovieFilmFrame.mjs.map +1 -1
- package/lib/scene/softPropCordSurface.d.ts +14 -0
- package/lib/scene/softPropCordSurface.js +128 -0
- package/lib/scene/softPropCordSurface.js.map +1 -0
- package/lib/scene/softPropCordSurface.mjs +88 -0
- package/lib/scene/softPropCordSurface.mjs.map +1 -0
- package/package.json +4 -4
- package/src/AutoMovieFrameGrid.ts +70 -0
- package/src/caption/canonicalProductionWebVtt.ts +20 -4
- package/src/draw/bindAutoMovieDrawSceneSoftProps.ts +43 -0
- package/src/draw/index.ts +1 -0
- package/src/index.ts +1 -0
- package/src/planSequenceRender.ts +21 -10
- package/src/scene/IAutoMovieSceneObject.ts +6 -1
- package/src/scene/IAutoMovieSceneSoftProps.ts +38 -0
- package/src/scene/IChunkObject.ts +10 -3
- package/src/scene/applyPracticalSurfaceMaterials.ts +79 -0
- package/src/scene/buildInstancedFormation.ts +86 -55
- package/src/scene/buildScene.ts +22 -6
- package/src/scene/buildSceneSoftProps.ts +83 -0
- package/src/scene/human-polygon/AutoMovieHumanPolygon.ts +61 -1
- package/src/scene/human-polygon/buildHumanPolygon.ts +22 -2
- package/src/scene/human-polygon/buildPolygonShotActor.ts +112 -0
- package/src/scene/human-polygon/index.ts +1 -0
- package/src/scene/human-polygon/prepareHumanPolygonPresentation.ts +328 -0
- package/src/scene/index.ts +3 -0
- package/src/scene/renderAutoMovieFilmFrame.ts +14 -9
- package/src/scene/softPropCordSurface.ts +132 -0
|
@@ -11,6 +11,7 @@ import { applyHumanPolygonPose } from "./applyHumanPolygonPose.js";
|
|
|
11
11
|
import { buildHumanPolygonModule } from "./buildHumanPolygonModule.js";
|
|
12
12
|
import { buildHumanPolygonParts } from "./buildHumanPolygonParts.js";
|
|
13
13
|
import { createHumanPolygonPalette } from "./createHumanPolygonPalette.js";
|
|
14
|
+
import { prepareHumanPolygonPresentation } from "./prepareHumanPolygonPresentation.js";
|
|
14
15
|
|
|
15
16
|
/**
|
|
16
17
|
* Draw a rigid polygon blockout from the generated skeleton, in metres.
|
|
@@ -36,7 +37,7 @@ import { createHumanPolygonPalette } from "./createHumanPolygonPalette.js";
|
|
|
36
37
|
* The caller may attach a face to `head.object` in that same local frame.
|
|
37
38
|
*
|
|
38
39
|
* @param output Generated bones and placements.
|
|
39
|
-
* @param options Optional display colours keyed by emitted bone name
|
|
40
|
+
* @param options Optional display colours keyed by emitted bone name and authored cues sampled on the shot-local source clock.
|
|
40
41
|
* @returns Owned surface, actual bone/mesh registries, pose/palette ports, generating sections, head attachment and cleanup. Local probe points use registered rest point minus the corresponding rest joint; actor-root placement belongs to the parent.
|
|
41
42
|
*
|
|
42
43
|
* @evidence contracts/development/implementation.md#principled-implementation Every dimension comes from skeleton joints, tips and girth radii; no skin surface of the realistic Human is read, so a change in how the Human lofts its skin cannot break the blockout.
|
|
@@ -52,6 +53,8 @@ export function buildHumanPolygon(
|
|
|
52
53
|
options: {
|
|
53
54
|
/** RGB hex overrides for matching emitted parts; omitted parts retain clay. */
|
|
54
55
|
partColors?: Readonly<Record<string, number>>;
|
|
56
|
+
/** Source pose, actor frame and authored polygon cues for optional time-based drawing. */
|
|
57
|
+
presentation?: AutoMovieHumanPolygon.IPresentation;
|
|
55
58
|
} = {},
|
|
56
59
|
): AutoMovieHumanPolygon.IDrawing {
|
|
57
60
|
createHumanPolygonPalette.validate(options.partColors);
|
|
@@ -121,6 +124,9 @@ export function buildHumanPolygon(
|
|
|
121
124
|
const palette: ReturnType<typeof createHumanPolygonPalette> =
|
|
122
125
|
createHumanPolygonPalette(material, partMeshes);
|
|
123
126
|
let disposed: boolean = false;
|
|
127
|
+
let samplePresentation:
|
|
128
|
+
| ReturnType<typeof prepareHumanPolygonPresentation>
|
|
129
|
+
| undefined;
|
|
124
130
|
let retirementFailure: { error: unknown } | undefined;
|
|
125
131
|
|
|
126
132
|
/**
|
|
@@ -210,6 +216,7 @@ export function buildHumanPolygon(
|
|
|
210
216
|
if (retirementFailure !== undefined) throw retirementFailure.error;
|
|
211
217
|
if (disposed) return;
|
|
212
218
|
disposed = true;
|
|
219
|
+
samplePresentation = undefined;
|
|
213
220
|
try {
|
|
214
221
|
reportAutoMovieResourceRetirement(
|
|
215
222
|
[
|
|
@@ -259,13 +266,19 @@ export function buildHumanPolygon(
|
|
|
259
266
|
groups.set(bone.bone, joint);
|
|
260
267
|
bindings.set(bone.bone, [joint]);
|
|
261
268
|
}
|
|
269
|
+
if (options.presentation !== undefined)
|
|
270
|
+
samplePresentation = prepareHumanPolygonPresentation(
|
|
271
|
+
options.presentation,
|
|
272
|
+
bones,
|
|
273
|
+
new Set(partMeshes.keys()),
|
|
274
|
+
);
|
|
262
275
|
setPartColors(options.partColors);
|
|
263
276
|
applyHumanPolygonPose(object, bindings, required, output);
|
|
264
277
|
} catch (error: unknown) {
|
|
265
278
|
dispose({ error });
|
|
266
279
|
throw error;
|
|
267
280
|
}
|
|
268
|
-
|
|
281
|
+
const drawing: AutoMovieHumanPolygon.IDrawing = {
|
|
269
282
|
object,
|
|
270
283
|
surface,
|
|
271
284
|
sections,
|
|
@@ -291,4 +304,11 @@ export function buildHumanPolygon(
|
|
|
291
304
|
},
|
|
292
305
|
dispose,
|
|
293
306
|
};
|
|
307
|
+
if (samplePresentation !== undefined)
|
|
308
|
+
drawing.drawAt = (seconds: number): void => {
|
|
309
|
+
if (samplePresentation === undefined)
|
|
310
|
+
throw new Error("Polygon drawing is disposed");
|
|
311
|
+
drawing.setPose(samplePresentation(seconds));
|
|
312
|
+
};
|
|
313
|
+
return drawing;
|
|
294
314
|
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { productionFrameBoundaryToSeconds } from "@automovie/engine";
|
|
2
|
+
import type {
|
|
3
|
+
IAutoMovieHumanSkeleton,
|
|
4
|
+
IAutoMovieProductionFrameRate,
|
|
5
|
+
IAutoMovieProductionRenderLayer,
|
|
6
|
+
IAutoMovieQuaternion,
|
|
7
|
+
IAutoMovieRigidTransform,
|
|
8
|
+
IAutoMovieShot,
|
|
9
|
+
IAutoMovieVector3,
|
|
10
|
+
} from "@automovie/interface";
|
|
11
|
+
import { Quaternion, Vector3 } from "three";
|
|
12
|
+
|
|
13
|
+
import type { AutoMovieHumanPolygon } from "./AutoMovieHumanPolygon.js";
|
|
14
|
+
import { buildHumanPolygon } from "./buildHumanPolygon.js";
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Build a polygon actor and its source-frame sampler for a compiled shot.
|
|
18
|
+
* A film host mounts the drawing in the shot scene and supplies `drawLayer`
|
|
19
|
+
* as a layer preparation callback. Its source frame accounts for cuts and
|
|
20
|
+
* trims. If an actor frame is supplied, the sampler also places the drawing
|
|
21
|
+
* at that world frame under its rigid parent. Without a supplied frame the
|
|
22
|
+
* cue's shot axes coincide with the drawing's axes at the origin.
|
|
23
|
+
* Dispose the drawing with the usual polygon drawing owner.
|
|
24
|
+
*
|
|
25
|
+
* @evidence contracts/development/common.md#meaningful-documentation States the host's mounting, sampling and disposal responsibilities, along with the source time and frame conventions.
|
|
26
|
+
* @evidence contracts/development/implementation.md#principled-implementation All passes read the same polygon node transform at the exact shot-local frame boundary.
|
|
27
|
+
* @evidence contracts/development/implementation.md#clear-and-simple-structure Build the existing drawing with its shot cues, then convert each layer's source frame through the production clock.
|
|
28
|
+
* @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts Refuses a layer from another shot and uses the timeline's source frame directly.
|
|
29
|
+
* @evidence contracts/development/implementation.md#efficient-algorithms The polygon drawing and cue plan are built once. Each layer converts one frame and applies one sample.
|
|
30
|
+
* @evidence contracts/development/implementation.md#reuse-equivalent-work Uses the regular polygon drawing and the same rational clock as other production render passes.
|
|
31
|
+
* @evidence contracts/development/implementation.md#bound-retention-and-release-resources The returned drawing owns the render resources. The sampler retains that drawing and the shot's fixed source clock.
|
|
32
|
+
*/
|
|
33
|
+
export function buildPolygonShotActor(input: {
|
|
34
|
+
/** Compiled shot and its optional body presentation cues. */
|
|
35
|
+
shot: Pick<IAutoMovieShot, "id" | "polygonBodyCues">;
|
|
36
|
+
/** Staged actor id. */
|
|
37
|
+
subject: string;
|
|
38
|
+
/** Bind bones and placements used to build the polygon drawing. */
|
|
39
|
+
opening: Pick<IAutoMovieHumanSkeleton.IOutput, "bones" | "posed">;
|
|
40
|
+
/** Canonical body-frame pose at a shot-local time. */
|
|
41
|
+
poseAt: (seconds: number) => Pick<IAutoMovieHumanSkeleton.IOutput, "posed">;
|
|
42
|
+
/** Deterministic, synchronous actor rigid frame at shot-local time in scene-world axes. Detach sampling can read the same time again. */
|
|
43
|
+
actorFrameAt?: (seconds: number) => IAutoMovieRigidTransform;
|
|
44
|
+
/** Production frame grid used by the layer's source frame. */
|
|
45
|
+
frameRate: IAutoMovieProductionFrameRate;
|
|
46
|
+
/** Optional palette by emitted bone name. */
|
|
47
|
+
partColors?: Readonly<Record<string, number>>;
|
|
48
|
+
}): {
|
|
49
|
+
/** Drawing to mount in the shot scene and dispose when finished. */
|
|
50
|
+
drawing: AutoMovieHumanPolygon.IDrawing;
|
|
51
|
+
/** Evaluate the visible actor for an admitted render layer of this shot. */
|
|
52
|
+
drawLayer: (layer: IAutoMovieProductionRenderLayer) => void;
|
|
53
|
+
} {
|
|
54
|
+
const {
|
|
55
|
+
shot,
|
|
56
|
+
subject,
|
|
57
|
+
opening,
|
|
58
|
+
poseAt,
|
|
59
|
+
actorFrameAt,
|
|
60
|
+
frameRate,
|
|
61
|
+
partColors,
|
|
62
|
+
} = input;
|
|
63
|
+
const drawing: AutoMovieHumanPolygon.IDrawing = buildHumanPolygon(opening, {
|
|
64
|
+
...(partColors === undefined ? {} : { partColors }),
|
|
65
|
+
presentation: {
|
|
66
|
+
subject,
|
|
67
|
+
cues: shot.polygonBodyCues ?? [],
|
|
68
|
+
poseAt,
|
|
69
|
+
...(actorFrameAt === undefined ? {} : { actorFrameAt }),
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
const shotId: string = shot.id;
|
|
73
|
+
return {
|
|
74
|
+
drawing,
|
|
75
|
+
drawLayer: (layer: IAutoMovieProductionRenderLayer): void => {
|
|
76
|
+
if (layer.shot !== shotId)
|
|
77
|
+
throw new Error(`Polygon actor ${subject} belongs to shot ${shotId}`);
|
|
78
|
+
const seconds: number = productionFrameBoundaryToSeconds({
|
|
79
|
+
frame: layer.sourceFrame,
|
|
80
|
+
frameRate,
|
|
81
|
+
});
|
|
82
|
+
if (actorFrameAt === undefined) {
|
|
83
|
+
drawing.drawAt!(seconds);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
const {
|
|
87
|
+
position: translation,
|
|
88
|
+
rotation: orientation,
|
|
89
|
+
}: IAutoMovieRigidTransform = actorFrameAt(seconds);
|
|
90
|
+
const { x: tx, y: ty, z: tz }: IAutoMovieVector3 = translation;
|
|
91
|
+
const { x, y, z, w }: IAutoMovieQuaternion = orientation;
|
|
92
|
+
if (
|
|
93
|
+
![tx, ty, tz, x, y, z, w].every(Number.isFinite) ||
|
|
94
|
+
Math.abs(x ** 2 + y ** 2 + z ** 2 + w ** 2 - 1) > 1e-6
|
|
95
|
+
)
|
|
96
|
+
throw new Error(`Invalid staging frame for polygon actor ${subject}`);
|
|
97
|
+
const position: Vector3 = new Vector3(tx, ty, tz);
|
|
98
|
+
const rotation: Quaternion = new Quaternion(x, y, z, w).normalize();
|
|
99
|
+
const parent = drawing.object.parent;
|
|
100
|
+
if (parent !== null) {
|
|
101
|
+
parent.worldToLocal(position);
|
|
102
|
+
rotation.premultiply(
|
|
103
|
+
parent.getWorldQuaternion(new Quaternion()).invert(),
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
drawing.drawAt!(seconds);
|
|
107
|
+
drawing.object.position.copy(position);
|
|
108
|
+
drawing.object.quaternion.copy(rotation);
|
|
109
|
+
drawing.object.updateWorldMatrix(true, true);
|
|
110
|
+
},
|
|
111
|
+
};
|
|
112
|
+
}
|
|
@@ -2,4 +2,5 @@ export type { AutoMovieHumanPolygon } from "./AutoMovieHumanPolygon.js";
|
|
|
2
2
|
export type { AutoMovieHumanCartoon } from "./AutoMovieHumanCartoon.js";
|
|
3
3
|
export { buildHumanPolygon } from "./buildHumanPolygon.js";
|
|
4
4
|
export { buildHumanCartoonFace } from "./buildHumanCartoonFace.js";
|
|
5
|
+
export { buildPolygonShotActor } from "./buildPolygonShotActor.js";
|
|
5
6
|
export { createAutoMovieHumanPolygonFigure } from "./createAutoMovieHumanPolygonFigure.js";
|
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
IAutoMovieHumanBindBone,
|
|
3
|
+
IAutoMovieHumanBonePlacement,
|
|
4
|
+
IAutoMovieHumanSkeleton,
|
|
5
|
+
IAutoMoviePolygonBodyCue,
|
|
6
|
+
IAutoMovieRigidTransform,
|
|
7
|
+
} from "@automovie/interface";
|
|
8
|
+
import { Quaternion, Vector3 } from "three";
|
|
9
|
+
|
|
10
|
+
import type { AutoMovieHumanPolygon } from "./AutoMovieHumanPolygon.js";
|
|
11
|
+
|
|
12
|
+
/** A complete evaluated pose in registered Human body coordinates. */
|
|
13
|
+
type AutoMoviePolygonPose = Pick<IAutoMovieHumanSkeleton.IOutput, "posed">;
|
|
14
|
+
|
|
15
|
+
/** One evaluated frame retained or used for rigid placement arithmetic. */
|
|
16
|
+
interface IAutoMoviePolygonFrame {
|
|
17
|
+
position: Vector3;
|
|
18
|
+
rotation: Quaternion;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Shared timing and authored rotation of a prepared visual cue. */
|
|
22
|
+
interface IAutoMoviePolygonCueTiming {
|
|
23
|
+
at: number;
|
|
24
|
+
duration: number;
|
|
25
|
+
rotation: Quaternion;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** A live bend or a frozen shot-world release with its authored displacement. */
|
|
29
|
+
type AutoMoviePreparedPolygonCue = IAutoMoviePolygonCueTiming &
|
|
30
|
+
(
|
|
31
|
+
| { kind: "bend"; bone: string }
|
|
32
|
+
| {
|
|
33
|
+
kind: "detach";
|
|
34
|
+
pivot: Vector3;
|
|
35
|
+
released: ReadonlyMap<string, IAutoMoviePolygonFrame>;
|
|
36
|
+
translation: Vector3;
|
|
37
|
+
}
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
/** Admit a finite quaternion with the same squared-norm tolerance as a polygon pose. */
|
|
41
|
+
function unitRotation(
|
|
42
|
+
x: number,
|
|
43
|
+
y: number,
|
|
44
|
+
z: number,
|
|
45
|
+
w: number,
|
|
46
|
+
label: string,
|
|
47
|
+
): Quaternion {
|
|
48
|
+
if (
|
|
49
|
+
![x, y, z, w].every(Number.isFinite) ||
|
|
50
|
+
Math.abs(x ** 2 + y ** 2 + z ** 2 + w ** 2 - 1) > 1e-6
|
|
51
|
+
)
|
|
52
|
+
throw new Error(`Invalid polygon rotation: ${label}`);
|
|
53
|
+
return new Quaternion(x, y, z, w).normalize();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Admit the metre translation of a rigid frame. */
|
|
57
|
+
function finitePosition(
|
|
58
|
+
x: number,
|
|
59
|
+
y: number,
|
|
60
|
+
z: number,
|
|
61
|
+
label: string,
|
|
62
|
+
): Vector3 {
|
|
63
|
+
if (![x, y, z].every(Number.isFinite))
|
|
64
|
+
throw new Error(`Invalid polygon position: ${label}`);
|
|
65
|
+
return new Vector3(x, y, z);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Copy one source joint frame for arithmetic without mutating the evaluated pose. */
|
|
69
|
+
function boneFrame(
|
|
70
|
+
placement: IAutoMovieHumanBonePlacement,
|
|
71
|
+
): IAutoMoviePolygonFrame {
|
|
72
|
+
if (placement.position.length !== 3 || placement.rotation.length !== 4)
|
|
73
|
+
throw new Error(`Invalid polygon placement: ${placement.bone}`);
|
|
74
|
+
return {
|
|
75
|
+
position: finitePosition(...placement.position, placement.bone),
|
|
76
|
+
rotation: unitRotation(...placement.rotation, placement.bone),
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** Read the actor parent frame in shot world or use the fixed identity frame. */
|
|
81
|
+
function actorFrame(
|
|
82
|
+
actorFrameAt: AutoMovieHumanPolygon.IPresentation["actorFrameAt"],
|
|
83
|
+
seconds: number,
|
|
84
|
+
): IAutoMoviePolygonFrame {
|
|
85
|
+
if (actorFrameAt === undefined)
|
|
86
|
+
return { position: new Vector3(), rotation: new Quaternion() };
|
|
87
|
+
const { position, rotation }: IAutoMovieRigidTransform =
|
|
88
|
+
actorFrameAt(seconds);
|
|
89
|
+
return {
|
|
90
|
+
position: finitePosition(position.x, position.y, position.z, "actor frame"),
|
|
91
|
+
rotation: unitRotation(
|
|
92
|
+
rotation.x,
|
|
93
|
+
rotation.y,
|
|
94
|
+
rotation.z,
|
|
95
|
+
rotation.w,
|
|
96
|
+
"actor frame",
|
|
97
|
+
),
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Prepare rigid visual cues for one polygon drawing on its source clock.
|
|
103
|
+
*
|
|
104
|
+
* @evidence contracts/development/common.md#meaningful-documentation Takes source poses, a source hierarchy, emitted targets and actor staging. Returns a seekable sampler in Human body coordinates.
|
|
105
|
+
* @evidence contracts/development/implementation.md#principled-implementation Resolves disjoint subtrees through source parents and requires an emitted part in each subtree. Bends use a live joint pivot. A release admits the replaced live placements and maps its world-space snapshot back through live actor staging.
|
|
106
|
+
* @evidence contracts/development/implementation.md#clear-and-simple-structure Preparation owns target admission and reference sampling. Existing pose admission and graphics writes remain at the drawing.
|
|
107
|
+
* @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts Uses the actual source pivots and emitted descendants. No simulation, graph creation or changes to the source skeletal pose are performed.
|
|
108
|
+
* @evidence contracts/development/implementation.md#efficient-algorithms Admission builds a child index and visits each selected bone once. A release scans one source pose and retains only its branch placements. Active drawing samples index and visit the live pose once.
|
|
109
|
+
* @evidence contracts/development/implementation.md#reuse-equivalent-work The source hierarchy and captured release frames are reused across samples, including reverse seeks. Bend-only samples need no actor staging.
|
|
110
|
+
* @evidence contracts/development/implementation.md#bound-retention-and-release-resources Retains one reference frame per released bone and no graphics or external handles.
|
|
111
|
+
*/
|
|
112
|
+
export function prepareHumanPolygonPresentation(
|
|
113
|
+
presentation: AutoMovieHumanPolygon.IPresentation,
|
|
114
|
+
bones: ReadonlyMap<string, IAutoMovieHumanBindBone>,
|
|
115
|
+
emitted: ReadonlySet<string>,
|
|
116
|
+
): (seconds: number) => AutoMoviePolygonPose {
|
|
117
|
+
const { subject, poseAt, actorFrameAt }: AutoMovieHumanPolygon.IPresentation =
|
|
118
|
+
presentation;
|
|
119
|
+
const children: Map<string, string[]> = new Map();
|
|
120
|
+
for (const { bone, parent } of bones.values()) {
|
|
121
|
+
if (parent === null) continue;
|
|
122
|
+
const siblings: string[] | undefined = children.get(parent);
|
|
123
|
+
if (siblings === undefined) children.set(parent, [bone]);
|
|
124
|
+
else siblings.push(bone);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const cuesByBone: Map<string, AutoMoviePreparedPolygonCue> = new Map();
|
|
128
|
+
const occupied: Set<string> = new Set();
|
|
129
|
+
let firstCue: number = Infinity;
|
|
130
|
+
for (const cue of presentation.cues) {
|
|
131
|
+
if (cue.subject !== subject) continue;
|
|
132
|
+
if (!bones.has(cue.bone))
|
|
133
|
+
throw new Error(`Unsupported polygon cue target: ${cue.bone}`);
|
|
134
|
+
if (
|
|
135
|
+
!Number.isFinite(cue.at) ||
|
|
136
|
+
cue.at < 0 ||
|
|
137
|
+
!Number.isFinite(cue.duration) ||
|
|
138
|
+
cue.duration < 0 ||
|
|
139
|
+
!Number.isFinite(cue.at + cue.duration)
|
|
140
|
+
)
|
|
141
|
+
throw new Error(`Invalid polygon cue timing: ${cue.bone}`);
|
|
142
|
+
firstCue = Math.min(firstCue, cue.at);
|
|
143
|
+
|
|
144
|
+
const subtree: string[] = [cue.bone];
|
|
145
|
+
let hasEmittedPart: boolean = false;
|
|
146
|
+
for (const bone of subtree) {
|
|
147
|
+
if (occupied.has(bone))
|
|
148
|
+
throw new Error(`Overlapping polygon cue subtree: ${bone}`);
|
|
149
|
+
occupied.add(bone);
|
|
150
|
+
hasEmittedPart ||= emitted.has(bone);
|
|
151
|
+
for (const child of children.get(bone) ?? []) subtree.push(child);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (!hasEmittedPart)
|
|
155
|
+
throw new Error(`Unsupported polygon cue target: ${cue.bone}`);
|
|
156
|
+
|
|
157
|
+
// Authored cue admission measures the quaternion norm. Registered
|
|
158
|
+
// skeletal placements use the drawing's separate squared-norm tolerance.
|
|
159
|
+
const { x, y, z, w }: IAutoMoviePolygonBodyCue["rotation"] = cue.rotation;
|
|
160
|
+
const norm: number = Math.hypot(x, y, z, w);
|
|
161
|
+
if (![x, y, z, w].every(Number.isFinite) || Math.abs(norm - 1) > 1e-6)
|
|
162
|
+
throw new Error(`Invalid polygon rotation: ${cue.bone}`);
|
|
163
|
+
const timing: IAutoMoviePolygonCueTiming = {
|
|
164
|
+
at: cue.at,
|
|
165
|
+
duration: cue.duration,
|
|
166
|
+
rotation: new Quaternion(x / norm, y / norm, z / norm, w / norm),
|
|
167
|
+
};
|
|
168
|
+
let prepared: AutoMoviePreparedPolygonCue;
|
|
169
|
+
if (cue.kind === "bend") {
|
|
170
|
+
prepared = { ...timing, kind: cue.kind, bone: cue.bone };
|
|
171
|
+
} else if (cue.kind === "detach") {
|
|
172
|
+
const translation: Vector3 = finitePosition(
|
|
173
|
+
cue.translation.x,
|
|
174
|
+
cue.translation.y,
|
|
175
|
+
cue.translation.z,
|
|
176
|
+
cue.bone,
|
|
177
|
+
);
|
|
178
|
+
const released: Map<string, IAutoMoviePolygonFrame> = new Map();
|
|
179
|
+
const selected: Set<string> = new Set(subtree);
|
|
180
|
+
const actor: IAutoMoviePolygonFrame = actorFrame(actorFrameAt, cue.at);
|
|
181
|
+
|
|
182
|
+
// Capture the branch's world placement once so later poses and actor
|
|
183
|
+
// staging cannot drive the released parts.
|
|
184
|
+
for (const placement of poseAt(cue.at).posed) {
|
|
185
|
+
if (!selected.has(placement.bone)) continue;
|
|
186
|
+
if (released.has(placement.bone))
|
|
187
|
+
throw new Error(
|
|
188
|
+
`Duplicate polygon release placement: ${placement.bone}`,
|
|
189
|
+
);
|
|
190
|
+
const frame: IAutoMoviePolygonFrame = boneFrame(placement);
|
|
191
|
+
frame.position.applyQuaternion(actor.rotation).add(actor.position);
|
|
192
|
+
frame.rotation.premultiply(actor.rotation);
|
|
193
|
+
released.set(placement.bone, frame);
|
|
194
|
+
}
|
|
195
|
+
const origin: IAutoMoviePolygonFrame | undefined = released.get(cue.bone);
|
|
196
|
+
if (origin === undefined || released.size !== subtree.length)
|
|
197
|
+
throw new Error(`Incomplete polygon release pose: ${cue.bone}`);
|
|
198
|
+
prepared = {
|
|
199
|
+
...timing,
|
|
200
|
+
kind: cue.kind,
|
|
201
|
+
pivot: origin.position,
|
|
202
|
+
released,
|
|
203
|
+
translation,
|
|
204
|
+
};
|
|
205
|
+
} else {
|
|
206
|
+
throw new Error("Unsupported polygon cue kind");
|
|
207
|
+
}
|
|
208
|
+
for (const bone of subtree) cuesByBone.set(bone, prepared);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
return (seconds: number): AutoMoviePolygonPose => {
|
|
212
|
+
if (!Number.isFinite(seconds))
|
|
213
|
+
throw new Error("Invalid polygon drawing time");
|
|
214
|
+
const pose: AutoMoviePolygonPose = poseAt(seconds);
|
|
215
|
+
if (seconds < firstCue) return pose;
|
|
216
|
+
const live: Map<string, IAutoMovieHumanBonePlacement> = new Map(
|
|
217
|
+
pose.posed.map(
|
|
218
|
+
(
|
|
219
|
+
placement: IAutoMovieHumanBonePlacement,
|
|
220
|
+
): [string, IAutoMovieHumanBonePlacement] => [
|
|
221
|
+
placement.bone,
|
|
222
|
+
placement,
|
|
223
|
+
],
|
|
224
|
+
),
|
|
225
|
+
);
|
|
226
|
+
const deltas: Map<AutoMoviePreparedPolygonCue, IAutoMoviePolygonFrame> =
|
|
227
|
+
new Map();
|
|
228
|
+
let actor: IAutoMoviePolygonFrame | undefined;
|
|
229
|
+
let inverseActorRotation: Quaternion | undefined;
|
|
230
|
+
return {
|
|
231
|
+
posed: pose.posed.map(
|
|
232
|
+
(
|
|
233
|
+
placement: IAutoMovieHumanBonePlacement,
|
|
234
|
+
): IAutoMovieHumanBonePlacement => {
|
|
235
|
+
const cue: AutoMoviePreparedPolygonCue | undefined = cuesByBone.get(
|
|
236
|
+
placement.bone,
|
|
237
|
+
);
|
|
238
|
+
if (cue === undefined || seconds < cue.at) return placement;
|
|
239
|
+
const amount: number =
|
|
240
|
+
cue.duration === 0
|
|
241
|
+
? 1
|
|
242
|
+
: Math.min(1, (seconds - cue.at) / cue.duration);
|
|
243
|
+
if (amount === 0) return placement;
|
|
244
|
+
|
|
245
|
+
let delta: IAutoMoviePolygonFrame | undefined = deltas.get(cue);
|
|
246
|
+
if (delta === undefined) {
|
|
247
|
+
const rotation: Quaternion = new Quaternion().slerp(
|
|
248
|
+
cue.rotation,
|
|
249
|
+
amount,
|
|
250
|
+
);
|
|
251
|
+
if (cue.kind === "bend") {
|
|
252
|
+
const joint: IAutoMovieHumanBonePlacement | undefined = live.get(
|
|
253
|
+
cue.bone,
|
|
254
|
+
);
|
|
255
|
+
if (joint === undefined)
|
|
256
|
+
throw new Error(`Missing polygon bend pivot: ${cue.bone}`);
|
|
257
|
+
const frame: IAutoMoviePolygonFrame = boneFrame(joint);
|
|
258
|
+
|
|
259
|
+
// Conjugating the local rotation gives the same turn in body
|
|
260
|
+
// coordinates, which the flat descendant placements share.
|
|
261
|
+
rotation
|
|
262
|
+
.premultiply(frame.rotation)
|
|
263
|
+
.multiply(frame.rotation.invert());
|
|
264
|
+
delta = { position: frame.position, rotation };
|
|
265
|
+
} else {
|
|
266
|
+
actor ??= actorFrame(actorFrameAt, seconds);
|
|
267
|
+
inverseActorRotation ??= actor.rotation.clone().invert();
|
|
268
|
+
delta = {
|
|
269
|
+
position: cue.pivot
|
|
270
|
+
.clone()
|
|
271
|
+
.addScaledVector(cue.translation, amount),
|
|
272
|
+
rotation,
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
deltas.set(cue, delta);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// Admit the raw placement before a release can replace it.
|
|
279
|
+
let frame: IAutoMoviePolygonFrame = boneFrame(placement);
|
|
280
|
+
if (cue.kind === "bend") {
|
|
281
|
+
frame.position
|
|
282
|
+
.sub(delta.position)
|
|
283
|
+
.applyQuaternion(delta.rotation)
|
|
284
|
+
.add(delta.position);
|
|
285
|
+
frame.rotation.premultiply(delta.rotation);
|
|
286
|
+
} else {
|
|
287
|
+
const release: IAutoMoviePolygonFrame | undefined =
|
|
288
|
+
cue.released.get(placement.bone);
|
|
289
|
+
if (
|
|
290
|
+
release === undefined ||
|
|
291
|
+
actor === undefined ||
|
|
292
|
+
inverseActorRotation === undefined
|
|
293
|
+
)
|
|
294
|
+
throw new Error(
|
|
295
|
+
`Missing polygon release frame: ${placement.bone}`,
|
|
296
|
+
);
|
|
297
|
+
|
|
298
|
+
// Existing groups are actor-local. Cancel the live parent frame
|
|
299
|
+
// so the renderer applies it once and reaches the intended world pose.
|
|
300
|
+
frame = {
|
|
301
|
+
position: release.position
|
|
302
|
+
.clone()
|
|
303
|
+
.sub(cue.pivot)
|
|
304
|
+
.applyQuaternion(delta.rotation)
|
|
305
|
+
.add(delta.position)
|
|
306
|
+
.sub(actor.position)
|
|
307
|
+
.applyQuaternion(inverseActorRotation),
|
|
308
|
+
rotation: release.rotation
|
|
309
|
+
.clone()
|
|
310
|
+
.premultiply(delta.rotation)
|
|
311
|
+
.premultiply(inverseActorRotation),
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
return {
|
|
315
|
+
bone: placement.bone,
|
|
316
|
+
position: [frame.position.x, frame.position.y, frame.position.z],
|
|
317
|
+
rotation: [
|
|
318
|
+
frame.rotation.x,
|
|
319
|
+
frame.rotation.y,
|
|
320
|
+
frame.rotation.z,
|
|
321
|
+
frame.rotation.w,
|
|
322
|
+
],
|
|
323
|
+
};
|
|
324
|
+
},
|
|
325
|
+
),
|
|
326
|
+
};
|
|
327
|
+
};
|
|
328
|
+
}
|
package/src/scene/index.ts
CHANGED
|
@@ -44,6 +44,7 @@ export * from "./importedModel/index.js";
|
|
|
44
44
|
export * from "./applyObjectMotion.js";
|
|
45
45
|
export * from "./applyObjectMotions.js";
|
|
46
46
|
export * from "./applyLightMotion.js";
|
|
47
|
+
export * from "./applyPracticalSurfaceMaterials.js";
|
|
47
48
|
export * from "./applyLightState.js";
|
|
48
49
|
export * from "./renderCrossDissolveFrames.js";
|
|
49
50
|
export * from "./renderCrossDissolve.js";
|
|
@@ -52,7 +53,9 @@ export * from "./buildSpace.js";
|
|
|
52
53
|
export * from "./deliveryCrop.js";
|
|
53
54
|
export * from "./cameraDepthPrecision.js";
|
|
54
55
|
export * from "./buildScene.js";
|
|
56
|
+
export * from "./buildSceneSoftProps.js";
|
|
55
57
|
export * from "./IAutoMovieSceneObject.js";
|
|
58
|
+
export * from "./IAutoMovieSceneSoftProps.js";
|
|
56
59
|
export * from "./applyAutoMovieShadowParticipation.js";
|
|
57
60
|
export * from "./applySceneFog.js";
|
|
58
61
|
export * from "./buildLight.js";
|
|
@@ -9,14 +9,14 @@ import { resolveAutoMovieFilmBeautyComposition } from "./resolveAutoMovieFilmBea
|
|
|
9
9
|
/**
|
|
10
10
|
* Render already sampled film layers through one beauty/guide boundary.
|
|
11
11
|
*
|
|
12
|
-
* Layer sample fields are opaque to this owner.
|
|
12
|
+
* Layer sample fields are opaque to this owner. An optional preparation callback samples the selected source before its draw, including each source of a dissolve. The render callback owns its reversible pass configuration. Beauty preserves direct, fade and dissolve weights; structural passes consume the Engine's single full-weight dominant layer with incoming winning a tie. Input admission happens before either callback can alter the display.
|
|
13
13
|
*
|
|
14
14
|
* The sampled film inputs are explicit. Interactive display-clock updates and inspection CLI timestamp filenames remain host observations rather than deterministic delivered-frame identity.
|
|
15
15
|
*
|
|
16
16
|
* @evidence contracts/development/implementation.md#principled-implementation Admits sampled one/two-layer beauty composition before callbacks, dispatches direct/fade/dissolve beauty and uses the Engine full-weight dominant layer with incoming tie winner for structural passes.
|
|
17
|
-
* @evidence contracts/development/implementation.md#clear-and-simple-structure
|
|
17
|
+
* @evidence contracts/development/implementation.md#clear-and-simple-structure The optional preparation callback applies each selected source's state immediately before the separate render callback. Canonical pass selection and beauty composition stay with their existing owners.
|
|
18
18
|
* @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts Invalid weight/cardinality/complement sum refuse rather than clamp or blend structural classifications; host clock/filename observations do not become deterministic delivered-frame identity.
|
|
19
|
-
* @evidence contracts/development/common.md#meaningful-documentation Documents opaque sampled fields, reversible
|
|
19
|
+
* @evidence contracts/development/common.md#meaningful-documentation Documents opaque sampled fields, per-source preparation order, reversible pass ownership, beauty weights, structural tie rule and pre-effect admission.
|
|
20
20
|
* @evidence contracts/development/implementation.md#efficient-algorithms One/two admitted layers give fixed dispatch work; structural selection clones the selected layer payload and compositor draws/readbacks retain their actual pixel/native costs.
|
|
21
21
|
* @evidence contracts/development/implementation.md#reuse-equivalent-work Canonical selection is reused by guide consumers and renderer-scoped beauty owners reuse their allocated copies; sampled source callbacks still execute for each actual requested frame.
|
|
22
22
|
* @evidence contracts/development/implementation.md#bound-retention-and-release-resources The adapter acquires no scene or renderer; callbacks own reversible state and compositor owners retain/release their native display copies, including terminal failure uncertainty.
|
|
@@ -29,6 +29,7 @@ export const renderAutoMovieFilmFrame: <Layer extends { weight: number }>(
|
|
|
29
29
|
layer: Omit<Layer, "weight"> & { weight: number },
|
|
30
30
|
pass: AutoMovieGuidePass,
|
|
31
31
|
) => void,
|
|
32
|
+
prepareLayer?: (layer: Omit<Layer, "weight"> & { weight: number }) => void,
|
|
32
33
|
) => void = <Layer extends { weight: number }>(
|
|
33
34
|
renderer: THREE.WebGLRenderer,
|
|
34
35
|
layers: readonly Layer[],
|
|
@@ -37,27 +38,31 @@ export const renderAutoMovieFilmFrame: <Layer extends { weight: number }>(
|
|
|
37
38
|
layer: Omit<Layer, "weight"> & { weight: number },
|
|
38
39
|
pass: AutoMovieGuidePass,
|
|
39
40
|
) => void,
|
|
41
|
+
prepareLayer?: (layer: Omit<Layer, "weight"> & { weight: number }) => void,
|
|
40
42
|
): void => {
|
|
41
43
|
const composition: ReturnType<
|
|
42
44
|
typeof resolveAutoMovieFilmBeautyComposition<Layer>
|
|
43
45
|
> = resolveAutoMovieFilmBeautyComposition(layers);
|
|
46
|
+
const draw = (layer: Omit<Layer, "weight"> & { weight: number }): void => {
|
|
47
|
+
prepareLayer?.(layer);
|
|
48
|
+
renderLayer(layer, pass);
|
|
49
|
+
};
|
|
44
50
|
if (pass !== "beauty") {
|
|
45
51
|
const selected: ReturnType<typeof productionRenderLayersForPass<Layer>> =
|
|
46
52
|
productionRenderLayersForPass({ layers }, pass);
|
|
47
|
-
|
|
48
|
-
} else if (composition.kind === "direct")
|
|
49
|
-
renderLayer(composition.layer, pass);
|
|
53
|
+
draw(selected[0]!);
|
|
54
|
+
} else if (composition.kind === "direct") draw(composition.layer);
|
|
50
55
|
else if (composition.kind === "fade")
|
|
51
56
|
renderFadeToBlackFrame(
|
|
52
57
|
renderer,
|
|
53
|
-
(): void =>
|
|
58
|
+
(): void => draw(composition.layer),
|
|
54
59
|
composition.weight,
|
|
55
60
|
);
|
|
56
61
|
else
|
|
57
62
|
renderCrossDissolveFrames(
|
|
58
63
|
renderer,
|
|
59
|
-
(): void =>
|
|
60
|
-
(): void =>
|
|
64
|
+
(): void => draw(composition.outgoing),
|
|
65
|
+
(): void => draw(composition.incoming),
|
|
61
66
|
composition.alpha,
|
|
62
67
|
);
|
|
63
68
|
};
|