@@ -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-
697706function 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