minecraft-renderer 0.1.79 → 0.1.80
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/README.md +29 -25
- package/dist/mesher.js +36 -36
- package/dist/mesher.js.map +4 -4
- package/dist/mesherWasm.js +217 -217
- package/dist/minecraft-renderer.js +27 -27
- package/dist/minecraft-renderer.js.meta.json +1 -1
- package/dist/threeWorker.js +133 -133
- package/package.json +5 -2
- package/src/bundler/bundlePrepare.ts +3 -8
- package/src/graphicsBackend/appViewer.ts +10 -7
- package/src/graphicsBackend/config.ts +1 -5
- package/src/graphicsBackend/playerState.ts +35 -34
- package/src/graphicsBackend/preloadWorkers.ts +43 -41
- package/src/graphicsBackend/rendererDefaultOptions.ts +68 -70
- package/src/graphicsBackend/rendererOptionsSync.ts +24 -50
- package/src/graphicsBackend/types.ts +2 -2
- package/src/index.ts +6 -27
- package/src/lib/DebugGui.ts +34 -31
- package/src/lib/animationController.ts +9 -9
- package/src/lib/bakeLegacyLight.ts +1 -6
- package/src/lib/bindAbortableListener.test.ts +32 -12
- package/src/lib/bindAbortableListener.ts +14 -6
- package/src/lib/blockEntityLightRegistry.ts +11 -20
- package/src/lib/blockEntityLighting.test.ts +1 -6
- package/src/lib/blockEntityLighting.ts +5 -5
- package/src/lib/buildSharedConfig.mjs +4 -4
- package/src/lib/buildWorkerMcDataIndexes.test.ts +4 -4
- package/src/lib/buildWorkerMcDataIndexes.ts +11 -19
- package/src/lib/cameraBobbing.ts +1 -1
- package/src/lib/canvas2DOverlay.example.ts +13 -33
- package/src/lib/canvas2DOverlay.quickstart.ts +24 -54
- package/src/lib/canvas2DOverlay.ts +28 -47
- package/src/lib/cleanupDecorator.ts +2 -2
- package/src/lib/createPlayerObject.test.ts +2 -7
- package/src/lib/createPlayerObject.ts +18 -25
- package/src/lib/frameTimingCollector.ts +2 -5
- package/src/lib/guiRenderer.ts +57 -42
- package/src/lib/items.ts +15 -9
- package/src/lib/mesherlogReader.ts +5 -6
- package/src/lib/simpleUtils.ts +5 -5
- package/src/lib/skyLight.ts +3 -3
- package/src/lib/smoothSwitcher.ts +11 -18
- package/src/lib/ui/newStats.ts +10 -12
- package/src/lib/utils/proxy.ts +7 -1
- package/src/lib/utils/skins.ts +4 -4
- package/src/lib/utils.ts +1 -1
- package/src/lib/workerMessageSanitize.ts +5 -12
- package/src/lib/workerProxy.ts +52 -42
- package/src/lib/workerSyncOps.test.ts +58 -41
- package/src/lib/worldrendererCommon.reconfigure.test.ts +24 -21
- package/src/lib/worldrendererCommon.removeColumn.test.ts +11 -13
- package/src/lib/worldrendererCommon.ts +338 -211
- package/src/mesher-legacy/mesher.ts +9 -4
- package/src/mesher-legacy/test/a.ts +1 -1
- package/src/mesher-legacy/test/mesherTester.ts +2 -2
- package/src/mesher-legacy/test/playground.ts +1 -1
- package/src/mesher-legacy/test/run/test-js.ts +1 -1
- package/src/mesher-legacy/test/snapshotUtils.ts +3 -8
- package/src/mesher-legacy/test/test-perf.ts +1 -1
- package/src/mesher-legacy/test/tests.test.ts +2 -2
- package/src/mesher-shared/blockEntityMetadata.test.ts +7 -5
- package/src/mesher-shared/blockEntityMetadata.ts +28 -19
- package/src/mesher-shared/blockPropertiesForMeshing.ts +2 -2
- package/src/mesher-shared/computeHeightmap.ts +2 -4
- package/src/mesher-shared/exportedGeometryTypes.ts +3 -3
- package/src/mesher-shared/faceOcclusion.ts +324 -0
- package/src/mesher-shared/models.ts +80 -131
- package/src/mesher-shared/modelsGeometryCommon.ts +30 -15
- package/src/mesher-shared/shared.ts +46 -46
- package/src/mesher-shared/standaloneRenderer.ts +40 -44
- package/src/mesher-shared/tests/faceOcclusion.test.ts +179 -0
- package/src/mesher-shared/tests/liquidQuadInvariant.test.ts +12 -8
- package/src/mesher-shared/vertexShading.ts +2 -11
- package/src/mesher-shared/world.ts +19 -19
- package/src/mesher-shared/worldLighting.test.ts +2 -2
- package/src/performanceMonitor/PerformanceMonitor.ts +4 -13
- package/src/performanceMonitor/formatPerformanceFactorsDebug.ts +2 -2
- package/src/performanceMonitor/index.ts +1 -5
- package/src/performanceMonitor/types.ts +1 -1
- package/src/playerState/playerState.ts +55 -50
- package/src/playerState/types.ts +2 -8
- package/src/playground/allEntitiesDebug.ts +19 -16
- package/src/playground/baseScene.ts +29 -32
- package/src/playground/mobileControls.tsx +133 -129
- package/src/playground/playground.html +76 -73
- package/src/playground/playground.ts +14 -1
- package/src/playground/playgroundUi.tsx +100 -74
- package/src/playground/reactUtils.ts +3 -7
- package/src/playground/scenes/entities.ts +10 -7
- package/src/playground/scenes/frequentUpdates.ts +5 -5
- package/src/playground/scenes/geometryExport.ts +6 -20
- package/src/playground/scenes/highPosEntityUpdates.ts +2 -10
- package/src/playground/scenes/index.ts +1 -1
- package/src/playground/scenes/lightingStarfield.ts +18 -12
- package/src/playground/scenes/main.ts +15 -11
- package/src/playground/scenes/partialBlockCulling.ts +31 -0
- package/src/playground/scenes/railsCobweb.ts +1 -1
- package/src/playground/scenes/rotationIssue.ts +1 -1
- package/src/playground/scenes/slabsOptimization.ts +1 -2
- package/src/playground/scenes/transparencyIssue.ts +1 -1
- package/src/playground/shared.ts +2 -2
- package/src/resourcesManager/resourcesManager.ts +29 -54
- package/src/resourcesManager/resourcesManager.worker.test.ts +6 -10
- package/src/shims/minecraftData.ts +70 -24
- package/src/sign-renderer/index.html +10 -12
- package/src/sign-renderer/index.ts +29 -29
- package/src/sign-renderer/playground.ts +22 -15
- package/src/sign-renderer/tests.test.ts +16 -13
- package/src/sign-renderer/vite.config.ts +2 -2
- package/src/three/appShared.ts +46 -25
- package/src/three/bannerRenderer.ts +33 -61
- package/src/three/cameraShake.ts +15 -6
- package/src/three/chunkMeshManager.ts +239 -282
- package/src/three/cinimaticScript.ts +26 -15
- package/src/three/cubeDrawSpans.ts +27 -37
- package/src/three/cubeMultiDraw.ts +9 -22
- package/src/three/documentRenderer.ts +15 -18
- package/src/three/entities.ts +175 -150
- package/src/three/entity/EntityMesh.ts +114 -108
- package/src/three/entity/animations.js +3 -3
- package/src/three/entity/armorModels.ts +15 -15
- package/src/three/entity/gltfAnimationUtils.ts +2 -5
- package/src/three/fireworks.ts +34 -32
- package/src/three/fireworksRenderer.ts +32 -29
- package/src/three/globalBlockBuffer.ts +167 -100
- package/src/three/globalLegacyBuffer.ts +257 -166
- package/src/three/graphicsBackendBase.ts +19 -25
- package/src/three/graphicsBackendOffThread.ts +12 -15
- package/src/three/hand.ts +21 -21
- package/src/three/handLegacy.ts +3 -13
- package/src/three/holdingBlock.ts +116 -79
- package/src/three/holdingBlockFactory.ts +1 -4
- package/src/three/holdingBlockItemIdentity.test.ts +25 -17
- package/src/three/holdingBlockItemIdentity.ts +9 -6
- package/src/three/holdingBlockLegacy.ts +113 -132
- package/src/three/itemMesh.ts +20 -29
- package/src/three/legacyMultiDraw.ts +10 -16
- package/src/three/legacySectionCull.ts +8 -14
- package/src/three/menuBackground/activeView.ts +1 -4
- package/src/three/menuBackground/assetUrl.ts +1 -1
- package/src/three/menuBackground/classic.ts +4 -12
- package/src/three/menuBackground/gpuPreference.ts +1 -3
- package/src/three/menuBackground/index.ts +2 -11
- package/src/three/menuBackground/renderer.ts +1 -5
- package/src/three/menuBackground/types.ts +1 -4
- package/src/three/menuBackground/v2.ts +196 -96
- package/src/three/menuBackground/v2Meta.ts +3 -3
- package/src/three/menuBackground/worldBlocks.ts +37 -35
- package/src/three/modules/blockBreakParticles.ts +59 -28
- package/src/three/modules/cameraBobbing.ts +3 -6
- package/src/three/modules/index.ts +1 -1
- package/src/three/modules/rain.ts +10 -23
- package/src/three/modules/sciFiWorldReveal.ts +11 -25
- package/src/three/modules/starfield.ts +7 -13
- package/src/three/renderSlot.ts +28 -16
- package/src/three/rendererModuleSystem.ts +1 -3
- package/src/three/sceneOrigin.ts +96 -33
- package/src/three/sectionRaycastAabb.ts +30 -18
- package/src/three/shaderCubeMesh.ts +6 -17
- package/src/three/shaders/cubeBlockShader.ts +85 -96
- package/src/three/shaders/legacyBlockShader.ts +21 -43
- package/src/three/shaders/textureIndexMapping.ts +89 -95
- package/src/three/shaders/tintPalette.ts +156 -170
- package/src/three/signTextureCache.ts +9 -12
- package/src/three/skyboxRenderer.ts +62 -70
- package/src/three/tests/chunkMeshManagerLegacy.test.ts +34 -34
- package/src/three/tests/cubeDrawSpans.test.ts +55 -25
- package/src/three/tests/globalBlockBuffer.test.ts +217 -0
- package/src/three/tests/globalLegacyBuffer.test.ts +300 -41
- package/src/three/tests/legacyMultiDraw.test.ts +8 -29
- package/src/three/tests/pr3PerFrameCpuCuts.test.ts +106 -29
- package/src/three/tests/signTextureCache.test.ts +4 -4
- package/src/three/threeJsMedia.ts +55 -72
- package/src/three/threeJsParticles.ts +32 -41
- package/src/three/threeJsSound.ts +3 -3
- package/src/three/threeJsUtils.ts +3 -3
- package/src/three/threeWorker.ts +2 -2
- package/src/three/waypointSprite.ts +55 -82
- package/src/three/waypoints.ts +20 -23
- package/src/three/world/cursorBlock.ts +25 -12
- package/src/three/world/vr.ts +11 -17
- package/src/three/worldGeometryExport.ts +15 -34
- package/src/three/worldRendererThree.ts +117 -129
- package/src/wasm-mesher/bridge/convertChunk.ts +3 -9
- package/src/wasm-mesher/bridge/render-from-wasm.ts +204 -229
- package/src/wasm-mesher/bridge/shaderCubeBridge.ts +26 -67
- package/src/wasm-mesher/tests/cullingRegression.test.ts +307 -0
- package/src/wasm-mesher/tests/heightmapParity.test.ts +8 -18
- package/src/wasm-mesher/tests/mesherWasmConversionCache.test.ts +2 -2
- package/src/wasm-mesher/tests/sectionRaycastAabb.test.ts +17 -4
- package/src/wasm-mesher/tests/shaderCubeInstances.test.ts +103 -141
- package/src/wasm-mesher/tests/splitColumnWasmOutput.test.ts +14 -22
- package/src/wasm-mesher/worker/mesherWasm.ts +150 -141
- package/src/wasm-mesher/worker/mesherWasmConversionCache.ts +2 -8
- package/src/wasm-mesher/worker/mesherWasmLightDirty.test.ts +1 -3
- package/src/wasm-mesher/worker/mesherWasmLightDirty.ts +1 -5
- package/src/wasm-mesher/worker/mesherWasmRequestTracker.ts +42 -42
- package/src/worldView/worldView.spiral.test.ts +1 -1
- package/src/worldView/worldView.ts +34 -39
- package/src/worldView/worldViewWorkerBridge.test.ts +4 -4
|
@@ -26,23 +26,25 @@ export interface RendererOptionsSubscribeHooks {
|
|
|
26
26
|
isSafari?: boolean
|
|
27
27
|
isCypress?: boolean
|
|
28
28
|
getWindowFocused?: () => boolean
|
|
29
|
-
onRegisterFocusHandlers?: (handlers: { onFocus: () => void
|
|
29
|
+
onRegisterFocusHandlers?: (handlers: { onFocus: () => void; onBlur: () => void }) => void
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
export interface RendererWorldViewLike {
|
|
33
33
|
keepChunksDistance: number
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
export function menuBackgroundOptionsFromStorage(
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
36
|
+
export function menuBackgroundOptionsFromStorage(
|
|
37
|
+
o: Pick<
|
|
38
|
+
RendererStorageOptions,
|
|
39
|
+
| 'menuBackgroundMode'
|
|
40
|
+
| 'menuBackgroundMinecraftTextures'
|
|
41
|
+
| 'menuBackgroundV2Scene'
|
|
42
|
+
| 'menuBackgroundV2Camera'
|
|
43
|
+
| 'menuBackgroundV2BlockGroup'
|
|
44
|
+
| 'menuBackgroundV2CameraSpeed'
|
|
45
|
+
| 'menuBackgroundV2BlockSpeed'
|
|
46
|
+
>
|
|
47
|
+
): MenuBackgroundOptions {
|
|
46
48
|
return {
|
|
47
49
|
mode: o.menuBackgroundMode as MenuBackgroundOptions['mode'],
|
|
48
50
|
useMinecraftTextures: o.menuBackgroundMinecraftTextures,
|
|
@@ -50,7 +52,7 @@ export function menuBackgroundOptionsFromStorage(o: Pick<
|
|
|
50
52
|
v2Camera: o.menuBackgroundV2Camera as V2CameraId,
|
|
51
53
|
v2BlockGroup: o.menuBackgroundV2BlockGroup as MinecraftBlockGroupId,
|
|
52
54
|
v2CameraSpeed: menuBackgroundSpeedToMultiplier(o.menuBackgroundV2CameraSpeed),
|
|
53
|
-
v2BlockSpeed: menuBackgroundSpeedToMultiplier(o.menuBackgroundV2BlockSpeed)
|
|
55
|
+
v2BlockSpeed: menuBackgroundSpeedToMultiplier(o.menuBackgroundV2BlockSpeed)
|
|
54
56
|
}
|
|
55
57
|
}
|
|
56
58
|
|
|
@@ -58,11 +60,7 @@ export function applyMenuBackgroundLiveOptions(
|
|
|
58
60
|
menu: MenuBackgroundRenderer,
|
|
59
61
|
o: Pick<
|
|
60
62
|
RendererStorageOptions,
|
|
61
|
-
| '
|
|
62
|
-
| 'menuBackgroundV2Camera'
|
|
63
|
-
| 'menuBackgroundV2BlockGroup'
|
|
64
|
-
| 'menuBackgroundV2CameraSpeed'
|
|
65
|
-
| 'menuBackgroundV2BlockSpeed'
|
|
63
|
+
'menuBackgroundV2Scene' | 'menuBackgroundV2Camera' | 'menuBackgroundV2BlockGroup' | 'menuBackgroundV2CameraSpeed' | 'menuBackgroundV2BlockSpeed'
|
|
66
64
|
>
|
|
67
65
|
): void {
|
|
68
66
|
const v2 = menu.v2
|
|
@@ -78,11 +76,7 @@ function resolveWasmMesherActive(o: RendererStorageOptions): boolean {
|
|
|
78
76
|
return o.rendererMesher !== 'legacy-js'
|
|
79
77
|
}
|
|
80
78
|
|
|
81
|
-
function applyMesherWorkersPreset(
|
|
82
|
-
appViewer: AppViewer,
|
|
83
|
-
o: RendererStorageOptions,
|
|
84
|
-
wasmActive: boolean
|
|
85
|
-
): void {
|
|
79
|
+
function applyMesherWorkersPreset(appViewer: AppViewer, o: RendererStorageOptions, wasmActive: boolean): void {
|
|
86
80
|
const cfg = appViewer.inWorldRenderingConfig
|
|
87
81
|
const override = o.rendererMeshersCountOverride
|
|
88
82
|
const applyMesherWorkers = (workers: number) => {
|
|
@@ -104,11 +98,7 @@ function applyMesherWorkersPreset(
|
|
|
104
98
|
}
|
|
105
99
|
}
|
|
106
100
|
|
|
107
|
-
function applyFpsLimit(
|
|
108
|
-
appViewer: AppViewer,
|
|
109
|
-
o: RendererStorageOptions,
|
|
110
|
-
windowFocused: boolean
|
|
111
|
-
): void {
|
|
101
|
+
function applyFpsLimit(appViewer: AppViewer, o: RendererStorageOptions, windowFocused: boolean): void {
|
|
112
102
|
const backgroundFpsLimit = o.backgroundRendering
|
|
113
103
|
const normalFpsLimit = o.frameLimit
|
|
114
104
|
|
|
@@ -123,11 +113,7 @@ function applyFpsLimit(
|
|
|
123
113
|
}
|
|
124
114
|
}
|
|
125
115
|
|
|
126
|
-
function applyStatsVisible(
|
|
127
|
-
appViewer: AppViewer,
|
|
128
|
-
o: RendererStorageOptions,
|
|
129
|
-
ctx: ApplyRendererOptionsContext
|
|
130
|
-
): void {
|
|
116
|
+
function applyStatsVisible(appViewer: AppViewer, o: RendererStorageOptions, ctx: ApplyRendererOptionsContext): void {
|
|
131
117
|
const { renderDebug } = o
|
|
132
118
|
if (renderDebug === 'none' || ctx.isCypress) {
|
|
133
119
|
appViewer.config.statsVisible = 0
|
|
@@ -139,11 +125,7 @@ function applyStatsVisible(
|
|
|
139
125
|
}
|
|
140
126
|
|
|
141
127
|
// ensure no object assigns to the config
|
|
142
|
-
export function applyRendererOptions(
|
|
143
|
-
appViewer: AppViewer,
|
|
144
|
-
o: RendererStorageOptions,
|
|
145
|
-
ctx: ApplyRendererOptionsContext = {}
|
|
146
|
-
): void {
|
|
128
|
+
export function applyRendererOptions(appViewer: AppViewer, o: RendererStorageOptions, ctx: ApplyRendererOptionsContext = {}): void {
|
|
147
129
|
const cfg = appViewer.inWorldRenderingConfig
|
|
148
130
|
const wasmActive = resolveWasmMesherActive(o)
|
|
149
131
|
|
|
@@ -180,10 +162,7 @@ export function applyRendererOptions(
|
|
|
180
162
|
export function applyRendererWorldViewOptions(
|
|
181
163
|
appViewer: AppViewer,
|
|
182
164
|
worldView: RendererWorldViewLike,
|
|
183
|
-
o: Pick<
|
|
184
|
-
RendererStorageOptions,
|
|
185
|
-
'keepChunksDistance' | 'renderEars' | 'showHand' | 'viewBobbing' | 'dayCycleAndLighting'
|
|
186
|
-
>
|
|
165
|
+
o: Pick<RendererStorageOptions, 'keepChunksDistance' | 'renderEars' | 'showHand' | 'viewBobbing' | 'dayCycleAndLighting'>
|
|
187
166
|
): void {
|
|
188
167
|
worldView.keepChunksDistance = o.keepChunksDistance
|
|
189
168
|
const cfg = appViewer.inWorldRenderingConfig
|
|
@@ -211,7 +190,7 @@ export function subscribeRendererOptions<T extends RendererStorageOptions>(
|
|
|
211
190
|
applyRendererOptions(appViewer, snapshot, {
|
|
212
191
|
isSafari: hooks.isSafari,
|
|
213
192
|
isCypress: hooks.isCypress,
|
|
214
|
-
windowFocused
|
|
193
|
+
windowFocused
|
|
215
194
|
})
|
|
216
195
|
|
|
217
196
|
if (appViewer.currentDisplay === 'menu') {
|
|
@@ -230,18 +209,13 @@ export function subscribeRendererOptions<T extends RendererStorageOptions>(
|
|
|
230
209
|
onBlur: () => {
|
|
231
210
|
windowFocused = false
|
|
232
211
|
run()
|
|
233
|
-
}
|
|
212
|
+
}
|
|
234
213
|
})
|
|
235
214
|
|
|
236
215
|
return subscribe(optionsProxy, run)
|
|
237
216
|
}
|
|
238
217
|
|
|
239
218
|
/** Call when mineflayer bot is created (lighting depends on protocol features). */
|
|
240
|
-
export function applyRendererEnableLighting(
|
|
241
|
-
appViewer
|
|
242
|
-
newVersionsLighting: boolean,
|
|
243
|
-
blockStateIdSupported: boolean
|
|
244
|
-
): void {
|
|
245
|
-
appViewer.inWorldRenderingConfig.enableLighting =
|
|
246
|
-
!blockStateIdSupported || newVersionsLighting
|
|
219
|
+
export function applyRendererEnableLighting(appViewer: AppViewer, newVersionsLighting: boolean, blockStateIdSupported: boolean): void {
|
|
220
|
+
appViewer.inWorldRenderingConfig.enableLighting = !blockStateIdSupported || newVersionsLighting
|
|
247
221
|
}
|
|
@@ -18,7 +18,7 @@ import { WorldRendererConfig } from './config'
|
|
|
18
18
|
export type MaybePromise<T> = Promise<T> | T
|
|
19
19
|
|
|
20
20
|
export interface SoundSystem {
|
|
21
|
-
playSound: (position: { x: number
|
|
21
|
+
playSound: (position: { x: number; y: number; z: number }, path: string, volume?: number, pitch?: number, timeout?: number) => void
|
|
22
22
|
destroy: () => void
|
|
23
23
|
}
|
|
24
24
|
|
|
@@ -131,7 +131,7 @@ export interface GraphicsBackend {
|
|
|
131
131
|
updateCamera(pos: Vec3 | null, yaw: number, pitch: number): void
|
|
132
132
|
soundSystem?: any
|
|
133
133
|
backendMethods?: any
|
|
134
|
-
getDebugOverlay?(): { entitiesString?: string
|
|
134
|
+
getDebugOverlay?(): { entitiesString?: string; left?: Record<string, string>; right?: Record<string, string> }
|
|
135
135
|
/** Active main-menu background, when `currentDisplay === 'menu'`. */
|
|
136
136
|
getMenuBackground?(): MenuBackgroundRenderer | undefined
|
|
137
137
|
}
|
package/src/index.ts
CHANGED
|
@@ -37,47 +37,26 @@ export * from './graphicsBackend'
|
|
|
37
37
|
// ============================================================================
|
|
38
38
|
// World View
|
|
39
39
|
// ============================================================================
|
|
40
|
-
export {
|
|
41
|
-
WorldView,
|
|
42
|
-
WorldViewWorker,
|
|
43
|
-
chunkPos,
|
|
44
|
-
sectionPos,
|
|
45
|
-
delayedIterator
|
|
46
|
-
} from './worldView'
|
|
40
|
+
export { WorldView, WorldViewWorker, chunkPos, sectionPos, delayedIterator } from './worldView'
|
|
47
41
|
export type { WorldProvider } from './worldView'
|
|
48
42
|
|
|
49
43
|
// ============================================================================
|
|
50
44
|
// Player State
|
|
51
45
|
// ============================================================================
|
|
52
|
-
export {
|
|
53
|
-
getInitialPlayerState,
|
|
54
|
-
getPlayerStateUtils,
|
|
55
|
-
getInitialPlayerStateRenderer
|
|
56
|
-
} from './playerState/playerState'
|
|
46
|
+
export { getInitialPlayerState, getPlayerStateUtils, getInitialPlayerStateRenderer } from './playerState/playerState'
|
|
57
47
|
|
|
58
48
|
// ============================================================================
|
|
59
49
|
// Resource Manager
|
|
60
50
|
// ============================================================================
|
|
61
|
-
export {
|
|
62
|
-
ResourcesManager,
|
|
63
|
-
LoadedResourcesTransferrable
|
|
64
|
-
} from './resourcesManager'
|
|
51
|
+
export { ResourcesManager, LoadedResourcesTransferrable } from './resourcesManager'
|
|
65
52
|
|
|
66
53
|
// ============================================================================
|
|
67
54
|
// Three.js Backend (re-exported for convenience)
|
|
68
55
|
// ============================================================================
|
|
69
|
-
export {
|
|
70
|
-
|
|
71
|
-
} from './three/graphicsBackendSingleThread'
|
|
72
|
-
export {
|
|
73
|
-
createGraphicsBackendOffThread
|
|
74
|
-
} from './three/graphicsBackendOffThread'
|
|
56
|
+
export { createGraphicsBackendSingleThread } from './three/graphicsBackendSingleThread'
|
|
57
|
+
export { createGraphicsBackendOffThread } from './three/graphicsBackendOffThread'
|
|
75
58
|
|
|
76
|
-
export {
|
|
77
|
-
DocumentRenderer,
|
|
78
|
-
addCanvasForWorker,
|
|
79
|
-
isWebWorker
|
|
80
|
-
} from './three/documentRenderer'
|
|
59
|
+
export { DocumentRenderer, addCanvasForWorker, isWebWorker } from './three/documentRenderer'
|
|
81
60
|
export { MC_RENDERER_DEBUG_OVERLAY_CLASS } from './lib/ui/newStats'
|
|
82
61
|
|
|
83
62
|
// Main-menu background (title screen backdrop)
|
package/src/lib/DebugGui.ts
CHANGED
|
@@ -19,7 +19,7 @@ export class DebugGui {
|
|
|
19
19
|
private readonly initialValues: Record<string, any> = {} // Store initial values
|
|
20
20
|
private initialized = false
|
|
21
21
|
|
|
22
|
-
constructor
|
|
22
|
+
constructor(id: string, target: any, params?: string[], paramsMeta?: Record<string, ParamMeta>) {
|
|
23
23
|
// If in web worker, don't initialize anything
|
|
24
24
|
if (isWebWorker) return
|
|
25
25
|
|
|
@@ -39,7 +39,7 @@ export class DebugGui {
|
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
// Initialize and show the GUI
|
|
42
|
-
activate
|
|
42
|
+
activate() {
|
|
43
43
|
if (isWebWorker) return this
|
|
44
44
|
|
|
45
45
|
if (!this.initialized && this.gui) {
|
|
@@ -52,20 +52,20 @@ export class DebugGui {
|
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
// Getter for visibility
|
|
55
|
-
get visible
|
|
55
|
+
get visible(): boolean {
|
|
56
56
|
if (isWebWorker) return false
|
|
57
57
|
return this._visible
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
// Setter for visibility
|
|
61
|
-
set visible
|
|
61
|
+
set visible(value: boolean) {
|
|
62
62
|
if (isWebWorker || !this.gui) return
|
|
63
63
|
this._visible = value
|
|
64
64
|
this.gui.domElement.style.display = value ? 'block' : 'none'
|
|
65
65
|
this.saveVisibility()
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
private loadSavedValues
|
|
68
|
+
private loadSavedValues() {
|
|
69
69
|
if (isWebWorker) return
|
|
70
70
|
try {
|
|
71
71
|
const saved = localStorage.getItem(this.storageKey)
|
|
@@ -86,7 +86,7 @@ export class DebugGui {
|
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
private saveValues
|
|
89
|
+
private saveValues(deleteKey = false) {
|
|
90
90
|
if (isWebWorker) return
|
|
91
91
|
try {
|
|
92
92
|
const values = {}
|
|
@@ -103,7 +103,7 @@ export class DebugGui {
|
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
-
private saveVisibility
|
|
106
|
+
private saveVisibility() {
|
|
107
107
|
if (isWebWorker) return
|
|
108
108
|
try {
|
|
109
109
|
localStorage.setItem(`${this.storageKey}_visible`, this._visible.toString())
|
|
@@ -112,21 +112,28 @@ export class DebugGui {
|
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
-
private setupControls
|
|
115
|
+
private setupControls() {
|
|
116
116
|
if (isWebWorker || !this.gui) return
|
|
117
117
|
|
|
118
118
|
// Add visibility toggle at the top
|
|
119
119
|
this.gui.add(this, 'visible').name('Show Controls')
|
|
120
|
-
this.gui
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
120
|
+
this.gui
|
|
121
|
+
.add(
|
|
122
|
+
{
|
|
123
|
+
resetAll: () => {
|
|
124
|
+
if (!this.gui) return
|
|
125
|
+
for (const param of this.params) {
|
|
126
|
+
this.target[param] = this.initialValues[param]
|
|
127
|
+
}
|
|
128
|
+
this.saveValues(true)
|
|
129
|
+
this.gui.destroy()
|
|
130
|
+
this.gui = new GUI()
|
|
131
|
+
this.setupControls()
|
|
132
|
+
}
|
|
133
|
+
},
|
|
134
|
+
'resetAll'
|
|
135
|
+
)
|
|
136
|
+
.name('Reset All Parameters')
|
|
130
137
|
|
|
131
138
|
for (const param of this.params) {
|
|
132
139
|
const value = this.target[param]
|
|
@@ -138,54 +145,50 @@ export class DebugGui {
|
|
|
138
145
|
const max = meta.max ?? value + Math.abs(value * 2)
|
|
139
146
|
const step = meta.step ?? Math.abs(value) / 100
|
|
140
147
|
|
|
141
|
-
this.gui.add(this.target, param, min, max, step)
|
|
142
|
-
.onChange(() => this.saveValues())
|
|
148
|
+
this.gui.add(this.target, param, min, max, step).onChange(() => this.saveValues())
|
|
143
149
|
} else if (typeof value === 'boolean') {
|
|
144
150
|
// For booleans, create a checkbox
|
|
145
|
-
this.gui.add(this.target, param)
|
|
146
|
-
.onChange(() => this.saveValues())
|
|
151
|
+
this.gui.add(this.target, param).onChange(() => this.saveValues())
|
|
147
152
|
} else if (typeof value === 'string' && ['x', 'y', 'z'].includes(param)) {
|
|
148
153
|
// Special case for xyz coordinates
|
|
149
154
|
const min = meta.min ?? -10
|
|
150
155
|
const max = meta.max ?? 10
|
|
151
156
|
const step = meta.step ?? 0.1
|
|
152
157
|
|
|
153
|
-
this.gui.add(this.target, param, min, max, step)
|
|
154
|
-
.onChange(() => this.saveValues())
|
|
158
|
+
this.gui.add(this.target, param, min, max, step).onChange(() => this.saveValues())
|
|
155
159
|
} else if (Array.isArray(value)) {
|
|
156
160
|
// For arrays, create a dropdown
|
|
157
|
-
this.gui.add(this.target, param, value)
|
|
158
|
-
.onChange(() => this.saveValues())
|
|
161
|
+
this.gui.add(this.target, param, value).onChange(() => this.saveValues())
|
|
159
162
|
}
|
|
160
163
|
}
|
|
161
164
|
}
|
|
162
165
|
|
|
163
166
|
// Method to manually trigger save
|
|
164
|
-
save
|
|
167
|
+
save() {
|
|
165
168
|
if (isWebWorker) return
|
|
166
169
|
this.saveValues()
|
|
167
170
|
this.saveVisibility()
|
|
168
171
|
}
|
|
169
172
|
|
|
170
173
|
// Method to destroy the GUI and clean up
|
|
171
|
-
destroy
|
|
174
|
+
destroy() {
|
|
172
175
|
if (isWebWorker || !this.gui) return
|
|
173
176
|
this.saveVisibility()
|
|
174
177
|
this.gui.destroy()
|
|
175
178
|
}
|
|
176
179
|
|
|
177
180
|
// Toggle visibility
|
|
178
|
-
toggle
|
|
181
|
+
toggle() {
|
|
179
182
|
this.visible = !this.visible
|
|
180
183
|
}
|
|
181
184
|
|
|
182
185
|
// Show the GUI
|
|
183
|
-
show
|
|
186
|
+
show() {
|
|
184
187
|
this.visible = true
|
|
185
188
|
}
|
|
186
189
|
|
|
187
190
|
// Hide the GUI
|
|
188
|
-
hide
|
|
191
|
+
hide() {
|
|
189
192
|
this.visible = false
|
|
190
193
|
}
|
|
191
194
|
}
|
|
@@ -9,12 +9,12 @@ export class AnimationController {
|
|
|
9
9
|
private currentCancelCallback: (() => void) | null = null
|
|
10
10
|
|
|
11
11
|
/** Main method */
|
|
12
|
-
async startAnimation
|
|
12
|
+
async startAnimation(createAnimation: () => tweenJs.Group, onCancelled?: () => void): Promise<void> {
|
|
13
13
|
if (this.isAnimating) {
|
|
14
14
|
await this.cancelCurrentAnimation()
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
return new Promise(
|
|
17
|
+
return new Promise(resolve => {
|
|
18
18
|
this.isAnimating = true
|
|
19
19
|
this.cancelRequested = false
|
|
20
20
|
this.currentCancelCallback = onCancelled ?? null
|
|
@@ -29,7 +29,7 @@ export class AnimationController {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
/** Main method */
|
|
32
|
-
async cancelCurrentAnimation
|
|
32
|
+
async cancelCurrentAnimation(): Promise<void> {
|
|
33
33
|
if (!this.isAnimating) return
|
|
34
34
|
|
|
35
35
|
if (this.currentCancelCallback) {
|
|
@@ -38,7 +38,7 @@ export class AnimationController {
|
|
|
38
38
|
callback()
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
return new Promise(
|
|
41
|
+
return new Promise(resolve => {
|
|
42
42
|
this.cancelRequested = true
|
|
43
43
|
this.completionCallbacks.push(() => {
|
|
44
44
|
resolve()
|
|
@@ -46,11 +46,11 @@ export class AnimationController {
|
|
|
46
46
|
})
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
animationCycleFinish
|
|
49
|
+
animationCycleFinish() {
|
|
50
50
|
if (this.cancelRequested) this.forceFinish()
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
forceFinish
|
|
53
|
+
forceFinish(callComplete = true) {
|
|
54
54
|
if (!this.isAnimating) return
|
|
55
55
|
|
|
56
56
|
if (this.currentAnimation) {
|
|
@@ -70,17 +70,17 @@ export class AnimationController {
|
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
/** Required method */
|
|
73
|
-
update
|
|
73
|
+
update() {
|
|
74
74
|
if (this.currentAnimation) {
|
|
75
75
|
this.currentAnimation.update()
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
get isActive
|
|
79
|
+
get isActive() {
|
|
80
80
|
return this.isAnimating
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
get shouldCancel
|
|
83
|
+
get shouldCancel() {
|
|
84
84
|
return this.cancelRequested
|
|
85
85
|
}
|
|
86
86
|
}
|
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
//@ts-nocheck
|
|
2
2
|
/** Bake tint×AO colors with sky/block channels for static export (no live u_skyLevel uniform). */
|
|
3
|
-
export function bakeLegacyVertexColors
|
|
4
|
-
colors: ArrayLike<number>,
|
|
5
|
-
skyLights: ArrayLike<number>,
|
|
6
|
-
blockLights: ArrayLike<number>,
|
|
7
|
-
skyLevel: number,
|
|
8
|
-
): number[] {
|
|
3
|
+
export function bakeLegacyVertexColors(colors: ArrayLike<number>, skyLights: ArrayLike<number>, blockLights: ArrayLike<number>, skyLevel: number): number[] {
|
|
9
4
|
const vertCount = colors.length / 3
|
|
10
5
|
const out: number[] = []
|
|
11
6
|
for (let v = 0; v < vertCount; v++) {
|
|
@@ -9,9 +9,14 @@ describe('bindAbortableListener', () => {
|
|
|
9
9
|
const emitter = new WorldViewWorker()
|
|
10
10
|
const controller = new AbortController()
|
|
11
11
|
let calls = 0
|
|
12
|
-
bindAbortableListener(
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
bindAbortableListener(
|
|
13
|
+
emitter,
|
|
14
|
+
'renderDistance',
|
|
15
|
+
() => {
|
|
16
|
+
calls++
|
|
17
|
+
},
|
|
18
|
+
controller.signal
|
|
19
|
+
)
|
|
15
20
|
|
|
16
21
|
emitter.emit('renderDistance', 8)
|
|
17
22
|
expect(calls).toBe(1)
|
|
@@ -28,12 +33,22 @@ describe('bindAbortableListener', () => {
|
|
|
28
33
|
let callsA = 0
|
|
29
34
|
let callsB = 0
|
|
30
35
|
|
|
31
|
-
bindAbortableListener(
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
36
|
+
bindAbortableListener(
|
|
37
|
+
emitter,
|
|
38
|
+
'renderDistance',
|
|
39
|
+
() => {
|
|
40
|
+
callsA++
|
|
41
|
+
},
|
|
42
|
+
controllerA.signal
|
|
43
|
+
)
|
|
44
|
+
bindAbortableListener(
|
|
45
|
+
emitter,
|
|
46
|
+
'renderDistance',
|
|
47
|
+
() => {
|
|
48
|
+
callsB++
|
|
49
|
+
},
|
|
50
|
+
controllerB.signal
|
|
51
|
+
)
|
|
37
52
|
|
|
38
53
|
emitter.emit('renderDistance', 4)
|
|
39
54
|
expect(callsA).toBe(1)
|
|
@@ -51,9 +66,14 @@ describe('bindAbortableEmitterListener', () => {
|
|
|
51
66
|
const emitter = new EventEmitter()
|
|
52
67
|
const controller = new AbortController()
|
|
53
68
|
let calls = 0
|
|
54
|
-
bindAbortableEmitterListener(
|
|
55
|
-
|
|
56
|
-
|
|
69
|
+
bindAbortableEmitterListener(
|
|
70
|
+
emitter,
|
|
71
|
+
'test',
|
|
72
|
+
() => {
|
|
73
|
+
calls++
|
|
74
|
+
},
|
|
75
|
+
controller.signal
|
|
76
|
+
)
|
|
57
77
|
|
|
58
78
|
emitter.emit('test')
|
|
59
79
|
expect(calls).toBe(1)
|
|
@@ -18,9 +18,13 @@ export function bindAbortableListener<E extends keyof WorldViewEvents>(
|
|
|
18
18
|
emitter.off(event, handler as (...args: any[]) => void)
|
|
19
19
|
return
|
|
20
20
|
}
|
|
21
|
-
signal.addEventListener(
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
signal.addEventListener(
|
|
22
|
+
'abort',
|
|
23
|
+
() => {
|
|
24
|
+
emitter.off(event, handler as (...args: any[]) => void)
|
|
25
|
+
},
|
|
26
|
+
{ once: true }
|
|
27
|
+
)
|
|
24
28
|
}
|
|
25
29
|
|
|
26
30
|
/** Same pattern for plain EventEmitters (e.g. resourcesManager). */
|
|
@@ -35,7 +39,11 @@ export function bindAbortableEmitterListener(
|
|
|
35
39
|
emitter.off(event, handler)
|
|
36
40
|
return
|
|
37
41
|
}
|
|
38
|
-
signal.addEventListener(
|
|
39
|
-
|
|
40
|
-
|
|
42
|
+
signal.addEventListener(
|
|
43
|
+
'abort',
|
|
44
|
+
() => {
|
|
45
|
+
emitter.off(event, handler)
|
|
46
|
+
},
|
|
47
|
+
{ once: true }
|
|
48
|
+
)
|
|
41
49
|
}
|
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
//@ts-nocheck
|
|
2
2
|
import * as THREE from 'three'
|
|
3
|
-
import {
|
|
4
|
-
blockEntityBrightness,
|
|
5
|
-
DEFAULT_LIGHTMAP_PARAMS,
|
|
6
|
-
type BlockLightmapParams,
|
|
7
|
-
} from './blockEntityLighting'
|
|
3
|
+
import { blockEntityBrightness, DEFAULT_LIGHTMAP_PARAMS, type BlockLightmapParams } from './blockEntityLighting'
|
|
8
4
|
|
|
9
5
|
export type BlockEntityOverlayLight = {
|
|
10
6
|
material: THREE.MeshBasicMaterial
|
|
@@ -17,12 +13,12 @@ export class BlockEntityLightRegistry {
|
|
|
17
13
|
private skyLevel = 1
|
|
18
14
|
private lightmapParams: BlockLightmapParams = { ...DEFAULT_LIGHTMAP_PARAMS }
|
|
19
15
|
|
|
20
|
-
register
|
|
16
|
+
register(entry: BlockEntityOverlayLight): void {
|
|
21
17
|
this.entries.add(entry)
|
|
22
18
|
this.applyBrightness(entry)
|
|
23
19
|
}
|
|
24
20
|
|
|
25
|
-
unregister
|
|
21
|
+
unregister(material: THREE.Material): void {
|
|
26
22
|
for (const entry of this.entries) {
|
|
27
23
|
if (entry.material === material) {
|
|
28
24
|
this.entries.delete(entry)
|
|
@@ -31,43 +27,38 @@ export class BlockEntityLightRegistry {
|
|
|
31
27
|
}
|
|
32
28
|
}
|
|
33
29
|
|
|
34
|
-
setSkyLevel
|
|
30
|
+
setSkyLevel(value: number): void {
|
|
35
31
|
this.skyLevel = value
|
|
36
32
|
this.refreshAll()
|
|
37
33
|
}
|
|
38
34
|
|
|
39
|
-
setLightmapParams
|
|
35
|
+
setLightmapParams(params: BlockLightmapParams): void {
|
|
40
36
|
this.lightmapParams = { ...this.lightmapParams, ...params }
|
|
41
37
|
this.refreshAll()
|
|
42
38
|
}
|
|
43
39
|
|
|
44
|
-
getSkyLevel
|
|
40
|
+
getSkyLevel(): number {
|
|
45
41
|
return this.skyLevel
|
|
46
42
|
}
|
|
47
43
|
|
|
48
|
-
private refreshAll
|
|
44
|
+
private refreshAll(): void {
|
|
49
45
|
for (const entry of this.entries) {
|
|
50
46
|
this.applyBrightness(entry)
|
|
51
47
|
}
|
|
52
48
|
}
|
|
53
49
|
|
|
54
|
-
private applyBrightness
|
|
55
|
-
const brightness = blockEntityBrightness(
|
|
56
|
-
entry.blockLightNorm,
|
|
57
|
-
entry.skyLightNorm,
|
|
58
|
-
this.skyLevel,
|
|
59
|
-
this.lightmapParams,
|
|
60
|
-
)
|
|
50
|
+
private applyBrightness(entry: BlockEntityOverlayLight): void {
|
|
51
|
+
const brightness = blockEntityBrightness(entry.blockLightNorm, entry.skyLightNorm, this.skyLevel, this.lightmapParams)
|
|
61
52
|
entry.material.color.setScalar(brightness)
|
|
62
53
|
}
|
|
63
54
|
}
|
|
64
55
|
|
|
65
|
-
export function tintBannerMaterial
|
|
56
|
+
export function tintBannerMaterial(
|
|
66
57
|
material: THREE.MeshBasicMaterial,
|
|
67
58
|
blockLightNorm: number,
|
|
68
59
|
skyLightNorm: number,
|
|
69
60
|
skyLevel: number,
|
|
70
|
-
lightmapParams: BlockLightmapParams = DEFAULT_LIGHTMAP_PARAMS
|
|
61
|
+
lightmapParams: BlockLightmapParams = DEFAULT_LIGHTMAP_PARAMS
|
|
71
62
|
): number {
|
|
72
63
|
const brightness = blockEntityBrightness(blockLightNorm, skyLightNorm, skyLevel, lightmapParams)
|
|
73
64
|
material.color.setScalar(brightness)
|
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
//@ts-nocheck
|
|
2
2
|
import { describe, expect, it } from 'vitest'
|
|
3
|
-
import {
|
|
4
|
-
applyLightmap,
|
|
5
|
-
blockEntityBrightness,
|
|
6
|
-
combinedBlockLight,
|
|
7
|
-
DEFAULT_LIGHTMAP_PARAMS,
|
|
8
|
-
} from './blockEntityLighting'
|
|
3
|
+
import { applyLightmap, blockEntityBrightness, combinedBlockLight, DEFAULT_LIGHTMAP_PARAMS } from './blockEntityLighting'
|
|
9
4
|
|
|
10
5
|
describe('blockEntityLighting', () => {
|
|
11
6
|
it('applyLightmap(1) === 1 for default params', () => {
|