Skip to content

Commit 87e5ae2

Browse files
committed
simplify panorama, sfp fixes!
1 parent b8b1320 commit 87e5ae2

File tree

3 files changed

+23
-39
lines changed

3 files changed

+23
-39
lines changed

renderer/viewer/lib/worldrendererCommon.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,14 @@ export abstract class WorldRendererCommon<WorkerSend = any, WorkerReceive = any>
339339
this.version = version
340340
this.texturesVersion = texturesVersion
341341
this.resetWorld()
342+
343+
// for workers in single file build
344+
if (document.readyState === 'loading') {
345+
await new Promise(resolve => {
346+
document.addEventListener('DOMContentLoaded', resolve)
347+
})
348+
}
349+
342350
this.initWorkers()
343351
this.active = true
344352
this.mesherConfig.outputFormat = this.outputFormat

rsbuild.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ const appConfig = defineConfig({
208208
let html = fs.readFileSync(singleBuildHtml, 'utf8')
209209
const verToMajor = (ver: string) => ver.split('.').slice(0, 2).join('.')
210210
const supportedMajorVersions = [...new Set(supportedVersions.map(a => verToMajor(a)))].join(', ')
211-
html = `<!DOCTYPE html><!-- MINECRAFT WEB CLIENT ${releaseTag} -->\n<!-- A true SINGLE FILE BUILD with built-in server -->\n<!-- All textures, assets and Minecraft data for ${supportedMajorVersions} inlined into one file. -->\n${html}`
211+
html = `<!DOCTYPE html><!-- MINECRAFT WEB CLIENT ${releaseTag ?? ''} -->\n<!-- A true SINGLE FILE BUILD with built-in server -->\n<!-- All textures, assets and Minecraft data for ${supportedMajorVersions} inlined into one file. -->\n${html}`
212212

213213
const resizedImage = (await (sharp('./assets/favicon.png') as any).resize(64).toBuffer()).toString('base64')
214214
html = html.replace('favicon.png', `data:image/png;base64,${resizedImage}`)

src/panorama.ts

Lines changed: 14 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
11
//@ts-check
22

33
import { join } from 'path'
4-
import fs from 'fs'
54
import * as THREE from 'three'
6-
import { subscribeKey } from 'valtio/utils'
75
import { EntityMesh } from 'renderer/viewer/lib/entity/EntityMesh'
86
import { WorldDataEmitter } from 'renderer/viewer'
97
import { Vec3 } from 'vec3'
108
import { getSyncWorld } from 'renderer/playground/shared'
119
import * as tweenJs from '@tweenjs/tween.js'
12-
import { fromTexturePackPath, resourcePackState } from './resourcePack'
13-
import { options, watchValue } from './optionsStorage'
10+
import { subscribeKey } from 'valtio/utils'
11+
import { options } from './optionsStorage'
1412
import { miscUiState } from './globalState'
1513
import { loadMinecraftData } from './connect'
1614

1715
let panoramaCubeMap
1816
let shouldDisplayPanorama = false
19-
let panoramaUsesResourcePack = null as boolean | null
2017

2118
const panoramaFiles = [
2219
'panorama_3.png', // right (+x)
@@ -27,45 +24,17 @@ const panoramaFiles = [
2724
'panorama_2.png', // back (-z)
2825
]
2926

30-
const panoramaResourcePackPath = 'assets/minecraft/textures/gui/title/background'
31-
const possiblyLoadPanoramaFromResourcePack = async (file) => {
32-
let base64Texture
33-
if (panoramaUsesResourcePack) {
34-
try {
35-
// TODO!
36-
// base64Texture = await fs.promises.readFile(fromTexturePackPath(join(panoramaResourcePackPath, file)), 'base64')
37-
} catch (err) {
38-
panoramaUsesResourcePack = false
39-
}
40-
}
41-
if (base64Texture) return `data:image/png;base64,${base64Texture}`
42-
else return join('background', file)
43-
}
44-
45-
const updateResourcePackSupportPanorama = async () => {
46-
try {
47-
// TODO!
48-
// await fs.promises.readFile(fromTexturePackPath(join(panoramaResourcePackPath, panoramaFiles[0])), 'base64')
49-
// panoramaUsesResourcePack = true
50-
} catch (err) {
51-
panoramaUsesResourcePack = false
52-
}
53-
}
54-
55-
setTimeout(() => {
56-
// after viewer is initialized
57-
void addPanoramaCubeMap()
58-
}, 0)
59-
6027
let unloadPanoramaCallbacks = [] as Array<() => void>
6128

6229
// Menu panorama background
6330
// TODO-low use abort controller
6431
export async function addPanoramaCubeMap () {
6532
if (panoramaCubeMap || miscUiState.loadedDataVersion || options.disableAssets) return
33+
await new Promise(resolve => {
34+
setTimeout(resolve, 0) // wait for viewer to be initialized
35+
})
6636
viewer.camera.fov = 85
67-
await updateResourcePackSupportPanorama()
68-
if (process.env.SINGLE_FILE_BUILD_MODE && !panoramaUsesResourcePack) {
37+
if (process.env.SINGLE_FILE_BUILD_MODE) {
6938
void initDemoWorld()
7039
return
7140
}
@@ -82,7 +51,7 @@ export async function addPanoramaCubeMap () {
8251
const loader = new THREE.TextureLoader()
8352
const panorMaterials = [] as THREE.MeshBasicMaterial[]
8453
for (const file of panoramaFiles) {
85-
const texture = loader.load(await possiblyLoadPanoramaFromResourcePack(file))
54+
const texture = loader.load(join('background', file))
8655

8756
// Instead of using repeat/offset to flip, we'll use the texture matrix
8857
texture.matrixAutoUpdate = false
@@ -133,6 +102,13 @@ export async function addPanoramaCubeMap () {
133102
panoramaCubeMap = group
134103
}
135104

105+
subscribeKey(miscUiState, 'fsReady', () => {
106+
if (miscUiState.fsReady) {
107+
// don't do it earlier to load fs and display menu faster
108+
void addPanoramaCubeMap()
109+
}
110+
})
111+
136112
export function removePanorama () {
137113
for (const unloadPanoramaCallback of unloadPanoramaCallbacks) {
138114
unloadPanoramaCallback()

0 commit comments

Comments
 (0)