@@ -2,22 +2,19 @@ import { Vector3 } from 'three'
22import { ChunkTerrain } from './ChunkTerrain.js'
33import { AnimatedTextureAtlas } from './AnimatedTextureAtlas.js'
44import { SectionComputer } from './SectionComputer.js'
5- import vec3 from 'vec3'
6- import ChunkWorker from './chunk.worker.js'
75import { ChunkManager } from './ChunkManager.js'
6+ import ChunkWorker from './chunk.worker.js'
87
9- const World = class World {
8+ class World {
109 constructor ( game ) {
1110 this . game = game
1211 this . blocksDef = this . game . al . get ( 'blocksDef' )
13- this . models = { }
1412 this . chunkTerrain = new ChunkTerrain ( {
1513 blocksDef : this . blocksDef
1614 } )
1715 this . ATA = new AnimatedTextureAtlas ( this . game )
1816 this . material = this . ATA . material
1917 this . cellUpdateTime = null
20- this . renderTime = 100
2118 this . lastPlayerChunk = null
2219 this . blocksUpdate = false
2320
@@ -44,13 +41,6 @@ const World = class World {
4441 } )
4542 }
4643
47- updateRenderOrder ( cell ) {
48- for ( const [ k , v ] of this . chunkManager . cellMesh ) {
49- const x = vec3 ( this . chunkTerrain . strToVec ( k ) )
50- v . renderOrder = - vec3 ( ...cell ) . distanceTo ( x )
51- }
52- }
53-
5444 setChunk ( chunkX , chunkY , chunkZ , buffer ) {
5545 this . cellUpdateTime = window . performance . now ( )
5646 this . chunkWorker . postMessage ( {
@@ -84,9 +74,7 @@ const World = class World {
8474 }
8575
8676 getRayBlock ( ) {
87- const start = new Vector3 ( ) . setFromMatrixPosition (
88- this . game . camera . matrixWorld
89- )
77+ const start = new Vector3 ( ) . setFromMatrixPosition ( this . game . camera . matrixWorld )
9078 const end = new Vector3 ( ) . set ( 0 , 0 , 1 ) . unproject ( this . game . camera )
9179 const intersection = this . chunkTerrain . intersectsRay ( start , end )
9280 if ( intersection ) {
@@ -117,10 +105,9 @@ const World = class World {
117105 } )
118106 } else if ( this . lastPlayerChunk !== JSON . stringify ( cell ) ) {
119107 if (
120- this . cellUpdateTime !== null &&
121- window . performance . now ( ) - this . cellUpdateTime > this . renderTime
108+ this . cellUpdateTime !== null && window . performance . now ( ) - this . cellUpdateTime > 100
122109 ) {
123- this . updateRenderOrder ( cell )
110+ this . chunkManager . updateRenderOrder ( cell )
124111 this . lastPlayerChunk = JSON . stringify ( cell )
125112 this . chunkWorker . postMessage ( {
126113 type : 'updateChunksAroundPlayer' ,
@@ -130,9 +117,8 @@ const World = class World {
130117 }
131118 }
132119
133- computeSections ( sections , x , z ) {
120+ computeSections ( sections , biomes , x , z ) {
134121 const result = SectionComputer ( { sections, x, z } )
135- // console.log(result);
136122 const results = [ ]
137123 for ( const i in result ) {
138124 const j = result [ i ]
0 commit comments