fix(simulation): isolate semantics and correct clipping and orthographic LOD
This commit is contained in:
@@ -6,6 +6,7 @@ import {PerspectiveCamera,Vector3} from 'three';
|
||||
import {Camera,GraphNode,ASPECT_MANUAL} from 'playcanvas';
|
||||
const url=s=>`data:text/javascript;base64,${Buffer.from(s).toString('base64')}`;
|
||||
function moduleUrl(p){return url(ts.transpileModule(readFileSync(p,'utf8'),{compilerOptions:{module:ts.ModuleKind.ESNext}}).outputText.replace(/from "([^"]+)"/g,(_,n)=>`from "${n.startsWith('.')?moduleUrl(new URL(n+'.ts',p)):import.meta.resolve(n)}"`));}
|
||||
const quality=moduleUrl(new URL('../src/core/simulation/gaussianQuality.ts',import.meta.url));
|
||||
const projection=moduleUrl(new URL('../src/core/simulation/editorProjection.ts',import.meta.url));
|
||||
const coordinates=moduleUrl(new URL('../src/core/simulation/aiEditorCoordinates.ts',import.meta.url));
|
||||
const drag=moduleUrl(new URL('../src/core/simulation/waypointDrag.ts',import.meta.url));
|
||||
@@ -16,14 +17,14 @@ const ast=ts.createSourceFile('runtime.ts',source,ts.ScriptTarget.Latest,true);
|
||||
const cls=ast.statements.find(s=>ts.isClassDeclaration(s));
|
||||
const names=new Set(['syncCamera','project','projectSemantic','moveSemantic','semanticGizmo','semanticSegmentParameter']);
|
||||
const methods=cls.members.filter(m=>names.has(m.name?.getText(ast))).map(m=>m.getText(ast)).join('\n');
|
||||
const actual=`import {Vec3,PROJECTION_ORTHOGRAPHIC,PROJECTION_PERSPECTIVE} from "${import.meta.resolve('playcanvas')}";import {isOrthographic,screenSpan} from "${projection}";import {toEditor,toMission} from "${coordinates}";import {dragWaypoint} from "${drag}";export class Runtime {${methods}}`;
|
||||
const actual=`import {orthographicLodFov} from "${quality}";import {Vec3,PROJECTION_ORTHOGRAPHIC,PROJECTION_PERSPECTIVE} from "${import.meta.resolve('playcanvas')}";import {isOrthographic,screenSpan} from "${projection}";import {toEditor,toMission} from "${coordinates}";import {dragWaypoint} from "${drag}";export class Runtime {${methods}}`;
|
||||
const {Runtime}=await import(url(ts.transpileModule(actual,{compilerOptions:{module:ts.ModuleKind.ESNext,target:ts.ScriptTarget.ES2022}}).outputText));
|
||||
function fixture(mode){
|
||||
let c=new PerspectiveCamera(60,1.5,.05,3000);c.position.set(7,12,20);c.lookAt(0,0,0);c.updateMatrixWorld();
|
||||
c=switchProjection(c,mode,1.5,c.position.length());
|
||||
const pc=new Camera(),node=new GraphNode();pc.node=node;pc.aspectRatioMode=ASPECT_MANUAL;pc.aspectRatio=1.5;pc.fov=60;pc.nearClip=.05;pc.farClip=3000;
|
||||
node.camera={get projection(){return pc.projection;},set projection(v){pc.projection=v;},get orthoHeight(){return pc.orthoHeight;},set orthoHeight(v){pc.orthoHeight=v;},worldToScreen:p=>pc.worldToScreen(p,900,600),screenToWorld:(x,y,z)=>pc.screenToWorld(x,y,z,900,600)};
|
||||
const r=new Runtime();Object.assign(r,{camera:node,controls:{camera:c},canvas:{clientWidth:900,clientHeight:600},clip:Infinity,clipFloor:-Infinity,preferences:{pivot:{pixels:100}}});r.syncCamera();return {r,c,pc};
|
||||
const r=new Runtime();Object.assign(r,{camera:node,controls:{camera:c,focusDepth:c.position.length()},canvas:{clientWidth:900,clientHeight:600},clip:Infinity,clipFloor:-Infinity,preferences:{pivot:{pixels:100}}});r.syncCamera();return {r,c,pc};
|
||||
}
|
||||
for(const mode of ['orthographic','perspective']){
|
||||
test(`${mode}: render and overlay projection agree; axis/plane dragging lands under cursor`,()=>{
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
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);
|
||||
}
|
||||
});
|
||||
@@ -2,7 +2,7 @@ import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import {build} from 'esbuild';
|
||||
const result=await build({entryPoints:[new URL('../src/core/simulation/sceneClip.ts',import.meta.url).pathname],bundle:true,write:false,platform:'node',format:'esm'});
|
||||
const {sceneClipBounds,sceneClipValue}=await import('data:text/javascript;base64,'+Buffer.from(result.outputFiles[0].contents).toString('base64'));
|
||||
const {sceneClipBounds,sceneClipValue,sceneClipRange,sceneClipLabel}=await import('data:text/javascript;base64,'+Buffer.from(result.outputFiles[0].contents).toString('base64'));
|
||||
test('Gaussian clipping covers visual and collision extents with at least a 500 m ceiling',()=>{
|
||||
assert.deepEqual(sceneClipBounds([-51.4623,210.4],[-30,77.72065000000002]),[-52,500]);
|
||||
assert.deepEqual(sceneClipBounds([-60.3,912.7],null),[-61,913]);
|
||||
@@ -16,3 +16,14 @@ test('native rounded maximum disables clipping and returning to a finite height
|
||||
const bounds=sceneClipBounds([-51.4623,210.4],oldBounds);
|
||||
assert.deepEqual([40,500,40,500].map(v=>sceneClipValue(v,bounds)),[40,Infinity,40,Infinity]);
|
||||
});
|
||||
|
||||
test('stored open ends and out-of-range legacy values agree with the slider',()=>{
|
||||
const bounds=[-33,500];
|
||||
assert.deepEqual(sceneClipRange([null,null],bounds),bounds);
|
||||
assert.deepEqual(sceneClipRange([-100,900],bounds),bounds);
|
||||
assert.deepEqual(sceneClipRange([-20,null],bounds),[-20,500]);
|
||||
assert.deepEqual(sceneClipRange([null,120],bounds),[-33,120]);
|
||||
assert.equal(sceneClipLabel(-33,bounds),'−∞');
|
||||
assert.equal(sceneClipLabel(500,bounds),'+∞');
|
||||
assert.equal(sceneClipLabel(-20,bounds),'-20.0 м');
|
||||
});
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import {before,after,test} from 'node:test';
|
||||
import {createServer} from './support/vite-server.mjs';
|
||||
let server,Runtime;
|
||||
before(async()=>{
|
||||
server=await createServer({appType:'custom',logLevel:'silent',server:{middlewareMode:true}});
|
||||
({AiEditorRuntime:Runtime}=await server.ssrLoadModule('/src/components/simulation/AiEditorRuntime.ts'));
|
||||
});
|
||||
after(async()=>{await server?.close();});
|
||||
|
||||
function runtime(){
|
||||
const value=Object.create(Runtime.prototype), parameters=new Map(), planes=[];
|
||||
Object.assign(value,{height:[-33,500],semanticMode:false,urbanVisible:false,
|
||||
surfacePicker:{invalidate(){}},controls:{invalidateSurface(){},restore(){},snapshot(){return {};}},
|
||||
syncCamera(){},scan:{gsplat:{setParameter:(k,v)=>parameters.set(k,v)}},
|
||||
urbanLayer:{setVisible(v){this.visible=v;},setClip:(...p)=>planes.push(p)},
|
||||
collisionLayer:{setClip:(...p)=>planes.push(p)},experienceLayer:{setClip:(...p)=>planes.push(p)}});
|
||||
return {value,parameters,planes};
|
||||
}
|
||||
test('semantic visibility cannot leak on mode exit or a late analysis callback',()=>{
|
||||
const {value}=runtime();
|
||||
value.showUrbanMap(true);assert.equal(value.urbanLayer.visible,false);
|
||||
value.setSemanticMode(true);assert.equal(value.urbanLayer.visible,true);
|
||||
value.setSemanticMode(false);assert.equal(value.urbanLayer.visible,false);
|
||||
value.showUrbanMap(true);assert.equal(value.urbanLayer.visible,false);
|
||||
value.setSemanticMode(true);assert.equal(value.urbanLayer.visible,true);
|
||||
value.showUrbanMap(false);assert.equal(value.urbanLayer.visible,false);
|
||||
value.setSemanticMode(false);value.setSemanticMode(true);
|
||||
assert.equal(value.urbanLayer.visible,false);
|
||||
});
|
||||
test('both full-range endpoints disable actual clipping and persist as open planes',()=>{
|
||||
const {value,parameters,planes}=runtime();
|
||||
value.setClip(200,-10);
|
||||
assert.equal(parameters.get('editorClipEnabled'),1);
|
||||
assert.equal(parameters.get('editorFloorEnabled'),1);
|
||||
assert.deepEqual(value.snapshotView().clip,[-10,200]);
|
||||
value.setClip(500,-33);
|
||||
assert.equal(parameters.get('editorClipEnabled'),0);
|
||||
assert.equal(parameters.get('editorFloorEnabled'),0);
|
||||
assert.deepEqual(value.snapshotView().clip,[null,null]);
|
||||
assert.deepEqual(planes.slice(-3),Array(3).fill([Infinity,-Infinity]));
|
||||
value.setClip(200,-33);
|
||||
assert.deepEqual(value.snapshotView().clip,[null,200]);
|
||||
value.setClip(500,-10);
|
||||
assert.deepEqual(value.snapshotView().clip,[-10,null]);
|
||||
});
|
||||
test('restoring old finite endpoint values cannot reopen invisible clipping planes',()=>{
|
||||
const {value,parameters}=runtime();
|
||||
value.restoreView({clip:[-33,500]});
|
||||
assert.deepEqual(value.snapshotView().clip,[null,null]);
|
||||
assert.equal(parameters.get('editorFloorEnabled'),0);
|
||||
value.restoreView({clip:[-200,900]});
|
||||
assert.deepEqual(value.snapshotView().clip,[null,null]);
|
||||
value.restoreView({clip:[-10,null]});
|
||||
assert.deepEqual(value.snapshotView().clip,[-10,null]);
|
||||
});
|
||||
@@ -494,7 +494,7 @@ test("vegetation realtime LAB uses one upstream Rerun clock and keeps archival r
|
||||
assert.match(rerunSource, /<RerunViewport/);
|
||||
assert.match(rerunSource, /ИСХ\. ТОЧКИ/);
|
||||
assert.match(rerunSource, /ЛОК\. SLAM/);
|
||||
assert.match(rerunSource, /resolveReplay\(resultId, value/);
|
||||
assert.match(rerunSource, /prepareLabReplay\(resultId, sessionId, resolveReplay/);
|
||||
assert.doesNotMatch(rerunSource, /canonical-overlay\.rrd/);
|
||||
assert.match(rerunSource, /unifiedPerception: splitView/);
|
||||
assert.match(rerunSource, /lockPerceptionCameraInteraction: false/);
|
||||
@@ -510,7 +510,7 @@ test("vegetation realtime LAB uses one upstream Rerun clock and keeps archival r
|
||||
assert.match(rerunSource, /<ToastStack items=\{toasts\}/);
|
||||
assert.match(rerunSource, /isRecordedPlaybackPresentationReady\(viewerStatus, playback\)/);
|
||||
assert.match(rerunSource, /data-presentation-state=\{presentationState\}/);
|
||||
assert.match(rerunSource, /<ActivityIndicator label="Загружаем синхронизированную запись"/);
|
||||
assert.match(rerunSource, /<LabReplayProgress progress=/);
|
||||
assert.match(rerunSource, /presentationReady && playback && playbackController/);
|
||||
assert.match(
|
||||
replayStyles,
|
||||
|
||||
Reference in New Issue
Block a user