@wildshard/engine 0.1.18 → 0.1.20
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 +16 -0
- package/budgets/shard-size-baseline.json +10 -4
- package/index.html +6 -4
- package/lint/engine-sides.json +18 -0
- package/lint/ratchet.json +0 -68
- package/lint/ratchet.mjs +1 -4
- package/package.json +19 -15
- package/scripts/agent-sync.mjs +27 -8
- package/scripts/app-build/appCook.ts +8 -2
- package/scripts/app-build/catalogue.ts +10 -7
- package/scripts/app-build/gen.ts +33 -2
- package/scripts/app-build/isolation.d.mts +10 -0
- package/scripts/app-build/isolation.mjs +47 -0
- package/scripts/app-build/outputProducts.mjs +4 -0
- package/scripts/app-build/previousDeploy.d.mts +2 -0
- package/scripts/app-build/previousDeploy.mjs +10 -1
- package/scripts/app-build/serviceWorker.ts +10 -3
- package/scripts/app-build/splitOutput.mjs +4 -2
- package/scripts/app-build/standaloneOutput.d.mts +1 -1
- package/scripts/app-build/standaloneOutput.mjs +5 -3
- package/scripts/app-build/titlePreloads.d.mts +8 -0
- package/scripts/app-build/titlePreloads.mjs +69 -0
- package/scripts/app-build/worldMapAtlas.ts +10 -6
- package/scripts/app-build-pipeline.mjs +31 -3
- package/scripts/built-product.mjs +1 -1
- package/scripts/cell-mem-bench.mjs +83 -23
- package/scripts/check-custom-sections-zero.mjs +1 -1
- package/scripts/check-devserver.mjs +2 -0
- package/scripts/check-models.mjs +2 -0
- package/scripts/check-paths.allow.json +0 -115
- package/scripts/check-paths.mjs +2 -2
- package/scripts/check-platform-ratchets.mjs +2 -3
- package/scripts/chromium-keychain.d.mts +1 -1
- package/scripts/ci-static.sh +1 -1
- package/scripts/committed-fast-checks.mjs +0 -2
- package/scripts/content-sw-proof.mjs +2 -1
- package/scripts/cook-worker.mjs +9 -3
- package/scripts/cook.mjs +18 -5
- package/scripts/docs-inputs-proof.mjs +6 -6
- package/scripts/e7-voice-staging-proof.mjs +1 -1
- package/scripts/gate-related-tests.mjs +1 -1
- package/scripts/git-source-view.mjs +1 -1
- package/scripts/goldens/capture.mjs +17 -5
- package/scripts/grid-crossing-nightly.mjs +59 -0
- package/scripts/grid-crossing-qa.mjs +44 -0
- package/scripts/grid-crossing-ratchet.d.mts +6 -0
- package/scripts/grid-crossing-ratchet.mjs +52 -0
- package/scripts/grid-crossing-report.mjs +122 -0
- package/scripts/grid-crossing-stages.mjs +47 -0
- package/scripts/grid-crossing-tour.mjs +284 -0
- package/scripts/grid-crossing-walk-proof.mjs +126 -17
- package/scripts/host-ruler/roots.mjs +2 -2
- package/scripts/host-ruler.d.mts +91 -0
- package/scripts/host-ruler.mjs +565 -0
- package/scripts/land.mjs +2 -1
- package/scripts/live-prepush.py +3 -5
- package/scripts/loading-flow/benchmax.mjs +37 -12
- package/scripts/loading-flow/deskbench.mjs +276 -0
- package/scripts/loading-flow/stalls.d.mts +17 -3
- package/scripts/loading-flow/stalls.mjs +82 -3
- package/scripts/look-loop/test_look_loop.py +1 -38
- package/scripts/memory-proof.mjs +61 -6
- package/scripts/mmo-bots.mjs +8 -2
- package/scripts/net-lag-proof.mjs +219 -0
- package/scripts/night-market-kit-budget.mjs +2 -2
- package/scripts/nightly-model.ts +9 -6
- package/scripts/offline-proof-rules.d.mts +2 -2
- package/scripts/offline-proof-rules.mjs +15 -4
- package/scripts/offline-proof.mjs +80 -13
- package/scripts/{shard-platform-output.mjs → output-reader.mjs} +1 -1
- package/scripts/page-release/content.d.mts +9 -1
- package/scripts/page-release/content.mjs +131 -17
- package/scripts/page-release/flow.mjs +36 -10
- package/scripts/page-release/stamp-content.mjs +24 -0
- package/scripts/page-release.mjs +28 -6
- package/scripts/page-size.mjs +2 -1
- package/scripts/parity/boot-smoke.mjs +13 -2
- package/scripts/pin-format.ts +5 -2
- package/scripts/pin-packs.ts +1 -1
- package/scripts/pins-reuse.d.mts +1 -0
- package/scripts/pins-reuse.mjs +22 -0
- package/scripts/pins.ts +4 -4
- package/scripts/precommit-checks.mjs +1 -7
- package/scripts/precommit-jobs.mjs +0 -1
- package/scripts/precommit-source.py +1 -9
- package/scripts/program-discovery.mjs +1 -1
- package/scripts/ring-cook.mjs +2 -1
- package/scripts/ring-step.ts +1 -1
- package/scripts/scratch-dir.mjs +95 -0
- package/scripts/scratch-sweep.mjs +182 -0
- package/scripts/script-scenario-metrics.mjs +1 -1
- package/scripts/shard-output-content.d.mts +1 -1
- package/scripts/shard-output-content.mjs +2 -2
- package/scripts/shard-outputs.mjs +1 -1
- package/scripts/shard-public.mjs +1 -1
- package/scripts/shard-wire-meter.mjs +24 -9
- package/scripts/side-parity.mjs +4 -2
- package/scripts/standalone-smoke.mjs +8 -3
- package/scripts/tier-textures.mjs +22 -4
- package/scripts/tile-bake-report.mjs +1 -1
- package/scripts/tile-bakes.mjs +1 -1
- package/scripts/title-assets.generated.json +2 -0
- package/scripts/tsconfig.json +2 -14
- package/scripts/vendor/basisu/LICENSE +201 -0
- package/scripts/vendor/basisu/basis_encoder.cjs +2 -0
- package/scripts/vendor/basisu/basis_encoder.wasm +0 -0
- package/scripts/vitest-push-guards.config.ts +1 -1
- package/scripts/vps/harden-apply.sh +4 -1
- package/scripts/vps/harden-prometheus.sh +179 -0
- package/scripts/vps/harden.sh +16 -0
- package/scripts/vps/rebuild.sh +18 -0
- package/scripts/vps/wildshard-config +6 -2
- package/scripts/worker-client-play.mjs +6 -2
- package/scripts/worktree-reap.mjs +59 -13
- package/scripts/worktree.mjs +19 -5
- package/src/.oxlintrc.json +3 -182
- package/src/client/app/entry.ts +10 -2
- package/src/client/engine/anim/rigParser.ts +2 -2
- package/src/client/engine/boot/bootCache.ts +2 -2
- package/src/client/engine/boot/bootTrace.ts +12 -4
- package/src/client/engine/boot/browserChunkRecovery.ts +4 -0
- package/src/client/engine/boot/clearDownloads.ts +5 -2
- package/src/client/engine/boot/contentRead.ts +11 -0
- package/src/client/engine/boot/gpuFiles.ts +4 -2
- package/src/client/engine/boot/lastEnd.ts +99 -12
- package/src/client/engine/boot/texturePack.ts +2 -2
- package/src/client/engine/core/Game.ts +63 -19
- package/src/client/engine/core/gpuOnly.ts +10 -0
- package/src/client/engine/core/renderBudget.ts +134 -0
- package/src/client/engine/net/netPlayer.ts +19 -2
- package/src/client/engine/net/otherPlayers.ts +55 -8
- package/src/client/engine/net/predictor.ts +33 -9
- package/src/client/engine/net/redial.ts +68 -10
- package/src/client/engine/pwa/cacheNames.ts +58 -1
- package/src/client/engine/pwa/sw.js +41 -11
- package/src/client/engine/render/dataLook.ts +219 -44
- package/src/client/engine/render/families/detail.ts +89 -0
- package/src/client/engine/render/families/pbr.ts +9 -1
- package/src/client/engine/render/families/registry.ts +11 -2
- package/src/client/engine/render/families/sceneSurface.ts +116 -0
- package/src/client/engine/render/look.ts +12 -0
- package/src/client/engine/render/lookLight.ts +103 -11
- package/src/client/engine/render/lookRender.ts +105 -0
- package/src/client/engine/render/precompile.ts +4 -2
- package/src/client/engine/render/tiers.ts +4 -1
- package/src/client/engine/saves/indexed.ts +2 -2
- package/src/client/engine/telemetry/browserErrors.ts +24 -3
- package/src/client/engine/telemetry/staleBuildReport.ts +22 -1
- package/src/client/engine/ui/debugOptions.ts +1 -1
- package/src/client/engine/ui/lookLightOption.ts +10 -6
- package/src/client/engine/ui/namePrompt.ts +7 -0
- package/src/client/engine/world/declaredProps.ts +5 -1
- package/src/client/engine/world/skyRig.ts +4 -1
- package/src/client/engine/world/terrainTileView.ts +64 -23
- package/src/client/game/boot/audio.generated.ts +114 -114
- package/src/client/game/boot/bytes.generated.ts +118 -220
- package/src/client/game/boot/placedSpawn.ts +35 -0
- package/src/client/game/boot/spawnDownload.ts +25 -6
- package/src/client/game/boot/versions.generated.ts +7 -5
- package/src/client/game/devScene/hook.ts +428 -0
- package/src/client/game/devScene/liveLook.ts +21 -0
- package/src/client/game/grid/cellLoading.ts +12 -2
- package/src/client/game/grid/live.ts +152 -19
- package/src/client/game/grid/liveSession.ts +53 -3
- package/src/client/game/grid/mapAtlas.ts +18 -4
- package/src/client/game/grid/minimapBlend.ts +15 -5
- package/src/client/game/grid/oneWayIn.ts +5 -1
- package/src/client/game/grid/pageEntry.ts +12 -1
- package/src/client/game/grid/placedCells.ts +114 -12
- package/src/client/game/grid/placedContent.ts +85 -0
- package/src/client/game/grid/prefetch.ts +9 -1
- package/src/client/game/grid/productInputs.ts +23 -10
- package/src/client/game/grid/productLeases.ts +4 -1
- package/src/client/game/grid/products.ts +8 -4
- package/src/client/game/grid/roadLook.ts +24 -15
- package/src/client/game/grid/roadLookPlatform.ts +4 -2
- package/src/client/game/grid/roadResources.ts +24 -0
- package/src/client/game/grid/roadSign.worker.ts +4 -3
- package/src/client/game/grid/roadSignPaint.ts +16 -5
- package/src/client/game/grid/roadSignPreparation.ts +4 -3
- package/src/client/game/grid/roadSignScale.ts +8 -0
- package/src/client/game/grid/roadTileCapture.worker.ts +3 -1
- package/src/client/game/grid/roadTileCaptureWorker.ts +2 -1
- package/src/client/game/grid/roadTileWrite.worker.ts +4 -2
- package/src/client/game/grid/roadTileWriter.ts +2 -1
- package/src/client/game/grid/screenReports.ts +39 -0
- package/src/client/game/grid/session.ts +32 -7
- package/src/client/game/grid/softWallLook.ts +25 -8
- package/src/client/game/mainMenu.ts +6 -2
- package/src/client/game/plugin/context.ts +2 -1
- package/src/client/game/plugin/followedMovers.ts +7 -1
- package/src/client/game/quest/figures.ts +2 -0
- package/src/client/game/session/finish.ts +9 -0
- package/src/client/game/shardfile/assetCache.ts +4 -4
- package/src/client/game/shardfile/client.ts +28 -8
- package/src/client/game/shardfile/clientAssets.ts +9 -5
- package/src/client/game/shardfile/clientLibrary.ts +1 -1
- package/src/client/game/shardfile/clientPropMaterials.ts +4 -1
- package/src/client/game/shardfile/clientViews.ts +36 -8
- package/src/client/game/shardfile/clientWater.ts +51 -9
- package/src/client/game/shardfile/clientWorker.ts +19 -7
- package/src/client/game/shardfile/constructionCheckpoint.ts +2 -2
- package/src/client/game/shardfile/groundMerge.ts +57 -5
- package/src/client/game/shardfile/hybrid.ts +2 -0
- package/src/client/game/shardfile/look.ts +8 -3
- package/src/client/game/shardfile/product.ts +34 -7
- package/src/client/game/shardfile/productChecks.ts +2 -2
- package/src/client/game/shardfile/productCost.ts +2 -2
- package/src/client/game/shardfile/readAsset.ts +2 -2
- package/src/client/game/shardfile/reflectingWater.ts +73 -0
- package/src/client/game/shardfile/seatGrace.ts +9 -0
- package/src/client/game/shardfile/skinPlayback.ts +1 -1
- package/src/client/game/shardfile/slabLibrary.ts +115 -49
- package/src/client/game/shardfile/tileContent.ts +1 -1
- package/src/client/game/shardfile/tileDriver.ts +38 -11
- package/src/client/game/shardfile/wirePage.ts +7 -3
- package/src/client/game/shardfile/worldScenes.ts +17 -10
- package/src/client/game/systems/npc/figureRows.ts +9 -0
- package/src/client/host/online/doctor.ts +22 -7
- package/src/client/host/online/doctorView.ts +2 -0
- package/src/client/host/online/linkScreens.ts +109 -5
- package/src/client/host/online/shell.ts +13 -4
- package/src/client/host/standalone/shell.ts +40 -0
- package/src/cook/game/astc6Encode.ts +55 -0
- package/src/cook/game/astc6Wasm.ts +176 -0
- package/src/cook/game/cookJob.ts +30 -6
- package/src/cook/game/cookWorker.ts +38 -11
- package/src/cook/game/entryTotals.ts +51 -24
- package/src/cook/game/shardCook.ts +35 -7
- package/src/cook/game/spawnParts.ts +33 -8
- package/src/cook/game/tierTextures.ts +87 -14
- package/src/server/engine/ai/bossContenders.ts +27 -3
- package/src/server/engine/ai/phases.ts +1 -1
- package/src/server/engine/entities/creatureRefill.ts +9 -2
- package/src/server/engine/net/ledgerBook.ts +2 -0
- package/src/server/engine/net/room.ts +15 -0
- package/src/server/engine/sim/respawn.ts +8 -0
- package/src/server/game/boss/arenaRoomEntry.ts +5 -1
- package/src/server/game/boss/arenaRoomNative.ts +2 -0
- package/src/server/game/boss/native.ts +2 -1
- package/src/server/game/boss/nativeWake.ts +9 -5
- package/src/server/game/boss/openArenaNative.ts +2 -2
- package/src/server/game/boss/openArenaRoom.ts +3 -1
- package/src/server/game/grid/room.ts +44 -3
- package/src/server/game/grid/simulation.ts +23 -0
- package/src/server/game/population/mixedRoster.ts +11 -3
- package/src/server/game/population/nativeBake.ts +8 -3
- package/src/server/game/population/nativeReturns.ts +6 -3
- package/src/server/game/population/roster.ts +5 -3
- package/src/server/game/quest/eliteDrops.ts +18 -3
- package/src/server/game/quest/nativeChapter.ts +1 -1
- package/src/server/game/quest/nativeComposition.ts +5 -1
- package/src/server/game/riding/nativeTaming.ts +22 -7
- package/src/server/game/riding/wildRefill.ts +3 -2
- package/src/server/game/shardfile/bossRow.ts +4 -2
- package/src/server/game/shardfile/homeKeeper.ts +4 -2
- package/src/server/host/bake/headlessWorker.ts +1 -1
- package/src/server/host/dedicated/cellHost.ts +112 -18
- package/src/server/host/dedicated/cellProtocol.ts +18 -1
- package/src/server/host/dedicated/cellWorker.ts +8 -5
- package/src/server/host/dedicated/dedicatedRoom.ts +38 -11
- package/src/server/host/dedicated/gridCells.ts +15 -6
- package/src/server/host/dedicated/loopLag.ts +21 -0
- package/src/server/host/dedicated/main.ts +13 -5
- package/src/server/host/dedicated/packReader.ts +3 -3
- package/src/server/host/dedicated/placementFile.ts +3 -2
- package/src/server/host/dedicated/roadRoom.ts +34 -4
- package/src/server/host/dedicated/serverMetrics.ts +135 -0
- package/src/server/host/dedicated/socketPump.ts +21 -4
- package/src/server/host/dedicated/workerTable.ts +32 -14
- package/src/server/host/dedicated/world.ts +65 -7
- package/src/server/host/headless.ts +1 -1
- package/src/server/host/headlessRuntime.ts +1 -1
- package/src/server/host/standalone/roadWorld.ts +15 -3
- package/src/server/host/standalone/serverHost.ts +57 -8
- package/src/server/host/standalone/serverProduct.ts +48 -16
- package/src/server/host/standalone/serverRuntime.ts +1 -1
- package/src/shared/engine/ai/BossBrain.ts +8 -0
- package/src/shared/engine/core/framePacing.ts +12 -1
- package/src/shared/engine/physics/terrainTiles.ts +20 -4
- package/src/shared/game/boss/wake.ts +6 -0
- package/src/shared/game/devColliders.ts +107 -0
- package/src/shared/game/devGameplay.ts +41 -0
- package/src/shared/game/eliteSystem.ts +8 -0
- package/src/shared/game/grid/allocator.ts +3 -0
- package/src/shared/game/grid/placementRows.ts +5 -2
- package/src/shared/game/plugin/bossRecord.ts +3 -2
- package/src/shared/game/shardfile/ktx2Targets.ts +23 -3
- package/src/shared/game/shardfile/outputDescriptor.ts +9 -5
- package/src/shared/game/shardfile/packReads.ts +28 -3
- package/src/shared/game/shardfile/serverPack.ts +9 -0
- package/src/shared/game/systems/looks/trampleField.ts +2 -0
- package/src/shared/host/formatJsonSchema.ts +2 -2
- package/src/tsconfig.json +1 -27
- package/lint/host-reviews.json +0 -14
- package/lint/listed-view-code.json +0 -13
- package/lint/platform-pending-users.json +0 -2520
- package/lint/platform-pending-users.md +0 -18
- package/scripts/cell-mem/metrics-preload.mjs +0 -65
- package/scripts/check-closed-components.d.mts +0 -7
- package/scripts/check-closed-components.mjs +0 -87
- package/scripts/g571-hosts.d.mts +0 -3
- package/scripts/g571-hosts.mjs +0 -54
- package/scripts/host-ruler/register-migrate.mjs +0 -242
- package/scripts/listed-view-code.d.mts +0 -7
- package/scripts/listed-view-code.mjs +0 -93
- package/scripts/look-loop/fit-lut.py +0 -142
- package/scripts/look-loop/palette-delta.py +0 -183
- package/scripts/look-loop/regions/driftwood-isle.json +0 -25
- package/scripts/look-loop/regions/far-reach.json +0 -225
- package/scripts/look-loop/regions/open-plot-night-market.json +0 -855
- package/scripts/look-loop/regions/pine-hollow.json +0 -22
- package/scripts/look-loop/regions/sunscar-dunes.json +0 -281
- package/scripts/platform-chargebacks.d.mts +0 -9
- package/scripts/platform-chargebacks.mjs +0 -135
- package/scripts/shard-component-spans.d.mts +0 -15
- package/scripts/shard-component-spans.mjs +0 -18
- package/scripts/shard-components.d.mts +0 -16
- package/scripts/shard-components.mjs +0 -363
- package/scripts/shard-platform-hosts.d.mts +0 -2
- package/scripts/shard-platform-hosts.mjs +0 -93
- package/scripts/shard-platform-sections.d.mts +0 -2
- package/scripts/shard-platform-sections.mjs +0 -9
- package/scripts/shard-platform.d.mts +0 -76
- package/scripts/shard-platform.mjs +0 -1072
- package/src/.oxfmtrc.json +0 -48
- package/src/scripts/ask-new.sh +0 -29
- package/src/scripts/asks.mjs +0 -142
- package/src/scripts/herdr-prompt.sh +0 -34
- package/src/scripts/herdr-question-open.sh +0 -67
- package/src/scripts/md-wrap.mjs +0 -229
- /package/scripts/{shard-platform-format.d.mts → node-format.d.mts} +0 -0
- /package/scripts/{shard-platform-format.mjs → node-format.mjs} +0 -0
- /package/scripts/{shard-platform-output.d.mts → output-reader.d.mts} +0 -0
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
*/
|
|
17
17
|
import { BufferAttribute, BufferGeometry, Mesh, type Material, type Object3D } from 'three';
|
|
18
18
|
import type { Scope } from '../../../shared/engine/app/scope';
|
|
19
|
-
import { gpuOnlyTrees } from '../core/gpuOnly';
|
|
19
|
+
import { gpuOnlyTrees, refillGpuOnly } from '../core/gpuOnly';
|
|
20
20
|
import { decodeTerrainTile, type TerrainTileData } from '@wildshard/format/terrainTileBytes';
|
|
21
21
|
import { keepShadowWhole } from './shadowChunks';
|
|
22
22
|
|
|
@@ -25,9 +25,12 @@ const COARSE = { resolution: 17, size: 125, half: 8 } as const;
|
|
|
25
25
|
|
|
26
26
|
interface TileState { readonly indices: BufferAttribute; readonly resolution: number }
|
|
27
27
|
const coarseTiles = new WeakMap<Mesh, TileState>();
|
|
28
|
+
/** Where each installed tile sits on the ground, for `refreshTerrainTile`. */
|
|
29
|
+
const shapes = new WeakMap<Mesh, Pick<TerrainTileData, 'resolution' | 'x' | 'z' | 'size'>>();
|
|
28
30
|
|
|
29
31
|
/** True when this tile is a coarse tile whose quadrants refinement may hide. */
|
|
30
|
-
|
|
32
|
+
/** a coarse (L1) terrain tile: no skirt, its quadrants masked under fine tiles */
|
|
33
|
+
export function isCoarse(data: TerrainTileData): boolean { return data.resolution === COARSE.resolution && data.size === COARSE.size; }
|
|
31
34
|
|
|
32
35
|
/** A grid's slope along one axis at sample `at` of `n`: central inside, second-order one-sided on the grid's edge. Sample
|
|
33
36
|
* `i` of the line is `heights[base + i * stride]` (no closure per vertex: a tile's normals run once per sample at boot). */
|
|
@@ -98,29 +101,17 @@ function perimeter(r: number): number[] {
|
|
|
98
101
|
*/
|
|
99
102
|
export function installTerrainTile(bytes: Uint8Array | TerrainTileData, ports: { root: Object3D; scope: Scope; material: Material; shadow: boolean; lattice?: TerrainTileData }): Mesh {
|
|
100
103
|
if (ports.scope.disposed) throw new Error('terrain tile: its scope is already disposed');
|
|
101
|
-
const data = bytes instanceof Uint8Array ? decodeTerrainTile(bytes) : bytes, r = data.resolution,
|
|
102
|
-
|
|
103
|
-
const
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
const positions = new Float32Array(vertices * 3), normals = new Float32Array(vertices * 3), colour = coarse ? colours : new Float32Array(vertices * 3);
|
|
107
|
-
const indices = vertices > 65535 ? new Uint32Array(total) : new Uint16Array(total), cell = data.size / (r - 1);
|
|
108
|
-
for (let z = 0; z < r; z++) for (let x = 0; x < r; x++) {
|
|
109
|
-
const vertex = z * r + x, at = vertex * 3;
|
|
110
|
-
positions[at] = x * cell; positions[at + 1] = data.heights[vertex] ?? 0; positions[at + 2] = z * cell;
|
|
104
|
+
const data = bytes instanceof Uint8Array ? decodeTerrainTile(bytes) : bytes, r = data.resolution, coarse = isCoarse(data);
|
|
105
|
+
const { positions, normals, colour, vertices } = tileVertices(data, ports.lattice);
|
|
106
|
+
const ring = coarse ? 0 : vertices - r * r, gridIndices = (r - 1) ** 2 * 6, total = gridIndices + ring * 6;
|
|
107
|
+
const indices = vertices > 65535 ? new Uint32Array(total) : new Uint16Array(total);
|
|
108
|
+
for (let z = 0; z < r - 1; z++) for (let x = 0; x < r - 1; x++) {
|
|
111
109
|
// Rapier's split: the triangles (x, z) (x, z+1) (x+1, z) and (x+1, z) (x, z+1) (x+1, z+1), diagonal (x+1, z)–(x, z+1).
|
|
112
|
-
|
|
110
|
+
const vertex = z * r + x;
|
|
111
|
+
indices.set([vertex, vertex + r, vertex + 1, vertex + 1, vertex + r, vertex + r + 1], (z * (r - 1) + x) * 6);
|
|
113
112
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
const depth = data.size / 16;
|
|
117
|
-
ring.forEach((border, i) => {
|
|
118
|
-
const skirt = grid + i, next = (i + 1) % ring.length, from = border * 3, to = skirt * 3;
|
|
119
|
-
positions[to] = positions[from] ?? 0; positions[to + 1] = (positions[from + 1] ?? 0) - depth; positions[to + 2] = positions[from + 2] ?? 0;
|
|
120
|
-
for (let c = 0; c < 3; c++) { normals[to + c] = normals[from + c] ?? 0; colour[to + c] = colour[from + c] ?? 0; }
|
|
121
|
-
const b = ring[next] ?? border;
|
|
122
|
-
indices.set([border, b, skirt, b, grid + next, skirt], gridIndices + i * 6);
|
|
123
|
-
});
|
|
113
|
+
const edge = coarse ? [] : perimeter(r), grid = r * r;
|
|
114
|
+
edge.forEach((border, i) => { const next = (i + 1) % edge.length, b = edge[next] ?? border; indices.set([border, b, grid + i, b, grid + next, grid + i], gridIndices + i * 6); });
|
|
124
115
|
const geometry = ports.scope.own(new BufferGeometry());
|
|
125
116
|
geometry.setAttribute('position', new BufferAttribute(positions, 3));
|
|
126
117
|
geometry.setAttribute('normal', new BufferAttribute(normals, 3));
|
|
@@ -135,10 +126,60 @@ export function installTerrainTile(bytes: Uint8Array | TerrainTileData, ports: {
|
|
|
135
126
|
// a tile is already one shadow-culling piece, and the caller's shadow disc switches its castShadow: never split it (SF16)
|
|
136
127
|
keepShadowWhole(mesh);
|
|
137
128
|
if (coarse) coarseTiles.set(mesh, { indices: index, resolution: r });
|
|
129
|
+
shapes.set(mesh, { resolution: r, x: data.x, z: data.z, size: data.size });
|
|
138
130
|
ports.root.add(mesh); ports.scope.onDispose(() => { mesh.removeFromParent(); coarseTiles.delete(mesh); });
|
|
139
131
|
return mesh;
|
|
140
132
|
}
|
|
141
133
|
|
|
134
|
+
/** A tile's vertex arrays, its skirt ring after the grid on a fine tile: what `installTerrainTile` uploads. */
|
|
135
|
+
function tileVertices(data: TerrainTileData, lattice: TerrainTileData | undefined): { positions: Float32Array; normals: Float32Array; colour: Float32Array; vertices: number } {
|
|
136
|
+
const r = data.resolution, colours = data.colours;
|
|
137
|
+
if (colours === undefined) throw new Error('terrain tile: a render tile needs vertex colours (a heights-only payload is a collider)');
|
|
138
|
+
const coarse = isCoarse(data), ring = coarse ? [] : perimeter(r), grid = r * r, vertices = grid + ring.length;
|
|
139
|
+
// a coarse tile has no skirt, so it draws the decoded colours as they are; a skirted tile extends a copy
|
|
140
|
+
const positions = new Float32Array(vertices * 3), normals = new Float32Array(vertices * 3), colour = coarse ? colours : new Float32Array(vertices * 3);
|
|
141
|
+
const cell = data.size / (r - 1);
|
|
142
|
+
for (let z = 0; z < r; z++) for (let x = 0; x < r; x++) {
|
|
143
|
+
const at = (z * r + x) * 3;
|
|
144
|
+
positions[at] = x * cell; positions[at + 1] = data.heights[z * r + x] ?? 0; positions[at + 2] = z * cell;
|
|
145
|
+
}
|
|
146
|
+
if (!coarse) colour.set(colours);
|
|
147
|
+
if (lattice === undefined || !latticeNormals(data, lattice, normals)) gridNormals(data, normals);
|
|
148
|
+
const depth = data.size / 16;
|
|
149
|
+
ring.forEach((border, i) => {
|
|
150
|
+
const from = border * 3, to = (grid + i) * 3;
|
|
151
|
+
positions[to] = positions[from] ?? 0; positions[to + 1] = (positions[from + 1] ?? 0) - depth; positions[to + 2] = positions[from + 2] ?? 0;
|
|
152
|
+
for (let c = 0; c < 3; c++) { normals[to + c] = normals[from + c] ?? 0; colour[to + c] = colour[from + c] ?? 0; }
|
|
153
|
+
});
|
|
154
|
+
return { positions, normals, colour, vertices };
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* SHARD-SOURCE AP18 (dev only: `wildshard watch`'s ground swap). Cut this installed tile again from a new whole-ground
|
|
159
|
+
* lattice (heights and colours, the 257² the tiles were baked from) and rewrite its vertices in their buffers: the same
|
|
160
|
+
* vertices `installTerrainTile` makes from a tile the bake cut from that lattice. False, and nothing written, when the tile
|
|
161
|
+
* is not one of this module's or its vertices are not the lattice's samples.
|
|
162
|
+
*/
|
|
163
|
+
export function refreshTerrainTile(mesh: Mesh, lattice: TerrainTileData): boolean {
|
|
164
|
+
const shape = shapes.get(mesh), colours = lattice.colours;
|
|
165
|
+
if (shape === undefined || colours === undefined) return false;
|
|
166
|
+
const r = shape.resolution, n = lattice.resolution, step = lattice.size / (n - 1), cell = shape.size / (r - 1);
|
|
167
|
+
const heights = new Float32Array(r * r), colour = new Float32Array(r * r * 3);
|
|
168
|
+
for (let z = 0; z < r; z++) for (let x = 0; x < r; x++) {
|
|
169
|
+
const lx = latticeIndex(shape.x + x * cell, lattice.x, step, n), lz = latticeIndex(shape.z + z * cell, lattice.z, step, n);
|
|
170
|
+
if (lx < 0 || lz < 0) return false;
|
|
171
|
+
const at = lz * n + lx, i = z * r + x;
|
|
172
|
+
heights[i] = lattice.heights[at] ?? 0; colour.set(colours.subarray(at * 3, at * 3 + 3), i * 3);
|
|
173
|
+
}
|
|
174
|
+
const fresh = tileVertices({ ...shape, heights, colours: colour }, lattice);
|
|
175
|
+
const geometry = mesh.geometry, position = geometry.getAttribute('position'), normal = geometry.getAttribute('normal'), tint = geometry.getAttribute('color');
|
|
176
|
+
if (!(position instanceof BufferAttribute) || !(normal instanceof BufferAttribute) || !(tint instanceof BufferAttribute) || position.count !== fresh.vertices) return false;
|
|
177
|
+
position.array.set(fresh.positions); position.needsUpdate = true;
|
|
178
|
+
refillGpuOnly(normal, fresh.normals); refillGpuOnly(tint, fresh.colour);
|
|
179
|
+
geometry.computeBoundingBox(); geometry.computeBoundingSphere();
|
|
180
|
+
return true;
|
|
181
|
+
}
|
|
182
|
+
|
|
142
183
|
/**
|
|
143
184
|
* Hide a coarse tile's quadrants (0 = −x −z, 1 = +x −z, 2 = −x +z, 3 = +x +z) in place while fine tiles cover them.
|
|
144
185
|
* The tile's one index buffer is rewritten and its draw range shortened, so no allocation, no extra draw and no
|