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
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
// look.ground: how the terrain looks (colors, variation, shading, detail layer, material). Registered by the terrain module.
|
|
2
|
-
// set({ colors, biomeColors, steep, variation, shading, detail })
|
|
3
|
-
// colors / biomeColors / steep / variation / shading are baked into the chunks by the workers: a change rebuilds every chunk (cost 'rebuild';
|
|
4
|
-
// edits stay). colors / biomeColors / steep are given whole (they replace the style's table), variation / detail are objects (style.terrain.*).
|
|
5
|
-
// patch('detail', glsl) the detail layer's `vec4 threedogDetailSample(vec2 p)` (render/detail.js); a detail object must be set too
|
|
6
|
-
// replace(Material | (engine) => Material) the ground material (terrain({ material }) / style.terrain.material is the first one); null gives it back
|
|
7
|
-
// Why not in ChunkManager.js: that file is at its size cap, and every ground option below already reached it as config before; this only
|
|
8
|
-
// writes the same config again when a verb changes it.
|
|
9
|
-
import { defineLookPart, REPLACE } from '../../core/look/part.js';
|
|
10
|
-
import { terrainMaterial } from '../../render/materials.js';
|
|
11
|
-
|
|
12
|
-
const GEN = ['colors', 'biomeColors', 'steep', 'variation', 'shading'];
|
|
13
|
-
const isObj = v => (v && typeof v === 'object' ? null : 'must be an object');
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* @param {any} e @param {any} w the ChunkManager
|
|
17
|
-
* @param {{ cfg: () => any, setCfg: (c: any) => void, game: Record<string, any> }} h the module's current terrain config, and what terrain({...}) itself passed (written as owner 'terrain()')
|
|
18
|
-
*/
|
|
19
|
-
export function defineGroundLook(e, w, h) {
|
|
20
|
-
const st = e.style.terrain ?? {}, cfg0 = h.cfg();
|
|
21
|
-
const rebuild = 'rebuild';
|
|
22
|
-
const part = defineLookPart(e, {
|
|
23
|
-
id: 'ground', group: 'surface', module: 'terrain', object: () => w.terrainMat, applyAtStart: false, docs: ['recipes/52-look.md'],
|
|
24
|
-
params: {
|
|
25
|
-
colors: { type: 'any', default: {}, neutral: true, cost: rebuild, check: isObj, desc: 'palette name -> color; the whole table (a ground type without a color is neutral gray)' },
|
|
26
|
-
biomeColors: { type: 'any', default: {}, neutral: true, cost: rebuild, check: isObj, desc: 'ground type -> palette name(s); the whole table' },
|
|
27
|
-
steep: { type: 'array', default: [], neutral: true, cost: rebuild, desc: 'slope colors [{ maxNormalY, colors }]' },
|
|
28
|
-
variation: { type: 'any', default: null, neutral: true, cost: rebuild, check: isObj, desc: '{ blend, jitter, patches } color variation (style.terrain.variation); null = none' },
|
|
29
|
-
shading: { type: 'string', values: ['smooth', 'flat', 'texture'], default: 'smooth', cost: rebuild,
|
|
30
|
-
why: 'terrain colors are blended per grid point (smooth) so the ground has no visible facets', off: "look.ground.set({ shading: 'flat' }) for one color per triangle, or 'texture' for a per-chunk color map" },
|
|
31
|
-
detail: { type: 'any', default: null, neutral: true, cost: 'recompile', check: isObj, desc: '{ texture | noise | glsl, scale, strength ... } detail layer over the ground (style.terrain.detail); null = none' },
|
|
32
|
-
},
|
|
33
|
-
style: () => ({ colors: st.colors, biomeColors: st.biomeColors, steep: st.steep, variation: st.variation, shading: st.config?.shading, detail: st.detail, [REPLACE]: st.material }),
|
|
34
|
-
read: () => ({}),
|
|
35
|
-
hooks: { detail: { signature: 'vec4 threedogDetailSample(vec2 p) // rgb + height 0-1', scope: ['fragment'], example: "engine.look.ground.patch('detail', glsl)" } },
|
|
36
|
-
replace: { accepts: 'a Material, or (engine) => Material; null gives the style\'s back', loses: ['the style\'s terrain material (cloud shadows and season tint are added to the new one)'] },
|
|
37
|
-
applyReplace: () => material(), applyHook: () => material(),
|
|
38
|
-
apply(v, changed) {
|
|
39
|
-
if (changed.has('detail')) material();
|
|
40
|
-
if (!GEN.some(k => changed.has(k))) return;
|
|
41
|
-
const next = { ...h.cfg() };
|
|
42
|
-
for (const k of GEN) if (changed.has(k)) { if (v[k] == null) delete next[k]; else next[k] = v[k]; }
|
|
43
|
-
if (!next.shading) next.shading = cfg0.shading;
|
|
44
|
-
h.setCfg(next);
|
|
45
|
-
const species = {}; for (const sp of e.vegetation?.list() || []) species[sp.name] = sp.rule;
|
|
46
|
-
w.reinit(next, species);
|
|
47
|
-
},
|
|
48
|
-
});
|
|
49
|
-
// what terrain({ colors, shading, material ... }) itself was given sits on the game layer under the owner 'terrain()', so describe shows it
|
|
50
|
-
const given = {};
|
|
51
|
-
for (const k of GEN) if (h.game[k] !== undefined) given[k] = h.game[k];
|
|
52
|
-
if (h.game.material !== undefined) given[REPLACE] = h.game.material;
|
|
53
|
-
if (Object.keys(given).length) part.write('terrain()', given);
|
|
54
|
-
/** Rebuild the ground material from the resolved replace / detail, then every chunk picks it up */
|
|
55
|
-
function material() {
|
|
56
|
-
const impl = part.value(REPLACE) ?? null;
|
|
57
|
-
w.terrainMat = terrainMaterial(typeof impl === 'function' ? impl(e) : impl, e);
|
|
58
|
-
w.rebuild();
|
|
59
|
-
}
|
|
60
|
-
return part;
|
|
61
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
// Upload a generated terrain chunk (helper of ChunkManager.js): geometry from the worker's arrays, one mesh in a group at the chunk origin, added to the scene.
|
|
2
|
-
// `m` is the ChunkManager; c is the chunk record it keeps.
|
|
3
|
-
import * as THREE from 'three';
|
|
4
|
-
import { mountColorMap } from './terrainTexture.js';
|
|
5
|
-
|
|
6
|
-
export function mountTerrain(m, c, t) {
|
|
7
|
-
const t0 = performance.now(); // measure: the 'build' stage of engine.budget.cost
|
|
8
|
-
const g = new THREE.BufferGeometry();
|
|
9
|
-
g.setAttribute('position', new THREE.BufferAttribute(t.pos, 3));
|
|
10
|
-
g.setAttribute('normal', new THREE.BufferAttribute(t.nor, 3));
|
|
11
|
-
g.setAttribute('color', new THREE.BufferAttribute(t.col, 3));
|
|
12
|
-
g.setAttribute('uv', new THREE.BufferAttribute(t.uv, 2));
|
|
13
|
-
let mat = t.tex ? mountColorMap(m, c, t.tex, c.cx * m.T.CHUNK, c.cz * m.T.CHUNK) : m.terrainMat; // texture shading: a material with this chunk's color map
|
|
14
|
-
if (t.top != null) { // island chunk (terrain({ shape })): vertices are top, side, bottom
|
|
15
|
-
const rest = t.pos.length / 3 - t.top;
|
|
16
|
-
// the color map is sampled by world xz, so it would smear down the sides: sides and bottom keep vertex colors (or the game's material)
|
|
17
|
-
if (rest && (t.tex || m.sideMat)) { g.addGroup(0, t.top, 0); g.addGroup(t.top, rest, 1); mat = [mat, m.sideMat ?? m.terrainMat]; }
|
|
18
|
-
c.solidCount = t.solid; // collision takes top and sides, not the bottom
|
|
19
|
-
m.lowest = Math.min(m.lowest, t.minH);
|
|
20
|
-
}
|
|
21
|
-
const mesh = new THREE.Mesh(g, mat);
|
|
22
|
-
mesh.receiveShadow = true; mesh.frustumCulled = false; mesh.matrixAutoUpdate = false;
|
|
23
|
-
c.group = new THREE.Group();
|
|
24
|
-
c.group.userData.budgetTag = 'terrain';
|
|
25
|
-
c.group.position.set(c.cx * m.T.CHUNK, 0, c.cz * m.T.CHUNK);
|
|
26
|
-
c.group.add(mesh); c.terrain = mesh;
|
|
27
|
-
c.group.updateMatrixWorld(true);
|
|
28
|
-
c.sphere = new THREE.Sphere(new THREE.Vector3(t.sphere[0], t.sphere[1], t.sphere[2]), t.sphere[3]);
|
|
29
|
-
c.state = 'ready';
|
|
30
|
-
m.engine.scene.add(c.group);
|
|
31
|
-
m.engine.budget.cost.end('build', t0);
|
|
32
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
// look.wind: how plants sway. Registered by the vegetation module (it is the one that adds wind patches to its species' materials).
|
|
2
|
-
// set({ frequency, amplitude }) uniforms: live on every wind patch (trees already planted too)
|
|
3
|
-
// patch('sway', glsl) a threedogWind function (style.wind.glsl is the style layer); read when a species is ADDED, so patch before vegetation.add
|
|
4
|
-
// No replace: the sway patch already is the whole motion; weather's gusts (uWind) still scale it.
|
|
5
|
-
import { defineLookPart } from '../../core/look/part.js';
|
|
6
|
-
import { codedError } from '../../core/errorHints.js';
|
|
7
|
-
import { windCustom } from '../../render/materials.js';
|
|
8
|
-
|
|
9
|
-
const asObj = v => (typeof v === 'string' ? { glsl: v } : v);
|
|
10
|
-
/** The custom sway { glsl, uniforms } to give a new wind patch, or null for the built-in sway */
|
|
11
|
-
export function swayOf(e) { const v = e.look?.wind?.value('hook:sway'); return v ? asObj(v) : null; }
|
|
12
|
-
|
|
13
|
-
/** @param {any} e */
|
|
14
|
-
export function defineWindLook(e) {
|
|
15
|
-
if (e.look?.wind) return;
|
|
16
|
-
const u = e.uniforms, w = e.style.wind ?? {};
|
|
17
|
-
const part = defineLookPart(e, {
|
|
18
|
-
id: 'wind', group: 'motion', module: 'vegetation', object: () => u, docs: ['recipes/52-look.md'],
|
|
19
|
-
params: {
|
|
20
|
-
frequency: { type: 'number', default: 1, min: 0, neutral: true, cost: 'uniform', desc: 'sway speed multiplier (style.wind.frequency)' },
|
|
21
|
-
amplitude: { type: 'number', default: 1, min: 0, neutral: true, cost: 'uniform', desc: "multiplies every species' wind amplitude; 0 = plants stand still" },
|
|
22
|
-
},
|
|
23
|
-
style: () => ({ frequency: w.frequency, ...(w.glsl ? { 'hook:sway': { glsl: w.glsl, uniforms: w.uniforms } } : {}) }),
|
|
24
|
-
read: () => ({ frequency: u.uWindFreq.value, amplitude: u.uWindAmp.value }),
|
|
25
|
-
apply(v, changed) {
|
|
26
|
-
if (changed.has('frequency')) u.uWindFreq.value = v.frequency;
|
|
27
|
-
if (changed.has('amplitude')) u.uWindAmp.value = v.amplitude;
|
|
28
|
-
},
|
|
29
|
-
hooks: { sway: { signature: 'void threedogWind(inout vec3 transformed, vec3 ip, vec3 position)', scope: ['vertex'], example: 'engine.look.wind.patch("sway", glsl) // or { glsl, uniforms }' } },
|
|
30
|
-
noReplace: 'the sway patch already is the whole motion; patch("sway", glsl) rewrites it, set({ amplitude: 0 }) stops it',
|
|
31
|
-
});
|
|
32
|
-
const patch = part.patch.bind(part);
|
|
33
|
-
part.patch = (name, glsl, o) => { // a wrong sway function throws here, not later inside vegetation.add
|
|
34
|
-
if (glsl != null) { try { windCustom(asObj(glsl)); } catch (err) { throw codedError('look-param', `look.wind.patch('${name}'): ${err.message}`); } }
|
|
35
|
-
return patch(name, glsl, o);
|
|
36
|
-
};
|
|
37
|
-
}
|
package/modules/water/look.js
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
// look.water: the water's look as a look part (recipes/52-look.md).
|
|
2
|
-
// set({ color, opacity, waveHeight, waveScale, waveSpeed, fresnel }) live: uniforms and material fields, no recompile
|
|
3
|
-
// set({ depthColor, foam }) structural: the shared material is rebuilt once (one recompile)
|
|
4
|
-
// patch('wave' | 'surface', glsl) the GLSL hooks of style.water.glsl (recipes/44)
|
|
5
|
-
// replace((engine, { uniforms, waves, surface, normalMap }) => Material) the whole surface (style.water.material)
|
|
6
|
-
// The style layer is style.water; the options of water({...}) are the game's own layer ('game'). Why a rebuild and not a patch of the old
|
|
7
|
-
// material: depthColor / foam / hooks decide which GLSL exists, and the shader is part of the material program.
|
|
8
|
-
import { defineLookPart, REPLACE } from '../../core/look/part.js';
|
|
9
|
-
import { waterLook } from './surface.js';
|
|
10
|
-
|
|
11
|
-
const WHY = 'the water module draws a plain gray, mostly opaque sea when the style gives none';
|
|
12
|
-
const OFF = "engine.use(water({ sea: false })) for no global water, or look.water.set({ opacity: 0 }) to hide the surface";
|
|
13
|
-
const KEYS = ['color', 'opacity', 'waveHeight', 'waveScale', 'waveSpeed', 'fresnel', 'depthColor', 'foam'];
|
|
14
|
-
const UN = { waveHeight: 'uWave', waveScale: 'uWaveScale', waveSpeed: 'uWaveSpeed', fresnel: 'uFresnel' }; // the uniforms behind the live keys
|
|
15
|
-
const STRUCT = ['depthColor', 'foam'];
|
|
16
|
-
const validate = (w, k) => v => { try { waterLook({ ...w.st, [k]: v }); return null; } catch (err) { return err.message; } };
|
|
17
|
-
|
|
18
|
-
/** @param {any} w the Water module */
|
|
19
|
-
export function defineWaterLook(w) {
|
|
20
|
-
const e = w.engine, st = w.st, g = st.glsl ?? {};
|
|
21
|
-
const pick = o => Object.fromEntries(KEYS.filter(k => o[k] !== undefined).map(k => [k, o[k]]));
|
|
22
|
-
const built = { sig: '', material: undefined };
|
|
23
|
-
const sig = () => JSON.stringify([st.depthColor ?? null, st.foam ?? null, st.glsl ?? null]);
|
|
24
|
-
built.sig = sig(); built.material = st.material;
|
|
25
|
-
const live = (k, v) => {
|
|
26
|
-
const m = w.material, u = w._u;
|
|
27
|
-
if (k === 'color' && !st.material && m.color) m.color.set(v);
|
|
28
|
-
else if (k === 'opacity' && !st.material) { const t = v < 1; m.opacity = v; if (m.transparent !== t) { m.transparent = t; m.needsUpdate = true; } }
|
|
29
|
-
else if (u?.[UN[k]]) u[UN[k]].value = v;
|
|
30
|
-
};
|
|
31
|
-
const rebuild = () => {
|
|
32
|
-
const now = sig();
|
|
33
|
-
if (now === built.sig && st.material === built.material) return; // the same structure again (e.g. the game layer repeating the style): nothing to do
|
|
34
|
-
built.sig = now; built.material = st.material;
|
|
35
|
-
w._rebuild();
|
|
36
|
-
};
|
|
37
|
-
const p = defineLookPart(e, {
|
|
38
|
-
id: 'water', group: 'surface', module: 'water', object: () => ({ material: w.material, sea: w.sea }), docs: ['recipes/52-look.md'], applyAtStart: false,
|
|
39
|
-
params: {
|
|
40
|
-
color: { type: 'any', default: 0x888888, cost: 'uniform', why: WHY, off: OFF, desc: 'base color (any THREE.Color input)' },
|
|
41
|
-
opacity: { type: 'number', default: 0.85, min: 0, max: 1, cost: 'uniform', why: WHY, off: OFF },
|
|
42
|
-
waveHeight: { type: 'number', default: 1, min: 0, neutral: true, cost: 'uniform', desc: 'multiplies the wave function (0 = flat)' },
|
|
43
|
-
waveScale: { type: 'number', default: 1, min: 0, neutral: true, cost: 'uniform', desc: 'world position scale fed to the wave function' },
|
|
44
|
-
waveSpeed: { type: 'number', default: 1, min: 0, neutral: true, cost: 'uniform', desc: 'time scale fed to the wave function' },
|
|
45
|
-
fresnel: { type: 'number', default: 0.5, min: 0, max: 1, cost: 'uniform', why: 'grazing angles blend toward the fog (horizon) color', off: 'look.water.set({ fresnel: 0 })' },
|
|
46
|
-
depthColor: { type: 'any', default: null, neutral: true, cost: 'recompile', desc: '{ shallow, deep, by: "view" | "wave", curve } or null; rebuilds the water material once', check: validate(w, 'depthColor') },
|
|
47
|
-
foam: { type: 'any', default: null, neutral: true, cost: 'recompile', desc: 'true | { color, start, end, opacity } or null; rebuilds the water material once', check: validate(w, 'foam') },
|
|
48
|
-
},
|
|
49
|
-
style: () => ({ ...pick(e.style.water ?? {}), ...(g.wave ? { 'hook:wave': g.wave } : {}), ...(g.surface ? { 'hook:surface': g.surface } : {}),
|
|
50
|
-
...(e.style.water?.material ? { [REPLACE]: e.style.water.material } : {}) }),
|
|
51
|
-
read: () => ({ opacity: !st.material && w.material.opacity !== undefined ? w.material.opacity : undefined }),
|
|
52
|
-
apply(v, changed) {
|
|
53
|
-
for (const k of changed) { st[k] = v[k]; live(k, v[k]); }
|
|
54
|
-
if (STRUCT.some(k => changed.has(k))) rebuild();
|
|
55
|
-
},
|
|
56
|
-
hooks: {
|
|
57
|
-
wave: { signature: 'float threedogWaterWave(vec3 p, float t)', scope: ['uTime'], example: 'float threedogWaterWave(vec3 p, float t) { return sin(p.x + t) * 0.2; }' },
|
|
58
|
-
surface: { signature: 'vec4 threedogWaterSurface(vec4 base, float wave, float facing, vec3 worldPos, float time)', scope: ['uTime'],
|
|
59
|
-
example: 'vec4 threedogWaterSurface(vec4 base, float wave, float facing, vec3 worldPos, float time) { return vec4(base.rgb * (0.8 + wave), base.a); }' },
|
|
60
|
-
},
|
|
61
|
-
applyHook(name, glsl) {
|
|
62
|
-
const was = st.glsl;
|
|
63
|
-
st.glsl = { ...was, [name]: glsl ?? undefined };
|
|
64
|
-
try { waterLook(st); rebuild(); } catch (err) { st.glsl = was; throw err; }
|
|
65
|
-
},
|
|
66
|
-
replace: { accepts: '(engine, { uniforms, waves, surface, normalMap }) => THREE.Material', loses: ['built-in role "water" material, fresnel, color and opacity (your material owns them)', 'depthColor / foam unless your material uses surface'] },
|
|
67
|
-
// checked before any layer is written: the replace slot is a function, a GLSL hook builds (waterLook compiles it on a copy of the state)
|
|
68
|
-
validate: (k, v) => k === REPLACE ? (typeof v === 'function' ? null : 'is (engine, { uniforms, waves, surface, normalMap }) => THREE.Material')
|
|
69
|
-
: k.startsWith('hook:') ? validate(w, 'glsl')({ ...w.st.glsl, [k.slice(5)]: v }) : null,
|
|
70
|
-
applyReplace(impl) {
|
|
71
|
-
st.material = impl ?? undefined; rebuild();
|
|
72
|
-
},
|
|
73
|
-
});
|
|
74
|
-
// water({...}) options are the game's layer
|
|
75
|
-
const o = w.opts ?? {}, mine = pick(o);
|
|
76
|
-
if (Object.keys(mine).length) p.set(mine);
|
|
77
|
-
if (o.glsl) for (const k of ['wave', 'surface']) if (o.glsl[k]) p.patch(k, o.glsl[k]);
|
|
78
|
-
if (o.material) p.replace(o.material);
|
|
79
|
-
return p;
|
|
80
|
-
}
|
package/modules/weather/look.js
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
// look.weather: rain / snow particles, lightning flash and the overcast color as a look part (recipes/52-look.md).
|
|
2
|
-
// set({ 'rain.color', 'rain.speed', 'snow.size', 'lightning.brightness', overcastColor ... }) rebuilds that field's particle system once (a few ms)
|
|
3
|
-
// patch('rain.vertex' | 'rain.fragment' | 'snow.vertex' | 'snow.fragment', glsl) the WHOLE shader text, not a function (see shaders.js)
|
|
4
|
-
// replace({ rain: spec, ash: spec }) spec = the keys of style.weather.rain or { create(engine, { area, count }) => { object, update } }; null gives back
|
|
5
|
-
// The old engine.weather call with a field name was renamed in 0.2 (it throws): use replace({ [field]: spec }).
|
|
6
|
-
// Why the shader stays whole (decision #9): the rain / snow shaders move vertices and size points; a function hook would hide most of that.
|
|
7
|
-
import { defineLookPart, REPLACE } from '../../core/look/part.js';
|
|
8
|
-
import { warnOnce } from '../../core/validate.js';
|
|
9
|
-
import { RAIN, SNOW, dropSystem } from './particles.js';
|
|
10
|
-
|
|
11
|
-
const WHY = { rain: 'built-in rain: streaks drawn while a weather type has rain > 0', snow: 'built-in snow: flakes drawn while a weather type has snow > 0' };
|
|
12
|
-
const OFF = { rain: "leave 'rain' out of the weather table (no particles are built), or look.weather.set({ 'rain.opacity': 0 })", snow: "leave 'snow' out of the weather table, or look.weather.set({ 'snow.opacity': 0 })" };
|
|
13
|
-
const KEYS = { rain: ['color', 'opacity', 'length', 'speed', 'slant'], snow: ['color', 'opacity', 'size', 'speed', 'sway'] };
|
|
14
|
-
const BASE = { rain: RAIN, snow: SNOW };
|
|
15
|
-
const FIELDS = ['rain', 'snow'], STAGES = ['vertex', 'fragment'];
|
|
16
|
-
|
|
17
|
-
/** { 'rain.color': { type, default, why, off } ... } built from the particle defaults, so the numbers live in one place (particles.js) */
|
|
18
|
-
const rows = () => Object.fromEntries(FIELDS.flatMap(f => KEYS[f].map(k => [`${f}.${k}`,
|
|
19
|
-
{ type: k === 'color' ? 'any' : 'number', default: BASE[f][k], ...(k === 'color' ? {} : { min: 0 }), cost: 'gpu', why: WHY[f], off: OFF[f] }])));
|
|
20
|
-
|
|
21
|
-
/** @param {any} w the Weather module */
|
|
22
|
-
export function defineWeatherLook(w) {
|
|
23
|
-
const e = w.engine, st = e.style.weather ?? {}, { cover, ...snowStyle } = st.snow ?? {};
|
|
24
|
-
const styleSpec = f => (f === 'snow' ? snowStyle : st[f] ?? {});
|
|
25
|
-
let applied = {}; // fields a replace() holds now: field -> spec
|
|
26
|
-
const rebuild = f => {
|
|
27
|
-
if (applied[f]) return; // replace() owns this field
|
|
28
|
-
if (!w.systems.has(f)) { warnOnce(`look.weather: this game's weather table has no ${f}, so there are no ${f} particles to change; add a type with ${f}: 1 to weather({ types })`); return; }
|
|
29
|
-
const v = p.values(), s = styleSpec(f), g = { ...s.glsl };
|
|
30
|
-
for (const h of STAGES) { const x = p.value(`hook:${f}.${h}`); if (x) g[h] = x; }
|
|
31
|
-
w._build(f, { ...s, ...Object.fromEntries(KEYS[f].map(k => [k, v[`${f}.${k}`]])), ...(Object.keys(g).length ? { glsl: g } : {}) }, BASE[f]);
|
|
32
|
-
};
|
|
33
|
-
const p = defineLookPart(e, {
|
|
34
|
-
id: 'weather', group: 'dynamic', module: 'weather', object: () => w.systems, docs: ['recipes/52-look.md'], applyAtStart: false,
|
|
35
|
-
params: {
|
|
36
|
-
...rows(),
|
|
37
|
-
'lightning.brightness': { type: 'number', default: 1, min: 0, neutral: true, cost: 'uniform', desc: 'how bright the sky flashes at a strike' },
|
|
38
|
-
overcastColor: { type: 'any', default: 0x8c8c8c, cost: 'uniform', why: 'sky and fog turn this gray as a weather type raises grey', off: 'weather types with grey: 0 never use it' },
|
|
39
|
-
},
|
|
40
|
-
style: () => ({
|
|
41
|
-
...Object.fromEntries(FIELDS.flatMap(f => KEYS[f].filter(k => styleSpec(f)[k] !== undefined).map(k => [`${f}.${k}`, styleSpec(f)[k]]))),
|
|
42
|
-
...Object.fromEntries(FIELDS.flatMap(f => STAGES.filter(h => styleSpec(f).glsl?.[h]).map(h => [`hook:${f}.${h}`, styleSpec(f).glsl[h]]))),
|
|
43
|
-
'lightning.brightness': st.lightningBrightness, overcastColor: st.overcastColor,
|
|
44
|
-
}),
|
|
45
|
-
read: () => ({}),
|
|
46
|
-
apply(v, changed) {
|
|
47
|
-
if (changed.has('lightning.brightness')) w.flashStrength = v['lightning.brightness'];
|
|
48
|
-
if (changed.has('overcastColor')) w.grey.set(v.overcastColor);
|
|
49
|
-
for (const f of FIELDS) if ([...changed].some(k => k.startsWith(f + '.'))) rebuild(f);
|
|
50
|
-
},
|
|
51
|
-
hooks: Object.fromEntries(FIELDS.flatMap(f => STAGES.map(h => [`${f}.${h}`, { signature: 'whole GLSL shader text (copy it from modules/weather/shaders.js)', scope: ['uCam', 'uSize', 'uFallOff', 'uOpacity', 'uColor'] }]))),
|
|
52
|
-
applyHook(name) { rebuild(name.split('.')[0]); },
|
|
53
|
-
replace: { accepts: '{ <field>: spec } with spec = the keys of style.weather.rain, or { create(engine, { area, count }) => { object, update?(amount, ctx) } }; null gives the fields back',
|
|
54
|
-
loses: ['the style rain / snow look of every field named in the object (look.weather.set values for it are ignored while it holds)'] },
|
|
55
|
-
// a wrong replace value stops here, before any layer is written (the throw used to come from applyReplace, after the write)
|
|
56
|
-
validate: (k, v) => {
|
|
57
|
-
if (k !== REPLACE) return null;
|
|
58
|
-
if (v != null && (typeof v !== 'object' || Array.isArray(v))) return "is { <field>: spec }, e.g. replace({ ash: { shape: 'soft', color: 0x555555 } }); see recipes/44-water-weather-look-hooks.md";
|
|
59
|
-
const fields = [...new Set(Object.values(w.types).flatMap(t => Object.keys(t)))], bad = Object.keys(v ?? {}).find(f => !fields.includes(f));
|
|
60
|
-
return bad ? `no weather type has a field '${bad}'; add it to a type in weather({ types }) (e.g. ashfall: { ${bad}: 1 }), or use one of ${fields.join(', ')}` : null;
|
|
61
|
-
},
|
|
62
|
-
applyReplace(impl) {
|
|
63
|
-
const next = impl ?? {}, old = applied;
|
|
64
|
-
applied = next;
|
|
65
|
-
for (const f of new Set([...Object.keys(old), ...Object.keys(next)])) {
|
|
66
|
-
if (next[f] && next[f] === old[f]) continue; // unchanged: keep the system (and any handle the game holds)
|
|
67
|
-
if (next[f]) w._build(f, next[f], BASE[f]);
|
|
68
|
-
else if (BASE[f]) rebuild(f);
|
|
69
|
-
else { const s = w.systems.get(f); if (s) { dropSystem(e, s); w.systems.delete(f); } }
|
|
70
|
-
}
|
|
71
|
-
},
|
|
72
|
-
});
|
|
73
|
-
return p;
|
|
74
|
-
}
|
|
75
|
-
|
package/modules/world/cells.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
// Spatial index for world: the xz plane is cut into fixed-size cells (default 32 m) and each record is filed under its cell. Distance queries and focus-based model building both pre-filter by cell.
|
|
2
|
-
// Cell keys are numbers and cells hold record objects directly: there are hundreds to thousands of moves and neighbor queries per step, and string keys plus id lookups would only add garbage and cost.
|
|
3
|
-
|
|
4
|
-
const OFF = 2 ** 20, SPAN = 2 ** 21; // ±1 million cells in each direction (±30,000 km at 32 m per cell); keys stay safe integers
|
|
5
|
-
|
|
6
|
-
/** @internal */
|
|
7
|
-
export class Cells {
|
|
8
|
-
/** @param {number} size cell edge length (meters) */
|
|
9
|
-
constructor(size) {
|
|
10
|
-
this.size = size;
|
|
11
|
-
this.map = new Map(); // cell key → Set<record> (deleted when empty, so walked-through areas leave no empty cells)
|
|
12
|
-
this.of = new Map(); // id → cell key
|
|
13
|
-
}
|
|
14
|
-
key(x, z) { return (Math.floor(x / this.size) + OFF) * SPAN + Math.floor(z / this.size) + OFF; }
|
|
15
|
-
/** Put into / move to the cell containing the position; returns true if the cell changed */
|
|
16
|
-
put(rec) {
|
|
17
|
-
const k = this.key(rec.position.x, rec.position.z), old = this.of.get(rec.id);
|
|
18
|
-
if (old === k) return false;
|
|
19
|
-
if (old !== undefined) this.out(old, rec);
|
|
20
|
-
let set = this.map.get(k); if (!set) this.map.set(k, set = new Set());
|
|
21
|
-
set.add(rec); this.of.set(rec.id, k);
|
|
22
|
-
return true;
|
|
23
|
-
}
|
|
24
|
-
delete(rec) { const k = this.of.get(rec.id); if (k !== undefined) this.out(k, rec); this.of.delete(rec.id); }
|
|
25
|
-
out(k, rec) { const set = this.map.get(k); set.delete(rec); if (!set.size) this.map.delete(k); }
|
|
26
|
-
clear() { this.map.clear(); this.of.clear(); }
|
|
27
|
-
/** Call fn(rec, squared distance) for each record within radius of c. No allocation, no sorting.
|
|
28
|
-
* When the circle covers more cells than exist (huge radius, even Infinity) scan all cells instead, so it cannot hang */
|
|
29
|
-
forEach(c, radius, fn) {
|
|
30
|
-
const s = this.size, r2 = radius * radius, cx = c.x, cz = c.z;
|
|
31
|
-
const x0 = Math.floor((cx - radius) / s), x1 = Math.floor((cx + radius) / s), z0 = Math.floor((cz - radius) / s), z1 = Math.floor((cz + radius) / s);
|
|
32
|
-
if ((x1 - x0 + 1) * (z1 - z0 + 1) > this.map.size) { for (const set of this.map.values()) visit(set, cx, cz, r2, fn); return; }
|
|
33
|
-
for (let x = x0; x <= x1; x++) for (let z = z0; z <= z1; z++) {
|
|
34
|
-
const set = this.map.get((x + OFF) * SPAN + z + OFF);
|
|
35
|
-
if (set) visit(set, cx, cz, r2, fn);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function visit(set, cx, cz, r2, fn) {
|
|
41
|
-
for (const rec of set) { const dx = rec.position.x - cx, dz = rec.position.z - cz, d2 = dx * dx + dz * dz; if (d2 <= r2) fn(rec, d2); }
|
|
42
|
-
}
|
package/render/lookSurface.js
DELETED
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
// look.materials and look.surface (render/materials.js reads them when it makes a material).
|
|
2
|
-
// Why a file of its own: materials.js is near the size cap, and the two parts share one rule: a verb changes what makeMaterial does NEXT time
|
|
3
|
-
// (a Material already handed out is not touched, catalog / describe say appliesTo; rebuilding made materials from the spec costs a recompile each, so it is not done).
|
|
4
|
-
// Exception: plain numeric / color properties (LIVE_KEYS below) are written to the already-made materials of that role at once; they need no recompile.
|
|
5
|
-
// look.materials set({ wool: { roughness: 0.4 } }) merge into the role's spec (style.materials[role] stays below as the style layer)
|
|
6
|
-
// patch(name, shaderPatch, { roles }) add a named ShaderPatch (render/patches.js) to materials made for those roles
|
|
7
|
-
// replace(role, Material | fn) a role is this Material (cloned) / this (params, purpose, engine) => Material
|
|
8
|
-
// look.surface set({ lighting: { wrap, shadowTint, rim }, detail: {...}, ramp: [...], soften }) defaults for every spec-made material
|
|
9
|
-
// patch('lighting' | 'detail', glsl) the shared threedogLighting / threedogDetailSample function
|
|
10
|
-
import { defineLookPart } from '../core/look/part.js';
|
|
11
|
-
import * as THREE from 'three';
|
|
12
|
-
import { codedError } from '../core/errorHints.js';
|
|
13
|
-
import { isPlainObject as isPlain } from '../core/util.js';
|
|
14
|
-
import { rampTexture } from './lighting.js';
|
|
15
|
-
|
|
16
|
-
const asGlsl = v => (typeof v === 'string' ? { glsl: v } : v); // a hook value is a GLSL string or { glsl, uniforms }
|
|
17
|
-
|
|
18
|
-
/** A material spec key makeMaterial understands: its own keys (materials.js SPEC_KEYS + type) or a property of one of the three.js types it makes */
|
|
19
|
-
const probes = []; // one probe Material per three.js type, made on first use; page-wide on purpose (they are never rendered)
|
|
20
|
-
function knownSpecKey(k) {
|
|
21
|
-
if (['type', 'steps', 'ramp', 'soften', 'repeat', 'wrap', 'detail', 'lighting'].includes(k)) return true;
|
|
22
|
-
if (!probes.length) probes.push(...[THREE.MeshPhysicalMaterial, THREE.MeshLambertMaterial, THREE.MeshPhongMaterial, THREE.MeshToonMaterial, THREE.MeshBasicMaterial].map(C => new C()));
|
|
23
|
-
return probes.some(m => k in m);
|
|
24
|
-
}
|
|
25
|
-
/** Plain material properties that change at once on materials already made for the role (no shader change, so no recompile); every other key is for new materials only */
|
|
26
|
-
export const LIVE_KEYS = ['color', 'emissive', 'emissiveIntensity', 'roughness', 'metalness', 'opacity', 'envMapIntensity', 'shininess', 'specular'];
|
|
27
|
-
const COLOR_KEYS = new Set(['color', 'emissive', 'specular']);
|
|
28
|
-
/** Every Material made per role, per engine, as weak refs (a disposed material that nobody holds drops out) */
|
|
29
|
-
const LIVE = new WeakMap();
|
|
30
|
-
const liveOf = e => LIVE.get(e) ?? LIVE.set(e, new Map()).get(e);
|
|
31
|
-
/** The last Material made per role, per engine (look.materials.object(role)); kept here so materials.js never touches the part's fields */
|
|
32
|
-
const MADE = new WeakMap();
|
|
33
|
-
const madeOf = e => MADE.get(e) ?? MADE.set(e, new Map()).get(e);
|
|
34
|
-
|
|
35
|
-
/** Materials: role names are open, so the part grows `<role>.<specKey>` params as the style or a game mentions them */
|
|
36
|
-
export function defineMaterialsLook(e, purposes) {
|
|
37
|
-
const M = e.style.materials ?? {};
|
|
38
|
-
const params = {}, style = {};
|
|
39
|
-
const grow = (into, key) => { into[key] = { type: 'any', default: null, neutral: true, desc: 'a spec key of this role (type, color, roughness, steps, ramp, detail, lighting ...); null = not overridden' }; };
|
|
40
|
-
for (const [role, spec] of Object.entries(M)) if (isPlain(spec)) for (const [k, v] of Object.entries(spec)) { grow(params, `${role}.${k}`); style[`${role}.${k}`] = v; }
|
|
41
|
-
const made = madeOf(e);
|
|
42
|
-
const part = defineLookPart(e, {
|
|
43
|
-
id: 'materials', group: 'surface', module: 'core', docs: ['recipes/52-look.md'], params, style: () => style, appliesTo: `materials made after the change, except the live keys (${LIVE_KEYS.join(', ')}), which also change the materials already made for that role; type, steps, ramp, soften, repeat, wrap, detail, lighting, patch and replace are for new materials only`,
|
|
44
|
-
applyAtStart: false,
|
|
45
|
-
apply(v, changed) { // live keys: write them to the already-made materials of the role (a cleared key goes back to the style value, or stays when the style gave none)
|
|
46
|
-
for (const k of changed) {
|
|
47
|
-
const i = k.indexOf('.'), role = k.slice(0, i), prop = k.slice(i + 1);
|
|
48
|
-
if (i < 0 || !LIVE_KEYS.includes(prop)) continue;
|
|
49
|
-
const val = v[k] ?? style[k];
|
|
50
|
-
if (val == null) continue;
|
|
51
|
-
for (const ref of liveOf(e).get(role) ?? []) {
|
|
52
|
-
const m = ref.deref();
|
|
53
|
-
if (!m) { liveOf(e).get(role).delete(ref); continue; }
|
|
54
|
-
if (!(prop in m)) continue;
|
|
55
|
-
if (COLOR_KEYS.has(prop)) m[prop].set(val); else m[prop] = val;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
},
|
|
59
|
-
// a function, not a map: look.materials.object('wool') is the last Material made for that role, object() all of them
|
|
60
|
-
object: () => role => (role === undefined ? Object.fromEntries(made) : made.get(role)),
|
|
61
|
-
// set({ wool: { roughnes: 1 } }) used to add the typo as a new key; now a role key must be one makeMaterial reads (review M7).
|
|
62
|
-
// normalize runs for set() and engine.debug.override alike, before the values are checked
|
|
63
|
-
normalize(p) {
|
|
64
|
-
const grown = {};
|
|
65
|
-
for (const [role, spec] of Object.entries(p)) if (isPlain(spec)) for (const k of Object.keys(spec)) if (!part.has(`${role}.${k}`)) {
|
|
66
|
-
if (!knownSpecKey(k)) throw codedError('look-param', `look.materials.set(): ${role}.${k} is not a material spec key (type, color, roughness, steps, ramp, detail, lighting or a three.js material property)`);
|
|
67
|
-
grow(grown, `${role}.${k}`);
|
|
68
|
-
}
|
|
69
|
-
if (Object.keys(grown).length) part.extend(grown);
|
|
70
|
-
return p;
|
|
71
|
-
},
|
|
72
|
-
hooks: { '<name>': { signature: 'a ShaderPatch { name, glsl, uniforms, needs } (render/patches.js); patch(name, spec, { roles: ["wool"] }) adds it to materials made for those roles (none = all)', scope: ['fragment', 'vertex'] } },
|
|
73
|
-
replace: { accepts: "replace('wool', Material | (params, purpose, engine) => Material); replace('wool', null) gives the role back to the style", loses: ['the role spec: type, steps, ramp, detail, lighting ... and look.materials.set keys for that role'] },
|
|
74
|
-
verbs: {
|
|
75
|
-
patch: { signature: 'patch(name, shaderPatch | null, { roles, owner })',
|
|
76
|
-
take(bad, name, spec, { roles, owner } = {}) {
|
|
77
|
-
if (typeof name !== 'string' || !name) bad("name is the patch's name, e.g. patch('snap', { glsl: {...} }, { roles: ['wool'] })");
|
|
78
|
-
if (spec != null && !isPlain(spec)) bad(`the patch is a ShaderPatch object { glsl: { vertex|fragment: {...} }, uniforms, needs } (render/patches.js); got ${typeof spec}`);
|
|
79
|
-
return [{ [`hook:${name}`]: spec == null ? null : { patch: { name, ...spec }, roles: roles ?? null } }, owner];
|
|
80
|
-
} },
|
|
81
|
-
replace: { signature: 'replace(role, Material | (params, purpose, engine) => Material | null, { owner })',
|
|
82
|
-
take(bad, role, impl, { owner } = {}) {
|
|
83
|
-
if (typeof role !== 'string') bad("the first argument is the role name, e.g. replace('wool', new THREE.MeshMatcapMaterial(...))");
|
|
84
|
-
if (impl != null && !impl.isMaterial && typeof impl !== 'function') bad(`give a three.js Material or a function (params, purpose, engine) => Material; got ${typeof impl}`);
|
|
85
|
-
return [{ [`replace:${role}`]: impl ?? null }, owner];
|
|
86
|
-
} },
|
|
87
|
-
},
|
|
88
|
-
});
|
|
89
|
-
return part;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/** What the games and debug layers changed for a role: { key: value } to lay over the role's spec (makeMaterial) */
|
|
93
|
-
export function materialOverrides(eng, role) {
|
|
94
|
-
const p = eng?.look?.materials, out = {};
|
|
95
|
-
if (!p) return out;
|
|
96
|
-
for (const [k] of p.resolved(role + '.')) { const v = p.top(k); if (v != null) out[k.slice(role.length + 1)] = v; }
|
|
97
|
-
return out;
|
|
98
|
-
}
|
|
99
|
-
/** replace(role, ...) from a game / debug layer, else undefined */
|
|
100
|
-
export const materialReplace = (eng, role) => eng?.look?.materials?.top(`replace:${role}`) ?? undefined;
|
|
101
|
-
/** Patches added with look.materials.patch for this role */
|
|
102
|
-
export function materialPatches(eng, role) {
|
|
103
|
-
const p = eng?.look?.materials, out = [];
|
|
104
|
-
if (p) for (const [, v] of p.resolved('hook:')) if (v && (!v.roles || v.roles.includes(role))) out.push(v.patch);
|
|
105
|
-
return out;
|
|
106
|
-
}
|
|
107
|
-
/** Remember the last Material made for a role (look.materials.object(role)) */
|
|
108
|
-
export function materialMade(eng, role, m) {
|
|
109
|
-
if (!eng) return;
|
|
110
|
-
madeOf(eng).set(role, m);
|
|
111
|
-
(liveOf(eng).get(role) ?? liveOf(eng).set(role, new Set()).get(role)).add(new WeakRef(m));
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
const needColor = name => v => (isPlain(v) && v.color !== undefined ? null : `needs a color, e.g. { color: '#334', strength: 0.5 } (${name})`);
|
|
115
|
-
/** Surface: the pack-wide lighting / detail / toon ramp every spec-made material starts from */
|
|
116
|
-
export function defineSurfaceLook(e) {
|
|
117
|
-
const L = e.style.lighting ?? {};
|
|
118
|
-
const keep = o => Object.fromEntries(Object.entries(o).filter(([, v]) => v != null));
|
|
119
|
-
const num = v => (typeof v === 'number' ? null : 'must be a number');
|
|
120
|
-
defineLookPart(e, {
|
|
121
|
-
id: 'surface', appliesTo: 'materials made after the change', group: 'surface', module: 'core', docs: ['recipes/52-look.md'],
|
|
122
|
-
params: {
|
|
123
|
-
'lighting.wrap': { type: 'any', default: null, neutral: true, check: num, desc: 'half-lambert wrap 0-1: how far light bends past the terminator (softer shade edge); null = off' },
|
|
124
|
-
'lighting.shadowTint': { type: 'any', default: null, neutral: true, check: needColor('shadowTint'), desc: '{ color, strength?, soft? } hue of the shaded side; null = off' },
|
|
125
|
-
'lighting.rim': { type: 'any', default: null, neutral: true, check: needColor('rim'), desc: '{ color, strength?, power?, shadowSide? } edge light; null = off' },
|
|
126
|
-
detail: { type: 'any', default: null, neutral: true, check: v => (isPlain(v) ? null : 'must be a detail object, e.g. { noise: "grain", strength: 0.2 } (render/detail.js)'), desc: 'detail layer added to every spec-made material (a spec\'s own detail wins; detail: false in a spec opts out); null = none' },
|
|
127
|
-
ramp: { type: 'any', default: null, neutral: true, check: v => { try { rampTexture(v); return null; } catch (err) { return err.message; } }, desc: 'toon ramp for every toon material, grays or colors dark to light; null = each spec\'s own steps / ramp' },
|
|
128
|
-
soften: { type: 'any', default: null, neutral: true, check: num, desc: 'how much the toon bands melt into each other 0-1; used with ramp' },
|
|
129
|
-
},
|
|
130
|
-
style: () => keep({ 'lighting.wrap': L.wrap, 'lighting.shadowTint': L.shadowTint, 'lighting.rim': L.rim, 'hook:lighting': L.glsl ? { glsl: L.glsl, uniforms: L.uniforms } : null }),
|
|
131
|
-
hooks: {
|
|
132
|
-
lighting: { signature: 'void threedogLighting(inout ReflectedLight light, vec3 normal, vec3 viewDir, vec3 sunDir, float sunShadow, vec3 albedo)', scope: ['fragment'], example: 'engine.look.surface.patch("lighting", glslString)' },
|
|
133
|
-
detail: { signature: 'vec4 threedogDetailSample(vec2 p) // rgb + height 0-1', scope: ['fragment'], example: 'engine.look.surface.patch("detail", glslString)' },
|
|
134
|
-
},
|
|
135
|
-
noReplace: 'to swap a whole material, use engine.look.materials.replace(role, ...)',
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/** The pack-wide lighting options for makeMaterial: style.lighting under any look.surface change (undefined without the part) */
|
|
140
|
-
export function surfaceLighting(eng) {
|
|
141
|
-
const p = eng?.look?.surface;
|
|
142
|
-
if (!p) return eng?.style?.lighting;
|
|
143
|
-
const o = keep3({ wrap: p.value('lighting.wrap'), shadowTint: p.value('lighting.shadowTint'), rim: p.value('lighting.rim'), ...asGlsl(p.value('hook:lighting')) });
|
|
144
|
-
return Object.keys(o).length ? o : undefined;
|
|
145
|
-
}
|
|
146
|
-
/** The pack-wide detail options (with the detail hook's glsl), or undefined */
|
|
147
|
-
export function surfaceDetail(eng) {
|
|
148
|
-
const p = eng?.look?.surface, d = p?.value('detail');
|
|
149
|
-
return d ? { ...asGlsl(p.value('hook:detail')), ...d } : undefined;
|
|
150
|
-
}
|
|
151
|
-
/** The pack-wide toon ramp { ramp, soften }, or undefined */
|
|
152
|
-
export function surfaceRamp(eng) {
|
|
153
|
-
const p = eng?.look?.surface, r = p?.value('ramp');
|
|
154
|
-
return r ? { ramp: r, soften: p.value('soften') ?? 0 } : undefined;
|
|
155
|
-
}
|
|
156
|
-
function keep3(o) { return Object.fromEntries(Object.entries(o).filter(([, v]) => v != null)); }
|
|
157
|
-
/** The ground's detail options: look.ground (style.terrain.detail under any change, plus its detail glsl hook), or style.terrain.detail without the part */
|
|
158
|
-
export function groundDetail(eng) {
|
|
159
|
-
const p = eng?.look?.ground, d = p ? p.value('detail') : eng?.style?.terrain?.detail;
|
|
160
|
-
return d ? { ...asGlsl(p?.value('hook:detail')), ...d } : undefined;
|
|
161
|
-
}
|
package/render/postLook.js
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
// look.post: the post-processing chain as a look part (recipes/52-look.md).
|
|
2
|
-
// set({ bloom: { strength: 0.6 }, vignette: false }) keys are '<effect>.<param>' and '<effect>.enabled'; false / true is the same as enabled
|
|
3
|
-
// patch('grain', glsl | { glsl, slot, order, uniforms, values }) generates a fuse effect named 'grain' (PostFuse in PostFX.js); patch('grain', null) removes it
|
|
4
|
-
// add(effect, { owner }) adds ONE custom pass (name, create | fuse, slot, order, params) without replacing the chain; returns { remove() }
|
|
5
|
-
// replace([effect, ...]) swaps the whole chain for these effects; replace(null) gives the style's chain back
|
|
6
|
-
// The old engine.post.add / enable and handle set / enable / remove were removed in 0.2 (they throw renamed-api): this part is the one way to change the chain, so describe().look
|
|
7
|
-
// and describe().render say who changed what. Style-pack effects (bloom, ao, outline ...) are the style layer; the keys come and go with the
|
|
8
|
-
// effects, so the part adds and removes its params as the chain changes (core/look/dynamic.js).
|
|
9
|
-
// Why '<effect>.<param>' keys and not one object per effect: layering and owners are per key, so a game can change bloom.strength and leave
|
|
10
|
-
// the style's bloom.threshold alone.
|
|
11
|
-
import { defineLookPart } from '../core/look/part.js';
|
|
12
|
-
import { codedError } from '../core/errorHints.js';
|
|
13
|
-
|
|
14
|
-
/** @param {any} post PostFX @param {any[]} styleDefs the style pack's effects */
|
|
15
|
-
export function definePostLook(post, styleDefs) {
|
|
16
|
-
const e = post.engine, low = e.tier === 'low', generated = new Map(), source = new Map();
|
|
17
|
-
const defaultOn = d => (d.enabled ?? true) && !(d.costly && low); // a costly effect starts off on low-tier devices unless the game said otherwise
|
|
18
|
-
const decl = h => {
|
|
19
|
-
const d = h._def, n = h.name;
|
|
20
|
-
return { [`${n}.enabled`]: { type: 'bool', default: !!defaultOn(d), cost: d.costly ? 'gpu' : 'uniform',
|
|
21
|
-
why: low && d.costly ? (post._offWhy[n] ?? `costly effect: off on low-tier devices`) : `post effect '${n}'${styleDefs.includes(d) ? ' of the style pack' : ''}`,
|
|
22
|
-
off: `look.post.set({ ${n}: ${defaultOn(d) ? 'false' : 'true'} })` },
|
|
23
|
-
...Object.fromEntries(Object.entries(d.params ?? {}).map(([k, v]) => [`${n}.${k}`, { type: 'any', default: v, neutral: true, cost: d.fuse ? 'uniform' : 'recompile' }])) };
|
|
24
|
-
};
|
|
25
|
-
const styleValues = () => Object.fromEntries(post._list.filter(h => styleDefs.includes(h._def)).flatMap(h => Object.entries(h.params).map(([k, v]) => [`${h.name}.${k}`, v])));
|
|
26
|
-
/** The game layer records what differs from the default (createEngine({ post }), or an effect the game added) */
|
|
27
|
-
const record = h => { if (!styleDefs.includes(h._def) || h.enabled !== !!defaultOn(h._def)) part.write('game', { [`${h.name}.enabled`]: h.enabled }); };
|
|
28
|
-
const split = k => { const i = k.indexOf('.'); return [k.slice(0, i), k.slice(i + 1)]; };
|
|
29
|
-
const part = defineLookPart(e, {
|
|
30
|
-
id: 'post', group: 'screen', module: 'core', object: () => post.composer, docs: ['recipes/52-look.md'], applyAtStart: false,
|
|
31
|
-
params: Object.assign({}, ...post._list.map(decl)), style: styleValues,
|
|
32
|
-
read: () => ({}),
|
|
33
|
-
normalize(p) { // post.set({ vignette: false }) -> { 'vignette.enabled': false }
|
|
34
|
-
return Object.fromEntries(Object.entries(p).map(([k, v]) => (typeof v === 'boolean' && part.has(`${k}.enabled`) ? [`${k}.enabled`, v] : [k, v])));
|
|
35
|
-
},
|
|
36
|
-
apply(v, changed) {
|
|
37
|
-
const sets = new Map();
|
|
38
|
-
for (const k of changed) {
|
|
39
|
-
const [n, p] = split(k), h = post.get(n);
|
|
40
|
-
if (!h) continue;
|
|
41
|
-
if (p === 'enabled') { if (h.enabled !== !!v[k]) h._enable(!!v[k]); } else if (h.params[p] !== v[k]) (sets.get(h) ?? sets.set(h, {}).get(h))[p] = v[k];
|
|
42
|
-
}
|
|
43
|
-
for (const [h, p] of sets) h._set(p);
|
|
44
|
-
},
|
|
45
|
-
hooks: { '*': { signature: 'GLSL statements that edit `vec4 color` (see PostFuse in render/PostFX.js); spec { glsl, slot: "ldr", order, uniforms, values }', scope: ['vUv', 'tDiffuse', 'uTime', 'uResolution', 'fxHash(vec2)'] } },
|
|
46
|
-
extraSignatures: { add: 'add(effect, { owner })' },
|
|
47
|
-
applyHook(name, impl) {
|
|
48
|
-
if (impl != null && generated.has(name) && source.get(name) === impl) return; // the same spec again (a rolled-back write re-applies every hook): keep the built effect
|
|
49
|
-
generated.get(name)?._remove();
|
|
50
|
-
source.delete(name);
|
|
51
|
-
if (generated.delete(name)) part.retract(name + '.');
|
|
52
|
-
if (impl == null) return;
|
|
53
|
-
if (post.get(name)) throw new Error(`look.post.patch/add('${name}'): an effect named '${name}' already exists; pick another name, or change it with look.post.set({ '${name}.<param>': value })`);
|
|
54
|
-
const s = typeof impl === 'string' ? { glsl: impl } : impl, { slot, order, params, ...fuse } = s;
|
|
55
|
-
// add(effect) passes a whole effect (create | fuse): it keeps its own slot / order / enabled; patch(name, spec) is a fuse snippet in 'ldr'
|
|
56
|
-
const h = s.create || s.fuse ? post._add({ ...s, name }) : post._add({ name, fuse, slot: slot ?? 'ldr', order, params });
|
|
57
|
-
generated.set(name, h); source.set(name, impl); part.extend(decl(h));
|
|
58
|
-
},
|
|
59
|
-
replace: { accepts: 'an array of post effects ({ name, create | fuse, slot, order, params }); null gives the style\'s chain back',
|
|
60
|
-
loses: ['every effect the style, patch() or a replaced chain brought (their look.post values go with them)'] },
|
|
61
|
-
// checked before the record is written, so a wrong replace never reaches applyReplace (review H1)
|
|
62
|
-
validate: (k, v) => (k === '@replace' && !Array.isArray(v) ? 'is an array of effects like [bloom({ strength: 0.4 }), myGrain]; null gives the style chain back' : null),
|
|
63
|
-
applyReplace(impl) {
|
|
64
|
-
if (impl != null && !Array.isArray(impl)) throw new Error('look.post.replace(effects): effects is an array like [bloom({ strength: 0.4 }), myGrain]; null gives the style chain back');
|
|
65
|
-
post._building = true;
|
|
66
|
-
try {
|
|
67
|
-
for (const h of [...post._list]) { h._remove(); part.retract(h.name + '.'); }
|
|
68
|
-
generated.clear(); source.clear();
|
|
69
|
-
for (const d of impl ?? styleDefs) { const lowOff = impl == null && d.costly && low; const h = post._add(d, { enabled: lowOff ? false : undefined }); part.extend(decl(h)); }
|
|
70
|
-
part.restyle(impl ? {} : styleValues());
|
|
71
|
-
} finally { post._building = false; post._sync(); }
|
|
72
|
-
},
|
|
73
|
-
});
|
|
74
|
-
/** Add one custom pass; it is a patch under the effect's name, so owner layers, describe, remove and rollback work like every look verb */
|
|
75
|
-
part.add = (effect, o) => {
|
|
76
|
-
if (!effect || typeof effect.name !== 'string' || (typeof effect.create !== 'function' && !effect.fuse))
|
|
77
|
-
throw codedError('look-verb', "look.post.add(effect): needs { name: 'myEffect', create: (ctx) => pass } (or a fuse snippet { name, fuse: { glsl } }, see PostEffect)");
|
|
78
|
-
// checked here, before any write: the hook key is the effect name, so a second write under it would replace (and tear down) the first effect
|
|
79
|
-
if (post.get(effect.name)) throw codedError('look-verb', `look.post.add: post effect '${effect.name}' is already added; change it with look.post.set({ '${effect.name}.<param>': value }), or drop it with its handle.remove() / look.post.replace([...])`);
|
|
80
|
-
part.patch(effect.name, effect, o);
|
|
81
|
-
// patch's handle would drop the owner's WHOLE post layer (every other effect this owner added); remove only this effect's hook
|
|
82
|
-
return { remove: () => { part.patch(effect.name, null, o); } };
|
|
83
|
-
};
|
|
84
|
-
for (const h of post._list) record(h);
|
|
85
|
-
return { part };
|
|
86
|
-
}
|