threedog 0.7.0 → 0.8.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 +196 -1
- package/README.md +6 -9
- package/core/{Animator.js → assets/Animator.js} +28 -18
- package/core/{Assets.js → assets/Assets.js} +98 -54
- package/core/{Baked.js → assets/Baked.js} +4 -4
- package/core/assets/assetEntry.js +237 -0
- package/core/{assetHot.js → assets/assetHot.js} +7 -6
- package/core/{assetLoad.js → assets/assetLoad.js} +55 -16
- package/core/assets/assetLod.js +113 -0
- package/core/{assetManifest.js → assets/assetManifest.js} +19 -11
- package/core/{assetReport.js → assets/assetReport.js} +6 -12
- package/core/{namedModel.js → assets/namedModel.js} +17 -13
- package/core/{Audio.js → audio/Audio.js} +26 -23
- package/core/{audioRules.js → audio/audioRules.js} +8 -5
- package/core/{audioVoice.js → audio/audioVoice.js} +17 -30
- package/core/{Events.js → base/Events.js} +3 -3
- package/core/{I18n.js → base/I18n.js} +10 -10
- package/core/{Random.js → base/Random.js} +5 -4
- package/core/{easing.js → base/easing.js} +1 -1
- package/core/{errorCodes.js → base/errorCodes.js} +98 -110
- package/core/{errorHints.js → base/errorHints.js} +5 -9
- package/core/{errors.js → base/errors.js} +6 -6
- package/core/{events.generated.js → base/events.generated.js} +1 -0
- package/core/{math.js → base/math.js} +15 -4
- package/core/{params.js → base/params.js} +3 -4
- package/core/base/util.js +32 -0
- package/core/{validate.js → base/validate.js} +28 -7
- package/core/{Engine.js → engine/Engine.js} +80 -77
- package/core/{Loading.js → engine/Loading.js} +4 -2
- package/core/{copies.js → engine/copies.js} +4 -4
- package/core/{headlessLoad.js → engine/headlessLoad.js} +4 -4
- package/core/{lifecycle.js → engine/lifecycle.js} +14 -12
- package/core/{loop.js → engine/loop.js} +68 -47
- package/core/{moduleSlots.js → engine/moduleSlots.js} +6 -6
- package/core/{moduleTypes.js → engine/moduleTypes.js} +13 -14
- package/core/{modules.js → engine/modules.js} +14 -11
- package/core/{page.js → engine/page.js} +36 -23
- package/core/{plugins.js → engine/plugins.js} +6 -9
- package/core/{services.js → engine/services.js} +47 -40
- package/core/{startup.js → engine/startup.js} +26 -24
- package/core/{Input.js → input/Input.js} +30 -22
- package/core/{inputContext.js → input/inputContext.js} +14 -5
- package/core/{inputPad.js → input/inputPad.js} +1 -1
- package/core/{inputPointer.js → input/inputPointer.js} +8 -2
- package/core/{inputTouch.js → input/inputTouch.js} +1 -1
- package/core/{Budget.js → inspect/Budget.js} +21 -20
- package/core/{DebugOverrides.js → inspect/DebugOverrides.js} +30 -16
- package/core/{Describe.js → inspect/Describe.js} +26 -22
- package/core/{Inspect.js → inspect/Inspect.js} +9 -7
- package/core/{InspectMaterials.js → inspect/InspectMaterials.js} +7 -8
- package/core/{InspectPerf.js → inspect/InspectPerf.js} +19 -13
- package/core/{InspectScene.js → inspect/InspectScene.js} +8 -5
- package/core/{MaterialInfo.js → inspect/MaterialInfo.js} +3 -2
- package/core/{UrlState.js → inspect/UrlState.js} +52 -20
- package/core/{catalog.js → inspect/catalog.js} +3 -3
- package/core/{checks.js → inspect/checks.js} +7 -5
- package/core/{debugView.js → inspect/debugView.js} +4 -4
- package/core/{describeRender.js → inspect/describeRender.js} +21 -20
- package/core/{describeText.js → inspect/describeText.js} +11 -6
- package/core/inspect/geometryWatch.js +38 -0
- package/core/{lightWatch.js → inspect/lightWatch.js} +8 -8
- package/core/{pictureWriters.js → inspect/pictureWriters.js} +15 -16
- package/core/{shaderCost.js → inspect/shaderCost.js} +1 -1
- package/core/{Ops.js → ops/Ops.js} +16 -11
- package/core/{control.js → ops/control.js} +13 -12
- package/core/ops/holds.js +139 -0
- package/core/{opsAtomic.js → ops/opsAtomic.js} +2 -1
- package/core/{opsCheck.js → ops/opsCheck.js} +4 -5
- package/core/{opsGuard.js → ops/opsGuard.js} +3 -3
- package/core/{opsRun.js → ops/opsRun.js} +7 -4
- package/core/{owned.js → ops/owned.js} +14 -17
- package/core/{sharedPoint.js → ops/sharedPoint.js} +8 -8
- package/core/{stackFrames.js → ops/stackFrames.js} +2 -2
- package/core/{stacks.js → ops/stacks.js} +12 -14
- package/core/{wrap.js → ops/wrap.js} +8 -6
- package/core/{SaveStore.js → saves/SaveStore.js} +1 -1
- package/core/{Saves.js → saves/Saves.js} +58 -36
- package/core/{saveApply.js → saves/saveApply.js} +13 -9
- package/core/{saveFiles.js → saves/saveFiles.js} +17 -15
- package/core/{saveValues.js → saves/saveValues.js} +20 -3
- package/core/{saveVersions.js → saves/saveVersions.js} +4 -17
- package/core/{session.js → saves/session.js} +31 -17
- package/core/{Rays.js → scene/Rays.js} +23 -25
- package/core/{Views.js → scene/Views.js} +14 -6
- package/core/{adaptive.js → scene/adaptive.js} +15 -8
- package/core/{canvasBox.js → scene/canvasBox.js} +2 -3
- package/core/{engineCamera.js → scene/engineCamera.js} +1 -1
- package/core/{gameLights.js → scene/gameLights.js} +17 -7
- package/core/{grayMap.js → scene/grayMap.js} +8 -2
- package/core/{grid.js → scene/grid.js} +4 -4
- package/core/{gridLoad.js → scene/gridLoad.js} +1 -1
- package/core/{ground.js → scene/ground.js} +9 -9
- package/core/{movement.js → scene/movement.js} +3 -3
- package/core/{pictureSlots.js → scene/pictureSlots.js} +2 -2
- package/core/{sceneDelta.js → scene/sceneDelta.js} +2 -2
- package/core/{sceneMethods.js → scene/sceneMethods.js} +36 -13
- package/core/scene/stepPoses.js +55 -0
- package/core/{targeting.js → scene/targeting.js} +4 -5
- package/core/{thingExplain.js → scene/thingExplain.js} +6 -5
- package/core/{thingOps.js → scene/thingOps.js} +4 -3
- package/core/{things.js → scene/things.js} +18 -5
- package/core/{threePatches.js → scene/threePatches.js} +1 -1
- package/core/{view.js → scene/view.js} +17 -16
- package/core/{Batching.js → stream/Batching.js} +85 -27
- package/core/{Stream.js → stream/Stream.js} +60 -30
- package/core/{batchGroups.js → stream/batchGroups.js} +10 -9
- package/core/{chunkStream.js → stream/chunkStream.js} +40 -0
- package/core/{scatter.js → stream/scatter.js} +2 -2
- package/core/{streamSources.js → stream/streamSources.js} +12 -7
- package/core/{Commits.js → threads/Commits.js} +6 -5
- package/core/{Jobs.js → threads/Jobs.js} +12 -10
- package/core/{Threads.js → threads/Threads.js} +16 -16
- package/core/{threadPure.js → threads/threadPure.js} +7 -5
- package/core/{threadServe.js → threads/threadServe.js} +3 -3
- package/core/{Clock.js → time/Clock.js} +17 -10
- package/core/{dayTime.js → time/dayTime.js} +5 -1
- package/core/{skip.js → time/skip.js} +18 -17
- package/core/{time.js → time/time.js} +18 -12
- package/core/{uiClock.js → time/uiClock.js} +4 -4
- package/docs/AI.md +22 -19
- package/docs/API.md +24 -23
- package/docs/CODEMAP.md +76 -183
- package/docs/COMMANDS.md +66 -58
- package/docs/CONVENTIONS.md +54 -14
- package/docs/MIGRATING-0.8.md +169 -0
- package/docs/THREE.md +78 -29
- package/docs/api/assets.md +12 -13
- package/docs/api/audio.md +6 -5
- package/docs/api/budget.md +4 -4
- package/docs/api/calendar.md +10 -11
- package/docs/api/cameraRig.md +29 -29
- package/docs/api/characters.md +23 -18
- package/docs/api/clock.md +1 -1
- package/docs/api/collision.md +12 -9
- package/docs/api/content.md +6 -6
- package/docs/api/dialogue.md +3 -3
- package/docs/api/engine.md +45 -43
- package/docs/api/events.md +3 -2
- package/docs/api/flow.md +1 -1
- package/docs/api/grids.md +1 -1
- package/docs/api/ground.md +4 -5
- package/docs/api/hud.md +2 -2
- package/docs/api/i18n.md +6 -6
- package/docs/api/input.md +7 -7
- package/docs/api/interactions.md +4 -4
- package/docs/api/inventory.md +9 -9
- package/docs/api/jobs.md +5 -5
- package/docs/api/level.md +7 -7
- package/docs/api/lightPool.md +1 -6
- package/docs/api/music.md +3 -3
- package/docs/api/nav.md +10 -10
- package/docs/api/openWorld.md +1 -1
- package/docs/api/particles.md +2 -2
- package/docs/api/photo.md +4 -2
- package/docs/api/pickups.md +2 -2
- package/docs/api/post.md +20 -3
- package/docs/api/quests.md +3 -3
- package/docs/api/rays.md +5 -7
- package/docs/api/rigid.md +27 -18
- package/docs/api/saves.md +8 -7
- package/docs/api/settings.md +9 -8
- package/docs/api/sky.md +8 -7
- package/docs/api/stream.md +7 -7
- package/docs/api/swarm.md +34 -0
- package/docs/api/terrain.md +7 -8
- package/docs/api/terrainDraw.md +1 -1
- package/docs/api/timeline.md +2 -2
- package/docs/api/tools.md +25 -22
- package/docs/api/vars.md +1 -1
- package/docs/api/vegetation.md +4 -3
- package/docs/api/vegetationDraw.md +1 -1
- package/docs/api/water.md +1 -1
- package/docs/api/weather.md +9 -9
- package/docs/api/weatherDraw.md +3 -3
- package/docs/api/world.md +5 -5
- package/docs/recipes/01-new-game.md +25 -40
- package/docs/recipes/02-npc.md +19 -20
- package/docs/recipes/03-items-pickups.md +27 -43
- package/docs/recipes/04-quests.md +3 -4
- package/docs/recipes/05-props-bake.md +29 -39
- package/docs/recipes/06-clock-events.md +27 -18
- package/docs/recipes/07-flow-scenes-pause.md +12 -17
- package/docs/recipes/08-weather-sky.md +88 -34
- package/docs/recipes/09-materials-lights-models.md +22 -36
- package/docs/recipes/10-blender-level.md +6 -7
- package/docs/recipes/11-vehicles.md +30 -22
- package/docs/recipes/12-navmesh.md +9 -8
- package/docs/recipes/13-animation.md +39 -17
- package/docs/recipes/14-custom-module.md +14 -13
- package/docs/recipes/15-perf.md +49 -26
- package/docs/recipes/16-dev-bridge.md +32 -52
- package/docs/recipes/18-world.md +36 -23
- package/docs/recipes/19-shooting-picking.md +4 -2
- package/docs/recipes/20-content-actions-save.md +30 -35
- package/docs/recipes/21-camera.md +33 -5
- package/docs/recipes/22-shop-gold.md +0 -4
- package/docs/recipes/23-ops.md +10 -10
- package/docs/recipes/26-ui-parts.md +22 -12
- package/docs/recipes/27-net.md +0 -2
- package/docs/recipes/28-terrain.md +117 -21
- package/docs/recipes/29-grid.md +2 -2
- package/docs/recipes/30-templates.md +55 -19
- package/docs/recipes/31-audio.md +5 -5
- package/docs/recipes/32-action-game.md +15 -6
- package/docs/recipes/33-stream-sources.md +2 -2
- package/docs/recipes/34-environment-lighting.md +67 -19
- package/docs/recipes/35-picture-from-reference.md +10 -17
- package/docs/recipes/36-ground-plants.md +105 -0
- package/docs/recipes/40-scene.md +7 -11
- package/docs/recipes/43-shader-patches-surfaces.md +20 -41
- package/docs/recipes/44-water-weather-hooks.md +48 -43
- package/docs/recipes/45-cascaded-shadows.md +39 -17
- package/docs/recipes/46-blender-art-route.md +7 -8
- package/docs/recipes/49-game-module-contract.md +5 -5
- package/docs/recipes/50-own-renderer.md +2 -2
- package/docs/recipes/52-around-the-picture.md +54 -98
- package/docs/recipes/53-ground-up-close.md +61 -24
- package/docs/recipes/55-mods-time-wrap.md +12 -16
- package/docs/recipes/56-webgpu-tsl.md +16 -14
- package/docs/recipes/57-control.md +9 -2
- package/docs/recipes/58-input.md +2 -2
- package/docs/recipes/59-depth-post-effects.md +1 -1
- package/docs/recipes/60-judge-the-picture.md +29 -24
- package/docs/recipes/62-picture-code.md +49 -17
- package/docs/recipes/63-third-person-start.md +17 -4
- package/docs/recipes/64-particles.md +1 -1
- package/docs/recipes/65-swarm.md +140 -0
- package/examples/action/.threedog/content-index.json +1 -1
- package/examples/action/GAMEMAP.md +2 -2
- package/examples/{sheepisland → perf-island}/.threedog/content-index.json +1 -1
- package/examples/{sheepisland → perf-island}/GAMEMAP.md +12 -11
- package/examples/{sheepisland → perf-island}/assets.js +1 -1
- package/examples/{sheepisland → perf-island}/main.js +8 -8
- package/examples/{sheepisland → perf-island}/models.js +1 -1
- package/examples/{sheepisland → perf-island}/params.js +1 -1
- package/examples/{sheepisland → perf-island}/picture/index.js +1 -1
- package/examples/{sheepisland → perf-island}/picture/palette.js +2 -2
- package/examples/{sheepisland → perf-island}/views.js +1 -1
- package/examples/plain-picture/GAMEMAP.md +1 -0
- package/examples/rc2d/GAMEMAP.md +3 -2
- package/examples/rc2d/main.js +1 -3
- package/examples/styletest/.threedog/content-index.json +1 -1
- package/examples/styletest/GAMEMAP.md +3 -2
- package/examples/techniques/contact-shadows/contactShadows.js +1 -1
- package/examples/techniques/contact-shadows/main.js +1 -1
- package/examples/techniques/interior-light/main.js +1 -1
- package/examples/techniques/modular-building/README.md +7 -6
- package/examples/techniques/outlines-and-rim/picture/post.js +1 -1
- package/examples/techniques/procedural-animation/README.md +1 -1
- package/examples/webgpu-tsl/GAMEMAP.md +1 -0
- package/examples/world/.threedog/content-index.json +1 -1
- package/examples/world/GAMEMAP.md +4 -3
- package/examples/world/picture/sky.js +1 -1
- package/index.d.ts +8 -7
- package/index.js +31 -31
- package/llms.txt +9 -13
- package/modules/ambience/Ambience.js +11 -8
- package/modules/calendar/Calendar.js +19 -19
- package/modules/calendar/index.js +13 -13
- package/modules/calendar/schedule.js +11 -6
- package/modules/calendar/seasons.js +7 -7
- package/modules/camera/FirstPersonCamera.js +2 -2
- package/modules/camera/FixedCamera.js +14 -15
- package/modules/camera/FollowCamera.js +4 -4
- package/modules/camera/RtsCamera.js +11 -11
- package/modules/camera/common.js +48 -24
- package/modules/camera/contract.js +1 -0
- package/modules/camera/projection.js +2 -2
- package/modules/characters/Character.js +33 -30
- package/modules/characters/NPC.js +27 -19
- package/modules/characters/assetModel.js +14 -10
- package/modules/characters/astar.js +7 -5
- package/modules/characters/behaviors.js +4 -5
- package/modules/characters/contract.js +2 -2
- package/modules/characters/index.js +168 -214
- package/modules/characters/moveHelpers.js +14 -3
- package/modules/characters/movers/common.js +16 -14
- package/modules/characters/movers/manual.js +1 -1
- package/modules/characters/movers/rapier.js +7 -6
- package/modules/characters/movers/simple.js +3 -3
- package/modules/characters/movers/support.js +8 -8
- package/modules/characters/npcAvoid.js +4 -4
- package/modules/characters/npcSim.js +23 -17
- package/modules/characters/npcView.js +6 -5
- package/modules/characters/pathAsync.js +12 -10
- package/modules/characters/pathWorker.js +1 -1
- package/modules/characters/player.js +108 -0
- package/modules/characters/playerStrings.js +2 -2
- package/modules/characters/proceduralRig.js +2 -2
- package/modules/characters/useModel.js +3 -3
- package/modules/characters/walkTo.js +11 -17
- package/modules/collision/Collision.js +26 -20
- package/modules/collision/contract.js +15 -0
- package/modules/content/explain.js +1 -2
- package/modules/content/fields.js +24 -3
- package/modules/content/ids.js +2 -2
- package/modules/content/index.js +61 -99
- package/modules/content/loader.js +14 -17
- package/modules/content/markers.js +25 -0
- package/modules/content/models.js +10 -7
- package/modules/content/packs.js +3 -3
- package/modules/content/parts.js +2 -2
- package/modules/content/places.js +35 -0
- package/modules/content/props.js +17 -14
- package/modules/content/rules.js +25 -21
- package/modules/content/stages.js +7 -7
- package/modules/content/templates.js +20 -20
- package/modules/content/words.js +34 -0
- package/modules/debug/DebugPanel.js +10 -43
- package/modules/flow/contract.js +1 -1
- package/modules/flow/index.js +11 -7
- package/modules/gameplay/Container.js +12 -11
- package/modules/gameplay/Containers.js +14 -5
- package/modules/gameplay/Dialogue.js +13 -11
- package/modules/gameplay/Interactions.js +37 -24
- package/modules/gameplay/Inventory.js +8 -9
- package/modules/gameplay/Quests.js +16 -9
- package/modules/gameplay/boxOps.js +1 -1
- package/modules/gameplay/dialogueBubbles.js +3 -4
- package/modules/gameplay/inventoryOps.js +0 -1
- package/modules/gameplay/pickups.js +22 -23
- package/modules/gameplay/questSave.js +3 -3
- package/modules/grid/Grid.js +1 -1
- package/modules/grid/Layer.js +4 -4
- package/modules/grid/index.js +7 -8
- package/modules/grid/preview.js +7 -7
- package/modules/grid/tiles.js +6 -6
- package/modules/hlod/index.js +37 -55
- package/modules/hud/index.js +17 -11
- package/modules/hud/parts.js +4 -4
- package/modules/level/contract.js +16 -0
- package/modules/level/heightfield.js +12 -10
- package/modules/level/index.js +47 -152
- package/modules/level/load.js +79 -0
- package/modules/level/meshes.js +65 -0
- package/modules/level/nodes.js +6 -7
- package/modules/lights/index.js +28 -181
- package/modules/lights/slots.js +93 -0
- package/modules/lights/sources.js +88 -0
- package/modules/music/Music.js +30 -26
- package/modules/music/rules.js +1 -1
- package/modules/nav/contract.js +14 -0
- package/modules/nav/index.js +11 -10
- package/modules/net/Client.js +7 -7
- package/modules/net/Host.js +7 -7
- package/modules/net/Net.js +1 -1
- package/modules/net/index.js +5 -4
- package/modules/net/sync.js +2 -2
- package/modules/net/transports.js +2 -2
- package/modules/particles/Particles.js +11 -8
- package/modules/particles/effect.js +7 -5
- package/modules/particles/shaders.js +2 -1
- package/modules/photo/Photo.js +15 -17
- package/modules/rigid/RigidBodies.js +66 -43
- package/modules/rigid/Vehicles.js +2 -3
- package/modules/rigid/ragdoll.js +287 -0
- package/modules/rigid/ragdollBones.js +159 -0
- package/modules/rigid/sync.js +6 -6
- package/modules/settings/Settings.js +108 -39
- package/modules/settings/apply.js +6 -6
- package/modules/settings/sections.js +16 -14
- package/modules/settings/view.js +3 -3
- package/modules/sky/Sky.js +29 -22
- package/modules/sky/clouds.js +7 -7
- package/modules/sky/dome.js +33 -20
- package/modules/sky/domeLayers.js +9 -9
- package/modules/sky/environment.js +6 -6
- package/modules/sky/frame.js +19 -10
- package/modules/sky/season.js +7 -1
- package/modules/sky/shader.js +24 -25
- package/modules/sky/skyModule.js +14 -27
- package/modules/sky/tint.js +1 -1
- package/modules/swarm/Swarm.js +346 -0
- package/modules/swarm/draw.js +68 -0
- package/modules/swarm/grid.js +63 -0
- package/modules/terrain/ChunkManager.js +70 -52
- package/modules/terrain/chunkQueries.js +7 -24
- package/modules/terrain/chunkWorker.js +1 -1
- package/modules/terrain/draw.js +14 -11
- package/modules/terrain/index.js +28 -34
- package/modules/terrain/terrainColorMap.js +6 -3
- package/modules/terrain/terrainDefaults.js +2 -1
- package/modules/terrain/terrainEdit.js +32 -27
- package/modules/terrain/terrainGen.js +17 -12
- package/modules/terrain/terrainIsland.js +2 -2
- package/modules/terrain/terrainMesh.js +7 -6
- package/modules/terrain/terrainShape.js +8 -10
- package/modules/terrain/terrainShapeMain.js +3 -3
- package/modules/timeline/Timeline.js +27 -19
- package/modules/timeline/Tween.js +6 -6
- package/modules/timeline/shots.js +5 -7
- package/modules/triggers/index.js +9 -9
- package/modules/vegetation/Vegetation.js +30 -23
- package/modules/vegetation/densityMap.js +4 -7
- package/modules/vegetation/draw.js +23 -18
- package/modules/vegetation/groundChunks.js +11 -31
- package/modules/vegetation/index.js +8 -6
- package/modules/vegetation/modelGeometry.js +3 -6
- package/modules/vegetation/nearFade.js +1 -1
- package/modules/water/Water.js +16 -16
- package/modules/water/surface.js +3 -3
- package/modules/weather/Weather.js +41 -30
- package/modules/weather/particles.js +8 -8
- package/modules/weather/weatherDraw.js +22 -18
- package/modules/world/World.js +8 -8
- package/modules/world/explain.js +1 -1
- package/modules/world/index.js +18 -12
- package/modules/world/persist.js +73 -25
- package/modules/world/pos.js +4 -4
- package/modules/world/records.js +28 -8
- package/modules/world/sim.js +4 -4
- package/modules/world/state.js +12 -5
- package/modules/world/thingSource.js +4 -2
- package/modules/world/views.js +11 -9
- package/package.json +42 -7
- package/presets.js +1 -3
- package/render/PostFX.js +39 -27
- package/render/backend.js +26 -32
- package/render/cascades.js +17 -12
- package/render/cascades.tsl.js +5 -8
- package/render/daylight.js +20 -3
- package/render/detail.js +8 -7
- package/render/effects.js +28 -25
- package/render/fuse.js +3 -3
- package/render/fx/cloudShadow.tsl.js +3 -3
- package/render/fx/detail.tsl.js +1 -1
- package/render/fx/index.js +5 -10
- package/render/fx/library.tsl.js +11 -0
- package/render/fx/lighting.tsl.js +2 -1
- package/render/fx/nodeErrors.tsl.js +2 -2
- package/render/fx/objectOrigin.tsl.js +1 -2
- package/render/fx/patchNodes.tsl.js +5 -15
- package/render/fx/postWebGPU.tsl.js +27 -23
- package/render/fx/sky.tsl.js +15 -17
- package/render/fx/uniforms.tsl.js +4 -4
- package/render/fx/wind.tsl.js +1 -1
- package/render/fxNumbers.js +3 -0
- package/render/layers.js +1 -1
- package/render/lighting.js +5 -3
- package/render/lightmap.js +20 -20
- package/render/lights.js +6 -6
- package/render/lit.js +24 -0
- package/render/materials.js +8 -7
- package/render/mergeCommon.js +22 -0
- package/render/modeling.js +2 -2
- package/render/occlusion.js +20 -4
- package/render/ownFrame.js +4 -4
- package/render/patches.js +13 -13
- package/render/postWebGL.js +12 -10
- package/render/probes.js +16 -19
- package/render/recordSweep.js +117 -0
- package/render/shaderErrors.js +10 -9
- package/render/shadowCache.tsl.js +107 -0
- package/render/shadowTypes.js +9 -0
- package/{core → render}/shadows.js +57 -11
- package/render/slots.js +7 -7
- package/render/terms.js +22 -24
- package/render/uniformDecl.js +1 -1
- package/types/core.d.ts +200 -153
- package/types/gameplay.d.ts +163 -91
- package/types/generated/core/{Audio.d.ts → audio/Audio.d.ts} +22 -7
- package/types/generated/core/{audioVoice.d.ts → audio/audioVoice.d.ts} +2 -2
- package/types/generated/core/{Events.d.ts → base/Events.d.ts} +4 -4
- package/types/generated/core/{I18n.d.ts → base/I18n.d.ts} +7 -15
- package/types/generated/core/{Random.d.ts → base/Random.d.ts} +4 -3
- package/types/generated/core/{page.d.ts → engine/page.d.ts} +8 -9
- package/types/generated/core/{Input.d.ts → input/Input.d.ts} +12 -8
- package/types/generated/core/{Budget.d.ts → inspect/Budget.d.ts} +36 -26
- package/types/generated/core/{DebugOverrides.d.ts → inspect/DebugOverrides.d.ts} +2 -2
- package/types/generated/core/{Ops.d.ts → ops/Ops.d.ts} +4 -3
- package/types/generated/core/{control.d.ts → ops/control.d.ts} +4 -10
- package/types/generated/core/{Saves.d.ts → saves/Saves.d.ts} +37 -13
- package/types/generated/core/{session.d.ts → saves/session.d.ts} +2 -1
- package/types/generated/core/{Rays.d.ts → scene/Rays.d.ts} +8 -27
- package/types/generated/core/{Views.d.ts → scene/Views.d.ts} +1 -1
- package/types/generated/core/{Batching.d.ts → stream/Batching.d.ts} +7 -7
- package/types/generated/core/{Stream.d.ts → stream/Stream.d.ts} +18 -16
- package/types/generated/core/{Commits.d.ts → threads/Commits.d.ts} +1 -1
- package/types/generated/core/{Jobs.d.ts → threads/Jobs.d.ts} +6 -6
- package/types/generated/core/{Threads.d.ts → threads/Threads.d.ts} +4 -4
- package/types/generated/modules/calendar/Calendar.d.ts +10 -11
- package/types/generated/modules/debug/DebugPanel.d.ts +1 -9
- package/types/generated/modules/grid/Layer.d.ts +1 -1
- package/types/generated/modules/grid/index.d.ts +3 -3
- package/types/generated/modules/music/Music.d.ts +7 -5
- package/types/generated/modules/particles/Particles.d.ts +1 -1
- package/types/generated/modules/sky/Sky.d.ts +21 -10
- package/types/generated/modules/swarm/Swarm.d.ts +80 -0
- package/types/generated/modules/timeline/Timeline.d.ts +2 -1
- package/types/generated/modules/water/Water.d.ts +1 -0
- package/types/generated/modules/weather/Weather.d.ts +16 -12
- package/types/generated/modules/weather/weatherDraw.d.ts +3 -3
- package/types/generated/modules/world/World.d.ts +5 -3
- package/types/generated/render/PostFX.d.ts +17 -11
- package/types/generated/render/materials.d.ts +1 -0
- package/types/generated/render/occlusion.d.ts +9 -0
- package/types/generated/render/patches.d.ts +1 -0
- package/types/generated/ui/Focus.d.ts +1 -0
- package/types/generated/ui/UI.d.ts +1 -0
- package/types/nav.d.ts +11 -11
- package/types/physics.d.ts +99 -70
- package/types/tsl.d.ts +37 -4
- package/types/world.d.ts +38 -71
- package/ui/Focus.js +10 -9
- package/ui/Parts.js +4 -3
- package/ui/UI.js +7 -7
- package/ui/defaults.js +3 -2
- package/ui/theme.js +5 -3
- package/core/assetEntry.js +0 -109
- package/core/holds.js +0 -134
- package/core/shadowTypes.js +0 -16
- package/core/util.js +0 -17
- package/docs/MIGRATING-0.3.md +0 -248
- package/docs/MIGRATING-0.4.md +0 -320
- package/docs/MIGRATING-0.5.md +0 -68
- package/docs/MIGRATING-0.6.md +0 -126
- package/docs/PERF.md +0 -245
- package/docs/recipes/36-sky-ground-plants.md +0 -158
- package/docs/recipes/37-terrain-hooks.md +0 -115
- package/docs/recipes/38-environment-hooks.md +0 -67
- package/docs/recipes/42-terrain-shape.md +0 -64
- package/docs/recipes/47-island-snow-backdrop.md +0 -43
- package/docs/recipes/54-three-idioms.md +0 -88
- package/examples/plain-picture/FINDINGS.md +0 -53
- /package/core/{Vars.js → base/Vars.js} +0 -0
- /package/core/{mulberry32.js → base/mulberry32.js} +0 -0
- /package/core/{inputDefaults.js → input/inputDefaults.js} +0 -0
- /package/core/{textureBytes.js → inspect/textureBytes.js} +0 -0
- /package/core/{actor.js → ops/actor.js} +0 -0
- /package/core/{opsFail.js → ops/opsFail.js} +0 -0
- /package/core/{opsHistory.js → ops/opsHistory.js} +0 -0
- /package/core/{saveIds.js → saves/saveIds.js} +0 -0
- /package/core/{screenToGround.js → scene/screenToGround.js} +0 -0
- /package/core/{tier.js → scene/tier.js} +0 -0
- /package/core/{cells.js → stream/cells.js} +0 -0
- /package/core/{streamCells.js → stream/streamCells.js} +0 -0
- /package/core/{pureWorker.js → threads/pureWorker.js} +0 -0
- /package/examples/{sheepisland → perf-island}/content/index.js +0 -0
- /package/examples/{sheepisland → perf-island}/content/props.js +0 -0
- /package/examples/{sheepisland → perf-island}/content/templates.js +0 -0
- /package/examples/{sheepisland → perf-island}/content/vegetation.js +0 -0
- /package/examples/{sheepisland → perf-island}/picture/lights.js +0 -0
- /package/examples/{sheepisland → perf-island}/picture/materials.js +0 -0
- /package/examples/{sheepisland → perf-island}/picture/sky.js +0 -0
package/render/lighting.js
CHANGED
|
@@ -5,13 +5,15 @@
|
|
|
5
5
|
// follow a toon ramp (a toon ramp is the better tool there); cloud shadows are not "shadow" for shadowTint.
|
|
6
6
|
// All values are uniforms: materials differing only in numbers or colors share one program (the cacheKey holds which features are on).
|
|
7
7
|
import * as THREE from 'three';
|
|
8
|
-
import { readParams, keysSchema
|
|
8
|
+
import { readParams, keysSchema } from '../core/base/params.js';
|
|
9
|
+
import { isOptions } from '../core/base/util.js';
|
|
9
10
|
import { hashText } from './effects.js';
|
|
10
11
|
import { declareUniforms } from './uniformDecl.js';
|
|
11
|
-
import { codedError } from '../core/errorHints.js';
|
|
12
|
+
import { codedError } from '../core/base/errorHints.js';
|
|
13
|
+
import { LUMA } from './fxNumbers.js';
|
|
12
14
|
|
|
13
15
|
const KEYS = ['wrap', 'shadowTint', 'rim', 'glsl', 'uniforms'];
|
|
14
|
-
const lum =
|
|
16
|
+
const lum = `vec3(${LUMA.join(', ')})`;
|
|
15
17
|
|
|
16
18
|
// Callable (#include <threedog_lighting> in your own ShaderMaterial; the patch below calls the same functions, so the math lives once).
|
|
17
19
|
// Plain inputs, no uniforms and no three internals: nl = dot(normal, sunDir), shadow 1 lit / 0 shadowed, viewDir from the surface to the eye.
|
package/render/lightmap.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
// Baked lightmaps: reads the file `threedog bake light` writes and hands plain three.js what it needs. At run time a lightmap is only
|
|
2
|
-
// material.lightMap and a second UV set, so it costs nothing per frame and looks the same on WebGL and WebGPU
|
|
2
|
+
// material.lightMap and a second UV set, so it costs nothing per frame and looks the same on WebGL and WebGPU.
|
|
3
3
|
// Why the file carries geometry and not just a picture: the unwrap cuts seams, so a baked mesh has more vertices than the source. Each entry keeps which
|
|
4
4
|
// source vertex every new vertex came from, and the mesh is rebuilt from that: the game's own attributes stay the game's, only the layout changes.
|
|
5
5
|
// The checks are here because the runtime is where it goes wrong without a word: a mesh that moved keeps light from where it was, a mesh that is not the
|
|
6
6
|
// one baked gets its UVs scrambled, and ambient light the bake already saw adds again.
|
|
7
7
|
import * as THREE from 'three';
|
|
8
|
-
import { readParams } from '../core/params.js';
|
|
9
|
-
import { codedError, coded } from '../core/errorHints.js';
|
|
10
|
-
import { warnOnce } from '../core/validate.js';
|
|
8
|
+
import { readParams } from '../core/base/params.js';
|
|
9
|
+
import { codedError, coded } from '../core/base/errorHints.js';
|
|
10
|
+
import { warnOnce, fmt } from '../core/base/validate.js';
|
|
11
|
+
import { mats, noteFillLight, noteEnvironment } from './lit.js';
|
|
11
12
|
|
|
12
13
|
const FORMAT = 'threedog-lightmap', VERSION = 1, MAGIC = 0x4d4c4454; // 'TDLM'
|
|
13
14
|
const LOAD = { owner: { type: 'string', default: 'game', desc: 'who loaded it (describe().render.lightmap)' } };
|
|
@@ -23,7 +24,7 @@ const STRINGS = {
|
|
|
23
24
|
|
|
24
25
|
/** Split the file into its table and its binary part; every problem is a coded refusal before anything is touched */
|
|
25
26
|
function parse(buf) {
|
|
26
|
-
const bad = why => codedError('lightmap-data', STRINGS.data
|
|
27
|
+
const bad = why => codedError('lightmap-data', fmt(STRINGS.data, { why }));
|
|
27
28
|
if (buf.byteLength < 8 || new DataView(buf).getUint32(0, true) !== MAGIC) throw bad('this is not a lightmap file');
|
|
28
29
|
const n = new DataView(buf).getUint32(4, true);
|
|
29
30
|
if (8 + n > buf.byteLength) throw bad('the file is cut short');
|
|
@@ -34,7 +35,7 @@ function parse(buf) {
|
|
|
34
35
|
if (!Number.isInteger(meta.size) || meta.size < 4 || !Array.isArray(meta.meshes)) throw bad('its table has no size or mesh list');
|
|
35
36
|
const base = (8 + n + 7) & ~7, end = base + meta.size * meta.size * 8; // 8: the half floats and the 32-bit lists after them need aligned views
|
|
36
37
|
if (end > buf.byteLength) throw bad('the file is cut short');
|
|
37
|
-
for (const m of meta.meshes) if (
|
|
38
|
+
for (const m of meta.meshes) if (end + m.at + (m.count * 3 + m.indices) * 4 > buf.byteLength) throw bad(`the data of mesh ${m.name} is cut short`);
|
|
38
39
|
return { meta, base };
|
|
39
40
|
}
|
|
40
41
|
|
|
@@ -54,8 +55,6 @@ function relayout(src, from, index, uv1) {
|
|
|
54
55
|
return g;
|
|
55
56
|
}
|
|
56
57
|
|
|
57
|
-
const mats = o => Array.isArray(o.material) ? o.material : [o.material];
|
|
58
|
-
|
|
59
58
|
/** One lightmap in the scene: three's plain texture on the baked meshes' materials. Made by loadLightmap only */
|
|
60
59
|
class Lightmap {
|
|
61
60
|
constructor(e, meta, texture, owner, file) {
|
|
@@ -66,11 +65,11 @@ class Lightmap {
|
|
|
66
65
|
const moved = [], doubled = [], shared = [], onMapped = new Set();
|
|
67
66
|
for (const [o] of this._entries) for (const m of mats(o)) onMapped.add(m);
|
|
68
67
|
this._e.scene.traverseVisible(o => {
|
|
69
|
-
if (
|
|
70
|
-
|
|
68
|
+
if (noteFillLight(o, doubled)) return;
|
|
69
|
+
if (o.isLightProbeGrid) doubled.push(`probe grid ${o.name}`);
|
|
71
70
|
else if (o.isMesh && !this._entries.has(o) && mats(o).some(m => onMapped.has(m))) shared.push(o.name || `${o.type} ${o.id}`);
|
|
72
71
|
});
|
|
73
|
-
|
|
72
|
+
noteEnvironment(this._e.scene, doubled);
|
|
74
73
|
for (const [o, matrix] of this._entries) {
|
|
75
74
|
o.updateWorldMatrix(true, false);
|
|
76
75
|
if (o.matrixWorld.elements.some((v, i) => Math.abs(v - matrix[i]) > 1e-3)) moved.push(o.name);
|
|
@@ -90,7 +89,7 @@ class Lightmap {
|
|
|
90
89
|
}
|
|
91
90
|
}
|
|
92
91
|
|
|
93
|
-
/** Mixed into Engine.prototype (core/Engine.js) */
|
|
92
|
+
/** Mixed into Engine.prototype (core/engine/Engine.js) */
|
|
94
93
|
export const lightmapMethods = {
|
|
95
94
|
/**
|
|
96
95
|
* Put a baked lightmap on the scene: `threedog bake light` wrote the file from the meshes the game marked `userData.static = true`; this rebuilds each with
|
|
@@ -107,11 +106,11 @@ export const lightmapMethods = {
|
|
|
107
106
|
*/
|
|
108
107
|
async loadLightmap(file, opts) {
|
|
109
108
|
const o = readParams('engine.loadLightmap()', LOAD, opts);
|
|
110
|
-
if (typeof file !== 'string' && !(file instanceof ArrayBuffer)) throw codedError('lightmap-data', STRINGS.file
|
|
109
|
+
if (typeof file !== 'string' && !(file instanceof ArrayBuffer)) throw codedError('lightmap-data', fmt(STRINGS.file, { got: String(file) }));
|
|
111
110
|
let buf = file;
|
|
112
111
|
if (typeof file === 'string') {
|
|
113
112
|
const res = await fetch(file).catch(err => ({ ok: false, statusText: String(err) }));
|
|
114
|
-
if (!res.ok) throw codedError('lightmap-data', STRINGS.fetch
|
|
113
|
+
if (!res.ok) throw codedError('lightmap-data', fmt(STRINGS.fetch, { file, why: res.statusText }));
|
|
115
114
|
buf = await res.arrayBuffer();
|
|
116
115
|
}
|
|
117
116
|
const { meta, base } = parse(/** @type {ArrayBuffer} */ (buf));
|
|
@@ -125,18 +124,19 @@ export const lightmapMethods = {
|
|
|
125
124
|
const mesh = names.get(m.name);
|
|
126
125
|
// the vertex count is what the bake's list was made from: another count means another mesh, and its UVs would be noise
|
|
127
126
|
if (!mesh || mesh.isInstancedMesh || mesh.geometry.attributes.position.count !== m.vertices) { set.missing.push(m.name); continue; }
|
|
128
|
-
const at = binary + m.at;
|
|
129
|
-
mesh.geometry = relayout(
|
|
127
|
+
const at = binary + m.at, old = mesh.geometry;
|
|
128
|
+
mesh.geometry = relayout(old, new Uint32Array(/** @type {ArrayBuffer} */ (buf), at, m.count), new Uint32Array(/** @type {ArrayBuffer} */ (buf), at + m.count * 4, m.indices),
|
|
130
129
|
new Float32Array(/** @type {ArrayBuffer} */ (buf), at + (m.count + m.indices) * 4, m.count * 2));
|
|
130
|
+
old.dispose(); // nothing else frees its GPU buffers; a mesh that shares it just uploads it again
|
|
131
131
|
for (const x of mats(mesh)) { x.lightMap = tex; x.needsUpdate = true; }
|
|
132
132
|
set._entries.set(mesh, m.matrix);
|
|
133
133
|
}
|
|
134
134
|
this._lightmap = set;
|
|
135
135
|
const { moved, doubled, shared } = set._checks(), first = l => l.slice(0, 3).join(', ');
|
|
136
|
-
if (set.missing.length) warnOnce(coded('lightmap-check', STRINGS.missing
|
|
137
|
-
if (moved.length) warnOnce(coded('lightmap-check', STRINGS.moved
|
|
138
|
-
if (doubled.length) warnOnce(coded('lightmap-check', STRINGS.doubled
|
|
139
|
-
if (shared.length) warnOnce(coded('lightmap-check', STRINGS.shared
|
|
136
|
+
if (set.missing.length) warnOnce(coded('lightmap-check', fmt(STRINGS.missing, { n: set.missing.length, names: first(set.missing) })));
|
|
137
|
+
if (moved.length) warnOnce(coded('lightmap-check', fmt(STRINGS.moved, { n: moved.length, names: first(moved) })));
|
|
138
|
+
if (doubled.length) warnOnce(coded('lightmap-check', fmt(STRINGS.doubled, { what: doubled.join(', ') })));
|
|
139
|
+
if (shared.length) warnOnce(coded('lightmap-check', fmt(STRINGS.shared, { names: first(shared) })));
|
|
140
140
|
return set;
|
|
141
141
|
},
|
|
142
142
|
};
|
package/render/lights.js
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
// shows neutral gray instead of black (P5). Nothing moves them with the time of day: the sky only gives signals. A game lights its own world with
|
|
3
3
|
// createEngine({ lights: false }) and its own three.js lights, before engine.start(): a light count that changes during play recompiles shaders
|
|
4
4
|
// (recipes/09 "Lights and stalls", lightPool() for many lights).
|
|
5
|
-
import { engineOwned } from '../core/things.js';
|
|
5
|
+
import { engineOwned } from '../core/scene/things.js';
|
|
6
6
|
import * as THREE from 'three';
|
|
7
|
-
import { defineOwned } from '../core/owned.js';
|
|
7
|
+
import { defineOwned } from '../core/ops/owned.js';
|
|
8
8
|
|
|
9
9
|
const BOX = 30, SNAP = 0.5;
|
|
10
10
|
|
|
@@ -13,7 +13,7 @@ export function createDefaultLights(engine, { add = true } = {}) {
|
|
|
13
13
|
const hemi = new THREE.HemisphereLight(0xffffff, 0x555555, 1.2);
|
|
14
14
|
const sun = new THREE.DirectionalLight(0xffffff, 2);
|
|
15
15
|
sun.position.set(40, 80, 30); // above and to the side, so faces read with some shading
|
|
16
|
-
sun.castShadow = true; // the engine's light casts; whether anything draws shadows is engine.shadows.enabled (
|
|
16
|
+
sun.castShadow = true; // the engine's light casts; whether anything draws shadows is engine.shadows.enabled (render/shadows.js)
|
|
17
17
|
// the one place these defaults live: nothing writes them later, a sky included, so what a game writes on engine.lights.sun stays.
|
|
18
18
|
// baseline shadow box: 2048 map over 60 m around engine.focus (~3 cm texels; 1024 on a low-tier device, a quarter of the fill cost), PCF with a small blur
|
|
19
19
|
// radius = soft edges; bias / normalBias keep acne off flat ground and slopes without visible peter-panning at this texel size. bias is in the shadow
|
|
@@ -24,14 +24,14 @@ export function createDefaultLights(engine, { add = true } = {}) {
|
|
|
24
24
|
sun.shadow.bias = -0.0001; sun.shadow.normalBias = 0.04; sun.shadow.radius = 3;
|
|
25
25
|
// add: false (createEngine({ lights: false })): the objects still exist so engine.lights.sun / hemi and the sky module never hit undefined, but they
|
|
26
26
|
// are not in the scene, so nothing is lit by them and they cost no shader light slots; the game brings all its own lights
|
|
27
|
-
engineOwned('lights', hemi, sun, sun.target); // the module's, not the game's, when the scene adopts what is added (core/things.js)
|
|
27
|
+
engineOwned('lights', hemi, sun, sun.target); // the module's, not the game's, when the scene adopts what is added (core/scene/things.js)
|
|
28
28
|
if (add) engine.scene.add(hemi, sun, sun.target);
|
|
29
29
|
return { sun, hemi };
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
33
|
* Baseline sun follow (no sky module): keep the shadow box around engine.focus, snapped to SNAP m so it only moves in steps (no shimmer while still).
|
|
34
|
-
* Under a sky, or after engine.shadows.box(engine.lights.sun), that box does it (
|
|
34
|
+
* Under a sky, or after engine.shadows.box(engine.lights.sun), that box does it (render/shadows.js). Called before the main render.
|
|
35
35
|
* @param {any} e
|
|
36
36
|
*/
|
|
37
37
|
export function followFocus(e) {
|
|
@@ -43,7 +43,7 @@ export function followFocus(e) {
|
|
|
43
43
|
const held = e._owned?.get('shadow.follow');
|
|
44
44
|
if (held && held !== e._oBaseFollow) return;
|
|
45
45
|
// registered again whenever it is not the current one (a box came and went)
|
|
46
|
-
const o = held
|
|
46
|
+
const o = held ?? (e._oBaseFollow = defineOwned(e, {
|
|
47
47
|
id: 'shadow.follow', part: 'shadow', key: 'follow', read: () => sun.target.position.toArray(), objects: [sun.target, sun.target.position],
|
|
48
48
|
levels: { manual: 'engine.shadows.box(engine.lights.sun, { follow: false })', back: "engine.shadows.box(engine.lights.sun, { follow: 'focus' })" } }));
|
|
49
49
|
if (!o._snap) o.mark();
|
package/render/lit.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// What counts as a lit material, and what adds light a bake already holds: one answer for patches (render/fx/patchNodes.tsl.js), lightmaps and probe sets.
|
|
2
|
+
// cascades.js keeps its own list: it names the materials its GLSL patch can reach, which is a different question.
|
|
3
|
+
|
|
4
|
+
/** Every material of a mesh @param {any} o @returns {any[]} */
|
|
5
|
+
export const mats = o => (Array.isArray(o.material) ? o.material : [o.material]);
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A material that takes light. A classic material has no `lights` flag (that is a ShaderMaterial / NodeMaterial field): the lit classic types are the ones three's node twins light.
|
|
9
|
+
* @param {any} m @returns {boolean}
|
|
10
|
+
*/
|
|
11
|
+
export const lit = m => (m?.isNodeMaterial ? !!m.lights && !m.isMeshBasicNodeMaterial
|
|
12
|
+
: !!(m?.isMeshLambertMaterial || m?.isMeshPhongMaterial || m?.isMeshStandardMaterial || m?.isMeshToonMaterial));
|
|
13
|
+
|
|
14
|
+
/** Is o a fill light? A lit one goes on the `doubled` list, since the bake saw it already @param {any} o @param {string[]} doubled @returns {boolean} */
|
|
15
|
+
export function noteFillLight(o, doubled) {
|
|
16
|
+
if (!(o.isAmbientLight || o.isHemisphereLight || o.isLightProbe)) return false;
|
|
17
|
+
if (o.intensity > 0) doubled.push(`${o.type} ${o.name || o.id}`);
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** The scene's environment light, the same way @param {any} scene @param {string[]} doubled */
|
|
22
|
+
export function noteEnvironment(scene, doubled) {
|
|
23
|
+
if (scene.environment && scene.environmentIntensity > 0) doubled.push('scene.environment');
|
|
24
|
+
}
|
package/render/materials.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Shader effects on plain three.js materials (shadows, fog and tone mapping kept): wind sway, cloud shadows, season tint, ground detail texture,
|
|
2
2
|
// light shaping; plus the terrain's base material and vertex-colored merging. A material's picture is the game's: this file only adds effects to it.
|
|
3
3
|
import * as THREE from 'three';
|
|
4
|
+
import { oneForm } from '../core/base/validate.js';
|
|
4
5
|
import { patchMaterial, sharedPatch } from './patches.js';
|
|
5
6
|
import { declareUniforms } from './uniformDecl.js';
|
|
6
7
|
import { EFFECTS } from './effects.js';
|
|
@@ -8,7 +9,7 @@ import { cloudsPatch, seasonPatch, trackTerms } from './terms.js';
|
|
|
8
9
|
import { detailPatch } from './detail.js';
|
|
9
10
|
import { lightingPatch } from './lighting.js';
|
|
10
11
|
import { neutralMaterial } from './neutral.js';
|
|
11
|
-
import { codedError } from '../core/errorHints.js';
|
|
12
|
+
import { codedError } from '../core/base/errorHints.js';
|
|
12
13
|
/** @import { ColorLike, Material, BufferGeometry } from '../types/common' */
|
|
13
14
|
|
|
14
15
|
// Live engines in creation order: applyEffects called without an engine (a game's module-level code) uses the first one's assets and terms
|
|
@@ -32,8 +33,8 @@ export function windCustom({ glsl, uniforms, tsl }, gpu) {
|
|
|
32
33
|
if (tsl != null && typeof tsl !== 'function') throw codedError('material-option', "wind.tsl is (ctx) => vec3 node: the moved object-space position (ctx.position, ctx.fx.wind, ctx.fx.objectOrigin())");
|
|
33
34
|
if ((glsl != null || tsl == null) && !/void\s+threedogWind\s*\(/.test(glsl || '')) throw codedError('material-option', 'the sway GLSL must define `void threedogWind(inout vec3 transformed, vec3 ip, vec3 position)`: move the vertex (object space) by the sway; ip = world position of this instance, uTime / uWind / uWindFreq / THREEDOG_WIND_AMP are in scope');
|
|
34
35
|
// each renderer draws its own form: the missing one would leave the built-in sway in place without a word
|
|
35
|
-
if (gpu === false && glsl == null) throw
|
|
36
|
-
if (gpu && tsl == null) throw
|
|
36
|
+
if (gpu === false && glsl == null) throw oneForm('material-option', 'wind', false);
|
|
37
|
+
if (gpu && tsl == null) throw oneForm('material-option', 'wind', true);
|
|
37
38
|
return { glsl, tsl, ...declareUniforms('wind.uniforms', uniforms) };
|
|
38
39
|
}
|
|
39
40
|
/**
|
|
@@ -57,7 +58,7 @@ export function windCustom({ glsl, uniforms, tsl }, gpu) {
|
|
|
57
58
|
*/
|
|
58
59
|
export function applyEffects(material, { wind, clouds = true, season, detail, lighting, engine, patches } = {}) {
|
|
59
60
|
const list = [], te = engine ?? ENGINES[0] ?? null;
|
|
60
|
-
// cloud shadow and season tint: the engine's own term, or the one the game put in its place (engine.
|
|
61
|
+
// cloud shadow and season tint: the engine's own term, or the one the game put in its place (engine.shaderTerms,
|
|
61
62
|
// render/terms.js). The material is remembered under its engine, so a replace made later reaches it too.
|
|
62
63
|
const cp = clouds && cloudsPatch(te), sp = season && seasonPatch(te, season);
|
|
63
64
|
if (clouds || season) trackTerms(te, material, { clouds: !!clouds, season: season || null });
|
|
@@ -82,12 +83,12 @@ export function applyEffects(material, { wind, clouds = true, season, detail, li
|
|
|
82
83
|
* @param {{ assets: any }} [engine]
|
|
83
84
|
* @param {{ effects?: boolean, detail?: import('./detail.js').DetailOptions | null }} [o]
|
|
84
85
|
* @returns {Material}
|
|
86
|
+
* @experimental
|
|
85
87
|
*/
|
|
86
88
|
export function terrainMaterial(base = null, engine = undefined, { effects = true, detail = null } = {}) {
|
|
87
89
|
if (base && effects === false) return base;
|
|
88
|
-
const e = engine ?? ENGINES[0], on = detail && ((detail.texture && e?.assets) || detail.noise || detail.glsl);
|
|
89
90
|
return applyEffects(base || neutralMaterial('terrain', { vertexColors: true }),
|
|
90
|
-
{ season: 'ground', engine:
|
|
91
|
+
{ season: 'ground', engine: engine ?? ENGINES[0], ...(detail && { detail }) });
|
|
91
92
|
}
|
|
92
93
|
|
|
93
94
|
/**
|
|
@@ -106,7 +107,7 @@ export function mergeColored(parts, { flat = true } = {}) {
|
|
|
106
107
|
const keepUV = parts.every(([g]) => g.attributes.uv);
|
|
107
108
|
for (const [g0, hex] of parts) {
|
|
108
109
|
if (!flat && !g0.attributes.normal) g0.computeVertexNormals();
|
|
109
|
-
const g = g0.index ? g0.toNonIndexed() : g0;
|
|
110
|
+
const g = g0.index ? g0.toNonIndexed() : flat ? g0.clone() : g0; // flat rewrites normals: never on the caller's geometry
|
|
110
111
|
if (flat) g.computeVertexNormals();
|
|
111
112
|
const c = new THREE.Color(hex), p = g.attributes.position.array, n = g.attributes.normal.array;
|
|
112
113
|
for (let i = 0; i < p.length; i++) { pos.push(p[i]); nor.push(n[i]); }
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// Merge geometries that came from different meshes: hlod proxies, a many-material model made into one vegetation species.
|
|
2
|
+
import { mergeGeometries } from 'three/addons/utils/BufferGeometryUtils.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* One geometry from geometries the caller owns (clones): only the attributes all of them have stay, no morph targets, and an index only if
|
|
6
|
+
* all have one. The inputs are spent: they are changed, then disposed.
|
|
7
|
+
* @param {import('three').BufferGeometry[]} geos @param {boolean} [groups] one group per input
|
|
8
|
+
* @returns {import('three').BufferGeometry}
|
|
9
|
+
*/
|
|
10
|
+
export function mergeCommon(geos, groups = false) {
|
|
11
|
+
const names = Object.keys(geos[0].attributes).filter(n => geos.every(g => g.attributes[n]));
|
|
12
|
+
const indexed = geos.every(g => g.index);
|
|
13
|
+
const ready = geos.map(g => {
|
|
14
|
+
const h = indexed || !g.index ? g : g.toNonIndexed();
|
|
15
|
+
for (const n of Object.keys(h.attributes)) if (!names.includes(n)) h.deleteAttribute(n);
|
|
16
|
+
h.morphAttributes = {};
|
|
17
|
+
return h;
|
|
18
|
+
});
|
|
19
|
+
const out = mergeGeometries(ready, groups);
|
|
20
|
+
for (const g of new Set([...geos, ...ready])) g.dispose();
|
|
21
|
+
return out;
|
|
22
|
+
}
|
package/render/modeling.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// Modeling gaps three lacks. Merging, sweeping, sampling, decals, hulls, simplifying and noise are already in three / three/addons
|
|
2
|
-
// (
|
|
2
|
+
// (THREE.md "Code-built models" lists them), so this file adds nothing of that kind.
|
|
3
3
|
// Every function takes and returns plain three.js objects and has no engine state, so it runs inside an assets.manifest generator (and is then
|
|
4
4
|
// cached / baked with the model) or anywhere else.
|
|
5
5
|
import * as THREE from 'three';
|
|
6
6
|
import { MeshBVH } from 'three-mesh-bvh';
|
|
7
|
-
import { mulberry32 } from '../core/mulberry32.js';
|
|
7
|
+
import { mulberry32 } from '../core/base/mulberry32.js';
|
|
8
8
|
/** @import { BufferGeometry } from '../types/common' */
|
|
9
9
|
|
|
10
10
|
/**
|
package/render/occlusion.js
CHANGED
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
// once the scene is drawn (_sceneDrawn), every display.pass on WebGPU renders without it.
|
|
13
13
|
import * as THREE from 'three';
|
|
14
14
|
import { isWebGPU, onRendererSwap } from './backend.js';
|
|
15
|
-
import { codedError } from '../core/errorHints.js';
|
|
15
|
+
import { codedError } from '../core/base/errorHints.js';
|
|
16
|
+
import { engineOwned } from '../core/scene/things.js';
|
|
16
17
|
import { RESERVED_LAYERS } from './layers.js';
|
|
17
18
|
|
|
18
19
|
const { occlusionHidden: HIDDEN_LAYER, occlusionBox: BOX_LAYER } = RESERVED_LAYERS;
|
|
@@ -20,6 +21,21 @@ const HIDE_AFTER = 2;
|
|
|
20
21
|
const DELAY = 3; // frames between a box being drawn and its result being read, at worst
|
|
21
22
|
const LIGHT_WALK = 60; // frames between looks for new shadow lights
|
|
22
23
|
|
|
24
|
+
/** The mask bit of the batch layer, where a far original waits (hlod, assets.lod); three keeps layer masks unsigned */
|
|
25
|
+
export const FAR_BIT = (1 << RESERVED_LAYERS.batched) >>> 0;
|
|
26
|
+
/** For the raycast slot of an object rays must pass through: a batch, a proxy, an occlusion box */
|
|
27
|
+
export const noRaycast = () => {};
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The mask a mesh goes back to after the engine hid it on one layer. A game's write while hidden stands (hard rule 4): layers.set took the hidden layer
|
|
31
|
+
* away, so the mask is the game's; layers.enable added to it, so the game's bit joins what was there before.
|
|
32
|
+
* @param {number} now the mask now @param {number} bit the hiding layer's bit @param {number} before the mask before hiding @returns {number}
|
|
33
|
+
*/
|
|
34
|
+
export function unhideMask(now, bit, before) {
|
|
35
|
+
if (now === bit) return before;
|
|
36
|
+
return now & bit ? ((now & ~bit) | before) >>> 0 : now;
|
|
37
|
+
}
|
|
38
|
+
|
|
23
39
|
const unitBox = new THREE.BoxGeometry(1, 1, 1);
|
|
24
40
|
const size = new THREE.Vector3(), center = new THREE.Vector3(), here = new THREE.Vector3(), grown = new THREE.Box3();
|
|
25
41
|
const trianglesOf = m => (m.geometry.index?.count ?? m.geometry.attributes.position.count) / 3 * (m.isInstancedMesh ? m.count : 1);
|
|
@@ -46,7 +62,7 @@ export class Occlusion {
|
|
|
46
62
|
this._on = v;
|
|
47
63
|
const cam = this.engine.camera;
|
|
48
64
|
if (v) {
|
|
49
|
-
this._root ??= Object.assign(new THREE.Group(), { name: 'occlusion boxes' });
|
|
65
|
+
this._root ??= engineOwned('occlusion', Object.assign(new THREE.Group(), { name: 'occlusion boxes' }));
|
|
50
66
|
this.engine.scene.add(this._root);
|
|
51
67
|
this._material ??= new THREE.MeshBasicMaterial({ colorWrite: false, depthWrite: false, side: THREE.DoubleSide });
|
|
52
68
|
for (const it of this._items) this._box(it);
|
|
@@ -82,7 +98,7 @@ export class Occlusion {
|
|
|
82
98
|
_box(it) {
|
|
83
99
|
if (!it.read) it.box ??= it.meshes.reduce((b, m) => b.expandByObject(m), new THREE.Box3());
|
|
84
100
|
const p = it.proxy = new THREE.Mesh(unitBox, this._material);
|
|
85
|
-
p.name = 'occlusion box'; p.layers.set(BOX_LAYER); p.renderOrder = Number.MAX_SAFE_INTEGER; p.matrixAutoUpdate = false; p.raycast =
|
|
101
|
+
p.name = 'occlusion box'; p.layers.set(BOX_LAYER); p.renderOrder = Number.MAX_SAFE_INTEGER; p.matrixAutoUpdate = false; p.raycast = noRaycast;
|
|
86
102
|
p.userData.batch = false;
|
|
87
103
|
if (isWebGPU(this.engine.renderer)) {
|
|
88
104
|
p.occlusionTest = true;
|
|
@@ -137,7 +153,7 @@ export class Occlusion {
|
|
|
137
153
|
}
|
|
138
154
|
_show(it) {
|
|
139
155
|
if (!it.hidden) return;
|
|
140
|
-
it.meshes.forEach((m, i) => { m.layers.mask = it.masks[i]; });
|
|
156
|
+
it.meshes.forEach((m, i) => { m.layers.mask = unhideMask(m.layers.mask, 1 << HIDDEN_LAYER, it.masks[i]); });
|
|
141
157
|
it.hidden = false; it.masks = null;
|
|
142
158
|
}
|
|
143
159
|
/** Shadow cameras see HIDDEN_LAYER plus what the view camera sees, the boxes apart. A cascade's own lights hang off its shadow node, not the scene */
|
package/render/ownFrame.js
CHANGED
|
@@ -15,9 +15,9 @@
|
|
|
15
15
|
// untouched), installed again when start() replaces the renderer; listed in threePatches as 'renderer-render'. Hand-back is automatic: an
|
|
16
16
|
// engine frame with no outside canvas draw since the previous one draws again, so deleting the game's own render call is the whole hand-back.
|
|
17
17
|
import { Vector2, Vector4 } from 'three';
|
|
18
|
-
import { warnOnce } from '../core/validate.js';
|
|
19
|
-
import { coded } from '../core/errorHints.js';
|
|
20
|
-
import { notePatch, patchOn } from '../core/threePatches.js';
|
|
18
|
+
import { warnOnce, fmt } from '../core/base/validate.js';
|
|
19
|
+
import { coded } from '../core/base/errorHints.js';
|
|
20
|
+
import { notePatch, patchOn } from '../core/scene/threePatches.js';
|
|
21
21
|
import { onRendererSwap } from './backend.js';
|
|
22
22
|
|
|
23
23
|
const WRAPPED = Symbol.for('threedog.ownFrame');
|
|
@@ -70,7 +70,7 @@ export function engineDraws(engine) {
|
|
|
70
70
|
if (!st) return true;
|
|
71
71
|
const took = st.outside > 0;
|
|
72
72
|
st.outside = 0;
|
|
73
|
-
if (took && !st.yielded) warnOnce(coded('own-frame', STRINGS.took
|
|
73
|
+
if (took && !st.yielded) warnOnce(coded('own-frame', fmt(STRINGS.took, { what: st.what })));
|
|
74
74
|
st.yielded = took;
|
|
75
75
|
return !took;
|
|
76
76
|
}
|
package/render/patches.js
CHANGED
|
@@ -9,11 +9,11 @@
|
|
|
9
9
|
// on a NodeMaterial, and on the node twin WebGPURenderer builds of a classic material (dressNodeTwins below). So one patched MeshLambertMaterial
|
|
10
10
|
// draws with its GLSL on WebGLRenderer and with its tsl on WebGPURenderer: the engine's own materials stay classic, which is what lets
|
|
11
11
|
// fallback: 'webgl' (decided in start(), after they were made) keep them. A patch without tsl throws on a NodeMaterial and is named by
|
|
12
|
-
// start() on WebGPURenderer (render/backend.js webglOnlyOn). Engine uniforms (engine.uniforms: uTime, uWind,
|
|
12
|
+
// start() on WebGPURenderer (render/backend.js webglOnlyOn). Engine uniforms (engine.uniforms: uTime, uWind, uWeatherCloud...) are resolved per
|
|
13
13
|
// renderer when the program compiles, so one material works under any engine and two engines on a page each drive their own time and weather.
|
|
14
14
|
// A patch that moves vertices (shadow: true) owns its shadow: meshes using the material get matching depth and distance
|
|
15
15
|
// materials automatically (see the customDepthMaterial / customDistanceMaterial defaults below), callers never set them.
|
|
16
|
-
// material.clone() does not carry patches (three's Material.copy skips onBeforeCompile):
|
|
16
|
+
// material.clone() does not carry patches (three's Material.copy skips onBeforeCompile): a game applies the effects to the clone again (recipes/09); engine code calls copyPatches(from, to).
|
|
17
17
|
//
|
|
18
18
|
// Composition contract (each part is checked, so a bad combination fails loudly in development instead of rendering wrong):
|
|
19
19
|
// needs.data program inputs the code reads, named like three's program parameters ('instancing', 'instancingColor',
|
|
@@ -28,15 +28,14 @@
|
|
|
28
28
|
// the material's own key + '|threedog:' + name=cacheKey of every patch in order; one name + cacheKey producing
|
|
29
29
|
// two different GLSL texts throws, since those materials would silently share one program.
|
|
30
30
|
import * as THREE from 'three';
|
|
31
|
-
import { closest, DEV, warnOnce } from '../core/validate.js';
|
|
31
|
+
import { closest, DEV, warnOnce } from '../core/base/validate.js';
|
|
32
32
|
import { EFFECTS, PROVIDED_BY } from './effects.js';
|
|
33
|
-
import { noteCopy, VERSION } from '../core/copies.js';
|
|
34
|
-
import { notePatch, patchOn } from '../core/threePatches.js';
|
|
35
|
-
import { sameUniform, resolveUniform } from './engineUniforms.js';
|
|
33
|
+
import { noteCopy, VERSION } from '../core/engine/copies.js';
|
|
34
|
+
import { notePatch, patchOn } from '../core/scene/threePatches.js';
|
|
35
|
+
import { sameUniform, resolveUniform, engineUniformName } from './engineUniforms.js';
|
|
36
36
|
import { SLOTS, SLOT_NAMES, toAnchors } from './slots.js';
|
|
37
|
-
import { codedError, coded } from '../core/errorHints.js';
|
|
37
|
+
import { codedError, coded } from '../core/base/errorHints.js';
|
|
38
38
|
import { webgpuPart, webgpuPartOrNull, addWebGPURule } from './backend.js';
|
|
39
|
-
import { engineUniformName } from './engineUniforms.js';
|
|
40
39
|
import { copyTerms } from './terms.js'; // a cycle (terms.js patches materials); only called at run time, never while loading
|
|
41
40
|
|
|
42
41
|
/** @import { Material } from '../types/common' */
|
|
@@ -309,7 +308,7 @@ function optionsKey(v) {
|
|
|
309
308
|
}
|
|
310
309
|
|
|
311
310
|
/**
|
|
312
|
-
* @internal core/Engine.js, once per WebGPURenderer: the node twin three makes of a classic material (NodeLibrary.fromMaterial, run for each
|
|
311
|
+
* @internal core/engine/Engine.js, once per WebGPURenderer: the node twin three makes of a classic material (NodeLibrary.fromMaterial, run for each
|
|
313
312
|
* program it builds) gets the material's patches as nodes. Why this one call: it is where three turns MeshLambertMaterial into
|
|
314
313
|
* MeshLambertNodeMaterial, copying the plain properties and nothing of onBeforeCompile, so without it every engine material lost wind,
|
|
315
314
|
* season, cloud shadows, detail and lighting on WebGPU without a word. Unpatched twins pass through too: a Lambert / Phong twin gets
|
|
@@ -340,7 +339,7 @@ addWebGPURule(m => {
|
|
|
340
339
|
return list?.length ? webgpuPartOrNull('nodePatches')?.problem(m, list) ?? null : null;
|
|
341
340
|
});
|
|
342
341
|
|
|
343
|
-
/** The TSL side (render/fx/patchNodes.tsl.js registers it when threedog/tsl loads
|
|
342
|
+
/** The TSL side (render/fx/patchNodes.tsl.js registers it when threedog/tsl loads, so this file never imports three/tsl) */
|
|
344
343
|
function nodePatches(m) {
|
|
345
344
|
return webgpuPart('nodePatches', `patches on ${m.type}`);
|
|
346
345
|
}
|
|
@@ -369,6 +368,7 @@ function withProviders(patches, list) {
|
|
|
369
368
|
* Names of the patches on a material (in order), e.g. ['clouds', 'tint', 'wind']
|
|
370
369
|
* @param {Material} material
|
|
371
370
|
* @returns {string[]}
|
|
371
|
+
* @experimental
|
|
372
372
|
*/
|
|
373
373
|
export function materialPatches(material) { return (LISTS.get(material) || []).map(p => p.name); }
|
|
374
374
|
|
|
@@ -423,7 +423,7 @@ export function patchesOf(material) { return [...(LISTS.get(material) ?? [])]; }
|
|
|
423
423
|
|
|
424
424
|
/**
|
|
425
425
|
* Take the patch named `name` off a material (no-op when absent); returns the material.
|
|
426
|
-
* @internal
|
|
426
|
+
* @internal cascades, shader terms, and the modules that swap one patch
|
|
427
427
|
* @param {Material} material
|
|
428
428
|
* @param {string} name
|
|
429
429
|
* @returns {Material}
|
|
@@ -448,7 +448,7 @@ export function unpatchMaterial(material, name) {
|
|
|
448
448
|
export function copyPatches(from, to) {
|
|
449
449
|
const list = LISTS.get(from);
|
|
450
450
|
if (!list?.length || from === to) return to;
|
|
451
|
-
copyTerms(from, to); // the copy carries the cloud / season terms, so a later engine.
|
|
451
|
+
copyTerms(from, to); // the copy carries the cloud / season terms, so a later engine.shaderTerms call reaches it too
|
|
452
452
|
deriving = true; // already checked on `from`
|
|
453
453
|
try { return patchMaterial(to, list, { strict: false }); } finally { deriving = false; }
|
|
454
454
|
}
|
|
@@ -506,7 +506,7 @@ function shadowMaterial(material, kind) {
|
|
|
506
506
|
// on Mesh.prototype before any mesh exists (Object3D's constructor assigns both, which would otherwise make own properties).
|
|
507
507
|
// Explicit values live under a global symbol, so a second copy of this file (hot reload) redefining the accessor loses none.
|
|
508
508
|
// A second copy of the ENGINE (another path) still breaks the first copy's moving shadows (its shadowMaterial is no longer the one
|
|
509
|
-
// asked), so noteCopy says so once, with both paths and how to dedupe (core/copies.js).
|
|
509
|
+
// asked), so noteCopy says so once, with both paths and how to dedupe (core/engine/copies.js).
|
|
510
510
|
{ const w = noteCopy({ version: VERSION, url: import.meta.url }); if (w) warnOnce(w); }
|
|
511
511
|
{
|
|
512
512
|
/** @type {[string, PropertyDescriptor | undefined][]} */
|
package/render/postWebGL.js
CHANGED
|
@@ -14,9 +14,9 @@ import { EffectComposer } from 'three/addons/postprocessing/EffectComposer.js';
|
|
|
14
14
|
import { RenderPass } from 'three/addons/postprocessing/RenderPass.js';
|
|
15
15
|
import { OutputPass } from 'three/addons/postprocessing/OutputPass.js';
|
|
16
16
|
import { FusedPass, groupFuse, checkDepthOrder } from './fuse.js';
|
|
17
|
-
import { codedError } from '../core/errorHints.js';
|
|
18
|
-
import { holdShadowRedraw } from './backend.js';
|
|
19
|
-
import { notePatch, patchOn } from '../core/threePatches.js';
|
|
17
|
+
import { codedError } from '../core/base/errorHints.js';
|
|
18
|
+
import { holdShadowRedraw, MSAA_SAMPLES } from './backend.js';
|
|
19
|
+
import { notePatch, patchOn } from '../core/scene/threePatches.js';
|
|
20
20
|
|
|
21
21
|
// One FusedPass per group of neighboring fuse effects, kept while the same effects stay grouped (a changed group recompiles once)
|
|
22
22
|
function fuseEntry(post, group, used) {
|
|
@@ -28,7 +28,7 @@ function fuseEntry(post, group, used) {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
// Shadow maps once a frame. three redraws every shadow map in each renderer.render() while shadowMap.autoUpdate is on, and effects that render the
|
|
31
|
-
// scene again for their own buffers (ao's normals, outline's
|
|
31
|
+
// scene again for their own buffers (ao's normals, outline's normals and mask) did so a second time: measured 2 redraws a frame with ao on, 5-20 % frame
|
|
32
32
|
// time (tests/specs/shadow-passes.mjs). So the pass that draws the scene (index 0 of the chain) turns redraws off once it has drawn, and
|
|
33
33
|
// render() puts the switch back after the whole chain. Why after the scene pass and not before the chain: that pass is the one whose
|
|
34
34
|
// shadows the picture shows, and it also uses up a requested redraw (needsUpdate, sky's shadow.updateEvery), so "every N frames" still works.
|
|
@@ -42,6 +42,7 @@ function holdAfterScene(post, pass) {
|
|
|
42
42
|
const render = pass.render;
|
|
43
43
|
pass.render = function (...a) {
|
|
44
44
|
const out = render.apply(this, a);
|
|
45
|
+
post.engine.occlusion?._sceneDrawn(); // whichever pass drew the scene: the later passes must not see occlusion's boxes
|
|
45
46
|
if (post._shadowRelease === null && patchOn('post-shadow-hold')) post._shadowRelease = holdShadowRedraw(post.engine.renderer, post.engine.scene);
|
|
46
47
|
return out;
|
|
47
48
|
};
|
|
@@ -115,23 +116,21 @@ export const webglPost = {
|
|
|
115
116
|
},
|
|
116
117
|
/** a fuse effect's params changed: its fused pass re-reads the values (uniforms, no recompile) */
|
|
117
118
|
refresh(post) { for (const p of post._fused.values()) p.refresh(); },
|
|
118
|
-
samples: post => (post.active ? post.composer?.renderTarget1.samples ?? (post._aa ?
|
|
119
|
+
samples: post => (post.active ? post.composer?.renderTarget1.samples ?? (post._aa ? MSAA_SAMPLES : 0) : post._ownAA ? MSAA_SAMPLES : 0),
|
|
119
120
|
setAntialias(post, on) {
|
|
120
|
-
if (post.composer) for (const rt of [post.composer.renderTarget1, post.composer.renderTarget2]) { rt.samples = on ?
|
|
121
|
+
if (post.composer) for (const rt of [post.composer.renderTarget1, post.composer.renderTarget2]) { rt.samples = on ? MSAA_SAMPLES : 0; rt.dispose(); }
|
|
121
122
|
},
|
|
122
123
|
// Rebuild the pass chain from the list: scene (or the default RenderPass) -> hdr -> tone (or the default OutputPass) -> ldr -> final.
|
|
123
124
|
// Only enabled effects are in the chain; an implementation is built the first time its effect is on and kept after.
|
|
124
125
|
sync(post) {
|
|
125
126
|
const { renderer, scene, camera } = post.engine, size = post._size();
|
|
126
127
|
if (!post.composer) {
|
|
127
|
-
const rt = new THREE.WebGLRenderTarget(size.x, size.y, { type: THREE.HalfFloatType, samples: post._aa ?
|
|
128
|
+
const rt = new THREE.WebGLRenderTarget(size.x, size.y, { type: THREE.HalfFloatType, samples: post._aa ? MSAA_SAMPLES : 0 });
|
|
128
129
|
post.composer = new EffectComposer(renderer, rt);
|
|
129
130
|
// EffectComposer takes a given target's size (device pixels) as its CSS size; reset it so setPixelRatio does not scale twice
|
|
130
131
|
const css = renderer.getSize(new THREE.Vector2());
|
|
131
132
|
post.composer.setSize(css.x, css.y);
|
|
132
133
|
post._scenePass = new RenderPass(scene, camera);
|
|
133
|
-
const drawScene = post._scenePass.render.bind(post._scenePass);
|
|
134
|
-
post._scenePass.render = (...a) => { drawScene(...a); post.engine.occlusion?._sceneDrawn(); };
|
|
135
134
|
post._output = new OutputPass();
|
|
136
135
|
}
|
|
137
136
|
const c = post.composer, on = post._sorted().filter(e => e.enabled);
|
|
@@ -151,6 +150,8 @@ export const webglPost = {
|
|
|
151
150
|
c.passes = named.map(e => e._impl);
|
|
152
151
|
holdAfterScene(post, c.passes[0]);
|
|
153
152
|
for (const p of c.passes) p.setSize(size.x, size.y);
|
|
153
|
+
// nothing on and the canvas's own MSAA in use: the frame draws straight to the canvas, so the targets give their memory back (over 200 MB at 1080p with MSAA); three allocates them again on the next use
|
|
154
|
+
if (!post.active) for (const rt of [c.renderTarget1, c.renderTarget2]) rt.dispose();
|
|
154
155
|
},
|
|
155
156
|
dispose(post) {
|
|
156
157
|
for (const p of post._fused.values()) p.dispose();
|
|
@@ -193,7 +194,8 @@ export const webglPost = {
|
|
|
193
194
|
if (r.toneMapping !== THREE.NoToneMapping && bg?.isTexture && THREE.ColorManagement.getTransfer(bg.colorSpace) === THREE.SRGBTransfer) {
|
|
194
195
|
toneBackground(post, () => r.render(s, camera)); return;
|
|
195
196
|
}
|
|
196
|
-
|
|
197
|
+
// a Color background only while three's clear would paint it: with autoClear off three still clears for a Color, depth too, which the quad would not
|
|
198
|
+
const col = bg?.isColor ? (r.autoClear && r.autoClearColor ? bg : null) : bg == null ? post._clearColor() : null;
|
|
197
199
|
if (!col || r.toneMapping === THREE.NoToneMapping) { r.render(s, camera); return; }
|
|
198
200
|
const t = post._bgTex ??= Object.assign(new THREE.DataTexture(new Float32Array(4), 1, 1, THREE.RGBAFormat, THREE.FloatType), { colorSpace: THREE.LinearSRGBColorSpace });
|
|
199
201
|
const d = t.image.data;
|