Prompt specification
Build or customize the Three.js 3D scene "Context-aware posture comparison exhibit" 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: Context-aware posture comparison exhibit
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/context-aware-posture-comparison-exhibit-x0672
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing three voxel dog-posture vignettes on adjacent small platforms. Use the same dog design in each: one near a familiar toy, one resting beside a seated person, and one looking toward an unfamiliar object behind a low barrier. Make head angle, tail position, leg stance, and surrounding cues individually visible. Selecting a platform brings its pose into a closer view without changing the other scenes. Captions should describe observable posture and context, not declare a hidden emotion from a single pose. Build fur markings, toys, and furniture from clear cubic forms, with neutral daylight and an uncluttered arrangement.
Verify the behavior against the actual geometry and data in each relevant state. Use schematic labels for deliberately synthetic elements.
Technical checks: Frame the populated toy and barrier platforms when selected. Separate the dogs and props enough to compare their postures individually.
Return one complete HTML document. The file must run in a sandbox allowing inline scripts and the cdnjs Three.js r160 module. Construct procedural assets, use local event handlers and avoid remote assets, runtime network requests besides Three.js, pointer lock and native form submission. Keep the main requested geometry visible in the initial view.
Working Three.js Starter (context-aware-posture-comparison-exhibit-x0672):
```html
<!DOCTYPE html>
<html lang="pt-BR">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Vignettes voxel — posturas caninas</title>
<style>
:root {
color-scheme: light;
--ink: #26312d;
--muted: #65706b;
--paper: #f3f4ef;
--panel: rgba(255, 255, 255, 0.88);
--line: #cfd5ce;
--accent: #496b5d;
--warm: #a05d3f;
}
* { box-sizing: border-box; }
html, body {
margin: 0;
min-height: 100%;
background: var(--paper);
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button { font: inherit; }
#app {
min-height: 100vh;
display: grid;
grid-template-rows: auto minmax(360px, 1fr) auto;
}
header {
z-index: 5;
display: flex;
align-items: center;
justify-content: space-between;
gap: 24px;
padding: 16px 22px;
border-bottom: 1px solid var(--line);
background: rgba(248, 249, 245, 0.94);
}
.heading { min-width: 0; }
h1 {
margin: 0;
font-size: clamp(1.08rem, 2vw, 1.45rem);
font-weight: 720;
letter-spacing: -0.025em;
}
.subtitle {
margin: 4px 0 0;
color: var(--muted);
font-size: 0.83rem;
line-height: 1.35;
}
.toolbar {
display: flex;
align-items: center;
justify-content: flex-end;
gap: 10px;
flex-wrap: wrap;
}
.toolbar button,
.vignette-button {
border: 1px solid #b9c2ba;
border-radius: 8px;
background: #fff;
color: var(--ink);
cursor: pointer;
transition: border-color 160ms ease, background 160ms ease, transform 160ms ease;
}
.toolbar button {
padding: 9px 13px;
font-size: 0.84rem;
font-weight: 650;
}
.toolbar button:hover,
.vignette-button:hover {
border-color: var(--accent);
transform: translateY(-1px);
}
.toolbar button:focus-visible,
.vignette-button:focus-visible {
outline: 3px solid rgba(73, 107, 93, 0.26);
outline-offset: 2px;
}
#overview[aria-pressed="true"] {
background: #e3ebe5;
border-color: var(--accent);
}
#status {
max-width: 30ch;
color: var(--muted);
font-size: 0.78rem;
line-height: 1.3;
}
#viewport {
position: relative;
min-height: 360px;
overflow: hidden;
background: #e9ede8;
isolation: isolate;
}
#viewport canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#viewport canvas:active { cursor: grabbing; }
#labels {
position: absolute;
inset: 0;
z-index: 2;
overflow: hidden;
pointer-events: none;
}
.scene-label {
position: absolute;
left: 0;
top: 0;
transform: translate(-50%, -100%);
padding: 4px 7px;
border: 1px solid rgba(59, 70, 64, 0.32);
border-radius: 5px;
background: rgba(255, 255, 255, 0.87);
color: #34423c;
box-shadow: 0 2px 8px rgba(30, 40, 35, 0.08);
font-size: 0.66rem;
font-weight: 750;
letter-spacing: 0.045em;
line-height: 1.15;
white-space: nowrap;
will-change: transform;
}
.scene-label::after {
content: "";
position: absolute;
left: 50%;
top: 100%;
width: 1px;
height: 9px;
background: rgba(59, 70, 64, 0.42);
}
.scene-label.synthetic {
border-color: rgba(160, 93, 63, 0.62);
color: #7f412c;
background: rgba(255, 248, 242, 0.93);
}
.scene-label.index {
min-width: 24px;
padding: 4px 6px;
text-align: center;
color: #fff;
background: #46544e;
border-color: #46544e;
font-size: 0.64rem;
}
.scene-label.index::after { display: none; }
#help {
position: absolute;
left: 14px;
bottom: 12px;
z-index: 3;
padding: 6px 9px;
border: 1px solid rgba(80, 92, 85, 0.18);
border-radius: 6px;
background: rgba(249, 250, 247, 0.82);
color: #5b6761;
font-size: 0.7rem;
pointer-events: none;
}
#cards {
z-index: 5;
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 12px;
padding: 13px 16px 16px;
border-top: 1px solid var(--line);
background: rgba(248, 249, 245, 0.96);
}
.card {
min-width: 0;
padding: 12px 13px 13px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(255, 255, 255, 0.72);
transition: border-color 160ms ease, background 160ms ease;
}
.card.active {
border-color: var(--accent);
background: #f8fbf8;
box-shadow: inset 0 0 0 1px rgba(73, 107, 93, 0.12);
}
.vignette-button {
width: 100%;
padding: 7px 9px;
margin-bottom: 8px;
text-align: left;
font-size: 0.82rem;
font-weight: 720;
}
.card.active .vignette-button {
color: #fff;
background: var(--accent);
border-color: var(--accent);
}
.card p {
margin: 0;
color: #4f5b55;
font-size: 0.79rem;
line-height: 1.45;
}
.caption-tag {
display: inline-block;
margin-bottom: 5px;
color: #7a857f;
font-size: 0.62rem;
font-weight: 750;
letter-spacing: 0.09em;
text-transform: uppercase;
}
@media (max-width: 820px) {
#app {
height: auto;
grid-template-rows: auto 58vh auto;
}
header {
align-items: flex-start;
flex-direction: column;
gap: 10px;
}
.toolbar {
width: 100%;
justify-content: space-between;
}
#status { max-width: none; }
#cards {
grid-template-columns: 1fr;
}
}
@media (max-width: 520px) {
header { padding: 12px 14px; }
#cards { padding: 10px; }
.subtitle { font-size: 0.76rem; }
#help { font-size: 0.64rem; }
}
</style>
</head>
<body>
<main id="app">
<header>
<div class="heading">
<h1>Três vignettes de postura canina</h1>
<p class="subtitle">Construções voxel em blocos. As legendas relatam posição, direção e contexto observáveis.</p>
</div>
<div class="toolbar">
<div id="status" aria-live="polite">Visão geral das três plataformas</div>
<button id="overview" type="button" aria-pressed="true">Visão geral</button>
</div>
</header>
<section id="viewport" aria-label="Galeria 3D interativa">
<div id="labels" aria-hidden="true"></div>
<div id="help">Arraste: orbitar · roda: zoom · clique: aproximar · Esc: visão geral</div>
</section>
<section id="cards" aria-label="Legendas das três vignettes">
<article class="card" data-card="0">
<span class="caption-tag">Vignette 01 · contexto</span>
<button class="vignette-button" type="button" data-select="0" aria-pressed="false">Brinquedo familiar</button>
<p>As quatro patas sustentam o corpo. A cabeça está girada e abaixada para o lado do brinquedo; a cauda permanece quase horizontal. Uma pata dianteira foi deslocada para a lateral, na direção do brinquedo.</p>
</article>
<article class="card" data-card="1">
<span class="caption-tag">Vignette 02 · contexto</span>
<button class="vignette-button" type="button" data-select="1" aria-pressed="false">Descanso ao lado de uma pessoa</button>
<p>O corpo está baixo, com as patas dianteiras dobradas sob o peito. A cabeça fica erguida na direção da pessoa sentada. A cauda permanece recolhida junto ao flanco, e a pessoa ocupa o lado oposto da plataforma.</p>
</article>
<article class="card" data-card="2">
<span class="caption-tag">Vignette 03 · contexto</span>
<button class="vignette-button" type="button" data-select="2" aria-pressed="false">Objeto além de uma barreira</button>
<p>O cão está em pé, com uma pata dianteira afastada para o lado da barreira. A cabeça gira para trás e para a direita; a cauda sobe em dois segmentos. Um objeto sintético fica além da barreira baixa.</p>
</article>
</section>
</main>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const viewport = document.querySelector("#viewport");
const labelsContainer = document.querySelector("#labels");
const status = document.querySelector("#status");
const overviewButton = document.querySelector("#overview");
const cards = [...document.querySelectorAll(".card")];
const selectButtons = [...document.querySelectorAll("[data-select]")];
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe9ede8);
scene.fog = new THREE.Fog(0xe9ede8, 29, 68);
const camera = new THREE.PerspectiveCamera(40, 1, 0.1, 100);
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute("aria-label", "Cena tridimensional com três的平台 de demonstração canina");
viewport.prepend(renderer.domElement);
const hemi = new THREE.HemisphereLight(0xf5fbff, 0x8b877b, 2.15);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff8e9, 3.0);
sun.position.set(-9, 17, 13);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -17;
sun.shadow.camera.right = 17;
sun.shadow.camera.top = 15;
sun.shadow.camera.bottom = -13;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 48;
sun.shadow.bias = -0.00025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xdde9f2, 0.7);
fill.position.set(12, 8, -10);
scene.add(fill);
const material = (color, roughness = 0.83, metalness = 0) =>
new THREE.MeshStandardMaterial({ color, roughness, metalness });
const M = {
ground: material(0xdde2dc, 0.96),
platformEdge: material(0x707b74, 0.92),
platformTop: material(0xf0eee5, 0.9),
platformSage: material(0x819b8a, 0.86),
platformBlue: material(0x8798a4, 0.86),
platformClay: material(0xa9826c, 0.86),
fur: material(0xb97842, 0.91),
furLight: material(0xd8b180, 0.91),
furDark: material(0x403a35, 0.9),
cream: material(0xe9dfc8, 0.92),
eye: material(0x171b1a, 0.64),
nose: material(0x2b2927, 0.7),
toy: material(0xd7b655, 0.88),
toyRed: material(0xb96350, 0.87),
stool: material(0x9b7650, 0.9),
shirt: material(0x647d8a, 0.88),
pants: material(0x4a555b, 0.9),
skin: material(0xc9916b, 0.88),
hair: material(0x463b34, 0.92),
barrier: material(0x8f7657, 0.9),
robot: material(0x548c88, 0.72),
robotLight: material(0x8bb8ad, 0.7),
robotEye: material(0x142521, 0.62)
};
function box(parent, size, position, mat, shadow = true) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(...size), mat);
mesh.position.set(...position);
mesh.castShadow = shadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function group(parent, position = [0, 0, 0], rotationY = 0) {
const g = new THREE.Group();
g.position.set(...position);
g.rotation.y = rotationY;
parent.add(g);
return g;
}
const labelEntries = [];
function addSceneLabel(text, parent, position, variant = "") {
const anchor = new THREE.Object3D();
anchor.position.set(...position);
parent.add(anchor);
const element = document.createElement("div");
element.className = `scene-label ${variant}`.trim();
element.textContent = text;
labelsContainer.appendChild(element);
labelEntries.push({ anchor, element });
return anchor;
}
const floor = new THREE.Mesh(new THREE.PlaneGeometry(90, 70), M.ground);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.025;
floor.receiveShadow = true;
scene.add(floor);
function makePlatform(index, centerX, accentMaterial) {
const platform = group(scene, [centerX, 0, 0]);
platform.userData.vignetteIndex = index;
box(platform, [5.25, 0.34, 4.4], [0, 0.17, 0], M.platformEdge);
box(platform, [5.08, 0.06, 4.23], [0, 0.37, 0], M.platformTop);
box(platform, [4.72, 0.055, 0.075], [0, 0.39, 2.105], accentMaterial, false);
const indexAnchor = addSceneLabel(
String(index + 1).padStart(2, "0"),
platform,
[0, 0.56, 2.24],
"index"
);
return { platform, indexAnchor };
}
function makeDog(parent, options) {
const {
position = [0, 0, 0],
rotationY = 0,
pose = "stand",
headYaw = 0,
headPitch = 0,
tail = "level",
frontPawSide = 0
} = options;
const dog = group(parent, position, rotationY);
const resting = pose === "rest";
const bodyW = resting ? 1.18 : 1.16;
const bodyH = resting ? 0.66 : 0.78;
const bodyD = resting ? 1.58 : 1.56;
const bodyY = resting ? 0.60 : 1.03;
box(dog, [bodyW, bodyH, bodyD], [0, bodyY, 0], M.fur);
box(dog, [0.72, bodyH * 0.66, 0.14], [0, bodyY - 0.02, bodyD / 2 + 0.065], M.cream);
box(dog, [0.045, 0.43, 0.59], [bodyW / 2 + 0.018, bodyY + 0.07, -0.15], M.furDark);
box(dog, [0.53, 0.045, 0.64], [0.08, bodyY + bodyH / 2 + 0.018, -0.14], M.furDark);
box(dog, [0.30, 0.045, 0.31], [-0.34, bodyY + bodyH / 2 + 0.022, 0.40], M.cream);
const headPivot = group(dog, [0, resting ? 1.10 : 1.65, resting ? 0.68 : 0.73]);
headPivot.rotation.order = "YXZ";
headPivot.rotation.y = headYaw;
headPivot.rotation.x = headPitch;
box(headPivot, [0.52, 0.52, 0.32], [0, -0.04, -0.10], M.fur);
box(headPivot, [0.82, 0.76, 0.80], [0, 0, 0.18], M.fur);
box(headPivot, [0.56, 0.34, 0.45], [0, -0.13, 0.70], M.furLight);
box(headPivot, [0.34, 0.21, 0.11], [0, -0.08, 0.975], M.cream);
box(headPivot, [0.25, 0.16, 0.12], [0, -0.07, 1.045], M.nose);
box(headPivot, [0.105, 0.11, 0.065], [-0.22, 0.12, 0.60], M.eye, false);
box(headPivot, [0.105, 0.11, 0.065], [0.22, 0.12, 0.60], M.eye, false);
box(headPivot, [0.27, 0.28, 0.065], [-0.22, 0.15, 0.625], M.furDark, false);
const leftEar = box(headPivot, [0.25, 0.54, 0.31], [-0.47, 0.31, 0.08], M.furDark);
leftEar.rotation.z = -0.13;
const rightEar = box(headPivot, [0.25, 0.54, 0.31], [0.47, 0.31, 0.08], M.furDark);
rightEar.rotation.z = 0.13;
if (!resting) {
const frontZ = 0.55;
const rearZ = -0.57;
box(dog, [0.25, 0.72, 0.25], [-0.43, 0.47, frontZ], M.fur);
box(dog, [0.25, 0.72, 0.25], [0.43, 0.47, frontZ], M.fur);
box(dog, [0.27, 0.73, 0.27], [-0.43, 0.47, rearZ], M.fur);
box(dog, [0.27, 0.73, 0.27], [0.43, 0.47, rearZ], M.fur);
const leftFrontX = frontPawSide < 0 ? -0.58 : -0.43;
const rightFrontX = frontPawSide > 0 ? 0.58 : 0.43;
box(dog, [0.25, 0.72, 0.25], [leftFrontX, 0.47, frontZ + 0.10], M.fur);
box(dog, [0.25, 0.72, 0.25], [rightFrontX, 0.47, frontZ + 0.08], M.fur);
box(dog, [0.34, 0.18, 0.40], [leftFrontX, 0.11, frontZ + 0.14], M.cream);
box(dog, [0.34, 0.18, 0.40], [rightFrontX, 0.11, frontZ + 0.12], M.cream);
box(dog, [0.36, 0.18, 0.43], [-0.43, 0.11, rearZ - 0.08], M.cream);
box(dog, [0.36, 0.18, 0.43], [0.43, 0.11, rearZ - 0.08], M.cream);
} else {
box(dog, [0.34, 0.36, 0.72], [-0.48, 0.34, -0.18], M.fur);
box(dog, [0.34, 0.36, 0.72], [0.48, 0.34, -0.18], M.fur);
box(dog, [0.32, 0.18, 0.46], [-0.36, 0.12, 0.58], M.cream);
box(dog, [0.32, 0.18, 0.46], [0.36, 0.12, 0.58], M.cream);
box(dog, [0.31, 0.18, 0.39], [-0.52, 0.12, 0.18], M.cream);
box(dog, [0.31, 0.18, 0.39], [0.52, 0.12, 0.18], M.cream);
}
const tailGroup = group(dog, [0, bodyY + 0.22, -bodyD / 2 - 0.025]);
if (tail === "tucked") {
box(tailGroup, [0.26, 0.25, 0.36], [0, 0, -0.15], M.furDark);
box(tailGroup, [0.24, 0.24, 0.38], [0.27, -0.03, -0.19], M.furDark);
box(tailGroup, [0.22, 0.22, 0.30], [0.47, -0.07, 0.02], M.furDark);
} else {
box(tailGroup, [0.27, 0.27, 0.39], [0, 0, -0.18], M.furDark);
if (tail === "raised") {
const middle = box(tailGroup, [0.25, 0.25, 0.40], [0, 0.10, -0.51], M.furDark);
middle.rotation.x = -0.25;
const tip = box(tailGroup, [0.23, 0.23, 0.34], [0, 0.29, -0.80], M.furDark);
tip.rotation.x = -0.36;
} else {
box(tailGroup, [0.25, 0.25, 0.40], [0, 0, -0.53], M.furDark);
box(tailGroup, [0.23, 0.23, 0.31], [0, 0, -0.84], M.furDark);
}
}
return dog;
}
function makeToy(parent, position) {
const toy = group(parent, position, 0.12);
box(toy, [0.78, 0.18, 0.23], [0, 0.12, 0], M.toy);
box(toy, [0.27, 0.27, 0.30], [-0.45, 0.14, 0], M.toy);
box(toy, [0.27, 0.27, 0.30], [0.45, 0.14, 0], M.toy);
box(toy, [0.16, 0.31, 0.34], [-0.45, 0.14, 0], M.toy);
box(toy, [0.16, 0.31, 0.34], [0.45, 0.14, 0], M.toy);
box(toy, [0.20, 0.075, 0.255], [0, 0.235, 0], M.toyRed, false);
return toy;
}
function makeSeatedPerson(parent, position) {
const person = group(parent, position, -Math.PI / 2);
box(person, [0.84, 0.28, 0.60], [0, 0.62, -0.02], M.pants);
box(person, [0.78, 0.88, 0.44], [0, 1.16, -0.08], M.shirt);
box(person, [0.55, 0.56, 0.55], [0, 1.87, -0.05], M.skin);
box(person, [0.59, 0.16, 0.59], [0, 2.14, -0.06], M.hair);
box(person, [0.61, 0.24, 0.18], [0, 2.00, 0.22], M.hair);
box(person, [0.29, 0.27, 0.76], [-0.26, 0.54, 0.36], M.pants);
box(person, [0.29, 0.27, 0.76], [0.26, 0.54, 0.36], M.pants);
box(person, [0.26, 0.43, 0.27], [-0.26, 0.25, 0.65], M.pants);
box(person, [0.26, 0.43, 0.27], [0.26, 0.25, 0.65], M.pants);
box(person, [0.33, 0.15, 0.45], [-0.26, 0.08, 0.78], M.hair);
box(person, [0.33, 0.15, 0.45], [0.26, 0.08, 0.78], M.hair);
box(person, [0.24, 0.70, 0.24], [-0.51, 1.17, 0.01], M.shirt);
box(person, [0.24, 0.70, 0.24], [0.51, 1.17, 0.01], M.shirt);
box(person, [0.22, 0.22, 0.55], [-0.51, 0.83, 0.23], M.skin);
box(person, [0.22, 0.22, 0.55], [0.51, 0.83, 0.23], M.skin);
return person;
}
function makeBarrier(parent, position) {
const barrier = group(parent, position);
box(barrier, [0.20, 0.74, 0.20], [-0.82, 0.37, 0], M.barrier);
box(barrier, [0.20, 0.74, 0.20], [0.82, 0.37, 0], M.barrier);
box(barrier, [1.86, 0.17, 0.18], [0, 0.55, 0], M.barrier);
box(barrier, [1.86, 0.13, 0.18], [0, 0.29, 0], M.barrier);
return barrier;
}
function makeRobot(parent, position) {
const robot = group(parent, position);
box(robot, [0.70, 0.78, 0.55], [0, 0.71, 0], M.robot);
box(robot, [0.62, 0.48, 0.54], [0, 1.33, 0], M.robotLight);
box(robot, [0.12, 0.12, 0.06], [-0.16, 1.37, 0.29], M.robotEye, false);
box(robot, [0.12, 0.12, 0.06], [0.16, 1.37, 0.29], M.robotEye, false);
box(robot, [0.07, 0.24, 0.07], [0, 1.69, 0], M.robot);
box(robot, [0.14, 0.14, 0.14], [0, 1.86, 0], M.toyRed);
box(robot, [0.20, 0.45, 0.20], [-0.48, 0.72, 0], M.robot);
box(robot, [0.20, 0.45, 0.20], [0.48, 0.72, 0], M.robot);
box(robot, [0.23, 0.18, 0.43], [-0.48, 0.23, 0], M.robotLight);
box(robot, [0.23, 0.18, 0.43], [0.48, 0.23, 0], M.robotLight);
return robot;
}
const platformXs = [-7.4, 0, 7.4];
const clickTargets = [];
const toyScene = makePlatform(0, platformXs[0], M.platformSage);
clickTargets.push(toyScene.platform);
const toyDog = makeDog(toyScene.platform, {
position: [0.35, 0.405, 0],
rotationY: -0.35,
pose: "stand",
headYaw: -1.48,
headPitch: 0.16,
tail: "level",
frontPawSide: -1
});
const toy = makeToy(toyScene.platform, [-1.40, 0.405, 0.62]);
addSceneLabel("BRINQUEDO", toy, [0, 0.62, 0]);
const restScene = makePlatform(1, platformXs[1], M.platformBlue);
clickTargets.push(restScene.platform);
const restingDog = makeDog(restScene.platform, {
position: [-0.86, 0.405, 0.02],
rotationY: Math.PI / 2,
pose: "rest",
headYaw: 0,
headPitch: -0.035,
tail: "tucked"
});
const person = makeSeatedPerson(restScene.platform, [1.28, 0.405, -0.05]);
box(restScene.platform, [1.08, 0.16, 0.82], [1.28, 0.49, -0.25], M.stool);
box(restScene.platform, [0.18, 0.45, 0.18], [1.28, 0.23, -0.25], M.stool);
addSceneLabel("PESSOA SENTADA", person, [0, 2.48, -0.05]);
const barrierScene = makePlatform(2, platformXs[2], M.platformClay);
clickTargets.push(barrierScene.platform);
const barrierDog = makeDog(barrierScene.platform, {
position: [-0.78, 0.405, -0.08],
rotationY: 0.10,
pose: "stand",
headYaw: 2.08,
headPitch: -0.03,
tail: "raised",
frontPawSide: 1
});
const barrier = makeBarrier(barrierScene.platform, [0.46, 0.405, 1.03]);
addSceneLabel("BARREIRA BAIXA", barrier, [0, 0.95, 0]);
const robot = makeRobot(barrierScene.platform, [1.33, 0.405, -0.67]);
addSceneLabel("OBJETO SINTÉTICO NÃO FAMILIAR", robot, [0, 2.18, 0], "synthetic");
const overviewTarget = new THREE.Vector3(0, 1.0, 0);
const focusTargets = [
new THREE.Vector3(platformXs[0] + 0.35, 1.28, 0.12),
new THREE.Vector3(platformXs[1] - 0.86, 1.03, 0.02),
new THREE.Vector3(platformXs[2] - 0.78, 1.18, -0.08)
];
let selectedIndex = null;
let overviewDistance = 19;
let focusDistance = 8.8;
const desired = {
target: overviewTarget.clone(),
distance: overviewDistance,
yaw: 0,
pitch: 0.34
};
const current = {
target: overviewTarget.clone(),
distance: overviewDistance,
yaw: 0,
pitch: 0.34
};
function getOverviewDistance() {
const halfFov = THREE.MathUtils.degToRad(camera.fov * 0.5);
const widthFit = 21.3 / (2 * Math.tan(halfFov) * camera.aspect);
return Math.max(17.8, widthFit);
}
function getFocusDistance() {
const halfFov = THREE.MathUtils.degToRad(camera.fov * 0.5);
const widthFit = 6.3 / (2 * Math.tan(halfFov) * camera.aspect);
return Math.max(8.8, widthFit);
}
function setCardState(index) {
cards.forEach((card, i) => card.classList.toggle("active", i === index));
selectButtons.forEach((button, i) => {
button.setAttribute("aria-pressed", String(i === index));
});
overviewButton.setAttribute("aria-pressed", String(index === null));
}
function selectVignette(index) {
selectedIndex = index;
desired.target.copy(focusTargets[index]);
desired.distance = getFocusDistance();
desired.yaw = 0;
desired.pitch = 0.28;
const titles = [
"Vignette 01 aproximada — brinquedo à frente e à esquerda",
"Vignette 02 aproximada — cão deitado ao lado da pessoa",
"Vignette 03 aproximada — cabeça virada para o objeto além da barreira"
];
status.textContent = titles[index];
setCardState(index);
}
function showOverview() {
selectedIndex = null;
desired.target.copy(overviewTarget);
desired.distance = getOverviewDistance();
desired.yaw = 0;
desired.pitch = 0.34;
status.textContent = "Visão geral das três plataformas";
setCardState(null);
}
selectButtons.forEach((button) => {
button.addEventListener("click", () => selectVignette(Number(button.dataset.select)));
});
overviewButton.addEventListener("click", showOverview);
window.addEventListener("keydown", (event) => {
if (event.key === "Escape") showOverview();
if (event.key === "1") selectVignette(0);
if (event.key === "2") selectVignette(1);
if (event.key === "3") selectVignette(2);
if (event.key === "0") showOverview();
});
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
function setPointerFromEvent(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;
}
function findVignette(object) {
let node = object;
while (node) {
if (Number.isInteger(node.userData.vignetteIndex)) return node.userData.vignetteIndex;
node = node.parent;
}
return null;
}
function hitVignette(event) {
setPointerFromEvent(event);
raycaster.setFromCamera(pointer, camera);
const intersections = raycaster.intersectObjects(clickTargets, true);
for (const hit of intersections) {
const index = findVignette(hit.object);
if (index !== null) return index;
}
return null;
}
let pointerDown = null;
renderer.domElement.addEventListener("pointerdown", (event) => {
pointerDown = {
x: event.clientX,
y: event.clientY,
pointerId: event.pointerId,
moved: false
};
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (pointerDown && pointerDown.pointerId === event.pointerId) {
const dx = event.clientX - pointerDown.x;
const dy = event.clientY - pointerDown.y;
if (Math.hypot(dx, dy) > 5) pointerDown.moved = true;
if (pointerDown.moved) {
desired.yaw -= dx * 0.006;
desired.pitch = THREE.MathUtils.clamp(desired.pitch + dy * 0.004, 0.10, 0.88);
pointerDown.x = event.clientX;
pointerDown.y = event.clientY;
renderer.domElement.style.cursor = "grabbing";
}
} else {
renderer.domElement.style.cursor = hitVignette(event) !== null ? "pointer" : "grab";
}
});
renderer.domElement.addEventListener("pointerup", (event) => {
if (pointerDown && pointerDown.pointerId === event.pointerId) {
if (!pointerDown.moved) {
const index = hitVignette(event);
if (index !== null) selectVignette(index);
}
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
pointerDown = null;
renderer.domElement.style.cursor = "grab";
});
renderer.domElement.addEventListener("pointercancel", () => {
pointerDown = null;
renderer.domElement.style.cursor = "grab";
});
renderer.domElement.addEventListener("wheel", (event) => {
event.preventDefault();
const minimum = selectedIndex === null ? 13.5 : 6.4;
const maximum = selectedIndex === null ? 36 : 16;
desired.distance = THREE.MathUtils.clamp(
desired.distance * Math.exp(event.deltaY * 0.001),
minimum,
maximum
);
}, { passive: false });
function resize() {
const width = Math.max(1, viewport.clientWidth);
const height = Math.max(1, viewport.clientHeight);
camera.aspect = width / height;
camera.fov = camera.aspect < 0.9 ? 50 : 40;
camera.updateProjectionMatrix();
renderer.setSize(width, height, false);
if (selectedIndex === null) {
desired.distance = getOverviewDistance();
if (current.distance > 30) current.distance = desired.distance;
} else {
desired.distance = getFocusDistance();
}
}
const resizeObserver = new ResizeObserver(resize);
resizeObserver.observe(viewport);
resize();
current.distance = desired.distance;
current.target.copy(desired.target);
const projected = new THREE.Vector3();
const clock = new THREE.Clock();
function animate() {
const dt = Math.min(clock.getDelta(), 0.05);
const smoothing = 1 - Math.exp(-dt * 6.5);
current.target.lerp(desired.target, smoothing);
current.distance = THREE.MathUtils.lerp(current.distance, desired.distance, smoothing);
current.yaw = THREE.MathUtils.lerp(current.yaw, desired.yaw, smoothing);
current.pitch = THREE.MathUtils.lerp(current.pitch, desired.pitch, smoothing);
const horizontalDistance = Math.cos(current.pitch) * current.distance;
camera.position.set(
current.target.x + Math.sin(current.yaw) * horizontalDistance,
current.target.y + Math.sin(current.pitch) * current.distance,
current.target.z + Math.cos(current.yaw) * horizontalDistance
);
camera.lookAt(current.target);
for (const entry of labelEntries) {
entry.anchor.getWorldPosition(projected);
projected.project(camera);
const visible = projected.z > -1 && projected.z < 1;
entry.element.style.display = visible ? "block" : "none";
if (visible) {
const x = (projected.x * 0.5 + 0.5) * viewport.clientWidth;
const y = (-projected.y * 0.5 + 0.5) * viewport.clientHeight;
entry.element.style.transform = `translate(${x}px, ${y}px) translate(-50%, -100%)`;
}
}
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>
```