multimodalart's picture
multimodalart HF Staff
Upload folder using huggingface_hub
19c0aab verified
Raw History Blame Contribute Delete
29.8 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Mars Cargo Landing Zone</title> <style> * { box-sizing: border-box; } html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; background: #160b09; color: #fff2df; font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; } canvas { display: block; width: 100%; height: 100%; } #hud { position: fixed; top: 22px; left: 24px; z-index: 10; pointer-events: none; text-shadow: 0 2px 12px rgba(0, 0, 0, 0.7); } #hud h1 { margin: 0 0 5px; font-size: clamp(20px, 3vw, 34px); letter-spacing: 0.12em; font-weight: 650; } #hud p { margin: 0; color: rgba(255, 240, 220, 0.75); font-size: 13px; letter-spacing: 0.04em; } #status { position: fixed; right: 24px; top: 24px; z-index: 10; padding: 12px 15px; border: 1px solid rgba(255, 210, 170, 0.25); border-radius: 8px; background: rgba(25, 11, 8, 0.55); backdrop-filter: blur(10px); font-size: 12px; letter-spacing: 0.08em; pointer-events: none; } #status .dot { display: inline-block; width: 7px; height: 7px; margin-right: 8px; border-radius: 50%; background: #8cffac; box-shadow: 0 0 10px #8cffac; } #controls { position: fixed; left: 24px; bottom: 22px; z-index: 10; padding: 10px 13px; border: 1px solid rgba(255, 220, 180, 0.2); border-radius: 7px; background: rgba(20, 9, 7, 0.5); backdrop-filter: blur(8px); color: rgba(255, 238, 218, 0.75); font-size: 12px; pointer-events: none; } @media (max-width: 650px) { #status { top: auto; right: 16px; bottom: 70px; } #controls { left: 16px; bottom: 16px; } } </style> </head> <body> <div id="hud"> <h1>MARS CARGO LANDING ZONE</h1> <p>Habitat 07 · Cargo operations · Surface route C-22</p> </div> <div id="status"> <span class="dot"></span>ROVER ON ROUTE </div> <div id="controls"> Drag to orbit · Scroll to zoom · Right-drag to pan </div> <script type="module"> import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js"; // ------------------------------------------------------------------------- // Renderer and scene // ------------------------------------------------------------------------- const renderer = new THREE.WebGLRenderer({ antialias: true, powerPreference: "high-performance" }); renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2)); renderer.setSize(window.innerWidth, window.innerHeight); renderer.shadowMap.enabled = true; renderer.shadowMap.type = THREE.PCFSoftShadowMap; renderer.outputColorSpace = THREE.SRGBColorSpace; renderer.toneMapping = THREE.ACESFilmicToneMapping; renderer.toneMappingExposure = 1.15; document.body.prepend(renderer.domElement); const scene = new THREE.Scene(); scene.background = new THREE.Color(0x4a1810); scene.fog = new THREE.FogExp2(0x4a1810, 0.009); const camera = new THREE.PerspectiveCamera( 48, window.innerWidth / window.innerHeight, 0.1, 500 ); const cameraState = { target: new THREE.Vector3(0, 2, 0), radius: 58, theta: 0.72, phi: 1.12, dragging: false, panning: false, lastX: 0, lastY: 0 }; function updateCamera() { const sinPhi = Math.sin(cameraState.phi); camera.position.set( cameraState.target.x + cameraState.radius * sinPhi * Math.sin(cameraState.theta), cameraState.target.y + cameraState.radius * Math.cos(cameraState.phi), cameraState.target.z + cameraState.radius * sinPhi * Math.cos(cameraState.theta) ); camera.lookAt(cameraState.target); } updateCamera(); // ------------------------------------------------------------------------- // Lighting // ------------------------------------------------------------------------- const hemisphere = new THREE.HemisphereLight(0xffd7bd, 0x4a1c14, 1.65); scene.add(hemisphere); const sun = new THREE.DirectionalLight(0xffead0, 3.2); sun.position.set(-35, 55, 25); sun.castShadow = true; sun.shadow.mapSize.set(2048, 2048); sun.shadow.camera.left = -70; sun.shadow.camera.right = 70; sun.shadow.camera.top = 70; sun.shadow.camera.bottom = -70; sun.shadow.camera.near = 1; sun.shadow.camera.far = 150; sun.shadow.bias = -0.00025; scene.add(sun); const rim = new THREE.DirectionalLight(0xff6a45, 1.1); rim.position.set(30, 15, -40); scene.add(rim); // ------------------------------------------------------------------------- // Materials // ------------------------------------------------------------------------- const mat = { habitat: new THREE.MeshStandardMaterial({ color: 0xd8c5a7, roughness: 0.62, metalness: 0.18 }), habitatDark: new THREE.MeshStandardMaterial({ color: 0x5a493b, roughness: 0.68, metalness: 0.32 }), orange: new THREE.MeshStandardMaterial({ color: 0xd8622e, roughness: 0.55, metalness: 0.22 }), steel: new THREE.MeshStandardMaterial({ color: 0x777b7d, roughness: 0.4, metalness: 0.72 }), darkSteel: new THREE.MeshStandardMaterial({ color: 0x292c2e, roughness: 0.55, metalness: 0.58 }), gold: new THREE.MeshStandardMaterial({ color: 0xc89038, roughness: 0.5, metalness: 0.55 }), black: new THREE.MeshStandardMaterial({ color: 0x111315, roughness: 0.9 }), glass: new THREE.MeshStandardMaterial({ color: 0x2c7582, emissive: 0x164c57, emissiveIntensity: 0.55, roughness: 0.2, metalness: 0.3 }), cream: new THREE.MeshStandardMaterial({ color: 0xe9ddc4, roughness: 0.8 }) }; function addMesh(geometry, material, parent = scene, cast = true, receive = true) { const mesh = new THREE.Mesh(geometry, material); mesh.castShadow = cast; mesh.receiveShadow = receive; parent.add(mesh); return mesh; } // ------------------------------------------------------------------------- // Procedural Mars terrain // ------------------------------------------------------------------------- function hash(x, z) { const n = Math.sin(x * 12.9898 + z * 78.233) * 43758.5453123; return n - Math.floor(n); } function terrainHeight(x, z) { return ( Math.sin(x * 0.055) * 1.15 + Math.cos(z * 0.047) * 0.9 + Math.sin((x + z) * 0.027) * 0.65 + hash(Math.floor(x / 5), Math.floor(z / 5)) * 0.18 ); } const terrainSize = 220; const terrainSegments = 120; const terrainGeometry = new THREE.PlaneGeometry( terrainSize, terrainSize, terrainSegments, terrainSegments ); terrainGeometry.rotateX(-Math.PI / 2); const terrainPositions = terrainGeometry.attributes.position; const terrainColors = []; const lowColor = new THREE.Color(0x6d2c1d); const highColor = new THREE.Color(0xb05231); const darkColor = new THREE.Color(0x351b17); for (let i = 0; i < terrainPositions.count; i++) { const x = terrainPositions.getX(i); const z = terrainPositions.getZ(i); const y = terrainHeight(x, z); terrainPositions.setY(i, y); const blend = THREE.MathUtils.clamp((y + 1.6) / 3.2, 0, 1); const color = darkColor.clone().lerp(lowColor, blend).lerp(highColor, blend * 0.45); terrainColors.push(color.r, color.g, color.b); } terrainGeometry.setAttribute( "color", new THREE.Float32BufferAttribute(terrainColors, 3) ); terrainGeometry.computeVertexNormals(); const terrain = addMesh( terrainGeometry, new THREE.MeshStandardMaterial({ vertexColors: true, roughness: 1, metalness: 0.02 }), scene, false, true ); // Background rocks const rockGeometry = new THREE.DodecahedronGeometry(1, 0); const rockMaterial = new THREE.MeshStandardMaterial({ color: 0x6a3224, roughness: 1 }); for (let i = 0; i < 85; i++) { const angle = hash(i, 2) * Math.PI * 2; const radius = 45 + hash(i, 3) * 70; const x = Math.cos(angle) * radius; const z = Math.sin(angle) * radius; const scale = 0.3 + hash(i, 4) * 2.1; const rock = addMesh( rockGeometry, rockMaterial, scene, true, true ); rock.position.set(x, terrainHeight(x, z) + scale * 0.28, z); rock.scale.set( scale * (0.8 + hash(i, 5) * 0.5), scale * (0.55 + hash(i, 6) * 0.4), scale * (0.8 + hash(i, 7) * 0.5) ); rock.rotation.set(hash(i, 8), hash(i, 9), hash(i, 10)); } // ------------------------------------------------------------------------- // Central habitat // ------------------------------------------------------------------------- const habitat = new THREE.Group(); habitat.position.set(-8, terrainHeight(-8, -4), -4); scene.add(habitat); const habitatBase = addMesh( new THREE.CylinderGeometry(8.5, 8.9, 1.2, 48), mat.habitatDark, habitat ); habitatBase.position.y = 0.6; const habitatBody = addMesh( new THREE.CylinderGeometry(7.4, 7.8, 5.2, 48), mat.habitat, habitat ); habitatBody.position.y = 3.8; const habitatRoof = addMesh( new THREE.SphereGeometry(7.4, 48, 18, 0, Math.PI * 2), mat.habitat, habitat ); habitatRoof.scale.y = 0.34; habitatRoof.position.y = 6.4; const habitatBand = addMesh( new THREE.TorusGeometry(7.55, 0.12, 8, 64), mat.orange, habitat ); habitatBand.rotation.x = Math.PI / 2; habitatBand.position.y = 2.2; // Paneled exterior details for (let i = 0; i < 12; i++) { const angle = (i / 12) * Math.PI * 2; const panel = addMesh( new THREE.BoxGeometry(0.16, 3.8, 0.8), mat.habitatDark, habitat ); panel.position.set( Math.cos(angle) * 7.62, 3.8, Math.sin(angle) * 7.62 ); panel.rotation.y = -angle; } // Windows for (let i = 0; i < 14; i++) { const angle = (i / 14) * Math.PI * 2; const windowMesh = addMesh( new THREE.BoxGeometry(0.65, 0.9, 0.12), mat.glass, habitat, false, false ); windowMesh.position.set( Math.cos(angle) * 7.55, 4.6, Math.sin(angle) * 7.55 ); windowMesh.rotation.y = -angle + Math.PI / 2; } // Main airlock const airlock = addMesh( new THREE.BoxGeometry(2.7, 3.2, 2.4), mat.cream, habitat ); airlock.position.set(0, 2.2, 7.4); const door = addMesh( new THREE.BoxGeometry(1.2, 2.4, 0.16), mat.darkSteel, habitat ); door.position.set(0, 2.0, 8.64); const doorWindow = addMesh( new THREE.BoxGeometry(0.58, 0.58, 0.05), mat.glass, habitat, false, false ); doorWindow.position.set(0, 2.8, 8.74); // Roof antenna and beacon const mast = addMesh( new THREE.CylinderGeometry(0.08, 0.12, 4.3, 8), mat.steel, habitat ); mast.position.set(1.6, 9.1, -0.8); const antennaDish = addMesh( new THREE.SphereGeometry(0.7, 18, 10, 0, Math.PI * 2, 0, Math.PI * 0.5), mat.cream, habitat ); antennaDish.position.set(1.6, 10.55, -0.8); antennaDish.rotation.x = Math.PI * 0.72; const beaconMaterial = new THREE.MeshStandardMaterial({ color: 0xff6b45, emissive: 0xff3516, emissiveIntensity: 3 }); const beacon = addMesh( new THREE.SphereGeometry(0.17, 12, 8), beaconMaterial, habitat, false, false ); beacon.position.set(1.6, 10.75, -0.8); // Habitat landing lights for (let i = 0; i < 8; i++) { const angle = (i / 8) * Math.PI * 2; const light = addMesh( new THREE.SphereGeometry(0.12, 8, 6), beaconMaterial, habitat, false, false ); light.position.set( Math.cos(angle) * 8.2, 1.35, Math.sin(angle) * 8.2 ); } // Stairs to airlock for (let i = 0; i < 6; i++) { const step = addMesh( new THREE.BoxGeometry(2.4, 0.18, 0.6), mat.habitatDark, habitat ); step.position.set(0, 0.16 + i * 0.24, 9.25 + i * 0.48); } // ------------------------------------------------------------------------- // Cargo decks and containers // ------------------------------------------------------------------------- const deck = new THREE.Group(); deck.position.set(16, terrainHeight(16, 8), 8); scene.add(deck); const deckPad = addMesh( new THREE.CylinderGeometry(10, 10.6, 0.65, 12), mat.habitatDark, deck ); deckPad.position.y = 0.25; deckPad.rotation.y = Math.PI / 12; const deckFloor = addMesh( new THREE.CylinderGeometry(9.6, 9.6, 0.18, 12), new THREE.MeshStandardMaterial({ color: 0x6c5041, roughness: 0.95 }), deck ); deckFloor.position.y = 0.68; deckFloor.rotation.y = Math.PI / 12; const containerColors = [0xb85b32, 0xd39a43, 0x647c78, 0x745d7d]; function makeContainer(parent, x, z, index, ry = 0) { const group = new THREE.Group(); group.position.set(x, 1.5, z); group.rotation.y = ry; parent.add(group); const bodyMaterial = new THREE.MeshStandardMaterial({ color: containerColors[index % containerColors.length], roughness: 0.72, metalness: 0.15 }); const body = addMesh( new THREE.BoxGeometry(3.4, 1.65, 1.65), bodyMaterial, group ); for (let i = -5; i <= 5; i++) { const rib = addMesh( new THREE.BoxGeometry(0.08, 1.72, 1.72), mat.steel, group ); rib.position.x = i * 0.3; } const top = addMesh( new THREE.BoxGeometry(3.6, 0.12, 1.8), mat.gold, group ); top.position.y = 0.9; return group; } makeContainer(deck, -4.4, -1.5, 0, 0.12); makeContainer(deck, 0.0, -1.7, 1, -0.08); makeContainer(deck, 4.3, -1.2, 2, 0.04); makeContainer(deck, -2.4, 2.8, 3, 0.2); makeContainer(deck, 2.4, 2.8, 1, -0.15); // Small cargo crates for (let i = 0; i < 11; i++) { const crate = addMesh( new THREE.BoxGeometry(0.9, 0.9, 0.9), i % 2 ? mat.gold : mat.cream, deck ); crate.position.set( -5 + (i % 4) * 2.5, 1.25, 5.7 + Math.floor(i / 4) * 1.25 ); crate.rotation.y = hash(i, 22) * 0.4; } // Fence posts around the deck for (let i = 0; i < 16; i++) { const angle = (i / 16) * Math.PI * 2; const post = addMesh( new THREE.CylinderGeometry(0.07, 0.07, 1.2, 8), mat.steel, deck ); post.position.set( Math.cos(angle) * 10.2, 1.25, Math.sin(angle) * 10.2 ); } // ------------------------------------------------------------------------- // Cranes // ------------------------------------------------------------------------- function makeCrane(position, rotation = 0) { const crane = new THREE.Group(); crane.position.copy(position); crane.rotation.y = rotation; scene.add(crane); const foot = addMesh( new THREE.CylinderGeometry(1.1, 1.4, 0.6, 8), mat.steel, crane ); foot.position.y = 0.3; const tower = addMesh( new THREE.BoxGeometry(1.5, 10, 1.5), mat.orange, crane ); tower.position.y = 5.3; const cab = addMesh( new THREE.BoxGeometry(2.1, 1.8, 2.2), mat.cream, crane ); cab.position.y = 10.8; const cabWindow = addMesh( new THREE.BoxGeometry(2.14, 0.65, 1.65), mat.glass, crane, false, false ); cabWindow.position.y = 11.15; const jib = addMesh( new THREE.BoxGeometry(14, 0.48, 0.55), mat.orange, crane ); jib.position.set(5.3, 11.6, 0); const jibTip = addMesh( new THREE.BoxGeometry(1.2, 1.1, 1.2), mat.steel, crane ); jibTip.position.set(11.6, 11.4, 0); for (let i = 0; i < 8; i++) { const cable = addMesh( new THREE.CylinderGeometry(0.018, 0.018, 4.2, 5), mat.black, crane ); cable.position.set(3.2 + i * 1.45, 9.45, 0); } const hook = addMesh( new THREE.TorusGeometry(0.42, 0.1, 8, 16, Math.PI * 1.5), mat.steel, crane ); hook.position.set(8.3, 6.7, 0); hook.rotation.z = Math.PI * 0.2; const suspendedBox = addMesh( new THREE.BoxGeometry(1.7, 1.4, 1.7), mat.gold, crane ); suspendedBox.position.set(8.3, 5.35, 0); return crane; } makeCrane(new THREE.Vector3(23, terrainHeight(23, 2), 2), -0.45); makeCrane(new THREE.Vector3(-8, terrainHeight(-8, 22), 22), 2.35); // ------------------------------------------------------------------------- // Marked rover route // ------------------------------------------------------------------------- const routeControls = [ new THREE.Vector3(-4, 0, -18), new THREE.Vector3(12, 0, -26), new THREE.Vector3(30, 0, -18), new THREE.Vector3(39, 0, 7), new THREE.Vector3(24, 0, 25), new THREE.Vector3(2, 0, 31), new THREE.Vector3(-22, 0, 22), new THREE.Vector3(-33, 0, 0), new THREE.Vector3(-25, 0, -17), new THREE.Vector3(-4, 0, -18) ]; for (const point of routeControls) { point.y = terrainHeight(point.x, point.z); } const routeCurve = new THREE.CatmullRomCurve3( routeControls, true, "catmullrom", 0.25 ); function createRouteRibbon(curve, width, yOffset, material) { const samples = 320; const positions = []; const indices = []; for (let i = 0; i <= samples; i++) { const u = i / samples; const point = curve.getPointAt(u); const tangent = curve.getTangentAt(u); const side = new THREE.Vector3(tangent.z, 0, -tangent.x).normalize(); const left = point.clone().addScaledVector(side, width * 0.5); const right = point.clone().addScaledVector(side, -width * 0.5); left.y = terrainHeight(left.x, left.z) + yOffset; right.y = terrainHeight(right.x, right.z) + yOffset; positions.push(left.x, left.y, left.z); positions.push(right.x, right.y, right.z); if (i < samples) { const a = i * 2; indices.push(a, a + 2, a + 1, a + 1, a + 2, a + 3); } } const geometry = new THREE.BufferGeometry(); geometry.setAttribute("position", new THREE.Float32BufferAttribute(positions, 3)); geometry.setIndex(indices); geometry.computeVertexNormals(); const mesh = new THREE.Mesh(geometry, material); mesh.receiveShadow = true; scene.add(mesh); return mesh; } const routeMaterial = new THREE.MeshStandardMaterial({ color: 0x8c3d2a, roughness: 0.92, side: THREE.DoubleSide }); createRouteRibbon(routeCurve, 4.6, 0.055, routeMaterial); // Center dashes const dashMaterial = new THREE.MeshStandardMaterial({ color: 0xe0b453, roughness: 0.8 }); for (let i = 0; i < 70; i++) { const u = i / 70; const point = routeCurve.getPointAt(u); const tangent = routeCurve.getTangentAt(u); const dash = addMesh( new THREE.BoxGeometry(0.22, 0.035, 1.25), dashMaterial, scene, false, true ); dash.position.set( point.x, terrainHeight(point.x, point.z) + 0.085, point.z ); dash.rotation.y = Math.atan2(tangent.x, tangent.z); } // Route edge strips const edgeMaterial = new THREE.MeshStandardMaterial({ color: 0xd8d2b5, roughness: 0.9, side: THREE.DoubleSide }); createRouteRibbon(routeCurve, 5.1, 0.045, edgeMaterial); createRouteRibbon(routeCurve, 4.15, 0.07, routeMaterial); // Painted direction chevrons const chevronShape = new THREE.Shape(); chevronShape.moveTo(-0.7, -1.4); chevronShape.lineTo(0, -0.4); chevronShape.lineTo(0.7, -1.4); chevronShape.lineTo(0.7, -0.8); chevronShape.lineTo(0, 0.2); chevronShape.lineTo(-0.7, -0.8); chevronShape.closePath(); const chevronGeometry = new THREE.ShapeGeometry(chevronShape); const chevronMaterial = new THREE.MeshStandardMaterial({ color: 0xe6b84f, roughness: 0.9, side: THREE.DoubleSide }); for (let i = 0; i < 10; i++) { const u = (i + 0.5) / 10; const point = routeCurve.getPointAt(u); const tangent = routeCurve.getTangentAt(u); const chevron = addMesh( chevronGeometry, chevronMaterial, scene, false, true ); chevron.position.set(point.x, terrainHeight(point.x, point.z) + 0.1, point.z); chevron.rotation.x = -Math.PI / 2; chevron.rotation.z = -Math.atan2(tangent.x, tangent.z); } // ------------------------------------------------------------------------- // Rover // ------------------------------------------------------------------------- const rover = new THREE.Group(); scene.add(rover); // Chassis const roverBody = addMesh( new THREE.BoxGeometry(2.55, 0.48, 3.45), mat.orange, rover ); roverBody.position.y = 0.95; const roverTop = addMesh( new THREE.BoxGeometry(2.15, 0.72, 2.25), mat.cream, rover ); roverTop.position.set(0, 1.45, -0.1); const cockpitGlass = addMesh( new THREE.BoxGeometry(1.9, 0.52, 1.35), mat.glass, rover, false, false ); cockpitGlass.position.set(0, 1.63, 0.15); // Side panels for (const side of [-1, 1]) { const panel = addMesh( new THREE.BoxGeometry(0.12, 0.38, 2.4), mat.gold, rover ); panel.position.set(side * 1.32, 1.0, -0.1); } // Cargo box at rear const cargoBox = addMesh( new THREE.BoxGeometry(1.85, 1.0, 1.05), mat.steel, rover ); cargoBox.position.set(0, 1.55, -1.35); // Antenna const roverAntenna = addMesh( new THREE.CylinderGeometry(0.025, 0.035, 1.4, 6), mat.steel, rover ); roverAntenna.position.set(-0.8, 2.25, -1.1); const roverBeacon = addMesh( new THREE.SphereGeometry(0.1, 8, 6), beaconMaterial, rover, false, false ); roverBeacon.position.set(-0.8, 2.98, -1.1); // Headlights for (const side of [-1, 1]) { const headlight = addMesh( new THREE.SphereGeometry(0.12, 8, 6), new THREE.MeshStandardMaterial({ color: 0xfff4c8, emissive: 0xffd57a, emissiveIntensity: 2.5 }), rover, false, false ); headlight.position.set(side * 0.75, 1.06, 1.77); } // Six wheels const wheels = []; const wheelPositions = [ [-1.3, 0.55, 1.1], [ 1.3, 0.55, 1.1], [-1.3, 0.55, 0.0], [ 1.3, 0.55, 0.0], [-1.3, 0.55, -1.1], [ 1.3, 0.55, -1.1] ]; for (const [x, y, z] of wheelPositions) { const wheelPivot = new THREE.Group(); wheelPivot.position.set(x, y, z); rover.add(wheelPivot); const tire = addMesh( new THREE.CylinderGeometry(0.48, 0.48, 0.36, 18), mat.black, wheelPivot ); tire.rotation.z = Math.PI / 2; const hub = addMesh( new THREE.CylinderGeometry(0.22, 0.22, 0.38, 12), mat.gold, wheelPivot ); hub.rotation.z = Math.PI / 2; wheels.push(wheelPivot); } // Rover follows the complete route continuously let roverProgress = 0.22; const roverSpeed = 0.009; const roverPosition = new THREE.Vector3(); const roverTangent = new THREE.Vector3(); function updateRover(dt) { roverProgress = (roverProgress + roverSpeed * dt) % 1; roverPosition.copy(routeCurve.getPointAt(roverProgress)); roverTangent.copy(routeCurve.getTangentAt(roverProgress)).normalize(); rover.position.set( roverPosition.x, terrainHeight(roverPosition.x, roverPosition.z) + 0.28, roverPosition.z ); rover.rotation.y = Math.atan2(roverTangent.x, roverTangent.z); const wheelAngle = performance.now() * 0.0025; for (const wheel of wheels) { wheel.rotation.x = wheelAngle; } } updateRover(0); // ------------------------------------------------------------------------- // Custom orbit, pan, and zoom camera controls // ------------------------------------------------------------------------- const canvas = renderer.domElement; canvas.addEventListener("contextmenu", event => event.preventDefault()); canvas.addEventListener("pointerdown", event => { cameraState.dragging = true; cameraState.panning = event.button === 2; cameraState.lastX = event.clientX; cameraState.lastY = event.clientY; canvas.setPointerCapture(event.pointerId); }); canvas.addEventListener("pointermove", event => { if (!cameraState.dragging) return; const dx = event.clientX - cameraState.lastX; const dy = event.clientY - cameraState.lastY; cameraState.lastX = event.clientX; cameraState.lastY = event.clientY; if (cameraState.panning) { const forward = new THREE.Vector3(); camera.getWorldDirection(forward); forward.y = 0; forward.normalize(); const right = new THREE.Vector3().crossVectors(forward, camera.up).normalize(); const panScale = cameraState.radius * 0.0015; cameraState.target.addScaledVector(right, -dx * panScale); cameraState.target.addScaledVector(forward, -dy * panScale); } else { cameraState.theta -= dx * 0.005; cameraState.phi = THREE.MathUtils.clamp( cameraState.phi - dy * 0.004, 0.18, Math.PI * 0.48 ); } updateCamera(); }); canvas.addEventListener("pointerup", event => { cameraState.dragging = false; cameraState.panning = false; if (canvas.hasPointerCapture(event.pointerId)) { canvas.releasePointerCapture(event.pointerId); } }); canvas.addEventListener("pointercancel", () => { cameraState.dragging = false; cameraState.panning = false; }); canvas.addEventListener("wheel", event => { event.preventDefault(); cameraState.radius = THREE.MathUtils.clamp( cameraState.radius * Math.exp(event.deltaY * 0.001), 12, 130 ); updateCamera(); }, { passive: false }); // Keyboard camera movement const keys = new Set(); window.addEventListener("keydown", event => { keys.add(event.key.toLowerCase()); }); window.addEventListener("keyup", event => { keys.delete(event.key.toLowerCase()); }); function updateKeyboardCamera(dt) { const forward = new THREE.Vector3(); camera.getWorldDirection(forward); forward.y = 0; forward.normalize(); const right = new THREE.Vector3().crossVectors(forward, camera.up).normalize(); const movement = new THREE.Vector3(); if (keys.has("w") || keys.has("arrowup")) movement.add(forward); if (keys.has("s") || keys.has("arrowdown")) movement.sub(forward); if (keys.has("d") || keys.has("arrowright")) movement.add(right); if (keys.has("a") || keys.has("arrowleft")) movement.sub(right); if (movement.lengthSq() > 0) { movement.normalize().multiplyScalar(dt * 14); cameraState.target.add(movement); updateCamera(); } } // ------------------------------------------------------------------------- // Animation // ------------------------------------------------------------------------- const clock = new THREE.Clock(); function animate() { const dt = Math.min(clock.getDelta(), 0.05); updateRover(dt); updateKeyboardCamera(dt); beaconMaterial.emissiveIntensity = 2.4 + Math.sin(clock.elapsedTime * 4) * 0.8; renderer.render(scene, camera); requestAnimationFrame(animate); } animate(); window.addEventListener("resize", () => { camera.aspect = window.innerWidth / window.innerHeight; camera.updateProjectionMatrix(); renderer.setSize(window.innerWidth, window.innerHeight); renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2)); }); </script> </body> </html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Mars Cargo Landing Zone</title>
<style>
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #160b09;
color: #fff2df;
font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
}
#hud {
position: fixed;
top: 22px;
left: 24px;
z-index: 10;
pointer-events: none;
text-shadow: 0 2px 12px rgba(0, 0, 0, 0.7);
}
#hud h1 {
margin: 0 0 5px;
font-size: clamp(20px, 3vw, 34px);
letter-spacing: 0.12em;
font-weight: 650;
}
#hud p {
margin: 0;
color: rgba(255, 240, 220, 0.75);
font-size: 13px;
letter-spacing: 0.04em;
}
#status {
position: fixed;
right: 24px;
top: 24px;
z-index: 10;
padding: 12px 15px;
border: 1px solid rgba(255, 210, 170, 0.25);
border-radius: 8px;
background: rgba(25, 11, 8, 0.55);
backdrop-filter: blur(10px);
font-size: 12px;
letter-spacing: 0.08em;
pointer-events: none;
}
#status .dot {
display: inline-block;
width: 7px;
height: 7px;
margin-right: 8px;
border-radius: 50%;
background: #8cffac;
box-shadow: 0 0 10px #8cffac;
}
#controls {
position: fixed;
left: 24px;
bottom: 22px;
z-index: 10;
padding: 10px 13px;
border: 1px solid rgba(255, 220, 180, 0.2);
border-radius: 7px;
background: rgba(20, 9, 7, 0.5);
backdrop-filter: blur(8px);
color: rgba(255, 238, 218, 0.75);
font-size: 12px;
pointer-events: none;
}
@media (max-width: 650px) {
#status {
top: auto;
right: 16px;
bottom: 70px;
}
#controls {