Au trait : maisons, serres (y compris celles des objets) et témoin à la même encre (PAL.trait, opacité 0,55) ; après la pose des objets et du témoin, les arêtes visibles et fixes deviennent une LineSegments par racine (quartier, 2035, aujourd'hui), faces voisines en polygonOffset. Coque inversée des couronnes (geoCoque, vegetal.js) : + 43 % de triangles au mieux, au-delà des + 15 % du brief : TRAIT_M.contours = [] (['haies'] la rallume). Les bêtes et les objets du Tour n'ont pas de trait. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
966 lines
82 KiB
JavaScript
966 lines
82 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 { mergeGeometries } from 'three/addons/utils/BufferGeometryUtils.js';
|
|
import { lot, geoCoque, haiesEssences, vergers, arbresPlan, thuyas, plantesEau, potager, NOMS_AQUA, rnd } from './vegetal.js';
|
|
import { vieAnimale, velo as veloA, veloCargo, attelage, voiture, chien, remorque, quille } from './animaux.js';
|
|
import { gestesDuTour } from './gestes.js';
|
|
import { objetsNouveaux } from './objets.js';
|
|
import { detaillerTemoin } from './maison.js';
|
|
import { PLAFONDS_FOND, prochaineImage, vueScenario, SCENARIO_FOND } from './mode.ts';
|
|
import { intensiteBrille } from './ressources.ts';
|
|
import { largeurQuartier, hauteurLibre, borneSocle } from './cadrage.ts';
|
|
import { RETOUCHES_EN_FOND, PISTE, gabaritCourant, trajetsVelos, ATTENTE_VELO } from './retouches.ts';
|
|
import { LUMIERES, TRAIT_M } from './rendu.ts';
|
|
|
|
// lot ⑤ (07/11) : la zone de toucher des petits objets qui roulent (rayon en px CSS autour de leur centre à l'écran ; 0 l'éteint).
|
|
// À 390 px en vue quartier, la Rosalie fait ≈ 7 px : sans cette zone, elle ne se touche pas au doigt.
|
|
const TOUCHER_PETITS = 22;
|
|
|
|
// lot ④ (06/11) : la largeur du cadrage `maison` en S (m ; 0 rend l'ancien cadrage), et le témoin détaillé en mode fond
|
|
// (faux : le fond reste identique au pixel, docs/EMBED.md).
|
|
const LARGEUR_S = 26;
|
|
const DETAILS_EN_FOND = false;
|
|
|
|
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 = () => {}, differer = false, rendu = 'avant' }) {
|
|
const t0 = performance.now();
|
|
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;
|
|
// retouches du 07/11 (retouches.ts) : lieu commun, minibus coupé au bord du socle, vélos sur leur piste et sur les sentiers ;
|
|
// jamais en mode fond (le fond reste identique au pixel)
|
|
const retouches = !fond || RETOUCHES_EN_FOND;
|
|
if (retouches) renderer.localClippingEnabled = true;
|
|
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);
|
|
|
|
// lot M1 (rendu.ts) : `trait` rend le quartier au trait, lumière franche et ombre grise ; jamais en mode fond (au pixel)
|
|
const trait = rendu === 'trait' && !fond, LUM = LUMIERES[trait ? 'trait' : 'avant'];
|
|
// lumière : soleil bas du sud-ouest ; avant, un ciel chaud et des ombres légères (un lavis) ; au trait, un soleil franc
|
|
// et un ciel refroidi (l'ombre grise, les aplats dans la palette)
|
|
scene.add(new THREE.HemisphereLight(LUM.ciel, LUM.sol, LUM.hemi));
|
|
const soleil = new THREE.DirectionalLight(LUM.soleil, LUM.intensite);
|
|
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 = LUM.ombre;
|
|
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);
|
|
// lot ⑥b : quand on arrive sur la vue « Le territoire » (la maquette tue dessous), les images de la scène attendent
|
|
// `charger()` : la carte et ses tuiles passent d'abord sur un réseau lent. Ailleurs, rien ne change.
|
|
let attente = differer ? [] : null;
|
|
const charger = (url, fin) => {
|
|
if (!attente) return chargeur.load(url, fin);
|
|
const t = new THREE.Texture();
|
|
attente.push(() => chargeur.load(url, (x) => { t.image = x.image; t.needsUpdate = true; if (fin) fin(); }));
|
|
return t;
|
|
};
|
|
const tex = (url) => { const t = charger(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
|
|
// lot M1 (X3) : au trait, une seule encre pour tout ce qui est posé (maisons, serres, témoin), atténuée (jamais les faces)
|
|
const encre = trait ? new THREE.LineBasicMaterial({ color: PAL.trait, transparent: true, opacity: TRAIT_M.opacite }) : null;
|
|
const matTrait = encre || 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: encre || 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;
|
|
// retouches du 07/11 (T2) : « une maison devient le lieu commun, c'est tout » ; le grand bâtiment prend le gabarit d'une
|
|
// maison courante du plan (retouches.ts), à un bout de son ancienne emprise ; l'autre bout devient sa terrasse
|
|
let commun = null;
|
|
if (estGrand && retouches && variante === '2035') { // aujourd'hui, le grand bâtiment reste tel quel (checkpoint du 10/11)
|
|
const gc = gabaritCourant(D.maisons), axeX = Lu >= Lv, long0 = Math.max(Lu, Lv), court0 = Math.min(Lu, Lv);
|
|
if (axeX) { Lu = gc.long; Lv = gc.court; } else { Lu = gc.court; Lv = gc.long; }
|
|
const rot = Math.atan2(-u.y, u.x), vz = axeX ? -Math.sin(rot) : Math.cos(rot), s = vz > 0 ? -1 : 1; // vers le nord : la terrasse devant
|
|
commun = { axeX, s, dec: (long0 - gc.long) / 2, long: long0 - gc.long, court: court0, mi: gc.long / 2 };
|
|
}
|
|
const haut = estGrand && !commun;
|
|
const eave = haut ? 7.4 : 5.4, rh = Math.min(haut ? 5 : 3.4, Lv * (haut ? 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);
|
|
const arT = new THREE.LineSegments(new THREE.EdgesGeometry(t.geometry, 20), matTrait); g.add(arT);
|
|
if (commun) { for (const o of g.children) o.position[commun.axeX ? 'x' : 'z'] += commun.s * commun.dec; g.userData.commun = commun; }
|
|
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);
|
|
// maison.js (lot ④) reprend ces volumes pour le trait et l'écorché du témoin
|
|
Object.assign(info, { gout, desc, filtre, pompe, ze, xd: desc.position.x, murs, toitM: t, pg, serre, aretes: [ar, arT, as] });
|
|
}
|
|
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;
|
|
}
|
|
// les maisons qui ne changent pas d'époque gardent leur groupe (par indice du plan) : les objets nouveaux en font des
|
|
// cliquables (la colocation, la grande maison des tiny houses, les deux maisons du jardin commun)
|
|
const groupes2035 = []; // lot ⑤ : le groupe de chaque maison du plan en 2035, par indice (les parcelles cliquables)
|
|
const groupesMaisons = D.maisons.map((h) => {
|
|
if (h.t === 'transformee') { const g = maison(h, '2035'); G.v2035.add(g); G.vAuj.add(maison(h, 'auj')); groupes2035.push(g); return null; }
|
|
// retouches (T2) : le lieu commun rapetisse en 2035 seulement ; aujourd'hui garde le grand bâtiment (l'« aujourd'hui »
|
|
// d'abord : `maison()` retient le dernier grand bâtiment construit, celui de 2035)
|
|
if (h.t === 'grand' && retouches) { G.vAuj.add(maison(h, 'auj')); const g = maison(h, '2035'); G.v2035.add(g); groupes2035.push(g); return g; }
|
|
const g = maison(h, '2035'); scene.add(g); groupes2035.push(g); return g;
|
|
});
|
|
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' });
|
|
// retouches du 07/11 (T2) : la terrasse du lieu commun, sur le reste de l'ancienne emprise (le sol de 2035 y dessine
|
|
// encore le plan du grand bâtiment) : gravier, deux tables, des bancs, du monde. En 2035 seulement ; elle ouvre la parcelle.
|
|
if (grand && grand.userData.commun) {
|
|
const c = grand.userData.commun, tg = new THREE.Group(), gr = new THREE.MeshLambertMaterial({ color: '#d8cfbd' }), bois = new THREE.MeshLambertMaterial({ color: '#c49a64' });
|
|
tg.position.copy(grand.position); tg.rotation.y = grand.rotation.y;
|
|
const ter = new THREE.Group(); ter.position[c.axeX ? 'x' : 'z'] = -c.s * c.mi; if (!c.axeX) ter.rotation.y = Math.PI / 2; tg.add(ter);
|
|
// le sol couvre toute l'ancienne emprise, débord compris (les murs dessinés du plan ne dépassent plus), la maison posée dessus
|
|
const L0 = c.long + 2 * c.mi + 1.0, l0 = c.court + 1.2, sol = new THREE.Mesh(new THREE.BoxGeometry(c.axeX ? L0 : l0, 0.06, c.axeX ? l0 : L0), gr);
|
|
sol.position.y = 0.03; sol.receiveShadow = true; tg.add(sol);
|
|
// deux tables et leurs bancs : une seule géométrie (un appel de dessin)
|
|
const pers = [], B = (x, y, z, px, py, pz) => new THREE.BoxGeometry(x, y, z).translate(px, py, pz), bouts = [];
|
|
for (const dx of [-c.long / 4, c.long / 4]) {
|
|
bouts.push(B(3.4, 0.08, 0.9, dx, 0.76, 0));
|
|
for (const dz of [-0.75, 0.75]) { bouts.push(B(3.2, 0.06, 0.34, dx, 0.45, dz)); pers.push([dx - 0.9, dz], [dx + 0.6, dz]); }
|
|
for (const [a, b] of [[1.5, 0.35], [-1.5, 0.35], [1.5, -0.35], [-1.5, -0.35]]) bouts.push(B(0.07, 0.72, 0.07, dx + a, 0.36, b));
|
|
}
|
|
const tables = new THREE.Mesh(mergeGeometries(bouts), bois); tables.castShadow = true; ter.add(tables);
|
|
// des gens assis (les quilles de scene.js : geoP n'est pas encore construite ici, même forme)
|
|
const imT = new THREE.InstancedMesh(quille(trait), new THREE.MeshLambertMaterial({ color: '#ffffff' }), pers.length);
|
|
pers.forEach(([x, z], i) => { imT.setMatrixAt(i, new THREE.Matrix4().makeScale(1, 0.62, 1).setPosition(x, 0.93, z)); imT.setColorAt(i, new THREE.Color(PAL.gens[(i * 3 + 2) % PAL.gens.length])); });
|
|
imT.instanceColor.needsUpdate = true; imT.castShadow = true; ter.add(imT);
|
|
G.v2035.add(tg); cliquables.push({ o: tg, fiche: 'quartier-communs', parcelle: D.maisons.findIndex((h) => h.t === 'grand') });
|
|
}
|
|
|
|
// ---------------------------------------------------------------- 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);
|
|
// le lot des haies se dessine AVANT les poses : lot() écrit centre, rx, ry, haut sur chaque arbre, que plan() (gestes.js)
|
|
// et les étiquettes des essences lisent ; dessiné après, les couronnes des haies n'existaient pas pour la pose et les
|
|
// étiquettes partaient à NaN (revue du checkpoint du 03/11). La haie du jardin commun (objets.js) se redessine plus bas.
|
|
let lotHaies = lot(itemsHaies, matsHaie, E.reglages.fruits);
|
|
G.v2035.add(lotHaies);
|
|
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 = quille(trait); // lot M1 (X5) : au trait, les personnages ont une tête
|
|
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);
|
|
cliquables.push({ o: vie.troupeau, fiche: 'vivant-animaux' }, { o: vie.basse, fiche: 'vivant-animaux' }); // lot ⑤ (P4) : moutons, chèvres et poules se touchent
|
|
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; };
|
|
// lot ④ : le cycliste assis sur la selle (animaux.js) ; en mode fond, l'ancien vélo (le fond reste identique au pixel)
|
|
const velo = (c) => veloA(c, !fond);
|
|
// retouches du 07/11 (T3, « le bus qui roule sur les vélos ») : vélos, cargos et charrette prennent la piste au bord de la
|
|
// route (± PISTE), le minibus garde sa voie (VOIE_BUS, objets.js) ; aucun tronçon partagé. Le mode fond garde les anciens décalages.
|
|
const piste = (d) => (retouches ? Math.sign(d) * PISTE : d);
|
|
ajoute(velo(PAL.gens[0]), tr.principale, 4.2, piste(2.8), 0.1, G.v2035, 'velo'); ajoute(velo(PAL.gens[3]), tr.principale, 3.8, piste(-2.6), 0.65, G.v2035, 'velo');
|
|
ajoute(velo(PAL.gens[1]), tr.verticale, 4.0, piste(2.2), 0.4, G.v2035, 'velo'); ajoute(velo(PAL.gens[4]), tr.anneau, 3.5, piste(2.0), 0.2, G.v2035, 'velo');
|
|
ajoute(veloCargo(PAL.gens[2], trait), tr.principale, 3.2, piste(-2.4), 0.3, G.v2035, 'cargo'); ajoute(veloCargo(PAL.gens[5], trait), tr.verticale, 3.0, piste(-2.0), 0.75, G.v2035, 'cargo');
|
|
const attelageM = ajoute(attelage(trait), tr.principale, 1.6, piste(2.2), 0.55, G.v2035, 'attelage');
|
|
cliquables.push({ o: attelageM.obj, fiche: 'quartier-mobilite' }); // lot ⑤ (P4) : la charrette ouvre « À pied, à vélo, en charrette »
|
|
const partagee = ajoute(voiture('#7fa3a6', true), tr.principale, 7, 1.8, 0.85, G.v2035, 'partagee');
|
|
// lot ⑤ (P3 ③) : la voiture partagée existe en M ; elle se touche (fiche de la voiture pour trois maisons) et brille.
|
|
// Ses matériaux lui deviennent propres (MAT.partage n'est qu'à elle, les boules jaunes sont neuves), pas en mode fond.
|
|
cliquables.push({ o: partagee.obj, fiche: 'transport-voiture' });
|
|
const brillePropres = { travail: [] };
|
|
if (!fond) partagee.obj.traverse((o) => { if (o.material && o.material.emissive) { o.material = o.material.clone(); brillePropres.travail.push(o.material); } });
|
|
if (cheminsLongs[0]) ajoute(velo(PAL.gens[6]), cheminsLongs[0], 3.2, 0, 0.3, G.v2035, 'velo');
|
|
// retouches du 07/11 (T4) : des vélos sur les sentiers piétons, entre les maisons, jusqu'au fond de la forêt (trajets
|
|
// calculés sur les sentiers du plan, retouches.ts) ; aller simple : ils paraissent au départ, disparaissent dans la forêt
|
|
// et repartent après une attente ; arrêtés sous mouvement réduit. Ils ouvrent « À pied, à vélo, en charrette ». T5 : le
|
|
// trajet des deux vélos du témoin (maison.js), sur le sentier qui longe la haie et la noue.
|
|
const velosT = retouches ? trajetsVelos(D, [T.c.x, T.c.y]) : null, velosSentiers = [];
|
|
if (velosT) velosT.sentiers.forEach((o, k) => {
|
|
const t = trajet(o.pts), v = velo(PAL.gens[(k * 3 + 5) % PAL.gens.length]), cycle = t.L + o.v * ATTENTE_VELO; G.v2035.add(v);
|
|
const pose = (tt) => {
|
|
const u = ((reduit ? 0 : tt) * o.v + o.ph * cycle) % cycle; v.visible = u <= t.L; if (!v.visible) return;
|
|
const p = surTrajet(t, u), n = Math.hypot(p.dx, p.dz) || 1; v.position.set(p.x, 0, p.z); v.rotation.y = Math.atan2(-p.dz / n, p.dx / n);
|
|
v.scale.setScalar(Math.max(0.01, Math.min(1, u / 1.5, (t.L - u) / 1.5))); // il paraît et disparaît en un mètre et demi
|
|
};
|
|
pose(0); anim.push(pose); cliquables.push({ o: v, fiche: 'quartier-mobilite', siVisible: true }); velosSentiers.push({ L: t.L, v: o.v, pts: o.pts, obj: v });
|
|
});
|
|
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 = retouches ? PISTE : 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, objs: membres.map((m) => m.o) };
|
|
})();
|
|
|
|
// ---------------------------------------------------------------- les objets nouveaux (31/10, objets.js) et ceux du Tour,
|
|
// cliquables : chacun ouvre sa fiche, a son cadrage et s'allume quand on la lit. Tous de 2035.
|
|
const objets = objetsNouveaux({ D, groupe: G.v2035, T, P: gestes.P, maisons: groupesMaisons, tr, PAL, geoP, verre: mat.verre, matsArbres: matsAutres,
|
|
tour: gestes, convoi, fond, aujourdhui: G.vAuj });
|
|
anim.push(...objets.anim);
|
|
cliquables.push(...objets.cliquables);
|
|
if (objets.haieOuverte) {
|
|
// la haie entre les deux maisons du jardin commun s'ouvre : le lot se redessine sans les arbres de ce morceau
|
|
const o = objets.haieOuverte;
|
|
G.v2035.remove(lotHaies);
|
|
lotHaies = lot(itemsHaies.filter((it) => !(it.haie === o.k && it.s > o.s0 && it.s < o.s1)), matsHaie, E.reglages.fruits);
|
|
G.v2035.add(lotHaies);
|
|
}
|
|
// ---------------------------------------------------------------- la maison témoin détaillée (lot ④, maison.js) : après les
|
|
// objets nouveaux (l'ordre de construction ne change aucune pose), en démo seulement (M8)
|
|
const temoin = !fond || DETAILS_EN_FOND ? detaillerTemoin({ T, D, PAL, mat, matT, geoP, groupe: G.v2035, velo, reduit, P: gestes.P, trajetVelos: velosT ? velosT.temoin : null,
|
|
evite: [...Object.values(objets.points), ...Object.values(gestes.points)].filter(Boolean) }) : null;
|
|
if (temoin) { anim.push(...temoin.anim); cliquables.unshift(...temoin.cliquables); } // avant la maison : ses morceaux ouvrent leur fiche
|
|
// lot ⑤ (P1) : chaque maison du plan est une parcelle. Une maison déjà cliquable (transformée, grand bâtiment, colocation,
|
|
// tiny houses, jardin commun) garde sa fiche et reçoit son indice ; les autres deviennent cliquables, sans fiche. C'est
|
|
// main.js qui choisit : la parcelle en M (2035), la fiche d'avant en S.
|
|
groupes2035.forEach((g, i) => {
|
|
const deja = cliquables.filter((c) => c.o === g);
|
|
if (deja.length) deja.forEach((c) => (c.parcelle = i)); else cliquables.push({ o: g, fiche: null, parcelle: i });
|
|
});
|
|
// les petits objets qui roulent : on les touche à TOUCHER_PETITS px de leur centre à l'écran
|
|
const petits = [
|
|
objets.points.rosalie && { c: objets.points.rosalie, fiche: 'quartier-rosalie' },
|
|
objets.points.navette && { c: objets.points.navette, fiche: 'quartier-navette' },
|
|
objets.points.bus && { c: objets.points.bus, fiche: 'quartier-bus' },
|
|
{ c: partagee.obj.position, fiche: 'transport-voiture' },
|
|
{ c: attelageM.obj.position, fiche: 'quartier-mobilite' },
|
|
// checkpoint du 10/11 : les vélos des sentiers (≈ 10 px à l'arrivée au téléphone) se touchent comme la Rosalie
|
|
...velosSentiers.map((o) => ({ c: o.obj.position, o: o.obj, fiche: 'quartier-mobilite' })),
|
|
].filter(Boolean);
|
|
|
|
// ---------------------------------------------------------------- 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 = charger(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
|
|
// lot ④ (M1) : en S, la caméra cadre la maison témoin de plus près (26 m au bureau ; la règle portrait de cadrer() s'applique)
|
|
maison: LARGEUR_S ? T_({ x: T.c.x, z: T.c.y, w: LARGEUR_S }) : 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;
|
|
// un cadrage par objet (objets.js) : fixe, ou qui suit le véhicule (navette, bus, Rosalie, convoi) tant qu'on ne touche pas
|
|
for (const [nom, p] of Object.entries(objets.points)) {
|
|
if (CAD[nom]) continue;
|
|
CAD[nom] = p.w ? { x: p.x, z: p.z, w: p.w } : { get x() { return p.x; }, get z() { return p.z; }, w: 56, suit: true };
|
|
}
|
|
// lot ⑤ : un cadrage par parcelle (la maison au centre, 44 m vus), « parcelle-<indice> »
|
|
groupes2035.forEach((g, i) => { CAD[`parcelle-${i}`] = { x: g.position.x, z: g.position.z, w: 44 }; });
|
|
|
|
// ---------------------------------------------------------------- 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 });
|
|
let suivi = null; // un cadrage qui suit un véhicule : le décalage du panneau, gardé
|
|
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), cx = c.x, cz = c.z;
|
|
// 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 (nom === 'quartier') {
|
|
// retouches du 09/11 (T7, cadrage.ts) : en portrait (démo), le socle remplit la hauteur libre, la largeur déborde et le
|
|
// doigt fait le reste ; au bureau et en mode fond, rien ne change (la règle du 03/11 reste celle du fond)
|
|
const q = largeurQuartier({ W, H, w0: w, hLibre: hauteurLibre(H, p), Hm: D.Hm, el: vue.el, fond });
|
|
w = q.w; if (q.plein) { cx = 0; cz = 0; }
|
|
} else if (W < H && w < 400) w *= 0.8; // en portrait, la largeur de l'écran est la dimension qui manque (les fiches)
|
|
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: cx - ra * offX - fa * offY, z: cz - rza * offX - fza * offY, az, el: vue.el, w };
|
|
suivi = c.suit && !reduit ? { nom, ox: apres.x - c.x, oz: apres.z - c.z } : null; // sous mouvement réduit, la caméra ne suit pas le véhicule (checkpoint du 03/11)
|
|
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'); });
|
|
// retouches du 09/11 (T7) : le centre de la zone libre, au sol, et la demi-étendue vue (m) ; le doigt le garde sur le socle
|
|
function centreLibre() {
|
|
const p = panneau_(), { W, H } = taille(), haut = p.haut ?? 64, y1 = Math.max(haut + 1, H - (p.bas - 64 + haut)), wpp = vue.w / W;
|
|
return { g: solSous((p.gauche + W) / 2, (haut + y1) / 2), r: ((W - p.gauche) / 2) * wpp, f: ((y1 - haut) / 2) * wpp / Math.sin(vue.el) };
|
|
}
|
|
ecoute('pointermove', (e) => {
|
|
if (!ptrs.has(e.pointerId)) return;
|
|
const c0 = e.pointerType !== 'mouse' ? centreLibre().g : null;
|
|
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;
|
|
}
|
|
// borné au socle (cadrage.ts), au doigt seulement : la souris du bureau garde son glissé libre (checkpoint du 10/11)
|
|
if (e.pointerType !== 'mouse') { const c1 = centreLibre(), b = borneSocle(c1.g, c0, c1, vue.az, D.Wm, D.Hm); vue.x += b.x - c1.g.x; vue.z += b.z - c1.g.z; }
|
|
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', garage: 'quartier-atelier' };
|
|
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; }
|
|
// lot ⑤ : un petit objet qui roule, à TOUCHER_PETITS px de son centre à l'écran (le plus proche), passe avant le reste
|
|
if (TOUCHER_PETITS > 0) {
|
|
let best = null;
|
|
// un objet caché (le minibus qui attend hors champ, un vélo des sentiers entre deux passages) ne se touche pas
|
|
for (const p of petits) { if (p.c.cache || (p.o && !p.o.visible)) continue; const e = versEcran(p.c.x, 1, p.c.z), d = Math.hypot(e.x - px, e.y - py); if (d <= TOUCHER_PETITS && (!best || d < best.d)) best = { d, p }; }
|
|
if (best) { onToucher('fiche', best.p.fiche, null); return; }
|
|
}
|
|
const hits = ray.intersectObjects(cliquables.filter((c) => !c.siVisible || c.o.visible).map((c) => c.o), true); // le Raycaster ignore `visible`
|
|
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, c.parcelle ?? null); }
|
|
}
|
|
const vEcran = new THREE.Vector3();
|
|
function versEcran(x, y, z) { vEcran.set(x, y, z).project(cam); const { W, H } = taille(); return { x: (vEcran.x + 1) / 2 * W, y: (1 - vEcran.y) / 2 * H };
|
|
}
|
|
|
|
// ---------------------------------------------------------------- état : époque, effet
|
|
const etat = { epoque: '2035', fx: null, fxs: new Set(), auj: 0, cibleAuj: 0, fond: false, brille: null };
|
|
function epoque(e) { etat.epoque = e; etat.cibleAuj = e === 'auj' ? 1 : 0; G.v2035.visible = e === '2035'; G.vAuj.visible = e === 'auj'; besoin = true; }
|
|
// un effet (une fiche), ou plusieurs ensemble (lot ④ : l'allumage sous mouvement réduit allume tout le chapitre)
|
|
function effets(noms) {
|
|
const L = (noms || []).filter(Boolean); etat.fx = L[0] || null; etat.fxs = new Set(L);
|
|
chantier.visible = etat.fxs.has('chantier') || etat.fond; besoin = true;
|
|
}
|
|
const effet = (nom) => effets([nom]);
|
|
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);
|
|
// checkpoint du 10/11 : le téléphone qui pivote refait le cadrage d'arrivée (portrait : pleine hauteur ; paysage : la règle
|
|
// du bureau), si la vue n'a pas bougé depuis ; après le bandeau, qui se remesure au même évènement (main.js)
|
|
let portrait = null;
|
|
function redim() {
|
|
const { W, H } = taille(); renderer.setSize(W, H, false); besoin = true;
|
|
const p = W < H; if (!fond && portrait !== null && p !== portrait && cadrageCourant === 'quartier') requestAnimationFrame(() => cadrer('quartier', 0, true));
|
|
portrait = p;
|
|
}
|
|
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;
|
|
// lot ④ : plusieurs effets peuvent être allumés ensemble (sous mouvement réduit, tout le chapitre de la maison) ; `on(k)`
|
|
// vaut `fx === k` quand un seul l'est (la démo en M, le mode fond : rien ne change)
|
|
const puls = reduit && !fond && !etat.fond ? 0.7 : 0.5 + 0.5 * Math.sin(t * 2.6), fxs = etat.fxs, on = (k) => fxs.has(k);
|
|
const eauT = (i) => i === D.temoin.noue;
|
|
surv.noues.forEach((m) => (m.material.opacity = on('noue-plantes') ? (eauT(m.userData.i) ? 0.3 + 0.3 * puls : 0.12) : on('mare') || on('phyto') ? 0.22 : on('eaux-grises') && eauT(m.userData.i) ? 0.3 : 0));
|
|
surv.bassins.forEach((m) => (m.material.opacity = on('mare') || on('phyto') ? 0.3 + 0.3 * puls : 0));
|
|
surv.sentiers.forEach((m) => (m.material.opacity = on('sentiers') ? 0.3 + 0.35 * puls : 0));
|
|
surv.liaisons.forEach((m) => { m.material.uniforms.uT.value = t; m.material.uniforms.uA.value = on('eaux-grises') ? (m.userData.i === D.temoin.liaison ? 0.95 : 0.12) : on('mare') ? 0.35 : 0; });
|
|
surv.chemins.forEach((m) => { m.material.uniforms.uT.value = t; m.material.uniforms.uA.value = on('sentiers') || on('mobilite') ? 0.9 : on('foret') ? 0.5 : 0; });
|
|
const vivant = on('haie-essences') || on('strates') || on('nourrir');
|
|
pulseEm(matsHaie.couronne, vivant, 0.1, 0.2, 0.02, puls);
|
|
pulseEm(matsForet.couronne, on('foret'), 0.08, 0.18, 0.04, puls);
|
|
pulseEm(mat.paille, on('transformees'), 0.26, 0.16, 0, puls);
|
|
pulseEm(matT.paille, on('paille') || on('chantier') || on('transformees'), 0.26, 0.16, 0, puls);
|
|
pulseEm(matT.verre, on('serre'), 0.3, 0.25, 0.05, puls);
|
|
pulseEm(matT.cuve, on('cuve') || on('pompe'), 0.05, 0.22, 0.4, puls);
|
|
pulseEm(matT.chem, on('poele'), 0.35, 0.12, 0, puls);
|
|
pulseEm(mat.pompe, on('pompe'), 0.05, 0.25, 0.45, puls);
|
|
pulseEm(mat.grandToit, on('communs'), 0.35, 0.12, 0, puls);
|
|
matEtal.forEach((m) => pulseEm(m, on('marche'), 0.25, 0.14, 0, puls));
|
|
// les objets (objets.js) et les morceaux du témoin (maison.js) : un émissif léger par-dessus leur émissif propre
|
|
// lot ⑤ (R5) : « certaines images brillent un peu » ; les effets de `etat.brille` pulsent lentement (ressources.ts), jamais
|
|
// en mode fond ni sous mouvement réduit ; une fiche allumée garde son allumage habituel (on(nom) passe avant)
|
|
const kB = (etat.kB = etat.brille && !fond && !etat.fond ? intensiteBrille(t * 1000, reduit) : 0), brille = (nom) => (kB > 0 && etat.brille.has(nom) ? kB : 0);
|
|
for (const lum of temoin ? [objets.lumieres, temoin.lumieres] : [objets.lumieres]) for (const [nom, L] of Object.entries(lum)) {
|
|
const k = on(nom) ? puls : lum === objets.lumieres ? brille(nom) : 0;
|
|
for (const m of L) { const b = (m.userData.base ??= m.emissive.clone()); m.emissive.setRGB(b.r + 0.26 * k, b.g + 0.17 * k, b.b + 0.05 * k); }
|
|
}
|
|
for (const [nom, L] of Object.entries(brillePropres)) { const k = brille(nom); for (const m of L) m.emissive.setRGB(0.26 * k, 0.17 * k, 0.05 * k); }
|
|
if (!on('marche') && brille('marche')) matEtal.forEach((m) => pulseEm(m, true, 0.25, 0.14, 0, brille('marche')));
|
|
if (!on('communs') && brille('communs')) pulseEm(mat.grandToit, true, 0.35, 0.12, 0, brille('communs'));
|
|
if (imPotager) pulseEm(imPotager.material, on('strates') || on('nourrir'), 0.15, 0.12, 0, puls);
|
|
eauV.meshes.forEach((m) => pulseEm(m.material, on('noue-plantes') || on('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 += ((on(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 o = on('pluie-toit'); p.s.material.opacity = o ? 0.75 : 0; if (!o) 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 = on('gouttiere') || on('filtre'); filets.gouttiere.maj(t); }
|
|
if (filets.pompe) { filets.pompe.on = on('pompe'); filets.pompe.maj(t); }
|
|
if (filets['eaux-grises']) { filets['eaux-grises'].on = on('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 = on('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, a = on('mare') || on('phyto'); o.scale.setScalar(1 + k * 11); o.material.opacity = a ? 0.6 * (1 - k) : 0; });
|
|
const LIEES = { 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'] };
|
|
const lieesA = [...fxs].flatMap((k) => LIEES[k] || []);
|
|
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, o = lieesA.includes(u.id), k = (o ? 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 = (on('haie-essences') || on('noue-plantes') || on('strates')) && !o ? 0.25 : lieesA.length && !o ? 0.55 : 1; });
|
|
anim.forEach((f) => f(t));
|
|
if (temoin) temoin.maj(dt, { on, fxs, cam, reduit, paille: matT.paille });
|
|
vie.troupeau.children.forEach((o, i) => { o.position.y = on('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 = on('mobilite') || on('travail');
|
|
mobiles.forEach((m) => { if (m.role && m.obj.children) { const k = vMob && (m.role === 'cargo' || m.role === 'attelage' || (on('travail') && m.role === 'partagee')) ? 1.25 : 1; m.obj.scale.setScalar(k); } });
|
|
if (G.v2035.visible) { convoi.maj(dt); objets.maj.forEach((f) => f(dt)); }
|
|
if (kB > 0) besoin = true;
|
|
// la caméra suit le véhicule de la fiche, en douceur, tant que personne ne la reprend
|
|
if (suivi && suivi.nom === cadrageCourant && !vol && !scenario) { const c = CAD[suivi.nom], k = Math.min(1, dt * 2.5); vue.x += (c.x + suivi.ox - vue.x) * k; vue.z += (c.z + suivi.oz - vue.z) * k; }
|
|
// 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();
|
|
}
|
|
|
|
// ---------------------------------------------------------------- lot M1 (X3) : le trait, fusionné par famille
|
|
// Une fois tout posé (objets, témoin) : les arêtes à l'encre et celles des serres, visibles et fixes, deviennent une
|
|
// seule LineSegments par racine (le quartier, 2035, aujourd'hui) ; les faces voisines reculent d'un cran (polygonOffset)
|
|
// pour que le trait ne scintille pas. Les arbres instanciés ont un contour : une coque inversée à l'encre, enfant de leur
|
|
// InstancedMesh (elle en partage les matrices et la visibilité). Les bêtes et les objets du Tour n'ont pas de trait.
|
|
const mesureTrait = { familles: 0, segments: 0, fusionnees: 0, coques: 0 };
|
|
if (trait) {
|
|
scene.updateMatrixWorld(true);
|
|
const racines = [G.v2035, G.vAuj, scene], par = new Map(), bordSerre = new THREE.Color('#86ada7'), recule = new Set();
|
|
const lignes = [];
|
|
scene.traverse((o) => { if (o.isLineSegments && o.material && (o.material === encre || (o.material.isLineBasicMaterial && o.material.color.equals(bordSerre)))) lignes.push(o); });
|
|
for (const o of lignes) {
|
|
let v = o.visible, r = o.parent;
|
|
while (r && !racines.includes(r)) { v = v && r.visible; r = r.parent; }
|
|
if (!v || !r) continue; // le témoin : maison.js cache ses arêtes (il a son propre trait, rattaché à l'encre plus bas)
|
|
const m = new THREE.Matrix4().copy(r.matrixWorld).invert().multiply(o.matrixWorld);
|
|
(par.get(r) || par.set(r, []).get(r)).push(o.geometry.clone().applyMatrix4(m));
|
|
for (const f of o.parent.children) if (f.isMesh && !f.isInstancedMesh) for (const mt of [f.material].flat()) recule.add(mt);
|
|
o.parent.remove(o); mesureTrait.fusionnees++;
|
|
}
|
|
for (const [r, geos] of par) {
|
|
const l = new THREE.LineSegments(mergeGeometries(geos), encre); l.matrixAutoUpdate = false; r.add(l);
|
|
mesureTrait.familles++; mesureTrait.segments += l.geometry.attributes.position.count / 2;
|
|
}
|
|
for (const mt of recule) if (mt && !mt.transparent) Object.assign(mt, { polygonOffset: true, polygonOffsetFactor: 1, polygonOffsetUnits: 1 });
|
|
if (temoin && temoin.meshes.trait) temoin.meshes.trait.material = encre;
|
|
// le contour des arbres : la coque (TRAIT_M.coque) de chaque couronne, faces arrière seulement
|
|
const couronnes = new Set(TRAIT_M.contours.map((k) => ({ haies: matsHaie, foret: matsForet, autres: matsAutres })[k].couronne)), coques = new Map();
|
|
const encreCoque = new THREE.MeshBasicMaterial({ color: new THREE.Color(PAL.trait).lerp(new THREE.Color(PAL.fond), 1 - TRAIT_M.coqueOpacite), side: THREE.BackSide });
|
|
const ims = []; scene.traverse((o) => { if (o.isInstancedMesh && couronnes.has(o.material)) ims.push(o); });
|
|
for (const im of ims) {
|
|
if (!coques.has(im.geometry)) coques.set(im.geometry, geoCoque(im.geometry, TRAIT_M.coque));
|
|
if (!coques.get(im.geometry)) continue;
|
|
const c = new THREE.InstancedMesh(coques.get(im.geometry), encreCoque, im.count);
|
|
c.instanceMatrix = im.instanceMatrix; c.count = im.count; c.frustumCulled = im.frustumCulled; c.raycast = () => {};
|
|
im.add(c); mesureTrait.coques++;
|
|
}
|
|
}
|
|
|
|
// `?mesure` dans l'adresse : les instruments du RECAP (triangles, temps de construction, position à l'écran d'un objet),
|
|
// lus par les scripts de capture ; rien sans ce paramètre
|
|
if (/[?&]mesure\b/.test(location.search)) {
|
|
const v = new THREE.Vector3();
|
|
// lot ⑤ : les maisons que portent les objets, le centre de chaque parcelle, ce qui brille, et la taille à l'écran de
|
|
// chaque objet cliquable (px CSS, boîte englobante projetée) : la check-list du thème 2 au RECAP
|
|
const B3 = new THREE.Box3(), coins = [];
|
|
const tailles = () => {
|
|
const par = {};
|
|
for (const c of cliquables) {
|
|
if (!c.fiche || !c.o.visible || (c.o.parent && !c.o.parent.visible)) continue;
|
|
B3.setFromObject(c.o); if (B3.isEmpty()) continue;
|
|
coins.length = 0; for (const x of [B3.min.x, B3.max.x]) for (const y of [B3.min.y, B3.max.y]) for (const z of [B3.min.z, B3.max.z]) coins.push(versEcran(x, y, z));
|
|
const r = { x0: Math.min(...coins.map((e) => e.x)), x1: Math.max(...coins.map((e) => e.x)), y0: Math.min(...coins.map((e) => e.y)), y1: Math.max(...coins.map((e) => e.y)) };
|
|
const p = (par[c.fiche] ??= { x0: Infinity, x1: -Infinity, y0: Infinity, y1: -Infinity, n: 0 });
|
|
p.x0 = Math.min(p.x0, r.x0); p.x1 = Math.max(p.x1, r.x1); p.y0 = Math.min(p.y0, r.y0); p.y1 = Math.max(p.y1, r.y1); p.n++;
|
|
(p.morceaux ??= []).push({ l: Math.round(r.x1 - r.x0), h: Math.round(r.y1 - r.y0), cx: Math.round((r.x0 + r.x1) / 2), cy: Math.round((r.y0 + r.y1) / 2) });
|
|
}
|
|
return par;
|
|
};
|
|
window.__quartier = { renderer, construction: performance.now() - t0, laisses: objets.laisses, points: objets.points, cadrage: () => cadrageCourant,
|
|
maisonsObjets: objets.maisonsObjets, parcelles: groupes2035.map((g) => ({ x: g.position.x, z: g.position.z })), brille: () => (etat.brille ? [...etat.brille] : null), brilleK: () => etat.kB || 0, tailles,
|
|
ecranDe: (x, y, z) => versEcran(x, y, z),
|
|
// retouches du 09/11 (T7) : la vue courante, la zone libre (px) et le socle (m) ; le marqueur « N % de la hauteur libre »
|
|
vue: () => ({ ...vue }), libre: () => { const p = panneau_(), { H } = taille(), haut = p.haut ?? 64; return { haut, bas: haut + hauteurLibre(H, p), h: hauteurLibre(H, p) }; }, socle: { Wm: D.Wm, Hm: D.Hm },
|
|
// retouches du 07/11 : le minibus, la maison de maître, le lieu commun, les trajets des vélos (le RECAP les mesure)
|
|
retouches: { ...objets.retouches, velos: velosSentiers.map(({ L, v, pts }) => ({ L, v, pts })), velosTemoin: velosT ? velosT.temoin : null, commun: grand ? grand.userData.commun || null : null },
|
|
velosEcran: () => velosSentiers.filter((o) => o.obj.visible).map((o) => ({ ...versEcran(o.obj.position.x, 1, o.obj.position.z), x3: o.obj.position.x, z3: o.obj.position.z })),
|
|
// un vélo des sentiers « vu » : le premier objet que le rayon de la caméra rencontre est le vélo (aucune couronne devant)
|
|
velosVus: () => { const { W, H } = taille(); return velosSentiers.filter((o) => o.obj.visible).map((o) => { const e = versEcran(o.obj.position.x, 0.9, o.obj.position.z); ray.setFromCamera(new THREE.Vector2((e.x / W) * 2 - 1, -(e.y / H) * 2 + 1), cam); const h = ray.intersectObjects(G.v2035.children, true)[0]; let x = h && h.object; while (x && x !== o.obj) x = x.parent; return { x: e.x, y: e.y, vu: !!x }; }); },
|
|
velosTemoinEcran: () => (temoin ? Object.entries(temoin.meshes).filter(([k]) => k.startsWith('velo')).map(([, o]) => ({ ...versEcran(o.position.x, 1, o.position.z), x3: o.position.x, z3: o.position.z })) : []),
|
|
temoin: temoin ? temoin.mesure : null, effets: () => [...etat.fxs], trait: mesureTrait,
|
|
ecran(x, y, z) { v.set(x, y, z).project(cam); const { W, H } = taille(); return { x: (v.x + 1) / 2 * W, y: (1 - v.y) / 2 * H }; } };
|
|
}
|
|
return {
|
|
cadrer, effet, effets, epoque, tourner,
|
|
poserPanneau(f) { panneau_ = f; },
|
|
/** Lot ⑤ (R5) : les effets qui brillent (un Set), ou null pour éteindre la pulsation. */
|
|
brille(S) { const avant = etat.brille; etat.brille = S && S.size ? S : null; if (avant && !etat.brille) besoin = true; },
|
|
/** 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; },
|
|
/** Lot ⑥b : charge les images retenues par `differer` (rien sinon). */
|
|
charger() { if (!attente) return; const a = attente; attente = null; a.forEach((f) => f()); besoin = true; },
|
|
/** Lot ④ bis : la caméra est-elle en mouvement (un cadrage en cours) ? Le dessin de S attend la fin du vol. */
|
|
enVol: () => !!vol,
|
|
/** Accès clavier aux parcelles (checkpoint du lot ⑤) : la position à l'écran (px CSS) du haut de la maison `i`, ou null. */
|
|
ecranParcelle(i) { const g = groupes2035[i]; if (!g) return null; g.updateMatrixWorld(); const p = new THREE.Box3().setFromObject(g); return p.isEmpty() ? null : versEcran((p.min.x + p.max.x) / 2, p.max.y, (p.min.z + p.max.z) / 2); },
|
|
/** 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); },
|
|
};
|
|
}
|