threedog 0.7.0 → 1.0.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 +411 -1
- package/README.md +8 -11
- package/core/{Animator.js → assets/Animator.js} +30 -18
- package/core/{Assets.js → assets/Assets.js} +131 -56
- package/core/{Baked.js → assets/Baked.js} +4 -4
- package/core/assets/assetEntry.js +302 -0
- package/core/{assetHot.js → assets/assetHot.js} +9 -7
- 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} +7 -14
- package/core/{namedModel.js → assets/namedModel.js} +17 -13
- package/core/{Audio.js → audio/Audio.js} +47 -25
- 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} +15 -12
- package/core/{Random.js → base/Random.js} +7 -4
- package/core/{Vars.js → base/Vars.js} +14 -4
- package/core/{easing.js → base/easing.js} +1 -1
- package/core/{errorCodes.js → base/errorCodes.js} +151 -125
- package/core/{errorHints.js → base/errorHints.js} +17 -10
- package/core/{errors.js → base/errors.js} +12 -10
- package/core/{events.generated.js → base/events.generated.js} +11 -0
- package/core/base/follows.js +26 -0
- package/core/base/math.js +66 -0
- package/core/{params.js → base/params.js} +5 -6
- package/core/base/saveValues.js +81 -0
- package/core/base/sections.js +97 -0
- package/core/base/spelling.js +32 -0
- package/core/base/util.js +32 -0
- package/core/{validate.js → base/validate.js} +34 -34
- package/core/{Engine.js → engine/Engine.js} +137 -91
- package/core/{Loading.js → engine/Loading.js} +34 -5
- package/core/{copies.js → engine/copies.js} +4 -4
- package/core/{headlessLoad.js → engine/headlessLoad.js} +32 -15
- package/core/{lifecycle.js → engine/lifecycle.js} +41 -34
- package/core/{loop.js → engine/loop.js} +88 -49
- package/core/engine/moduleSlots.js +176 -0
- package/core/{moduleTypes.js → engine/moduleTypes.js} +26 -14
- package/core/engine/modules.js +503 -0
- package/core/{page.js → engine/page.js} +59 -29
- package/core/{plugins.js → engine/plugins.js} +21 -12
- package/core/{services.js → engine/services.js} +50 -40
- package/core/{startup.js → engine/startup.js} +66 -54
- package/core/{Input.js → input/Input.js} +67 -39
- package/core/{inputContext.js → input/inputContext.js} +14 -5
- package/core/input/inputKeyboard.js +39 -0
- package/core/{inputPad.js → input/inputPad.js} +24 -3
- package/core/{inputPointer.js → input/inputPointer.js} +11 -3
- package/core/input/inputSeat.js +66 -0
- package/core/{inputTouch.js → input/inputTouch.js} +24 -7
- package/core/{Budget.js → inspect/Budget.js} +21 -20
- package/core/{DebugOverrides.js → inspect/DebugOverrides.js} +43 -18
- package/core/{Describe.js → inspect/Describe.js} +34 -26
- package/core/{Inspect.js → inspect/Inspect.js} +39 -10
- 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} +60 -24
- package/core/{catalog.js → inspect/catalog.js} +15 -8
- 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} +24 -22
- package/core/{describeText.js → inspect/describeText.js} +17 -8
- package/core/inspect/geometryWatch.js +38 -0
- package/core/{lightWatch.js → inspect/lightWatch.js} +8 -8
- package/core/inspect/metadata.generated.js +4140 -0
- package/core/{pictureWriters.js → inspect/pictureWriters.js} +130 -47
- package/core/{shaderCost.js → inspect/shaderCost.js} +1 -1
- package/core/inspect/toolDoor.js +21 -0
- package/core/inspect/valueHistory.js +35 -0
- package/core/{Ops.js → ops/Ops.js} +44 -14
- package/core/{control.js → ops/control.js} +57 -31
- package/core/ops/holds.js +140 -0
- package/core/{opsAtomic.js → ops/opsAtomic.js} +18 -5
- package/core/{opsCheck.js → ops/opsCheck.js} +11 -10
- package/core/{opsFail.js → ops/opsFail.js} +5 -7
- package/core/{opsGuard.js → ops/opsGuard.js} +3 -3
- package/core/{opsRun.js → ops/opsRun.js} +9 -6
- package/core/{owned.js → ops/owned.js} +33 -19
- package/core/{sharedPoint.js → ops/sharedPoint.js} +13 -16
- package/core/{stackFrames.js → ops/stackFrames.js} +2 -2
- package/core/{stacks.js → ops/stacks.js} +34 -15
- package/core/{wrap.js → ops/wrap.js} +8 -6
- package/core/{SaveStore.js → saves/SaveStore.js} +53 -27
- package/core/{Saves.js → saves/Saves.js} +171 -54
- package/core/saves/saveApply.js +312 -0
- package/core/{saveFiles.js → saves/saveFiles.js} +45 -38
- package/core/{saveVersions.js → saves/saveVersions.js} +24 -23
- package/core/saves/session.js +231 -0
- package/core/saves/stateReplace.js +184 -0
- package/core/{Rays.js → scene/Rays.js} +44 -30
- package/core/{Views.js → scene/Views.js} +16 -8
- package/core/{adaptive.js → scene/adaptive.js} +19 -9
- package/core/{canvasBox.js → scene/canvasBox.js} +4 -3
- package/core/scene/compositeGround.js +72 -0
- package/core/scene/floor.js +17 -0
- 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} +6 -4
- package/core/{gridLoad.js → scene/gridLoad.js} +1 -1
- package/core/scene/ground.contract.js +14 -0
- package/core/scene/ground.js +139 -0
- package/core/{movement.js → scene/movement.js} +3 -3
- package/core/{pictureSlots.js → scene/pictureSlots.js} +2 -2
- package/core/scene/pixel.js +154 -0
- package/core/scene/pixelRatio.js +167 -0
- package/core/{sceneDelta.js → scene/sceneDelta.js} +5 -5
- package/core/{sceneMethods.js → scene/sceneMethods.js} +43 -15
- package/core/scene/stepPoses.js +60 -0
- package/core/{targeting.js → scene/targeting.js} +4 -5
- package/core/{thingExplain.js → scene/thingExplain.js} +7 -6
- package/core/{thingOps.js → scene/thingOps.js} +25 -16
- package/core/{things.js → scene/things.js} +18 -5
- package/core/{threePatches.js → scene/threePatches.js} +1 -1
- package/core/{tier.js → scene/tier.js} +10 -0
- package/core/scene/view.js +161 -0
- package/core/{Batching.js → stream/Batching.js} +85 -28
- package/core/{Stream.js → stream/Stream.js} +80 -38
- package/core/{batchGroups.js → stream/batchGroups.js} +11 -9
- package/core/{chunkStream.js → stream/chunkStream.js} +40 -0
- package/core/{scatter.js → stream/scatter.js} +7 -4
- package/core/{streamSources.js → stream/streamSources.js} +14 -8
- package/core/{Commits.js → threads/Commits.js} +17 -11
- package/core/{Jobs.js → threads/Jobs.js} +25 -13
- package/core/{Threads.js → threads/Threads.js} +21 -18
- 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} +20 -11
- package/core/{dayTime.js → time/dayTime.js} +5 -1
- package/core/{skip.js → time/skip.js} +28 -21
- package/core/{time.js → time/time.js} +32 -20
- package/core/{uiClock.js → time/uiClock.js} +4 -4
- package/docs/AI.md +92 -72
- package/docs/API.md +33 -28
- package/docs/CODEMAP.md +121 -200
- package/docs/COMMANDS.md +77 -70
- package/docs/CONVENTIONS.md +167 -24
- package/docs/MIGRATING-0.8.md +171 -0
- package/docs/MIGRATING-1.0.md +101 -0
- package/docs/THREE.md +140 -38
- 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 +32 -29
- package/docs/api/characters.md +35 -24
- package/docs/api/clock.md +1 -1
- package/docs/api/collider3d.md +9 -0
- package/docs/api/collision.md +12 -9
- package/docs/api/content.md +18 -17
- package/docs/api/dialogue.md +5 -4
- package/docs/api/engine.md +58 -54
- package/docs/api/events.md +17 -6
- package/docs/api/flow.md +1 -1
- package/docs/api/grids.md +1 -1
- package/docs/api/ground.md +6 -7
- package/docs/api/hud.md +2 -2
- package/docs/api/i18n.md +6 -6
- package/docs/api/input.md +9 -8
- package/docs/api/interactions.md +5 -5
- package/docs/api/inventory.md +10 -10
- package/docs/api/jobs.md +5 -5
- package/docs/api/level.md +10 -9
- package/docs/api/lightPool.md +1 -6
- package/docs/api/music.md +3 -3
- package/docs/api/nav.md +14 -12
- package/docs/api/openWorld.md +1 -1
- package/docs/api/particles.md +10 -7
- package/docs/api/photo.md +4 -2
- package/docs/api/pickups.md +3 -3
- package/docs/api/post.md +21 -5
- package/docs/api/quests.md +7 -5
- package/docs/api/rays.md +7 -7
- package/docs/api/rigid.md +29 -19
- package/docs/api/saves.md +13 -11
- package/docs/api/settings.md +9 -8
- package/docs/api/sky.md +8 -7
- package/docs/api/stream.md +8 -9
- package/docs/api/swarm.md +34 -0
- package/docs/api/terrain.md +6 -8
- package/docs/api/terrainDraw.md +2 -2
- package/docs/api/timeline.md +4 -4
- package/docs/api/tools.md +27 -22
- package/docs/api/triggers.md +2 -0
- package/docs/api/vars.md +1 -1
- package/docs/api/vegetation.md +4 -3
- package/docs/api/vegetationDraw.md +2 -2
- package/docs/api/water.md +7 -3
- package/docs/api/weather.md +27 -12
- package/docs/api/weatherDraw.md +4 -4
- package/docs/api/world.md +6 -6
- package/docs/recipes/01-new-game.md +28 -43
- package/docs/recipes/02-npc.md +21 -23
- package/docs/recipes/03-items-pickups.md +37 -53
- package/docs/recipes/04-quests.md +5 -4
- package/docs/recipes/05-props-bake.md +34 -44
- package/docs/recipes/06-clock-events.md +31 -22
- package/docs/recipes/07-flow-scenes-pause.md +30 -32
- package/docs/recipes/08-weather-sky.md +91 -37
- package/docs/recipes/09-materials-lights-models.md +25 -39
- package/docs/recipes/10-blender-level.md +22 -11
- package/docs/recipes/11-vehicles.md +44 -24
- package/docs/recipes/12-navmesh.md +60 -15
- package/docs/recipes/13-animation.md +70 -22
- package/docs/recipes/14-custom-module.md +33 -20
- package/docs/recipes/15-perf.md +51 -28
- package/docs/recipes/16-dev-bridge.md +39 -58
- package/docs/recipes/18-world.md +49 -28
- package/docs/recipes/19-shooting-picking.md +7 -4
- package/docs/recipes/20-content-actions-save.md +55 -40
- package/docs/recipes/21-camera.md +47 -25
- package/docs/recipes/22-shop-gold.md +21 -16
- package/docs/recipes/23-ops.md +28 -24
- package/docs/recipes/26-ui-parts.md +25 -14
- package/docs/recipes/27-net.md +3 -5
- package/docs/recipes/28-terrain.md +119 -23
- package/docs/recipes/29-grid.md +3 -3
- package/docs/recipes/30-templates.md +63 -30
- package/docs/recipes/31-audio.md +7 -7
- package/docs/recipes/32-action-game.md +21 -11
- package/docs/recipes/33-stream-sources.md +6 -3
- package/docs/recipes/34-environment-lighting.md +72 -25
- package/docs/recipes/35-picture-from-reference.md +20 -23
- package/docs/recipes/36-ground-plants.md +106 -0
- package/docs/recipes/40-scene.md +18 -21
- package/docs/recipes/43-shader-patches-surfaces.md +27 -48
- package/docs/recipes/44-water-weather-hooks.md +56 -50
- package/docs/recipes/45-cascaded-shadows.md +41 -20
- package/docs/recipes/46-blender-art-route.md +9 -10
- package/docs/recipes/49-game-module-contract.md +7 -6
- package/docs/recipes/50-own-renderer.md +3 -2
- package/docs/recipes/51-capability-catalog.md +14 -8
- package/docs/recipes/52-around-the-picture.md +56 -100
- package/docs/recipes/53-ground-up-close.md +61 -24
- package/docs/recipes/55-mods-time-wrap.md +17 -20
- package/docs/recipes/56-webgpu-tsl.md +28 -15
- package/docs/recipes/57-control.md +39 -12
- package/docs/recipes/58-input.md +15 -2
- package/docs/recipes/59-depth-post-effects.md +1 -1
- package/docs/recipes/60-judge-the-picture.md +30 -25
- package/docs/recipes/62-picture-code.md +129 -39
- package/docs/recipes/63-third-person-start.md +19 -5
- package/docs/recipes/64-particles.md +54 -5
- package/docs/recipes/65-swarm.md +140 -0
- package/docs/recipes/66-common-tasks.md +313 -0
- package/examples/action/.threedog/content-index.json +1 -1
- package/examples/action/GAMEMAP.md +5 -5
- package/examples/perf-island/.threedog/content-index.json +1 -0
- package/examples/{sheepisland → perf-island}/GAMEMAP.md +15 -14
- 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 +4 -1
- package/examples/rc2d/GAMEMAP.md +4 -3
- package/examples/rc2d/main.js +1 -3
- package/examples/rc2d/rc2d.js +1 -1
- package/examples/styletest/.threedog/content-index.json +1 -1
- package/examples/styletest/GAMEMAP.md +6 -5
- 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 +2 -1
- package/examples/world/.threedog/content-index.json +1 -1
- package/examples/world/GAMEMAP.md +9 -7
- package/examples/world/main.js +3 -3
- package/examples/world/picture/sky.js +1 -1
- package/index.d.ts +16 -12
- package/index.js +53 -32
- package/llms.txt +11 -14
- package/modules/ambience/Ambience.js +16 -11
- package/modules/calendar/Calendar.js +19 -19
- package/modules/calendar/index.js +18 -16
- package/modules/calendar/schedule.js +11 -6
- package/modules/calendar/seasons.js +7 -7
- package/modules/camera/FirstPersonCamera.js +5 -5
- package/modules/camera/FixedCamera.js +43 -30
- package/modules/camera/FollowCamera.js +24 -15
- package/modules/camera/RtsCamera.js +12 -11
- package/modules/camera/common.js +72 -37
- package/modules/camera/contract.js +1 -0
- package/modules/camera/pixelSnap.js +62 -0
- package/modules/characters/Character.js +166 -70
- package/modules/characters/NPC.js +84 -44
- package/modules/characters/assetModel.js +16 -12
- package/modules/characters/astar.js +48 -27
- package/modules/characters/behaviors.js +4 -5
- package/modules/characters/character.contract.js +21 -0
- package/modules/characters/contract.js +17 -3
- package/modules/characters/index.js +240 -226
- package/modules/characters/moveHelpers.js +88 -12
- package/modules/characters/mover.contract.js +14 -0
- package/modules/characters/movers/common.js +22 -18
- package/modules/characters/movers/manual.js +1 -1
- package/modules/characters/movers/rapier.js +18 -10
- package/modules/characters/movers/simple.js +26 -13
- package/modules/characters/movers/support.js +24 -13
- package/modules/characters/npcAvoid.js +19 -16
- package/modules/characters/npcSim.js +88 -32
- package/modules/characters/npcView.js +19 -11
- package/modules/characters/pathAsync.js +81 -29
- package/modules/characters/pathJob.js +38 -21
- package/modules/characters/pathWorker.js +1 -1
- package/modules/characters/player.js +120 -0
- package/modules/characters/playerStrings.js +2 -2
- package/modules/characters/proceduralRig.js +2 -2
- package/modules/characters/seat.js +56 -0
- package/modules/characters/useModel.js +3 -3
- package/modules/characters/vehicle.contract.js +8 -5
- package/modules/characters/walkTo.js +40 -33
- package/modules/collision/Collision.js +69 -45
- package/modules/collision/contract.js +15 -0
- package/modules/collision/grid.js +6 -1
- package/modules/content/explain.js +2 -3
- package/modules/content/fields.js +24 -3
- package/modules/content/ids.js +5 -3
- package/modules/content/index.js +132 -114
- package/modules/content/loader.js +117 -140
- package/modules/content/markers.js +25 -0
- package/modules/content/models.js +54 -17
- package/modules/content/packs.js +5 -4
- package/modules/content/parts.js +2 -2
- package/modules/content/places.js +36 -0
- package/modules/content/props.js +22 -17
- package/modules/content/rules.js +47 -61
- package/modules/content/stages.js +7 -7
- package/modules/content/templates.js +80 -49
- package/modules/content/words.js +47 -0
- package/modules/debug/DebugPanel.js +14 -45
- package/modules/flow/contract.js +2 -1
- package/modules/flow/index.js +30 -16
- package/modules/gameplay/Container.js +17 -13
- package/modules/gameplay/Containers.js +23 -6
- package/modules/gameplay/Dialogue.js +93 -34
- package/modules/gameplay/Interactions.js +93 -51
- package/modules/gameplay/Inventory.js +64 -22
- package/modules/gameplay/Quests.js +146 -30
- package/modules/gameplay/boxOps.js +8 -1
- package/modules/gameplay/dialogueBubbles.js +16 -12
- package/modules/gameplay/inventoryOps.js +11 -8
- package/modules/gameplay/pickups.js +63 -37
- package/modules/gameplay/questLog.js +4 -2
- package/modules/gameplay/questSave.js +9 -4
- package/modules/gameplay/quests.contract.js +1 -1
- package/modules/grid/Grid.js +2 -2
- package/modules/grid/Layer.js +12 -8
- package/modules/grid/index.js +28 -23
- package/modules/grid/ops.js +43 -46
- package/modules/grid/preview.js +7 -7
- package/modules/grid/tiles.js +6 -6
- package/modules/hlod/index.js +42 -57
- package/modules/hud/index.js +22 -14
- package/modules/hud/parts.js +8 -8
- package/modules/level/contract.js +16 -0
- package/modules/level/heightfield.js +29 -31
- package/modules/level/index.js +113 -161
- package/modules/level/load.js +196 -0
- package/modules/level/meshes.js +65 -0
- package/modules/level/nodes.js +40 -23
- package/modules/lights/index.js +33 -183
- package/modules/lights/slots.js +93 -0
- package/modules/lights/sources.js +90 -0
- package/modules/music/Music.js +34 -28
- package/modules/music/rules.js +1 -1
- package/modules/nav/contract.js +16 -0
- package/modules/nav/index.js +180 -49
- package/modules/nav/navPath.js +45 -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 +6 -5
- package/modules/net/sync.js +2 -2
- package/modules/net/transports.js +2 -2
- package/modules/particles/Particles.js +95 -29
- package/modules/particles/effect.js +86 -32
- package/modules/particles/shaders.js +19 -1
- package/modules/photo/Photo.js +23 -23
- package/modules/rigid/RigidBodies.js +255 -89
- package/modules/rigid/Vehicles.js +17 -8
- package/modules/rigid/collider3d.contract.js +26 -0
- package/modules/rigid/ragdoll.js +298 -0
- package/modules/rigid/ragdollBones.js +209 -0
- package/modules/rigid/refresh.js +10 -0
- package/modules/rigid/sync.js +51 -20
- package/modules/settings/Settings.js +177 -61
- package/modules/settings/apply.js +20 -13
- package/modules/settings/sections.js +19 -14
- package/modules/settings/strings.js +2 -2
- 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 +17 -28
- package/modules/sky/tint.js +1 -1
- package/modules/swarm/Swarm.js +356 -0
- package/modules/swarm/draw.js +68 -0
- package/modules/swarm/grid.js +63 -0
- package/modules/terrain/ChunkManager.js +71 -59
- 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 +42 -42
- package/modules/terrain/terrainColorMap.js +6 -3
- package/modules/terrain/terrainDefaults.js +2 -1
- package/modules/terrain/terrainEdit.js +45 -29
- package/modules/terrain/terrainGen.js +19 -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 +83 -43
- package/modules/timeline/Tween.js +25 -19
- package/modules/timeline/shots.js +24 -17
- package/modules/triggers/index.js +95 -28
- package/modules/vegetation/Vegetation.js +34 -26
- package/modules/vegetation/densityMap.js +4 -7
- package/modules/vegetation/draw.js +39 -18
- package/modules/vegetation/groundChunks.js +21 -38
- package/modules/vegetation/index.js +37 -12
- package/modules/vegetation/modelGeometry.js +3 -6
- package/modules/vegetation/nearFade.js +1 -1
- package/modules/water/Water.js +20 -16
- package/modules/water/surface.js +3 -3
- package/modules/weather/Weather.js +52 -40
- package/modules/weather/particles.js +8 -8
- package/modules/weather/weatherDraw.js +28 -23
- package/modules/world/World.js +28 -15
- package/modules/world/explain.js +1 -1
- package/modules/world/index.js +30 -17
- package/modules/world/persist.js +90 -27
- package/modules/world/pos.js +5 -5
- package/modules/world/records.js +37 -11
- package/modules/world/sim.js +78 -27
- package/modules/world/simFar.js +2 -2
- package/modules/world/state.js +43 -11
- package/modules/world/thingSource.js +20 -5
- package/modules/world/views.js +27 -14
- package/package.json +48 -7
- package/presets.js +1 -3
- package/render/PostFX.js +83 -53
- package/render/backend.js +31 -33
- 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/particles.tsl.js +8 -6
- package/render/fx/patchNodes.tsl.js +5 -15
- package/render/fx/postWebGPU.tsl.js +30 -26
- 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 +2 -2
- package/render/lighting.js +5 -3
- package/render/lightmap.js +41 -21
- 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 +62 -15
- package/render/ownFrame.js +4 -4
- package/render/patches.js +15 -15
- package/render/postWebGL.js +15 -12
- package/render/probes.js +41 -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 +59 -13
- package/render/slots.js +7 -7
- package/render/terms.js +22 -24
- package/render/uniformDecl.js +1 -1
- package/types/core.d.ts +336 -202
- package/types/gameplay.d.ts +254 -130
- 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} +8 -16
- 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} +28 -10
- package/types/generated/core/input/inputSeat.d.ts +26 -0
- package/types/generated/core/{Budget.d.ts → inspect/Budget.d.ts} +36 -26
- package/types/generated/core/{DebugOverrides.d.ts → inspect/DebugOverrides.d.ts} +17 -3
- package/types/generated/core/{Ops.d.ts → ops/Ops.d.ts} +6 -4
- package/types/generated/core/{control.d.ts → ops/control.d.ts} +14 -10
- package/types/generated/core/{Saves.d.ts → saves/Saves.d.ts} +62 -18
- package/types/generated/core/{session.d.ts → saves/session.d.ts} +3 -2
- package/types/generated/core/{Rays.d.ts → scene/Rays.d.ts} +8 -27
- package/types/generated/core/{Views.d.ts → scene/Views.d.ts} +2 -2
- package/types/generated/core/{Batching.d.ts → stream/Batching.d.ts} +7 -7
- package/types/generated/core/{Stream.d.ts → stream/Stream.d.ts} +22 -18
- 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/Grid.d.ts +1 -0
- 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 +5 -4
- 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 +7 -5
- package/types/generated/modules/water/Water.d.ts +1 -0
- package/types/generated/modules/weather/Weather.d.ts +14 -16
- package/types/generated/modules/weather/weatherDraw.d.ts +3 -3
- package/types/generated/modules/world/World.d.ts +11 -7
- package/types/generated/render/PostFX.d.ts +21 -23
- 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 +47 -15
- package/types/physics.d.ts +150 -73
- package/types/pixel.d.ts +75 -0
- package/types/tsl.d.ts +37 -4
- package/types/world.d.ts +48 -75
- package/ui/Focus.js +10 -9
- package/ui/Parts.js +13 -5
- package/ui/UI.js +7 -7
- package/ui/defaults.js +3 -2
- package/ui/theme.js +7 -5
- package/core/assetEntry.js +0 -109
- package/core/engineCamera.js +0 -32
- package/core/ground.js +0 -104
- package/core/holds.js +0 -134
- package/core/math.js +0 -48
- package/core/moduleSlots.js +0 -100
- package/core/modules.js +0 -314
- package/core/saveApply.js +0 -210
- package/core/saveValues.js +0 -46
- package/core/session.js +0 -174
- package/core/shadowTypes.js +0 -16
- package/core/util.js +0 -17
- package/core/view.js +0 -43
- 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/examples/sheepisland/.threedog/content-index.json +0 -1
- package/modules/camera/projection.js +0 -21
- /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/{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/{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
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
// engine.particles.count('dust') // live particle count; no name = all
|
|
13
13
|
//
|
|
14
14
|
// Params (all optional; below are the neutral fallback values):
|
|
15
|
-
// max 120 max particles alive at once (
|
|
15
|
+
// max 120 max particles alive at once (the default is 60 when engine.tier is 'low'; a number the game gives stands)
|
|
16
16
|
// lifetime [1,2] seconds each particle lives (random range)
|
|
17
17
|
// rate 10 particles per second by default for attach
|
|
18
18
|
// speed [0.5,1.5] initial speed (m/s); direction [0,1,0] emit direction; spread 0.5 max angle off the direction (radians, pi = all directions)
|
|
@@ -30,25 +30,39 @@
|
|
|
30
30
|
// after birth particles always move in world coordinates and are not dragged along by the object
|
|
31
31
|
// fog true affected by fog
|
|
32
32
|
// maxPixels 512 largest on-screen size of one particle (pixels), so smoke drifting past the camera does not fill the screen
|
|
33
|
+
// ratePerMeter 0 with attach, particles per meter the emitter moves, on top of rate, spread along the path it moved (no beads behind a fast emitter)
|
|
34
|
+
// soft 0 meters over which a particle fades where it meets opaque geometry; 0 is off. Set at define, not per batch
|
|
35
|
+
// size, color and opacity also take more stops: evenly spaced [0, 0.8, 0], or timed [[0, 0], [0.1, 0.8], [1, 0]] (time 0 birth, 1 death).
|
|
36
|
+
// Each particle's life fraction (0 birth, 1 death) is the geometry attribute aLife, for a game's own material.
|
|
33
37
|
//
|
|
34
38
|
// Pictures: particles({ effects: { name: {...same params...} }, default: {...} }). effects[name] sits under the define() params (what define sets wins),
|
|
35
39
|
// so a game can write only engine.particles.define('leaves', { max: 200 }) and keep color and texture with the rest of its picture. default is the fallback for all effects.
|
|
36
40
|
// A name in effects that the game never define()d is defined on the first emit/attach.
|
|
37
41
|
// Material: each effect's material is a plain three.js material, swapped with fx.material = myMaterial and drawn as given; fx.uniforms are the engine's { value } objects.
|
|
38
42
|
import * as THREE from 'three';
|
|
39
|
-
import { vec3 } from '../../core/math.js';
|
|
40
|
-
import { Effect, NEUTRAL, KEYS } from './effect.js';
|
|
41
|
-
import { warnMissing } from '../../core/validate.js';
|
|
42
|
-
import { readParams, keysSchema
|
|
43
|
-
import {
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
import { vec3 } from '../../core/base/math.js';
|
|
44
|
+
import { Effect, NEUTRAL, KEYS, OVER_LIFE, curve } from './effect.js';
|
|
45
|
+
import { warnMissing } from '../../core/base/validate.js';
|
|
46
|
+
import { readParams, keysSchema } from '../../core/base/params.js';
|
|
47
|
+
import { isOptions } from '../../core/base/util.js';
|
|
48
|
+
import { codedError } from '../../core/base/errorHints.js';
|
|
49
|
+
// one schema per public entry (unknown keys throw in dev with did-you-mean). Effect param values come in many shapes (number or [min, max], color), so most are only checked by key name
|
|
50
|
+
const FX_PARAMS = keysSchema(KEYS, {}, {
|
|
51
|
+
ratePerMeter: { type: 'number', optional: true, min: 0, desc: 'particles per meter the emitter moves' },
|
|
52
|
+
soft: { type: 'number', optional: true, min: 0, desc: 'meters over which a particle fades into opaque geometry' },
|
|
53
|
+
});
|
|
54
|
+
/** Check one table of effect params: the schema, then the values over life (at the call, not on a later emit) */
|
|
55
|
+
function readFx(where, o) {
|
|
56
|
+
readParams(where, FX_PARAMS, o);
|
|
57
|
+
for (const k of Object.keys(OVER_LIFE)) if (k in o) curve(k, o[k], where);
|
|
58
|
+
}
|
|
46
59
|
const PARTICLES_PARAMS = {
|
|
47
60
|
effects: { type: 'object', optional: true, desc: 'effect params by name: under what define() gives, and defined on the first emit / attach when define() never ran' },
|
|
48
61
|
default: { type: 'object', optional: true, desc: 'params every effect starts from' },
|
|
49
62
|
};
|
|
50
63
|
const EMIT_PARAMS = { count: { type: 'number', default: 10, min: 0, desc: 'particles in this burst' }, overrides: 'any?' }; // overrides: null is allowed (no override)
|
|
51
|
-
const ATTACH_PARAMS = { rate: { type: 'number', optional: true, min: 0, desc: 'particles per second (default: the effect rate)' },
|
|
64
|
+
const ATTACH_PARAMS = { rate: { type: 'number', optional: true, min: 0, desc: 'particles per second (default: the effect rate)' },
|
|
65
|
+
ratePerMeter: { type: 'number', optional: true, min: 0, desc: 'particles per meter moved (default: the effect ratePerMeter)' }, offset: 'any?', overrides: 'any?' };
|
|
52
66
|
const _vs = new THREE.Vector2(); // canvas CSS size (particle point scale follows the canvas height, not the window)
|
|
53
67
|
/** @import { ModuleDef } from '../../types/core' */
|
|
54
68
|
/** @import { Object3D, PositionLike } from '../../types/common' */
|
|
@@ -65,13 +79,15 @@ export class Particles {
|
|
|
65
79
|
/** @internal */ this.engine = engine;
|
|
66
80
|
/** @internal what particles({ effects }) gave */ this._given = effects;
|
|
67
81
|
/** @internal what particles({ default }) gave */ this._fallback = fallback;
|
|
68
|
-
/** Defined effects @type {Map<string, ParticleEffect>} */
|
|
82
|
+
/** Defined effects @type {Map<string, ParticleEffect>} @experimental */
|
|
69
83
|
this.effects = new Map();
|
|
70
84
|
/** @internal */ this.emitters = new Set();
|
|
71
85
|
/** @internal */ this._dir = new THREE.Vector3(); this._up = new THREE.Vector3(); this._t1 = new THREE.Vector3(); this._t2 = new THREE.Vector3();
|
|
72
86
|
/** @internal */ this._q = new THREE.Quaternion();
|
|
73
87
|
/** @internal */ this._o = new THREE.Vector3();
|
|
74
88
|
/** @internal */ this._e = new THREE.Vector3();
|
|
89
|
+
/** @internal */ this._path = { from: new THREE.Vector3(), first: 0, step: 0 };
|
|
90
|
+
/** @internal the scene depth soft effects read on WebGLRenderer, once one draws */ this._depth = null;
|
|
75
91
|
}
|
|
76
92
|
|
|
77
93
|
/**
|
|
@@ -85,9 +101,9 @@ export class Particles {
|
|
|
85
101
|
* @returns {ParticleEffect}
|
|
86
102
|
*/
|
|
87
103
|
define(name, opts = {}) {
|
|
88
|
-
|
|
104
|
+
readFx(`particles.define('${name}')`, opts);
|
|
89
105
|
const old = this.effects.get(name);
|
|
90
|
-
const o = { ...NEUTRAL, ...this._fallback, ...this._given[name], ...opts };
|
|
106
|
+
const o = { ...NEUTRAL, max: this.engine.tier === 'low' ? NEUTRAL.max / 2 : NEUTRAL.max, ...this._fallback, ...this._given[name], ...opts };
|
|
91
107
|
const fx = new Effect(this, name, o);
|
|
92
108
|
this.effects.set(name, fx);
|
|
93
109
|
// emitters attached to the old effect keep running on the new one (redefining tunes an effect, it does not stop it)
|
|
@@ -109,7 +125,7 @@ export class Particles {
|
|
|
109
125
|
}
|
|
110
126
|
|
|
111
127
|
/**
|
|
112
|
-
* Burst: emit count particles at once (default 10) at position (Vector3 / Object3D / [x, y, z] / {x, y, z}). overrides affect this batch only (color, speed, direction...; max/texture/blending cannot be changed temporarily)
|
|
128
|
+
* Burst: emit count particles at once (default 10) at position (Vector3 / Object3D / [x, y, z] / {x, y, z}). overrides affect this batch only (color, speed, direction...; max/texture/blending/soft cannot be changed temporarily)
|
|
113
129
|
* @param {string} name
|
|
114
130
|
* @param {PositionLike} position
|
|
115
131
|
* @param {{ count?: number, overrides?: ParticleOptions | null }} [opts]
|
|
@@ -118,22 +134,22 @@ export class Particles {
|
|
|
118
134
|
emit(name, position, opts = {}) {
|
|
119
135
|
const { count, overrides = null } = readParams(`particles.emit('${name}')`, EMIT_PARAMS, opts);
|
|
120
136
|
const fx = this._get(name); if (!fx) return;
|
|
121
|
-
if (overrides)
|
|
137
|
+
if (overrides) readFx(`particles.emit('${name}') overrides`, overrides);
|
|
122
138
|
fx.spawn(vec3(position, this._e), count, overrides ? { ...fx.o, ...overrides } : fx.o, null);
|
|
123
139
|
}
|
|
124
140
|
|
|
125
141
|
/**
|
|
126
|
-
* Keep emitting while following an object: rate per second, offset in the object's local coordinates [x, y, z] (meters). Returns a handle { remove(), rate, active } (active = false pauses)
|
|
142
|
+
* Keep emitting while following an object: rate per second, ratePerMeter per meter it moves (spread along the path, on top of rate), offset in the object's local coordinates [x, y, z] (meters). Returns a handle { remove(), rate, ratePerMeter, active } (active = false pauses)
|
|
127
143
|
* @param {string} name
|
|
128
144
|
* @param {Object3D} object3d
|
|
129
|
-
* @param {{ rate?: number, offset?: number[], overrides?: ParticleOptions | null }} [opts]
|
|
145
|
+
* @param {{ rate?: number, ratePerMeter?: number, offset?: number[], overrides?: ParticleOptions | null }} [opts]
|
|
130
146
|
* @returns {ParticleEmitter}
|
|
131
147
|
*/
|
|
132
148
|
attach(name, object3d, opts = {}) {
|
|
133
|
-
const { rate, offset = [0, 0, 0], overrides = null } = readParams(`particles.attach('${name}')`, ATTACH_PARAMS, opts);
|
|
134
|
-
if (overrides)
|
|
135
|
-
const fx = this._get(name); if (!fx) return { remove() {}, rate: 0, active: false };
|
|
136
|
-
const h = { fx, object: object3d, rate: rate ?? fx.o.rate, offset, overrides, active: true, acc: 0, remove: () => { h.active = false; this.emitters.delete(h); } };
|
|
149
|
+
const { rate, ratePerMeter, offset = [0, 0, 0], overrides = null } = readParams(`particles.attach('${name}')`, ATTACH_PARAMS, opts);
|
|
150
|
+
if (overrides) readFx(`particles.attach('${name}') overrides`, overrides);
|
|
151
|
+
const fx = this._get(name); if (!fx) return { remove() {}, rate: 0, ratePerMeter: 0, active: false };
|
|
152
|
+
const h = { fx, object: object3d, rate: rate ?? fx.o.rate, ratePerMeter: ratePerMeter ?? fx.o.ratePerMeter, last: null, offset, overrides, active: true, acc: 0, remove: () => { h.active = false; this.emitters.delete(h); } };
|
|
137
153
|
this.emitters.add(h);
|
|
138
154
|
return h;
|
|
139
155
|
}
|
|
@@ -153,7 +169,53 @@ export class Particles {
|
|
|
153
169
|
* @param {string} [name]
|
|
154
170
|
* @returns {void}
|
|
155
171
|
*/
|
|
156
|
-
clear(name) { for (const fx of name ? [this.effects.get(name)].filter(Boolean) : this.effects.values()) { fx.life.fill(0); fx.aAlpha.array.fill(0); fx.alive = 0; fx.points.visible = false; } }
|
|
172
|
+
clear(name) { for (const fx of name ? [this.effects.get(name)].filter(Boolean) : this.effects.values()) { fx.life.fill(0); fx.aAlpha.array.fill(0); fx.alive = 0; fx._stale = fx.max; fx.points.visible = false; } }
|
|
173
|
+
|
|
174
|
+
/** @internal Where the emitter is in the world (written into this._o) */
|
|
175
|
+
_at(h) {
|
|
176
|
+
h.object.updateWorldMatrix(true, false);
|
|
177
|
+
return this._o.set(h.offset[0], h.offset[1], h.offset[2]).applyMatrix4(h.object.matrixWorld);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* @internal Add what emitter h earned by moving this step to h.acc. Returns the path for spawn, or null when it did not move: every particle
|
|
182
|
+
* this step gets the same spacing, whichever of rate and ratePerMeter earned it, and the fraction left in h.acc carries it across steps
|
|
183
|
+
*/
|
|
184
|
+
_walked(h, dt) {
|
|
185
|
+
const to = this._at(h), moved = h.last && dt > 0 ? to.distanceTo(h.last) : 0, path = this._path;
|
|
186
|
+
if (moved > 0) {
|
|
187
|
+
const earned = moved * h.ratePerMeter;
|
|
188
|
+
path.from.copy(h.last); path.step = 1 / (earned + dt * h.rate); path.first = (1 - h.acc) * path.step;
|
|
189
|
+
h.acc += earned;
|
|
190
|
+
}
|
|
191
|
+
(h.last ??= new THREE.Vector3()).copy(to);
|
|
192
|
+
return moved > 0 ? path : null;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* @internal The depth of what is opaque, for soft effects on WebGLRenderer. A shader cannot read the depth buffer it is drawing into there, so the scene's
|
|
197
|
+
* opaque objects are drawn once more, depth only, from inside the draw of the first soft effect of this render: nothing runs unless a soft effect is on screen.
|
|
198
|
+
* The stand-in material knows no wind, displacement or alphaTest, so such surfaces fade as their plain shape
|
|
199
|
+
*/
|
|
200
|
+
_sceneDepth(r, scene, camera) {
|
|
201
|
+
const d = this._depth ??= { target: new THREE.WebGLRenderTarget(1, 1, { depthTexture: new THREE.DepthTexture(1, 1) }), frame: -1, camera: null,
|
|
202
|
+
material: new THREE.MeshDepthMaterial({ colorWrite: false, side: THREE.DoubleSide }) };
|
|
203
|
+
if (d.frame === r.info.render.frame && d.camera === camera) return d.target.depthTexture;
|
|
204
|
+
const size = r.getDrawingBufferSize(_vs), target = r.getRenderTarget(), { autoClear } = r, { autoUpdate } = r.shadowMap, { overrideMaterial, background } = scene, off = [];
|
|
205
|
+
d.target.setSize(size.x, size.y);
|
|
206
|
+
// by layer, not visible: an opaque child of a transparent parent still counts
|
|
207
|
+
scene.traverseVisible(o => { if (o.material && (o.isPoints || [o.material].flat().some(m => !m.depthWrite || m.transmission > 0))) { off.push(o, o.layers.mask); o.layers.disableAll(); } });
|
|
208
|
+
scene.overrideMaterial = d.material; scene.background = null; r.autoClear = true; r.shadowMap.autoUpdate = false;
|
|
209
|
+
r.state.buffers.depth.setMask(true); // the transparent pass left it off, and the clear needs it
|
|
210
|
+
try { r.setRenderTarget(d.target); r.render(scene, camera); }
|
|
211
|
+
finally { // a throwing render must not leave the scene on the depth material with layers off (M11)
|
|
212
|
+
r.setRenderTarget(target);
|
|
213
|
+
scene.overrideMaterial = overrideMaterial; scene.background = background; r.autoClear = autoClear; r.shadowMap.autoUpdate = autoUpdate;
|
|
214
|
+
for (let i = 0; i < off.length; i += 2) off[i].layers.mask = off[i + 1];
|
|
215
|
+
}
|
|
216
|
+
d.frame = r.info.render.frame; d.camera = camera;
|
|
217
|
+
return d.target.depthTexture;
|
|
218
|
+
}
|
|
157
219
|
|
|
158
220
|
/**
|
|
159
221
|
* Update all effects every frame (called by the module each frame)
|
|
@@ -162,10 +224,12 @@ export class Particles {
|
|
|
162
224
|
* @internal
|
|
163
225
|
*/
|
|
164
226
|
update(dt) {
|
|
165
|
-
|
|
227
|
+
if (this.engine.still) dt = 0; // freeze(owner, { ambient: true }): sparks hold in the air
|
|
228
|
+
const cam = this.engine.camera, pr = this.engine.renderer.getPixelRatio(), scale = this.engine.renderer.getSize(_vs).y * pr / (cam.isOrthographicCamera ? 2 / cam.projectionMatrix.elements[5] : 2 * Math.tan(THREE.MathUtils.degToRad(cam.fov) / 2)); // orthographic: pixels per world unit
|
|
166
229
|
for (const h of this.emitters) {
|
|
167
|
-
if (!h.active) continue;
|
|
230
|
+
if (!h.active) { h.last = null; continue; } // a pause leaves no line from where it stopped to where it starts again
|
|
168
231
|
if (!h.object.parent) { h.remove(); continue; } // object removed from the scene: stop automatically
|
|
232
|
+
const path = h.ratePerMeter > 0 ? this._walked(h, dt) : null;
|
|
169
233
|
h.acc += dt * h.rate;
|
|
170
234
|
const n = Math.floor(h.acc);
|
|
171
235
|
if (n <= 0) continue;
|
|
@@ -173,10 +237,9 @@ export class Particles {
|
|
|
173
237
|
// merged params are cached on the handle (re-merged only when overrides is a new object), not spread every frame
|
|
174
238
|
if (h._ov !== h.overrides || h._base !== h.fx.o) { h._ov = h.overrides; h._base = h.fx.o; h._merged = h.overrides ? { ...h.fx.o, ...h.overrides } : h.fx.o; }
|
|
175
239
|
const o = h._merged;
|
|
176
|
-
|
|
177
|
-
const p = this._o.set(h.offset[0], h.offset[1], h.offset[2]).applyMatrix4(h.object.matrixWorld);
|
|
240
|
+
const p = this._at(h);
|
|
178
241
|
h.object.getWorldQuaternion(this._q);
|
|
179
|
-
h.fx.spawn(p, n, o, o.worldSpace === false ? this._q : null);
|
|
242
|
+
h.fx.spawn(p, n, o, o.worldSpace === false ? this._q : null, path);
|
|
180
243
|
}
|
|
181
244
|
for (const fx of this.effects.values()) { fx.uniforms.uScale.value = scale; fx.update(dt); }
|
|
182
245
|
}
|
|
@@ -194,11 +257,12 @@ export function particles(opts = {}) {
|
|
|
194
257
|
// checked here, not on the first emit: a typo in a style table should fail at startup, not in the middle of play
|
|
195
258
|
for (const [name, spec] of Object.entries(opts.effects ?? {})) {
|
|
196
259
|
if (!isOptions(spec)) throw codedError('module-params', `particles({ effects: { ${name} } }): an effect is an object of params, e.g. { max: 200, color: 0xcccccc }; got ${JSON.stringify(spec)}`);
|
|
197
|
-
|
|
260
|
+
readFx(`particles({ effects: { ${name} } })`, spec);
|
|
198
261
|
}
|
|
199
|
-
if (opts.default)
|
|
262
|
+
if (opts.default) readFx('particles({ default })', opts.default);
|
|
200
263
|
let p = null;
|
|
201
|
-
return { name: 'particles', type: 'picture', provides: ['particles'], label: 'Particles', params: PARTICLES_PARAMS, options: opts, stage: 'effects', install(e) { e.i18n.add({ 'zh-CN': { 'module.particles': '粒子' }, en: { 'module.particles': 'particles' } }); p = new Particles(e, opts); return p; }, frame(dt) { p.update(dt); },
|
|
264
|
+
return { name: 'particles', skipKind: 'none', type: 'picture', provides: ['particles'], label: 'Particles', params: PARTICLES_PARAMS, options: opts, stage: 'effects', install(e) { e.i18n.add({ 'zh-CN': { 'module.particles': '粒子' }, en: { 'module.particles': 'particles' } }); p = new Particles(e, opts); return p; }, frame(dt) { p.update(dt); },
|
|
265
|
+
dispose() { for (const fx of p.effects.values()) fx.dispose(); p.effects.clear(); p.emitters.clear(); p._depth?.target.depthTexture.dispose(); p._depth?.target.dispose(); p._depth?.material.dispose(); },
|
|
202
266
|
counts() { return { alive: p.count(), emitters: p.emitters.size }; }, // engine.counts().particles
|
|
203
267
|
// "did the dust burst fire": live particles in total and per effect that has any (idle effects left out to stay short). Kept under `alive`
|
|
204
268
|
// because the numbers change every frame (an emitter's smoke): state comparisons (the session spec) skip that key as presentation, not game state
|
|
@@ -207,3 +271,5 @@ export function particles(opts = {}) {
|
|
|
207
271
|
return { effects: p.effects.size, emitters: p.emitters.size, alive: { total: p.count(), effects: each } };
|
|
208
272
|
} };
|
|
209
273
|
}
|
|
274
|
+
|
|
275
|
+
export const handRolled = [{ kind: 'particles', seen: 'a particle loop of its own', use: 'engine.particles: emitters on game time, one draw call, budgets (recipe 64)', quiet: /\b(engine|e|eng|ctx)\.particles\b|\bparticles\(\s*[{)]/, code: /\bfor\s*\([^)]*\bof\s+[\w.]*(?:particles|sparks|embers)\b|\b(?:particles|sparks|embers)\.(?:forEach|filter)\s*\(/i, near: [{ re: /\.(?:life|age|ttl|vel\w*|v[xyz])\b/, lines: 5 }] }];
|
|
@@ -1,16 +1,47 @@
|
|
|
1
1
|
// One particle effect (helper of Particles.js): a ring buffer of particles drawn as one THREE.Points, updated on the CPU every frame.
|
|
2
2
|
import * as THREE from 'three';
|
|
3
|
+
import { needMaterial, warnOnce } from '../../core/base/validate.js';
|
|
4
|
+
import { codedError, coded } from '../../core/base/errorHints.js';
|
|
3
5
|
import { vert, frag } from './shaders.js';
|
|
4
|
-
import { codedError } from '../../core/errorHints.js';
|
|
5
6
|
import { isWebGPU, webgpuPart, onRendererSwap } from '../../render/backend.js';
|
|
6
7
|
|
|
7
8
|
export const NEUTRAL = {
|
|
8
9
|
max: 120, lifetime: [1, 2], rate: 10, speed: [0.5, 1.5], direction: [0, 1, 0], spread: 0.5, area: 0,
|
|
9
10
|
gravity: -2, drag: 0.5, wind: 0, windDir: [1, 0, 0.3], size: [0.3, 0.3], color: [0xcccccc, 0xcccccc], opacity: [0.8, 0],
|
|
10
|
-
texture: null, blending: 'normal', spin: 0, worldSpace: true, fog: true, maxPixels: 512,
|
|
11
|
+
texture: null, blending: 'normal', spin: 0, worldSpace: true, fog: true, maxPixels: 512, ratePerMeter: 0, soft: 0,
|
|
11
12
|
};
|
|
12
13
|
export const KEYS = Object.keys(NEUTRAL);
|
|
13
14
|
const pair = v => Array.isArray(v) ? v : [v, v];
|
|
15
|
+
/** Numbers per stop of the values that change over life */
|
|
16
|
+
export const OVER_LIFE = { size: 1, opacity: 1, color: 3 };
|
|
17
|
+
const _col = new THREE.Color();
|
|
18
|
+
/**
|
|
19
|
+
* A value over life as { t, v, w }: stop times (0 birth, 1 death) and w numbers per stop. Given as one value, [birth, death], evenly spaced
|
|
20
|
+
* [a, b, c...] or timed [[0, a], [0.2, b], [1, c]] (before the first time and after the last the end stop holds). Throws on anything else.
|
|
21
|
+
* @param {keyof typeof OVER_LIFE} key @param {any} given @param {string} where
|
|
22
|
+
*/
|
|
23
|
+
export function curve(key, given, where) {
|
|
24
|
+
const list = Array.isArray(given) ? given : [given, given], timed = Array.isArray(list[0]), n = list.length, w = OVER_LIFE[key], t = [], v = [];
|
|
25
|
+
const bad = why => codedError('module-params', `${where}: ${key} ${why}. It is one value, [birth, death], evenly spaced stops [a, b, c], or timed stops [[0, a], [0.2, b], [1, c]]; got ${JSON.stringify(given)}`);
|
|
26
|
+
if (n < 2) throw bad('needs two stops or more');
|
|
27
|
+
list.forEach((s, i) => {
|
|
28
|
+
if (Array.isArray(s) !== timed || timed && s.length !== 2) throw bad('mixes the forms');
|
|
29
|
+
const at = timed ? s[0] : i / (n - 1), val = timed ? s[1] : s;
|
|
30
|
+
if (!(at >= (i ? t[i - 1] : 0) && at <= 1)) throw bad('needs stop times from 0 to 1, in order');
|
|
31
|
+
t.push(at);
|
|
32
|
+
if (w === 3) { _col.set(val); v.push(_col.r, _col.g, _col.b); } // three converts to linear color space automatically
|
|
33
|
+
else if (Number.isFinite(val)) v.push(val);
|
|
34
|
+
else throw bad('needs numbers');
|
|
35
|
+
});
|
|
36
|
+
return { t, v, w };
|
|
37
|
+
}
|
|
38
|
+
/** One channel of c at life fraction k */
|
|
39
|
+
function sample(c, k, ch = 0) {
|
|
40
|
+
const t = c.t, last = t.length - 2;
|
|
41
|
+
let s = 0; while (s < last && k >= t[s + 1]) s++;
|
|
42
|
+
const a = c.v[s * c.w + ch];
|
|
43
|
+
return a + (c.v[(s + 1) * c.w + ch] - a) * Math.min(1, Math.max(0, (k - t[s]) / (t[s + 1] - t[s] || 1)));
|
|
44
|
+
}
|
|
14
45
|
/** The node-material side (render/fx/particles.tsl.js, loaded with threedog/tsl) when the renderer is a WebGPURenderer, else null */
|
|
15
46
|
function nodeSide(engine, name) {
|
|
16
47
|
return isWebGPU(engine.renderer) ? webgpuPart('particles', `[particles ${name}] the particle material`) : null;
|
|
@@ -19,24 +50,24 @@ function nodeSide(engine, name) {
|
|
|
19
50
|
export class Effect {
|
|
20
51
|
constructor(sys, name, o) {
|
|
21
52
|
this.sys = sys; this.name = name; this.o = o;
|
|
22
|
-
const N = this.max = Math.max(1, Math.round(o.max
|
|
53
|
+
const N = this.max = Math.max(1, Math.round(o.max));
|
|
23
54
|
this.pos = new Float32Array(N * 3); this.vel = new Float32Array(N * 3);
|
|
24
55
|
this.age = new Float32Array(N); this.life = new Float32Array(N).fill(0); // life 0 = empty slot
|
|
25
56
|
this.spinV = new Float32Array(N);
|
|
26
|
-
this.
|
|
27
|
-
this.sz = new Float32Array(N * 2); this.op = new Float32Array(N * 2);
|
|
57
|
+
this.overLife = { size: new Array(N), opacity: new Array(N), color: new Array(N) }; // each particle's curves, shared by its batch (emit may override)
|
|
28
58
|
this.extra = new Float32Array(N * 3); // gravity, drag, wind (emit may override)
|
|
59
|
+
this._curves = {}; // the last curve of each kind: most batches reuse the effect's own, like the merged params of a handle
|
|
29
60
|
this.head = 0; this.alive = 0;
|
|
61
|
+
/** @internal clear() zeroed slots the GPU copy still shows: the next upload reaches this far */ this._stale = 0;
|
|
30
62
|
/** @internal the game's material while one is set */ this._given = null;
|
|
31
|
-
this._c0 = new THREE.Color(); this._c1 = new THREE.Color();
|
|
32
63
|
this._build();
|
|
33
64
|
// fallback 'webgl': an effect defined before start() was built for the WebGPURenderer start() then replaced; build its draw object again
|
|
34
65
|
// for the renderer in use (the particle state lives in the arrays above, so live particles carry over)
|
|
35
66
|
/** @internal */ this._swap = onRendererSwap(sys.engine, () => {
|
|
36
|
-
const vis = this.points.visible, was =
|
|
67
|
+
const vis = this.points.visible, was = this._attrs.map(a => a.array);
|
|
37
68
|
this._drop();
|
|
38
69
|
this._build();
|
|
39
|
-
|
|
70
|
+
this._attrs.forEach((a, i) => a.array.set(was[i]));
|
|
40
71
|
this.points.visible = vis;
|
|
41
72
|
if (this._given) this.points.material = this._given;
|
|
42
73
|
if (this._tex) this._useTexture(this._tex);
|
|
@@ -47,11 +78,14 @@ export class Effect {
|
|
|
47
78
|
/** The plain three.js material drawn; set yours and it is drawn as given, null gives the engine's back */
|
|
48
79
|
get material() { return this._given ?? this._own; }
|
|
49
80
|
set material(m) {
|
|
50
|
-
if (m != null
|
|
81
|
+
if (m != null) needMaterial('module-params', `particles '${this.name}': material`, m, " (null gives the engine's back)");
|
|
82
|
+
if (m && this._own.isNodeMaterial && !m.isNodeMaterial) throw codedError('module-params', `particles '${this.name}': on WebGPURenderer the material is a node material (PointsNodeMaterial from 'three/webgpu'), got ${m.type}`);
|
|
51
83
|
this._given = m || null;
|
|
84
|
+
// WebGPU: the effect is one quad drawn N times, and where each one goes and how big is the engine material's nodes. Without them every particle sits on the origin
|
|
85
|
+
if (m && this._own.isNodeMaterial) { m.positionNode ??= this._own.positionNode; m.sizeNode ??= this._own.sizeNode; }
|
|
52
86
|
this.points.material = m ?? this._own;
|
|
53
87
|
}
|
|
54
|
-
/** The engine material's { value } objects (uMap, uHasMap, uScale, uMaxPx): the engine writes them whichever material is drawn, a ShaderMaterial of yours can share them */
|
|
88
|
+
/** The engine material's { value } objects (uMap, uHasMap, uScale, uMaxPx, and uSoft with soft on): the engine writes them whichever material is drawn, a ShaderMaterial of yours can share them */
|
|
55
89
|
get uniforms() { return this._own.uniforms; }
|
|
56
90
|
|
|
57
91
|
/** @internal engine.remove disposes what the object draws, so the game's material comes off first: it stays the game's */
|
|
@@ -63,16 +97,30 @@ export class Effect {
|
|
|
63
97
|
const g = this.geometry = new THREE.BufferGeometry();
|
|
64
98
|
const gpu = nodeSide(sys.engine, name); // WebGPU: the same attributes, read per instance by sprite quads
|
|
65
99
|
const attr = (n, size) => { const a = new (gpu ? THREE.InstancedBufferAttribute : THREE.BufferAttribute)(new Float32Array(N * size), size); a.setUsage(THREE.DynamicDrawUsage); g.setAttribute(n, a); return a; };
|
|
66
|
-
this.aPos = attr('position', 3); this.aSize = attr('aSize', 1); this.aAlpha = attr('aAlpha', 1); this.aAngle = attr('aAngle', 1); this.aColor = attr('aColor', 3);
|
|
67
|
-
this._attrs =
|
|
100
|
+
this.aPos = attr('position', 3); this.aSize = attr('aSize', 1); this.aAlpha = attr('aAlpha', 1); this.aAngle = attr('aAngle', 1); this.aColor = attr('aColor', 3); this.aLife = attr('aLife', 1);
|
|
101
|
+
this._attrs = [this.aPos, this.aSize, this.aAlpha, this.aColor, this.aAngle, this.aLife];
|
|
102
|
+
const soft = o.soft > 0 ? o.soft : 0;
|
|
68
103
|
if (gpu) ({ material: this._own, object: this.points } = gpu.particles({ count: N, fog: o.fog !== false, additive: o.blending === 'additive',
|
|
69
|
-
maxPixels: o.maxPixels, attrs: { aPos: this.aPos, aSize: this.aSize, aAlpha: this.aAlpha, aAngle: this.aAngle, aColor: this.aColor } }));
|
|
104
|
+
maxPixels: o.maxPixels, soft, attrs: { aPos: this.aPos, aSize: this.aSize, aAlpha: this.aAlpha, aAngle: this.aAngle, aColor: this.aColor, aLife: this.aLife } }));
|
|
70
105
|
else this._own = new THREE.ShaderMaterial({
|
|
71
106
|
vertexShader: vert, fragmentShader: frag, transparent: true, depthWrite: false, fog: o.fog !== false,
|
|
72
107
|
blending: o.blending === 'additive' ? THREE.AdditiveBlending : THREE.NormalBlending,
|
|
73
|
-
uniforms: THREE.UniformsUtils.merge([THREE.UniformsLib.fog, { uMap: { value: null }, uHasMap: { value: 0 }, uScale: { value: 400 }, uMaxPx: { value: o.maxPixels } }
|
|
108
|
+
uniforms: THREE.UniformsUtils.merge([THREE.UniformsLib.fog, { uMap: { value: null }, uHasMap: { value: 0 }, uScale: { value: 400 }, uMaxPx: { value: o.maxPixels } },
|
|
109
|
+
soft ? { uSoft: { value: soft }, uDepth: { value: null }, uDepthView: { value: new THREE.Vector4() }, uClip: { value: new THREE.Vector2() } } : {}]),
|
|
110
|
+
defines: soft ? { SOFT: 1 } : {},
|
|
74
111
|
});
|
|
75
112
|
if (!gpu) this.points = new THREE.Points(g, this._own);
|
|
113
|
+
// On the WebGL2 backend three's depth copy works from a multisampled target only, so the canvas and a plain target give no fade. The backend is known at the first draw
|
|
114
|
+
if (gpu && soft) this.points.onBeforeRender = r => {
|
|
115
|
+
if (r.backend.isWebGLBackend) warnOnce(coded('module-params', `particles '${name}': soft has no fade on WebGPURenderer's WebGL2 backend unless post draws with antialias; the particles draw hard`), 'particles-soft-webgl2');
|
|
116
|
+
};
|
|
117
|
+
if (!gpu && soft) this.points.onBeforeRender = (r, scene, camera) => {
|
|
118
|
+
if (this.points.material !== this._own) return; // the game's material reads what it wants; nobody needs the depth drawn
|
|
119
|
+
const u = this._own.uniforms;
|
|
120
|
+
u.uDepth.value = sys._sceneDepth(r, scene, camera);
|
|
121
|
+
r.getCurrentViewport(u.uDepthView.value); u.uClip.value.set(camera.near, camera.far);
|
|
122
|
+
this._own.uniformsNeedUpdate = true;
|
|
123
|
+
};
|
|
76
124
|
this.points.frustumCulled = false; this.points.visible = false; this.points.renderOrder = 10;
|
|
77
125
|
this.points.matrixAutoUpdate = false;
|
|
78
126
|
sys.engine.add(this.points, { owner: 'engine:particles' });
|
|
@@ -86,22 +134,32 @@ export class Effect {
|
|
|
86
134
|
else this.sys.engine.assets.useTexture(t, tex => this._useTexture(tex), { where: `particles '${this.name}'`, instead: 'a round dot shows instead' });
|
|
87
135
|
}
|
|
88
136
|
|
|
89
|
-
/**
|
|
90
|
-
|
|
137
|
+
/** curve(), read again only when the value given is another one @internal */
|
|
138
|
+
_curve(key, given, where) {
|
|
139
|
+
const last = this._curves[key];
|
|
140
|
+
return last?.given === given ? last : (this._curves[key] = { ...curve(key, given, where), given });
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Emit count particles. origin {x,y,z}; o is the merged params; frame optional: particle direction rotates with the object.
|
|
145
|
+
* path optional { from, first, step }: particle n is born that fraction of the way from `from` to origin (first + n * step); over max, the newest stay
|
|
146
|
+
*/
|
|
147
|
+
spawn(origin, count, o, quat, path = null) {
|
|
91
148
|
// presentation: particle scatter
|
|
92
|
-
const N = this.max, rnd = Math.random, life = pair(o.lifetime), spd = pair(o.speed),
|
|
93
|
-
this.
|
|
149
|
+
const N = this.max, rnd = Math.random, life = pair(o.lifetime), spd = pair(o.speed), where = `particles '${this.name}'`;
|
|
150
|
+
const size = this._curve('size', o.size, where), opacity = this._curve('opacity', o.opacity, where), color = this._curve('color', o.color, where);
|
|
94
151
|
const dir = this.sys._dir.set(o.direction[0], o.direction[1], o.direction[2]).normalize();
|
|
95
152
|
if (quat) dir.applyQuaternion(quat);
|
|
96
153
|
// two perpendicular directions around axis dir, for random picks inside the cone
|
|
97
154
|
const up = Math.abs(dir.y) < 0.99 ? this.sys._up.set(0, 1, 0) : this.sys._up.set(1, 0, 0);
|
|
98
155
|
const t1 = this.sys._t1.crossVectors(dir, up).normalize(), t2 = this.sys._t2.crossVectors(dir, t1);
|
|
99
156
|
const area = o.area, ax = Array.isArray(area) ? area[0] : area, ay = Array.isArray(area) ? area[1] : area, az = Array.isArray(area) ? area[2] : area;
|
|
100
|
-
for (let n = 0; n < count; n++) {
|
|
157
|
+
for (let n = path ? Math.max(0, count - N) : 0; n < count; n++) {
|
|
101
158
|
const i = this.head; this.head = (this.head + 1) % N;
|
|
102
159
|
if (this.life[i] === 0) this.alive++;
|
|
103
160
|
const i3 = i * 3;
|
|
104
|
-
|
|
161
|
+
const at = path ? this.sys._e.lerpVectors(path.from, origin, path.first + n * path.step) : origin;
|
|
162
|
+
this.pos[i3] = at.x + (rnd() * 2 - 1) * ax; this.pos[i3 + 1] = at.y + (rnd() * 2 - 1) * ay; this.pos[i3 + 2] = at.z + (rnd() * 2 - 1) * az;
|
|
105
163
|
// random direction in a cone: off-axis angle theta in [0, spread] (cos theta uniform = uniform on the sphere)
|
|
106
164
|
const cosT = 1 - rnd() * (1 - Math.cos(Math.min(Math.PI, o.spread))), sinT = Math.sqrt(1 - cosT * cosT), ph = rnd() * Math.PI * 2;
|
|
107
165
|
const a = Math.cos(ph) * sinT, b = Math.sin(ph) * sinT, v = spd[0] + rnd() * (spd[1] - spd[0]);
|
|
@@ -111,9 +169,7 @@ export class Effect {
|
|
|
111
169
|
this.age[i] = 0; this.life[i] = life[0] + rnd() * (life[1] - life[0]) || 0.01;
|
|
112
170
|
this.spinV[i] = o.spin ? (rnd() * 2 - 1) * o.spin : 0;
|
|
113
171
|
this.aAngle.array[i] = rnd() * Math.PI * 2;
|
|
114
|
-
this.
|
|
115
|
-
this.col1[i3] = this._c1.r; this.col1[i3 + 1] = this._c1.g; this.col1[i3 + 2] = this._c1.b;
|
|
116
|
-
this.sz[i * 2] = sz[0]; this.sz[i * 2 + 1] = sz[1]; this.op[i * 2] = op[0]; this.op[i * 2 + 1] = op[1];
|
|
172
|
+
this.overLife.size[i] = size; this.overLife.opacity[i] = opacity; this.overLife.color[i] = color;
|
|
117
173
|
this.extra[i3] = o.gravity; this.extra[i3 + 1] = o.drag; this.extra[i3 + 2] = o.wind;
|
|
118
174
|
}
|
|
119
175
|
this.points.visible = true;
|
|
@@ -121,7 +177,7 @@ export class Effect {
|
|
|
121
177
|
|
|
122
178
|
update(dt) {
|
|
123
179
|
if (!this.alive) { this.points.visible = false; return; }
|
|
124
|
-
const N = this.max, P = this.pos, V = this.vel, ap = this.aPos.array, as = this.aSize.array, aa = this.aAlpha.array, ac = this.aColor.array, ag = this.aAngle.array;
|
|
180
|
+
const N = this.max, P = this.pos, V = this.vel, ap = this.aPos.array, as = this.aSize.array, aa = this.aAlpha.array, ac = this.aColor.array, ag = this.aAngle.array, al = this.aLife.array, { size, opacity, color } = this.overLife;
|
|
125
181
|
const w = this.o.windDir, wl = Math.hypot(w[0], w[2]) || 1, wind = this.sys.engine.uniforms.uWind.value, wx = w[0] / wl * wind, wz = w[2] / wl * wind;
|
|
126
182
|
let alive = 0, hi = -1;
|
|
127
183
|
for (let i = 0; i < N; i++) {
|
|
@@ -134,20 +190,18 @@ export class Effect {
|
|
|
134
190
|
const i3 = i * 3, k = age / L, g = this.extra[i3], dr = Math.max(0, 1 - this.extra[i3 + 1] * dt), wd = this.extra[i3 + 2];
|
|
135
191
|
V[i3] = V[i3] * dr + wx * wd * dt; V[i3 + 1] = V[i3 + 1] * dr + g * dt; V[i3 + 2] = V[i3 + 2] * dr + wz * wd * dt;
|
|
136
192
|
ap[i3] = P[i3] += V[i3] * dt; ap[i3 + 1] = P[i3 + 1] += V[i3 + 1] * dt; ap[i3 + 2] = P[i3 + 2] += V[i3 + 2] * dt;
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
ac[i3] = this.col0[i3] + (this.col1[i3] - this.col0[i3]) * k;
|
|
140
|
-
ac[i3 + 1] = this.col0[i3 + 1] + (this.col1[i3 + 1] - this.col0[i3 + 1]) * k;
|
|
141
|
-
ac[i3 + 2] = this.col0[i3 + 2] + (this.col1[i3 + 2] - this.col0[i3 + 2]) * k;
|
|
193
|
+
al[i] = k; as[i] = sample(size[i], k); aa[i] = sample(opacity[i], k);
|
|
194
|
+
ac[i3] = sample(color[i], k); ac[i3 + 1] = sample(color[i], k, 1); ac[i3 + 2] = sample(color[i], k, 2);
|
|
142
195
|
if (this.spinV[i]) ag[i] += this.spinV[i] * dt;
|
|
143
196
|
}
|
|
144
197
|
this.alive = alive;
|
|
145
198
|
this.points.visible = alive > 0;
|
|
146
199
|
// upload only the used range (0 to the last live particle), not the whole buffer
|
|
147
|
-
const n = hi + 1;
|
|
200
|
+
const n = hi + 1, up = Math.max(n, this._stale);
|
|
201
|
+
this._stale = 0;
|
|
148
202
|
if (this.points.isSprite) this.points.count = n; // WebGPU sprites: instances up to the last live one (dead ones in between have size 0)
|
|
149
|
-
for (const a of this._attrs
|
|
150
|
-
a.clearUpdateRanges(); a.addUpdateRange(0,
|
|
203
|
+
for (const a of this._attrs) {
|
|
204
|
+
a.clearUpdateRanges(); a.addUpdateRange(0, up * a.itemSize); a.needsUpdate = true;
|
|
151
205
|
}
|
|
152
206
|
}
|
|
153
207
|
|
|
@@ -1,19 +1,32 @@
|
|
|
1
1
|
// Particle point-sprite shaders: size by distance (capped at uMaxPx), soft round dot or a texture, rotation, fog, tone mapping and output color space.
|
|
2
|
+
// SOFT (the soft option): fades where the particle meets opaque geometry; uDepth is the scene depth Particles._sceneDepth drew. Without it the shaders are as ever.
|
|
2
3
|
export const vert = `
|
|
3
4
|
attribute float aSize; attribute float aAlpha; attribute float aAngle; attribute vec3 aColor;
|
|
4
5
|
varying float vAlpha; varying float vAngle; varying vec3 vColor;
|
|
5
6
|
uniform float uScale; uniform float uMaxPx;
|
|
7
|
+
#ifdef SOFT
|
|
8
|
+
varying float vViewZ;
|
|
9
|
+
#endif
|
|
6
10
|
#include <fog_pars_vertex>
|
|
7
11
|
void main() {
|
|
8
12
|
vAlpha = aAlpha; vAngle = aAngle; vColor = aColor;
|
|
9
13
|
vec4 mvPosition = modelViewMatrix * vec4(position, 1.0);
|
|
10
14
|
gl_Position = projectionMatrix * mvPosition;
|
|
11
|
-
|
|
15
|
+
#ifdef SOFT
|
|
16
|
+
vViewZ = mvPosition.z;
|
|
17
|
+
#endif
|
|
18
|
+
// uScale is pixels per meter at distance 1, or just pixels per meter on an orthographic camera (no shrink with distance); capped: no screen-filling sprites near the camera
|
|
19
|
+
gl_PointSize = aAlpha <= 0.0 ? 0.0 : min(aSize * uScale / (isOrthographic ? 1.0 : max(0.1, -mvPosition.z)), uMaxPx);
|
|
12
20
|
#include <fog_vertex>
|
|
13
21
|
}`;
|
|
14
22
|
export const frag = `
|
|
15
23
|
uniform sampler2D uMap; uniform float uHasMap;
|
|
16
24
|
varying float vAlpha; varying float vAngle; varying vec3 vColor;
|
|
25
|
+
#ifdef SOFT
|
|
26
|
+
#include <packing>
|
|
27
|
+
uniform sampler2D uDepth; uniform vec4 uDepthView; uniform vec2 uClip; uniform float uSoft;
|
|
28
|
+
varying float vViewZ;
|
|
29
|
+
#endif
|
|
17
30
|
#include <fog_pars_fragment>
|
|
18
31
|
void main() {
|
|
19
32
|
vec2 p = gl_PointCoord - 0.5;
|
|
@@ -21,6 +34,11 @@ export const frag = `
|
|
|
21
34
|
p = vec2(c * p.x - s * p.y, s * p.x + c * p.y);
|
|
22
35
|
vec4 tex = uHasMap > 0.5 ? texture2D(uMap, p + 0.5) : vec4(1.0, 1.0, 1.0, smoothstep(0.5, 0.2, length(p)));
|
|
23
36
|
gl_FragColor = vec4(vColor * tex.rgb, tex.a * vAlpha);
|
|
37
|
+
#ifdef SOFT
|
|
38
|
+
float d = texture2D(uDepth, (gl_FragCoord.xy - uDepthView.xy) / uDepthView.zw).x;
|
|
39
|
+
float sceneZ = isOrthographic ? orthographicDepthToViewZ(d, uClip.x, uClip.y) : perspectiveDepthToViewZ(d, uClip.x, uClip.y);
|
|
40
|
+
gl_FragColor.a *= clamp((vViewZ - sceneZ) / uSoft, 0.0, 1.0);
|
|
41
|
+
#endif
|
|
24
42
|
if (gl_FragColor.a < 0.01) discard;
|
|
25
43
|
#include <tonemapping_fragment>
|
|
26
44
|
#include <colorspace_fragment>
|
package/modules/photo/Photo.js
CHANGED
|
@@ -6,17 +6,18 @@
|
|
|
6
6
|
// photo.canTake (true or a reason) is its can. engine.photo.take() is the low-level capture the op calls (no checks).
|
|
7
7
|
// const r = engine.ops.run('photo.take'); // r.value = { url, time, position, subject } or r.code (e.g. 'noFilm')
|
|
8
8
|
// When the photo key's op is refused the module emits photo:denied { reason } (the game shows it; a button reads r.code itself).
|
|
9
|
-
// subject is what is in the middle of the frame { name, kind, distance }: NPC (kind 'npc'),
|
|
9
|
+
// subject is what is in the middle of the frame { name, kind, distance }: NPC (kind 'npc'), named object ('object'),
|
|
10
10
|
// vegetation ('vegetation'; after hitting an instanced mesh, vegetation.instanceAt looks up the kind); null when it hits the sky or an unnamed ground.
|
|
11
11
|
// The photo key (action 'photo') is the game's: engine.input.bind('photo', ['KeyC', 'PadX']), presets.bindings.photo (P / gamepad RB) or [] for no key
|
|
12
12
|
// Shutter sound: the game's createEngine({ audio: { sounds: { shutter } } }) supplies a file, otherwise a synthesized fallback
|
|
13
|
-
import { warnOnce } from '../../core/validate.js';
|
|
14
|
-
import { builtInSounds } from '../../core/assetManifest.js';
|
|
15
|
-
import { readParams, keysSchema } from '../../core/params.js';
|
|
13
|
+
import { warnOnce } from '../../core/base/validate.js';
|
|
14
|
+
import { builtInSounds } from '../../core/assets/assetManifest.js';
|
|
15
|
+
import { readParams, keysSchema } from '../../core/base/params.js';
|
|
16
16
|
import { toast } from '../../ui/UI.js';
|
|
17
|
-
import { coded } from '../../core/errorHints.js';
|
|
17
|
+
import { coded } from '../../core/base/errorHints.js';
|
|
18
18
|
import { setShadowUpdate, shadowsOn } from '../../render/backend.js';
|
|
19
|
-
|
|
19
|
+
import { borrowRatio } from '../../core/scene/pixelRatio.js';
|
|
20
|
+
const GROUP = 'photo'; // attachment group in engine.saves
|
|
20
21
|
const TAKE_KEYS = ['scale', 'shadowMapSize', 'bloom', 'quality', 'format'];
|
|
21
22
|
|
|
22
23
|
export class Photo {
|
|
@@ -32,15 +33,14 @@ export class Photo {
|
|
|
32
33
|
readParams('photo.take()', keysSchema(TAKE_KEYS), opts);
|
|
33
34
|
const o = { scale: this.scale, shadowMapSize: this.shadowMapSize, bloom: this.bloom, quality: this.quality, format: this.format, ...opts };
|
|
34
35
|
const e = this.engine, r = e.renderer;
|
|
35
|
-
const
|
|
36
|
+
const prevBloom = e.post.get('bloom')?.enabled, suns = [];
|
|
36
37
|
if (shadowsOn(e)) e.scene.traverse(l => { if (l.isDirectionalLight && l.castShadow && l.visible) suns.push([l, l.shadow.mapSize.x, l.shadow.mapSize.y]); });
|
|
37
|
-
const pr = Math.min(3, prevPR * o.scale);
|
|
38
38
|
const forceBloom = typeof o.bloom === 'boolean' && prevBloom !== undefined;
|
|
39
|
-
let url, bloomHold = null;
|
|
39
|
+
let url, bloomHold = null, ratioBack = null;
|
|
40
40
|
// restored in finally: a throw mid-shot (a failed WebGPU frame, a tainted canvas in toDataURL) must not leave the game running at the photo's
|
|
41
41
|
// pixel ratio and shadow map size with photo's bloom hold still on
|
|
42
42
|
try {
|
|
43
|
-
r.
|
|
43
|
+
ratioBack = borrowRatio(e, Math.min(3, r.getPixelRatio() * o.scale)); // the post chain follows the renderer on its next draw (postWebGL.js follow)
|
|
44
44
|
for (const [l] of suns) e.shadows.mapSize(l, o.shadowMapSize);
|
|
45
45
|
// a hold on the system layer, removed after the shot: the game's own choice stays what it was (tests/specs/render-once.mjs); a settings restriction still wins
|
|
46
46
|
bloomHold = forceBloom ? e.mod('post.bloom.enabled', { owner: 'photo', set: o.bloom, layer: 'system' }) : null;
|
|
@@ -48,7 +48,7 @@ export class Photo {
|
|
|
48
48
|
e.renderOnce(); // the frame the player sees, post included, read below in the same task; a fresh frame on WebGPU (engine.renderOnce)
|
|
49
49
|
url = r.domElement.toDataURL(o.format, o.quality);
|
|
50
50
|
} finally {
|
|
51
|
-
|
|
51
|
+
ratioBack?.();
|
|
52
52
|
for (const [l, w, h] of suns) e.shadows.mapSize(l, w, h);
|
|
53
53
|
bloomHold?.remove();
|
|
54
54
|
}
|
|
@@ -67,27 +67,24 @@ export class Photo {
|
|
|
67
67
|
async _persist(shot) {
|
|
68
68
|
const id = shot.id = `${Date.now().toString(36)}-${this._n++}`; // wall-clock: photo id
|
|
69
69
|
const meta = { time: shot.time, position: shot.position, subject: shot.subject };
|
|
70
|
-
const saves = this.engine.saves;
|
|
71
70
|
try {
|
|
72
|
-
await saves.
|
|
71
|
+
await this.engine.saves.putAttachment(GROUP, id, async () => { // a function, so saves.flush() also waits for the bytes of this photo
|
|
73
72
|
const blob = await (await fetch(shot.url)).blob();
|
|
74
73
|
if (this.album.includes(shot)) shot.url = URL.createObjectURL(blob); // still in the album: hold the bytes as a Blob from now on
|
|
75
|
-
|
|
76
|
-
});
|
|
74
|
+
return blob;
|
|
75
|
+
}, meta);
|
|
77
76
|
} catch (err) { this._fail(err); }
|
|
78
77
|
}
|
|
79
78
|
/** Photos pushed out of the album: delete from storage and release the blob: URLs created at load */
|
|
80
79
|
_drop(shot) {
|
|
81
80
|
if (shot.url.startsWith('blob:')) URL.revokeObjectURL(shot.url);
|
|
82
|
-
if (shot.id) this.engine.saves.
|
|
81
|
+
if (shot.id) this.engine.saves.removeAttachment(GROUP, shot.id).catch(err => this._fail(err));
|
|
83
82
|
}
|
|
84
83
|
/** At startup / after importing a save file, read the stored photos back into the album (newest first, merged with and de-duplicated against what is already there) */
|
|
85
84
|
async restore() {
|
|
86
|
-
|
|
87
|
-
await saves.whenReady;
|
|
88
|
-
let rows; try { rows = await saves.store.blobs(GROUP); } catch (err) { this._fail(err); return; }
|
|
85
|
+
let rows; try { rows = await this.engine.saves.attachments(GROUP); } catch (err) { this._fail(err); return; }
|
|
89
86
|
const have = new Set(this.album.map(s => s.id));
|
|
90
|
-
for (const r of rows) if (!have.has(r.id)) this.album.push({ id: r.id, url: URL.createObjectURL(r.blob),
|
|
87
|
+
for (const r of rows) if (!have.has(r.id)) this.album.push({ ...r.meta, id: r.id, url: URL.createObjectURL(r.blob), at: r.at }); // meta first: an imported file's meta.url must not replace the photo
|
|
91
88
|
this.album.sort((a, b) => (b.at ?? Infinity) - (a.at ?? Infinity) || 0); // a just-taken shot has no `at`: goes first
|
|
92
89
|
while (this.album.length > this.maxAlbum) this._drop(this.album.pop());
|
|
93
90
|
}
|
|
@@ -127,19 +124,19 @@ export function photo(all = {}) {
|
|
|
127
124
|
const opts = all;
|
|
128
125
|
let ph = null;
|
|
129
126
|
return {
|
|
130
|
-
name: 'photo', type: 'tool', params: PHOTO_PARAMS, options: all, label: 'Photo mode', optional: ['cameraRig', 'sky', 'calendar', 'vegetation'],
|
|
127
|
+
name: 'photo', skipKind: 'none', type: 'tool', params: PHOTO_PARAMS, options: all, label: 'Photo mode', optional: ['cameraRig', 'sky', 'calendar', 'vegetation', 'characters'],
|
|
131
128
|
install(e, ctx) {
|
|
132
129
|
e.i18n.add(STRINGS);
|
|
133
130
|
// declared only: the game binds the key (presets.bindings.photo or its own; [] = no key), so every key in a game comes from one bindings table
|
|
134
131
|
ctx.input.action('photo', { label: 'photo.action' });
|
|
135
|
-
if (e.input.keysOf('photo').length) e.input.touchButton('photo', 'photo.action');
|
|
132
|
+
if (e.input.keysOf('photo').length) ctx.track(e.input.touchButton('photo', 'photo.action'));
|
|
136
133
|
builtInSounds(e.assets, { shutter: (audio, p, out) => { // sound asset 'shutter', silent until audio.sounds names it
|
|
137
134
|
audio.noiseBurst({ dur: 0.03, type: 'highpass', freq: p.freq ?? 3000, vol: p.volume ?? 0.4, out });
|
|
138
135
|
audio.noiseBurst({ dur: 0.05, type: 'bandpass', freq: 1800, vol: (p.volume ?? 0.4) * 0.75, delay: 0.07, out }); return 0.15;
|
|
139
136
|
} });
|
|
140
137
|
ph = new Photo(e, opts);
|
|
141
138
|
ph.restore(); // read photos taken last time back from storage
|
|
142
|
-
|
|
139
|
+
ctx.ops.define('photo.take', {
|
|
143
140
|
desc: 'Take a photo (refused when photo.canTake() returns false or a reason)',
|
|
144
141
|
can: () => { const r = ph.canTake(); return r === true ? true : typeof r === 'string' && r ? r : 'denied'; },
|
|
145
142
|
run: () => ph.take(),
|
|
@@ -149,6 +146,7 @@ export function photo(all = {}) {
|
|
|
149
146
|
ctx.track(e.events.on('save:imported', () => ph.restore())); // after restoring from a save file, the attachments in the file (photos) also go into the album
|
|
150
147
|
return ph;
|
|
151
148
|
},
|
|
149
|
+
dispose() { for (const s of ph.album) if (s.url.startsWith('blob:')) URL.revokeObjectURL(s.url); }, // a blob: URL holds its bytes until revoked, past the engine's life
|
|
152
150
|
frame(dt, e) {
|
|
153
151
|
if (!e.input.pressed('photo')) return;
|
|
154
152
|
const r = e.ops.run('photo.take', {}, { source: 'player' });
|
|
@@ -162,3 +160,5 @@ export function photo(all = {}) {
|
|
|
162
160
|
},
|
|
163
161
|
};
|
|
164
162
|
}
|
|
163
|
+
|
|
164
|
+
export const handRolled = 'none: a screenshot is one browser call, and a hint would add nothing to it';
|