33 lines
1.4 KiB
TypeScript
33 lines
1.4 KiB
TypeScript
import assert from 'node:assert/strict';
|
|
import test from 'node:test';
|
|
import { BoxGeometry, Group, Mesh, MeshStandardMaterial, Vector3 } from 'three';
|
|
import { createSummitMarker } from '../src/scene/summitMarker.ts';
|
|
|
|
test('marker seats its foot on sloping bedrock without deforming the stone', () => {
|
|
const asset = new Group();
|
|
const mesh = new Mesh(new BoxGeometry(4, 4, 2), new MeshStandardMaterial());
|
|
mesh.position.y = 2;
|
|
asset.add(mesh);
|
|
const groundAt = (x: number, z: number) => 12 + .3*x - .2*z;
|
|
const rock = new MeshStandardMaterial();
|
|
const marker = createSummitMarker(asset, {x:0,z:0}, groundAt, rock);
|
|
marker.group.updateMatrixWorld(true);
|
|
const position = mesh.geometry.getAttribute('position');
|
|
const point = new Vector3();
|
|
let nearestContact = Infinity;
|
|
for (let i=0; i<position.count; i++) {
|
|
point.fromBufferAttribute(position,i).applyMatrix4(mesh.matrixWorld);
|
|
if (position.getY(i)<0) {
|
|
const burial = groundAt(point.x,point.z)-point.y;
|
|
assert.ok(burial > .05, `base must stay below terrain: ${burial}`);
|
|
assert.equal(position.getY(i),-2,'base geometry remains unchanged');
|
|
nearestContact = Math.min(nearestContact,burial);
|
|
} else {
|
|
assert.equal(position.getY(i),2,'upper geometry remains unchanged');
|
|
}
|
|
}
|
|
assert.ok(nearestContact < .3,'the stone is seated close to its lowest contact');
|
|
marker.dispose();
|
|
rock.dispose();
|
|
});
|