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/core/inputPad.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// Gamepad (standard layout) button names; like keyboard key names they can go into action bindings
|
|
2
|
+
const PAD_BUTTONS = ['PadA', 'PadB', 'PadX', 'PadY', 'PadLB', 'PadRB', 'PadLT', 'PadRT', 'PadSelect', 'PadStart', 'PadL3', 'PadR3', 'PadUp', 'PadDown', 'PadLeft', 'PadRight'];
|
|
3
|
+
|
|
4
|
+
/** Read the first connected gamepad into the input's keys, stick and look (every frame, allocates nothing) @internal */
|
|
5
|
+
export function pollPad(input, dt) {
|
|
6
|
+
const pads = navigator.getGamepads?.();
|
|
7
|
+
let gp = null;
|
|
8
|
+
if (pads) for (let i = 0; i < pads.length && !gp; i++) if (pads[i]?.connected) gp = pads[i];
|
|
9
|
+
if (!gp) {
|
|
10
|
+
input.padStick.x = input.padStick.y = 0;
|
|
11
|
+
if (input._padOn) { input._padOn = false; for (const b of PAD_BUTTONS) input._keyUp(b); } // disconnected (battery died): release what it held, once
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
input._padOn = true;
|
|
15
|
+
const btns = gp.buttons;
|
|
16
|
+
for (let i = 0; i < btns.length && i < PAD_BUTTONS.length; i++) { if (btns[i].pressed) input._keyDown(PAD_BUTTONS[i], 'pad'); else input._keyUp(PAD_BUTTONS[i]); }
|
|
17
|
+
const z = input.padDeadzone, cut = v => Math.abs(v) < z ? 0 : v;
|
|
18
|
+
input.padStick.x = cut(gp.axes[0] || 0); input.padStick.y = -cut(gp.axes[1] || 0);
|
|
19
|
+
const lx = cut(gp.axes[2] || 0), ly = cut(gp.axes[3] || 0);
|
|
20
|
+
if (lx || ly || input.padStick.x || input.padStick.y) input.lastDevice = 'pad';
|
|
21
|
+
input.look.dx += lx * input.padLookSpeed * 60 * dt; input.look.dy += ly * input.padLookSpeed * 60 * dt;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const KEY_NAMES = { Space: 'Space', Enter: 'Enter', Escape: 'Esc', ShiftLeft: 'Shift', ShiftRight: 'Shift', ControlLeft: 'Ctrl', AltLeft: 'Alt', ArrowUp: '↑', ArrowDown: '↓', ArrowLeft: '←', ArrowRight: '→', Tab: 'Tab', Backquote: '`' };
|
|
25
|
+
const keyName = code => KEY_NAMES[code] ?? code.replace(/^Key|^Digit|^Pad/, '');
|
|
26
|
+
|
|
27
|
+
/** Key name shown in the UI, e.g. "E" (follows the last used device: gamepad keys after a pad press) @internal */
|
|
28
|
+
export function keyLabel(input, action) {
|
|
29
|
+
const keys = input.keysOf(action).filter(k => !k.startsWith('Touch:'));
|
|
30
|
+
const pad = keys.filter(k => k.startsWith('Pad')), kb = keys.filter(k => !k.startsWith('Pad'));
|
|
31
|
+
const use = input.lastDevice === 'pad' && pad.length ? pad : kb.length ? kb : pad;
|
|
32
|
+
// Key names go through the string table too (key.Space -> its localized name); fall back to the generic form if missing
|
|
33
|
+
const name = k => input.engine.i18n?.has('key.' + k) ? input.engine.t('key.' + k) : keyName(k);
|
|
34
|
+
return use.map(name).filter((v, i, arr) => arr.indexOf(v) === i).join('/');
|
|
35
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// The mouse / touch pointer part of input: drag to look, wheel to zoom, pointer state; mouse buttons act as keys (Mouse0 left / Mouse1 middle / Mouse2 right) passed to Input's _keyDown / _keyUp,
|
|
2
|
+
// the same path as the keyboard, so they can be defined as actions and enter the fixed-step snapshot. Touch taps are not mouse buttons (pointerType only accepts 'mouse').
|
|
3
|
+
|
|
4
|
+
/** Wire pointer events on the canvas to input (called once when Input is constructed). signal: engine.dispose() cancels all listeners at once */
|
|
5
|
+
export function bindPointer(input, canvas, signal) {
|
|
6
|
+
let drag = null;
|
|
7
|
+
// pointer x / y are pixels from the canvas content box's top-left, ndc is -1..1 across that box: a canvas in a page section or editor
|
|
8
|
+
// panel picks the thing under the mouse, not the thing under the same window position. Read on every event (the canvas may have moved)
|
|
9
|
+
const place = e => {
|
|
10
|
+
const p = input.pointer, b = canvas.getBoundingClientRect(), w = canvas.clientWidth || b.width || 1, h = canvas.clientHeight || b.height || 1;
|
|
11
|
+
p.x = e.clientX - b.left - canvas.clientLeft; p.y = e.clientY - b.top - canvas.clientTop;
|
|
12
|
+
p.ndcX = p.x / w * 2 - 1; p.ndcY = -(p.y / h) * 2 + 1;
|
|
13
|
+
};
|
|
14
|
+
canvas.addEventListener('pointerdown', e => {
|
|
15
|
+
place(e); // a touch tap has no pointermove before it: without this, ndc would still point at the last drag
|
|
16
|
+
// The press that only locks the mouse (camera pointerLock) is not an action: no Mouse0, no click, no pointer.down
|
|
17
|
+
const swallowed = e.pointerType === 'mouse' && !!input.swallowLockClick?.();
|
|
18
|
+
if (!swallowed) {
|
|
19
|
+
input.pointer.down = true; input.pointer.button = e.button;
|
|
20
|
+
if (e.pointerType === 'mouse') input._keyDown('Mouse' + e.button, 'keyboard');
|
|
21
|
+
}
|
|
22
|
+
drag = { x: e.clientX, y: e.clientY, id: e.pointerId, moved: 0, swallowed }; canvas.focus();
|
|
23
|
+
// While the mouse is locked (first person) Chromium rejects pointer capture with InvalidStateError; capture is only needed for drag-to-look anyway
|
|
24
|
+
if (document.pointerLockElement !== canvas) canvas.setPointerCapture(e.pointerId);
|
|
25
|
+
}, { signal });
|
|
26
|
+
canvas.addEventListener('pointermove', e => {
|
|
27
|
+
const p = input.pointer;
|
|
28
|
+
place(e);
|
|
29
|
+
if (!drag || drag.id !== e.pointerId) return;
|
|
30
|
+
const dx = e.clientX - drag.x, dy = e.clientY - drag.y;
|
|
31
|
+
if (document.pointerLockElement === canvas) return;
|
|
32
|
+
input.look.dx += dx; input.look.dy += dy; drag.moved += Math.abs(dx) + Math.abs(dy); drag.x = e.clientX; drag.y = e.clientY;
|
|
33
|
+
}, { signal });
|
|
34
|
+
// When the mouse is locked (first person), use relative movement
|
|
35
|
+
addEventListener('mousemove', e => { if (document.pointerLockElement === canvas) { input.look.dx += e.movementX; input.look.dy += e.movementY; } }, { signal });
|
|
36
|
+
const end = e => {
|
|
37
|
+
const swallowed = drag?.swallowed;
|
|
38
|
+
if (drag && !swallowed && drag.moved < 6) input.pointer.clicked = true;
|
|
39
|
+
drag = null;
|
|
40
|
+
if (swallowed) return;
|
|
41
|
+
input.pointer.down = false;
|
|
42
|
+
if (e.pointerType === 'mouse') input._keyUp('Mouse' + e.button);
|
|
43
|
+
};
|
|
44
|
+
canvas.addEventListener('pointerup', end, { signal }); canvas.addEventListener('pointercancel', end, { signal });
|
|
45
|
+
// if the right button is bound to an action, do not show the browser menu
|
|
46
|
+
canvas.addEventListener('contextmenu', e => { if ([...input.actions.values()].some(a => a.keys.includes('Mouse2'))) e.preventDefault(); }, { signal });
|
|
47
|
+
canvas.addEventListener('wheel', e => { e.preventDefault(); input.look.zoom += Math.sign(e.deltaY); }, { passive: false, signal });
|
|
48
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// The touch part of input: which on-screen controls the game needs (a stick, a button per action) and what using them does.
|
|
2
|
+
// Drawing is the UI part 'touch' (default ui/touchPart.js); a game replaces it or turns it off with createEngine({ ui: { touch: ... } }).
|
|
3
|
+
// press / release go to Input's _keyDown / _keyUp as the key 'Touch:<action>', the same path as real keys (snapshot and just-pressed behave identically).
|
|
4
|
+
/** @import { Input } from './Input.js' */
|
|
5
|
+
/** @import { TouchView } from '../types/core' */
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Touch button: registers the key 'Touch:<action>' on the action and asks the touch part to draw a button (touch devices only)
|
|
9
|
+
* @param {Input} inp
|
|
10
|
+
* @param {string} action
|
|
11
|
+
* @param {string} labelKey string-table key of the button text
|
|
12
|
+
* @internal
|
|
13
|
+
*/
|
|
14
|
+
export function touchButton(inp, action, labelKey) {
|
|
15
|
+
if (!inp.touch || inp._touch.some(b => b.action === action)) return;
|
|
16
|
+
const code = 'Touch:' + action, a = inp.actions.get(action);
|
|
17
|
+
if (a && !a.keys.includes(code)) a.keys.push(code);
|
|
18
|
+
inp._touch.push({ action, labelKey });
|
|
19
|
+
touchRefresh(inp);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* engine.start(): from now on the touch part draws (UI parts are settled). Nothing is created when no stick and no button is wanted (desktop).
|
|
24
|
+
* @param {Input} inp
|
|
25
|
+
* @internal
|
|
26
|
+
*/
|
|
27
|
+
export function touchStart(inp) {
|
|
28
|
+
inp._touchOn = true;
|
|
29
|
+
inp.engine.events.on('i18n:change', () => touchRefresh(inp));
|
|
30
|
+
touchRefresh(inp);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** @param {Input} inp */
|
|
34
|
+
function touchRefresh(inp) {
|
|
35
|
+
if (!inp._touchOn) return;
|
|
36
|
+
const stick = inp.joystick === true || (inp.joystick === 'auto' && inp.touch);
|
|
37
|
+
if (!stick && !inp._touch.length) return;
|
|
38
|
+
const e = inp.engine, first = !inp._touchPart;
|
|
39
|
+
inp._touchPart ??= e.ui.get('touch');
|
|
40
|
+
/** @type {TouchView} */
|
|
41
|
+
const view = {
|
|
42
|
+
stick, buttons: inp._touch.map(b => ({ action: b.action, label: e.t(b.labelKey) })),
|
|
43
|
+
move: (x, y) => { inp.stick.x = x; inp.stick.y = y; },
|
|
44
|
+
press: action => inp._keyDown('Touch:' + action, 'touch'),
|
|
45
|
+
release: action => inp._keyUp('Touch:' + action),
|
|
46
|
+
};
|
|
47
|
+
if (first) inp._touchPart?.show(view); else inp._touchPart?.update(view);
|
|
48
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// Engine lifecycle (part of Engine, mixed into Engine.prototype): dispose() and counts() for leak hunting.
|
|
2
|
+
//
|
|
3
|
+
// Who cleans up what:
|
|
4
|
+
// - DOM listeners: attach to engine.signal (an AbortController); dispose aborts them all at once. Modules and games adding their own window / document listeners do the same:
|
|
5
|
+
// addEventListener('resize', fn, { signal: engine.signal })
|
|
6
|
+
// - UI elements: the engine and modules build UI under engine.uiRoot, removed as a whole on dispose; do not attach to document.body directly.
|
|
7
|
+
// - Events, onFixed / onFrame, clock timers, jobs, stream, ray registrations: core clears them all, modules need not.
|
|
8
|
+
// - Things core does not know about (Worker, physics world, Audio nodes, real-time timers): clean up in the module's dispose(e) hook, called in reverse install order.
|
|
9
|
+
// - GPU memory: every geometry, material and texture in the scene, the assets cache, the post composer, then renderer.dispose().
|
|
10
|
+
// Level changes do not come through here: things inside a level register with level.track(handle), and the level removes them itself on change.
|
|
11
|
+
|
|
12
|
+
import { coded } from './errorHints.js';
|
|
13
|
+
|
|
14
|
+
const STRINGS = { failed: '[engine] dispose hook of module {name} threw (the rest are still cleaned up)' };
|
|
15
|
+
|
|
16
|
+
/** Dispose the geometry, materials and material textures used by an object */
|
|
17
|
+
function disposeObject(o) {
|
|
18
|
+
o.geometry?.dispose();
|
|
19
|
+
for (const m of [].concat(o.material || [])) {
|
|
20
|
+
for (const k in m) if (m[k]?.isTexture) m[k].dispose();
|
|
21
|
+
m.dispose();
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const lifecycleMethods = {
|
|
26
|
+
/**
|
|
27
|
+
* Destroy the engine: stop the main loop, call each module's dispose(e) in reverse install order, then clean up core (listeners, timers, sound, UI, GPU memory).
|
|
28
|
+
* No callbacks fire afterwards and engine.disposed becomes true. Safe to call repeatedly.
|
|
29
|
+
*/
|
|
30
|
+
dispose() {
|
|
31
|
+
if (this.disposed) return;
|
|
32
|
+
this.disposed = true; this.ready = false; this.paused = true;
|
|
33
|
+
cancelAnimationFrame(this._raf);
|
|
34
|
+
for (const m of [...this.modules.values()].reverse()) {
|
|
35
|
+
this._modState.set(m.name, 'disposed');
|
|
36
|
+
if (!m.dispose) continue;
|
|
37
|
+
try { m.dispose(this); } catch (err) { console.error(coded('module-dispose', STRINGS.failed.replace('{name}', m.name)), err); }
|
|
38
|
+
}
|
|
39
|
+
this._abort.abort();
|
|
40
|
+
this.debug.dispose(); // before the scene is disposed: undoes every diagnostic override and view (puts swapped materials back)
|
|
41
|
+
for (const part of [this.saves, this.audio, this.clock, this.commits, this.jobs, this.threads, this.stream, this.batching, this.rays, this.events]) part.dispose();
|
|
42
|
+
this._fixed = []; this._frame = []; this._hooks = { fixed: [], frame: [], afterRender: [], skip: [] }; this._afterTick = null;
|
|
43
|
+
this.scene.traverse(disposeObject);
|
|
44
|
+
for (const t of [this.scene.background, this.scene.environment]) if (t?.isTexture) t.dispose();
|
|
45
|
+
this.assets.dispose();
|
|
46
|
+
this.post.dispose();
|
|
47
|
+
this.renderer.dispose();
|
|
48
|
+
this.ui._dispose();
|
|
49
|
+
this._materials.remove();
|
|
50
|
+
this._uiStyle.remove();
|
|
51
|
+
this.uiRoot.remove();
|
|
52
|
+
},
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Counts for leak hunting: after repeatedly entering and leaving levels or opening and closing windows, these should not keep growing.
|
|
56
|
+
* geometries / textures come from three.js renderer.info.memory (counted only once rendered).
|
|
57
|
+
* Each installed module with a counts(e) hook adds its own field under its name, e.g. world { records, views }, rigid (body count), particles { alive, emitters }, sky { timers }.
|
|
58
|
+
*/
|
|
59
|
+
counts() {
|
|
60
|
+
const mem = this.renderer.info.memory;
|
|
61
|
+
const c = {
|
|
62
|
+
listeners: this.events.size, fixed: this._fixed.length, frame: this._frame.length, timers: this.clock.size,
|
|
63
|
+
statics: this.rays.statics.size, streamEntries: this.stream.entries.size, jobs: this.jobs.pending, commits: this.commits.pending,
|
|
64
|
+
geometries: mem.geometries, textures: mem.textures,
|
|
65
|
+
};
|
|
66
|
+
for (const m of this.modules.values()) if (m.counts) c[m.name] = m.counts(this);
|
|
67
|
+
return c;
|
|
68
|
+
},
|
|
69
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// Dev-only check (called from loop.js after each render once the engine is ready): warn when three.js compiled new shader programs
|
|
2
|
+
// when the light layout also differs from the last observation (not proven to be the same frame: the layout is only reread when programs grow). Why: three.js builds one program per material for each light setup, so a light added,
|
|
3
|
+
// removed or hidden mid-play compiles again and freezes that frame (a dungeon game froze ~450 ms when a torch turned its light on).
|
|
4
|
+
// engine.start() already compiled everything for the startup lights; this names the cause when a game changes them afterwards.
|
|
5
|
+
// Cost: one array-length compare per frame; the scene walk that counts lights runs only in a frame whose program count went up (rare).
|
|
6
|
+
import { warnOnce } from './validate.js';
|
|
7
|
+
import { coded } from './errorHints.js';
|
|
8
|
+
|
|
9
|
+
const MANY = 8; // above this many real-time lights every material's fragment shader loops over all of them: mobile GPUs slow down first
|
|
10
|
+
|
|
11
|
+
const STRINGS = {
|
|
12
|
+
many: '{n} real-time lights are in the scene (more than {max}, not counting lightPool lights). Every lit material pays for every light in every pixel. ' +
|
|
13
|
+
'For torches, lamps and muzzle flashes use engine.use(lightPool({ point: 8 })) and engine.lightPool.add(torch, {...}): a fixed set of real lights lit for the nearest sources',
|
|
14
|
+
changed: 'Shader programs were compiled during play ({from} -> {to}) and, compared with the last observation, the light layout also changed ({was} -> {now}). ' +
|
|
15
|
+
'three.js compiles every material again for a new light setup, so adding, removing or hiding a light mid-game freezes a frame. ' +
|
|
16
|
+
'Use engine.use(lightPool({ point: 8 })) and engine.lightPool.add(torch, {...}) for many lights, or fade a fixed set with intensity ' +
|
|
17
|
+
'(recipes/09-style-pack.md "Lights and stalls")',
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/** Visible lights by the kinds three.js counts in its light setup (ambient and probes do not change programs), as one comparable string */
|
|
21
|
+
export function lightSetup(scene) {
|
|
22
|
+
let point = 0, spot = 0, dir = 0, hemi = 0, rect = 0;
|
|
23
|
+
scene.traverseVisible(o => {
|
|
24
|
+
if (!o.isLight) return;
|
|
25
|
+
if (o.isPointLight) point++; else if (o.isSpotLight) spot++; else if (o.isDirectionalLight) dir++;
|
|
26
|
+
else if (o.isHemisphereLight) hemi++; else if (o.isRectAreaLight) rect++;
|
|
27
|
+
});
|
|
28
|
+
return `point ${point}, spot ${spot}, directional ${dir}, hemisphere ${hemi}, rect ${rect}`;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Lights that are not part of a lightPool (those are fixed and already the recommended fix) */
|
|
32
|
+
function countLoose(scene) {
|
|
33
|
+
let c = 0;
|
|
34
|
+
scene.traverseVisible(o => { if (o.isLight && !o.isAmbientLight && !o.isLightProbe && !o.name.startsWith('lightPool_')) c++; });
|
|
35
|
+
return c;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** @param {any} e the engine (dev and ready only: the caller checks) */
|
|
39
|
+
export function watchLights(e) {
|
|
40
|
+
const n = e.renderer.info?.programs?.length;
|
|
41
|
+
if (n == null) return;
|
|
42
|
+
const first = !e._lightWatch;
|
|
43
|
+
const w = e._lightWatch ??= { n, lights: lightSetup(e.scene) };
|
|
44
|
+
// the scene walk runs on the first observation and when programs grow (a light was added), never on a quiet frame
|
|
45
|
+
if (!w.manyDone && (first || n > w.n)) {
|
|
46
|
+
const c = countLoose(e.scene);
|
|
47
|
+
if (c > MANY) { w.manyDone = true; warnOnce(coded('many-lights', STRINGS.many.replace('{n}', String(c)).replace('{max}', String(MANY)))); }
|
|
48
|
+
}
|
|
49
|
+
if (n <= w.n) { w.n = n; return; } // fewer programs (materials disposed) or none new: nothing to say
|
|
50
|
+
const lights = lightSetup(e.scene);
|
|
51
|
+
if (lights !== w.lights) {
|
|
52
|
+
// the layout is only reread when programs grow, so we say "since the last observation", never "in this frame"
|
|
53
|
+
warnOnce(coded('light-recompile', STRINGS.changed.replace('{from}', String(w.n)).replace('{to}', String(n)).replace('{was}', w.lights).replace('{now}', lights)));
|
|
54
|
+
}
|
|
55
|
+
w.n = n; w.lights = lights;
|
|
56
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
// look.tone, lights, clouds.
|
|
2
|
+
// look.tone = renderer tone mapping and exposure, look.lights = the engine's placeholder sun + hemisphere, look.cloudShadow = the cloud-shadow patch.
|
|
3
|
+
// Why here and not in sceneMethods: the 0.2 renames (recipe 52) now write the 'game' layer, and the style values
|
|
4
|
+
// are the 'style' layer, so describe().look / describe().render can say who set a value instead of guessing from start values.
|
|
5
|
+
import * as THREE from 'three';
|
|
6
|
+
import { defineLookPart } from './part.js';
|
|
7
|
+
|
|
8
|
+
/** style.toneMapping names -> three constants */
|
|
9
|
+
export const TONE = { aces: THREE.ACESFilmicToneMapping, agx: THREE.AgXToneMapping, neutral: THREE.NeutralToneMapping, none: THREE.NoToneMapping };
|
|
10
|
+
const toneName = v => Object.keys(TONE).find(k => TONE[k] === v) ?? String(v);
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Exposure over the day: [[time 0-1, exposure], ...] sorted by time, wrapping across midnight (after the last row it blends back to the first),
|
|
14
|
+
* or (sky) => number. Returns the per-frame function, null for a plain number (set once); throws on anything else
|
|
15
|
+
*/
|
|
16
|
+
export function exposureDriver(v) {
|
|
17
|
+
if (typeof v === 'number') return null;
|
|
18
|
+
if (typeof v === 'function') return v;
|
|
19
|
+
const ok = Array.isArray(v) && v.length > 0 && v.every((k, i) => Array.isArray(k) && typeof k[0] === 'number' && typeof k[1] === 'number' && k[0] >= 0 && k[0] <= 1 && (i === 0 || k[0] > v[i - 1][0]));
|
|
20
|
+
if (!ok) throw new Error(`exposure must be a number, [[time 0-1, exposure], ...] sorted by time (e.g. [[0, 1.6], [0.5, 1], [0.8, 1.3]]) or (sky) => number; got ${JSON.stringify(v)}`);
|
|
21
|
+
return sky => {
|
|
22
|
+
const t = sky.timeOfDay, n = v.length;
|
|
23
|
+
let i = -1; for (let k = 0; k < n; k++) if (v[k][0] <= t) i = k;
|
|
24
|
+
const a = v[i < 0 ? n - 1 : i], b = v[(i + 1) % n]; // before the first row or after the last: the segment across midnight
|
|
25
|
+
const span = (b[0] - a[0] + 1) % 1 || 1, f = ((t - a[0] + 1) % 1) / span;
|
|
26
|
+
return a[1] + (b[1] - a[1]) * f;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
const badExposure = v => { try { exposureDriver(v); return null; } catch (err) { return err.message; } };
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Register look.tone and look.lights. owned: false when the game passed its own renderer: then the style's tone values are not applied at start
|
|
33
|
+
* (the renderer is the game's), but a later look.tone.set still writes it.
|
|
34
|
+
* @param {any} e @param {{ owned: boolean }} o
|
|
35
|
+
*/
|
|
36
|
+
export function defineCoreLook(e, { owned }) {
|
|
37
|
+
const r = e.renderer;
|
|
38
|
+
defineLookPart(e, {
|
|
39
|
+
id: 'tone', group: 'atmosphere', module: 'core', object: () => e.renderer, applyAtStart: owned, docs: ['recipes/52-look.md'],
|
|
40
|
+
params: {
|
|
41
|
+
mapping: { type: 'string', values: Object.keys(TONE), default: 'none', neutral: true, cost: 'recompile', desc: 'tone mapping curve; changing it recompiles each material once' },
|
|
42
|
+
exposure: { type: 'any', default: 1, neutral: true, cost: 'uniform', check: badExposure, desc: 'a number, day keyframes [[time 0-1, exposure], ...] or (sky) => number (a time-of-day module evaluates it each frame)' },
|
|
43
|
+
},
|
|
44
|
+
style: () => (owned ? { mapping: e.style.toneMapping, exposure: e.style.exposure } : {}),
|
|
45
|
+
read: () => ({ mapping: toneName(r.toneMapping), exposure: e.exposureDriver ? undefined : r.toneMappingExposure }),
|
|
46
|
+
apply(v, changed) {
|
|
47
|
+
if (changed.has('mapping')) r.toneMapping = TONE[v.mapping]; // three recompiles each material on its next draw (tone mapping is part of its program)
|
|
48
|
+
if (changed.has('exposure')) {
|
|
49
|
+
// keyframes / a function become exposureDriver, which a time-of-day module (sky) evaluates each frame; core knows no time of day
|
|
50
|
+
e.exposureDriver = exposureDriver(v.exposure);
|
|
51
|
+
if (typeof v.exposure === 'number') r.toneMappingExposure = v.exposure;
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
noPatch: "custom tone curves (three's CustomToneMapping) are not offered yet; pick a curve with look.tone.set({ mapping: 'aces' })",
|
|
55
|
+
noReplace: 'to own tone mapping completely, pass your own renderer: createEngine({ renderer }) (recipes/50)',
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
const { sun, hemi } = e.lights;
|
|
59
|
+
const off = "look.lights.set({ sun: { intensity: 0 } }) (or hemi), or createEngine({ lights: false }) and light the world with your own three.js lights";
|
|
60
|
+
const why = 'placeholder light so a scene without a sky module (and the gray placeholders) is never black; an installed sky drives it from style.sky.keyframes instead';
|
|
61
|
+
defineLookPart(e, {
|
|
62
|
+
id: 'lights', group: 'atmosphere', module: 'core', object: () => e.lights, docs: ['recipes/52-look.md'],
|
|
63
|
+
params: {
|
|
64
|
+
'sun.intensity': { type: 'number', default: 2, min: 0, cost: 'uniform', why, off },
|
|
65
|
+
'sun.color': { type: 'any', default: '#ffffff', neutral: true, cost: 'uniform', desc: 'any THREE.Color input' },
|
|
66
|
+
'hemi.intensity': { type: 'number', default: 1.2, min: 0, cost: 'uniform', why, off },
|
|
67
|
+
'hemi.color': { type: 'any', default: '#ffffff', neutral: true, cost: 'uniform', desc: 'sky color of the hemisphere light' },
|
|
68
|
+
'hemi.ground': { type: 'any', default: '#555555', cost: 'uniform', why: 'darker ground color, so faces turned down read darker than faces turned up', off: "look.lights.set({ hemi: { ground: '#ffffff' } })" },
|
|
69
|
+
},
|
|
70
|
+
read: () => ({ 'sun.intensity': sun.intensity, 'hemi.intensity': hemi.intensity }),
|
|
71
|
+
apply(v, changed) {
|
|
72
|
+
// undefined = a style driver (sky) writes this key every frame: leave it to the driver
|
|
73
|
+
const set = (k, fn) => { if (changed.has(k) && v[k] !== undefined) fn(v[k]); };
|
|
74
|
+
set('sun.intensity', x => { sun.intensity = x; });
|
|
75
|
+
set('sun.color', x => sun.color.set(x));
|
|
76
|
+
set('hemi.intensity', x => { hemi.intensity = x; });
|
|
77
|
+
set('hemi.color', x => hemi.color.set(x));
|
|
78
|
+
set('hemi.ground', x => hemi.groundColor.set(x));
|
|
79
|
+
},
|
|
80
|
+
noPatch: 'lights have no shader of their own; how surfaces take light is look.surface (lighting / ramp)',
|
|
81
|
+
noReplace: "to light the world yourself, turn the engine lights off: createEngine({ lights: false }), or sky({ sun: 'manual' | false })",
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* look.cloudShadow: drifting cloud shadows on the ground and on every material from makeMaterial / applyEffects. The patch is on by default (clouds: true)
|
|
87
|
+
* so the style and the weather can darken it later without a recompile; how dark comes from style.clouds.shadow, 0 (nothing drawn) without one.
|
|
88
|
+
* Declared as a part so this default is visible in describe().look and the catalog instead of hiding in applyEffects.
|
|
89
|
+
* @param {any} e
|
|
90
|
+
*/
|
|
91
|
+
export function defineCloudShadowLook(e) {
|
|
92
|
+
const u = e.uniforms, c = e.style.clouds ?? {};
|
|
93
|
+
defineLookPart(e, {
|
|
94
|
+
id: 'cloudShadow', group: 'surface', module: 'core', object: () => u, docs: ['recipes/52-look.md'],
|
|
95
|
+
params: {
|
|
96
|
+
shadow: { type: 'number', default: 0, min: 0, max: 1, cost: 'uniform', desc: 'darkest cloud shadow (uCloudShadow)',
|
|
97
|
+
why: 'every engine material carries the cloud-shadow patch (applyEffects clouds: true) so a style or the weather can darken it with no recompile; at 0 it draws nothing',
|
|
98
|
+
off: 'look.cloudShadow.set({ shadow: 0 }); to leave the patch out of one material: applyEffects(mat, { clouds: false })' },
|
|
99
|
+
scale: { type: 'number', default: 0.006, min: 0, neutral: true, cost: 'uniform', desc: 'cloud size (smaller = bigger clouds)' },
|
|
100
|
+
speed: { type: 'array', default: [0.012, 0.006], neutral: true, cost: 'uniform', desc: 'drift [x, z] per second' },
|
|
101
|
+
},
|
|
102
|
+
style: () => ({ shadow: c.shadow, scale: c.scale, speed: c.speed }),
|
|
103
|
+
read: () => ({ shadow: u.uCloudShadow.value, scale: u.uCloudScale.value }),
|
|
104
|
+
apply(v, changed) {
|
|
105
|
+
if (changed.has('shadow')) u.uCloudShadow.value = v.shadow;
|
|
106
|
+
if (changed.has('scale')) u.uCloudScale.value = v.scale;
|
|
107
|
+
if (changed.has('speed')) u.uCloudSpeed.value.set(v.speed[0], v.speed[1]);
|
|
108
|
+
},
|
|
109
|
+
noPatch: 'the cloud-shadow GLSL is shared with the sky clouds; change the look with look.cloudShadow.set({ shadow, scale, speed })',
|
|
110
|
+
noReplace: 'to drop cloud shadows from a material, build it with applyEffects(mat, { clouds: false })',
|
|
111
|
+
});
|
|
112
|
+
}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
// The layer arithmetic behind a LookPart (part.js): where a key's value comes from, and the recompute that hands changed keys to apply.
|
|
2
|
+
// Why a file of its own: part.js holds the verbs a game and a part author call; this file is the bookkeeping they share, kept apart so
|
|
3
|
+
// both stay under the file-size cap and the verbs read without the loops in between.
|
|
4
|
+
import { parseSpec } from '../params.js';
|
|
5
|
+
import { DEV } from '../validate.js';
|
|
6
|
+
import { codedError, renamed } from '../errorHints.js';
|
|
7
|
+
|
|
8
|
+
/** Look-only fields of a param spec; stripped before the shared params schema (params.js) parses the rest */
|
|
9
|
+
const LOOK_FIELDS = ['why', 'off', 'cost', 'neutral', 'check'];
|
|
10
|
+
export const REPLACE = '@replace';
|
|
11
|
+
export const HOOK = 'hook:';
|
|
12
|
+
|
|
13
|
+
const FRAME = /\(?((?:[a-z]+:\/\/[^/\s]+)?[^\s()]+?\.[cm]?[jt]sx?)(?:\?[^:\s)]*)?:(\d+):\d+\)?\s*$/i;
|
|
14
|
+
const ENGINE_FRAME = /(?:engine|threedog)\/(?:core|modules|render|ui)\//; // engine code (engine.look.tone.set and the like, called from inside the engine) is skipped: `at` names the game's line
|
|
15
|
+
|
|
16
|
+
/** 'main.js:50' of the first caller outside the engine (dev only: release builds keep no stacks) */
|
|
17
|
+
export function callerAt() {
|
|
18
|
+
if (!DEV) return null;
|
|
19
|
+
const lim = Error.stackTraceLimit; Error.stackTraceLimit = 14;
|
|
20
|
+
const stack = String(new Error().stack ?? ''); Error.stackTraceLimit = lim;
|
|
21
|
+
for (const l of stack.split('\n').slice(1)) {
|
|
22
|
+
const f = FRAME.exec(l);
|
|
23
|
+
if (f && !ENGINE_FRAME.test(f[1].replace(/\\/g, '/'))) return `${f[1].replace(/^[a-z]+:\/\/[^/]+\//i, '').replace(/^\/+/, '')}:${f[2]}`;
|
|
24
|
+
}
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Parse param specs into part._params / part._meta (constructor and extend share it, so a key added later is checked the same way) */
|
|
29
|
+
export function addParams(part, params, { skipKnown = false } = {}) {
|
|
30
|
+
for (const [k, raw] of Object.entries(params ?? {})) {
|
|
31
|
+
if (skipKnown && k in part._params) continue;
|
|
32
|
+
const meta = {}, rest = { ...raw };
|
|
33
|
+
for (const f of LOOK_FIELDS) if (f in rest) { meta[f] = rest[f]; delete rest[f]; }
|
|
34
|
+
if (!('default' in rest)) throw codedError('look-param', `defineLookPart('${part._spec.id}'): param ${k} has no default. Every look param declares the value the engine uses when nobody sets it (and why / off when that value changes the picture)`);
|
|
35
|
+
part._params[k] = parseSpec(part.id, k, rest, msg => codedError('look-param', msg));
|
|
36
|
+
part._meta[k] = meta;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Highest game / debug record holding key: debug beats game, later beats earlier within a layer */
|
|
41
|
+
export function topOf(part, key) {
|
|
42
|
+
for (const layer of ['debug', 'game']) {
|
|
43
|
+
let best = null;
|
|
44
|
+
for (const [owner, r] of part._owners[layer]) if (r.values.has(key) && (!best || r.seq > best.seq)) best = { owner, layer, at: r.at, seq: r.seq, value: r.values.get(key) };
|
|
45
|
+
if (best) return best;
|
|
46
|
+
}
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Every key that has a value anywhere: params, plus hooks / replace that someone set */
|
|
51
|
+
export function allKeys(part) {
|
|
52
|
+
const ks = new Set(Object.keys(part._params));
|
|
53
|
+
for (const k of part._style.keys()) ks.add(k);
|
|
54
|
+
for (const l of ['game', 'debug']) for (const r of part._owners[l].values()) for (const k of r.values.keys()) ks.add(k);
|
|
55
|
+
return ks;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Where a key's value comes from: { value, owner, layer, at } plus the layers it covers (under) */
|
|
59
|
+
export function sourceOf(part, key) {
|
|
60
|
+
const under = [];
|
|
61
|
+
for (const layer of ['debug', 'game']) for (const [owner, r] of part._owners[layer]) if (r.values.has(key)) under.push({ owner, layer, at: r.at, seq: r.seq, value: r.values.get(key) });
|
|
62
|
+
under.sort((a, b) => (a.layer === b.layer ? b.seq - a.seq : a.layer === 'debug' ? -1 : 1));
|
|
63
|
+
if (part._driven.has(key)) under.push({ owner: part._driven.get(key), layer: 'style', at: null, driven: true, value: undefined });
|
|
64
|
+
if (part._style.has(key)) under.push({ owner: 'style', layer: 'style', at: null, value: part._style.get(key) });
|
|
65
|
+
if (key in part._params) under.push({ owner: 'engine', layer: 'engine', at: null, value: part._params[key].default });
|
|
66
|
+
const top = under.shift();
|
|
67
|
+
return top ? { ...top, under } : null;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Recompute every key; hand the changed ones to the part's apply / applyHook / applyReplace.
|
|
72
|
+
* The key set is taken once per call, not once per key, so a set costs O(keys) (review #14).
|
|
73
|
+
*/
|
|
74
|
+
export function refresh(part, force = false) {
|
|
75
|
+
const changed = [], keys = allKeys(part);
|
|
76
|
+
for (const k of keys) {
|
|
77
|
+
const v = sourceOf(part, k)?.value;
|
|
78
|
+
if (force || !part._resolved.has(k) || part._resolved.get(k) !== v) changed.push(k);
|
|
79
|
+
v === undefined ? part._resolved.delete(k) : part._resolved.set(k, v);
|
|
80
|
+
}
|
|
81
|
+
for (const k of [...part._resolved.keys()]) if (!keys.has(k)) { part._resolved.delete(k); changed.push(k); }
|
|
82
|
+
if (!part._started) return;
|
|
83
|
+
const s = part._spec, params = changed.filter(k => k in part._params);
|
|
84
|
+
if (changed.includes(REPLACE)) s.applyReplace?.(part._resolved.get(REPLACE) ?? null);
|
|
85
|
+
for (const k of changed) if (k.startsWith(HOOK)) s.applyHook?.(k.slice(HOOK.length), part._resolved.get(k) ?? null);
|
|
86
|
+
if (params.length) s.apply?.(part.values(), new Set(params));
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Recompute after a record change; on a throw put the records back (undo), re-apply the old values to the three.js objects and rethrow.
|
|
91
|
+
* Why: apply used to throw after the layer was already written, leaving a record that described a picture nobody saw (review H1).
|
|
92
|
+
*/
|
|
93
|
+
export function commit(part, undo) {
|
|
94
|
+
const before = new Map(part._resolved);
|
|
95
|
+
try { refresh(part); } catch (err) {
|
|
96
|
+
undo(); part._resolved = before;
|
|
97
|
+
try { refresh(part, true); } catch { /* reported: the rethrow below is the error that broke it; this one is its echo on the old values */ }
|
|
98
|
+
throw err;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** Remove every key starting with prefix, with the values any layer holds for them (LookPart.retract) */
|
|
103
|
+
export function retractKeys(part, prefix) {
|
|
104
|
+
const mine = k => k.startsWith(prefix);
|
|
105
|
+
for (const k of Object.keys(part._params)) if (mine(k)) { delete part._params[k]; delete part._meta[k]; }
|
|
106
|
+
for (const k of [...part._style.keys()]) if (mine(k)) part._style.delete(k);
|
|
107
|
+
for (const l of ['game', 'debug']) for (const [o, r] of part._owners[l]) {
|
|
108
|
+
for (const k of [...r.values.keys()]) if (mine(k)) r.values.delete(k);
|
|
109
|
+
if (!r.values.size) part._owners[l].delete(o);
|
|
110
|
+
}
|
|
111
|
+
quietRefresh(part);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** Old part names: reading one throws renamed-api and names the new part (recipes/52-look.md "Renamed in 0.2"); hidden, so describe / catalog never list it */
|
|
115
|
+
const ALIASES = { clouds: 'cloudShadow' };
|
|
116
|
+
/** engine.look with the old names as hidden throwing getters */
|
|
117
|
+
export function aliased(look) {
|
|
118
|
+
for (const [old] of Object.entries(ALIASES)) if (!(old in look)) Object.defineProperty(look, old, { get: () => renamed('lookClouds'), enumerable: false, configurable: true });
|
|
119
|
+
return look;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** A module went away (dispose, or engine.use rolled it back): drop the parts it registered and release the keys it drives (review M9) */
|
|
123
|
+
export function disposeLooksOf(e, name) {
|
|
124
|
+
if (!name) return;
|
|
125
|
+
for (const p of Object.values(e.look ?? {})) {
|
|
126
|
+
if (p._spec.module === name) { p.dispose(); continue; }
|
|
127
|
+
const mine = [...p._driven].filter(([, by]) => by === name).map(([k]) => k);
|
|
128
|
+
if (mine.length) p.drive(mine, null);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** Recompute without calling apply: a key added later describes the object its owner just made, its default must not be pushed onto it */
|
|
133
|
+
export function quietRefresh(part) {
|
|
134
|
+
const was = part._started; part._started = false;
|
|
135
|
+
try { refresh(part); } finally { part._started = was; }
|
|
136
|
+
}
|