@@ -5,6 +5,7 @@ import {AnimatedTextureAtlas} from './AnimatedTextureAtlas.js'
55class World
66 constructor : (options ) ->
77 _this = @
8+ @cellBlackList = {}
89 @cellMesh = {}
910 @cellNeedsUpdate = {}
1011 @models = {}
@@ -18,6 +19,7 @@ class World
1819 @material = @ATA .material
1920 @cellUpdateTime = null
2021 @renderTime = 100
22+ @renderer = options .renderer
2123 @neighbours = [[- 1 , 0 , 0 ],[1 , 0 , 0 ],[0 , - 1 , 0 ],[0 , 1 , 0 ],[0 , 0 , - 1 ],[0 , 0 , 1 ]]
2224
2325 # Utworzenie Workera do obliczania geometrii chunków
@@ -66,16 +68,24 @@ class World
6668 # Updatowanie komórek wokół gracza w danym zasięgu
6769 _this = @
6870 if @cellUpdateTime isnt null and (performance .now ()- @cellUpdateTime > @renderTime )
71+ # Ustawianie z defaultu, żeby każdy Mesh był wykasowywany
72+ cellBlackList = {}
6973 for k,v of @cellMesh
70- v .visible = false
74+ if v isnt " disposed"
75+ cellBlackList[k]= true
7176 cell = @cellTerrain .computeCellForVoxel (Math .floor pos .x ),(Math .floor pos .y ),(Math .floor pos .z )
7277 up = (x ,y ,z )->
7378 pcell = [cell[0 ]+ x,cell[1 ]+ y,cell[2 ]+ z]
74- if _this .cellMesh [_this .cellTerrain .vec3 (pcell... )]
75- _this .cellMesh [_this .cellTerrain .vec3 (pcell... )].visible = true
76- if _this .cellNeedsUpdate [_this .cellTerrain .vec3 (pcell... )]
79+ cellId = _this .cellTerrain .vec3 (pcell... )
80+ # Updatowanie mesha, jeśli był disposed lub potrzebuje updatu
81+ if _this .cellNeedsUpdate [cellId] or _this .cellMesh [cellId] is " disposed"
82+
83+ if _this .cellNeedsUpdate [cellId]
84+ delete _this .cellNeedsUpdate [cellId]
85+ if _this .cellMesh [cellId] is " disposed"
86+ _this .cellMesh [cellId]= " disposedX"
7787 _this ._genCellGeo pcell...
78- delete _this . cellNeedsUpdate [ _this . cellTerrain . vec3 (pcell ... )]
88+ cellBlackList[cellId] = false
7989 return
8090 odw = {}
8191 for i in [0 .. radius]
@@ -85,6 +95,14 @@ class World
8595 if not odw[" #{ x} :#{ y} :#{ z} " ]
8696 up (x,y,z)
8797 odw[" #{ x} :#{ y} :#{ z} " ]= true
98+ # Kasowanie Meshy, które mają znacznik .todel
99+ for i of cellBlackList
100+ if cellBlackList[i] is true
101+ @cellMesh [i].geometry .dispose ()
102+ @cellMesh [i].material .dispose ()
103+ @scene .remove @cellMesh [i]
104+ @cellMesh [i]= " disposed"
105+ @renderer .renderLists .dispose ()
88106 updateCell : (data )->
89107 # Updatowanie komórki z już obliczoną geometrią
90108 cellId = @cellTerrain .vec3 data .info ...
@@ -95,7 +113,7 @@ class World
95113 geometry .setAttribute ' normal' ,new THREE.BufferAttribute (new Float32Array (cell .normals ), 3 )
96114 geometry .setAttribute ' uv' ,new THREE.BufferAttribute (new Float32Array (cell .uvs ), 2 )
97115 geometry .setAttribute ' color' ,new THREE.BufferAttribute (new Float32Array (cell .colors ), 3 )
98- if mesh is undefined
116+ if mesh is undefined or mesh is " disposedX "
99117 @cellMesh [cellId]= new THREE.Mesh geometry,@material
100118 @cellMesh [cellId].frustumCulled = false
101119 _this = @
0 commit comments