minecraft-renderer 0.1.34 → 0.1.36
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/dist/mesher.js +64 -64
- package/dist/mesher.js.map +3 -3
- package/dist/mesherWasm.js +1 -1
- package/dist/minecraft-renderer.js +55 -55
- package/dist/minecraft-renderer.js.meta.json +1 -1
- package/dist/threeWorker.js +363 -363
- package/package.json +1 -1
- package/src/graphicsBackend/config.ts +6 -1
- package/src/graphicsBackend/playerState.ts +1 -0
- package/src/lib/worldrendererCommon.ts +8 -0
- package/src/mesher/models.ts +15 -6
- package/src/mesher/shared.ts +3 -1
- package/src/playerState/playerState.ts +2 -0
- package/src/playground/scenes/main.ts +1 -1
- package/src/three/chunkMeshManager.ts +808 -0
- package/src/three/entities.ts +42 -36
- package/src/three/graphicsBackendBase.ts +1 -1
- package/src/three/modules/sciFiWorldReveal.ts +10 -21
- package/src/three/panorama.ts +1 -1
- package/src/three/worldRendererThree.ts +65 -40
- package/src/three/worldBlockGeometry.ts +0 -355
package/package.json
CHANGED
|
@@ -19,7 +19,7 @@ export const defaultWorldRendererConfig = {
|
|
|
19
19
|
|
|
20
20
|
// Debug settings
|
|
21
21
|
showChunkBorders: false,
|
|
22
|
-
enableDebugOverlay:
|
|
22
|
+
enableDebugOverlay: true,
|
|
23
23
|
debugModelVariant: undefined as undefined | number[],
|
|
24
24
|
futuristicReveal: false,
|
|
25
25
|
|
|
@@ -29,8 +29,13 @@ export const defaultWorldRendererConfig = {
|
|
|
29
29
|
addChunksBatchWaitTime: 200,
|
|
30
30
|
_experimentalSmoothChunkLoading: true,
|
|
31
31
|
_renderByChunks: false,
|
|
32
|
+
autoLowerRenderDistance: false,
|
|
32
33
|
|
|
33
34
|
// Rendering engine settings
|
|
35
|
+
/** Face shading: vanilla Minecraft vs higher-contrast client look */
|
|
36
|
+
shadingTheme: 'high-contrast' as 'vanilla' | 'high-contrast',
|
|
37
|
+
/** Synced from player reactive state (dimension / nether) — consumed by mesher */
|
|
38
|
+
cardinalLight: 'default' as string,
|
|
34
39
|
dayCycle: true,
|
|
35
40
|
smoothLighting: true,
|
|
36
41
|
enableLighting: true,
|
|
@@ -77,6 +77,7 @@ export abstract class WorldRendererCommon<WorkerSend = any, WorkerReceive = any>
|
|
|
77
77
|
enableChunksLoadDelay = false
|
|
78
78
|
texturesVersion?: string
|
|
79
79
|
viewDistance = -1
|
|
80
|
+
onRenderDistanceChanged?: (viewDistance: number) => void
|
|
80
81
|
chunksLength = 0
|
|
81
82
|
allChunksFinished = false
|
|
82
83
|
messageQueue: any[] = []
|
|
@@ -123,6 +124,7 @@ export abstract class WorldRendererCommon<WorkerSend = any, WorkerReceive = any>
|
|
|
123
124
|
soundSystem: SoundSystem | undefined
|
|
124
125
|
|
|
125
126
|
abstract changeBackgroundColor(color: [number, number, number]): void
|
|
127
|
+
abstract changeCardinalLight(cardinalLight: string): void
|
|
126
128
|
|
|
127
129
|
/** Override in subclass to check if any enabled module requires heightmap data */
|
|
128
130
|
protected anyModuleRequiresHeightmap(): boolean {
|
|
@@ -309,6 +311,9 @@ export abstract class WorldRendererCommon<WorkerSend = any, WorkerReceive = any>
|
|
|
309
311
|
this.onReactivePlayerStateUpdated('backgroundColor', (value) => {
|
|
310
312
|
this.changeBackgroundColor(value)
|
|
311
313
|
})
|
|
314
|
+
this.onReactivePlayerStateUpdated('cardinalLight', (value) => {
|
|
315
|
+
this.changeCardinalLight(value)
|
|
316
|
+
})
|
|
312
317
|
}
|
|
313
318
|
|
|
314
319
|
watchReactiveConfig() {
|
|
@@ -548,6 +553,8 @@ export abstract class WorldRendererCommon<WorkerSend = any, WorkerReceive = any>
|
|
|
548
553
|
enableLighting: this.worldRendererConfig.enableLighting,
|
|
549
554
|
skyLight,
|
|
550
555
|
smoothLighting: this.worldRendererConfig.smoothLighting,
|
|
556
|
+
shadingTheme: this.worldRendererConfig.shadingTheme,
|
|
557
|
+
cardinalLight: this.worldRendererConfig.cardinalLight,
|
|
551
558
|
outputFormat: this.outputFormat,
|
|
552
559
|
// textureSize: this.resourcesManager.currentResources!.blocksAtlasParser.atlas.latest.width,
|
|
553
560
|
debugModelVariant: this.worldRendererConfig.debugModelVariant,
|
|
@@ -813,6 +820,7 @@ export abstract class WorldRendererCommon<WorkerSend = any, WorkerReceive = any>
|
|
|
813
820
|
this.viewDistance = d
|
|
814
821
|
this.chunksLength = d === 0 ? 1 : generateSpiralMatrix(d).length
|
|
815
822
|
this.allChunksFinished = Object.keys(this.finishedChunks).length === this.chunksLength
|
|
823
|
+
this.onRenderDistanceChanged?.(d)
|
|
816
824
|
})
|
|
817
825
|
|
|
818
826
|
worldEmitter.on('markAsLoaded', ({ x, z }) => {
|
package/src/mesher/models.ts
CHANGED
|
@@ -395,7 +395,16 @@ function renderElement(world: World, cursor: Vec3, element: BlockElement, doAO:
|
|
|
395
395
|
const aos: number[] = []
|
|
396
396
|
const neighborPos = position.plus(new Vec3(...dir))
|
|
397
397
|
// 10%
|
|
398
|
-
const
|
|
398
|
+
const { smoothLighting, shadingTheme, cardinalLight } = world.config
|
|
399
|
+
const faceLight = world.getLight(neighborPos, undefined, undefined, block.name)
|
|
400
|
+
const sideShading = (shadingTheme === 'high-contrast')
|
|
401
|
+
? (0.8 + 0.5 * Math.max(0, 0.66 * dir[0] + 0.66 * dir[1] + 0.33 * dir[2])) // old directional light behavior
|
|
402
|
+
: (
|
|
403
|
+
cardinalLight === 'nether'
|
|
404
|
+
? (0.5 + Math.abs(0.1 * dir[0] + 0.4 * dir[1] + 0.3 * dir[2]))
|
|
405
|
+
: (0.75 + 0.25 * dir[1] + 0.05 * (Math.abs(dir[2]) - 3 * Math.abs(dir[0])))
|
|
406
|
+
)
|
|
407
|
+
const baseLight = sideShading * faceLight / 15
|
|
399
408
|
for (const pos of corners) {
|
|
400
409
|
let vertex = [
|
|
401
410
|
(pos[0] ? maxx : minx),
|
|
@@ -429,8 +438,6 @@ function renderElement(world: World, cursor: Vec3, element: BlockElement, doAO:
|
|
|
429
438
|
}
|
|
430
439
|
|
|
431
440
|
let light = 1
|
|
432
|
-
const { smoothLighting } = world.config
|
|
433
|
-
// const smoothLighting = true
|
|
434
441
|
if (doAO) {
|
|
435
442
|
const dx = pos[0] * 2 - 1
|
|
436
443
|
const dy = pos[1] * 2 - 1
|
|
@@ -442,7 +449,7 @@ function renderElement(world: World, cursor: Vec3, element: BlockElement, doAO:
|
|
|
442
449
|
const side2 = world.getBlock(cursor.offset(...side2Dir))
|
|
443
450
|
const corner = world.getBlock(cursor.offset(...cornerDir))
|
|
444
451
|
|
|
445
|
-
let cornerLightResult =
|
|
452
|
+
let cornerLightResult = faceLight
|
|
446
453
|
|
|
447
454
|
if (smoothLighting) {
|
|
448
455
|
const dirVec = new Vec3(...dir)
|
|
@@ -459,7 +466,7 @@ function renderElement(world: World, cursor: Vec3, element: BlockElement, doAO:
|
|
|
459
466
|
const cornerLightDir = getVec(new Vec3(...cornerDir))
|
|
460
467
|
const cornerLight = world.getLight(cursor.plus(cornerLightDir))
|
|
461
468
|
// interpolate
|
|
462
|
-
const lights = [side1Light, side2Light, cornerLight,
|
|
469
|
+
const lights = [side1Light, side2Light, cornerLight, faceLight]
|
|
463
470
|
cornerLightResult = lights.reduce((acc, cur) => acc + cur, 0) / lights.length
|
|
464
471
|
}
|
|
465
472
|
|
|
@@ -470,8 +477,10 @@ function renderElement(world: World, cursor: Vec3, element: BlockElement, doAO:
|
|
|
470
477
|
// TODO: correctly interpolate ao light based on pos (evaluate once for each corner of the block)
|
|
471
478
|
|
|
472
479
|
const ao = (side1Block && side2Block) ? 0 : (3 - (side1Block + side2Block + cornerBlock))
|
|
480
|
+
const ao_bias = (shadingTheme === 'high-contrast') ? 0.25 : 0.4
|
|
481
|
+
const ao_scale = (shadingTheme === 'high-contrast') ? 0.25 : 0.2
|
|
473
482
|
// todo light should go upper on lower blocks
|
|
474
|
-
light = (ao +
|
|
483
|
+
light = sideShading * (ao * ao_scale + ao_bias) * (cornerLightResult / 15)
|
|
475
484
|
aos.push(ao)
|
|
476
485
|
|
|
477
486
|
// Log AO and light for this corner (corner index is aos.length - 1)
|
package/src/mesher/shared.ts
CHANGED
|
@@ -11,7 +11,9 @@ export const defaultMesherConfig = {
|
|
|
11
11
|
worldMinY: 0,
|
|
12
12
|
enableLighting: true,
|
|
13
13
|
skyLight: 15,
|
|
14
|
-
smoothLighting:
|
|
14
|
+
smoothLighting: true,
|
|
15
|
+
shadingTheme: 'high-contrast' as 'vanilla' | 'high-contrast',
|
|
16
|
+
cardinalLight: 'default' as string,
|
|
15
17
|
outputFormat: 'threeJs' as 'threeJs' | 'webgpu',
|
|
16
18
|
// textureSize: 1024, // for testing
|
|
17
19
|
debugModelVariant: undefined as undefined | number[],
|
|
@@ -39,6 +39,8 @@ export const getInitialPlayerState = () => proxy({
|
|
|
39
39
|
itemUsageTicks: 0,
|
|
40
40
|
username: '',
|
|
41
41
|
onlineMode: false,
|
|
42
|
+
/** Dimension ambient lighting preset (e.g. nether) — from login/respawn dimension data when available */
|
|
43
|
+
cardinalLight: 'default' as string,
|
|
42
44
|
lightingDisabled: false,
|
|
43
45
|
shouldHideHand: false,
|
|
44
46
|
heldItemMain: undefined as HandItemBlock | undefined,
|
|
@@ -219,7 +219,7 @@ class MainScene extends BasePlaygroundScene {
|
|
|
219
219
|
|
|
220
220
|
// Temporarily replace PerspectiveCamera with OrthographicCamera for block rendering
|
|
221
221
|
this.worldRenderer.camera = new THREE.OrthographicCamera(-1, 1, 1, -1, 0, 10) as any
|
|
222
|
-
this.worldRenderer.
|
|
222
|
+
this.worldRenderer.realScene.background = null
|
|
223
223
|
|
|
224
224
|
const rad = THREE.MathUtils.degToRad(-120)
|
|
225
225
|
this.worldRenderer.directionalLight.position.set(
|