Skip to content

Commit 9174b42

Browse files
committed
ghastTest
1 parent b314618 commit 9174b42

File tree

6 files changed

+148
-57
lines changed

6 files changed

+148
-57
lines changed

assets/blocks.json

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
{
2+
"0":{
3+
"name":"air",
4+
"isBlock":false
5+
},
6+
"1": {
7+
"name":"grass",
8+
"isBlock":true,
9+
"faces": {
10+
"nx": "grass_block_side",
11+
"ny": "grass_block_top",
12+
"nz": "grass_block_side",
13+
"px": "grass_block_side",
14+
"py": "grass_block_top",
15+
"pz": "grass_block_side"
16+
}
17+
},
18+
"2": {
19+
"name":"stone",
20+
"isBlock":true,
21+
"faces": {
22+
"nx": "stone",
23+
"ny": "stone",
24+
"nz": "stone",
25+
"px": "stone",
26+
"py": "stone",
27+
"pz": "stone"
28+
}
29+
},
30+
"3": {
31+
"name":"oak_planks",
32+
"isBlock":true,
33+
"faces": {
34+
"nx": "oak_planks",
35+
"ny": "oak_planks",
36+
"nz": "oak_planks",
37+
"px": "oak_planks",
38+
"py": "oak_planks",
39+
"pz": "oak_planks"
40+
}
41+
},
42+
"4": {
43+
"name":"stairs",
44+
"isBlock":false,
45+
"model":"stairs/stairs.fbx"
46+
},
47+
"5": {
48+
"name":"anvil",
49+
"isBlock":false,
50+
"model":"anvil/anvil.fbx"
51+
},
52+
"6": {
53+
"name":"brick",
54+
"isBlock":true,
55+
"faces": {
56+
"nx": "bricks",
57+
"ny": "bricks",
58+
"nz": "bricks",
59+
"px": "bricks",
60+
"py": "bricks",
61+
"pz": "bricks"
62+
}
63+
},
64+
"7": {
65+
"name":"furnace",
66+
"isBlock":true,
67+
"faces": {
68+
"nx": "furnace_side",
69+
"ny": "furnace_top",
70+
"nz": "furnace_side",
71+
"px": "furnace_side",
72+
"py": "furnace_top",
73+
"pz": "furnace_front"
74+
}
75+
},
76+
"8": {
77+
"name":"library",
78+
"isBlock":true,
79+
"faces": {
80+
"nx": "bookshelf",
81+
"ny": "oak_planks",
82+
"nz": "bookshelf",
83+
"px": "bookshelf",
84+
"py": "oak_planks",
85+
"pz": "bookshelf"
86+
}
87+
},
88+
"9": {
89+
"name":"tnt",
90+
"isBlock":true,
91+
"faces": {
92+
"nx": "tnt_side",
93+
"ny": "tnt_bottom",
94+
"nz": "tnt_side",
95+
"px": "tnt_side",
96+
"py": "tnt_top",
97+
"pz": "tnt_side"
98+
}
99+
}
100+
}

assets/models/ghast/ghast.blend

981 KB
Binary file not shown.

assets/models/ghast/ghast.fbx

120 KB
Binary file not shown.

assets/textures/ghast.png

686 Bytes
Loading

index.html

Lines changed: 48 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,10 @@ <h3>Gra zatrzymana</h3>
102102
[0, 1, 0],
103103
[0, 0, -1],
104104
[0, 0, 1]
105-
],
105+
]
106106
this.blocks = {
107-
0: {
107+
0:{
108+
name:"air",
108109
isSolid:false
109110
},
110111
1: {
@@ -336,18 +337,9 @@ <h3>Gra zatrzymana</h3>
336337
var voxel = this.getVoxel(x, y, z);
337338
var matrix = new THREE.Matrix4();
338339
matrix.makeTranslation(x, y, z);
339-
if(voxel==4){
340-
var geo=stairsGeometry.clone()
341-
geo=geo.applyMatrix4(matrix)
342-
geo.translate(0,-0.25,0)
343-
return [geo]
344-
}else if(voxel==5){
345-
var geo=anvilGeometry.clone()
346-
geo=geo.applyMatrix4(matrix)
347-
geo.translate(0,-0.25,0)
348-
return [geo]
349-
}else{
350-
if (voxel!=0 && voxel!=4) {
340+
if(voxel){
341+
if(this.blocks[voxel].isSolid){
342+
//Normal block
351343
var geometries = [];
352344
if (!this.blocks[this.getVoxel(x - 1, y, z)].isSolid) {
353345
var nxGeometry = this.generateFace("nx", voxel);
@@ -374,10 +366,23 @@ <h3>Gra zatrzymana</h3>
374366
geometries.push(pzGeometry.applyMatrix4(matrix))
375367
}
376368
return geometries;
377-
} else {
378-
return []
369+
}else{
370+
if(voxel==4){
371+
var geo=stairsGeometry.clone()
372+
geo=geo.applyMatrix4(matrix)
373+
geo.translate(0,-0.25,0)
374+
return [geo]
375+
}else if(voxel==5){
376+
var geo=anvilGeometry.clone()
377+
geo=geo.applyMatrix4(matrix)
378+
geo.translate(0,-0.25,0)
379+
return [geo]
380+
}
379381
}
382+
}else{
383+
return []
380384
}
385+
381386
}
382387
generateFace(type, voxel) {
383388
var geometry = new THREE.PlaneBufferGeometry(1, 1);
@@ -682,18 +687,22 @@ <h3>Gra zatrzymana</h3>
682687
}
683688
}
684689

690+
$.get("assets/blocks.json",function (blocks){
691+
Object.keys(blocks).forEach(function (p){
692+
if(!blocks[p].isBlock){
693+
console.log(blocks[p].name,"isn't a solid block")
694+
}
695+
})
696+
})
685697

686-
687-
$.get("assets/textures/textureMapping.json",function (data){
688-
textureAtlasMapping=data
689-
console.log(data["bricks"].x)
698+
$.get("assets/textureMapping.json",function (textureMapping){
699+
textureAtlasMapping=textureMapping
690700
init()
691701
animate()
702+
692703
})
693704

694705

695-
696-
697706
function init(){
698707
socket=io.connect("https://d93db05c1da1.ngrok.io/");
699708
socket.on("connect",()=>{
@@ -732,13 +741,8 @@ <h3>Gra zatrzymana</h3>
732741
playersx[p].children[1].children[0].children[0].children[0].children[2].rotation.x=players[p].xyaw;
733742
playersx[p].children[1].children[0].rotation.z=players[p].zyaw
734743
}catch(e){}
735-
736-
// setInterval(function (){
737-
// object.children[1].children[0].children[0].children[0].children[2].rotation.x=-camera.rotation.x
738-
// object.children[1].children[0].rotation.z=camera.rotation.y+Math.PI
739-
// })
740744
})
741-
// console.log(players)
745+
742746
Object.keys(playersx).forEach(function (p){
743747
if(sockets[p]==undefined){
744748
scene.remove(playersx[p]);
@@ -797,42 +801,29 @@ <h3>Gra zatrzymana</h3>
797801
anvilGeometry.rotateX(-Math.PI/2)
798802
anvilGeometry.translate(0,0.17,0)
799803
});
800-
801-
// loader.load( 'assets/models/player.fbx', function ( object ) {
802-
// // object.scale.set(0.01,0.01,0.01)
803-
// // console.log(object)
804-
// var texturex = new THREE.TextureLoader().load('assets/textures/steve.png');
805-
// texturex.magFilter = THREE.NearestFilter;
806-
807-
// object.children[1].scale.set(1,1,1)
808-
// object.children[1].position.set(25,25,25)
809-
// object.children[0].material.map=texturex
810-
// object.children[0].material.color=new THREE.Color( 0xffffff );
811-
// object.children[1].scale.set(0.5,0.5,0.5)
812-
// setInterval(function (){
813-
// object.children[1].children[0].children[0].children[0].children[2].rotation.x=-camera.rotation.x
814-
// object.children[1].children[0].rotation.z=camera.rotation.y+Math.PI
815-
// })
816-
// scene.add(object)
817-
// });
804+
loader.load( 'assets/models/ghast/ghast.fbx', function ( object ) {
805+
var texturex = new THREE.TextureLoader().load('assets/textures/ghast.png');
806+
console.log("Creating new player:")
807+
texturex.magFilter = THREE.NearestFilter;
808+
object.children[0].children[0].scale.set(0.01,0.01,0.01)
809+
// object.children[1].position.set(25,25,25)
810+
object.children[1].material.map=texturex
811+
object.children[1].material.color=new THREE.Color( 0xffffff );
812+
// object.children[1].scale.set(0.5,0.5,0.5)
813+
console.log(object)
814+
scene.add(object)
815+
var x2=object.clone()
816+
scene.add(x2)
817+
x2.children[0].position.set(0,0,0)
818+
});
818819

819820
world = new Terrain({
820821
textureAtlas: texture,
821822
textureRows: 27,
822823
textureCols: 27,
823824
cellSize: 16,
824825
})
825-
// var vari=50
826-
// for (let y = 0; y < vari; ++y) {
827-
// for (let z = 0; z < vari; ++z) {
828-
// for (let x = 0; x < vari; ++x) {
829-
// const height = (Math.sin(x / vari * Math.PI * 2) + Math.sin(z / vari * Math.PI * 3)) * (vari / 6) + (vari / 2);
830-
// if (y < height) {
831-
// world.setVoxel(x, y, z, 2);
832-
// }
833-
// }
834-
// }
835-
// }
826+
836827
var inv_bar = new InventoryBar({
837828
boxSize: 60,
838829
boxes: 9,

0 commit comments

Comments
 (0)