Objets nouveaux : point de reprise du 03/11 (travail du 31/10, non relu)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PWGVmzHkRQiiivdZYKzLAP
This commit is contained in:
Jules Nény
2026-11-03 14:12:11 +01:00
co-authored by Claude Opus 5.5
parent f8ec86469f
commit 34e0727572
5 changed files with 1026 additions and 21 deletions
+46 -8
View File
@@ -5,6 +5,7 @@ import * as THREE from 'three';
import { lot, haiesEssences, vergers, arbresPlan, thuyas, plantesEau, potager, NOMS_AQUA, rnd } from './vegetal.js';
import { vieAnimale, velo, veloCargo, attelage, voiture, chien, remorque } from './animaux.js';
import { gestesDuTour } from './gestes.js';
import { objetsNouveaux } from './objets.js';
import { PLAFONDS_FOND, prochaineImage, vueScenario, SCENARIO_FOND } from './mode.ts';
const PAL = {
@@ -20,6 +21,7 @@ const PAL = {
// 1,5, 30 images par seconde, le sol d'aujourd'hui jamais chargé (on reste en 2035), et `onPret()` appelé après la
// première image dessinée textures chargées ; sous mouvement réduit, cette image est la seule (aucune boucle).
export function creerScene(canvas, { D, ESSENCES, BULLES, IMG, reduit, petit, onToucher, fond = false, onPret = () => {} }) {
const t0 = performance.now();
const renderer = new THREE.WebGLRenderer({ canvas, antialias: true, powerPreference: fond ? 'low-power' : 'high-performance' });
if (!renderer.getContext()) return null;
renderer.setPixelRatio(Math.min(devicePixelRatio || 1, fond ? PLAFONDS_FOND.pixelRatio : petit ? 1.5 : 2));
@@ -139,10 +141,12 @@ export function creerScene(canvas, { D, ESSENCES, BULLES, IMG, reduit, petit, on
if (estGrand) grand = g;
return g;
}
for (const h of D.maisons) {
if (h.t === 'transformee') { G.v2035.add(maison(h, '2035')); G.vAuj.add(maison(h, 'auj')); }
else scene.add(maison(h, '2035'));
}
// les maisons qui ne changent pas d'époque gardent leur groupe (par indice du plan) : les objets nouveaux en font des
// cliquables (la colocation, la grande maison des tiny houses, les deux maisons du jardin commun)
const groupesMaisons = D.maisons.map((h) => {
if (h.t === 'transformee') { G.v2035.add(maison(h, '2035')); G.vAuj.add(maison(h, 'auj')); return null; }
const g = maison(h, '2035'); scene.add(g); return g;
});
const T = transformees[D.temoin.maison];
transformees.forEach((m) => cliquables.push({ o: m.g, fiche: 'energie-paille' }));
if (grand) cliquables.push({ o: grand, fiche: 'quartier-communs' });
@@ -153,7 +157,8 @@ export function creerScene(canvas, { D, ESSENCES, BULLES, IMG, reduit, petit, on
const matsForet = { couronne: new THREE.MeshLambertMaterial({ color: '#ffffff', emissive: '#000000' }), tronc: matsHaie.tronc, fruit: matsHaie.fruit };
const matsAutres = { couronne: new THREE.MeshLambertMaterial({ color: '#ffffff' }), tronc: matsHaie.tronc, fruit: matsHaie.fruit };
const itemsHaies = haiesEssences(D.haies, E);
G.v2035.add(lot(itemsHaies, matsHaie, E.reglages.fruits));
let lotHaies = lot(itemsHaies, matsHaie, E.reglages.fruits); // redessiné sans la haie ouverte du jardin commun (objets.js)
G.v2035.add(lotHaies);
const itemsVergers = vergers(D.vergers, E);
G.v2035.add(lot(itemsVergers, matsHaie, E.reglages.fruits));
const parGenre = (k) => D.arbres.filter((a) => a[4] === k);
@@ -392,9 +397,21 @@ export function creerScene(canvas, { D, ESSENCES, BULLES, IMG, reduit, petit, on
});
}
maj(0);
return { maj, centre };
return { maj, centre, objs: membres.map((m) => m.o) };
})();
// ---------------------------------------------------------------- les objets nouveaux (31/10, objets.js) et ceux du Tour,
// cliquables : chacun ouvre sa fiche, a son cadrage et s'allume quand on la lit. Tous de 2035.
const objets = objetsNouveaux({ D, groupe: G.v2035, T, P: gestes.P, maisons: groupesMaisons, tr, PAL, geoP, verre: mat.verre, matsArbres: matsAutres,
tour: gestes, convoi });
anim.push(...objets.anim);
cliquables.push(...objets.cliquables);
if (objets.haieOuverte) {
// la haie entre les deux maisons du jardin commun s'ouvre : on la redessine sans les arbres de ce morceau
const { k, s0, s1 } = objets.haieOuverte;
G.v2035.remove(lotHaies); lotHaies.children.forEach((c) => c.dispose?.()); lotHaies = lot(itemsHaies.filter((it) => !(it.haie === k && it.s > s0 && it.s < s1)), matsHaie, E.reglages.fruits); G.v2035.add(lotHaies);
}
// ---------------------------------------------------------------- bulles de la planche 2030 (dessins de Jules, p. 15)
const VERT = new Set(['pomme', 'abeille', 'fleur', 'arbre', 'oiseaux']);
const matTige = { v: new THREE.MeshLambertMaterial({ color: '#9db878' }), q: new THREE.MeshLambertMaterial({ color: '#d9a866' }) };
@@ -449,6 +466,11 @@ export function creerScene(canvas, { D, ESSENCES, BULLES, IMG, reduit, petit, on
})(),
};
CAD.toit = CAD.maison;
// un cadrage par objet (objets.js) : fixe, ou qui suit le véhicule (navette, bus, Rosalie, convoi) tant qu'on ne touche pas
for (const [nom, p] of Object.entries(objets.points)) {
if (CAD[nom]) continue;
CAD[nom] = p.w ? { x: p.x, z: p.z, w: p.w } : { get x() { return p.x; }, get z() { return p.z; }, w: 56, suit: true };
}
// ---------------------------------------------------------------- le tour du mode fond (22/10) : les éléments, dans l'ordre
// (brief du lot, §3) ; chacun avec sa largeur vue (S3 : ≈ 55 m, plus serré sur les petits objets). Les positions sont
@@ -483,6 +505,7 @@ export function creerScene(canvas, { D, ESSENCES, BULLES, IMG, reduit, petit, on
cam.lookAt(vue.x, 0, vue.z);
}
let panneau_ = () => ({ bas: 0, gauche: 0 });
let suivi = null; // un cadrage qui suit un véhicule : le décalage du panneau, gardé
function largeur(c) {
if (c.w) return c.w;
const { W, H } = taille(), a = W / H;
@@ -504,6 +527,7 @@ export function creerScene(canvas, { D, ESSENCES, BULLES, IMG, reduit, petit, on
let az = c.az ?? 0; while (az - vue.az > Math.PI) az -= 2 * Math.PI; while (az - vue.az < -Math.PI) az += 2 * Math.PI;
const ra = Math.cos(az), rza = -Math.sin(az), fa = -Math.sin(az), fza = -Math.cos(az);
const apres = { x: c.x - ra * offX - fa * offY, z: c.z - rza * offX - fza * offY, az, el: vue.el, w };
suivi = c.suit ? { nom, ox: apres.x - c.x, oz: apres.z - c.z } : null;
if (reduit || duree === 0) { Object.assign(vue, apres); besoin = true; return; }
vol = { avant: { ...vue }, apres, t0: performance.now(), d: duree };
}
@@ -549,7 +573,7 @@ export function creerScene(canvas, { D, ESSENCES, BULLES, IMG, reduit, petit, on
ecoute('pointerup', fin); ecoute('pointercancel', fin);
ecoute('wheel', (e) => { e.preventDefault(); vol = null; zoomVers(e.clientX, e.clientY, e.deltaY > 0 ? 1.12 : 1 / 1.12); onToucher('geste'); }, { passive: false });
const ray = new THREE.Raycaster();
const LIENS_BULLES = { marche: 'quartier-marche', pomme: 'vivant-haie', abeille: 'vivant-foret', miel: 'vivant-foret', fleur: 'vivant-foret', arbre: 'vivant-strates', biere: 'quartier-communs', couverts: 'quartier-communs', outils: 'energie-ensemble', oiseaux: 'eau-mare', promeneurs: 'vivant-sentier', enfant: 'quartier-mobilite', confiture: 'vivant-nourrir', bouteille: 'vivant-nourrir', apaise1: 'quartier-mobilite', apaise2: 'quartier-mobilite' };
const LIENS_BULLES = { marche: 'quartier-marche', pomme: 'vivant-haie', abeille: 'vivant-foret', miel: 'vivant-foret', fleur: 'vivant-foret', arbre: 'vivant-strates', biere: 'quartier-communs', couverts: 'quartier-communs', outils: 'energie-ensemble', oiseaux: 'eau-mare', promeneurs: 'vivant-sentier', enfant: 'quartier-mobilite', confiture: 'vivant-nourrir', bouteille: 'vivant-nourrir', apaise1: 'quartier-mobilite', apaise2: 'quartier-mobilite', garage: 'quartier-atelier' };
function toucher(px, py) {
if (!G.v2035.visible) return;
const { W, H } = taille(); ray.setFromCamera(new THREE.Vector2((px / W) * 2 - 1, -(py / H) * 2 + 1), cam);
@@ -602,6 +626,11 @@ export function creerScene(canvas, { D, ESSENCES, BULLES, IMG, reduit, petit, on
pulseEm(mat.pompe, fx === 'pompe', 0.05, 0.25, 0.45, puls);
pulseEm(mat.grandToit, fx === 'communs', 0.35, 0.12, 0, puls);
matEtal.forEach((m) => pulseEm(m, fx === 'marche', 0.25, 0.14, 0, puls));
// les objets (objets.js) : un émissif léger par-dessus leur émissif propre (le verre du tube en a un)
for (const [nom, L] of Object.entries(objets.lumieres)) {
const on = fx === nom ? puls : 0;
for (const m of L) { const b = (m.userData.base ??= m.emissive.clone()); m.emissive.setRGB(b.r + 0.26 * on, b.g + 0.17 * on, b.b + 0.05 * on); }
}
if (imPotager) pulseEm(imPotager.material, fx === 'strates' || fx === 'nourrir', 0.15, 0.12, 0, puls);
eauV.meshes.forEach((m) => pulseEm(m.material, fx === 'noue-plantes' || fx === 'phyto', 0.06, 0.12, 0.08, puls));
const zoom = Math.max(0.55, Math.min(1.6, vue.w / 60));
@@ -631,7 +660,9 @@ export function creerScene(canvas, { D, ESSENCES, BULLES, IMG, reduit, petit, on
});
const vMob = fx === 'mobilite' || fx === 'travail';
mobiles.forEach((m) => { if (m.role && m.obj.children) { const k = vMob && (m.role === 'cargo' || m.role === 'attelage' || (fx === 'travail' && m.role === 'partagee')) ? 1.25 : 1; m.obj.scale.setScalar(k); } });
if (G.v2035.visible) convoi.maj(dt);
if (G.v2035.visible) { convoi.maj(dt); objets.maj.forEach((f) => f(dt)); }
// la caméra suit le véhicule de la fiche, en douceur, tant que personne ne la reprend
if (suivi && suivi.nom === cadrageCourant && !vol && !scenario) { const c = CAD[suivi.nom], k = Math.min(1, dt * 2.5); vue.x += (c.x + suivi.ox - vue.x) * k; vue.z += (c.z + suivi.oz - vue.z) * k; }
// mode fond : la caméra suit le scénario (x, z, largeur ; jamais l'azimut ni l'élévation). Son temps avance avec la
// boucle, donc s'arrête sous `document.hidden`, ne saute pas après un retard (dt plafonné), et ne part qu'après la
// première image (celle du message `quartier:pret`).
@@ -655,6 +686,13 @@ export function creerScene(canvas, { D, ESSENCES, BULLES, IMG, reduit, petit, on
dessiner();
}
// `?mesure` dans l'adresse : les instruments du RECAP (triangles, temps de construction, position à l'écran d'un objet),
// lus par les scripts de capture ; rien sans ce paramètre
if (/[?&]mesure\b/.test(location.search)) {
const v = new THREE.Vector3();
window.__quartier = { renderer, construction: performance.now() - t0, laisses: objets.laisses, diag: objets.diag, points: objets.points, cadrage: () => cadrageCourant,
ecran(x, y, z) { v.set(x, y, z).project(cam); const { W, H } = taille(); return { x: (v.x + 1) / 2 * W, y: (1 - v.y) / 2 * H }; } };
}
return {
cadrer, effet, epoque, tourner,
poserPanneau(f) { panneau_ = f; },