minecraft-renderer 0.1.53 → 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.
@@ -0,0 +1,15 @@
1
+ //@ts-nocheck
2
+ export function menuBackgroundAssetUrl (...segments: string[]): string {
3
+ const relative = segments.filter(s => s.length > 0).join('/')
4
+ const base =
5
+ typeof globalThis.location !== 'undefined' && globalThis.location.href
6
+ ? globalThis.location.href
7
+ : typeof import.meta !== 'undefined' && import.meta.url
8
+ ? import.meta.url
9
+ : `/${relative}`
10
+ try {
11
+ return new URL(relative, base).href
12
+ } catch {
13
+ return `/${relative}`
14
+ }
15
+ }
@@ -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
  }
@@ -123,7 +123,9 @@ function shaderMaterialForExport(legacyMaterial: THREE.Material): THREE.ShaderMa
123
123
  if (!atlas) return null
124
124
  const shaderMat = createCubeBlockMaterial()
125
125
  shaderMat.uniforms.u_atlas.value = atlas
126
- const { tintPalette } = getShaderCubeResources()
126
+ const resources = getShaderCubeResources()
127
+ if (!resources) return null
128
+ const { tintPalette } = resources
127
129
  if (!tintPalette.isReady()) tintPalette.createTexture()
128
130
  shaderMat.uniforms.u_tintPalette.value = tintPalette.getTexture()
129
131
  return shaderMat
@@ -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
  }
@@ -81,6 +81,7 @@ export interface ShaderCubeModelInput {
81
81
 
82
82
  let tintPalette: TintPalette | null = null
83
83
  let textureIndexMapping: TextureIndexMapping | null = null
84
+ let tintsMissingWarned = false
84
85
 
85
86
  /** Convert mc-assets texture scales (normalized or negative) to pixel tile size for index lookup. */
86
87
  function normalizeTextureEntryForTileIndex(
@@ -122,10 +123,14 @@ export function resolveFaceTileIndex(
122
123
  }
123
124
 
124
125
  /** Main thread + worker: use `loadedData` set by the app / mesher (see mesherWasm). */
125
- function getTintsJson(): Record<string, any> {
126
+ function getTintsJson(): Record<string, any> | null {
126
127
  const tints = (globalThis as any).loadedData?.tints
127
128
  if (!tints) {
128
- throw new Error('shaderCubeBridge: globalThis.loadedData.tints is not available yet')
129
+ if (!tintsMissingWarned) {
130
+ tintsMissingWarned = true
131
+ console.warn('[shaderCubeBridge] loadedData.tints missing; shader cubes use legacy path')
132
+ }
133
+ return null
129
134
  }
130
135
  return tints
131
136
  }
@@ -133,9 +138,13 @@ function getTintsJson(): Record<string, any> {
133
138
  export function getShaderCubeResources(): {
134
139
  tintPalette: TintPalette
135
140
  textureIndexMapping: TextureIndexMapping
136
- } {
141
+ } | null {
142
+ const tintsData = getTintsJson()
143
+ if (!tintsData) {
144
+ return null
145
+ }
137
146
  if (!tintPalette) {
138
- tintPalette = TintPalette.fromTintsData(getTintsJson())
147
+ tintPalette = TintPalette.fromTintsData(tintsData)
139
148
  tintPalette.createTexture()
140
149
  }
141
150
  if (!textureIndexMapping) {
@@ -155,6 +164,7 @@ export function getShaderCubeResources(): {
155
164
  export function resetShaderCubeResources(): void {
156
165
  tintPalette = null
157
166
  textureIndexMapping = null
167
+ tintsMissingWarned = false
158
168
  }
159
169
 
160
170
  /**
@@ -358,3 +358,12 @@ test('GlobalBlockBuffer: free-list reuses slot with EMPTY sentinel', () => {
358
358
  buffer.dispose()
359
359
  mat.dispose()
360
360
  })
361
+
362
+ test('getShaderCubeResources: returns null without loadedData.tints (no throw)', () => {
363
+ const prev = (globalThis as any).loadedData
364
+ ;(globalThis as any).loadedData = {}
365
+ resetShaderCubeResources()
366
+ expect(getShaderCubeResources()).toBeNull()
367
+ ;(globalThis as any).loadedData = prev
368
+ resetShaderCubeResources()
369
+ })