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,15 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
// Materials by name. Windows and lamp heads glow by the same level as the lamps: a lit window and a lit street must agree.
|
|
3
|
+
import { THREE } from 'threedog';
|
|
4
|
+
import { COLORS, LAMPS } from './palette.js';
|
|
5
|
+
|
|
6
|
+
export function createMaterials() {
|
|
7
|
+
const flat = (/** @type {number} */ color) => new THREE.MeshStandardMaterial({ color, roughness: 0.9 });
|
|
8
|
+
const glass = new THREE.MeshStandardMaterial({ color: COLORS.dark, emissive: COLORS.window, emissiveIntensity: 0, roughness: 0.9 });
|
|
9
|
+
const head = new THREE.MeshStandardMaterial({ color: COLORS.dark, emissive: COLORS.lampHead, emissiveIntensity: 0, roughness: 0.9 });
|
|
10
|
+
return {
|
|
11
|
+
mat: { ground: flat(COLORS.ground), wall: flat(COLORS.wall), roof: flat(COLORS.roof), figure: flat(COLORS.figure), crate: flat(COLORS.crate), glass, head },
|
|
12
|
+
/** @param {number} level the lamps' level, 0 off .. 1 on */
|
|
13
|
+
update(level) { glass.emissiveIntensity = LAMPS.window * level; head.emissiveIntensity = LAMPS.head * level; },
|
|
14
|
+
};
|
|
15
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
// Day-night palette: one set of keyframes over the day for sky, light, exposure, grade and lamps. Numbers are a neutral starting point on a gray
|
|
3
|
+
// scene; the colors of your game come from its own picture, not from here.
|
|
4
|
+
import { THREE } from 'threedog';
|
|
5
|
+
|
|
6
|
+
/** Materials and lamp colors of the demo street, by name */
|
|
7
|
+
export const COLORS = { ground: 0x8e8e8e, wall: 0xb2b2b2, roof: 0x7a7a7a, figure: 0xa0a0a0, crate: 0x9c9c9c, dark: 0x202020, window: 0xffc27a, lampHead: 0xffd29a, lamp: 0xffc88a };
|
|
8
|
+
/** Sky keyframes: [time 0-1, zenith, horizon (= fog color), sun color (the moon at night), sun intensity, ambient color, ambient intensity] */
|
|
9
|
+
export const SKY = [
|
|
10
|
+
[0.00, 0x0d1626, 0x1f2c44, 0x8fa4d4, 0.35, 0x2f3147, 0.26], // night: the "sun" row is moonlight, blue and weak; ambient keeps a floor
|
|
11
|
+
[0.21, 0x172036, 0x3a4058, 0x9aa8d4, 0.35, 0x2f3147, 0.26],
|
|
12
|
+
[0.26, 0x55688c, 0xd09c7c, 0xffb27c, 1.2, 0x8088a8, 0.6], // sunrise: warm sun, horizon warm, zenith still cool (the contrast IS the picture)
|
|
13
|
+
[0.33, 0x6d92c2, 0xc6d2dc, 0xfff0dc, 2.4, 0xa0b6d4, 0.9],
|
|
14
|
+
[0.50, 0x6e98ce, 0xcfdae4, 0xfffaf2, 3.0, 0xa8bdd9, 1.1], // noon: sun 3 + ambient 1.1 ~ pi: mid-tone albedos show at their own value
|
|
15
|
+
[0.68, 0x6a8ebe, 0xd4d0c6, 0xfff0d8, 2.6, 0xa4b8d4, 1.0],
|
|
16
|
+
[0.73, 0x4c5c86, 0xdc9c6c, 0xffa264, 1.6, 0x7c88ac, 0.7], // dusk: warmth in the LIGHT color, ambient drops so shadows turn cool by contrast
|
|
17
|
+
[0.78, 0x222e4c, 0x5c5068, 0x9aa6d4, 0.35, 0x3c4060, 0.32], // blue hour: the moon row again, a little more ambient than deep night
|
|
18
|
+
[1.00, 0x0d1626, 0x1f2c44, 0x8fa4d4, 0.35, 0x2f3147, 0.26],
|
|
19
|
+
];
|
|
20
|
+
/** Exposure over the day [time, exposure]: lifted at night so the moonlit scene reads, but never back to day brightness */
|
|
21
|
+
export const EXPOSURE = [[0, 1.15], [0.22, 1.15], [0.3, 1.0], [0.7, 1.0], [0.77, 1.1], [1, 1.15]];
|
|
22
|
+
/** Color grade over the day [time, temperature (-1 cool..1 warm), saturation, contrast] */
|
|
23
|
+
export const GRADE = [
|
|
24
|
+
[0.00, -0.45, 0.72, 1.06], // night: cooler and less saturated (eyes lose color in the dark), a touch of contrast keeps edges
|
|
25
|
+
[0.22, -0.3, 0.8, 1.04],
|
|
26
|
+
[0.28, 0.35, 0.95, 1.0],
|
|
27
|
+
[0.40, 0, 1, 1],
|
|
28
|
+
[0.65, 0, 1, 1],
|
|
29
|
+
[0.73, 0.5, 0.9, 1.04], // dusk: warm, and saturation DOWN as warmth goes up, or oranges clip into neon
|
|
30
|
+
[0.79, -0.25, 0.78, 1.05],
|
|
31
|
+
[1.00, -0.45, 0.72, 1.06],
|
|
32
|
+
];
|
|
33
|
+
/** Lamps: fully on below this daylight (0 night .. 1 noon), fading in above it. Daylight 0.35 is about 16:40: lamps come on before dark, as people switch them on */
|
|
34
|
+
export const LAMPS = { onBelow: 0.02, offAbove: 0.35, light: 14, window: 2.2, head: 3 };
|
|
35
|
+
export const TONE_MAPPING = THREE.AgXToneMapping;
|
|
36
|
+
|
|
37
|
+
/** The two keyframe rows around t and how far t is between them; rows are sorted by t and the table wraps at 1 @param {number[][]} rows @param {number} t */
|
|
38
|
+
function around(rows, t) {
|
|
39
|
+
let i = rows.findIndex(r => r[0] > t);
|
|
40
|
+
if (i <= 0) i = i === 0 ? 0 : rows.length - 1;
|
|
41
|
+
const a = rows[Math.max(0, i - 1)], b = rows[i], k = b[0] === a[0] ? 0 : (t - a[0]) / (b[0] - a[0]);
|
|
42
|
+
return { a, b, k: Math.min(1, Math.max(0, k)) };
|
|
43
|
+
}
|
|
44
|
+
/** Plain numbers at t @param {number[][]} rows @param {number} t */
|
|
45
|
+
export function sample(rows, t) {
|
|
46
|
+
const { a, b, k } = around(rows, t);
|
|
47
|
+
return a.slice(1).map((v, j) => v + (b[j + 1] - v) * k);
|
|
48
|
+
}
|
|
49
|
+
const ca = new THREE.Color(), cb = new THREE.Color();
|
|
50
|
+
/** One color column of SKY at t, blended as colors (hex numbers must not be interpolated as numbers) @param {THREE.Color} out @param {number} col @param {number} t */
|
|
51
|
+
export function skyColor(out, col, t) {
|
|
52
|
+
const { a, b, k } = around(SKY, t);
|
|
53
|
+
return out.copy(ca.set(a[col])).lerp(cb.set(b[col]), k);
|
|
54
|
+
}
|
|
55
|
+
/** One number column of SKY at t @param {number} col @param {number} t */
|
|
56
|
+
export function skyNumber(col, t) {
|
|
57
|
+
const { a, b, k } = around(SKY, t);
|
|
58
|
+
return a[col] + (b[col] - a[col]) * k;
|
|
59
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
// The color grade: one plain ShaderPass whose uniforms the keyframes write directly, so nothing sits between the table and the shader.
|
|
3
|
+
import { ShaderPass } from 'three/addons/postprocessing/ShaderPass.js';
|
|
4
|
+
import { GRADE, sample } from './palette.js';
|
|
5
|
+
|
|
6
|
+
/** @param {any} engine */
|
|
7
|
+
export function createPost(engine) {
|
|
8
|
+
const pass = new ShaderPass({
|
|
9
|
+
uniforms: { tDiffuse: { value: null }, uTemp: { value: 0 }, uSat: { value: 1 }, uContrast: { value: 1 } },
|
|
10
|
+
vertexShader: 'varying vec2 vUv; void main(){ vUv = uv; gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0); }',
|
|
11
|
+
fragmentShader: `uniform sampler2D tDiffuse; uniform float uTemp; uniform float uSat; uniform float uContrast; varying vec2 vUv;
|
|
12
|
+
void main(){ vec4 c = texture2D(tDiffuse, vUv);
|
|
13
|
+
c.rgb += vec3(uTemp * 0.06, 0.0, -uTemp * 0.06);
|
|
14
|
+
c.rgb = clamp((c.rgb - 0.5) * uContrast + 0.5, 0.0, 1.0);
|
|
15
|
+
c.rgb = mix(vec3(dot(c.rgb, vec3(0.2126, 0.7152, 0.0722))), c.rgb, uSat);
|
|
16
|
+
gl_FragColor = c; }`,
|
|
17
|
+
});
|
|
18
|
+
const u = pass.uniforms, handle = engine.post.add(pass, { name: 'grade', slot: 'ldr' }); // 'ldr': after the tone curve, on display colors
|
|
19
|
+
return {
|
|
20
|
+
grade: () => ({ temperature: u.uTemp.value, saturation: u.uSat.value, contrast: u.uContrast.value }),
|
|
21
|
+
remove: () => handle.remove(),
|
|
22
|
+
/** @param {any} s engine.uniforms */
|
|
23
|
+
update(s) { [u.uTemp.value, u.uSat.value, u.uContrast.value] = sample(GRADE, s.uTimeOfDay.value); },
|
|
24
|
+
};
|
|
25
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
// The sky is the game's: a gradient sphere from the keyframes, with fog in the horizon color. The engine's dome is hidden.
|
|
3
|
+
import { THREE } from 'threedog';
|
|
4
|
+
import { skyColor } from './palette.js';
|
|
5
|
+
|
|
6
|
+
/** @param {any} engine */
|
|
7
|
+
export function createSky(engine) {
|
|
8
|
+
const { scene } = engine;
|
|
9
|
+
scene.fog = new THREE.Fog(0x000000, 180, 600);
|
|
10
|
+
const skyMat = new THREE.ShaderMaterial({
|
|
11
|
+
side: THREE.BackSide, depthWrite: false, fog: false,
|
|
12
|
+
uniforms: { uTop: { value: new THREE.Color() }, uHorizon: { value: new THREE.Color() } },
|
|
13
|
+
vertexShader: 'varying vec3 vDir; void main(){ vDir = normalize(position); gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0); }',
|
|
14
|
+
// tonemapping_fragment: the sky takes the same curve and exposure as the street, so a dusk horizon and a dusk wall stay in one picture
|
|
15
|
+
fragmentShader: `uniform vec3 uTop; uniform vec3 uHorizon; varying vec3 vDir;
|
|
16
|
+
void main(){ gl_FragColor = vec4(mix(uHorizon, uTop, smoothstep(-0.05, 0.45, vDir.y)), 1.0);
|
|
17
|
+
#include <tonemapping_fragment>
|
|
18
|
+
#include <colorspace_fragment>
|
|
19
|
+
}`,
|
|
20
|
+
});
|
|
21
|
+
const dome = new THREE.Mesh(new THREE.SphereGeometry(400, 32, 16), skyMat);
|
|
22
|
+
dome.renderOrder = -1;
|
|
23
|
+
scene.add(dome);
|
|
24
|
+
if (engine.sky) engine.sky.dome.visible = false;
|
|
25
|
+
return {
|
|
26
|
+
/** @param {any} s engine.uniforms */
|
|
27
|
+
update(s) {
|
|
28
|
+
const t = s.uTimeOfDay.value, u = skyMat.uniforms;
|
|
29
|
+
skyColor(u.uTop.value, 1, t); skyColor(u.uHorizon.value, 2, t);
|
|
30
|
+
/** @type {THREE.Fog} */ (scene.fog).color.copy(u.uHorizon.value);
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
Interior light: sun through a window with shadows, the window as an area light, faked bounce with light probes or a fill light, exposure from outside to inside, and lamps at night without glare.
|
|
2
|
+
|
|
3
|
+
# Interior light (technique example)
|
|
4
|
+
|
|
5
|
+
A neutral gray room (8 x 6 m, 3 m high, a window in the west wall, a door in the south wall), lit from outside by day and by lamps at night.
|
|
6
|
+
Run `npm run dev` and open `/interior-light.html`. The engine never imports this folder.
|
|
7
|
+
|
|
8
|
+
| URL | What changes |
|
|
9
|
+
|---|---|
|
|
10
|
+
| `?cam=inside \| doorway \| outside` | the camera view (the zone, and so exposure and ambient, follows the camera) |
|
|
11
|
+
| `&fill=probes \| light \| none` | bounce baked into light probes (default), one cheap point light, or nothing |
|
|
12
|
+
| `&night=1` | night: lamps instead of the sun |
|
|
13
|
+
| `&area=0` | no window area light |
|
|
14
|
+
| `&leak=1` | keep the outdoor ambient indoors (shows the problem the zones solve) |
|
|
15
|
+
|
|
16
|
+
The whole picture is plain three.js in `picture/`; every value of it sits in `picture/palette.js` (`SUN`, `MOON`, `AMBIENT`, `WINDOW_LIGHT`, `BOUNCE_LIGHT`,
|
|
17
|
+
`EXPOSURE`, `LAMPS`, `SHADOW`, `SKY`). `main.js` keeps the shapes (`ROOM`, `WINDOW`, `DOOR`, `VIEWS`). Related: `sun-and-key-light` (the sun itself), `contact-shadows`, `night-lights` (lights in an outdoor night).
|
|
18
|
+
|
|
19
|
+
## The principle
|
|
20
|
+
**A room is lit from its openings.** Daylight enters in two parts: the sun (a hard patch on the floor, the brightest thing in the room) and
|
|
21
|
+
the sky seen through the window (a soft, cool light that falls off with distance from the window). Everything else is bounce: the sun patch
|
|
22
|
+
lights the ceiling and the walls around it. A room without bounce looks like a cave with one spotlight; a room where the bounce is as bright
|
|
23
|
+
as the patch looks flat.
|
|
24
|
+
|
|
25
|
+
**Outdoor ambient leaks.** Hemisphere and environment light reach every surface regardless of walls, so indoors they light the room as if
|
|
26
|
+
it had no roof. Turn them down inside and let the bounce do the fill. `?leak=1` shows the room with the outdoor values: evenly gray, the sun
|
|
27
|
+
patch barely stands out.
|
|
28
|
+
|
|
29
|
+
**Exposure is the eye.** Real interiors are many times darker than the street; the eye adapts, a camera changes exposure. Games compress the
|
|
30
|
+
range: inside gets a higher exposure, eased over about a second when the player crosses the threshold. Looking in from outside, the room usually
|
|
31
|
+
reads darker than the street (and from inside the window brighter than the room), which gives the space its depth; if your game wants a flat,
|
|
32
|
+
evenly lit look (a diorama, a cutaway), keep one exposure on purpose.
|
|
33
|
+
|
|
34
|
+
**Night: light the surfaces, not the bulb.** A lamp is a pool of light on a table, a wall, a floor. Hide the bulb in a shade, keep the visible
|
|
35
|
+
emitter dim, and let the light do the work; several small warm lights read cozier than one bright one. Glare and clipped white come from
|
|
36
|
+
bright visible emitters plus bloom; without bloom they just look like flat white shapes.
|
|
37
|
+
|
|
38
|
+
How to judge it in a shot: the sun patch is the brightest area, the wall opposite the window clearly dimmer, and the corner furthest from the
|
|
39
|
+
window dark but still readable if the game needs it readable. Check from the cameras the game really uses, including the doorway.
|
|
40
|
+
|
|
41
|
+
## Plain three.js
|
|
42
|
+
- Sun patch: a `DirectionalLight` with `castShadow`, every wall / ceiling / frame `castShadow`, and `shadow.camera` fitted to the room
|
|
43
|
+
([DirectionalLightShadow](https://threejs.org/docs/#api/en/lights/shadows/DirectionalLightShadow)).
|
|
44
|
+
- Window sky light: [RectAreaLight](https://threejs.org/docs/#api/en/lights/RectAreaLight) with `RectAreaLightUniformsLib.init()`
|
|
45
|
+
([webgl_lights_rectarealight](https://threejs.org/examples/#webgl_lights_rectarealight)).
|
|
46
|
+
- Bounce: a [LightProbe](https://threejs.org/docs/#api/en/lights/LightProbe) filled by `LightProbeGenerator.fromCubeRenderTarget` after a
|
|
47
|
+
`CubeCamera` render inside the room; or a weak unshadowed `PointLight` above the patch; or a lightmap (`material.lightMap`, needs a second UV set).
|
|
48
|
+
- Exposure: ease `renderer.toneMappingExposure` and the `HemisphereLight` intensity together when the camera enters a box.
|
|
49
|
+
- Lamps: `PointLight` with `decay: 2`, intensity in candela ([PointLight](https://threejs.org/docs/#api/en/lights/PointLight)), a low
|
|
50
|
+
`emissiveIntensity` on the shade.
|
|
51
|
+
|
|
52
|
+
## Style routes
|
|
53
|
+
- **Realistic**: probes or lightmaps for the bounce, a strong sun patch, exposure zones with a noticeable change. Costs a bake.
|
|
54
|
+
- **Stylized / cozy**: warmer bounce (`BOUNCE_LIGHT.color`), softer contrast between patch and room, more lamps at night, gentle exposure
|
|
55
|
+
change. Costs a few more lights.
|
|
56
|
+
- **Horror / stealth**: little or no fill, a hard window patch, slow exposure adaptation so the player is blind for a moment at the door. Cheapest.
|
|
57
|
+
- **Top-down or isometric**: the ceiling is usually hidden; the window patch and lamp pools carry the room. For 2D-like spreading light that
|
|
58
|
+
stops at walls see `examples/rc2d`.
|
|
59
|
+
- **Baked (static rooms)**: lightmaps from Blender give per-surface bounce at no run-time cost when the room does not change (recipe 46).
|
|
60
|
+
|
|
61
|
+
## The engine helper (optional convenience)
|
|
62
|
+
`threedog examples pull interior-light` copies `interiorLight.js` and this README into the game; the probes are `engine.bakeProbes` itself.
|
|
63
|
+
- `exposureZones(engine, { hemi, isInside, exposure, ambient, ease })`: changes exposure and the leaking outdoor ambient together, eased, and only
|
|
64
|
+
when the zone changes. It writes `hemi.intensity`, `scene.environmentIntensity` and `renderer.toneMappingExposure`; call its `update(dt)` from
|
|
65
|
+
`engine.onFrame`, and `update()` to jump to the zone's values at once. The page uses a box around the room and `EXPOSURE.day.outside` / `.inside`,
|
|
66
|
+
eased over `EXPOSURE.ease` seconds.
|
|
67
|
+
- `windowLight(engine, { position, lookAt, width, height })`: a `RectAreaLight` with its one-time uniforms init done.
|
|
68
|
+
|
|
69
|
+
| fill | what it gives | cost |
|
|
70
|
+
|---|---|---|
|
|
71
|
+
| `probes` | bounce from the actual sun patch and walls, colored by them, direction-dependent | a bake at load (6 cube renders per probe; `probes.bakeMs` says how long); at run time one LightProbe, about free |
|
|
72
|
+
| `light` | one unshadowed PointLight above the sun patch, standing in for its bounce | one more light in every lit shader; no bake. Simple and easy to tune, but it is a point, so it shows as a hot spot if too strong |
|
|
73
|
+
| `none` | the room as the direct lights leave it | nothing |
|
|
74
|
+
|
|
75
|
+
Measured in the test (linear light, the floor along the north wall and the wall's lower part, out of the sun patch): probes make them clearly
|
|
76
|
+
brighter than no fill (the test requires more than 1.15x).
|
|
77
|
+
|
|
78
|
+
Zones vs measured exposure: a zone is cheap and predictable, and the designer decides the values. Measured auto exposure (average the frame's
|
|
79
|
+
luminance, ease toward a target) adapts to anything but needs a downsample and readback every few frames, can pump when bright objects enter
|
|
80
|
+
the view, and still needs limits. A zone also carries the ambient change, which measured exposure cannot. Limit of zones: they follow the
|
|
81
|
+
camera, so looking into the room from outside it still gets outdoor ambient (`?cam=doorway`). When that view matters, give indoor surfaces
|
|
82
|
+
their own fill (a probe grid over each part, or lightmaps).
|
|
83
|
+
|
|
84
|
+
Night (`?night=1`): a very low moon (`MOON`), the indoor zone's exposure at 1, two warm PointLights (physical falloff,
|
|
85
|
+
decay 2, intensity in candela) inside shades with an emissive of 0.35; one casts a 512 px shadow (a point light shadow is six renders: give it
|
|
86
|
+
only to the light that needs it). With bloom (`@threedog/post-effects`), keep the emitter's `emissiveIntensity` low or it blooms across the room.
|
|
87
|
+
|
|
88
|
+
Rules (correctness):
|
|
89
|
+
- `RectAreaLight` needs `RectAreaLightUniformsLib.init()` once, lights only `MeshStandardMaterial` / `MeshPhysicalMaterial`, and **casts no
|
|
90
|
+
shadow**: it lights through furniture and walls on its front side. Use it for the window's soft sky light or a screen, and keep the
|
|
91
|
+
shadowed part to the sun (a DirectionalLight) or a SpotLight.
|
|
92
|
+
- The sun through a window needs every wall, the ceiling and the window frame to `castShadow`, and a shadow box that covers the room. `picture/lights.js`
|
|
93
|
+
aims its own `DirectionalLight` and writes `shadow.camera` to fit the room. Thin walls want a small `normalBias` (here 1 cm) or light leaks along
|
|
94
|
+
their inner edge.
|
|
95
|
+
- `engine.bakeProbes({ bounds, spacing })` bakes the scene as it is at that moment: set the indoor ambient and the lights first, and
|
|
96
|
+
bake again (or ship one bake per state) if the lighting changes a lot (day / night). Probes add to the hemisphere and environment, which
|
|
97
|
+
the bake also saw (recipe 34). Every pixel in the room takes its own light; outside `bounds` there is none,
|
|
98
|
+
so a building seen from outside needs its own light.
|
|
99
|
+
- The bake renders after start; this page tracks it in `engine.loading` so screenshots and tests wait for it.
|
|
100
|
+
- Do not name page URL parameters `time` or `view` (or the other engine scenario keys: `weather`, `pos`, `season`, `state`, `save`, `wait`,
|
|
101
|
+
`cutscene`): `?time=night` reaches the sky as a clock time, turns into NaN and blacks out the frame.
|
|
102
|
+
|
|
103
|
+
Sources: written for this repository, no code copied. Background: three.js `RectAreaLight` and `LightProbe` docs and examples (0.187), general
|
|
104
|
+
architectural-visualization and game-lighting writing on window light, bounce and eye adaptation.
|
|
105
|
+
|
|
106
|
+
This example is written in GLSL: it is the WebGL route (`threedog new-game --webgl`). A game on the default WebGPU route writes the same ideas in TSL (recipe 56).
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
// Interior light helpers (technique example, README.md next to this file). Imports only three and its RectAreaLight addon.
|
|
3
|
+
// Why helpers: the zone switch has to change exposure and the leaking outdoor ambient together, eased, and only when the zone changes;
|
|
4
|
+
// the window light needs a one-time uniforms init. Both are easy to get half right by hand.
|
|
5
|
+
import * as THREE from 'three';
|
|
6
|
+
import { RectAreaLightUniformsLib } from 'three/addons/lights/RectAreaLightUniformsLib.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Exposure and ambient by zone, following the camera. `isInside(cameraPosition)` decides the zone; on a change the hemisphere / environment
|
|
10
|
+
* intensities switch at once (they light through walls) and the exposure eases over `ease` seconds (an eye adapting). Presentation only: call
|
|
11
|
+
* update(dt) from engine.onFrame; update() with no dt jumps straight to the zone's values. Writes hemi.intensity, scene.environmentIntensity and
|
|
12
|
+
* renderer.toneMappingExposure, nothing else.
|
|
13
|
+
* @param {{ camera: THREE.Camera, scene: THREE.Scene, renderer: THREE.WebGLRenderer }} engine
|
|
14
|
+
* @param {{ hemi: THREE.HemisphereLight, isInside: (p: THREE.Vector3) => boolean, exposure: { inside: number, outside: number }, ambient: { inside: { hemi: number, env: number }, outside: { hemi: number, env: number } }, ease?: number }} o
|
|
15
|
+
*/
|
|
16
|
+
export function exposureZones(engine, { hemi, isInside, exposure, ambient, ease = 1.2 }) {
|
|
17
|
+
const zone = { name: '', exposure: 0, target: 0 };
|
|
18
|
+
return {
|
|
19
|
+
zone,
|
|
20
|
+
update(dt = Infinity) {
|
|
21
|
+
const name = isInside(engine.camera.position) ? 'inside' : 'outside';
|
|
22
|
+
if (name !== zone.name) {
|
|
23
|
+
zone.name = name;
|
|
24
|
+
zone.target = exposure[name];
|
|
25
|
+
hemi.intensity = ambient[name].hemi;
|
|
26
|
+
engine.scene.environmentIntensity = ambient[name].env;
|
|
27
|
+
}
|
|
28
|
+
zone.exposure = zone.exposure ? zone.exposure + (zone.target - zone.exposure) * Math.min(1, dt / (ease / 3)) : zone.target;
|
|
29
|
+
engine.renderer.toneMappingExposure = zone.exposure;
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The sky seen through a window as a RectAreaLight in the opening, facing `lookAt`. Soft and window-shaped, but it casts no shadow and lights
|
|
36
|
+
* only MeshStandardMaterial / MeshPhysicalMaterial.
|
|
37
|
+
* @param {any} engine
|
|
38
|
+
* @param {{ position: number[], lookAt: number[], width: number, height: number, color?: THREE.ColorRepresentation, intensity?: number }} o
|
|
39
|
+
*/
|
|
40
|
+
export function windowLight(engine, { position, lookAt, width, height, color = '#cfe0ff', intensity = 2 }) {
|
|
41
|
+
RectAreaLightUniformsLib.init(); // once per page is enough; calling it again is harmless
|
|
42
|
+
const area = new THREE.RectAreaLight(color, intensity, width, height);
|
|
43
|
+
area.position.set(position[0], position[1], position[2]);
|
|
44
|
+
area.lookAt(lookAt[0], lookAt[1], lookAt[2]);
|
|
45
|
+
engine.scene.add(area);
|
|
46
|
+
return area;
|
|
47
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
// Technique example: interior light (page /interior-light.html, README.md next to this file). A neutral gray room (8 x 6 m, 3 m high) with a
|
|
3
|
+
// window in the west wall and a door in the south wall. One skill: lighting a room from outside (sun through the opening, sky light through the
|
|
4
|
+
// window), filling the shadowed side with bounce, the exposure change between outside and inside, and lamps at night.
|
|
5
|
+
// (time and view are the engine's own URL scenario keys, see core/UrlState.js: page params use other names)
|
|
6
|
+
// URL: ?night=1 ?cam=inside|doorway|outside ?fill=probes|light|none ?area=0 (no window area light) ?leak=1 (keep outdoor ambient indoors)
|
|
7
|
+
// Test page for tests/specs/techniques-light.mjs: window.interiorTest = { THREE, ready, points, picture }. Shapes only here; the whole picture is picture/.
|
|
8
|
+
import { createEngine, sky, fixedCamera, THREE } from 'threedog';
|
|
9
|
+
import { createPicture } from './picture/index.js';
|
|
10
|
+
|
|
11
|
+
// ---- parameters: change these ----------------------------------------------------------------------------------------------------------
|
|
12
|
+
const ROOM = { min: [-4, 0, -3], max: [4, 3, 3], wall: 0.2 };
|
|
13
|
+
const WINDOW = { z: [-1.1, 1.1], y: [0.8, 2.4] }; // opening in the west wall (x = -4)
|
|
14
|
+
const DOOR = { x: [1.4, 2.5], y: [0, 2.2] }; // opening in the south wall (z = +3)
|
|
15
|
+
const LAMPS = /** @type {{ at: number[], kind: 'main' | 'side' }[]} */ ([{ at: [2.6, 1.55, -2.2], kind: 'main' }, { at: [-2.8, 1.0, 2.2], kind: 'side' }]);
|
|
16
|
+
const VIEWS = {
|
|
17
|
+
inside: { position: [3.4, 1.65, 2.4], lookAt: [-3, 0.8, -0.6] },
|
|
18
|
+
doorway: { position: [1.95, 1.65, 5.2], lookAt: [0.6, 1.1, -3] },
|
|
19
|
+
outside: { position: [6, 1.7, 12], lookAt: [0, 1.2, 0] },
|
|
20
|
+
};
|
|
21
|
+
// ------------------------------------------------------------------------------------------------------------------------------------------
|
|
22
|
+
|
|
23
|
+
const url = new URLSearchParams(location.search);
|
|
24
|
+
const night = url.get('night') === '1', fill = url.get('fill') ?? 'probes', view = /** @type {keyof typeof VIEWS} */ (url.get('cam') ?? 'inside');
|
|
25
|
+
if (!VIEWS[view]) throw new Error(`?cam=${view}: use one of ${Object.keys(VIEWS).join(', ')}`);
|
|
26
|
+
|
|
27
|
+
const engine = createEngine({ canvas: /** @type {HTMLCanvasElement} */ (document.getElementById('view')), lights: false, ui: { loading: false }, saveKey: 'threedog-interior' });
|
|
28
|
+
engine.use(sky({ time: night ? '22:30' : '15:00' }));
|
|
29
|
+
engine.use(fixedCamera({ shots: VIEWS, start: view }));
|
|
30
|
+
|
|
31
|
+
const [x0, , z0] = ROOM.min, [x1, h, z1] = ROOM.max, t = ROOM.wall, windowY = (WINDOW.y[0] + WINDOW.y[1]) / 2;
|
|
32
|
+
// the camera inside this box gets indoor ambient and indoor exposure, eased
|
|
33
|
+
const inside = (/** @type {THREE.Vector3} */ p) => p.x > x0 && p.x < x1 && p.z > z0 && p.z < z1 + 0.5 && p.y < h;
|
|
34
|
+
const picture = createPicture(engine, { night, fill, isInside: inside, leak: url.get('leak') === '1',
|
|
35
|
+
// the window as a light: a RectAreaLight in the opening, facing in
|
|
36
|
+
windowOpening: url.get('area') === '0' ? null : { position: [x0 - 0.02, windowY, 0], lookAt: [0, windowY, 0], width: WINDOW.z[1] - WINDOW.z[0], height: WINDOW.y[1] - WINDOW.y[0] } });
|
|
37
|
+
const { mat } = picture;
|
|
38
|
+
|
|
39
|
+
// ---- the neutral gray room ----
|
|
40
|
+
const box = (/** @type {number[]} */ min, /** @type {number[]} */ max, m = mat.wall) => {
|
|
41
|
+
const mesh = new THREE.Mesh(new THREE.BoxGeometry(max[0] - min[0], max[1] - min[1], max[2] - min[2]), m);
|
|
42
|
+
mesh.position.set((min[0] + max[0]) / 2, (min[1] + max[1]) / 2, (min[2] + max[2]) / 2);
|
|
43
|
+
mesh.castShadow = mesh.receiveShadow = true;
|
|
44
|
+
engine.scene.add(mesh);
|
|
45
|
+
return mesh;
|
|
46
|
+
};
|
|
47
|
+
const ground = new THREE.Mesh(new THREE.PlaneGeometry(120, 120), mat.ground);
|
|
48
|
+
ground.rotation.x = -Math.PI / 2;
|
|
49
|
+
ground.position.y = -0.01;
|
|
50
|
+
ground.receiveShadow = true;
|
|
51
|
+
engine.scene.add(ground);
|
|
52
|
+
box([x0, -0.01, z0], [x1, 0.02, z1], mat.floor); // the floor
|
|
53
|
+
box([x0 - t, h, z0 - t], [x1 + t, h + t, z1 + t]); // the ceiling
|
|
54
|
+
box([x0 - t, 0, z0 - t], [x1 + t, h, z0]); // north wall
|
|
55
|
+
box([x1, 0, z0], [x1 + t, h, z1]); // east wall
|
|
56
|
+
// west wall with the window: four pieces around the opening
|
|
57
|
+
box([x0 - t, 0, z0], [x0, h, WINDOW.z[0]]); box([x0 - t, 0, WINDOW.z[1]], [x0, h, z1]);
|
|
58
|
+
box([x0 - t, 0, WINDOW.z[0]], [x0, WINDOW.y[0], WINDOW.z[1]]); box([x0 - t, WINDOW.y[1], WINDOW.z[0]], [x0, h, WINDOW.z[1]]);
|
|
59
|
+
// south wall with the door
|
|
60
|
+
box([x0 - t, 0, z1], [DOOR.x[0], h, z1 + t]); box([DOOR.x[1], 0, z1], [x1 + t, h, z1 + t]); box([DOOR.x[0], DOOR.y[1], z1], [DOOR.x[1], h, z1 + t]);
|
|
61
|
+
// furniture-sized blocks: a table, a cabinet against the east wall, a sofa-sized block in the corner
|
|
62
|
+
box([-1.2, 0, -0.5], [0.4, 0.75, 0.5], mat.table); box([3.2, 0, -1.4], [3.95, 1.9, 0.6], mat.cabinet); box([-3.9, 0, 1.4], [-2.2, 0.8, 2.9], mat.sofa);
|
|
63
|
+
|
|
64
|
+
// ---- night: lamps. The bulb hides inside a shade; the light lands on surfaces, the visible emitter stays dim ----
|
|
65
|
+
if (night) {
|
|
66
|
+
for (const { at, kind } of LAMPS) {
|
|
67
|
+
picture.addLamp(kind, at);
|
|
68
|
+
const shade = new THREE.Mesh(new THREE.CylinderGeometry(0.16, 0.26, 0.28, 24, 1, true), mat.shade[kind]);
|
|
69
|
+
shade.position.set(at[0], at[1], at[2]);
|
|
70
|
+
const stand = new THREE.Mesh(new THREE.CylinderGeometry(0.02, 0.02, at[1] - 0.14, 8), mat.stand);
|
|
71
|
+
stand.position.set(at[0], (at[1] - 0.14) / 2, at[2]);
|
|
72
|
+
engine.scene.add(shade, stand);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// ---- fill: bounce baked into light probes; ?fill=light is one cheap point light in picture/lights.js ----
|
|
77
|
+
async function setupFill() {
|
|
78
|
+
picture.snapZone(); // bake with indoor ambient, as the room is meant to be seen
|
|
79
|
+
if (fill !== 'probes') return;
|
|
80
|
+
// bounds = the room's air
|
|
81
|
+
await engine.bakeProbes({ bounds: { min: [x0 + 0.5, 0.4, z0 + 0.5], max: [x1 - 0.5, h - 0.4, z1 - 0.5] }, spacing: 2.5 });
|
|
82
|
+
}
|
|
83
|
+
// spots the spec reads: the floor along the north wall and the north wall's lower part, both out of the sun patch
|
|
84
|
+
const points = { corner: [-0.5, 0.03, -2.5], northWall: [1.5, 0.6, -2.98] };
|
|
85
|
+
// the bake renders cubes between frames, so it runs after start; tracked in engine.loading so screenshots and tests wait for it
|
|
86
|
+
const ready = engine.start().then(() => engine.loading.track('fill', setupFill));
|
|
87
|
+
Object.assign(window, { engine, interiorTest: { THREE, ready, points, picture, fill, night } });
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
// The picture of the interior-light demo: wiring only. Each part writes plain three.js.
|
|
3
|
+
import { exposureZones } from '../interiorLight.js';
|
|
4
|
+
import { AMBIENT, EXPOSURE, TONE_MAPPING } from './palette.js';
|
|
5
|
+
import { createLights } from './lights.js';
|
|
6
|
+
import { createMaterials } from './materials.js';
|
|
7
|
+
import { createSky } from './sky.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Returns { mat, sun, hemi, addLamp, zone, snapZone() }. snapZone(): the zone's values at once, without easing, for the bake.
|
|
11
|
+
* @param {any} engine
|
|
12
|
+
* @param {Parameters<typeof createLights>[1] & { isInside: (p: any) => boolean, leak: boolean }} o
|
|
13
|
+
*/
|
|
14
|
+
export function createPicture(engine, { isInside, leak, ...o }) {
|
|
15
|
+
engine.renderer.toneMapping = TONE_MAPPING;
|
|
16
|
+
const sky = createSky(engine), lights = createLights(engine, o), { mat } = createMaterials();
|
|
17
|
+
const zones = exposureZones(engine, { hemi: lights.hemi, isInside, exposure: EXPOSURE[o.night ? 'night' : 'day'], ease: EXPOSURE.ease,
|
|
18
|
+
ambient: leak ? { inside: AMBIENT.outside, outside: AMBIENT.outside } : AMBIENT });
|
|
19
|
+
// onRender, not onFrame: onFrame runs before the sky module, so it would read last frame's signals
|
|
20
|
+
engine.onRender(() => { sky.update(engine.uniforms); lights.update(engine.uniforms); });
|
|
21
|
+
// the zones read no signals but must count every second, and a frame that is not drawn still passes time: onFrame sees those, onRender does not
|
|
22
|
+
engine.onFrame((/** @type {number} */ dt) => zones.update(dt));
|
|
23
|
+
return { mat, sun: lights.sun, hemi: lights.hemi, addLamp: lights.addLamp, zone: zones.zone, snapZone: () => zones.update() };
|
|
24
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
// The room's lights: sun or moon aimed by hand with its shadow box fitted to the room, the hemisphere, the window as an area light, the bounce
|
|
3
|
+
// stand-in and the lamps. The sun stays fixed all day: this page is about the room, not the clock; only the hemisphere's colors read the signals.
|
|
4
|
+
import { THREE } from 'threedog';
|
|
5
|
+
import { windowLight } from '../interiorLight.js';
|
|
6
|
+
import { BOUNCE_LIGHT, HEMI, LAMPS, LAMP_SHADOW, MOON, SHADOW, SUN, WINDOW_LIGHT } from './palette.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @param {any} engine
|
|
10
|
+
* @param {{ night: boolean, fill: string, windowOpening: { position: number[], lookAt: number[], width: number, height: number } | null }} o
|
|
11
|
+
*/
|
|
12
|
+
export function createLights(engine, { night, fill, windowOpening }) {
|
|
13
|
+
const { scene, renderer } = engine, key = night ? MOON : SUN;
|
|
14
|
+
const hemi = new THREE.HemisphereLight(), sun = new THREE.DirectionalLight(key.color, key.intensity);
|
|
15
|
+
const az = THREE.MathUtils.degToRad(key.azimuth), el = THREE.MathUtils.degToRad(key.elevation);
|
|
16
|
+
sun.position.set(Math.sin(az) * Math.cos(el), Math.sin(el), -Math.cos(az) * Math.cos(el)).multiplyScalar(SHADOW.distance);
|
|
17
|
+
sun.castShadow = true;
|
|
18
|
+
renderer.shadowMap.type = SHADOW.type;
|
|
19
|
+
sun.shadow.mapSize.setScalar(SHADOW.mapSize[engine.tier === 'low' ? 'low' : 'high']);
|
|
20
|
+
const { extent: e, distance } = SHADOW;
|
|
21
|
+
Object.assign(sun.shadow.camera, { left: -e, right: e, top: e, bottom: -e, near: 1, far: distance * 2 });
|
|
22
|
+
// three adds bias in the shadow camera's 0-1 depth, i.e. a world offset of bias x (far - near)
|
|
23
|
+
Object.assign(sun.shadow, { normalBias: SHADOW.normalBias, bias: -SHADOW.biasCm / 100 / (distance * 2 - 1), radius: SHADOW.radius });
|
|
24
|
+
scene.add(hemi, sun, sun.target);
|
|
25
|
+
|
|
26
|
+
if (windowOpening && !night) windowLight(engine, { ...windowOpening, ...WINDOW_LIGHT });
|
|
27
|
+
if (fill === 'light' && !night) {
|
|
28
|
+
const { color, intensity, distance: reach, decay, at } = BOUNCE_LIGHT, bounce = new THREE.PointLight(color, intensity, reach, decay);
|
|
29
|
+
bounce.position.set(at[0], at[1], at[2]);
|
|
30
|
+
scene.add(bounce);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** The light of one lamp; the bulb hides inside the shade main.js puts around it @param {keyof typeof LAMPS} kind @param {number[]} at */
|
|
34
|
+
function addLamp(kind, at) {
|
|
35
|
+
const l = LAMPS[kind], p = new THREE.PointLight(l.color, l.intensity, 0, 2);
|
|
36
|
+
p.position.set(at[0], at[1], at[2]);
|
|
37
|
+
p.castShadow = l.shadow;
|
|
38
|
+
if (l.shadow) { p.shadow.mapSize.setScalar(LAMP_SHADOW.mapSize); p.shadow.bias = LAMP_SHADOW.bias; p.shadow.radius = LAMP_SHADOW.radius; }
|
|
39
|
+
scene.add(p);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const day = { sky: new THREE.Color(HEMI.day.sky), ground: new THREE.Color(HEMI.day.ground) }, dark = { sky: new THREE.Color(HEMI.night.sky), ground: new THREE.Color(HEMI.night.ground) };
|
|
43
|
+
return {
|
|
44
|
+
sun, hemi, addLamp,
|
|
45
|
+
/** @param {any} s engine.uniforms */
|
|
46
|
+
update(s) {
|
|
47
|
+
const light = s.uDaylight.value;
|
|
48
|
+
hemi.color.copy(dark.sky).lerp(day.sky, light);
|
|
49
|
+
hemi.groundColor.copy(dark.ground).lerp(day.ground, light);
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
// Materials by name. Standard everywhere, since a RectAreaLight lights nothing else. Each lamp's shade glows in its own light's color.
|
|
3
|
+
import { THREE } from 'threedog';
|
|
4
|
+
import { COLORS, LAMPS, ROUGHNESS } from './palette.js';
|
|
5
|
+
|
|
6
|
+
export function createMaterials() {
|
|
7
|
+
const flat = (/** @type {number} */ color, roughness = ROUGHNESS.surface) => new THREE.MeshStandardMaterial({ color, roughness });
|
|
8
|
+
const shade = (/** @type {{ color: string, glow: number }} */ l) => new THREE.MeshStandardMaterial({ color: COLORS.shade, emissive: l.color, emissiveIntensity: l.glow, side: THREE.DoubleSide, roughness: ROUGHNESS.shade });
|
|
9
|
+
return {
|
|
10
|
+
mat: { wall: flat(COLORS.wall), floor: flat(COLORS.floor), ground: flat(COLORS.ground, ROUGHNESS.ground), table: flat(COLORS.table), cabinet: flat(COLORS.cabinet),
|
|
11
|
+
sofa: flat(COLORS.sofa), stand: flat(COLORS.stand), shade: { main: shade(LAMPS.main), side: shade(LAMPS.side) } },
|
|
12
|
+
};
|
|
13
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
// Interior light palette: every value of the picture. Neutral numbers on a gray room; the colors of your game come from its own picture.
|
|
3
|
+
import { THREE } from 'threedog';
|
|
4
|
+
|
|
5
|
+
/** Surfaces of the room, by name */
|
|
6
|
+
export const COLORS = { wall: 0xb5b5b5, floor: 0x8f8f8f, ground: 0x8a8a8a, table: 0xa0a0a0, cabinet: 0x9c9c9c, sofa: 0xa6a6a6, stand: 0x777777, shade: 0xe8dccb };
|
|
7
|
+
export const ROUGHNESS = { surface: 0.9, ground: 0.95, shade: 1 };
|
|
8
|
+
/** azimuth: compass degrees from north (-Z), -90 = from the west. By night the same light is a weak moon */
|
|
9
|
+
export const SUN = { elevation: 32, azimuth: -90 + 12, intensity: 3.2, color: '#fff0dc' };
|
|
10
|
+
export const MOON = { elevation: 40, azimuth: -90 + 40, intensity: 0.12, color: '#8fa4d4' };
|
|
11
|
+
// the walls stop the sun but not these two, so indoors the ambient is turned down and the fill comes from bounce
|
|
12
|
+
export const AMBIENT = { outside: { hemi: 1.0, env: 0.3 }, inside: { hemi: 0.06, env: 0.04 } };
|
|
13
|
+
/** Hemisphere colors, blended by daylight */
|
|
14
|
+
export const HEMI = { day: { sky: '#b9b9b9', ground: '#4a4a4a' }, night: { sky: '#212121', ground: '#3a3a3a' } };
|
|
15
|
+
/** RectAreaLight: the sky seen through the window (nits-like units, Standard / Physical only) */
|
|
16
|
+
export const WINDOW_LIGHT = { color: '#cfe0ff', intensity: 2.2 };
|
|
17
|
+
/** ?fill=light: one unshadowed point light just above the sun patch, standing in for its bounce */
|
|
18
|
+
export const BOUNCE_LIGHT = { color: '#ffe2c0', intensity: 1.2, distance: 7, decay: 1, at: [-1.6, 0.4, 0.2] };
|
|
19
|
+
/** Exposure per zone, eased over `ease` seconds when the camera crosses the doorway (an eye adapting) */
|
|
20
|
+
export const EXPOSURE = { day: { outside: 1, inside: 1.9 }, night: { outside: 1.6, inside: 1 }, ease: 1.2 };
|
|
21
|
+
/** intensity in candela, physical falloff; a point light shadow is six renders, so only the light that needs it gets one. glow: the shade stays dim (no glare without bloom) */
|
|
22
|
+
export const LAMPS = {
|
|
23
|
+
main: { intensity: 5, color: '#ffc58a', shadow: true, glow: 0.35 },
|
|
24
|
+
side: { intensity: 2.5, color: '#ffb874', shadow: false, glow: 0.35 },
|
|
25
|
+
};
|
|
26
|
+
export const LAMP_SHADOW = { mapSize: 512, bias: -0.002, radius: 4 };
|
|
27
|
+
/** Fitted to the room: 8 m wide at 2048 px is 0.6 cm texels. Thin walls need a small normalBias, or light leaks along their inner edge; biasCm is the depth bias in centimeters */
|
|
28
|
+
export const SHADOW = { extent: 9, distance: 160, mapSize: { high: 2048, low: 1024 }, normalBias: 0.01, biasCm: 1, radius: 2, type: THREE.PCFShadowMap };
|
|
29
|
+
/** Sky colors by daylight; horizon is also the fog color */
|
|
30
|
+
export const SKY = { day: { top: '#d4d4d4', horizon: '#d4d4d4' }, night: { top: '#20242c', horizon: '#2a2a2a' } };
|
|
31
|
+
export const FOG = { near: 180, far: 600 };
|
|
32
|
+
export const TONE_MAPPING = THREE.AgXToneMapping;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
// The sky is the game's: a gradient sphere and fog in its horizon color, blended by daylight. The engine's dome is hidden. The environment is
|
|
3
|
+
// three's RoomEnvironment: soft fill with some direction, no asset; the zones write its strength.
|
|
4
|
+
import { THREE } from 'threedog';
|
|
5
|
+
import { RoomEnvironment } from 'three/addons/environments/RoomEnvironment.js';
|
|
6
|
+
import { FOG, SKY } from './palette.js';
|
|
7
|
+
|
|
8
|
+
/** @param {any} engine */
|
|
9
|
+
export function createSky(engine) {
|
|
10
|
+
const { scene, renderer } = engine;
|
|
11
|
+
scene.fog = new THREE.Fog(SKY.day.horizon, FOG.near, FOG.far);
|
|
12
|
+
const pmrem = new THREE.PMREMGenerator(renderer);
|
|
13
|
+
scene.environment = pmrem.fromScene(new RoomEnvironment(), 0.04).texture;
|
|
14
|
+
pmrem.dispose();
|
|
15
|
+
const skyMat = new THREE.ShaderMaterial({
|
|
16
|
+
side: THREE.BackSide, depthWrite: false, fog: false,
|
|
17
|
+
uniforms: { uTop: { value: new THREE.Color() }, uHorizon: { value: new THREE.Color() } },
|
|
18
|
+
vertexShader: 'varying vec3 vDir; void main(){ vDir = normalize(position); gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0); }',
|
|
19
|
+
// tonemapping_fragment: the sky takes the room's curve and exposure, so the window runs bright indoors and calms down outside, as the zones intend
|
|
20
|
+
fragmentShader: `uniform vec3 uTop; uniform vec3 uHorizon; varying vec3 vDir;
|
|
21
|
+
void main(){ gl_FragColor = vec4(mix(uHorizon, uTop, smoothstep(-0.05, 0.45, vDir.y)), 1.0);
|
|
22
|
+
#include <tonemapping_fragment>
|
|
23
|
+
#include <colorspace_fragment>
|
|
24
|
+
}`,
|
|
25
|
+
});
|
|
26
|
+
const dome = new THREE.Mesh(new THREE.SphereGeometry(400, 32, 16), skyMat);
|
|
27
|
+
dome.renderOrder = -1;
|
|
28
|
+
scene.add(dome);
|
|
29
|
+
if (engine.sky) engine.sky.dome.visible = false;
|
|
30
|
+
const day = { top: new THREE.Color(SKY.day.top), horizon: new THREE.Color(SKY.day.horizon) }, night = { top: new THREE.Color(SKY.night.top), horizon: new THREE.Color(SKY.night.horizon) };
|
|
31
|
+
return {
|
|
32
|
+
/** @param {any} s engine.uniforms */
|
|
33
|
+
update(s) {
|
|
34
|
+
const light = s.uDaylight.value, u = skyMat.uniforms;
|
|
35
|
+
u.uTop.value.copy(night.top).lerp(day.top, light);
|
|
36
|
+
u.uHorizon.value.copy(night.horizon).lerp(day.horizon, light);
|
|
37
|
+
/** @type {THREE.Fog} */ (scene.fog).color.copy(u.uHorizon.value);
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
}
|