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
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# Shooting and picking (first person; cast a ray from the screen center / mouse position)
|
|
2
|
+
|
|
3
|
+
Requires `openWorld({ camera: 'firstPerson' })` (or `firstPersonCamera()` by hand); a score display needs `hud()`.
|
|
4
|
+
The ray API is `engine.pick(ndcX, ndcY, opts)`: screen coordinates -1..1 (0, 0 is the screen center, which is also the first-person crosshair); it
|
|
5
|
+
returns the nearest hit `{ point, distance, object, ... }` or null. **If you only want to hit your own targets, pass `targets: [array of objects]`; no
|
|
6
|
+
ray registration is needed.**
|
|
7
|
+
|
|
8
|
+
## 1. A first-person shooting range (copy it and it runs)
|
|
9
|
+
```js
|
|
10
|
+
import { createEngine, presets, openWorld, hud, THREE, makeMaterial } from 'threedog';
|
|
11
|
+
import lowpoly from '@threedog/style-lowpoly';
|
|
12
|
+
import { terrainPreset } from '@threedog/terrain-noise';
|
|
13
|
+
|
|
14
|
+
const engine = createEngine({ canvas: document.getElementById('view'), style: lowpoly, saveKey: 'range' });
|
|
15
|
+
engine.use(openWorld({ seed: 7, terrain: terrainPreset(), camera: 'firstPerson' }), hud()); // camera (required): 'follow' | 'firstPerson' | 'rts' | 'fixed', or pass a module like firstPersonCamera({ height: 1.7 })
|
|
16
|
+
engine.input.define('shoot', ['Mouse0', 'KeyF'], '开枪'); // the left mouse button is a key too (Mouse0 / Mouse1 / Mouse2); either it or KeyF works
|
|
17
|
+
engine.characters.createPlayer({ ...presets.player.aim, spawn: engine.characters.findSpawn([0, 0, 0], { minH: 3, maxH: 14 }) });
|
|
18
|
+
await engine.start(); // place targets after the terrain is generated
|
|
19
|
+
|
|
20
|
+
// Targets: ordinary three.js objects. Put your own data in target.userData; managing them with a Map / Set is faster than traversing the scene
|
|
21
|
+
const targets = [];
|
|
22
|
+
function addTarget(x, z) {
|
|
23
|
+
const t = new THREE.Mesh(new THREE.CylinderGeometry(0.5, 0.5, 0.1, 16), makeMaterial('prop', { color: 0xd9534f }));
|
|
24
|
+
t.rotation.x = Math.PI / 2;
|
|
25
|
+
t.position.set(x, engine.surface(x, z) + 1.5, z);
|
|
26
|
+
engine.add(t); targets.push(t);
|
|
27
|
+
}
|
|
28
|
+
const p0 = engine.player.position;
|
|
29
|
+
for (let i = 0; i < 6; i++) addTarget(p0.x + (i - 2.5) * 3, p0.z - 15);
|
|
30
|
+
|
|
31
|
+
let score = 0;
|
|
32
|
+
engine.hud.counter('score', { label: '命中', value: 0 });
|
|
33
|
+
engine.describe.add('range', () => ({ score, targets: targets.length })); // visible with the dev bridge: threedog describe range
|
|
34
|
+
|
|
35
|
+
engine.onFixed(() => { // firing is gameplay: read it in fixed so the result is independent of frame rate
|
|
36
|
+
if (!engine.input.pressed('shoot')) return; // "just pressed" from the fixed-step snapshot; one click counts once
|
|
37
|
+
const hit = engine.pick(0, 0, { targets }); // cast from the screen center; hit.object may be a child mesh of the target, so find the target as below
|
|
38
|
+
const t = hit && targets.find(x => x === hit.object || x.getObjectById(hit.object.id));
|
|
39
|
+
if (!t) return;
|
|
40
|
+
engine.remove(t); targets.splice(targets.indexOf(t), 1);
|
|
41
|
+
engine.hud.counter('score', { value: ++score }); // calling again with the same id = update
|
|
42
|
+
});
|
|
43
|
+
```
|
|
44
|
+
- **Finding the target again**: when a target is made of several meshes, `hit.object` is the piece that was hit. Set `userData.target = true` on the
|
|
45
|
+
target's root object, then `let o = hit.object; while (o && !o.userData.target) o = o.parent;`.
|
|
46
|
+
- **Why not read `pointer.clicked`**: it is true only for "this frame" and requires no dragging; a fixed step can miss that frame (at a high frame
|
|
47
|
+
rate a frame may have 0 fixed steps). Leave `clicked` for UI and clicking the ground (read it in onFrame); bind firing / attacking to a `Mouse0`
|
|
48
|
+
action and read `pressed` in onFixed.
|
|
49
|
+
- **Picking instead of shooting**: for the mouse position use `engine.pick(engine.input.pointer.ndcX, engine.input.pointer.ndcY, { targets })`; with
|
|
50
|
+
the mouse locked in first person use `(0, 0)`. To click the ground (move, place) use `screenToGround(engine, ndcX, ndcY)`.
|
|
51
|
+
- **The first click**: on desktop, first person by default needs one click on the canvas to lock the mouse. That press only locks: it is not delivered
|
|
52
|
+
as `Mouse0` and not as a click, so it cannot fire (every later click after Esc and a re-lock behaves the same). `swallowLockClick: false` on the
|
|
53
|
+
camera delivers it too.
|
|
54
|
+
- **Adding a gamepad button**: `engine.input.define('shoot', ['Mouse0', 'KeyF', 'PadRT'], '开枪')`; the key names go into the settings key table and the
|
|
55
|
+
UI prompts. A touch tap does not count as `Mouse0` (give phones a button: `engine.input.touchButton('shoot', '开枪')`).
|
|
56
|
+
- To hit terrain / houses / registered static objects, don't pass `targets` (the default hits what was registered with `rays.addStatic`); to hit rigid
|
|
57
|
+
bodies too, pass `targets: 'all'`.
|
|
58
|
+
|
|
59
|
+
## 2. What happens after a hit
|
|
60
|
+
- Hit-point effect: `engine.particles.emit(name, hit.point)` (install `particles()` first).
|
|
61
|
+
- For bullets with flight time (arcs, enemies dodging): don't use a ray; write `world.add({ kind: 'bullet', ... })` + `world.simulate`, see `18-world.md`.
|
|
62
|
+
- Distance limit: `engine.pick(0, 0, { targets, far: 60 })`.
|
|
63
|
+
- Score, ammo: `hud.counter` / `hud.bar`; numbers that must be saved go in `engine.vars` (`engine.vars.bump('score')`); after changing them call
|
|
64
|
+
`hud.counter` again to sync the display.
|
|
65
|
+
|
|
66
|
+
## 3. Testing
|
|
67
|
+
```js
|
|
68
|
+
engine.pause();
|
|
69
|
+
engine.input.simulate('shoot'); engine.step(0.1); engine.input.simulate('shoot', false); // simulate a click on the action bound to Mouse0 (use your action name)
|
|
70
|
+
// To hit a specific target: first aim the camera at it with engine.cameraRig.lookAt(target), then click
|
|
71
|
+
```
|
|
72
|
+
From the command line: `npx threedog press Mouse0` (the same as pressing a keyboard key), then look at `describe range`:
|
|
73
|
+
```
|
|
74
|
+
npx threedog press Mouse0
|
|
75
|
+
npx threedog describe range
|
|
76
|
+
```
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
# Content vocabulary, key actions in actions.js, saving and loading at startup
|
|
2
|
+
|
|
3
|
+
## 1. Condition words / effect words
|
|
4
|
+
The full vocabulary is in the last section of `../api/content.md` (**generated from `modules/content/rules.js`**, so it never goes stale):
|
|
5
|
+
`flag has counter setFlag give take bump startQuest toast particles marker ...`, each with how to write its value. A game's own words go in
|
|
6
|
+
`content/rules.js` (format in the comment at the top of `rules.js`), or in code with `engine.content.condition(name, def)`. A game's own actions are
|
|
7
|
+
ops, used from content as `{ op: [...] }` / `{ can: [...] }` (`23-ops.md`), not new effect words.
|
|
8
|
+
- `has / lacks / give / take` need the `inventory()` module; without it they throw an error that says so.
|
|
9
|
+
- Conditions are used in: quest step `done`, dialogue choice `if`, line variant `if`. Several entries in one object = all must hold; an array = every
|
|
10
|
+
item must hold.
|
|
11
|
+
- Effects are used in: dialogue `do`, quest `reward`, trigger zone `onEnter / onExit`. Several entries in one object, or an array, run in order.
|
|
12
|
+
- Content validation (content-check inside `threedog check` / `threedog map`) checks the word names and how the values are written.
|
|
13
|
+
|
|
14
|
+
### A game's own data kinds (enemies, recipes, loot tables, waves…)
|
|
15
|
+
`content/` knows the engine's files (items, npcs, quests…) plus any kind the game registers in `content/rules.js`.
|
|
16
|
+
Register once and the loader, `threedog check` and GAMEMAP all know the file:
|
|
17
|
+
```js
|
|
18
|
+
// content/rules.js
|
|
19
|
+
import { craftOp } from '../crafting.js'; // the game's own code
|
|
20
|
+
export default {
|
|
21
|
+
kinds: {
|
|
22
|
+
recipes: {
|
|
23
|
+
desc: 'crafting recipes (id -> { needs: { item: n }, makes: item })',
|
|
24
|
+
// runs inside content.load, after the engine's data (items, NPCs, places)
|
|
25
|
+
load: (e, data) => { for (const [id, r] of Object.entries(data)) e.ops.define('craft.' + id, craftOp(r)); },
|
|
26
|
+
// optional, runs in threedog check; ctx.data = all content, ctx.err / ctx.warn report against content/recipes.js
|
|
27
|
+
check(data, ctx) {
|
|
28
|
+
for (const [id, r] of Object.entries(data)) if (!ctx.data.items?.[r.makes]) ctx.err(`recipe ${id} makes unknown item ${r.makes}`);
|
|
29
|
+
},
|
|
30
|
+
map: data => Object.entries(data).map(([id, r]) => `${id} -> ${r.makes}`), // optional GAMEMAP lines
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
```
|
|
35
|
+
```js
|
|
36
|
+
// content/recipes.js
|
|
37
|
+
export default { bread: { needs: { flour: 2 }, makes: 'bread' } };
|
|
38
|
+
```
|
|
39
|
+
Add `recipes` to `content/index.js` like any other file. A file in `content/` that is neither an engine file nor a registered kind is an error,
|
|
40
|
+
and so is `content.load({ enemies })` without the kind: both say how to register it. A kind may not reuse an engine file name.
|
|
41
|
+
|
|
42
|
+
## 1b. Content packs: several data sets in one load
|
|
43
|
+
A content pack is the same object `content/index.js` exports (`{ items, templates, props, quests, ... }`, optional `name` for messages), shipped as a
|
|
44
|
+
folder or an npm package: data only, assets by name (never a path or a function; `npm run check` and a dev warning report both). Load several together:
|
|
45
|
+
```js
|
|
46
|
+
import base from './content/index.js';
|
|
47
|
+
import forest from 'forest-content'; // its props name templates from base and models from the forest asset pack
|
|
48
|
+
import forestAssets from 'forest-assets'; // that asset pack: { name, base, models, textures, sounds, fonts }
|
|
49
|
+
engine.assets.manifest(forestAssets);
|
|
50
|
+
engine.content.load([base, forest], { places: { home } });
|
|
51
|
+
```
|
|
52
|
+
- Packs load in list order, so a pack may use what an earlier one defines.
|
|
53
|
+
- Within one call an id may live in one pack only: `items.apple` in two packs, or the same prop / pickup id, is an error naming both packs. A later,
|
|
54
|
+
separate `load` call still overrides by name on purpose (hot reload, a chapter replacing a quest).
|
|
55
|
+
- A pack may carry its sounds: `audio: { sounds, ambience, music, footsteps }` (`recipes/31-audio.md` section 8). Sounds, footsteps and music tracks
|
|
56
|
+
are ids like items (two packs, one name: an error); ambience and music rule lists concatenate.
|
|
57
|
+
|
|
58
|
+
## 2. actions.js: a game's own key actions
|
|
59
|
+
Format of `content/actions.js`: **action name -> { keys: default keys, label: display text }**. Actions that the engine brings along (move...) need
|
|
60
|
+
not be written; inventory, quests and photo bind a key only when given `keys` (`inventory({ ...presets.keys.inventory })`), and run, jump and interact
|
|
61
|
+
are not core keys either: they come from the game (`presets.player.*`, `interactions({ keys })`, this file or `createEngine({ bindings })`).
|
|
62
|
+
```js
|
|
63
|
+
// content/actions.js
|
|
64
|
+
export default {
|
|
65
|
+
kick: { keys: ['KeyF'], label: '推/踢' },
|
|
66
|
+
save: { keys: ['KeyK'], label: '存档' },
|
|
67
|
+
load: { keys: ['KeyL'], label: '读档' },
|
|
68
|
+
};
|
|
69
|
+
```
|
|
70
|
+
Don't forget to add it to the exports in `content/index.js` (`export default { ..., actions }`), otherwise `engine.content.load(data)` will not load
|
|
71
|
+
it (it calls `engine.input.define(name, keys, label)`). What happens on press is written in main.js, read inside a fixed step so it lands on a tick:
|
|
72
|
+
`engine.onFixed(() => { if (engine.input.pressed('kick')) engine.ops.run('ball.kick', {}, { source: 'player' }); })` (a gameplay action is an op,
|
|
73
|
+
recipes/23-ops.md). A game that does not use content calls `engine.input.define('kick', 'KeyF', '推/踢')` directly.
|
|
74
|
+
|
|
75
|
+
**The engine does not perform the `save` / `load` actions for you**: they only register the keys; after the press you call the engine yourself in
|
|
76
|
+
main.js. Saving and loading are async (`Promise<boolean>`): await them, and say "saved" only on `true` (on `false` the engine already showed why).
|
|
77
|
+
Loading a slot to keep playing from it is `engine.session.load`, which leaves nothing of the current playthrough behind:
|
|
78
|
+
```js
|
|
79
|
+
import { toast } from 'threedog';
|
|
80
|
+
engine.onFixed(() => { // read keys in the fixed step like every gameplay key; the async work runs after it
|
|
81
|
+
if (engine.input.pressed('save')) engine.saves.save('slot1').then(ok => ok && toast(engine, '已存档'));
|
|
82
|
+
if (engine.input.pressed('load')) engine.session.load('slot1').then(ok => !ok && toast(engine, '还没有存档'));
|
|
83
|
+
});
|
|
84
|
+
engine.saves.autosave(3); // autosave to 'auto' every 3 minutes of play (waits while paused, on the title screen and during newGame / load)
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## 3. Interact keys: which object, and who acts
|
|
88
|
+
`interactions({ pick, keys })` decides what the interact key uses and which key that is; neither has a default (`[interaction-setup]` names the fix).
|
|
89
|
+
Pick the rule that fits the camera, not the genre default:
|
|
90
|
+
```js
|
|
91
|
+
engine.use(interactions({ ...presets.interactions.nearest })); // E, nearest within 2.5 m (top-down, third person)
|
|
92
|
+
engine.use(interactions({ pick: 'facing', keys: ['KeyE'] })); // only what the actor faces (within 60°): the door behind you stays dark
|
|
93
|
+
engine.use(interactions({ pick: 'aim', keys: ['KeyF'], radius: 2 })); // closest to the screen-center ray: first person, shooters
|
|
94
|
+
engine.use(interactions({ pick: (list, ctx) => list.find(c => c.id.startsWith('npc')) ?? list[0], keys: ['KeyE'] })); // own rule; list = enabled ones in range, nearest first
|
|
95
|
+
engine.interactions.pickMode = 'aim'; // switch at runtime (entering a first-person mode)
|
|
96
|
+
```
|
|
97
|
+
One object with two verbs = two interactions with different key actions; each key picks among its own action, and `engine.interactions.options` lists
|
|
98
|
+
one `{ action, id, label }` per key for a prompt that shows both:
|
|
99
|
+
```js
|
|
100
|
+
engine.input.define('harvest', 'KeyF', '收获');
|
|
101
|
+
engine.interactions.add(crop, { label: '浇水', onUse: water }); // E
|
|
102
|
+
engine.interactions.add(crop, { label: '收获', action: 'harvest', enabled: () => ripe, onUse: harvest }); // F
|
|
103
|
+
```
|
|
104
|
+
**Who acts** is `engine.actor` (a world record id, default `'player'`). Interactions, trigger zones, objective-marker distances, the world simulation
|
|
105
|
+
center and the default `ctx.actor` of ops all measure from `engine.actorPosition()`. To let the user drive a boat or switch squad members, set
|
|
106
|
+
`engine.actor = 'boat_1'` and back to `'player'`; nothing else changes. Module code reads `engine.actorPosition()`, never `engine.player.position`
|
|
107
|
+
(rule R17 warns).
|
|
108
|
+
|
|
109
|
+
## 4. Continue and new game (the engine does not load automatically on start)
|
|
110
|
+
After a page refresh the game is a new run; to "continue last time", load **after** `await engine.start()` through `engine.session`, the standard form:
|
|
111
|
+
```js
|
|
112
|
+
await engine.start(); // modules and the save index are ready, so saves.list / check are synchronous
|
|
113
|
+
if (engine.saves.check('auto') === null) await engine.session.load('auto'); // continue from the autosave if it can be loaded
|
|
114
|
+
```
|
|
115
|
+
- `engine.session.load(slot)` and `engine.session.newGame()` both return `Promise<boolean>`: always `await`. `session.load` starts from the new-game
|
|
116
|
+
state and puts the save on top, so a part the save lacks (a module added in a later version) starts fresh instead of keeping the current run's
|
|
117
|
+
state. `engine.saves.load(slot)` is a quick load onto the running playthrough; never build Continue from it.
|
|
118
|
+
- Loading restores the player, world data (world changes and deletions), inventory, quests, clock and random state; initial data in content files
|
|
119
|
+
(`initial`) is the same whether it is loaded before or after the save, so ignore the order.
|
|
120
|
+
- For a "main menu: Continue / New game": show "Continue" only when `engine.saves.check(slot) === null`; on click `await engine.session.load(slot)`;
|
|
121
|
+
"New game" is `await engine.session.newGame()`.
|
|
122
|
+
- During development, to jump straight into a save: URL `?save=slot1` (`threedog state` also understands `save=`).
|
|
123
|
+
- In tests, `engine.saves.save('x'); await engine.saves.flush();` writes before reading back.
|
|
124
|
+
|
|
125
|
+
## Save failures and versions
|
|
126
|
+
- `await engine.saves.save(slot)` is `true` only after the write is on disk; show "saved" only then. On a failed write (storage full, IndexedDB /
|
|
127
|
+
localStorage refused) it is `false`, the player already saw why, and the previous save of that slot is kept (memory follows the disk).
|
|
128
|
+
- A corrupt save, a part from a newer build or a missing migrate step is refused before anything changes: `load` returns `false` with a message, the
|
|
129
|
+
running game and the stored save stay as they were. Ask first with `engine.saves.check(slot)` → `null | 'missing' | 'corrupt' | 'tooNew' | 'migrate'`.
|
|
130
|
+
- A part whose `save()` throws makes the whole save fail (`false`, the slot keeps its previous save); a part whose `load()` throws rolls the game back
|
|
131
|
+
to how it was before the load (`false`). Both go through the error tiers (`engine.error` in dev, code `save-part-threw` / `save-load-threw`).
|
|
132
|
+
- `engine.saves.versions` lists the version of every part this build reads (`{ world: 3, clock: 1, ... }`); raise a part's `version` with a `migrate`
|
|
133
|
+
step when its data changes shape.
|
|
134
|
+
- Import is offline and checked: `saves.import(text)` and `saves.importFile(file)` (default slot `'imported'`) refuse anything that is not a save, and
|
|
135
|
+
attachments must be `data:` URLs (nothing is fetched).
|
|
136
|
+
|
|
137
|
+
## Save format (frozen in v0.1)
|
|
138
|
+
A save is one envelope; `engine.saves.collect()` returns it and `export` / `exportFile` carry it unchanged:
|
|
139
|
+
```js
|
|
140
|
+
{ format: 1, // the envelope's own version: a save with a higher format is refused as tooNew (none = 1)
|
|
141
|
+
savedAt: 1730000000000, // real time of the save
|
|
142
|
+
versions: { world: 3, quests: 2, clock: 1 }, // each part's version (none = 1)
|
|
143
|
+
parts: { world: {...}, quests: {...}, clock: {...}, vars: {...} } } // each saves.register part's data, by key
|
|
144
|
+
```
|
|
145
|
+
- **Parts and versions**: each `engine.saves.register(key, { version, migrate, save, load })` owns one part. When `save()` changes shape, raise
|
|
146
|
+
`version` by 1 and add `migrate[oldVersion] = data => newData`; load runs the steps in order on a copy, so `load` only sees the current shape. A
|
|
147
|
+
part from a newer build, or a missing step, refuses the whole load before anything changes.
|
|
148
|
+
- **Parts nobody owns are kept**: a part in the loaded save whose module is not installed in this run (a feature turned off for a version) is written
|
|
149
|
+
back unchanged on every save, and handed to the module if it registers later. Only a new game drops it.
|
|
150
|
+
- **Authored baseline + per-id diff**: everything placed in a level comes from content (props, template instances, pickups, NPCs, grid items in
|
|
151
|
+
`props`, level-model nodes tagged `template` / `id`) with a stable id, and the world part stores only what play changed on top of it, keyed by id:
|
|
152
|
+
`changed` (fields of an authored record that differ), `removed` (authored records removed), `records` (records created during play, such as
|
|
153
|
+
`engine.spawn`, drops and built walls, saved whole), `owed` (seconds owed, only for kinds simulated with `far`). The same content gives the same
|
|
154
|
+
world, and a new game's world part is empty: in dev, start warns about records that code created or changed before it, naming them.
|
|
155
|
+
- **Orphans are kept**: a saved change whose id the content no longer defines (an entry renamed or deleted) stays in the save and is written
|
|
156
|
+
back, <!-- r18-ignore-line -->
|
|
157
|
+
never dropped, so reverting the content change gets the data back. Dev warns once with the closest id and the `content/renames.js` pair that
|
|
158
|
+
would <!-- r18-ignore-line -->
|
|
159
|
+
move it; `describe().world.orphans` lists them. A rename in `content/renames.js` moves the state to the new id (recipe 30, "Writing the ids, <!--
|
|
160
|
+
r18-ignore-line -->
|
|
161
|
+
renaming them"). <!-- r18-ignore-line -->
|
|
162
|
+
- **Runtime ids and migration**: records made during play are `<kind>#<n>` (world part version 3). An older save's `<kind>-<n>` ids are renamed when
|
|
163
|
+
it loads, together with the owed time, container goods and fields that name them; only ids the counter could have made are touched (own kind, `n` up
|
|
164
|
+
to the saved counter, each `n` once), so an authored `crate-2` stays as it is. A migrate step that needs another part gets the whole save as its
|
|
165
|
+
second argument: `migrate: { 1: (data, save) => … }`. <!-- r18-ignore-line -->
|
|
166
|
+
- **Grid layers diff too**: cells authored in `content/grids.js` (`farm: { …, layers: { soil: [[i, j, { tilled: true }]] } }`) are the baseline;
|
|
167
|
+
the <!-- r18-ignore-line -->
|
|
168
|
+
`grids` part (version 2) stores only changed cells (`set`) and emptied authored ones (`clear`), and keeps a diff for a grid the run does not
|
|
169
|
+
have. <!-- r18-ignore-line -->
|
|
170
|
+
- **Stable ids, never positions**: saved data names things by stable ids. The player's vehicle is saved by `rigid.addVehicle(mesh, { id })`; quest
|
|
171
|
+
progress by step ids (`steps: [{ id: 'talk-mayor', ... }]`, recipe 04). Content edits (a new step, a new prop) then never shift an old save.
|
|
172
|
+
- **Built-in part versions**: `world` 3 (version 1 kept `records` as an array, version 2 the `<kind>-<n>` runtime ids), `quests` 2 (version 1 kept
|
|
173
|
+
step positions; the migrate step maps them to ids through the quest definitions), `containers` 2 and `grids` 2, every other part 1.
|
|
174
|
+
- The export file wraps the envelope:
|
|
175
|
+
`{ threedog: 'save', format: 1, game, slot, savedAt, data: <envelope>, files: [{ group, id, at, meta, type, url: 'data:...' }] }`.
|
|
176
|
+
- Tests: `npm test -- "Save failure"`.
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
# Camera: first / third person, top-down strategy, fixed shots, switched at runtime
|
|
2
|
+
|
|
3
|
+
Four cameras; the kind names are always: `'follow'` third-person follow · `'firstPerson'` first person · `'rts'` top-down strategy · `'fixed'` fixed shots.
|
|
4
|
+
Pick one at the start: `openWorld({ camera: 'firstPerson' })`, or by hand `engine.use(followCamera({ distance: 10 }))` /
|
|
5
|
+
`firstPersonCamera({ height: 1.7 })` / `rtsCamera()` / `fixedCamera({ shots })`.
|
|
6
|
+
**There is exactly one entry point for changing camera in the game: `engine.setCamera(kind, options?)`**, no restart needed.
|
|
7
|
+
|
|
8
|
+
## 1. Press V to switch between first and third person (copy it)
|
|
9
|
+
```js
|
|
10
|
+
engine.input.define('toggleView', ['KeyV'], '切换视角');
|
|
11
|
+
engine.onFrame(() => { // UI-type actions read pressed in onFrame
|
|
12
|
+
if (!engine.input.pressed('toggleView')) return;
|
|
13
|
+
engine.setCamera?.(engine.cameraRig?.kind === 'follow' ? 'firstPerson' : 'follow'); // kind is the current kind
|
|
14
|
+
});
|
|
15
|
+
```
|
|
16
|
+
Starting in first person and switching later: `openWorld({ camera: 'firstPerson' })` can still `setCamera('follow')`; you don't need to install two cameras.
|
|
17
|
+
|
|
18
|
+
## 2. What the engine does for you when switching
|
|
19
|
+
- **Target and heading carry over**: the followed character stays the same; the horizontal heading (`yaw`) is carried over, so there is no sudden turn
|
|
20
|
+
after switching. Pitch means different things for each camera and is not carried over.
|
|
21
|
+
- **First person hides the body but keeps the shadow**: the character model is moved to a dedicated layer (`hideLayer`, default 30) that the camera
|
|
22
|
+
cannot see but the shadow camera can; a model that loads later is hidden too. When you switch away the body shows again immediately.
|
|
23
|
+
- **Mouse lock**: switching to first person (a key press counts as a user gesture) locks the mouse automatically, Esc leaves; switching away releases
|
|
24
|
+
it. No lock on phones.
|
|
25
|
+
- **Field of view (fov)**: switching away returns to the value from when the camera was installed; the first-person / strategy cameras each set it
|
|
26
|
+
from their own `fov` option.
|
|
27
|
+
- **Settings are kept**: the camera you switched away from is kept, so switching back keeps the zoom distance and pitch. To use a different set of
|
|
28
|
+
parameters pass options (that camera is rebuilt with the new parameters):
|
|
29
|
+
```js
|
|
30
|
+
engine.setCamera?.('firstPerson', { height: 1.7, fov: 80 });
|
|
31
|
+
engine.setCamera?.('follow', { distance: 8, pitch: 0.3 });
|
|
32
|
+
```
|
|
33
|
+
- A wrong kind name throws and lists the valid ones; a wrong option name gets the closest name suggested in development.
|
|
34
|
+
|
|
35
|
+
## 3. Other common things
|
|
36
|
+
- **Cycling through several**:
|
|
37
|
+
`const VIEWS = ['follow', 'firstPerson', 'rts']; engine.setCamera(VIEWS[(VIEWS.indexOf(engine.cameraRig.kind) + 1) % VIEWS.length]);`
|
|
38
|
+
- **A fixed camera needs shots first**: `engine.setCamera('fixed', { shots: { hall: { position: [0, 6, 12], lookAt: [0, 0, 0] } }, start: 'hall' })`.
|
|
39
|
+
- **Camera-specific methods** exist only after switching: `engine.cameraRig.lookAt(position)` (first person), `cut('name')` (fixed shots),
|
|
40
|
+
`screenToGround(...)` (rts). Check `kind` before calling.
|
|
41
|
+
- **Teleport, then lookAt**: `await engine.stream.teleport(p); engine.cameraRig.lookAt(target);` works in that order: `lookAt` aims from the body's
|
|
42
|
+
current position, not from the last drawn frame. Call it after the move (the angles do not follow later moves).
|
|
43
|
+
- **Player movement direction follows the camera**: `engine.cameraRig.forward()` / `right()` change automatically after switching.
|
|
44
|
+
- **Cutscene takeover**: while anyone holds `engine.takeCamera(owner)` (`engine.cameraOverride` is not null) the camera module leaves the camera alone; see [the engine API](../api/engine.md).
|
|
45
|
+
- **Shooting games**: bind first-person firing to a mouse-button action, see `19-shooting-picking.md`.
|
|
46
|
+
|
|
47
|
+
## 4. Over the shoulder, lock-on framing, mouse lock (follow camera)
|
|
48
|
+
```js
|
|
49
|
+
engine.use(followCamera({ distance: 3, shoulder: 0.7, pitch: 0.15, pointerLock: true })); // shooter / action-adventure view
|
|
50
|
+
engine.cameraRig.shoulder = -0.7; // switch shoulders at any time (plain property)
|
|
51
|
+
engine.cameraRig.frame(enemy.object); // lock-on: turn to "behind the player, looking at the enemy"; frame(null) lets go
|
|
52
|
+
```
|
|
53
|
+
- **`shoulder`**: meters the aim point (and so the camera) moves to the right along `right()`; negative = left, 0 = centered (default).
|
|
54
|
+
- **`pointerLock`** (default false): a click on the canvas locks the mouse, so moving it turns the view with no dragging; Esc releases. Not on phones. If the browser refuses the lock the camera falls back to dragging; `describe().camera.pointerLock` is a state machine: `state` is `off` / `unsupported` / `waiting-click` / `requesting` / `locked` / `refused`, plus `covered` (what sits on the canvas centre and eats the click), `cameraOverride` (a takeover blocks locking) and `lastFailure { reason, agoSec }`; the text line shows the same.
|
|
55
|
+
The press that locks is swallowed (no `Mouse0`, no click) so it cannot attack or fire; `swallowLockClick: false` delivers it.
|
|
56
|
+
Leave it off when the mouse buttons are for UI or clicking the ground.
|
|
57
|
+
- **`yaw` means which side of the player the camera is on**: `camera = focus + (sin yaw, cos yaw) * distance`, so the camera looks along
|
|
58
|
+
`forward() = -(sin yaw, cos yaw)`. To make it look toward a direction, negate it; better not to compute it at all and use `frame(target)`.
|
|
59
|
+
- **`frame(target, { strength = 6 })`**: `target` is an Object3D or `{ x, z }`; call it once when the lock starts, not every frame. While framing,
|
|
60
|
+
mouse / stick yaw is ignored and a `yaw` you write directly is pulled back, because `frame()` owns the heading; `frame(null)` hands it back.
|
|
61
|
+
`forward()` turns with it, so camera-relative movement strafes around the target.
|
|
62
|
+
- Only the follow camera has `frame`, `shoulder` and `pointerLock`; check `engine.cameraRig.kind === 'follow'` after a runtime switch.
|
|
63
|
+
|
|
64
|
+
## 5. Take over the player: your own movement, facing and lock-on
|
|
65
|
+
The engine has no default here: `createPlayer` needs `control` (a preset such as `presets.player.thirdPerson` gives keys relative to the camera, Shift
|
|
66
|
+
run, Space jump, turning toward where it walks and `cameraFollow: true`). Each piece below replaces one part and keeps the rest (world record, saving,
|
|
67
|
+
`describe().player`).
|
|
68
|
+
```js
|
|
69
|
+
import { presets, pickTarget, switchTarget } from 'threedog';
|
|
70
|
+
|
|
71
|
+
// who moves the player: 'camera' (keys relative to the camera) | 'none' (you call move) | (player, input, dt) => ({ x, z, run?, speed? }) | null
|
|
72
|
+
const player = engine.characters.createPlayer({ ...presets.player.none, cameraFollow: true, runKeys: ['ShiftLeft'] }); // runKeys: moveInput().run reads it
|
|
73
|
+
engine.input.define('lockOn', ['KeyQ'], 'Lock on').define('switchTarget', ['KeyR'], 'Switch target'); // no key is bound by itself
|
|
74
|
+
let lock = null, hitStun = 0, knockX = 0, knockZ = 0;
|
|
75
|
+
const enemies = () => engine.world.query({ kind: 'enemy', near: player.position, radius: 20 });
|
|
76
|
+
|
|
77
|
+
engine.onFixed(dt => {
|
|
78
|
+
const m = engine.characters.moveInput(); // the 'camera' key direction as a value, relative to the camera (a reused object: copy x / z if you keep it)
|
|
79
|
+
if (engine.input.pressed('lockOn')) { // pick what is in view; press again to let go
|
|
80
|
+
lock = lock ? null : pickTarget(player, engine.cameraRig.forward(), enemies(), { radius: 15 });
|
|
81
|
+
engine.cameraRig.frame(lock ? engine.world.view(lock.id) : null);
|
|
82
|
+
}
|
|
83
|
+
if (lock && engine.input.pressed('switchTarget')) lock = switchTarget(player, engine.cameraRig.forward(), lock, enemies(), 1) ?? lock;
|
|
84
|
+
player.faceMode = lock ? 'target' : 'move'; // 'move' toward velocity | 'camera' along the camera | 'target' toward faceTarget | 'manual' only face() turns it
|
|
85
|
+
player.faceTarget = lock ? engine.world.view(lock.id) : null;
|
|
86
|
+
if (hitStun > 0) { hitStun -= dt; player.push(knockX, knockZ, dt); player.move(0, 0, false, dt); } // knockback / roll: fixed velocity, never turns
|
|
87
|
+
else player.move(m.x, m.z, m.run, dt); // with control 'none' you must call move() once per fixed step
|
|
88
|
+
});
|
|
89
|
+
```
|
|
90
|
+
- **`control: 'none'`**: the engine never calls `move()` or reads the movement keys for the player. A `function` keeps jump and vehicles and only
|
|
91
|
+
replaces direction and speed (a side-scroller returns `{ x: input.axis.x, z: 0 }`); to wrap the camera-relative keys use
|
|
92
|
+
`control: (p, input) => busy ? null : engine.characters.moveInput()`. `player.control` can be changed at any time. Leaving `control` out throws
|
|
93
|
+
`[player-control]`.
|
|
94
|
+
- **`cameraFollow: true`** points the camera module at the player (again after a vehicle and on a new session); without it the camera stays where the
|
|
95
|
+
game puts it (`engine.cameraRig.follow(obj)`), and dev builds warn once if a camera is installed and the option was left out.
|
|
96
|
+
- **`faceMode`** is a plain property of every Character (NPCs too), change it per state. `player.face(angle)` turns at once (0 = +Z, PI / 2 = +X),
|
|
97
|
+
`face(target)` toward a point; with `'manual'` that is the only thing that turns it.
|
|
98
|
+
- **`push(vx, vz, seconds)`** moves at a fixed velocity for that long, ignoring the direction given to `move()`; gravity and collision still apply.
|
|
99
|
+
When you push again every fixed step, pass `dt`.
|
|
100
|
+
- **`pickTarget` / `switchTarget`** are pure functions: they return the candidate itself (anything with a `position`) or null. The game keeps the
|
|
101
|
+
current target and its own rules, such as "let go beyond 20 m" or "target died, pick the next".
|
|
102
|
+
- The engine already calls `player.animate(dt)` every frame; a module with its own loop over characters must skip the player, or the walk cycle runs
|
|
103
|
+
twice as fast.
|
|
104
|
+
- Test without a keyboard: `engine.input.simulate('lockOn'); engine.step(1 / 60); engine.input.simulate('lockOn', false)`.
|
|
105
|
+
|
|
106
|
+
## 6. Orthographic view, and taking the camera over yourself
|
|
107
|
+
|
|
108
|
+
**Orthographic (isometric / 2.5D) with the built-in rigs.** `projection: 'orthographic'` plus `size` (world units of view height) on the fixed and follow cameras.
|
|
109
|
+
The default stays perspective. On resize the view height stays `size` and the width follows the aspect.
|
|
110
|
+
|
|
111
|
+
```js
|
|
112
|
+
// one fixed isometric shot (shorthand for a single shot named 'main')
|
|
113
|
+
engine.setCamera('fixed', { position: [14, 14, 14], lookAt: [0, 0, 0], projection: 'orthographic', size: 16 });
|
|
114
|
+
// per shot: shots: { hall: { position, lookAt, projection: 'orthographic', size: 12 }, yard: { position, lookAt } } // yard stays perspective
|
|
115
|
+
// follow the player from a fixed angle
|
|
116
|
+
engine.setCamera('follow', { pitch: 0.6, yaw: 0.8, distance: 20, projection: 'orthographic', size: 14 });
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
- `engine.camera` stays the one object everything holds (render, post, shadows, sky); it is flipped to an orthographic matrix, so `camera.isOrthographicCamera`
|
|
120
|
+
is true, `camera.left/right/top/bottom` are set, and `camera.zoom` still zooms. `camera.fov` is ignored while it is on.
|
|
121
|
+
- Blends between two orthographic shots blend `size`; a perspective/orthographic mix switches to the target's mode at once. Switching rig kinds returns to perspective.
|
|
122
|
+
- Limits: on the follow camera the mouse wheel changes `size` (clamped to the `minDistance`/`maxDistance` ratio of the starting `distance`).
|
|
123
|
+
The `fov` slider in the settings menu has no effect. Cascaded shadows, `dof` and `outline` handle orthographic depth; a custom post pass that assumes perspective depth must do the same.
|
|
124
|
+
|
|
125
|
+
**Placing the camera yourself (cutscene, photo mode, your own rig).** Take it with `engine.takeCamera(owner, { focus })`; the camera module leaves the camera alone until you `remove()` the handle.
|
|
126
|
+
Several holders can take it (a cutscene, then a named view on top): the latest is in charge, and removing it hands the camera back to the previous one, not to nobody.
|
|
127
|
+
|
|
128
|
+
```js
|
|
129
|
+
let t = 0;
|
|
130
|
+
const cam = engine.takeCamera('my-orbit', { focus: engine.player.position }); // focus (optional): where the world loads around
|
|
131
|
+
const frame = engine.onFrame(dt => {
|
|
132
|
+
t += dt; engine.camera.position.set(Math.cos(t) * 12, 8, Math.sin(t) * 12); engine.camera.lookAt(0, 1, 0);
|
|
133
|
+
});
|
|
134
|
+
// done: frame.remove(); cam.remove(); // the rig resumes from its own state
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
To use your own `THREE.OrthographicCamera` instead of flipping `engine.camera`:
|
|
138
|
+
|
|
139
|
+
```js
|
|
140
|
+
const original = engine.camera, size = 12;
|
|
141
|
+
const ortho = new THREE.OrthographicCamera(-1, 1, 1, -1, 0.1, 500);
|
|
142
|
+
function fit() { // the engine only updates engine.camera.aspect on resize, so keep your own camera's aspect here
|
|
143
|
+
const s = engine.renderer.getSize(new THREE.Vector2()), a = s.x / s.y;
|
|
144
|
+
ortho.left = -size * a / 2; ortho.right = size * a / 2; ortho.top = size / 2; ortho.bottom = -size / 2; ortho.updateProjectionMatrix();
|
|
145
|
+
}
|
|
146
|
+
const cam = engine.takeCamera('my-ortho');
|
|
147
|
+
engine.camera = ortho; // the plain render path, cascaded shadows and modules read engine.camera live
|
|
148
|
+
ortho.position.set(10, 10, 10); ortho.lookAt(0, 0, 0); fit(); addEventListener('resize', fit);
|
|
149
|
+
// give it back: removeEventListener('resize', fit); engine.camera = original; cam.remove();
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
Swapping the object only works while no post effect is active: the post chain's scene pass keeps the camera it was built with. With post effects, use
|
|
153
|
+
`projection: 'orthographic'` above instead.
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# Shop and gold: buy, sell / consign, gold HUD, saving
|
|
2
|
+
|
|
3
|
+
Requires modules `inventory({ ...presets.keys.inventory })` + `dialogue()` + `content()` (the gold HUD needs `hud()`). The engine has no "shop"
|
|
4
|
+
module: gold is an ordinary item, a shelf is an ordinary container, and buying and selling are two small ops that dialogue choices (or your own shop
|
|
5
|
+
window) run.
|
|
6
|
+
|
|
7
|
+
## 1. Where to keep gold (pick one)
|
|
8
|
+
| Form | Fits | Trade-off |
|
|
9
|
+
|---|---|---|
|
|
10
|
+
| **A. An item `gold` (recommended)** | Most games | `has / take / give` in content work directly; dialogue choice `if`, quest rewards, pickups and chests all understand it; saved with the inventory; **write `stack: 99999`** so it stays in one slot (by default 99 per slot; more spill into further slots, which only matters when the bag has a `capacity`) |
|
|
11
|
+
| B. A counter in `engine.vars` | Very large amounts, no slot wanted, must not be stolen / dropped | `vars.bump('gold', 50)` adds, `vars.counter('gold')` reads, saved with the game; the content `counter` condition can check "enough?", but the content `bump` effect only does +1, so charge money inside an op (`vars.bump('gold', -5)` in its `run`); it cannot be `transfer`red and does not appear in the inventory window |
|
|
12
|
+
|
|
13
|
+
The rest is written for A.
|
|
14
|
+
|
|
15
|
+
## 2. Data
|
|
16
|
+
`content/items.js`:
|
|
17
|
+
```js
|
|
18
|
+
export default {
|
|
19
|
+
gold: { name: '金币', icon: '🪙', stack: 99999 }, // currency: one slot however much
|
|
20
|
+
bread: { name: '面包', icon: '🍞', price: 5 }, // price: read by the shop ops below
|
|
21
|
+
};
|
|
22
|
+
export const startItems = { gold: 12 };
|
|
23
|
+
```
|
|
24
|
+
`content/containers.js` (the shelf. `items` is the initial stock, placed only the first time; a shelf that was emptied by looting / selling stays
|
|
25
|
+
empty after loading, see recipe 03):
|
|
26
|
+
```js
|
|
27
|
+
export default { 'shop-bakery': { capacity: 6, items: { bread: 3 } } };
|
|
28
|
+
```
|
|
29
|
+
Import it in `content/index.js` and put it in the exported object (`containers`).
|
|
30
|
+
|
|
31
|
+
## 3. Buy, sell / consign (two ops + dialogue choices)
|
|
32
|
+
Buying and selling are things the player decides to do, so they are ops (`recipes/23-ops.md`): define them once in `main.js`, and every caller
|
|
33
|
+
(dialogue choice, a shop window button, the dev bridge, a test) runs the same `can` / `run`. **Buy** is allowed only when the shelf has stock and the
|
|
34
|
+
player has the money; `transfer` returns how many actually moved, and money is charged only for those (a full inventory does not charge for nothing).
|
|
35
|
+
**Consign**: the player puts something on the shelf, and the shelf pays when it accepts it.
|
|
36
|
+
```js
|
|
37
|
+
// main.js (after engine.use(...inventory({ ...presets.keys.inventory })...))
|
|
38
|
+
const price = (e, item) => e.inventory.item(item).price ?? 1;
|
|
39
|
+
engine.ops.define('shop.buy', {
|
|
40
|
+
args: { shop: 'string', item: 'string' },
|
|
41
|
+
can(e, { shop, item }, ctx) {
|
|
42
|
+
if (!e.inventory.container(shop).has(item)) return 'soldOut';
|
|
43
|
+
if (!e.inventory.container(ctx.actor).has('gold', price(e, item))) return 'noMoney';
|
|
44
|
+
return true;
|
|
45
|
+
},
|
|
46
|
+
run(e, { shop, item }, ctx) {
|
|
47
|
+
const got = e.inventory.transfer(shop, ctx.actor, item, 1);
|
|
48
|
+
e.inventory.container(ctx.actor).remove('gold', price(e, item) * got);
|
|
49
|
+
return got;
|
|
50
|
+
},
|
|
51
|
+
reasons: { soldOut: 'Shelf is empty', noMoney: 'Not enough gold' },
|
|
52
|
+
});
|
|
53
|
+
engine.ops.define('shop.sell', {
|
|
54
|
+
args: { shop: 'string', item: 'string' },
|
|
55
|
+
can: (e, { item }, ctx) => e.inventory.container(ctx.actor).has(item) || 'notInBag',
|
|
56
|
+
run(e, { shop, item }, ctx) {
|
|
57
|
+
const got = e.inventory.transfer(ctx.actor, shop, item, 1);
|
|
58
|
+
e.inventory.container(ctx.actor).add('gold', Math.floor(price(e, item) * 0.6) * got, { silent: true });
|
|
59
|
+
return got;
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
```
|
|
63
|
+
In the dialogue, `if: { can: [...] }` shows a choice only when the op would succeed, and `do: { op: [...] }` runs it:
|
|
64
|
+
```js
|
|
65
|
+
// content/dialogues.js
|
|
66
|
+
const buyBread = ['shop.buy', { shop: 'shop-bakery', item: 'bread' }];
|
|
67
|
+
const sellBread = ['shop.sell', { shop: 'shop-bakery', item: 'bread' }];
|
|
68
|
+
export default {
|
|
69
|
+
baker: {
|
|
70
|
+
speaker: '面包师',
|
|
71
|
+
nodes: {
|
|
72
|
+
start: {
|
|
73
|
+
text: '要点什么?',
|
|
74
|
+
choices: [
|
|
75
|
+
{ text: '买面包(5 金币)', next: 'start', if: { can: buyBread }, do: { op: buyBread } },
|
|
76
|
+
{ text: '寄卖面包(3 金币)', next: 'start', if: { can: sellBread }, do: { op: sellBread } },
|
|
77
|
+
{ text: '再见', next: 'end' },
|
|
78
|
+
],
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
```
|
|
84
|
+
- The shelf id (`'shop-bakery'`) is any string, and the shelf contents are saved. A "shop window" is your own UI drawn from `shelf.list()`; its
|
|
85
|
+
buttons call `engine.ops.run('shop.buy', { shop, item })` and grey out with `engine.ops.can(...)`.
|
|
86
|
+
- Prices live on the item (`price` in items.js above), read with `e.inventory.item('bread').price`; an item without one costs 1 here.
|
|
87
|
+
- Items with their own data (a used sword with `durability`, recipe 03): pass the entry key as `item` (`'sword#3'`, from `shelf.list()[i].key`);
|
|
88
|
+
`transfer` moves exactly that piece with its data, and `e.inventory.container(shop).get(item)` reads the data for a price
|
|
89
|
+
(`def.price * data.durability / 100`).
|
|
90
|
+
- Show a failure reason to the player through your own i18n string (`e.t('shop.' + r.reason)`); the engine shows nothing itself.
|
|
91
|
+
- `npx threedog ops` lists what can be bought right now if you add `offers` (see recipe 23); `npx threedog op shop.buy shop=shop-bakery item=bread`
|
|
92
|
+
buys from the terminal.
|
|
93
|
+
|
|
94
|
+
## 4. Gold HUD
|
|
95
|
+
Calling `hud.counter` again with the same id = update, and it leaves the DOM alone when the value is unchanged, so calling it every frame is cheap:
|
|
96
|
+
```js
|
|
97
|
+
engine.onFrame(() => engine.hud.counter('gold', { icon: '🪙', label: '金币', value: engine.inventory.count('gold') }));
|
|
98
|
+
```
|
|
99
|
+
Loading a save replaces the whole inventory, and refreshing every frame follows naturally; no event listener is needed.
|
|
100
|
+
|
|
101
|
+
## 5. Saving
|
|
102
|
+
The inventory (gold included) and every container with contents are saved automatically; a shelf that was sold out is remembered too (`{}`), and
|
|
103
|
+
loading does not restock it. You write nothing.
|
|
104
|
+
|
|
105
|
+
## 6. Verification
|
|
106
|
+
The "shop" case in `tests/specs/containers.mjs` runs the whole flow: buy -> consign -> choice disappears when money is short -> save -> refresh and
|
|
107
|
+
load, with the shelf and gold consistent.
|