Prompt specification
Build or customize the Three.js 3D scene "Rubber-lipped dustpan" 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: Rubber-lipped dustpan
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/rubber-lipped-dustpan-x0021
Scene Description Prompt:
Make one HTML file using Three.js from cdnjs for this stylized scene: Show a dustpan with flat front lip, shallow bowl, and angled handle beside several paper crumbs; its contact edge must sit flush against the floor.
Technical checks: Keep the rubber lip flush with the floor and connect it to the pan basin with an unobstructed entrance so swept paper can pass into the pan.
Return one complete HTML document that works with the cdnjs Three.js r160 module inside a sandbox with scripts allowed. Make the requested subject visible at the default camera. Use procedural assets and local button handlers. Do not use native form submission, pointer lock, external assets or runtime requests other than Three.js.
Working Three.js Starter (rubber-lipped-dustpan-x0021):
```html
<!DOCTYPE html>
<html lang="pt-BR">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" href="data:,">
<title>Pá de recolher papéis</title>
<style>
:root {
color-scheme: light;
font-family: Inter, ui-rounded, "Segoe UI", Arial, sans-serif;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e8eadf;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.panel {
position: fixed;
z-index: 10;
top: 18px;
left: 18px;
width: min(380px, calc(100vw - 36px));
padding: 18px 18px 16px;
border: 1px solid rgba(31, 56, 55, 0.14);
border-radius: 18px;
background: rgba(255, 255, 255, 0.88);
box-shadow: 0 12px 35px rgba(39, 62, 58, 0.14);
backdrop-filter: blur(10px);
-webkit-backdrop-filter: blur(10px);
}
.eyebrow {
margin: 0 0 5px;
color: #28766e;
font-size: 0.72rem;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
h1 {
margin: 0;
color: #244442;
font-size: clamp(1.25rem, 2.5vw, 1.7rem);
line-height: 1.12;
}
.objective {
margin: 9px 0 14px;
color: #526563;
font-size: 0.9rem;
line-height: 1.45;
}
.buttons {
display: flex;
flex-wrap: wrap;
gap: 8px;
}
button {
appearance: none;
border: 0;
border-radius: 11px;
padding: 10px 13px;
background: #f5bc27;
color: #3d351d;
font: inherit;
font-size: 0.83rem;
font-weight: 800;
cursor: pointer;
box-shadow: 0 4px 0 #d69d13;
transition: transform 120ms ease, box-shadow 120ms ease, opacity 120ms ease;
}
button:hover:not(:disabled) {
transform: translateY(-1px);
box-shadow: 0 5px 0 #d69d13;
}
button:active:not(:disabled) {
transform: translateY(2px);
box-shadow: 0 2px 0 #d69d13;
}
button.secondary {
background: #dcebea;
color: #245b57;
box-shadow: 0 4px 0 #b8d1cf;
}
button.secondary:hover:not(:disabled) {
box-shadow: 0 5px 0 #b8d1cf;
}
button:disabled {
cursor: wait;
opacity: 0.62;
}
.status {
min-height: 42px;
margin-top: 13px;
padding: 10px 11px;
border-radius: 11px;
background: #eef3ee;
color: #4e625f;
font-size: 0.78rem;
font-weight: 700;
line-height: 1.35;
}
.status.good {
background: #dff3e8;
color: #236348;
}
.status.warn {
background: #fff2cc;
color: #725717;
}
.status.bad {
background: #fde4df;
color: #8b382b;
}
.counter {
float: right;
margin-left: 8px;
padding: 3px 8px;
border-radius: 999px;
background: rgba(39, 118, 110, 0.12);
color: #236b65;
font-size: 0.72rem;
white-space: nowrap;
}
.hint {
position: fixed;
z-index: 8;
left: 50%;
bottom: 18px;
width: max-content;
max-width: calc(100vw - 32px);
transform: translateX(-50%);
padding: 9px 14px;
border: 1px solid rgba(36, 68, 66, 0.12);
border-radius: 999px;
background: rgba(255, 255, 255, 0.86);
color: #49605d;
font-size: 0.78rem;
font-weight: 700;
text-align: center;
box-shadow: 0 6px 20px rgba(36, 68, 66, 0.11);
pointer-events: none;
}
@media (max-width: 620px) {
.panel {
top: 10px;
left: 10px;
width: calc(100vw - 20px);
padding: 14px;
}
.objective {
margin-bottom: 10px;
}
.hint {
bottom: 10px;
font-size: 0.72rem;
}
}
</style>
</head>
<body>
<main id="scene" aria-label="Cena 3D interativa de uma pá e pedaços de papel"></main>
<section class="panel" aria-label="Controles da atividade">
<p class="eyebrow">Atividade interativa</p>
<h1>Pá e farelos de papel</h1>
<p class="objective">
Objetivo: recolher os pedaços de papel e observar que a borda frontal rasa
mantém uma abertura contínua para a cuba.
</p>
<div class="buttons">
<button id="demoButton" type="button">Demonstrar e testar</button>
<button id="verifyButton" class="secondary" type="button">Verificar</button>
<button id="resetButton" class="secondary" type="button">Reiniciar</button>
</div>
<div id="status" class="status" role="status" aria-live="polite">
Preparando a cena…
</div>
</section>
<div class="hint">
Arraste os pedaços de papel para dentro da pá · Arraste o fundo para girar a câmera
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const sceneHost = document.getElementById("scene");
const statusElement = document.getElementById("status");
const demoButton = document.getElementById("demoButton");
const verifyButton = document.getElementById("verifyButton");
const resetButton = document.getElementById("resetButton");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe8eadf);
scene.fog = new THREE.Fog(0xe8eadf, 17, 32);
const renderer = new THREE.WebGLRenderer({ antialias: true });
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.08;
renderer.domElement.setAttribute(
"aria-label",
"Pá amarela, cuba rasa e pedaços de papel arrastáveis"
);
sceneHost.appendChild(renderer.domElement);
const camera = new THREE.PerspectiveCamera(
39,
window.innerWidth / window.innerHeight,
0.1,
100
);
const cameraTarget = new THREE.Vector3(0.25, 0.48, -0.18);
let cameraTheta = 0.57;
let cameraPhi = 0.86;
let cameraRadius = 10.9;
function updateCamera() {
const horizontal = Math.sin(cameraPhi) * cameraRadius;
camera.position.set(
cameraTarget.x + Math.sin(cameraTheta) * horizontal,
cameraTarget.y + Math.cos(cameraPhi) * cameraRadius,
cameraTarget.z + Math.cos(cameraTheta) * horizontal
);
camera.lookAt(cameraTarget);
}
function handleResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
cameraRadius = window.innerWidth < 620 ? 12.7 : 10.9;
updateCamera();
}
updateCamera();
window.addEventListener("resize", handleResize);
const hemisphere = new THREE.HemisphereLight(0xffffff, 0x8b9b87, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff5dc, 3.1);
sun.position.set(5.5, 9, 6.5);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -8;
sun.shadow.camera.right = 8;
sun.shadow.camera.top = 8;
sun.shadow.camera.bottom = -8;
sun.shadow.camera.near = 0.5;
sun.shadow.camera.far = 25;
sun.shadow.bias = -0.00015;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xcce7ea, 1.0);
fill.position.set(-5, 4, -4);
scene.add(fill);
const floorMaterial = new THREE.MeshStandardMaterial({
color: 0xeee8da,
roughness: 0.96,
metalness: 0
});
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(40, 40),
floorMaterial
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = 0;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(28, 28, 0x8ea9a2, 0xb5beb3);
grid.position.y = 0.003;
grid.material.transparent = true;
grid.material.opacity = 0.16;
scene.add(grid);
const dustpan = new THREE.Group();
dustpan.name = "Dustpan";
scene.add(dustpan);
const yellow = new THREE.MeshStandardMaterial({
color: 0xf4b91f,
roughness: 0.67,
metalness: 0.02,
side: THREE.DoubleSide
});
const yellowDark = new THREE.MeshStandardMaterial({
color: 0xd9930b,
roughness: 0.72,
metalness: 0.01,
side: THREE.DoubleSide
});
const yellowLight = new THREE.MeshStandardMaterial({
color: 0xffcd43,
roughness: 0.72,
metalness: 0,
side: THREE.DoubleSide
});
const gripMaterial = new THREE.MeshStandardMaterial({
color: 0x315b59,
roughness: 0.84,
metalness: 0
});
const FRONT_Z = 1.0;
const REAR_Z = -1.02;
// The tray is one continuous shallow surface. There is deliberately no
// transverse vertical wall behind the lip.
const stations = [
{ z: 1.00, half: 1.72, base: 0.045, side: 0.07 },
{ z: 0.34, half: 1.68, base: 0.050, side: 0.14 },
{ z: -0.34, half: 1.47, base: 0.078, side: 0.33 },
{ z: -1.02, half: 1.25, base: 0.150, side: 0.58 }
];
function stationAt(z) {
const t = THREE.MathUtils.clamp(
(FRONT_Z - z) / (FRONT_Z - REAR_Z),
0,
1
);
const scaled = t * (stations.length - 1);
const index = Math.min(Math.floor(scaled), stations.length - 2);
const fraction = scaled - index;
const a = stations[index];
const b = stations[index + 1];
return {
t,
z,
half: THREE.MathUtils.lerp(a.half, b.half, fraction),
base: THREE.MathUtils.lerp(a.base, b.base, fraction),
side: THREE.MathUtils.lerp(a.side, b.side, fraction)
};
}
function floorHeightAt(x, z) {
const st = stationAt(z);
const ratio = Math.min(Math.abs(x) / st.half, 1);
return st.base + 0.018 * ratio * ratio * st.t;
}
function halfWidthAt(z) {
return stationAt(z).half;
}
function isInsidePan(x, z) {
return (
z < FRONT_Z - 0.055 &&
z > REAR_Z + 0.08 &&
Math.abs(x) < halfWidthAt(z) - 0.10
);
}
function makeBowlFloorGeometry() {
const positions = [];
const uvs = [];
const indices = [];
const centerIndices = [];
const xSegments = 16;
for (let j = 0; j < stations.length; j++) {
const st = stations[j];
for (let i = 0; i <= xSegments; i++) {
const u = i / xSegments;
const x = THREE.MathUtils.lerp(-st.half, st.half, u);
const y = floorHeightAt(x, st.z);
positions.push(x, y, st.z);
uvs.push(u, j / (stations.length - 1));
if (i === xSegments / 2) {
centerIndices.push(positions.length / 3 - 1);
}
}
}
const rowLength = xSegments + 1;
for (let j = 0; j < stations.length - 1; j++) {
for (let i = 0; i < xSegments; i++) {
const a = j * rowLength + i;
const b = a + 1;
const c = a + rowLength;
const d = c + 1;
indices.push(a, b, c, b, d, c);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setAttribute("uv", new THREE.Float32BufferAttribute(uvs, 2));
geometry.setIndex(indices);
geometry.computeVertexNormals();
geometry.userData.centerIndices = centerIndices;
geometry.userData.stations = stations;
return geometry;
}
const bowlFloor = new THREE.Mesh(
makeBowlFloorGeometry(),
yellowLight
);
bowlFloor.name = "Continuous shallow bowl floor";
bowlFloor.userData.role = "bowl-floor";
bowlFloor.receiveShadow = true;
bowlFloor.castShadow = true;
dustpan.add(bowlFloor);
function makeSideWall(side) {
const positions = [];
const indices = [];
for (let j = 0; j < stations.length - 1; j++) {
const a = stations[j];
const b = stations[j + 1];
const baseIndex = positions.length / 3;
positions.push(
side * a.half, floorHeightAt(side * a.half, a.z), a.z,
side * b.half, floorHeightAt(side * b.half, b.z), b.z,
side * a.half, a.base + a.side, a.z,
side * b.half, b.base + b.side, b.z
);
indices.push(
baseIndex, baseIndex + 1, baseIndex + 2,
baseIndex + 1, baseIndex + 3, baseIndex + 2
);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
return geometry;
}
const leftWall = new THREE.Mesh(makeSideWall(-1), yellow);
const rightWall = new THREE.Mesh(makeSideWall(1), yellow);
leftWall.userData.role = "side-wall";
rightWall.userData.role = "side-wall";
leftWall.castShadow = rightWall.castShadow = true;
leftWall.receiveShadow = rightWall.receiveShadow = true;
dustpan.add(leftWall, rightWall);
function makeBackWall() {
const positions = [];
const indices = [];
const xSegments = 16;
const rear = stations[stations.length - 1];
for (let i = 0; i <= xSegments; i++) {
const u = i / xSegments;
const x = THREE.MathUtils.lerp(-rear.half, rear.half, u);
positions.push(
x, floorHeightAt(x, rear.z), rear.z,
x, rear.base + rear.side, rear.z
);
}
for (let i = 0; i < xSegments; i++) {
const a = i * 2;
indices.push(a, a + 2, a + 1, a + 2, a + 3, a + 1);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
return geometry;
}
const backWall = new THREE.Mesh(makeBackWall(), yellowDark);
backWall.name = "Rear wall only";
backWall.userData.role = "rear-wall";
backWall.castShadow = true;
backWall.receiveShadow = true;
dustpan.add(backWall);
// The front lip is a flat slab. Its lower face is exactly at floor level.
const lipGeometry = new THREE.BoxGeometry(3.44, 0.045, 0.60);
const frontLip = new THREE.Mesh(lipGeometry, yellow);
frontLip.name = "Flat flush front lip";
frontLip.userData.role = "front-lip";
frontLip.position.set(0, 0.0225, 1.28);
frontLip.castShadow = true;
frontLip.receiveShadow = true;
dustpan.add(frontLip);
function cylinderBetween(start, end, radius, material, radialSegments = 12) {
const direction = new THREE.Vector3().subVectors(end, start);
const length = direction.length();
const geometry = new THREE.CylinderGeometry(
radius,
radius,
length,
radialSegments
);
const mesh = new THREE.Mesh(geometry, material);
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
// Side rails emphasize the bowl shape without closing the front opening.
for (const side of [-1, 1]) {
for (let i = 0; i < stations.length - 1; i++) {
const a = stations[i];
const b = stations[i + 1];
const start = new THREE.Vector3(
side * a.half,
a.base + a.side,
a.z
);
const end = new THREE.Vector3(
side * b.half,
b.base + b.side,
b.z
);
const rail = cylinderBetween(start, end, 0.026, yellowDark, 10);
rail.userData.role = "side-rail";
dustpan.add(rail);
}
}
const rear = stations[stations.length - 1];
const rearRail = cylinderBetween(
new THREE.Vector3(-rear.half, rear.base + rear.side, rear.z),
new THREE.Vector3(rear.half, rear.base + rear.side, rear.z),
0.027,
yellowDark,
10
);
rearRail.userData.role = "rear-rail";
dustpan.add(rearRail);
const handleLeftStart = new THREE.Vector3(-1.12, 0.68, -1.03);
const handleRightStart = new THREE.Vector3(1.12, 0.68, -1.03);
const handleLeftEnd = new THREE.Vector3(-1.40, 1.45, -2.22);
const handleRightEnd = new THREE.Vector3(1.40, 1.45, -2.22);
dustpan.add(
cylinderBetween(handleLeftStart, handleLeftEnd, 0.072, yellow),
cylinderBetween(handleRightStart, handleRightEnd, 0.072, yellow)
);
const handleGrip = cylinderBetween(
new THREE.Vector3(-1.48, 1.45, -2.22),
new THREE.Vector3(1.48, 1.45, -2.22),
0.105,
gripMaterial,
16
);
handleGrip.name = "Angled handle grip";
dustpan.add(handleGrip);
function createPaperGeometry(size, seed) {
const count = 6;
const positions = [0, 0.016, 0];
const indices = [];
for (let i = 0; i < count; i++) {
const angle = (i / count) * Math.PI * 2;
const variation = 0.82 + 0.15 * Math.sin(seed * 2.7 + i * 4.1);
const x = Math.cos(angle) * size * variation;
const z = Math.sin(angle) * size * (0.78 + 0.12 * Math.cos(i + seed));
positions.push(x, 0, z);
}
for (let i = 0; i < count; i++) {
const current = i + 1;
const next = ((i + 1) % count) + 1;
indices.push(0, next, current);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
return geometry;
}
const paperColors = [0xfffdf4, 0xf5efd9, 0xffffff, 0xfff8e8];
const homePositions = [
new THREE.Vector3(2.38, 0.014, 1.48),
new THREE.Vector3(2.76, 0.014, 0.97),
new THREE.Vector3(2.30, 0.014, 0.37),
new THREE.Vector3(3.08, 0.014, 1.37)
];
const collectionTargets = [
new THREE.Vector2(-0.58, -0.52),
new THREE.Vector2(0.03, -0.60),
new THREE.Vector2(0.56, -0.34),
new THREE.Vector2(-0.10, -0.18)
];
const papers = [];
const paperMeshes = [];
homePositions.forEach((home, index) => {
const material = new THREE.MeshStandardMaterial({
color: paperColors[index],
roughness: 0.98,
metalness: 0,
side: THREE.DoubleSide
});
const mesh = new THREE.Mesh(
createPaperGeometry(0.30 + index * 0.025, index + 1),
material
);
mesh.name = `Paper scrap ${index + 1}`;
mesh.userData.paperIndex = index;
mesh.position.copy(home);
mesh.rotation.y = -0.4 + index * 0.71;
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
papers.push({
mesh,
home: home.clone(),
homeRotation: mesh.rotation.y,
collected: false
});
paperMeshes.push(mesh);
});
function collectedCount() {
return papers.filter((paper) => paper.collected).length;
}
function updateCounter() {
let counter = document.getElementById("paperCounter");
if (!counter) {
counter = document.createElement("span");
counter.id = "paperCounter";
counter.className = "counter";
statusElement.prepend(counter);
}
counter.textContent = `${collectedCount()}/${papers.length}`;
}
function collectPaper(index) {
const paper = papers[index];
const target = collectionTargets[index];
paper.collected = true;
paper.mesh.position.set(
target.x,
floorHeightAt(target.x, target.y) + 0.006,
target.y
);
paper.mesh.rotation.y = paper.homeRotation + 0.25;
updateCounter();
}
function resetPieces() {
demoState = null;
demoButton.disabled = false;
papers.forEach((paper, index) => {
paper.collected = false;
paper.mesh.position.copy(paper.home);
paper.mesh.rotation.y = paper.homeRotation;
});
updateCounter();
}
// Geometry audit uses the actual lip and bowl vertex data, plus the scene graph.
function auditGeometry() {
const lipBounds = new THREE.Box3().setFromObject(frontLip);
const lipBottom = lipBounds.min.y;
const lipTop = lipBounds.max.y;
const lipHeight = lipTop - lipBottom;
const positions = bowlFloor.geometry.getAttribute("position");
const centerIndices = bowlFloor.geometry.userData.centerIndices;
const centerline = centerIndices.map((index) => positions.getY(index));
let maximumRise = 0;
for (let i = 1; i < centerline.length; i++) {
maximumRise = Math.max(
maximumRise,
Math.abs(centerline[i] - centerline[i - 1])
);
}
let frontWallCount = 0;
dustpan.traverse((object) => {
if (
object.userData.role === "front-wall" &&
object.visible
) {
frontWallCount++;
}
});
const flush = Math.abs(lipBottom) < 0.0001;
const shallowLip = lipHeight < 0.08;
const continuousFront = Math.abs(centerline[0] - lipTop) < 0.025;
const noVerticalStep = maximumRise < 0.12;
const noFrontWall = frontWallCount === 0;
return {
pass:
flush &&
shallowLip &&
continuousFront &&
noVerticalStep &&
noFrontWall,
flush,
shallowLip,
continuousFront,
noVerticalStep,
noFrontWall,
lipHeight,
frontEdgeY: centerline[0],
lipTop,
maximumRise
};
}
function runAudit(showResult = true) {
const geometry = auditGeometry();
const allInside = papers.every((paper) =>
paper.collected &&
isInsidePan(paper.mesh.position.x, paper.mesh.position.z) &&
Math.abs(
paper.mesh.position.y -
(floorHeightAt(paper.mesh.position.x, paper.mesh.position.z) + 0.006)
) < 0.04
);
if (!showResult) return { geometry, allInside };
if (!geometry.pass) {
statusElement.className = "status bad";
statusElement.innerHTML =
`<span class="counter">${collectedCount()}/${papers.length}</span>` +
"Falha na geometria: a entrada frontal não está contínua.";
return { geometry, allInside };
}
if (allInside) {
statusElement.className = "status good";
statusElement.innerHTML =
`<span class="counter">${collectedCount()}/${papers.length}</span>` +
"PASSOU — borda frontal com 4,5 cm, sem parede transversal e 4/4 papéis dentro.";
} else {
statusElement.className = "status warn";
statusElement.innerHTML =
`<span class="counter">${collectedCount()}/${papers.length}</span>` +
"Geometria OK — arraste os papéis para dentro da cuba ou use “Demonstrar e testar”.";
}
return { geometry, allInside };
}
// A deterministic animation exercises the real interaction state:
// each scrap crosses the complete lip from outside and settles on the bowl.
let demoState = null;
function startDemo() {
resetPieces();
demoButton.disabled = true;
statusElement.className = "status warn";
statusElement.innerHTML =
`<span class="counter">0/${papers.length}</span>` +
"Testando a passagem real dos papéis pela abertura frontal…";
demoState = {
index: 0,
phase: 0,
time: 0
};
}
function easeInOut(t) {
return t < 0.5
? 4 * t * t * t
: 1 - Math.pow(-2 * t + 2, 3) / 2;
}
function easeOut(t) {
return 1 - Math.pow(1 - t, 3);
}
function updateDemo(dt) {
if (!demoState) return;
const paper = papers[demoState.index];
const target = collectionTargets[demoState.index];
const home = paper.home;
const staging = new THREE.Vector3(target.x, 0.09, FRONT_Z + 0.78);
const throughMouth = new THREE.Vector3(target.x, 0.09, target.y);
const settled = new THREE.Vector3(
target.x,
floorHeightAt(target.x, target.y) + 0.006,
target.y
);
demoState.time += dt;
if (demoState.phase === 0) {
const duration = 0.52;
const u = easeInOut(Math.min(demoState.time / duration, 1));
paper.mesh.position.lerpVectors(home, staging, u);
paper.mesh.rotation.y = paper.homeRotation + u * 0.35;
if (demoState.time >= duration) {
demoState.phase = 1;
demoState.time = 0;
}
} else if (demoState.phase === 1) {
const duration = 0.78;
const u = easeInOut(Math.min(demoState.time / duration, 1));
paper.mesh.position.lerpVectors(staging, throughMouth, u);
paper.mesh.rotation.y = paper.homeRotation + 0.35 + u * 0.42;
if (demoState.time >= duration) {
demoState.phase = 2;
demoState.time = 0;
}
} else {
const duration = 0.28;
const u = easeOut(Math.min(demoState.time / duration, 1));
paper.mesh.position.lerpVectors(throughMouth, settled, u);
if (demoState.time >= duration) {
paper.collected = true;
paper.mesh.position.copy(settled);
updateCounter();
demoState.index++;
if (demoState.index >= papers.length) {
demoState = null;
demoButton.disabled = false;
runAudit(true);
} else {
demoState.phase = 0;
demoState.time = 0;
}
}
}
}
demoButton.addEventListener("click", startDemo);
verifyButton.addEventListener("click", () => runAudit(true));
resetButton.addEventListener("click", () => {
resetPieces();
runAudit(true);
});
// Direct camera and paper controls, implemented without addons.
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const floorPlane = new THREE.Plane(new THREE.Vector3(0, 1, 0), 0);
const planeHit = new THREE.Vector3();
let dragState = null;
let orbitState = null;
function setPointer(event) {
const rect = renderer.domElement.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);
}
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
setPointer(event);
const hits = raycaster.intersectObjects(paperMeshes, false);
if (hits.length > 0) {
const index = hits[0].object.userData.paperIndex;
const paper = papers[index];
if (paper.collected) {
paper.collected = false;
updateCounter();
}
raycaster.ray.intersectPlane(floorPlane, planeHit);
dragState = {
index,
offsetX: paper.mesh.position.x - planeHit.x,
offsetZ: paper.mesh.position.z - planeHit.z,
lastX: event.clientX
};
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.style.cursor = "grabbing";
} else {
orbitState = {
x: event.clientX,
y: event.clientY
};
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.style.cursor = "grabbing";
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (dragState) {
setPointer(event);
if (raycaster.ray.intersectPlane(floorPlane, planeHit)) {
const paper = papers[dragState.index];
const x = THREE.MathUtils.clamp(
planeHit.x + dragState.offsetX,
-4.2,
4.2
);
const z = THREE.MathUtils.clamp(
planeHit.z + dragState.offsetZ,
-3.0,
3.3
);
paper.mesh.position.x = x;
paper.mesh.position.z = z;
paper.mesh.position.y = 0.09;
paper.mesh.rotation.y += (event.clientX - dragState.lastX) * 0.006;
dragState.lastX = event.clientX;
}
return;
}
if (orbitState) {
const dx = event.clientX - orbitState.x;
const dy = event.clientY - orbitState.y;
cameraTheta -= dx * 0.006;
cameraPhi = THREE.MathUtils.clamp(
cameraPhi - dy * 0.005,
0.48,
1.34
);
orbitState.x = event.clientX;
orbitState.y = event.clientY;
updateCamera();
return;
}
setPointer(event);
const hoveringPaper = raycaster.intersectObjects(paperMeshes, false).length > 0;
renderer.domElement.style.cursor = hoveringPaper ? "grab" : "default";
});
function endPointer(event) {
if (dragState) {
const paper = papers[dragState.index];
if (isInsidePan(paper.mesh.position.x, paper.mesh.position.z)) {
collectPaper(dragState.index);
} else {
paper.mesh.position.y = 0.014;
}
dragState = null;
}
orbitState = null;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
renderer.domElement.style.cursor = "default";
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener("wheel", (event) => {
event.preventDefault();
cameraRadius = THREE.MathUtils.clamp(
cameraRadius + event.deltaY * 0.008,
7.4,
15.5
);
updateCamera();
}, { passive: false });
resetPieces();
runAudit(false);
statusElement.className = "status good";
statusElement.innerHTML =
`<span class="counter">0/${papers.length}</span>` +
"Cena pronta — a borda frontal está rente ao piso e a passagem está livre.";
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
updateDemo(dt);
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```