@@ -0,0 +1,809 @@
// Les objets nouveaux du quartier (31/10, LOT Q objets nouveaux) : la liste de la direction du 31/10 (soirées d'équipe
// des 25 et 26/10, carnet du 29/10), posée dans le quartier de 2035. La navette communale et le bus scolaire
// circulent ; un point fraîcheur, une colocation, un atelier, une conserverie, un potager partagé, des tiny houses autour
// d'une grande maison, deux maisons qui font jardin commun, des vélos cargos à prêter, la Rosalie, des ruches, la fête de
// la place, un terrain pour les forains, une parcelle en syntropie et un jardin punk.
// Même grammaire que gestes.js et animaux.js : formes de jouet en bois, palette de la planche, aucune texture, aucun
// texte, aucun chiffre. Les places sont calculées à la construction depuis le plan (data/scene2035.json), sur la même
// grille d'occupation que les gestes du Tour (P, gestes.js) : place libre sur toute l'emprise, et vue de la caméra.
// Si une place manque, l'objet n'est pas posé (et `laisses` dit lequel) : jamais en contradiction avec le plan.
import * as THREE from 'three' ;
import { mergeGeometries } from 'three/addons/utils/BufferGeometryUtils.js' ;
import { lot , teinte , rnd } from './vegetal.js' ;
import { MAT , veloCargo } from './animaux.js' ;
const lam = ( c ) => new THREE . MeshLambertMaterial ( { color : c , emissive : '#000000' } ) ;
const mesh = ( geo , m , x = 0 , y = 0 , z = 0 , ombre = false ) => { const o = new THREE . Mesh ( geo , m ) ; o . position . set ( x , y , z ) ; o . castShadow = ombre ; o . receiveShadow = true ; return o ; } ;
const boite = ( x , y , z ) => new THREE . BoxGeometry ( x , y , z ) ;
const cyl = ( r , h , n = 8 ) => new THREE . CylinderGeometry ( r , r , h , n ) ;
// teintes ajoutées dans l'esprit de la planche (bois, enduits, terre cuite, zinc) ; les autres viennent de PAL et MAT
const COUL = {
poteau : '#7b6a55' , planche : '#c49a64' , bois : '#b68f5f' , boisGris : '#8f8576' , enduit : '#e8e0cc' , zinc : '#9aa3a6' , sombre : '#3e3a35' ,
vitre : '#6f8c99' , terre : '#8a7556' , terreF : '#6f5a40' , compost : '#4a3b2c' , paillis : '#5b4a36' , sable : '#e3d3a4' , pierre : '#b9b2a6' ,
cuivre : '#b87333' , brique : '#a0634a' , tuile : '#c98466' , navette : '#e8e3d6' , eau : '#6aa3bd' , abeille : '#e3b53a' , toile : '#efe7d2' ,
} ;
const DOUX = [ '#e3d3b8' , '#c9d6c4' , '#e6c9b8' , '#cfd8de' , '#efe4c4' , '#d8c3d0' ] ; // les tiny houses, les portes : des couleurs douces
// ---------------------------------------------------------------- géométries communes
// Un toit à deux pans, faîtage le long de x : longueur L, largeur W, hauteur h ; base à y = 0. Pignons compris.
function toit2 ( L , W , h ) {
const x = L / 2 , z = W / 2 , g = new THREE . BufferGeometry ( ) ;
g . setAttribute ( 'position' , new THREE . Float32BufferAttribute ( [
- x , 0 , z , x , 0 , z , x , h , 0 , - x , 0 , z , x , h , 0 , - x , h , 0 ,
x , 0 , - z , - x , 0 , - z , - x , h , 0 , x , 0 , - z , - x , h , 0 , x , h , 0 ,
x , 0 , z , x , 0 , - z , x , h , 0 , - x , 0 , - z , - x , 0 , z , - x , h , 0 ] , 3 ) ) ;
g . computeVertexNormals ( ) ; return g ;
}
// Les gens sont des quilles (geoP de scene.js) : debout, assis (sur un banc de 0,46 m) ou enfants.
function quilles ( geoP , L , couleurs ) {
const im = new THREE . InstancedMesh ( geoP , lam ( '#ffffff' ) , L . length ) , M = new THREE . Matrix4 ( ) , col = new THREE . Color ( ) ;
L . forEach ( ( [ x , z , sorte ] , i ) => {
const k = sorte === 'assis' ? [ 1 , 0.62 , 1 ] : sorte === 'enfant' ? [ 0.62 , 0.62 , 0.62 ] : [ 1 , 1 , 1 ] ;
const y = sorte === 'assis' ? 0.46 + 0.47 : 0.76 * k [ 1 ] ;
im . setMatrixAt ( i , M . makeScale ( ... k ) . setPosition ( x , y , z ) ) ; im . setColorAt ( i , col . set ( couleurs [ ( i * 3 + 1 ) % couleurs . length ] ) ) ;
} ) ;
im . instanceColor . needsUpdate = true ; im . castShadow = true ; return im ;
}
// Un banc, une table : des planches sur pieds.
function banc ( L , m , x , z , rot = 0 ) {
const g = new THREE . Group ( ) ; g . add ( mesh ( boite ( L , 0.06 , 0.36 ) , m , 0 , 0.44 , 0 ) ) ;
for ( const s of [ 1 , - 1 ] ) g . add ( mesh ( boite ( 0.06 , 0.42 , 0.3 ) , m , s * ( L / 2 - 0.2 ) , 0.21 , 0 ) ) ;
g . position . set ( x , 0 , z ) ; g . rotation . y = rot ; return g ;
}
function table ( L , W , m , x , z , rot = 0 ) {
const g = new THREE . Group ( ) ; g . add ( mesh ( boite ( L , 0.07 , W ) , m , 0 , 0.74 , 0 , true ) ) ;
for ( const [ a , b ] of [ [ 1 , 1 ] , [ 1 , - 1 ] , [ - 1 , 1 ] , [ - 1 , - 1 ] ] ) g . add ( mesh ( boite ( 0.07 , 0.72 , 0.07 ) , m , a * ( L / 2 - 0.15 ) , 0.36 , b * ( W / 2 - 0.1 ) ) ) ;
g . position . set ( x , 0 , z ) ; g . rotation . y = rot ; return g ;
}
// ---------------------------------------------------------------- les véhicules (formes de jouet, avant vers +x)
// La navette communale : basse et ronde, 4 m, sans capot ni calandre ; deux bandeaux de vitres (un de chaque côté) et
// les deux bouts vitrés ; un petit dôme sombre sur le toit (ce qui la guide) ; quatre roues.
export function navette ( ) {
const g = new THREE . Group ( ) , m = lam ( COUL . navette ) , v = lam ( COUL . vitre ) ;
g . add ( mesh ( new THREE . CapsuleGeometry ( 0.86 , 2.3 , 4 , 14 ) . rotateZ ( Math . PI / 2 ) , m , 0 , 1.2 , 0 , true ) ) ;
for ( const s of [ 1 , - 1 ] ) {
g . add ( mesh ( boite ( 2.7 , 0.42 , 0.05 ) , v , 0 , 1.48 , s * 0.79 ) ) ;
g . add ( mesh ( boite ( 0.05 , 0.4 , 1.0 ) . rotateZ ( s * 0.5 ) , v , s * 1.86 , 1.42 , 0 ) ) ;
}
g . add ( mesh ( new THREE . SphereGeometry ( 0.2 , 10 , 6 , 0 , Math . PI * 2 , 0 , Math . PI / 2 ) , lam ( COUL . sombre ) , 0.2 , 2.03 , 0 ) ) ;
for ( const [ x , z ] of [ [ 1.2 , 0.74 ] , [ 1.2 , - 0.74 ] , [ - 1.2 , 0.74 ] , [ - 1.2 , - 0.74 ] ] ) g . add ( mesh ( cyl ( 0.31 , 0.18 , 12 ) . rotateX ( Math . PI / 2 ) , MAT . roue , x , 0.31 , z ) ) ;
return g ;
}
// Le bus scolaire : long et haut, 9 m ; un bandeau de vitres, un pare-brise, un toit clair, six roues.
export function bus ( couleur ) {
const g = new THREE . Group ( ) , m = lam ( couleur ) , v = lam ( COUL . vitre ) ;
g . add ( mesh ( boite ( 9 , 2.3 , 2.45 ) , m , 0 , 1.6 , 0 , true ) ) ;
g . add ( mesh ( boite ( 8.9 , 0.12 , 2.3 ) , lam ( '#e9e3d2' ) , 0 , 2.81 , 0 ) ) ;
g . add ( mesh ( boite ( 7.4 , 0.72 , 2.5 ) , v , - 0.5 , 2.1 , 0 ) ) ;
g . add ( mesh ( boite ( 0.06 , 1.0 , 2.2 ) , v , 4.52 , 1.95 , 0 ) ) ;
for ( const x of [ 3.1 , - 2.4 , - 3.4 ] ) for ( const z of [ 1.15 , - 1.15 ] ) g . add ( mesh ( cyl ( 0.5 , 0.26 , 12 ) . rotateX ( Math . PI / 2 ) , MAT . roue , x , 0.5 , z ) ) ;
return g ;
}
// La Rosalie : un châssis bas à quatre roues, quatre places qui pédalent (des quilles assises), un auvent rayé.
export function rosalie ( geoP , couleurs ) {
const g = new THREE . Group ( ) , cadre = lam ( '#5f7f5a' ) ;
g . add ( mesh ( boite ( 2.5 , 0.12 , 1.3 ) , cadre , 0 , 0.5 , 0 , true ) ) ;
for ( const [ x , z ] of [ [ 0.95 , 0.72 ] , [ 0.95 , - 0.72 ] , [ - 0.95 , 0.72 ] , [ - 0.95 , - 0.72 ] ] ) g . add ( mesh ( new THREE . TorusGeometry ( 0.32 , 0.045 , 5 , 14 ) , MAT . velo , x , 0.34 , z ) ) ;
for ( const [ x , z ] of [ [ 0.95 , 0.62 ] , [ 0.95 , - 0.62 ] , [ - 0.95 , 0.62 ] , [ - 0.95 , - 0.62 ] ] ) g . add ( mesh ( cyl ( 0.03 , 1.55 , 5 ) , cadre , x , 1.3 , z ) ) ;
for ( const [ x , z ] of [ [ 0.45 , 0.32 ] , [ 0.45 , - 0.32 ] , [ - 0.45 , 0.32 ] , [ - 0.45 , - 0.32 ] ] ) g . add ( mesh ( boite ( 0.42 , 0.42 , 0.06 ) , cadre , x , 0.75 , z * 1.4 ) ) ;
// l'auvent : cinq bandes, deux teintes
const a = lam ( '#c8553d' ) , b = lam ( COUL . toile ) ;
for ( let i = 0 ; i < 5 ; i ++ ) g . add ( mesh ( boite ( 2.7 / 5 , 0.08 , 1.55 ) , i % 2 ? b : a , - 1.35 + 2.7 / 10 + i * 2.7 / 5 , 2.1 , 0 , i === 2 ) ) ;
g . add ( quilles ( geoP , [ [ 0.45 , 0.32 , 'assis' ] , [ 0.45 , - 0.32 , 'assis' ] , [ - 0.45 , 0.32 , 'assis' ] , [ - 0.45 , - 0.32 , 'assis' ] ] . map ( ( [ x , z , s ] ) => [ x , z , s ] ) , couleurs ) . translateY ( 0.15 ) ) ;
return g ;
}
// ---------------------------------------------------------------- les trajets
function trajet ( pts ) { const c = [ 0 ] ; for ( let i = 1 ; i < pts . length ; i ++ ) c . push ( c [ i - 1 ] + Math . hypot ( pts [ i ] [ 0 ] - pts [ i - 1 ] [ 0 ] , pts [ i ] [ 1 ] - pts [ i - 1 ] [ 1 ] ) ) ; return { pts , c , L : c [ c . length - 1 ] } ; }
function surTrajet ( t , s ) {
s = Math . max ( 0 , Math . min ( t . L , s ) ) ; let i = 1 ; while ( i < t . c . length - 1 && t . c [ i ] < s ) i ++ ;
const a = t . pts [ i - 1 ] , b = t . pts [ i ] , k = ( s - t . c [ i - 1 ] ) / ( ( t . c [ i ] - t . c [ i - 1 ] ) || 1 ) ;
return { x : a [ 0 ] + ( b [ 0 ] - a [ 0 ] ) * k , z : a [ 1 ] + ( b [ 1 ] - a [ 1 ] ) * k , dx : b [ 0 ] - a [ 0 ] , dz : b [ 1 ] - a [ 1 ] } ;
}
// l'abscisse du point du trajet le plus proche de (x, z)
function projete ( t , x , z ) {
let best = { d : Infinity , s : 0 } ;
for ( let i = 1 ; i < t . pts . length ; i ++ ) {
const [ a , b ] = [ t . pts [ i - 1 ] , t . pts [ i ] ] , dx = b [ 0 ] - a [ 0 ] , dz = b [ 1 ] - a [ 1 ] , l = dx * dx + dz * dz || 1 , k = Math . max ( 0 , Math . min ( 1 , ( ( x - a [ 0 ] ) * dx + ( z - a [ 1 ] ) * dz ) / l ) ) ;
const d = Math . hypot ( x - a [ 0 ] - k * dx , z - a [ 1 ] - k * dz ) ; if ( d < best . d ) best = { d , s : t . c [ i - 1 ] + k * Math . sqrt ( l ) } ;
}
return best ;
}
// Un mobile qui roule sur un trajet, sur sa droite (`decal`), à la vitesse `v` ; il ralentit avant chaque arrêt, s'y tient
// `p` secondes et repart doucement. En aller-retour (`boucle` faux), chaque bout est un demi-tour ; en boucle, le trajet
// recommence (`bouts` : le trajet fait demi-tour sur lui-même à son point de départ, la file se resserre au milieu).
// Pendant un arrêt qui est un demi-tour, le véhicule tourne sur place.
function roule ( obj , t , { v , decal , arrets = [ ] , boucle = false , bouts = ! boucle , depart = 0 } ) {
const L = t . L , w = ( s ) => ( boucle ? ( ( s % L ) + L ) % L : Math . max ( 0 , Math . min ( L , s ) ) ) ;
let s = depart * L , sens = 1 , attente = 0 , duree = 1 , arret = null , parcouru = 99 , cap = 0 , capA = 0 , capB = 0 ;
const centre = { x : 0 , z : 0 } ;
const capEn = ( s , sens ) => { const p = surTrajet ( t , w ( s ) ) ; return Math . atan2 ( - p . dz * sens , p . dx * sens ) ; } ;
function maj ( dt ) {
if ( attente > 0 ) {
attente -= dt ; const k = 1 - Math . max ( 0 , attente ) / duree ; cap = capA + ( capB - capA ) * k * k * ( 3 - 2 * k ) ;
} else {
let d = Infinity , a = null ;
for ( const q of arrets ) { if ( q === arret && parcouru < 3 ) continue ; let e = ( q . s - s ) * sens ; if ( boucle && e < - 0.01 ) e += L ; if ( e >= - 0.01 && e < d ) { d = Math . max ( 0 , e ) ; a = q ; } }
if ( ! boucle ) { const e = sens > 0 ? L - s : s ; if ( e < d ) { d = e ; a = { s : sens > 0 ? L : 0 , p : 1.5 , bout : true } ; } }
const pas = v * Math . max ( 0.12 , Math . min ( 1 , d / 10 , 0.25 + parcouru / 8 ) ) * dt ;
if ( a && pas >= d ) {
capA = capEn ( s - 0.5 * sens , sens ) ;
s = w ( s + d * sens ) ; parcouru = 0 ; arret = a . bout ? null : a ; attente = duree = a . p ;
if ( a . bout ) sens = - sens ;
capB = capEn ( s + 0.5 * sens , sens ) ; while ( capB - capA > Math . PI ) capB -= 2 * Math . PI ; while ( capB - capA < - Math . PI ) capB += 2 * Math . PI ;
if ( Math . abs ( Math . abs ( capB - capA ) - Math . PI ) < 0.2 ) capB = capA + Math . PI ; // un demi-tour : toujours du même côté
} else { s = w ( s + pas * sens ) ; parcouru += pas ; cap = capEn ( s + 0.3 * sens , sens ) ; }
}
const p = surTrajet ( t , s ) ; let dx = p . dx * sens , dz = p . dz * sens ; const n = Math . hypot ( dx , dz ) || 1 ; dx /= n ; dz /= n ;
const f = bouts ? Math . min ( 1 , Math . min ( s , L - s ) / 5 ) : 1 ;
obj . position . set ( p . x - dz * decal * f , 0 , p . z + dx * decal * f ) ; obj . rotation . y = cap ;
centre . x = obj . position . x ; centre . z = obj . position . z ;
}
maj ( 0 ) ;
return { maj , centre } ;
}
// ---------------------------------------------------------------- la pose : où il y a de la place, et que la caméra voit
function grilleP ( L , pas = 6 ) {
const g = new Map ( ) , cle = ( i , j ) => ( i + 2048 ) * 4096 + j + 2048 ;
for ( const o of L ) { const k = cle ( Math . floor ( o [ 0 ] / pas ) , Math . floor ( o [ 1 ] / pas ) ) ; let c = g . get ( k ) ; if ( ! c ) g . set ( k , ( c = [ ] ) ) ; c . push ( o ) ; }
return ( x , z , r ) => { let d = Infinity ; for ( let i = Math . floor ( ( x - r ) / pas ) ; i <= Math . floor ( ( x + r ) / pas ) ; i ++ ) for ( let j = Math . floor ( ( z - r ) / pas ) ; j <= Math . floor ( ( z + r ) / pas ) ; j ++ ) { const c = g . get ( cle ( i , j ) ) ; if ( c ) for ( const o of c ) d = Math . min ( d , Math . hypot ( o [ 0 ] - x , o [ 1 ] - z ) ) ; } return d ; } ;
}
// Les segments qui séparent deux jardins : haies, routes, chemins, sentiers (un objet ne s'étend pas par-dessus).
function barrieres ( D ) {
const S = [ ] ;
const poly = ( p ) => { for ( let i = 1 ; i < p . length ; i ++ ) if ( Math . hypot ( p [ i ] [ 0 ] - p [ i - 1 ] [ 0 ] , p [ i ] [ 1 ] - p [ i - 1 ] [ 1 ] ) > 0.05 ) S . push ( [ p [ i - 1 ] , p [ i ] ] ) ; } ;
D . haies . forEach ( poly ) ; Object . values ( D . routes ) . forEach ( poly ) ; D . chemins . forEach ( poly ) ; D . sentiers . forEach ( poly ) ;
const coupe = ( [ a , b ] , [ c , d ] ) => {
const r = ( p , q , s ) => ( q [ 0 ] - p [ 0 ] ) * ( s [ 1 ] - p [ 1 ] ) - ( q [ 1 ] - p [ 1 ] ) * ( s [ 0 ] - p [ 0 ] ) ;
return r ( a , b , c ) * r ( a , b , d ) < 0 && r ( c , d , a ) * r ( c , d , b ) < 0 ;
} ;
return ( a , b ) => { const x0 = Math . min ( a [ 0 ] , b [ 0 ] ) , x1 = Math . max ( a [ 0 ] , b [ 0 ] ) , z0 = Math . min ( a [ 1 ] , b [ 1 ] ) , z1 = Math . max ( a [ 1 ] , b [ 1 ] ) ;
for ( const s of S ) { if ( Math . max ( s [ 0 ] [ 0 ] , s [ 1 ] [ 0 ] ) < x0 || Math . min ( s [ 0 ] [ 0 ] , s [ 1 ] [ 0 ] ) > x1 || Math . max ( s [ 0 ] [ 1 ] , s [ 1 ] [ 1 ] ) < z0 || Math . min ( s [ 0 ] [ 1 ] , s [ 1 ] [ 1 ] ) > z1 ) continue ; if ( coupe ( s , [ a , b ] ) ) return true ; } return false ; } ;
}
// Le repère d'une maison du plan (comme `maison()` de scene.js) : centre, rotation, Lu (le long de u), Lv.
function repere ( h ) {
const p = h . p . map ( ( [ x , z ] ) => new THREE . Vector2 ( x , z ) ) , c = p . reduce ( ( a , b ) => a . add ( b ) , new THREE . Vector2 ( ) ) . multiplyScalar ( 0.25 ) ;
const e1 = p [ 1 ] . clone ( ) . sub ( p [ 0 ] ) , e2 = p [ 2 ] . clone ( ) . sub ( p [ 1 ] ) , fw = new THREE . Vector2 ( Math . cos ( h . f ) , - Math . sin ( h . f ) ) ;
let u , Lu , Lv ;
if ( Math . abs ( e1 . clone ( ) . normalize ( ) . dot ( fw ) ) >= Math . abs ( e2 . clone ( ) . normalize ( ) . dot ( fw ) ) ) { u = e1 . clone ( ) . normalize ( ) ; Lu = e1 . length ( ) ; Lv = e2 . length ( ) ; }
else { u = e2 . clone ( ) . normalize ( ) ; Lu = e2 . length ( ) ; Lv = e1 . length ( ) ; }
const rot = Math . atan2 ( - u . y , u . x ) , cs = Math . cos ( rot ) , sn = Math . sin ( rot ) ;
const monde = ( lx , lz ) => [ c . x + lx * cs + lz * sn , c . y - lx * sn + lz * cs ] ;
// la façade que la caméra voit (normale la plus tournée vers +z, le sud de la planche) : n, t, demi-profondeur, largeur
const faces = [ [ 1 , 0 , Lu / 2 , Lv ] , [ - 1 , 0 , Lu / 2 , Lv ] , [ 0 , 1 , Lv / 2 , Lu ] , [ 0 , - 1 , Lv / 2 , Lu ] ] . map ( ( [ a , b , d , W ] ) => {
const n = [ a * cs + b * sn , - a * sn + b * cs ] ; return { n , t : [ - n [ 1 ] , n [ 0 ] ] , d , W } ;
} ) ;
const face = faces . reduce ( ( m , f ) => ( f . n [ 1 ] > m . n [ 1 ] ? f : m ) ) ;
return { h , c : { x : c . x , z : c . y } , rot , Lu , Lv , monde , face , aire : Lu * Lv } ;
}
// ---------------------------------------------------------------- les objets fixes (coordonnées locales, ouverture vers +z)
function abriBus ( ) {
const g = new THREE . Group ( ) , mp = lam ( COUL . poteau ) , toit = mesh ( boite ( 3.7 , 0.08 , 1.9 ) , lam ( COUL . zinc ) , 0 , 2.45 , - 0.2 , true ) ;
toit . rotation . x = - 0.12 ; g . add ( toit ) ;
for ( const x of [ 1.6 , - 1.6 ] ) g . add ( mesh ( cyl ( 0.06 , 2.5 , 6 ) , mp , x , 1.25 , - 0.85 , true ) ) ;
g . add ( mesh ( boite ( 3.2 , 1.7 , 0.05 ) , new THREE . MeshLambertMaterial ( { color : '#d4ebe6' , transparent : true , opacity : 0.55 , depthWrite : false , emissive : '#000000' } ) , 0 , 1.25 , - 0.88 ) ) ;
g . add ( banc ( 2.4 , lam ( COUL . planche ) , 0 , - 0.5 ) ) ;
// le poteau de l'arrêt : un disque de couleur, sans rien d'écrit
g . add ( mesh ( cyl ( 0.05 , 2.8 , 6 ) , mp , 2.3 , 1.4 , 0.4 ) , mesh ( cyl ( 0.34 , 0.06 , 18 ) . rotateX ( Math . PI / 2 ) , lam ( '#6f8fa8' ) , 2.3 , 2.7 , 0.4 ) ) ;
return g ;
}
function pointFraicheur ( geoP , couleurs ) {
const g = new THREE . Group ( ) , mp = lam ( COUL . poteau ) , bois = lam ( COUL . planche ) ;
for ( const [ x , z ] of [ [ 2.3 , 1.8 ] , [ 2.3 , - 1.8 ] , [ - 2.3 , 1.8 ] , [ - 2.3 , - 1.8 ] ] ) g . add ( mesh ( cyl ( 0.08 , 2.65 , 6 ) , mp , x , 1.32 , z , true ) ) ;
for ( const z of [ 1.8 , - 1.8 ] ) g . add ( mesh ( boite ( 5.1 , 0.14 , 0.14 ) , mp , 0 , 2.6 , z ) ) ;
// les lattes : une seule géométrie, leurs ombres font la fraîcheur
const lattes = [ ] ; for ( let i = 0 ; i < 10 ; i ++ ) lattes . push ( boite ( 0.12 , 0.06 , 4.1 ) . translate ( - 2.25 + i * 0.5 , 2.7 , 0 ) ) ;
g . add ( mesh ( mergeGeometries ( lattes ) , bois , 0 , 0 , 0 , true ) ) ;
g . add ( table ( 1.9 , 0.8 , bois , 0 , 0 ) ) ; g . add ( banc ( 1.9 , bois , 0 , 0.85 ) , banc ( 1.9 , bois , 0 , - 0.85 ) ) ;
// le bassin bas, de l'eau ; le brumisateur : une fine ligne et un voile de brume
g . add ( mesh ( new THREE . CylinderGeometry ( 1.0 , 1.1 , 0.45 , 20 ) , lam ( COUL . pierre ) , 3.7 , 0.22 , 0.4 , true ) ) ;
g . add ( mesh ( new THREE . CircleGeometry ( 0.86 , 20 ) . rotateX ( - Math . PI / 2 ) , lam ( COUL . eau ) , 3.7 , 0.46 , 0.4 ) ) ;
g . add ( mesh ( cyl ( 0.018 , 2.5 , 4 ) , lam ( '#dfe9ec' ) , 2.0 , 1.3 , - 1.6 ) ) ;
const brume = new THREE . Mesh ( new THREE . ConeGeometry ( 0.75 , 1.3 , 14 , 1 , true ) , new THREE . MeshLambertMaterial ( { color : '#f4f8fa' , transparent : true , opacity : 0.28 , depthWrite : false , emissive : '#000000' , side : THREE . DoubleSide } ) ) ;
brume . position . set ( 2.0 , 1.9 , - 1.6 ) ; g . add ( brume ) ;
g . add ( quilles ( geoP , [ [ - 0.5 , 0.85 , 'assis' ] , [ 0.55 , 0.85 , 'assis' ] , [ - 0.2 , - 0.85 , 'assis' ] , [ 3.0 , 1.6 , 'enfant' ] ] , couleurs ) ) ;
return g ;
}
// Le vélo de l'atelier, retourné sur sa selle et son guidon (roues en l'air).
function veloRetourne ( couleur ) {
const g = new THREE . Group ( ) , m = lam ( couleur ) ;
g . add ( mesh ( boite ( 1.15 , 0.08 , 0.08 ) , m , 0 , 0.62 , 0 ) ) ;
for ( const x of [ 0.62 , - 0.62 ] ) g . add ( mesh ( new THREE . TorusGeometry ( 0.32 , 0.04 , 5 , 14 ) , MAT . velo , x , 0.92 , 0 ) ) ;
g . add ( mesh ( boite ( 0.06 , 0.55 , 0.06 ) , m , 0.35 , 0.33 , 0 ) , mesh ( boite ( 0.06 , 0.55 , 0.06 ) , m , - 0.3 , 0.33 , 0 ) ) ;
g . add ( mesh ( boite ( 0.25 , 0.06 , 0.12 ) , MAT . velo , - 0.3 , 0.04 , 0 ) , mesh ( boite ( 0.06 , 0.06 , 0.5 ) , MAT . velo , 0.35 , 0.04 , 0 ) ) ;
return g ;
}
function atelier ( geoP , couleurs , couleurAuto ) {
const g = new THREE . Group ( ) , murs = lam ( '#c9b89a' ) ;
// le hangar, toit à deux pans (faîtage le long de x), la grande porte ouverte : un rectangle sombre
g . add ( mesh ( boite ( 7 , 3.0 , 5 ) , murs , 0 , 1.5 , - 2.0 , true ) ) ;
g . add ( mesh ( toit2 ( 7.6 , 5.6 , 1.5 ) , new THREE . MeshLambertMaterial ( { color : '#8a7b6a' , side : THREE . DoubleSide , emissive : '#000000' } ) , 0 , 3.0 , - 2.0 , true ) ) ;
g . add ( mesh ( boite ( 3.2 , 2.5 , 0.06 ) , lam ( COUL . sombre ) , - 1.2 , 1.25 , 0.52 ) ) ;
// dehors : l'établi, trois vélos retournés, la voiture ouverte sur la fosse
const et = new THREE . Group ( ) ; et . add ( mesh ( boite ( 2.0 , 0.08 , 0.7 ) , lam ( COUL . planche ) , 0 , 0.9 , 0 , true ) ) ;
for ( const [ a , b ] of [ [ 0.9 , 0.3 ] , [ 0.9 , - 0.3 ] , [ - 0.9 , 0.3 ] , [ - 0.9 , - 0.3 ] ] ) et . add ( mesh ( boite ( 0.07 , 0.88 , 0.07 ) , lam ( COUL . poteau ) , a , 0.44 , b ) ) ;
et . add ( mesh ( boite ( 0.22 , 0.18 , 0.2 ) , lam ( '#5f6a70' ) , 0.7 , 1.03 , 0 ) , mesh ( boite ( 0.5 , 0.05 , 0.12 ) , lam ( '#a9433a' ) , - 0.3 , 0.97 , 0.1 ) ) ;
et . position . set ( - 2.4 , 0 , 1.6 ) ; g . add ( et ) ;
[ [ '#c47f5a' , - 3.2 , 3.2 ] , [ '#6f8fa8' , - 1.7 , 3.5 ] , [ '#d3b45c' , - 0.3 , 3.0 ] ] . forEach ( ( [ c , x , z ] , i ) => { const v = veloRetourne ( c ) ; v . position . set ( x , 0 , z ) ; v . rotation . y = 0.3 - i * 0.35 ; g . add ( v ) ; } ) ;
g . add ( mesh ( boite ( 1.3 , 0.03 , 4.0 ) , lam ( '#2e2b28' ) , 2.4 , 0.02 , 2.6 ) ) ;
const auto = new THREE . Group ( ) , ma = lam ( couleurAuto ) ;
auto . add ( mesh ( boite ( 4.0 , 0.85 , 1.75 ) , ma , 0 , 0.75 , 0 , true ) , mesh ( boite ( 2.1 , 0.7 , 1.58 ) , ma , - 0.3 , 1.5 , 0 , true ) ) ;
for ( const [ x , z ] of [ [ 1.3 , 0.85 ] , [ 1.3 , - 0.85 ] , [ - 1.3 , 0.85 ] , [ - 1.3 , - 0.85 ] ] ) auto . add ( mesh ( cyl ( 0.34 , 0.2 , 10 ) . rotateX ( Math . PI / 2 ) , MAT . roue , x , 0.34 , z ) ) ;
const capot = mesh ( boite ( 1.1 , 0.05 , 1.6 ) , ma , 0 , 0 , 0 ) ; capot . geometry . translate ( - 0.55 , 0 , 0 ) ; capot . position . set ( 2.0 , 1.18 , 0 ) ; capot . rotation . z = 1.0 ; auto . add ( capot ) ;
auto . position . set ( 2.4 , 0.05 , 2.6 ) ; auto . rotation . y = - Math . PI / 2 ; g . add ( auto ) ;
g . add ( quilles ( geoP , [ [ - 2.4 , 2.3 ] , [ 1.0 , 3.6 ] , [ 3.6 , 3.1 ] ] , couleurs ) ) ;
return g ;
}
function conserverie ( geoP , couleurs ) {
const g = new THREE . Group ( ) ;
// le petit bâtiment, toit à un pan, cheminée courte, une porte
g . add ( mesh ( boite ( 5 , 3.0 , 3.4 ) , lam ( COUL . enduit ) , 0 , 1.5 , - 1.0 , true ) ) ;
const toit = mesh ( boite ( 5.5 , 0.1 , 4.0 ) , lam ( COUL . zinc ) , 0 , 3.25 , - 1.0 , true ) ; toit . rotation . x = 0.16 ; g . add ( toit ) ;
g . add ( mesh ( boite ( 0.5 , 1.0 , 0.5 ) , lam ( COUL . brique ) , 1.5 , 3.7 , - 1.9 , true ) ) ;
g . add ( mesh ( boite ( 1.0 , 2.1 , 0.06 ) , lam ( COUL . bois ) , - 1.6 , 1.05 , 0.72 ) ) ;
// l'étagère dehors, contre la façade, et les bocaux (petits cylindres clairs : une seule géométrie, instanciée)
const mp = lam ( COUL . poteau ) , bois = lam ( COUL . planche ) ;
for ( const x of [ - 0.3 , 1.9 ] ) g . add ( mesh ( boite ( 0.06 , 1.6 , 0.06 ) , mp , x , 0.8 , 0.95 ) ) ;
for ( const y of [ 0.75 , 1.3 ] ) g . add ( mesh ( boite ( 2.3 , 0.04 , 0.42 ) , bois , 0.8 , y , 0.92 ) ) ;
const pots = [ ] , CB = [ '#f3eee2' , '#e6c96a' , '#c8553d' , '#b8434f' , '#a9be7c' , '#d9893a' ] ;
for ( const y of [ 0.77 , 1.32 ] ) for ( let i = 0 ; i < 11 ; i ++ ) pots . push ( [ - 0.15 + i * 0.19 , y + 0.08 , 0.92 + ( i % 2 ? 0.08 : - 0.08 ) ] ) ;
const imB = new THREE . InstancedMesh ( cyl ( 0.065 , 0.16 , 8 ) , lam ( '#ffffff' ) , pots . length ) , M = new THREE . Matrix4 ( ) , col = new THREE . Color ( ) ;
pots . forEach ( ( [ x , y , z ] , i ) => { imB . setMatrixAt ( i , M . makeTranslation ( x , y , z ) ) ; imB . setColorAt ( i , col . set ( CB [ ( i * 7 ) % CB . length ] ) ) ; } ) ; imB . instanceColor . needsUpdate = true ; g . add ( imB ) ;
// les cagettes empilées
for ( const [ x , z , n ] of [ [ 3.0 , 0.8 , 3 ] , [ 3.0 , 0.15 , 2 ] , [ 3.6 , 0.5 , 2 ] ] ) for ( let k = 0 ; k < n ; k ++ ) g . add ( mesh ( boite ( 0.58 , 0.28 , 0.4 ) , MAT . caisse , x , 0.14 + k * 0.29 , z , k === 0 ) ) ;
g . add ( quilles ( geoP , [ [ - 0.9 , 1.5 ] ] , couleurs ) ) ;
return g ;
}
// L'atelier public de distillation (B6, revu le 03/11) : hors Alsace-Moselle, on ne distille pas chez soi (code rural
// L664-4 à L664-31, base de connaissances, entrée « Alambic ») ; l'alambic est donc un petit abri communal à part, ni dans
// ni contre une maison. Trois murs d'enduit ouverts vers +z, un toit de zinc à un pan ; dedans, le chaudron de cuivre sur
// son foyer de brique, le col de cygne vers le serpentin (un fût) ; dehors, des cagettes de fruits qui attendent.
function atelierDistillation ( ) {
// le toit ne couvre que le fond : vu d'en haut et du sud (la caméra), le chaudron de cuivre reste à découvert devant
const g = new THREE . Group ( ) , cu = lam ( COUL . cuivre ) , murs = lam ( COUL . enduit ) ;
g . add ( mesh ( boite ( 4.2 , 2.6 , 0.2 ) , murs , 0 , 1.3 , - 1.5 , true ) ) ;
for ( const x of [ 2.0 , - 2.0 ] ) g . add ( mesh ( boite ( 0.2 , 2.6 , 1.8 ) , murs , x , 1.3 , - 0.7 , true ) ) ;
const toit = mesh ( boite ( 4.8 , 0.1 , 2.4 ) , lam ( COUL . zinc ) , 0 , 2.85 , - 0.7 , true ) ; toit . rotation . x = 0.14 ; g . add ( toit ) ;
g . add ( mesh ( cyl ( 0.11 , 1.6 , 8 ) , lam ( COUL . sombre ) , - 1.2 , 3.3 , - 1.1 ) ) ; // le conduit du foyer
g . add ( mesh ( boite ( 1.3 , 0.6 , 1.3 ) , lam ( COUL . brique ) , - 0.6 , 0.3 , 0.8 , true ) ) ;
g . add ( mesh ( new THREE . SphereGeometry ( 0.68 , 14 , 10 ) . scale ( 1 , 0.85 , 1 ) , cu , - 0.6 , 1.1 , 0.8 , true ) ) ;
g . add ( mesh ( cyl ( 0.16 , 0.5 , 10 ) , cu , - 0.6 , 1.8 , 0.8 ) ) ;
g . add ( mesh ( new THREE . TorusGeometry ( 0.6 , 0.065 , 6 , 12 , Math . PI ) , cu , 0.0 , 2.02 , 0.8 ) ) ;
g . add ( mesh ( new THREE . CylinderGeometry ( 0.45 , 0.45 , 1.3 , 12 ) , lam ( COUL . bois ) , 0.65 , 0.65 , 0.8 , true ) ) ;
for ( const [ x , z , n ] of [ [ 2.8 , 1.2 , 2 ] , [ 2.8 , 0.6 , 1 ] , [ - 2.7 , 1.3 , 2 ] ] ) for ( let k = 0 ; k < n ; k ++ ) g . add ( mesh ( boite ( 0.58 , 0.28 , 0.4 ) , MAT . caisse , x , 0.14 + k * 0.29 , z , k === 0 ) ) ;
return g ;
}
// Le potager partagé (L × W, +z vers le sud) : des planches de légumes, la serre commune au fond à droite, la cabane à
// outils et le composteur à trois bacs à gauche, quatre jardiniers. La taille suit la place trouvée (20 × 12 m, sinon
// 16 × 10, sinon 13 × 8,5 : `objetsNouveaux`) ; la serre garde 8 × 3,8 m tant qu'elle tient.
function potagerCommun ( geoP , couleurs , verre , L = 20 , W = 12 ) {
const g = new THREE . Group ( ) , x0 = - L / 2 , z0 = - W / 2 ;
g . add ( mesh ( new THREE . PlaneGeometry ( L , W ) . rotateX ( - Math . PI / 2 ) , lam ( COUL . terre ) , 0 , 0.03 , 0 ) ) ;
const sL = Math . min ( 8 , L * 0.42 ) , sW = Math . min ( 3.8 , W * 0.32 ) ;
// les planches, des légumes (instanciés) : à droite de la colonne cabane-composteur, devant la serre
const terre = lam ( COUL . terreF ) , legs = [ ] , xa = x0 + 3.8 , xb = L / 2 - 0.7 , zs = [ ] ;
for ( let z = z0 + sW + 1.3 ; z <= W / 2 - 0.8 + 1e-6 ; z += 1.85 ) zs . push ( z ) ;
for ( const z of zs ) { g . add ( mesh ( boite ( xb - xa , 0.16 , 1.2 ) , terre , ( xa + xb ) / 2 , 0.1 , z ) ) ; for ( let x = xa + 0.4 ; x <= xb - 0.4 ; x += 0.75 ) for ( const dz of [ - 0.28 , 0.28 ] ) legs . push ( [ x + ( rnd ( x * 3 + z ) - 0.5 ) * 0.2 , z + dz ] ) ; }
const C = [ '#8aa35f' , '#b8714f' , '#9db36a' , '#cf9c52' , '#7d965a' , '#c9b05a' ] ;
const imL = new THREE . InstancedMesh ( new THREE . IcosahedronGeometry ( 1 , 0 ) , lam ( '#ffffff' ) , legs . length ) , M = new THREE . Matrix4 ( ) , col = new THREE . Color ( ) ;
legs . forEach ( ( [ x , z ] , i ) => { const r = 0.16 + rnd ( i * 3 ) * 0.08 ; imL . setMatrixAt ( i , M . makeScale ( r * 1.3 , r , r * 1.3 ) . setPosition ( x , 0.18 + r * 0.7 , z ) ) ; imL . setColorAt ( i , col . set ( C [ i % C . length ] ) ) ; } ) ;
imL . instanceColor . needsUpdate = true ; g . add ( imL ) ;
// la serre commune, en verre, toit à deux pans
const serre = new THREE . Group ( ) ; serre . position . set ( L / 2 - sL / 2 - 0.5 , 0 , z0 + sW / 2 + 0.4 ) ;
const caisse = mesh ( boite ( sL , 2.2 , sW ) , verre , 0 , 1.1 , 0 ) ; caisse . renderOrder = 1 ; serre . add ( caisse ) ;
const toitS = mesh ( toit2 ( sL , sW , 1.2 ) , verre , 0 , 2.2 , 0 ) ; toitS . renderOrder = 1 ; serre . add ( toitS ) ;
const bord = new THREE . LineBasicMaterial ( { color : '#86ada7' } ) ;
serre . add ( new THREE . LineSegments ( new THREE . EdgesGeometry ( caisse . geometry ) , bord ) . translateY ( 1.1 ) , new THREE . LineSegments ( new THREE . EdgesGeometry ( toitS . geometry , 20 ) , bord ) . translateY ( 2.2 ) ) ;
for ( let x = - sL / 2 + 1 ; x <= sL / 2 - 1 + 1e-6 ; x += 1.5 ) serre . add ( mesh ( new THREE . IcosahedronGeometry ( 0.3 , 0 ) . scale ( 1.2 , 0.9 , 1.2 ) , lam ( '#9db36a' ) , x , 0.85 , sW / 2 - 0.9 ) , mesh ( boite ( 1.2 , 0.6 , 0.6 ) , lam ( COUL . bois ) , x , 0.3 , sW / 2 - 0.9 ) ) ;
g . add ( serre ) ;
// la cabane à outils, le composteur à trois bacs
const cab = lam ( COUL . bois ) ; g . add ( mesh ( boite ( 2 , 2.0 , 2 ) , cab , x0 + 1.3 , 1.0 , z0 + 1.3 , true ) , mesh ( toit2 ( 2.3 , 2.4 , 0.7 ) , new THREE . MeshLambertMaterial ( { color : '#8a7b6a' , side : THREE . DoubleSide , emissive : '#000000' } ) , x0 + 1.3 , 2.0 , z0 + 1.3 , true ) ) ;
for ( let i = 0 ; i < 3 ; i ++ ) { const z = z0 + 3.4 + i * 1.08 ; g . add ( mesh ( boite ( 1.0 , 0.75 , 1.0 ) , lam ( COUL . poteau ) , x0 + 1.0 , 0.37 , z , true ) ) ; g . add ( mesh ( boite ( 0.86 , 0.04 , 0.86 ) , lam ( COUL . compost ) , x0 + 1.0 , 0.76 - i * 0.12 , z ) ) ; }
const zq = zs . length > 1 ? ( zs [ 0 ] + zs [ 1 ] ) / 2 : zs [ 0 ] + 0.9 ;
g . add ( quilles ( geoP , [ [ x0 + 2.6 , z0 + 3.0 ] , [ xa + ( xb - xa ) * 0.3 , zq ] , [ xa + ( xb - xa ) * 0.75 , zq ] , [ L / 2 - sL - 0.9 , z0 + 1.2 ] ] , couleurs ) ) ;
return g ;
}
// Une tiny house (local, longueur le long de x) : rendue par instances, voir `tinies()`.
function tinies ( L ) {
const g = new THREE . Group ( ) , n = L . length , M = new THREE . Matrix4 ( ) , Q = new THREE . Quaternion ( ) , V = new THREE . Vector3 ( ) , S = new THREE . Vector3 ( 1 , 1 , 1 ) , Y = new THREE . Vector3 ( 0 , 1 , 0 ) , col = new THREE . Color ( ) ;
const parts = [
[ boite ( 5.6 , 2.3 , 2.5 ) . translate ( 0 , 1.6 , 0 ) , lam ( '#ffffff' ) , true , ( i ) => DOUX [ i % DOUX . length ] ] ,
[ toit2 ( 6.1 , 2.95 , 1.05 ) . translate ( 0 , 2.75 , 0 ) , new THREE . MeshLambertMaterial ( { color : '#8f7d6a' , side : THREE . DoubleSide , emissive : '#000000' } ) , true ] ,
[ boite ( 0.9 , 1.9 , 0.06 ) . translate ( 1.2 , 1.4 , 1.27 ) , lam ( COUL . bois ) ] ,
[ boite ( 1.1 , 0.7 , 0.06 ) . translate ( - 1.3 , 1.8 , 1.27 ) , lam ( COUL . vitre ) ] ,
[ mergeGeometries ( [ [ 1.3 , 1.3 ] , [ 1.3 , - 1.3 ] , [ - 1.3 , 1.3 ] , [ - 1.3 , - 1.3 ] ] . map ( ( [ x , z ] ) => cyl ( 0.3 , 0.16 , 10 ) . rotateX ( Math . PI / 2 ) . translate ( x , 0.3 , z ) ) ) , MAT . roue ] ,
] ;
for ( const [ geo , m , ombre , couleur ] of parts ) {
const im = new THREE . InstancedMesh ( geo , m , n ) ; im . castShadow = ! ! ombre ; im . receiveShadow = true ;
L . forEach ( ( [ x , z , rot ] , i ) => { im . setMatrixAt ( i , M . compose ( V . set ( x , 0 , z ) , Q . setFromAxisAngle ( Y , rot ) , S ) ) ; if ( couleur ) im . setColorAt ( i , col . set ( couleur ( i ) ) ) ; } ) ;
if ( couleur ) im . instanceColor . needsUpdate = true ;
g . add ( im ) ;
}
return g ;
}
function four ( ) {
const g = new THREE . Group ( ) ;
g . add ( mesh ( boite ( 1.6 , 0.9 , 1.6 ) , lam ( COUL . pierre ) , 0 , 0.45 , 0 , true ) ) ;
g . add ( mesh ( new THREE . SphereGeometry ( 0.72 , 14 , 8 , 0 , Math . PI * 2 , 0 , Math . PI / 2 ) , lam ( COUL . tuile ) , 0 , 0.9 , 0 , true ) ) ;
g . add ( mesh ( boite ( 0.5 , 0.42 , 0.06 ) , lam ( COUL . sombre ) , 0 , 1.08 , 0.66 ) , mesh ( cyl ( 0.11 , 0.6 , 8 ) , lam ( COUL . brique ) , - 0.25 , 1.75 , - 0.2 ) ) ;
return g ;
}
function abriCargos ( ) {
const g = new THREE . Group ( ) , mp = lam ( COUL . poteau ) ;
for ( const [ x , z ] of [ [ 2.9 , 1.1 ] , [ 2.9 , - 1.1 ] , [ - 2.9 , 1.1 ] , [ - 2.9 , - 1.1 ] ] ) g . add ( mesh ( cyl ( 0.07 , 2.3 , 6 ) , mp , x , 1.15 , z , true ) ) ;
g . add ( mesh ( boite ( 6.4 , 0.12 , 2.8 ) , lam ( COUL . bois ) , 0 , 2.35 , 0 , true ) ) ;
[ '#c47f5a' , '#8aa36a' , '#6f8fa8' ] . forEach ( ( c , i ) => {
const v = veloCargo ( c ) ; v . children . splice ( v . children . length - 3 , 3 ) ; // garé : ni chargement, ni cycliste
v . position . set ( - 2.0 + i * 2.0 , 0 , 0 ) ; v . rotation . y = Math . PI / 2 + 0.55 ; g . add ( v ) ;
} ) ;
return g ;
}
function ruches ( n ) {
const g = new THREE . Group ( ) , M = new THREE . Matrix4 ( ) , col = new THREE . Color ( ) , C = [ '#e9dcb8' , '#cfdde3' , '#efe0a6' , '#e6c9b8' ] ;
const pos = Array . from ( { length : n } , ( _ , i ) => [ ( i - ( n - 1 ) / 2 ) * 1.6 , 0 ] ) ;
const parts = [ [ boite ( 0.52 , 0.46 , 0.42 ) . translate ( 0 , 0.58 , 0 ) , true ] , [ boite ( 0.62 , 0.06 , 0.52 ) . translate ( 0 , 0.84 , 0 ) , false , COUL . zinc ] ,
[ mergeGeometries ( [ [ 0.2 , 0.15 ] , [ 0.2 , - 0.15 ] , [ - 0.2 , 0.15 ] , [ - 0.2 , - 0.15 ] ] . map ( ( [ x , z ] ) => boite ( 0.05 , 0.36 , 0.05 ) . translate ( x , 0.18 , z ) ) ) , false , COUL . poteau ] , [ boite ( 0.3 , 0.04 , 0.03 ) . translate ( 0 , 0.39 , 0.22 ) , false , COUL . sombre ] ] ;
for ( const [ geo , couleurs , c ] of parts ) {
const im = new THREE . InstancedMesh ( geo , lam ( c || '#ffffff' ) , n ) ; im . castShadow = ! ! couleurs ;
pos . forEach ( ( [ x , z ] , i ) => { im . setMatrixAt ( i , M . makeTranslation ( x , 0 , z ) ) ; if ( couleurs ) im . setColorAt ( i , col . set ( C [ i % C . length ] ) ) ; } ) ;
if ( couleurs ) im . instanceColor . needsUpdate = true ; g . add ( im ) ;
}
return g ;
}
function chapiteau ( ) {
const g = new THREE . Group ( ) ;
g . add ( mesh ( new THREE . CylinderGeometry ( 4.2 , 4.2 , 2.3 , 18 ) , lam ( COUL . toile ) , 0 , 1.15 , 0 , true ) ) ;
g . add ( mesh ( new THREE . ConeGeometry ( 4.7 , 3.0 , 18 ) , lam ( '#b8434f' ) , 0 , 3.8 , 0 , true ) ) ;
g . add ( mesh ( cyl ( 0.06 , 1.2 , 5 ) , lam ( COUL . poteau ) , 0 , 5.6 , 0 ) , mesh ( new THREE . ConeGeometry ( 0.25 , 0.6 , 4 ) . rotateZ ( - Math . PI / 2 ) , lam ( '#e0b04a' ) , 0.3 , 5.95 , 0 ) ) ;
g . add ( mesh ( boite ( 1.8 , 2.0 , 0.08 ) , lam ( COUL . sombre ) , 0 , 1.0 , 4.17 ) ) ;
// la caravane : une boîte arrondie sur deux roues, un timon
const car = new THREE . Group ( ) ; car . position . set ( 7.4 , 0 , 1.5 ) ; car . rotation . y = - 0.4 ;
car . add ( mesh ( new THREE . CapsuleGeometry ( 0.95 , 2.6 , 4 , 12 ) . rotateZ ( Math . PI / 2 ) . scale ( 1 , 1 , 0.85 ) , lam ( '#e0c27a' ) , 0 , 1.45 , 0 , true ) ) ;
car . add ( mesh ( boite ( 2.2 , 0.4 , 0.05 ) , lam ( COUL . vitre ) , - 0.2 , 1.75 , 0.8 ) , mesh ( boite ( 0.6 , 1.2 , 0.05 ) , lam ( COUL . bois ) , 1.0 , 1.25 , 0.81 ) ) ;
for ( const z of [ 0.85 , - 0.85 ] ) car . add ( mesh ( cyl ( 0.38 , 0.16 , 12 ) . rotateX ( Math . PI / 2 ) , MAT . roue , 0 , 0.38 , z ) ) ;
car . add ( mesh ( boite ( 1.2 , 0.06 , 0.06 ) , MAT . velo , 2.75 , 0.55 , 0 ) ) ;
g . add ( car ) ;
return g ;
}
// ---------------------------------------------------------------- la pose
// ctx : le même que gestesDuTour, plus P (la grille d'occupation de gestes.js), maisons (les groupes des maisons du plan,
// par indice de D.maisons), tr (les routes en trajets), PAL, geoP, verre (le matériau de verre des serres), tour (le retour
// de gestesDuTour) et convoi ({ objs, centre }) : les objets du Tour deviennent cliquables ici, avec les nouveaux.
// Rend { anim, maj, cliquables: [{ o, fiche }], points: { id: { x, z, w } }, lumieres: { effet: [matériaux] },
// haieOuverte: { k, s0, s1 } | null (la haie qui tombe entre les deux maisons du jardin commun), laisses: [id] }.
export function objetsNouveaux ( { D , groupe , T , P , maisons , tr , PAL , geoP , verre , matsArbres , tour , convoi } ) {
const anim = [ ] , maj = [ ] , cliquables = [ ] , points = { } , lumieres = { } , laisses = [ ] , gens = PAL . gens ;
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
if ( arret ) {
const o = bus ( PAL . autos [ 1 ] ) ; groupe . add ( o ) ;
const r = roule ( o , tP , { v : 6 , decal : 1.9 , arrets : [ { s : arret . s , p : 6 } ] , depart : 0.15 } ) ;
maj . push ( r . maj ) ; relie ( [ o , ... arret . objs ] , 'quartier-bus' , 'bus' ) ; points . bus = r . centre ; points . arret = { x : arret . x , z : arret . z , w : 40 } ;
} 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' } ) ;
} 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' } ) ;
} 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 , choix } = best ; prises . add ( r . i ) ;
const g = tinies ( choix . map ( ( c ) => [ c . x , c . z , c . rot ] ) ) ; groupe . add ( g ) ;
choix . forEach ( ( c ) => occupe ( c . x , c . z , c . rot , 3.2 , 1.6 ) ) ;
// l'allée de gravier, de la maison à chaque tiny house ; la table commune au milieu
const gravier = lam ( '#d8cfbd' ) , objs = [ g ] ;
const fx = r . c . x + r . face . n [ 0 ] * ( r . face . d + 1 ) , fz = r . c . z + r . face . n [ 1 ] * ( r . face . d + 1 ) ;
for ( const c of choix ) { const L = Math . hypot ( c . x - fx , c . z - fz ) - 3 ; if ( L < 1 ) continue ; const a = mesh ( boite ( L , 0.04 , 0.9 ) , gravier , 0 , 0.03 , 0 ) ; a . position . set ( ( fx + c . x ) / 2 , 0.03 , ( fz + c . z ) / 2 ) ; a . rotation . y = Math . atan2 ( - ( c . z - fz ) , c . x - fx ) ; groupe . add ( a ) ; objs . push ( a ) ; }
const m = choix . reduce ( ( a , c ) => [ a [ 0 ] + c . x / choix . length , a [ 1 ] + c . z / choix . length ] , [ 0 , 0 ] ) ;
let tb = null ; for ( const [ x , z ] of autour ( ( m [ 0 ] + r . c . x ) / 2 , ( m [ 1 ] + r . c . z ) / 2 , 8 , 1 ) ) { const pl = emprise ( x , z , r . rot , 1.6 , 1.2 , 0.1 ) ; if ( pl >= 0.1 && ( ! tb || pl > tb . pl ) ) tb = { x , z , pl } ; }
if ( tb ) { const t = new THREE . Group ( ) ; t . add ( table ( 2.4 , 0.9 , lam ( COUL . planche ) , 0 , 0 ) , banc ( 2.4 , lam ( COUL . planche ) , 0 , 0.8 ) , banc ( 2.4 , lam ( COUL . planche ) , 0 , - 0.8 ) , quilles ( geoP , [ [ - 0.6 , 0.8 , 'assis' ] , [ 0.6 , - 0.8 , 'assis' ] , [ 1.9 , 0.2 ] ] , gens ) ) ; objs . push ( pose ( t , tb . x , tb . z , r . rot ) ) ; ajoute ( tb . x , tb . z , 1.8 ) ; }
relie ( objs , 'quartier-tiny' , 'tiny' , { x : ( m [ 0 ] * 2 + r . c . x ) / 3 , z : ( m [ 1 ] * 2 + r . c . z ) / 3 , w : 60 } ) ;
if ( maisons [ r . i ] ) cliquables . push ( { o : maisons [ r . i ] , fiche : 'quartier-tiny' } ) ;
} else laisses . push ( 'tiny' ) ;
}
// ---- B1. Les vélos cargos à prêter : un abri ouvert près de la place
{
const best = cherche ( place [ 0 ] , place [ 1 ] , 34 , 3.3 , 1.6 , 2.4 , { rots : [ 0 , 0.3 , - 0.3 , Math . PI / 2 ] } ) ;
if ( best ) { const o = pose ( abriCargos ( ) , best . x , best . z , best . rot ) ; occupe ( best . x , best . z , best . rot , 3.3 , 1.6 ) ; relie ( [ o ] , 'quartier-cargos' , 'cargos' , { x : best . x , z : best . z , w : 40 } ) ; }
else laisses . push ( 'cargos' ) ;
}
// ---- B2. La Rosalie : en boucle sur l'anneau, lentement
if ( tr . anneau ) {
const o = rosalie ( geoP , gens ) ; groupe . add ( o ) ;
// à 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 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 ) ;
const g = new THREE . Group ( ) , items = [ ] ;
g . add ( mesh ( new THREE . PlaneGeometry ( 7.6 , 6.6 ) . rotateX ( - Math . PI / 2 ) , lam ( COUL . paillis ) , - 4.2 , 0.04 , 0 ) ) ;
// la syntropie : trois étages plantés serré, au même moment
for ( let i = 0 ; i < 22 ; i ++ ) {
const etage = i < 4 ? 0 : i < 10 ? 1 : 2 , u = - 7.4 + rnd ( i * 3.3 ) * 6.4 , v = - 2.8 + rnd ( i * 5.7 ) * 5.6 , j = 0.85 + rnd ( i * 7.1 ) * 0.3 ;
const [ x , z ] = loc ( best . x , best . z , best . rot , u , v ) ;
items . push ( etage === 0 ? { x , z , H : 6.2 * j , W : 2.2 * j , forme : 'ovoïde' , couleur : teinte ( '#7f9f5c' , { } , 93000 + i ) , fruit : null , rot : rnd ( i ) * 6.28 }
: etage === 1 ? { x , z , H : 3.2 * j , W : 2.0 * j , forme : 'boule' , couleur : teinte ( '#94ad62' , { } , 93100 + i ) , fruit : null , rot : rnd ( i ) * 6.28 }
: { x , z , H : 1.2 * j , W : 1.3 * j , forme : 'buisson' , couleur : teinte ( '#87a35d' , { } , 93200 + i ) , fruit : null , rot : rnd ( i ) * 6.28 } ) ;
}
const arbresS = lot ( items , { couronne : matsArbres . couronne . clone ( ) , tronc : matsArbres . tronc . clone ( ) , fruit : matsArbres . fruit } , false ) ;
// le jardin punk : des herbes hautes (cônes fins), un vieux banc
const n = 150 , im = new THREE . InstancedMesh ( new THREE . ConeGeometry ( 0.06 , 1 , 4 ) . translate ( 0 , 0.5 , 0 ) , lam ( '#ffffff' ) , n ) , M = new THREE . Matrix4 ( ) , Q = new THREE . Quaternion ( ) , col = new THREE . Color ( ) , E = new THREE . Euler ( ) ;
const CH = [ '#b9b27a' , '#a9a670' , '#94ad62' , '#cbbf86' , '#8ea366' ] ;
for ( let i = 0 ; i < n ; i ++ ) { const h = 0.7 + rnd ( i * 2.3 ) * 0.9 ; Q . setFromEuler ( E . set ( ( rnd ( i * 4.1 ) - 0.5 ) * 0.5 , 0 , ( rnd ( i * 6.7 ) - 0.5 ) * 0.5 ) ) ; im . setMatrixAt ( i , M . compose ( new THREE . Vector3 ( 0.8 + rnd ( i * 1.9 ) * 7.0 , 0 , - 3 + rnd ( i * 3.7 ) * 6 ) , Q , new THREE . Vector3 ( 1 , h , 1 ) ) ) ; im . setColorAt ( i , col . set ( CH [ i % CH . length ] ) ) ; }
im . instanceColor . needsUpdate = true ; g . add ( im ) ;
const vb = new THREE . Group ( ) , mb = lam ( COUL . boisGris ) ; vb . add ( banc ( 1.6 , mb , 0 , 0 ) ) ; vb . add ( mesh ( boite ( 1.6 , 0.4 , 0.05 ) , mb , 0 , 0.7 , - 0.17 ) ) ; vb . position . set ( 4.5 , 0 , 1.5 ) ; vb . rotation . y = 0.2 ; g . add ( vb ) ;
pose ( g , best . x , best . z , best . rot ) ; groupe . add ( arbresS ) ; occupe ( best . x , best . z , best . rot , 8.4 , 3.6 ) ;
relie ( [ g , arbresS ] , 'vivant-syntropie' , 'syntropie' , { x : best . x , z : best . z , w : 44 } ) ;
} else laisses . push ( 'syntropie' ) ;
}
return { anim , maj , cliquables , points , lumieres , haieOuverte , laisses } ;
}
// 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 ] ; }