Datasets:
Download source/tower.html from LocalLLaMA/optiq-3d-coder-assets: direct link, hf CLI and curl.
- Browser
- Download file 18.5 kB
-
https://huggingface.co/datasets/LocalLLaMA/optiq-3d-coder-assets/resolve/main/source/tower.html
- Command line
-
hf download hf://datasets/LocalLLaMA/optiq-3d-coder-assets/source/tower.html
-
curl -L -o tower.html https://huggingface.co/datasets/LocalLLaMA/optiq-3d-coder-assets/resolve/main/source/tower.html
18.5 kB
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Medieval Castle Guard Tower</title> | |
| <style> | |
| * { | |
| box-sizing: border-box; | |
| } | |
| html, | |
| body { | |
| width: 100%; | |
| height: 100%; | |
| margin: 0; | |
| overflow: hidden; | |
| background: #b8ad98; | |
| font-family: Georgia, "Times New Roman", serif; | |
| } | |
| canvas { | |
| display: block; | |
| width: 100%; | |
| height: 100%; | |
| cursor: grab; | |
| touch-action: none; | |
| } | |
| canvas.dragging { | |
| cursor: grabbing; | |
| } | |
| .title-card { | |
| position: fixed; | |
| top: 24px; | |
| left: 26px; | |
| z-index: 10; | |
| max-width: min(390px, calc(100vw - 52px)); | |
| padding: 15px 18px; | |
| color: #f4ead6; | |
| background: linear-gradient(145deg, rgba(38, 31, 25, 0.88), rgba(65, 48, 34, 0.72)); | |
| border: 1px solid rgba(218, 184, 120, 0.55); | |
| border-radius: 8px; | |
| box-shadow: 0 12px 35px rgba(35, 26, 18, 0.25); | |
| backdrop-filter: blur(8px); | |
| pointer-events: none; | |
| } | |
| .title-card h1 { | |
| margin: 0 0 5px; | |
| font-size: 20px; | |
| font-weight: 600; | |
| letter-spacing: 0.04em; | |
| } | |
| .title-card p { | |
| margin: 0; | |
| color: #d8c7a8; | |
| font-size: 12px; | |
| line-height: 1.45; | |
| } | |
| .controls { | |
| position: fixed; | |
| right: 22px; | |
| bottom: 22px; | |
| z-index: 10; | |
| display: flex; | |
| align-items: center; | |
| gap: 12px; | |
| padding: 10px 12px; | |
| color: #f4ead6; | |
| background: rgba(38, 31, 25, 0.78); | |
| border: 1px solid rgba(218, 184, 120, 0.45); | |
| border-radius: 7px; | |
| box-shadow: 0 8px 24px rgba(35, 26, 18, 0.2); | |
| backdrop-filter: blur(8px); | |
| font: 12px/1.35 Georgia, "Times New Roman", serif; | |
| } | |
| button { | |
| appearance: none; | |
| padding: 7px 10px; | |
| color: #f4ead6; | |
| background: rgba(218, 184, 120, 0.15); | |
| border: 1px solid rgba(218, 184, 120, 0.55); | |
| border-radius: 4px; | |
| font: inherit; | |
| cursor: pointer; | |
| } | |
| button:hover { | |
| background: rgba(218, 184, 120, 0.28); | |
| } | |
| button:active { | |
| transform: translateY(1px); | |
| } | |
| .hint { | |
| color: #d8c7a8; | |
| } | |
| @media (max-width: 600px) { | |
| .title-card { | |
| top: 14px; | |
| left: 14px; | |
| padding: 11px 13px; | |
| } | |
| .title-card h1 { | |
| font-size: 17px; | |
| } | |
| .controls { | |
| right: 12px; | |
| bottom: 12px; | |
| } | |
| .hint { | |
| display: none; | |
| } | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <canvas id="scene" aria-label="Interactive 3D medieval castle guard tower"></canvas> | |
| <div class="title-card"> | |
| <h1>Castle Guard Tower</h1> | |
| <p>A stone watchtower with crenellations, an arched oak door, and a waving banner.</p> | |
| </div> | |
| <div class="controls"> | |
| <span class="hint">Drag to orbit · Scroll to zoom · Double-click to reset</span> | |
| <button id="turntableButton" type="button" aria-pressed="false">Pause turntable</button> | |
| </div> | |
| <script type="module"> | |
| import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js"; | |
| const canvas = document.querySelector("#scene"); | |
| const turntableButton = document.querySelector("#turntableButton"); | |
| // Renderer | |
| const renderer = new THREE.WebGLRenderer({ | |
| canvas, | |
| 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.05; | |
| renderer.shadowMap.enabled = true; | |
| renderer.shadowMap.type = THREE.PCFSoftShadowMap; | |
| // Scene | |
| const scene = new THREE.Scene(); | |
| scene.background = new THREE.Color(0xb8ad98); | |
| scene.fog = new THREE.Fog(0xb8ad98, 18, 42); | |
| const camera = new THREE.PerspectiveCamera( | |
| 42, | |
| window.innerWidth / window.innerHeight, | |
| 0.1, | |
| 100 | |
| ); | |
| // Lighting | |
| scene.add(new THREE.HemisphereLight(0xdde4dc, 0x69533e, 2.1)); | |
| const sun = new THREE.DirectionalLight(0xffe5b5, 3.2); | |
| sun.position.set(-7, 11, 8); | |
| sun.castShadow = true; | |
| sun.shadow.mapSize.set(2048, 2048); | |
| sun.shadow.camera.left = -10; | |
| sun.shadow.camera.right = 10; | |
| sun.shadow.camera.top = 12; | |
| sun.shadow.camera.bottom = -8; | |
| sun.shadow.camera.near = 1; | |
| sun.shadow.camera.far = 30; | |
| sun.shadow.bias = -0.00035; | |
| scene.add(sun); | |
| const fill = new THREE.DirectionalLight(0x9fb8c7, 0.75); | |
| fill.position.set(7, 5, -8); | |
| scene.add(fill); | |
| // Materials | |
| const materials = { | |
| stone: new THREE.MeshStandardMaterial({ | |
| color: 0x8d816d, | |
| roughness: 0.96 | |
| }), | |
| stoneLight: new THREE.MeshStandardMaterial({ | |
| color: 0xa5977c, | |
| roughness: 0.94 | |
| }), | |
| stoneDark: new THREE.MeshStandardMaterial({ | |
| color: 0x685f4e, | |
| roughness: 1 | |
| }), | |
| wood: new THREE.MeshStandardMaterial({ | |
| color: 0x5b321d, | |
| roughness: 0.88 | |
| }), | |
| darkWood: new THREE.MeshStandardMaterial({ | |
| color: 0x2d170d, | |
| roughness: 0.96 | |
| }), | |
| iron: new THREE.MeshStandardMaterial({ | |
| color: 0x303438, | |
| roughness: 0.55, | |
| metalness: 0.72 | |
| }), | |
| gold: new THREE.MeshStandardMaterial({ | |
| color: 0xd6a74c, | |
| roughness: 0.42, | |
| metalness: 0.65 | |
| }), | |
| cloth: new THREE.MeshStandardMaterial({ | |
| color: 0xc75332, | |
| roughness: 0.8, | |
| side: THREE.DoubleSide | |
| }), | |
| ground: new THREE.MeshStandardMaterial({ | |
| color: 0xb6aa91, | |
| roughness: 1 | |
| }) | |
| }; | |
| // Helper for adding named, shadowed meshes | |
| function addMesh(geometry, material, position, parent, name) { | |
| const mesh = new THREE.Mesh(geometry, material); | |
| mesh.position.set(position[0], position[1], position[2]); | |
| mesh.name = name; | |
| mesh.castShadow = true; | |
| mesh.receiveShadow = true; | |
| parent.add(mesh); | |
| return mesh; | |
| } | |
| // Ground plane, kept stationary while the tower rotates on its turntable | |
| const ground = addMesh( | |
| new THREE.PlaneGeometry(80, 80), | |
| materials.ground, | |
| [0, -0.045, 0], | |
| scene, | |
| "Plain ground plane" | |
| ); | |
| ground.rotation.x = -Math.PI / 2; | |
| ground.castShadow = false; | |
| // Turntable and tower assembly | |
| const turntable = new THREE.Group(); | |
| turntable.name = "Rotating turntable"; | |
| scene.add(turntable); | |
| // Stone turntable base | |
| addMesh( | |
| new THREE.BoxGeometry(4.7, 0.18, 4.7), | |
| materials.stoneDark, | |
| [0, 0.09, 0], | |
| turntable, | |
| "Stone turntable base" | |
| ); | |
| const tower = new THREE.Group(); | |
| turntable.add(tower); | |
| // Foundation | |
| addMesh( | |
| new THREE.BoxGeometry(3.15, 0.55, 3.15), | |
| materials.stoneLight, | |
| [0, 0.43, 0], | |
| tower, | |
| "Tower foundation" | |
| ); | |
| // Main tower body with a true arched opening | |
| const towerShape = new THREE.Shape(); | |
| towerShape.moveTo(-1.35, 0); | |
| towerShape.lineTo(1.35, 0); | |
| towerShape.lineTo(1.35, 3.8); | |
| towerShape.lineTo(-1.35, 3.8); | |
| towerShape.closePath(); | |
| const doorOpening = new THREE.Path(); | |
| doorOpening.moveTo(-0.48, 0); | |
| doorOpening.lineTo(0.48, 0); | |
| doorOpening.lineTo(0.48, 1.45); | |
| doorOpening.absarc(0, 1.45, 0.48, 0, Math.PI, false); | |
| doorOpening.lineTo(-0.48, 0); | |
| doorOpening.closePath(); | |
| towerShape.holes.push(doorOpening); | |
| const towerBodyGeometry = new THREE.ExtrudeGeometry(towerShape, { | |
| depth: 2.4, | |
| bevelEnabled: false, | |
| curveSegments: 16, | |
| steps: 1 | |
| }); | |
| addMesh( | |
| towerBodyGeometry, | |
| materials.stone, | |
| [0, 0.78, -1.2], | |
| tower, | |
| "Arched stone tower body" | |
| ); | |
| // Dark interior visible through the opening | |
| const interiorShape = new THREE.Shape(); | |
| interiorShape.moveTo(-0.47, 0); | |
| interiorShape.lineTo(0.47, 0); | |
| interiorShape.lineTo(0.47, 1.45); | |
| interiorShape.absarc(0, 1.45, 0.47, 0, Math.PI, false); | |
| interiorShape.lineTo(-0.47, 0); | |
| interiorShape.closePath(); | |
| const interior = addMesh( | |
| new THREE.ShapeGeometry(interiorShape, 16), | |
| materials.darkWood, | |
| [0, 0.78, -1.185], | |
| tower, | |
| "Dark tower interior" | |
| ); | |
| interior.castShadow = false; | |
| // Wooden arched door | |
| const doorShape = new THREE.Shape(); | |
| doorShape.moveTo(-0.47, 0); | |
| doorShape.lineTo(0.47, 0); | |
| doorShape.lineTo(0.47, 1.45); | |
| doorShape.absarc(0, 1.45, 0.47, 0, Math.PI, false); | |
| doorShape.lineTo(-0.47, 0); | |
| doorShape.closePath(); | |
| addMesh( | |
| new THREE.ShapeGeometry(doorShape, 16), | |
| materials.wood, | |
| [0, 0.79, 1.205], | |
| tower, | |
| "Arched wooden door" | |
| ); | |
| // Door frame | |
| addMesh( | |
| new THREE.BoxGeometry(0.13, 2.0, 0.14), | |
| materials.stoneLight, | |
| [-0.56, 1.78, 1.245], | |
| tower, | |
| "Left door jamb" | |
| ); | |
| addMesh( | |
| new THREE.BoxGeometry(0.13, 2.0, 0.14), | |
| materials.stoneLight, | |
| [0.56, 1.78, 1.245], | |
| tower, | |
| "Right door jamb" | |
| ); | |
| const archFrame = addMesh( | |
| new THREE.TorusGeometry(0.55, 0.075, 8, 24, Math.PI), | |
| materials.stoneLight, | |
| [0, 1.45, 1.27], | |
| tower, | |
| "Arched door frame" | |
| ); | |
| addMesh( | |
| new THREE.BoxGeometry(0.16, 0.28, 0.16), | |
| materials.stoneLight, | |
| [0, 2.02, 1.27], | |
| tower, | |
| "Door keystone" | |
| ); | |
| // Iron door hardware | |
| addMesh( | |
| new THREE.BoxGeometry(0.045, 0.72, 0.035), | |
| materials.iron, | |
| [-0.31, 1.08, 1.235], | |
| tower, | |
| "Left iron door strap" | |
| ); | |
| addMesh( | |
| new THREE.BoxGeometry(0.045, 0.72, 0.035), | |
| materials.iron, | |
| [0.31, 1.08, 1.235], | |
| tower, | |
| "Right iron door strap" | |
| ); | |
| addMesh( | |
| new THREE.BoxGeometry(0.66, 0.045, 0.035), | |
| materials.iron, | |
| [0, 1.27, 1.235], | |
| tower, | |
| "Iron crossbar" | |
| ); | |
| const handle = addMesh( | |
| new THREE.SphereGeometry(0.055, 12, 8), | |
| materials.iron, | |
| [0.25, 1.35, 1.28], | |
| tower, | |
| "Door handle" | |
| ); | |
| // Alternating corner quoins | |
| for (const x of [-1.24, 1.24]) { | |
| for (const z of [-1.02, 1.02]) { | |
| for (let row = 0; row < 6; row++) { | |
| const material = (row + (x > 0 ? 1 : 0)) % 2 === 0 | |
| ? materials.stoneLight | |
| : materials.stone; | |
| addMesh( | |
| new THREE.BoxGeometry(0.3, 0.36, 0.3), | |
| material, | |
| [x, 1.08 + row * 0.42, z], | |
| tower, | |
| `Corner quoin ${x > 0 ? "right" : "left"}` | |
| ); | |
| } | |
| } | |
| } | |
| // Side buttresses | |
| for (const x of [-1.45, 1.45]) { | |
| addMesh( | |
| new THREE.BoxGeometry(0.28, 2.9, 2.45), | |
| materials.stoneDark, | |
| [x, 2.55, 0], | |
| tower, | |
| "Side buttress" | |
| ); | |
| } | |
| // Parapet walkway | |
| addMesh( | |
| new THREE.BoxGeometry(2.8, 0.24, 2.5), | |
| materials.stoneLight, | |
| [0, 4.72, 0], | |
| tower, | |
| "Top parapet walkway" | |
| ); | |
| // Front and back crenellations | |
| for (const z of [-1.18, 1.18]) { | |
| for (let i = 0; i < 5; i++) { | |
| const x = -1.05 + i * 0.42; | |
| addMesh( | |
| new THREE.BoxGeometry(0.68, 0.7, 0.46), | |
| materials.stone, | |
| [x, 5.12, z], | |
| tower, | |
| `Front/back crenellation ${i + 1}` | |
| ); | |
| } | |
| } | |
| // Side crenellations | |
| for (const x of [-1.35, 1.35]) { | |
| for (let i = 0; i < 3; i++) { | |
| const z = -0.72 + i * 0.72; | |
| addMesh( | |
| new THREE.BoxGeometry(0.46, 0.7, 0.68), | |
| materials.stone, | |
| [x, 5.12, z], | |
| tower, | |
| `Side crenellation ${i + 1}` | |
| ); | |
| } | |
| } | |
| // Four small corner turrets | |
| for (const x of [-1.2, 1.2]) { | |
| for (const z of [-1.02, 1.02]) { | |
| addMesh( | |
| new THREE.BoxGeometry(0.55, 1.05, 0.55), | |
| materials.stoneDark, | |
| [x, 5.455, z], | |
| tower, | |
| "Corner turret" | |
| ); | |
| for (let i = 0; i < 3; i++) { | |
| addMesh( | |
| new THREE.BoxGeometry(0.62, 0.55, 0.62), | |
| materials.stone, | |
| [x, 6.1 + i * 0.18, z], | |
| tower, | |
| "Corner turret crenellation" | |
| ); | |
| } | |
| } | |
| } | |
| // Flagpole | |
| const poleBase = 5.89; | |
| const poleHeight = 1.15; | |
| addMesh( | |
| new THREE.CylinderGeometry(0.035, 0.045, poleHeight, 10), | |
| materials.iron, | |
| [0, poleBase + poleHeight / 2, 0], | |
| tower, | |
| "Flagpole" | |
| ); | |
| addMesh( | |
| new THREE.SphereGeometry(0.065, 12, 8), | |
| materials.gold, | |
| [0, poleBase + poleHeight + 0.02, 0], | |
| tower, | |
| "Pole finial" | |
| ); | |
| // Animated flag geometry | |
| const flagWidth = 1.35; | |
| const flagHeight = 1.06; | |
| const flagColumns = 16; | |
| const flagRows = 8; | |
| const flagVertexCount = (flagColumns + 1) * (flagRows + 1); | |
| const flagPositions = new Float32Array(flagVertexCount * 3); | |
| const flagUVs = new Float32Array(flagVertexCount * 2); | |
| const flagIndices = []; | |
| for (let row = 0; row <= flagRows; row++) { | |
| for (let column = 0; column <= flagColumns; column++) { | |
| const vertex = row * (flagColumns + 1) + column; | |
| const u = column / flagColumns; | |
| const v = row / flagRows; | |
| flagPositions[vertex * 3] = u * flagWidth; | |
| flagPositions[vertex * 3 + 1] = v * flagHeight; | |
| flagPositions[vertex * 3 + 2] = 0; | |
| flagUVs[vertex * 2] = u; | |
| flagUVs[vertex * 2 + 1] = v; | |
| } | |
| } | |
| for (let row = 0; row < flagRows; row++) { | |
| for (let column = 0; column < flagColumns; column++) { | |
| const a = row * (flagColumns + 1) + column; | |
| const b = a + 1; | |
| const c = a + flagColumns + 1; | |
| const d = c + 1; | |
| flagIndices.push(a, c, b, b, c, d); | |
| } | |
| } | |
| const flagGeometry = new THREE.BufferGeometry(); | |
| flagGeometry.setAttribute( | |
| "position", | |
| new THREE.BufferAttribute(flagPositions, 3) | |
| ); | |
| flagGeometry.setAttribute( | |
| "uv", | |
| new THREE.BufferAttribute(flagUVs, 2) | |
| ); | |
| flagGeometry.setIndex(flagIndices); | |
| flagGeometry.computeVertexNormals(); | |
| const flag = addMesh( | |
| flagGeometry, | |
| materials.cloth, | |
| [0, 5.98, 0], | |
| tower, | |
| "Waving banner flag" | |
| ); | |
| flag.castShadow = true; | |
| // Small gold emblem attached to the flag | |
| const emblem = addMesh( | |
| new THREE.CircleGeometry(0.115, 20), | |
| materials.gold, | |
| [0.27, 0.63, 0.115], | |
| tower, | |
| "Golden flag emblem" | |
| ); | |
| emblem.castShadow = false; | |
| // Custom orbit camera controls | |
| const target = new THREE.Vector3(0, 3.2, 0); | |
| const spherical = new THREE.Spherical(10.8, 1.24, 0.72); | |
| let dragging = false; | |
| let previousX = 0; | |
| let previousY = 0; | |
| function updateCamera() { | |
| spherical.phi = THREE.MathUtils.clamp(spherical.phi, 0.45, 1.52); | |
| spherical.radius = THREE.MathUtils.clamp(spherical.radius, 6.5, 18); | |
| camera.position.setFromSpherical(spherical).add(target); | |
| camera.lookAt(target); | |
| } | |
| function resetCamera() { | |
| spherical.set(10.8, 1.24, 0.72); | |
| target.set(0, 3.2, 0); | |
| updateCamera(); | |
| } | |
| canvas.addEventListener("pointerdown", (event) => { | |
| dragging = true; | |
| previousX = event.clientX; | |
| previousY = event.clientY; | |
| canvas.setPointerCapture(event.pointerId); | |
| canvas.classList.add("dragging"); | |
| }); | |
| canvas.addEventListener("pointermove", (event) => { | |
| if (!dragging) return; | |
| const deltaX = event.clientX - previousX; | |
| const deltaY = event.clientY - previousY; | |
| previousX = event.clientX; | |
| previousY = event.clientY; | |
| spherical.theta -= deltaX * 0.006; | |
| spherical.phi -= deltaY * 0.005; | |
| updateCamera(); | |
| }); | |
| function stopDragging(event) { | |
| dragging = false; | |
| canvas.classList.remove("dragging"); | |
| if (event && canvas.hasPointerCapture(event.pointerId)) { | |
| canvas.releasePointerCapture(event.pointerId); | |
| } | |
| } | |
| canvas.addEventListener("pointerup", stopDragging); | |
| canvas.addEventListener("pointercancel", stopDragging); | |
| canvas.addEventListener("contextmenu", (event) => event.preventDefault()); | |
| canvas.addEventListener("wheel", (event) => { | |
| event.preventDefault(); | |
| spherical.radius *= Math.exp(event.deltaY * 0.001); | |
| updateCamera(); | |
| }, { passive: false }); | |
| canvas.addEventListener("dblclick", resetCamera); | |
| // Turntable and pause controls | |
| let autoRotate = true; | |
| function toggleTurntable() { | |
| autoRotate = !autoRotate; | |
| turntableButton.textContent = autoRotate ? "Pause turntable" : "Resume turntable"; | |
| turntableButton.setAttribute("aria-pressed", String(!autoRotate)); | |
| } | |
| turntableButton.addEventListener("click", toggleTurntable); | |
| window.addEventListener("keydown", (event) => { | |
| if (event.code === "Space") { | |
| event.preventDefault(); | |
| toggleTurntable(); | |
| } | |
| if (event.code === "KeyR") { | |
| resetCamera(); | |
| } | |
| }); | |
| 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 | |
| const clock = new THREE.Clock(); | |
| let elapsed = 0; | |
| renderer.setAnimationLoop(() => { | |
| const delta = Math.min(clock.getDelta(), 0.05); | |
| elapsed += delta; | |
| if (autoRotate) { | |
| turntable.rotation.y += delta * 0.105; | |
| } | |
| // Update the flag's vertices each frame | |
| const positions = flagGeometry.attributes.position; | |
| for (let vertex = 0; vertex < flagVertexCount; vertex++) { | |
| const x = positions.getX(vertex); | |
| const y = positions.getY(vertex); | |
| const normalizedY = y / flagHeight; | |
| const wave = | |
| Math.sin(x * 4.2 - elapsed * 2.35) * 0.21 * normalizedY + | |
| Math.sin((x + flagWidth / 2) * 6.0 - elapsed * 3.1) * | |
| 0.075 * | |
| normalizedY; | |
| positions.setZ(vertex, wave); | |
| } | |
| positions.needsUpdate = true; | |
| flagGeometry.computeVertexNormals(); | |
| renderer.render(scene, camera); | |
| }); | |
| resetCamera(); | |
| </script> | |
| </body> | |
| </html> | |