La caméra du mode fond (?mode=fond) quitte l'orbite continue : image fixe 6 s, puis un tour des éléments (approche 18 s, arrêt 7 s, glissement de l'un à l'autre), retour à la vue d'ensemble 14 s, pause 10 s, et le tour recommence. Seuls x, z et la largeur vue bougent, jamais l'azimut ni l'élévation. Fonction pure vueScenario (maquette/mode.ts, SCENARIO_FOND), testée en Node ; le temps est celui de la boucle (s'arrête sous document.hidden). La démo ne change pas de comportement ; PLAFONDS_FOND.derive retiré (seul le mode fond s'en servait). Les gestes du Tour (directive du 20/10, priorité A), en formes de jouet en bois, dans les deux régimes : le convoi de sept vélos et sa remorque chargée, trois cuves sous un appentis, une baissière plantée d'arbres d'ombre, un tube de cuisson solaire, deux cochons dans un enclos sous des arbres, un panneau d'affichage au chantier, une boîte à surplus, des planches bâchées et paillées (maquette/gestes.js, animaux.js). Places calculées à la construction depuis data/scene2035.json, là où la caméra les voit ; aucune texture, aucun texte. docs/EMBED.md mis à jour. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Q3iHV9X8C4SaLQH1tn1UQQ
680 lines
56 KiB
JavaScript
680 lines
56 KiB
JavaScript
// 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, remorque } from './animaux.js';
|
|
import { gestesDuTour } from './gestes.js';
|
|
import { PLAFONDS_FOND, prochaineImage, vueScenario, SCENARIO_FOND } from './mode.ts';
|
|
|
|
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'],
|
|
};
|
|
|
|
// `fond` (14/10, docs/EMBED.md) : la scène seule en fond d'une autre page. Aucun écouteur de pointeur, DPR plafonné à
|
|
// 1,5, 30 images par seconde, le sol d'aujourd'hui jamais chargé (on reste en 2035), et `onPret()` appelé après la
|
|
// première image dessinée textures chargées ; sous mouvement réduit, cette image est la seule (aucune boucle).
|
|
export function creerScene(canvas, { D, ESSENCES, BULLES, IMG, reduit, petit, onToucher, fond = false, onPret = () => {} }) {
|
|
const renderer = new THREE.WebGLRenderer({ canvas, antialias: true, powerPreference: fond ? 'low-power' : 'high-performance' });
|
|
if (!renderer.getContext()) return null;
|
|
renderer.setPixelRatio(Math.min(devicePixelRatio || 1, fond ? PLAFONDS_FOND.pixelRatio : 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 ELEVATION = 0.62; // l'élévation de l'axonométrie (rad) ; les gestes du Tour s'en servent pour se poser là où on les voit
|
|
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;
|
|
// un gestionnaire à soi : `charge` passe à vrai quand toutes les textures sont arrivées (ou ont échoué), pour le mode fond
|
|
const gestion = new THREE.LoadingManager(); let charge = false; gestion.onLoad = () => { charge = true; besoin = true; };
|
|
const chargeur = new THREE.TextureLoader(gestion);
|
|
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: fond ? null : 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: 'energie-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));
|
|
const itemsVergers = vergers(D.vergers, E);
|
|
G.v2035.add(lot(itemsVergers, 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);
|
|
const itemsPlan = [arbresPlan(foret, E, 'foret', 1, med(foret)), arbresPlan(exist, E, 'arbre existant', 2, med(exist)), arbresPlan(buis, E, 'buisson existant', 3, med(buis))];
|
|
G.v2035.add(lot(itemsPlan[0], matsForet, false));
|
|
scene.add(lot(itemsPlan[1], matsAutres, false));
|
|
scene.add(lot(itemsPlan[2], 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: [], 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); }
|
|
// les gestes du Tour (22/10, directive du 20/10, priorité A) : cuves sous appentis, baissière, tube solaire, cochon,
|
|
// panneau du chantier, boîte à surplus, planches bâchées et paillées ; dans les deux régimes (gestes.js)
|
|
const gestes = gestesDuTour({ D, groupe: G.v2035, transformees, T, mats: { zinc: mat.zinc, cuve: mat.cuve }, matsArbres: matsAutres, potager: ptsPotager, haiesT,
|
|
arbres3D: [...itemsHaies, ...itemsVergers, ...itemsPlan.flat()], el: ELEVATION });
|
|
anim.push(...gestes.anim);
|
|
|
|
// ---------------------------------------------------------------- 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'));
|
|
// le convoi (22/10, directive 3.1 : « quinze vélos sur la route », la remorque chargée) : sept vélos ensemble, à la
|
|
// queue leu leu sur la route principale, la remorque derrière le dernier. Ils vont et viennent d'un bout à l'autre ;
|
|
// à chaque bout, la file tourne vélo après vélo (le décalage sur la droite s'annule en approchant du bout).
|
|
const convoi = (() => {
|
|
const t = tr.principale, n = 7, ecart = 2.7, v = 3.4, droite = 1.9, membres = [];
|
|
for (let i = 0; i < n; i++) { const o = velo(PAL.gens[(i * 3 + 1) % PAL.gens.length]); G.v2035.add(o); membres.push({ o, recul: i * ecart }); }
|
|
const rq = remorque(); G.v2035.add(rq); membres.push({ o: rq, recul: (n - 1) * ecart + 2.3 });
|
|
// départ : au premier arrêt du scénario (≈ 27 s), la file passe au milieu de la route
|
|
let u = 0.55 * t.L - v * (SCENARIO_FOND.ouverture + SCENARIO_FOND.approche + SCENARIO_FOND.arret / 2) + (n - 1) * ecart / 2;
|
|
const centre = { x: 0, z: 0 };
|
|
function maj(dt) {
|
|
u = (u + v * dt) % (2 * t.L);
|
|
membres.forEach((m, i) => {
|
|
const uk = (((u - m.recul) % (2 * t.L)) + 2 * t.L) % (2 * t.L), s = uk < t.L ? uk : 2 * t.L - uk, sens = uk < t.L ? 1 : -1;
|
|
const p = surTrajet(t, s); let dx = p.dx * sens, dz = p.dz * sens; const k = Math.hypot(dx, dz) || 1; dx /= k; dz /= k;
|
|
const d = droite * Math.min(1, Math.min(s, t.L - s) / 4);
|
|
m.o.position.set(p.x - dz * d, 0, p.z + dx * d); m.o.rotation.y = Math.atan2(-dz, dx);
|
|
if (i === 3) { centre.x = m.o.position.x; centre.z = m.o.position.z; }
|
|
});
|
|
}
|
|
maj(0);
|
|
return { maj, centre };
|
|
})();
|
|
|
|
// ---------------------------------------------------------------- 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);
|
|
});
|
|
|
|
// Le hors-champ (les grandes infrastructures des trois systèmes, en volumes) est retiré le 09/10 : c'est la carte du
|
|
// territoire dessinée par Jules qui entoure désormais le quartier (maquette/carte.js). On y passe en dézoomant.
|
|
|
|
// ---------------------------------------------------------------- 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: 250 }, // le socle fait 268,9 m de large : les bords de la forêt et de l'ouest sont à peine rognés
|
|
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 },
|
|
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;
|
|
|
|
// ---------------------------------------------------------------- le tour du mode fond (22/10) : les éléments, dans l'ordre
|
|
// (brief du lot, §3) ; chacun avec sa largeur vue (S3 : ≈ 55 m, plus serré sur les petits objets). Les positions sont
|
|
// celles des objets de la scène, calculées à la construction ; le convoi bouge, sa place est relue à chaque image.
|
|
const pt = (p, w) => (p ? { x: p.x, z: p.z, w } : null);
|
|
const TOUR = [
|
|
{ x: convoi.centre.x, z: convoi.centre.z, w: 60, convoi: true },
|
|
pt(gestes.points.cuves, 34),
|
|
pt(gestes.points.baissiere, 55),
|
|
pt(gestes.points.tube, 24),
|
|
pt(gestes.points.cochon, 30),
|
|
pt(gestes.points.chantier, 48),
|
|
pt(gestes.points.surplus, 22),
|
|
pt(gestes.points.planches, 36),
|
|
{ x: MARE.x, z: MARE.z, w: 55 },
|
|
{ x: CAD.place.x, z: CAD.place.z, w: 56 }, // le marché : la place et ses étals (le premier étal est caché par la grande maison)
|
|
].filter(Boolean);
|
|
// la caméra reste au-dessus de la maquette : un élément près du bord (le convoi qui fait demi-tour) se voit décentré
|
|
const surSocle = (p, x, z) => { const mx = D.Wm / 2 - p.w / 2, mz = D.Hm / 2 - p.w * 0.45; p.x = Math.max(-mx, Math.min(mx, x)); p.z = Math.max(-mz, Math.min(mz, z)); };
|
|
TOUR.forEach((p) => surSocle(p, p.x, p.z));
|
|
|
|
// ---------------------------------------------------------------- caméra : axonométrie orthographique, pilotable au doigt
|
|
const vue = { x: 0, z: 0, az: 0, el: ELEVATION, w: 210 };
|
|
let vol = null, cadrageCourant = null;
|
|
// mode fond : le scénario (maquette/mode.ts, vueScenario) part de la vue d'ensemble posée par `fond(true)`
|
|
let scenario = null;
|
|
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 W_MAX = 470; // au-delà, le quartier est entier et entouré de papier : on passe sur la carte du territoire
|
|
const bornes = () => { vue.w = Math.max(14, Math.min(W_MAX, vue.w)); vue.x = Math.max(-260, Math.min(260, vue.x)); vue.z = Math.max(-260, Math.min(260, 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 };
|
|
}
|
|
let poussee = 0; // on insiste pour dézoomer alors que le quartier est déjà entier : au troisième cran, la carte
|
|
function zoomVers(px, py, f) {
|
|
if (f > 1 && vue.w >= W_MAX - 1) { if (++poussee >= 3) { poussee = 0; onToucher('dezoom'); } return; }
|
|
if (f < 1) poussee = 0;
|
|
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;
|
|
}
|
|
// en mode fond, la scène n'écoute rien : ni pointeur, ni molette (le parent la pose en pointer-events: none, en plus)
|
|
const ecoute = fond ? () => {} : (type, f, o) => canvas.addEventListener(type, f, o);
|
|
const ptrs = new Map(); let geste = null;
|
|
ecoute('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'); });
|
|
ecoute('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;
|
|
};
|
|
ecoute('pointerup', fin); ecoute('pointercancel', fin);
|
|
ecoute('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: 'energie-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, suspendue = false;
|
|
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);
|
|
// mode fond : rien avant que les textures soient là (l'image d'attente reste chez le parent), au plus 30 images par
|
|
// seconde ; sous mouvement réduit, une seule image (plus une à chaque redimensionnement), et aucune boucle.
|
|
const uneImage = fond && reduit; let prochaine = 0, pret = false;
|
|
function boucle(now) {
|
|
if (!uneImage) requestAnimationFrame(boucle);
|
|
if (document.hidden || suspendue) { horloge.getDelta(); return; }
|
|
if (fond) {
|
|
if (!charge) { horloge.getDelta(); return; }
|
|
if (!uneImage) { const p = prochaineImage(now, prochaine); if (p === null) return; prochaine = p; }
|
|
}
|
|
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; }
|
|
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; });
|
|
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); } });
|
|
if (G.v2035.visible) convoi.maj(dt);
|
|
// mode fond : la caméra suit le scénario (x, z, largeur ; jamais l'azimut ni l'élévation). Son temps avance avec la
|
|
// boucle, donc s'arrête sous `document.hidden`, ne saute pas après un retard (dt plafonné), et ne part qu'après la
|
|
// première image (celle du message `quartier:pret`).
|
|
if (scenario && !reduit && !vol) {
|
|
if (pret) scenario.t += dt;
|
|
surSocle(TOUR[0], convoi.centre.x, convoi.centre.z);
|
|
const v = vueScenario(scenario.t, scenario.ensemble, TOUR);
|
|
vue.x = v.x; vue.z = v.z; vue.w = v.w;
|
|
}
|
|
place(); renderer.render(scene, cam); besoin = false;
|
|
if (fond && !pret) { pret = true; onPret(); }
|
|
}
|
|
epoque('2035'); // le groupe « aujourd'hui » (voitures garées, thuyas) est caché dès le départ
|
|
place();
|
|
if (!uneImage) requestAnimationFrame(boucle);
|
|
else {
|
|
const dessiner = () => { if (charge && !document.hidden) boucle(performance.now()); };
|
|
gestion.onLoad = () => { charge = true; besoin = true; dessiner(); };
|
|
addEventListener('resize', dessiner);
|
|
document.addEventListener('visibilitychange', () => { if (!pret) dessiner(); });
|
|
dessiner();
|
|
}
|
|
|
|
return {
|
|
cadrer, effet, epoque, tourner,
|
|
poserPanneau(f) { panneau_ = f; },
|
|
/** Mode fond : le scénario de caméra part de la vue courante (la vue d'ensemble) ; le chantier chez le voisin reste montré. */
|
|
fond(on) { etat.fond = on; scenario = on ? { ensemble: { x: vue.x, z: vue.z, w: vue.w }, t: 0 } : null; chantier.visible = on || etat.fx === 'chantier'; besoin = true; },
|
|
cadrages: Object.keys(CAD),
|
|
/** La maquette cesse de se dessiner tant que la carte la couvre (téléphones : la batterie). */
|
|
suspendre(on) { suspendue = on; },
|
|
/** Le rectangle du socle à l'écran (px CSS), pour la vue courante : la carte cale l'îlot du quartier dessus. */
|
|
rectSocle() {
|
|
const { W, H } = taille(), wpp = vue.w / W, rx = Math.cos(vue.az), rz = -Math.sin(vue.az);
|
|
const ux = -Math.sin(vue.az) * Math.sin(vue.el), uy = Math.cos(vue.el), uz = -Math.cos(vue.az) * Math.sin(vue.el);
|
|
const X = [], Y = [];
|
|
for (const [px, pz] of [[-D.Wm / 2, -D.Hm / 2], [D.Wm / 2, -D.Hm / 2], [D.Wm / 2, D.Hm / 2], [-D.Wm / 2, D.Hm / 2]]) {
|
|
const dx = px - vue.x, dz = pz - vue.z;
|
|
X.push(W / 2 + (dx * rx + dz * rz) / wpp); Y.push(H / 2 - (dx * ux + 0 * uy + dz * uz) / wpp);
|
|
}
|
|
return { x0: Math.min(...X), y0: Math.min(...Y), x1: Math.max(...X), y1: Math.max(...Y), az: vue.az };
|
|
},
|
|
apercu() { renderer.render(scene, cam); return renderer.domElement.toDataURL('image/jpeg', 0.86); },
|
|
};
|
|
}
|