Skip to content

Commit 607a008

Browse files
committed
BlockGeo
1 parent db9aaba commit 607a008

File tree

4 files changed

+163
-161
lines changed

4 files changed

+163
-161
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
class BlockGeo
2+
constructor:(options)->
3+
@toxelSize=options.toxelSize
4+
@q=1/@toxelSize
5+
@blocksMapping=options.blocksMapping
6+
getToxel:(x,y)->
7+
x-=1
8+
y-=1
9+
x1=@q*x
10+
y1=1-@q*y-@q
11+
x2=@q*x+@q
12+
y2=1-@q*y
13+
return [
14+
[x1,y1]
15+
[x1,y2]
16+
[x2,y1]
17+
[x2,y2]
18+
]
19+
genBlockFace: (type,block,pos)->
20+
if block.name is "water"
21+
toxX=@blocksMapping["water_flow"]["x"]
22+
toxY=@blocksMapping["water_flow"]["y"]
23+
else if @blocksMapping[block.name]
24+
toxX=@blocksMapping[block.name]["x"]
25+
toxY=@blocksMapping[block.name]["y"]
26+
else
27+
toxX=@blocksMapping["debug"]["x"]
28+
toxY=28-@blocksMapping["debug"]["y"]
29+
uv=@getToxel toxX,toxY
30+
switch type
31+
when "pz"
32+
return {
33+
pos:[-0.5+pos[0], -0.5+pos[1], 0.5+pos[2],0.5+pos[0], -0.5+pos[1], 0.5+pos[2],-0.5+pos[0], 0.5+pos[1], 0.5+pos[2],-0.5+pos[0], 0.5+pos[1], 0.5+pos[2],0.5+pos[0], -0.5+pos[1], 0.5+pos[2],0.5+pos[0], 0.5+pos[1], 0.5+pos[2]]
34+
norm:[0, 0, 1,0, 0, 1,0, 0, 1,0, 0, 1,0, 0, 1,0, 0, 1]
35+
uv:[uv[0]...,uv[2]...,uv[1]...,uv[1]...,uv[2]...,uv[3]...]
36+
}
37+
when "nx"
38+
return {
39+
pos:[ 0.5+pos[0], -0.5+pos[1], 0.5+pos[2], 0.5+pos[0], -0.5+pos[1], -0.5+pos[2],0.5+pos[0], 0.5+pos[1], 0.5+pos[2], 0.5+pos[0], 0.5+pos[1], 0.5+pos[2],0.5+pos[0], -0.5+pos[1], -0.5+pos[2], 0.5+pos[0], 0.5+pos[1], -0.5+pos[2]]
40+
norm:[ 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0]
41+
uv:[uv[0]...,uv[2]...,uv[1]...,uv[1]...,uv[2]...,uv[3]...]
42+
}
43+
when "nz"
44+
return {
45+
pos:[ 0.5+pos[0], -0.5+pos[1], -0.5+pos[2],-0.5+pos[0], -0.5+pos[1], -0.5+pos[2],0.5+pos[0], 0.5+pos[1], -0.5+pos[2], 0.5+pos[0], 0.5+pos[1], -0.5+pos[2],-0.5+pos[0], -0.5+pos[1], -0.5+pos[2],-0.5+pos[0], 0.5+pos[1], -0.5+pos[2]]
46+
norm:[ 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1]
47+
uv:[uv[0]...,uv[2]...,uv[1]...,uv[1]...,uv[2]...,uv[3]...]
48+
}
49+
when "px"
50+
return {
51+
pos:[-0.5+pos[0], -0.5+pos[1], -0.5+pos[2],-0.5+pos[0], -0.5+pos[1], 0.5+pos[2],-0.5+pos[0], 0.5+pos[1], -0.5+pos[2],-0.5+pos[0], 0.5+pos[1], -0.5+pos[2],-0.5+pos[0], -0.5+pos[1], 0.5+pos[2],-0.5+pos[0], 0.5+pos[1], 0.5+pos[2]]
52+
norm:[-1, 0, 0,-1, 0, 0,-1, 0, 0,-1, 0, 0,-1, 0, 0,-1, 0, 0]
53+
uv:[uv[0]...,uv[2]...,uv[1]...,uv[1]...,uv[2]...,uv[3]...]
54+
}
55+
when "py"
56+
return {
57+
pos:[ 0.5+pos[0], 0.5+pos[1], -0.5+pos[2],-0.5+pos[0], 0.5+pos[1], -0.5+pos[2],0.5+pos[0], 0.5+pos[1], 0.5+pos[2], 0.5+pos[0], 0.5+pos[1], 0.5+pos[2],-0.5+pos[0], 0.5+pos[1], -0.5+pos[2],-0.5+pos[0], 0.5+pos[1], 0.5+pos[2]]
58+
norm:[ 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0]
59+
uv:[uv[0]...,uv[2]...,uv[1]...,uv[1]...,uv[2]...,uv[3]...]
60+
}
61+
when "ny"
62+
return {
63+
pos:[ 0.5+pos[0], -0.5+pos[1], 0.5+pos[2],-0.5+pos[0], -0.5+pos[1], 0.5+pos[2],0.5+pos[0], -0.5+pos[1], -0.5+pos[2], 0.5+pos[0], -0.5+pos[1], -0.5+pos[2],-0.5+pos[0], -0.5+pos[1], 0.5+pos[2],-0.5+pos[0], -0.5+pos[1], -0.5+pos[2]]
64+
norm:[ 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0]
65+
uv:[uv[0]...,uv[2]...,uv[1]...,uv[1]...,uv[2]...,uv[3]...]
66+
}
67+
68+
export {BlockGeo}

coffee/client/module/World/ChunkWorker.coffee

Lines changed: 8 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,98 +1,29 @@
11
import {CellTerrain} from './CellTerrain.js'
2-
import {Block} from './../build/Block.js'
2+
import {BlockGeo} from './BlockGeo.js'
3+
34
console.log "CHUNK WORKER STARTED!"
5+
46
class TerrainManager
57
constructor: (options)->
6-
@toxelSize=options.toxelSize
7-
@q=1/@toxelSize
8-
@blocks=options.blocks
9-
@blocksMapping=options.blocksMapping
108
@cellSize=options.cellSize
11-
@models=options.models
129
@cellTerrain=new CellTerrain {
1310
cellSize:@cellSize
1411
}
15-
getToxel: (x,y)->
16-
x-=1
17-
y-=1
18-
x1=@q*x
19-
y1=1-@q*y-@q
20-
x2=@q*x+@q
21-
y2=1-@q*y
22-
return [
23-
[x1,y1]
24-
[x1,y2]
25-
[x2,y1]
26-
[x2,y2]
27-
]
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"]
35-
else
36-
toxX=@blocksMapping["debug"]["x"]
37-
toxY=28-@blocksMapping["debug"]["y"]
38-
uv=@getToxel toxX,toxY
39-
switch type
40-
when "pz"
41-
return {
42-
pos:[-0.5+pos[0], -0.5+pos[1], 0.5+pos[2],0.5+pos[0], -0.5+pos[1], 0.5+pos[2],-0.5+pos[0], 0.5+pos[1], 0.5+pos[2],-0.5+pos[0], 0.5+pos[1], 0.5+pos[2],0.5+pos[0], -0.5+pos[1], 0.5+pos[2],0.5+pos[0], 0.5+pos[1], 0.5+pos[2]]
43-
norm:[0, 0, 1,0, 0, 1,0, 0, 1,0, 0, 1,0, 0, 1,0, 0, 1]
44-
uv:[uv[0]...,uv[2]...,uv[1]...,uv[1]...,uv[2]...,uv[3]...]
45-
}
46-
when "nx"
47-
return {
48-
pos:[ 0.5+pos[0], -0.5+pos[1], 0.5+pos[2], 0.5+pos[0], -0.5+pos[1], -0.5+pos[2],0.5+pos[0], 0.5+pos[1], 0.5+pos[2], 0.5+pos[0], 0.5+pos[1], 0.5+pos[2],0.5+pos[0], -0.5+pos[1], -0.5+pos[2], 0.5+pos[0], 0.5+pos[1], -0.5+pos[2]]
49-
norm:[ 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0]
50-
uv:[uv[0]...,uv[2]...,uv[1]...,uv[1]...,uv[2]...,uv[3]...]
51-
}
52-
when "nz"
53-
return {
54-
pos:[ 0.5+pos[0], -0.5+pos[1], -0.5+pos[2],-0.5+pos[0], -0.5+pos[1], -0.5+pos[2],0.5+pos[0], 0.5+pos[1], -0.5+pos[2], 0.5+pos[0], 0.5+pos[1], -0.5+pos[2],-0.5+pos[0], -0.5+pos[1], -0.5+pos[2],-0.5+pos[0], 0.5+pos[1], -0.5+pos[2]]
55-
norm:[ 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1]
56-
uv:[uv[0]...,uv[2]...,uv[1]...,uv[1]...,uv[2]...,uv[3]...]
57-
}
58-
when "px"
59-
return {
60-
pos:[-0.5+pos[0], -0.5+pos[1], -0.5+pos[2],-0.5+pos[0], -0.5+pos[1], 0.5+pos[2],-0.5+pos[0], 0.5+pos[1], -0.5+pos[2],-0.5+pos[0], 0.5+pos[1], -0.5+pos[2],-0.5+pos[0], -0.5+pos[1], 0.5+pos[2],-0.5+pos[0], 0.5+pos[1], 0.5+pos[2]]
61-
norm:[-1, 0, 0,-1, 0, 0,-1, 0, 0,-1, 0, 0,-1, 0, 0,-1, 0, 0]
62-
uv:[uv[0]...,uv[2]...,uv[1]...,uv[1]...,uv[2]...,uv[3]...]
63-
}
64-
when "py"
65-
return {
66-
pos:[ 0.5+pos[0], 0.5+pos[1], -0.5+pos[2],-0.5+pos[0], 0.5+pos[1], -0.5+pos[2],0.5+pos[0], 0.5+pos[1], 0.5+pos[2], 0.5+pos[0], 0.5+pos[1], 0.5+pos[2],-0.5+pos[0], 0.5+pos[1], -0.5+pos[2],-0.5+pos[0], 0.5+pos[1], 0.5+pos[2]]
67-
norm:[ 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0]
68-
uv:[uv[0]...,uv[2]...,uv[1]...,uv[1]...,uv[2]...,uv[3]...]
69-
}
70-
when "ny"
71-
return {
72-
pos:[ 0.5+pos[0], -0.5+pos[1], 0.5+pos[2],-0.5+pos[0], -0.5+pos[1], 0.5+pos[2],0.5+pos[0], -0.5+pos[1], -0.5+pos[2], 0.5+pos[0], -0.5+pos[1], -0.5+pos[2],-0.5+pos[0], -0.5+pos[1], 0.5+pos[2],-0.5+pos[0], -0.5+pos[1], -0.5+pos[2]]
73-
norm:[ 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0]
74-
uv:[uv[0]...,uv[2]...,uv[1]...,uv[1]...,uv[2]...,uv[3]...]
75-
}
12+
@BlockGeo=new BlockGeo {
13+
toxelSize:options.toxelSize
14+
blocksMapping:options.blocksMapping
15+
}
7616
genCellGeo: (cellX,cellY,cellZ)->
7717
_this=@
7818
positions=[]
7919
normals=[]
8020
uvs=[]
8121
addFace=(type,pos)->
82-
faceVertex=_this.genBlockFace type,_this.cellTerrain.getBlock(pos...),pos
22+
faceVertex=_this.BlockGeo.genBlockFace type,_this.cellTerrain.getBlock(pos...),pos
8323
positions.push faceVertex.pos...
8424
normals.push faceVertex.norm...
8525
uvs.push faceVertex.uv...
8626
return
87-
addGeo=(geo,pos)->
88-
posi=geo.position.array
89-
norm=geo.normal.array
90-
uv=geo.uv.array
91-
for i in [0..posi.length-1]
92-
positions.push posi[i]+pos[i%3]
93-
normals.push norm...
94-
uvs.push uv...
95-
return
9627
for i in [0..@cellSize-1]
9728
for j in [0..@cellSize-1]
9829
for k in [0..@cellSize-1]

src/client/module/World/BlockGeo.js

Lines changed: 79 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/client/module/World/ChunkWorker.js

Lines changed: 8 additions & 84 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)