threedog 0.7.0 → 1.0.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 +411 -1
- package/README.md +8 -11
- package/core/{Animator.js → assets/Animator.js} +30 -18
- package/core/{Assets.js → assets/Assets.js} +131 -56
- package/core/{Baked.js → assets/Baked.js} +4 -4
- package/core/assets/assetEntry.js +302 -0
- package/core/{assetHot.js → assets/assetHot.js} +9 -7
- package/core/{assetLoad.js → assets/assetLoad.js} +55 -16
- package/core/assets/assetLod.js +113 -0
- package/core/{assetManifest.js → assets/assetManifest.js} +19 -11
- package/core/{assetReport.js → assets/assetReport.js} +7 -14
- package/core/{namedModel.js → assets/namedModel.js} +17 -13
- package/core/{Audio.js → audio/Audio.js} +47 -25
- package/core/{audioRules.js → audio/audioRules.js} +8 -5
- package/core/{audioVoice.js → audio/audioVoice.js} +17 -30
- package/core/{Events.js → base/Events.js} +3 -3
- package/core/{I18n.js → base/I18n.js} +15 -12
- package/core/{Random.js → base/Random.js} +7 -4
- package/core/{Vars.js → base/Vars.js} +14 -4
- package/core/{easing.js → base/easing.js} +1 -1
- package/core/{errorCodes.js → base/errorCodes.js} +151 -125
- package/core/{errorHints.js → base/errorHints.js} +17 -10
- package/core/{errors.js → base/errors.js} +12 -10
- package/core/{events.generated.js → base/events.generated.js} +11 -0
- package/core/base/follows.js +26 -0
- package/core/base/math.js +66 -0
- package/core/{params.js → base/params.js} +5 -6
- package/core/base/saveValues.js +81 -0
- package/core/base/sections.js +97 -0
- package/core/base/spelling.js +32 -0
- package/core/base/util.js +32 -0
- package/core/{validate.js → base/validate.js} +34 -34
- package/core/{Engine.js → engine/Engine.js} +137 -91
- package/core/{Loading.js → engine/Loading.js} +34 -5
- package/core/{copies.js → engine/copies.js} +4 -4
- package/core/{headlessLoad.js → engine/headlessLoad.js} +32 -15
- package/core/{lifecycle.js → engine/lifecycle.js} +41 -34
- package/core/{loop.js → engine/loop.js} +88 -49
- package/core/engine/moduleSlots.js +176 -0
- package/core/{moduleTypes.js → engine/moduleTypes.js} +26 -14
- package/core/engine/modules.js +503 -0
- package/core/{page.js → engine/page.js} +59 -29
- package/core/{plugins.js → engine/plugins.js} +21 -12
- package/core/{services.js → engine/services.js} +50 -40
- package/core/{startup.js → engine/startup.js} +66 -54
- package/core/{Input.js → input/Input.js} +67 -39
- package/core/{inputContext.js → input/inputContext.js} +14 -5
- package/core/input/inputKeyboard.js +39 -0
- package/core/{inputPad.js → input/inputPad.js} +24 -3
- package/core/{inputPointer.js → input/inputPointer.js} +11 -3
- package/core/input/inputSeat.js +66 -0
- package/core/{inputTouch.js → input/inputTouch.js} +24 -7
- package/core/{Budget.js → inspect/Budget.js} +21 -20
- package/core/{DebugOverrides.js → inspect/DebugOverrides.js} +43 -18
- package/core/{Describe.js → inspect/Describe.js} +34 -26
- package/core/{Inspect.js → inspect/Inspect.js} +39 -10
- package/core/{InspectMaterials.js → inspect/InspectMaterials.js} +7 -8
- package/core/{InspectPerf.js → inspect/InspectPerf.js} +19 -13
- package/core/{InspectScene.js → inspect/InspectScene.js} +8 -5
- package/core/{MaterialInfo.js → inspect/MaterialInfo.js} +3 -2
- package/core/{UrlState.js → inspect/UrlState.js} +60 -24
- package/core/{catalog.js → inspect/catalog.js} +15 -8
- package/core/{checks.js → inspect/checks.js} +7 -5
- package/core/{debugView.js → inspect/debugView.js} +4 -4
- package/core/{describeRender.js → inspect/describeRender.js} +24 -22
- package/core/{describeText.js → inspect/describeText.js} +17 -8
- package/core/inspect/geometryWatch.js +38 -0
- package/core/{lightWatch.js → inspect/lightWatch.js} +8 -8
- package/core/inspect/metadata.generated.js +4140 -0
- package/core/{pictureWriters.js → inspect/pictureWriters.js} +130 -47
- package/core/{shaderCost.js → inspect/shaderCost.js} +1 -1
- package/core/inspect/toolDoor.js +21 -0
- package/core/inspect/valueHistory.js +35 -0
- package/core/{Ops.js → ops/Ops.js} +44 -14
- package/core/{control.js → ops/control.js} +57 -31
- package/core/ops/holds.js +140 -0
- package/core/{opsAtomic.js → ops/opsAtomic.js} +18 -5
- package/core/{opsCheck.js → ops/opsCheck.js} +11 -10
- package/core/{opsFail.js → ops/opsFail.js} +5 -7
- package/core/{opsGuard.js → ops/opsGuard.js} +3 -3
- package/core/{opsRun.js → ops/opsRun.js} +9 -6
- package/core/{owned.js → ops/owned.js} +33 -19
- package/core/{sharedPoint.js → ops/sharedPoint.js} +13 -16
- package/core/{stackFrames.js → ops/stackFrames.js} +2 -2
- package/core/{stacks.js → ops/stacks.js} +34 -15
- package/core/{wrap.js → ops/wrap.js} +8 -6
- package/core/{SaveStore.js → saves/SaveStore.js} +53 -27
- package/core/{Saves.js → saves/Saves.js} +171 -54
- package/core/saves/saveApply.js +312 -0
- package/core/{saveFiles.js → saves/saveFiles.js} +45 -38
- package/core/{saveVersions.js → saves/saveVersions.js} +24 -23
- package/core/saves/session.js +231 -0
- package/core/saves/stateReplace.js +184 -0
- package/core/{Rays.js → scene/Rays.js} +44 -30
- package/core/{Views.js → scene/Views.js} +16 -8
- package/core/{adaptive.js → scene/adaptive.js} +19 -9
- package/core/{canvasBox.js → scene/canvasBox.js} +4 -3
- package/core/scene/compositeGround.js +72 -0
- package/core/scene/floor.js +17 -0
- package/core/{gameLights.js → scene/gameLights.js} +17 -7
- package/core/{grayMap.js → scene/grayMap.js} +8 -2
- package/core/{grid.js → scene/grid.js} +6 -4
- package/core/{gridLoad.js → scene/gridLoad.js} +1 -1
- package/core/scene/ground.contract.js +14 -0
- package/core/scene/ground.js +139 -0
- package/core/{movement.js → scene/movement.js} +3 -3
- package/core/{pictureSlots.js → scene/pictureSlots.js} +2 -2
- package/core/scene/pixel.js +154 -0
- package/core/scene/pixelRatio.js +167 -0
- package/core/{sceneDelta.js → scene/sceneDelta.js} +5 -5
- package/core/{sceneMethods.js → scene/sceneMethods.js} +43 -15
- package/core/scene/stepPoses.js +60 -0
- package/core/{targeting.js → scene/targeting.js} +4 -5
- package/core/{thingExplain.js → scene/thingExplain.js} +7 -6
- package/core/{thingOps.js → scene/thingOps.js} +25 -16
- package/core/{things.js → scene/things.js} +18 -5
- package/core/{threePatches.js → scene/threePatches.js} +1 -1
- package/core/{tier.js → scene/tier.js} +10 -0
- package/core/scene/view.js +161 -0
- package/core/{Batching.js → stream/Batching.js} +85 -28
- package/core/{Stream.js → stream/Stream.js} +80 -38
- package/core/{batchGroups.js → stream/batchGroups.js} +11 -9
- package/core/{chunkStream.js → stream/chunkStream.js} +40 -0
- package/core/{scatter.js → stream/scatter.js} +7 -4
- package/core/{streamSources.js → stream/streamSources.js} +14 -8
- package/core/{Commits.js → threads/Commits.js} +17 -11
- package/core/{Jobs.js → threads/Jobs.js} +25 -13
- package/core/{Threads.js → threads/Threads.js} +21 -18
- package/core/{threadPure.js → threads/threadPure.js} +7 -5
- package/core/{threadServe.js → threads/threadServe.js} +3 -3
- package/core/{Clock.js → time/Clock.js} +20 -11
- package/core/{dayTime.js → time/dayTime.js} +5 -1
- package/core/{skip.js → time/skip.js} +28 -21
- package/core/{time.js → time/time.js} +32 -20
- package/core/{uiClock.js → time/uiClock.js} +4 -4
- package/docs/AI.md +92 -72
- package/docs/API.md +33 -28
- package/docs/CODEMAP.md +121 -200
- package/docs/COMMANDS.md +77 -70
- package/docs/CONVENTIONS.md +167 -24
- package/docs/MIGRATING-0.8.md +171 -0
- package/docs/MIGRATING-1.0.md +101 -0
- package/docs/THREE.md +140 -38
- package/docs/api/assets.md +12 -13
- package/docs/api/audio.md +6 -5
- package/docs/api/budget.md +4 -4
- package/docs/api/calendar.md +10 -11
- package/docs/api/cameraRig.md +32 -29
- package/docs/api/characters.md +35 -24
- package/docs/api/clock.md +1 -1
- package/docs/api/collider3d.md +9 -0
- package/docs/api/collision.md +12 -9
- package/docs/api/content.md +18 -17
- package/docs/api/dialogue.md +5 -4
- package/docs/api/engine.md +58 -54
- package/docs/api/events.md +17 -6
- package/docs/api/flow.md +1 -1
- package/docs/api/grids.md +1 -1
- package/docs/api/ground.md +6 -7
- package/docs/api/hud.md +2 -2
- package/docs/api/i18n.md +6 -6
- package/docs/api/input.md +9 -8
- package/docs/api/interactions.md +5 -5
- package/docs/api/inventory.md +10 -10
- package/docs/api/jobs.md +5 -5
- package/docs/api/level.md +10 -9
- package/docs/api/lightPool.md +1 -6
- package/docs/api/music.md +3 -3
- package/docs/api/nav.md +14 -12
- package/docs/api/openWorld.md +1 -1
- package/docs/api/particles.md +10 -7
- package/docs/api/photo.md +4 -2
- package/docs/api/pickups.md +3 -3
- package/docs/api/post.md +21 -5
- package/docs/api/quests.md +7 -5
- package/docs/api/rays.md +7 -7
- package/docs/api/rigid.md +29 -19
- package/docs/api/saves.md +13 -11
- package/docs/api/settings.md +9 -8
- package/docs/api/sky.md +8 -7
- package/docs/api/stream.md +8 -9
- package/docs/api/swarm.md +34 -0
- package/docs/api/terrain.md +6 -8
- package/docs/api/terrainDraw.md +2 -2
- package/docs/api/timeline.md +4 -4
- package/docs/api/tools.md +27 -22
- package/docs/api/triggers.md +2 -0
- package/docs/api/vars.md +1 -1
- package/docs/api/vegetation.md +4 -3
- package/docs/api/vegetationDraw.md +2 -2
- package/docs/api/water.md +7 -3
- package/docs/api/weather.md +27 -12
- package/docs/api/weatherDraw.md +4 -4
- package/docs/api/world.md +6 -6
- package/docs/recipes/01-new-game.md +28 -43
- package/docs/recipes/02-npc.md +21 -23
- package/docs/recipes/03-items-pickups.md +37 -53
- package/docs/recipes/04-quests.md +5 -4
- package/docs/recipes/05-props-bake.md +34 -44
- package/docs/recipes/06-clock-events.md +31 -22
- package/docs/recipes/07-flow-scenes-pause.md +30 -32
- package/docs/recipes/08-weather-sky.md +91 -37
- package/docs/recipes/09-materials-lights-models.md +25 -39
- package/docs/recipes/10-blender-level.md +22 -11
- package/docs/recipes/11-vehicles.md +44 -24
- package/docs/recipes/12-navmesh.md +60 -15
- package/docs/recipes/13-animation.md +70 -22
- package/docs/recipes/14-custom-module.md +33 -20
- package/docs/recipes/15-perf.md +51 -28
- package/docs/recipes/16-dev-bridge.md +39 -58
- package/docs/recipes/18-world.md +49 -28
- package/docs/recipes/19-shooting-picking.md +7 -4
- package/docs/recipes/20-content-actions-save.md +55 -40
- package/docs/recipes/21-camera.md +47 -25
- package/docs/recipes/22-shop-gold.md +21 -16
- package/docs/recipes/23-ops.md +28 -24
- package/docs/recipes/26-ui-parts.md +25 -14
- package/docs/recipes/27-net.md +3 -5
- package/docs/recipes/28-terrain.md +119 -23
- package/docs/recipes/29-grid.md +3 -3
- package/docs/recipes/30-templates.md +63 -30
- package/docs/recipes/31-audio.md +7 -7
- package/docs/recipes/32-action-game.md +21 -11
- package/docs/recipes/33-stream-sources.md +6 -3
- package/docs/recipes/34-environment-lighting.md +72 -25
- package/docs/recipes/35-picture-from-reference.md +20 -23
- package/docs/recipes/36-ground-plants.md +106 -0
- package/docs/recipes/40-scene.md +18 -21
- package/docs/recipes/43-shader-patches-surfaces.md +27 -48
- package/docs/recipes/44-water-weather-hooks.md +56 -50
- package/docs/recipes/45-cascaded-shadows.md +41 -20
- package/docs/recipes/46-blender-art-route.md +9 -10
- package/docs/recipes/49-game-module-contract.md +7 -6
- package/docs/recipes/50-own-renderer.md +3 -2
- package/docs/recipes/51-capability-catalog.md +14 -8
- package/docs/recipes/52-around-the-picture.md +56 -100
- package/docs/recipes/53-ground-up-close.md +61 -24
- package/docs/recipes/55-mods-time-wrap.md +17 -20
- package/docs/recipes/56-webgpu-tsl.md +28 -15
- package/docs/recipes/57-control.md +39 -12
- package/docs/recipes/58-input.md +15 -2
- package/docs/recipes/59-depth-post-effects.md +1 -1
- package/docs/recipes/60-judge-the-picture.md +30 -25
- package/docs/recipes/62-picture-code.md +129 -39
- package/docs/recipes/63-third-person-start.md +19 -5
- package/docs/recipes/64-particles.md +54 -5
- package/docs/recipes/65-swarm.md +140 -0
- package/docs/recipes/66-common-tasks.md +313 -0
- package/examples/action/.threedog/content-index.json +1 -1
- package/examples/action/GAMEMAP.md +5 -5
- package/examples/perf-island/.threedog/content-index.json +1 -0
- package/examples/{sheepisland → perf-island}/GAMEMAP.md +15 -14
- package/examples/{sheepisland → perf-island}/assets.js +1 -1
- package/examples/{sheepisland → perf-island}/main.js +8 -8
- package/examples/{sheepisland → perf-island}/models.js +1 -1
- package/examples/{sheepisland → perf-island}/params.js +1 -1
- package/examples/{sheepisland → perf-island}/picture/index.js +1 -1
- package/examples/{sheepisland → perf-island}/picture/palette.js +2 -2
- package/examples/{sheepisland → perf-island}/views.js +1 -1
- package/examples/plain-picture/GAMEMAP.md +4 -1
- package/examples/rc2d/GAMEMAP.md +4 -3
- package/examples/rc2d/main.js +1 -3
- package/examples/rc2d/rc2d.js +1 -1
- package/examples/styletest/.threedog/content-index.json +1 -1
- package/examples/styletest/GAMEMAP.md +6 -5
- package/examples/techniques/contact-shadows/contactShadows.js +1 -1
- package/examples/techniques/contact-shadows/main.js +1 -1
- package/examples/techniques/interior-light/main.js +1 -1
- package/examples/techniques/modular-building/README.md +7 -6
- package/examples/techniques/outlines-and-rim/picture/post.js +1 -1
- package/examples/techniques/procedural-animation/README.md +1 -1
- package/examples/webgpu-tsl/GAMEMAP.md +2 -1
- package/examples/world/.threedog/content-index.json +1 -1
- package/examples/world/GAMEMAP.md +9 -7
- package/examples/world/main.js +3 -3
- package/examples/world/picture/sky.js +1 -1
- package/index.d.ts +16 -12
- package/index.js +53 -32
- package/llms.txt +11 -14
- package/modules/ambience/Ambience.js +16 -11
- package/modules/calendar/Calendar.js +19 -19
- package/modules/calendar/index.js +18 -16
- package/modules/calendar/schedule.js +11 -6
- package/modules/calendar/seasons.js +7 -7
- package/modules/camera/FirstPersonCamera.js +5 -5
- package/modules/camera/FixedCamera.js +43 -30
- package/modules/camera/FollowCamera.js +24 -15
- package/modules/camera/RtsCamera.js +12 -11
- package/modules/camera/common.js +72 -37
- package/modules/camera/contract.js +1 -0
- package/modules/camera/pixelSnap.js +62 -0
- package/modules/characters/Character.js +166 -70
- package/modules/characters/NPC.js +84 -44
- package/modules/characters/assetModel.js +16 -12
- package/modules/characters/astar.js +48 -27
- package/modules/characters/behaviors.js +4 -5
- package/modules/characters/character.contract.js +21 -0
- package/modules/characters/contract.js +17 -3
- package/modules/characters/index.js +240 -226
- package/modules/characters/moveHelpers.js +88 -12
- package/modules/characters/mover.contract.js +14 -0
- package/modules/characters/movers/common.js +22 -18
- package/modules/characters/movers/manual.js +1 -1
- package/modules/characters/movers/rapier.js +18 -10
- package/modules/characters/movers/simple.js +26 -13
- package/modules/characters/movers/support.js +24 -13
- package/modules/characters/npcAvoid.js +19 -16
- package/modules/characters/npcSim.js +88 -32
- package/modules/characters/npcView.js +19 -11
- package/modules/characters/pathAsync.js +81 -29
- package/modules/characters/pathJob.js +38 -21
- package/modules/characters/pathWorker.js +1 -1
- package/modules/characters/player.js +120 -0
- package/modules/characters/playerStrings.js +2 -2
- package/modules/characters/proceduralRig.js +2 -2
- package/modules/characters/seat.js +56 -0
- package/modules/characters/useModel.js +3 -3
- package/modules/characters/vehicle.contract.js +8 -5
- package/modules/characters/walkTo.js +40 -33
- package/modules/collision/Collision.js +69 -45
- package/modules/collision/contract.js +15 -0
- package/modules/collision/grid.js +6 -1
- package/modules/content/explain.js +2 -3
- package/modules/content/fields.js +24 -3
- package/modules/content/ids.js +5 -3
- package/modules/content/index.js +132 -114
- package/modules/content/loader.js +117 -140
- package/modules/content/markers.js +25 -0
- package/modules/content/models.js +54 -17
- package/modules/content/packs.js +5 -4
- package/modules/content/parts.js +2 -2
- package/modules/content/places.js +36 -0
- package/modules/content/props.js +22 -17
- package/modules/content/rules.js +47 -61
- package/modules/content/stages.js +7 -7
- package/modules/content/templates.js +80 -49
- package/modules/content/words.js +47 -0
- package/modules/debug/DebugPanel.js +14 -45
- package/modules/flow/contract.js +2 -1
- package/modules/flow/index.js +30 -16
- package/modules/gameplay/Container.js +17 -13
- package/modules/gameplay/Containers.js +23 -6
- package/modules/gameplay/Dialogue.js +93 -34
- package/modules/gameplay/Interactions.js +93 -51
- package/modules/gameplay/Inventory.js +64 -22
- package/modules/gameplay/Quests.js +146 -30
- package/modules/gameplay/boxOps.js +8 -1
- package/modules/gameplay/dialogueBubbles.js +16 -12
- package/modules/gameplay/inventoryOps.js +11 -8
- package/modules/gameplay/pickups.js +63 -37
- package/modules/gameplay/questLog.js +4 -2
- package/modules/gameplay/questSave.js +9 -4
- package/modules/gameplay/quests.contract.js +1 -1
- package/modules/grid/Grid.js +2 -2
- package/modules/grid/Layer.js +12 -8
- package/modules/grid/index.js +28 -23
- package/modules/grid/ops.js +43 -46
- package/modules/grid/preview.js +7 -7
- package/modules/grid/tiles.js +6 -6
- package/modules/hlod/index.js +42 -57
- package/modules/hud/index.js +22 -14
- package/modules/hud/parts.js +8 -8
- package/modules/level/contract.js +16 -0
- package/modules/level/heightfield.js +29 -31
- package/modules/level/index.js +113 -161
- package/modules/level/load.js +196 -0
- package/modules/level/meshes.js +65 -0
- package/modules/level/nodes.js +40 -23
- package/modules/lights/index.js +33 -183
- package/modules/lights/slots.js +93 -0
- package/modules/lights/sources.js +90 -0
- package/modules/music/Music.js +34 -28
- package/modules/music/rules.js +1 -1
- package/modules/nav/contract.js +16 -0
- package/modules/nav/index.js +180 -49
- package/modules/nav/navPath.js +45 -10
- package/modules/net/Client.js +7 -7
- package/modules/net/Host.js +7 -7
- package/modules/net/Net.js +1 -1
- package/modules/net/index.js +6 -5
- package/modules/net/sync.js +2 -2
- package/modules/net/transports.js +2 -2
- package/modules/particles/Particles.js +95 -29
- package/modules/particles/effect.js +86 -32
- package/modules/particles/shaders.js +19 -1
- package/modules/photo/Photo.js +23 -23
- package/modules/rigid/RigidBodies.js +255 -89
- package/modules/rigid/Vehicles.js +17 -8
- package/modules/rigid/collider3d.contract.js +26 -0
- package/modules/rigid/ragdoll.js +298 -0
- package/modules/rigid/ragdollBones.js +209 -0
- package/modules/rigid/refresh.js +10 -0
- package/modules/rigid/sync.js +51 -20
- package/modules/settings/Settings.js +177 -61
- package/modules/settings/apply.js +20 -13
- package/modules/settings/sections.js +19 -14
- package/modules/settings/strings.js +2 -2
- package/modules/settings/view.js +3 -3
- package/modules/sky/Sky.js +29 -22
- package/modules/sky/clouds.js +7 -7
- package/modules/sky/dome.js +33 -20
- package/modules/sky/domeLayers.js +9 -9
- package/modules/sky/environment.js +6 -6
- package/modules/sky/frame.js +19 -10
- package/modules/sky/season.js +7 -1
- package/modules/sky/shader.js +24 -25
- package/modules/sky/skyModule.js +17 -28
- package/modules/sky/tint.js +1 -1
- package/modules/swarm/Swarm.js +356 -0
- package/modules/swarm/draw.js +68 -0
- package/modules/swarm/grid.js +63 -0
- package/modules/terrain/ChunkManager.js +71 -59
- package/modules/terrain/chunkQueries.js +7 -24
- package/modules/terrain/chunkWorker.js +1 -1
- package/modules/terrain/draw.js +14 -11
- package/modules/terrain/index.js +42 -42
- package/modules/terrain/terrainColorMap.js +6 -3
- package/modules/terrain/terrainDefaults.js +2 -1
- package/modules/terrain/terrainEdit.js +45 -29
- package/modules/terrain/terrainGen.js +19 -12
- package/modules/terrain/terrainIsland.js +2 -2
- package/modules/terrain/terrainMesh.js +7 -6
- package/modules/terrain/terrainShape.js +8 -10
- package/modules/terrain/terrainShapeMain.js +3 -3
- package/modules/timeline/Timeline.js +83 -43
- package/modules/timeline/Tween.js +25 -19
- package/modules/timeline/shots.js +24 -17
- package/modules/triggers/index.js +95 -28
- package/modules/vegetation/Vegetation.js +34 -26
- package/modules/vegetation/densityMap.js +4 -7
- package/modules/vegetation/draw.js +39 -18
- package/modules/vegetation/groundChunks.js +21 -38
- package/modules/vegetation/index.js +37 -12
- package/modules/vegetation/modelGeometry.js +3 -6
- package/modules/vegetation/nearFade.js +1 -1
- package/modules/water/Water.js +20 -16
- package/modules/water/surface.js +3 -3
- package/modules/weather/Weather.js +52 -40
- package/modules/weather/particles.js +8 -8
- package/modules/weather/weatherDraw.js +28 -23
- package/modules/world/World.js +28 -15
- package/modules/world/explain.js +1 -1
- package/modules/world/index.js +30 -17
- package/modules/world/persist.js +90 -27
- package/modules/world/pos.js +5 -5
- package/modules/world/records.js +37 -11
- package/modules/world/sim.js +78 -27
- package/modules/world/simFar.js +2 -2
- package/modules/world/state.js +43 -11
- package/modules/world/thingSource.js +20 -5
- package/modules/world/views.js +27 -14
- package/package.json +48 -7
- package/presets.js +1 -3
- package/render/PostFX.js +83 -53
- package/render/backend.js +31 -33
- package/render/cascades.js +17 -12
- package/render/cascades.tsl.js +5 -8
- package/render/daylight.js +20 -3
- package/render/detail.js +8 -7
- package/render/effects.js +28 -25
- package/render/fuse.js +3 -3
- package/render/fx/cloudShadow.tsl.js +3 -3
- package/render/fx/detail.tsl.js +1 -1
- package/render/fx/index.js +5 -10
- package/render/fx/library.tsl.js +11 -0
- package/render/fx/lighting.tsl.js +2 -1
- package/render/fx/nodeErrors.tsl.js +2 -2
- package/render/fx/objectOrigin.tsl.js +1 -2
- package/render/fx/particles.tsl.js +8 -6
- package/render/fx/patchNodes.tsl.js +5 -15
- package/render/fx/postWebGPU.tsl.js +30 -26
- package/render/fx/sky.tsl.js +15 -17
- package/render/fx/uniforms.tsl.js +4 -4
- package/render/fx/wind.tsl.js +1 -1
- package/render/fxNumbers.js +3 -0
- package/render/layers.js +2 -2
- package/render/lighting.js +5 -3
- package/render/lightmap.js +41 -21
- package/render/lights.js +6 -6
- package/render/lit.js +24 -0
- package/render/materials.js +8 -7
- package/render/mergeCommon.js +22 -0
- package/render/modeling.js +2 -2
- package/render/occlusion.js +62 -15
- package/render/ownFrame.js +4 -4
- package/render/patches.js +15 -15
- package/render/postWebGL.js +15 -12
- package/render/probes.js +41 -19
- package/render/recordSweep.js +117 -0
- package/render/shaderErrors.js +10 -9
- package/render/shadowCache.tsl.js +107 -0
- package/render/shadowTypes.js +9 -0
- package/{core → render}/shadows.js +59 -13
- package/render/slots.js +7 -7
- package/render/terms.js +22 -24
- package/render/uniformDecl.js +1 -1
- package/types/core.d.ts +336 -202
- package/types/gameplay.d.ts +254 -130
- package/types/generated/core/{Audio.d.ts → audio/Audio.d.ts} +22 -7
- package/types/generated/core/{audioVoice.d.ts → audio/audioVoice.d.ts} +2 -2
- package/types/generated/core/{Events.d.ts → base/Events.d.ts} +4 -4
- package/types/generated/core/{I18n.d.ts → base/I18n.d.ts} +8 -16
- package/types/generated/core/{Random.d.ts → base/Random.d.ts} +4 -3
- package/types/generated/core/{page.d.ts → engine/page.d.ts} +8 -9
- package/types/generated/core/{Input.d.ts → input/Input.d.ts} +28 -10
- package/types/generated/core/input/inputSeat.d.ts +26 -0
- package/types/generated/core/{Budget.d.ts → inspect/Budget.d.ts} +36 -26
- package/types/generated/core/{DebugOverrides.d.ts → inspect/DebugOverrides.d.ts} +17 -3
- package/types/generated/core/{Ops.d.ts → ops/Ops.d.ts} +6 -4
- package/types/generated/core/{control.d.ts → ops/control.d.ts} +14 -10
- package/types/generated/core/{Saves.d.ts → saves/Saves.d.ts} +62 -18
- package/types/generated/core/{session.d.ts → saves/session.d.ts} +3 -2
- package/types/generated/core/{Rays.d.ts → scene/Rays.d.ts} +8 -27
- package/types/generated/core/{Views.d.ts → scene/Views.d.ts} +2 -2
- package/types/generated/core/{Batching.d.ts → stream/Batching.d.ts} +7 -7
- package/types/generated/core/{Stream.d.ts → stream/Stream.d.ts} +22 -18
- package/types/generated/core/{Commits.d.ts → threads/Commits.d.ts} +1 -1
- package/types/generated/core/{Jobs.d.ts → threads/Jobs.d.ts} +6 -6
- package/types/generated/core/{Threads.d.ts → threads/Threads.d.ts} +4 -4
- package/types/generated/modules/calendar/Calendar.d.ts +10 -11
- package/types/generated/modules/debug/DebugPanel.d.ts +1 -9
- package/types/generated/modules/grid/Grid.d.ts +1 -0
- package/types/generated/modules/grid/Layer.d.ts +1 -1
- package/types/generated/modules/grid/index.d.ts +3 -3
- package/types/generated/modules/music/Music.d.ts +7 -5
- package/types/generated/modules/particles/Particles.d.ts +5 -4
- package/types/generated/modules/sky/Sky.d.ts +21 -10
- package/types/generated/modules/swarm/Swarm.d.ts +80 -0
- package/types/generated/modules/timeline/Timeline.d.ts +7 -5
- package/types/generated/modules/water/Water.d.ts +1 -0
- package/types/generated/modules/weather/Weather.d.ts +14 -16
- package/types/generated/modules/weather/weatherDraw.d.ts +3 -3
- package/types/generated/modules/world/World.d.ts +11 -7
- package/types/generated/render/PostFX.d.ts +21 -23
- package/types/generated/render/materials.d.ts +1 -0
- package/types/generated/render/occlusion.d.ts +9 -0
- package/types/generated/render/patches.d.ts +1 -0
- package/types/generated/ui/Focus.d.ts +1 -0
- package/types/generated/ui/UI.d.ts +1 -0
- package/types/nav.d.ts +47 -15
- package/types/physics.d.ts +150 -73
- package/types/pixel.d.ts +75 -0
- package/types/tsl.d.ts +37 -4
- package/types/world.d.ts +48 -75
- package/ui/Focus.js +10 -9
- package/ui/Parts.js +13 -5
- package/ui/UI.js +7 -7
- package/ui/defaults.js +3 -2
- package/ui/theme.js +7 -5
- package/core/assetEntry.js +0 -109
- package/core/engineCamera.js +0 -32
- package/core/ground.js +0 -104
- package/core/holds.js +0 -134
- package/core/math.js +0 -48
- package/core/moduleSlots.js +0 -100
- package/core/modules.js +0 -314
- package/core/saveApply.js +0 -210
- package/core/saveValues.js +0 -46
- package/core/session.js +0 -174
- package/core/shadowTypes.js +0 -16
- package/core/util.js +0 -17
- package/core/view.js +0 -43
- package/docs/MIGRATING-0.3.md +0 -248
- package/docs/MIGRATING-0.4.md +0 -320
- package/docs/MIGRATING-0.5.md +0 -68
- package/docs/MIGRATING-0.6.md +0 -126
- package/docs/PERF.md +0 -245
- package/docs/recipes/36-sky-ground-plants.md +0 -158
- package/docs/recipes/37-terrain-hooks.md +0 -115
- package/docs/recipes/38-environment-hooks.md +0 -67
- package/docs/recipes/42-terrain-shape.md +0 -64
- package/docs/recipes/47-island-snow-backdrop.md +0 -43
- package/docs/recipes/54-three-idioms.md +0 -88
- package/examples/plain-picture/FINDINGS.md +0 -53
- package/examples/sheepisland/.threedog/content-index.json +0 -1
- package/modules/camera/projection.js +0 -21
- /package/core/{mulberry32.js → base/mulberry32.js} +0 -0
- /package/core/{inputDefaults.js → input/inputDefaults.js} +0 -0
- /package/core/{textureBytes.js → inspect/textureBytes.js} +0 -0
- /package/core/{actor.js → ops/actor.js} +0 -0
- /package/core/{opsHistory.js → ops/opsHistory.js} +0 -0
- /package/core/{saveIds.js → saves/saveIds.js} +0 -0
- /package/core/{screenToGround.js → scene/screenToGround.js} +0 -0
- /package/core/{cells.js → stream/cells.js} +0 -0
- /package/core/{streamCells.js → stream/streamCells.js} +0 -0
- /package/core/{pureWorker.js → threads/pureWorker.js} +0 -0
- /package/examples/{sheepisland → perf-island}/content/index.js +0 -0
- /package/examples/{sheepisland → perf-island}/content/props.js +0 -0
- /package/examples/{sheepisland → perf-island}/content/templates.js +0 -0
- /package/examples/{sheepisland → perf-island}/content/vegetation.js +0 -0
- /package/examples/{sheepisland → perf-island}/picture/lights.js +0 -0
- /package/examples/{sheepisland → perf-island}/picture/materials.js +0 -0
- /package/examples/{sheepisland → perf-island}/picture/sky.js +0 -0
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
# Common tasks, complete
|
|
2
|
+
|
|
3
|
+
**In this recipe**: whole examples first, then "In an existing game", the lines to add to a game that runs.
|
|
4
|
+
|
|
5
|
+
The most asked tasks, each as one short whole file: the modules it needs, the definitions, the input, then a check that also shows the cleanup. `threedog how` prints these sections whole, and a test runs every block, so they cannot go stale.
|
|
6
|
+
The sections "In an existing game" hold only the lines to add to a game that runs, with where they go, what to skip if it is there, the failure to handle and the check; `threedog how` prints them when it finds a game. They are a starting point, not the only way: each ends with the next route. Names like `gem` and `pace` stand for yours. The second block of a section runs on the live page with `threedog js --file <file>`.
|
|
7
|
+
|
|
8
|
+
## Pickup: something to take that goes in a bag
|
|
9
|
+
```js
|
|
10
|
+
import { createEngine, presets, world, collision, characters, inventory, pickups, interactions } from 'threedog';
|
|
11
|
+
|
|
12
|
+
const engine = createEngine({ canvas: document.getElementById('view'), bindings: { ...presets.bindings.walk, ...presets.bindings.interact } }); // interact is E
|
|
13
|
+
engine.use(world(), collision(), characters(), inventory(), pickups(), interactions({ ...presets.interactions.nearest }));
|
|
14
|
+
engine.characters.createPlayer({ ...presets.player.thirdPerson, spawn: [0, 0, 0] });
|
|
15
|
+
engine.inventory.define('gem', { name: 'Gem' });
|
|
16
|
+
engine.pickups.spawn([1, 0, 0], { give: 'gem', id: 'gem-1' });
|
|
17
|
+
Object.assign(window, { engine });
|
|
18
|
+
await engine.start();
|
|
19
|
+
```
|
|
20
|
+
```js
|
|
21
|
+
step(0.2);
|
|
22
|
+
engine.input.simulate('interact', true); step(0.1); engine.input.simulate('interact', false); step(0.1);
|
|
23
|
+
expect(engine.inventory.count('gem'), 'E takes it').toBe(1);
|
|
24
|
+
const left = engine.pickups.spawn([3, 0, 0], { give: 'gem', id: 'gem-2' });
|
|
25
|
+
left.remove(); // cleanup: data and model go together
|
|
26
|
+
assert(!engine.world.get('gem-2'), 'a removed pickup is gone');
|
|
27
|
+
```
|
|
28
|
+
**When it does not fit:** a mesh you already have and a number on screen, with no bag: `engine.interactions.add(mesh, { once: true, counter })`, recipe 03 "Pick and count".
|
|
29
|
+
|
|
30
|
+
## Custom picture piece: your own three.js in the scene
|
|
31
|
+
```js
|
|
32
|
+
import { createEngine, THREE } from 'threedog';
|
|
33
|
+
|
|
34
|
+
const lantern = () => ({ name: 'lantern', type: 'picture', install(e, ctx) {
|
|
35
|
+
const glow = new THREE.PointLight(0xffcc88, 2, 12);
|
|
36
|
+
glow.name = 'lantern-glow';
|
|
37
|
+
e.scene.add(glow);
|
|
38
|
+
ctx.track({ remove() { e.scene.remove(glow); glow.dispose(); } }); // leaves with the piece
|
|
39
|
+
ctx.track(e.onRender(() => { glow.intensity = 2 + Math.sin(e.time.tick / 20) * 0.2; }));
|
|
40
|
+
} });
|
|
41
|
+
|
|
42
|
+
const engine = createEngine({ canvas: document.getElementById('view') });
|
|
43
|
+
engine.use(lantern());
|
|
44
|
+
Object.assign(window, { engine });
|
|
45
|
+
await engine.start();
|
|
46
|
+
```
|
|
47
|
+
```js
|
|
48
|
+
step(0.1);
|
|
49
|
+
assert(engine.scene.getObjectByName('lantern-glow'), 'the piece is in the scene');
|
|
50
|
+
await engine.unuse('lantern'); // cleanup: what it tracked leaves with it
|
|
51
|
+
assert(!engine.scene.getObjectByName('lantern-glow'), 'the piece took its light away');
|
|
52
|
+
```
|
|
53
|
+
**When it does not fit:** one author and one look: put it in `picture/` and call it from `picture/index.js`, recipe 62. No module is needed to add a mesh: `engine.scene.add(mesh)` is plain three.js.
|
|
54
|
+
|
|
55
|
+
## Saved game value: a number that survives a reload
|
|
56
|
+
```js
|
|
57
|
+
import { createEngine } from 'threedog';
|
|
58
|
+
|
|
59
|
+
const engine = createEngine({ canvas: document.getElementById('view') });
|
|
60
|
+
const best = { score: 0 };
|
|
61
|
+
engine.saves.register('best', { version: 1, save: () => ({ ...best }), load: d => { best.score = d.score; } });
|
|
62
|
+
engine.onFixed(() => { best.score += 1; });
|
|
63
|
+
Object.assign(window, { engine, best });
|
|
64
|
+
await engine.start();
|
|
65
|
+
```
|
|
66
|
+
```js
|
|
67
|
+
step(0.1);
|
|
68
|
+
await engine.saves.save('check');
|
|
69
|
+
const kept = best.score;
|
|
70
|
+
step(0.5);
|
|
71
|
+
assert(best.score > kept, 'the value moved on');
|
|
72
|
+
await engine.saves.load('check');
|
|
73
|
+
expect(best.score, 'the save brought it back').toBe(kept);
|
|
74
|
+
await engine.saves.remove('check'); // cleanup: the test slot; the part itself lasts as long as the game
|
|
75
|
+
```
|
|
76
|
+
**When it does not fit:** a preference (volume, language) is not game state: `localStorage` with `engine.saves.storageKey(name)`. A best time that outlives every save: recipe 20. A value several systems change: `engine.mod`, recipe 55.
|
|
77
|
+
|
|
78
|
+
## Input action: your own key
|
|
79
|
+
```js
|
|
80
|
+
import { createEngine } from 'threedog';
|
|
81
|
+
|
|
82
|
+
const engine = createEngine({ canvas: document.getElementById('view'), bindings: { dash: ['KeyQ', 'PadX'] } }); // the game binds keys, the player can rebind them
|
|
83
|
+
const dashes = { n: 0 };
|
|
84
|
+
const action = engine.input.action('dash', { label: 'Dash' });
|
|
85
|
+
const reader = engine.onFixed(() => { if (engine.input.pressed('dash')) dashes.n++; }); // gameplay reads in the fixed step
|
|
86
|
+
Object.assign(window, { engine, dashes, leave: () => { reader.remove(); action.remove(); } });
|
|
87
|
+
await engine.start();
|
|
88
|
+
```
|
|
89
|
+
```js
|
|
90
|
+
engine.input.simulate('dash', true); step(0.1); engine.input.simulate('dash', false); step(0.1);
|
|
91
|
+
expect(dashes.n, 'one press, one dash').toBe(1);
|
|
92
|
+
expect(engine.input.isUnbound('dash'), 'it has a key').toBe(false);
|
|
93
|
+
leave(); // cleanup: the reader and the action go; in a module, ctx.input takes them with it
|
|
94
|
+
```
|
|
95
|
+
**When it does not fit:** a key only inside a vehicle or menu: a context, `engine.input.push`, recipe 58 §2. A text field keeps its own browser listener.
|
|
96
|
+
|
|
97
|
+
## Rain effect: weather with its particles
|
|
98
|
+
```js
|
|
99
|
+
import { createEngine, calendar, sky, weather } from 'threedog';
|
|
100
|
+
|
|
101
|
+
const engine = createEngine({ canvas: document.getElementById('view') });
|
|
102
|
+
// the table is the game's: without one only a calm 'clear' exists (presets.weather.temperate has seven types)
|
|
103
|
+
engine.use(calendar(), sky(), weather({ types: { clear: {}, rain: { rain: 1, cloud: 0.8 } }, rain: { count: 500 } }));
|
|
104
|
+
Object.assign(window, { engine });
|
|
105
|
+
await engine.start();
|
|
106
|
+
engine.weather.set('rain', { seconds: 0 });
|
|
107
|
+
```
|
|
108
|
+
```js
|
|
109
|
+
step(0.2);
|
|
110
|
+
expect(engine.describe().weather.name, 'it rains').toBe('rain');
|
|
111
|
+
assert(engine.describe().weather.rain > 0, 'the rain is falling');
|
|
112
|
+
engine.weather.set('clear', { seconds: 0 }); // cleanup: the module stays, the rain stops
|
|
113
|
+
step(0.2);
|
|
114
|
+
expect(engine.describe().weather.name, 'it stopped').toBe('clear');
|
|
115
|
+
```
|
|
116
|
+
**When it does not fit:** a rain that is not weather (a burst in one room, a fountain): `particles()`, recipe 64, or your own three.js `Points`. Your own drawing of the weather table: `weather.defineField`, recipe 44.
|
|
117
|
+
|
|
118
|
+
## Custom NPC behaviour: your own rule for what it does
|
|
119
|
+
```js
|
|
120
|
+
import { createEngine, world, collision, characters } from 'threedog';
|
|
121
|
+
|
|
122
|
+
const engine = createEngine({ canvas: document.getElementById('view') });
|
|
123
|
+
engine.use(world(), collision(), characters());
|
|
124
|
+
engine.npcs.behavior('pace', { // what must be remembered goes in rec.mind: plain values, saved with the NPC
|
|
125
|
+
near(rec, dt) { rec.mind.walked = (rec.mind.walked ?? 0) + dt; },
|
|
126
|
+
far(rec, dt) { rec.mind.walked = (rec.mind.walked ?? 0) + dt; },
|
|
127
|
+
});
|
|
128
|
+
engine.npcs.add({ id: 'guard', name: 'Guard', position: [2, 0, 2], behavior: 'pace', mind: {} });
|
|
129
|
+
Object.assign(window, { engine });
|
|
130
|
+
await engine.start();
|
|
131
|
+
```
|
|
132
|
+
```js
|
|
133
|
+
step(0.5);
|
|
134
|
+
assert(engine.world.get('guard').mind.walked > 0, 'the behaviour runs');
|
|
135
|
+
engine.npcs.remove('guard'); // cleanup: the data, the model and its interaction go together
|
|
136
|
+
assert(!engine.npcs.get('guard'), 'the NPC is gone');
|
|
137
|
+
```
|
|
138
|
+
**When it does not fit:** a daily route needs no code: `schedule` or `behavior: 'wander'`, recipe 02. Something that is not a person (a crowd of birds): recipe 65, or your own objects and `engine.onFixed`.
|
|
139
|
+
|
|
140
|
+
## Custom path source: paths that do not come from the ground
|
|
141
|
+
```js
|
|
142
|
+
import { createEngine, world, collision, characters } from 'threedog';
|
|
143
|
+
|
|
144
|
+
const engine = createEngine({ canvas: document.getElementById('view') });
|
|
145
|
+
engine.use(world(), collision(), characters());
|
|
146
|
+
Object.assign(window, { engine });
|
|
147
|
+
await engine.start();
|
|
148
|
+
// a list of points, null for no way, 'walk' for the built-in search
|
|
149
|
+
window.rails = engine.mod('characters.path', { owner: 'rails', set: ({ from, to }) => [from, { x: to.x, y: 0, z: from.z }, to] });
|
|
150
|
+
```
|
|
151
|
+
```js
|
|
152
|
+
const path = engine.characters.findPath({ x: 0, z: 0 }, { x: 4, z: 4 });
|
|
153
|
+
expect(path.length, 'the source answered').toBe(3);
|
|
154
|
+
expect(path[1].x, 'through its corner').toBe(4);
|
|
155
|
+
rails.remove(); // cleanup: the built-in search answers again
|
|
156
|
+
assert(JSON.stringify(engine.characters.findPath({ x: 0, z: 0 }, { x: 4, z: 4 })) !== JSON.stringify(path), 'the source no longer answers');
|
|
157
|
+
```
|
|
158
|
+
**When it does not fit:** walking around obstacles on the ground needs no source: `engine.characters.findPath`, or `nav()` for a navmesh, recipe 12. One character only: give the entry an `id`.
|
|
159
|
+
|
|
160
|
+
## Two areas built in code: the engine remembers which one
|
|
161
|
+
```js
|
|
162
|
+
import { createEngine, world, collision, characters, level, THREE } from 'threedog';
|
|
163
|
+
|
|
164
|
+
const engine = createEngine({ canvas: document.getElementById('view') });
|
|
165
|
+
const floor = size => new THREE.Mesh(new THREE.BoxGeometry(size, 1, size).translate(0, -0.5, 0), new THREE.MeshStandardMaterial());
|
|
166
|
+
// a name in the manifest is what a save remembers, and its builder is how the area comes back: nothing else to wire
|
|
167
|
+
engine.assets.manifest({ models: { house: () => floor(20), outpost: () => floor(40) } });
|
|
168
|
+
engine.use(world(), collision(), characters(), level({ url: 'house' }));
|
|
169
|
+
engine.characters.createPlayer({ control: () => null, spawn: [0, 0, 0] });
|
|
170
|
+
Object.assign(window, { engine });
|
|
171
|
+
await engine.start();
|
|
172
|
+
```
|
|
173
|
+
```js
|
|
174
|
+
await engine.level.load('outpost'); step(0.1);
|
|
175
|
+
engine.player.placeAt([15, 0, 0]);
|
|
176
|
+
await engine.saves.save('check');
|
|
177
|
+
await engine.level.load('house'); step(0.1);
|
|
178
|
+
expect(engine.world.zone, 'walked back').toBe('house');
|
|
179
|
+
await engine.saves.load('check'); step(0.1);
|
|
180
|
+
expect(engine.world.zone, 'the save went back by itself').toBe('outpost');
|
|
181
|
+
expect(engine.player.position.x, 'with the player where it stood').toBe(15);
|
|
182
|
+
await engine.saves.remove('check'); // cleanup: the test slot
|
|
183
|
+
```
|
|
184
|
+
**When it does not fit:** `level({ scene })` takes an object with no name, so a save cannot rebuild it: fine for a game with one area. Records with `zone: 'outpost'` show only there, recipe 07. Changing area in play: `engine.flow.transition`, recipe 07.
|
|
185
|
+
|
|
186
|
+
## Climb a ladder: your own movement, kept when loading mid-climb
|
|
187
|
+
```js
|
|
188
|
+
import { createEngine, world, collision, characters } from 'threedog';
|
|
189
|
+
const engine = createEngine({ canvas: document.getElementById('view'), audio: { sounds: { rung: { src: 'footstep' } } } });
|
|
190
|
+
engine.use(world(), collision(), characters(), { name: 'ladder', afterLoad: () => grip() }); // after a load: the hold of the save, or none
|
|
191
|
+
engine.setGround({ height: (x, z) => z > 1 ? 3 : 0, slope: () => 0, type: () => 'wood' }); // the upper floor starts at z = 1
|
|
192
|
+
const player = engine.characters.createPlayer({ control: () => null, spawn: [0, 0, 0] });
|
|
193
|
+
let hold = null; // running code, so no save keeps it: the record field does, and grip puts the hold back
|
|
194
|
+
const grip = () => { hold?.remove(); hold = engine.world.get('player').climbing ? engine.control.take(player, { owner: 'ladder', step: (dt, ch) => (climb(dt, ch), false) }) : null; }; // false: placed by hand, no mover, no gravity
|
|
195
|
+
const climb = (dt, ch) => {
|
|
196
|
+
const y = ch.root.position.y += 1.5 * dt;
|
|
197
|
+
if (y % 0.5 < 1.5 * dt) engine.audio.sfx('rung', { at: ch.root });
|
|
198
|
+
ch.syncRecord(); engine.characters.kit.ownState(ch, 'climb', 1.5); // the position is saved with the record, the state picks the animation
|
|
199
|
+
if (y >= 3) { engine.world.set('player', { climbing: false }); grip(); ch.placeAt([0, 3, 2]); }
|
|
200
|
+
};
|
|
201
|
+
engine.ops.define('ladder.climb', { run: e => { e.world.set('player', { climbing: true }); grip(); } });
|
|
202
|
+
Object.assign(window, { engine }); await engine.start();
|
|
203
|
+
```
|
|
204
|
+
```js
|
|
205
|
+
engine.ops.run('ladder.climb'); step(1);
|
|
206
|
+
const rung = engine.player.position.y;
|
|
207
|
+
assert(rung > 1 && rung < 3, 'halfway up');
|
|
208
|
+
await engine.saves.save('check');
|
|
209
|
+
step(2);
|
|
210
|
+
expect(engine.player.position.z, 'stepped off at the top').toBe(2);
|
|
211
|
+
expect(engine.control.of(engine.player).owner, 'the keys are back').toBe('player-input');
|
|
212
|
+
await engine.saves.load('check');
|
|
213
|
+
expect(engine.player.position.y, 'back on the rung').toBe(rung);
|
|
214
|
+
expect(engine.control.of(engine.player).owner, 'holding on again').toBe('ladder');
|
|
215
|
+
step(0.5);
|
|
216
|
+
assert(engine.player.position.y > rung, 'and the climb goes on');
|
|
217
|
+
step(2);
|
|
218
|
+
expect(engine.player.position.y, 'to the top').toBe(3);
|
|
219
|
+
await engine.saves.remove('check'); // cleanup: the test slot; the climb ended itself and took its hold away
|
|
220
|
+
```
|
|
221
|
+
**When it does not fit:** climbing with the up and down keys, or a climb animation clip: recipe 57 "a ladder". A climb that stops for a cutscene: a higher `layer` pauses this hold, recipe 57. Your own way of moving for a whole game (flying, swimming): your own mover, recipe 57.
|
|
222
|
+
|
|
223
|
+
## In an existing game: pickup
|
|
224
|
+
```js
|
|
225
|
+
// main.js imports: add the ones it lacks. engine.use goes before engine.start(); a module it already has is ignored with a warning, so drop those
|
|
226
|
+
import { presets, world, collision, characters, inventory, pickups, interactions } from 'threedog';
|
|
227
|
+
engine.use(world(), collision(), characters(), inventory({ capacity: 1, defaultStack: 1 }), pickups(), interactions({ ...presets.interactions.nearest }));
|
|
228
|
+
engine.characters.createPlayer({ ...presets.player.thirdPerson, spawn: [0, 0, 0] }); // only if there is no hero yet
|
|
229
|
+
// where the level is set up
|
|
230
|
+
engine.inventory.define('gem', { name: 'Gem' });
|
|
231
|
+
engine.pickups.spawn([1, 0, 0], { give: 'gem', id: 'gem-1' });
|
|
232
|
+
// giving by hand: the answer is an object, so read .ok; if (inventory.add(...)) is true even when the bag is full
|
|
233
|
+
const given = engine.inventory.add('gem');
|
|
234
|
+
if (!given.ok) console.warn('bag full', given.code);
|
|
235
|
+
```
|
|
236
|
+
```js
|
|
237
|
+
expect(engine.inventory.add('gem').ok, 'a second gem does not fit').toBe(false);
|
|
238
|
+
step(0.2);
|
|
239
|
+
engine.input.simulate('interact', true); step(0.1); engine.input.simulate('interact', false); step(0.1);
|
|
240
|
+
assert(engine.world.get('gem-1'), 'with a full bag it stays on the ground');
|
|
241
|
+
engine.inventory.remove('gem'); // cleanup: the bag as it was
|
|
242
|
+
```
|
|
243
|
+
**When it does not fit:** it reuses what your game has: the whole file is "Pickup" above. Items in your own data: `inventory.define` takes them from `content/`, recipe 03.
|
|
244
|
+
|
|
245
|
+
## In an existing game: saved value
|
|
246
|
+
```js
|
|
247
|
+
// beside the system that owns the value, once, before the first load. A module's own state saves itself: this is for yours
|
|
248
|
+
const tally = { score: 0 };
|
|
249
|
+
engine.saves.register('tally', { version: 1, save: () => ({ ...tally }), load: d => { tally.score = d.score; } });
|
|
250
|
+
// at a checkpoint or a menu: false means nothing was written, so say "saved" only after true
|
|
251
|
+
const saveTally = async () => { if (!await engine.saves.save('slot1')) console.warn('not saved'); };
|
|
252
|
+
```
|
|
253
|
+
```js
|
|
254
|
+
tally.score = 7;
|
|
255
|
+
await saveTally();
|
|
256
|
+
tally.score = 0;
|
|
257
|
+
expect(await engine.saves.load('slot1'), 'it loads').toBe(true);
|
|
258
|
+
expect(tally.score, 'the value came back').toBe(7);
|
|
259
|
+
await engine.saves.remove('slot1'); // cleanup: the test slot
|
|
260
|
+
```
|
|
261
|
+
**When it does not fit:** a part that changes shape later needs a `migrate`: recipe 20. A preference is no game state: `localStorage`.
|
|
262
|
+
|
|
263
|
+
## In an existing game: press a key on a thing
|
|
264
|
+
```js
|
|
265
|
+
// main.js imports and engine.use, as in the pickup above. The key is the 'interact' action in your bindings
|
|
266
|
+
import { presets, world, collision, characters, interactions } from 'threedog';
|
|
267
|
+
engine.use(world(), collision(), characters(), interactions({ ...presets.interactions.nearest }));
|
|
268
|
+
engine.characters.createPlayer({ ...presets.player.thirdPerson, spawn: [0, 0, 0] }); // only if there is no hero yet
|
|
269
|
+
// where the level is set up: a mesh of yours, or a position
|
|
270
|
+
const door = { open: false, locked: false };
|
|
271
|
+
const spot = engine.interactions.add([1, 0, 0], { onUse: () => { if (door.locked) return { ok: false, code: 'locked' }; door.open = true; } });
|
|
272
|
+
```
|
|
273
|
+
```js
|
|
274
|
+
step(0.2);
|
|
275
|
+
engine.input.simulate('interact', true); step(0.1); engine.input.simulate('interact', false); step(0.1);
|
|
276
|
+
assert(door.open, 'E opens it');
|
|
277
|
+
spot.remove(); // cleanup: the handle ends it with the door
|
|
278
|
+
```
|
|
279
|
+
**When it does not fit:** something that happens by walking in, with no key: `triggers()`. Clicking with the mouse: `engine.rays`, recipe 19.
|
|
280
|
+
|
|
281
|
+
## In an existing game: after a delay
|
|
282
|
+
```js
|
|
283
|
+
// no setup: the clock is in every engine and stops when the game pauses, setTimeout would run on
|
|
284
|
+
const flags = { late: false };
|
|
285
|
+
const timer = engine.clock.after(2, () => { flags.late = true; }, { channel: 'real' });
|
|
286
|
+
// called off: timer.remove(). A function does not survive a load: pass an event name if the wait must
|
|
287
|
+
```
|
|
288
|
+
```js
|
|
289
|
+
step(2.1);
|
|
290
|
+
assert(flags.late, 'it ran in game time');
|
|
291
|
+
timer.remove(); // cleanup: removing it twice is fine
|
|
292
|
+
```
|
|
293
|
+
**When it does not fit:** hours and days of a calendar: `calendar()`, recipe 06. A wait in real seconds, for a menu or a sound: `{ channel: 'real' }`.
|
|
294
|
+
|
|
295
|
+
## In an existing game: steer the hero for a moment
|
|
296
|
+
```js
|
|
297
|
+
// main.js imports and engine.use, as in the pickup above; a hero must exist
|
|
298
|
+
import { presets, world, collision, characters } from 'threedog';
|
|
299
|
+
engine.use(world(), collision(), characters());
|
|
300
|
+
engine.characters.createPlayer({ ...presets.player.thirdPerson, spawn: [0, 0, 0] }); // only if there is no hero yet
|
|
301
|
+
// from your own rule: a hold outranks the keys until it ends, so never write the hero's position each frame
|
|
302
|
+
const dash = () => { const hold = engine.control.take(engine.player, { owner: 'dash', layer: 'script', step: () => ({ x: 0, z: 1, run: true }) }); engine.clock.after(0.4, () => hold.remove(), { channel: 'real' }); };
|
|
303
|
+
```
|
|
304
|
+
```js
|
|
305
|
+
step(0.2);
|
|
306
|
+
const from = engine.player.position.z;
|
|
307
|
+
dash();
|
|
308
|
+
step(0.3);
|
|
309
|
+
assert(engine.player.position.z !== from, 'the hold moved the hero');
|
|
310
|
+
step(0.3); // cleanup: the hold ended by itself
|
|
311
|
+
expect(engine.control.of(engine.player).owner, 'the keys are back').toBe('player-input');
|
|
312
|
+
```
|
|
313
|
+
**When it does not fit:** a whole new way of moving: "Climb a ladder" above. A car or a ship: recipe 11. Who holds what: recipe 57.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":1,"files":{"content/actions.js":{"kind":"actions","mtime":
|
|
1
|
+
{"version":1,"files":{"content/actions.js":{"kind":"actions","mtime":1794045415000,"size":481,"from":0,"count":4,"indexIds":0,"positional":[]},"content/audio.js":{"kind":"audio","mtime":1794045415000,"size":430,"from":0,"count":1,"indexIds":0,"positional":[]},"content/items.js":{"kind":"items","mtime":1794045415000,"size":204,"from":0,"count":1,"indexIds":0,"positional":[]},"content/places.js":{"kind":"places","mtime":1794045415000,"size":209,"from":0,"count":1,"indexIds":0,"positional":[]},"content/props.js":{"kind":"props","mtime":1794045415000,"size":707,"from":0,"count":8,"indexIds":0,"positional":[]},"content/templates.js":{"kind":"templates","mtime":1794045415000,"size":835,"from":0,"count":4,"indexIds":0,"positional":[]},"content/views.js":{"kind":"views","mtime":1794045415000,"size":539,"from":0,"count":2,"indexIds":0,"positional":[]}},"ids":{"attack":[{"file":"content/actions.js","kind":"actions","line":4,"placed":false}],"retry":[{"file":"content/actions.js","kind":"actions","line":5,"placed":false}],"save":[{"file":"content/actions.js","kind":"actions","line":6,"placed":false}],"load":[{"file":"content/actions.js","kind":"actions","line":7,"placed":false}],"sounds":[{"file":"content/audio.js","kind":"audio","line":4,"placed":false}],"gem":[{"file":"content/items.js","kind":"items","line":3,"placed":false}],"room":[{"file":"content/places.js","kind":"places","line":3,"placed":false}],"floor":[{"file":"content/props.js","kind":"props","line":3,"placed":true},{"file":"content/templates.js","kind":"templates","line":4,"placed":false}],"wall-n":[{"file":"content/props.js","kind":"props","line":4,"placed":true}],"wall-s":[{"file":"content/props.js","kind":"props","line":5,"placed":true}],"wall-w":[{"file":"content/props.js","kind":"props","line":6,"placed":true}],"wall-e":[{"file":"content/props.js","kind":"props","line":7,"placed":true}],"pillar-1":[{"file":"content/props.js","kind":"props","line":8,"placed":true}],"pillar-2":[{"file":"content/props.js","kind":"props","line":9,"placed":true}],"slime-1":[{"file":"content/props.js","kind":"props","line":10,"placed":true}],"wall":[{"file":"content/templates.js","kind":"templates","line":5,"placed":false}],"pillar":[{"file":"content/templates.js","kind":"templates","line":6,"placed":false}],"slime":[{"file":"content/templates.js","kind":"templates","line":9,"placed":false}],"corner":[{"file":"content/views.js","kind":"views","line":4,"placed":false}],"door":[{"file":"content/views.js","kind":"views","line":5,"placed":false}]}}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Game map: action (generated, do not edit by hand)
|
|
2
2
|
|
|
3
3
|
> Generated by `npm run map` by scanning this folder; paths are relative to it. Pages: /action.html, entry `main.js`.
|
|
4
|
-
> Content data is in `content/*.js` (condition/effect syntax: `node_modules/threedog/docs/recipes/20-content-actions-save.md`), which main.js hands to the engine with `engine.content.load()`;
|
|
4
|
+
> Content data is in `content/*.js` (condition/effect syntax: `node_modules/threedog/docs/recipes/20-content-actions-save.md`), which main.js hands to the engine with `engine.content.load()`; to look up a name: the module pages listed below (`node_modules/threedog/docs/API.md` indexes them).
|
|
5
5
|
|
|
6
6
|
Content: actions 4 · audio 1 · items 1 · places 1 · props 8 (from templates 8) · templates 4 · views 2
|
|
7
7
|
|
|
@@ -23,11 +23,11 @@ Content: actions 4 · audio 1 · items 1 · places 1 · props 8 (from templates
|
|
|
23
23
|
|
|
24
24
|
## Read for this game (per installed module: recipe · api page; core API: `node_modules/threedog/docs/api/engine.md`)
|
|
25
25
|
|
|
26
|
-
- world: `node_modules/threedog/docs/recipes/
|
|
26
|
+
- world: `node_modules/threedog/docs/recipes/66-common-tasks.md` · `node_modules/threedog/docs/api/world.md`
|
|
27
27
|
- calendar: `node_modules/threedog/docs/recipes/06-clock-events.md` · `node_modules/threedog/docs/api/calendar.md`
|
|
28
28
|
- sky: `node_modules/threedog/docs/recipes/08-weather-sky.md` · `node_modules/threedog/docs/api/sky.md`
|
|
29
29
|
- collision: `node_modules/threedog/docs/recipes/12-navmesh.md` · `node_modules/threedog/docs/api/collision.md`
|
|
30
|
-
- characters: `node_modules/threedog/docs/recipes/
|
|
30
|
+
- characters: `node_modules/threedog/docs/recipes/66-common-tasks.md` · `node_modules/threedog/docs/api/characters.md`
|
|
31
31
|
- settings: `node_modules/threedog/docs/recipes/26-ui-parts.md` · `node_modules/threedog/docs/api/settings.md`
|
|
32
32
|
- interactions: `node_modules/threedog/docs/recipes/20-content-actions-save.md` · `node_modules/threedog/docs/api/interactions.md`
|
|
33
33
|
- inventory: `node_modules/threedog/docs/recipes/03-items-pickups.md` · `node_modules/threedog/docs/api/inventory.md`
|
|
@@ -38,6 +38,7 @@ Content: actions 4 · audio 1 · items 1 · places 1 · props 8 (from templates
|
|
|
38
38
|
Not used yet (check these before writing the system yourself):
|
|
39
39
|
|
|
40
40
|
- quests: goals with steps, conditions and rewards: `quests()` + key map presets.bindings.quests, content/quests.js (node_modules/threedog/docs/recipes/04-quests.md)
|
|
41
|
+
- swarm: many same-kind moving things (shots, crowds, flocks, debris) in typed arrays, drawn as one mesh: `swarm()` (node_modules/threedog/docs/recipes/65-swarm.md)
|
|
41
42
|
- grids: cell placement for farming and building: `grids()` (node_modules/threedog/docs/recipes/29-grid.md)
|
|
42
43
|
|
|
43
44
|
## Files
|
|
@@ -124,8 +125,7 @@ Code that breaks saves or manages world models: none (rule R33).
|
|
|
124
125
|
|
|
125
126
|
- Save prefix saveKey: threedog-action
|
|
126
127
|
- Save slots: slot1
|
|
127
|
-
- Save entries the game registers itself:
|
|
128
|
-
'action
|
|
128
|
+
- Save entries the game registers itself: action
|
|
129
129
|
- Saved parts of the engine modules (vars, inventory, quests, timers, world...): `threedog catalog` (saves per module)
|
|
130
130
|
|
|
131
131
|
## Style keys
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":1,"files":{"content/props.js":{"kind":"props","mtime":1794045415000,"size":1370,"from":0,"count":15,"indexIds":0,"positional":[]},"content/templates.js":{"kind":"templates","mtime":1794045415000,"size":232,"from":0,"count":2,"indexIds":0,"positional":[]},"content/vegetation.js":{"kind":"vegetation","mtime":1794045415000,"size":522,"from":0,"count":1,"indexIds":0,"positional":[]}},"ids":{"tree-1":[{"file":"content/props.js","kind":"props","line":4,"placed":true}],"tree-2":[{"file":"content/props.js","kind":"props","line":5,"placed":true}],"tree-3":[{"file":"content/props.js","kind":"props","line":6,"placed":true}],"tree-4":[{"file":"content/props.js","kind":"props","line":7,"placed":true}],"tree-5":[{"file":"content/props.js","kind":"props","line":8,"placed":true}],"tree-6":[{"file":"content/props.js","kind":"props","line":9,"placed":true}],"tree-7":[{"file":"content/props.js","kind":"props","line":10,"placed":true}],"sheep-1":[{"file":"content/props.js","kind":"props","line":11,"placed":true}],"sheep-2":[{"file":"content/props.js","kind":"props","line":12,"placed":true}],"sheep-3":[{"file":"content/props.js","kind":"props","line":13,"placed":true}],"sheep-4":[{"file":"content/props.js","kind":"props","line":14,"placed":true}],"sheep-5":[{"file":"content/props.js","kind":"props","line":15,"placed":true}],"sheep-6":[{"file":"content/props.js","kind":"props","line":16,"placed":true}],"sheep-7":[{"file":"content/props.js","kind":"props","line":17,"placed":true}],"sheep-8":[{"file":"content/props.js","kind":"props","line":18,"placed":true}],"tree":[{"file":"content/templates.js","kind":"templates","line":3,"placed":false}],"sheep":[{"file":"content/templates.js","kind":"templates","line":4,"placed":false}],"wheat":[{"file":"content/vegetation.js","kind":"vegetation","line":6,"placed":false}]}}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
# Game map:
|
|
1
|
+
# Game map: perf-island (generated, do not edit by hand)
|
|
2
2
|
|
|
3
|
-
> Generated by `npm run map` by scanning this folder; paths are relative to it. Pages: /
|
|
4
|
-
> Content data is in `content/*.js` (condition/effect syntax: `node_modules/threedog/docs/recipes/20-content-actions-save.md`), which main.js hands to the engine with `engine.content.load()`;
|
|
3
|
+
> Generated by `npm run map` by scanning this folder; paths are relative to it. Pages: /perf-island.html, entry `main.js`.
|
|
4
|
+
> Content data is in `content/*.js` (condition/effect syntax: `node_modules/threedog/docs/recipes/20-content-actions-save.md`), which main.js hands to the engine with `engine.content.load()`; to look up a name: the module pages listed below (`node_modules/threedog/docs/API.md` indexes them).
|
|
5
5
|
|
|
6
6
|
Content: props 15 (from templates 15) · templates 2 · vegetation 1
|
|
7
7
|
|
|
@@ -11,20 +11,20 @@ None yet, write them in `DESIGN.md` (why it is designed this way, what not to ch
|
|
|
11
11
|
|
|
12
12
|
## Engine modules (engine.use)
|
|
13
13
|
|
|
14
|
-
- createEngine: { bindings: { ...presets.bindings.debug }, lights: false, saveKey: 'threedog-
|
|
14
|
+
- createEngine: { bindings: { ...presets.bindings.debug }, lights: false, saveKey: 'threedog-perf-island', ui: { loading: { t…
|
|
15
15
|
- openWorld preset ({ camera: fixedCamera(), terrain: island, water: false, rigid: false, ambience: false, calendar: { …) → world, terrain, vegetation, calendar, sky, weather, collision, characters, settings, debug
|
|
16
16
|
- content
|
|
17
17
|
|
|
18
18
|
## Read for this game (per installed module: recipe · api page; core API: `node_modules/threedog/docs/api/engine.md`)
|
|
19
19
|
|
|
20
|
-
- world: `node_modules/threedog/docs/recipes/
|
|
21
|
-
- terrain: `node_modules/threedog/docs/recipes/
|
|
22
|
-
- vegetation: `node_modules/threedog/docs/recipes/36-
|
|
20
|
+
- world: `node_modules/threedog/docs/recipes/66-common-tasks.md` · `node_modules/threedog/docs/api/world.md`
|
|
21
|
+
- terrain: `node_modules/threedog/docs/recipes/28-terrain.md` · `node_modules/threedog/docs/api/terrain.md`
|
|
22
|
+
- vegetation: `node_modules/threedog/docs/recipes/36-ground-plants.md` · `node_modules/threedog/docs/api/vegetation.md`
|
|
23
23
|
- calendar: `node_modules/threedog/docs/recipes/06-clock-events.md` · `node_modules/threedog/docs/api/calendar.md`
|
|
24
24
|
- sky: `node_modules/threedog/docs/recipes/08-weather-sky.md` · `node_modules/threedog/docs/api/sky.md`
|
|
25
25
|
- weather: `node_modules/threedog/docs/recipes/44-water-weather-hooks.md` · `node_modules/threedog/docs/api/weather.md`
|
|
26
26
|
- collision: `node_modules/threedog/docs/recipes/12-navmesh.md` · `node_modules/threedog/docs/api/collision.md`
|
|
27
|
-
- characters: `node_modules/threedog/docs/recipes/
|
|
27
|
+
- characters: `node_modules/threedog/docs/recipes/66-common-tasks.md` · `node_modules/threedog/docs/api/characters.md`
|
|
28
28
|
- settings: `node_modules/threedog/docs/recipes/26-ui-parts.md` · `node_modules/threedog/docs/api/settings.md`
|
|
29
29
|
- content: `node_modules/threedog/docs/recipes/30-templates.md` · `node_modules/threedog/docs/api/content.md`
|
|
30
30
|
|
|
@@ -34,6 +34,7 @@ Not used yet (check these before writing the system yourself):
|
|
|
34
34
|
- saves: save your own state: `engine.saves.register(key, { version, save, load })` (node_modules/threedog/docs/recipes/20-content-actions-save.md)
|
|
35
35
|
- interactions: press a key near a thing: `interactions({ ...presets.interactions.nearest })` (E, nearest; the game picks the pick mode and keys), template `interact: { label, op }` (node_modules/threedog/docs/recipes/30-templates.md)
|
|
36
36
|
- quests: goals with steps, conditions and rewards: `quests()` + key map presets.bindings.quests, content/quests.js (node_modules/threedog/docs/recipes/04-quests.md)
|
|
37
|
+
- swarm: many same-kind moving things (shots, crowds, flocks, debris) in typed arrays, drawn as one mesh: `swarm()` (node_modules/threedog/docs/recipes/65-swarm.md)
|
|
37
38
|
- grids: cell placement for farming and building: `grids()` (node_modules/threedog/docs/recipes/29-grid.md)
|
|
38
39
|
|
|
39
40
|
## Files
|
|
@@ -48,14 +49,14 @@ content/*.js is content data: how to write it in `node_modules/threedog/docs/rec
|
|
|
48
49
|
| content/templates.js | 6 | |
|
|
49
50
|
| content/vegetation.js | 11 | |
|
|
50
51
|
| main.js | 83 | @ts-check This example is written in GLSL: it is the WebGL route (`threedog new-game --webgl`). On … |
|
|
51
|
-
| models.js | 49 |
|
|
52
|
-
| params.js | 26 | URL parameters of the
|
|
53
|
-
| picture/index.js | 21 | @ts-check The picture of
|
|
52
|
+
| models.js | 49 | perf-island procedural models: a round tree, a sheep, a wheat tuft. Built in code, no files; regist… |
|
|
53
|
+
| params.js | 26 | URL parameters of the perf island page. Import this file first in main.js: it rewrites word values … |
|
|
54
|
+
| picture/index.js | 21 | @ts-check The picture of perf island: wiring only. Each part writes plain three.js from the signals… |
|
|
54
55
|
| picture/lights.js | 35 | @ts-check Sun or moon and ambient, both from the day table in palette.js. |
|
|
55
56
|
| picture/materials.js | 62 | @ts-check Materials by name. All matte Lambert with two shader additions: soft light (the wrap and … |
|
|
56
|
-
| picture/palette.js | 61 | @ts-check
|
|
57
|
+
| picture/palette.js | 61 | @ts-check Perf island palette: every color and key value of the picture, one copy. A soft painted d… |
|
|
57
58
|
| picture/sky.js | 21 | @ts-check A flat painted backdrop: one color at every height, the same as the fog, so the island fl… |
|
|
58
|
-
| views.js | 10 | Named camera positions of the
|
|
59
|
+
| views.js | 10 | Named camera positions of the perf island. Same name = same framing every time, so two screenshots … |
|
|
59
60
|
|
|
60
61
|
## NPCs (content/npcs.js)
|
|
61
62
|
|
|
@@ -103,7 +104,7 @@ Code that breaks saves or manages world models: none (rule R33).
|
|
|
103
104
|
|
|
104
105
|
## Saves
|
|
105
106
|
|
|
106
|
-
- Save prefix saveKey: threedog-
|
|
107
|
+
- Save prefix saveKey: threedog-perf-island
|
|
107
108
|
- Saved parts of the engine modules (vars, inventory, quests, timers, world...): `threedog catalog` (saves per module)
|
|
108
109
|
|
|
109
110
|
## Style keys
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
// objects and checks the model / sound names content uses against them (one source, no scanning of main.js).
|
|
3
3
|
import { models } from './models.js'; // roundTree, sheep, wheatTuft
|
|
4
4
|
|
|
5
|
-
export default [{ name: '
|
|
5
|
+
export default [{ name: 'perf-island', models }];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
// This example is written in GLSL: it is the WebGL route (`threedog new-game --webgl`). On the default WebGPU route the same ideas are written in TSL (recipe 56).
|
|
3
|
-
//
|
|
3
|
+
// Perf island: a small floating island built only from the engine's public entry points.
|
|
4
4
|
// A meadow with a river, round trees, a wheat field and a flock of sheep on an island with a ragged rim, over a pale backdrop with no horizon.
|
|
5
5
|
// Parameters (params.js): time day | dusk | night, weather clear | snow, view overview | flock | field | river | rim.
|
|
6
6
|
// main.js holds wiring only: modules, the island's terrain functions, view switching and the snow-to-winter link. Objects are content (rule R33),
|
|
@@ -19,7 +19,7 @@ import { VIEWS } from './views.js';
|
|
|
19
19
|
const island = {
|
|
20
20
|
...GROUND,
|
|
21
21
|
material: mat.ground, effects: /** @type {const} */ (false), // drawn as given: picture/materials.js brings its own snow, and this island has no cloud shadow
|
|
22
|
-
resolution: 48, // 64 m chunk / 48 = 1.33 m cells: the rim is cut along cells, so finer cells give a finer brushed edge (recipe
|
|
22
|
+
resolution: 48, // 64 m chunk / 48 = 1.33 m cells: the rim is cut along cells, so finer cells give a finer brushed edge (recipe 28 §5)
|
|
23
23
|
// the river's centre line z = amp * sin(x * freq) + shift: one set of numbers both functions read (n.params), so the dip and the river
|
|
24
24
|
// ground type cannot drift apart
|
|
25
25
|
params: { river: { amp: 6, freq: 0.09, shift: 2, dip: 3.2, wet: 2.4 } },
|
|
@@ -45,8 +45,8 @@ const island = {
|
|
|
45
45
|
|
|
46
46
|
// ---------- 2. Engine: no placeholder lights, open-world preset with a fixed sky; a two-season calendar so snow can turn the island white ----------
|
|
47
47
|
const WINTER_DAY = 1001; // seasons last 1000 days each, so the season never blends towards the next one (it does over the last 20%)
|
|
48
|
-
const engine = createEngine({ bindings: { ...presets.bindings.debug }, canvas: /** @type {HTMLCanvasElement} */ (document.getElementById('view')), lights: false, saveKey: 'threedog-
|
|
49
|
-
ui: { loading: { title: '
|
|
48
|
+
const engine = createEngine({ bindings: { ...presets.bindings.debug }, canvas: /** @type {HTMLCanvasElement} */ (document.getElementById('view')), lights: false, saveKey: 'threedog-perf-island',
|
|
49
|
+
ui: { loading: { title: 'perf island' } } });
|
|
50
50
|
engine.use(openWorld({ camera: fixedCamera(), terrain: island, water: false, rigid: false, ambience: false,
|
|
51
51
|
calendar: { ...presets.calendar.fixedTime, time: 0.5, seasons: ['summer', 'winter'], daysPerSeason: 1000 },
|
|
52
52
|
weather: { ...presets.weather.temperate, start: 'clear' }, autoWeather: false }), content());
|
|
@@ -63,7 +63,7 @@ engine.onFrame(() => {
|
|
|
63
63
|
|
|
64
64
|
// ---------- 4. Views: an op, so the URL, the dev bridge and tests switch the same way ----------
|
|
65
65
|
const state = { view: params.view };
|
|
66
|
-
engine.ops.define('
|
|
66
|
+
engine.ops.define('island.view', {
|
|
67
67
|
desc: 'Move the camera to a named view: overview, flock, field, river, rim', args: { name: 'string' },
|
|
68
68
|
can: (e, { name }) => VIEW_NAMES.includes(name) ? true : 'unknownView',
|
|
69
69
|
run: (e, { name }) => {
|
|
@@ -74,9 +74,9 @@ engine.ops.define('sheepisland.view', {
|
|
|
74
74
|
},
|
|
75
75
|
reasons: { unknownView: 'View names: overview, flock, field, river, rim' },
|
|
76
76
|
});
|
|
77
|
-
engine.describe.add('
|
|
78
|
-
engine.events.on('engine:ready', () => engine.ops.run('
|
|
79
|
-
if (params.badView) console.warn(`
|
|
77
|
+
engine.describe.add('perf-island', () => ({ view: state.view, season: engine.calendar.season, weather: engine.weather?.name }));
|
|
78
|
+
engine.events.on('engine:ready', () => engine.ops.run('island.view', { name: params.view }));
|
|
79
|
+
if (params.badView) console.warn(`perf-island: unknown view '${params.badView}', showing overview. Views: ${VIEW_NAMES.join(', ')}`);
|
|
80
80
|
|
|
81
81
|
engine.start();
|
|
82
82
|
Object.assign(window, { engine, picture }); // handy for debugging in the browser console
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//
|
|
1
|
+
// perf-island procedural models: a round tree, a sheep, a wheat tuft. Built in code, no files; registered as an asset pack (assets.js).
|
|
2
2
|
// Colors and materials come by name from picture/, so a picture change never touches this file.
|
|
3
3
|
// Shapes are clusters of smooth spheres: the reference reads as soft blobs, not facets. Shadow flags are set here (the engine does not guess them).
|
|
4
4
|
import { THREE, mergeColored } from '../../index.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// URL parameters of the
|
|
1
|
+
// URL parameters of the perf island page. Import this file first in main.js: it rewrites word values into the forms the engine's own
|
|
2
2
|
// URL state understands (time=dusk -> 18:30, weather=雪 -> snow) before createEngine reads the URL. Same words as the style test page.
|
|
3
3
|
// time day | dusk | night (白天 黄昏 夜晚), or HH:MM weather clear | snow (晴 雪), or any engine weather name
|
|
4
4
|
// view overview | flock | field | river | rim (总览 羊群 麦田 河 边缘)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @ts-check
|
|
2
|
-
// The picture of
|
|
2
|
+
// The picture of perf island: wiring only. Each part writes plain three.js from the signals; one onRender drives them all.
|
|
3
3
|
import { EXPOSURE, TONE_MAPPING } from './palette.js';
|
|
4
4
|
import { createLights } from './lights.js';
|
|
5
5
|
import { createMaterials } from './materials.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @ts-check
|
|
2
|
-
//
|
|
2
|
+
// Perf island palette: every color and key value of the picture, one copy. A soft painted diorama: few flat colors, soft shadows, a pale warm
|
|
3
3
|
// backdrop with no horizon. The other files here read these; the island's shape is the game's terrain() in ../main.js, never here.
|
|
4
4
|
import { THREE } from '../../../index.js';
|
|
5
5
|
|
|
@@ -8,7 +8,7 @@ export const COLORS = { leaf: 0x6fa64a, leafLight: 0x8fbf5c, bark: 0x8a6448, woo
|
|
|
8
8
|
|
|
9
9
|
/** How the ground is colored, spread into terrain({...}) in main.js: the workers bake these into the chunks, so they go in at the start */
|
|
10
10
|
export const GROUND = {
|
|
11
|
-
shading: /** @type {const} */ ('texture'), colorResolution: 256, // crisp river bank and field edge without more triangles (recipe
|
|
11
|
+
shading: /** @type {const} */ ('texture'), colorResolution: 256, // crisp river bank and field edge without more triangles (recipe 53); 128 (0.5 m pixels) shows stairs up close
|
|
12
12
|
colors: { grassA: 0x92c062, grassB: 0x86b658, river: 0x6aa6d6, riverDeep: 0x5b97ca, wheatA: 0xdcae48, wheatB: 0xd2a442, earth: 0xb98d64, rock: 0x94705a },
|
|
13
13
|
biomeColors: { grass: ['grassA', 'grassB'], river: ['river', 'riverDeep'], wheat: ['wheatA', 'wheatB'], cliff: ['earth'], rock: ['rock'] },
|
|
14
14
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Named camera positions of the
|
|
1
|
+
// Named camera positions of the perf island. Same name = same framing every time, so two screenshots differ only by time or weather.
|
|
2
2
|
// The island is centred on (0, 0) and is about 60 m across; positions are [x, y, z] in world space.
|
|
3
3
|
export const VIEWS = {
|
|
4
4
|
overview: { pos: [0, 36, 48], look: [0, -1, 0] }, // the whole island floating on the backdrop, from the south, a little above
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Game map: plain-picture (generated, do not edit by hand)
|
|
2
2
|
|
|
3
3
|
> Generated by `npm run map` by scanning this folder; paths are relative to it. Pages: /plain-picture.html, entry `main.js`.
|
|
4
|
-
> Content data is in `content/*.js` (condition/effect syntax: `node_modules/threedog/docs/recipes/20-content-actions-save.md`), which main.js hands to the engine with `engine.content.load()`;
|
|
4
|
+
> Content data is in `content/*.js` (condition/effect syntax: `node_modules/threedog/docs/recipes/20-content-actions-save.md`), which main.js hands to the engine with `engine.content.load()`; to look up a name: the module pages listed below (`node_modules/threedog/docs/API.md` indexes them).
|
|
5
5
|
|
|
6
6
|
Content: none (no content/ folder)
|
|
7
7
|
|
|
@@ -14,12 +14,14 @@ None yet, write them in `DESIGN.md` (why it is designed this way, what not to ch
|
|
|
14
14
|
- createEngine: { ui: { loading: false }, saveKey: 'threedog-plain-picture', lights: false }
|
|
15
15
|
- calendar ({ ...presets.calendar.fixedTime, time: '22:00' })
|
|
16
16
|
- sky
|
|
17
|
+
- weather ({ types: { clear: {}, rain: { rain: 1, cloud: 0.8, fog: 0.6 } } })
|
|
17
18
|
- fixedCamera ({ shots: { street: { position: [2.5, 1.8, 14], lookAt: [-1, 2.6, -20] } }, start: 'street' })
|
|
18
19
|
|
|
19
20
|
## Read for this game (per installed module: recipe · api page; core API: `node_modules/threedog/docs/api/engine.md`)
|
|
20
21
|
|
|
21
22
|
- calendar: `node_modules/threedog/docs/recipes/06-clock-events.md` · `node_modules/threedog/docs/api/calendar.md`
|
|
22
23
|
- sky: `node_modules/threedog/docs/recipes/08-weather-sky.md` · `node_modules/threedog/docs/api/sky.md`
|
|
24
|
+
- weather: `node_modules/threedog/docs/recipes/44-water-weather-hooks.md` · `node_modules/threedog/docs/api/weather.md`
|
|
23
25
|
- cameraRig: `node_modules/threedog/docs/recipes/21-camera.md` · `node_modules/threedog/docs/api/cameraRig.md`
|
|
24
26
|
|
|
25
27
|
Not used yet (check these before writing the system yourself):
|
|
@@ -30,6 +32,7 @@ Not used yet (check these before writing the system yourself):
|
|
|
30
32
|
- saves: save your own state: `engine.saves.register(key, { version, save, load })` (node_modules/threedog/docs/recipes/20-content-actions-save.md)
|
|
31
33
|
- interactions: press a key near a thing: `interactions({ ...presets.interactions.nearest })` (E, nearest; the game picks the pick mode and keys), template `interact: { label, op }` (node_modules/threedog/docs/recipes/30-templates.md)
|
|
32
34
|
- quests: goals with steps, conditions and rewards: `quests()` + key map presets.bindings.quests, content/quests.js (node_modules/threedog/docs/recipes/04-quests.md)
|
|
35
|
+
- swarm: many same-kind moving things (shots, crowds, flocks, debris) in typed arrays, drawn as one mesh: `swarm()` (node_modules/threedog/docs/recipes/65-swarm.md)
|
|
33
36
|
- grids: cell placement for farming and building: `grids()` (node_modules/threedog/docs/recipes/29-grid.md)
|
|
34
37
|
- templates: reusable objects placed from content: content/templates.js + props { template } (node_modules/threedog/docs/recipes/30-templates.md)
|
|
35
38
|
|