V0 publique « Quelque part en 2035 » : la maquette du test axo devient la page du build

Retours de Jules du 30/09 (points 1 à 5, décision du 08/10) :
- harmonie de la planche sur toute la scène (palette relevée sur le sol, grain de papier procédural, traits des volumes) ;
- aucun arbre dans l'eau, plantes d'eau du recueil p. 19 et 21 ;
- arbres paramétriques : content/essences.md (recueil p. 10-11) pilote haies, vergers, forêt ; haies sur les limites
  de parcelles, trois côtés (pipeline/axo/09_haies_eau.py) ;
- 2035 sans voitures : vélos, vélos-cargos, attelage, moutons et chèvres, poules, canards, une voiture partagée ;
- navigation par chapitres ancrée sur une maison témoin, menu des quatre fils sur le modèle d'ORENO p. 6 ;
- bascule plan retirée.

Mise en public : Three.js et Barlow servis par le build (plus de CDN ni de Google Fonts), tout le texte dans content/
(fiches, essences, cycle de l'eau) lu et validé au build par scripts/contenu.ts. Lint de frontières rendu portable
(Windows). Shader des rubans corrigé pour Three r170. Groupe « aujourd'hui » caché au départ (défaut du 27/09).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Jules Nény
2026-10-08 11:38:47 +02:00
co-authored by Claude Opus 5.5
parent a4d99f92cd
commit c6755ef4a7
57 changed files with 2466 additions and 856 deletions
+129
View File
@@ -0,0 +1,129 @@
// La vie de 2035 (retours de Jules du 30/09) : moutons et chèvres sous les haies, poules près des maisons, canards
// sur la mare, oiseaux, et sur les routes des vélos, des vélos-cargos, un attelage et une seule voiture, partagée.
// Formes de jouet en bois : quelques volumes simples, dans les couleurs de la planche.
import * as THREE from 'three';
import { rnd } from './vegetal.js';
const lam = (c) => new THREE.MeshLambertMaterial({ color: c, emissive: '#000000' });
const mesh = (geo, m, x = 0, y = 0, z = 0, ombre = true) => { const o = new THREE.Mesh(geo, m); o.position.set(x, y, z); o.castShadow = ombre; return o; };
const boule = (r, sx = 1, sy = 1, sz = 1) => new THREE.SphereGeometry(r, 10, 7).scale(sx, sy, sz);
const boite = (x, y, z) => new THREE.BoxGeometry(x, y, z);
export const MAT = {
laine: lam('#f3eee2'), tete: lam('#4f463e'), chevre: lam('#b49a78'), poule: lam('#c98a52'), pouleB: lam('#f1ebdf'), crete: lam('#c0443a'),
canard: lam('#e9e3d2'), canardT: lam('#4f7a5a'), bec: lam('#e0a33a'), cheval: lam('#8a5f3c'), criniere: lam('#4a3628'), bois: lam('#b68f5f'),
roue: lam('#5c4c3c'), velo: lam('#3e3c37'), caisse: lam('#c9a46a'), partage: lam('#7fa3a6'), toitP: lam('#f2efe6'), oiseau: lam('#5a5650'),
chien: lam('#9a7350'),
};
export function mouton() {
const g = new THREE.Group();
g.add(mesh(boule(0.55, 1.35, 0.85, 0.95), MAT.laine, 0, 0.75, 0));
g.add(mesh(boule(0.22, 1.2, 1, 0.9), MAT.tete, 0.78, 0.9, 0));
for (const [x, z] of [[0.4, 0.25], [0.4, -0.25], [-0.4, 0.25], [-0.4, -0.25]]) g.add(mesh(boite(0.08, 0.42, 0.08), MAT.tete, x, 0.21, z, false));
return g;
}
export function chevre() {
const g = new THREE.Group();
g.add(mesh(boule(0.42, 1.45, 0.85, 0.85), MAT.chevre, 0, 0.82, 0));
g.add(mesh(boule(0.18, 1.4, 1, 0.85), MAT.chevre, 0.7, 1.12, 0));
g.add(mesh(new THREE.ConeGeometry(0.04, 0.22, 4), MAT.tete, 0.66, 1.33, 0.06, false), mesh(new THREE.ConeGeometry(0.04, 0.22, 4), MAT.tete, 0.66, 1.33, -0.06, false));
for (const [x, z] of [[0.35, 0.18], [0.35, -0.18], [-0.35, 0.18], [-0.35, -0.18]]) g.add(mesh(boite(0.07, 0.5, 0.07), MAT.tete, x, 0.25, z, false));
return g;
}
export function poule(i) {
const g = new THREE.Group();
g.add(mesh(boule(0.17, 1.3, 1, 1), i % 3 ? MAT.poule : MAT.pouleB, 0, 0.24, 0));
g.add(mesh(boule(0.09), i % 3 ? MAT.poule : MAT.pouleB, 0.17, 0.4, 0));
g.add(mesh(boite(0.05, 0.07, 0.03), MAT.crete, 0.18, 0.5, 0, false));
return g;
}
export function canard() {
const g = new THREE.Group();
g.add(mesh(boule(0.2, 1.5, 0.75, 1), MAT.canard, 0, 0.1, 0));
g.add(mesh(boule(0.1), MAT.canardT, 0.26, 0.28, 0));
g.add(mesh(boite(0.1, 0.03, 0.06), MAT.bec, 0.38, 0.26, 0, false));
return g;
}
export function attelage() {
const g = new THREE.Group();
const cheval = new THREE.Group();
cheval.add(mesh(boule(0.5, 1.6, 0.85, 0.75), MAT.cheval, 0, 1.45, 0));
cheval.add(mesh(boite(0.32, 0.75, 0.3), MAT.cheval, 0.78, 1.85, 0));
cheval.add(mesh(boule(0.22, 1.5, 0.9, 0.9), MAT.cheval, 1.0, 2.2, 0));
cheval.add(mesh(boite(0.5, 0.12, 0.08), MAT.criniere, 0.62, 2.12, 0, false));
for (const [x, z] of [[0.5, 0.2], [0.5, -0.2], [-0.5, 0.2], [-0.5, -0.2]]) cheval.add(mesh(boite(0.12, 1.05, 0.12), MAT.cheval, x, 0.52, z, false));
cheval.position.x = 1.7; g.add(cheval);
g.add(mesh(boite(2.2, 0.5, 1.4), MAT.bois, -0.6, 1.0, 0));
g.add(mesh(boite(0.6, 0.35, 0.5), MAT.caisse, -0.9, 1.42, 0.2), mesh(boite(0.5, 0.3, 0.45), lam('#a9be7c'), -0.2, 1.4, -0.25));
for (const z of [0.78, -0.78]) g.add(mesh(new THREE.CylinderGeometry(0.55, 0.55, 0.12, 14).rotateX(Math.PI / 2), MAT.roue, -0.6, 0.55, z));
g.add(mesh(new THREE.CapsuleGeometry(0.24, 0.55, 3, 8), lam('#6f8fa8'), 0.25, 1.65, 0));
return g;
}
export function velo(couleur) {
const g = new THREE.Group();
g.add(mesh(boite(1.7, 0.1, 0.12), MAT.velo, 0, 0.62, 0));
for (const x of [0.7, -0.7]) g.add(mesh(new THREE.TorusGeometry(0.32, 0.04, 5, 14), MAT.velo, x, 0.34, 0, false));
g.add(mesh(new THREE.CapsuleGeometry(0.24, 0.62, 3, 8), lam(couleur), -0.1, 1.32, 0));
return g;
}
export function veloCargo(couleur) {
const g = new THREE.Group();
g.add(mesh(boite(2.5, 0.1, 0.12), MAT.velo, 0, 0.55, 0));
for (const x of [1.05, -0.95]) g.add(mesh(new THREE.TorusGeometry(0.3, 0.04, 5, 14), MAT.velo, x, 0.32, 0, false));
g.add(mesh(boite(0.85, 0.6, 0.8), MAT.caisse, 0.75, 0.88, 0));
g.add(mesh(boule(0.18), lam('#c8553d'), 0.6, 1.25, 0.15), mesh(boule(0.16), lam('#a9be7c'), 0.9, 1.24, -0.15));
g.add(mesh(new THREE.CapsuleGeometry(0.24, 0.62, 3, 8), lam(couleur), -0.55, 1.28, 0));
return g;
}
export function voiture(couleur, partagee = false) {
const g = new THREE.Group(), m = partagee ? MAT.partage : lam(couleur);
g.add(mesh(boite(4.2, 0.9, 1.8), m, 0, 0.65, 0));
g.add(mesh(boite(2.3, 0.75, 1.62), m, -0.25, 1.45, 0));
if (partagee) {
g.add(mesh(boite(0.7, 0.28, 0.5), MAT.toitP, -0.25, 1.98, 0));
for (const [x, z] of [[0.3, 0.45], [-0.6, 0.45], [-0.6, -0.45]]) g.add(mesh(boule(0.2), lam('#e6c96a'), x, 1.55, z, false));
}
return g;
}
export function chien() {
const g = new THREE.Group();
g.add(mesh(boule(0.18, 1.6, 0.9, 0.8), MAT.chien, 0, 0.36, 0));
g.add(mesh(boule(0.12), MAT.chien, 0.3, 0.5, 0));
for (const [x, z] of [[0.18, 0.08], [0.18, -0.08], [-0.18, 0.08], [-0.18, -0.08]]) g.add(mesh(boite(0.05, 0.26, 0.05), MAT.chien, x, 0.13, z, false));
return g;
}
export function oiseau() {
const g = new THREE.Group(), geo = new THREE.BufferGeometry();
geo.setAttribute('position', new THREE.Float32BufferAttribute([0, 0, 0, -0.25, 0, 0.55, 0.15, 0, 0, 0, 0, 0, 0.15, 0, 0, -0.25, 0, -0.55], 3));
geo.computeVertexNormals();
const ailes = new THREE.Mesh(geo, new THREE.MeshLambertMaterial({ color: '#5a5650', side: THREE.DoubleSide }));
g.add(ailes); g.userData.ailes = ailes;
return g;
}
// ---------------------------------------------------------------- troupeau, basse-cour, canards, oiseaux
export function vieAnimale(D, G2035) {
const anim = [];
const troupeau = new THREE.Group(), basse = new THREE.Group(), mare = new THREE.Group(), ciel = new THREE.Group();
G2035.add(troupeau, basse, mare, ciel);
D.troupeaux.forEach(([x, z, espece, rot], i) => {
const o = espece === 0 ? mouton() : chevre(); o.position.set(x, 0, z); o.rotation.y = rot; troupeau.add(o);
anim.push((t) => { o.rotation.y = rot + Math.sin(t * 0.3 + i) * 0.35; o.children[1].position.y = (espece === 0 ? 0.9 : 1.12) - (Math.sin(t * 0.8 + i * 2) > 0.6 ? 0.18 : 0); });
});
D.poules.forEach(([x, z, rot], i) => {
const o = poule(i); o.position.set(x, 0, z); o.rotation.y = rot; basse.add(o);
anim.push((t) => { const k = Math.sin(t * 2.2 + i * 1.7); o.rotation.z = k > 0.5 ? -0.5 : 0; o.position.x = x + Math.sin(t * 0.25 + i) * 0.4; });
});
const { c, r, n } = D.canards;
for (let i = 0; i < n; i++) {
const o = canard(); mare.add(o);
anim.push((t) => { const a = t * 0.12 + (i / n) * Math.PI * 2, rr = r * (0.55 + 0.35 * Math.sin(i * 1.7)); o.position.set(c[0] + Math.cos(a) * rr, 0.05, c[1] + Math.sin(a) * rr); o.rotation.y = -a - Math.PI / 2; });
}
const centres = [[c[0], c[1]], [100, -40]];
for (let i = 0; i < 9; i++) {
const o = oiseau(); ciel.add(o); const [cx, cz] = centres[i % 2]; const R = 9 + (i % 4) * 4, h = 13 + (i % 3) * 3, v = 0.25 + rnd(i) * 0.15;
anim.push((t) => { const a = t * v + i; o.position.set(cx + Math.cos(a) * R, h + Math.sin(t * 0.7 + i) * 0.8, cz + Math.sin(a) * R); o.rotation.y = -a; o.userData.ailes.scale.z = 0.4 + 0.6 * Math.abs(Math.sin(t * 7 + i)); });
}
return { anim, troupeau, basse, mare };
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 248 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 315 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 253 KiB

+71
View File
@@ -0,0 +1,71 @@
// La planche de l'eau (concours 2020, planche 6, à 417 dpi) : onze étapes qui s'allument, pan et pince au doigt.
// Les textes viennent de content/cycle-eau.md.
export function creerCycle({ $, ETAPES, EAU, image, reduit, onFermer }) {
$('img-eau').src = image;
const svg = $('svg-eau'), NS = 'http://www.w3.org/2000/svg', n = ETAPES.length;
for (const [k, l] of Object.entries(EAU.flux)) { const p = document.createElementNS(NS, 'path'); p.setAttribute('d', 'M' + l.map((q) => q.join(' ')).join(' L')); p.setAttribute('class', 'flux'); p.dataset.f = k; svg.appendChild(p); }
const etapeDe = {}; ETAPES.forEach((e, i) => e.points.forEach((h) => (etapeDe[h] = i)));
const C = { i: 0, t0: 0, pause: 0, s: 1, x: 0, y: 0, vol: null };
for (const [k, [x, y]] of Object.entries(EAU.pts)) {
const e = ETAPES[etapeDe[k]]; if (!e) continue;
const g = document.createElementNS(NS, 'g'); g.setAttribute('class', 'pe'); g.setAttribute('transform', `translate(${x} ${y})`); g.dataset.h = k;
g.setAttribute('tabindex', '0'); g.setAttribute('role', 'button'); g.setAttribute('aria-label', `Étape ${e.n} : ${e.titre}`);
g.innerHTML = `<circle class="halo" r="16"/><circle class="coeur" r="14"/><text>${e.n}</text>`;
const go = () => { C.i = etapeDe[k]; C.pause = performance.now() + 20000; etape(); };
g.addEventListener('click', go); g.addEventListener('keydown', (ev) => { if (ev.key === 'Enter' || ev.key === ' ') { ev.preventDefault(); go(); } });
svg.appendChild(g);
}
const plateau = $('plateau'), vp = $('vue-planche');
const applique = () => (plateau.style.transform = `translate(${C.x}px, ${C.y}px) scale(${C.s})`);
const ajuste = () => { const r = vp.getBoundingClientRect(); return Math.min(r.width / 1615, r.height / 860); };
function borne(o, r) {
const w = 1615 * o.s, h = 860 * o.s;
o.x = w >= r.width ? Math.min(0, Math.max(r.width - w, o.x)) : (r.width - w) / 2;
o.y = h >= r.height ? Math.min(0, Math.max(r.height - h, o.y)) : (r.height - h) / 2;
return o;
}
function viser(x, y, s) {
const r = vp.getBoundingClientRect(), fin = borne({ s, x: r.width / 2 - x * s, y: r.height / 2 - y * s }, r);
if (reduit) { Object.assign(C, fin); applique(); return; }
const debut = { s: C.s, x: C.x, y: C.y }, t0 = performance.now();
const pas = (now) => { const k = Math.min(1, (now - t0) / 900), e = k < 0.5 ? 2 * k * k : 1 - Math.pow(-2 * k + 2, 2) / 2; C.s = debut.s + (fin.s - debut.s) * e; C.x = debut.x + (fin.x - debut.x) * e; C.y = debut.y + (fin.y - debut.y) * e; applique(); if (k < 1) C.vol = requestAnimationFrame(pas); };
cancelAnimationFrame(C.vol); C.vol = requestAnimationFrame(pas);
}
function etape() {
const e = ETAPES[C.i];
$('etape').innerHTML = `<div class="couche" style="--c-encre: var(--eau-encre)">Étape ${e.n} sur ${n}</div><h3>${e.titre}</h3><p>${e.texte}</p>${e.chiffres.length ? `<div class="chiffres" style="--c-encre: var(--eau-encre)">${e.chiffres.map(([v, l]) => `<div><b>${v}</b><small>${l}</small></div>`).join('')}</div>` : ''}<div class="source">${e.chiffres.length ? 'Chiffres pour une maison · ' : ''}source : TMIP 2024, p. 13 ; concours Habiter Demain 2020, planche 6</div>`;
$('compteur-eau').textContent = `${e.n} / ${n}`;
svg.querySelectorAll('.pe').forEach((g) => g.classList.toggle('actif', e.points.includes(g.dataset.h)));
svg.querySelectorAll('.flux').forEach((p) => p.classList.toggle('actif', e.flux.includes(p.dataset.f)));
const pt = EAU.pts[e.points[0]]; if (!pt) return;
const [x, y] = pt, sf = ajuste(), r = vp.getBoundingClientRect();
const zoom = r.width < r.height ? Math.max(sf * 2.3, (r.height * 0.98) / 860) : sf * 2.3;
viser(x, y, Math.min(Math.max(zoom, sf), 1.25));
C.t0 = performance.now();
}
function ouvrir() { $('cycle').hidden = false; C.i = 0; C.pause = 0; const sf = ajuste(); C.s = sf; C.x = 0; C.y = 0; applique(); etape(); $('b-retour').focus(); }
function fermer() { $('cycle').hidden = true; onFermer(); }
$('b-retour').addEventListener('click', fermer);
addEventListener('keydown', (e) => { if (e.key === 'Escape' && !$('cycle').hidden) fermer(); });
$('e-prec').addEventListener('click', () => { C.i = (C.i + n - 1) % n; C.pause = performance.now() + 20000; etape(); });
$('e-suiv').addEventListener('click', () => { C.i = (C.i + 1) % n; C.pause = performance.now() + 20000; etape(); });
const pp = new Map();
vp.addEventListener('pointerdown', (e) => { if (e.target.closest('.pe')) return; vp.setPointerCapture(e.pointerId); pp.set(e.pointerId, [e.clientX, e.clientY]); C.pause = performance.now() + 20000; cancelAnimationFrame(C.vol); });
vp.addEventListener('pointermove', (e) => {
if (!pp.has(e.pointerId)) return; const av = [...pp.values()].map((p) => [...p]); pp.set(e.pointerId, [e.clientX, e.clientY]); const ap = [...pp.values()];
const c = (L) => [L.reduce((s, p) => s + p[0], 0) / L.length, L.reduce((s, p) => s + p[1], 0) / L.length], a = c(av), b = c(ap);
C.x += b[0] - a[0]; C.y += b[1] - a[1];
if (av.length === 2 && ap.length === 2) { const r = vp.getBoundingClientRect(), dA = Math.hypot(av[0][0] - av[1][0], av[0][1] - av[1][1]), dB = Math.hypot(ap[0][0] - ap[1][0], ap[0][1] - ap[1][1]); const k = dB / dA, ns = Math.max(ajuste() * 0.9, Math.min(2.5, C.s * k)), kk = ns / C.s, px = b[0] - r.left, py = b[1] - r.top; C.x = px - (px - C.x) * kk; C.y = py - (py - C.y) * kk; C.s = ns; }
applique();
});
const finP = (e) => pp.delete(e.pointerId); vp.addEventListener('pointerup', finP); vp.addEventListener('pointercancel', finP);
vp.addEventListener('wheel', (e) => { e.preventDefault(); const r = vp.getBoundingClientRect(), ns = Math.max(ajuste() * 0.9, Math.min(2.5, C.s * (e.deltaY > 0 ? 0.9 : 1.11))), kk = ns / C.s, px = e.clientX - r.left, py = e.clientY - r.top; C.x = px - (px - C.x) * kk; C.y = py - (py - C.y) * kk; C.s = ns; applique(); C.pause = performance.now() + 20000; }, { passive: false });
(function tic(now) {
requestAnimationFrame(tic);
if ($('cycle').hidden) return;
if (now < C.pause) { C.t0 = now; $('temps-eau').style.width = '0%'; return; }
const k = (now - C.t0) / 8000; $('temps-eau').style.width = Math.min(100, k * 100) + '%';
if (k >= 1 && !reduit) { C.i = (C.i + 1) % n; etape(); }
})(performance.now());
return { ouvrir, fermer };
}
+1
View File
@@ -0,0 +1 @@
{"W": 1615, "H": 860, "pts": {"h1": [410, 660], "h2": [590, 720], "h3": [617, 482], "h4": [820, 530], "h5": [835, 670], "h6": [1110, 570], "h7": [1195, 660], "h8": [1358, 495], "h9": [1300, 650], "h10": [1235, 750], "h11": [1085, 745], "h1b": [610, 170], "h5b": [1005, 242]}, "flux": {"usees": [[572, 692], [620, 742], [680, 795], [740, 818], [810, 820], [865, 805], [920, 765], [980, 720], [1030, 675], [1070, 635]], "pluie": [[565, 618], [610, 620], [670, 628]]}}
+182
View File
@@ -0,0 +1,182 @@
// « Quelque part en 2035 » — V0 publique (08/10/2026) : le prototype du test axo devenu page du build.
// Navigation par chapitres (eau, vivant, chaleur, quartier), chacun ancré sur une maison ; menu des quatre fils sur le
// modèle de la p. 6 d'ORENO. Le texte vient de content/, sauf les onze légendes des bulles sans fiche (plus bas,
// reprises du test du 27/09) : dette notée au RECAP, à déplacer dans content/ avec le portage de novembre.
import '@fontsource/barlow/400.css';
import '@fontsource/barlow/500.css';
import '@fontsource/barlow/600.css';
import '@fontsource/barlow/700.css';
import '@fontsource/barlow-condensed/500.css';
import '@fontsource/barlow-condensed/600.css';
import './style.css';
import { CHAPITRES, ESSENCES, CYCLE } from 'virtual:contenu';
import D from '../data/scene2035.json';
import EAU from './eau_crop.json';
import sol2035 from './assets/sol2035.jpg';
import solauj from './assets/solauj.jpg';
import eauCrop from './assets/eau_crop.jpg';
import { creerScene } from './scene.js';
import { creerCycle } from './cycle.js';
import { picto, COULEURS } from './pictos.js';
const $ = (id) => document.getElementById(id);
const BULLES = Object.fromEntries(Object.entries(import.meta.glob('./assets/bulles/*.png', { eager: true, query: '?url', import: 'default' })).map(([k, v]) => [k.split('/').pop().slice(0, -4), v]));
const reduit = matchMedia('(prefers-reduced-motion: reduce)').matches;
const petit = Math.min(innerWidth, innerHeight) < 700;
const params = new URL(location.href).searchParams;
const FOND = params.get('mode') === 'fond';
// ---------------------------------------------------------------- le grain du papier (procédural : aucune texture tierce)
(function grain() {
const c = document.createElement('canvas'); c.width = c.height = 256; const x = c.getContext('2d'), im = x.createImageData(256, 256);
const h = (i, j) => { const s = Math.sin(i * 127.1 + j * 311.7) * 43758.5453; return s - Math.floor(s); };
const lisse = (u, v, f) => { const i = Math.floor(u / f), j = Math.floor(v / f), a = u / f - i, b = v / f - j, w = (k) => k * k * (3 - 2 * k); const n = (p, q) => h(((p % (256 / f)) + 256 / f) % (256 / f), ((q % (256 / f)) + 256 / f) % (256 / f)); return n(i, j) * (1 - w(a)) * (1 - w(b)) + n(i + 1, j) * w(a) * (1 - w(b)) + n(i, j + 1) * (1 - w(a)) * w(b) + n(i + 1, j + 1) * w(a) * w(b); };
for (let v = 0; v < 256; v++) for (let u = 0; u < 256; u++) {
const k = (v * 256 + u) * 4, g = 0.55 * lisse(u, v, 32) + 0.3 * lisse(u, v, 8) + 0.15 * h(u, v);
const l = 255 - Math.round(g * 26); im.data[k] = l; im.data[k + 1] = l - 1; im.data[k + 2] = l - 5; im.data[k + 3] = 255;
}
x.putImageData(im, 0, 0); $('grain').style.backgroundImage = `url(${c.toDataURL()})`;
})();
// ---------------------------------------------------------------- le parcours
const FILS = ['eau', 'vivant', 'chaleur', 'quartier'];
const CH = Object.fromEntries(CHAPITRES.map((c) => [c.id, c]));
const parcours2035 = ['accueil', ...FILS].flatMap((id) => CH[id].fiches);
const parcoursAuj = CH.auj.fiches;
const FICHE = Object.fromEntries(CHAPITRES.flatMap((c) => c.fiches.map((f) => [f.id, f])));
const E = { epoque: '2035', i: 0, lecture: !reduit && !FOND, t0: performance.now(), pause: 0, mini: null };
const DUREE = 12000;
const liste = () => (E.epoque === 'auj' ? parcoursAuj : parcours2035);
const couleur = (id) => COULEURS[id] || COULEURS.accueil;
const styleC = (id) => { const k = couleur(id); return `--c:${k.c};--c-encre:${k.encre};--c-fond:${k.fond}`; };
let T3 = null;
const panneau = () => {
const r = $('fiches').getBoundingClientRect(), W = innerWidth;
return W >= 900 ? { bas: 0, gauche: r.right + 8 } : { bas: Math.max(0, innerHeight - r.top), gauche: 0 };
};
function onglets() {
const o = $('onglets');
if (E.epoque === 'auj') { o.innerHTML = `<button type="button" aria-current="true" style="${styleC('auj')}"><i></i>${CH.auj.court}</button>`; return; }
const ch = liste()[E.i].chapitre;
o.innerHTML = FILS.map((id) => `<button type="button" data-ch="${id}" aria-current="${ch === id}" style="${styleC(id)}"><i></i>${CH[id].court}</button>`).join('');
o.querySelectorAll('button[data-ch]').forEach((b) => b.addEventListener('click', () => { suspendre(); allerA(CH[b.dataset.ch].fiches[0].id); }));
}
function points(f) {
const L = liste().filter((x) => x.chapitre === f.chapitre), k = L.indexOf(f);
$('points').innerHTML = L.map((_, i) => `<b class="${i < k ? 'vu' : i === k ? 'ici' : ''}"></b>`).join('');
$('compteur').textContent = L.length > 1 ? `${k + 1} / ${L.length}` : '';
}
let changement = 0;
function montrer(voler = true) {
const L = liste(); E.i = (E.i + L.length) % L.length;
const f = E.mini || L[E.i];
const fiches = $('fiches'); fiches.setAttribute('style', styleC(f.chapitre));
const art = $('fiche'), id = ++changement;
const remplir = () => {
if (id !== changement) return;
const ch = CH[f.chapitre];
art.innerHTML = `<div class="icone">${picto(f.picto, BULLES)}</div><div>
<div class="couche">${ch ? ch.titre : ''}</div>
<h2>${f.titre}</h2>${f.texte.map((p) => `<p>${p}</p>`).join('')}
${f.chiffres.length ? `<div class="chiffres">${f.chiffres.map(([v, l]) => `<div><b>${v}</b><small>${l}</small></div>`).join('')}</div>` : ''}
<div class="source">source : ${f.source}</div>
${f.action ? `<button type="button" class="action" id="b-action">${f.action} →</button>` : ''}</div>`;
const b = $('b-action'); if (b) b.addEventListener('click', () => { suspendre(60000); cycle.ouvrir(); });
art.classList.remove('sort');
};
if (reduit || !art.innerHTML) remplir(); else { art.classList.add('sort'); setTimeout(remplir, 260); }
onglets(); if (!E.mini) points(f);
E.t0 = performance.now();
if (!E.mini) history.replaceState(null, '', `#${f.id}`);
if (T3) { T3.effet(f.effet); if (voler) T3.cadrer(f.cadrage.split(/\s+/)[0]); }
}
function aller(d) { E.mini = null; E.i += d; montrer(); }
function allerA(id) {
const f = FICHE[id]; if (!f) return;
if (f.epoque !== E.epoque) setEpoque(f.epoque, false);
const i = liste().findIndex((x) => x.id === id); if (i >= 0) { E.mini = null; E.i = i; montrer(); }
}
function suspendre(ms = 25000) { E.pause = performance.now() + ms; }
$('b-prec').addEventListener('click', () => { suspendre(); aller(-1); });
$('b-suiv').addEventListener('click', () => { suspendre(); aller(1); });
$('b-lecture').addEventListener('click', () => { E.lecture = !E.lecture; E.pause = 0; E.t0 = performance.now(); majLecture(); });
function majLecture() {
$('b-lecture').setAttribute('aria-label', E.lecture ? 'Pause' : 'Lecture');
$('i-lecture').innerHTML = E.lecture ? '<rect x="6" y="5" width="4" height="14" rx="1"/><rect x="14" y="5" width="4" height="14" rx="1"/>' : '<path d="M7 5l12 7-12 7z"/>';
}
(function tic(now) {
requestAnimationFrame(tic);
if (!$('cycle').hidden || !$('menu').hidden) { E.t0 = now; return; }
const actif = E.lecture && now > E.pause && !E.mini;
if (!actif) { $('temps').style.width = '0%'; if (now <= E.pause) E.t0 = now; return; }
const k = (now - E.t0) / DUREE; $('temps').style.width = Math.min(100, k * 100) + '%';
if (k >= 1) aller(1);
})(performance.now());
// ---------------------------------------------------------------- époque, menu des quatre fils
function setEpoque(e, montrerFiche = true) {
E.epoque = e; E.i = 0; E.mini = null;
$('b-auj').setAttribute('aria-pressed', e === 'auj'); $('b-2035').setAttribute('aria-pressed', e === '2035');
$('b-menu').parentElement.hidden = e === 'auj';
if (T3) T3.epoque(e);
if (montrerFiche) montrer();
}
$('b-auj').addEventListener('click', () => { suspendre(); setEpoque('auj'); });
$('b-2035').addEventListener('click', () => { suspendre(); setEpoque('2035'); });
$('b-tourner').addEventListener('click', () => { if (T3) T3.tourner(); });
const POS = { quartier: 'quartier', chaleur: 'chaleur', eau: 'eau', vivant: 'vivant' };
function menu() {
const html = FILS.map((id) => {
const ch = CH[id], k = couleur(id);
const propres = ch.fiches.map((f, n) => ({ f, n: n + 1, de: id }));
const croisees = CHAPITRES.filter((c) => c.id !== id).flatMap((c) => c.fiches.filter((f) => f.aussi.includes(id)).map((f) => ({ f, n: '', de: c.id })));
const li = [...propres, ...croisees].map(({ f, n, de }) => {
const x = [de, ...f.aussi].filter((v, i, a) => a.indexOf(v) === i);
return `<li><button type="button" data-f="${f.id}"><span class="n">${n}</span>${f.titre}${x.length > 1 ? `<span class="x" aria-label="appartient à deux fils">${x.map((c) => `<i style="background:${couleur(c).c}"></i>`).join('')}</span>` : ''}</button></li>`;
}).join('');
return `<div class="cadre ${POS[id]}" style="${styleC(id)}"><h3>${picto({ eau: 'noue', vivant: 'pomme', chaleur: 'paille', quartier: 'marche' }[id], BULLES)}${ch.titre}</h3><ol>${li}</ol></div>`;
}).join('');
$('cadres').innerHTML = html;
$('cadres').querySelectorAll('button[data-f]').forEach((b) => b.addEventListener('click', () => { fermerMenu(); suspendre(); allerA(b.dataset.f); }));
}
function ouvrirMenu() { menu(); $('menu').hidden = false; $('b-menu').setAttribute('aria-expanded', 'true'); if (T3) { T3.effet(null); T3.cadrer('maison', 1400, true); } $('b-menu-fermer').focus(); }
function fermerMenu() { $('menu').hidden = true; $('b-menu').setAttribute('aria-expanded', 'false'); }
$('b-menu').addEventListener('click', () => ($('menu').hidden ? ouvrirMenu() : (fermerMenu(), montrer())));
$('b-menu-fermer').addEventListener('click', () => { fermerMenu(); montrer(); });
addEventListener('keydown', (e) => { if (e.key === 'Escape' && !$('menu').hidden) { fermerMenu(); montrer(); } });
// ---------------------------------------------------------------- la scène
try {
T3 = creerScene($('scene'), {
D, ESSENCES, BULLES, IMG: { sol2035, solauj }, reduit, petit,
onToucher(type, a, b) {
suspendre();
if (type === 'fiche') allerA(a);
if (type === 'bulle') {
if (b) allerA(b);
else { const t = { film: 'Un ciné-club dans un garage ouvert.', ballons: 'Les délaissés deviennent terrains de jeu.', barbecue: 'Un barbecue partagé au bord de la place.', confiture: 'Une conserverie : le surplus des haies en bocaux.', bouteille: 'Jus et cidre des vergers du quartier.', musique: 'Un bal sur la place, au bord de la mare.', bols: 'Un atelier de céramique.', soin: 'Un cabinet de soin, une herboristerie.', entraide: "Garde d'enfants partagée, entraide entre voisins.", reemploi: 'Une recyclerie et un compost de quartier.', garage: 'Un garage associatif de réparation.' }[a];
if (t) { E.mini = { id: 'mini', chapitre: 'quartier', picto: a, titre: t.split(/[.:]/)[0], texte: [t], chiffres: [], source: 'bulle de la planche « le quartier en 2030 », TMIP 2024, p. 15', cadrage: 'place', effet: null, action: null }; montrer(false); } }
}
},
});
} catch (e) { console.error(e); T3 = null; }
if (T3) T3.poserPanneau(panneau);
else { $('scene').hidden = true; const r = $('repli'); r.hidden = false; r.style.backgroundImage = `url(${sol2035})`; }
const cycle = creerCycle({ $, ETAPES: CYCLE, EAU, image: eauCrop, reduit, onFermer: () => { E.t0 = performance.now(); } });
// ---------------------------------------------------------------- départ : liens directs (#fiche, #aujourdhui, #cycle), mode fond
majLecture();
const h = location.hash.slice(1);
if (FOND) {
document.body.classList.add('fond');
$('fiches').hidden = true; document.querySelector('.barre').hidden = true;
const m = params.get('maison');
if (T3) { T3.fond(true, 1); T3.cadrer(m !== null ? 'maison' : 'quartier', 0, true); }
} else if (h === 'aujourdhui') setEpoque('auj');
else if (FICHE[h]) allerA(h);
else { montrer(false); if (T3) T3.cadrer('quartier', 0, true); }
if (h === 'cycle') setTimeout(() => cycle.ouvrir(), 300);
+40
View File
@@ -0,0 +1,40 @@
// Pictos PROVISOIRES des fiches. Ils seront remplacés par les fichiers du lot pictos de la plateforme
// (reinnover public/pictos/<nom>.svg, un seul découpage : SPEC menu branches fiches §10). Les bulles de la p. 15
// (dessins de Jules) servent quand le nom d'un picto est celui d'une bulle.
export const COULEURS = {
eau: { c: '#3a74a8', encre: '#1d5886', fond: '#e1ebf5' },
vivant: { c: '#8f7b22', encre: '#62560f', fond: '#eeead0' },
chaleur: { c: '#c96d0c', encre: '#8f4506', fond: '#fde8c8' },
quartier: { c: '#8a5a7a', encre: '#5e3a54', fond: '#f1e6ee' },
accueil: { c: '#6b6458', encre: '#3f5563', fond: '#ece8de' },
auj: { c: '#6b6458', encre: '#4a443b', fond: '#ece8de' },
};
const rond = (c, corps) => `<svg viewBox="0 0 56 56" role="img" aria-hidden="true"><circle cx="28" cy="28" r="25" fill="#fff" stroke="${c}" stroke-width="2.5"/>${corps}</svg>`;
const E = COULEURS.eau.c, V = COULEURS.vivant.c, C = COULEURS.chaleur.c, Q = COULEURS.quartier.c, G = '#6b6458', VERT = '#7d9a4f';
const DESSINS = {
toit: [E, `<path d="M14 27l12-10 12 10" fill="none" stroke="${E}" stroke-width="2.6" stroke-linejoin="round"/><path d="M17 30v12h12V30" fill="none" stroke="${E}" stroke-width="2.2"/><path d="M36 13c1.6 2.4 2.4 3.6 2.4 4.8a2.4 2.4 0 0 1-4.8 0c0-1.2.8-2.4 2.4-4.8zM42 19c1.6 2.4 2.4 3.6 2.4 4.8a2.4 2.4 0 0 1-4.8 0c0-1.2.8-2.4 2.4-4.8z" fill="${E}"/>`],
gouttiere: [E, `<path d="M12 22h26v3H12z" fill="#cfe0ef" stroke="${E}" stroke-width="2"/><path d="M35 25v10" stroke="${E}" stroke-width="3"/><rect x="29" y="35" width="12" height="9" rx="2" fill="#fff" stroke="${E}" stroke-width="2.2"/><path d="M31 38h8M31 41h8" stroke="${E}" stroke-width="1.4"/><path d="M20 30c1.4 2 2 3 2 4a2 2 0 0 1-4 0c0-1 .6-2 2-4z" fill="${E}"/>`],
cuve: [E, `<ellipse cx="28" cy="18" rx="11" ry="4" fill="#cfe0ef" stroke="${E}" stroke-width="2.2"/><path d="M17 18v18c0 2.2 5 4 11 4s11-1.8 11-4V18" fill="#e7f0f8" stroke="${E}" stroke-width="2.2"/><path d="M17 27c0 2.2 5 4 11 4s11-1.8 11-4" fill="none" stroke="${E}" stroke-width="1.6" stroke-dasharray="2 2"/><path d="M19 31c3 2 15 2 18 0v5c0 2-4 3.5-9 3.5S19 38 19 36z" fill="#9fc3e3"/>`],
pompe: [E, `<rect x="14" y="26" width="13" height="12" rx="2" fill="#fff" stroke="${E}" stroke-width="2.2"/><circle cx="20.5" cy="32" r="3.2" fill="none" stroke="${E}" stroke-width="2"/><path d="M27 32h7v-9h6" fill="none" stroke="${E}" stroke-width="2.4" stroke-linejoin="round"/><path d="M40 20v6" stroke="${E}" stroke-width="2.4"/><path d="M38 31c1.4 2 2 3 2 4a2 2 0 0 1-4 0c0-1 .6-2 2-4z" fill="${E}"/>`],
rigole: [E, `<path d="M13 22h9l6 6h8l7 7" fill="none" stroke="${E}" stroke-width="2.6" stroke-dasharray="3 3" stroke-linecap="round"/><path d="M39 31l4 4-5 1" fill="none" stroke="${E}" stroke-width="2.6" stroke-linecap="round" stroke-linejoin="round"/><path d="M18 36c2 3 3 4.5 3 6a3 3 0 0 1-6 0c0-1.5 1-3 3-6z" fill="${E}"/>`],
noue: [E, `<path d="M11 34c4 5 9 7 17 7s13-2 17-7" fill="#cfe0ef" stroke="${E}" stroke-width="2.4"/><path d="M20 33v-9M24 33v-12M32 33v-10M36 33v-7" stroke="${VERT}" stroke-width="2.4" stroke-linecap="round"/><circle cx="24" cy="20" r="2" fill="#d9b23a"/><circle cx="32" cy="22" r="2" fill="#b0608a"/>`],
bassin: [E, `<path d="M11 30h34" stroke="#8a847a" stroke-width="2"/><path d="M13 31c3 8 8 11 15 11s12-3 15-11z" fill="#cfe0ef" stroke="${E}" stroke-width="2.4"/><path d="M19 36c3-2 6 2 9 0s6-2 9 0" fill="none" stroke="${E}" stroke-width="2"/><path d="M34 29v-9M38 29v-6" stroke="${VERT}" stroke-width="2.4" stroke-linecap="round"/>`],
paille: [C, `<path d="M14 28l14-12 14 12" fill="none" stroke="${C}" stroke-width="2.6" stroke-linejoin="round"/><rect x="17" y="27" width="22" height="15" fill="#f1d58a" stroke="${C}" stroke-width="2.2"/><path d="M21 31h6M29 35h6M21 39h6" stroke="${C}" stroke-width="1.6"/>`],
serre: [C, `<path d="M12 40V26l9-7h23v21z" fill="#e9f4f1" stroke="${C}" stroke-width="2.2" stroke-linejoin="round"/><path d="M21 19v21M30 19v21M37 19v21M12 31h32" stroke="${C}" stroke-width="1.4"/><circle cx="42" cy="13" r="4" fill="#f4b24a"/>`],
poele: [C, `<rect x="19" y="24" width="18" height="18" rx="3" fill="#fff" stroke="${C}" stroke-width="2.2"/><path d="M25 32c2-3 1-5 3-7 0 3 3 4 3 7a3 3 0 0 1-6 0z" fill="#e3893a"/><path d="M26 24v-10h4v10" fill="none" stroke="${C}" stroke-width="2.2"/><path d="M33 12c2 1 2 3 0 4" fill="none" stroke="#b5ab9b" stroke-width="2"/>`],
quartier: [G, `<path d="M9 36l7-6 7 6v7H9zM24 33l8-7 8 7v10H24zM37 37l5-4 5 4v6H37z" fill="#fff" stroke="${G}" stroke-width="2" stroke-linejoin="round"/><circle cx="17" cy="21" r="4" fill="#a9be7c"/><circle cx="41" cy="24" r="3.5" fill="#e6c96a"/>`],
liens: [G, `<path d="M28 12l-8 31M28 12l8 31M22 30h12M24 22h8" fill="none" stroke="${G}" stroke-width="2.4" stroke-linecap="round"/><path d="M10 44c6-4 12-4 18 0s12 4 18 0" fill="none" stroke="${Q}" stroke-width="2.2" stroke-dasharray="3 3"/>`],
route: [Q, `<rect x="13" y="26" width="30" height="10" rx="4" fill="#fff" stroke="${G}" stroke-width="2.4"/><path d="M18 26l4-6h12l4 6" fill="none" stroke="${G}" stroke-width="2.4" stroke-linejoin="round"/><circle cx="20" cy="37" r="3" fill="${G}"/><circle cx="36" cy="37" r="3" fill="${G}"/>`],
voiture: [Q, `<rect x="12" y="27" width="32" height="10" rx="4" fill="#d6e6e6" stroke="${G}" stroke-width="2.2"/><path d="M17 27l4-6h14l4 6" fill="none" stroke="${G}" stroke-width="2.2" stroke-linejoin="round"/><circle cx="20" cy="38" r="3" fill="${G}"/><circle cx="36" cy="38" r="3" fill="${G}"/><circle cx="22" cy="16" r="2.4" fill="${Q}"/><circle cx="28" cy="15" r="2.4" fill="${Q}"/><circle cx="34" cy="16" r="2.4" fill="${Q}"/>`],
mouton: [V, `<ellipse cx="27" cy="31" rx="11" ry="7" fill="#f6f2e8" stroke="${G}" stroke-width="2"/><circle cx="20" cy="27" r="3.4" fill="#f6f2e8" stroke="${G}" stroke-width="1.6"/><circle cx="26" cy="25" r="3.6" fill="#f6f2e8" stroke="${G}" stroke-width="1.6"/><circle cx="33" cy="26" r="3.4" fill="#f6f2e8" stroke="${G}" stroke-width="1.6"/><ellipse cx="40" cy="30" rx="4" ry="3" fill="#5a5148"/><path d="M22 37v5M31 37v5" stroke="#5a5148" stroke-width="2"/>`],
};
export function picto(nom, bulles) {
const d = DESSINS[nom];
if (d) return rond(d[0], d[1]);
if (bulles && bulles[nom]) return `<img src="${bulles[nom]}" alt="">`;
return rond(G, DESSINS.quartier[1]);
}
+611
View File
@@ -0,0 +1,611 @@
// La scène 3D : le plan vectoriel du concours posé sur un socle, les volumes, le végétal, l'eau, la vie, le hors-champ.
// Caméra axonométrique orthographique. Les fiches appellent cadrer(nom) et effet(nom) : deux fiches qui partagent
// un cadrage ne bougent pas la caméra (c'est ce qui empêche les fiches de « se balader »).
import * as THREE from 'three';
import { lot, haiesEssences, vergers, arbresPlan, thuyas, plantesEau, potager, NOMS_AQUA, rnd } from './vegetal.js';
import { vieAnimale, velo, veloCargo, attelage, voiture, chien } from './animaux.js';
const PAL = {
fond: '#efeee2', papier: '#e7e5d3', socle: '#d9d3bc',
mur: '#f4f0e4', toit: '#c9bba8', paille: '#e6cf8a', toitT: '#b9a68e', grandMur: '#f1ebdc', grandToit: '#c99a7f',
trait: '#7d6a5c', tronc: '#8f7a62', thuya: '#6f8659', eau: '#3f8fb0', eauVive: '#2f7fa8', sentier: '#d6a83a',
gens: ['#c47f5a', '#6f8fa8', '#d3b45c', '#8aa36a', '#a7768e', '#7a7066', '#cbbfa6', '#8f7aa6'],
autos: ['#9aa1a6', '#a8675a', '#6d7f99', '#d8d2c4', '#6a6e70', '#8a9a72'],
etals: ['#d9a35b', '#e0c27a', '#c98466', '#9fb57a', '#85adc0'],
};
export function creerScene(canvas, { D, ESSENCES, BULLES, IMG, reduit, petit, onToucher }) {
const renderer = new THREE.WebGLRenderer({ canvas, antialias: true, powerPreference: 'high-performance' });
if (!renderer.getContext()) return null;
renderer.setPixelRatio(Math.min(devicePixelRatio || 1, petit ? 1.5 : 2));
renderer.shadowMap.enabled = true; renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(PAL.fond);
const cam = new THREE.OrthographicCamera(-1, 1, 1, -1, 1, 4000);
const C = (h) => new THREE.Color(h);
// lumière douce : ciel chaud, soleil bas du sud-ouest (ombres légères, comme un lavis)
scene.add(new THREE.HemisphereLight(0xfffcf2, 0xd9d2bf, 2.35));
const soleil = new THREE.DirectionalLight(0xfff1dc, 1.05);
soleil.position.set(-110, 170, 120); soleil.castShadow = true; soleil.shadow.mapSize.set(petit ? 1024 : 2048, petit ? 1024 : 2048);
Object.assign(soleil.shadow.camera, { left: -170, right: 170, top: 130, bottom: -130, near: 20, far: 520 });
soleil.shadow.bias = -0.0006; soleil.shadow.normalBias = 0.35; soleil.shadow.intensity = 0.7;
scene.add(soleil, soleil.target);
// ---------------------------------------------------------------- sol : le plan, en deux états
let besoin = true;
const chargeur = new THREE.TextureLoader();
const tex = (url) => { const t = chargeur.load(url, () => (besoin = true)); t.colorSpace = THREE.SRGBColorSpace; t.anisotropy = renderer.capabilities.getMaxAnisotropy(); return t; };
const papier = new THREE.Mesh(new THREE.PlaneGeometry(5000, 5000).rotateX(-Math.PI / 2), new THREE.MeshLambertMaterial({ color: PAL.papier }));
papier.position.y = -2.3; papier.receiveShadow = true; scene.add(papier);
const socle = new THREE.Mesh(new THREE.BoxGeometry(D.Wm, 2.2, D.Hm), new THREE.MeshLambertMaterial({ color: PAL.socle }));
socle.position.y = -1.13; socle.receiveShadow = true; scene.add(socle);
const geoSol = new THREE.PlaneGeometry(D.Wm, D.Hm).rotateX(-Math.PI / 2);
const sol35 = new THREE.Mesh(geoSol, new THREE.MeshLambertMaterial({ map: tex(IMG.sol2035) }));
sol35.receiveShadow = true; scene.add(sol35);
const matAuj = new THREE.MeshLambertMaterial({ map: tex(IMG.solauj), transparent: true, opacity: 0, depthWrite: false, polygonOffset: true, polygonOffsetFactor: -2, polygonOffsetUnits: -2 });
const solAuj = new THREE.Mesh(geoSol, matAuj); solAuj.receiveShadow = true; solAuj.position.y = 0.02; scene.add(solAuj);
const G = { v2035: new THREE.Group(), vAuj: new THREE.Group() };
scene.add(G.v2035, G.vAuj);
const cliquables = [];
const anim = [];
// ---------------------------------------------------------------- maisons
const matTrait = new THREE.LineBasicMaterial({ color: PAL.trait, transparent: true, opacity: 0.42 });
const mat = {
mur: new THREE.MeshLambertMaterial({ color: PAL.mur }), toit: new THREE.MeshLambertMaterial({ color: PAL.toit, side: THREE.DoubleSide }),
paille: new THREE.MeshLambertMaterial({ color: PAL.paille, emissive: '#000000' }), toitT: new THREE.MeshLambertMaterial({ color: PAL.toitT, side: THREE.DoubleSide }),
verre: new THREE.MeshLambertMaterial({ color: '#d4ebe6', transparent: true, opacity: 0.55, depthWrite: false, emissive: '#000000' }), bord: new THREE.LineBasicMaterial({ color: '#86ada7' }),
chem: new THREE.MeshLambertMaterial({ color: '#a39a8c', emissive: '#000000' }), cuve: new THREE.MeshLambertMaterial({ color: '#7fb3cf', emissive: '#000000' }),
grandMur: new THREE.MeshLambertMaterial({ color: PAL.grandMur }), grandToit: new THREE.MeshLambertMaterial({ color: PAL.grandToit, side: THREE.DoubleSide, emissive: '#000000' }),
zinc: new THREE.MeshLambertMaterial({ color: '#9aa3a6', emissive: '#000000' }), pompe: new THREE.MeshLambertMaterial({ color: '#5f7f96', emissive: '#000000' }),
};
// la maison témoin a ses propres matériaux : ses effets n'allument qu'elle
const matT = { paille: mat.paille.clone(), verre: mat.verre.clone(), cuve: mat.cuve.clone(), chem: mat.chem.clone(), toitT: mat.toitT.clone() };
function toit(Lu, Lv, eave, rh, o) {
const hu = Lu / 2 + o, hv = Lv / 2 + o, ry = eave + rh, yb = eave - rh * (o / (Lv / 2));
const g = new THREE.BufferGeometry();
g.setAttribute('position', new THREE.Float32BufferAttribute([
-hu, yb, -hv, hu, yb, -hv, hu, ry, 0, -hu, yb, -hv, hu, ry, 0, -hu, ry, 0,
-hu, yb, hv, -hu, ry, 0, hu, ry, 0, -hu, yb, hv, hu, ry, 0, hu, yb, hv], 3));
g.computeVertexNormals(); return g;
}
function pignons(Lu, Lv, eave, rh) {
const g = new THREE.BufferGeometry(), x = Lu / 2, v = Lv / 2, ry = eave + rh;
g.setAttribute('position', new THREE.Float32BufferAttribute([-x, eave, -v, -x, eave, v, -x, ry, 0, x, eave, v, x, eave, -v, x, ry, 0], 3));
g.computeVertexNormals(); return g;
}
const transformees = []; // { g, c, eave, rh, Lu, Lv, ite, chem, cuve, temoin }
let indexT = 0, grand = null;
function maison(h, variante) {
const p = h.p.map(([x, z]) => new THREE.Vector2(x, z));
const c = p.reduce((a, b) => a.add(b), new THREE.Vector2()).multiplyScalar(0.25);
const e1 = p[1].clone().sub(p[0]), e2 = p[2].clone().sub(p[1]);
const fw = new THREE.Vector2(Math.cos(h.f), -Math.sin(h.f));
let u, Lu, Lv;
if (Math.abs(e1.clone().normalize().dot(fw)) >= Math.abs(e2.clone().normalize().dot(fw))) { u = e1.clone().normalize(); Lu = e1.length(); Lv = e2.length(); }
else { u = e2.clone().normalize(); Lu = e2.length(); Lv = e1.length(); }
const g = new THREE.Group(); g.position.set(c.x, 0, c.y); g.rotation.y = Math.atan2(-u.y, u.x);
const estGrand = h.t === 'grand', transfo = h.t === 'transformee' && variante === '2035';
const temoin = transfo && indexT === D.temoin.maison;
const M = temoin ? { ...mat, ...matT } : mat;
const eave = estGrand ? 7.4 : 5.4, rh = Math.min(estGrand ? 5 : 3.4, Lv * (estGrand ? 0.27 : 0.31)), ite = transfo ? 0.7 : 0;
const mMur = estGrand ? M.grandMur : transfo ? M.paille : M.mur, mToit = estGrand ? M.grandToit : transfo ? M.toitT : M.toit;
const murs = new THREE.Mesh(new THREE.BoxGeometry(Lu + ite, eave, Lv + ite), mMur); murs.position.y = eave / 2;
const t = new THREE.Mesh(toit(Lu + ite, Lv + ite, eave, rh, 0.55), mToit);
const pg = new THREE.Mesh(pignons(Lu + ite, Lv + ite, eave, rh), transfo ? M.paille : new THREE.MeshLambertMaterial({ color: mMur.color, side: THREE.DoubleSide }));
[murs, t, pg].forEach((m) => { m.castShadow = true; m.receiveShadow = true; g.add(m); });
// le trait du dessin : arêtes des volumes, discrètes
const ar = new THREE.LineSegments(new THREE.EdgesGeometry(murs.geometry), matTrait); ar.position.copy(murs.position); g.add(ar);
g.add(new THREE.LineSegments(new THREE.EdgesGeometry(t.geometry, 20), matTrait));
if (transfo) {
const th = g.rotation.y, faces = [[1, 0, Math.cos(th), -Math.sin(th)], [-1, 0, -Math.cos(th), Math.sin(th)], [0, 1, Math.sin(th), Math.cos(th)], [0, -1, -Math.sin(th), -Math.cos(th)]];
const f = faces.reduce((a, b) => (b[3] > a[3] ? b : a));
const sh = 3.3, d = 2.4, cote = f[0] !== 0 ? Lv : Lu;
const serre = new THREE.Mesh(new THREE.BoxGeometry(f[0] !== 0 ? d : cote * 0.7, sh, f[0] !== 0 ? cote * 0.7 : d), M.verre);
serre.position.set(f[0] * ((Lu + ite) / 2 + d / 2), sh / 2, f[1] * ((Lv + ite) / 2 + d / 2)); serre.renderOrder = 1; g.add(serre);
const as = new THREE.LineSegments(new THREE.EdgesGeometry(serre.geometry), mat.bord); as.position.copy(serre.position); g.add(as);
const ch = new THREE.Mesh(new THREE.BoxGeometry(0.7, 2.6, 0.7), M.chem); ch.position.set(Lu * 0.2, eave + rh * 0.62 + 0.7, -f[1] * Lv * 0.12); ch.castShadow = true; g.add(ch);
// la cuve, au pied de la descente, à l'opposé de la serre
const bout = (Lu + ite) / 2 + 1.1;
const cu = new THREE.Mesh(new THREE.CylinderGeometry(0.85, 0.85, 1.8, 16), M.cuve);
if (f[0] !== 0) cu.position.set(-f[0] * bout, 0.9, Lv / 2 - 1); else cu.position.set(bout, 0.9, -f[1] * (Lv / 2 - 1));
cu.castShadow = true; g.add(cu);
const info = { g, c, eave, rh, Lu, Lv, ite, temoin, f, cu, ch };
if (temoin) {
// gouttière, descente, filtre et pompe : le circuit de la chaîne de l'eau, sur la maison témoin seulement
const cote = cu.position.z >= 0 ? 1 : -1, ze = cote * ((Lv + ite) / 2 + 0.6);
const gout = new THREE.Mesh(new THREE.BoxGeometry(Lu + ite + 1.1, 0.16, 0.2), mat.zinc); gout.position.set(0, eave - 0.2, ze); g.add(gout);
const xd = cu.position.x;
const desc = new THREE.Mesh(new THREE.CylinderGeometry(0.08, 0.08, eave - 1.6, 8), mat.zinc); desc.position.set(Math.max(-(Lu + ite) / 2, Math.min((Lu + ite) / 2, xd)), (eave - 1.6) / 2 + 1.4, ze); g.add(desc);
const filtre = new THREE.Mesh(new THREE.BoxGeometry(0.6, 0.9, 0.2), mat.zinc); filtre.position.set(desc.position.x, 1.0, ze + cote * 0.05); g.add(filtre);
const pompe = new THREE.Mesh(new THREE.BoxGeometry(0.55, 0.45, 0.45), mat.pompe); pompe.position.set(cu.position.x + (cu.position.x > 0 ? -1.2 : 1.2), 0.23, cu.position.z); pompe.castShadow = true; g.add(pompe);
Object.assign(info, { gout, desc, filtre, pompe, ze, xd: desc.position.x });
}
g.updateMatrixWorld(true);
info.chemW = ch.getWorldPosition(new THREE.Vector3()).add(new THREE.Vector3(0, 1.4, 0));
info.cuveW = cu.getWorldPosition(new THREE.Vector3());
transformees.push(info); indexT++;
}
if (estGrand) grand = g;
return g;
}
for (const h of D.maisons) {
if (h.t === 'transformee') { G.v2035.add(maison(h, '2035')); G.vAuj.add(maison(h, 'auj')); }
else scene.add(maison(h, '2035'));
}
const T = transformees[D.temoin.maison];
transformees.forEach((m) => cliquables.push({ o: m.g, fiche: 'chaleur-paille' }));
if (grand) cliquables.push({ o: grand, fiche: 'quartier-communs' });
// ---------------------------------------------------------------- végétal (content/essences.md)
const E = ESSENCES;
const matsHaie = { couronne: new THREE.MeshLambertMaterial({ color: '#ffffff', emissive: '#000000' }), tronc: new THREE.MeshLambertMaterial({ color: PAL.tronc }), fruit: new THREE.MeshLambertMaterial({ color: '#ffffff' }) };
const matsForet = { couronne: new THREE.MeshLambertMaterial({ color: '#ffffff', emissive: '#000000' }), tronc: matsHaie.tronc, fruit: matsHaie.fruit };
const matsAutres = { couronne: new THREE.MeshLambertMaterial({ color: '#ffffff' }), tronc: matsHaie.tronc, fruit: matsHaie.fruit };
const itemsHaies = haiesEssences(D.haies, E);
G.v2035.add(lot(itemsHaies, matsHaie, E.reglages.fruits));
G.v2035.add(lot(vergers(D.vergers, E), matsHaie, E.reglages.fruits));
const parGenre = (k) => D.arbres.filter((a) => a[4] === k);
const med = (L) => { const v = L.map((a) => a[2]).sort((a, b) => a - b); return v[Math.floor(v.length / 2)] || 1; };
const foret = parGenre(1), exist = parGenre(2), buis = parGenre(3);
G.v2035.add(lot(arbresPlan(foret, E, 'foret', 1, med(foret)), matsForet, false));
scene.add(lot(arbresPlan(exist, E, 'arbre existant', 2, med(exist)), matsAutres, false));
scene.add(lot(arbresPlan(buis, E, 'buisson existant', 3, med(buis)), matsAutres, false));
G.vAuj.add(thuyas(D.haies, new THREE.MeshLambertMaterial({ color: PAL.thuya })));
const eauV = plantesEau(D.aqua); G.v2035.add(eauV.groupe);
// les haies du jardin témoin : toutes celles qui passent à moins de 28 m de la maison
const echantillon = (pl, pas = 2) => { const out = []; for (let i = 1; i < pl.length; i++) { const [a, b] = [pl[i - 1], pl[i]], L = Math.hypot(b[0] - a[0], b[1] - a[1]); for (let s = 0; s <= L; s += pas) out.push([a[0] + (b[0] - a[0]) * s / L, a[1] + (b[1] - a[1]) * s / L]); } return out; };
const pres2 = ([x, z]) => Math.hypot(x - T.c.x, z - T.c.y);
const haiesT = new Set(D.haies.map((h, i) => [i, echantillon(h, 1)]).filter(([, pts]) => pts.some((p) => pres2(p) < 28)).map(([i]) => i));
// le potager au pied de ces haies, côté jardin
const ptsPotager = [];
for (const k of haiesT) {
const haieT = D.haies[k];
for (let i = 1; i < haieT.length; i++) {
const [a, b] = [haieT[i - 1], haieT[i]], L = Math.hypot(b[0] - a[0], b[1] - a[1]), tx = (b[0] - a[0]) / L, tz = (b[1] - a[1]) / L;
let nx = -tz, nz = tx; if ((T.c.x - a[0]) * nx + (T.c.y - a[1]) * nz < 0) { nx = -nx; nz = -nz; }
for (let s = 0.5; s < L; s += 0.7) for (const off of [2.3]) {
const x = a[0] + tx * s + nx * off, z = a[1] + tz * s + nz * off;
if (Math.hypot(x - T.c.x, z - T.c.y) < 16 && Math.hypot(x - T.c.x, z - T.c.y) > 6) ptsPotager.push([x, z]);
}
}
}
const imPotager = ptsPotager.length ? potager(ptsPotager) : null;
if (imPotager) G.v2035.add(imPotager);
// ---------------------------------------------------------------- personnages, étals, voitures garées
const geoP = new THREE.CapsuleGeometry(0.28, 0.95, 3, 8);
const PAL_P = PAL.gens.map(C);
const imP = new THREE.InstancedMesh(geoP, new THREE.MeshLambertMaterial({ color: '#ffffff' }), D.persos.length); imP.castShadow = true;
D.persos.forEach(([x, z], i) => { imP.setMatrixAt(i, new THREE.Matrix4().makeTranslation(x, 0.76, z)); imP.setColorAt(i, PAL_P[i % PAL_P.length]); });
imP.instanceColor.needsUpdate = true; G.v2035.add(imP);
const matEtal = PAL.etals.map((c) => new THREE.MeshLambertMaterial({ color: c, emissive: '#000000' }));
const matPoteau = new THREE.MeshLambertMaterial({ color: '#7b6a55' }), matTable = new THREE.MeshLambertMaterial({ color: '#c49a64' });
function axes(pts) {
const p = pts.map(([x, z]) => new THREE.Vector2(x, z)), c = p.reduce((a, b) => a.add(b), new THREE.Vector2()).multiplyScalar(0.25);
const e1 = p[1].clone().sub(p[0]), e2 = p[2].clone().sub(p[1]); const [u, L, W] = e1.length() >= e2.length() ? [e1.clone().normalize(), e1.length(), e2.length()] : [e2.clone().normalize(), e2.length(), e1.length()];
return { c, rot: Math.atan2(-u.y, u.x), L, W };
}
D.etals.forEach((e, i) => {
const a = axes(e.p), g = new THREE.Group(); g.position.set(a.c.x, 0, a.c.y); g.rotation.y = a.rot;
const L = Math.min(a.L, 4.5), W = Math.min(a.W, 3);
const toile = new THREE.Mesh(new THREE.BoxGeometry(L + 0.4, 0.16, W + 0.4), matEtal[i % matEtal.length]); toile.position.y = 2.45; toile.castShadow = true; g.add(toile);
for (const [sx, sz] of [[1, 1], [1, -1], [-1, 1], [-1, -1]]) { const po = new THREE.Mesh(new THREE.CylinderGeometry(0.06, 0.06, 2.45, 5), matPoteau); po.position.set(sx * L / 2, 1.22, sz * W / 2); g.add(po); }
const tb = new THREE.Mesh(new THREE.BoxGeometry(L * 0.9, 0.85, W * 0.45), matTable); tb.position.set(0, 0.42, W * 0.18); tb.castShadow = true; g.add(tb);
G.v2035.add(g); cliquables.push({ o: g, fiche: 'quartier-marche' });
const v = voiture(PAL.autos[i % PAL.autos.length]); v.position.set(a.c.x, 0, a.c.y); v.rotation.y = a.rot + Math.PI / 2; G.vAuj.add(v);
});
// ---------------------------------------------------------------- eau, sentiers : surfaces qui s'allument
const aire = (pts) => Math.abs(pts.reduce((s, p, i) => { const q = pts[(i + 1) % pts.length]; return s + p[0] * q[1] - q[0] * p[1]; }, 0)) / 2;
function surface(pts, couleur, y) {
const sh = new THREE.Shape(pts.map(([x, z]) => new THREE.Vector2(x, -z)));
const g = new THREE.ShapeGeometry(sh).rotateX(-Math.PI / 2);
const m = new THREE.Mesh(g, new THREE.MeshBasicMaterial({ color: couleur, transparent: true, opacity: 0, depthWrite: false }));
m.position.y = y; m.renderOrder = 2; G.v2035.add(m); return m;
}
const surv = { noues: [], bassins: [], sentiers: [], liaisons: [], chemins: [], flux: {}, bulles: [], ondes: [] };
D.noues.forEach((pts, i) => { const m = surface(pts, PAL.eau, 0.08); m.userData.i = i; surv.noues.push(m); cliquables.push({ o: m, fiche: 'eau-noue' }); });
D.plantes.forEach((pts) => { if (pts.length > 3 && aire(pts) > 60) { const m = surface(pts, '#3e9aa3', 0.08); surv.bassins.push(m); cliquables.push({ o: m, fiche: 'eau-mare' }); } });
D.sentiers.forEach((pts) => surv.sentiers.push(surface(pts, PAL.sentier, 0.07)));
// rubans en pointillés qui coulent (liaisons, chemins, liens du hors-champ)
const vs = 'varying vec2 vUv; void main(){ vUv = uv; gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0); }';
const fs = 'uniform float uT; uniform float uA; uniform float uV; uniform float uP; uniform vec3 uC; varying vec2 vUv; void main(){ float d = fract(vUv.x / uP - uT * uV); float t = smoothstep(0.0, 0.08, d) * (1.0 - smoothstep(0.45, 0.55, d)); float e = 1.0 - smoothstep(0.3, 0.5, abs(vUv.y - 0.5)); gl_FragColor = vec4(uC, uA * (0.22 + 0.78 * t) * e);\n#include <colorspace_fragment>\n}';
function ruban(pts, largeur, couleur, vitesse, pas, y, groupe, dessus = true) {
const pos = [], uv = [], idx = []; let L = 0;
for (let i = 0; i < pts.length; i++) {
const [x, z] = pts[i], a = pts[Math.max(0, i - 1)], b = pts[Math.min(pts.length - 1, i + 1)];
let dx = b[0] - a[0], dz = b[1] - a[1]; const n = Math.hypot(dx, dz) || 1; dx /= n; dz /= n;
const rx = -dz * largeur / 2, rz = dx * largeur / 2;
if (i > 0) L += Math.hypot(x - pts[i - 1][0], z - pts[i - 1][1]);
pos.push(x - rx, 0, z - rz, x + rx, 0, z + rz); uv.push(L, 0, L, 1);
if (i > 0) { const k = 2 * i; idx.push(k - 2, k - 1, k, k - 1, k + 1, k); }
}
const g = new THREE.BufferGeometry(); g.setAttribute('position', new THREE.Float32BufferAttribute(pos, 3)); g.setAttribute('uv', new THREE.Float32BufferAttribute(uv, 2)); g.setIndex(idx);
// depthTest désactivé : un ruban allumé est un tracé de diagramme, il passe au-dessus du feuillage
const m = new THREE.ShaderMaterial({ vertexShader: vs, fragmentShader: fs, transparent: true, depthWrite: false, depthTest: !dessus, side: THREE.DoubleSide,
uniforms: { uT: { value: 0 }, uA: { value: 0 }, uV: { value: vitesse }, uP: { value: pas }, uC: { value: new THREE.Color(couleur) } } });
const mesh = new THREE.Mesh(g, m); mesh.position.y = y; mesh.renderOrder = 3; (groupe || G.v2035).add(mesh); return mesh;
}
const sommetsNoues = D.noues.flat();
const dNoue = ([x, z]) => Math.min(...sommetsNoues.map(([a, b]) => (a - x) ** 2 + (b - z) ** 2));
D.liaisons.forEach((l, i) => { const pts = dNoue(l[0]) < dNoue(l[l.length - 1]) ? l.slice().reverse() : l; const r = ruban(pts, 1.0, PAL.eauVive, 0.9, 2.2, 0.14); r.userData.i = i; surv.liaisons.push(r); });
D.chemins.forEach((l) => { let L = 0; for (let i = 1; i < l.length; i++) L += Math.hypot(l[i][0] - l[i - 1][0], l[i][1] - l[i - 1][1]); if (L > 12) surv.chemins.push(ruban(l, 1.1, '#c79528', 0.35, 3.0, 0.13)); });
// ---------------------------------------------------------------- gouttes : pluie, gouttière, pompe, fumée
const disque = (() => { const c = document.createElement('canvas'); c.width = c.height = 64; const x = c.getContext('2d'); const g = x.createRadialGradient(32, 32, 2, 32, 32, 30); g.addColorStop(0, 'rgba(255,255,255,1)'); g.addColorStop(1, 'rgba(255,255,255,0)'); x.fillStyle = g; x.fillRect(0, 0, 64, 64); const t = new THREE.CanvasTexture(c); t.colorSpace = THREE.SRGBColorSpace; return t; })();
const sprite = (couleur, op = 0, dessus = false) => new THREE.Sprite(new THREE.SpriteMaterial({ map: disque, color: couleur, transparent: true, opacity: op, depthWrite: false, depthTest: !dessus }));
// un « filet » : des gouttes qui parcourent un chemin 3D
function filet(chemin, n, taille, couleur, vitesse) {
const pts = chemin.map((p) => new THREE.Vector3(...p)), c = [0];
for (let i = 1; i < pts.length; i++) c.push(c[i - 1] + pts[i].distanceTo(pts[i - 1]));
const L = c[c.length - 1], sp = [];
for (let i = 0; i < n; i++) { const s = sprite(couleur, 0, true); s.scale.setScalar(taille); s.renderOrder = 6; G.v2035.add(s); sp.push(s); }
return { on: false, maj(t) {
sp.forEach((s, i) => {
s.material.opacity = this.on ? 0.9 : 0; if (!this.on) return;
const d = ((t * vitesse + (i / n) * L) % L); let k = 1; while (k < c.length - 1 && c[k] < d) k++;
const a = pts[k - 1], b = pts[k], u = (d - c[k - 1]) / ((c[k] - c[k - 1]) || 1); s.position.lerpVectors(a, b, u);
});
} };
}
const local = (x, y, z) => T.g.localToWorld(new THREE.Vector3(x, y, z)).toArray();
const filets = {};
// pluie sur le toit de la maison témoin
const pluie = [];
for (let i = 0; i < 46; i++) { const s = sprite('#5d9fc7'); s.scale.set(0.22, 0.9, 1); G.v2035.add(s); pluie.push({ s, x: (rnd(i * 3) - 0.5) * (T.Lu + 2), z: (rnd(i * 7) - 0.5) * (T.Lv + 2), ph: rnd(i * 11) }); }
if (T.gout) {
const xe = (T.Lu + T.ite) / 2;
filets.gouttiere = filet([local(-xe, T.eave - 0.1, T.ze), local(T.xd, T.eave - 0.1, T.ze), local(T.xd, 1.45, T.ze), local(T.xd, 1.0, T.ze), local(T.cu.position.x, 1.85, T.cu.position.z)], 14, 0.5, '#3f8fc7', 2.2);
const xp = T.pompe.position.x, mur = T.cu.position.x > 0 ? (T.Lu + T.ite) / 2 : -(T.Lu + T.ite) / 2;
filets.pompe = filet([local(T.cu.position.x, 0.3, T.cu.position.z), local(xp, 0.3, T.cu.position.z), local(mur, 0.4, T.cu.position.z * 0.6), local(mur * 0.6, 1.2, T.cu.position.z * 0.3)], 10, 0.42, '#3f8fc7', 1.4);
}
// les eaux grises : de la maison à la noue, le long de la liaison du plan
{
const l = D.liaisons[D.temoin.liaison];
if (l) {
const d0 = Math.hypot(l[0][0] - T.c.x, l[0][1] - T.c.y), d1 = Math.hypot(l[l.length - 1][0] - T.c.x, l[l.length - 1][1] - T.c.y);
const pts = (d0 <= d1 ? l : l.slice().reverse()).map(([x, z]) => [x, 0.45, z]);
filets['eaux-grises'] = filet([[T.c.x, 0.6, T.c.y], ...pts], 12, 0.55, '#8a9a8c', 1.6);
}
}
const fumee = [];
transformees.forEach((m, k) => { for (let i = 0; i < 6; i++) { const s = sprite('#b9b2a6', 0.5); s.userData = { m, ph: (i + rnd(k * 13 + i)) / 6 }; G.v2035.add(s); fumee.push(s); } });
const MARE = (() => { const p = D.mare; const c = p.reduce((a, q) => [a[0] + q[0] / p.length, a[1] + q[1] / p.length], [0, 0]); return { x: D.canards.c[0] ?? c[0], z: D.canards.c[1] ?? c[1] }; })();
for (let i = 0; i < 3; i++) {
const o = new THREE.Mesh(new THREE.RingGeometry(0.85, 1.15, 48).rotateX(-Math.PI / 2), new THREE.MeshBasicMaterial({ color: PAL.eauVive, transparent: true, opacity: 0, depthWrite: false }));
o.position.set(MARE.x, 0.16, MARE.z); o.userData = { ph: i / 3 }; G.v2035.add(o); surv.ondes.push(o);
}
// ---------------------------------------------------------------- étiquettes (essences de la haie, plantes de la noue, strates)
function etiquette(texte, couleur = '#62560f', taille = 1) {
const c = document.createElement('canvas'); c.width = 512; c.height = 112; const x = c.getContext('2d');
x.font = '600 52px "Barlow Condensed", Barlow, sans-serif'; const w = Math.min(500, x.measureText(texte).width + 44);
x.fillStyle = 'rgba(255,253,246,0.95)'; x.beginPath(); if (x.roundRect) x.roundRect((512 - w) / 2, 8, w, 92, 46); else x.rect((512 - w) / 2, 8, w, 92); x.fill();
x.strokeStyle = couleur; x.lineWidth = 5; x.stroke();
x.fillStyle = couleur; x.textAlign = 'center'; x.textBaseline = 'middle'; x.fillText(texte, 256, 56);
const t = new THREE.CanvasTexture(c); t.colorSpace = THREE.SRGBColorSpace;
const s = new THREE.Sprite(new THREE.SpriteMaterial({ map: t, transparent: true, depthTest: false, opacity: 0 })); s.scale.set(5.6 * taille, 1.23 * taille, 1); s.renderOrder = 12;
return s;
}
const etiquettes = { 'haie-essences': [], 'noue-plantes': [], strates: [], paturage: [] };
const pres = (it) => Math.hypot(it.x - T.c.x, it.z - T.c.y);
itemsHaies.filter((it) => haiesT.has(it.haie) && it.strate === "arbre").sort((a, b) => pres(a) - pres(b)).slice(0, 8)
.forEach((it) => { const s = etiquette(it.nom); s.position.set(it.x, it.haut + 1.1, it.z); G.v2035.add(s); etiquettes['haie-essences'].push(s); });
const noueT = D.noues[D.temoin.noue];
if (noueT) {
const dans = (x, z) => { let c = false; for (let i = 0, j = noueT.length - 1; i < noueT.length; j = i++) { const [xi, zi] = noueT[i], [xj, zj] = noueT[j]; if ((zi > z) !== (zj > z) && x < ((xj - xi) * (z - zi)) / (zj - zi) + xi) c = !c; } return c; };
// une étiquette par plante présente, posée sur la plante la plus éloignée des étiquettes déjà posées (pas de chevauchement)
const dansNoue = D.aqua.filter((p) => dans(p[0], p[1])).sort((a, b) => Math.hypot(a[0] - T.c.x, a[1] - T.c.y) - Math.hypot(b[0] - T.c.x, b[1] - T.c.y)).slice(0, 40), poses = [];
for (const type of [...new Set(dansNoue.map((p) => p[2]))]) {
const cand = dansNoue.filter((p) => p[2] === type);
const p = cand.reduce((m, q) => { const d = (r) => Math.min(99, ...poses.map((o) => Math.hypot(o[0] - r[0], o[1] - r[1]))); return d(q) > d(m) ? q : m; }, cand[0]);
poses.push(p);
const s = etiquette(NOMS_AQUA[type], '#1d5886', 0.8); s.position.set(p[0], 2.0 + (poses.length % 3) * 1.15, p[1]); G.v2035.add(s); etiquettes["noue-plantes"].push(s);
}
}
{
const a = itemsHaies.filter((it) => haiesT.has(it.haie) && it.strate === "arbre").sort((x, y) => pres(x) - pres(y))[0];
const b = itemsHaies.filter((it) => haiesT.has(it.haie) && it.strate === "arbuste").sort((x, y) => pres(x) - pres(y))[0];
const p = ptsPotager.length ? ptsPotager.reduce((m, q) => (Math.hypot(q[0] - T.c.x, q[1] - T.c.y) < Math.hypot(m[0] - T.c.x, m[1] - T.c.y) ? q : m)) : null;
if (a) { const s = etiquette('arbres · 5 ans'); s.position.set(a.x, a.haut + 1.2, a.z); etiquettes.strates.push(s); }
if (b) { const s = etiquette('arbustes · 2 à 3 ans'); s.position.set(b.x, b.haut + 2.4, b.z); etiquettes.strates.push(s); }
if (p) { const s = etiquette('légumes · 1 an'); s.position.set(p[0], 2.2, p[1]); etiquettes.strates.push(s); }
etiquettes.strates.forEach((s) => G.v2035.add(s));
}
// ---------------------------------------------------------------- animaux
const vie = vieAnimale(D, G.v2035);
anim.push(...vie.anim);
if (D.troupeaux.length) {
const [x, z] = D.troupeaux[0]; const s = etiquette('moutons et chèvres'); s.position.set(x, 3.4, z); G.v2035.add(s); etiquettes.paturage.push(s);
}
// le chantier-école : des voisins autour de la maison témoin
const chantier = new THREE.Group(); chantier.visible = false; G.v2035.add(chantier);
for (let i = 0; i < 6; i++) {
const a = (i / 6) * Math.PI * 2 + 0.4, r = Math.max(T.Lu, T.Lv) / 2 + 2.2;
const p = new THREE.Mesh(geoP, new THREE.MeshLambertMaterial({ color: PAL.gens[(i + 2) % PAL.gens.length] })); p.position.set(T.c.x + Math.cos(a) * r, 0.76, T.c.y + Math.sin(a) * r); p.castShadow = true;
const casque = new THREE.Mesh(new THREE.SphereGeometry(0.2, 8, 5, 0, Math.PI * 2, 0, Math.PI / 2), new THREE.MeshLambertMaterial({ color: '#e0b23a' })); casque.position.set(p.position.x, 1.55, p.position.z);
chantier.add(p, casque);
}
const botte = new THREE.Mesh(new THREE.BoxGeometry(1.1, 0.45, 0.5), new THREE.MeshLambertMaterial({ color: PAL.paille }));
for (let i = 0; i < 8; i++) { const b = botte.clone(); b.position.set(T.c.x + (T.Lu / 2 + 3.2) * (i < 4 ? 1 : -1) * 0.9, 0.23 + Math.floor((i % 4) / 2) * 0.46, T.c.y + ((i % 2) - 0.5) * 1.2); b.castShadow = true; chantier.add(b); }
// ---------------------------------------------------------------- véhicules, vélos, attelage, marcheurs
function trajet(pts) { const c = [0]; for (let i = 1; i < pts.length; i++) c.push(c[i - 1] + Math.hypot(pts[i][0] - pts[i - 1][0], pts[i][1] - pts[i - 1][1])); return { pts, c, L: c[c.length - 1] }; }
function surTrajet(t, s) {
s = Math.max(0, Math.min(t.L, s)); let i = 1; while (i < t.c.length - 1 && t.c[i] < s) i++;
const a = t.pts[i - 1], b = t.pts[i], k = (s - t.c[i - 1]) / ((t.c[i] - t.c[i - 1]) || 1);
return { x: a[0] + (b[0] - a[0]) * k, z: a[1] + (b[1] - a[1]) * k, dx: b[0] - a[0], dz: b[1] - a[1] };
}
const mobiles = [];
const tr = {}; for (const k in D.routes) tr[k] = trajet(D.routes[k]);
const cheminsLongs = D.chemins.map(trajet).filter((t) => t.L > 40).sort((a, b) => b.L - a.L);
const ajoute = (obj, t, vitesse, decal, depart, groupe, role) => { groupe.add(obj); const m = { obj, t, v: vitesse, d: decal, s: depart * t.L, sens: 1, role }; mobiles.push(m); return m; };
ajoute(velo(PAL.gens[0]), tr.principale, 4.2, 2.8, 0.1, G.v2035, 'velo'); ajoute(velo(PAL.gens[3]), tr.principale, 3.8, -2.6, 0.65, G.v2035, 'velo');
ajoute(velo(PAL.gens[1]), tr.verticale, 4.0, 2.2, 0.4, G.v2035, 'velo'); ajoute(velo(PAL.gens[4]), tr.anneau, 3.5, 2.0, 0.2, G.v2035, 'velo');
ajoute(veloCargo(PAL.gens[2]), tr.principale, 3.2, -2.4, 0.3, G.v2035, 'cargo'); ajoute(veloCargo(PAL.gens[5]), tr.verticale, 3.0, -2.0, 0.75, G.v2035, 'cargo');
ajoute(attelage(), tr.principale, 1.6, 2.2, 0.55, G.v2035, 'attelage');
ajoute(voiture('#7fa3a6', true), tr.principale, 7, 1.8, 0.85, G.v2035, 'partagee');
if (cheminsLongs[0]) ajoute(velo(PAL.gens[6]), cheminsLongs[0], 3.2, 0, 0.3, G.v2035, 'velo');
const marcheurs = cheminsLongs.slice(0, 5).map((t, i) => { const p = new THREE.Mesh(geoP, new THREE.MeshLambertMaterial({ color: PAL.gens[(i + 3) % PAL.gens.length] })); p.castShadow = true; const g = new THREE.Group(); p.position.y = 0.76; g.add(p); return ajoute(g, t, 1.3, 0, rnd(i + 3), G.v2035, 'marcheur'); });
marcheurs.slice(0, 2).forEach((m) => { const c = chien(); G.v2035.add(c); mobiles.push({ obj: c, suit: m, d: 0.9 }); });
[['principale', 0.05], ['principale', 0.35], ['principale', 0.7], ['verticale', 0.2], ['verticale', 0.6], ['liaison_anneau', 0.5], ['anneau', 0.3], ['droite', 0.5]]
.forEach(([k, d], i) => ajoute(voiture(PAL.autos[(i + 1) % PAL.autos.length]), tr[k], 9, 1.8, d, G.vAuj, 'auto'));
// ---------------------------------------------------------------- bulles de la planche 2030 (dessins de Jules, p. 15)
const VERT = new Set(['pomme', 'abeille', 'fleur', 'arbre', 'oiseaux']);
const matTige = { v: new THREE.MeshLambertMaterial({ color: '#9db878' }), q: new THREE.MeshLambertMaterial({ color: '#d9a866' }) };
const geoTige = new THREE.CylinderGeometry(0.1, 0.1, 1, 6).translate(0, 0.5, 0);
D.bulles.forEach((b, i) => {
const [x, z] = b.w, vert = VERT.has(b.id);
const tige = new THREE.Mesh(geoTige, vert ? matTige.v : matTige.q); tige.position.set(x, 0, z); tige.scale.y = 8.4; G.v2035.add(tige);
const t = chargeur.load(BULLES[b.id], () => (besoin = true)); t.colorSpace = THREE.SRGBColorSpace;
const s = new THREE.Sprite(new THREE.SpriteMaterial({ map: t, transparent: true, depthTest: false }));
const petit = b.id.startsWith('apaise'); s.scale.set(petit ? 3.4 : 6.4, petit ? 3.4 : 6.4, 1); s.position.set(x, petit ? 7.4 : 10.4, z); s.renderOrder = 10;
s.userData = { id: b.id, base: s.position.y, ph: rnd(i) * 6.28, taille: s.scale.x }; G.v2035.add(s); surv.bulles.push(s);
});
// ---------------------------------------------------------------- hors-champ : les grandes infrastructures et leurs liens
const matI = (c) => new THREE.MeshLambertMaterial({ color: c });
function panneau(texte, couleur) {
const c = document.createElement('canvas'); c.width = 640; c.height = 120; const x = c.getContext('2d');
x.fillStyle = 'rgba(255,253,246,0.94)'; x.beginPath(); if (x.roundRect) x.roundRect(4, 4, 632, 112, 22); else x.rect(4, 4, 632, 112); x.fill(); x.strokeStyle = couleur; x.lineWidth = 5; x.stroke();
x.fillStyle = '#102a3a'; x.font = '600 50px "Barlow Condensed", Barlow, sans-serif'; x.textAlign = 'center'; x.textBaseline = 'middle'; x.fillText(texte, 320, 62);
const t = new THREE.CanvasTexture(c); t.colorSpace = THREE.SRGBColorSpace;
const s = new THREE.Sprite(new THREE.SpriteMaterial({ map: t, transparent: true, depthTest: false })); s.scale.set(64, 12, 1); s.renderOrder = 9; return s;
}
const INFRA = [
{ k: 'centrale', n: 'Centrale, gaz importé', c: '#c96d0c', x: -130, z: -330, sys: 'chaleur' },
{ k: 'potab', n: 'Puisement, potabilisation', c: '#3a74a8', x: 170, z: -300, sys: 'eau' },
{ k: 'agri', n: 'Agriculture industrielle · 850 km', c: '#8f7b22', x: 360, z: -40, sys: 'vivant' },
{ k: 'step', n: "Station d'épuration", c: '#3a74a8', x: 110, z: 300, sys: 'eau' },
{ k: 'super', n: 'Supermarché', c: '#8a5a7a', x: -230, z: 260, sys: 'quartier' },
{ k: 'ciment', n: 'Gravière, cimenterie', c: '#c96d0c', x: -380, z: 70, sys: 'chaleur' },
{ k: 'emploi', n: "Bassin d'emploi", c: '#6b6458', x: -400, z: -200, sys: 'travail' },
];
const HC = new THREE.Group(); HC.position.y = -2.3; scene.add(HC);
for (const f of INFRA) {
const g = new THREE.Group(); g.position.set(f.x, 0, f.z);
const add = (geo, m, x, y, z) => { const o = new THREE.Mesh(geo, m); o.position.set(x, y, z); o.castShadow = true; g.add(o); return o; };
if (f.k === 'centrale') { add(new THREE.CylinderGeometry(8, 12, 34, 24), matI('#dcd6ca'), -12, 17, 0); add(new THREE.CylinderGeometry(8, 12, 34, 24), matI('#dcd6ca'), 14, 17, 8); add(new THREE.BoxGeometry(16, 14, 16), matI('#c9c3b7'), 2, 7, -22); }
if (f.k === 'potab') { add(new THREE.CylinderGeometry(2.5, 2.5, 26, 12), matI('#d3cec4'), 0, 13, 0); add(new THREE.CylinderGeometry(9, 6, 8, 20), matI('#c4d6df'), 0, 30, 0); }
if (f.k === 'agri') { for (let i = 0; i < 6; i++) add(new THREE.BoxGeometry(120, 0.3, 16), matI(['#dcd49a', '#cdd59f', '#e2d29a'][i % 3]), 0, 0.15, -48 + i * 17); for (let i = 0; i < 3; i++) add(new THREE.CylinderGeometry(4, 4, 22, 14), matI('#cdc7bb'), -70, 11, -12 + i * 10); }
if (f.k === 'step') { for (let i = 0; i < 3; i++) { add(new THREE.CylinderGeometry(12, 12, 2.4, 32), matI('#c9c5bd'), -30 + i * 28, 1.2, 0); add(new THREE.CylinderGeometry(11, 11, 0.2, 32), matI('#a7c8d6'), -30 + i * 28, 2.45, 0); } }
if (f.k === 'super') { add(new THREE.BoxGeometry(72, 9, 44), matI('#e2dbcd'), 0, 4.5, 0); add(new THREE.BoxGeometry(90, 0.2, 42), matI('#d3cfc6'), 0, 0.1, 48); }
if (f.k === 'ciment') { add(new THREE.ConeGeometry(14, 11, 18), matI('#cfbd9d'), -14, 5.5, 8); add(new THREE.ConeGeometry(10, 8, 18), matI('#c7b48f'), 14, 4, 16); add(new THREE.CylinderGeometry(4, 4, 34, 14), matI('#bdb6aa'), 6, 17, -14); }
if (f.k === 'emploi') { add(new THREE.BoxGeometry(16, 44, 16), matI('#cfd3d8'), -12, 22, 0); add(new THREE.BoxGeometry(14, 30, 14), matI('#c3c8ce'), 12, 15, 10); add(new THREE.BoxGeometry(12, 22, 12), matI('#d8dbe0'), 6, 11, -16); }
const e = panneau(f.n, f.c); e.position.set(0, 58, 0); g.add(e);
HC.add(g);
const pts = []; const cx = f.x * 0.45 + (f.z > 0 ? 30 : -30), cz = f.z * 0.45;
for (let i = 0; i <= 40; i++) { const t = i / 40, a = (1 - t) * (1 - t), b = 2 * (1 - t) * t, c = t * t; pts.push([a * f.x + b * cx + c * MARE.x, a * f.z + b * cz + c * MARE.z]); }
surv.flux[f.k] = { r: ruban(pts, 4, f.c, 0.35, 14, 0.2, HC, false), sys: f.sys };
}
// ---------------------------------------------------------------- cadrages nommés
const P = (x, y) => ({ x: (x - D.W / 2) / D.s, z: (y - D.H / 2) / D.s });
function boite(pts, marge = 1.3, min = 30) {
let x0 = Infinity, x1 = -Infinity, z0 = Infinity, z1 = -Infinity;
for (const [x, z] of pts) { x0 = Math.min(x0, x); x1 = Math.max(x1, x); z0 = Math.min(z0, z); z1 = Math.max(z1, z); }
return { x: (x0 + x1) / 2, z: (z0 + z1) / 2, dx: x1 - x0, dz: z1 - z0, marge, min };
}
const ptsMaisonT = [[T.c.x - T.Lu / 2 - 3, T.c.y - T.Lv / 2 - 3], [T.c.x + T.Lu / 2 + 3, T.c.y + T.Lv / 2 + 3], ...(D.liaisons[D.temoin.liaison] || [])];
const bassinsPts = D.plantes.filter((p) => p.length > 3 && aire(p) > 60).flat();
const prochesHaie = [...haiesT].flatMap((k) => echantillon(D.haies[k])).filter((p) => pres2(p) < 20);
// la caméra des cadrages de la maison témoin regarde depuis le côté de sa noue : la chaîne de l'eau se lit au premier plan
const cN = noueT ? noueT.reduce((a, p) => [a[0] + p[0] / noueT.length, a[1] + p[1] / noueT.length], [0, 0]) : [T.c.x, T.c.y + 1];
const azT = Math.atan2(cN[0] - T.c.x, cN[1] - T.c.y) * 0.75; // trois quarts du chemin vers la noue : la façade sud reste lisible
const T_ = (c) => ({ ...c, az: azT });
const CAD = {
quartier: { x: 0, z: 2, w: 215 },
maison: T_(boite(ptsMaisonT, 1.25, 34)),
jardin: T_(boite([...ptsMaisonT, ...prochesHaie, ...(noueT || [])], 1.15, 46)),
haie: T_(boite(prochesHaie.length ? [...prochesHaie, [T.c.x, T.c.y]] : ptsMaisonT, 1.15, 36)),
noue: T_(boite(noueT && noueT.some((p) => pres2(p) < 22) ? [...noueT.filter((p) => pres2(p) < 22), [T.c.x, T.c.y]] : ptsMaisonT, 1.3, 30)),
mare: boite([...D.mare, ...bassinsPts], 1.12, 60),
bassins: boite(bassinsPts.length ? bassinsPts : D.mare, 1.3, 40),
place: { ...P(505, 300), w: 56 },
grand: grand ? { x: grand.position.x, z: grand.position.z, w: 62 } : { ...P(330, 540), w: 62 },
foret: { ...P(1470, 330), w: 120 },
routes: { ...P(720, 520), w: 130 },
sentiers: { ...P(1330, 800), w: 110 },
horscamp: { x: -60, z: -40, w: 640 },
transformees: boite(transformees.map((m) => [m.c.x, m.c.y]), 1.2, 120),
paturage: (() => {
// le troupeau le plus proche de la maison témoin, et ses poules
const groupes = {}; for (const t of D.troupeaux) (groupes[t[4] ?? 0] ??= []).push([t[0], t[1]]);
const G_ = Object.values(groupes); if (!G_.length) return { x: 0, z: 0, w: 120 };
const c = (L) => L.reduce((a, p) => [a[0] + p[0] / L.length, a[1] + p[1] / L.length], [0, 0]);
const g = G_.reduce((m, L) => (Math.hypot(c(L)[0] - T.c.x, c(L)[1] - T.c.y) < Math.hypot(c(m)[0] - T.c.x, c(m)[1] - T.c.y) ? L : m));
return boite(g, 1.8, 34);
})(),
};
CAD.toit = CAD.maison;
// ---------------------------------------------------------------- caméra : axonométrie orthographique, pilotable au doigt
const vue = { x: 0, z: 0, az: 0, el: 0.62, w: 210 };
let vol = null, cadrageCourant = null, derive = 0;
const taille = () => ({ W: canvas.clientWidth, H: canvas.clientHeight });
function place() {
const { W, H } = taille(), a = W / H, vh = vue.w / a;
cam.left = -vue.w / 2; cam.right = vue.w / 2; cam.top = vh / 2; cam.bottom = -vh / 2; cam.updateProjectionMatrix();
const d = 1500; cam.position.set(vue.x + Math.sin(vue.az) * Math.cos(vue.el) * d, Math.sin(vue.el) * d, vue.z + Math.cos(vue.az) * Math.cos(vue.el) * d);
cam.lookAt(vue.x, 0, vue.z);
}
let panneau_ = () => ({ bas: 0, gauche: 0 });
function largeur(c) {
if (c.w) return c.w;
const { W, H } = taille(), a = W / H;
return Math.max(c.min, Math.max(c.dx, c.dz * Math.sin(vue.el) * a) * c.marge);
}
function cadrer(nom, duree = 1600, force = false) {
const c = CAD[nom] || CAD.quartier;
if (!force && nom === cadrageCourant) return;
cadrageCourant = nom;
const { W, H } = taille(); let w = largeur(c);
if (W < H && w < 400) w *= 0.8; // en portrait, la largeur de l'écran est la dimension qui manque
// le panneau des fiches cache une partie de l'écran : le cadrage se fait dans la zone libre, et la cible s'y décale
const p = panneau_();
if (p.gauche > 0) w *= W / Math.max(240, W - p.gauche);
const wpp = w / W;
const offX = (p.gauche / 2) * wpp, offY = ((p.bas - 64) / 2) * wpp / Math.sin(vue.el);
const rx = Math.cos(vue.az), rz = -Math.sin(vue.az), fx = -Math.sin(vue.az), fz = -Math.cos(vue.az);
// azimut du cadrage (0 = la planche dans son sens) ; on tourne par le plus court chemin
let az = c.az ?? 0; while (az - vue.az > Math.PI) az -= 2 * Math.PI; while (az - vue.az < -Math.PI) az += 2 * Math.PI;
const ra = Math.cos(az), rza = -Math.sin(az), fa = -Math.sin(az), fza = -Math.cos(az);
const apres = { x: c.x - ra * offX - fa * offY, z: c.z - rza * offX - fza * offY, az, el: vue.el, w };
if (reduit || duree === 0) { Object.assign(vue, apres); besoin = true; return; }
vol = { avant: { ...vue }, apres, t0: performance.now(), d: duree };
}
const bornes = () => { vue.w = Math.max(14, Math.min(1000, vue.w)); vue.x = Math.max(-450, Math.min(450, vue.x)); vue.z = Math.max(-450, Math.min(450, vue.z)); };
function solSous(px, py) {
const { W, H } = taille(), wpp = vue.w / W, sx = px - W / 2, sy = py - H / 2;
const rx = Math.cos(vue.az), rz = -Math.sin(vue.az), fx = -Math.sin(vue.az), fz = -Math.cos(vue.az), k = wpp / Math.sin(vue.el);
return { x: vue.x + rx * sx * wpp - fx * sy * k, z: vue.z + rz * sx * wpp - fz * sy * k };
}
function zoomVers(px, py, f) { const p = solSous(px, py); vue.w *= f; vue.x = p.x + (vue.x - p.x) * f; vue.z = p.z + (vue.z - p.z) * f; bornes(); besoin = true; cadrageCourant = null; }
const ptrs = new Map(); let geste = null;
canvas.addEventListener('pointerdown', (e) => { canvas.setPointerCapture(e.pointerId); ptrs.set(e.pointerId, { x: e.clientX, y: e.clientY }); geste = { t: performance.now(), bouge: 0 }; vol = null; canvas.classList.add('tire'); onToucher('geste'); });
canvas.addEventListener('pointermove', (e) => {
if (!ptrs.has(e.pointerId)) return;
const avant = [...ptrs.values()].map((p) => ({ ...p })); ptrs.set(e.pointerId, { x: e.clientX, y: e.clientY }); const apres = [...ptrs.values()];
const { W } = taille(), wpp = vue.w / W;
const cA = avant.reduce((a, p) => ({ x: a.x + p.x / avant.length, y: a.y + p.y / avant.length }), { x: 0, y: 0 });
const cB = apres.reduce((a, p) => ({ x: a.x + p.x / apres.length, y: a.y + p.y / apres.length }), { x: 0, y: 0 });
const dx = cB.x - cA.x, dy = cB.y - cA.y; if (geste) geste.bouge += Math.abs(dx) + Math.abs(dy);
const rx = Math.cos(vue.az), rz = -Math.sin(vue.az), fx = -Math.sin(vue.az), fz = -Math.cos(vue.az), k = wpp / Math.sin(vue.el);
vue.x -= rx * dx * wpp - fx * dy * k; vue.z -= rz * dx * wpp - fz * dy * k; cadrageCourant = null;
if (apres.length === 2 && avant.length === 2) {
const dA = Math.hypot(avant[0].x - avant[1].x, avant[0].y - avant[1].y), dB = Math.hypot(apres[0].x - apres[1].x, apres[0].y - apres[1].y);
if (dA > 0 && dB > 0) zoomVers(cB.x, cB.y, dA / dB);
const aA = Math.atan2(avant[1].y - avant[0].y, avant[1].x - avant[0].x), aB = Math.atan2(apres[1].y - apres[0].y, apres[1].x - apres[0].x);
let da = aB - aA; if (da > Math.PI) da -= 2 * Math.PI; if (da < -Math.PI) da += 2 * Math.PI; vue.az -= da;
}
bornes(); besoin = true;
});
const fin = (e) => {
ptrs.delete(e.pointerId); if (!ptrs.size) canvas.classList.remove('tire');
if (geste && !ptrs.size && geste.bouge < 8 && performance.now() - geste.t < 450) toucher(e.clientX, e.clientY);
if (!ptrs.size) geste = null;
};
canvas.addEventListener('pointerup', fin); canvas.addEventListener('pointercancel', fin);
canvas.addEventListener('wheel', (e) => { e.preventDefault(); vol = null; zoomVers(e.clientX, e.clientY, e.deltaY > 0 ? 1.12 : 1 / 1.12); onToucher('geste'); }, { passive: false });
const ray = new THREE.Raycaster();
const LIENS_BULLES = { marche: 'quartier-marche', pomme: 'vivant-haie', abeille: 'vivant-foret', miel: 'vivant-foret', fleur: 'vivant-foret', arbre: 'vivant-strates', biere: 'quartier-communs', couverts: 'quartier-communs', outils: 'chaleur-ensemble', oiseaux: 'eau-mare', promeneurs: 'vivant-sentier', enfant: 'quartier-mobilite', confiture: 'vivant-nourrir', bouteille: 'vivant-nourrir', apaise1: 'quartier-mobilite', apaise2: 'quartier-mobilite' };
function toucher(px, py) {
if (!G.v2035.visible) return;
const { W, H } = taille(); ray.setFromCamera(new THREE.Vector2((px / W) * 2 - 1, -(py / H) * 2 + 1), cam);
const hb = ray.intersectObjects(surv.bulles, false)[0];
if (hb) { onToucher('bulle', hb.object.userData.id, LIENS_BULLES[hb.object.userData.id] || null); return; }
const hits = ray.intersectObjects(cliquables.map((c) => c.o), true);
if (hits.length) { const o = hits[0].object; const c = cliquables.find((c) => { let x = o; while (x) { if (x === c.o) return true; x = x.parent; } return false; }); if (c) onToucher('fiche', c.fiche); }
}
// ---------------------------------------------------------------- état : époque, effet
const etat = { epoque: '2035', fx: null, auj: 0, cibleAuj: 0, fond: false };
function epoque(e) { etat.epoque = e; etat.cibleAuj = e === 'auj' ? 1 : 0; G.v2035.visible = e === '2035'; G.vAuj.visible = e === 'auj'; besoin = true; }
function effet(nom) { etat.fx = nom || null; chantier.visible = nom === 'chantier'; besoin = true; }
function tourner() { vol = { avant: { ...vue }, apres: { ...vue, az: vue.az + Math.PI / 2 }, t0: performance.now(), d: reduit ? 0 : 900 }; cadrageCourant = null; }
// ---------------------------------------------------------------- boucle
const horloge = new THREE.Clock(); let t = 0;
const ease = (k) => (k < 0.5 ? 4 * k * k * k : 1 - Math.pow(-2 * k + 2, 3) / 2);
function redim() { const { W, H } = taille(); renderer.setSize(W, H, false); besoin = true; }
addEventListener('resize', redim); redim();
const pulseEm = (m, on, r, g, b, puls) => m.emissive.setRGB(on ? r * puls : 0, on ? g * puls : 0, on ? b * puls : 0);
function boucle(now) {
requestAnimationFrame(boucle);
if (document.hidden) return;
const dt = Math.min(0.05, horloge.getDelta()); t += dt;
if (vol) { const k = Math.min(1, (now - vol.t0) / (vol.d || 1)), e = ease(k); for (const key of ['x', 'z', 'az', 'el', 'w']) vue[key] = vol.avant[key] + (vol.apres[key] - vol.avant[key]) * e; if (k >= 1) vol = null; }
if (etat.fond && !vol && !reduit) vue.az += dt * 0.025 * derive;
etat.auj += (etat.cibleAuj - etat.auj) * Math.min(1, dt * 4); matAuj.opacity = etat.auj;
const puls = 0.5 + 0.5 * Math.sin(t * 2.6), fx = etat.fx;
const eauT = (i) => i === D.temoin.noue;
surv.noues.forEach((m) => (m.material.opacity = fx === 'noue-plantes' ? (eauT(m.userData.i) ? 0.3 + 0.3 * puls : 0.12) : fx === 'mare' || fx === 'phyto' ? 0.22 : fx === 'eaux-grises' && eauT(m.userData.i) ? 0.3 : 0));
surv.bassins.forEach((m) => (m.material.opacity = fx === 'mare' || fx === 'phyto' ? 0.3 + 0.3 * puls : 0));
surv.sentiers.forEach((m) => (m.material.opacity = fx === 'sentiers' ? 0.3 + 0.35 * puls : 0));
surv.liaisons.forEach((m) => { m.material.uniforms.uT.value = t; m.material.uniforms.uA.value = fx === 'eaux-grises' ? (m.userData.i === D.temoin.liaison ? 0.95 : 0.12) : fx === 'mare' ? 0.35 : 0; });
surv.chemins.forEach((m) => { m.material.uniforms.uT.value = t; m.material.uniforms.uA.value = fx === 'sentiers' || fx === 'mobilite' ? 0.9 : fx === 'foret' ? 0.5 : 0; });
for (const k in surv.flux) {
const f = surv.flux[k], u = f.r.material.uniforms; u.uT.value = t;
const tendu = etat.epoque === 'auj' || f.sys === 'travail', vise = fx === 'flux' || (fx === 'travail' && f.sys === 'travail');
u.uA.value = tendu ? (vise ? 0.95 : 0.7) : (vise ? 0.22 : 0); u.uV.value = tendu ? 0.45 : 0.05;
}
const vivant = fx === 'haie-essences' || fx === 'strates' || fx === 'nourrir';
pulseEm(matsHaie.couronne, vivant, 0.1, 0.2, 0.02, puls);
pulseEm(matsForet.couronne, fx === 'foret', 0.08, 0.18, 0.04, puls);
pulseEm(mat.paille, fx === 'transformees', 0.26, 0.16, 0, puls);
pulseEm(matT.paille, fx === 'paille' || fx === 'chantier' || fx === 'transformees', 0.26, 0.16, 0, puls);
pulseEm(matT.verre, fx === 'serre', 0.3, 0.25, 0.05, puls);
pulseEm(matT.cuve, fx === 'cuve' || fx === 'pompe', 0.05, 0.22, 0.4, puls);
pulseEm(matT.chem, fx === 'poele', 0.35, 0.12, 0, puls);
pulseEm(mat.pompe, fx === 'pompe', 0.05, 0.25, 0.45, puls);
pulseEm(mat.grandToit, fx === 'communs', 0.35, 0.12, 0, puls);
matEtal.forEach((m) => pulseEm(m, fx === 'marche', 0.25, 0.14, 0, puls));
if (imPotager) pulseEm(imPotager.material, fx === 'strates' || fx === 'nourrir', 0.15, 0.12, 0, puls);
eauV.meshes.forEach((m) => pulseEm(m.material, fx === 'noue-plantes' || fx === 'phyto', 0.06, 0.12, 0.08, puls));
const zoom = Math.max(0.55, Math.min(1.6, vue.w / 60));
for (const [k, L] of Object.entries(etiquettes)) L.forEach((s) => { s.material.opacity += ((fx === k ? 1 : 0) - s.material.opacity) * Math.min(1, dt * 5); s.visible = s.material.opacity > 0.02; s.scale.set(5.6 * zoom * (k === 'noue-plantes' ? 0.8 : 1), 1.23 * zoom * (k === 'noue-plantes' ? 0.8 : 1), 1); });
pluie.forEach((p) => {
const on = fx === 'pluie-toit'; p.s.material.opacity = on ? 0.75 : 0; if (!on) return;
const k = (t * 0.7 + p.ph) % 1; p.s.position.copy(T.g.localToWorld(new THREE.Vector3(p.x, T.eave + T.rh + 0.4 + (1 - k) * 12, p.z)));
});
if (filets.gouttiere) { filets.gouttiere.on = fx === 'gouttiere'; filets.gouttiere.maj(t); }
if (filets.pompe) { filets.pompe.on = fx === 'pompe'; filets.pompe.maj(t); }
if (filets['eaux-grises']) { filets['eaux-grises'].on = fx === 'eaux-grises'; filets['eaux-grises'].maj(t); }
fumee.forEach((s) => {
const k = (t * 0.12 + s.userData.ph) % 1, m = s.userData.m; s.position.set(m.chemW.x - k * 5, m.chemW.y + k * 9, m.chemW.z - k * 2.5);
const fort = fx === 'poele' && m.temoin, sc = (fort ? 1.6 : 1.2) + k * 4.5; s.scale.set(sc, sc, 1); s.material.opacity = (fort ? 0.8 : 0.45) * (1 - k) * Math.min(1, k * 6);
});
surv.ondes.forEach((o) => { const k = (t * 0.35 + o.userData.ph) % 1, on = fx === 'mare' || fx === 'phyto'; o.scale.setScalar(1 + k * 11); o.material.opacity = on ? 0.6 * (1 - k) : 0; });
const lieesA = { marche: ['marche', 'musique'], 'haie-essences': ['pomme'], nourrir: ['pomme', 'confiture', 'bouteille', 'marche'], foret: ['abeille', 'miel', 'fleur', 'arbre'], communs: ['biere', 'couverts', 'outils'], mare: ['oiseaux', 'musique'], sentiers: ['promeneurs'], mobilite: ['enfant', 'promeneurs', 'apaise1', 'apaise2', 'ballons'], chantier: ['outils'] }[fx] || [];
const zb = Math.max(0.32, Math.min(1, vue.w / 150)); // en gros plan, les bulles se font petites : elles ne masquent plus la maison
surv.bulles.forEach((s) => { const u = s.userData, on = lieesA.includes(u.id), k = (on ? 1.35 : 1) * zb; s.position.y = u.base + Math.sin(t * 1.4 + u.ph) * 0.35; s.scale.set(u.taille * k, u.taille * k, 1); s.material.opacity = (fx === 'haie-essences' || fx === 'noue-plantes' || fx === 'strates') && !on ? 0.25 : lieesA.length && !on ? 0.55 : 1; });
anim.forEach((f) => f(t));
vie.troupeau.children.forEach((o, i) => { o.position.y = fx === 'paturage' ? Math.abs(Math.sin(t * 3 + i)) * 0.25 : 0; });
mobiles.forEach((m) => {
if (m.suit) { const s = m.suit; m.obj.visible = s.obj.parent.visible; const p = surTrajet(s.t, s.s - s.sens * m.d); m.obj.position.set(p.x + 0.5, 0, p.z + 0.4); m.obj.rotation.y = s.obj.rotation.y; return; }
if (!m.obj.parent.visible) return; m.s += m.v * dt * m.sens; if (m.s > m.t.L) { m.s = m.t.L; m.sens = -1; } if (m.s < 0) { m.s = 0; m.sens = 1; }
const p = surTrajet(m.t, m.s); let dx = p.dx * m.sens, dz = p.dz * m.sens; const n = Math.hypot(dx, dz) || 1; dx /= n; dz /= n;
m.obj.position.set(p.x - dz * m.d, 0, p.z + dx * m.d); m.obj.rotation.y = Math.atan2(-dz, dx);
});
const vMob = fx === 'mobilite' || fx === 'travail';
mobiles.forEach((m) => { if (m.role && m.obj.children) { const k = vMob && (m.role === 'cargo' || m.role === 'attelage' || (fx === 'travail' && m.role === 'partagee')) ? 1.25 : 1; m.obj.scale.setScalar(k); } });
place(); renderer.render(scene, cam); besoin = false;
}
epoque('2035'); // le groupe « aujourd'hui » (voitures garées, thuyas) est caché dès le départ
place(); requestAnimationFrame(boucle);
return {
cadrer, effet, epoque, tourner,
poserPanneau(f) { panneau_ = f; },
fond(on, d = 1) { etat.fond = on; derive = d; },
cadrages: Object.keys(CAD),
apercu() { renderer.render(scene, cam); return renderer.domElement.toDataURL('image/jpeg', 0.86); },
};
}
+133
View File
@@ -0,0 +1,133 @@
/* Une seule ambiance : le papier des planches TMIP. Couleurs des fils = cadres de la DA de la plateforme
(EAU bleu d'eau, ÉNERGIE ambre, JARDIN ocre olive ; QUARTIER provisoire, en attendant le quatrième cadre de la DA). */
:root {
--papier: #efeee2; --papier-2: #fffdf6; --encre: #102a3a; --encre-2: #3f5563; --trait: #ddd8c4;
--eau: #3a74a8; --eau-encre: #1d5886; --eau-fond: #e1ebf5;
--vivant: #8f7b22; --vivant-encre: #62560f; --vivant-fond: #eeead0;
--chaleur: #c96d0c; --chaleur-encre: #8f4506; --chaleur-fond: #fde8c8;
--quartier: #8a5a7a; --quartier-encre: #5e3a54; --quartier-fond: #f1e6ee;
--auj: #6b6458; --auj-encre: #4a443b; --auj-fond: #ece8de;
--ombre: 0 10px 30px rgba(16, 42, 58, .14);
color-scheme: light;
}
[hidden] { display: none !important; }
html, body { height: 100%; }
body { margin: 0; overflow: hidden; background: var(--papier); color: var(--encre);
font: 15px/1.45 Barlow, system-ui, -apple-system, "Segoe UI", sans-serif; -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, [tabindex]:focus-visible, a:focus-visible { outline: 2px solid var(--eau-encre); outline-offset: 2px; }
#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
#scene.tire { cursor: grabbing; }
/* le grain du papier, posé sur la scène (pas sur les panneaux) */
#grain { position: fixed; inset: 0; pointer-events: none; z-index: 1; mix-blend-mode: multiply; opacity: .55; background-size: 512px 512px; }
#repli { position: fixed; inset: 0; background: var(--papier) center / cover no-repeat; }
.sans-js { position: fixed; inset: auto 16px 16px; background: var(--papier-2); padding: 12px; border-radius: 12px; }
/* ---------- barre du haut ---------- */
.barre { position: fixed; z-index: 5; top: calc(env(safe-area-inset-top, 0px) + 10px); left: 12px; right: 12px;
display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; flex-wrap: wrap; pointer-events: none; }
.barre > * { pointer-events: auto; }
.titre { background: rgba(255, 253, 246, .93); border: 1px solid var(--trait); border-radius: 12px; padding: 7px 12px; box-shadow: var(--ombre); }
.titre h1 { margin: 0; font: 600 20px/1.1 "Barlow Condensed", Barlow, sans-serif; letter-spacing: .01em; }
.titre p { margin: 1px 0 0; font-size: 12.5px; color: var(--encre-2); }
.commandes { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.groupe { display: flex; background: rgba(255, 253, 246, .93); border: 1px solid var(--trait); border-radius: 12px; padding: 3px; box-shadow: var(--ombre); }
.groupe button { border: 0; background: transparent; border-radius: 9px; padding: 0 11px; min-height: 38px; min-width: 40px; font-weight: 500; font-size: 14px; }
.groupe button[aria-pressed="true"] { background: var(--encre); color: var(--papier-2); }
#b-menu { font: 600 14px/1 "Barlow Condensed", Barlow, sans-serif; text-transform: uppercase; letter-spacing: .06em; }
.groupe svg { width: 20px; height: 20px; display: block; margin: auto; }
@media (max-width: 560px) { .titre p { display: none; } .titre h1 { font-size: 18px; } .groupe button { padding: 0 9px; font-size: 13.5px; } }
/* ---------- fiches ---------- */
#fiches { position: fixed; z-index: 6; left: 0; right: 0; bottom: 0; background: var(--papier-2); border-top: 1px solid var(--trait);
border-radius: 16px 16px 0 0; box-shadow: 0 -8px 28px rgba(16, 42, 58, .12); padding: 10px 14px calc(env(safe-area-inset-bottom, 0px) + 8px);
display: flex; flex-direction: column; gap: 8px; max-height: 52%; }
@media (min-width: 900px) { #fiches { left: 16px; right: auto; bottom: 16px; width: 440px; border: 1px solid var(--trait); border-radius: 16px; max-height: calc(100% - 110px); } }
.onglets { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; flex: none; }
.onglets::-webkit-scrollbar { display: none; }
.onglets button { flex: none; display: flex; align-items: center; gap: 6px; border: 1px solid var(--trait); background: #fff; border-radius: 999px; padding: 5px 12px; min-height: 34px;
font: 600 13.5px/1 "Barlow Condensed", Barlow, sans-serif; text-transform: uppercase; letter-spacing: .05em; color: var(--c-encre, var(--encre)); }
.onglets button i { width: 9px; height: 9px; border-radius: 50%; background: var(--c, var(--auj)); }
.onglets button[aria-current="true"] { background: var(--c-fond, var(--papier)); border-color: var(--c, var(--encre)); }
.fiche { display: grid; grid-template-columns: 56px 1fr; gap: 12px; overflow-y: auto; min-height: 0; transition: opacity .35s ease; }
.fiche.sort { opacity: 0; }
.fiche .icone { width: 56px; height: 56px; border-radius: 50%; display: block; background: #fff; box-shadow: 0 2px 8px rgba(0,0,0,.08); }
.fiche .icone svg, .fiche .icone img { width: 56px; height: 56px; display: block; border-radius: 50%; }
.couche { font: 600 12.5px/1.2 "Barlow Condensed", Barlow, sans-serif; text-transform: uppercase; letter-spacing: .07em; color: var(--c-encre, var(--encre-2)); }
.fiche h2 { margin: 2px 0 5px; font-size: 19px; line-height: 1.22; font-weight: 600; text-wrap: balance; }
.fiche p { margin: 0 0 8px; }
.chiffres { display: flex; flex-wrap: wrap; gap: 8px 16px; margin: 2px 0 6px; }
.chiffres div { font-variant-numeric: tabular-nums; }
.chiffres b { display: block; font-size: 21px; font-weight: 700; line-height: 1.1; color: var(--c-encre, var(--encre)); }
.chiffres small { display: block; font-size: 12.5px; line-height: 1.3; color: var(--encre-2); max-width: 24ch; }
.source { font-size: 11.5px; color: var(--encre-2); }
.action { margin-top: 8px; border: 0; background: var(--c-encre, var(--eau-encre)); color: #fff; font-weight: 600; border-radius: 10px; padding: 10px 14px; min-height: 42px; }
.pied { display: flex; align-items: center; gap: 8px; flex: none; }
.points { flex: 1; display: flex; gap: 5px; align-items: center; flex-wrap: wrap; }
.points b { width: 7px; height: 7px; border-radius: 50%; background: var(--trait); }
.points b.vu { background: var(--c, var(--encre-2)); opacity: .45; }
.points b.ici { background: var(--c, var(--encre)); width: 18px; border-radius: 4px; opacity: 1; }
.pied button { border: 1px solid var(--trait); background: #fff; border-radius: 10px; width: 40px; height: 40px; display: grid; place-items: center; }
.pied svg { width: 18px; height: 18px; }
.compteur { font-size: 12.5px; color: var(--encre-2); font-variant-numeric: tabular-nums; min-width: 40px; text-align: right; }
.barre-temps { height: 2px; background: var(--trait); border-radius: 2px; overflow: hidden; flex: none; }
.barre-temps span { display: block; height: 100%; width: 0; background: var(--c, var(--encre)); }
.mentions { margin: 0; font-size: 11px; color: var(--encre-2); }
@media (max-width: 560px) { .mentions { display: none; } .fiche { grid-template-columns: 44px 1fr; gap: 10px; } .fiche .icone, .fiche .icone svg, .fiche .icone img { width: 44px; height: 44px; } .fiche h2 { font-size: 17.5px; } }
/* ---------- le menu : la maison au centre, les quatre fils aux coins (modèle ORENO p. 6) ---------- */
#menu { position: fixed; inset: 0; z-index: 15; display: grid; grid-template-rows: auto 1fr; pointer-events: none; }
#menu > * { pointer-events: auto; }
body.menu-ouvert #fiches { display: none; }
.menu-tete { justify-self: center; margin-top: calc(env(safe-area-inset-top, 0px) + 64px); max-width: 520px; background: rgba(255, 253, 246, .95); border: 1px solid var(--trait);
border-radius: 14px; padding: 10px 14px; box-shadow: var(--ombre); display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; }
.menu-tete h2 { margin: 0; font: 600 20px/1.15 "Barlow Condensed", Barlow, sans-serif; }
.menu-tete p { margin: 0; grid-column: 1; font-size: 13px; color: var(--encre-2); }
.menu-tete button { grid-column: 2; grid-row: 1 / span 2; align-self: center; border: 1px solid var(--trait); background: #fff; border-radius: 10px; min-height: 40px; padding: 0 12px; font-weight: 500; }
.cadres { position: relative; pointer-events: none; }
.cadre { position: absolute; width: min(330px, 30vw); background: var(--c-fond); border: 2px solid var(--c); border-radius: 14px; padding: 10px 12px; box-shadow: var(--ombre); pointer-events: auto; }
.cadre h3 { margin: 0 0 6px; font: 600 15px/1.1 "Barlow Condensed", Barlow, sans-serif; text-transform: uppercase; letter-spacing: .07em; color: var(--c-encre); display: flex; align-items: center; gap: 8px; }
.cadre h3 svg, .cadre h3 img { width: 30px; height: 30px; flex: none; border-radius: 50%; }
.cadre ol { margin: 0; padding: 0; list-style: none; display: grid; gap: 3px; }
.cadre li button { width: 100%; text-align: left; border: 0; background: rgba(255,255,255,.7); border-radius: 8px; padding: 6px 8px; min-height: 34px; font-size: 13.5px; line-height: 1.25; display: flex; gap: 6px; align-items: center; }
.cadre li button:hover { background: #fff; }
.cadre li button .n { font: 600 12px/1 "Barlow Condensed", Barlow, sans-serif; color: var(--c-encre); min-width: 14px; }
.cadre li button .x { margin-left: auto; display: flex; gap: 3px; }
.cadre li button .x i { width: 8px; height: 8px; border-radius: 50%; }
.cadre.quartier { left: 2%; top: 4%; } .cadre.chaleur { right: 2%; top: 4%; } .cadre.eau { left: 2%; bottom: 4%; } .cadre.vivant { right: 2%; bottom: 4%; }
@media (max-width: 900px) {
#menu { background: rgba(239, 238, 226, .9); overflow-y: auto; }
.menu-tete { margin: calc(env(safe-area-inset-top, 0px) + 10px) 12px 0; }
.cadres { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 12px 12px calc(env(safe-area-inset-bottom, 0px) + 16px); align-content: start; }
.cadre { position: static; width: auto; }
}
@media (max-width: 560px) { .cadres { grid-template-columns: 1fr; } }
/* ---------- le cycle de l'eau (planche du concours) ---------- */
#cycle { position: fixed; inset: 0; z-index: 20; background: var(--papier); display: grid; grid-template-rows: auto 1fr auto; }
#cycle header { display: flex; align-items: center; gap: 10px; padding: calc(env(safe-area-inset-top, 0px) + 10px) 14px 8px; }
#cycle header button { border: 1px solid var(--trait); background: #fff; border-radius: 10px; min-height: 40px; padding: 0 12px; font-weight: 500; }
#cycle header h2 { margin: 0; font: 600 20px/1.1 "Barlow Condensed", Barlow, sans-serif; }
#cycle header p { margin: 0; font-size: 12.5px; color: var(--encre-2); }
.vue-planche { position: relative; overflow: hidden; touch-action: none; cursor: grab; }
.plateau { position: absolute; left: 0; top: 0; width: 1615px; height: 860px; transform-origin: 0 0; will-change: transform; }
.plateau img { position: absolute; inset: 0; width: 100%; height: 100%; user-select: none; -webkit-user-drag: none; pointer-events: none; }
.plateau svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.flux { fill: none; stroke: var(--eau); stroke-width: 7; stroke-linecap: round; stroke-dasharray: 2 16; opacity: .25; transition: opacity .5s; }
.flux.actif { opacity: .95; animation: couler 1.1s linear infinite; }
@keyframes couler { to { stroke-dashoffset: -18; } }
.pe { cursor: pointer; }
.pe .halo { fill: var(--eau); opacity: 0; }
.pe .coeur { fill: #fff; stroke: var(--eau); stroke-width: 3; }
.pe text { font: 700 15px Barlow, sans-serif; fill: var(--eau-encre); text-anchor: middle; dominant-baseline: central; pointer-events: none; }
.pe.actif .coeur { fill: var(--eau); }
.pe.actif text { fill: #fff; }
.pe.actif .halo { animation: halo 1.6s ease-out infinite; }
@keyframes halo { 0% { opacity: .45; r: 16; } 100% { opacity: 0; r: 46; } }
#cycle .bas { background: var(--papier-2); border-top: 1px solid var(--trait); padding: 10px 14px calc(env(safe-area-inset-bottom, 0px) + 10px); display: flex; flex-direction: column; gap: 8px; }
#cycle .bas .barre-temps { flex: 1; }
#temps-eau { background: var(--eau); }
@media (min-width: 900px) { #cycle .bas { position: absolute; left: 16px; bottom: 16px; width: 440px; border: 1px solid var(--trait); border-radius: 16px; box-shadow: var(--ombre); } #cycle { grid-template-rows: auto 1fr; } }
#cycle .etape h3 { margin: 2px 0 5px; font-size: 18px; font-weight: 600; }
#cycle .etape p { margin: 0 0 6px; }
@media (prefers-reduced-motion: reduce) { .flux.actif, .pe.actif .halo { animation: none; } .pe.actif .halo { opacity: .25; } .fiche { transition: none; } }
+232
View File
@@ -0,0 +1,232 @@
// Le végétal de la maquette, généré depuis content/essences.md (esprit Grasshopper : des paramètres, un générateur,
// des instances). Les positions viennent du plan (haies = limites de parcelles, forêt et arbres existants = blocs Rhino) ;
// l'essence, la taille, la forme et la couleur viennent du tableau. Changer le tableau change toute la scène.
import * as THREE from 'three';
import { mergeGeometries, mergeVertices } from 'three/addons/utils/BufferGeometryUtils.js';
export const rnd = (i) => { const x = Math.sin(i * 12.9898 + 78.233) * 43758.5453; return x - Math.floor(x); };
const norm = (s) => s.normalize('NFD').replace(/[̀-ͯ]/g, '').toLowerCase().trim();
// ---------------------------------------------------------------- géométries
// couronne « lavis » : sphère légèrement bosselée, lissée (pas de facettes : la planche est peinte, pas taillée)
function couronne(seed, bosse = 0.13, detail = 2) {
let g = new THREE.IcosahedronGeometry(1, detail);
g.deleteAttribute('normal'); g.deleteAttribute('uv');
g = mergeVertices(g);
const p = g.attributes.position, v = new THREE.Vector3();
for (let i = 0; i < p.count; i++) {
v.fromBufferAttribute(p, i);
const n = 1 + bosse * Math.sin(v.x * 3.1 + seed) * Math.sin(v.y * 2.6 + seed * 2.1) * Math.sin(v.z * 3.4 + seed * 2.9);
p.setXYZ(i, v.x * n, v.y * n, v.z * n);
}
g.computeVertexNormals();
return g;
}
function buisson() {
const a = couronne(3, 0.16, 1).translate(-0.32, -0.05, 0.1).scale(0.72, 0.8, 0.72);
const b = couronne(5, 0.16, 1).translate(0.3, 0.02, -0.12).scale(0.7, 0.85, 0.7);
const c = couronne(7, 0.16, 1).translate(0, 0.22, 0.05).scale(0.62, 0.7, 0.62);
return mergeVertices(mergeGeometries([a, b, c].map((x) => { x.deleteAttribute('uv'); return x; })));
}
// tronc : cylindre unitaire posé sur le sol
const geoTronc = new THREE.CylinderGeometry(0.55, 1, 1, 6).translate(0, 0.5, 0);
const geoFruit = new THREE.IcosahedronGeometry(1, 0);
// part de tronc et proportions de la couronne, par forme (lu sur la description des dessins du recueil)
const FORMES = {
'étalée': { tronc: 0.34, sx: 1, sy: 0.92, geo: () => couronne(1) },
'boule': { tronc: 0.3, sx: 1, sy: 1, geo: () => couronne(2) },
'boule basse': { tronc: 0.1, sx: 1, sy: 1, geo: () => couronne(4) },
'arrondie': { tronc: 0.46, sx: 1, sy: 1, geo: () => couronne(6) },
'ovoïde': { tronc: 0.32, sx: 0.84, sy: 1, geo: () => couronne(8, 0.18) },
'buisson': { tronc: 0, sx: 1, sy: 1, geo: buisson },
};
const GEO = {};
const geoForme = (f) => (GEO[f] ??= FORMES[f].geo());
// ---------------------------------------------------------------- couleurs
export function teinte(ton, tons, i) {
let hex = ton;
if (ton === 'melange') hex = tons[['clair', 'moyen', 'fonce'][Math.floor(rnd(i * 3.7) * 3)]];
else if (tons[ton]) hex = tons[ton];
const c = new THREE.Color(hex);
// un lavis n'est jamais uniforme : ±6 % de valeur, ±3 % de teinte
const hsl = {}; c.getHSL(hsl);
c.setHSL(hsl.h + (rnd(i * 1.3) - 0.5) * 0.03, hsl.s * (0.92 + rnd(i * 2.1) * 0.12), Math.min(0.92, hsl.l * (0.94 + rnd(i * 5.9) * 0.12)));
return c;
}
// ---------------------------------------------------------------- un lot d'arbres → meshes instanciés
// items : { x, z, H, W, forme, couleur: THREE.Color, fruit: '#hex'|null, rot }
export function lot(items, mat, avecFruits) {
const groupe = new THREE.Group();
const M = new THREE.Matrix4(), Q = new THREE.Quaternion(), S = new THREE.Vector3(), V = new THREE.Vector3(), Y = new THREE.Vector3(0, 1, 0);
const parForme = {};
for (const it of items) (parForme[it.forme] ??= []).push(it);
const troncs = items.filter((it) => FORMES[it.forme].tronc > 0);
const imT = troncs.length ? new THREE.InstancedMesh(geoTronc, mat.tronc, troncs.length) : null;
if (imT) { imT.castShadow = true; groupe.add(imT); }
let iT = 0;
const fruits = [];
for (const [forme, L] of Object.entries(parForme)) {
const F = FORMES[forme];
const im = new THREE.InstancedMesh(geoForme(forme), mat.couronne, L.length);
im.castShadow = true; im.receiveShadow = true;
L.forEach((it, i) => {
const ht = it.H * F.tronc, rx = (it.W / 2) * F.sx, ry = ((it.H - ht) / 2) * F.sy;
const cy = ht + ry;
Q.setFromAxisAngle(Y, it.rot);
im.setMatrixAt(i, M.compose(V.set(it.x, cy, it.z), Q, S.set(rx, ry, rx)));
im.setColorAt(i, it.couleur);
it.haut = cy + ry; it.centre = cy; it.rx = rx; it.ry = ry;
if (imT && F.tronc > 0) {
const rt = Math.max(0.07, it.W * 0.035);
imT.setMatrixAt(iT++, M.compose(V.set(it.x, 0, it.z), Q.identity(), S.set(rt, ht + ry * 0.4, rt)));
}
if (avecFruits && it.fruit) {
const n = forme === 'buisson' ? 3 : 6, r = forme === 'buisson' ? 0.07 : Math.max(0.11, it.W * 0.035);
for (let k = 0; k < n; k++) {
const a = rnd(it.x * 7 + it.z * 3 + k * 11) * Math.PI * 2, e = -0.15 + rnd(it.z * 5 + k * 13) * 0.9;
const c = Math.sqrt(1 - e * e);
fruits.push({ x: it.x + Math.cos(a) * c * rx * 0.96, y: cy + e * ry * 0.96, z: it.z + Math.sin(a) * c * rx * 0.96, r, c: it.fruit });
}
}
});
im.instanceColor.needsUpdate = true;
groupe.add(im);
}
if (fruits.length) {
const imF = new THREE.InstancedMesh(geoFruit, mat.fruit, fruits.length);
const col = new THREE.Color();
fruits.forEach((f, i) => { imF.setMatrixAt(i, M.compose(V.set(f.x, f.y, f.z), Q.identity(), S.setScalar(f.r))); imF.setColorAt(i, col.set(f.c)); });
imF.instanceColor.needsUpdate = true;
groupe.add(imF);
}
return groupe;
}
// ---------------------------------------------------------------- poser les essences le long des haies
function polyligne(pts) {
const c = [0];
for (let i = 1; i < pts.length; i++) c.push(c[i - 1] + Math.hypot(pts[i][0] - pts[i - 1][0], pts[i][1] - pts[i - 1][1]));
return { pts, c, L: c[c.length - 1] };
}
export function surPolyligne(t, s) {
let i = 1; while (i < t.c.length - 1 && t.c[i] < s) i++;
const a = t.pts[i - 1], b = t.pts[i], k = (s - t.c[i - 1]) / ((t.c[i] - t.c[i - 1]) || 1);
const dx = b[0] - a[0], dz = b[1] - a[1], n = Math.hypot(dx, dz) || 1;
return { x: a[0] + dx * k, z: a[1] + dz * k, tx: dx / n, tz: dz / n };
}
export function haiesEssences(haies, E) {
const R = E.reglages, arbres = new Map(E.arbres.map((e) => [norm(e.nom), e])), arbustes = new Map(E.arbustes.map((e) => [norm(e.nom), e]));
const seqA = E.sequenceArbres.map((n) => arbres.get(norm(n))), seqB = E.sequenceArbustes.map((n) => arbustes.get(norm(n)));
const items = [];
haies.forEach((h, k) => {
const t = polyligne(h);
const dA = Math.floor(rnd(k * 7 + 1) * seqA.length), dB = Math.floor(rnd(k * 13 + 2) * seqB.length);
const sA = [];
for (let s = R.pasArbres * (0.3 + rnd(k) * 0.4), i = 0; s < t.L - 0.4; s += R.pasArbres, i++) {
sA.push(s);
const p = surPolyligne(t, s), e = seqA[(dA + i) % seqA.length], j = 0.9 + rnd(k * 31 + i) * 0.2, lat = (rnd(k * 17 + i) - 0.5) * 0.5;
items.push({ x: p.x - p.tz * lat, z: p.z + p.tx * lat, H: e.hauteur * R.echelleHauteur * j, W: e.couronne * R.echelleCouronne * j, forme: e.forme,
couleur: teinte(e.ton, R.tons, k * 1000 + i), fruit: R.fruits ? e.fruit : null, rot: rnd(k * 5 + i) * 6.28, nom: e.nom, haie: k, s, strate: 'arbre' });
}
for (let s = R.pasArbustes / 2, i = 0; s < t.L; s += R.pasArbustes, i++) {
if (sA.some((a) => Math.abs(a - s) < 1.0)) continue;
const p = surPolyligne(t, s), e = seqB[(dB + i) % seqB.length], j = 0.85 + rnd(k * 41 + i) * 0.3, lat = (rnd(k * 19 + i) - 0.5) * 0.7;
items.push({ x: p.x - p.tz * lat, z: p.z + p.tx * lat, H: e.hauteur * j, W: e.couronne * j, forme: e.forme,
couleur: teinte(e.ton, R.tons, k * 1000 + 500 + i), fruit: R.fruits ? e.fruit : null, rot: rnd(k * 9 + i) * 6.28, nom: e.nom, haie: k, s, strate: 'arbuste' });
}
});
return items;
}
// fruitiers isolés au milieu des jardins : une essence du tableau, au hasard mais toujours la même
export function vergers(points, E) {
const R = E.reglages;
return points.map(([x, z], i) => {
const e = E.arbres[Math.floor(rnd(x * 3.1 + z * 1.7) * E.arbres.length)], j = 0.9 + rnd(i * 3) * 0.2;
return { x, z, H: e.hauteur * R.echelleHauteur * j, W: e.couronne * R.echelleCouronne * j, forme: e.forme, couleur: teinte(e.ton, R.tons, 70000 + i),
fruit: R.fruits ? e.fruit : null, rot: rnd(i * 7) * 6.28, nom: e.nom };
});
}
// arbres du plan (forêt, existants, buissons) : taille du tableau × taille relative du bloc Rhino
export function arbresPlan(arbres, E, genre, ref, mediane) {
const A = E.autres[genre], R = E.reglages, ech = genre === 'buisson existant' ? 1 : R.echelleHauteur, echW = genre === 'buisson existant' ? 1 : R.echelleCouronne;
return arbres.map((a, i) => {
const k = Math.max(0.7, Math.min(1.35, a[2] / mediane)) * (0.92 + rnd(i * 5 + ref) * 0.16);
return { x: a[0], z: a[1], H: A.hauteur * ech * k, W: A.couronne * echW * k, forme: A.forme, couleur: teinte(A.ton, R.tons, ref * 10000 + i), fruit: null, rot: rnd(i + ref) * 6.28 };
});
}
// ---------------------------------------------------------------- aujourd'hui : des haies de thuyas taillées
export function thuyas(haies, mat) {
const segs = [];
for (const h of haies) for (let i = 1; i < h.length; i++) segs.push([h[i - 1], h[i]]);
const im = new THREE.InstancedMesh(new THREE.BoxGeometry(1, 1, 1).translate(0, 0.5, 0), mat, segs.length);
const M = new THREE.Matrix4(), Q = new THREE.Quaternion(), S = new THREE.Vector3(), V = new THREE.Vector3(), Y = new THREE.Vector3(0, 1, 0);
segs.forEach(([a, b], i) => {
const L = Math.hypot(b[0] - a[0], b[1] - a[1]);
Q.setFromAxisAngle(Y, Math.atan2(-(b[1] - a[1]), b[0] - a[0]));
im.setMatrixAt(i, M.compose(V.set((a[0] + b[0]) / 2, 0, (a[1] + b[1]) / 2), Q, S.set(L + 0.3, 1.9, 0.85)));
});
im.castShadow = true; im.receiveShadow = true;
return im;
}
// ---------------------------------------------------------------- les plantes d'eau (recueil p. 19 et p. 21)
// 0 jonc · 1 lysimaque · 2 salicaire · 3 papyrus · 4 pétasite · 5 nénuphar · 6 iris jaune · 7 roseau
export const NOMS_AQUA = ['jonc', 'lysimaque', 'salicaire', 'papyrus', 'pétasite', 'nénuphar', 'iris jaune', 'roseau'];
function tiges(n, h, r, evase, seed) {
const L = [];
for (let i = 0; i < n; i++) {
const a = (i / n) * Math.PI * 2 + rnd(seed + i), e = evase * (0.5 + rnd(seed * 3 + i) * 0.5), hh = h * (0.75 + rnd(seed * 7 + i) * 0.35);
const g = new THREE.ConeGeometry(r, hh, 4).translate(0, hh / 2, 0);
g.rotateZ(Math.cos(a) * e); g.rotateX(Math.sin(a) * e);
g.deleteAttribute('uv'); L.push(g);
}
return mergeGeometries(L);
}
function touffe(r, h) { const g = couronne(9, 0.2, 1).scale(r, h, r).translate(0, h * 0.8, 0); g.deleteAttribute('uv'); return g; }
const AQUA = [
{ feuille: () => tiges(9, 1.1, 0.035, 0.35, 1), cf: '#8ea366' },
{ feuille: () => touffe(0.42, 0.42), cf: '#87a35d', fleur: () => tiges(5, 0.35, 0.06, 0.25, 2).translate(0, 0.62, 0), cfl: '#e2c24a' },
{ feuille: () => touffe(0.38, 0.45), cf: '#86a060', fleur: () => tiges(4, 0.55, 0.07, 0.2, 3).translate(0, 0.7, 0), cfl: '#b0608a' },
{ feuille: () => tiges(7, 1.5, 0.025, 0.18, 4), cf: '#94ad62', fleur: () => { const L = []; for (let i = 0; i < 4; i++) { const g = new THREE.SphereGeometry(0.28, 8, 4).scale(1, 0.35, 1).translate((rnd(i) - 0.5) * 0.4, 1.55 + rnd(i * 3) * 0.2, (rnd(i * 5) - 0.5) * 0.4); g.deleteAttribute('uv'); L.push(g); } return mergeGeometries(L); }, cfl: '#a9bd6c' },
{ feuille: () => touffe(0.62, 0.3), cf: '#6f8f55' },
{ feuille: () => { const g = new THREE.CylinderGeometry(0.42, 0.42, 0.04, 14).translate(0, 0.06, 0); g.deleteAttribute('uv'); return g; }, cf: '#7fa77a', fleur: () => { const g = new THREE.SphereGeometry(0.11, 8, 6).translate(0.12, 0.13, 0.05); g.deleteAttribute('uv'); return g; }, cfl: '#efe7c8' },
{ feuille: () => tiges(6, 0.95, 0.05, 0.22, 5), cf: '#8aa665', fleur: () => tiges(3, 0.2, 0.07, 0.6, 6).translate(0, 0.85, 0), cfl: '#e6c84f' },
{ feuille: () => tiges(8, 2.1, 0.03, 0.15, 7), cf: '#a9a670', fleur: () => { const g = new THREE.SphereGeometry(0.16, 6, 4).scale(1, 2.2, 1).translate(0, 2.15, 0); g.deleteAttribute('uv'); return g; }, cfl: '#b39b6b' },
];
export function plantesEau(aqua) {
const groupe = new THREE.Group(), parType = {};
for (const p of aqua) (parType[p[2]] ??= []).push(p);
const M = new THREE.Matrix4(), Q = new THREE.Quaternion(), S = new THREE.Vector3(), V = new THREE.Vector3(), Y = new THREE.Vector3(0, 1, 0);
const meshes = [];
for (const [t, L] of Object.entries(parType)) {
const def = AQUA[t];
const parts = [[def.feuille(), def.cf], def.fleur ? [def.fleur(), def.cfl] : null].filter(Boolean);
for (const [geo, c] of parts) {
const im = new THREE.InstancedMesh(geo, new THREE.MeshLambertMaterial({ color: c, emissive: '#000000' }), L.length);
L.forEach((p, i) => { Q.setFromAxisAngle(Y, rnd(i * 3 + +t) * 6.28); im.setMatrixAt(i, M.compose(V.set(p[0], 0, p[1]), Q, S.setScalar(p[3]))); });
im.castShadow = +t !== 5; groupe.add(im); meshes.push(im);
}
}
return { groupe, meshes };
}
// ---------------------------------------------------------------- le potager au pied de la haie témoin (strate herbacée)
export function potager(points) {
const C = ['#8aa35f', '#b8714f', '#9db36a', '#cf9c52', '#7d965a', '#c9b05a'];
const im = new THREE.InstancedMesh(new THREE.IcosahedronGeometry(1, 1), new THREE.MeshLambertMaterial({ color: '#ffffff', emissive: '#000000' }), points.length);
const M = new THREE.Matrix4(), col = new THREE.Color();
points.forEach(([x, z], i) => {
const r = 0.13 + rnd(i * 3) * 0.08;
im.setMatrixAt(i, M.makeScale(r * 1.4, r, r * 1.4).setPosition(x, r * 0.8, z));
im.setColorAt(i, col.set(C[i % C.length]));
});
im.instanceColor.needsUpdate = true; im.castShadow = true;
return im;
}