Prompt specification
Build or customize the Three.js 3D scene "Green Roof Layer Sample" 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: Green Roof Layer Sample
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/green-roof-layer-sample-x3937
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows green-roof layers. Model a schematic roof sample with vegetation, growing medium, drainage, and waterproofing layers. Keep functions distinct and avoid claiming the stack is a complete construction specification. Low-poly.
Verify the behavior against the actual geometry and data in each relevant state. Use schematic labels for deliberately synthetic elements.
Technical checks: Initialize the camera before reading its position. Render the full green-roof cross-section in the initial view and make its layers distinguishable.
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 (green-roof-layer-sample-x3937):
```html
<!DOCTYPE html>
<html lang="pt-BR">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="#e9e5da">
<title>Cobertura verde — corte esquemático low-poly</title>
<style>
:root {
--ink: #17332d;
--muted: #61706a;
--paper: rgba(250, 248, 241, 0.91);
--line: rgba(23, 51, 45, 0.14);
--green: #477b43;
--soil: #9a6845;
--drain: #357c91;
--waterproof: #405b91;
--accent: #ef9f3d;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
color: var(--ink);
background: #e9e5da;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input { font: inherit; }
#app, #stage {
position: absolute;
inset: 0;
}
#stage canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
}
.glass {
background: var(--paper);
border: 1px solid rgba(255, 255, 255, 0.72);
box-shadow: 0 14px 38px rgba(35, 53, 46, 0.12);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
.hero {
position: absolute;
z-index: 8;
top: 24px;
left: 24px;
width: min(420px, calc(100vw - 48px));
padding: 18px 20px 16px;
border-radius: 18px;
pointer-events: none;
}
.eyebrow {
margin: 0 0 6px;
color: #6f7c76;
font-size: 0.68rem;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(1.45rem, 2.5vw, 2.15rem);
line-height: 1.05;
letter-spacing: -0.045em;
}
.hero p {
margin: 10px 0 0;
color: var(--muted);
font-size: 0.84rem;
line-height: 1.45;
}
.disclaimer {
margin-top: 12px;
padding-top: 11px;
border-top: 1px solid var(--line);
color: #40534c;
font-size: 0.72rem;
line-height: 1.42;
}
.disclaimer strong { color: var(--ink); }
.toolbar {
position: absolute;
z-index: 9;
top: 24px;
right: 24px;
width: 310px;
padding: 14px;
border-radius: 18px;
display: grid;
gap: 11px;
}
.toolbar-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
}
.toolbar-title {
font-size: 0.72rem;
font-weight: 850;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.button {
border: 1px solid var(--line);
border-radius: 10px;
padding: 8px 11px;
color: var(--ink);
background: rgba(255, 255, 255, 0.74);
cursor: pointer;
font-size: 0.76rem;
font-weight: 750;
transition: transform 150ms ease, background 150ms ease;
}
.button:hover {
transform: translateY(-1px);
background: #fff;
}
.button:active { transform: translateY(0); }
.toggle {
display: flex;
align-items: center;
gap: 9px;
color: #42574f;
cursor: pointer;
font-size: 0.78rem;
user-select: none;
}
.toggle input {
width: 17px;
height: 17px;
margin: 0;
accent-color: var(--green);
}
.range-wrap {
padding: 10px 11px 8px;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(255, 255, 255, 0.48);
}
.range-label {
display: flex;
justify-content: space-between;
margin-bottom: 7px;
color: #43564f;
font-size: 0.75rem;
font-weight: 750;
}
#rain {
width: 100%;
margin: 0;
accent-color: var(--drain);
cursor: pointer;
}
.toolbar-status {
display: flex;
justify-content: space-between;
gap: 10px;
color: #6a7872;
font-size: 0.67rem;
}
.toolbar-status strong {
color: var(--ink);
font-weight: 800;
}
.inspector {
position: absolute;
z-index: 8;
right: 24px;
bottom: 24px;
width: 326px;
padding: 17px 18px 16px;
border-radius: 18px;
}
.inspector-header {
display: flex;
justify-content: space-between;
align-items: flex-start;
gap: 12px;
}
.inspector h2 {
margin: 2px 0 0;
font-size: 1.18rem;
letter-spacing: -0.025em;
}
.tag {
flex: 0 0 auto;
padding: 5px 7px;
border-radius: 999px;
color: #65502e;
background: #f7e4bd;
font-size: 0.61rem;
font-weight: 850;
letter-spacing: 0.06em;
text-transform: uppercase;
}
#selectedDescription {
margin: 12px 0;
color: #53655e;
font-size: 0.79rem;
line-height: 1.48;
}
#selectedFacts {
display: grid;
gap: 6px;
padding-top: 10px;
border-top: 1px solid var(--line);
}
.fact {
display: flex;
align-items: center;
justify-content: space-between;
gap: 14px;
color: #68756f;
font-size: 0.7rem;
}
.fact strong {
color: var(--ink);
text-align: right;
font-weight: 800;
}
.inspector-note {
margin-top: 12px;
color: #7a817d;
font-size: 0.66rem;
line-height: 1.42;
}
.legend {
position: absolute;
z-index: 7;
left: 24px;
bottom: 24px;
width: 285px;
padding: 15px 17px;
border-radius: 18px;
pointer-events: none;
}
.legend h3 {
margin: 0 0 10px;
font-size: 0.68rem;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.legend-row {
display: grid;
grid-template-columns: 10px 1fr auto;
align-items: center;
gap: 8px;
padding: 5px 0;
border-top: 1px solid rgba(23, 51, 45, 0.08);
color: #52635c;
font-size: 0.69rem;
}
.legend-row:first-of-type { border-top: 0; }
.swatch {
width: 9px;
height: 9px;
border-radius: 3px;
box-shadow: inset 0 0 0 1px rgba(0,0,0,.08);
}
.legend-row b {
color: #29483e;
font-weight: 800;
}
.legend-note {
margin-top: 9px;
color: #77817c;
font-size: 0.65rem;
line-height: 1.4;
}
.hint {
position: absolute;
z-index: 7;
left: 50%;
bottom: 22px;
transform: translateX(-50%);
padding: 8px 12px;
border: 1px solid rgba(255,255,255,.65);
border-radius: 999px;
color: #52665d;
background: rgba(250,248,241,.76);
box-shadow: 0 8px 20px rgba(35,53,46,.09);
backdrop-filter: blur(10px);
font-size: 0.68rem;
white-space: nowrap;
pointer-events: none;
}
#scene-labels {
position: absolute;
inset: 0;
z-index: 5;
pointer-events: none;
}
.scene-label {
position: absolute;
display: flex;
align-items: center;
gap: 8px;
width: max-content;
max-width: 210px;
padding: 7px 10px;
border: 1px solid rgba(255,255,255,.78);
border-radius: 10px;
color: var(--ink);
background: rgba(250,248,241,.88);
box-shadow: 0 8px 20px rgba(35,53,46,.10);
backdrop-filter: blur(8px);
cursor: pointer;
pointer-events: auto;
transform: translate(14px, -50%);
text-align: left;
transition: border-color 150ms ease, box-shadow 150ms ease, opacity 150ms ease;
}
.scene-label::before {
content: "";
position: absolute;
left: -14px;
top: 50%;
width: 14px;
height: 1px;
background: rgba(23,51,45,.44);
}
.scene-label.flip {
transform: translate(calc(-100% - 14px), -50%);
}
.scene-label.flip::before {
left: auto;
right: -14px;
}
.scene-label.selected {
border-color: rgba(239,159,61,.9);
box-shadow: 0 8px 22px rgba(35,53,46,.12), 0 0 0 2px rgba(239,159,61,.22);
}
.scene-label .dot {
flex: 0 0 auto;
width: 9px;
height: 9px;
border-radius: 3px;
box-shadow: inset 0 0 0 1px rgba(0,0,0,.08);
}
.scene-label strong {
display: block;
font-size: 0.69rem;
line-height: 1.15;
}
.scene-label small {
display: block;
margin-top: 2px;
color: #758079;
font-size: 0.58rem;
line-height: 1.1;
}
#scene-labels.hidden { opacity: 0; pointer-events: none; }
.loading {
position: absolute;
z-index: 20;
inset: 0;
display: grid;
place-items: center;
color: #50635b;
background: #e9e5da;
font-size: 0.8rem;
letter-spacing: 0.08em;
text-transform: uppercase;
transition: opacity 300ms ease;
}
.loading.ready { opacity: 0; pointer-events: none; }
@media (max-width: 900px) {
.hero {
top: 12px;
left: 12px;
width: min(365px, calc(100vw - 24px));
padding: 14px 16px;
}
.hero p { display: none; }
.disclaimer { margin-top: 8px; padding-top: 8px; }
.toolbar {
top: auto;
right: 12px;
bottom: 12px;
width: min(320px, calc(100vw - 24px));
padding: 11px;
}
.inspector {
right: 12px;
bottom: 192px;
width: min(300px, calc(100vw - 24px));
}
.legend, .hint { display: none; }
}
@media (max-width: 560px) {
.hero { max-width: calc(100vw - 24px); }
.hero h1 { font-size: 1.35rem; }
.disclaimer { font-size: 0.65rem; }
.inspector { display: none; }
.toolbar { width: calc(100vw - 24px); }
.scene-label { max-width: 165px; padding: 6px 8px; }
.scene-label small { display: none; }
}
</style>
</head>
<body>
<div id="app">
<div id="stage" aria-label="Visualização tridimensional esquemática de uma cobertura verde">
<div id="scene-labels"></div>
<div id="loading" class="loading">Preparando modelo esquemático…</div>
</div>
<header class="hero glass">
<p class="eyebrow">Amostra conceitual · low-poly</p>
<h1>Cobertura verde em corte</h1>
<p>Quatro camadas exploráveis: vegetação, meio de crescimento, drenagem e impermeabilização.</p>
<div class="disclaimer">
<strong>Diagrama sintético, não é especificação.</strong>
Geometria, materiais, espessuras, juntas e fluxo são ilustrativos; a sequência visual não é normativa.
</div>
</header>
<section class="toolbar glass" aria-label="Controles do modelo">
<div class="toolbar-row">
<span class="toolbar-title">Controles</span>
<button id="resetCamera" class="button" type="button">Redefinir vista</button>
</div>
<label class="toggle">
<input id="explodeToggle" type="checkbox" checked>
<span>Separar camadas</span>
</label>
<label class="toggle">
<input id="labelsToggle" type="checkbox" checked>
<span>Mostrar rótulos</span>
</label>
<div class="range-wrap">
<div class="range-label">
<span>Fluxo sintético</span>
<span id="rainValue">45%</span>
</div>
<input id="rain" type="range" min="0" max="100" value="45" aria-label="Intensidade do fluxo sintético">
</div>
<div class="toolbar-status">
<span id="stackState"><strong>Separadas</strong> · visualização</span>
<span id="dropCount">14 gotas</span>
</div>
</section>
<section class="inspector glass" aria-live="polite">
<div class="inspector-header">
<div>
<div id="selectedIndex" class="eyebrow">01 / 04</div>
<h2 id="selectedName">Vegetação</h2>
</div>
<span id="selectedTag" class="tag">Sintética</span>
</div>
<p id="selectedDescription"></p>
<div id="selectedFacts"></div>
<div class="inspector-note">
Selecione uma camada no modelo ou em um rótulo. Os números abaixo descrevem a geometria realmente presente nesta cena.
</div>
</section>
<aside class="legend glass" aria-label="Legenda do modelo">
<h3>Geometria presente</h3>
<div class="legend-row">
<span class="swatch" style="background:#477b43"></span>
<span>Vegetação procedural</span>
<b>32 tufos</b>
</div>
<div class="legend-row">
<span class="swatch" style="background:#9a6845"></span>
<span>Meio de crescimento</span>
<b>24 nódulos</b>
</div>
<div class="legend-row">
<span class="swatch" style="background:#357c91"></span>
<span>Drenagem sintética</span>
<b>18 furos</b>
</div>
<div class="legend-row">
<span class="swatch" style="background:#405b91"></span>
<span>Impermeabilização</span>
<b>3 juntas</b>
</div>
<div class="legend-note">
Sem escala métrica. O apoio cinza é apenas uma base visual e não representa uma camada especificada.
</div>
</aside>
<div class="hint">Arraste para orbitar · roda para zoom · clique para inspecionar</div>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const stage = document.getElementById("stage");
const loading = document.getElementById("loading");
const labelsHost = document.getElementById("scene-labels");
const layerOrder = ["vegetation", "growing", "drainage", "waterproof"];
const layerGroups = {};
const layerStats = {};
const interactiveMeshes = [];
const swayLeaves = [];
const state = {
exploded: true,
explodeAmount: 1,
targetExplodeAmount: 1,
labelsVisible: true,
rainfall: 0.45,
selected: "vegetation"
};
const layerData = {
vegetation: {
number: "01",
name: "Vegetação",
color: "#477b43",
subtitle: "procedural e ilustrativa",
tag: "Sintética",
description: "Tufos low-poly distribuídos sobre uma base vegetal fina. Representa apenas a presença de cobertura viva, não espécies, densidade ou solução de cultivo.",
facts: [
["Tufos construídos", "32"],
["Folhas geométricas", "96"],
["Base vegetal", "1 painel"]
]
},
growing: {
number: "02",
name: "Meio de crescimento",
color: "#9a6845",
subtitle: "bloco e nódulos sintéticos",
tag: "Sintético",
description: "Volume esquemático de substrato com pequenos nódulos na face superior. Cor, granulometria, profundidade e comportamento hydraulicamente não são definidos.",
facts: [
["Bloco principal", "1"],
["Nódulosdistribution", "24"],
["Espessura visual", "não métrica"]
]
},
drainage: {
number: "03",
name: "Drenagem",
color: "#357c91",
subtitle: "canais e furos sintéticos",
tag: "Sintética",
description: "Painel ilustrativo com canais, perfurações e saídas frontais. Não estabelece declividade, posição de saídas, capacidade ou relação comCollector de água.",
facts: [
["Canais superiores", "5"],
["Perfurações", "18"],
["Saídas no bordo", "6"]
]
},
waterproof: {
number: "04",
name: "Impermeabilização",
color: "#405b91",
subtitle: "membrana e juntas sintéticas",
tag: "Sintético",
description: "Painel esquemático com três juntas aparentes. Não define produto, espessura real, continuity, encontros,细节 de bordas ou desempenho impermeável.",
facts: [
["Painel principal", "1"],
["Juntas aparentes", "3"],
["Bordas线", "4 linhas"]
]
}
};
function createScene() {
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe9e5da);
scene.fog = new THREE.Fog(0xe9e5da, 25, 48);
const hemisphere = new THREE.HemisphereLight(0xfffdf4, 0x857766, 2.2);
scene.add(hemisphere);
const key = new THREE.DirectionalLight(0xfff0d4, 3.1);
key.position.set(-8, 14, 10);
key.castShadow = true;
key.shadow.mapSize.set(2048, 2048);
key.shadow.camera.left = -15;
key.shadow.camera.right = 15;
key.shadow.camera.top = 15;
key.shadow.camera.bottom = -15;
key.shadow.camera.near = 1;
key.shadow.camera.far = 40;
key.shadow.bias = -0.00035;
scene.add(key);
const fill = new THREE.DirectionalLight(0xa8c9ed, 1.15);
fill.position.set(11, 7, -9);
scene.add(fill);
const groundMaterial = new THREE.MeshStandardMaterial({
color: 0xe6e0d2,
roughness: 1,
metalness: 0
});
const ground = new THREE.Mesh(new THREE.PlaneGeometry(60, 60), groundMaterial);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.87;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(34, 17, 0x87958d, 0xa9afa8);
grid.position.y = -0.86;
const gridMaterials = Array.isArray(grid.material) ? grid.material : [grid.material];
gridMaterials.forEach(material => {
material.transparent = true;
material.opacity = 0.17;
material.depthWrite = false;
});
scene.add(grid);
return scene;
}
function createCamera(aspect) {
const camera = new THREE.PerspectiveCamera(42, aspect, 0.1, 100);
camera.position.set(12, 10, 14);
camera.lookAt(0, 1.2, 0);
return camera;
}
function createRenderer() {
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(stage.clientWidth, stage.clientHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.domElement.setAttribute("tabindex", "0");
renderer.domElement.setAttribute("aria-label", "Modelo 3D interativo de camadas de cobertura verde");
stage.appendChild(renderer.domElement);
return renderer;
}
function standardMaterial(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.86,
metalness: 0,
flatShading: true,
...options
});
}
function makeBox(width, height, depth, material, x = 0, y = 0, z = 0) {
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;
}
function seededRandom(seed) {
let value = seed >>> 0;
return function () {
value += 0x6D2B79F5;
let result = value;
result = Math.imul(result ^ (result >>> 15), result | 1);
result ^= result + Math.imul(result ^ (result >>> 7), result | 61);
return ((result ^ (result >>> 14)) >>> 0) / 4294967296;
};
}
function registerLayer(key, group) {
group.userData.layerKey = key;
group.traverse(object => {
if (object.isMesh) {
object.userData.layerKey = key;
interactiveMeshes.push(object);
}
});
layerGroups[key] = group;
scene.add(group);
}
function buildVegetationLayer() {
const group = new THREE.Group();
const random = seededRandom(19);
const turfMaterial = standardMaterial(0x416f39);
const leafMaterials = [
standardMaterial(0x4f8443),
standardMaterial(0x6a914d),
standardMaterial(0x3f713f)
];
group.add(makeBox(10.0, 0.12, 6.4, turfMaterial, 0, 0, 0));
let leafCount = 0;
for (let i = 0; i < 32; i++) {
const tuft = new THREE.Group();
const margin = 0.58;
tuft.position.set(
THREE.MathUtils.lerp(-margin, margin, random()),
0.05,
THREE.MathUtils.lerp(-margin, margin, random())
);
tuft.rotation.y = random() * Math.PI * 2;
for (let j = 0; j < 3; j++) {
const height = 0.42 + random() * 0.28;
const leaf = new THREE.Mesh(
new THREE.ConeGeometry(0.14 + random() * 0.035, height, 5),
leafMaterials[(i + j) % leafMaterials.length]
);
const angle = j * (Math.PI * 2 / 3) + random() * 0.45;
leaf.position.set(
Math.cos(angle) * 0.07,
height * 0.5,
Math.sin(angle) * 0.07
);
leaf.rotation.x = (random() - 0.5) * 0.32;
leaf.rotation.z = (random() - 0.5) * 0.42;
leaf.castShadow = true;
leaf.receiveShadow = true;
leaf.userData.baseRotationZ = leaf.rotation.z;
leaf.userData.phase = random() * Math.PI * 2;
swayLeaves.push(leaf);
leafCount++;
tuft.add(leaf);
}
const scale = 0.82 + random() * 0.34;
tuft.scale.set(scale, scale, scale);
group.add(tuft);
}
layerStats.vegetation = { tufts: 32, leaves: leafCount, panels: 1 };
registerLayer("vegetation", group);
}
function buildGrowingMediumLayer() {
const group = new THREE.Group();
const random = seededGlobalRandom(71);
const soilMaterial = standardMaterial(0x926343);
const clodMaterials = [
standardMaterial(0x6f4934),
standardMaterial(0xa87950),
standardMaterial(0x81533c)
];
group.add(makeBox(10.0, 0.72, 6.4, soilMaterial));
for (let i = 0; i < 24; i++) {
const clod = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.07 + random() * 0.025, 0),
clodMaterials[i % clodMaterials.length]
);
clod.position.set(
THREE.MathUtils.lerp(-4.55, 4.55, random()),
0.355 + random() * 0.015,
THREE.MathUtils.lerp(-2.75, 2.75, random())
);
clod.rotation.set(random() * Math.PI, random() * Math.PI, random() * Math.PI);
clod.castShadow = true;
clod.receiveShadow = true;
group.add(clod);
}
layerStats.growing = { blocks: 1, nodules: 24 };
registerLayer("growing", group);
}
function seededGlobalRandom(seed) {
return seededRandom(seed);
}
function buildDrainageLayer() {
const group = new THREE.Group();
const panelMaterial = standardMaterial(0x3e5153);
const channelMaterial = standardMaterial(0x2e8195, { roughness: 0.58 });
const holeMaterial = standardMaterial(0x10272b, { roughness: 1 });
const ringMaterial = standardMaterial(0x61a9b9, { roughness: 0.5 });
group.add(makeBox(10.0, 0.42, 6.4, panelMaterial));
for (let i = 0; i < 5; i++) {
const channel = makeBox(8.9, 0.035, 0.08, channelMaterial, 0, 0.225, -2.45 + i * 1.22);
group.add(channel);
}
for (let row = 0; row < 3; row++) {
for (let column = 0; column < 6; column++) {
const x = -4.15 + column * 1.66;
const z = -2.05 + row * 2.05;
const hole = new THREE.Mesh(
new THREE.CylinderGeometry(0.09, 0.09, 0.035, 12),
holeMaterial
);
hole.position.set(x, 0.238, z);
hole.castShadow = true;
group.add(hole);
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.115, 0.022, 5, 12),
ringMaterial
);
ring.rotation.x = Math.PI / 2;
ring.position.set(x, 0.244, z);
group.add(ring);
}
}
for (let i = 0; i < 6; i++) {
const outlet = new THREE.Mesh(
new THREE.CylinderGeometry(0.12, 0.12, 0.20, 10),
channelMaterial
);
outlet.rotation.x = Math.PI / 2;
outlet.position.set(-3.75 + i * 1.5, 0, 3.28);
outlet.castShadow = true;
group.add(outlet);
}
layerStats.drainage = { channels: 5, perforations: 18, outlets: 6 };
registerLayer("drainage", group);
}
function buildWaterproofingLayer() {
const group = new THREE.Group();
const membraneMaterial = standardMaterial(0x405b91, { roughness: 0.64 });
const seamMaterial = standardMaterial(0x243b68, { roughness: 0.75 });
group.add(makeBox(10.2, 0.18, 6.6, membraneMaterial));
for (let i = 0; i < 3; i++) {
group.add(makeBox(10.05, 0.025, 0.055, seamMaterial, 0, 0.103, -2.05 + i * 2.05));
}
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(new THREE.BoxGeometry(10.2, 0.18, 6.6)),
new THREE.LineBasicMaterial({ color: 0x22385f })
);
group.add(edges);
layerStats.waterproof = { panels: 1, seams: 3, edgeLines: 4 };
registerLayer("waterproof", group);
}
function buildVisualSupport() {
const support = makeBox(
10.8,
0.44,
7.0,
standardMaterial(0xaaa79d, { roughness: 0.94 })
);
support.position.y = -0.64;
scene.add(support);
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(new THREE.BoxGeometry(10.8, 0.44, 7.0)),
new THREE.LineBasicMaterial({ color: 0x777970 })
);
edges.position.copy(support.position);
scene.add(edges);
}
function buildSyntheticDroplets() {
const group = new THREE.Group();
const random = seededRandom(303);
const material = new THREE.MeshStandardMaterial({
color: 0x3b9fbd,
roughness: 0.25,
metalness: 0.05,
transparent: true,
opacity: 0.82,
depthWrite: false,
flatShading: true
});
const droplets = [];
for (let i = 0; i < 30; i++) {
const drop = new THREE.Mesh(new THREE.OctahedronGeometry(0.075, 0), material);
drop.userData.phase = random();
drop.userData.speed = 0.85 + random() * 0.35;
drop.userData.x = THREE.MathUtils.lerp(-4.5, 4.5, random());
drop.userData.z = THREE.MathUtils.lerp(-2.7, 2.7, random());
drop.visible = false;
droplets.push(drop);
group.add(drop);
}
scene.add(group);
return droplets;
}
const scene = createScene();
const camera = createCamera(stage.clientWidth / stage.clientHeight);
const renderer = createRenderer();
buildVegetationLayer();
buildGrowingMediumLayer();
buildDrainageLayer();
buildWaterproofingLayer();
buildVisualSupport();
const droplets = buildSyntheticDroplets();
const layout = {
vegetation: { restY: 0.99, explodeOffset: 2.15 },
growing: { restY: 0.55, explodeOffset: 1.35 },
drainage: { restY: -0.05, explodeOffset: 0.65 },
waterproof: { restY: -0.38, explodeOffset: 0.25 }
};
layerOrder.forEach(key => {
const item = layout[key];
layerGroups[key].position.y = item.restY + item.explodeOffset;
});
const selectionBox = new THREE.Box3();
const selectionHelper = new THREE.Box3Helper(selectionBox, 0xef9f3d);
selectionHelper.material.transparent = true;
selectionHelper.material.opacity = 0.92;
selectionHelper.material.depthTest = false;
selectionHelper.renderOrder = 20;
scene.add(selectionHelper);
const orbit = {
target: new THREE.Vector3(0, 1.25, 0),
theta: 0.74,
phi: 1.04,
radius: 19.5
};
function updateCamera() {
orbit.phi = THREE.MathUtils.clamp(orbit.phi, 0.36, 1.43);
orbit.radius = THREE.MathUtils.clamp(orbit.radius, 11.5, 29);
const spherical = new THREE.Spherical(orbit.radius, orbit.phi, orbit.theta);
const offset = new THREE.Vector3().setFromSpherical(spherical);
camera.position.copy(orbit.target).add(offset);
camera.lookAt(orbit.target);
camera.updateMatrixWorld();
}
const labelElements = [];
function createLabelElements() {
const anchors = {
vegetation: { x: 5.12, y: 0.48, z: -2.92 },
growing: { x: 5.10, y: 0.02, z: -2.92 },
drainage: { x: 5.10, y: 0.26, z: -2.92 },
waterproof: { x: 5.22, y: 0.08, z: -3.00 }
};
layerOrder.forEach(key => {
const data = layerData[key];
const anchor = new THREE.Object3D();
anchor.position.set(anchors[key].x, anchors[key].y, anchors[key].z);
layerGroups[key].add(anchor);
const button = document.createElement("button");
button.type = "button";
button.className = "scene-label";
button.dataset.layer = key;
button.setAttribute("aria-label", `Inspecionar ${data.name}`);
button.innerHTML = `
<span class="dot" style="background:${data.color}"></span>
<span>
<strong>${data.number} · ${data.name}</strong>
<small>${data.subtitle}</small>
</span>
`;
button.addEventListener("click", () => selectLayer(key));
labelsHost.appendChild(button);
labelElements.push({ key, anchor, button });
});
}
function renderSelection() {
const data = layerData[state.selected];
document.getElementById("selectedIndex").textContent = `${data.number} / 04`;
document.getElementById("selectedName").textContent = data.name;
document.getElementById("selectedTag").textContent = data.tag;
document.getElementById("selectedDescription").textContent = data.description;
document.getElementById("selectedFacts").innerHTML = data.facts
.map(([label, value]) => `<div class="fact"><span>${label}</span><strong>${value}</strong></div>`)
.join("");
labelElements.forEach(({ key, button }) => {
button.classList.toggle("selected", key === state.selected);
});
}
function selectLayer(key) {
if (!layerGroups[key]) return;
state.selected = key;
renderSelection();
updateSelectionBox();
}
function updateSelectionBox() {
scene.updateMatrixWorld(true);
selectionBox.setFromObject(layerGroups[state.selected]);
selectionHelper.box.copy(selectionBox);
selectionHelper.updateMatrixWorld(true);
}
function updateLayerPositions(delta) {
const damping = 1 - Math.exp(-delta * 7.5);
state.explodeAmount += (state.targetExplodeAmount - state.explodeAmount) * damping;
layerOrder.forEach(key => {
const item = layout[key];
layerGroups[key].position.y = item.restY + item.explodeOffset * state.explodeAmount;
});
}
function updateVegetation(elapsed) {
const amount = 0.018 + state.rainfall * 0.045;
swayLeaves.forEach(leaf => {
leaf.rotation.z = leaf.userData.baseRotationZ +
Math.sin(elapsed * 1.55 + leaf.userData.phase) * amount;
});
}
function updateDroplets(elapsed) {
const activeCount = Math.round(state.rainfall * droplets.length);
const top = layerGroups.vegetation.position.y - 0.08;
const bottom = layerGroups.drainage.position.y + 0.24;
droplets.forEach((drop, index) => {
drop.visible = index < activeCount;
if (!drop.visible) return;
const progress = (elapsed * drop.userData.speed * (0.23 + state.rainfall * 0.52) + drop.userData.phase) % 1;
drop.position.set(
drop.userData.x,
THREE.MathUtils.lerp(top, bottom, progress),
drop.userData.z
);
drop.rotation.x = elapsed * 2.2 + index;
drop.rotation.z = elapsed * 1.4 + index * 0.4;
const pulse = 0.82 + Math.sin(elapsed * 5 + index) * 0.13;
drop.scale.setScalar(pulse);
});
}
const projected = new THREE.Vector3();
function updateLabels() {
const width = stage.clientWidth;
const height = stage.clientHeight;
labelElements.forEach(({ anchor, button }) => {
anchor.getWorldPosition(projected);
projected.project(camera);
const visible = projected.z > -1 && projected.z < 1 &&
projected.x > -1.08 && projected.x < 1.08 &&
projected.y > -1.08 && projected.y < 1.08;
button.style.display = visible ? "flex" : "none";
if (!visible) return;
const screenX = (projected.x * 0.5 + 0.5) * width;
const screenY = (-projected.y * 0.5 + 0.5) * height;
button.style.left = `${screenX}px`;
button.style.top = `${screenY}px`;
button.classList.toggle("flip", projected.x > 0.35);
});
}
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let pointerDown = null;
let dragDistance = 0;
function pickLayer(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;
camera.updateMatrixWorld();
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(interactiveMeshes, false);
if (hits.length) {
const key = hits[0].object.userData.layerKey;
if (key) selectLayer(key);
}
}
function setupInteraction() {
const canvas = renderer.domElement;
canvas.addEventListener("pointerdown", event => {
pointerDown = { x: event.clientX, y: event.clientY };
dragDistance = 0;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", event => {
if (!pointerDown) return;
const dx = event.clientX - pointerDown.x;
const dy = event.clientY - pointerDown.y;
dragDistance = Math.max(dragDistance, Math.hypot(dx, dy));
orbit.theta -= dx * 0.006;
orbit.phi -= dy * 0.005;
pointerDown.x = event.clientX;
pointerDown.y = event.clientY;
});
canvas.addEventListener("pointerup", event => {
if (pointerDown && dragDistance < 5) pickLayer(event);
pointerDown = null;
if (canvas.hasPointerCapture(event.pointerId)) canvas.releasePointerCapture(event.pointerId);
});
canvas.addEventListener("pointercancel", () => {
pointerDown = null;
});
canvas.addEventListener("wheel", event => {
event.preventDefault();
orbit.radius *= Math.exp(event.deltaY * 0.001);
}, { passive: false });
document.getElementById("explodeToggle").addEventListener("change", event => {
state.exploded = event.target.checked;
state.targetExplodeAmount = state.exploded ? 1 : 0;
document.getElementById("stackState").innerHTML = state.exploded
? "<strong>Separadas</strong> · visualização"
: "<strong>Conectadas</strong> · visualização";
});
document.getElementById("labelsToggle").addEventListener("change", event => {
state.labelsVisible = event.target.checked;
labelsHost.classList.toggle("hidden", !state.labelsVisible);
});
document.getElementById("rain").addEventListener("input", event => {
state.rainfall = Number(event.target.value) / 100;
const count = Math.round(state.rainfall * droplets.length);
document.getElementById("rainValue").textContent = `${event.target.value}%`;
document.getElementById("dropCount").textContent = `${count} gotas`;
});
document.getElementById("resetCamera").addEventListener("click", () => {
orbit.theta = 0.74;
orbit.phi = 1.04;
orbit.radius = 19.5;
orbit.target.set(0, 1.25, 0);
});
window.addEventListener("resize", resizeRenderer);
}
function resizeRenderer() {
const width = stage.clientWidth;
const height = stage.clientHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
createLabelElements();
renderSelection();
setupInteraction();
updateCamera();
updateSelectionBox();
resizeRenderer();
const clock = new THREE.Clock();
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
updateLayerPositions(delta);
updateCamera();
updateVegetation(elapsed);
updateDroplets(elapsed);
updateSelectionBox();
updateLabels();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
requestAnimationFrame(() => {
loading.classList.add("ready");
setTimeout(() => loading.remove(), 350);
animate();
});
</script>
</body>
</html>
```