Datasets:
File size: 20,749 Bytes
01f0f49 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 | <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Swamp Goblin — Voxel Enemy</title>
<style>
:root {
color-scheme: dark;
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #789887;
}
#stage {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
canvas:active {
cursor: grabbing;
}
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(
ellipse at 50% 45%,
transparent 45%,
rgba(17, 28, 22, 0.22) 100%
);
}
.hud {
position: fixed;
top: 24px;
left: 24px;
z-index: 2;
max-width: min(360px, calc(100vw - 48px));
padding: 16px 18px;
color: #f2f4df;
background: rgba(20, 31, 24, 0.76);
border: 1px solid rgba(230, 235, 196, 0.2);
border-radius: 14px;
box-shadow: 0 14px 40px rgba(15, 26, 20, 0.22);
backdrop-filter: blur(12px);
pointer-events: none;
}
.eyebrow {
margin: 0 0 6px;
color: #b8ca91;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(23px, 4vw, 34px);
line-height: 1;
letter-spacing: -0.035em;
}
.subtitle {
margin: 8px 0 0;
color: rgba(242, 244, 223, 0.68);
font-size: 13px;
}
.controls {
position: fixed;
right: 24px;
bottom: 24px;
z-index: 3;
display: flex;
align-items: center;
gap: 12px;
padding: 10px 12px;
color: rgba(245, 247, 229, 0.82);
background: rgba(20, 31, 24, 0.72);
border: 1px solid rgba(230, 235, 196, 0.18);
border-radius: 12px;
box-shadow: 0 12px 35px rgba(15, 26, 20, 0.2);
backdrop-filter: blur(10px);
font-size: 12px;
}
#pause {
appearance: none;
padding: 8px 12px;
color: #203025;
background: #b8ca91;
border: 0;
border-radius: 8px;
font: inherit;
font-weight: 800;
cursor: pointer;
}
#pause:hover {
background: #d2dfb0;
}
#hint {
position: fixed;
left: 50%;
bottom: 24px;
z-index: 2;
transform: translateX(-50%);
padding: 8px 12px;
color: rgba(245, 247, 229, 0.72);
background: rgba(20, 31, 24, 0.55);
border: 1px solid rgba(230, 235, 196, 0.12);
border-radius: 999px;
box-shadow: 0 8px 25px rgba(15, 26, 20, 0.15);
backdrop-filter: blur(8px);
font-size: 11px;
white-space: nowrap;
pointer-events: none;
}
@media (max-width: 640px) {
.hud {
top: 14px;
left: 14px;
padding: 12px 14px;
}
.subtitle {
display: none;
}
.controls {
right: 14px;
bottom: 14px;
}
#hint {
display: none;
}
}
</style>
</head>
<body>
<div id="stage"></div>
<div class="vignette"></div>
<section class="hud" aria-label="Scene information">
<p class="eyebrow">Voxel Enemy Archive</p>
<h1>Swamp Goblin</h1>
<p class="subtitle">Big-eared woodland raider with a leather vest and spiked club.</p>
</section>
<div id="hint">Drag to orbit · Scroll to zoom · Double-click to reset</div>
<div class="controls">
<button id="pause" type="button">Pause turntable</button>
<span>Auto-rotating</span>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const stage = document.getElementById("stage");
const pauseButton = document.getElementById("pause");
// -------------------------------------------------------------------------
// Renderer, scene, camera
// -------------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Interactive 3D voxel swamp goblin enemy"
);
stage.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x789887);
scene.fog = new THREE.Fog(0x789887, 19, 42);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
const cameraTarget = new THREE.Vector3(0, 2.25, 0);
const cameraView = {
theta: 0.72,
phi: 1.12,
radius: 12.6
};
function updateCamera() {
const sinPhi = Math.sin(cameraView.phi);
camera.position.set(
cameraTarget.x +
cameraView.radius * sinPhi * Math.sin(cameraView.theta),
cameraTarget.y + cameraView.radius * Math.cos(cameraView.phi),
cameraTarget.z +
cameraView.radius * sinPhi * Math.cos(cameraView.theta)
);
camera.lookAt(cameraTarget);
}
updateCamera();
// -------------------------------------------------------------------------
// Lighting
// -------------------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(
0xd8ead4,
0x344336,
1.75
);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffe3a6, 3.2);
keyLight.position.set(6, 10, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 30;
keyLight.shadow.camera.left = -7;
keyLight.shadow.camera.right = 7;
keyLight.shadow.camera.top = 8;
keyLight.shadow.camera.bottom = -5;
keyLight.shadow.bias = -0.0004;
keyLight.shadow.normalBias = 0.025;
keyLight.target.position.set(0, 2, 0);
scene.add(keyLight, keyLight.target);
const fillLight = new THREE.DirectionalLight(0x9fc9d0, 1.1);
fillLight.position.set(-7, 5, 4);
scene.add(fillLight);
const rimLight = new THREE.DirectionalLight(0xffc96e, 0.8);
rimLight.position.set(1, 4, -8);
scene.add(rimLight);
// -------------------------------------------------------------------------
// Plain ground plane
// -------------------------------------------------------------------------
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(80, 80),
new THREE.MeshStandardMaterial({
color: 0x53624c,
roughness: 1,
metalness: 0
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.025;
ground.receiveShadow = true;
scene.add(ground);
// -------------------------------------------------------------------------
// Voxel construction
//
// Every visible part of the goblin is assembled from axis-aligned boxes.
// Instanced rendering keeps the block count manageable while preserving
// clear gaps, shadows, and individual cubic geometry.
// -------------------------------------------------------------------------
const model = new THREE.Group();
model.rotation.y = -0.1;
const voxels = [];
function addVoxel(x, y, z, sx, sy, sz, color) {
voxels.push({ x, y, z, sx, sy, sz, color });
}
const skin = 0x8b954e;
const skinLight = 0x9da353;
const skinDark = 0x747e3f;
const earOuter = 0x68763d;
const earInner = 0x9ca258;
const leather = 0x4b2d20;
const leatherDark = 0x2d1c17;
const leatherTrim = 0x714633;
const brass = 0xb88a3d;
const clubWood = 0x764723;
const clubLight = 0xb8773e;
const clubDark = 0x57321b;
const eyeBlack = 0x11150e;
const eyeIris = 0xe0b847;
const eyeGlint = 0xfff3b0;
const hair = 0x263b2b;
// Boots and feet.
for (const side of [-1, 1]) {
const x = side * 0.43;
addVoxel(x, 0.13, 0.25, 0.48, 0.26, 0.58, clubDark);
addVoxel(x, 0.29, 0.25, 0.42, 0.18, 0.54, leather);
addVoxel(x, 0.40, 0.04, 0.23, 0.22, 0.50, skin);
addVoxel(x, 0.40, 0.38, 0.23, 0.22, 0.20, skinLight);
addVoxel(x - 0.10, 0.40, 0.42, 0.16, 0.16, 0.16, skin);
}
// Legs and hips.
for (const side of [-1, 1]) {
for (let y = 0.58; y <= 1.73; y += 0.23) {
addVoxel(side * 0.36, y, 0.02, 0.22, 0.22, 0.24, skin);
}
addVoxel(side * 0.43, 1.78, 0, 0.34, 0.22, 0.38, skinDark);
}
// Torso: a 6 × 6 × 3 grid of visible skin blocks.
for (let row = 0; row < 6; row++) {
for (let column = 0; column < 6; column++) {
for (let depth = 0; depth < 3; depth++) {
addVoxel(
-0.62 + column * 0.23,
1.78 + row * 0.23,
-0.34 + depth * 0.34,
0.215,
0.215,
0.215,
(row + column + depth) % 4 === 0
? skinDark
: skin
);
}
}
}
// Leather vest front and back.
for (let row = 0; row < 5; row++) {
for (let column = 0; column < 6; column++) {
const x = -0.58 + column * 0.22;
const y = 1.91 + row * 0.23;
addVoxel(
x,
y,
0.43,
0.208,
0.218,
0.18,
(row + column) % 3 === 0 ? leatherDark : leather
);
addVoxel(
x,
y,
-0.43,
0.208,
0.218,
0.18,
(row + column + 1) % 3 === 0 ? leatherDark : leather
);
}
}
// Shoulder armor.
for (const side of [-1, 1]) {
addVoxel(side * 0.64, 3.12, 0, 0.30, 0.25, 0.44, leather);
addVoxel(side * 0.64, 3.29, 0, 0.25, 0.12, 0.38, leatherDark);
}
// Necklace / neck block.
addVoxel(0, 3.22, 0, 0.28, 0.18, 0.28, skinDark);
addVoxel(0, 3.31, 0, 0.12, 0.055, 0.13, brass);
// Arms.
for (const side of [-1, 1]) {
const armX = [0.65, 0.77, 0.89, 1.01, 1.13, 1.25];
for (let i = 0; i < armX.length; i++) {
addVoxel(
side * armX[i],
[2.90, 2.67, 2.44, 2.21, 1.98, 1.75][i],
0.02,
0.20,
0.20,
0.22,
i === 0 ? skinLight : skin
);
}
// Arm straps.
addVoxel(side * 0.68, 2.78, 0.12, 0.25, 0.32, 0.22, leather);
addVoxel(side * 0.68, 2.60, 0.12, 0.24, 0.08, 0.23, leatherDark);
}
// Hands.
for (const x of [-1.12, -1.35, 1.12, 1.35]) {
addVoxel(x, 1.90, 0.25, 0.20, 0.20, 0.22, skinLight);
addVoxel(x, 2.14, 0.25, 0.20, 0.20, 0.22, skin);
addVoxel(x, 1.80, 0.37, 0.14, 0.14, 0.14, skin);
}
// Chest belt and pouch.
for (let i = 0; i < 7; i++) {
addVoxel(
-0.60 + i * 0.20,
1.55,
0.01,
0.19,
0.10,
0.44,
i % 2 === 0 ? leather : leatherDark
);
}
addVoxel(0, 1.55, 0.28, 0.18, 0.18, 0.12, brass);
addVoxel(0.34, 1.38, 0.38, 0.32, 0.28, 0.34, leatherDark);
addVoxel(0.34, 1.38, 0.58, 0.24, 0.18, 0.08, leatherTrim);
// Chest studs.
for (const x of [-0.45, 0, 0.45]) {
addVoxel(x, 2.68, 0.60, 0.09, 0.09, 0.08, brass);
}
// Horizontal chest strap.
for (let i = 0; i < 7; i++) {
addVoxel(
-0.60 + i * 0.20,
2.52,
0.57,
0.19,
0.08,
0.08,
leatherDark
);
}
// -------------------------------------------------------------------------
// Head
// -------------------------------------------------------------------------
for (let row = 0; row < 4; row++) {
for (let column = 0; column < 5; column++) {
for (let depth = 0; depth < 3; depth++) {
addVoxel(
-0.52 + column * 0.23,
3.62 + row * 0.23,
-0.30 + depth * 0.33,
0.215,
0.215,
0.215,
(row + column + depth) % 5 === 0
? skinDark
: skin
);
}
}
}
// Forehead blocks give the face a chunky, readable silhouette.
for (const x of [-0.42, -0.21, 0, 0.21, 0.42]) {
addVoxel(x, 4.13, 0.34, 0.19, 0.19, 0.10, skinLight);
addVoxel(x, 4.35, 0.34, 0.19, 0.19, 0.10, skin);
}
// Eyes, irises, and tiny highlights.
for (const x of [-0.23, 0.23]) {
addVoxel(x, 4.08, 0.43, 0.15, 0.15, 0.08, skinDark);
addVoxel(x, 4.08, 0.49, 0.10, 0.10, 0.05, eyeBlack);
addVoxel(x, 4.08, 0.535, 0.055, 0.055, 0.035, eyeIris);
addVoxel(x, 4.08, 0.567, 0.025, 0.025, 0.02, eyeGlint);
}
// Eyebrows.
for (const x of [-0.25, 0.25]) {
addVoxel(x, 4.25, 0.44, 0.34, 0.08, 0.10, skinDark);
}
// Nose and mouth.
addVoxel(0, 4.12, 0.48, 0.15, 0.16, 0.15, skinDark);
addVoxel(0, 3.99, 0.53, 0.13, 0.12, 0.12, skin);
addVoxel(0, 3.57, 0.47, 0.23, 0.07, 0.08, clubDark);
addVoxel(-0.12, 3.43, 0.52, 0.08, 0.17, 0.08, clubLight);
addVoxel(0.12, 3.43, 0.52, 0.08, 0.17, 0.08, clubLight);
// -------------------------------------------------------------------------
// Large pointed ears
// -------------------------------------------------------------------------
for (const side of [-1, 1]) {
// Ear bases.
addVoxel(side * 0.78, 3.48, -0.02, 0.25, 0.25, 0.22, earOuter);
// Four columns and five rows create a tall, pointed silhouette.
for (let column = 0; column < 5; column++) {
const x = side * (0.96 + column * 0.18);
for (let row = 0; row < 5; row++) {
const y = 3.55 + row * 0.23;
addVoxel(x, y, -0.02, 0.17, 0.21, 0.18, earOuter);
// Inner ear panel on the visible/front side.
addVoxel(
side * (1.03 + column * 0.18),
y,
0.12,
0.12,
0.15,
0.08,
earInner
);
}
}
// Dark slit in the inner ear.
addVoxel(side * 1.16, 4.18, 0.18, 0.045, 0.25, 0.035, eyeBlack);
}
// -------------------------------------------------------------------------
// Spiked wooden club in the right hand
// -------------------------------------------------------------------------
// Handle.
for (const x of [1.25, 1.48, 1.71]) {
addVoxel(x, 2.12, 0.25, 0.22, 0.22, 0.24, clubWood);
}
// Club head.
for (const x of [1.90, 2.13, 2.36]) {
for (const y of [2.02, 2.25]) {
addVoxel(x, y, 0.25, 0.22, 0.22, 0.24, clubLight);
}
}
// Handle spikes.
for (const x of [1.25, 1.48, 1.71]) {
addVoxel(x, 2.12, 0.35, 0.08, 0.18, 0.18, clubLight);
}
// Head spikes pointing outward.
for (const x of [2.56, 2.78, 2.99]) {
addVoxel(x, 2.12, 0.25, 0.12, 0.22, 0.22, clubLight);
}
// Top and bottom spikes.
for (const x of [2.13, 2.36]) {
addVoxel(x, 1.90, 0.46, 0.16, 0.12, 0.12, clubLight);
addVoxel(x, 2.34, 0.46, 0.16, 0.12, 0.12, clubLight);
}
// Front spike.
addVoxel(2.13, 2.12, 0.55, 0.16, 0.16, 0.10, clubLight);
// -------------------------------------------------------------------------
// Convert all cubes into one efficient instanced mesh
// -------------------------------------------------------------------------
const voxelGeometry = new THREE.BoxGeometry(1, 1, 1);
const voxelMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.86,
metalness: 0,
flatShading: true
});
const voxelMesh = new THREE.InstancedMesh(
voxelGeometry,
voxelMaterial,
voxels.length
);
const matrix = new THREE.Matrix4();
const position = new THREE.Vector3();
const quaternion = new THREE.Quaternion();
const scale = new THREE.Vector3();
const color = new THREE.Color();
voxels.forEach((voxel, index) => {
position.set(voxel.x, voxel.y, voxel.z);
scale.set(voxel.sx, voxel.sy, voxel.sz);
matrix.compose(position, quaternion, scale);
voxelMesh.setMatrixAt(index, matrix);
voxelMesh.setColorAt(index, color.setHex(voxel.color));
});
voxelMesh.instanceMatrix.needsUpdate = true;
if (voxelMesh.instanceColor) {
voxelMesh.instanceColor.needsUpdate = true;
}
voxelMesh.castShadow = true;
voxelMesh.receiveShadow = true;
voxelMesh.frustumCulled = false;
voxelMesh.computeBoundingSphere();
model.add(voxelMesh);
scene.add(model);
// -------------------------------------------------------------------------
// Custom mouse orbit controls — no external controls addon
// -------------------------------------------------------------------------
let dragging = false;
let pointerId = null;
let lastX = 0;
let lastY = 0;
const canvas = renderer.domElement;
function resetView() {
cameraView.theta = 0.72;
cameraView.phi = 1.12;
cameraView.radius = 12.6;
updateCamera();
}
canvas.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragging = true;
pointerId = event.pointerId;
lastX = event.clientX;
lastY = event.clientY;
canvas.setPointerCapture(pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging || event.pointerId !== pointerId) return;
const deltaX = event.clientX - lastX;
const deltaY = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
cameraView.theta -= deltaX * 0.006;
cameraView.phi = THREE.MathUtils.clamp(
cameraView.phi - deltaY * 0.005,
0.42,
1.47
);
updateCamera();
});
function endDrag(event) {
if (event.pointerId !== pointerId) return;
dragging = false;
if (canvas.hasPointerCapture(pointerId)) {
canvas.releasePointerCapture(pointerId);
}
pointerId = null;
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraView.radius = THREE.MathUtils.clamp(
cameraView.radius + event.deltaY * 0.008,
7.5,
20
);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetView);
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
// -------------------------------------------------------------------------
// Turntable and UI
// -------------------------------------------------------------------------
let paused = false;
let lastTime = performance.now();
function togglePause() {
paused = !paused;
pauseButton.textContent = paused ? "Resume rotation" : "Pause turntable";
}
pauseButton.addEventListener("click", togglePause);
window.addEventListener("keydown", (event) => {
if (event.code === "Space" && event.target === document.body) {
event.preventDefault();
togglePause();
}
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
function animate(now) {
requestAnimationFrame(animate);
const delta = Math.min((now - lastTime) / 1000, 0.05);
lastTime = now;
if (!paused) {
model.rotation.y += delta * 0.16;
}
renderer.render(scene, camera);
}
requestAnimationFrame(animate);
</script>
</body>
</html>
|