diff --git a/maquette/animaux.js b/maquette/animaux.js index 82e239b..50d68de 100644 --- a/maquette/animaux.js +++ b/maquette/animaux.js @@ -4,6 +4,7 @@ import * as THREE from 'three'; import { mergeGeometries } from 'three/addons/utils/BufferGeometryUtils.js'; import { rnd } from './vegetal.js'; +import { parcoursCanards } from './canards.ts'; const lam = (c) => new THREE.MeshLambertMaterial({ color: c, emissive: '#000000' }); const mesh = (geo, m, x = 0, y = 0, z = 0, ombre = true) => { const o = new THREE.Mesh(geo, m); o.position.set(x, y, z); o.castShadow = ombre; return o; }; @@ -188,10 +189,11 @@ export function vieAnimale(D, G2035) { const o = poule(i); o.position.set(x, 0, z); o.rotation.y = rot; basse.add(o); anim.push((t) => { const k = Math.sin(t * 2.2 + i * 1.7); o.rotation.z = k > 0.5 ? -0.5 : 0; o.position.x = x + Math.sin(t * 0.25 + i) * 0.4; }); }); - const { c, r, n } = D.canards; - for (let i = 0; i < n; i++) { + // les canards nagent sur le parcours de canards.ts ; `c` (le centre de la mare des données) reste celui du vol des oiseaux + const { c } = D.canards, nage = parcoursCanards(D); + for (let i = 0; i < nage.n; i++) { const o = canard(); mare.add(o); - anim.push((t) => { const a = t * 0.12 + (i / n) * Math.PI * 2, rr = r * (0.55 + 0.35 * Math.sin(i * 1.7)); o.position.set(c[0] + Math.cos(a) * rr, 0.05, c[1] + Math.sin(a) * rr); o.rotation.y = -a - Math.PI / 2; }); + anim.push((t) => { const p = nage.pos(i, t); o.position.set(p.x, 0.05, p.z); o.rotation.y = p.rot; }); } const centres = [[c[0], c[1]], [100, -40]]; for (let i = 0; i < 9; i++) { diff --git a/maquette/canards.ts b/maquette/canards.ts new file mode 100644 index 0000000..7d633f0 --- /dev/null +++ b/maquette/canards.ts @@ -0,0 +1,33 @@ +// Les canards de la mare (LOT Q-bords-canards, 16/11 : « les canards de la mare ne sont pas pile sur l'eau »). Fichier pur +// (aucun three) : animaux.js pose les six corps, ce fichier dit où ils nagent à l'instant t. + +type Pt = [number, number]; +export type DonneesCanards = { canards: { c: Pt; r: number; n: number }; mare: Pt[] }; + +/** + * Le contour du corps d'un canard, au sol, dans son repère (m) : x vers le bec, z sur le côté (canard() d'animaux.js : le corps, + * une boule de 0,2 m étirée × 1,5 en x et × 1 en z ; la tête de 0,1 m à x = 0,26 ; le bec jusqu'à x = 0,43). + */ +export const CORPS: Pt[] = [ + ...Array.from({ length: 12 }, (_, k) => [0.3 * Math.cos((k / 12) * 2 * Math.PI), 0.2 * Math.sin((k / 12) * 2 * Math.PI)] as Pt), + [0.36, 0], [0.26, 0.1], [0.26, -0.1], [0.43, 0.03], [0.43, -0.03], +]; + +/** Le parcours des canards : leur nombre, et la position (x, z) et l'orientation (rotation.y) du canard `i` à l'instant `t` (s). */ +export function parcoursCanards(D: DonneesCanards): { n: number; pos: (i: number, t: number) => { x: number; z: number; rot: number } } { + const { c, r, n } = D.canards; + return { + n, + pos(i, t) { + const a = t * 0.12 + (i / n) * Math.PI * 2, rr = r * (0.55 + 0.35 * Math.sin(i * 1.7)); + return { x: c[0] + Math.cos(a) * rr, z: c[1] + Math.sin(a) * rr, rot: -a - Math.PI / 2 }; + }, + }; +} + +/** Les points du contour du corps, au sol, pour un canard posé en (x, z) et tourné de `rot` (rotation.y de three). */ +export function corpsAuSol(p: { x: number; z: number; rot: number }): Pt[] { + const c = Math.cos(p.rot), s = Math.sin(p.rot); + // rotation.y de three : l'axe x local va en (cos, 0, −sin), l'axe z local en (sin, 0, cos) + return CORPS.map(([u, v]) => [p.x + u * c + v * s, p.z - u * s + v * c]); +} diff --git a/scripts/banc-bords.mjs b/scripts/banc-bords.mjs new file mode 100644 index 0000000..bf9f4d0 --- /dev/null +++ b/scripts/banc-bords.mjs @@ -0,0 +1,212 @@ +// Banc du LOT Q-bords-canards (16/11) : « on ne voit plus le bord de la maquette, à aucun zoom ni aucune rotation ». +// node scripts/banc-bords.mjs