mapserver/static/js/test.js

95 lines
2.2 KiB
JavaScript
Raw Normal View History

2019-05-05 18:33:09 +03:00
var camera, scene, renderer;
2019-12-13 13:03:34 +03:00
var geometry;
2019-05-05 18:33:09 +03:00
init();
animate();
2019-05-05 18:44:30 +03:00
function getNodePos(x,y,z){ return x + (y * 16) + (z * 256); }
2019-05-05 18:33:09 +03:00
2019-12-13 13:03:34 +03:00
function drawMapblock(posx,posy,posz,colormapping){
m.request("api/viewblock/"+posx+"/"+posy+"/"+posz)
2019-05-05 18:33:09 +03:00
.then(function(mapblock){
2019-05-05 18:44:30 +03:00
if (!mapblock)
return;
2019-05-05 18:33:09 +03:00
for (var x=0; x<16; x++){
for (var y=0; y<16; y++){
for (var z=0; z<16; z++){
var i = getNodePos(x,y,z);
2019-12-13 13:03:34 +03:00
var contentId = mapblock.contentid[i];
2019-05-05 18:33:09 +03:00
var nodeName = mapblock.blockmapping[contentId]
var colorObj = colormapping[nodeName];
if (!colorObj)
continue;
var color = new THREE.Color( colorObj.r/256, colorObj.g/256, colorObj.b/256 );
var material = new THREE.MeshBasicMaterial( { color: color } );
var mesh = new THREE.Mesh( geometry, material );
2019-05-05 18:44:30 +03:00
mesh.position.x = (x*3) + (posx*3*16);
mesh.position.y = (y*3) + (posy*3*16);
mesh.position.z = (z*3) + (posz*3*16);
2019-05-05 18:33:09 +03:00
scene.add( mesh );
}
}
}
2019-05-05 18:44:30 +03:00
});
}
function init() {
camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 2, 2000 );
camera.position.z = 30;
camera.position.y = 10;
scene = new THREE.Scene();
geometry = new THREE.BoxGeometry( 3, 3, 3 );
m.request("api/colormapping")
2019-12-13 13:03:34 +03:00
.then(function(colormapping){
for (var x=0; x<14; x++){
2019-05-05 18:47:06 +03:00
for (var y=0; y<2; y++){
2019-05-05 18:44:30 +03:00
for (var z=-4; z<4; z++){
2019-12-13 13:03:34 +03:00
drawMapblock(x,y,z,colormapping);
2019-05-05 18:44:30 +03:00
}
}
}
2019-05-05 18:33:09 +03:00
});
renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
controls = new THREE.TrackballControls( camera, renderer.domElement );
controls.rotateSpeed = 1.0;
controls.zoomSpeed = 1.2;
controls.panSpeed = 0.8;
controls.noZoom = false;
controls.noPan = false;
controls.staticMoving = true;
controls.dynamicDampingFactor = 0.3;
controls.keys = [ 65, 83, 68 ];
controls.addEventListener( 'change', render );
render();
}
function render(){
renderer.render( scene, camera );
}
function animate() {
requestAnimationFrame( animate );
controls.update();
}