3D engine that AI agents drive
Merge branch 'worktree-agent-ab442205ab2b427cb' into feat/scene-kits
Nguyen Xuan An6e6a240653d8
diff --cc .gitignoreindex 85fc6d88,0559ee1a..8bd40bd5--- a/.gitignore+++ b/.gitignore@@@ -18,8 -18,7 +18,9 @@@ public/mesh-query.mpublic/primitives.mdpublic/shrinkwrap.mdpublic/spume.md+public/retarget.md+public/vehicle.md+ public/vegetation.mdpublic/scene-graph.mdpublic/modeling.mdpublic/animation-curves.mddiff --cc README.mdindex 349b418f,feca4992..a3354811--- a/README.md+++ b/README.md@@@ -209,10 -209,8 +209,11 @@@ The source [shrinkwrap addon](docs/shriCompatible results can become relative GPU morph targets, so animation reuses the computed shape instead of repeating the vertex queries every frame.The source [Spume addon](docs/spume.md) plays back liquid baked by the [Spume](https://github.com/codepawl/spume) GPU solver, with whitewater, through `renderer.replaceParts`.+ The source [Vegetation addon](docs/vegetation.md) grows seeded trees with real branches and leaf cards, grass, Poisson-disk scattering on terrain and distance level of detail.The solver runs offline; the browser only reads the compact cache.+The source [retarget addon](docs/retarget.md) transfers humanoid clips between rigs (Mixamo, VRM, Unreal, Rigify names) and offsets crowds deterministically. Mixamo files need the owner's Adobe login to download.++The source [vehicle addon](docs/vehicle.md) drives wheeled vehicles along a path deterministically: wheel spin, steering, body roll and pitch, and ground following, for parts, scene-graph nodes or imported GLBs.The current source adds [surface attachments](docs/surface-attachment.md) for rigid accessories following a selected triangle through morphing and skinning.The retained frame uses world-space clearance and samples three bound vertices without rebuilding a BVH every frame.diff --cc docs/guide.mdindex 97ad1b1e,c3f156aa..0c07fc8d--- a/docs/guide.md+++ b/docs/guide.md@@@ -189,18 -174,16 +189,28 @@@ The [retarget contract](/retarget.md) cThe [Spume contract](/spume.md) covers the cache format, whitewater options, placement and measured cost.The scene must stay rigid and untextured while frames are replaced.+## Wheeled vehicles++`67js/addons/vehicle` is in the current source and not yet published. It drives a car or truck along a path with deterministic, physics-free animation.++1. Describe the vehicle with `createVehicleRig({ parts })`; wheels are found by name and geometry. Check `rig.wheels` or `findWheelCandidates(names)`.+2. Build a drive with `driveAlongPath(rig, points, { cruiseSpeed, groundHeight })`.+3. Each frame, call `applyVehiclePoseToParts(rig, drive.sample(seconds))` and then `renderer.updateParts(parts)`.++Wheel spin, front-wheel steering, roll, pitch and ground following come from the path.+Scene-graph nodes and imported GLBs use `applyVehiclePoseToSceneGraph` and `applyVehiclePoseToAsset`.+The [vehicle contract](/vehicle.md) lists conventions, options and limits.++ ## Trees and grass++ `67js/addons/vegetation` is in the current source and not yet published. It grows seeded trees with real branches and leaf cards, grass and flowers.++ 1. Scatter with `scatterVegetation({ area, density, terrainHeight, slopeLimit, exclusion, mix, leaves })`.+ 2. Pick detail per camera with `selectLevels(forest.instances, eye)`.+ 3. Pass `view.parts` to `Renderer67` and rebuild when `view.changed` is true.+-Use `leaves: 'mesh'` until the renderer honors alpha masks. The [Vegetation contract](/vegetation.md) lists species, triangle budgets and limits.++Cards (`leaves: 'cards'`, the default) use alpha-masked, double-sided textures; `'mesh'` leaves cost more triangles but sway with the `foliage` wind. The [Vegetation contract](/vegetation.md) lists species, triangle budgets and limits.+## Retained surface attachments`createSurfaceAttachment` is introduced in `0.4.1`. Published npm `0.4.0` does not include this addon.diff --cc docs/vegetation.mdindex 00000000,212dcbf1..35f58ffcmode 000000,100644..100644--- a/docs/vegetation.md+++ b/docs/vegetation.md@@@ -1,0 -1,99 +1,99 @@@+ # Vegetation++ `67js/addons/vegetation` grows seeded trees, bushes and grass, scatters them on terrain and switches detail by distance.+ It is in the current source and not yet published. Everything returns plain renderer parts: geometry, a matrix and a material.++ ```js+ import { Renderer67 } from '67js';+ import { scatterVegetation, selectLevels } from '67js/addons/vegetation';++ const forest = scatterVegetation({+ area: { minX: -40, maxX: 40, minZ: -40, maxZ: 40 },+ density: 0.016,+ terrainHeight: (x, z) => Math.sin(x * 0.1) * 1.5,+ slopeLimit: 30,+ exclusion: (x, z) => Math.hypot(x, z) < 8,+ mix: { broadleaf: 3, birch: 1.5, conifer: 2, bush: 2.5 },+ leaves: 'cards',+ seed: 11,+ });+ const view = selectLevels(forest.instances, camera.eye, { cullDistance: 120 });+ const renderer = new Renderer67(canvas, [terrain, ...view.parts], options);+ ```++ ## Trees++ `createTree(species | { species, height, leaves }, seed)` grows one tree. Species: `broadleaf`, `birch`, `conifer`, `palm`, `bush`.+ The same species and seed always give the same tree.++ The skeleton is a parametric recursive branching model: each generation has a length, wander, tropism (up or droop), taper and child spread.+ It was chosen over space colonization because a species is a short readable preset, the cost is known before growing, and conifer whorls and palm fronds fit the same code.+ Branches are swept tubes with parallel-transported rings, a taper, a root flare below the ground line and bark UVs (`u` around, `v` along, one tile per 0.6 m).+ Leaves sit on terminal twigs, face outward and up with jitter, and carry vertex colors that darken toward the crown center, so the canopy has depth.+ Shading normals blend toward the crown, so a flat card lights like part of a rounded crown.++ The tree has three levels of detail, each listing parts with a `role`, `geometry`, `material` and `tintable` flag:++ | Level | Content | Default switch distance |+ | --- | --- | --- |+ | 0 | Full skeleton, every leaf site | up to 38 m |+ | 1 | Twigs dropped, fewer sides, one third of the leaves 1.7 times larger | 38 to 95 m |+ | 2 | Trunk and main limbs, crown as merged clumps (low-poly blobs or crossed cards) | beyond 95 m |++ Measured triangle counts for seed 4 (level 0 / 1 / 2):++ | Species | `cards` | `mesh` |+ | --- | --- | --- |+ | broadleaf | 7.4k / 2.4k / 0.7k | 16.0k / 5.3k / 3.0k |+ | birch | 10.7k / 3.3k / 0.8k | 21.9k / 7.0k / 2.8k |+ | conifer | 26.1k / 7.2k / 2.3k | 63.9k / 19.8k / 3.4k |+ | palm | 6.4k / 1.9k / 1.1k | 11.8k / 3.7k / 2.9k |+ | bush | 4.7k / 1.7k / 0.5k | 10.9k / 3.7k / 1.9k |++ ## Leaves: cards or mesh++ `leaves: 'cards'` (default) uses a procedural RGBA leaf texture (`material.map`) on crossed, slightly curved cards with `alphaMode: 'mask'`, `alphaCutoff: 0.5` and `doubleSided: true`.-Until the renderer honors alpha masking, cards draw as opaque quads: use `leaves: 'mesh'` there.++Cards rely on the renderer's alpha masking with alpha-to-coverage under MSAA; with `samples: 1` their edges fall back to a hard cutout.+ Cards also carry both faces in the geometry, so they stay visible with back-face culling. Once `doubleSided` is honored, that duplicate costs triangles you can drop.+ `leaves: 'mesh'` builds real leaf silhouettes (ovate, fir spray, palm leaflet) as folded, drooping meshes with the `foliage` tag. It needs no alpha support and costs about twice the triangles.++ Wind: the vertex shader sways only the `foliage` and `grass` tags, by local height. Mesh leaves and grass blades therefore sway, and bark (a standard material) stays still.+ Textured materials must use a standard tag, so `cards` do not sway yet. A small shader hook that reads the tag for textured materials would add it.++ ## Grass and flowers++ `createGrassClump({ blades, height, radius, style, seed })` builds `blades` (curved tapered blades with the `grass` tag, level 1 has half the blades) or `cards` (three crossed alpha cards).+ `createFlowerPatch({ flowers, height, color, seed })` builds stems, six petals and a center; color lives in vertex colors.+ `createGrassField(options)` is `scatterVegetation` with a grass and flower mix at 2.5 clumps per square meter.++ ## Scattering++ `scatterVegetation({ area, density, terrainHeight, slopeLimit, exclusion, seed, mix, variants, leaves, scale, spacing })`:++ - Poisson-disk spacing (Bridson with restarts, so exclusion zones cannot strand regions). `density` is instances per square meter; spacing defaults to `sqrt(0.6 / density)`.+ - `slopeLimit` is in degrees, measured from `terrainHeight` over a 1.2 m span. `exclusion(x, z)` returns true to keep a spot clear.+ - `mix` weighs species (`broadleaf`, `birch`, `conifer`, `palm`, `bush`, `grass`, `flowers`); low-frequency noise groups species into stands.+ - `variants` (default 3) variants per species are shared by every instance, so the renderer batches each part by geometry identity. Instances differ by yaw, scale and tint.++ It returns `{ instances, parts, variants, counts }`; `parts` shows every instance at level 0.++ ## Level of detail++ `selectLevels(instances, eye, { distanceScale, hysteresis, cullDistance })` sets each instance's level from its distance to `eye`.+ A level changes only after the distance passes its threshold by `hysteresis` (default 0.12), so instances on a boundary do not flicker.+ It returns `{ parts, changed, levelCounts, culled, triangles }`. Part objects are cached per instance and level, so unchanged instances keep their identity.+ When `changed` is true, build a new renderer from the new parts. Grass switches at 24 m; set `cullDistance` to drop far instances.++ `vegetationParts(variant, matrix, level, name)` places one tree or clump yourself.++ ## Measured++ On the demo clearing (125 trees and bushes, 1,941 grass clumps and 129 flower patches, camera at the clearing edge), headless Chrome with GPU:+ `mesh` leaves with level of detail draw 2.28M triangles in 65 draws (3.78M without level of detail); `cards` draw 1.15M. Building the scene takes about 1 s; a frame takes under 0.2 s.+ Meshes and textures are built in plain JavaScript, so tests run in Node.++ ## Limits++ - Cards need the renderer's alpha mask to look right, and do not sway under the current shader.+ - Level changes pop; there is no cross-fade. Level 2 crowns are blobs or crossed cards, not baked imposters.+ - Species are fixed presets; there is no seasonal color, wind-bent skeleton or collision with other trees.diff --cc package.jsonindex b2b7b448,5c1d906d..6e1697c9--- a/package.json+++ b/package.json@@@ -77,11 -77,9 +78,12 @@@"./addons/surface-attachment": "./build/surface-attachment.js","./addons/physics": "./build/physics.js","./addons/spume": "./build/spume.js",+ "./addons/retarget": "./build/retarget.js",+ "./addons/vehicle": "./build/vehicle.js",+ "./addons/vegetation": "./build/vegetation.js","./addons/agent-scene": "./build/agent-scene.js","./addons/agent-asset": "./build/agent-asset.js",+ "./addons/hdri": "./build/hdri.js","./package.json": "./package.json"},"scripts": {diff --cc scripts/prepare-release.mjsindex d6c01cab,74f34e62..44fbbfea--- a/scripts/prepare-release.mjs+++ b/scripts/prepare-release.mjs@@@ -39,9 -39,7 +39,10 @@@ await copyFile(resolve(root, 'docs/gltfconst sourceDocuments = ['scene-graph.md', 'modeling.md', 'animation-curves.md', 'animation-mixer.md','gltf-morph.md', 'morph-targets.md', 'skinning.md', 'physics.md',- 'export-glb.md', 'sculpt.md', 'surface.md', 'mesh-query.md', 'primitives.md', 'shrinkwrap.md', 'spume.md', 'vegetation.md',+ 'export-glb.md', 'sculpt.md', 'surface.md', 'mesh-query.md', 'primitives.md', 'shrinkwrap.md', 'spume.md',+ 'retarget.md',+ 'vehicle.md',++ 'vegetation.md','camera-path.md', 'lighting.md', 'volumetric.md', 'film-physics.md','surface-attachment.md', 'agent-scene.md', 'mcp.md', 'agent-look.md', 'agent-asset.md', 'agent-render-jobs.md', 'agent-motion.md', 'agent-character-motion.md', 'agent-review.md',];diff --cc vite.lib.config.jsindex c78cba94,5de9bf91..5a99ced1--- a/vite.lib.config.js+++ b/vite.lib.config.js@@@ -26,11 -26,9 +26,12 @@@ export default defineConfig('surface-attachment': 'src/surface-attachment.js',physics: 'src/physics.js',spume: 'src/spume.js',+ retarget: 'src/retarget.js',+ vehicle: 'src/vehicle.js',+ vegetation: 'src/vegetation.js','agent-scene': 'src/agent-scene.js','agent-asset': 'src/agent-asset.js',+ hdri: 'src/hdri.js',},formats: ['es'],fileName: (_, entry) => entry === 'core' ? '67.module.js' : `${entry}.js`,