minecraft-renderer 0.1.79 → 0.1.81
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 +66 -26
- package/dist/mesher.js +36 -36
- package/dist/mesher.js.map +4 -4
- package/dist/mesherWasm.js +217 -217
- package/dist/minecraft-renderer.js +66 -66
- package/dist/minecraft-renderer.js.meta.json +1 -1
- package/dist/threeWorker.js +450 -450
- 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 +349 -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/cameraCollisionBlockCache.ts +156 -0
- package/src/three/cameraCollisionSolidity.ts +50 -0
- package/src/three/cameraShake.ts +15 -6
- package/src/three/chunkMeshManager.ts +223 -390
- 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 +248 -264
- 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 +24 -110
- 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 -64
- 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/thirdPersonVoxelRaycast.ts +120 -0
- 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 +144 -166
- 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/cameraCollisionBlockCache.test.ts +82 -0
- 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 +1 -93
- package/src/wasm-mesher/tests/shaderCubeInstances.test.ts +103 -141
- package/src/wasm-mesher/tests/splitColumnWasmOutput.test.ts +14 -22
- package/src/wasm-mesher/tests/thirdPersonVoxelRaycast.test.ts +63 -0
- 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
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
//@ts-nocheck
|
|
2
2
|
import * as THREE from 'three'
|
|
3
|
-
import {
|
|
4
|
-
APPLY_LIGHTMAP_GLSL,
|
|
5
|
-
DEFAULT_LIGHTMAP_PARAMS,
|
|
6
|
-
type BlockLightmapParams,
|
|
7
|
-
} from '../../lib/blockEntityLighting'
|
|
3
|
+
import { APPLY_LIGHTMAP_GLSL, DEFAULT_LIGHTMAP_PARAMS, type BlockLightmapParams } from '../../lib/blockEntityLighting'
|
|
8
4
|
|
|
9
5
|
export type { BlockLightmapParams }
|
|
10
6
|
|
|
@@ -326,81 +322,74 @@ void main() {
|
|
|
326
322
|
`
|
|
327
323
|
|
|
328
324
|
export function createCubeBlockMaterial(): THREE.ShaderMaterial {
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
325
|
+
return new THREE.ShaderMaterial({
|
|
326
|
+
vertexShader,
|
|
327
|
+
fragmentShader,
|
|
328
|
+
// Merge UniformsLib.fog (fogColor/fogNear/fogFar/fogDensity) so Three.js's
|
|
329
|
+
// WebGLMaterials.refreshFogUniforms can keep them in sync with scene.fog each
|
|
330
|
+
// frame — only happens for materials with \`fog: true\` set below.
|
|
331
|
+
uniforms: THREE.UniformsUtils.merge([
|
|
332
|
+
THREE.UniformsLib.fog,
|
|
333
|
+
{
|
|
334
|
+
u_atlas: { value: null },
|
|
335
|
+
u_tintPalette: { value: null },
|
|
336
|
+
u_debugMode: { value: 0 },
|
|
337
|
+
u_skyLevel: { value: 1.0 },
|
|
338
|
+
u_shadingTheme: { value: 1.0 },
|
|
339
|
+
u_cardinalLight: { value: 0.0 },
|
|
340
|
+
u_lightCurve: { value: DEFAULT_LIGHTMAP_PARAMS.curve },
|
|
341
|
+
u_minBrightness: { value: DEFAULT_LIGHTMAP_PARAMS.minBrightness },
|
|
342
|
+
u_lightGamma: { value: DEFAULT_LIGHTMAP_PARAMS.gamma },
|
|
343
|
+
u_sectionOriginRel: { value: new THREE.Vector3(0, 0, 0) },
|
|
344
|
+
u_originDelta: { value: new THREE.Vector3() },
|
|
345
|
+
u_cameraOriginFrac: { value: new THREE.Vector3() }
|
|
346
|
+
}
|
|
347
|
+
]),
|
|
348
|
+
// Opaque full cubes — WASM mesher already culls interior faces between
|
|
349
|
+
// solid neighbors, so no z-fighting between own faces. Keep NoBlending so
|
|
350
|
+
// the alpha=1 path writes pure pixels and depth.
|
|
351
|
+
transparent: false,
|
|
352
|
+
depthWrite: true,
|
|
353
|
+
depthTest: true,
|
|
354
|
+
blending: THREE.NoBlending,
|
|
355
|
+
glslVersion: THREE.GLSL3,
|
|
356
|
+
// Required for Three.js to inject \`#define USE_FOG\` (and refresh fog uniforms).
|
|
357
|
+
fog: true
|
|
358
|
+
})
|
|
363
359
|
}
|
|
364
360
|
|
|
365
361
|
// Three geometry constants: 6 vertices per face (2 triangles, un-indexed)
|
|
366
|
-
export function setCubeSkyLevel
|
|
367
|
-
|
|
368
|
-
|
|
362
|
+
export function setCubeSkyLevel(material: THREE.ShaderMaterial, value: number): void {
|
|
363
|
+
const u = material.uniforms.u_skyLevel
|
|
364
|
+
if (u) u.value = value
|
|
369
365
|
}
|
|
370
366
|
|
|
371
|
-
export function setCubeShadingTheme
|
|
372
|
-
material: THREE.ShaderMaterial,
|
|
373
|
-
theme: 'vanilla' | 'high-contrast',
|
|
374
|
-
cardinalLight: string,
|
|
375
|
-
): void {
|
|
367
|
+
export function setCubeShadingTheme(material: THREE.ShaderMaterial, theme: 'vanilla' | 'high-contrast', cardinalLight: string): void {
|
|
376
368
|
const t = material.uniforms.u_shadingTheme
|
|
377
369
|
if (t) t.value = theme === 'high-contrast' ? 1.0 : 0.0
|
|
378
370
|
const c = material.uniforms.u_cardinalLight
|
|
379
371
|
if (c) c.value = cardinalLight === 'nether' ? 1.0 : 0.0
|
|
380
372
|
}
|
|
381
373
|
|
|
382
|
-
export function setCubeLightmapParams
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
)
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
const u = material.uniforms.u_lightGamma
|
|
396
|
-
if (u) u.value = params.gamma
|
|
397
|
-
}
|
|
374
|
+
export function setCubeLightmapParams(material: THREE.ShaderMaterial, params: BlockLightmapParams): void {
|
|
375
|
+
if (params.curve !== undefined) {
|
|
376
|
+
const u = material.uniforms.u_lightCurve
|
|
377
|
+
if (u) u.value = params.curve
|
|
378
|
+
}
|
|
379
|
+
if (params.minBrightness !== undefined) {
|
|
380
|
+
const u = material.uniforms.u_minBrightness
|
|
381
|
+
if (u) u.value = params.minBrightness
|
|
382
|
+
}
|
|
383
|
+
if (params.gamma !== undefined) {
|
|
384
|
+
const u = material.uniforms.u_lightGamma
|
|
385
|
+
if (u) u.value = params.gamma
|
|
386
|
+
}
|
|
398
387
|
}
|
|
399
388
|
|
|
400
389
|
export const VERTICES_PER_FACE = 6
|
|
401
390
|
|
|
402
391
|
/** Section index units for render origin R (R is always a multiple of 16). */
|
|
403
|
-
export function computeSectionOriginRel
|
|
392
|
+
export function computeSectionOriginRel(renderOrigin: { x: number; y: number; z: number }): {
|
|
404
393
|
x: number
|
|
405
394
|
y: number
|
|
406
395
|
z: number
|
|
@@ -408,51 +397,51 @@ export function computeSectionOriginRel (renderOrigin: { x: number, y: number, z
|
|
|
408
397
|
return {
|
|
409
398
|
x: Math.round(renderOrigin.x / 16),
|
|
410
399
|
y: Math.round(renderOrigin.y / 16),
|
|
411
|
-
z: Math.round(renderOrigin.z / 16)
|
|
400
|
+
z: Math.round(renderOrigin.z / 16)
|
|
412
401
|
}
|
|
413
402
|
}
|
|
414
403
|
|
|
415
404
|
// Word layout constants (for encoding/decoding instances)
|
|
416
405
|
export const WORD0 = {
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
406
|
+
LX_BITS: 4,
|
|
407
|
+
LY_BITS: 4,
|
|
408
|
+
LZ_BITS: 4,
|
|
409
|
+
FACE_BITS: 3,
|
|
410
|
+
TINT_BITS: 8,
|
|
411
|
+
AO_BITS_PER_CORNER: 2,
|
|
412
|
+
NUM_CORNERS: 4,
|
|
413
|
+
// Bit offsets
|
|
414
|
+
LX_SHIFT: 0,
|
|
415
|
+
LY_SHIFT: 4,
|
|
416
|
+
LZ_SHIFT: 8,
|
|
417
|
+
FACE_SHIFT: 12,
|
|
418
|
+
TINT_SHIFT: 15,
|
|
419
|
+
AO_SHIFT: 23,
|
|
420
|
+
TRANSPARENT_SHIFT: 31
|
|
432
421
|
} as const
|
|
433
422
|
|
|
434
423
|
export const WORD1 = {
|
|
435
|
-
|
|
436
|
-
|
|
424
|
+
LIGHT_BITS_PER_CORNER: 8,
|
|
425
|
+
NUM_CORNERS: 4
|
|
437
426
|
} as const
|
|
438
427
|
|
|
439
428
|
export const WORD2 = {
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
429
|
+
TEX_INDEX_BITS: 12,
|
|
430
|
+
DIAGONAL_FLAG_SHIFT: 12,
|
|
431
|
+
SECTION_Y_SHIFT: 13,
|
|
432
|
+
SECTION_Y_BITS: 5,
|
|
433
|
+
EMPTY_SHIFT: 18,
|
|
434
|
+
SECTION_X_HI_SHIFT: 19,
|
|
435
|
+
SECTION_Z_HI_SHIFT: 25,
|
|
436
|
+
SECTION_HI_BITS: 6,
|
|
437
|
+
SPARE_BITS: 1
|
|
449
438
|
} as const
|
|
450
439
|
|
|
451
440
|
/** Section base X/Z: low 16 bits in a_w3, high 6 in a_w2 (22-bit biased section index). */
|
|
452
441
|
export const WORD3 = {
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
442
|
+
SECTION_BITS: 22,
|
|
443
|
+
SECTION_MASK: (1 << 22) - 1,
|
|
444
|
+
LO_BITS: 16,
|
|
445
|
+
HI_BITS: 6,
|
|
446
|
+
SECTION_BIAS: 2097152
|
|
458
447
|
} as const
|
|
@@ -1,19 +1,15 @@
|
|
|
1
1
|
//@ts-nocheck
|
|
2
2
|
import * as THREE from 'three'
|
|
3
|
-
import {
|
|
4
|
-
APPLY_LIGHTMAP_GLSL,
|
|
5
|
-
DEFAULT_LIGHTMAP_PARAMS,
|
|
6
|
-
type BlockLightmapParams,
|
|
7
|
-
} from '../../lib/blockEntityLighting'
|
|
3
|
+
import { APPLY_LIGHTMAP_GLSL, DEFAULT_LIGHTMAP_PARAMS, type BlockLightmapParams } from '../../lib/blockEntityLighting'
|
|
8
4
|
|
|
9
|
-
export type RenderOrigin = { x: number
|
|
5
|
+
export type RenderOrigin = { x: number; y: number; z: number }
|
|
10
6
|
|
|
11
|
-
export function computeCameraRelativeUniforms
|
|
7
|
+
export function computeCameraRelativeUniforms(
|
|
12
8
|
renderOrigin: RenderOrigin,
|
|
13
9
|
x: number,
|
|
14
10
|
y: number,
|
|
15
|
-
z: number
|
|
16
|
-
): { originDelta: RenderOrigin
|
|
11
|
+
z: number
|
|
12
|
+
): { originDelta: RenderOrigin; cameraOriginFrac: RenderOrigin } {
|
|
17
13
|
const ix = Math.floor(x)
|
|
18
14
|
const iy = Math.floor(y)
|
|
19
15
|
const iz = Math.floor(z)
|
|
@@ -21,13 +17,13 @@ export function computeCameraRelativeUniforms (
|
|
|
21
17
|
originDelta: {
|
|
22
18
|
x: renderOrigin.x - ix,
|
|
23
19
|
y: renderOrigin.y - iy,
|
|
24
|
-
z: renderOrigin.z - iz
|
|
20
|
+
z: renderOrigin.z - iz
|
|
25
21
|
},
|
|
26
22
|
cameraOriginFrac: {
|
|
27
23
|
x: x - ix,
|
|
28
24
|
y: y - iy,
|
|
29
|
-
z: z - iz
|
|
30
|
-
}
|
|
25
|
+
z: z - iz
|
|
26
|
+
}
|
|
31
27
|
}
|
|
32
28
|
}
|
|
33
29
|
|
|
@@ -193,70 +189,55 @@ const legacyUniforms = {
|
|
|
193
189
|
u_skyLevel: { value: 1.0 },
|
|
194
190
|
u_lightCurve: { value: DEFAULT_LIGHTMAP_PARAMS.curve },
|
|
195
191
|
u_minBrightness: { value: DEFAULT_LIGHTMAP_PARAMS.minBrightness },
|
|
196
|
-
u_lightGamma: { value: DEFAULT_LIGHTMAP_PARAMS.gamma }
|
|
192
|
+
u_lightGamma: { value: DEFAULT_LIGHTMAP_PARAMS.gamma }
|
|
197
193
|
}
|
|
198
194
|
|
|
199
|
-
export function createLegacyBlockMaterial
|
|
195
|
+
export function createLegacyBlockMaterial(): THREE.ShaderMaterial {
|
|
200
196
|
return new THREE.ShaderMaterial({
|
|
201
197
|
vertexShader,
|
|
202
198
|
fragmentShader,
|
|
203
|
-
uniforms: THREE.UniformsUtils.merge([
|
|
204
|
-
THREE.UniformsLib.fog,
|
|
205
|
-
legacyUniforms,
|
|
206
|
-
]),
|
|
199
|
+
uniforms: THREE.UniformsUtils.merge([THREE.UniformsLib.fog, legacyUniforms]),
|
|
207
200
|
transparent: true,
|
|
208
201
|
depthWrite: true,
|
|
209
202
|
depthTest: true,
|
|
210
203
|
vertexColors: true,
|
|
211
204
|
glslVersion: THREE.GLSL3,
|
|
212
|
-
fog: true
|
|
205
|
+
fog: true
|
|
213
206
|
})
|
|
214
207
|
}
|
|
215
208
|
|
|
216
209
|
/** Global opaque legacy buffer — per-vertex section origin via a_origin. */
|
|
217
|
-
export function createGlobalLegacyBlockMaterial
|
|
210
|
+
export function createGlobalLegacyBlockMaterial(): THREE.ShaderMaterial {
|
|
218
211
|
return new THREE.ShaderMaterial({
|
|
219
212
|
vertexShader: globalVertexShader,
|
|
220
213
|
fragmentShader,
|
|
221
|
-
uniforms: THREE.UniformsUtils.merge([
|
|
222
|
-
THREE.UniformsLib.fog,
|
|
223
|
-
legacyUniforms,
|
|
224
|
-
]),
|
|
214
|
+
uniforms: THREE.UniformsUtils.merge([THREE.UniformsLib.fog, legacyUniforms]),
|
|
225
215
|
transparent: false,
|
|
226
216
|
depthWrite: true,
|
|
227
217
|
depthTest: true,
|
|
228
218
|
vertexColors: true,
|
|
229
219
|
glslVersion: THREE.GLSL3,
|
|
230
|
-
fog: true
|
|
220
|
+
fog: true
|
|
231
221
|
})
|
|
232
222
|
}
|
|
233
223
|
|
|
234
224
|
/** Global transparent blend buffer — same shaders as opaque global, blend material flags. */
|
|
235
|
-
export function createGlobalLegacyBlendMaterial
|
|
225
|
+
export function createGlobalLegacyBlendMaterial(): THREE.ShaderMaterial {
|
|
236
226
|
return new THREE.ShaderMaterial({
|
|
237
227
|
vertexShader: globalVertexShader,
|
|
238
228
|
fragmentShader,
|
|
239
|
-
uniforms: THREE.UniformsUtils.merge([
|
|
240
|
-
THREE.UniformsLib.fog,
|
|
241
|
-
legacyUniforms,
|
|
242
|
-
]),
|
|
229
|
+
uniforms: THREE.UniformsUtils.merge([THREE.UniformsLib.fog, legacyUniforms]),
|
|
243
230
|
transparent: true,
|
|
244
231
|
depthWrite: true,
|
|
245
232
|
depthTest: true,
|
|
246
233
|
vertexColors: true,
|
|
247
234
|
glslVersion: THREE.GLSL3,
|
|
248
|
-
fog: true
|
|
235
|
+
fog: true
|
|
249
236
|
})
|
|
250
237
|
}
|
|
251
238
|
|
|
252
239
|
/** Render-origin + fractional camera split — matches GlobalBlockBuffer.setCameraOrigin. */
|
|
253
|
-
export function setLegacyCameraOrigin
|
|
254
|
-
material: THREE.ShaderMaterial,
|
|
255
|
-
renderOrigin: RenderOrigin,
|
|
256
|
-
x: number,
|
|
257
|
-
y: number,
|
|
258
|
-
z: number,
|
|
259
|
-
): void {
|
|
240
|
+
export function setLegacyCameraOrigin(material: THREE.ShaderMaterial, renderOrigin: RenderOrigin, x: number, y: number, z: number): void {
|
|
260
241
|
const { originDelta, cameraOriginFrac } = computeCameraRelativeUniforms(renderOrigin, x, y, z)
|
|
261
242
|
const u = material.uniforms.u_originDelta
|
|
262
243
|
if (u?.value?.set) {
|
|
@@ -268,15 +249,12 @@ export function setLegacyCameraOrigin (
|
|
|
268
249
|
}
|
|
269
250
|
}
|
|
270
251
|
|
|
271
|
-
export function setLegacySkyLevel
|
|
252
|
+
export function setLegacySkyLevel(material: THREE.ShaderMaterial, value: number): void {
|
|
272
253
|
const u = material.uniforms.u_skyLevel
|
|
273
254
|
if (u) u.value = value
|
|
274
255
|
}
|
|
275
256
|
|
|
276
|
-
export function setLegacyLightmapParams
|
|
277
|
-
material: THREE.ShaderMaterial,
|
|
278
|
-
params: BlockLightmapParams,
|
|
279
|
-
): void {
|
|
257
|
+
export function setLegacyLightmapParams(material: THREE.ShaderMaterial, params: BlockLightmapParams): void {
|
|
280
258
|
if (params.curve !== undefined) {
|
|
281
259
|
const u = material.uniforms.u_lightCurve
|
|
282
260
|
if (u) u.value = params.curve
|
|
@@ -10,113 +10,107 @@
|
|
|
10
10
|
|
|
11
11
|
// WorldBlockProvider interface (subset used by this module)
|
|
12
12
|
export interface TextureAtlasInfo {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
13
|
+
/** Atlas width in pixels (must be 1024) */
|
|
14
|
+
width: number
|
|
15
|
+
/** Atlas height in pixels (must be 1024) */
|
|
16
|
+
height: number
|
|
17
|
+
/** Tile size in pixels (must be 16) */
|
|
18
|
+
tileSize: number
|
|
19
|
+
/** Resolution scale (suSv = tileSize * resolution) */
|
|
20
|
+
suSv: number
|
|
21
|
+
/** Texture name → atlas position */
|
|
22
|
+
textures: Record<string, TextureEntry>
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
export interface TextureEntry {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
26
|
+
/** Horizontal pixel offset within atlas */
|
|
27
|
+
u: number
|
|
28
|
+
/** Vertical pixel offset within atlas */
|
|
29
|
+
v: number
|
|
30
|
+
/** Horizontal pixel count (typically 16 or suSv) */
|
|
31
|
+
su: number
|
|
32
|
+
/** Vertical pixel count (typically 16 or suSv) */
|
|
33
|
+
sv: number
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
export class TextureIndexMapping {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
37
|
+
private atlasWidth: number
|
|
38
|
+
private atlasHeight: number
|
|
39
|
+
private tileSize: number
|
|
40
|
+
private tilesPerRow: number
|
|
41
|
+
private maxTiles: number
|
|
42
|
+
private valid: boolean
|
|
43
43
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
44
|
+
constructor(atlasInfo: TextureAtlasInfo) {
|
|
45
|
+
this.atlasWidth = atlasInfo.width
|
|
46
|
+
this.atlasHeight = atlasInfo.height
|
|
47
|
+
this.tileSize = atlasInfo.tileSize
|
|
48
|
+
this.tilesPerRow = Math.floor(this.atlasWidth / this.tileSize)
|
|
49
|
+
this.maxTiles = this.tilesPerRow * Math.floor(this.atlasHeight / this.tileSize)
|
|
50
50
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
&& this.tileSize === 16
|
|
55
|
-
&& this.maxTiles <= 4096 // 12-bit limit
|
|
56
|
-
}
|
|
51
|
+
// Only valid when atlas matches the shader's hardcoded layout (1024×1024, 16×16 tiles).
|
|
52
|
+
this.valid = this.atlasWidth === 1024 && this.atlasHeight === 1024 && this.tileSize === 16 && this.maxTiles <= 4096 // 12-bit limit
|
|
53
|
+
}
|
|
57
54
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
55
|
+
/** True when 12-bit texIndex encoding is safe (atlas matches the shader's layout). */
|
|
56
|
+
isValid(): boolean {
|
|
57
|
+
return this.valid
|
|
58
|
+
}
|
|
62
59
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
60
|
+
/** Tiles per row in the atlas */
|
|
61
|
+
getTilesPerRow(): number {
|
|
62
|
+
return this.tilesPerRow
|
|
63
|
+
}
|
|
67
64
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
65
|
+
/**
|
|
66
|
+
* Compute absolute tile index from atlas pixel position.
|
|
67
|
+
* Returns -1 if the position is out of range or gate fails.
|
|
68
|
+
*/
|
|
69
|
+
tileIndexFromPixelCoords(u: number, v: number): number {
|
|
70
|
+
if (!this.valid) return -1
|
|
71
|
+
const tileCol = Math.floor(u / this.tileSize)
|
|
72
|
+
const tileRow = Math.floor(v / this.tileSize)
|
|
73
|
+
if (tileCol < 0 || tileCol >= this.tilesPerRow || tileRow < 0) return -1
|
|
74
|
+
const index = tileRow * this.tilesPerRow + tileCol
|
|
75
|
+
if (index >= this.maxTiles) return -1
|
|
76
|
+
return index
|
|
77
|
+
}
|
|
81
78
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
79
|
+
/**
|
|
80
|
+
* Get tile index for a texture entry from the atlas.
|
|
81
|
+
* Returns -1 if the texture spans multiple tiles or gate fails.
|
|
82
|
+
*/
|
|
83
|
+
tileIndexFromTextureEntry(entry: TextureEntry): number {
|
|
84
|
+
if (!this.valid) return -1
|
|
85
|
+
// Verify the texture occupies exactly one tile
|
|
86
|
+
if (entry.su !== this.tileSize || entry.sv !== this.tileSize) return -1
|
|
87
|
+
return this.tileIndexFromPixelCoords(entry.u, entry.v)
|
|
88
|
+
}
|
|
92
89
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
// Try without 'block/' prefix
|
|
116
|
-
const stripped = textureName.replace(/^block\//, '')
|
|
117
|
-
entry = atlasInfo.textures[stripped]
|
|
118
|
-
}
|
|
119
|
-
if (!entry) return -1
|
|
120
|
-
return this.tileIndexFromTextureEntry(entry)
|
|
90
|
+
/**
|
|
91
|
+
* Look up tile index by texture name.
|
|
92
|
+
* Returns -1 if the texture is not found, spans multiple tiles, or gate fails.
|
|
93
|
+
*/
|
|
94
|
+
tileIndexFromTextureName(textureName: string, atlasInfo: TextureAtlasInfo): number {
|
|
95
|
+
if (!this.valid) return -1
|
|
96
|
+
// Try exact name, then strip namespace prefix
|
|
97
|
+
let entry = atlasInfo.textures[textureName]
|
|
98
|
+
if (!entry && textureName.includes(':')) {
|
|
99
|
+
entry = atlasInfo.textures[textureName.split(':')[1]]
|
|
100
|
+
}
|
|
101
|
+
if (!entry && textureName.includes('/')) {
|
|
102
|
+
entry = atlasInfo.textures[textureName.split('/')[1]]
|
|
103
|
+
}
|
|
104
|
+
if (!entry) {
|
|
105
|
+
// Try 'block/' prefix
|
|
106
|
+
entry = atlasInfo.textures[`block/${textureName}`]
|
|
107
|
+
}
|
|
108
|
+
if (!entry) {
|
|
109
|
+
// Try without 'block/' prefix
|
|
110
|
+
const stripped = textureName.replace(/^block\//, '')
|
|
111
|
+
entry = atlasInfo.textures[stripped]
|
|
121
112
|
}
|
|
113
|
+
if (!entry) return -1
|
|
114
|
+
return this.tileIndexFromTextureEntry(entry)
|
|
115
|
+
}
|
|
122
116
|
}
|