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
package/src/three/sceneOrigin.ts
CHANGED
|
@@ -4,20 +4,53 @@ import type { Object3D, Scene, Vector3 } from 'three'
|
|
|
4
4
|
const IS_TRACKED_PROXY = Symbol('tracked-proxy')
|
|
5
5
|
|
|
6
6
|
const MUTATING_METHODS = new Set([
|
|
7
|
-
'add',
|
|
8
|
-
'
|
|
9
|
-
'
|
|
10
|
-
'
|
|
11
|
-
'
|
|
12
|
-
'
|
|
13
|
-
'
|
|
14
|
-
'
|
|
15
|
-
'
|
|
16
|
-
'
|
|
17
|
-
'
|
|
18
|
-
'
|
|
19
|
-
'
|
|
20
|
-
'
|
|
7
|
+
'add',
|
|
8
|
+
'addScalar',
|
|
9
|
+
'addScaledVector',
|
|
10
|
+
'addVectors',
|
|
11
|
+
'sub',
|
|
12
|
+
'subScalar',
|
|
13
|
+
'subVectors',
|
|
14
|
+
'multiply',
|
|
15
|
+
'multiplyScalar',
|
|
16
|
+
'multiplyVectors',
|
|
17
|
+
'divide',
|
|
18
|
+
'divideScalar',
|
|
19
|
+
'applyEuler',
|
|
20
|
+
'applyAxisAngle',
|
|
21
|
+
'applyMatrix3',
|
|
22
|
+
'applyMatrix4',
|
|
23
|
+
'applyNormalMatrix',
|
|
24
|
+
'applyQuaternion',
|
|
25
|
+
'negate',
|
|
26
|
+
'floor',
|
|
27
|
+
'ceil',
|
|
28
|
+
'round',
|
|
29
|
+
'roundToZero',
|
|
30
|
+
'min',
|
|
31
|
+
'max',
|
|
32
|
+
'clamp',
|
|
33
|
+
'clampLength',
|
|
34
|
+
'clampScalar',
|
|
35
|
+
'project',
|
|
36
|
+
'unproject',
|
|
37
|
+
'reflect',
|
|
38
|
+
'lerp',
|
|
39
|
+
'lerpVectors',
|
|
40
|
+
'cross',
|
|
41
|
+
'crossVectors',
|
|
42
|
+
'setFromMatrixPosition',
|
|
43
|
+
'setFromMatrixColumn',
|
|
44
|
+
'setFromMatrix3Column',
|
|
45
|
+
'setFromEuler',
|
|
46
|
+
'setFromSpherical',
|
|
47
|
+
'setFromSphericalCoords',
|
|
48
|
+
'setFromCylindrical',
|
|
49
|
+
'fromArray',
|
|
50
|
+
'fromBufferAttribute',
|
|
51
|
+
'setComponent',
|
|
52
|
+
'randomDirection',
|
|
53
|
+
'random'
|
|
21
54
|
])
|
|
22
55
|
|
|
23
56
|
interface TrackOptions {
|
|
@@ -41,9 +74,15 @@ export class SceneOrigin {
|
|
|
41
74
|
this.scene = scene
|
|
42
75
|
}
|
|
43
76
|
|
|
44
|
-
get x(): number {
|
|
45
|
-
|
|
46
|
-
|
|
77
|
+
get x(): number {
|
|
78
|
+
return this._x
|
|
79
|
+
}
|
|
80
|
+
get y(): number {
|
|
81
|
+
return this._y
|
|
82
|
+
}
|
|
83
|
+
get z(): number {
|
|
84
|
+
return this._z
|
|
85
|
+
}
|
|
47
86
|
|
|
48
87
|
/** Update origin (called each frame with camera world position) */
|
|
49
88
|
update(worldX: number, worldY: number, worldZ: number): void {
|
|
@@ -83,7 +122,9 @@ export class SceneOrigin {
|
|
|
83
122
|
if (prop === IS_TRACKED_PROXY) return worldData
|
|
84
123
|
if (prop === 'set') {
|
|
85
124
|
return (x: number, y: number, z: number) => {
|
|
86
|
-
worldData.x = x
|
|
125
|
+
worldData.x = x
|
|
126
|
+
worldData.y = y
|
|
127
|
+
worldData.z = z
|
|
87
128
|
target.set(x - origin._x, y - origin._y, z - origin._z)
|
|
88
129
|
if (opts?.updateMatrix) obj.updateMatrix()
|
|
89
130
|
return receiver
|
|
@@ -95,7 +136,9 @@ export class SceneOrigin {
|
|
|
95
136
|
const wx = srcWorld ? srcWorld.x : v.x
|
|
96
137
|
const wy = srcWorld ? srcWorld.y : v.y
|
|
97
138
|
const wz = srcWorld ? srcWorld.z : v.z
|
|
98
|
-
worldData.x = wx
|
|
139
|
+
worldData.x = wx
|
|
140
|
+
worldData.y = wy
|
|
141
|
+
worldData.z = wz
|
|
99
142
|
target.set(wx - origin._x, wy - origin._y, wz - origin._z)
|
|
100
143
|
if (opts?.updateMatrix) obj.updateMatrix()
|
|
101
144
|
return receiver
|
|
@@ -103,27 +146,32 @@ export class SceneOrigin {
|
|
|
103
146
|
}
|
|
104
147
|
if (prop === 'setX') {
|
|
105
148
|
return (val: number) => {
|
|
106
|
-
worldData.x = val
|
|
149
|
+
worldData.x = val
|
|
150
|
+
target.x = val - origin._x
|
|
107
151
|
if (opts?.updateMatrix) obj.updateMatrix()
|
|
108
152
|
return receiver
|
|
109
153
|
}
|
|
110
154
|
}
|
|
111
155
|
if (prop === 'setY') {
|
|
112
156
|
return (val: number) => {
|
|
113
|
-
worldData.y = val
|
|
157
|
+
worldData.y = val
|
|
158
|
+
target.y = val - origin._y
|
|
114
159
|
if (opts?.updateMatrix) obj.updateMatrix()
|
|
115
160
|
return receiver
|
|
116
161
|
}
|
|
117
162
|
}
|
|
118
163
|
if (prop === 'setZ') {
|
|
119
164
|
return (val: number) => {
|
|
120
|
-
worldData.z = val
|
|
165
|
+
worldData.z = val
|
|
166
|
+
target.z = val - origin._z
|
|
121
167
|
if (opts?.updateMatrix) obj.updateMatrix()
|
|
122
168
|
return receiver
|
|
123
169
|
}
|
|
124
170
|
}
|
|
125
171
|
if (typeof prop === 'string' && MUTATING_METHODS.has(prop)) {
|
|
126
|
-
return () => {
|
|
172
|
+
return () => {
|
|
173
|
+
throw new Error(`Cannot call position.${prop}() on a tracked object. Use position.set(x, y, z) instead.`)
|
|
174
|
+
}
|
|
127
175
|
}
|
|
128
176
|
const value = (target as any)[prop]
|
|
129
177
|
if (typeof value === 'function') return value.bind(target)
|
|
@@ -131,17 +179,20 @@ export class SceneOrigin {
|
|
|
131
179
|
},
|
|
132
180
|
set(target, prop, value) {
|
|
133
181
|
if (prop === 'x') {
|
|
134
|
-
worldData.x = value
|
|
182
|
+
worldData.x = value
|
|
183
|
+
target.x = value - origin._x
|
|
135
184
|
if (opts?.updateMatrix) obj.updateMatrix()
|
|
136
185
|
return true
|
|
137
186
|
}
|
|
138
187
|
if (prop === 'y') {
|
|
139
|
-
worldData.y = value
|
|
188
|
+
worldData.y = value
|
|
189
|
+
target.y = value - origin._y
|
|
140
190
|
if (opts?.updateMatrix) obj.updateMatrix()
|
|
141
191
|
return true
|
|
142
192
|
}
|
|
143
193
|
if (prop === 'z') {
|
|
144
|
-
worldData.z = value
|
|
194
|
+
worldData.z = value
|
|
195
|
+
target.z = value - origin._z
|
|
145
196
|
if (opts?.updateMatrix) obj.updateMatrix()
|
|
146
197
|
return true
|
|
147
198
|
}
|
|
@@ -179,7 +230,7 @@ export class SceneOrigin {
|
|
|
179
230
|
|
|
180
231
|
/** Untrack an Object3D and all its descendants, then remove from the scene */
|
|
181
232
|
removeAndUntrackAll(obj: Object3D): void {
|
|
182
|
-
obj.traverse(
|
|
233
|
+
obj.traverse(child => {
|
|
183
234
|
this.untrack(child)
|
|
184
235
|
})
|
|
185
236
|
obj.removeFromParent()
|
|
@@ -204,12 +255,24 @@ export class SceneOrigin {
|
|
|
204
255
|
}
|
|
205
256
|
|
|
206
257
|
/** Convert world coordinates → scene coordinates */
|
|
207
|
-
toSceneX(worldX: number): number {
|
|
208
|
-
|
|
209
|
-
|
|
258
|
+
toSceneX(worldX: number): number {
|
|
259
|
+
return worldX - this._x
|
|
260
|
+
}
|
|
261
|
+
toSceneY(worldY: number): number {
|
|
262
|
+
return worldY - this._y
|
|
263
|
+
}
|
|
264
|
+
toSceneZ(worldZ: number): number {
|
|
265
|
+
return worldZ - this._z
|
|
266
|
+
}
|
|
210
267
|
|
|
211
268
|
/** Convert scene coordinates → world coordinates */
|
|
212
|
-
toWorldX(sceneX: number): number {
|
|
213
|
-
|
|
214
|
-
|
|
269
|
+
toWorldX(sceneX: number): number {
|
|
270
|
+
return sceneX + this._x
|
|
271
|
+
}
|
|
272
|
+
toWorldY(sceneY: number): number {
|
|
273
|
+
return sceneY + this._y
|
|
274
|
+
}
|
|
275
|
+
toWorldZ(sceneZ: number): number {
|
|
276
|
+
return sceneZ + this._z
|
|
277
|
+
}
|
|
215
278
|
}
|
|
@@ -25,12 +25,12 @@ export type ShaderSectionRaycastEntry = {
|
|
|
25
25
|
* Tight world-space AABB covering occupied shader-cube blocks in a section.
|
|
26
26
|
* `sectionCenter*` is geometryData.sx/sy/sz (section base + 8).
|
|
27
27
|
*/
|
|
28
|
-
export function computeShaderSectionRaycastAabb
|
|
28
|
+
export function computeShaderSectionRaycastAabb(
|
|
29
29
|
words: Uint32Array,
|
|
30
30
|
faceCount: number,
|
|
31
31
|
sectionCenterX: number,
|
|
32
32
|
sectionCenterY: number,
|
|
33
|
-
sectionCenterZ: number
|
|
33
|
+
sectionCenterZ: number
|
|
34
34
|
): ShaderSectionRaycastBox | undefined {
|
|
35
35
|
if (faceCount <= 0) return undefined
|
|
36
36
|
|
|
@@ -77,11 +77,11 @@ export function computeShaderSectionRaycastAabb (
|
|
|
77
77
|
maxZ,
|
|
78
78
|
cx: (minX + maxX) * 0.5,
|
|
79
79
|
cy: (minY + maxY) * 0.5,
|
|
80
|
-
cz: (minZ + maxZ) * 0.5
|
|
80
|
+
cz: (minZ + maxZ) * 0.5
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
export function isPointInsideAabb
|
|
84
|
+
export function isPointInsideAabb(
|
|
85
85
|
ox: number,
|
|
86
86
|
oy: number,
|
|
87
87
|
oz: number,
|
|
@@ -90,14 +90,14 @@ export function isPointInsideAabb (
|
|
|
90
90
|
minZ: number,
|
|
91
91
|
maxX: number,
|
|
92
92
|
maxY: number,
|
|
93
|
-
maxZ: number
|
|
93
|
+
maxZ: number
|
|
94
94
|
): boolean {
|
|
95
95
|
return ox >= minX && ox <= maxX && oy >= minY && oy <= maxY && oz >= minZ && oz <= maxZ
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
/** True if a `far`-bounded ray from (ox,oy,oz) dir (dx,dy,dz) crosses or starts inside
|
|
99
99
|
* the cube-section AABB centered at (cx,cy,cz) with the given half-extent. */
|
|
100
|
-
export function sectionAabbIntersectsRay
|
|
100
|
+
export function sectionAabbIntersectsRay(
|
|
101
101
|
cx: number,
|
|
102
102
|
cy: number,
|
|
103
103
|
cz: number,
|
|
@@ -108,7 +108,7 @@ export function sectionAabbIntersectsRay (
|
|
|
108
108
|
dy: number,
|
|
109
109
|
dz: number,
|
|
110
110
|
far: number,
|
|
111
|
-
halfExtent: number
|
|
111
|
+
halfExtent: number
|
|
112
112
|
): boolean {
|
|
113
113
|
const minX = cx - halfExtent
|
|
114
114
|
const minY = cy - halfExtent
|
|
@@ -121,7 +121,7 @@ export function sectionAabbIntersectsRay (
|
|
|
121
121
|
}
|
|
122
122
|
|
|
123
123
|
/** Ray–AABB entry distance, or undefined. Ignores hits when origin is inside the box. */
|
|
124
|
-
export function raycastAabb
|
|
124
|
+
export function raycastAabb(
|
|
125
125
|
ox: number,
|
|
126
126
|
oy: number,
|
|
127
127
|
oz: number,
|
|
@@ -134,7 +134,7 @@ export function raycastAabb (
|
|
|
134
134
|
maxX: number,
|
|
135
135
|
maxY: number,
|
|
136
136
|
maxZ: number,
|
|
137
|
-
maxDist: number
|
|
137
|
+
maxDist: number
|
|
138
138
|
): number | undefined {
|
|
139
139
|
if (isPointInsideAabb(ox, oy, oz, minX, minY, minZ, maxX, maxY, maxZ)) {
|
|
140
140
|
return undefined
|
|
@@ -149,7 +149,11 @@ export function raycastAabb (
|
|
|
149
149
|
const inv = 1 / dx
|
|
150
150
|
let t1 = (minX - ox) * inv
|
|
151
151
|
let t2 = (maxX - ox) * inv
|
|
152
|
-
if (t1 > t2) {
|
|
152
|
+
if (t1 > t2) {
|
|
153
|
+
const tmp = t1
|
|
154
|
+
t1 = t2
|
|
155
|
+
t2 = tmp
|
|
156
|
+
}
|
|
153
157
|
tmin = Math.max(tmin, t1)
|
|
154
158
|
tmax = Math.min(tmax, t2)
|
|
155
159
|
if (tmin > tmax) return undefined
|
|
@@ -161,7 +165,11 @@ export function raycastAabb (
|
|
|
161
165
|
const inv = 1 / dy
|
|
162
166
|
let t1 = (minY - oy) * inv
|
|
163
167
|
let t2 = (maxY - oy) * inv
|
|
164
|
-
if (t1 > t2) {
|
|
168
|
+
if (t1 > t2) {
|
|
169
|
+
const tmp = t1
|
|
170
|
+
t1 = t2
|
|
171
|
+
t2 = tmp
|
|
172
|
+
}
|
|
165
173
|
tmin = Math.max(tmin, t1)
|
|
166
174
|
tmax = Math.min(tmax, t2)
|
|
167
175
|
if (tmin > tmax) return undefined
|
|
@@ -173,7 +181,11 @@ export function raycastAabb (
|
|
|
173
181
|
const inv = 1 / dz
|
|
174
182
|
let t1 = (minZ - oz) * inv
|
|
175
183
|
let t2 = (maxZ - oz) * inv
|
|
176
|
-
if (t1 > t2) {
|
|
184
|
+
if (t1 > t2) {
|
|
185
|
+
const tmp = t1
|
|
186
|
+
t1 = t2
|
|
187
|
+
t2 = tmp
|
|
188
|
+
}
|
|
177
189
|
tmin = Math.max(tmin, t1)
|
|
178
190
|
tmax = Math.min(tmax, t2)
|
|
179
191
|
if (tmin > tmax) return undefined
|
|
@@ -183,7 +195,7 @@ export function raycastAabb (
|
|
|
183
195
|
}
|
|
184
196
|
|
|
185
197
|
/** Ray origin inside AABB: distance to exit face along the ray. */
|
|
186
|
-
export function raycastAabbFromInside
|
|
198
|
+
export function raycastAabbFromInside(
|
|
187
199
|
ox: number,
|
|
188
200
|
oy: number,
|
|
189
201
|
oz: number,
|
|
@@ -196,7 +208,7 @@ export function raycastAabbFromInside (
|
|
|
196
208
|
maxX: number,
|
|
197
209
|
maxY: number,
|
|
198
210
|
maxZ: number,
|
|
199
|
-
maxDist: number
|
|
211
|
+
maxDist: number
|
|
200
212
|
): number | undefined {
|
|
201
213
|
let tExit = maxDist
|
|
202
214
|
|
|
@@ -219,7 +231,7 @@ export function raycastAabbFromInside (
|
|
|
219
231
|
}
|
|
220
232
|
|
|
221
233
|
/** Per-block raycast; `word0Stride` 1 = GlobalBlockBuffer SoA, 4 = deferred AoS. */
|
|
222
|
-
export function raycastShaderBlocksAabb
|
|
234
|
+
export function raycastShaderBlocksAabb(
|
|
223
235
|
w0Source: Uint32Array,
|
|
224
236
|
start: number,
|
|
225
237
|
faceCount: number,
|
|
@@ -235,7 +247,7 @@ export function raycastShaderBlocksAabb (
|
|
|
235
247
|
dz: number,
|
|
236
248
|
maxDist: number,
|
|
237
249
|
visitGen: Uint16Array,
|
|
238
|
-
visitStamp: number
|
|
250
|
+
visitStamp: number
|
|
239
251
|
): number | undefined {
|
|
240
252
|
const baseX = sectionCenterX - 8
|
|
241
253
|
const baseY = sectionCenterY - 8
|
|
@@ -276,7 +288,7 @@ export function raycastShaderBlocksAabb (
|
|
|
276
288
|
}
|
|
277
289
|
|
|
278
290
|
/** 16³ section box centered at (cx, cy, cz) — tests / legacy helper. */
|
|
279
|
-
export function raycastSectionAabb
|
|
291
|
+
export function raycastSectionAabb(
|
|
280
292
|
ox: number,
|
|
281
293
|
oy: number,
|
|
282
294
|
oz: number,
|
|
@@ -286,7 +298,7 @@ export function raycastSectionAabb (
|
|
|
286
298
|
cx: number,
|
|
287
299
|
cy: number,
|
|
288
300
|
cz: number,
|
|
289
|
-
maxDist: number
|
|
301
|
+
maxDist: number
|
|
290
302
|
): number | undefined {
|
|
291
303
|
return raycastAabb(ox, oy, oz, dx, dy, dz, cx - 8, cy - 8, cz - 8, cx + 8, cy + 8, cz + 8, maxDist)
|
|
292
304
|
}
|
|
@@ -12,10 +12,7 @@ export type ShaderCubeInstanceData = {
|
|
|
12
12
|
* Build InstancedBufferGeometry for full-cube shader faces.
|
|
13
13
|
* One instance = one visible face; vertex shader uses gl_VertexID (6 verts/face).
|
|
14
14
|
*/
|
|
15
|
-
export function buildShaderCubeGeometry(
|
|
16
|
-
words: Uint32Array,
|
|
17
|
-
faceCount: number,
|
|
18
|
-
): THREE.InstancedBufferGeometry {
|
|
15
|
+
export function buildShaderCubeGeometry(words: Uint32Array, faceCount: number): THREE.InstancedBufferGeometry {
|
|
19
16
|
const geometry = new THREE.InstancedBufferGeometry()
|
|
20
17
|
|
|
21
18
|
const positions = new Float32Array(VERTICES_PER_FACE * 3)
|
|
@@ -39,14 +36,8 @@ export function buildShaderCubeGeometry(
|
|
|
39
36
|
geometry.setAttribute('a_w3', new THREE.InstancedBufferAttribute(w3, 1))
|
|
40
37
|
|
|
41
38
|
geometry.instanceCount = faceCount
|
|
42
|
-
geometry.boundingBox = new THREE.Box3(
|
|
43
|
-
|
|
44
|
-
new THREE.Vector3(8, 8, 8),
|
|
45
|
-
)
|
|
46
|
-
geometry.boundingSphere = new THREE.Sphere(
|
|
47
|
-
new THREE.Vector3(0, 0, 0),
|
|
48
|
-
Math.sqrt(3 * 8 ** 2),
|
|
49
|
-
)
|
|
39
|
+
geometry.boundingBox = new THREE.Box3(new THREE.Vector3(-8, -8, -8), new THREE.Vector3(8, 8, 8))
|
|
40
|
+
geometry.boundingSphere = new THREE.Sphere(new THREE.Vector3(0, 0, 0), Math.sqrt(3 * 8 ** 2))
|
|
50
41
|
|
|
51
42
|
return geometry
|
|
52
43
|
}
|
|
@@ -58,9 +49,7 @@ const _raycastPoint = new THREE.Vector3()
|
|
|
58
49
|
* CPU raycast uses section AABB (geometry.boundingBox), not GPU-generated faces.
|
|
59
50
|
* Enough for third-person camera collision; block pick uses mineflayer, not mesh raycast.
|
|
60
51
|
*/
|
|
61
|
-
export function attachShaderCubeRaycast(
|
|
62
|
-
mesh: THREE.Mesh<THREE.BufferGeometry, THREE.Material>,
|
|
63
|
-
): void {
|
|
52
|
+
export function attachShaderCubeRaycast(mesh: THREE.Mesh<THREE.BufferGeometry, THREE.Material>): void {
|
|
64
53
|
mesh.raycast = (raycaster, intersects) => {
|
|
65
54
|
const { geometry } = mesh
|
|
66
55
|
if (!geometry.boundingBox) return
|
|
@@ -70,14 +59,14 @@ export function attachShaderCubeRaycast(
|
|
|
70
59
|
intersects.push({
|
|
71
60
|
distance,
|
|
72
61
|
point: _raycastPoint.clone(),
|
|
73
|
-
object: mesh
|
|
62
|
+
object: mesh
|
|
74
63
|
})
|
|
75
64
|
}
|
|
76
65
|
}
|
|
77
66
|
|
|
78
67
|
export function createShaderCubeMesh(
|
|
79
68
|
data: ShaderCubeInstanceData,
|
|
80
|
-
material: THREE.ShaderMaterial
|
|
69
|
+
material: THREE.ShaderMaterial
|
|
81
70
|
): THREE.Mesh<THREE.InstancedBufferGeometry, THREE.ShaderMaterial> {
|
|
82
71
|
const geometry = buildShaderCubeGeometry(data.words, data.count)
|
|
83
72
|
const mesh = new THREE.Mesh(geometry, material)
|
|
@@ -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
|