Skip to content

Official Codebase of 3DCodeVerse

Python

scene lib: makeMeadow reads the scene's one wind through grass.windOf — a number, dir or direction all move it

gaoypeng6fa1b4e59b2b
diff --git a/harness/codeverse3d/languages/scene_threejs/starter/src/lib/grass.js b/harness/codeverse3d/languages/scene_threejs/starter/src/lib/grass.js
index 44d7c78b..5096153d 100644
--- a/harness/codeverse3d/languages/scene_threejs/starter/src/lib/grass.js
+++ b/harness/codeverse3d/languages/scene_threejs/starter/src/lib/grass.js
@@ -103,7 +103,8 @@ export function makeGrass(opts = {}) {
}
/**
- * Read the `wind` option in either of its two spellings.
+ * Read the `wind` option in either of its two spellings: a number
+ * (strength) or {dir (alias `direction`): [x,z] or {x,y}, strength, speed}.
*
* Exported because one scene's wind has to move its meadow,
* its reeds and its trees as ONE wind: a library that
@@ -112,7 +113,7 @@ export function makeGrass(opts = {}) {
*/
export function windOf(w) {
const o = (w && typeof w === 'object') ? w : { strength: w };
- const d = o.dir;
+ const d = o.dir ?? o.direction;
const dir = new THREE.Vector2(
d ? (d.x === undefined ? d[0] : d.x) : 1,
d ? (d.y === undefined ? d[1] : d.y) : 0.45);
diff --git a/harness/codeverse3d/languages/scene_threejs/starter/src/lib/meadow.js b/harness/codeverse3d/languages/scene_threejs/starter/src/lib/meadow.js
index 8c9d4e8c..fdfb1c74 100644
--- a/harness/codeverse3d/languages/scene_threejs/starter/src/lib/meadow.js
+++ b/harness/codeverse3d/languages/scene_threejs/starter/src/lib/meadow.js
@@ -7,8 +7,10 @@
* Moving directional, spot and point-light shadows share that deformation.
*
* makeMeadow({size:[10,10], density:700, height:.38, seed:12, heightAt,
- * mask, wind:{direction:[1,.3],strength:.35,speed:1.2}, dry:.12,
+ * mask, wind:{dir:[1,.3],strength:1,speed:1}, dry:.12,
* shadows:true, ground:true, diversity:.85, seedHeads:.003}) -> Group; userData.update(t), dispose().
+ * wind is grass.js's `windOf`: a number (strength) or {dir|direction, strength, speed},
+ * so one wind moves the meadow, grass and trees alike (strength 1 = breeze).
* density = blades/m² before the mask; maxBlades bounds memory and triangles.
* mask(x,z) -> 0..1 and heightAt(x,z) are LOCAL coordinates. A mask of 0
* leaves soil, a mask of 1 grows all blades. diversity (0..1) blends between
@@ -17,6 +19,7 @@
*/
import * as THREE from 'three';
import { attachDisposal, snapshotResources } from './lifecycle.js';
+import { windOf } from './grass.js';
import { fbm2, mulberry32 } from './noise.js';
import { patchStandard, shadowLike, tickShaders } from './shader.js';
@@ -237,16 +240,14 @@ export function makeMeadow(opts = {}) {
const seedHeads = finite(opts.seedHeads, .003, 0, .05, 'seedHeads');
const maxBlades = Math.floor(finite(opts.maxBlades, 100000, 1, 300000, 'maxBlades'));
const rows = Math.floor(finite(opts.segments, 5, 3, 12, 'segments'));
- const wind = opts.wind ?? {};
- const strength = finite(wind.strength, .5, 0, 3, 'wind.strength');
- const speed = finite(wind.speed, 1.2, 0, 10, 'wind.speed');
- const direction = wind.direction ?? [1, .3];
- if (!Array.isArray(direction) || direction.length !== 2 || !direction.every(Number.isFinite)) {
- throw new TypeError('makeMeadow: wind.direction must be [x,z] finite numbers');
+ const wind = windOf(opts.wind);
+ const strength = finite(wind.amp, .5, 0, 3, 'wind.strength');
+ // The meadow's own gust clock runs 1.2x the shared wind's.
+ const speed = finite(wind.speed * 1.2, 1.2, 0, 10, 'wind.speed');
+ const dir = wind.dir;
+ if (!Number.isFinite(dir.x) || !Number.isFinite(dir.y)) {
+ throw new TypeError('makeMeadow: wind direction must be [x,z] finite numbers');
}
- const dir = new THREE.Vector2(...direction);
- if (dir.lengthSq() < 1e-12) dir.set(1, 0);
- dir.normalize();
const heightAt = opts.heightAt ?? (() => 0), mask = opts.mask ?? (() => 1);
if (typeof heightAt !== 'function' || typeof mask !== 'function') {
throw new TypeError('makeMeadow: heightAt and mask must be functions');
diff --git a/harness/codeverse3d/prompts/scene_threejs/effects_catalog.md b/harness/codeverse3d/prompts/scene_threejs/effects_catalog.md
index 6ed0e446..2bdc4b32 100644
--- a/harness/codeverse3d/prompts/scene_threejs/effects_catalog.md
+++ b/harness/codeverse3d/prompts/scene_threejs/effects_catalog.md
@@ -25,7 +25,7 @@ says `import { makeGrass } from '../lib/grass.js';`, `src/scene.js` says
| thick broken ice with actual open fissures | `makeFracturedIce({ size: [8,6], thickness: 0.28, crackDensity: 0.65, frost: 0.35, seed })` — `lib/ice.js`; closed floes, bevels, internal air and local optical thickness. Nominal top is y=0. `userData.sampleHeight(x,z)` returns local top height or null in a gap. Supply an opaque lakebed/water backing: transparent volumes are not recursively refracted. |
| dunes, wind ripples, sand grains | `makeSandTerrain({ size: [60, 60], duneHeight: 3, duneSpacing: 18, windDirection: [1, 0.3], seed })` — `lib/sand.js`; Group with `userData.sampleHeight(x, z)` and `userData.update(t, dt)`. Sample height for every prop. |
| a close-view fractured rock or a talus field | `makeRock({ type: 'sandstone', size: [2, 1.5, 2], seed, moisture: 0.2 })` · `makeRockField` — `lib/rock.js`; types sandstone / granite / basalt; closed geometry, stratification and weathering. Rock rests at local y≈0; place using terrain height. |
-| close-view grass with folded blades and flowing wind | `makeMeadow({ size: [8, 8], height: 0.3, density: 900, heightAt, mask, seed, wind: { direction: [1, 0.3], strength: 0.6, speed: 1 } })` — `lib/meadow.js`; mask(x,z) is 0..1 coverage; Group with `userData.update(t, dt)`. Set `ground: false` over an existing terrain. Fit the sun shadow frustum tightly; blades need millimetre-scale shadow texels. |
+| close-view grass with folded blades and flowing wind | `makeMeadow({ size: [8, 8], height: 0.3, density: 900, heightAt, mask, seed, wind: { dir: [1, 0.3], strength: 1.2, speed: 1 } })` — `lib/meadow.js`; its wind is read by grass.js's `windOf`, so one wind object moves meadow, grass and trees alike; mask(x,z) is 0..1 coverage; Group with `userData.update(t, dt)`. Set `ground: false` over an existing terrain. Fit the sun shadow frustum tightly; blades need millimetre-scale shadow texels. |
| a grassy surface | `makeGrass({ extent, density, height, heightAt, patchy })` — `lib/grass.js` |
| a complete near/middle-distance tree or shrub | `makeTree({ species: 'oak', height: 6, crownRadius: 2.5, leafDensity: 1, seed, wind: { dir: [1,0.3], strength: 0.5, speed: 1 } })` · `makeShrub` — `lib/tree.js`; oak/birch/willow, connected branches, individual leaves and matching moving shadows. Root at y=0, actual envelope in `userData.bounds`. A default tree is heavy geometry. `leafSegments: 4` reduces per-leaf geometry while preserving crown density; species defaults are 10–16 for close views. Also lower `opts.maxLeaves`/`opts.leafDensity`, or use distant imposters when leaves are unresolved. |
| A CROWN OF LEAVES — every broadleaf tree, hedge and bush | `makeCanopy({ crowns: [{position, radius, height}] — or [{position, size:[x,y,z]}] for a mass that is not a ball, which is how a HEDGE is built — color, hue, wind })` — `lib/canopy.js`. NEVER a displaced sphere: see the rule at the end. |
diff --git a/harness/examples/graphics_lab/scenes/cloud_volume.js b/harness/examples/graphics_lab/scenes/cloud_volume.js
index 5f4879f2..a29b0d5f 100644
--- a/harness/examples/graphics_lab/scenes/cloud_volume.js
+++ b/harness/examples/graphics_lab/scenes/cloud_volume.js
@@ -80,7 +80,7 @@ export function createScene() {
size: [160, 130], density: 8, maxBlades: 70000, height: .34,
seed: 63, color: 0x596b35, dry: .15, ground: false,
heightAt, mask: (x, z) => THREE.MathUtils.smoothstep(heightAt(x, z), .4, 2),
- wind: { direction: [1, .2], strength: .45, speed: 1.0 },
+ wind: { dir: [1, .2], strength: .9, speed: 1 / 1.2 },
});
scene.add(grass);
for (let i = 0; i < 17; i++) {
diff --git a/harness/examples/graphics_lab/scenes/meadow.js b/harness/examples/graphics_lab/scenes/meadow.js
index 2b0b6296..768d6392 100644
--- a/harness/examples/graphics_lab/scenes/meadow.js
+++ b/harness/examples/graphics_lab/scenes/meadow.js
@@ -20,7 +20,7 @@ export function createScene() {
scene.userData.grade={contrast:1.03,saturation:.93,warmth:.01};
const heightAt=(x,z)=>.12*Math.sin(x*.45)+.09*Math.cos(z*.48)
+.16*Math.sin(z*.19+x*.17) + 2.2*Math.exp(-Math.pow((z+14)/8,2));
- const wind={direction:[1,.4],strength:.46,speed:1.15};
+ const wind={dir:[1,.4],strength:.92,speed:1.15/1.2};
const field=makeMeadow({size:[14,14],density:1650,maxBlades:145000,segments:4,
height:.32,bladeWidth:.012,seed:41,dry:.065,heightAt,
color:0x537e2c,wind});
diff --git a/harness/examples/graphics_lab/scenes/rain_shelter.js b/harness/examples/graphics_lab/scenes/rain_shelter.js
index 23fd12d7..2e2861be 100644
--- a/harness/examples/graphics_lab/scenes/rain_shelter.js
+++ b/harness/examples/graphics_lab/scenes/rain_shelter.js
@@ -118,7 +118,7 @@ export function createScene() {
bladeWidth:.012,segments:5,seed:83,color:0x486032,dry:.14,ground:false,seedHeads:.001,
heightAt,mask:(x,z)=>smooth(.78,1.18,Math.hypot(x/10,(z+1)/11.8))
*(.40+.6*smooth(-.15,.16,fbm2(x*.32,z*.32,{seed:85}))),
- wind:{direction:[.65,.3],strength:.18,speed:.7}}));
+ wind:{dir:[.65,.3],strength:.36,speed:.7/1.2}}));
// A close strip has enough short blades to read as turf at eye level.
// Sampling converts its local patch coordinates back to the terrain frame.
const turf=makeMeadow({size:[16,16],height:.13,density:3000,maxBlades:300000,
@@ -126,7 +126,7 @@ export function createScene() {
heightAt:(x,z)=>heightAt(x+5,z+8),
mask:(x,z)=>smooth(.83,1.08,Math.hypot((x+5)/10,(z+9)/11.8))
*(.5+.5*smooth(-.16,.2,fbm2((x+5)*.32,(z+8)*.32,{seed:85}))),
- wind:{direction:[.65,.3],strength:.10,speed:.7}});
+ wind:{dir:[.65,.3],strength:.20,speed:.7/1.2}});
turf.position.set(5,0,8);effect(turf);
for(let i=0;i<18;i++){
const angle=2.2+i*2.39996,r=14+rand()*16,x=Math.cos(angle)*r,z=Math.sin(angle)*r-4;
diff --git a/harness/examples/graphics_lab/scenes/waterfall.js b/harness/examples/graphics_lab/scenes/waterfall.js
index bd77e10d..492da5ee 100644
--- a/harness/examples/graphics_lab/scenes/waterfall.js
+++ b/harness/examples/graphics_lab/scenes/waterfall.js
@@ -166,13 +166,13 @@ export function createScene() {
if(Math.abs(Math.abs(x)-1.52)<.42&&z<-1&&z>-3.1)return 0;
for(const rock of stones)mask*=smooth(rock.r*.45,rock.r,Math.hypot(x-rock.x,z-rock.z));
return mask;
- },wind:{direction:[1,.4],strength:.28,speed:.7}});
+ },wind:{dir:[1,.4],strength:.56,speed:.7/1.2}});
scene.add(meadow);
const distantGrass=makeMeadow({size:[42,47],height:.22,density:100,maxBlades:50000,segments:3,seed:21,
color:0x526332,bladeWidth:.018,dry:.16,ground:false,seedHeads:0,heightAt,
mask:(x,z)=>smooth(.83,1,Math.max(Math.abs(x)/8.5,Math.abs(z)/11.5))*smooth(.10,.9,
closest(x,z,z<-.3?upperSamples:lowerSamples).offset),
- wind:{direction:[1,.4],strength:.24,speed:.7}});
+ wind:{dir:[1,.4],strength:.48,speed:.7/1.2}});
scene.add(distantGrass);
const plants=[];
for(const [species,x,z,h,r,seed] of [