Datasets:
Download source/voxel-goblin.html from LocalLLaMA/optiq-3d-coder-assets: direct link, hf CLI and curl.
- Browser
- Download file 20.7 kB
-
https://huggingface.co/datasets/LocalLLaMA/optiq-3d-coder-assets/resolve/main/source/voxel-goblin.html
- Command line
-
hf download hf://datasets/LocalLLaMA/optiq-3d-coder-assets/source/voxel-goblin.html
-
curl -L -o voxel-goblin.html https://huggingface.co/datasets/LocalLLaMA/optiq-3d-coder-assets/resolve/main/source/voxel-goblin.html
20.7 kB
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Swamp Goblin — Voxel Enemy</title> | |
| <style> | |
| :root { | |
| color-scheme: dark; | |
| font-family: Inter, ui-sans-serif, system-ui, -apple-system, | |
| BlinkMacSystemFont, "Segoe UI", sans-serif; | |
| } | |
| * { | |
| box-sizing: border-box; | |
| } | |
| html, | |
| body { | |
| width: 100%; | |
| height: 100%; | |
| margin: 0; | |
| overflow: hidden; | |
| background: #789887; | |
| } | |
| #stage { | |
| position: fixed; | |
| inset: 0; | |
| } | |
| canvas { | |
| display: block; | |
| width: 100%; | |
| height: 100%; | |
| cursor: grab; | |
| touch-action: none; | |
| } | |
| canvas:active { | |
| cursor: grabbing; | |
| } | |
| .vignette { | |
| position: fixed; | |
| inset: 0; | |
| pointer-events: none; | |
| background: | |
| radial-gradient( | |
| ellipse at 50% 45%, | |
| transparent 45%, | |
| rgba(17, 28, 22, 0.22) 100% | |
| ); | |
| } | |
| .hud { | |
| position: fixed; | |
| top: 24px; | |
| left: 24px; | |
| z-index: 2; | |
| max-width: min(360px, calc(100vw - 48px)); | |
| padding: 16px 18px; | |
| color: #f2f4df; | |
| background: rgba(20, 31, 24, 0.76); | |
| border: 1px solid rgba(230, 235, 196, 0.2); | |
| border-radius: 14px; | |
| box-shadow: 0 14px 40px rgba(15, 26, 20, 0.22); | |
| backdrop-filter: blur(12px); | |
| pointer-events: none; | |
| } | |
| .eyebrow { | |
| margin: 0 0 6px; | |
| color: #b8ca91; | |
| font-size: 11px; | |
| font-weight: 800; | |
| letter-spacing: 0.18em; | |
| text-transform: uppercase; | |
| } | |
| h1 { | |
| margin: 0; | |
| font-size: clamp(23px, 4vw, 34px); | |
| line-height: 1; | |
| letter-spacing: -0.035em; | |
| } | |
| .subtitle { | |
| margin: 8px 0 0; | |
| color: rgba(242, 244, 223, 0.68); | |
| font-size: 13px; | |
| } | |
| .controls { | |
| position: fixed; | |
| right: 24px; | |
| bottom: 24px; | |
| z-index: 3; | |
| display: flex; | |
| align-items: center; | |
| gap: 12px; | |
| padding: 10px 12px; | |
| color: rgba(245, 247, 229, 0.82); | |
| background: rgba(20, 31, 24, 0.72); | |
| border: 1px solid rgba(230, 235, 196, 0.18); | |
| border-radius: 12px; | |
| box-shadow: 0 12px 35px rgba(15, 26, 20, 0.2); | |
| backdrop-filter: blur(10px); | |
| font-size: 12px; | |
| } | |
| #pause { | |
| appearance: none; | |
| padding: 8px 12px; | |
| color: #203025; | |
| background: #b8ca91; | |
| border: 0; | |
| border-radius: 8px; | |
| font: inherit; | |
| font-weight: 800; | |
| cursor: pointer; | |
| } | |
| #pause:hover { | |
| background: #d2dfb0; | |
| } | |
| #hint { | |
| position: fixed; | |
| left: 50%; | |
| bottom: 24px; | |
| z-index: 2; | |
| transform: translateX(-50%); | |
| padding: 8px 12px; | |
| color: rgba(245, 247, 229, 0.72); | |
| background: rgba(20, 31, 24, 0.55); | |
| border: 1px solid rgba(230, 235, 196, 0.12); | |
| border-radius: 999px; | |
| box-shadow: 0 8px 25px rgba(15, 26, 20, 0.15); | |
| backdrop-filter: blur(8px); | |
| font-size: 11px; | |
| white-space: nowrap; | |
| pointer-events: none; | |
| } | |
| @media (max-width: 640px) { | |
| .hud { | |
| top: 14px; | |
| left: 14px; | |
| padding: 12px 14px; | |
| } | |
| .subtitle { | |
| display: none; | |
| } | |
| .controls { | |
| right: 14px; | |
| bottom: 14px; | |
| } | |
| #hint { | |
| display: none; | |
| } | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <div id="stage"></div> | |
| <div class="vignette"></div> | |
| <section class="hud" aria-label="Scene information"> | |
| <p class="eyebrow">Voxel Enemy Archive</p> | |
| <h1>Swamp Goblin</h1> | |
| <p class="subtitle">Big-eared woodland raider with a leather vest and spiked club.</p> | |
| </section> | |
| <div id="hint">Drag to orbit · Scroll to zoom · Double-click to reset</div> | |
| <div class="controls"> | |
| <button id="pause" type="button">Pause turntable</button> | |
| <span>Auto-rotating</span> | |
| </div> | |
| <script type="module"> | |
| import * as THREE from | |
| "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js"; | |
| const stage = document.getElementById("stage"); | |
| const pauseButton = document.getElementById("pause"); | |
| // ------------------------------------------------------------------------- | |
| // Renderer, scene, camera | |
| // ------------------------------------------------------------------------- | |
| const renderer = new THREE.WebGLRenderer({ | |
| antialias: true, | |
| alpha: false, | |
| powerPreference: "high-performance" | |
| }); | |
| renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2)); | |
| renderer.setSize(window.innerWidth, window.innerHeight); | |
| renderer.outputColorSpace = THREE.SRGBColorSpace; | |
| renderer.toneMapping = THREE.ACESFilmicToneMapping; | |
| renderer.toneMappingExposure = 1.05; | |
| renderer.shadowMap.enabled = true; | |
| renderer.shadowMap.type = THREE.PCFSoftShadowMap; | |
| renderer.domElement.setAttribute( | |
| "aria-label", | |
| "Interactive 3D voxel swamp goblin enemy" | |
| ); | |
| stage.appendChild(renderer.domElement); | |
| const scene = new THREE.Scene(); | |
| scene.background = new THREE.Color(0x789887); | |
| scene.fog = new THREE.Fog(0x789887, 19, 42); | |
| const camera = new THREE.PerspectiveCamera( | |
| 38, | |
| window.innerWidth / window.innerHeight, | |
| 0.1, | |
| 100 | |
| ); | |
| const cameraTarget = new THREE.Vector3(0, 2.25, 0); | |
| const cameraView = { | |
| theta: 0.72, | |
| phi: 1.12, | |
| radius: 12.6 | |
| }; | |
| function updateCamera() { | |
| const sinPhi = Math.sin(cameraView.phi); | |
| camera.position.set( | |
| cameraTarget.x + | |
| cameraView.radius * sinPhi * Math.sin(cameraView.theta), | |
| cameraTarget.y + cameraView.radius * Math.cos(cameraView.phi), | |
| cameraTarget.z + | |
| cameraView.radius * sinPhi * Math.cos(cameraView.theta) | |
| ); | |
| camera.lookAt(cameraTarget); | |
| } | |
| updateCamera(); | |
| // ------------------------------------------------------------------------- | |
| // Lighting | |
| // ------------------------------------------------------------------------- | |
| const hemisphere = new THREE.HemisphereLight( | |
| 0xd8ead4, | |
| 0x344336, | |
| 1.75 | |
| ); | |
| scene.add(hemisphere); | |
| const keyLight = new THREE.DirectionalLight(0xffe3a6, 3.2); | |
| keyLight.position.set(6, 10, 8); | |
| keyLight.castShadow = true; | |
| keyLight.shadow.mapSize.set(2048, 2048); | |
| keyLight.shadow.camera.near = 1; | |
| keyLight.shadow.camera.far = 30; | |
| keyLight.shadow.camera.left = -7; | |
| keyLight.shadow.camera.right = 7; | |
| keyLight.shadow.camera.top = 8; | |
| keyLight.shadow.camera.bottom = -5; | |
| keyLight.shadow.bias = -0.0004; | |
| keyLight.shadow.normalBias = 0.025; | |
| keyLight.target.position.set(0, 2, 0); | |
| scene.add(keyLight, keyLight.target); | |
| const fillLight = new THREE.DirectionalLight(0x9fc9d0, 1.1); | |
| fillLight.position.set(-7, 5, 4); | |
| scene.add(fillLight); | |
| const rimLight = new THREE.DirectionalLight(0xffc96e, 0.8); | |
| rimLight.position.set(1, 4, -8); | |
| scene.add(rimLight); | |
| // ------------------------------------------------------------------------- | |
| // Plain ground plane | |
| // ------------------------------------------------------------------------- | |
| const ground = new THREE.Mesh( | |
| new THREE.PlaneGeometry(80, 80), | |
| new THREE.MeshStandardMaterial({ | |
| color: 0x53624c, | |
| roughness: 1, | |
| metalness: 0 | |
| }) | |
| ); | |
| ground.rotation.x = -Math.PI / 2; | |
| ground.position.y = -0.025; | |
| ground.receiveShadow = true; | |
| scene.add(ground); | |
| // ------------------------------------------------------------------------- | |
| // Voxel construction | |
| // | |
| // Every visible part of the goblin is assembled from axis-aligned boxes. | |
| // Instanced rendering keeps the block count manageable while preserving | |
| // clear gaps, shadows, and individual cubic geometry. | |
| // ------------------------------------------------------------------------- | |
| const model = new THREE.Group(); | |
| model.rotation.y = -0.1; | |
| const voxels = []; | |
| function addVoxel(x, y, z, sx, sy, sz, color) { | |
| voxels.push({ x, y, z, sx, sy, sz, color }); | |
| } | |
| const skin = 0x8b954e; | |
| const skinLight = 0x9da353; | |
| const skinDark = 0x747e3f; | |
| const earOuter = 0x68763d; | |
| const earInner = 0x9ca258; | |
| const leather = 0x4b2d20; | |
| const leatherDark = 0x2d1c17; | |
| const leatherTrim = 0x714633; | |
| const brass = 0xb88a3d; | |
| const clubWood = 0x764723; | |
| const clubLight = 0xb8773e; | |
| const clubDark = 0x57321b; | |
| const eyeBlack = 0x11150e; | |
| const eyeIris = 0xe0b847; | |
| const eyeGlint = 0xfff3b0; | |
| const hair = 0x263b2b; | |
| // Boots and feet. | |
| for (const side of [-1, 1]) { | |
| const x = side * 0.43; | |
| addVoxel(x, 0.13, 0.25, 0.48, 0.26, 0.58, clubDark); | |
| addVoxel(x, 0.29, 0.25, 0.42, 0.18, 0.54, leather); | |
| addVoxel(x, 0.40, 0.04, 0.23, 0.22, 0.50, skin); | |
| addVoxel(x, 0.40, 0.38, 0.23, 0.22, 0.20, skinLight); | |
| addVoxel(x - 0.10, 0.40, 0.42, 0.16, 0.16, 0.16, skin); | |
| } | |
| // Legs and hips. | |
| for (const side of [-1, 1]) { | |
| for (let y = 0.58; y <= 1.73; y += 0.23) { | |
| addVoxel(side * 0.36, y, 0.02, 0.22, 0.22, 0.24, skin); | |
| } | |
| addVoxel(side * 0.43, 1.78, 0, 0.34, 0.22, 0.38, skinDark); | |
| } | |
| // Torso: a 6 × 6 × 3 grid of visible skin blocks. | |
| for (let row = 0; row < 6; row++) { | |
| for (let column = 0; column < 6; column++) { | |
| for (let depth = 0; depth < 3; depth++) { | |
| addVoxel( | |
| -0.62 + column * 0.23, | |
| 1.78 + row * 0.23, | |
| -0.34 + depth * 0.34, | |
| 0.215, | |
| 0.215, | |
| 0.215, | |
| (row + column + depth) % 4 === 0 | |
| ? skinDark | |
| : skin | |
| ); | |
| } | |
| } | |
| } | |
| // Leather vest front and back. | |
| for (let row = 0; row < 5; row++) { | |
| for (let column = 0; column < 6; column++) { | |
| const x = -0.58 + column * 0.22; | |
| const y = 1.91 + row * 0.23; | |
| addVoxel( | |
| x, | |
| y, | |
| 0.43, | |
| 0.208, | |
| 0.218, | |
| 0.18, | |
| (row + column) % 3 === 0 ? leatherDark : leather | |
| ); | |
| addVoxel( | |
| x, | |
| y, | |
| -0.43, | |
| 0.208, | |
| 0.218, | |
| 0.18, | |
| (row + column + 1) % 3 === 0 ? leatherDark : leather | |
| ); | |
| } | |
| } | |
| // Shoulder armor. | |
| for (const side of [-1, 1]) { | |
| addVoxel(side * 0.64, 3.12, 0, 0.30, 0.25, 0.44, leather); | |
| addVoxel(side * 0.64, 3.29, 0, 0.25, 0.12, 0.38, leatherDark); | |
| } | |
| // Necklace / neck block. | |
| addVoxel(0, 3.22, 0, 0.28, 0.18, 0.28, skinDark); | |
| addVoxel(0, 3.31, 0, 0.12, 0.055, 0.13, brass); | |
| // Arms. | |
| for (const side of [-1, 1]) { | |
| const armX = [0.65, 0.77, 0.89, 1.01, 1.13, 1.25]; | |
| for (let i = 0; i < armX.length; i++) { | |
| addVoxel( | |
| side * armX[i], | |
| [2.90, 2.67, 2.44, 2.21, 1.98, 1.75][i], | |
| 0.02, | |
| 0.20, | |
| 0.20, | |
| 0.22, | |
| i === 0 ? skinLight : skin | |
| ); | |
| } | |
| // Arm straps. | |
| addVoxel(side * 0.68, 2.78, 0.12, 0.25, 0.32, 0.22, leather); | |
| addVoxel(side * 0.68, 2.60, 0.12, 0.24, 0.08, 0.23, leatherDark); | |
| } | |
| // Hands. | |
| for (const x of [-1.12, -1.35, 1.12, 1.35]) { | |
| addVoxel(x, 1.90, 0.25, 0.20, 0.20, 0.22, skinLight); | |
| addVoxel(x, 2.14, 0.25, 0.20, 0.20, 0.22, skin); | |
| addVoxel(x, 1.80, 0.37, 0.14, 0.14, 0.14, skin); | |
| } | |
| // Chest belt and pouch. | |
| for (let i = 0; i < 7; i++) { | |
| addVoxel( | |
| -0.60 + i * 0.20, | |
| 1.55, | |
| 0.01, | |
| 0.19, | |
| 0.10, | |
| 0.44, | |
| i % 2 === 0 ? leather : leatherDark | |
| ); | |
| } | |
| addVoxel(0, 1.55, 0.28, 0.18, 0.18, 0.12, brass); | |
| addVoxel(0.34, 1.38, 0.38, 0.32, 0.28, 0.34, leatherDark); | |
| addVoxel(0.34, 1.38, 0.58, 0.24, 0.18, 0.08, leatherTrim); | |
| // Chest studs. | |
| for (const x of [-0.45, 0, 0.45]) { | |
| addVoxel(x, 2.68, 0.60, 0.09, 0.09, 0.08, brass); | |
| } | |
| // Horizontal chest strap. | |
| for (let i = 0; i < 7; i++) { | |
| addVoxel( | |
| -0.60 + i * 0.20, | |
| 2.52, | |
| 0.57, | |
| 0.19, | |
| 0.08, | |
| 0.08, | |
| leatherDark | |
| ); | |
| } | |
| // ------------------------------------------------------------------------- | |
| // Head | |
| // ------------------------------------------------------------------------- | |
| for (let row = 0; row < 4; row++) { | |
| for (let column = 0; column < 5; column++) { | |
| for (let depth = 0; depth < 3; depth++) { | |
| addVoxel( | |
| -0.52 + column * 0.23, | |
| 3.62 + row * 0.23, | |
| -0.30 + depth * 0.33, | |
| 0.215, | |
| 0.215, | |
| 0.215, | |
| (row + column + depth) % 5 === 0 | |
| ? skinDark | |
| : skin | |
| ); | |
| } | |
| } | |
| } | |
| // Forehead blocks give the face a chunky, readable silhouette. | |
| for (const x of [-0.42, -0.21, 0, 0.21, 0.42]) { | |
| addVoxel(x, 4.13, 0.34, 0.19, 0.19, 0.10, skinLight); | |
| addVoxel(x, 4.35, 0.34, 0.19, 0.19, 0.10, skin); | |
| } | |
| // Eyes, irises, and tiny highlights. | |
| for (const x of [-0.23, 0.23]) { | |
| addVoxel(x, 4.08, 0.43, 0.15, 0.15, 0.08, skinDark); | |
| addVoxel(x, 4.08, 0.49, 0.10, 0.10, 0.05, eyeBlack); | |
| addVoxel(x, 4.08, 0.535, 0.055, 0.055, 0.035, eyeIris); | |
| addVoxel(x, 4.08, 0.567, 0.025, 0.025, 0.02, eyeGlint); | |
| } | |
| // Eyebrows. | |
| for (const x of [-0.25, 0.25]) { | |
| addVoxel(x, 4.25, 0.44, 0.34, 0.08, 0.10, skinDark); | |
| } | |
| // Nose and mouth. | |
| addVoxel(0, 4.12, 0.48, 0.15, 0.16, 0.15, skinDark); | |
| addVoxel(0, 3.99, 0.53, 0.13, 0.12, 0.12, skin); | |
| addVoxel(0, 3.57, 0.47, 0.23, 0.07, 0.08, clubDark); | |
| addVoxel(-0.12, 3.43, 0.52, 0.08, 0.17, 0.08, clubLight); | |
| addVoxel(0.12, 3.43, 0.52, 0.08, 0.17, 0.08, clubLight); | |
| // ------------------------------------------------------------------------- | |
| // Large pointed ears | |
| // ------------------------------------------------------------------------- | |
| for (const side of [-1, 1]) { | |
| // Ear bases. | |
| addVoxel(side * 0.78, 3.48, -0.02, 0.25, 0.25, 0.22, earOuter); | |
| // Four columns and five rows create a tall, pointed silhouette. | |
| for (let column = 0; column < 5; column++) { | |
| const x = side * (0.96 + column * 0.18); | |
| for (let row = 0; row < 5; row++) { | |
| const y = 3.55 + row * 0.23; | |
| addVoxel(x, y, -0.02, 0.17, 0.21, 0.18, earOuter); | |
| // Inner ear panel on the visible/front side. | |
| addVoxel( | |
| side * (1.03 + column * 0.18), | |
| y, | |
| 0.12, | |
| 0.12, | |
| 0.15, | |
| 0.08, | |
| earInner | |
| ); | |
| } | |
| } | |
| // Dark slit in the inner ear. | |
| addVoxel(side * 1.16, 4.18, 0.18, 0.045, 0.25, 0.035, eyeBlack); | |
| } | |
| // ------------------------------------------------------------------------- | |
| // Spiked wooden club in the right hand | |
| // ------------------------------------------------------------------------- | |
| // Handle. | |
| for (const x of [1.25, 1.48, 1.71]) { | |
| addVoxel(x, 2.12, 0.25, 0.22, 0.22, 0.24, clubWood); | |
| } | |
| // Club head. | |
| for (const x of [1.90, 2.13, 2.36]) { | |
| for (const y of [2.02, 2.25]) { | |
| addVoxel(x, y, 0.25, 0.22, 0.22, 0.24, clubLight); | |
| } | |
| } | |
| // Handle spikes. | |
| for (const x of [1.25, 1.48, 1.71]) { | |
| addVoxel(x, 2.12, 0.35, 0.08, 0.18, 0.18, clubLight); | |
| } | |
| // Head spikes pointing outward. | |
| for (const x of [2.56, 2.78, 2.99]) { | |
| addVoxel(x, 2.12, 0.25, 0.12, 0.22, 0.22, clubLight); | |
| } | |
| // Top and bottom spikes. | |
| for (const x of [2.13, 2.36]) { | |
| addVoxel(x, 1.90, 0.46, 0.16, 0.12, 0.12, clubLight); | |
| addVoxel(x, 2.34, 0.46, 0.16, 0.12, 0.12, clubLight); | |
| } | |
| // Front spike. | |
| addVoxel(2.13, 2.12, 0.55, 0.16, 0.16, 0.10, clubLight); | |
| // ------------------------------------------------------------------------- | |
| // Convert all cubes into one efficient instanced mesh | |
| // ------------------------------------------------------------------------- | |
| const voxelGeometry = new THREE.BoxGeometry(1, 1, 1); | |
| const voxelMaterial = new THREE.MeshStandardMaterial({ | |
| color: 0xffffff, | |
| roughness: 0.86, | |
| metalness: 0, | |
| flatShading: true | |
| }); | |
| const voxelMesh = new THREE.InstancedMesh( | |
| voxelGeometry, | |
| voxelMaterial, | |
| voxels.length | |
| ); | |
| const matrix = new THREE.Matrix4(); | |
| const position = new THREE.Vector3(); | |
| const quaternion = new THREE.Quaternion(); | |
| const scale = new THREE.Vector3(); | |
| const color = new THREE.Color(); | |
| voxels.forEach((voxel, index) => { | |
| position.set(voxel.x, voxel.y, voxel.z); | |
| scale.set(voxel.sx, voxel.sy, voxel.sz); | |
| matrix.compose(position, quaternion, scale); | |
| voxelMesh.setMatrixAt(index, matrix); | |
| voxelMesh.setColorAt(index, color.setHex(voxel.color)); | |
| }); | |
| voxelMesh.instanceMatrix.needsUpdate = true; | |
| if (voxelMesh.instanceColor) { | |
| voxelMesh.instanceColor.needsUpdate = true; | |
| } | |
| voxelMesh.castShadow = true; | |
| voxelMesh.receiveShadow = true; | |
| voxelMesh.frustumCulled = false; | |
| voxelMesh.computeBoundingSphere(); | |
| model.add(voxelMesh); | |
| scene.add(model); | |
| // ------------------------------------------------------------------------- | |
| // Custom mouse orbit controls — no external controls addon | |
| // ------------------------------------------------------------------------- | |
| let dragging = false; | |
| let pointerId = null; | |
| let lastX = 0; | |
| let lastY = 0; | |
| const canvas = renderer.domElement; | |
| function resetView() { | |
| cameraView.theta = 0.72; | |
| cameraView.phi = 1.12; | |
| cameraView.radius = 12.6; | |
| updateCamera(); | |
| } | |
| canvas.addEventListener("pointerdown", (event) => { | |
| if (event.button !== 0) return; | |
| dragging = true; | |
| pointerId = event.pointerId; | |
| lastX = event.clientX; | |
| lastY = event.clientY; | |
| canvas.setPointerCapture(pointerId); | |
| }); | |
| canvas.addEventListener("pointermove", (event) => { | |
| if (!dragging || event.pointerId !== pointerId) return; | |
| const deltaX = event.clientX - lastX; | |
| const deltaY = event.clientY - lastY; | |
| lastX = event.clientX; | |
| lastY = event.clientY; | |
| cameraView.theta -= deltaX * 0.006; | |
| cameraView.phi = THREE.MathUtils.clamp( | |
| cameraView.phi - deltaY * 0.005, | |
| 0.42, | |
| 1.47 | |
| ); | |
| updateCamera(); | |
| }); | |
| function endDrag(event) { | |
| if (event.pointerId !== pointerId) return; | |
| dragging = false; | |
| if (canvas.hasPointerCapture(pointerId)) { | |
| canvas.releasePointerCapture(pointerId); | |
| } | |
| pointerId = null; | |
| } | |
| canvas.addEventListener("pointerup", endDrag); | |
| canvas.addEventListener("pointercancel", endDrag); | |
| canvas.addEventListener( | |
| "wheel", | |
| (event) => { | |
| event.preventDefault(); | |
| cameraView.radius = THREE.MathUtils.clamp( | |
| cameraView.radius + event.deltaY * 0.008, | |
| 7.5, | |
| 20 | |
| ); | |
| updateCamera(); | |
| }, | |
| { passive: false } | |
| ); | |
| canvas.addEventListener("dblclick", resetView); | |
| canvas.addEventListener("contextmenu", (event) => event.preventDefault()); | |
| // ------------------------------------------------------------------------- | |
| // Turntable and UI | |
| // ------------------------------------------------------------------------- | |
| let paused = false; | |
| let lastTime = performance.now(); | |
| function togglePause() { | |
| paused = !paused; | |
| pauseButton.textContent = paused ? "Resume rotation" : "Pause turntable"; | |
| } | |
| pauseButton.addEventListener("click", togglePause); | |
| window.addEventListener("keydown", (event) => { | |
| if (event.code === "Space" && event.target === document.body) { | |
| event.preventDefault(); | |
| togglePause(); | |
| } | |
| }); | |
| window.addEventListener("resize", () => { | |
| camera.aspect = window.innerWidth / window.innerHeight; | |
| camera.updateProjectionMatrix(); | |
| renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2)); | |
| renderer.setSize(window.innerWidth, window.innerHeight); | |
| }); | |
| // ------------------------------------------------------------------------- | |
| // Animation | |
| // ------------------------------------------------------------------------- | |
| function animate(now) { | |
| requestAnimationFrame(animate); | |
| const delta = Math.min((now - lastTime) / 1000, 0.05); | |
| lastTime = now; | |
| if (!paused) { | |
| model.rotation.y += delta * 0.16; | |
| } | |
| renderer.render(scene, camera); | |
| } | |
| requestAnimationFrame(animate); | |
| </script> | |
| </body> | |
| </html> | |