Datasets:
Download source/cannon.html from LocalLLaMA/optiq-3d-coder-assets: direct link, hf CLI and curl.
- Browser
- Download file 20.1 kB
-
https://huggingface.co/datasets/LocalLLaMA/optiq-3d-coder-assets/resolve/main/source/cannon.html
- Command line
-
hf download hf://datasets/LocalLLaMA/optiq-3d-coder-assets/source/cannon.html
-
curl -L -o cannon.html https://huggingface.co/datasets/LocalLLaMA/optiq-3d-coder-assets/resolve/main/source/cannon.html
20.1 kB
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Pirate Deck Cannon</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: #0d1114; | |
| } | |
| #app { | |
| position: fixed; | |
| inset: 0; | |
| } | |
| canvas { | |
| display: block; | |
| width: 100%; | |
| height: 100%; | |
| cursor: grab; | |
| touch-action: none; | |
| } | |
| canvas:active { | |
| cursor: grabbing; | |
| } | |
| .title-card { | |
| position: fixed; | |
| top: 24px; | |
| left: 26px; | |
| z-index: 2; | |
| max-width: min(390px, calc(100vw - 52px)); | |
| padding: 16px 18px; | |
| color: #f4e7c9; | |
| background: linear-gradient(145deg, rgba(24, 20, 15, 0.88), rgba(20, 17, 13, 0.72)); | |
| border: 1px solid rgba(225, 184, 111, 0.35); | |
| border-radius: 14px; | |
| box-shadow: 0 14px 40px rgba(0, 0, 0, 0.3); | |
| backdrop-filter: blur(12px); | |
| pointer-events: none; | |
| } | |
| .title-card h1 { | |
| margin: 0 0 5px; | |
| font-family: Georgia, "Times New Roman", serif; | |
| font-size: clamp(22px, 3vw, 32px); | |
| font-weight: 600; | |
| letter-spacing: 0.025em; | |
| } | |
| .title-card p { | |
| margin: 0; | |
| color: #bda887; | |
| font-size: 13px; | |
| line-height: 1.45; | |
| } | |
| .controls-hint { | |
| position: fixed; | |
| right: 22px; | |
| bottom: 20px; | |
| z-index: 2; | |
| padding: 9px 12px; | |
| color: #c4b291; | |
| background: rgba(12, 15, 17, 0.68); | |
| border: 1px solid rgba(255, 255, 255, 0.08); | |
| border-radius: 999px; | |
| font-size: 12px; | |
| letter-spacing: 0.02em; | |
| pointer-events: none; | |
| backdrop-filter: blur(8px); | |
| } | |
| @media (max-width: 600px) { | |
| .title-card { | |
| top: 14px; | |
| left: 14px; | |
| padding: 12px 14px; | |
| } | |
| .title-card p { | |
| display: none; | |
| } | |
| .controls-hint { | |
| right: 12px; | |
| bottom: 12px; | |
| } | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <div id="app"></div> | |
| <div class="title-card"> | |
| <h1>Pirate Deck Cannon</h1> | |
| <p>A turntable-ready cannon mounted on a wooden carriage, with a stacked load of cannonballs.</p> | |
| </div> | |
| <div class="controls-hint">Drag to orbit · Scroll to zoom · Double-click to reset</div> | |
| <script type="module"> | |
| import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js"; | |
| const app = document.getElementById("app"); | |
| const scene = new THREE.Scene(); | |
| scene.background = new THREE.Color(0x101518); | |
| scene.fog = new THREE.Fog(0x101518, 17, 42); | |
| const camera = new THREE.PerspectiveCamera( | |
| 38, | |
| window.innerWidth / window.innerHeight, | |
| 0.1, | |
| 100 | |
| ); | |
| const renderer = new THREE.WebGLRenderer({ | |
| antialias: true, | |
| 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.08; | |
| renderer.shadowMap.enabled = true; | |
| renderer.shadowMap.type = THREE.PCFSoftShadowMap; | |
| renderer.domElement.setAttribute("aria-label", "Interactive 3D pirate deck cannon"); | |
| app.appendChild(renderer.domElement); | |
| // Lighting | |
| scene.add(new THREE.HemisphereLight(0xb8c9d3, 0x3a2618, 1.65)); | |
| const keyLight = new THREE.DirectionalLight(0xffe0ad, 3.2); | |
| keyLight.position.set(5.5, 9, 6.5); | |
| keyLight.castShadow = true; | |
| keyLight.shadow.mapSize.set(2048, 2048); | |
| keyLight.shadow.camera.left = -7; | |
| keyLight.shadow.camera.right = 7; | |
| keyLight.shadow.camera.top = 7; | |
| keyLight.shadow.camera.bottom = -7; | |
| keyLight.shadow.camera.near = 1; | |
| keyLight.shadow.camera.far = 25; | |
| keyLight.shadow.bias = -0.00035; | |
| scene.add(keyLight); | |
| const rimLight = new THREE.DirectionalLight(0x769ab4, 1.35); | |
| rimLight.position.set(-6, 5, -5); | |
| scene.add(rimLight); | |
| const warmFill = new THREE.PointLight(0xd78b42, 22, 12, 2); | |
| warmFill.position.set(2.5, 3.5, 3.5); | |
| scene.add(warmFill); | |
| // Deterministic procedural wood texture. | |
| function createWoodTexture() { | |
| const canvas = document.createElement("canvas"); | |
| canvas.width = 512; | |
| canvas.height = 512; | |
| const ctx = canvas.getContext("2d"); | |
| ctx.fillStyle = "#704327"; | |
| ctx.fillRect(0, 0, 512, 512); | |
| let seed = 9137; | |
| const random = () => { | |
| seed = (seed * 16807) % 2147483647; | |
| return (seed - 1) / 2147483646; | |
| }; | |
| for (let y = -10; y < 530; y += 3) { | |
| const amplitude = 2 + random() * 8; | |
| const frequency = 0.012 + random() * 0.028; | |
| const phase = random() * Math.PI * 2; | |
| ctx.beginPath(); | |
| for (let x = 0; x <= 520; x += 8) { | |
| const waveY = | |
| y + | |
| Math.sin(x * frequency + phase) * amplitude + | |
| Math.sin(x * frequency * 0.43 + phase) * amplitude * 0.35; | |
| if (x === 0) ctx.moveTo(x, waveY); | |
| else ctx.lineTo(x, waveY); | |
| } | |
| ctx.strokeStyle = `rgba(35, 15, 7, ${0.08 + random() * 0.16})`; | |
| ctx.lineWidth = 0.5 + random() * 2.2; | |
| ctx.stroke(); | |
| } | |
| for (let i = 0; i < 18; i++) { | |
| const x = random() * 512; | |
| const y = random() * 512; | |
| const rx = 8 + random() * 25; | |
| const ry = 2 + random() * 7; | |
| ctx.beginPath(); | |
| ctx.ellipse(x, y, rx, ry, 0, 0, Math.PI * 2); | |
| ctx.strokeStyle = "rgba(35, 15, 7, 0.16)"; | |
| ctx.lineWidth = 1.2; | |
| ctx.stroke(); | |
| } | |
| const texture = new THREE.CanvasTexture(canvas); | |
| texture.colorSpace = THREE.SRGBColorSpace; | |
| texture.wrapS = THREE.RepeatWrapping; | |
| texture.wrapT = THREE.RepeatWrapping; | |
| texture.repeat.set(2, 2); | |
| texture.anisotropy = renderer.capabilities.getMaxAnisotropy(); | |
| return texture; | |
| } | |
| const woodTexture = createWoodTexture(); | |
| const materials = { | |
| wood: new THREE.MeshStandardMaterial({ | |
| map: woodTexture, | |
| color: 0xffffff, | |
| roughness: 0.82, | |
| metalness: 0.02 | |
| }), | |
| darkWood: new THREE.MeshStandardMaterial({ | |
| map: woodTexture, | |
| color: 0x8b5938, | |
| roughness: 0.9, | |
| metalness: 0.01 | |
| }), | |
| iron: new THREE.MeshStandardMaterial({ | |
| color: 0x252b2d, | |
| roughness: 0.48, | |
| metalness: 0.78 | |
| }), | |
| blackIron: new THREE.MeshStandardMaterial({ | |
| color: 0x101517, | |
| roughness: 0.58, | |
| metalness: 0.72 | |
| }), | |
| steel: new THREE.MeshStandardMaterial({ | |
| color: 0x8b9291, | |
| roughness: 0.35, | |
| metalness: 0.9 | |
| }), | |
| brass: new THREE.MeshStandardMaterial({ | |
| color: 0xb68a45, | |
| roughness: 0.38, | |
| metalness: 0.8 | |
| }), | |
| ball: new THREE.MeshStandardMaterial({ | |
| color: 0x8d918e, | |
| roughness: 0.42, | |
| metalness: 0.82 | |
| }), | |
| ballSeam: new THREE.MeshStandardMaterial({ | |
| color: 0x484d4c, | |
| roughness: 0.55, | |
| metalness: 0.68 | |
| }), | |
| ground: new THREE.MeshStandardMaterial({ | |
| color: 0x252c2d, | |
| roughness: 0.96, | |
| metalness: 0.02 | |
| }) | |
| }; | |
| const model = new THREE.Group(); | |
| model.name = "Pirate deck cannon assembly"; | |
| scene.add(model); | |
| const turntable = new THREE.Group(); | |
| turntable.name = "Rotating turntable"; | |
| model.add(turntable); | |
| function addMesh( | |
| geometry, | |
| material, | |
| parent, | |
| position = [0, 0, 0], | |
| rotation = [0, 0, 0], | |
| name = "Unnamed mesh" | |
| ) { | |
| const mesh = new THREE.Mesh(geometry, material); | |
| mesh.position.set(...position); | |
| mesh.rotation.set(...rotation); | |
| mesh.name = name; | |
| mesh.castShadow = true; | |
| mesh.receiveShadow = true; | |
| parent.add(mesh); | |
| return mesh; | |
| } | |
| // Turntable | |
| addMesh( | |
| new THREE.CylinderGeometry(2.08, 2.32, 0.24, 64), | |
| materials.darkWood, | |
| turntable, | |
| [0, 0.12, 0], | |
| [0, 0, 0], | |
| "Turntable pedestal" | |
| ); | |
| addMesh( | |
| new THREE.CylinderGeometry(2.28, 2.28, 0.16, 64), | |
| materials.wood, | |
| turntable, | |
| [0, 0.32, 0], | |
| [0, 0, 0], | |
| "Turntable deck" | |
| ); | |
| addMesh( | |
| new THREE.TorusGeometry(2.19, 0.035, 10, 80), | |
| materials.brass, | |
| turntable, | |
| [0, 0.415, 0], | |
| [Math.PI / 2, 0, 0], | |
| "Turntable brass rim" | |
| ); | |
| // Wooden carriage | |
| const carriage = new THREE.Group(); | |
| carriage.name = "Wooden carriage"; | |
| model.add(carriage); | |
| addMesh( | |
| new THREE.BoxGeometry(4.8, 0.28, 3.2), | |
| materials.wood, | |
| carriage, | |
| [0, 0.6, 0], | |
| [0, 0, 0], | |
| "Carriage deck" | |
| ); | |
| addMesh( | |
| new THREE.BoxGeometry(4.95, 0.13, 3.34), | |
| materials.darkWood, | |
| carriage, | |
| [0, 0.78, 0], | |
| [0, 0, 0], | |
| "Carriage top rail" | |
| ); | |
| for (const z of [-1.48, 1.48]) { | |
| addMesh( | |
| new THREE.BoxGeometry(4.85, 0.24, 0.18), | |
| materials.darkWood, | |
| carriage, | |
| [0, 0.84, z], | |
| [0, 0, 0], | |
| "Carriage side rail" | |
| ); | |
| } | |
| for (const x of [-1.72, 1.72]) { | |
| addMesh( | |
| new THREE.BoxGeometry(0.22, 0.25, 2.85), | |
| materials.darkWood, | |
| carriage, | |
| [x, 0.79, 0], | |
| [0, 0, 0], | |
| "Carriage cross brace" | |
| ); | |
| } | |
| for (const x of [-2.02, 2.02]) { | |
| addMesh( | |
| new THREE.BoxGeometry(0.2, 0.22, 2.9), | |
| materials.darkWood, | |
| carriage, | |
| [x, 0.78, 0], | |
| [0, 0, 0], | |
| "Carriage end brace" | |
| ); | |
| } | |
| // Deck bolts | |
| for (const x of [-1.9, -0.95, 0.1, 1.15, 2.1]) { | |
| for (const z of [-1.48, 1.48]) { | |
| addMesh( | |
| new THREE.CylinderGeometry(0.055, 0.055, 0.035, 12), | |
| materials.brass, | |
| carriage, | |
| [x, 0.865, z], | |
| [0, 0, 0], | |
| "Carriage bolt" | |
| ); | |
| } | |
| } | |
| // Four wooden carriage wheels | |
| function createWheel(x, z, facing) { | |
| const wheel = new THREE.Group(); | |
| wheel.name = "Carriage wheel"; | |
| wheel.position.set(x, 0.57, z); | |
| carriage.add(wheel); | |
| addMesh( | |
| new THREE.CylinderGeometry(0.55, 0.55, 0.34, 32), | |
| materials.darkWood, | |
| wheel, | |
| [0, 0, 0], | |
| [Math.PI / 2, 0, 0], | |
| "Wheel rim" | |
| ); | |
| addMesh( | |
| new THREE.TorusGeometry(0.45, 0.075, 8, 36), | |
| materials.wood, | |
| wheel, | |
| [0, 0, 0], | |
| [0, 0, 0], | |
| "Wheel outer rim" | |
| ); | |
| addMesh( | |
| new THREE.CylinderGeometry(0.19, 0.19, 0.4, 20), | |
| materials.iron, | |
| wheel, | |
| [0, 0, 0], | |
| [Math.PI / 2, 0, 0], | |
| "Wheel hub" | |
| ); | |
| const spokeZ = facing * 0.18; | |
| for (let i = 0; i < 6; i++) { | |
| const angle = (i / 6) * Math.PI * 2; | |
| addMesh( | |
| new THREE.BoxGeometry(1.02, 0.09, 0.065), | |
| materials.wood, | |
| wheel, | |
| [Math.cos(angle) * 0.39, Math.sin(angle) * 0.39, spokeZ], | |
| [0, 0, angle], | |
| "Carriage wheel spoke" | |
| ); | |
| } | |
| } | |
| createWheel(-1.72, -1.38, -1); | |
| createWheel(1.72, -1.38, -1); | |
| createWheel(-1.72, 1.38, 1); | |
| createWheel(1.72, 1.38, 1); | |
| // Deck cannon | |
| const cannon = new THREE.Group(); | |
| cannon.name = "Iron deck cannon"; | |
| model.add(cannon); | |
| // Barrel support cheeks | |
| for (const z of [-0.5, 0.5]) { | |
| addMesh( | |
| new THREE.BoxGeometry(0.52, 0.34, 0.25), | |
| materials.iron, | |
| cannon, | |
| [-0.18, 1.19, z], | |
| [0, 0, 0], | |
| "Cannon cheek block" | |
| ); | |
| } | |
| // Trunnion | |
| addMesh( | |
| new THREE.CylinderGeometry(0.28, 0.33, 0.55, 24), | |
| materials.iron, | |
| cannon, | |
| [-0.62, 1.34, 0], | |
| [0, 0, Math.PI / 2], | |
| "Cannon trunnion" | |
| ); | |
| // Main barrel, tapering toward the muzzle | |
| addMesh( | |
| new THREE.CylinderGeometry(0.19, 0.34, 2.65, 28), | |
| materials.iron, | |
| cannon, | |
| [0.85, 1.31, 0], | |
| [0, 0, -Math.PI / 2], | |
| "Cannon barrel" | |
| ); | |
| // Barrel bands | |
| addMesh( | |
| new THREE.TorusGeometry(0.345, 0.045, 8, 36), | |
| materials.iron, | |
| cannon, | |
| [-0.49, 1.31, 0], | |
| [0, Math.PI / 2, 0], | |
| "Rear barrel band" | |
| ); | |
| addMesh( | |
| new THREE.TorusGeometry(0.315, 0.04, 8, 36), | |
| materials.iron, | |
| cannon, | |
| [0.12, 1.31, 0], | |
| [0, Math.PI / 2, 0], | |
| "Middle barrel band" | |
| ); | |
| addMesh( | |
| new THREE.TorusGeometry(0.225, 0.045, 8, 36), | |
| materials.iron, | |
| cannon, | |
| [2.19, 1.31, 0], | |
| [0, Math.PI / 2, 0], | |
| "Muzzle barrel band" | |
| ); | |
| // Dark bore and muzzle lip | |
| addMesh( | |
| new THREE.CylinderGeometry(0.13, 0.16, 0.2, 24), | |
| materials.blackIron, | |
| cannon, | |
| [2.28, 1.31, 0], | |
| [0, 0, -Math.PI / 2], | |
| "Cannon bore" | |
| ); | |
| addMesh( | |
| new THREE.TorusGeometry(0.19, 0.025, 8, 32), | |
| materials.steel, | |
| cannon, | |
| [2.31, 1.31, 0], | |
| [0, Math.PI / 2, 0], | |
| "Muzzle lip" | |
| ); | |
| // Rear collar and sight | |
| addMesh( | |
| new THREE.CylinderGeometry(0.37, 0.37, 0.18, 24), | |
| materials.iron, | |
| cannon, | |
| [-0.72, 1.34, 0], | |
| [0, 0, Math.PI / 2], | |
| "Cannon rear collar" | |
| ); | |
| addMesh( | |
| new THREE.BoxGeometry(0.18, 0.13, 0.12), | |
| materials.brass, | |
| cannon, | |
| [-0.56, 1.58, 0.5], | |
| [0, 0, 0], | |
| "Front sight" | |
| ); | |
| addMesh( | |
| new THREE.CylinderGeometry(0.055, 0.055, 0.3, 12), | |
| materials.brass, | |
| cannon, | |
| [-0.56, 1.49, 0.5], | |
| [0, 0, 0], | |
| "Sight post" | |
| ); | |
| // Handle behind the cannon | |
| for (const z of [-0.28, 0.28]) { | |
| addMesh( | |
| new THREE.CylinderGeometry(0.045, 0.045, 0.48, 12), | |
| materials.iron, | |
| cannon, | |
| [-0.92, 1.31, z], | |
| [0, 0, Math.PI / 2], | |
| "Handle post" | |
| ); | |
| } | |
| addMesh( | |
| new THREE.BoxGeometry(0.18, 0.12, 0.72), | |
| materials.iron, | |
| cannon, | |
| [-0.92, 1.56, 0], | |
| [0, 0, 0], | |
| "Cannon handle" | |
| ); | |
| // Cannonball stack | |
| const ballStack = new THREE.Group(); | |
| ballStack.name = "Stack of cannonballs"; | |
| model.add(ballStack); | |
| const ballPositions = [ | |
| [-2.02, 1.76, 0.95], | |
| [-1.52, 1.76, 0.95], | |
| [-1.02, 1.76, 0.95], | |
| [-1.77, 2.54, 0.95], | |
| [-1.27, 2.54, 0.95], | |
| [-1.52, 3.32, 0.95] | |
| ]; | |
| for (const [x, y, z] of ballPositions) { | |
| const radius = 0.38; | |
| addMesh( | |
| new THREE.SphereGeometry(radius, 32, 24), | |
| materials.ball, | |
| ballStack, | |
| [x, y, z], | |
| [0, 0, 0], | |
| "Cannonball" | |
| ); | |
| // Equatorial seam | |
| addMesh( | |
| new THREE.TorusGeometry(radius + 0.006, 0.014, 6, 36), | |
| materials.ballSeam, | |
| ballStack, | |
| [x, y, z], | |
| [Math.PI / 2, 0, 0], | |
| "Cannonball equatorial seam" | |
| ); | |
| // Vertical seam | |
| addMesh( | |
| new THREE.TorusGeometry(radius + 0.006, 0.012, 6, 36), | |
| materials.ballSeam, | |
| ballStack, | |
| [x, y, z], | |
| [0, 0, 0], | |
| "Cannonball vertical seam" | |
| ); | |
| } | |
| // Small brass carriage plaque | |
| const plaque = new THREE.Group(); | |
| plaque.name = "Carriage plaque"; | |
| plaque.position.set(0, 0.87, 1.675); | |
| carriage.add(plaque); | |
| addMesh( | |
| new THREE.BoxGeometry(1.45, 0.28, 0.035), | |
| materials.brass, | |
| plaque, | |
| [0, 0, 0], | |
| [0, 0, 0], | |
| "Carriage plaque" | |
| ); | |
| addMesh( | |
| new THREE.BoxGeometry(0.34, 0.035, 0.012), | |
| materials.iron, | |
| plaque, | |
| [-0.38, 0, 0.025], | |
| [0, 0, 0], | |
| "Plaque inset" | |
| ); | |
| // Plain ground plane | |
| const ground = addMesh( | |
| new THREE.PlaneGeometry(100, 100), | |
| materials.ground, | |
| scene, | |
| [0, 0, 0], | |
| [-Math.PI / 2, 0, 0], | |
| "Plain ground plane" | |
| ); | |
| ground.castShadow = false; | |
| // Custom orbit controls implemented without external addons. | |
| const cameraTarget = new THREE.Vector3(0, 1.35, 0); | |
| const desired = { | |
| theta: 0.72, | |
| phi: 1.08, | |
| radius: 10.6 | |
| }; | |
| const current = { | |
| theta: desired.theta, | |
| phi: desired.phi, | |
| radius: desired.radius | |
| }; | |
| let dragging = false; | |
| let previousX = 0; | |
| let previousY = 0; | |
| function updateCamera() { | |
| current.theta += (desired.theta - current.theta) * 0.08; | |
| current.phi += (desired.phi - current.phi) * 0.08; | |
| current.radius += (desired.radius - current.radius) * 0.08; | |
| const sinPhi = Math.sin(current.phi); | |
| camera.position.set( | |
| cameraTarget.x + current.radius * sinPhi * Math.sin(current.theta), | |
| cameraTarget.y + current.radius * Math.cos(current.phi), | |
| cameraTarget.z + current.radius * sinPhi * Math.cos(current.theta) | |
| ); | |
| camera.lookAt(cameraTarget); | |
| } | |
| function resetCamera() { | |
| desired.theta = 0.72; | |
| desired.phi = 1.08; | |
| desired.radius = 10.6; | |
| } | |
| renderer.domElement.addEventListener("pointerdown", (event) => { | |
| dragging = true; | |
| previousX = event.clientX; | |
| previousY = event.clientY; | |
| renderer.domElement.setPointerCapture(event.pointerId); | |
| }); | |
| renderer.domElement.addEventListener("pointermove", (event) => { | |
| if (!dragging) return; | |
| const deltaX = event.clientX - previousX; | |
| const deltaY = event.clientY - previousY; | |
| previousX = event.clientX; | |
| previousY = event.clientY; | |
| desired.theta -= deltaX * 0.006; | |
| desired.phi = THREE.MathUtils.clamp( | |
| desired.phi - deltaY * 0.005, | |
| 0.34, | |
| 1.48 | |
| ); | |
| }); | |
| function endDrag(event) { | |
| dragging = false; | |
| if (renderer.domElement.hasPointerCapture(event.pointerId)) { | |
| renderer.domElement.releasePointerCapture(event.pointerId); | |
| } | |
| } | |
| renderer.domElement.addEventListener("pointerup", endDrag); | |
| renderer.domElement.addEventListener("pointercancel", endDrag); | |
| renderer.domElement.addEventListener("contextmenu", (event) => event.preventDefault()); | |
| renderer.domElement.addEventListener( | |
| "wheel", | |
| (event) => { | |
| event.preventDefault(); | |
| desired.radius = THREE.MathUtils.clamp( | |
| desired.radius * Math.exp(event.deltaY * 0.001), | |
| 5.5, | |
| 18 | |
| ); | |
| }, | |
| { passive: false } | |
| ); | |
| renderer.domElement.addEventListener("dblclick", resetCamera); | |
| window.addEventListener("keydown", (event) => { | |
| if (event.key === "ArrowLeft") desired.theta += 0.12; | |
| if (event.key === "ArrowRight") desired.theta -= 0.12; | |
| if (event.key === "ArrowUp") desired.phi = Math.max(0.34, desired.phi - 0.08); | |
| if (event.key === "ArrowDown") desired.phi = Math.min(1.48, desired.phi + 0.08); | |
| if (event.key === "+" || event.key === "=") desired.radius = Math.max(5.5, desired.radius - 0.5); | |
| if (event.key === "-") desired.radius = Math.min(18, desired.radius + 0.5); | |
| }); | |
| window.addEventListener("resize", () => { | |
| camera.aspect = window.innerWidth / window.innerHeight; | |
| camera.updateProjectionMatrix(); | |
| renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2)); | |
| renderer.setSize(window.innerWidth, window.innerHeight); | |
| }); | |
| const reducedMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches; | |
| const turntableSpeed = reducedMotion ? 0.035 : 0.22; | |
| const initialTurn = reducedMotion ? 0 : -0.28; | |
| let elapsed = 0; | |
| const clock = new THREE.Clock(); | |
| function animate() { | |
| requestAnimationFrame(animate); | |
| const delta = Math.min(clock.getDelta(), 0.05); | |
| elapsed += delta; | |
| turntable.rotation.y = initialTurn + elapsed * turntableSpeed; | |
| updateCamera(); | |
| renderer.render(scene, camera); | |
| } | |
| updateCamera(); | |
| animate(); | |
| </script> | |
| </body> | |
| </html> | |