Compare commits
12
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
21689831e5 | ||
|
|
df17a2440c | ||
|
|
7627a55b2b | ||
|
|
b36a4b63a3 | ||
|
|
eeb2a9a066 | ||
|
|
b138e2c1ee | ||
|
|
b0a4f3b009 | ||
|
|
3d04f7c50d | ||
|
|
eeabc09dc1 | ||
|
|
6e93784225 | ||
|
|
eedcaff710 | ||
|
|
907282c0ea |
@@ -0,0 +1,50 @@
|
||||
---
|
||||
titre: Les objets du quartier en 2035 (un objet = une ligne)
|
||||
statut: à relire par Jules (lot M1 table, 14/11/2026)
|
||||
licence: CC BY-SA 4.0
|
||||
---
|
||||
|
||||
# Les objets
|
||||
|
||||
Chaque objet posé dans le quartier de 2035 a sa ligne ici : ce qu'il est, la règle qui choisit sa place, sa fiche, son cadrage. La scène les pose **dans l'ordre des lignes**, chacun là où il reste de la place (l'atelier avant la colocation, sinon elle lui prenait sa place) : une ligne ajoutée en bas ne déplace aucun objet au-dessus d'elle.
|
||||
|
||||
## Mode d'emploi
|
||||
|
||||
- **Ajouter un objet d'un type qui existe** (une ruche de plus, un deuxième abri à vélos) : copier sa ligne, la coller en bas du tableau, lui donner un `id` neuf. **Déplacer** un objet : changer son `ancre` (près de quoi, à combien de mètres). Le build s'arrête et nomme la ligne si quelque chose ne va pas.
|
||||
- `id` : un nom en clair, unique, sans espace (`arret-bus`). `famille` : pour la lecture. `type` : la forme de l'objet (une fabrique de `maquette/objets.js` ; un type nouveau demande du code). `regle` : comment sa place est choisie (liste ci-dessous).
|
||||
- `ancre` : près de quoi, en mètres. Repères : `place`, `mare`, `grand` (le lieu commun), `bulle:<nom>` (une bulle de la planche), ou l'`id` d'une ligne au-dessus. `, sinon` donne un repli.
|
||||
- `taille` : longueur × largeur × hauteur (m), l'emprise que la place doit avoir libre ; elle ne redessine pas l'objet (sa forme est celle du type). `teinte` : une couleur de la palette (`autos-5`, `sentier`…), jamais un code ; `—` laisse celle du type.
|
||||
- `fiche` : l'identifiant d'une fiche de `fiches.md` (`—` : l'objet ouvre la fiche d'une autre ligne). `cadrage` : le nom du cadrage et sa largeur vue (m) ; sans largeur, le cadrage suit l'objet qui roule ; `avec <id>` élargit le cadrage de cette ligne pour montrer les deux.
|
||||
- `epoque` : `2035`, `auj` ou `les deux`. `plaque` : réservée aux plaques voisines (`centre` partout ; pas encore lue).
|
||||
|
||||
Les règles : `bord-route` (au bord d'une route, près d'un repère) · `pres-de` (au plus près d'un repère, là où c'est libre et vu) · `ombre` (sous des arbres, près d'un repère) · `plus-grande-place` (la plus grande des tailles qui tient, hors pâturages) · `lisiere` (en lisière de la forêt ou des vergers, loin des chemins) · `maison-existante` (dans le jardin d'une maison existante, sinon sur une parcelle libre) · `sur-trajet` (roule sur une route, à tant de m/s) · `coordonnees` (x z en mètres : en dernier recours) · `propre` (l'objet change le plan — une haie qui s'ouvre, une maison qui change de rôle — et sa pose reste écrite à la main).
|
||||
|
||||
## Objets
|
||||
|
||||
| id | famille | type | regle | ancre | taille | teinte | fiche | cadrage | epoque | plaque |
|
||||
|---|---|---|---|---|---|---|---|---|---|---|
|
||||
| cuves | Objets du Tour | geste | propre | — | — | — | eau-cuves-appentis | cuves 40 | 2035 | centre |
|
||||
| baissiere | Objets du Tour | geste | propre | — | — | — | eau-baissiere | baissiere 55 | 2035 | centre |
|
||||
| tube | Objets du Tour | geste | propre | — | — | — | energie-tube-solaire | tube 40 | 2035 | centre |
|
||||
| cochon | Objets du Tour | geste | propre | — | — | — | vivant-cochon | cochon 40 | 2035 | centre |
|
||||
| chantier | Objets du Tour | geste | propre | — | — | — | quartier-chantier | chantier 50 | 2035 | centre |
|
||||
| surplus | Objets du Tour | geste | propre | — | — | — | quartier-surplus | surplus 40 | 2035 | centre |
|
||||
| planches | Objets du Tour | geste | propre | — | — | — | vivant-planches | planches 40 | 2035 | centre |
|
||||
| convoi | Mobilité | convoi | propre | principale | — | — | quartier-convoi | convoi | 2035 | centre |
|
||||
| arret-bus | Mobilité | abri-bus | bord-route | principale, place 25 | 5,2 × 2,2 × 2,6 | — | — | arret 40 | 2035 | centre |
|
||||
| point-fraicheur | Faire ensemble | point-fraicheur | ombre | mare 40, place 40 | 7,2 × 5,2 × 2,8 | — | quartier-fraicheur | fraicheur 42 | 2035 | centre |
|
||||
| navette | Mobilité | navette | sur-trajet | anneau 4,5 | — | — | quartier-navette | navette | 2035 | centre |
|
||||
| bus | Mobilité | minibus | propre | arret-bus | — | autos-1 | quartier-bus | bus | 2035 | centre |
|
||||
| atelier | Faire ensemble | atelier | pres-de | bulle:garage 26, sinon grand 40 | 8,8 × 8,6 × 4,5 | autos-5 | quartier-atelier | atelier 44 | 2035 | centre |
|
||||
| jardin-commun | Habiter ensemble | jardin-commun | propre | — | — | — | quartier-jardin-commun | jardin-commun 58 | 2035 | centre |
|
||||
| colocation | Habiter ensemble | colocation | propre | — | — | — | quartier-colocation | colocation 44 | 2035 | centre |
|
||||
| conserverie | Faire ensemble | conserverie | pres-de | bulle:confiture 26, sinon grand 40 | 9,2 × 5,4 × 3,6 | — | quartier-conserverie | conserverie 42 | 2035 | centre |
|
||||
| alambic | Faire ensemble | alambic | pres-de | conserverie 30 | 6,6 × 4 × 2,8 | — | quartier-conserverie | avec conserverie | 2035 | centre |
|
||||
| potager-commun | Faire ensemble | potager-commun | plus-grande-place | troupeaux 12 | 20 × 12 × 2,5, sinon 16 × 10 × 2,5, sinon 13 × 8,5 × 2,5 | — | vivant-potager | potager 44 | 2035 | centre |
|
||||
| tiny-houses | Habiter ensemble | tiny-houses | propre | — | — | — | quartier-tiny | tiny 60 | les deux | centre |
|
||||
| abri-cargos | Mobilité | abri-cargos | pres-de | place 34 | 6,6 × 3,2 × 2,4 | — | quartier-cargos | cargos 40 | 2035 | centre |
|
||||
| rosalie | Mobilité | rosalie | sur-trajet | anneau à rebours 2 | — | sentier | quartier-rosalie | rosalie | 2035 | centre |
|
||||
| ruches | Faire ensemble | ruches | lisiere | forêt ou vergers | 6 × 1,6 × 1 | — | vivant-ruches | ruches 40 | 2035 | centre |
|
||||
| fete | Fête | fete | propre | place | — | — | quartier-fete | fete 62 | 2035 | centre |
|
||||
| forains | Fête | chapiteau | pres-de | place 70 | 13,6 × 10 × 5,5 | — | quartier-forains | forains 50 | 2035 | centre |
|
||||
| syntropie | Faire ensemble | syntropie | maison-existante | jardin 22 | 16,8 × 7,2 × 4,5 | — | vivant-syntropie | syntropie 44 | 2035 | centre |
|
||||
+29
-5
@@ -46,7 +46,7 @@ export function canard() {
|
||||
g.add(mesh(boite(0.1, 0.03, 0.06), MAT.bec, 0.38, 0.26, 0, false));
|
||||
return g;
|
||||
}
|
||||
export function attelage() {
|
||||
export function attelage(tete = false) {
|
||||
const g = new THREE.Group();
|
||||
const cheval = new THREE.Group();
|
||||
cheval.add(mesh(boule(0.5, 1.6, 0.85, 0.75), MAT.cheval, 0, 1.45, 0));
|
||||
@@ -58,7 +58,9 @@ export function attelage() {
|
||||
g.add(mesh(boite(2.2, 0.5, 1.4), MAT.bois, -0.6, 1.0, 0));
|
||||
g.add(mesh(boite(0.6, 0.35, 0.5), MAT.caisse, -0.9, 1.42, 0.2), mesh(boite(0.5, 0.3, 0.45), lam('#a9be7c'), -0.2, 1.4, -0.25));
|
||||
for (const z of [0.78, -0.78]) g.add(mesh(new THREE.CylinderGeometry(0.55, 0.55, 0.12, 14).rotateX(Math.PI / 2), MAT.roue, -0.6, 0.55, z));
|
||||
g.add(mesh(new THREE.CapsuleGeometry(0.24, 0.55, 3, 8), lam('#6f8fa8'), 0.25, 1.65, 0));
|
||||
// le meneur ; au trait (lot M1, X5), avec une tête
|
||||
g.add(mesh(tete ? mergeGeometries([new THREE.CapsuleGeometry(0.24, 0.4, 3, 8).translate(0, -0.075, 0), new THREE.SphereGeometry(0.17, 10, 7).translate(0, 0.5, 0)])
|
||||
: new THREE.CapsuleGeometry(0.24, 0.55, 3, 8), lam('#6f8fa8'), 0.25, 1.65, 0));
|
||||
return g;
|
||||
}
|
||||
// Un tube entre deux points (pour les jambes, les bras, la tige de selle).
|
||||
@@ -89,15 +91,37 @@ export function velo(couleur, remonte = true) {
|
||||
g.add(mesh(new THREE.CapsuleGeometry(0.24, 0.62, 3, 8), lam(couleur), -0.1, 1.32, 0));
|
||||
return g;
|
||||
}
|
||||
export function veloCargo(couleur) {
|
||||
// `monte` (lot M1, 14/11, étude du 03/11 §1 n° 4) : comme `velo()` remonté, le cycliste est assis sur une selle (tige et
|
||||
// selle dans le cadre), les mains au guidon, les pieds aux pédales, une tête. Les enfants du groupe restent sept, dans le
|
||||
// même ordre (cadre, deux roues, caisse, deux fruits, cycliste) : objets.js et maison.js retirent les trois derniers pour
|
||||
// un cargo garé. Faux : l'ancien cargo (le cycliste flottait de 13 cm au-dessus du cadre), gardé pour `?rendu=avant`.
|
||||
export const SELLE_CARGO = { x: -0.55, y: 0.96 };
|
||||
export function veloCargo(couleur, monte = false) {
|
||||
const g = new THREE.Group();
|
||||
g.add(mesh(boite(2.5, 0.1, 0.12), MAT.velo, 0, 0.55, 0));
|
||||
if (monte) {
|
||||
const { x: xs, y: ys } = SELLE_CARGO;
|
||||
g.add(mesh(mergeGeometries([boite(2.5, 0.1, 0.12).translate(0, 0.55, 0), segment([xs, 0.58, 0], [xs, ys - 0.05, 0], 0.035), boite(0.28, 0.06, 0.15).translate(xs, ys - 0.03, 0),
|
||||
segment([0.22, 0.58, 0], [0.18, 1.14, 0], 0.035), boite(0.06, 0.05, 0.62).translate(0.18, 1.15, 0)]), MAT.velo));
|
||||
} else g.add(mesh(boite(2.5, 0.1, 0.12), MAT.velo, 0, 0.55, 0));
|
||||
for (const x of [1.05, -0.95]) g.add(mesh(new THREE.TorusGeometry(0.3, 0.04, 5, 14), MAT.velo, x, 0.32, 0, false));
|
||||
g.add(mesh(boite(0.85, 0.6, 0.8), MAT.caisse, 0.75, 0.88, 0));
|
||||
g.add(mesh(boule(0.18), lam('#c8553d'), 0.6, 1.25, 0.15), mesh(boule(0.16), lam('#a9be7c'), 0.9, 1.24, -0.15));
|
||||
g.add(mesh(new THREE.CapsuleGeometry(0.24, 0.62, 3, 8), lam(couleur), -0.55, 1.28, 0));
|
||||
if (monte) {
|
||||
const { x: xs, y: ys } = SELLE_CARGO, ax = (l) => [xs + l * Math.sin(0.45), ys + l * Math.cos(0.45)]; // l'axe du buste, penché de 0,45 rad
|
||||
const [ex, ey] = ax(0.66), [tx, ty] = ax(1.0);
|
||||
g.add(mesh(mergeGeometries([new THREE.CapsuleGeometry(0.2, 0.42, 3, 8).translate(0, 0.42, 0).rotateZ(-0.45).translate(xs, ys, 0),
|
||||
new THREE.SphereGeometry(0.16, 10, 7).translate(tx, ty, 0),
|
||||
...[0.12, -0.12].flatMap((z) => [segment([xs + 0.04, ys + 0.03, z], [xs + 0.4, 0.7, z], 0.075), segment([xs + 0.4, 0.7, z], [xs + 0.36, 0.38, z * 1.2], 0.065),
|
||||
segment([ex, ey, z * 1.5], [0.18, 1.15, z * 2.3], 0.055)])]), lam(couleur)));
|
||||
} else g.add(mesh(new THREE.CapsuleGeometry(0.24, 0.62, 3, 8), lam(couleur), -0.55, 1.28, 0));
|
||||
return g;
|
||||
}
|
||||
/** Le personnage (lot M1, X5) : la quille d'avant (capsule de 1,51 m) ou, `tete`, un buste et une tête, même hauteur,
|
||||
* même pied (centrée comme l'ancienne : posée à y = 0,76). Une seule géométrie : les instances ne coûtent rien de plus. */
|
||||
export function quille(tete = false) {
|
||||
if (!tete) return new THREE.CapsuleGeometry(0.28, 0.95, 3, 8);
|
||||
return mergeGeometries([new THREE.CapsuleGeometry(0.27, 0.6, 3, 8).translate(0, -0.185, 0), new THREE.SphereGeometry(0.2, 10, 7).translate(0, 0.555, 0)]);
|
||||
}
|
||||
export function voiture(couleur, partagee = false) {
|
||||
const g = new THREE.Group(), m = partagee ? MAT.partage : lam(couleur);
|
||||
g.add(mesh(boite(4.2, 0.9, 1.8), m, 0, 0.65, 0));
|
||||
|
||||
+2
-1
@@ -34,6 +34,7 @@ import { creerMur } from './mur.js';
|
||||
import { creerCarte } from './carte.js';
|
||||
import { picto, COULEURS } from './pictos.js';
|
||||
import { lireModeV0 } from './mode.ts';
|
||||
import { lireRendu } from './rendu.ts';
|
||||
import { ANCRES, BARRE, BUREAU_MIN, LIBELLES, echelleDe, etatCamera, etatDepart, etatSuivant, finDefilement, hauteurBandeau, ongletsDe, parcoursActif, SEUIL_TIRAGE, tirage } from './nav.ts';
|
||||
import { PAS, etapesDe, demarrer, allumage, aller as allerEtape, pause as pauseAllumage, reprendre, indexDe, debutChapitre } from './allumage.ts';
|
||||
import { TRAIT_SEUL, maisonTrait, allumer, vueS, VUE_S_DEPART } from './maison-trait.ts';
|
||||
@@ -539,7 +540,7 @@ addEventListener('keydown', (e) => {
|
||||
let toucheObjet = -1e9;
|
||||
try {
|
||||
T3 = creerScene($('scene'), {
|
||||
D, ESSENCES, BULLES, IMG: { sol2035, solauj }, reduit, petit, differer: ARRIVEE_TER,
|
||||
D, ESSENCES, BULLES, IMG: { sol2035, solauj }, reduit, petit, differer: ARRIVEE_TER, rendu: lireRendu(location.search, FOND),
|
||||
onToucher(type, a, b) {
|
||||
suspendre();
|
||||
if (type === 'dezoom') { allerA(ficheCarte()); bandeau.envoyer('echelle'); return; } // dézoomer au-delà du quartier : la carte du territoire
|
||||
|
||||
+362
-583
@@ -12,6 +12,8 @@ import { mergeGeometries } from 'three/addons/utils/BufferGeometryUtils.js';
|
||||
import { lot, teinte, rnd } from './vegetal.js';
|
||||
import { MAT, veloCargo } from './animaux.js';
|
||||
import { RETOUCHES_EN_FOND, MINIBUS, VOIE_BUS, gabaritManoir, voisinesMangees, trajetBus, horaireBus } from './retouches.ts';
|
||||
import { creerPose, REGLES, trajet, surTrajet, projete, roule, inter } from './pose.ts';
|
||||
import { OBJETS } from 'virtual:contenu';
|
||||
|
||||
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; };
|
||||
@@ -153,91 +155,6 @@ export function rosalie(geoP, couleurs, teinteCadre = ROSALIE_CADRE_FOND) {
|
||||
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;
|
||||
}
|
||||
// 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);
|
||||
@@ -428,497 +345,35 @@ function chapiteau() {
|
||||
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] }.
|
||||
// lot ⑤ : `fond` (le mode fond, aucun matériau cloné de plus, la Rosalie dans son vert) ; rend aussi `maisonsObjets`
|
||||
// ({ effet: [indices de D.maisons] }) : les maisons du plan que portent la colocation, les tiny houses et le jardin commun.
|
||||
export function objetsNouveaux({ D, groupe, T, P, maisons, tr, PAL, geoP, verre, matsArbres, tour, convoi, fond = false, aujourdhui = null }) {
|
||||
const anim = [], maj = [], cliquables = [], points = {}, lumieres = {}, laisses = [], gens = PAL.gens, maisonsObjets = {};
|
||||
// retouches du 07/11 (retouches.ts) : le minibus, la maison de maître ; jamais en mode fond (le fond reste au pixel)
|
||||
const retouches = !fond || RETOUCHES_EN_FOND, mesureRetouches = {};
|
||||
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. La grille
|
||||
// encadre la valeur vraie (P.libre ne varie pas plus vite que la distance) : au-dessus du seuil par le bas, c'est libre ;
|
||||
// sous le seuil par le haut, c'est pris ; entre les deux (1,4 m au plus), on calcule la valeur vraie. Sans ce calcul, la
|
||||
// grille seule coûtait jusqu'à 1,4 m et laissait de côté l'arrêt de bus, la colocation et le potager (03/11).
|
||||
const PAS = 2, memo = new Map(), fin = 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, seuil = -Infinity) => {
|
||||
const i = Math.round(x / PAS), j = Math.round(z / PAS), c = cellule(i, j), d = Math.hypot(x - i * PAS, z - j * PAS);
|
||||
let v = c - d >= seuil ? c - d : c + d < seuil ? c + d : null;
|
||||
if (v === null) { // une seconde grille, de 0,5 m (écart 0,35 m au plus), avant la valeur vraie
|
||||
const fi = Math.round(x * 2), fj = Math.round(z * 2), k = cle(fi, fj); let f = fin.get(k);
|
||||
if (f === undefined) fin.set(k, (f = P.libre(fi / 2, fj / 2)));
|
||||
const e = Math.hypot(x - fi / 2, z - fj / 2); v = f - e >= seuil ? f - e : f + e < seuil ? f + e : P.libre(x, z);
|
||||
}
|
||||
return Math.min(v, dVie(x, z, 3) - 1.0, dForet(x, z, 4) - 2.0);
|
||||
};
|
||||
const ajoute = (x, z, r) => { P.ajoute(x, z, r); fin.clear(); 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) {
|
||||
// tri rapide : le disque inscrit (rayon min(a, b)) doit être libre ; la grille en donne un majorant au centre
|
||||
{ const i = Math.round(x / PAS), j = Math.round(z / PAS), hi = cellule(i, j) + Math.hypot(x - i * PAS, z - j * PAS) - Math.min(a, b); if (hi < seuil) return hi; }
|
||||
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, seuil)); 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]) for (const off of [6.2, 7.0, 7.8]) {
|
||||
const nx = -tz * cote, nz = tx * cote, x = p.x + nx * off, z = p.z + nz * off, 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) - 0.3 * (off - 6.2);
|
||||
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 : en boucle sur l'anneau (le défaut du brief), 4,5 m/s, 5 s à deux arrêts : au carrefour de la
|
||||
// liaison et à l'opposé, au bas de la boucle. Elle ne va pas jusqu'à l'arrêt de bus : la seule route qui y mène depuis
|
||||
// l'anneau, `liaison_anneau`, traverse une maison du plan (la n° 11) ; aucune route n'est inventée (03/11).
|
||||
if (tr.anneau) {
|
||||
const t = tr.anneau, la = tr.liaison_anneau?.pts, bout = la ? la[la.length - 1] : t.pts[0];
|
||||
const s1 = projete(t, bout[0], bout[1]).s, s2 = (s1 + t.L / 2) % t.L;
|
||||
const o = navette(); groupe.add(o);
|
||||
const r = roule(o, t, { v: 4.5, decal: 1.8, arrets: [{ s: s1, p: 5 }, { s: s2, p: 5 }], boucle: true, bouts: false, 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.
|
||||
// Retouches du 07/11 (T3) : un minibus de quartier, sur sa voie (VOIE_BUS, les vélos ont leur piste, PISTE) ; la principale
|
||||
// va d'un bord de la carte à l'autre (aucune boucle ne passe par l'arrêt) : il entre par un bord, s'arrête à l'arrêt,
|
||||
// sort par l'autre, attend hors champ et revient dans l'autre sens. Hors du socle, il est coupé (plans de coupe) : aucun
|
||||
// demi-tour ne se voit. Le mode fond garde le bus d'avant.
|
||||
const tBus = arret && retouches ? trajetBus(tP.pts, D) : null;
|
||||
if (arret) {
|
||||
let o, centre;
|
||||
if (tBus) {
|
||||
const t = trajet(tBus), sArret = projete(t, arret.x, arret.z).s, v = 6; o = minibus(PAL.autos[1]); centre = { x: 0, z: 0 };
|
||||
let tau = sArret / v + 1.5; // au départ, le minibus est à l'arrêt (on le voit en arrivant)
|
||||
const poser = (dt) => {
|
||||
tau += dt; const h = horaireBus(tau, t.L, v, sArret), p = surTrajet(t, h.s);
|
||||
let dx = p.dx * h.sens, dz = p.dz * h.sens; const n = Math.hypot(dx, dz) || 1; dx /= n; dz /= n;
|
||||
o.position.set(p.x - dz * VOIE_BUS, 0, p.z + dx * VOIE_BUS); o.rotation.y = Math.atan2(-dz, dx);
|
||||
o.visible = !h.attente; centre.cache = !!h.attente; centre.x = o.position.x; centre.z = o.position.z;
|
||||
};
|
||||
poser(0); maj.push(poser);
|
||||
Object.assign(mesureRetouches, { bus: { L: MINIBUS.L, l: MINIBUS.l, h: MINIBUS.h, trajet: tBus, sArret, voie: VOIE_BUS, v } });
|
||||
} else {
|
||||
o = bus(PAL.autos[1]);
|
||||
const r = roule(o, tP, { v: 6, decal: 1.9, arrets: [{ s: arret.s, p: 6 }], depart: 0.15 }); maj.push(r.maj); centre = r.centre;
|
||||
}
|
||||
groupe.add(o); relie([o, ...arret.objs], 'quartier-bus', 'bus'); points.bus = centre; points.arret = { x: arret.x, z: arret.z, w: 40 };
|
||||
// les plans de coupe : le minibus n'existe que sur le socle (scene.js allume localClippingEnabled hors mode fond)
|
||||
if (tBus) {
|
||||
const plans = [[1, 0], [-1, 0], [0, 1], [0, -1]].map(([a, b]) => new THREE.Plane(new THREE.Vector3(a, 0, b), a ? D.Wm / 2 : D.Hm / 2));
|
||||
o.traverse((m) => { if (m.material) { m.material.clippingPlanes = plans; m.material.clipShadows = true; } });
|
||||
}
|
||||
} else laisses.push('bus');
|
||||
|
||||
// ---- A5 (posé avant les maisons : la colocation lui prenait sa place). 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');
|
||||
}
|
||||
|
||||
// ---- 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' });
|
||||
// lot ⑤ (P3) : les deux maisons s'allument et brillent avec le jardin (leurs matériaux leur deviennent propres ; pas en mode fond)
|
||||
if (!fond) {
|
||||
const map = new Map();
|
||||
for (const m of [ma, mb]) if (m) m.traverse((o) => { if (!o.material || Array.isArray(o.material) || !o.material.emissive) return; if (!map.has(o.material)) map.set(o.material, o.material.clone()); o.material = map.get(o.material); });
|
||||
lumieres['jardin-commun'].push(...map.values());
|
||||
}
|
||||
maisonsObjets['jardin-commun'] = [a.i, b.i];
|
||||
} 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;
|
||||
// à 3,5 m du mur, la maison elle-même compte pour 1,5 m (son contour est un obstacle de 2 m) : au-dessus de 1,2, rien
|
||||
// d'autre n'est sur la terrasse ; plus loin (portique, bac à sable, étendoir), 0,3 m de marge suffit
|
||||
for (let al = -W / 2 + 0.5; al <= W / 2 - 0.5 + 1e-6; al += 1.5) for (const [dp, m] of [[3.5, 0.9], [4.5, 0], [5.5, 0], [6.6, 0]]) 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, 0.3 + m) - m);
|
||||
if (pl < 0.3) 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, 6.4));
|
||||
const fil = new THREE.BufferGeometry(); fil.setAttribute('position', new THREE.Float32BufferAttribute([-W * 0.3 - 1.2, 1.7, 6.4, -W * 0.3 + 1.2, 1.7, 6.4], 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, 6.4)));
|
||||
// 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, 5.7],
|
||||
[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' });
|
||||
maisonsObjets.colocation = [r.i];
|
||||
} else laisses.push('colocation');
|
||||
}
|
||||
|
||||
// ---- A6. La conserverie : sous la bulle « confiture », ou près du grand bâtiment. B6. L'atelier public de distillation
|
||||
// (03/11) : à part, à 8-30 m de la conserverie, à 4 m au moins de toute maison (jamais dans ni contre une maison) ; même
|
||||
// fiche, même allumage, le cadrage de la conserverie s'élargit pour les montrer ensemble.
|
||||
{
|
||||
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));
|
||||
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);
|
||||
const loin = (x, z) => { const d = Math.hypot(x - best.x, z - best.z); return d >= 8 && d <= 30 && reps.every((r) => Math.hypot(x - r.c.x, z - r.c.z) > Math.max(r.Lu, r.Lv) / 2 + 4); };
|
||||
const al = cherche(best.x, best.z, 30, 3.3, 2.0, 2.8, { rots: [0, 0.3, -0.3], filtre: loin });
|
||||
const objs = [o]; let point = { x: best.x, z: best.z, w: 42 };
|
||||
if (al) {
|
||||
objs.push(pose(atelierDistillation(), al.x, al.z, al.rot)); occupe(al.x, al.z, al.rot, 3.3, 2.0);
|
||||
point = { x: (best.x + al.x) / 2, z: (best.z + al.z) / 2, w: Math.min(66, Math.max(42, Math.hypot(al.x - best.x, al.z - best.z) + 28)) };
|
||||
} else laisses.push('alambic');
|
||||
relie(objs, 'quartier-conserverie', 'conserverie', point);
|
||||
} else laisses.push('conserverie', 'alambic');
|
||||
}
|
||||
|
||||
// ---- A7. Le potager partagé et la serre commune : la plus grande place libre hors forêt, mare et pâturages (12 m au
|
||||
// moins de tout troupeau), vue ; 20 × 12 m si la place y est, sinon 16 × 10, sinon 13 × 8,5 (le plan est plein : 03/11)
|
||||
{
|
||||
const dTroupeau = grilleP(D.troupeaux.map((t) => [t[0], t[1]]), 8);
|
||||
let best = null;
|
||||
for (const [L, W] of [[20, 12], [16, 10], [13, 8.5]]) {
|
||||
const a = L / 2 + 0.6, b = W / 2 + 0.6;
|
||||
for (const [x, z] of autour(0, 0, 200, 4)) for (const rot of [0, 0.3, -0.3, Math.PI / 2]) {
|
||||
if (dTroupeau(x, z, 12 + a) < 12 + a) continue;
|
||||
const pl = emprise(x, z, rot, a, b, 0.1); if (pl < 0.1) continue;
|
||||
const score = -3 * vu(x, z, rot, a, b, 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, L, W, a, b };
|
||||
}
|
||||
if (best) break;
|
||||
}
|
||||
if (best) {
|
||||
const o = pose(potagerCommun(geoP, gens, verre.clone(), best.L, best.W), best.x, best.z, best.rot); occupe(best.x, best.z, best.rot, best.a, best.b);
|
||||
relie([o], 'vivant-potager', 'potager', { x: best.x, z: best.z, w: Math.max(44, best.L * 2.5) });
|
||||
} 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 } = best; let { choix } = best; prises.add(r.i);
|
||||
// Retouches du 07/11 (T1) : la maison devient une maison de maître (deux fois la médiane, un étage de plus, quatre pans),
|
||||
// son terrain « mange » la maison voisine que ni route, ni chemin, ni sentier n'en sépare (retouches.ts), et les tiny
|
||||
// houses se répartissent de l'une à l'autre. Une tiny house ne se pose pas devant un objet du Tour (elle le cacherait).
|
||||
let fx = r.c.x + r.face.n[0] * (r.face.d + 1), fz = r.c.z + r.face.n[1] * (r.face.d + 1), mangees = [], manoirG = null, proche = choix;
|
||||
if (retouches && maisons[r.i]) {
|
||||
const gab = gabaritManoir(D.maisons), hg = maisons[r.i], rot = hg.rotation.y, n = r.face.n;
|
||||
const face = [n[0] * Math.cos(rot) - n[1] * Math.sin(rot), n[0] * Math.sin(rot) + n[1] * Math.cos(rot)];
|
||||
const trait = hg.children.find((o) => o.isLineSegments)?.material;
|
||||
// aujourd'hui, la maison d'avant et sa voisine restent (checkpoint du 10/11) : une copie dans `aujourdhui`, l'original en 2035
|
||||
const garde = (m) => { if (!aujourdhui || !m) return; aujourdhui.add(m.clone()); groupe.attach(m); };
|
||||
garde(hg); hg.clear(); manoirG = manoir(gab, gab, trait, face); hg.add(manoirG);
|
||||
const dF = (Math.abs(face[0]) > Math.abs(face[1]) ? gab.long : gab.court) / 2; fx = r.c.x + n[0] * (dF + 2.4); fz = r.c.z + n[1] * (dF + 2.4);
|
||||
occupe(r.c.x, r.c.z, r.rot, gab.long / 2 + 1.5, gab.court / 2 + 1.5);
|
||||
mangees = voisinesMangees(D, r.i, { prises, loinDe: [[T.c.x, T.c.y]] });
|
||||
for (const j of mangees) { prises.add(j); if (maisons[j]) { garde(maisons[j]); maisons[j].clear(); } } // la maison mangée n'est plus dessinée
|
||||
// les places : de la maison de maître jusqu'à chaque maison mangée (à 16 m au plus de leur ligne), sans route, chemin ni
|
||||
// sentier entre elles ; vues de la caméra ; pas devant un objet du Tour (à moins de 6 m de côté, 14 m devant)
|
||||
const devant = Object.values(tour?.points || {}).filter(Boolean);
|
||||
const cache = (x, z) => devant.some((q) => Math.abs(x - q.x) < 6 && z - q.z > -2 && z - q.z < 14);
|
||||
const cibles = [r, ...mangees.map((j) => reps[j])], cands = [];
|
||||
for (const [x, z] of autour(r.c.x, r.c.z, 26 + Math.max(0, ...cibles.map((q) => Math.hypot(q.c.x - r.c.x, q.c.z - r.c.z))), 2)) {
|
||||
const pres = Math.min(...cibles.map((q) => Math.hypot(x - q.c.x, z - q.c.z)));
|
||||
const ligne = cibles.slice(1).some((q) => { const ux = q.c.x - r.c.x, uz = q.c.z - r.c.z, l = Math.hypot(ux, uz) || 1, t = ((x - r.c.x) * ux + (z - r.c.z) * uz) / l; return t > 0 && t < l && Math.abs(((x - r.c.x) * uz - (z - r.c.z) * ux) / l) < 16; });
|
||||
if (pres > 24 && !ligne) continue;
|
||||
if (coupeSansHaie([r.c.x, r.c.z], [x, z]) || cache(x, z)) continue;
|
||||
for (const rt of [r.rot, r.rot + Math.PI / 2]) { if (emprise(x, z, rt, 3.2, 1.6, 0.4) < 0.4 || vu(x, z, rt, 3.2, 1.6, 3.6) > 0) continue; cands.push({ x, z, rot: rt, R: Math.hypot(x - r.c.x, z - r.c.z) }); }
|
||||
}
|
||||
// réparties : la moitié près de la maison, le reste en échelons jusqu'à la maison mangée la plus loin
|
||||
const Rmax = Math.max(...cands.map((c) => c.R), 1), nouveaux = [];
|
||||
for (const cible of [0, 0, 0, 0, 0.35, 0.55, 0.75, 0.95]) {
|
||||
const dispo = cands.filter((c) => !nouveaux.some((o) => Math.hypot(o.x - c.x, o.z - c.z) < 7.6));
|
||||
if (!dispo.length) break;
|
||||
nouveaux.push(dispo.reduce((a, c) => (Math.abs(c.R - cible * Rmax) < Math.abs(a.R - cible * Rmax) ? c : a)));
|
||||
}
|
||||
if (nouveaux.length >= 4) choix = nouveaux;
|
||||
proche = choix.filter((c) => Math.hypot(c.x - r.c.x, c.z - r.c.z) < 30);
|
||||
mesureRetouches.manoir = { maison: r.i, ...gab, mangees, tiny: choix.length, x: r.c.x, z: r.c.z };
|
||||
}
|
||||
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 proche ; la table commune au milieu
|
||||
const gravier = lam('#d8cfbd'), objs = [g];
|
||||
for (const c of proche) { 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 = (proche.length ? proche : choix).reduce((a, c, _, L) => [a[0] + c.x / L.length, a[1] + c.z / L.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); }
|
||||
// le cadrage : la maison et toutes ses tiny houses (le terrain agrandi), 60 m au moins
|
||||
let point = { x: (m[0] * 2 + r.c.x) / 3, z: (m[1] * 2 + r.c.z) / 3, w: 60 };
|
||||
if (manoirG) { const X = [r.c.x, ...choix.map((c) => c.x)], Z = [r.c.z, ...choix.map((c) => c.z)]; point = { x: (Math.min(...X) + Math.max(...X)) / 2, z: (Math.min(...Z) + Math.max(...Z)) / 2, w: Math.max(60, (Math.max(...X) - Math.min(...X)) * 1.3 + 16, (Math.max(...Z) - Math.min(...Z)) * 0.9 + 16) };
|
||||
point.x = Math.max(point.x, -D.Wm / 2 + point.w * 0.4); } // au bord ouest : le cadrage reste sur le socle (au téléphone, × 0,8)
|
||||
relie(objs, 'quartier-tiny', 'tiny', point);
|
||||
if (maisons[r.i]) cliquables.push({ o: maisons[r.i], fiche: 'quartier-tiny' });
|
||||
// la maison de maître s'allume et brille avec ses tiny houses (ses matériaux sont à elle)
|
||||
if (manoirG) { const S = new Set(); manoirG.traverse((o) => { if (o.material && o.material.emissive) S.add(o.material); }); lumieres.tiny.push(...S); }
|
||||
maisonsObjets.tiny = [r.i, ...mangees];
|
||||
if (mangees.length) maisonsObjets.mangees = mangees;
|
||||
} 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, fond ? ROSALIE_CADRE_FOND : ROSALIE_CADRE); groupe.add(o);
|
||||
// à contresens de la navette : sur sa droite, elle est dans l'autre voie et ne la croise jamais dans la même
|
||||
const r = roule(o, trajet([...tr.anneau.pts].reverse()), { 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 types : la fabrique de chaque type de content/objets.md
|
||||
// et ses réglages de pose (rotations essayées, pas, repli, décalage de l'emprise, cadrage). `fabrique(place, ligne)` rend
|
||||
// l'objet { o, extra?, anim? } (o est posé à la place ; extra est ajouté tel quel au groupe). Un type nouveau = une entrée
|
||||
// ici, une fabrique au-dessus, et son nom dans TYPES_OBJETS (scripts/contenu.ts).
|
||||
function typesObjets({ geoP, gens, PAL, verre, matsArbres, fond, c }) {
|
||||
return {
|
||||
'abri-bus': { fabrique: () => ({ o: abriBus() }), offs: [6.2, 7.0, 7.8] },
|
||||
'point-fraicheur': { fabrique: () => ({ o: pointFraicheur(geoP, gens) }), rots: [0, 0.35, -0.35], decal: 0.7, point: (b, w) => ({ x: b.x + 0.7, z: b.z, w }) },
|
||||
atelier: { fabrique: (b, l) => ({ o: atelier(geoP, gens, teinteDe(l, PAL.autos[5])) }), rots: [0, 0.25, -0.25], point: (b, w) => ({ x: b.x, z: b.z + 0.5, w }) },
|
||||
conserverie: { fabrique: () => { const g = new THREE.Group(); g.add(conserverie(geoP, gens)); g.position.x = 0.5; const o = new THREE.Group(); o.add(g); return { o }; }, rots: [0, 0.25, -0.25], repli: { rots: [0] } },
|
||||
// B6 (03/11) : l'atelier public de distillation, à part : à 8-30 m de son ancre, à 4 m au moins de toute maison
|
||||
alambic: { fabrique: () => ({ o: atelierDistillation() }), rots: [0, 0.3, -0.3],
|
||||
filtre: (c, q) => (x, z) => { const d = Math.hypot(x - q[0], z - q[1]); return d >= 8 && d <= 30 && c.reps.every((r) => Math.hypot(x - r.c.x, z - r.c.z) > Math.max(r.Lu, r.Lv) / 2 + 4); } },
|
||||
'potager-commun': { fabrique: (b) => ({ o: potagerCommun(geoP, gens, verre.clone(), b.L, b.W) }), marge: 0.6, rots: [0, 0.3, -0.3, Math.PI / 2], point: (b, w) => ({ x: b.x, z: b.z, w: Math.max(w, b.L * 2.5) }) },
|
||||
'abri-cargos': { fabrique: () => ({ o: abriCargos() }), rots: [0, 0.3, -0.3, Math.PI / 2] },
|
||||
chapiteau: { fabrique: () => ({ o: chapiteau() }), rots: [0], pas: 3, poidsD: 0.04, poseDx: -1.8 },
|
||||
ruches: { fabrique: () => {
|
||||
const o = ruches(4), n = 12, im = new THREE.InstancedMesh(new THREE.IcosahedronGeometry(0.07, 0), lam(COUL.abeille), n), M = new THREE.Matrix4(); o.add(im);
|
||||
// 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), sinon sur
|
||||
// une parcelle libre
|
||||
{
|
||||
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 };
|
||||
}
|
||||
// sinon, une parcelle libre ailleurs, hors pâturages (la forêt et la mare sont déjà exclues par la place libre)
|
||||
if (!best) {
|
||||
const dT = grilleP(D.troupeaux.map((t) => [t[0], t[1]]), 8);
|
||||
best = cherche(0, 0, 200, 8.4, 3.6, 4.5, { rots: [0, Math.PI / 2], pas: 4, poidsD: 0.01, filtre: (x, z) => !(dT(x, z, 20) < 20) });
|
||||
}
|
||||
if (best) {
|
||||
if (best.r) prises.add(best.r.i);
|
||||
return { o, anim: [(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; }] };
|
||||
} },
|
||||
// C1. Syntropie et jardin punk : deux parcelles côte à côte ; les arbres de la syntropie sont posés en coordonnées du plan
|
||||
syntropie: { fabrique: (best) => {
|
||||
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);
|
||||
const [x, z] = c.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 });
|
||||
@@ -930,22 +385,346 @@ export function objetsNouveaux({ D, groupe, T, P, maisons, tr, PAL, geoP, verre,
|
||||
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');
|
||||
return { o: g, extra: [arbresS] };
|
||||
} },
|
||||
// A1. La navette : en boucle sur l'anneau, 5 s à deux arrêts : au carrefour de la liaison et à l'opposé, au bas de la
|
||||
// boucle. Elle ne va pas jusqu'à l'arrêt de bus : la seule route qui y mène depuis l'anneau, `liaison_anneau`, traverse
|
||||
// une maison du plan (la n° 11) ; aucune route n'est inventée (03/11).
|
||||
navette: { fabrique: () => ({ o: navette() }), roule: (t, tr) => {
|
||||
const la = tr.liaison_anneau?.pts, bout = la ? la[la.length - 1] : t.pts[0];
|
||||
const s1 = projete(t, bout[0], bout[1]).s, s2 = (s1 + t.L / 2) % t.L;
|
||||
return { decal: 1.8, arrets: [{ s: s1, p: 5 }, { s: s2, p: 5 }], boucle: true, bouts: false, depart: 0.3 };
|
||||
} },
|
||||
// B2. La Rosalie : lentement, à contresens de la navette (sur sa droite, elle est dans l'autre voie et ne la croise jamais)
|
||||
rosalie: { fabrique: (b, l) => ({ o: rosalie(geoP, gens, fond ? ROSALIE_CADRE_FOND : teinteDe(l, ROSALIE_CADRE)) }), roule: () => ({ decal: 1.4, boucle: true, bouts: false, depart: 0.55 }) },
|
||||
};
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- 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] }.
|
||||
// lot ⑤ : `fond` (le mode fond, aucun matériau cloné de plus, la Rosalie dans son vert) ; rend aussi `maisonsObjets`
|
||||
// ({ effet: [indices de D.maisons] }) : les maisons du plan que portent la colocation, les tiny houses et le jardin commun.
|
||||
// Lot M1 table (14/11) : la pose est une boucle sur `table` (content/objets.md, dans l'ordre des lignes) : pour chaque ligne,
|
||||
// la règle (pose.ts) choisit la place, la fabrique fait l'objet, il est posé, son emprise occupée, il est relié à sa fiche.
|
||||
// Les objets qui changent le plan (règle `propre`) gardent leur branche, plus bas (PROPRES).
|
||||
export function objetsNouveaux({ D, groupe, T, P, maisons, tr, PAL, geoP, verre, matsArbres, tour, convoi, fond = false, aujourdhui = null, lignes = OBJETS }) {
|
||||
const anim = [], maj = [], cliquables = [], points = {}, lumieres = {}, laisses = [], gens = PAL.gens, maisonsObjets = {};
|
||||
PALETTE = PAL;
|
||||
// retouches du 07/11 (retouches.ts) : le minibus, la maison de maître ; jamais en mode fond (le fond reste au pixel)
|
||||
const retouches = !fond || RETOUCHES_EN_FOND, mesureRetouches = {};
|
||||
const c = creerPose({ D, P, T });
|
||||
const { libre, ajoute, loc, emprise, occupe, vu, autour, cherche, place, reps, prises, existantes, coupe, coupeSansHaie } = c;
|
||||
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;
|
||||
}
|
||||
let haieOuverte = null;
|
||||
const posees = {}, PROPRES = {}, TYPES = typesObjets({ geoP, gens, PAL, verre, matsArbres, fond, c });
|
||||
// les objets du Tour (22/10), posés par gestes.js : leurs fiches, leurs cadrages (largeur vue, m), leur allumage
|
||||
PROPRES.geste = (l) => { if (tour && tour.objets[l.id] && tour.points[l.id]) relie(tour.objets[l.id], l.fiche, l.cadrage.nom, { ...tour.points[l.id], w: l.cadrage.w }); };
|
||||
// le convoi, posé par scene.js
|
||||
PROPRES.convoi = (l) => { if (convoi) { relie(convoi.objs, l.fiche, l.cadrage.nom); points[l.cadrage.nom] = convoi.centre; } };
|
||||
PROPRES['minibus'] = (l) => {
|
||||
const arret = posees['arret-bus'] || null, tP = tr.principale;
|
||||
// ---- A2. Le bus scolaire : la route principale, aller et retour ; 6 s à l'arrêt dans les deux sens.
|
||||
// Retouches du 07/11 (T3) : un minibus de quartier, sur sa voie (VOIE_BUS, les vélos ont leur piste, PISTE) ; la principale
|
||||
// va d'un bord de la carte à l'autre (aucune boucle ne passe par l'arrêt) : il entre par un bord, s'arrête à l'arrêt,
|
||||
// sort par l'autre, attend hors champ et revient dans l'autre sens. Hors du socle, il est coupé (plans de coupe) : aucun
|
||||
// demi-tour ne se voit. Le mode fond garde le bus d'avant.
|
||||
const tBus = arret && retouches ? trajetBus(tP.pts, D) : null;
|
||||
if (arret) {
|
||||
let o, centre;
|
||||
if (tBus) {
|
||||
const t = trajet(tBus), sArret = projete(t, arret.x, arret.z).s, v = 6; o = minibus(teinteDe(l, PAL.autos[1])); centre = { x: 0, z: 0 };
|
||||
let tau = sArret / v + 1.5; // au départ, le minibus est à l'arrêt (on le voit en arrivant)
|
||||
const poser = (dt) => {
|
||||
tau += dt; const h = horaireBus(tau, t.L, v, sArret), p = surTrajet(t, h.s);
|
||||
let dx = p.dx * h.sens, dz = p.dz * h.sens; const n = Math.hypot(dx, dz) || 1; dx /= n; dz /= n;
|
||||
o.position.set(p.x - dz * VOIE_BUS, 0, p.z + dx * VOIE_BUS); o.rotation.y = Math.atan2(-dz, dx);
|
||||
o.visible = !h.attente; centre.cache = !!h.attente; centre.x = o.position.x; centre.z = o.position.z;
|
||||
};
|
||||
poser(0); maj.push(poser);
|
||||
Object.assign(mesureRetouches, { bus: { L: MINIBUS.L, l: MINIBUS.l, h: MINIBUS.h, trajet: tBus, sArret, voie: VOIE_BUS, v } });
|
||||
} else {
|
||||
o = bus(teinteDe(l, PAL.autos[1]));
|
||||
const r = roule(o, tP, { v: 6, decal: 1.9, arrets: [{ s: arret.s, p: 6 }], depart: 0.15 }); maj.push(r.maj); centre = r.centre;
|
||||
}
|
||||
groupe.add(o); relie([o, ...arret.objs], 'quartier-bus', 'bus'); points.bus = centre; points.arret = { x: arret.x, z: arret.z, w: arret.w };
|
||||
// les plans de coupe : le minibus n'existe que sur le socle (scene.js allume localClippingEnabled hors mode fond)
|
||||
if (tBus) {
|
||||
const plans = [[1, 0], [-1, 0], [0, 1], [0, -1]].map(([a, b]) => new THREE.Plane(new THREE.Vector3(a, 0, b), a ? D.Wm / 2 : D.Hm / 2));
|
||||
o.traverse((m) => { if (m.material) { m.material.clippingPlanes = plans; m.material.clipShadows = true; } });
|
||||
}
|
||||
} else laisses.push(l.id);
|
||||
|
||||
};
|
||||
PROPRES['jardin-commun'] = (l) => {
|
||||
// ---- 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 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: l.cadrage.w });
|
||||
for (const m of [ma, mb]) if (m) cliquables.push({ o: m, fiche: 'quartier-jardin-commun' });
|
||||
// lot ⑤ (P3) : les deux maisons s'allument et brillent avec le jardin (leurs matériaux leur deviennent propres ; pas en mode fond)
|
||||
if (!fond) {
|
||||
const map = new Map();
|
||||
for (const m of [ma, mb]) if (m) m.traverse((o) => { if (!o.material || Array.isArray(o.material) || !o.material.emissive) return; if (!map.has(o.material)) map.set(o.material, o.material.clone()); o.material = map.get(o.material); });
|
||||
lumieres['jardin-commun'].push(...map.values());
|
||||
}
|
||||
maisonsObjets['jardin-commun'] = [a.i, b.i];
|
||||
} else laisses.push(l.id);
|
||||
}
|
||||
|
||||
};
|
||||
PROPRES['colocation'] = (l) => {
|
||||
// ---- 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;
|
||||
// à 3,5 m du mur, la maison elle-même compte pour 1,5 m (son contour est un obstacle de 2 m) : au-dessus de 1,2, rien
|
||||
// d'autre n'est sur la terrasse ; plus loin (portique, bac à sable, étendoir), 0,3 m de marge suffit
|
||||
for (let al = -W / 2 + 0.5; al <= W / 2 - 0.5 + 1e-6; al += 1.5) for (const [dp, m] of [[3.5, 0.9], [4.5, 0], [5.5, 0], [6.6, 0]]) 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, 0.3 + m) - m);
|
||||
if (pl < 0.3) 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, 6.4));
|
||||
const fil = new THREE.BufferGeometry(); fil.setAttribute('position', new THREE.Float32BufferAttribute([-W * 0.3 - 1.2, 1.7, 6.4, -W * 0.3 + 1.2, 1.7, 6.4], 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, 6.4)));
|
||||
// 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, 5.7],
|
||||
[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: l.cadrage.w });
|
||||
if (maisons[r.i]) cliquables.push({ o: maisons[r.i], fiche: 'quartier-colocation' });
|
||||
maisonsObjets.colocation = [r.i];
|
||||
} else laisses.push(l.id);
|
||||
}
|
||||
|
||||
};
|
||||
PROPRES['tiny-houses'] = (l) => {
|
||||
// ---- 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 } = best; let { choix } = best; prises.add(r.i);
|
||||
// Retouches du 07/11 (T1) : la maison devient une maison de maître (deux fois la médiane, un étage de plus, quatre pans),
|
||||
// son terrain « mange » la maison voisine que ni route, ni chemin, ni sentier n'en sépare (retouches.ts), et les tiny
|
||||
// houses se répartissent de l'une à l'autre. Une tiny house ne se pose pas devant un objet du Tour (elle le cacherait).
|
||||
let fx = r.c.x + r.face.n[0] * (r.face.d + 1), fz = r.c.z + r.face.n[1] * (r.face.d + 1), mangees = [], manoirG = null, proche = choix;
|
||||
if (retouches && maisons[r.i]) {
|
||||
const gab = gabaritManoir(D.maisons), hg = maisons[r.i], rot = hg.rotation.y, n = r.face.n;
|
||||
const face = [n[0] * Math.cos(rot) - n[1] * Math.sin(rot), n[0] * Math.sin(rot) + n[1] * Math.cos(rot)];
|
||||
const trait = hg.children.find((o) => o.isLineSegments)?.material;
|
||||
// aujourd'hui, la maison d'avant et sa voisine restent (checkpoint du 10/11) : une copie dans `aujourdhui`, l'original en 2035
|
||||
const garde = (m) => { if (!aujourdhui || !m) return; aujourdhui.add(m.clone()); groupe.attach(m); };
|
||||
garde(hg); hg.clear(); manoirG = manoir(gab, gab, trait, face); hg.add(manoirG);
|
||||
const dF = (Math.abs(face[0]) > Math.abs(face[1]) ? gab.long : gab.court) / 2; fx = r.c.x + n[0] * (dF + 2.4); fz = r.c.z + n[1] * (dF + 2.4);
|
||||
occupe(r.c.x, r.c.z, r.rot, gab.long / 2 + 1.5, gab.court / 2 + 1.5);
|
||||
mangees = voisinesMangees(D, r.i, { prises, loinDe: [[T.c.x, T.c.y]] });
|
||||
for (const j of mangees) { prises.add(j); if (maisons[j]) { garde(maisons[j]); maisons[j].clear(); } } // la maison mangée n'est plus dessinée
|
||||
// les places : de la maison de maître jusqu'à chaque maison mangée (à 16 m au plus de leur ligne), sans route, chemin ni
|
||||
// sentier entre elles ; vues de la caméra ; pas devant un objet du Tour (à moins de 6 m de côté, 14 m devant)
|
||||
const devant = Object.values(tour?.points || {}).filter(Boolean);
|
||||
const cache = (x, z) => devant.some((q) => Math.abs(x - q.x) < 6 && z - q.z > -2 && z - q.z < 14);
|
||||
const cibles = [r, ...mangees.map((j) => reps[j])], cands = [];
|
||||
for (const [x, z] of autour(r.c.x, r.c.z, 26 + Math.max(0, ...cibles.map((q) => Math.hypot(q.c.x - r.c.x, q.c.z - r.c.z))), 2)) {
|
||||
const pres = Math.min(...cibles.map((q) => Math.hypot(x - q.c.x, z - q.c.z)));
|
||||
const ligne = cibles.slice(1).some((q) => { const ux = q.c.x - r.c.x, uz = q.c.z - r.c.z, l = Math.hypot(ux, uz) || 1, t = ((x - r.c.x) * ux + (z - r.c.z) * uz) / l; return t > 0 && t < l && Math.abs(((x - r.c.x) * uz - (z - r.c.z) * ux) / l) < 16; });
|
||||
if (pres > 24 && !ligne) continue;
|
||||
if (coupeSansHaie([r.c.x, r.c.z], [x, z]) || cache(x, z)) continue;
|
||||
for (const rt of [r.rot, r.rot + Math.PI / 2]) { if (emprise(x, z, rt, 3.2, 1.6, 0.4) < 0.4 || vu(x, z, rt, 3.2, 1.6, 3.6) > 0) continue; cands.push({ x, z, rot: rt, R: Math.hypot(x - r.c.x, z - r.c.z) }); }
|
||||
}
|
||||
// réparties : la moitié près de la maison, le reste en échelons jusqu'à la maison mangée la plus loin
|
||||
const Rmax = Math.max(...cands.map((c) => c.R), 1), nouveaux = [];
|
||||
for (const cible of [0, 0, 0, 0, 0.35, 0.55, 0.75, 0.95]) {
|
||||
const dispo = cands.filter((c) => !nouveaux.some((o) => Math.hypot(o.x - c.x, o.z - c.z) < 7.6));
|
||||
if (!dispo.length) break;
|
||||
nouveaux.push(dispo.reduce((a, c) => (Math.abs(c.R - cible * Rmax) < Math.abs(a.R - cible * Rmax) ? c : a)));
|
||||
}
|
||||
if (nouveaux.length >= 4) choix = nouveaux;
|
||||
proche = choix.filter((c) => Math.hypot(c.x - r.c.x, c.z - r.c.z) < 30);
|
||||
mesureRetouches.manoir = { maison: r.i, ...gab, mangees, tiny: choix.length, x: r.c.x, z: r.c.z };
|
||||
}
|
||||
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 proche ; la table commune au milieu
|
||||
const gravier = lam('#d8cfbd'), objs = [g];
|
||||
for (const c of proche) { 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 = (proche.length ? proche : choix).reduce((a, c, _, L) => [a[0] + c.x / L.length, a[1] + c.z / L.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); }
|
||||
// le cadrage : la maison et toutes ses tiny houses (le terrain agrandi), 60 m au moins
|
||||
let point = { x: (m[0] * 2 + r.c.x) / 3, z: (m[1] * 2 + r.c.z) / 3, w: l.cadrage.w };
|
||||
if (manoirG) { const X = [r.c.x, ...choix.map((c) => c.x)], Z = [r.c.z, ...choix.map((c) => c.z)]; point = { x: (Math.min(...X) + Math.max(...X)) / 2, z: (Math.min(...Z) + Math.max(...Z)) / 2, w: Math.max(l.cadrage.w, (Math.max(...X) - Math.min(...X)) * 1.3 + 16, (Math.max(...Z) - Math.min(...Z)) * 0.9 + 16) };
|
||||
point.x = Math.max(point.x, -D.Wm / 2 + point.w * 0.4); } // au bord ouest : le cadrage reste sur le socle (au téléphone, × 0,8)
|
||||
relie(objs, 'quartier-tiny', 'tiny', point);
|
||||
if (maisons[r.i]) cliquables.push({ o: maisons[r.i], fiche: 'quartier-tiny' });
|
||||
// la maison de maître s'allume et brille avec ses tiny houses (ses matériaux sont à elle)
|
||||
if (manoirG) { const S = new Set(); manoirG.traverse((o) => { if (o.material && o.material.emissive) S.add(o.material); }); lumieres.tiny.push(...S); }
|
||||
maisonsObjets.tiny = [r.i, ...mangees];
|
||||
if (mangees.length) maisonsObjets.mangees = mangees;
|
||||
} else laisses.push(l.id);
|
||||
}
|
||||
|
||||
};
|
||||
PROPRES['fete'] = (l) => {
|
||||
// ---- 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: l.cadrage.w });
|
||||
} else laisses.push(l.id);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// ---- la boucle : une ligne, un objet
|
||||
for (const l of lignes) {
|
||||
if (l.regle === 'propre') { const n0 = cliquables.length; PROPRES[l.type](l); posees[l.id] ??= { objs: cliquables.slice(n0).map((k) => k.o).filter((o) => !maisons.includes(o)) }; continue; }
|
||||
const ty = TYPES[l.type], place_ = REGLES[l.regle](c, l, ty, posees, tr);
|
||||
if (!place_) { laisses.push(l.id); continue; }
|
||||
const f = ty.fabrique(place_, l), objs = [f.o, ...(f.extra || [])];
|
||||
if (ty.roule) { // un objet qui roule : il n'occupe aucune place, son cadrage le suit
|
||||
groupe.add(f.o); const r = roule(f.o, place_.trajet, { v: place_.v, ...ty.roule(place_.trajet, tr) });
|
||||
maj.push(r.maj); if (l.fiche) relie(objs, l.fiche, l.cadrage.nom); points[l.cadrage.nom] ??= r.centre; posees[l.id] = { ...place_, objs, centre: r.centre };
|
||||
continue;
|
||||
}
|
||||
const { x, z, rot } = place_, a = place_.a ?? l.tailles[0][0] / 2, b = place_.b ?? l.tailles[0][1] / 2, dx = ty.decal || 0;
|
||||
pose(f.o, x + (ty.poseDx || 0), z, rot); for (const e of f.extra || []) groupe.add(e);
|
||||
occupe(x + dx * Math.cos(rot), z - dx * Math.sin(rot), rot, a, b);
|
||||
if (f.anim) anim.push(...f.anim);
|
||||
const cad = l.cadrage, w = cad && 'w' in cad ? cad.w : null;
|
||||
posees[l.id] = { ...place_, objs, w };
|
||||
if (cad && 'avec' in cad) { // le cadrage d'une autre ligne s'élargit pour montrer les deux
|
||||
const A = posees[cad.avec], nom = lignes.find((k) => k.id === cad.avec).cadrage.nom, d = Math.hypot(x - A.x, z - A.z);
|
||||
relie(objs, l.fiche, nom, { x: (A.x + x) / 2, z: (A.z + z) / 2, w: Math.min(66, Math.max(A.w, d + 28)) });
|
||||
// un cadrage déjà posé par une ligne au-dessus (une deuxième ruche) reste le sien : la fiche montre le premier objet
|
||||
} else if (l.fiche) relie(objs, l.fiche, cad.nom, cad.w === null || points[cad.nom] ? undefined : ty.point ? ty.point(place_, cad.w) : { x, z, w: cad.w });
|
||||
}
|
||||
|
||||
return { anim, maj, cliquables, points, lumieres, haieOuverte, laisses, maisonsObjets, retouches: mesureRetouches };
|
||||
// lot M1 table (E) : les objets fixes, d'après la table (ni sur-trajet, ni un véhicule) : scene.js fusionne leurs arêtes à l'encre
|
||||
const mobiles = new Set(['minibus', 'convoi']), fixes = [];
|
||||
for (const l of lignes) {
|
||||
if (l.regle === 'sur-trajet' || mobiles.has(l.type)) continue;
|
||||
if (l.type === 'geste') fixes.push(...(tour?.objets[l.id] || []).filter((o) => !o.userData?.corps)); // checkpoint 14/11 : les cochons s'animent (corps, tête) ; un trait fusionné resterait figé : l'enclos seul else fixes.push(...(posees[l.id]?.objs || []));
|
||||
}
|
||||
return { anim, maj, cliquables, points, lumieres, haieOuverte, laisses, maisonsObjets, retouches: mesureRetouches, fixes };
|
||||
}
|
||||
// la teinte d'une ligne (une clé de la palette PAL de scene.js : `autos-5` = PAL.autos[5], `sentier` = PAL.sentier), sinon celle du type
|
||||
function teinteDe(l, defaut) { if (!l.teinte) return defaut; const [k, i] = l.teinte.split(/-(?=\d+$)/); return i === undefined ? PALETTE[k] ?? defaut : PALETTE[k]?.[+i] ?? defaut; }
|
||||
let PALETTE = {}; // la palette de scene.js (PAL), posée à chaque construction
|
||||
// lot ⑤ (P3 ②) : le cadre de la Rosalie en démo, une clé de la palette (PAL.sentier de scene.js, l'ocre des sentiers allumés)
|
||||
export const ROSALIE_CADRE = '#d6a83a';
|
||||
|
||||
// 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]; }
|
||||
|
||||
@@ -0,0 +1,279 @@
|
||||
// La pose des objets du quartier (lot M1 table, 14/11) : les règles nommées de content/objets.md, une fonction chacune,
|
||||
// toutes par la grille d'occupation unique de gestes.js (P) et son test `cache()`. Chaque règle reprend le calcul que la
|
||||
// branche d'objets.js faisait avant le lot (le témoin tests/temoin-objets.json en est le juge) : aucun calcul neuf.
|
||||
// Ici aussi, en un seul exemplaire (dette du lot objets nouveaux, §9) : les trajets (trajet, surTrajet, projete, roule),
|
||||
// la grille de distance (grilleP), les barrières entre jardins, le repère d'une maison. scene.js les importe.
|
||||
// Le module ne pose rien lui-même : il rend une place { x, z, rot, … } ou null ; objets.js fabrique, pose et relie.
|
||||
import * as THREE from 'three';
|
||||
|
||||
type Pt = number[];
|
||||
export interface Trajet { pts: Pt[]; c: number[]; L: number }
|
||||
|
||||
// ---------------------------------------------------------------- les trajets
|
||||
export function trajet(pts: Pt[]): Trajet { const c = [0]; for (let i = 1; i < pts.length; i++) c.push(c[i - 1]! + Math.hypot(pts[i]![0]! - pts[i - 1]![0]!, pts[i]![1]! - pts[i - 1]![1]!)); return { pts, c, L: c[c.length - 1]! }; }
|
||||
export function surTrajet(t: Trajet, s: number) {
|
||||
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)
|
||||
export function projete(t: Trajet, x: number, z: number) {
|
||||
let best = { d: Infinity, s: 0 };
|
||||
for (let i = 1; i < t.pts.length; i++) {
|
||||
const a = t.pts[i - 1]!, b = 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;
|
||||
}
|
||||
// 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.
|
||||
export function roule(obj: THREE.Object3D, t: Trajet, { v, decal, arrets = [], boucle = false, bouts = !boucle, depart = 0 }: { v: number; decal: number; arrets?: { s: number; p: number; bout?: boolean }[]; boucle?: boolean; bouts?: boolean; depart?: number }) {
|
||||
const L = t.L, w = (s: number) => (boucle ? ((s % L) + L) % L : Math.max(0, Math.min(L, s)));
|
||||
let s = depart * L, sens = 1, attente = 0, duree = 1, arret: { s: number; p: number; bout?: boolean } | null = null, parcouru = 99, cap = 0, capA = 0, capB = 0;
|
||||
const centre = { x: 0, z: 0 };
|
||||
const capEn = (s: number, sens: number) => { const p = surTrajet(t, w(s)); return Math.atan2(-p.dz * sens, p.dx * sens); };
|
||||
function maj(dt: number) {
|
||||
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: { s: number; p: number; bout?: boolean } | null = 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 distance à un nuage de points, les barrières, le repère d'une maison
|
||||
export function grilleP(L: Pt[], pas = 6) {
|
||||
const g = new Map<number, Pt[]>(), cle = (i: number, j: number) => (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: number, z: number, r: number) => { 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).
|
||||
export function barrieres(D: any) {
|
||||
const S: [Pt, Pt][] = [];
|
||||
const poly = (p: Pt[]) => { 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) as Pt[][]).forEach(poly); D.chemins.forEach(poly); D.sentiers.forEach(poly);
|
||||
const coupe = ([a, b]: Pt[], [c, d]: Pt[]) => {
|
||||
const r = (p: Pt, q: Pt, s: Pt) => (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: Pt, b: Pt) => { 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.
|
||||
export function repere(h: any) {
|
||||
const p = h.p.map(([x, z]: number[]) => new THREE.Vector2(x, z)), c = p.reduce((a: THREE.Vector2, b: THREE.Vector2) => 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: number, lz: number) => [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: d!, W: 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 };
|
||||
}
|
||||
// l'intersection de deux segments [a, b] et [c, d] : { x, z, u } (u le long de [c, d]) ou null
|
||||
export function inter(a: Pt, b: Pt, c: Pt, d: Pt) {
|
||||
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;
|
||||
}
|
||||
export function grandPos(D: any): Pt { const g = D.maisons.find((m: any) => m.t === 'grand'); return g ? [g.p.reduce((a: number, p: Pt) => a + p[0]! / 4, 0), g.p.reduce((a: number, p: Pt) => a + p[1]! / 4, 0)] : [0, 0]; }
|
||||
|
||||
// ---------------------------------------------------------------- le contexte de pose : la place libre, l'emprise, la vue
|
||||
// P : la grille d'occupation de gestes.js (libre, ajoute, cache, compte). T : la maison témoin.
|
||||
export function creerPose({ D, P, T }: { D: any; P: any; T: any }) {
|
||||
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: any) => a[4] === 1)), dVie = grilleP([...D.persos, ...D.troupeaux.map((t: Pt) => [t[0], t[1]]), ...D.poules.map((p: Pt) => [p[0], p[1]])]);
|
||||
const dChemin = grilleP([...D.chemins, ...D.sentiers].flatMap((l: Pt[]) => { const o: Pt[] = []; 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. La grille
|
||||
// encadre la valeur vraie (P.libre ne varie pas plus vite que la distance) : au-dessus du seuil par le bas, c'est libre ;
|
||||
// sous le seuil par le haut, c'est pris ; entre les deux (1,4 m au plus), on calcule la valeur vraie. Sans ce calcul, la
|
||||
// grille seule coûtait jusqu'à 1,4 m et laissait de côté l'arrêt de bus, la colocation et le potager (03/11).
|
||||
const PAS = 2, memo = new Map<number, number>(), fin = new Map<number, number>(), cle = (i: number, j: number) => (i + 2048) * 4096 + j + 2048;
|
||||
const cellule = (i: number, j: number) => { 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: number, z: number, seuil = -Infinity) => {
|
||||
const i = Math.round(x / PAS), j = Math.round(z / PAS), c = cellule(i, j), d = Math.hypot(x - i * PAS, z - j * PAS);
|
||||
let v = c - d >= seuil ? c - d : c + d < seuil ? c + d : null;
|
||||
if (v === null) { // une seconde grille, de 0,5 m (écart 0,35 m au plus), avant la valeur vraie
|
||||
const fi = Math.round(x * 2), fj = Math.round(z * 2), k = cle(fi, fj); let f = fin.get(k);
|
||||
if (f === undefined) fin.set(k, (f = P.libre(fi / 2, fj / 2)));
|
||||
const e = Math.hypot(x - fi / 2, z - fj / 2); v = f! - e >= seuil ? f! - e : f! + e < seuil ? f! + e : P.libre(x, z);
|
||||
}
|
||||
return Math.min(v!, dVie(x, z, 3) - 1.0, dForet(x, z, 4) - 2.0);
|
||||
};
|
||||
const ajoute = (x: number, z: number, r: number) => { P.ajoute(x, z, r); fin.clear(); 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: number, z: number, rot: number, u: number, v: number) => [x + u * Math.cos(rot) + v * Math.sin(rot), z - u * Math.sin(rot) + v * Math.cos(rot)] as [number, number];
|
||||
function emprise(x: number, z: number, rot: number, a: number, b: number, seuil = -Infinity) {
|
||||
// tri rapide : le disque inscrit (rayon min(a, b)) doit être libre ; la grille en donne un majorant au centre
|
||||
{ const i = Math.round(x / PAS), j = Math.round(z / PAS), hi = cellule(i, j) + Math.hypot(x - i * PAS, z - j * PAS) - Math.min(a, b); if (hi < seuil) return hi; }
|
||||
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, seuil)); if (m < seuil) return m; }
|
||||
return m;
|
||||
}
|
||||
const occupe = (x: number, z: number, rot: number, a: number, b: number) => { 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: number, a: number, b: number) => Math.abs(a * Math.cos(rot)) + Math.abs(b * Math.sin(rot));
|
||||
const vu = (x: number, z: number, rot: number, a: number, b: number, h: number) => P.cache(x, z, h, demiX(rot, a, b));
|
||||
function* autour(cx: number, cz: number, R: number, pas = 2): Generator<[number, number]> { 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: number, cz: number, R: number, a: number, b: number, h: number, { rots = [0], marge = 0.3, poidsVu = 4, poidsD = 0.08, filtre = null as ((x: number, z: number) => boolean) | null, pas = 2 } = {}) {
|
||||
let best: { x: number; z: number; rot: number; score: number } | null = 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;
|
||||
}
|
||||
// les repères du plan : le centre de la place (le milieu des étals), la mare, le lieu commun, les bulles de la planche
|
||||
const place = D.etals.reduce((a: Pt, e: any) => [a[0]! + e.c[0] / D.etals.length, a[1]! + e.c[1] / D.etals.length], [0, 0]) as Pt;
|
||||
const mare = D.canards.c as Pt;
|
||||
const bulle = (id: string) => D.bulles.find((b: any) => b.id === id)?.w as Pt | undefined;
|
||||
const reps = D.maisons.map((h: any, i: number) => ({ ...repere(h), i })), prises = new Set<number>();
|
||||
const existantes = reps.filter((r: any) => 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: any) => q.h.t !== 'existante' && Math.hypot(q.c.x - r.c.x, q.c.z - r.c.z) < 3));
|
||||
return { D, P, T, Wx, Wz, coupe, coupeSansHaie, dForet, dVie, dChemin, libre, ajoute, loc, emprise, occupe, demiX, vu, autour, cherche, place, mare, bulle, reps, prises, existantes };
|
||||
}
|
||||
export type Pose = ReturnType<typeof creerPose>;
|
||||
|
||||
// ---------------------------------------------------------------- les règles nommées
|
||||
// Une règle reçoit le contexte, la ligne de la table (ancre, tailles), le type (ses réglages : rotations, pas, filtre…) et
|
||||
// les objets déjà posés (par id) ; elle rend la place { x, z, rot, … } ou null (l'objet n'est pas posé, `laisses` le dit).
|
||||
type Ligne = { id: string; ancre: { cibles: { cible: string; R: number }[]; route: string | null; rebours: boolean; v: number | null; x: number | null; z: number | null; rot: number | null; lisiere: string[] }; tailles: number[][] };
|
||||
type Place = { x: number; z: number; rot: number; [k: string]: any };
|
||||
// un repère de l'ancre : place, mare, grand, bulle:<nom> (le lieu commun si la bulle manque), ou un objet déjà posé
|
||||
export function repereDe(c: Pose, cible: string, posees: Record<string, Place>): Pt | null {
|
||||
if (cible === 'place') return c.place;
|
||||
if (cible === 'mare') return c.mare;
|
||||
if (cible === 'grand') return grandPos(c.D);
|
||||
if (cible.startsWith('bulle:')) return c.bulle(cible.slice(6)) || grandPos(c.D);
|
||||
const o = posees[cible]; return o ? [o.x, o.z] : null;
|
||||
}
|
||||
const demi = (l: Ligne, k = 0) => { const [L = 0, W = 0, h = 0] = l.tailles[k] || []; return { a: L / 2, b: W / 2, h }; };
|
||||
|
||||
export const REGLES: Record<string, (c: Pose, l: Ligne, ty: any, posees: Record<string, Place>, tr: Record<string, Trajet>) => Place | null> = {
|
||||
// au bord d'une route, à R m au plus du repère, du côté que la caméra voit (A2, l'arrêt de bus)
|
||||
'bord-route'(c, l, ty, posees, tr) {
|
||||
const t = tr[l.ancre.route!], q = repereDe(c, l.ancre.cibles[0]!.cible, posees), R = l.ancre.cibles[0]!.R, { a, b, h } = demi(l), offs: number[] = ty.offs || [6.2, 7.0, 7.8];
|
||||
if (!t || !q) return null;
|
||||
let best: Place | null = null;
|
||||
for (let s = 0; s <= t.L; s += 1) {
|
||||
const p = surTrajet(t, s), n = Math.hypot(p.dx, p.dz) || 1, tx = p.dx / n, tz = p.dz / n;
|
||||
if (Math.hypot(p.x - q[0]!, p.z - q[1]!) > R) continue;
|
||||
for (const cote of [1, -1]) for (const off of offs) {
|
||||
const nx = -tz * cote, nz = tx * cote, x = p.x + nx * off, z = p.z + nz * off, rot = Math.atan2(-nx, -nz);
|
||||
const pl = c.emprise(x, z, rot, a, b, 0.2); if (pl < 0.2) continue;
|
||||
const score = -4 * c.vu(x, z, rot, a, b, h) - 0.08 * Math.hypot(x - q[0]!, z - q[1]!) + 0.3 * Math.min(pl, 2) + (nz > 0 ? 0.5 : 0) - 0.3 * (off - offs[0]!);
|
||||
if (!best || score > best.score) best = { x, z, rot, s, score };
|
||||
}
|
||||
}
|
||||
return best;
|
||||
},
|
||||
// au plus près du premier repère où la place est libre et vue ; `sinon` : le repère suivant (A5, A6, B6, B1, B5)
|
||||
'pres-de'(c, l, ty, posees) {
|
||||
const { a, b, h } = demi(l);
|
||||
for (const [k, { cible, R }] of l.ancre.cibles.entries()) {
|
||||
const q = repereDe(c, cible, posees); if (!q) return null;
|
||||
const o = k > 0 && ty.repli ? ty.repli : ty;
|
||||
const best = c.cherche(q[0]!, q[1]!, R, a, b, h, { rots: o.rots || [0], pas: o.pas || 2, poidsD: o.poidsD ?? 0.08, filtre: ty.filtre ? ty.filtre(c, q) : null });
|
||||
if (best) return best;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
// sous des arbres existants (deux au moins à 11 m), près de l'un des repères, vu ; la meilleure place sur tous (A3)
|
||||
ombre(c, l, ty) {
|
||||
const { a, b, h } = demi(l), dx = ty.decal || 0;
|
||||
let best: Place | null = null;
|
||||
for (const { cible, R } of l.ancre.cibles) {
|
||||
const q = repereDe(c, cible, {}); if (!q) continue;
|
||||
const [cx, cz] = q as [number, number];
|
||||
for (const [x, z] of c.autour(cx, cz, R, 2)) for (const rot of ty.rots || [0]) {
|
||||
const ombre = c.P.compte(x, z, 11); if (ombre < 2) continue;
|
||||
const pl = c.emprise(x + dx * Math.cos(rot), z - dx * Math.sin(rot), rot, a, b, 0.2); if (pl < 0.2) continue;
|
||||
const score = Math.min(ombre, 6) - 5 * c.vu(x, z, rot, a, b, h) - 0.06 * Math.hypot(x - cx, z - cz);
|
||||
if (!best || score > best.score) best = { x, z, rot, score };
|
||||
}
|
||||
}
|
||||
return best;
|
||||
},
|
||||
// la plus grande des tailles qui tient, hors forêt, mare et pâturages (à R m de tout troupeau), vue (A7, le potager)
|
||||
'plus-grande-place'(c, l, ty) {
|
||||
const R = l.ancre.cibles[0]!.R, marge = ty.marge || 0, dTroupeau = grilleP(c.D.troupeaux.map((t: Pt) => [t[0], t[1]]), 8);
|
||||
let best: Place | null = null;
|
||||
for (const [L = 0, W = 0, h = 0] of l.tailles) {
|
||||
const a = L / 2 + marge, b = W / 2 + marge;
|
||||
for (const [x, z] of c.autour(0, 0, 200, 4)) for (const rot of ty.rots || [0]) {
|
||||
if (dTroupeau(x, z, R + a) < R + a) continue;
|
||||
const pl = c.emprise(x, z, rot, a, b, 0.1); if (pl < 0.1) continue;
|
||||
const score = -3 * c.vu(x, z, rot, a, b, h) - 0.01 * Math.hypot(x - c.place[0]!, z - c.place[1]!) + 0.2 * Math.min(pl, 3);
|
||||
if (!best || score > best.score) best = { x, z, rot, score, L, W, a, b };
|
||||
}
|
||||
if (best) break;
|
||||
}
|
||||
return best;
|
||||
},
|
||||
// en lisière (2,5 à 8 m) de la forêt ou des vergers, à 8 m au moins des chemins et sentiers, vu ; ouvert au sud (B3)
|
||||
lisiere(c, l) {
|
||||
const { a, b, h } = demi(l), vergers = grilleP(c.D.vergers, 6), F = l.ancre.lisiere.includes('foret'), V = l.ancre.lisiere.includes('vergers');
|
||||
let best: Place | null = null;
|
||||
for (const [x, z] of c.autour(0, 0, 200, 2)) {
|
||||
const lis = Math.min(F ? c.dForet(x, z, 9) : Infinity, V ? vergers(x, z, 9) : Infinity); if (lis < 2.5 || lis > 8) continue;
|
||||
if (c.dChemin(x, z, 9) < 8) continue;
|
||||
const pl = c.emprise(x, z, 0, a, b, 0.2); if (pl < 0.2) continue;
|
||||
const score = -4 * c.vu(x, z, 0, a, b, h) - 0.3 * lis - 0.005 * Math.hypot(x, z);
|
||||
if (!best || score > best.score) best = { x, z, rot: 0, score };
|
||||
}
|
||||
return best;
|
||||
},
|
||||
// dans le jardin d'une maison existante libre (à 8 m au moins de la maison, sans barrière entre), sinon sur une parcelle
|
||||
// libre hors pâturages (C1) ; la maison choisie est prise
|
||||
'maison-existante'(c, l) {
|
||||
const { a, b, h } = demi(l), R = l.ancre.cibles[0]!.R;
|
||||
let best: Place | null = null;
|
||||
for (const r of c.existantes) {
|
||||
if (c.prises.has(r.i)) continue;
|
||||
const p = c.cherche(r.c.x, r.c.z, R, a, b, h, { rots: [r.rot, r.rot + Math.PI / 2], filtre: (x, z) => Math.hypot(x - r.c.x, z - r.c.z) > 8 && !c.coupe([r.c.x, r.c.z], [x, z]) });
|
||||
if (p && (!best || p.score > best.score)) best = { ...p, r };
|
||||
}
|
||||
if (!best) {
|
||||
const dT = grilleP(c.D.troupeaux.map((t: Pt) => [t[0], t[1]]), 8);
|
||||
best = c.cherche(0, 0, 200, a, b, h, { rots: [0, Math.PI / 2], pas: 4, poidsD: 0.01, filtre: (x, z) => !(dT(x, z, 20) < 20) });
|
||||
}
|
||||
if (best?.r) c.prises.add(best.r.i);
|
||||
return best;
|
||||
},
|
||||
// un objet qui roule : la route (à rebours si dit), la vitesse ; le type dit le décalage, les arrêts, le départ
|
||||
'sur-trajet'(c, l, ty, posees, tr) {
|
||||
const t0 = tr[l.ancre.route!]; if (!t0) return null;
|
||||
const t = l.ancre.rebours ? trajet([...t0.pts].reverse()) : t0;
|
||||
return { x: 0, z: 0, rot: 0, trajet: t, v: l.ancre.v };
|
||||
},
|
||||
// en dernier recours : x z (m) et la rotation, écrits dans la table ; la place n'est pas vérifiée
|
||||
coordonnees(c, l) { return { x: l.ancre.x!, z: l.ancre.z!, rot: l.ancre.rot || 0 }; },
|
||||
};
|
||||
@@ -0,0 +1,41 @@
|
||||
// Le rendu de l'échelle M (LOT Q-m1-trait-gris, 14/11) : « ça marche, c'est efficace, mais pas encore vraiment joli »
|
||||
// (Jules, 31/10). M1 : lumière franche, ombre grise, aplats dans la palette validée (inchangée), un seul régime de trait,
|
||||
// vélos montés, personnages avec une tête. Le retour arrière est un réglage : `?rendu=avant` rend le quartier comme la
|
||||
// prod du 11/11 (`c946484`), et le mode fond reste au pixel (docs/EMBED.md) : il ne lit jamais ce réglage.
|
||||
|
||||
export type Rendu = 'trait' | 'avant';
|
||||
|
||||
/** Le rendu par défaut de la démo. `'avant'` remet tout le lot à zéro (lumières, trait, vélos, têtes). */
|
||||
export const RENDU: Rendu = 'trait';
|
||||
|
||||
/** Le rendu demandé par l'adresse : `?rendu=avant` ou `?rendu=trait` ; le mode fond rend toujours l'avant. */
|
||||
export function lireRendu(recherche: string, fond = false): Rendu {
|
||||
if (fond) return 'avant';
|
||||
const r = new URLSearchParams(recherche).get('rendu');
|
||||
return r === 'avant' || r === 'trait' ? r : RENDU;
|
||||
}
|
||||
|
||||
/**
|
||||
* Les lumières. `avant` : les chiffres de la prod du 11/11 (ciel chaud, sol de l'hémisphérique brun clair, ombre à 0,7).
|
||||
* `trait` (X1, X2) : moins d'hémisphérique, plus de soleil (les deux pans d'un toit se distinguent), et l'hémisphérique
|
||||
* refroidi : ce qui n'est éclairé que par lui (l'ombre portée, les faces à contre-jour) tire vers un gris neutre au lieu
|
||||
* du beige, sans qu'aucune couleur de matériau change. Le soleil ne bouge pas (les ombres tombent au même endroit).
|
||||
* Mesures au RECAP §2.
|
||||
*/
|
||||
export const LUMIERES = {
|
||||
avant: { ciel: 0xfffcf2, sol: 0xd9d2bf, hemi: 2.35, soleil: 0xfff1dc, intensite: 1.05, ombre: 0.7 },
|
||||
trait: { ciel: 0xe4ebf6, sol: 0xc9cbcd, hemi: 1.75, soleil: 0xfff1dc, intensite: 2.1, ombre: 0.62 },
|
||||
} as const;
|
||||
|
||||
/**
|
||||
* Le trait de M (X3) : une encre, une épaisseur (celle de WebGL : 1 px), arêtes vives au-delà de `seuil` degrés,
|
||||
* fusionnées par famille. Les arbres instanciés ont un contour par coque inversée (`coque` : l'agrandissement).
|
||||
* L'encre est celle de la palette (`PAL.trait`), atténuée par `opacite` : on atténue le trait, jamais les faces.
|
||||
*/
|
||||
export const TRAIT_M = {
|
||||
opacite: 0.55, seuil: 20, coque: 1.12, coqueOpacite: 0.5,
|
||||
/** Les lots d'arbres qui ont un contour : aucun (X8, mesuré au banc le 14/11 : + 43 % de triangles avec les seules haies en
|
||||
* coque fine, + 43 % aussi avec haies et arbres existants en coque d'un cran moins fine, + 68 % avec tout ; le brief
|
||||
* retire le trait des arbres au-delà de + 15 %). Le mécanisme reste : ['haies'] le rallume. */
|
||||
contours: [] as ReadonlyArray<'haies' | 'foret' | 'autres'>,
|
||||
} as const;
|
||||
+70
-20
@@ -3,8 +3,8 @@
|
||||
// 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, haiesEssences, vergers, arbresPlan, thuyas, plantesEau, potager, NOMS_AQUA, rnd } from './vegetal.js';
|
||||
import { vieAnimale, velo as veloA, veloCargo, attelage, voiture, chien, remorque } from './animaux.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';
|
||||
@@ -12,6 +12,9 @@ import { PLAFONDS_FOND, prochaineImage, vueScenario, SCENARIO_FOND } from './mod
|
||||
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';
|
||||
import { releverObjets } from './temoin.ts';
|
||||
import { trajet, surTrajet } from './pose.ts'; // lot M1 table : les trajets en un seul exemplaire (pose.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.
|
||||
@@ -34,7 +37,7 @@ const PAL = {
|
||||
// `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 }) {
|
||||
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;
|
||||
@@ -50,12 +53,15 @@ export function creerScene(canvas, { D, ESSENCES, BULLES, IMG, reduit, petit, on
|
||||
const cam = new THREE.OrthographicCamera(-1, 1, 1, -1, 1, 4000);
|
||||
const C = (h) => new THREE.Color(h);
|
||||
|
||||
// lumière douce : ciel chaud, soleil bas du sud-ouest (ombres légères, comme un lavis)
|
||||
scene.add(new THREE.HemisphereLight(0xfffcf2, 0xd9d2bf, 2.35));
|
||||
const soleil = new THREE.DirectionalLight(0xfff1dc, 1.05);
|
||||
// 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 = 0.7;
|
||||
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
|
||||
@@ -89,11 +95,13 @@ export function creerScene(canvas, { D, ESSENCES, BULLES, IMG, reduit, petit, on
|
||||
const anim = [];
|
||||
|
||||
// ---------------------------------------------------------------- maisons
|
||||
const matTrait = new THREE.LineBasicMaterial({ color: PAL.trait, transparent: true, opacity: 0.42 });
|
||||
// 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: new THREE.LineBasicMaterial({ color: '#86ada7' }),
|
||||
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' }),
|
||||
@@ -211,7 +219,7 @@ export function creerScene(canvas, { D, ESSENCES, BULLES, IMG, reduit, petit, on
|
||||
}
|
||||
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(new THREE.CapsuleGeometry(0.28, 0.95, 3, 8), new THREE.MeshLambertMaterial({ color: '#ffffff' }), pers.length);
|
||||
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') });
|
||||
@@ -261,7 +269,7 @@ export function creerScene(canvas, { D, ESSENCES, BULLES, IMG, reduit, petit, on
|
||||
if (imPotager) G.v2035.add(imPotager);
|
||||
|
||||
// ---------------------------------------------------------------- personnages, étals, voitures garées
|
||||
const geoP = new THREE.CapsuleGeometry(0.28, 0.95, 3, 8);
|
||||
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]); });
|
||||
@@ -426,12 +434,6 @@ export function creerScene(canvas, { D, ESSENCES, BULLES, IMG, reduit, petit, on
|
||||
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);
|
||||
@@ -443,8 +445,8 @@ export function creerScene(canvas, { D, ESSENCES, BULLES, IMG, reduit, petit, on
|
||||
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]), tr.principale, 3.2, piste(-2.4), 0.3, G.v2035, 'cargo'); ajoute(veloCargo(PAL.gens[5]), tr.verticale, 3.0, piste(-2.0), 0.75, G.v2035, 'cargo');
|
||||
const attelageM = ajoute(attelage(), tr.principale, 1.6, piste(2.2), 0.55, G.v2035, 'attelage');
|
||||
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.
|
||||
@@ -497,8 +499,11 @@ export function creerScene(canvas, { D, ESSENCES, BULLES, IMG, reduit, petit, on
|
||||
|
||||
// ---------------------------------------------------------------- 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.
|
||||
// lot M1 table (étape A) : sous `?mesure`, le témoin des positions (temoin.ts), relevé avant toute image ; le temps de pose
|
||||
const mesureA = /[?&]mesure\b/.test(location.search), avantObjets = mesureA ? new Set(G.v2035.children) : null, tPose0 = performance.now();
|
||||
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 });
|
||||
const tPose = performance.now() - tPose0, releveObjets = avantObjets ? releverObjets(G.v2035, avantObjets, objets, groupesMaisons, gestes) : null;
|
||||
anim.push(...objets.anim);
|
||||
cliquables.push(...objets.cliquables);
|
||||
if (objets.haieOuverte) {
|
||||
@@ -854,6 +859,51 @@ export function creerScene(canvas, { D, ESSENCES, BULLES, IMG, reduit, petit, on
|
||||
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 ce qui roule n'ont pas de trait.
|
||||
const mesureTrait = { familles: 0, segments: 0, fusionnees: 0, coques: 0, objets: 0 };
|
||||
if (trait) {
|
||||
// lot M1 table (E) : les objets fixes de content/objets.md (objets.js → fixes : ni sur-trajet, ni véhicule) prennent leurs
|
||||
// arêtes vives (seuil de TRAIT_M) à l'encre ; elles rejoignent la fusion ci-dessous (aucun appel de dessin de plus)
|
||||
for (const f of objets.fixes || []) {
|
||||
const ms = []; f.traverse((m) => { if (m.isMesh && !m.isInstancedMesh && m.geometry && !(m.material && m.material.transparent)) ms.push(m); });
|
||||
for (const m of ms) { const e = new THREE.LineSegments(new THREE.EdgesGeometry(m.geometry, TRAIT_M.seuil), encre); e.position.copy(m.position); e.quaternion.copy(m.quaternion); e.scale.copy(m.scale); m.parent.add(e); mesureTrait.objets++; }
|
||||
}
|
||||
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)) {
|
||||
@@ -885,7 +935,7 @@ export function creerScene(canvas, { D, ESSENCES, BULLES, IMG, reduit, petit, on
|
||||
// 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],
|
||||
temoin: temoin ? temoin.mesure : null, effets: () => [...etat.fxs], trait: mesureTrait, objets: releveObjets, tPose,
|
||||
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 {
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
// Le témoin des positions (lot M1 table, étape A) : ce que la pose a posé, relevé juste après objetsNouveaux (scene.js,
|
||||
// sous `?mesure` seulement), avant toute image : pour chaque objet ajouté au groupe de 2035, sa fiche, sa position, sa
|
||||
// rotation, son échelle, sa boîte englobante et sa taille (maillages, sommets) ; les cadrages ; les maisons que portent
|
||||
// les objets (leur boîte, qui change avec la maison de maître). scripts/temoin-objets.mjs l'écrit dans
|
||||
// tests/temoin-objets.json (figé à l'étape A) et compare une scène neuve à ce témoin, à 1 cm et 0,1° près.
|
||||
import * as THREE from 'three';
|
||||
|
||||
type Releve = { id: string; fiche: string | null; p: number[]; r: number[]; s: number[]; boite: number[] | null; maillages: number; sommets: number; visible: boolean };
|
||||
const mm = (v: number) => Math.round(v * 1000) / 1000;
|
||||
const rad = (v: number) => Math.round(v * 1e5) / 1e5;
|
||||
|
||||
function releve(o: THREE.Object3D, id: string, fiche: string | null): Releve {
|
||||
o.updateMatrixWorld(true);
|
||||
const b = new THREE.Box3().setFromObject(o);
|
||||
let maillages = 0, sommets = 0;
|
||||
o.traverse((m: any) => { if (m.geometry) { maillages++; sommets += (m.geometry.attributes?.position?.count || 0) * (m.isInstancedMesh ? m.count : 1); } });
|
||||
return {
|
||||
id, fiche, p: [o.position.x, o.position.y, o.position.z].map(mm), r: [o.rotation.x, o.rotation.y, o.rotation.z].map(rad), s: [o.scale.x, o.scale.y, o.scale.z].map(mm),
|
||||
boite: b.isEmpty() ? null : [b.min.x, b.min.y, b.min.z, b.max.x, b.max.y, b.max.z].map(mm), maillages, sommets, visible: o.visible,
|
||||
};
|
||||
}
|
||||
|
||||
/** Les objets que la pose a ajoutés à `groupe` (absents de `avant`), dans l'ordre d'ajout, nommés par leur fiche. */
|
||||
export function releverObjets(groupe: THREE.Object3D, avant: Set<THREE.Object3D>, objets: any, maisons: THREE.Object3D[], tour: any) {
|
||||
const fiches = new Map<THREE.Object3D, string>();
|
||||
for (const c of objets.cliquables) if (!fiches.has(c.o)) fiches.set(c.o, c.fiche);
|
||||
const n: Record<string, number> = {};
|
||||
const nomme = (f: string | null) => { const k = f || 'sans-fiche'; n[k] = (n[k] || 0) + 1; return `${k}#${n[k]}`; };
|
||||
const poses = groupe.children.filter((o) => !avant.has(o)).map((o) => { const f = fiches.get(o) || null; return releve(o, nomme(f), f); });
|
||||
const touchees = [...new Set(Object.values(objets.maisonsObjets || {}).flat() as number[])].sort((a, b) => a - b);
|
||||
const tourR = Object.entries(tour?.objets || {}).flatMap(([k, L]: [string, any]) => (L || []).map((o: THREE.Object3D, i: number) => releve(o, `tour-${k}#${i + 1}`, fiches.get(o) || null)));
|
||||
const pts = Object.fromEntries(Object.entries(objets.points || {}).sort(([a], [b]) => a.localeCompare(b)).map(([k, v]: [string, any]) => [k, v ? { x: mm(v.x), z: mm(v.z), w: v.w === undefined ? null : mm(v.w) } : null]));
|
||||
return {
|
||||
poses, tour: tourR, points: pts, laisses: [...objets.laisses], haieOuverte: objets.haieOuverte ? { k: objets.haieOuverte.k, s0: mm(objets.haieOuverte.s0), s1: mm(objets.haieOuverte.s1) } : null,
|
||||
maisonsObjets: objets.maisonsObjets, maisons: touchees.map((i) => ({ i, ...(maisons[i] ? releve(maisons[i], `maison-${i}`, null) : {}) })),
|
||||
};
|
||||
}
|
||||
|
||||
type Ecart = string;
|
||||
/** Compare deux relevés : la liste des écarts (vide si la scène est la même), à `cm` m et `deg` degrés près. */
|
||||
export function comparerReleves(a: any, b: any, cm = 0.01, deg = 0.1): Ecart[] {
|
||||
const e: Ecart[] = [], dr = (deg * Math.PI) / 180;
|
||||
const proche = (u: number[] | null, v: number[] | null, tol: number) => (u === null || v === null ? u === v : u.length === v.length && u.every((x, i) => Math.abs(x - v[i]!) <= tol));
|
||||
const un = (x: any, y: any, nom: string) => {
|
||||
if (!y) { e.push(`${nom} : absent après`); return; }
|
||||
if (x.fiche !== y.fiche) e.push(`${nom} : fiche ${x.fiche} → ${y.fiche}`);
|
||||
if (!proche(x.p, y.p, cm)) e.push(`${nom} : position ${x.p} → ${y.p}`);
|
||||
if (!proche(x.r, y.r, dr)) e.push(`${nom} : rotation ${x.r} → ${y.r}`);
|
||||
if (!proche(x.s, y.s, 1e-3)) e.push(`${nom} : échelle ${x.s} → ${y.s}`);
|
||||
if (!proche(x.boite, y.boite, cm)) e.push(`${nom} : boîte ${x.boite} → ${y.boite}`);
|
||||
if (x.maillages !== y.maillages || x.sommets !== y.sommets) e.push(`${nom} : ${x.maillages} maillages / ${x.sommets} sommets → ${y.maillages} / ${y.sommets}`);
|
||||
if (x.visible !== y.visible) e.push(`${nom} : visible ${x.visible} → ${y.visible}`);
|
||||
};
|
||||
for (const cle of ['poses', 'tour', 'maisons'] as const) {
|
||||
const B = new Map((b[cle] || []).map((o: any) => [o.id ?? o.i, o]));
|
||||
for (const o of a[cle] || []) un(o, B.get(o.id ?? o.i), `${cle} ${o.id ?? o.i}`);
|
||||
if ((b[cle] || []).length !== (a[cle] || []).length) e.push(`${cle} : ${(a[cle] || []).length} avant, ${(b[cle] || []).length} après`);
|
||||
}
|
||||
// l'ordre d'ajout des objets communs (une ligne ajoutée en bas de la table ajoute un objet à la fin, sans changer l'ordre)
|
||||
const idsB = new Set((b.poses || []).map((o: any) => o.id)), idsA = new Set((a.poses || []).map((o: any) => o.id));
|
||||
const ordreA = (a.poses || []).map((o: any) => o.id).filter((i: string) => idsB.has(i)).join(','), ordreB = (b.poses || []).map((o: any) => o.id).filter((i: string) => idsA.has(i)).join(',');
|
||||
if (ordreA !== ordreB) e.push('poses : l\'ordre d\'ajout a changé');
|
||||
for (const k of new Set([...Object.keys(a.points || {}), ...Object.keys(b.points || {})])) {
|
||||
const p = a.points[k], q = b.points?.[k];
|
||||
if (!p || !q) { if (p !== q) e.push(`cadrage ${k} : ${JSON.stringify(p)} → ${JSON.stringify(q)}`); continue; }
|
||||
if (Math.abs(p.x - q.x) > cm || Math.abs(p.z - q.z) > cm || (p.w ?? 0) - (q.w ?? 0) > cm || (q.w ?? 0) - (p.w ?? 0) > cm) e.push(`cadrage ${k} : ${JSON.stringify(p)} → ${JSON.stringify(q)}`);
|
||||
}
|
||||
if (JSON.stringify(a.laisses) !== JSON.stringify(b.laisses)) e.push(`laissés : ${a.laisses} → ${b.laisses}`);
|
||||
if (JSON.stringify(a.haieOuverte) !== JSON.stringify(b.haieOuverte)) e.push(`haie ouverte : ${JSON.stringify(a.haieOuverte)} → ${JSON.stringify(b.haieOuverte)}`);
|
||||
if (JSON.stringify(a.maisonsObjets) !== JSON.stringify(b.maisonsObjets)) e.push(`maisons des objets : ${JSON.stringify(a.maisonsObjets)} → ${JSON.stringify(b.maisonsObjets)}`);
|
||||
return e;
|
||||
}
|
||||
@@ -43,6 +43,14 @@ const FORMES = {
|
||||
};
|
||||
const GEO = {};
|
||||
const geoForme = (f) => (GEO[f] ??= FORMES[f].geo());
|
||||
// lot M1 (X3) : la coque du contour d'une couronne, au même bruit mais un cran moins fine (80 faces au lieu de 320 : les
|
||||
// triangles restent sous + 15 %), agrandie de `k` ; null si la géométrie n'est pas une couronne de ce module
|
||||
const COQUES = { 'étalée': [1, 0.13], 'boule': [2, 0.13], 'boule basse': [4, 0.13], 'arrondie': [6, 0.13], 'ovoïde': [8, 0.18] };
|
||||
export function geoCoque(geo, k) {
|
||||
const f = Object.keys(GEO).find((x) => GEO[x] === geo); if (!f) return null;
|
||||
const g = COQUES[f] ? couronne(COQUES[f][0], COQUES[f][1], 1) : geo.clone();
|
||||
return g.scale(k, k, k);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- couleurs
|
||||
export function teinte(ton, tons, i) {
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
// node diff.mjs a.png b.png [a2.png b2.png ...] : pixels différents
|
||||
import { createRequire } from 'node:module'; import { readFileSync } from 'node:fs';
|
||||
const require = createRequire(process.env.PW_CORE || '/home/julesneny8/.npm/_npx/9833c18b2d85bc59/node_modules/');
|
||||
const { chromium } = require('playwright-core');
|
||||
const b = await chromium.launch({ executablePath: process.env.CHROMIUM || '/home/julesneny8/.cache/ms-playwright/chromium-1254/chrome-linux64/chrome' });
|
||||
const p = await b.newPage(); const f = process.argv.slice(2);
|
||||
for (let i = 0; i < f.length; i += 2) {
|
||||
const r = await p.evaluate(async ([a, c]) => {
|
||||
const ld = (s) => new Promise((ok) => { const i = new Image(); i.onload = () => ok(i); i.src = 'data:image/png;base64,' + s; });
|
||||
const [A, B] = await Promise.all([ld(a), ld(c)]); if (A.width !== B.width || A.height !== B.height) return 'tailles différentes';
|
||||
const d = (I) => { const k = document.createElement('canvas'); k.width = I.width; k.height = I.height; const x = k.getContext('2d'); x.drawImage(I, 0, 0); return x.getImageData(0, 0, I.width, I.height).data; };
|
||||
const da = d(A), db = d(B); let n = 0, x0 = 1e9, x1 = -1, y0 = 1e9, y1 = -1; for (let j = 0; j < da.length; j += 4) if (da[j] !== db[j] || da[j + 1] !== db[j + 1] || da[j + 2] !== db[j + 2]) { n++; const q = j / 4, X = q % A.width, Y = (q / A.width) | 0; x0 = Math.min(x0, X); x1 = Math.max(x1, X); y0 = Math.min(y0, Y); y1 = Math.max(y1, Y); }
|
||||
return `${n} px sur ${A.width * A.height}` + (n ? ` boîte ${x0},${y0}-${x1},${y1}` : "");
|
||||
}, [readFileSync(f[i]).toString('base64'), readFileSync(f[i + 1]).toString('base64')]);
|
||||
console.log(f[i].split('/').pop(), '|', f[i + 1].split('/').pop(), ':', r);
|
||||
}
|
||||
await b.close();
|
||||
@@ -0,0 +1,129 @@
|
||||
// Banc de mesure et de captures, lot M1 trait et gris. node bench.mjs <base-url> <label> <outdir> [quoi]
|
||||
// quoi : captures | mesures | fond | fps | tout
|
||||
import { createRequire } from 'node:module';
|
||||
import { readFileSync, writeFileSync, mkdirSync } from 'node:fs';
|
||||
const require = createRequire(process.env.PW_CORE || '/home/julesneny8/.npm/_npx/9833c18b2d85bc59/node_modules/');
|
||||
const { chromium } = require('playwright-core');
|
||||
const [base, label, out, quoi = 'tout'] = process.argv.slice(2);
|
||||
mkdirSync(out, { recursive: true });
|
||||
const EXE = process.env.CHROMIUM || '/home/julesneny8/.cache/ms-playwright/chromium-1254/chrome-linux64/chrome';
|
||||
const D = JSON.parse(readFileSync(new URL('../data/scene2035.json', import.meta.url), 'utf8'));
|
||||
const extra = process.env.EXTRA || ''; // ex. &rendu=avant
|
||||
|
||||
const browser = await chromium.launch({ executablePath: EXE, args: ['--use-angle=swiftshader', '--enable-unsafe-swiftshader', '--ignore-gpu-blocklist'] });
|
||||
const erreurs = [];
|
||||
async function ouvrir(w, h, dpr, q, hash, reduit = true) {
|
||||
const ctx = await browser.newContext({ viewport: { width: w, height: h }, deviceScaleFactor: dpr, reducedMotion: reduit ? 'reduce' : 'no-preference' });
|
||||
const page = await ctx.newPage();
|
||||
if (reduit && !process.env.HORLOGE_LIBRE) await page.addInitScript(() => { const T = 5000; performance.now = () => T; const r = window.requestAnimationFrame.bind(window); window.requestAnimationFrame = (f) => r(() => f(T)); });
|
||||
page.on('console', (m) => { if (m.type() === 'error') erreurs.push(`${w} ${q}${hash}: ${m.text()}`); });
|
||||
page.on('pageerror', (e) => erreurs.push(`${w} ${q}${hash}: ${e.message}`));
|
||||
if (process.env.CANVAS_SEUL) await page.addInitScript(() => addEventListener('DOMContentLoaded', () => { const st = document.createElement('style'); st.textContent = '*{visibility:hidden!important} #scene{visibility:visible!important}'; document.head.append(st); }));
|
||||
await page.goto(`${base}/?${q}${extra}${hash ? '#' + hash : ''}`, { waitUntil: 'networkidle' });
|
||||
await page.waitForTimeout(3500);
|
||||
return { ctx, page };
|
||||
}
|
||||
|
||||
// les deux pans de toit d'une maison (même calcul que maison() de scene.js)
|
||||
function pans(h) {
|
||||
const p = h.p, c = [p.reduce((a, q) => a + q[0], 0) / 4, p.reduce((a, q) => a + q[1], 0) / 4];
|
||||
const e1 = [p[1][0] - p[0][0], p[1][1] - p[0][1]], e2 = [p[2][0] - p[1][0], p[2][1] - p[1][1]];
|
||||
const n = (v) => { const l = Math.hypot(...v); return [v[0] / l, v[1] / l]; }, fw = [Math.cos(h.f), -Math.sin(h.f)];
|
||||
let u, Lv;
|
||||
if (Math.abs(n(e1)[0] * fw[0] + n(e1)[1] * fw[1]) >= Math.abs(n(e2)[0] * fw[0] + n(e2)[1] * fw[1])) { u = n(e1); Lv = Math.hypot(...e2); } else { u = n(e2); Lv = Math.hypot(...e1); }
|
||||
const r = Math.atan2(-u[1], u[0]), eave = 5.4, rh = Math.min(3.4, Lv * 0.31);
|
||||
return [-1, 1].map((s) => { const z = s * Lv / 4; return [c[0] + z * Math.sin(r), eave + rh / 2 + 0.1, c[1] + z * Math.cos(r)]; });
|
||||
}
|
||||
// ombre portée : un point du sol du côté opposé au soleil (soleil de (-110,170,120) : l'ombre part vers +x, -z), et un point éclairé côté soleil
|
||||
function sols(h) {
|
||||
const p = h.p, c = [p.reduce((a, q) => a + q[0], 0) / 4, p.reduce((a, q) => a + q[1], 0) / 4];
|
||||
const R = Math.max(...p.map((q) => Math.hypot(q[0] - c[0], q[1] - c[1])));
|
||||
const d = [0.675, -0.737];
|
||||
return { ombre: [c[0] + d[0] * (R + 1.2), 0.05, c[1] + d[1] * (R + 1.2)], lumiere: [c[0] - d[0] * (R + 4), 0.05, c[1] - d[1] * (R + 4)] };
|
||||
}
|
||||
const lum = ([r, g, b]) => { const f = (v) => { v /= 255; return v <= 0.04045 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4; }; return 0.2126 * f(r) + 0.7152 * f(g) + 0.0722 * f(b); };
|
||||
const sat = ([r, g, b]) => { const M = Math.max(r, g, b) / 255, m = Math.min(r, g, b) / 255, L = (M + m) / 2; return M === m ? 0 : L > 0.5 ? (M - m) / (2 - M - m) : (M - m) / (M + m); };
|
||||
|
||||
async function pixels(page, pts) {
|
||||
// une image rendue maintenant, lue aux points écran (px CSS) donnés
|
||||
return page.evaluate(async (pts) => {
|
||||
const Q = window.__quartier, url = Q.renderer.domElement.toDataURL ? (Q.renderer.render ? null : null) : null;
|
||||
const img = await new Promise((ok) => { const i = new Image(); i.onload = () => ok(i); i.src = window.__apercuPNG(); });
|
||||
const c = document.createElement('canvas'); c.width = img.width; c.height = img.height; const x = c.getContext('2d'); x.drawImage(img, 0, 0);
|
||||
const k = img.width / innerWidth;
|
||||
return pts.map(([X, Y]) => { const d = x.getImageData(Math.round(X * k), Math.round(Y * k), 1, 1).data; return [d[0], d[1], d[2]]; });
|
||||
}, pts);
|
||||
}
|
||||
async function preparer(page) {
|
||||
await page.evaluate(() => {
|
||||
const Q = window.__quartier, r = Q.renderer;
|
||||
window.__apercuPNG = () => { const s = r.domElement; r.info.autoReset = true; window.__scene3.apercu(); return s.toDataURL('image/png'); };
|
||||
});
|
||||
}
|
||||
|
||||
const res = { label, erreurs };
|
||||
if (quoi === 'captures' || quoi === 'tout') {
|
||||
const SH = [['390-M-01-arrivee', 390, 844, 3, ''], ['390-M-02-convoi', 390, 844, 3, 'quartier-convoi'], ['1280-M-01-ensemble', 1280, 800, 1, ''],
|
||||
['1280-M-02-arret-convoi', 1280, 800, 1, 'quartier-convoi'], ['1280-M-03-velos-gros-plan', 1280, 800, 1, 'quartier-cargos'], ['1280-M-04-foret', 1280, 800, 1, 'vivant-foret']];
|
||||
const garder = (process.env.SHOTS || '').split(',').filter(Boolean);
|
||||
for (const [nom, w, h, dpr, hash] of SH) {
|
||||
if (garder.length && !garder.includes(nom)) continue;
|
||||
const { ctx, page } = await ouvrir(w, h, dpr, 'mesure', hash);
|
||||
await page.screenshot({ path: `${out}/${nom}-${label}.png` }); await ctx.close();
|
||||
}
|
||||
}
|
||||
if (quoi === 'mesures' || quoi === 'tout') {
|
||||
const MW = +(process.env.MESURE_W || 2560), { ctx, page } = await ouvrir(MW, Math.round(MW * 0.625), 1, 'mesure', '');
|
||||
// une image : passer par la boucle (besoin) n'est pas garanti sous mouvement réduit ; on rend par renderer avec la scène du canvas
|
||||
const st = await page.evaluate(() => {
|
||||
const r = window.__quartier.renderer; const before = { ...r.info.render };
|
||||
return { calls: before.calls, triangles: before.triangles, lines: before.lines, geometries: r.info.memory.geometries, programs: r.info.programs?.length };
|
||||
});
|
||||
res.info0 = st;
|
||||
// points de mesure
|
||||
const T = D.maisons.map((h, i) => [h, i]).filter(([h]) => h.t === 'transformee');
|
||||
const temoinIdx = T[D.temoin.maison][1];
|
||||
const ordinaires = D.maisons.map((h, i) => [h, i]).filter(([h]) => h.t === 'existante').map(([, i]) => i);
|
||||
const toits = [temoinIdx, ...ordinaires];
|
||||
const pts3 = [];
|
||||
for (const i of toits) { const [a, b] = pans(D.maisons[i]); pts3.push(a, b); }
|
||||
const solsP = ordinaires.map((i) => sols(D.maisons[i]));
|
||||
for (const s of solsP) pts3.push(s.ombre, s.lumiere);
|
||||
const ecr = await page.evaluate((P) => P.map(([x, y, z]) => { const e = window.__quartier.ecran(x, y, z); return [e.x, e.y]; }), pts3);
|
||||
const sh = await page.screenshot();
|
||||
writeFileSync(`${out}/mesure-${MW}-${label}.png`, sh);
|
||||
const px = await page.evaluate(async ({ b64, pts }) => {
|
||||
const img = await new Promise((ok) => { const i = new Image(); i.onload = () => ok(i); i.src = 'data:image/png;base64,' + b64; });
|
||||
const c = document.createElement('canvas'); c.width = img.width; c.height = img.height; const x = c.getContext('2d'); x.drawImage(img, 0, 0);
|
||||
return pts.map(([X, Y]) => { let s = [0, 0, 0]; for (let dx = -1; dx <= 1; dx++) for (let dy = -1; dy <= 1; dy++) { const d = x.getImageData(Math.round(X) + dx, Math.round(Y) + dy, 1, 1).data; s[0] += d[0]; s[1] += d[1]; s[2] += d[2]; } return s.map((v) => Math.round(v / 9)); });
|
||||
}, { b64: sh.toString('base64'), pts: ecr });
|
||||
let k = 0; res.toits = [];
|
||||
for (const i of toits) { const a = px[k++], b = px[k++]; const la = lum(a), lb = lum(b); res.toits.push({ maison: i, temoin: i === temoinIdx, ecran: [ecr[k - 2].map(Math.round), ecr[k - 1].map(Math.round)], rgb: [a, b], contraste: +(Math.max(la, lb) / Math.min(la, lb)).toFixed(3) }); }
|
||||
res.sols = [];
|
||||
for (const i of ordinaires) { const o = px[k++], l = px[k++]; res.sols.push({ maison: i, ecran: [ecr[k - 2].map(Math.round), ecr[k - 1].map(Math.round)], ombre: o, lumiere: l, lo: +lum(o).toFixed(4), ll: +lum(l).toFixed(4), sat: +sat(o).toFixed(3) }); }
|
||||
// poids : octets transférés au premier affichage
|
||||
res.octets = await page.evaluate(() => { const n = performance.getEntriesByType('navigation')[0]; return Math.round((n.transferSize + performance.getEntriesByType('resource').reduce((s, r) => s + (r.transferSize || 0), 0)) / 1024); });
|
||||
res.ressources = await page.evaluate(() => performance.getEntriesByType('resource').length);
|
||||
await ctx.close();
|
||||
}
|
||||
if (quoi === 'fond' || quoi === 'tout') {
|
||||
for (const [w, h, dpr] of [[1280, 800, 1], [390, 844, 3]]) {
|
||||
const { ctx, page } = await ouvrir(w, h, dpr, 'mode=fond', '');
|
||||
await page.screenshot({ path: `${out}/fond-${w}-${label}.png` }); await ctx.close();
|
||||
}
|
||||
}
|
||||
if (quoi === 'fps' || quoi === 'tout') {
|
||||
res.fps = {};
|
||||
for (const cpu of [1, 4]) {
|
||||
const { ctx, page } = await ouvrir(1280, 800, 1, 'mesure', '', false);
|
||||
const cdp = await ctx.newCDPSession(page); await cdp.send('Emulation.setCPUThrottlingRate', { rate: cpu });
|
||||
await page.waitForTimeout(1500);
|
||||
res.fps[`x${cpu}`] = await page.evaluate(() => new Promise((ok) => { let n = 0; const t0 = performance.now(); const f = () => { n++; if (performance.now() - t0 < 6000) requestAnimationFrame(f); else ok(+(n / ((performance.now() - t0) / 1000)).toFixed(1)); }; requestAnimationFrame(f); }));
|
||||
// appels de dessin et triangles d'une image de la boucle
|
||||
res.fps[`info${cpu}`] = await page.evaluate(() => { const i = window.__quartier.renderer.info.render; return { calls: i.calls, triangles: i.triangles, lines: i.lines }; });
|
||||
await ctx.close();
|
||||
}
|
||||
}
|
||||
await browser.close();
|
||||
writeFileSync(`${out}/mesures-${label}${quoi === 'tout' ? '' : '-' + quoi}.json`, JSON.stringify(res, null, 1));
|
||||
console.log(JSON.stringify({ label, info0: res.info0, fps: res.fps, octets: res.octets, erreurs: erreurs.length }, null, 0));
|
||||
@@ -614,3 +614,81 @@ export function lireTextesXl(md: string, fichier = 'content/xl-textes.md'): Text
|
||||
}
|
||||
return out as TextesXL;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- les objets du quartier (lot M1 table, 14/11) : un objet = une ligne
|
||||
// content/objets.md, ## Objets : | id | famille | type | regle | ancre | taille | teinte | fiche | cadrage | epoque | plaque |
|
||||
// Lu au build (vite.config.ts → `virtual:contenu`, OBJETS) et posé par maquette/objets.js dans l'ordre des lignes, chaque
|
||||
// règle par maquette/pose.ts. Une faute (type, règle, fiche, teinte, ancre) arrête le build avec la ligne.
|
||||
/** Les types d'objets (les fabriques de maquette/objets.js ; `geste` : un objet du Tour, posé par gestes.js). */
|
||||
export const TYPES_OBJETS = ['geste', 'convoi', 'abri-bus', 'point-fraicheur', 'navette', 'minibus', 'atelier', 'jardin-commun', 'colocation', 'conserverie',
|
||||
'alambic', 'potager-commun', 'tiny-houses', 'abri-cargos', 'rosalie', 'ruches', 'fete', 'chapiteau', 'syntropie'] as const;
|
||||
/** Les règles de pose (maquette/pose.ts) ; `propre` : la pose reste écrite à la main (l'objet change le plan). */
|
||||
export const REGLES_OBJETS = ['bord-route', 'pres-de', 'ombre', 'plus-grande-place', 'lisiere', 'maison-existante', 'sur-trajet', 'coordonnees', 'propre'] as const;
|
||||
/** Les teintes : les clés de la palette de la maquette (PAL de maquette/scene.js ; `autos-5` = PAL.autos[5]). */
|
||||
export const TEINTES_OBJETS = ['fond', 'papier', 'socle', 'mur', 'toit', 'paille', 'toitT', 'grandMur', 'grandToit', 'trait', 'tronc', 'thuya', 'eau', 'eauVive', 'sentier',
|
||||
...[0, 1, 2, 3, 4, 5, 6, 7].map((i) => `gens-${i}`), ...[0, 1, 2, 3, 4, 5].map((i) => `autos-${i}`), ...[0, 1, 2, 3, 4].map((i) => `etals-${i}`)];
|
||||
export const EPOQUES_OBJETS = ['2035', 'auj', 'les deux'] as const;
|
||||
export const REPERES_OBJETS = ['place', 'mare', 'grand'] as const;
|
||||
export interface Cible { cible: string; R: number }
|
||||
export interface LigneObjet {
|
||||
id: string; famille: string; type: (typeof TYPES_OBJETS)[number]; regle: (typeof REGLES_OBJETS)[number];
|
||||
ancre: { texte: string; cibles: Cible[]; route: string | null; rebours: boolean; v: number | null; x: number | null; z: number | null; rot: number | null; lisiere: string[] };
|
||||
tailles: [number, number, number][]; teinte: string | null; fiche: string | null;
|
||||
cadrage: { nom: string; w: number | null } | { avec: string } | null; epoque: (typeof EPOQUES_OBJETS)[number]; plaque: string; ligne: number;
|
||||
}
|
||||
export function lireObjets(md: string, chapitres: Chapitre[], fichier = 'content/objets.md'): LigneObjet[] {
|
||||
const sec = sections(md).get('objets') ?? erreur(fichier, 0, 'section « ## Objets » introuvable');
|
||||
const fiches = new Map(chapitres.flatMap((c) => c.fiches).map((f) => [f.id, f]));
|
||||
const vide = (s: string) => !s || s === '—' || s === '-';
|
||||
const num = (s: string, n: number, quoi: string) => { const v = nombre(s); if (!Number.isFinite(v)) erreur(fichier, n, `${quoi} « ${s} » : un nombre est attendu`); return v; };
|
||||
const lignes: LigneObjet[] = [];
|
||||
for (const { c, n } of tableau(sec)) {
|
||||
const [id = '', famille = '', type = '', regle = '', ancre = '', taille = '', teinte = '', fiche = '', cadrage = '', epoque = '', plaque = ''] = c;
|
||||
if (!/^[a-z0-9][a-z0-9-]*$/.test(id)) erreur(fichier, n, `id « ${id} » : des minuscules, des chiffres et des tirets, sans espace`);
|
||||
if (lignes.some((l) => l.id === id)) erreur(fichier, n, `l'id « ${id} » est déjà pris ligne ${lignes.find((l) => l.id === id)!.ligne}`);
|
||||
if (!(TYPES_OBJETS as readonly string[]).includes(type)) erreur(fichier, n, `type « ${type} » inconnu (${TYPES_OBJETS.join(', ')}) : un type nouveau demande une fabrique dans maquette/objets.js`);
|
||||
if (!(REGLES_OBJETS as readonly string[]).includes(regle)) erreur(fichier, n, `règle « ${regle} » inconnue (${REGLES_OBJETS.join(', ')})`);
|
||||
if (!(EPOQUES_OBJETS as readonly string[]).includes(epoque)) erreur(fichier, n, `époque « ${epoque} » : 2035, auj ou les deux`);
|
||||
if (!vide(teinte) && !TEINTES_OBJETS.includes(teinte)) erreur(fichier, n, `teinte « ${teinte} » hors palette (${TEINTES_OBJETS.join(', ')}) ; jamais un code couleur`);
|
||||
if (!vide(fiche) && !fiches.has(fiche)) erreur(fichier, n, `fiche « ${fiche} » absente de content/fiches.md`);
|
||||
// l'ancre, lue selon la règle
|
||||
const A: LigneObjet['ancre'] = { texte: ancre, cibles: [], route: null, rebours: false, v: null, x: null, z: null, rot: null, lisiere: [] };
|
||||
const cible = (s: string) => {
|
||||
const m = /^(\S+)\s+([\d,.]+)$/.exec(s.trim()) ?? erreur(fichier, n, `ancre « ${s} » : un repère et une distance en mètres (« place 25 »)`);
|
||||
const [, k = '', R = ''] = m;
|
||||
if (!(REPERES_OBJETS as readonly string[]).includes(k) && !/^bulle:[a-z-]+$/.test(k) && !lignes.some((l) => l.id === k)) erreur(fichier, n, `repère « ${k} » inconnu : place, mare, grand, bulle:<nom>, ou l'id d'une ligne au-dessus`);
|
||||
return { cible: k, R: num(R, n, 'distance') };
|
||||
};
|
||||
const clauses = ancre.split(/,\s*(?:sinon\s+)?/).map((s) => s.trim()).filter(Boolean);
|
||||
if (regle === 'pres-de' || regle === 'ombre') A.cibles = clauses.map(cible);
|
||||
else if (regle === 'bord-route') { A.route = clauses[0] ?? ''; A.cibles = clauses.slice(1).map(cible); if (!A.route || !A.cibles.length) erreur(fichier, n, 'bord-route : « <route>, <repère> <m> »'); }
|
||||
else if (regle === 'sur-trajet') { const m = /^([a-z_]+)(\s+à rebours)?\s+([\d,.]+)$/.exec(ancre.trim()) ?? erreur(fichier, n, `sur-trajet : « <route> [à rebours] <m/s> », pas « ${ancre} »`); A.route = m[1]!; A.rebours = !!m[2]; A.v = num(m[3]!, n, 'vitesse'); }
|
||||
else if (regle === 'plus-grande-place') { const m = /^troupeaux\s+([\d,.]+)$/.exec(ancre.trim()) ?? erreur(fichier, n, 'plus-grande-place : « troupeaux <m> » (la distance aux pâturages)'); A.cibles = [{ cible: 'troupeaux', R: num(m[1]!, n, 'distance') }]; }
|
||||
else if (regle === 'lisiere') { A.lisiere = ancre.split(/\s+ou\s+/).map((s) => sansAccent(s)); if (!A.lisiere.length || A.lisiere.some((s) => s !== 'foret' && s !== 'vergers')) erreur(fichier, n, 'lisiere : « forêt », « vergers » ou « forêt ou vergers »'); }
|
||||
else if (regle === 'maison-existante') { const m = /^jardin\s+([\d,.]+)$/.exec(ancre.trim()) ?? erreur(fichier, n, 'maison-existante : « jardin <m> »'); A.cibles = [{ cible: 'jardin', R: num(m[1]!, n, 'distance') }]; }
|
||||
else if (regle === 'coordonnees') { const [x = '', z = '', r = '0'] = ancre.trim().split(/\s+/); A.x = num(x, n, 'x'); A.z = num(z, n, 'z'); A.rot = (num(r.replace('°', ''), n, 'rotation') * Math.PI) / 180; }
|
||||
// la taille : L × l × h (m), et des replis pour plus-grande-place
|
||||
const tailles = vide(taille) ? [] : taille.split(/,\s*sinon\s+/).map((t) => {
|
||||
const v = t.split('×').map((s) => num(s, n, 'taille'));
|
||||
if (v.length !== 3 || v.some((x) => !(x > 0))) erreur(fichier, n, `taille « ${t} » : longueur × largeur × hauteur, en mètres`);
|
||||
return v as [number, number, number];
|
||||
});
|
||||
if (!['propre', 'sur-trajet'].includes(regle) && !tailles.length) erreur(fichier, n, `la règle ${regle} demande une taille (l'emprise à trouver libre)`);
|
||||
// le cadrage : « nom largeur », « nom » (suit l'objet), « avec <id> », ou rien
|
||||
let cad: LigneObjet['cadrage'] = null;
|
||||
if (!vide(cadrage)) {
|
||||
const av = /^avec\s+(\S+)$/.exec(cadrage);
|
||||
if (av) { if (!lignes.some((l) => l.id === av[1])) erreur(fichier, n, `cadrage « ${cadrage} » : « avec » nomme une ligne au-dessus`); cad = { avec: av[1]! }; }
|
||||
else {
|
||||
const m = /^([a-z-]+)(?:\s+([\d,.]+))?$/.exec(cadrage) ?? erreur(fichier, n, `cadrage « ${cadrage} » : « nom largeur » (m), « nom », ou « avec <id> »`);
|
||||
cad = { nom: m[1]!, w: m[2] ? num(m[2], n, 'largeur') : null };
|
||||
const f = vide(fiche) ? null : fiches.get(fiche)!;
|
||||
if (f && f.cadrage !== m[1]) erreur(fichier, n, `cadrage « ${m[1]} » : la fiche ${fiche} a le cadrage « ${f.cadrage} »`);
|
||||
}
|
||||
}
|
||||
lignes.push({ id, famille, type: type as LigneObjet['type'], regle: regle as LigneObjet['regle'], ancre: A, tailles, teinte: vide(teinte) ? null : teinte, fiche: vide(fiche) ? null : fiche,
|
||||
cadrage: cad, epoque: epoque as LigneObjet['epoque'], plaque: plaque || 'centre', ligne: n });
|
||||
}
|
||||
if (!lignes.length) erreur(fichier, 0, 'le tableau des objets est vide');
|
||||
return lignes;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
// Le témoin des positions (lot M1 table, étape A). La scène se construit dans Chromium (elle demande WebGL : aucune
|
||||
// construction sans navigateur n'est fidèle), sous `?mesure` ; maquette/temoin.ts relève, juste après la pose et avant
|
||||
// toute image, chaque objet posé (fiche, position, rotation, échelle, boîte, maillages, sommets), les cadrages, les
|
||||
// maisons que portent les objets. En démo (`?mesure`) et en mode fond (`?mode=fond&mesure`).
|
||||
//
|
||||
// node scripts/temoin-objets.mjs build, preview, compare à tests/temoin-objets.json (code 1 si un écart)
|
||||
// node scripts/temoin-objets.mjs --ecrire écrit le témoin (une seule fois : il est figé au commit de l'étape A)
|
||||
// options : --sans-build (dist/ déjà construit) · --base http://127.0.0.1:PORT (un serveur déjà lancé) · --sortie f.json
|
||||
import { createRequire } from 'node:module';
|
||||
import { readFileSync, writeFileSync } from 'node:fs';
|
||||
import { spawn, execSync } from 'node:child_process';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { comparerReleves } from '../maquette/temoin.ts';
|
||||
|
||||
const require = createRequire(process.env.PW_CORE || '/home/julesneny8/.npm/_npx/9833c18b2d85bc59/node_modules/');
|
||||
const { chromium } = require('playwright-core');
|
||||
const EXE = process.env.CHROMIUM || '/home/julesneny8/.cache/ms-playwright/chromium-1254/chrome-linux64/chrome';
|
||||
const args = process.argv.slice(2), opt = (k) => { const i = args.indexOf(k); return i < 0 ? null : args[i + 1]; };
|
||||
const racine = fileURLToPath(new URL('..', import.meta.url)), TEMOIN = `${racine}tests/temoin-objets.json`;
|
||||
|
||||
let base = opt('--base'), serveur = null;
|
||||
if (!base) {
|
||||
if (!args.includes('--sans-build')) execSync('npx vite build', { cwd: racine, stdio: 'ignore' });
|
||||
const port = 4300 + Math.floor(Math.random() * 500);
|
||||
serveur = spawn('npx', ['vite', 'preview', '--host', '127.0.0.1', '--port', String(port), '--strictPort'], { cwd: racine, stdio: 'ignore', detached: true });
|
||||
base = `http://127.0.0.1:${port}`;
|
||||
for (let i = 0; i < 60; i++) { try { await fetch(base); break; } catch { await new Promise((ok) => setTimeout(ok, 250)); } }
|
||||
}
|
||||
const fin = () => { if (serveur) try { process.kill(-serveur.pid); } catch { /* déjà arrêté */ } };
|
||||
|
||||
const browser = await chromium.launch({ executablePath: EXE, args: ['--use-angle=swiftshader', '--enable-unsafe-swiftshader', '--ignore-gpu-blocklist'] });
|
||||
const erreurs = [], scene = {};
|
||||
try {
|
||||
for (const [nom, q] of [['demo', 'mesure'], ['fond', 'mode=fond&mesure']]) {
|
||||
const ctx = await browser.newContext({ viewport: { width: 1280, height: 800 }, deviceScaleFactor: 1, reducedMotion: 'reduce' });
|
||||
const page = await ctx.newPage();
|
||||
page.on('console', (m) => { if (m.type() === 'error') erreurs.push(`${nom}: ${m.text()}`); });
|
||||
page.on('pageerror', (e) => erreurs.push(`${nom}: ${e.message}`));
|
||||
await page.goto(`${base}/?${q}`, { waitUntil: 'networkidle' });
|
||||
try { await page.waitForFunction(() => window.__quartier && window.__quartier.objets, null, { timeout: 60000 }); }
|
||||
catch (e) { console.log(`${nom} : la scène ne s'est pas construite\n ${erreurs.join('\n ')}`); throw e; }
|
||||
scene[nom] = await page.evaluate(() => ({ ...window.__quartier.objets, tPose: Math.round(window.__quartier.tPose) }));
|
||||
await ctx.close();
|
||||
}
|
||||
} finally { await browser.close(); fin(); }
|
||||
|
||||
const resume = (s) => `${s.poses.length} objets posés, ${s.tour.length} objets du Tour, ${Object.keys(s.points).length} cadrages, laissés [${s.laisses}], pose ${s.tPose} ms`;
|
||||
for (const k of Object.keys(scene)) console.log(`${k} : ${resume(scene[k])}`);
|
||||
if (erreurs.length) console.log(`erreurs console : ${erreurs.length}\n ${erreurs.join('\n ')}`);
|
||||
const sortie = opt('--sortie');
|
||||
if (sortie) writeFileSync(sortie, JSON.stringify(scene, null, 1));
|
||||
if (args.includes('--ecrire')) {
|
||||
const sans = (s) => { const { tPose, ...r } = s; return r; };
|
||||
writeFileSync(TEMOIN, JSON.stringify({ demo: sans(scene.demo), fond: sans(scene.fond) }, null, 1) + '\n');
|
||||
console.log(`témoin écrit : ${TEMOIN}`);
|
||||
} else {
|
||||
const T = JSON.parse(readFileSync(TEMOIN, 'utf8'));
|
||||
let n = 0;
|
||||
for (const k of ['demo', 'fond']) { const e = comparerReleves(T[k], scene[k]); n += e.length; console.log(`${k} : ${e.length ? `${e.length} écart(s)\n ${e.slice(0, 40).join('\n ')}` : 'identique au témoin (1 cm, 0,1°)'}`); }
|
||||
process.exitCode = n || erreurs.length ? 1 : 0;
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
// Le quartier au trait (LOT Q-m1-trait-gris, 14/11) : lumière franche, ombre grise, aplats dans la palette validée,
|
||||
// un seul régime de trait, vélos montés, personnages avec une tête ; `?rendu=avant` et `?mode=fond` rendent l'avant.
|
||||
// Les mesures au pixel (0 px de différence, contraste des toits, saturation de l'ombre) sont au RECAP, faites par
|
||||
// scripts/banc-m1-trait.mjs ; ici, ce qui se vérifie sans navigateur.
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { lireRendu, RENDU, LUMIERES, TRAIT_M } from '../maquette/rendu.ts';
|
||||
|
||||
const lire = (p: string) => readFileSync(new URL(`../${p}`, import.meta.url), 'utf8');
|
||||
const hex = (s: string) => [...new Set(s.match(/#[0-9a-fA-F]{6}\b/g) || [])].sort().join(' ');
|
||||
|
||||
test('le rendu : trait par défaut, avant sur demande, toujours avant en mode fond', () => {
|
||||
assert.equal(RENDU, 'trait');
|
||||
assert.equal(lireRendu(''), 'trait');
|
||||
assert.equal(lireRendu('?rendu=avant'), 'avant');
|
||||
assert.equal(lireRendu('?rendu=trait'), 'trait');
|
||||
assert.equal(lireRendu('?rendu=n-importe'), RENDU);
|
||||
assert.equal(lireRendu('', true), 'avant');
|
||||
assert.equal(lireRendu('?mode=fond&rendu=trait', true), 'avant');
|
||||
});
|
||||
|
||||
test('`?rendu=avant` et `?mode=fond` rendent les lumières de la prod du 11/11 (c946484)', () => {
|
||||
assert.deepEqual({ ...LUMIERES.avant }, { ciel: 0xfffcf2, sol: 0xd9d2bf, hemi: 2.35, soleil: 0xfff1dc, intensite: 1.05, ombre: 0.7 });
|
||||
const scene = lire('maquette/scene.js'), main = lire('maquette/main.js');
|
||||
// une seule source pour les lumières, choisie par le rendu ; le mode fond ne passe jamais `rendu` (défaut : avant)
|
||||
assert.match(scene, /rendu = 'avant' \}\) \{/);
|
||||
assert.match(scene, /const trait = rendu === 'trait' && !fond, LUM = LUMIERES\[trait \? 'trait' : 'avant'\]/);
|
||||
assert.equal((scene.match(/new THREE\.HemisphereLight\(/g) || []).length, 1);
|
||||
assert.match(scene, /new THREE\.HemisphereLight\(LUM\.ciel, LUM\.sol, LUM\.hemi\)/);
|
||||
assert.match(scene, /shadow\.intensity = LUM\.ombre/);
|
||||
assert.match(main, /rendu: lireRendu\(location\.search, FOND\)/);
|
||||
const fond = main.slice(main.indexOf('function fond()'), main.indexOf('function fond()') + 800);
|
||||
assert.doesNotMatch(fond, /rendu/);
|
||||
});
|
||||
|
||||
test('lumière franche : plus de soleil que d\'hémisphérique, le soleil au même endroit, une ombre plus lisible', () => {
|
||||
const t = LUMIERES.trait, a = LUMIERES.avant;
|
||||
assert.ok(t.intensite / t.hemi > 2 * (a.intensite / a.hemi));
|
||||
assert.equal(t.soleil, a.soleil);
|
||||
assert.ok(t.ombre > 0 && t.ombre <= 1);
|
||||
// l'ombre grise : le ciel refroidi (le bleu au moins égal au rouge), le sol de l'hémisphérique presque neutre
|
||||
const rgb = (c: number) => [(c >> 16) & 255, (c >> 8) & 255, c & 255];
|
||||
const [r = 0, , b = 0] = rgb(t.ciel); assert.ok(b >= r);
|
||||
const s = rgb(t.sol); assert.ok(Math.max(...s) - Math.min(...s) <= 8);
|
||||
});
|
||||
|
||||
test('les couleurs de la palette ne changent pas (0 hex modifié contre c946484)', () => {
|
||||
assert.equal(hex(lire('maquette/scene.js')), '#000000 #1d5886 #2f7fa8 #3e9aa3 #3f8fb0 #3f8fc7 #5d9fc7 #5f7f96 #62560f #6a6e70 #6d7f99 #6f8659 #6f8fa8 #7a7066 #7b6a55 #7d6a5c #7fa3a6 #7fb3cf #85adc0 #86ada7 #8a9a72 #8a9a8c #8aa36a #8f7a62 #8f7aa6 #9aa1a6 #9aa3a6 #9db878 #9fb57a #a39a8c #a7768e #a8675a #b9a68e #b9b2a6 #c47f5a #c49a64 #c79528 #c98466 #c99a7f #c9bba8 #cbbfa6 #d3b45c #d4ebe6 #d6a83a #d8cfbd #d8d2c4 #d9a35b #d9a866 #d9d3bc #e0b23a #e0c27a #e6cf8a #e7e5d3 #efeee2 #f1ebdc #f4f0e4 #ffffff');
|
||||
assert.equal(hex(lire('maquette/animaux.js')), '#000000 #3e3c37 #4a3628 #4f463e #4f7a5a #5a5650 #5c4c3c #6f8fa8 #7fa3a6 #8a5f3c #9a7350 #a9be7c #b49a78 #b68f5f #b9786a #c0443a #c8553d #c98a52 #c9a46a #d8a090 #e0a33a #e6c96a #e6cf8a #e9e3d2 #f1ebdf #f2efe6 #f3eee2');
|
||||
assert.equal(hex(lire('maquette/vegetal.js')), '#000000 #6f8f55 #7d965a #7fa77a #86a060 #87a35d #8aa35f #8aa665 #8ea366 #94ad62 #9db36a #a9a670 #a9bd6c #b0608a #b39b6b #b8714f #c9b05a #cf9c52 #e2c24a #e6c84f #efe7c8 #ffffff');
|
||||
assert.ok(TRAIT_M.opacite > 0 && TRAIT_M.opacite <= 1);
|
||||
});
|
||||
|
||||
// la géométrie : le cycliste posé sur la selle (à 1 cm près), le personnage avec une tête
|
||||
import * as THREE from 'three';
|
||||
// animaux.js n'a pas de types : on l'importe par son adresse, et on dit ce qu'on en lit
|
||||
const A = (await import(new URL('../maquette/animaux.js', import.meta.url).href)) as {
|
||||
velo: (c: string) => THREE.Group; veloCargo: (c: string, monte?: boolean) => THREE.Group; quille: (tete?: boolean) => THREE.BufferGeometry;
|
||||
attelage: (tete?: boolean) => THREE.Group; SELLE_CARGO: { x: number; y: number };
|
||||
};
|
||||
const { velo, veloCargo, quille, attelage, SELLE_CARGO } = A;
|
||||
|
||||
// le point le plus bas du cycliste au-dessus de la selle (|x - xs| < 0,12 m), moins le dessus de la selle
|
||||
function ecartSelle(g: THREE.Group, xs: number, dessusSelle: number) {
|
||||
const c = g.children[g.children.length - 1] as THREE.Mesh, p = c.geometry.attributes.position!, v = new THREE.Vector3();
|
||||
let bas = Infinity;
|
||||
for (let i = 0; i < p.count; i++) { v.fromBufferAttribute(p, i).applyMatrix4(c.matrix); if (Math.abs(v.x - xs) < 0.12 && Math.abs(v.z) < 0.15) bas = Math.min(bas, v.y); }
|
||||
return bas - dessusSelle;
|
||||
}
|
||||
const dessus = (g: THREE.Group, xs: number) => { // le dessus du cadre ou de la selle, au droit de la selle
|
||||
let h = -Infinity; const v = new THREE.Vector3();
|
||||
for (const o of g.children.slice(0, 1)) { const m = o as THREE.Mesh, p = m.geometry.attributes.position!; m.updateMatrix(); for (let i = 0; i < p.count; i++) { v.fromBufferAttribute(p, i).applyMatrix4(m.matrix); if (Math.abs(v.x - xs) < 0.15) h = Math.max(h, v.y); }
|
||||
if (h === -Infinity) { m.geometry.computeBoundingBox(); h = m.geometry.boundingBox!.clone().applyMatrix4(m.matrix).max.y; } } // une poutre : ses sommets sont aux bouts
|
||||
return h;
|
||||
};
|
||||
|
||||
test('les vélos montés : le cycliste est assis sur la selle, à 1 cm près (vélo et vélo-cargo)', () => {
|
||||
for (const [g, xs] of [[velo('#c47f5a'), -0.34], [veloCargo('#c47f5a', true), SELLE_CARGO.x]] as const) {
|
||||
g.children.forEach((o: THREE.Object3D) => o.updateMatrix());
|
||||
const e = ecartSelle(g, xs, dessus(g, xs));
|
||||
assert.ok(e <= 0.01 && e >= -0.06, `écart selle-cycliste ${e.toFixed(3)} m`);
|
||||
}
|
||||
// l'ancien cargo flottait (gardé pour ?rendu=avant), et le cargo garé reste à quatre enfants
|
||||
const ancien = veloCargo('#c47f5a'); ancien.children.forEach((o: THREE.Object3D) => o.updateMatrix());
|
||||
assert.ok(ecartSelle(ancien, -0.55, dessus(ancien, -0.55)) > 0.1);
|
||||
for (const m of [true, false]) { const g = veloCargo('#c47f5a', m); assert.equal(g.children.length, 7); g.children.splice(4, 3); assert.equal(g.children.length, 4); }
|
||||
});
|
||||
|
||||
test('chaque personnage a une tête : même hauteur, même pied ; la scène n\'a plus de quille sans tête au trait', () => {
|
||||
const haut = (g: THREE.BufferGeometry) => { g.computeBoundingBox(); return g.boundingBox!; };
|
||||
const a = haut(quille(false)), b = haut(quille(true));
|
||||
assert.ok(Math.abs(a.min.y - b.min.y) < 0.01 && Math.abs(a.max.y - b.max.y) < 0.03);
|
||||
// une tête : un rétrécissement (le cou) entre le buste et le haut
|
||||
const p = quille(true).attributes.position!, largeur = (y0: number, y1: number) => { let r = 0; for (let i = 0; i < p.count; i++) { const y = p.getY(i); if (y > y0 && y < y1) r = Math.max(r, Math.hypot(p.getX(i), p.getZ(i))); } return r; };
|
||||
assert.ok(largeur(0.33, 0.4) < 0.85 * largeur(0.5, 0.6));
|
||||
const scene = lire('maquette/scene.js');
|
||||
assert.match(scene, /const geoP = quille\(trait\)/);
|
||||
assert.match(scene, /new THREE\.InstancedMesh\(quille\(trait\)/);
|
||||
assert.doesNotMatch(scene, /CapsuleGeometry\(0\.28, 0\.95/);
|
||||
assert.match(scene, /attelage\(trait\)/);
|
||||
assert.equal(attelage(true).children.length, attelage(false).children.length);
|
||||
});
|
||||
|
||||
test('un seul matériau de trait : maisons, serres et témoin à la même encre, fusionnés par famille', () => {
|
||||
const scene = lire('maquette/scene.js');
|
||||
assert.match(scene, /const encre = trait \? new THREE\.LineBasicMaterial\(\{ color: PAL\.trait, transparent: true, opacity: TRAIT_M\.opacite \}\) : null;/);
|
||||
assert.match(scene, /const matTrait = encre \|\| /);
|
||||
assert.match(scene, /bord: encre \|\| /);
|
||||
assert.match(scene, /temoin\.meshes\.trait\.material = encre/);
|
||||
// la fusion : une LineSegments par racine, à l'encre, après la pose des objets et du témoin
|
||||
assert.match(scene, /new THREE\.LineSegments\(mergeGeometries\(geos\), encre\)/);
|
||||
assert.ok(scene.indexOf('const mesureTrait') > scene.indexOf('const temoin = !fond'));
|
||||
assert.ok(TRAIT_M.seuil > 0 && TRAIT_M.coque > 1);
|
||||
});
|
||||
@@ -4,7 +4,7 @@
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { lireFiches, CADRAGES } from '../scripts/contenu.ts';
|
||||
import { lireFiches, lireObjets, CADRAGES } from '../scripts/contenu.ts';
|
||||
|
||||
const lire = (p: string) => readFileSync(new URL(`../${p}`, import.meta.url), 'utf8');
|
||||
const objets = lire('maquette/objets.js'), scene = lire('maquette/scene.js'), gestes = lire('maquette/gestes.js');
|
||||
@@ -12,11 +12,12 @@ const chapitres = lireFiches(lire('content/fiches.md'));
|
||||
const fiches = new Map(chapitres.flatMap((c) => c.fiches).map((f) => [f.id, f]));
|
||||
const tous = (re: RegExp, s: string) => [...s.matchAll(re)].map((m) => m[1]!);
|
||||
|
||||
// les objets reliés par objets.js : relie(objs, '<fiche>', '<effet = cadrage>', …)
|
||||
const relies = [...objets.matchAll(/relie\((?:\[[^\]]*\]|[^,]+), '([a-z-]+)', '([a-z-]+)'/g)].map((m) => ({ fiche: m[1]!, nom: m[2]! }));
|
||||
// les objets du Tour : TOUR_FICHES = { <nom>: ['<fiche>', <largeur>], … } (leur nom est leur effet et leur cadrage)
|
||||
const tourSrc = objets.slice(objets.indexOf('export const TOUR_FICHES'));
|
||||
const tour = [...tourSrc.slice(0, tourSrc.indexOf('};')).matchAll(/([a-z]+): \['([a-z-]+)', \d+\]/g)].map((m) => ({ fiche: m[2]!, nom: m[1]! }));
|
||||
// Lot M1 table (14/11) : les objets reliés et leurs cadrages ne s'écrivent plus dans objets.js mais dans content/objets.md
|
||||
// (une ligne par objet) ; ce test lit la table. Les objets du Tour sont ses lignes de type `geste` (leur id est leur effet et
|
||||
// leur cadrage) ; une ligne « avec <id> » élargit le cadrage d'une autre et ne compte pas à part.
|
||||
const table = lireObjets(lire('content/objets.md'), chapitres).filter((l) => l.fiche && l.cadrage && 'nom' in l.cadrage);
|
||||
const relies = table.filter((l) => l.type !== 'geste').map((l) => ({ fiche: l.fiche!, nom: (l.cadrage as { nom: string }).nom }));
|
||||
const tour = table.filter((l) => l.type === 'geste').map((l) => ({ fiche: l.fiche!, nom: l.id }));
|
||||
const OBJETS = [...relies, ...tour];
|
||||
|
||||
test('objets : la lecture des sources trouve les objets (garde-fou du test lui-même)', () => {
|
||||
|
||||
@@ -82,7 +82,7 @@ test('T3 : le minibus, sur la route seulement, sans demi-tour à vue, jamais sur
|
||||
const V = R.trajetsVelos(D, T), bus = echantillonne(t, 1);
|
||||
for (const o of V.sentiers) for (const p of echantillonne(o.pts, 1)) assert.ok(Math.min(...bus.map((q) => dist(p, q))) > 4, 'un trajet de vélo passe sur la route du bus');
|
||||
// scene.js : vélos, cargos, charrette et convoi de la route prennent la piste ; objets.js : le minibus sa voie, hors mode fond
|
||||
for (const re of [/tr\.principale, 4\.2, piste\(2\.8\)/, /tr\.principale, 3\.8, piste\(-2\.6\)/, /tr\.principale, 3\.2, piste\(-2\.4\)/, /attelage\(\), tr\.principale, 1\.6, piste\(2\.2\)/, /droite = retouches \? PISTE : 1\.9/]) assert.match(scene, re);
|
||||
for (const re of [/tr\.principale, 4\.2, piste\(2\.8\)/, /tr\.principale, 3\.8, piste\(-2\.6\)/, /tr\.principale, 3\.2, piste\(-2\.4\)/, /attelage\((?:trait)?\), tr\.principale, 1\.6, piste\(2\.2\)/, /droite = retouches \? PISTE : 1\.9/]) assert.match(scene, re);
|
||||
assert.match(objets, /o\.position\.set\(p\.x - dz \* VOIE_BUS, 0, p\.z \+ dx \* VOIE_BUS\)/);
|
||||
assert.match(objets, /o\.visible = !h\.attente/);
|
||||
assert.match(lire('content/fiches.md'), /### quartier-bus — [^\n]*\n(?:- [^\n]*\n)+Un petit bus de quartier /);
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
// Lot M1 table (14/11) : un objet = une ligne de content/objets.md. Le témoin des positions (étape A) est figé : la scène
|
||||
// construite après le lot doit lui être égale, à 1 cm et 0,1° près (maquette/temoin.ts, scripts/temoin-objets.mjs).
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { readFileSync, existsSync } from 'node:fs';
|
||||
import { spawnSync } from 'node:child_process';
|
||||
import { lireFiches, lireObjets } from '../scripts/contenu.ts';
|
||||
import { comparerReleves } from '../maquette/temoin.ts';
|
||||
|
||||
const lire = (p: string) => readFileSync(new URL(`../${p}`, import.meta.url), 'utf8');
|
||||
const TEMOIN = JSON.parse(lire('tests/temoin-objets.json'));
|
||||
const CHAP = lireFiches(lire('content/fiches.md')), MD = lire('content/objets.md');
|
||||
const fiches = new Set(CHAP.flatMap((c) => c.fiches.map((f) => f.id)));
|
||||
const CHROMIUM = process.env.CHROMIUM || '/home/julesneny8/.cache/ms-playwright/chromium-1254/chrome-linux64/chrome';
|
||||
|
||||
test('témoin : figé, complet (démo et mode fond), chaque objet nommé par une fiche qui existe', () => {
|
||||
for (const k of ['demo', 'fond']) {
|
||||
const t = TEMOIN[k];
|
||||
assert.equal(t.poses.length, 28, `${k} : 28 objets posés au témoin`);
|
||||
assert.equal(t.laisses.length, 0, `${k} : aucun objet laissé`);
|
||||
for (const o of t.poses) if (o.fiche) assert.ok(fiches.has(o.fiche), `${k} ${o.id} : fiche absente`);
|
||||
assert.deepEqual(comparerReleves(t, t), [], `${k} : le témoin est égal à lui-même`);
|
||||
}
|
||||
});
|
||||
|
||||
test('témoin : la comparaison voit un objet déplacé de 2 cm, tourné de 0,2°, ou retiré', () => {
|
||||
const t = structuredClone(TEMOIN.demo);
|
||||
t.poses[3].p[0] += 0.02; t.poses[5].r[1] += (0.2 * Math.PI) / 180;
|
||||
const e = comparerReleves(TEMOIN.demo, t);
|
||||
assert.ok(e.some((x) => x.includes(`${t.poses[3].id} : position`)), e.join('\n'));
|
||||
assert.ok(e.some((x) => x.includes(`${t.poses[5].id} : rotation`)), e.join('\n'));
|
||||
const u = structuredClone(TEMOIN.demo); u.poses.pop();
|
||||
assert.ok(comparerReleves(TEMOIN.demo, u).some((x) => x.includes('absent après')));
|
||||
const v = structuredClone(TEMOIN.demo); v.poses[3].p[0] += 0.009;
|
||||
assert.deepEqual(comparerReleves(TEMOIN.demo, v), [], 'sous 1 cm, rien');
|
||||
});
|
||||
|
||||
// la scène construite (Chromium : la scène demande WebGL) égale le témoin ; sauté sans Chromium ou sous QUARTIER_RAPIDE=1
|
||||
test('témoin : la scène construite aujourd’hui égale le témoin (démo et fond)', { skip: !existsSync(CHROMIUM) || process.env.QUARTIER_RAPIDE === '1' }, () => {
|
||||
const r = spawnSync(process.execPath, ['scripts/temoin-objets.mjs'], { cwd: new URL('..', import.meta.url), encoding: 'utf8', timeout: 300000 });
|
||||
assert.equal(r.status, 0, `${r.stdout}\n${r.stderr}`);
|
||||
assert.match(r.stdout, /demo : identique au témoin/);
|
||||
assert.match(r.stdout, /fond : identique au témoin/);
|
||||
});
|
||||
|
||||
test('table : content/objets.md se lit ; une ligne par objet, dans l’ordre de la pose', () => {
|
||||
const L = lireObjets(MD, CHAP);
|
||||
assert.equal(L.length, 25, '25 lignes');
|
||||
assert.deepEqual(L.slice(0, 8).map((l) => l.id), ['cuves', 'baissiere', 'tube', 'cochon', 'chantier', 'surplus', 'planches', 'convoi'], 'les objets du Tour et le convoi d’abord');
|
||||
// l’ordre compte : l’atelier avant la colocation (elle lui prenait sa place), le jardin commun avant les autres maisons
|
||||
const i = (id: string) => L.findIndex((l) => l.id === id);
|
||||
assert.ok(i('atelier') < i('jardin-commun') && i('jardin-commun') < i('colocation') && i('colocation') < i('tiny-houses'));
|
||||
// les lignes du témoin, dans le même ordre que les objets posés (une fiche par objet, à la première occurrence)
|
||||
const ordre = [...new Set(TEMOIN.demo.poses.map((o: { fiche: string | null }) => o.fiche).filter(Boolean))];
|
||||
const ordreTable = [...new Set(L.filter((l) => l.type !== 'geste' && l.type !== 'convoi').map((l) => (l.id === 'arret-bus' ? 'quartier-bus' : l.fiche)))];
|
||||
assert.deepEqual(ordreTable, ordre, 'l’ordre des lignes est celui de la pose au témoin');
|
||||
for (const l of L) if (l.fiche) assert.ok(fiches.has(l.fiche), l.id);
|
||||
});
|
||||
|
||||
const avec = (avant: string, apres: string) => { assert.ok(MD.includes(avant), `le test cherche « ${avant} »`); return MD.replace(avant, apres); };
|
||||
test('table : un type inconnu arrête la lecture et nomme la ligne', () => {
|
||||
assert.throws(() => lireObjets(avec('| ruches | Faire ensemble | ruches |', '| ruches | Faire ensemble | ruchez |'), CHAP), /content\/objets\.md, ligne \d+ : type « ruchez » inconnu/);
|
||||
});
|
||||
test('table : une fiche absente de fiches.md arrête la lecture et nomme la ligne', () => {
|
||||
assert.throws(() => lireObjets(avec('| vivant-ruches | ruches 40 |', '| vivant-rucher | ruches 40 |'), CHAP), /ligne \d+ : fiche « vivant-rucher » absente/);
|
||||
});
|
||||
test('table : une teinte hors palette (ou un code couleur) arrête la lecture et nomme la ligne', () => {
|
||||
assert.throws(() => lireObjets(avec('| autos-5 | quartier-atelier |', '| #c8553d | quartier-atelier |'), CHAP), /ligne \d+ : teinte « #c8553d » hors palette/);
|
||||
assert.throws(() => lireObjets(avec('| autos-5 | quartier-atelier |', '| autos-9 | quartier-atelier |'), CHAP), /teinte « autos-9 » hors palette/);
|
||||
});
|
||||
test('table : une règle inconnue, un repère inconnu, un id en double arrêtent la lecture', () => {
|
||||
assert.throws(() => lireObjets(avec('| ruches | lisiere |', '| ruches | au-hasard |'), CHAP), /règle « au-hasard » inconnue/);
|
||||
assert.throws(() => lireObjets(avec('| place 34 |', '| fontaine 34 |'), CHAP), /repère « fontaine » inconnu/);
|
||||
assert.throws(() => lireObjets(MD.trimEnd() + '\n| ruches | Faire ensemble | ruches | lisiere | forêt ou vergers | 6 × 1,6 × 1 | — | vivant-ruches | ruches 40 | 2035 | centre |\n', CHAP), /l'id « ruches » est déjà pris/);
|
||||
});
|
||||
test('table : une ligne ajoutée en bas, d’un type existant, se lit sans toucher aux autres', () => {
|
||||
const L = lireObjets(MD, CHAP), L2 = lireObjets(MD.trimEnd() + '\n| ruches-2 | Faire ensemble | ruches | lisiere | forêt ou vergers | 6 × 1,6 × 1 | — | vivant-ruches | ruches 40 | 2035 | centre |\n', CHAP);
|
||||
assert.equal(L2.length, L.length + 1);
|
||||
assert.deepEqual(L2.slice(0, L.length), L);
|
||||
assert.equal(L2.at(-1)!.id, 'ruches-2');
|
||||
});
|
||||
|
||||
test('table : chaque règle de la liste a sa fonction dans pose.ts, chaque type sa fabrique (ou sa branche propre) dans objets.js', async () => {
|
||||
const { REGLES_OBJETS, TYPES_OBJETS } = await import('../scripts/contenu.ts');
|
||||
const pose = lire('maquette/pose.ts'), objets = lire('maquette/objets.js');
|
||||
const regles = pose.slice(pose.indexOf('export const REGLES'));
|
||||
for (const r of REGLES_OBJETS) if (r !== 'propre') assert.match(regles, new RegExp(`(^|\\n) '?${r}'?\\(c,`), `la règle ${r} n'a pas de fonction`);
|
||||
for (const t of TYPES_OBJETS) assert.ok(objets.includes(`'${t}': {`) || objets.includes(`\n ${t}: {`) || objets.includes(`PROPRES['${t}']`) || objets.includes(`PROPRES.${t} =`), `le type ${t} n'a ni fabrique ni branche`);
|
||||
});
|
||||
File diff suppressed because it is too large
Load Diff
+4
-3
@@ -2,7 +2,7 @@ import { defineConfig, type Plugin } from 'vite';
|
||||
import { execSync } from 'node:child_process';
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { lireEssences, lireFiches, lireCycle, lirePlanches, lireSystemes, lireCarte, verifierDocuments, verifierCadragesCarte, verifierDocumentsSystemes, lireRessources, lierRessources, lireParcelles, lireAjouter, lireEpingles, lireTextesXl, lireTypesXl, RECTANGLE, REGROUPEMENT } from './scripts/contenu.ts';
|
||||
import { lireEssences, lireFiches, lireCycle, lirePlanches, lireSystemes, lireCarte, verifierDocuments, verifierCadragesCarte, verifierDocumentsSystemes, lireRessources, lierRessources, lireParcelles, lireObjets, lireAjouter, lireEpingles, lireTextesXl, lireTypesXl, RECTANGLE, REGROUPEMENT } from './scripts/contenu.ts';
|
||||
|
||||
// Marqueur de build : hash git court, injecté dans la page et dans /build.json.
|
||||
// Un HTTP 200 ne valide rien ; le marqueur, si.
|
||||
@@ -23,7 +23,7 @@ const FICHIERS_XL = [ici('./content/xl-epingles.md'), ici('./content/xl-textes.m
|
||||
// Une faute de saisie arrête le build avec la ligne à corriger (scripts/contenu.ts).
|
||||
function contenu(): Plugin {
|
||||
const ID = 'virtual:contenu';
|
||||
const fichiers = [ici('./content/fiches.md'), ici('./content/essences.md'), ici('./content/cycle-eau.md'), ici('./content/planches.md'), ici('./maquette/documents.json'), ici('./content/systemes.md'), ici('./maquette/carte.json'), ici('./content/carte.md'), ici('./content/ressources.md'), ici('./content/parcelles.md'), ici('./data/scene2035.json'), FICHIERS_XL[1]!];
|
||||
const fichiers = [ici('./content/fiches.md'), ici('./content/essences.md'), ici('./content/cycle-eau.md'), ici('./content/planches.md'), ici('./maquette/documents.json'), ici('./content/systemes.md'), ici('./maquette/carte.json'), ici('./content/carte.md'), ici('./content/ressources.md'), ici('./content/parcelles.md'), ici('./data/scene2035.json'), FICHIERS_XL[1]!, ici('./content/objets.md')];
|
||||
return {
|
||||
name: 'quartier-contenu',
|
||||
resolveId: (id) => (id === ID ? '\0' + ID : null),
|
||||
@@ -34,6 +34,7 @@ function contenu(): Plugin {
|
||||
// lot ⑤ : les ressources des fiches, et les parcelles (une ligne par maison du plan)
|
||||
lierRessources(CHAPITRES, lireRessources(readFileSync(fichiers[8]!, 'utf8'), CHAPITRES));
|
||||
const PARCELLES = lireParcelles(readFileSync(fichiers[9]!, 'utf8'), CHAPITRES, JSON.parse(readFileSync(fichiers[10]!, 'utf8')).maisons);
|
||||
const OBJETS = lireObjets(readFileSync(process.env.QUARTIER_OBJETS || fichiers[12]!, 'utf8'), CHAPITRES); // lot M1 table : un objet = une ligne
|
||||
const AJOUTER = lireAjouter(readFileSync(fichiers[8]!, 'utf8')); // les textes du bloc « Ajouter une ressource » (10/11)
|
||||
const ESSENCES = lireEssences(readFileSync(fichiers[1]!, 'utf8'));
|
||||
const CYCLE = lireCycle(readFileSync(fichiers[2]!, 'utf8'));
|
||||
@@ -43,7 +44,7 @@ function contenu(): Plugin {
|
||||
verifierDocuments(CHAPITRES, PLANCHES);
|
||||
verifierCadragesCarte(CHAPITRES, CARTE);
|
||||
verifierDocumentsSystemes(SYSTEMES, PLANCHES);
|
||||
return `export const CHAPITRES = ${JSON.stringify(CHAPITRES)};\nexport const ESSENCES = ${JSON.stringify(ESSENCES)};\nexport const CYCLE = ${JSON.stringify(CYCLE)};\nexport const PLANCHES = ${JSON.stringify(PLANCHES)};\nexport const SYSTEMES = ${JSON.stringify(SYSTEMES)};\nexport const CARTE = ${JSON.stringify(CARTE)};\nexport const PARCELLES = ${JSON.stringify(PARCELLES)};\nexport const AJOUTER = ${JSON.stringify(AJOUTER)};\nexport const XL_VUES = ${JSON.stringify(lireXl().TEXTES.vues)};`;
|
||||
return `export const CHAPITRES = ${JSON.stringify(CHAPITRES)};\nexport const ESSENCES = ${JSON.stringify(ESSENCES)};\nexport const CYCLE = ${JSON.stringify(CYCLE)};\nexport const PLANCHES = ${JSON.stringify(PLANCHES)};\nexport const SYSTEMES = ${JSON.stringify(SYSTEMES)};\nexport const CARTE = ${JSON.stringify(CARTE)};\nexport const PARCELLES = ${JSON.stringify(PARCELLES)};\nexport const AJOUTER = ${JSON.stringify(AJOUTER)};\nexport const XL_VUES = ${JSON.stringify(lireXl().TEXTES.vues)};\nexport const OBJETS = ${JSON.stringify(OBJETS)};`;
|
||||
},
|
||||
handleHotUpdate(ctx) {
|
||||
if (fichiers.some((f) => ctx.file.replace(/\\/g, '/') === f.replace(/\\/g, '/'))) {
|
||||
|
||||
Reference in New Issue
Block a user