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
|
@@ -12,7 +12,7 @@ export interface CinimaticPoint {
|
|
|
12
12
|
pitch: number
|
|
13
13
|
duration: number // Time to reach this point from the previous one
|
|
14
14
|
easing?: 'linear' | 'easeIn' | 'easeOut' | 'easeInOut' | 'smoothstep' | 'bounce'
|
|
15
|
-
lookAt?: { x: number
|
|
15
|
+
lookAt?: { x: number; y: number; z: number } // Optional: override rotation to look at this point
|
|
16
16
|
fov?: number // Optional: change field of view
|
|
17
17
|
}
|
|
18
18
|
|
|
@@ -41,8 +41,8 @@ export class CinimaticScriptRunner {
|
|
|
41
41
|
private readonly worldRenderer: WorldRendererThree,
|
|
42
42
|
private readonly updateCamera: (pos: Vec3, yaw: number, pitch: number) => void,
|
|
43
43
|
private readonly updateFov: (fov: number) => void,
|
|
44
|
-
private readonly getInitialState: () => { position: Vec3
|
|
45
|
-
) {
|
|
44
|
+
private readonly getInitialState: () => { position: Vec3; yaw: number; pitch: number; fov: number }
|
|
45
|
+
) {}
|
|
46
46
|
|
|
47
47
|
startScript(script: CinimaticScript): boolean {
|
|
48
48
|
if (this.isRunning) {
|
|
@@ -116,7 +116,7 @@ export class CinimaticScriptRunner {
|
|
|
116
116
|
{ pos: playerPos.offset(-20, 10, -20), lookAt: playerPos, duration: 3000 },
|
|
117
117
|
{ pos: playerPos.offset(20, 15, -20), lookAt: playerPos, duration: 3000 },
|
|
118
118
|
{ pos: playerPos.offset(20, 20, 20), lookAt: playerPos, duration: 3000 },
|
|
119
|
-
{ pos: playerPos.offset(-20, 25, 20), lookAt: playerPos, duration: 3000 }
|
|
119
|
+
{ pos: playerPos.offset(-20, 25, 20), lookAt: playerPos, duration: 3000 }
|
|
120
120
|
])
|
|
121
121
|
|
|
122
122
|
const scripts = [circular, spiral, buildingTour]
|
|
@@ -212,7 +212,7 @@ export class CinimaticScriptRunner {
|
|
|
212
212
|
})
|
|
213
213
|
}
|
|
214
214
|
|
|
215
|
-
private wrapRotation(target: { yaw: number
|
|
215
|
+
private wrapRotation(target: { yaw: number; pitch: number }): { yaw: number; pitch: number } {
|
|
216
216
|
// Handle yaw wrapping to take shortest path
|
|
217
217
|
let targetYaw = target.yaw
|
|
218
218
|
const yawDiff = targetYaw - this.currentRotation.yaw
|
|
@@ -231,13 +231,20 @@ export class CinimaticScriptRunner {
|
|
|
231
231
|
|
|
232
232
|
private getEasingFunction(easing: string): (t: number) => number {
|
|
233
233
|
switch (easing) {
|
|
234
|
-
case 'linear':
|
|
235
|
-
|
|
236
|
-
case '
|
|
237
|
-
|
|
238
|
-
case '
|
|
239
|
-
|
|
240
|
-
|
|
234
|
+
case 'linear':
|
|
235
|
+
return tweenJs.Easing.Linear.None
|
|
236
|
+
case 'easeIn':
|
|
237
|
+
return tweenJs.Easing.Quadratic.In
|
|
238
|
+
case 'easeOut':
|
|
239
|
+
return tweenJs.Easing.Quadratic.Out
|
|
240
|
+
case 'easeInOut':
|
|
241
|
+
return tweenJs.Easing.Quadratic.InOut
|
|
242
|
+
case 'smoothstep':
|
|
243
|
+
return tweenJs.Easing.Cubic.InOut
|
|
244
|
+
case 'bounce':
|
|
245
|
+
return tweenJs.Easing.Bounce.Out
|
|
246
|
+
default:
|
|
247
|
+
return tweenJs.Easing.Quadratic.InOut
|
|
241
248
|
}
|
|
242
249
|
}
|
|
243
250
|
|
|
@@ -285,7 +292,9 @@ export class CinimaticScriptRunner {
|
|
|
285
292
|
const y = center.y + height
|
|
286
293
|
|
|
287
294
|
points.push({
|
|
288
|
-
x,
|
|
295
|
+
x,
|
|
296
|
+
y,
|
|
297
|
+
z,
|
|
289
298
|
yaw: angle + Math.PI / 2, // Look tangent to circle
|
|
290
299
|
pitch: -0.2, // Look slightly down
|
|
291
300
|
duration: duration / numPoints,
|
|
@@ -315,7 +324,9 @@ export class CinimaticScriptRunner {
|
|
|
315
324
|
const y = THREE.MathUtils.lerp(start.y, end.y, t)
|
|
316
325
|
|
|
317
326
|
points.push({
|
|
318
|
-
x,
|
|
327
|
+
x,
|
|
328
|
+
y,
|
|
329
|
+
z,
|
|
319
330
|
yaw: angle + Math.PI / 2,
|
|
320
331
|
pitch: -0.3 * t, // Gradually look more down
|
|
321
332
|
duration: duration / numPoints,
|
|
@@ -330,7 +341,7 @@ export class CinimaticScriptRunner {
|
|
|
330
341
|
}
|
|
331
342
|
}
|
|
332
343
|
|
|
333
|
-
static createBuildingTour(waypoints: Array<{ pos: Vec3
|
|
344
|
+
static createBuildingTour(waypoints: Array<{ pos: Vec3; lookAt?: Vec3; duration?: number }>): CinimaticScript {
|
|
334
345
|
const points: CinimaticPoint[] = waypoints.map((wp, i) => ({
|
|
335
346
|
x: wp.pos.x,
|
|
336
347
|
y: wp.pos.y,
|
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
//@ts-nocheck
|
|
2
2
|
import {
|
|
3
|
+
assertDrawSpansWithinLiveRanges,
|
|
4
|
+
carveSpansAroundPendingRanges,
|
|
3
5
|
FULL_DRAW_VISIBLE_FRACTION,
|
|
4
6
|
MAX_OPAQUE_SPANS,
|
|
5
|
-
|
|
7
|
+
type DirtyRange
|
|
6
8
|
} from './globalLegacyBuffer'
|
|
7
9
|
|
|
8
|
-
export
|
|
9
|
-
export const SPAN_GAP_TOLERANCE_FACES = SPAN_GAP_TOLERANCE_QUADS
|
|
10
|
-
export { FULL_DRAW_VISIBLE_FRACTION }
|
|
10
|
+
export { FULL_DRAW_VISIBLE_FRACTION, MAX_OPAQUE_SPANS as MAX_CUBE_SPANS }
|
|
11
11
|
|
|
12
|
-
export type CubeDrawSpan = { start: number
|
|
12
|
+
export type CubeDrawSpan = { start: number; count: number }
|
|
13
13
|
|
|
14
|
-
export type VisibleCubeSlot = { start: number
|
|
14
|
+
export type VisibleCubeSlot = { start: number; count: number }
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
/** Merge only physically adjacent face ranges (gap === 0). Never bridge interior holes. */
|
|
17
|
+
function mergeCubeSpans(spans: CubeDrawSpan[]): void {
|
|
17
18
|
if (spans.length < 2) return
|
|
18
19
|
let i = 0
|
|
19
20
|
while (i < spans.length - 1) {
|
|
20
21
|
const cur = spans[i]!
|
|
21
22
|
const next = spans[i + 1]!
|
|
22
|
-
|
|
23
|
-
if (gap <= SPAN_GAP_TOLERANCE_FACES) {
|
|
23
|
+
if (cur.start + cur.count === next.start) {
|
|
24
24
|
cur.count = next.start + next.count - cur.start
|
|
25
25
|
spans.splice(i + 1, 1)
|
|
26
26
|
} else {
|
|
@@ -29,31 +29,16 @@ function mergeCubeSpans (spans: CubeDrawSpan[]): void {
|
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
function capCubeSpans (spans: CubeDrawSpan[]): void {
|
|
33
|
-
while (spans.length > MAX_CUBE_SPANS) {
|
|
34
|
-
let bestIdx = 0
|
|
35
|
-
let bestGap = Infinity
|
|
36
|
-
for (let i = 0; i < spans.length - 1; i++) {
|
|
37
|
-
const gap = spans[i + 1]!.start - (spans[i]!.start + spans[i]!.count)
|
|
38
|
-
if (gap < bestGap) {
|
|
39
|
-
bestGap = gap
|
|
40
|
-
bestIdx = i
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
const cur = spans[bestIdx]!
|
|
44
|
-
const next = spans[bestIdx + 1]!
|
|
45
|
-
cur.count = next.start + next.count - cur.start
|
|
46
|
-
spans.splice(bestIdx + 1, 1)
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
32
|
/**
|
|
51
|
-
* Merge
|
|
33
|
+
* Merge visible face-instance ranges for WEBGL_multi_draw (option B).
|
|
52
34
|
* Instance indices — no *6 scaling on span values.
|
|
53
35
|
*/
|
|
54
|
-
export function buildVisibleCubeSpans
|
|
36
|
+
export function buildVisibleCubeSpans(
|
|
55
37
|
visibleSlots: VisibleCubeSlot[],
|
|
56
38
|
highWatermark: number,
|
|
39
|
+
canFullDraw = true,
|
|
40
|
+
_isRangeUploaded?: (start: number, end: number) => boolean,
|
|
41
|
+
pendingRanges: ReadonlyArray<DirtyRange> = []
|
|
57
42
|
): CubeDrawSpan[] {
|
|
58
43
|
if (visibleSlots.length === 0 || highWatermark === 0) return []
|
|
59
44
|
|
|
@@ -62,13 +47,18 @@ export function buildVisibleCubeSpans (
|
|
|
62
47
|
visibleFaceCount += slot.count
|
|
63
48
|
}
|
|
64
49
|
|
|
65
|
-
|
|
66
|
-
|
|
50
|
+
let spans: CubeDrawSpan[]
|
|
51
|
+
const usedFullDraw = canFullDraw && visibleFaceCount >= highWatermark * FULL_DRAW_VISIBLE_FRACTION
|
|
52
|
+
if (usedFullDraw) {
|
|
53
|
+
spans = [{ start: 0, count: highWatermark }]
|
|
54
|
+
} else {
|
|
55
|
+
spans = visibleSlots.map(s => ({ start: s.start, count: s.count }))
|
|
56
|
+
spans.sort((a, b) => a.start - b.start)
|
|
57
|
+
const liveDrawRanges = spans.map(s => ({ ...s }))
|
|
58
|
+
mergeCubeSpans(spans)
|
|
59
|
+
spans = carveSpansAroundPendingRanges(spans, pendingRanges)
|
|
60
|
+
assertDrawSpansWithinLiveRanges(spans, liveDrawRanges, 'globalBlockBuffer')
|
|
61
|
+
return spans
|
|
67
62
|
}
|
|
68
|
-
|
|
69
|
-
const spans = visibleSlots.map(s => ({ start: s.start, count: s.count }))
|
|
70
|
-
spans.sort((a, b) => a.start - b.start)
|
|
71
|
-
mergeCubeSpans(spans)
|
|
72
|
-
capCubeSpans(spans)
|
|
73
|
-
return spans
|
|
63
|
+
return carveSpansAroundPendingRanges(spans, pendingRanges)
|
|
74
64
|
}
|
|
@@ -21,18 +21,12 @@ type MultiDrawInstancedExt = {
|
|
|
21
21
|
instanceCountsOffset: number,
|
|
22
22
|
baseInstances: Int32Array,
|
|
23
23
|
baseInstancesOffset: number,
|
|
24
|
-
drawCount: number
|
|
24
|
+
drawCount: number
|
|
25
25
|
) => void
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
type DrawInstancedBaseExt = {
|
|
29
|
-
drawArraysInstancedBaseInstanceWEBGL: (
|
|
30
|
-
mode: number,
|
|
31
|
-
first: number,
|
|
32
|
-
count: number,
|
|
33
|
-
instanceCount: number,
|
|
34
|
-
baseInstance: number,
|
|
35
|
-
) => void
|
|
29
|
+
drawArraysInstancedBaseInstanceWEBGL: (mode: number, first: number, count: number, instanceCount: number, baseInstance: number) => void
|
|
36
30
|
}
|
|
37
31
|
|
|
38
32
|
export type CubeMultiDrawScratch = {
|
|
@@ -42,16 +36,16 @@ export type CubeMultiDrawScratch = {
|
|
|
42
36
|
baseInstances: Int32Array
|
|
43
37
|
}
|
|
44
38
|
|
|
45
|
-
export function createCubeMultiDrawScratch
|
|
39
|
+
export function createCubeMultiDrawScratch(): CubeMultiDrawScratch {
|
|
46
40
|
return {
|
|
47
41
|
firsts: new Int32Array(MAX_CUBE_SPANS),
|
|
48
42
|
counts: new Int32Array(MAX_CUBE_SPANS),
|
|
49
43
|
instanceCounts: new Int32Array(MAX_CUBE_SPANS),
|
|
50
|
-
baseInstances: new Int32Array(MAX_CUBE_SPANS)
|
|
44
|
+
baseInstances: new Int32Array(MAX_CUBE_SPANS)
|
|
51
45
|
}
|
|
52
46
|
}
|
|
53
47
|
|
|
54
|
-
export function detectMultiDrawCaps
|
|
48
|
+
export function detectMultiDrawCaps(gl: WebGL2RenderingContext): MultiDrawCaps {
|
|
55
49
|
const tierA = gl.getExtension('WEBGL_multi_draw_instanced_base_vertex_base_instance')
|
|
56
50
|
if (tierA) {
|
|
57
51
|
return { tier: 'A', ext: tierA as MultiDrawInstancedExt }
|
|
@@ -65,7 +59,7 @@ export function detectMultiDrawCaps (gl: WebGL2RenderingContext): MultiDrawCaps
|
|
|
65
59
|
|
|
66
60
|
let tierLogged = false
|
|
67
61
|
|
|
68
|
-
export function logMultiDrawTierOnce
|
|
62
|
+
export function logMultiDrawTierOnce(tier: MultiDrawTier, debug: boolean): void {
|
|
69
63
|
if (tierLogged || !debug) return
|
|
70
64
|
tierLogged = true
|
|
71
65
|
console.info('[globalBlockBuffer] cube multi_draw tier', tier)
|
|
@@ -74,12 +68,12 @@ export function logMultiDrawTierOnce (tier: MultiDrawTier, debug: boolean): void
|
|
|
74
68
|
/**
|
|
75
69
|
* Issue instanced cube draws for visible spans. Tier C delegates to buffer-owned VAO path.
|
|
76
70
|
*/
|
|
77
|
-
export function drawCubeSpans
|
|
71
|
+
export function drawCubeSpans(
|
|
78
72
|
gl: WebGL2RenderingContext,
|
|
79
73
|
caps: MultiDrawCaps,
|
|
80
74
|
spans: readonly CubeDrawSpan[],
|
|
81
75
|
scratch: CubeMultiDrawScratch,
|
|
82
|
-
tierCDraw?: (gl: WebGL2RenderingContext, spans: readonly CubeDrawSpan[]) => void
|
|
76
|
+
tierCDraw?: (gl: WebGL2RenderingContext, spans: readonly CubeDrawSpan[]) => void
|
|
83
77
|
): void {
|
|
84
78
|
const drawCount = spans.length
|
|
85
79
|
if (drawCount === 0) return
|
|
@@ -95,14 +89,7 @@ export function drawCubeSpans (
|
|
|
95
89
|
scratch.instanceCounts[i] = span.count
|
|
96
90
|
scratch.baseInstances[i] = span.start
|
|
97
91
|
}
|
|
98
|
-
ext.multiDrawArraysInstancedBaseInstanceWEBGL(
|
|
99
|
-
mode,
|
|
100
|
-
scratch.firsts, 0,
|
|
101
|
-
scratch.counts, 0,
|
|
102
|
-
scratch.instanceCounts, 0,
|
|
103
|
-
scratch.baseInstances, 0,
|
|
104
|
-
drawCount,
|
|
105
|
-
)
|
|
92
|
+
ext.multiDrawArraysInstancedBaseInstanceWEBGL(mode, scratch.firsts, 0, scratch.counts, 0, scratch.instanceCounts, 0, scratch.baseInstances, 0, drawCount)
|
|
106
93
|
return
|
|
107
94
|
}
|
|
108
95
|
|
|
@@ -52,8 +52,7 @@ export interface ThreeRendererMainData {
|
|
|
52
52
|
canvas: OffscreenCanvas
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
export const isWebWorker = typeof (globalThis as any).WorkerGlobalScope !== 'undefined' &&
|
|
56
|
-
globalThis instanceof (globalThis as any).WorkerGlobalScope
|
|
55
|
+
export const isWebWorker = typeof (globalThis as any).WorkerGlobalScope !== 'undefined' && globalThis instanceof (globalThis as any).WorkerGlobalScope
|
|
57
56
|
|
|
58
57
|
// ============================================================================
|
|
59
58
|
// TopRightStats - Performance stats display
|
|
@@ -66,13 +65,15 @@ class TopRightStats {
|
|
|
66
65
|
private total = 0
|
|
67
66
|
private readonly denseMode: boolean
|
|
68
67
|
|
|
69
|
-
constructor(
|
|
68
|
+
constructor(
|
|
69
|
+
private readonly canvas: HTMLCanvasElement,
|
|
70
|
+
initialStatsVisible = 0
|
|
71
|
+
) {
|
|
70
72
|
this.stats = new Stats()
|
|
71
73
|
this.stats2 = new Stats()
|
|
72
74
|
this.statsGl = new StatsGl({ minimal: true })
|
|
73
75
|
this.stats2.showPanel(2)
|
|
74
|
-
this.denseMode = typeof process !== 'undefined' && process.env?.NODE_ENV === 'production' ||
|
|
75
|
-
(typeof window !== 'undefined' && window.innerHeight < 500)
|
|
76
|
+
this.denseMode = (typeof process !== 'undefined' && process.env?.NODE_ENV === 'production') || (typeof window !== 'undefined' && window.innerHeight < 500)
|
|
76
77
|
|
|
77
78
|
this.initStats()
|
|
78
79
|
this.setVisibility(initialStatsVisible)
|
|
@@ -176,10 +177,10 @@ export class DocumentRenderer {
|
|
|
176
177
|
disconnected = false
|
|
177
178
|
|
|
178
179
|
// Render hooks
|
|
179
|
-
preRender = () => {
|
|
180
|
-
render = (sizeChanged: boolean) => {
|
|
181
|
-
postRender = () => {
|
|
182
|
-
sizeChanged = () => {
|
|
180
|
+
preRender = () => {}
|
|
181
|
+
render = (sizeChanged: boolean) => {}
|
|
182
|
+
postRender = () => {}
|
|
183
|
+
sizeChanged = () => {}
|
|
183
184
|
|
|
184
185
|
droppedFpsPercentage = 0
|
|
185
186
|
config: GraphicsBackendConfig
|
|
@@ -210,9 +211,7 @@ export class DocumentRenderer {
|
|
|
210
211
|
powerPreference: gpuPreferenceToWebGLPowerPreference(gpuPreference)
|
|
211
212
|
})
|
|
212
213
|
} catch (err: any) {
|
|
213
|
-
initOptions.callbacks.displayCriticalError(
|
|
214
|
-
new Error(`Failed to create WebGL context, not possible to render (restart browser): ${err.message}`)
|
|
215
|
-
)
|
|
214
|
+
initOptions.callbacks.displayCriticalError(new Error(`Failed to create WebGL context, not possible to render (restart browser): ${err.message}`))
|
|
216
215
|
throw err
|
|
217
216
|
}
|
|
218
217
|
|
|
@@ -333,13 +332,12 @@ export class DocumentRenderer {
|
|
|
333
332
|
if (this.config.timeoutRendering) {
|
|
334
333
|
const targetFps = this.config.fpsLimit ? Math.min(this.config.fpsLimit, 60) : 60
|
|
335
334
|
const timeoutMs = 1000 / targetFps
|
|
336
|
-
|
|
335
|
+
;(this as any).timeoutId = setTimeout(animate, timeoutMs)
|
|
337
336
|
} else {
|
|
338
337
|
this.animationFrameId = requestAnimationFrame(animate)
|
|
339
338
|
}
|
|
340
339
|
|
|
341
|
-
if (this.paused ||
|
|
342
|
-
(this.renderer.xr.isPresenting && !this.inWorldRenderingConfig?.vrPageGameRendering)) {
|
|
340
|
+
if (this.paused || (this.renderer.xr.isPresenting && !this.inWorldRenderingConfig?.vrPageGameRendering)) {
|
|
343
341
|
return
|
|
344
342
|
}
|
|
345
343
|
|
|
@@ -364,8 +362,7 @@ export class DocumentRenderer {
|
|
|
364
362
|
this.pendingResize = false
|
|
365
363
|
}
|
|
366
364
|
|
|
367
|
-
if (this.previousCanvasWidth !== this.currentWidth ||
|
|
368
|
-
this.previousCanvasHeight !== this.currentHeight) {
|
|
365
|
+
if (this.previousCanvasWidth !== this.currentWidth || this.previousCanvasHeight !== this.currentHeight) {
|
|
369
366
|
this.previousCanvasWidth = this.currentWidth
|
|
370
367
|
this.previousCanvasHeight = this.currentHeight
|
|
371
368
|
this.sizeUpdated()
|
|
@@ -449,7 +446,7 @@ export const addCanvasForWorker = (): {
|
|
|
449
446
|
const canvas = addCanvasToPage()
|
|
450
447
|
const transferred = canvas.transferControlToOffscreen()
|
|
451
448
|
let removed = false
|
|
452
|
-
let onSizeChanged = (w: number, h: number) => {
|
|
449
|
+
let onSizeChanged = (w: number, h: number) => {}
|
|
453
450
|
let oldSize = { width: 0, height: 0 }
|
|
454
451
|
|
|
455
452
|
const checkSize = () => {
|