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/Input.js
ADDED
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
// Input: read by "action", not by "key". Games and modules ask "did the player press interact", not "did they press E".
|
|
2
|
+
// Why: keys can be rebound in settings, and on-screen key hints follow automatically.
|
|
3
|
+
//
|
|
4
|
+
// engine.input.define('jump', ['Space'], 'Jump'); // a module/game registers its own action. Redefining: the later one overrides keys and label (warns once in
|
|
5
|
+
// dev); keys the player rebound are kept
|
|
6
|
+
// engine.input.define('inventory', ['KeyI'], 'inv.open', { pad: 'PadY' }) // the module that registers an action supplies its default gamepad key (or write
|
|
7
|
+
// 'PadY' straight into the key array)
|
|
8
|
+
// engine.input.down('run') held
|
|
9
|
+
// engine.input.pressed('jump') just pressed; engine.input.released('jump') just released
|
|
10
|
+
// Gameplay (onFixed, module fixed) reads a snapshot taken at the start of each fixed step: reads within one step agree, and "just pressed" counts exactly once,
|
|
11
|
+
// never lost, whatever the frame rate.
|
|
12
|
+
// UI keys and camera (onFrame, module frame) read this frame's latest state. Gameplay keys (jump, attack, fire, interact) are always read in fixed
|
|
13
|
+
// Contexts: engine.input.push('vehicle') groups/shadows actions (inputContext.js); menus, dialogue and cutscenes push an opaque one. Window blur / tab hide
|
|
14
|
+
// (page:blur from core/page.js) releases every held key
|
|
15
|
+
// engine.input.label('interact') -> "E" (for UI hints; 'interact' exists only once the game bound it)
|
|
16
|
+
// engine.input.rebind('interact', ['KeyF']) rebind a key (this session only; with the settings module installed it saves to the browser and restores next time)
|
|
17
|
+
// engine.input.axis -> { x, y } movement direction (moveLeft/Right/Forward/Back + mobile stick)
|
|
18
|
+
//
|
|
19
|
+
// Mouse buttons are keys too: 'Mouse0' left / 'Mouse1' middle / 'Mouse2' right (real mouse only; touch taps do not count). Bind them in actions and read in
|
|
20
|
+
// fixed steps, independent of frame rate:
|
|
21
|
+
// engine.input.define('attack', ['KeyJ', 'Mouse0'], 'Attack'); engine.onFixed(() => { if (engine.input.pressed('attack')) … });
|
|
22
|
+
// input.pointer = { x, y, ndcX, ndcY, down, clicked } (x / y pixels and ndc -1..1 relative to the canvas box, not the window): for UI and ground picking
|
|
23
|
+
// (click-to-move via screenToGround); clicked is true only on this frame and a drag does not count,
|
|
24
|
+
// gameplay (fire, attack) must not read it; bind a Mouse0 action instead
|
|
25
|
+
|
|
26
|
+
/** @import { Pointer, Autopilot } from '../types/core' */
|
|
27
|
+
import { coded } from './errorHints.js';
|
|
28
|
+
import { warnMissing, warnOnce } from './validate.js';
|
|
29
|
+
import { touchButton } from './inputTouch.js';
|
|
30
|
+
import { bindPointer } from './inputPointer.js';
|
|
31
|
+
import { pollPad, keyLabel } from './inputPad.js';
|
|
32
|
+
import { DEFAULT_ACTIONS, BOUND_LABELS, PAD_DEFAULTS, fmtRedefine } from './inputDefaults.js';
|
|
33
|
+
import { initContexts, pushContext, readableMap, applyContexts } from './inputContext.js';
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
/** Input: read by "action", not by "key". Key names are the browser's KeyboardEvent.code, e.g. 'KeyE', 'Space', 'ShiftLeft'; gamepad keys are 'PadA' etc. */
|
|
37
|
+
export class Input {
|
|
38
|
+
/** @internal */
|
|
39
|
+
constructor(engine, canvas, { joystick = 'auto', bindings = {}, padBindings = {}, padDeadzone = 0.18, padLookSpeed = 9 } = {}) {
|
|
40
|
+
/** @internal */ this.engine = engine;
|
|
41
|
+
/** @internal */ this.canvas = canvas;
|
|
42
|
+
/** @internal */ this.keys = new Set();
|
|
43
|
+
/** @internal */ this.justPressed = new Set(); // pressed / released this frame (read in frame, cleared by endFrame)
|
|
44
|
+
/** @internal */ this.justReleased = new Set();
|
|
45
|
+
/** @internal */ this._accP = new Set(); // pressed / released since the last snapshot (accumulated until the start of the next fixed step)
|
|
46
|
+
/** @internal */ this._accR = new Set();
|
|
47
|
+
/** @internal */ this._fx = { keys: new Set(), pressed: new Set(), released: new Set(), x: 0, y: 0 }; // this fixed step's snapshot
|
|
48
|
+
/** @internal */ this._live = { keys: this.keys, pressed: this.justPressed, released: this.justReleased };
|
|
49
|
+
/** @internal */ this._inFixed = false;
|
|
50
|
+
/** This frame's look-drag amount (pixels) and wheel notches */
|
|
51
|
+
this.look = { dx: 0, dy: 0, zoom: 0 };
|
|
52
|
+
/** Mouse/touch pointer @type {Pointer} */
|
|
53
|
+
this.pointer = { x: 0, y: 0, ndcX: 0, ndcY: 0, down: false, clicked: false, button: 0 };
|
|
54
|
+
/** Set by a camera that locks the mouse on click: true while the next mouse press would only lock it, so that press is not delivered as Mouse0 / a click @internal */
|
|
55
|
+
this.swallowLockClick = /** @type {null | (() => boolean)} */ (null);
|
|
56
|
+
/** On-screen stick (touch) */
|
|
57
|
+
this.stick = { x: 0, y: 0 };
|
|
58
|
+
/** Auto movement (stress tests, test scripts) @type {Autopilot | null} */
|
|
59
|
+
this.autopilot = null;
|
|
60
|
+
/** action name -> { keys = key list, labelKey = string-table key } @type {Map<string, { keys: string[], labelKey: string }>} */
|
|
61
|
+
this.actions = new Map();
|
|
62
|
+
initContexts(this);
|
|
63
|
+
/** @internal */ this.padDefaults = { ...PAD_DEFAULTS, ...padBindings };
|
|
64
|
+
/** @internal */ this.padDeadzone = padDeadzone;
|
|
65
|
+
/** @internal */ this.padLookSpeed = padLookSpeed;
|
|
66
|
+
/** @internal */ this.padStick = { x: 0, y: 0 };
|
|
67
|
+
/** Most recently used device: UI key hints follow it @type {'keyboard' | 'pad' | 'touch'} */
|
|
68
|
+
this.lastDevice = 'keyboard';
|
|
69
|
+
/** Is this a touch device? */
|
|
70
|
+
this.touch = matchMedia('(pointer: coarse)').matches;
|
|
71
|
+
/** @internal touch buttons the game asked for [{ action, labelKey }]; drawn by the UI part 'touch' (inputTouch.js) */ this._touch = [];
|
|
72
|
+
for (const [a, [keys, label]] of Object.entries(DEFAULT_ACTIONS)) this.actions.set(a, { keys: this._withPad(a, bindings[a] || keys), labelKey: label });
|
|
73
|
+
// bindings may also name actions outside the neutral table (createEngine({ bindings: { interact: ['KeyF'] } })): they exist from the start, and a module's
|
|
74
|
+
// later define() keeps the game's keys (the game chose them; the module's keys are only its fallback)
|
|
75
|
+
/** @internal */ this._bound = bindings;
|
|
76
|
+
for (const [a, keys] of Object.entries(bindings)) if (!DEFAULT_ACTIONS[a]) this.actions.set(a, { keys: this._withPad(a, [].concat(keys)), labelKey: BOUND_LABELS[a] || a });
|
|
77
|
+
|
|
78
|
+
const { signal } = engine; // engine.dispose() cancels all listeners at once
|
|
79
|
+
addEventListener('keydown', e => {
|
|
80
|
+
if (/INPUT|TEXTAREA|SELECT/.test(e.target.tagName)) return;
|
|
81
|
+
this._keyDown(e.code, 'keyboard');
|
|
82
|
+
if (e.code === 'Space' || e.code === 'Tab' || e.code.startsWith('Arrow')) e.preventDefault();
|
|
83
|
+
}, { signal });
|
|
84
|
+
addEventListener('keyup', e => this._keyUp(e.code), { signal });
|
|
85
|
+
// Losing focus swallows the keyup events, so release everything when the page goes away (window blur or tab hidden; core/page.js owns those listeners)
|
|
86
|
+
engine.events.on('page:blur', () => { for (const k of [...this.keys]) this._keyUp(k); });
|
|
87
|
+
|
|
88
|
+
bindPointer(this, canvas, signal);
|
|
89
|
+
|
|
90
|
+
/** @internal */ this.joystick = joystick;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// ---------- actions ----------
|
|
94
|
+
/**
|
|
95
|
+
* Register an action. keys is a key name or array (gamepad keys such as 'PadY' can go in directly); labelKey is the display name (a string-table key or
|
|
96
|
+
* text).
|
|
97
|
+
* opts.pad: the default gamepad key for this action (gameplay-specific actions get it from the registering module; createEngine({ padBindings }) takes
|
|
98
|
+
* precedence).
|
|
99
|
+
* If the action exists, the later definition overrides (warns once in dev when the keys differ); keys the player rebound in settings are kept
|
|
100
|
+
* @param {string} action
|
|
101
|
+
* @param {string | string[]} keys
|
|
102
|
+
* @param {string} [labelKey]
|
|
103
|
+
* opts.context: the input context the action belongs to (default 'gameplay'); it is readable only while that context is on the stack and not shadowed, see
|
|
104
|
+
* push().
|
|
105
|
+
* @param {{ pad?: string | string[], context?: string }} [opts]
|
|
106
|
+
* @returns {this}
|
|
107
|
+
* @example engine.input.define('openMap', 'KeyM', 'input.openMap', { pad: 'PadY' });
|
|
108
|
+
* @example engine.input.define('brake', 'KeyB', 'Brake', { context: 'vehicle' }); // only readable while input.push('vehicle') is on the stack
|
|
109
|
+
* @example engine.input.define('attack', ['KeyJ', 'Mouse0'], 'Attack'); // mouse buttons can be bound too: Mouse0 left / Mouse1 middle / Mouse2 right
|
|
110
|
+
*/
|
|
111
|
+
define(action, keys, labelKey, opts = {}) {
|
|
112
|
+
const { pad, context } = opts;
|
|
113
|
+
this._readable = null;
|
|
114
|
+
keys = [].concat(this._bound[action] ?? keys); // createEngine({ bindings }) wins over the keys a module passes
|
|
115
|
+
// a createEngine({ padBindings }) entry takes precedence
|
|
116
|
+
if (pad && !this.padDefaults[action]) keys = [...keys, ...[].concat(pad).filter(p => !keys.includes(p))];
|
|
117
|
+
const cur = this.actions.get(action), want = this._withPad(action, keys);
|
|
118
|
+
if (!cur) { this.actions.set(action, { keys: want, labelKey: labelKey || action, custom: false, defined: true, context }); return this; }
|
|
119
|
+
if (labelKey) cur.labelKey = labelKey;
|
|
120
|
+
if (context) cur.context = context;
|
|
121
|
+
if (cur.custom) return this;
|
|
122
|
+
const same = want.length === cur.keys.filter(k => !k.startsWith('Touch:')).length && want.every(k => cur.keys.includes(k));
|
|
123
|
+
if (!same) {
|
|
124
|
+
if (cur.defined) warnOnce(coded('input-binding', fmtRedefine(action, cur.keys, want)));
|
|
125
|
+
cur.keys = [...want, ...cur.keys.filter(k => k.startsWith('Touch:'))]; // keep the touch button keys
|
|
126
|
+
}
|
|
127
|
+
cur.defined = true;
|
|
128
|
+
return this;
|
|
129
|
+
}
|
|
130
|
+
/** @internal */
|
|
131
|
+
_withPad(action, keys) { const p = this.padDefaults[action]; return p && !keys.includes(p) ? [...keys, p] : keys; }
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Touch button (appears only on touch devices); pressing it triggers the action. labelKey is the string-table key of the button text (updates when the
|
|
135
|
+
* language changes) @param {string} action @param {string} labelKey
|
|
136
|
+
*/
|
|
137
|
+
touchButton(action, labelKey) { touchButton(this, action, labelKey); }
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Press (down true) or release an action from code, through the same path as a real key: tests, AI drivers, replays. Presses the action's first bound key
|
|
141
|
+
* @example engine.input.simulate('jump'); engine.step(1 / 60); engine.input.simulate('jump', false)
|
|
142
|
+
*/
|
|
143
|
+
simulate(action, down = true) { this._known(action); const k = this.keysOf(action)[0]; if (k) { if (down) this._keyDown(k, this.lastDevice); else this._keyUp(k); } }
|
|
144
|
+
_keyDown(code, device) {
|
|
145
|
+
if (this.keys.has(code) || this._muted.has(code)) return;
|
|
146
|
+
this.keys.add(code); this.justPressed.add(code); this._accP.add(code); this.lastDevice = device;
|
|
147
|
+
}
|
|
148
|
+
/** @internal */
|
|
149
|
+
_keyUp(code) { this._muted.delete(code); if (this.keys.delete(code)) { this.justReleased.add(code); this._accR.add(code); } }
|
|
150
|
+
/** @internal Called at the start of each frame: read the gamepad (runs every frame, allocates nothing) */
|
|
151
|
+
poll(dt) { pollPad(this, dt); }
|
|
152
|
+
/** Rebind a key @param {string} action @param {string | string[]} keys */
|
|
153
|
+
rebind(action, keys) {
|
|
154
|
+
const a = this.actions.get(action); if (!a) return;
|
|
155
|
+
a.keys = [].concat(keys); a.custom = true; this._readable = null;
|
|
156
|
+
this.engine.events.emit('input:rebind', { action, keys: a.keys });
|
|
157
|
+
}
|
|
158
|
+
/** All keys bound to an action @param {string} action @returns {string[]} */
|
|
159
|
+
keysOf(action) { return this.actions.get(action)?.keys || []; }
|
|
160
|
+
// Reading an unregistered action: most likely a misspelled name
|
|
161
|
+
/** @internal */
|
|
162
|
+
_known(action) { if (!this.actions.has(action)) warnMissing('action', action, [...this.actions.keys()]); }
|
|
163
|
+
/** Key name shown in the UI, e.g. "E" @param {string} action @returns {string} */
|
|
164
|
+
label(action) { return keyLabel(this, action); }
|
|
165
|
+
/** Which copy to read: the snapshot inside fixed steps, this frame's latest state elsewhere @internal */
|
|
166
|
+
_has(action, set) { this._known(action); if (!readableMap(this).get(action)) return false; const S = (this._inFixed ? this._fx : this._live)[set]; return this.keysOf(action).some(k => S.has(k)); }
|
|
167
|
+
/** Held (a snapshot of this step in fixed, the latest state in frame) @param {string} action @returns {boolean} */
|
|
168
|
+
down(action) { return this._has(action, 'keys'); }
|
|
169
|
+
/**
|
|
170
|
+
* Just pressed. Read in onFixed / module fixed: pressed since the previous fixed step, true only for this step (counted once however the frame rate varies,
|
|
171
|
+
* never lost);
|
|
172
|
+
* read in onFrame / module frame: pressed this frame (UI keys only). Read gameplay keys in fixed
|
|
173
|
+
* @param {string} action @returns {boolean}
|
|
174
|
+
* @example engine.onFixed(() => { if (engine.input.pressed('jump')) player.jump(); });
|
|
175
|
+
*/
|
|
176
|
+
pressed(action) { return this._has(action, 'pressed'); }
|
|
177
|
+
/**
|
|
178
|
+
* Just released (which copy is read is the same as pressed; for things like release-to-fire after charging) @param {string} action @returns {boolean}
|
|
179
|
+
* @example if (engine.input.released('fire')) shoot(charge);
|
|
180
|
+
*/
|
|
181
|
+
released(action) { return this._has(action, 'released'); }
|
|
182
|
+
/**
|
|
183
|
+
* Just pressed, ignoring input contexts (for menus and dialogue themselves, which run while a context blocks the game) @param {string} action @returns
|
|
184
|
+
* {boolean}
|
|
185
|
+
*/
|
|
186
|
+
pressedRaw(action) { this._known(action); const S = (this._inFixed ? this._fx : this._live).pressed; return this.keysOf(action).some(k => S.has(k)); }
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Push an input context (an action group, like a Unity Action Map). The top context shadows lower actions bound to the same key.
|
|
190
|
+
* Opaque by default (nothing below is readable: menus, dialogue, cutscenes); { pass: true } lets unrelated lower actions keep working (vehicle, build mode).
|
|
191
|
+
* Applies at the start of the next fixed step; actions it blocks lose their held state (no stuck keys after a menu closes). Join a context with define(..., {
|
|
192
|
+
* context }); menu keys: pressedRaw.
|
|
193
|
+
* @param {string} name e.g. 'vehicle', 'menu', 'build' (the base context is 'gameplay')
|
|
194
|
+
* @param {{ pass?: boolean }} [opts]
|
|
195
|
+
* @returns {{ name: string, remove(): void }} remove() pops it (safe to call twice)
|
|
196
|
+
* @example const h = engine.input.push('vehicle', { pass: true }); // vehicle-context actions (brake) work, and shadow gameplay actions on the same key
|
|
197
|
+
* h.remove();
|
|
198
|
+
*/
|
|
199
|
+
push(name, opts) { return pushContext(this, name, opts); }
|
|
200
|
+
/** Names of the active contexts, bottom to top (pending switches apply at the next fixed step) @returns {string[]} */
|
|
201
|
+
get contexts() { return this._stack.map(c => c.name); }
|
|
202
|
+
/**
|
|
203
|
+
* False while an opaque context (menu, dialogue, cutscene...) covers gameplay: no game action can be read, and cameras ignore look/zoom @returns {boolean}
|
|
204
|
+
*/
|
|
205
|
+
get enabled() { return this._stack.every(c => c.pass); }
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Movement direction: x positive right, y positive forward, length <= 1 (a snapshot of this step in fixed, the latest state in frame) @returns {{ x: number,
|
|
209
|
+
* y: number }}
|
|
210
|
+
*/
|
|
211
|
+
get axis() {
|
|
212
|
+
if (!this.enabled) return { x: 0, y: 0 };
|
|
213
|
+
if (this._inFixed) return { x: this._fx.x, y: this._fx.y };
|
|
214
|
+
return this._axisInto({ x: 0, y: 0 });
|
|
215
|
+
}
|
|
216
|
+
/** @internal Write the live movement axis into out (beginFixed reuses its snapshot object: no allocation per step) */
|
|
217
|
+
_axisInto(out) {
|
|
218
|
+
out.x = out.y = 0;
|
|
219
|
+
if (!this.enabled) return out;
|
|
220
|
+
let x = this.stick.x + this.padStick.x, y = this.stick.y + this.padStick.y;
|
|
221
|
+
if (this.down('moveForward')) y += 1;
|
|
222
|
+
if (this.down('moveBack')) y -= 1;
|
|
223
|
+
if (this.down('moveLeft')) x -= 1;
|
|
224
|
+
if (this.down('moveRight')) x += 1;
|
|
225
|
+
const l = Math.hypot(x, y); if (l > 1) { x /= l; y /= l; }
|
|
226
|
+
out.x = x; out.y = y;
|
|
227
|
+
return out;
|
|
228
|
+
}
|
|
229
|
+
/** Take the snapshot at the start of a fixed step (also while frozen, so keys pressed during a freeze do not take effect only after unfreezing) @internal */
|
|
230
|
+
beginFixed() {
|
|
231
|
+
applyContexts(this);
|
|
232
|
+
const f = this._fx;
|
|
233
|
+
f.keys.clear(); for (const k of this.keys) f.keys.add(k);
|
|
234
|
+
let t = f.pressed; f.pressed = this._accP; this._accP = t; t.clear(); // swap the two copies, no allocation
|
|
235
|
+
t = f.released; f.released = this._accR; this._accR = t; t.clear();
|
|
236
|
+
this._axisInto(f);
|
|
237
|
+
this._inFixed = true;
|
|
238
|
+
}
|
|
239
|
+
/** @internal */
|
|
240
|
+
endFixed() { this._inFixed = false; }
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
/** @internal */
|
|
244
|
+
endFrame() { this.justPressed.clear(); this.justReleased.clear(); this.look.dx = this.look.dy = this.look.zoom = 0; this.pointer.clicked = false; }
|
|
245
|
+
}
|
package/core/Inspect.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// engine.inspect / engine.explain: questions an AI asks while debugging, answered from the ops registry and describe().
|
|
2
|
+
// engine.inspect() what is around the player and what the player can do now (each op offer checked with can)
|
|
3
|
+
// engine.inspect('npc_3') the same for another actor (world record id): "why did this enemy not attack?"
|
|
4
|
+
// engine.inspect([x, z]) things around a spot, ops as the player
|
|
5
|
+
// engine.explain({ op: 'shop.buy', args }) why an op can / cannot run now (text: reason + fix first; detail: its last attempt and the events around it)
|
|
6
|
+
// engine.explain({ quest: 'first-light' }) any other key is answered by the module whose definition has explain: { quest(e, id) {...} }
|
|
7
|
+
// engine.pick(x, y).thing point -> thing: the world record a ray hit belongs to, else the engine.add object (thingOf; engine.thing is the same lookup)
|
|
8
|
+
// Built on ops because a failed op already carries its reason; explain turns that into a sentence instead of making the AI read can().
|
|
9
|
+
import { closest } from './validate.js';
|
|
10
|
+
import { codedError } from './errorHints.js';
|
|
11
|
+
import { findThing, hintThing } from './thingOps.js';
|
|
12
|
+
import { atomicNote } from './opsAtomic.js';
|
|
13
|
+
|
|
14
|
+
const OPS_MAX = 8;
|
|
15
|
+
|
|
16
|
+
/** Where an actor stands: the player, or a world record */
|
|
17
|
+
function placeOf(e, actor) {
|
|
18
|
+
if (actor === 'player') return e.player?.position ?? e.focus;
|
|
19
|
+
return e._things.source(actor)?.get(actor).position ?? e._things.live(actor)?.getWorldPosition(new e.THREE.Vector3()) ?? null; // a record, else an engine.add object
|
|
20
|
+
}
|
|
21
|
+
const note = (e, op, reason) => e.ops.defs.get(op)?.reasons?.[reason];
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @param {any} e
|
|
25
|
+
* @param {string | { x: number, z: number } | number[]} [at] actor id (world record) or a spot; default the player
|
|
26
|
+
* @param {{ radius?: number }} [opts]
|
|
27
|
+
*/
|
|
28
|
+
export function inspect(e, at, { radius = 10 } = {}) {
|
|
29
|
+
const actor = typeof at === 'string' ? at : 'player';
|
|
30
|
+
const p = typeof at === 'string' ? placeOf(e, at) : Array.isArray(at) ? { x: at[0], z: at[at.length - 1] } : at ?? placeOf(e, 'player');
|
|
31
|
+
if (!p) throw codedError('world-record', `engine.inspect('${at}'): no world record or engine.add object with this id${hintThing(e, at)}. Pass an id engine.thing knows, [x, z] or nothing for the player`);
|
|
32
|
+
const near = e.describe({ radius, center: { x: p.x, z: p.z } }).nearby;
|
|
33
|
+
const ops = e.ops.list({ available: true, actor }).sort((a, b) => b.ok - a.ok).slice(0, OPS_MAX)
|
|
34
|
+
.map(o => ({ op: o.name, args: o.args, ok: o.ok, ...(o.ok ? {} : { code: o.code, why: note(e, o.name, o.code) ?? null, facts: o.facts, nextActions: o.nextActions }) }));
|
|
35
|
+
const thing = typeof at === 'string' && at !== 'player' ? findThing(e, at) : null;
|
|
36
|
+
return { actor, at: { x: Math.round(p.x * 10) / 10, z: Math.round(p.z * 10) / 10 }, near, ops, ...(thing && { thing }) };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Point -> thing: what a ray hit is. A hit on a batched instance resolves to its original object first (engine.batching.item).
|
|
41
|
+
* Returns the record's thing (a source's explain), else the engine.add object's (engine.thing), plus the mesh and material names; for an object neither knows
|
|
42
|
+
* (engine.scene.add) id is null and only those are known.
|
|
43
|
+
* @param {any} e @param {any} obj the hit object @param {{ instanceId?: number }} [hit] @internal
|
|
44
|
+
*/
|
|
45
|
+
export function thingOf(e, obj, hit) {
|
|
46
|
+
if (obj?.isInstancedMesh && hit?.instanceId != null) obj = e.batching.item(obj, hit.instanceId) ?? obj;
|
|
47
|
+
const t = findThing(e, obj), mat = Array.isArray(obj?.material) ? obj.material[0] : obj?.material;
|
|
48
|
+
const look = { mesh: obj?.name || null, material: mat?.name || null };
|
|
49
|
+
return t ? Object.assign(t, look) : { id: null, kind: null, template: null, definedAt: null, model: null, fields: {}, edit: null, ...look };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* @param {any} e
|
|
54
|
+
* @param {Record<string, any>} q
|
|
55
|
+
*/
|
|
56
|
+
export function explain(e, q) {
|
|
57
|
+
if (q?.op) return explainOp(e, q);
|
|
58
|
+
const key = Object.keys(q || {})[0];
|
|
59
|
+
for (const m of e.modules.values()) if (m.explain?.[key]) return m.explain[key](e, q[key], q);
|
|
60
|
+
const keys = ['op', ...[...e.modules.values()].flatMap(m => Object.keys(m.explain || {}))];
|
|
61
|
+
throw codedError('unknown-name', `engine.explain({ ${key}: ... }): nothing explains '${key}'${closest(key, keys) ? ` (did you mean '${closest(key, keys)}'?)` : ''}. Keys: ${keys.join(', ')} (a module adds one with explain: { ${key}(e, value) { return { ok, text } } })`);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Can this op run now (text: the reason and the op's note on how to fix it), and in detail what happened around its last attempt */
|
|
65
|
+
function explainOp(e, { op, args = {}, actor }) {
|
|
66
|
+
const now = e.ops.can(op, args, actor ? { actor } : undefined);
|
|
67
|
+
const recent = e.ops.recent(op).slice(-5);
|
|
68
|
+
const last = recent.at(-1);
|
|
69
|
+
// events within a step of the last attempt: what else changed when it ran / failed
|
|
70
|
+
const events = last ? e.events.recent().filter(h => Math.abs((h.tick ?? 0) - last.tick) <= 1).slice(-8).map(h => h.name) : [];
|
|
71
|
+
const why = now.ok ? 'can run now' : `cannot run now: ${now.code}${note(e, op, now.code) ? ` (${note(e, op, now.code)})` : ''}`;
|
|
72
|
+
const target = typeof args.id === 'string' ? e._things.source(args.id)?.explain(args.id) ?? null : null; // the thing it acts on: where to change it for good
|
|
73
|
+
const before = last ? `last attempt at tick ${last.tick} (${last.source}, ${last.actor}): ${last.ok ? 'ok' : last.code}${last.count > 1 ? ` x${last.count}` : ''}` : 'never run';
|
|
74
|
+
const def = e.ops.defs.get(op), atom = def && atomicNote(def);
|
|
75
|
+
const detail = (atom ? atom + '; ' : '') + before + (events.length ? `; events around it: ${events.join(', ')}` : '');
|
|
76
|
+
return { ok: now.ok, code: now.code ?? null, atomic: def?.atomic === true, revision: e.ops.revision, facts: now.facts ?? {}, nextActions: now.nextActions ?? [], text: `${op} ${JSON.stringify(args)} ${why}${target?.edit ? ` · ${args.id} ${target.edit}` : ''}`, detail, recent, events, ...(target && { thing: target }) };
|
|
77
|
+
}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
// engine.inspect.scene(): "the mesh exists but I do not see it, why?" Walks the scene once, on call (nothing runs per frame, nothing is registered),
|
|
2
|
+
// and for every Mesh / Points / Line / Sprite says whether it can be drawn and, when not, every reason found, most likely first.
|
|
3
|
+
// Pure checks of what three.js itself would do (visible flags up the parent chain, layers, material flags, transform and geometry validity,
|
|
4
|
+
// the view frustum, fog). It cannot see what a shader does with a pixel, or something drawn over it.
|
|
5
|
+
import * as THREE from 'three';
|
|
6
|
+
import { materialInfo, infoLine } from './MaterialInfo.js';
|
|
7
|
+
import { describeRender } from './describeRender.js';
|
|
8
|
+
|
|
9
|
+
const KINDS = [['isMesh', 'Mesh'], ['isPoints', 'Points'], ['isLine', 'Line'], ['isSprite', 'Sprite']];
|
|
10
|
+
const kindOf = o => KINDS.find(([k]) => o[k])?.[1] ?? null;
|
|
11
|
+
const PLANES = ['right', 'left', 'bottom', 'top', 'far', 'near']; // order of THREE.Frustum.planes
|
|
12
|
+
const NAN_SCAN_MAX = 100000; // vertices checked for NaN per geometry: enough to find a broken generator, bounded for huge merged meshes
|
|
13
|
+
const r1 = v => Math.round(v * 10) / 10;
|
|
14
|
+
const fmt = o => o.name || '(unnamed)';
|
|
15
|
+
const why = (code, text, fix, level = 'hidden') => ({ code, level, text, ...(fix && { fix }) });
|
|
16
|
+
|
|
17
|
+
/** Path of names from the scene down to o, for telling same-named objects apart */
|
|
18
|
+
function pathOf(o) {
|
|
19
|
+
const p = [];
|
|
20
|
+
for (let n = o; n; n = n.parent) p.unshift(n.name || n.type);
|
|
21
|
+
return p.join(' > ');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** NaN / Infinity in a geometry's positions (first NAN_SCAN_MAX vertices), memoized per call */
|
|
25
|
+
function badPositions(g, memo) {
|
|
26
|
+
if (memo.has(g)) return memo.get(g);
|
|
27
|
+
const a = g?.attributes?.position;
|
|
28
|
+
let bad = false;
|
|
29
|
+
if (a) {
|
|
30
|
+
for (let i = 0, n = Math.min(a.count, NAN_SCAN_MAX); i < n && !bad; i++) bad = !(Number.isFinite(a.getX(i)) && Number.isFinite(a.getY(i)) && Number.isFinite(a.getZ(i)));
|
|
31
|
+
}
|
|
32
|
+
memo.set(g, bad);
|
|
33
|
+
return bad;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Why there are no vertices to draw: no positions, count 0, an empty draw range, an InstancedMesh with count 0 */
|
|
37
|
+
function emptyReason(o) {
|
|
38
|
+
const g = o.geometry, pos = g?.attributes?.position;
|
|
39
|
+
if (o.isSprite) return null;
|
|
40
|
+
if (!pos || pos.count === 0) return 'the geometry has no vertices';
|
|
41
|
+
if (o.isInstancedMesh && o.count === 0) return 'InstancedMesh.count is 0 (no instances)';
|
|
42
|
+
const n = g.index ? g.index.count : pos.count, dr = g.drawRange;
|
|
43
|
+
if (!(Math.min(n - dr.start, dr.count) > 0)) return `the draw range leaves nothing to draw (drawRange start ${dr.start}, count ${dr.count}, ${n} available)`;
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Reasons from the material(s). An array of materials draws if any one of them does, so it only hides when all of them hide */
|
|
48
|
+
function materialReasons(o) {
|
|
49
|
+
const per = (Array.isArray(o.material) ? o.material : [o.material]).filter(Boolean).map(m => {
|
|
50
|
+
const r = [], id = `material "${m.name || m.type}"`;
|
|
51
|
+
if (m.visible === false) r.push(why('material-hidden', `${id} has visible = false`, 'material.visible = true'));
|
|
52
|
+
if (m.opacity === 0 && m.transparent) r.push(why('opacity-zero', `${id} is transparent with opacity 0`, 'raise material.opacity'));
|
|
53
|
+
else if (m.opacity === 0) {
|
|
54
|
+
r.push(why('opacity-zero',
|
|
55
|
+
`${id} has opacity 0 but transparent is false, so three.js ignores the opacity and draws it opaque (a custom shader may still use it)`,
|
|
56
|
+
'material.transparent = true to fade it for real', 'maybe'));
|
|
57
|
+
}
|
|
58
|
+
if (m.colorWrite === false) r.push(why('color-write-off', `${id} has colorWrite = false: it writes depth only, no color`, 'material.colorWrite = true'));
|
|
59
|
+
if (m.alphaTest >= 1) r.push(why('alpha-test', `${id} has alphaTest ${m.alphaTest}: pixels with alpha below it are discarded, which is all of them`,
|
|
60
|
+
'lower material.alphaTest', 'maybe'));
|
|
61
|
+
if (o.isPoints && m.size === 0) r.push(why('points-size-zero', 'PointsMaterial size is 0', 'material.size = 0.1 (or more)'));
|
|
62
|
+
if (m.depthWrite === false) {
|
|
63
|
+
r.push(why('depth-write-off', `${id} has depthWrite = false: drawn, but it does not occlude and other transparent objects may paint over it`,
|
|
64
|
+
'material.depthWrite = true unless this is a deliberate overlay', 'maybe'));
|
|
65
|
+
}
|
|
66
|
+
return r;
|
|
67
|
+
});
|
|
68
|
+
const hides = per.filter(r => r.some(x => x.level === 'hidden')), soft = per.flat().filter(x => x.level !== 'hidden');
|
|
69
|
+
return per.length && hides.length === per.length ? hides[0].concat(soft.filter(x => !hides[0].includes(x))) : soft;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** The camera's side: where it is, which way it looks, its frustum */
|
|
73
|
+
function viewOf(cam) {
|
|
74
|
+
if (!cam) return null;
|
|
75
|
+
cam.updateMatrixWorld();
|
|
76
|
+
const inv = new THREE.Matrix4().copy(cam.matrixWorld).invert(), me = cam.matrixWorld.elements;
|
|
77
|
+
return { pos: new THREE.Vector3().setFromMatrixPosition(cam.matrixWorld), fwd: new THREE.Vector3(-me[8], -me[9], -me[10]).normalize(),
|
|
78
|
+
frustum: new THREE.Frustum().setFromProjectionMatrix(new THREE.Matrix4().multiplyMatrices(cam.projectionMatrix, inv)) };
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** Transform and geometry sanity: NaN positions / scales, scale 0, NaN vertices, nothing to draw */
|
|
82
|
+
function shapeReasons(o, type, sc, memo) {
|
|
83
|
+
const r = [], me = o.matrixWorld.elements;
|
|
84
|
+
if (![o.position.x, o.position.y, o.position.z].every(Number.isFinite)) r.push(why('position-nan', 'its own position has NaN or Infinity in it',
|
|
85
|
+
'find the code that sets position (an undefined, a division by zero)'));
|
|
86
|
+
else if (![me[12], me[13], me[14]].every(Number.isFinite)) r.push(why('position-nan',
|
|
87
|
+
'its world position is NaN: a transform up the parent chain has NaN or Infinity', 'check the positions / scales of its ancestors'));
|
|
88
|
+
if (sc.some(s => !Number.isFinite(s))) r.push(why('scale-zero', 'its world scale is NaN or Infinity', 'check scale on it and its ancestors'));
|
|
89
|
+
else if (sc.some(s => s < 1e-9)) r.push(why('scale-zero', `its world scale is 0 on at least one axis (${sc.map(r1).join(', ')}): it flattens to nothing`,
|
|
90
|
+
`${fmt(o)}.scale.set(1, 1, 1), and check ancestors`));
|
|
91
|
+
if (type !== 'Sprite' && badPositions(o.geometry, memo)) {
|
|
92
|
+
r.push(why('geometry-nan', 'the geometry has NaN or Infinity in its vertex positions: it cannot be culled or drawn correctly',
|
|
93
|
+
'fix the generator that wrote the positions (radius 0, division by zero, missing input)'));
|
|
94
|
+
}
|
|
95
|
+
const empty = emptyReason(o);
|
|
96
|
+
if (empty) r.push(why('geometry-empty', empty, 'check the code that builds the geometry, geometry.setDrawRange, InstancedMesh.count'));
|
|
97
|
+
return r;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** Where it is relative to the camera: behind, beyond far, outside the view, lost in fog. center / radius are in the world */
|
|
101
|
+
function viewReasons(o, type, center, radius, view, cam, fog) {
|
|
102
|
+
const r = [], dz = center.clone().sub(view.pos).dot(view.fwd), where = `${r1(dz)} m ahead of the camera`;
|
|
103
|
+
if (Number.isNaN(radius)) r.push(why('radius-nan', 'its bounding sphere radius is NaN, so frustum culling rejects it',
|
|
104
|
+
'fix the geometry positions, then geometry.computeBoundingSphere()'));
|
|
105
|
+
else if (radius === 0 && (type === 'Mesh' || type === 'Line')) r.push(why('radius-zero',
|
|
106
|
+
'its bounding sphere radius is 0: all vertices are at one point, nothing to see', 'check the generator (a size or radius of 0)'));
|
|
107
|
+
if (!Number.isFinite(radius)) return r;
|
|
108
|
+
if (dz < -radius) r.push(why('behind-camera', `it is behind the camera (${r1(-dz)} m behind)`,
|
|
109
|
+
'move the camera or the object; check the camera looks where you think'));
|
|
110
|
+
else if (dz - radius > cam.far) r.push(why('beyond-far', `it is beyond camera.far (${r1(dz - radius)} m away, far is ${cam.far})`,
|
|
111
|
+
'raise camera.far or bring the object closer'));
|
|
112
|
+
else {
|
|
113
|
+
const out = view.frustum.planes.findIndex(p => p.distanceToPoint(center) < -radius);
|
|
114
|
+
if (out >= 0) r.push(why('outside-frustum', `it is outside the view (${PLANES[out]} plane; ${where}). frustumCulled is ${o.frustumCulled}`,
|
|
115
|
+
'move the camera to face it, or check its position'));
|
|
116
|
+
}
|
|
117
|
+
const m0 = Array.isArray(o.material) ? o.material[0] : o.material;
|
|
118
|
+
if (fog && m0?.fog !== false && (fog.isFogExp2 ? dz - radius > 2.15 / fog.density : dz - radius >= fog.far)) {
|
|
119
|
+
r.push(why('fogged-out', `it is fully inside the fog (${where}; ${fog.isFogExp2 ? 'density ' + fog.density : 'fog far ' + fog.far})`,
|
|
120
|
+
'raise fog.far / lower the density, or set material.fog = false', 'maybe'));
|
|
121
|
+
}
|
|
122
|
+
return r;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** One object: its reasons (most likely first: switched off, wrong layer, material, transform / geometry, then where it is) and its record */
|
|
126
|
+
function checkObject(o, type, ctx) {
|
|
127
|
+
const { view, cam, scene, memo } = ctx, reasons = [], off = [];
|
|
128
|
+
for (let n = o; n; n = n.parent) if (n.visible === false) off.push(n);
|
|
129
|
+
if (off[0] === o) reasons.push(why('hidden-self', 'its own visible is false', `${fmt(o)}.visible = true`));
|
|
130
|
+
const anc = off.find(n => n !== o);
|
|
131
|
+
if (anc) reasons.push(why('hidden-ancestor', `ancestor "${fmt(anc)}" (${pathOf(anc)}) has visible = false, which hides all its children`,
|
|
132
|
+
`${fmt(anc)}.visible = true`));
|
|
133
|
+
if (cam && !o.layers.test(cam.layers)) {
|
|
134
|
+
reasons.push(why('layers', `layers do not match the camera (object mask ${o.layers.mask}, camera mask ${cam.layers.mask}): the renderer skips it`,
|
|
135
|
+
'object.layers.enable(n) for a layer the camera sees, or camera.layers.enable(n)'));
|
|
136
|
+
}
|
|
137
|
+
reasons.push(...materialReasons(o));
|
|
138
|
+
const me = o.matrixWorld.elements, sc = [Math.hypot(me[0], me[1], me[2]), Math.hypot(me[4], me[5], me[6]), Math.hypot(me[8], me[9], me[10])];
|
|
139
|
+
const shape = shapeReasons(o, type, sc, memo);
|
|
140
|
+
reasons.push(...shape);
|
|
141
|
+
let center = new THREE.Vector3().setFromMatrixPosition(o.matrixWorld), radius = NaN;
|
|
142
|
+
if (!shape.some(x => ['geometry-nan', 'position-nan', 'geometry-empty'].includes(x.code))) {
|
|
143
|
+
let bs = o.boundingSphere ?? o.geometry.boundingSphere;
|
|
144
|
+
if (!bs) { (o.isInstancedMesh ? o : o.geometry).computeBoundingSphere(); bs = o.boundingSphere ?? o.geometry.boundingSphere; }
|
|
145
|
+
center = bs.center.clone().applyMatrix4(o.matrixWorld);
|
|
146
|
+
radius = bs.radius * Math.max(...sc);
|
|
147
|
+
if (view) reasons.push(...viewReasons(o, type, center, radius, view, cam, scene.fog));
|
|
148
|
+
}
|
|
149
|
+
const ranked = [...reasons.filter(x => x.level === 'hidden'), ...reasons.filter(x => x.level !== 'hidden')], mats = (Array.isArray(o.material) ? o.material : [o.material]).filter(Boolean);
|
|
150
|
+
const drawn = !ranked.some(x => x.level === 'hidden');
|
|
151
|
+
return { name: o.name || null, type, path: pathOf(o), id: o.id, position: { x: r1(center.x), y: r1(center.y), z: r1(center.z) }, radius: Number.isFinite(radius) ? r1(radius) : null,
|
|
152
|
+
material: mats.length ? { type: mats.map(m => m.type).join('+'), purpose: mats[0].userData?.purpose ?? o.userData?.purpose ?? null, info: mats.map(m => materialInfo(m, o)) } : null,
|
|
153
|
+
visible: o.visible, drawn, ...(ranked.length && { reasons: ranked }) };
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** Text of one listed object: a line, the reasons that hide it, then the "maybe" ones */
|
|
157
|
+
function lineOf(x) {
|
|
158
|
+
const hard = (x.reasons ?? []).filter(r => r.level === 'hidden'), soft = (x.reasons ?? []).filter(r => r.level === 'maybe');
|
|
159
|
+
return `${x.drawn ? '✓' : '✗'} ${x.name ?? '(unnamed)'} [${x.type}] (${x.position.x}, ${x.position.y}, ${x.position.z}) r=${x.radius ?? '?'}`
|
|
160
|
+
+ `${x.material ? ` · ${x.material.type}${x.material.purpose ? '/' + x.material.purpose : ''}` : ''}`
|
|
161
|
+
+ (x.material?.info ? '\n material: ' + x.material.info.map(infoLine).join('\n material: ') : '')
|
|
162
|
+
+ (hard.length ? '\n ' + hard.map(r => r.text).join('\n ') : '') + (soft.length ? `\n maybe: ${soft.map(r => r.text).join(' · ')}` : '');
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Check every Mesh / Points / Line / Sprite in the scene. Not drawn (as far as these checks can tell) means at least one reason of level 'hidden';
|
|
167
|
+
* level 'maybe' reasons are things that may explain a missing or odd look but do not by themselves stop drawing.
|
|
168
|
+
* @param {any} e engine
|
|
169
|
+
* @param {{ hidden?: boolean, limit?: number }} [opts] hidden: list only objects that are not drawn; limit: how many to list (default 40; counts cover all)
|
|
170
|
+
*/
|
|
171
|
+
export function inspectScene(e, { hidden = false, limit = 40 } = {}) {
|
|
172
|
+
const scene = e.scene, cam = e.camera, ctx = { scene, cam, view: viewOf(cam), memo: new Map() };
|
|
173
|
+
scene.updateMatrixWorld();
|
|
174
|
+
const items = [], counts = { total: 0, drawn: 0, notDrawn: 0, byType: {} };
|
|
175
|
+
scene.traverse(o => {
|
|
176
|
+
const type = kindOf(o);
|
|
177
|
+
if (!type) return;
|
|
178
|
+
const item = checkObject(o, type, ctx);
|
|
179
|
+
counts.total++; counts.byType[type] = (counts.byType[type] ?? 0) + 1; counts[item.drawn ? 'drawn' : 'notDrawn']++;
|
|
180
|
+
if (!(hidden && item.drawn)) items.push(item);
|
|
181
|
+
});
|
|
182
|
+
items.sort((a, b) => a.drawn - b.drawn);
|
|
183
|
+
const shown = items.slice(0, limit), cp = ctx.view?.pos, types = Object.entries(counts.byType).map(([k, v]) => `${k} ${v}`).join(', ') || 'none';
|
|
184
|
+
const head = `Scene: ${counts.total} drawable objects (${types}), ${counts.drawn} drawn, ${counts.notDrawn} not drawn`
|
|
185
|
+
+ (cp ? ` · camera at (${r1(cp.x)}, ${r1(cp.y)}, ${r1(cp.z)}), far ${cam.far}` : ' · no camera');
|
|
186
|
+
const render = describeRender(e)?.text.split('\n')[0]; // the renderer line (tone mapping + exposure), reused from describe().render
|
|
187
|
+
const text = [head, render, ...shown.map(lineOf), items.length > shown.length ? `… ${items.length - shown.length} more (limit ${limit}; pass a bigger limit)` : null,
|
|
188
|
+
'Checks what three.js would do (visible flags, layers, material flags, transform / geometry validity, frustum, fog). It cannot see shader output or something drawn over it.']
|
|
189
|
+
.filter(Boolean).join('\n');
|
|
190
|
+
return { camera: cam ? { position: { x: r1(cp.x), y: r1(cp.y), z: r1(cp.z) }, near: cam.near, far: cam.far } : null, counts, items: shown, truncated: items.length - shown.length, render: render ?? null, text };
|
|
191
|
+
}
|