1- //@ts -nocheck
21// eslint-disable-next-line import/no-named-as-default
32import GUI , { Controller } from 'lil-gui'
43import * as THREE from 'three'
54import JSZip from 'jszip'
65import { BasePlaygroundScene } from '../baseScene'
76import { TWEEN_DURATION } from '../../viewer/three/entities'
87import { EntityMesh } from '../../viewer/three/entity/EntityMesh'
8+ import supportedVersions from '../../../src/supportedVersions.mjs'
9+
10+ const includedVersions = globalThis . includedVersions ?? supportedVersions
911
1012class MainScene extends BasePlaygroundScene {
1113 // eslint-disable-next-line @typescript-eslint/no-useless-constructor
1214 constructor ( ...args ) {
13- //@ts -expect-error
1415 super ( ...args )
1516 }
1617
1718 override initGui ( ) : void {
1819 // initial values
1920 this . params = {
20- version : globalThis . includedVersions . at ( - 1 ) ,
21+ version : includedVersions . at ( - 1 ) ,
2122 skipQs : '' ,
2223 block : '' ,
2324 metadata : 0 ,
@@ -35,7 +36,7 @@ class MainScene extends BasePlaygroundScene {
3536 this . metadataGui = this . gui . add ( this . params , 'metadata' )
3637 this . paramOptions = {
3738 version : {
38- options : globalThis . includedVersions ,
39+ options : includedVersions ,
3940 hide : false
4041 } ,
4142 block : {
@@ -113,8 +114,8 @@ class MainScene extends BasePlaygroundScene {
113114 this . entityUpdateShared ( )
114115 if ( ! this . params . entity ) return
115116 if ( this . params . entity === 'player' ) {
116- viewer . entities . updatePlayerSkin ( 'id' , viewer . entities . entities . id . username , undefined , true , true )
117- viewer . entities . playAnimation ( 'id' , 'running' )
117+ this . worldRenderer ! . entities . updatePlayerSkin ( 'id' , this . worldRenderer ! . entities . entities . id . username , undefined , true , true )
118+ this . worldRenderer ! . entities . playAnimation ( 'id' , 'running' )
118119 }
119120 // let prev = false
120121 // setInterval(() => {
@@ -129,17 +130,17 @@ class MainScene extends BasePlaygroundScene {
129130 // entityRotationFolder.open()
130131 } ,
131132 supportBlock : ( ) => {
132- viewer . setBlockStateId ( this . targetPos . offset ( 0 , - 1 , 0 ) , this . params . supportBlock ? 1 : 0 )
133+ this . worldView ! . setBlockStateId ( this . targetPos . offset ( 0 , - 1 , 0 ) , this . params . supportBlock ? 1 : 0 )
133134 } ,
134135 modelVariant : ( ) => {
135- viewer . world . mesherConfig . debugModelVariant = this . params . modelVariant === 0 ? undefined : [ this . params . modelVariant ]
136+ this . worldRenderer ! . worldRendererConfig . debugModelVariant = this . params . modelVariant === 0 ? undefined : [ this . params . modelVariant ]
136137 }
137138 }
138139
139140 entityUpdateShared ( ) {
140- viewer . entities . clear ( )
141+ this . worldRenderer ! . entities . clear ( )
141142 if ( ! this . params . entity ) return
142- worldView ! . emit ( 'entity' , {
143+ this . worldView ! . emit ( 'entity' , {
143144 id : 'id' , name : this . params . entity , pos : this . targetPos . offset ( 0.5 , 1 , 0.5 ) , width : 1 , height : 1 , username : localStorage . testUsername , yaw : Math . PI , pitch : 0
144145 } )
145146 const enableSkeletonDebug = ( obj ) => {
@@ -153,14 +154,14 @@ class MainScene extends BasePlaygroundScene {
153154 if ( typeof child === 'object' ) enableSkeletonDebug ( child )
154155 }
155156 }
156- enableSkeletonDebug ( viewer . entities . entities [ 'id' ] )
157+ enableSkeletonDebug ( this . worldRenderer ! . entities . entities [ 'id' ] )
157158 setTimeout ( ( ) => {
158- viewer . render ( )
159+ this . render ( )
159160 } , TWEEN_DURATION )
160161 }
161162
162163 blockIsomorphicRenderBundle ( ) {
163- const { renderer } = viewer
164+ const { renderer } = this . worldRenderer !
164165
165166 const canvas = renderer . domElement
166167 const onlyCurrent = ! confirm ( 'Ok - render all blocks, Cancel - render only current one' )
@@ -169,28 +170,28 @@ class MainScene extends BasePlaygroundScene {
169170 const size = parseInt ( sizeRaw , 10 )
170171 // const size = 512
171172
172- this . ignoreResize = true
173173 canvas . width = size
174174 canvas . height = size
175175 renderer . setSize ( size , size )
176176
177- viewer . camera = new THREE . OrthographicCamera ( - 1 , 1 , 1 , - 1 , 0 , 10 )
178- viewer . scene . background = null
177+ // Temporarily replace PerspectiveCamera with OrthographicCamera for block rendering
178+ this . worldRenderer ! . camera = new THREE . OrthographicCamera ( - 1 , 1 , 1 , - 1 , 0 , 10 ) as any
179+ this . worldRenderer ! . scene . background = null
179180
180181 const rad = THREE . MathUtils . degToRad ( - 120 )
181- viewer . directionalLight . position . set (
182+ this . worldRenderer ! . directionalLight . position . set (
182183 Math . cos ( rad ) ,
183184 Math . sin ( rad ) ,
184185 0.2
185186 ) . normalize ( )
186- viewer . directionalLight . intensity = 1
187+ this . worldRenderer ! . directionalLight . intensity = 1
187188
188189 const cameraPos = this . targetPos . offset ( 2 , 2 , 2 )
189190 const pitch = THREE . MathUtils . degToRad ( - 30 )
190191 const yaw = THREE . MathUtils . degToRad ( 45 )
191- viewer . camera . rotation . set ( pitch , yaw , 0 , 'ZYX' )
192- // viewer .camera.lookAt(center.x + 0.5, center.y + 0.5, center.z + 0.5)
193- viewer . camera . position . set ( cameraPos . x + 1 , cameraPos . y + 0.5 , cameraPos . z + 1 )
192+ this . worldRenderer ! . camera . rotation . set ( pitch , yaw , 0 , 'ZYX' )
193+ // this.worldRenderer! .camera.lookAt(center.x + 0.5, center.y + 0.5, center.z + 0.5)
194+ this . worldRenderer ! . camera . position . set ( cameraPos . x + 1 , cameraPos . y + 0.5 , cameraPos . z + 1 )
194195
195196 const allBlocks = mcData . blocksArray . map ( b => b . name )
196197 // const allBlocks = ['stone', 'warped_slab']
@@ -206,17 +207,17 @@ class MainScene extends BasePlaygroundScene {
206207 // onUpdate.block()
207208 // applyChanges(false, true)
208209 }
209- void viewer . waitForChunksToRender ( ) . then ( async ( ) => {
210+ void this . worldRenderer ! . waitForChunksToRender ( ) . then ( async ( ) => {
210211 // wait for next macro task
211212 await new Promise ( resolve => {
212213 setTimeout ( resolve , 0 )
213214 } )
214215 if ( onlyCurrent ) {
215- viewer . render ( )
216+ this . render ( )
216217 onWorldUpdate ( )
217218 } else {
218219 // will be called on every render update
219- viewer . world . renderUpdateEmitter . addListener ( 'update' , onWorldUpdate )
220+ this . worldRenderer ! . renderUpdateEmitter . addListener ( 'update' , onWorldUpdate )
220221 updateBlock ( )
221222 }
222223 } )
@@ -236,7 +237,7 @@ class MainScene extends BasePlaygroundScene {
236237 URL . revokeObjectURL ( dataUrlZip )
237238 console . log ( 'end' )
238239
239- viewer . world . renderUpdateEmitter . removeListener ( 'update' , onWorldUpdate )
240+ this . worldRenderer ! . renderUpdateEmitter . removeListener ( 'update' , onWorldUpdate )
240241 }
241242
242243 async function onWorldUpdate ( ) {
@@ -295,7 +296,7 @@ class MainScene extends BasePlaygroundScene {
295296 }
296297 }
297298
298- worldView ! . setBlockStateId ( this . targetPos , block . stateId ?? 0 )
299+ this . worldView ! . setBlockStateId ( this . targetPos , block . stateId ?? 0 )
299300 console . log ( 'up stateId' , block . stateId )
300301 this . params . metadata = block . metadata
301302 this . metadataGui . updateDisplay ( )
0 commit comments