56 lines
2.0 KiB
JavaScript
56 lines
2.0 KiB
JavaScript
import { describe, expect, it } from "bun:test";
|
|
import * as THREE from "three";
|
|
|
|
import {
|
|
createSurfaceRibbonGeometry,
|
|
createSurfaceRibbonMaterial,
|
|
getActiveRibbonMaterialCount,
|
|
updateAllRibbonResolutions,
|
|
} from "./surface-ribbon.js";
|
|
|
|
describe("surface-ribbon GLSL ES 1.00 geometry & material", () => {
|
|
it("builds extruded single and multi-polyline ribbon geometry with normalized arc progress", () => {
|
|
const single = createSurfaceRibbonGeometry([
|
|
new THREE.Vector3(100, 0, 0),
|
|
new THREE.Vector3(100, 1, 0),
|
|
new THREE.Vector3(100, 4, 0),
|
|
]);
|
|
expect(single.attributes.position.count).toBe(6);
|
|
expect(single.attributes.aSide.array).toEqual(new Float32Array([-1, 1, -1, 1, -1, 1]));
|
|
expect(single.attributes.aProgress.array[0]).toBeCloseTo(0);
|
|
expect(single.attributes.aProgress.array[2]).toBeCloseTo(0.25);
|
|
expect(single.attributes.aProgress.array[4]).toBeCloseTo(1);
|
|
expect(single.index.count).toBe(12);
|
|
single.dispose();
|
|
|
|
const multi = createSurfaceRibbonGeometry([
|
|
[new THREE.Vector3(10, 0, 0), new THREE.Vector3(12, 0, 0)],
|
|
[new THREE.Vector3(0, 10, 0), new THREE.Vector3(0, 13, 0)],
|
|
]);
|
|
expect(multi.attributes.position.count).toBe(8);
|
|
expect(multi.index.count).toBe(12);
|
|
multi.dispose();
|
|
});
|
|
|
|
it("tracks active ribbon materials across resolution updates and cleans up on dispose", () => {
|
|
const before = getActiveRibbonMaterialCount();
|
|
const mat = createSurfaceRibbonMaterial({
|
|
color: 0x38bdf8,
|
|
halfWidthPx: 5.5,
|
|
pulseSpeed: 0.8,
|
|
tailFade: 1.0,
|
|
});
|
|
expect(mat.transparent).toBe(true);
|
|
expect(mat.depthWrite).toBe(false);
|
|
expect(mat.vertexShader).toContain("max(abs(clip.w), 0.001)");
|
|
expect(getActiveRibbonMaterialCount()).toBe(before + 1);
|
|
|
|
updateAllRibbonResolutions(1920, 1080);
|
|
expect(mat.uniforms.uResolution.value.x).toBe(1920);
|
|
expect(mat.uniforms.uResolution.value.y).toBe(1080);
|
|
|
|
mat.dispose();
|
|
expect(getActiveRibbonMaterialCount()).toBe(before);
|
|
});
|
|
});
|