@automovie/viewer 0.0.0 → 0.1.0
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/README.md +1 -1
- package/lib/AutoMoviePlayer.d.ts +2 -2
- package/lib/AutoMoviePlayer.js.map +1 -1
- package/lib/applyPose.d.ts +2 -2
- package/lib/applyPose.js.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/raster/AutoMovieRasterLighting.d.ts +43 -0
- package/lib/raster/AutoMovieRasterLighting.js +179 -0
- package/lib/raster/AutoMovieRasterLighting.js.map +1 -0
- package/lib/raster/AutoMovieRasterSheet.d.ts +68 -0
- package/lib/raster/AutoMovieRasterSheet.js +141 -0
- package/lib/raster/AutoMovieRasterSheet.js.map +1 -0
- package/lib/raster/AutoMovieRasterTarget.d.ts +87 -0
- package/lib/raster/AutoMovieRasterTarget.js +227 -0
- package/lib/raster/AutoMovieRasterTarget.js.map +1 -0
- package/lib/raster/IAutoMovieSceneRaster.d.ts +52 -0
- package/lib/raster/IAutoMovieSceneRaster.js +2 -0
- package/lib/raster/IAutoMovieSceneRaster.js.map +1 -0
- package/lib/raster/IRasterizeAutoMovieSceneProps.d.ts +28 -0
- package/lib/raster/IRasterizeAutoMovieSceneProps.js +2 -0
- package/lib/raster/IRasterizeAutoMovieSceneProps.js.map +1 -0
- package/lib/raster/encodeAutoMovieRasterPng.d.ts +17 -0
- package/lib/raster/encodeAutoMovieRasterPng.js +71 -0
- package/lib/raster/encodeAutoMovieRasterPng.js.map +1 -0
- package/lib/raster/index.d.ts +8 -0
- package/lib/raster/index.js +9 -0
- package/lib/raster/index.js.map +1 -0
- package/lib/raster/rasterizeAutoMovieScene.d.ts +33 -0
- package/lib/raster/rasterizeAutoMovieScene.js +409 -0
- package/lib/raster/rasterizeAutoMovieScene.js.map +1 -0
- package/lib/raster/stampAutoMovieRasterLabel.d.ts +19 -0
- package/lib/raster/stampAutoMovieRasterLabel.js +88 -0
- package/lib/raster/stampAutoMovieRasterLabel.js.map +1 -0
- package/package.json +3 -3
- package/src/AutoMoviePlayer.ts +1 -1
- package/src/applyPose.ts +1 -1
- package/src/index.ts +1 -0
- package/src/raster/AutoMovieRasterLighting.ts +221 -0
- package/src/raster/AutoMovieRasterSheet.ts +175 -0
- package/src/raster/AutoMovieRasterTarget.ts +282 -0
- package/src/raster/IAutoMovieSceneRaster.ts +62 -0
- package/src/raster/IRasterizeAutoMovieSceneProps.ts +34 -0
- package/src/raster/encodeAutoMovieRasterPng.ts +77 -0
- package/src/raster/index.ts +8 -0
- package/src/raster/rasterizeAutoMovieScene.ts +594 -0
- package/src/raster/stampAutoMovieRasterLabel.ts +120 -0
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The colour and depth buffers one Node frame is drawn into, with the
|
|
3
|
+
* primitive fills `rasterizeAutoMovieScene` needs: depth-tested triangles,
|
|
4
|
+
* lines and points in screen pixels, and conversion to sRGB bytes.
|
|
5
|
+
*
|
|
6
|
+
* Colours are linear RGB floats, the working space three.js materials and
|
|
7
|
+
* lights use; depth is normalized device depth in [-1, 1], smaller nearer.
|
|
8
|
+
* Screen coordinates put pixel centres at half-integers from the top-left.
|
|
9
|
+
*
|
|
10
|
+
* @evidence contracts/development/common.md#meaningful-documentation The comment states the colour space, depth convention and pixel-centre convention every method relies on; each method states its inputs and effect.
|
|
11
|
+
* @evidence contracts/development/design.md#principled-representation Linear float colour keeps lighting sums and supersample averaging exact before one sRGB conversion; a float depth buffer resolves visibility per pixel independent of submission order.
|
|
12
|
+
* @evidence contracts/development/design.md#minimal-and-owned-surface The target owns its two buffers and the fills that write them; traversal, shading and encoding stay with their callers.
|
|
13
|
+
* @evidence contracts/development/design.md#prohibited-design-shortcuts No method knows a scene, material or film; every fill takes plain coordinates and a colour.
|
|
14
|
+
*/
|
|
15
|
+
export declare class AutoMovieRasterTarget {
|
|
16
|
+
/** Linear RGB, three floats per pixel, row-major from the top-left. */
|
|
17
|
+
readonly color: Float32Array;
|
|
18
|
+
/** Normalized device depth per pixel; `Infinity` where nothing was drawn. */
|
|
19
|
+
readonly depth: Float32Array;
|
|
20
|
+
/** Width in pixels. */
|
|
21
|
+
readonly width: number;
|
|
22
|
+
/** Height in pixels. */
|
|
23
|
+
readonly height: number;
|
|
24
|
+
/**
|
|
25
|
+
* Allocate a target filled with one background colour.
|
|
26
|
+
*
|
|
27
|
+
* @param width Width in pixels.
|
|
28
|
+
* @param height Height in pixels.
|
|
29
|
+
* @param background Linear RGB background.
|
|
30
|
+
*/
|
|
31
|
+
constructor(width: number, height: number, background: readonly [number, number, number]);
|
|
32
|
+
/**
|
|
33
|
+
* Fill a screen triangle with one colour, depth-tested per pixel centre.
|
|
34
|
+
*
|
|
35
|
+
* `alpha` below one blends over the current colour; `write` false keeps the
|
|
36
|
+
* depth buffer unchanged, as transparent surfaces do in the Viewer.
|
|
37
|
+
*
|
|
38
|
+
* @evidence contracts/development/common.md#meaningful-documentation States the coverage rule, the depth test and how alpha and depth writes behave.
|
|
39
|
+
* @evidence contracts/development/implementation.md#principled-implementation Barycentric edge functions normalized by the signed area cover pixel centres for either winding, and depth interpolates linearly in screen space because normalized device depth is affine there.
|
|
40
|
+
* @evidence contracts/development/implementation.md#clear-and-simple-structure One loop over the clamped bounding box tests coverage, depth range and the buffer in that order.
|
|
41
|
+
* @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts Degenerate triangles return without drawing instead of being nudged; depth outside the clip range is rejected rather than clamped.
|
|
42
|
+
* @evidence contracts/development/implementation.md#efficient-algorithms Work is linear in the clamped bounding box area; edge coefficients are computed once per triangle.
|
|
43
|
+
* @evidence contracts/development/implementation.md#reuse-equivalent-work Coefficients shared by every pixel are hoisted out of the loop.
|
|
44
|
+
* @evidence contracts/development/implementation.md#bound-retention-and-release-resources No allocation; writes go into the target's existing buffers.
|
|
45
|
+
*/
|
|
46
|
+
triangle(x0: number, y0: number, z0: number, x1: number, y1: number, z1: number, x2: number, y2: number, z2: number, rgb: readonly [number, number, number], alpha: number, write: boolean): boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Draw a one-pixel line between two screen points, interpolating depth and
|
|
49
|
+
* testing it unless `test` is false.
|
|
50
|
+
*
|
|
51
|
+
* @evidence contracts/development/common.md#meaningful-documentation States the width, the depth interpolation and the optional depth test.
|
|
52
|
+
* @evidence contracts/development/implementation.md#principled-implementation A DDA over the longer axis visits one pixel per step, so the line has no gaps; depth interpolates with the same parameter.
|
|
53
|
+
* @evidence contracts/development/implementation.md#clear-and-simple-structure One loop; per-pixel writes go through the shared point fill.
|
|
54
|
+
* @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts Off-raster pixels are skipped individually rather than clipping the whole line away.
|
|
55
|
+
* @evidence contracts/development/implementation.md#efficient-algorithms Linear in the line's pixel length.
|
|
56
|
+
* @evidence contracts/development/implementation.md#reuse-equivalent-work Reuses the point fill for the depth test and write.
|
|
57
|
+
* @evidence contracts/development/implementation.md#bound-retention-and-release-resources No allocation.
|
|
58
|
+
*/
|
|
59
|
+
line(x0: number, y0: number, z0: number, x1: number, y1: number, z1: number, rgb: readonly [number, number, number], test: boolean): void;
|
|
60
|
+
/**
|
|
61
|
+
* Fill the square of pixels within `radius` of a screen point at one depth.
|
|
62
|
+
*
|
|
63
|
+
* @evidence contracts/development/common.md#meaningful-documentation States the covered square and the depth behaviour.
|
|
64
|
+
* @evidence contracts/development/implementation.md#principled-implementation Each covered pixel takes the same depth test and write as a surface, so points and lines hide behind nearer surfaces.
|
|
65
|
+
* @evidence contracts/development/implementation.md#clear-and-simple-structure One nested loop over the clamped square.
|
|
66
|
+
* @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts Depth outside the clip range is rejected, not clamped.
|
|
67
|
+
* @evidence contracts/development/implementation.md#efficient-algorithms Constant work for the small radii used.
|
|
68
|
+
* @evidence contracts/development/implementation.md#reuse-equivalent-work Lines call it per step instead of repeating the test.
|
|
69
|
+
* @evidence contracts/development/implementation.md#bound-retention-and-release-resources No allocation.
|
|
70
|
+
*/
|
|
71
|
+
point(x: number, y: number, z: number, radius: number, rgb: readonly [number, number, number], test: boolean): void;
|
|
72
|
+
/**
|
|
73
|
+
* Convert to opaque sRGB bytes, averaging `factor` × `factor` blocks when
|
|
74
|
+
* the target was drawn supersampled.
|
|
75
|
+
*
|
|
76
|
+
* @evidence contracts/development/common.md#meaningful-documentation States the transfer function, the block averaging and the output size.
|
|
77
|
+
* @evidence contracts/development/implementation.md#principled-implementation Blocks average in linear light before the sRGB transfer, which is the order that keeps antialiased edges at the right brightness.
|
|
78
|
+
* @evidence contracts/development/implementation.md#clear-and-simple-structure One pass over output pixels, one over each block.
|
|
79
|
+
* @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts A size that the factor does not divide throws instead of cropping.
|
|
80
|
+
* @evidence contracts/development/implementation.md#efficient-algorithms Linear in the target's pixel count; the transfer function is a 4096-entry table.
|
|
81
|
+
* @evidence contracts/development/implementation.md#reuse-equivalent-work The transfer table is built once per process.
|
|
82
|
+
* @evidence contracts/development/implementation.md#bound-retention-and-release-resources Allocates only the returned bytes.
|
|
83
|
+
*/
|
|
84
|
+
toSrgb(factor: number): Uint8ClampedArray;
|
|
85
|
+
/** Mix a colour over one pixel with the given opacity. */
|
|
86
|
+
private blend;
|
|
87
|
+
}
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The colour and depth buffers one Node frame is drawn into, with the
|
|
3
|
+
* primitive fills `rasterizeAutoMovieScene` needs: depth-tested triangles,
|
|
4
|
+
* lines and points in screen pixels, and conversion to sRGB bytes.
|
|
5
|
+
*
|
|
6
|
+
* Colours are linear RGB floats, the working space three.js materials and
|
|
7
|
+
* lights use; depth is normalized device depth in [-1, 1], smaller nearer.
|
|
8
|
+
* Screen coordinates put pixel centres at half-integers from the top-left.
|
|
9
|
+
*
|
|
10
|
+
* @evidence contracts/development/common.md#meaningful-documentation The comment states the colour space, depth convention and pixel-centre convention every method relies on; each method states its inputs and effect.
|
|
11
|
+
* @evidence contracts/development/design.md#principled-representation Linear float colour keeps lighting sums and supersample averaging exact before one sRGB conversion; a float depth buffer resolves visibility per pixel independent of submission order.
|
|
12
|
+
* @evidence contracts/development/design.md#minimal-and-owned-surface The target owns its two buffers and the fills that write them; traversal, shading and encoding stay with their callers.
|
|
13
|
+
* @evidence contracts/development/design.md#prohibited-design-shortcuts No method knows a scene, material or film; every fill takes plain coordinates and a colour.
|
|
14
|
+
*/
|
|
15
|
+
export class AutoMovieRasterTarget {
|
|
16
|
+
/** Linear RGB, three floats per pixel, row-major from the top-left. */
|
|
17
|
+
color;
|
|
18
|
+
/** Normalized device depth per pixel; `Infinity` where nothing was drawn. */
|
|
19
|
+
depth;
|
|
20
|
+
/** Width in pixels. */
|
|
21
|
+
width;
|
|
22
|
+
/** Height in pixels. */
|
|
23
|
+
height;
|
|
24
|
+
/**
|
|
25
|
+
* Allocate a target filled with one background colour.
|
|
26
|
+
*
|
|
27
|
+
* @param width Width in pixels.
|
|
28
|
+
* @param height Height in pixels.
|
|
29
|
+
* @param background Linear RGB background.
|
|
30
|
+
*/
|
|
31
|
+
constructor(width, height, background) {
|
|
32
|
+
this.width = width;
|
|
33
|
+
this.height = height;
|
|
34
|
+
this.color = new Float32Array(width * height * 3);
|
|
35
|
+
this.depth = new Float32Array(width * height).fill(Infinity);
|
|
36
|
+
for (let index = 0; index < width * height; index++)
|
|
37
|
+
this.color.set(background, index * 3);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Fill a screen triangle with one colour, depth-tested per pixel centre.
|
|
41
|
+
*
|
|
42
|
+
* `alpha` below one blends over the current colour; `write` false keeps the
|
|
43
|
+
* depth buffer unchanged, as transparent surfaces do in the Viewer.
|
|
44
|
+
*
|
|
45
|
+
* @evidence contracts/development/common.md#meaningful-documentation States the coverage rule, the depth test and how alpha and depth writes behave.
|
|
46
|
+
* @evidence contracts/development/implementation.md#principled-implementation Barycentric edge functions normalized by the signed area cover pixel centres for either winding, and depth interpolates linearly in screen space because normalized device depth is affine there.
|
|
47
|
+
* @evidence contracts/development/implementation.md#clear-and-simple-structure One loop over the clamped bounding box tests coverage, depth range and the buffer in that order.
|
|
48
|
+
* @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts Degenerate triangles return without drawing instead of being nudged; depth outside the clip range is rejected rather than clamped.
|
|
49
|
+
* @evidence contracts/development/implementation.md#efficient-algorithms Work is linear in the clamped bounding box area; edge coefficients are computed once per triangle.
|
|
50
|
+
* @evidence contracts/development/implementation.md#reuse-equivalent-work Coefficients shared by every pixel are hoisted out of the loop.
|
|
51
|
+
* @evidence contracts/development/implementation.md#bound-retention-and-release-resources No allocation; writes go into the target's existing buffers.
|
|
52
|
+
*/
|
|
53
|
+
triangle(x0, y0, z0, x1, y1, z1, x2, y2, z2, rgb, alpha, write) {
|
|
54
|
+
const area = (x1 - x0) * (y2 - y0) - (x2 - x0) * (y1 - y0);
|
|
55
|
+
if (!(Math.abs(area) > 1e-12))
|
|
56
|
+
return false;
|
|
57
|
+
const minX = Math.max(0, Math.floor(Math.min(x0, x1, x2)));
|
|
58
|
+
const maxX = Math.min(this.width - 1, Math.ceil(Math.max(x0, x1, x2)));
|
|
59
|
+
const minY = Math.max(0, Math.floor(Math.min(y0, y1, y2)));
|
|
60
|
+
const maxY = Math.min(this.height - 1, Math.ceil(Math.max(y0, y1, y2)));
|
|
61
|
+
if (minX > maxX || minY > maxY)
|
|
62
|
+
return false;
|
|
63
|
+
// Edge functions of the three sides, divided by the area so each weight
|
|
64
|
+
// is the barycentric coordinate of the opposite vertex.
|
|
65
|
+
const inverse = 1 / area;
|
|
66
|
+
const a0 = (y1 - y2) * inverse;
|
|
67
|
+
const b0 = (x2 - x1) * inverse;
|
|
68
|
+
const a1 = (y2 - y0) * inverse;
|
|
69
|
+
const b1 = (x0 - x2) * inverse;
|
|
70
|
+
const a2 = (y0 - y1) * inverse;
|
|
71
|
+
const b2 = (x1 - x0) * inverse;
|
|
72
|
+
let drawn = false;
|
|
73
|
+
for (let y = minY; y <= maxY; y++) {
|
|
74
|
+
const py = y + 0.5;
|
|
75
|
+
for (let x = minX; x <= maxX; x++) {
|
|
76
|
+
const px = x + 0.5;
|
|
77
|
+
const w0 = a0 * (px - x1) + b0 * (py - y1);
|
|
78
|
+
if (w0 < 0)
|
|
79
|
+
continue;
|
|
80
|
+
const w1 = a1 * (px - x2) + b1 * (py - y2);
|
|
81
|
+
if (w1 < 0)
|
|
82
|
+
continue;
|
|
83
|
+
const w2 = a2 * (px - x0) + b2 * (py - y0);
|
|
84
|
+
if (w2 < 0)
|
|
85
|
+
continue;
|
|
86
|
+
const z = w0 * z0 + w1 * z1 + w2 * z2;
|
|
87
|
+
if (z < -1 || z > 1)
|
|
88
|
+
continue;
|
|
89
|
+
const index = y * this.width + x;
|
|
90
|
+
if (z >= this.depth[index])
|
|
91
|
+
continue;
|
|
92
|
+
if (write)
|
|
93
|
+
this.depth[index] = z;
|
|
94
|
+
this.blend(index, rgb, alpha);
|
|
95
|
+
drawn = true;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return drawn;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Draw a one-pixel line between two screen points, interpolating depth and
|
|
102
|
+
* testing it unless `test` is false.
|
|
103
|
+
*
|
|
104
|
+
* @evidence contracts/development/common.md#meaningful-documentation States the width, the depth interpolation and the optional depth test.
|
|
105
|
+
* @evidence contracts/development/implementation.md#principled-implementation A DDA over the longer axis visits one pixel per step, so the line has no gaps; depth interpolates with the same parameter.
|
|
106
|
+
* @evidence contracts/development/implementation.md#clear-and-simple-structure One loop; per-pixel writes go through the shared point fill.
|
|
107
|
+
* @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts Off-raster pixels are skipped individually rather than clipping the whole line away.
|
|
108
|
+
* @evidence contracts/development/implementation.md#efficient-algorithms Linear in the line's pixel length.
|
|
109
|
+
* @evidence contracts/development/implementation.md#reuse-equivalent-work Reuses the point fill for the depth test and write.
|
|
110
|
+
* @evidence contracts/development/implementation.md#bound-retention-and-release-resources No allocation.
|
|
111
|
+
*/
|
|
112
|
+
line(x0, y0, z0, x1, y1, z1, rgb, test) {
|
|
113
|
+
const steps = Math.ceil(Math.max(Math.abs(x1 - x0), Math.abs(y1 - y0)));
|
|
114
|
+
for (let step = 0; step <= steps; step++) {
|
|
115
|
+
const t = steps === 0 ? 0 : step / steps;
|
|
116
|
+
this.point(x0 + (x1 - x0) * t, y0 + (y1 - y0) * t, z0 + (z1 - z0) * t, 0, rgb, test);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Fill the square of pixels within `radius` of a screen point at one depth.
|
|
121
|
+
*
|
|
122
|
+
* @evidence contracts/development/common.md#meaningful-documentation States the covered square and the depth behaviour.
|
|
123
|
+
* @evidence contracts/development/implementation.md#principled-implementation Each covered pixel takes the same depth test and write as a surface, so points and lines hide behind nearer surfaces.
|
|
124
|
+
* @evidence contracts/development/implementation.md#clear-and-simple-structure One nested loop over the clamped square.
|
|
125
|
+
* @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts Depth outside the clip range is rejected, not clamped.
|
|
126
|
+
* @evidence contracts/development/implementation.md#efficient-algorithms Constant work for the small radii used.
|
|
127
|
+
* @evidence contracts/development/implementation.md#reuse-equivalent-work Lines call it per step instead of repeating the test.
|
|
128
|
+
* @evidence contracts/development/implementation.md#bound-retention-and-release-resources No allocation.
|
|
129
|
+
*/
|
|
130
|
+
point(x, y, z, radius, rgb, test) {
|
|
131
|
+
if (z < -1 || z > 1)
|
|
132
|
+
return;
|
|
133
|
+
const cx = Math.floor(x);
|
|
134
|
+
const cy = Math.floor(y);
|
|
135
|
+
for (let py = cy - radius; py <= cy + radius; py++) {
|
|
136
|
+
if (py < 0 || py >= this.height)
|
|
137
|
+
continue;
|
|
138
|
+
for (let px = cx - radius; px <= cx + radius; px++) {
|
|
139
|
+
if (px < 0 || px >= this.width)
|
|
140
|
+
continue;
|
|
141
|
+
const index = py * this.width + px;
|
|
142
|
+
if (test && z >= this.depth[index])
|
|
143
|
+
continue;
|
|
144
|
+
if (test)
|
|
145
|
+
this.depth[index] = z;
|
|
146
|
+
this.blend(index, rgb, 1);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Convert to opaque sRGB bytes, averaging `factor` × `factor` blocks when
|
|
152
|
+
* the target was drawn supersampled.
|
|
153
|
+
*
|
|
154
|
+
* @evidence contracts/development/common.md#meaningful-documentation States the transfer function, the block averaging and the output size.
|
|
155
|
+
* @evidence contracts/development/implementation.md#principled-implementation Blocks average in linear light before the sRGB transfer, which is the order that keeps antialiased edges at the right brightness.
|
|
156
|
+
* @evidence contracts/development/implementation.md#clear-and-simple-structure One pass over output pixels, one over each block.
|
|
157
|
+
* @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts A size that the factor does not divide throws instead of cropping.
|
|
158
|
+
* @evidence contracts/development/implementation.md#efficient-algorithms Linear in the target's pixel count; the transfer function is a 4096-entry table.
|
|
159
|
+
* @evidence contracts/development/implementation.md#reuse-equivalent-work The transfer table is built once per process.
|
|
160
|
+
* @evidence contracts/development/implementation.md#bound-retention-and-release-resources Allocates only the returned bytes.
|
|
161
|
+
*/
|
|
162
|
+
toSrgb(factor) {
|
|
163
|
+
if (this.width % factor !== 0 || this.height % factor !== 0)
|
|
164
|
+
throw new Error("Supersampled raster size is not a multiple of its factor");
|
|
165
|
+
const width = this.width / factor;
|
|
166
|
+
const height = this.height / factor;
|
|
167
|
+
const out = new Uint8ClampedArray(width * height * 4);
|
|
168
|
+
const table = srgbTable();
|
|
169
|
+
const samples = factor * factor;
|
|
170
|
+
for (let y = 0; y < height; y++)
|
|
171
|
+
for (let x = 0; x < width; x++) {
|
|
172
|
+
let r = 0;
|
|
173
|
+
let g = 0;
|
|
174
|
+
let b = 0;
|
|
175
|
+
for (let sy = 0; sy < factor; sy++)
|
|
176
|
+
for (let sx = 0; sx < factor; sx++) {
|
|
177
|
+
const source = ((y * factor + sy) * this.width + x * factor + sx) * 3;
|
|
178
|
+
r += this.color[source];
|
|
179
|
+
g += this.color[source + 1];
|
|
180
|
+
b += this.color[source + 2];
|
|
181
|
+
}
|
|
182
|
+
const target = (y * width + x) * 4;
|
|
183
|
+
out[target] = table[encode(r / samples)];
|
|
184
|
+
out[target + 1] = table[encode(g / samples)];
|
|
185
|
+
out[target + 2] = table[encode(b / samples)];
|
|
186
|
+
out[target + 3] = 255;
|
|
187
|
+
}
|
|
188
|
+
return out;
|
|
189
|
+
}
|
|
190
|
+
/** Mix a colour over one pixel with the given opacity. */
|
|
191
|
+
blend(index, rgb, alpha) {
|
|
192
|
+
const offset = index * 3;
|
|
193
|
+
if (alpha >= 1) {
|
|
194
|
+
this.color[offset] = rgb[0];
|
|
195
|
+
this.color[offset + 1] = rgb[1];
|
|
196
|
+
this.color[offset + 2] = rgb[2];
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
const keep = 1 - alpha;
|
|
200
|
+
this.color[offset] = this.color[offset] * keep + rgb[0] * alpha;
|
|
201
|
+
this.color[offset + 1] = this.color[offset + 1] * keep + rgb[1] * alpha;
|
|
202
|
+
this.color[offset + 2] = this.color[offset + 2] * keep + rgb[2] * alpha;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
/** Table index of a linear value clamped to [0, 1]. */
|
|
206
|
+
function encode(value) {
|
|
207
|
+
return Math.round(Math.min(1, Math.max(0, value)) * (TABLE_SIZE - 1));
|
|
208
|
+
}
|
|
209
|
+
/** Entries of the linear-to-sRGB table. */
|
|
210
|
+
const TABLE_SIZE = 4096;
|
|
211
|
+
/** The lazily built linear-to-sRGB byte table. */
|
|
212
|
+
let table;
|
|
213
|
+
/** The linear-to-sRGB byte table, built on first use. */
|
|
214
|
+
function srgbTable() {
|
|
215
|
+
if (table !== undefined)
|
|
216
|
+
return table;
|
|
217
|
+
table = new Uint8ClampedArray(TABLE_SIZE);
|
|
218
|
+
for (let index = 0; index < TABLE_SIZE; index++) {
|
|
219
|
+
const linear = index / (TABLE_SIZE - 1);
|
|
220
|
+
const encoded = linear <= 0.0031308
|
|
221
|
+
? 12.92 * linear
|
|
222
|
+
: 1.055 * Math.pow(linear, 1 / 2.4) - 0.055;
|
|
223
|
+
table[index] = Math.round(encoded * 255);
|
|
224
|
+
}
|
|
225
|
+
return table;
|
|
226
|
+
}
|
|
227
|
+
//# sourceMappingURL=AutoMovieRasterTarget.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AutoMovieRasterTarget.js","sourceRoot":"","sources":["../../src/raster/AutoMovieRasterTarget.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,MAAM,OAAO,qBAAqB;IAChC,uEAAuE;IACvD,KAAK,CAAe;IAEpC,6EAA6E;IAC7D,KAAK,CAAe;IAEpC,uBAAuB;IACP,KAAK,CAAS;IAE9B,wBAAwB;IACR,MAAM,CAAS;IAE/B;;;;;;OAMG;IACH,YACE,KAAa,EACb,MAAc,EACd,UAA6C;QAE7C,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,KAAK,GAAG,IAAI,YAAY,CAAC,KAAK,GAAG,MAAM,GAAG,CAAC,CAAC,CAAC;QAClD,IAAI,CAAC,KAAK,GAAG,IAAI,YAAY,CAAC,KAAK,GAAG,MAAM,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC7D,KAAK,IAAI,KAAK,GAAW,CAAC,EAAE,KAAK,GAAG,KAAK,GAAG,MAAM,EAAE,KAAK,EAAE;YACzD,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,UAAU,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC;IAC1C,CAAC;IAED;;;;;;;;;;;;;OAaG;IACI,QAAQ,CACb,EAAU,EACV,EAAU,EACV,E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;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One frame drawn in Node by `rasterizeAutoMovieScene`: its opaque sRGB
|
|
3
|
+
* pixels and a count of what was drawn and what could not be represented.
|
|
4
|
+
*
|
|
5
|
+
* The frame is a CPU diagnostic of geometry, pose, staging and framing, not a
|
|
6
|
+
* copy of the GPU Viewer's pixels: surfaces are flat shaded from their base
|
|
7
|
+
* colours under the scene's lights, without textures, shadows, fog or
|
|
8
|
+
* post-processing. `statistics.skipped` and `statistics.untextured` say what a
|
|
9
|
+
* reader should not expect to see.
|
|
10
|
+
*
|
|
11
|
+
* @evidence contracts/development/common.md#meaningful-documentation The comment says which call produces the frame, that it is a geometry and staging diagnostic rather than GPU parity, what the shading leaves out, and where the omissions are counted; each member states its unit and layout.
|
|
12
|
+
* @evidence contracts/development/design.md#principled-representation A frame is exactly what a PNG encoder and a reviewer need: integer raster size, row-major opaque RGBA bytes and counts; byte layout matches the encoder and the sheet writer without conversion.
|
|
13
|
+
* @evidence contracts/development/design.md#minimal-and-owned-surface Four members, all read by the encoder, label stamping or the capture manifest; the statistics shape lives in the companion namespace.
|
|
14
|
+
* @evidence contracts/development/design.md#prohibited-design-shortcuts No member names a particular film, figure or capture command.
|
|
15
|
+
*/
|
|
16
|
+
export interface IAutoMovieSceneRaster {
|
|
17
|
+
/** Raster width in pixels. */
|
|
18
|
+
width: number;
|
|
19
|
+
/** Raster height in pixels. */
|
|
20
|
+
height: number;
|
|
21
|
+
/** Opaque sRGB RGBA bytes, row-major from the top-left corner. */
|
|
22
|
+
pixels: Uint8ClampedArray;
|
|
23
|
+
/** What the frame drew and what it replaced or left out. */
|
|
24
|
+
statistics: IAutoMovieSceneRaster.IStatistics;
|
|
25
|
+
}
|
|
26
|
+
/** Companion types of {@link IAutoMovieSceneRaster}. */
|
|
27
|
+
export declare namespace IAutoMovieSceneRaster {
|
|
28
|
+
/**
|
|
29
|
+
* Counts of one frame's drawing work.
|
|
30
|
+
*
|
|
31
|
+
* @evidence contracts/development/common.md#meaningful-documentation Each count states what it counts, so a reader can tell an empty frame from an unrepresentable one.
|
|
32
|
+
* @evidence contracts/development/design.md#principled-representation Plain non-negative counts keyed by stable three.js type names serialize directly into a capture manifest.
|
|
33
|
+
* @evidence contracts/development/design.md#minimal-and-owned-surface Only the counts a reviewer needs to judge coverage: drawn primitives, skipped object types, approximated materials.
|
|
34
|
+
* @evidence contracts/development/design.md#prohibited-design-shortcuts No count is specific to one production or object name.
|
|
35
|
+
*/
|
|
36
|
+
interface IStatistics {
|
|
37
|
+
/** Visible meshes submitted, counting each instance of an instanced mesh. */
|
|
38
|
+
meshes: number;
|
|
39
|
+
/** Triangles that reached the raster after culling and clipping. */
|
|
40
|
+
triangles: number;
|
|
41
|
+
/** Line segments drawn from `Line`, `LineSegments` and `LineLoop` objects. */
|
|
42
|
+
lines: number;
|
|
43
|
+
/** Points drawn from `Points` objects. */
|
|
44
|
+
points: number;
|
|
45
|
+
/** Visible objects of a type this rasterizer does not draw, by three.js type name. */
|
|
46
|
+
skipped: Record<string, number>;
|
|
47
|
+
/** Submitted materials whose texture map was replaced by the base colour. */
|
|
48
|
+
untextured: number;
|
|
49
|
+
/** Submitted shader materials drawn with a neutral clay colour. */
|
|
50
|
+
approximated: number;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IAutoMovieSceneRaster.js","sourceRoot":"","sources":["../../src/raster/IAutoMovieSceneRaster.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type * as THREE from "three";
|
|
2
|
+
/**
|
|
3
|
+
* Input of `rasterizeAutoMovieScene`: the scene graph and camera to draw and
|
|
4
|
+
* the raster to draw them into.
|
|
5
|
+
*
|
|
6
|
+
* The camera is read as it is: callers that want the raster's aspect set
|
|
7
|
+
* `PerspectiveCamera.aspect` and update its projection first, as the Viewer
|
|
8
|
+
* does when it sizes its canvas.
|
|
9
|
+
*
|
|
10
|
+
* @evidence contracts/development/common.md#meaningful-documentation The comment states what is drawn and who owns the camera's aspect; each member states its unit, range and default.
|
|
11
|
+
* @evidence contracts/development/design.md#principled-representation The scene and camera are the same three.js objects the Viewer renders, so a film's own `seek` places them once for either drawing path.
|
|
12
|
+
* @evidence contracts/development/design.md#minimal-and-owned-surface Raster size, the two objects, an optional fallback background and an optional supersampling factor; lighting and materials come from the scene itself.
|
|
13
|
+
* @evidence contracts/development/design.md#prohibited-design-shortcuts No member selects a film, figure or capture command.
|
|
14
|
+
*/
|
|
15
|
+
export interface IRasterizeAutoMovieSceneProps {
|
|
16
|
+
/** Scene graph to draw; its visible meshes, lines, points and lights are read. */
|
|
17
|
+
scene: THREE.Object3D;
|
|
18
|
+
/** Perspective or orthographic camera whose projection and world matrix are used as they are. */
|
|
19
|
+
camera: THREE.Camera;
|
|
20
|
+
/** Output width in pixels, a positive integer. */
|
|
21
|
+
width: number;
|
|
22
|
+
/** Output height in pixels, a positive integer. */
|
|
23
|
+
height: number;
|
|
24
|
+
/** sRGB hex colour behind everything when the scene has no colour background; default `0x202020`. */
|
|
25
|
+
background?: number;
|
|
26
|
+
/** Samples per pixel along each axis, an integer from 1 to 4; default 1. */
|
|
27
|
+
supersample?: number;
|
|
28
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IRasterizeAutoMovieSceneProps.js","sourceRoot":"","sources":["../../src/raster/IRasterizeAutoMovieSceneProps.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { IAutoMovieSceneRaster } from "./IAutoMovieSceneRaster.js";
|
|
2
|
+
/**
|
|
3
|
+
* Encode a Node-drawn frame as a lossless 8-bit RGB PNG.
|
|
4
|
+
*
|
|
5
|
+
* The frame is opaque, so alpha is dropped; rows use filter type 0 and one
|
|
6
|
+
* zlib stream, which every PNG reader, including `pngjs` and the frame-sheet
|
|
7
|
+
* writer, decodes.
|
|
8
|
+
*
|
|
9
|
+
* @evidence contracts/development/common.md#meaningful-documentation States the format, the dropped alpha, the row filter and who can read the result.
|
|
10
|
+
* @evidence contracts/development/implementation.md#principled-implementation The chunk layout, big-endian lengths and CRC-32 over type and data follow the PNG specification; Node's zlib supplies the deflate stream the IDAT chunk requires.
|
|
11
|
+
* @evidence contracts/development/implementation.md#clear-and-simple-structure Rows are packed once, compressed once and wrapped in the three required chunks.
|
|
12
|
+
* @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts A pixel buffer whose length disagrees with the size throws instead of writing a truncated image.
|
|
13
|
+
* @evidence contracts/development/implementation.md#efficient-algorithms Linear in the pixel count; the CRC table is built once per process.
|
|
14
|
+
* @evidence contracts/development/implementation.md#reuse-equivalent-work The CRC table is shared by every chunk and call.
|
|
15
|
+
* @evidence contracts/development/implementation.md#bound-retention-and-release-resources Allocates the packed rows and the returned buffer; nothing is retained.
|
|
16
|
+
*/
|
|
17
|
+
export declare function encodeAutoMovieRasterPng(raster: IAutoMovieSceneRaster): Buffer;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// A namespace import reads `deflateSync` only when encoding, so a browser
|
|
2
|
+
// bundle that reaches this module through a package index still loads.
|
|
3
|
+
import * as zlib from "node:zlib";
|
|
4
|
+
/**
|
|
5
|
+
* Encode a Node-drawn frame as a lossless 8-bit RGB PNG.
|
|
6
|
+
*
|
|
7
|
+
* The frame is opaque, so alpha is dropped; rows use filter type 0 and one
|
|
8
|
+
* zlib stream, which every PNG reader, including `pngjs` and the frame-sheet
|
|
9
|
+
* writer, decodes.
|
|
10
|
+
*
|
|
11
|
+
* @evidence contracts/development/common.md#meaningful-documentation States the format, the dropped alpha, the row filter and who can read the result.
|
|
12
|
+
* @evidence contracts/development/implementation.md#principled-implementation The chunk layout, big-endian lengths and CRC-32 over type and data follow the PNG specification; Node's zlib supplies the deflate stream the IDAT chunk requires.
|
|
13
|
+
* @evidence contracts/development/implementation.md#clear-and-simple-structure Rows are packed once, compressed once and wrapped in the three required chunks.
|
|
14
|
+
* @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts A pixel buffer whose length disagrees with the size throws instead of writing a truncated image.
|
|
15
|
+
* @evidence contracts/development/implementation.md#efficient-algorithms Linear in the pixel count; the CRC table is built once per process.
|
|
16
|
+
* @evidence contracts/development/implementation.md#reuse-equivalent-work The CRC table is shared by every chunk and call.
|
|
17
|
+
* @evidence contracts/development/implementation.md#bound-retention-and-release-resources Allocates the packed rows and the returned buffer; nothing is retained.
|
|
18
|
+
*/
|
|
19
|
+
export function encodeAutoMovieRasterPng(raster) {
|
|
20
|
+
const { width, height, pixels } = raster;
|
|
21
|
+
if (pixels.length !== width * height * 4)
|
|
22
|
+
throw new Error("Raster pixels do not match its size");
|
|
23
|
+
const stride = width * 3 + 1;
|
|
24
|
+
const rows = Buffer.alloc(stride * height);
|
|
25
|
+
for (let y = 0; y < height; y++)
|
|
26
|
+
for (let x = 0; x < width; x++) {
|
|
27
|
+
const from = (y * width + x) * 4;
|
|
28
|
+
const to = y * stride + 1 + x * 3;
|
|
29
|
+
rows[to] = pixels[from];
|
|
30
|
+
rows[to + 1] = pixels[from + 1];
|
|
31
|
+
rows[to + 2] = pixels[from + 2];
|
|
32
|
+
}
|
|
33
|
+
const header = Buffer.alloc(13);
|
|
34
|
+
header.writeUInt32BE(width, 0);
|
|
35
|
+
header.writeUInt32BE(height, 4);
|
|
36
|
+
header.set([8, 2, 0, 0, 0], 8);
|
|
37
|
+
return Buffer.concat([
|
|
38
|
+
Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]),
|
|
39
|
+
chunk("IHDR", header),
|
|
40
|
+
chunk("IDAT", zlib.deflateSync(rows, { level: 6 })),
|
|
41
|
+
chunk("IEND", Buffer.alloc(0)),
|
|
42
|
+
]);
|
|
43
|
+
}
|
|
44
|
+
/** One PNG chunk: length, type, data and CRC-32 of type and data. */
|
|
45
|
+
function chunk(type, data) {
|
|
46
|
+
const out = Buffer.alloc(12 + data.length);
|
|
47
|
+
out.writeUInt32BE(data.length, 0);
|
|
48
|
+
out.write(type, 4, "ascii");
|
|
49
|
+
data.copy(out, 8);
|
|
50
|
+
out.writeUInt32BE(crc32(out.subarray(4, 8 + data.length)), 8 + data.length);
|
|
51
|
+
return out;
|
|
52
|
+
}
|
|
53
|
+
/** The CRC-32 lookup table, built on first use. */
|
|
54
|
+
let table;
|
|
55
|
+
/** CRC-32 (IEEE) of a byte range. */
|
|
56
|
+
function crc32(bytes) {
|
|
57
|
+
if (table === undefined) {
|
|
58
|
+
table = new Uint32Array(256);
|
|
59
|
+
for (let n = 0; n < 256; n++) {
|
|
60
|
+
let c = n;
|
|
61
|
+
for (let k = 0; k < 8; k++)
|
|
62
|
+
c = c & 1 ? 0xedb88320 ^ (c >>> 1) : c >>> 1;
|
|
63
|
+
table[n] = c >>> 0;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
let crc = 0xffffffff;
|
|
67
|
+
for (const byte of bytes)
|
|
68
|
+
crc = table[(crc ^ byte) & 0xff] ^ (crc >>> 8);
|
|
69
|
+
return (crc ^ 0xffffffff) >>> 0;
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=encodeAutoMovieRasterPng.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encodeAutoMovieRasterPng.js","sourceRoot":"","sources":["../../src/raster/encodeAutoMovieRasterPng.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,uEAAuE;AACvE,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAIlC;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,wBAAwB,CACtC,MAA6B;IAE7B,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;IACzC,IAAI,MAAM,CAAC,MAAM,KAAK,KAAK,GAAG,MAAM,GAAG,CAAC;QACtC,MAAM,IAAI,KAA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,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;YAC/C,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACrB,CAAC;IACH,CAAC;IACD,IAAI,GAAG,GAAW,UAAU,CAAC;IAC7B,KAAK,MAAM,IAAI,IAAI,KAAK;QAAE,GAAG,GAAG,KAAK,CAAC,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,IAAI,CAAE,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC;IAC1E,OAAO,CAAC,GAAG,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC;AAClC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from "./AutoMovieRasterLighting.js";
|
|
2
|
+
export * from "./AutoMovieRasterSheet.js";
|
|
3
|
+
export * from "./AutoMovieRasterTarget.js";
|
|
4
|
+
export * from "./encodeAutoMovieRasterPng.js";
|
|
5
|
+
export * from "./IAutoMovieSceneRaster.js";
|
|
6
|
+
export * from "./IRasterizeAutoMovieSceneProps.js";
|
|
7
|
+
export * from "./rasterizeAutoMovieScene.js";
|
|
8
|
+
export * from "./stampAutoMovieRasterLabel.js";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from "./AutoMovieRasterLighting.js";
|
|
2
|
+
export * from "./AutoMovieRasterSheet.js";
|
|
3
|
+
export * from "./AutoMovieRasterTarget.js";
|
|
4
|
+
export * from "./encodeAutoMovieRasterPng.js";
|
|
5
|
+
export * from "./IAutoMovieSceneRaster.js";
|
|
6
|
+
export * from "./IRasterizeAutoMovieSceneProps.js";
|
|
7
|
+
export * from "./rasterizeAutoMovieScene.js";
|
|
8
|
+
export * from "./stampAutoMovieRasterLabel.js";
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/raster/index.ts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAC;AAC7C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,oCAAoC,CAAC;AACnD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,gCAAgC,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { IAutoMovieSceneRaster } from "./IAutoMovieSceneRaster.js";
|
|
2
|
+
import type { IRasterizeAutoMovieSceneProps } from "./IRasterizeAutoMovieSceneProps.js";
|
|
3
|
+
/**
|
|
4
|
+
* Draw a three.js scene through its camera on the CPU, in Node, with no
|
|
5
|
+
* browser or GPU: the inspection path for reading a film's poses, contacts,
|
|
6
|
+
* staging and framing frame by frame.
|
|
7
|
+
*
|
|
8
|
+
* Visible meshes (including skinned, morphed and instanced meshes) are drawn
|
|
9
|
+
* as flat-shaded triangles with a per-pixel depth buffer, honouring each
|
|
10
|
+
* material's side, visibility, opacity, vertex or instance colours and
|
|
11
|
+
* emissive colour; lit materials take the scene's lights through three.js's
|
|
12
|
+
* Lambert convention and `MeshBasicMaterial` is unlit. Lines are drawn one
|
|
13
|
+
* pixel wide; points are squares of their `PointsMaterial` size in output
|
|
14
|
+
* pixels, attenuated by distance as three.js does when `sizeAttenuation` is
|
|
15
|
+
* on; transparent surfaces are blended back to front after
|
|
16
|
+
* opaque ones, and the result is converted to sRGB. Textures, shadows, fog,
|
|
17
|
+
* sprites and post-processing are not drawn; the statistics count them.
|
|
18
|
+
*
|
|
19
|
+
* ```ts
|
|
20
|
+
* production.seek(12.5);
|
|
21
|
+
* const frame = rasterizeAutoMovieScene({ scene, camera, width: 720, height: 1280 });
|
|
22
|
+
* await writeFile("f.png", encodeAutoMovieRasterPng(frame));
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @evidence contracts/development/common.md#meaningful-documentation The comment states the purpose, every drawn object kind and material property honoured, the shading convention, the transparency order and what is left out and where it is counted.
|
|
26
|
+
* @evidence contracts/development/implementation.md#principled-implementation Vertices go through the camera's own projection and view matrices and are clipped against the near plane in clip space before division, so geometry behind the camera never wraps; skinned and morphed vertices come from three.js's own getVertexPosition, so poses match the Viewer's bones.
|
|
27
|
+
* @evidence contracts/development/implementation.md#clear-and-simple-structure Traversal submits primitives; the raster target owns buffers and fills, the lighting owns irradiance, and transparent triangles are queued and drawn after the opaque pass.
|
|
28
|
+
* @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts Invalid raster sizes and supersampling factors throw; unsupported objects and materials are counted rather than silently dropped or guessed.
|
|
29
|
+
* @evidence contracts/development/implementation.md#efficient-algorithms Each mesh's vertices are transformed once per instance and shared by its triangles; triangle fill cost is bounded by each triangle's clipped bounding box.
|
|
30
|
+
* @evidence contracts/development/implementation.md#reuse-equivalent-work Lights are flattened once per frame and scratch vectors are reused across triangles.
|
|
31
|
+
* @evidence contracts/development/implementation.md#bound-retention-and-release-resources The frame allocates its buffers and per-mesh vertex arrays and keeps only the returned bytes; the scene and camera are read, never retained or modified beyond three.js's own world-matrix update.
|
|
32
|
+
*/
|
|
33
|
+
export declare function rasterizeAutoMovieScene(props: IRasterizeAutoMovieSceneProps): IAutoMovieSceneRaster;
|