@@ -25,11 +25,13 @@ class TerrainManager
2525 [x2,y1]
2626 [x2,y2]
2727 ]
28- genBlockFace : (type ,voxel ,pos )->
29- xd = new Block.fromStateId voxel
30- if @blocksMapping [xd .name ]
31- toxX = @blocksMapping [xd .name ][" x" ]
32- toxY = @blocksMapping [xd .name ][" y" ]
28+ genBlockFace : (type ,block ,pos )->
29+ if block .name is " water"
30+ toxX = @blocksMapping [" water_flow" ][" x" ]
31+ toxY = @blocksMapping [" water_flow" ][" y" ]
32+ else if @blocksMapping [block .name ]
33+ toxX = @blocksMapping [block .name ][" x" ]
34+ toxY = @blocksMapping [block .name ][" y" ]
3335 else
3436 toxX = @blocksMapping [" debug" ][" x" ]
3537 toxY = 28 - @blocksMapping [" debug" ][" y" ]
@@ -76,8 +78,8 @@ class TerrainManager
7678 normals = []
7779 uvs = []
7880 _this = @
79- addFace = (type ,pos , voxel )->
80- faceVertex = _this .genBlockFace type,voxel ,pos
81+ addFace = (type ,pos )->
82+ faceVertex = _this .genBlockFace type,_this . cellTerrain . getBlock (pos ... ) ,pos
8183 positions .push faceVertex .pos ...
8284 normals .push faceVertex .norm ...
8385 uvs .push faceVertex .uv ...
@@ -95,24 +97,35 @@ class TerrainManager
9597 for j in [0 .. @cellSize - 1 ]
9698 for k in [0 .. @cellSize - 1 ]
9799 pos = [cellX* @cellSize + i,cellY* @cellSize + j,cellZ* @cellSize + k]
98- voxel = @ getVoxel pos...
99- if voxel
100- if @blocks [voxel] is undefined or @blocks [voxel].isBlock
101- if not (@blocks [@ getVoxel (pos[0 ]+ 1 ,pos[1 ],pos[2 ])] is undefined or @blocks [@ getVoxel (pos[0 ]+ 1 ,pos[1 ],pos[2 ])].isBlock )
102- addFace " nx" ,pos,voxel
103- if not (@blocks [@ getVoxel (pos[0 ]- 1 ,pos[1 ],pos[2 ])] is undefined or @blocks [@ getVoxel (pos[0 ]- 1 ,pos[1 ],pos[2 ])].isBlock )
104- addFace " px" ,pos,voxel
105- if not (@blocks [@ getVoxel (pos[0 ],pos[1 ]- 1 ,pos[2 ])] is undefined or @blocks [@ getVoxel (pos[0 ],pos[1 ]- 1 ,pos[2 ])].isBlock )
106- addFace " ny" ,pos,voxel
107- if not (@blocks [@ getVoxel (pos[0 ],pos[1 ]+ 1 ,pos[2 ])] is undefined or @blocks [@ getVoxel (pos[0 ],pos[1 ]+ 1 ,pos[2 ])].isBlock )
108- addFace " py" ,pos,voxel
109- if not (@blocks [@ getVoxel (pos[0 ],pos[1 ],pos[2 ]+ 1 )] is undefined or @blocks [@ getVoxel (pos[0 ],pos[1 ],pos[2 ]+ 1 )].isBlock )
110- addFace " pz" ,pos,voxel
111- if not (@blocks [@ getVoxel (pos[0 ],pos[1 ],pos[2 ]- 1 )] is undefined or @blocks [@ getVoxel (pos[0 ],pos[1 ],pos[2 ]- 1 )].isBlock )
112- addFace " nz" ,pos,voxel
113- else
114- geo = @models [@blocks [voxel].model ]
115- addGeo geo,pos
100+ if @cellTerrain .getBlock (pos... ).boundingBox is " block"
101+ if (@cellTerrain .getBlock (pos[0 ]+ 1 ,pos[1 ],pos[2 ]).boundingBox isnt " block" )
102+ addFace " nx" ,pos
103+ if (@cellTerrain .getBlock (pos[0 ]- 1 ,pos[1 ],pos[2 ]).boundingBox isnt " block" )
104+ addFace " px" ,pos
105+ if (@cellTerrain .getBlock (pos[0 ],pos[1 ]- 1 ,pos[2 ]).boundingBox isnt " block" )
106+ addFace " ny" ,pos
107+ if (@cellTerrain .getBlock (pos[0 ],pos[1 ]+ 1 ,pos[2 ]).boundingBox isnt " block" )
108+ addFace " py" ,pos
109+ if (@cellTerrain .getBlock (pos[0 ],pos[1 ],pos[2 ]+ 1 ).boundingBox isnt " block" )
110+ addFace " pz" ,pos
111+ if (@cellTerrain .getBlock (pos[0 ],pos[1 ],pos[2 ]- 1 ).boundingBox isnt " block" )
112+ addFace " nz" ,pos
113+ else if @cellTerrain .getBlock (pos... ).name is " water"
114+ if (@cellTerrain .getBlock (pos[0 ]+ 1 ,pos[1 ],pos[2 ]).name is " air" )
115+ addFace " nx" ,pos
116+ if (@cellTerrain .getBlock (pos[0 ]- 1 ,pos[1 ],pos[2 ]).name is " air" )
117+ addFace " px" ,pos
118+ if (@cellTerrain .getBlock (pos[0 ],pos[1 ]- 1 ,pos[2 ]).name is " air" )
119+ addFace " ny" ,pos
120+ if (@cellTerrain .getBlock (pos[0 ],pos[1 ]+ 1 ,pos[2 ]).name is " air" )
121+ addFace " py" ,pos
122+ if (@cellTerrain .getBlock (pos[0 ],pos[1 ],pos[2 ]+ 1 ).name is " air" )
123+ addFace " pz" ,pos
124+ if (@cellTerrain .getBlock (pos[0 ],pos[1 ],pos[2 ]- 1 ).name is " air" )
125+ addFace " nz" ,pos
126+ # else
127+ # geo=@models[@blocks[voxel].model]
128+ # addGeo geo,pos
116129 return {
117130 positions
118131 normals
0 commit comments