11//@ts -check
22
33import { join } from 'path'
4- import fs from 'fs'
54import * as THREE from 'three'
6- import { subscribeKey } from 'valtio/utils'
75import { EntityMesh } from 'renderer/viewer/lib/entity/EntityMesh'
86import { WorldDataEmitter } from 'renderer/viewer'
97import { Vec3 } from 'vec3'
108import { getSyncWorld } from 'renderer/playground/shared'
119import * 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'
1412import { miscUiState } from './globalState'
1513import { loadMinecraftData } from './connect'
1614
1715let panoramaCubeMap
1816let shouldDisplayPanorama = false
19- let panoramaUsesResourcePack = null as boolean | null
2017
2118const 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-
6027let unloadPanoramaCallbacks = [ ] as Array < ( ) => void >
6128
6229// Menu panorama background
6330// TODO-low use abort controller
6431export 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+
136112export function removePanorama ( ) {
137113 for ( const unloadPanoramaCallback of unloadPanoramaCallbacks ) {
138114 unloadPanoramaCallback ( )
0 commit comments