### Build and deploy showcase Source: https://github.com/majidmanzarpour/threejs-procedural-animals/blob/main/README.md Commands to install dependencies, build the showcase and pages, and record the demo reel. Requires Chromium and ffmpeg for recording. ```sh npm install npm run build:showcase # dist/showcase.html npm run build:pages # dist/pages/, deployed to GitHub Pages by .github/workflows/pages.yml node showcase/record.mjs # render the demo reel to MP4 (needs Chromium and ffmpeg) ``` -------------------------------- ### Install procedural-animals and three via npm Source: https://github.com/majidmanzarpour/threejs-procedural-animals/blob/main/README.md Install the package and its peer dependency three.js. The second command installs directly from GitHub until the package is published on npm. ```sh npm install procedural-animals three # until it is published on npm: npm install github:majidmanzarpour/threejs-procedural-animals three ``` -------------------------------- ### Quickstart: create and animate a wolf with createAnimal Source: https://github.com/majidmanzarpour/threejs-procedural-animals/blob/main/README.md Sets up a three.js scene, creates a wolf with seed 3 and high quality, then moves and updates it each frame. The comment notes that the animal moves itself and that top-level await is avoided to prevent deadlocking a Vite production build. ```js import * as THREE from 'three'; import { createAnimal } from 'procedural-animals'; const renderer = new THREE.WebGLRenderer({ antialias: true }); renderer.setSize(innerWidth, innerHeight); renderer.shadowMap.enabled = true; document.body.appendChild(renderer.domElement); const scene = new THREE.Scene(); scene.background = new THREE.Color(0xa9c1e0); const camera = new THREE.PerspectiveCamera(40, innerWidth / innerHeight, 0.1, 500); camera.position.set(6, 3, 8); const sun = new THREE.DirectionalLight(0xfff3e4, 2.7); sun.position.set(6, 10, 4); sun.castShadow = true; scene.add(sun, new THREE.HemisphereLight(0xdde6f2, 0x5f5a52, 1.15)); const floor = new THREE.Mesh(new THREE.PlaneGeometry(200, 200).rotateX(-Math.PI / 2), new THREE.MeshStandardMaterial({ color: 0x77736a })); floor.receiveShadow = true; scene.add(floor); async function main() { const wolf = await createAnimal('wolf', { seed: 3, quality: 'high' }); scene.add(wolf.object); // don't move wolf.object yourself: the animal moves itself let last = performance.now(); renderer.setAnimationLoop((now) => { const dt = (now - last) / 1000; // seconds last = now; wolf.move({ speed: wolf.gears.walk, heading: now / 1000 * 0.3 }); // m/s, radians wolf.update(dt); // once per frame camera.lookAt(wolf.position); renderer.render(scene, camera); }); } main(); // no top-level await in the entry module (it can deadlock a Vite production build) ``` -------------------------------- ### Bake an animal to a .animal file Source: https://github.com/majidmanzarpour/threejs-procedural-animals/blob/main/README.md CLI command to pre-build an individual animal and save it as a .animal file for instant loading. The example bakes a wolf with seed 3 and high quality to public/wolf-3.animal. ```sh npx procedural-animals-bake wolf --seed 3 --quality high -o public/wolf-3.animal ``` -------------------------------- ### move Source: https://github.com/majidmanzarpour/threejs-procedural-animals/blob/main/llms.txt Starts continuous movement for the animal. Accepts optional speed, gait, and climb parameters. ```APIDOC ## move ### Description Starts continuous movement for the animal. Accepts optional speed, gait, and climb parameters. ### Method move ### Parameters - **speed** (number) - Optional. Movement speed in m/s. - **gait** (string) - Optional. Gait name to use. - **climb** (number) - Optional. Climb rate for birds (m/s). ### Returns - **this** - The animal instance for chaining. ``` -------------------------------- ### Scripted bake with Node Source: https://github.com/majidmanzarpour/threejs-procedural-animals/blob/main/llms.txt Node.js example that writes a baked .animal file using writeBake and buildAnimalData. The example uses a horse with seed 7, medium quality, and palomino variant. ```javascript fs.writeFileSync(out, new Uint8Array(writeBake(await buildAnimalData('horse', { seed: 7, quality: 'medium', variant: 'palomino' })))) ``` -------------------------------- ### Run tests and tools Source: https://github.com/majidmanzarpour/threejs-procedural-animals/blob/main/README.md Commands to run tests and various tools for species validation. The browser tools require Chromium installed via npx playwright-core install chromium. ```sh npm test # every species builds, moves and plays every action node tools/metrics.mjs --seeds 1-4 # motion, skin and performance checks (tools/thresholds.json) node tools/render.mjs --views turntable,gaits,face,actions node tools/compare.mjs # renders beside your local reference photos ``` -------------------------------- ### Bundle worker with esbuild Source: https://github.com/majidmanzarpour/threejs-procedural-animals/blob/main/README.md Builds the worker file into a standalone script for bundlers that need manual setup. The output is placed in public/animal-worker.js. ```sh npx esbuild node_modules/procedural-animals/src/worker.js --bundle --format=iife --minify --outfile=public/animal-worker.js ``` -------------------------------- ### Minimal integration with createAnimal and wolf.update Source: https://github.com/majidmanzarpour/threejs-procedural-animals/blob/main/llms.txt Use this to add a procedurally generated animal to a Three.js scene. The example creates a wolf, adds it to the scene, moves it, and updates it every frame. Do not use top-level await in the app entry module; wrap startup in an async function. Call wolf.update(dt) exactly once per frame before rendering. ```javascript import * as THREE from 'three'; import { createAnimal } from 'procedural-animals'; async function main(scene, renderer, camera) { const wolf = await createAnimal('wolf', { seed: 3, quality: 'high', ground: (x, z) => 0 }); scene.add(wolf.object); // never transform wolf.object yourself wolf.move({ speed: wolf.gears.trot, heading: Math.PI / 2 }); let last = performance.now(); renderer.setAnimationLoop((now) => { const dt = (now - last) / 1000; // seconds last = now; wolf.update(dt); // every frame, before render renderer.render(scene, camera); }); } ``` -------------------------------- ### Set custom worker factory Source: https://github.com/majidmanzarpour/threejs-procedural-animals/blob/main/README.md Registers a factory that creates a Worker from the bundled script. Use this when your bundler cannot handle the default worker setup. ```js import { setWorkerFactory } from 'procedural-animals'; setWorkerFactory(() => new Worker('/animal-worker.js')); ``` -------------------------------- ### Build showcase: npm run build:showcase Source: https://github.com/majidmanzarpour/threejs-procedural-animals/blob/main/docs/AUTHORING.md Builds the real showcase page. Open dist/showcase.html to test the live page; test-harness renders are not enough because a species can lose fur in the live page while test renders look fine. ```bash npm run build:showcase ``` -------------------------------- ### Test showcase: node showcase/test.mjs Source: https://github.com/majidmanzarpour/threejs-procedural-animals/blob/main/docs/AUTHORING.md Scripts the showcase to test picking a species, playing every action, every gait, and crowd mode. Run after building the showcase. ```bash node showcase/test.mjs ``` -------------------------------- ### Smoke test showcase: node showcase/smoke.mjs Source: https://github.com/majidmanzarpour/threejs-procedural-animals/blob/main/docs/AUTHORING.md Scripts the showcase to verify it works. Run after building the showcase. ```bash node showcase/smoke.mjs ``` -------------------------------- ### Compare renders to reference photos: node tools/compare.mjs Source: https://github.com/majidmanzarpour/threejs-procedural-animals/blob/main/docs/AUTHORING.md Renders the species next to reference photos from matching angles. Add facing and bbox to entries in //index.json for exact framing (see ยง10). Iterate until silhouette, proportions, colours, and face match; a 5% error in leg length or head size is visible. ```bash node tools/compare.mjs ``` -------------------------------- ### Run tests for a species: npm test -- Source: https://github.com/majidmanzarpour/threejs-procedural-animals/blob/main/docs/AUTHORING.md Builds the species, runs every action, performs a bake round trip, and checks for NaN. Output goes to out/ which is gitignored. ```bash npm test -- ``` -------------------------------- ### Render views for review: node tools/render.mjs --views turntable,gaits,face,actions,tiers Source: https://github.com/majidmanzarpour/threejs-procedural-animals/blob/main/docs/AUTHORING.md Renders the specified views (turntable, gaits, face, actions, tiers) for visual inspection. Output goes to out/. ```bash node tools/render.mjs --views turntable,gaits,face,actions,tiers ``` -------------------------------- ### sculpt(model, rig, params) Source: https://github.com/majidmanzarpour/threejs-procedural-animals/blob/main/docs/AUTHORING.md Adds primitives to an SDFModel to build the animal's shape. This is the main entry point for sculpting operations. ```APIDOC ## sculpt(model, rig, params) ### Description Adds primitives to an SDFModel to build the animal's shape. This is the main entry point for sculpting operations. ### Parameters - **model** (SDFModel) - Required - The model to which primitives are added. - **rig** (Rig) - Required - The rig containing joints for positioning primitives. - **params** (Object) - Required - Additional parameters for the sculpting operation. ``` -------------------------------- ### Bake a species via CLI Source: https://github.com/majidmanzarpour/threejs-procedural-animals/blob/main/llms.txt Command-line tool to generate a .animal file for a species. Options include seed, quality tier, sex, age, and output file. The CLI verifies the round trip and that the file loads and animates. ```bash npx procedural-animals-bake [--seed N] [--quality tier] [--sex male|female] [--age adult|juvenile] [-o file.animal] ``` -------------------------------- ### Verify a baked .animal file Source: https://github.com/majidmanzarpour/threejs-procedural-animals/blob/main/llms.txt CLI command to verify that a .animal file loads and animates correctly. ```bash npx procedural-animals-bake --verify file.animal ``` -------------------------------- ### Control and events: moveTo, follow, lookAt, play, on, dispose Source: https://github.com/majidmanzarpour/threejs-procedural-animals/blob/main/README.md Shows the main API for steering an animal, listening to events, and cleaning up. The play method resolves to 'done' | 'interrupted' | 'stopped' | 'refused'. ```js wolf.moveTo(new THREE.Vector3(10, 0, 4), { speed: 3 }); // walk there, emits 'arrive' wolf.follow(body.position, body.velocity); // or follow your physics body, every frame wolf.lookAt(player.position); // null to stop await wolf.play('attack'); // 'done' | 'interrupted' | 'stopped' | 'refused' wolf.on('footstep', (e) => sfx.play('step', e.position, e.strength)); wolf.on('attackHit', (e) => damage(e.position, e.direction)); wolf.dispose(); // free GPU resources, remove from the scene ``` -------------------------------- ### Run metrics checks: node tools/metrics.mjs Source: https://github.com/majidmanzarpour/threejs-procedural-animals/blob/main/docs/AUTHORING.md Validates every threshold in tools/thresholds.json (set on the cheetah). Fails on joint pops, jitter, sliding stance feet, stretched patterns, or performance budget violations. Fix the cause, never loosen a threshold; explain in the PR if you believe a threshold is wrong. ```bash node tools/metrics.mjs ``` -------------------------------- ### eyeSpecs(params, rig) Source: https://github.com/majidmanzarpour/threejs-procedural-animals/blob/main/docs/AUTHORING.md Returns eye specifications for each eye, including geometry, placement, and appearance details. Use this to configure eye parameters for procedural animals. ```APIDOC ## eyeSpecs(params, rig) ### Description Returns one entry per eye with geometry, placement, and appearance specifications. ### Parameters - **params** (object) - Required - Parameters for eye generation. - **rig** (object) - Required - Rig data for the animal. ### Returns Array of eye entries, each containing: - **side** (string) - Side of the eye (e.g., 'left', 'right'). - **spec** (object) - Geometry specification (see `core/sdf/eyeSocket.js`). - **headOrigin** (vector) - Origin point of the head. - **bone** (string) - Bone name, always 'head'. - **look** (object) - Visual appearance settings: - **pupil** (string) - Pupil shape: 'round', 'slit', or 'bar'. - **pupilSize** (array) - [min, max] fraction of iris radius. - **iris** (object) - Iris colors: `{ inner, mid, hi, outer }` in linear RGB. - **sclera** (object) - Sclera settings: `{ color, visible }`. - **lids** (string) - Lid type: 'mammal', 'bird', 'none', or 'simple'. - **lidColor** (color) - Color of the eyelids. ### Usage Notes - Measure eye size and placement from face photos. - Ensure eyeball front sits at the skin surface. - Set `tilt` using `apertureTiltAlong(EYE, HEAD_O, HZ)`. - Keep eyelid patch inner radius containing the aperture rim. - Check metrics via `eyes:` line and `node tools/render.mjs --views eyes --quality hero`. ``` -------------------------------- ### Render seeded turntable: node tools/render.mjs --views turntable --seed Source: https://github.com/majidmanzarpour/threejs-procedural-animals/blob/main/docs/AUTHORING.md Renders 6 seeds side by side to check variation. A herd must not look cloned, and every individual must still look like the species. ```bash node tools/render.mjs --views turntable --seed ``` -------------------------------- ### Vite config for Web Workers Source: https://github.com/majidmanzarpour/threejs-procedural-animals/blob/main/README.md Required Vite configuration so createAnimal can use module workers. The build target es2022 and excluding the package from optimization are needed for worker support. ```js // vite.config.js export default { worker: { format: 'es' }, build: { target: 'es2022' }, optimizeDeps: { exclude: ['procedural-animals'] }, }; ``` -------------------------------- ### createAnimal(id, options) Source: https://github.com/majidmanzarpour/threejs-procedural-animals/blob/main/README.md Asynchronously creates an animal instance with the given species ID and configuration options. Returns a promise that resolves to an animal object with methods for movement, actions, updating, and disposal. ```APIDOC ## createAnimal(id, options) ### Description Asynchronously creates an animal instance with the given species ID and configuration options. Returns a promise that resolves to an animal object with methods for movement, actions, updating, and disposal. ### Method async function ### Parameters - **id** (string) - Required - The species identifier. - **options** (object) - Required - Configuration options. - **seed** (number) - Optional - Random seed for procedural generation. - **quality** (number) - Optional - Quality level for the animal model. - **ground** (string) - Optional - Terrain type; must match the terrain you draw. - **position** (Vector3) - Optional - Initial position in world space. - **heading** (number) - Optional - Initial heading in radians; 0 faces +Z. ### Returns - **Promise** - Resolves to an animal object with methods: `object`, `move`, `moveTo`, `follow`, `play`, `update`, `dispose`, and `gears`. ``` -------------------------------- ### Bundle worker for other bundlers or no bundler Source: https://github.com/majidmanzarpour/threejs-procedural-animals/blob/main/llms.txt Command to bundle the worker script into an IIFE file for environments that do not natively support the new URL worker pattern. After bundling, use setWorkerFactory to point to the output file. ```bash esbuild node_modules/procedural-animals/src/worker.js --bundle --format=iife --minify --outfile=public/animal-worker.js ``` -------------------------------- ### Vite configuration for worker format and build target Source: https://github.com/majidmanzarpour/threejs-procedural-animals/blob/main/llms.txt Required Vite configuration to use the library's default worker pattern. Sets worker format to 'es' and build target to 'es2022', and excludes 'procedural-animals' from dependency optimization. ```javascript export default { worker: { format: 'es' }, build: { target: 'es2022' }, optimizeDeps: { exclude: ['procedural-animals'] } } ``` -------------------------------- ### clearBuildCache() Source: https://github.com/majidmanzarpour/threejs-procedural-animals/blob/main/README.md Clears the internal build cache, forcing rebuilds of animals. ```APIDOC ## clearBuildCache() ### Description Clears the internal build cache, forcing rebuilds of animals. ### Example ```js import { clearBuildCache } from 'procedural-animals'; clearBuildCache(); ``` ``` -------------------------------- ### Load a baked animal Source: https://github.com/majidmanzarpour/threejs-procedural-animals/blob/main/README.md Creates an animal from a baked .animal file fetched as an ArrayBuffer. The baked option accepts a promise that resolves to the buffer. ```js const wolf = await createAnimal('wolf', { baked: fetch('/wolf-3.animal').then((r) => r.arrayBuffer()) }); ``` -------------------------------- ### follow Source: https://github.com/majidmanzarpour/threejs-procedural-animals/blob/main/llms.txt Makes the animal follow an external physics body. Accepts a position and optional velocity. ```APIDOC ## follow ### Description Makes the animal follow an external physics body. Accepts a position and optional velocity. ### Method follow ### Parameters - **position** (Vector3) - Required. Position to follow. - **velocity** (Vector3) - Optional. Velocity of the target. ### Returns - **this** - The animal instance for chaining. ``` -------------------------------- ### animal.follow(body.position, body.velocity) Source: https://github.com/majidmanzarpour/threejs-procedural-animals/blob/main/llms.txt Makes the animal follow a physics body by setting its position and velocity. This is used for physics-driven movement. ```APIDOC ## animal.follow(body.position, body.velocity) ### Description Makes the animal follow a physics body by setting its position and velocity. This is used for physics-driven movement. ### Method N/A (method call) ### Endpoint N/A ### Parameters - **position** (Vector3) - Required - Target position - **velocity** (Vector3) - Required - Target velocity ### Request Example ```js animal.follow(body.position, body.velocity); ``` ### Response #### Success Response No return value. ``` -------------------------------- ### QUALITY Source: https://github.com/majidmanzarpour/threejs-procedural-animals/blob/main/README.md An object containing quality tier constants for use with createAnimal. ```APIDOC ## QUALITY ### Description An object containing quality tier constants for use with createAnimal. ### Values - **hero** - 110-130k vertices, for cinematic close-ups. - **high** - 65-80k vertices, for the player's animal (default). - **medium** - 25-32k vertices, for mid distance and phones. - **low** - 11-15k vertices, for herds of 10-20. - **crowd** - 5-8k vertices, for crowds of 100 (with `setLod(2)`), one draw call. ### Example ```js import { QUALITY } from 'procedural-animals'; const animal = createAnimal('dog', { quality: QUALITY.hero }); ``` ``` -------------------------------- ### loadSpecies(id | module) Source: https://github.com/majidmanzarpour/threejs-procedural-animals/blob/main/llms.txt Loads a species by its identifier or module. Returns a promise that resolves to a species module containing species data and methods. ```APIDOC ## loadSpecies(id | module) ### Description Loads a species by its identifier or module. Returns a promise that resolves to a species module containing species data and methods. ### Method N/A (function call) ### Endpoint N/A ### Parameters - **id** (string) - Required - Species identifier - **module** (module) - Required - Module object (alternative to id) ### Request Example ```js const species = await loadSpecies('deer'); ``` ### Response #### Success Response - **species** (object) - Species module with properties: id, name, latin, plan, group, covering, variants, and methods. #### Response Example ```json { "id": "deer", "name": "Deer", "latin": "Cervidae", "plan": "quadruped", "group": "mammal", "covering": "fur", "variants": ["brown", "white"] } ``` ``` -------------------------------- ### animal.move({ speed, heading }) Source: https://github.com/majidmanzarpour/threejs-procedural-animals/blob/main/README.md Steers the animal with a given speed and heading. Should be called every frame for continuous movement. ```APIDOC ## animal.move({ speed, heading }) ### Description Steers the animal with a given speed and heading. Should be called every frame for continuous movement. ### Method method ### Parameters - **speed** (number) - Required - Movement speed in metres per second. - **heading** (number) - Required - Heading in radians; 0 faces +Z. ### Returns - **void** ``` -------------------------------- ### animal.play('jump') Source: https://github.com/majidmanzarpour/threejs-procedural-animals/blob/main/llms.txt Plays an animation on the animal. The animation name must be a valid gear name for the species. ```APIDOC ## animal.play('jump') ### Description Plays an animation on the animal. The animation name must be a valid gear name for the species. ### Method N/A (method call) ### Endpoint N/A ### Parameters - **animationName** (string) - Required - Name of the animation to play (e.g., 'jump', 'eat') ### Request Example ```js animal.play('jump'); ``` ### Response #### Success Response No return value. ``` -------------------------------- ### animal.follow(pos, vel) Source: https://github.com/majidmanzarpour/threejs-procedural-animals/blob/main/README.md Makes the animal follow a moving target with given position and velocity. Should be called every frame for continuous movement. ```APIDOC ## animal.follow(pos, vel) ### Description Makes the animal follow a moving target with given position and velocity. Should be called every frame for continuous movement. ### Method method ### Parameters - **pos** (Vector3) - Required - Target position. - **vel** (Vector3) - Required - Target velocity. ### Returns - **void** ``` -------------------------------- ### m.ell({ c, r, axis, up, bone, group, part, tag, k, carve, bias, thin }) Source: https://github.com/majidmanzarpour/threejs-procedural-animals/blob/main/docs/AUTHORING.md Adds an ellipsoid primitive to the model. The ellipsoid is positioned relative to joints and requires bone and group for skinning and grouping. ```APIDOC ## m.ell({ c, r, axis, up, bone, group, part, tag, k, carve, bias, thin }) ### Description Adds an ellipsoid primitive to the model. The ellipsoid is positioned relative to joints and requires bone and group for skinning and grouping. ### Parameters - **c** (Vector) - Required - Center position of the ellipsoid. - **r** (Array) - Required - Radii [rx, ry, rz]. - **axis** (Vector) - Optional - Axis orientation. - **up** (Vector) - Optional - Up vector. - **bone** (String) - Required - Bone for skinning. - **group** (String) - Required - Group: 'axial', a limb id (e.g., 'FL'), or an appendage group (e.g., 'earL'). - **part** (String) - Optional - Surface part: 'body' or 'jaw'. - **tag** (String) - Optional - Name for coat painter and weights. - **k** (Number) - Optional - Smooth-union blend radius; 0 gives hard union. - **carve** (Boolean) - Optional - If true, subtracts from the model. - **bias** (Number) - Optional - Bias parameter. - **thin** (Boolean) - Optional - Marks thin parts for inflation at coarse quality tiers. ``` -------------------------------- ### update Source: https://github.com/majidmanzarpour/threejs-procedural-animals/blob/main/llms.txt Updates the animal's state. Should be called every frame. ```APIDOC ## update ### Description Updates the animal's state. Should be called every frame. ### Method update ### Parameters - **dt** (number) - Required. Delta time in seconds. ### Returns - **this** - The animal instance for chaining. ``` -------------------------------- ### m.sphere({ c, rad, ... }) Source: https://github.com/majidmanzarpour/threejs-procedural-animals/blob/main/docs/AUTHORING.md Adds a sphere primitive to the model. Requires bone and group for skinning and grouping. ```APIDOC ## m.sphere({ c, rad, ... }) ### Description Adds a sphere primitive to the model. Requires bone and group for skinning and grouping. ### Parameters - **c** (Vector) - Required - Center position. - **rad** (Number) - Required - Radius. - **...** (Object) - Optional - Additional parameters (same as ellipsoid: bone, group, part, tag, k, carve, bias, thin). ``` -------------------------------- ### loadSpecies(species) Source: https://github.com/majidmanzarpour/threejs-procedural-animals/blob/main/README.md Loads a species definition, making it available for use with createAnimal. ```APIDOC ## loadSpecies(species) ### Description Loads a species definition, making it available for use with createAnimal. ### Parameters - **species** (string) - Required - The species identifier to load. ### Returns A Promise that resolves when the species is loaded. ### Example ```js import { loadSpecies } from 'procedural-animals'; await loadSpecies('dog'); ``` ``` -------------------------------- ### createAnimal(species, options) Source: https://github.com/majidmanzarpour/threejs-procedural-animals/blob/main/README.md Creates a new procedural animal instance. Accepts a species identifier and an options object to control the animal's appearance, behavior, and environment. ```APIDOC ## createAnimal(species, options) ### Description Creates a new procedural animal instance. Accepts a species identifier and an options object to control the animal's appearance, behavior, and environment. ### Parameters - **species** (string) - Required - The species identifier (e.g., 'dog', 'cat', etc.) - **options** (object) - Optional - Configuration options for the animal. - **seed** (number) - Optional - The individual (size, proportions, coat; sex, age and variant unless given). Default: `1`. - **quality** (string) - Optional - Quality tier: `'hero' | 'high' | 'medium' | 'low' | 'crowd'`. Default: `'high'`. - **variant** (string) - Optional - Breed / coat / morph. Default: by seed. - **sex** (string) - Optional - `'male' | 'female'`. Default: by seed. - **age** (string) - Optional - `'adult' | 'juvenile'`. Default: by seed. - **ground** (function) - Optional - `(x, z) => y` terrain height, in the space of `animal.object.parent`. Default: `() => 0`. - **water** (function) - Optional - `(x, z) => y | null` water surface (swimmers need it; land animals drink and wade). Default: none. - **perches** (Vector3[]) - Optional - Points birds can fly to. Default: `[]`. - **position** (Vector3) - Optional - Start position. Default: origin. - **heading** (number) - Optional - Start heading in radians, `0` faces +Z. Default: `0`. - **baked** (ArrayBuffer | Promise) - Optional - An `ArrayBuffer` (or a Promise of one) from a `.animal` file. Default: none. - **worker** (boolean) - Optional - `false` builds on this thread. Default: `true`. - **castShadow** (boolean) - Optional - Whether the animal casts shadows. Default: `true`. - **receiveShadow** (boolean) - Optional - Whether the animal receives shadows. Default: `true`. ### Returns An animal object with the following members: - **object** (Object3D) - The `Object3D` to add to your scene (keep its transform at identity). - **update(dt)** - Advance `dt` seconds; call once per frame. - **move({ speed, heading })**, **stop()**, **moveTo(point, { speed })**, **follow(pos, vel)** - Locomotion; the animal picks its gait. - **lookAt(target)** - Track a `Vector3` with the head. - **play(action, opts)**, **stopAction(name)** - Actions; `play` returns a Promise. - **on(event, fn)**, **off(event, fn)** - Events: `footstep`, `attackHit`, `actionStart`, `actionEnd`, `arrive`, `takeoff`, `land`, `death`, `vocalize`, `wingbeat`. - **setQuality(tier)**, **setLod(0 | 1 | 2)** - Coat detail on the existing mesh; motion detail for crowds. - **setDebug(mode, on)**, **setCoverings(on)** - `'albedo' | 'weights' | 'material' | 'bare'`; fur shells on/off. - **position**, **heading**, **speed**, **velocity**, **state** - Current motion state (read only). - **gears**, **gaits**, **actions** - This individual's named speeds (m/s), gaits and actions. - **attachments** - `mouth`, `head`, `back` (+ bird feet, horse `seat` / stirrups / bits) to parent props to. - **dispose()** - Free everything. ### Example ```js import { createAnimal } from 'procedural-animals'; const animal = createAnimal('dog', { seed: 42, quality: 'high' }); scene.add(animal.object); ``` ``` -------------------------------- ### m.cone({ a, b, ra, rb, ... }) Source: https://github.com/majidmanzarpour/threejs-procedural-animals/blob/main/docs/AUTHORING.md Adds a round cone (tapered capsule) primitive to the model. Requires bone and group for skinning and grouping. ```APIDOC ## m.cone({ a, b, ra, rb, ... }) ### Description Adds a round cone (tapered capsule) primitive to the model. Requires bone and group for skinning and grouping. ### Parameters - **a** (Vector) - Required - Start point. - **b** (Vector) - Required - End point. - **ra** (Number) - Required - Radius at start. - **rb** (Number) - Required - Radius at end. - **...** (Object) - Optional - Additional parameters (same as ellipsoid: bone, group, part, tag, k, carve, bias, thin). ``` -------------------------------- ### animal.gears Source: https://github.com/majidmanzarpour/threejs-procedural-animals/blob/main/README.md Provides access to the animal's movement parameters, such as speed values. Gear names differ per species. ```APIDOC ## animal.gears ### Description Provides access to the animal's movement parameters, such as speed values. Gear names differ per species. ### Type property ### Returns - **object** - Contains movement parameters (e.g., speed values). ``` -------------------------------- ### dispose Source: https://github.com/majidmanzarpour/threejs-procedural-animals/blob/main/llms.txt Frees GPU resources and removes the animal from its parent. ```APIDOC ## dispose ### Description Frees GPU resources and removes the animal from its parent. ### Method dispose ### Returns - **void** ``` -------------------------------- ### sculptEyeSocket() Source: https://github.com/majidmanzarpour/threejs-procedural-animals/blob/main/docs/AUTHORING.md Helper function from core/sdf/eyeSocket.js for creating eye sockets with lids. ```APIDOC ## sculptEyeSocket() ### Description Helper function from core/sdf/eyeSocket.js for creating eye sockets with lids. ### Parameters None specified in source. ``` -------------------------------- ### listSpecies() Source: https://github.com/majidmanzarpour/threejs-procedural-animals/blob/main/README.md Returns a list of available species identifiers that can be used with createAnimal. ```APIDOC ## listSpecies() ### Description Returns a list of available species identifiers that can be used with createAnimal. ### Returns An array of species identifiers (strings). ### Example ```js import { listSpecies } from 'procedural-animals'; const species = listSpecies(); console.log(species); ``` ``` -------------------------------- ### animal.play(action) Source: https://github.com/majidmanzarpour/threejs-procedural-animals/blob/main/README.md Triggers a named action on the animal, such as a gait or behaviour. Action names vary per species. ```APIDOC ## animal.play(action) ### Description Triggers a named action on the animal, such as a gait or behaviour. Action names vary per species. ### Method method ### Parameters - **action** (string) - Required - The action name to play. ### Returns - **void** ``` -------------------------------- ### animal.moveTo(point) Source: https://github.com/majidmanzarpour/threejs-procedural-animals/blob/main/README.md Moves the animal towards a specific point in world space. Should be called every frame for continuous movement. ```APIDOC ## animal.moveTo(point) ### Description Moves the animal towards a specific point in world space. Should be called every frame for continuous movement. ### Method method ### Parameters - **point** (Vector3) - Required - Target position in world space. ### Returns - **void** ``` -------------------------------- ### setCoverings Source: https://github.com/majidmanzarpour/threejs-procedural-animals/blob/main/llms.txt Shows or hides fur and fins coverings. Accepts a boolean flag. ```APIDOC ## setCoverings ### Description Shows or hides fur and fins coverings. Accepts a boolean flag. ### Method setCoverings ### Parameters - **on** (boolean) - Required. Whether to show or hide coverings. ### Returns - **this** - The animal instance for chaining. ``` -------------------------------- ### m.lens({...}) Source: https://github.com/majidmanzarpour/threejs-procedural-animals/blob/main/docs/AUTHORING.md Adds an almond aperture (eyelids) primitive to the model. Use with sculptEyeSocket() for eye sockets. ```APIDOC ## m.lens({...}) ### Description Adds an almond aperture (eyelids) primitive to the model. Use with sculptEyeSocket() for eye sockets. ### Parameters - **...** (Object) - Required - Parameters for the lens shape (details not specified in source). ``` -------------------------------- ### animal.moveTo(random point) Source: https://github.com/majidmanzarpour/threejs-procedural-animals/blob/main/llms.txt Moves the animal to a random point. The animal will navigate to the specified point. ```APIDOC ## animal.moveTo(random point) ### Description Moves the animal to a random point. The animal will navigate to the specified point. ### Method N/A (method call) ### Endpoint N/A ### Parameters - **point** (Vector3) - Required - Destination point ### Request Example ```js animal.moveTo(new THREE.Vector3(10, 0, 10)); ``` ### Response #### Success Response No return value. ``` -------------------------------- ### animal.setScale(x, y, z) Source: https://github.com/majidmanzarpour/threejs-procedural-animals/blob/main/llms.txt Sets the scale of the animal in 3D space. ```APIDOC ## animal.setScale(x, y, z) ### Description Sets the scale of the animal in 3D space. ### Method N/A (method call) ### Endpoint N/A ### Parameters - **x** (number) - Required - X scale factor - **y** (number) - Required - Y scale factor - **z** (number) - Required - Z scale factor ### Request Example ```js animal.setScale(1, 1, 1); ``` ### Response #### Success Response No return value. ``` -------------------------------- ### lookAt Source: https://github.com/majidmanzarpour/threejs-procedural-animals/blob/main/llms.txt Makes the animal look at a specified target point. The head and eyes track the target. ```APIDOC ## lookAt ### Description Makes the animal look at a specified target point. The head and eyes track the target. ### Method lookAt ### Parameters - **target** (Vector3) - Required. Target position to look at. ### Returns - **this** - The animal instance for chaining. ``` -------------------------------- ### animal.setPosition(x, y, z) Source: https://github.com/majidmanzarpour/threejs-procedural-animals/blob/main/llms.txt Sets the position of the animal in 3D space. ```APIDOC ## animal.setPosition(x, y, z) ### Description Sets the position of the animal in 3D space. ### Method N/A (method call) ### Endpoint N/A ### Parameters - **x** (number) - Required - X coordinate - **y** (number) - Required - Y coordinate - **z** (number) - Required - Z coordinate ### Request Example ```js animal.setPosition(0, 0, 0); ``` ### Response #### Success Response No return value. ``` -------------------------------- ### addLoader(id, () => import(...)) Source: https://github.com/majidmanzarpour/threejs-procedural-animals/blob/main/llms.txt Adds a dynamic loader for a species. The loader function is called when the species is loaded. ```APIDOC ## addLoader(id, () => import(...)) ### Description Adds a dynamic loader for a species. The loader function is called when the species is loaded. ### Method N/A (function call) ### Endpoint N/A ### Parameters - **id** (string) - Required - Species identifier - **loader** (function) - Required - Function that returns a promise of the species module ### Request Example ```js addLoader('deer', () => import('./species/deer.js')); ``` ### Response #### Success Response No return value. ``` -------------------------------- ### setWorkerFactory(factory) Source: https://github.com/majidmanzarpour/threejs-procedural-animals/blob/main/README.md Sets a custom worker factory for building animals in a worker thread. ```APIDOC ## setWorkerFactory(factory) ### Description Sets a custom worker factory for building animals in a worker thread. ### Parameters - **factory** (function) - Required - A factory function that returns a Worker instance. ### Example ```js import { setWorkerFactory } from 'procedural-animals'; setWorkerFactory(() => new MyWorker()); ``` ``` -------------------------------- ### animal.dispose() Source: https://github.com/majidmanzarpour/threejs-procedural-animals/blob/main/README.md Releases all resources associated with the animal. Call when the animal is no longer needed. ```APIDOC ## animal.dispose() ### Description Releases all resources associated with the animal. Call when the animal is no longer needed. ### Method method ### Parameters None ### Returns - **void** ``` -------------------------------- ### animal.update(dt) Source: https://github.com/majidmanzarpour/threejs-procedural-animals/blob/main/README.md Advances the animal's animation and physics by the given delta time. Must be called once per frame with dt in seconds. ```APIDOC ## animal.update(dt) ### Description Advances the animal's animation and physics by the given delta time. Must be called once per frame with dt in seconds. ### Method method ### Parameters - **dt** (number) - Required - Delta time in seconds. ### Returns - **void** ``` -------------------------------- ### animal.setRotation(x, y, z) Source: https://github.com/majidmanzarpour/threejs-procedural-animals/blob/main/llms.txt Sets the rotation of the animal in 3D space. ```APIDOC ## animal.setRotation(x, y, z) ### Description Sets the rotation of the animal in 3D space. ### Method N/A (method call) ### Endpoint N/A ### Parameters - **x** (number) - Required - X rotation (radians) - **y** (number) - Required - Y rotation (radians) - **z** (number) - Required - Z rotation (radians) ### Request Example ```js animal.setRotation(0, Math.PI, 0); ``` ### Response #### Success Response No return value. ``` -------------------------------- ### animal.update(dt) Source: https://github.com/majidmanzarpour/threejs-procedural-animals/blob/main/llms.txt Updates the animal's state. Must be called every frame with the delta time in milliseconds. ```APIDOC ## animal.update(dt) ### Description Updates the animal's state. Must be called every frame with the delta time in milliseconds. ### Method N/A (method call) ### Endpoint N/A ### Parameters - **dt** (number) - Required - Delta time in milliseconds ### Request Example ```js animal.update(16.67); ``` ### Response #### Success Response No return value. ``` -------------------------------- ### registerSpecies(module) Source: https://github.com/majidmanzarpour/threejs-procedural-animals/blob/main/llms.txt Registers a species module for later use. This is typically used to add custom species to the registry. ```APIDOC ## registerSpecies(module) ### Description Registers a species module for later use. This is typically used to add custom species to the registry. ### Method N/A (function call) ### Endpoint N/A ### Parameters - **module** (module) - Required - Species module to register ### Request Example ```js registerSpecies({ id: 'custom', name: 'Custom', ... }); ``` ### Response #### Success Response No return value. ``` -------------------------------- ### animal.setLod(0/1/2) Source: https://github.com/majidmanzarpour/threejs-procedural-animals/blob/main/llms.txt Sets the level of detail for the animal. Lower values indicate higher detail. ```APIDOC ## animal.setLod(0/1/2) ### Description Sets the level of detail for the animal. Lower values indicate higher detail. ### Method N/A (method call) ### Endpoint N/A ### Parameters - **level** (number) - Required - Level of detail (0, 1, or 2) ### Request Example ```js animal.setLod(0); ``` ### Response #### Success Response No return value. ``` -------------------------------- ### setDebug Source: https://github.com/majidmanzarpour/threejs-procedural-animals/blob/main/llms.txt Enables or disables debug mode. Accepts a mode and a boolean flag. ```APIDOC ## setDebug ### Description Enables or disables debug mode. Accepts a mode and a boolean flag. ### Method setDebug ### Parameters - **mode** (string) - Required. Debug mode: 'albedo', 'weights', 'material', or 'bare'. - **on** (boolean) - Required. Whether to enable or disable. ### Returns - **this** - The animal instance for chaining. ``` -------------------------------- ### stop Source: https://github.com/majidmanzarpour/threejs-procedural-animals/blob/main/llms.txt Stops the animal's movement. Equivalent to calling move with speed 0. ```APIDOC ## stop ### Description Stops the animal's movement. Equivalent to calling move with speed 0. ### Method stop ### Returns - **this** - The animal instance for chaining. ``` -------------------------------- ### animal.setQuality('high' | 'medium' | 'low') Source: https://github.com/majidmanzarpour/threejs-procedural-animals/blob/main/llms.txt Sets the quality of the animal's rendering. This affects the mesh resolution. ```APIDOC ## animal.setQuality('high' | 'medium' | 'low') ### Description Sets the quality of the animal's rendering. This affects the mesh resolution. ### Method N/A (method call) ### Endpoint N/A ### Parameters - **quality** (string) - Required - Quality level: 'high', 'medium', or 'low' ### Request Example ```js animal.setQuality('high'); ``` ### Response #### Success Response No return value. ``` -------------------------------- ### setLod Source: https://github.com/majidmanzarpour/threejs-procedural-animals/blob/main/llms.txt Sets the level of detail for the animal's mesh. Accepts a tier value. ```APIDOC ## setLod ### Description Sets the level of detail for the animal's mesh. Accepts a tier value. ### Method setLod ### Parameters - **tier** (number) - Required. Level of detail tier (0, 1, or 2). ### Returns - **this** - The animal instance for chaining. ``` -------------------------------- ### Custom species worker module Source: https://github.com/majidmanzarpour/threejs-procedural-animals/blob/main/llms.txt Worker module that imports the library's worker entry and registers a custom species loader. The loader function dynamically imports the species definition. ```javascript import 'procedural-animals/worker'; addLoader(id, () => import(...)); ```