Skip to content

Commit f8ef748

Browse files
committed
fix: disable chunk batch display by default because of incorrect order and its too slow
1 parent f161fd3 commit f8ef748

File tree

6 files changed

+113
-57
lines changed

6 files changed

+113
-57
lines changed

renderer/viewer/lib/worldrendererCommon.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ export const defaultWorldRendererConfig = {
4545
fetchPlayerSkins: true,
4646
highlightBlockColor: 'blue',
4747
foreground: true,
48-
_experimentalSmoothChunkLoading: true
48+
_experimentalSmoothChunkLoading: true,
49+
_renderByChunks: false
4950
}
5051

5152
export type WorldRendererConfig = typeof defaultWorldRendererConfig

renderer/viewer/three/documentRenderer.ts

+4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export class DocumentRenderer {
2222
sizeChanged = () => { }
2323
droppedFpsPercentage: number
2424
config: GraphicsBackendConfig
25+
onRender = [] as Array<(sizeChanged: boolean) => void>
2526

2627
constructor (initOptions: GraphicsInitOptions) {
2728
this.config = initOptions.config
@@ -120,6 +121,9 @@ export class DocumentRenderer {
120121
this.stats.markStart()
121122
tween.update()
122123
this.render(sizeChanged)
124+
for (const fn of this.onRender) {
125+
fn(sizeChanged)
126+
}
123127
this.renderedFps++
124128
this.stats.markEnd()
125129
this.postRender()

renderer/viewer/three/panorama.ts

+95-48
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,57 @@ export class PanoramaRenderer {
6969
}
7070

7171
addClassicPanorama () {
72-
const classicPanorama = new ClassicPanoramaRenderer(panoramaFiles.map(file => join('background', file)))
73-
classicPanorama.panoramaGroup.onBeforeRender = () => {
72+
const panorGeo = new THREE.BoxGeometry(1000, 1000, 1000)
73+
const loader = new THREE.TextureLoader()
74+
const panorMaterials = [] as THREE.MeshBasicMaterial[]
75+
76+
for (const file of panoramaFiles) {
77+
const texture = loader.load(join('background', file))
78+
79+
// Instead of using repeat/offset to flip, we'll use the texture matrix
80+
texture.matrixAutoUpdate = false
81+
texture.matrix.set(
82+
-1, 0, 1, 0, 1, 0, 0, 0, 1
83+
)
84+
85+
texture.wrapS = THREE.ClampToEdgeWrapping // Changed from RepeatWrapping
86+
texture.wrapT = THREE.ClampToEdgeWrapping // Changed from RepeatWrapping
87+
texture.minFilter = THREE.LinearFilter
88+
texture.magFilter = THREE.LinearFilter
89+
90+
panorMaterials.push(new THREE.MeshBasicMaterial({
91+
map: texture,
92+
transparent: true,
93+
side: THREE.DoubleSide,
94+
depthWrite: false,
95+
}))
96+
}
97+
98+
const panoramaBox = new THREE.Mesh(panorGeo, panorMaterials)
99+
panoramaBox.onBeforeRender = () => {
74100
this.time += 0.01
75-
classicPanorama.panoramaGroup.rotation.y = Math.PI + this.time * 0.01
76-
classicPanorama.panoramaGroup.rotation.z = Math.sin(-this.time * 0.001) * 0.001
101+
panoramaBox.rotation.y = Math.PI + this.time * 0.01
102+
panoramaBox.rotation.z = Math.sin(-this.time * 0.001) * 0.001
103+
}
104+
105+
const group = new THREE.Object3D()
106+
group.add(panoramaBox)
107+
108+
// Add squids
109+
for (let i = 0; i < 20; i++) {
110+
const m = new EntityMesh('1.16.4', 'squid').mesh
111+
m.position.set(Math.random() * 30 - 15, Math.random() * 20 - 10, Math.random() * 10 - 17)
112+
m.rotation.set(0, Math.PI + Math.random(), -Math.PI / 4, 'ZYX')
113+
const v = Math.random() * 0.01
114+
m.children[0].onBeforeRender = () => {
115+
m.rotation.y += v
116+
m.rotation.z = Math.cos(panoramaBox.rotation.y * 3) * Math.PI / 4 - Math.PI / 2
117+
}
118+
group.add(m)
77119
}
78-
this.scene.add(classicPanorama.panoramaGroup)
79-
this.panoramaGroup = classicPanorama.panoramaGroup
120+
121+
this.scene.add(group)
122+
this.panoramaGroup = group
80123
}
81124

82125
async worldBlocksPanorama () {
@@ -167,54 +210,58 @@ export class PanoramaRenderer {
167210
}
168211
}
169212

170-
class ClassicPanoramaRenderer {
171-
panoramaGroup: THREE.Object3D
213+
// export class ClassicPanoramaRenderer {
214+
// panoramaGroup: THREE.Object3D
172215

173-
constructor (private readonly backgroundFiles: string[]) {
174-
const panorGeo = new THREE.BoxGeometry(1000, 1000, 1000)
175-
const loader = new THREE.TextureLoader()
176-
const panorMaterials = [] as THREE.MeshBasicMaterial[]
216+
// constructor (private readonly backgroundFiles: string[], onRender: Array<(sizeChanged: boolean) => void>, addSquids = true) {
217+
// const panorGeo = new THREE.BoxGeometry(1000, 1000, 1000)
218+
// const loader = new THREE.TextureLoader()
219+
// const panorMaterials = [] as THREE.MeshBasicMaterial[]
177220

178-
for (const file of this.backgroundFiles) {
179-
const texture = loader.load(file)
221+
// for (const file of this.backgroundFiles) {
222+
// const texture = loader.load(file)
180223

181-
// Instead of using repeat/offset to flip, we'll use the texture matrix
182-
texture.matrixAutoUpdate = false
183-
texture.matrix.set(
184-
-1, 0, 1, 0, 1, 0, 0, 0, 1
185-
)
224+
// // Instead of using repeat/offset to flip, we'll use the texture matrix
225+
// texture.matrixAutoUpdate = false
226+
// texture.matrix.set(
227+
// -1, 0, 1, 0, 1, 0, 0, 0, 1
228+
// )
186229

187-
texture.wrapS = THREE.ClampToEdgeWrapping // Changed from RepeatWrapping
188-
texture.wrapT = THREE.ClampToEdgeWrapping // Changed from RepeatWrapping
189-
texture.minFilter = THREE.LinearFilter
190-
texture.magFilter = THREE.LinearFilter
230+
// texture.wrapS = THREE.ClampToEdgeWrapping // Changed from RepeatWrapping
231+
// texture.wrapT = THREE.ClampToEdgeWrapping // Changed from RepeatWrapping
232+
// texture.minFilter = THREE.LinearFilter
233+
// texture.magFilter = THREE.LinearFilter
191234

192-
panorMaterials.push(new THREE.MeshBasicMaterial({
193-
map: texture,
194-
transparent: true,
195-
side: THREE.DoubleSide,
196-
depthWrite: false,
197-
}))
198-
}
235+
// panorMaterials.push(new THREE.MeshBasicMaterial({
236+
// map: texture,
237+
// transparent: true,
238+
// side: THREE.DoubleSide,
239+
// depthWrite: false,
240+
// }))
241+
// }
199242

200-
const panoramaBox = new THREE.Mesh(panorGeo, panorMaterials)
243+
// const panoramaBox = new THREE.Mesh(panorGeo, panorMaterials)
244+
// panoramaBox.onBeforeRender = () => {
245+
// }
201246

202-
const group = new THREE.Object3D()
203-
group.add(panoramaBox)
247+
// const group = new THREE.Object3D()
248+
// group.add(panoramaBox)
204249

205-
// Add squids
206-
for (let i = 0; i < 20; i++) {
207-
const m = new EntityMesh('1.16.4', 'squid').mesh
208-
m.position.set(Math.random() * 30 - 15, Math.random() * 20 - 10, Math.random() * 10 - 17)
209-
m.rotation.set(0, Math.PI + Math.random(), -Math.PI / 4, 'ZYX')
210-
const v = Math.random() * 0.01
211-
m.children[0].onBeforeRender = () => {
212-
m.rotation.y += v
213-
m.rotation.z = Math.cos(panoramaBox.rotation.y * 3) * Math.PI / 4 - Math.PI / 2
214-
}
215-
group.add(m)
216-
}
250+
// if (addSquids) {
251+
// // Add squids
252+
// for (let i = 0; i < 20; i++) {
253+
// const m = new EntityMesh('1.16.4', 'squid').mesh
254+
// m.position.set(Math.random() * 30 - 15, Math.random() * 20 - 10, Math.random() * 10 - 17)
255+
// m.rotation.set(0, Math.PI + Math.random(), -Math.PI / 4, 'ZYX')
256+
// const v = Math.random() * 0.01
257+
// onRender.push(() => {
258+
// m.rotation.y += v
259+
// m.rotation.z = Math.cos(panoramaBox.rotation.y * 3) * Math.PI / 4 - Math.PI / 2
260+
// })
261+
// group.add(m)
262+
// }
263+
// }
217264

218-
this.panoramaGroup = group
219-
}
220-
}
265+
// this.panoramaGroup = group
266+
// }
267+
// }

renderer/viewer/three/worldrendererThree.ts

+9-7
Original file line numberDiff line numberDiff line change
@@ -366,13 +366,15 @@ export class WorldRendererThree extends WorldRendererCommon {
366366
}
367367
}
368368
this.sectionObjects[data.key] = object
369-
object.visible = false
370-
const chunkKey = `${chunkCoords[0]},${chunkCoords[2]}`
371-
this.waitingChunksToDisplay[chunkKey] ??= []
372-
this.waitingChunksToDisplay[chunkKey].push(data.key)
373-
if (this.finishedChunks[chunkKey]) {
374-
// todo it might happen even when it was not an update
375-
this.finishChunk(chunkKey)
369+
if (this.displayOptions.inWorldRenderingConfig._renderByChunks) {
370+
object.visible = false
371+
const chunkKey = `${chunkCoords[0]},${chunkCoords[2]}`
372+
this.waitingChunksToDisplay[chunkKey] ??= []
373+
this.waitingChunksToDisplay[chunkKey].push(data.key)
374+
if (this.finishedChunks[chunkKey]) {
375+
// todo it might happen even when it was not an update
376+
this.finishChunk(chunkKey)
377+
}
376378
}
377379

378380
this.updatePosDataChunk(data.key)

src/optionsStorage.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ const defaultOptions = {
111111
highlightBlockColor: 'auto' as 'auto' | 'blue' | 'classic',
112112
rendererOptions: {
113113
three: {
114-
_experimentalSmoothChunkLoading: true
114+
_experimentalSmoothChunkLoading: true,
115+
_renderByChunks: false
115116
}
116117
}
117118
}

src/watchOptions.ts

+1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ export const watchOptionsAfterViewerInit = () => {
8686
appViewer.inWorldRenderingConfig.fetchPlayerSkins = o.loadPlayerSkins
8787
appViewer.inWorldRenderingConfig.highlightBlockColor = o.highlightBlockColor
8888
appViewer.inWorldRenderingConfig._experimentalSmoothChunkLoading = o.rendererOptions.three._experimentalSmoothChunkLoading
89+
appViewer.inWorldRenderingConfig._renderByChunks = o.rendererOptions.three._renderByChunks
8990
})
9091

9192
appViewer.inWorldRenderingConfig.smoothLighting = options.smoothLighting

0 commit comments

Comments
 (0)