minecraft-renderer 0.1.54 → 0.1.55

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.
@@ -1,11 +1,12 @@
1
1
  //@ts-nocheck
2
- import { join } from 'path'
3
2
  import * as THREE from 'three'
4
3
  import { EntityMesh } from '../entity/EntityMesh'
4
+ import { loadImageFromUrl } from '../../lib/utils'
5
5
  import type { DocumentRenderer } from '../documentRenderer'
6
- import { loadThreeJsTextureFromUrl, loadThreeJsTextureFromUrlSync } from '../threeJsUtils'
6
+ import { loadThreeJsTextureFromBitmap } from '../threeJsUtils'
7
7
  import type { MenuBackgroundView } from './activeView'
8
8
  import { resizeMenuBackgroundCamera } from './activeView'
9
+ import { menuBackgroundAssetUrl } from './assetUrl'
9
10
 
10
11
  const date = new Date()
11
12
  const isChristmas = date.getMonth() === 11 && date.getDate() >= 24 && date.getDate() <= 26
@@ -75,7 +76,9 @@ export class ClassicMenuBackground implements MenuBackgroundView {
75
76
 
76
77
  for (const file of panoramaFiles) {
77
78
  const load = async () => {
78
- const { texture } = loadThreeJsTextureFromUrlSync(join('background', isChristmas ? 'christmas' : '', file))
79
+ const url = menuBackgroundAssetUrl('background', isChristmas ? 'christmas' : '', file)
80
+ const bitmap = await loadImageFromUrl(url)
81
+ const texture = loadThreeJsTextureFromBitmap(bitmap)
79
82
 
80
83
  texture.matrixAutoUpdate = false
81
84
  texture.matrix.set(-1, 0, 1, 0, 1, 0, 0, 0, 1)
@@ -96,7 +99,9 @@ export class ClassicMenuBackground implements MenuBackgroundView {
96
99
  panorMaterials.push(material)
97
100
  }
98
101
 
99
- void load()
102
+ void load().catch(err => {
103
+ console.warn('[ClassicMenuBackground] Failed to load panorama face:', file, err)
104
+ })
100
105
  }
101
106
 
102
107
  const panoramaBox = new THREE.Mesh(panorGeo, panorMaterials)
@@ -137,7 +142,8 @@ export class ClassicMenuBackground implements MenuBackgroundView {
137
142
 
138
143
  /** Debug helper: flat cubemap face in front of the camera. */
139
144
  async debugImageInFrontOfCamera() {
140
- const image = await loadThreeJsTextureFromUrl(join('background', 'panorama_0.webp'))
145
+ const bitmap = await loadImageFromUrl(menuBackgroundAssetUrl('background', 'panorama_0.webp'))
146
+ const image = loadThreeJsTextureFromBitmap(bitmap)
141
147
  const mesh = new THREE.Mesh(
142
148
  new THREE.PlaneGeometry(1000, 1000),
143
149
  new THREE.MeshBasicMaterial({ map: image })
@@ -632,6 +632,9 @@ export class FuturisticMenuBackground implements MenuBackgroundView {
632
632
  const resourcesManager = this.resourcesManager ?? new ResourcesManager()
633
633
  const needsAssetUpdate = !resourcesManager.currentResources?.blocksAtlasImage
634
634
  if (needsAssetUpdate) {
635
+ if (typeof document === 'undefined') {
636
+ throw new Error('Menu atlas missing in worker; pass resourcesManager from main thread')
637
+ }
635
638
  resourcesManager.currentConfig = {
636
639
  ...resourcesManager.currentConfig,
637
640
  version: MENU_BACKGROUND_MC_VERSION,
@@ -1,30 +1,31 @@
1
1
  //@ts-nocheck
2
- // Three.js Worker Entry Point
3
- // This worker handles three.js rendering in an offscreen canvas
2
+ import { augmentWorkerMcData } from '../lib/buildWorkerMcDataIndexes'
4
3
 
5
4
  globalThis.structuredClone ??= (value) => JSON.parse(JSON.stringify(value))
6
5
 
7
- // Handle mcData messages - needed for esbuild plugin to access globalThis.mcData
8
- // Use addEventListener to coexist with worker proxy's message handler
6
+ const applyWorkerMcData = (raw: Record<string, unknown>) => {
7
+ augmentWorkerMcData(raw)
8
+ const globalVar: any = globalThis
9
+ globalVar.mcData = raw
10
+ globalVar.loadedData = raw
11
+ // eslint-disable-next-line no-restricted-globals
12
+ self.postMessage({ type: 'mcDataApplied' })
13
+ }
14
+
9
15
  // eslint-disable-next-line no-restricted-globals
10
16
  self.addEventListener('message', (event: MessageEvent) => {
11
17
  const data = event.data
12
- const globalVar: any = globalThis
13
-
14
18
  if (data.type === 'mcData') {
15
- globalVar.mcData = data.mcData
16
- globalVar.loadedData = data.mcData
19
+ applyWorkerMcData(data.mcData)
17
20
  console.log('data loaded')
18
21
  return
19
22
  }
20
23
 
21
- // Handle array of messages (batch mode)
22
24
  if (Array.isArray(data)) {
23
25
  // eslint-disable-next-line unicorn/no-array-for-each
24
26
  data.forEach((msg) => {
25
27
  if (msg.type === 'mcData') {
26
- globalVar.mcData = msg.mcData
27
- globalVar.loadedData = msg.mcData
28
+ applyWorkerMcData(msg.mcData)
28
29
  }
29
30
  })
30
31
  }
@@ -1510,6 +1510,13 @@ export class WorldRendererThree extends WorldRendererCommon {
1510
1510
  this.chunkMeshManager.onChunkRemovedFromGate(`${x},${z}`)
1511
1511
  }
1512
1512
 
1513
+ updateViewerPosition(pos: Vec3) {
1514
+ super.updateViewerPosition(pos)
1515
+ if (this.chunkMeshManager.pendingNearReveal.size > 0) {
1516
+ this.chunkMeshManager.tryRevealPending()
1517
+ }
1518
+ }
1519
+
1513
1520
  protected onViewerChunkPositionChanged(): void {
1514
1521
  this.chunkMeshManager.tryRevealPending()
1515
1522
  }