@threenative/core 0.3.11 → 0.3.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/capabilities.json +1988 -204
- package/dist/{assets-YUbXa3-Y.d.ts → assets-CfMKnOsK.d.ts} +78 -1
- package/dist/camera-shake-CZKOfGn4.d.ts +46 -0
- package/dist/{canvas-layer-vCtanIeB.d.ts → canvas-layer-G7ttVy7y.d.ts} +1 -1
- package/dist/chunk-4SRAQFTU.js +133 -0
- package/dist/chunk-CFGTPFUH.js +231 -0
- package/dist/chunk-DIPIJICH.js +8916 -0
- package/dist/chunk-EEABDLUC.js +2237 -0
- package/dist/chunk-EFWZWLPY.js +1895 -0
- package/dist/chunk-GXY7B3JG.js +46 -0
- package/dist/chunk-GYUZJQ7U.js +280 -0
- package/dist/chunk-H4J6IAJE.js +504 -0
- package/dist/chunk-KIRUKTBQ.js +187 -0
- package/dist/chunk-QWJEMUUT.js +94 -0
- package/dist/chunk-SV4QVUTQ.js +31 -0
- package/dist/chunk-U4YHUKKL.js +615 -0
- package/dist/chunk-VP43GIWW.js +18 -0
- package/dist/chunk-XDTZ4QMO.js +160 -0
- package/dist/default-tone-mapping-GgKPTiBP.d.ts +4 -0
- package/dist/{game-DzMcitDO.d.ts → game-k8K3hZai.d.ts} +85 -9
- package/dist/hot.d.ts +5 -4
- package/dist/hot.js +5 -52
- package/dist/index.d.ts +633 -1351
- package/dist/index.js +12873 -23068
- package/dist/{model-lod-CTpZ6imz.d.ts → model-lod-DPTzeCcD.d.ts} +35 -3
- package/dist/playtest.d.ts +5 -4
- package/dist/playtest.js +25 -75
- package/dist/quality-BYqKGAwo.d.ts +868 -0
- package/dist/react-css.js +1 -215
- package/dist/react.d.ts +3 -2
- package/dist/render-environment.d.ts +170 -0
- package/dist/render-environment.js +352 -0
- package/dist/{renderer-rZm0hVqq.d.ts → renderer-BtOSseYf.d.ts} +42 -35
- package/dist/spells/index.d.ts +643 -0
- package/dist/spells/index.js +1558 -0
- package/dist/spells/ultra/index.d.ts +1600 -0
- package/dist/spells/ultra/index.js +6804 -0
- package/dist/terrain-jobs-worker.js +1 -123
- package/dist/two-sided-foliage-W523J3UM.js +1 -0
- package/dist/ui-layer.js +6 -384
- package/dist/worker.js +13 -43
- package/dist/world.d.ts +988 -268
- package/dist/world.js +17464 -18290
- package/mcp/animation-server.mjs +1 -1
- package/mcp/animation.mjs +2 -3
- package/mcp/engine-server.mjs +245 -52
- package/mcp/servers.mjs +10 -3
- package/mcp/terrain.mjs +8 -0
- package/package.json +19 -7
- package/patches/three@0.187.0-prd269-upgrade.patch +2102 -0
- package/patches/three@0.187.0.patch +2004 -407
- package/src/animation-batch.ts +193 -0
- package/src/animation-layers.ts +7 -3
- package/src/animation.ts +209 -29
- package/src/asset-cache.ts +3 -3
- package/src/asset-memo.ts +202 -0
- package/src/assets.ts +437 -125
- package/src/auto-batch.ts +190 -44
- package/src/card-lod.ts +152 -0
- package/src/compressed-texture-preparation.ts +1008 -0
- package/src/compute-driven.ts +1 -1
- package/src/config.ts +8 -0
- package/src/debug.ts +103 -22
- package/src/dev-global.ts +54 -0
- package/src/engine-hooks.ts +37 -0
- package/src/frame-budget.ts +50 -23
- package/src/game-boot-phase.ts +269 -0
- package/src/game-dev-tools.ts +86 -0
- package/src/game-frame-loop.ts +958 -0
- package/src/game-renderer-metrics.ts +77 -0
- package/src/game-startup.ts +1076 -0
- package/src/game-ui.ts +84 -0
- package/src/game-validate.ts +70 -0
- package/src/game.ts +198 -2264
- package/src/gamepad-mappings.ts +269 -0
- package/src/generated/console-markers.ts +13 -0
- package/src/geometry-capture.ts +28 -4
- package/src/gpu-readings.ts +98 -0
- package/src/gpu-scene-bvh.ts +149 -36
- package/src/hot.ts +4 -7
- package/src/index.ts +141 -9
- package/src/input.ts +237 -25
- package/src/instanced-batch-lod.ts +3 -8
- package/src/interpolation.ts +171 -40
- package/src/launch-diagnostics.ts +22 -12
- package/src/look/ao-admission.ts +25 -0
- package/src/look/auto-exposure.ts +5 -16
- package/src/look/default-tone-mapping.ts +41 -5
- package/src/look/filmic-tone-mapping.ts +15 -13
- package/src/look/local-exposure.ts +2 -7
- package/src/look/look-diagnostics.ts +3 -3
- package/src/look/quad-pass.ts +21 -0
- package/src/look/quality.ts +14 -5
- package/src/look/unreal-bloom.ts +4 -13
- package/src/look/world-environment.ts +113 -103
- package/src/loop.ts +29 -0
- package/src/merge-parts.ts +20 -24
- package/src/model-lod.ts +139 -17
- package/src/particle-kinds.ts +515 -0
- package/src/particle-significance.ts +12 -0
- package/src/particles.ts +19 -10
- package/src/picking.ts +17 -3
- package/src/platform.ts +23 -4
- package/src/playtest.ts +27 -1
- package/src/profiling/FrameStages.ts +5 -6
- package/src/profiling/Spans.ts +3 -17
- package/src/profiling/debug-telemetry.ts +2 -6
- package/src/profiling/render-list-validate.ts +6 -15
- package/src/projection-apply.ts +4 -1
- package/src/projection-marker.ts +2 -1
- package/src/projection-plan.ts +9 -6
- package/src/quiet-markers.ts +3 -10
- package/src/render/cpu-bvh.ts +100 -0
- package/src/render/depth-pyramid.ts +6 -14
- package/src/render/environment/environmentContribution.ts +202 -0
- package/src/render/environment/environmentRadiance.ts +44 -0
- package/src/render/environment/environmentSampleCache.ts +56 -0
- package/src/render/environment/environmentSampling.ts +201 -0
- package/src/render/environment/environmentSnapshot.ts +71 -0
- package/src/render/environment/gate.ts +57 -0
- package/src/render/mesh-pool.ts +4 -20
- package/src/render/probe-trace.ts +872 -0
- package/src/render/probe-volume.ts +780 -34
- package/src/render/radiance-cache.ts +17 -0
- package/src/render/resolution-subrect.ts +2 -0
- package/src/render/rough-diffuse.ts +46 -12
- package/src/render/soft-shadow.ts +27 -12
- package/src/render/virtual-shadow-adaptive.ts +55 -0
- package/src/render/virtual-shadow-casters.ts +175 -0
- package/src/render/virtual-shadow-layers.ts +76 -0
- package/src/render/virtual-shadow-level.ts +224 -0
- package/src/render/virtual-shadow-markers.ts +193 -0
- package/src/render/virtual-shadow-options.ts +370 -0
- package/src/render/virtual-shadow-pages.ts +5 -0
- package/src/render/virtual-shadow-partial.ts +13 -0
- package/src/render/virtual-shadow.ts +231 -1008
- package/src/render/world-impostor-surface.ts +402 -40
- package/src/render/world-impostor.ts +5 -2
- package/src/render-camera-cull.ts +98 -3
- package/src/render-environment.ts +41 -0
- package/src/render-pass-budget.ts +34 -7
- package/src/renderProjection.ts +22 -0
- package/src/renderer-config.ts +36 -0
- package/src/renderer-facts.ts +37 -0
- package/src/renderer.ts +144 -65
- package/src/resolution-scaler.ts +3 -2
- package/src/scene-entry-inspectors.ts +61 -0
- package/src/snow-field.ts +2 -1
- package/src/spells/cast-pool.ts +361 -0
- package/src/spells/index.ts +177 -0
- package/src/spells/mechanisms.ts +295 -0
- package/src/spells/reaction-field.ts +415 -0
- package/src/spells/spell-lights.ts +139 -0
- package/src/spells/spell-world.ts +187 -0
- package/src/spells/spell.ts +397 -0
- package/src/spells/spells.ts +283 -0
- package/src/spells/ultra/engine/camera.ts +184 -0
- package/src/spells/ultra/engine/quality.ts +96 -0
- package/src/spells/ultra/index.ts +52 -0
- package/src/spells/ultra/main.ts +305 -0
- package/src/spells/ultra/scene/arenaMaterial.ts +325 -0
- package/src/spells/ultra/spells/cast.ts +233 -0
- package/src/spells/ultra/spells/fire.ts +1267 -0
- package/src/spells/ultra/vfx/FluidVolume.ts +816 -0
- package/src/spells/ultra/vfx/FluidVolume.tsl.ts +855 -0
- package/src/spells/ultra/vfx/FxTarget.ts +61 -0
- package/src/spells/ultra/vfx/GroundField.ts +1399 -0
- package/src/spells/ultra/vfx/Particles.ts +1475 -0
- package/src/spells/ultra/vfx/Ribbons.ts +645 -0
- package/src/spells/ultra/vfx/Shockwaves.ts +286 -0
- package/src/spells/ultra/vfx/Volumes.ts +489 -0
- package/src/spells/ultra/vfx/common.ts +1195 -0
- package/src/spells/ultra/vfx/noise.ts +441 -0
- package/src/startup-offscreen-bytes.ts +78 -0
- package/src/startup-readiness.ts +128 -34
- package/src/static-transform.ts +25 -19
- package/src/streamed-textures.ts +112 -0
- package/src/streaming.ts +68 -4
- package/src/texture-streaming.ts +331 -0
- package/src/version.ts +1 -1
- package/src/warmup.ts +56 -8
- package/src/water-surface.ts +9 -3
- package/src/worker.ts +12 -2
- package/src/world-bundle-safety.ts +446 -0
- package/src/world-cell-batches.ts +1178 -0
- package/src/world-cell-chunks.ts +1128 -0
- package/src/world-cell-data.ts +995 -0
- package/src/world-cell-impostors.ts +1461 -0
- package/src/world-cell-lod-bias.ts +151 -0
- package/src/world-cell-models.ts +1074 -0
- package/src/world-cell-options.ts +177 -0
- package/src/world-cell-placements.ts +798 -0
- package/src/world-cell-prewarm.ts +592 -0
- package/src/world-cell-readiness.ts +357 -0
- package/src/world-cell-records.ts +401 -0
- package/src/world-cell-render-bundles.ts +459 -0
- package/src/world-cell-render-gpu-dress.ts +710 -0
- package/src/world-cell-render-main-cull.ts +540 -0
- package/src/world-cell-render-shadow-claims.ts +198 -0
- package/src/world-cell-render-util.ts +259 -0
- package/src/world-cell-render.ts +1501 -0
- package/src/world-cell-residency.ts +754 -0
- package/src/world-cell-stale.ts +238 -0
- package/src/world-cells.ts +1335 -10418
- package/src/world-chunk-shadow.ts +308 -0
- package/src/world-collar.ts +315 -0
- package/src/world-gpu-flags.ts +131 -0
- package/src/world-gpu-readback.ts +881 -0
- package/src/world-gpu-reference.ts +524 -0
- package/src/world-gpu-scene.ts +256 -2286
- package/src/world-gpu-shadow.ts +203 -0
- package/src/world-gpu-types.ts +409 -0
- package/src/world-gpu-validation.ts +518 -0
- package/src/world-heightfield.ts +802 -0
- package/src/world-load-limiter.ts +111 -0
- package/src/world-model-sections.ts +80 -0
- package/src/world-noise.ts +241 -0
- package/src/world-package.ts +42 -0
- package/src/world-region.ts +1 -1
- package/src/world-river-ribbon.ts +282 -0
- package/src/world-root-frame.ts +39 -0
- package/src/world-shore-field.ts +91 -0
- package/src/world-static-pose.ts +163 -0
- package/src/world-surface-sampler.ts +48 -0
- package/src/world-terrain-splat.ts +361 -153
- package/src/world-tile-budget.ts +249 -0
- package/src/world-tile-geometry.ts +469 -0
- package/src/world-tile-lod.ts +408 -0
- package/src/world-tile-observation.ts +566 -0
- package/src/world-tile-stitch.ts +166 -0
- package/src/world-tiles.ts +247 -1755
- package/src/world-validate.ts +6 -14
- package/src/world-warm.ts +51 -0
- package/src/world-water-bodies.ts +359 -0
- package/src/world.ts +48 -741
|
@@ -0,0 +1,515 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Particle behaviour as data, so a spell's look is not a shader.
|
|
3
|
+
*
|
|
4
|
+
* Upstream `Particles.js` keeps one kernel and a table of kinds — flame, ember, spark, smoke,
|
|
5
|
+
* debris — and a spell picks kinds and retunes them. Nothing recompiles when it does, because the
|
|
6
|
+
* numbers a kind owns are uniforms and the kernel reads them. This is that table, driving the
|
|
7
|
+
* engine's own `GPUParticles3D` instead of upstream's WebGL2 renderer.
|
|
8
|
+
*
|
|
9
|
+
* Every value here is behaviour: how long a particle lives, how far and how fast it flies, what
|
|
10
|
+
* gravity and the air do to it, and what colour it runs from and to. The table holds those as
|
|
11
|
+
* uniforms, so a settings screen or a spell override writes them and the pipeline, the material and
|
|
12
|
+
* the kernels all stay exactly as they were.
|
|
13
|
+
*
|
|
14
|
+
* One emitter reads one kind. Two emitters of the same kind and the same code share a pipeline;
|
|
15
|
+
* the engine's node builder hashes the graph, so a second emitter of the same kind costs buffers
|
|
16
|
+
* and a draw, never a program.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { Vector2, Vector3, Vector4 } from "three";
|
|
20
|
+
import type { Node } from "three/src/nodes/Nodes.js";
|
|
21
|
+
import {
|
|
22
|
+
Fn,
|
|
23
|
+
If,
|
|
24
|
+
abs,
|
|
25
|
+
atan,
|
|
26
|
+
cos,
|
|
27
|
+
cross,
|
|
28
|
+
exp,
|
|
29
|
+
float,
|
|
30
|
+
hash,
|
|
31
|
+
instanceIndex,
|
|
32
|
+
mix,
|
|
33
|
+
normalize,
|
|
34
|
+
sin,
|
|
35
|
+
smoothstep,
|
|
36
|
+
step,
|
|
37
|
+
time,
|
|
38
|
+
uint,
|
|
39
|
+
uniform,
|
|
40
|
+
uv,
|
|
41
|
+
varying,
|
|
42
|
+
vec2,
|
|
43
|
+
vec3,
|
|
44
|
+
vec4,
|
|
45
|
+
} from "three/tsl";
|
|
46
|
+
import {
|
|
47
|
+
type ComputeNode,
|
|
48
|
+
SpriteNodeMaterial,
|
|
49
|
+
type StorageBufferNode,
|
|
50
|
+
type UniformNode,
|
|
51
|
+
} from "three/webgpu";
|
|
52
|
+
import * as three from "three/webgpu";
|
|
53
|
+
import type { IGPUParticles3DSpawnOptions, IGPUParticles3DSpawnRequest } from "./particles.js";
|
|
54
|
+
|
|
55
|
+
/** The kinds a spell or an effect selects from. Adding one is a row, not a shader. */
|
|
56
|
+
export const PARTICLE_KINDS = [
|
|
57
|
+
"flame",
|
|
58
|
+
"ember",
|
|
59
|
+
"spark",
|
|
60
|
+
"smoke",
|
|
61
|
+
"ice",
|
|
62
|
+
"arc",
|
|
63
|
+
"mote",
|
|
64
|
+
"debris",
|
|
65
|
+
] as const;
|
|
66
|
+
|
|
67
|
+
export type ParticleKindName = (typeof PARTICLE_KINDS)[number];
|
|
68
|
+
|
|
69
|
+
/** How a kind's sprite is drawn. Mask and stretch only; colour comes from the table. */
|
|
70
|
+
export type ParticleStyle = "glow" | "media" | "spark";
|
|
71
|
+
|
|
72
|
+
/** Every value a kind owns. A retune writes these and rebuilds nothing. */
|
|
73
|
+
export interface IParticleKindValues {
|
|
74
|
+
/** Seconds a particle lives, shortest and longest. */
|
|
75
|
+
readonly lifetime: readonly [number, number];
|
|
76
|
+
/** Metres across the sprite, at birth and at death. */
|
|
77
|
+
readonly size: readonly [number, number];
|
|
78
|
+
/** Metres per second at spawn, slowest and fastest. */
|
|
79
|
+
readonly speed: readonly [number, number];
|
|
80
|
+
/** Half-angle of the launch cone in radians, around the emitter's direction. */
|
|
81
|
+
readonly cone: number;
|
|
82
|
+
/** Downward acceleration, m/s². 9.8 reads as debris, 0 as magic. */
|
|
83
|
+
readonly gravity: number;
|
|
84
|
+
/** Exponential velocity decay per second. High drag is a licking flame; low is a thrown spark. */
|
|
85
|
+
readonly drag: number;
|
|
86
|
+
/** Upward acceleration, m/s². Fire and smoke rise; sparks do not. */
|
|
87
|
+
readonly buoyancy: number;
|
|
88
|
+
/** Opacity at birth and at death. */
|
|
89
|
+
readonly alpha: readonly [number, number];
|
|
90
|
+
/** Colour at birth, and at death. A spell retunes both. */
|
|
91
|
+
readonly colour: readonly [number, number, number];
|
|
92
|
+
readonly highlight: readonly [number, number, number];
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** The stock table. A spell names a kind and overrides what it must. */
|
|
96
|
+
const KIND_DEFAULTS: Readonly<Record<ParticleKindName, IParticleKindValues>> = {
|
|
97
|
+
// A small fast-cooling lick: rides off the ball, drags hard and stops short.
|
|
98
|
+
flame: {
|
|
99
|
+
alpha: [0.95, 0],
|
|
100
|
+
buoyancy: 3.8,
|
|
101
|
+
colour: [1, 0.72, 0.34],
|
|
102
|
+
cone: 0.9,
|
|
103
|
+
drag: 3.6,
|
|
104
|
+
gravity: 0,
|
|
105
|
+
highlight: [1, 0.24, 0.04],
|
|
106
|
+
lifetime: [0.16, 0.36],
|
|
107
|
+
size: [0.32, 0.09],
|
|
108
|
+
speed: [0.8, 2.6],
|
|
109
|
+
},
|
|
110
|
+
// A glowing chip that skitters and burns in.
|
|
111
|
+
ember: {
|
|
112
|
+
alpha: [1, 0],
|
|
113
|
+
buoyancy: 1.7,
|
|
114
|
+
colour: [1, 0.82, 0.4],
|
|
115
|
+
cone: 1.2,
|
|
116
|
+
drag: 0.6,
|
|
117
|
+
gravity: 1.2,
|
|
118
|
+
highlight: [1, 0.3, 0.05],
|
|
119
|
+
lifetime: [1, 2.6],
|
|
120
|
+
size: [0.035, 0.01],
|
|
121
|
+
speed: [1.4, 4.2],
|
|
122
|
+
},
|
|
123
|
+
// Fast, heavy, gone in a fifth of a second.
|
|
124
|
+
spark: {
|
|
125
|
+
alpha: [1, 0],
|
|
126
|
+
buoyancy: 0,
|
|
127
|
+
colour: [1, 0.95, 0.82],
|
|
128
|
+
cone: 1.4,
|
|
129
|
+
drag: 0.35,
|
|
130
|
+
gravity: 9.8,
|
|
131
|
+
highlight: [1, 0.34, 0.06],
|
|
132
|
+
lifetime: [0.4, 1.3],
|
|
133
|
+
size: [0.04, 0.01],
|
|
134
|
+
speed: [4, 9],
|
|
135
|
+
},
|
|
136
|
+
// Rises and swells: long-lived and slow.
|
|
137
|
+
smoke: {
|
|
138
|
+
alpha: [0.55, 0],
|
|
139
|
+
buoyancy: 1.6,
|
|
140
|
+
colour: [0.16, 0.15, 0.14],
|
|
141
|
+
cone: 0.6,
|
|
142
|
+
drag: 1.3,
|
|
143
|
+
gravity: 0,
|
|
144
|
+
highlight: [0.09, 0.085, 0.08],
|
|
145
|
+
lifetime: [2.2, 4.5],
|
|
146
|
+
size: [0.4, 1.9],
|
|
147
|
+
speed: [0.3, 1.2],
|
|
148
|
+
},
|
|
149
|
+
// Cold: falls, and drags the air with it.
|
|
150
|
+
ice: {
|
|
151
|
+
alpha: [0.9, 0],
|
|
152
|
+
buoyancy: -0.4,
|
|
153
|
+
colour: [0.72, 0.95, 1],
|
|
154
|
+
cone: 0.8,
|
|
155
|
+
drag: 0.9,
|
|
156
|
+
gravity: 6.5,
|
|
157
|
+
highlight: [0.36, 0.62, 1],
|
|
158
|
+
lifetime: [0.6, 1.8],
|
|
159
|
+
size: [0.08, 0.22],
|
|
160
|
+
speed: [2, 6],
|
|
161
|
+
},
|
|
162
|
+
// An ionised filament: nearly straight, very fast, over almost before it is read.
|
|
163
|
+
arc: {
|
|
164
|
+
alpha: [1, 0],
|
|
165
|
+
buoyancy: 0,
|
|
166
|
+
colour: [0.85, 0.93, 1],
|
|
167
|
+
cone: 0.25,
|
|
168
|
+
drag: 0.2,
|
|
169
|
+
gravity: 0,
|
|
170
|
+
highlight: [0.36, 0.44, 1],
|
|
171
|
+
lifetime: [0.08, 0.24],
|
|
172
|
+
size: [0.06, 0.02],
|
|
173
|
+
speed: [10, 20],
|
|
174
|
+
},
|
|
175
|
+
// A charge mote: slow, converging, drawn in rather than thrown out.
|
|
176
|
+
mote: {
|
|
177
|
+
alpha: [0, 1],
|
|
178
|
+
buoyancy: 0.3,
|
|
179
|
+
colour: [0.72, 0.82, 1],
|
|
180
|
+
cone: 0.5,
|
|
181
|
+
drag: 1.2,
|
|
182
|
+
gravity: 0,
|
|
183
|
+
highlight: [1, 0.95, 1],
|
|
184
|
+
lifetime: [0.35, 0.7],
|
|
185
|
+
size: [0.02, 0.05],
|
|
186
|
+
speed: [0.2, 0.9],
|
|
187
|
+
},
|
|
188
|
+
// Lit rock: heavy, and it lies where it lands.
|
|
189
|
+
debris: {
|
|
190
|
+
alpha: [1, 0.9],
|
|
191
|
+
buoyancy: 0,
|
|
192
|
+
colour: [0.16, 0.13, 0.12],
|
|
193
|
+
cone: 1.1,
|
|
194
|
+
drag: 0.25,
|
|
195
|
+
gravity: 9.8,
|
|
196
|
+
highlight: [1, 0.35, 0.06],
|
|
197
|
+
lifetime: [1.6, 3.2],
|
|
198
|
+
size: [0.085, 0.085],
|
|
199
|
+
speed: [3, 7],
|
|
200
|
+
},
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
/** The uniforms one kind's kernel and material read. Held so a retune never touches the graph. */
|
|
204
|
+
export interface IParticleKindNodes {
|
|
205
|
+
readonly lifetime: UniformNode<"vec2", Vector2>;
|
|
206
|
+
readonly size: UniformNode<"vec2", Vector2>;
|
|
207
|
+
readonly speed: UniformNode<"vec2", Vector2>;
|
|
208
|
+
readonly alpha: UniformNode<"vec2", Vector2>;
|
|
209
|
+
readonly colour: UniformNode<"vec3", Vector3>;
|
|
210
|
+
readonly highlight: UniformNode<"vec3", Vector3>;
|
|
211
|
+
/** `x` cone, `y` gravity, `z` drag, `w` buoyancy. */
|
|
212
|
+
readonly shape: UniformNode<"vec4", Vector4>;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const TAU = Math.PI * 2;
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* The tunable kind table.
|
|
219
|
+
*
|
|
220
|
+
* One table per game, or one per spell: it knows only the kinds it was asked for, so a spell that
|
|
221
|
+
* never uses `debris` pays nothing for it. `set` writes uniforms, which is why retuning a spell from
|
|
222
|
+
* a settings screen builds no pipeline.
|
|
223
|
+
*/
|
|
224
|
+
export class ParticleKindTable {
|
|
225
|
+
readonly kinds: readonly ParticleKindName[];
|
|
226
|
+
readonly #nodes = new Map<ParticleKindName, IParticleKindNodes>();
|
|
227
|
+
|
|
228
|
+
constructor(kinds: readonly ParticleKindName[] = PARTICLE_KINDS) {
|
|
229
|
+
const seen = new Set<ParticleKindName>();
|
|
230
|
+
for (const kind of kinds) {
|
|
231
|
+
if (!(PARTICLE_KINDS as readonly string[]).includes(kind))
|
|
232
|
+
throw new RangeError(`unknown particle kind ${kind}`);
|
|
233
|
+
if (seen.has(kind)) throw new RangeError(`particle kind ${kind} listed twice`);
|
|
234
|
+
seen.add(kind);
|
|
235
|
+
this.#nodes.set(kind, nodesFor(KIND_DEFAULTS[kind]));
|
|
236
|
+
}
|
|
237
|
+
this.kinds = [...kinds];
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
has(kind: ParticleKindName): boolean {
|
|
241
|
+
return this.#nodes.has(kind);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/** Read one kind's current values. */
|
|
245
|
+
get(kind: ParticleKindName): IParticleKindValues {
|
|
246
|
+
const nodes = this.nodes(kind);
|
|
247
|
+
return {
|
|
248
|
+
alpha: [nodes.alpha.value.x, nodes.alpha.value.y],
|
|
249
|
+
buoyancy: nodes.shape.value.w,
|
|
250
|
+
colour: [nodes.colour.value.x, nodes.colour.value.y, nodes.colour.value.z],
|
|
251
|
+
cone: nodes.shape.value.x,
|
|
252
|
+
drag: nodes.shape.value.z,
|
|
253
|
+
gravity: nodes.shape.value.y,
|
|
254
|
+
highlight: [nodes.highlight.value.x, nodes.highlight.value.y, nodes.highlight.value.z],
|
|
255
|
+
lifetime: [nodes.lifetime.value.x, nodes.lifetime.value.y],
|
|
256
|
+
size: [nodes.size.value.x, nodes.size.value.y],
|
|
257
|
+
speed: [nodes.speed.value.x, nodes.speed.value.y],
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Retune a kind. Every field is optional, every value must be finite, and a partial patch leaves
|
|
263
|
+
* the rest alone. No kernel is rebuilt and no material is replaced.
|
|
264
|
+
*/
|
|
265
|
+
set(kind: ParticleKindName, patch: Partial<IParticleKindValues>): this {
|
|
266
|
+
const nodes = this.nodes(kind);
|
|
267
|
+
if (patch.lifetime !== undefined)
|
|
268
|
+
writePair(nodes.lifetime.value, patch.lifetime, `${kind}.lifetime`);
|
|
269
|
+
if (patch.size !== undefined) writePair(nodes.size.value, patch.size, `${kind}.size`);
|
|
270
|
+
if (patch.speed !== undefined) writePair(nodes.speed.value, patch.speed, `${kind}.speed`);
|
|
271
|
+
if (patch.alpha !== undefined) writePair(nodes.alpha.value, patch.alpha, `${kind}.alpha`);
|
|
272
|
+
if (patch.colour !== undefined) writeTriple(nodes.colour.value, patch.colour, `${kind}.colour`);
|
|
273
|
+
if (patch.highlight !== undefined)
|
|
274
|
+
writeTriple(nodes.highlight.value, patch.highlight, `${kind}.highlight`);
|
|
275
|
+
const shape = nodes.shape.value;
|
|
276
|
+
if (patch.cone !== undefined) shape.x = atLeast(`${kind}.cone`, patch.cone, 0);
|
|
277
|
+
if (patch.gravity !== undefined)
|
|
278
|
+
shape.y = atLeast(`${kind}.gravity`, patch.gravity, Number.NEGATIVE_INFINITY);
|
|
279
|
+
if (patch.drag !== undefined) shape.z = atLeast(`${kind}.drag`, patch.drag, 0);
|
|
280
|
+
if (patch.buoyancy !== undefined)
|
|
281
|
+
shape.w = atLeast(`${kind}.buoyancy`, patch.buoyancy, Number.NEGATIVE_INFINITY);
|
|
282
|
+
return this;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/** The TSL nodes one kind's kernel and material read. Stable for the table's lifetime. */
|
|
286
|
+
nodes(kind: ParticleKindName): IParticleKindNodes {
|
|
287
|
+
const nodes = this.#nodes.get(kind);
|
|
288
|
+
if (nodes === undefined) throw new RangeError(`particle kind ${kind} is not in this table`);
|
|
289
|
+
return nodes;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/** A literal look for one emitter. Retuning the table does not change these. */
|
|
294
|
+
export interface IParticleLook {
|
|
295
|
+
readonly colour: readonly [number, number, number];
|
|
296
|
+
readonly highlight: readonly [number, number, number];
|
|
297
|
+
/** Metres across the sprite. Defaults to the kind's own stock size, floored to stay readable. */
|
|
298
|
+
readonly size?: number;
|
|
299
|
+
/** Defaults to the kind's stock start alpha, floored so a fade-in does not begin invisible. */
|
|
300
|
+
readonly alpha?: number;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
export interface IParticleKindEmitterOptions {
|
|
304
|
+
readonly table: ParticleKindTable;
|
|
305
|
+
readonly kind: ParticleKindName;
|
|
306
|
+
/** The spell's own colour. Defaults to the kind's stock look. */
|
|
307
|
+
readonly look?: IParticleLook;
|
|
308
|
+
/** Ring capacity. Room for the overlapping bursts of one spell. */
|
|
309
|
+
readonly amount: number;
|
|
310
|
+
/**
|
|
311
|
+
* World direction the launch cone points down. Defaults to straight up, so a burst lifts before it
|
|
312
|
+
* falls. A spell emitting a trail behind a moving ball points this back along the flight.
|
|
313
|
+
*/
|
|
314
|
+
readonly direction?: readonly [number, number, number];
|
|
315
|
+
/** Per-emitter seed: two casters' sparks do not land in the same places. */
|
|
316
|
+
readonly seed?: number;
|
|
317
|
+
readonly style?: ParticleStyle;
|
|
318
|
+
readonly blending?: three.Blending;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Build one kind's emitter options for `GPUParticles3D`.
|
|
323
|
+
*
|
|
324
|
+
* Both kernels and the material read the table's uniforms, so a later `table.set` moves every live
|
|
325
|
+
* particle's behaviour on the very next dispatch and no pipeline is created in response.
|
|
326
|
+
*/
|
|
327
|
+
export function createParticleKindEmitter(
|
|
328
|
+
options: IParticleKindEmitterOptions,
|
|
329
|
+
): IGPUParticles3DSpawnOptions {
|
|
330
|
+
const nodes = options.table.nodes(options.kind);
|
|
331
|
+
const seed = options.seed ?? 0;
|
|
332
|
+
const capacity = options.amount;
|
|
333
|
+
const style = options.style ?? "glow";
|
|
334
|
+
const direction = normalize(vec3(...(options.direction ?? [0, 1, 0])));
|
|
335
|
+
// cross(direction, tangent) is zero when the two are parallel and a normalised zero is NaN, which
|
|
336
|
+
// hangs the GPU the first frame it reaches a sprite. Pick the tangent off the smallest component.
|
|
337
|
+
const tangent = abs(direction.y).greaterThan(0.9) ? vec3(1, 0, 0) : vec3(0, 1, 0);
|
|
338
|
+
const bitangent = normalize(cross(direction, tangent));
|
|
339
|
+
const material = new SpriteNodeMaterial({
|
|
340
|
+
blending: options.blending ?? three.AdditiveBlending,
|
|
341
|
+
depthWrite: false,
|
|
342
|
+
toneMapped: false,
|
|
343
|
+
transparent: true,
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
const random = (salt: number, key: Node<"uint">): Node<"float"> =>
|
|
347
|
+
hash(instanceIndex.add(seed + salt).add(key));
|
|
348
|
+
|
|
349
|
+
const launch = (key: Node<"uint">) => {
|
|
350
|
+
const cone = nodes.shape.x.mul(random(29, key).sqrt());
|
|
351
|
+
const azimuth = random(31, key).mul(TAU);
|
|
352
|
+
return normalize(
|
|
353
|
+
direction
|
|
354
|
+
.mul(cos(cone))
|
|
355
|
+
.add(tangent.mul(cos(azimuth)).mul(sin(cone)))
|
|
356
|
+
.add(bitangent.mul(sin(azimuth)).mul(sin(cone))),
|
|
357
|
+
).mul(mix(nodes.speed.x, nodes.speed.y, random(23, key)));
|
|
358
|
+
};
|
|
359
|
+
|
|
360
|
+
/** The material can only read the birth stamp once the engine has made the buffer. */
|
|
361
|
+
const bindMaterial = (born: Node<"float">): void => {
|
|
362
|
+
const key = born.max(0).mul(1000).toUint();
|
|
363
|
+
const age = time.sub(born);
|
|
364
|
+
const life = mix(nodes.lifetime.x, nodes.lifetime.y, random(13, key));
|
|
365
|
+
const alive = varying(step(0, age).mul(step(age, life)));
|
|
366
|
+
const phase = varying(age.div(life).clamp(0, 1));
|
|
367
|
+
const size = mix(nodes.size.x, nodes.size.y, phase);
|
|
368
|
+
void size;
|
|
369
|
+
void phase;
|
|
370
|
+
void alive;
|
|
371
|
+
void key;
|
|
372
|
+
// Baked from the kind's stock values, not read off the uniform nodes: a `SpriteNodeMaterial`
|
|
373
|
+
// whose `colorNode` is built from uniform nodes draws nothing on this three build, and reading
|
|
374
|
+
// those uniforms here happens on the same pass. Behaviour stays live in `process`.
|
|
375
|
+
const stock = KIND_DEFAULTS[options.kind];
|
|
376
|
+
// Pure spell colour, not a blend toward its highlight: additive blending saturates an overlap
|
|
377
|
+
// to white, and a white puff has no colour identity at all — which is exactly what the judge saw.
|
|
378
|
+
const rgb = options.look?.colour ?? stock.colour;
|
|
379
|
+
// A kind whose stock alpha starts at 0 (a mote fading in) would otherwise begin invisible.
|
|
380
|
+
// Low enough that a hundred overlapping sprites stack into a glow instead of a white disc.
|
|
381
|
+
const opacity = Math.min(0.34, Math.max(0.16, (options.look?.alpha ?? stock.alpha[0]) * 0.32));
|
|
382
|
+
// A 3 cm spark is sub-pixel at spell range, which is how this read as "particles do not draw".
|
|
383
|
+
// A 3 cm spark is sub-pixel at spell range. The floor keeps a kind readable without turning
|
|
384
|
+
// every particle into a bokeh ball.
|
|
385
|
+
const spriteSize = Math.max(0.26, (options.look?.size ?? stock.size[0]) * 0.8);
|
|
386
|
+
material.scaleNode = vec2(spriteSize, spriteSize);
|
|
387
|
+
material.colorNode = vec4(rgb[0], rgb[1], rgb[2], opacity).mul(mask(style));
|
|
388
|
+
};
|
|
389
|
+
|
|
390
|
+
const spawn = (
|
|
391
|
+
{
|
|
392
|
+
positions,
|
|
393
|
+
velocities,
|
|
394
|
+
births,
|
|
395
|
+
}: {
|
|
396
|
+
readonly positions: StorageBufferNode<"vec3">;
|
|
397
|
+
readonly velocities: StorageBufferNode<"vec3">;
|
|
398
|
+
readonly births: StorageBufferNode<"float">;
|
|
399
|
+
},
|
|
400
|
+
request: IGPUParticles3DSpawnRequest,
|
|
401
|
+
): ComputeNode => {
|
|
402
|
+
bindMaterial(births.toAttribute());
|
|
403
|
+
return Fn(() => {
|
|
404
|
+
If(instanceIndex.lessThan(request.count), () => {
|
|
405
|
+
const slot = request.first.add(instanceIndex).mod(uint(capacity));
|
|
406
|
+
// `velocities` holds each burst's origin: it is written once and never touched again.
|
|
407
|
+
velocities.element(slot).assign(request.origin);
|
|
408
|
+
positions.element(slot).assign(request.origin);
|
|
409
|
+
});
|
|
410
|
+
})().compute(capacity);
|
|
411
|
+
};
|
|
412
|
+
|
|
413
|
+
const process = ({
|
|
414
|
+
positions,
|
|
415
|
+
velocities,
|
|
416
|
+
births,
|
|
417
|
+
}: {
|
|
418
|
+
readonly positions: StorageBufferNode<"vec3">;
|
|
419
|
+
readonly velocities: StorageBufferNode<"vec3">;
|
|
420
|
+
readonly births: StorageBufferNode<"float">;
|
|
421
|
+
}): ComputeNode =>
|
|
422
|
+
Fn(() => {
|
|
423
|
+
const born = births.element(instanceIndex);
|
|
424
|
+
const key = born.max(0).mul(1000).toUint();
|
|
425
|
+
const age = time.sub(born).max(0);
|
|
426
|
+
// Integrate drag in closed form: v(t) = v0·e^(-k t), so the distance is v0·(1 - e^(-k t))/k.
|
|
427
|
+
// ponytail: the launch axis is the emitter's current direction, not the one at spawn. A trail
|
|
428
|
+
// re-emitted every frame hides it; a spell that turns hard inside one burst will show it.
|
|
429
|
+
const drag = nodes.shape.z.max(1e-3);
|
|
430
|
+
const travel = float(1)
|
|
431
|
+
.sub(exp(drag.mul(age).negate()))
|
|
432
|
+
.div(drag);
|
|
433
|
+
const fall = nodes.shape.y.mul(age.mul(age)).mul(0.5);
|
|
434
|
+
const lift = nodes.shape.w.mul(age.mul(age)).mul(0.5);
|
|
435
|
+
const local = launch(key)
|
|
436
|
+
.mul(travel)
|
|
437
|
+
.add(vec3(0, float(lift.sub(fall)), 0));
|
|
438
|
+
positions.element(instanceIndex).assign(velocities.element(instanceIndex).add(local));
|
|
439
|
+
})().compute(capacity);
|
|
440
|
+
|
|
441
|
+
return {
|
|
442
|
+
amount: capacity,
|
|
443
|
+
lifetime: Math.max(nodes.lifetime.value.y, 0.01),
|
|
444
|
+
material,
|
|
445
|
+
onCull: "pause",
|
|
446
|
+
process,
|
|
447
|
+
spawn,
|
|
448
|
+
};
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
/** A soft round sprite, a smoking puff, or a streaked spark. */
|
|
452
|
+
function mask(style: ParticleStyle): Node<"float"> {
|
|
453
|
+
const point = uv().sub(0.5);
|
|
454
|
+
const radius = point.length();
|
|
455
|
+
if (style === "spark") {
|
|
456
|
+
const streak = float(1)
|
|
457
|
+
.sub(smoothstep(0.02, 0.1, abs(point.y)))
|
|
458
|
+
.mul(float(1).sub(smoothstep(0.14, 0.5, abs(point.x))));
|
|
459
|
+
return float(1)
|
|
460
|
+
.sub(smoothstep(0.06, 0.5, radius))
|
|
461
|
+
.max(streak);
|
|
462
|
+
}
|
|
463
|
+
if (style === "media") return float(1).sub(smoothstep(0.02, 0.5, radius));
|
|
464
|
+
return float(1)
|
|
465
|
+
.sub(smoothstep(0.06, 0.54, radius))
|
|
466
|
+
.add(float(0.22).mul(float(1).sub(smoothstep(0.01, 0.22, radius))));
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
/** Mix two stock colours into one literal, so the sprite needs no uniform. */
|
|
470
|
+
function blendOf(
|
|
471
|
+
from: readonly [number, number, number],
|
|
472
|
+
to: readonly [number, number, number],
|
|
473
|
+
t: number,
|
|
474
|
+
): readonly [number, number, number] {
|
|
475
|
+
return [
|
|
476
|
+
from[0] + (to[0] - from[0]) * t,
|
|
477
|
+
from[1] + (to[1] - from[1]) * t,
|
|
478
|
+
from[2] + (to[2] - from[2]) * t,
|
|
479
|
+
];
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
function nodesFor(values: IParticleKindValues): IParticleKindNodes {
|
|
483
|
+
return {
|
|
484
|
+
alpha: uniform(new Vector2(values.alpha[0], values.alpha[1])),
|
|
485
|
+
colour: uniform(new Vector3(...values.colour)) as UniformNode<"vec3", Vector3>,
|
|
486
|
+
highlight: uniform(new Vector3(...values.highlight)) as UniformNode<"vec3", Vector3>,
|
|
487
|
+
lifetime: uniform(new Vector2(values.lifetime[0], values.lifetime[1])),
|
|
488
|
+
shape: uniform(new Vector4(values.cone, values.gravity, values.drag, values.buoyancy)),
|
|
489
|
+
size: uniform(new Vector2(values.size[0], values.size[1])),
|
|
490
|
+
speed: uniform(new Vector2(values.speed[0], values.speed[1])),
|
|
491
|
+
};
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
function writePair(target: Vector2, pair: readonly [number, number], label: string): void {
|
|
495
|
+
if (!Number.isFinite(pair[0]) || !Number.isFinite(pair[1]))
|
|
496
|
+
throw new TypeError(`${label} must be finite`);
|
|
497
|
+
// A reversed range is not "unusual", it is a caller bug: the kernel would read a negative life.
|
|
498
|
+
if (pair[0] > pair[1]) throw new RangeError(`${label} must be ordered low then high`);
|
|
499
|
+
target.set(pair[0], pair[1]);
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
function writeTriple(
|
|
503
|
+
target: Vector3,
|
|
504
|
+
triple: readonly [number, number, number],
|
|
505
|
+
label: string,
|
|
506
|
+
): void {
|
|
507
|
+
if (!triple.every(Number.isFinite)) throw new TypeError(`${label} must be finite`);
|
|
508
|
+
target.set(triple[0], triple[1], triple[2]);
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
function atLeast(label: string, value: number, minimum: number): number {
|
|
512
|
+
if (!Number.isFinite(value)) throw new TypeError(`${label} must be finite`);
|
|
513
|
+
if (value < minimum) throw new RangeError(`${label} must be at least ${minimum}`);
|
|
514
|
+
return value;
|
|
515
|
+
}
|
|
@@ -31,6 +31,8 @@ export interface IParticleSignificanceOptions {
|
|
|
31
31
|
*/
|
|
32
32
|
export class ParticleSignificance {
|
|
33
33
|
#shed = 0;
|
|
34
|
+
/** Candidates this pass has yielded and not yet resumed. */
|
|
35
|
+
#yielded = 0;
|
|
34
36
|
readonly #decayPerSecond: number;
|
|
35
37
|
readonly #graceSeconds: number;
|
|
36
38
|
readonly #states = new WeakMap<IBudgetCandidate, { yielded: boolean; changedAt: number }>();
|
|
@@ -78,7 +80,16 @@ export class ParticleSignificance {
|
|
|
78
80
|
return this.#shed;
|
|
79
81
|
}
|
|
80
82
|
|
|
83
|
+
/**
|
|
84
|
+
* Nothing to shed and nothing yielded: {@link apply} would change nothing, so the caller can skip
|
|
85
|
+
* asking each candidate its significance (an engine crossing per emitter on the owned engine, PRD-828).
|
|
86
|
+
*/
|
|
87
|
+
get idle(): boolean {
|
|
88
|
+
return this.#shed === 0 && this.#yielded === 0;
|
|
89
|
+
}
|
|
90
|
+
|
|
81
91
|
apply(candidates: Iterable<IBudgetCandidate>, camera: Camera, nowSeconds: number): void {
|
|
92
|
+
if (this.idle) return;
|
|
82
93
|
const ranked: { candidate: IBudgetCandidate; significance: number }[] = [];
|
|
83
94
|
for (const candidate of candidates) {
|
|
84
95
|
const significance = candidate.significance(camera);
|
|
@@ -95,6 +106,7 @@ export class ParticleSignificance {
|
|
|
95
106
|
const yielded = index < count;
|
|
96
107
|
if (state.yielded === yielded || nowSeconds - state.changedAt < this.#graceSeconds) continue;
|
|
97
108
|
candidate.yield(yielded);
|
|
109
|
+
this.#yielded += yielded ? 1 : -1;
|
|
98
110
|
state.yielded = yielded;
|
|
99
111
|
state.changedAt = nowSeconds;
|
|
100
112
|
}
|
package/src/particles.ts
CHANGED
|
@@ -492,17 +492,26 @@ export class GPUParticles3D extends Sprite implements IComputeDriven {
|
|
|
492
492
|
if (camera !== undefined && !this.castShadow && this.#authoredVisible) {
|
|
493
493
|
const bounds = this.measuredBounds;
|
|
494
494
|
if (bounds !== undefined && this.#graceSeconds !== Number.POSITIVE_INFINITY) {
|
|
495
|
-
|
|
496
|
-
this
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
camera.
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
495
|
+
// The native engine folds the same test in one call (PRD-828); a NaN padding asks for the default.
|
|
496
|
+
const engine = (this as { __boundsInView?: (c: Camera, b: Box3, p: number) => boolean })
|
|
497
|
+
.__boundsInView;
|
|
498
|
+
let inView: boolean;
|
|
499
|
+
if (typeof engine === "function")
|
|
500
|
+
inView = engine.call(this, camera, bounds, this.#padding ?? Number.NaN);
|
|
501
|
+
else {
|
|
502
|
+
if (camera.matrixWorldAutoUpdate) camera.updateMatrixWorld();
|
|
503
|
+
this.updateWorldMatrix(true, false);
|
|
504
|
+
viewProjection.multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse);
|
|
505
|
+
frustum.setFromProjectionMatrix(
|
|
506
|
+
viewProjection,
|
|
507
|
+
camera.coordinateSystem,
|
|
508
|
+
camera.reversedDepth,
|
|
509
|
+
);
|
|
510
|
+
worldBox.copy(bounds).applyMatrix4(this.matrixWorld).expandByScalar(this.#worldPadding);
|
|
511
|
+
inView = frustum.intersectsBox(worldBox);
|
|
512
|
+
}
|
|
504
513
|
// ponytail: bounds lag by boundsEveryFrames; grace delays culling and paused clouds do not move.
|
|
505
|
-
if (
|
|
514
|
+
if (inView) this.#outsideSince = undefined;
|
|
506
515
|
else {
|
|
507
516
|
// Wall time is only for callers without a loop clock.
|
|
508
517
|
const now = simulatedSeconds ?? performance.now() / 1000;
|
package/src/picking.ts
CHANGED
|
@@ -60,6 +60,11 @@ function isWithin(object: Object3D, root: Object3D): boolean {
|
|
|
60
60
|
return false;
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
+
/** The game set `raycast` on this instance: a stock `Raycaster` would call it, so picking does too. */
|
|
64
|
+
function ownsRaycast(object: Object3D): boolean {
|
|
65
|
+
return Object.hasOwn(object, "raycast");
|
|
66
|
+
}
|
|
67
|
+
|
|
63
68
|
export class ScenePicker {
|
|
64
69
|
#camera: Camera;
|
|
65
70
|
#pointer: () => Vector2;
|
|
@@ -186,7 +191,8 @@ export class ScenePicker {
|
|
|
186
191
|
root: Object3D,
|
|
187
192
|
): void {
|
|
188
193
|
if (excluded.size !== 0 && this.#isExcluded(object, excluded)) return;
|
|
189
|
-
|
|
194
|
+
// An object with its own `raycast` answers for itself, merged or not (see `#hitTest`).
|
|
195
|
+
const pick = ownsRaycast(object) ? undefined : autoBatchOf(object);
|
|
190
196
|
if (pick !== undefined) {
|
|
191
197
|
// A source the engine merged and hid: its merged mesh answers for it, once per ray.
|
|
192
198
|
if (object.layers.test(this.#raycaster.layers)) this.#reach(pick, root);
|
|
@@ -237,7 +243,12 @@ export class ScenePicker {
|
|
|
237
243
|
for (const hit of found) {
|
|
238
244
|
const source =
|
|
239
245
|
hit.face === null || hit.face === undefined ? undefined : pick.sourceAt(hit.face.a);
|
|
240
|
-
if (
|
|
246
|
+
if (
|
|
247
|
+
source === undefined ||
|
|
248
|
+
ownsRaycast(source) ||
|
|
249
|
+
!roots.some((root) => isWithin(source, root))
|
|
250
|
+
)
|
|
251
|
+
continue;
|
|
241
252
|
if (excluded.size !== 0 && this.#isExcluded(source, excluded)) continue;
|
|
242
253
|
this.#hits.push(this.#asSource(hit, source));
|
|
243
254
|
}
|
|
@@ -258,7 +269,10 @@ export class ScenePicker {
|
|
|
258
269
|
// node identity. Authored primitives are hidden from the render, never from a ray test, so the
|
|
259
270
|
// proxy must be skipped or a pick at distance would answer with an object the game never added.
|
|
260
271
|
if (isLodJoinProxy(object) || isAutoBatchMerged(object)) return;
|
|
261
|
-
|
|
272
|
+
// three's convention: an instance `raycast` (a no-op for decoration, or custom picking) wins
|
|
273
|
+
// over the prototype, as it does under a stock Raycaster and three-mesh-bvh. Building a tree
|
|
274
|
+
// first would cost a decorative 1.5M-triangle mesh a second on its first ray, then be ignored.
|
|
275
|
+
const tree = ownsRaycast(object) ? undefined : this.#treeFor(object);
|
|
262
276
|
if (tree === undefined) {
|
|
263
277
|
object.raycast(this.#raycaster, into);
|
|
264
278
|
return;
|