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,167 @@
|
|
|
1
|
+
// HLOD: merge far-away buildings into a few proxy meshes, show originals when near; fewer draw calls.
|
|
2
|
+
// engine.use(level({ url }), hlod()); // default: handles the level automatically (on level:loaded)
|
|
3
|
+
// engine.hlod.add(group, { cell: 64, near: 160 }); // or register manually
|
|
4
|
+
// 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;
|
|
5
|
+
// 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.
|
|
6
|
+
// 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).
|
|
7
|
+
// 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
|
|
8
|
+
// 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 get userData.rayVisible,
|
|
9
|
+
// so engine.raycast still hits far buildings (see core/Rays.js).
|
|
10
|
+
// Skips meshes whose material moves vertices (wind and other shadow: true patches): that code reads object space (height above the
|
|
11
|
+
// model origin, phase from the origin), so a world-space proxy would sway far more on high ground and every merged object in lockstep.
|
|
12
|
+
// Those meshes stay as they are (always drawn) and keep their own sway.
|
|
13
|
+
// 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 }.
|
|
14
|
+
import * as THREE from 'three';
|
|
15
|
+
import { mergeGeometries } from 'three/addons/utils/BufferGeometryUtils.js';
|
|
16
|
+
import { checkOptions } from '../../core/validate.js';
|
|
17
|
+
import { readParams, keysSchema } from '../../core/params.js';
|
|
18
|
+
import { movesVertices } from '../../render/patches.js';
|
|
19
|
+
/** @import { ModuleDef } from '../../types/core' */
|
|
20
|
+
/** @import { Hlod, HlodOptions } from '../../types/world' */
|
|
21
|
+
|
|
22
|
+
const ADD_KEYS = ['cell', 'near', 'castShadow', 'include'];
|
|
23
|
+
const LOD_RE = /_LOD1$/;
|
|
24
|
+
const noRaycast = () => {};
|
|
25
|
+
|
|
26
|
+
// merge geometries of one material: keep only attributes all have; if any lacks an index, drop indices from all
|
|
27
|
+
function mergeGroup(meshes) {
|
|
28
|
+
const geos = meshes.map(m => m.geometry.clone().applyMatrix4(m.matrixWorld));
|
|
29
|
+
const names = Object.keys(geos[0].attributes).filter(n => geos.every(g => g.attributes[n]));
|
|
30
|
+
const indexed = geos.every(g => g.index);
|
|
31
|
+
const ready = geos.map(g => {
|
|
32
|
+
const h = indexed ? g : g.toNonIndexed();
|
|
33
|
+
for (const n of Object.keys(h.attributes)) if (!names.includes(n)) h.deleteAttribute(n);
|
|
34
|
+
h.morphAttributes = {};
|
|
35
|
+
return h;
|
|
36
|
+
});
|
|
37
|
+
const out = mergeGeometries(ready, false);
|
|
38
|
+
for (const g of new Set([...geos, ...ready])) g.dispose();
|
|
39
|
+
return out;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const FULL = { detail: 'full' };
|
|
43
|
+
const HLOD_PARAMS = keysSchema(['level', ...ADD_KEYS]);
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* HLOD (merge far buildings into a few meshes) -> engine.hlod
|
|
47
|
+
* @param {HlodOptions} [opts]
|
|
48
|
+
* @returns {ModuleDef<Hlod>}
|
|
49
|
+
* @experimental
|
|
50
|
+
*/
|
|
51
|
+
export function hlod(opts = {}) {
|
|
52
|
+
readParams('hlod', HLOD_PARAMS, opts);
|
|
53
|
+
const { level: autoLevel = true, ...defaults } = opts;
|
|
54
|
+
let e = null, timer = 0, levelHandle = null;
|
|
55
|
+
const handles = new Set();
|
|
56
|
+
|
|
57
|
+
/** 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 */
|
|
58
|
+
function isFar(c, near) {
|
|
59
|
+
const CH = e.terrain?.CHUNK;
|
|
60
|
+
for (const f of e.stream.sources(FULL)) {
|
|
61
|
+
const n = f.reach(near);
|
|
62
|
+
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(n / CH)
|
|
63
|
+
: Math.hypot(c.center.x - f.x, c.center.z - f.z) <= n) return false;
|
|
64
|
+
}
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
function setFar(c, far) {
|
|
68
|
+
if (c.far === far) return;
|
|
69
|
+
c.far = far;
|
|
70
|
+
for (const p of c.proxy) p.visible = far;
|
|
71
|
+
for (const m of c.originals) { m.visible = !far; if (far) m.userData.rayVisible = true; else delete m.userData.rayVisible; }
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const api = {
|
|
75
|
+
cells: [],
|
|
76
|
+
/** Register objects (root or array) and merge them per cell into proxies; returns handle { cells, ready, whenReady, remove() } */
|
|
77
|
+
add(target, o = {}) {
|
|
78
|
+
checkOptions('hlod.add()', o, ADD_KEYS);
|
|
79
|
+
const { cell = e.stream.cellSize, near = 160, castShadow = false, include = null } = { ...defaults, ...o };
|
|
80
|
+
const roots = [].concat(target);
|
|
81
|
+
for (const r of roots) r.updateMatrixWorld(true);
|
|
82
|
+
// simplified node xxx_LOD1: record it, hide it
|
|
83
|
+
const lods = new Map();
|
|
84
|
+
for (const r of roots) r.traverse(n => { if (LOD_RE.test(n.name)) lods.set(n.name.replace(LOD_RE, ''), { node: n, visible: n.visible, used: false }); });
|
|
85
|
+
// originals: visible plain meshes (skip LOD1 subtrees, skinned, instanced, multi-material)
|
|
86
|
+
const originals = [];
|
|
87
|
+
const walk = n => {
|
|
88
|
+
if (!n.visible || LOD_RE.test(n.name)) return;
|
|
89
|
+
if (n.isMesh && !n.isInstancedMesh && !n.isSkinnedMesh && !n.userData.batched && !Array.isArray(n.material) && n.geometry && (!include || include(n))) originals.push(n);
|
|
90
|
+
for (const c of n.children) walk(c);
|
|
91
|
+
};
|
|
92
|
+
roots.forEach(walk);
|
|
93
|
+
for (let i = originals.length; i--;) if (movesVertices(originals[i].material)) originals.splice(i, 1); // swaying meshes keep their own transform (see header)
|
|
94
|
+
for (const m of originals) m.userData.hlod = true; // engine.batching leaves hlod's meshes alone (marked after the filter: swaying meshes stay batchable)
|
|
95
|
+
for (const l of lods.values()) l.node.visible = false;
|
|
96
|
+
// split into cells by bounding-box center; where a LOD1 exists, its meshes join the merge instead (each LOD1 used once)
|
|
97
|
+
const cells = new Map(), box = new THREE.Box3(), v = new THREE.Vector3();
|
|
98
|
+
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; };
|
|
99
|
+
for (const m of originals) {
|
|
100
|
+
box.setFromObject(m).getCenter(v);
|
|
101
|
+
const key = Math.floor(v.x / cell) + ',' + Math.floor(v.z / cell);
|
|
102
|
+
const c = cells.get(key) || cells.set(key, { key, proxy: [], originals: [], sources: [], center: new THREE.Vector3(), far: false }).get(key);
|
|
103
|
+
c.originals.push(m); c.center.add(v);
|
|
104
|
+
const l = lodOf(m);
|
|
105
|
+
if (!l) c.sources.push(m);
|
|
106
|
+
else if (!l.used) { l.used = true; l.node.traverse(n => { if (n.isMesh && !Array.isArray(n.material)) c.sources.push(n); }); }
|
|
107
|
+
}
|
|
108
|
+
const group = new THREE.Group();
|
|
109
|
+
group.name = 'hlod'; group.userData.budgetTag = 'hlod'; group.matrixAutoUpdate = false;
|
|
110
|
+
e.add(group, { owner: 'engine:hlod' });
|
|
111
|
+
const list = [...cells.values()];
|
|
112
|
+
for (const c of list) c.center.divideScalar(c.originals.length);
|
|
113
|
+
const h = {
|
|
114
|
+
cells: list, near, ready: false,
|
|
115
|
+
// one step per cell: merge by material into a proxy (spread over frames, at most engine.jobs.budgetMs ms per frame)
|
|
116
|
+
whenReady: e.jobs.add(function* () {
|
|
117
|
+
for (const c of list) {
|
|
118
|
+
if (h.removed) return;
|
|
119
|
+
const byMat = new Map();
|
|
120
|
+
for (const m of c.sources) (byMat.get(m.material) || byMat.set(m.material, []).get(m.material)).push(m);
|
|
121
|
+
for (const [mat, ms] of byMat) {
|
|
122
|
+
const p = new THREE.Mesh(mergeGroup(ms), mat);
|
|
123
|
+
p.name = 'hlod_' + c.key; p.castShadow = castShadow; p.receiveShadow = true;
|
|
124
|
+
p.matrixAutoUpdate = false; p.visible = false; p.raycast = noRaycast;
|
|
125
|
+
group.add(p); c.proxy.push(p);
|
|
126
|
+
}
|
|
127
|
+
delete c.sources;
|
|
128
|
+
api.cells.push(c);
|
|
129
|
+
yield;
|
|
130
|
+
}
|
|
131
|
+
h.ready = true;
|
|
132
|
+
return h;
|
|
133
|
+
}),
|
|
134
|
+
/** Unregister: restore originals, release proxies */
|
|
135
|
+
remove() {
|
|
136
|
+
h.removed = true; handles.delete(h);
|
|
137
|
+
for (const c of list) { setFar(c, false); for (const p of c.proxy) p.geometry.dispose(); for (const m of c.originals) delete m.userData.hlod; }
|
|
138
|
+
api.cells = api.cells.filter(c => !list.includes(c));
|
|
139
|
+
for (const l of lods.values()) l.node.visible = l.visible;
|
|
140
|
+
e.detach(group); // proxies share the originals' materials and are never ray-registered: geometries were disposed above
|
|
141
|
+
},
|
|
142
|
+
};
|
|
143
|
+
handles.add(h);
|
|
144
|
+
timer = Infinity; // switch by distance on the next frame
|
|
145
|
+
return h;
|
|
146
|
+
},
|
|
147
|
+
/** @internal Switch by the current stream sources right now (normally runs automatically every 0.25 s) */
|
|
148
|
+
update() {
|
|
149
|
+
for (const h of handles) for (const c of h.cells) if (c.proxy.length) setFar(c, isFar(c, h.near));
|
|
150
|
+
},
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
const addLevel = root => { levelHandle?.remove(); levelHandle = root ? api.add(root) : null; };
|
|
154
|
+
return {
|
|
155
|
+
name: 'hlod', params: HLOD_PARAMS, options: opts, label: 'HLOD', optional: ['terrain', 'level'], presentation: true,
|
|
156
|
+
install(engine) {
|
|
157
|
+
e = engine;
|
|
158
|
+
if (autoLevel) {
|
|
159
|
+
e.events.on('level:loaded', ({ root }) => addLevel(root));
|
|
160
|
+
if (e.level?.ready && e.level.root) addLevel(e.level.root); // install hlod only after the level is ready
|
|
161
|
+
}
|
|
162
|
+
return api;
|
|
163
|
+
},
|
|
164
|
+
frame(dt) { if ((timer += dt) >= 0.25) { timer = 0; api.update(); } },
|
|
165
|
+
describe() { return { cells: api.cells.length, far: api.cells.filter(c => c.far).length }; },
|
|
166
|
+
};
|
|
167
|
+
}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
// Objective markers and a simple HUD: world markers (an edge-of-screen arrow when the target is off-screen), counters, progress bars.
|
|
2
|
+
// const m = engine.hud.marker(npc.root, { label: '面包师' }); m.set({ label: '面包师(关门了)' }); m.remove();
|
|
3
|
+
// engine.hud.marker('river') // a place name (content places or a level marker point), { x, z }, an object or a character all work
|
|
4
|
+
// engine.hud.marker({ nearest: 'berry' }) // the nearest not-yet-picked pickup of a kind (hides itself once all are taken)
|
|
5
|
+
// engine.hud.marker(() => targetOrNull) // function: resolves the target each frame, null hides it; m.setTarget(newTarget) swaps the target
|
|
6
|
+
// engine.hud.counter('fish', { icon: '🐟', label: '鱼', value: 2, max: 5 }); // calling again with the same id = update
|
|
7
|
+
// engine.hud.bar('stamina', { value: 0.6, label: '体力' }); engine.hud.remove('stamina');
|
|
8
|
+
// Quests: a marker shows automatically when the current step has a target, and is removed on completion (turn off with hud({ questMarkers: false })).
|
|
9
|
+
// Quest markers follow the quests' state: they are dropped when a playthrough ends and rebuilt when the next starts (engine.session) or a save loads.
|
|
10
|
+
// Markers, counters and bars the game made itself stay; ones made during play go through engine.session.track(m) (counters / bars: hud.remove(id)).
|
|
11
|
+
// Drawing is done by UI parts (see parts.js): engine.ui.set('hud.marker' | 'hud.counter' | 'hud.bar', yourFactory | false) replaces or hides each kind;
|
|
12
|
+
// this file keeps the logic (targets, projection, arrows, quest sync, describe) so a replaced part only draws the data it gets.
|
|
13
|
+
import * as THREE from 'three';
|
|
14
|
+
import { injectUICSS, worldToScreen } from '../../ui/UI.js';
|
|
15
|
+
import { checkOptions } from '../../core/validate.js';
|
|
16
|
+
import { readParams, keysSchema } from '../../core/params.js';
|
|
17
|
+
import { vec3 } from '../../core/math.js';
|
|
18
|
+
import { surfaceOr } from '../../core/ground.js';
|
|
19
|
+
import { CSS, defineHudParts } from './parts.js';
|
|
20
|
+
/** @import { ModuleDef } from '../../types/core' */
|
|
21
|
+
/** @import { Hud, HudOptions } from '../../types/gameplay' */
|
|
22
|
+
|
|
23
|
+
const STRINGS = {
|
|
24
|
+
'zh-CN': { 'hud.distance': '{m} 米' },
|
|
25
|
+
en: { 'hud.distance': '{m} m' },
|
|
26
|
+
};
|
|
27
|
+
const MARKER_KEYS = ['label', 'icon', 'offscreen', 'distance', 'height'];
|
|
28
|
+
const _size = new THREE.Vector2();
|
|
29
|
+
const EDGE = 28; // how far the arrow sits from the screen edge (px)
|
|
30
|
+
|
|
31
|
+
const HUD_PARAMS = keysSchema(['questMarkers']);
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Objective markers, counters, progress bars -> engine.hud
|
|
35
|
+
* @param {HudOptions} [opts]
|
|
36
|
+
* @returns {ModuleDef<Hud>}
|
|
37
|
+
*/
|
|
38
|
+
export function hud(opts = {}) {
|
|
39
|
+
readParams('hud', HUD_PARAMS, opts);
|
|
40
|
+
let e = null, root = null;
|
|
41
|
+
const items = new Map(); // counters, bars: id -> { kind, o, part }
|
|
42
|
+
const quest = new Map(); // quest id -> auto marker
|
|
43
|
+
const v = new THREE.Vector3();
|
|
44
|
+
// Containers of the default parts, built on first use (a game that replaced every part gets no empty HUD layer)
|
|
45
|
+
const containers = () => {
|
|
46
|
+
if (!root) {
|
|
47
|
+
injectUICSS(CSS);
|
|
48
|
+
const layer = document.createElement('div'); layer.className = 'threedog-ui threedog-hud';
|
|
49
|
+
const stats = document.createElement('div'); stats.className = 'threedog-hud-stats';
|
|
50
|
+
layer.appendChild(stats); e.uiRoot.appendChild(layer);
|
|
51
|
+
root = { layer, stats };
|
|
52
|
+
}
|
|
53
|
+
return root;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
// { nearest: itemId } -> the nearest not-yet-picked pickup (world data, so it is found even when far away with no model)
|
|
57
|
+
const nearest = id => e.inventory?.nearestPickup(id, e.actorPosition())?.position ?? null;
|
|
58
|
+
// Target -> world position (written into v); null if not found
|
|
59
|
+
const resolve = (target, height) => {
|
|
60
|
+
if (typeof target === 'function') target = target();
|
|
61
|
+
if (target?.nearest != null) target = nearest(target.nearest);
|
|
62
|
+
if (target == null) return null;
|
|
63
|
+
if (typeof target === 'string') {
|
|
64
|
+
const p = e.content?.place(target) ?? e.level?.marker(target)?.position;
|
|
65
|
+
if (!p) return null;
|
|
66
|
+
return v.set(p.x, surfaceOr(e, p.x, p.z, p.y, p.y ?? 0) + height, p.z); // a level marker's own height picks its storey
|
|
67
|
+
}
|
|
68
|
+
const obj = target.root?.isObject3D ? target.root : target;
|
|
69
|
+
if (obj.isObject3D) { obj.getWorldPosition(v); v.y += height; return v; }
|
|
70
|
+
vec3(target, v);
|
|
71
|
+
if (target.y === undefined) v.y = surfaceOr(e, v.x, v.z);
|
|
72
|
+
v.y += height;
|
|
73
|
+
return v;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const hideMarker = m => { if (m.visible) { m.visible = false; m.part?.hide(); } };
|
|
77
|
+
const updateMarker = m => {
|
|
78
|
+
const p = resolve(m.target, m.o.height ?? 2.2);
|
|
79
|
+
if (!p) { hideMarker(m); return; }
|
|
80
|
+
const from = e.actorPosition() ?? e.focus; // distance from whoever the user controls (engine.actor)
|
|
81
|
+
m.dist = Math.round(p.distanceTo(from));
|
|
82
|
+
const s = worldToScreen(e, p), { x: W, y: H } = e.renderer.getSize(_size); // the canvas box, not the window
|
|
83
|
+
m.onScreen = s.onScreen;
|
|
84
|
+
if (!s.onScreen && m.o.offscreen === 'hide') { hideMarker(m); return; }
|
|
85
|
+
m.visible = true;
|
|
86
|
+
let x = s.x, y = s.y, angle = 0;
|
|
87
|
+
m.arrow = !s.onScreen;
|
|
88
|
+
if (m.arrow) {
|
|
89
|
+
// Point from the screen center to the target (the projection is mirrored when behind, so flip it), clamped to the screen edge
|
|
90
|
+
let dx = x - W / 2, dy = y - H / 2;
|
|
91
|
+
if (s.behind) { dx = -dx; dy = -dy; }
|
|
92
|
+
if (!dx && !dy) dy = 1;
|
|
93
|
+
const k = Math.min((W / 2 - EDGE) / Math.abs(dx || 1e-6), (H / 2 - EDGE) / Math.abs(dy || 1e-6));
|
|
94
|
+
x = W / 2 + dx * k; y = H / 2 + dy * k; angle = Math.atan2(dy, dx);
|
|
95
|
+
}
|
|
96
|
+
if (!m.part) return;
|
|
97
|
+
const o = m.o, label = typeof o.label === 'function' ? o.label() : o.label ?? '';
|
|
98
|
+
const distance = o.distance !== false && m.dist != null ? e.t('hud.distance', { m: m.dist }) : '';
|
|
99
|
+
m.part.update({ x, y, onScreen: s.onScreen, arrow: m.arrow, angle, label, icon: o.icon ?? '', distance });
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
const item = (kind, id, o) => {
|
|
103
|
+
let it = items.get(id);
|
|
104
|
+
if (!it) { it = { kind, o: {}, part: e.ui.create('hud.' + kind) }; items.set(id, it); }
|
|
105
|
+
else if (Object.keys(o).every(k => it.o[k] === o[k])) return; // value unchanged: leave the part alone (cheap even when called every frame)
|
|
106
|
+
Object.assign(it.o, o);
|
|
107
|
+
it.part?.update({ id, ...it.o });
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
// The current quest step's target -> marker; a parallel step marks each part not yet done (key 'quest#part')
|
|
111
|
+
const syncQuests = () => {
|
|
112
|
+
if (opts.questMarkers === false || !e.quests) return;
|
|
113
|
+
const want = new Map();
|
|
114
|
+
for (const q of e.quests.list()) {
|
|
115
|
+
const s = q.steps.find(x => x.current);
|
|
116
|
+
if (s?.parts) s.parts.forEach((p, k) => { if (!p.done && p.target != null) want.set(`${q.id}#${k}`, { target: p.target, label: p.text }); });
|
|
117
|
+
else if (s?.target != null) want.set(q.id, { target: s.target, label: q.title });
|
|
118
|
+
}
|
|
119
|
+
for (const [id, m] of quest) if (want.get(id)?.target !== m.target) { m.remove(); quest.delete(id); }
|
|
120
|
+
for (const [id, w] of want) if (!quest.has(id)) quest.set(id, api.marker(w.target, { label: w.label }));
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
const api = {
|
|
124
|
+
/** All markers */
|
|
125
|
+
markers: [],
|
|
126
|
+
/** Add an objective marker (target: object, character, { x, z }, place name, { nearest: itemId }, or a function returning a target); returns { set(opts), setTarget(t), remove() } */
|
|
127
|
+
marker(target, o = {}) {
|
|
128
|
+
checkOptions('hud.marker()', o, MARKER_KEYS);
|
|
129
|
+
const part = e.ui.create('hud.marker');
|
|
130
|
+
const m = {
|
|
131
|
+
target, o: { offscreen: 'arrow', distance: true, ...o }, part, el: part?.el ?? null, dist: null, onScreen: false, arrow: false, visible: false,
|
|
132
|
+
set(p) { checkOptions('hud.marker().set()', p, MARKER_KEYS); Object.assign(m.o, p); },
|
|
133
|
+
setTarget(t) { m.target = t; },
|
|
134
|
+
remove() { part?.dispose(); api.markers = api.markers.filter(x => x !== m); },
|
|
135
|
+
};
|
|
136
|
+
api.markers.push(m);
|
|
137
|
+
return m;
|
|
138
|
+
},
|
|
139
|
+
/** Counter (calling again with the same id = update): { label, icon, value, max } */
|
|
140
|
+
counter(id, o) { item('counter', id, o); },
|
|
141
|
+
/** Progress bar (calling again with the same id = update): { value, max = 1, label } */
|
|
142
|
+
bar(id, o) { item('bar', id, o); },
|
|
143
|
+
/** Remove a counter or bar */
|
|
144
|
+
remove(id) { items.get(id)?.part?.dispose(); items.delete(id); },
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
return {
|
|
148
|
+
name: 'hud', params: HUD_PARAMS, options: opts, label: 'Objective markers', optional: ['inventory', 'content', 'level', 'quests'], stage: 'presentation', after: ['particles', 'settings'], presentation: true,
|
|
149
|
+
install(engine) {
|
|
150
|
+
e = engine;
|
|
151
|
+
e.i18n.add(STRINGS);
|
|
152
|
+
defineHudParts(e, containers);
|
|
153
|
+
for (const ev of ['quest:start', 'quest:step', 'quest:part', 'quest:done', 'quest:fail', 'save:loaded', 'session:start']) e.events.on(ev, syncQuests);
|
|
154
|
+
// per-playthrough state (recipes/14-custom-module.md "Per-playthrough state"): quest markers belong to the old quests
|
|
155
|
+
e.events.on('session:end', () => { for (const m of quest.values()) m.remove(); quest.clear(); });
|
|
156
|
+
e.events.on('i18n:change', () => { for (const [id, it] of items) it.part?.update({ id, ...it.o }); });
|
|
157
|
+
return api;
|
|
158
|
+
},
|
|
159
|
+
frame() { for (const m of api.markers) updateMarker(m); },
|
|
160
|
+
describe() {
|
|
161
|
+
return {
|
|
162
|
+
markers: api.markers.map(m => ({ label: typeof m.o.label === 'function' ? m.o.label() : m.o.label ?? null, distance: m.dist, onScreen: m.onScreen, visible: m.visible })),
|
|
163
|
+
counters: Object.fromEntries([...items].map(([id, it]) => [id, it.o.value ?? null])),
|
|
164
|
+
};
|
|
165
|
+
},
|
|
166
|
+
};
|
|
167
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// Default HUD UI parts (hud.marker, hud.counter, hud.bar). hud/index.js keeps the logic (targets, projection, edge arrows, quest sync)
|
|
2
|
+
// and hands each part plain data; a game replaces any of them with engine.ui.set('hud.counter', ...) or turns it off with false.
|
|
3
|
+
// Look: CSS classes .threedog-hud .threedog-hud-stats .threedog-hud-marker .threedog-hud-arrow .threedog-hud-counter .threedog-hud-bar;
|
|
4
|
+
// colors --threedog-hud-bg/fg/accent (style pack style.ui.hudBg...); layout is plain CSS, so style.ui.css moves the stats column, sizes, fonts.
|
|
5
|
+
// Inner HTML: style.ui.templates.hudMarker / hudCounter / hudBar (data, { esc, t }) => HTML.
|
|
6
|
+
import { esc, placeAt } from '../../ui/UI.js';
|
|
7
|
+
/** @import { Engine, UIPart } from '../../types/core' */
|
|
8
|
+
|
|
9
|
+
export const CSS = `
|
|
10
|
+
.threedog-hud{position:fixed;inset:0;pointer-events:none;z-index:12;font:13px/1.4 var(--threedog-font);color:var(--threedog-hud-fg)}
|
|
11
|
+
.threedog-hud-stats{position:absolute;left:calc(12px + env(safe-area-inset-left,0px));top:calc(12px + env(safe-area-inset-top,0px));display:flex;flex-direction:column;gap:6px}
|
|
12
|
+
.threedog-hud-counter,.threedog-hud-bar{background:var(--threedog-hud-bg);border-radius:8px;padding:4px 10px;min-width:120px}
|
|
13
|
+
.threedog-hud-bar-track{height:6px;border-radius:3px;background:var(--threedog-line);overflow:hidden;margin-top:3px}
|
|
14
|
+
.threedog-hud-bar-fill{height:100%;width:calc(var(--threedog-hud-fill,0) * 100%);background:var(--threedog-hud-accent)}
|
|
15
|
+
.threedog-hud-marker{position:absolute;left:0;top:0;transform:translate(-50%,-100%);display:flex;flex-direction:column;align-items:center;white-space:nowrap;text-shadow:0 1px 2px rgba(0,0,0,.6)}
|
|
16
|
+
.threedog-hud-marker::after{content:'';width:10px;height:10px;margin-top:2px;border-radius:50%;background:var(--threedog-hud-accent)}
|
|
17
|
+
.threedog-hud-marker.threedog-hud-arrow{transform:translate(-50%,-50%)}
|
|
18
|
+
.threedog-hud-marker.threedog-hud-arrow::after{width:0;height:0;border-radius:0;border:7px solid transparent;border-left:12px solid var(--threedog-hud-accent);order:-1;transform:rotate(var(--threedog-hud-angle,0rad))}
|
|
19
|
+
.threedog-hud-dist{color:var(--threedog-hud-accent);font-size:12px}
|
|
20
|
+
`;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Declare the default HUD parts. layer / stats are hud's containers (created only when some default part is in use).
|
|
24
|
+
* @param {Engine} e
|
|
25
|
+
* @param {() => { layer: HTMLElement, stats: HTMLElement }} root
|
|
26
|
+
* @returns {void}
|
|
27
|
+
*/
|
|
28
|
+
export function defineHudParts(e, root) {
|
|
29
|
+
const tools = { esc, t: (k, p) => e.t(k, p) };
|
|
30
|
+
const tpl = name => e.style.ui?.templates?.[name];
|
|
31
|
+
|
|
32
|
+
// One marker: update({ x, y, arrow, angle, label, icon, distance }) moves and redraws it; hide() hides it
|
|
33
|
+
e.ui.define('hud.marker', () => {
|
|
34
|
+
const el = document.createElement('div');
|
|
35
|
+
el.className = 'threedog-hud-marker'; el.hidden = true; root().layer.appendChild(el);
|
|
36
|
+
let html = null;
|
|
37
|
+
return {
|
|
38
|
+
el,
|
|
39
|
+
update(d) {
|
|
40
|
+
el.hidden = false;
|
|
41
|
+
el.classList.toggle('threedog-hud-arrow', d.arrow);
|
|
42
|
+
if (d.arrow) el.style.setProperty('--threedog-hud-angle', d.angle.toFixed(3) + 'rad');
|
|
43
|
+
placeAt(el, d.x, d.y);
|
|
44
|
+
const t = tpl('hudMarker');
|
|
45
|
+
const h = t ? t(d, tools) : `${d.icon || d.label ? `<span class="threedog-hud-label">${esc(d.icon)} ${esc(d.label)}</span>` : ''}${d.distance ? `<span class="threedog-hud-dist">${esc(d.distance)}</span>` : ''}`;
|
|
46
|
+
if (h !== html) { html = h; el.innerHTML = h; } // rebuild only when the text changed (called every frame)
|
|
47
|
+
},
|
|
48
|
+
hide() { el.hidden = true; },
|
|
49
|
+
dispose() { el.remove(); },
|
|
50
|
+
};
|
|
51
|
+
}, { multi: true });
|
|
52
|
+
|
|
53
|
+
e.ui.define('hud.counter', () => {
|
|
54
|
+
const el = document.createElement('div'); el.className = 'threedog-hud-counter'; root().stats.appendChild(el);
|
|
55
|
+
return {
|
|
56
|
+
el,
|
|
57
|
+
update(d) {
|
|
58
|
+
const t = tpl('hudCounter');
|
|
59
|
+
if (t) el.innerHTML = t(d, tools);
|
|
60
|
+
else el.textContent = `${d.icon ?? ''} ${d.label ?? d.id} ${d.value ?? 0}${d.max != null ? ' / ' + d.max : ''}`.trim();
|
|
61
|
+
},
|
|
62
|
+
dispose() { el.remove(); },
|
|
63
|
+
};
|
|
64
|
+
}, { multi: true });
|
|
65
|
+
|
|
66
|
+
e.ui.define('hud.bar', () => {
|
|
67
|
+
const el = document.createElement('div'); el.className = 'threedog-hud-bar'; root().stats.appendChild(el);
|
|
68
|
+
let label;
|
|
69
|
+
return {
|
|
70
|
+
el,
|
|
71
|
+
update(d) {
|
|
72
|
+
const t = tpl('hudBar');
|
|
73
|
+
if (t) { el.innerHTML = t(d, tools); return; }
|
|
74
|
+
if (label !== d.label) { label = d.label; el.innerHTML = `${d.label ? `<span>${esc(d.label)}</span>` : ''}<div class="threedog-hud-bar-track"><div class="threedog-hud-bar-fill"></div></div>`; }
|
|
75
|
+
el.style.setProperty('--threedog-hud-fill', Math.max(0, Math.min(1, (d.value ?? 0) / (d.max ?? 1))));
|
|
76
|
+
},
|
|
77
|
+
dispose() { el.remove(); },
|
|
78
|
+
};
|
|
79
|
+
}, { multi: true });
|
|
80
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// Geometry the level module derives from its meshes: world-space triangles of the walkable meshes (for the physics module's static colliders) and the
|
|
2
|
+
// best-fit rotated boxes of the collision meshes. Pure functions: no engine, no state.
|
|
3
|
+
import * as THREE from 'three';
|
|
4
|
+
|
|
5
|
+
/** World-space triangles of meshes: [{ positions: Float32Array, indices: Uint32Array }] */
|
|
6
|
+
export function worldTrimeshes(meshes) {
|
|
7
|
+
return meshes.map(m => {
|
|
8
|
+
const g = m.geometry, pos = g.attributes.position, v = new THREE.Vector3();
|
|
9
|
+
const positions = new Float32Array(pos.count * 3);
|
|
10
|
+
for (let i = 0; i < pos.count; i++) { v.fromBufferAttribute(pos, i).applyMatrix4(m.matrixWorld); positions[i * 3] = v.x; positions[i * 3 + 1] = v.y; positions[i * 3 + 2] = v.z; }
|
|
11
|
+
let indices;
|
|
12
|
+
if (g.index) indices = Uint32Array.from(g.index.array);
|
|
13
|
+
else { indices = new Uint32Array(pos.count); for (let i = 0; i < pos.count; i++) indices[i] = i; }
|
|
14
|
+
// mirrored scale (negative determinant) flips triangles; swap order to keep them facing up
|
|
15
|
+
if (m.matrixWorld.determinant() < 0) for (let i = 0; i + 2 < indices.length; i += 3) { const t = indices[i + 1]; indices[i + 1] = indices[i + 2]; indices[i + 2] = t; }
|
|
16
|
+
return { positions, indices };
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Best-fit box of each collision mesh by the mesh's world orientation, as collision.addBox arguments: [{ at: { x, z }, opts }]
|
|
22
|
+
* @param {any[]} meshes
|
|
23
|
+
* @param {{ colliderHeight: number, colliderPad: number }} cfg
|
|
24
|
+
*/
|
|
25
|
+
export function colliderBoxes(meshes, { colliderHeight, colliderPad }) {
|
|
26
|
+
const corner = new THREE.Vector3(), xAxis = new THREE.Vector3(), out = [];
|
|
27
|
+
for (const m of meshes) {
|
|
28
|
+
const g = m.geometry; if (!g) continue;
|
|
29
|
+
if (!g.boundingBox) g.computeBoundingBox();
|
|
30
|
+
const bb = g.boundingBox, mw = m.matrixWorld;
|
|
31
|
+
xAxis.setFromMatrixColumn(mw, 0);
|
|
32
|
+
const yaw = Math.atan2(-xAxis.z, xAxis.x), c = Math.cos(yaw), s = Math.sin(yaw);
|
|
33
|
+
let x0 = Infinity, x1 = -Infinity, z0 = Infinity, z1 = -Infinity, y0 = Infinity, y1 = -Infinity;
|
|
34
|
+
for (let i = 0; i < 8; i++) {
|
|
35
|
+
corner.set(i & 1 ? bb.max.x : bb.min.x, i & 2 ? bb.max.y : bb.min.y, i & 4 ? bb.max.z : bb.min.z).applyMatrix4(mw);
|
|
36
|
+
const lx = corner.x * c - corner.z * s, lz = corner.x * s + corner.z * c; // rotate into the box's own orientation
|
|
37
|
+
x0 = Math.min(x0, lx); x1 = Math.max(x1, lx); z0 = Math.min(z0, lz); z1 = Math.max(z1, lz);
|
|
38
|
+
y0 = Math.min(y0, corner.y); y1 = Math.max(y1, corner.y);
|
|
39
|
+
}
|
|
40
|
+
const lcx = (x0 + x1) / 2, lcz = (z0 + z1) / 2;
|
|
41
|
+
const wx = lcx * c + lcz * s, wz = -lcx * s + lcz * c; // rotate the center back to world space
|
|
42
|
+
const h = Math.max(colliderHeight, y1 - y0);
|
|
43
|
+
out.push({ at: { x: wx, z: wz }, opts: { halfWidth: (x1 - x0) / 2 + colliderPad, halfDepth: (z1 - z0) / 2 + colliderPad, rotation: yaw, height: h, y: y0 } });
|
|
44
|
+
}
|
|
45
|
+
return out;
|
|
46
|
+
}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
// Level heightfield: project walkable meshes onto a horizontal grid, storing per grid point the highest surface height and ground type.
|
|
2
|
+
// Equivalent to casting a ray down at every grid point and taking the highest hit, but it stamps triangles directly,
|
|
3
|
+
// so no ray acceleration structure is needed; tens of thousands of triangles take only tens of ms. Height queries are then O(1) bilinear interpolation.
|
|
4
|
+
//
|
|
5
|
+
// Internal to the level module only:
|
|
6
|
+
// const hf = buildHeightfield(meshes, { cellSize: 0.5, outside: 0, typeOf });
|
|
7
|
+
// hf.height(x, z, refY?) / hf.slope(x, z) / hf.type(x, z)
|
|
8
|
+
//
|
|
9
|
+
// Multi-layer (bridges, caves, interiors): up-facing surfaces more than layerGap apart at one grid point each get a layer (layerGap defaults to character height: a gap too low to stand in, like a crate on the ground, is not a layer). The top layer stays in H/T;
|
|
10
|
+
// other layers are stored only for points that have several (extra: point index -> [{ y, t }]); single-layer levels pay no extra memory or time.
|
|
11
|
+
// height(x, z, refY) with a reference height picks the highest layer not above refY + stepUp.
|
|
12
|
+
import * as THREE from 'three';
|
|
13
|
+
import { MOVEMENT_DEFAULTS } from '../../core/movement.js';
|
|
14
|
+
|
|
15
|
+
// Step-height default comes from the shared movement params (core/movement.js); level passes engine.movement.stepHeight, don't hardcode it elsewhere
|
|
16
|
+
const STEP_UP = MOVEMENT_DEFAULTS.stepHeight, LAYER_GAP = MOVEMENT_DEFAULTS.height; // step height, min gap between layers (character height)
|
|
17
|
+
|
|
18
|
+
const _a = new THREE.Vector3(), _b = new THREE.Vector3(), _c = new THREE.Vector3();
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* meshes walkable meshes (world matrices must be up to date)
|
|
22
|
+
* cellSize cell edge length (m); auto-enlarged for huge scenes so memory stays bounded (capped at maxCells grid points)
|
|
23
|
+
* outside height returned outside the mesh or at points with no surface
|
|
24
|
+
* typeOf(mesh, materialIndex) -> ground type string
|
|
25
|
+
* sharpEdge corner-height difference within a cell (m) above which it is a cliff/wall edge: no interpolation, take the nearest corner,
|
|
26
|
+
* otherwise a 2 m platform edge would smear into a 0.5 m wide slope the character could climb in tiny steps
|
|
27
|
+
*/
|
|
28
|
+
export function buildHeightfield(meshes, { cellSize = 0.5, outside = 0, maxCells = 4e6, typeOf = () => 'default', sharpEdge = 0.6, layerGap = LAYER_GAP, stepUp = STEP_UP } = {}) {
|
|
29
|
+
const bounds = new THREE.Box3();
|
|
30
|
+
for (const m of meshes) bounds.expandByObject(m);
|
|
31
|
+
if (bounds.isEmpty()) return emptyField(outside);
|
|
32
|
+
|
|
33
|
+
let cell = cellSize, nx, nz;
|
|
34
|
+
const w = bounds.max.x - bounds.min.x, d = bounds.max.z - bounds.min.z;
|
|
35
|
+
for (;;) {
|
|
36
|
+
nx = Math.max(2, Math.ceil(w / cell) + 1); nz = Math.max(2, Math.ceil(d / cell) + 1);
|
|
37
|
+
if (nx * nz <= maxCells) break;
|
|
38
|
+
cell *= 1.5;
|
|
39
|
+
}
|
|
40
|
+
if (cell !== cellSize) console.warn(`Level too large; heightfield cell enlarged from ${cellSize}m to ${cell.toFixed(2)}m`);
|
|
41
|
+
const minX = bounds.min.x, minZ = bounds.min.z;
|
|
42
|
+
const H = new Float32Array(nx * nz).fill(-Infinity);
|
|
43
|
+
const T = new Uint16Array(nx * nz); // ground type index into the types array
|
|
44
|
+
const types = ['default'], typeIndex = new Map([['default', 0]]);
|
|
45
|
+
const EPS = 1e-4;
|
|
46
|
+
const extra = new Map(); // multi-layer: point index -> layers other than the top [{ y, t }]
|
|
47
|
+
|
|
48
|
+
for (const mesh of meshes) {
|
|
49
|
+
const g = mesh.geometry, pos = g?.attributes?.position;
|
|
50
|
+
if (!pos) continue;
|
|
51
|
+
const idx = g.index, mw = mesh.matrixWorld;
|
|
52
|
+
const triCount = (idx ? idx.count : pos.count) / 3;
|
|
53
|
+
// multi-material mesh: find each triangle's material via geometry.groups
|
|
54
|
+
const groups = Array.isArray(mesh.material) && g.groups.length ? g.groups : null;
|
|
55
|
+
let curType = typeId(typeOf(mesh, 0)), gi = 0;
|
|
56
|
+
for (let t = 0; t < triCount; t++) {
|
|
57
|
+
if (groups) {
|
|
58
|
+
const v0 = t * 3;
|
|
59
|
+
while (gi < groups.length && v0 >= groups[gi].start + groups[gi].count) gi++;
|
|
60
|
+
curType = gi < groups.length ? typeId(typeOf(mesh, groups[gi].materialIndex)) : 0;
|
|
61
|
+
}
|
|
62
|
+
const i0 = idx ? idx.getX(t * 3) : t * 3, i1 = idx ? idx.getX(t * 3 + 1) : t * 3 + 1, i2 = idx ? idx.getX(t * 3 + 2) : t * 3 + 2;
|
|
63
|
+
_a.fromBufferAttribute(pos, i0).applyMatrix4(mw);
|
|
64
|
+
_b.fromBufferAttribute(pos, i1).applyMatrix4(mw);
|
|
65
|
+
_c.fromBufferAttribute(pos, i2).applyMatrix4(mw);
|
|
66
|
+
const ax = _a.x, az = _a.z, bx = _b.x, bz = _b.z, cx = _c.x, cz = _c.z;
|
|
67
|
+
const det = (bz - cz) * (ax - cx) + (cx - bx) * (az - cz);
|
|
68
|
+
if (Math.abs(det) < 1e-9) continue; // vertical faces (wall sides) are invisible from above
|
|
69
|
+
const up = (_b.z - _a.z) * (_c.x - _a.x) - (_b.x - _a.x) * (_c.z - _a.z) > 0; // only up-facing faces count as an extra layer (a box bottom is not walkable)
|
|
70
|
+
const ia = Math.max(0, Math.ceil((Math.min(ax, bx, cx) - minX) / cell - 1e-6));
|
|
71
|
+
const ib = Math.min(nx - 1, Math.floor((Math.max(ax, bx, cx) - minX) / cell + 1e-6));
|
|
72
|
+
const ja = Math.max(0, Math.ceil((Math.min(az, bz, cz) - minZ) / cell - 1e-6));
|
|
73
|
+
const jb = Math.min(nz - 1, Math.floor((Math.max(az, bz, cz) - minZ) / cell + 1e-6));
|
|
74
|
+
for (let j = ja; j <= jb; j++) {
|
|
75
|
+
const pz = minZ + j * cell;
|
|
76
|
+
for (let i = ia; i <= ib; i++) {
|
|
77
|
+
const px = minX + i * cell;
|
|
78
|
+
const l1 = ((bz - cz) * (px - cx) + (cx - bx) * (pz - cz)) / det;
|
|
79
|
+
if (l1 < -EPS) continue;
|
|
80
|
+
const l2 = ((cz - az) * (px - cx) + (ax - cx) * (pz - cz)) / det;
|
|
81
|
+
if (l2 < -EPS) continue;
|
|
82
|
+
const l3 = 1 - l1 - l2;
|
|
83
|
+
if (l3 < -EPS) continue;
|
|
84
|
+
const y = l1 * _a.y + l2 * _b.y + l3 * _c.y, k = j * nx + i;
|
|
85
|
+
const top = H[k];
|
|
86
|
+
if (top === -Infinity) { H[k] = y; T[k] = curType; continue; }
|
|
87
|
+
if (y > top) {
|
|
88
|
+
if (y - top > layerGap && up) addLayer(k, top, T[k]); // the old top layer becomes a lower layer
|
|
89
|
+
H[k] = y; T[k] = curType;
|
|
90
|
+
} else if (top - y > layerGap && up) addLayer(k, y, curType);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
for (let k = 0; k < H.length; k++) if (H[k] === -Infinity) H[k] = outside;
|
|
96
|
+
|
|
97
|
+
// record an extra layer; within layerGap of an existing layer counts as the same layer, keep the higher
|
|
98
|
+
function addLayer(k, y, t) {
|
|
99
|
+
let a = extra.get(k);
|
|
100
|
+
if (!a) extra.set(k, a = []);
|
|
101
|
+
for (const l of a) if (Math.abs(l.y - y) <= layerGap) { if (y > l.y) { l.y = y; l.t = t; } return; }
|
|
102
|
+
a.push({ y, t });
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function typeId(name) {
|
|
106
|
+
let id = typeIndex.get(name);
|
|
107
|
+
if (id === undefined) { id = types.length; types.push(name); typeIndex.set(name, id); }
|
|
108
|
+
return id;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// highest layer below limit lim at a point; if none, take the lowest layer (so a cave with only a ceiling overhead still has a floor)
|
|
112
|
+
function layerAt(k, lim) {
|
|
113
|
+
const a = extra.get(k);
|
|
114
|
+
if (!a || H[k] <= lim) return H[k];
|
|
115
|
+
let best = -Infinity, low = H[k];
|
|
116
|
+
for (const l of a) { if (l.y <= lim && l.y > best) best = l.y; if (l.y < low) low = l.y; }
|
|
117
|
+
return best > -Infinity ? best : low;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const maxI = nx - 1, maxJ = nz - 1;
|
|
121
|
+
return {
|
|
122
|
+
cell, nx, nz, minX, minZ, H, T, types, bounds, extra,
|
|
123
|
+
/** Bilinear height; outside the grid returns outside. With refY: highest layer not above refY + stepUp; without, the top layer */
|
|
124
|
+
height(x, z, refY) {
|
|
125
|
+
const fx = (x - minX) / cell, fz = (z - minZ) / cell;
|
|
126
|
+
if (!(fx >= 0 && fz >= 0 && fx <= maxI && fz <= maxJ)) return outside;
|
|
127
|
+
const i = Math.min(maxI - 1, fx | 0), j = Math.min(maxJ - 1, fz | 0), tx = fx - i, tz = fz - j, k = j * nx + i;
|
|
128
|
+
let h00 = H[k], h10 = H[k + 1], h01 = H[k + nx], h11 = H[k + nx + 1];
|
|
129
|
+
if (refY !== undefined && extra.size && (extra.has(k) || extra.has(k + 1) || extra.has(k + nx) || extra.has(k + nx + 1))) {
|
|
130
|
+
const lim = refY + stepUp;
|
|
131
|
+
h00 = layerAt(k, lim); h10 = layerAt(k + 1, lim); h01 = layerAt(k + nx, lim); h11 = layerAt(k + nx + 1, lim);
|
|
132
|
+
}
|
|
133
|
+
if (Math.max(h00, h10, h01, h11) - Math.min(h00, h10, h01, h11) > sharpEdge) return tz < 0.5 ? (tx < 0.5 ? h00 : h10) : (tx < 0.5 ? h01 : h11);
|
|
134
|
+
return (h00 * (1 - tx) + h10 * tx) * (1 - tz) + (h01 * (1 - tx) + h11 * tx) * tz;
|
|
135
|
+
},
|
|
136
|
+
/** Slope = height change / horizontal distance (same as the terrain module) */
|
|
137
|
+
slope(x, z) {
|
|
138
|
+
const fx = (x - minX) / cell, fz = (z - minZ) / cell;
|
|
139
|
+
if (!(fx >= 0 && fz >= 0 && fx <= maxI && fz <= maxJ)) return 0;
|
|
140
|
+
const i = Math.min(maxI - 1, fx | 0), j = Math.min(maxJ - 1, fz | 0), tx = fx - i, tz = fz - j, k = j * nx + i;
|
|
141
|
+
const h00 = H[k], h10 = H[k + 1], h01 = H[k + nx], h11 = H[k + nx + 1];
|
|
142
|
+
const gx = ((h10 - h00) * (1 - tz) + (h11 - h01) * tz) / cell, gz = ((h01 - h00) * (1 - tx) + (h11 - h10) * tx) / cell;
|
|
143
|
+
return Math.sqrt(gx * gx + gz * gz);
|
|
144
|
+
},
|
|
145
|
+
/** Ground type at the nearest grid point */
|
|
146
|
+
type(x, z) {
|
|
147
|
+
const fx = (x - minX) / cell, fz = (z - minZ) / cell;
|
|
148
|
+
// same bounds as height / slope: rounding alone would give a point up to half a cell outside the grid the edge's type while
|
|
149
|
+
// height already says "outside", and a rule picking that type would plant on the outside plane next to the floor
|
|
150
|
+
if (!(fx >= 0 && fz >= 0 && fx <= maxI && fz <= maxJ)) return 'default';
|
|
151
|
+
const i = Math.round(fx), j = Math.round(fz);
|
|
152
|
+
return types[T[j * nx + i]];
|
|
153
|
+
},
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function emptyField(outside) {
|
|
158
|
+
return { cell: 1, nx: 0, nz: 0, minX: 0, minZ: 0, H: new Float32Array(0), T: new Uint16Array(0), types: ['default'], bounds: new THREE.Box3(),
|
|
159
|
+
height: () => outside, slope: () => 0, type: () => 'default' };
|
|
160
|
+
}
|