Lot M1 trait, étape C : une encre, fusionnée par famille (X3) ; contour des arbres posé mais éteint (X8)
Au trait : maisons, serres (y compris celles des objets) et témoin à la même encre (PAL.trait, opacité 0,55) ; après la pose des objets et du témoin, les arêtes visibles et fixes deviennent une LineSegments par racine (quartier, 2035, aujourd'hui), faces voisines en polygonOffset. Coque inversée des couronnes (geoCoque, vegetal.js) : + 43 % de triangles au mieux, au-delà des + 15 % du brief : TRAIT_M.contours = [] (['haies'] la rallume). Les bêtes et les objets du Tour n'ont pas de trait. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
eeabc09dc1
commit
3d04f7c50d
+7
-1
@@ -32,4 +32,10 @@ export const LUMIERES = {
|
|||||||
* fusionnées par famille. Les arbres instanciés ont un contour par coque inversée (`coque` : l'agrandissement).
|
* 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.
|
* 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.07, coqueOpacite: 0.5 } as const;
|
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;
|
||||||
|
|||||||
+45
-4
@@ -3,7 +3,7 @@
|
|||||||
// un cadrage ne bougent pas la caméra (c'est ce qui empêche les fiches de « se balader »).
|
// 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 * as THREE from 'three';
|
||||||
import { mergeGeometries } from 'three/addons/utils/BufferGeometryUtils.js';
|
import { mergeGeometries } from 'three/addons/utils/BufferGeometryUtils.js';
|
||||||
import { lot, haiesEssences, vergers, arbresPlan, thuyas, plantesEau, potager, NOMS_AQUA, rnd } from './vegetal.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 { vieAnimale, velo as veloA, veloCargo, attelage, voiture, chien, remorque, quille } from './animaux.js';
|
||||||
import { gestesDuTour } from './gestes.js';
|
import { gestesDuTour } from './gestes.js';
|
||||||
import { objetsNouveaux } from './objets.js';
|
import { objetsNouveaux } from './objets.js';
|
||||||
@@ -93,11 +93,13 @@ export function creerScene(canvas, { D, ESSENCES, BULLES, IMG, reduit, petit, on
|
|||||||
const anim = [];
|
const anim = [];
|
||||||
|
|
||||||
// ---------------------------------------------------------------- maisons
|
// ---------------------------------------------------------------- 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 = {
|
const mat = {
|
||||||
mur: new THREE.MeshLambertMaterial({ color: PAL.mur }), toit: new THREE.MeshLambertMaterial({ color: PAL.toit, side: THREE.DoubleSide }),
|
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 }),
|
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' }),
|
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' }),
|
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' }),
|
zinc: new THREE.MeshLambertMaterial({ color: '#9aa3a6', emissive: '#000000' }), pompe: new THREE.MeshLambertMaterial({ color: '#5f7f96', emissive: '#000000' }),
|
||||||
@@ -858,6 +860,45 @@ export function creerScene(canvas, { D, ESSENCES, BULLES, IMG, reduit, petit, on
|
|||||||
dessiner();
|
dessiner();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------- lot M1 (X3) : le trait, fusionné par famille
|
||||||
|
// Une fois tout posé (objets, témoin) : les arêtes à l'encre et celles des serres, visibles et fixes, deviennent une
|
||||||
|
// seule LineSegments par racine (le quartier, 2035, aujourd'hui) ; les faces voisines reculent d'un cran (polygonOffset)
|
||||||
|
// pour que le trait ne scintille pas. Les arbres instanciés ont un contour : une coque inversée à l'encre, enfant de leur
|
||||||
|
// InstancedMesh (elle en partage les matrices et la visibilité). Les bêtes et les objets du Tour n'ont pas de trait.
|
||||||
|
const mesureTrait = { familles: 0, segments: 0, fusionnees: 0, coques: 0 };
|
||||||
|
if (trait) {
|
||||||
|
scene.updateMatrixWorld(true);
|
||||||
|
const racines = [G.v2035, G.vAuj, scene], par = new Map(), bordSerre = new THREE.Color('#86ada7'), recule = new Set();
|
||||||
|
const lignes = [];
|
||||||
|
scene.traverse((o) => { if (o.isLineSegments && o.material && (o.material === encre || (o.material.isLineBasicMaterial && o.material.color.equals(bordSerre)))) lignes.push(o); });
|
||||||
|
for (const o of lignes) {
|
||||||
|
let v = o.visible, r = o.parent;
|
||||||
|
while (r && !racines.includes(r)) { v = v && r.visible; r = r.parent; }
|
||||||
|
if (!v || !r) continue; // le témoin : maison.js cache ses arêtes (il a son propre trait, rattaché à l'encre plus bas)
|
||||||
|
const m = new THREE.Matrix4().copy(r.matrixWorld).invert().multiply(o.matrixWorld);
|
||||||
|
(par.get(r) || par.set(r, []).get(r)).push(o.geometry.clone().applyMatrix4(m));
|
||||||
|
for (const f of o.parent.children) if (f.isMesh && !f.isInstancedMesh) for (const mt of [f.material].flat()) recule.add(mt);
|
||||||
|
o.parent.remove(o); mesureTrait.fusionnees++;
|
||||||
|
}
|
||||||
|
for (const [r, geos] of par) {
|
||||||
|
const l = new THREE.LineSegments(mergeGeometries(geos), encre); l.matrixAutoUpdate = false; r.add(l);
|
||||||
|
mesureTrait.familles++; mesureTrait.segments += l.geometry.attributes.position.count / 2;
|
||||||
|
}
|
||||||
|
for (const mt of recule) if (mt && !mt.transparent) Object.assign(mt, { polygonOffset: true, polygonOffsetFactor: 1, polygonOffsetUnits: 1 });
|
||||||
|
if (temoin && temoin.meshes.trait) temoin.meshes.trait.material = encre;
|
||||||
|
// le contour des arbres : la coque (TRAIT_M.coque) de chaque couronne, faces arrière seulement
|
||||||
|
const couronnes = new Set(TRAIT_M.contours.map((k) => ({ haies: matsHaie, foret: matsForet, autres: matsAutres })[k].couronne)), coques = new Map();
|
||||||
|
const encreCoque = new THREE.MeshBasicMaterial({ color: new THREE.Color(PAL.trait).lerp(new THREE.Color(PAL.fond), 1 - TRAIT_M.coqueOpacite), side: THREE.BackSide });
|
||||||
|
const ims = []; scene.traverse((o) => { if (o.isInstancedMesh && couronnes.has(o.material)) ims.push(o); });
|
||||||
|
for (const im of ims) {
|
||||||
|
if (!coques.has(im.geometry)) coques.set(im.geometry, geoCoque(im.geometry, TRAIT_M.coque));
|
||||||
|
if (!coques.get(im.geometry)) continue;
|
||||||
|
const c = new THREE.InstancedMesh(coques.get(im.geometry), encreCoque, im.count);
|
||||||
|
c.instanceMatrix = im.instanceMatrix; c.count = im.count; c.frustumCulled = im.frustumCulled; c.raycast = () => {};
|
||||||
|
im.add(c); mesureTrait.coques++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// `?mesure` dans l'adresse : les instruments du RECAP (triangles, temps de construction, position à l'écran d'un objet),
|
// `?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
|
// lus par les scripts de capture ; rien sans ce paramètre
|
||||||
if (/[?&]mesure\b/.test(location.search)) {
|
if (/[?&]mesure\b/.test(location.search)) {
|
||||||
@@ -889,7 +930,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)
|
// 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 }; }); },
|
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 })) : []),
|
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,
|
||||||
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 }; } };
|
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 {
|
return {
|
||||||
|
|||||||
@@ -43,6 +43,14 @@ const FORMES = {
|
|||||||
};
|
};
|
||||||
const GEO = {};
|
const GEO = {};
|
||||||
const geoForme = (f) => (GEO[f] ??= FORMES[f].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
|
// ---------------------------------------------------------------- couleurs
|
||||||
export function teinte(ton, tons, i) {
|
export function teinte(ton, tons, i) {
|
||||||
|
|||||||
@@ -101,3 +101,15 @@ test('chaque personnage a une tête : même hauteur, même pied ; la scène n\'a
|
|||||||
assert.match(scene, /attelage\(trait\)/);
|
assert.match(scene, /attelage\(trait\)/);
|
||||||
assert.equal(attelage(true).children.length, attelage(false).children.length);
|
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);
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user