roamwright 0.61.19 → 0.61.21
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 +13 -12
- package/examples/scenes.html +54 -0
- package/examples/scenes.js +594 -0
- package/geometry/primitives.js +13 -0
- package/geometry/projectile-shapes.js +85 -0
- package/index.js +52 -1
- package/motion/fallen-mount.js +63 -0
- package/motion/melee-combat.js +328 -0
- package/motion/melee-cuts.js +395 -0
- package/motion/melee-duels.js +142 -0
- package/motion/melee-exchange-creatures.js +86 -0
- package/motion/melee-exchange.js +498 -0
- package/motion/melee-reactions.js +147 -0
- package/motion/prop-contact.js +87 -0
- package/motion/triangle-height-field.js +177 -0
- package/package.json +1 -1
- package/rendering/blade-trails.js +128 -0
- package/rendering/scene-beams.js +486 -0
- package/rendering/scene-coverage.js +500 -0
- package/rendering/scene-markers.js +421 -0
- package/rendering/scene-projectiles.js +395 -0
- package/rendering/scene-props.js +383 -0
- package/rendering/scene-shots.js +199 -0
- package/runtime/foley-surface.js +79 -0
- package/runtime/scene-script.js +137 -0
- package/runtime/scene-zones.js +117 -0
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Contact-transition IK for scene props: guides one or two actors' hands to a shared handoff
|
|
3
|
+
* point, a tabletop slide elevation, or a world resting point before transferring grip ownership.
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import * as THREE from 'three';
|
|
8
|
+
import { sstep } from '../math/scalar.js';
|
|
9
|
+
import { createContactTransition } from './contact-transition.js';
|
|
10
|
+
|
|
11
|
+
const _grip = new THREE.Vector3(),
|
|
12
|
+
_origin = new THREE.Vector3(),
|
|
13
|
+
_meeting = new THREE.Vector3(),
|
|
14
|
+
_shoulder = new THREE.Vector3();
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Starts a timed handoff or placement contact transition for prop `p`.
|
|
18
|
+
* @param {object} p Prop registry entry (`hand`, `left`, `grip`, `s`, `obj`, `taken`).
|
|
19
|
+
* @param {number} seconds Duration of the reach-and-transfer transition in seconds.
|
|
20
|
+
* @param {object} options
|
|
21
|
+
* @param {object | null} [options.to] Receiving actor, or `null` when laying the prop down.
|
|
22
|
+
* @param {boolean} [options.toLeft] True when transferring into the receiver's left hand.
|
|
23
|
+
* @param {THREE.Vector3 | null} [options.at] World target point when picking up or laying down.
|
|
24
|
+
* @param {THREE.Quaternion | null} [options.turn] Target world orientation when laying down or handing a blade.
|
|
25
|
+
* @param {number | null} [options.slideHeight] Optional tabletop height above ground for sliding handoffs.
|
|
26
|
+
* @param {object} helpers Actor hand/IK/ground hooks.
|
|
27
|
+
* @param {(actor: object, radius: number, out: THREE.Vector3, left: boolean) => void} helpers.inHand Computes world grip point inside an actor's hand.
|
|
28
|
+
* @param {(actor: object, radius: number, snap: boolean, left: boolean) => boolean} helpers.closeHand Closes an actor's fingers around `radius`.
|
|
29
|
+
* @param {(actor: object, left: boolean) => void} helpers.openHand Opens an actor's hand.
|
|
30
|
+
* @param {Function} helpers.reachArm Two-bone arm IK solver.
|
|
31
|
+
* @param {(x: number, z: number) => number} helpers.groundAt Ground height sampler.
|
|
32
|
+
* @returns {{ from: object | null, to: object | null, turn: THREE.Quaternion | null, phase: number, approach: number, advance: (dt: number) => boolean }} Active contact controller.
|
|
33
|
+
*/
|
|
34
|
+
export function createPropContact(
|
|
35
|
+
p,
|
|
36
|
+
seconds,
|
|
37
|
+
{ to = null, toLeft = false, at = null, turn = null, slideHeight = null },
|
|
38
|
+
{ inHand, closeHand, openHand, reachArm, groundAt },
|
|
39
|
+
) {
|
|
40
|
+
const from = p.hand,
|
|
41
|
+
fromLeft = p.left,
|
|
42
|
+
radius = p.grip * p.s,
|
|
43
|
+
contact = { from, to, turn, phase: 0, approach: 0, advance: null };
|
|
44
|
+
|
|
45
|
+
function guideGrip(actor, weight, left) {
|
|
46
|
+
if (!actor || !weight) return;
|
|
47
|
+
const wrist = left ? actor.handL : actor.handR,
|
|
48
|
+
fore = left ? actor.foreL : actor.foreR;
|
|
49
|
+
if (!fore || !wrist) return;
|
|
50
|
+
inHand(actor, radius, _grip, left);
|
|
51
|
+
wrist.worldToLocal(_grip);
|
|
52
|
+
reachArm(left ? actor.armL : actor.armR, fore, wrist, _grip, _origin, _meeting, left ? -1 : 1, weight);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
contact.advance = createContactTransition({
|
|
56
|
+
duration: seconds,
|
|
57
|
+
pose(weight, approach, phase) {
|
|
58
|
+
contact.phase = phase;
|
|
59
|
+
contact.approach = approach;
|
|
60
|
+
if (from && to) {
|
|
61
|
+
const giverArm = fromLeft ? from.armL : from.armR,
|
|
62
|
+
receiverArm = toLeft ? to.armL : to.armR;
|
|
63
|
+
if (!giverArm || !receiverArm) return;
|
|
64
|
+
giverArm.getWorldPosition(_meeting);
|
|
65
|
+
receiverArm.getWorldPosition(_shoulder);
|
|
66
|
+
_meeting.lerp(_shoulder, 0.5);
|
|
67
|
+
if (slideHeight != null) {
|
|
68
|
+
_meeting.lerp(_shoulder, 0.18 * sstep(0.18, 0.54, phase));
|
|
69
|
+
_meeting.y = groundAt(_meeting.x, _meeting.z) + slideHeight;
|
|
70
|
+
} else _meeting.y -= 0.24;
|
|
71
|
+
} else _meeting.copy(at);
|
|
72
|
+
guideGrip(from, weight, fromLeft);
|
|
73
|
+
guideGrip(to, weight, toLeft);
|
|
74
|
+
},
|
|
75
|
+
transfer() {
|
|
76
|
+
if (from) openHand(from, fromLeft);
|
|
77
|
+
p.left = toLeft;
|
|
78
|
+
p.hand = to;
|
|
79
|
+
if (to) p.taken = closeHand(to, radius, false, toLeft);
|
|
80
|
+
else {
|
|
81
|
+
p.obj.position.copy(at);
|
|
82
|
+
p.obj.quaternion.copy(turn);
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
return contact;
|
|
87
|
+
}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A walkable height field over a triangle soup, for a solid the player can walk on and be stopped by, a moving one
|
|
3
|
+
* included (query it in the solid's own frame). Faces are sorted into floors and cliffs by how steeply they stand, kept
|
|
4
|
+
* packed ten numbers each, and listed by the cells of a square grid they cover, so a query reads only the faces near it.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const FACE = 10; // a face's corner, its two edges from it, and 1/area seen from above for a floor (0 for a wall)
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Makes an empty height field to fill with triangles.
|
|
11
|
+
* @param {object} [options]
|
|
12
|
+
* @param {number} [options.cell=8] the grid's cell size, in the soup's units
|
|
13
|
+
* @param {number} [options.firstFaces=4096] faces room is made for at first; the room doubles as it fills
|
|
14
|
+
* @param {number} [options.floorSlope=0.17] a face is a floor where its upward share of the normal is over this
|
|
15
|
+
* @param {number} [options.cliffSlope=0.62] and a cliff where it is under this (a face between the two is both)
|
|
16
|
+
* @param {number} [options.reach=0.31] how far ahead of a step a cliff stops it
|
|
17
|
+
* @param {number[]} [options.rays] the heights over the feet at which a step is tested against cliffs (knee and eye)
|
|
18
|
+
* @returns {{
|
|
19
|
+
* add(positions: ArrayLike<number>, start?: number): void,
|
|
20
|
+
* seal(): void,
|
|
21
|
+
* at(x: number, z: number, limit: number): number,
|
|
22
|
+
* blocked(x: number, feet: number, z: number, toX: number, toZ: number): boolean,
|
|
23
|
+
* }} `add` takes non-indexed triangle positions (nine numbers a face) from `start`; `seal` lets go of unused room once
|
|
24
|
+
* every face is in; `at` is the highest floor under (x, z) no higher than `limit`, or -Infinity; `blocked` says
|
|
25
|
+
* whether a step from (x, z) to (toX, toZ) with the feet at `feet` runs into a cliff facing it.
|
|
26
|
+
*/
|
|
27
|
+
export function createTriangleHeightField({
|
|
28
|
+
cell = 8,
|
|
29
|
+
firstFaces = 4096,
|
|
30
|
+
floorSlope = 0.17,
|
|
31
|
+
cliffSlope = 0.62,
|
|
32
|
+
reach = 0.31,
|
|
33
|
+
rays = [0.97, 0.97 + 0.68],
|
|
34
|
+
} = {}) {
|
|
35
|
+
const cells = new Map(),
|
|
36
|
+
cliffs = new Map(),
|
|
37
|
+
key = (x, z) => x * 65536 + z;
|
|
38
|
+
let faces = new Float32Array(firstFaces * FACE),
|
|
39
|
+
count = 0;
|
|
40
|
+
function store(map, k, face) {
|
|
41
|
+
let bucket = map.get(k);
|
|
42
|
+
if (!bucket) {
|
|
43
|
+
bucket = [];
|
|
44
|
+
map.set(k, bucket);
|
|
45
|
+
}
|
|
46
|
+
bucket.push(face);
|
|
47
|
+
}
|
|
48
|
+
function newFace(x, y, z, ux, uy, uz, vx, vy, vz, inv) {
|
|
49
|
+
if ((count + 1) * FACE > faces.length) {
|
|
50
|
+
const more = new Float32Array(faces.length * 2);
|
|
51
|
+
more.set(faces);
|
|
52
|
+
faces = more;
|
|
53
|
+
}
|
|
54
|
+
const o = count * FACE;
|
|
55
|
+
faces[o] = x;
|
|
56
|
+
faces[o + 1] = y;
|
|
57
|
+
faces[o + 2] = z;
|
|
58
|
+
faces[o + 3] = ux;
|
|
59
|
+
faces[o + 4] = uy;
|
|
60
|
+
faces[o + 5] = uz;
|
|
61
|
+
faces[o + 6] = vx;
|
|
62
|
+
faces[o + 7] = vy;
|
|
63
|
+
faces[o + 8] = vz;
|
|
64
|
+
faces[o + 9] = inv;
|
|
65
|
+
return count++;
|
|
66
|
+
}
|
|
67
|
+
return {
|
|
68
|
+
add(p, start = 0) {
|
|
69
|
+
for (let i = start; i < p.length; i += 9) {
|
|
70
|
+
const x = p[i],
|
|
71
|
+
y = p[i + 1],
|
|
72
|
+
z = p[i + 2];
|
|
73
|
+
const ux = p[i + 3] - x,
|
|
74
|
+
uy = p[i + 4] - y,
|
|
75
|
+
uz = p[i + 5] - z,
|
|
76
|
+
vx = p[i + 6] - x,
|
|
77
|
+
vy = p[i + 7] - y,
|
|
78
|
+
vz = p[i + 8] - z;
|
|
79
|
+
const area = uz * vx - ux * vz;
|
|
80
|
+
const normal = Math.hypot(uy * vz - uz * vy, area, ux * vy - uy * vx);
|
|
81
|
+
if (normal < 1e-5) continue;
|
|
82
|
+
const isFloor = area > normal * floorSlope,
|
|
83
|
+
isCliff = area < normal * cliffSlope;
|
|
84
|
+
if (!isFloor && !isCliff) continue;
|
|
85
|
+
const face = newFace(x, y, z, ux, uy, uz, vx, vy, vz, isFloor ? 1 / area : 0);
|
|
86
|
+
const bx = p[i + 3],
|
|
87
|
+
bz = p[i + 5],
|
|
88
|
+
cx = p[i + 6],
|
|
89
|
+
cz = p[i + 8];
|
|
90
|
+
const x0 = Math.floor(Math.min(x, bx, cx) / cell),
|
|
91
|
+
x1 = Math.floor(Math.max(x, bx, cx) / cell);
|
|
92
|
+
const z0 = Math.floor(Math.min(z, bz, cz) / cell),
|
|
93
|
+
z1 = Math.floor(Math.max(z, bz, cz) / cell);
|
|
94
|
+
for (let ix = x0; ix <= x1; ix++)
|
|
95
|
+
for (let iz = z0; iz <= z1; iz++) {
|
|
96
|
+
const k = key(ix, iz);
|
|
97
|
+
if (isFloor) store(cells, k, face);
|
|
98
|
+
if (isCliff) store(cliffs, k, face);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
seal() {
|
|
103
|
+
faces = faces.slice(0, count * FACE);
|
|
104
|
+
},
|
|
105
|
+
at(x, z, limit) {
|
|
106
|
+
const list = cells.get(key(Math.floor(x / cell), Math.floor(z / cell)));
|
|
107
|
+
let best = -Infinity;
|
|
108
|
+
if (!list) return best;
|
|
109
|
+
for (let i = 0; i < list.length; i++) {
|
|
110
|
+
const o = list[i] * FACE,
|
|
111
|
+
dx = x - faces[o],
|
|
112
|
+
dz = z - faces[o + 2],
|
|
113
|
+
ux = faces[o + 3],
|
|
114
|
+
uz = faces[o + 5],
|
|
115
|
+
vx = faces[o + 6],
|
|
116
|
+
vz = faces[o + 8],
|
|
117
|
+
inv = faces[o + 9];
|
|
118
|
+
const u = (dz * vx - dx * vz) * inv,
|
|
119
|
+
v = (uz * dx - ux * dz) * inv;
|
|
120
|
+
if (u < -1e-6 || v < -1e-6 || u + v > 1.000001) continue;
|
|
121
|
+
const y = faces[o + 1] + u * faces[o + 4] + v * faces[o + 7];
|
|
122
|
+
if (y > best && y <= limit) best = y;
|
|
123
|
+
}
|
|
124
|
+
return best;
|
|
125
|
+
},
|
|
126
|
+
blocked(x, feet, z, toX, toZ) {
|
|
127
|
+
const sx = toX - x,
|
|
128
|
+
sz = toZ - z,
|
|
129
|
+
length = Math.hypot(sx, sz);
|
|
130
|
+
if (length < 1e-5) return false;
|
|
131
|
+
const dx = sx * (1 + reach / length),
|
|
132
|
+
dz = sz * (1 + reach / length);
|
|
133
|
+
const x0 = Math.floor(Math.min(x, x + dx) / cell),
|
|
134
|
+
x1 = Math.floor(Math.max(x, x + dx) / cell);
|
|
135
|
+
const z0 = Math.floor(Math.min(z, z + dz) / cell),
|
|
136
|
+
z1 = Math.floor(Math.max(z, z + dz) / cell);
|
|
137
|
+
for (let ix = x0; ix <= x1; ix++)
|
|
138
|
+
for (let iz = z0; iz <= z1; iz++) {
|
|
139
|
+
const list = cliffs.get(key(ix, iz));
|
|
140
|
+
if (!list) continue;
|
|
141
|
+
for (let i = 0; i < list.length; i++) {
|
|
142
|
+
const o = list[i] * FACE,
|
|
143
|
+
ax = faces[o],
|
|
144
|
+
ay = faces[o + 1],
|
|
145
|
+
az = faces[o + 2],
|
|
146
|
+
ux = faces[o + 3],
|
|
147
|
+
uy = faces[o + 4],
|
|
148
|
+
uz = faces[o + 5],
|
|
149
|
+
vx = faces[o + 6],
|
|
150
|
+
vy = faces[o + 7],
|
|
151
|
+
vz = faces[o + 8];
|
|
152
|
+
// level rays at each height, culling back faces so a walker touching a wall can still step away from it
|
|
153
|
+
const hx = -dz * vy,
|
|
154
|
+
hy = dz * vx - dx * vz,
|
|
155
|
+
hz = dx * vy;
|
|
156
|
+
const det = ux * hx + uy * hy + uz * hz;
|
|
157
|
+
if (det <= 1e-6) continue;
|
|
158
|
+
const px = x - ax,
|
|
159
|
+
pz = z - az,
|
|
160
|
+
qy = pz * ux - px * uz;
|
|
161
|
+
for (let r = 0; r < rays.length; r++) {
|
|
162
|
+
const py = feet + rays[r] - ay,
|
|
163
|
+
u = (px * hx + py * hy + pz * hz) / det;
|
|
164
|
+
if (u < 0 || u > 1) continue;
|
|
165
|
+
const qx = py * uz - pz * uy,
|
|
166
|
+
qz = px * uy - py * ux;
|
|
167
|
+
const v = (dx * qx + dz * qz) / det;
|
|
168
|
+
if (v < 0 || u + v > 1) continue;
|
|
169
|
+
const t = (vx * qx + vy * qy + vz * qz) / det;
|
|
170
|
+
if (t > 0 && t <= 1) return true;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return false;
|
|
175
|
+
},
|
|
176
|
+
};
|
|
177
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "roamwright",
|
|
3
|
-
"version": "0.61.
|
|
3
|
+
"version": "0.61.21",
|
|
4
4
|
"description": "A procedural worldbuilding engine built on top of Three.js. Generate landscapes with rivers and changing weather, animate crowds, and explore on foot or in flight.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"threejs",
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pooled additive ribbon trails that follow the outer edge of swinging blades and fade out over
|
|
3
|
+
* a brief lifetime without per-frame allocation.
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import * as THREE from 'three';
|
|
8
|
+
import { clamp } from '../math/scalar.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Creates a bounded pool of additive weapon-swing ribbon trails attached to `scene`.
|
|
12
|
+
* @param {object} options
|
|
13
|
+
* @param {THREE.Object3D} options.scene Parent scene or group receiving trail meshes.
|
|
14
|
+
* @param {number} [options.capacity] Maximum simultaneous trails (default `6`).
|
|
15
|
+
* @param {number} [options.segments] Number of cross-section rings per trail (default `12`).
|
|
16
|
+
* @param {number} [options.duration] Trail fade lifetime in seconds (default `0.22`).
|
|
17
|
+
* @param {number} [options.glint] Leading-edge additive brightness (default `0.3`).
|
|
18
|
+
* @param {number} [options.layer] Render layer assigned to trail meshes (default `1`).
|
|
19
|
+
* @param {number} [options.renderOrder] Transparent draw order (default `13`).
|
|
20
|
+
* @param {[number, number, number]} [options.color] RGB tint of the outer blade edge (default `[0.85, 0.92, 1.0]`).
|
|
21
|
+
* @returns {{ acquire: () => object | null, push: (trail: object, base: THREE.Vector3, tip: THREE.Vector3) => void, update: (dt: number) => void, clear: () => void, dispose: () => void, trails: object[] }}
|
|
22
|
+
*/
|
|
23
|
+
export function createBladeTrailPool({
|
|
24
|
+
scene,
|
|
25
|
+
capacity = 6,
|
|
26
|
+
segments = 12,
|
|
27
|
+
duration = 0.22,
|
|
28
|
+
glint = 0.3,
|
|
29
|
+
layer = 1,
|
|
30
|
+
renderOrder = 13,
|
|
31
|
+
color = [0.85, 0.92, 1.0],
|
|
32
|
+
} = {}) {
|
|
33
|
+
const trails = [];
|
|
34
|
+
const [cr, cg, cb] = color;
|
|
35
|
+
|
|
36
|
+
function acquire() {
|
|
37
|
+
for (let i = 0; i < trails.length; i++) if (trails[i].life <= 0) return trails[i];
|
|
38
|
+
if (trails.length >= capacity) return null;
|
|
39
|
+
const geometry = new THREE.BufferGeometry(),
|
|
40
|
+
pos = new Float32Array(segments * 6),
|
|
41
|
+
col = new Float32Array(segments * 6),
|
|
42
|
+
idx = [];
|
|
43
|
+
for (let i = 0; i < segments - 1; i++) idx.push(i * 2, i * 2 + 1, i * 2 + 2, i * 2 + 1, i * 2 + 3, i * 2 + 2);
|
|
44
|
+
geometry.setAttribute('position', new THREE.BufferAttribute(pos, 3));
|
|
45
|
+
geometry.setAttribute('color', new THREE.BufferAttribute(col, 3));
|
|
46
|
+
geometry.setIndex(idx);
|
|
47
|
+
const mesh = new THREE.Mesh(
|
|
48
|
+
geometry,
|
|
49
|
+
new THREE.MeshBasicMaterial({
|
|
50
|
+
vertexColors: true,
|
|
51
|
+
transparent: true,
|
|
52
|
+
blending: THREE.AdditiveBlending,
|
|
53
|
+
depthWrite: false,
|
|
54
|
+
side: THREE.DoubleSide,
|
|
55
|
+
fog: false,
|
|
56
|
+
}),
|
|
57
|
+
);
|
|
58
|
+
mesh.frustumCulled = false;
|
|
59
|
+
mesh.renderOrder = renderOrder;
|
|
60
|
+
if (layer != null) mesh.layers.set(layer);
|
|
61
|
+
mesh.visible = false;
|
|
62
|
+
scene?.add(mesh);
|
|
63
|
+
const trail = { mesh, pos, col, N: segments, n: 0, life: 0 };
|
|
64
|
+
trails.push(trail);
|
|
65
|
+
return trail;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function push(trail, base, tip) {
|
|
69
|
+
const points = trail.pos,
|
|
70
|
+
N = trail.N;
|
|
71
|
+
points.copyWithin(6, 0, (N - 1) * 6);
|
|
72
|
+
points[0] = base.x;
|
|
73
|
+
points[1] = base.y;
|
|
74
|
+
points[2] = base.z;
|
|
75
|
+
points[3] = tip.x;
|
|
76
|
+
points[4] = tip.y;
|
|
77
|
+
points[5] = tip.z;
|
|
78
|
+
if (trail.n === 0) for (let i = 1; i < N; i++) points.copyWithin(i * 6, 0, 6);
|
|
79
|
+
trail.n = Math.min(N, trail.n + 1);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function paint(trail) {
|
|
83
|
+
const colours = trail.col,
|
|
84
|
+
N = trail.N,
|
|
85
|
+
k = clamp(trail.life / duration, 0, 1);
|
|
86
|
+
for (let i = 0; i < N; i++) {
|
|
87
|
+
const f = 1 - i / (N - 1),
|
|
88
|
+
v = f * f * f * k * glint * (i < trail.n ? 1 : 0);
|
|
89
|
+
colours[i * 6] = 0;
|
|
90
|
+
colours[i * 6 + 1] = 0;
|
|
91
|
+
colours[i * 6 + 2] = 0;
|
|
92
|
+
colours[i * 6 + 3] = cr * v;
|
|
93
|
+
colours[i * 6 + 4] = cg * v;
|
|
94
|
+
colours[i * 6 + 5] = cb * v;
|
|
95
|
+
}
|
|
96
|
+
trail.mesh.geometry.attributes.position.needsUpdate = true;
|
|
97
|
+
trail.mesh.geometry.attributes.color.needsUpdate = true;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function update(dt) {
|
|
101
|
+
for (let i = 0; i < trails.length; i++) {
|
|
102
|
+
const trail = trails[i];
|
|
103
|
+
if (trail.life > 0) {
|
|
104
|
+
trail.life -= dt;
|
|
105
|
+
if (trail.life <= 0) trail.mesh.visible = false;
|
|
106
|
+
else paint(trail);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function clear() {
|
|
112
|
+
for (let i = 0; i < trails.length; i++) {
|
|
113
|
+
trails[i].life = 0;
|
|
114
|
+
trails[i].mesh.visible = false;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function dispose() {
|
|
119
|
+
for (let i = 0; i < trails.length; i++) {
|
|
120
|
+
trails[i].mesh.removeFromParent();
|
|
121
|
+
trails[i].mesh.geometry.dispose();
|
|
122
|
+
trails[i].mesh.material.dispose();
|
|
123
|
+
}
|
|
124
|
+
trails.length = 0;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return { acquire, push, update, clear, dispose, trails };
|
|
128
|
+
}
|