threedog 0.2.1 → 0.7.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 +371 -1
- package/README.md +21 -12
- package/core/Animator.js +15 -12
- package/core/Assets.js +92 -26
- package/core/Audio.js +45 -38
- package/core/Baked.js +30 -15
- package/core/Batching.js +102 -15
- package/core/Budget.js +40 -19
- package/core/Clock.js +40 -80
- package/core/DebugOverrides.js +75 -25
- package/core/Describe.js +105 -45
- package/core/Engine.js +203 -75
- package/core/Events.js +4 -1
- package/core/I18n.js +25 -13
- package/core/Input.js +175 -80
- package/core/Inspect.js +8 -5
- package/core/InspectMaterials.js +84 -0
- package/core/InspectPerf.js +68 -0
- package/core/InspectScene.js +13 -2
- package/core/Loading.js +2 -1
- package/core/MaterialInfo.js +7 -5
- package/core/Ops.js +50 -9
- package/core/Random.js +9 -2
- package/core/Rays.js +12 -7
- package/core/SaveStore.js +41 -9
- package/core/Saves.js +71 -15
- package/core/Stream.js +13 -10
- package/core/Threads.js +26 -7
- package/core/UrlState.js +69 -13
- package/core/Views.js +10 -6
- package/core/actor.js +1 -1
- package/core/adaptive.js +93 -0
- package/core/assetEntry.js +27 -7
- package/core/assetHot.js +176 -0
- package/core/assetLoad.js +44 -19
- package/core/assetManifest.js +53 -11
- package/core/assetReport.js +5 -5
- package/core/audioRules.js +13 -11
- package/core/audioVoice.js +69 -42
- package/core/batchGroups.js +9 -1
- package/core/canvasBox.js +1 -2
- package/core/catalog.js +21 -5
- 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 +85 -18
- package/core/describeRender.js +117 -21
- package/core/describeText.js +41 -21
- package/core/engineCamera.js +32 -0
- package/core/errorCodes.js +478 -32
- package/core/errorHints.js +41 -142
- package/core/errors.js +31 -8
- package/core/events.generated.js +13 -7
- package/core/gameLights.js +69 -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 +46 -12
- package/core/lightWatch.js +9 -5
- package/core/loop.js +109 -43
- package/core/math.js +18 -3
- package/core/moduleSlots.js +100 -0
- package/core/moduleTypes.js +86 -0
- package/core/modules.js +147 -29
- package/core/movement.js +2 -2
- package/core/namedModel.js +74 -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 +171 -0
- package/core/page.js +44 -10
- package/core/params.js +30 -8
- package/core/pictureSlots.js +33 -0
- package/core/pictureWriters.js +343 -0
- package/core/plugins.js +245 -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 +211 -0
- package/core/sceneMethods.js +31 -33
- 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 +3 -2
- package/core/shadows.js +405 -0
- package/core/sharedPoint.js +303 -0
- package/core/skip.js +36 -28
- package/core/stackFrames.js +45 -0
- package/core/stacks.js +166 -0
- package/core/startup.js +153 -13
- package/core/streamSources.js +0 -11
- package/core/targeting.js +1 -1
- package/core/textureBytes.js +20 -0
- package/core/thingExplain.js +3 -3
- package/core/thingOps.js +29 -6
- package/core/things.js +22 -12
- 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 +8 -2
- package/core/validate.js +66 -87
- package/core/view.js +43 -0
- package/core/wrap.js +106 -0
- package/docs/AI.md +95 -104
- package/docs/API.md +35 -31
- package/docs/CODEMAP.md +231 -176
- package/docs/COMMANDS.md +63 -39
- package/docs/CONVENTIONS.md +99 -31
- package/docs/MIGRATING-0.3.md +248 -0
- package/docs/MIGRATING-0.4.md +320 -0
- package/docs/MIGRATING-0.5.md +68 -0
- package/docs/MIGRATING-0.6.md +126 -0
- package/docs/MIGRATING-0.7.md +39 -0
- package/docs/PERF.md +35 -7
- package/docs/THREE.md +82 -28
- package/docs/api/ambience.md +0 -1
- package/docs/api/assets.md +15 -11
- package/docs/api/audio.md +10 -14
- package/docs/api/budget.md +4 -0
- package/docs/api/calendar.md +41 -0
- package/docs/api/cameraRig.md +16 -5
- package/docs/api/characters.md +41 -24
- package/docs/api/clock.md +6 -5
- package/docs/api/collision.md +10 -7
- package/docs/api/content.md +6 -4
- package/docs/api/dialogue.md +9 -9
- package/docs/api/engine.md +95 -65
- package/docs/api/events.md +20 -14
- package/docs/api/grids.md +10 -3
- package/docs/api/ground.md +1 -1
- package/docs/api/hud.md +5 -2
- package/docs/api/i18n.md +1 -1
- package/docs/api/input.md +13 -7
- package/docs/api/interactions.md +10 -6
- package/docs/api/inventory.md +17 -17
- package/docs/api/level.md +0 -2
- package/docs/api/lightPool.md +3 -1
- package/docs/api/music.md +1 -1
- package/docs/api/nav.md +3 -0
- package/docs/api/occlusion.md +5 -0
- package/docs/api/openWorld.md +2 -1
- package/docs/api/particles.md +6 -3
- package/docs/api/photo.md +0 -2
- package/docs/api/pickups.md +21 -0
- package/docs/api/post.md +8 -5
- 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 +18 -49
- package/docs/api/stream.md +1 -1
- package/docs/api/terrain.md +16 -7
- package/docs/api/terrainDraw.md +12 -0
- package/docs/api/timeline.md +3 -4
- package/docs/api/tools.md +32 -15
- package/docs/api/triggers.md +7 -10
- package/docs/api/vegetation.md +17 -9
- package/docs/api/vegetationDraw.md +10 -0
- package/docs/api/water.md +9 -21
- package/docs/api/weather.md +10 -15
- package/docs/api/weatherDraw.md +10 -0
- package/docs/api/world.md +3 -2
- package/docs/recipes/01-new-game.md +52 -42
- package/docs/recipes/02-npc.md +24 -7
- package/docs/recipes/03-items-pickups.md +57 -22
- package/docs/recipes/04-quests.md +12 -5
- package/docs/recipes/05-props-bake.md +174 -22
- package/docs/recipes/06-clock-events.md +100 -52
- package/docs/recipes/07-flow-scenes-pause.md +50 -10
- package/docs/recipes/08-weather-sky.md +134 -37
- package/docs/recipes/09-materials-lights-models.md +185 -0
- package/docs/recipes/10-blender-level.md +16 -4
- package/docs/recipes/11-vehicles.md +67 -10
- package/docs/recipes/13-animation.md +23 -9
- package/docs/recipes/14-custom-module.md +63 -29
- package/docs/recipes/15-perf.md +31 -10
- package/docs/recipes/16-dev-bridge.md +74 -40
- package/docs/recipes/18-world.md +26 -14
- package/docs/recipes/19-shooting-picking.md +12 -10
- package/docs/recipes/20-content-actions-save.md +60 -18
- package/docs/recipes/21-camera.md +55 -17
- package/docs/recipes/22-shop-gold.md +3 -3
- package/docs/recipes/23-ops.md +17 -11
- package/docs/recipes/26-ui-parts.md +86 -13
- package/docs/recipes/27-net.md +11 -5
- package/docs/recipes/28-terrain.md +36 -3
- package/docs/recipes/29-grid.md +46 -19
- package/docs/recipes/30-templates.md +72 -15
- package/docs/recipes/31-audio.md +20 -12
- package/docs/recipes/32-action-game.md +51 -4
- package/docs/recipes/34-environment-lighting.md +108 -21
- package/docs/recipes/35-picture-from-reference.md +147 -0
- package/docs/recipes/36-sky-ground-plants.md +158 -0
- package/docs/recipes/{37-terrain-look-hooks.md → 37-terrain-hooks.md} +9 -12
- package/docs/recipes/38-environment-hooks.md +67 -0
- package/docs/recipes/40-scene.md +114 -32
- package/docs/recipes/42-terrain-shape.md +2 -2
- package/docs/recipes/43-shader-patches-surfaces.md +206 -0
- package/docs/recipes/44-water-weather-hooks.md +191 -0
- package/docs/recipes/45-cascaded-shadows.md +130 -23
- package/docs/recipes/46-blender-art-route.md +17 -20
- package/docs/recipes/47-island-snow-backdrop.md +13 -15
- package/docs/recipes/49-game-module-contract.md +30 -17
- package/docs/recipes/50-own-renderer.md +4 -4
- package/docs/recipes/51-capability-catalog.md +3 -3
- package/docs/recipes/52-around-the-picture.md +181 -0
- package/docs/recipes/53-ground-up-close.md +12 -12
- package/docs/recipes/54-three-idioms.md +88 -0
- package/docs/recipes/55-mods-time-wrap.md +124 -0
- package/docs/recipes/56-webgpu-tsl.md +303 -0
- package/docs/recipes/57-control.md +104 -0
- package/docs/recipes/58-input.md +60 -0
- package/docs/recipes/59-depth-post-effects.md +83 -0
- package/docs/recipes/60-judge-the-picture.md +70 -0
- package/docs/recipes/61-deploy.md +27 -0
- package/docs/recipes/62-picture-code.md +244 -0
- package/docs/recipes/63-third-person-start.md +77 -0
- package/docs/recipes/64-particles.md +35 -0
- package/examples/action/.threedog/content-index.json +1 -0
- package/examples/action/GAMEMAP.md +20 -14
- 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/main.js +12 -15
- package/examples/action/models.js +23 -24
- package/examples/action/picture/index.js +13 -0
- package/examples/action/picture/lights.js +35 -0
- package/examples/action/picture/materials.js +8 -0
- package/examples/action/picture/palette.js +33 -0
- package/examples/plain-picture/.threedog/content-index.json +1 -0
- package/examples/plain-picture/FINDINGS.md +53 -0
- package/examples/plain-picture/GAMEMAP.md +90 -0
- package/examples/plain-picture/main.js +48 -0
- package/examples/plain-picture/picture/index.js +21 -0
- package/examples/plain-picture/picture/lights.js +54 -0
- package/examples/plain-picture/picture/materials.js +24 -0
- package/examples/plain-picture/picture/palette.js +16 -0
- package/examples/plain-picture/picture/sky.js +37 -0
- package/examples/pullable.json +133 -0
- package/examples/rc2d/.threedog/content-index.json +1 -0
- package/examples/rc2d/GAMEMAP.md +88 -0
- package/examples/rc2d/README.md +57 -0
- package/examples/rc2d/main.js +55 -0
- package/examples/rc2d/picture/index.js +18 -0
- package/examples/rc2d/picture/lights.js +11 -0
- package/examples/rc2d/picture/materials.js +18 -0
- package/examples/rc2d/picture/palette.js +15 -0
- package/examples/rc2d/picture/post.js +11 -0
- package/examples/rc2d/rc2d.js +187 -0
- package/examples/rc2d/shaders.js +144 -0
- package/examples/sheepisland/.threedog/content-index.json +1 -0
- package/examples/sheepisland/GAMEMAP.md +22 -17
- package/examples/sheepisland/assets.js +5 -0
- package/examples/sheepisland/content/templates.js +1 -1
- package/examples/sheepisland/content/vegetation.js +3 -1
- package/examples/sheepisland/main.js +29 -18
- package/examples/sheepisland/{style/models.js → models.js} +13 -24
- package/examples/sheepisland/picture/index.js +20 -0
- package/examples/sheepisland/picture/lights.js +34 -0
- package/examples/sheepisland/picture/materials.js +61 -0
- package/examples/sheepisland/picture/palette.js +60 -0
- package/examples/sheepisland/picture/sky.js +20 -0
- package/examples/sheepisland/views.js +1 -1
- package/examples/styletest/.threedog/content-index.json +1 -0
- package/examples/styletest/GAMEMAP.md +25 -22
- 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/main.js +25 -34
- package/examples/styletest/models.js +30 -30
- package/examples/styletest/params.js +2 -5
- package/examples/styletest/picture/env.js +38 -0
- package/examples/styletest/picture/index.js +16 -0
- package/examples/styletest/picture/lights.js +9 -0
- package/examples/styletest/picture/materials.js +28 -0
- package/examples/styletest/picture/palette.js +22 -0
- package/examples/techniques/contact-shadows/README.md +91 -0
- package/examples/techniques/contact-shadows/contactShadows.js +67 -0
- package/examples/techniques/contact-shadows/main.js +55 -0
- package/examples/techniques/contact-shadows/picture/index.js +14 -0
- package/examples/techniques/contact-shadows/picture/lights.js +34 -0
- package/examples/techniques/contact-shadows/picture/materials.js +12 -0
- package/examples/techniques/contact-shadows/picture/palette.js +17 -0
- package/examples/techniques/day-night-grade/README.md +83 -0
- package/examples/techniques/day-night-grade/main.js +41 -0
- package/examples/techniques/day-night-grade/picture/index.js +20 -0
- package/examples/techniques/day-night-grade/picture/lights.js +45 -0
- package/examples/techniques/day-night-grade/picture/materials.js +15 -0
- package/examples/techniques/day-night-grade/picture/palette.js +59 -0
- package/examples/techniques/day-night-grade/picture/post.js +25 -0
- package/examples/techniques/day-night-grade/picture/sky.js +33 -0
- package/examples/techniques/interior-light/README.md +106 -0
- package/examples/techniques/interior-light/interiorLight.js +47 -0
- package/examples/techniques/interior-light/main.js +87 -0
- package/examples/techniques/interior-light/picture/index.js +24 -0
- package/examples/techniques/interior-light/picture/lights.js +52 -0
- package/examples/techniques/interior-light/picture/materials.js +13 -0
- package/examples/techniques/interior-light/picture/palette.js +32 -0
- package/examples/techniques/interior-light/picture/sky.js +40 -0
- package/examples/techniques/modular-building/README.md +126 -0
- package/examples/techniques/modular-building/kit.js +426 -0
- package/examples/techniques/modular-building/main.js +39 -0
- package/examples/techniques/modular-building/picture/index.js +17 -0
- package/examples/techniques/modular-building/picture/lights.js +26 -0
- package/examples/techniques/modular-building/picture/materials.js +13 -0
- package/examples/techniques/modular-building/picture/palette.js +23 -0
- package/examples/techniques/night-lights/README.md +95 -0
- package/examples/techniques/night-lights/main.js +47 -0
- package/examples/techniques/night-lights/nightLights.js +95 -0
- package/examples/techniques/night-lights/picture/index.js +18 -0
- package/examples/techniques/night-lights/picture/lights.js +44 -0
- package/examples/techniques/night-lights/picture/materials.js +15 -0
- package/examples/techniques/night-lights/picture/palette.js +34 -0
- package/examples/techniques/night-lights/picture/post.js +9 -0
- package/examples/techniques/night-lights/picture/sky.js +36 -0
- package/examples/techniques/outlines-and-rim/README.md +59 -0
- package/examples/techniques/outlines-and-rim/main.js +61 -0
- package/examples/techniques/outlines-and-rim/outlines.js +64 -0
- package/examples/techniques/outlines-and-rim/picture/index.js +16 -0
- package/examples/techniques/outlines-and-rim/picture/lights.js +18 -0
- package/examples/techniques/outlines-and-rim/picture/materials.js +11 -0
- package/examples/techniques/outlines-and-rim/picture/palette.js +16 -0
- package/examples/techniques/outlines-and-rim/picture/post.js +10 -0
- package/examples/techniques/procedural-animation/README.md +79 -0
- package/examples/techniques/procedural-animation/creature.js +44 -0
- package/examples/techniques/procedural-animation/main.js +47 -0
- package/examples/techniques/procedural-animation/picture/index.js +15 -0
- package/examples/techniques/procedural-animation/picture/lights.js +35 -0
- package/examples/techniques/procedural-animation/picture/materials.js +10 -0
- package/examples/techniques/procedural-animation/picture/palette.js +16 -0
- package/examples/techniques/procedural-animation/picture/sky.js +31 -0
- package/examples/techniques/procedural-animation/proceduralAnim.js +118 -0
- package/examples/techniques/procedural-surface/README.md +69 -0
- package/examples/techniques/procedural-surface/main.js +65 -0
- package/examples/techniques/procedural-surface/picture/index.js +14 -0
- package/examples/techniques/procedural-surface/picture/lights.js +18 -0
- package/examples/techniques/procedural-surface/picture/materials.js +34 -0
- package/examples/techniques/procedural-surface/picture/palette.js +15 -0
- package/examples/techniques/procedural-surface/surface.js +120 -0
- package/examples/techniques/stylized-shading/README.md +74 -0
- package/examples/techniques/stylized-shading/main.js +62 -0
- package/examples/techniques/stylized-shading/picture/index.js +14 -0
- package/examples/techniques/stylized-shading/picture/lights.js +23 -0
- package/examples/techniques/stylized-shading/picture/materials.js +18 -0
- package/examples/techniques/stylized-shading/picture/palette.js +19 -0
- package/examples/techniques/stylized-shading/shading.js +131 -0
- package/examples/techniques/sun-and-key-light/README.md +133 -0
- package/examples/techniques/sun-and-key-light/keyLight.js +71 -0
- package/examples/techniques/sun-and-key-light/main.js +51 -0
- package/examples/techniques/sun-and-key-light/picture/index.js +13 -0
- package/examples/techniques/sun-and-key-light/picture/lights.js +33 -0
- package/examples/techniques/sun-and-key-light/picture/materials.js +9 -0
- package/examples/techniques/sun-and-key-light/picture/palette.js +29 -0
- package/examples/techniques/sun-and-key-light/picture/sky.js +16 -0
- package/examples/techniques/three-looks/README.md +21 -0
- package/examples/techniques/three-looks/main.js +58 -0
- package/examples/techniques/three-looks/picture/cartoon.js +23 -0
- package/examples/techniques/three-looks/picture/cinematic.js +27 -0
- package/examples/techniques/three-looks/picture/comic.js +27 -0
- package/examples/techniques/three-looks/picture/index.js +14 -0
- package/examples/techniques/three-looks/picture/sun.js +23 -0
- package/examples/techniques/wet-road/README.md +102 -0
- package/examples/techniques/wet-road/main.js +48 -0
- package/examples/techniques/wet-road/picture/index.js +17 -0
- package/examples/techniques/wet-road/picture/lights.js +57 -0
- package/examples/techniques/wet-road/picture/materials.js +16 -0
- package/examples/techniques/wet-road/picture/palette.js +24 -0
- package/examples/techniques/wet-road/picture/sky.js +46 -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 +89 -0
- package/examples/webgpu-tsl/README.md +45 -0
- package/examples/webgpu-tsl/main.js +44 -0
- package/examples/webgpu-tsl/picture/index.js +18 -0
- package/examples/webgpu-tsl/picture/lights.js +25 -0
- package/examples/webgpu-tsl/picture/materials.js +36 -0
- package/examples/webgpu-tsl/picture/palette.js +23 -0
- package/examples/webgpu-tsl/picture/post.js +16 -0
- package/examples/webgpu-tsl/picture/sky.js +30 -0
- package/examples/world/.threedog/content-index.json +1 -0
- package/examples/world/GAMEMAP.md +31 -21
- package/examples/world/art/humanoid.js +38 -0
- package/examples/world/art/index.js +11 -0
- package/examples/world/art/models.js +57 -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/items.js +1 -1
- 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 +22 -18
- package/examples/world/models.js +17 -7
- package/examples/world/picture/index.js +20 -0
- package/examples/world/picture/lights.js +41 -0
- package/examples/world/picture/materials.js +34 -0
- package/examples/world/picture/palette.js +74 -0
- package/examples/world/picture/post.js +9 -0
- package/examples/world/picture/sky.js +39 -0
- package/index.d.ts +44 -54
- package/index.js +29 -25
- package/llms.txt +24 -15
- 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 +82 -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 +73 -20
- package/modules/camera/contract.js +17 -0
- package/modules/camera/projection.js +11 -24
- package/modules/characters/Character.js +188 -48
- package/modules/characters/NPC.js +92 -41
- package/modules/characters/assetModel.js +8 -16
- 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 +112 -49
- package/modules/characters/moveHelpers.js +4 -5
- package/modules/characters/movers/common.js +102 -19
- package/modules/characters/movers/manual.js +23 -0
- package/modules/characters/movers/rapier.js +19 -16
- package/modules/characters/movers/simple.js +14 -11
- package/modules/characters/movers/support.js +186 -0
- package/modules/characters/npcAvoid.js +47 -42
- package/modules/characters/npcSim.js +17 -9
- 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 +19 -4
- package/modules/characters/useModel.js +2 -2
- package/modules/characters/vehicle.contract.js +21 -0
- package/modules/characters/walkTo.js +21 -7
- package/modules/collision/Collision.js +69 -27
- 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 +104 -27
- package/modules/content/loader.js +45 -33
- package/modules/content/models.js +58 -42
- package/modules/content/packs.js +6 -5
- package/modules/content/parts.js +41 -0
- package/modules/content/props.js +20 -11
- package/modules/content/rules.js +66 -0
- package/modules/content/stages.js +80 -0
- package/modules/content/templates.js +123 -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 +273 -72
- package/modules/gameplay/Inventory.js +72 -76
- 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 +19 -17
- package/modules/gameplay/pickups.js +306 -85
- package/modules/gameplay/questLog.js +6 -6
- package/modules/gameplay/quests.contract.js +17 -0
- package/modules/grid/Grid.js +92 -50
- package/modules/grid/Layer.js +27 -13
- package/modules/grid/index.js +96 -43
- package/modules/grid/ops.js +20 -18
- package/modules/grid/preview.js +37 -29
- package/modules/grid/strings.js +12 -0
- package/modules/grid/tiles.js +19 -22
- package/modules/hlod/index.js +52 -19
- package/modules/hud/index.js +48 -20
- package/modules/hud/parts.js +28 -13
- package/modules/level/heightfield.js +3 -1
- package/modules/level/index.js +49 -23
- package/modules/level/nodes.js +4 -3
- package/modules/lights/index.js +47 -19
- 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 +58 -28
- package/modules/particles/contract.js +17 -0
- package/modules/particles/effect.js +54 -11
- package/modules/photo/Photo.js +56 -38
- 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 +60 -55
- 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 +132 -205
- package/modules/sky/clouds.js +37 -23
- package/modules/sky/dome.js +100 -0
- package/modules/sky/domeLayers.js +30 -15
- package/modules/sky/environment.js +45 -99
- package/modules/sky/fog.js +9 -139
- package/modules/sky/frame.js +60 -56
- package/modules/sky/season.js +21 -0
- package/modules/sky/shader.js +63 -35
- package/modules/sky/skyModule.js +52 -37
- package/modules/sky/tint.js +59 -0
- package/modules/terrain/ChunkManager.js +194 -110
- package/modules/terrain/chunkJob.js +1 -1
- package/modules/terrain/chunkQueries.js +6 -4
- package/modules/terrain/draw.js +154 -0
- package/modules/terrain/index.js +87 -54
- package/modules/terrain/terrainDefaults.js +2 -2
- package/modules/terrain/terrainEdit.js +18 -20
- package/modules/terrain/terrainGen.js +6 -4
- 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 +111 -76
- package/modules/vegetation/Vegetation.js +229 -112
- package/modules/vegetation/densityMap.js +62 -0
- package/modules/vegetation/draw.js +191 -0
- package/modules/vegetation/groundChunks.js +52 -58
- package/modules/vegetation/index.js +32 -11
- package/modules/vegetation/modelGeometry.js +3 -2
- package/modules/vegetation/nearFade.js +8 -2
- package/modules/water/Water.js +157 -72
- package/modules/water/surface.js +86 -47
- package/modules/weather/Weather.js +96 -103
- package/modules/weather/particles.js +37 -14
- package/modules/weather/shaders.js +1 -1
- package/modules/weather/strings.js +2 -2
- package/modules/weather/weatherDraw.js +141 -0
- package/modules/world/World.js +26 -9
- 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 +8 -6
- package/package.json +8 -3
- package/presets.js +43 -29
- package/render/PostFX.js +318 -135
- package/render/backend.js +486 -0
- package/render/cascades.js +195 -0
- package/render/cascades.tsl.js +96 -0
- package/render/daylight.js +39 -0
- package/render/detail.js +122 -41
- package/render/effects.js +155 -48
- package/render/engineUniforms.js +10 -1
- package/render/fuse.js +5 -4
- package/render/fx/cel.tsl.js +42 -0
- package/render/fx/cloudShadow.tsl.js +16 -0
- package/render/fx/detail.tsl.js +66 -0
- package/render/fx/index.js +28 -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 +181 -0
- package/render/fx/season.tsl.js +13 -0
- package/render/fx/sky.tsl.js +187 -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/layers.js +14 -0
- package/render/lighting.js +71 -18
- package/render/lightmap.js +142 -0
- package/render/lights.js +47 -6
- package/render/materials.js +55 -152
- package/render/modeling.js +73 -0
- package/render/neutral.js +23 -0
- package/render/occlusion.js +184 -0
- package/render/ownFrame.js +76 -0
- package/render/patches.js +317 -35
- package/render/postWebGL.js +205 -0
- package/render/probes.js +288 -0
- package/render/shaderErrors.js +154 -0
- package/render/slots.js +165 -0
- package/render/terms.js +163 -0
- package/render/uniformDecl.js +4 -3
- package/types/common.d.ts +2 -2
- package/types/core.d.ts +757 -346
- package/types/gameplay.d.ts +539 -330
- 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 +58 -9
- package/types/generated/core/I18n.d.ts +2 -2
- package/types/generated/core/Input.d.ts +110 -32
- 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/page.d.ts +9 -2
- 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 +13 -5
- package/types/generated/modules/grid/index.d.ts +56 -20
- 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 +13 -6
- package/types/generated/modules/sky/Sky.d.ts +85 -110
- package/types/generated/modules/sky/skyModule.d.ts +1 -1
- package/types/generated/modules/timeline/Timeline.d.ts +8 -6
- package/types/generated/modules/water/Water.d.ts +50 -3
- package/types/generated/modules/weather/Weather.d.ts +44 -15
- package/types/generated/modules/weather/weatherDraw.d.ts +11 -0
- package/types/generated/modules/world/World.d.ts +20 -5
- package/types/generated/render/PostFX.d.ts +109 -29
- package/types/generated/render/lighting.d.ts +29 -0
- package/types/generated/render/materials.d.ts +31 -50
- package/types/generated/render/modeling.d.ts +30 -0
- package/types/generated/render/occlusion.d.ts +13 -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 +140 -45
- package/types/tsl.d.ts +94 -0
- package/types/world.d.ts +489 -122
- package/ui/Focus.js +35 -14
- package/ui/LoadingScreen.js +3 -3
- package/ui/Parts.js +35 -15
- package/ui/UI.js +27 -17
- package/ui/cursor.js +115 -0
- package/ui/defaults.js +15 -11
- package/ui/theme.js +36 -27
- package/ui/touchPart.js +2 -2
- package/core/claims.js +0 -51
- package/core/look/coreParts.js +0 -112
- package/core/look/layers.js +0 -136
- package/core/look/part.js +0 -173
- package/core/look/report.js +0 -79
- package/core/look/write.js +0 -86
- package/core/renamed.js +0 -22
- package/core/styleParts.js +0 -98
- package/docs/api/entities.md +0 -61
- package/docs/api/style.md +0 -134
- package/docs/recipes/09-style-pack.md +0 -169
- package/docs/recipes/35-style-from-reference.md +0 -84
- package/docs/recipes/36-sky-ground-plant-looks.md +0 -118
- package/docs/recipes/38-environment-look-hooks.md +0 -88
- package/docs/recipes/41-thing-registry.md +0 -93
- package/docs/recipes/43-shader-patches-surface-looks.md +0 -135
- package/docs/recipes/44-water-weather-look-hooks.md +0 -135
- package/docs/recipes/48-make-material.md +0 -70
- package/docs/recipes/52-look.md +0 -146
- package/examples/action/look.js +0 -5
- package/examples/sheepisland/style/index.js +0 -79
- package/examples/styletest/look.js +0 -11
- 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/cascades.js +0 -125
- package/modules/sky/layers.js +0 -69
- package/modules/sky/look.js +0 -51
- package/modules/sky/lookFog.js +0 -80
- package/modules/sky/lookShadow.js +0 -50
- package/modules/sky/lookSky.js +0 -108
- package/modules/sky/shadow.js +0 -74
- package/modules/terrain/chunkLevels.js +0 -40
- package/modules/terrain/lookGround.js +0 -61
- package/modules/terrain/mountTerrain.js +0 -32
- package/modules/vegetation/lookWind.js +0 -37
- package/modules/water/look.js +0 -80
- package/modules/weather/look.js +0 -75
- package/modules/world/cells.js +0 -42
- package/render/lookSurface.js +0 -161
- package/render/postLook.js +0 -86
- package/render/surface.js +0 -69
- package/types/style.d.ts +0 -643
|
@@ -0,0 +1,187 @@
|
|
|
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
|
+
// yourPostChain.add(rc.pass); // a plain three.js Pass; before the tone curve, the light is linear
|
|
9
|
+
// rc.describe(); rc.texture; rc.resize(); rc.dispose();
|
|
10
|
+
//
|
|
11
|
+
// Each frame (engine.onRender, before the frame): the meshes on `layer` are drawn from the game camera into a scene target (rgb = their emissive,
|
|
12
|
+
// a = solid) -> jump flood -> distance field -> cascades traced and merged from the coarsest down -> gather into `texture` (linear light per
|
|
13
|
+
// screen pixel). `pass` is a three.js ShaderPass that adds that light to the frame; the caller puts it in the post chain, or leaves it out and
|
|
14
|
+
// samples `texture` in its own materials (screen uv). Colours and strengths are the game's: a lamp shines with its material's emissive * emissiveIntensity.
|
|
15
|
+
import * as THREE from 'three';
|
|
16
|
+
import { FullScreenQuad } from 'three/addons/postprocessing/Pass.js';
|
|
17
|
+
import { ShaderPass } from 'three/addons/postprocessing/ShaderPass.js';
|
|
18
|
+
import { VERT, SEED, JFA, DIST, CASCADE, GATHER, APPLY } from './shaders.js';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The parameters, in one place. quality: RC resolution as a share of the screen (CSS pixels) and the march step cap per ray.
|
|
22
|
+
* 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.
|
|
23
|
+
* ambient: the light level the frame is already lit with (albedo = color / ambient).
|
|
24
|
+
*/
|
|
25
|
+
export const RC2D_DEFAULTS = Object.freeze({ layer: 5, quality: 'medium', cascades: 'auto', interval: 4, ambient: 1 });
|
|
26
|
+
/** @typedef {{ layer?: number, quality?: 'low' | 'medium' | 'high', cascades?: number | 'auto', interval?: number, ambient?: number }} Rc2dOptions */
|
|
27
|
+
export const RC2D_QUALITY = Object.freeze({ low: { scale: 0.25, steps: 16 }, medium: { scale: 0.5, steps: 24 }, high: { scale: 1, steps: 32 } });
|
|
28
|
+
const SPACING0 = 2; // cascade 0 probe spacing (RC pixels); with 4 directions it keeps every cascade target about the scene target's size
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @param {any} engine a threedog engine (renderer, scene, onRender)
|
|
32
|
+
* @param {Rc2dOptions} [options]
|
|
33
|
+
*/
|
|
34
|
+
export function createRadianceCascades2D(engine, options = {}) {
|
|
35
|
+
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(', ')}`);
|
|
36
|
+
const o = /** @type {Required<Rc2dOptions>} */ ({ ...RC2D_DEFAULTS, ...options });
|
|
37
|
+
const q = RC2D_QUALITY[/** @type {keyof typeof RC2D_QUALITY} */ (o.quality)];
|
|
38
|
+
if (!q) throw new Error(`rc2d: quality '${o.quality}' is not one of ${Object.keys(RC2D_QUALITY).join(', ')}`);
|
|
39
|
+
if (!(o.interval > 0)) throw new Error(`rc2d: interval is cascade 0's ray length in RC pixels (> 0), got ${o.interval}`);
|
|
40
|
+
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}`);
|
|
41
|
+
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}`);
|
|
42
|
+
if (!(o.ambient > 0)) throw new Error(`rc2d: ambient is the light level the frame is already lit with (> 0), got ${o.ambient}`);
|
|
43
|
+
|
|
44
|
+
const { renderer, scene } = engine;
|
|
45
|
+
const quad = new FullScreenQuad();
|
|
46
|
+
const mat = (/** @type {string} */ fragmentShader, /** @type {Record<string, any>} */ uniforms, defines = {}) => new THREE.ShaderMaterial({
|
|
47
|
+
vertexShader: VERT, fragmentShader, uniforms, defines, depthTest: false, depthWrite: false });
|
|
48
|
+
const u = (/** @type {any} */ v) => ({ value: v });
|
|
49
|
+
const mats = {
|
|
50
|
+
seed: mat(SEED, { tScene: u(null) }),
|
|
51
|
+
jfa: mat(JFA, { tSeed: u(null), uSize: u(new THREE.Vector2()), uStep: u(1) }),
|
|
52
|
+
dist: mat(DIST, { tSeed: u(null) }),
|
|
53
|
+
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),
|
|
54
|
+
uSpacing: u(SPACING0), uStart: u(0), uLen: u(1), uHasUpper: u(0), uUpperTile: u(new THREE.Vector2()), uUpperS: u(4) },
|
|
55
|
+
{ STEPS: q.steps }),
|
|
56
|
+
gather: mat(GATHER, { tC0: u(null), uTile0: u(new THREE.Vector2()), uTex0: u(new THREE.Vector2()), uSpacing0: u(SPACING0) }),
|
|
57
|
+
};
|
|
58
|
+
// frame * (1 + gi / ambient), in linear colour before tone mapping. tGI is written after each gather: a resize makes a new texture
|
|
59
|
+
const pass = new ShaderPass(mat(APPLY, { tDiffuse: u(null), tGI: u(null), uAmbient: u(o.ambient) }));
|
|
60
|
+
/** @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} */
|
|
61
|
+
let t = null;
|
|
62
|
+
const size = new THREE.Vector2(), css = new THREE.Vector2();
|
|
63
|
+
let disposed = false;
|
|
64
|
+
|
|
65
|
+
const target = (/** @type {number} */ w, /** @type {number} */ h, /** @type {object} */ extra = {}) => new THREE.WebGLRenderTarget(w, h,
|
|
66
|
+
{ type: THREE.HalfFloatType, minFilter: THREE.NearestFilter, magFilter: THREE.NearestFilter, depthBuffer: false, ...extra });
|
|
67
|
+
const freeTargets = () => {
|
|
68
|
+
if (!t) return;
|
|
69
|
+
for (const rt of [t.scene, ...t.seed, t.dist, t.gi, ...t.cascades.map(c => c.rt)]) rt.dispose();
|
|
70
|
+
t = null;
|
|
71
|
+
};
|
|
72
|
+
// Sized from the renderer's CSS size (not the drawing buffer), so adaptive resolution changing the pixel ratio does not rebuild everything
|
|
73
|
+
function build() {
|
|
74
|
+
renderer.getSize(css);
|
|
75
|
+
const w = Math.max(8, Math.ceil(css.x * q.scale)), h = Math.max(8, Math.ceil(css.y * q.scale));
|
|
76
|
+
if (t && size.x === w && size.y === h) return;
|
|
77
|
+
freeTargets();
|
|
78
|
+
size.set(w, h);
|
|
79
|
+
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;
|
|
80
|
+
const cascades = [];
|
|
81
|
+
for (let i = 0; i < n; i++) {
|
|
82
|
+
const spacing = SPACING0 * 2 ** i, s = 2 ** (i + 1); // probes halve per axis, directions x4: each target stays near the scene size
|
|
83
|
+
const tile = new THREE.Vector2(Math.ceil(w / spacing), Math.ceil(h / spacing));
|
|
84
|
+
// linear filtering for cascade 0 only: the gather reads 4 neighbouring probes in one fetch (the merge reads exact texels)
|
|
85
|
+
const filter = i === 0 ? THREE.LinearFilter : THREE.NearestFilter;
|
|
86
|
+
cascades.push({ rt: target(tile.x * s, tile.y * s, { minFilter: filter, magFilter: filter }), tile, s, spacing,
|
|
87
|
+
start: o.interval * (4 ** i - 1) / 3, len: o.interval * 4 ** i });
|
|
88
|
+
}
|
|
89
|
+
t = { scene: target(w, h), seed: [target(w, h, { type: THREE.FloatType }), target(w, h, { type: THREE.FloatType })], dist: target(w, h),
|
|
90
|
+
gi: target(w, h, { minFilter: THREE.LinearFilter, magFilter: THREE.LinearFilter }), cascades };
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const draw = (/** @type {THREE.ShaderMaterial} */ m, /** @type {THREE.WebGLRenderTarget} */ rt) => { quad.material = m; renderer.setRenderTarget(rt); quad.render(renderer); };
|
|
94
|
+
|
|
95
|
+
// The meshes on `layer` drawn with a flat material each: colour = their emissive (0 for walls), alpha 1 = solid. Cached per source material.
|
|
96
|
+
/** @type {WeakMap<THREE.Material, THREE.MeshBasicMaterial>} */
|
|
97
|
+
const proxies = new WeakMap();
|
|
98
|
+
const swapped = /** @type {[THREE.Mesh, any][]} */ ([]);
|
|
99
|
+
const proxyOf = (/** @type {any} */ m) => {
|
|
100
|
+
let p = proxies.get(m);
|
|
101
|
+
// hint-off(material): a flat stand-in whose colour is the source material's emissive, not art
|
|
102
|
+
if (!p) { p = new THREE.MeshBasicMaterial({ fog: false, toneMapped: false }); proxies.set(m, p); }
|
|
103
|
+
p.color.setRGB(0, 0, 0);
|
|
104
|
+
if (m.emissive) p.color.copy(m.emissive).multiplyScalar(m.emissiveIntensity ?? 1); // read every frame: flicker and day / night keep working
|
|
105
|
+
p.side = m.side;
|
|
106
|
+
return p;
|
|
107
|
+
};
|
|
108
|
+
const clear = new THREE.Color();
|
|
109
|
+
function drawScene(/** @type {THREE.Camera} */ camera) {
|
|
110
|
+
scene.traverse((/** @type {any} */ obj) => {
|
|
111
|
+
if (!obj.isMesh || !obj.layers.isEnabled(o.layer)) return;
|
|
112
|
+
swapped.push([obj, obj.material]);
|
|
113
|
+
obj.material = Array.isArray(obj.material) ? obj.material.map(proxyOf) : proxyOf(obj.material);
|
|
114
|
+
});
|
|
115
|
+
// 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
|
|
116
|
+
const mask = camera.layers.mask, bg = scene.background, alpha = renderer.getClearAlpha(), auto = renderer.shadowMap.autoUpdate;
|
|
117
|
+
renderer.getClearColor(clear);
|
|
118
|
+
camera.layers.set(o.layer); scene.background = null; renderer.shadowMap.autoUpdate = false;
|
|
119
|
+
renderer.setClearColor(0x000000, 0);
|
|
120
|
+
renderer.setRenderTarget(t.scene); renderer.clear(); renderer.render(scene, camera);
|
|
121
|
+
renderer.setClearColor(clear, alpha); renderer.shadowMap.autoUpdate = auto; scene.background = bg; camera.layers.mask = mask;
|
|
122
|
+
for (const [obj, m] of swapped) obj.material = m;
|
|
123
|
+
swapped.length = 0;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
let frameMs = 0;
|
|
127
|
+
function update(/** @type {{ camera: THREE.Camera }} */ { camera }) {
|
|
128
|
+
if (disposed) return;
|
|
129
|
+
const t0 = performance.now(); // measure: CPU-side submit time only (describe().ms); GPU time needs the perf tool
|
|
130
|
+
build();
|
|
131
|
+
if (!t) return;
|
|
132
|
+
drawScene(camera);
|
|
133
|
+
// jump flood: seed, then steps of half the largest power of two down to 1, ping-ponging the two float targets
|
|
134
|
+
mats.seed.uniforms.tScene.value = t.scene.texture; draw(mats.seed, t.seed[0]);
|
|
135
|
+
let src = 0;
|
|
136
|
+
mats.jfa.uniforms.uSize.value.copy(size);
|
|
137
|
+
for (let step = 2 ** Math.floor(Math.log2(Math.max(size.x, size.y))); step >= 1; step /= 2) {
|
|
138
|
+
mats.jfa.uniforms.tSeed.value = t.seed[src].texture; mats.jfa.uniforms.uStep.value = step;
|
|
139
|
+
draw(mats.jfa, t.seed[1 - src]); src = 1 - src;
|
|
140
|
+
}
|
|
141
|
+
mats.dist.uniforms.tSeed.value = t.seed[src].texture; draw(mats.dist, t.dist);
|
|
142
|
+
// cascades from the coarsest (longest rays, fewest probes) to cascade 0, each merging the one above it
|
|
143
|
+
const cu = mats.cascade.uniforms;
|
|
144
|
+
cu.tScene.value = t.scene.texture; cu.tDist.value = t.dist.texture; cu.uSize.value.copy(size);
|
|
145
|
+
for (let i = t.cascades.length - 1; i >= 0; i--) {
|
|
146
|
+
const c = t.cascades[i], up = t.cascades[i + 1];
|
|
147
|
+
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;
|
|
148
|
+
cu.uHasUpper.value = up ? 1 : 0;
|
|
149
|
+
if (up) { cu.tUpper.value = up.rt.texture; cu.uUpperTile.value.copy(up.tile); cu.uUpperS.value = up.s; }
|
|
150
|
+
else cu.tUpper.value = null; // never the target being written
|
|
151
|
+
draw(mats.cascade, c.rt);
|
|
152
|
+
}
|
|
153
|
+
const c0 = t.cascades[0], gu = mats.gather.uniforms;
|
|
154
|
+
gu.tC0.value = c0.rt.texture; gu.uTile0.value.copy(c0.tile); gu.uTex0.value.set(c0.rt.width, c0.rt.height);
|
|
155
|
+
draw(mats.gather, t.gi);
|
|
156
|
+
pass.uniforms.tGI.value = t.gi.texture;
|
|
157
|
+
renderer.setRenderTarget(null);
|
|
158
|
+
frameMs = performance.now() - t0;
|
|
159
|
+
}
|
|
160
|
+
const hook = engine.onRender(update);
|
|
161
|
+
|
|
162
|
+
return {
|
|
163
|
+
/** The ShaderPass that adds the light to the frame. Yours to put in the post chain; take it out of the chain before dispose() */
|
|
164
|
+
pass,
|
|
165
|
+
/** The gathered light, linear rgb per screen uv (null before the first frame); a new texture after a resize */
|
|
166
|
+
get texture() { return t ? t.gi.texture : null; },
|
|
167
|
+
/** The render target holding `texture` (HalfFloat RGBA, linear filtering), for size or readRenderTargetPixels (Uint16Array, half floats) */
|
|
168
|
+
get target() { return t ? t.gi : null; },
|
|
169
|
+
/** Re-read the render size now (it is also checked every frame); rebuilds the targets when it changed */
|
|
170
|
+
resize() { if (!disposed) build(); },
|
|
171
|
+
/** Remove the hook, free every render target and material, the pass's too */
|
|
172
|
+
dispose() {
|
|
173
|
+
if (disposed) return;
|
|
174
|
+
disposed = true;
|
|
175
|
+
hook.remove();
|
|
176
|
+
freeTargets();
|
|
177
|
+
for (const m of Object.values(mats)) m.dispose();
|
|
178
|
+
quad.dispose();
|
|
179
|
+
pass.dispose();
|
|
180
|
+
},
|
|
181
|
+
describe() {
|
|
182
|
+
return { size: [size.x, size.y], quality: o.quality, layer: o.layer, interval: o.interval, ambient: o.ambient,
|
|
183
|
+
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] })) : [],
|
|
184
|
+
targets: t ? 5 + t.cascades.length : 0, cpuMs: +frameMs.toFixed(2), disposed };
|
|
185
|
+
},
|
|
186
|
+
};
|
|
187
|
+
}
|
|
@@ -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":1793829782000,"from":0,"count":15,"indexIds":0,"positional":[]},"content/templates.js":{"kind":"templates","mtime":1793829782000,"from":0,"count":2,"indexIds":0,"positional":[]},"content/vegetation.js":{"kind":"vegetation","mtime":1793829782000,"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}]}}
|
|
@@ -11,28 +11,29 @@ 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: {
|
|
15
|
-
- openWorld preset ({ camera: fixedCamera(), terrain: island, water: false, rigid: false, ambience: false,
|
|
14
|
+
- createEngine: { bindings: { ...presets.bindings.debug }, lights: false, saveKey: 'threedog-sheepisland', ui: { loading: { t…
|
|
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
20
|
- world: `node_modules/threedog/docs/recipes/18-world.md` · `node_modules/threedog/docs/api/world.md`
|
|
21
|
-
- terrain: `node_modules/threedog/docs/recipes/
|
|
22
|
-
- vegetation: `node_modules/threedog/docs/recipes/
|
|
21
|
+
- terrain: `node_modules/threedog/docs/recipes/36-sky-ground-plants.md` · `node_modules/threedog/docs/api/terrain.md`
|
|
22
|
+
- vegetation: `node_modules/threedog/docs/recipes/36-sky-ground-plants.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
|
-
- weather: `node_modules/threedog/docs/recipes/
|
|
25
|
+
- weather: `node_modules/threedog/docs/recipes/44-water-weather-hooks.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
|
-
- characters: `node_modules/threedog/docs/recipes/
|
|
27
|
+
- characters: `node_modules/threedog/docs/recipes/13-animation.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,14 +42,19 @@ 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
|
-
| content/vegetation.js |
|
|
48
|
-
| main.js |
|
|
49
|
+
| content/vegetation.js | 11 | |
|
|
50
|
+
| 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 | sheepisland procedural models: a round tree, a sheep, a wheat tuft. Built in code, no files; regist… |
|
|
49
52
|
| params.js | 26 | URL parameters of the sheep island page. Import this file first in main.js: it rewrites word values… |
|
|
50
|
-
|
|
|
51
|
-
|
|
|
53
|
+
| picture/index.js | 21 | @ts-check The picture of sheep island: wiring only. Each part writes plain three.js from the signal… |
|
|
54
|
+
| picture/lights.js | 35 | @ts-check Sun or moon and ambient, both from the day table in palette.js. |
|
|
55
|
+
| 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 Sheep island palette: every color and key value of the picture, one copy. A soft painted … |
|
|
57
|
+
| picture/sky.js | 21 | @ts-check A flat painted backdrop: one color at every height, the same as the fog, so the island fl… |
|
|
52
58
|
| views.js | 10 | Named camera positions of the sheep island. Same name = same framing every time, so two screenshots… |
|
|
53
59
|
|
|
54
60
|
## NPCs (content/npcs.js)
|
|
@@ -71,7 +77,7 @@ content/*.js is content data: how to write it in `node_modules/threedog/docs/rec
|
|
|
71
77
|
|
|
72
78
|
(none)
|
|
73
79
|
|
|
74
|
-
## Object templates (content/templates.js; placed with props { template }, spawned with engine.spawn)
|
|
80
|
+
## Object templates (content/templates.js; placed with props { template }, spawned with engine.content.spawn)
|
|
75
81
|
|
|
76
82
|
| Template | Model | Collide | Interact (op / label) | Container | State (defaults) | Instances |
|
|
77
83
|
|---|---|---|---|---|---|---|
|
|
@@ -98,10 +104,9 @@ Code that breaks saves or manages world models: none (rule R33).
|
|
|
98
104
|
## Saves
|
|
99
105
|
|
|
100
106
|
- Save prefix saveKey: threedog-sheepisland
|
|
101
|
-
- Saved parts of the engine modules (vars, inventory, quests, timers, world...): `
|
|
107
|
+
- Saved parts of the engine modules (vars, inventory, quests, timers, world...): `threedog catalog` (saves per module)
|
|
102
108
|
|
|
103
|
-
## Style
|
|
109
|
+
## Style keys
|
|
104
110
|
|
|
105
|
-
- Style pack: none (all neutral fallback look)
|
|
106
111
|
- Models (asset names): wheatTuft, roundTree, sheep
|
|
107
112
|
- 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 { models } from './models.js'; // roundTree, sheep, wheatTuft
|
|
4
|
+
|
|
5
|
+
export default [{ name: 'sheepisland', models }];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Templates: the island's two kinds of objects. Model names come from the example's
|
|
1
|
+
// Templates: the island's two kinds of objects. Model names come from the example's asset pack (models.js, registered in main.js).
|
|
2
2
|
export default {
|
|
3
3
|
tree: { model: 'roundTree', collide: 'circle' },
|
|
4
4
|
sheep: { model: 'sheep' },
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
// Vegetation: the wheat field. Tufts grow only on the ground type 'wheat' (main.js groundType), so the field's edge is the terrain's, not a list
|
|
2
2
|
// of positions. rule cannot hold functions (it is sent to a worker thread).
|
|
3
|
+
import { mat } from '../picture/materials.js';
|
|
4
|
+
|
|
3
5
|
export default {
|
|
4
6
|
wheat: {
|
|
5
|
-
model: 'wheatTuft', wind: 0.04, castShadow: true,
|
|
7
|
+
model: 'wheatTuft', material: mat.wheat, wind: 0.04, castShadow: true,
|
|
6
8
|
rule: { perChunk: 9000, cluster: 'none', scale: [1.1, 1.4], stretch: [0.9, 1.15], sink: 0.02, biomes: { wheat: 1 }, avoidFlat: false },
|
|
7
9
|
},
|
|
8
10
|
};
|
|
@@ -1,25 +1,35 @@
|
|
|
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
|
+
// 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
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.
|
|
4
5
|
// Parameters (params.js): time day | dusk | night, weather clear | snow, view overview | flock | field | river | rim.
|
|
5
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),
|
|
6
|
-
// the
|
|
7
|
+
// the whole picture is plain three.js in picture/.
|
|
7
8
|
import { params, VIEW_NAMES } from './params.js'; // first: rewrites ?time=dusk style words before the engine reads the URL
|
|
8
9
|
import { createEngine, openWorld, presets, content, fixedCamera } from '../../index.js';
|
|
9
|
-
import
|
|
10
|
+
import { createPicture } from './picture/index.js';
|
|
11
|
+
import { GROUND } from './picture/palette.js';
|
|
12
|
+
import { mat } from './picture/materials.js';
|
|
13
|
+
import packs from './assets.js';
|
|
10
14
|
import data from './content/index.js';
|
|
11
15
|
import { VIEWS } from './views.js';
|
|
12
16
|
|
|
13
|
-
// ---------- 1. The island: outline, height and ground types are world rules, so they live here, not in
|
|
17
|
+
// ---------- 1. The island: outline, height and ground types are world rules, so they live here, not in picture/ ----------
|
|
14
18
|
// Every function runs in terrain workers: pure, only its parameters and Math (recipe 28 §1).
|
|
15
19
|
const island = {
|
|
20
|
+
...GROUND,
|
|
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
|
|
16
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 42 §4)
|
|
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
|
+
// ground type cannot drift apart
|
|
25
|
+
params: { river: { amp: 6, freq: 0.09, shift: 2, dip: 3.2, wet: 2.4 } },
|
|
17
26
|
height: (x, z, n) => {
|
|
18
|
-
const d = Math.abs(z - (
|
|
19
|
-
return 3 + 1.2 * n.fbm(x * 0.03, z * 0.03) - (d <
|
|
27
|
+
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
|
|
28
|
+
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
29
|
},
|
|
21
|
-
groundType: (x, z) => {
|
|
22
|
-
|
|
30
|
+
groundType: (x, z, h, slope, n) => {
|
|
31
|
+
const r = n.params.river;
|
|
32
|
+
if (Math.abs(z - (r.amp * Math.sin(x * r.freq) + r.shift)) < r.wet) return 'river';
|
|
23
33
|
const fx = (x - 14) / 9.5, fz = (z + 13) / 6.5; // the wheat field: an ellipse north-east of the river
|
|
24
34
|
return fx * fx + fz * fz < 1 ? 'wheat' : 'grass';
|
|
25
35
|
},
|
|
@@ -27,27 +37,28 @@ const island = {
|
|
|
27
37
|
mask: (x, z) => 30 - Math.hypot(x, z * 1.15), // > 0 is ground: a 60 x 52 m oval
|
|
28
38
|
// a ragged outline and a chipped rim. round stays 0: with round > 0 the bent-down top leaves see-through gaps above the wall (acceptance notes)
|
|
29
39
|
edge: { noise: 3, size: 9, jitter: 0.5, round: 0 },
|
|
30
|
-
// own wall material: it takes no
|
|
31
|
-
side: { depth: 2.5, material:
|
|
40
|
+
// own wall material: it takes no snow, so in snow the earth walls stay brown under a white top
|
|
41
|
+
side: { depth: 2.5, material: mat.cliff },
|
|
32
42
|
bottom: { depth: (x, z, n, m) => 1.5 + m * 0.35 + 2 * n.fbm(x * 0.08, z * 0.08), ground: 'rock' }, // hangs lower inland
|
|
33
43
|
},
|
|
34
44
|
};
|
|
35
45
|
|
|
36
|
-
// ---------- 2. Engine:
|
|
46
|
+
// ---------- 2. Engine: no placeholder lights, open-world preset with a fixed sky; a two-season calendar so snow can turn the island white ----------
|
|
37
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%)
|
|
38
|
-
const engine = createEngine({ canvas: /** @type {HTMLCanvasElement} */ (document.getElementById('view')),
|
|
48
|
+
const engine = createEngine({ bindings: { ...presets.bindings.debug }, canvas: /** @type {HTMLCanvasElement} */ (document.getElementById('view')), lights: false, saveKey: 'threedog-sheepisland',
|
|
39
49
|
ui: { loading: { title: 'sheep island' } } });
|
|
40
50
|
engine.use(openWorld({ camera: fixedCamera(), terrain: island, water: false, rigid: false, ambience: false,
|
|
41
|
-
|
|
51
|
+
calendar: { ...presets.calendar.fixedTime, time: 0.5, seasons: ['summer', 'winter'], daysPerSeason: 1000 },
|
|
42
52
|
weather: { ...presets.weather.temperate, start: 'clear' }, autoWeather: false }), content());
|
|
43
|
-
engine
|
|
53
|
+
const picture = createPicture(engine);
|
|
54
|
+
engine.assets.manifest(packs);
|
|
44
55
|
engine.content.load(data);
|
|
45
56
|
|
|
46
|
-
// ---------- 3. Snow means winter:
|
|
57
|
+
// ---------- 3. Snow means winter: picture/materials.js whitens foliage and ground when the season is winter ----------
|
|
47
58
|
// 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
59
|
engine.onFrame(() => {
|
|
49
60
|
const day = engine.weather?.name === 'snow' ? WINTER_DAY : 1;
|
|
50
|
-
if (engine.
|
|
61
|
+
if (engine.calendar.day !== day) engine.calendar.day = day;
|
|
51
62
|
});
|
|
52
63
|
|
|
53
64
|
// ---------- 4. Views: an op, so the URL, the dev bridge and tests switch the same way ----------
|
|
@@ -63,9 +74,9 @@ engine.ops.define('sheepisland.view', {
|
|
|
63
74
|
},
|
|
64
75
|
reasons: { unknownView: 'View names: overview, flock, field, river, rim' },
|
|
65
76
|
});
|
|
66
|
-
engine.describe.add('sheepisland', () => ({ view: state.view, season: engine.
|
|
77
|
+
engine.describe.add('sheepisland', () => ({ view: state.view, season: engine.calendar.season, weather: engine.weather?.name }));
|
|
67
78
|
engine.events.on('engine:ready', () => engine.ops.run('sheepisland.view', { name: params.view }));
|
|
68
79
|
if (params.badView) console.warn(`sheepisland: unknown view '${params.badView}', showing overview. Views: ${VIEW_NAMES.join(', ')}`);
|
|
69
80
|
|
|
70
81
|
engine.start();
|
|
71
|
-
window
|
|
82
|
+
Object.assign(window, { engine, picture }); // handy for debugging in the browser console
|
|
@@ -1,19 +1,9 @@
|
|
|
1
|
-
// sheepisland procedural models: a round tree, a sheep, a wheat tuft. Built in code, no files; registered as an asset pack (
|
|
2
|
-
// Colors come
|
|
1
|
+
// sheepisland procedural models: a round tree, a sheep, a wheat tuft. Built in code, no files; registered as an asset pack (assets.js).
|
|
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
|
-
import { THREE,
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export const PALETTE = {
|
|
8
|
-
leaf: 0x6fa64a, // tree crown, main
|
|
9
|
-
leafLight: 0x8fbf5c, // tree crown, upper blobs
|
|
10
|
-
bark: 0x8a6448,
|
|
11
|
-
wool: 0xf3efe6,
|
|
12
|
-
face: 0x2b2725, // sheep face and legs
|
|
13
|
-
wheat: 0xe2b448,
|
|
14
|
-
wheatTip: 0xf0cf6a,
|
|
15
|
-
};
|
|
16
|
-
const pal = ctx => ({ ...PALETTE, ...ctx?.palette });
|
|
4
|
+
import { THREE, mergeColored } from '../../index.js';
|
|
5
|
+
import { COLORS as c } from './picture/palette.js';
|
|
6
|
+
import { mat } from './picture/materials.js';
|
|
17
7
|
|
|
18
8
|
const mesh = (geo, mat) => { const m = new THREE.Mesh(geo, mat); m.castShadow = m.receiveShadow = true; return m; };
|
|
19
9
|
const ball = (r, x, y, z, detail = 3) => new THREE.IcosahedronGeometry(r, detail).translate(x, y, z);
|
|
@@ -22,24 +12,23 @@ const ball = (r, x, y, z, detail = 3) => new THREE.IcosahedronGeometry(r, detail
|
|
|
22
12
|
const CROWN = [[1.7, 0, 3.6, 0], [1.25, 1.1, 3.1, 0.4], [1.2, -1.0, 3.2, -0.5], [1.1, 0.2, 4.6, -0.3], [1.0, -0.4, 3.0, 1.0]];
|
|
23
13
|
|
|
24
14
|
export const models = {
|
|
25
|
-
/** A round tree: short trunk, crown of five soft blobs. The crown takes the
|
|
15
|
+
/** A round tree: short trunk, crown of five soft blobs. The crown material takes the snow */
|
|
26
16
|
roundTree: function () {
|
|
27
|
-
const
|
|
28
|
-
g.add(mesh(new THREE.CylinderGeometry(0.22, 0.32, 2.6, 8).translate(0, 1.3, 0),
|
|
17
|
+
const g = new THREE.Group();
|
|
18
|
+
g.add(mesh(new THREE.CylinderGeometry(0.22, 0.32, 2.6, 8).translate(0, 1.3, 0), mat.bark));
|
|
29
19
|
// two shades in one geometry: upper blobs lighter, as if lit from above; vertex colors so it stays one draw
|
|
30
20
|
const crown = mergeColored(CROWN.map(([r, x, y, z], i) => [ball(r, x, y, z), i === 3 ? c.leafLight : c.leaf]), { flat: false }); // flat: false = smooth blobs (the default is faceted)
|
|
31
|
-
|
|
32
|
-
g.add(mesh(crown, applyEffects(makeMaterial('leaf', { vertexColors: true }), { season: 'foliage' })));
|
|
21
|
+
g.add(mesh(crown, mat.leaf));
|
|
33
22
|
return g;
|
|
34
23
|
},
|
|
35
24
|
|
|
36
25
|
/** A sheep, about 1.4 m long, facing +Z: a body of wool blobs, a black head and four black legs */
|
|
37
26
|
sheep: function () {
|
|
38
|
-
const
|
|
27
|
+
const g = new THREE.Group();
|
|
39
28
|
const wool = mergeColored([[0.5, 0, 0.75, 0], [0.42, 0, 0.8, 0.38], [0.42, 0, 0.8, -0.38], [0.36, 0.22, 0.98, 0], [0.36, -0.22, 0.98, 0.1]]
|
|
40
29
|
.map(([r, x, y, z]) => [ball(r, x, y, z, 2), c.wool]), { flat: false });
|
|
41
|
-
g.add(mesh(wool,
|
|
42
|
-
const black =
|
|
30
|
+
g.add(mesh(wool, mat.wool));
|
|
31
|
+
const black = mat.face;
|
|
43
32
|
g.add(mesh(new THREE.SphereGeometry(0.22, 16, 12).scale(0.85, 1, 1.25).translate(0, 0.9, 0.78), black)); // head
|
|
44
33
|
for (const [x, z] of [[0.2, 0.32], [-0.2, 0.32], [0.2, -0.32], [-0.2, -0.32]])
|
|
45
34
|
g.add(mesh(new THREE.CylinderGeometry(0.06, 0.06, 0.5, 6).translate(x, 0.25, z), black)); // legs
|
|
@@ -48,7 +37,7 @@ export const models = {
|
|
|
48
37
|
|
|
49
38
|
/** One wheat tuft for content vegetation (a generator returning a geometry): nine stalks with ears, vertex-colored, one draw per chunk */
|
|
50
39
|
wheatTuft: function () {
|
|
51
|
-
const
|
|
40
|
+
const parts = [];
|
|
52
41
|
for (let i = 0; i < 9; i++) {
|
|
53
42
|
const a = i * 2.4, r = i ? 0.06 + 0.02 * i : 0, x = Math.cos(a) * r, z = Math.sin(a) * r, h = 0.85 + (i % 3) * 0.1;
|
|
54
43
|
parts.push([new THREE.CylinderGeometry(0.012, 0.018, h, 3).translate(x, h / 2, z), c.wheat]);
|