Datasets:
Add five 3D assets written by Qwen3.5-4B-3D-Coder-OptiQ-4bit, as GLB plus source HTML
Browse files- .gitattributes +4 -0
- README.md +59 -0
- assets/cannon.glb +3 -0
- assets/golem.glb +3 -0
- assets/potions.glb +3 -0
- assets/tower.glb +3 -0
- assets/voxel-goblin.glb +0 -0
- source/cannon.html +800 -0
- source/cannon.png +3 -0
- source/golem-front.png +3 -0
- source/golem-side.png +3 -0
- source/golem.html +898 -0
- source/potions.html +677 -0
- source/potions.png +3 -0
- source/tower.html +732 -0
- source/tower.png +3 -0
- source/voxel-goblin.html +768 -0
- source/voxel-goblin.png +3 -0
.gitattributes
CHANGED
|
@@ -58,3 +58,7 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 58 |
# Video files - compressed
|
| 59 |
*.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 60 |
*.webm filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
# Video files - compressed
|
| 59 |
*.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 60 |
*.webm filter=lfs diff=lfs merge=lfs -text
|
| 61 |
+
assets/cannon.glb filter=lfs diff=lfs merge=lfs -text
|
| 62 |
+
assets/golem.glb filter=lfs diff=lfs merge=lfs -text
|
| 63 |
+
assets/potions.glb filter=lfs diff=lfs merge=lfs -text
|
| 64 |
+
assets/tower.glb filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
pretty_name: OptiQ 3D Coder assets
|
| 4 |
+
tags:
|
| 5 |
+
- 3d
|
| 6 |
+
- glb
|
| 7 |
+
- gltf
|
| 8 |
+
- three.js
|
| 9 |
+
- game-assets
|
| 10 |
+
- mlx
|
| 11 |
+
- optiq
|
| 12 |
+
- apple-silicon
|
| 13 |
+
size_categories:
|
| 14 |
+
- n<1K
|
| 15 |
+
---
|
| 16 |
+
|
| 17 |
+
# OptiQ 3D Coder assets
|
| 18 |
+
|
| 19 |
+
Five game-style 3D assets written by [mlx-community/Qwen3.5-4B-3D-Coder-OptiQ-4bit](https://huggingface.co/mlx-community/Qwen3.5-4B-3D-Coder-OptiQ-4bit), a 4B model running locally on a Mac (M4, 24 GB). The model writes each asset as a single-file Three.js HTML scene. That code is unedited. The `.glb` files in `assets/` were exported from those generated scenes in a headless browser, so they can be viewed in the gallery here or dropped into a game engine.
|
| 20 |
+
|
| 21 |
+
## Assets
|
| 22 |
+
|
| 23 |
+
| Asset | GLB | Source | Prompt | Tokens |
|
| 24 |
+
|---|---|---|---|---:|
|
| 25 |
+
| Stone golem boss | [golem.glb](assets/golem.glb) | [HTML](source/golem.html), [front](source/golem-front.png), [side](source/golem-side.png) | Please create one self-contained HTML file with Three.js from cdnjs showing a stone golem boss with glowing green crystals growing from its shoulders. Make it a single game-ready asset: centred on a plain ground plane, a clear readable silhouette, built from separate named meshes, slowly turning on a turntable, with mouse orbit controls. | 10,771 |
|
| 26 |
+
| Pirate deck cannon | [cannon.glb](assets/cannon.glb) | [HTML](source/cannon.html), [PNG](source/cannon.png) | Please create one self-contained HTML file with Three.js from cdnjs showing a pirate deck cannon on a wooden carriage with a stack of cannonballs. Make it a single game-ready asset: centred on a plain ground plane, a clear readable silhouette, built from separate named meshes, slowly turning on a turntable, with mouse orbit controls. | 14,269 |
|
| 27 |
+
| Potion set | [potions.glb](assets/potions.glb) | [HTML](source/potions.html), [PNG](source/potions.png) | Please create one self-contained HTML file with Three.js from cdnjs showing a set of three potion bottles, red, blue and green, with corks, on a small wooden tray. Make it a single game-ready asset: centred on a plain ground plane, a clear readable silhouette, built from separate named meshes, slowly turning on a turntable, with mouse orbit controls. | 12,802 |
|
| 28 |
+
| Voxel swamp goblin | [voxel-goblin.glb](assets/voxel-goblin.glb) | [HTML](source/voxel-goblin.html), [PNG](source/voxel-goblin.png) | Please create one self-contained HTML file with Three.js from cdnjs showing a swamp goblin enemy with big ears, a leather vest and a spiked wooden club. Render it as a deliberate 3D voxel model built from visible cubic blocks, with clear depth, readable silhouettes, and solid spatial relationships. Make it a single game-ready asset centred on a plain ground plane, slowly turning on a turntable, with mouse orbit controls. | 20,079 |
|
| 29 |
+
| Castle guard tower | [tower.glb](assets/tower.glb) | [HTML](source/tower.html), [PNG](source/tower.png) | Please create one self-contained HTML file with Three.js from cdnjs showing a medieval castle guard tower module with battlements, a wooden door and a flag waving at the top. Make it a single game-ready asset: centred on a plain ground plane, a clear readable silhouette, built from separate named meshes, slowly turning on a turntable, with mouse orbit controls. | 14,070 |
|
| 30 |
+
|
| 31 |
+
Token counts include the model's reasoning. Each run used this system prompt from the base model's author:
|
| 32 |
+
|
| 33 |
+
```text
|
| 34 |
+
Use only the Three.js core ES module from
|
| 35 |
+
https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js.
|
| 36 |
+
Do not import addons or legacy examples/js paths;
|
| 37 |
+
implement any camera controls directly inside the HTML.
|
| 38 |
+
```
|
| 39 |
+
|
| 40 |
+
Settings: temperature 0.6, top_p 0.95, top_k 20, no repetition penalty, `max_tokens` 64000, thinking on, seeded.
|
| 41 |
+
|
| 42 |
+
## Notes
|
| 43 |
+
|
| 44 |
+
- **These are picks, not a typical sample.** Of 18 attempts, 11 rendered in the browser, 3 crashed on load and 4 looped in reasoning until the 64k token cap. These five were chosen from the 11 that rendered.
|
| 45 |
+
- **They aren't flawless.** The potions have no visible corks, the goblin's ears are flat from the side, and the tower's battlements are oversized.
|
| 46 |
+
- **The GLBs are exports of the rendered scenes.** Each was exported with Three.js r160's `GLTFExporter` after the scene had built. The large ground plane, lights, fog, background and the golem's floating dust particles were left out, and animation is not included, so each file is the static asset. Materials are simplified in the conversion: glow, shadows and some non-standard materials won't look exactly as they do in the original page. Open the HTML in `source/` to see the scene as the model wrote it.
|
| 47 |
+
|
| 48 |
+
## Run the model
|
| 49 |
+
|
| 50 |
+
```bash
|
| 51 |
+
pip install mlx-optiq
|
| 52 |
+
optiq serve --model mlx-community/Qwen3.5-4B-3D-Coder-OptiQ-4bit
|
| 53 |
+
```
|
| 54 |
+
|
| 55 |
+
[OptiQ](https://mlx-optiq.com/?utm_source=huggingface&utm_medium=dataset&utm_campaign=3d_assets) is a free MLX toolkit to quantize, fine-tune and serve LLMs locally on Apple Silicon. [OptiQ Code](https://mlx-optiq.com/code?utm_source=huggingface&utm_medium=dataset&utm_campaign=3d_assets) is its coding agent.
|
| 56 |
+
|
| 57 |
+
## Credits
|
| 58 |
+
|
| 59 |
+
The base model is [ccore/Qwen3.5-4B-3D-Coder](https://huggingface.co/ccore/Qwen3.5-4B-3D-Coder), a Qwen3.5 4B fine-tune for writing Three.js scenes, released under Apache 2.0. This dataset uses the same license.
|
assets/cannon.glb
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b160a01848479c3e1e79e1f672d2204744e448406f20b7c721b97b6eac426cc6
|
| 3 |
+
size 986292
|
assets/golem.glb
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:3dd12412971e133253e52d7a26c7bf0219e8db74e06bb92a982845057a390b24
|
| 3 |
+
size 125184
|
assets/potions.glb
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:8de4cf391f9d18567600b9ec39254152e644b7eb1031c0cd06c9a143396a2a0a
|
| 3 |
+
size 367828
|
assets/tower.glb
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:91f148fde3ff23cb72f37746c3ce1feb33f80520e8632e688ae868e715b982df
|
| 3 |
+
size 178576
|
assets/voxel-goblin.glb
ADDED
|
Binary file (26.8 kB). View file
|
|
|
source/cannon.html
ADDED
|
@@ -0,0 +1,800 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Pirate Deck Cannon</title>
|
| 7 |
+
<style>
|
| 8 |
+
:root {
|
| 9 |
+
color-scheme: dark;
|
| 10 |
+
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
|
| 11 |
+
"Segoe UI", sans-serif;
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
* {
|
| 15 |
+
box-sizing: border-box;
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
html,
|
| 19 |
+
body {
|
| 20 |
+
width: 100%;
|
| 21 |
+
height: 100%;
|
| 22 |
+
margin: 0;
|
| 23 |
+
overflow: hidden;
|
| 24 |
+
background: #0d1114;
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
#app {
|
| 28 |
+
position: fixed;
|
| 29 |
+
inset: 0;
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
canvas {
|
| 33 |
+
display: block;
|
| 34 |
+
width: 100%;
|
| 35 |
+
height: 100%;
|
| 36 |
+
cursor: grab;
|
| 37 |
+
touch-action: none;
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
canvas:active {
|
| 41 |
+
cursor: grabbing;
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
.title-card {
|
| 45 |
+
position: fixed;
|
| 46 |
+
top: 24px;
|
| 47 |
+
left: 26px;
|
| 48 |
+
z-index: 2;
|
| 49 |
+
max-width: min(390px, calc(100vw - 52px));
|
| 50 |
+
padding: 16px 18px;
|
| 51 |
+
color: #f4e7c9;
|
| 52 |
+
background: linear-gradient(145deg, rgba(24, 20, 15, 0.88), rgba(20, 17, 13, 0.72));
|
| 53 |
+
border: 1px solid rgba(225, 184, 111, 0.35);
|
| 54 |
+
border-radius: 14px;
|
| 55 |
+
box-shadow: 0 14px 40px rgba(0, 0, 0, 0.3);
|
| 56 |
+
backdrop-filter: blur(12px);
|
| 57 |
+
pointer-events: none;
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
.title-card h1 {
|
| 61 |
+
margin: 0 0 5px;
|
| 62 |
+
font-family: Georgia, "Times New Roman", serif;
|
| 63 |
+
font-size: clamp(22px, 3vw, 32px);
|
| 64 |
+
font-weight: 600;
|
| 65 |
+
letter-spacing: 0.025em;
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
.title-card p {
|
| 69 |
+
margin: 0;
|
| 70 |
+
color: #bda887;
|
| 71 |
+
font-size: 13px;
|
| 72 |
+
line-height: 1.45;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
.controls-hint {
|
| 76 |
+
position: fixed;
|
| 77 |
+
right: 22px;
|
| 78 |
+
bottom: 20px;
|
| 79 |
+
z-index: 2;
|
| 80 |
+
padding: 9px 12px;
|
| 81 |
+
color: #c4b291;
|
| 82 |
+
background: rgba(12, 15, 17, 0.68);
|
| 83 |
+
border: 1px solid rgba(255, 255, 255, 0.08);
|
| 84 |
+
border-radius: 999px;
|
| 85 |
+
font-size: 12px;
|
| 86 |
+
letter-spacing: 0.02em;
|
| 87 |
+
pointer-events: none;
|
| 88 |
+
backdrop-filter: blur(8px);
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
@media (max-width: 600px) {
|
| 92 |
+
.title-card {
|
| 93 |
+
top: 14px;
|
| 94 |
+
left: 14px;
|
| 95 |
+
padding: 12px 14px;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
.title-card p {
|
| 99 |
+
display: none;
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
.controls-hint {
|
| 103 |
+
right: 12px;
|
| 104 |
+
bottom: 12px;
|
| 105 |
+
}
|
| 106 |
+
}
|
| 107 |
+
</style>
|
| 108 |
+
</head>
|
| 109 |
+
<body>
|
| 110 |
+
<div id="app"></div>
|
| 111 |
+
|
| 112 |
+
<div class="title-card">
|
| 113 |
+
<h1>Pirate Deck Cannon</h1>
|
| 114 |
+
<p>A turntable-ready cannon mounted on a wooden carriage, with a stacked load of cannonballs.</p>
|
| 115 |
+
</div>
|
| 116 |
+
|
| 117 |
+
<div class="controls-hint">Drag to orbit · Scroll to zoom · Double-click to reset</div>
|
| 118 |
+
|
| 119 |
+
<script type="module">
|
| 120 |
+
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
|
| 121 |
+
|
| 122 |
+
const app = document.getElementById("app");
|
| 123 |
+
|
| 124 |
+
const scene = new THREE.Scene();
|
| 125 |
+
scene.background = new THREE.Color(0x101518);
|
| 126 |
+
scene.fog = new THREE.Fog(0x101518, 17, 42);
|
| 127 |
+
|
| 128 |
+
const camera = new THREE.PerspectiveCamera(
|
| 129 |
+
38,
|
| 130 |
+
window.innerWidth / window.innerHeight,
|
| 131 |
+
0.1,
|
| 132 |
+
100
|
| 133 |
+
);
|
| 134 |
+
|
| 135 |
+
const renderer = new THREE.WebGLRenderer({
|
| 136 |
+
antialias: true,
|
| 137 |
+
powerPreference: "high-performance"
|
| 138 |
+
});
|
| 139 |
+
|
| 140 |
+
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
|
| 141 |
+
renderer.setSize(window.innerWidth, window.innerHeight);
|
| 142 |
+
renderer.outputColorSpace = THREE.SRGBColorSpace;
|
| 143 |
+
renderer.toneMapping = THREE.ACESFilmicToneMapping;
|
| 144 |
+
renderer.toneMappingExposure = 1.08;
|
| 145 |
+
renderer.shadowMap.enabled = true;
|
| 146 |
+
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
|
| 147 |
+
renderer.domElement.setAttribute("aria-label", "Interactive 3D pirate deck cannon");
|
| 148 |
+
app.appendChild(renderer.domElement);
|
| 149 |
+
|
| 150 |
+
// Lighting
|
| 151 |
+
scene.add(new THREE.HemisphereLight(0xb8c9d3, 0x3a2618, 1.65));
|
| 152 |
+
|
| 153 |
+
const keyLight = new THREE.DirectionalLight(0xffe0ad, 3.2);
|
| 154 |
+
keyLight.position.set(5.5, 9, 6.5);
|
| 155 |
+
keyLight.castShadow = true;
|
| 156 |
+
keyLight.shadow.mapSize.set(2048, 2048);
|
| 157 |
+
keyLight.shadow.camera.left = -7;
|
| 158 |
+
keyLight.shadow.camera.right = 7;
|
| 159 |
+
keyLight.shadow.camera.top = 7;
|
| 160 |
+
keyLight.shadow.camera.bottom = -7;
|
| 161 |
+
keyLight.shadow.camera.near = 1;
|
| 162 |
+
keyLight.shadow.camera.far = 25;
|
| 163 |
+
keyLight.shadow.bias = -0.00035;
|
| 164 |
+
scene.add(keyLight);
|
| 165 |
+
|
| 166 |
+
const rimLight = new THREE.DirectionalLight(0x769ab4, 1.35);
|
| 167 |
+
rimLight.position.set(-6, 5, -5);
|
| 168 |
+
scene.add(rimLight);
|
| 169 |
+
|
| 170 |
+
const warmFill = new THREE.PointLight(0xd78b42, 22, 12, 2);
|
| 171 |
+
warmFill.position.set(2.5, 3.5, 3.5);
|
| 172 |
+
scene.add(warmFill);
|
| 173 |
+
|
| 174 |
+
// Deterministic procedural wood texture.
|
| 175 |
+
function createWoodTexture() {
|
| 176 |
+
const canvas = document.createElement("canvas");
|
| 177 |
+
canvas.width = 512;
|
| 178 |
+
canvas.height = 512;
|
| 179 |
+
const ctx = canvas.getContext("2d");
|
| 180 |
+
|
| 181 |
+
ctx.fillStyle = "#704327";
|
| 182 |
+
ctx.fillRect(0, 0, 512, 512);
|
| 183 |
+
|
| 184 |
+
let seed = 9137;
|
| 185 |
+
const random = () => {
|
| 186 |
+
seed = (seed * 16807) % 2147483647;
|
| 187 |
+
return (seed - 1) / 2147483646;
|
| 188 |
+
};
|
| 189 |
+
|
| 190 |
+
for (let y = -10; y < 530; y += 3) {
|
| 191 |
+
const amplitude = 2 + random() * 8;
|
| 192 |
+
const frequency = 0.012 + random() * 0.028;
|
| 193 |
+
const phase = random() * Math.PI * 2;
|
| 194 |
+
|
| 195 |
+
ctx.beginPath();
|
| 196 |
+
for (let x = 0; x <= 520; x += 8) {
|
| 197 |
+
const waveY =
|
| 198 |
+
y +
|
| 199 |
+
Math.sin(x * frequency + phase) * amplitude +
|
| 200 |
+
Math.sin(x * frequency * 0.43 + phase) * amplitude * 0.35;
|
| 201 |
+
if (x === 0) ctx.moveTo(x, waveY);
|
| 202 |
+
else ctx.lineTo(x, waveY);
|
| 203 |
+
}
|
| 204 |
+
|
| 205 |
+
ctx.strokeStyle = `rgba(35, 15, 7, ${0.08 + random() * 0.16})`;
|
| 206 |
+
ctx.lineWidth = 0.5 + random() * 2.2;
|
| 207 |
+
ctx.stroke();
|
| 208 |
+
}
|
| 209 |
+
|
| 210 |
+
for (let i = 0; i < 18; i++) {
|
| 211 |
+
const x = random() * 512;
|
| 212 |
+
const y = random() * 512;
|
| 213 |
+
const rx = 8 + random() * 25;
|
| 214 |
+
const ry = 2 + random() * 7;
|
| 215 |
+
|
| 216 |
+
ctx.beginPath();
|
| 217 |
+
ctx.ellipse(x, y, rx, ry, 0, 0, Math.PI * 2);
|
| 218 |
+
ctx.strokeStyle = "rgba(35, 15, 7, 0.16)";
|
| 219 |
+
ctx.lineWidth = 1.2;
|
| 220 |
+
ctx.stroke();
|
| 221 |
+
}
|
| 222 |
+
|
| 223 |
+
const texture = new THREE.CanvasTexture(canvas);
|
| 224 |
+
texture.colorSpace = THREE.SRGBColorSpace;
|
| 225 |
+
texture.wrapS = THREE.RepeatWrapping;
|
| 226 |
+
texture.wrapT = THREE.RepeatWrapping;
|
| 227 |
+
texture.repeat.set(2, 2);
|
| 228 |
+
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
|
| 229 |
+
return texture;
|
| 230 |
+
}
|
| 231 |
+
|
| 232 |
+
const woodTexture = createWoodTexture();
|
| 233 |
+
|
| 234 |
+
const materials = {
|
| 235 |
+
wood: new THREE.MeshStandardMaterial({
|
| 236 |
+
map: woodTexture,
|
| 237 |
+
color: 0xffffff,
|
| 238 |
+
roughness: 0.82,
|
| 239 |
+
metalness: 0.02
|
| 240 |
+
}),
|
| 241 |
+
darkWood: new THREE.MeshStandardMaterial({
|
| 242 |
+
map: woodTexture,
|
| 243 |
+
color: 0x8b5938,
|
| 244 |
+
roughness: 0.9,
|
| 245 |
+
metalness: 0.01
|
| 246 |
+
}),
|
| 247 |
+
iron: new THREE.MeshStandardMaterial({
|
| 248 |
+
color: 0x252b2d,
|
| 249 |
+
roughness: 0.48,
|
| 250 |
+
metalness: 0.78
|
| 251 |
+
}),
|
| 252 |
+
blackIron: new THREE.MeshStandardMaterial({
|
| 253 |
+
color: 0x101517,
|
| 254 |
+
roughness: 0.58,
|
| 255 |
+
metalness: 0.72
|
| 256 |
+
}),
|
| 257 |
+
steel: new THREE.MeshStandardMaterial({
|
| 258 |
+
color: 0x8b9291,
|
| 259 |
+
roughness: 0.35,
|
| 260 |
+
metalness: 0.9
|
| 261 |
+
}),
|
| 262 |
+
brass: new THREE.MeshStandardMaterial({
|
| 263 |
+
color: 0xb68a45,
|
| 264 |
+
roughness: 0.38,
|
| 265 |
+
metalness: 0.8
|
| 266 |
+
}),
|
| 267 |
+
ball: new THREE.MeshStandardMaterial({
|
| 268 |
+
color: 0x8d918e,
|
| 269 |
+
roughness: 0.42,
|
| 270 |
+
metalness: 0.82
|
| 271 |
+
}),
|
| 272 |
+
ballSeam: new THREE.MeshStandardMaterial({
|
| 273 |
+
color: 0x484d4c,
|
| 274 |
+
roughness: 0.55,
|
| 275 |
+
metalness: 0.68
|
| 276 |
+
}),
|
| 277 |
+
ground: new THREE.MeshStandardMaterial({
|
| 278 |
+
color: 0x252c2d,
|
| 279 |
+
roughness: 0.96,
|
| 280 |
+
metalness: 0.02
|
| 281 |
+
})
|
| 282 |
+
};
|
| 283 |
+
|
| 284 |
+
const model = new THREE.Group();
|
| 285 |
+
model.name = "Pirate deck cannon assembly";
|
| 286 |
+
scene.add(model);
|
| 287 |
+
|
| 288 |
+
const turntable = new THREE.Group();
|
| 289 |
+
turntable.name = "Rotating turntable";
|
| 290 |
+
model.add(turntable);
|
| 291 |
+
|
| 292 |
+
function addMesh(
|
| 293 |
+
geometry,
|
| 294 |
+
material,
|
| 295 |
+
parent,
|
| 296 |
+
position = [0, 0, 0],
|
| 297 |
+
rotation = [0, 0, 0],
|
| 298 |
+
name = "Unnamed mesh"
|
| 299 |
+
) {
|
| 300 |
+
const mesh = new THREE.Mesh(geometry, material);
|
| 301 |
+
mesh.position.set(...position);
|
| 302 |
+
mesh.rotation.set(...rotation);
|
| 303 |
+
mesh.name = name;
|
| 304 |
+
mesh.castShadow = true;
|
| 305 |
+
mesh.receiveShadow = true;
|
| 306 |
+
parent.add(mesh);
|
| 307 |
+
return mesh;
|
| 308 |
+
}
|
| 309 |
+
|
| 310 |
+
// Turntable
|
| 311 |
+
addMesh(
|
| 312 |
+
new THREE.CylinderGeometry(2.08, 2.32, 0.24, 64),
|
| 313 |
+
materials.darkWood,
|
| 314 |
+
turntable,
|
| 315 |
+
[0, 0.12, 0],
|
| 316 |
+
[0, 0, 0],
|
| 317 |
+
"Turntable pedestal"
|
| 318 |
+
);
|
| 319 |
+
|
| 320 |
+
addMesh(
|
| 321 |
+
new THREE.CylinderGeometry(2.28, 2.28, 0.16, 64),
|
| 322 |
+
materials.wood,
|
| 323 |
+
turntable,
|
| 324 |
+
[0, 0.32, 0],
|
| 325 |
+
[0, 0, 0],
|
| 326 |
+
"Turntable deck"
|
| 327 |
+
);
|
| 328 |
+
|
| 329 |
+
addMesh(
|
| 330 |
+
new THREE.TorusGeometry(2.19, 0.035, 10, 80),
|
| 331 |
+
materials.brass,
|
| 332 |
+
turntable,
|
| 333 |
+
[0, 0.415, 0],
|
| 334 |
+
[Math.PI / 2, 0, 0],
|
| 335 |
+
"Turntable brass rim"
|
| 336 |
+
);
|
| 337 |
+
|
| 338 |
+
// Wooden carriage
|
| 339 |
+
const carriage = new THREE.Group();
|
| 340 |
+
carriage.name = "Wooden carriage";
|
| 341 |
+
model.add(carriage);
|
| 342 |
+
|
| 343 |
+
addMesh(
|
| 344 |
+
new THREE.BoxGeometry(4.8, 0.28, 3.2),
|
| 345 |
+
materials.wood,
|
| 346 |
+
carriage,
|
| 347 |
+
[0, 0.6, 0],
|
| 348 |
+
[0, 0, 0],
|
| 349 |
+
"Carriage deck"
|
| 350 |
+
);
|
| 351 |
+
|
| 352 |
+
addMesh(
|
| 353 |
+
new THREE.BoxGeometry(4.95, 0.13, 3.34),
|
| 354 |
+
materials.darkWood,
|
| 355 |
+
carriage,
|
| 356 |
+
[0, 0.78, 0],
|
| 357 |
+
[0, 0, 0],
|
| 358 |
+
"Carriage top rail"
|
| 359 |
+
);
|
| 360 |
+
|
| 361 |
+
for (const z of [-1.48, 1.48]) {
|
| 362 |
+
addMesh(
|
| 363 |
+
new THREE.BoxGeometry(4.85, 0.24, 0.18),
|
| 364 |
+
materials.darkWood,
|
| 365 |
+
carriage,
|
| 366 |
+
[0, 0.84, z],
|
| 367 |
+
[0, 0, 0],
|
| 368 |
+
"Carriage side rail"
|
| 369 |
+
);
|
| 370 |
+
}
|
| 371 |
+
|
| 372 |
+
for (const x of [-1.72, 1.72]) {
|
| 373 |
+
addMesh(
|
| 374 |
+
new THREE.BoxGeometry(0.22, 0.25, 2.85),
|
| 375 |
+
materials.darkWood,
|
| 376 |
+
carriage,
|
| 377 |
+
[x, 0.79, 0],
|
| 378 |
+
[0, 0, 0],
|
| 379 |
+
"Carriage cross brace"
|
| 380 |
+
);
|
| 381 |
+
}
|
| 382 |
+
|
| 383 |
+
for (const x of [-2.02, 2.02]) {
|
| 384 |
+
addMesh(
|
| 385 |
+
new THREE.BoxGeometry(0.2, 0.22, 2.9),
|
| 386 |
+
materials.darkWood,
|
| 387 |
+
carriage,
|
| 388 |
+
[x, 0.78, 0],
|
| 389 |
+
[0, 0, 0],
|
| 390 |
+
"Carriage end brace"
|
| 391 |
+
);
|
| 392 |
+
}
|
| 393 |
+
|
| 394 |
+
// Deck bolts
|
| 395 |
+
for (const x of [-1.9, -0.95, 0.1, 1.15, 2.1]) {
|
| 396 |
+
for (const z of [-1.48, 1.48]) {
|
| 397 |
+
addMesh(
|
| 398 |
+
new THREE.CylinderGeometry(0.055, 0.055, 0.035, 12),
|
| 399 |
+
materials.brass,
|
| 400 |
+
carriage,
|
| 401 |
+
[x, 0.865, z],
|
| 402 |
+
[0, 0, 0],
|
| 403 |
+
"Carriage bolt"
|
| 404 |
+
);
|
| 405 |
+
}
|
| 406 |
+
}
|
| 407 |
+
|
| 408 |
+
// Four wooden carriage wheels
|
| 409 |
+
function createWheel(x, z, facing) {
|
| 410 |
+
const wheel = new THREE.Group();
|
| 411 |
+
wheel.name = "Carriage wheel";
|
| 412 |
+
wheel.position.set(x, 0.57, z);
|
| 413 |
+
carriage.add(wheel);
|
| 414 |
+
|
| 415 |
+
addMesh(
|
| 416 |
+
new THREE.CylinderGeometry(0.55, 0.55, 0.34, 32),
|
| 417 |
+
materials.darkWood,
|
| 418 |
+
wheel,
|
| 419 |
+
[0, 0, 0],
|
| 420 |
+
[Math.PI / 2, 0, 0],
|
| 421 |
+
"Wheel rim"
|
| 422 |
+
);
|
| 423 |
+
|
| 424 |
+
addMesh(
|
| 425 |
+
new THREE.TorusGeometry(0.45, 0.075, 8, 36),
|
| 426 |
+
materials.wood,
|
| 427 |
+
wheel,
|
| 428 |
+
[0, 0, 0],
|
| 429 |
+
[0, 0, 0],
|
| 430 |
+
"Wheel outer rim"
|
| 431 |
+
);
|
| 432 |
+
|
| 433 |
+
addMesh(
|
| 434 |
+
new THREE.CylinderGeometry(0.19, 0.19, 0.4, 20),
|
| 435 |
+
materials.iron,
|
| 436 |
+
wheel,
|
| 437 |
+
[0, 0, 0],
|
| 438 |
+
[Math.PI / 2, 0, 0],
|
| 439 |
+
"Wheel hub"
|
| 440 |
+
);
|
| 441 |
+
|
| 442 |
+
const spokeZ = facing * 0.18;
|
| 443 |
+
for (let i = 0; i < 6; i++) {
|
| 444 |
+
const angle = (i / 6) * Math.PI * 2;
|
| 445 |
+
addMesh(
|
| 446 |
+
new THREE.BoxGeometry(1.02, 0.09, 0.065),
|
| 447 |
+
materials.wood,
|
| 448 |
+
wheel,
|
| 449 |
+
[Math.cos(angle) * 0.39, Math.sin(angle) * 0.39, spokeZ],
|
| 450 |
+
[0, 0, angle],
|
| 451 |
+
"Carriage wheel spoke"
|
| 452 |
+
);
|
| 453 |
+
}
|
| 454 |
+
}
|
| 455 |
+
|
| 456 |
+
createWheel(-1.72, -1.38, -1);
|
| 457 |
+
createWheel(1.72, -1.38, -1);
|
| 458 |
+
createWheel(-1.72, 1.38, 1);
|
| 459 |
+
createWheel(1.72, 1.38, 1);
|
| 460 |
+
|
| 461 |
+
// Deck cannon
|
| 462 |
+
const cannon = new THREE.Group();
|
| 463 |
+
cannon.name = "Iron deck cannon";
|
| 464 |
+
model.add(cannon);
|
| 465 |
+
|
| 466 |
+
// Barrel support cheeks
|
| 467 |
+
for (const z of [-0.5, 0.5]) {
|
| 468 |
+
addMesh(
|
| 469 |
+
new THREE.BoxGeometry(0.52, 0.34, 0.25),
|
| 470 |
+
materials.iron,
|
| 471 |
+
cannon,
|
| 472 |
+
[-0.18, 1.19, z],
|
| 473 |
+
[0, 0, 0],
|
| 474 |
+
"Cannon cheek block"
|
| 475 |
+
);
|
| 476 |
+
}
|
| 477 |
+
|
| 478 |
+
// Trunnion
|
| 479 |
+
addMesh(
|
| 480 |
+
new THREE.CylinderGeometry(0.28, 0.33, 0.55, 24),
|
| 481 |
+
materials.iron,
|
| 482 |
+
cannon,
|
| 483 |
+
[-0.62, 1.34, 0],
|
| 484 |
+
[0, 0, Math.PI / 2],
|
| 485 |
+
"Cannon trunnion"
|
| 486 |
+
);
|
| 487 |
+
|
| 488 |
+
// Main barrel, tapering toward the muzzle
|
| 489 |
+
addMesh(
|
| 490 |
+
new THREE.CylinderGeometry(0.19, 0.34, 2.65, 28),
|
| 491 |
+
materials.iron,
|
| 492 |
+
cannon,
|
| 493 |
+
[0.85, 1.31, 0],
|
| 494 |
+
[0, 0, -Math.PI / 2],
|
| 495 |
+
"Cannon barrel"
|
| 496 |
+
);
|
| 497 |
+
|
| 498 |
+
// Barrel bands
|
| 499 |
+
addMesh(
|
| 500 |
+
new THREE.TorusGeometry(0.345, 0.045, 8, 36),
|
| 501 |
+
materials.iron,
|
| 502 |
+
cannon,
|
| 503 |
+
[-0.49, 1.31, 0],
|
| 504 |
+
[0, Math.PI / 2, 0],
|
| 505 |
+
"Rear barrel band"
|
| 506 |
+
);
|
| 507 |
+
|
| 508 |
+
addMesh(
|
| 509 |
+
new THREE.TorusGeometry(0.315, 0.04, 8, 36),
|
| 510 |
+
materials.iron,
|
| 511 |
+
cannon,
|
| 512 |
+
[0.12, 1.31, 0],
|
| 513 |
+
[0, Math.PI / 2, 0],
|
| 514 |
+
"Middle barrel band"
|
| 515 |
+
);
|
| 516 |
+
|
| 517 |
+
addMesh(
|
| 518 |
+
new THREE.TorusGeometry(0.225, 0.045, 8, 36),
|
| 519 |
+
materials.iron,
|
| 520 |
+
cannon,
|
| 521 |
+
[2.19, 1.31, 0],
|
| 522 |
+
[0, Math.PI / 2, 0],
|
| 523 |
+
"Muzzle barrel band"
|
| 524 |
+
);
|
| 525 |
+
|
| 526 |
+
// Dark bore and muzzle lip
|
| 527 |
+
addMesh(
|
| 528 |
+
new THREE.CylinderGeometry(0.13, 0.16, 0.2, 24),
|
| 529 |
+
materials.blackIron,
|
| 530 |
+
cannon,
|
| 531 |
+
[2.28, 1.31, 0],
|
| 532 |
+
[0, 0, -Math.PI / 2],
|
| 533 |
+
"Cannon bore"
|
| 534 |
+
);
|
| 535 |
+
|
| 536 |
+
addMesh(
|
| 537 |
+
new THREE.TorusGeometry(0.19, 0.025, 8, 32),
|
| 538 |
+
materials.steel,
|
| 539 |
+
cannon,
|
| 540 |
+
[2.31, 1.31, 0],
|
| 541 |
+
[0, Math.PI / 2, 0],
|
| 542 |
+
"Muzzle lip"
|
| 543 |
+
);
|
| 544 |
+
|
| 545 |
+
// Rear collar and sight
|
| 546 |
+
addMesh(
|
| 547 |
+
new THREE.CylinderGeometry(0.37, 0.37, 0.18, 24),
|
| 548 |
+
materials.iron,
|
| 549 |
+
cannon,
|
| 550 |
+
[-0.72, 1.34, 0],
|
| 551 |
+
[0, 0, Math.PI / 2],
|
| 552 |
+
"Cannon rear collar"
|
| 553 |
+
);
|
| 554 |
+
|
| 555 |
+
addMesh(
|
| 556 |
+
new THREE.BoxGeometry(0.18, 0.13, 0.12),
|
| 557 |
+
materials.brass,
|
| 558 |
+
cannon,
|
| 559 |
+
[-0.56, 1.58, 0.5],
|
| 560 |
+
[0, 0, 0],
|
| 561 |
+
"Front sight"
|
| 562 |
+
);
|
| 563 |
+
|
| 564 |
+
addMesh(
|
| 565 |
+
new THREE.CylinderGeometry(0.055, 0.055, 0.3, 12),
|
| 566 |
+
materials.brass,
|
| 567 |
+
cannon,
|
| 568 |
+
[-0.56, 1.49, 0.5],
|
| 569 |
+
[0, 0, 0],
|
| 570 |
+
"Sight post"
|
| 571 |
+
);
|
| 572 |
+
|
| 573 |
+
// Handle behind the cannon
|
| 574 |
+
for (const z of [-0.28, 0.28]) {
|
| 575 |
+
addMesh(
|
| 576 |
+
new THREE.CylinderGeometry(0.045, 0.045, 0.48, 12),
|
| 577 |
+
materials.iron,
|
| 578 |
+
cannon,
|
| 579 |
+
[-0.92, 1.31, z],
|
| 580 |
+
[0, 0, Math.PI / 2],
|
| 581 |
+
"Handle post"
|
| 582 |
+
);
|
| 583 |
+
}
|
| 584 |
+
|
| 585 |
+
addMesh(
|
| 586 |
+
new THREE.BoxGeometry(0.18, 0.12, 0.72),
|
| 587 |
+
materials.iron,
|
| 588 |
+
cannon,
|
| 589 |
+
[-0.92, 1.56, 0],
|
| 590 |
+
[0, 0, 0],
|
| 591 |
+
"Cannon handle"
|
| 592 |
+
);
|
| 593 |
+
|
| 594 |
+
// Cannonball stack
|
| 595 |
+
const ballStack = new THREE.Group();
|
| 596 |
+
ballStack.name = "Stack of cannonballs";
|
| 597 |
+
model.add(ballStack);
|
| 598 |
+
|
| 599 |
+
const ballPositions = [
|
| 600 |
+
[-2.02, 1.76, 0.95],
|
| 601 |
+
[-1.52, 1.76, 0.95],
|
| 602 |
+
[-1.02, 1.76, 0.95],
|
| 603 |
+
[-1.77, 2.54, 0.95],
|
| 604 |
+
[-1.27, 2.54, 0.95],
|
| 605 |
+
[-1.52, 3.32, 0.95]
|
| 606 |
+
];
|
| 607 |
+
|
| 608 |
+
for (const [x, y, z] of ballPositions) {
|
| 609 |
+
const radius = 0.38;
|
| 610 |
+
|
| 611 |
+
addMesh(
|
| 612 |
+
new THREE.SphereGeometry(radius, 32, 24),
|
| 613 |
+
materials.ball,
|
| 614 |
+
ballStack,
|
| 615 |
+
[x, y, z],
|
| 616 |
+
[0, 0, 0],
|
| 617 |
+
"Cannonball"
|
| 618 |
+
);
|
| 619 |
+
|
| 620 |
+
// Equatorial seam
|
| 621 |
+
addMesh(
|
| 622 |
+
new THREE.TorusGeometry(radius + 0.006, 0.014, 6, 36),
|
| 623 |
+
materials.ballSeam,
|
| 624 |
+
ballStack,
|
| 625 |
+
[x, y, z],
|
| 626 |
+
[Math.PI / 2, 0, 0],
|
| 627 |
+
"Cannonball equatorial seam"
|
| 628 |
+
);
|
| 629 |
+
|
| 630 |
+
// Vertical seam
|
| 631 |
+
addMesh(
|
| 632 |
+
new THREE.TorusGeometry(radius + 0.006, 0.012, 6, 36),
|
| 633 |
+
materials.ballSeam,
|
| 634 |
+
ballStack,
|
| 635 |
+
[x, y, z],
|
| 636 |
+
[0, 0, 0],
|
| 637 |
+
"Cannonball vertical seam"
|
| 638 |
+
);
|
| 639 |
+
}
|
| 640 |
+
|
| 641 |
+
// Small brass carriage plaque
|
| 642 |
+
const plaque = new THREE.Group();
|
| 643 |
+
plaque.name = "Carriage plaque";
|
| 644 |
+
plaque.position.set(0, 0.87, 1.675);
|
| 645 |
+
carriage.add(plaque);
|
| 646 |
+
|
| 647 |
+
addMesh(
|
| 648 |
+
new THREE.BoxGeometry(1.45, 0.28, 0.035),
|
| 649 |
+
materials.brass,
|
| 650 |
+
plaque,
|
| 651 |
+
[0, 0, 0],
|
| 652 |
+
[0, 0, 0],
|
| 653 |
+
"Carriage plaque"
|
| 654 |
+
);
|
| 655 |
+
|
| 656 |
+
addMesh(
|
| 657 |
+
new THREE.BoxGeometry(0.34, 0.035, 0.012),
|
| 658 |
+
materials.iron,
|
| 659 |
+
plaque,
|
| 660 |
+
[-0.38, 0, 0.025],
|
| 661 |
+
[0, 0, 0],
|
| 662 |
+
"Plaque inset"
|
| 663 |
+
);
|
| 664 |
+
|
| 665 |
+
// Plain ground plane
|
| 666 |
+
const ground = addMesh(
|
| 667 |
+
new THREE.PlaneGeometry(100, 100),
|
| 668 |
+
materials.ground,
|
| 669 |
+
scene,
|
| 670 |
+
[0, 0, 0],
|
| 671 |
+
[-Math.PI / 2, 0, 0],
|
| 672 |
+
"Plain ground plane"
|
| 673 |
+
);
|
| 674 |
+
ground.castShadow = false;
|
| 675 |
+
|
| 676 |
+
// Custom orbit controls implemented without external addons.
|
| 677 |
+
const cameraTarget = new THREE.Vector3(0, 1.35, 0);
|
| 678 |
+
const desired = {
|
| 679 |
+
theta: 0.72,
|
| 680 |
+
phi: 1.08,
|
| 681 |
+
radius: 10.6
|
| 682 |
+
};
|
| 683 |
+
const current = {
|
| 684 |
+
theta: desired.theta,
|
| 685 |
+
phi: desired.phi,
|
| 686 |
+
radius: desired.radius
|
| 687 |
+
};
|
| 688 |
+
|
| 689 |
+
let dragging = false;
|
| 690 |
+
let previousX = 0;
|
| 691 |
+
let previousY = 0;
|
| 692 |
+
|
| 693 |
+
function updateCamera() {
|
| 694 |
+
current.theta += (desired.theta - current.theta) * 0.08;
|
| 695 |
+
current.phi += (desired.phi - current.phi) * 0.08;
|
| 696 |
+
current.radius += (desired.radius - current.radius) * 0.08;
|
| 697 |
+
|
| 698 |
+
const sinPhi = Math.sin(current.phi);
|
| 699 |
+
camera.position.set(
|
| 700 |
+
cameraTarget.x + current.radius * sinPhi * Math.sin(current.theta),
|
| 701 |
+
cameraTarget.y + current.radius * Math.cos(current.phi),
|
| 702 |
+
cameraTarget.z + current.radius * sinPhi * Math.cos(current.theta)
|
| 703 |
+
);
|
| 704 |
+
camera.lookAt(cameraTarget);
|
| 705 |
+
}
|
| 706 |
+
|
| 707 |
+
function resetCamera() {
|
| 708 |
+
desired.theta = 0.72;
|
| 709 |
+
desired.phi = 1.08;
|
| 710 |
+
desired.radius = 10.6;
|
| 711 |
+
}
|
| 712 |
+
|
| 713 |
+
renderer.domElement.addEventListener("pointerdown", (event) => {
|
| 714 |
+
dragging = true;
|
| 715 |
+
previousX = event.clientX;
|
| 716 |
+
previousY = event.clientY;
|
| 717 |
+
renderer.domElement.setPointerCapture(event.pointerId);
|
| 718 |
+
});
|
| 719 |
+
|
| 720 |
+
renderer.domElement.addEventListener("pointermove", (event) => {
|
| 721 |
+
if (!dragging) return;
|
| 722 |
+
|
| 723 |
+
const deltaX = event.clientX - previousX;
|
| 724 |
+
const deltaY = event.clientY - previousY;
|
| 725 |
+
previousX = event.clientX;
|
| 726 |
+
previousY = event.clientY;
|
| 727 |
+
|
| 728 |
+
desired.theta -= deltaX * 0.006;
|
| 729 |
+
desired.phi = THREE.MathUtils.clamp(
|
| 730 |
+
desired.phi - deltaY * 0.005,
|
| 731 |
+
0.34,
|
| 732 |
+
1.48
|
| 733 |
+
);
|
| 734 |
+
});
|
| 735 |
+
|
| 736 |
+
function endDrag(event) {
|
| 737 |
+
dragging = false;
|
| 738 |
+
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
|
| 739 |
+
renderer.domElement.releasePointerCapture(event.pointerId);
|
| 740 |
+
}
|
| 741 |
+
}
|
| 742 |
+
|
| 743 |
+
renderer.domElement.addEventListener("pointerup", endDrag);
|
| 744 |
+
renderer.domElement.addEventListener("pointercancel", endDrag);
|
| 745 |
+
renderer.domElement.addEventListener("contextmenu", (event) => event.preventDefault());
|
| 746 |
+
|
| 747 |
+
renderer.domElement.addEventListener(
|
| 748 |
+
"wheel",
|
| 749 |
+
(event) => {
|
| 750 |
+
event.preventDefault();
|
| 751 |
+
desired.radius = THREE.MathUtils.clamp(
|
| 752 |
+
desired.radius * Math.exp(event.deltaY * 0.001),
|
| 753 |
+
5.5,
|
| 754 |
+
18
|
| 755 |
+
);
|
| 756 |
+
},
|
| 757 |
+
{ passive: false }
|
| 758 |
+
);
|
| 759 |
+
|
| 760 |
+
renderer.domElement.addEventListener("dblclick", resetCamera);
|
| 761 |
+
|
| 762 |
+
window.addEventListener("keydown", (event) => {
|
| 763 |
+
if (event.key === "ArrowLeft") desired.theta += 0.12;
|
| 764 |
+
if (event.key === "ArrowRight") desired.theta -= 0.12;
|
| 765 |
+
if (event.key === "ArrowUp") desired.phi = Math.max(0.34, desired.phi - 0.08);
|
| 766 |
+
if (event.key === "ArrowDown") desired.phi = Math.min(1.48, desired.phi + 0.08);
|
| 767 |
+
if (event.key === "+" || event.key === "=") desired.radius = Math.max(5.5, desired.radius - 0.5);
|
| 768 |
+
if (event.key === "-") desired.radius = Math.min(18, desired.radius + 0.5);
|
| 769 |
+
});
|
| 770 |
+
|
| 771 |
+
window.addEventListener("resize", () => {
|
| 772 |
+
camera.aspect = window.innerWidth / window.innerHeight;
|
| 773 |
+
camera.updateProjectionMatrix();
|
| 774 |
+
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
|
| 775 |
+
renderer.setSize(window.innerWidth, window.innerHeight);
|
| 776 |
+
});
|
| 777 |
+
|
| 778 |
+
const reducedMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
| 779 |
+
const turntableSpeed = reducedMotion ? 0.035 : 0.22;
|
| 780 |
+
const initialTurn = reducedMotion ? 0 : -0.28;
|
| 781 |
+
let elapsed = 0;
|
| 782 |
+
|
| 783 |
+
const clock = new THREE.Clock();
|
| 784 |
+
|
| 785 |
+
function animate() {
|
| 786 |
+
requestAnimationFrame(animate);
|
| 787 |
+
|
| 788 |
+
const delta = Math.min(clock.getDelta(), 0.05);
|
| 789 |
+
elapsed += delta;
|
| 790 |
+
|
| 791 |
+
turntable.rotation.y = initialTurn + elapsed * turntableSpeed;
|
| 792 |
+
updateCamera();
|
| 793 |
+
renderer.render(scene, camera);
|
| 794 |
+
}
|
| 795 |
+
|
| 796 |
+
updateCamera();
|
| 797 |
+
animate();
|
| 798 |
+
</script>
|
| 799 |
+
</body>
|
| 800 |
+
</html>
|
source/cannon.png
ADDED
|
Git LFS Details
|
source/golem-front.png
ADDED
|
Git LFS Details
|
source/golem-side.png
ADDED
|
Git LFS Details
|
source/golem.html
ADDED
|
@@ -0,0 +1,898 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8" />
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 6 |
+
<title>Stone Golem Boss</title>
|
| 7 |
+
|
| 8 |
+
<style>
|
| 9 |
+
:root {
|
| 10 |
+
color-scheme: dark;
|
| 11 |
+
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
|
| 12 |
+
"Segoe UI", sans-serif;
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
* {
|
| 16 |
+
box-sizing: border-box;
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
html,
|
| 20 |
+
body {
|
| 21 |
+
width: 100%;
|
| 22 |
+
height: 100%;
|
| 23 |
+
margin: 0;
|
| 24 |
+
overflow: hidden;
|
| 25 |
+
background:
|
| 26 |
+
radial-gradient(circle at 50% 35%, #172126 0%, #080c0e 48%, #030506 100%);
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
#stage {
|
| 30 |
+
position: fixed;
|
| 31 |
+
inset: 0;
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
canvas {
|
| 35 |
+
display: block;
|
| 36 |
+
width: 100%;
|
| 37 |
+
height: 100%;
|
| 38 |
+
touch-action: none;
|
| 39 |
+
cursor: grab;
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
canvas:active {
|
| 43 |
+
cursor: grabbing;
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
.hud {
|
| 47 |
+
position: fixed;
|
| 48 |
+
z-index: 10;
|
| 49 |
+
pointer-events: none;
|
| 50 |
+
user-select: none;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
.title {
|
| 54 |
+
top: 28px;
|
| 55 |
+
left: 30px;
|
| 56 |
+
max-width: min(420px, calc(100vw - 60px));
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
.eyebrow {
|
| 60 |
+
margin-bottom: 8px;
|
| 61 |
+
color: #75e58c;
|
| 62 |
+
font-size: 11px;
|
| 63 |
+
font-weight: 700;
|
| 64 |
+
letter-spacing: 0.24em;
|
| 65 |
+
text-transform: uppercase;
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
h1 {
|
| 69 |
+
margin: 0;
|
| 70 |
+
color: #edf4f1;
|
| 71 |
+
font-size: clamp(25px, 4vw, 48px);
|
| 72 |
+
font-weight: 800;
|
| 73 |
+
line-height: 0.98;
|
| 74 |
+
letter-spacing: -0.04em;
|
| 75 |
+
text-transform: uppercase;
|
| 76 |
+
text-shadow: 0 0 30px rgba(47, 225, 116, 0.22);
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
.subtitle {
|
| 80 |
+
margin-top: 12px;
|
| 81 |
+
color: #8d9b9b;
|
| 82 |
+
font-size: 12px;
|
| 83 |
+
line-height: 1.5;
|
| 84 |
+
letter-spacing: 0.06em;
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
.controls {
|
| 88 |
+
right: 24px;
|
| 89 |
+
bottom: 24px;
|
| 90 |
+
display: flex;
|
| 91 |
+
align-items: center;
|
| 92 |
+
gap: 12px;
|
| 93 |
+
pointer-events: auto;
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
.hint {
|
| 97 |
+
color: #899595;
|
| 98 |
+
font-size: 11px;
|
| 99 |
+
letter-spacing: 0.05em;
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
button {
|
| 103 |
+
border: 1px solid rgba(117, 229, 140, 0.35);
|
| 104 |
+
border-radius: 999px;
|
| 105 |
+
padding: 9px 14px;
|
| 106 |
+
color: #bfe9a3;
|
| 107 |
+
background: rgba(12, 22, 22, 0.72);
|
| 108 |
+
font: inherit;
|
| 109 |
+
font-size: 11px;
|
| 110 |
+
font-weight: 700;
|
| 111 |
+
letter-spacing: 0.08em;
|
| 112 |
+
text-transform: uppercase;
|
| 113 |
+
cursor: pointer;
|
| 114 |
+
backdrop-filter: blur(10px);
|
| 115 |
+
transition: background 160ms ease, border-color 160ms ease, transform 160ms ease;
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
button:hover {
|
| 119 |
+
border-color: rgba(117, 229, 140, 0.75);
|
| 120 |
+
background: rgba(20, 38, 35, 0.88);
|
| 121 |
+
transform: translateY(-1px);
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
.status {
|
| 125 |
+
top: 30px;
|
| 126 |
+
right: 28px;
|
| 127 |
+
display: flex;
|
| 128 |
+
align-items: center;
|
| 129 |
+
gap: 9px;
|
| 130 |
+
color: #7d8b8b;
|
| 131 |
+
font-size: 10px;
|
| 132 |
+
font-weight: 700;
|
| 133 |
+
letter-spacing: 0.16em;
|
| 134 |
+
text-transform: uppercase;
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
.status::before {
|
| 138 |
+
width: 7px;
|
| 139 |
+
height: 7px;
|
| 140 |
+
border-radius: 50%;
|
| 141 |
+
background: #55ff91;
|
| 142 |
+
box-shadow: 0 0 12px #55ff91;
|
| 143 |
+
content: "";
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
#loading {
|
| 147 |
+
position: fixed;
|
| 148 |
+
inset: 0;
|
| 149 |
+
z-index: 20;
|
| 150 |
+
display: grid;
|
| 151 |
+
place-items: center;
|
| 152 |
+
color: #7ce38c;
|
| 153 |
+
background: #070b0c;
|
| 154 |
+
font-size: 11px;
|
| 155 |
+
font-weight: 700;
|
| 156 |
+
letter-spacing: 0.2em;
|
| 157 |
+
text-transform: uppercase;
|
| 158 |
+
transition: opacity 500ms ease;
|
| 159 |
+
}
|
| 160 |
+
|
| 161 |
+
#loading.hidden {
|
| 162 |
+
opacity: 0;
|
| 163 |
+
pointer-events: none;
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
@media (max-width: 620px) {
|
| 167 |
+
.title {
|
| 168 |
+
top: 20px;
|
| 169 |
+
left: 20px;
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
.subtitle {
|
| 173 |
+
max-width: 270px;
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
+
.status {
|
| 177 |
+
display: none;
|
| 178 |
+
}
|
| 179 |
+
|
| 180 |
+
.controls {
|
| 181 |
+
right: 16px;
|
| 182 |
+
bottom: 16px;
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
.hint {
|
| 186 |
+
display: none;
|
| 187 |
+
}
|
| 188 |
+
}
|
| 189 |
+
</style>
|
| 190 |
+
</head>
|
| 191 |
+
|
| 192 |
+
<body>
|
| 193 |
+
<div id="stage"></div>
|
| 194 |
+
|
| 195 |
+
<div class="hud title">
|
| 196 |
+
<div class="eyebrow">Sector 07 · Final Guardian</div>
|
| 197 |
+
<h1>Stone Golem</h1>
|
| 198 |
+
<div class="subtitle">
|
| 199 |
+
An ancient guardian awakened by a surge of corrupted bio-luminescent energy.
|
| 200 |
+
</div>
|
| 201 |
+
</div>
|
| 202 |
+
|
| 203 |
+
<div class="hud status">Turntable active</div>
|
| 204 |
+
|
| 205 |
+
<div class="hud controls">
|
| 206 |
+
<span class="hint">Drag to orbit · Scroll to zoom</span>
|
| 207 |
+
<button id="rotateButton" type="button">Pause rotation</button>
|
| 208 |
+
</div>
|
| 209 |
+
|
| 210 |
+
<div id="loading">Forging the guardian…</div>
|
| 211 |
+
|
| 212 |
+
<script type="module">
|
| 213 |
+
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
|
| 214 |
+
|
| 215 |
+
const stage = document.getElementById("stage");
|
| 216 |
+
const loading = document.getElementById("loading");
|
| 217 |
+
const rotateButton = document.getElementById("rotateButton");
|
| 218 |
+
|
| 219 |
+
// ---------------------------------------------------------------------
|
| 220 |
+
// Renderer and scene
|
| 221 |
+
// ---------------------------------------------------------------------
|
| 222 |
+
|
| 223 |
+
const scene = new THREE.Scene();
|
| 224 |
+
scene.background = new THREE.Color(0x070b0c);
|
| 225 |
+
scene.fog = new THREE.Fog(0x070b0c, 17, 43);
|
| 226 |
+
|
| 227 |
+
const camera = new THREE.PerspectiveCamera(
|
| 228 |
+
42,
|
| 229 |
+
window.innerWidth / window.innerHeight,
|
| 230 |
+
0.1,
|
| 231 |
+
100
|
| 232 |
+
);
|
| 233 |
+
|
| 234 |
+
const renderer = new THREE.WebGLRenderer({
|
| 235 |
+
antialias: true,
|
| 236 |
+
powerPreference: "high-performance"
|
| 237 |
+
});
|
| 238 |
+
|
| 239 |
+
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
|
| 240 |
+
renderer.setSize(window.innerWidth, window.innerHeight);
|
| 241 |
+
renderer.outputColorSpace = THREE.SRGBColorSpace;
|
| 242 |
+
renderer.toneMapping = THREE.ACESFilmicToneMapping;
|
| 243 |
+
renderer.toneMappingExposure = 1.12;
|
| 244 |
+
renderer.shadowMap.enabled = true;
|
| 245 |
+
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
|
| 246 |
+
stage.appendChild(renderer.domElement);
|
| 247 |
+
|
| 248 |
+
const hemi = new THREE.HemisphereLight(0x9ab4c4, 0x17120b, 1.25);
|
| 249 |
+
scene.add(hemi);
|
| 250 |
+
|
| 251 |
+
const keyLight = new THREE.DirectionalLight(0xffe1b0, 3.2);
|
| 252 |
+
keyLight.position.set(6, 11, 8);
|
| 253 |
+
keyLight.castShadow = true;
|
| 254 |
+
keyLight.shadow.mapSize.set(2048, 2048);
|
| 255 |
+
keyLight.shadow.camera.left = -8;
|
| 256 |
+
keyLight.shadow.camera.right = 8;
|
| 257 |
+
keyLight.shadow.camera.top = 10;
|
| 258 |
+
keyLight.shadow.camera.bottom = -4;
|
| 259 |
+
keyLight.shadow.camera.near = 1;
|
| 260 |
+
keyLight.shadow.camera.far = 28;
|
| 261 |
+
keyLight.shadow.bias = -0.0005;
|
| 262 |
+
scene.add(keyLight);
|
| 263 |
+
|
| 264 |
+
const rimLight = new THREE.DirectionalLight(0x43d99a, 2.1);
|
| 265 |
+
rimLight.position.set(-7, 5, -6);
|
| 266 |
+
scene.add(rimLight);
|
| 267 |
+
|
| 268 |
+
const frontFill = new THREE.PointLight(0x677b78, 12, 18, 2);
|
| 269 |
+
frontFill.position.set(0, 4, 7);
|
| 270 |
+
scene.add(frontFill);
|
| 271 |
+
|
| 272 |
+
// ---------------------------------------------------------------------
|
| 273 |
+
// Materials
|
| 274 |
+
// ---------------------------------------------------------------------
|
| 275 |
+
|
| 276 |
+
const stoneMaterial = new THREE.MeshStandardMaterial({
|
| 277 |
+
color: 0x667073,
|
| 278 |
+
roughness: 0.92,
|
| 279 |
+
metalness: 0.08
|
| 280 |
+
});
|
| 281 |
+
|
| 282 |
+
const darkStoneMaterial = new THREE.MeshStandardMaterial({
|
| 283 |
+
color: 0x343d40,
|
| 284 |
+
roughness: 0.98,
|
| 285 |
+
metalness: 0.04
|
| 286 |
+
});
|
| 287 |
+
|
| 288 |
+
const wornStoneMaterial = new THREE.MeshStandardMaterial({
|
| 289 |
+
color: 0x858b87,
|
| 290 |
+
roughness: 0.95,
|
| 291 |
+
metalness: 0.03
|
| 292 |
+
});
|
| 293 |
+
|
| 294 |
+
const armorMaterial = new THREE.MeshStandardMaterial({
|
| 295 |
+
color: 0x414b4d,
|
| 296 |
+
roughness: 0.68,
|
| 297 |
+
metalness: 0.48
|
| 298 |
+
});
|
| 299 |
+
|
| 300 |
+
const ironMaterial = new THREE.MeshStandardMaterial({
|
| 301 |
+
color: 0x20282b,
|
| 302 |
+
roughness: 0.58,
|
| 303 |
+
metalness: 0.72
|
| 304 |
+
});
|
| 305 |
+
|
| 306 |
+
const crackMaterial = new THREE.LineBasicMaterial({
|
| 307 |
+
color: 0x171b1c,
|
| 308 |
+
transparent: true,
|
| 309 |
+
opacity: 0.72
|
| 310 |
+
});
|
| 311 |
+
|
| 312 |
+
const crystalMaterial = new THREE.MeshStandardMaterial({
|
| 313 |
+
color: 0x8dffa5,
|
| 314 |
+
emissive: 0x2dff65,
|
| 315 |
+
emissiveIntensity: 1.7,
|
| 316 |
+
roughness: 0.28,
|
| 317 |
+
metalness: 0.12,
|
| 318 |
+
flatShading: true
|
| 319 |
+
});
|
| 320 |
+
|
| 321 |
+
const crystalCoreMaterial = new THREE.MeshStandardMaterial({
|
| 322 |
+
color: 0xd6ffbf,
|
| 323 |
+
emissive: 0x75ff9d,
|
| 324 |
+
emissiveIntensity: 2.4,
|
| 325 |
+
roughness: 0.2,
|
| 326 |
+
metalness: 0.08,
|
| 327 |
+
flatShading: true
|
| 328 |
+
});
|
| 329 |
+
|
| 330 |
+
const eyeMaterial = new THREE.MeshStandardMaterial({
|
| 331 |
+
color: 0x82e8a3,
|
| 332 |
+
emissive: 0x35ff83,
|
| 333 |
+
emissiveIntensity: 1.5,
|
| 334 |
+
roughness: 0.25
|
| 335 |
+
});
|
| 336 |
+
|
| 337 |
+
const edgeMaterial = new THREE.LineBasicMaterial({
|
| 338 |
+
color: 0x252d2e,
|
| 339 |
+
transparent: true,
|
| 340 |
+
opacity: 0.65
|
| 341 |
+
});
|
| 342 |
+
|
| 343 |
+
// ---------------------------------------------------------------------
|
| 344 |
+
// Helpers
|
| 345 |
+
// ---------------------------------------------------------------------
|
| 346 |
+
|
| 347 |
+
const boss = new THREE.Group();
|
| 348 |
+
boss.position.y = 0.02;
|
| 349 |
+
scene.add(boss);
|
| 350 |
+
|
| 351 |
+
function box(
|
| 352 |
+
width,
|
| 353 |
+
height,
|
| 354 |
+
depth,
|
| 355 |
+
material,
|
| 356 |
+
x,
|
| 357 |
+
y,
|
| 358 |
+
z,
|
| 359 |
+
parent = boss,
|
| 360 |
+
name = "stone-part"
|
| 361 |
+
) {
|
| 362 |
+
const mesh = new THREE.Mesh(
|
| 363 |
+
new THREE.BoxGeometry(width, height, depth),
|
| 364 |
+
material
|
| 365 |
+
);
|
| 366 |
+
|
| 367 |
+
mesh.position.set(x, y, z);
|
| 368 |
+
mesh.castShadow = true;
|
| 369 |
+
mesh.receiveShadow = true;
|
| 370 |
+
mesh.name = name;
|
| 371 |
+
parent.add(mesh);
|
| 372 |
+
|
| 373 |
+
return mesh;
|
| 374 |
+
}
|
| 375 |
+
|
| 376 |
+
function cylinder(
|
| 377 |
+
radiusTop,
|
| 378 |
+
radiusBottom,
|
| 379 |
+
height,
|
| 380 |
+
material,
|
| 381 |
+
x,
|
| 382 |
+
y,
|
| 383 |
+
z,
|
| 384 |
+
parent = boss,
|
| 385 |
+
name = "stone-part"
|
| 386 |
+
) {
|
| 387 |
+
const mesh = new THREE.Mesh(
|
| 388 |
+
new THREE.CylinderGeometry(radiusTop, radiusBottom, height, 12),
|
| 389 |
+
material
|
| 390 |
+
);
|
| 391 |
+
|
| 392 |
+
mesh.position.set(x, y, z);
|
| 393 |
+
mesh.castShadow = true;
|
| 394 |
+
mesh.receiveShadow = true;
|
| 395 |
+
mesh.name = name;
|
| 396 |
+
parent.add(mesh);
|
| 397 |
+
|
| 398 |
+
return mesh;
|
| 399 |
+
}
|
| 400 |
+
|
| 401 |
+
function addEdges(mesh, opacity = 0.55) {
|
| 402 |
+
const edges = new THREE.LineSegments(
|
| 403 |
+
new THREE.EdgesGeometry(mesh.geometry),
|
| 404 |
+
new THREE.LineBasicMaterial({
|
| 405 |
+
color: 0x1c2527,
|
| 406 |
+
transparent: true,
|
| 407 |
+
opacity
|
| 408 |
+
})
|
| 409 |
+
);
|
| 410 |
+
|
| 411 |
+
edges.position.copy(mesh.position);
|
| 412 |
+
mesh.parent.add(edges);
|
| 413 |
+
return edges;
|
| 414 |
+
}
|
| 415 |
+
|
| 416 |
+
// ---------------------------------------------------------------------
|
| 417 |
+
// Ground and subtle environmental marker
|
| 418 |
+
// ---------------------------------------------------------------------
|
| 419 |
+
|
| 420 |
+
const ground = new THREE.Mesh(
|
| 421 |
+
new THREE.PlaneGeometry(80, 80),
|
| 422 |
+
new THREE.MeshStandardMaterial({
|
| 423 |
+
color: 0x111719,
|
| 424 |
+
roughness: 1,
|
| 425 |
+
metalness: 0
|
| 426 |
+
})
|
| 427 |
+
);
|
| 428 |
+
|
| 429 |
+
ground.rotation.x = -Math.PI / 2;
|
| 430 |
+
ground.position.y = -0.015;
|
| 431 |
+
ground.receiveShadow = true;
|
| 432 |
+
scene.add(ground);
|
| 433 |
+
|
| 434 |
+
const halo = new THREE.Mesh(
|
| 435 |
+
new THREE.RingGeometry(3.6, 3.63, 96),
|
| 436 |
+
new THREE.MeshBasicMaterial({
|
| 437 |
+
color: 0x55ff8a,
|
| 438 |
+
transparent: true,
|
| 439 |
+
opacity: 0.18,
|
| 440 |
+
side: THREE.DoubleSide,
|
| 441 |
+
depthWrite: false
|
| 442 |
+
})
|
| 443 |
+
);
|
| 444 |
+
|
| 445 |
+
halo.rotation.x = -Math.PI / 2;
|
| 446 |
+
halo.position.y = 0.008;
|
| 447 |
+
scene.add(halo);
|
| 448 |
+
|
| 449 |
+
const innerHalo = new THREE.Mesh(
|
| 450 |
+
new THREE.RingGeometry(2.25, 2.265, 96),
|
| 451 |
+
new THREE.MeshBasicMaterial({
|
| 452 |
+
color: 0x85ff9d,
|
| 453 |
+
transparent: true,
|
| 454 |
+
opacity: 0.3,
|
| 455 |
+
side: THREE.DoubleSide,
|
| 456 |
+
depthWrite: false
|
| 457 |
+
})
|
| 458 |
+
);
|
| 459 |
+
|
| 460 |
+
innerHalo.rotation.x = -Math.PI / 2;
|
| 461 |
+
innerHalo.position.y = 0.012;
|
| 462 |
+
scene.add(innerHalo);
|
| 463 |
+
|
| 464 |
+
// ---------------------------------------------------------------------
|
| 465 |
+
// Legs and feet
|
| 466 |
+
// ---------------------------------------------------------------------
|
| 467 |
+
|
| 468 |
+
const leftLeg = box(
|
| 469 |
+
1.55, 2.65, 1.75,
|
| 470 |
+
stoneMaterial,
|
| 471 |
+
-1.02, 1.55, 0,
|
| 472 |
+
boss,
|
| 473 |
+
"left-thigh"
|
| 474 |
+
);
|
| 475 |
+
addEdges(leftLeg, 0.4);
|
| 476 |
+
|
| 477 |
+
const rightLeg = box(
|
| 478 |
+
1.55, 2.65, 1.75,
|
| 479 |
+
stoneMaterial,
|
| 480 |
+
1.02, 1.55, 0,
|
| 481 |
+
boss,
|
| 482 |
+
"right-thigh"
|
| 483 |
+
);
|
| 484 |
+
addEdges(rightLeg, 0.4);
|
| 485 |
+
|
| 486 |
+
const leftFoot = box(
|
| 487 |
+
2.05, 0.55, 2.45,
|
| 488 |
+
darkStoneMaterial,
|
| 489 |
+
-1.02, 0.32, 0.1,
|
| 490 |
+
boss,
|
| 491 |
+
"left-foot"
|
| 492 |
+
);
|
| 493 |
+
|
| 494 |
+
const rightFoot = box(
|
| 495 |
+
2.05, 0.55, 2.45,
|
| 496 |
+
darkStoneMaterial,
|
| 497 |
+
1.02, 0.32, 0.1,
|
| 498 |
+
boss,
|
| 499 |
+
"right-foot"
|
| 500 |
+
);
|
| 501 |
+
|
| 502 |
+
// ---------------------------------------------------------------------
|
| 503 |
+
// Torso, chest, neck, and head
|
| 504 |
+
// ---------------------------------------------------------------------
|
| 505 |
+
|
| 506 |
+
const lowerTorso = box(
|
| 507 |
+
3.15, 4.15, 3.0,
|
| 508 |
+
stoneMaterial,
|
| 509 |
+
0, 2.68, 0,
|
| 510 |
+
boss,
|
| 511 |
+
"lower-torso"
|
| 512 |
+
);
|
| 513 |
+
addEdges(lowerTorso, 0.32);
|
| 514 |
+
|
| 515 |
+
const chest = box(
|
| 516 |
+
3.45, 1.75, 3.25,
|
| 517 |
+
wornStoneMaterial,
|
| 518 |
+
0, 4.25, 0,
|
| 519 |
+
boss,
|
| 520 |
+
"chest-plate"
|
| 521 |
+
);
|
| 522 |
+
addEdges(chest, 0.38);
|
| 523 |
+
|
| 524 |
+
const upperTorso = box(
|
| 525 |
+
2.75, 1.1, 2.65,
|
| 526 |
+
stoneMaterial,
|
| 527 |
+
0, 5.3, 0,
|
| 528 |
+
boss,
|
| 529 |
+
"upper-torso"
|
| 530 |
+
);
|
| 531 |
+
|
| 532 |
+
const neck = box(
|
| 533 |
+
1.35, 1.1, 1.5,
|
| 534 |
+
darkStoneMaterial,
|
| 535 |
+
0, 5.7, 0,
|
| 536 |
+
boss,
|
| 537 |
+
"neck"
|
| 538 |
+
);
|
| 539 |
+
addEdges(neck, 0.4);
|
| 540 |
+
|
| 541 |
+
const skull = box(
|
| 542 |
+
2.35, 1.65, 2.05,
|
| 543 |
+
stoneMaterial,
|
| 544 |
+
0, 6.45, 0,
|
| 545 |
+
boss,
|
| 546 |
+
"skull"
|
| 547 |
+
);
|
| 548 |
+
addEdges(skull, 0.45);
|
| 549 |
+
|
| 550 |
+
const jaw = box(
|
| 551 |
+
2.65, 0.65, 2.18,
|
| 552 |
+
darkStoneMaterial,
|
| 553 |
+
0, 5.55, 0.04,
|
| 554 |
+
boss,
|
| 555 |
+
"jaw"
|
| 556 |
+
);
|
| 557 |
+
|
| 558 |
+
// Brow ridges.
|
| 559 |
+
box(0.85, 0.34, 0.42, darkStoneMaterial, -0.78, 6.94, 0.72, boss, "left-brow");
|
| 560 |
+
box(0.85, 0.34, 0.42, darkStoneMaterial, 0.78, 6.94, 0.72, boss, "right-brow");
|
| 561 |
+
|
| 562 |
+
// Eye sockets and luminous cores.
|
| 563 |
+
box(0.34, 0.43, 0.18, ironMaterial, -0.57, 6.55, 1.02, boss, "left-eye-socket");
|
| 564 |
+
box(0.34, 0.43, 0.18, ironMaterial, 0.57, 6.55, 1.02, boss, "right-eye-socket");
|
| 565 |
+
|
| 566 |
+
box(0.18, 0.25, 0.12, eyeMaterial, -0.57, 6.55, 1.13, boss, "left-eye");
|
| 567 |
+
box(0.18, 0.25, 0.12, eyeMaterial, 0.57, 6.55, 1.13, boss, "right-eye");
|
| 568 |
+
|
| 569 |
+
// Mouth and cheek stones.
|
| 570 |
+
box(1.45, 0.16, 0.12, ironMaterial, 0, 5.92, 1.06, boss, "mouth");
|
| 571 |
+
box(0.45, 0.55, 0.4, darkStoneMaterial, -0.9, 6.08, 0.85, boss, "left-cheek");
|
| 572 |
+
box(0.45, 0.55, 0.4, darkStoneMaterial, 0.9, 6.08, 0.85, boss, "right-cheek");
|
| 573 |
+
|
| 574 |
+
// ---------------------------------------------------------------------
|
| 575 |
+
// Arms, gauntlets, and shoulder armor
|
| 576 |
+
// ---------------------------------------------------------------------
|
| 577 |
+
|
| 578 |
+
for (const side of [-1, 1]) {
|
| 579 |
+
const upperArm = box(
|
| 580 |
+
1.35, 2.15, 1.45,
|
| 581 |
+
stoneMaterial,
|
| 582 |
+
side * 2.35, 3.2, 0,
|
| 583 |
+
boss,
|
| 584 |
+
`${side === -1 ? "left" : "right"}-upper-arm`
|
| 585 |
+
);
|
| 586 |
+
addEdges(upperArm, 0.3);
|
| 587 |
+
|
| 588 |
+
const forearm = box(
|
| 589 |
+
1.0, 2.45, 1.18,
|
| 590 |
+
wornStoneMaterial,
|
| 591 |
+
side * 3.08, 2.0, 0.05,
|
| 592 |
+
boss,
|
| 593 |
+
`${side === -1 ? "left" : "right"}-forearm`
|
| 594 |
+
);
|
| 595 |
+
addEdges(forearm, 0.3);
|
| 596 |
+
|
| 597 |
+
const hand = box(
|
| 598 |
+
1.05, 1.05, 1.15,
|
| 599 |
+
ironMaterial,
|
| 600 |
+
side * 3.08, 1.05, 0.08,
|
| 601 |
+
boss,
|
| 602 |
+
`${side === -1 ? "left" : "right"}-hand`
|
| 603 |
+
);
|
| 604 |
+
addEdges(hand, 0.35);
|
| 605 |
+
|
| 606 |
+
const shoulderPad = box(
|
| 607 |
+
1.7, 0.72, 1.55,
|
| 608 |
+
armorMaterial,
|
| 609 |
+
side * 2.2, 4.18, 0.05,
|
| 610 |
+
boss,
|
| 611 |
+
`${side === -1 ? "left" : "right"}-shoulder-pad`
|
| 612 |
+
);
|
| 613 |
+
addEdges(shoulderPad, 0.35);
|
| 614 |
+
|
| 615 |
+
const gauntlet = box(
|
| 616 |
+
1.12, 0.75, 1.22,
|
| 617 |
+
ironMaterial,
|
| 618 |
+
side * 3.05, 1.67, 0.08,
|
| 619 |
+
boss,
|
| 620 |
+
`${side === -1 ? "left" : "right"}-gauntlet`
|
| 621 |
+
);
|
| 622 |
+
addEdges(gauntlet, 0.3);
|
| 623 |
+
}
|
| 624 |
+
|
| 625 |
+
// Belt and chest trim.
|
| 626 |
+
const belt = new THREE.Mesh(
|
| 627 |
+
new THREE.TorusGeometry(1.62, 0.16, 8, 40),
|
| 628 |
+
ironMaterial
|
| 629 |
+
);
|
| 630 |
+
belt.rotation.x = Math.PI / 2;
|
| 631 |
+
belt.position.y = 2.45;
|
| 632 |
+
belt.castShadow = true;
|
| 633 |
+
boss.add(belt);
|
| 634 |
+
|
| 635 |
+
box(0.8, 0.22, 0.12, ironMaterial, 0, 4.9, 1.68, boss, "chest-trim");
|
| 636 |
+
|
| 637 |
+
// ---------------------------------------------------------------------
|
| 638 |
+
// Glowing green shoulder crystal clusters
|
| 639 |
+
// ---------------------------------------------------------------------
|
| 640 |
+
|
| 641 |
+
const animatedCrystals = [];
|
| 642 |
+
|
| 643 |
+
function createShoulderCrystals(side) {
|
| 644 |
+
const cluster = new THREE.Group();
|
| 645 |
+
cluster.position.set(side * 2.18, 4.38, 0.52);
|
| 646 |
+
cluster.rotation.z = side * 0.035;
|
| 647 |
+
cluster.name = `${side === -1 ? "left" : "right"}-crystal-cluster`;
|
| 648 |
+
boss.add(cluster);
|
| 649 |
+
|
| 650 |
+
const stem = box(
|
| 651 |
+
0.22, 0.55, 0.22,
|
| 652 |
+
ironMaterial,
|
| 653 |
+
0, 0.25, 0,
|
| 654 |
+
cluster,
|
| 655 |
+
"crystal-stem"
|
| 656 |
+
);
|
| 657 |
+
addEdges(stem, 0.25);
|
| 658 |
+
|
| 659 |
+
const centralCrystal = new THREE.Mesh(
|
| 660 |
+
new THREE.ConeGeometry(0.42, 1.55, 5, 1),
|
| 661 |
+
crystalMaterial
|
| 662 |
+
);
|
| 663 |
+
centralCrystal.position.set(0, 1.13, 0);
|
| 664 |
+
centralCrystal.castShadow = true;
|
| 665 |
+
centralCrystal.name = "central-shoulder-crystal";
|
| 666 |
+
cluster.add(centralCrystal);
|
| 667 |
+
|
| 668 |
+
const sideCrystals = [
|
| 669 |
+
{ x: -0.46, y: 0.86, scale: 0.72 },
|
| 670 |
+
{ x: 0.46, y: 0.86, scale: 0.72 },
|
| 671 |
+
{ x: 0, y: 0.68, scale: 0.48 }
|
| 672 |
+
];
|
| 673 |
+
|
| 674 |
+
for (const shard of sideCrystals) {
|
| 675 |
+
const crystal = new THREE.Mesh(
|
| 676 |
+
new THREE.OctahedronGeometry(0.34, 0),
|
| 677 |
+
crystalMaterial
|
| 678 |
+
);
|
| 679 |
+
|
| 680 |
+
crystal.position.set(shard.x, shard.y, 0.02);
|
| 681 |
+
crystal.scale.setScalar(shard.scale);
|
| 682 |
+
crystal.rotation.y = shard.x * 0.7;
|
| 683 |
+
crystal.castShadow = true;
|
| 684 |
+
crystal.name = `shoulder-${side === -1 ? "left" : "right"}-crystal`;
|
| 685 |
+
cluster.add(crystal);
|
| 686 |
+
}
|
| 687 |
+
|
| 688 |
+
const clusterLight = new THREE.PointLight(0x4dff78, 4.2, 5, 2);
|
| 689 |
+
clusterLight.position.set(0, 1.15, 0.2);
|
| 690 |
+
cluster.add(clusterLight);
|
| 691 |
+
|
| 692 |
+
animatedCrystals.push({
|
| 693 |
+
group: cluster,
|
| 694 |
+
phase: side * 1.7,
|
| 695 |
+
baseScale: 1
|
| 696 |
+
});
|
| 697 |
+
}
|
| 698 |
+
|
| 699 |
+
createShoulderCrystals(-1);
|
| 700 |
+
createShoulderCrystals(1);
|
| 701 |
+
|
| 702 |
+
// A smaller crystal at the center of the chest.
|
| 703 |
+
const chestCrystal = new THREE.Mesh(
|
| 704 |
+
new THREE.OctahedronGeometry(0.38, 0),
|
| 705 |
+
crystalCoreMaterial
|
| 706 |
+
);
|
| 707 |
+
chestCrystal.position.set(0, 4.75, 1.2);
|
| 708 |
+
chestCrystal.castShadow = true;
|
| 709 |
+
boss.add(chestCrystal);
|
| 710 |
+
|
| 711 |
+
const chestLight = new THREE.PointLight(0x3dff83, 2.8, 4, 2);
|
| 712 |
+
chestLight.position.set(0, 4.75, 1.35);
|
| 713 |
+
boss.add(chestLight);
|
| 714 |
+
|
| 715 |
+
// ---------------------------------------------------------------------
|
| 716 |
+
// Small environmental particles
|
| 717 |
+
// ---------------------------------------------------------------------
|
| 718 |
+
|
| 719 |
+
const particleCount = 28;
|
| 720 |
+
const particlePositions = new Float32Array(particleCount * 3);
|
| 721 |
+
|
| 722 |
+
for (let i = 0; i < particleCount; i++) {
|
| 723 |
+
const angle = Math.random() * Math.PI * 2;
|
| 724 |
+
const radius = 2.5 + Math.random() * 5;
|
| 725 |
+
particlePositions[i * 3] = Math.cos(angle) * radius;
|
| 726 |
+
particlePositions[i * 3 + 1] = 0.3 + Math.random() * 4.5;
|
| 727 |
+
particlePositions[i * 3 + 2] = Math.sin(angle) * radius;
|
| 728 |
+
}
|
| 729 |
+
|
| 730 |
+
const particleGeometry = new THREE.BufferGeometry();
|
| 731 |
+
particleGeometry.setAttribute(
|
| 732 |
+
"position",
|
| 733 |
+
new THREE.BufferAttribute(particlePositions, 3)
|
| 734 |
+
);
|
| 735 |
+
|
| 736 |
+
const particles = new THREE.Points(
|
| 737 |
+
particleGeometry,
|
| 738 |
+
new THREE.PointsMaterial({
|
| 739 |
+
color: 0x65ff91,
|
| 740 |
+
size: 0.045,
|
| 741 |
+
transparent: true,
|
| 742 |
+
opacity: 0.65,
|
| 743 |
+
depthWrite: false,
|
| 744 |
+
blending: THREE.AdditiveBlending
|
| 745 |
+
})
|
| 746 |
+
);
|
| 747 |
+
|
| 748 |
+
scene.add(particles);
|
| 749 |
+
|
| 750 |
+
// ---------------------------------------------------------------------
|
| 751 |
+
// Custom camera controls
|
| 752 |
+
// ---------------------------------------------------------------------
|
| 753 |
+
|
| 754 |
+
const cameraState = {
|
| 755 |
+
radius: 12.2,
|
| 756 |
+
theta: 0.72,
|
| 757 |
+
phi: 1.17,
|
| 758 |
+
target: new THREE.Vector3(0, 3.25, 0)
|
| 759 |
+
};
|
| 760 |
+
|
| 761 |
+
const defaultCamera = { ...cameraState };
|
| 762 |
+
|
| 763 |
+
function updateCamera() {
|
| 764 |
+
const sinPhi = Math.sin(cameraState.phi);
|
| 765 |
+
|
| 766 |
+
camera.position.set(
|
| 767 |
+
cameraState.target.x +
|
| 768 |
+
cameraState.radius * sinPhi * Math.sin(cameraState.theta),
|
| 769 |
+
cameraState.target.y +
|
| 770 |
+
cameraState.radius * Math.cos(cameraState.phi),
|
| 771 |
+
cameraState.target.z +
|
| 772 |
+
cameraState.radius * sinPhi * Math.cos(cameraState.theta)
|
| 773 |
+
);
|
| 774 |
+
|
| 775 |
+
camera.lookAt(cameraState.target);
|
| 776 |
+
}
|
| 777 |
+
|
| 778 |
+
updateCamera();
|
| 779 |
+
|
| 780 |
+
let dragging = false;
|
| 781 |
+
let pointerX = 0;
|
| 782 |
+
let pointerY = 0;
|
| 783 |
+
|
| 784 |
+
renderer.domElement.addEventListener("pointerdown", (event) => {
|
| 785 |
+
dragging = true;
|
| 786 |
+
pointerX = event.clientX;
|
| 787 |
+
pointerY = event.clientY;
|
| 788 |
+
renderer.domElement.setPointerCapture(event.pointerId);
|
| 789 |
+
});
|
| 790 |
+
|
| 791 |
+
renderer.domElement.addEventListener("pointermove", (event) => {
|
| 792 |
+
if (!dragging) return;
|
| 793 |
+
|
| 794 |
+
const deltaX = event.clientX - pointerX;
|
| 795 |
+
const deltaY = event.clientY - pointerY;
|
| 796 |
+
|
| 797 |
+
pointerX = event.clientX;
|
| 798 |
+
pointerY = event.clientY;
|
| 799 |
+
|
| 800 |
+
cameraState.theta -= deltaX * 0.006;
|
| 801 |
+
cameraState.phi = THREE.MathUtils.clamp(
|
| 802 |
+
cameraState.phi - deltaY * 0.005,
|
| 803 |
+
0.55,
|
| 804 |
+
1.48
|
| 805 |
+
);
|
| 806 |
+
|
| 807 |
+
updateCamera();
|
| 808 |
+
});
|
| 809 |
+
|
| 810 |
+
function endDrag(event) {
|
| 811 |
+
dragging = false;
|
| 812 |
+
|
| 813 |
+
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
|
| 814 |
+
renderer.domElement.releasePointerCapture(event.pointerId);
|
| 815 |
+
}
|
| 816 |
+
}
|
| 817 |
+
|
| 818 |
+
renderer.domElement.addEventListener("pointerup", endDrag);
|
| 819 |
+
renderer.domElement.addEventListener("pointercancel", endDrag);
|
| 820 |
+
|
| 821 |
+
renderer.domElement.addEventListener(
|
| 822 |
+
"wheel",
|
| 823 |
+
(event) => {
|
| 824 |
+
event.preventDefault();
|
| 825 |
+
|
| 826 |
+
cameraState.radius = THREE.MathUtils.clamp(
|
| 827 |
+
cameraState.radius * Math.exp(event.deltaY * 0.001),
|
| 828 |
+
7.2,
|
| 829 |
+
20
|
| 830 |
+
);
|
| 831 |
+
|
| 832 |
+
updateCamera();
|
| 833 |
+
},
|
| 834 |
+
{ passive: false }
|
| 835 |
+
);
|
| 836 |
+
|
| 837 |
+
// ---------------------------------------------------------------------
|
| 838 |
+
// Turntable and animation
|
| 839 |
+
// ---------------------------------------------------------------------
|
| 840 |
+
|
| 841 |
+
let turning = true;
|
| 842 |
+
let elapsed = 0;
|
| 843 |
+
|
| 844 |
+
rotateButton.addEventListener("click", () => {
|
| 845 |
+
turning = !turning;
|
| 846 |
+
rotateButton.textContent = turning ? "Pause rotation" : "Resume rotation";
|
| 847 |
+
rotateButton.setAttribute("aria-pressed", String(!turning));
|
| 848 |
+
});
|
| 849 |
+
|
| 850 |
+
const clock = new THREE.Clock();
|
| 851 |
+
|
| 852 |
+
renderer.setAnimationLoop(() => {
|
| 853 |
+
const delta = Math.min(clock.getDelta(), 0.05);
|
| 854 |
+
elapsed += delta;
|
| 855 |
+
|
| 856 |
+
// Slow 360-degree turntable rotation.
|
| 857 |
+
if (turning) {
|
| 858 |
+
boss.rotation.y += delta * 0.15;
|
| 859 |
+
}
|
| 860 |
+
|
| 861 |
+
// Pulsing crystal growth.
|
| 862 |
+
for (const crystal of animatedCrystals) {
|
| 863 |
+
const pulse = 1 + Math.sin(elapsed * 1.7 + crystal.phase) * 0.075;
|
| 864 |
+
crystal.group.scale.setScalar(pulse);
|
| 865 |
+
}
|
| 866 |
+
|
| 867 |
+
crystalMaterial.emissiveIntensity = 1.65 + Math.sin(elapsed * 2.1) * 0.22;
|
| 868 |
+
crystalCoreMaterial.emissiveIntensity = 2.25 + Math.sin(elapsed * 2.8) * 0.35;
|
| 869 |
+
|
| 870 |
+
chestCrystal.scale.setScalar(1 + Math.sin(elapsed * 2.3) * 0.08);
|
| 871 |
+
particles.rotation.y = elapsed * 0.08;
|
| 872 |
+
particles.position.y = Math.sin(elapsed * 0.7) * 0.12;
|
| 873 |
+
|
| 874 |
+
halo.rotation.z = elapsed * 0.025;
|
| 875 |
+
halo.material.opacity = 0.16 + Math.sin(elapsed * 0.8) * 0.035;
|
| 876 |
+
|
| 877 |
+
renderer.render(scene, camera);
|
| 878 |
+
});
|
| 879 |
+
|
| 880 |
+
// ---------------------------------------------------------------------
|
| 881 |
+
// Resize handling
|
| 882 |
+
// ---------------------------------------------------------------------
|
| 883 |
+
|
| 884 |
+
window.addEventListener("resize", () => {
|
| 885 |
+
camera.aspect = window.innerWidth / window.innerHeight;
|
| 886 |
+
camera.updateProjectionMatrix();
|
| 887 |
+
|
| 888 |
+
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
|
| 889 |
+
renderer.setSize(window.innerWidth, window.innerHeight);
|
| 890 |
+
});
|
| 891 |
+
|
| 892 |
+
requestAnimationFrame(() => {
|
| 893 |
+
loading.classList.add("hidden");
|
| 894 |
+
setTimeout(() => loading.remove(), 600);
|
| 895 |
+
});
|
| 896 |
+
</script>
|
| 897 |
+
</body>
|
| 898 |
+
</html>
|
source/potions.html
ADDED
|
@@ -0,0 +1,677 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!doctype html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="utf-8" />
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
| 6 |
+
<title>Three Potion Bottles</title>
|
| 7 |
+
|
| 8 |
+
<style>
|
| 9 |
+
:root {
|
| 10 |
+
color-scheme: light;
|
| 11 |
+
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
|
| 12 |
+
"Segoe UI", sans-serif;
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
* {
|
| 16 |
+
box-sizing: border-box;
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
html,
|
| 20 |
+
body {
|
| 21 |
+
width: 100%;
|
| 22 |
+
height: 100%;
|
| 23 |
+
margin: 0;
|
| 24 |
+
overflow: hidden;
|
| 25 |
+
background: #dfe5df;
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
#stage {
|
| 29 |
+
position: fixed;
|
| 30 |
+
inset: 0;
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
canvas {
|
| 34 |
+
display: block;
|
| 35 |
+
width: 100%;
|
| 36 |
+
height: 100%;
|
| 37 |
+
touch-action: none;
|
| 38 |
+
cursor: grab;
|
| 39 |
+
outline: none;
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
canvas.dragging {
|
| 43 |
+
cursor: grabbing;
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
.hud {
|
| 47 |
+
position: fixed;
|
| 48 |
+
top: 24px;
|
| 49 |
+
left: 26px;
|
| 50 |
+
z-index: 2;
|
| 51 |
+
max-width: min(360px, calc(100vw - 52px));
|
| 52 |
+
padding: 16px 18px;
|
| 53 |
+
border: 1px solid rgba(255, 255, 255, 0.58);
|
| 54 |
+
border-radius: 16px;
|
| 55 |
+
background: rgba(250, 248, 240, 0.72);
|
| 56 |
+
box-shadow: 0 12px 36px rgba(49, 58, 51, 0.12);
|
| 57 |
+
backdrop-filter: blur(12px);
|
| 58 |
+
pointer-events: none;
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
.eyebrow {
|
| 62 |
+
margin-bottom: 5px;
|
| 63 |
+
color: #718078;
|
| 64 |
+
font-size: 10px;
|
| 65 |
+
font-weight: 800;
|
| 66 |
+
letter-spacing: 0.18em;
|
| 67 |
+
text-transform: uppercase;
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
h1 {
|
| 71 |
+
margin: 0;
|
| 72 |
+
color: #303b36;
|
| 73 |
+
font-size: clamp(25px, 4vw, 38px);
|
| 74 |
+
font-weight: 750;
|
| 75 |
+
letter-spacing: -0.045em;
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
.hud p {
|
| 79 |
+
margin: 8px 0 0;
|
| 80 |
+
color: #69746d;
|
| 81 |
+
font-size: 13px;
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
.controls {
|
| 85 |
+
position: fixed;
|
| 86 |
+
right: 22px;
|
| 87 |
+
bottom: 22px;
|
| 88 |
+
z-index: 3;
|
| 89 |
+
display: flex;
|
| 90 |
+
align-items: center;
|
| 91 |
+
gap: 12px;
|
| 92 |
+
padding: 10px 12px;
|
| 93 |
+
border: 1px solid rgba(255, 255, 255, 0.62);
|
| 94 |
+
border-radius: 12px;
|
| 95 |
+
background: rgba(250, 248, 240, 0.76);
|
| 96 |
+
box-shadow: 0 10px 30px rgba(49, 58, 51, 0.12);
|
| 97 |
+
backdrop-filter: blur(10px);
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
.status {
|
| 101 |
+
color: #738078;
|
| 102 |
+
font-size: 11px;
|
| 103 |
+
font-weight: 700;
|
| 104 |
+
letter-spacing: 0.08em;
|
| 105 |
+
text-transform: uppercase;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
button {
|
| 109 |
+
border: 0;
|
| 110 |
+
border-radius: 8px;
|
| 111 |
+
padding: 9px 12px;
|
| 112 |
+
background: #415047;
|
| 113 |
+
color: #fffdf5;
|
| 114 |
+
font: inherit;
|
| 115 |
+
font-size: 12px;
|
| 116 |
+
font-weight: 700;
|
| 117 |
+
cursor: pointer;
|
| 118 |
+
transition: transform 150ms ease, background 150ms ease;
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
button:hover {
|
| 122 |
+
background: #526157;
|
| 123 |
+
transform: translateY(-1px);
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
button:active {
|
| 127 |
+
transform: translateY(0);
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
@media (max-width: 600px) {
|
| 131 |
+
.hud {
|
| 132 |
+
top: 14px;
|
| 133 |
+
left: 14px;
|
| 134 |
+
padding: 13px 15px;
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
.hud p {
|
| 138 |
+
max-width: 230px;
|
| 139 |
+
font-size: 12px;
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
.controls {
|
| 143 |
+
right: 14px;
|
| 144 |
+
bottom: 14px;
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
.status {
|
| 148 |
+
display: none;
|
| 149 |
+
}
|
| 150 |
+
}
|
| 151 |
+
</style>
|
| 152 |
+
</head>
|
| 153 |
+
|
| 154 |
+
<body>
|
| 155 |
+
<main id="stage" aria-label="Interactive three-dimensional potion bottle scene"></main>
|
| 156 |
+
|
| 157 |
+
<section class="hud">
|
| 158 |
+
<div class="eyebrow">Interactive 3D asset</div>
|
| 159 |
+
<h1>Three Potions</h1>
|
| 160 |
+
<p>Drag to orbit · Scroll or pinch to zoom · Double-click to reset</p>
|
| 161 |
+
</section>
|
| 162 |
+
|
| 163 |
+
<div class="controls">
|
| 164 |
+
<span class="status" id="status">Auto spin</span>
|
| 165 |
+
<button id="pause" type="button">Pause rotation</button>
|
| 166 |
+
</div>
|
| 167 |
+
|
| 168 |
+
<script type="module">
|
| 169 |
+
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
|
| 170 |
+
|
| 171 |
+
const stage = document.querySelector("#stage");
|
| 172 |
+
const pauseButton = document.querySelector("#pause");
|
| 173 |
+
const status = document.querySelector("#status");
|
| 174 |
+
|
| 175 |
+
// ---------------------------------------------------------------------
|
| 176 |
+
// Renderer, scene, and camera
|
| 177 |
+
// ---------------------------------------------------------------------
|
| 178 |
+
|
| 179 |
+
const renderer = new THREE.WebGLRenderer({
|
| 180 |
+
antialias: true,
|
| 181 |
+
powerPreference: "high-performance"
|
| 182 |
+
});
|
| 183 |
+
|
| 184 |
+
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
|
| 185 |
+
renderer.setSize(window.innerWidth, window.innerHeight);
|
| 186 |
+
renderer.shadowMap.enabled = true;
|
| 187 |
+
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
|
| 188 |
+
renderer.outputColorSpace = THREE.SRGBColorSpace;
|
| 189 |
+
renderer.toneMapping = THREE.ACESFilmicToneMapping;
|
| 190 |
+
renderer.toneMappingExposure = 1.08;
|
| 191 |
+
|
| 192 |
+
renderer.domElement.setAttribute(
|
| 193 |
+
"aria-label",
|
| 194 |
+
"Three colored potion bottles with corks resting on a wooden tray"
|
| 195 |
+
);
|
| 196 |
+
|
| 197 |
+
stage.appendChild(renderer.domElement);
|
| 198 |
+
|
| 199 |
+
const scene = new THREE.Scene();
|
| 200 |
+
scene.background = new THREE.Color(0xdfe5df);
|
| 201 |
+
scene.fog = new THREE.Fog(0xdfe5df, 13, 30);
|
| 202 |
+
|
| 203 |
+
const camera = new THREE.PerspectiveCamera(
|
| 204 |
+
38,
|
| 205 |
+
window.innerWidth / window.innerHeight,
|
| 206 |
+
0.1,
|
| 207 |
+
100
|
| 208 |
+
);
|
| 209 |
+
|
| 210 |
+
const controls = {
|
| 211 |
+
yaw: 0.58,
|
| 212 |
+
pitch: 0.52,
|
| 213 |
+
distance: 8.4,
|
| 214 |
+
target: new THREE.Vector3(0, 1.08, 0)
|
| 215 |
+
};
|
| 216 |
+
|
| 217 |
+
function updateCamera() {
|
| 218 |
+
const horizontalDistance =
|
| 219 |
+
controls.distance * Math.cos(controls.pitch);
|
| 220 |
+
|
| 221 |
+
camera.position.set(
|
| 222 |
+
controls.target.x + Math.sin(controls.yaw) * horizontalDistance,
|
| 223 |
+
controls.target.y + Math.sin(controls.pitch) * controls.distance,
|
| 224 |
+
controls.target.z + Math.cos(controls.yaw) * horizontalDistance
|
| 225 |
+
);
|
| 226 |
+
|
| 227 |
+
camera.lookAt(controls.target);
|
| 228 |
+
}
|
| 229 |
+
|
| 230 |
+
updateCamera();
|
| 231 |
+
|
| 232 |
+
// ---------------------------------------------------------------------
|
| 233 |
+
// Lighting
|
| 234 |
+
// ---------------------------------------------------------------------
|
| 235 |
+
|
| 236 |
+
scene.add(new THREE.HemisphereLight(0xf8fcff, 0x8a6848, 2.1));
|
| 237 |
+
|
| 238 |
+
const keyLight = new THREE.DirectionalLight(0xfff1d7, 3.2);
|
| 239 |
+
keyLight.position.set(-4.5, 8, 5.5);
|
| 240 |
+
keyLight.castShadow = true;
|
| 241 |
+
keyLight.shadow.mapSize.set(2048, 2048);
|
| 242 |
+
keyLight.shadow.camera.left = -7;
|
| 243 |
+
keyLight.shadow.camera.right = 7;
|
| 244 |
+
keyLight.shadow.camera.top = 7;
|
| 245 |
+
keyLight.shadow.camera.bottom = -7;
|
| 246 |
+
keyLight.shadow.camera.near = 0.5;
|
| 247 |
+
keyLight.shadow.camera.far = 20;
|
| 248 |
+
keyLight.shadow.normalBias = 0.025;
|
| 249 |
+
keyLight.target.position.set(0, 0.8, 0);
|
| 250 |
+
scene.add(keyLight, keyLight.target);
|
| 251 |
+
|
| 252 |
+
const fillLight = new THREE.DirectionalLight(0xc5dcff, 1.25);
|
| 253 |
+
fillLight.position.set(5, 3.5, -4);
|
| 254 |
+
scene.add(fillLight);
|
| 255 |
+
|
| 256 |
+
// ---------------------------------------------------------------------
|
| 257 |
+
// Materials and geometry helpers
|
| 258 |
+
// ---------------------------------------------------------------------
|
| 259 |
+
|
| 260 |
+
function createWoodTexture() {
|
| 261 |
+
const canvas = document.createElement("canvas");
|
| 262 |
+
canvas.width = 512;
|
| 263 |
+
canvas.height = 512;
|
| 264 |
+
|
| 265 |
+
const context = canvas.getContext("2d");
|
| 266 |
+
context.fillStyle = "#8a542f";
|
| 267 |
+
context.fillRect(0, 0, 512, 512);
|
| 268 |
+
|
| 269 |
+
let seed = 9137;
|
| 270 |
+
|
| 271 |
+
function random() {
|
| 272 |
+
seed = (seed * 16807) % 2147483647;
|
| 273 |
+
return (seed - 1) / 2147483646;
|
| 274 |
+
}
|
| 275 |
+
|
| 276 |
+
for (let i = 0; i < 100; i++) {
|
| 277 |
+
const y = random() * 512;
|
| 278 |
+
const amplitude = 1 + random() * 5;
|
| 279 |
+
const frequency = 0.008 + random() * 0.018;
|
| 280 |
+
|
| 281 |
+
context.beginPath();
|
| 282 |
+
context.moveTo(0, y);
|
| 283 |
+
|
| 284 |
+
for (let x = 0; x <= 512; x += 8) {
|
| 285 |
+
const wave = Math.sin(x * frequency + i) * amplitude;
|
| 286 |
+
const noise = (random() - 0.5) * 2;
|
| 287 |
+
context.lineTo(x, y + wave + noise);
|
| 288 |
+
}
|
| 289 |
+
|
| 290 |
+
context.strokeStyle = `rgba(48, 23, 10, ${0.08 + random() * 0.16})`;
|
| 291 |
+
context.lineWidth = 0.5 + random() * 2.2;
|
| 292 |
+
context.stroke();
|
| 293 |
+
}
|
| 294 |
+
|
| 295 |
+
for (let i = 0; i < 8; i++) {
|
| 296 |
+
const x = random() * 512;
|
| 297 |
+
const y = random() * 512;
|
| 298 |
+
const radiusX = 8 + random() * 24;
|
| 299 |
+
const radiusY = 2 + random() * 7;
|
| 300 |
+
|
| 301 |
+
context.beginPath();
|
| 302 |
+
context.ellipse(x, y, radiusX, radiusY, 0, 0, Math.PI * 2);
|
| 303 |
+
context.strokeStyle = "rgba(45, 22, 9, 0.18)";
|
| 304 |
+
context.lineWidth = 2;
|
| 305 |
+
context.stroke();
|
| 306 |
+
}
|
| 307 |
+
|
| 308 |
+
const texture = new THREE.CanvasTexture(canvas);
|
| 309 |
+
texture.colorSpace = THREE.SRGBColorSpace;
|
| 310 |
+
texture.wrapS = THREE.RepeatWrapping;
|
| 311 |
+
texture.wrapT = THREE.RepeatWrapping;
|
| 312 |
+
texture.repeat.set(1.5, 1.5);
|
| 313 |
+
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
|
| 314 |
+
|
| 315 |
+
return texture;
|
| 316 |
+
}
|
| 317 |
+
|
| 318 |
+
const woodTexture = createWoodTexture();
|
| 319 |
+
|
| 320 |
+
const materials = {
|
| 321 |
+
wood: new THREE.MeshStandardMaterial({
|
| 322 |
+
map: woodTexture,
|
| 323 |
+
color: 0xffffff,
|
| 324 |
+
roughness: 0.78
|
| 325 |
+
}),
|
| 326 |
+
darkWood: new THREE.MeshStandardMaterial({
|
| 327 |
+
map: woodTexture,
|
| 328 |
+
color: 0x6d4127,
|
| 329 |
+
roughness: 0.86
|
| 330 |
+
}),
|
| 331 |
+
cork: new THREE.MeshStandardMaterial({
|
| 332 |
+
color: 0xb9864e,
|
| 333 |
+
roughness: 0.82
|
| 334 |
+
}),
|
| 335 |
+
corkTop: new THREE.MeshStandardMaterial({
|
| 336 |
+
color: 0xd0a264,
|
| 337 |
+
roughness: 0.72
|
| 338 |
+
}),
|
| 339 |
+
label: new THREE.MeshStandardMaterial({
|
| 340 |
+
color: 0xf3e3bd,
|
| 341 |
+
roughness: 0.88
|
| 342 |
+
})
|
| 343 |
+
};
|
| 344 |
+
|
| 345 |
+
function addMesh(
|
| 346 |
+
geometry,
|
| 347 |
+
material,
|
| 348 |
+
parent,
|
| 349 |
+
name,
|
| 350 |
+
position = [0, 0, 0],
|
| 351 |
+
rotation = [0, 0, 0],
|
| 352 |
+
castShadow = true,
|
| 353 |
+
receiveShadow = true
|
| 354 |
+
) {
|
| 355 |
+
const object = new THREE.Mesh(geometry, material);
|
| 356 |
+
object.name = name;
|
| 357 |
+
object.position.set(...position);
|
| 358 |
+
object.rotation.set(...rotation);
|
| 359 |
+
object.castShadow = castShadow;
|
| 360 |
+
object.receiveShadow = receiveShadow;
|
| 361 |
+
parent.add(object);
|
| 362 |
+
|
| 363 |
+
return object;
|
| 364 |
+
}
|
| 365 |
+
|
| 366 |
+
// ---------------------------------------------------------------------
|
| 367 |
+
// Ground plane
|
| 368 |
+
// ---------------------------------------------------------------------
|
| 369 |
+
|
| 370 |
+
const ground = addMesh(
|
| 371 |
+
new THREE.PlaneGeometry(40, 40),
|
| 372 |
+
new THREE.MeshStandardMaterial({
|
| 373 |
+
color: 0xd9dfda,
|
| 374 |
+
roughness: 1
|
| 375 |
+
}),
|
| 376 |
+
scene,
|
| 377 |
+
"Plain ground plane",
|
| 378 |
+
[0, -0.012, 0],
|
| 379 |
+
[-Math.PI / 2, 0, 0],
|
| 380 |
+
false,
|
| 381 |
+
true
|
| 382 |
+
);
|
| 383 |
+
|
| 384 |
+
// ---------------------------------------------------------------------
|
| 385 |
+
// Turntable and wooden tray
|
| 386 |
+
// ---------------------------------------------------------------------
|
| 387 |
+
|
| 388 |
+
const turntable = new THREE.Group();
|
| 389 |
+
turntable.name = "Rotating turntable";
|
| 390 |
+
scene.add(turntable);
|
| 391 |
+
|
| 392 |
+
addMesh(
|
| 393 |
+
new THREE.CylinderGeometry(3.08, 3.14, 0.1, 96),
|
| 394 |
+
materials.darkWood,
|
| 395 |
+
turntable,
|
| 396 |
+
"Turntable plinth",
|
| 397 |
+
[0, -0.04, 0]
|
| 398 |
+
);
|
| 399 |
+
|
| 400 |
+
addMesh(
|
| 401 |
+
new THREE.TorusGeometry(3.08, 0.025, 10, 96),
|
| 402 |
+
materials.wood,
|
| 403 |
+
turntable,
|
| 404 |
+
"Turntable rim",
|
| 405 |
+
[0, 0.012, 0],
|
| 406 |
+
[Math.PI / 2, 0, 0]
|
| 407 |
+
);
|
| 408 |
+
|
| 409 |
+
const tray = new THREE.Group();
|
| 410 |
+
tray.name = "Small wooden tray";
|
| 411 |
+
tray.position.y = 0.07;
|
| 412 |
+
turntable.add(tray);
|
| 413 |
+
|
| 414 |
+
addMesh(
|
| 415 |
+
new THREE.BoxGeometry(4.95, 0.16, 3.3),
|
| 416 |
+
materials.wood,
|
| 417 |
+
tray,
|
| 418 |
+
"Tray base"
|
| 419 |
+
);
|
| 420 |
+
|
| 421 |
+
addMesh(
|
| 422 |
+
new THREE.BoxGeometry(0.16, 0.36, 3.3),
|
| 423 |
+
materials.wood,
|
| 424 |
+
tray,
|
| 425 |
+
"Left tray rail",
|
| 426 |
+
[-2.39, 0, 0]
|
| 427 |
+
);
|
| 428 |
+
|
| 429 |
+
addMesh(
|
| 430 |
+
new THREE.BoxGeometry(0.16, 0.36, 3.3),
|
| 431 |
+
materials.wood,
|
| 432 |
+
tray,
|
| 433 |
+
"Right tray rail",
|
| 434 |
+
[2.39, 0, 0]
|
| 435 |
+
);
|
| 436 |
+
|
| 437 |
+
addMesh(
|
| 438 |
+
new THREE.BoxGeometry(4.83, 0.36, 0.16),
|
| 439 |
+
materials.wood,
|
| 440 |
+
tray,
|
| 441 |
+
"Front tray rail",
|
| 442 |
+
[0, 0, 1.59]
|
| 443 |
+
);
|
| 444 |
+
|
| 445 |
+
addMesh(
|
| 446 |
+
new THREE.BoxGeometry(4.83, 0.36, 0.16),
|
| 447 |
+
materials.wood,
|
| 448 |
+
tray,
|
| 449 |
+
"Back tray rail",
|
| 450 |
+
[0, 0, -1.59]
|
| 451 |
+
);
|
| 452 |
+
|
| 453 |
+
addMesh(
|
| 454 |
+
new THREE.BoxGeometry(4.68, 0.035, 3.08),
|
| 455 |
+
materials.wood,
|
| 456 |
+
tray,
|
| 457 |
+
"Tray floor"
|
| 458 |
+
);
|
| 459 |
+
|
| 460 |
+
// ---------------------------------------------------------------------
|
| 461 |
+
// Bottle construction
|
| 462 |
+
// ---------------------------------------------------------------------
|
| 463 |
+
|
| 464 |
+
const bottleProfile = [
|
| 465 |
+
new THREE.Vector2(0.0, 0.0),
|
| 466 |
+
new THREE.Vector2(0.23, 0.0),
|
| 467 |
+
new THREE.Vector2(0.33, 0.08),
|
| 468 |
+
new THREE.Vector2(0.41, 0.22),
|
| 469 |
+
new THREE.Vector2(0.43, 0.55),
|
| 470 |
+
new THREE.Vector2(0.43, 0.95),
|
| 471 |
+
new THREE.Vector2(0.4, 1.2),
|
| 472 |
+
new THREE.Vector2(0.31, 1.4),
|
| 473 |
+
new THREE.Vector2(0.22, 1.55),
|
| 474 |
+
new THREE.Vector2(0.17, 1.68),
|
| 475 |
+
new THREE.Vector2(0.17, 1.82)
|
| 476 |
+
];
|
| 477 |
+
|
| 478 |
+
function createLabelTexture() {
|
| 479 |
+
const canvas = document.createElement("canvas");
|
| 480 |
+
canvas.width = 256;
|
| 481 |
+
canvas.height = 128;
|
| 482 |
+
|
| 483 |
+
const context = canvas.getContext("2d");
|
| 484 |
+
|
| 485 |
+
context.fillStyle = "#f3e3bd";
|
| 486 |
+
context.fillRect(0, 0, 256, 128);
|
| 487 |
+
|
| 488 |
+
context.strokeStyle = "#b78b45";
|
| 489 |
+
context.lineWidth = 8;
|
| 490 |
+
context.strokeRect(9, 9, 238, 110);
|
| 491 |
+
|
| 492 |
+
context.fillStyle = "#59452d";
|
| 493 |
+
context.textAlign = "center";
|
| 494 |
+
context.textBaseline = "middle";
|
| 495 |
+
context.font = "700 42px Georgia, serif";
|
| 496 |
+
context.fillText("POTION", 128, 65);
|
| 497 |
+
|
| 498 |
+
const texture = new THREE.CanvasTexture(canvas);
|
| 499 |
+
texture.colorSpace = THREE.SRGBColorSpace;
|
| 500 |
+
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
|
| 501 |
+
|
| 502 |
+
return texture;
|
| 503 |
+
}
|
| 504 |
+
|
| 505 |
+
const labelTexture = createLabelTexture();
|
| 506 |
+
|
| 507 |
+
function createBottle(name, bodyColor, xPosition) {
|
| 508 |
+
const bottle = new THREE.Group();
|
| 509 |
+
bottle.name = name;
|
| 510 |
+
bottle.position.set(xPosition, 0.17, 0);
|
| 511 |
+
turntable.add(bottle);
|
| 512 |
+
|
| 513 |
+
const bodyMaterial = new THREE.MeshPhysicalMaterial({
|
| 514 |
+
color: bodyColor,
|
| 515 |
+
roughness: 0.22,
|
| 516 |
+
metalness: 0,
|
| 517 |
+
clearcoat: 0.65,
|
| 518 |
+
clearcoatRoughness: 0.24
|
| 519 |
+
});
|
| 520 |
+
|
| 521 |
+
addMesh(
|
| 522 |
+
new THREE.LatheGeometry(bottleProfile, 64),
|
| 523 |
+
bodyMaterial,
|
| 524 |
+
bottle,
|
| 525 |
+
`${name} bottle body`
|
| 526 |
+
);
|
| 527 |
+
|
| 528 |
+
addMesh(
|
| 529 |
+
new THREE.CylinderGeometry(0.17, 0.19, 0.42, 32),
|
| 530 |
+
materials.cork,
|
| 531 |
+
bottle,
|
| 532 |
+
`${name} cork`
|
| 533 |
+
);
|
| 534 |
+
|
| 535 |
+
addMesh(
|
| 536 |
+
new THREE.CylinderGeometry(0.172, 0.172, 0.025, 32),
|
| 537 |
+
materials.corkTop,
|
| 538 |
+
bottle,
|
| 539 |
+
`${name} cork top`
|
| 540 |
+
);
|
| 541 |
+
|
| 542 |
+
const label = addMesh(
|
| 543 |
+
new THREE.PlaneGeometry(0.48, 0.24),
|
| 544 |
+
new THREE.MeshStandardMaterial({
|
| 545 |
+
map: labelTexture,
|
| 546 |
+
roughness: 0.88
|
| 547 |
+
}),
|
| 548 |
+
bottle,
|
| 549 |
+
`${name} front label`,
|
| 550 |
+
[0, 0.77, 0.425]
|
| 551 |
+
);
|
| 552 |
+
|
| 553 |
+
label.castShadow = false;
|
| 554 |
+
|
| 555 |
+
return bottle;
|
| 556 |
+
}
|
| 557 |
+
|
| 558 |
+
createBottle("Crimson potion bottle", 0xc6353b, -1.25);
|
| 559 |
+
createBottle("Cobalt potion bottle", 0x245ad4, 0);
|
| 560 |
+
createBottle("Emerald potion bottle", 0x2d8d65, 1.25);
|
| 561 |
+
|
| 562 |
+
// ---------------------------------------------------------------------
|
| 563 |
+
// Direct mouse orbit controls — no external control modules
|
| 564 |
+
// ---------------------------------------------------------------------
|
| 565 |
+
|
| 566 |
+
let dragging = false;
|
| 567 |
+
let previousX = 0;
|
| 568 |
+
let previousY = 0;
|
| 569 |
+
|
| 570 |
+
const canvas = renderer.domElement;
|
| 571 |
+
|
| 572 |
+
canvas.addEventListener("pointerdown", (event) => {
|
| 573 |
+
if (event.button !== 0) return;
|
| 574 |
+
|
| 575 |
+
dragging = true;
|
| 576 |
+
previousX = event.clientX;
|
| 577 |
+
previousY = event.clientY;
|
| 578 |
+
canvas.setPointerCapture(event.pointerId);
|
| 579 |
+
canvas.classList.add("dragging");
|
| 580 |
+
});
|
| 581 |
+
|
| 582 |
+
canvas.addEventListener("pointermove", (event) => {
|
| 583 |
+
if (!dragging) return;
|
| 584 |
+
|
| 585 |
+
const deltaX = event.clientX - previousX;
|
| 586 |
+
const deltaY = event.clientY - previousY;
|
| 587 |
+
|
| 588 |
+
previousX = event.clientX;
|
| 589 |
+
previousY = event.clientY;
|
| 590 |
+
|
| 591 |
+
controls.yaw -= deltaX * 0.006;
|
| 592 |
+
controls.pitch = THREE.MathUtils.clamp(
|
| 593 |
+
controls.pitch + deltaY * 0.005,
|
| 594 |
+
0.25,
|
| 595 |
+
1.35
|
| 596 |
+
);
|
| 597 |
+
|
| 598 |
+
updateCamera();
|
| 599 |
+
});
|
| 600 |
+
|
| 601 |
+
function endDrag(event) {
|
| 602 |
+
dragging = false;
|
| 603 |
+
canvas.classList.remove("dragging");
|
| 604 |
+
|
| 605 |
+
if (event.pointerId !== undefined && canvas.hasPointerCapture(event.pointerId)) {
|
| 606 |
+
canvas.releasePointerCapture(event.pointerId);
|
| 607 |
+
}
|
| 608 |
+
}
|
| 609 |
+
|
| 610 |
+
canvas.addEventListener("pointerup", endDrag);
|
| 611 |
+
canvas.addEventListener("pointercancel", endDrag);
|
| 612 |
+
|
| 613 |
+
canvas.addEventListener(
|
| 614 |
+
"wheel",
|
| 615 |
+
(event) => {
|
| 616 |
+
event.preventDefault();
|
| 617 |
+
|
| 618 |
+
controls.distance = THREE.MathUtils.clamp(
|
| 619 |
+
controls.distance * Math.exp(event.deltaY * 0.001),
|
| 620 |
+
5.6,
|
| 621 |
+
13
|
| 622 |
+
);
|
| 623 |
+
|
| 624 |
+
updateCamera();
|
| 625 |
+
},
|
| 626 |
+
{ passive: false }
|
| 627 |
+
);
|
| 628 |
+
|
| 629 |
+
canvas.addEventListener("dblclick", () => {
|
| 630 |
+
controls.yaw = 0.58;
|
| 631 |
+
controls.pitch = 0.52;
|
| 632 |
+
controls.distance = 8.4;
|
| 633 |
+
updateCamera();
|
| 634 |
+
});
|
| 635 |
+
|
| 636 |
+
canvas.addEventListener("contextmenu", (event) => {
|
| 637 |
+
event.preventDefault();
|
| 638 |
+
});
|
| 639 |
+
|
| 640 |
+
// ---------------------------------------------------------------------
|
| 641 |
+
// Animation and UI
|
| 642 |
+
// ---------------------------------------------------------------------
|
| 643 |
+
|
| 644 |
+
let elapsed = 0;
|
| 645 |
+
let paused = false;
|
| 646 |
+
|
| 647 |
+
pauseButton.addEventListener("click", () => {
|
| 648 |
+
paused = !paused;
|
| 649 |
+
pauseButton.textContent = paused ? "Resume rotation" : "Pause rotation";
|
| 650 |
+
status.textContent = paused ? "Paused" : "Auto spin";
|
| 651 |
+
});
|
| 652 |
+
|
| 653 |
+
const clock = new THREE.Clock();
|
| 654 |
+
|
| 655 |
+
function animate() {
|
| 656 |
+
const delta = Math.min(clock.getDelta(), 0.05);
|
| 657 |
+
|
| 658 |
+
if (!paused) {
|
| 659 |
+
elapsed += delta;
|
| 660 |
+
}
|
| 661 |
+
|
| 662 |
+
turntable.rotation.y = elapsed * 0.28;
|
| 663 |
+
renderer.render(scene, camera);
|
| 664 |
+
}
|
| 665 |
+
|
| 666 |
+
renderer.setAnimationLoop(animate);
|
| 667 |
+
|
| 668 |
+
window.addEventListener("resize", () => {
|
| 669 |
+
camera.aspect = window.innerWidth / window.innerHeight;
|
| 670 |
+
camera.updateProjectionMatrix();
|
| 671 |
+
|
| 672 |
+
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
|
| 673 |
+
renderer.setSize(window.innerWidth, window.innerHeight);
|
| 674 |
+
});
|
| 675 |
+
</script>
|
| 676 |
+
</body>
|
| 677 |
+
</html>
|
source/potions.png
ADDED
|
Git LFS Details
|
source/tower.html
ADDED
|
@@ -0,0 +1,732 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Medieval Castle Guard Tower</title>
|
| 7 |
+
|
| 8 |
+
<style>
|
| 9 |
+
* {
|
| 10 |
+
box-sizing: border-box;
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
html,
|
| 14 |
+
body {
|
| 15 |
+
width: 100%;
|
| 16 |
+
height: 100%;
|
| 17 |
+
margin: 0;
|
| 18 |
+
overflow: hidden;
|
| 19 |
+
background: #b8ad98;
|
| 20 |
+
font-family: Georgia, "Times New Roman", serif;
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
canvas {
|
| 24 |
+
display: block;
|
| 25 |
+
width: 100%;
|
| 26 |
+
height: 100%;
|
| 27 |
+
cursor: grab;
|
| 28 |
+
touch-action: none;
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
canvas.dragging {
|
| 32 |
+
cursor: grabbing;
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
.title-card {
|
| 36 |
+
position: fixed;
|
| 37 |
+
top: 24px;
|
| 38 |
+
left: 26px;
|
| 39 |
+
z-index: 10;
|
| 40 |
+
max-width: min(390px, calc(100vw - 52px));
|
| 41 |
+
padding: 15px 18px;
|
| 42 |
+
color: #f4ead6;
|
| 43 |
+
background: linear-gradient(145deg, rgba(38, 31, 25, 0.88), rgba(65, 48, 34, 0.72));
|
| 44 |
+
border: 1px solid rgba(218, 184, 120, 0.55);
|
| 45 |
+
border-radius: 8px;
|
| 46 |
+
box-shadow: 0 12px 35px rgba(35, 26, 18, 0.25);
|
| 47 |
+
backdrop-filter: blur(8px);
|
| 48 |
+
pointer-events: none;
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
.title-card h1 {
|
| 52 |
+
margin: 0 0 5px;
|
| 53 |
+
font-size: 20px;
|
| 54 |
+
font-weight: 600;
|
| 55 |
+
letter-spacing: 0.04em;
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
.title-card p {
|
| 59 |
+
margin: 0;
|
| 60 |
+
color: #d8c7a8;
|
| 61 |
+
font-size: 12px;
|
| 62 |
+
line-height: 1.45;
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
.controls {
|
| 66 |
+
position: fixed;
|
| 67 |
+
right: 22px;
|
| 68 |
+
bottom: 22px;
|
| 69 |
+
z-index: 10;
|
| 70 |
+
display: flex;
|
| 71 |
+
align-items: center;
|
| 72 |
+
gap: 12px;
|
| 73 |
+
padding: 10px 12px;
|
| 74 |
+
color: #f4ead6;
|
| 75 |
+
background: rgba(38, 31, 25, 0.78);
|
| 76 |
+
border: 1px solid rgba(218, 184, 120, 0.45);
|
| 77 |
+
border-radius: 7px;
|
| 78 |
+
box-shadow: 0 8px 24px rgba(35, 26, 18, 0.2);
|
| 79 |
+
backdrop-filter: blur(8px);
|
| 80 |
+
font: 12px/1.35 Georgia, "Times New Roman", serif;
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
button {
|
| 84 |
+
appearance: none;
|
| 85 |
+
padding: 7px 10px;
|
| 86 |
+
color: #f4ead6;
|
| 87 |
+
background: rgba(218, 184, 120, 0.15);
|
| 88 |
+
border: 1px solid rgba(218, 184, 120, 0.55);
|
| 89 |
+
border-radius: 4px;
|
| 90 |
+
font: inherit;
|
| 91 |
+
cursor: pointer;
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
button:hover {
|
| 95 |
+
background: rgba(218, 184, 120, 0.28);
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
button:active {
|
| 99 |
+
transform: translateY(1px);
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
.hint {
|
| 103 |
+
color: #d8c7a8;
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
@media (max-width: 600px) {
|
| 107 |
+
.title-card {
|
| 108 |
+
top: 14px;
|
| 109 |
+
left: 14px;
|
| 110 |
+
padding: 11px 13px;
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
.title-card h1 {
|
| 114 |
+
font-size: 17px;
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
.controls {
|
| 118 |
+
right: 12px;
|
| 119 |
+
bottom: 12px;
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
.hint {
|
| 123 |
+
display: none;
|
| 124 |
+
}
|
| 125 |
+
}
|
| 126 |
+
</style>
|
| 127 |
+
</head>
|
| 128 |
+
|
| 129 |
+
<body>
|
| 130 |
+
<canvas id="scene" aria-label="Interactive 3D medieval castle guard tower"></canvas>
|
| 131 |
+
|
| 132 |
+
<div class="title-card">
|
| 133 |
+
<h1>Castle Guard Tower</h1>
|
| 134 |
+
<p>A stone watchtower with crenellations, an arched oak door, and a waving banner.</p>
|
| 135 |
+
</div>
|
| 136 |
+
|
| 137 |
+
<div class="controls">
|
| 138 |
+
<span class="hint">Drag to orbit · Scroll to zoom · Double-click to reset</span>
|
| 139 |
+
<button id="turntableButton" type="button" aria-pressed="false">Pause turntable</button>
|
| 140 |
+
</div>
|
| 141 |
+
|
| 142 |
+
<script type="module">
|
| 143 |
+
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
|
| 144 |
+
|
| 145 |
+
const canvas = document.querySelector("#scene");
|
| 146 |
+
const turntableButton = document.querySelector("#turntableButton");
|
| 147 |
+
|
| 148 |
+
// Renderer
|
| 149 |
+
const renderer = new THREE.WebGLRenderer({
|
| 150 |
+
canvas,
|
| 151 |
+
antialias: true,
|
| 152 |
+
powerPreference: "high-performance"
|
| 153 |
+
});
|
| 154 |
+
|
| 155 |
+
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
|
| 156 |
+
renderer.setSize(window.innerWidth, window.innerHeight);
|
| 157 |
+
renderer.outputColorSpace = THREE.SRGBColorSpace;
|
| 158 |
+
renderer.toneMapping = THREE.ACESFilmicToneMapping;
|
| 159 |
+
renderer.toneMappingExposure = 1.05;
|
| 160 |
+
renderer.shadowMap.enabled = true;
|
| 161 |
+
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
|
| 162 |
+
|
| 163 |
+
// Scene
|
| 164 |
+
const scene = new THREE.Scene();
|
| 165 |
+
scene.background = new THREE.Color(0xb8ad98);
|
| 166 |
+
scene.fog = new THREE.Fog(0xb8ad98, 18, 42);
|
| 167 |
+
|
| 168 |
+
const camera = new THREE.PerspectiveCamera(
|
| 169 |
+
42,
|
| 170 |
+
window.innerWidth / window.innerHeight,
|
| 171 |
+
0.1,
|
| 172 |
+
100
|
| 173 |
+
);
|
| 174 |
+
|
| 175 |
+
// Lighting
|
| 176 |
+
scene.add(new THREE.HemisphereLight(0xdde4dc, 0x69533e, 2.1));
|
| 177 |
+
|
| 178 |
+
const sun = new THREE.DirectionalLight(0xffe5b5, 3.2);
|
| 179 |
+
sun.position.set(-7, 11, 8);
|
| 180 |
+
sun.castShadow = true;
|
| 181 |
+
sun.shadow.mapSize.set(2048, 2048);
|
| 182 |
+
sun.shadow.camera.left = -10;
|
| 183 |
+
sun.shadow.camera.right = 10;
|
| 184 |
+
sun.shadow.camera.top = 12;
|
| 185 |
+
sun.shadow.camera.bottom = -8;
|
| 186 |
+
sun.shadow.camera.near = 1;
|
| 187 |
+
sun.shadow.camera.far = 30;
|
| 188 |
+
sun.shadow.bias = -0.00035;
|
| 189 |
+
scene.add(sun);
|
| 190 |
+
|
| 191 |
+
const fill = new THREE.DirectionalLight(0x9fb8c7, 0.75);
|
| 192 |
+
fill.position.set(7, 5, -8);
|
| 193 |
+
scene.add(fill);
|
| 194 |
+
|
| 195 |
+
// Materials
|
| 196 |
+
const materials = {
|
| 197 |
+
stone: new THREE.MeshStandardMaterial({
|
| 198 |
+
color: 0x8d816d,
|
| 199 |
+
roughness: 0.96
|
| 200 |
+
}),
|
| 201 |
+
stoneLight: new THREE.MeshStandardMaterial({
|
| 202 |
+
color: 0xa5977c,
|
| 203 |
+
roughness: 0.94
|
| 204 |
+
}),
|
| 205 |
+
stoneDark: new THREE.MeshStandardMaterial({
|
| 206 |
+
color: 0x685f4e,
|
| 207 |
+
roughness: 1
|
| 208 |
+
}),
|
| 209 |
+
wood: new THREE.MeshStandardMaterial({
|
| 210 |
+
color: 0x5b321d,
|
| 211 |
+
roughness: 0.88
|
| 212 |
+
}),
|
| 213 |
+
darkWood: new THREE.MeshStandardMaterial({
|
| 214 |
+
color: 0x2d170d,
|
| 215 |
+
roughness: 0.96
|
| 216 |
+
}),
|
| 217 |
+
iron: new THREE.MeshStandardMaterial({
|
| 218 |
+
color: 0x303438,
|
| 219 |
+
roughness: 0.55,
|
| 220 |
+
metalness: 0.72
|
| 221 |
+
}),
|
| 222 |
+
gold: new THREE.MeshStandardMaterial({
|
| 223 |
+
color: 0xd6a74c,
|
| 224 |
+
roughness: 0.42,
|
| 225 |
+
metalness: 0.65
|
| 226 |
+
}),
|
| 227 |
+
cloth: new THREE.MeshStandardMaterial({
|
| 228 |
+
color: 0xc75332,
|
| 229 |
+
roughness: 0.8,
|
| 230 |
+
side: THREE.DoubleSide
|
| 231 |
+
}),
|
| 232 |
+
ground: new THREE.MeshStandardMaterial({
|
| 233 |
+
color: 0xb6aa91,
|
| 234 |
+
roughness: 1
|
| 235 |
+
})
|
| 236 |
+
};
|
| 237 |
+
|
| 238 |
+
// Helper for adding named, shadowed meshes
|
| 239 |
+
function addMesh(geometry, material, position, parent, name) {
|
| 240 |
+
const mesh = new THREE.Mesh(geometry, material);
|
| 241 |
+
mesh.position.set(position[0], position[1], position[2]);
|
| 242 |
+
mesh.name = name;
|
| 243 |
+
mesh.castShadow = true;
|
| 244 |
+
mesh.receiveShadow = true;
|
| 245 |
+
parent.add(mesh);
|
| 246 |
+
return mesh;
|
| 247 |
+
}
|
| 248 |
+
|
| 249 |
+
// Ground plane, kept stationary while the tower rotates on its turntable
|
| 250 |
+
const ground = addMesh(
|
| 251 |
+
new THREE.PlaneGeometry(80, 80),
|
| 252 |
+
materials.ground,
|
| 253 |
+
[0, -0.045, 0],
|
| 254 |
+
scene,
|
| 255 |
+
"Plain ground plane"
|
| 256 |
+
);
|
| 257 |
+
ground.rotation.x = -Math.PI / 2;
|
| 258 |
+
ground.castShadow = false;
|
| 259 |
+
|
| 260 |
+
// Turntable and tower assembly
|
| 261 |
+
const turntable = new THREE.Group();
|
| 262 |
+
turntable.name = "Rotating turntable";
|
| 263 |
+
scene.add(turntable);
|
| 264 |
+
|
| 265 |
+
// Stone turntable base
|
| 266 |
+
addMesh(
|
| 267 |
+
new THREE.BoxGeometry(4.7, 0.18, 4.7),
|
| 268 |
+
materials.stoneDark,
|
| 269 |
+
[0, 0.09, 0],
|
| 270 |
+
turntable,
|
| 271 |
+
"Stone turntable base"
|
| 272 |
+
);
|
| 273 |
+
|
| 274 |
+
const tower = new THREE.Group();
|
| 275 |
+
turntable.add(tower);
|
| 276 |
+
|
| 277 |
+
// Foundation
|
| 278 |
+
addMesh(
|
| 279 |
+
new THREE.BoxGeometry(3.15, 0.55, 3.15),
|
| 280 |
+
materials.stoneLight,
|
| 281 |
+
[0, 0.43, 0],
|
| 282 |
+
tower,
|
| 283 |
+
"Tower foundation"
|
| 284 |
+
);
|
| 285 |
+
|
| 286 |
+
// Main tower body with a true arched opening
|
| 287 |
+
const towerShape = new THREE.Shape();
|
| 288 |
+
towerShape.moveTo(-1.35, 0);
|
| 289 |
+
towerShape.lineTo(1.35, 0);
|
| 290 |
+
towerShape.lineTo(1.35, 3.8);
|
| 291 |
+
towerShape.lineTo(-1.35, 3.8);
|
| 292 |
+
towerShape.closePath();
|
| 293 |
+
|
| 294 |
+
const doorOpening = new THREE.Path();
|
| 295 |
+
doorOpening.moveTo(-0.48, 0);
|
| 296 |
+
doorOpening.lineTo(0.48, 0);
|
| 297 |
+
doorOpening.lineTo(0.48, 1.45);
|
| 298 |
+
doorOpening.absarc(0, 1.45, 0.48, 0, Math.PI, false);
|
| 299 |
+
doorOpening.lineTo(-0.48, 0);
|
| 300 |
+
doorOpening.closePath();
|
| 301 |
+
towerShape.holes.push(doorOpening);
|
| 302 |
+
|
| 303 |
+
const towerBodyGeometry = new THREE.ExtrudeGeometry(towerShape, {
|
| 304 |
+
depth: 2.4,
|
| 305 |
+
bevelEnabled: false,
|
| 306 |
+
curveSegments: 16,
|
| 307 |
+
steps: 1
|
| 308 |
+
});
|
| 309 |
+
|
| 310 |
+
addMesh(
|
| 311 |
+
towerBodyGeometry,
|
| 312 |
+
materials.stone,
|
| 313 |
+
[0, 0.78, -1.2],
|
| 314 |
+
tower,
|
| 315 |
+
"Arched stone tower body"
|
| 316 |
+
);
|
| 317 |
+
|
| 318 |
+
// Dark interior visible through the opening
|
| 319 |
+
const interiorShape = new THREE.Shape();
|
| 320 |
+
interiorShape.moveTo(-0.47, 0);
|
| 321 |
+
interiorShape.lineTo(0.47, 0);
|
| 322 |
+
interiorShape.lineTo(0.47, 1.45);
|
| 323 |
+
interiorShape.absarc(0, 1.45, 0.47, 0, Math.PI, false);
|
| 324 |
+
interiorShape.lineTo(-0.47, 0);
|
| 325 |
+
interiorShape.closePath();
|
| 326 |
+
|
| 327 |
+
const interior = addMesh(
|
| 328 |
+
new THREE.ShapeGeometry(interiorShape, 16),
|
| 329 |
+
materials.darkWood,
|
| 330 |
+
[0, 0.78, -1.185],
|
| 331 |
+
tower,
|
| 332 |
+
"Dark tower interior"
|
| 333 |
+
);
|
| 334 |
+
interior.castShadow = false;
|
| 335 |
+
|
| 336 |
+
// Wooden arched door
|
| 337 |
+
const doorShape = new THREE.Shape();
|
| 338 |
+
doorShape.moveTo(-0.47, 0);
|
| 339 |
+
doorShape.lineTo(0.47, 0);
|
| 340 |
+
doorShape.lineTo(0.47, 1.45);
|
| 341 |
+
doorShape.absarc(0, 1.45, 0.47, 0, Math.PI, false);
|
| 342 |
+
doorShape.lineTo(-0.47, 0);
|
| 343 |
+
doorShape.closePath();
|
| 344 |
+
|
| 345 |
+
addMesh(
|
| 346 |
+
new THREE.ShapeGeometry(doorShape, 16),
|
| 347 |
+
materials.wood,
|
| 348 |
+
[0, 0.79, 1.205],
|
| 349 |
+
tower,
|
| 350 |
+
"Arched wooden door"
|
| 351 |
+
);
|
| 352 |
+
|
| 353 |
+
// Door frame
|
| 354 |
+
addMesh(
|
| 355 |
+
new THREE.BoxGeometry(0.13, 2.0, 0.14),
|
| 356 |
+
materials.stoneLight,
|
| 357 |
+
[-0.56, 1.78, 1.245],
|
| 358 |
+
tower,
|
| 359 |
+
"Left door jamb"
|
| 360 |
+
);
|
| 361 |
+
|
| 362 |
+
addMesh(
|
| 363 |
+
new THREE.BoxGeometry(0.13, 2.0, 0.14),
|
| 364 |
+
materials.stoneLight,
|
| 365 |
+
[0.56, 1.78, 1.245],
|
| 366 |
+
tower,
|
| 367 |
+
"Right door jamb"
|
| 368 |
+
);
|
| 369 |
+
|
| 370 |
+
const archFrame = addMesh(
|
| 371 |
+
new THREE.TorusGeometry(0.55, 0.075, 8, 24, Math.PI),
|
| 372 |
+
materials.stoneLight,
|
| 373 |
+
[0, 1.45, 1.27],
|
| 374 |
+
tower,
|
| 375 |
+
"Arched door frame"
|
| 376 |
+
);
|
| 377 |
+
|
| 378 |
+
addMesh(
|
| 379 |
+
new THREE.BoxGeometry(0.16, 0.28, 0.16),
|
| 380 |
+
materials.stoneLight,
|
| 381 |
+
[0, 2.02, 1.27],
|
| 382 |
+
tower,
|
| 383 |
+
"Door keystone"
|
| 384 |
+
);
|
| 385 |
+
|
| 386 |
+
// Iron door hardware
|
| 387 |
+
addMesh(
|
| 388 |
+
new THREE.BoxGeometry(0.045, 0.72, 0.035),
|
| 389 |
+
materials.iron,
|
| 390 |
+
[-0.31, 1.08, 1.235],
|
| 391 |
+
tower,
|
| 392 |
+
"Left iron door strap"
|
| 393 |
+
);
|
| 394 |
+
|
| 395 |
+
addMesh(
|
| 396 |
+
new THREE.BoxGeometry(0.045, 0.72, 0.035),
|
| 397 |
+
materials.iron,
|
| 398 |
+
[0.31, 1.08, 1.235],
|
| 399 |
+
tower,
|
| 400 |
+
"Right iron door strap"
|
| 401 |
+
);
|
| 402 |
+
|
| 403 |
+
addMesh(
|
| 404 |
+
new THREE.BoxGeometry(0.66, 0.045, 0.035),
|
| 405 |
+
materials.iron,
|
| 406 |
+
[0, 1.27, 1.235],
|
| 407 |
+
tower,
|
| 408 |
+
"Iron crossbar"
|
| 409 |
+
);
|
| 410 |
+
|
| 411 |
+
const handle = addMesh(
|
| 412 |
+
new THREE.SphereGeometry(0.055, 12, 8),
|
| 413 |
+
materials.iron,
|
| 414 |
+
[0.25, 1.35, 1.28],
|
| 415 |
+
tower,
|
| 416 |
+
"Door handle"
|
| 417 |
+
);
|
| 418 |
+
|
| 419 |
+
// Alternating corner quoins
|
| 420 |
+
for (const x of [-1.24, 1.24]) {
|
| 421 |
+
for (const z of [-1.02, 1.02]) {
|
| 422 |
+
for (let row = 0; row < 6; row++) {
|
| 423 |
+
const material = (row + (x > 0 ? 1 : 0)) % 2 === 0
|
| 424 |
+
? materials.stoneLight
|
| 425 |
+
: materials.stone;
|
| 426 |
+
|
| 427 |
+
addMesh(
|
| 428 |
+
new THREE.BoxGeometry(0.3, 0.36, 0.3),
|
| 429 |
+
material,
|
| 430 |
+
[x, 1.08 + row * 0.42, z],
|
| 431 |
+
tower,
|
| 432 |
+
`Corner quoin ${x > 0 ? "right" : "left"}`
|
| 433 |
+
);
|
| 434 |
+
}
|
| 435 |
+
}
|
| 436 |
+
}
|
| 437 |
+
|
| 438 |
+
// Side buttresses
|
| 439 |
+
for (const x of [-1.45, 1.45]) {
|
| 440 |
+
addMesh(
|
| 441 |
+
new THREE.BoxGeometry(0.28, 2.9, 2.45),
|
| 442 |
+
materials.stoneDark,
|
| 443 |
+
[x, 2.55, 0],
|
| 444 |
+
tower,
|
| 445 |
+
"Side buttress"
|
| 446 |
+
);
|
| 447 |
+
}
|
| 448 |
+
|
| 449 |
+
// Parapet walkway
|
| 450 |
+
addMesh(
|
| 451 |
+
new THREE.BoxGeometry(2.8, 0.24, 2.5),
|
| 452 |
+
materials.stoneLight,
|
| 453 |
+
[0, 4.72, 0],
|
| 454 |
+
tower,
|
| 455 |
+
"Top parapet walkway"
|
| 456 |
+
);
|
| 457 |
+
|
| 458 |
+
// Front and back crenellations
|
| 459 |
+
for (const z of [-1.18, 1.18]) {
|
| 460 |
+
for (let i = 0; i < 5; i++) {
|
| 461 |
+
const x = -1.05 + i * 0.42;
|
| 462 |
+
|
| 463 |
+
addMesh(
|
| 464 |
+
new THREE.BoxGeometry(0.68, 0.7, 0.46),
|
| 465 |
+
materials.stone,
|
| 466 |
+
[x, 5.12, z],
|
| 467 |
+
tower,
|
| 468 |
+
`Front/back crenellation ${i + 1}`
|
| 469 |
+
);
|
| 470 |
+
}
|
| 471 |
+
}
|
| 472 |
+
|
| 473 |
+
// Side crenellations
|
| 474 |
+
for (const x of [-1.35, 1.35]) {
|
| 475 |
+
for (let i = 0; i < 3; i++) {
|
| 476 |
+
const z = -0.72 + i * 0.72;
|
| 477 |
+
|
| 478 |
+
addMesh(
|
| 479 |
+
new THREE.BoxGeometry(0.46, 0.7, 0.68),
|
| 480 |
+
materials.stone,
|
| 481 |
+
[x, 5.12, z],
|
| 482 |
+
tower,
|
| 483 |
+
`Side crenellation ${i + 1}`
|
| 484 |
+
);
|
| 485 |
+
}
|
| 486 |
+
}
|
| 487 |
+
|
| 488 |
+
// Four small corner turrets
|
| 489 |
+
for (const x of [-1.2, 1.2]) {
|
| 490 |
+
for (const z of [-1.02, 1.02]) {
|
| 491 |
+
addMesh(
|
| 492 |
+
new THREE.BoxGeometry(0.55, 1.05, 0.55),
|
| 493 |
+
materials.stoneDark,
|
| 494 |
+
[x, 5.455, z],
|
| 495 |
+
tower,
|
| 496 |
+
"Corner turret"
|
| 497 |
+
);
|
| 498 |
+
|
| 499 |
+
for (let i = 0; i < 3; i++) {
|
| 500 |
+
addMesh(
|
| 501 |
+
new THREE.BoxGeometry(0.62, 0.55, 0.62),
|
| 502 |
+
materials.stone,
|
| 503 |
+
[x, 6.1 + i * 0.18, z],
|
| 504 |
+
tower,
|
| 505 |
+
"Corner turret crenellation"
|
| 506 |
+
);
|
| 507 |
+
}
|
| 508 |
+
}
|
| 509 |
+
}
|
| 510 |
+
|
| 511 |
+
// Flagpole
|
| 512 |
+
const poleBase = 5.89;
|
| 513 |
+
const poleHeight = 1.15;
|
| 514 |
+
|
| 515 |
+
addMesh(
|
| 516 |
+
new THREE.CylinderGeometry(0.035, 0.045, poleHeight, 10),
|
| 517 |
+
materials.iron,
|
| 518 |
+
[0, poleBase + poleHeight / 2, 0],
|
| 519 |
+
tower,
|
| 520 |
+
"Flagpole"
|
| 521 |
+
);
|
| 522 |
+
|
| 523 |
+
addMesh(
|
| 524 |
+
new THREE.SphereGeometry(0.065, 12, 8),
|
| 525 |
+
materials.gold,
|
| 526 |
+
[0, poleBase + poleHeight + 0.02, 0],
|
| 527 |
+
tower,
|
| 528 |
+
"Pole finial"
|
| 529 |
+
);
|
| 530 |
+
|
| 531 |
+
// Animated flag geometry
|
| 532 |
+
const flagWidth = 1.35;
|
| 533 |
+
const flagHeight = 1.06;
|
| 534 |
+
const flagColumns = 16;
|
| 535 |
+
const flagRows = 8;
|
| 536 |
+
const flagVertexCount = (flagColumns + 1) * (flagRows + 1);
|
| 537 |
+
|
| 538 |
+
const flagPositions = new Float32Array(flagVertexCount * 3);
|
| 539 |
+
const flagUVs = new Float32Array(flagVertexCount * 2);
|
| 540 |
+
const flagIndices = [];
|
| 541 |
+
|
| 542 |
+
for (let row = 0; row <= flagRows; row++) {
|
| 543 |
+
for (let column = 0; column <= flagColumns; column++) {
|
| 544 |
+
const vertex = row * (flagColumns + 1) + column;
|
| 545 |
+
const u = column / flagColumns;
|
| 546 |
+
const v = row / flagRows;
|
| 547 |
+
|
| 548 |
+
flagPositions[vertex * 3] = u * flagWidth;
|
| 549 |
+
flagPositions[vertex * 3 + 1] = v * flagHeight;
|
| 550 |
+
flagPositions[vertex * 3 + 2] = 0;
|
| 551 |
+
|
| 552 |
+
flagUVs[vertex * 2] = u;
|
| 553 |
+
flagUVs[vertex * 2 + 1] = v;
|
| 554 |
+
}
|
| 555 |
+
}
|
| 556 |
+
|
| 557 |
+
for (let row = 0; row < flagRows; row++) {
|
| 558 |
+
for (let column = 0; column < flagColumns; column++) {
|
| 559 |
+
const a = row * (flagColumns + 1) + column;
|
| 560 |
+
const b = a + 1;
|
| 561 |
+
const c = a + flagColumns + 1;
|
| 562 |
+
const d = c + 1;
|
| 563 |
+
|
| 564 |
+
flagIndices.push(a, c, b, b, c, d);
|
| 565 |
+
}
|
| 566 |
+
}
|
| 567 |
+
|
| 568 |
+
const flagGeometry = new THREE.BufferGeometry();
|
| 569 |
+
flagGeometry.setAttribute(
|
| 570 |
+
"position",
|
| 571 |
+
new THREE.BufferAttribute(flagPositions, 3)
|
| 572 |
+
);
|
| 573 |
+
flagGeometry.setAttribute(
|
| 574 |
+
"uv",
|
| 575 |
+
new THREE.BufferAttribute(flagUVs, 2)
|
| 576 |
+
);
|
| 577 |
+
flagGeometry.setIndex(flagIndices);
|
| 578 |
+
flagGeometry.computeVertexNormals();
|
| 579 |
+
|
| 580 |
+
const flag = addMesh(
|
| 581 |
+
flagGeometry,
|
| 582 |
+
materials.cloth,
|
| 583 |
+
[0, 5.98, 0],
|
| 584 |
+
tower,
|
| 585 |
+
"Waving banner flag"
|
| 586 |
+
);
|
| 587 |
+
flag.castShadow = true;
|
| 588 |
+
|
| 589 |
+
// Small gold emblem attached to the flag
|
| 590 |
+
const emblem = addMesh(
|
| 591 |
+
new THREE.CircleGeometry(0.115, 20),
|
| 592 |
+
materials.gold,
|
| 593 |
+
[0.27, 0.63, 0.115],
|
| 594 |
+
tower,
|
| 595 |
+
"Golden flag emblem"
|
| 596 |
+
);
|
| 597 |
+
emblem.castShadow = false;
|
| 598 |
+
|
| 599 |
+
// Custom orbit camera controls
|
| 600 |
+
const target = new THREE.Vector3(0, 3.2, 0);
|
| 601 |
+
const spherical = new THREE.Spherical(10.8, 1.24, 0.72);
|
| 602 |
+
|
| 603 |
+
let dragging = false;
|
| 604 |
+
let previousX = 0;
|
| 605 |
+
let previousY = 0;
|
| 606 |
+
|
| 607 |
+
function updateCamera() {
|
| 608 |
+
spherical.phi = THREE.MathUtils.clamp(spherical.phi, 0.45, 1.52);
|
| 609 |
+
spherical.radius = THREE.MathUtils.clamp(spherical.radius, 6.5, 18);
|
| 610 |
+
|
| 611 |
+
camera.position.setFromSpherical(spherical).add(target);
|
| 612 |
+
camera.lookAt(target);
|
| 613 |
+
}
|
| 614 |
+
|
| 615 |
+
function resetCamera() {
|
| 616 |
+
spherical.set(10.8, 1.24, 0.72);
|
| 617 |
+
target.set(0, 3.2, 0);
|
| 618 |
+
updateCamera();
|
| 619 |
+
}
|
| 620 |
+
|
| 621 |
+
canvas.addEventListener("pointerdown", (event) => {
|
| 622 |
+
dragging = true;
|
| 623 |
+
previousX = event.clientX;
|
| 624 |
+
previousY = event.clientY;
|
| 625 |
+
canvas.setPointerCapture(event.pointerId);
|
| 626 |
+
canvas.classList.add("dragging");
|
| 627 |
+
});
|
| 628 |
+
|
| 629 |
+
canvas.addEventListener("pointermove", (event) => {
|
| 630 |
+
if (!dragging) return;
|
| 631 |
+
|
| 632 |
+
const deltaX = event.clientX - previousX;
|
| 633 |
+
const deltaY = event.clientY - previousY;
|
| 634 |
+
|
| 635 |
+
previousX = event.clientX;
|
| 636 |
+
previousY = event.clientY;
|
| 637 |
+
|
| 638 |
+
spherical.theta -= deltaX * 0.006;
|
| 639 |
+
spherical.phi -= deltaY * 0.005;
|
| 640 |
+
|
| 641 |
+
updateCamera();
|
| 642 |
+
});
|
| 643 |
+
|
| 644 |
+
function stopDragging(event) {
|
| 645 |
+
dragging = false;
|
| 646 |
+
canvas.classList.remove("dragging");
|
| 647 |
+
|
| 648 |
+
if (event && canvas.hasPointerCapture(event.pointerId)) {
|
| 649 |
+
canvas.releasePointerCapture(event.pointerId);
|
| 650 |
+
}
|
| 651 |
+
}
|
| 652 |
+
|
| 653 |
+
canvas.addEventListener("pointerup", stopDragging);
|
| 654 |
+
canvas.addEventListener("pointercancel", stopDragging);
|
| 655 |
+
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
|
| 656 |
+
|
| 657 |
+
canvas.addEventListener("wheel", (event) => {
|
| 658 |
+
event.preventDefault();
|
| 659 |
+
spherical.radius *= Math.exp(event.deltaY * 0.001);
|
| 660 |
+
updateCamera();
|
| 661 |
+
}, { passive: false });
|
| 662 |
+
|
| 663 |
+
canvas.addEventListener("dblclick", resetCamera);
|
| 664 |
+
|
| 665 |
+
// Turntable and pause controls
|
| 666 |
+
let autoRotate = true;
|
| 667 |
+
|
| 668 |
+
function toggleTurntable() {
|
| 669 |
+
autoRotate = !autoRotate;
|
| 670 |
+
turntableButton.textContent = autoRotate ? "Pause turntable" : "Resume turntable";
|
| 671 |
+
turntableButton.setAttribute("aria-pressed", String(!autoRotate));
|
| 672 |
+
}
|
| 673 |
+
|
| 674 |
+
turntableButton.addEventListener("click", toggleTurntable);
|
| 675 |
+
|
| 676 |
+
window.addEventListener("keydown", (event) => {
|
| 677 |
+
if (event.code === "Space") {
|
| 678 |
+
event.preventDefault();
|
| 679 |
+
toggleTurntable();
|
| 680 |
+
}
|
| 681 |
+
|
| 682 |
+
if (event.code === "KeyR") {
|
| 683 |
+
resetCamera();
|
| 684 |
+
}
|
| 685 |
+
});
|
| 686 |
+
|
| 687 |
+
window.addEventListener("resize", () => {
|
| 688 |
+
camera.aspect = window.innerWidth / window.innerHeight;
|
| 689 |
+
camera.updateProjectionMatrix();
|
| 690 |
+
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
|
| 691 |
+
renderer.setSize(window.innerWidth, window.innerHeight);
|
| 692 |
+
});
|
| 693 |
+
|
| 694 |
+
// Animation
|
| 695 |
+
const clock = new THREE.Clock();
|
| 696 |
+
let elapsed = 0;
|
| 697 |
+
|
| 698 |
+
renderer.setAnimationLoop(() => {
|
| 699 |
+
const delta = Math.min(clock.getDelta(), 0.05);
|
| 700 |
+
elapsed += delta;
|
| 701 |
+
|
| 702 |
+
if (autoRotate) {
|
| 703 |
+
turntable.rotation.y += delta * 0.105;
|
| 704 |
+
}
|
| 705 |
+
|
| 706 |
+
// Update the flag's vertices each frame
|
| 707 |
+
const positions = flagGeometry.attributes.position;
|
| 708 |
+
|
| 709 |
+
for (let vertex = 0; vertex < flagVertexCount; vertex++) {
|
| 710 |
+
const x = positions.getX(vertex);
|
| 711 |
+
const y = positions.getY(vertex);
|
| 712 |
+
const normalizedY = y / flagHeight;
|
| 713 |
+
|
| 714 |
+
const wave =
|
| 715 |
+
Math.sin(x * 4.2 - elapsed * 2.35) * 0.21 * normalizedY +
|
| 716 |
+
Math.sin((x + flagWidth / 2) * 6.0 - elapsed * 3.1) *
|
| 717 |
+
0.075 *
|
| 718 |
+
normalizedY;
|
| 719 |
+
|
| 720 |
+
positions.setZ(vertex, wave);
|
| 721 |
+
}
|
| 722 |
+
|
| 723 |
+
positions.needsUpdate = true;
|
| 724 |
+
flagGeometry.computeVertexNormals();
|
| 725 |
+
|
| 726 |
+
renderer.render(scene, camera);
|
| 727 |
+
});
|
| 728 |
+
|
| 729 |
+
resetCamera();
|
| 730 |
+
</script>
|
| 731 |
+
</body>
|
| 732 |
+
</html>
|
source/tower.png
ADDED
|
Git LFS Details
|
source/voxel-goblin.html
ADDED
|
@@ -0,0 +1,768 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Swamp Goblin — Voxel Enemy</title>
|
| 7 |
+
|
| 8 |
+
<style>
|
| 9 |
+
:root {
|
| 10 |
+
color-scheme: dark;
|
| 11 |
+
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
|
| 12 |
+
BlinkMacSystemFont, "Segoe UI", sans-serif;
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
* {
|
| 16 |
+
box-sizing: border-box;
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
html,
|
| 20 |
+
body {
|
| 21 |
+
width: 100%;
|
| 22 |
+
height: 100%;
|
| 23 |
+
margin: 0;
|
| 24 |
+
overflow: hidden;
|
| 25 |
+
background: #789887;
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
#stage {
|
| 29 |
+
position: fixed;
|
| 30 |
+
inset: 0;
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
canvas {
|
| 34 |
+
display: block;
|
| 35 |
+
width: 100%;
|
| 36 |
+
height: 100%;
|
| 37 |
+
cursor: grab;
|
| 38 |
+
touch-action: none;
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
canvas:active {
|
| 42 |
+
cursor: grabbing;
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
.vignette {
|
| 46 |
+
position: fixed;
|
| 47 |
+
inset: 0;
|
| 48 |
+
pointer-events: none;
|
| 49 |
+
background:
|
| 50 |
+
radial-gradient(
|
| 51 |
+
ellipse at 50% 45%,
|
| 52 |
+
transparent 45%,
|
| 53 |
+
rgba(17, 28, 22, 0.22) 100%
|
| 54 |
+
);
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
.hud {
|
| 58 |
+
position: fixed;
|
| 59 |
+
top: 24px;
|
| 60 |
+
left: 24px;
|
| 61 |
+
z-index: 2;
|
| 62 |
+
max-width: min(360px, calc(100vw - 48px));
|
| 63 |
+
padding: 16px 18px;
|
| 64 |
+
color: #f2f4df;
|
| 65 |
+
background: rgba(20, 31, 24, 0.76);
|
| 66 |
+
border: 1px solid rgba(230, 235, 196, 0.2);
|
| 67 |
+
border-radius: 14px;
|
| 68 |
+
box-shadow: 0 14px 40px rgba(15, 26, 20, 0.22);
|
| 69 |
+
backdrop-filter: blur(12px);
|
| 70 |
+
pointer-events: none;
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
.eyebrow {
|
| 74 |
+
margin: 0 0 6px;
|
| 75 |
+
color: #b8ca91;
|
| 76 |
+
font-size: 11px;
|
| 77 |
+
font-weight: 800;
|
| 78 |
+
letter-spacing: 0.18em;
|
| 79 |
+
text-transform: uppercase;
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
h1 {
|
| 83 |
+
margin: 0;
|
| 84 |
+
font-size: clamp(23px, 4vw, 34px);
|
| 85 |
+
line-height: 1;
|
| 86 |
+
letter-spacing: -0.035em;
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
.subtitle {
|
| 90 |
+
margin: 8px 0 0;
|
| 91 |
+
color: rgba(242, 244, 223, 0.68);
|
| 92 |
+
font-size: 13px;
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
.controls {
|
| 96 |
+
position: fixed;
|
| 97 |
+
right: 24px;
|
| 98 |
+
bottom: 24px;
|
| 99 |
+
z-index: 3;
|
| 100 |
+
display: flex;
|
| 101 |
+
align-items: center;
|
| 102 |
+
gap: 12px;
|
| 103 |
+
padding: 10px 12px;
|
| 104 |
+
color: rgba(245, 247, 229, 0.82);
|
| 105 |
+
background: rgba(20, 31, 24, 0.72);
|
| 106 |
+
border: 1px solid rgba(230, 235, 196, 0.18);
|
| 107 |
+
border-radius: 12px;
|
| 108 |
+
box-shadow: 0 12px 35px rgba(15, 26, 20, 0.2);
|
| 109 |
+
backdrop-filter: blur(10px);
|
| 110 |
+
font-size: 12px;
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
#pause {
|
| 114 |
+
appearance: none;
|
| 115 |
+
padding: 8px 12px;
|
| 116 |
+
color: #203025;
|
| 117 |
+
background: #b8ca91;
|
| 118 |
+
border: 0;
|
| 119 |
+
border-radius: 8px;
|
| 120 |
+
font: inherit;
|
| 121 |
+
font-weight: 800;
|
| 122 |
+
cursor: pointer;
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
#pause:hover {
|
| 126 |
+
background: #d2dfb0;
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
#hint {
|
| 130 |
+
position: fixed;
|
| 131 |
+
left: 50%;
|
| 132 |
+
bottom: 24px;
|
| 133 |
+
z-index: 2;
|
| 134 |
+
transform: translateX(-50%);
|
| 135 |
+
padding: 8px 12px;
|
| 136 |
+
color: rgba(245, 247, 229, 0.72);
|
| 137 |
+
background: rgba(20, 31, 24, 0.55);
|
| 138 |
+
border: 1px solid rgba(230, 235, 196, 0.12);
|
| 139 |
+
border-radius: 999px;
|
| 140 |
+
box-shadow: 0 8px 25px rgba(15, 26, 20, 0.15);
|
| 141 |
+
backdrop-filter: blur(8px);
|
| 142 |
+
font-size: 11px;
|
| 143 |
+
white-space: nowrap;
|
| 144 |
+
pointer-events: none;
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
@media (max-width: 640px) {
|
| 148 |
+
.hud {
|
| 149 |
+
top: 14px;
|
| 150 |
+
left: 14px;
|
| 151 |
+
padding: 12px 14px;
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
.subtitle {
|
| 155 |
+
display: none;
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
.controls {
|
| 159 |
+
right: 14px;
|
| 160 |
+
bottom: 14px;
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
#hint {
|
| 164 |
+
display: none;
|
| 165 |
+
}
|
| 166 |
+
}
|
| 167 |
+
</style>
|
| 168 |
+
</head>
|
| 169 |
+
|
| 170 |
+
<body>
|
| 171 |
+
<div id="stage"></div>
|
| 172 |
+
<div class="vignette"></div>
|
| 173 |
+
|
| 174 |
+
<section class="hud" aria-label="Scene information">
|
| 175 |
+
<p class="eyebrow">Voxel Enemy Archive</p>
|
| 176 |
+
<h1>Swamp Goblin</h1>
|
| 177 |
+
<p class="subtitle">Big-eared woodland raider with a leather vest and spiked club.</p>
|
| 178 |
+
</section>
|
| 179 |
+
|
| 180 |
+
<div id="hint">Drag to orbit · Scroll to zoom · Double-click to reset</div>
|
| 181 |
+
|
| 182 |
+
<div class="controls">
|
| 183 |
+
<button id="pause" type="button">Pause turntable</button>
|
| 184 |
+
<span>Auto-rotating</span>
|
| 185 |
+
</div>
|
| 186 |
+
|
| 187 |
+
<script type="module">
|
| 188 |
+
import * as THREE from
|
| 189 |
+
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
|
| 190 |
+
|
| 191 |
+
const stage = document.getElementById("stage");
|
| 192 |
+
const pauseButton = document.getElementById("pause");
|
| 193 |
+
|
| 194 |
+
// -------------------------------------------------------------------------
|
| 195 |
+
// Renderer, scene, camera
|
| 196 |
+
// -------------------------------------------------------------------------
|
| 197 |
+
|
| 198 |
+
const renderer = new THREE.WebGLRenderer({
|
| 199 |
+
antialias: true,
|
| 200 |
+
alpha: false,
|
| 201 |
+
powerPreference: "high-performance"
|
| 202 |
+
});
|
| 203 |
+
|
| 204 |
+
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
|
| 205 |
+
renderer.setSize(window.innerWidth, window.innerHeight);
|
| 206 |
+
renderer.outputColorSpace = THREE.SRGBColorSpace;
|
| 207 |
+
renderer.toneMapping = THREE.ACESFilmicToneMapping;
|
| 208 |
+
renderer.toneMappingExposure = 1.05;
|
| 209 |
+
renderer.shadowMap.enabled = true;
|
| 210 |
+
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
|
| 211 |
+
renderer.domElement.setAttribute(
|
| 212 |
+
"aria-label",
|
| 213 |
+
"Interactive 3D voxel swamp goblin enemy"
|
| 214 |
+
);
|
| 215 |
+
stage.appendChild(renderer.domElement);
|
| 216 |
+
|
| 217 |
+
const scene = new THREE.Scene();
|
| 218 |
+
scene.background = new THREE.Color(0x789887);
|
| 219 |
+
scene.fog = new THREE.Fog(0x789887, 19, 42);
|
| 220 |
+
|
| 221 |
+
const camera = new THREE.PerspectiveCamera(
|
| 222 |
+
38,
|
| 223 |
+
window.innerWidth / window.innerHeight,
|
| 224 |
+
0.1,
|
| 225 |
+
100
|
| 226 |
+
);
|
| 227 |
+
|
| 228 |
+
const cameraTarget = new THREE.Vector3(0, 2.25, 0);
|
| 229 |
+
const cameraView = {
|
| 230 |
+
theta: 0.72,
|
| 231 |
+
phi: 1.12,
|
| 232 |
+
radius: 12.6
|
| 233 |
+
};
|
| 234 |
+
|
| 235 |
+
function updateCamera() {
|
| 236 |
+
const sinPhi = Math.sin(cameraView.phi);
|
| 237 |
+
|
| 238 |
+
camera.position.set(
|
| 239 |
+
cameraTarget.x +
|
| 240 |
+
cameraView.radius * sinPhi * Math.sin(cameraView.theta),
|
| 241 |
+
cameraTarget.y + cameraView.radius * Math.cos(cameraView.phi),
|
| 242 |
+
cameraTarget.z +
|
| 243 |
+
cameraView.radius * sinPhi * Math.cos(cameraView.theta)
|
| 244 |
+
);
|
| 245 |
+
|
| 246 |
+
camera.lookAt(cameraTarget);
|
| 247 |
+
}
|
| 248 |
+
|
| 249 |
+
updateCamera();
|
| 250 |
+
|
| 251 |
+
// -------------------------------------------------------------------------
|
| 252 |
+
// Lighting
|
| 253 |
+
// -------------------------------------------------------------------------
|
| 254 |
+
|
| 255 |
+
const hemisphere = new THREE.HemisphereLight(
|
| 256 |
+
0xd8ead4,
|
| 257 |
+
0x344336,
|
| 258 |
+
1.75
|
| 259 |
+
);
|
| 260 |
+
scene.add(hemisphere);
|
| 261 |
+
|
| 262 |
+
const keyLight = new THREE.DirectionalLight(0xffe3a6, 3.2);
|
| 263 |
+
keyLight.position.set(6, 10, 8);
|
| 264 |
+
keyLight.castShadow = true;
|
| 265 |
+
keyLight.shadow.mapSize.set(2048, 2048);
|
| 266 |
+
keyLight.shadow.camera.near = 1;
|
| 267 |
+
keyLight.shadow.camera.far = 30;
|
| 268 |
+
keyLight.shadow.camera.left = -7;
|
| 269 |
+
keyLight.shadow.camera.right = 7;
|
| 270 |
+
keyLight.shadow.camera.top = 8;
|
| 271 |
+
keyLight.shadow.camera.bottom = -5;
|
| 272 |
+
keyLight.shadow.bias = -0.0004;
|
| 273 |
+
keyLight.shadow.normalBias = 0.025;
|
| 274 |
+
keyLight.target.position.set(0, 2, 0);
|
| 275 |
+
scene.add(keyLight, keyLight.target);
|
| 276 |
+
|
| 277 |
+
const fillLight = new THREE.DirectionalLight(0x9fc9d0, 1.1);
|
| 278 |
+
fillLight.position.set(-7, 5, 4);
|
| 279 |
+
scene.add(fillLight);
|
| 280 |
+
|
| 281 |
+
const rimLight = new THREE.DirectionalLight(0xffc96e, 0.8);
|
| 282 |
+
rimLight.position.set(1, 4, -8);
|
| 283 |
+
scene.add(rimLight);
|
| 284 |
+
|
| 285 |
+
// -------------------------------------------------------------------------
|
| 286 |
+
// Plain ground plane
|
| 287 |
+
// -------------------------------------------------------------------------
|
| 288 |
+
|
| 289 |
+
const ground = new THREE.Mesh(
|
| 290 |
+
new THREE.PlaneGeometry(80, 80),
|
| 291 |
+
new THREE.MeshStandardMaterial({
|
| 292 |
+
color: 0x53624c,
|
| 293 |
+
roughness: 1,
|
| 294 |
+
metalness: 0
|
| 295 |
+
})
|
| 296 |
+
);
|
| 297 |
+
|
| 298 |
+
ground.rotation.x = -Math.PI / 2;
|
| 299 |
+
ground.position.y = -0.025;
|
| 300 |
+
ground.receiveShadow = true;
|
| 301 |
+
scene.add(ground);
|
| 302 |
+
|
| 303 |
+
// -------------------------------------------------------------------------
|
| 304 |
+
// Voxel construction
|
| 305 |
+
//
|
| 306 |
+
// Every visible part of the goblin is assembled from axis-aligned boxes.
|
| 307 |
+
// Instanced rendering keeps the block count manageable while preserving
|
| 308 |
+
// clear gaps, shadows, and individual cubic geometry.
|
| 309 |
+
// -------------------------------------------------------------------------
|
| 310 |
+
|
| 311 |
+
const model = new THREE.Group();
|
| 312 |
+
model.rotation.y = -0.1;
|
| 313 |
+
|
| 314 |
+
const voxels = [];
|
| 315 |
+
|
| 316 |
+
function addVoxel(x, y, z, sx, sy, sz, color) {
|
| 317 |
+
voxels.push({ x, y, z, sx, sy, sz, color });
|
| 318 |
+
}
|
| 319 |
+
|
| 320 |
+
const skin = 0x8b954e;
|
| 321 |
+
const skinLight = 0x9da353;
|
| 322 |
+
const skinDark = 0x747e3f;
|
| 323 |
+
const earOuter = 0x68763d;
|
| 324 |
+
const earInner = 0x9ca258;
|
| 325 |
+
const leather = 0x4b2d20;
|
| 326 |
+
const leatherDark = 0x2d1c17;
|
| 327 |
+
const leatherTrim = 0x714633;
|
| 328 |
+
const brass = 0xb88a3d;
|
| 329 |
+
const clubWood = 0x764723;
|
| 330 |
+
const clubLight = 0xb8773e;
|
| 331 |
+
const clubDark = 0x57321b;
|
| 332 |
+
const eyeBlack = 0x11150e;
|
| 333 |
+
const eyeIris = 0xe0b847;
|
| 334 |
+
const eyeGlint = 0xfff3b0;
|
| 335 |
+
const hair = 0x263b2b;
|
| 336 |
+
|
| 337 |
+
// Boots and feet.
|
| 338 |
+
for (const side of [-1, 1]) {
|
| 339 |
+
const x = side * 0.43;
|
| 340 |
+
|
| 341 |
+
addVoxel(x, 0.13, 0.25, 0.48, 0.26, 0.58, clubDark);
|
| 342 |
+
addVoxel(x, 0.29, 0.25, 0.42, 0.18, 0.54, leather);
|
| 343 |
+
addVoxel(x, 0.40, 0.04, 0.23, 0.22, 0.50, skin);
|
| 344 |
+
addVoxel(x, 0.40, 0.38, 0.23, 0.22, 0.20, skinLight);
|
| 345 |
+
addVoxel(x - 0.10, 0.40, 0.42, 0.16, 0.16, 0.16, skin);
|
| 346 |
+
}
|
| 347 |
+
|
| 348 |
+
// Legs and hips.
|
| 349 |
+
for (const side of [-1, 1]) {
|
| 350 |
+
for (let y = 0.58; y <= 1.73; y += 0.23) {
|
| 351 |
+
addVoxel(side * 0.36, y, 0.02, 0.22, 0.22, 0.24, skin);
|
| 352 |
+
}
|
| 353 |
+
|
| 354 |
+
addVoxel(side * 0.43, 1.78, 0, 0.34, 0.22, 0.38, skinDark);
|
| 355 |
+
}
|
| 356 |
+
|
| 357 |
+
// Torso: a 6 × 6 × 3 grid of visible skin blocks.
|
| 358 |
+
for (let row = 0; row < 6; row++) {
|
| 359 |
+
for (let column = 0; column < 6; column++) {
|
| 360 |
+
for (let depth = 0; depth < 3; depth++) {
|
| 361 |
+
addVoxel(
|
| 362 |
+
-0.62 + column * 0.23,
|
| 363 |
+
1.78 + row * 0.23,
|
| 364 |
+
-0.34 + depth * 0.34,
|
| 365 |
+
0.215,
|
| 366 |
+
0.215,
|
| 367 |
+
0.215,
|
| 368 |
+
(row + column + depth) % 4 === 0
|
| 369 |
+
? skinDark
|
| 370 |
+
: skin
|
| 371 |
+
);
|
| 372 |
+
}
|
| 373 |
+
}
|
| 374 |
+
}
|
| 375 |
+
|
| 376 |
+
// Leather vest front and back.
|
| 377 |
+
for (let row = 0; row < 5; row++) {
|
| 378 |
+
for (let column = 0; column < 6; column++) {
|
| 379 |
+
const x = -0.58 + column * 0.22;
|
| 380 |
+
const y = 1.91 + row * 0.23;
|
| 381 |
+
|
| 382 |
+
addVoxel(
|
| 383 |
+
x,
|
| 384 |
+
y,
|
| 385 |
+
0.43,
|
| 386 |
+
0.208,
|
| 387 |
+
0.218,
|
| 388 |
+
0.18,
|
| 389 |
+
(row + column) % 3 === 0 ? leatherDark : leather
|
| 390 |
+
);
|
| 391 |
+
|
| 392 |
+
addVoxel(
|
| 393 |
+
x,
|
| 394 |
+
y,
|
| 395 |
+
-0.43,
|
| 396 |
+
0.208,
|
| 397 |
+
0.218,
|
| 398 |
+
0.18,
|
| 399 |
+
(row + column + 1) % 3 === 0 ? leatherDark : leather
|
| 400 |
+
);
|
| 401 |
+
}
|
| 402 |
+
}
|
| 403 |
+
|
| 404 |
+
// Shoulder armor.
|
| 405 |
+
for (const side of [-1, 1]) {
|
| 406 |
+
addVoxel(side * 0.64, 3.12, 0, 0.30, 0.25, 0.44, leather);
|
| 407 |
+
addVoxel(side * 0.64, 3.29, 0, 0.25, 0.12, 0.38, leatherDark);
|
| 408 |
+
}
|
| 409 |
+
|
| 410 |
+
// Necklace / neck block.
|
| 411 |
+
addVoxel(0, 3.22, 0, 0.28, 0.18, 0.28, skinDark);
|
| 412 |
+
addVoxel(0, 3.31, 0, 0.12, 0.055, 0.13, brass);
|
| 413 |
+
|
| 414 |
+
// Arms.
|
| 415 |
+
for (const side of [-1, 1]) {
|
| 416 |
+
const armX = [0.65, 0.77, 0.89, 1.01, 1.13, 1.25];
|
| 417 |
+
|
| 418 |
+
for (let i = 0; i < armX.length; i++) {
|
| 419 |
+
addVoxel(
|
| 420 |
+
side * armX[i],
|
| 421 |
+
[2.90, 2.67, 2.44, 2.21, 1.98, 1.75][i],
|
| 422 |
+
0.02,
|
| 423 |
+
0.20,
|
| 424 |
+
0.20,
|
| 425 |
+
0.22,
|
| 426 |
+
i === 0 ? skinLight : skin
|
| 427 |
+
);
|
| 428 |
+
}
|
| 429 |
+
|
| 430 |
+
// Arm straps.
|
| 431 |
+
addVoxel(side * 0.68, 2.78, 0.12, 0.25, 0.32, 0.22, leather);
|
| 432 |
+
addVoxel(side * 0.68, 2.60, 0.12, 0.24, 0.08, 0.23, leatherDark);
|
| 433 |
+
}
|
| 434 |
+
|
| 435 |
+
// Hands.
|
| 436 |
+
for (const x of [-1.12, -1.35, 1.12, 1.35]) {
|
| 437 |
+
addVoxel(x, 1.90, 0.25, 0.20, 0.20, 0.22, skinLight);
|
| 438 |
+
addVoxel(x, 2.14, 0.25, 0.20, 0.20, 0.22, skin);
|
| 439 |
+
addVoxel(x, 1.80, 0.37, 0.14, 0.14, 0.14, skin);
|
| 440 |
+
}
|
| 441 |
+
|
| 442 |
+
// Chest belt and pouch.
|
| 443 |
+
for (let i = 0; i < 7; i++) {
|
| 444 |
+
addVoxel(
|
| 445 |
+
-0.60 + i * 0.20,
|
| 446 |
+
1.55,
|
| 447 |
+
0.01,
|
| 448 |
+
0.19,
|
| 449 |
+
0.10,
|
| 450 |
+
0.44,
|
| 451 |
+
i % 2 === 0 ? leather : leatherDark
|
| 452 |
+
);
|
| 453 |
+
}
|
| 454 |
+
|
| 455 |
+
addVoxel(0, 1.55, 0.28, 0.18, 0.18, 0.12, brass);
|
| 456 |
+
addVoxel(0.34, 1.38, 0.38, 0.32, 0.28, 0.34, leatherDark);
|
| 457 |
+
addVoxel(0.34, 1.38, 0.58, 0.24, 0.18, 0.08, leatherTrim);
|
| 458 |
+
|
| 459 |
+
// Chest studs.
|
| 460 |
+
for (const x of [-0.45, 0, 0.45]) {
|
| 461 |
+
addVoxel(x, 2.68, 0.60, 0.09, 0.09, 0.08, brass);
|
| 462 |
+
}
|
| 463 |
+
|
| 464 |
+
// Horizontal chest strap.
|
| 465 |
+
for (let i = 0; i < 7; i++) {
|
| 466 |
+
addVoxel(
|
| 467 |
+
-0.60 + i * 0.20,
|
| 468 |
+
2.52,
|
| 469 |
+
0.57,
|
| 470 |
+
0.19,
|
| 471 |
+
0.08,
|
| 472 |
+
0.08,
|
| 473 |
+
leatherDark
|
| 474 |
+
);
|
| 475 |
+
}
|
| 476 |
+
|
| 477 |
+
// -------------------------------------------------------------------------
|
| 478 |
+
// Head
|
| 479 |
+
// -------------------------------------------------------------------------
|
| 480 |
+
|
| 481 |
+
for (let row = 0; row < 4; row++) {
|
| 482 |
+
for (let column = 0; column < 5; column++) {
|
| 483 |
+
for (let depth = 0; depth < 3; depth++) {
|
| 484 |
+
addVoxel(
|
| 485 |
+
-0.52 + column * 0.23,
|
| 486 |
+
3.62 + row * 0.23,
|
| 487 |
+
-0.30 + depth * 0.33,
|
| 488 |
+
0.215,
|
| 489 |
+
0.215,
|
| 490 |
+
0.215,
|
| 491 |
+
(row + column + depth) % 5 === 0
|
| 492 |
+
? skinDark
|
| 493 |
+
: skin
|
| 494 |
+
);
|
| 495 |
+
}
|
| 496 |
+
}
|
| 497 |
+
}
|
| 498 |
+
|
| 499 |
+
// Forehead blocks give the face a chunky, readable silhouette.
|
| 500 |
+
for (const x of [-0.42, -0.21, 0, 0.21, 0.42]) {
|
| 501 |
+
addVoxel(x, 4.13, 0.34, 0.19, 0.19, 0.10, skinLight);
|
| 502 |
+
addVoxel(x, 4.35, 0.34, 0.19, 0.19, 0.10, skin);
|
| 503 |
+
}
|
| 504 |
+
|
| 505 |
+
// Eyes, irises, and tiny highlights.
|
| 506 |
+
for (const x of [-0.23, 0.23]) {
|
| 507 |
+
addVoxel(x, 4.08, 0.43, 0.15, 0.15, 0.08, skinDark);
|
| 508 |
+
addVoxel(x, 4.08, 0.49, 0.10, 0.10, 0.05, eyeBlack);
|
| 509 |
+
addVoxel(x, 4.08, 0.535, 0.055, 0.055, 0.035, eyeIris);
|
| 510 |
+
addVoxel(x, 4.08, 0.567, 0.025, 0.025, 0.02, eyeGlint);
|
| 511 |
+
}
|
| 512 |
+
|
| 513 |
+
// Eyebrows.
|
| 514 |
+
for (const x of [-0.25, 0.25]) {
|
| 515 |
+
addVoxel(x, 4.25, 0.44, 0.34, 0.08, 0.10, skinDark);
|
| 516 |
+
}
|
| 517 |
+
|
| 518 |
+
// Nose and mouth.
|
| 519 |
+
addVoxel(0, 4.12, 0.48, 0.15, 0.16, 0.15, skinDark);
|
| 520 |
+
addVoxel(0, 3.99, 0.53, 0.13, 0.12, 0.12, skin);
|
| 521 |
+
addVoxel(0, 3.57, 0.47, 0.23, 0.07, 0.08, clubDark);
|
| 522 |
+
addVoxel(-0.12, 3.43, 0.52, 0.08, 0.17, 0.08, clubLight);
|
| 523 |
+
addVoxel(0.12, 3.43, 0.52, 0.08, 0.17, 0.08, clubLight);
|
| 524 |
+
|
| 525 |
+
// -------------------------------------------------------------------------
|
| 526 |
+
// Large pointed ears
|
| 527 |
+
// -------------------------------------------------------------------------
|
| 528 |
+
|
| 529 |
+
for (const side of [-1, 1]) {
|
| 530 |
+
// Ear bases.
|
| 531 |
+
addVoxel(side * 0.78, 3.48, -0.02, 0.25, 0.25, 0.22, earOuter);
|
| 532 |
+
|
| 533 |
+
// Four columns and five rows create a tall, pointed silhouette.
|
| 534 |
+
for (let column = 0; column < 5; column++) {
|
| 535 |
+
const x = side * (0.96 + column * 0.18);
|
| 536 |
+
|
| 537 |
+
for (let row = 0; row < 5; row++) {
|
| 538 |
+
const y = 3.55 + row * 0.23;
|
| 539 |
+
|
| 540 |
+
addVoxel(x, y, -0.02, 0.17, 0.21, 0.18, earOuter);
|
| 541 |
+
|
| 542 |
+
// Inner ear panel on the visible/front side.
|
| 543 |
+
addVoxel(
|
| 544 |
+
side * (1.03 + column * 0.18),
|
| 545 |
+
y,
|
| 546 |
+
0.12,
|
| 547 |
+
0.12,
|
| 548 |
+
0.15,
|
| 549 |
+
0.08,
|
| 550 |
+
earInner
|
| 551 |
+
);
|
| 552 |
+
}
|
| 553 |
+
}
|
| 554 |
+
|
| 555 |
+
// Dark slit in the inner ear.
|
| 556 |
+
addVoxel(side * 1.16, 4.18, 0.18, 0.045, 0.25, 0.035, eyeBlack);
|
| 557 |
+
}
|
| 558 |
+
|
| 559 |
+
// -------------------------------------------------------------------------
|
| 560 |
+
// Spiked wooden club in the right hand
|
| 561 |
+
// -------------------------------------------------------------------------
|
| 562 |
+
|
| 563 |
+
// Handle.
|
| 564 |
+
for (const x of [1.25, 1.48, 1.71]) {
|
| 565 |
+
addVoxel(x, 2.12, 0.25, 0.22, 0.22, 0.24, clubWood);
|
| 566 |
+
}
|
| 567 |
+
|
| 568 |
+
// Club head.
|
| 569 |
+
for (const x of [1.90, 2.13, 2.36]) {
|
| 570 |
+
for (const y of [2.02, 2.25]) {
|
| 571 |
+
addVoxel(x, y, 0.25, 0.22, 0.22, 0.24, clubLight);
|
| 572 |
+
}
|
| 573 |
+
}
|
| 574 |
+
|
| 575 |
+
// Handle spikes.
|
| 576 |
+
for (const x of [1.25, 1.48, 1.71]) {
|
| 577 |
+
addVoxel(x, 2.12, 0.35, 0.08, 0.18, 0.18, clubLight);
|
| 578 |
+
}
|
| 579 |
+
|
| 580 |
+
// Head spikes pointing outward.
|
| 581 |
+
for (const x of [2.56, 2.78, 2.99]) {
|
| 582 |
+
addVoxel(x, 2.12, 0.25, 0.12, 0.22, 0.22, clubLight);
|
| 583 |
+
}
|
| 584 |
+
|
| 585 |
+
// Top and bottom spikes.
|
| 586 |
+
for (const x of [2.13, 2.36]) {
|
| 587 |
+
addVoxel(x, 1.90, 0.46, 0.16, 0.12, 0.12, clubLight);
|
| 588 |
+
addVoxel(x, 2.34, 0.46, 0.16, 0.12, 0.12, clubLight);
|
| 589 |
+
}
|
| 590 |
+
|
| 591 |
+
// Front spike.
|
| 592 |
+
addVoxel(2.13, 2.12, 0.55, 0.16, 0.16, 0.10, clubLight);
|
| 593 |
+
|
| 594 |
+
// -------------------------------------------------------------------------
|
| 595 |
+
// Convert all cubes into one efficient instanced mesh
|
| 596 |
+
// -------------------------------------------------------------------------
|
| 597 |
+
|
| 598 |
+
const voxelGeometry = new THREE.BoxGeometry(1, 1, 1);
|
| 599 |
+
const voxelMaterial = new THREE.MeshStandardMaterial({
|
| 600 |
+
color: 0xffffff,
|
| 601 |
+
roughness: 0.86,
|
| 602 |
+
metalness: 0,
|
| 603 |
+
flatShading: true
|
| 604 |
+
});
|
| 605 |
+
|
| 606 |
+
const voxelMesh = new THREE.InstancedMesh(
|
| 607 |
+
voxelGeometry,
|
| 608 |
+
voxelMaterial,
|
| 609 |
+
voxels.length
|
| 610 |
+
);
|
| 611 |
+
|
| 612 |
+
const matrix = new THREE.Matrix4();
|
| 613 |
+
const position = new THREE.Vector3();
|
| 614 |
+
const quaternion = new THREE.Quaternion();
|
| 615 |
+
const scale = new THREE.Vector3();
|
| 616 |
+
const color = new THREE.Color();
|
| 617 |
+
|
| 618 |
+
voxels.forEach((voxel, index) => {
|
| 619 |
+
position.set(voxel.x, voxel.y, voxel.z);
|
| 620 |
+
scale.set(voxel.sx, voxel.sy, voxel.sz);
|
| 621 |
+
matrix.compose(position, quaternion, scale);
|
| 622 |
+
voxelMesh.setMatrixAt(index, matrix);
|
| 623 |
+
voxelMesh.setColorAt(index, color.setHex(voxel.color));
|
| 624 |
+
});
|
| 625 |
+
|
| 626 |
+
voxelMesh.instanceMatrix.needsUpdate = true;
|
| 627 |
+
if (voxelMesh.instanceColor) {
|
| 628 |
+
voxelMesh.instanceColor.needsUpdate = true;
|
| 629 |
+
}
|
| 630 |
+
|
| 631 |
+
voxelMesh.castShadow = true;
|
| 632 |
+
voxelMesh.receiveShadow = true;
|
| 633 |
+
voxelMesh.frustumCulled = false;
|
| 634 |
+
voxelMesh.computeBoundingSphere();
|
| 635 |
+
|
| 636 |
+
model.add(voxelMesh);
|
| 637 |
+
scene.add(model);
|
| 638 |
+
|
| 639 |
+
// -------------------------------------------------------------------------
|
| 640 |
+
// Custom mouse orbit controls — no external controls addon
|
| 641 |
+
// -------------------------------------------------------------------------
|
| 642 |
+
|
| 643 |
+
let dragging = false;
|
| 644 |
+
let pointerId = null;
|
| 645 |
+
let lastX = 0;
|
| 646 |
+
let lastY = 0;
|
| 647 |
+
|
| 648 |
+
const canvas = renderer.domElement;
|
| 649 |
+
|
| 650 |
+
function resetView() {
|
| 651 |
+
cameraView.theta = 0.72;
|
| 652 |
+
cameraView.phi = 1.12;
|
| 653 |
+
cameraView.radius = 12.6;
|
| 654 |
+
updateCamera();
|
| 655 |
+
}
|
| 656 |
+
|
| 657 |
+
canvas.addEventListener("pointerdown", (event) => {
|
| 658 |
+
if (event.button !== 0) return;
|
| 659 |
+
|
| 660 |
+
dragging = true;
|
| 661 |
+
pointerId = event.pointerId;
|
| 662 |
+
lastX = event.clientX;
|
| 663 |
+
lastY = event.clientY;
|
| 664 |
+
canvas.setPointerCapture(pointerId);
|
| 665 |
+
});
|
| 666 |
+
|
| 667 |
+
canvas.addEventListener("pointermove", (event) => {
|
| 668 |
+
if (!dragging || event.pointerId !== pointerId) return;
|
| 669 |
+
|
| 670 |
+
const deltaX = event.clientX - lastX;
|
| 671 |
+
const deltaY = event.clientY - lastY;
|
| 672 |
+
|
| 673 |
+
lastX = event.clientX;
|
| 674 |
+
lastY = event.clientY;
|
| 675 |
+
|
| 676 |
+
cameraView.theta -= deltaX * 0.006;
|
| 677 |
+
cameraView.phi = THREE.MathUtils.clamp(
|
| 678 |
+
cameraView.phi - deltaY * 0.005,
|
| 679 |
+
0.42,
|
| 680 |
+
1.47
|
| 681 |
+
);
|
| 682 |
+
|
| 683 |
+
updateCamera();
|
| 684 |
+
});
|
| 685 |
+
|
| 686 |
+
function endDrag(event) {
|
| 687 |
+
if (event.pointerId !== pointerId) return;
|
| 688 |
+
|
| 689 |
+
dragging = false;
|
| 690 |
+
|
| 691 |
+
if (canvas.hasPointerCapture(pointerId)) {
|
| 692 |
+
canvas.releasePointerCapture(pointerId);
|
| 693 |
+
}
|
| 694 |
+
|
| 695 |
+
pointerId = null;
|
| 696 |
+
}
|
| 697 |
+
|
| 698 |
+
canvas.addEventListener("pointerup", endDrag);
|
| 699 |
+
canvas.addEventListener("pointercancel", endDrag);
|
| 700 |
+
|
| 701 |
+
canvas.addEventListener(
|
| 702 |
+
"wheel",
|
| 703 |
+
(event) => {
|
| 704 |
+
event.preventDefault();
|
| 705 |
+
|
| 706 |
+
cameraView.radius = THREE.MathUtils.clamp(
|
| 707 |
+
cameraView.radius + event.deltaY * 0.008,
|
| 708 |
+
7.5,
|
| 709 |
+
20
|
| 710 |
+
);
|
| 711 |
+
|
| 712 |
+
updateCamera();
|
| 713 |
+
},
|
| 714 |
+
{ passive: false }
|
| 715 |
+
);
|
| 716 |
+
|
| 717 |
+
canvas.addEventListener("dblclick", resetView);
|
| 718 |
+
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
|
| 719 |
+
|
| 720 |
+
// -------------------------------------------------------------------------
|
| 721 |
+
// Turntable and UI
|
| 722 |
+
// -------------------------------------------------------------------------
|
| 723 |
+
|
| 724 |
+
let paused = false;
|
| 725 |
+
let lastTime = performance.now();
|
| 726 |
+
|
| 727 |
+
function togglePause() {
|
| 728 |
+
paused = !paused;
|
| 729 |
+
pauseButton.textContent = paused ? "Resume rotation" : "Pause turntable";
|
| 730 |
+
}
|
| 731 |
+
|
| 732 |
+
pauseButton.addEventListener("click", togglePause);
|
| 733 |
+
|
| 734 |
+
window.addEventListener("keydown", (event) => {
|
| 735 |
+
if (event.code === "Space" && event.target === document.body) {
|
| 736 |
+
event.preventDefault();
|
| 737 |
+
togglePause();
|
| 738 |
+
}
|
| 739 |
+
});
|
| 740 |
+
|
| 741 |
+
window.addEventListener("resize", () => {
|
| 742 |
+
camera.aspect = window.innerWidth / window.innerHeight;
|
| 743 |
+
camera.updateProjectionMatrix();
|
| 744 |
+
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
|
| 745 |
+
renderer.setSize(window.innerWidth, window.innerHeight);
|
| 746 |
+
});
|
| 747 |
+
|
| 748 |
+
// -------------------------------------------------------------------------
|
| 749 |
+
// Animation
|
| 750 |
+
// -------------------------------------------------------------------------
|
| 751 |
+
|
| 752 |
+
function animate(now) {
|
| 753 |
+
requestAnimationFrame(animate);
|
| 754 |
+
|
| 755 |
+
const delta = Math.min((now - lastTime) / 1000, 0.05);
|
| 756 |
+
lastTime = now;
|
| 757 |
+
|
| 758 |
+
if (!paused) {
|
| 759 |
+
model.rotation.y += delta * 0.16;
|
| 760 |
+
}
|
| 761 |
+
|
| 762 |
+
renderer.render(scene, camera);
|
| 763 |
+
}
|
| 764 |
+
|
| 765 |
+
requestAnimationFrame(animate);
|
| 766 |
+
</script>
|
| 767 |
+
</body>
|
| 768 |
+
</html>
|
source/voxel-goblin.png
ADDED
|
Git LFS Details
|