Skip to content

Commit 5c0f8ad

Browse files
committed
ChunkUpdateConsole
1 parent c2e3079 commit 5c0f8ad

File tree

2 files changed

+35
-46
lines changed

2 files changed

+35
-46
lines changed

index.html

Lines changed: 33 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
<html>
23
<head>
34
<title>Minecraft Renderer</title>
@@ -10,13 +11,11 @@
1011
<body>
1112
<canvas id="c"></canvas>
1213
<script src="js/jq2.js"></script>
13-
<script src="js/1pc.js"></script>
14+
<script src="js/firstPersonControls.js?xd"></script>
1415
<script type="module">
1516

1617
import * as THREE from 'https://threejsfundamentals.org/threejs/resources/threejs/r115/build/three.module.js';
1718
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';
2019

2120

2221
class Terrain{
@@ -116,11 +115,13 @@
116115
})
117116
}
118117
updateCellGeometry(x,y,z){
118+
console.log(`updating Chunk: ${x}:${y}:${z}`)
119119
const {textureAtlas}=this;
120120
if(this.cells[this.parseVec(x,y,z)]==undefined || this.cells[this.parseVec(x,y,z)].needsUpdate){
121121
var mesh=this.cells_meshes[this.parseVec(x,y,z)];
122122
var geometry=this.generateCellGeometry(x,y,z);
123123
if(geometry!=null){
124+
geometry.dynamic = false;
124125
if(mesh!=undefined){
125126
mesh.geometry=geometry;
126127
}else{
@@ -130,6 +131,10 @@
130131
scene.add(mesh)
131132
this.cells_meshes[this.parseVec(x,y,z)]=mesh;
132133
}
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)]
133138
}
134139
try{
135140
this.cells[this.parseVec(x,y,z)].needsUpdate=false;
@@ -269,11 +274,11 @@
269274

270275
scene = new THREE.Scene();
271276
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)
273278

274279
camera = new THREE.PerspectiveCamera(75, 2, 0.1, 1000);
275280
camera.rotation.order="YXZ"
276-
camera.position.set(50,50,50)
281+
camera.position.set(25,25,25)
277282
FirstPersonControls(canvas,camera,0.07)
278283

279284

@@ -282,14 +287,28 @@
282287
raycaster = new THREE.Raycaster();
283288
var mouse = {x:0,y:0};
284289

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+
291311

292-
animate()
293312

294313
function precision(number){
295314
try{
@@ -383,9 +402,6 @@
383402
setInterval(function (){
384403
raycast()
385404
})
386-
setInterval(function (){
387-
world.updateCells()
388-
},100)
389405
$(document).click(function (e){
390406
// console.log(positionQ)
391407
// console.log(cube.position)
@@ -398,35 +414,7 @@
398414

399415
})
400416

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()
430418

431419

432420
function animate() {
@@ -453,6 +441,7 @@
453441
camera.updateProjectionMatrix();
454442
}
455443
renderer.render(scene, camera);
444+
world.updateCells()
456445

457446
// composer.render();
458447
}

js/1pc.js renamed to js/firstPersonControls.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ function FirstPersonControls(_canvas,_camera,_micromove){
8080
$("#xxdd").attr("style","position:fixed;top:0px;left:0px")
8181
p.width=window.innerWidth
8282
p.height=window.innerHeight
83-
var cw=25;
84-
ctx.lineWidth=3
83+
var cw=15;
84+
ctx.lineWidth=1
8585
ctx.beginPath();
8686
ctx.moveTo(window.innerWidth/2-cw,window.innerHeight/2);
8787
ctx.lineTo(window.innerWidth/2+cw,window.innerHeight/2);

0 commit comments

Comments
 (0)