minecraft-renderer 0.1.74 → 0.1.76

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.
@@ -2,12 +2,10 @@
2
2
  import * as THREE from 'three'
3
3
  import { Vec3 } from 'vec3'
4
4
  import nbt from 'prismarine-nbt'
5
- import PrismarineChatLoader from 'prismarine-chat'
6
5
  import * as tweenJs from '@tweenjs/tween.js'
7
6
  import { Biome } from 'minecraft-data'
8
- import { renderSign } from '../sign-renderer'
9
7
  import { DisplayWorldOptions, GraphicsInitOptions } from '../graphicsBackend/types'
10
- import { chunkPos, sectionPos } from '../lib/simpleUtils'
8
+ import { sectionPos } from '../lib/simpleUtils'
11
9
  import { WorldRendererCommon } from '../lib/worldrendererCommon'
12
10
  import { calculateSkyLightSimple } from '../lib/skyLight'
13
11
  import { addNewStat, MC_RENDERER_DEBUG_OVERLAY_CLASS } from '../lib/ui/newStats'
@@ -55,8 +53,6 @@ export class WorldRendererThree extends WorldRendererCommon {
55
53
  get sectionObjects() {
56
54
  return this.chunkMeshManager.sectionObjects
57
55
  }
58
- chunkTextures = new Map<string, { [pos: string]: THREE.Texture }>()
59
- signsCache = new Map<string, any>()
60
56
  cameraSectionPos: Vec3 = new Vec3(0, 0, 0)
61
57
  holdingBlock: IHoldingBlock
62
58
  holdingBlockLeft: IHoldingBlock
@@ -762,11 +758,20 @@ export class WorldRendererThree extends WorldRendererCommon {
762
758
  const formatCompact = (num: number) => new Intl.NumberFormat('en-US', { notation: 'compact', maximumFractionDigits: 1 }).format(num)
763
759
  let text = ''
764
760
  text += `TE: ${formatFull(this.renderer.info.memory.textures)} `
765
- text += `F: ${formatCompact(this.tilesRendered)} `
766
- text += `B: ${formatCompact(this.blocksRendered)} `
761
+ const gb = this.chunkMeshManager.getGlobalBufferStats()
762
+ if (gb.shaderFaces) {
763
+ const s = gb.shaderFaces
764
+ text += `CUBE: ${formatCompact(s.used)}/${formatCompact(s.capacity)}f `
765
+ }
766
+ if (gb.legacyOpaque) {
767
+ const s = gb.legacyOpaque
768
+ text += `LEG-O: ${formatCompact(s.used)}/${formatCompact(s.capacity)}q `
769
+ }
770
+ if (gb.legacyBlend) {
771
+ const s = gb.legacyBlend
772
+ text += `LEG-B: ${formatCompact(s.used)}/${formatCompact(s.capacity)}q `
773
+ }
767
774
  text += `MEM: ${this.chunkMeshManager.getEstimatedMemoryUsage().total} `
768
- const poolStats = this.chunkMeshManager.getStats()
769
- text += `POOL: ${poolStats.activeCount}/${poolStats.poolSize} `
770
775
  const pf = formatPerformanceFactorsDebug(this.reactiveState.world.instabilityFactors)
771
776
  if (pf) text += `PF: ${pf} `
772
777
  // entities can be seen in F3
@@ -929,28 +934,6 @@ export class WorldRendererThree extends WorldRendererCommon {
929
934
  }
930
935
 
931
936
 
932
- getSignTexture(position: Vec3, blockEntity, isHanging, backSide = false) {
933
- const chunk = chunkPos(position)
934
- let textures = this.chunkTextures.get(`${chunk[0]},${chunk[1]}`)
935
- if (!textures) {
936
- textures = {}
937
- this.chunkTextures.set(`${chunk[0]},${chunk[1]}`, textures)
938
- }
939
- const texturekey = `${position.x},${position.y},${position.z}`
940
- // todo investigate bug and remove this so don't need to clean in section dirty
941
- if (textures[texturekey]) return textures[texturekey]
942
-
943
- const PrismarineChat = PrismarineChatLoader(this.version)
944
- const canvas = renderSign(blockEntity, isHanging, PrismarineChat)
945
- if (!canvas) return
946
- const tex = new THREE.Texture(canvas)
947
- tex.magFilter = THREE.NearestFilter
948
- tex.minFilter = THREE.NearestFilter
949
- tex.needsUpdate = true
950
- textures[texturekey] = tex
951
- return tex
952
- }
953
-
954
937
  getCameraPosition(target?: THREE.Vector3): THREE.Vector3 {
955
938
  return (target ?? this._tmpCameraPos).set(this.cameraWorldPos.x, this.cameraWorldPos.y, this.cameraWorldPos.z)
956
939
  }
@@ -1443,49 +1426,6 @@ export class WorldRendererThree extends WorldRendererCommon {
1443
1426
  }
1444
1427
  }
1445
1428
 
1446
- renderSign(position: Vec3, rotation: number, isWall: boolean, isHanging: boolean, blockEntity) {
1447
- const tex = this.getSignTexture(position, blockEntity, isHanging)
1448
-
1449
- if (!tex) return
1450
-
1451
- // todo implement
1452
- // const key = JSON.stringify({ position, rotation, isWall })
1453
- // if (this.signsCache.has(key)) {
1454
- // console.log('cached', key)
1455
- // } else {
1456
- // this.signsCache.set(key, tex)
1457
- // }
1458
-
1459
- const mesh = new THREE.Mesh(new THREE.PlaneGeometry(1, 1), new THREE.MeshBasicMaterial({ map: tex, transparent: true }))
1460
- mesh.renderOrder = 999
1461
-
1462
- const lineHeight = 7 / 16
1463
- const scaleFactor = isHanging ? 1.3 : 1
1464
- mesh.scale.set(1 * scaleFactor, lineHeight * scaleFactor, 1 * scaleFactor)
1465
-
1466
- const thickness = (isHanging ? 2 : 1.5) / 16
1467
- const wallSpacing = 0.25 / 16
1468
- if (isWall && !isHanging) {
1469
- mesh.position.set(0, 0, -0.5 + thickness + wallSpacing + 0.0001)
1470
- } else {
1471
- mesh.position.set(0, 0, thickness / 2 + 0.0001)
1472
- }
1473
-
1474
- const group = new THREE.Group()
1475
- group.rotation.set(
1476
- 0,
1477
- -THREE.MathUtils.degToRad(rotation * (isWall ? 90 : 45 / 2)),
1478
- 0
1479
- )
1480
- group.add(mesh)
1481
- const height = (isHanging ? 10 : 8) / 16
1482
- const heightOffset = (isHanging ? 0 : isWall ? 4.333 : 9.333) / 16
1483
- const textPosition = height / 2 + heightOffset
1484
- this.sceneOrigin.track(group)
1485
- group.position.set(position.x + 0.5, position.y + textPosition, position.z + 0.5)
1486
- return group
1487
- }
1488
-
1489
1429
  lightUpdate(chunkX: number, chunkZ: number) {
1490
1430
  // set all sections in the chunk dirty
1491
1431
  for (let y = this.worldSizeParams.minY; y < this.worldSizeParams.worldHeight; y += 16) {
@@ -1535,19 +1475,6 @@ export class WorldRendererThree extends WorldRendererCommon {
1535
1475
  }))
1536
1476
  }
1537
1477
 
1538
- cleanChunkTextures(x, z) {
1539
- const textures = this.chunkTextures.get(`${Math.floor(x / 16)},${Math.floor(z / 16)}`) ?? {}
1540
- for (const key of Object.keys(textures)) {
1541
- textures[key].dispose()
1542
- delete textures[key]
1543
- }
1544
- // Sign / head textures moved to ChunkMeshManager.signHeadsRenderer in PR
1545
- // #16; without invalidating that cache here, sign edits (and any other
1546
- // block-entity NBT change picked up via setSectionDirty) would re-render
1547
- // with the stale cached canvas until a full world reset.
1548
- this.chunkMeshManager.cleanSignChunkTextures(x, z)
1549
- }
1550
-
1551
1478
  readdChunks() {
1552
1479
  for (const key of Object.keys(this.sectionObjects)) {
1553
1480
  this.scene.remove(this.sectionObjects[key])
@@ -1569,7 +1496,6 @@ export class WorldRendererThree extends WorldRendererCommon {
1569
1496
  removeColumn(x, z) {
1570
1497
  super.removeColumn(x, z)
1571
1498
 
1572
- this.cleanChunkTextures(x, z)
1573
1499
  this.clearPendingSectionUpdatesForChunk(x, z)
1574
1500
  const sectionHeight = this.getSectionHeight()
1575
1501
  const worldMinY = this.worldMinYRender