Files
NODEDC_MISSION_CORE/apps/control-station/test/gaussianLod.test.mjs
T

34 lines
2.1 KiB
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import {build} from 'esbuild';
import {Camera,GraphNode,PROJECTION_ORTHOGRAPHIC,ASPECT_MANUAL,Mat4} from 'playcanvas';
import {GSplatOctreeInstance} from '../node_modules/playcanvas/build/playcanvas/src/scene/gsplat-unified/gsplat-octree-instance.js';
const result=await build({entryPoints:[new URL('../src/core/simulation/gaussianQuality.ts',import.meta.url).pathname],bundle:true,write:false,platform:'node',format:'esm'});
const {orthographicLodFov,QUALITY_PROFILES}=await import('data:text/javascript;base64,'+Buffer.from(result.outputFiles[0].contents).toString('base64'));
// Exercise the installed engine LOD evaluator, rather than a copy of its distance formula.
function lod(halfSpan,depth,compensated=true){
const camera=new GraphNode();camera.setPosition(0,0,depth);
camera.camera=new Camera();camera.camera.projection=PROJECTION_ORTHOGRAPHIC;
camera.camera.aspectRatioMode=ASPECT_MANUAL;camera.camera.aspectRatio=1.5;camera.camera.orthoHeight=halfSpan;
camera.camera.fov=compensated?orthographicLodFov(halfSpan,depth):60;
const instance=Object.create(GSplatOctreeInstance.prototype);
Object.assign(instance,{placement:{node:{getWorldTransform:()=>new Mat4()}},octree:{nodes:[{}],nodeBoundsMinMax:new Float32Array([-1,-1,0,1,1,0])},nodeInfos:[{}]});
const p=QUALITY_PROFILES.maximum;
instance.evaluateNodeLods(camera,6,p.lodBaseDistance,p.lodMultiplier,p.lodRangeMin,p.lodRangeMax,{lodBehindPenalty:1},1,false);
return instance.nodeInfos[0].optimalLod;
}
test('orthographic zoom refines actual streamed LOD while distant camera stays put',()=>{
assert.equal(lod(100,1000,false),5);
assert.equal(lod(2,1000,false),5); // Reproduction: zoom was ignored.
assert.ok(lod(100,1000)>lod(10,1000));
assert.equal(lod(2,1000),0);
});
test('same orthographic screen scale selects the same detail at different camera depths',()=>{
for(const span of [2,10,50,100])assert.equal(lod(span,50),lod(span,1000));
});
test('equivalent FOV preserves the perspective focal-plane scale',()=>{
for(const depth of [1,25,1000]){
assert.ok(Math.abs(orthographicLodFov(depth*Math.tan(Math.PI/6),depth)-60)<1e-10);
}
});