@@ -106,14 +106,14 @@ <h3>Gra zatrzymana</h3>
106106 </ div >
107107 < script src ="js/jq.js?10210281028012 "> </ script >
108108 < script type ="module ">
109- import * as THREE from 'https://threejsfundamentals .org/threejs/resources/threejs/r115 /build/three.module.js' ;
109+ import * as THREE from 'https://threejs .org/build/three.module.js' ;
110110import {
111111 BufferGeometryUtils
112- } from 'https://threejsfundamentals .org/threejs/resources/threejs/r115 /examples/jsm/utils/BufferGeometryUtils.js' ;
113- import Stats from 'https://threejsfundamentals .org/threejs/resources/threejs/r115 /examples/jsm/libs/stats.module.js' ;
112+ } from 'https://threejs .org/examples/jsm/utils/BufferGeometryUtils.js' ;
113+ import Stats from 'https://threejs .org/examples/jsm/libs/stats.module.js' ;
114114
115115import { FirstPersonControls } from './js/fpc.module.js?123' ;
116- import { FBXLoader } from 'https://threejsfundamentals .org/threejs/resources/threejs/r115 /examples/jsm/loaders/FBXLoader.js' ;
116+ import { FBXLoader } from 'https://threejs .org/examples/jsm/loaders/FBXLoader.js' ;
117117
118118//Renderer
119119var canvas = document . querySelector ( '#c' ) ;
@@ -127,15 +127,8 @@ <h3>Gra zatrzymana</h3>
127127// scene.fog= new THREE.Fog(new THREE.Color('lightblue'),50, 64)
128128scene . fog = new THREE . FogExp2 ( 0xffffff , 0.00015 ) ;
129129
130- //clouds
131- var loader = new FBXLoader ( ) ;
132- loader . load ( 'objects/clouds.fbx' , function ( object ) {
133- object . scale . x = 0.1
134- object . scale . y = 0.1
135- object . scale . z = 0.1
136- object . position . y = 100
137- scene . add ( object ) ;
138- } ) ;
130+
131+
139132
140133//Camera
141134var camera = new THREE . PerspectiveCamera ( 75 , 2 , 0.1 , 1000 ) ;
@@ -166,12 +159,40 @@ <h3>Gra zatrzymana</h3>
166159
167160
168161//Textures
169- var texture = new THREE . TextureLoader ( ) . load ( 'Terrain .png' ) ;
162+ var texture = new THREE . TextureLoader ( ) . load ( 'atla .png' ) ;
170163texture . magFilter = THREE . NearestFilter ;
171164
172165var gameState = "menu" ;
173166
174167
168+ //clouds
169+ var loader = new FBXLoader ( ) ;
170+ loader . load ( 'assets/models/clouds.fbx' , function ( object ) {
171+ object . scale . x = 0.1
172+ object . scale . y = 0.1
173+ object . scale . z = 0.1
174+ object . position . y = 100
175+ scene . add ( object ) ;
176+ } ) ;
177+
178+ var stairsGeometry ;
179+ loader . load ( 'assets/models/stairso.fbx' , function ( object ) {
180+ stairsGeometry = object . children [ 0 ] . geometry
181+ stairsGeometry . scale ( 10 , 10 , 10 )
182+ // object.scale.set(0.01,0.01,0.01)
183+ // object.children[0].material=new THREE.MeshLambertMaterial({
184+ // map: texture,
185+ // side: 2
186+ // })
187+ // // var mesh=new THREE.Mesh(object.geometry,object.material);
188+ // object.children[0].index=null
189+
190+
191+ // scene.add(object)
192+ // object.position.set(26,26,26)
193+ } ) ;
194+
195+
175196class Terrain {
176197 constructor ( options ) {
177198 this . textureAtlas = options . textureAtlas ;
@@ -330,14 +351,23 @@ <h3>Gra zatrzymana</h3>
330351 var voxelGeometries = this . generateVoxelGeometry ( x * cellSize + i , y * cellSize + j , z * cellSize + k ) ;
331352 // console.log(voxelGeometries)
332353 for ( var l = 0 ; l < voxelGeometries . length ; l ++ ) {
354+ if ( voxelGeometries [ l ] . index != null ) {
355+ voxelGeometries [ l ] = voxelGeometries [ l ] . toNonIndexed ( )
356+ } else {
357+ console . log ( "NON INDEXED" )
358+ }
333359 geometries . push ( voxelGeometries [ l ] ) ;
360+
334361 }
335362 }
336363 }
337364 }
338365 // console.log(geometries)
339366 if ( geometries . length != 0 ) {
367+ // console.log(geometries)
368+ console . log ( geometries )
340369 var geometry = BufferGeometryUtils . mergeBufferGeometries ( geometries ) ;
370+ // console.log(geometry)
341371 geometry . computeBoundingSphere ( ) ;
342372 } else {
343373 var geometry = null ;
@@ -349,36 +379,49 @@ <h3>Gra zatrzymana</h3>
349379 var voxel = this . getVoxel ( x , y , z ) ;
350380 var matrix = new THREE . Matrix4 ( ) ;
351381 matrix . makeTranslation ( x , y , z ) ;
352- if ( this . blocks [ voxel ] != undefined ) {
353- var geometries = [ ] ;
354- if ( this . getVoxel ( x - 1 , y , z ) == 0 ) {
355- var nxGeometry = this . generateFace ( "nx" , voxel ) ;
356- geometries . push ( nxGeometry . applyMatrix4 ( matrix ) )
357- }
358- if ( this . getVoxel ( x + 1 , y , z ) == 0 ) {
359- var pxGeometry = this . generateFace ( "px" , voxel ) ;
360- geometries . push ( pxGeometry . applyMatrix4 ( matrix ) )
361- }
362- if ( this . getVoxel ( x , y - 1 , z ) == 0 ) {
363- var nyGeometry = this . generateFace ( "ny" , voxel ) ;
364- geometries . push ( nyGeometry . applyMatrix4 ( matrix ) )
365- }
366- if ( this . getVoxel ( x , y + 1 , z ) == 0 ) {
367- var pyGeometry = this . generateFace ( "py" , voxel ) ;
368- geometries . push ( pyGeometry . applyMatrix4 ( matrix ) )
369- }
370- if ( this . getVoxel ( x , y , z - 1 ) == 0 ) {
371- var nzGeometry = this . generateFace ( "nz" , voxel ) ;
372- geometries . push ( nzGeometry . applyMatrix4 ( matrix ) )
373- }
374- if ( this . getVoxel ( x , y , z + 1 ) == 0 ) {
375- var pzGeometry = this . generateFace ( "pz" , voxel ) ;
376- geometries . push ( pzGeometry . applyMatrix4 ( matrix ) )
382+ if ( voxel == 4 ) {
383+ // console.log(stairsGeometry)
384+ var geo = stairsGeometry . clone ( )
385+ geo = geo . applyMatrix4 ( matrix )
386+ geo . translate ( 0 , - 0.25 , 0 )
387+ console . log ( geo )
388+ return [ geo ]
389+
390+
391+
392+ } else {
393+ if ( this . blocks [ voxel ] != undefined ) {
394+ var geometries = [ ] ;
395+ if ( this . getVoxel ( x - 1 , y , z ) == 0 ) {
396+ var nxGeometry = this . generateFace ( "nx" , voxel ) ;
397+ geometries . push ( nxGeometry . applyMatrix4 ( matrix ) )
398+ }
399+ if ( this . getVoxel ( x + 1 , y , z ) == 0 ) {
400+ var pxGeometry = this . generateFace ( "px" , voxel ) ;
401+ geometries . push ( pxGeometry . applyMatrix4 ( matrix ) )
402+ }
403+ if ( this . getVoxel ( x , y - 1 , z ) == 0 ) {
404+ var nyGeometry = this . generateFace ( "ny" , voxel ) ;
405+ geometries . push ( nyGeometry . applyMatrix4 ( matrix ) )
406+ }
407+ if ( this . getVoxel ( x , y + 1 , z ) == 0 ) {
408+ var pyGeometry = this . generateFace ( "py" , voxel ) ;
409+ geometries . push ( pyGeometry . applyMatrix4 ( matrix ) )
410+ }
411+ if ( this . getVoxel ( x , y , z - 1 ) == 0 ) {
412+ var nzGeometry = this . generateFace ( "nz" , voxel ) ;
413+ geometries . push ( nzGeometry . applyMatrix4 ( matrix ) )
414+ }
415+ if ( this . getVoxel ( x , y , z + 1 ) == 0 ) {
416+ var pzGeometry = this . generateFace ( "pz" , voxel ) ;
417+ geometries . push ( pzGeometry . applyMatrix4 ( matrix ) )
418+ }
419+ return geometries ;
420+ } else {
421+ return [ ]
377422 }
378- return geometries ;
379- } else {
380- return [ ]
381423 }
424+
382425 }
383426 generateFace ( type , voxel ) {
384427 var geometry = new THREE . PlaneBufferGeometry ( 1 , 1 ) ;
@@ -546,7 +589,7 @@ <h3>Gra zatrzymana</h3>
546589//Setup inventory bar
547590var inv_bar = new InventoryBar ( {
548591 boxSize : 60 ,
549- boxes : 3 ,
592+ boxes : 4 ,
550593 padding : 4 ,
551594 div : ".inventoryBar" ,
552595 activeBox : 1
@@ -724,6 +767,7 @@ <h3>Gra zatrzymana</h3>
724767 } else {
725768 //Budowanie
726769 world . setVoxel ( positionQ [ 0 ] , positionQ [ 1 ] , positionQ [ 2 ] , inv_bar . activeBox )
770+ // console.log(inv_bar.activeBox)
727771 // console.log(world.cells[world.computeCellId(...positionQ)])
728772 }
729773 }
@@ -737,6 +781,7 @@ <h3>Gra zatrzymana</h3>
737781function animate ( ) {
738782 stats . begin ( ) ;
739783 render ( )
784+ // console.log(renderer.info.render.calls)
740785 stats . end ( ) ;
741786 requestAnimationFrame ( animate )
742787}
0 commit comments