Spaces:
Running
Running
Even studio lighting from all sides, full vertical orbit, grey floor (part 2)
Browse files4 unmodified lines5678910111213141510 unmodified lines2627282930319 unmodified lines414243444546472 unmodified lines50515253545556575812 unmodified lines7172737475767726 unmodified lines1041051061071081094 unmodified linesimport { OrbitControls } from "three/addons/controls/OrbitControls.js";import { GLTFLoader } from "three/addons/loaders/GLTFLoader.js";import { DRACOLoader } from "three/addons/loaders/DRACOLoader.js";import { RoomEnvironment } from "three/addons/environments/RoomEnvironment.js";// Neutral grey studio (both themes): dark-to-light grey sky, grey floor with a faint grid// fading into the horizon, one shadow-casting key light plus soft fill.const STUDIO = { top: "#2b2d31", horizon: "#777a7f", floor: 0x7b7e83, grid: 0x5f6267 };function skyTexture() {const c = document.createElement("canvas");10 unmodified linesreturn tex;}export function createViewer() {const root = document.createElement("div");root.className = "viewer3d";9 unmodified linesrenderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));renderer.outputColorSpace = THREE.SRGBColorSpace;renderer.toneMapping = THREE.ACESFilmicToneMapping;renderer.toneMappingExposure = 1.05;renderer.shadowMap.enabled = true;renderer.shadowMap.type = THREE.PCFSoftShadowMap;stage.prepend(renderer.domElement);2 unmodified linesscene.background = skyTexture();scene.fog = new THREE.Fog(STUDIO.horizon, 10, 50);const pmrem = new THREE.PMREMGenerator(renderer);scene.environment = pmrem.fromScene(new RoomEnvironment(), 0.04).texture;scene.add(new THREE.HemisphereLight(0xffffff, 0x55585d, 0.75));const key = new THREE.DirectionalLight(0xffffff, 1.7);key.castShadow = true;key.shadow.mapSize.set(2048, 2048);key.shadow.radius = 5;12 unmodified linescontrols.zoomSpeed = 3; // ~14% per wheel step (three's default is 5%)controls.zoomToCursor = true;controls.screenSpacePanning = true;controls.maxPolarAngle = Math.PI * 0.495; // stay above the floorconst loader = new GLTFLoader();const draco = new DRACOLoader();26 unmodified linesscene.fog.far = s * 12;key.position.set(c.x - s * 1.3, c.y + s * 1.9, c.z + s * 0.6); // from the left, so the shadow falls to the rightkey.target.position.copy(c);const sc = key.shadow.camera;sc.left = sc.bottom = -s * 1.5; sc.right = sc.top = s * 1.5;sc.near = s * 0.1; sc.far = s * 6;4 unmodified lines56789101112131410 unmodified lines2526272829303132333435363738394041424344454647484950515253545556579 unmodified lines676869707172732 unmodified lines76777879808182838485868712 unmodified lines10010110210310410526 unmodified lines1321331341351361371381391401414 unmodified linesimport { OrbitControls } from "three/addons/controls/OrbitControls.js";import { GLTFLoader } from "three/addons/loaders/GLTFLoader.js";import { DRACOLoader } from "three/addons/loaders/DRACOLoader.js";// Neutral grey studio (both themes): dark-to-light grey sky, grey floor with a faint grid// fading into the horizon, one shadow-casting key light plus soft fill.const STUDIO = { top: "#2b2d31", horizon: "#74777c", floor: 0x4f5257, grid: 0x3f4247 };function skyTexture() {const c = document.createElement("canvas");10 unmodified linesreturn tex;}// Reflections: an even grey room with soft light panels on every side, so metal and// glossy parts stay lit from any viewing angle (the stock room light is one-sided).function studioEnvironment(pmrem) {const env = new THREE.Scene();env.add(new THREE.Mesh(new THREE.BoxGeometry(10, 10, 10),new THREE.MeshBasicMaterial({ color: 0x9a9da2, side: THREE.BackSide })));const panel = (w, h, pos, power) => {const m = new THREE.Mesh(new THREE.PlaneGeometry(w, h),new THREE.MeshBasicMaterial({ color: new THREE.Color(1, 1, 1).multiplyScalar(power), side: THREE.DoubleSide }));m.position.set(...pos);m.lookAt(0, 0, 0);env.add(m);};panel(7, 7, [0, 4.8, 0], 2.6); // overhead softboxpanel(5, 5, [-4.8, 1.5, 1], 2.2); // left (key side)panel(5, 5, [4.8, 1.5, -1], 1.6); // rightpanel(6, 4, [0, 1.5, 4.8], 1.4); // frontpanel(6, 4, [0, 1.5, -4.8], 1.4); // backconst ground = new THREE.Mesh(new THREE.PlaneGeometry(10, 10), new THREE.MeshBasicMaterial({ color: 0x55585d }));ground.rotation.x = -Math.PI / 2;ground.position.y = -4.9;env.add(ground);const tex = pmrem.fromScene(env, 0.035).texture;env.traverse((o) => { if (o.isMesh) { o.geometry.dispose(); o.material.dispose(); } });return tex;}export function createViewer() {const root = document.createElement("div");root.className = "viewer3d";9 unmodified linesrenderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));renderer.outputColorSpace = THREE.SRGBColorSpace;renderer.toneMapping = THREE.ACESFilmicToneMapping;renderer.toneMappingExposure = 1.0;renderer.shadowMap.enabled = true;renderer.shadowMap.type = THREE.PCFSoftShadowMap;stage.prepend(renderer.domElement);2 unmodified linesscene.background = skyTexture();scene.fog = new THREE.Fog(STUDIO.horizon, 10, 50);const pmrem = new THREE.PMREMGenerator(renderer);scene.environment = studioEnvironment(pmrem);scene.add(new THREE.HemisphereLight(0xffffff, 0x6a6d72, 0.8));const fill = new THREE.DirectionalLight(0xffffff, 0.7); // opposite the key, no shadowconst rim = new THREE.DirectionalLight(0xffffff, 0.6); // from behind, lights the backscene.add(fill, fill.target, rim, rim.target);const key = new THREE.DirectionalLight(0xffffff, 1.5);key.castShadow = true;key.shadow.mapSize.set(2048, 2048);key.shadow.radius = 5;12 unmodified linescontrols.zoomSpeed = 3; // ~14% per wheel step (three's default is 5%)controls.zoomToCursor = true;controls.screenSpacePanning = true;const loader = new GLTFLoader();const draco = new DRACOLoader();26 unmodified linesscene.fog.far = s * 12;key.position.set(c.x - s * 1.3, c.y + s * 1.9, c.z + s * 0.6); // from the left, so the shadow falls to the rightkey.target.position.copy(c);fill.position.set(c.x + s * 1.5, c.y + s * 0.8, c.z + s * 0.4);rim.position.set(c.x + s * 0.3, c.y + s * 1.2, c.z - s * 1.6);fill.target.position.copy(c);rim.target.position.copy(c);const sc = key.shadow.camera;sc.left = sc.bottom = -s * 1.5; sc.right = sc.top = s * 1.5;sc.near = s * 0.1; sc.far = s * 6;
viewer.js+39-7