@@ -8,12 +8,10 @@ import {FirstPersonControls} from './FirstPersonControls.js'
88import {gpuInfo} from ' ./gpuInfo.js'
99import {AssetLoader} from ' ./AssetLoader.js'
1010import {InventoryBar} from ' ./InventoryBar.js'
11- import {Players} from ' ./Players.js'
1211import {RandomNick} from ' ./RandomNick.js'
13-
12+ import {GUI} from ' ./jsm/libs/dat.gui.module.js '
1413
1514init = ()->
16- # canvas,renderer,camera,lights
1715 canvas = document .querySelector ' #c'
1816 renderer = new THREE.WebGLRenderer {
1917 canvas
@@ -23,34 +21,29 @@ init = ()->
2321 camera = new THREE.PerspectiveCamera 90 , 2 , 0.1 , 64
2422 camera .rotation .order = " YXZ"
2523 camera .position .set 26 , 26 , 26
26- color = new THREE.Color ( " #adc8ff" )
24+ color = new THREE.Color " #adc8ff"
2725 near = 32
2826 far = 64
29- scene .fog = new THREE.Fog (color, near, far)
30- # skybox
31- loader = new THREE.TextureLoader ();
32- skybox = loader .load " assets/images/skybox.jpg" , () ->
33- rt = new THREE.WebGLCubeRenderTarget skybox .image .height
34- rt .fromEquirectangularTexture renderer, skybox
35- scene .background = rt
36- return
37- # Lights
27+ scene .fog = new THREE.Fog color, near, far
28+
29+ rt = new THREE.WebGLCubeRenderTarget al .get (" skybox" ).image .height
30+ rt .fromEquirectangularTexture renderer, al .get " skybox"
31+ scene .background = rt
32+
3833 ambientLight = new THREE.AmbientLight 0xcccccc
3934 scene .add ambientLight
4035 directionalLight = new THREE.DirectionalLight 0x333333 , 2
4136 directionalLight .position .set (1 , 1 , 0.5 ).normalize ()
4237 scene .add directionalLight
4338 console .warn gpuInfo ()
4439
45- # Clouds
4640 clouds = al .get " clouds"
4741 clouds .scale .x = 0.1
4842 clouds .scale .y = 0.1
4943 clouds .scale .z = 0.1
5044 clouds .position .y = 170
5145 scene .add clouds
5246
53- # setup world
5447 world = new World ({
5548 toxelSize : 27
5649 cellSize : 16
@@ -59,7 +52,6 @@ init = ()->
5952 al
6053 })
6154
62- # Socket.io setup
6355 socket = io .connect " #{ al .get (" host" )} :#{ al .get (" websocket-port" )} "
6456 socket .on " connect" ,()->
6557 console .log " Połączono z serverem!"
@@ -72,32 +64,25 @@ init = ()->
7264 socket .emit " initClient" , {
7365 nick : nick
7466 }
67+ console .log " First Load packet recieved!"
68+ # world.replaceWorld v
69+ $ (" .initLoading" ).css " display" ," none"
70+ stats = new Stats ();
71+ stats .showPanel (0 );
72+ document .body .appendChild stats .dom
7573 return
76- socket .on " blockUpdate" ,(block )->
77- world .setBlock block...
78- return
74+ # socket.on "blockUpdate",(block)->
75+ # world.setBlock block...
76+ # return
7977 socket .on " mapChunk" , (sections ,x ,z )->
8078 world ._computeSections sections,x,z
81- socket .on " botPosition " , (pos )->
79+ socket .on " move " , (pos )->
8280 to = {x : pos .x - 0.5 ,y : pos .y + 17 ,z : pos .z - 0.5 }
8381 new TWEEN.Tween camera .position
84- .to to, 40
82+ .to to, 100
8583 .easing TWEEN .Easing .Quadratic .Out
8684 .start ()
87- players = new Players {socket,scene,al}
88- socket .on " playerUpdate" ,(data )->
89- players .update data
90- return
91- socket .on " firstLoad" ,(v )->
92- console .log " First Load packet recieved!"
93- world .replaceWorld v
94- $ (" .initLoading" ).css " display" ," none"
95- stats = new Stats ();
96- stats .showPanel (0 );
97- document .body .appendChild stats .dom
98- return
9985
100- # Inventory Bar
10186 inv_bar = new InventoryBar ({
10287 boxSize : 60
10388 padding : 4
@@ -114,15 +99,13 @@ init = ()->
11499 " assets/images/tnt.png"
115100 ]).setFocusOnly (1 ).listen ()
116101
117- # First Person Controls
118102 FPC = new FirstPersonControls {
119103 canvas
120104 camera
121105 micromove : 0.3
122106 socket
123107 }
124108
125- # Raycast cursor
126109 cursor = new THREE.LineSegments (
127110 new THREE.EdgesGeometry (
128111 new THREE.BoxGeometry 1 , 1 , 1
@@ -133,28 +116,29 @@ init = ()->
133116 }
134117 )
135118 scene .add cursor
136-
137- # jquery events
138- $ (document ).mousedown (e)->
139- if FPC .gameState is " game"
140- rayBlock = world .getRayBlock ()
141- if rayBlock
142- if e .which is 1
143- voxelId = 0
144- pos = rayBlock .posBreak
145- else
146- voxelId = inv_bar .activeBox
147- pos = rayBlock .posPlace
148- pos[0 ]= Math .floor pos[0 ]
149- pos[1 ]= Math .floor pos[1 ]
150- pos[2 ]= Math .floor pos[2 ]
151- socket .emit " blockUpdate" ,[pos... ,voxelId]
152- return
153-
119+ # $(document).mousedown (e)->
120+ # if FPC.gameState is "game"
121+ # rayBlock=world.getRayBlock()
122+ # if rayBlock
123+ # if e.which is 1
124+ # voxelId=0
125+ # pos=rayBlock.posBreak
126+ # else
127+ # voxelId=inv_bar.activeBox
128+ # pos=rayBlock.posPlace
129+ # pos[0]=Math.floor pos[0]
130+ # pos[1]=Math.floor pos[1]
131+ # pos[2]=Math.floor pos[2]
132+ # socket.emit "blockUpdate",[pos...,voxelId]
133+ # return
134+ gui = new GUI ()
135+ params = {
136+ test : true
137+ }
138+ gui .add ( params, ' test' ).name ( ' test' )
154139 animate ()
155140 return
156141render = ->
157- # Autoresize canvas
158142 width = window .innerWidth
159143 height = window .innerHeight
160144 if canvas .width isnt width or canvas .height isnt height
@@ -164,17 +148,6 @@ render = ->
164148 camera .aspect = width / height
165149 camera .updateProjectionMatrix ()
166150
167- # Player movement
168- if FPC .gameState is " game"
169- socket .emit " playerUpdate" , {
170- x : camera .position .x
171- y : camera .position .y
172- z : camera .position .z
173- xyaw : - camera .rotation .x
174- zyaw : camera .rotation .y + Math .PI
175- }
176-
177- # Update cursor
178151 rayBlock = world .getRayBlock ()
179152 if rayBlock
180153 pos = rayBlock .posBreak
@@ -186,7 +159,6 @@ render = ->
186159 else
187160 cursor .visible = false
188161
189- # Rendering
190162 world .updateCells ()
191163 TWEEN .update ();
192164 renderer .render scene, camera
0 commit comments