peih's picture
backup native-eiffel
5dd27d0 verified
Raw History Blame Contribute Delete
1.58 kB
// Headless PrototypeShell: everything is the real module except the renderer,
// which records the scene and camera instead of drawing them.
export * from '/assets/user-interface/PrototypeShell.js';
export function createRenderer(container, { pixelRatio = 1 } = {}) {
const renderer = {
domElement: globalThis.document.createElement('canvas'),
shadowMap: { enabled: false },
outputColorSpace: 'srgb',
toneMapping: 0,
toneMappingExposure: 1,
clearColor: '#000000',
pixelRatio,
width: globalThis.innerWidth,
height: globalThis.innerHeight,
lastScene: null,
lastCamera: null,
renders: 0,
setPixelRatio(value) { this.pixelRatio = value; },
setClearColor(color) { this.clearColor = color; },
setSize(width, height) { this.width = width; this.height = height; },
// Same matrix updates WebGLRenderer.render() performs before drawing.
render(scene, camera) {
if (scene.matrixWorldAutoUpdate === true) scene.updateMatrixWorld();
if (camera.parent === null && camera.matrixWorldAutoUpdate === true) camera.updateMatrixWorld();
this.lastScene = scene;
this.lastCamera = camera;
this.renders++;
},
};
globalThis.__headlessRenderer = renderer;
container?.appendChild?.(renderer.domElement);
return renderer;
}
export function installResize(renderer, camera) {
renderer.setSize(globalThis.innerWidth, globalThis.innerHeight);
if (camera.isPerspectiveCamera) {
camera.aspect = globalThis.innerWidth / globalThis.innerHeight;
camera.updateProjectionMatrix();
}
}