44
55 < title > Web-Minecraft</ title >
66
7- < link rel ="icon " href ="https://gamepedia.cursecdn.com/minecraft_gamepedia/6/6a/Grass_Block_JE6_BE5 .png ">
7+ < link rel ="icon " href ="assets/images/grass_block .png ">
88
99 < div css >
1010 < link rel ="stylesheet " href ="https://use.fontawesome.com/releases/v5.8.2/css/all.css ">
@@ -79,6 +79,7 @@ <h3>Gra zatrzymana</h3>
7979
8080import * as THREE from './module/build/three.module.js' ;
8181import { BufferGeometryUtils } from './module/jsm/utils/BufferGeometryUtils.js' ;
82+ import { SkeletonUtils } from './module/jsm/utils/SkeletonUtils.js' ;
8283import Stats from './module/jsm/libs/stats.module.js' ;
8384import { FBXLoader } from './module/jsm/loaders/FBXLoader.js?1' ;
8485
@@ -270,17 +271,10 @@ <h3>Gra zatrzymana</h3>
270271 }
271272 return geometries ;
272273 } else {
273- if ( voxel == 4 ) {
274- var geo = world . models . stairs . clone ( )
275- geo = geo . applyMatrix4 ( matrix )
276- // geo
277- return [ geo ]
278- } else if ( voxel == 5 ) {
279- var geo = world . models . anvil . clone ( )
280- geo = geo . applyMatrix4 ( matrix )
281- // geo.translate(0,-0.25,0)
282- return [ geo ]
283- }
274+ var blockName = this . blocks [ voxel ] . name
275+ var geo = world . models [ blockName ] . clone ( )
276+ geo = geo . applyMatrix4 ( matrix )
277+ return [ geo ]
284278 }
285279 } else {
286280 return [ ]
@@ -318,8 +312,8 @@ <h3>Gra zatrzymana</h3>
318312 var uvX = textureAtlasMapping [ uv ] [ "x" ] - 1
319313 var uvY = 27 - textureAtlasMapping [ uv ] [ "y" ]
320314 } catch ( e ) {
321- var uvX = 1
322- var uvY = 1
315+ var uvX = textureAtlasMapping [ "debug" ] [ "x" ] - 1
316+ var uvY = 27 - textureAtlasMapping [ "debug" ] [ "y" ]
323317 }
324318
325319
@@ -470,7 +464,7 @@ <h3>Gra zatrzymana</h3>
470464 boxSize,
471465 padding
472466 } = this ;
473- console . warn ( "InventoryBar created!" )
467+ // console.warn("InventoryBar created!")
474468 var result = `` ;
475469 for ( var i = 0 ; i < boxes ; i ++ ) {
476470 result += `<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=" width=${ boxSize } height=${ boxSize } style="border:1px solid black" alt="">`
@@ -584,11 +578,9 @@ <h3>Gra zatrzymana</h3>
584578 }
585579}
586580
587- $ . get ( "assets/textureMapping.json" , function ( textureMapping ) {
588- textureAtlasMapping = textureMapping
589- init ( )
590- animate ( )
591- } )
581+ init ( )
582+ animate ( )
583+
592584
593585
594586function init ( ) {
@@ -637,28 +629,33 @@ <h3>Gra zatrzymana</h3>
637629 object . children [ 1 ] . material . map = texturex
638630 object . children [ 1 ] . material . color = new THREE . Color ( 0xffffff ) ;
639631 // object.children[1].scale.set(0.5,0.5,0.5)
632+ console . log ( object )
640633 scene . add ( object )
641- } ) ;
642634
635+ var ghast2 = SkeletonUtils . clone ( object ) ;
636+ scene . add ( ghast2 )
637+ ghast2 . position . set ( 3 , 0 , 0 )
638+ } ) ;
643639
640+ $ . get ( "assets/textureMapping.json" , function ( textureMapping ) {
641+ textureAtlasMapping = textureMapping
642+ } )
644643 world = new Terrain ( {
645644 textureAtlas : texture ,
646645 textureRows : 27 ,
647646 textureCols : 27 ,
648647 cellSize : 16 ,
649648 } )
650- $ . get ( " assets/blocks.json" , function ( blocks ) {
649+ $ . get ( ` assets/blocks.json? ${ uuidv4 ( ) } ` , function ( blocks ) {
651650 world . blocks = blocks
652- loadBlocksModels ( function ( ) {
653- console . log ( world . models )
654- } )
651+ loadBlocksModels ( )
655652 } )
656653
657654
658655
659656 socket = io . connect ( "https://d93db05c1da1.ngrok.io/" ) ;
660657 socket . on ( "connect" , ( ) => {
661- console . log ( "Połączono z serverem socketio " )
658+ console . log ( "Połączono z serverem! " )
662659 socket . emit ( "siemka" , "siemka" )
663660
664661 } )
@@ -673,7 +670,7 @@ <h3>Gra zatrzymana</h3>
673670 if ( playersx [ p ] == undefined && p != socket . id ) {
674671 loader . load ( 'assets/models/player/player.fbx' , function ( object ) {
675672 var texturex = new THREE . TextureLoader ( ) . load ( 'assets/textures/steve.png' ) ;
676- console . log ( "Creating new player:" + p )
673+ // console.log("Creating new player:"+p)
677674 texturex . magFilter = THREE . NearestFilter ;
678675 object . children [ 1 ] . scale . set ( 1 , 1 , 1 )
679676 object . children [ 1 ] . position . set ( 25 , 25 , 25 )
@@ -812,11 +809,11 @@ <h3>Gra zatrzymana</h3>
812809 Object . keys ( blocks ) . forEach ( function ( p ) {
813810 if ( ! blocks [ p ] . isBlock && p != 0 ) {
814811 var modelPath = `assets/models/${ blocks [ p ] . model } ` ;
815- console . log ( blocks [ p ] . name , ": preparing to load model" )
816812 modelsNumber ++ ;
817813 modelsToLoad . push ( blocks [ p ] )
818814 }
819815 } )
816+ // console.table(modelsToLoad)
820817 for ( var i = 0 ; i < modelsToLoad . length ; i ++ ) {
821818 ( function ( ) {
822819 var block = modelsToLoad [ i ] ;
@@ -825,15 +822,17 @@ <h3>Gra zatrzymana</h3>
825822 world . saveModel ( prepareModel ( geometry , block . name ) , block . name )
826823 modelsLoaded ++ ;
827824 if ( modelsLoaded == modelsNumber ) {
828- console . warn ( "DONE! Models loaded!" )
829- f ( ) ;
825+ // console.log("DONE! Models loaded!")
826+ if ( f != null ) {
827+ f ( ) ;
828+ }
829+
830830 }
831831 } ) ;
832832 } ) ( ) ;
833833
834834 }
835835}
836-
837836function prepareModel ( geometry , name ) {
838837 if ( name == "anvil" ) {
839838 geometry . rotateX ( - Math . PI / 2 )
@@ -848,6 +847,12 @@ <h3>Gra zatrzymana</h3>
848847}
849848
850849
850+ function uuidv4 ( ) {
851+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx' . replace ( / [ x y ] / g, function ( c ) {
852+ var r = Math . random ( ) * 16 | 0 , v = c == 'x' ? r : ( r & 0x3 | 0x8 ) ;
853+ return v . toString ( 16 ) ;
854+ } ) ;
855+ }
851856
852857
853858function updateCursor ( ) {
0 commit comments