SOURCE / PINNED RELEASE
Made of little things.
Poly Dogfight
- Release
- b8511ee374e3…
- Author-recorded commit
- 5579434b9d8b…
- License
- LICENSE
- Author’s source reference
- nostr://npub1ye5ptcxfyyxl5vjvdjar2ua3f0hynkjzpx552mu5snj3qmx5pzjscpknpr/wss%3A%2F%2Fgit.napplet.soy%2F/n-44f63e5422b
Archive hash verified: bcadd2430d8ea2bc…. The source-to-build association is the author’s claim; it has not been independently rebuilt.
import { BoxGeometry, InstancedMesh, Matrix4, MeshBasicMaterial, Quaternion, Vector3 } from 'three';
import type { Bullet } from '../sim/guns.ts';
const MAX_TRACERS = 512;
/** Every round in flight drawn as one glowing streak, in a single draw call. */
export function createTracers() {
const mesh = new InstancedMesh(
new BoxGeometry(0.12, 0.12, 4.5),
new MeshBasicMaterial({ color: 0xffd36b }),
MAX_TRACERS,
);
mesh.frustumCulled = false;
mesh.count = 0;
const matrix = new Matrix4();
const turn = new Quaternion();
const dir = new Vector3();
const zAxis = new Vector3(0, 0, 1);
const unit = new Vector3(1, 1, 1);
return {
mesh,
update(bullets: readonly Bullet[]) {
const count = Math.min(MAX_TRACERS, bullets.length);
for (let i = 0; i < count; i++) {
const bullet = bullets[i]!;
dir.copy(bullet.velocity).normalize();
turn.setFromUnitVectors(zAxis, dir);
matrix.compose(bullet.position, turn, unit);
mesh.setMatrixAt(i, matrix);
}
mesh.count = count;
mesh.instanceMatrix.needsUpdate = true;
},
};
}
