threedog 0.0.0-stage → 0.2.0
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/CHANGELOG.md +5 -0
- package/LICENSE +21 -0
- package/README.md +39 -2
- package/core/Animator.js +268 -0
- package/core/Assets.js +256 -0
- package/core/Audio.js +267 -0
- package/core/Baked.js +72 -0
- package/core/Batching.js +247 -0
- package/core/Budget.js +221 -0
- package/core/Clock.js +94 -0
- package/core/Commits.js +77 -0
- package/core/DebugOverrides.js +143 -0
- package/core/Describe.js +145 -0
- package/core/Engine.js +184 -0
- package/core/Events.js +153 -0
- package/core/I18n.js +94 -0
- package/core/Input.js +245 -0
- package/core/Inspect.js +77 -0
- package/core/InspectScene.js +191 -0
- package/core/Jobs.js +146 -0
- package/core/Loading.js +149 -0
- package/core/MaterialInfo.js +32 -0
- package/core/Ops.js +256 -0
- package/core/Random.js +52 -0
- package/core/Rays.js +160 -0
- package/core/SaveStore.js +85 -0
- package/core/Saves.js +254 -0
- package/core/Stream.js +279 -0
- package/core/Threads.js +158 -0
- package/core/UrlState.js +94 -0
- package/core/Vars.js +35 -0
- package/core/Views.js +49 -0
- package/core/actor.js +23 -0
- package/core/assetEntry.js +89 -0
- package/core/assetLoad.js +190 -0
- package/core/assetManifest.js +35 -0
- package/core/assetReport.js +83 -0
- package/core/audioRules.js +121 -0
- package/core/audioVoice.js +225 -0
- package/core/batchGroups.js +116 -0
- package/core/canvasBox.js +63 -0
- package/core/catalog.js +169 -0
- package/core/checks.js +67 -0
- package/core/claims.js +51 -0
- package/core/dayTime.js +15 -0
- package/core/debugView.js +76 -0
- package/core/describeRender.js +45 -0
- package/core/describeText.js +143 -0
- package/core/easing.js +34 -0
- package/core/errorCodes.js +205 -0
- package/core/errorHints.js +208 -0
- package/core/errors.js +40 -0
- package/core/events.generated.js +84 -0
- package/core/ground.js +102 -0
- package/core/holds.js +106 -0
- package/core/inputContext.js +69 -0
- package/core/inputDefaults.js +22 -0
- package/core/inputPad.js +35 -0
- package/core/inputPointer.js +48 -0
- package/core/inputTouch.js +48 -0
- package/core/lifecycle.js +69 -0
- package/core/lightWatch.js +56 -0
- package/core/look/coreParts.js +112 -0
- package/core/look/layers.js +136 -0
- package/core/look/part.js +173 -0
- package/core/look/report.js +79 -0
- package/core/look/write.js +86 -0
- package/core/loop.js +200 -0
- package/core/math.js +33 -0
- package/core/modules.js +196 -0
- package/core/movement.js +19 -0
- package/core/mulberry32.js +14 -0
- package/core/opsAtomic.js +31 -0
- package/core/opsCheck.js +97 -0
- package/core/opsFail.js +20 -0
- package/core/opsGuard.js +26 -0
- package/core/opsHistory.js +27 -0
- package/core/opsRun.js +77 -0
- package/core/page.js +78 -0
- package/core/params.js +132 -0
- package/core/pureWorker.js +5 -0
- package/core/renamed.js +21 -0
- package/core/saveApply.js +128 -0
- package/core/saveFiles.js +139 -0
- package/core/saveIds.js +53 -0
- package/core/saveVersions.js +97 -0
- package/core/scatter.js +92 -0
- package/core/sceneMethods.js +100 -0
- package/core/screenToGround.js +39 -0
- package/core/services.js +73 -0
- package/core/session.js +171 -0
- package/core/shadowTypes.js +15 -0
- package/core/skip.js +104 -0
- package/core/startup.js +135 -0
- package/core/streamCells.js +24 -0
- package/core/streamSources.js +73 -0
- package/core/styleParts.js +96 -0
- package/core/targeting.js +64 -0
- package/core/thingExplain.js +68 -0
- package/core/thingOps.js +168 -0
- package/core/things.js +212 -0
- package/core/threadPure.js +120 -0
- package/core/threadServe.js +25 -0
- package/core/tier.js +11 -0
- package/core/util.js +11 -0
- package/core/validate.js +204 -0
- package/docs/AI.md +123 -0
- package/docs/API.md +83 -0
- package/docs/CODEMAP.md +347 -0
- package/docs/COMMANDS.md +108 -0
- package/docs/CONVENTIONS.md +145 -0
- package/docs/PERF.md +217 -0
- package/docs/THREE.md +86 -0
- package/docs/api/ambience.md +15 -0
- package/docs/api/assets.md +62 -0
- package/docs/api/audio.md +53 -0
- package/docs/api/budget.md +40 -0
- package/docs/api/cameraRig.md +120 -0
- package/docs/api/characters.md +144 -0
- package/docs/api/clock.md +7 -0
- package/docs/api/collision.md +39 -0
- package/docs/api/content.md +64 -0
- package/docs/api/dialogue.md +39 -0
- package/docs/api/engine.md +199 -0
- package/docs/api/entities.md +61 -0
- package/docs/api/events.md +95 -0
- package/docs/api/flow.md +27 -0
- package/docs/api/grids.md +11 -0
- package/docs/api/ground.md +16 -0
- package/docs/api/hlod.md +34 -0
- package/docs/api/hud.md +31 -0
- package/docs/api/i18n.md +10 -0
- package/docs/api/input.md +24 -0
- package/docs/api/interactions.md +31 -0
- package/docs/api/inventory.md +66 -0
- package/docs/api/jobs.md +10 -0
- package/docs/api/level.md +41 -0
- package/docs/api/lightPool.md +56 -0
- package/docs/api/music.md +34 -0
- package/docs/api/nav.md +26 -0
- package/docs/api/net.md +14 -0
- package/docs/api/openWorld.md +24 -0
- package/docs/api/particles.md +41 -0
- package/docs/api/photo.md +15 -0
- package/docs/api/post.md +10 -0
- package/docs/api/quests.md +36 -0
- package/docs/api/rays.md +26 -0
- package/docs/api/rigid.md +84 -0
- package/docs/api/saves.md +32 -0
- package/docs/api/settings.md +36 -0
- package/docs/api/sky.md +58 -0
- package/docs/api/stream.md +31 -0
- package/docs/api/style.md +134 -0
- package/docs/api/terrain.md +34 -0
- package/docs/api/timeline.md +39 -0
- package/docs/api/tools.md +57 -0
- package/docs/api/triggers.md +56 -0
- package/docs/api/vars.md +9 -0
- package/docs/api/vegetation.md +52 -0
- package/docs/api/water.md +48 -0
- package/docs/api/weather.md +29 -0
- package/docs/api/world.md +30 -0
- package/docs/recipes/01-new-game.md +148 -0
- package/docs/recipes/02-npc.md +167 -0
- package/docs/recipes/03-items-pickups.md +158 -0
- package/docs/recipes/04-quests.md +83 -0
- package/docs/recipes/05-props-bake.md +159 -0
- package/docs/recipes/06-clock-events.md +117 -0
- package/docs/recipes/07-flow-scenes-pause.md +132 -0
- package/docs/recipes/08-weather-sky.md +74 -0
- package/docs/recipes/09-style-pack.md +234 -0
- package/docs/recipes/10-blender-level.md +67 -0
- package/docs/recipes/11-vehicles.md +55 -0
- package/docs/recipes/12-navmesh.md +79 -0
- package/docs/recipes/13-animation.md +149 -0
- package/docs/recipes/14-custom-module.md +91 -0
- package/docs/recipes/15-perf.md +78 -0
- package/docs/recipes/16-dev-bridge.md +180 -0
- package/docs/recipes/18-world.md +185 -0
- package/docs/recipes/19-shooting-picking.md +76 -0
- package/docs/recipes/20-content-actions-save.md +176 -0
- package/docs/recipes/21-camera.md +153 -0
- package/docs/recipes/22-shop-gold.md +107 -0
- package/docs/recipes/23-ops.md +175 -0
- package/docs/recipes/26-ui-parts.md +138 -0
- package/docs/recipes/27-net.md +96 -0
- package/docs/recipes/28-terrain.md +80 -0
- package/docs/recipes/29-grid.md +87 -0
- package/docs/recipes/30-templates.md +131 -0
- package/docs/recipes/31-audio.md +126 -0
- package/docs/recipes/32-action-game.md +33 -0
- package/docs/recipes/33-stream-sources.md +37 -0
- package/docs/recipes/34-environment-lighting.md +36 -0
- package/docs/recipes/35-style-from-reference.md +89 -0
- package/docs/recipes/36-sky-ground-plant-looks.md +116 -0
- package/docs/recipes/37-terrain-look-hooks.md +97 -0
- package/docs/recipes/38-environment-look-hooks.md +83 -0
- package/docs/recipes/40-scene.md +108 -0
- package/docs/recipes/41-thing-registry.md +93 -0
- package/docs/recipes/42-terrain-shape.md +64 -0
- package/docs/recipes/43-shader-patches-surface-looks.md +120 -0
- package/docs/recipes/44-water-weather-look-hooks.md +135 -0
- package/docs/recipes/45-cascaded-shadows.md +51 -0
- package/docs/recipes/46-blender-art-route.md +114 -0
- package/docs/recipes/47-island-snow-backdrop.md +44 -0
- package/docs/recipes/48-make-material.md +70 -0
- package/docs/recipes/49-game-module-contract.md +71 -0
- package/docs/recipes/50-own-renderer.md +12 -0
- package/docs/recipes/51-capability-catalog.md +63 -0
- package/docs/recipes/52-look.md +108 -0
- package/examples/action/DESIGN.md +3 -0
- package/examples/action/GAMEMAP.md +127 -0
- package/examples/action/content/actions.js +8 -0
- package/examples/action/content/audio.js +9 -0
- package/examples/action/content/index.js +10 -0
- package/examples/action/content/items.js +4 -0
- package/examples/action/content/places.js +4 -0
- package/examples/action/content/props.js +11 -0
- package/examples/action/content/templates.js +10 -0
- package/examples/action/content/views.js +6 -0
- package/examples/action/look.js +5 -0
- package/examples/action/main.js +137 -0
- package/examples/action/models.js +25 -0
- package/examples/sheepisland/GAMEMAP.md +107 -0
- package/examples/sheepisland/content/index.js +6 -0
- package/examples/sheepisland/content/props.js +19 -0
- package/examples/sheepisland/content/templates.js +5 -0
- package/examples/sheepisland/content/vegetation.js +8 -0
- package/examples/sheepisland/main.js +71 -0
- package/examples/sheepisland/params.js +25 -0
- package/examples/sheepisland/style/index.js +79 -0
- package/examples/sheepisland/style/models.js +59 -0
- package/examples/sheepisland/views.js +9 -0
- package/examples/styletest/GAMEMAP.md +135 -0
- package/examples/styletest/content/index.js +9 -0
- package/examples/styletest/content/items.js +8 -0
- package/examples/styletest/content/npcs.js +8 -0
- package/examples/styletest/content/places.js +5 -0
- package/examples/styletest/content/props.js +16 -0
- package/examples/styletest/content/templates.js +9 -0
- package/examples/styletest/content/vegetation.js +31 -0
- package/examples/styletest/look.js +11 -0
- package/examples/styletest/main.js +95 -0
- package/examples/styletest/models.js +87 -0
- package/examples/styletest/overrides.js +33 -0
- package/examples/styletest/panel.js +135 -0
- package/examples/styletest/params.js +32 -0
- package/examples/styletest/views.js +31 -0
- package/examples/world/DESIGN.md +5 -0
- package/examples/world/GAMEMAP.md +171 -0
- package/examples/world/content/actions.js +8 -0
- package/examples/world/content/audio.js +25 -0
- package/examples/world/content/bodies.js +12 -0
- package/examples/world/content/containers.js +4 -0
- package/examples/world/content/dialogues.js +33 -0
- package/examples/world/content/index.js +17 -0
- package/examples/world/content/items.js +10 -0
- package/examples/world/content/npcs.js +14 -0
- package/examples/world/content/pickups.js +11 -0
- package/examples/world/content/places.js +6 -0
- package/examples/world/content/props.js +12 -0
- package/examples/world/content/quests.js +15 -0
- package/examples/world/content/rules.js +23 -0
- package/examples/world/content/templates.js +5 -0
- package/examples/world/content/vegetation.js +32 -0
- package/examples/world/main.js +168 -0
- package/examples/world/models.js +28 -0
- package/index.d.ts +306 -0
- package/index.js +122 -0
- package/llms.txt +61 -0
- package/modules/ambience/Ambience.js +186 -0
- package/modules/camera/FirstPersonCamera.js +131 -0
- package/modules/camera/FixedCamera.js +162 -0
- package/modules/camera/FollowCamera.js +91 -0
- package/modules/camera/RtsCamera.js +132 -0
- package/modules/camera/common.js +182 -0
- package/modules/camera/index.js +11 -0
- package/modules/camera/projection.js +34 -0
- package/modules/characters/Character.js +235 -0
- package/modules/characters/NPC.js +242 -0
- package/modules/characters/assetModel.js +42 -0
- package/modules/characters/astar.js +66 -0
- package/modules/characters/behaviors.js +72 -0
- package/modules/characters/footsteps.js +13 -0
- package/modules/characters/index.js +215 -0
- package/modules/characters/moveHelpers.js +29 -0
- package/modules/characters/movers/common.js +62 -0
- package/modules/characters/movers/rapier.js +74 -0
- package/modules/characters/movers/simple.js +43 -0
- package/modules/characters/npcAvoid.js +129 -0
- package/modules/characters/npcSim.js +150 -0
- package/modules/characters/npcView.js +42 -0
- package/modules/characters/pathAsync.js +113 -0
- package/modules/characters/pathJob.js +62 -0
- package/modules/characters/pathWorker.js +7 -0
- package/modules/characters/playerStrings.js +12 -0
- package/modules/characters/proceduralRig.js +58 -0
- package/modules/characters/useModel.js +22 -0
- package/modules/characters/walkTo.js +58 -0
- package/modules/collision/Collision.js +274 -0
- package/modules/collision/grid.js +63 -0
- package/modules/content/explain.js +13 -0
- package/modules/content/ids.js +95 -0
- package/modules/content/index.js +154 -0
- package/modules/content/loader.js +190 -0
- package/modules/content/models.js +69 -0
- package/modules/content/packs.js +69 -0
- package/modules/content/props.js +89 -0
- package/modules/content/rules.js +134 -0
- package/modules/content/templates.js +189 -0
- package/modules/debug/DebugPanel.js +174 -0
- package/modules/entities/Entities.js +243 -0
- package/modules/entities/build.js +25 -0
- package/modules/entities/index.js +4 -0
- package/modules/flow/index.js +101 -0
- package/modules/gameplay/Container.js +227 -0
- package/modules/gameplay/Containers.js +89 -0
- package/modules/gameplay/Dialogue.js +219 -0
- package/modules/gameplay/Interactions.js +253 -0
- package/modules/gameplay/Inventory.js +224 -0
- package/modules/gameplay/Quests.js +205 -0
- package/modules/gameplay/boxOps.js +60 -0
- package/modules/gameplay/dialogueBox.js +48 -0
- package/modules/gameplay/interactionPrompt.js +28 -0
- package/modules/gameplay/inventoryOps.js +137 -0
- package/modules/gameplay/pickups.js +115 -0
- package/modules/gameplay/questLog.js +54 -0
- package/modules/gameplay/questSave.js +71 -0
- package/modules/grid/Grid.js +184 -0
- package/modules/grid/Layer.js +142 -0
- package/modules/grid/index.js +236 -0
- package/modules/grid/ops.js +73 -0
- package/modules/grid/preview.js +85 -0
- package/modules/grid/tiles.js +79 -0
- package/modules/hlod/index.js +167 -0
- package/modules/hud/index.js +167 -0
- package/modules/hud/parts.js +80 -0
- package/modules/level/geometry.js +46 -0
- package/modules/level/heightfield.js +160 -0
- package/modules/level/index.js +233 -0
- package/modules/level/nodes.js +84 -0
- package/modules/lights/index.js +227 -0
- package/modules/music/Music.js +294 -0
- package/modules/music/index.js +2 -0
- package/modules/music/rules.js +28 -0
- package/modules/nav/index.js +156 -0
- package/modules/nav/navPath.js +17 -0
- package/modules/net/Client.js +137 -0
- package/modules/net/Host.js +117 -0
- package/modules/net/Net.js +49 -0
- package/modules/net/index.js +77 -0
- package/modules/net/sync.js +114 -0
- package/modules/net/transports.js +118 -0
- package/modules/particles/Particles.js +179 -0
- package/modules/particles/effect.js +112 -0
- package/modules/particles/shaders.js +28 -0
- package/modules/photo/Photo.js +146 -0
- package/modules/rigid/RigidBodies.js +265 -0
- package/modules/rigid/Vehicles.js +97 -0
- package/modules/rigid/sync.js +158 -0
- package/modules/settings/Settings.js +297 -0
- package/modules/settings/apply.js +21 -0
- package/modules/settings/index.js +3 -0
- package/modules/settings/sections.js +156 -0
- package/modules/settings/strings.js +53 -0
- package/modules/settings/view.js +65 -0
- package/modules/sky/Sky.js +259 -0
- package/modules/sky/calendar.js +80 -0
- package/modules/sky/cascades.js +125 -0
- package/modules/sky/clouds.js +79 -0
- package/modules/sky/domeLayers.js +33 -0
- package/modules/sky/environment.js +141 -0
- package/modules/sky/fog.js +139 -0
- package/modules/sky/frame.js +77 -0
- package/modules/sky/layers.js +69 -0
- package/modules/sky/look.js +51 -0
- package/modules/sky/lookFog.js +80 -0
- package/modules/sky/lookShadow.js +50 -0
- package/modules/sky/lookSky.js +108 -0
- package/modules/sky/schedule.js +80 -0
- package/modules/sky/shader.js +96 -0
- package/modules/sky/shadow.js +74 -0
- package/modules/sky/skyModule.js +60 -0
- package/modules/terrain/ChunkManager.js +260 -0
- package/modules/terrain/chunkJob.js +19 -0
- package/modules/terrain/chunkLevels.js +40 -0
- package/modules/terrain/chunkQueries.js +42 -0
- package/modules/terrain/chunkWorker.js +5 -0
- package/modules/terrain/index.js +118 -0
- package/modules/terrain/lookGround.js +61 -0
- package/modules/terrain/mountTerrain.js +32 -0
- package/modules/terrain/terrainColorMap.js +41 -0
- package/modules/terrain/terrainDefaults.js +39 -0
- package/modules/terrain/terrainEdit.js +139 -0
- package/modules/terrain/terrainGen.js +155 -0
- package/modules/terrain/terrainIsland.js +131 -0
- package/modules/terrain/terrainMesh.js +92 -0
- package/modules/terrain/terrainShape.js +108 -0
- package/modules/terrain/terrainShapeMain.js +41 -0
- package/modules/terrain/terrainTexture.js +44 -0
- package/modules/timeline/Timeline.js +253 -0
- package/modules/timeline/Tween.js +114 -0
- package/modules/timeline/letterbox.js +24 -0
- package/modules/timeline/shots.js +90 -0
- package/modules/triggers/index.js +268 -0
- package/modules/vegetation/Vegetation.js +256 -0
- package/modules/vegetation/groundChunks.js +177 -0
- package/modules/vegetation/index.js +43 -0
- package/modules/vegetation/lookWind.js +37 -0
- package/modules/vegetation/modelGeometry.js +21 -0
- package/modules/water/Water.js +160 -0
- package/modules/water/look.js +80 -0
- package/modules/water/surface.js +88 -0
- package/modules/weather/Weather.js +242 -0
- package/modules/weather/look.js +75 -0
- package/modules/weather/particles.js +92 -0
- package/modules/weather/shaders.js +49 -0
- package/modules/weather/strings.js +15 -0
- package/modules/world/World.js +231 -0
- package/modules/world/cells.js +42 -0
- package/modules/world/explain.js +11 -0
- package/modules/world/index.js +71 -0
- package/modules/world/persist.js +107 -0
- package/modules/world/pos.js +20 -0
- package/modules/world/records.js +89 -0
- package/modules/world/sim.js +175 -0
- package/modules/world/simFar.js +82 -0
- package/modules/world/state.js +115 -0
- package/modules/world/thingSource.js +44 -0
- package/modules/world/views.js +182 -0
- package/package.json +66 -4
- package/presets.js +96 -0
- package/render/PostFX.js +240 -0
- package/render/detail.js +105 -0
- package/render/effects.js +144 -0
- package/render/engineUniforms.js +23 -0
- package/render/fuse.js +84 -0
- package/render/lighting.js +100 -0
- package/render/lights.js +18 -0
- package/render/lookSurface.js +161 -0
- package/render/materials.js +220 -0
- package/render/patches.js +252 -0
- package/render/postLook.js +86 -0
- package/render/surface.js +69 -0
- package/render/uniformDecl.js +29 -0
- package/types/common.d.ts +34 -0
- package/types/core.d.ts +1965 -0
- package/types/gameplay.d.ts +1822 -0
- package/types/generated/core/Audio.d.ts +200 -0
- package/types/generated/core/Batching.d.ts +47 -0
- package/types/generated/core/Budget.d.ts +90 -0
- package/types/generated/core/Commits.d.ts +31 -0
- package/types/generated/core/DebugOverrides.d.ts +52 -0
- package/types/generated/core/Events.d.ts +89 -0
- package/types/generated/core/I18n.d.ts +30 -0
- package/types/generated/core/Input.d.ts +118 -0
- package/types/generated/core/Jobs.d.ts +41 -0
- package/types/generated/core/Ops.d.ts +203 -0
- package/types/generated/core/Random.d.ts +49 -0
- package/types/generated/core/Rays.d.ts +49 -0
- package/types/generated/core/Saves.d.ts +162 -0
- package/types/generated/core/Stream.d.ts +93 -0
- package/types/generated/core/Threads.d.ts +82 -0
- package/types/generated/core/Views.d.ts +33 -0
- package/types/generated/core/audioVoice.d.ts +47 -0
- package/types/generated/core/page.d.ts +18 -0
- package/types/generated/core/session.d.ts +48 -0
- package/types/generated/modules/ambience/Ambience.d.ts +48 -0
- package/types/generated/modules/debug/DebugPanel.d.ts +24 -0
- package/types/generated/modules/flow/index.d.ts +10 -0
- package/types/generated/modules/grid/Grid.d.ts +151 -0
- package/types/generated/modules/grid/Layer.d.ts +65 -0
- package/types/generated/modules/grid/index.d.ts +86 -0
- package/types/generated/modules/hlod/index.d.ts +11 -0
- package/types/generated/modules/hud/index.d.ts +10 -0
- package/types/generated/modules/lights/index.d.ts +13 -0
- package/types/generated/modules/music/Music.d.ts +111 -0
- package/types/generated/modules/net/Net.d.ts +34 -0
- package/types/generated/modules/net/index.d.ts +53 -0
- package/types/generated/modules/net/transports.d.ts +58 -0
- package/types/generated/modules/particles/Particles.d.ts +69 -0
- package/types/generated/modules/sky/Sky.d.ts +145 -0
- package/types/generated/modules/sky/skyModule.d.ts +10 -0
- package/types/generated/modules/timeline/Timeline.d.ts +51 -0
- package/types/generated/modules/water/Water.d.ts +29 -0
- package/types/generated/modules/weather/Weather.d.ts +62 -0
- package/types/generated/modules/world/World.d.ts +242 -0
- package/types/generated/modules/world/index.d.ts +15 -0
- package/types/generated/render/PostFX.d.ts +125 -0
- package/types/generated/render/materials.d.ts +100 -0
- package/types/generated/render/patches.d.ts +41 -0
- package/types/generated/ui/Focus.d.ts +11 -0
- package/types/generated/ui/LoadingScreen.d.ts +2 -0
- package/types/generated/ui/UI.d.ts +57 -0
- package/types/nav.d.ts +52 -0
- package/types/physics.d.ts +592 -0
- package/types/style.d.ts +638 -0
- package/types/worker.d.ts +11 -0
- package/types/world.d.ts +772 -0
- package/ui/Focus.js +51 -0
- package/ui/LoadingScreen.js +42 -0
- package/ui/Parts.js +199 -0
- package/ui/UI.js +167 -0
- package/ui/defaults.js +85 -0
- package/ui/theme.js +124 -0
- package/ui/touchPart.js +49 -0
package/index.js
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
// Engine entry.
|
|
2
|
+
//
|
|
3
|
+
// Core (always present): rendering, main loop, events, input, assets, audio, saves, UI base, loading screen, ground API
|
|
4
|
+
// Modules (opt-in): every lowercase function exported below is a module
|
|
5
|
+
//
|
|
6
|
+
// import { createEngine, terrain, vegetation, sky, weather, water, collision, rigid,
|
|
7
|
+
// followCamera, characters, interactions, dialogue, inventory, quests, photo, ambience, debug } from 'threedog';
|
|
8
|
+
// import lowpoly from '@threedog/style-lowpoly'; // optional: the engine itself ships no art
|
|
9
|
+
// import { terrainPreset } from '@threedog/terrain-noise'; // optional: nor a terrain generator
|
|
10
|
+
//
|
|
11
|
+
// const engine = createEngine({ canvas, style: lowpoly }); // without a style pack: neutral gray placeholders
|
|
12
|
+
// engine.use(terrain({ seed: 7, ...terrainPreset() }), vegetation(), sky(), weather(), water(), collision(), followCamera(), characters());
|
|
13
|
+
// engine.start();
|
|
14
|
+
//
|
|
15
|
+
// Or install the usual open-world set at once with a preset: engine.use(openWorld({ seed: 7, camera: 'follow', terrain: terrainPreset() }))
|
|
16
|
+
import * as THREE from 'three';
|
|
17
|
+
import { Engine } from './core/Engine.js';
|
|
18
|
+
import { terrain } from './modules/terrain/index.js';
|
|
19
|
+
import { vegetation } from './modules/vegetation/index.js';
|
|
20
|
+
import { sky } from './modules/sky/skyModule.js';
|
|
21
|
+
import { weather } from './modules/weather/Weather.js';
|
|
22
|
+
import { water } from './modules/water/Water.js';
|
|
23
|
+
import { collision } from './modules/collision/Collision.js';
|
|
24
|
+
import { rigid } from './modules/rigid/RigidBodies.js';
|
|
25
|
+
import { followCamera } from './modules/camera/FollowCamera.js';
|
|
26
|
+
import { characters } from './modules/characters/index.js';
|
|
27
|
+
import { interactions } from './modules/gameplay/Interactions.js';
|
|
28
|
+
import { dialogue } from './modules/gameplay/Dialogue.js';
|
|
29
|
+
import { inventory } from './modules/gameplay/Inventory.js';
|
|
30
|
+
import { quests } from './modules/gameplay/Quests.js';
|
|
31
|
+
import { photo } from './modules/photo/Photo.js';
|
|
32
|
+
import { ambience } from './modules/ambience/Ambience.js';
|
|
33
|
+
import { debug } from './modules/debug/DebugPanel.js';
|
|
34
|
+
import { level } from './modules/level/index.js';
|
|
35
|
+
import { triggers } from './modules/triggers/index.js';
|
|
36
|
+
import { entities } from './modules/entities/index.js';
|
|
37
|
+
import { particles } from './modules/particles/Particles.js';
|
|
38
|
+
import { settings } from './modules/settings/index.js';
|
|
39
|
+
import { music } from './modules/music/index.js';
|
|
40
|
+
import { firstPersonCamera, fixedCamera, rtsCamera } from './modules/camera/index.js';
|
|
41
|
+
import { timeline } from './modules/timeline/Timeline.js';
|
|
42
|
+
import { nav } from './modules/nav/index.js';
|
|
43
|
+
import { hlod } from './modules/hlod/index.js';
|
|
44
|
+
import { lightPool } from './modules/lights/index.js';
|
|
45
|
+
import { content } from './modules/content/index.js';
|
|
46
|
+
import { flow } from './modules/flow/index.js';
|
|
47
|
+
import { hud } from './modules/hud/index.js';
|
|
48
|
+
import { world } from './modules/world/index.js';
|
|
49
|
+
import { grids } from './modules/grid/index.js';
|
|
50
|
+
import { checkOptions, DEV } from './core/validate.js';
|
|
51
|
+
import { codedError } from './core/errorHints.js';
|
|
52
|
+
|
|
53
|
+
// Engine and Animator are exported for types and instanceof; make them with createEngine / engine.assets.animate (AI.md entry-point table)
|
|
54
|
+
export { THREE, Engine };
|
|
55
|
+
export { Animator } from './core/Animator.js';
|
|
56
|
+
export { terrain, vegetation, sky, weather, water, collision, rigid, followCamera, characters, interactions, dialogue, inventory, quests, photo, ambience, debug,
|
|
57
|
+
level, triggers, entities, particles, settings, music, firstPersonCamera, fixedCamera, rtsCamera, timeline, nav, hlod, lightPool, content, flow, hud, world, grids };
|
|
58
|
+
export { net, fakeNetwork, webSocket } from './modules/net/index.js';
|
|
59
|
+
export { screenToGround } from './core/screenToGround.js';
|
|
60
|
+
export { EASINGS, ease } from './core/easing.js';
|
|
61
|
+
export { checkOptions };
|
|
62
|
+
export { defineLookPart } from './core/look/part.js'; // a module's own look part: engine.look.<id> with set / patch / replace, catalog and describe (recipes/52)
|
|
63
|
+
export { readParams } from './core/params.js'; // params schema for game-made modules: validated, defaults filled, shown by engine.catalog() // for game-made modules (recipes/14): the package exposes no core/* deep paths
|
|
64
|
+
export { createTerrain } from './modules/terrain/index.js';
|
|
65
|
+
export { Character, NPC } from './modules/characters/index.js';
|
|
66
|
+
export { presets } from './presets.js'; // opt-in gameplay presets (weather tables, calendars, player feel, camera): never applied by the engine itself
|
|
67
|
+
export { terrainMaterial, mergeColored, applyEffects, makeMaterial, MATERIAL_PURPOSES } from './render/materials.js';
|
|
68
|
+
export { materialPatches } from './render/patches.js';
|
|
69
|
+
export { toast, makeWindow, worldToScreen, fadeScreen, uiFocus, toggleOnKey } from './ui/UI.js';
|
|
70
|
+
export { parseClock, formatClock, inRange } from './core/dayTime.js';
|
|
71
|
+
export { pickTarget, switchTarget } from './core/targeting.js';
|
|
72
|
+
|
|
73
|
+
/** Create an engine (core only). For the options see core/Engine.js */
|
|
74
|
+
export function createEngine(opts) { return new Engine(opts); }
|
|
75
|
+
export { postAdd, postRemove } from './core/styleParts.js';
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Open-world preset: covers only "world and environment" plus the basics every game needs:
|
|
79
|
+
* world, terrain, vegetation, sky, weather, water, collision, rigid, camera, characters, ambience, settings, debug (debug only in dev builds).
|
|
80
|
+
* Gameplay modules (interactions, dialogue, inventory, quests, photo mode, timeline, trigger zones, entities, particles, music, markers...) are not included:
|
|
81
|
+
* engine.use(openWorld({ seed: 7, camera: 'follow' }), interactions({ ...presets.interactions.nearest }), dialogue(), inventory({ ...presets.keys.inventory }), quests({ ...presets.keys.quests }));
|
|
82
|
+
* Every part takes false (leave it out) or an object (that module's own options), so the preset never has to be abandoned for one setting:
|
|
83
|
+
* openWorld({ seed: 7, camera: 'follow', sky: { seasons: ['wet', 'dry'], daysPerSeason: 28 }, characters: { npcs: false }, rigid: false, ambience: false })
|
|
84
|
+
* The bundle hides the terrain's far edge in fog (terrain viewFog: true; openWorld({ terrain: { viewFog: false } }) keeps the game's fogFar).
|
|
85
|
+
* Shorthands still work and go to their module: seed / viewChunks / density / flatten → terrain, time / dayLength → sky,
|
|
86
|
+
* weather: 'rain' (starting weather) and autoWeather → weather. An object for the same module wins over the shorthand.
|
|
87
|
+
* debug: installed only in dev builds by default (players of a release build get no F3 panel); true installs it in release builds too.
|
|
88
|
+
* Camera (required: the bundle picks no camera feel for the game): 'follow' / 'firstPerson' / 'rts' / 'fixed', a camera module with options, or false:
|
|
89
|
+
* engine.use(openWorld({ seed: 7, camera: followCamera({ shoulder: 0.7, distance: 3 }) }));
|
|
90
|
+
* Switch at runtime: engine.setCamera('firstPerson') (see recipes/21-camera.md).
|
|
91
|
+
* @param {{ camera: 'follow' | 'firstPerson' | 'rts' | 'fixed' | false | import('./types/core').ModuleDef, [k: string]: any }} opts
|
|
92
|
+
*/
|
|
93
|
+
const CAMERAS = { follow: followCamera, firstPerson: firstPersonCamera, rts: rtsCamera, fixed: fixedCamera };
|
|
94
|
+
const OPEN_WORLD_PARTS = { world, terrain, vegetation, sky, weather, water, collision, rigid, characters, ambience, settings, debug };
|
|
95
|
+
const OPEN_WORLD_SHORT = ['seed', 'viewChunks', 'density', 'flatten', 'time', 'dayLength', 'autoWeather', 'camera'];
|
|
96
|
+
const OW_ERR = { camera: 'openWorld(): camera has no kind \'{k}\'; available: {list}, or pass a camera module (e.g. rtsCamera({ height: 60 })) or false',
|
|
97
|
+
noCamera: "openWorld(): no camera given; pick one: openWorld({ camera: 'follow' }) (or 'firstPerson' / 'rts' / 'fixed', a camera module such as followCamera(presets.camera.overShoulder), or false for none)",
|
|
98
|
+
part: 'openWorld(): {k} must be false (leave it out), true or an options object, e.g. openWorld({ {k}: false }); got {got}',
|
|
99
|
+
noOpts: 'openWorld(): {k} takes no options, only true / false; got {got}. {hint}' };
|
|
100
|
+
// parts whose module takes no options: an options object would be dropped silently, so it throws and points to where the setting lives
|
|
101
|
+
const NO_OPTIONS = { vegetation: 'How much vegetation grows is a terrain setting: openWorld({ density: 1.5 }) or terrain({ density }); the species are game content (content vegetation; a style pack only paints them). On ground without terrain (a level) it takes its own options: openWorld({ terrain: false, vegetation: { area, density } })' };
|
|
102
|
+
export function openWorld(opts = {}) {
|
|
103
|
+
checkOptions('openWorld()', opts, [...OPEN_WORLD_SHORT, ...Object.keys(OPEN_WORLD_PARTS)]);
|
|
104
|
+
const { seed, viewChunks, density, flatten = [], time, dayLength, autoWeather = false, camera } = opts;
|
|
105
|
+
if (camera === undefined) throw codedError('open-world-camera', OW_ERR.noCamera); // no default camera feel: the game names one (genericity rule)
|
|
106
|
+
if (typeof camera === 'string' && !CAMERAS[camera]) throw new Error(OW_ERR.camera.replace('{k}', camera).replace('{list}', Object.keys(CAMERAS).join(', ')));
|
|
107
|
+
const w = opts.weather;
|
|
108
|
+
const short = { terrain: { seed, viewChunks, density, flatten, viewFog: true }, sky: { time, dayLength }, weather: { start: typeof w === 'string' ? w : undefined, auto: autoWeather } }; // no start: weather() picks one from the game's table
|
|
109
|
+
const part = k => {
|
|
110
|
+
const v = opts[k];
|
|
111
|
+
if (v === false || (k === 'debug' && v === undefined && !DEV)) return null;
|
|
112
|
+
if (v !== undefined && v !== true && typeof v !== 'object' && !(k === 'weather' && typeof v === 'string')) {
|
|
113
|
+
throw new Error(OW_ERR.part.replaceAll('{k}', k).replace('{got}', JSON.stringify(v)));
|
|
114
|
+
}
|
|
115
|
+
// vegetation takes options only when it grows on its own chunks (terrain: false); on terrain those settings belong to terrain
|
|
116
|
+
if (NO_OPTIONS[k] && !(k === 'vegetation' && opts.terrain === false) && v && typeof v === 'object' && Object.keys(v).length) throw new Error(OW_ERR.noOpts.replace('{k}', k).replace('{got}', JSON.stringify(v)).replace('{hint}', NO_OPTIONS[k]));
|
|
117
|
+
return OPEN_WORLD_PARTS[k]({ ...short[k], ...(typeof v === 'object' ? v : null) });
|
|
118
|
+
};
|
|
119
|
+
const cam = camera === false ? null : typeof camera === 'string' ? CAMERAS[camera]() : camera;
|
|
120
|
+
return [part('world'), part('terrain'), part('vegetation'), part('sky'), part('weather'), part('water'), part('collision'), part('rigid'),
|
|
121
|
+
cam, part('characters'), part('ambience'), part('settings'), part('debug')].filter(Boolean);
|
|
122
|
+
}
|
package/llms.txt
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# threedog
|
|
2
|
+
|
|
3
|
+
> A web 3D game engine on three.js 0.187 (plain three.js, no React): core, modules installed with engine.use, and style packs for all art.
|
|
4
|
+
|
|
5
|
+
Reading order: docs/AI.md (the index: one line per task) -> the recipe for the task -> docs/api/<module>.md for details -> the game's GAMEMAP.md.
|
|
6
|
+
|
|
7
|
+
## Start
|
|
8
|
+
|
|
9
|
+
- [AI.md](docs/AI.md): entry table, commands, verification rules, conventions
|
|
10
|
+
- [API.md](docs/API.md): API index; one page per module in docs/api/
|
|
11
|
+
|
|
12
|
+
## Recipes
|
|
13
|
+
|
|
14
|
+
- [01-new-game](docs/recipes/01-new-game.md): Starting a new game (a workspace under games/)
|
|
15
|
+
- [02-npc](docs/recipes/02-npc.md): Adding an NPC (schedule + dialogue)
|
|
16
|
+
- [03-items-pickups](docs/recipes/03-items-pickups.md): Adding items and pickups
|
|
17
|
+
- [04-quests](docs/recipes/04-quests.md): Adding quests (with HUD objective markers)
|
|
18
|
+
- [05-props-bake](docs/recipes/05-props-bake.md): Props and baking
|
|
19
|
+
- [06-clock-events](docs/recipes/06-clock-events.md): Scheduling events on the game clock
|
|
20
|
+
- [07-flow-scenes-pause](docs/recipes/07-flow-scenes-pause.md): Scene transitions and pause (flow)
|
|
21
|
+
- [08-weather-sky](docs/recipes/08-weather-sky.md): Add weather or change the sky
|
|
22
|
+
- [09-style-pack](docs/recipes/09-style-pack.md): Changing the art / writing a style pack
|
|
23
|
+
- [10-blender-level](docs/recipes/10-blender-level.md): Importing Blender models and levels
|
|
24
|
+
- [11-vehicles](docs/recipes/11-vehicles.md): Vehicles and boarding
|
|
25
|
+
- [12-navmesh](docs/recipes/12-navmesh.md): Navigation mesh (nav)
|
|
26
|
+
- [13-animation](docs/recipes/13-animation.md): Animation state machine (skeletal animation)
|
|
27
|
+
- [14-custom-module](docs/recipes/14-custom-module.md): Custom module
|
|
28
|
+
- [15-perf](docs/recipes/15-perf.md): Performance investigation (F3, budget, profile, describe().perf)
|
|
29
|
+
- [16-dev-bridge](docs/recipes/16-dev-bridge.md): Dev bridge: operate the running game from the terminal (npx threedog describe / step / press / op...)
|
|
30
|
+
- [18-world](docs/recipes/18-world.md): World data: things that must be saved, grow, and keep changing while far away
|
|
31
|
+
- [19-shooting-picking](docs/recipes/19-shooting-picking.md): Shooting and picking (first person; cast a ray from the screen center / mouse position)
|
|
32
|
+
- [20-content-actions-save](docs/recipes/20-content-actions-save.md): Content vocabulary, key actions in actions.js, saving and loading at startup
|
|
33
|
+
- [21-camera](docs/recipes/21-camera.md): Camera: first / third person, top-down strategy, fixed shots, switched at runtime
|
|
34
|
+
- [22-shop-gold](docs/recipes/22-shop-gold.md): Shop and gold: buy, sell / consign, gold HUD, saving
|
|
35
|
+
- [23-ops](docs/recipes/23-ops.md): Ops: one entry point for what players and NPCs do (engine.ops)
|
|
36
|
+
- [26-ui-parts](docs/recipes/26-ui-parts.md): UI parts: replace or turn off any piece of the engine's screen UI
|
|
37
|
+
- [27-net](docs/recipes/27-net.md): Co-op multiplayer: net() (host authority + state sync)
|
|
38
|
+
- [28-terrain](docs/recipes/28-terrain.md): Terrain: your own generator, digging, raising and painting the ground
|
|
39
|
+
- [29-grid](docs/recipes/29-grid.md): Grid placement: farming, furniture, crates, building
|
|
40
|
+
- [30-templates](docs/recipes/30-templates.md): Templates: reusable objects, definition vs instance state
|
|
41
|
+
- [31-audio](docs/recipes/31-audio.md): Sound: buses, sounds by name, ambience rules, music, footsteps, ducking
|
|
42
|
+
- [32-action-game](docs/recipes/32-action-game.md): Action game wiring: hp, attacks, enemy AI, drops and death without engine combat rules
|
|
43
|
+
- [33-stream-sources](docs/recipes/33-stream-sources.md): Stream sources: what is loaded where (teleport, far camera)
|
|
44
|
+
- [34-environment-lighting](docs/recipes/34-environment-lighting.md): Environment lighting
|
|
45
|
+
- [35-style-from-reference](docs/recipes/35-style-from-reference.md): Making a new look from a reference picture
|
|
46
|
+
- [36-sky-ground-plant-looks](docs/recipes/36-sky-ground-plant-looks.md): Sky, ground and plant looks: what a style can change
|
|
47
|
+
- [37-terrain-look-hooks](docs/recipes/37-terrain-look-hooks.md): Terrain look open points: shading, color map, triangle cut, normals
|
|
48
|
+
- [38-environment-look-hooks](docs/recipes/38-environment-look-hooks.md): Environment look open points: lights, fog, exposure, sky layers
|
|
49
|
+
- [40-scene](docs/recipes/40-scene.md): Scene: what is in the world, where, and what a save keeps
|
|
50
|
+
- [41-thing-registry](docs/recipes/41-thing-registry.md): Things: what is in the scene, who manages it, what a save keeps (engine.thing)
|
|
51
|
+
- [42-terrain-shape](docs/recipes/42-terrain-shape.md): Terrain outline: islands, floating rocks, a world that ends
|
|
52
|
+
- [43-shader-patches-surface-looks](docs/recipes/43-shader-patches-surface-looks.md): Writing shader patches and surface looks
|
|
53
|
+
- [44-water-weather-look-hooks](docs/recipes/44-water-weather-look-hooks.md): Water and weather look open points: depth color, foam, reflections, rain and snow, lightning, own particles
|
|
54
|
+
- [45-cascaded-shadows](docs/recipes/45-cascaded-shadows.md): Cascaded shadows
|
|
55
|
+
- [46-blender-art-route](docs/recipes/46-blender-art-route.md): Hand-painted art route: from Blender to the game
|
|
56
|
+
- [47-island-snow-backdrop](docs/recipes/47-island-snow-backdrop.md): Floating island look: round rim, snow that settles, flat backdrop
|
|
57
|
+
- [48-make-material](docs/recipes/48-make-material.md): 48. `engine.makeMaterial(role, spec)`: which keys work, who wins
|
|
58
|
+
- [49-game-module-contract](docs/recipes/49-game-module-contract.md): Writing a game system module (crops, burning, a production machine) that plugs into the engine's contracts
|
|
59
|
+
- [50-own-renderer](docs/recipes/50-own-renderer.md): Bring your own renderer: `createEngine({ renderer })`
|
|
60
|
+
- [51-capability-catalog](docs/recipes/51-capability-catalog.md): Capability catalog: ask what the game can do before reading docs
|
|
61
|
+
- [52-look](docs/recipes/52-look.md): 52 Change any look: `engine.look`
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
// Ambience module: a rule table of background sounds. Each rule names a sound from audio.sounds and says when and how loud it plays:
|
|
2
|
+
//
|
|
3
|
+
// createEngine({ audio: {
|
|
4
|
+
// sounds: { wind: 'synth', cave: '/sfx/cave-drip.ogg', crows: ['/sfx/crow1.ogg', '/sfx/crow2.ogg'] },
|
|
5
|
+
// ambience: [
|
|
6
|
+
// { sound: 'wind', volume: e => 0.1 + (e.weather?.current.wind ?? 0) * 0.1 }, // a loop; volume may be a function of the moment
|
|
7
|
+
// { sound: 'cave', when: { zone: 'cave' }, volume: 0.6, fade: 2 }, // condition keys: zone (triggers), time (sky), weather, state
|
|
8
|
+
// { sound: 'crows', when: { time: 'day' }, every: [4, 12] }, // every: a one-shot at random gaps instead of a loop
|
|
9
|
+
// ] } });
|
|
10
|
+
// The same rules as data in a content pack (audio: { ambience }): measures instead of functions, e.g.
|
|
11
|
+
// { sound: 'rain', volume: { add: { rain: 0.22 } } }, { sound: 'birds', when: { daylight: { gt: 0.15 } }, every: [2, 7] }
|
|
12
|
+
// This module adds the measures nearWater (share of water within 12 m of the listener, 0-1) and altitude (ground height under it, 0 below sea level).
|
|
13
|
+
// engine.use(ambience()); // openWorld() installs it
|
|
14
|
+
//
|
|
15
|
+
// The engine plays nothing unless a rule asks. Built-in synths (wind, rain, water, birds, crickets) are registered silent and only play
|
|
16
|
+
// when the game's audio.sounds names them ('synth'). A rule that is off fades out and its loop stops, so unused rules cost nothing.
|
|
17
|
+
// Timing of one-shots only affects sound (not gameplay), so it uses Math.random and carries // presentation.
|
|
18
|
+
|
|
19
|
+
import * as THREE from 'three';
|
|
20
|
+
import { checkOptions } from '../../core/validate.js';
|
|
21
|
+
import { readParams, keysSchema } from '../../core/params.js';
|
|
22
|
+
/** @import { ModuleDef, AmbienceRule } from '../../types/core' */
|
|
23
|
+
/** @import { AmbienceOptions } from '../../types/gameplay' */
|
|
24
|
+
const RULE_KEYS = ['sound', 'when', 'volume', 'fade', 'every', 'bus'];
|
|
25
|
+
const gap = r => r.every[0] + Math.random() * (r.every[1] - r.every[0]); // presentation
|
|
26
|
+
|
|
27
|
+
/** engine.ambience: the rule table of background sounds */
|
|
28
|
+
export class Ambience {
|
|
29
|
+
/** @internal */
|
|
30
|
+
constructor(engine, opts = {}) {
|
|
31
|
+
/** @internal */ this.engine = engine;
|
|
32
|
+
/** @internal */ this.interval = opts.interval ?? 0.25;
|
|
33
|
+
/** @internal */ this._acc = 0;
|
|
34
|
+
/** @internal @type {{ rule: AmbienceRule, voice: any, level: number, offT: number, next: number }[]} */
|
|
35
|
+
this._rules = [];
|
|
36
|
+
/** Where the sounds are heard from: whoever the player controls (engine.actor), else the camera focus @type {THREE.Vector3} */
|
|
37
|
+
this.position = new THREE.Vector3();
|
|
38
|
+
for (const r of [...(engine.audio.config.ambience || []), ...(opts.rules || [])]) this.add(r);
|
|
39
|
+
/** @internal content pack key -> handles of its rules (a pack loaded again replaces its own rules, never the game's) */
|
|
40
|
+
this._packs = new Map();
|
|
41
|
+
engine.audio.onPack((key, pack) => {
|
|
42
|
+
for (const h of this._packs.get(key) || []) h.remove();
|
|
43
|
+
this._packs.set(key, pack.ambience.map(r => this.add(r)));
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Add one rule; returns a handle whose remove() fades the sound out and drops the rule
|
|
49
|
+
* @param {AmbienceRule} rule
|
|
50
|
+
* @returns {{ remove(): void }}
|
|
51
|
+
* @example const h = engine.ambience.add({ sound: 'storm-wind', when: { weather: 'storm' }, volume: 0.5 });
|
|
52
|
+
*/
|
|
53
|
+
add(rule) {
|
|
54
|
+
checkOptions('ambience rule', rule, RULE_KEYS);
|
|
55
|
+
if (typeof rule.sound !== 'string') throw new TypeError(`ambience rule needs sound: a name from audio.sounds, got ${JSON.stringify(rule.sound)}. Example: { sound: 'wind', volume: 0.3 }`);
|
|
56
|
+
const slot = { rule, voice: null, level: 0, offT: 0, next: rule.every ? gap(rule) : 0 };
|
|
57
|
+
this._rules.push(slot);
|
|
58
|
+
return { remove: () => { slot.voice?.stop(rule.fade ?? 1); this._rules = this._rules.filter(s => s !== slot); } };
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Replace the whole rule table (null or [] = silence)
|
|
62
|
+
* @param {AmbienceRule[] | null} list
|
|
63
|
+
* @returns {this}
|
|
64
|
+
*/
|
|
65
|
+
rules(list) {
|
|
66
|
+
for (const s of this._rules) s.voice?.stop(s.rule.fade ?? 1);
|
|
67
|
+
this._rules = [];
|
|
68
|
+
for (const r of list || []) this.add(r);
|
|
69
|
+
return this;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* How much of the ground within `radius` meters of the listener is water (0-1), sampled at 6 points: for a water rule's volume
|
|
73
|
+
* @param {number} [radius]
|
|
74
|
+
* @returns {number}
|
|
75
|
+
* @example { sound: 'river', volume: (e, a) => a.nearWater(20) * 0.12 } // in data: volume: { add: { nearWater: 0.12 } } (12 m)
|
|
76
|
+
*/
|
|
77
|
+
nearWater(radius = 12) {
|
|
78
|
+
const e = this.engine, p = this.position; let n = 0;
|
|
79
|
+
for (let ang = 0; ang < 6.28; ang += 1.05) {
|
|
80
|
+
const x = p.x + Math.cos(ang) * radius, z = p.z + Math.sin(ang) * radius;
|
|
81
|
+
if (e.surface(x, z) < e.waterAt(x, z)) n += 1 / 6;
|
|
82
|
+
}
|
|
83
|
+
return n;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* What each rule is doing (debug, tests): sound name, whether its condition holds, its current target volume
|
|
87
|
+
* @returns {{ sound: string, on: boolean, volume: number }[]}
|
|
88
|
+
*/
|
|
89
|
+
get info() { return this._rules.map(s => ({ sound: s.rule.sound, on: s.level > 0, volume: +s.level.toFixed(3) })); }
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Per-frame update: checks the rules every `interval` seconds and fades sounds toward their targets
|
|
93
|
+
* @param {number} dt
|
|
94
|
+
* @returns {void}
|
|
95
|
+
* @internal
|
|
96
|
+
*/
|
|
97
|
+
update(dt) {
|
|
98
|
+
const e = this.engine, a = e.audio;
|
|
99
|
+
if (!a.running || !this._rules.length) return;
|
|
100
|
+
if ((this._acc += dt) < this.interval) return;
|
|
101
|
+
dt = this._acc; this._acc = 0;
|
|
102
|
+
this._listen();
|
|
103
|
+
for (const s of this._rules) this._step(s, dt);
|
|
104
|
+
}
|
|
105
|
+
/** @internal Refresh this.position from the listener (player, else the camera focus). The measures call it too: music rules read them while ambience may have no rules (then update() returns early and never moves the position) */
|
|
106
|
+
_listen() { const p = this.engine.actorPosition() ?? this.engine.focus; return this.position.set(p.x, p.y ?? 0, p.z); }
|
|
107
|
+
/** @internal */
|
|
108
|
+
_step(s, dt) {
|
|
109
|
+
const r = s.rule, a = this.engine.audio, fade = r.fade ?? 1;
|
|
110
|
+
if (s.failed) return; // its file failed to load: retrying every check would refetch it ~4 times a second forever. Reloading the rules (rules(), a pack loaded again, a page reload) tries again
|
|
111
|
+
if (s.voice?.failed) { s.failed = true; s.voice = null; console.warn(`[threedog] ambience: sound '${r.sound}' failed to load, its rule stays silent until the rules are loaded again. Fix the file path / asset name in audio.sounds`); return; }
|
|
112
|
+
const on = a.matches(r.when, this);
|
|
113
|
+
s.level = on ? Math.max(0, a.volumeOf(r.volume, this)) : 0;
|
|
114
|
+
if (r.every) {
|
|
115
|
+
if ((s.next -= dt) > 0) return;
|
|
116
|
+
s.next = gap(r);
|
|
117
|
+
if (s.level > 0) a.sfx(r.sound, { bus: r.bus ?? 'ambience', volume: s.level });
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
if (s.level > 0.001) {
|
|
121
|
+
s.offT = 0;
|
|
122
|
+
if (!s.voice?.playing) s.voice = a.sfx(r.sound, { bus: r.bus ?? 'ambience', loop: true, volume: 0 });
|
|
123
|
+
s.voice?.fade(s.level, fade);
|
|
124
|
+
} else if (s.voice) {
|
|
125
|
+
if (s.offT === 0) s.voice.fade(0, fade);
|
|
126
|
+
if ((s.offT += dt) > fade) { s.voice.stop(0); s.voice = null; s.offT = 0; } // faded out: stop the loop so an idle rule costs nothing
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// ---------- built-in synths (silent until the game's audio.sounds names them, e.g. wind: 'synth') ----------
|
|
132
|
+
/** A filtered noise loop with an optional slow wobble on its level (wind gusts) */
|
|
133
|
+
function noiseLoop(audio, out, filters, wobble = 0) {
|
|
134
|
+
const ctx = audio.ctx, src = ctx.createBufferSource(), mix = ctx.createGain(), nodes = [src];
|
|
135
|
+
src.buffer = audio.noise; src.loop = true; src.playbackRate.value = 0.5 + Math.random() * 0.5; // presentation
|
|
136
|
+
for (const [type, freq, q, vol = 1] of filters) {
|
|
137
|
+
const f = ctx.createBiquadFilter(), g = ctx.createGain(); f.type = type; f.frequency.value = freq; f.Q.value = q; g.gain.value = vol;
|
|
138
|
+
src.connect(f).connect(g).connect(mix);
|
|
139
|
+
}
|
|
140
|
+
if (wobble) { // two slow oscillators on the level: the gusting of the old per-frame code, without per-frame work
|
|
141
|
+
for (const hz of [0.37, 0.13]) { const o = ctx.createOscillator(), d = ctx.createGain(); o.frequency.value = hz; d.gain.value = wobble / 2; o.connect(d).connect(mix.gain); o.start(); nodes.push(o); }
|
|
142
|
+
mix.gain.value = 1 - wobble / 2;
|
|
143
|
+
}
|
|
144
|
+
mix.connect(out); src.start(0, Math.random()); // presentation
|
|
145
|
+
return { stop: t => { for (const n of nodes) n.stop(t); } };
|
|
146
|
+
}
|
|
147
|
+
const SYNTHS = {
|
|
148
|
+
wind: (a, p, out) => noiseLoop(a, out, [['bandpass', p.freq ?? 330, 0.6]], p.gust ?? 0.3),
|
|
149
|
+
rain: (a, p, out) => noiseLoop(a, out, [['highpass', 1800, 0.3], ['lowpass', 500, 0.5, 0.8]]),
|
|
150
|
+
water: (a, p, out) => noiseLoop(a, out, [['lowpass', p.freq ?? 700, 1]]),
|
|
151
|
+
birds: (a, p, out) => { // p.range: [low, high] Hz of the chirps; p.pitch is the sfx pitch multiplier every synth gets
|
|
152
|
+
const [lo, hi] = p.range ?? [2200, 4000], base = (lo + Math.random() * (hi - lo)) * (p.pitch ?? 1), notes = 2 + Math.floor(Math.random() * 4), pan = Math.random() * 2 - 1; // presentation
|
|
153
|
+
let t = 0;
|
|
154
|
+
for (let i = 0; i < notes; i++) { a.tone({ freq: base * (1 + Math.random() * 0.3), to: base * (0.7 + Math.random() * 0.6), dur: 0.08, vol: p.volume ?? 0.04, delay: t, pan, out }); t += 0.09 + Math.random() * 0.06; } // presentation
|
|
155
|
+
return t + 0.1;
|
|
156
|
+
},
|
|
157
|
+
crickets: (a, p, out) => { // p.freq: chirp Hz (default 4300); p.pitch is the sfx pitch multiplier (~1), like birds
|
|
158
|
+
const pan = Math.random() * 2 - 1; // presentation
|
|
159
|
+
for (let i = 0; i < 3; i++) a.tone({ freq: ((p.freq ?? 4300) + Math.random() * 200) * (p.pitch ?? 1), dur: 0.035, vol: p.volume ?? 0.02, delay: i * 0.05, pan, out }); // presentation
|
|
160
|
+
return 0.2;
|
|
161
|
+
},
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
const AMBIENCE_PARAMS = keysSchema(['rules', 'interval']);
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Ambience -> engine.ambience. Rules come from createEngine({ audio: { ambience: [...] } }) plus opts.rules
|
|
168
|
+
* @param {AmbienceOptions} [opts]
|
|
169
|
+
* @returns {ModuleDef<Ambience>}
|
|
170
|
+
* @example engine.use(ambience({ rules: [{ sound: 'hum', when: { zone: 'lab' }, volume: 0.4 }] }));
|
|
171
|
+
*/
|
|
172
|
+
export function ambience(opts = {}) {
|
|
173
|
+
readParams('ambience', AMBIENCE_PARAMS, opts);
|
|
174
|
+
let a = null;
|
|
175
|
+
return { name: 'ambience', params: AMBIENCE_PARAMS, options: opts, label: 'Ambience', stage: 'late', presentation: true,
|
|
176
|
+
install(e) {
|
|
177
|
+
for (const [name, fn] of Object.entries(SYNTHS)) e.audio.register(name, fn, { builtIn: true, bus: 'ambience' });
|
|
178
|
+
a = new Ambience(e, opts);
|
|
179
|
+
// measures for data rules (content packs hold no functions). Each reads the listener position itself: music rules call them too,
|
|
180
|
+
// and ambience refreshes this.position only while it has rules of its own
|
|
181
|
+
e.audio.measure('nearWater', () => { a._listen(); return a.nearWater(12); });
|
|
182
|
+
e.audio.measure('altitude', () => { const p = a._listen(); return Math.max(0, e.surface(p.x, p.z)); });
|
|
183
|
+
return a;
|
|
184
|
+
},
|
|
185
|
+
frame(dt) { a.update(dt); } };
|
|
186
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
// First-person camera: sits at the character's eye height; the mouse looks around.
|
|
2
|
+
// - Desktop: with pointerLock true, one click locks the mouse (Esc exits), then moving the mouse turns the head; otherwise hold and drag to turn
|
|
3
|
+
// - Mobile: drag to turn
|
|
4
|
+
// - Slight vertical bob while walking (headBob), can be turned off
|
|
5
|
+
// - hideTarget: hide the followed character from the camera (no seeing inside your own body); the shadow stays
|
|
6
|
+
// Cutscene takeover: while someone holds engine.takeCamera (engine.cameraOverride is not null) the camera is left alone (see common.js).
|
|
7
|
+
//
|
|
8
|
+
// engine.use(firstPersonCamera({ height: 1.6, sensitivity: 1, fov: 70, headBob: 0.04, pointerLock: true }));
|
|
9
|
+
// engine.cameraRig.yaw = Math.PI; // set facing directly
|
|
10
|
+
// engine.cameraRig.lookAt(position); // turn toward a point (Vector3 / object / [x, y, z])
|
|
11
|
+
// engine.setCamera('follow'); // switch back to third person at runtime (mouse lock releases, body shows again); see recipes/21-camera.md
|
|
12
|
+
import * as THREE from 'three';
|
|
13
|
+
import { rigModule, defineRig, YAW_RIG, clickToLock, releaseLock } from './common.js';
|
|
14
|
+
import { vec3 } from '../../core/math.js';
|
|
15
|
+
|
|
16
|
+
export class FirstPersonCamera {
|
|
17
|
+
/**
|
|
18
|
+
* height eye height above the feet; sensitivity mouse sensitivity; fov field of view (unchanged if omitted);
|
|
19
|
+
* headBob walking bob amplitude (m, 0 = off); bobFrequency bobs per meter; hideTarget hide the character itself; hideLayer layer number used for hiding (0-31, must not clash with other uses);
|
|
20
|
+
* pointerLock lock the mouse on click (the press that locks is swallowed: not Mouse0, not a click; swallowLockClick: false delivers it); yaw/pitch initial facing; minPitch/maxPitch look-down/look-up limits (radians);
|
|
21
|
+
* yawLimits [min, max] limits left-right turning (e.g. seated in a car), unlimited by default; smoothing how smoothly the camera follows the body; invertY flip vertical look
|
|
22
|
+
*/
|
|
23
|
+
constructor(engine, { height = 1.6, sensitivity = 1, fov = null, headBob = 0.04, bobFrequency = 0.9, hideTarget = true, hideLayer = 30,
|
|
24
|
+
pointerLock = true, yaw = 0, pitch = 0, minPitch = -1.45, maxPitch = 1.45, yawLimits = null, smoothing = 30, invertY = false, swallowLockClick = true } = {}) {
|
|
25
|
+
Object.assign(this, { swallowLockClick, engine, height, sensitivity, headBob, bobFrequency, hideTarget, hideLayer, pointerLock, yaw, pitch, minPitch, maxPitch, yawLimits, smoothing, invertY });
|
|
26
|
+
this.target = null;
|
|
27
|
+
this.eye = new THREE.Vector3();
|
|
28
|
+
this._bob = 0; this._bobAmp = 0; this._last = null; this._hidden = [];
|
|
29
|
+
this.fov = fov;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Called when this camera is switched in (module install, setCamera): applies fov and click-to-lock; a runtime switch (key press counts as a gesture) locks at once */
|
|
33
|
+
onEnter(switched) {
|
|
34
|
+
const { engine, fov } = this;
|
|
35
|
+
if (fov) { engine.camera.fov = fov; engine.camera.updateProjectionMatrix(); }
|
|
36
|
+
// The shadow camera must see the hidden layer too, or the character's shadow vanishes
|
|
37
|
+
this._shadowLayers();
|
|
38
|
+
clickToLock(this, switched);
|
|
39
|
+
}
|
|
40
|
+
/** Called when this camera is switched out: release the mouse lock and show the body again */
|
|
41
|
+
onExit() {
|
|
42
|
+
releaseLock(this);
|
|
43
|
+
this.follow(null); // body shows again; stop watching newly loaded models
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
follow(obj) {
|
|
47
|
+
this._unhide();
|
|
48
|
+
this._onChild && this.target?.removeEventListener('childadded', this._onChild);
|
|
49
|
+
this.target = obj; this._last = null;
|
|
50
|
+
if (obj) {
|
|
51
|
+
this.eye.copy(obj.position); this.eye.y += this.height; this._hide();
|
|
52
|
+
// The model may load later (attached under the character): hide children as they are added, no periodic traversal
|
|
53
|
+
this._onChild ??= () => this._hide();
|
|
54
|
+
obj.addEventListener('childadded', this._onChild);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Turn toward a world position (Vector3 / object / [x, y, z] / { x, y, z }).
|
|
59
|
+
* The angle is computed from where the head is NOW (the followed body's current position + eye height), not from the last drawn frame,
|
|
60
|
+
* so teleport-then-lookAt works in one go: `await engine.stream.teleport(p); engine.cameraRig.lookAt(target);`. The eye is also snapped there
|
|
61
|
+
* (no easing up from the old height after a teleport). Call lookAt after the move, not before: yaw/pitch are angles, they do not follow later moves.
|
|
62
|
+
* @example await engine.stream.teleport([10, 0, 4]); engine.cameraRig.lookAt([10, 1.5, -6]);
|
|
63
|
+
* @param {any} position
|
|
64
|
+
*/
|
|
65
|
+
lookAt(position) {
|
|
66
|
+
const t = this.target?.position;
|
|
67
|
+
if (t) this.eye.set(t.x, t.y + this.height, t.z); // teleport moved the body; update() would only catch up on the next frame
|
|
68
|
+
const { x, y, z } = vec3(position, this._look ??= new THREE.Vector3()), dx = x - this.eye.x, dy = y - this.eye.y, dz = z - this.eye.z;
|
|
69
|
+
this.yaw = Math.atan2(-dx, -dz);
|
|
70
|
+
this.pitch = Math.atan2(dy, Math.hypot(dx, dz));
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
update(dt, input) {
|
|
74
|
+
const cam = this.engine.camera;
|
|
75
|
+
if (input.enabled) {
|
|
76
|
+
const k = 0.0025 * this.sensitivity;
|
|
77
|
+
this.yaw -= input.look.dx * k;
|
|
78
|
+
this.pitch -= input.look.dy * k * (this.invertY ? -1 : 1);
|
|
79
|
+
}
|
|
80
|
+
if (this.yawLimits) this.yaw = Math.min(this.yawLimits[1], Math.max(this.yawLimits[0], this.yaw));
|
|
81
|
+
this.pitch = Math.min(this.maxPitch, Math.max(this.minPitch, this.pitch));
|
|
82
|
+
if (this.target) {
|
|
83
|
+
const p = this.target.position;
|
|
84
|
+
// Walking bob: advance the phase by how far the character moved this frame
|
|
85
|
+
let speed = 0;
|
|
86
|
+
if (this._last && dt > 0) speed = Math.hypot(p.x - this._last.x, p.z - this._last.z) / dt;
|
|
87
|
+
(this._last ??= new THREE.Vector3()).copy(p);
|
|
88
|
+
if (this.headBob > 0) {
|
|
89
|
+
this._bob += speed * dt * this.bobFrequency * Math.PI * 2;
|
|
90
|
+
const want = Math.min(1, speed / 4) * this.headBob;
|
|
91
|
+
this._bobAmp += (want - this._bobAmp) * (1 - Math.exp(-8 * dt));
|
|
92
|
+
}
|
|
93
|
+
const k = 1 - Math.exp(-this.smoothing * dt);
|
|
94
|
+
this.eye.x = p.x; this.eye.z = p.z;
|
|
95
|
+
this.eye.y += (p.y + this.height - this.eye.y) * k;
|
|
96
|
+
}
|
|
97
|
+
cam.position.copy(this.eye);
|
|
98
|
+
cam.position.y += Math.sin(this._bob) * this._bobAmp;
|
|
99
|
+
cam.rotation.set(this.pitch, this.yaw, Math.sin(this._bob * 0.5) * this._bobAmp * 0.15, 'YXZ');
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** Release the mouse lock when a cutscene takes over */
|
|
103
|
+
onOverride(on) {
|
|
104
|
+
if (on) releaseLock(this, true);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
_hide() {
|
|
108
|
+
if (!this.hideTarget || !this.target) return;
|
|
109
|
+
this.target.traverse(o => {
|
|
110
|
+
if ((o.isMesh || o.isSkinnedMesh || o.isPoints || o.isLine) && !o.layers.isEnabled(this.hideLayer)) {
|
|
111
|
+
this._hidden.push([o, o.layers.mask]);
|
|
112
|
+
o.layers.set(this.hideLayer);
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
_unhide() { for (const [o, mask] of this._hidden) o.layers.mask = mask; this._hidden = []; }
|
|
117
|
+
// Done once at module install (the sky module has built the lights by then); lights added later call shadow.camera.layers.enable(hideLayer) themselves
|
|
118
|
+
_shadowLayers() { this.engine.scene.traverse(o => { if (o.isLight && o.shadow?.camera) o.shadow.camera.layers.enable(this.hideLayer); }); }
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
Object.assign(FirstPersonCamera.prototype, YAW_RIG); // forward / right / focusPoint
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* First-person camera module. Installs engine.cameraRig (pick it or followCamera; switch at runtime with engine.setCamera('firstPerson')).
|
|
125
|
+
* firstPersonCamera({ height: 1.6, sensitivity: 1, fov: 70, headBob: 0.04, hideTarget: true, pointerLock: true })
|
|
126
|
+
*/
|
|
127
|
+
export function firstPersonCamera(opts = {}) { return rigModule('firstPerson', opts); }
|
|
128
|
+
defineRig('firstPerson', (e, opts) => {
|
|
129
|
+
return new FirstPersonCamera(e, opts);
|
|
130
|
+
}, ['height', 'sensitivity', 'fov', 'headBob', 'bobFrequency', 'hideTarget', 'hideLayer', 'pointerLock', 'yaw', 'pitch',
|
|
131
|
+
'minPitch', 'maxPitch', 'yawLimits', 'smoothing', 'invertY', 'swallowLockClick']);
|