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
|
@@ -18,9 +18,10 @@
|
|
|
18
18
|
// The log window is the UI part 'questLog' (questLog.js): replace it or turn it off with engine.ui.set('questLog', ...) (recipes/26-ui-parts.md).
|
|
19
19
|
import { toast, toggleOnKey } from '../../ui/UI.js';
|
|
20
20
|
import { questLogWindow } from './questLog.js';
|
|
21
|
-
import { warnMissing, DEV } from '../../core/validate.js';
|
|
22
|
-
import { readParams, keysSchema } from '../../core/params.js';
|
|
23
|
-
import { codedError } from '../../core/errorHints.js';
|
|
21
|
+
import { warnMissing, warnOnce, DEV } from '../../core/base/validate.js';
|
|
22
|
+
import { readParams, keysSchema } from '../../core/base/params.js';
|
|
23
|
+
import { codedError } from '../../core/base/errorHints.js';
|
|
24
|
+
import { reportError } from '../../core/base/errors.js';
|
|
24
25
|
import { toSaved, fromSaved, migrateV1, stepId } from './questSave.js';
|
|
25
26
|
|
|
26
27
|
const STRINGS = {
|
|
@@ -45,7 +46,6 @@ export class Quests {
|
|
|
45
46
|
// declared only: the game binds the key (presets.bindings.quests or its own; [] = no key), so every key in a game comes from one bindings table
|
|
46
47
|
track(engine.input.action(action, { label: 'quests.action', owner: 'quests' }));
|
|
47
48
|
this.win = questLogWindow(engine, this, track); // { open, toggle, refresh } over engine.ui
|
|
48
|
-
// counters live in engine.vars
|
|
49
49
|
// saved by stable step ids (questSave.js); version 1 saved positions
|
|
50
50
|
engine.saves.register('quests', { atomic: true, version: 2, migrate: { 1: d => migrateV1(this.defs, d) }, save: () => this._save(), load: d => this._load(d) });
|
|
51
51
|
}
|
|
@@ -65,13 +65,14 @@ export class Quests {
|
|
|
65
65
|
define(id, def) {
|
|
66
66
|
const at = `quests.define('${id}')`;
|
|
67
67
|
readParams(at, keysSchema(['title', 'desc', 'steps', 'reward', 'fail', 'onFail']), def);
|
|
68
|
-
|
|
68
|
+
if (!Array.isArray(def?.steps)) throw codedError('quest-step', `${at}: steps is a list of steps, e.g. steps: [{ text: 'Find the key', done: e => e.vars.flag('key') }]; got ${JSON.stringify(def?.steps)}`); // every later read needs it, and this one names the quest
|
|
69
|
+
for (const s of def.steps) {
|
|
69
70
|
if (!s.all && (typeof s.done !== 'function' || s.optional !== undefined)) throw codedError('quest-step', `${at}: a step needs done (a function), or all: [parts] for parallel goals; optional goes on a part inside all`);
|
|
70
71
|
readParams(`${at} steps`, keysSchema(s.all ? ['id', 'text', 'all'] : ['id', 'text', 'done', 'target']), s);
|
|
71
72
|
for (const p of s.all || []) readParams(`${at} parallel part`, keysSchema(['id', 'text', 'done', 'target', 'optional']), p);
|
|
72
73
|
if (s.all && !s.all.some(p => !p.optional)) throw codedError('quest-step', `${at}: a parallel step needs at least one part without optional: true, or it would finish at once`);
|
|
73
74
|
}
|
|
74
|
-
const ids =
|
|
75
|
+
const ids = def.steps.map((_, i) => stepId(def, i)), dup = ids.find((x, i) => ids.indexOf(x) !== i);
|
|
75
76
|
if (dup != null) throw codedError('quest-step', `${at}: two steps have the id '${dup}'; step ids must be unique (saves find a step by it)`);
|
|
76
77
|
this.defs.set(id, def);
|
|
77
78
|
if (id in this._saved) { this._progress[id] = fromSaved(id, def, this._saved[id]); delete this._saved[id]; this.win.refresh(); }
|
|
@@ -110,7 +111,10 @@ export class Quests {
|
|
|
110
111
|
}
|
|
111
112
|
start(id) {
|
|
112
113
|
if (!this.defs.has(id)) { warnMissing('quest', id, [...this.defs.keys()]); return; }
|
|
113
|
-
if (this._progress[id] && !this._progress[id].failed)
|
|
114
|
+
if (this._progress[id] && !this._progress[id].failed) { // a failed quest may be taken again (a daily order, a retry); an active one is a harmless repeat
|
|
115
|
+
if (this._progress[id].done) warnOnce(`quests.start('${id}'): the quest is already done, so nothing happens (a done quest does not restart). Use a new quest id for a repeatable order, or let it fail first`);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
114
118
|
DEV && this.engine.ops.guard('quests.start');
|
|
115
119
|
this._progress[id] = { step: 0, done: false };
|
|
116
120
|
this._say('start', id, this.engine.t('quests.new', { title: this.defs.get(id).title }));
|
|
@@ -147,7 +151,10 @@ export class Quests {
|
|
|
147
151
|
/** @internal after steps moved: complete the quest at the end, else announce the new step */
|
|
148
152
|
_finishOrSay(id, s, d, advanced) {
|
|
149
153
|
if (s.step >= d.steps.length) {
|
|
150
|
-
s.done = true;
|
|
154
|
+
s.done = true;
|
|
155
|
+
// done is already set, so a reward that throws must not stop here: the quest:done event and the toast would be lost and the reward would be half given.
|
|
156
|
+
// The failure is reported (soft, no freeze) and the rest goes on; content.run applies every other effect of the reward before it rethrows
|
|
157
|
+
try { d.reward?.(this.engine); } catch (err) { reportError(this.engine, err, `quest '${id}' reward`, { soft: true }); }
|
|
151
158
|
this._say('done', id, this.engine.t('quests.done', { title: d.title })); this.engine.events.emit('quest:done', { id });
|
|
152
159
|
} else if (advanced) this._say('step', id, stepText(d.steps[s.step]));
|
|
153
160
|
if (advanced) this.win.refresh();
|
|
@@ -195,7 +202,7 @@ export class Quests {
|
|
|
195
202
|
|
|
196
203
|
const QUEST_PARAMS = {
|
|
197
204
|
action: { type: 'string', default: 'quests', desc: 'input action that opens the quest log' },
|
|
198
|
-
checkInterval: { type: 'number', default: 0.5, min: 0, desc: 'seconds
|
|
205
|
+
checkInterval: { type: 'number', default: 0.5, min: 0, desc: 'real seconds between quest condition checks' },
|
|
199
206
|
notify: { type: 'any', default: true, desc: 'true = toast, false = silent, or a function ({ type, id, text }) => void' },
|
|
200
207
|
};
|
|
201
208
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Container internals that need no class state beyond the box they get as `b` (helper of Container.js): the dry runs behind trade / transfer, adding with
|
|
2
2
|
// the room check and its dev messages, and reading a saved list.
|
|
3
3
|
import { toast } from '../../ui/UI.js';
|
|
4
|
-
import { warnOnce, fmt } from '../../core/validate.js';
|
|
4
|
+
import { warnOnce, fmt } from '../../core/base/validate.js';
|
|
5
5
|
|
|
6
6
|
const STRINGS = {
|
|
7
7
|
full: 'Container {box} has no room for {id} (capacity {cap} slots, maxWeight {mw}): add returns false. Raise capacity / maxWeight, or remove something first',
|
|
@@ -60,10 +60,9 @@ export class Bubbles {
|
|
|
60
60
|
_place(at, height) {
|
|
61
61
|
const e = this.engine;
|
|
62
62
|
if (at == null) return { x: 0, y: 0, onScreen: true, screen: true };
|
|
63
|
-
|
|
64
|
-
if (at
|
|
65
|
-
else
|
|
66
|
-
else p = _v.set(at.x, at.y ?? 0, at.z);
|
|
63
|
+
if (at.isObject3D) at.getWorldPosition(_v);
|
|
64
|
+
else if (typeof at === 'string') { const q = e.actorPosition?.(at); if (!q) return { x: 0, y: 0, onScreen: false, screen: false }; _v.set(q.x, q.y ?? 0, q.z); }
|
|
65
|
+
else _v.set(at.x, at.y ?? 0, at.z);
|
|
67
66
|
_v.y += height;
|
|
68
67
|
const s = worldToScreen(e, _v);
|
|
69
68
|
return { x: s.x, y: s.y, onScreen: s.onScreen, screen: false };
|
|
@@ -6,7 +6,6 @@
|
|
|
6
6
|
// engine.ui.set('inventory', (engine) => ({ show: d => …, update: d => …, hide: () => …, dispose: () => … })) your own
|
|
7
7
|
import { esc, iconHTML as icon, injectUICSS } from '../../ui/UI.js';
|
|
8
8
|
|
|
9
|
-
|
|
10
9
|
/** Texts of the inventory window, the got / full toasts and the ops (zh-CN and en) @internal */
|
|
11
10
|
export const INVENTORY_STRINGS = {
|
|
12
11
|
'zh-CN': { 'module.inventory': '背包', 'inventory.title': '背包', 'inventory.action': '背包', 'inventory.empty': '背包是空的。', 'inventory.full': '背包满了',
|
|
@@ -16,15 +16,15 @@
|
|
|
16
16
|
import * as THREE from 'three';
|
|
17
17
|
import { neutralMaterial } from '../../render/neutral.js';
|
|
18
18
|
import { copyPatches, isEngineMade, markEngineMade } from '../../render/patches.js';
|
|
19
|
-
import { xzOf } from '../../core/math.js';
|
|
20
|
-
import { placeY } from '../../core/ground.js';
|
|
21
|
-
import { warnOnce } from '../../core/validate.js';
|
|
22
|
-
import { readParams, keysSchema } from '../../core/params.js';
|
|
19
|
+
import { xzOf, yOf } from '../../core/base/math.js';
|
|
20
|
+
import { placeY } from '../../core/scene/ground.js';
|
|
21
|
+
import { warnOnce, needMaterial, fmt } from '../../core/base/validate.js';
|
|
22
|
+
import { readParams, keysSchema } from '../../core/base/params.js';
|
|
23
23
|
import { copyData } from './Container.js';
|
|
24
|
-
import { failure } from '../../core/opsFail.js';
|
|
25
|
-
import { protoOf } from '../../core/namedModel.js';
|
|
26
|
-
import { shadowDefaults } from '../../core/assetEntry.js';
|
|
27
|
-
import { codedError, coded } from '../../core/errorHints.js';
|
|
24
|
+
import { failure } from '../../core/ops/opsFail.js';
|
|
25
|
+
import { protoOf } from '../../core/assets/namedModel.js';
|
|
26
|
+
import { shadowDefaults } from '../../core/assets/assetEntry.js';
|
|
27
|
+
import { codedError, coded } from '../../core/base/errorHints.js';
|
|
28
28
|
|
|
29
29
|
const STRINGS = { 'zh-CN': { 'module.pickups': '拾取物', 'pickups.take': '捡起 {name}' }, en: { 'module.pickups': 'pickups', 'pickups.take': 'Pick up {name}' } };
|
|
30
30
|
const SPAWN_KEYS = ['give', 'count', 'data', 'name', 'model', 'color', 'mesh', 'respawnSeconds', 'bob', 'id', 'initial', 'zone', 'radius', 'auto'];
|
|
@@ -35,7 +35,7 @@ const NET_SLACK = 1;
|
|
|
35
35
|
|
|
36
36
|
export class Pickups {
|
|
37
37
|
/** @internal track: the module's ctx.track */
|
|
38
|
-
constructor(engine, { radius
|
|
38
|
+
constructor(engine, { radius, showDistance, takers, color, size, lift }, track) {
|
|
39
39
|
this.engine = engine;
|
|
40
40
|
/** Edge of the placeholder box (meters), read when one is built */ this.size = size;
|
|
41
41
|
/** Height above the ground new pickups float at (meters) */ this.lift = lift;
|
|
@@ -73,7 +73,7 @@ export class Pickups {
|
|
|
73
73
|
*/
|
|
74
74
|
get material() { return this._material; }
|
|
75
75
|
set material(m) {
|
|
76
|
-
|
|
76
|
+
needMaterial('pickup-misuse', 'engine.pickups.material', m, '. Example: engine.pickups.material = new THREE.MeshStandardMaterial({ color: 0xffd24a })');
|
|
77
77
|
const old = this._material;
|
|
78
78
|
if (m === old) return;
|
|
79
79
|
this._material = m;
|
|
@@ -112,16 +112,15 @@ export class Pickups {
|
|
|
112
112
|
if (item && !e.inventory) throw codedError('pickup-misuse', `pickups.spawn({ give: '${item}' }): an item pickup goes into the picker's container, so it needs inventory() installed; for an instant effect pass give: (e, { actor }) => ...`);
|
|
113
113
|
const [x, z] = xzOf(position);
|
|
114
114
|
// a given y is the reference height on multi-layer ground (as snapToGround): a pickup on a bridge deck or a second floor stays there; without one it sits on the top layer
|
|
115
|
-
const p = /** @type {any} */ (position).isObject3D ? /** @type {any} */ (position).position : position, refY = Array.isArray(p) ? p[1] : p.y;
|
|
116
115
|
const { count = 1, mesh = null, respawnSeconds = 0, bob = true, id, initial = false, zone, radius, auto = false, name, model: m, color } = opts;
|
|
117
116
|
const what = item ?? name ?? 'pickup';
|
|
118
117
|
if (radius != null && !(radius > 0)) throw codedError('pickup-misuse', `pickups.spawn('${what}'): radius must be a positive number of meters, got ${radius}`);
|
|
119
118
|
const data = copyData('pickups.spawn', what, opts.data);
|
|
120
119
|
const def = { id, kind: 'pickup', ...(item && { item }), count, bob, ...(data && { data }), ...(name != null && { name }), ...(m != null && { model: m }), ...(color != null && { color }),
|
|
121
120
|
...(radius != null && { radius }), ...(auto && { auto: true }), ...(respawnSeconds > 0 && { respawn: respawnSeconds }), ...(zone != null && { zone }),
|
|
122
|
-
position: [x, placeY(e, `pickups.spawn('${what}')`, x, z,
|
|
121
|
+
position: [x, placeY(e, `pickups.spawn('${what}')`, x, z, yOf(position)) + this.lift, z] };
|
|
123
122
|
const rec = initial ? w.add(def, { initial }) : id != null && w.get(id) || w.add(def); // initial data: world decides whether it exists / was deleted from the save (null)
|
|
124
|
-
if (rec && (rec.kind !== 'pickup' || (rec.item ?? null) !== item)) throw codedError('
|
|
123
|
+
if (rec && (rec.kind !== 'pickup' || (rec.item ?? null) !== item)) throw codedError('world-id', `pickup id '${id}' is already used by other data (${rec.kind}${rec.item ? ' ' + rec.item : ''}): use a different id`);
|
|
125
124
|
const wid = rec?.id ?? id;
|
|
126
125
|
if (mesh || !item) this._live.set(wid, { mesh, give: item ? null : give });
|
|
127
126
|
return { id: wid, give, get object() { return w.view(wid); }, remove: () => { w.remove(wid); this._live.delete(wid); } };
|
|
@@ -148,12 +147,12 @@ export class Pickups {
|
|
|
148
147
|
*/
|
|
149
148
|
_take(rec, actor) {
|
|
150
149
|
const e = this.engine, W = e.world;
|
|
151
|
-
let value;
|
|
150
|
+
let value, left = 0;
|
|
152
151
|
if (rec.item) {
|
|
153
152
|
if (!e.inventory) return failure('noInventory');
|
|
154
|
-
const
|
|
155
|
-
if (!
|
|
156
|
-
value = key;
|
|
153
|
+
const put = e.inventory.of(actor).add(rec.item, rec.count, rec.data && { data: rec.data });
|
|
154
|
+
if (!put.ok) return put;
|
|
155
|
+
value = put.key; left = rec.count - (put.added ?? rec.count); // a bag with room for part of it: the rest stays on the ground
|
|
157
156
|
} else {
|
|
158
157
|
const fn = this._live.get(rec.id)?.give;
|
|
159
158
|
if (!fn) { warnOnce(`pickups: '${rec.id}' gives with a function, which is not saved data; spawn it again with the same id after a load (content and setup code do)`); return failure('noGive'); }
|
|
@@ -161,9 +160,10 @@ export class Pickups {
|
|
|
161
160
|
if (value && value.ok === false) return value;
|
|
162
161
|
}
|
|
163
162
|
// without respawn the record is deleted; with respawn time it gets until (show tears down the model), saved so the countdown continues after a load
|
|
164
|
-
if (
|
|
163
|
+
if (left > 0) W.set(rec.id, { count: left });
|
|
164
|
+
else if (rec.respawn > 0) W.set(rec.id, { until: e.clock.now + rec.respawn });
|
|
165
165
|
else W.remove(rec.id); // world:remove drops the live parts
|
|
166
|
-
e.events.emit('pickup:take', { pickup: rec.id, item: rec.item ?? null, count: rec.count, actor, x: rec.position.x, z: rec.position.z });
|
|
166
|
+
e.events.emit('pickup:take', { pickup: rec.id, item: rec.item ?? null, count: rec.count - left, actor, x: rec.position.x, z: rec.position.z });
|
|
167
167
|
return { ok: true, value };
|
|
168
168
|
}
|
|
169
169
|
|
|
@@ -213,14 +213,13 @@ function present(pk) {
|
|
|
213
213
|
const NO_PICKUP = "pickups: no model for '{item}', so it lies on the ground as a gray box (a placeholder). Register a model in an asset pack and name it: "
|
|
214
214
|
+ "pickups.spawn(p, { model: 'gem' }) / inventory.define('{item}', { model: 'gem' }), or call the model 'pickup:{item}' (this item) / 'pickup' (every pickup without its own)";
|
|
215
215
|
const NO_NAME = "pickups: '{item}' has model '{model}', but no asset pack registers a model of that name (engine.assets.manifest({ models: { {model}: fn | '/models/{model}.glb' } })); using the gray placeholder box";
|
|
216
|
-
const fill = (t, o) => t.replace(/\{(\w+)\}/g, (_, k) => o[k]);
|
|
217
216
|
/** Which model name a pickup shows (its own model, else the item's, else 'pickup:<item>' / 'pickup'), or null for the placeholder @internal */
|
|
218
217
|
function pickupModelName(e, item, model) {
|
|
219
218
|
const has = n => { const x = e.assets.entries.get(n); return !!x?.named && x.type === 'model'; };
|
|
220
219
|
const what = item ?? 'pickup';
|
|
221
|
-
if (typeof model === 'string') { if (has(model)) return model; warnOnce(
|
|
220
|
+
if (typeof model === 'string') { if (has(model)) return model; warnOnce(fmt(NO_NAME, { item: what, model })); return null; }
|
|
222
221
|
for (const n of item ? ['pickup:' + item, 'pickup'] : ['pickup']) if (has(n)) return n;
|
|
223
|
-
warnOnce(
|
|
222
|
+
warnOnce(fmt(NO_PICKUP, { item: what }));
|
|
224
223
|
return null;
|
|
225
224
|
}
|
|
226
225
|
/**
|
|
@@ -325,7 +324,7 @@ export function pickups(opts = {}) {
|
|
|
325
324
|
name: 'pickups', type: 'rules', label: 'Pickups', params: PICKUP_PARAMS, options: o, requires: ['world'], optional: ['interactions', 'inventory', 'net'], stage: 'gameplay',
|
|
326
325
|
noSkip: 'auto pickups are spatial; respawn follows the game clock',
|
|
327
326
|
install(e, ctx) {
|
|
328
|
-
pk = new Pickups(e,
|
|
327
|
+
pk = new Pickups(e, o, ctx.track); defineTake(e, pk); return pk; // o: the schema defaults are filled in, the class repeats none
|
|
329
328
|
},
|
|
330
329
|
fixed() { pk._auto(); },
|
|
331
330
|
describe(e, ctx) { // use the model if present (same object the interactions module reports, merged into one entry); far away only data
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
// A step's (or parallel part's) id is its `id` field (quests.define / content: steps: [{ id: 'talk-mayor', text, done }]), else its position as text
|
|
5
5
|
// ('0', '1', ...): give steps ids before shipping, then edits to the step list never move a player's progress.
|
|
6
6
|
// Version 1 saved positions: migrateV1 maps them to ids through the quest definitions known when the save is loaded.
|
|
7
|
-
import { warnOnce } from '../../core/validate.js';
|
|
8
|
-
import { coded } from '../../core/errorHints.js';
|
|
7
|
+
import { warnOnce, fmt } from '../../core/base/validate.js';
|
|
8
|
+
import { coded } from '../../core/base/errorHints.js';
|
|
9
9
|
|
|
10
10
|
const STRINGS = {
|
|
11
11
|
missing: "quests: the save has quest '{q}' at step '{step}', which its definition no longer has; it restarts from the first step. Keep step ids stable, or add a migrate step to the 'quests' save part",
|
|
@@ -44,7 +44,7 @@ export function toSaved(def, s) {
|
|
|
44
44
|
*/
|
|
45
45
|
export function fromSaved(id, def, q) {
|
|
46
46
|
let step = q.done ? def.steps.length : indexOf(def, q.step);
|
|
47
|
-
if (step < 0) { warnOnce(coded('quest-step', STRINGS.missing
|
|
47
|
+
if (step < 0) { warnOnce(coded('quest-step', fmt(STRINGS.missing, { q: id, step: String(q.step) }))); step = 0; }
|
|
48
48
|
const s = { step, done: !!q.done };
|
|
49
49
|
if (q.failed) s.failed = true;
|
|
50
50
|
const st = def.steps[step];
|
package/modules/grid/Grid.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
// mapping is one replaceable pair (grids.add({ mapping })), so a game with another lattice swaps two functions instead of every caller's math.
|
|
8
8
|
// A footprint is anchored at its min corner cell; rotation is in quarter turns (0-3) and odd turns swap width and depth.
|
|
9
9
|
import { Layer } from './Layer.js';
|
|
10
|
-
import { xzOf } from '../../core/math.js';
|
|
10
|
+
import { xzOf } from '../../core/base/math.js';
|
|
11
11
|
|
|
12
12
|
/** The default occupancy layer of an item that names none */
|
|
13
13
|
export const MAIN = 'main';
|
package/modules/grid/Layer.js
CHANGED
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
// Version 1 saved every cell whole; its step turns that into { set, whole: true } (cells not listed are empty, whatever content authors now).
|
|
7
7
|
// Writes are saved gameplay state, so they pass the ops guard like world.set (write inside an op or a fixed step).
|
|
8
8
|
// _ver counts changes so views (tiles) rebuild only when something changed, without events.
|
|
9
|
-
import { DEV } from '../../core/validate.js';
|
|
10
|
-
import { codedError } from '../../core/errorHints.js';
|
|
9
|
+
import { DEV, needMaterial } from '../../core/base/validate.js';
|
|
10
|
+
import { codedError } from '../../core/base/errorHints.js';
|
|
11
11
|
|
|
12
12
|
const key = (i, j) => i + ',' + j;
|
|
13
13
|
const plainErr = (where, v) => `${where}: layer data must be plain values (numbers, strings, booleans, arrays, plain objects); got ${v?.constructor?.name ?? typeof v}. Keep models in tiles / world.present`;
|
|
@@ -52,7 +52,7 @@ export class Layer {
|
|
|
52
52
|
set material(m) {
|
|
53
53
|
const mesh = this.grid._owner._tiles.get(this)?.mesh;
|
|
54
54
|
if (!mesh) throw codedError('grids-misuse', `layer '${this.name}'.material: this layer draws no default tiles; give it a picture first: grid.layer('${this.name}', { tiles: true })`);
|
|
55
|
-
|
|
55
|
+
needMaterial('grids-misuse', `layer '${this.name}'.material`, m);
|
|
56
56
|
mesh.material = m;
|
|
57
57
|
}
|
|
58
58
|
/** @internal */
|
|
@@ -151,6 +151,6 @@ export class Layer {
|
|
|
151
151
|
|
|
152
152
|
/**
|
|
153
153
|
* Options of grid.layer(name, opts)
|
|
154
|
-
* @typedef {{ tiles?: boolean | {
|
|
154
|
+
* @typedef {{ tiles?: boolean | { color?: (data: Record<string, any>, cell: [number, number]) => any, colors?: Record<string, number | string>, lift?: number }
|
|
155
155
|
* | ((engine: any, layer: Layer) => { update?: (cells: { cell: [number, number], data: Record<string, any> }[]) => void, dispose?: () => void }) }} LayerOptions
|
|
156
156
|
*/
|
package/modules/grid/index.js
CHANGED
|
@@ -16,11 +16,11 @@ import { defineGridOps, placed } from './ops.js';
|
|
|
16
16
|
|
|
17
17
|
/** Grids save part: version 1 stored every cell of a layer whole ([[i, j, data]]); version 2 stores a diff against the authored cells (Layer.js) */
|
|
18
18
|
const GRIDS_MIGRATE = { 1: d => Object.fromEntries(Object.entries(d || {}).map(([g, ls]) => [g, Object.fromEntries(Object.entries(ls || {}).map(([n, rows]) => [n, { set: rows, whole: true }]))])) };
|
|
19
|
-
import { closest, DEV, warnOnce } from '../../core/validate.js';
|
|
20
|
-
import { readParams, keysSchema } from '../../core/params.js';
|
|
21
|
-
import { failure } from '../../core/opsFail.js';
|
|
19
|
+
import { closest, DEV, warnOnce, fmt } from '../../core/base/validate.js';
|
|
20
|
+
import { readParams, keysSchema } from '../../core/base/params.js';
|
|
21
|
+
import { failure } from '../../core/ops/opsFail.js';
|
|
22
22
|
import { STRINGS as TEXT } from './strings.js';
|
|
23
|
-
import { codedError, coded } from '../../core/errorHints.js';
|
|
23
|
+
import { codedError, coded } from '../../core/base/errorHints.js';
|
|
24
24
|
|
|
25
25
|
const STRINGS = {
|
|
26
26
|
dup: "grids.add('{name}'): a grid with this name exists",
|
|
@@ -29,7 +29,6 @@ const STRINGS = {
|
|
|
29
29
|
orphan: "[engine] grid '{grid}': {id} is a '{item}', which this content no longer defines; it is kept in the save but takes no cells. Define '{item}' again (engine.grids.define) to bring it back, or remove it with engine.ops.run('grid.remove', { id })",
|
|
30
30
|
overlap: "[engine] grid '{grid}': {id} overlaps {other} at cell {cell}; the cell stays with {other}. Place things with engine.ops.run('grid.place', ...) / 'grid.move', which check can() first",
|
|
31
31
|
};
|
|
32
|
-
const fmt = (s, v) => s.replace(/\{(\w+)\}/g, (_, k) => v[k] ?? '');
|
|
33
32
|
const hint = (n, list) => { const c = closest(n, list); return c ? ` (did you mean '${c}'?)` : ''; };
|
|
34
33
|
const freeze = p => { Object.freeze(p.cell); Object.freeze(p.size); return Object.freeze(p); };
|
|
35
34
|
|
|
@@ -88,11 +87,11 @@ export class Grids {
|
|
|
88
87
|
return g;
|
|
89
88
|
}
|
|
90
89
|
/**
|
|
91
|
-
* A grid by name, or
|
|
90
|
+
* A grid by name, or undefined when there is none
|
|
92
91
|
* @param {string} name
|
|
93
|
-
* @returns {Grid |
|
|
92
|
+
* @returns {Grid | undefined}
|
|
94
93
|
*/
|
|
95
|
-
get(name) { return this._grids.get(name)
|
|
94
|
+
get(name) { return this._grids.get(name); }
|
|
96
95
|
/** @internal A grid by name; throws with the names that exist */
|
|
97
96
|
_must(name) {
|
|
98
97
|
const g = this._grids.get(name);
|
package/modules/grid/preview.js
CHANGED
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
// The picture is a replaceable part: draw: false (no visual, the handle still answers), or (engine) => ({ update(view), hide(), dispose() }); pv.material is the default box's.
|
|
5
5
|
import * as THREE from 'three';
|
|
6
6
|
import { neutralMaterial } from '../../render/neutral.js';
|
|
7
|
-
import { screenToGround } from '../../core/screenToGround.js';
|
|
8
|
-
import { warnOnce } from '../../core/validate.js';
|
|
9
|
-
import { failure } from '../../core/opsFail.js';
|
|
10
|
-
import { codedError } from '../../core/errorHints.js';
|
|
7
|
+
import { screenToGround } from '../../core/scene/screenToGround.js';
|
|
8
|
+
import { warnOnce, needMaterial, fmt } from '../../core/base/validate.js';
|
|
9
|
+
import { failure } from '../../core/ops/opsFail.js';
|
|
10
|
+
import { codedError } from '../../core/base/errorHints.js';
|
|
11
11
|
|
|
12
12
|
const NO_KEY = 'grids.preview(): the action "{a}" has no keys, so the preview cannot be turned by input. Bind it (engine.input.bind("{a}", ["KeyR"]) or presets.bindings.gridRotate), or pass rotate: false and call pv.rotate() from your own control';
|
|
13
13
|
|
|
@@ -21,7 +21,7 @@ function boxPart(e, st) {
|
|
|
21
21
|
return {
|
|
22
22
|
get material() { return mesh.material; },
|
|
23
23
|
set material(m) {
|
|
24
|
-
|
|
24
|
+
needMaterial('grids-misuse', 'pv.material', m);
|
|
25
25
|
mesh.material = m;
|
|
26
26
|
},
|
|
27
27
|
update(v) {
|
|
@@ -54,7 +54,7 @@ export function makePreview(e, grids, opts) {
|
|
|
54
54
|
// declared by the preview, owned by the grid module and taken away with the preview (or the module), so nothing outlives it; the game binds
|
|
55
55
|
// the key (presets.bindings.gridRotate) like every module action
|
|
56
56
|
const decl = rotate ? e.input.action(rotate, { label: 'grid.rotate', owner: 'grids', optional: true }) : null;
|
|
57
|
-
if (rotate && !e.input.keysOf(rotate).length) warnOnce(NO_KEY
|
|
57
|
+
if (rotate && !e.input.keysOf(rotate).length) warnOnce(fmt(NO_KEY, { a: rotate }));
|
|
58
58
|
const part = draw === false ? null : typeof draw === 'function' ? draw(e) : boxPart(e, grids);
|
|
59
59
|
const h = {
|
|
60
60
|
/** target cell or null (nothing under the pointer) */ cell: null,
|
|
@@ -74,7 +74,7 @@ export function makePreview(e, grids, opts) {
|
|
|
74
74
|
return e.ops.run('grid.place', { grid, item, cell: h.cell, rotation: h.rotation, ...(fields ? { fields } : {}) });
|
|
75
75
|
},
|
|
76
76
|
/** Remove the preview (cancel convention: safe to call again) */
|
|
77
|
-
remove() { grids._previews.delete(h); decl?.remove(); part?.dispose?.(); },
|
|
77
|
+
remove() { if (!grids._previews.delete(h)) return; decl?.remove(); part?.dispose?.(); },
|
|
78
78
|
/** @internal */
|
|
79
79
|
frame() {
|
|
80
80
|
if (rotate && e.input.pressed(rotate)) h.rotate(1);
|
package/modules/grid/tiles.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
// Crisp per-cell tiles for a layer (a painted floor, a buildable zone, tilled soil): one mesh per layer, each non-empty cell a quad
|
|
2
2
|
// whose four corners sit on engine.surface + lift, so tiles hug a ramp or terrain and work on any ground provider
|
|
3
3
|
// (procedural terrain, a Blender level, a flat greenhouse floor). One merged mesh = one draw call; it is rebuilt only when
|
|
4
|
-
// the layer version or the ground (level:loaded) changes.
|
|
4
|
+
// the layer version or the ground (level:loaded, a terrain edit's ground:change) changes.
|
|
5
5
|
// Picture: layer option tiles.color(data, cell) -> color | null, else tiles.colors = { field: color }, else the module's table grids({ tiles: { layer: { field: color } } })
|
|
6
6
|
// (first truthy field in the table's order wins), else neutral gray. tiles: false = off; a function = your own part. layer.material is the three.js material they draw with.
|
|
7
7
|
import * as THREE from 'three';
|
|
8
8
|
import { neutralMaterial } from '../../render/neutral.js';
|
|
9
|
-
import { surfaceOr } from '../../core/ground.js';
|
|
10
|
-
import { readParams, keysSchema } from '../../core/params.js';
|
|
9
|
+
import { surfaceOr } from '../../core/scene/ground.js';
|
|
10
|
+
import { readParams, keysSchema } from '../../core/base/params.js';
|
|
11
11
|
|
|
12
12
|
const GAP = 0.03; // fraction of a cell left between tiles: keeps tiles visibly separate (crisp edges)
|
|
13
13
|
const FALLBACK = 0x9a9a9a;
|
|
@@ -34,7 +34,7 @@ export function layerTiles(e, layer, st) {
|
|
|
34
34
|
mesh.name = `grid:${layer.grid.name}.${name}`; mesh.receiveShadow = true; mesh.frustumCulled = false;
|
|
35
35
|
e.add(mesh, { owner: 'engine:grid' });
|
|
36
36
|
let ver = -1, ground = 0, built = -1;
|
|
37
|
-
const
|
|
37
|
+
const offs = ['level:loaded', 'ground:change'].map(n => e.events.on(n, () => { ground++; })); // new ground heights: a new level, or dug / raised terrain
|
|
38
38
|
const col = new THREE.Color(), g = layer.grid;
|
|
39
39
|
function rebuild() {
|
|
40
40
|
const cells = layer.query(), pos = [], clr = [], idx = [];
|
|
@@ -58,10 +58,10 @@ export function layerTiles(e, layer, st) {
|
|
|
58
58
|
return {
|
|
59
59
|
mesh,
|
|
60
60
|
frame() {
|
|
61
|
-
mesh.visible =
|
|
61
|
+
mesh.visible = e.world?.inZone(g) ?? true;
|
|
62
62
|
if (layer._ver !== ver || ground !== built) { ver = layer._ver; built = ground; rebuild(); }
|
|
63
63
|
},
|
|
64
|
-
dispose() {
|
|
64
|
+
dispose() { for (const o of offs) o.remove(); e.remove(mesh); geo.dispose(); own.dispose(); }, // a material the game set stays the game's
|
|
65
65
|
};
|
|
66
66
|
}
|
|
67
67
|
|
package/modules/hlod/index.js
CHANGED
|
@@ -5,46 +5,30 @@
|
|
|
5
5
|
// How: split into cells of `cell` meters (default = engine.stream cell size); per cell, meshes sharing a material are baked to world space and merged into one proxy mesh;
|
|
6
6
|
// a node named xxx_LOD1 is a simplified xxx and is preferred when merging (it stays hidden itself). Merging runs in engine.jobs, spread over frames, so startup does not hitch.
|
|
7
7
|
// Every 0.25 s, switch by distance from the full-detail engine.stream sources: cell center farther than `near` meters from all of them shows the proxy and hides originals; with terrain, uses chunk-ring distance (same measure as terrain LOD).
|
|
8
|
+
// Merges, never simplifies: engine.assets.lod is the one that lowers one model's triangles (core/assets/assetLod.js says how the neighbours split the work).
|
|
8
9
|
// Owns far: batching (engine.batching) owns repeated near props; a mesh hlod registers is marked userData.hlod and batching skips it, and a mesh already
|
|
9
|
-
// batched (userData.batched) is skipped here, so the two never fight. Skips vegetation (it has its own instancing and LOD); no mesh simplification; proxies are not raycast (rays only hit originals): originals hidden when far
|
|
10
|
-
// so engine.raycast still hits far buildings (see core/Rays.js).
|
|
11
|
-
// The game's visible stays the game's: a
|
|
12
|
-
// so
|
|
13
|
-
// A xxx_LOD1 node gets the same accessor, always hidden. Both are listed in threePatches as 'hlod-visible' (handle.remove() is the off switch).
|
|
10
|
+
// batched (userData.batched) is skipped here, so the two never fight. Skips vegetation (it has its own instancing and LOD); no mesh simplification; proxies are not raycast (rays only hit originals): originals hidden when far sit on the batch layer, which rays see,
|
|
11
|
+
// so engine.raycast still hits far buildings (see core/scene/Rays.js).
|
|
12
|
+
// The game's visible stays the game's: a far original moves to the batch layer (RESERVED_LAYERS.batched: not drawn, no shadows, rays hit it), the same way engine.batching
|
|
13
|
+
// hides what it draws, so nothing here sits between the game and three.js. A building the game hides (near or far) stays hidden after the switch and is not hit by rays.
|
|
14
14
|
// Skips meshes whose material moves vertices (wind and other shadow: true patches): that code reads object space (height above the
|
|
15
15
|
// model origin, phase from the origin), so a world-space proxy would sway far more on high ground and every merged object in lockstep.
|
|
16
|
-
// Those meshes stay as they are (always drawn) and keep their own sway.
|
|
16
|
+
// Those meshes stay as they are (always drawn) and keep their own sway. Mirrored meshes (negative scale) stay out of the proxies the same way.
|
|
17
17
|
// After install, engine.hlod: add() returns a handle { cells, ready (boolean: all proxies merged), whenReady (Promise), remove() }; each cell is { key, proxy, originals, center, far }.
|
|
18
18
|
import * as THREE from 'three';
|
|
19
|
-
import {
|
|
19
|
+
import { mergeCommon } from '../../render/mergeCommon.js';
|
|
20
20
|
|
|
21
|
-
import { readParams, keysSchema } from '../../core/params.js';
|
|
21
|
+
import { readParams, keysSchema } from '../../core/base/params.js';
|
|
22
22
|
import { movesVertices } from '../../render/patches.js';
|
|
23
|
-
import {
|
|
23
|
+
import { warnOnce } from '../../core/base/validate.js';
|
|
24
|
+
import { isShown, isUnder } from '../../core/base/util.js';
|
|
25
|
+
import { RESERVED_LAYERS } from '../../render/layers.js';
|
|
26
|
+
import { unhideMask, FAR_BIT, noRaycast } from '../../render/occlusion.js';
|
|
24
27
|
/** @import { ModuleDef } from '../../types/core' */
|
|
25
28
|
/** @import { Hlod, HlodOptions } from '../../types/world' */
|
|
26
29
|
|
|
27
30
|
const ADD_KEYS = ['cell', 'near', 'castShadow', 'include'];
|
|
28
31
|
const LOD_RE = /_LOD1$/;
|
|
29
|
-
const noRaycast = () => {};
|
|
30
|
-
notePatch('hlod-visible', "visible on the meshes registered with engine.hlod.add (and their xxx_LOD1 nodes): an own get / set on each, reading the game's value and not hidden far",
|
|
31
|
-
null, { scope: 'objects registered with hlod', lost: "per handle: engine.hlod.add(...).remove() hands each mesh its plain visible back (the game's last value)" });
|
|
32
|
-
|
|
33
|
-
// merge geometries of one material: keep only attributes all have; if any lacks an index, drop indices from all
|
|
34
|
-
function mergeGroup(meshes) {
|
|
35
|
-
const geos = meshes.map(m => m.geometry.clone().applyMatrix4(m.matrixWorld));
|
|
36
|
-
const names = Object.keys(geos[0].attributes).filter(n => geos.every(g => g.attributes[n]));
|
|
37
|
-
const indexed = geos.every(g => g.index);
|
|
38
|
-
const ready = geos.map(g => {
|
|
39
|
-
const h = indexed ? g : g.toNonIndexed();
|
|
40
|
-
for (const n of Object.keys(h.attributes)) if (!names.includes(n)) h.deleteAttribute(n);
|
|
41
|
-
h.morphAttributes = {};
|
|
42
|
-
return h;
|
|
43
|
-
});
|
|
44
|
-
const out = mergeGeometries(ready, false);
|
|
45
|
-
for (const g of new Set([...geos, ...ready])) g.dispose();
|
|
46
|
-
return out;
|
|
47
|
-
}
|
|
48
32
|
|
|
49
33
|
const FULL = { detail: 'full' };
|
|
50
34
|
const HLOD_PARAMS = keysSchema(['level', ...ADD_KEYS]);
|
|
@@ -60,12 +44,12 @@ export function hlod(opts = {}) {
|
|
|
60
44
|
const { level: autoLevel = true, ...defaults } = opts;
|
|
61
45
|
let e = null, timer = 0, levelHandle = null;
|
|
62
46
|
const handles = new Set();
|
|
63
|
-
const
|
|
47
|
+
const away = new Map(); // far original -> its layer mask before it moved
|
|
64
48
|
|
|
65
49
|
/** Far from every full-detail stream source (a 'simple' source keeps the proxy): chunk-ring difference with terrain, else horizontal distance (meters); a source radius caps near.
|
|
66
50
|
* srcs: [{ x, z, n }] per source with n = its reach for this handle's near, read once per update for all cells */
|
|
67
51
|
function isFar(c, srcs) {
|
|
68
|
-
const CH = e.terrain?.
|
|
52
|
+
const CH = e.terrain?.chunkSize;
|
|
69
53
|
for (const f of srcs) {
|
|
70
54
|
if (CH ? Math.max(Math.abs(Math.floor(c.center.x / CH) - Math.floor(f.x / CH)), Math.abs(Math.floor(c.center.z / CH) - Math.floor(f.z / CH))) <= Math.ceil(f.n / CH)
|
|
71
55
|
: Math.hypot(c.center.x - f.x, c.center.z - f.z) <= f.n) return false;
|
|
@@ -75,24 +59,16 @@ export function hlod(opts = {}) {
|
|
|
75
59
|
function setFar(c, far) {
|
|
76
60
|
if (c.far === far) return;
|
|
77
61
|
c.far = far;
|
|
62
|
+
// occlusion watches what is on screen. Taking the old watch away first shows anything it hid, so its mask never mixes with the one kept here
|
|
63
|
+
c.watch?.remove();
|
|
78
64
|
for (const p of c.proxy) p.visible = far;
|
|
79
|
-
for (const m of c.originals)
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
function takeVisible(m, rays = true) {
|
|
85
|
-
if (shade.has(m)) return; // registered twice: one owner of the property is enough
|
|
86
|
-
let mine = m.visible, far = false;
|
|
87
|
-
// rays keep hitting a far original only while the game itself shows it (the proxy merely stands in for it on screen)
|
|
88
|
-
const sync = () => { if (rays && far && mine) m.userData.rayVisible = true; else delete m.userData.rayVisible; };
|
|
89
|
-
Object.defineProperty(m, 'visible', { configurable: true, enumerable: true, get: () => mine && !far, set: v => { mine = v; sync(); } });
|
|
90
|
-
shade.set(m, {
|
|
91
|
-
far(f) { far = f; sync(); },
|
|
92
|
-
shown() { if (!mine) return false; for (let p = m.parent; p; p = p.parent) if (!p.visible) return false; return true; },
|
|
93
|
-
release() { shade.delete(m); delete m.visible; m.visible = mine; delete m.userData.rayVisible; },
|
|
94
|
-
});
|
|
65
|
+
for (const m of c.originals) {
|
|
66
|
+
if (far && !away.has(m)) { away.set(m, m.layers.mask); m.layers.set(RESERVED_LAYERS.batched); }
|
|
67
|
+
else if (!far && away.has(m)) { m.layers.mask = unhideMask(m.layers.mask, FAR_BIT, away.get(m)); away.delete(m); }
|
|
68
|
+
}
|
|
69
|
+
if (c.watch) c.watch = watch(c);
|
|
95
70
|
}
|
|
71
|
+
const watch = c => e.occlusion.watch(c.far ? c.proxy : c.originals);
|
|
96
72
|
|
|
97
73
|
const api = {
|
|
98
74
|
cells: [],
|
|
@@ -109,14 +85,18 @@ export function hlod(opts = {}) {
|
|
|
109
85
|
const originals = [];
|
|
110
86
|
const walk = n => {
|
|
111
87
|
if (!n.visible || LOD_RE.test(n.name)) return;
|
|
88
|
+
if (n.isLOD) return; // already swaps its own levels: a proxy of it would fight lod.update over what is shown
|
|
89
|
+
// a bundle replays as recorded, so hlod could never hide its meshes: near and far would both draw
|
|
90
|
+
if (n.isBundleGroup) { warnOnce(`hlod.add(): "${n.name || 'a BundleGroup'}" is left out: a BundleGroup draws its own meshes, hlod cannot swap them. Use a plain Group for what hlod should take`); return; }
|
|
112
91
|
if (n.isMesh && !n.isInstancedMesh && !n.isSkinnedMesh && !n.userData.batched && !Array.isArray(n.material) && n.geometry && (!include || include(n))) originals.push(n);
|
|
113
92
|
for (const c of n.children) walk(c);
|
|
114
93
|
};
|
|
115
94
|
roots.forEach(walk);
|
|
116
|
-
|
|
117
|
-
for (
|
|
118
|
-
|
|
119
|
-
|
|
95
|
+
// swaying meshes keep their own transform (see header); so do mirrored ones (negative scale): baked into a proxy their faces turn inside out, and only a mesh's own matrix flips the winding back
|
|
96
|
+
for (let i = originals.length; i--;) if (movesVertices(originals[i].material) || originals[i].matrixWorld.determinant() < 0) originals.splice(i, 1);
|
|
97
|
+
for (const m of originals) m.userData.hlod = true; // engine.batching leaves hlod's meshes alone (marked after the filter: swaying meshes stay batchable)
|
|
98
|
+
// the LOD1 copy is only merge material: never drawn, never hit by rays; remove() gives it its visible back
|
|
99
|
+
for (const l of lods.values()) { l.visible = l.node.visible; l.node.visible = false; }
|
|
120
100
|
// split into cells by bounding-box center; where a LOD1 exists, its meshes join the merge instead (each LOD1 used once)
|
|
121
101
|
const cells = new Map(), box = new THREE.Box3(), v = new THREE.Vector3();
|
|
122
102
|
const lodOf = m => { for (let p = m; p; p = p.parent) { const l = lods.get(p.name); if (l) return l; if (roots.includes(p)) break; } return null; };
|
|
@@ -143,13 +123,13 @@ export function hlod(opts = {}) {
|
|
|
143
123
|
const byMat = new Map();
|
|
144
124
|
for (const m of c.sources) (byMat.get(m.material) || byMat.set(m.material, []).get(m.material)).push(m);
|
|
145
125
|
for (const [mat, ms] of byMat) {
|
|
146
|
-
const p = new THREE.Mesh(
|
|
126
|
+
const p = new THREE.Mesh(mergeCommon(ms.map(m => m.geometry.clone().applyMatrix4(m.matrixWorld))), mat);
|
|
147
127
|
p.name = 'hlod_' + c.key; p.castShadow = castShadow; p.receiveShadow = true;
|
|
148
128
|
p.matrixAutoUpdate = false; p.visible = false; p.raycast = noRaycast;
|
|
149
129
|
group.add(p); c.proxy.push(p);
|
|
150
130
|
}
|
|
151
131
|
delete c.sources;
|
|
152
|
-
c.watch =
|
|
132
|
+
c.watch = watch(c);
|
|
153
133
|
api.cells.push(c);
|
|
154
134
|
yield;
|
|
155
135
|
}
|
|
@@ -159,9 +139,9 @@ export function hlod(opts = {}) {
|
|
|
159
139
|
/** Unregister: restore originals, release proxies */
|
|
160
140
|
remove() {
|
|
161
141
|
h.removed = true; handles.delete(h);
|
|
162
|
-
for (const c of list) { c.watch?.remove();
|
|
142
|
+
for (const c of list) { setFar(c, false); c.watch?.remove(); for (const p of c.proxy) p.geometry.dispose(); for (const m of c.originals) delete m.userData.hlod; }
|
|
163
143
|
api.cells = api.cells.filter(c => !list.includes(c));
|
|
164
|
-
for (const l of lods.values())
|
|
144
|
+
for (const l of lods.values()) l.node.visible = l.visible;
|
|
165
145
|
e.detach(group); // proxies share the originals' materials and are never ray-registered: geometries were disposed above
|
|
166
146
|
},
|
|
167
147
|
};
|
|
@@ -177,7 +157,7 @@ export function hlod(opts = {}) {
|
|
|
177
157
|
const src = handles.size ? e.stream.sources(FULL) : [];
|
|
178
158
|
for (const h of handles) {
|
|
179
159
|
const srcs = src.map(f => ({ x: f.x, z: f.z, n: f.reach(h.near) }));
|
|
180
|
-
for (const c of h.cells) if (c.proxy.length) setFar(c, isFar(c, srcs) && c.originals.every(m =>
|
|
160
|
+
for (const c of h.cells) if (c.proxy.length) setFar(c, isFar(c, srcs) && c.originals.every(m => isShown(m) && isUnder(m, e.scene)));
|
|
181
161
|
}
|
|
182
162
|
},
|
|
183
163
|
};
|
|
@@ -195,6 +175,8 @@ export function hlod(opts = {}) {
|
|
|
195
175
|
return api;
|
|
196
176
|
},
|
|
197
177
|
frame(dt) { if ((timer += dt) >= 0.25) { timer = 0; api.update(); } },
|
|
178
|
+
// unloaded or rolled back: proxies go, far originals come back off the batch layer
|
|
179
|
+
dispose() { for (const h of [...handles]) h.remove(); },
|
|
198
180
|
describe() { return { cells: api.cells.length, far: api.cells.filter(c => c.far).length }; },
|
|
199
181
|
};
|
|
200
182
|
}
|