Prompt specification
Build or customize the Three.js 3D scene "Three Plot Tiles With Recovery Counters" 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: Three Plot Tiles With Recovery Counters
Category: Games & Play · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/three-plot-tiles-with-recovery-counters-x3569
Scene Description Prompt:
Please make a stylized Three.js scene in one standalone HTML file using cdnjs. Model three field tiles with a visible toy fertility counter and harvest marker. Keep this abstract game state separate from claims about real soil chemistry.
Working Three.js Starter (three-plot-tiles-with-recovery-counters-x3569):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Patchwork Play — Toy Field Scene</title>
<style>
:root {
--ink: #26352f;
--muted: #66756d;
--cream: #fff8e8;
--paper: rgba(255, 250, 237, 0.94);
--coral: #e75e48;
--yellow: #f3bd46;
--green: #4f9a68;
--teal: #347e78;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e9efd9;
color: var(--ink);
font-family:
Inter, ui-rounded, "SF Pro Rounded", "Segoe UI", system-ui,
-apple-system, sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.hud {
position: fixed;
inset: 0;
z-index: 10;
pointer-events: none;
}
.brand {
position: absolute;
top: 24px;
left: 26px;
max-width: 390px;
}
.eyebrow {
display: inline-flex;
align-items: center;
gap: 7px;
margin-bottom: 7px;
padding: 6px 10px;
border: 1px solid rgba(38, 53, 47, 0.18);
border-radius: 999px;
background: rgba(255, 248, 232, 0.75);
color: var(--teal);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
backdrop-filter: blur(10px);
}
.eyebrow::before {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--yellow);
box-shadow: 0 0 0 3px rgba(243, 189, 70, 0.25);
content: "";
}
h1 {
margin: 0;
font-size: clamp(30px, 4vw, 53px);
font-weight: 900;
letter-spacing: -0.055em;
line-height: 0.95;
text-shadow: 0 2px 0 rgba(255, 255, 255, 0.4);
}
.subtitle {
margin: 10px 0 0;
color: var(--muted);
font-size: 14px;
font-weight: 600;
}
.inspector {
position: absolute;
top: 24px;
right: 26px;
width: 286px;
padding: 18px;
border: 1px solid rgba(38, 53, 47, 0.15);
border-radius: 22px;
background: var(--paper);
box-shadow:
0 18px 50px rgba(56, 67, 45, 0.13),
inset 0 1px 0 rgba(255, 255, 255, 0.8);
backdrop-filter: blur(16px);
pointer-events: auto;
}
.panel-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 13px;
}
.panel-label {
color: var(--muted);
font-size: 10px;
font-weight: 900;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.tile-letter {
display: grid;
width: 31px;
height: 31px;
place-items: center;
border-radius: 10px;
background: var(--coral);
color: white;
font-weight: 900;
box-shadow: 0 4px 0 #b83e30;
}
.tile-name {
margin: 0 0 13px;
font-size: 24px;
font-weight: 900;
letter-spacing: -0.035em;
}
.counter-box {
padding: 14px;
border: 2px solid rgba(231, 94, 72, 0.65);
border-radius: 17px;
background: #fff3d8;
}
.counter-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 14px;
}
.counter-title {
font-size: 10px;
font-weight: 900;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.counter-number {
margin-top: 2px;
font-size: 28px;
font-weight: 950;
letter-spacing: -0.04em;
}
.pips {
display: flex;
gap: 7px;
}
.pip {
width: 18px;
height: 18px;
border: 2px solid #d4a83e;
border-radius: 50%;
background: #eadfc6;
}
.pip.on {
background: var(--yellow);
box-shadow: 0 3px 0 #c58f25;
}
.status {
display: inline-flex;
align-items: center;
gap: 7px;
margin-top: 12px;
padding: 7px 10px;
border-radius: 999px;
background: rgba(79, 154, 104, 0.14);
color: #337048;
font-size: 12px;
font-weight: 800;
}
.status::before {
width: 7px;
height: 7px;
border-radius: 50%;
background: currentColor;
content: "";
}
.actions {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px;
margin-top: 12px;
}
button {
min-height: 38px;
border: 0;
border-radius: 12px;
background: var(--ink);
color: white;
cursor: pointer;
font: inherit;
font-size: 12px;
font-weight: 800;
transition:
transform 120ms ease,
background 120ms ease;
}
button:hover {
transform: translateY(-2px);
background: #395047;
}
button:active {
transform: translateY(0);
}
button.secondary {
border: 1px solid rgba(38, 53, 47, 0.17);
background: rgba(255, 255, 255, 0.65);
color: var(--ink);
}
.hint {
margin-top: 13px;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
text-align: center;
}
.disclaimer {
position: absolute;
right: 26px;
bottom: 23px;
left: 26px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 20px;
padding: 12px 15px;
border: 1px solid rgba(38, 53, 47, 0.13);
border-radius: 15px;
background: rgba(255, 250, 237, 0.88);
color: #5d655e;
font-size: 11px;
line-height: 1.45;
backdrop-filter: blur(12px);
}
.disclaimer strong {
color: var(--ink);
}
.fiction-badge {
flex: 0 0 auto;
padding: 6px 9px;
border-radius: 8px;
background: var(--ink);
color: white;
font-size: 9px;
font-weight: 900;
letter-spacing: 0.12em;
}
.loading {
position: fixed;
inset: 0;
z-index: 30;
display: grid;
place-items: center;
background: #e9efd9;
color: var(--ink);
font-weight: 900;
letter-spacing: 0.08em;
transition: opacity 350ms ease;
}
.loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 720px) {
.brand {
top: 16px;
left: 16px;
}
.subtitle {
display: none;
}
.inspector {
top: auto;
right: 14px;
bottom: 78px;
width: 220px;
padding: 13px;
border-radius: 18px;
}
.tile-name {
margin-bottom: 9px;
font-size: 19px;
}
.counter-box {
padding: 10px;
}
.counter-number {
font-size: 22px;
}
.pip {
width: 14px;
height: 14px;
}
.status {
margin-top: 8px;
}
.actions,
.hint {
display: none;
}
.disclaimer {
right: 14px;
bottom: 14px;
left: 14px;
padding: 10px 12px;
}
.fiction-badge {
display: none;
}
}
</style>
</head>
<body>
<div class="loading" id="loading">BUILDING THE LITTLE FIELDS…</div>
<div class="hud">
<header class="brand">
<div class="eyebrow">A tiny fictional farm game</div>
<h1>Patchwork<br />Play</h1>
<p class="subtitle">Three toy plots, one harvest marker, and a very serious plastic counter.</p>
</header>
<aside class="inspector" aria-live="polite">
<div class="panel-top">
<span class="panel-label">Selected field tile</span>
<span class="tile-letter" id="tileLetter">A</span>
</div>
<h2 class="tile-name" id="tileName">Sunpatch</h2>
<div class="counter-box">
<div class="counter-row">
<div>
<div class="counter-title">Toy fertility counter</div>
<div class="counter-number">
<span id="fertilityValue">3</span> / 3
</div>
</div>
<div class="pips" id="pips" aria-label="3 of 3 tokens">
<span class="pip on"></span>
<span class="pip on"></span>
<span class="pip on"></span>
</div>
</div>
</div>
<div class="status" id="tileStatus">Ready to harvest</div>
<div class="actions">
<button id="nextTile" type="button">Next tile</button>
<button id="resetView" class="secondary" type="button">Reset view</button>
</div>
<div class="hint">Drag to orbit · Scroll to zoom · Click a tile to inspect</div>
</aside>
<footer class="disclaimer">
<span>
<strong>Fictional game state:</strong> “Fertility” counts toy tokens only.
This is not a soil test and makes no claim about nutrients, pH, soil chemistry,
or real-world crop performance.
</span>
<span class="fiction-badge">GAME TOKENS ONLY</span>
</footer>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Renderer and scene
// ------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
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.12;
renderer.domElement.setAttribute(
"aria-label",
"Interactive Three.js scene with three stylized field tiles"
);
renderer.domElement.tabIndex = 0;
document.body.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe9efd9);
scene.fog = new THREE.Fog(0xe9efd9, 17, 30);
const camera = new THREE.PerspectiveCamera(
39,
window.innerWidth / window.innerHeight,
0.1,
60
);
const hemiLight = new THREE.HemisphereLight(0xfff8df, 0x60765f, 2.15);
scene.add(hemiLight);
const sunLight = new THREE.DirectionalLight(0xfff1c4, 3.3);
sunLight.position.set(-7, 12, 8);
sunLight.castShadow = true;
sunLight.shadow.mapSize.set(2048, 2048);
sunLight.shadow.camera.left = -10;
sunLight.shadow.camera.right = 10;
sunLight.shadow.camera.top = 10;
sunLight.shadow.camera.bottom = -10;
sunLight.shadow.camera.near = 1;
sunLight.shadow.camera.far = 30;
sunLight.shadow.bias = -0.0004;
scene.add(sunLight);
const fillLight = new THREE.DirectionalLight(0xb9dddc, 0.8);
fillLight.position.set(7, 5, -8);
scene.add(fillLight);
// ------------------------------------------------------------
// Small geometry and texture helpers
// ------------------------------------------------------------
function roundedRectPath(ctx, x, y, width, height, radius) {
const r = Math.min(radius, width / 2, height / 2);
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.arcTo(x + width, y, x + width, y + height, r);
ctx.arcTo(x + width, y + height, x, y + height, r);
ctx.arcTo(x, y + height, x, y, r);
ctx.arcTo(x, y, x + width, y, r);
ctx.closePath();
}
function makeRoundedGeometry(width, depth, height, radius, bevel = 0.06) {
const shape = new THREE.Shape();
const x = -width / 2;
const y = -depth / 2;
const r = radius;
shape.moveTo(x + r, y);
shape.lineTo(x + width - r, y);
shape.quadraticCurveTo(x + width, y, x + width, y + r);
shape.lineTo(x + width, y + depth - r);
shape.quadraticCurveTo(
x + width,
y + depth,
x + width - r,
y + depth
);
shape.lineTo(x + r, y + depth);
shape.quadraticCurveTo(x, y + depth, x, y + depth - r);
shape.lineTo(x, y + r);
shape.quadraticCurveTo(x, y, x + r, y);
const geometry = new THREE.ExtrudeGeometry(shape, {
depth: height,
bevelEnabled: bevel > 0,
bevelSegments: 3,
steps: 1,
bevelSize: bevel,
bevelThickness: bevel
});
geometry.rotateX(-Math.PI / 2);
geometry.computeVertexNormals();
return geometry;
}
function canvasTexture(canvas) {
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
function makeLabelSprite(title, subtitle, accent) {
const canvas = document.createElement("canvas");
canvas.width = 640;
canvas.height = 170;
const ctx = canvas.getContext("2d");
roundedRectPath(ctx, 8, 8, 624, 154, 34);
ctx.fillStyle = "#fff8e8";
ctx.fill();
ctx.lineWidth = 10;
ctx.strokeStyle = accent;
ctx.stroke();
ctx.fillStyle = accent;
ctx.beginPath();
ctx.arc(58, 85, 18, 0, Math.PI * 2);
ctx.fill();
ctx.textAlign = "left";
ctx.textBaseline = "middle";
ctx.fillStyle = "#26352f";
ctx.font = "900 43px system-ui, sans-serif";
ctx.fillText(title, 94, 69);
ctx.fillStyle = "#66756d";
ctx.font = "700 24px system-ui, sans-serif";
ctx.fillText(subtitle, 95, 111);
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: canvasTexture(canvas),
transparent: true,
depthWrite: false
})
);
sprite.scale.set(2.45, 0.65, 1);
return sprite;
}
// ------------------------------------------------------------
// Shared materials and geometry
// ------------------------------------------------------------
const materials = {
soilA: new THREE.MeshStandardMaterial({ color: 0xb86f43, roughness: 0.96 }),
soilB: new THREE.MeshStandardMaterial({ color: 0x9f7049, roughness: 0.98 }),
soilC: new THREE.MeshStandardMaterial({ color: 0xc28758, roughness: 0.96 }),
soilEdge: new THREE.MeshStandardMaterial({ color: 0x744b38, roughness: 1 }),
furrow: new THREE.MeshStandardMaterial({ color: 0x76462f, roughness: 1 }),
stem: new THREE.MeshStandardMaterial({ color: 0x39734c, roughness: 0.8 }),
leaf: new THREE.MeshStandardMaterial({ color: 0x58a75e, roughness: 0.76 }),
leafLight: new THREE.MeshStandardMaterial({ color: 0x7cc36d, roughness: 0.74 }),
fruit: new THREE.MeshStandardMaterial({ color: 0xef7655, roughness: 0.58 }),
stone: new THREE.MeshStandardMaterial({ color: 0xd9cfb5, roughness: 0.95 }),
pole: new THREE.MeshStandardMaterial({ color: 0x70503b, roughness: 0.8 }),
flag: new THREE.MeshStandardMaterial({
color: 0xef6749,
roughness: 0.7,
side: THREE.DoubleSide
})
};
const leafGeometry = new THREE.SphereGeometry(0.16, 9, 7);
const fruitGeometry = new THREE.SphereGeometry(0.115, 10, 8);
const pebbleGeometry = new THREE.DodecahedronGeometry(0.065, 0);
// ------------------------------------------------------------
// Ground island
// ------------------------------------------------------------
const island = new THREE.Mesh(
makeRoundedGeometry(13.4, 6.7, 0.22, 0.75, 0.11),
new THREE.MeshStandardMaterial({ color: 0xa9c884, roughness: 0.95 })
);
island.position.set(0, -0.27, 0.1);
island.receiveShadow = true;
scene.add(island);
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(80, 80),
new THREE.MeshStandardMaterial({ color: 0xe9efd9, roughness: 1 })
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.4;
ground.receiveShadow = true;
scene.add(ground);
// Decorative toy stones around the field island.
const stonePalette = [0xd6ccb1, 0xe1d6bb, 0xc4b99e];
for (let i = 0; i < 22; i++) {
const angle = (i / 22) * Math.PI * 2;
const radiusX = 6.35 + Math.sin(i * 3.1) * 0.25;
const radiusZ = 3.05 + Math.cos(i * 2.3) * 0.2;
const stone = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.09 + (i % 3) * 0.025, 0),
new THREE.MeshStandardMaterial({
color: stonePalette[i % stonePalette.length],
roughness: 0.95
})
);
stone.position.set(
Math.cos(angle) * radiusX,
-0.03,
Math.sin(angle) * radiusZ + 0.1
);
stone.scale.y = 0.65;
stone.rotation.set(i * 0.2, i * 0.7, i * 0.4);
stone.castShadow = true;
stone.receiveShadow = true;
scene.add(stone);
}
// ------------------------------------------------------------
// Field tiles
// ------------------------------------------------------------
const tileDefinitions = [
{
letter: "A",
name: "Sunpatch",
subtitle: "ripe rows",
fertility: 3,
stage: 3,
status: "Ready to harvest",
accent: "#e75e48",
soil: materials.soilA,
position: new THREE.Vector3(-3.75, 0, -0.15)
},
{
letter: "B",
name: "Leaflet",
subtitle: "growing rows",
fertility: 2,
stage: 2,
status: "Growing",
accent: "#347e78",
soil: materials.soilB,
position: new THREE.Vector3(0, 0, 0.2)
},
{
letter: "C",
name: "Ember Row",
subtitle: "tiny sprouts",
fertility: 1,
stage: 1,
status: "Tiny sprouts",
accent: "#d49b31",
soil: materials.soilC,
position: new THREE.Vector3(3.75, 0, -0.12)
}
];
const tileGroups = [];
const tileHitMeshes = [];
const animatedCrops = [];
function createCrop(parent, x, z, stage, phase) {
const crop = new THREE.Group();
crop.position.set(x, 0.68, z);
crop.rotation.y = phase * 0.35;
parent.add(crop);
const height = [0.18, 0.25, 0.36, 0.48][stage];
const leafCount = [1, 1, 2, 3][stage];
const stem = new THREE.Mesh(
new THREE.CylinderGeometry(0.025, 0.035, height, 6),
materials.stem
);
stem.position.y = height / 2;
stem.castShadow = true;
crop.add(stem);
for (let i = 0; i < leafCount; i++) {
const leaf = new THREE.Mesh(
leafGeometry,
i % 2 === 0 ? materials.leaf : materials.leafLight
);
const angle = (i / leafCount) * Math.PI * 2 + phase;
leaf.position.set(
Math.cos(angle) * 0.095,
height * (0.64 + i * 0.09),
Math.sin(angle) * 0.095
);
leaf.scale.set(0.55, 1.35, 0.42);
leaf.rotation.set(Math.sin(angle) * 0.65, angle, Math.cos(angle) * 0.65);
leaf.castShadow = true;
crop.add(leaf);
}
if (stage === 3) {
const fruit = new THREE.Mesh(fruitGeometry, materials.fruit);
fruit.position.y = height * 0.54;
fruit.scale.set(1, 0.92, 1);
fruit.castShadow = true;
crop.add(fruit);
}
crop.userData.phase = phase;
animatedCrops.push(crop);
}
function createTile(def, index) {
const group = new THREE.Group();
group.position.copy(def.position);
scene.add(group);
const base = new THREE.Mesh(
makeRoundedGeometry(3.5, 2.9, 0.48, 0.32, 0.08),
materials.soilEdge
);
base.castShadow = true;
base.receiveShadow = true;
base.userData.tileIndex = index;
group.add(base);
tileHitMeshes.push(base);
const topMaterial = def.soil.clone();
const top = new THREE.Mesh(
makeRoundedGeometry(3.34, 2.74, 0.14, 0.28, 0.045),
topMaterial
);
top.position.y = 0.48;
top.castShadow = true;
top.receiveShadow = true;
top.userData.tileIndex = index;
group.add(top);
tileHitMeshes.push(top);
// Toy-like furrows.
for (let row = 0; row < 3; row++) {
const furrow = new THREE.Mesh(
new THREE.BoxGeometry(2.93, 0.025, 0.07),
materials.furrow
);
furrow.position.set(0, 0.63, -0.72 + row * 0.72);
furrow.receiveShadow = true;
group.add(furrow);
}
// Nine plants per field, with a gently varied handmade layout.
for (let row = 0; row < 3; row++) {
for (let column = 0; column < 3; column++) {
const x = -0.95 + column * 0.95 + Math.sin(column * 5 + row) * 0.055;
const z = -0.72 + row * 0.72 + Math.cos(column * 3 + row) * 0.045;
createCrop(group, x, z, def.stage, row + column * 0.8 + index);
}
}
// Small soil pebbles.
for (let i = 0; i < 18; i++) {
const pebble = new THREE.Mesh(pebbleGeometry, materials.stone);
const angle = i * 2.399;
const radius = 0.25 + (i % 5) * 0.24;
pebble.position.set(
Math.cos(angle) * radius * 1.4,
0.65,
Math.sin(angle) * radius * 0.84
);
pebble.scale.setScalar(0.55 + (i % 3) * 0.15);
pebble.rotation.set(i * 0.3, i * 0.8, i * 0.5);
pebble.castShadow = true;
group.add(pebble);
}
const label = makeLabelSprite(
`${def.letter} · ${def.name}`,
def.subtitle,
def.accent
);
label.position.set(0, 0.34, 1.51);
group.add(label);
tileGroups.push({
group,
top,
topMaterial,
definition: def
});
}
tileDefinitions.forEach(createTile);
// ------------------------------------------------------------
// Harvest marker on tile A
// ------------------------------------------------------------
const harvestGroup = new THREE.Group();
tileGroups[0].group.add(harvestGroup);
const harvestPole = new THREE.Mesh(
new THREE.CylinderGeometry(0.035, 0.045, 1.8, 8),
materials.pole
);
harvestPole.position.set(1.22, 1.55, -0.92);
harvestPole.castShadow = true;
harvestGroup.add(harvestPole);
const flagPivot = new THREE.Group();
flagPivot.position.set(1.22, 2.36, -0.92);
harvestGroup.add(flagPivot);
const flagShape = new THREE.Shape();
flagShape.moveTo(0, 0.19);
flagShape.lineTo(0.78, 0.04);
flagShape.lineTo(0, -0.13);
flagShape.closePath();
const flag = new THREE.Mesh(
new THREE.ShapeGeometry(flagShape),
materials.flag
);
flag.castShadow = true;
flagPivot.add(flag);
const harvestCanvas = document.createElement("canvas");
harvestCanvas.width = 512;
harvestCanvas.height = 150;
const harvestCtx = harvestCanvas.getContext("2d");
roundedRectPath(harvestCtx, 6, 6, 500, 138, 30);
harvestCtx.fillStyle = "#f3bd46";
harvestCtx.fill();
harvestCtx.lineWidth = 9;
harvestCtx.strokeStyle = "#26352f";
harvestCtx.stroke();
harvestCtx.fillStyle = "#26352f";
harvestCtx.textAlign = "center";
harvestCtx.textBaseline = "middle";
harvestCtx.font = "900 57px system-ui, sans-serif";
harvestCtx.fillText("HARVEST!", 256, 72);
const harvestLabel = new THREE.Sprite(
new THREE.SpriteMaterial({
map: canvasTexture(harvestCanvas),
transparent: true,
depthWrite: false
})
);
harvestLabel.position.set(1.25, 2.92, -0.92);
harvestLabel.scale.set(1.85, 0.54, 1);
harvestGroup.add(harvestLabel);
// ------------------------------------------------------------
// Freestanding toy fertility counter
// ------------------------------------------------------------
const counterGroup = new THREE.Group();
counterGroup.position.set(0, 0, -2.58);
scene.add(counterGroup);
const counterPole = new THREE.Mesh(
new THREE.CylinderGeometry(0.055, 0.07, 2.75, 8),
materials.pole
);
counterPole.position.y = 1.36;
counterPole.castShadow = true;
counterGroup.add(counterPole);
const counterFeet = new THREE.Mesh(
makeRoundedGeometry(0.72, 0.42, 0.14, 0.13, 0.035),
new THREE.MeshStandardMaterial({ color: 0xd75b46, roughness: 0.75 })
);
counterFeet.position.y = 0.02;
counterFeet.castShadow = true;
counterGroup.add(counterFeet);
const counterCanvas = document.createElement("canvas");
counterCanvas.width = 1024;
counterCanvas.height = 420;
function updateCounterTexture(tile) {
const ctx = counterCanvas.getContext("2d");
ctx.clearRect(0, 0, counterCanvas.width, counterCanvas.height);
roundedRectPath(ctx, 10, 10, 1004, 400, 58);
ctx.fillStyle = "#fff4d9";
ctx.fill();
ctx.lineWidth = 22;
ctx.strokeStyle = "#e75e48";
ctx.stroke();
roundedRectPath(ctx, 34, 34, 956, 352, 42);
ctx.lineWidth = 7;
ctx.strokeStyle = "#26352f";
ctx.stroke();
ctx.textBaseline = "middle";
ctx.fillStyle = "#e75e48";
ctx.font = "900 42px system-ui, sans-serif";
ctx.fillText("TOY FERTILITY", 78, 91);
ctx.fillStyle = "#66756d";
ctx.font = "800 23px system-ui, sans-serif";
ctx.fillText("GAME TOKENS ONLY • NO SOIL TEST", 80, 137);
ctx.strokeStyle = "rgba(38,53,47,.22)";
ctx.lineWidth = 4;
ctx.beginPath();
ctx.moveTo(360, 70);
ctx.lineTo(360, 346);
ctx.stroke();
ctx.fillStyle = "#26352f";
ctx.font = "950 165px system-ui, sans-serif";
ctx.fillText(String(tile.fertility), 104, 248);
ctx.fillStyle = "#7c837d";
ctx.font = "800 54px system-ui, sans-serif";
ctx.fillText("/ 3", 285, 270);
ctx.fillStyle = "#26352f";
ctx.font = "950 64px system-ui, sans-serif";
ctx.fillText(`TILE ${tile.letter}`, 415, 109);
ctx.fillStyle = "#66756d";
ctx.font = "800 31px system-ui, sans-serif";
ctx.fillText(tile.name, 415, 165);
for (let i = 0; i < 3; i++) {
const x = 450 + i * 105;
ctx.beginPath();
ctx.arc(x, 255, 36, 0, Math.PI * 2);
if (i < tile.fertility) {
ctx.fillStyle = "#f3bd46";
ctx.fill();
ctx.lineWidth = 8;
ctx.strokeStyle = "#b9831d";
ctx.stroke();
} else {
ctx.fillStyle = "#ded4bd";
ctx.fill();
ctx.lineWidth = 8;
ctx.strokeStyle = "#b6aa91";
ctx.stroke();
}
}
ctx.fillStyle = "#26352f";
ctx.font = "900 24px system-ui, sans-serif";
ctx.fillText("SELECT A FIELD TO CHANGE THE PLASTIC NUMBER", 415, 340);
if (counterSprite.material.map) {
counterSprite.material.map.dispose();
}
counterSprite.material.map = canvasTexture(counterCanvas);
counterSprite.material.needsUpdate = true;
}
const counterSprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: canvasTexture(counterCanvas),
transparent: true,
depthWrite: false
})
);
counterSprite.position.set(0, 3.05, 0);
counterSprite.scale.set(4.65, 1.91, 1);
counterGroup.add(counterSprite);
// ------------------------------------------------------------
// Selection outline
// ------------------------------------------------------------
const selectionOutline = new THREE.Mesh(
makeRoundedGeometry(3.72, 3.12, 0.04, 0.38, 0.02),
new THREE.MeshBasicMaterial({
color: 0xf3bd46,
transparent: true,
opacity: 0.48,
depthWrite: false
})
);
selectionOutline.position.set(
tileDefinitions[0].position.x,
-0.025,
tileDefinitions[0].position.z
);
scene.add(selectionOutline);
// A few softly floating game-like specks.
const floatingSpecks = [];
const speckGeometry = new THREE.SphereGeometry(0.035, 7, 6);
const speckMaterial = new THREE.MeshBasicMaterial({ color: 0xf7d46d });
for (let i = 0; i < 14; i++) {
const speck = new THREE.Mesh(speckGeometry, speckMaterial);
speck.position.set(
-5.5 + (i * 1.73) % 11,
1.1 + (i % 4) * 0.32,
-1.7 + (i % 5) * 0.75
);
speck.userData.phase = i * 0.7;
scene.add(speck);
floatingSpecks.push(speck);
}
// ------------------------------------------------------------
// UI state and selection
// ------------------------------------------------------------
const ui = {
letter: document.getElementById("tileLetter"),
name: document.getElementById("tileName"),
value: document.getElementById("fertilityValue"),
pips: document.getElementById("pips"),
status: document.getElementById("tileStatus")
};
let selectedTile = 0;
function selectTile(index) {
selectedTile = (index + tileDefinitions.length) % tileDefinitions.length;
const tile = tileDefinitions[selectedTile];
const tileObject = tileGroups[selectedTile];
selectionOutline.position.set(
tile.position.x,
-0.025,
tile.position.z
);
tileGroups.forEach((entry, i) => {
entry.topMaterial.emissive.setHex(
i === selectedTile ? 0x3a210d : 0x000000
);
entry.topMaterial.emissiveIntensity = i === selectedTile ? 0.16 : 0;
});
ui.letter.textContent = tile.letter;
ui.name.textContent = tile.name;
ui.value.textContent = tile.fertility;
ui.status.textContent = tile.status;
ui.pips.setAttribute(
"aria-label",
`${tile.fertility} of 3 game tokens`
);
[...ui.pips.children].forEach((pip, i) => {
pip.classList.toggle("on", i < tile.fertility);
});
updateCounterTexture(tile);
}
document.getElementById("nextTile").addEventListener("click", () => {
selectTile(selectedTile + 1);
});
selectTile(0);
// ------------------------------------------------------------
// Direct camera controls — no external controls module
// ------------------------------------------------------------
const target = new THREE.Vector3(0, 0.85, 0);
const spherical = new THREE.Spherical(13.5, 1.02, 0.58);
function resetCamera() {
spherical.radius = 13.5;
spherical.phi = 1.02;
spherical.theta = 0.58;
}
function updateCamera() {
spherical.phi = THREE.MathUtils.clamp(spherical.phi, 0.62, 1.36);
spherical.radius = THREE.MathUtils.clamp(spherical.radius, 8.5, 19);
camera.position.setFromSpherical(spherical).add(target);
camera.lookAt(target);
}
document.getElementById("resetView").addEventListener("click", resetCamera);
updateCamera();
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const canvas = renderer.domElement;
let pointerDown = false;
let pointerMoved = false;
let previousX = 0;
let previousY = 0;
let downX = 0;
let downY = 0;
canvas.addEventListener("pointerdown", (event) => {
pointerDown = true;
pointerMoved = false;
previousX = event.clientX;
previousY = event.clientY;
downX = event.clientX;
downY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.style.cursor = "grabbing";
});
canvas.addEventListener("pointermove", (event) => {
if (!pointerDown) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
if (
Math.abs(event.clientX - downX) +
Math.abs(event.clientY - downY) >
5
) {
pointerMoved = true;
}
spherical.theta -= dx * 0.006;
spherical.phi -= dy * 0.005;
previousX = event.clientX;
previousY = event.clientY;
updateCamera();
});
canvas.addEventListener("pointerup", (event) => {
if (!pointerDown) return;
pointerDown = false;
canvas.style.cursor = "grab";
if (!pointerMoved) {
const rect = canvas.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(tileHitMeshes, false);
if (hits.length) {
selectTile(hits[0].object.userData.tileIndex);
}
}
});
canvas.addEventListener("pointercancel", () => {
pointerDown = false;
canvas.style.cursor = "grab";
});
canvas.addEventListener("wheel", (event) => {
event.preventDefault();
spherical.radius += event.deltaY * 0.008;
updateCamera();
}, { passive: false });
canvas.style.cursor = "grab";
// ------------------------------------------------------------
// Resize and animation
// ------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
const clock = new THREE.Clock();
function animate() {
const elapsed = clock.getElapsedTime();
animatedCrops.forEach((crop) => {
crop.rotation.z = Math.sin(elapsed * 1.6 + crop.userData.phase) * 0.025;
crop.position.y =
0.68 + Math.sin(elapsed * 1.35 + crop.userData.phase) * 0.012;
});
flagPivot.rotation.y = Math.sin(elapsed * 2.3) * 0.08;
flagPivot.rotation.z = Math.sin(elapsed * 2.8) * 0.025;
counterSprite.position.y =
3.05 + Math.sin(elapsed * 1.1) * 0.025;
floatingSpecks.forEach((speck, i) => {
speck.position.y += Math.sin(elapsed * 1.5 + speck.userData.phase) * 0.002;
speck.position.x += Math.sin(elapsed * 0.45 + i) * 0.0007;
speck.material.opacity = 0.75;
});
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();
requestAnimationFrame(() => {
const loading = document.getElementById("loading");
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 400);
});
</script>
</body>
</html>
```