@zkmake/three-audit 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/LICENSE +21 -0
- package/README.md +116 -0
- package/dist/index.d.ts +209 -0
- package/dist/index.js +645 -0
- package/dist/index.js.map +1 -0
- package/package.json +62 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Zubin Khavarian
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
# @zkmake/three-audit
|
|
2
|
+
|
|
3
|
+
Checks for a three.js scene: what it costs and what's wrong with it. Triangle counts, the meshes and
|
|
4
|
+
geometries behind them, z-fighting, NaN geometry, black frames, and a ledger of every draw call in
|
|
5
|
+
one frame. Zero dependencies. The geometry checks need no renderer, so they run in a unit test as
|
|
6
|
+
well as the browser console.
|
|
7
|
+
|
|
8
|
+
```sh
|
|
9
|
+
bun add -d @zkmake/three-audit # or npm i -D / pnpm add -D
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## In a test
|
|
13
|
+
|
|
14
|
+
Build the object the way the app does and assert it's clean:
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
import { findBadGeometry, findZFighting } from "@zkmake/three-audit";
|
|
18
|
+
import { expect, test } from "vitest";
|
|
19
|
+
|
|
20
|
+
import { buildWindmill } from "../src/windmill.ts";
|
|
21
|
+
|
|
22
|
+
test("windmill has no z-fighting and no NaN geometry", () => {
|
|
23
|
+
const windmill = buildWindmill();
|
|
24
|
+
|
|
25
|
+
expect(findZFighting(windmill)).toEqual([]);
|
|
26
|
+
expect(findBadGeometry(windmill)).toEqual([]);
|
|
27
|
+
});
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
A failure lists each pair of meshes with faces in one plane, facing the same way, overlapping:
|
|
31
|
+
|
|
32
|
+
```
|
|
33
|
+
[{ a: "windmill/plinth [stone] @ (0, 0.1, 0)", b: "windmill/wall [plaster] @ (0, 0.5, 0)", triangles: 4 }]
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## In the console
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
import { installAuditHelpers } from "@zkmake/three-audit";
|
|
40
|
+
|
|
41
|
+
installAuditHelpers(scene, { renderer }); // returns a function that removes them
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
React Three Fiber:
|
|
45
|
+
|
|
46
|
+
```tsx
|
|
47
|
+
const { scene, gl } = useThree();
|
|
48
|
+
|
|
49
|
+
useLayoutEffect(() => installAuditHelpers(scene, { renderer: gl }), [scene, gl]);
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
| Global | Returns |
|
|
53
|
+
| --------------------- | ----------------------------------------------------------------------------------- |
|
|
54
|
+
| `tris()` | Triangles one pass draws: visible meshes, instances and batches counted, no culling |
|
|
55
|
+
| `meshes()` | Every visible mesh: triangles, instances, total, most first |
|
|
56
|
+
| `census()` | Geometries by triangles drawn, hidden meshes included |
|
|
57
|
+
| `audit()` | Meshes with NaN positions or normals, or zero-length normals |
|
|
58
|
+
| `zfight(gap?, self?)` | Pairs of meshes that z-fight |
|
|
59
|
+
| `report()` | All of the above in one JSON-safe object |
|
|
60
|
+
| `ledger()` | One frame's draw calls by object and pass, printed as tables (WebGL) |
|
|
61
|
+
| `blackFrames(10)` | Frames in the next 10 s that came out black (WebGL) |
|
|
62
|
+
|
|
63
|
+
From a headless browser: `agent-browser eval 'JSON.stringify(report())'`.
|
|
64
|
+
|
|
65
|
+
## The checks
|
|
66
|
+
|
|
67
|
+
### `findZFighting(root, options?)`
|
|
68
|
+
|
|
69
|
+
Triangles are bucketed by plane (normal and offset), then tested for overlap in their shared plane.
|
|
70
|
+
World space, so parent transforms count.
|
|
71
|
+
|
|
72
|
+
- `gap` (default `0.004`): how close two planes count as one, in world units. 4 mm at 1 unit = 1 m is
|
|
73
|
+
about what depth precision loses with a camera ~50 m out. Scale it with your units.
|
|
74
|
+
- `self`: also compare triangles within one mesh, for merged geometry.
|
|
75
|
+
- `tagged`: only meshes inside an object with `userData.studioObject` (or `tagKey`). Defaults to on
|
|
76
|
+
when anything under the root is tagged, so a studio's ground and props stay out.
|
|
77
|
+
- `skip(object)`: leave an object and its subtree out, e.g. a merged copy whose sources are still in
|
|
78
|
+
the scene: `skip: (o) => o.userData.bakedResult === true`.
|
|
79
|
+
|
|
80
|
+
Instanced and batched meshes are skipped: check their source parts as plain meshes.
|
|
81
|
+
|
|
82
|
+
Typical fixes: stand the smaller part 5 mm off, shorten it inside the larger one, or fit panels
|
|
83
|
+
between each other instead of over each other's ends.
|
|
84
|
+
|
|
85
|
+
### `findBadGeometry(root, options?)`
|
|
86
|
+
|
|
87
|
+
Vertices with a non-finite position or normal, and zero-length normals on triangles with area.
|
|
88
|
+
Either lights a pixel NaN, and bloom smears one NaN pixel into a black block.
|
|
89
|
+
|
|
90
|
+
### `countTriangles`, `listMeshes`, `geometryCensus`
|
|
91
|
+
|
|
92
|
+
Where a triangle budget goes. Name meshes and geometries (`mesh.name`, `geometry.name`) so the rows
|
|
93
|
+
say something. Draw ranges are respected; a shadow pass adds roughly as much again per light.
|
|
94
|
+
|
|
95
|
+
### `recordDrawLedger(renderer)` / `beginDrawLedger(renderer)`
|
|
96
|
+
|
|
97
|
+
Wraps `WebGLRenderer.renderBufferDirect` and counts every draw by object name, by group (the name up
|
|
98
|
+
to its first `:` or `#`), and by pass: `shadow`, then each `render()` call by scene name, or
|
|
99
|
+
`render 1`, `render 2`… `recordDrawLedger` records exactly one animation frame; `beginDrawLedger`
|
|
100
|
+
returns `{ end() }` for any span. `printDrawLedger` prints the tables.
|
|
101
|
+
|
|
102
|
+
### `watchBlackFrames(renderer)`
|
|
103
|
+
|
|
104
|
+
After each render to the screen, reads a 3 × 3 grid of pixels and counts frames where three or more
|
|
105
|
+
are pure black. Use a visible browser: headless ones haven't reproduced black frames. Each read
|
|
106
|
+
stalls the GPU, so watch, read `blackFrames`, `stop()`.
|
|
107
|
+
|
|
108
|
+
### `auditScene(root, options?)`
|
|
109
|
+
|
|
110
|
+
`{ triangles, zFighting, badGeometry, meshes }` in one call. Rows carry the live mesh as a
|
|
111
|
+
non-enumerable property (`row.mesh`, `row.meshes`), so they print and serialise without dragging the
|
|
112
|
+
scene along.
|
|
113
|
+
|
|
114
|
+
## License
|
|
115
|
+
|
|
116
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import { BufferGeometry, Camera, Material, Mesh, Object3D, Scene } from "three";
|
|
2
|
+
//#region src/scene.d.ts
|
|
3
|
+
/** Leave an object and everything under it out of a check. */
|
|
4
|
+
type Skip = (object: Object3D) => boolean;
|
|
5
|
+
/** Triangles one draw of this geometry makes: indexed or not, within its draw range. */
|
|
6
|
+
export declare const triangleCount: (geometry: BufferGeometry) => number;
|
|
7
|
+
//#endregion
|
|
8
|
+
//#region src/bad-geometry.d.ts
|
|
9
|
+
type BadGeometryOptions = {
|
|
10
|
+
skip?: Skip | undefined;
|
|
11
|
+
/** `userData` key naming the part a mesh belongs to, for the `under` column. */
|
|
12
|
+
tagKey?: string;
|
|
13
|
+
};
|
|
14
|
+
type BadGeometryRow = {
|
|
15
|
+
mesh: string;
|
|
16
|
+
/** The tagged part it sits in, or its parent's name. */
|
|
17
|
+
under: string;
|
|
18
|
+
/** Vertices with a NaN or infinite position or normal component. */
|
|
19
|
+
nonFinite: number;
|
|
20
|
+
/** Vertices of triangles with area whose normal has no length. */
|
|
21
|
+
zeroNormals: number;
|
|
22
|
+
/** Not enumerable: kept out of JSON and `console.table`. */
|
|
23
|
+
readonly object: Mesh;
|
|
24
|
+
};
|
|
25
|
+
/** Meshes with geometry that renders NaN, hidden ones included. `[]` is a pass. */
|
|
26
|
+
export declare const findBadGeometry: (root: Object3D, options?: BadGeometryOptions) => BadGeometryRow[];
|
|
27
|
+
//#endregion
|
|
28
|
+
//#region src/triangles.d.ts
|
|
29
|
+
type TriangleOptions = {
|
|
30
|
+
skip?: Skip | undefined;
|
|
31
|
+
};
|
|
32
|
+
type MeshRow = {
|
|
33
|
+
name: string;
|
|
34
|
+
/** Triangles in one copy (a batch's average). */
|
|
35
|
+
triangles: number;
|
|
36
|
+
instances: number;
|
|
37
|
+
total: number;
|
|
38
|
+
/** Not enumerable: kept out of JSON and `console.table`. */
|
|
39
|
+
readonly mesh: Mesh;
|
|
40
|
+
};
|
|
41
|
+
type GeometryRow = {
|
|
42
|
+
/** `geometry.name`, or its type and the start of its uuid. */
|
|
43
|
+
geometry: string;
|
|
44
|
+
/** Copies drawn: every mesh using it, instances counted. */
|
|
45
|
+
uses: number;
|
|
46
|
+
triangles: number;
|
|
47
|
+
total: number;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Triangles one pass draws: visible meshes, instances counted, no frustum culling. A shadow pass
|
|
51
|
+
* adds roughly as much again for each shadow-casting light.
|
|
52
|
+
*/
|
|
53
|
+
export declare const countTriangles: (root: Object3D, options?: TriangleOptions) => number;
|
|
54
|
+
/** Every visible mesh, most triangles drawn first. */
|
|
55
|
+
export declare const listMeshes: (root: Object3D, options?: TriangleOptions) => MeshRow[];
|
|
56
|
+
/**
|
|
57
|
+
* Geometries by triangles drawn, hidden meshes included, most first. Name geometries
|
|
58
|
+
* (`geometry.name`) to make this readable. Batches are left out: their shared buffer is not one
|
|
59
|
+
* geometry; `listMeshes` counts them.
|
|
60
|
+
*/
|
|
61
|
+
export declare const geometryCensus: (root: Object3D, options?: TriangleOptions) => GeometryRow[];
|
|
62
|
+
//#endregion
|
|
63
|
+
//#region src/z-fighting.d.ts
|
|
64
|
+
type ZFightingOptions = {
|
|
65
|
+
/**
|
|
66
|
+
* How close two planes count as one, in world units. 0.004 (4 mm at 1 unit = 1 m) is about what
|
|
67
|
+
* depth precision loses with a camera ~50 m out. Scale it with your units.
|
|
68
|
+
*/
|
|
69
|
+
gap?: number;
|
|
70
|
+
/** Also compare triangles within one mesh: for merged geometry whose parts share a buffer. */
|
|
71
|
+
self?: boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Only meshes inside a tagged object (`userData[tagKey]`), so a studio's ground and props stay
|
|
74
|
+
* out. Defaults to true when anything under the root is tagged, false otherwise.
|
|
75
|
+
*/
|
|
76
|
+
tagged?: boolean;
|
|
77
|
+
tagKey?: string;
|
|
78
|
+
skip?: Skip | undefined;
|
|
79
|
+
};
|
|
80
|
+
type ZFightingRow = {
|
|
81
|
+
/** `tag/mesh [material] @ (x, y, z)`, the centre in world space. */
|
|
82
|
+
a: string;
|
|
83
|
+
b: string;
|
|
84
|
+
/** Overlapping triangle pairs between the two. */
|
|
85
|
+
triangles: number;
|
|
86
|
+
/** Not enumerable: kept out of JSON and `console.table`. */
|
|
87
|
+
readonly meshes: readonly [Mesh, Mesh];
|
|
88
|
+
};
|
|
89
|
+
/** Pairs of meshes that z-fight, most overlapping triangles first. `[]` is a pass. */
|
|
90
|
+
export declare const findZFighting: (root: Object3D, options?: ZFightingOptions) => ZFightingRow[];
|
|
91
|
+
//#endregion
|
|
92
|
+
//#region src/audit-scene.d.ts
|
|
93
|
+
type AuditSceneOptions = Pick<ZFightingOptions, "gap" | "self" | "tagged"> & {
|
|
94
|
+
skip?: Skip | undefined;
|
|
95
|
+
tagKey?: string;
|
|
96
|
+
/** How many of the costliest meshes to list. */
|
|
97
|
+
top?: number;
|
|
98
|
+
};
|
|
99
|
+
type AuditReport = {
|
|
100
|
+
triangles: number;
|
|
101
|
+
zFighting: ZFightingRow[];
|
|
102
|
+
badGeometry: BadGeometryRow[];
|
|
103
|
+
/** The costliest meshes, most triangles first. */
|
|
104
|
+
meshes: MeshRow[];
|
|
105
|
+
};
|
|
106
|
+
/**
|
|
107
|
+
* Every check at once, JSON-safe: what a test asserts on or a headless browser prints. A clean
|
|
108
|
+
* scene has `zFighting` and `badGeometry` both `[]`.
|
|
109
|
+
*/
|
|
110
|
+
export declare const auditScene: (root: Object3D, options?: AuditSceneOptions) => AuditReport;
|
|
111
|
+
//#endregion
|
|
112
|
+
//#region src/black-frames.d.ts
|
|
113
|
+
/** The `WebGLRenderer` methods the probe uses. */
|
|
114
|
+
type ProbeRenderer = {
|
|
115
|
+
render(scene: Object3D, camera: Camera): void;
|
|
116
|
+
getContext(): unknown;
|
|
117
|
+
getRenderTarget(): unknown;
|
|
118
|
+
};
|
|
119
|
+
type BlackFrameOptions = {
|
|
120
|
+
/** Samples per side: 3 reads a 3 × 3 grid at the quarter lines. */
|
|
121
|
+
grid?: number;
|
|
122
|
+
/** Black samples that make a frame black. */
|
|
123
|
+
threshold?: number;
|
|
124
|
+
};
|
|
125
|
+
type BlackFrameWatch = {
|
|
126
|
+
/** Frames sampled since the start or the last `reset()`. */
|
|
127
|
+
readonly frames: number;
|
|
128
|
+
/** Which of those frames (1-based) were black. */
|
|
129
|
+
readonly blackFrames: readonly number[];
|
|
130
|
+
reset: () => void;
|
|
131
|
+
/** Restore the renderer and stop sampling. */
|
|
132
|
+
stop: () => void;
|
|
133
|
+
};
|
|
134
|
+
/**
|
|
135
|
+
* Sample every frame the app draws to the screen. Several screen renders in one frame (an overlay
|
|
136
|
+
* redrawn after the composer) count once, as the last of them: the image the display shows.
|
|
137
|
+
* Browser only: frames are told apart by `requestAnimationFrame`.
|
|
138
|
+
*/
|
|
139
|
+
export declare const watchBlackFrames: (renderer: ProbeRenderer, options?: BlackFrameOptions) => BlackFrameWatch;
|
|
140
|
+
//#endregion
|
|
141
|
+
//#region src/draw-ledger.d.ts
|
|
142
|
+
/** The two `WebGLRenderer` methods the ledger wraps. */
|
|
143
|
+
type LedgerRenderer = {
|
|
144
|
+
render(scene: Object3D, camera: Camera): void;
|
|
145
|
+
renderBufferDirect(camera: Camera, scene: Scene | null, geometry: BufferGeometry, material: Material, object: Object3D, group: unknown): void;
|
|
146
|
+
};
|
|
147
|
+
type DrawLedgerOptions = {
|
|
148
|
+
/**
|
|
149
|
+
* The group an object name files under. Default: up to the first `:` or `#`, so a bake's
|
|
150
|
+
* `wagon:paint` and a strip's `grass#3` group as `wagon` and `grass`.
|
|
151
|
+
*/
|
|
152
|
+
groupOf?: (name: string) => string;
|
|
153
|
+
};
|
|
154
|
+
type LedgerRow = {
|
|
155
|
+
name: string;
|
|
156
|
+
total: number;
|
|
157
|
+
/** Draws per pass name. */
|
|
158
|
+
passes: Record<string, number>;
|
|
159
|
+
};
|
|
160
|
+
type DrawLedger = {
|
|
161
|
+
/**
|
|
162
|
+
* Pass names in the order they first drew: `shadow`, then each `render()` call as its scene's
|
|
163
|
+
* name, or `render 1`, `render 2`… when unnamed (a post-processing chain is several).
|
|
164
|
+
*/
|
|
165
|
+
passes: string[];
|
|
166
|
+
/** By group, most draws first. */
|
|
167
|
+
groups: LedgerRow[];
|
|
168
|
+
/** By object name, most draws first. */
|
|
169
|
+
objects: LedgerRow[];
|
|
170
|
+
draws: number;
|
|
171
|
+
};
|
|
172
|
+
type DrawLedgerRecording = {
|
|
173
|
+
/** Restore the renderer and return what was drawn since `beginDrawLedger`. */
|
|
174
|
+
end: () => DrawLedger;
|
|
175
|
+
};
|
|
176
|
+
/** Start counting every draw. Call `end()` after the frame to restore the renderer and read it. */
|
|
177
|
+
export declare const beginDrawLedger: (renderer: LedgerRenderer, options?: DrawLedgerOptions) => DrawLedgerRecording;
|
|
178
|
+
/**
|
|
179
|
+
* Record exactly one frame of an app that renders from `requestAnimationFrame` (three's
|
|
180
|
+
* `setAnimationLoop`, React Three Fiber): from one animation frame to the next. A demand-driven
|
|
181
|
+
* loop that renders nothing that frame gives an empty ledger. Browser only.
|
|
182
|
+
*/
|
|
183
|
+
export declare const recordDrawLedger: (renderer: LedgerRenderer, options?: DrawLedgerOptions) => Promise<DrawLedger>;
|
|
184
|
+
/** Rows shaped for `console.table`: one column per pass, then the total. */
|
|
185
|
+
export declare const ledgerTable: (rows: LedgerRow[], passes: string[]) => {
|
|
186
|
+
name: string;
|
|
187
|
+
total: number;
|
|
188
|
+
}[];
|
|
189
|
+
/** The ledger as two console tables: by group, and every object collapsed beneath. */
|
|
190
|
+
export declare const printDrawLedger: (ledger: DrawLedger) => void;
|
|
191
|
+
//#endregion
|
|
192
|
+
//#region src/console-helpers.d.ts
|
|
193
|
+
type AuditHelpersOptions = {
|
|
194
|
+
/** A `WebGLRenderer`, for `ledger()` and `blackFrames()`. */
|
|
195
|
+
renderer?: (LedgerRenderer & ProbeRenderer) | undefined;
|
|
196
|
+
skip?: Skip | undefined;
|
|
197
|
+
tagKey?: string;
|
|
198
|
+
};
|
|
199
|
+
/**
|
|
200
|
+
* Put the helpers on `globalThis`. Returns a function that removes them.
|
|
201
|
+
*
|
|
202
|
+
* vanilla: installAuditHelpers(scene, { renderer })
|
|
203
|
+
* R3F: const { scene, gl } = useThree();
|
|
204
|
+
* useLayoutEffect(() => installAuditHelpers(scene, { renderer: gl }), [scene, gl]);
|
|
205
|
+
*/
|
|
206
|
+
export declare const installAuditHelpers: (root: Object3D, options?: AuditHelpersOptions) => () => void;
|
|
207
|
+
//#endregion
|
|
208
|
+
export type { AuditHelpersOptions, AuditReport, AuditSceneOptions, BadGeometryOptions, BadGeometryRow, BlackFrameOptions, BlackFrameWatch, DrawLedger, DrawLedgerOptions, DrawLedgerRecording, GeometryRow, LedgerRenderer, LedgerRow, MeshRow, ProbeRenderer, Skip, TriangleOptions, ZFightingOptions, ZFightingRow };
|
|
209
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,645 @@
|
|
|
1
|
+
//#region src/scene.ts
|
|
2
|
+
/** Depth-first, in child order. A skipped (or, with `visibleOnly`, hidden) object prunes its subtree. */
|
|
3
|
+
const walk = (root, options, visit) => {
|
|
4
|
+
const stack = [root];
|
|
5
|
+
while (stack.length > 0) {
|
|
6
|
+
const object = stack.pop();
|
|
7
|
+
if (options.visibleOnly === true && !object.visible || options.skip?.(object) === true) continue;
|
|
8
|
+
visit(object);
|
|
9
|
+
for (let i = object.children.length - 1; i >= 0; i -= 1) stack.push(object.children[i]);
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
const isMesh = (object) => object.isMesh === true;
|
|
13
|
+
const isInstanced = (mesh) => mesh.isInstancedMesh === true;
|
|
14
|
+
const isBatched = (mesh) => mesh.isBatchedMesh === true;
|
|
15
|
+
/** Triangles one draw of this geometry makes: indexed or not, within its draw range. */
|
|
16
|
+
const triangleCount = (geometry) => {
|
|
17
|
+
const elements = geometry.index?.count ?? geometry.attributes.position?.count ?? 0;
|
|
18
|
+
const { start, count } = geometry.drawRange;
|
|
19
|
+
const drawn = Math.min(elements, start + count) - start;
|
|
20
|
+
return Math.max(0, Math.floor(drawn / 3));
|
|
21
|
+
};
|
|
22
|
+
/** Triangles a batch draws across its visible instances, and how many instances that is. */
|
|
23
|
+
const batchedTriangles = (batch) => {
|
|
24
|
+
let triangles = 0;
|
|
25
|
+
let instances = 0;
|
|
26
|
+
for (let id = 0; id < batch.maxInstanceCount; id += 1) {
|
|
27
|
+
let geometryId;
|
|
28
|
+
try {
|
|
29
|
+
if (!batch.getVisibleAt(id)) continue;
|
|
30
|
+
geometryId = batch.getGeometryIdAt(id);
|
|
31
|
+
} catch {
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
const range = batch.getGeometryRangeAt(geometryId);
|
|
35
|
+
const elements = range.count ?? (batch.geometry.index ? range.indexCount : range.vertexCount);
|
|
36
|
+
triangles += Math.floor(elements / 3);
|
|
37
|
+
instances += 1;
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
instances,
|
|
41
|
+
triangles
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
/** The tag of the nearest tagged ancestor (the object itself included), or `null`. */
|
|
45
|
+
const tagOf = (object, tagKey) => {
|
|
46
|
+
for (let at = object; at; at = at.parent) {
|
|
47
|
+
const tag = at.userData[tagKey];
|
|
48
|
+
if (tag !== void 0 && tag !== null) return String(tag);
|
|
49
|
+
}
|
|
50
|
+
return null;
|
|
51
|
+
};
|
|
52
|
+
const hasTag = (root, tagKey, skip) => {
|
|
53
|
+
let found = false;
|
|
54
|
+
walk(root, { skip }, (object) => {
|
|
55
|
+
found ||= object.userData[tagKey] !== void 0 && object.userData[tagKey] !== null;
|
|
56
|
+
});
|
|
57
|
+
return found;
|
|
58
|
+
};
|
|
59
|
+
const meshName = (mesh) => mesh.name || mesh.geometry.name || mesh.geometry.type;
|
|
60
|
+
const materialName = (mesh) => {
|
|
61
|
+
const material = Array.isArray(mesh.material) ? mesh.material[0] : mesh.material;
|
|
62
|
+
return material ? material.name || material.type : "none";
|
|
63
|
+
};
|
|
64
|
+
/** Adds a property JSON and `console.table` leave out: a live object that would serialise the scene. */
|
|
65
|
+
const withHidden = (row, key, value) => Object.defineProperty(row, key, {
|
|
66
|
+
value,
|
|
67
|
+
enumerable: false
|
|
68
|
+
});
|
|
69
|
+
//#endregion
|
|
70
|
+
//#region src/bad-geometry.ts
|
|
71
|
+
const corner = (geometry, k) => geometry.index?.getX(k) ?? k;
|
|
72
|
+
const check = (geometry) => {
|
|
73
|
+
const position = geometry.attributes.position;
|
|
74
|
+
const normal = geometry.attributes.normal;
|
|
75
|
+
const flagged = new Uint8Array(position.count);
|
|
76
|
+
let nonFinite = 0;
|
|
77
|
+
let zeroNormals = 0;
|
|
78
|
+
for (let v = 0; v < position.count; v += 1) if (!(Number.isFinite(position.getX(v)) && Number.isFinite(position.getY(v)) && Number.isFinite(position.getZ(v)) && (!normal || Number.isFinite(normal.getX(v)) && Number.isFinite(normal.getY(v)) && Number.isFinite(normal.getZ(v))))) {
|
|
79
|
+
flagged[v] = 1;
|
|
80
|
+
nonFinite += 1;
|
|
81
|
+
}
|
|
82
|
+
if (!normal) return {
|
|
83
|
+
nonFinite,
|
|
84
|
+
zeroNormals
|
|
85
|
+
};
|
|
86
|
+
const corners = geometry.index?.count ?? position.count;
|
|
87
|
+
for (let k = 0; k + 2 < corners; k += 3) {
|
|
88
|
+
const a = corner(geometry, k);
|
|
89
|
+
const b = corner(geometry, k + 1);
|
|
90
|
+
const c = corner(geometry, k + 2);
|
|
91
|
+
const ux = position.getX(b) - position.getX(a);
|
|
92
|
+
const uy = position.getY(b) - position.getY(a);
|
|
93
|
+
const uz = position.getZ(b) - position.getZ(a);
|
|
94
|
+
const vx = position.getX(c) - position.getX(a);
|
|
95
|
+
const vy = position.getY(c) - position.getY(a);
|
|
96
|
+
const vz = position.getZ(c) - position.getZ(a);
|
|
97
|
+
if (!(Math.hypot(uy * vz - uz * vy, uz * vx - ux * vz, ux * vy - uy * vx) > 1e-8)) continue;
|
|
98
|
+
for (const v of [
|
|
99
|
+
a,
|
|
100
|
+
b,
|
|
101
|
+
c
|
|
102
|
+
]) if (flagged[v] === 0 && Math.hypot(normal.getX(v), normal.getY(v), normal.getZ(v)) < 1e-4) {
|
|
103
|
+
flagged[v] = 1;
|
|
104
|
+
zeroNormals += 1;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return {
|
|
108
|
+
nonFinite,
|
|
109
|
+
zeroNormals
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
/** Meshes with geometry that renders NaN, hidden ones included. `[]` is a pass. */
|
|
113
|
+
const findBadGeometry = (root, options = {}) => {
|
|
114
|
+
const tagKey = options.tagKey ?? "studioObject";
|
|
115
|
+
const rows = [];
|
|
116
|
+
walk(root, { skip: options.skip }, (object) => {
|
|
117
|
+
if (!isMesh(object) || !object.geometry.attributes.position) return;
|
|
118
|
+
const { nonFinite, zeroNormals } = check(object.geometry);
|
|
119
|
+
if (nonFinite > 0 || zeroNormals > 0) {
|
|
120
|
+
const under = tagOf(object, tagKey) ?? object.parent?.name ?? "";
|
|
121
|
+
rows.push(withHidden({
|
|
122
|
+
mesh: meshName(object),
|
|
123
|
+
under,
|
|
124
|
+
nonFinite,
|
|
125
|
+
zeroNormals
|
|
126
|
+
}, "object", object));
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
return rows;
|
|
130
|
+
};
|
|
131
|
+
//#endregion
|
|
132
|
+
//#region src/triangles.ts
|
|
133
|
+
const cost = (mesh) => {
|
|
134
|
+
if (isBatched(mesh)) return batchedTriangles(mesh);
|
|
135
|
+
const instances = isInstanced(mesh) ? mesh.count : 1;
|
|
136
|
+
return {
|
|
137
|
+
instances,
|
|
138
|
+
triangles: triangleCount(mesh.geometry) * instances
|
|
139
|
+
};
|
|
140
|
+
};
|
|
141
|
+
/**
|
|
142
|
+
* Triangles one pass draws: visible meshes, instances counted, no frustum culling. A shadow pass
|
|
143
|
+
* adds roughly as much again for each shadow-casting light.
|
|
144
|
+
*/
|
|
145
|
+
const countTriangles = (root, options = {}) => {
|
|
146
|
+
let total = 0;
|
|
147
|
+
walk(root, {
|
|
148
|
+
skip: options.skip,
|
|
149
|
+
visibleOnly: true
|
|
150
|
+
}, (object) => {
|
|
151
|
+
if (isMesh(object)) total += cost(object).triangles;
|
|
152
|
+
});
|
|
153
|
+
return total;
|
|
154
|
+
};
|
|
155
|
+
/** Every visible mesh, most triangles drawn first. */
|
|
156
|
+
const listMeshes = (root, options = {}) => {
|
|
157
|
+
const rows = [];
|
|
158
|
+
walk(root, {
|
|
159
|
+
skip: options.skip,
|
|
160
|
+
visibleOnly: true
|
|
161
|
+
}, (object) => {
|
|
162
|
+
if (!isMesh(object)) return;
|
|
163
|
+
const { instances, triangles } = cost(object);
|
|
164
|
+
const row = {
|
|
165
|
+
name: meshName(object),
|
|
166
|
+
triangles: instances > 0 ? Math.round(triangles / instances) : 0,
|
|
167
|
+
instances,
|
|
168
|
+
total: triangles
|
|
169
|
+
};
|
|
170
|
+
rows.push(withHidden(row, "mesh", object));
|
|
171
|
+
});
|
|
172
|
+
return rows.sort((a, b) => b.total - a.total);
|
|
173
|
+
};
|
|
174
|
+
/**
|
|
175
|
+
* Geometries by triangles drawn, hidden meshes included, most first. Name geometries
|
|
176
|
+
* (`geometry.name`) to make this readable. Batches are left out: their shared buffer is not one
|
|
177
|
+
* geometry; `listMeshes` counts them.
|
|
178
|
+
*/
|
|
179
|
+
const geometryCensus = (root, options = {}) => {
|
|
180
|
+
const rows = /* @__PURE__ */ new Map();
|
|
181
|
+
walk(root, { skip: options.skip }, (object) => {
|
|
182
|
+
if (!isMesh(object) || isBatched(object) || !object.geometry.attributes.position) return;
|
|
183
|
+
const geometry = object.geometry;
|
|
184
|
+
const key = geometry.name || `${geometry.type}:${geometry.uuid.slice(0, 6)}`;
|
|
185
|
+
const triangles = triangleCount(geometry);
|
|
186
|
+
const uses = isInstanced(object) ? object.count : 1;
|
|
187
|
+
const row = rows.get(key) ?? {
|
|
188
|
+
geometry: key,
|
|
189
|
+
uses: 0,
|
|
190
|
+
triangles,
|
|
191
|
+
total: 0
|
|
192
|
+
};
|
|
193
|
+
row.uses += uses;
|
|
194
|
+
row.total += triangles * uses;
|
|
195
|
+
rows.set(key, row);
|
|
196
|
+
});
|
|
197
|
+
return [...rows.values()].sort((a, b) => b.total - a.total);
|
|
198
|
+
};
|
|
199
|
+
//#endregion
|
|
200
|
+
//#region src/z-fighting.ts
|
|
201
|
+
/** Normals quantised to 1/40: neighbouring buckets are searched, so this only sets bucket size. */
|
|
202
|
+
const QUANT = 40;
|
|
203
|
+
/** Normals this aligned count as parallel (about 2.6°). */
|
|
204
|
+
const PARALLEL = .999;
|
|
205
|
+
const round = (value) => Math.round(value * 100) / 100;
|
|
206
|
+
const labelOf = (part) => {
|
|
207
|
+
const centre = part.min.map((low, axis) => round((low + part.max[axis]) / 2));
|
|
208
|
+
return `${part.tag === null ? "" : `${part.tag}/`}${meshName(part.mesh)} [${materialName(part.mesh)}] @ (${centre.join(", ")})`;
|
|
209
|
+
};
|
|
210
|
+
/** Pairs of meshes that z-fight, most overlapping triangles first. `[]` is a pass. */
|
|
211
|
+
const findZFighting = (root, options = {}) => {
|
|
212
|
+
const gap = options.gap ?? .004;
|
|
213
|
+
const self = options.self ?? false;
|
|
214
|
+
const tagKey = options.tagKey ?? "studioObject";
|
|
215
|
+
const tagged = options.tagged ?? hasTag(root, tagKey, options.skip);
|
|
216
|
+
root.updateWorldMatrix(true, true);
|
|
217
|
+
const parts = [];
|
|
218
|
+
const owner = [];
|
|
219
|
+
const planes = [];
|
|
220
|
+
const corners = [];
|
|
221
|
+
const keys = [];
|
|
222
|
+
const buckets = /* @__PURE__ */ new Map();
|
|
223
|
+
const keyOf = (x, y, z, d) => `${x},${y},${z},${d}`;
|
|
224
|
+
walk(root, { skip: options.skip }, (object) => {
|
|
225
|
+
if (!isMesh(object) || isInstanced(object) || isBatched(object) || !object.geometry.attributes.position) return;
|
|
226
|
+
const tag = tagOf(object, tagKey);
|
|
227
|
+
if (tagged && tag === null) return;
|
|
228
|
+
const part = parts.length;
|
|
229
|
+
const { index, attributes } = object.geometry;
|
|
230
|
+
const position = attributes.position;
|
|
231
|
+
const e = object.matrixWorld.elements;
|
|
232
|
+
const min = [
|
|
233
|
+
Infinity,
|
|
234
|
+
Infinity,
|
|
235
|
+
Infinity
|
|
236
|
+
];
|
|
237
|
+
const max = [
|
|
238
|
+
-Infinity,
|
|
239
|
+
-Infinity,
|
|
240
|
+
-Infinity
|
|
241
|
+
];
|
|
242
|
+
const count = index?.count ?? position.count;
|
|
243
|
+
const world = [
|
|
244
|
+
0,
|
|
245
|
+
0,
|
|
246
|
+
0,
|
|
247
|
+
0,
|
|
248
|
+
0,
|
|
249
|
+
0,
|
|
250
|
+
0,
|
|
251
|
+
0,
|
|
252
|
+
0
|
|
253
|
+
];
|
|
254
|
+
parts.push({
|
|
255
|
+
mesh: object,
|
|
256
|
+
tag,
|
|
257
|
+
min,
|
|
258
|
+
max
|
|
259
|
+
});
|
|
260
|
+
for (let k = 0; k + 2 < count; k += 3) {
|
|
261
|
+
for (let c = 0; c < 3; c += 1) {
|
|
262
|
+
const v = index?.getX(k + c) ?? k + c;
|
|
263
|
+
const x = position.getX(v);
|
|
264
|
+
const y = position.getY(v);
|
|
265
|
+
const z = position.getZ(v);
|
|
266
|
+
for (let axis = 0; axis < 3; axis += 1) {
|
|
267
|
+
const value = e[axis] * x + e[axis + 4] * y + e[axis + 8] * z + e[axis + 12];
|
|
268
|
+
world[c * 3 + axis] = value;
|
|
269
|
+
min[axis] = Math.min(min[axis], value);
|
|
270
|
+
max[axis] = Math.max(max[axis], value);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
const [ax, ay, az, bx, by, bz, cx, cy, cz] = world;
|
|
274
|
+
const ux = bx - ax;
|
|
275
|
+
const uy = by - ay;
|
|
276
|
+
const uz = bz - az;
|
|
277
|
+
const vx = cx - ax;
|
|
278
|
+
const vy = cy - ay;
|
|
279
|
+
const vz = cz - az;
|
|
280
|
+
let nx = uy * vz - uz * vy;
|
|
281
|
+
let ny = uz * vx - ux * vz;
|
|
282
|
+
let nz = ux * vy - uy * vx;
|
|
283
|
+
const length = Math.hypot(nx, ny, nz);
|
|
284
|
+
if (!(length / 2 >= 1e-5)) continue;
|
|
285
|
+
nx /= length;
|
|
286
|
+
ny /= length;
|
|
287
|
+
nz /= length;
|
|
288
|
+
const d = nx * ax + ny * ay + nz * az;
|
|
289
|
+
const id = owner.length;
|
|
290
|
+
const key = [
|
|
291
|
+
Math.round(nx * QUANT),
|
|
292
|
+
Math.round(ny * QUANT),
|
|
293
|
+
Math.round(nz * QUANT),
|
|
294
|
+
Math.round(d / gap)
|
|
295
|
+
];
|
|
296
|
+
const bucket = buckets.get(keyOf(...key));
|
|
297
|
+
owner.push(part);
|
|
298
|
+
planes.push(nx, ny, nz, d);
|
|
299
|
+
corners.push(...world);
|
|
300
|
+
keys.push(key);
|
|
301
|
+
if (bucket) bucket.push(id);
|
|
302
|
+
else buckets.set(keyOf(...key), [id]);
|
|
303
|
+
}
|
|
304
|
+
});
|
|
305
|
+
const margin = gap / 2;
|
|
306
|
+
const flat = [
|
|
307
|
+
0,
|
|
308
|
+
0,
|
|
309
|
+
0,
|
|
310
|
+
0,
|
|
311
|
+
0,
|
|
312
|
+
0,
|
|
313
|
+
0,
|
|
314
|
+
0,
|
|
315
|
+
0,
|
|
316
|
+
0,
|
|
317
|
+
0,
|
|
318
|
+
0
|
|
319
|
+
];
|
|
320
|
+
const overlaps = (s, t) => {
|
|
321
|
+
const S = s * 9;
|
|
322
|
+
const T = t * 9;
|
|
323
|
+
let ux = corners[S + 3] - corners[S];
|
|
324
|
+
let uy = corners[S + 4] - corners[S + 1];
|
|
325
|
+
let uz = corners[S + 5] - corners[S + 2];
|
|
326
|
+
const length = Math.hypot(ux, uy, uz) || 1;
|
|
327
|
+
ux /= length;
|
|
328
|
+
uy /= length;
|
|
329
|
+
uz /= length;
|
|
330
|
+
const nx = planes[s * 4];
|
|
331
|
+
const ny = planes[s * 4 + 1];
|
|
332
|
+
const nz = planes[s * 4 + 2];
|
|
333
|
+
const vx = ny * uz - nz * uy;
|
|
334
|
+
const vy = nz * ux - nx * uz;
|
|
335
|
+
const vz = nx * uy - ny * ux;
|
|
336
|
+
for (let i = 0; i < 6; i += 1) {
|
|
337
|
+
const at = i < 3 ? S + i * 3 : T + (i - 3) * 3;
|
|
338
|
+
const px = corners[at];
|
|
339
|
+
const py = corners[at + 1];
|
|
340
|
+
const pz = corners[at + 2];
|
|
341
|
+
flat[i * 2] = px * ux + py * uy + pz * uz;
|
|
342
|
+
flat[i * 2 + 1] = px * vx + py * vy + pz * vz;
|
|
343
|
+
}
|
|
344
|
+
for (let edge = 0; edge < 6; edge += 1) {
|
|
345
|
+
const from = edge;
|
|
346
|
+
const to = edge < 3 ? (edge + 1) % 3 : 3 + (edge + 1) % 3;
|
|
347
|
+
const ex = flat[to * 2] - flat[from * 2];
|
|
348
|
+
const ey = flat[to * 2 + 1] - flat[from * 2 + 1];
|
|
349
|
+
const edgeLength = Math.hypot(ex, ey) || 1;
|
|
350
|
+
const axisX = -ey / edgeLength;
|
|
351
|
+
const axisY = ex / edgeLength;
|
|
352
|
+
let p0 = Infinity;
|
|
353
|
+
let p1 = -Infinity;
|
|
354
|
+
let q0 = Infinity;
|
|
355
|
+
let q1 = -Infinity;
|
|
356
|
+
for (let i = 0; i < 6; i += 1) {
|
|
357
|
+
const value = flat[i * 2] * axisX + flat[i * 2 + 1] * axisY;
|
|
358
|
+
if (i < 3) {
|
|
359
|
+
p0 = Math.min(p0, value);
|
|
360
|
+
p1 = Math.max(p1, value);
|
|
361
|
+
} else {
|
|
362
|
+
q0 = Math.min(q0, value);
|
|
363
|
+
q1 = Math.max(q1, value);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
if (Math.min(p1, q1) - Math.max(p0, q0) < margin) return false;
|
|
367
|
+
}
|
|
368
|
+
return true;
|
|
369
|
+
};
|
|
370
|
+
const pairs = /* @__PURE__ */ new Map();
|
|
371
|
+
for (let s = 0; s < owner.length; s += 1) {
|
|
372
|
+
const [kx, ky, kz, kd] = keys[s];
|
|
373
|
+
for (let i = -1; i <= 1; i += 1) for (let j = -1; j <= 1; j += 1) for (let k = -1; k <= 1; k += 1) for (let l = -1; l <= 1; l += 1) for (const t of buckets.get(keyOf(kx + i, ky + j, kz + k, kd + l)) ?? []) {
|
|
374
|
+
const a = owner[s];
|
|
375
|
+
const b = owner[t];
|
|
376
|
+
if (t <= s || a === b && !self || planes[s * 4] * planes[t * 4] + planes[s * 4 + 1] * planes[t * 4 + 1] + planes[s * 4 + 2] * planes[t * 4 + 2] < PARALLEL || Math.abs(planes[s * 4 + 3] - planes[t * 4 + 3]) > gap || !overlaps(s, t)) continue;
|
|
377
|
+
const key = a < b ? `${a}:${b}` : `${b}:${a}`;
|
|
378
|
+
const pair = pairs.get(key) ?? {
|
|
379
|
+
a: Math.min(a, b),
|
|
380
|
+
b: Math.max(a, b),
|
|
381
|
+
triangles: 0
|
|
382
|
+
};
|
|
383
|
+
pair.triangles += 1;
|
|
384
|
+
pairs.set(key, pair);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
return [...pairs.values()].sort((x, y) => y.triangles - x.triangles).map(({ a, b, triangles }) => withHidden({
|
|
388
|
+
a: labelOf(parts[a]),
|
|
389
|
+
b: labelOf(parts[b]),
|
|
390
|
+
triangles
|
|
391
|
+
}, "meshes", [parts[a].mesh, parts[b].mesh]));
|
|
392
|
+
};
|
|
393
|
+
//#endregion
|
|
394
|
+
//#region src/audit-scene.ts
|
|
395
|
+
/**
|
|
396
|
+
* Every check at once, JSON-safe: what a test asserts on or a headless browser prints. A clean
|
|
397
|
+
* scene has `zFighting` and `badGeometry` both `[]`.
|
|
398
|
+
*/
|
|
399
|
+
const auditScene = (root, options = {}) => {
|
|
400
|
+
const { skip, tagKey } = options;
|
|
401
|
+
return {
|
|
402
|
+
triangles: countTriangles(root, { skip }),
|
|
403
|
+
zFighting: findZFighting(root, options),
|
|
404
|
+
badGeometry: findBadGeometry(root, tagKey === void 0 ? { skip } : {
|
|
405
|
+
skip,
|
|
406
|
+
tagKey
|
|
407
|
+
}),
|
|
408
|
+
meshes: listMeshes(root, { skip }).slice(0, options.top ?? 10)
|
|
409
|
+
};
|
|
410
|
+
};
|
|
411
|
+
//#endregion
|
|
412
|
+
//#region src/patch.ts
|
|
413
|
+
/** Swap `key` on `target` for `value`; the returned function puts back exactly what was there. */
|
|
414
|
+
const patch = (target, key, value) => {
|
|
415
|
+
const own = Object.hasOwn(target, key);
|
|
416
|
+
const original = target[key];
|
|
417
|
+
target[key] = value;
|
|
418
|
+
return () => {
|
|
419
|
+
if (own) target[key] = original;
|
|
420
|
+
else delete target[key];
|
|
421
|
+
};
|
|
422
|
+
};
|
|
423
|
+
//#endregion
|
|
424
|
+
//#region src/black-frames.ts
|
|
425
|
+
/**
|
|
426
|
+
* Sample every frame the app draws to the screen. Several screen renders in one frame (an overlay
|
|
427
|
+
* redrawn after the composer) count once, as the last of them: the image the display shows.
|
|
428
|
+
* Browser only: frames are told apart by `requestAnimationFrame`.
|
|
429
|
+
*/
|
|
430
|
+
const watchBlackFrames = (renderer, options = {}) => {
|
|
431
|
+
const context = renderer.getContext();
|
|
432
|
+
if (typeof context?.readPixels !== "function") throw new TypeError("three-audit: the black-frame probe needs a WebGLRenderer");
|
|
433
|
+
if (typeof requestAnimationFrame !== "function") throw new TypeError("three-audit: the black-frame probe needs requestAnimationFrame");
|
|
434
|
+
const gl = context;
|
|
435
|
+
const grid = options.grid ?? 3;
|
|
436
|
+
const threshold = options.threshold ?? 3;
|
|
437
|
+
const pixel = /* @__PURE__ */ new Uint8Array(4);
|
|
438
|
+
const render = renderer.render;
|
|
439
|
+
let frames = 0;
|
|
440
|
+
let black = [];
|
|
441
|
+
let pending = null;
|
|
442
|
+
const isBlack = () => {
|
|
443
|
+
let count = 0;
|
|
444
|
+
for (let i = 1; i <= grid; i += 1) for (let j = 1; j <= grid; j += 1) {
|
|
445
|
+
const x = Math.floor(gl.drawingBufferWidth * i / (grid + 1));
|
|
446
|
+
const y = Math.floor(gl.drawingBufferHeight * j / (grid + 1));
|
|
447
|
+
gl.readPixels(x, y, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, pixel);
|
|
448
|
+
if (pixel[0] < 4 && pixel[1] < 4 && pixel[2] < 4 && pixel[3] > 250) count += 1;
|
|
449
|
+
}
|
|
450
|
+
return count >= threshold;
|
|
451
|
+
};
|
|
452
|
+
let raf = 0;
|
|
453
|
+
const commit = () => {
|
|
454
|
+
if (pending !== null) {
|
|
455
|
+
frames += 1;
|
|
456
|
+
if (pending) black.push(frames);
|
|
457
|
+
pending = null;
|
|
458
|
+
}
|
|
459
|
+
raf = requestAnimationFrame(commit);
|
|
460
|
+
};
|
|
461
|
+
raf = requestAnimationFrame(commit);
|
|
462
|
+
const restore = patch(renderer, "render", function(scene, camera) {
|
|
463
|
+
render.call(this, scene, camera);
|
|
464
|
+
if (renderer.getRenderTarget() === null) pending = isBlack();
|
|
465
|
+
});
|
|
466
|
+
return {
|
|
467
|
+
get frames() {
|
|
468
|
+
return frames;
|
|
469
|
+
},
|
|
470
|
+
get blackFrames() {
|
|
471
|
+
return black;
|
|
472
|
+
},
|
|
473
|
+
reset: () => {
|
|
474
|
+
frames = 0;
|
|
475
|
+
black = [];
|
|
476
|
+
pending = null;
|
|
477
|
+
},
|
|
478
|
+
stop: () => {
|
|
479
|
+
cancelAnimationFrame(raf);
|
|
480
|
+
restore();
|
|
481
|
+
}
|
|
482
|
+
};
|
|
483
|
+
};
|
|
484
|
+
//#endregion
|
|
485
|
+
//#region src/draw-ledger.ts
|
|
486
|
+
const defaultGroupOf = (name) => name.split(/[:#]/)[0] || name;
|
|
487
|
+
const nameOf = (object, material) => object.name || `${object.type}:${material.name || material.type}`;
|
|
488
|
+
const tally = (rows, name, pass) => {
|
|
489
|
+
const row = rows.get(name) ?? {
|
|
490
|
+
name,
|
|
491
|
+
total: 0,
|
|
492
|
+
passes: {}
|
|
493
|
+
};
|
|
494
|
+
row.total += 1;
|
|
495
|
+
row.passes[pass] = (row.passes[pass] ?? 0) + 1;
|
|
496
|
+
rows.set(name, row);
|
|
497
|
+
};
|
|
498
|
+
const sorted = (rows) => [...rows.values()].sort((a, b) => b.total - a.total);
|
|
499
|
+
/** Start counting every draw. Call `end()` after the frame to restore the renderer and read it. */
|
|
500
|
+
const beginDrawLedger = (renderer, options = {}) => {
|
|
501
|
+
if (typeof renderer.renderBufferDirect !== "function") throw new TypeError("three-audit: the draw ledger needs a WebGLRenderer");
|
|
502
|
+
const groupOf = options.groupOf ?? defaultGroupOf;
|
|
503
|
+
const render = renderer.render;
|
|
504
|
+
const renderBufferDirect = renderer.renderBufferDirect;
|
|
505
|
+
const passes = [];
|
|
506
|
+
const objects = /* @__PURE__ */ new Map();
|
|
507
|
+
const groups = /* @__PURE__ */ new Map();
|
|
508
|
+
let renders = 0;
|
|
509
|
+
let current = "direct";
|
|
510
|
+
let draws = 0;
|
|
511
|
+
const restoreRender = patch(renderer, "render", function(scene, camera) {
|
|
512
|
+
const outer = current;
|
|
513
|
+
renders += 1;
|
|
514
|
+
current = scene.name || `render ${renders}`;
|
|
515
|
+
try {
|
|
516
|
+
render.call(this, scene, camera);
|
|
517
|
+
} finally {
|
|
518
|
+
current = outer;
|
|
519
|
+
}
|
|
520
|
+
});
|
|
521
|
+
const restoreDraw = patch(renderer, "renderBufferDirect", function(camera, scene, geometry, material, object, group) {
|
|
522
|
+
const pass = material.isMeshDepthMaterial === true || material.isMeshDistanceMaterial === true ? "shadow" : current;
|
|
523
|
+
const name = nameOf(object, material);
|
|
524
|
+
if (!passes.includes(pass)) passes.push(pass);
|
|
525
|
+
draws += 1;
|
|
526
|
+
tally(objects, name, pass);
|
|
527
|
+
tally(groups, groupOf(name), pass);
|
|
528
|
+
renderBufferDirect.call(this, camera, scene, geometry, material, object, group);
|
|
529
|
+
});
|
|
530
|
+
return { end: () => {
|
|
531
|
+
restoreDraw();
|
|
532
|
+
restoreRender();
|
|
533
|
+
return {
|
|
534
|
+
passes,
|
|
535
|
+
groups: sorted(groups),
|
|
536
|
+
objects: sorted(objects),
|
|
537
|
+
draws
|
|
538
|
+
};
|
|
539
|
+
} };
|
|
540
|
+
};
|
|
541
|
+
/**
|
|
542
|
+
* Record exactly one frame of an app that renders from `requestAnimationFrame` (three's
|
|
543
|
+
* `setAnimationLoop`, React Three Fiber): from one animation frame to the next. A demand-driven
|
|
544
|
+
* loop that renders nothing that frame gives an empty ledger. Browser only.
|
|
545
|
+
*/
|
|
546
|
+
const recordDrawLedger = (renderer, options = {}) => new Promise((resolve, reject) => {
|
|
547
|
+
if (typeof requestAnimationFrame !== "function") {
|
|
548
|
+
reject(/* @__PURE__ */ new Error("three-audit: recordDrawLedger needs requestAnimationFrame"));
|
|
549
|
+
return;
|
|
550
|
+
}
|
|
551
|
+
requestAnimationFrame(() => {
|
|
552
|
+
try {
|
|
553
|
+
const recording = beginDrawLedger(renderer, options);
|
|
554
|
+
requestAnimationFrame(() => resolve(recording.end()));
|
|
555
|
+
} catch (error) {
|
|
556
|
+
reject(error);
|
|
557
|
+
}
|
|
558
|
+
});
|
|
559
|
+
});
|
|
560
|
+
/** Rows shaped for `console.table`: one column per pass, then the total. */
|
|
561
|
+
const ledgerTable = (rows, passes) => rows.map((row) => ({
|
|
562
|
+
name: row.name,
|
|
563
|
+
...Object.fromEntries(passes.map((pass) => [pass, row.passes[pass] ?? 0])),
|
|
564
|
+
total: row.total
|
|
565
|
+
}));
|
|
566
|
+
/** The ledger as two console tables: by group, and every object collapsed beneath. */
|
|
567
|
+
const printDrawLedger = (ledger) => {
|
|
568
|
+
console.group(`Draw ledger: ${ledger.draws} draws in one frame`);
|
|
569
|
+
console.table(ledgerTable(ledger.groups, ledger.passes));
|
|
570
|
+
console.groupCollapsed("Every object");
|
|
571
|
+
console.table(ledgerTable(ledger.objects, ledger.passes));
|
|
572
|
+
console.groupEnd();
|
|
573
|
+
console.groupEnd();
|
|
574
|
+
};
|
|
575
|
+
//#endregion
|
|
576
|
+
//#region src/console-helpers.ts
|
|
577
|
+
const NAMES = [
|
|
578
|
+
"auditRoot",
|
|
579
|
+
"tris",
|
|
580
|
+
"meshes",
|
|
581
|
+
"census",
|
|
582
|
+
"audit",
|
|
583
|
+
"zfight",
|
|
584
|
+
"report",
|
|
585
|
+
"ledger",
|
|
586
|
+
"blackFrames"
|
|
587
|
+
];
|
|
588
|
+
const needsRenderer = (name) => () => {
|
|
589
|
+
throw new Error(`three-audit: ${name}() needs installAuditHelpers(scene, { renderer })`);
|
|
590
|
+
};
|
|
591
|
+
/**
|
|
592
|
+
* Put the helpers on `globalThis`. Returns a function that removes them.
|
|
593
|
+
*
|
|
594
|
+
* vanilla: installAuditHelpers(scene, { renderer })
|
|
595
|
+
* R3F: const { scene, gl } = useThree();
|
|
596
|
+
* useLayoutEffect(() => installAuditHelpers(scene, { renderer: gl }), [scene, gl]);
|
|
597
|
+
*/
|
|
598
|
+
const installAuditHelpers = (root, options = {}) => {
|
|
599
|
+
const { renderer, skip } = options;
|
|
600
|
+
const tagKey = options.tagKey ?? "studioObject";
|
|
601
|
+
const helpers = {
|
|
602
|
+
auditRoot: root,
|
|
603
|
+
tris: () => countTriangles(root, { skip }),
|
|
604
|
+
meshes: () => listMeshes(root, { skip }),
|
|
605
|
+
census: () => geometryCensus(root, { skip }),
|
|
606
|
+
audit: () => findBadGeometry(root, {
|
|
607
|
+
skip,
|
|
608
|
+
tagKey
|
|
609
|
+
}),
|
|
610
|
+
zfight: (gap, self) => findZFighting(root, {
|
|
611
|
+
skip,
|
|
612
|
+
tagKey,
|
|
613
|
+
...gap === void 0 ? {} : { gap },
|
|
614
|
+
...self === void 0 ? {} : { self }
|
|
615
|
+
}),
|
|
616
|
+
report: () => auditScene(root, {
|
|
617
|
+
skip,
|
|
618
|
+
tagKey
|
|
619
|
+
}),
|
|
620
|
+
ledger: renderer ? async () => {
|
|
621
|
+
const ledger = await recordDrawLedger(renderer);
|
|
622
|
+
printDrawLedger(ledger);
|
|
623
|
+
return ledger;
|
|
624
|
+
} : needsRenderer("ledger"),
|
|
625
|
+
blackFrames: renderer ? (seconds = 10) => new Promise((resolve) => {
|
|
626
|
+
const watch = watchBlackFrames(renderer);
|
|
627
|
+
setTimeout(() => {
|
|
628
|
+
watch.stop();
|
|
629
|
+
resolve({
|
|
630
|
+
frames: watch.frames,
|
|
631
|
+
blackFrames: watch.blackFrames
|
|
632
|
+
});
|
|
633
|
+
}, seconds * 1e3);
|
|
634
|
+
}) : needsRenderer("blackFrames")
|
|
635
|
+
};
|
|
636
|
+
Object.assign(globalThis, helpers);
|
|
637
|
+
return () => {
|
|
638
|
+
const scope = globalThis;
|
|
639
|
+
for (const name of NAMES) if (scope[name] === helpers[name]) delete scope[name];
|
|
640
|
+
};
|
|
641
|
+
};
|
|
642
|
+
//#endregion
|
|
643
|
+
export { auditScene, beginDrawLedger, countTriangles, findBadGeometry, findZFighting, geometryCensus, installAuditHelpers, ledgerTable, listMeshes, printDrawLedger, recordDrawLedger, triangleCount, watchBlackFrames };
|
|
644
|
+
|
|
645
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/scene.ts","../src/bad-geometry.ts","../src/triangles.ts","../src/z-fighting.ts","../src/audit-scene.ts","../src/patch.ts","../src/black-frames.ts","../src/draw-ledger.ts","../src/console-helpers.ts"],"sourcesContent":["/**\n * Scene-graph plumbing every check shares: the walk, mesh kinds, triangle counts, tags and names.\n *\n * Nothing here imports three at runtime; objects are recognised by three's own `is*` flags, so the\n * checks work on whatever copy of three the app bundles.\n */\nimport type { BatchedMesh, BufferGeometry, InstancedMesh, Material, Mesh, Object3D } from \"three\";\n\n/** Leave an object and everything under it out of a check. */\nexport type Skip = (object: Object3D) => boolean;\n\nexport type WalkOptions = {\n skip?: Skip | undefined;\n /** Prune hidden objects and their subtrees, as the renderer does. */\n visibleOnly?: boolean;\n};\n\n/** Depth-first, in child order. A skipped (or, with `visibleOnly`, hidden) object prunes its subtree. */\nexport const walk = (root: Object3D, options: WalkOptions, visit: (object: Object3D) => void) => {\n const stack = [root];\n\n while (stack.length > 0) {\n const object = stack.pop()!;\n\n if ((options.visibleOnly === true && !object.visible) || options.skip?.(object) === true) {\n continue;\n }\n\n visit(object);\n\n for (let i = object.children.length - 1; i >= 0; i -= 1) {\n stack.push(object.children[i]!);\n }\n }\n};\n\nexport const isMesh = (object: Object3D): object is Mesh => (object as Mesh).isMesh === true;\n\nexport const isInstanced = (mesh: Mesh): mesh is InstancedMesh =>\n (mesh as InstancedMesh).isInstancedMesh === true;\n\nexport const isBatched = (mesh: Mesh): mesh is BatchedMesh =>\n (mesh as unknown as BatchedMesh).isBatchedMesh === true;\n\n/** Triangles one draw of this geometry makes: indexed or not, within its draw range. */\nexport const triangleCount = (geometry: BufferGeometry) => {\n const elements = geometry.index?.count ?? geometry.attributes.position?.count ?? 0;\n const { start, count } = geometry.drawRange;\n const drawn = Math.min(elements, start + count) - start;\n\n return Math.max(0, Math.floor(drawn / 3));\n};\n\n/** Triangles a batch draws across its visible instances, and how many instances that is. */\nexport const batchedTriangles = (batch: BatchedMesh) => {\n let triangles = 0;\n let instances = 0;\n\n for (let id = 0; id < batch.maxInstanceCount; id += 1) {\n let geometryId: number;\n\n // Deleted and never-used ids throw.\n try {\n if (!batch.getVisibleAt(id)) {\n continue;\n }\n\n geometryId = batch.getGeometryIdAt(id);\n } catch {\n continue;\n }\n\n const range = batch.getGeometryRangeAt(geometryId) as {\n count?: number;\n indexCount: number;\n vertexCount: number;\n };\n const elements = range.count ?? (batch.geometry.index ? range.indexCount : range.vertexCount);\n\n triangles += Math.floor(elements / 3);\n instances += 1;\n }\n\n return { instances, triangles };\n};\n\n/** The tag of the nearest tagged ancestor (the object itself included), or `null`. */\nexport const tagOf = (object: Object3D, tagKey: string) => {\n for (let at: Object3D | null = object; at; at = at.parent) {\n const tag: unknown = at.userData[tagKey];\n\n if (tag !== undefined && tag !== null) {\n return String(tag);\n }\n }\n\n return null;\n};\n\nexport const hasTag = (root: Object3D, tagKey: string, skip?: Skip) => {\n let found = false;\n\n walk(root, { skip }, (object) => {\n found ||= object.userData[tagKey] !== undefined && object.userData[tagKey] !== null;\n });\n\n return found;\n};\n\nexport const meshName = (mesh: Mesh) => mesh.name || mesh.geometry.name || mesh.geometry.type;\n\nexport const materialName = (mesh: Mesh) => {\n const material = (Array.isArray(mesh.material) ? mesh.material[0] : mesh.material) as\n | Material\n | undefined;\n\n return material ? material.name || material.type : \"none\";\n};\n\n/** Adds a property JSON and `console.table` leave out: a live object that would serialise the scene. */\nexport const withHidden = <Row extends object, Key extends string, Value>(\n row: Row,\n key: Key,\n value: Value,\n) => Object.defineProperty(row, key, { value, enumerable: false }) as Row & Record<Key, Value>;\n","/**\n * Geometry that lights a pixel NaN: a non-finite position or normal, or a zero-length normal on a\n * triangle with area. Bloom and other blurs spread one NaN pixel into a black block.\n */\nimport type { BufferGeometry, Mesh, Object3D } from \"three\";\n\nimport { isMesh, meshName, type Skip, tagOf, walk, withHidden } from \"./scene.ts\";\n\nexport type BadGeometryOptions = {\n skip?: Skip | undefined;\n /** `userData` key naming the part a mesh belongs to, for the `under` column. */\n tagKey?: string;\n};\n\nexport type BadGeometryRow = {\n mesh: string;\n /** The tagged part it sits in, or its parent's name. */\n under: string;\n /** Vertices with a NaN or infinite position or normal component. */\n nonFinite: number;\n /** Vertices of triangles with area whose normal has no length. */\n zeroNormals: number;\n /** Not enumerable: kept out of JSON and `console.table`. */\n readonly object: Mesh;\n};\n\nconst corner = (geometry: BufferGeometry, k: number) => geometry.index?.getX(k) ?? k;\n\nconst check = (geometry: BufferGeometry) => {\n const position = geometry.attributes.position!;\n const normal = geometry.attributes.normal;\n const flagged = new Uint8Array(position.count);\n let nonFinite = 0;\n let zeroNormals = 0;\n\n for (let v = 0; v < position.count; v += 1) {\n const finite =\n Number.isFinite(position.getX(v)) &&\n Number.isFinite(position.getY(v)) &&\n Number.isFinite(position.getZ(v)) &&\n (!normal ||\n (Number.isFinite(normal.getX(v)) &&\n Number.isFinite(normal.getY(v)) &&\n Number.isFinite(normal.getZ(v))));\n\n if (!finite) {\n flagged[v] = 1;\n nonFinite += 1;\n }\n }\n\n if (!normal) {\n return { nonFinite, zeroNormals };\n }\n\n const corners = geometry.index?.count ?? position.count;\n\n for (let k = 0; k + 2 < corners; k += 3) {\n const a = corner(geometry, k);\n const b = corner(geometry, k + 1);\n const c = corner(geometry, k + 2);\n const ux = position.getX(b) - position.getX(a);\n const uy = position.getY(b) - position.getY(a);\n const uz = position.getZ(b) - position.getZ(a);\n const vx = position.getX(c) - position.getX(a);\n const vy = position.getY(c) - position.getY(a);\n const vz = position.getZ(c) - position.getZ(a);\n const area = Math.hypot(uy * vz - uz * vy, uz * vx - ux * vz, ux * vy - uy * vx);\n\n if (!(area > 1e-8)) {\n continue;\n }\n\n for (const v of [a, b, c]) {\n if (flagged[v] === 0 && Math.hypot(normal.getX(v), normal.getY(v), normal.getZ(v)) < 1e-4) {\n flagged[v] = 1;\n zeroNormals += 1;\n }\n }\n }\n\n return { nonFinite, zeroNormals };\n};\n\n/** Meshes with geometry that renders NaN, hidden ones included. `[]` is a pass. */\nexport const findBadGeometry = (\n root: Object3D,\n options: BadGeometryOptions = {},\n): BadGeometryRow[] => {\n const tagKey = options.tagKey ?? \"studioObject\";\n const rows: BadGeometryRow[] = [];\n\n walk(root, { skip: options.skip }, (object) => {\n if (!isMesh(object) || !object.geometry.attributes.position) {\n return;\n }\n\n const { nonFinite, zeroNormals } = check(object.geometry);\n\n if (nonFinite > 0 || zeroNormals > 0) {\n const under = tagOf(object, tagKey) ?? object.parent?.name ?? \"\";\n\n rows.push(\n withHidden({ mesh: meshName(object), under, nonFinite, zeroNormals }, \"object\", object),\n );\n }\n });\n\n return rows;\n};\n","/**\n * Where a triangle budget goes: the total one pass draws, the meshes drawing it, and the\n * geometries behind them.\n */\nimport type { Mesh, Object3D } from \"three\";\n\nimport {\n batchedTriangles,\n isBatched,\n isInstanced,\n isMesh,\n meshName,\n type Skip,\n triangleCount,\n walk,\n withHidden,\n} from \"./scene.ts\";\n\nexport type TriangleOptions = { skip?: Skip | undefined };\n\nexport type MeshRow = {\n name: string;\n /** Triangles in one copy (a batch's average). */\n triangles: number;\n instances: number;\n total: number;\n /** Not enumerable: kept out of JSON and `console.table`. */\n readonly mesh: Mesh;\n};\n\nexport type GeometryRow = {\n /** `geometry.name`, or its type and the start of its uuid. */\n geometry: string;\n /** Copies drawn: every mesh using it, instances counted. */\n uses: number;\n triangles: number;\n total: number;\n};\n\nconst cost = (mesh: Mesh) => {\n if (isBatched(mesh)) {\n return batchedTriangles(mesh);\n }\n\n const instances = isInstanced(mesh) ? mesh.count : 1;\n\n return { instances, triangles: triangleCount(mesh.geometry) * instances };\n};\n\n/**\n * Triangles one pass draws: visible meshes, instances counted, no frustum culling. A shadow pass\n * adds roughly as much again for each shadow-casting light.\n */\nexport const countTriangles = (root: Object3D, options: TriangleOptions = {}) => {\n let total = 0;\n\n walk(root, { skip: options.skip, visibleOnly: true }, (object) => {\n if (isMesh(object)) {\n total += cost(object).triangles;\n }\n });\n\n return total;\n};\n\n/** Every visible mesh, most triangles drawn first. */\nexport const listMeshes = (root: Object3D, options: TriangleOptions = {}): MeshRow[] => {\n const rows: MeshRow[] = [];\n\n walk(root, { skip: options.skip, visibleOnly: true }, (object) => {\n if (!isMesh(object)) {\n return;\n }\n\n const { instances, triangles } = cost(object);\n const row = {\n name: meshName(object),\n triangles: instances > 0 ? Math.round(triangles / instances) : 0,\n instances,\n total: triangles,\n };\n\n rows.push(withHidden(row, \"mesh\", object));\n });\n\n return rows.sort((a, b) => b.total - a.total);\n};\n\n/**\n * Geometries by triangles drawn, hidden meshes included, most first. Name geometries\n * (`geometry.name`) to make this readable. Batches are left out: their shared buffer is not one\n * geometry; `listMeshes` counts them.\n */\nexport const geometryCensus = (root: Object3D, options: TriangleOptions = {}): GeometryRow[] => {\n const rows = new Map<string, GeometryRow>();\n\n walk(root, { skip: options.skip }, (object) => {\n if (!isMesh(object) || isBatched(object) || !object.geometry.attributes.position) {\n return;\n }\n\n const geometry = object.geometry;\n const key = geometry.name || `${geometry.type}:${geometry.uuid.slice(0, 6)}`;\n const triangles = triangleCount(geometry);\n const uses = isInstanced(object) ? object.count : 1;\n const row = rows.get(key) ?? { geometry: key, uses: 0, triangles, total: 0 };\n\n row.uses += uses;\n row.total += triangles * uses;\n rows.set(key, row);\n });\n\n return [...rows.values()].sort((a, b) => b.total - a.total);\n};\n","/**\n * Z-fighting found by geometry instead of by eye: pairs of meshes with triangles in (nearly) one\n * plane, facing the same way, overlapping. Those flicker wherever depth precision runs out.\n *\n * Triangles are bucketed by their quantised plane (normal and offset), so only triangles in\n * neighbouring buckets are compared; overlap in the shared plane is a separating-axis test.\n */\nimport type { Mesh, Object3D } from \"three\";\n\nimport {\n hasTag,\n isBatched,\n isInstanced,\n isMesh,\n materialName,\n meshName,\n type Skip,\n tagOf,\n walk,\n withHidden,\n} from \"./scene.ts\";\n\nexport type ZFightingOptions = {\n /**\n * How close two planes count as one, in world units. 0.004 (4 mm at 1 unit = 1 m) is about what\n * depth precision loses with a camera ~50 m out. Scale it with your units.\n */\n gap?: number;\n /** Also compare triangles within one mesh: for merged geometry whose parts share a buffer. */\n self?: boolean;\n /**\n * Only meshes inside a tagged object (`userData[tagKey]`), so a studio's ground and props stay\n * out. Defaults to true when anything under the root is tagged, false otherwise.\n */\n tagged?: boolean;\n tagKey?: string;\n skip?: Skip | undefined;\n};\n\nexport type ZFightingRow = {\n /** `tag/mesh [material] @ (x, y, z)`, the centre in world space. */\n a: string;\n b: string;\n /** Overlapping triangle pairs between the two. */\n triangles: number;\n /** Not enumerable: kept out of JSON and `console.table`. */\n readonly meshes: readonly [Mesh, Mesh];\n};\n\n/** Normals quantised to 1/40: neighbouring buckets are searched, so this only sets bucket size. */\nconst QUANT = 40;\n/** Normals this aligned count as parallel (about 2.6°). */\nconst PARALLEL = 0.999;\n\ntype Part = { mesh: Mesh; tag: string | null; min: number[]; max: number[] };\n\nconst round = (value: number) => Math.round(value * 100) / 100;\n\nconst labelOf = (part: Part) => {\n const centre = part.min.map((low, axis) => round((low + part.max[axis]!) / 2));\n const tag = part.tag === null ? \"\" : `${part.tag}/`;\n\n return `${tag}${meshName(part.mesh)} [${materialName(part.mesh)}] @ (${centre.join(\", \")})`;\n};\n\n/** Pairs of meshes that z-fight, most overlapping triangles first. `[]` is a pass. */\nexport const findZFighting = (root: Object3D, options: ZFightingOptions = {}): ZFightingRow[] => {\n const gap = options.gap ?? 0.004;\n const self = options.self ?? false;\n const tagKey = options.tagKey ?? \"studioObject\";\n const tagged = options.tagged ?? hasTag(root, tagKey, options.skip);\n\n root.updateWorldMatrix(true, true);\n\n const parts: Part[] = [];\n // Per triangle: its part, plane (nx, ny, nz, d) and world corners (9 numbers).\n const owner: number[] = [];\n const planes: number[] = [];\n const corners: number[] = [];\n const keys: [number, number, number, number][] = [];\n const buckets = new Map<string, number[]>();\n const keyOf = (x: number, y: number, z: number, d: number) => `${x},${y},${z},${d}`;\n\n walk(root, { skip: options.skip }, (object) => {\n if (\n !isMesh(object) ||\n isInstanced(object) ||\n isBatched(object) ||\n !object.geometry.attributes.position\n ) {\n return;\n }\n\n const tag = tagOf(object, tagKey);\n\n if (tagged && tag === null) {\n return;\n }\n\n const part = parts.length;\n const { index, attributes } = object.geometry;\n const position = attributes.position!;\n const e = object.matrixWorld.elements;\n const min = [Infinity, Infinity, Infinity];\n const max = [-Infinity, -Infinity, -Infinity];\n const count = index?.count ?? position.count;\n const world = [0, 0, 0, 0, 0, 0, 0, 0, 0];\n\n parts.push({ mesh: object, tag, min, max });\n\n for (let k = 0; k + 2 < count; k += 3) {\n for (let c = 0; c < 3; c += 1) {\n const v = index?.getX(k + c) ?? k + c;\n const x = position.getX(v);\n const y = position.getY(v);\n const z = position.getZ(v);\n\n for (let axis = 0; axis < 3; axis += 1) {\n const value = e[axis]! * x + e[axis + 4]! * y + e[axis + 8]! * z + e[axis + 12]!;\n\n world[c * 3 + axis] = value;\n min[axis] = Math.min(min[axis]!, value);\n max[axis] = Math.max(max[axis]!, value);\n }\n }\n\n const [ax, ay, az, bx, by, bz, cx, cy, cz] = world as [\n number,\n number,\n number,\n number,\n number,\n number,\n number,\n number,\n number,\n ];\n const ux = bx - ax;\n const uy = by - ay;\n const uz = bz - az;\n const vx = cx - ax;\n const vy = cy - ay;\n const vz = cz - az;\n let nx = uy * vz - uz * vy;\n let ny = uz * vx - ux * vz;\n let nz = ux * vy - uy * vx;\n const length = Math.hypot(nx, ny, nz);\n\n // Slivers under ~1e-5 m² show nothing.\n if (!(length / 2 >= 1e-5)) {\n continue;\n }\n\n nx /= length;\n ny /= length;\n nz /= length;\n\n const d = nx * ax + ny * ay + nz * az;\n const id = owner.length;\n const key: [number, number, number, number] = [\n Math.round(nx * QUANT),\n Math.round(ny * QUANT),\n Math.round(nz * QUANT),\n Math.round(d / gap),\n ];\n const bucket = buckets.get(keyOf(...key));\n\n owner.push(part);\n planes.push(nx, ny, nz, d);\n corners.push(...world);\n keys.push(key);\n\n if (bucket) {\n bucket.push(id);\n } else {\n buckets.set(keyOf(...key), [id]);\n }\n }\n });\n\n // Overlap in s's plane, with a margin so triangles merely sharing an edge don't count.\n const margin = gap / 2;\n const flat = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];\n\n const overlaps = (s: number, t: number) => {\n const S = s * 9;\n const T = t * 9;\n let ux = corners[S + 3]! - corners[S]!;\n let uy = corners[S + 4]! - corners[S + 1]!;\n let uz = corners[S + 5]! - corners[S + 2]!;\n const length = Math.hypot(ux, uy, uz) || 1;\n\n ux /= length;\n uy /= length;\n uz /= length;\n\n const nx = planes[s * 4]!;\n const ny = planes[s * 4 + 1]!;\n const nz = planes[s * 4 + 2]!;\n const vx = ny * uz - nz * uy;\n const vy = nz * ux - nx * uz;\n const vz = nx * uy - ny * ux;\n\n // Corners 0–2 are s, 3–5 are t, as (x, y) in the plane.\n for (let i = 0; i < 6; i += 1) {\n const at = i < 3 ? S + i * 3 : T + (i - 3) * 3;\n const px = corners[at]!;\n const py = corners[at + 1]!;\n const pz = corners[at + 2]!;\n\n flat[i * 2] = px * ux + py * uy + pz * uz;\n flat[i * 2 + 1] = px * vx + py * vy + pz * vz;\n }\n\n for (let edge = 0; edge < 6; edge += 1) {\n const from = edge;\n const to = edge < 3 ? (edge + 1) % 3 : 3 + ((edge + 1) % 3);\n const ex = flat[to * 2]! - flat[from * 2]!;\n const ey = flat[to * 2 + 1]! - flat[from * 2 + 1]!;\n const edgeLength = Math.hypot(ex, ey) || 1;\n const axisX = -ey / edgeLength;\n const axisY = ex / edgeLength;\n let p0 = Infinity;\n let p1 = -Infinity;\n let q0 = Infinity;\n let q1 = -Infinity;\n\n for (let i = 0; i < 6; i += 1) {\n const value = flat[i * 2]! * axisX + flat[i * 2 + 1]! * axisY;\n\n if (i < 3) {\n p0 = Math.min(p0, value);\n p1 = Math.max(p1, value);\n } else {\n q0 = Math.min(q0, value);\n q1 = Math.max(q1, value);\n }\n }\n\n if (Math.min(p1, q1) - Math.max(p0, q0) < margin) {\n return false;\n }\n }\n\n return true;\n };\n\n const pairs = new Map<string, { a: number; b: number; triangles: number }>();\n\n // Every neighbouring bucket, so near-equal planes that round apart still meet.\n for (let s = 0; s < owner.length; s += 1) {\n const [kx, ky, kz, kd] = keys[s]!;\n\n for (let i = -1; i <= 1; i += 1) {\n for (let j = -1; j <= 1; j += 1) {\n for (let k = -1; k <= 1; k += 1) {\n for (let l = -1; l <= 1; l += 1) {\n for (const t of buckets.get(keyOf(kx + i, ky + j, kz + k, kd + l)) ?? []) {\n const a = owner[s]!;\n const b = owner[t]!;\n\n if (\n t <= s ||\n (a === b && !self) ||\n planes[s * 4]! * planes[t * 4]! +\n planes[s * 4 + 1]! * planes[t * 4 + 1]! +\n planes[s * 4 + 2]! * planes[t * 4 + 2]! <\n PARALLEL ||\n Math.abs(planes[s * 4 + 3]! - planes[t * 4 + 3]!) > gap ||\n !overlaps(s, t)\n ) {\n continue;\n }\n\n const key = a < b ? `${a}:${b}` : `${b}:${a}`;\n const pair = pairs.get(key) ?? { a: Math.min(a, b), b: Math.max(a, b), triangles: 0 };\n\n pair.triangles += 1;\n pairs.set(key, pair);\n }\n }\n }\n }\n }\n }\n\n return [...pairs.values()]\n .sort((x, y) => y.triangles - x.triangles)\n .map(({ a, b, triangles }) =>\n withHidden({ a: labelOf(parts[a]!), b: labelOf(parts[b]!), triangles }, \"meshes\", [\n parts[a]!.mesh,\n parts[b]!.mesh,\n ] as const),\n );\n};\n","import type { Object3D } from \"three\";\n\nimport { type BadGeometryRow, findBadGeometry } from \"./bad-geometry.ts\";\nimport type { Skip } from \"./scene.ts\";\nimport { countTriangles, listMeshes, type MeshRow } from \"./triangles.ts\";\nimport { findZFighting, type ZFightingOptions, type ZFightingRow } from \"./z-fighting.ts\";\n\nexport type AuditSceneOptions = Pick<ZFightingOptions, \"gap\" | \"self\" | \"tagged\"> & {\n skip?: Skip | undefined;\n tagKey?: string;\n /** How many of the costliest meshes to list. */\n top?: number;\n};\n\nexport type AuditReport = {\n triangles: number;\n zFighting: ZFightingRow[];\n badGeometry: BadGeometryRow[];\n /** The costliest meshes, most triangles first. */\n meshes: MeshRow[];\n};\n\n/**\n * Every check at once, JSON-safe: what a test asserts on or a headless browser prints. A clean\n * scene has `zFighting` and `badGeometry` both `[]`.\n */\nexport const auditScene = (root: Object3D, options: AuditSceneOptions = {}): AuditReport => {\n const { skip, tagKey } = options;\n\n return {\n triangles: countTriangles(root, { skip }),\n zFighting: findZFighting(root, options),\n badGeometry: findBadGeometry(root, tagKey === undefined ? { skip } : { skip, tagKey }),\n meshes: listMeshes(root, { skip }).slice(0, options.top ?? 10),\n };\n};\n","/** Swap `key` on `target` for `value`; the returned function puts back exactly what was there. */\nexport const patch = <Target extends object, Key extends keyof Target>(\n target: Target,\n key: Key,\n value: Target[Key],\n) => {\n const own = Object.hasOwn(target, key);\n const original = target[key];\n\n target[key] = value;\n\n return () => {\n if (own) {\n target[key] = original;\n } else {\n delete target[key];\n }\n };\n};\n","/**\n * Black-frame probe: after each frame, samples a grid of the drawing buffer and counts frames\n * where several samples are pure black. Catches the flash a NaN pixel makes once bloom spreads it,\n * which lasts one frame in twenty and never shows in a screenshot.\n *\n * WebGL only (`readPixels`). Each sample stalls the GPU pipeline, so watch, read, stop.\n */\nimport type { Camera, Object3D } from \"three\";\n\nimport { patch } from \"./patch.ts\";\n\n/** The `WebGLRenderer` methods the probe uses. */\nexport type ProbeRenderer = {\n render(scene: Object3D, camera: Camera): void;\n getContext(): unknown;\n getRenderTarget(): unknown;\n};\n\nexport type BlackFrameOptions = {\n /** Samples per side: 3 reads a 3 × 3 grid at the quarter lines. */\n grid?: number;\n /** Black samples that make a frame black. */\n threshold?: number;\n};\n\nexport type BlackFrameWatch = {\n /** Frames sampled since the start or the last `reset()`. */\n readonly frames: number;\n /** Which of those frames (1-based) were black. */\n readonly blackFrames: readonly number[];\n reset: () => void;\n /** Restore the renderer and stop sampling. */\n stop: () => void;\n};\n\ntype ReadPixels = Pick<\n WebGLRenderingContext,\n \"RGBA\" | \"UNSIGNED_BYTE\" | \"drawingBufferHeight\" | \"drawingBufferWidth\" | \"readPixels\"\n>;\n\n/**\n * Sample every frame the app draws to the screen. Several screen renders in one frame (an overlay\n * redrawn after the composer) count once, as the last of them: the image the display shows.\n * Browser only: frames are told apart by `requestAnimationFrame`.\n */\nexport const watchBlackFrames = (\n renderer: ProbeRenderer,\n options: BlackFrameOptions = {},\n): BlackFrameWatch => {\n const context = renderer.getContext() as Partial<ReadPixels> | null;\n\n if (typeof context?.readPixels !== \"function\") {\n throw new TypeError(\"three-audit: the black-frame probe needs a WebGLRenderer\");\n }\n\n if (typeof requestAnimationFrame !== \"function\") {\n throw new TypeError(\"three-audit: the black-frame probe needs requestAnimationFrame\");\n }\n\n const gl = context as ReadPixels;\n const grid = options.grid ?? 3;\n const threshold = options.threshold ?? 3;\n const pixel = new Uint8Array(4);\n const render = renderer.render;\n let frames = 0;\n let black: number[] = [];\n let pending: boolean | null = null;\n\n const isBlack = () => {\n let count = 0;\n\n for (let i = 1; i <= grid; i += 1) {\n for (let j = 1; j <= grid; j += 1) {\n const x = Math.floor((gl.drawingBufferWidth * i) / (grid + 1));\n const y = Math.floor((gl.drawingBufferHeight * j) / (grid + 1));\n\n gl.readPixels(x, y, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, pixel);\n\n if (pixel[0]! < 4 && pixel[1]! < 4 && pixel[2]! < 4 && pixel[3]! > 250) {\n count += 1;\n }\n }\n }\n\n return count >= threshold;\n };\n\n // Commit the frame's last screen sample once per animation frame.\n let raf = 0;\n const commit = () => {\n if (pending !== null) {\n frames += 1;\n\n if (pending) {\n black.push(frames);\n }\n\n pending = null;\n }\n\n raf = requestAnimationFrame(commit);\n };\n\n raf = requestAnimationFrame(commit);\n\n const restore = patch(renderer, \"render\", function (this: unknown, scene, camera) {\n render.call(this, scene, camera);\n\n // Read before the browser presents (and, without preserveDrawingBuffer, clears) the buffer.\n if (renderer.getRenderTarget() === null) {\n pending = isBlack();\n }\n });\n\n return {\n get frames() {\n return frames;\n },\n get blackFrames() {\n return black;\n },\n reset: () => {\n frames = 0;\n black = [];\n pending = null;\n },\n stop: () => {\n cancelAnimationFrame(raf);\n restore();\n },\n };\n};\n","/**\n * A ledger of every draw call over one frame: which object drew, in which pass. Exact counts from\n * the renderer itself, where `renderer.info` gives one total (and resets it every `render()`).\n *\n * WebGL only: it wraps `WebGLRenderer.renderBufferDirect`, which every draw goes through, and\n * `render()`, to tell passes apart. Draws with a depth or distance material are the shadow maps.\n */\nimport type { BufferGeometry, Camera, Material, Object3D, Scene } from \"three\";\n\nimport { patch } from \"./patch.ts\";\n\n/** The two `WebGLRenderer` methods the ledger wraps. */\nexport type LedgerRenderer = {\n render(scene: Object3D, camera: Camera): void;\n renderBufferDirect(\n camera: Camera,\n scene: Scene | null,\n geometry: BufferGeometry,\n material: Material,\n object: Object3D,\n group: unknown,\n ): void;\n};\n\nexport type DrawLedgerOptions = {\n /**\n * The group an object name files under. Default: up to the first `:` or `#`, so a bake's\n * `wagon:paint` and a strip's `grass#3` group as `wagon` and `grass`.\n */\n groupOf?: (name: string) => string;\n};\n\nexport type LedgerRow = {\n name: string;\n total: number;\n /** Draws per pass name. */\n passes: Record<string, number>;\n};\n\nexport type DrawLedger = {\n /**\n * Pass names in the order they first drew: `shadow`, then each `render()` call as its scene's\n * name, or `render 1`, `render 2`… when unnamed (a post-processing chain is several).\n */\n passes: string[];\n /** By group, most draws first. */\n groups: LedgerRow[];\n /** By object name, most draws first. */\n objects: LedgerRow[];\n draws: number;\n};\n\nexport type DrawLedgerRecording = {\n /** Restore the renderer and return what was drawn since `beginDrawLedger`. */\n end: () => DrawLedger;\n};\n\nconst defaultGroupOf = (name: string) => name.split(/[:#]/)[0] || name;\n\nconst nameOf = (object: Object3D, material: Material) =>\n object.name || `${object.type}:${material.name || material.type}`;\n\nconst tally = (rows: Map<string, LedgerRow>, name: string, pass: string) => {\n const row = rows.get(name) ?? { name, total: 0, passes: {} };\n\n row.total += 1;\n row.passes[pass] = (row.passes[pass] ?? 0) + 1;\n rows.set(name, row);\n};\n\nconst sorted = (rows: Map<string, LedgerRow>) =>\n [...rows.values()].sort((a, b) => b.total - a.total);\n\n/** Start counting every draw. Call `end()` after the frame to restore the renderer and read it. */\nexport const beginDrawLedger = (\n renderer: LedgerRenderer,\n options: DrawLedgerOptions = {},\n): DrawLedgerRecording => {\n if (typeof renderer.renderBufferDirect !== \"function\") {\n throw new TypeError(\"three-audit: the draw ledger needs a WebGLRenderer\");\n }\n\n const groupOf = options.groupOf ?? defaultGroupOf;\n const render = renderer.render;\n const renderBufferDirect = renderer.renderBufferDirect;\n const passes: string[] = [];\n const objects = new Map<string, LedgerRow>();\n const groups = new Map<string, LedgerRow>();\n let renders = 0;\n let current = \"direct\";\n let draws = 0;\n\n const restoreRender = patch(renderer, \"render\", function (this: unknown, scene, camera) {\n const outer = current;\n\n renders += 1;\n current = scene.name || `render ${renders}`;\n\n try {\n render.call(this, scene, camera);\n } finally {\n current = outer;\n }\n });\n\n const restoreDraw = patch(\n renderer,\n \"renderBufferDirect\",\n function (this: unknown, camera, scene, geometry, material, object, group) {\n const shadow =\n (material as { isMeshDepthMaterial?: boolean }).isMeshDepthMaterial === true ||\n (material as { isMeshDistanceMaterial?: boolean }).isMeshDistanceMaterial === true;\n const pass = shadow ? \"shadow\" : current;\n const name = nameOf(object, material);\n\n if (!passes.includes(pass)) {\n passes.push(pass);\n }\n\n draws += 1;\n tally(objects, name, pass);\n tally(groups, groupOf(name), pass);\n renderBufferDirect.call(this, camera, scene, geometry, material, object, group);\n },\n );\n\n return {\n end: () => {\n restoreDraw();\n restoreRender();\n\n return { passes, groups: sorted(groups), objects: sorted(objects), draws };\n },\n };\n};\n\n/**\n * Record exactly one frame of an app that renders from `requestAnimationFrame` (three's\n * `setAnimationLoop`, React Three Fiber): from one animation frame to the next. A demand-driven\n * loop that renders nothing that frame gives an empty ledger. Browser only.\n */\nexport const recordDrawLedger = (renderer: LedgerRenderer, options: DrawLedgerOptions = {}) =>\n new Promise<DrawLedger>((resolve, reject) => {\n if (typeof requestAnimationFrame !== \"function\") {\n reject(new Error(\"three-audit: recordDrawLedger needs requestAnimationFrame\"));\n\n return;\n }\n\n requestAnimationFrame(() => {\n try {\n const recording = beginDrawLedger(renderer, options);\n\n requestAnimationFrame(() => resolve(recording.end()));\n } catch (error) {\n reject(error);\n }\n });\n });\n\n/** Rows shaped for `console.table`: one column per pass, then the total. */\nexport const ledgerTable = (rows: LedgerRow[], passes: string[]) =>\n rows.map((row) => ({\n name: row.name,\n ...Object.fromEntries(passes.map((pass) => [pass, row.passes[pass] ?? 0])),\n total: row.total,\n }));\n\n/** The ledger as two console tables: by group, and every object collapsed beneath. */\nexport const printDrawLedger = (ledger: DrawLedger) => {\n /* oxlint-disable no-console -- printing is this function's job */\n console.group(`Draw ledger: ${ledger.draws} draws in one frame`);\n console.table(ledgerTable(ledger.groups, ledger.passes));\n console.groupCollapsed(\"Every object\");\n console.table(ledgerTable(ledger.objects, ledger.passes));\n console.groupEnd();\n console.groupEnd();\n /* oxlint-enable no-console */\n};\n","/**\n * The checks as short console globals, for a dev page or a headless browser's `eval`:\n * `tris()`, `meshes()`, `census()`, `audit()`, `zfight()`, `report()`, and with a renderer\n * `ledger()` and `blackFrames()`.\n */\nimport type { Object3D } from \"three\";\n\nimport { auditScene } from \"./audit-scene.ts\";\nimport { findBadGeometry } from \"./bad-geometry.ts\";\nimport { type ProbeRenderer, watchBlackFrames } from \"./black-frames.ts\";\nimport { type LedgerRenderer, printDrawLedger, recordDrawLedger } from \"./draw-ledger.ts\";\nimport type { Skip } from \"./scene.ts\";\nimport { countTriangles, geometryCensus, listMeshes } from \"./triangles.ts\";\nimport { findZFighting } from \"./z-fighting.ts\";\n\nexport type AuditHelpersOptions = {\n /** A `WebGLRenderer`, for `ledger()` and `blackFrames()`. */\n renderer?: (LedgerRenderer & ProbeRenderer) | undefined;\n skip?: Skip | undefined;\n tagKey?: string;\n};\n\nconst NAMES = [\n \"auditRoot\",\n \"tris\",\n \"meshes\",\n \"census\",\n \"audit\",\n \"zfight\",\n \"report\",\n \"ledger\",\n \"blackFrames\",\n] as const;\n\nconst needsRenderer = (name: string) => () => {\n throw new Error(`three-audit: ${name}() needs installAuditHelpers(scene, { renderer })`);\n};\n\n/**\n * Put the helpers on `globalThis`. Returns a function that removes them.\n *\n * vanilla: installAuditHelpers(scene, { renderer })\n * R3F: const { scene, gl } = useThree();\n * useLayoutEffect(() => installAuditHelpers(scene, { renderer: gl }), [scene, gl]);\n */\nexport const installAuditHelpers = (root: Object3D, options: AuditHelpersOptions = {}) => {\n const { renderer, skip } = options;\n const tagKey = options.tagKey ?? \"studioObject\";\n\n const helpers: Record<(typeof NAMES)[number], unknown> = {\n auditRoot: root,\n tris: () => countTriangles(root, { skip }),\n meshes: () => listMeshes(root, { skip }),\n census: () => geometryCensus(root, { skip }),\n audit: () => findBadGeometry(root, { skip, tagKey }),\n zfight: (gap?: number, self?: boolean) =>\n findZFighting(root, {\n skip,\n tagKey,\n ...(gap === undefined ? {} : { gap }),\n ...(self === undefined ? {} : { self }),\n }),\n report: () => auditScene(root, { skip, tagKey }),\n ledger: renderer\n ? async () => {\n const ledger = await recordDrawLedger(renderer);\n\n printDrawLedger(ledger);\n\n return ledger;\n }\n : needsRenderer(\"ledger\"),\n blackFrames: renderer\n ? (seconds = 10) =>\n new Promise<{ frames: number; blackFrames: readonly number[] }>((resolve) => {\n const watch = watchBlackFrames(renderer);\n\n setTimeout(() => {\n watch.stop();\n resolve({ frames: watch.frames, blackFrames: watch.blackFrames });\n }, seconds * 1000);\n })\n : needsRenderer(\"blackFrames\"),\n };\n\n Object.assign(globalThis, helpers);\n\n return () => {\n const scope = globalThis as Record<string, unknown>;\n\n for (const name of NAMES) {\n if (scope[name] === helpers[name]) {\n delete scope[name];\n }\n }\n };\n};\n"],"mappings":";;AAkBA,MAAa,QAAQ,MAAgB,SAAsB,UAAsC;CAC/F,MAAM,QAAQ,CAAC,IAAI;CAEnB,OAAO,MAAM,SAAS,GAAG;EACvB,MAAM,SAAS,MAAM,IAAI;EAEzB,IAAK,QAAQ,gBAAgB,QAAQ,CAAC,OAAO,WAAY,QAAQ,OAAO,MAAM,MAAM,MAClF;EAGF,MAAM,MAAM;EAEZ,KAAK,IAAI,IAAI,OAAO,SAAS,SAAS,GAAG,KAAK,GAAG,KAAK,GACpD,MAAM,KAAK,OAAO,SAAS,EAAG;CAElC;AACF;AAEA,MAAa,UAAU,WAAsC,OAAgB,WAAW;AAExF,MAAa,eAAe,SACzB,KAAuB,oBAAoB;AAE9C,MAAa,aAAa,SACvB,KAAgC,kBAAkB;;AAGrD,MAAa,iBAAiB,aAA6B;CACzD,MAAM,WAAW,SAAS,OAAO,SAAS,SAAS,WAAW,UAAU,SAAS;CACjF,MAAM,EAAE,OAAO,UAAU,SAAS;CAClC,MAAM,QAAQ,KAAK,IAAI,U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AM;GAClB;GACA;GACA,GAAI,QAAQ,KAAA,IAAY,CAAC,IAAI,EAAE,IAAI;GACnC,GAAI,SAAS,KAAA,IAAY,CAAC,IAAI,EAAE,KAAK;EACvC,CAAC;EACH,cAAc,WAAW,MAAM;GAAE;GAAM;EAAO,CAAC;EAC/C,QAAQ,WACJ,YAAY;GACV,MAAM,SAAS,MAAM,iBAAiB,QAAQ;GAE9C,gBAAgB,MAAM;GAEtB,OAAO;EACT,IACA,cAAc,QAAQ;EAC1B,aAAa,YACR,UAAU,OACT,IAAI,SAA6D,YAAY;GAC3E,MAAM,QAAQ,iBAAiB,QAAQ;GAEvC,iBAAiB;IACf,MAAM,KAAK;IACX,QAAQ;KAAE,QAAQ,MAAM;KAAQ,aAAa,MAAM;IAAY,CAAC;GAClE,GAAG,UAAU,GAAI;EACnB,CAAC,IACH,cAAc,aAAa;CACjC;CAEA,OAAO,OAAO,YAAY,OAAO;CAEjC,aAAa;EACX,MAAM,QAAQ;EAEd,KAAK,MAAM,QAAQ,OACjB,IAAI,MAAM,UAAU,QAAQ,OAC1B,OAAO,MAAM;CAGnB;AACF"}
|
package/package.json
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@zkmake/three-audit",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Scene checks for three.js: triangle counts, cost census, NaN normals, z-fighting, black frames and a one-frame draw-call ledger. Zero dependencies.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"audit",
|
|
7
|
+
"devtools",
|
|
8
|
+
"draw-calls",
|
|
9
|
+
"lint",
|
|
10
|
+
"r3f",
|
|
11
|
+
"three",
|
|
12
|
+
"threejs",
|
|
13
|
+
"triangles",
|
|
14
|
+
"z-fighting"
|
|
15
|
+
],
|
|
16
|
+
"homepage": "https://github.com/zkmake/three-kit/tree/main/packages/three-audit#readme",
|
|
17
|
+
"bugs": "https://github.com/zkmake/three-kit/issues",
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"author": "Zubin Khavarian",
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/zkmake/three-kit.git",
|
|
23
|
+
"directory": "packages/three-audit"
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"dist",
|
|
27
|
+
"README.md",
|
|
28
|
+
"LICENSE"
|
|
29
|
+
],
|
|
30
|
+
"type": "module",
|
|
31
|
+
"sideEffects": false,
|
|
32
|
+
"exports": {
|
|
33
|
+
".": "./dist/index.js",
|
|
34
|
+
"./package.json": "./package.json"
|
|
35
|
+
},
|
|
36
|
+
"publishConfig": {
|
|
37
|
+
"access": "public"
|
|
38
|
+
},
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "tsdown",
|
|
41
|
+
"ci:test": "vitest run",
|
|
42
|
+
"ci:typecheck": "tsc",
|
|
43
|
+
"pack:check": "npm pack --dry-run",
|
|
44
|
+
"test": "vitest watch",
|
|
45
|
+
"typecheck": "tsc"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@arethetypeswrong/core": "catalog:",
|
|
49
|
+
"@types/three": "catalog:",
|
|
50
|
+
"publint": "catalog:",
|
|
51
|
+
"three": "catalog:",
|
|
52
|
+
"tsdown": "catalog:",
|
|
53
|
+
"typescript": "catalog:",
|
|
54
|
+
"vitest": "catalog:"
|
|
55
|
+
},
|
|
56
|
+
"peerDependencies": {
|
|
57
|
+
"three": ">=0.160"
|
|
58
|
+
},
|
|
59
|
+
"engines": {
|
|
60
|
+
"node": ">=20.19"
|
|
61
|
+
}
|
|
62
|
+
}
|