Prompt specification
Build or customize the Three.js 3D scene "One Tile Step and Obstacle Cube" 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: One Tile Step and Obstacle Cube
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/one-tile-step-and-obstacle-cube-x3457
Scene Description Prompt:
Make a voxel grid-movement puzzle with two floor tiles, a player, and a blocking cube. Three.js from cdnjs, one HTML file.
Working Three.js Starter (one-tile-step-and-obstacle-cube-x3457):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Voxel Shift</title>
<style>
:root {
color-scheme: dark;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
--panel: rgba(13, 20, 38, 0.78);
--border: rgba(255, 255, 255, 0.12);
--cyan: #66e6ff;
--gold: #ffd166;
--red: #ff6377;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #10172a;
color: white;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
}
.topbar {
position: absolute;
top: 20px;
left: 20px;
right: 20px;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 16px;
}
.card {
background: var(--panel);
border: 1px solid var(--border);
border-radius: 18px;
box-shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
.intro {
width: min(390px, calc(100vw - 112px));
padding: 18px 20px;
}
.eyebrow {
margin-bottom: 7px;
color: var(--cyan);
font-size: 0.72rem;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(1.5rem, 3vw, 2.1rem);
line-height: 1;
letter-spacing: -0.04em;
}
.description {
margin: 12px 0 15px;
color: rgba(255, 255, 255, 0.72);
font-size: 0.92rem;
line-height: 1.45;
}
.status-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
}
.status {
display: inline-flex;
align-items: center;
gap: 7px;
color: rgba(255, 255, 255, 0.78);
font-size: 0.78rem;
font-weight: 700;
}
.status-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--red);
box-shadow: 0 0 12px var(--red);
}
#goal-state {
padding: 6px 9px;
border: 1px solid rgba(255, 99, 119, 0.25);
border-radius: 999px;
color: #ff9aaa;
background: rgba(255, 99, 119, 0.08);
font-size: 0.66rem;
font-weight: 900;
letter-spacing: 0.12em;
}
button {
pointer-events: auto;
border: 1px solid var(--border);
color: white;
background: rgba(255, 255, 255, 0.08);
font: inherit;
font-weight: 750;
cursor: pointer;
transition:
transform 120ms ease,
background 120ms ease,
border-color 120ms ease,
opacity 120ms ease;
}
button:hover:not(:disabled) {
transform: translateY(-2px);
background: rgba(255, 255, 255, 0.14);
border-color: rgba(255, 255, 255, 0.28);
}
button:active:not(:disabled) {
transform: translateY(0);
}
button:focus-visible {
outline: 2px solid var(--cyan);
outline-offset: 3px;
}
button:disabled {
cursor: not-allowed;
opacity: 0.35;
}
#reset {
min-width: 82px;
padding: 12px 16px;
border-radius: 14px;
}
.camera-tip {
position: absolute;
right: 22px;
bottom: 22px;
padding: 9px 12px;
border-radius: 999px;
color: rgba(255, 255, 255, 0.55);
background: rgba(9, 14, 27, 0.48);
font-size: 0.72rem;
pointer-events: none;
}
.controls {
position: absolute;
left: 50%;
bottom: 22px;
transform: translateX(-50%);
display: flex;
align-items: center;
gap: 8px;
padding: 9px;
border-radius: 18px;
white-space: nowrap;
}
.move-button {
width: 48px;
height: 44px;
border-radius: 12px;
font-size: 1.2rem;
}
.control-copy {
min-width: 130px;
padding: 0 8px;
color: rgba(255, 255, 255, 0.68);
text-align: center;
font-size: 0.75rem;
line-height: 1.3;
}
kbd {
display: inline-block;
min-width: 22px;
margin: 0 2px;
padding: 2px 5px;
border: 1px solid rgba(255, 255, 255, 0.18);
border-bottom-width: 2px;
border-radius: 5px;
color: white;
background: rgba(255, 255, 255, 0.07);
font: 700 0.68rem ui-monospace, SFMono-Regular, Menlo, monospace;
}
.win {
position: absolute;
top: 50%;
left: 50%;
min-width: min(360px, calc(100vw - 40px));
padding: 26px;
border: 1px solid rgba(255, 209, 102, 0.4);
border-radius: 22px;
background: rgba(20, 26, 43, 0.9);
box-shadow:
0 24px 80px rgba(0, 0, 0, 0.45),
0 0 60px rgba(255, 209, 102, 0.12);
text-align: center;
opacity: 0;
transform: translate(-50%, -42%) scale(0.92);
transition:
opacity 240ms ease,
transform 300ms cubic-bezier(0.2, 0.9, 0.2, 1.15);
}
.win.show {
opacity: 1;
transform: translate(-50%, -50%) scale(1);
}
.win-icon {
display: grid;
width: 54px;
height: 54px;
margin: 0 auto 13px;
place-items: center;
border-radius: 16px;
color: #222033;
background: var(--gold);
font-size: 1.7rem;
font-weight: 900;
box-shadow: 0 0 35px rgba(255, 209, 102, 0.35);
}
.win h2 {
margin: 0 0 7px;
font-size: 1.7rem;
letter-spacing: -0.035em;
}
.win p {
margin: 0;
color: rgba(255, 255, 255, 0.67);
font-size: 0.9rem;
}
@media (max-width: 620px) {
.topbar {
top: 12px;
left: 12px;
right: 12px;
}
.intro {
width: calc(100vw - 92px);
padding: 15px 16px;
}
.description {
margin: 9px 0 12px;
font-size: 0.82rem;
}
#reset {
min-width: 68px;
padding: 11px 12px;
}
.controls {
bottom: 14px;
}
.camera-tip {
display: none;
}
.control-copy {
min-width: 105px;
font-size: 0.68rem;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Voxel grid movement puzzle"></canvas>
<div class="hud">
<div class="topbar">
<section class="card intro">
<div class="eyebrow">One-tile puzzle</div>
<h1>Voxel Shift</h1>
<p class="description">
The red cube blocks the gold tile. Push it off the edge to clear your path.
</p>
<div class="status-row">
<div class="status">
<span class="status-dot"></span>
<span id="move-count">0 moves</span>
</div>
<div id="goal-state">BLOCKED</div>
</div>
</section>
<button id="reset" class="card" type="button">Reset</button>
</div>
<div class="controls card">
<button id="left" class="move-button" type="button" aria-label="Move left">←</button>
<div class="control-copy">
Move / push<br />
<kbd>A</kbd><kbd>D</kbd> or <kbd>←</kbd><kbd>→</kbd>
</div>
<button id="right" class="move-button" type="button" aria-label="Move right">→</button>
</div>
<div class="camera-tip">Drag to orbit · Scroll to zoom</div>
<section id="win" class="win card" aria-live="polite">
<div class="win-icon">✓</div>
<h2>Tile cleared!</h2>
<p id="win-message">You solved the puzzle in 1 move.</p>
</section>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.querySelector("#scene");
const moveCount = document.querySelector("#move-count");
const goalState = document.querySelector("#goal-state");
const winBanner = document.querySelector("#win");
const winMessage = document.querySelector("#win-message");
const leftButton = document.querySelector("#left");
const rightButton = document.querySelector("#right");
const resetButton = document.querySelector("#reset");
const TILE_STEP = 2;
const TILE_TOP = 0.14;
const PLAYER_START_X = -1;
const GOAL_X = 1;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x10172a);
scene.fog = new THREE.Fog(0x10172a, 9, 18);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight, false);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
const hemisphere = new THREE.HemisphereLight(0xccecff, 0x182038, 2.1);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffffff, 3.1);
keyLight.position.set(4, 7, 5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -7;
keyLight.shadow.camera.right = 7;
keyLight.shadow.camera.top = 7;
keyLight.shadow.camera.bottom = -7;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 20;
keyLight.shadow.bias = -0.0005;
scene.add(keyLight);
const rimLight = new THREE.PointLight(0x6b7cff, 22, 12, 2);
rimLight.position.set(-4, 3, -4);
scene.add(rimLight);
const warmLight = new THREE.PointLight(0xffc15a, 12, 10, 2);
warmLight.position.set(4, 2.5, 1);
scene.add(warmLight);
function makeBlock(width, height, depth, material, x, y, z) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
// Exactly two walkable floor tiles.
const safeMaterial = new THREE.MeshStandardMaterial({
color: 0x3b5878,
roughness: 0.72,
metalness: 0.08,
emissive: 0x10243a,
emissiveIntensity: 0.16
});
const goalMaterial = new THREE.MeshStandardMaterial({
color: 0xf4bd55,
roughness: 0.48,
metalness: 0.22,
emissive: 0xffa928,
emissiveIntensity: 0.28
});
const tileMeshes = [];
const tiles = [
{
x: PLAYER_START_X,
material: safeMaterial,
index: 0
},
{
x: GOAL_X,
material: goalMaterial,
index: 1
}
];
for (const tile of tiles) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(1.86, 0.28, 1.86),
tile.material
);
mesh.position.set(tile.x, 0, 0);
mesh.castShadow = true;
mesh.receiveShadow = true;
mesh.userData.tileIndex = tile.index;
tileMeshes.push(mesh);
scene.add(mesh);
}
// Blocky voxel player.
const player = new THREE.Group();
scene.add(player);
const cyanMaterial = new THREE.MeshStandardMaterial({
color: 0x58d9f4,
roughness: 0.58,
metalness: 0.05
});
const paleMaterial = new THREE.MeshStandardMaterial({
color: 0xd8f7ff,
roughness: 0.68,
metalness: 0
});
const navyMaterial = new THREE.MeshStandardMaterial({
color: 0x162238,
roughness: 0.78,
metalness: 0.02
});
const eyeMaterial = new THREE.MeshBasicMaterial({ color: 0x111827 });
player.add(
makeBlock(0.18, 0.34, 0.22, navyMaterial, -0.14, 0.17, 0),
makeBlock(0.18, 0.34, 0.22, navyMaterial, 0.14, 0.17, 0),
makeBlock(0.54, 0.46, 0.36, cyanMaterial, 0, 0.57, 0),
makeBlock(0.16, 0.38, 0.2, cyanMaterial, -0.36, 0.56, 0),
makeBlock(0.16, 0.38, 0.2, cyanMaterial, 0.36, 0.56, 0),
makeBlock(0.52, 0.46, 0.48, paleMaterial, 0, 1.03, 0),
makeBlock(0.09, 0.11, 0.025, eyeMaterial, -0.12, 1.06, 0.252),
makeBlock(0.09, 0.11, 0.025, eyeMaterial, 0.12, 1.06, 0.252),
makeBlock(0.16, 0.055, 0.025, eyeMaterial, 0, 0.93, 0.252)
);
// The blocking, pushable voxel cube.
const cube = new THREE.Group();
const cubeMaterial = new THREE.MeshStandardMaterial({
color: 0xf04f65,
roughness: 0.52,
metalness: 0.12,
emissive: 0x5e0c1a,
emissiveIntensity: 0.24,
transparent: true,
opacity: 1
});
const cubeGeometry = new THREE.BoxGeometry(0.88, 0.88, 0.88);
const cubeMesh = new THREE.Mesh(cubeGeometry, cubeMaterial);
cubeMesh.position.y = 0.44;
cubeMesh.castShadow = true;
cubeMesh.receiveShadow = true;
cube.add(cubeMesh);
const cubeEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(cubeGeometry),
new THREE.LineBasicMaterial({
color: 0xffa9b4,
transparent: true,
opacity: 0.78
})
);
cubeEdges.position.y = 0.44;
cube.add(cubeEdges);
scene.add(cube);
let playerIndex = 0;
let cubeIndex = 1;
let moves = 0;
let busy = false;
let won = false;
let motion = null;
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
// Direct camera controls, implemented without Three.js addons.
const view = {
azimuth: 0.64,
elevation: 0.67,
radius: 7.6,
target: new THREE.Vector3(0, 0.38, 0)
};
function updateCamera() {
const horizontal = Math.cos(view.elevation) * view.radius;
camera.position.set(
view.target.x + horizontal * Math.sin(view.azimuth),
view.target.y + Math.sin(view.elevation) * view.radius,
view.target.z + horizontal * Math.cos(view.azimuth)
);
camera.lookAt(view.target);
}
updateCamera();
function easeOutCubic(value) {
return 1 - Math.pow(1 - value, 3);
}
function updateHUD() {
moveCount.textContent = `${moves} ${moves === 1 ? "move" : "moves"}`;
if (won) {
goalState.textContent = "SOLVED";
goalState.style.color = "#ffe29a";
goalState.style.borderColor = "rgba(255, 209, 102, 0.35)";
goalState.style.background = "rgba(255, 209, 102, 0.09)";
} else if (motion?.kind === "push") {
goalState.textContent = "PUSHING";
goalState.style.color = "#ffd166";
goalState.style.borderColor = "rgba(255, 209, 102, 0.35)";
goalState.style.background = "rgba(255, 209, 102, 0.09)";
} else {
goalState.textContent = "BLOCKED";
goalState.style.color = "#ff9aaa";
goalState.style.borderColor = "rgba(255, 99, 119, 0.25)";
goalState.style.background = "rgba(255, 99, 119, 0.08)";
}
leftButton.disabled = busy || won || playerIndex === 0;
rightButton.disabled = busy || won || playerIndex === 1;
}
function showWin() {
won = true;
winMessage.textContent = `You solved the puzzle in ${moves} ${
moves === 1 ? "move" : "moves"
}.`;
winBanner.classList.add("show");
updateHUD();
}
function tryMove(direction) {
if (busy || won) return;
const targetIndex = playerIndex + direction;
if (targetIndex < 0 || targetIndex >= tiles.length) return;
busy = true;
moves++;
const playerFrom = player.position.clone();
const playerTo = new THREE.Vector3(
tiles[targetIndex].x,
TILE_TOP,
0
);
playerIndex = targetIndex;
player.rotation.y = direction > 0 ? Math.PI / 2 : -Math.PI / 2;
if (cubeIndex === targetIndex) {
const cubeFrom = cube.position.clone();
const cubeTo = cubeFrom.clone().add(
new THREE.Vector3(direction * TILE_STEP, 0, 0)
);
cubeIndex = null;
motion = {
kind: "push",
start: performance.now(),
duration: 900,
playerFrom,
playerTo,
cubeFrom,
cubeTo
};
} else {
motion = {
kind: "walk",
start: performance.now(),
duration: 280,
playerFrom,
playerTo
};
}
updateHUD();
}
function finishMotion() {
const completedMotion = motion;
motion = null;
busy = false;
if (completedMotion.kind === "push") {
cube.visible = false;
showWin();
} else if (playerIndex === 1) {
showWin();
} else {
updateHUD();
}
}
function updateMotion(now) {
if (!motion) return;
const t = Math.min((now - motion.start) / motion.duration, 1);
if (motion.kind === "push") {
const pushProgress = Math.min(t / 0.52, 1);
const easedPush = easeOutCubic(pushProgress);
player.position.lerpVectors(
motion.playerFrom,
motion.playerTo,
easedPush
);
cube.position.lerpVectors(
motion.cubeFrom,
motion.cubeTo,
easedPush
);
if (t > 0.52) {
const fallProgress = (t - 0.52) / 0.48;
cube.position.y =
motion.cubeTo.y - 5.5 * fallProgress * fallProgress;
cube.rotation.z = fallProgress * 1.35;
cube.rotation.x = fallProgress * 0.28;
cubeMaterial.opacity = 1 - fallProgress;
cubeEdges.material.opacity = 0.78 * (1 - fallProgress);
}
} else {
player.position.lerpVectors(
motion.playerFrom,
motion.playerTo,
easeOutCubic(t)
);
}
if (t >= 1) {
finishMotion();
}
}
function resetPuzzle() {
motion = null;
busy = false;
won = false;
moves = 0;
playerIndex = 0;
cubeIndex = 1;
player.position.set(PLAYER_START_X, TILE_TOP, 0);
player.rotation.set(0, 0, 0);
cube.position.set(GOAL_X, TILE_TOP, 0);
cube.rotation.set(0, 0, 0);
cube.scale.set(1, 1, 1);
cube.visible = true;
cubeMaterial.opacity = 1;
cubeEdges.material.opacity = 0.78;
winBanner.classList.remove("show");
updateHUD();
}
function selectTile(event) {
if (busy || won) return;
const bounds = canvas.getBoundingClientRect();
pointer.x =
((event.clientX - bounds.left) / bounds.width) * 2 - 1;
pointer.y =
-((event.clientY - bounds.top) / bounds.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(tileMeshes, false);
if (!hits.length) return;
const selectedIndex = hits[0].object.userData.tileIndex;
if (selectedIndex === playerIndex) return;
tryMove(Math.sign(selectedIndex - playerIndex));
}
let dragging = false;
let dragPointerId = null;
let lastX = 0;
let lastY = 0;
let dragDistance = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
dragPointerId = event.pointerId;
lastX = event.clientX;
lastY = event.clientY;
dragDistance = 0;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging || event.pointerId !== dragPointerId) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
dragDistance += Math.abs(dx) + Math.abs(dy);
lastX = event.clientX;
lastY = event.clientY;
view.azimuth -= dx * 0.006;
view.elevation = THREE.MathUtils.clamp(
view.elevation + dy * 0.004,
0.35,
1.12
);
updateCamera();
});
canvas.addEventListener("pointerup", (event) => {
if (!dragging || event.pointerId !== dragPointerId) return;
dragging = false;
dragPointerId = null;
if (dragDistance < 8) {
selectTile(event);
}
});
canvas.addEventListener("pointercancel", () => {
dragging = false;
dragPointerId = null;
});
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
view.radius = THREE.MathUtils.clamp(
view.radius + event.deltaY * 0.006,
5.5,
11
);
updateCamera();
},
{ passive: false }
);
leftButton.addEventListener("click", () => tryMove(-1));
rightButton.addEventListener("click", () => tryMove(1));
resetButton.addEventListener("click", resetPuzzle);
window.addEventListener("keydown", (event) => {
if (
event.code === "KeyA" ||
event.code === "ArrowLeft"
) {
event.preventDefault();
tryMove(-1);
}
if (
event.code === "KeyD" ||
event.code === "ArrowRight"
) {
event.preventDefault();
tryMove(1);
}
if (event.code === "KeyR") {
resetPuzzle();
}
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight, false);
});
resetPuzzle();
renderer.setAnimationLoop((now) => {
updateMotion(now);
const time = now * 0.001;
goalMaterial.emissiveIntensity = won
? 0.64 + Math.sin(time * 4) * 0.08
: 0.28 + Math.sin(time * 3.2) * 0.1;
renderer.render(scene, camera);
});
</script>
</body>
</html>
```