@call-me-sensei/toonlab 0.3.0 → 0.4.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +549 -184
- package/agents/README.md +59 -0
- package/agents/references/anime-art-direction.md +24 -0
- package/agents/references/asset-sourcing-policy.md +23 -0
- package/agents/references/custom-gap-report.md +16 -0
- package/agents/references/geology-playbook.md +118 -0
- package/agents/references/mcp-asset-discovery.md +104 -0
- package/agents/references/runtime-entry-points.md +174 -0
- package/agents/references/style-bundles.md +71 -0
- package/agents/skills/claude/asset-sourcing/SKILL.md +275 -0
- package/agents/skills/claude/environment/SKILL.md +59 -0
- package/agents/skills/claude/game-dev/SKILL.md +100 -0
- package/agents/skills/claude/karst-cliff-construction/SKILL.md +258 -0
- package/agents/skills/claude/outdoor-world/SKILL.md +492 -0
- package/agents/skills/claude/outdoor-world/references/coastal-landform-formation.md +100 -0
- package/agents/skills/claude/post-processing/SKILL.md +44 -0
- package/agents/skills/claude/rock-ground-shaders/SKILL.md +118 -0
- package/agents/skills/claude/rockgen/SKILL.md +30 -0
- package/agents/skills/claude/scene-style-application/SKILL.md +74 -0
- package/agents/skills/claude/style-presets/SKILL.md +101 -0
- package/agents/skills/claude/toon-shading/SKILL.md +44 -0
- package/agents/skills/claude/vegetation-sky/SKILL.md +167 -0
- package/agents/skills/claude/visual-verification/SKILL.md +136 -0
- package/agents/skills/claude/water/SKILL.md +105 -0
- package/agents/skills/codex/asset-sourcing/SKILL.md +275 -0
- package/agents/skills/codex/environment/SKILL.md +59 -0
- package/agents/skills/codex/game-dev/SKILL.md +100 -0
- package/agents/skills/codex/karst-cliff-construction/SKILL.md +258 -0
- package/agents/skills/codex/outdoor-world/SKILL.md +492 -0
- package/agents/skills/codex/outdoor-world/references/coastal-landform-formation.md +100 -0
- package/agents/skills/codex/post-processing/SKILL.md +44 -0
- package/agents/skills/codex/rock-ground-shaders/SKILL.md +118 -0
- package/agents/skills/codex/rockgen/SKILL.md +30 -0
- package/agents/skills/codex/scene-style-application/SKILL.md +74 -0
- package/agents/skills/codex/style-presets/SKILL.md +101 -0
- package/agents/skills/codex/toon-shading/SKILL.md +44 -0
- package/agents/skills/codex/vegetation-sky/SKILL.md +167 -0
- package/agents/skills/codex/visual-verification/SKILL.md +136 -0
- package/agents/skills/codex/water/SKILL.md +105 -0
- package/cli/toonlab.mjs +52 -0
- package/compose.yaml +20 -0
- package/database/apply-sql.mjs +141 -0
- package/database/client.mjs +39 -0
- package/database/creation-tags.mjs +23 -0
- package/database/env.mjs +16 -0
- package/database/generation-service.mjs +314 -0
- package/database/migrations/0001_local_workspace.sql +120 -0
- package/database/migrations/0002_file_ownership.sql +11 -0
- package/database/migrations/0003_remove_autosaves_from_library.sql +7 -0
- package/database/migrations/0004_catalog_asset_packs.sql +39 -0
- package/database/migrations/0005_creation_tag_discovery.sql +1 -0
- package/database/migrations/0006_normalize_creation_tags.sql +28 -0
- package/database/providers.mjs +465 -0
- package/database/repository.mjs +625 -0
- package/database/seeds/catalog/0001_empty_official_catalog.sql +4 -0
- package/database/seeds/catalog/0002_2026-08.sql +19454 -0
- package/mcp/lab-management.mjs +629 -0
- package/mcp/public-catalog.mjs +168 -0
- package/mcp/server.mjs +1026 -63
- package/mcp/vite-plugin.mjs +443 -26
- package/mcp/workspace.mjs +26 -1
- package/package.json +312 -45
- package/scripts/generate-catalog-seed.mjs +297 -0
- package/scripts/setup-local.mjs +128 -0
- package/src/agents/index.js +7 -0
- package/src/agents/sceneStyleOperations.js +169 -0
- package/src/asset-policy/catalogLicenses.js +44 -0
- package/src/asset-policy/index.js +315 -0
- package/src/assetlib/assetRef.js +1 -1
- package/src/assetlib/galleryMaterialFamily.js +165 -0
- package/src/assetlib/index.js +6 -2
- package/src/assetlib/plateau.js +188 -0
- package/src/assetlib/plateauLandmarks.js +144 -0
- package/src/assetlib/plateauViewer.js +348 -0
- package/src/assetlib/sources.js +16 -2
- package/src/catalog/manifest.js +11 -1
- package/src/catalog/officialCatalog.js +4 -0
- package/src/catalog/officialCatalogAssetRuntime.js +313 -0
- package/src/catalog/officialCatalogLod.js +150 -0
- package/src/catalog/officialCatalogPlacement.js +228 -0
- package/src/catalog/officialCatalogProvider.js +334 -0
- package/src/character/animationRetarget.js +1082 -0
- package/src/character/characterRuntime.js +376 -0
- package/src/character/groundStabilizer.js +137 -0
- package/src/character/index.js +8 -0
- package/src/character/locomotionActions.js +74 -0
- package/src/character/locomotionStateMachine.js +241 -0
- package/src/character/mannequinAsset.js +15 -0
- package/src/character/mannequinAssetUrl.browser.js +4 -0
- package/src/character/mannequinAssetUrl.node.js +3 -0
- package/src/character/modelLoader.js +92 -12
- package/src/character/walkableCharacterRuntime.js +284 -0
- package/src/character/waterInteractionController.js +217 -0
- package/src/cloud/ambientSkyBaker.js +248 -0
- package/src/cloud/cloudLighting.js +1114 -0
- package/src/cloud/cloudParams.js +819 -0
- package/src/cloud/cloudReprojection.js +563 -0
- package/src/cloud/cloudStyle.js +780 -0
- package/src/cloud/cloudStyleSnapshots.js +387 -0
- package/src/cloud/cloudVolume.js +1903 -0
- package/src/cloud/heroCloudRecipe.js +404 -0
- package/src/cloud/index.js +42 -0
- package/src/cloud/noise/baseShapeVolume.js +331 -0
- package/src/cloud/noise/cirrusMap.js +131 -0
- package/src/cloud/noise/curlNoise.js +289 -0
- package/src/cloud/noise/erosionVolume.js +188 -0
- package/src/cloud/noise/noiseVolume.js +202 -0
- package/src/cloud/noise/periodicNoise3.js +295 -0
- package/src/cloud/noise/weatherMap.js +470 -0
- package/src/cloud/paramSchema.js +458 -0
- package/src/collisionMetadata.js +320 -0
- package/src/core/systemStylePolicy.js +32 -0
- package/src/environment/dayCurves.js +146 -0
- package/src/environment/environmentGroundFieldPass.js +354 -0
- package/src/environment/environmentMaterialAdapter.js +114 -6
- package/src/environment/environmentPresets.js +396 -90
- package/src/environment/environmentRigs.js +17 -2
- package/src/environment/environmentSettings.js +37 -1
- package/src/environment/environmentShaderMaterials.js +37 -6
- package/src/environment/environmentState.js +133 -0
- package/src/environment/environmentSunShadowPass.js +357 -6
- package/src/environment/environmentTextureResolver.js +7 -0
- package/src/environment/index.js +51 -0
- package/src/environment/manufacturedMaterialContract.js +837 -0
- package/src/environment/manufacturedReflectionProvider.js +114 -0
- package/src/environment/scanAssetStylize.js +4 -4
- package/src/environment/surfaceMaterialModes.js +71 -0
- package/src/environment/toonLabEnvironmentMaterials.js +353 -0
- package/src/environment/toonLabMaterialPassCoupling.js +347 -0
- package/src/environment/toonLabNormalIntegration.js +171 -0
- package/src/environment/toonLabRockMaterialResolver.js +592 -0
- package/src/environment/toonLabSourceDefaultLit.js +444 -0
- package/src/environment/toonLabSourceLibrary.js +762 -0
- package/src/environment/toonLabSourceMaterials.js +3718 -0
- package/src/environment/toonLabSourceSubsurfaceLighting.js +415 -0
- package/src/environment/toonLabSourceTemporal.js +717 -0
- package/src/environment/toonLabSurfaceLighting.js +364 -0
- package/src/environment/toonLabTextureReadiness.js +105 -0
- package/src/environment/toonLabTreeMaterials.js +450 -0
- package/src/environment/transparentMaterialProfile.js +87 -0
- package/src/environment/urbanPropMaterial.js +2874 -0
- package/src/ground-shader/groundPrintLayer.js +375 -0
- package/src/ground-shader/groundShaderMaterial.js +851 -0
- package/src/ground-shader/groundShaderSettings.js +468 -0
- package/src/ground-shader/index.js +3 -0
- package/src/index.js +52 -22
- package/src/lighting/callMeSenseiLightingContract.js +163 -0
- package/src/lighting/index.js +14 -7
- package/src/lighting/lightingCapabilities.js +2 -2
- package/src/lighting/lightingPresets.js +6 -3
- package/src/lighting/lightingStyle.js +41 -6
- package/src/lighting/lightingSystem.js +140 -1
- package/src/lighting/{unrealExport.js → toonLabExport.js} +40 -41
- package/src/post/postProcessing.js +71 -12
- package/src/react/index.js +66 -0
- package/src/renderer/index.js +9 -0
- package/src/renderer/rendererConfiguration.js +250 -0
- package/src/rock-shader/index.js +3 -0
- package/src/rock-shader/rockMaterial.js +1843 -0
- package/src/rock-shader/rockShaderRuntime.js +494 -0
- package/src/rock-shader/rockShaderSettings.js +869 -0
- package/src/rockgen/export/glbExport.js +104 -14
- package/src/rockgen/index.js +4 -3
- package/src/rockgen/lod/index.js +6 -0
- package/src/rockgen/lod/rockLodMetrics.js +168 -0
- package/src/rockgen/lod/rockLodPlanner.js +372 -0
- package/src/rockgen/lod/rockLodPolicy.js +235 -0
- package/src/rockgen/lod/rockLodRuntime.js +124 -0
- package/src/rockgen/lod/rockLodSimplifier.js +173 -0
- package/src/rockgen/lod/rockLodValidation.js +113 -0
- package/src/rockgen/mesh/meshAttributes.js +17 -0
- package/src/rockgen/mesh/meshDocument.js +6 -0
- package/src/rockgen/rockDocument.js +352 -9
- package/src/rockgen/rockgenPresets.js +114 -13
- package/src/rockgen/rockgenSettings.js +62 -11
- package/src/runtime/index.js +14 -0
- package/src/runtime/sceneCollisionRuntime.js +317 -0
- package/src/runtime/sceneSurfaceRuntime.js +451 -0
- package/src/runtime/sceneUpdateScheduler.js +203 -0
- package/src/shaders-tsl/anime.js +9 -2
- package/src/shaders-tsl/chunks/environment-ground-field.js +174 -0
- package/src/shaders-tsl/chunks/environment-state.js +79 -0
- package/src/shaders-tsl/chunks/environment-sun-shadow.js +99 -32
- package/src/shaders-tsl/chunks/normalized-hue.js +41 -0
- package/src/shaders-tsl/chunks/pass-depth-color.js +4 -2
- package/src/shaders-tsl/chunks/scene-depth-color-pass.js +273 -0
- package/src/shaders-tsl/chunks/vegetation-style.js +116 -8
- package/src/shaders-tsl/chunks/water-color.js +19 -5
- package/src/shaders-tsl/chunks/water-shore-state.js +8 -1
- package/src/shaders-tsl/chunks/world-noise.js +30 -0
- package/src/shaders-tsl/environment.js +123 -17
- package/src/shaders-tsl/flower.js +51 -8
- package/src/shaders-tsl/grass.js +194 -29
- package/src/shaders-tsl/post-composite.js +83 -2
- package/src/shaders-tsl/tree-leaf.js +107 -16
- package/src/shaders-tsl/water-breaker.js +18 -4
- package/src/shaders-tsl/water.js +43 -3
- package/src/shaders-tsl/woody-surface.js +59 -7
- package/src/sky/atmosphereDome.js +193 -0
- package/src/sky/atmosphereParams.js +396 -0
- package/src/sky/atmosphereScattering.js +593 -0
- package/src/sky/atmosphereSky.js +371 -0
- package/src/sky/cloudShadow.js +355 -0
- package/src/sky/godRays.js +257 -0
- package/src/sky/index.js +55 -1
- package/src/sky/nightSky.js +1190 -0
- package/src/sky/renderLayers.js +120 -0
- package/src/sky/skyColor.js +582 -0
- package/src/sky/skyDayCycle.js +244 -0
- package/src/sky/skyParams.js +661 -0
- package/src/sky/skyPresets.js +772 -0
- package/src/sky/skyQualityTiers.js +383 -0
- package/src/sky/skyShaderSettings.js +699 -0
- package/src/sky/skyStyleSnapshots.js +211 -0
- package/src/sky/skySystem.js +1438 -0
- package/src/sky/skyTimeKeyframes.js +361 -0
- package/src/sky/stylizedSky.js +405 -116
- package/src/sky/sunDriver.js +499 -0
- package/src/sky/timeOfDay.js +335 -0
- package/src/styles/animeGameProfile.js +44 -0
- package/src/styles/index.js +134 -0
- package/src/styles/manufacturedStyleLabeling.js +204 -0
- package/src/styles/sceneLayerDocuments.js +185 -0
- package/src/styles/sceneLookComposition.js +156 -0
- package/src/styles/sceneQualityApplication.js +152 -0
- package/src/styles/sceneQualityProfiles.js +268 -0
- package/src/styles/sceneStyleAudit.js +512 -0
- package/src/styles/sceneStyleRuntime.js +876 -0
- package/src/styles/styleAdapters.js +166 -0
- package/src/styles/styleApplication.js +369 -0
- package/src/styles/styleBundle.js +444 -91
- package/src/styles/styleBundleProvider.js +83 -0
- package/src/styles/styleDomains.js +21 -0
- package/src/styles/styleInspector.js +262 -0
- package/src/styles/styleMaterialContract.js +375 -0
- package/src/styles/styleMetadata.js +73 -0
- package/src/styles/styleTargetDiscovery.js +162 -0
- package/src/styles/styleTargetLabels.js +206 -0
- package/src/styles/styleTargetMaterialCoverage.js +137 -0
- package/src/styles/styleTransaction.js +272 -0
- package/src/texgen/textureGenerators.js +21 -5
- package/src/toon/toonSettings.js +4 -0
- package/src/vegetation/branchTree.js +302 -0
- package/src/vegetation/callMeSenseiGrass.js +183 -0
- package/src/vegetation/compiledTree.js +506 -0
- package/src/vegetation/contactShadowField.js +107 -0
- package/src/vegetation/flowerSpecies.js +10 -2
- package/src/vegetation/grass.js +13 -0
- package/src/vegetation/grassClump.js +1179 -0
- package/src/vegetation/importedVegetationMaterial.js +183 -0
- package/src/vegetation/index.js +15 -1
- package/src/vegetation/legacyTreePresets.js +120 -0
- package/src/vegetation/scatter.js +322 -3
- package/src/vegetation/stylizedBush.js +14 -0
- package/src/vegetation/stylizedFlower.js +31 -0
- package/src/vegetation/stylizedFlowers.js +59 -7
- package/src/vegetation/stylizedForest.js +455 -147
- package/src/vegetation/stylizedGrass.js +188 -24
- package/src/vegetation/stylizedTree.js +378 -46
- package/src/vegetation/stylizedTreeFoliage.js +889 -38
- package/src/vegetation/stylizedUnderstory.js +230 -0
- package/src/vegetation/treeExport.js +262 -47
- package/src/vegetation/treeSurfaceTextures.js +337 -0
- package/src/vegetation/vegetationShaders.js +617 -28
- package/src/version.js +3 -0
- package/src/water/water.js +2 -0
- package/src/water/waterBreakerSystem.js +2 -0
- package/src/water/waterCurrentField.js +1 -0
- package/src/water/waterMaterial.js +3 -0
- package/src/water/waterRain.js +2 -0
- package/src/water/waterScenePasses.js +170 -7
- package/src/water/waterSettings.js +235 -43
- package/src/water/waterShoreMaterial.js +16 -2
- package/src/water/waterShoreStateField.js +1 -1
- package/src/water/waterSplashSystem.js +2 -0
- package/src/water/waterStageSettings.js +60 -0
- package/src/water/waterSurface.js +144 -4
- package/src/water/waterUnderwaterAtmosphere.js +288 -0
- package/src/water/waterVegetation.js +20 -4
- package/src/worldCollision.js +64 -9
- package/types/agents/index.d.ts +1 -0
- package/types/agents/sceneStyleOperations.d.ts +484 -0
- package/types/asset-policy/catalogLicenses.d.ts +5 -0
- package/types/asset-policy/index.d.ts +18 -0
- package/types/assetlib/ambientcg.d.ts +81 -0
- package/types/assetlib/assetRef.d.ts +26 -0
- package/types/assetlib/galleryMaterialFamily.d.ts +13 -0
- package/types/assetlib/importedEntry.d.ts +18 -0
- package/types/assetlib/index.d.ts +16 -0
- package/types/assetlib/kaykit.d.ts +112 -0
- package/types/assetlib/kaykitStaticIndex.d.ts +38 -0
- package/types/assetlib/loadImported.d.ts +54 -0
- package/types/assetlib/opensource3d.d.ts +55 -0
- package/types/assetlib/plateau.d.ts +67 -0
- package/types/assetlib/plateauLandmarks.d.ts +238 -0
- package/types/assetlib/plateauViewer.d.ts +3 -0
- package/types/assetlib/polyhaven.d.ts +90 -0
- package/types/assetlib/polypizza.d.ts +10 -0
- package/types/assetlib/smithsonian.d.ts +9 -0
- package/types/assetlib/sources.d.ts +22 -0
- package/types/assetlib/zip.d.ts +8 -0
- package/types/catalog/manifest.d.ts +26 -0
- package/types/catalog/officialCatalog.d.ts +4 -0
- package/types/catalog/officialCatalogAssetRuntime.d.ts +2 -0
- package/types/catalog/officialCatalogLod.d.ts +5 -0
- package/types/catalog/officialCatalogPlacement.d.ts +49 -0
- package/types/catalog/officialCatalogProvider.d.ts +7 -0
- package/types/character/animationRetarget.d.ts +20 -0
- package/types/character/characterRig.d.ts +28 -0
- package/types/character/characterRuntime.d.ts +4 -0
- package/types/character/freestyleSwimClip.d.ts +5 -0
- package/types/character/groundStabilizer.d.ts +55 -0
- package/types/character/index.d.ts +10 -0
- package/types/character/locomotionActions.d.ts +4 -0
- package/types/character/locomotionStateMachine.d.ts +62 -0
- package/types/character/mannequinAsset.d.ts +12 -0
- package/types/character/mannequinAssetUrl.node.d.ts +1 -0
- package/types/character/modelLoader.d.ts +7 -0
- package/types/character/walkableCharacterRuntime.d.ts +343 -0
- package/types/character/waterInteractionController.d.ts +114 -0
- package/types/cloud/ambientSkyBaker.d.ts +18 -0
- package/types/cloud/cloudLighting.d.ts +38 -0
- package/types/cloud/cloudParams.d.ts +18 -0
- package/types/cloud/cloudReprojection.d.ts +15 -0
- package/types/cloud/cloudStyle.d.ts +1380 -0
- package/types/cloud/cloudStyleSnapshots.d.ts +10 -0
- package/types/cloud/cloudVolume.d.ts +43 -0
- package/types/cloud/heroCloudRecipe.d.ts +167 -0
- package/types/cloud/index.d.ts +12 -0
- package/types/cloud/noise/baseShapeVolume.d.ts +86 -0
- package/types/cloud/noise/cirrusMap.d.ts +24 -0
- package/types/cloud/noise/curlNoise.d.ts +106 -0
- package/types/cloud/noise/erosionVolume.d.ts +58 -0
- package/types/cloud/noise/noiseVolume.d.ts +63 -0
- package/types/cloud/noise/periodicNoise3.d.ts +75 -0
- package/types/cloud/noise/weatherMap.d.ts +227 -0
- package/types/cloud/paramSchema.d.ts +142 -0
- package/types/collisionMetadata.d.ts +11 -0
- package/types/core/generation.d.ts +95 -0
- package/types/core/materialRoles.d.ts +102 -0
- package/types/core/presetDocuments.d.ts +25 -0
- package/types/core/systemStylePolicy.d.ts +4 -0
- package/types/environment/dayCurves.d.ts +47 -0
- package/types/environment/environmentAmbientProbe.d.ts +2 -0
- package/types/environment/environmentGroundFieldPass.d.ts +2 -0
- package/types/environment/environmentMaterialAdapter.d.ts +42 -0
- package/types/environment/environmentMaterialClassifier.d.ts +26 -0
- package/types/environment/environmentPlanarReflection.d.ts +3 -0
- package/types/environment/environmentPresets.d.ts +171 -0
- package/types/environment/environmentRigs.d.ts +13 -0
- package/types/environment/environmentSettings.d.ts +161 -0
- package/types/environment/environmentShaderMaterials.d.ts +14 -0
- package/types/environment/environmentState.d.ts +6 -0
- package/types/environment/environmentSunShadowPass.d.ts +2 -0
- package/types/environment/environmentTextureResolver.d.ts +30 -0
- package/types/environment/environmentTimeOfDay.d.ts +25 -0
- package/types/environment/environmentVertexAo.d.ts +18 -0
- package/types/environment/index.d.ts +27 -0
- package/types/environment/manufacturedMaterialContract.d.ts +129 -0
- package/types/environment/manufacturedReflectionProvider.d.ts +3 -0
- package/types/environment/scanAssetStylize.d.ts +43 -0
- package/types/environment/surfaceMaterialModes.d.ts +14 -0
- package/types/environment/toonLabEnvironmentMaterials.d.ts +139 -0
- package/types/environment/toonLabMaterialPassCoupling.d.ts +7 -0
- package/types/environment/toonLabNormalIntegration.d.ts +29 -0
- package/types/environment/toonLabRockMaterialResolver.d.ts +270 -0
- package/types/environment/toonLabSourceDefaultLit.d.ts +136 -0
- package/types/environment/toonLabSourceLibrary.d.ts +19 -0
- package/types/environment/toonLabSourceMaterials.d.ts +14 -0
- package/types/environment/toonLabSourceSubsurfaceLighting.d.ts +85 -0
- package/types/environment/toonLabSourceTemporal.d.ts +20 -0
- package/types/environment/toonLabSurfaceLighting.d.ts +136 -0
- package/types/environment/toonLabTextureReadiness.d.ts +8 -0
- package/types/environment/toonLabTreeMaterials.d.ts +7 -0
- package/types/environment/transparentMaterialProfile.d.ts +76 -0
- package/types/environment/urbanPropMaterial.d.ts +25 -0
- package/types/ground-shader/groundPrintLayer.d.ts +4 -0
- package/types/ground-shader/groundShaderMaterial.d.ts +11 -0
- package/types/ground-shader/groundShaderSettings.d.ts +90 -0
- package/types/ground-shader/index.d.ts +3 -0
- package/types/index.d.ts +1502 -0
- package/types/lighting/callMeSenseiLightingContract.d.ts +14 -0
- package/types/lighting/colorIntensity.d.ts +44 -0
- package/types/lighting/index.d.ts +12 -0
- package/types/lighting/lightDescriptors.d.ts +803 -0
- package/types/lighting/lightingCapabilities.d.ts +85 -0
- package/types/lighting/lightingDocuments.d.ts +140 -0
- package/types/lighting/lightingFixtures.d.ts +171 -0
- package/types/lighting/lightingGenerator.d.ts +403 -0
- package/types/lighting/lightingPresets.d.ts +264 -0
- package/types/lighting/lightingRuntime.d.ts +401 -0
- package/types/lighting/lightingStyle.d.ts +156 -0
- package/types/lighting/lightingSystem.d.ts +433 -0
- package/types/lighting/toonLabExport.d.ts +46 -0
- package/types/lighting/utils.d.ts +18 -0
- package/types/loaders/index.d.ts +1 -0
- package/types/post/index.d.ts +2 -0
- package/types/post/postGenerator.d.ts +282 -0
- package/types/post/postProcessing.d.ts +16 -0
- package/types/react/index.d.ts +1765 -0
- package/types/renderer/index.d.ts +1 -0
- package/types/renderer/rendererConfiguration.d.ts +8 -0
- package/types/rock-shader/index.d.ts +3 -0
- package/types/rock-shader/rockMaterial.d.ts +18 -0
- package/types/rock-shader/rockShaderRuntime.d.ts +8 -0
- package/types/rock-shader/rockShaderSettings.d.ts +170 -0
- package/types/rockgen/export/glbExport.d.ts +58 -0
- package/types/rockgen/heightfield/heightfieldErosion.d.ts +10 -0
- package/types/rockgen/heightfield/heightfieldPatch.d.ts +15 -0
- package/types/rockgen/heightfield/stylizedErosionSim.d.ts +41 -0
- package/types/rockgen/index.d.ts +11 -0
- package/types/rockgen/lod/index.d.ts +6 -0
- package/types/rockgen/lod/rockLodMetrics.d.ts +62 -0
- package/types/rockgen/lod/rockLodPlanner.d.ts +86 -0
- package/types/rockgen/lod/rockLodPolicy.d.ts +76 -0
- package/types/rockgen/lod/rockLodRuntime.d.ts +95 -0
- package/types/rockgen/lod/rockLodSimplifier.d.ts +15 -0
- package/types/rockgen/lod/rockLodValidation.d.ts +16 -0
- package/types/rockgen/mesh/meshAttributes.d.ts +32 -0
- package/types/rockgen/mesh/meshDocument.d.ts +40 -0
- package/types/rockgen/mesh/surfaceNets.d.ts +42 -0
- package/types/rockgen/noise/cellularNoise3.d.ts +24 -0
- package/types/rockgen/noise/prng.d.ts +16 -0
- package/types/rockgen/noise/simplexNoise3.d.ts +2 -0
- package/types/rockgen/noise/valueNoise3.d.ts +12 -0
- package/types/rockgen/rockDocument.d.ts +215 -0
- package/types/rockgen/rockHelpers.d.ts +2 -0
- package/types/rockgen/rockgenPresets.d.ts +10 -0
- package/types/rockgen/rockgenSettings.d.ts +531 -0
- package/types/rockgen/sdf/fieldCompiler.d.ts +20 -0
- package/types/rockgen/sdf/sculptEdits.d.ts +30 -0
- package/types/rockgen/sdf/sdfModifiers.d.ts +19 -0
- package/types/rockgen/sdf/sdfOps.d.ts +8 -0
- package/types/rockgen/sdf/sdfPrimitives.d.ts +22 -0
- package/types/runtime/index.d.ts +3 -0
- package/types/runtime/sceneCollisionRuntime.d.ts +94 -0
- package/types/runtime/sceneSurfaceRuntime.d.ts +90 -0
- package/types/runtime/sceneUpdateScheduler.d.ts +28 -0
- package/types/shaders-tsl/anime.d.ts +9 -0
- package/types/shaders-tsl/chunks/character-color.d.ts +6 -0
- package/types/shaders-tsl/chunks/character-highlights.d.ts +12 -0
- package/types/shaders-tsl/chunks/character-lighting.d.ts +20 -0
- package/types/shaders-tsl/chunks/character-material-maps.d.ts +18 -0
- package/types/shaders-tsl/chunks/character-roles.d.ts +21 -0
- package/types/shaders-tsl/chunks/character-scene-lights.d.ts +48 -0
- package/types/shaders-tsl/chunks/character-shadow-color.d.ts +5 -0
- package/types/shaders-tsl/chunks/character-skinning.d.ts +23 -0
- package/types/shaders-tsl/chunks/environment-color.d.ts +9 -0
- package/types/shaders-tsl/chunks/environment-debug.d.ts +24 -0
- package/types/shaders-tsl/chunks/environment-ground-field.d.ts +40 -0
- package/types/shaders-tsl/chunks/environment-lighting.d.ts +22 -0
- package/types/shaders-tsl/chunks/environment-state.d.ts +42 -0
- package/types/shaders-tsl/chunks/environment-sun-shadow.d.ts +19 -0
- package/types/shaders-tsl/chunks/foliage-fog.d.ts +21 -0
- package/types/shaders-tsl/chunks/normalized-hue.d.ts +1 -0
- package/types/shaders-tsl/chunks/pass-depth-color.d.ts +20 -0
- package/types/shaders-tsl/chunks/projected-water-caustics.d.ts +24 -0
- package/types/shaders-tsl/chunks/scene-depth-color-pass.d.ts +39 -0
- package/types/shaders-tsl/chunks/stylized-cloud-shadow.d.ts +9 -0
- package/types/shaders-tsl/chunks/vegetation-style.d.ts +60 -0
- package/types/shaders-tsl/chunks/water-color.d.ts +15 -0
- package/types/shaders-tsl/chunks/water-common.d.ts +9 -0
- package/types/shaders-tsl/chunks/water-foam.d.ts +8 -0
- package/types/shaders-tsl/chunks/water-lighting.d.ts +9 -0
- package/types/shaders-tsl/chunks/water-ripple.d.ts +8 -0
- package/types/shaders-tsl/chunks/water-shore-state.d.ts +7 -0
- package/types/shaders-tsl/chunks/water-waves.d.ts +18 -0
- package/types/shaders-tsl/chunks/world-noise.d.ts +4 -0
- package/types/shaders-tsl/environment-ao-overlay.d.ts +5 -0
- package/types/shaders-tsl/environment.d.ts +34 -0
- package/types/shaders-tsl/flower.d.ts +6 -0
- package/types/shaders-tsl/grass.d.ts +4 -0
- package/types/shaders-tsl/post-composite.d.ts +25 -0
- package/types/shaders-tsl/sky.d.ts +4 -0
- package/types/shaders-tsl/tree-leaf.d.ts +2 -0
- package/types/shaders-tsl/water-breaker.d.ts +15 -0
- package/types/shaders-tsl/water-kelp.d.ts +5 -0
- package/types/shaders-tsl/water-rain.d.ts +10 -0
- package/types/shaders-tsl/water-shore-state-simulation.d.ts +12 -0
- package/types/shaders-tsl/water-simulation.d.ts +5 -0
- package/types/shaders-tsl/water-splash.d.ts +12 -0
- package/types/shaders-tsl/water.d.ts +22 -0
- package/types/shaders-tsl/woody-surface.d.ts +3 -0
- package/types/sky/atmosphereDome.d.ts +2 -0
- package/types/sky/atmosphereParams.d.ts +185 -0
- package/types/sky/atmosphereScattering.d.ts +11 -0
- package/types/sky/atmosphereSky.d.ts +2 -0
- package/types/sky/cloudShadow.d.ts +68 -0
- package/types/sky/godRays.d.ts +5 -0
- package/types/sky/index.d.ts +18 -0
- package/types/sky/nightSky.d.ts +22 -0
- package/types/sky/renderLayers.d.ts +59 -0
- package/types/sky/sceneOverrideLayers.d.ts +10 -0
- package/types/sky/skyColor.d.ts +704 -0
- package/types/sky/skyDayCycle.d.ts +86 -0
- package/types/sky/skyParams.d.ts +3407 -0
- package/types/sky/skyPresets.d.ts +160 -0
- package/types/sky/skyQuality.d.ts +21 -0
- package/types/sky/skyQualityTiers.d.ts +223 -0
- package/types/sky/skyShaderSettings.d.ts +152 -0
- package/types/sky/skyStyleSnapshots.d.ts +11 -0
- package/types/sky/skySystem.d.ts +3 -0
- package/types/sky/skyTimeKeyframes.d.ts +230 -0
- package/types/sky/stylizedSky.d.ts +341 -0
- package/types/sky/sunDriver.d.ts +15 -0
- package/types/sky/timeOfDay.d.ts +145 -0
- package/types/styles/animeGameProfile.d.ts +27 -0
- package/types/styles/index.d.ts +17 -0
- package/types/styles/manufacturedStyleLabeling.d.ts +119 -0
- package/types/styles/sceneLayerDocuments.d.ts +145 -0
- package/types/styles/sceneLookComposition.d.ts +53 -0
- package/types/styles/sceneQualityApplication.d.ts +34 -0
- package/types/styles/sceneQualityProfiles.d.ts +13 -0
- package/types/styles/sceneStyleAudit.d.ts +80 -0
- package/types/styles/sceneStyleRuntime.d.ts +1782 -0
- package/types/styles/styleAdapters.d.ts +14 -0
- package/types/styles/styleApplication.d.ts +47 -0
- package/types/styles/styleBundle.d.ts +19 -0
- package/types/styles/styleBundleProvider.d.ts +44 -0
- package/types/styles/styleDomains.d.ts +18 -0
- package/types/styles/styleInspector.d.ts +59 -0
- package/types/styles/styleMaterialContract.d.ts +46 -0
- package/types/styles/styleMetadata.d.ts +11 -0
- package/types/styles/styleTargetDiscovery.d.ts +48 -0
- package/types/styles/styleTargetLabels.d.ts +32 -0
- package/types/styles/styleTargetMaterialCoverage.d.ts +20 -0
- package/types/styles/styleTransaction.d.ts +10 -0
- package/types/styles/styleTypes.d.ts +66 -0
- package/types/texgen/evaluateTexture.d.ts +40 -0
- package/types/texgen/index.d.ts +7 -0
- package/types/texgen/noise2.d.ts +46 -0
- package/types/texgen/textureAi.d.ts +6 -0
- package/types/texgen/textureGenerators.d.ts +261 -0
- package/types/texgen/texturePresets.d.ts +45 -0
- package/types/texgen/textureSettings.d.ts +121 -0
- package/types/texgen/textureThree.d.ts +13 -0
- package/types/toon/characterRenderPasses.d.ts +3 -0
- package/types/toon/index.d.ts +3 -0
- package/types/toon/settings/alphaSettings.d.ts +125 -0
- package/types/toon/settings/averageShadowSettings.d.ts +39 -0
- package/types/toon/settings/baseTextureSettings.d.ts +39 -0
- package/types/toon/settings/celShadeSettings.d.ts +37 -0
- package/types/toon/settings/contactShadowSettings.d.ts +30 -0
- package/types/toon/settings/eyeHighlightSettings.d.ts +55 -0
- package/types/toon/settings/faceLightingSettings.d.ts +32 -0
- package/types/toon/settings/furSettings.d.ts +23 -0
- package/types/toon/settings/glitterSettings.d.ts +43 -0
- package/types/toon/settings/hairHighlightSettings.d.ts +89 -0
- package/types/toon/settings/indirectLightSettings.d.ts +43 -0
- package/types/toon/settings/localLightSettings.d.ts +46 -0
- package/types/toon/settings/materialMapSettings.d.ts +86 -0
- package/types/toon/settings/outlineSettings.d.ts +125 -0
- package/types/toon/settings/perspectiveRemovalSettings.d.ts +14 -0
- package/types/toon/settings/rimLightSettings.d.ts +79 -0
- package/types/toon/settings/sceneShadowSettings.d.ts +32 -0
- package/types/toon/settings/selfShadowSettings.d.ts +44 -0
- package/types/toon/settings/shadowColorSettings.d.ts +77 -0
- package/types/toon/settings/skinToneSettings.d.ts +30 -0
- package/types/toon/settings/specularSettings.d.ts +96 -0
- package/types/toon/settings/stickerSettings.d.ts +40 -0
- package/types/toon/toonMaterialAdapter.d.ts +883 -0
- package/types/toon/toonSettings.d.ts +1182 -0
- package/types/vegetation/branchTree.d.ts +10 -0
- package/types/vegetation/callMeSenseiGrass.d.ts +8 -0
- package/types/vegetation/compiledTree.d.ts +75 -0
- package/types/vegetation/contactShadowField.d.ts +26 -0
- package/types/vegetation/flowerSpecies.d.ts +107 -0
- package/types/vegetation/grass.d.ts +4 -0
- package/types/vegetation/grassClump.d.ts +7 -0
- package/types/vegetation/grassPalettes.d.ts +29 -0
- package/types/vegetation/importedVegetationMaterial.d.ts +13 -0
- package/types/vegetation/index.d.ts +216 -0
- package/types/vegetation/legacyTreePresets.d.ts +22 -0
- package/types/vegetation/scatter.d.ts +12 -0
- package/types/vegetation/stylizedBush.d.ts +2 -0
- package/types/vegetation/stylizedFlower.d.ts +2 -0
- package/types/vegetation/stylizedFlowers.d.ts +8 -0
- package/types/vegetation/stylizedForest.d.ts +3 -0
- package/types/vegetation/stylizedGrass.d.ts +21 -0
- package/types/vegetation/stylizedTree.d.ts +19 -0
- package/types/vegetation/stylizedTreeFoliage.d.ts +18 -0
- package/types/vegetation/stylizedUnderstory.d.ts +50 -0
- package/types/vegetation/treeExport.d.ts +6 -0
- package/types/vegetation/treeSurfaceTextures.d.ts +72 -0
- package/types/vegetation/vegetationShaders.d.ts +74 -0
- package/types/version.d.ts +1 -0
- package/types/water/index.d.ts +1 -0
- package/types/water/sceneOverrideLayers.d.ts +16 -0
- package/types/water/water.d.ts +17 -0
- package/types/water/waterBreakerSystem.d.ts +46 -0
- package/types/water/waterCurrentField.d.ts +115 -0
- package/types/water/waterInteraction.d.ts +21 -0
- package/types/water/waterMaterial.d.ts +60 -0
- package/types/water/waterNearshorePhase.d.ts +5 -0
- package/types/water/waterRain.d.ts +17 -0
- package/types/water/waterRippleSimulation.d.ts +52 -0
- package/types/water/waterScenePasses.d.ts +70 -0
- package/types/water/waterSettings.d.ts +648 -0
- package/types/water/waterShoreMaterial.d.ts +3 -0
- package/types/water/waterShoreStateField.d.ts +2 -0
- package/types/water/waterSplashSystem.d.ts +2 -0
- package/types/water/waterStageSettings.d.ts +9 -0
- package/types/water/waterSurface.d.ts +2 -0
- package/types/water/waterUnderwaterAtmosphere.d.ts +103 -0
- package/types/water/waterVegetation.d.ts +16 -0
- package/types/worldCollision.d.ts +22 -0
- package/AGENTS.md +0 -254
- package/ATTRIBUTION.md +0 -78
- package/docs/characters.md +0 -144
- package/docs/debug-panel.md +0 -126
- package/docs/docs.css +0 -589
- package/docs/environment.md +0 -186
- package/docs/getting-started.md +0 -180
- package/docs/index.html +0 -14
- package/docs/lab-architecture.md +0 -100
- package/docs/lighting.md +0 -825
- package/docs/main.jsx +0 -739
- package/docs/mcp.md +0 -97
- package/docs/post-processing.md +0 -98
- package/docs/settings-reference.md +0 -1878
- package/docs/shader-constants.md +0 -77
- package/docs/sky.md +0 -182
- package/docs/style-labs.md +0 -309
- package/docs/texture-lab.md +0 -135
- package/docs/toon-shading.md +0 -183
- package/docs/tsl-conventions.md +0 -167
- package/docs/vegetation-sky.md +0 -275
- package/docs/water.md +0 -430
- package/docs/weather.md +0 -200
- package/docs/world-scale.md +0 -111
- package/mcp/style-lab-tools.mjs +0 -371
- package/src/ambientfx/INTEGRATION.md +0 -164
- package/src/ambientfx/ambientFxPresets.js +0 -83
- package/src/ambientfx/ambientFxSettings.js +0 -368
- package/src/ambientfx/emitters.js +0 -169
- package/src/ambientfx/index.js +0 -5
- package/src/ambientfx/particleBackbone.js +0 -493
- package/src/ambientfx/stylizedAmbientFx.js +0 -450
- package/src/biome/biomeGenerator.js +0 -385
- package/src/biome/biomeRuntime.js +0 -299
- package/src/biome/index.js +0 -2
- package/src/buildinggen/buildingAsset.js +0 -44
- package/src/buildinggen/buildingGrammar.js +0 -311
- package/src/buildinggen/buildingMesh.js +0 -451
- package/src/buildinggen/buildingPresets.js +0 -46
- package/src/buildinggen/buildingRecipe.js +0 -100
- package/src/buildinggen/buildingSettings.js +0 -238
- package/src/buildinggen/index.js +0 -6
- package/src/camera/cameraDirector.js +0 -157
- package/src/camera/cameraGenerator.js +0 -367
- package/src/camera/cameraRig.js +0 -570
- package/src/camera/cameraSettings.js +0 -236
- package/src/camera/index.js +0 -7
- package/src/catalog/builtinEntries.js +0 -245
- package/src/catalog/catalog.js +0 -210
- package/src/catalog/index.js +0 -3
- package/src/core/shaderBackend.js +0 -24
- package/src/debrisgen/debrisFields.js +0 -544
- package/src/debrisgen/debrisGenerator.js +0 -1929
- package/src/debrisgen/debrisPalettes.js +0 -71
- package/src/debrisgen/debrisPhysics.js +0 -198
- package/src/debrisgen/debrisPresets.js +0 -162
- package/src/debrisgen/debrisSettings.js +0 -333
- package/src/debrisgen/debrisTextures.js +0 -380
- package/src/debrisgen/index.js +0 -5
- package/src/debug/fieldValues.js +0 -95
- package/src/debug/index.js +0 -7
- package/src/debug/settingsPanel.js +0 -170
- package/src/fauna/INTEGRATION.md +0 -174
- package/src/fauna/boids.js +0 -861
- package/src/fauna/faunaBodies.js +0 -492
- package/src/fauna/faunaPresets.js +0 -52
- package/src/fauna/faunaSettings.js +0 -525
- package/src/fauna/index.js +0 -5
- package/src/fauna/stylizedFauna.js +0 -395
- package/src/game-feel/gameFeelGenerator.js +0 -402
- package/src/game-feel/gameFeelRuntime.js +0 -549
- package/src/game-feel/index.js +0 -2
- package/src/motion/index.js +0 -5
- package/src/motion/motionClip.js +0 -441
- package/src/motion/motionController.js +0 -628
- package/src/motion/motionDocuments.js +0 -225
- package/src/motion/motionGraph.js +0 -307
- package/src/motion/motionSettings.js +0 -222
- package/src/pathgen/index.js +0 -7
- package/src/pathgen/pathBridge.js +0 -232
- package/src/pathgen/pathPresets.js +0 -35
- package/src/pathgen/pathRibbon.js +0 -410
- package/src/pathgen/pathRouter.js +0 -380
- package/src/pathgen/pathSettings.js +0 -335
- package/src/pathgen/pathTextures.js +0 -123
- package/src/pathgen/stylizedPaths.js +0 -453
- package/src/propgen/generatorsWave1.js +0 -379
- package/src/propgen/generatorsWave2.js +0 -462
- package/src/propgen/index.js +0 -5
- package/src/propgen/propAsset.js +0 -323
- package/src/propgen/propParts.js +0 -170
- package/src/propgen/propPlacement.js +0 -459
- package/src/propgen/propPresets.js +0 -82
- package/src/propgen/propSettings.js +0 -395
- package/src/soundscape/index.js +0 -4
- package/src/soundscape/soundscapeGenerator.js +0 -179
- package/src/soundscape/soundscapeRuntime.js +0 -806
- package/src/soundscape/soundscapeSettings.js +0 -292
- package/src/stylizedTerrain.js +0 -631
- package/src/stylizedWorld.js +0 -903
- package/src/vegetation/treeRecipe.js +0 -647
- package/src/vfxgen/INTEGRATION.md +0 -145
- package/src/vfxgen/core/burstBackbone.js +0 -380
- package/src/vfxgen/core/projectileCore.js +0 -92
- package/src/vfxgen/core/spriteShapes.js +0 -98
- package/src/vfxgen/core/trailRibbon.js +0 -272
- package/src/vfxgen/core/vfxRandom.js +0 -29
- package/src/vfxgen/effects/emitHelpers.js +0 -37
- package/src/vfxgen/effects/magicEffects.js +0 -162
- package/src/vfxgen/effects/movementEffects.js +0 -87
- package/src/vfxgen/effects/weaponEffects.js +0 -118
- package/src/vfxgen/index.js +0 -18
- package/src/vfxgen/moves/moveController.js +0 -146
- package/src/vfxgen/moves/moveLibrary.js +0 -335
- package/src/vfxgen/vfxPresets.js +0 -98
- package/src/vfxgen/vfxSettings.js +0 -384
- package/src/vfxgen/vfxSystem.js +0 -449
- package/src/vfxgen/weapons/stylizedWeapons.js +0 -137
- package/src/villagegen/index.js +0 -4
- package/src/villagegen/stylizedVillage.js +0 -490
- package/src/villagegen/villageArchetypes.js +0 -160
- package/src/villagegen/villageNames.js +0 -40
- package/src/villagegen/villageSites.js +0 -105
- package/src/weather/index.js +0 -6
- package/src/weather/weatherPrecipitation.js +0 -221
- package/src/weather/weatherPresets.js +0 -258
- package/src/weather/weatherSettings.js +0 -269
- package/src/weather/weatherSystem.js +0 -871
- package/src/worldMinimap.js +0 -214
- package/src/worldPresets.js +0 -125
package/src/fauna/boids.js
DELETED
|
@@ -1,861 +0,0 @@
|
|
|
1
|
-
// Steering core for the fauna layer — classic boids with cheap XZ spatial
|
|
2
|
-
// hashing, staggered ticks, and hard budgets. Pure JS with no THREE
|
|
3
|
-
// dependency so scripts/verify-fauna.mjs can run the whole simulation in
|
|
4
|
-
// Node and assert the invariants (fish depth clamps, mask compliance, tick
|
|
5
|
-
// budgets, determinism).
|
|
6
|
-
//
|
|
7
|
-
// The split of work is the whole performance story:
|
|
8
|
-
// - a full steering TICK (neighbor search, forces, rand-gated decisions,
|
|
9
|
-
// heightAt cache refresh) touches at most `tickShare` (default 1/4) of
|
|
10
|
-
// all agents per update, walked round-robin;
|
|
11
|
-
// - INTEGRATION (pos += v·dt, clamps, heading smoothing) runs for every
|
|
12
|
-
// agent every frame — a few flops each, so motion stays 60 Hz smooth
|
|
13
|
-
// while steering runs at ~15 Hz;
|
|
14
|
-
// - agents farther than `farDistance` from the follow target skip steering
|
|
15
|
-
// entirely and fly scripted circles (their tick only refreshes terrain
|
|
16
|
-
// caches), so a distant flock costs integration alone.
|
|
17
|
-
//
|
|
18
|
-
// Determinism: one mulberry32 stream per agent (seeded from the world seed),
|
|
19
|
-
// advanced only inside that agent's own ticks; the walk order is fixed; no
|
|
20
|
-
// Math.random anywhere. Same seed + same update(dt) sequence → the same sky.
|
|
21
|
-
|
|
22
|
-
import {
|
|
23
|
-
createFaunaSettings,
|
|
24
|
-
FAUNA_SPECIES,
|
|
25
|
-
normalizeFaunaPopulations,
|
|
26
|
-
} from './faunaSettings.js';
|
|
27
|
-
|
|
28
|
-
export const FAUNA_STATE = Object.freeze({
|
|
29
|
-
FLY: 0, // also HOVER for dragonflies
|
|
30
|
-
APPROACH: 1, // bird gliding to a claimed perch
|
|
31
|
-
PERCHED: 2,
|
|
32
|
-
DART: 3, // dragonfly relocating
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
function mulberry32(seed) {
|
|
36
|
-
let state = (Math.trunc(seed) || 1) >>> 0;
|
|
37
|
-
return () => {
|
|
38
|
-
state = (state + 0x6d2b79f5) >>> 0;
|
|
39
|
-
let t = state;
|
|
40
|
-
t = Math.imul(t ^ (t >>> 15), t | 1);
|
|
41
|
-
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
|
|
42
|
-
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export function hashCombine(a, b) {
|
|
47
|
-
let h = (Math.imul(Math.trunc(a) | 0, 0x9e3779b1) ^ Math.imul(Math.trunc(b) | 0, 0x85ebca77)) | 0;
|
|
48
|
-
h = Math.imul(h ^ (h >>> 13), 0xc2b2ae35);
|
|
49
|
-
return (h ^ (h >>> 16)) >>> 0;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// Per-agent rng: mulberry32 with the state array as backing store.
|
|
53
|
-
function nextRand(states, i) {
|
|
54
|
-
const s = (states[i] + 0x6d2b79f5) >>> 0;
|
|
55
|
-
states[i] = s;
|
|
56
|
-
let t = s;
|
|
57
|
-
t = Math.imul(t ^ (t >>> 15), t | 1);
|
|
58
|
-
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
|
|
59
|
-
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function sampleHeight(heightAt, x, z) {
|
|
63
|
-
if (typeof heightAt !== 'function') return 0;
|
|
64
|
-
const y = Number(heightAt(x, z));
|
|
65
|
-
return Number.isFinite(y) ? y : 0;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
function normalizeBounds(bounds) {
|
|
69
|
-
if (typeof bounds === 'number' && Number.isFinite(bounds)) {
|
|
70
|
-
const half = Math.max(Math.abs(bounds), 10);
|
|
71
|
-
return { minX: -half, maxX: half, minZ: -half, maxZ: half };
|
|
72
|
-
}
|
|
73
|
-
const source = bounds && typeof bounds === 'object' ? bounds : {};
|
|
74
|
-
if (source.min && source.max) {
|
|
75
|
-
return {
|
|
76
|
-
minX: Number(source.min.x) || -200, maxX: Number(source.max.x) || 200,
|
|
77
|
-
minZ: Number(source.min.z) || -200, maxZ: Number(source.max.z) || 200,
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
const hx = Math.max(Math.abs(Number(source.x) || 200), 10);
|
|
81
|
-
const hz = Math.max(Math.abs(Number(source.z) || Number(source.x) || 200), 10);
|
|
82
|
-
return { minX: -hx, maxX: hx, minZ: -hz, maxZ: hz };
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
function makeArrays(count) {
|
|
86
|
-
return {
|
|
87
|
-
px: new Float32Array(count), py: new Float32Array(count), pz: new Float32Array(count),
|
|
88
|
-
vx: new Float32Array(count), vy: new Float32Array(count), vz: new Float32Array(count),
|
|
89
|
-
heading: new Float32Array(count), bank: new Float32Array(count),
|
|
90
|
-
phase: new Float32Array(count), speedMul: new Float32Array(count), scale: new Float32Array(count),
|
|
91
|
-
variant: new Uint8Array(count), state: new Uint8Array(count), far: new Uint8Array(count),
|
|
92
|
-
amp: new Float32Array(count), ampTarget: new Float32Array(count),
|
|
93
|
-
fold: new Float32Array(count), foldTarget: new Float32Array(count),
|
|
94
|
-
timer: new Float32Array(count), cooldown: new Float32Array(count),
|
|
95
|
-
groundY: new Float32Array(count), // terrain cache (bed for fish)
|
|
96
|
-
homeX: new Float32Array(count), homeY: new Float32Array(count), homeZ: new Float32Array(count),
|
|
97
|
-
target: new Int32Array(count).fill(-1), // perch index for birds
|
|
98
|
-
turn: new Float32Array(count), // scripted-loop yaw rate (rad/s)
|
|
99
|
-
lastTick: new Float32Array(count),
|
|
100
|
-
hoverBias: new Float32Array(count), // per-agent band position 0..1
|
|
101
|
-
wf: new Float32Array(count * 4), // wander sinusoid freqs/phases
|
|
102
|
-
rng: new Uint32Array(count),
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// Rejection-samples `count` points passing `accept(x, z)`; degrades to fewer
|
|
107
|
-
// points instead of hanging when the mask is starved.
|
|
108
|
-
function samplePool(rng, bounds, count, accept) {
|
|
109
|
-
const pool = [];
|
|
110
|
-
const spanX = bounds.maxX - bounds.minX;
|
|
111
|
-
const spanZ = bounds.maxZ - bounds.minZ;
|
|
112
|
-
let attempts = Math.max(count, 1) * 60;
|
|
113
|
-
while (pool.length < count && attempts > 0) {
|
|
114
|
-
attempts -= 1;
|
|
115
|
-
const x = bounds.minX + rng() * spanX;
|
|
116
|
-
const z = bounds.minZ + rng() * spanZ;
|
|
117
|
-
if (accept(x, z)) pool.push({ x, z });
|
|
118
|
-
}
|
|
119
|
-
return pool;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* Creates the CPU fauna simulation. All coordinates are world meters.
|
|
124
|
-
*
|
|
125
|
-
* @param {Object} options
|
|
126
|
-
* @param {number} [options.seed]
|
|
127
|
-
* @param {Function} [options.heightAt] `(x, z) => y` terrain sampler.
|
|
128
|
-
* @param {number} [options.waterLevel]
|
|
129
|
-
* @param {number|{x,z}|{min,max}} [options.bounds] Roaming rectangle.
|
|
130
|
-
* @param {Object} [options.species] Populations `{ birds, butterflies, dragonflies, fish }`.
|
|
131
|
-
* @param {Object} [options.masks] `{ flowers?: (x, z) => boolean }` butterfly anchor mask.
|
|
132
|
-
* @param {Object} [options.settings] Grouped overrides (see createFaunaSettings).
|
|
133
|
-
* @param {Array} [options.perchPoints] Initial `{ x, y, z }` roosts.
|
|
134
|
-
* @param {Object} [options.variantCounts] Geometry variants per species (the
|
|
135
|
-
* renderer passes the palette's real scheme count; variant assignment
|
|
136
|
-
* happens here so it is deterministic and Node-testable).
|
|
137
|
-
*/
|
|
138
|
-
export function createFaunaSimulation({
|
|
139
|
-
seed = 1,
|
|
140
|
-
heightAt = null,
|
|
141
|
-
waterLevel = 0,
|
|
142
|
-
bounds = 240,
|
|
143
|
-
species = {},
|
|
144
|
-
masks = {},
|
|
145
|
-
settings = {},
|
|
146
|
-
perchPoints = [],
|
|
147
|
-
variantCounts: variantCountsOption = {},
|
|
148
|
-
} = {}) {
|
|
149
|
-
const cfg = createFaunaSettings(settings);
|
|
150
|
-
const populations = normalizeFaunaPopulations(species);
|
|
151
|
-
const box = normalizeBounds(bounds);
|
|
152
|
-
const rootRng = mulberry32(hashCombine(Math.round(Number(seed) || 1), 0xfa07a));
|
|
153
|
-
const ground = (x, z) => sampleHeight(heightAt, x, z);
|
|
154
|
-
const flowerMask = typeof masks?.flowers === 'function' ? masks.flowers : null;
|
|
155
|
-
|
|
156
|
-
// --- shared pools ---------------------------------------------------------
|
|
157
|
-
|
|
158
|
-
// Terrain roosts used when no host cluster has registered perch points yet.
|
|
159
|
-
const perches = [];
|
|
160
|
-
const addPerchPoints = (points) => {
|
|
161
|
-
for (const p of points ?? []) {
|
|
162
|
-
if (!Number.isFinite(p?.x) || !Number.isFinite(p?.z)) continue;
|
|
163
|
-
perches.push({
|
|
164
|
-
occupant: -1,
|
|
165
|
-
x: Number(p.x),
|
|
166
|
-
y: Number.isFinite(p.y) ? Number(p.y) : ground(p.x, p.z),
|
|
167
|
-
z: Number(p.z),
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
};
|
|
171
|
-
if (Array.isArray(perchPoints) && perchPoints.length > 0) addPerchPoints(perchPoints);
|
|
172
|
-
if (perches.length === 0 && populations.birds > 0) {
|
|
173
|
-
addPerchPoints(samplePool(rootRng, box, 24, (x, z) => ground(x, z) > waterLevel + 0.5)
|
|
174
|
-
.map((p) => ({ x: p.x, y: ground(p.x, p.z) + 0.15, z: p.z })));
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
// Butterfly anchors come FROM the mask, so wandering around an anchor
|
|
178
|
-
// (radius-capped) keeps agents over the flower field by construction.
|
|
179
|
-
// Fewer anchors than agents on purpose: shared anchors read as the flower
|
|
180
|
-
// clumps butterflies gather on, instead of a uniform sprinkle.
|
|
181
|
-
const dryLand = (x, z) => ground(x, z) > waterLevel + 0.2;
|
|
182
|
-
const flowerPool = populations.butterflies > 0
|
|
183
|
-
? samplePool(rootRng, box, Math.max(8, Math.ceil(populations.butterflies / 5)),
|
|
184
|
-
flowerMask ? (x, z) => flowerMask(x, z) && dryLand(x, z) : dryLand)
|
|
185
|
-
: [];
|
|
186
|
-
|
|
187
|
-
// Dragonfly anchors hover the shallow-water margin (bed just below the
|
|
188
|
-
// waterline). Falls back to any water, then to the butterfly pool.
|
|
189
|
-
const shoreWater = (x, z) => {
|
|
190
|
-
const bed = ground(x, z);
|
|
191
|
-
return bed < waterLevel - 0.15 && bed > waterLevel - 3.5;
|
|
192
|
-
};
|
|
193
|
-
let dragonPool = populations.dragonflies > 0
|
|
194
|
-
? samplePool(rootRng, box, Math.max(6, Math.ceil(populations.dragonflies / 2)), shoreWater)
|
|
195
|
-
: [];
|
|
196
|
-
if (populations.dragonflies > 0 && dragonPool.length === 0) {
|
|
197
|
-
dragonPool = samplePool(rootRng, box, Math.max(12, populations.dragonflies),
|
|
198
|
-
(x, z) => ground(x, z) < waterLevel - 0.15);
|
|
199
|
-
}
|
|
200
|
-
if (populations.dragonflies > 0 && dragonPool.length === 0) dragonPool = flowerPool;
|
|
201
|
-
|
|
202
|
-
// --- species construction -------------------------------------------------
|
|
203
|
-
|
|
204
|
-
const speciesStates = {};
|
|
205
|
-
|
|
206
|
-
function initCommon(state, i, x, y, z, s, headingAngle, speed) {
|
|
207
|
-
const a = state.arrays;
|
|
208
|
-
a.px[i] = x; a.py[i] = y; a.pz[i] = z;
|
|
209
|
-
a.vx[i] = Math.sin(headingAngle) * speed;
|
|
210
|
-
a.vy[i] = 0;
|
|
211
|
-
a.vz[i] = Math.cos(headingAngle) * speed;
|
|
212
|
-
a.heading[i] = headingAngle;
|
|
213
|
-
a.rng[i] = hashCombine(hashCombine(seed, state.speciesIndex * 0x51ed), i + 1);
|
|
214
|
-
const r = () => nextRand(a.rng, i);
|
|
215
|
-
a.variant[i] = Math.floor(r() * state.variantCount) % state.variantCount;
|
|
216
|
-
a.phase[i] = r() * Math.PI * 2;
|
|
217
|
-
a.speedMul[i] = 0.85 + r() * 0.3;
|
|
218
|
-
a.scale[i] = s * (1 - state.scaleJitter / 2 + r() * state.scaleJitter);
|
|
219
|
-
a.amp[i] = 1; a.ampTarget[i] = 1;
|
|
220
|
-
a.turn[i] = (r() < 0.5 ? -1 : 1) * (0.25 + r() * 0.3);
|
|
221
|
-
a.hoverBias[i] = r();
|
|
222
|
-
a.wf[i * 4] = 0.25 + r() * 0.5;
|
|
223
|
-
a.wf[i * 4 + 1] = r() * Math.PI * 2;
|
|
224
|
-
a.wf[i * 4 + 2] = 0.3 + r() * 0.55;
|
|
225
|
-
a.wf[i * 4 + 3] = r() * Math.PI * 2;
|
|
226
|
-
a.groundY[i] = ground(x, z);
|
|
227
|
-
a.lastTick[i] = -r() * 0.25; // desync first ticks
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
function makeSpecies(name, index, count, variantCount, scaleJitter, cellSize) {
|
|
231
|
-
const state = {
|
|
232
|
-
arrays: makeArrays(count),
|
|
233
|
-
cell: Math.max(cellSize, 1),
|
|
234
|
-
count,
|
|
235
|
-
grid: new Map(),
|
|
236
|
-
gridStamp: -1,
|
|
237
|
-
name,
|
|
238
|
-
scaleJitter,
|
|
239
|
-
speciesIndex: index,
|
|
240
|
-
variantCount: Math.max(1, variantCount),
|
|
241
|
-
};
|
|
242
|
-
speciesStates[name] = state;
|
|
243
|
-
return state;
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
const variantCounts = {
|
|
247
|
-
birds: 3, butterflies: 4, dragonflies: 3, fish: 4,
|
|
248
|
-
...(variantCountsOption && typeof variantCountsOption === 'object' ? variantCountsOption : {}),
|
|
249
|
-
};
|
|
250
|
-
|
|
251
|
-
// Birds spawn in a few flock clusters so the first frame already reads as
|
|
252
|
-
// flocks, not confetti.
|
|
253
|
-
{
|
|
254
|
-
const s = makeSpecies('birds', 0, populations.birds, variantCounts.birds, 0.24, cfg.birds.neighborRadius);
|
|
255
|
-
const clusters = samplePool(rootRng, box, Math.max(1, Math.ceil(s.count / 16)), () => true);
|
|
256
|
-
for (let i = 0; i < s.count; i += 1) {
|
|
257
|
-
const c = clusters[i % Math.max(clusters.length, 1)] ?? { x: 0, z: 0 };
|
|
258
|
-
const x = c.x + (rootRng() - 0.5) * 24;
|
|
259
|
-
const z = c.z + (rootRng() - 0.5) * 24;
|
|
260
|
-
const g = ground(x, z);
|
|
261
|
-
const y = g + cfg.birds.altitudeMin
|
|
262
|
-
+ rootRng() * Math.max(cfg.birds.altitudeMax - cfg.birds.altitudeMin, 1);
|
|
263
|
-
initCommon(s, i, x, y, z, cfg.birds.scale, rootRng() * Math.PI * 2, cfg.birds.cruiseSpeed);
|
|
264
|
-
s.arrays.timer[i] = 2 + rootRng() * 6; // perch-decision cooldown
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
{
|
|
269
|
-
const s = makeSpecies('butterflies', 1, populations.butterflies, variantCounts.butterflies, 0.4, 4);
|
|
270
|
-
for (let i = 0; i < s.count; i += 1) {
|
|
271
|
-
const anchor = flowerPool.length > 0 ? flowerPool[i % flowerPool.length] : { x: 0, z: 0 };
|
|
272
|
-
const x = anchor.x + (rootRng() - 0.5) * 3;
|
|
273
|
-
const z = anchor.z + (rootRng() - 0.5) * 3;
|
|
274
|
-
const g = ground(x, z);
|
|
275
|
-
const y = g + cfg.butterflies.hoverMin
|
|
276
|
-
+ rootRng() * Math.max(cfg.butterflies.hoverMax - cfg.butterflies.hoverMin, 0.1);
|
|
277
|
-
initCommon(s, i, x, y, z, cfg.butterflies.scale, rootRng() * Math.PI * 2, cfg.butterflies.speed * 0.6);
|
|
278
|
-
s.arrays.homeX[i] = anchor.x;
|
|
279
|
-
s.arrays.homeZ[i] = anchor.z;
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
{
|
|
284
|
-
const s = makeSpecies('dragonflies', 2, populations.dragonflies, variantCounts.dragonflies, 0.3, 5);
|
|
285
|
-
for (let i = 0; i < s.count; i += 1) {
|
|
286
|
-
const anchor = dragonPool.length > 0 ? dragonPool[i % dragonPool.length] : { x: 0, z: 0 };
|
|
287
|
-
const x = anchor.x + (rootRng() - 0.5) * 2;
|
|
288
|
-
const z = anchor.z + (rootRng() - 0.5) * 2;
|
|
289
|
-
initCommon(s, i, x, waterLevel + cfg.dragonflies.hoverHeight, z,
|
|
290
|
-
cfg.dragonflies.scale, rootRng() * Math.PI * 2, 0.4);
|
|
291
|
-
s.arrays.homeX[i] = anchor.x;
|
|
292
|
-
s.arrays.homeZ[i] = anchor.z;
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
// Fish spawn in schools at points with enough water column; a world with
|
|
297
|
-
// no qualifying water simply holds zero fish (population budget, not error).
|
|
298
|
-
{
|
|
299
|
-
const deepEnough = (x, z) => waterLevel - ground(x, z) >= cfg.fish.minSpawnDepth;
|
|
300
|
-
const schools = populations.fish > 0
|
|
301
|
-
? samplePool(rootRng, box, Math.max(1, Math.ceil(populations.fish / 14)), deepEnough)
|
|
302
|
-
: [];
|
|
303
|
-
const count = schools.length > 0 ? populations.fish : 0;
|
|
304
|
-
const s = makeSpecies('fish', 3, count, variantCounts.fish, 0.5, cfg.fish.neighborRadius);
|
|
305
|
-
for (let i = 0; i < s.count; i += 1) {
|
|
306
|
-
const c = schools[i % schools.length];
|
|
307
|
-
let x = c.x;
|
|
308
|
-
let z = c.z;
|
|
309
|
-
for (let attempt = 0; attempt < 8; attempt += 1) {
|
|
310
|
-
const cx = c.x + (rootRng() - 0.5) * 8;
|
|
311
|
-
const cz = c.z + (rootRng() - 0.5) * 8;
|
|
312
|
-
if (deepEnough(cx, cz)) { x = cx; z = cz; break; }
|
|
313
|
-
}
|
|
314
|
-
const bed = ground(x, z);
|
|
315
|
-
const lo = bed + cfg.fish.bedMargin;
|
|
316
|
-
const hi = waterLevel - cfg.fish.surfaceMargin;
|
|
317
|
-
const y = Math.max(hi - (0.4 + rootRng() * 1.6), lo + 0.2);
|
|
318
|
-
initCommon(s, i, x, y, z, cfg.fish.scale, rootRng() * Math.PI * 2, cfg.fish.cruiseSpeed);
|
|
319
|
-
s.arrays.py[i] = Math.min(Math.max(y, lo), Math.max(hi, lo));
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
// Fixed walk order for the staggered tick budget.
|
|
324
|
-
const walk = [];
|
|
325
|
-
for (const name of FAUNA_SPECIES) {
|
|
326
|
-
const s = speciesStates[name];
|
|
327
|
-
for (let i = 0; i < s.count; i += 1) walk.push({ i, s });
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
const stats = {
|
|
331
|
-
agents: Object.fromEntries(FAUNA_SPECIES.map((name) => [name, speciesStates[name].count])),
|
|
332
|
-
steeredLastUpdate: 0,
|
|
333
|
-
tickBudget: Math.max(1, Math.ceil(walk.length * cfg.shared.tickShare)),
|
|
334
|
-
total: walk.length,
|
|
335
|
-
updates: 0,
|
|
336
|
-
};
|
|
337
|
-
|
|
338
|
-
const sim = {
|
|
339
|
-
addPerchPoints,
|
|
340
|
-
bounds: box,
|
|
341
|
-
perches,
|
|
342
|
-
settings: cfg,
|
|
343
|
-
species: speciesStates,
|
|
344
|
-
stats,
|
|
345
|
-
time: 0,
|
|
346
|
-
waterLevel,
|
|
347
|
-
};
|
|
348
|
-
|
|
349
|
-
// --- spatial hash ----------------------------------------------------------
|
|
350
|
-
|
|
351
|
-
function rebuildGrid(state, stamp) {
|
|
352
|
-
if (state.gridStamp === stamp) return;
|
|
353
|
-
state.gridStamp = stamp;
|
|
354
|
-
state.grid.clear();
|
|
355
|
-
const { px, pz } = state.arrays;
|
|
356
|
-
const inv = 1 / state.cell;
|
|
357
|
-
for (let i = 0; i < state.count; i += 1) {
|
|
358
|
-
const key = ((Math.floor(px[i] * inv) + 1024) << 12) | ((Math.floor(pz[i] * inv) + 1024) & 0xfff);
|
|
359
|
-
const bucket = state.grid.get(key);
|
|
360
|
-
if (bucket) bucket.push(i);
|
|
361
|
-
else state.grid.set(key, [i]);
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
const flock = { ax: 0, ay: 0, az: 0 };
|
|
366
|
-
function accumulateFlock(state, i, radius, sepRadius, wCoh, wAli, wSep) {
|
|
367
|
-
const a = state.arrays;
|
|
368
|
-
const inv = 1 / state.cell;
|
|
369
|
-
const cx = Math.floor(a.px[i] * inv);
|
|
370
|
-
const cz = Math.floor(a.pz[i] * inv);
|
|
371
|
-
const radiusSq = radius * radius;
|
|
372
|
-
const sepSq = sepRadius * sepRadius;
|
|
373
|
-
let n = 0;
|
|
374
|
-
let sumX = 0; let sumY = 0; let sumZ = 0;
|
|
375
|
-
let velX = 0; let velY = 0; let velZ = 0;
|
|
376
|
-
let sepX = 0; let sepY = 0; let sepZ = 0;
|
|
377
|
-
for (let gx = cx - 1; gx <= cx + 1; gx += 1) {
|
|
378
|
-
for (let gz = cz - 1; gz <= cz + 1; gz += 1) {
|
|
379
|
-
const bucket = state.grid.get(((gx + 1024) << 12) | ((gz + 1024) & 0xfff));
|
|
380
|
-
if (!bucket) continue;
|
|
381
|
-
for (let b = 0; b < bucket.length; b += 1) {
|
|
382
|
-
const j = bucket[b];
|
|
383
|
-
if (j === i) continue;
|
|
384
|
-
const dx = a.px[j] - a.px[i];
|
|
385
|
-
const dy = a.py[j] - a.py[i];
|
|
386
|
-
const dz = a.pz[j] - a.pz[i];
|
|
387
|
-
const d2 = dx * dx + dy * dy + dz * dz;
|
|
388
|
-
if (d2 > radiusSq) continue;
|
|
389
|
-
n += 1;
|
|
390
|
-
sumX += a.px[j]; sumY += a.py[j]; sumZ += a.pz[j];
|
|
391
|
-
velX += a.vx[j]; velY += a.vy[j]; velZ += a.vz[j];
|
|
392
|
-
if (d2 < sepSq && d2 > 1e-6) {
|
|
393
|
-
const w = 1 / d2;
|
|
394
|
-
sepX -= dx * w; sepY -= dy * w; sepZ -= dz * w;
|
|
395
|
-
}
|
|
396
|
-
if (n >= 10) break; // cap: flocking quality saturates fast
|
|
397
|
-
}
|
|
398
|
-
if (n >= 10) break;
|
|
399
|
-
}
|
|
400
|
-
if (n >= 10) break;
|
|
401
|
-
}
|
|
402
|
-
if (n === 0) {
|
|
403
|
-
flock.ax = 0; flock.ay = 0; flock.az = 0;
|
|
404
|
-
return;
|
|
405
|
-
}
|
|
406
|
-
const invN = 1 / n;
|
|
407
|
-
flock.ax = (sumX * invN - a.px[i]) * wCoh + velX * invN * wAli + sepX * wSep;
|
|
408
|
-
flock.ay = (sumY * invN - a.py[i]) * wCoh * 0.5 + velY * invN * wAli * 0.5 + sepY * wSep;
|
|
409
|
-
flock.az = (sumZ * invN - a.pz[i]) * wCoh + velZ * invN * wAli + sepZ * wSep;
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
function clampSpeed(a, i, min, max) {
|
|
413
|
-
const speed = Math.hypot(a.vx[i], a.vy[i], a.vz[i]);
|
|
414
|
-
if (speed < 1e-5) return;
|
|
415
|
-
const clamped = Math.min(Math.max(speed, min), max);
|
|
416
|
-
if (clamped !== speed) {
|
|
417
|
-
const k = clamped / speed;
|
|
418
|
-
a.vx[i] *= k; a.vy[i] *= k; a.vz[i] *= k;
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
|
|
422
|
-
function boundsForce(a, i, dt, strength = 3) {
|
|
423
|
-
const margin = 10;
|
|
424
|
-
if (a.px[i] < box.minX + margin) a.vx[i] += strength * dt * (box.minX + margin - a.px[i]);
|
|
425
|
-
if (a.px[i] > box.maxX - margin) a.vx[i] += strength * dt * (box.maxX - margin - a.px[i]);
|
|
426
|
-
if (a.pz[i] < box.minZ + margin) a.vz[i] += strength * dt * (box.minZ + margin - a.pz[i]);
|
|
427
|
-
if (a.pz[i] > box.maxZ - margin) a.vz[i] += strength * dt * (box.maxZ - margin - a.pz[i]);
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
// --- species ticks ---------------------------------------------------------
|
|
431
|
-
|
|
432
|
-
function birdTick(state, i, dt, follow, stamp) {
|
|
433
|
-
const a = state.arrays;
|
|
434
|
-
const b = cfg.birds;
|
|
435
|
-
a.groundY[i] = ground(a.px[i], a.pz[i]);
|
|
436
|
-
a.cooldown[i] = Math.max(0, a.cooldown[i] - dt);
|
|
437
|
-
|
|
438
|
-
// TRUE 3D flee distance: a camera or player well above the flock is not
|
|
439
|
-
// a threat; a walker at perch height is.
|
|
440
|
-
const fx = follow ? a.px[i] - follow.x : 0;
|
|
441
|
-
const fy = follow ? a.py[i] - (follow.y ?? 0) : 0;
|
|
442
|
-
const fz = follow ? a.pz[i] - follow.z : 0;
|
|
443
|
-
const followD2 = follow ? fx * fx + fy * fy + fz * fz : Infinity;
|
|
444
|
-
|
|
445
|
-
if (a.state[i] === FAUNA_STATE.PERCHED) {
|
|
446
|
-
a.timer[i] -= dt;
|
|
447
|
-
if (a.timer[i] <= 0 || followD2 < b.fleeRadius * b.fleeRadius) {
|
|
448
|
-
// Flush: launch up and away, wings out.
|
|
449
|
-
const away = Math.max(Math.sqrt(followD2), 1e-3);
|
|
450
|
-
const dirX = follow && followD2 < b.fleeRadius * b.fleeRadius ? fx / away : Math.sin(a.heading[i]);
|
|
451
|
-
const dirZ = follow && followD2 < b.fleeRadius * b.fleeRadius ? fz / away : Math.cos(a.heading[i]);
|
|
452
|
-
if (a.target[i] >= 0 && perches[a.target[i]]) perches[a.target[i]].occupant = -1;
|
|
453
|
-
a.target[i] = -1;
|
|
454
|
-
a.state[i] = FAUNA_STATE.FLY;
|
|
455
|
-
a.foldTarget[i] = 0;
|
|
456
|
-
a.ampTarget[i] = 1;
|
|
457
|
-
a.vx[i] = dirX * b.cruiseSpeed * 1.2;
|
|
458
|
-
a.vy[i] = b.cruiseSpeed * 0.55;
|
|
459
|
-
a.vz[i] = dirZ * b.cruiseSpeed * 1.2;
|
|
460
|
-
a.cooldown[i] = 6 + nextRand(a.rng, i) * 8;
|
|
461
|
-
}
|
|
462
|
-
return;
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
if (a.state[i] === FAUNA_STATE.APPROACH) {
|
|
466
|
-
const perch = perches[a.target[i]];
|
|
467
|
-
if (!perch || perch.occupant !== i) { a.state[i] = FAUNA_STATE.FLY; a.target[i] = -1; return; }
|
|
468
|
-
const dx = perch.x - a.px[i];
|
|
469
|
-
const dy = perch.y - a.py[i];
|
|
470
|
-
const dz = perch.z - a.pz[i];
|
|
471
|
-
const dist = Math.hypot(dx, dy, dz);
|
|
472
|
-
if (dist < 0.6) {
|
|
473
|
-
a.px[i] = perch.x; a.py[i] = perch.y + 0.1; a.pz[i] = perch.z;
|
|
474
|
-
a.vx[i] = 0; a.vy[i] = 0; a.vz[i] = 0;
|
|
475
|
-
a.state[i] = FAUNA_STATE.PERCHED;
|
|
476
|
-
a.foldTarget[i] = 1;
|
|
477
|
-
a.ampTarget[i] = 0;
|
|
478
|
-
a.timer[i] = b.perchDuration * (0.6 + nextRand(a.rng, i) * 0.8);
|
|
479
|
-
return;
|
|
480
|
-
}
|
|
481
|
-
// Arrive: decelerating approach, gliding (low flap amplitude).
|
|
482
|
-
const arrive = Math.min(dist / 6, 1) * b.cruiseSpeed + 1.2;
|
|
483
|
-
const inv = arrive / Math.max(dist, 1e-4);
|
|
484
|
-
a.vx[i] += (dx * inv - a.vx[i]) * Math.min(1, 2.5 * dt);
|
|
485
|
-
a.vy[i] += (dy * inv - a.vy[i]) * Math.min(1, 2.5 * dt);
|
|
486
|
-
a.vz[i] += (dz * inv - a.vz[i]) * Math.min(1, 2.5 * dt);
|
|
487
|
-
a.ampTarget[i] = 0.25;
|
|
488
|
-
a.timer[i] -= dt;
|
|
489
|
-
if (a.timer[i] < -20) { // stuck approach: give up
|
|
490
|
-
if (perch) perch.occupant = -1;
|
|
491
|
-
a.target[i] = -1;
|
|
492
|
-
a.state[i] = FAUNA_STATE.FLY;
|
|
493
|
-
}
|
|
494
|
-
return;
|
|
495
|
-
}
|
|
496
|
-
|
|
497
|
-
// FLY. Far agents circle; only their caches refresh (above).
|
|
498
|
-
if (a.far[i]) {
|
|
499
|
-
clampSpeed(a, i, b.cruiseSpeed * 0.9, b.cruiseSpeed * 1.1);
|
|
500
|
-
a.vy[i] *= 0.6;
|
|
501
|
-
a.ampTarget[i] = 0.7;
|
|
502
|
-
return;
|
|
503
|
-
}
|
|
504
|
-
|
|
505
|
-
rebuildGrid(state, stamp);
|
|
506
|
-
accumulateFlock(state, i, b.neighborRadius, b.separationRadius,
|
|
507
|
-
b.cohesion * 0.4, b.alignment * 0.55, b.separation * 1.6);
|
|
508
|
-
a.vx[i] += flock.ax * dt;
|
|
509
|
-
a.vy[i] += flock.ay * dt;
|
|
510
|
-
a.vz[i] += flock.az * dt;
|
|
511
|
-
|
|
512
|
-
// Wander + altitude band spring.
|
|
513
|
-
const w = a.wf;
|
|
514
|
-
a.vx[i] += Math.sin(sim.time * w[i * 4] + w[i * 4 + 1]) * b.wander * 1.6 * dt;
|
|
515
|
-
a.vz[i] += Math.cos(sim.time * w[i * 4 + 2] + w[i * 4 + 3]) * b.wander * 1.6 * dt;
|
|
516
|
-
const bandY = a.groundY[i] + b.altitudeMin
|
|
517
|
-
+ a.hoverBias[i] * Math.max(b.altitudeMax - b.altitudeMin, 1);
|
|
518
|
-
a.vy[i] += (bandY - a.py[i]) * 0.35 * dt;
|
|
519
|
-
a.vy[i] *= 1 - Math.min(1, 0.6 * dt);
|
|
520
|
-
boundsForce(a, i, dt);
|
|
521
|
-
|
|
522
|
-
if (followD2 < b.fleeRadius * b.fleeRadius) {
|
|
523
|
-
const d = Math.max(Math.sqrt(followD2), 1e-3);
|
|
524
|
-
a.vx[i] += (fx / d) * 26 * dt;
|
|
525
|
-
a.vy[i] += 9 * dt;
|
|
526
|
-
a.vz[i] += (fz / d) * 26 * dt;
|
|
527
|
-
a.ampTarget[i] = 1;
|
|
528
|
-
a.cooldown[i] = Math.max(a.cooldown[i], 4);
|
|
529
|
-
} else if (a.cooldown[i] <= 0 && perches.length > 0
|
|
530
|
-
&& nextRand(a.rng, i) < b.perchChance * dt * 0.1) {
|
|
531
|
-
// Claim the nearest free perch within gliding range.
|
|
532
|
-
let best = -1;
|
|
533
|
-
let bestD2 = 30 * 30;
|
|
534
|
-
for (let p = 0; p < perches.length; p += 1) {
|
|
535
|
-
if (perches[p].occupant >= 0) continue;
|
|
536
|
-
const dx = perches[p].x - a.px[i];
|
|
537
|
-
const dz = perches[p].z - a.pz[i];
|
|
538
|
-
const d2 = dx * dx + dz * dz;
|
|
539
|
-
if (d2 < bestD2) { bestD2 = d2; best = p; }
|
|
540
|
-
}
|
|
541
|
-
if (best >= 0) {
|
|
542
|
-
perches[best].occupant = i;
|
|
543
|
-
a.target[i] = best;
|
|
544
|
-
a.state[i] = FAUNA_STATE.APPROACH;
|
|
545
|
-
a.timer[i] = 0;
|
|
546
|
-
return;
|
|
547
|
-
}
|
|
548
|
-
a.cooldown[i] = 3;
|
|
549
|
-
}
|
|
550
|
-
|
|
551
|
-
clampSpeed(a, i, b.cruiseSpeed * 0.55, b.maxSpeed);
|
|
552
|
-
// Flap hard when climbing or slow, glide when descending.
|
|
553
|
-
const speed = Math.hypot(a.vx[i], a.vy[i], a.vz[i]);
|
|
554
|
-
a.ampTarget[i] = Math.min(1, Math.max(0.12,
|
|
555
|
-
0.45 + a.vy[i] * 0.35 + (speed < b.cruiseSpeed ? 0.25 : 0)));
|
|
556
|
-
}
|
|
557
|
-
|
|
558
|
-
function butterflyTick(state, i, dt, follow) {
|
|
559
|
-
const a = state.arrays;
|
|
560
|
-
const b = cfg.butterflies;
|
|
561
|
-
a.groundY[i] = ground(a.px[i], a.pz[i]);
|
|
562
|
-
|
|
563
|
-
const hx = a.homeX[i] - a.px[i];
|
|
564
|
-
const hz = a.homeZ[i] - a.pz[i];
|
|
565
|
-
const homeD = Math.hypot(hx, hz);
|
|
566
|
-
|
|
567
|
-
if (a.far[i]) {
|
|
568
|
-
// Scripted loop around the anchor: pull home + keep the circling turn.
|
|
569
|
-
if (homeD > 2) {
|
|
570
|
-
a.vx[i] += hx / homeD * 0.8 * dt;
|
|
571
|
-
a.vz[i] += hz / homeD * 0.8 * dt;
|
|
572
|
-
}
|
|
573
|
-
clampSpeed(a, i, b.speed * 0.4, b.speed);
|
|
574
|
-
return;
|
|
575
|
-
}
|
|
576
|
-
|
|
577
|
-
// Anchor spring, ramping in over the last 30% of the wander radius.
|
|
578
|
-
const over = homeD - b.wanderRadius * 0.7;
|
|
579
|
-
if (over > 0) {
|
|
580
|
-
const k = Math.min(over / Math.max(b.wanderRadius * 0.3, 0.5), 2) * 2.4;
|
|
581
|
-
a.vx[i] += hx / Math.max(homeD, 1e-3) * k * dt;
|
|
582
|
-
a.vz[i] += hz / Math.max(homeD, 1e-3) * k * dt;
|
|
583
|
-
}
|
|
584
|
-
|
|
585
|
-
// The flutter: sinusoid wander in XZ + a bobbing hover band.
|
|
586
|
-
const w = a.wf;
|
|
587
|
-
a.vx[i] += Math.sin(sim.time * (1.1 + w[i * 4]) + w[i * 4 + 1]) * b.speed * 2.6 * dt;
|
|
588
|
-
a.vz[i] += Math.cos(sim.time * (1.2 + w[i * 4 + 2]) + w[i * 4 + 3]) * b.speed * 2.6 * dt;
|
|
589
|
-
const hoverY = a.groundY[i] + b.hoverMin
|
|
590
|
-
+ a.hoverBias[i] * Math.max(b.hoverMax - b.hoverMin, 0.1);
|
|
591
|
-
a.vy[i] += (hoverY - a.py[i]) * 2.2 * dt;
|
|
592
|
-
a.vy[i] *= 1 - Math.min(1, 1.5 * dt);
|
|
593
|
-
|
|
594
|
-
if (follow) {
|
|
595
|
-
const fx = a.px[i] - follow.x;
|
|
596
|
-
const fy = a.py[i] - (follow.y ?? 0);
|
|
597
|
-
const fz = a.pz[i] - follow.z;
|
|
598
|
-
const d2 = fx * fx + fy * fy + fz * fz; // 3D: an aerial camera is far
|
|
599
|
-
if (d2 < b.fleeRadius * b.fleeRadius) {
|
|
600
|
-
const d = Math.max(Math.sqrt(d2), 1e-3);
|
|
601
|
-
a.vx[i] += (fx / d) * 8 * dt;
|
|
602
|
-
a.vy[i] += 2.5 * dt;
|
|
603
|
-
a.vz[i] += (fz / d) * 8 * dt;
|
|
604
|
-
}
|
|
605
|
-
}
|
|
606
|
-
|
|
607
|
-
// Occasional anchor hop — only to NEARBY flower points, so butterflies
|
|
608
|
-
// drift around their patch instead of migrating across the map (and the
|
|
609
|
-
// flower-mask invariant holds through the transit).
|
|
610
|
-
if (flowerPool.length > 1 && nextRand(a.rng, i) < 0.06 * dt) {
|
|
611
|
-
const reach = b.wanderRadius * 3;
|
|
612
|
-
for (let attempt = 0; attempt < 4; attempt += 1) {
|
|
613
|
-
const pick = flowerPool[Math.floor(nextRand(a.rng, i) * flowerPool.length) % flowerPool.length];
|
|
614
|
-
const dx = pick.x - a.px[i];
|
|
615
|
-
const dz = pick.z - a.pz[i];
|
|
616
|
-
if (dx * dx + dz * dz < reach * reach) {
|
|
617
|
-
a.homeX[i] = pick.x;
|
|
618
|
-
a.homeZ[i] = pick.z;
|
|
619
|
-
break;
|
|
620
|
-
}
|
|
621
|
-
}
|
|
622
|
-
}
|
|
623
|
-
boundsForce(a, i, dt);
|
|
624
|
-
clampSpeed(a, i, b.speed * 0.3, b.speed * 1.8);
|
|
625
|
-
}
|
|
626
|
-
|
|
627
|
-
function dragonflyTick(state, i, dt, follow) {
|
|
628
|
-
const a = state.arrays;
|
|
629
|
-
const b = cfg.dragonflies;
|
|
630
|
-
a.groundY[i] = ground(a.px[i], a.pz[i]);
|
|
631
|
-
const hoverY = waterLevel + b.hoverHeight * (0.7 + a.hoverBias[i] * 0.7);
|
|
632
|
-
|
|
633
|
-
if (a.state[i] === FAUNA_STATE.DART) {
|
|
634
|
-
const dx = a.homeX[i] - a.px[i];
|
|
635
|
-
const dz = a.homeZ[i] - a.pz[i];
|
|
636
|
-
const d = Math.hypot(dx, dz);
|
|
637
|
-
if (d < 1) {
|
|
638
|
-
a.state[i] = FAUNA_STATE.FLY;
|
|
639
|
-
a.vx[i] *= 0.25; a.vz[i] *= 0.25;
|
|
640
|
-
} else {
|
|
641
|
-
a.vx[i] = dx / d * b.dartSpeed;
|
|
642
|
-
a.vz[i] = dz / d * b.dartSpeed;
|
|
643
|
-
}
|
|
644
|
-
a.vy[i] += (hoverY - a.py[i]) * 4 * dt;
|
|
645
|
-
return;
|
|
646
|
-
}
|
|
647
|
-
|
|
648
|
-
if (!a.far[i]) {
|
|
649
|
-
// Hover jitter: tight, twitchy sinusoids — the dragonfly read.
|
|
650
|
-
const w = a.wf;
|
|
651
|
-
a.vx[i] += Math.sin(sim.time * (3 + w[i * 4] * 4) + w[i * 4 + 1]) * 3.2 * dt;
|
|
652
|
-
a.vz[i] += Math.cos(sim.time * (3 + w[i * 4 + 2] * 4) + w[i * 4 + 3]) * 3.2 * dt;
|
|
653
|
-
const hxD = a.homeX[i] - a.px[i];
|
|
654
|
-
const hzD = a.homeZ[i] - a.pz[i];
|
|
655
|
-
const dh = Math.hypot(hxD, hzD);
|
|
656
|
-
if (dh > b.hoverRadius * 0.6) {
|
|
657
|
-
a.vx[i] += hxD / Math.max(dh, 1e-3) * 3 * dt;
|
|
658
|
-
a.vz[i] += hzD / Math.max(dh, 1e-3) * 3 * dt;
|
|
659
|
-
}
|
|
660
|
-
if (follow) {
|
|
661
|
-
const fx = a.px[i] - follow.x;
|
|
662
|
-
const fy = a.py[i] - (follow.y ?? 0);
|
|
663
|
-
const fz = a.pz[i] - follow.z;
|
|
664
|
-
const d2 = fx * fx + fy * fy + fz * fz;
|
|
665
|
-
if (d2 < 6.25) { // dragonflies tolerate ~2.5 m before darting
|
|
666
|
-
const d = Math.max(Math.sqrt(d2), 1e-3);
|
|
667
|
-
a.vx[i] += (fx / d) * 14 * dt;
|
|
668
|
-
a.vz[i] += (fz / d) * 14 * dt;
|
|
669
|
-
}
|
|
670
|
-
}
|
|
671
|
-
if (dragonPool.length > 1 && nextRand(a.rng, i) < b.dartChance * dt * 0.125) {
|
|
672
|
-
const pick = dragonPool[Math.floor(nextRand(a.rng, i) * dragonPool.length) % dragonPool.length];
|
|
673
|
-
a.homeX[i] = pick.x;
|
|
674
|
-
a.homeZ[i] = pick.z;
|
|
675
|
-
a.state[i] = FAUNA_STATE.DART;
|
|
676
|
-
}
|
|
677
|
-
}
|
|
678
|
-
a.vy[i] += (hoverY - a.py[i]) * 5 * dt;
|
|
679
|
-
a.vy[i] *= 1 - Math.min(1, 3 * dt);
|
|
680
|
-
boundsForce(a, i, dt);
|
|
681
|
-
clampSpeed(a, i, 0, b.dartSpeed);
|
|
682
|
-
}
|
|
683
|
-
|
|
684
|
-
function fishTick(state, i, dt, follow, stamp) {
|
|
685
|
-
const a = state.arrays;
|
|
686
|
-
const f = cfg.fish;
|
|
687
|
-
const bed = ground(a.px[i], a.pz[i]);
|
|
688
|
-
a.groundY[i] = bed;
|
|
689
|
-
const lo = bed + f.bedMargin;
|
|
690
|
-
const hi = waterLevel - f.surfaceMargin;
|
|
691
|
-
|
|
692
|
-
// Shallow-water escape dominates everything: swim down the bed gradient
|
|
693
|
-
// before the depth clamps can ever pinch (see the invariant analysis in
|
|
694
|
-
// scripts/verify-fauna.mjs).
|
|
695
|
-
const room = hi - lo;
|
|
696
|
-
if (room < 0.5) {
|
|
697
|
-
const e = 1.5;
|
|
698
|
-
const gx = (ground(a.px[i] + e, a.pz[i]) - ground(a.px[i] - e, a.pz[i])) / (2 * e);
|
|
699
|
-
const gz = (ground(a.px[i], a.pz[i] + e) - ground(a.px[i], a.pz[i] - e)) / (2 * e);
|
|
700
|
-
const g = Math.max(Math.hypot(gx, gz), 1e-4);
|
|
701
|
-
const urgency = room < 0.2 ? 3 : 1;
|
|
702
|
-
a.vx[i] += (-gx / g) * f.cruiseSpeed * 4 * urgency * dt;
|
|
703
|
-
a.vz[i] += (-gz / g) * f.cruiseSpeed * 4 * urgency * dt;
|
|
704
|
-
a.vy[i] -= 0.8 * dt;
|
|
705
|
-
clampSpeed(a, i, f.cruiseSpeed * 0.6, f.maxSpeed);
|
|
706
|
-
return;
|
|
707
|
-
}
|
|
708
|
-
|
|
709
|
-
if (a.far[i]) {
|
|
710
|
-
clampSpeed(a, i, f.cruiseSpeed * 0.9, f.cruiseSpeed * 1.1);
|
|
711
|
-
a.vy[i] *= 0.5;
|
|
712
|
-
return;
|
|
713
|
-
}
|
|
714
|
-
|
|
715
|
-
rebuildGrid(state, stamp);
|
|
716
|
-
accumulateFlock(state, i, f.neighborRadius, f.separationRadius,
|
|
717
|
-
f.cohesion * 1.2, f.alignment * 0.7, f.separation * 0.35);
|
|
718
|
-
a.vx[i] += flock.ax * dt;
|
|
719
|
-
a.vy[i] += flock.ay * dt;
|
|
720
|
-
a.vz[i] += flock.az * dt;
|
|
721
|
-
|
|
722
|
-
const w = a.wf;
|
|
723
|
-
a.vx[i] += Math.sin(sim.time * w[i * 4] * 0.7 + w[i * 4 + 1]) * f.wander * 0.8 * dt;
|
|
724
|
-
a.vz[i] += Math.cos(sim.time * w[i * 4 + 2] * 0.7 + w[i * 4 + 3]) * f.wander * 0.8 * dt;
|
|
725
|
-
// Preferred depth: a lane in the top of the water column — koi live where
|
|
726
|
-
// the refraction pass can show them, not on the bed.
|
|
727
|
-
const laneY = Math.max(hi - (0.2 + a.hoverBias[i] * 0.7), lo + Math.min(room, 2) * 0.15);
|
|
728
|
-
a.vy[i] += (laneY - a.py[i]) * 0.8 * dt;
|
|
729
|
-
a.vy[i] *= 1 - Math.min(1, 1.2 * dt);
|
|
730
|
-
|
|
731
|
-
if (follow) {
|
|
732
|
-
const fx = a.px[i] - follow.x;
|
|
733
|
-
const fy = a.py[i] - (follow.y ?? 0);
|
|
734
|
-
const fz = a.pz[i] - follow.z;
|
|
735
|
-
// 3D: a swimmer or a bridge-walker close above scares fish; an aerial
|
|
736
|
-
// camera does not empty the shot.
|
|
737
|
-
const d2 = fx * fx + fy * fy + fz * fz;
|
|
738
|
-
if (d2 < f.fleeRadius * f.fleeRadius) {
|
|
739
|
-
const d = Math.max(Math.sqrt(d2), 1e-3);
|
|
740
|
-
a.vx[i] += (fx / d) * 10 * dt;
|
|
741
|
-
a.vz[i] += (fz / d) * 10 * dt;
|
|
742
|
-
}
|
|
743
|
-
}
|
|
744
|
-
boundsForce(a, i, dt);
|
|
745
|
-
clampSpeed(a, i, f.cruiseSpeed * 0.45, f.maxSpeed);
|
|
746
|
-
}
|
|
747
|
-
|
|
748
|
-
const TICKS = {
|
|
749
|
-
birds: birdTick,
|
|
750
|
-
butterflies: butterflyTick,
|
|
751
|
-
dragonflies: dragonflyTick,
|
|
752
|
-
fish: fishTick,
|
|
753
|
-
};
|
|
754
|
-
|
|
755
|
-
// --- integration (every agent, every frame) --------------------------------
|
|
756
|
-
|
|
757
|
-
function integrate(dt, follow) {
|
|
758
|
-
const far2 = cfg.shared.farDistance * cfg.shared.farDistance;
|
|
759
|
-
for (const name of FAUNA_SPECIES) {
|
|
760
|
-
const state = speciesStates[name];
|
|
761
|
-
const a = state.arrays;
|
|
762
|
-
const isFish = name === 'fish';
|
|
763
|
-
const isBird = name === 'birds';
|
|
764
|
-
for (let i = 0; i < state.count; i += 1) {
|
|
765
|
-
// Far flag (cheap: one distance per agent per frame keeps the
|
|
766
|
-
// degrade responsive even between that agent's steering ticks).
|
|
767
|
-
if (follow) {
|
|
768
|
-
const dx = a.px[i] - follow.x;
|
|
769
|
-
const dz = a.pz[i] - follow.z;
|
|
770
|
-
a.far[i] = dx * dx + dz * dz > far2 ? 1 : 0;
|
|
771
|
-
} else {
|
|
772
|
-
a.far[i] = 0;
|
|
773
|
-
}
|
|
774
|
-
|
|
775
|
-
const k = Math.min(1, 5 * dt);
|
|
776
|
-
a.amp[i] += (a.ampTarget[i] - a.amp[i]) * k;
|
|
777
|
-
a.fold[i] += (a.foldTarget[i] - a.fold[i]) * Math.min(1, 3.5 * dt);
|
|
778
|
-
|
|
779
|
-
if (a.state[i] === FAUNA_STATE.PERCHED) continue;
|
|
780
|
-
|
|
781
|
-
if (a.far[i] && a.state[i] === FAUNA_STATE.FLY) {
|
|
782
|
-
// Scripted loop: constant-rate yaw — perfect circles, no steering.
|
|
783
|
-
const wd = a.turn[i] * dt;
|
|
784
|
-
const nvx = a.vx[i] - a.vz[i] * wd;
|
|
785
|
-
a.vz[i] += a.vx[i] * wd;
|
|
786
|
-
a.vx[i] = nvx;
|
|
787
|
-
}
|
|
788
|
-
|
|
789
|
-
a.px[i] += a.vx[i] * dt;
|
|
790
|
-
a.py[i] += a.vy[i] * dt;
|
|
791
|
-
a.pz[i] += a.vz[i] * dt;
|
|
792
|
-
|
|
793
|
-
// Hard bounds (steering springs should make these no-ops).
|
|
794
|
-
if (a.px[i] < box.minX) { a.px[i] = box.minX; a.vx[i] *= -0.5; }
|
|
795
|
-
else if (a.px[i] > box.maxX) { a.px[i] = box.maxX; a.vx[i] *= -0.5; }
|
|
796
|
-
if (a.pz[i] < box.minZ) { a.pz[i] = box.minZ; a.vz[i] *= -0.5; }
|
|
797
|
-
else if (a.pz[i] > box.maxZ) { a.pz[i] = box.maxZ; a.vz[i] *= -0.5; }
|
|
798
|
-
|
|
799
|
-
if (isFish) {
|
|
800
|
-
const lo = a.groundY[i] + cfg.fish.bedMargin;
|
|
801
|
-
const hi = waterLevel - cfg.fish.surfaceMargin;
|
|
802
|
-
if (a.py[i] > hi) { a.py[i] = hi; if (a.vy[i] > 0) a.vy[i] = 0; }
|
|
803
|
-
if (a.py[i] < lo) { a.py[i] = Math.min(lo, hi); if (a.vy[i] < 0) a.vy[i] = 0; }
|
|
804
|
-
} else if (isBird) {
|
|
805
|
-
const floor = a.groundY[i] + (a.state[i] === FAUNA_STATE.APPROACH ? 0.1 : 1.0);
|
|
806
|
-
if (a.py[i] < floor) { a.py[i] = floor; if (a.vy[i] < 0) a.vy[i] = 0; }
|
|
807
|
-
} else {
|
|
808
|
-
const floor = name === 'dragonflies'
|
|
809
|
-
? Math.max(waterLevel + 0.15, a.groundY[i] + 0.2)
|
|
810
|
-
: a.groundY[i] + cfg.butterflies.hoverMin * 0.5;
|
|
811
|
-
if (a.py[i] < floor) { a.py[i] = floor; if (a.vy[i] < 0) a.vy[i] = 0; }
|
|
812
|
-
}
|
|
813
|
-
|
|
814
|
-
// Heading smoothing + banking from the applied turn.
|
|
815
|
-
const speed2 = a.vx[i] * a.vx[i] + a.vz[i] * a.vz[i];
|
|
816
|
-
if (speed2 > 1e-6) {
|
|
817
|
-
const target = Math.atan2(a.vx[i], a.vz[i]);
|
|
818
|
-
let delta = target - a.heading[i];
|
|
819
|
-
delta -= Math.round(delta / (Math.PI * 2)) * Math.PI * 2;
|
|
820
|
-
const maxTurn = 7 * dt;
|
|
821
|
-
const applied = Math.min(Math.max(delta, -maxTurn), maxTurn);
|
|
822
|
-
a.heading[i] += applied;
|
|
823
|
-
const targetBank = Math.min(Math.max(applied / Math.max(dt, 1e-4) * -0.12, -0.6), 0.6);
|
|
824
|
-
a.bank[i] += (targetBank - a.bank[i]) * Math.min(1, 6 * dt);
|
|
825
|
-
} else {
|
|
826
|
-
a.bank[i] *= 1 - Math.min(1, 4 * dt);
|
|
827
|
-
}
|
|
828
|
-
}
|
|
829
|
-
}
|
|
830
|
-
}
|
|
831
|
-
|
|
832
|
-
// --- public update ----------------------------------------------------------
|
|
833
|
-
|
|
834
|
-
let cursor = 0;
|
|
835
|
-
sim.update = (delta, follow = null) => {
|
|
836
|
-
const dt = Math.min(Math.max(Number(delta) || 0.016, 0.0005), 0.1);
|
|
837
|
-
sim.time += dt;
|
|
838
|
-
stats.updates += 1;
|
|
839
|
-
|
|
840
|
-
integrate(dt, follow);
|
|
841
|
-
|
|
842
|
-
// Staggered steering slice.
|
|
843
|
-
let steered = 0;
|
|
844
|
-
const budget = Math.min(stats.tickBudget, walk.length);
|
|
845
|
-
for (let n = 0; n < budget; n += 1) {
|
|
846
|
-
const entry = walk[cursor];
|
|
847
|
-
cursor = (cursor + 1) % Math.max(walk.length, 1);
|
|
848
|
-
const state = entry.s;
|
|
849
|
-
const i = entry.i;
|
|
850
|
-
const a = state.arrays;
|
|
851
|
-
const dtTick = Math.min(Math.max(sim.time - a.lastTick[i], 1 / 240), 0.6);
|
|
852
|
-
a.lastTick[i] = sim.time;
|
|
853
|
-
TICKS[state.name](state, i, dtTick, follow, stats.updates);
|
|
854
|
-
steered += 1;
|
|
855
|
-
}
|
|
856
|
-
stats.steeredLastUpdate = steered;
|
|
857
|
-
return sim;
|
|
858
|
-
};
|
|
859
|
-
|
|
860
|
-
return sim;
|
|
861
|
-
}
|