threedog 0.0.0-stage → 0.2.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 +5 -0
- package/LICENSE +21 -0
- package/README.md +39 -2
- package/core/Animator.js +268 -0
- package/core/Assets.js +256 -0
- package/core/Audio.js +267 -0
- package/core/Baked.js +72 -0
- package/core/Batching.js +247 -0
- package/core/Budget.js +221 -0
- package/core/Clock.js +94 -0
- package/core/Commits.js +77 -0
- package/core/DebugOverrides.js +143 -0
- package/core/Describe.js +145 -0
- package/core/Engine.js +184 -0
- package/core/Events.js +153 -0
- package/core/I18n.js +94 -0
- package/core/Input.js +245 -0
- package/core/Inspect.js +77 -0
- package/core/InspectScene.js +191 -0
- package/core/Jobs.js +146 -0
- package/core/Loading.js +149 -0
- package/core/MaterialInfo.js +32 -0
- package/core/Ops.js +256 -0
- package/core/Random.js +52 -0
- package/core/Rays.js +160 -0
- package/core/SaveStore.js +85 -0
- package/core/Saves.js +254 -0
- package/core/Stream.js +279 -0
- package/core/Threads.js +158 -0
- package/core/UrlState.js +94 -0
- package/core/Vars.js +35 -0
- package/core/Views.js +49 -0
- package/core/actor.js +23 -0
- package/core/assetEntry.js +89 -0
- package/core/assetLoad.js +190 -0
- package/core/assetManifest.js +35 -0
- package/core/assetReport.js +83 -0
- package/core/audioRules.js +121 -0
- package/core/audioVoice.js +225 -0
- package/core/batchGroups.js +116 -0
- package/core/canvasBox.js +63 -0
- package/core/catalog.js +169 -0
- package/core/checks.js +67 -0
- package/core/claims.js +51 -0
- package/core/dayTime.js +15 -0
- package/core/debugView.js +76 -0
- package/core/describeRender.js +45 -0
- package/core/describeText.js +143 -0
- package/core/easing.js +34 -0
- package/core/errorCodes.js +205 -0
- package/core/errorHints.js +208 -0
- package/core/errors.js +40 -0
- package/core/events.generated.js +84 -0
- package/core/ground.js +102 -0
- package/core/holds.js +106 -0
- package/core/inputContext.js +69 -0
- package/core/inputDefaults.js +22 -0
- package/core/inputPad.js +35 -0
- package/core/inputPointer.js +48 -0
- package/core/inputTouch.js +48 -0
- package/core/lifecycle.js +69 -0
- package/core/lightWatch.js +56 -0
- package/core/look/coreParts.js +112 -0
- package/core/look/layers.js +136 -0
- package/core/look/part.js +173 -0
- package/core/look/report.js +79 -0
- package/core/look/write.js +86 -0
- package/core/loop.js +200 -0
- package/core/math.js +33 -0
- package/core/modules.js +196 -0
- package/core/movement.js +19 -0
- package/core/mulberry32.js +14 -0
- package/core/opsAtomic.js +31 -0
- package/core/opsCheck.js +97 -0
- package/core/opsFail.js +20 -0
- package/core/opsGuard.js +26 -0
- package/core/opsHistory.js +27 -0
- package/core/opsRun.js +77 -0
- package/core/page.js +78 -0
- package/core/params.js +132 -0
- package/core/pureWorker.js +5 -0
- package/core/renamed.js +21 -0
- package/core/saveApply.js +128 -0
- package/core/saveFiles.js +139 -0
- package/core/saveIds.js +53 -0
- package/core/saveVersions.js +97 -0
- package/core/scatter.js +92 -0
- package/core/sceneMethods.js +100 -0
- package/core/screenToGround.js +39 -0
- package/core/services.js +73 -0
- package/core/session.js +171 -0
- package/core/shadowTypes.js +15 -0
- package/core/skip.js +104 -0
- package/core/startup.js +135 -0
- package/core/streamCells.js +24 -0
- package/core/streamSources.js +73 -0
- package/core/styleParts.js +96 -0
- package/core/targeting.js +64 -0
- package/core/thingExplain.js +68 -0
- package/core/thingOps.js +168 -0
- package/core/things.js +212 -0
- package/core/threadPure.js +120 -0
- package/core/threadServe.js +25 -0
- package/core/tier.js +11 -0
- package/core/util.js +11 -0
- package/core/validate.js +204 -0
- package/docs/AI.md +123 -0
- package/docs/API.md +83 -0
- package/docs/CODEMAP.md +347 -0
- package/docs/COMMANDS.md +108 -0
- package/docs/CONVENTIONS.md +145 -0
- package/docs/PERF.md +217 -0
- package/docs/THREE.md +86 -0
- package/docs/api/ambience.md +15 -0
- package/docs/api/assets.md +62 -0
- package/docs/api/audio.md +53 -0
- package/docs/api/budget.md +40 -0
- package/docs/api/cameraRig.md +120 -0
- package/docs/api/characters.md +144 -0
- package/docs/api/clock.md +7 -0
- package/docs/api/collision.md +39 -0
- package/docs/api/content.md +64 -0
- package/docs/api/dialogue.md +39 -0
- package/docs/api/engine.md +199 -0
- package/docs/api/entities.md +61 -0
- package/docs/api/events.md +95 -0
- package/docs/api/flow.md +27 -0
- package/docs/api/grids.md +11 -0
- package/docs/api/ground.md +16 -0
- package/docs/api/hlod.md +34 -0
- package/docs/api/hud.md +31 -0
- package/docs/api/i18n.md +10 -0
- package/docs/api/input.md +24 -0
- package/docs/api/interactions.md +31 -0
- package/docs/api/inventory.md +66 -0
- package/docs/api/jobs.md +10 -0
- package/docs/api/level.md +41 -0
- package/docs/api/lightPool.md +56 -0
- package/docs/api/music.md +34 -0
- package/docs/api/nav.md +26 -0
- package/docs/api/net.md +14 -0
- package/docs/api/openWorld.md +24 -0
- package/docs/api/particles.md +41 -0
- package/docs/api/photo.md +15 -0
- package/docs/api/post.md +10 -0
- package/docs/api/quests.md +36 -0
- package/docs/api/rays.md +26 -0
- package/docs/api/rigid.md +84 -0
- package/docs/api/saves.md +32 -0
- package/docs/api/settings.md +36 -0
- package/docs/api/sky.md +58 -0
- package/docs/api/stream.md +31 -0
- package/docs/api/style.md +134 -0
- package/docs/api/terrain.md +34 -0
- package/docs/api/timeline.md +39 -0
- package/docs/api/tools.md +57 -0
- package/docs/api/triggers.md +56 -0
- package/docs/api/vars.md +9 -0
- package/docs/api/vegetation.md +52 -0
- package/docs/api/water.md +48 -0
- package/docs/api/weather.md +29 -0
- package/docs/api/world.md +30 -0
- package/docs/recipes/01-new-game.md +148 -0
- package/docs/recipes/02-npc.md +167 -0
- package/docs/recipes/03-items-pickups.md +158 -0
- package/docs/recipes/04-quests.md +83 -0
- package/docs/recipes/05-props-bake.md +159 -0
- package/docs/recipes/06-clock-events.md +117 -0
- package/docs/recipes/07-flow-scenes-pause.md +132 -0
- package/docs/recipes/08-weather-sky.md +74 -0
- package/docs/recipes/09-style-pack.md +234 -0
- package/docs/recipes/10-blender-level.md +67 -0
- package/docs/recipes/11-vehicles.md +55 -0
- package/docs/recipes/12-navmesh.md +79 -0
- package/docs/recipes/13-animation.md +149 -0
- package/docs/recipes/14-custom-module.md +91 -0
- package/docs/recipes/15-perf.md +78 -0
- package/docs/recipes/16-dev-bridge.md +180 -0
- package/docs/recipes/18-world.md +185 -0
- package/docs/recipes/19-shooting-picking.md +76 -0
- package/docs/recipes/20-content-actions-save.md +176 -0
- package/docs/recipes/21-camera.md +153 -0
- package/docs/recipes/22-shop-gold.md +107 -0
- package/docs/recipes/23-ops.md +175 -0
- package/docs/recipes/26-ui-parts.md +138 -0
- package/docs/recipes/27-net.md +96 -0
- package/docs/recipes/28-terrain.md +80 -0
- package/docs/recipes/29-grid.md +87 -0
- package/docs/recipes/30-templates.md +131 -0
- package/docs/recipes/31-audio.md +126 -0
- package/docs/recipes/32-action-game.md +33 -0
- package/docs/recipes/33-stream-sources.md +37 -0
- package/docs/recipes/34-environment-lighting.md +36 -0
- package/docs/recipes/35-style-from-reference.md +89 -0
- package/docs/recipes/36-sky-ground-plant-looks.md +116 -0
- package/docs/recipes/37-terrain-look-hooks.md +97 -0
- package/docs/recipes/38-environment-look-hooks.md +83 -0
- package/docs/recipes/40-scene.md +108 -0
- package/docs/recipes/41-thing-registry.md +93 -0
- package/docs/recipes/42-terrain-shape.md +64 -0
- package/docs/recipes/43-shader-patches-surface-looks.md +120 -0
- package/docs/recipes/44-water-weather-look-hooks.md +135 -0
- package/docs/recipes/45-cascaded-shadows.md +51 -0
- package/docs/recipes/46-blender-art-route.md +114 -0
- package/docs/recipes/47-island-snow-backdrop.md +44 -0
- package/docs/recipes/48-make-material.md +70 -0
- package/docs/recipes/49-game-module-contract.md +71 -0
- package/docs/recipes/50-own-renderer.md +12 -0
- package/docs/recipes/51-capability-catalog.md +63 -0
- package/docs/recipes/52-look.md +108 -0
- package/examples/action/DESIGN.md +3 -0
- package/examples/action/GAMEMAP.md +127 -0
- package/examples/action/content/actions.js +8 -0
- package/examples/action/content/audio.js +9 -0
- package/examples/action/content/index.js +10 -0
- package/examples/action/content/items.js +4 -0
- package/examples/action/content/places.js +4 -0
- package/examples/action/content/props.js +11 -0
- package/examples/action/content/templates.js +10 -0
- package/examples/action/content/views.js +6 -0
- package/examples/action/look.js +5 -0
- package/examples/action/main.js +137 -0
- package/examples/action/models.js +25 -0
- package/examples/sheepisland/GAMEMAP.md +107 -0
- package/examples/sheepisland/content/index.js +6 -0
- package/examples/sheepisland/content/props.js +19 -0
- package/examples/sheepisland/content/templates.js +5 -0
- package/examples/sheepisland/content/vegetation.js +8 -0
- package/examples/sheepisland/main.js +71 -0
- package/examples/sheepisland/params.js +25 -0
- package/examples/sheepisland/style/index.js +79 -0
- package/examples/sheepisland/style/models.js +59 -0
- package/examples/sheepisland/views.js +9 -0
- package/examples/styletest/GAMEMAP.md +135 -0
- package/examples/styletest/content/index.js +9 -0
- package/examples/styletest/content/items.js +8 -0
- package/examples/styletest/content/npcs.js +8 -0
- package/examples/styletest/content/places.js +5 -0
- package/examples/styletest/content/props.js +16 -0
- package/examples/styletest/content/templates.js +9 -0
- package/examples/styletest/content/vegetation.js +31 -0
- package/examples/styletest/look.js +11 -0
- package/examples/styletest/main.js +95 -0
- package/examples/styletest/models.js +87 -0
- package/examples/styletest/overrides.js +33 -0
- package/examples/styletest/panel.js +135 -0
- package/examples/styletest/params.js +32 -0
- package/examples/styletest/views.js +31 -0
- package/examples/world/DESIGN.md +5 -0
- package/examples/world/GAMEMAP.md +171 -0
- package/examples/world/content/actions.js +8 -0
- package/examples/world/content/audio.js +25 -0
- package/examples/world/content/bodies.js +12 -0
- package/examples/world/content/containers.js +4 -0
- package/examples/world/content/dialogues.js +33 -0
- package/examples/world/content/index.js +17 -0
- package/examples/world/content/items.js +10 -0
- package/examples/world/content/npcs.js +14 -0
- package/examples/world/content/pickups.js +11 -0
- package/examples/world/content/places.js +6 -0
- package/examples/world/content/props.js +12 -0
- package/examples/world/content/quests.js +15 -0
- package/examples/world/content/rules.js +23 -0
- package/examples/world/content/templates.js +5 -0
- package/examples/world/content/vegetation.js +32 -0
- package/examples/world/main.js +168 -0
- package/examples/world/models.js +28 -0
- package/index.d.ts +306 -0
- package/index.js +122 -0
- package/llms.txt +61 -0
- package/modules/ambience/Ambience.js +186 -0
- package/modules/camera/FirstPersonCamera.js +131 -0
- package/modules/camera/FixedCamera.js +162 -0
- package/modules/camera/FollowCamera.js +91 -0
- package/modules/camera/RtsCamera.js +132 -0
- package/modules/camera/common.js +182 -0
- package/modules/camera/index.js +11 -0
- package/modules/camera/projection.js +34 -0
- package/modules/characters/Character.js +235 -0
- package/modules/characters/NPC.js +242 -0
- package/modules/characters/assetModel.js +42 -0
- package/modules/characters/astar.js +66 -0
- package/modules/characters/behaviors.js +72 -0
- package/modules/characters/footsteps.js +13 -0
- package/modules/characters/index.js +215 -0
- package/modules/characters/moveHelpers.js +29 -0
- package/modules/characters/movers/common.js +62 -0
- package/modules/characters/movers/rapier.js +74 -0
- package/modules/characters/movers/simple.js +43 -0
- package/modules/characters/npcAvoid.js +129 -0
- package/modules/characters/npcSim.js +150 -0
- package/modules/characters/npcView.js +42 -0
- package/modules/characters/pathAsync.js +113 -0
- package/modules/characters/pathJob.js +62 -0
- package/modules/characters/pathWorker.js +7 -0
- package/modules/characters/playerStrings.js +12 -0
- package/modules/characters/proceduralRig.js +58 -0
- package/modules/characters/useModel.js +22 -0
- package/modules/characters/walkTo.js +58 -0
- package/modules/collision/Collision.js +274 -0
- package/modules/collision/grid.js +63 -0
- package/modules/content/explain.js +13 -0
- package/modules/content/ids.js +95 -0
- package/modules/content/index.js +154 -0
- package/modules/content/loader.js +190 -0
- package/modules/content/models.js +69 -0
- package/modules/content/packs.js +69 -0
- package/modules/content/props.js +89 -0
- package/modules/content/rules.js +134 -0
- package/modules/content/templates.js +189 -0
- package/modules/debug/DebugPanel.js +174 -0
- package/modules/entities/Entities.js +243 -0
- package/modules/entities/build.js +25 -0
- package/modules/entities/index.js +4 -0
- package/modules/flow/index.js +101 -0
- package/modules/gameplay/Container.js +227 -0
- package/modules/gameplay/Containers.js +89 -0
- package/modules/gameplay/Dialogue.js +219 -0
- package/modules/gameplay/Interactions.js +253 -0
- package/modules/gameplay/Inventory.js +224 -0
- package/modules/gameplay/Quests.js +205 -0
- package/modules/gameplay/boxOps.js +60 -0
- package/modules/gameplay/dialogueBox.js +48 -0
- package/modules/gameplay/interactionPrompt.js +28 -0
- package/modules/gameplay/inventoryOps.js +137 -0
- package/modules/gameplay/pickups.js +115 -0
- package/modules/gameplay/questLog.js +54 -0
- package/modules/gameplay/questSave.js +71 -0
- package/modules/grid/Grid.js +184 -0
- package/modules/grid/Layer.js +142 -0
- package/modules/grid/index.js +236 -0
- package/modules/grid/ops.js +73 -0
- package/modules/grid/preview.js +85 -0
- package/modules/grid/tiles.js +79 -0
- package/modules/hlod/index.js +167 -0
- package/modules/hud/index.js +167 -0
- package/modules/hud/parts.js +80 -0
- package/modules/level/geometry.js +46 -0
- package/modules/level/heightfield.js +160 -0
- package/modules/level/index.js +233 -0
- package/modules/level/nodes.js +84 -0
- package/modules/lights/index.js +227 -0
- package/modules/music/Music.js +294 -0
- package/modules/music/index.js +2 -0
- package/modules/music/rules.js +28 -0
- package/modules/nav/index.js +156 -0
- package/modules/nav/navPath.js +17 -0
- package/modules/net/Client.js +137 -0
- package/modules/net/Host.js +117 -0
- package/modules/net/Net.js +49 -0
- package/modules/net/index.js +77 -0
- package/modules/net/sync.js +114 -0
- package/modules/net/transports.js +118 -0
- package/modules/particles/Particles.js +179 -0
- package/modules/particles/effect.js +112 -0
- package/modules/particles/shaders.js +28 -0
- package/modules/photo/Photo.js +146 -0
- package/modules/rigid/RigidBodies.js +265 -0
- package/modules/rigid/Vehicles.js +97 -0
- package/modules/rigid/sync.js +158 -0
- package/modules/settings/Settings.js +297 -0
- package/modules/settings/apply.js +21 -0
- package/modules/settings/index.js +3 -0
- package/modules/settings/sections.js +156 -0
- package/modules/settings/strings.js +53 -0
- package/modules/settings/view.js +65 -0
- package/modules/sky/Sky.js +259 -0
- package/modules/sky/calendar.js +80 -0
- package/modules/sky/cascades.js +125 -0
- package/modules/sky/clouds.js +79 -0
- package/modules/sky/domeLayers.js +33 -0
- package/modules/sky/environment.js +141 -0
- package/modules/sky/fog.js +139 -0
- package/modules/sky/frame.js +77 -0
- package/modules/sky/layers.js +69 -0
- package/modules/sky/look.js +51 -0
- package/modules/sky/lookFog.js +80 -0
- package/modules/sky/lookShadow.js +50 -0
- package/modules/sky/lookSky.js +108 -0
- package/modules/sky/schedule.js +80 -0
- package/modules/sky/shader.js +96 -0
- package/modules/sky/shadow.js +74 -0
- package/modules/sky/skyModule.js +60 -0
- package/modules/terrain/ChunkManager.js +260 -0
- package/modules/terrain/chunkJob.js +19 -0
- package/modules/terrain/chunkLevels.js +40 -0
- package/modules/terrain/chunkQueries.js +42 -0
- package/modules/terrain/chunkWorker.js +5 -0
- package/modules/terrain/index.js +118 -0
- package/modules/terrain/lookGround.js +61 -0
- package/modules/terrain/mountTerrain.js +32 -0
- package/modules/terrain/terrainColorMap.js +41 -0
- package/modules/terrain/terrainDefaults.js +39 -0
- package/modules/terrain/terrainEdit.js +139 -0
- package/modules/terrain/terrainGen.js +155 -0
- package/modules/terrain/terrainIsland.js +131 -0
- package/modules/terrain/terrainMesh.js +92 -0
- package/modules/terrain/terrainShape.js +108 -0
- package/modules/terrain/terrainShapeMain.js +41 -0
- package/modules/terrain/terrainTexture.js +44 -0
- package/modules/timeline/Timeline.js +253 -0
- package/modules/timeline/Tween.js +114 -0
- package/modules/timeline/letterbox.js +24 -0
- package/modules/timeline/shots.js +90 -0
- package/modules/triggers/index.js +268 -0
- package/modules/vegetation/Vegetation.js +256 -0
- package/modules/vegetation/groundChunks.js +177 -0
- package/modules/vegetation/index.js +43 -0
- package/modules/vegetation/lookWind.js +37 -0
- package/modules/vegetation/modelGeometry.js +21 -0
- package/modules/water/Water.js +160 -0
- package/modules/water/look.js +80 -0
- package/modules/water/surface.js +88 -0
- package/modules/weather/Weather.js +242 -0
- package/modules/weather/look.js +75 -0
- package/modules/weather/particles.js +92 -0
- package/modules/weather/shaders.js +49 -0
- package/modules/weather/strings.js +15 -0
- package/modules/world/World.js +231 -0
- package/modules/world/cells.js +42 -0
- package/modules/world/explain.js +11 -0
- package/modules/world/index.js +71 -0
- package/modules/world/persist.js +107 -0
- package/modules/world/pos.js +20 -0
- package/modules/world/records.js +89 -0
- package/modules/world/sim.js +175 -0
- package/modules/world/simFar.js +82 -0
- package/modules/world/state.js +115 -0
- package/modules/world/thingSource.js +44 -0
- package/modules/world/views.js +182 -0
- package/package.json +66 -4
- package/presets.js +96 -0
- package/render/PostFX.js +240 -0
- package/render/detail.js +105 -0
- package/render/effects.js +144 -0
- package/render/engineUniforms.js +23 -0
- package/render/fuse.js +84 -0
- package/render/lighting.js +100 -0
- package/render/lights.js +18 -0
- package/render/lookSurface.js +161 -0
- package/render/materials.js +220 -0
- package/render/patches.js +252 -0
- package/render/postLook.js +86 -0
- package/render/surface.js +69 -0
- package/render/uniformDecl.js +29 -0
- package/types/common.d.ts +34 -0
- package/types/core.d.ts +1965 -0
- package/types/gameplay.d.ts +1822 -0
- package/types/generated/core/Audio.d.ts +200 -0
- package/types/generated/core/Batching.d.ts +47 -0
- package/types/generated/core/Budget.d.ts +90 -0
- package/types/generated/core/Commits.d.ts +31 -0
- package/types/generated/core/DebugOverrides.d.ts +52 -0
- package/types/generated/core/Events.d.ts +89 -0
- package/types/generated/core/I18n.d.ts +30 -0
- package/types/generated/core/Input.d.ts +118 -0
- package/types/generated/core/Jobs.d.ts +41 -0
- package/types/generated/core/Ops.d.ts +203 -0
- package/types/generated/core/Random.d.ts +49 -0
- package/types/generated/core/Rays.d.ts +49 -0
- package/types/generated/core/Saves.d.ts +162 -0
- package/types/generated/core/Stream.d.ts +93 -0
- package/types/generated/core/Threads.d.ts +82 -0
- package/types/generated/core/Views.d.ts +33 -0
- package/types/generated/core/audioVoice.d.ts +47 -0
- package/types/generated/core/page.d.ts +18 -0
- package/types/generated/core/session.d.ts +48 -0
- package/types/generated/modules/ambience/Ambience.d.ts +48 -0
- package/types/generated/modules/debug/DebugPanel.d.ts +24 -0
- package/types/generated/modules/flow/index.d.ts +10 -0
- package/types/generated/modules/grid/Grid.d.ts +151 -0
- package/types/generated/modules/grid/Layer.d.ts +65 -0
- package/types/generated/modules/grid/index.d.ts +86 -0
- package/types/generated/modules/hlod/index.d.ts +11 -0
- package/types/generated/modules/hud/index.d.ts +10 -0
- package/types/generated/modules/lights/index.d.ts +13 -0
- package/types/generated/modules/music/Music.d.ts +111 -0
- package/types/generated/modules/net/Net.d.ts +34 -0
- package/types/generated/modules/net/index.d.ts +53 -0
- package/types/generated/modules/net/transports.d.ts +58 -0
- package/types/generated/modules/particles/Particles.d.ts +69 -0
- package/types/generated/modules/sky/Sky.d.ts +145 -0
- package/types/generated/modules/sky/skyModule.d.ts +10 -0
- package/types/generated/modules/timeline/Timeline.d.ts +51 -0
- package/types/generated/modules/water/Water.d.ts +29 -0
- package/types/generated/modules/weather/Weather.d.ts +62 -0
- package/types/generated/modules/world/World.d.ts +242 -0
- package/types/generated/modules/world/index.d.ts +15 -0
- package/types/generated/render/PostFX.d.ts +125 -0
- package/types/generated/render/materials.d.ts +100 -0
- package/types/generated/render/patches.d.ts +41 -0
- package/types/generated/ui/Focus.d.ts +11 -0
- package/types/generated/ui/LoadingScreen.d.ts +2 -0
- package/types/generated/ui/UI.d.ts +57 -0
- package/types/nav.d.ts +52 -0
- package/types/physics.d.ts +592 -0
- package/types/style.d.ts +638 -0
- package/types/worker.d.ts +11 -0
- package/types/world.d.ts +772 -0
- package/ui/Focus.js +51 -0
- package/ui/LoadingScreen.js +42 -0
- package/ui/Parts.js +199 -0
- package/ui/UI.js +167 -0
- package/ui/defaults.js +85 -0
- package/ui/theme.js +124 -0
- package/ui/touchPart.js +49 -0
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// Timeline camera and path steps (helper of Timeline.js): a shot takes the camera over with engine.takeCamera (core/holds.js) and gives it back when the run ends;
|
|
2
|
+
// a path moves any object (a character, the camera) along a spline. Each function takes the Timeline as `t`.
|
|
3
|
+
import * as THREE from 'three';
|
|
4
|
+
import { vec3 as v3 } from '../../core/math.js';
|
|
5
|
+
import { surfaceOr } from '../../core/ground.js';
|
|
6
|
+
|
|
7
|
+
/** Camera: { from?, to: { position, lookAt }, duration, ease, fov } or { release: true } */
|
|
8
|
+
export function cameraStep(t, c, run) {
|
|
9
|
+
const e = t.engine, cam = e.camera;
|
|
10
|
+
if (c.release) { releaseCamera(t, run); return Promise.resolve(); }
|
|
11
|
+
const st = takeCamera(t, run);
|
|
12
|
+
let fromP, fromL, fromFov, toP, toL;
|
|
13
|
+
const lookOf = l => l?.isObject3D ? l.position : l; // may look at a moving object
|
|
14
|
+
return t._timed(run, {
|
|
15
|
+
duration: c.duration ?? 1, ease: c.ease ?? 'inOutCubic',
|
|
16
|
+
start: () => {
|
|
17
|
+
fromP = c.from?.position ? v3(c.from.position) : cam.position.clone();
|
|
18
|
+
toP = c.to?.position ? v3(c.to.position) : fromP.clone();
|
|
19
|
+
// start look-at: use it if given, otherwise keep the current view direction at the same distance as the target
|
|
20
|
+
if (c.from?.lookAt) fromL = v3(lookOf(c.from.lookAt));
|
|
21
|
+
else { const d = c.to?.lookAt ? Math.max(1, cam.position.distanceTo(v3(lookOf(c.to.lookAt)))) : 10; fromL = cam.getWorldDirection(new THREE.Vector3()).multiplyScalar(d).add(cam.position); }
|
|
22
|
+
toL = c.to?.lookAt ? v3(lookOf(c.to.lookAt)) : fromL.clone();
|
|
23
|
+
fromFov = c.from?.fov ?? cam.fov;
|
|
24
|
+
},
|
|
25
|
+
step: k => {
|
|
26
|
+
if (c.to?.lookAt?.isObject3D) toL.copy(c.to.lookAt.position);
|
|
27
|
+
cam.position.lerpVectors(fromP, toP, k);
|
|
28
|
+
st.look.lerpVectors(fromL, toL, k);
|
|
29
|
+
cam.lookAt(st.look);
|
|
30
|
+
if (c.fov != null) { cam.fov = fromFov + (c.fov - fromFov) * k; cam.updateProjectionMatrix(); }
|
|
31
|
+
st.override.focus.copy(st.look);
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
/** */
|
|
36
|
+
function takeCamera(t, run) {
|
|
37
|
+
const e = t.engine;
|
|
38
|
+
if (!run.cam) {
|
|
39
|
+
// a claim of its own (engine.takeCamera): a named view or a game holding the camera keeps its claim and gets the camera back afterwards.
|
|
40
|
+
// The owner carries the run id so two overlapping runs are two holders, not one overwriting the other.
|
|
41
|
+
const override = { owner: 'timeline:' + run.id, id: run.id, focus: e.focus.clone() };
|
|
42
|
+
run.cam = { fov: e.camera.fov, look: new THREE.Vector3(), override, hold: e.takeCamera(override.owner, override) };
|
|
43
|
+
}
|
|
44
|
+
return run.cam;
|
|
45
|
+
}
|
|
46
|
+
/** */
|
|
47
|
+
export function releaseCamera(t, run) {
|
|
48
|
+
const st = run.cam; if (!st) return;
|
|
49
|
+
run.cam = null;
|
|
50
|
+
const e = t.engine;
|
|
51
|
+
st.hold.remove();
|
|
52
|
+
if (e.camera.fov !== st.fov) { e.camera.fov = st.fov; e.camera.updateProjectionMatrix(); }
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Path: { object, points, duration, ease, lookAhead, ground, closed, curve: 'catmullrom'|'centripetal'|'chordal', tension } */
|
|
56
|
+
export function pathStep(t, p, run) {
|
|
57
|
+
// a character (Character) can be passed directly
|
|
58
|
+
const e = t.engine, chr = p.object?.root?.isObject3D ? p.object : null, obj = chr ? chr.root : p.object;
|
|
59
|
+
if (!obj || !p.points?.length) return Promise.resolve();
|
|
60
|
+
const pts = p.points.map(x => v3(x));
|
|
61
|
+
if (pts.length === 1) pts.unshift(obj.position.clone());
|
|
62
|
+
const curve = new THREE.CatmullRomCurve3(pts, !!p.closed, p.curve ?? 'centripetal', p.tension ?? 0.5);
|
|
63
|
+
const isCam = obj === e.camera;
|
|
64
|
+
const st = isCam ? takeCamera(t, run) : null;
|
|
65
|
+
const pos = new THREE.Vector3(), ahead = new THREE.Vector3();
|
|
66
|
+
return t._timed(run, {
|
|
67
|
+
duration: p.duration ?? 2, ease: p.ease ?? 'inOutSine',
|
|
68
|
+
step: k => {
|
|
69
|
+
curve.getPointAt(Math.min(1, Math.max(0, k)), pos);
|
|
70
|
+
if (p.ground) pos.y = surfaceOr(e, pos.x, pos.z, undefined, pos.y) + (typeof p.ground === 'number' ? p.ground : 0);
|
|
71
|
+
obj.position.copy(pos);
|
|
72
|
+
if (p.lookAhead) {
|
|
73
|
+
const k2 = Math.min(1, k + p.lookAhead);
|
|
74
|
+
if (k2 - k > 1e-4) {
|
|
75
|
+
curve.getPointAt(k2, ahead);
|
|
76
|
+
if (p.upright !== false && !isCam) ahead.y = pos.y; // keep the character upright, only turn the horizontal heading
|
|
77
|
+
obj.lookAt(ahead);
|
|
78
|
+
if (chr && 'facing' in chr) chr.facing = obj.rotation.y; // sync the character's own facing too, so it does not turn back after the walk
|
|
79
|
+
if (isCam) st.look.copy(ahead);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if (isCam) st.override.focus.copy(pos);
|
|
83
|
+
},
|
|
84
|
+
}).then(r => {
|
|
85
|
+
// the path moved the model, not the mover: the character's world record (the player's) catches up once, so a save right after the cutscene has the new
|
|
86
|
+
// place
|
|
87
|
+
if (chr?.recordId && chr.syncRecord) e.ops.allow(() => chr.syncRecord());
|
|
88
|
+
return r;
|
|
89
|
+
});
|
|
90
|
+
}
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
// Trigger zone module: invisible regions in the world that notify you when the player (or something else) enters, leaves or stays inside.
|
|
2
|
+
// Use for: auto-opening a door, showing a place name on entering a village, traps, starting dialogue at a story spot, stopping music when leaving an area...
|
|
3
|
+
//
|
|
4
|
+
// const door = engine.triggers.add({
|
|
5
|
+
// shape: 'box', position: { x: 4, y: 0, z: -2 }, size: [3, 3, 2],
|
|
6
|
+
// tag: 'door', onEnter: t => openDoor(), onExit: t => closeDoor(),
|
|
7
|
+
// });
|
|
8
|
+
// door.remove(); // remove when no longer needed
|
|
9
|
+
// engine.events.on('trigger:enter', ({ tag }) => ...); // or listen to the events globally
|
|
10
|
+
// engine.triggers.fromMarkers(); // every trigger_xxx marker in the level becomes a trigger zone (tag = xxx)
|
|
11
|
+
//
|
|
12
|
+
// Parameters of add():
|
|
13
|
+
// shape 'sphere' | 'box' (can rotate) | 'cylinder' (vertical, default)
|
|
14
|
+
// position center { x, y, z } / Vector3 / Object3D / [x, y, z]. For box and cylinder, y is the bottom height; if y is omitted, the ground height there is used
|
|
15
|
+
// radius sphere/cylinder radius (default 1.5); size [width, height, depth] (box, default [2,2,2]); height cylinder height (default 3)
|
|
16
|
+
// rotation box rotation around the Y axis in radians (default 0)
|
|
17
|
+
// onEnter(t, who) / onExit(t, who) / onStay(dt, t, who) callbacks; who is the position that entered
|
|
18
|
+
// once fire on the first enter only (default false; exit follows at once); t.used is true afterwards, and a new playthrough (engine.session) re-arms it
|
|
19
|
+
// enabled false pauses detection (handle.enabled can be changed any time)
|
|
20
|
+
// tag name carried in events, for shared handling
|
|
21
|
+
// who what can trigger: default is engine.actorPosition() (the player, or what engine.actor names; engine.focus without a player); or a Vector3 / Object3D, or a function returning an array of positions () => [p1, p2]
|
|
22
|
+
// (a zone with a function / object `who` is checked every step; zones with the default `who` cost nothing while the actor is far away)
|
|
23
|
+
// cooldown seconds after leaving during which enter will not fire again (stops edge jitter from re-triggering), default 0
|
|
24
|
+
// Returned handle: { tag, inside, enabled, used, remove(), contains(p) }
|
|
25
|
+
//
|
|
26
|
+
// Events: trigger:enter / trigger:exit with { tag, trigger, who }. On removal (remove / clear) and at the end of a playthrough, zones still occupied send exit first (who is null)
|
|
27
|
+
// A playthrough ending (engine.session newGame / load / quit) resets every zone: occupied ones exit, cooldowns clear, once zones are re-armed;
|
|
28
|
+
// so the zone around the spawn point fires enter again in the new playthrough. Zones added during play belong to the game: wrap them in engine.session.track(h).
|
|
29
|
+
//
|
|
30
|
+
// Debug display: triggers({ debug: true }) or engine.triggers.setDebug(true) draws all trigger zones as wireframes.
|
|
31
|
+
// Look comes from style.triggers = { debugColor, debugOpacity } of the style pack; neutral gray if absent (a dev overlay: its line material is not a makeMaterial role).
|
|
32
|
+
// In dev builds F4 (action triggersDebug, rebindable) toggles the display; release builds bind no key unless triggers({ keys }) names one.
|
|
33
|
+
import * as THREE from 'three';
|
|
34
|
+
import { checkOptions, DEV } from '../../core/validate.js';
|
|
35
|
+
import { readParams } from '../../core/params.js';
|
|
36
|
+
|
|
37
|
+
// Zones are indexed by the grid cells their bounding box covers, so a step looks at the zones near the actor instead of every zone. A zone with its own `who`
|
|
38
|
+
// (any position, unknown until it runs) or one covering more than MAX_CELLS cells goes to the always-checked `_global` list.
|
|
39
|
+
const CELL = 16, MAX_CELLS = 64, KEY = 1048576, PAD = 0.01; // PAD: contains() is inclusive, so a point exactly on the edge must still find the zone's cell
|
|
40
|
+
const bySeqDesc = (a, b) => b._seq - a._seq; // the order zones have always run in: newest first
|
|
41
|
+
|
|
42
|
+
const ADD_KEYS = ['shape', 'position', 'radius', 'size', 'height', 'rotation', 'onEnter', 'onExit', 'onStay', 'once', 'enabled', 'tag', 'who', 'cooldown', 'userData'];
|
|
43
|
+
|
|
44
|
+
const STRINGS = {
|
|
45
|
+
'zh-CN': { 'triggers.debug': '显示触发区' },
|
|
46
|
+
en: { 'triggers.debug': 'Show triggers' },
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export class Triggers {
|
|
50
|
+
constructor(engine, { debug = false, action = 'triggersDebug', keys = DEV ? ['F4'] : [] } = {}) {
|
|
51
|
+
this.engine = engine;
|
|
52
|
+
this._list = [];
|
|
53
|
+
this.debug = false;
|
|
54
|
+
this.action = action;
|
|
55
|
+
this._one = [null]; // by default "who" is a single position: reuse this array to avoid per-frame allocation
|
|
56
|
+
this._custom = [null];
|
|
57
|
+
this._scan = []; // zones update() visits this step (a snapshot: callbacks may add / remove zones)
|
|
58
|
+
this._cells = new Map(); // grid cell -> zones whose bounding box covers it
|
|
59
|
+
this._global = []; // zones checked every step (custom `who`, or too large for the grid)
|
|
60
|
+
this._busy = new Set(); // zones that need a visit even when nobody is near: occupied, or cooling down
|
|
61
|
+
this._seq = 0; this._stamp = 0;
|
|
62
|
+
this._debugGroup = null;
|
|
63
|
+
engine.i18n.add(STRINGS);
|
|
64
|
+
/** @internal the debug toggle has a key */ this._keyed = keys.length > 0;
|
|
65
|
+
if (this._keyed) engine.input.define(action, keys, 'triggers.debug');
|
|
66
|
+
if (debug) this.setDebug(true);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
add(opts = {}) {
|
|
70
|
+
checkOptions('triggers.add()', opts, ADD_KEYS);
|
|
71
|
+
const { shape = 'cylinder', position: at = {}, radius = 1.5, size = [2, 2, 2], height = 3, rotation = 0, onEnter = null, onExit = null, onStay = null,
|
|
72
|
+
once = false, enabled = true, tag = '', who = null, cooldown = 0, userData = {} } = opts;
|
|
73
|
+
const position = at.isObject3D ? at.position : Array.isArray(at) ? { x: at[0], y: at[1], z: at[2] } : at;
|
|
74
|
+
const e = this.engine, x = position.x ?? 0, z = position.z ?? 0;
|
|
75
|
+
const y = position.y ?? e.surface(x, z);
|
|
76
|
+
const t = {
|
|
77
|
+
shape, x, y, z, radius, hx: size[0] / 2, hy: size[1] / 2, hz: size[2] / 2, sy: size[1], height, rotation,
|
|
78
|
+
c: Math.cos(rotation), s: Math.sin(rotation), onEnter, onExit, onStay, once, enabled, tag, who, cooldown, userData,
|
|
79
|
+
inside: false, used: false, _cool: 0, _mesh: null, _gone: false,
|
|
80
|
+
remove: () => this._remove(t),
|
|
81
|
+
contains: p => this._contains(t, p),
|
|
82
|
+
};
|
|
83
|
+
t._seq = this._seq++; t._span = null;
|
|
84
|
+
this._list.push(t); this._register(t);
|
|
85
|
+
if (this.debug) this._addDebugMesh(t);
|
|
86
|
+
return t;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
_remove(t) { // remove only through the handle t.remove(); zones still occupied send exit first (so music areas and content onExit can clean up)
|
|
90
|
+
const i = this._list.indexOf(t); if (i < 0) return;
|
|
91
|
+
if (t.inside) this._exit(t, null);
|
|
92
|
+
this._list.splice(i, 1); this._unregister(t); this._busy.delete(t);
|
|
93
|
+
t._gone = true;
|
|
94
|
+
if (t._mesh) { t._mesh.parent?.remove(t._mesh); t._mesh.geometry.dispose(); t._mesh = null; }
|
|
95
|
+
}
|
|
96
|
+
_register(t) {
|
|
97
|
+
if (t.who) { this._global.push(t); return; }
|
|
98
|
+
const ex = (t.shape === 'box' ? t.hx * Math.abs(t.c) + t.hz * Math.abs(t.s) : t.radius) + PAD;
|
|
99
|
+
const ez = (t.shape === 'box' ? t.hx * Math.abs(t.s) + t.hz * Math.abs(t.c) : t.radius) + PAD;
|
|
100
|
+
const x0 = Math.floor((t.x - ex) / CELL), x1 = Math.floor((t.x + ex) / CELL), z0 = Math.floor((t.z - ez) / CELL), z1 = Math.floor((t.z + ez) / CELL);
|
|
101
|
+
if ((x1 - x0 + 1) * (z1 - z0 + 1) > MAX_CELLS) { this._global.push(t); return; }
|
|
102
|
+
t._span = [x0, x1, z0, z1];
|
|
103
|
+
for (let i = x0; i <= x1; i++) for (let j = z0; j <= z1; j++) {
|
|
104
|
+
const k = i * KEY + j; let c = this._cells.get(k); if (!c) this._cells.set(k, c = []); c.push(t);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
_unregister(t) {
|
|
108
|
+
const sp = t._span;
|
|
109
|
+
if (!sp) { this._global.splice(this._global.indexOf(t), 1); return; }
|
|
110
|
+
for (let i = sp[0]; i <= sp[1]; i++) for (let j = sp[2]; j <= sp[3]; j++) {
|
|
111
|
+
const k = i * KEY + j, c = this._cells.get(k);
|
|
112
|
+
c.splice(c.indexOf(t), 1); if (!c.length) this._cells.delete(k);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
/** All trigger zones (a new array) */
|
|
116
|
+
list() { return [...this._list]; }
|
|
117
|
+
clear() { for (const t of [...this._list]) this._remove(t); }
|
|
118
|
+
byTag(tag) { return this._list.filter(t => t.tag === tag); }
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Create trigger zones from level markers: each trigger_xxx becomes a zone with tag xxx.
|
|
122
|
+
* Shape and size are read first from the marker's userData.shape / radius / size / height, otherwise derived from object scale:
|
|
123
|
+
* scale (sx, sy, sz) -> box [2sx, 2sy, 2sz] centered on the marker (matches Blender's default cube empty)
|
|
124
|
+
* Callbacks etc. in opts are shared by every zone. Returns an array of created handles.
|
|
125
|
+
* These zones belong to the current level: removed automatically on level change / unload (level.track)
|
|
126
|
+
*/
|
|
127
|
+
fromMarkers(opts = {}) {
|
|
128
|
+
const markers = this.engine.level?.markers || {};
|
|
129
|
+
const out = [];
|
|
130
|
+
for (const m of Object.values(markers)) {
|
|
131
|
+
if (!/^trigger_/i.test(m.name)) continue;
|
|
132
|
+
const u = m.userData || {}, s = m.scale, p = m.position;
|
|
133
|
+
const shape = u.shape || opts.shape || 'box';
|
|
134
|
+
const euler = new THREE.Euler().setFromQuaternion(m.quaternion, 'YXZ');
|
|
135
|
+
const size = u.size || [2 * Math.abs(s.x), 2 * Math.abs(s.y), 2 * Math.abs(s.z)];
|
|
136
|
+
const radius = u.radius ?? Math.max(Math.abs(s.x), Math.abs(s.z));
|
|
137
|
+
const height = u.height ?? 2 * Math.abs(s.y);
|
|
138
|
+
// box/cylinder y is the bottom: marker is the center, so shift down by half the height
|
|
139
|
+
const half = shape === 'box' ? size[1] / 2 : shape === 'cylinder' ? height / 2 : 0;
|
|
140
|
+
const t = this.add({ ...opts, shape, size, radius, height, rotation: euler.y, tag: m.name.slice(8), userData: u,
|
|
141
|
+
position: { x: p.x, y: p.y - half, z: p.z } });
|
|
142
|
+
this.engine.level?.track(t);
|
|
143
|
+
out.push(t);
|
|
144
|
+
}
|
|
145
|
+
return out;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
_contains(t, p) {
|
|
149
|
+
const dx = p.x - t.x, dz = p.z - t.z;
|
|
150
|
+
if (t.shape === 'sphere') { const dy = p.y - t.y; return dx * dx + dy * dy + dz * dz <= t.radius * t.radius; }
|
|
151
|
+
const dy = p.y - t.y;
|
|
152
|
+
if (t.shape === 'box') {
|
|
153
|
+
if (dy < 0 || dy > t.sy) return false;
|
|
154
|
+
const lx = dx * t.c - dz * t.s, lz = dx * t.s + dz * t.c; // same rotation convention as the collision module's rectangle
|
|
155
|
+
return Math.abs(lx) <= t.hx && Math.abs(lz) <= t.hz;
|
|
156
|
+
}
|
|
157
|
+
return dy >= 0 && dy <= t.height && dx * dx + dz * dz <= t.radius * t.radius;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
_defaultWho() {
|
|
161
|
+
const e = this.engine;
|
|
162
|
+
this._one[0] = e.actorPosition(); // engine.actor: the player by default, or the vehicle / squad member the game handed control to
|
|
163
|
+
return this._one;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/** @internal Fixed step: enter / stay / exit for the zones that can change: those near the actor, always-checked ones, occupied or cooling ones */
|
|
167
|
+
update(dt) {
|
|
168
|
+
if (!this._list.length) return;
|
|
169
|
+
const def = this._defaultWho(), scan = this._scan, st = ++this._stamp;
|
|
170
|
+
scan.length = 0;
|
|
171
|
+
for (const t of this._busy) { t._q = st; scan.push(t); }
|
|
172
|
+
const g = this._global;
|
|
173
|
+
for (let i = 0; i < g.length; i++) { const t = g[i]; if (t._q !== st) { t._q = st; scan.push(t); } }
|
|
174
|
+
for (let k = 0; k < def.length; k++) {
|
|
175
|
+
const p = def[k]; if (!p) continue;
|
|
176
|
+
const c = this._cells.get(Math.floor(p.x / CELL) * KEY + Math.floor(p.z / CELL));
|
|
177
|
+
if (c) for (let i = 0; i < c.length; i++) { const t = c[i]; if (t._q !== st) { t._q = st; scan.push(t); } }
|
|
178
|
+
}
|
|
179
|
+
if (scan.length > 1) scan.sort(bySeqDesc); // a callback removing an earlier zone must not make a later one run twice: scan is a snapshot, removed zones are skipped
|
|
180
|
+
for (let i = 0; i < scan.length; i++) {
|
|
181
|
+
const t = scan[i];
|
|
182
|
+
if (t._gone) continue;
|
|
183
|
+
this._visit(t, dt, def);
|
|
184
|
+
if (t._gone) continue;
|
|
185
|
+
if (t.inside || t._cool > 0) this._busy.add(t); else this._busy.delete(t);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
_visit(t, dt, def) {
|
|
189
|
+
const e = this.engine;
|
|
190
|
+
if (t._cool > 0) t._cool -= dt;
|
|
191
|
+
if (!t.enabled || t.used) { if (t.inside) this._exit(t, null); return; }
|
|
192
|
+
let ps = def;
|
|
193
|
+
if (t.who) { if (typeof t.who === 'function') ps = t.who(); else { this._custom[0] = t.who.isObject3D ? t.who.position : t.who; ps = this._custom; } }
|
|
194
|
+
let hit = null;
|
|
195
|
+
if (ps) for (let k = 0; k < ps.length; k++) { const p = ps[k]; if (p && this._contains(t, p)) { hit = p; break; } }
|
|
196
|
+
if (hit && !t.inside) {
|
|
197
|
+
if (t._cool > 0) return;
|
|
198
|
+
t.inside = true;
|
|
199
|
+
t.onEnter?.(t, hit);
|
|
200
|
+
e.events.emit('trigger:enter', { tag: t.tag, trigger: t, who: hit });
|
|
201
|
+
if (t.once) { t.used = true; this._exit(t, null); }
|
|
202
|
+
} else if (!hit && t.inside) this._exit(t, null);
|
|
203
|
+
else if (hit && t.inside) t.onStay?.(dt, t, hit);
|
|
204
|
+
}
|
|
205
|
+
/** @internal session:end: occupied zones exit, cooldowns clear, once zones are armed again (recipes/14-custom-module.md "Per-playthrough state") */
|
|
206
|
+
_reset() {
|
|
207
|
+
for (const t of [...this._list]) { if (t.inside) this._exit(t, null); t._cool = 0; t.used = false; }
|
|
208
|
+
}
|
|
209
|
+
_exit(t, who) {
|
|
210
|
+
t.inside = false; t._cool = t.cooldown;
|
|
211
|
+
t.onExit?.(t, who);
|
|
212
|
+
this.engine.events.emit('trigger:exit', { tag: t.tag, trigger: t, who });
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// ---------- debug display ----------
|
|
216
|
+
setDebug(on) {
|
|
217
|
+
this.debug = on;
|
|
218
|
+
if (on) {
|
|
219
|
+
if (!this._debugGroup) { this._debugGroup = new THREE.Group(); this._debugGroup.name = 'triggers-debug'; }
|
|
220
|
+
const st = this.engine.style.triggers || {};
|
|
221
|
+
this._mat ??= new THREE.LineBasicMaterial({ color: st.debugColor ?? 0x9a9a9a, transparent: true, opacity: st.debugOpacity ?? 0.8, depthTest: false });
|
|
222
|
+
this.engine.add(this._debugGroup, { owner: 'engine:triggers' });
|
|
223
|
+
for (const t of this._list) if (!t._mesh) this._addDebugMesh(t);
|
|
224
|
+
} else if (this._debugGroup) {
|
|
225
|
+
for (const t of this._list) if (t._mesh) { t._mesh.geometry.dispose(); t._mesh = null; }
|
|
226
|
+
this._debugGroup.clear(); this.engine.detach(this._debugGroup); // keep group and material for the next enable
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
_addDebugMesh(t) {
|
|
230
|
+
let geo;
|
|
231
|
+
if (t.shape === 'sphere') geo = new THREE.SphereGeometry(t.radius, 12, 8);
|
|
232
|
+
else if (t.shape === 'box') geo = new THREE.BoxGeometry(t.hx * 2, t.sy, t.hz * 2).translate(0, t.sy / 2, 0);
|
|
233
|
+
else geo = new THREE.CylinderGeometry(t.radius, t.radius, t.height, 16, 1, true).translate(0, t.height / 2, 0);
|
|
234
|
+
const lines = new THREE.LineSegments(new THREE.WireframeGeometry(geo), this._mat);
|
|
235
|
+
geo.dispose();
|
|
236
|
+
lines.position.set(t.x, t.y, t.z); lines.rotation.y = t.rotation; lines.renderOrder = 999;
|
|
237
|
+
this._debugGroup.add(lines);
|
|
238
|
+
t._mesh = lines;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
const TRIGGER_PARAMS = {
|
|
243
|
+
debug: { type: 'bool', default: false, desc: 'draw all zones as wireframes from the start' },
|
|
244
|
+
action: { type: 'string', default: 'triggersDebug', desc: 'input action that toggles the debug display' },
|
|
245
|
+
keys: { type: 'array', optional: true, desc: "keys for that toggle (default ['F4'] in dev builds, none in release)" },
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
/** Trigger zone module. Provides engine.triggers once installed. Optional dependency: level (used by fromMarkers) */
|
|
249
|
+
export function triggers(opts = {}) {
|
|
250
|
+
const o = readParams('triggers', TRIGGER_PARAMS, opts);
|
|
251
|
+
let tr = null;
|
|
252
|
+
return {
|
|
253
|
+
name: 'triggers', label: 'Triggers', params: TRIGGER_PARAMS, options: o, noSkip: 'zone enter/exit is re-evaluated on the next fixed step', optional: ['level'], stage: 'gameplay', after: ['interactions'],
|
|
254
|
+
install(e) {
|
|
255
|
+
tr = new Triggers(e, opts);
|
|
256
|
+
// audio rule condition { zone: 'cave' | ['cave', 'mine'] }: some trigger zone with that tag is occupied
|
|
257
|
+
e.audio.condition('zone', v => [].concat(v).some(tag => tr.byTag(tag).some(t => t.inside)));
|
|
258
|
+
e.events.on('session:end', () => tr._reset());
|
|
259
|
+
return tr;
|
|
260
|
+
},
|
|
261
|
+
fixed(dt) { tr.update(dt); },
|
|
262
|
+
frame(dt, e) { if (tr._keyed && e.input.pressed(tr.action)) tr.setDebug(!tr.debug); },
|
|
263
|
+
describe(e, ctx) {
|
|
264
|
+
for (const t of tr._list) if (t.enabled && !t.used) ctx.near(t, { name: t.tag || t.shape, kind: 'trigger', inside: t.inside });
|
|
265
|
+
return { inside: tr._list.filter(t => t.inside).map(t => t.tag || t.shape), used: tr._list.filter(t => t.used).map(t => t.tag || t.shape) };
|
|
266
|
+
},
|
|
267
|
+
};
|
|
268
|
+
}
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
// Vegetation module: defines what to plant, where, how far before switching to low-poly, and how far before not drawing. Models (the look) come from the game
|
|
2
|
+
// or style pack.
|
|
3
|
+
import * as THREE from 'three';
|
|
4
|
+
import { fromModel } from './modelGeometry.js';
|
|
5
|
+
import { makeMaterial, applyEffects } from '../../render/materials.js';
|
|
6
|
+
import { checkOptions, checkOptionsArg, warnMissing } from '../../core/validate.js';
|
|
7
|
+
import { xzOf } from '../../core/math.js';
|
|
8
|
+
import { GroundChunks } from './groundChunks.js';
|
|
9
|
+
import { swayOf } from './lookWind.js';
|
|
10
|
+
// parameters read by vegetation.add(); keys inside rule (sent to the worker thread)
|
|
11
|
+
const ADD_KEYS = ['geometry', 'model', 'lodGeometry', 'rule', 'wind', 'nearOnly', 'maxRing', 'lodRing', 'castShadow', 'shadowRing', 'receiveShadow', 'material', 'effects', 'doubleSided'];
|
|
12
|
+
const RULE_KEYS = ['perChunk', 'chance', 'minHeight', 'maxHeight', 'maxSlope', 'cluster', 'scale', 'stretch', 'sink', 'tintJitter', 'tints', 'biomes', 'collider', 'avoidFlat', 'salt'];
|
|
13
|
+
|
|
14
|
+
// Single-instance removal/restore (chop a tree, mine a rock): records are owned by vegetation and saved with the save (save key 'vegetation', entry
|
|
15
|
+
// 'veg:<name>:<cx>,<cz>:<id>'), and reapplied when a chunk reloads.
|
|
16
|
+
// The id is this tree's stable number (independent of quality and vegetation density), not its index in the instance array.
|
|
17
|
+
// const hit = engine.vegetation.instanceAt(position, { radius: 2, species: '松树' }); // → { species, cx, cz, id, position } or null
|
|
18
|
+
// engine.vegetation.removeInstance(hit.species, hit.cx, hit.cz, hit.id, { regrowSeconds: 300 }); // grows back after 300 game seconds
|
|
19
|
+
// engine.vegetation.restoreInstance(...) // restore immediately
|
|
20
|
+
// Hiding: scale this instance's matrix to 0 (count unchanged) and drop it from the chunk's collision circles.
|
|
21
|
+
// Regrowth: the record stores the expiry time (engine.clock game seconds), checked once per second; the clock is saved, so the countdown continues after
|
|
22
|
+
// reload.
|
|
23
|
+
const KEY_RE = /^veg:(.*):(-?\d+),(-?\d+):(\d+)$/;
|
|
24
|
+
const ZERO16 = new Float32Array(16);
|
|
25
|
+
const hashName = s => { let h = 7; for (const ch of s) h = (Math.imul(h, 31) + ch.codePointAt(0)) | 0; return h & 0x7fffffff; };
|
|
26
|
+
// stable id -> instance index (built once per InstancedMesh)
|
|
27
|
+
function slotOf(im, id) {
|
|
28
|
+
if (!im.userData.slot) { im.userData.slot = new Map(); const ids = im.userData.ids; if (ids) for (let i = 0; i < ids.length; i++) im.userData.slot.set(ids[i], i); }
|
|
29
|
+
return im.userData.slot.get(id);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export class Vegetation {
|
|
33
|
+
constructor(engine, opts = {}) {
|
|
34
|
+
this.engine = engine; this.species = new Map();
|
|
35
|
+
// where it grows: on terrain chunks when the terrain module is installed (placed in its workers), else on vegetation's own chunks over
|
|
36
|
+
// whatever provides the ground (a level, a code-built ground, flat). Both hosts keep chunks of one shape, so everything below is shared
|
|
37
|
+
if (engine.terrain && Object.keys(opts).length) throw new Error(`vegetation({ ${Object.keys(opts).join(', ')} }): with terrain() installed vegetation grows on the terrain chunks, and density / view distance are terrain options (terrain({ density, viewChunks })). The vegetation() options are for ground without terrain (a level, a code-built ground)`);
|
|
38
|
+
/** @internal the chunk table vegetation lives in: engine.terrain, or its own GroundChunks */
|
|
39
|
+
this.host = engine.terrain ?? new GroundChunks(engine, this, opts);
|
|
40
|
+
this._removed = new Map(); // 'name:cx,cz' -> Map(id -> regrow time (clock game seconds), null = permanent)
|
|
41
|
+
this._acc = 0;
|
|
42
|
+
engine.saves.register('vegetation', {
|
|
43
|
+
save: () => {
|
|
44
|
+
const removed = {};
|
|
45
|
+
for (const [ck, m] of this._removed) { for (const [id, until] of m) removed[`veg:${ck}:${id}`] = until; }
|
|
46
|
+
return { removed };
|
|
47
|
+
},
|
|
48
|
+
load: d => {
|
|
49
|
+
this._removed.clear();
|
|
50
|
+
for (const [k, until] of Object.entries(d?.removed || {})) {
|
|
51
|
+
const m = KEY_RE.exec(k); if (!m) continue;
|
|
52
|
+
const ck = `${m[1]}:${m[2]},${m[3]}`;
|
|
53
|
+
if (!this._removed.has(ck)) this._removed.set(ck, new Map());
|
|
54
|
+
this._removed.get(ck).set(+m[4], until);
|
|
55
|
+
}
|
|
56
|
+
for (const c of this.host.chunks.values()) for (const n in c.veg) this.applyEdits(c, n);
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Register one kind of vegetation.
|
|
63
|
+
* @param {string} name
|
|
64
|
+
* @param {object} o
|
|
65
|
+
* geometry high-detail model (this or model is required)
|
|
66
|
+
* model Object3D with one material per mesh (e.g. assets.model('oak')): trunk and leaves keep their own materials, still one draw per part
|
|
67
|
+
* lodGeometry low-detail model (optional), used beyond the lodRing ring; with model it is a geometry (drawn with the first material) or an Object3D with the
|
|
68
|
+
* same mesh order
|
|
69
|
+
* rule placement rule: perChunk attempts per chunk, minHeight/maxHeight, maxSlope, cluster('forest'|'meadow'|'none'),
|
|
70
|
+
* scale[min,max], stretch[min,max], sink, tintJitter, tints[{color:[r,g,b],chance}]
|
|
71
|
+
* wind wind sway amplitude (0 disables)
|
|
72
|
+
* nearOnly generate only near the player (grass, flowers)
|
|
73
|
+
* maxRing not drawn beyond this ring count
|
|
74
|
+
* lodRing switch to low-poly beyond this ring count
|
|
75
|
+
* castShadow / shadowRing whether to cast shadows, and within how many rings
|
|
76
|
+
* material custom material, any three.js material (optional, default is the style pack's 'vegetation' role); wind, cloud
|
|
77
|
+
* shadows and season tint are added to it (and its shadow sways) unless effects: false
|
|
78
|
+
*/
|
|
79
|
+
add(name, o) {
|
|
80
|
+
checkOptions(`vegetation.add('${name}')`, o, ADD_KEYS);
|
|
81
|
+
checkOptions(`vegetation.add('${name}').rule`, o.rule, RULE_KEYS);
|
|
82
|
+
const sw = swayOf(this.engine), wind = o.wind && sw ? { amplitude: o.wind, glsl: sw.glsl, uniforms: sw.uniforms } : o.wind; // look.wind 'sway' (style.wind.glsl or a game's patch) replaces the sway shape
|
|
83
|
+
const fx = m => o.effects === false ? m : applyEffects(m, { wind, season: 'foliage' });
|
|
84
|
+
const mdl = o.model && fromModel(o.model, `vegetation.add('${name}')`);
|
|
85
|
+
let lod = o.lodGeometry?.isObject3D ? fromModel(o.lodGeometry, `vegetation.add('${name}').lodGeometry`).geometry : o.lodGeometry || null;
|
|
86
|
+
if (mdl && lod && !lod.groups.length) { lod = lod.clone(); lod.addGroup(0, Infinity, 0); } // a material array draws nothing without groups
|
|
87
|
+
const sp = {
|
|
88
|
+
name, geometry: mdl ? mdl.geometry : o.geometry, lodGeometry: lod,
|
|
89
|
+
rule: { salt: hashName(name), ...(o.rule || {}) }, // random seed from the name: placement is unaffected by registration order
|
|
90
|
+
nearOnly: !!o.nearOnly, maxRing: o.maxRing ?? (o.nearOnly ? 1 : 99), lodRing: o.lodRing ?? 1,
|
|
91
|
+
castShadow: o.castShadow ?? !o.nearOnly, shadowRing: o.shadowRing ?? 1, receiveShadow: o.receiveShadow ?? true,
|
|
92
|
+
material: mdl ? mdl.materials.map(fx)
|
|
93
|
+
: fx(o.material ?? makeMaterial('vegetation', { vertexColors: true, side: o.doubleSided ? THREE.DoubleSide : THREE.FrontSide }, this.engine)),
|
|
94
|
+
};
|
|
95
|
+
this.species.set(name, sp);
|
|
96
|
+
this.host.registerSpecies(name, sp.rule);
|
|
97
|
+
return sp;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Place every chunk again: after changing the ground behind the same provider (a ground function reading game state). A new setGround or level is followed
|
|
101
|
+
* automatically
|
|
102
|
+
*/
|
|
103
|
+
rebuild() { this.host.rebuild(); }
|
|
104
|
+
get(name) { return this.species.get(name); }
|
|
105
|
+
list() { return [...this.species.values()]; }
|
|
106
|
+
/**
|
|
107
|
+
* Change at runtime how far a vegetation kind casts shadows: within `ring` chunk rings of the player (0 = only the chunk you stand in, 1 = the default,
|
|
108
|
+
* larger = further and dearer). Takes effect at once; the add() option shadowRing is only the starting value. An unknown name warns with the known ones
|
|
109
|
+
* @example engine.vegetation.setShadowRing('tree', 0); // graphics setting "shadows: low": trees shadow only the nearest chunk
|
|
110
|
+
* @param {string} name species name given to vegetation.add
|
|
111
|
+
* @param {number} ring chunk rings, 0 or more
|
|
112
|
+
* @returns {void}
|
|
113
|
+
*/
|
|
114
|
+
setShadowRing(name, ring) {
|
|
115
|
+
const sp = this.species.get(name);
|
|
116
|
+
if (!sp) { warnMissing('vegetation', name, [...this.species.keys()]); return; }
|
|
117
|
+
sp.shadowRing = ring;
|
|
118
|
+
this.host.refreshLevels();
|
|
119
|
+
}
|
|
120
|
+
/** @internal terrain plumbing */
|
|
121
|
+
baseNames() { return this.list().filter(s => !s.nearOnly).map(s => s.name); }
|
|
122
|
+
/** @internal terrain plumbing */
|
|
123
|
+
nearNames() { return this.list().filter(s => s.nearOnly).map(s => s.name); }
|
|
124
|
+
|
|
125
|
+
// ---------- single-instance remove / restore ----------
|
|
126
|
+
/** @internal save-key format */
|
|
127
|
+
key(species, cx, cz, id) { return `veg:${species}:${cx},${cz}:${id}`; }
|
|
128
|
+
isRemoved(species, cx, cz, id) { return !!this._removed.get(`${species}:${cx},${cz}`)?.has(id); }
|
|
129
|
+
/** Remove one instance (regrowSeconds: game seconds until it grows back, 0/omitted = permanent). The record is saved with the save */
|
|
130
|
+
removeInstance(species, cx, cz, id, { regrowSeconds = 0 } = {}) {
|
|
131
|
+
const ck = `${species}:${cx},${cz}`;
|
|
132
|
+
if (!this._removed.has(ck)) this._removed.set(ck, new Map());
|
|
133
|
+
this._removed.get(ck).set(id, regrowSeconds > 0 ? this.engine.clock.now + regrowSeconds : null);
|
|
134
|
+
this._refresh(species, cx, cz, id);
|
|
135
|
+
this.engine.events.emit('vegetation:remove', { species, cx, cz, id });
|
|
136
|
+
return this.key(species, cx, cz, id);
|
|
137
|
+
}
|
|
138
|
+
restoreInstance(species, cx, cz, id) {
|
|
139
|
+
const ck = `${species}:${cx},${cz}`, m = this._removed.get(ck);
|
|
140
|
+
if (m) { m.delete(id); if (!m.size) this._removed.delete(ck); }
|
|
141
|
+
this._refresh(species, cx, cz, id);
|
|
142
|
+
this.engine.events.emit('vegetation:restore', { species, cx, cz, id });
|
|
143
|
+
}
|
|
144
|
+
/** @internal module hook: check once per second, those due grow back */
|
|
145
|
+
tick(dt) {
|
|
146
|
+
this._acc += dt;
|
|
147
|
+
if (this._acc < 1) return;
|
|
148
|
+
this._acc = 0;
|
|
149
|
+
const now = this.engine.clock.now, due = [];
|
|
150
|
+
for (const [ck, m] of this._removed) {
|
|
151
|
+
const a = ck.lastIndexOf(':');
|
|
152
|
+
for (const [id, until] of m) if (until != null && until <= now) due.push([ck.slice(0, a), ...ck.slice(a + 1).split(',').map(Number), id]);
|
|
153
|
+
}
|
|
154
|
+
for (const d of due) this.restoreInstance(...d);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Nearest instance within radius meters (default 2) of position (loaded chunks only; species restricts to one kind): { species, cx, cz, id, position } or
|
|
159
|
+
* null
|
|
160
|
+
*/
|
|
161
|
+
instanceAt(position, opts = {}) {
|
|
162
|
+
checkOptionsArg('vegetation.instanceAt()', opts, ['radius', 'species']);
|
|
163
|
+
const [x, z] = xzOf(position), { radius = 2, species = null } = typeof opts === 'object' && opts ? opts : {};
|
|
164
|
+
const T = this.host, CH = T.CHUNK;
|
|
165
|
+
let best = null, bestD = radius * radius;
|
|
166
|
+
for (let cz = Math.floor((z - radius) / CH); cz <= Math.floor((z + radius) / CH); cz++)
|
|
167
|
+
for (let cx = Math.floor((x - radius) / CH); cx <= Math.floor((x + radius) / CH); cx++) {
|
|
168
|
+
const c = T.chunks.get(cx + ',' + cz);
|
|
169
|
+
if (!c || c.state !== 'ready') continue;
|
|
170
|
+
for (const name in c.veg) {
|
|
171
|
+
if (species && name !== species) continue;
|
|
172
|
+
const im = c.veg[name], a = im.instanceMatrix.array, hid = im.userData.hidden, ox = cx * CH, oz = cz * CH;
|
|
173
|
+
for (let i = 0; i < im.count; i++) {
|
|
174
|
+
if (hid?.has(i)) continue;
|
|
175
|
+
const dx = ox + a[i * 16 + 12] - x, dz = oz + a[i * 16 + 14] - z, d = dx * dx + dz * dz;
|
|
176
|
+
if (d < bestD) { bestD = d; best = { species: name, cx, cz, id: im.userData.ids ? im.userData.ids[i] : i, position: new this.engine.THREE.Vector3(ox + a[i * 16 + 12], a[i * 16 + 13], oz + a[i * 16 + 14]) }; }
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
return best;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** @internal chunk plumbing (terrain chunks and ground chunks): upload one species' placement result r into chunk c as an InstancedMesh */
|
|
184
|
+
mount(c, name, r) {
|
|
185
|
+
if (r.k && r.k.length) c.colliders[name] = r.k; else delete c.colliders[name];
|
|
186
|
+
(c.collidersAll ||= {})[name] = c.colliders[name]; // original collision circles (before felled trees are filtered), for single-tree removal
|
|
187
|
+
if (r.n === 0) return;
|
|
188
|
+
const t0 = performance.now(), sp = this.species.get(name); // measure: the 'build' stage of engine.budget.cost
|
|
189
|
+
const im = new THREE.InstancedMesh(sp.geometry, sp.material, r.n);
|
|
190
|
+
im.instanceMatrix.array.set(r.m); im.instanceMatrix.needsUpdate = true;
|
|
191
|
+
im.instanceColor = new THREE.InstancedBufferAttribute(r.c, 3);
|
|
192
|
+
im.frustumCulled = false; im.matrixAutoUpdate = false;
|
|
193
|
+
im.receiveShadow = sp.receiveShadow;
|
|
194
|
+
im.userData.ids = r.ids; // stable id per instance (used by felled-tree records)
|
|
195
|
+
im.userData.budgetTag = 'vegetation';
|
|
196
|
+
c.group.add(im); im.updateMatrixWorld(true);
|
|
197
|
+
if (c.veg[name]) { c.group.remove(c.veg[name]); c.veg[name].dispose(); }
|
|
198
|
+
c.veg[name] = im;
|
|
199
|
+
this.engine.budget.cost.end('build', t0);
|
|
200
|
+
this.applyEdits(c, name); // felled trees stay gone after reload
|
|
201
|
+
}
|
|
202
|
+
/** @internal chunk plumbing: drop a near-only species from a chunk that moved out of its ring */
|
|
203
|
+
unmount(c, name) {
|
|
204
|
+
const im = c.veg[name]; if (!im) return;
|
|
205
|
+
c.group.remove(im); im.dispose(); delete c.veg[name]; delete c.colliders[name]; if (c.collidersAll) delete c.collidersAll[name];
|
|
206
|
+
}
|
|
207
|
+
/** @internal chunk plumbing: draw distance, low-poly swap and shadows of one species' instances at a ring */
|
|
208
|
+
levelOf(im, sp, ring) {
|
|
209
|
+
im.visible = ring <= sp.maxRing;
|
|
210
|
+
im.geometry = sp.lodGeometry && ring > sp.lodRing ? sp.lodGeometry : sp.geometry;
|
|
211
|
+
im.castShadow = this.engine.shadows && sp.castShadow && ring <= sp.shadowRing;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/** @internal Called by the terrain module when a chunk's vegetation was just uploaded: reapply the edit records */
|
|
215
|
+
applyEdits(c, name) {
|
|
216
|
+
const im = c.veg[name];
|
|
217
|
+
if (!im) return;
|
|
218
|
+
const want = this._removed.get(`${name}:${c.cx},${c.cz}`)?.keys() ?? [];
|
|
219
|
+
const hid = im.userData.hidden;
|
|
220
|
+
const wantSlots = new Set(); for (const id of want) { const s = slotOf(im, id); if (s !== undefined) wantSlots.add(s); }
|
|
221
|
+
if (hid) for (const i of [...hid.keys()]) if (!wantSlots.has(i)) this._show(im, i, true);
|
|
222
|
+
for (const i of wantSlots) this._show(im, i, false);
|
|
223
|
+
this._filterColliders(c, name);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
_refresh(species, cx, cz, id) {
|
|
227
|
+
const c = this.host.chunks.get(cx + ',' + cz), im = c?.veg[species];
|
|
228
|
+
if (!im) return; // chunk not loaded: applyEdits handles it when loaded
|
|
229
|
+
const slot = slotOf(im, id); if (slot === undefined) return;
|
|
230
|
+
this._show(im, slot, !this.isRemoved(species, cx, cz, id));
|
|
231
|
+
this._filterColliders(c, species);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// show/hide an instance: when hiding, save the original matrix and write an all-zero matrix
|
|
235
|
+
_show(im, i, visible) {
|
|
236
|
+
if (i >= im.count) return;
|
|
237
|
+
const a = im.instanceMatrix.array, hid = (im.userData.hidden ||= new Map());
|
|
238
|
+
if (visible) { const m = hid.get(i); if (!m) return; a.set(m, i * 16); hid.delete(i); }
|
|
239
|
+
else { if (hid.has(i)) return; hid.set(i, a.slice(i * 16, i * 16 + 16)); a.set(ZERO16, i * 16); }
|
|
240
|
+
im.instanceMatrix.needsUpdate = true;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// collision circles map one-to-one to instances (instance i = group i of [x, z, r]); drop the hidden ones
|
|
244
|
+
_filterColliders(c, name) {
|
|
245
|
+
const all = c.collidersAll?.[name], hid = c.veg[name]?.userData.hidden;
|
|
246
|
+
if (!all) return;
|
|
247
|
+
const before = c.colliders[name];
|
|
248
|
+
if (!hid || !hid.size) c.colliders[name] = all;
|
|
249
|
+
else {
|
|
250
|
+
const out = [];
|
|
251
|
+
for (let i = 0; i < all.length / 3; i++) if (!hid.has(i)) out.push(all[i * 3], all[i * 3 + 1], all[i * 3 + 2]);
|
|
252
|
+
c.colliders[name] = new Float32Array(out);
|
|
253
|
+
}
|
|
254
|
+
if (before !== c.colliders[name]) c.colToken = {}; // tell the physics module to rebuild this chunk's collision
|
|
255
|
+
}
|
|
256
|
+
}
|