Skip to content

Commit 5d5157f

Browse files
committed
basic transparent material
1 parent 1b300ac commit 5d5157f

File tree

6 files changed

+56
-40
lines changed

6 files changed

+56
-40
lines changed

src/client/scripts/World/AnimatedTextureAtlas.coffee

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ class AnimatedTextureAtlas
7272
@material=new THREE.MeshStandardMaterial({
7373
side: 0
7474
map:null
75-
vertexColors: true
75+
vertexColors:true
76+
transparent:true
77+
depthTest:true
7678
})
7779
@uni=
7880
view:new THREE.Vector3

src/client/scripts/World/CellTerrain.coffee

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class CellTerrain
5858
name:def[0]
5959
stateId
6060
boundingBox
61+
transparent:def[2]
6162
}
6263
else
6364
return false

src/client/scripts/World/World.coffee

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ class World
2020
@renderTime=100
2121
@neighbours=[[-1, 0, 0],[1, 0, 0],[0, -1, 0],[0, 1, 0],[0, 0, -1],[0, 0, 1]]
2222

23-
#Utworzenie Workera do obliczania geometrii chunków
2423
@chunkWorker=new chunkWorker
2524
@chunkWorker.onmessage=(message)->
2625
if message.data.type is "cellGeo"
@@ -42,6 +41,9 @@ class World
4241
}
4342
}
4443
return
44+
updateRenderOrder: (cell)->
45+
#Here will be ordering meshes
46+
return
4547
setCell: (cellX,cellY,cellZ,buffer)->
4648
@_setCell cellX,cellY,cellZ,buffer
4749
@cellTerrain.setCell cellX,cellY,cellZ,buffer
@@ -63,7 +65,6 @@ class World
6365
@_resetWorld()
6466
return
6567
updateCell: (data)->
66-
#Updatowanie komórki z już obliczoną geometrią
6768
cellId=@cellTerrain.vec3 data.info...
6869
cell=data.cell
6970
mesh=@cellMesh[cellId]
@@ -176,8 +177,6 @@ class World
176177
else
177178
return false
178179
_setCell: (cellX,cellY,cellZ,buffer,biome)->
179-
#Wysyłanie do ChunkWorkera informacji nowej komórce
180-
181180
@cellUpdateTime=performance.now()
182181
@chunkWorker.postMessage {
183182
type:"setCell"
@@ -190,13 +189,11 @@ class World
190189
}
191190
return
192191
_setVoxel: (voxelX,voxelY,voxelZ,value)->
193-
#Wysyłanie do ChunkWorkera informacji o nowym Voxelu
194192
@chunkWorker.postMessage {
195193
type:"setVoxel"
196194
data:[voxelX,voxelY,voxelZ,value]
197195
}
198196
_genCellGeo: (cellX,cellY,cellZ)->
199-
#Wysyłanie do ChunkWorkera prośby o wygenerowanie geometrii komórki
200197
cellX=parseInt cellX
201198
cellY=parseInt cellY
202199
cellZ=parseInt cellZ
@@ -208,6 +205,7 @@ class World
208205
if @cellUpdateTime isnt null and (performance.now()-@cellUpdateTime>@renderTime)
209206
pos=@game.camera.position
210207
cell=@cellTerrain.computeCellForVoxel (Math.floor pos.x),(Math.floor pos.y),(Math.floor pos.z)
208+
@updateRenderOrder cell
211209
@chunkWorker.postMessage {
212210
type:"updateCellsAroundPlayer"
213211
data:[cell,radius]

src/client/scripts/World/chunk.worker.coffee

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ class TerrainManager
108108
normals=[]
109109
uvs=[]
110110
colors=[]
111+
t_positions=[]
112+
t_normals=[]
113+
t_uvs=[]
114+
t_colors=[]
111115
aoColor=(type)->
112116
if type is 0
113117
return [0.9,0.9,0.9]
@@ -119,9 +123,6 @@ class TerrainManager
119123
return [0.3,0.3,0.3]
120124
addFace=(type,pos)->
121125
faceVertex=_this.genBlockFace type,_this.cellTerrain.getBlock(pos...),pos
122-
positions.push faceVertex.pos...
123-
normals.push faceVertex.norm...
124-
uvs.push faceVertex.uv...
125126
# _this.cellTerrain.getBlock(pos[0],pos[1],pos[2])
126127
loaded={}
127128
for x in [-1..1]
@@ -165,8 +166,17 @@ class TerrainManager
165166
col4=aoColor(loaded["0:1:-1"]+loaded["-1:1:-1"]+loaded["-1:0:-1"])
166167
col1=aoColor(loaded["0:-1:-1"]+loaded["1:-1:-1"]+loaded["1:0:-1"])
167168
col2=aoColor(loaded["0:1:-1"]+loaded["1:1:-1"]+loaded["1:0:-1"])
168-
169-
colors.push col1...,col3...,col2...,col2...,col3...,col4...
169+
if _this.cellTerrain.getBlock(pos...).transparent
170+
t_positions.push faceVertex.pos...
171+
t_normals.push faceVertex.norm...
172+
t_uvs.push faceVertex.uv...
173+
t_colors.push col1...,col3...,col2...,col2...,col3...,col4...
174+
else
175+
positions.push faceVertex.pos...
176+
normals.push faceVertex.norm...
177+
uvs.push faceVertex.uv...
178+
colors.push col1...,col3...,col2...,col2...,col3...,col4...
179+
170180
return
171181
for i in [0..@cellSize-1]
172182
for j in [0..@cellSize-1]
@@ -198,6 +208,10 @@ class TerrainManager
198208
addFace "pz",pos
199209
if (@cellTerrain.getBlock(pos[0],pos[1],pos[2]-1).name is "air")
200210
addFace "nz",pos
211+
positions.push t_positions...
212+
normals.push t_normals...
213+
uvs.push t_uvs...
214+
colors.push t_colors...
201215
return {
202216
positions
203217
normals

src/client/scripts/index.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class Game
3939
@renderer=new THREE.WebGLRenderer
4040
canvas:@canvas
4141
PixelRatio:window.devicePixelRatio
42+
@renderer.sortObjects=false
4243
@scene=new THREE.Scene
4344
@dimBg=
4445
"minecraft:overworld":[173/255, 200/255, 255/255]
@@ -213,7 +214,6 @@ class Game
213214
@pii.render()
214215
@inv_bar.tick()
215216
@world.ATA.uni.view.copy(@camera.position).applyMatrix4(@camera.matrixWorldInverse)
216-
217217
@renderer.render @scene, @camera
218218
return
219219
new Game()

src/prebuild.coffee

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,44 +4,45 @@ pBlock=require("prismarine-block")(config.version)
44
atlasCreator=require "./atlasCreator.coffee"
55

66
new atlasCreator {
7-
pref:"items"
8-
toxelSize:50
9-
loadPath:"#{__dirname}/assets/items"
10-
buildPath:"#{__dirname}/client/assets/items"
11-
atlasSize:32
12-
oneFrame:false
7+
pref:"items"
8+
toxelSize:50
9+
loadPath:"#{__dirname}/assets/items"
10+
buildPath:"#{__dirname}/client/assets/items"
11+
atlasSize:32
12+
oneFrame:false
1313
}
1414
new atlasCreator {
15-
pref:"blocks"
16-
toxelSize:16
17-
loadPath:"#{__dirname}/assets/blocks"
18-
buildPath:"#{__dirname}/client/assets/blocks"
19-
atlasSize:36
20-
oneFrame:false
15+
pref:"blocks"
16+
toxelSize:16
17+
loadPath:"#{__dirname}/assets/blocks"
18+
buildPath:"#{__dirname}/client/assets/blocks"
19+
atlasSize:36
20+
oneFrame:false
2121
}
2222
new atlasCreator {
23-
pref:"blocksSnap"
24-
toxelSize:16
25-
loadPath:"#{__dirname}/assets/blocks"
26-
buildPath:"#{__dirname}/client/assets/blocks"
27-
atlasSize:27
28-
oneFrame:true
23+
pref:"blocksSnap"
24+
toxelSize:16
25+
loadPath:"#{__dirname}/assets/blocks"
26+
buildPath:"#{__dirname}/client/assets/blocks"
27+
atlasSize:27
28+
oneFrame:true
2929
}
3030

3131
maxStateId=0
3232
for i in [0..100000]
33-
block=pBlock.fromStateId i
34-
if block.type is undefined
35-
maxStateId=i-1
36-
break
33+
block=pBlock.fromStateId i
34+
if block.type is undefined
35+
maxStateId=i-1
36+
break
3737
console.log "\x1b[33mBlock max stateId: #{maxStateId}\x1b[0m"
3838
result=[]
3939
for i in [0..maxStateId]
40-
if pBlock.fromStateId(i).boundingBox is "block"
41-
bbox=1
42-
else
43-
bbox=0
44-
result.push [pBlock.fromStateId(i).name,bbox]
40+
block=pBlock.fromStateId i
41+
result.push [
42+
block.name
43+
if block.boundingBox is "block" then 1 else 0
44+
if block.transparent then 1 else 0
45+
]
4546
buildPath="#{__dirname}/client/assets/blocks/blocksDef.json"
4647
fs.writeFileSync buildPath, JSON.stringify(result)
4748
console.log "\x1b[32mGenerated blocksDefinitions: #{buildPath}\x1b[0m\n"

0 commit comments

Comments
 (0)