Build and revise procedural 3D assets with your coding agent. Local MCP server, CLI and TypeScript engine with rendered review, editable source and GLB export.
JavaScript 3d3d-assets3d-modelingagent-skillsagent-toolsai-agentsasset-pipelinecligame-assetsglbgltfmcpmcp-servermodel-context-protocolprocedural-generationprocedural-modelingtext-to-3dthreejstypescript
import { describe, expect, test } from 'bun:test';
import { smoothUnion, smoothUnionSpheres, sphereInside } from '../sdf';
describe('sdf helpers', () => {
test('public field helpers reject nonfinite inputs and invalid blend widths', () => {
expect(() => sphereInside([NaN, 0, 0], [0, 0, 0], 1)).toThrow();
expect(() => smoothUnion(Infinity, 0, 0.1)).toThrow();
expect(() => smoothUnion(0, NaN, 0.1)).toThrow();
expect(() => smoothUnionSpheres([0, 0, 0], [{ center: [0, 0, 0], radius: 1 }], 0)).toThrow();
});
test('sphereInside is positive at the center', () => {
expect(sphereInside([0, 0, 0], [0, 0, 0], 0.5)).toBe(0.5);
expect(sphereInside([0.5, 0, 0], [0, 0, 0], 0.5)).toBe(0);
});
test('smoothUnion blends between spheres', () => {
const p: [number, number, number] = [0, 0, 0];
const a = sphereInside(p, [-0.2, 0, 0], 0.4);
const b = sphereInside(p, [0.2, 0, 0], 0.4);
const blended = smoothUnion(a, b, 0.2);
expect(blended).toBeGreaterThan(Math.max(a, b) - 1e-6);
});
test('smoothUnionSpheres matches chained smoothUnion', () => {
const p: [number, number, number] = [0.1, 0.05, 0];
const spheres = [
{ center: [0, 0, 0] as [number, number, number], radius: 0.35 },
{ center: [0.25, 0.1, 0] as [number, number, number], radius: 0.25 },
];
const chained = smoothUnion(
sphereInside(p, spheres[0]!.center, spheres[0]!.radius),
sphereInside(p, spheres[1]!.center, spheres[1]!.radius),
0.15,
);
expect(smoothUnionSpheres(p, spheres, 0.15)).toBeCloseTo(chained, 6);
});
});