mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
feat(globe): implement the engine on Navara
src/globe/navara builds the GlobeEngine on a Navara 0.2.1 ThreeView. The engine keeps the camera pose in src/geo values and pushes it to Navara's setCamera in degrees (Cesium's heading/pitch/roll convention, S4); whatever Navara moves itself (user input, its flyTo arc) is read back from the drawn camera each frame. Projection, picks against the ellipsoid and the view rectangle are geo math on that pose, with Navara's fov kept on Cesium's 60° across the wider side. - flights: Navara flyTo in ms with mapped easings, cancelFlight via an empty setCamera, user input cancels a flight as in Cesium - events: moveStart/moveEnd (500 ms still)/changed from the pose - render: forceUpdate and animation (render on demand, S5) - surface: S2 CPU ray over 3D-tile meshes, Navara terrain fallback - maps: OSM/Esri raster, Re:Earth or ion quantized-mesh terrain, Google 3D tiles with a browser key and Google's logo - input: DOM pointer events with ScreenSpaceEventHandler semantics - the three private Navara members used live in internals.js, pinned to 0.2.1 by a test index.js builds the product view (MSAA 4, native pixel ratio, preserved drawing buffer, effects=minimal) for a dynamic import. The contract QA script gains --engine=navara on a dev-only harness page: 46/46 contract and 4/4 Navara checks; Cesium stays 53/53.
This commit is contained in:
1 parent
b6ac0e9c99
commit
90c8e7763a
19 files changed
+3311
No files matched your search
@@ -0,0 +1,77 @@
|
||||
// The Navara globe for the app's experimental engine mode: builds the view
|
||||
// the product way (viewOptions.js) and the GlobeEngine on it. Load it with a
|
||||
// dynamic import() so Navara stays out of the Cesium-mode bundle.
|
||||
|
||||
import ThreeView from '@navaramap/three';
|
||||
import { DefaultPlugin } from '@navaramap/three-default-plugin';
|
||||
import { createNavaraEngine } from './createNavaraEngine.js';
|
||||
import { navaraHooks } from './internals.js';
|
||||
import {
|
||||
NAVARA_CONTEXT_ATTRIBUTES,
|
||||
navaraScenePlan,
|
||||
navaraViewOptions,
|
||||
} from './viewOptions.js';
|
||||
|
||||
// Navara 0.2.1 has no preserveDrawingBuffer option but takes a canvas whose
|
||||
// WebGL2 context is already created (S4); three then uses that context.
|
||||
function preservedCanvas(container) {
|
||||
const canvas = document.createElement('canvas');
|
||||
Object.assign(canvas.style, {
|
||||
width: '100%',
|
||||
height: '100%',
|
||||
display: 'block',
|
||||
});
|
||||
container.appendChild(canvas);
|
||||
if (!canvas.getContext('webgl2', NAVARA_CONTEXT_ATTRIBUTES)) {
|
||||
canvas.remove();
|
||||
throw new Error('WebGL2 is not available');
|
||||
}
|
||||
return canvas;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {{
|
||||
* container: HTMLElement,
|
||||
* effects?: 'minimal' | 'photoreal',
|
||||
* pixelRatio?: number,
|
||||
* }} options `pixelRatio` only for measurements; the product uses the device's.
|
||||
* @returns {Promise<{ view: object, engine: import('../contract.js').GlobeEngine, destroy: () => void }>}
|
||||
*/
|
||||
export async function createNavaraGlobe({ container, effects, pixelRatio }) {
|
||||
if (!container) throw new TypeError('createNavaraGlobe needs a container');
|
||||
const plan = navaraScenePlan(effects);
|
||||
const canvas = preservedCanvas(container);
|
||||
let view;
|
||||
try {
|
||||
view = new ThreeView(navaraViewOptions({ container, canvas, pixelRatio }));
|
||||
const plugin = new DefaultPlugin();
|
||||
view.addPlugin(plugin);
|
||||
await view.init();
|
||||
if (plan.pluginDefault) plugin.addDefaultPhotorealScene();
|
||||
else {
|
||||
for (const name of plan.meshes) view.addMesh({ [name]: {} });
|
||||
for (const name of plan.lights) view.addLight({ [name]: {} });
|
||||
for (const name of plan.effects) view.addEffect({ [name]: {} });
|
||||
}
|
||||
} catch (error) {
|
||||
view?.dispose();
|
||||
canvas.remove();
|
||||
throw error;
|
||||
}
|
||||
const engine = createNavaraEngine(view, {
|
||||
hooks: navaraHooks(view),
|
||||
container,
|
||||
});
|
||||
let destroyed = false;
|
||||
return {
|
||||
view,
|
||||
engine,
|
||||
destroy() {
|
||||
if (destroyed) return;
|
||||
destroyed = true;
|
||||
engine.destroy();
|
||||
view.dispose();
|
||||
canvas.remove();
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user