@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,645 @@
|
|
|
1
|
+
// Ported from Ultra Elements src/vfx/Ribbons.js @698b720 (MIT, Copyright (c) 2026 Humpalumps). JavaScript copied verbatim; GLSL transliterated to TSL.
|
|
2
|
+
import {
|
|
3
|
+
type BufferGeometry,
|
|
4
|
+
Color,
|
|
5
|
+
DataTexture,
|
|
6
|
+
DoubleSide,
|
|
7
|
+
DynamicDrawUsage,
|
|
8
|
+
Float32BufferAttribute,
|
|
9
|
+
FloatType,
|
|
10
|
+
InstancedBufferAttribute,
|
|
11
|
+
InstancedBufferGeometry,
|
|
12
|
+
Mesh,
|
|
13
|
+
NearestFilter,
|
|
14
|
+
RGBAFormat,
|
|
15
|
+
Vector3,
|
|
16
|
+
Vector4,
|
|
17
|
+
} from "three";
|
|
18
|
+
import {
|
|
19
|
+
Fn,
|
|
20
|
+
attribute,
|
|
21
|
+
cameraPosition,
|
|
22
|
+
cameraProjectionMatrix,
|
|
23
|
+
cameraViewMatrix,
|
|
24
|
+
clamp,
|
|
25
|
+
cross,
|
|
26
|
+
dot,
|
|
27
|
+
exp,
|
|
28
|
+
float,
|
|
29
|
+
ivec2,
|
|
30
|
+
length,
|
|
31
|
+
max,
|
|
32
|
+
min,
|
|
33
|
+
mix,
|
|
34
|
+
mod,
|
|
35
|
+
normalize,
|
|
36
|
+
positionGeometry,
|
|
37
|
+
select,
|
|
38
|
+
smoothstep,
|
|
39
|
+
texture,
|
|
40
|
+
textureLoad,
|
|
41
|
+
uniform,
|
|
42
|
+
varying,
|
|
43
|
+
vec2,
|
|
44
|
+
vec3,
|
|
45
|
+
vec4,
|
|
46
|
+
} from "three/tsl";
|
|
47
|
+
import { MeshBasicNodeMaterial, type Node } from "three/webgpu";
|
|
48
|
+
import { FX_DISTORT_BLENDING, LINES_BLENDING, U, fxOutDistort, softFade } from "./common.js";
|
|
49
|
+
|
|
50
|
+
type F = Node<"float">;
|
|
51
|
+
type V2 = Node<"vec2">;
|
|
52
|
+
type V3 = Node<"vec3">;
|
|
53
|
+
type V4 = Node<"vec4">;
|
|
54
|
+
|
|
55
|
+
// Instanced camera-facing strips (PLAN 2.5 "Ribbons and bolts"). One draw per material for every
|
|
56
|
+
// ribbon it owns; nothing is allocated after construction. Strips wind either way depending on
|
|
57
|
+
// the path direction, so every strip material is DoubleSide.
|
|
58
|
+
// TrailRibbons history ribbons: a points x max float texture of head positions, a ring per row
|
|
59
|
+
// AnalyticRibbons stateless: the centreline is user TSL evaluated per vertex
|
|
60
|
+
// Bolts.js builds on STRIP_GLSL too.
|
|
61
|
+
//
|
|
62
|
+
// Distortion amounts everywhere are metres of apparent displacement at the strip's depth, so a far
|
|
63
|
+
// effect bends the background less than a near one.
|
|
64
|
+
// Engine: every 'fx' strip composites its emission and distortion through fxOutDistort (common.ts)
|
|
65
|
+
// with FX_DISTORT_BLENDING; the 'lines' strips keep LINES_BLENDING (additive, alpha 1).
|
|
66
|
+
|
|
67
|
+
// projectionMatrix[1][1]
|
|
68
|
+
const proj11 = (): F =>
|
|
69
|
+
(cameraProjectionMatrix as unknown as { element(i: number): V4 }).element(1).y;
|
|
70
|
+
const viewProj = (p: V3): V4 =>
|
|
71
|
+
cameraProjectionMatrix.mul(cameraViewMatrix).mul(vec4(p, 1.0)) as unknown as V4;
|
|
72
|
+
|
|
73
|
+
// STRIP_GLSL. Needs projectionMatrix, viewMatrix and cameraPosition.
|
|
74
|
+
// Humus "phone-wire" AA: a strip is never drawn thinner than 1.5 px; the width it lacks comes back
|
|
75
|
+
// as intensity (aa = trueWidth / clampedWidth), so thin wires fade out instead of breaking into dashes.
|
|
76
|
+
// Returns the world half width to expand by.
|
|
77
|
+
// ENGINE-GAP: a TSL Fn cannot assign its `out` argument ("assign requires a variable"), so this is
|
|
78
|
+
// plain JS that returns [half width, aa] (the vertex graph is built outside any Fn)
|
|
79
|
+
export const wireHalfWidth = (width: F, viewZ: F, pxPerM: F): [hw: F, aa: F] => {
|
|
80
|
+
const px = width.mul(pxPerM).div(max(viewZ, 1e-3));
|
|
81
|
+
const clamped = max(px, 1.5);
|
|
82
|
+
return [width.mul(0.5).mul(clamped).div(max(px, 1e-6)), px.div(clamped)];
|
|
83
|
+
};
|
|
84
|
+
// pixels per metre at view depth 1, for a target resY pixels tall
|
|
85
|
+
export const pxPerMetre = Fn(([resY]: [F]) => resY.mul(0.5).mul(proj11()));
|
|
86
|
+
// unit side vector of a strip through p with tangent t, facing the camera
|
|
87
|
+
export const stripSide = Fn(([p, t]: [V3, V3]) => {
|
|
88
|
+
const s = cross(t, p.sub(cameraPosition));
|
|
89
|
+
const l = length(s);
|
|
90
|
+
return select(l.greaterThan(1e-7), s.div(l), vec3(1.0, 0.0, 0.0));
|
|
91
|
+
});
|
|
92
|
+
// screen-UV offset of 1 m of apparent displacement along world dir at p (dir ~ perpendicular to the view ray)
|
|
93
|
+
export const distortPerMetre = Fn(([p, dir, viewZ, res]: [V3, V3, F, V2]) => {
|
|
94
|
+
const a = viewProj(p);
|
|
95
|
+
const b = viewProj(p.add(dir.mul(viewZ.mul(0.01))));
|
|
96
|
+
const px = b.xy.div(b.w).sub(a.xy.div(a.w)).mul(res);
|
|
97
|
+
const d = select(dot(px, px).greaterThan(1e-12), normalize(px), vec2(1.0, 0.0));
|
|
98
|
+
const h = proj11().mul(0.5).div(max(viewZ, 1e-3)); // metres -> fraction of screen height
|
|
99
|
+
return d.mul(vec2(h.mul(res.y).div(res.x), h));
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
// dead instances / strands: every vertex at one point outside the clip volume
|
|
103
|
+
const COLLAPSE = (): V4 => vec4(2.0, 2.0, 2.0, 1.0);
|
|
104
|
+
|
|
105
|
+
// (count + 1) x 2 vertex strip; position = (x, side, z) with x from xOf(i)
|
|
106
|
+
function stripIndex(index: number[], base: number, segments: number): void {
|
|
107
|
+
for (let i = 0; i < segments; i++) {
|
|
108
|
+
const a = base + i * 2;
|
|
109
|
+
index.push(a, a + 1, a + 2, a + 1, a + 3, a + 2);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// write 4 floats, report whether anything changed (dirty tracking without allocations)
|
|
114
|
+
export function put4(
|
|
115
|
+
arr: Float32Array,
|
|
116
|
+
o: number,
|
|
117
|
+
x: number,
|
|
118
|
+
y: number,
|
|
119
|
+
z: number,
|
|
120
|
+
w: number,
|
|
121
|
+
): boolean {
|
|
122
|
+
if (arr[o] === x && arr[o + 1] === y && arr[o + 2] === z && arr[o + 3] === w) return false;
|
|
123
|
+
arr[o] = x;
|
|
124
|
+
arr[o + 1] = y;
|
|
125
|
+
arr[o + 2] = z;
|
|
126
|
+
arr[o + 3] = w;
|
|
127
|
+
return true;
|
|
128
|
+
}
|
|
129
|
+
const put4v = (arr: Float32Array, o: number, v: Vector4) => put4(arr, o, v.x, v.y, v.z, v.w);
|
|
130
|
+
|
|
131
|
+
export function instanced(
|
|
132
|
+
geo: BufferGeometry,
|
|
133
|
+
name: string,
|
|
134
|
+
count: number,
|
|
135
|
+
size = 4,
|
|
136
|
+
): InstancedBufferAttribute {
|
|
137
|
+
const attr = new InstancedBufferAttribute(new Float32Array(count * size), size);
|
|
138
|
+
attr.setUsage(DynamicDrawUsage);
|
|
139
|
+
geo.setAttribute(name, attr);
|
|
140
|
+
return attr;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// --- history ribbons ---------------------------------------------------------------------
|
|
144
|
+
|
|
145
|
+
// TRAIL_VERT (fx: TRAIL_FX defined) and its two fragment shaders
|
|
146
|
+
function trailNodes(tex: DataTexture, P: number, uTrailTime: F, fx: boolean) {
|
|
147
|
+
const uTrailTex = texture(tex); // x = point slot (ring), y = trail row; xyz pos, w push time
|
|
148
|
+
const aTrail = attribute("aTrail", "vec4") as unknown as V4; // row, head slot, point count, fade time
|
|
149
|
+
const aLook = attribute("aLook", "vec4") as unknown as V4; // width, glow (fx width multiplier), taper, distortion (m)
|
|
150
|
+
const aColor = attribute("aColor", "vec4") as unknown as V4; // rgb * intensity, glow intensity (fraction of the core's)
|
|
151
|
+
const position = positionGeometry as unknown as V3;
|
|
152
|
+
|
|
153
|
+
const trailPoint = (row: F, head: F, i: F): V4 =>
|
|
154
|
+
textureLoad(
|
|
155
|
+
uTrailTex,
|
|
156
|
+
ivec2(mod(head.sub(i).add(P), float(P)).toInt(), row.toInt()),
|
|
157
|
+
) as unknown as V4;
|
|
158
|
+
|
|
159
|
+
const n = aTrail.z;
|
|
160
|
+
const row = aTrail.x;
|
|
161
|
+
const head = aTrail.y;
|
|
162
|
+
const i = min(position.x, n.sub(1.0));
|
|
163
|
+
const c = trailPoint(row, head, i);
|
|
164
|
+
const tangent = trailPoint(row, head, max(i.sub(1.0), 0.0)).xyz.sub(
|
|
165
|
+
trailPoint(row, head, min(i.add(1.0), n.sub(1.0))).xyz,
|
|
166
|
+
);
|
|
167
|
+
const u = i.div(n.sub(1.0));
|
|
168
|
+
// past the last point the strip folds onto it with zero width (zero-area triangles)
|
|
169
|
+
const alive = select(position.x.greaterThan(n.sub(1.0)), float(0.0), float(1.0));
|
|
170
|
+
const fade0 = clamp(float(1.0).sub(uTrailTime.sub(c.w).div(max(aTrail.w, 1e-3))), 0.0, 1.0);
|
|
171
|
+
const fade = fade0.mul(fade0);
|
|
172
|
+
const view = cameraViewMatrix.mul(vec4(c.xyz, 1.0)) as unknown as V4;
|
|
173
|
+
const viewZ = view.z.negate();
|
|
174
|
+
const side = stripSide(c.xyz, tangent);
|
|
175
|
+
const width = aLook.x.mul(mix(1.0, float(1.0).sub(u), aLook.z)).mul(alive);
|
|
176
|
+
let hw: F;
|
|
177
|
+
let aa: F;
|
|
178
|
+
let color: V3;
|
|
179
|
+
let dist: V2 = vec2(0.0);
|
|
180
|
+
if (fx) {
|
|
181
|
+
// the wide glow would end in a square cap at the head: fade it in over the first two points
|
|
182
|
+
const cap = smoothstep(0.0, 2.0, i);
|
|
183
|
+
[hw, aa] = wireHalfWidth(
|
|
184
|
+
width.mul(aLook.y).mul(mix(0.4, 1.0, cap)),
|
|
185
|
+
viewZ,
|
|
186
|
+
pxPerMetre(U.uFxResolution.y),
|
|
187
|
+
);
|
|
188
|
+
color = aColor.rgb.mul(aColor.a).mul(fade).mul(aa).mul(cap);
|
|
189
|
+
dist = distortPerMetre(c.xyz, side, viewZ, U.uFxResolution).mul(aLook.w).mul(fade);
|
|
190
|
+
} else {
|
|
191
|
+
[hw, aa] = wireHalfWidth(width, viewZ, pxPerMetre(U.uResolution.y));
|
|
192
|
+
color = aColor.rgb.mul(fade).mul(aa);
|
|
193
|
+
}
|
|
194
|
+
const vertexNode = select(
|
|
195
|
+
n.lessThan(2.0),
|
|
196
|
+
COLLAPSE(),
|
|
197
|
+
viewProj(c.xyz.add(side.mul(position.y).mul(hw))),
|
|
198
|
+
);
|
|
199
|
+
const vUv = varying(vec2(u, position.y)) as unknown as V2; // along (0 head .. 1 tail), across (-1..1)
|
|
200
|
+
const vColor = varying(color) as unknown as V3;
|
|
201
|
+
const vViewZ = varying(viewZ) as unknown as F;
|
|
202
|
+
const vDist = varying(dist) as unknown as V2;
|
|
203
|
+
|
|
204
|
+
let fragmentNode: V4;
|
|
205
|
+
if (fx) {
|
|
206
|
+
// TRAIL_FX_FRAG
|
|
207
|
+
const v = vUv.y;
|
|
208
|
+
const g = max(exp(v.mul(v).mul(-4.0)).sub(0.0183), 0.0); // gaussian, zero at the strip edge
|
|
209
|
+
// derivative-of-gaussian profile: the centreline acts as a cylindrical lens (pushes outward)
|
|
210
|
+
const d = vDist.mul(v.mul(exp(v.mul(v).mul(-3.0))).mul(2.33));
|
|
211
|
+
fragmentNode = fxOutDistort(vColor.mul(g).mul(softFade(vViewZ, 0.4)), d, vec3(0.0), float(0.0));
|
|
212
|
+
} else {
|
|
213
|
+
// TRAIL_LINES_FRAG
|
|
214
|
+
const v = float(1.0).sub(vUv.y.mul(vUv.y));
|
|
215
|
+
fragmentNode = vec4(vColor.mul(v).mul(v), 1.0);
|
|
216
|
+
}
|
|
217
|
+
return { vertexNode, fragmentNode };
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// per-trail look, reset on acquire. spacing: metres between committed points (points * spacing
|
|
221
|
+
// caps the trail's length; fadeTime its duration)
|
|
222
|
+
const TRAIL_DEFAULTS = {
|
|
223
|
+
width: 0.06,
|
|
224
|
+
intensity: 4,
|
|
225
|
+
glow: 6,
|
|
226
|
+
glowIntensity: 0.3,
|
|
227
|
+
distortion: 0,
|
|
228
|
+
taper: 1,
|
|
229
|
+
fadeTime: 0.4,
|
|
230
|
+
spacing: 0.08,
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
export interface ITrailHandle {
|
|
234
|
+
row: number;
|
|
235
|
+
active: boolean;
|
|
236
|
+
released: boolean;
|
|
237
|
+
head: number;
|
|
238
|
+
count: number;
|
|
239
|
+
lastPush: number;
|
|
240
|
+
last: Vector3;
|
|
241
|
+
color: Color;
|
|
242
|
+
width: number;
|
|
243
|
+
intensity: number;
|
|
244
|
+
glow: number;
|
|
245
|
+
glowIntensity: number;
|
|
246
|
+
distortion: number;
|
|
247
|
+
taper: number;
|
|
248
|
+
fadeTime: number;
|
|
249
|
+
spacing: number;
|
|
250
|
+
push(p: Vector3): void;
|
|
251
|
+
release(): void;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
export class TrailRibbons {
|
|
255
|
+
readonly max: number;
|
|
256
|
+
readonly points: number;
|
|
257
|
+
time = 0;
|
|
258
|
+
readonly data: Float32Array;
|
|
259
|
+
readonly texture: DataTexture;
|
|
260
|
+
private _ranges: { start: number; count: number }[];
|
|
261
|
+
private _nRanges = 0;
|
|
262
|
+
private _full = false;
|
|
263
|
+
readonly geometry: InstancedBufferGeometry;
|
|
264
|
+
readonly aTrail: InstancedBufferAttribute;
|
|
265
|
+
readonly aLook: InstancedBufferAttribute;
|
|
266
|
+
readonly aColor: InstancedBufferAttribute;
|
|
267
|
+
readonly uniforms: typeof U & {
|
|
268
|
+
uTrailTex: { value: DataTexture };
|
|
269
|
+
uTrailTime: F & { value: number };
|
|
270
|
+
};
|
|
271
|
+
readonly lines: Mesh;
|
|
272
|
+
readonly fx: Mesh;
|
|
273
|
+
readonly trails: ITrailHandle[];
|
|
274
|
+
|
|
275
|
+
constructor({ max = 64, points = 48 } = {}) {
|
|
276
|
+
this.max = max;
|
|
277
|
+
this.points = points;
|
|
278
|
+
this.data = new Float32Array(points * max * 4);
|
|
279
|
+
const tex = new DataTexture(this.data, points, max, RGBAFormat, FloatType);
|
|
280
|
+
this.texture = tex;
|
|
281
|
+
tex.minFilter = tex.magFilter = NearestFilter;
|
|
282
|
+
tex.needsUpdate = true;
|
|
283
|
+
// one texel per push; preallocated so pushing into texture.updateRanges allocates nothing
|
|
284
|
+
this._ranges = Array.from({ length: max * 4 }, () => ({ start: 0, count: 0 }));
|
|
285
|
+
|
|
286
|
+
const geo = new InstancedBufferGeometry();
|
|
287
|
+
const pos: number[] = [];
|
|
288
|
+
const index: number[] = [];
|
|
289
|
+
for (let i = 0; i < points; i++) pos.push(i, -1, 0, i, 1, 0);
|
|
290
|
+
stripIndex(index, 0, points - 1);
|
|
291
|
+
geo.setAttribute("position", new Float32BufferAttribute(pos, 3));
|
|
292
|
+
geo.setIndex(index);
|
|
293
|
+
this.aTrail = instanced(geo, "aTrail", max);
|
|
294
|
+
this.aLook = instanced(geo, "aLook", max);
|
|
295
|
+
this.aColor = instanced(geo, "aColor", max);
|
|
296
|
+
geo.instanceCount = 0;
|
|
297
|
+
this.geometry = geo;
|
|
298
|
+
|
|
299
|
+
const uTrailTime = uniform(0) as unknown as F & { value: number };
|
|
300
|
+
this.uniforms = { ...U, uTrailTex: { value: tex }, uTrailTime };
|
|
301
|
+
const make = (blending: object, fx: boolean): Mesh => {
|
|
302
|
+
const material = new MeshBasicNodeMaterial({ ...blending, side: DoubleSide });
|
|
303
|
+
material.fog = false;
|
|
304
|
+
const nodes = trailNodes(tex, points, uTrailTime, fx);
|
|
305
|
+
material.vertexNode = nodes.vertexNode;
|
|
306
|
+
material.fragmentNode = nodes.fragmentNode;
|
|
307
|
+
const mesh = new Mesh(geo, material);
|
|
308
|
+
mesh.frustumCulled = false;
|
|
309
|
+
mesh.visible = false;
|
|
310
|
+
mesh.renderOrder = 10;
|
|
311
|
+
return mesh;
|
|
312
|
+
};
|
|
313
|
+
this.lines = make(LINES_BLENDING, false);
|
|
314
|
+
this.fx = make(FX_DISTORT_BLENDING, true);
|
|
315
|
+
|
|
316
|
+
const owner = this;
|
|
317
|
+
this.trails = Array.from(
|
|
318
|
+
{ length: max },
|
|
319
|
+
(_, row): ITrailHandle => ({
|
|
320
|
+
row,
|
|
321
|
+
active: false,
|
|
322
|
+
released: false,
|
|
323
|
+
head: 0,
|
|
324
|
+
count: 0,
|
|
325
|
+
lastPush: 0,
|
|
326
|
+
last: new Vector3(),
|
|
327
|
+
color: new Color(1, 1, 1),
|
|
328
|
+
...TRAIL_DEFAULTS,
|
|
329
|
+
// the newest point follows pos; a new point is committed once it is `spacing` from the last
|
|
330
|
+
push(p: Vector3) {
|
|
331
|
+
if (this.count > 0 && this.last.distanceToSquared(p) >= this.spacing * this.spacing) {
|
|
332
|
+
this.head = (this.head + 1) % owner.points;
|
|
333
|
+
this.count = Math.min(this.count + 1, owner.points);
|
|
334
|
+
this.last.copy(p);
|
|
335
|
+
} else if (this.count === 0) {
|
|
336
|
+
this.count = 1;
|
|
337
|
+
this.last.copy(p);
|
|
338
|
+
}
|
|
339
|
+
owner._write(this.row, this.head, p);
|
|
340
|
+
this.lastPush = owner.time;
|
|
341
|
+
},
|
|
342
|
+
release() {
|
|
343
|
+
this.released = true;
|
|
344
|
+
},
|
|
345
|
+
}),
|
|
346
|
+
);
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
// released trails keep drawing until their newest point has faded (fadeTime), then free
|
|
350
|
+
acquire(): ITrailHandle | null {
|
|
351
|
+
for (const t of this.trails) {
|
|
352
|
+
if (t.active) continue;
|
|
353
|
+
Object.assign(t, TRAIL_DEFAULTS);
|
|
354
|
+
t.active = true;
|
|
355
|
+
t.released = false;
|
|
356
|
+
t.head = 0;
|
|
357
|
+
t.count = 0;
|
|
358
|
+
t.color.setRGB(1, 1, 1);
|
|
359
|
+
return t;
|
|
360
|
+
}
|
|
361
|
+
return null;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
_write(row: number, slot: number, p: Vector3): void {
|
|
365
|
+
const i = row * this.points + slot;
|
|
366
|
+
const o = i * 4;
|
|
367
|
+
const d = this.data;
|
|
368
|
+
d[o] = p.x;
|
|
369
|
+
d[o + 1] = p.y;
|
|
370
|
+
d[o + 2] = p.z;
|
|
371
|
+
d[o + 3] = this.time;
|
|
372
|
+
if (this._nRanges < this._ranges.length) {
|
|
373
|
+
const r = this._ranges[this._nRanges++] as { start: number; count: number };
|
|
374
|
+
r.start = o;
|
|
375
|
+
r.count = 4;
|
|
376
|
+
} else this._full = true;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: upstream Ultra Elements code, copied verbatim
|
|
380
|
+
update(dt: number): void {
|
|
381
|
+
this.time += dt;
|
|
382
|
+
this.uniforms.uTrailTime.value = this.time;
|
|
383
|
+
const A = this.aTrail.array as Float32Array;
|
|
384
|
+
const B = this.aLook.array as Float32Array;
|
|
385
|
+
const C = this.aColor.array as Float32Array;
|
|
386
|
+
let n = 0;
|
|
387
|
+
for (const t of this.trails) {
|
|
388
|
+
if (!t.active) continue;
|
|
389
|
+
if (t.released && this.time - t.lastPush > t.fadeTime) {
|
|
390
|
+
t.active = false;
|
|
391
|
+
continue;
|
|
392
|
+
}
|
|
393
|
+
const o = n * 4;
|
|
394
|
+
const I = t.intensity;
|
|
395
|
+
A[o] = t.row;
|
|
396
|
+
A[o + 1] = t.head;
|
|
397
|
+
A[o + 2] = t.count;
|
|
398
|
+
A[o + 3] = t.fadeTime;
|
|
399
|
+
B[o] = t.width;
|
|
400
|
+
B[o + 1] = t.glow;
|
|
401
|
+
B[o + 2] = t.taper;
|
|
402
|
+
B[o + 3] = t.distortion;
|
|
403
|
+
C[o] = t.color.r * I;
|
|
404
|
+
C[o + 1] = t.color.g * I;
|
|
405
|
+
C[o + 2] = t.color.b * I;
|
|
406
|
+
C[o + 3] = t.glowIntensity;
|
|
407
|
+
n++;
|
|
408
|
+
}
|
|
409
|
+
this.geometry.instanceCount = n;
|
|
410
|
+
this.lines.visible = this.fx.visible = n > 0;
|
|
411
|
+
if (n) this.aTrail.needsUpdate = this.aLook.needsUpdate = this.aColor.needsUpdate = true;
|
|
412
|
+
|
|
413
|
+
// texel uploads: only what was pushed. Ranges still queued from a frame that never drew mean
|
|
414
|
+
// the GPU copy is behind, so send the whole texture once (48 KB at 64 x 48).
|
|
415
|
+
// Engine: a texture without updateRanges uploads whole on needsUpdate.
|
|
416
|
+
const tex = this.texture as DataTexture & { updateRanges?: { start: number; count: number }[] };
|
|
417
|
+
const ranges = tex.updateRanges;
|
|
418
|
+
if (ranges === undefined) {
|
|
419
|
+
if (this._nRanges || this._full) tex.needsUpdate = true;
|
|
420
|
+
} else {
|
|
421
|
+
if (ranges.length) this._full = true;
|
|
422
|
+
if (this._full) {
|
|
423
|
+
ranges.length = 0;
|
|
424
|
+
tex.needsUpdate = true;
|
|
425
|
+
} else if (this._nRanges) {
|
|
426
|
+
for (let i = 0; i < this._nRanges; i++)
|
|
427
|
+
ranges.push(this._ranges[i] as { start: number; count: number });
|
|
428
|
+
tex.needsUpdate = true;
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
this._full = false;
|
|
432
|
+
this._nRanges = 0;
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
// --- analytic ribbons ------------------------------------------------------------------
|
|
437
|
+
|
|
438
|
+
// ANALYTIC_HEAD's RibbonFrag; a TSL Fn cannot take a struct here, so the shade is plain JS over nodes
|
|
439
|
+
export interface IRibbonFrag {
|
|
440
|
+
uv: V2; // x along 0..1, y across -1..1
|
|
441
|
+
p0: V4;
|
|
442
|
+
p1: V4;
|
|
443
|
+
p2: V4;
|
|
444
|
+
p3: V4;
|
|
445
|
+
color: V3; // colour * intensity
|
|
446
|
+
viewZ: F;
|
|
447
|
+
}
|
|
448
|
+
// pathGLSL -> path: vec3 ribbonPath(float t, vec4 p0, vec4 p1, vec4 p2, vec4 p3, out float width) t 0..1
|
|
449
|
+
// ENGINE-GAP: no Fn out arguments, so a path returns { p, width }
|
|
450
|
+
export type RibbonPath = (t: F, p0: V4, p1: V4, p2: V4, p3: V4) => { p: V3; width: F };
|
|
451
|
+
// shadeGLSL -> shade: vec3 ribbonShade(RibbonFrag r, out vec3 media, out float alpha, out float distortion)
|
|
452
|
+
// returns emission; media/alpha (WBOIT coverage) and distortion only count for target 'fx'.
|
|
453
|
+
// distortion: signed metres along the +uv.y side; make it odd in uv.y (e.g. uv.y * exp(-3 uv.y^2))
|
|
454
|
+
// to push the background away from the centreline.
|
|
455
|
+
export type RibbonShade = (r: IRibbonFrag, media: V3, alpha: F, distortion: F) => V3;
|
|
456
|
+
|
|
457
|
+
// The default shade: a soft additive core in the ribbon's colour.
|
|
458
|
+
const DEFAULT_SHADE: RibbonShade = (r, media, alpha, distortion) => {
|
|
459
|
+
media.assign(vec3(0.0));
|
|
460
|
+
alpha.assign(0.0);
|
|
461
|
+
distortion.assign(0.0);
|
|
462
|
+
const v = float(1.0).sub(r.uv.y.mul(r.uv.y));
|
|
463
|
+
return r.color.mul(v).mul(v);
|
|
464
|
+
};
|
|
465
|
+
|
|
466
|
+
// ANALYTIC_VERT + ANALYTIC_LINES_FRAG / ANALYTIC_FX_FRAG
|
|
467
|
+
function analyticNodes(segments: number, path: RibbonPath, shade: RibbonShade, fx: boolean) {
|
|
468
|
+
const uSegments = float(segments);
|
|
469
|
+
const aP0 = attribute("aP0", "vec4") as unknown as V4;
|
|
470
|
+
const aP1 = attribute("aP1", "vec4") as unknown as V4;
|
|
471
|
+
const aP2 = attribute("aP2", "vec4") as unknown as V4;
|
|
472
|
+
const aP3 = attribute("aP3", "vec4") as unknown as V4;
|
|
473
|
+
const aColor = attribute("aColor", "vec4") as unknown as V4; // rgb * intensity, on
|
|
474
|
+
const position = positionGeometry as unknown as V3;
|
|
475
|
+
|
|
476
|
+
const t = position.x;
|
|
477
|
+
const { p, width: w } = path(t, aP0, aP1, aP2, aP3);
|
|
478
|
+
const h = float(0.5).div(uSegments);
|
|
479
|
+
const tangent = path(min(t.add(h), 1.0), aP0, aP1, aP2, aP3).p.sub(
|
|
480
|
+
path(max(t.sub(h), 0.0), aP0, aP1, aP2, aP3).p,
|
|
481
|
+
);
|
|
482
|
+
const side = stripSide(p, tangent);
|
|
483
|
+
const viewZ = (cameraViewMatrix.mul(vec4(p, 1.0)) as unknown as V4).z.negate();
|
|
484
|
+
const [hw, aa] = fx
|
|
485
|
+
? wireHalfWidth(w, viewZ, pxPerMetre(U.uFxResolution.y))
|
|
486
|
+
: wireHalfWidth(w, viewZ, pxPerMetre(U.uResolution.y));
|
|
487
|
+
const dist = fx ? distortPerMetre(p, side, viewZ, U.uFxResolution) : vec2(0.0);
|
|
488
|
+
const vertexNode = select(
|
|
489
|
+
aColor.a.lessThanEqual(0.0),
|
|
490
|
+
COLLAPSE(),
|
|
491
|
+
viewProj(p.add(side.mul(position.y).mul(hw))),
|
|
492
|
+
);
|
|
493
|
+
const vUv = varying(vec2(t, position.y)) as unknown as V2;
|
|
494
|
+
const vViewZ = varying(viewZ) as unknown as F;
|
|
495
|
+
const vAA = varying(aa) as unknown as F;
|
|
496
|
+
const vDist = varying(dist) as unknown as V2;
|
|
497
|
+
const r: IRibbonFrag = {
|
|
498
|
+
uv: vUv,
|
|
499
|
+
p0: varying(aP0) as unknown as V4,
|
|
500
|
+
p1: varying(aP1) as unknown as V4,
|
|
501
|
+
p2: varying(aP2) as unknown as V4,
|
|
502
|
+
p3: varying(aP3) as unknown as V4,
|
|
503
|
+
color: varying(aColor.rgb) as unknown as V3,
|
|
504
|
+
viewZ: vViewZ,
|
|
505
|
+
};
|
|
506
|
+
const fragmentNode = Fn(() => {
|
|
507
|
+
const media = vec3(0.0).toVar();
|
|
508
|
+
const alpha = float(0.0).toVar();
|
|
509
|
+
const distortion = float(0.0).toVar();
|
|
510
|
+
const e = shade(r, media, alpha, distortion);
|
|
511
|
+
if (!fx) return vec4(e.mul(vAA), 1.0);
|
|
512
|
+
const s = softFade(vViewZ, 0.3).mul(vAA);
|
|
513
|
+
// fxOut(media, alpha * s, e * s, vDist * distortion * s, vViewZ)
|
|
514
|
+
return fxOutDistort(e.mul(s), vDist.mul(distortion).mul(s), media, alpha.mul(s));
|
|
515
|
+
})();
|
|
516
|
+
return { vertexNode, fragmentNode };
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
export interface IAnalyticRibbon {
|
|
520
|
+
index: number;
|
|
521
|
+
active: boolean;
|
|
522
|
+
p0: Vector4;
|
|
523
|
+
p1: Vector4;
|
|
524
|
+
p2: Vector4;
|
|
525
|
+
p3: Vector4;
|
|
526
|
+
color: Color;
|
|
527
|
+
intensity: number;
|
|
528
|
+
release(): void;
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
// path / shade: TSL in place of upstream's pathGLSL / shadeGLSL (see RibbonPath, RibbonShade).
|
|
532
|
+
// Either may close over its own uniform nodes (upstream: `uniforms`, kept on this.uniforms).
|
|
533
|
+
export class AnalyticRibbons {
|
|
534
|
+
readonly max: number;
|
|
535
|
+
readonly geometry: InstancedBufferGeometry;
|
|
536
|
+
readonly attrs: InstancedBufferAttribute[];
|
|
537
|
+
readonly uniforms: Record<string, unknown>;
|
|
538
|
+
readonly mesh: Mesh;
|
|
539
|
+
readonly ribbons: IAnalyticRibbon[];
|
|
540
|
+
|
|
541
|
+
constructor({
|
|
542
|
+
max = 16,
|
|
543
|
+
segments = 64,
|
|
544
|
+
path,
|
|
545
|
+
shade = DEFAULT_SHADE,
|
|
546
|
+
target = "lines",
|
|
547
|
+
uniforms = {},
|
|
548
|
+
}: {
|
|
549
|
+
max?: number;
|
|
550
|
+
segments?: number;
|
|
551
|
+
path: RibbonPath;
|
|
552
|
+
shade?: RibbonShade;
|
|
553
|
+
target?: "lines" | "fx";
|
|
554
|
+
uniforms?: Record<string, unknown>;
|
|
555
|
+
}) {
|
|
556
|
+
this.max = max;
|
|
557
|
+
const geo = new InstancedBufferGeometry();
|
|
558
|
+
const pos: number[] = [];
|
|
559
|
+
const index: number[] = [];
|
|
560
|
+
for (let i = 0; i <= segments; i++) pos.push(i / segments, -1, 0, i / segments, 1, 0);
|
|
561
|
+
stripIndex(index, 0, segments);
|
|
562
|
+
geo.setAttribute("position", new Float32BufferAttribute(pos, 3));
|
|
563
|
+
geo.setIndex(index);
|
|
564
|
+
this.attrs = ["aP0", "aP1", "aP2", "aP3", "aColor"].map((n) => instanced(geo, n, max));
|
|
565
|
+
geo.instanceCount = 0;
|
|
566
|
+
this.geometry = geo;
|
|
567
|
+
this.uniforms = { ...U, ...uniforms, uSegments: { value: segments } };
|
|
568
|
+
const fx = target === "fx";
|
|
569
|
+
const material = new MeshBasicNodeMaterial({
|
|
570
|
+
...(fx ? FX_DISTORT_BLENDING : LINES_BLENDING),
|
|
571
|
+
side: DoubleSide,
|
|
572
|
+
});
|
|
573
|
+
material.fog = false;
|
|
574
|
+
const nodes = analyticNodes(segments, path, shade, fx);
|
|
575
|
+
material.vertexNode = nodes.vertexNode;
|
|
576
|
+
material.fragmentNode = nodes.fragmentNode;
|
|
577
|
+
this.mesh = new Mesh(geo, material);
|
|
578
|
+
this.mesh.frustumCulled = false;
|
|
579
|
+
this.mesh.visible = false;
|
|
580
|
+
this.mesh.renderOrder = 10;
|
|
581
|
+
this.ribbons = Array.from({ length: max }, (_, index) => ({
|
|
582
|
+
index,
|
|
583
|
+
active: false,
|
|
584
|
+
p0: new Vector4(),
|
|
585
|
+
p1: new Vector4(),
|
|
586
|
+
p2: new Vector4(),
|
|
587
|
+
p3: new Vector4(),
|
|
588
|
+
color: new Color(1, 1, 1),
|
|
589
|
+
intensity: 1,
|
|
590
|
+
release() {
|
|
591
|
+
this.active = false;
|
|
592
|
+
},
|
|
593
|
+
}));
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
acquire(): IAnalyticRibbon | null {
|
|
597
|
+
for (const r of this.ribbons) {
|
|
598
|
+
if (r.active) continue;
|
|
599
|
+
r.active = true;
|
|
600
|
+
r.intensity = 1;
|
|
601
|
+
r.color.setRGB(1, 1, 1);
|
|
602
|
+
r.p0.set(0, 0, 0, 0);
|
|
603
|
+
r.p1.set(0, 0, 0, 0);
|
|
604
|
+
r.p2.set(0, 0, 0, 0);
|
|
605
|
+
r.p3.set(0, 0, 0, 0);
|
|
606
|
+
return r;
|
|
607
|
+
}
|
|
608
|
+
return null;
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
// copy handle fields into the instance attributes; upload only if something changed
|
|
612
|
+
// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: upstream Ultra Elements code, copied verbatim
|
|
613
|
+
update(): void {
|
|
614
|
+
let top = 0;
|
|
615
|
+
let dirty = false;
|
|
616
|
+
const X = this.attrs;
|
|
617
|
+
const a0 = X[0]?.array as Float32Array;
|
|
618
|
+
const a1 = X[1]?.array as Float32Array;
|
|
619
|
+
const a2 = X[2]?.array as Float32Array;
|
|
620
|
+
const a3 = X[3]?.array as Float32Array;
|
|
621
|
+
const ac = X[4]?.array as Float32Array;
|
|
622
|
+
for (const r of this.ribbons) {
|
|
623
|
+
const o = r.index * 4;
|
|
624
|
+
const on = r.active && r.intensity > 0;
|
|
625
|
+
if (on) top = r.index + 1;
|
|
626
|
+
dirty =
|
|
627
|
+
put4(
|
|
628
|
+
ac,
|
|
629
|
+
o,
|
|
630
|
+
r.color.r * r.intensity,
|
|
631
|
+
r.color.g * r.intensity,
|
|
632
|
+
r.color.b * r.intensity,
|
|
633
|
+
on ? 1 : 0,
|
|
634
|
+
) || dirty;
|
|
635
|
+
if (!on) continue;
|
|
636
|
+
dirty = put4v(a0, o, r.p0) || dirty;
|
|
637
|
+
dirty = put4v(a1, o, r.p1) || dirty;
|
|
638
|
+
dirty = put4v(a2, o, r.p2) || dirty;
|
|
639
|
+
dirty = put4v(a3, o, r.p3) || dirty;
|
|
640
|
+
}
|
|
641
|
+
if (dirty) for (const x of this.attrs) x.needsUpdate = true;
|
|
642
|
+
this.geometry.instanceCount = top;
|
|
643
|
+
this.mesh.visible = top > 0;
|
|
644
|
+
}
|
|
645
|
+
}
|