Files
quartier/maquette/objets.js
T

773 lines
59 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Les objets nouveaux du quartier (31/10, LOT Q objets nouveaux) : la liste de la direction du 31/10 (soirées de Jules
// et Sacha des 25 et 26/10, carnet du 29/10), posée dans le quartier de 2035. La navette communale et le bus scolaire
// circulent ; un point fraîcheur, une colocation, un atelier, une conserverie, un potager partagé, des tiny houses autour
// d'une grande maison, deux maisons qui font jardin commun, des vélos cargos à prêter, la Rosalie, des ruches, la fête de
// la place, un terrain pour les forains, une parcelle en syntropie et un jardin punk.
// Même grammaire que gestes.js et animaux.js : formes de jouet en bois, palette de la planche, aucune texture, aucun
// texte, aucun chiffre. Les places sont calculées à la construction depuis le plan (data/scene2035.json), sur la même
// grille d'occupation que les gestes du Tour (P, gestes.js) : place libre sur toute l'emprise, et vue de la caméra.
// Si une place manque, l'objet n'est pas posé (et `laisses` dit lequel) : jamais en contradiction avec le plan.
import * as THREE from 'three';
import { mergeGeometries } from 'three/addons/utils/BufferGeometryUtils.js';
import { lot, teinte, rnd } from './vegetal.js';
import { MAT, veloCargo } from './animaux.js';
const lam = (c) => new THREE.MeshLambertMaterial({ color: c, emissive: '#000000' });
const mesh = (geo, m, x = 0, y = 0, z = 0, ombre = false) => { const o = new THREE.Mesh(geo, m); o.position.set(x, y, z); o.castShadow = ombre; o.receiveShadow = true; return o; };
const boite = (x, y, z) => new THREE.BoxGeometry(x, y, z);
const cyl = (r, h, n = 8) => new THREE.CylinderGeometry(r, r, h, n);
// teintes ajoutées dans l'esprit de la planche (bois, enduits, terre cuite, zinc) ; les autres viennent de PAL et MAT
const COUL = {
poteau: '#7b6a55', planche: '#c49a64', bois: '#b68f5f', boisGris: '#8f8576', enduit: '#e8e0cc', zinc: '#9aa3a6', sombre: '#3e3a35',
vitre: '#6f8c99', terre: '#8a7556', terreF: '#6f5a40', compost: '#4a3b2c', paillis: '#5b4a36', sable: '#e3d3a4', pierre: '#b9b2a6',
cuivre: '#b87333', brique: '#a0634a', tuile: '#c98466', navette: '#e8e3d6', eau: '#6aa3bd', abeille: '#e3b53a', toile: '#efe7d2',
};
const DOUX = ['#e3d3b8', '#c9d6c4', '#e6c9b8', '#cfd8de', '#efe4c4', '#d8c3d0']; // les tiny houses, les portes : des couleurs douces
// ---------------------------------------------------------------- géométries communes
// Un toit à deux pans, faîtage le long de x : longueur L, largeur W, hauteur h ; base à y = 0. Pignons compris.
function toit2(L, W, h) {
const x = L / 2, z = W / 2, g = new THREE.BufferGeometry();
g.setAttribute('position', new THREE.Float32BufferAttribute([
-x, 0, z, x, 0, z, x, h, 0, -x, 0, z, x, h, 0, -x, h, 0,
x, 0, -z, -x, 0, -z, -x, h, 0, x, 0, -z, -x, h, 0, x, h, 0,
x, 0, z, x, 0, -z, x, h, 0, -x, 0, -z, -x, 0, z, -x, h, 0], 3));
g.computeVertexNormals(); return g;
}
// Les gens sont des quilles (geoP de scene.js) : debout, assis (sur un banc de 0,46 m) ou enfants.
function quilles(geoP, L, couleurs) {
const im = new THREE.InstancedMesh(geoP, lam('#ffffff'), L.length), M = new THREE.Matrix4(), col = new THREE.Color();
L.forEach(([x, z, sorte], i) => {
const k = sorte === 'assis' ? [1, 0.62, 1] : sorte === 'enfant' ? [0.62, 0.62, 0.62] : [1, 1, 1];
const y = sorte === 'assis' ? 0.46 + 0.47 : 0.76 * k[1];
im.setMatrixAt(i, M.makeScale(...k).setPosition(x, y, z)); im.setColorAt(i, col.set(couleurs[(i * 3 + 1) % couleurs.length]));
});
im.instanceColor.needsUpdate = true; im.castShadow = true; return im;
}
// Un banc, une table : des planches sur pieds.
function banc(L, m, x, z, rot = 0) {
const g = new THREE.Group(); g.add(mesh(boite(L, 0.06, 0.36), m, 0, 0.44, 0));
for (const s of [1, -1]) g.add(mesh(boite(0.06, 0.42, 0.3), m, s * (L / 2 - 0.2), 0.21, 0));
g.position.set(x, 0, z); g.rotation.y = rot; return g;
}
function table(L, W, m, x, z, rot = 0) {
const g = new THREE.Group(); g.add(mesh(boite(L, 0.07, W), m, 0, 0.74, 0, true));
for (const [a, b] of [[1, 1], [1, -1], [-1, 1], [-1, -1]]) g.add(mesh(boite(0.07, 0.72, 0.07), m, a * (L / 2 - 0.15), 0.36, b * (W / 2 - 0.1)));
g.position.set(x, 0, z); g.rotation.y = rot; return g;
}
// ---------------------------------------------------------------- les véhicules (formes de jouet, avant vers +x)
// La navette communale : basse et ronde, 4 m, sans capot ni calandre ; deux bandeaux de vitres (un de chaque côté) et
// les deux bouts vitrés ; un petit dôme sombre sur le toit (ce qui la guide) ; quatre roues.
export function navette() {
const g = new THREE.Group(), m = lam(COUL.navette), v = lam(COUL.vitre);
g.add(mesh(new THREE.CapsuleGeometry(0.86, 2.3, 4, 14).rotateZ(Math.PI / 2), m, 0, 1.2, 0, true));
for (const s of [1, -1]) {
g.add(mesh(boite(2.7, 0.42, 0.05), v, 0, 1.48, s * 0.79));
g.add(mesh(boite(0.05, 0.4, 1.0).rotateZ(s * 0.5), v, s * 1.86, 1.42, 0));
}
g.add(mesh(new THREE.SphereGeometry(0.2, 10, 6, 0, Math.PI * 2, 0, Math.PI / 2), lam(COUL.sombre), 0.2, 2.03, 0));
for (const [x, z] of [[1.2, 0.74], [1.2, -0.74], [-1.2, 0.74], [-1.2, -0.74]]) g.add(mesh(cyl(0.31, 0.18, 12).rotateX(Math.PI / 2), MAT.roue, x, 0.31, z));
return g;
}
// Le bus scolaire : long et haut, 9 m ; un bandeau de vitres, un pare-brise, un toit clair, six roues.
export function bus(couleur) {
const g = new THREE.Group(), m = lam(couleur), v = lam(COUL.vitre);
g.add(mesh(boite(9, 2.3, 2.45), m, 0, 1.6, 0, true));
g.add(mesh(boite(8.9, 0.12, 2.3), lam('#e9e3d2'), 0, 2.81, 0));
g.add(mesh(boite(7.4, 0.72, 2.5), v, -0.5, 2.1, 0));
g.add(mesh(boite(0.06, 1.0, 2.2), v, 4.52, 1.95, 0));
for (const x of [3.1, -2.4, -3.4]) for (const z of [1.15, -1.15]) g.add(mesh(cyl(0.5, 0.26, 12).rotateX(Math.PI / 2), MAT.roue, x, 0.5, z));
return g;
}
// La Rosalie : un châssis bas à quatre roues, quatre places qui pédalent (des quilles assises), un auvent rayé.
export function rosalie(geoP, couleurs) {
const g = new THREE.Group(), cadre = lam('#5f7f5a');
g.add(mesh(boite(2.5, 0.12, 1.3), cadre, 0, 0.5, 0, true));
for (const [x, z] of [[0.95, 0.72], [0.95, -0.72], [-0.95, 0.72], [-0.95, -0.72]]) g.add(mesh(new THREE.TorusGeometry(0.32, 0.045, 5, 14), MAT.velo, x, 0.34, z));
for (const [x, z] of [[0.95, 0.62], [0.95, -0.62], [-0.95, 0.62], [-0.95, -0.62]]) g.add(mesh(cyl(0.03, 1.55, 5), cadre, x, 1.3, z));
for (const [x, z] of [[0.45, 0.32], [0.45, -0.32], [-0.45, 0.32], [-0.45, -0.32]]) g.add(mesh(boite(0.42, 0.42, 0.06), cadre, x, 0.75, z * 1.4));
// l'auvent : cinq bandes, deux teintes
const a = lam('#c8553d'), b = lam(COUL.toile);
for (let i = 0; i < 5; i++) g.add(mesh(boite(2.7 / 5, 0.08, 1.55), i % 2 ? b : a, -1.35 + 2.7 / 10 + i * 2.7 / 5, 2.1, 0, i === 2));
g.add(quilles(geoP, [[0.45, 0.32, 'assis'], [0.45, -0.32, 'assis'], [-0.45, 0.32, 'assis'], [-0.45, -0.32, 'assis']].map(([x, z, s]) => [x, z, s]), couleurs).translateY(0.15));
return g;
}
// ---------------------------------------------------------------- les trajets
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] };
}
// l'abscisse du point du trajet le plus proche de (x, z)
function projete(t, x, z) {
let best = { d: Infinity, s: 0 };
for (let i = 1; i < t.pts.length; i++) {
const [a, b] = [t.pts[i - 1], t.pts[i]], dx = b[0] - a[0], dz = b[1] - a[1], l = dx * dx + dz * dz || 1, k = Math.max(0, Math.min(1, ((x - a[0]) * dx + (z - a[1]) * dz) / l));
const d = Math.hypot(x - a[0] - k * dx, z - a[1] - k * dz); if (d < best.d) best = { d, s: t.c[i - 1] + k * Math.sqrt(l) };
}
return best;
}
function morceau(t, s0, s1) { // les points du trajet entre deux abscisses, dans le sens de s0 vers s1
const pts = [surTrajet(t, s0)].map((p) => [p.x, p.z]);
const sens = s1 >= s0 ? 1 : -1;
for (let i = 0; i < t.pts.length; i++) if ((t.c[i] - s0) * sens > 0 && (s1 - t.c[i]) * sens > 0) pts.push(t.pts[i]);
if (sens < 0) pts.splice(1, pts.length - 1, ...pts.slice(1).reverse());
const p = surTrajet(t, s1); pts.push([p.x, p.z]); return pts;
}
// Un mobile qui roule sur un trajet, sur sa droite (`decal`), à la vitesse `v` ; il ralentit avant chaque arrêt, s'y tient
// `p` secondes et repart doucement. En aller-retour (`boucle` faux), chaque bout est un demi-tour ; en boucle, le trajet
// recommence (`bouts` : le trajet fait demi-tour sur lui-même à son point de départ, la file se resserre au milieu).
// Pendant un arrêt qui est un demi-tour, le véhicule tourne sur place.
function roule(obj, t, { v, decal, arrets = [], boucle = false, bouts = !boucle, depart = 0 }) {
const L = t.L, w = (s) => (boucle ? ((s % L) + L) % L : Math.max(0, Math.min(L, s)));
let s = depart * L, sens = 1, attente = 0, duree = 1, arret = null, parcouru = 99, cap = 0, capA = 0, capB = 0;
const centre = { x: 0, z: 0 };
const capEn = (s, sens) => { const p = surTrajet(t, w(s)); return Math.atan2(-p.dz * sens, p.dx * sens); };
function maj(dt) {
if (attente > 0) {
attente -= dt; const k = 1 - Math.max(0, attente) / duree; cap = capA + (capB - capA) * k * k * (3 - 2 * k);
} else {
let d = Infinity, a = null;
for (const q of arrets) { if (q === arret && parcouru < 3) continue; let e = (q.s - s) * sens; if (boucle && e < -0.01) e += L; if (e >= -0.01 && e < d) { d = Math.max(0, e); a = q; } }
if (!boucle) { const e = sens > 0 ? L - s : s; if (e < d) { d = e; a = { s: sens > 0 ? L : 0, p: 1.5, bout: true }; } }
const pas = v * Math.max(0.12, Math.min(1, d / 10, 0.25 + parcouru / 8)) * dt;
if (a && pas >= d) {
capA = capEn(s - 0.5 * sens, sens);
s = w(s + d * sens); parcouru = 0; arret = a.bout ? null : a; attente = duree = a.p;
if (a.bout) sens = -sens;
capB = capEn(s + 0.5 * sens, sens); while (capB - capA > Math.PI) capB -= 2 * Math.PI; while (capB - capA < -Math.PI) capB += 2 * Math.PI;
if (Math.abs(Math.abs(capB - capA) - Math.PI) < 0.2) capB = capA + Math.PI; // un demi-tour : toujours du même côté
} else { s = w(s + pas * sens); parcouru += pas; cap = capEn(s + 0.3 * sens, sens); }
}
const p = surTrajet(t, s); let dx = p.dx * sens, dz = p.dz * sens; const n = Math.hypot(dx, dz) || 1; dx /= n; dz /= n;
const f = bouts ? Math.min(1, Math.min(s, L - s) / 5) : 1;
obj.position.set(p.x - dz * decal * f, 0, p.z + dx * decal * f); obj.rotation.y = cap;
centre.x = obj.position.x; centre.z = obj.position.z;
}
maj(0);
return { maj, centre };
}
// ---------------------------------------------------------------- la pose : où il y a de la place, et que la caméra voit
function grilleP(L, pas = 6) {
const g = new Map(), cle = (i, j) => (i + 2048) * 4096 + j + 2048;
for (const o of L) { const k = cle(Math.floor(o[0] / pas), Math.floor(o[1] / pas)); let c = g.get(k); if (!c) g.set(k, (c = [])); c.push(o); }
return (x, z, r) => { let d = Infinity; for (let i = Math.floor((x - r) / pas); i <= Math.floor((x + r) / pas); i++) for (let j = Math.floor((z - r) / pas); j <= Math.floor((z + r) / pas); j++) { const c = g.get(cle(i, j)); if (c) for (const o of c) d = Math.min(d, Math.hypot(o[0] - x, o[1] - z)); } return d; };
}
// Les segments qui séparent deux jardins : haies, routes, chemins, sentiers (un objet ne s'étend pas par-dessus).
function barrieres(D) {
const S = [];
const poly = (p) => { for (let i = 1; i < p.length; i++) if (Math.hypot(p[i][0] - p[i - 1][0], p[i][1] - p[i - 1][1]) > 0.05) S.push([p[i - 1], p[i]]); };
D.haies.forEach(poly); Object.values(D.routes).forEach(poly); D.chemins.forEach(poly); D.sentiers.forEach(poly);
const coupe = ([a, b], [c, d]) => {
const r = (p, q, s) => (q[0] - p[0]) * (s[1] - p[1]) - (q[1] - p[1]) * (s[0] - p[0]);
return r(a, b, c) * r(a, b, d) < 0 && r(c, d, a) * r(c, d, b) < 0;
};
return (a, b) => { const x0 = Math.min(a[0], b[0]), x1 = Math.max(a[0], b[0]), z0 = Math.min(a[1], b[1]), z1 = Math.max(a[1], b[1]);
for (const s of S) { if (Math.max(s[0][0], s[1][0]) < x0 || Math.min(s[0][0], s[1][0]) > x1 || Math.max(s[0][1], s[1][1]) < z0 || Math.min(s[0][1], s[1][1]) > z1) continue; if (coupe(s, [a, b])) return true; } return false; };
}
// Le repère d'une maison du plan (comme `maison()` de scene.js) : centre, rotation, Lu (le long de u), Lv.
function repere(h) {
const p = h.p.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]), 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 rot = Math.atan2(-u.y, u.x), cs = Math.cos(rot), sn = Math.sin(rot);
const monde = (lx, lz) => [c.x + lx * cs + lz * sn, c.y - lx * sn + lz * cs];
// la façade que la caméra voit (normale la plus tournée vers +z, le sud de la planche) : n, t, demi-profondeur, largeur
const faces = [[1, 0, Lu / 2, Lv], [-1, 0, Lu / 2, Lv], [0, 1, Lv / 2, Lu], [0, -1, Lv / 2, Lu]].map(([a, b, d, W]) => {
const n = [a * cs + b * sn, -a * sn + b * cs]; return { n, t: [-n[1], n[0]], d, W };
});
const face = faces.reduce((m, f) => (f.n[1] > m.n[1] ? f : m));
return { h, c: { x: c.x, z: c.y }, rot, Lu, Lv, monde, face, aire: Lu * Lv };
}
// ---------------------------------------------------------------- les objets fixes (coordonnées locales, ouverture vers +z)
function abriBus() {
const g = new THREE.Group(), mp = lam(COUL.poteau), toit = mesh(boite(3.7, 0.08, 1.9), lam(COUL.zinc), 0, 2.45, -0.2, true);
toit.rotation.x = -0.12; g.add(toit);
for (const x of [1.6, -1.6]) g.add(mesh(cyl(0.06, 2.5, 6), mp, x, 1.25, -0.85, true));
g.add(mesh(boite(3.2, 1.7, 0.05), new THREE.MeshLambertMaterial({ color: '#d4ebe6', transparent: true, opacity: 0.55, depthWrite: false, emissive: '#000000' }), 0, 1.25, -0.88));
g.add(banc(2.4, lam(COUL.planche), 0, -0.5));
// le poteau de l'arrêt : un disque de couleur, sans rien d'écrit
g.add(mesh(cyl(0.05, 2.8, 6), mp, 2.3, 1.4, 0.4), mesh(cyl(0.34, 0.06, 18).rotateX(Math.PI / 2), lam('#6f8fa8'), 2.3, 2.7, 0.4));
return g;
}
function pointFraicheur(geoP, couleurs) {
const g = new THREE.Group(), mp = lam(COUL.poteau), bois = lam(COUL.planche);
for (const [x, z] of [[2.3, 1.8], [2.3, -1.8], [-2.3, 1.8], [-2.3, -1.8]]) g.add(mesh(cyl(0.08, 2.65, 6), mp, x, 1.32, z, true));
for (const z of [1.8, -1.8]) g.add(mesh(boite(5.1, 0.14, 0.14), mp, 0, 2.6, z));
// les lattes : une seule géométrie, leurs ombres font la fraîcheur
const lattes = []; for (let i = 0; i < 10; i++) lattes.push(boite(0.12, 0.06, 4.1).translate(-2.25 + i * 0.5, 2.7, 0));
g.add(mesh(mergeGeometries(lattes), bois, 0, 0, 0, true));
g.add(table(1.9, 0.8, bois, 0, 0)); g.add(banc(1.9, bois, 0, 0.85), banc(1.9, bois, 0, -0.85));
// le bassin bas, de l'eau ; le brumisateur : une fine ligne et un voile de brume
g.add(mesh(new THREE.CylinderGeometry(1.0, 1.1, 0.45, 20), lam(COUL.pierre), 3.7, 0.22, 0.4, true));
g.add(mesh(new THREE.CircleGeometry(0.86, 20).rotateX(-Math.PI / 2), lam(COUL.eau), 3.7, 0.46, 0.4));
g.add(mesh(cyl(0.018, 2.5, 4), lam('#dfe9ec'), 2.0, 1.3, -1.6));
const brume = new THREE.Mesh(new THREE.ConeGeometry(0.75, 1.3, 14, 1, true), new THREE.MeshLambertMaterial({ color: '#f4f8fa', transparent: true, opacity: 0.28, depthWrite: false, emissive: '#000000', side: THREE.DoubleSide }));
brume.position.set(2.0, 1.9, -1.6); g.add(brume);
g.add(quilles(geoP, [[-0.5, 0.85, 'assis'], [0.55, 0.85, 'assis'], [-0.2, -0.85, 'assis'], [3.0, 1.6, 'enfant']], couleurs));
return g;
}
// Le vélo de l'atelier, retourné sur sa selle et son guidon (roues en l'air).
function veloRetourne(couleur) {
const g = new THREE.Group(), m = lam(couleur);
g.add(mesh(boite(1.15, 0.08, 0.08), m, 0, 0.62, 0));
for (const x of [0.62, -0.62]) g.add(mesh(new THREE.TorusGeometry(0.32, 0.04, 5, 14), MAT.velo, x, 0.92, 0));
g.add(mesh(boite(0.06, 0.55, 0.06), m, 0.35, 0.33, 0), mesh(boite(0.06, 0.55, 0.06), m, -0.3, 0.33, 0));
g.add(mesh(boite(0.25, 0.06, 0.12), MAT.velo, -0.3, 0.04, 0), mesh(boite(0.06, 0.06, 0.5), MAT.velo, 0.35, 0.04, 0));
return g;
}
function atelier(geoP, couleurs, couleurAuto) {
const g = new THREE.Group(), murs = lam('#c9b89a');
// le hangar, toit à deux pans (faîtage le long de x), la grande porte ouverte : un rectangle sombre
g.add(mesh(boite(7, 3.0, 5), murs, 0, 1.5, -2.0, true));
g.add(mesh(toit2(7.6, 5.6, 1.5), new THREE.MeshLambertMaterial({ color: '#8a7b6a', side: THREE.DoubleSide, emissive: '#000000' }), 0, 3.0, -2.0, true));
g.add(mesh(boite(3.2, 2.5, 0.06), lam(COUL.sombre), -1.2, 1.25, 0.52));
// dehors : l'établi, trois vélos retournés, la voiture ouverte sur la fosse
const et = new THREE.Group(); et.add(mesh(boite(2.0, 0.08, 0.7), lam(COUL.planche), 0, 0.9, 0, true));
for (const [a, b] of [[0.9, 0.3], [0.9, -0.3], [-0.9, 0.3], [-0.9, -0.3]]) et.add(mesh(boite(0.07, 0.88, 0.07), lam(COUL.poteau), a, 0.44, b));
et.add(mesh(boite(0.22, 0.18, 0.2), lam('#5f6a70'), 0.7, 1.03, 0), mesh(boite(0.5, 0.05, 0.12), lam('#a9433a'), -0.3, 0.97, 0.1));
et.position.set(-2.4, 0, 1.6); g.add(et);
[['#c47f5a', -3.2, 3.2], ['#6f8fa8', -1.7, 3.5], ['#d3b45c', -0.3, 3.0]].forEach(([c, x, z], i) => { const v = veloRetourne(c); v.position.set(x, 0, z); v.rotation.y = 0.3 - i * 0.35; g.add(v); });
g.add(mesh(boite(1.3, 0.03, 4.0), lam('#2e2b28'), 2.4, 0.02, 2.6));
const auto = new THREE.Group(), ma = lam(couleurAuto);
auto.add(mesh(boite(4.0, 0.85, 1.75), ma, 0, 0.75, 0, true), mesh(boite(2.1, 0.7, 1.58), ma, -0.3, 1.5, 0, true));
for (const [x, z] of [[1.3, 0.85], [1.3, -0.85], [-1.3, 0.85], [-1.3, -0.85]]) auto.add(mesh(cyl(0.34, 0.2, 10).rotateX(Math.PI / 2), MAT.roue, x, 0.34, z));
const capot = mesh(boite(1.1, 0.05, 1.6), ma, 0, 0, 0); capot.geometry.translate(-0.55, 0, 0); capot.position.set(2.0, 1.18, 0); capot.rotation.z = 1.0; auto.add(capot);
auto.position.set(2.4, 0.05, 2.6); auto.rotation.y = -Math.PI / 2; g.add(auto);
g.add(quilles(geoP, [[-2.4, 2.3], [1.0, 3.6], [3.6, 3.1]], couleurs));
return g;
}
function conserverie(geoP, couleurs) {
const g = new THREE.Group();
// le petit bâtiment, toit à un pan, cheminée courte, une porte
g.add(mesh(boite(5, 3.0, 3.4), lam(COUL.enduit), 0, 1.5, -1.0, true));
const toit = mesh(boite(5.5, 0.1, 4.0), lam(COUL.zinc), 0, 3.25, -1.0, true); toit.rotation.x = 0.16; g.add(toit);
g.add(mesh(boite(0.5, 1.0, 0.5), lam(COUL.brique), 1.5, 3.7, -1.9, true));
g.add(mesh(boite(1.0, 2.1, 0.06), lam(COUL.bois), -1.6, 1.05, 0.72));
// l'étagère dehors, contre la façade, et les bocaux (petits cylindres clairs : une seule géométrie, instanciée)
const mp = lam(COUL.poteau), bois = lam(COUL.planche);
for (const x of [-0.3, 1.9]) g.add(mesh(boite(0.06, 1.6, 0.06), mp, x, 0.8, 0.95));
for (const y of [0.75, 1.3]) g.add(mesh(boite(2.3, 0.04, 0.42), bois, 0.8, y, 0.92));
const pots = [], CB = ['#f3eee2', '#e6c96a', '#c8553d', '#b8434f', '#a9be7c', '#d9893a'];
for (const y of [0.77, 1.32]) for (let i = 0; i < 11; i++) pots.push([-0.15 + i * 0.19, y + 0.08, 0.92 + (i % 2 ? 0.08 : -0.08)]);
const imB = new THREE.InstancedMesh(cyl(0.065, 0.16, 8), lam('#ffffff'), pots.length), M = new THREE.Matrix4(), col = new THREE.Color();
pots.forEach(([x, y, z], i) => { imB.setMatrixAt(i, M.makeTranslation(x, y, z)); imB.setColorAt(i, col.set(CB[(i * 7) % CB.length])); }); imB.instanceColor.needsUpdate = true; g.add(imB);
// les cagettes empilées
for (const [x, z, n] of [[3.0, 0.8, 3], [3.0, 0.15, 2], [3.6, 0.5, 2]]) for (let k = 0; k < n; k++) g.add(mesh(boite(0.58, 0.28, 0.4), MAT.caisse, x, 0.14 + k * 0.29, z, k === 0));
g.add(quilles(geoP, [[-0.9, 1.5]], couleurs));
return g;
}
// L'alambic (B6), adossé à la conserverie : un chaudron de cuivre sur un foyer de brique, le col de cygne, un fût ; sous un auvent.
function alambic() {
const g = new THREE.Group(), cu = lam(COUL.cuivre);
g.add(mesh(boite(0.95, 0.45, 0.95), lam(COUL.brique), 0, 0.22, 0, true));
g.add(mesh(new THREE.SphereGeometry(0.46, 14, 10).scale(1, 0.85, 1), cu, 0, 0.78, 0, true));
g.add(mesh(cyl(0.12, 0.35, 10), cu, 0, 1.25, 0));
g.add(mesh(new THREE.TorusGeometry(0.42, 0.045, 6, 12, Math.PI).rotateZ(0), cu, 0.42, 1.42, 0));
g.add(mesh(new THREE.CylinderGeometry(0.3, 0.3, 0.85, 12), lam(COUL.bois), 0.84, 0.42, 0, true));
const mp = lam(COUL.poteau);
for (const [x, z] of [[1.35, 0.8], [-0.6, 0.8]]) g.add(mesh(cyl(0.06, 2.3, 6), mp, x, 1.15, z));
const auvent = mesh(boite(2.4, 0.07, 2.0), lam(COUL.zinc), 0.37, 2.35, -0.05, true); auvent.rotation.x = 0.12; g.add(auvent);
return g;
}
function potagerCommun(geoP, couleurs, verre) {
const g = new THREE.Group();
g.add(mesh(new THREE.PlaneGeometry(20, 12).rotateX(-Math.PI / 2), lam(COUL.terre), 0, 0.03, 0));
// quatre planches, des légumes (instanciés)
const terre = lam(COUL.terreF), legs = [];
for (const z of [-0.6, 1.3, 3.2, 5.0]) { g.add(mesh(boite(15, 0.16, 1.2), terre, 1.0, 0.1, z)); for (let x = -6.2; x <= 8.2; x += 0.75) for (const dz of [-0.28, 0.28]) legs.push([x + (rnd(x * 3 + z) - 0.5) * 0.2, z + dz]); }
const C = ['#8aa35f', '#b8714f', '#9db36a', '#cf9c52', '#7d965a', '#c9b05a'];
const imL = new THREE.InstancedMesh(new THREE.IcosahedronGeometry(1, 0), lam('#ffffff'), legs.length), M = new THREE.Matrix4(), col = new THREE.Color();
legs.forEach(([x, z], i) => { const r = 0.16 + rnd(i * 3) * 0.08; imL.setMatrixAt(i, M.makeScale(r * 1.3, r, r * 1.3).setPosition(x, 0.18 + r * 0.7, z)); imL.setColorAt(i, col.set(C[i % C.length])); });
imL.instanceColor.needsUpdate = true; g.add(imL);
// la serre commune, 8 × 4 m, en verre, toit à deux pans
const serre = new THREE.Group(); serre.position.set(5.5, 0, -3.7);
const caisse = mesh(boite(8, 2.2, 3.8), verre, 0, 1.1, 0); caisse.renderOrder = 1; serre.add(caisse);
const toitS = mesh(toit2(8, 3.8, 1.2), verre, 0, 2.2, 0); toitS.renderOrder = 1; serre.add(toitS);
const bord = new THREE.LineBasicMaterial({ color: '#86ada7' });
serre.add(new THREE.LineSegments(new THREE.EdgesGeometry(caisse.geometry), bord).translateY(1.1), new THREE.LineSegments(new THREE.EdgesGeometry(toitS.geometry, 20), bord).translateY(2.2));
for (let x = -3; x <= 3; x += 1.5) serre.add(mesh(new THREE.IcosahedronGeometry(0.3, 0).scale(1.2, 0.9, 1.2), lam('#9db36a'), x, 0.85, 0.9), mesh(boite(1.2, 0.6, 0.6), lam(COUL.bois), x, 0.3, 0.9));
g.add(serre);
// la cabane à outils, le composteur à trois bacs
const cab = lam(COUL.bois); g.add(mesh(boite(2, 2.0, 2), cab, -8.3, 1.0, -4.3, true), mesh(toit2(2.3, 2.4, 0.7), new THREE.MeshLambertMaterial({ color: '#8a7b6a', side: THREE.DoubleSide, emissive: '#000000' }), -8.3, 2.0, -4.3, true));
for (let i = 0; i < 3; i++) { g.add(mesh(boite(1.0, 0.75, 1.0), lam(COUL.poteau), -8.6 + i * 1.08, 0.37, -1.0, true)); g.add(mesh(boite(0.86, 0.04, 0.86), lam(COUL.compost), -8.6 + i * 1.08, 0.76 - i * 0.12, -1.0)); }
g.add(quilles(geoP, [[-5.5, 0.35], [2.2, 2.25], [6.0, 4.1], [-3.0, -2.6]], couleurs));
return g;
}
// Une tiny house (local, longueur le long de x) : rendue par instances, voir `tinies()`.
function tinies(L) {
const g = new THREE.Group(), n = L.length, M = new THREE.Matrix4(), Q = new THREE.Quaternion(), V = new THREE.Vector3(), S = new THREE.Vector3(1, 1, 1), Y = new THREE.Vector3(0, 1, 0), col = new THREE.Color();
const parts = [
[boite(5.6, 2.3, 2.5).translate(0, 1.6, 0), lam('#ffffff'), true, (i) => DOUX[i % DOUX.length]],
[toit2(6.1, 2.95, 1.05).translate(0, 2.75, 0), new THREE.MeshLambertMaterial({ color: '#8f7d6a', side: THREE.DoubleSide, emissive: '#000000' }), true],
[boite(0.9, 1.9, 0.06).translate(1.2, 1.4, 1.27), lam(COUL.bois)],
[boite(1.1, 0.7, 0.06).translate(-1.3, 1.8, 1.27), lam(COUL.vitre)],
[mergeGeometries([[1.3, 1.3], [1.3, -1.3], [-1.3, 1.3], [-1.3, -1.3]].map(([x, z]) => cyl(0.3, 0.16, 10).rotateX(Math.PI / 2).translate(x, 0.3, z))), MAT.roue],
];
for (const [geo, m, ombre, couleur] of parts) {
const im = new THREE.InstancedMesh(geo, m, n); im.castShadow = !!ombre; im.receiveShadow = true;
L.forEach(([x, z, rot], i) => { im.setMatrixAt(i, M.compose(V.set(x, 0, z), Q.setFromAxisAngle(Y, rot), S)); if (couleur) im.setColorAt(i, col.set(couleur(i))); });
if (couleur) im.instanceColor.needsUpdate = true;
g.add(im);
}
return g;
}
function four() {
const g = new THREE.Group();
g.add(mesh(boite(1.6, 0.9, 1.6), lam(COUL.pierre), 0, 0.45, 0, true));
g.add(mesh(new THREE.SphereGeometry(0.72, 14, 8, 0, Math.PI * 2, 0, Math.PI / 2), lam(COUL.tuile), 0, 0.9, 0, true));
g.add(mesh(boite(0.5, 0.42, 0.06), lam(COUL.sombre), 0, 1.08, 0.66), mesh(cyl(0.11, 0.6, 8), lam(COUL.brique), -0.25, 1.75, -0.2));
return g;
}
function abriCargos() {
const g = new THREE.Group(), mp = lam(COUL.poteau);
for (const [x, z] of [[2.9, 1.1], [2.9, -1.1], [-2.9, 1.1], [-2.9, -1.1]]) g.add(mesh(cyl(0.07, 2.3, 6), mp, x, 1.15, z, true));
g.add(mesh(boite(6.4, 0.12, 2.8), lam(COUL.bois), 0, 2.35, 0, true));
['#c47f5a', '#8aa36a', '#6f8fa8'].forEach((c, i) => {
const v = veloCargo(c); v.children.splice(v.children.length - 3, 3); // garé : ni chargement, ni cycliste
v.position.set(-2.0 + i * 2.0, 0, 0); v.rotation.y = Math.PI / 2 + 0.55; g.add(v);
});
return g;
}
function ruches(n) {
const g = new THREE.Group(), M = new THREE.Matrix4(), col = new THREE.Color(), C = ['#e9dcb8', '#cfdde3', '#efe0a6', '#e6c9b8'];
const pos = Array.from({ length: n }, (_, i) => [(i - (n - 1) / 2) * 1.6, 0]);
const parts = [[boite(0.52, 0.46, 0.42).translate(0, 0.58, 0), true], [boite(0.62, 0.06, 0.52).translate(0, 0.84, 0), false, COUL.zinc],
[mergeGeometries([[0.2, 0.15], [0.2, -0.15], [-0.2, 0.15], [-0.2, -0.15]].map(([x, z]) => boite(0.05, 0.36, 0.05).translate(x, 0.18, z))), false, COUL.poteau], [boite(0.3, 0.04, 0.03).translate(0, 0.39, 0.22), false, COUL.sombre]];
for (const [geo, couleurs, c] of parts) {
const im = new THREE.InstancedMesh(geo, lam(c || '#ffffff'), n); im.castShadow = !!couleurs;
pos.forEach(([x, z], i) => { im.setMatrixAt(i, M.makeTranslation(x, 0, z)); if (couleurs) im.setColorAt(i, col.set(C[i % C.length])); });
if (couleurs) im.instanceColor.needsUpdate = true; g.add(im);
}
return g;
}
function chapiteau() {
const g = new THREE.Group();
g.add(mesh(new THREE.CylinderGeometry(4.2, 4.2, 2.3, 18), lam(COUL.toile), 0, 1.15, 0, true));
g.add(mesh(new THREE.ConeGeometry(4.7, 3.0, 18), lam('#b8434f'), 0, 3.8, 0, true));
g.add(mesh(cyl(0.06, 1.2, 5), lam(COUL.poteau), 0, 5.6, 0), mesh(new THREE.ConeGeometry(0.25, 0.6, 4).rotateZ(-Math.PI / 2), lam('#e0b04a'), 0.3, 5.95, 0));
g.add(mesh(boite(1.8, 2.0, 0.08), lam(COUL.sombre), 0, 1.0, 4.17));
// la caravane : une boîte arrondie sur deux roues, un timon
const car = new THREE.Group(); car.position.set(7.4, 0, 1.5); car.rotation.y = -0.4;
car.add(mesh(new THREE.CapsuleGeometry(0.95, 2.6, 4, 12).rotateZ(Math.PI / 2).scale(1, 1, 0.85), lam('#e0c27a'), 0, 1.45, 0, true));
car.add(mesh(boite(2.2, 0.4, 0.05), lam(COUL.vitre), -0.2, 1.75, 0.8), mesh(boite(0.6, 1.2, 0.05), lam(COUL.bois), 1.0, 1.25, 0.81));
for (const z of [0.85, -0.85]) car.add(mesh(cyl(0.38, 0.16, 12).rotateX(Math.PI / 2), MAT.roue, 0, 0.38, z));
car.add(mesh(boite(1.2, 0.06, 0.06), MAT.velo, 2.75, 0.55, 0));
g.add(car);
return g;
}
// ---------------------------------------------------------------- la pose
// ctx : le même que gestesDuTour, plus P (la grille d'occupation de gestes.js), maisons (les groupes des maisons du plan,
// par indice de D.maisons), tr (les routes en trajets), PAL, geoP, verre (le matériau de verre des serres), tour (le retour
// de gestesDuTour) et convoi ({ objs, centre }) : les objets du Tour deviennent cliquables ici, avec les nouveaux.
// Rend { anim, maj, cliquables: [{ o, fiche }], points: { id: { x, z, w } }, lumieres: { effet: [matériaux] },
// haieOuverte: { k, s0, s1 } | null (la haie qui tombe entre les deux maisons du jardin commun), laisses: [id] }.
export function objetsNouveaux({ D, groupe, T, P, maisons, tr, PAL, geoP, verre, matsArbres, tour, convoi }) {
const anim = [], maj = [], cliquables = [], points = {}, lumieres = {}, laisses = [], gens = PAL.gens, diag = {};
const Wx = D.Wm / 2 - 7, Wz = D.Hm / 2 - 7;
const coupe = barrieres(D), coupeSansHaie = barrieres({ ...D, haies: [] });
const dForet = grilleP(D.arbres.filter((a) => a[4] === 1)), dVie = grilleP([...D.persos, ...D.troupeaux.map((t) => [t[0], t[1]]), ...D.poules.map((p) => [p[0], p[1]])]);
const dChemin = grilleP([...D.chemins, ...D.sentiers].flatMap((l) => { const o = []; for (let i = 1; i < l.length; i++) { const L = Math.hypot(l[i][0] - l[i - 1][0], l[i][1] - l[i - 1][1]); for (let s = 0; s < L; s += 2) o.push([l[i - 1][0] + (l[i][0] - l[i - 1][0]) * s / L, l[i - 1][1] + (l[i][1] - l[i - 1][1]) * s / L]); } return o; }), 8);
// la place libre, lue sur une grille de 2 m calculée à la demande ; posée, une emprise vide les cases voisines
const PAS = 2, memo = new Map(), cle = (i, j) => (i + 2048) * 4096 + j + 2048;
const cellule = (i, j) => { const k = cle(i, j); let v = memo.get(k); if (v === undefined) memo.set(k, (v = P.libre(i * PAS, j * PAS))); return v; };
const libre = (x, z) => { const i = Math.round(x / PAS), j = Math.round(z / PAS); return Math.min(cellule(i, j) - Math.hypot(x - i * PAS, z - j * PAS), dVie(x, z, 3) - 1.0, dForet(x, z, 4) - 2.0); };
const ajoute = (x, z, r) => { P.ajoute(x, z, r); for (let i = Math.floor((x - r - 14) / PAS); i <= Math.ceil((x + r + 14) / PAS); i++) for (let j = Math.floor((z - r - 14) / PAS); j <= Math.ceil((z + r + 14) / PAS); j++) memo.delete(cle(i, j)); };
// un rectangle (demi-côtés a le long de x local, b le long de z local) tourné de rot : la plus petite place libre dessus
const loc = (x, z, rot, u, v) => [x + u * Math.cos(rot) + v * Math.sin(rot), z - u * Math.sin(rot) + v * Math.cos(rot)];
function emprise(x, z, rot, a, b, seuil = -Infinity) {
let m = Infinity; const na = Math.max(1, Math.ceil(2 * a / 1.5)), nb = Math.max(1, Math.ceil(2 * b / 1.5));
for (let i = 0; i <= na; i++) for (let j = 0; j <= nb; j++) { const [px, pz] = loc(x, z, rot, -a + 2 * a * i / na, -b + 2 * b * j / nb); if (Math.abs(px) > Wx || Math.abs(pz) > Wz) return -9; m = Math.min(m, libre(px, pz)); if (m < seuil) return m; }
return m;
}
const occupe = (x, z, rot, a, b) => { const r = Math.min(a, b) * 1.2 + 0.3, l = Math.max(a, b) - Math.min(a, b); const n = Math.max(1, Math.ceil(l / Math.min(a, b)) + 1);
for (let k = 0; k < n; k++) { const s = n === 1 ? 0 : -l + 2 * l * k / (n - 1); const [px, pz] = a >= b ? loc(x, z, rot, s, 0) : loc(x, z, rot, 0, s); ajoute(px, pz, r); } };
const demiX = (rot, a, b) => Math.abs(a * Math.cos(rot)) + Math.abs(b * Math.sin(rot));
const vu = (x, z, rot, a, b, h) => P.cache(x, z, h, demiX(rot, a, b));
function* autour(cx, cz, R, pas = 2) { for (let x = cx - R; x <= cx + R; x += pas) for (let z = cz - R; z <= cz + R; z += pas) if (Math.hypot(x - cx, z - cz) <= R && Math.abs(x) < Wx && Math.abs(z) < Wz) yield [x, z]; }
// la meilleure place d'un rectangle près de (cx, cz) : libre sur toute l'emprise, vue, proche
function cherche(cx, cz, R, a, b, h, { rots = [0], marge = 0.3, poidsVu = 4, poidsD = 0.08, filtre = null, pas = 2 } = {}) {
let best = null;
for (const [x, z] of autour(cx, cz, R, pas)) for (const rot of rots) {
if (filtre && !filtre(x, z)) continue;
const pl = emprise(x, z, rot, a, b, marge); if (pl < marge) continue;
const score = -poidsVu * vu(x, z, rot, a, b, h) - poidsD * Math.hypot(x - cx, z - cz) + 0.2 * Math.min(pl, 2);
if (!best || score > best.score) best = { x, z, rot, score };
}
return best;
}
const pose = (o, x, z, rot) => { o.position.set(x, 0, z); o.rotation.y = rot; groupe.add(o); return o; };
// l'objet devient cliquable et s'allume ; ses matériaux lui sont propres (un matériau partagé est dupliqué)
function relie(objs, fiche, effet, point) {
const map = new Map();
for (const o of objs) {
o.traverse((m) => { if (!m.material || Array.isArray(m.material)) return; if (!map.has(m.material)) map.set(m.material, m.material.clone()); m.material = map.get(m.material); });
cliquables.push({ o, fiche });
}
lumieres[effet] = [...lumieres[effet] || [], ...[...map.values()].filter((m) => m.emissive)];
if (point) points[effet] = point;
}
// ---- les objets du Tour (22/10) : leurs fiches, leurs cadrages (largeur vue, m), leur allumage
if (tour) for (const [k, [fiche, w]] of Object.entries(TOUR_FICHES)) if (tour.objets[k] && tour.points[k]) relie(tour.objets[k], fiche, k, { ...tour.points[k], w });
if (convoi) { relie(convoi.objs, 'quartier-convoi', 'convoi'); points.convoi = convoi.centre; }
// le centre de la place : le milieu des étals
const place = D.etals.reduce((a, e) => [a[0] + e.c[0] / D.etals.length, a[1] + e.c[1] / D.etals.length], [0, 0]);
const mare = D.canards.c;
const reps = D.maisons.map((h, i) => ({ ...repere(h), i })), prises = new Set();
const existantes = reps.filter((r) => r.h.t === 'existante' && Math.hypot(r.c.x - T.c.x, r.c.z - T.c.y) >= 20
// une maison existante posée exactement sous une maison transformée (le plan en porte une) ne compte pas
&& !reps.some((q) => q.h.t !== 'existante' && Math.hypot(q.c.x - r.c.x, q.c.z - r.c.z) < 3));
// ---- A2. L'arrêt de bus : au bord de la route principale, à 25 m au plus du milieu de la place, du côté que la caméra voit
const tP = tr.principale;
let arret = null;
{
let best = null;
for (let s = 0; s <= tP.L; s += 1) {
const p = surTrajet(tP, s), n = Math.hypot(p.dx, p.dz) || 1, tx = p.dx / n, tz = p.dz / n;
if (Math.hypot(p.x - place[0], p.z - place[1]) > 25) continue;
for (const cote of [1, -1]) {
const nx = -tz * cote, nz = tx * cote, x = p.x + nx * 6.2, z = p.z + nz * 6.2, rot = Math.atan2(-nx, -nz);
const pl = emprise(x, z, rot, 2.6, 1.1, 0.2); if (pl < 0.2) continue;
const score = -4 * vu(x, z, rot, 2.6, 1.1, 2.6) - 0.08 * Math.hypot(x - place[0], z - place[1]) + 0.3 * Math.min(pl, 2) + (nz > 0 ? 0.5 : 0);
if (!best || score > best.score) best = { x, z, rot, s, score };
}
}
if (best) {
const a = pose(abriBus(), best.x, best.z, best.rot); occupe(best.x, best.z, best.rot, 2.6, 1.1);
arret = { s: best.s, x: best.x, z: best.z, objs: [a] };
}
}
// ---- A3. Le point fraîcheur : à l'ombre d'arbres existants, près de la mare ou de la place, visible
let fraicheur = null;
{
let best = null;
for (const [cx, cz] of [mare, place]) for (const [x, z] of autour(cx, cz, 40, 2)) for (const rot of [0, 0.35, -0.35]) {
const ombre = P.compte(x, z, 11); if (ombre < 2) continue;
const pl = emprise(x + 0.7 * Math.cos(rot), z - 0.7 * Math.sin(rot), rot, 3.6, 2.6, 0.2); if (pl < 0.2) continue;
const score = Math.min(ombre, 6) - 5 * vu(x, z, rot, 3.6, 2.6, 2.8) - 0.06 * Math.hypot(x - cx, z - cz);
if (!best || score > best.score) best = { x, z, rot, score };
}
if (best) {
const o = pose(pointFraicheur(geoP, gens), best.x, best.z, best.rot); occupe(best.x + 0.7 * Math.cos(best.rot), best.z - 0.7 * Math.sin(best.rot), best.rot, 3.6, 2.6);
fraicheur = best; relie([o], 'quartier-fraicheur', 'fraicheur', { x: best.x + 0.7, z: best.z, w: 42 });
} else laisses.push('fraicheur');
}
// ---- A1. La navette : de l'arrêt de bus, par la route principale et la liaison, un tour de l'anneau, et retour ; elle
// s'arrête 5 s à l'arrêt (où elle fait demi-tour) et 5 s au plus près du point fraîcheur
if (arret && tr.liaison_anneau && tr.anneau) {
const la = tr.liaison_anneau.pts, an = tr.anneau.pts.slice(0, -1);
const sJ = projete(tP, la[0][0], la[0][1]).s, s0 = Math.min(tP.L, arret.s + (sJ > arret.s ? 10 : -10));
const A = [...morceau(tP, s0, sJ), ...la];
const j = an.reduce((m, p, i) => (Math.hypot(p[0] - la[la.length - 1][0], p[1] - la[la.length - 1][1]) < Math.hypot(an[m][0] - la[la.length - 1][0], an[m][1] - la[la.length - 1][1]) ? i : m), 0);
const tour = [...an.slice(j), ...an.slice(0, j), an[j]];
const pts = [...A, ...tour, ...A.slice().reverse()].filter((p, i, L) => i === 0 || Math.hypot(p[0] - L[i - 1][0], p[1] - L[i - 1][1]) > 0.3);
const t = trajet(pts), arrets = [{ s: 0.01, p: 5 }];
if (fraicheur) { const q = projete({ ...t, pts: t.pts.slice(0, A.length + tour.length), c: t.c.slice(0, A.length + tour.length) }, fraicheur.x, fraicheur.z); if (q.d < 30) arrets.push({ s: q.s, p: 5 }); }
if (arrets.length < 2) arrets.push({ s: t.c[A.length + Math.floor(tour.length / 2)], p: 5 }); // sinon, au milieu du tour de l'anneau
const o = navette(); groupe.add(o);
const r = roule(o, t, { v: 4.5, decal: 1.8, arrets, boucle: true, bouts: true, depart: 0.3 });
maj.push(r.maj); relie([o], 'quartier-navette', 'navette'); points.navette = r.centre;
} else laisses.push('navette');
// ---- A2. Le bus scolaire : la route principale, aller et retour ; 6 s à l'arrêt dans les deux sens
if (arret) {
const o = bus(PAL.autos[1]); groupe.add(o);
const r = roule(o, tP, { v: 6, decal: 1.9, arrets: [{ s: arret.s, p: 6 }], depart: 0.15 });
maj.push(r.maj); relie([o, ...arret.objs], 'quartier-bus', 'bus'); points.bus = r.centre; points.arret = { x: arret.x, z: arret.z };
} else laisses.push('bus');
// ---- A9 (choisi avant les autres maisons). Deux maisons voisines qui font jardin commun : une seule haie entre elles, et
// rien d'autre ; la haie s'ouvre sur 10 m (scene.js la redessine sans ces arbres) ; table longue, four, portail ouvert.
let haieOuverte = null;
{
let best = null;
const polyS = (h) => { const c = [0]; for (let i = 1; i < h.length; i++) c.push(c[i - 1] + Math.hypot(h[i][0] - h[i - 1][0], h[i][1] - h[i - 1][1])); return c; };
for (let i = 0; i < existantes.length; i++) for (let j = i + 1; j < existantes.length; j++) {
const a = existantes[i], b = existantes[j], d = Math.hypot(a.c.x - b.c.x, a.c.z - b.c.z); if (d > 38 || d < 12) continue;
const A = [a.c.x, a.c.z], B = [b.c.x, b.c.z];
// les haies coupées par la ligne qui joint les deux maisons : exactement une, et ni route ni chemin
const coupes = [];
D.haies.forEach((h, k) => { for (let q = 1; q < h.length; q++) { const r = inter(A, B, h[q - 1], h[q]); if (r) coupes.push({ k, q, r }); } });
if (coupes.length !== 1) continue;
if (coupeSansHaie(A, B)) continue;
const { k, q, r } = coupes[0], h = D.haies[k], c = polyS(h), s = c[q - 1] + r.u * (c[q] - c[q - 1]);
if (s < 5 || s > c[c.length - 1] - 5) continue; // pas au bout d'une haie : on ne verrait pas qu'elle s'ouvre
const [x, z] = [r.x, r.z], vue = P.cache(x, z, 1.5, 5);
const score = -4 * vue - 0.05 * d - 0.01 * Math.hypot(x - place[0], z - place[1]);
if (!best || score > best.score) best = { a, b, k, q, s, x, z, score, tx: h[q][0] - h[q - 1][0], tz: h[q][1] - h[q - 1][1] };
}
if (best) {
const { a, b, k, s, x, z } = best, n = Math.hypot(best.tx, best.tz), tx = best.tx / n, tz = best.tz / n;
haieOuverte = { k, s0: s - 5, s1: s + 5 }; prises.add(a.i); prises.add(b.i);
// la table et le four, de part et d'autre de la limite ouverte, dans l'axe de la haie ; le portail ouvert au bout
const objs = [], rot = Math.atan2(-tz, tx), bois = lam(COUL.planche);
const mi = [(a.c.x + b.c.x) / 2, (a.c.z + b.c.z) / 2];
const tb = new THREE.Group(); tb.add(table(4.6, 0.9, bois, 0, 0), banc(4.6, bois, 0, 0.8), banc(4.6, bois, 0, -0.8));
tb.add(quilles(geoP, [[-1.4, 0.8, 'assis'], [0.2, 0.8, 'assis'], [1.2, -0.8, 'assis'], [-0.6, -0.8, 'assis'], [2.9, 0.3]], gens));
objs.push(pose(tb, x, z, rot)); ajoute(x, z, 2.6);
// le four : du côté de la maison la plus visible, à 4 m de la limite
let fx = null;
for (const sgn of [1, -1]) for (const o of [3.5, 5, 6.5]) for (const dl of [-3, 0, 3]) {
const px = x - tz * o * sgn + tx * dl, pz = z + tx * o * sgn + tz * dl; const pl = emprise(px, pz, rot, 0.9, 0.9, 0.2); if (pl < 0.2) continue;
const sc = -3 * P.cache(px, pz, 1.6, 0.9) - 0.2 * o; if (!fx || sc > fx.sc) fx = { px, pz, sc };
}
if (fx) { objs.push(pose(four(), fx.px, fx.pz, rot)); ajoute(fx.px, fx.pz, 1.3); }
const mp = lam(COUL.poteau), portail = new THREE.Group();
for (const e of [-5, 5]) portail.add(mesh(cyl(0.08, 1.4, 6), mp, e, 0.7, 0));
const battant = new THREE.Group(); battant.position.set(5, 0, 0); battant.rotation.y = 1.25; portail.add(battant);
for (const y of [0.35, 0.95]) battant.add(mesh(boite(1.6, 0.08, 0.05), lam(COUL.bois), -0.8, y, 0));
for (const xx of [-0.1, -0.8, -1.5]) battant.add(mesh(boite(0.06, 0.8, 0.05), lam(COUL.bois), xx, 0.65, 0));
objs.push(pose(portail, x, z, rot));
const ma = maisons[a.i], mb = maisons[b.i];
relie(objs, 'quartier-jardin-commun', 'jardin-commun', { x: (x * 2 + mi[0]) / 3, z: (z * 2 + mi[1]) / 3, w: 58 });
for (const m of [ma, mb]) if (m) cliquables.push({ o: m, fiche: 'quartier-jardin-commun' });
} else laisses.push('jardin-commun');
}
// ---- A4. La colocation intergénérationnelle : une maison existante (à 20 m au moins de la maison témoin), sa façade
// vue de la caméra, du jardin devant ; trois portes, une terrasse commune, un portique, un bac à sable, un étendoir.
{
let best = null;
for (const r of existantes) {
if (prises.has(r.i)) continue;
const f = r.face, W = f.W; let pl = Infinity;
for (let al = -W / 2 + 0.5; al <= W / 2 - 0.5 + 1e-6; al += 1.5) for (const dp of [2.6, 4, 5.5, 7]) pl = Math.min(pl, libre(r.c.x + f.n[0] * (f.d + dp) + f.t[0] * al, r.c.z + f.n[1] * (f.d + dp) + f.t[1] * al));
if (pl < 0) continue;
const fx = r.c.x + f.n[0] * (f.d + 3), fz = r.c.z + f.n[1] * (f.d + 3), vue = P.cache(fx, fz, 2.5, W / 2) + P.cache(r.c.x + f.n[0] * f.d, r.c.z + f.n[1] * f.d, 3, W / 2);
const score = -4 * vue + Math.min(pl, 2) + 0.3 * f.n[1] + 0.02 * r.aire;
if (!best || score > best.score) best = { r, score };
}
if (best) {
const r = best.r, f = r.face, W = f.W; prises.add(r.i);
const g = new THREE.Group(); g.position.set(r.c.x + f.n[0] * f.d, 0, r.c.z + f.n[1] * f.d); g.rotation.y = Math.atan2(f.n[0], f.n[1]);
// dans le repère de la façade : x le long du mur (vers -t), z la profondeur vers le jardin
[-W / 3, 0, W / 3].forEach((al, i) => g.add(mesh(boite(0.95, 2.1, 0.08), lam(['#c47f5a', '#6f8fa8', '#8aa36a'][i]), al, 1.05, 0.05)));
g.add(mesh(boite(W * 0.86, 0.14, 2.8), lam(COUL.planche), 0, 0.07, 1.5, true));
g.add(table(2.4, 0.9, lam(COUL.bois), -W * 0.15, 1.6));
// le portique (deux A, une poutre, deux balançoires)
const port = new THREE.Group(), mp = lam(COUL.poteau); port.position.set(W * 0.22, 0, 5.2);
for (const x of [-1.3, 1.3]) for (const s of [1, -1]) { const p = mesh(cyl(0.06, 2.4, 6), mp, x, 1.12, s * 0.42); p.rotation.x = s * 0.38; port.add(p); }
port.add(mesh(cyl(0.07, 2.8, 6).rotateZ(Math.PI / 2), mp, 0, 2.22, 0, true));
for (const x of [-0.6, 0.6]) { port.add(mesh(boite(0.5, 0.05, 0.25), lam('#c8553d'), x, 0.5, 0)); for (const dx of [-0.22, 0.22]) port.add(mesh(cyl(0.012, 1.7, 3), lam(COUL.sombre), x + dx, 1.37, 0)); }
g.add(port);
// le bac à sable et ses boules de couleur ; l'étendoir et son linge
g.add(mesh(boite(1.7, 0.22, 1.7), lam(COUL.sable), -W * 0.3, 0.11, 5.0));
['#c8553d', '#e0b04a', '#6f8fa8', '#8aa36a'].forEach((c, i) => g.add(mesh(new THREE.SphereGeometry(0.16, 8, 6), lam(c), -W * 0.3 - 0.4 + i * 0.28, 0.36, 5.0 + (i % 2 ? 0.35 : -0.3))));
for (const x of [-1.2, 1.2]) g.add(mesh(cyl(0.04, 1.8, 5), mp, -W * 0.3 + x, 0.9, 7.0));
const fil = new THREE.BufferGeometry(); fil.setAttribute('position', new THREE.Float32BufferAttribute([-W * 0.3 - 1.2, 1.7, 7.0, -W * 0.3 + 1.2, 1.7, 7.0], 3));
g.add(new THREE.LineSegments(fil, new THREE.LineBasicMaterial({ color: '#5c4c3c' })));
['#f3eee2', '#c47f5a', '#85adc0', '#e6c96a'].forEach((c, i) => g.add(mesh(boite(0.45, 0.6 - (i % 2) * 0.15, 0.03), lam(c), -W * 0.3 - 0.8 + i * 0.55, 1.38 + (i % 2) * 0.07, 7.0)));
// six adultes et trois enfants
g.add(quilles(geoP, [[-W * 0.15 - 0.8, 1.0, 'assis'], [-W * 0.15 + 0.8, 1.0, 'assis'], [-W * 0.15, 2.3, 'assis'], [W * 0.3, 2.0], [W * 0.05, 4.2], [-W * 0.3 + 1.6, 6.3],
[W * 0.22 - 0.6, 5.2, 'enfant'], [W * 0.22 + 0.6, 5.6, 'enfant'], [-W * 0.3 + 0.4, 4.4, 'enfant']], gens));
groupe.add(g); ajoute(g.position.x + f.n[0] * 4.5, g.position.z + f.n[1] * 4.5, W / 2);
relie([g], 'quartier-colocation', 'colocation', { x: g.position.x + f.n[0] * 3, z: g.position.z + f.n[1] * 3, w: 44 });
if (maisons[r.i]) cliquables.push({ o: maisons[r.i], fiche: 'quartier-colocation' });
} else laisses.push('colocation');
}
// ---- A5. L'atelier partagé : sous la bulle « garage » de la planche (l'emplacement voulu par Jules), ou à côté
const bulle = (id) => D.bulles.find((b) => b.id === id)?.w;
{
const c = bulle('garage') || [grandPos(D)[0], grandPos(D)[1]];
let best = cherche(c[0], c[1], 26, 4.4, 4.3, 4.5, { rots: [0, 0.25, -0.25] });
if (!best) { const g = grandPos(D); best = cherche(g[0], g[1], 40, 4.4, 4.3, 4.5, { rots: [0, 0.25, -0.25] }); }
if (best) {
const o = pose(atelier(geoP, gens, PAL.autos[5]), best.x, best.z, best.rot); occupe(best.x, best.z, best.rot, 4.4, 4.3);
relie([o], 'quartier-atelier', 'atelier', { x: best.x, z: best.z + 0.5, w: 44 });
} else laisses.push('atelier');
}
// ---- A6 et B6. La conserverie et son alambic : sous la bulle « confiture », ou près du grand bâtiment
{
const c = bulle('confiture') || grandPos(D);
let best = cherche(c[0], c[1], 26, 4.6, 2.7, 3.6, { rots: [0, 0.25, -0.25] });
if (!best) { const g = grandPos(D); best = cherche(g[0], g[1], 40, 4.6, 2.7, 3.6); }
if (best) {
const g = new THREE.Group(); g.add(conserverie(geoP, gens)); const al = alambic(); al.position.set(-3.6, 0, -0.6); g.add(al);
g.position.x = 0.5; const o = new THREE.Group(); o.add(g); pose(o, best.x, best.z, best.rot); occupe(best.x, best.z, best.rot, 4.6, 2.7);
relie([o], 'quartier-conserverie', 'conserverie', { x: best.x, z: best.z, w: 42 });
} else laisses.push('conserverie');
}
// ---- A7. Le potager partagé et la serre commune : la plus grande place libre hors forêt, mare et pâturages, vue
{
let best = null;
for (const [x, z] of autour(0, 0, 200, 4)) for (const rot of [0, 0.3, -0.3]) {
const pl = emprise(x, z, rot, 10.6, 6.6, 0.1); if (pl < 0.1) continue;
const score = -3 * vu(x, z, rot, 10.6, 6.6, 2.5) - 0.01 * Math.hypot(x - place[0], z - place[1]) + 0.2 * Math.min(pl, 3);
if (!best || score > best.score) best = { x, z, rot, score };
}
if (best) {
const o = pose(potagerCommun(geoP, gens, verre.clone()), best.x, best.z, best.rot); occupe(best.x, best.z, best.rot, 10.6, 6.6);
relie([o], 'vivant-potager', 'potager', { x: best.x, z: best.z, w: 50 });
} else laisses.push('potager');
}
// ---- A8. La grande maison et ses tiny houses : une maison existante dont le jardin, du même côté des haies, reçoit
// quatre à six tiny houses de 3 × 6 m, vues de la caméra ; une allée de gravier, une table commune.
{
let best = null;
for (const r of existantes) {
if (prises.has(r.i)) continue;
const cands = [];
for (let R = 8; R <= 22; R += 2) for (let k = 0; k < 24; k++) {
const a = k * Math.PI / 12, x = r.c.x + Math.cos(a) * R, z = r.c.z + Math.sin(a) * R;
for (const rot of [r.rot, r.rot + Math.PI / 2]) {
const pl = emprise(x, z, rot, 3.2, 1.6, 0.4); if (pl < 0.4) continue;
const v = vu(x, z, rot, 3.2, 1.6, 3.6); if (v > 0) continue;
cands.push({ x, z, rot, R });
}
}
cands.sort((p, q) => p.R - q.R);
const choix = [];
for (const c of cands) { if (choix.length >= 6) break; if (choix.some((o) => Math.hypot(o.x - c.x, o.z - c.z) < 7.2)) continue; if (coupe([r.c.x, r.c.z], [c.x, c.z])) continue; choix.push(c); }
if (choix.length < 4) continue;
const score = choix.length * 2 + 0.05 * r.aire - 0.04 * choix.reduce((s, c) => s + c.R, 0) / choix.length;
if (!best || score > best.score) best = { r, choix, score };
}
if (best) {
const { r, choix } = best; prises.add(r.i);
const g = tinies(choix.map((c) => [c.x, c.z, c.rot])); groupe.add(g);
choix.forEach((c) => occupe(c.x, c.z, c.rot, 3.2, 1.6));
// l'allée de gravier, de la maison à chaque tiny house ; la table commune au milieu
const gravier = lam('#d8cfbd'), objs = [g];
const fx = r.c.x + r.face.n[0] * (r.face.d + 1), fz = r.c.z + r.face.n[1] * (r.face.d + 1);
for (const c of choix) { const L = Math.hypot(c.x - fx, c.z - fz) - 3; if (L < 1) continue; const a = mesh(boite(L, 0.04, 0.9), gravier, 0, 0.03, 0); a.position.set((fx + c.x) / 2, 0.03, (fz + c.z) / 2); a.rotation.y = Math.atan2(-(c.z - fz), c.x - fx); groupe.add(a); objs.push(a); }
const m = choix.reduce((a, c) => [a[0] + c.x / choix.length, a[1] + c.z / choix.length], [0, 0]);
let tb = null; for (const [x, z] of autour((m[0] + r.c.x) / 2, (m[1] + r.c.z) / 2, 8, 1)) { const pl = emprise(x, z, r.rot, 1.6, 1.2, 0.1); if (pl >= 0.1 && (!tb || pl > tb.pl)) tb = { x, z, pl }; }
if (tb) { const t = new THREE.Group(); t.add(table(2.4, 0.9, lam(COUL.planche), 0, 0), banc(2.4, lam(COUL.planche), 0, 0.8), banc(2.4, lam(COUL.planche), 0, -0.8), quilles(geoP, [[-0.6, 0.8, 'assis'], [0.6, -0.8, 'assis'], [1.9, 0.2]], gens)); objs.push(pose(t, tb.x, tb.z, r.rot)); ajoute(tb.x, tb.z, 1.8); }
relie(objs, 'quartier-tiny', 'tiny', { x: (m[0] * 2 + r.c.x) / 3, z: (m[1] * 2 + r.c.z) / 3, w: 60 });
if (maisons[r.i]) cliquables.push({ o: maisons[r.i], fiche: 'quartier-tiny' });
} else laisses.push('tiny');
}
// ---- B1. Les vélos cargos à prêter : un abri ouvert près de la place
{
const best = cherche(place[0], place[1], 34, 3.3, 1.6, 2.4, { rots: [0, 0.3, -0.3, Math.PI / 2] });
if (best) { const o = pose(abriCargos(), best.x, best.z, best.rot); occupe(best.x, best.z, best.rot, 3.3, 1.6); relie([o], 'quartier-cargos', 'cargos', { x: best.x, z: best.z, w: 40 }); }
else laisses.push('cargos');
}
// ---- B2. La Rosalie : en boucle sur l'anneau, lentement
if (tr.anneau) {
const o = rosalie(geoP, gens); groupe.add(o);
const r = roule(o, tr.anneau, { v: 2, decal: 1.4, boucle: true, bouts: false, depart: 0.55 });
maj.push(r.maj); relie([o], 'quartier-rosalie', 'rosalie'); points.rosalie = r.centre;
} else laisses.push('rosalie');
// ---- B3. Les ruches : trois ou quatre, en lisière de la forêt ou des vergers, loin des chemins, ouvertes au sud
{
const vergers = grilleP(D.vergers, 6);
let best = null;
for (const [x, z] of autour(0, 0, 200, 2)) {
const lis = Math.min(dForet(x, z, 9), vergers(x, z, 9)); if (lis < 2.5 || lis > 8) continue;
if (dChemin(x, z, 9) < 8) continue;
const pl = emprise(x, z, 0, 3.0, 0.8, 0.2); if (pl < 0.2) continue;
const score = -4 * vu(x, z, 0, 3.0, 0.8, 1.0) - 0.3 * lis - 0.005 * Math.hypot(x, z);
if (!best || score > best.score) best = { x, z, score };
}
if (best) {
const o = pose(ruches(4), best.x, best.z, 0); occupe(best.x, best.z, 0, 3.0, 0.8);
// les abeilles : quelques points jaunes en orbite lente
const n = 12, im = new THREE.InstancedMesh(new THREE.IcosahedronGeometry(0.07, 0), lam(COUL.abeille), n), M = new THREE.Matrix4(); o.add(im);
anim.push((t) => { for (let i = 0; i < n; i++) { const a = t * (0.5 + rnd(i) * 0.4) + i * 2.1, R = 1.2 + rnd(i * 3) * 1.8; im.setMatrixAt(i, M.makeTranslation(Math.cos(a) * R + (i % 4 - 1.5) * 1.6, 1.0 + Math.sin(t * 1.3 + i) * 0.4 + rnd(i * 5) * 0.8, Math.sin(a) * R * 0.7 + 0.6)); } im.instanceMatrix.needsUpdate = true; });
relie([o], 'vivant-ruches', 'ruches', { x: best.x, z: best.z, w: 40 });
} else laisses.push('ruches');
}
// ---- B4. La fête de la place : des guirlandes entre des mâts, au-dessus des étals ; une petite estrade
{
const objs = [], mMat = lam(COUL.poteau);
const tri = D.etals.map((e) => e.c).sort((a, b) => Math.atan2(a[1] - place[1], a[0] - place[0]) - Math.atan2(b[1] - place[1], b[0] - place[0]));
const mats = [];
for (const c of tri) { // un mât à côté de chaque étal, du côté de la place, là où il y a de la place
const dx = place[0] - c[0], dz = place[1] - c[1], n = Math.hypot(dx, dz) || 1; let m = null;
essai: for (const o of [3.2, 4.2, 5.2, 2.4]) for (const l of [0, 1.5, -1.5]) { const x = c[0] + dx / n * o - dz / n * l, z = c[1] + dz / n * o + dx / n * l; if (libre(x, z) >= 0.1) { m = [x, z]; break essai; } }
if (m) mats.push(m);
}
if (mats.length >= 3) {
const g = new THREE.Group(); objs.push(g);
mats.forEach(([x, z]) => { g.add(mesh(cyl(0.07, 4.4, 6), mMat, x, 2.2, z, true)); ajoute(x, z, 0.4); });
const fil = [], boules = [], CB = ['#c8553d', '#e0b04a', '#6f8fa8', '#8aa36a', '#efe7d2', '#a7768e'];
for (let i = 0; i < mats.length; i++) {
const a = mats[i], b = mats[(i + 1) % mats.length], L = Math.hypot(b[0] - a[0], b[1] - a[1]); if (L > 26 || L < 2) continue;
const pt = (u) => [a[0] + (b[0] - a[0]) * u, 4.2 - Math.sin(Math.PI * u) * Math.min(1.1, L * 0.06), a[1] + (b[1] - a[1]) * u];
for (let k = 0; k < 10; k++) fil.push(...pt(k / 10), ...pt((k + 1) / 10));
for (let s = 0.6; s < L - 0.3; s += 0.6) boules.push(pt(s / L));
}
const gf = new THREE.BufferGeometry(); gf.setAttribute('position', new THREE.Float32BufferAttribute(fil, 3)); g.add(new THREE.LineSegments(gf, new THREE.LineBasicMaterial({ color: '#5c4c3c' })));
const imB = new THREE.InstancedMesh(new THREE.IcosahedronGeometry(0.11, 0), lam('#ffffff'), boules.length), M = new THREE.Matrix4(), col = new THREE.Color();
boules.forEach(([x, y, z], i) => { imB.setMatrixAt(i, M.makeTranslation(x, y - 0.12, z)); imB.setColorAt(i, col.set(CB[i % CB.length])); }); imB.instanceColor.needsUpdate = true; g.add(imB);
groupe.add(g);
const es = cherche(place[0], place[1], 22, 2.2, 1.7, 1.2, { rots: [0, 0.4, -0.4] });
if (es) { const e = new THREE.Group(); e.add(mesh(boite(4, 0.55, 3), lam(COUL.planche), 0, 0.27, 0, true), mesh(boite(1.2, 0.27, 0.5), lam(COUL.bois), 0, 0.13, 1.75)); e.add(quilles(geoP, [[-0.8, -0.4], [0.7, 0.2]], gens).translateY(0.55)); objs.push(pose(e, es.x, es.z, es.rot)); occupe(es.x, es.z, es.rot, 2.2, 1.7); }
relie(objs, 'quartier-fete', 'fete', { x: place[0], z: place[1], w: 62 });
} else laisses.push('fete');
}
// ---- B5. Le terrain des forains : un chapiteau et une caravane, sur un délaissé assez grand à moins de 70 m de la place
{
const best = cherche(place[0], place[1], 70, 6.8, 5.0, 5.5, { rots: [0], pas: 3, poidsD: 0.04 });
if (best) { const o = pose(chapiteau(), best.x - 1.8, best.z, 0); occupe(best.x, best.z, 0, 6.8, 5.0); relie([o], 'quartier-forains', 'forains', { x: best.x, z: best.z, w: 50 }); }
else laisses.push('forains');
}
// ---- C1. Syntropie et jardin punk : deux parcelles côte à côte, dans un jardin (près d'une maison existante)
{
let best = null;
for (const r of existantes) {
if (prises.has(r.i)) continue;
const b = cherche(r.c.x, r.c.z, 22, 8.4, 3.6, 4.5, { rots: [r.rot, r.rot + Math.PI / 2], filtre: (x, z) => Math.hypot(x - r.c.x, z - r.c.z) > 8 && !coupe([r.c.x, r.c.z], [x, z]) });
if (b && (!best || b.score > best.score)) best = { ...b, r };
}
if (best) {
prises.add(best.r.i);
const g = new THREE.Group(), items = [];
g.add(mesh(new THREE.PlaneGeometry(7.6, 6.6).rotateX(-Math.PI / 2), lam(COUL.paillis), -4.2, 0.04, 0));
// la syntropie : trois étages plantés serré, au même moment
for (let i = 0; i < 22; i++) {
const etage = i < 4 ? 0 : i < 10 ? 1 : 2, u = -7.4 + rnd(i * 3.3) * 6.4, v = -2.8 + rnd(i * 5.7) * 5.6, j = 0.85 + rnd(i * 7.1) * 0.3;
const [x, z] = loc(best.x, best.z, best.rot, u, v);
items.push(etage === 0 ? { x, z, H: 6.2 * j, W: 2.2 * j, forme: 'ovoïde', couleur: teinte('#7f9f5c', {}, 93000 + i), fruit: null, rot: rnd(i) * 6.28 }
: etage === 1 ? { x, z, H: 3.2 * j, W: 2.0 * j, forme: 'boule', couleur: teinte('#94ad62', {}, 93100 + i), fruit: null, rot: rnd(i) * 6.28 }
: { x, z, H: 1.2 * j, W: 1.3 * j, forme: 'buisson', couleur: teinte('#87a35d', {}, 93200 + i), fruit: null, rot: rnd(i) * 6.28 });
}
const arbresS = lot(items, { couronne: matsArbres.couronne.clone(), tronc: matsArbres.tronc.clone(), fruit: matsArbres.fruit }, false);
// le jardin punk : des herbes hautes (cônes fins), un vieux banc
const n = 150, im = new THREE.InstancedMesh(new THREE.ConeGeometry(0.06, 1, 4).translate(0, 0.5, 0), lam('#ffffff'), n), M = new THREE.Matrix4(), Q = new THREE.Quaternion(), col = new THREE.Color(), E = new THREE.Euler();
const CH = ['#b9b27a', '#a9a670', '#94ad62', '#cbbf86', '#8ea366'];
for (let i = 0; i < n; i++) { const h = 0.7 + rnd(i * 2.3) * 0.9; Q.setFromEuler(E.set((rnd(i * 4.1) - 0.5) * 0.5, 0, (rnd(i * 6.7) - 0.5) * 0.5)); im.setMatrixAt(i, M.compose(new THREE.Vector3(0.8 + rnd(i * 1.9) * 7.0, 0, -3 + rnd(i * 3.7) * 6), Q, new THREE.Vector3(1, h, 1))); im.setColorAt(i, col.set(CH[i % CH.length])); }
im.instanceColor.needsUpdate = true; g.add(im);
const vb = new THREE.Group(), mb = lam(COUL.boisGris); vb.add(banc(1.6, mb, 0, 0)); vb.add(mesh(boite(1.6, 0.4, 0.05), mb, 0, 0.7, -0.17)); vb.position.set(4.5, 0, 1.5); vb.rotation.y = 0.2; g.add(vb);
pose(g, best.x, best.z, best.rot); groupe.add(arbresS); occupe(best.x, best.z, best.rot, 8.4, 3.6);
relie([g, arbresS], 'vivant-syntropie', 'syntropie', { x: best.x, z: best.z, w: 44 });
} else laisses.push('syntropie');
}
{ const L = []; for (let x = -Wx; x <= Wx; x += 2) for (let z = -Wz; z <= Wz; z += 2) L.push([Math.round(x), Math.round(z), +libre(x, z).toFixed(1)]); L.sort((a, b) => b[2] - a[2]); diag.grands = L.slice(0, 40); diag.place = place;
diag.route = []; for (let s = 0; s <= tP.L; s += 3) { const p = surTrajet(tP, s); if (Math.hypot(p.x - place[0], p.z - place[1]) < 30) { const n = Math.hypot(p.dx, p.dz), tx = p.dx / n, tz = p.dz / n; diag.route.push([Math.round(s), [5, 6.2, 8].map((o) => [1, -1].map((c) => +libre(p.x - tz * c * o, p.z + tx * c * o).toFixed(1)))]); } } }
return { anim, maj, cliquables, points, lumieres, haieOuverte, laisses, diag };
}
// les objets du Tour : leur fiche, la largeur de leur cadrage
export const TOUR_FICHES = { cuves: ['eau-cuves-appentis', 40], baissiere: ['eau-baissiere', 55], tube: ['energie-tube-solaire', 40], cochon: ['vivant-cochon', 40], chantier: ['quartier-chantier', 50], surplus: ['quartier-surplus', 40], planches: ['vivant-planches', 40] };
// l'intersection de deux segments [a, b] et [c, d] : { x, z, u } (u le long de [c, d]) ou null
function inter(a, b, c, d) {
const r = [b[0] - a[0], b[1] - a[1]], s = [d[0] - c[0], d[1] - c[1]], den = r[0] * s[1] - r[1] * s[0]; if (Math.abs(den) < 1e-9) return null;
const t = ((c[0] - a[0]) * s[1] - (c[1] - a[1]) * s[0]) / den, u = ((c[0] - a[0]) * r[1] - (c[1] - a[1]) * r[0]) / den;
return t > 0 && t < 1 && u >= 0 && u <= 1 ? { x: a[0] + t * r[0], z: a[1] + t * r[1], u } : null;
}
function grandPos(D) { const g = D.maisons.find((m) => m.t === 'grand'); return g ? [g.p.reduce((a, p) => a + p[0] / 4, 0), g.p.reduce((a, p) => a + p[1] / 4, 0)] : [0, 0]; }