Prompt specification
Build or customize the Three.js 3D scene "Two Wood Tokens Become One Crate" inside the active workspace.
Engineering Constraints:
1. Runtime & Orbit: Use Three.js r160 with OrbitControls (damping enabled) and ACESFilmicToneMapping.
2. Frame Timing: Drive all motion strictly with clock.getDelta() so animation speed is FPS-independent.
3. Viewport Hygiene: Handle window resize cleanly, cap DPR at Math.min(window.devicePixelRatio, 2), and dispose geometries/materials/renderer on unmount.
Scene Metadata:
Scene: Two Wood Tokens Become One Crate
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/two-wood-tokens-become-one-crate-x3565
Scene Description Prompt:
Create a standalone voxel scene in one HTML file using Three.js from cdnjs. Build a recipe board with two input sockets and one output socket. State the fictional conversion rule and remove consumed inputs when the crate appears.
Working Three.js Starter (two-wood-tokens-become-one-crate-x3565):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Voxel Recipe Board</title>
<style>
:root {
color-scheme: dark;
--cyan: #68f5e6;
--cyan-dim: #279f98;
--amber: #ffc45c;
--green: #88d96b;
--panel: rgba(5, 20, 24, 0.88);
--line: rgba(104, 245, 230, 0.28);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #07161b;
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
"Liberation Mono", monospace;
}
#scene {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
canvas.dragging {
cursor: grabbing;
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
}
.topbar {
position: absolute;
top: 22px;
left: 24px;
right: 24px;
display: flex;
justify-content: space-between;
align-items: flex-start;
gap: 20px;
}
.eyebrow {
color: var(--cyan-dim);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.24em;
text-transform: uppercase;
}
h1 {
margin: 7px 0 0;
color: #e8fffb;
font-size: clamp(20px, 3vw, 36px);
line-height: 1;
letter-spacing: -0.05em;
text-shadow: 0 3px 0 rgba(0, 0, 0, 0.35);
}
.machine-id {
padding: 10px 12px;
border: 1px solid var(--line);
border-radius: 5px;
background: rgba(5, 20, 24, 0.65);
color: #9fcfc9;
font-size: 10px;
letter-spacing: 0.13em;
text-align: right;
white-space: nowrap;
}
.machine-id strong {
display: block;
margin-top: 5px;
color: var(--cyan);
font-size: 12px;
}
.recipe-card {
position: absolute;
left: 24px;
bottom: 24px;
width: min(520px, calc(100vw - 48px));
padding: 15px 17px;
border: 1px solid var(--line);
border-left: 4px solid var(--cyan);
border-radius: 6px;
background: var(--panel);
box-shadow: 0 16px 45px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(12px);
}
.recipe-card .eyebrow {
color: #76a9a5;
}
.formula {
margin-top: 8px;
color: #effffc;
font-size: clamp(13px, 2vw, 18px);
font-weight: 800;
line-height: 1.4;
}
.formula .sun {
color: var(--amber);
}
.formula .moss {
color: var(--green);
}
.formula .crate {
color: var(--cyan);
}
.control-panel {
position: absolute;
right: 24px;
bottom: 24px;
width: min(360px, calc(100vw - 48px));
padding: 15px;
border: 1px solid var(--line);
border-radius: 6px;
background: var(--panel);
box-shadow: 0 16px 45px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(12px);
pointer-events: auto;
}
.status-row {
display: flex;
align-items: flex-start;
gap: 10px;
min-height: 43px;
}
.status-light {
flex: 0 0 auto;
width: 10px;
height: 10px;
margin-top: 4px;
border-radius: 2px;
background: var(--cyan);
box-shadow: 0 0 12px var(--cyan);
}
#statusTitle {
color: #effffc;
font-size: 12px;
font-weight: 800;
line-height: 1.35;
}
#statusDetail {
margin-top: 4px;
color: #86aaa7;
font-size: 10px;
line-height: 1.45;
}
.button-row {
display: flex;
gap: 9px;
margin-top: 12px;
}
button {
min-height: 42px;
border: 1px solid var(--cyan-dim);
border-radius: 4px;
padding: 0 16px;
background: #153b3c;
color: #cffff8;
font: 800 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.1em;
cursor: pointer;
transition:
transform 120ms ease,
background 120ms ease,
border-color 120ms ease;
}
button:hover:not(:disabled) {
transform: translateY(-2px);
border-color: var(--cyan);
background: #205453;
}
button:active:not(:disabled) {
transform: translateY(0);
}
button:disabled {
cursor: not-allowed;
opacity: 0.4;
}
#forgeButton {
flex: 1;
background: var(--cyan);
color: #082325;
border-color: var(--cyan);
}
#forgeButton:hover:not(:disabled) {
background: #a0fff3;
}
#resetButton {
flex: 1;
}
[hidden] {
display: none !important;
}
.hint {
position: absolute;
left: 50%;
bottom: 18px;
transform: translateX(-50%);
color: rgba(185, 231, 225, 0.58);
font-size: 9px;
letter-spacing: 0.12em;
text-align: center;
white-space: nowrap;
}
@media (max-width: 760px) {
.topbar {
top: 14px;
left: 14px;
right: 14px;
}
.machine-id {
display: none;
}
.recipe-card {
left: 14px;
bottom: 112px;
width: calc(100vw - 28px);
padding: 11px 13px;
}
.control-panel {
left: 14px;
right: 14px;
bottom: 14px;
width: auto;
padding: 11px;
}
.hint {
display: none;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<div class="hud">
<div class="topbar">
<div>
<div class="eyebrow">Voxel Foundry // Recipe Station 07</div>
<h1>The Lumen Crate</h1>
</div>
<div class="machine-id">
CONVERTER ONLINE
<strong>UNIT LC–07</strong>
</div>
</div>
<section class="recipe-card">
<div class="eyebrow">Fictional Conversion Rule</div>
<div class="formula">
<span class="sun">1 SUNSHARD</span>
+
<span class="moss">1 MOSS CUBE</span>
=
<span class="crate">1 LUMEN CRATE</span>
</div>
</section>
<section class="control-panel">
<div class="status-row">
<div class="status-light"></div>
<div>
<div id="statusTitle">Both input sockets are loaded.</div>
<div id="statusDetail">
The input items are consumed when the output crate appears.
</div>
</div>
</div>
<div class="button-row">
<button id="forgeButton" type="button">MANIFEST CRATE</button>
<button id="resetButton" type="button" hidden>RESET RECIPE</button>
</div>
</section>
<div class="hint">
DRAG TO ORBIT • SCROLL TO ZOOM • SPACE TO FORGE
</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer, camera, and custom camera controls
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
const sceneHost = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.1;
sceneHost.appendChild(renderer.domElement);
const camera = new THREE.OrthographicCamera(
-8,
8,
5.25,
-5.25,
0.1,
100
);
const cameraTarget = new THREE.Vector3(0.3, 2.55, 0);
const cameraRadius = 13;
let cameraTheta = 0.48;
let cameraPhi = 1.16;
let cameraZoom = 1;
function updateCamera() {
const sinPhi = Math.sin(cameraPhi);
camera.position.set(
cameraTarget.x + cameraRadius * sinPhi * Math.sin(cameraTheta),
cameraTarget.y + cameraRadius * Math.cos(cameraPhi),
cameraTarget.z + cameraRadius * sinPhi * Math.cos(cameraTheta)
);
camera.lookAt(cameraTarget);
camera.zoom = cameraZoom;
camera.updateProjectionMatrix();
}
updateCamera();
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.classList.add("dragging");
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
cameraTheta -= dx * 0.006;
cameraPhi = THREE.MathUtils.clamp(
cameraPhi - dy * 0.005,
0.62,
1.42
);
pointerX = event.clientX;
pointerY = event.clientY;
updateCamera();
});
function stopDragging(event) {
dragging = false;
renderer.domElement.classList.remove("dragging");
if (
renderer.domElement.hasPointerCapture?.(event.pointerId)
) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraZoom = THREE.MathUtils.clamp(
cameraZoom - event.deltaY * 0.001,
0.72,
1.65
);
updateCamera();
},
{ passive: false }
);
// -------------------------------------------------------------------------
// Scene lighting
// -------------------------------------------------------------------------
scene.background = new THREE.Color(0x07161b);
scene.fog = new THREE.Fog(0x07161b, 18, 38);
const hemisphere = new THREE.HemisphereLight(0xaeefff, 0x13272c, 1.65);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffefd0, 3.2);
keyLight.position.set(6, 11, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -12;
keyLight.shadow.camera.right = 12;
keyLight.shadow.camera.top = 12;
keyLight.shadow.camera.bottom = -12;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 35;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const cyanLight = new THREE.PointLight(0x39e7db, 28, 13, 2);
cyanLight.position.set(-4.8, 4.8, 1.5);
scene.add(cyanLight);
const amberLight = new THREE.PointLight(0xffa43d, 24, 11, 2);
amberLight.position.set(5, 4.2, 2.8);
scene.add(amberLight);
// -------------------------------------------------------------------------
// Geometry and texture helpers
// -------------------------------------------------------------------------
function box(
parent,
size,
position,
color,
options = {}
) {
const material = new THREE.MeshStandardMaterial({
color,
roughness: options.roughness ?? 0.78,
metalness: options.metalness ?? 0.08,
emissive: options.emissive ?? 0x000000,
emissiveIntensity: options.emissiveIntensity ?? 0
});
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
material
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = options.castShadow ?? true;
mesh.receiveShadow = options.receiveShadow ?? true;
parent.add(mesh);
return mesh;
}
function canvasTexture(
width,
height,
draw,
transparent = false
) {
const canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
const context = canvas.getContext("2d");
context.imageSmoothingEnabled = false;
draw(context, width, height);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
texture.magFilter = THREE.LinearFilter;
if (transparent) {
texture.premultiplyAlpha = true;
}
return texture;
}
function makeLabel(
parent,
text,
width,
height,
position,
color = "#dffffa"
) {
const texture = canvasTexture(
1024,
256,
(context, canvasWidth, canvasHeight) => {
context.clearRect(0, 0, canvasWidth, canvasHeight);
context.fillStyle = color;
context.font = "800 82px monospace";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, canvasWidth / 2, canvasHeight / 2);
},
true
);
const material = new THREE.MeshBasicMaterial({
map: texture,
transparent: true,
depthWrite: false,
toneMapped: false
});
const label = new THREE.Mesh(
new THREE.PlaneGeometry(width, height),
material
);
label.position.set(position[0], position[1], position[2]);
parent.add(label);
return label;
}
function makePlaque(
parent,
text,
width,
height,
position,
accent = "#68f5e6"
) {
const texture = canvasTexture(
1536,
256,
(context, canvasWidth, canvasHeight) => {
context.fillStyle = "#0b292f";
context.fillRect(0, 0, canvasWidth, canvasHeight);
context.strokeStyle = accent;
context.lineWidth = 10;
context.strokeRect(8, 8, canvasWidth - 16, canvasHeight - 16);
context.fillStyle = accent;
context.fillRect(28, 28, 10, canvasHeight - 56);
let fontSize = 78;
context.font = `800 ${fontSize}px monospace`;
while (
context.measureText(text).width > canvasWidth - 110 &&
fontSize > 28
) {
fontSize -= 2;
context.font = `800 ${fontSize}px monospace`;
}
context.fillStyle = "#e8fffb";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, canvasWidth / 2, canvasHeight / 2);
}
);
const plaque = new THREE.Mesh(
new THREE.PlaneGeometry(width, height),
new THREE.MeshBasicMaterial({
map: texture,
toneMapped: false
})
);
plaque.position.set(position[0], position[1], position[2]);
parent.add(plaque);
return plaque;
}
// -------------------------------------------------------------------------
// Voxel workshop environment
// -------------------------------------------------------------------------
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(40, 40),
new THREE.MeshStandardMaterial({
color: 0x0a2025,
roughness: 0.95,
metalness: 0.02
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.06;
floor.receiveShadow = true;
scene.add(floor);
const environment = new THREE.Group();
scene.add(environment);
// Alternating voxel floor plates.
for (let x = -7; x <= 7; x += 2) {
for (let z = -4; z <= 6; z += 2) {
box(
environment,
[1.92, 0.08, 1.92],
[x, 0, z],
(x + z) % 4 === 0 ? 0x102b30 : 0x0d252a,
{ castShadow: false }
);
}
}
// Back wall and structural columns.
box(
environment,
[25, 8, 0.45],
[0, 3.4, -5.1],
0x10282e
);
for (const x of [-8.5, -4.8, 4.8, 8.5]) {
box(
environment,
[0.38, 7.4, 0.38],
[x, 3.3, -4.7],
0x19383d
);
}
// Pipe-like voxel decorations.
for (const x of [-6.5, 6.4]) {
box(
environment,
[0.3, 5.2, 0.3],
[x, 3, -4.55],
0x264d50,
{ metalness: 0.45 }
);
for (const y of [1.2, 2.6, 4, 5.4]) {
box(
environment,
[0.58, 0.22, 0.5],
[x, y, -4.55],
0x397071,
{ metalness: 0.4 }
);
}
}
// Background voxel stacks.
function addBackgroundCrate(x, z, tint) {
const group = new THREE.Group();
group.position.set(x, 0, z);
environment.add(group);
box(group, [1.35, 1.1, 1.2], [0, 0.55, 0], tint);
box(group, [1.42, 0.14, 0.16], [0, 0.43, 0.62], 0x2f514e);
box(group, [1.42, 0.14, 0.16], [0, 0.72, 0.62], 0x2f514e);
box(group, [0.16, 1.14, 0.17], [-0.48, 0.55, 0.62], 0x2f514e);
box(group, [0.16, 1.14, 0.17], [0.48, 0.55, 0.62], 0x2f514e);
}
addBackgroundCrate(-6.3, -2.7, 0x29433e);
addBackgroundCrate(-6.25, -3.75, 0x354a3d);
addBackgroundCrate(6.5, -3.3, 0x3a4035);
addBackgroundCrate(-7.4, 2.8, 0x254148);
// Delivery pallet.
const pallet = new THREE.Group();
pallet.position.set(4.5, 0, 2.7);
environment.add(pallet);
for (const x of [-0.55, 0, 0.55]) {
box(
pallet,
[0.3, 0.65, 1.45],
[x, 0.32, 0],
0x3c4d42
);
}
for (const z of [-0.48, 0, 0.48]) {
box(
pallet,
[1.85, 0.15, 0.34],
[0, 0.68, z],
0x536653
);
}
makeLabel(
pallet,
"DELIVERY",
1.65,
0.3,
[0, 0.76, 0.74],
"#9bd1c9"
);
// -------------------------------------------------------------------------
// Main recipe board
// -------------------------------------------------------------------------
const board = new THREE.Group();
scene.add(board);
// Board body and frame.
box(board, [7.7, 4.35, 0.4], [0, 3.05, 0], 0x102e35);
box(board, [7.25, 3.9, 0.18], [0, 3.05, 0.26], 0x17434a);
for (const x of [-3.72, 3.72]) {
box(board, [0.28, 4.45, 0.5], [x, 3.05, 0.1], 0x31575a);
}
for (const y of [0.93, 5.17]) {
box(board, [7.65, 0.28, 0.5], [0, y, 0.1], 0x31575a);
}
// Supports and machine base.
for (const x of [-2.8, 2.8]) {
box(board, [0.52, 1.25, 0.65], [x, 0.48, -0.05], 0x1b4146);
box(board, [0.85, 0.22, 1.15], [x, 0.11, 0], 0x264b4e);
}
box(board, [6.4, 0.28, 1.25], [0, 0.13, 0], 0x19383d);
box(board, [5.8, 0.12, 1.05], [0, 0.33, 0], 0x275054);
makePlaque(
board,
"SUNSHARD + MOSS CUBE = LUMEN CRATE",
6.65,
0.78,
[0, 4.58, 0.42],
"#68f5e6"
);
makeLabel(
board,
"RECIPE BOARD // RECIPE 07",
3.3,
0.28,
[0, 5.36, 0.25],
"#71a49f"
);
// -------------------------------------------------------------------------
// Socket construction
// -------------------------------------------------------------------------
const inputItems = [];
const socketLights = [];
function createSocket(x, accent, labelText) {
const group = new THREE.Group();
group.position.set(x, 3.03, 0);
board.add(group);
box(group, [1.48, 1.48, 0.2], [0, 0, 0.37], 0x0a2026);
box(group, [1.22, 1.22, 0.11], [0, 0, 0.51], 0x071519);
const lightMaterial = new THREE.MeshStandardMaterial({
color: accent,
emissive: accent,
emissiveIntensity: 0.75,
roughness: 0.45,
metalness: 0.25
});
const light = new THREE.Mesh(
new THREE.BoxGeometry(0.12, 0.12, 0.08),
lightMaterial
);
light.position.set(0, 0.73, 0.46);
group.add(light);
socketLights.push(lightMaterial);
// Four chunky socket clamps.
for (const sx of [-1, 1]) {
for (const sy of [-1, 1]) {
box(
group,
[0.28, 0.28, 0.28],
[sx * 0.63, sy * 0.63, 0.43],
0x49666a,
{ metalness: 0.5 }
);
}
}
makeLabel(
group,
labelText,
1.8,
0.35,
[0, -1.03, 0.48],
"#b7d8d3"
);
return group;
}
const sunSocket = createSocket(-2.35, 0xffbd51, "SUNSHARD");
const mossSocket = createSocket(-0.5, 0x82dc66, "MOSS CUBE");
const outputSocket = createSocket(2.35, 0x5ff7e8, "OUTPUT");
// Voxel arrow between the second input and the output.
box(board, [0.48, 0.12, 0.12], [0.57, 3.03, 0.48], 0x5b8887);
box(board, [0.12, 0.42, 0.12], [0.87, 3.03, 0.48], 0x5b8887);
box(board, [0.12, 0.12, 0.12], [0.93, 3.17, 0.48], 0x5b8887);
box(board, [0.12, 0.12, 0.12], [0.93, 2.89, 0.48], 0x5b8887);
// -------------------------------------------------------------------------
// Input objects
// -------------------------------------------------------------------------
function createSunshard() {
const group = new THREE.Group();
box(
group,
[0.55, 0.66, 0.48],
[0, 0, 0],
0xffb536,
{
roughness: 0.42,
emissive: 0x8a3e00,
emissiveIntensity: 0.6
}
);
box(
group,
[0.34, 0.32, 0.4],
[-0.38, -0.16, 0],
0xd77b16,
{
roughness: 0.5,
emissive: 0x713000,
emissiveIntensity: 0.45
}
);
box(
group,
[0.3, 0.42, 0.35],
[0.34, 0.17, 0.03],
0xffd265,
{
roughness: 0.35,
emissive: 0xa55a00,
emissiveIntensity: 0.7
}
);
box(
group,
[0.23, 0.2, 0.22],
[0.02, 0.44, 0],
0xffcc59,
{
roughness: 0.45,
emissive: 0x8b4200,
emissiveIntensity: 0.5
}
);
return group;
}
function createMossCube() {
const group = new THREE.Group();
box(
group,
[0.62, 0.62, 0.58],
[0, 0, 0],
0x5da83c,
{ roughness: 1 }
);
box(
group,
[0.42, 0.3, 0.43],
[-0.38, -0.22, 0.02],
0x78c64d,
{ roughness: 1 }
);
box(
group,
[0.35, 0.43, 0.36],
[0.36, 0.2, 0.03],
0x8dd963,
{ roughness: 1 }
);
box(
group,
[0.25, 0.22, 0.2],
[0.18, 0.43, -0.02],
0x68bb42,
{ roughness: 1 }
);
box(
group,
[0.18, 0.12, 0.08],
[-0.1, 0.08, 0.32],
0xb3ef71,
{ roughness: 0.9 }
);
return group;
}
const sunItem = createSunshard();
sunItem.position.set(0, 0, 0.81);
sunSocket.add(sunItem);
inputItems.push(sunItem);
const mossItem = createMossCube();
mossItem.position.set(0, 0, 0.81);
mossSocket.add(mossItem);
inputItems.push(mossItem);
// -------------------------------------------------------------------------
// Output crate
// -------------------------------------------------------------------------
function createLumenCrate() {
const group = new THREE.Group();
box(
group,
[1.2, 1.05, 1.1],
[0, 0, 0],
0x8c6844,
{ roughness: 0.88 }
);
// Front and back planks.
for (const y of [-0.34, 0, 0.34]) {
box(
group,
[1.24, 0.22, 0.12],
[0, y, 0.59],
0xb08354
);
box(
group,
[1.24, 0.22, 0.12],
[0, y, -0.59],
0x765137
);
}
// Metal corners.
for (const x of [-0.53, 0.53]) {
for (const y of [-0.43, 0.43]) {
box(
group,
[0.18, 0.2, 1.16],
[x, y, 0],
0x405b5e,
{ metalness: 0.72, roughness: 0.36 }
);
}
}
// Top slats.
for (const x of [-0.36, 0, 0.36]) {
box(
group,
[0.26, 0.12, 1.14],
[x, 0.59, 0],
0xa7784d
);
}
// Voxel lumen rune on the front.
box(
group,
[0.18, 0.58, 0.1],
[0, 0, 0.69],
0x61f6e3,
{
emissive: 0x26cbb9,
emissiveIntensity: 1.7,
roughness: 0.3
}
);
box(
group,
[0.5, 0.18, 0.1],
[0, 0, 0.7],
0x61f6e3,
{
emissive: 0x26cbb9,
emissiveIntensity: 1.7,
roughness: 0.3
}
);
const light = new THREE.PointLight(0x4bf4df, 4.5, 4, 2);
light.position.set(0, 0, 0.8);
group.add(light);
group.userData.light = light;
return group;
}
// -------------------------------------------------------------------------
// Effects and state machine
// -------------------------------------------------------------------------
const particles = [];
const clock = new THREE.Clock();
let phase = "idle";
let phaseTime = 0;
let crate = null;
let crateHome = new THREE.Vector3();
const forgeButton = document.querySelector("#forgeButton");
const resetButton = document.querySelector("#resetButton");
const statusTitle = document.querySelector("#statusTitle");
const statusDetail = document.querySelector("#statusDetail");
function setStatus(title, detail) {
statusTitle.textContent = title;
statusDetail.textContent = detail;
}
function spawnBurst(position, color, count = 22) {
for (let i = 0; i < count; i++) {
const material = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 1
});
const size = 0.07 + Math.random() * 0.12;
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size, size, size),
material
);
mesh.position.copy(position);
mesh.rotation.set(
Math.random() * Math.PI,
Math.random() * Math.PI,
Math.random() * Math.PI
);
scene.add(mesh);
particles.push({
mesh,
velocity: new THREE.Vector3(
(Math.random() - 0.5) * 2.6,
1.1 + Math.random() * 2.7,
(Math.random() - 0.5) * 2.2
),
life: 0.7 + Math.random() * 0.55,
maxLife: 1.25
});
}
}
function clearParticles() {
for (const particle of particles) {
scene.remove(particle.mesh);
particle.mesh.geometry.dispose();
particle.mesh.material.dispose();
}
particles.length = 0;
}
function forgeCrate() {
if (phase !== "idle") return;
phase = "mixing";
phaseTime = 0;
forgeButton.disabled = true;
forgeButton.textContent = "CONVERTING...";
setStatus(
"Charging the conversion sockets...",
"The two input items remain present until the output appears."
);
}
function appearCrate() {
// Capture the ingredient positions before hiding them.
const sunPosition = new THREE.Vector3();
const mossPosition = new THREE.Vector3();
sunItem.getWorldPosition(sunPosition);
mossItem.getWorldPosition(mossPosition);
// The crate is created at the same moment the inputs are consumed.
crate = createLumenCrate();
scene.add(crate);
crateHome.copy(outputSocket.getWorldPosition(new THREE.Vector3()));
crateHome.z += 0.55;
crate.position.copy(crateHome);
crate.scale.setScalar(0.001);
// Consumed inputs are removed exactly when the crate appears.
inputItems.forEach((item) => {
item.visible = false;
});
spawnBurst(sunPosition, 0xffbd51, 24);
spawnBurst(mossPosition, 0x8de363, 24);
spawnBurst(crateHome, 0x62f7e5, 28);
phase = "appearing";
phaseTime = 0;
setStatus(
"Lumen crate appeared — inputs consumed.",
"Sunshard and Moss Cube were removed from their sockets."
);
}
const deliveryCurve = new THREE.CatmullRomCurve3([
new THREE.Vector3(2.35, 3.03, 0.81),
new THREE.Vector3(3.35, 3.38, 1.45),
new THREE.Vector3(4.1, 2.2, 2.2),
new THREE.Vector3(4.5, 1.29, 2.7)
]);
function resetRecipe() {
if (crate) {
scene.remove(crate);
}
crate = null;
phase = "idle";
phaseTime = 0;
clearParticles();
inputItems.forEach((item) => {
item.visible = true;
});
socketLights.forEach((material) => {
material.emissiveIntensity = 0.75;
});
forgeButton.disabled = false;
forgeButton.textContent = "MANIFEST CRATE";
forgeButton.hidden = false;
resetButton.hidden = true;
setStatus(
"Both input sockets are loaded.",
"The input items are consumed when the output crate appears."
);
}
forgeButton.addEventListener("click", forgeCrate);
resetButton.addEventListener("click", resetRecipe);
window.addEventListener("keydown", (event) => {
if (event.code === "Space") {
event.preventDefault();
forgeCrate();
}
if (event.code === "KeyR" && phase === "complete") {
resetRecipe();
}
});
// -------------------------------------------------------------------------
// Animation loop
// -------------------------------------------------------------------------
function easeOutBack(t) {
const c1 = 1.70158;
const c3 = c1 + 1;
return 1 + c3 * Math.pow(t - 1, 3) + c1 * Math.pow(t - 1, 2);
}
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
phaseTime += delta;
// Gentle idle motion for the input objects.
if (phase === "idle") {
sunItem.position.y = Math.sin(elapsed * 2.1) * 0.055;
sunItem.rotation.y = elapsed * 0.32;
mossItem.position.y = Math.sin(elapsed * 1.8 + 1.4) * 0.045;
mossItem.rotation.y = -elapsed * 0.24;
socketLights.forEach((material, index) => {
material.emissiveIntensity =
0.62 + Math.sin(elapsed * 2 + index * 1.7) * 0.18;
});
}
if (phase === "mixing") {
const pulse = Math.sin(phaseTime * 15);
sunItem.rotation.y += delta * (1.2 + pulse * 0.35);
mossItem.rotation.y -= delta * (1.2 - pulse * 0.35);
sunItem.position.y = Math.sin(phaseTime * 9) * 0.07;
mossItem.position.y = Math.sin(phaseTime * 9 + 2) * 0.07;
socketLights.forEach((material, index) => {
material.emissiveIntensity =
1.1 + Math.sin(phaseTime * 18 + index) * 0.65;
});
if (phaseTime > 1.15) {
appearCrate();
}
}
if (phase === "appearing" && crate) {
const t = Math.min(phaseTime / 0.62, 1);
const scale = easeOutBack(t);
crate.scale.setScalar(Math.max(0.001, scale));
crate.position.copy(crateHome);
crate.position.y += (1 - t) * 0.3;
crate.rotation.y = (1 - t) * 0.35;
socketLights[2].emissiveIntensity = 1.5 + (1 - t) * 2;
if (t >= 1) {
phase = "settled";
phaseTime = 0;
}
}
if (phase === "settled" && crate) {
crate.position.copy(crateHome);
crate.position.y += Math.sin(elapsed * 4) * 0.035;
setStatus(
"Lumen crate manifested at the output socket.",
"The crate is now moving to the delivery pallet."
);
if (phaseTime > 0.85) {
phase = "delivering";
phaseTime = 0;
}
}
if (phase === "delivering" && crate) {
const t = Math.min(phaseTime / 2.25, 1);
const eased = t * t * (3 - 2 * t);
deliveryCurve.getPointAt(eased, crate.position);
crate.rotation.y = eased * Math.PI * 0.6;
crate.rotation.z = Math.sin(eased * Math.PI) * 0.08;
setStatus(
"Delivering the Lumen Crate...",
"Both recipe inputs remain consumed."
);
if (t >= 1) {
phase = "complete";
phaseTime = 0;
crate.position.set(4.5, 1.29, 2.7);
crate.rotation.set(0, Math.PI * 0.6, 0);
forgeButton.hidden = true;
resetButton.hidden = false;
setStatus(
"Lumen Crate delivered.",
"Reset the recipe board to load both input sockets again."
);
}
}
if (phase === "complete" && crate) {
crate.position.y = 1.29 + Math.sin(elapsed * 2.3) * 0.025;
crate.userData.light.intensity =
4.2 + Math.sin(elapsed * 3.5) * 0.7;
}
// Update voxel particles.
for (let i = particles.length - 1; i >= 0; i--) {
const particle = particles[i];
particle.life -= delta;
particle.velocity.y -= 5.5 * delta;
particle.mesh.position.addScaledVector(particle.velocity, delta);
particle.mesh.rotation.x += delta * 4;
particle.mesh.rotation.y += delta * 5;
particle.mesh.material.opacity = Math.max(
0,
particle.life / particle.maxLife
);
if (particle.life <= 0) {
scene.remove(particle.mesh);
particle.mesh.geometry.dispose();
particle.mesh.material.dispose();
particles.splice(i, 1);
}
}
renderer.render(scene, camera);
}
// -------------------------------------------------------------------------
// Resize handling
// -------------------------------------------------------------------------
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const viewHeight = aspect < 1 ? 13 / aspect : 10.5;
camera.left = (-viewHeight * aspect) / 2;
camera.right = (viewHeight * aspect) / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
}
window.addEventListener("resize", resize);
resize();
animate();
</script>
</body>
</html>
```