@threenative/core 0.3.4 → 0.3.6
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/capabilities.json +1505 -79
- package/dist/{audio-7i3Xl0l3.d.ts → audio-DIJE5HTr.d.ts} +43 -3
- package/dist/{canvas-layer-DDmC_VVF.d.ts → canvas-layer-C1-5CviZ.d.ts} +5 -1
- package/dist/{game-CljaDv4D.d.ts → game-Jz4Fdoeb.d.ts} +114 -11
- package/dist/hot.d.ts +4 -4
- package/dist/index.d.ts +712 -118
- package/dist/index.js +12437 -4955
- package/dist/{gpu-readback-CqJEfWNQ.d.ts → model-lod-BDAUYgsS.d.ts} +80 -5
- package/dist/playtest.d.ts +6 -10
- package/dist/playtest.js +57 -24
- package/dist/react-css.d.ts +62 -0
- package/dist/react-css.js +591 -0
- package/dist/react.d.ts +2 -2
- package/dist/{renderer-CfsS2hxi.d.ts → renderer-9yEo9hPa.d.ts} +489 -22
- package/dist/terrain-jobs-worker.d.ts +2 -0
- package/dist/terrain-jobs-worker.js +130 -0
- package/dist/ui-layer.js +59 -8
- package/dist/world.d.ts +766 -73
- package/dist/world.js +9307 -3543
- package/gpl/recipes/export_world.py +18 -1
- package/mcp/blender-server.mjs +7 -4
- package/mcp/blender.mjs +3 -4
- package/mcp/engine-server.mjs +2 -2
- package/mcp/servers.mjs +4 -4
- package/package.json +15 -9
- package/patches/three@0.185.1-prd269-upgrade.patch +22418 -0
- package/patches/three@0.185.1.patch +6594 -700
- package/scripts/apply-three-patch.mjs +62 -4
- package/src/animation-blend.ts +264 -0
- package/src/animation-composition.ts +362 -0
- package/src/animation-layers.ts +260 -0
- package/src/animation-root-motion.ts +283 -0
- package/src/animation.ts +896 -0
- package/src/assets.ts +1303 -0
- package/src/atmosphere/index.ts +335 -0
- package/src/atmosphere/luts.ts +298 -0
- package/src/atmosphere/params.ts +323 -0
- package/src/audio.ts +912 -0
- package/src/billboard.ts +124 -0
- package/src/bone-lengths.ts +157 -0
- package/src/camera-shake.ts +116 -0
- package/src/canvas-layer.ts +47 -0
- package/src/clip-audit.ts +401 -0
- package/src/clustered-batch.ts +492 -0
- package/src/clustered-mesh.ts +638 -0
- package/src/compute-driven.ts +176 -0
- package/src/compute-timing.ts +318 -0
- package/src/config.ts +593 -0
- package/src/debug.ts +82 -0
- package/src/engine-render-hook.ts +25 -0
- package/src/entities.ts +79 -0
- package/src/entity-snapshot.ts +53 -0
- package/src/flight.ts +683 -0
- package/src/fluid-field.ts +748 -0
- package/src/fluid-particles.ts +1253 -0
- package/src/frame-budget.ts +1368 -0
- package/src/game.ts +2408 -0
- package/src/geometry-capture.ts +1098 -0
- package/src/gpu-class.ts +160 -0
- package/src/gpu-frame-observation.ts +424 -0
- package/src/gpu-readback.ts +143 -0
- package/src/gpu-scene-bvh.ts +464 -0
- package/src/grounding.ts +100 -0
- package/src/hot.ts +161 -0
- package/src/import-meta.d.ts +13 -0
- package/src/index.ts +1536 -0
- package/src/input.ts +690 -0
- package/src/instanced-batch-lod.ts +283 -0
- package/src/instanced-batch.ts +274 -0
- package/src/interpolation.ts +129 -0
- package/src/launch-diagnostics.ts +161 -0
- package/src/loop.ts +574 -0
- package/src/matrix-world.ts +245 -0
- package/src/merge-parts.ts +812 -0
- package/src/model-lod.ts +1315 -0
- package/src/net-protocol.ts +333 -0
- package/src/net-session.ts +477 -0
- package/src/net.ts +80 -0
- package/src/ocean/fft.ts +72 -0
- package/src/ocean/spectral.ts +728 -0
- package/src/particle-significance.ts +102 -0
- package/src/particles.ts +648 -0
- package/src/path-follow.ts +175 -0
- package/src/picking.ts +250 -0
- package/src/pipeline-census.ts +1566 -0
- package/src/platform.ts +210 -0
- package/src/playtest.ts +850 -0
- package/src/pointer-events.ts +411 -0
- package/src/pose-measure.ts +435 -0
- package/src/profiling/FrameCounters.ts +231 -0
- package/src/profiling/Spans.ts +548 -0
- package/src/profiling/opacity-convention.ts +21 -0
- package/src/profiling/render-list-validate.ts +175 -0
- package/src/profiling/render-trap-audit.ts +84 -0
- package/src/profiling/scene-warning.ts +190 -0
- package/src/profiling/span-probes.ts +191 -0
- package/src/profiling/unlit-foliage-warning.ts +149 -0
- package/src/projection-apply.ts +1529 -0
- package/src/projection-marker.ts +142 -0
- package/src/projection-plan.ts +1258 -0
- package/src/projection-skinned.ts +419 -0
- package/src/projection-stability.ts +409 -0
- package/src/projection-uniform.ts +328 -0
- package/src/random.ts +41 -0
- package/src/react-css.ts +604 -0
- package/src/react-glyphs.ts +114 -0
- package/src/react-host.ts +576 -0
- package/src/react-layout.ts +265 -0
- package/src/react.ts +60 -0
- package/src/render/alpha-antialiasing.ts +159 -0
- package/src/render/batched-velocity.ts +126 -0
- package/src/render/chain.ts +1021 -0
- package/src/render/daylight.ts +189 -0
- package/src/render/depth-pyramid.ts +596 -0
- package/src/render/foliage-alpha.ts +166 -0
- package/src/render/material-key.ts +60 -0
- package/src/render/mesh-pool.ts +144 -0
- package/src/render/probe-volume.ts +1668 -0
- package/src/render/resolution-subrect.ts +253 -0
- package/src/render/velocity.ts +442 -0
- package/src/render/virtual-shadow-pages.ts +827 -0
- package/src/render/virtual-shadow-partial.ts +174 -0
- package/src/render/virtual-shadow.ts +3330 -0
- package/src/render/world-impostor-surface.ts +722 -0
- package/src/render/world-impostor.ts +558 -0
- package/src/render-camera-cull.ts +441 -0
- package/src/render-pass-budget.ts +501 -0
- package/src/renderProjection.ts +758 -0
- package/src/renderer-config.ts +127 -0
- package/src/renderer.ts +1847 -0
- package/src/replay-protocol.ts +85 -0
- package/src/replay.ts +205 -0
- package/src/resolution-scaler.ts +819 -0
- package/src/rig-preparation.ts +271 -0
- package/src/ripple-field.ts +432 -0
- package/src/scale.ts +109 -0
- package/src/scene.ts +239 -0
- package/src/schedule.ts +155 -0
- package/src/skeletal-mesh.ts +61 -0
- package/src/skeleton.ts +100 -0
- package/src/snow-field.ts +744 -0
- package/src/softbody-topology.ts +269 -0
- package/src/softbody.ts +516 -0
- package/src/sprite-animator.ts +222 -0
- package/src/startup-readiness.ts +386 -0
- package/src/state.ts +66 -0
- package/src/static-transform.ts +274 -0
- package/src/storage-buffer.ts +253 -0
- package/src/streaming.ts +308 -0
- package/src/target-fps.ts +92 -0
- package/src/terrain-jobs-worker.ts +17 -0
- package/src/terrain-jobs.ts +353 -0
- package/src/textures.ts +39 -0
- package/src/tracers.ts +237 -0
- package/src/ui-bridge.ts +368 -0
- package/src/ui-hit-regions.ts +380 -0
- package/src/ui-layer.ts +83 -0
- package/src/ui-state.ts +220 -0
- package/src/version.ts +2 -0
- package/src/viewport.ts +253 -0
- package/src/warmup.ts +1357 -0
- package/src/water-surface.ts +384 -0
- package/src/wave-field.ts +524 -0
- package/src/world-capabilities.ts +131 -0
- package/src/world-cell-proxy.ts +392 -0
- package/src/world-cells.ts +10564 -0
- package/src/world-gpu-scene.ts +3354 -0
- package/src/world-heightmap.ts +82 -0
- package/src/world-package.ts +469 -0
- package/src/world-passes.ts +582 -0
- package/src/world-region.ts +17 -0
- package/src/world-terrain-splat.ts +564 -0
- package/src/world-tiles.ts +3826 -0
- package/src/world-topology.ts +370 -0
- package/src/world-validate.ts +48 -0
- package/src/world.ts +805 -0
|
@@ -0,0 +1,409 @@
|
|
|
1
|
+
import type { BufferGeometry, Material, Object3D, Scene } from "three";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
type IProjectionExactEntry,
|
|
5
|
+
type IProjectionScanResult,
|
|
6
|
+
displacesVertices,
|
|
7
|
+
geometryVersionSum,
|
|
8
|
+
hasMorphAttributes,
|
|
9
|
+
hasRenderHook,
|
|
10
|
+
isLight,
|
|
11
|
+
isRenderable,
|
|
12
|
+
} from "./projection-plan.js";
|
|
13
|
+
import type { ProjectionExactReason } from "./renderProjection.js";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The proof that a frame's classification is the one the last frame already derived.
|
|
17
|
+
*
|
|
18
|
+
* The scan is a pure function of the scene's **structure** and reads no world matrix: membership,
|
|
19
|
+
* each renderable's geometry, material and batching flags, its own and inherited visibility, and
|
|
20
|
+
* the lane predicates over that geometry and material. Every one of those can change at any time,
|
|
21
|
+
* so a frame may only skip the scan after proving the inputs are identical — and "identical" is
|
|
22
|
+
* checkable cheaply, because a changed input has to show up as a changed *value*.
|
|
23
|
+
*
|
|
24
|
+
* So this keeps what the last scan read, in the order the scan read it, and compares. The
|
|
25
|
+
* comparison is deliberately dumber than the classification: it reads the same fields the
|
|
26
|
+
* predicates read and compares them, where re-running the predicates would cost what the skip is
|
|
27
|
+
* for. Each distinct material and geometry is compared once per frame rather than once per object
|
|
28
|
+
* that shares it, because those values are per-material and per-geometry — that is what makes a
|
|
29
|
+
* 4,096-mesh scene cost a handful of extra reads instead of four thousand.
|
|
30
|
+
*
|
|
31
|
+
* What a move is *not*: the matrices. An object that animates every frame is still the same object
|
|
32
|
+
* in the same group, so its matrix moving is not a reason to classify it again — the mirror's apply
|
|
33
|
+
* writes that matrix into the baked draw every frame regardless, which is where a move belongs.
|
|
34
|
+
*
|
|
35
|
+
* A skip is only ever a *skip of the classification*. Everything the renderer is handed — batch
|
|
36
|
+
* slots, stand-ins, mirrored lights, retirement — is still rebuilt by the apply seam each frame, so
|
|
37
|
+
* a wrong answer here costs a re-scan and never a wrong picture.
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
/** One renderable's structure: every scan input a transform cannot change. */
|
|
41
|
+
interface IWatchedRenderable {
|
|
42
|
+
geometry: BufferGeometry | undefined;
|
|
43
|
+
material: Material | Material[] | undefined;
|
|
44
|
+
customDepthMaterial: unknown;
|
|
45
|
+
customDistanceMaterial: unknown;
|
|
46
|
+
layersMask: number;
|
|
47
|
+
renderOrder: number;
|
|
48
|
+
/** The class flags, the render hook, the batching flags and own visibility, as one number. */
|
|
49
|
+
kind: number;
|
|
50
|
+
/** Whether the game wants this drawn, ancestors included. */
|
|
51
|
+
visible: boolean;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** One distinct material's lane predicates, compared once a frame however many objects share it. */
|
|
55
|
+
interface IWatchedMaterial {
|
|
56
|
+
material: Material;
|
|
57
|
+
lane: number;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** One distinct geometry's lane predicates plus the version sum the material lane watches. */
|
|
61
|
+
interface IWatchedGeometry {
|
|
62
|
+
geometry: BufferGeometry;
|
|
63
|
+
lane: number;
|
|
64
|
+
version: number;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const KIND_LIGHT = 1;
|
|
68
|
+
const KIND_LOD = 2;
|
|
69
|
+
const KIND_RENDERABLE = 4;
|
|
70
|
+
const KIND_SKINNED = 8;
|
|
71
|
+
const KIND_INSTANCED = 16;
|
|
72
|
+
const KIND_BATCHED_SOURCE = 32;
|
|
73
|
+
const KIND_HOOK = 64;
|
|
74
|
+
const KIND_CAST_SHADOW = 128;
|
|
75
|
+
const KIND_RECEIVE_SHADOW = 256;
|
|
76
|
+
const KIND_FRUSTUM_CULLED = 512;
|
|
77
|
+
const KIND_VISIBLE = 1_024;
|
|
78
|
+
|
|
79
|
+
const MATERIAL_MULTI = 1;
|
|
80
|
+
const MATERIAL_TRANSPARENT = 2;
|
|
81
|
+
const MATERIAL_DISPLACED = 4;
|
|
82
|
+
|
|
83
|
+
const GEOMETRY_NO_POSITION = 1;
|
|
84
|
+
const GEOMETRY_INDIRECT = 2;
|
|
85
|
+
const GEOMETRY_MORPH = 4;
|
|
86
|
+
const GEOMETRY_DRAW_RANGE = 8;
|
|
87
|
+
|
|
88
|
+
type ProjectionCandidate = Object3D & {
|
|
89
|
+
isInstancedMesh?: boolean;
|
|
90
|
+
isBatchedMesh?: boolean;
|
|
91
|
+
isSkinnedMesh?: boolean;
|
|
92
|
+
geometry?: BufferGeometry;
|
|
93
|
+
material?: Material | Material[];
|
|
94
|
+
customDepthMaterial?: unknown;
|
|
95
|
+
customDistanceMaterial?: unknown;
|
|
96
|
+
renderOrder?: number;
|
|
97
|
+
castShadow?: boolean;
|
|
98
|
+
receiveShadow?: boolean;
|
|
99
|
+
frustumCulled?: boolean;
|
|
100
|
+
layers: { mask: number };
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
function kindOf(object: Object3D): number {
|
|
104
|
+
const candidate = object as ProjectionCandidate;
|
|
105
|
+
let kind = 0;
|
|
106
|
+
if (isLight(object)) kind |= KIND_LIGHT;
|
|
107
|
+
if ((object as { isLOD?: boolean }).isLOD === true) kind |= KIND_LOD;
|
|
108
|
+
if (isRenderable(object)) {
|
|
109
|
+
kind |= KIND_RENDERABLE;
|
|
110
|
+
if (candidate.isSkinnedMesh === true) kind |= KIND_SKINNED;
|
|
111
|
+
if (candidate.isInstancedMesh === true) kind |= KIND_INSTANCED;
|
|
112
|
+
if (candidate.isBatchedMesh === true) kind |= KIND_BATCHED_SOURCE;
|
|
113
|
+
if (candidate.castShadow === true) kind |= KIND_CAST_SHADOW;
|
|
114
|
+
if (candidate.receiveShadow === true) kind |= KIND_RECEIVE_SHADOW;
|
|
115
|
+
if (candidate.frustumCulled === true) kind |= KIND_FRUSTUM_CULLED;
|
|
116
|
+
if (object.visible) kind |= KIND_VISIBLE;
|
|
117
|
+
}
|
|
118
|
+
if (hasRenderHook(object)) kind |= KIND_HOOK;
|
|
119
|
+
return kind;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function materialLane(material: Material | Material[] | undefined): number {
|
|
123
|
+
if (material === undefined) return 0;
|
|
124
|
+
if (Array.isArray(material)) return MATERIAL_MULTI;
|
|
125
|
+
return (
|
|
126
|
+
(material.transparent === true ? MATERIAL_TRANSPARENT : 0) |
|
|
127
|
+
(displacesVertices(material) ? MATERIAL_DISPLACED : 0)
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function geometryLane(geometry: BufferGeometry | undefined): number {
|
|
132
|
+
if (geometry === undefined) return 0;
|
|
133
|
+
let lane = 0;
|
|
134
|
+
if (geometry.attributes.position === undefined) lane |= GEOMETRY_NO_POSITION;
|
|
135
|
+
if ((geometry as { indirect?: unknown }).indirect != null) lane |= GEOMETRY_INDIRECT;
|
|
136
|
+
if (hasMorphAttributes(geometry)) lane |= GEOMETRY_MORPH;
|
|
137
|
+
const range = geometry.drawRange;
|
|
138
|
+
if (range !== undefined && (range.start !== 0 || Number.isFinite(range.count)))
|
|
139
|
+
lane |= GEOMETRY_DRAW_RANGE;
|
|
140
|
+
return lane;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* A host whose objects live outside the script engine can hash what the scan reads from them (the
|
|
145
|
+
* walk order, visibility, and each mesh's geometry, material, flags, render order and layers) in
|
|
146
|
+
* one call instead of one read per field per object. three has no such method.
|
|
147
|
+
*/
|
|
148
|
+
function hostStamp(source: Scene): number | undefined {
|
|
149
|
+
const stamp = (source as { __tnStructureStamp?: () => number }).__tnStructureStamp;
|
|
150
|
+
return typeof stamp === "function" ? stamp.call(source) : undefined;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export class ProjectionStability {
|
|
154
|
+
/** Every node the last scan visited, in visit order: add, remove and reparent all move one. */
|
|
155
|
+
readonly #nodes: Array<Object3D | undefined> = [];
|
|
156
|
+
#nodeCount = 0;
|
|
157
|
+
readonly #watched: Array<IWatchedRenderable | undefined> = [];
|
|
158
|
+
#watchedCount = 0;
|
|
159
|
+
/** The renderables behind `#watched`, same order, for the checks a host stamp cannot cover. */
|
|
160
|
+
readonly #watchedObjects: Array<Object3D | undefined> = [];
|
|
161
|
+
/** The host's structure stamp when the last scan was recorded; undefined where there is none. */
|
|
162
|
+
#stamp: number | undefined;
|
|
163
|
+
readonly #materials: IWatchedMaterial[] = [];
|
|
164
|
+
readonly #geometries: IWatchedGeometry[] = [];
|
|
165
|
+
readonly #materialSet = new Set<Material>();
|
|
166
|
+
readonly #geometrySet = new Set<BufferGeometry>();
|
|
167
|
+
readonly #stack: Array<Object3D | undefined> = [];
|
|
168
|
+
/** Inherited visibility per stack slot, so a walk carries it down instead of walking back up. */
|
|
169
|
+
readonly #stackVisible: boolean[] = [];
|
|
170
|
+
readonly #exactObjects: Array<Object3D | undefined> = [];
|
|
171
|
+
readonly #exactReasons: ProjectionExactReason[] = [];
|
|
172
|
+
readonly #exact: Array<IProjectionExactEntry | undefined> = [];
|
|
173
|
+
#exactCount = 0;
|
|
174
|
+
|
|
175
|
+
/** Renderables the last scan classified, for a diagnostic. */
|
|
176
|
+
get watchedCount(): number {
|
|
177
|
+
return this.#watchedCount;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* The exact lane the last scan classified, repooled for this frame's apply.
|
|
182
|
+
*
|
|
183
|
+
* The mirror clears the entries it is handed once it has applied them, so the objects and reasons
|
|
184
|
+
* are held here and the pool is refilled per frame rather than handed over once.
|
|
185
|
+
*/
|
|
186
|
+
exactLane(): { entries: readonly IProjectionExactEntry[]; count: number } {
|
|
187
|
+
for (let index = 0; index < this.#exactCount; index += 1) {
|
|
188
|
+
let entry = this.#exact[index];
|
|
189
|
+
if (entry === undefined) {
|
|
190
|
+
entry = { object: undefined, reason: "unsupportedGeometry" };
|
|
191
|
+
this.#exact.push(entry);
|
|
192
|
+
}
|
|
193
|
+
entry.object = this.#exactObjects[index];
|
|
194
|
+
entry.reason = this.#exactReasons[index] as ProjectionExactReason;
|
|
195
|
+
this.#exact[index] = entry;
|
|
196
|
+
}
|
|
197
|
+
return { entries: this.#exact as readonly IProjectionExactEntry[], count: this.#exactCount };
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/** Records the structure a scan just classified, so a later frame can prove it unchanged. */
|
|
201
|
+
record(source: Scene, scan: IProjectionScanResult): void {
|
|
202
|
+
this.#materialSet.clear();
|
|
203
|
+
this.#geometrySet.clear();
|
|
204
|
+
const nodes = this.#nodes;
|
|
205
|
+
const stack = this.#stack;
|
|
206
|
+
const stackVisible = this.#stackVisible;
|
|
207
|
+
let depth = 0;
|
|
208
|
+
let visited = 0;
|
|
209
|
+
let watched = 0;
|
|
210
|
+
const roots = source.children;
|
|
211
|
+
for (let index = roots.length - 1; index >= 0; index -= 1) {
|
|
212
|
+
stack[depth] = roots[index] as Object3D;
|
|
213
|
+
stackVisible[depth] = true;
|
|
214
|
+
depth += 1;
|
|
215
|
+
}
|
|
216
|
+
while (depth > 0) {
|
|
217
|
+
depth -= 1;
|
|
218
|
+
const object = stack[depth] as Object3D;
|
|
219
|
+
const visibleInWorld = stackVisible[depth] === true;
|
|
220
|
+
stack[depth] = undefined;
|
|
221
|
+
nodes[visited] = object;
|
|
222
|
+
visited += 1;
|
|
223
|
+
const kind = kindOf(object);
|
|
224
|
+
if ((kind & KIND_RENDERABLE) !== 0) {
|
|
225
|
+
const candidate = object as ProjectionCandidate;
|
|
226
|
+
const geometry = candidate.geometry;
|
|
227
|
+
const material = candidate.material;
|
|
228
|
+
let watch = this.#watched[watched];
|
|
229
|
+
if (watch === undefined) {
|
|
230
|
+
watch = {
|
|
231
|
+
geometry: undefined,
|
|
232
|
+
material: undefined,
|
|
233
|
+
customDepthMaterial: undefined,
|
|
234
|
+
customDistanceMaterial: undefined,
|
|
235
|
+
layersMask: 0,
|
|
236
|
+
renderOrder: 0,
|
|
237
|
+
kind: 0,
|
|
238
|
+
visible: true,
|
|
239
|
+
};
|
|
240
|
+
this.#watched[watched] = watch;
|
|
241
|
+
}
|
|
242
|
+
this.#watchedObjects[watched] = object;
|
|
243
|
+
watch.geometry = geometry;
|
|
244
|
+
watch.material = material;
|
|
245
|
+
watch.customDepthMaterial = candidate.customDepthMaterial;
|
|
246
|
+
watch.customDistanceMaterial = candidate.customDistanceMaterial;
|
|
247
|
+
watch.layersMask = candidate.layers.mask;
|
|
248
|
+
watch.renderOrder = candidate.renderOrder ?? 0;
|
|
249
|
+
watch.kind = kind;
|
|
250
|
+
watch.visible = visibleInWorld;
|
|
251
|
+
watched += 1;
|
|
252
|
+
if (geometry !== undefined && !this.#geometrySet.has(geometry)) {
|
|
253
|
+
this.#geometrySet.add(geometry);
|
|
254
|
+
this.#geometries.push({
|
|
255
|
+
geometry,
|
|
256
|
+
lane: geometryLane(geometry),
|
|
257
|
+
version: geometryVersionSum(geometry),
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
if (
|
|
261
|
+
material !== undefined &&
|
|
262
|
+
!Array.isArray(material) &&
|
|
263
|
+
!this.#materialSet.has(material)
|
|
264
|
+
) {
|
|
265
|
+
this.#materialSet.add(material);
|
|
266
|
+
this.#materials.push({ material, lane: materialLane(material) });
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
if ((kind & (KIND_LIGHT | KIND_LOD)) !== 0) continue;
|
|
270
|
+
const childVisible = visibleInWorld && object.visible;
|
|
271
|
+
const children = object.children;
|
|
272
|
+
for (let index = children.length - 1; index >= 0; index -= 1) {
|
|
273
|
+
stack[depth] = children[index] as Object3D;
|
|
274
|
+
stackVisible[depth] = childVisible;
|
|
275
|
+
depth += 1;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
for (let index = depth; index < stack.length; index += 1) stack[index] = undefined;
|
|
279
|
+
for (let index = watched; index < this.#watched.length; index += 1) {
|
|
280
|
+
this.#watched[index] = undefined;
|
|
281
|
+
this.#watchedObjects[index] = undefined;
|
|
282
|
+
}
|
|
283
|
+
this.#stamp = hostStamp(source);
|
|
284
|
+
this.#nodeCount = visited;
|
|
285
|
+
this.#watchedCount = watched;
|
|
286
|
+
for (let index = 0; index < scan.exactLaneCount; index += 1) {
|
|
287
|
+
const entry = scan.exactLane[index] as IProjectionExactEntry;
|
|
288
|
+
this.#exactObjects[index] = entry.object;
|
|
289
|
+
this.#exactReasons[index] = entry.reason;
|
|
290
|
+
}
|
|
291
|
+
this.#exactCount = scan.exactLaneCount;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* True when nothing the scan reads has changed since {@link record}.
|
|
296
|
+
*
|
|
297
|
+
* False is always the safe answer: it costs one scan, which is what this frame would have paid
|
|
298
|
+
* anyway. True is a claim, and every input the classification reads is compared here.
|
|
299
|
+
*/
|
|
300
|
+
holds(source: Scene): boolean {
|
|
301
|
+
if (this.#nodeCount === 0) return false;
|
|
302
|
+
for (let index = 0; index < this.#materials.length; index += 1) {
|
|
303
|
+
const watched = this.#materials[index] as IWatchedMaterial;
|
|
304
|
+
if (watched.lane !== materialLane(watched.material)) return false;
|
|
305
|
+
}
|
|
306
|
+
for (let index = 0; index < this.#geometries.length; index += 1) {
|
|
307
|
+
const watched = this.#geometries[index] as IWatchedGeometry;
|
|
308
|
+
if (watched.lane !== geometryLane(watched.geometry)) return false;
|
|
309
|
+
if (watched.version !== geometryVersionSum(watched.geometry)) return false;
|
|
310
|
+
}
|
|
311
|
+
// A host that can hash everything the engine owns answers in one call. The walk below is for a
|
|
312
|
+
// host that cannot, and for any mismatch, since only the walk says whether a mismatch matters.
|
|
313
|
+
if (this.#stamp !== undefined && hostStamp(source) === this.#stamp && this.#scriptStateHolds())
|
|
314
|
+
return true;
|
|
315
|
+
const stack = this.#stack;
|
|
316
|
+
const stackVisible = this.#stackVisible;
|
|
317
|
+
const nodes = this.#nodes;
|
|
318
|
+
let depth = 0;
|
|
319
|
+
let visited = 0;
|
|
320
|
+
let watched = 0;
|
|
321
|
+
const roots = source.children;
|
|
322
|
+
for (let index = roots.length - 1; index >= 0; index -= 1) {
|
|
323
|
+
stack[depth] = roots[index] as Object3D;
|
|
324
|
+
stackVisible[depth] = true;
|
|
325
|
+
depth += 1;
|
|
326
|
+
}
|
|
327
|
+
while (depth > 0) {
|
|
328
|
+
depth -= 1;
|
|
329
|
+
const object = stack[depth] as Object3D;
|
|
330
|
+
const visibleInWorld = stackVisible[depth] === true;
|
|
331
|
+
stack[depth] = undefined;
|
|
332
|
+
if (nodes[visited] !== object) return false;
|
|
333
|
+
visited += 1;
|
|
334
|
+
const kind = kindOf(object);
|
|
335
|
+
if ((kind & KIND_RENDERABLE) === 0) {
|
|
336
|
+
if ((kind & (KIND_LIGHT | KIND_LOD)) !== 0) continue;
|
|
337
|
+
const childVisible = visibleInWorld && object.visible;
|
|
338
|
+
const children = object.children;
|
|
339
|
+
for (let index = children.length - 1; index >= 0; index -= 1) {
|
|
340
|
+
stack[depth] = children[index] as Object3D;
|
|
341
|
+
stackVisible[depth] = childVisible;
|
|
342
|
+
depth += 1;
|
|
343
|
+
}
|
|
344
|
+
continue;
|
|
345
|
+
}
|
|
346
|
+
const watch = this.#watched[watched];
|
|
347
|
+
if (watch === undefined) return false;
|
|
348
|
+
const candidate = object as ProjectionCandidate;
|
|
349
|
+
if (
|
|
350
|
+
watch.geometry !== candidate.geometry ||
|
|
351
|
+
watch.material !== candidate.material ||
|
|
352
|
+
watch.customDepthMaterial !== candidate.customDepthMaterial ||
|
|
353
|
+
watch.customDistanceMaterial !== candidate.customDistanceMaterial ||
|
|
354
|
+
watch.layersMask !== candidate.layers.mask ||
|
|
355
|
+
watch.renderOrder !== (candidate.renderOrder ?? 0) ||
|
|
356
|
+
watch.kind !== kind ||
|
|
357
|
+
watch.visible !== visibleInWorld
|
|
358
|
+
)
|
|
359
|
+
return false;
|
|
360
|
+
watched += 1;
|
|
361
|
+
if ((kind & (KIND_LIGHT | KIND_LOD)) !== 0) continue;
|
|
362
|
+
const childVisible = visibleInWorld && object.visible;
|
|
363
|
+
const children = object.children;
|
|
364
|
+
for (let index = children.length - 1; index >= 0; index -= 1) {
|
|
365
|
+
stack[depth] = children[index] as Object3D;
|
|
366
|
+
stackVisible[depth] = childVisible;
|
|
367
|
+
depth += 1;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
return visited === this.#nodeCount && watched === this.#watchedCount;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
/** The scan inputs that live on the script object rather than in the engine: no stamp sees them. */
|
|
374
|
+
#scriptStateHolds(): boolean {
|
|
375
|
+
for (let index = 0; index < this.#watchedCount; index += 1) {
|
|
376
|
+
const watch = this.#watched[index] as IWatchedRenderable;
|
|
377
|
+
const candidate = this.#watchedObjects[index] as ProjectionCandidate;
|
|
378
|
+
if (
|
|
379
|
+
watch.customDepthMaterial !== candidate.customDepthMaterial ||
|
|
380
|
+
watch.customDistanceMaterial !== candidate.customDistanceMaterial ||
|
|
381
|
+
hasRenderHook(candidate) !== ((watch.kind & KIND_HOOK) !== 0)
|
|
382
|
+
)
|
|
383
|
+
return false;
|
|
384
|
+
}
|
|
385
|
+
return true;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
/** Forgets the recorded structure, releasing the game objects it was holding. */
|
|
389
|
+
clear(): void {
|
|
390
|
+
for (let index = 0; index < this.#nodeCount; index += 1) this.#nodes[index] = undefined;
|
|
391
|
+
for (let index = 0; index < this.#watchedCount; index += 1) {
|
|
392
|
+
this.#watched[index] = undefined;
|
|
393
|
+
this.#watchedObjects[index] = undefined;
|
|
394
|
+
}
|
|
395
|
+
this.#stamp = undefined;
|
|
396
|
+
for (let index = 0; index < this.#exactCount; index += 1) {
|
|
397
|
+
this.#exactObjects[index] = undefined;
|
|
398
|
+
const entry = this.#exact[index];
|
|
399
|
+
if (entry !== undefined) entry.object = undefined;
|
|
400
|
+
}
|
|
401
|
+
this.#nodeCount = 0;
|
|
402
|
+
this.#watchedCount = 0;
|
|
403
|
+
this.#exactCount = 0;
|
|
404
|
+
this.#materials.length = 0;
|
|
405
|
+
this.#geometries.length = 0;
|
|
406
|
+
this.#materialSet.clear();
|
|
407
|
+
this.#geometrySet.clear();
|
|
408
|
+
}
|
|
409
|
+
}
|