36 lines
1.5 KiB
JavaScript
36 lines
1.5 KiB
JavaScript
// Adapted from fan-ziqi/robot_viewer (Copyright 2025 Ziqi Fan), Apache-2.0.
|
|
// Modified for vibemake's normalized robot scale and existing stage.
|
|
// See vendor/robot-viewer/LICENSE and vendor/robot-viewer/NOTICE.
|
|
import * as THREE from 'three';
|
|
|
|
export function configureRobotViewerRenderer(renderer) {
|
|
renderer.toneMapping = THREE.NoToneMapping;
|
|
renderer.toneMappingExposure = 1;
|
|
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
|
|
}
|
|
|
|
export function createRobotViewerLights(scene) {
|
|
const ambient = new THREE.HemisphereLight(0xffffff, 0x444444, 0.5);
|
|
ambient.position.set(0, 1, 0);
|
|
const key = new THREE.DirectionalLight(0xffffff, Math.PI);
|
|
// Directional light keeps the original angle; distance fits our unit-sized robots.
|
|
const keyOffset = new THREE.Vector3(4, 10, 1).normalize().multiplyScalar(4);
|
|
key.position.copy(keyOffset);
|
|
key.castShadow = true;
|
|
key.shadow.mapSize.set(2048, 2048);
|
|
Object.assign(key.shadow.camera, { left: -1.4, right: 1.4, top: 1.4, bottom: -1.4, near: 0.1, far: 8 });
|
|
key.shadow.normalBias = 0.001;
|
|
const fill = new THREE.DirectionalLight(0xffffff, Math.PI * 0.3);
|
|
fill.position.set(-2, 2, -2);
|
|
scene.add(ambient, key, key.target, fill);
|
|
return { key, keyOffset };
|
|
}
|
|
|
|
export function createRobotViewerReflectionMap() {
|
|
// The reference viewer uses a uniform white cube for Phong reflections.
|
|
const face = new THREE.DataTexture(new Uint8Array([255, 255, 255, 255]), 1, 1);
|
|
const texture = new THREE.CubeTexture(Array(6).fill(face));
|
|
texture.needsUpdate = true;
|
|
return texture;
|
|
}
|