threedog 0.2.1 → 0.5.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 +290 -0
- package/README.md +9 -8
- package/core/Animator.js +15 -12
- package/core/Assets.js +71 -16
- package/core/Audio.js +45 -38
- package/core/Baked.js +32 -8
- package/core/Batching.js +102 -15
- package/core/Budget.js +39 -18
- package/core/Clock.js +40 -80
- package/core/DebugOverrides.js +45 -10
- package/core/Describe.js +104 -43
- package/core/Engine.js +183 -59
- package/core/Events.js +4 -1
- package/core/I18n.js +25 -13
- package/core/Input.js +168 -79
- package/core/Inspect.js +2 -2
- package/core/InspectMaterials.js +85 -0
- package/core/InspectPerf.js +61 -0
- package/core/InspectScene.js +13 -2
- package/core/Loading.js +2 -1
- package/core/Ops.js +50 -9
- package/core/Random.js +9 -2
- package/core/Rays.js +5 -5
- package/core/SaveStore.js +41 -9
- package/core/Saves.js +71 -15
- package/core/Stream.js +14 -10
- package/core/Threads.js +26 -7
- package/core/UrlState.js +25 -9
- package/core/Views.js +9 -6
- package/core/actor.js +1 -1
- package/core/adaptive.js +93 -0
- package/core/assetEntry.js +22 -5
- package/core/assetHot.js +176 -0
- package/core/assetLoad.js +38 -11
- package/core/assetManifest.js +48 -9
- package/core/assetReport.js +1 -1
- package/core/audioRules.js +13 -11
- package/core/audioVoice.js +69 -42
- package/core/canvasBox.js +1 -2
- package/core/catalog.js +5 -2
- package/core/cells.js +62 -0
- package/core/checks.js +10 -8
- package/core/chunkStream.js +87 -0
- package/core/control.js +149 -0
- package/core/copies.js +32 -0
- package/core/dayTime.js +12 -6
- package/core/debugView.js +82 -15
- package/core/describeRender.js +37 -17
- package/core/describeText.js +41 -21
- package/core/engineCamera.js +32 -0
- package/core/errorCodes.js +438 -19
- package/core/errorHints.js +37 -141
- package/core/errors.js +31 -8
- package/core/events.generated.js +12 -7
- package/core/gameLights.js +62 -0
- package/core/grayMap.js +20 -0
- package/core/grid.js +14 -13
- package/core/gridLoad.js +2 -1
- package/core/ground.js +6 -4
- package/core/headlessLoad.js +55 -0
- package/core/holds.js +78 -50
- package/core/inputContext.js +11 -7
- package/core/inputDefaults.js +24 -21
- package/core/inputPad.js +1 -1
- package/core/inputPointer.js +1 -1
- package/core/inputTouch.js +2 -2
- package/core/lifecycle.js +48 -12
- package/core/lightWatch.js +6 -4
- package/core/look/coreParts.js +137 -30
- package/core/look/part.js +175 -95
- package/core/look/points.js +255 -0
- package/core/look/report.js +34 -17
- package/core/look/shadowPart.js +63 -0
- package/core/look/state.js +45 -0
- package/core/look/write.js +12 -28
- package/core/loop.js +100 -41
- package/core/math.js +11 -3
- package/core/moduleSlots.js +75 -0
- package/core/moduleTypes.js +73 -0
- package/core/modules.js +145 -27
- package/core/movement.js +2 -2
- package/core/namedModel.js +70 -0
- package/core/opsCheck.js +3 -3
- package/core/opsFail.js +15 -6
- package/core/opsGuard.js +4 -4
- package/core/opsRun.js +4 -3
- package/core/owned.js +168 -0
- package/core/page.js +2 -1
- package/core/params.js +30 -8
- package/core/plugins.js +277 -0
- package/core/saveApply.js +99 -17
- package/core/saveFiles.js +8 -6
- package/core/saveValues.js +46 -0
- package/core/saveVersions.js +20 -3
- package/core/scatter.js +48 -19
- package/core/sceneDelta.js +203 -0
- package/core/sceneMethods.js +35 -30
- package/core/screenToGround.js +1 -1
- package/core/services.js +27 -11
- package/core/session.js +28 -25
- package/core/shaderCost.js +78 -0
- package/core/shadowTypes.js +2 -1
- package/core/sharedPoint.js +317 -0
- package/core/skip.js +36 -28
- package/core/stackFrames.js +34 -0
- package/core/stacks.js +166 -0
- package/core/startup.js +153 -11
- package/core/streamSources.js +0 -11
- package/core/styleParts.js +63 -47
- package/core/targeting.js +1 -1
- package/core/textureBytes.js +20 -0
- package/core/thingExplain.js +2 -2
- package/core/thingOps.js +29 -6
- package/core/things.js +21 -11
- package/core/threadPure.js +7 -3
- package/core/threePatches.js +47 -0
- package/core/tier.js +21 -10
- package/core/time.js +236 -0
- package/core/uiClock.js +25 -0
- package/core/util.js +7 -1
- package/core/validate.js +65 -86
- package/core/wrap.js +106 -0
- package/docs/AI.md +87 -100
- package/docs/API.md +32 -28
- package/docs/CODEMAP.md +220 -147
- package/docs/COMMANDS.md +56 -35
- package/docs/CONVENTIONS.md +90 -28
- package/docs/MIGRATING-0.3.md +248 -0
- package/docs/MIGRATING-0.4.md +228 -0
- package/docs/MIGRATING-0.5.md +68 -0
- package/docs/PERF.md +35 -7
- package/docs/THREE.md +79 -27
- package/docs/api/ambience.md +0 -1
- package/docs/api/assets.md +11 -9
- package/docs/api/audio.md +10 -14
- package/docs/api/calendar.md +41 -0
- package/docs/api/cameraRig.md +16 -5
- package/docs/api/characters.md +38 -23
- package/docs/api/clock.md +6 -5
- package/docs/api/collision.md +9 -6
- package/docs/api/content.md +6 -4
- package/docs/api/dialogue.md +9 -9
- package/docs/api/engine.md +63 -60
- package/docs/api/events.md +19 -14
- package/docs/api/grids.md +3 -3
- package/docs/api/ground.md +1 -1
- package/docs/api/hud.md +2 -2
- package/docs/api/i18n.md +1 -1
- package/docs/api/input.md +11 -6
- package/docs/api/interactions.md +7 -5
- package/docs/api/inventory.md +17 -16
- package/docs/api/level.md +0 -1
- package/docs/api/lightPool.md +3 -1
- package/docs/api/music.md +1 -1
- package/docs/api/nav.md +3 -0
- package/docs/api/openWorld.md +2 -1
- package/docs/api/particles.md +2 -2
- package/docs/api/photo.md +0 -2
- package/docs/api/pickups.md +15 -0
- package/docs/api/post.md +5 -4
- package/docs/api/quests.md +2 -3
- package/docs/api/rigid.md +16 -14
- package/docs/api/saves.md +6 -4
- package/docs/api/settings.md +2 -3
- package/docs/api/sky.md +11 -44
- package/docs/api/stream.md +1 -1
- package/docs/api/style.md +28 -26
- package/docs/api/terrain.md +9 -6
- package/docs/api/terrainLook.md +10 -0
- package/docs/api/timeline.md +3 -4
- package/docs/api/tools.md +29 -13
- package/docs/api/triggers.md +5 -10
- package/docs/api/vegetation.md +11 -8
- package/docs/api/vegetationLook.md +10 -0
- package/docs/api/water.md +4 -20
- package/docs/api/weather.md +5 -15
- package/docs/api/weatherLook.md +10 -0
- package/docs/api/world.md +2 -1
- package/docs/recipes/01-new-game.md +48 -34
- package/docs/recipes/02-npc.md +24 -7
- package/docs/recipes/03-items-pickups.md +35 -21
- package/docs/recipes/04-quests.md +12 -5
- package/docs/recipes/05-props-bake.md +151 -15
- package/docs/recipes/06-clock-events.md +100 -52
- package/docs/recipes/07-flow-scenes-pause.md +40 -9
- package/docs/recipes/08-weather-sky.md +145 -36
- package/docs/recipes/{09-style-pack.md → 09-style.md} +101 -52
- package/docs/recipes/10-blender-level.md +14 -2
- package/docs/recipes/11-vehicles.md +64 -7
- package/docs/recipes/13-animation.md +14 -6
- package/docs/recipes/14-custom-module.md +61 -29
- package/docs/recipes/15-perf.md +30 -9
- package/docs/recipes/16-dev-bridge.md +61 -37
- package/docs/recipes/18-world.md +16 -6
- package/docs/recipes/19-shooting-picking.md +6 -6
- package/docs/recipes/20-content-actions-save.md +55 -17
- package/docs/recipes/21-camera.md +49 -16
- package/docs/recipes/22-shop-gold.md +3 -3
- package/docs/recipes/23-ops.md +16 -10
- package/docs/recipes/26-ui-parts.md +61 -12
- package/docs/recipes/27-net.md +11 -5
- package/docs/recipes/28-terrain.md +34 -1
- package/docs/recipes/29-grid.md +34 -16
- package/docs/recipes/30-templates.md +64 -12
- package/docs/recipes/31-audio.md +20 -12
- package/docs/recipes/32-action-game.md +35 -2
- package/docs/recipes/34-environment-lighting.md +26 -3
- package/docs/recipes/35-style-from-reference.md +88 -19
- package/docs/recipes/36-sky-ground-plant-looks.md +18 -18
- package/docs/recipes/37-terrain-look-hooks.md +3 -2
- package/docs/recipes/38-environment-look-hooks.md +37 -26
- package/docs/recipes/40-scene.md +16 -13
- package/docs/recipes/41-thing-registry.md +11 -7
- package/docs/recipes/42-terrain-shape.md +2 -2
- package/docs/recipes/43-shader-patches-surface-looks.md +158 -76
- package/docs/recipes/44-water-weather-look-hooks.md +26 -17
- package/docs/recipes/45-cascaded-shadows.md +16 -7
- package/docs/recipes/47-island-snow-backdrop.md +7 -7
- package/docs/recipes/48-make-material.md +11 -6
- package/docs/recipes/49-game-module-contract.md +30 -17
- package/docs/recipes/50-own-renderer.md +2 -2
- package/docs/recipes/51-capability-catalog.md +3 -3
- package/docs/recipes/52-look.md +197 -61
- package/docs/recipes/53-ground-up-close.md +1 -1
- package/docs/recipes/54-three-idioms.md +88 -0
- package/docs/recipes/55-mods-time-wrap.md +112 -0
- package/docs/recipes/56-webgpu-tsl.md +260 -0
- package/docs/recipes/57-control.md +65 -0
- package/docs/recipes/58-input.md +57 -0
- package/docs/recipes/59-depth-post-effects.md +83 -0
- package/docs/recipes/60-judge-the-picture.md +55 -0
- package/examples/action/.threedog/content-index.json +1 -0
- package/examples/action/GAMEMAP.md +17 -13
- package/examples/action/assets.js +8 -0
- package/examples/action/content/actions.js +1 -1
- package/examples/action/content/audio.js +5 -5
- package/examples/action/look.js +1 -1
- package/examples/action/main.js +10 -14
- package/examples/action/models.js +24 -23
- package/examples/pullable.json +111 -0
- package/examples/rc2d/.threedog/content-index.json +1 -0
- package/examples/rc2d/GAMEMAP.md +83 -0
- package/examples/rc2d/README.md +52 -0
- package/examples/rc2d/main.js +63 -0
- package/examples/rc2d/rc2d.js +197 -0
- package/examples/rc2d/shaders.js +144 -0
- package/examples/sheepisland/.threedog/content-index.json +1 -0
- package/examples/sheepisland/GAMEMAP.md +13 -11
- package/examples/sheepisland/assets.js +5 -0
- package/examples/sheepisland/main.js +17 -12
- package/examples/sheepisland/style/index.js +6 -6
- package/examples/styletest/.threedog/content-index.json +1 -0
- package/examples/styletest/GAMEMAP.md +15 -16
- package/examples/styletest/assets.js +6 -0
- package/examples/styletest/content/templates.js +1 -1
- package/examples/styletest/content/vegetation.js +1 -1
- package/examples/styletest/look.js +1 -1
- package/examples/styletest/main.js +17 -16
- package/examples/styletest/models.js +1 -1
- package/examples/styletest/params.js +3 -3
- package/examples/techniques/contact-shadows/README.md +92 -0
- package/examples/techniques/contact-shadows/contactShadows.js +51 -0
- package/examples/techniques/contact-shadows/main.js +53 -0
- package/examples/techniques/day-night-grade/README.md +86 -0
- package/examples/techniques/day-night-grade/dayNightGrade.js +76 -0
- package/examples/techniques/day-night-grade/main.js +51 -0
- package/examples/techniques/interior-light/README.md +103 -0
- package/examples/techniques/interior-light/interiorLight.js +45 -0
- package/examples/techniques/interior-light/main.js +124 -0
- package/examples/techniques/modular-building/README.md +125 -0
- package/examples/techniques/modular-building/kit.js +426 -0
- package/examples/techniques/modular-building/main.js +47 -0
- package/examples/techniques/night-lights/README.md +94 -0
- package/examples/techniques/night-lights/main.js +70 -0
- package/examples/techniques/night-lights/nightLights.js +91 -0
- package/examples/techniques/outlines-and-rim/README.md +59 -0
- package/examples/techniques/outlines-and-rim/main.js +84 -0
- package/examples/techniques/outlines-and-rim/outlines.js +64 -0
- package/examples/techniques/procedural-animation/README.md +77 -0
- package/examples/techniques/procedural-animation/creature.js +44 -0
- package/examples/techniques/procedural-animation/main.js +45 -0
- package/examples/techniques/procedural-animation/proceduralAnim.js +118 -0
- package/examples/techniques/procedural-surface/README.md +67 -0
- package/examples/techniques/procedural-surface/main.js +103 -0
- package/examples/techniques/procedural-surface/surface.js +120 -0
- package/examples/techniques/stylized-shading/README.md +75 -0
- package/examples/techniques/stylized-shading/main.js +93 -0
- package/examples/techniques/stylized-shading/shading.js +131 -0
- package/examples/techniques/sun-and-key-light/README.md +135 -0
- package/examples/techniques/sun-and-key-light/keyLight.js +53 -0
- package/examples/techniques/sun-and-key-light/main.js +95 -0
- package/examples/techniques/wet-road/README.md +99 -0
- package/examples/techniques/wet-road/main.js +68 -0
- package/examples/techniques/wet-road/wetRoad.js +209 -0
- package/examples/webgpu-tsl/.threedog/content-index.json +1 -0
- package/examples/webgpu-tsl/GAMEMAP.md +84 -0
- package/examples/webgpu-tsl/README.md +42 -0
- package/examples/webgpu-tsl/main.js +21 -0
- package/examples/webgpu-tsl/tslScene.js +75 -0
- package/examples/world/.threedog/content-index.json +1 -0
- package/examples/world/GAMEMAP.md +22 -15
- package/examples/world/art/humanoid.js +42 -0
- package/examples/world/art/index.js +11 -0
- package/examples/world/art/models.js +58 -0
- package/examples/world/art/shapes.js +9 -0
- package/examples/world/assets.js +6 -0
- package/examples/world/content/audio.js +5 -5
- package/examples/world/content/npcs.js +1 -1
- package/examples/world/content/props.js +1 -1
- package/examples/world/content/rules.js +1 -1
- package/examples/world/content/templates.js +1 -1
- package/examples/world/content/vegetation.js +1 -1
- package/examples/world/main.js +17 -13
- package/examples/world/style/index.js +61 -0
- package/examples/world/style/plugins/10-bloom.js +5 -0
- package/index.d.ts +44 -45
- package/index.js +26 -22
- package/llms.txt +11 -4
- package/modules/ambience/Ambience.js +34 -23
- package/modules/calendar/Calendar.js +163 -0
- package/modules/calendar/contract.js +21 -0
- package/modules/calendar/index.js +81 -0
- package/modules/{sky → calendar}/schedule.js +17 -16
- package/modules/calendar/seasons.js +55 -0
- package/modules/camera/FirstPersonCamera.js +6 -15
- package/modules/camera/FixedCamera.js +33 -15
- package/modules/camera/FollowCamera.js +90 -16
- package/modules/camera/RtsCamera.js +18 -17
- package/modules/camera/common.js +70 -19
- package/modules/camera/contract.js +17 -0
- package/modules/camera/projection.js +11 -24
- package/modules/characters/Character.js +177 -42
- package/modules/characters/NPC.js +87 -36
- package/modules/characters/assetModel.js +4 -13
- package/modules/characters/behaviors.js +2 -1
- package/modules/characters/contract.js +13 -0
- package/modules/characters/footsteps.js +1 -1
- package/modules/characters/index.js +87 -49
- package/modules/characters/moveHelpers.js +4 -5
- package/modules/characters/movers/common.js +97 -19
- package/modules/characters/movers/manual.js +20 -0
- package/modules/characters/movers/rapier.js +19 -16
- package/modules/characters/movers/simple.js +14 -11
- package/modules/characters/movers/support.js +172 -0
- package/modules/characters/npcAvoid.js +47 -42
- package/modules/characters/npcSim.js +12 -8
- package/modules/characters/npcView.js +44 -16
- package/modules/characters/pathAsync.js +7 -3
- package/modules/characters/playerStrings.js +4 -3
- package/modules/characters/proceduralRig.js +2 -1
- package/modules/characters/useModel.js +1 -1
- package/modules/characters/vehicle.contract.js +21 -0
- package/modules/characters/walkTo.js +21 -7
- package/modules/collision/Collision.js +65 -25
- package/modules/collision/grid.js +8 -6
- package/modules/content/explain.js +2 -2
- package/modules/content/fields.js +102 -0
- package/modules/content/ids.js +8 -6
- package/modules/content/index.js +96 -27
- package/modules/content/loader.js +45 -33
- package/modules/content/models.js +11 -40
- package/modules/content/packs.js +6 -5
- package/modules/content/parts.js +41 -0
- package/modules/content/props.js +16 -9
- package/modules/content/rules.js +58 -0
- package/modules/content/stages.js +80 -0
- package/modules/content/templates.js +121 -30
- package/modules/debug/DebugPanel.js +24 -17
- package/modules/flow/contract.js +16 -0
- package/modules/flow/index.js +21 -15
- package/modules/gameplay/Container.js +41 -32
- package/modules/gameplay/Containers.js +30 -15
- package/modules/gameplay/Dialogue.js +113 -55
- package/modules/gameplay/Interactions.js +193 -67
- package/modules/gameplay/Inventory.js +69 -73
- package/modules/gameplay/Quests.js +75 -39
- package/modules/gameplay/boxOps.js +3 -3
- package/modules/gameplay/dialogue.contract.js +21 -0
- package/modules/gameplay/dialogueBox.js +4 -2
- package/modules/gameplay/dialogueBubbles.js +116 -0
- package/modules/gameplay/interactionPrompt.js +4 -1
- package/modules/gameplay/interactions.contract.js +16 -0
- package/modules/gameplay/inventory.contract.js +23 -0
- package/modules/gameplay/inventoryOps.js +18 -16
- package/modules/gameplay/pickups.js +268 -85
- package/modules/gameplay/questLog.js +4 -4
- package/modules/gameplay/quests.contract.js +17 -0
- package/modules/grid/Grid.js +92 -50
- package/modules/grid/Layer.js +14 -13
- package/modules/grid/index.js +60 -36
- package/modules/grid/ops.js +20 -18
- package/modules/grid/preview.js +15 -16
- package/modules/grid/strings.js +12 -0
- package/modules/grid/tiles.js +6 -5
- package/modules/hlod/index.js +51 -19
- package/modules/hud/index.js +35 -20
- package/modules/hud/parts.js +20 -7
- package/modules/level/heightfield.js +3 -1
- package/modules/level/index.js +45 -20
- package/modules/level/nodes.js +4 -3
- package/modules/lights/index.js +42 -18
- package/modules/music/Music.js +38 -21
- package/modules/music/rules.js +1 -1
- package/modules/nav/index.js +48 -42
- package/modules/net/Client.js +13 -6
- package/modules/net/Host.js +19 -5
- package/modules/net/Net.js +2 -1
- package/modules/net/index.js +13 -8
- package/modules/net/sync.js +9 -8
- package/modules/net/transports.js +77 -27
- package/modules/particles/Particles.js +23 -14
- package/modules/particles/contract.js +17 -0
- package/modules/particles/effect.js +39 -11
- package/modules/photo/Photo.js +53 -36
- package/modules/rigid/RigidBodies.js +194 -32
- package/modules/rigid/Vehicles.js +18 -15
- package/modules/rigid/sync.js +62 -17
- package/modules/settings/Settings.js +57 -52
- package/modules/settings/apply.js +38 -3
- package/modules/settings/sections.js +5 -3
- package/modules/settings/strings.js +3 -2
- package/modules/settings/view.js +5 -3
- package/modules/sky/Sky.js +88 -176
- package/modules/sky/cascades.js +86 -25
- package/modules/sky/cascades.tsl.js +82 -0
- package/modules/sky/clouds.js +34 -19
- package/modules/sky/domeLayers.js +30 -15
- package/modules/sky/environment.js +83 -13
- package/modules/sky/fog.js +140 -95
- package/modules/sky/frame.js +112 -44
- package/modules/sky/look.js +22 -19
- package/modules/sky/lookFog.js +48 -52
- package/modules/sky/lookShadow.js +53 -41
- package/modules/sky/lookSky.js +82 -21
- package/modules/sky/season.js +21 -0
- package/modules/sky/shader.js +41 -19
- package/modules/sky/shadow.js +44 -20
- package/modules/sky/skyModule.js +45 -33
- package/modules/sky/tint.js +61 -0
- package/modules/terrain/ChunkManager.js +175 -108
- package/modules/terrain/chunkJob.js +1 -1
- package/modules/terrain/chunkQueries.js +6 -4
- package/modules/terrain/index.js +105 -50
- package/modules/terrain/look.js +83 -0
- package/modules/terrain/lookGround.js +21 -16
- package/modules/terrain/terrainDefaults.js +1 -1
- package/modules/terrain/terrainEdit.js +18 -20
- package/modules/terrain/terrainGen.js +5 -3
- package/modules/terrain/terrainIsland.js +5 -4
- package/modules/terrain/terrainShape.js +12 -12
- package/modules/terrain/terrainShapeMain.js +8 -7
- package/modules/terrain/terrainTexture.js +21 -19
- package/modules/timeline/Timeline.js +95 -43
- package/modules/timeline/Tween.js +18 -10
- package/modules/timeline/letterbox.js +2 -2
- package/modules/timeline/shots.js +5 -1
- package/modules/triggers/index.js +107 -76
- package/modules/vegetation/Vegetation.js +186 -110
- package/modules/vegetation/densityMap.js +62 -0
- package/modules/vegetation/groundChunks.js +52 -58
- package/modules/vegetation/index.js +32 -11
- package/modules/vegetation/look.js +119 -0
- package/modules/vegetation/lookWind.js +71 -10
- package/modules/vegetation/modelGeometry.js +3 -2
- package/modules/vegetation/nearFade.js +8 -2
- package/modules/water/Water.js +65 -27
- package/modules/water/look.js +29 -18
- package/modules/water/surface.js +64 -25
- package/modules/water/surfaceDefaults.js +3 -0
- package/modules/weather/Weather.js +62 -104
- package/modules/weather/look.js +1 -2
- package/modules/weather/particles.js +24 -9
- package/modules/weather/strings.js +2 -2
- package/modules/weather/weatherLook.js +135 -0
- package/modules/world/World.js +24 -7
- package/modules/world/explain.js +1 -1
- package/modules/world/index.js +18 -4
- package/modules/world/persist.js +62 -2
- package/modules/world/pos.js +3 -2
- package/modules/world/records.js +8 -6
- package/modules/world/sim.js +60 -20
- package/modules/world/simFar.js +4 -3
- package/modules/world/state.js +3 -2
- package/modules/world/thingSource.js +1 -1
- package/modules/world/views.js +7 -5
- package/package.json +7 -3
- package/presets.js +41 -27
- package/render/PostFX.js +145 -120
- package/render/backend.js +440 -0
- package/render/detail.js +120 -39
- package/render/effects.js +130 -38
- package/render/engineUniforms.js +10 -1
- package/render/fuse.js +5 -4
- package/render/fx/cloudShadow.tsl.js +16 -0
- package/render/fx/detail.tsl.js +66 -0
- package/render/fx/index.js +26 -0
- package/render/fx/lighting.tsl.js +28 -0
- package/render/fx/nodeErrors.tsl.js +68 -0
- package/render/fx/noise.tsl.js +12 -0
- package/render/fx/objectOrigin.tsl.js +42 -0
- package/render/fx/particles.tsl.js +139 -0
- package/render/fx/patchNodes.tsl.js +403 -0
- package/render/fx/postWebGPU.tsl.js +158 -0
- package/render/fx/season.tsl.js +13 -0
- package/render/fx/sky.tsl.js +260 -0
- package/render/fx/uniforms.tsl.js +67 -0
- package/render/fx/water.tsl.js +53 -0
- package/render/fx/wind.tsl.js +22 -0
- package/render/fxNumbers.js +36 -0
- package/render/hotGlsl.js +24 -0
- package/render/lighting.js +66 -14
- package/render/lights.js +223 -4
- package/render/lookGlow.js +139 -0
- package/render/lookSurface.js +99 -36
- package/render/materials.js +71 -52
- package/render/modeling.js +73 -0
- package/render/ownFrame.js +76 -0
- package/render/patches.js +311 -34
- package/render/postLook.js +124 -46
- package/render/postWebGL.js +197 -0
- package/render/probes.js +231 -0
- package/render/shaderErrors.js +154 -0
- package/render/slots.js +165 -0
- package/render/surface.js +53 -17
- package/render/terms.js +211 -0
- package/render/uniformDecl.js +3 -2
- package/types/common.d.ts +2 -2
- package/types/core.d.ts +614 -240
- package/types/gameplay.d.ts +482 -312
- package/types/generated/core/Audio.d.ts +26 -42
- package/types/generated/core/Batching.d.ts +6 -2
- package/types/generated/core/Budget.d.ts +2 -8
- package/types/generated/core/DebugOverrides.d.ts +44 -3
- package/types/generated/core/I18n.d.ts +2 -2
- package/types/generated/core/Input.d.ts +102 -31
- package/types/generated/core/Ops.d.ts +31 -0
- package/types/generated/core/Random.d.ts +2 -2
- package/types/generated/core/Saves.d.ts +10 -2
- package/types/generated/core/Stream.d.ts +1 -1
- package/types/generated/core/Threads.d.ts +4 -1
- package/types/generated/core/Views.d.ts +0 -1
- package/types/generated/core/audioVoice.d.ts +17 -9
- package/types/generated/core/control.d.ts +55 -0
- package/types/generated/core/session.d.ts +2 -1
- package/types/generated/modules/ambience/Ambience.d.ts +0 -9
- package/types/generated/modules/calendar/Calendar.d.ts +84 -0
- package/types/generated/modules/calendar/index.d.ts +10 -0
- package/types/generated/modules/debug/DebugPanel.d.ts +2 -2
- package/types/generated/modules/grid/Grid.d.ts +61 -25
- package/types/generated/modules/grid/Layer.d.ts +5 -5
- package/types/generated/modules/grid/index.d.ts +29 -17
- package/types/generated/modules/music/Music.d.ts +5 -3
- package/types/generated/modules/net/index.d.ts +3 -3
- package/types/generated/modules/net/transports.d.ts +12 -3
- package/types/generated/modules/particles/Particles.d.ts +1 -1
- package/types/generated/modules/sky/Sky.d.ts +12 -104
- package/types/generated/modules/sky/skyModule.d.ts +1 -1
- package/types/generated/modules/timeline/Timeline.d.ts +8 -6
- package/types/generated/modules/weather/Weather.d.ts +17 -18
- package/types/generated/modules/weather/weatherLook.d.ts +12 -0
- package/types/generated/modules/world/World.d.ts +18 -3
- package/types/generated/render/PostFX.d.ts +67 -30
- package/types/generated/render/materials.d.ts +26 -20
- package/types/generated/render/modeling.d.ts +30 -0
- package/types/generated/render/patches.d.ts +16 -2
- package/types/generated/ui/UI.d.ts +6 -3
- package/types/nav.d.ts +6 -0
- package/types/physics.d.ts +137 -44
- package/types/style.d.ts +109 -81
- package/types/tsl.d.ts +86 -0
- package/types/world.d.ts +158 -110
- package/ui/Focus.js +25 -14
- package/ui/LoadingScreen.js +1 -1
- package/ui/Parts.js +27 -11
- package/ui/UI.js +20 -10
- package/ui/cursor.js +115 -0
- package/ui/defaults.js +15 -11
- package/ui/theme.js +9 -6
- package/ui/touchPart.js +1 -1
- package/core/claims.js +0 -51
- package/core/look/layers.js +0 -136
- package/core/renamed.js +0 -22
- package/docs/api/entities.md +0 -61
- package/examples/styletest/overrides.js +0 -33
- package/examples/styletest/panel.js +0 -135
- package/modules/entities/Entities.js +0 -243
- package/modules/entities/build.js +0 -25
- package/modules/entities/index.js +0 -4
- package/modules/sky/calendar.js +0 -80
- package/modules/sky/layers.js +0 -69
- package/modules/terrain/chunkLevels.js +0 -40
- package/modules/terrain/mountTerrain.js +0 -32
- package/modules/world/cells.js +0 -42
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# 2D radiance cascades (optional example)
|
|
2
|
+
|
|
3
|
+
Screen-space global illumination for top-down and side-view games: lamps, lit windows and neon signs light the floor around them, walls block
|
|
4
|
+
that light and cast soft shadows, coloured lights mix. It is an example you copy, not an engine module: the engine never imports it and
|
|
5
|
+
nothing installs it. Run it with `npm run dev` and open `/rc2d.html` (`?quality=low|medium|high`, `cascades=auto|1..8`, `interval=4`, `apply=0`).
|
|
6
|
+
|
|
7
|
+
## When to use it
|
|
8
|
+
- A fixed top-down or side-on camera (orthographic or nearly so) where light should spread over the floor and stop at walls, with many
|
|
9
|
+
or large light shapes (a whole neon bar is one light, at no extra cost per light).
|
|
10
|
+
- Not for a free 3D camera: it only knows what is on screen, in the screen plane. A light off screen gives no light, and height is ignored.
|
|
11
|
+
For a few point lights in 3D, three.js lights (`engine.lightPool` for many) are cheaper and correct.
|
|
12
|
+
|
|
13
|
+
## How to copy it into a game
|
|
14
|
+
1. Copy `rc2d.js` and `shaders.js` into your game (`threedog examples pull rc2d`, or by hand). They import only `three` and `three/addons`.
|
|
15
|
+
2. Put what light sees on one layer: emitters (any mesh with `material.emissive`, strength `emissiveIntensity`) and occluders (meshes
|
|
16
|
+
without emissive). `mesh.layers.enable(5)` keeps them visible to the normal camera too. The floor stays off the layer: it receives light.
|
|
17
|
+
3. `const rc = createRadianceCascades2D(engine, { layer: 5, ambient: 0.15 })`. Each frame it renders in `engine.onRender` and, with `apply`
|
|
18
|
+
(default), one pass in the engine's `hdr` post slot (`engine.look.post.add`) adds the light to the frame: `color * (1 + light / ambient)`.
|
|
19
|
+
Set `ambient` to how bright your scene's own light already is, so the light lands on the surface colour (albedo = color / ambient).
|
|
20
|
+
4. Or `apply: false` and read `rc.texture` (linear light per screen uv) in your own materials. `rc.target` is its render target.
|
|
21
|
+
5. `rc.describe()` (size, cascades, intervals, targets), `rc.resize()` (also checked every frame), `rc.dispose()` (frees every target).
|
|
22
|
+
|
|
23
|
+
Colours and strengths are the game's: change a lamp's `emissiveIntensity` and the light follows the same frame (flicker, day / night).
|
|
24
|
+
`threedog examples pull rc2d` copies the two files and this README into the game (`techniques/rc2d/`), or copy them by hand.
|
|
25
|
+
|
|
26
|
+
## Parameters (all in `RC2D_DEFAULTS` / `RC2D_QUALITY` at the top of `rc2d.js`)
|
|
27
|
+
| Option | Default | Meaning |
|
|
28
|
+
|---|---|---|
|
|
29
|
+
| `quality` | `'medium'` | `low` / `medium` / `high`: resolution 1/4, 1/2, 1x of the canvas (CSS pixels) and 16 / 24 / 32 march steps per ray |
|
|
30
|
+
| `cascades` | `'auto'` | how many cascades; auto = enough for the longest ray to cross the screen diagonal |
|
|
31
|
+
| `interval` | `4` | cascade 0's ray length in RC pixels; each cascade above is 4x longer. Larger = smoother, softer contact light |
|
|
32
|
+
| `layer` | `5` | the three.js layer of emitters and occluders |
|
|
33
|
+
| `ambient` | `1` | the scene's own light level, see step 3 |
|
|
34
|
+
| `apply` | `true` | add the post pass; `false` = only `rc.texture` |
|
|
35
|
+
|
|
36
|
+
## Cost (1280x720 canvas, measured 2026-11-02, the demo scene)
|
|
37
|
+
- GPU (AMD Radeon 780M integrated, D3D11): frame 3.6 ms without, about 15.8 ms with `medium`, 32.6 ms with `high`; `low` about 14 ms
|
|
38
|
+
(at low the fixed cost of ~20 passes dominates). Use `low` or `medium` on integrated graphics.
|
|
39
|
+
- Software rendering (headless SwiftShader): about 16x a plain frame at `medium`; only for tests.
|
|
40
|
+
- Memory: about 10 half-float targets the size of the RC resolution (two float targets for the jump flood).
|
|
41
|
+
|
|
42
|
+
## Limits
|
|
43
|
+
- Screen space: nothing off screen contributes, and what moves off screen stops lighting.
|
|
44
|
+
- Occluder tops stay as the scene lights them (rays start inside them and see no light); light is 2D, so a lamp on a roof lights the
|
|
45
|
+
floor beside the building as if it stood on the ground.
|
|
46
|
+
- Thin occluders under about one RC pixel (2 screen pixels at `medium`) can leak.
|
|
47
|
+
- The merge uses the paper's "bilinear fix" (4 rays per merge) against leaks and rings; it is the main cost.
|
|
48
|
+
|
|
49
|
+
## Sources
|
|
50
|
+
Written from the public descriptions, no code copied: Alexander Sannikov, "Radiance Cascades: A Novel Approach to Calculating Global
|
|
51
|
+
Illumination" (2023); jason.today, "Building Real-Time Global Illumination" (parts 1 and 2: jump flood, distance field, cascades);
|
|
52
|
+
GM Shaders, "Radiance Cascades".
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
// 2D radiance cascades demo (page /rc2d.html): a top-down street at night. Street lamps, lit windows and a neon bar are emissive meshes; building
|
|
3
|
+
// blocks and a wall are occluders. Both are on layer 5, which is all rc2d.js looks at; the floor is not, so it only receives light.
|
|
4
|
+
// URL: ?quality=low|medium|high &cascades=auto|1..8 &interval=4 &apply=0 (no post pass: the frame stays as the scene's own light draws it).
|
|
5
|
+
// Test page for tests/specs/rc2d.mjs: window.rc2dTest = { rc, THREE, points } (points: world spots the spec reads the light at).
|
|
6
|
+
import { createEngine, fixedCamera, makeMaterial, THREE } from '../../index.js';
|
|
7
|
+
import { createRadianceCascades2D } from './rc2d.js';
|
|
8
|
+
|
|
9
|
+
const LAYER = 5, AMBIENT = 0.12; // the scene's own light (one ambient light); rc2d divides by it to get albedo back
|
|
10
|
+
const url = new URLSearchParams(location.search);
|
|
11
|
+
const engine = createEngine({ canvas: /** @type {HTMLCanvasElement} */ (document.getElementById('view')), lights: false, ui: { loading: false }, saveKey: 'threedog-rc2d' });
|
|
12
|
+
engine.scene.add(new THREE.AmbientLight(0xffffff, AMBIENT));
|
|
13
|
+
engine.look.lights.set({ env: { intensity: 0 } }); // no room-map light either: AMBIENT is the whole of the scene's own light
|
|
14
|
+
// projection / size per shot work at run time (recipes/21-camera.md) but CameraShot does not declare them yet, hence the cast
|
|
15
|
+
const top = /** @type {any} */ ({ position: [0, 40, 0.001], lookAt: [0, 0, 0], projection: 'orthographic', size: 30 });
|
|
16
|
+
engine.use(fixedCamera({ shots: { top }, start: 'top' }));
|
|
17
|
+
|
|
18
|
+
const floor = new THREE.Mesh(new THREE.PlaneGeometry(120, 120), makeMaterial('terrain', { color: 0x8a8a90 }));
|
|
19
|
+
floor.rotation.x = -Math.PI / 2;
|
|
20
|
+
engine.scene.add(floor);
|
|
21
|
+
|
|
22
|
+
/** A box seen from above: [x0, z0, x1, z1] in metres; on the light layer, so it blocks (and shines when emissive) */
|
|
23
|
+
function block(/** @type {number[]} */ [x0, z0, x1, z1], /** @type {THREE.Material} */ material, height = 4) {
|
|
24
|
+
const m = new THREE.Mesh(new THREE.BoxGeometry(x1 - x0, height, z1 - z0), material);
|
|
25
|
+
m.position.set((x0 + x1) / 2, height / 2, (z0 + z1) / 2);
|
|
26
|
+
m.layers.enable(LAYER);
|
|
27
|
+
engine.scene.add(m);
|
|
28
|
+
return m;
|
|
29
|
+
}
|
|
30
|
+
const wall = makeMaterial('prop', { color: 0x6d6258 });
|
|
31
|
+
for (const r of [[-14, -11, -4, -3], [3, -13, 13, -5], [-14, 4, -6, 12], [2, 3.7, 10, 4.3], [2, 3.7, 2.6, 11], [14, 2, 17, 9]]) block(r, wall);
|
|
32
|
+
// pillars along the street: small occluders that cast soft shadows from the lamps
|
|
33
|
+
for (let x = -10; x <= 10; x += 5) block([x - 0.3, 0.7, x + 0.3, 1.3], wall, 2);
|
|
34
|
+
|
|
35
|
+
const glow = (/** @type {number} */ color, /** @type {number} */ intensity) => makeMaterial('prop', { color: 0x000000, emissive: color, emissiveIntensity: intensity });
|
|
36
|
+
const lamps = [[7, 2.2], [-8, 2], [-2, -5], [-2, 14]].map(([x, z]) => {
|
|
37
|
+
const m = new THREE.Mesh(new THREE.CylinderGeometry(0.45, 0.45, 0.2, 20), glow(0xffb060, 6));
|
|
38
|
+
m.position.set(x, 4.5, z);
|
|
39
|
+
m.layers.enable(LAYER);
|
|
40
|
+
engine.scene.add(m);
|
|
41
|
+
return m;
|
|
42
|
+
});
|
|
43
|
+
// lit windows on the south face of the first block, a neon bar on the west face of the second
|
|
44
|
+
for (let x = -13; x < -5; x += 3) block([x, -3, x + 1.6, -2.75], glow(0x7fb0ff, 2), 3);
|
|
45
|
+
block([2.75, -12, 3, -6], glow(0xff40c0, 3), 3);
|
|
46
|
+
|
|
47
|
+
// one flickering lamp: rc2d reads emissiveIntensity every frame, so plain material writes are all it takes
|
|
48
|
+
const flicker = /** @type {any} */ (lamps[2].material);
|
|
49
|
+
engine.onFrame(() => { flicker.emissiveIntensity = 6 * (0.8 + 0.2 * Math.sin(engine.clock.now * 9) * Math.sin(engine.clock.now * 2.3)); });
|
|
50
|
+
|
|
51
|
+
const cascades = url.get('cascades');
|
|
52
|
+
const rc = createRadianceCascades2D(engine, {
|
|
53
|
+
layer: LAYER, ambient: AMBIENT,
|
|
54
|
+
quality: /** @type {any} */ (url.get('quality') ?? 'medium'),
|
|
55
|
+
cascades: cascades && cascades !== 'auto' ? Number(cascades) : 'auto',
|
|
56
|
+
interval: Number(url.get('interval') ?? 4),
|
|
57
|
+
apply: url.get('apply') !== '0',
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
// lit: 1 m from lamp 0; open: 4 m from it with nothing between; shadow: 4 m from it behind the wall at z 3.7..4.3
|
|
61
|
+
const points = { lit: [7, 3], open: [7, -1.8], shadow: [7, 6.2] };
|
|
62
|
+
Object.assign(window, { engine, rc2dTest: { rc, THREE, points } });
|
|
63
|
+
engine.start();
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
// 2D radiance cascades: screen-space global illumination for top-down and side-view games (WebGL2, fragment shaders only, no compute).
|
|
3
|
+
// An optional example, not an engine module: copy this folder (rc2d.js + shaders.js) into your game and import it.
|
|
4
|
+
//
|
|
5
|
+
// import { createRadianceCascades2D } from './rc2d/rc2d.js';
|
|
6
|
+
// wall.layers.enable(5); lamp.layers.enable(5); // what light sees: lamps (emissive) and walls (not emissive) on one layer
|
|
7
|
+
// const rc = createRadianceCascades2D(engine, { ambient: 0.15 });
|
|
8
|
+
// rc.describe(); rc.texture; rc.resize(); rc.dispose();
|
|
9
|
+
//
|
|
10
|
+
// Each frame (engine.onRender, before the frame): the meshes on `layer` are drawn from the game camera into a scene target (rgb = their emissive,
|
|
11
|
+
// a = solid) -> jump flood -> distance field -> cascades traced and merged from the coarsest down -> gather into `texture` (linear light per
|
|
12
|
+
// screen pixel). With `apply` (default) one post pass in the engine's 'hdr' slot (engine.look.post.add) adds that light to the frame; without it,
|
|
13
|
+
// sample `texture` in your own materials (screen uv). Colours and strengths are the game's: a lamp shines with its material's emissive * emissiveIntensity.
|
|
14
|
+
import * as THREE from 'three';
|
|
15
|
+
import { Pass, FullScreenQuad } from 'three/addons/postprocessing/Pass.js';
|
|
16
|
+
import { VERT, SEED, JFA, DIST, CASCADE, GATHER, APPLY } from './shaders.js';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The parameters, in one place. quality: RC resolution as a share of the screen (CSS pixels) and the march step cap per ray.
|
|
20
|
+
* interval: cascade 0's ray length in RC pixels (each cascade's is 4x the one below). cascades: 'auto' = enough to cross the screen diagonal.
|
|
21
|
+
* ambient: the light level the frame is already lit with (albedo = color / ambient); apply: add the pass to engine.post.
|
|
22
|
+
*/
|
|
23
|
+
export const RC2D_DEFAULTS = Object.freeze({ layer: 5, quality: 'medium', cascades: 'auto', interval: 4, ambient: 1, apply: true });
|
|
24
|
+
/** @typedef {{ layer?: number, quality?: 'low' | 'medium' | 'high', cascades?: number | 'auto', interval?: number, ambient?: number, apply?: boolean }} Rc2dOptions */
|
|
25
|
+
export const RC2D_QUALITY = Object.freeze({ low: { scale: 0.25, steps: 16 }, medium: { scale: 0.5, steps: 24 }, high: { scale: 1, steps: 32 } });
|
|
26
|
+
const SPACING0 = 2; // cascade 0 probe spacing (RC pixels); with 4 directions it keeps every cascade target about the scene target's size
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @param {any} engine a threedog engine (renderer, scene, camera, onRender, look.post)
|
|
30
|
+
* @param {Rc2dOptions} [options]
|
|
31
|
+
*/
|
|
32
|
+
export function createRadianceCascades2D(engine, options = {}) {
|
|
33
|
+
for (const k of Object.keys(options)) if (!(k in RC2D_DEFAULTS)) throw new Error(`rc2d: unknown option '${k}'; options: ${Object.keys(RC2D_DEFAULTS).join(', ')}`);
|
|
34
|
+
const o = /** @type {Required<Rc2dOptions>} */ ({ ...RC2D_DEFAULTS, ...options });
|
|
35
|
+
const q = RC2D_QUALITY[/** @type {keyof typeof RC2D_QUALITY} */ (o.quality)];
|
|
36
|
+
if (!q) throw new Error(`rc2d: quality '${o.quality}' is not one of ${Object.keys(RC2D_QUALITY).join(', ')}`);
|
|
37
|
+
if (!(o.interval > 0)) throw new Error(`rc2d: interval is cascade 0's ray length in RC pixels (> 0), got ${o.interval}`);
|
|
38
|
+
if (o.cascades !== 'auto' && !(Number.isInteger(o.cascades) && o.cascades >= 1 && o.cascades <= 8)) throw new Error(`rc2d: cascades is 'auto' or 1..8, got ${o.cascades}`);
|
|
39
|
+
if (!(Number.isInteger(o.layer) && o.layer >= 1 && o.layer <= 31)) throw new Error(`rc2d: layer is a three.js layer 1..31 (0 is everything), got ${o.layer}`);
|
|
40
|
+
if (!(o.ambient > 0)) throw new Error(`rc2d: ambient is the light level the frame is already lit with (> 0), got ${o.ambient}`);
|
|
41
|
+
|
|
42
|
+
const { renderer, scene } = engine;
|
|
43
|
+
const quad = new FullScreenQuad();
|
|
44
|
+
const mat = (/** @type {string} */ fragmentShader, /** @type {Record<string, any>} */ uniforms, defines = {}) => new THREE.ShaderMaterial({
|
|
45
|
+
vertexShader: VERT, fragmentShader, uniforms, defines, depthTest: false, depthWrite: false });
|
|
46
|
+
const u = (/** @type {any} */ v) => ({ value: v });
|
|
47
|
+
const mats = {
|
|
48
|
+
seed: mat(SEED, { tScene: u(null) }),
|
|
49
|
+
jfa: mat(JFA, { tSeed: u(null), uSize: u(new THREE.Vector2()), uStep: u(1) }),
|
|
50
|
+
dist: mat(DIST, { tSeed: u(null) }),
|
|
51
|
+
cascade: mat(CASCADE, { tScene: u(null), tDist: u(null), tUpper: u(null), uSize: u(new THREE.Vector2()), uTile: u(new THREE.Vector2()), uS: u(2),
|
|
52
|
+
uSpacing: u(SPACING0), uStart: u(0), uLen: u(1), uHasUpper: u(0), uUpperTile: u(new THREE.Vector2()), uUpperS: u(4) },
|
|
53
|
+
{ STEPS: q.steps }),
|
|
54
|
+
gather: mat(GATHER, { tC0: u(null), uTile0: u(new THREE.Vector2()), uTex0: u(new THREE.Vector2()), uSpacing0: u(SPACING0) }),
|
|
55
|
+
};
|
|
56
|
+
/** @type {{ scene: THREE.WebGLRenderTarget, seed: THREE.WebGLRenderTarget[], dist: THREE.WebGLRenderTarget, gi: THREE.WebGLRenderTarget, cascades: { rt: THREE.WebGLRenderTarget, tile: THREE.Vector2, s: number, spacing: number, start: number, len: number }[] } | null} */
|
|
57
|
+
let t = null;
|
|
58
|
+
const size = new THREE.Vector2(), css = new THREE.Vector2();
|
|
59
|
+
let disposed = false;
|
|
60
|
+
|
|
61
|
+
const target = (/** @type {number} */ w, /** @type {number} */ h, /** @type {object} */ extra = {}) => new THREE.WebGLRenderTarget(w, h,
|
|
62
|
+
{ type: THREE.HalfFloatType, minFilter: THREE.NearestFilter, magFilter: THREE.NearestFilter, depthBuffer: false, ...extra });
|
|
63
|
+
const freeTargets = () => {
|
|
64
|
+
if (!t) return;
|
|
65
|
+
for (const rt of [t.scene, ...t.seed, t.dist, t.gi, ...t.cascades.map(c => c.rt)]) rt.dispose();
|
|
66
|
+
t = null;
|
|
67
|
+
};
|
|
68
|
+
// Sized from the renderer's CSS size (not the drawing buffer), so adaptive resolution changing the pixel ratio does not rebuild everything
|
|
69
|
+
function build() {
|
|
70
|
+
renderer.getSize(css);
|
|
71
|
+
const w = Math.max(8, Math.ceil(css.x * q.scale)), h = Math.max(8, Math.ceil(css.y * q.scale));
|
|
72
|
+
if (t && size.x === w && size.y === h) return;
|
|
73
|
+
freeTargets();
|
|
74
|
+
size.set(w, h);
|
|
75
|
+
const n = o.cascades === 'auto' ? Math.min(8, Math.max(1, Math.ceil(Math.log(3 * Math.hypot(w, h) / o.interval + 1) / Math.log(4)))) : o.cascades;
|
|
76
|
+
const cascades = [];
|
|
77
|
+
for (let i = 0; i < n; i++) {
|
|
78
|
+
const spacing = SPACING0 * 2 ** i, s = 2 ** (i + 1); // probes halve per axis, directions x4: each target stays near the scene size
|
|
79
|
+
const tile = new THREE.Vector2(Math.ceil(w / spacing), Math.ceil(h / spacing));
|
|
80
|
+
// linear filtering for cascade 0 only: the gather reads 4 neighbouring probes in one fetch (the merge reads exact texels)
|
|
81
|
+
const filter = i === 0 ? THREE.LinearFilter : THREE.NearestFilter;
|
|
82
|
+
cascades.push({ rt: target(tile.x * s, tile.y * s, { minFilter: filter, magFilter: filter }), tile, s, spacing,
|
|
83
|
+
start: o.interval * (4 ** i - 1) / 3, len: o.interval * 4 ** i });
|
|
84
|
+
}
|
|
85
|
+
t = { scene: target(w, h), seed: [target(w, h, { type: THREE.FloatType }), target(w, h, { type: THREE.FloatType })], dist: target(w, h),
|
|
86
|
+
gi: target(w, h, { minFilter: THREE.LinearFilter, magFilter: THREE.LinearFilter }), cascades };
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const draw = (/** @type {THREE.ShaderMaterial} */ m, /** @type {THREE.WebGLRenderTarget} */ rt) => { quad.material = m; renderer.setRenderTarget(rt); quad.render(renderer); };
|
|
90
|
+
|
|
91
|
+
// The meshes on `layer` drawn with a flat material each: colour = their emissive (0 for walls), alpha 1 = solid. Cached per source material.
|
|
92
|
+
/** @type {WeakMap<THREE.Material, THREE.MeshBasicMaterial>} */
|
|
93
|
+
const proxies = new WeakMap();
|
|
94
|
+
const swapped = /** @type {[THREE.Mesh, any][]} */ ([]);
|
|
95
|
+
const proxyOf = (/** @type {any} */ m) => {
|
|
96
|
+
let p = proxies.get(m);
|
|
97
|
+
// hint-off(material): a flat stand-in whose colour is the source material's emissive, not art
|
|
98
|
+
if (!p) { p = new THREE.MeshBasicMaterial({ fog: false, toneMapped: false }); proxies.set(m, p); }
|
|
99
|
+
p.color.setRGB(0, 0, 0);
|
|
100
|
+
if (m.emissive) p.color.copy(m.emissive).multiplyScalar(m.emissiveIntensity ?? 1); // read every frame: flicker and day / night keep working
|
|
101
|
+
p.side = m.side;
|
|
102
|
+
return p;
|
|
103
|
+
};
|
|
104
|
+
const clear = new THREE.Color();
|
|
105
|
+
function drawScene(/** @type {THREE.Camera} */ camera) {
|
|
106
|
+
scene.traverse((/** @type {any} */ obj) => {
|
|
107
|
+
if (!obj.isMesh || !obj.layers.isEnabled(o.layer)) return;
|
|
108
|
+
swapped.push([obj, obj.material]);
|
|
109
|
+
obj.material = Array.isArray(obj.material) ? obj.material.map(proxyOf) : proxyOf(obj.material);
|
|
110
|
+
});
|
|
111
|
+
// what is saved here is put back before the frame renders, so the engine's own per-frame writes (sky background) never see a change
|
|
112
|
+
const mask = camera.layers.mask, bg = scene.background, alpha = renderer.getClearAlpha(), auto = renderer.shadowMap.autoUpdate;
|
|
113
|
+
renderer.getClearColor(clear);
|
|
114
|
+
camera.layers.set(o.layer); scene.background = null; renderer.shadowMap.autoUpdate = false;
|
|
115
|
+
renderer.setClearColor(0x000000, 0);
|
|
116
|
+
renderer.setRenderTarget(t.scene); renderer.clear(); renderer.render(scene, camera);
|
|
117
|
+
renderer.setClearColor(clear, alpha); renderer.shadowMap.autoUpdate = auto; scene.background = bg; camera.layers.mask = mask;
|
|
118
|
+
for (const [obj, m] of swapped) obj.material = m;
|
|
119
|
+
swapped.length = 0;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
let frameMs = 0;
|
|
123
|
+
function update(/** @type {{ camera: THREE.Camera }} */ { camera }) {
|
|
124
|
+
if (disposed) return;
|
|
125
|
+
const t0 = performance.now(); // measure: CPU-side submit time only (describe().ms); GPU time needs the perf tool
|
|
126
|
+
build();
|
|
127
|
+
if (!t) return;
|
|
128
|
+
drawScene(camera);
|
|
129
|
+
// jump flood: seed, then steps of half the largest power of two down to 1, ping-ponging the two float targets
|
|
130
|
+
mats.seed.uniforms.tScene.value = t.scene.texture; draw(mats.seed, t.seed[0]);
|
|
131
|
+
let src = 0;
|
|
132
|
+
mats.jfa.uniforms.uSize.value.copy(size);
|
|
133
|
+
for (let step = 2 ** Math.floor(Math.log2(Math.max(size.x, size.y))); step >= 1; step /= 2) {
|
|
134
|
+
mats.jfa.uniforms.tSeed.value = t.seed[src].texture; mats.jfa.uniforms.uStep.value = step;
|
|
135
|
+
draw(mats.jfa, t.seed[1 - src]); src = 1 - src;
|
|
136
|
+
}
|
|
137
|
+
mats.dist.uniforms.tSeed.value = t.seed[src].texture; draw(mats.dist, t.dist);
|
|
138
|
+
// cascades from the coarsest (longest rays, fewest probes) to cascade 0, each merging the one above it
|
|
139
|
+
const cu = mats.cascade.uniforms;
|
|
140
|
+
cu.tScene.value = t.scene.texture; cu.tDist.value = t.dist.texture; cu.uSize.value.copy(size);
|
|
141
|
+
for (let i = t.cascades.length - 1; i >= 0; i--) {
|
|
142
|
+
const c = t.cascades[i], up = t.cascades[i + 1];
|
|
143
|
+
cu.uTile.value.copy(c.tile); cu.uS.value = c.s; cu.uSpacing.value = c.spacing; cu.uStart.value = c.start; cu.uLen.value = c.len;
|
|
144
|
+
cu.uHasUpper.value = up ? 1 : 0;
|
|
145
|
+
if (up) { cu.tUpper.value = up.rt.texture; cu.uUpperTile.value.copy(up.tile); cu.uUpperS.value = up.s; }
|
|
146
|
+
else cu.tUpper.value = null; // never the target being written
|
|
147
|
+
draw(mats.cascade, c.rt);
|
|
148
|
+
}
|
|
149
|
+
const c0 = t.cascades[0], gu = mats.gather.uniforms;
|
|
150
|
+
gu.tC0.value = c0.rt.texture; gu.uTile0.value.copy(c0.tile); gu.uTex0.value.set(c0.rt.width, c0.rt.height);
|
|
151
|
+
draw(mats.gather, t.gi);
|
|
152
|
+
renderer.setRenderTarget(null);
|
|
153
|
+
frameMs = performance.now() - t0;
|
|
154
|
+
}
|
|
155
|
+
const hook = engine.onRender(update);
|
|
156
|
+
|
|
157
|
+
/** The apply pass: frame * (1 + gi / ambient), in linear colour before tone mapping */
|
|
158
|
+
class ApplyPass extends Pass {
|
|
159
|
+
constructor() {
|
|
160
|
+
super();
|
|
161
|
+
this.material = mat(APPLY, { tDiffuse: u(null), tGI: u(null), uAmbient: u(o.ambient) });
|
|
162
|
+
this.fsQuad = new FullScreenQuad(this.material);
|
|
163
|
+
}
|
|
164
|
+
/** @param {THREE.WebGLRenderer} r @param {THREE.WebGLRenderTarget} write @param {THREE.WebGLRenderTarget} read */
|
|
165
|
+
render(r, write, read) {
|
|
166
|
+
this.material.uniforms.tDiffuse.value = read.texture;
|
|
167
|
+
this.material.uniforms.tGI.value = t ? t.gi.texture : null;
|
|
168
|
+
r.setRenderTarget(this.renderToScreen ? null : write);
|
|
169
|
+
this.fsQuad.render(r);
|
|
170
|
+
}
|
|
171
|
+
dispose() { this.material.dispose(); this.fsQuad.dispose(); }
|
|
172
|
+
}
|
|
173
|
+
const post = o.apply ? engine.look.post.add({ name: 'rc2d', slot: 'hdr', create: () => new ApplyPass() }, { owner: 'rc2d' }) : null;
|
|
174
|
+
|
|
175
|
+
return {
|
|
176
|
+
/** The gathered light, linear rgb per screen uv (null before the first frame); a new texture after a resize */
|
|
177
|
+
get texture() { return t ? t.gi.texture : null; },
|
|
178
|
+
/** The render target holding `texture` (HalfFloat RGBA, linear filtering), for size or readRenderTargetPixels (Uint16Array, half floats) */
|
|
179
|
+
get target() { return t ? t.gi : null; },
|
|
180
|
+
/** Re-read the render size now (it is also checked every frame); rebuilds the targets when it changed */
|
|
181
|
+
resize() { if (!disposed) build(); },
|
|
182
|
+
/** Remove the hooks and the post pass, free every render target and material */
|
|
183
|
+
dispose() {
|
|
184
|
+
if (disposed) return;
|
|
185
|
+
disposed = true;
|
|
186
|
+
hook.remove(); post?.remove();
|
|
187
|
+
freeTargets();
|
|
188
|
+
for (const m of Object.values(mats)) m.dispose();
|
|
189
|
+
quad.dispose();
|
|
190
|
+
},
|
|
191
|
+
describe() {
|
|
192
|
+
return { size: [size.x, size.y], quality: o.quality, layer: o.layer, interval: o.interval, ambient: o.ambient, apply: o.apply,
|
|
193
|
+
cascades: t ? t.cascades.map(c => ({ probes: [c.tile.x, c.tile.y], directions: c.s * c.s, spacing: c.spacing, interval: [c.start, c.start + c.len] })) : [],
|
|
194
|
+
targets: t ? 5 + t.cascades.length : 0, cpuMs: +frameMs.toFixed(2), disposed };
|
|
195
|
+
},
|
|
196
|
+
};
|
|
197
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
// GLSL for rc2d.js (2D radiance cascades), GLSL ES 3.0 as three.js compiles a ShaderMaterial under WebGL2 (texelFetch; gl_FragColor is mapped).
|
|
2
|
+
// Every pass is a full-screen quad drawn into a render target whose viewport is that target, so gl_FragCoord.xy is the texel being written.
|
|
3
|
+
// Units: "RC pixels" = texels of the scene / distance targets (screen size * quality scale).
|
|
4
|
+
// Technique (written from the public descriptions, no code copied): Alexander Sannikov, "Radiance Cascades: A Novel Approach to Calculating
|
|
5
|
+
// Global Illumination" (2023); jason.today "Building Real-Time Global Illumination" parts 1-2 (jump flood -> distance field -> cascades);
|
|
6
|
+
// GM Shaders "Radiance Cascades" posts. Layout: direction-first (one tile per direction, every probe of that direction inside the tile).
|
|
7
|
+
|
|
8
|
+
export const VERT = /* glsl */`
|
|
9
|
+
varying vec2 vUv;
|
|
10
|
+
void main() { vUv = uv; gl_Position = vec4(position.xy, 0.0, 1.0); }`;
|
|
11
|
+
|
|
12
|
+
// Jump flood seed: a solid texel (alpha > 0.5 in the scene target) stores its own position; empty texels store "no seed" (alpha 0)
|
|
13
|
+
export const SEED = /* glsl */`
|
|
14
|
+
uniform sampler2D tScene;
|
|
15
|
+
void main() {
|
|
16
|
+
vec4 s = texelFetch(tScene, ivec2(gl_FragCoord.xy), 0);
|
|
17
|
+
gl_FragColor = s.a > 0.5 ? vec4(gl_FragCoord.xy, 0.0, 1.0) : vec4(0.0);
|
|
18
|
+
}`;
|
|
19
|
+
|
|
20
|
+
// One jump flood step: keep the nearest seed among the 3x3 neighbours uStep texels away. log2(size) steps give each texel its nearest solid texel.
|
|
21
|
+
export const JFA = /* glsl */`
|
|
22
|
+
uniform sampler2D tSeed;
|
|
23
|
+
uniform vec2 uSize;
|
|
24
|
+
uniform float uStep;
|
|
25
|
+
void main() {
|
|
26
|
+
vec2 p = gl_FragCoord.xy;
|
|
27
|
+
vec4 best = vec4(0.0);
|
|
28
|
+
float bestD = 1e20;
|
|
29
|
+
for (int y = -1; y <= 1; y++) for (int x = -1; x <= 1; x++) {
|
|
30
|
+
vec2 q = p + vec2(float(x), float(y)) * uStep;
|
|
31
|
+
if (q.x < 0.0 || q.y < 0.0 || q.x >= uSize.x || q.y >= uSize.y) continue;
|
|
32
|
+
vec4 s = texelFetch(tSeed, ivec2(q), 0);
|
|
33
|
+
if (s.a < 0.5) continue;
|
|
34
|
+
vec2 d = s.xy - p;
|
|
35
|
+
float dd = dot(d, d);
|
|
36
|
+
if (dd < bestD) { bestD = dd; best = s; }
|
|
37
|
+
}
|
|
38
|
+
gl_FragColor = best;
|
|
39
|
+
}`;
|
|
40
|
+
|
|
41
|
+
// Distance (RC pixels) from each texel centre to the nearest solid texel centre; 0 inside walls and lights, large where the screen has no solid at all
|
|
42
|
+
export const DIST = /* glsl */`
|
|
43
|
+
uniform sampler2D tSeed;
|
|
44
|
+
void main() {
|
|
45
|
+
vec4 s = texelFetch(tSeed, ivec2(gl_FragCoord.xy), 0);
|
|
46
|
+
gl_FragColor = vec4(s.a > 0.5 ? distance(s.xy, gl_FragCoord.xy) : 1e4, 0.0, 0.0, 1.0);
|
|
47
|
+
}`;
|
|
48
|
+
|
|
49
|
+
// One cascade: every texel is (direction tile, probe). Its ray is sphere-traced through the distance field over the cascade's interval and merged with
|
|
50
|
+
// the upper cascade (the 4 child directions of the same cone). The merge uses the "bilinear fix" from the paper: instead of tracing once and
|
|
51
|
+
// blending the 4 nearest upper probes, it traces one ray to each of those 4 probes' interval start and merges each with that probe, then blends
|
|
52
|
+
// the 4 results bilinearly. 4x the marching, but light no longer leaks through walls thinner than the upper probe spacing and the rings between
|
|
53
|
+
// cascades go. rgb = radiance, a = 1 if the ray was not blocked.
|
|
54
|
+
export const CASCADE = /* glsl */`
|
|
55
|
+
uniform sampler2D tScene;
|
|
56
|
+
uniform sampler2D tDist;
|
|
57
|
+
uniform sampler2D tUpper;
|
|
58
|
+
uniform vec2 uSize; // RC pixels
|
|
59
|
+
uniform vec2 uTile; // probes per axis in this cascade = one direction tile
|
|
60
|
+
uniform float uS; // direction tiles per axis (directions = uS * uS)
|
|
61
|
+
uniform float uSpacing; // probe spacing, RC pixels
|
|
62
|
+
uniform float uStart;
|
|
63
|
+
uniform float uLen;
|
|
64
|
+
uniform float uHasUpper;
|
|
65
|
+
uniform vec2 uUpperTile;
|
|
66
|
+
uniform float uUpperS;
|
|
67
|
+
|
|
68
|
+
vec4 march(vec2 from, vec2 to) {
|
|
69
|
+
vec2 dir = to - from;
|
|
70
|
+
float end = length(dir), t = 0.0;
|
|
71
|
+
dir /= max(end, 1e-4);
|
|
72
|
+
for (int i = 0; i < STEPS; i++) {
|
|
73
|
+
if (t > end) break;
|
|
74
|
+
vec2 p = from + dir * t;
|
|
75
|
+
// off screen: nothing is known there; opaque black ends the ray (screen-space GI cannot see lights it does not draw)
|
|
76
|
+
if (p.x < 0.0 || p.y < 0.0 || p.x >= uSize.x || p.y >= uSize.y) return vec4(0.0);
|
|
77
|
+
float d = texelFetch(tDist, ivec2(p), 0).r;
|
|
78
|
+
if (d < 0.5) return vec4(texelFetch(tScene, ivec2(p), 0).rgb, 0.0);
|
|
79
|
+
// distances are centre to centre, so step a little less than d (never skip a corner), at least half a texel (grazing rays along walls)
|
|
80
|
+
t += max(d - 0.7, 0.5);
|
|
81
|
+
}
|
|
82
|
+
return vec4(0.0, 0.0, 0.0, 1.0);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// the upper cascade's radiance at upper probe nb for this direction's cone: the mean of its 4 child directions
|
|
86
|
+
vec4 upper(vec2 nb, float idx) {
|
|
87
|
+
vec4 far = vec4(0.0);
|
|
88
|
+
for (int j = 0; j < 4; j++) {
|
|
89
|
+
float c = idx * 4.0 + float(j);
|
|
90
|
+
vec2 ut = vec2(mod(c, uUpperS), floor(c / uUpperS));
|
|
91
|
+
far += texelFetch(tUpper, ivec2(ut * uUpperTile + nb), 0);
|
|
92
|
+
}
|
|
93
|
+
return far * 0.25;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
void main() {
|
|
97
|
+
vec2 tc = floor(gl_FragCoord.xy);
|
|
98
|
+
vec2 tile = floor(tc / uTile);
|
|
99
|
+
vec2 probe = tc - tile * uTile;
|
|
100
|
+
float idx = tile.y * uS + tile.x;
|
|
101
|
+
float ang = (idx + 0.5) * 6.28318530718 / (uS * uS);
|
|
102
|
+
vec2 dir = vec2(cos(ang), sin(ang));
|
|
103
|
+
vec2 origin = (probe + 0.5) * uSpacing;
|
|
104
|
+
vec2 from = origin + dir * uStart;
|
|
105
|
+
if (uHasUpper < 0.5) { gl_FragColor = march(from, origin + dir * (uStart + uLen)); return; }
|
|
106
|
+
// this probe in upper probe grid coordinates; its 4 bilinear neighbours (clamped at the screen edge) and their weights
|
|
107
|
+
vec2 q = origin / (uSpacing * 2.0) - 0.5;
|
|
108
|
+
vec2 base = floor(q), f = q - base;
|
|
109
|
+
vec4 r = vec4(0.0);
|
|
110
|
+
for (int k = 0; k < 4; k++) {
|
|
111
|
+
vec2 o = vec2(float(k % 2), float(k / 2));
|
|
112
|
+
vec2 w2 = mix(1.0 - f, f, o);
|
|
113
|
+
vec2 nb = clamp(base + o, vec2(0.0), uUpperTile - 1.0);
|
|
114
|
+
vec4 near = march(from, (nb + 0.5) * uSpacing * 2.0 + dir * (uStart + uLen));
|
|
115
|
+
if (near.a > 0.0) { vec4 far = upper(nb, idx); near.rgb += far.rgb; near.a = far.a; }
|
|
116
|
+
r += near * (w2.x * w2.y);
|
|
117
|
+
}
|
|
118
|
+
gl_FragColor = r;
|
|
119
|
+
}`;
|
|
120
|
+
|
|
121
|
+
// Final gather: average cascade 0's 4 directions at each RC pixel (bilinear between its 4 nearest probes) = light arriving at that pixel
|
|
122
|
+
export const GATHER = /* glsl */`
|
|
123
|
+
uniform sampler2D tC0;
|
|
124
|
+
uniform vec2 uTile0;
|
|
125
|
+
uniform vec2 uTex0;
|
|
126
|
+
uniform float uSpacing0;
|
|
127
|
+
void main() {
|
|
128
|
+
vec2 q = clamp(gl_FragCoord.xy / uSpacing0 - 0.5, vec2(0.0), uTile0 - 1.0);
|
|
129
|
+
vec3 sum = vec3(0.0);
|
|
130
|
+
for (int j = 0; j < 4; j++) sum += texture(tC0, (vec2(float(j % 2), float(j / 2)) * uTile0 + q + 0.5) / uTex0).rgb;
|
|
131
|
+
gl_FragColor = vec4(sum * 0.25, 1.0);
|
|
132
|
+
}`;
|
|
133
|
+
|
|
134
|
+
// Apply (hdr slot, linear colour): the frame was lit by the scene's own light at level uAmbient, so albedo ~ color / uAmbient and the cascade
|
|
135
|
+
// light adds albedo * gi on top
|
|
136
|
+
export const APPLY = /* glsl */`
|
|
137
|
+
uniform sampler2D tDiffuse;
|
|
138
|
+
uniform sampler2D tGI;
|
|
139
|
+
uniform float uAmbient;
|
|
140
|
+
varying vec2 vUv;
|
|
141
|
+
void main() {
|
|
142
|
+
vec4 c = texture(tDiffuse, vUv);
|
|
143
|
+
gl_FragColor = vec4(c.rgb * (1.0 + texture(tGI, vUv).rgb / uAmbient), c.a);
|
|
144
|
+
}`;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":1,"files":{"content/props.js":{"kind":"props","mtime":1793500175294.8977,"from":0,"count":15,"indexIds":0,"positional":[]},"content/templates.js":{"kind":"templates","mtime":1793500175296.9004,"from":0,"count":2,"indexIds":0,"positional":[]},"content/vegetation.js":{"kind":"vegetation","mtime":1793500175298.9006,"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":4,"placed":false}]}}
|
|
@@ -11,8 +11,8 @@ 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: { style, saveKey: 'threedog-sheepisland', ui: { loading: { title: '
|
|
15
|
-
- openWorld preset ({ camera: fixedCamera(), terrain: island, water: false, rigid: false, ambience: false,
|
|
14
|
+
- createEngine: { bindings: { ...presets.bindings.debug }, style, saveKey: 'threedog-sheepisland', ui: { loading: { title: 's…
|
|
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`)
|
|
@@ -20,19 +20,20 @@ None yet, write them in `DESIGN.md` (why it is designed this way, what not to ch
|
|
|
20
20
|
- world: `node_modules/threedog/docs/recipes/18-world.md` · `node_modules/threedog/docs/api/world.md`
|
|
21
21
|
- terrain: `node_modules/threedog/docs/recipes/28-terrain.md` · `node_modules/threedog/docs/api/terrain.md`
|
|
22
22
|
- vegetation: `node_modules/threedog/docs/recipes/10-blender-level.md` · `node_modules/threedog/docs/api/vegetation.md`
|
|
23
|
+
- calendar: `node_modules/threedog/docs/recipes/06-clock-events.md` · `node_modules/threedog/docs/api/calendar.md`
|
|
23
24
|
- sky: `node_modules/threedog/docs/recipes/08-weather-sky.md` · `node_modules/threedog/docs/api/sky.md`
|
|
24
25
|
- weather: `node_modules/threedog/docs/recipes/08-weather-sky.md` · `node_modules/threedog/docs/api/weather.md`
|
|
25
26
|
- collision: `node_modules/threedog/docs/recipes/12-navmesh.md` · `node_modules/threedog/docs/api/collision.md`
|
|
26
27
|
- characters: `node_modules/threedog/docs/recipes/12-navmesh.md` · `node_modules/threedog/docs/api/characters.md`
|
|
27
28
|
- settings: `node_modules/threedog/docs/recipes/26-ui-parts.md` · `node_modules/threedog/docs/api/settings.md`
|
|
28
|
-
- content: `node_modules/threedog/docs/recipes/
|
|
29
|
+
- content: `node_modules/threedog/docs/recipes/30-templates.md` · `node_modules/threedog/docs/api/content.md`
|
|
29
30
|
|
|
30
31
|
Not used yet (check these before writing the system yourself):
|
|
31
32
|
|
|
32
|
-
- inventory: items, stacks, containers and pickups: `inventory(
|
|
33
|
+
- inventory: items, stacks, containers and pickups: `inventory()` + key map presets.bindings.inventory, content/items.js (node_modules/threedog/docs/recipes/03-items-pickups.md)
|
|
33
34
|
- saves: save your own state: `engine.saves.register(key, { version, save, load })` (node_modules/threedog/docs/recipes/20-content-actions-save.md)
|
|
34
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)
|
|
35
|
-
- quests: goals with steps, conditions and rewards: `quests(
|
|
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)
|
|
36
37
|
- grids: cell placement for farming and building: `grids()` (node_modules/threedog/docs/recipes/29-grid.md)
|
|
37
38
|
|
|
38
39
|
## Files
|
|
@@ -41,13 +42,14 @@ content/*.js is content data: how to write it in `node_modules/threedog/docs/rec
|
|
|
41
42
|
|
|
42
43
|
| File | Lines | Description |
|
|
43
44
|
|---|---|---|
|
|
45
|
+
| assets.js | 6 | The asset packs this game registers (main.js: engine.assets.manifest(packs)). Kept in their own fil… |
|
|
44
46
|
| content/index.js | 7 | |
|
|
45
47
|
| content/props.js | 20 | |
|
|
46
48
|
| content/templates.js | 6 | |
|
|
47
49
|
| content/vegetation.js | 9 | |
|
|
48
|
-
| main.js |
|
|
50
|
+
| main.js | 77 | @ts-check Sheep island: a small floating island built only from the engine's public entry points (t… |
|
|
49
51
|
| params.js | 26 | URL parameters of the sheep island page. Import this file first in main.js: it rewrites word values… |
|
|
50
|
-
| style/index.js | 80 | sheepisland:
|
|
52
|
+
| style/index.js | 80 | sheepisland: this game's style, LOOKS ONLY (recipes/09-style.md, 35-style-from-reference.md), fille… |
|
|
51
53
|
| style/models.js | 60 | sheepisland procedural models: a round tree, a sheep, a wheat tuft. Built in code, no files; regist… |
|
|
52
54
|
| views.js | 10 | Named camera positions of the sheep island. Same name = same framing every time, so two screenshots… |
|
|
53
55
|
|
|
@@ -71,7 +73,7 @@ content/*.js is content data: how to write it in `node_modules/threedog/docs/rec
|
|
|
71
73
|
|
|
72
74
|
(none)
|
|
73
75
|
|
|
74
|
-
## Object templates (content/templates.js; placed with props { template }, spawned with engine.spawn)
|
|
76
|
+
## Object templates (content/templates.js; placed with props { template }, spawned with engine.content.spawn)
|
|
75
77
|
|
|
76
78
|
| Template | Model | Collide | Interact (op / label) | Container | State (defaults) | Instances |
|
|
77
79
|
|---|---|---|---|---|---|---|
|
|
@@ -98,10 +100,10 @@ Code that breaks saves or manages world models: none (rule R33).
|
|
|
98
100
|
## Saves
|
|
99
101
|
|
|
100
102
|
- Save prefix saveKey: threedog-sheepisland
|
|
101
|
-
- Saved parts of the engine modules (vars, inventory, quests, timers, world...): `
|
|
103
|
+
- Saved parts of the engine modules (vars, inventory, quests, timers, world...): `threedog catalog` (saves per module)
|
|
102
104
|
|
|
103
|
-
## Style
|
|
105
|
+
## Style keys
|
|
104
106
|
|
|
105
|
-
- Style
|
|
107
|
+
- Style: none (all neutral fallback look)
|
|
106
108
|
- Models (asset names): wheatTuft, roundTree, sheep
|
|
107
109
|
- Vegetation (content/vegetation.js): wheat
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// The asset packs this game registers (main.js: engine.assets.manifest(packs)). Kept in their own file so `npm run check` imports the same
|
|
2
|
+
// objects and checks the model / sound names content uses against them (one source, no scanning of main.js).
|
|
3
|
+
import { assets } from './style/index.js'; // roundTree, sheep, wheatTuft
|
|
4
|
+
|
|
5
|
+
export default [assets];
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
// @ts-check
|
|
2
|
-
// Sheep island: a small floating island built only from the engine's public entry points (the acceptance scene of docs/plans/acceptance-sheepisland.md).
|
|
2
|
+
// Sheep island: a small floating island built only from the engine's public entry points (the acceptance scene of docs/plans/done/acceptance-sheepisland.md).
|
|
3
3
|
// 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.
|
|
4
4
|
// Parameters (params.js): time day | dusk | night, weather clear | snow, view overview | flock | field | river | rim.
|
|
5
5
|
// main.js holds wiring only: modules, the island's terrain functions, view switching and the snow-to-winter link. Objects are content (rule R33),
|
|
6
|
-
// the look is the style
|
|
6
|
+
// the look is the style in style/.
|
|
7
7
|
import { params, VIEW_NAMES } from './params.js'; // first: rewrites ?time=dusk style words before the engine reads the URL
|
|
8
8
|
import { createEngine, openWorld, presets, content, fixedCamera } from '../../index.js';
|
|
9
|
-
import style
|
|
9
|
+
import style from './style/index.js';
|
|
10
|
+
import packs from './assets.js';
|
|
10
11
|
import data from './content/index.js';
|
|
11
12
|
import { VIEWS } from './views.js';
|
|
12
13
|
|
|
@@ -14,12 +15,16 @@ import { VIEWS } from './views.js';
|
|
|
14
15
|
// Every function runs in terrain workers: pure, only its parameters and Math (recipe 28 §1).
|
|
15
16
|
const island = {
|
|
16
17
|
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 42 §4)
|
|
18
|
+
// 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
|
|
19
|
+
// ground type cannot drift apart
|
|
20
|
+
params: { river: { amp: 6, freq: 0.09, shift: 2, dip: 3.2, wet: 2.4 } },
|
|
17
21
|
height: (x, z, n) => {
|
|
18
|
-
const d = Math.abs(z - (
|
|
19
|
-
return 3 + 1.2 * n.fbm(x * 0.03, z * 0.03) - (d <
|
|
22
|
+
const r = n.params.river, d = Math.abs(z - (r.amp * Math.sin(x * r.freq) + r.shift)); // distance to the river's centre line
|
|
23
|
+
return 3 + 1.2 * n.fbm(x * 0.03, z * 0.03) - (d < r.dip ? (1 - d / r.dip) * 0.6 : 0); // a gentle meadow, a shallow dip for the river
|
|
20
24
|
},
|
|
21
|
-
groundType: (x, z) => {
|
|
22
|
-
|
|
25
|
+
groundType: (x, z, h, slope, n) => {
|
|
26
|
+
const r = n.params.river;
|
|
27
|
+
if (Math.abs(z - (r.amp * Math.sin(x * r.freq) + r.shift)) < r.wet) return 'river';
|
|
23
28
|
const fx = (x - 14) / 9.5, fz = (z + 13) / 6.5; // the wheat field: an ellipse north-east of the river
|
|
24
29
|
return fx * fx + fz * fz < 1 ? 'wheat' : 'grass';
|
|
25
30
|
},
|
|
@@ -35,19 +40,19 @@ const island = {
|
|
|
35
40
|
|
|
36
41
|
// ---------- 2. Engine: own style, open-world preset with a fixed sky; a two-season calendar so snow can turn the island white ----------
|
|
37
42
|
const WINTER_DAY = 1001; // seasons last 1000 days each, so the season never blends towards the next one (it does over the last 20%)
|
|
38
|
-
const engine = createEngine({ canvas: /** @type {HTMLCanvasElement} */ (document.getElementById('view')), style, saveKey: 'threedog-sheepisland',
|
|
43
|
+
const engine = createEngine({ bindings: { ...presets.bindings.debug }, canvas: /** @type {HTMLCanvasElement} */ (document.getElementById('view')), style, saveKey: 'threedog-sheepisland',
|
|
39
44
|
ui: { loading: { title: 'sheep island' } } });
|
|
40
45
|
engine.use(openWorld({ camera: fixedCamera(), terrain: island, water: false, rigid: false, ambience: false,
|
|
41
|
-
|
|
46
|
+
calendar: { ...presets.calendar.fixedTime, time: 0.5, seasons: ['summer', 'winter'], daysPerSeason: 1000 },
|
|
42
47
|
weather: { ...presets.weather.temperate, start: 'clear' }, autoWeather: false }), content());
|
|
43
|
-
engine.assets.manifest(
|
|
48
|
+
engine.assets.manifest(packs);
|
|
44
49
|
engine.content.load(data);
|
|
45
50
|
|
|
46
51
|
// ---------- 3. Snow means winter: the engine's season tint (style.seasons.winter) whitens foliage and ground ----------
|
|
47
52
|
// The weather module sends no change event and a weather has no ground cover of its own, so the calendar day follows the weather each frame.
|
|
48
53
|
engine.onFrame(() => {
|
|
49
54
|
const day = engine.weather?.name === 'snow' ? WINTER_DAY : 1;
|
|
50
|
-
if (engine.
|
|
55
|
+
if (engine.calendar.day !== day) engine.calendar.day = day;
|
|
51
56
|
});
|
|
52
57
|
|
|
53
58
|
// ---------- 4. Views: an op, so the URL, the dev bridge and tests switch the same way ----------
|
|
@@ -63,7 +68,7 @@ engine.ops.define('sheepisland.view', {
|
|
|
63
68
|
},
|
|
64
69
|
reasons: { unknownView: 'View names: overview, flock, field, river, rim' },
|
|
65
70
|
});
|
|
66
|
-
engine.describe.add('sheepisland', () => ({ view: state.view, season: engine.
|
|
71
|
+
engine.describe.add('sheepisland', () => ({ view: state.view, season: engine.calendar.season, weather: engine.weather?.name }));
|
|
67
72
|
engine.events.on('engine:ready', () => engine.ops.run('sheepisland.view', { name: params.view }));
|
|
68
73
|
if (params.badView) console.warn(`sheepisland: unknown view '${params.badView}', showing overview. Views: ${VIEW_NAMES.join(', ')}`);
|
|
69
74
|
|