|
| 1 | + |
1 | 2 | <html> |
2 | 3 | <head> |
3 | 4 | <title>Minecraft Renderer</title> |
|
10 | 11 | <body> |
11 | 12 | <canvas id="c"></canvas> |
12 | 13 | <script src="js/jq2.js"></script> |
13 | | - <script src="js/1pc.js"></script> |
| 14 | + <script src="js/firstPersonControls.js?xd"></script> |
14 | 15 | <script type="module"> |
15 | 16 |
|
16 | 17 | import * as THREE from 'https://threejsfundamentals.org/threejs/resources/threejs/r115/build/three.module.js'; |
17 | 18 | import { BufferGeometryUtils } from 'https://threejsfundamentals.org/threejs/resources/threejs/r115/examples/jsm/utils/BufferGeometryUtils.js'; |
18 | | -import { EffectComposer } from 'https://threejsfundamentals.org/threejs/resources/threejs/r115/examples/jsm/postprocessing/EffectComposer.js'; |
19 | | - import { SSAOPass } from 'https://threejsfundamentals.org/threejs/resources/threejs/r115/examples/jsm/postprocessing/SSAOPass.js'; |
20 | 19 |
|
21 | 20 |
|
22 | 21 | class Terrain{ |
|
116 | 115 | }) |
117 | 116 | } |
118 | 117 | updateCellGeometry(x,y,z){ |
| 118 | + console.log(`updating Chunk: ${x}:${y}:${z}`) |
119 | 119 | const {textureAtlas}=this; |
120 | 120 | if(this.cells[this.parseVec(x,y,z)]==undefined || this.cells[this.parseVec(x,y,z)].needsUpdate){ |
121 | 121 | var mesh=this.cells_meshes[this.parseVec(x,y,z)]; |
122 | 122 | var geometry=this.generateCellGeometry(x,y,z); |
123 | 123 | if(geometry!=null){ |
| 124 | + geometry.dynamic = false; |
124 | 125 | if(mesh!=undefined){ |
125 | 126 | mesh.geometry=geometry; |
126 | 127 | }else{ |
|
130 | 131 | scene.add(mesh) |
131 | 132 | this.cells_meshes[this.parseVec(x,y,z)]=mesh; |
132 | 133 | } |
| 134 | + }else{ |
| 135 | + scene.remove(this.cells_meshes[this.parseVec(x,y,z)]) |
| 136 | + delete this.cells_meshes[this.parseVec(x,y,z)] |
| 137 | + delete this.cells[this.parseVec(x,y,z)] |
133 | 138 | } |
134 | 139 | try{ |
135 | 140 | this.cells[this.parseVec(x,y,z)].needsUpdate=false; |
|
269 | 274 |
|
270 | 275 | scene = new THREE.Scene(); |
271 | 276 | scene.background = new THREE.Color('lightblue'); |
272 | | -scene.fog= new THREE.Fog(new THREE.Color('lightblue'),50, 64) |
| 277 | +// scene.fog= new THREE.Fog(new THREE.Color('lightblue'),50, 64) |
273 | 278 |
|
274 | 279 | camera = new THREE.PerspectiveCamera(75, 2, 0.1, 1000); |
275 | 280 | camera.rotation.order="YXZ" |
276 | | -camera.position.set(50,50,50) |
| 281 | +camera.position.set(25,25,25) |
277 | 282 | FirstPersonControls(canvas,camera,0.07) |
278 | 283 |
|
279 | 284 |
|
|
282 | 287 | raycaster = new THREE.Raycaster(); |
283 | 288 | var mouse = {x:0,y:0}; |
284 | 289 |
|
285 | | -var composer = new EffectComposer( renderer ); |
286 | | -var ssaoPass = new SSAOPass( scene, camera, window.innerWidth, window.innerHeight ); |
287 | | - ssaoPass.kernelRadius = 8; |
288 | | - ssaoPass.minDistance = 0.001; |
289 | | - ssaoPass.maxDistance=0.3 |
290 | | - composer.addPass( ssaoPass ); |
| 290 | +var texture = new THREE.TextureLoader().load( 'atla.png' ); |
| 291 | +texture.magFilter = THREE.NearestFilter; |
| 292 | +var world=new Terrain({ |
| 293 | + textureAtlas:texture, |
| 294 | + textureRows:16, |
| 295 | + textureCols:16, |
| 296 | + cellSize:16, |
| 297 | +}) |
| 298 | +var vari=50 |
| 299 | +for (let y = 0; y < vari; ++y) { |
| 300 | + for (let z = 0; z < vari; ++z) { |
| 301 | + for (let x = 0; x < vari; ++x) { |
| 302 | + const height = (Math.sin(x / vari * Math.PI * 2) + Math.sin(z / vari * Math.PI * 3)) * (vari / 6) + (vari / 2); |
| 303 | + if (y < height) { |
| 304 | + world.setVoxel(x, y, z, 2); |
| 305 | + } |
| 306 | + } |
| 307 | + } |
| 308 | +} |
| 309 | + |
| 310 | + |
291 | 311 |
|
292 | | -animate() |
293 | 312 |
|
294 | 313 | function precision(number){ |
295 | 314 | try{ |
|
383 | 402 | setInterval(function (){ |
384 | 403 | raycast() |
385 | 404 | }) |
386 | | -setInterval(function (){ |
387 | | - world.updateCells() |
388 | | -},100) |
389 | 405 | $(document).click(function (e){ |
390 | 406 | // console.log(positionQ) |
391 | 407 | // console.log(cube.position) |
|
398 | 414 |
|
399 | 415 | }) |
400 | 416 |
|
401 | | - |
402 | | -var texture = new THREE.TextureLoader().load( 'atla.png' ); |
403 | | -texture.magFilter = THREE.NearestFilter; |
404 | | -var world=new Terrain({ |
405 | | - textureAtlas:texture, |
406 | | - textureRows:16, |
407 | | - textureCols:16, |
408 | | - cellSize:16, |
409 | | -}) |
410 | | -var vari=100 |
411 | | -for (let y = 0; y < vari; ++y) { |
412 | | - for (let z = 0; z < vari; ++z) { |
413 | | - for (let x = 0; x < vari; ++x) { |
414 | | - const height = (Math.sin(x / vari * Math.PI * 2) + Math.sin(z / vari * Math.PI * 3)) * (vari / 6) + (vari / 2); |
415 | | - if (y < height) { |
416 | | - world.setVoxel(x, y, z, 2); |
417 | | - } |
418 | | - } |
419 | | - } |
420 | | -} |
421 | | -// // console.log(world.cells["0:0:0"]) |
422 | | -// for(var i=0;i<5;i++){ |
423 | | -// for(var j=0;j<5;j++){ |
424 | | -// for(var k=0;k<5;k++){ |
425 | | -// world.updateCellGeometry(i,j,k); |
426 | | -// } |
427 | | -// } |
428 | | -// } |
429 | | -world.updateCells() |
| 417 | +animate() |
430 | 418 |
|
431 | 419 |
|
432 | 420 | function animate() { |
|
453 | 441 | camera.updateProjectionMatrix(); |
454 | 442 | } |
455 | 443 | renderer.render(scene, camera); |
| 444 | + world.updateCells() |
456 | 445 |
|
457 | 446 | // composer.render(); |
458 | 447 | } |
|
0 commit comments