Skip to content

Commit a627f5e

Browse files
committed
fixCells
1 parent 5c0f8ad commit a627f5e

File tree

7 files changed

+86
-51298
lines changed

7 files changed

+86
-51298
lines changed

atlas-mc.jpg

-32.8 KB
Binary file not shown.

atlas.png

-3.81 KB
Binary file not shown.

atlasz.png

-109 KB
Binary file not shown.

index.html

Lines changed: 86 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,57 @@
44
<title>Minecraft Renderer</title>
55
<style>
66
body { margin: 0; }
7-
canvas { display: block; width:100%;height:100%;}
7+
canvas {
8+
display: block;
9+
width:100%;
10+
height:100%;
11+
position:fixed;
12+
top:0px;
13+
left:0px
14+
}
15+
.inventoryBar{
16+
position:fixed;
17+
bottom:0px;
18+
left:50%;
19+
width:378px;
20+
background:black;
21+
margin-left:-189px;
22+
height:40px;
23+
}
24+
.icell{
25+
margin:1px;
26+
padding:0px;
27+
border:0px;
28+
width:40px;
29+
height:40px;
30+
}
31+
.cross{
32+
z-index:999999999;
33+
position:fixed;
34+
top:50%;
35+
left:50%;
36+
margin-top:-15px;
37+
margin-left:-15px;
38+
}
839

940
</style>
1041
</head>
1142
<body>
1243
<canvas id="c"></canvas>
13-
<script src="js/jq2.js"></script>
14-
<script src="js/firstPersonControls.js?xd"></script>
44+
<div class="gui">
45+
<div class="inventoryBar">
46+
<img class="icell"><img class="icell"><img class="icell"><img class="icell"><img class="icell"><img class="icell"><img class="icell"><img class="icell"><img class="icell">
47+
</div>
48+
<div class="cross">
49+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
50+
<line x1="15" y1="0" x2="15" y2="30" stroke="black" stroke-width="1" />
51+
<line x1="0" y1="15" x2="30" y2="15" stroke="black" stroke-width="1" />
52+
</svg>
53+
</div>
54+
</div>
55+
<script src="js/jq.js?10210281028012"></script>
56+
<script src="js/firstPersonControls.js?912912"></script>
1557
<script type="module">
16-
1758
import * as THREE from 'https://threejsfundamentals.org/threejs/resources/threejs/r115/build/three.module.js';
1859
import { BufferGeometryUtils } from 'https://threejsfundamentals.org/threejs/resources/threejs/r115/examples/jsm/utils/BufferGeometryUtils.js';
1960

@@ -78,8 +119,9 @@
78119
if(this.cells[cellId]!=undefined){
79120
this.cells[cellId][this.parseVec(...voxel)]=v;
80121
}else{
81-
this.cells[cellId]={};
82-
this.cells[cellId][this.parseVec(...voxel)]=v;
122+
this.cells[cellId]={
123+
[this.parseVec(...voxel)]:v
124+
};
83125
}
84126
this.cells[cellId].needsUpdate=true;
85127
// console.log(this.neighbours)
@@ -115,9 +157,9 @@
115157
})
116158
}
117159
updateCellGeometry(x,y,z){
118-
console.log(`updating Chunk: ${x}:${y}:${z}`)
160+
console.warn(`updating Chunk: ${x}:${y}:${z}`)
119161
const {textureAtlas}=this;
120-
if(this.cells[this.parseVec(x,y,z)]==undefined || this.cells[this.parseVec(x,y,z)].needsUpdate){
162+
if( this.cells[this.parseVec(x,y,z)].needsUpdate){
121163
var mesh=this.cells_meshes[this.parseVec(x,y,z)];
122164
var geometry=this.generateCellGeometry(x,y,z);
123165
if(geometry!=null){
@@ -134,7 +176,7 @@
134176
}else{
135177
scene.remove(this.cells_meshes[this.parseVec(x,y,z)])
136178
delete this.cells_meshes[this.parseVec(x,y,z)]
137-
delete this.cells[this.parseVec(x,y,z)]
179+
// delete this.cells[this.parseVec(x,y,z)]
138180
}
139181
try{
140182
this.cells[this.parseVec(x,y,z)].needsUpdate=false;
@@ -264,6 +306,12 @@
264306
}
265307

266308
}
309+
class Inventory{
310+
constructor(options){
311+
this.cellSize=options.cellSize;
312+
this.windows=options.windows;
313+
}
314+
}
267315
var canvas,renderer,scene,camera,raycaster;
268316

269317

@@ -279,7 +327,7 @@
279327
camera = new THREE.PerspectiveCamera(75, 2, 0.1, 1000);
280328
camera.rotation.order="YXZ"
281329
camera.position.set(25,25,25)
282-
FirstPersonControls(canvas,camera,0.07)
330+
FirstPersonControls(document.getElementById("cross"),camera,0.07)
283331

284332

285333
var ambientLight = new THREE.AmbientLight( 0xcccccc );
@@ -295,7 +343,18 @@
295343
textureCols:16,
296344
cellSize:16,
297345
})
298-
var vari=50
346+
var vari=100
347+
// for(var i=0;i<vari;i++){
348+
// for(var j=0;j<vari;j++){
349+
// for(var k=0;k<vari;k++){
350+
// world.setVoxel(i,j,k,2)
351+
// }
352+
// }
353+
// }
354+
// console.log(world.cells["1:1:1"])
355+
// setTimeout(function (){
356+
// console.log(world.cells["1:1:1"])
357+
// },2000)
299358
for (let y = 0; y < vari; ++y) {
300359
for (let z = 0; z < vari; ++z) {
301360
for (let x = 0; x < vari; ++x) {
@@ -322,12 +381,16 @@
322381
var geometry = new THREE.BoxGeometry( 1, 1, 1 );
323382
// var material = new THREE.MeshBasicMaterial( {color: 0x00ff00} );
324383
var edges = new THREE.EdgesGeometry( geometry );
325-
var cube = new THREE.LineSegments( edges, new THREE.LineBasicMaterial( { color: 0x000000,linewidth:1 } ) );
384+
var cube = new THREE.LineSegments( edges, new THREE.LineBasicMaterial( { color: 0x000000,linewidth:0.5 } ) );
385+
// var cube=new THREE.Mesh()
386+
326387
var positionQ=[]
327388
// cube.material.visible=false;
389+
var selected=false;
328390
scene.add( cube );
329391
function raycast(){
330392
raycaster.setFromCamera( mouse, camera );
393+
raycaster.far=10
331394
// calculate objects intersecting the picking ray
332395
var intersects = raycaster.intersectObjects( scene.children );
333396
var miniDist=-1
@@ -346,6 +409,7 @@
346409

347410
}
348411
if(mini!=null){
412+
selected=true;
349413
cube.visible=true;
350414
var xd=Math.round(mini.point.x)
351415
var yd=Math.round(mini.point.y)
@@ -394,6 +458,7 @@
394458
}
395459
// console.log(mini.point)
396460
}else{
461+
selected=false;
397462
cube.visible=false;
398463
}
399464

@@ -405,13 +470,18 @@
405470
$(document).click(function (e){
406471
// console.log(positionQ)
407472
// console.log(cube.position)
408-
if(e.which==1){
409-
world.setVoxel(cube.position.x,cube.position.y,cube.position.z,0)
473+
if(selected){
474+
if(e.which==1){
475+
world.setVoxel(cube.position.x,cube.position.y,cube.position.z,0)
476+
}else{
477+
world.setVoxel(positionQ[0],positionQ[1],positionQ[2],1)
478+
// console.log(world.cells[world.computeCellId(...positionQ)])
479+
}
410480
}else{
411-
412-
world.setVoxel(positionQ[0],positionQ[1],positionQ[2],1)
481+
console.error("Jesteś za daleko!")
413482
}
414483

484+
415485
})
416486

417487
animate()

js/firstPersonControls.js

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -74,20 +74,4 @@ function FirstPersonControls(_canvas,_camera,_micromove){
7474
$(document).keyup(function (z){
7575
delete keys[z.keyCode];
7676
})
77-
$('body').append("<canvas id='xxdd'></canvas>")
78-
var p=document.getElementById("xxdd");
79-
var ctx=p.getContext("2d");
80-
$("#xxdd").attr("style","position:fixed;top:0px;left:0px")
81-
p.width=window.innerWidth
82-
p.height=window.innerHeight
83-
var cw=15;
84-
ctx.lineWidth=1
85-
ctx.beginPath();
86-
ctx.moveTo(window.innerWidth/2-cw,window.innerHeight/2);
87-
ctx.lineTo(window.innerWidth/2+cw,window.innerHeight/2);
88-
ctx.stroke();
89-
ctx.beginPath();
90-
ctx.moveTo(window.innerWidth/2,window.innerHeight/2-cw);
91-
ctx.lineTo(window.innerWidth/2,window.innerHeight/2+cw);
92-
ctx.stroke()
9377
}
File renamed without changes.

0 commit comments

Comments
 (0)