Spaces:
Running
Running
Always 3D, grey studio lighting with shadow, faster zoom (part 2)
Browse files136 unmodified lines137138139140141142143136 unmodified lines.viewer .thumb.checker { background: repeating-conic-gradient(#d9d9d9 0 25%, #f4f4f4 0 50%) 0 0 / 18px 18px; }.viewer-bar { display: flex; align-items: center; gap: 6px; padding: 6px; background: var(--raised); border-top: 1px solid var(--line); flex-wrap: wrap; }.viewer-bar .opt { height: 26px; font-size: 12px; }.viewer-bar .hint { margin-left: auto; font-size: 11.5px; color: var(--faint); }.viewer3d { position: relative; }.viewer3d-stage { position: relative; aspect-ratio: 4 / 3; touch-action: none; }.viewer3d-stage canvas { position: absolute; inset: 0; width: 100% !important; height: 100% !important; display: block; }136 unmodified lines137138139140141142143136 unmodified lines.viewer .thumb.checker { background: repeating-conic-gradient(#d9d9d9 0 25%, #f4f4f4 0 50%) 0 0 / 18px 18px; }.viewer-bar { display: flex; align-items: center; gap: 6px; padding: 6px; background: var(--raised); border-top: 1px solid var(--line); flex-wrap: wrap; }.viewer-bar .opt { height: 26px; font-size: 12px; }.viewer-bar .hint { font-size: 11.5px; color: var(--muted); }.viewer3d { position: relative; }.viewer3d-stage { position: relative; aspect-ratio: 4 / 3; touch-action: none; }.viewer3d-stage canvas { position: absolute; inset: 0; width: 100% !important; height: 100% !important; display: block; }
6 unmodified lines789101112131410 unmodified lines25262728293031323334353637383940414243443 unmodified lines4849505152535455565758596061626364656649 unmodified lines11611711811912012123 unmodified lines1451461471481491501511521531546 unmodified linesimport { DRACOLoader } from "three/addons/loaders/DRACOLoader.js";import { RoomEnvironment } from "three/addons/environments/RoomEnvironment.js";const BG = { dark: 0x1a1a1a, light: 0xf0f0f0 };const GRID = { dark: [0x3a3734, 0x292725], light: [0xc9c2b8, 0xdedad3] };export function createViewer() {const root = document.createElement("div");10 unmodified linesrenderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));renderer.outputColorSpace = THREE.SRGBColorSpace;renderer.toneMapping = THREE.ACESFilmicToneMapping;renderer.toneMappingExposure = 1.2;stage.prepend(renderer.domElement);const scene = new THREE.Scene();const pmrem = new THREE.PMREMGenerator(renderer);scene.environment = pmrem.fromScene(new RoomEnvironment(), 0.04).texture;scene.add(new THREE.HemisphereLight(0xffffff, 0x8a8078, 0.6));const key = new THREE.DirectionalLight(0xffffff, 0.9);key.position.set(2, 4, 3);scene.add(key);const camera = new THREE.PerspectiveCamera(35, 1, 0.01, 100);const controls = new OrbitControls(camera, renderer.domElement);controls.enableDamping = true;controls.dampingFactor = 0.12;const loader = new GLTFLoader();const draco = new DRACOLoader();3 unmodified lineslet model = null, grid = null, rig = [], grabMeshes = [], drag = null, gen = 0, theme = "dark", sizeM = 1;let onJoint = () => {};function setTheme(t) {theme = t === "light" ? "light" : "dark";scene.background = new THREE.Color(BG[theme]);if (grid) placeGrid();}function placeGrid() {if (grid) { scene.remove(grid); grid.geometry.dispose(); grid.material.dispose(); }if (!model) { grid = null; return; }const box = new THREE.Box3().setFromObject(model);const span = Math.max(sizeM * 3, 0.5);grid = new THREE.GridHelper(span, 20, ...GRID[theme]);grid.position.set((box.min.x + box.max.x) / 2, box.min.y - 0.0005, (box.min.z + box.max.z) / 2);scene.add(grid);}function resize() {49 unmodified linesmodel.add(inner);scene.add(model);model.updateMatrixWorld(true);const byName = {};gltf.scene.traverse((n) => { if (n.name && !(clean(n.name) in byName)) byName[clean(n.name)] = n; });23 unmodified linesconst box = new THREE.Box3().setFromObject(model);const c = box.getCenter(new THREE.Vector3());const size = Math.max(box.getSize(new THREE.Vector3()).length(), 0.02);camera.near = size / 200; camera.far = size * 60;camera.position.set(c.x + size * 0.85, c.y + size * 0.55, c.z + size * 1.05);controls.target.copy(c);controls.minDistance = size * 0.2; controls.maxDistance = size * 8;camera.updateProjectionMatrix();placeGrid();status.hidden = true;6 unmodified lines78910111213141516171819202122232425262728293010 unmodified lines414243444546474849505152535455565758596061626364656667686970717273747576773 unmodified lines8182838485868788899091929394959697989910010110210310410510610710810911011111211311449 unmodified lines16416516616716816917023 unmodified lines1941951961971981992002012022036 unmodified linesimport { 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");c.width = 2; c.height = 256;const g = c.getContext("2d");const grad = g.createLinearGradient(0, 0, 0, 256);grad.addColorStop(0, STUDIO.top);grad.addColorStop(0.62, "#5b5e63");grad.addColorStop(1, STUDIO.horizon);g.fillStyle = grad;g.fillRect(0, 0, 2, 256);const tex = new THREE.CanvasTexture(c);tex.colorSpace = THREE.SRGBColorSpace;return tex;}export function createViewer() {const root = document.createElement("div");10 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);const scene = new THREE.Scene();scene.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;key.shadow.bias = -0.0004;scene.add(key, key.target);const floor = new THREE.Mesh(new THREE.PlaneGeometry(1, 1),new THREE.MeshStandardMaterial({ color: STUDIO.floor, roughness: 1, metalness: 0 }));floor.rotation.x = -Math.PI / 2;floor.receiveShadow = true;floor.visible = false;scene.add(floor);const camera = new THREE.PerspectiveCamera(35, 1, 0.01, 100);const controls = new OrbitControls(camera, renderer.domElement);controls.enableDamping = true;controls.dampingFactor = 0.15;controls.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();3 unmodified lineslet model = null, grid = null, rig = [], grabMeshes = [], drag = null, gen = 0, theme = "dark", sizeM = 1;let onJoint = () => {};function setTheme(t) { theme = t === "light" ? "light" : "dark"; } // the studio is the same grey in both// Floor, grid, fog and the key light's shadow box, sized to the current model.function placeGrid() {if (grid) { scene.remove(grid); grid.geometry.dispose(); grid.material.dispose(); grid = null; }floor.visible = !!model;if (!model) return;const box = new THREE.Box3().setFromObject(model);const c = box.getCenter(new THREE.Vector3());const s = Math.max(sizeM, 0.05);const y = box.min.y - s * 0.002;floor.scale.set(s * 80, s * 80, 1);floor.position.set(c.x, y, c.z);const cell = Math.pow(10, Math.floor(Math.log10(s / 4))); // 1 cm / 10 cm / 1 m cellsconst span = cell * 400;grid = new THREE.GridHelper(span, 400, STUDIO.grid, STUDIO.grid);grid.material.transparent = true;grid.material.opacity = 0.45;grid.position.set(c.x, y + s * 0.0005, c.z);scene.add(grid);scene.fog.near = s * 2.5;scene.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;sc.updateProjectionMatrix();key.shadow.normalBias = s * 0.002;}function resize() {49 unmodified linesmodel.add(inner);scene.add(model);model.updateMatrixWorld(true);model.traverse((o) => { if (o.isMesh) o.castShadow = true; });const byName = {};gltf.scene.traverse((n) => { if (n.name && !(clean(n.name) in byName)) byName[clean(n.name)] = n; });23 unmodified linesconst box = new THREE.Box3().setFromObject(model);const c = box.getCenter(new THREE.Vector3());const size = Math.max(box.getSize(new THREE.Vector3()).length(), 0.02);camera.near = size / 400; camera.far = size * 80;camera.position.set(c.x + size * 0.85, c.y + size * 0.55, c.z + size * 1.05);controls.target.copy(c);controls.minDistance = size * 0.05; controls.maxDistance = size * 10;camera.updateProjectionMatrix();placeGrid();status.hidden = true;
style.css+1-1
viewer.js+69-20