374 lines
12 KiB
HTML
374 lines
12 KiB
HTML
|
|
|
|
<html>
|
|
<head>
|
|
<title>Lion</title>
|
|
<style>canvas { width: 100%; height: 100% }</style>
|
|
</head>
|
|
<body style="margin: 0; padding: 0">
|
|
|
|
<style type="text/css">
|
|
|
|
.info{
|
|
color:white;
|
|
font-weight: bold;
|
|
text-shadow: 1px 1px 1px black,
|
|
1px -1px 1px black,
|
|
-1px 1px 1px black,
|
|
-1px -1px 1px black;
|
|
}
|
|
|
|
a:hover, a:visited, a:link, a:active{
|
|
color: #ccccff;
|
|
text-decoration: none;
|
|
}
|
|
|
|
</style>
|
|
|
|
<script src="../libs/three.js/build/three.js"></script>
|
|
<script src="../libs/other/OrbitControls.js"></script>
|
|
<script src="../libs/other/stats.min.js"></script>
|
|
<script src="../libs/other/dat.gui.min.js"></script>
|
|
|
|
<script src="../build/js/potree.min.js"></script>
|
|
<script src="../src/PointCloudOctree.js"></script>
|
|
<script src="../src/FloatingOrigin.js"></script>
|
|
<script src="../src/TextSprite.js"></script>
|
|
<script src="../src/utils/LabelHelper.js"></script>
|
|
|
|
|
|
<div id="lblNumVisibleNodes" class="info" style="position: absolute; left: 10px; top: 80px; width: 400px; color:white"></div>
|
|
<div id="lblNumVisiblePoints" class="info" style="position: absolute; left: 10px; top: 100px; width: 400px; color:white"></div>
|
|
<div id="lblCamOffset" class="info" style="position: absolute; left: 10px; top: 120px; width: 400px; color:white"></div>
|
|
<div id="buttons" style="position: absolute; left: 10px; top: 140px; width: 400px; color:white">
|
|
<input type="button" value="calculateProfile" onmousedown="calculateProfile()"/>
|
|
</div>
|
|
<div id="waypoints" class="info" style="position: absolute; left: 10px; top: 200px; width: 400px; color:white; border: 1px solid black"></div>
|
|
|
|
<div class="info" style="position: absolute; left: 300px; right: 300px; top: 10px; text-align: center;">
|
|
<a href="http://potree.org" target="_blank">potree.org</a><br>
|
|
</div>
|
|
|
|
<script>
|
|
var States = {
|
|
DEFAULT: 1,
|
|
PICKING: 2
|
|
};
|
|
|
|
var defaultPointSize = 0.04;
|
|
var defaultLOD = 15;
|
|
var pointcloudPath = "../resources/pointclouds/lion_takanawa/cloud_bin.js";
|
|
|
|
var renderer;
|
|
var camera;
|
|
var scene, sceneTools, sceneHUD;
|
|
var cameraHUD;
|
|
var pointclouds = [];
|
|
var milestones = [];
|
|
var skybox;
|
|
var stats;
|
|
var clock = new THREE.Clock();
|
|
var materials = {};
|
|
var floatingOrigin;
|
|
var iLabel;
|
|
var mouse = { x: 1, y: 1 };
|
|
var state = States.default;
|
|
var sConnection;
|
|
var profileFrustum;
|
|
var profile;
|
|
|
|
var rtProfile = new THREE.WebGLRenderTarget( 1024, 1024, { minFilter: THREE.LinearFilter, magFilter: THREE.NearestFilter, format: THREE.RGBFormat } );
|
|
|
|
function calculateProfile(centroid, forward, side, width, height, depth){
|
|
|
|
//var start = new THREE.Vector3(-8, -2, 3 + 2*Math.sin(clock.getElapsedTime()));
|
|
//var end = new THREE.Vector3(5, -2, 3 + 2*Math.sin(clock.getElapsedTime()));
|
|
//
|
|
//var width = 0.2;
|
|
//var depth = 0;
|
|
//
|
|
////var points = pointclouds[0].getProfile(start, end, width, depth);
|
|
//
|
|
//if(sConnection === undefined){
|
|
// var lc = new THREE.Color( 0xff0000 );
|
|
// var lineGeometry = new THREE.Geometry();
|
|
// lineGeometry.vertices.push(start.clone(), end.clone());
|
|
// lineGeometry.colors.push(lc, lc, lc);
|
|
// var lineMaterial = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors } );
|
|
// //lineMaterial.depthTest = false;
|
|
// sConnection = new THREE.Line(lineGeometry, lineMaterial);
|
|
// scene.add(sConnection);
|
|
//}else{
|
|
// sConnection.geometry.vertices[0].copy(start);
|
|
// sConnection.geometry.vertices[1].copy(end);
|
|
// sConnection.geometry.verticesNeedUpdate = true;
|
|
//}
|
|
//
|
|
//
|
|
//var geometry = new THREE.SphereGeometry(0.1, 8, 8);
|
|
//var material = new THREE.MeshNormalMaterial();
|
|
//for(var i = 0; i < points.length; i++){
|
|
// var point = points[i];
|
|
// var sphere = new THREE.Mesh(geometry, material);
|
|
// sphere.position.copy(point);
|
|
// scene.add(sphere);
|
|
//}
|
|
|
|
if(profileFrustum === undefined){
|
|
var boxGeometry = new THREE.BoxGeometry(1,1,1,1,1,1);
|
|
var boxMaterial = new THREE.MeshBasicMaterial({color: 0xFF0000, transparent: true, opacity: 0.1});
|
|
profileFrustum = new THREE.Mesh(boxGeometry, boxMaterial);
|
|
|
|
sceneTools.add(profileFrustum);
|
|
}
|
|
|
|
profileFrustum.scale.set(width, height, depth);
|
|
|
|
|
|
var up = new THREE.Vector3().crossVectors(side, forward);
|
|
|
|
var camera = new THREE.OrthographicCamera( -width, width, height, -height, -depth/2, depth/2 );
|
|
camera.position.copy(centroid.clone().add(forward));
|
|
camera.lookAt(centroid);
|
|
camera.position.sub(forward);
|
|
|
|
profileFrustum.position.copy(centroid.clone().add(forward));
|
|
profileFrustum.lookAt(centroid);
|
|
profileFrustum.position.sub(forward);
|
|
|
|
|
|
pointclouds[0].material.size = 0.0001;
|
|
renderer.render(scene, camera, rtProfile, true);
|
|
|
|
|
|
|
|
}
|
|
|
|
function initGUI(){
|
|
|
|
//// dat.gui
|
|
//var gui = new dat.GUI({
|
|
// height : 5 * 32 - 1
|
|
//});
|
|
//
|
|
//var params = {
|
|
// PointSize: defaultPointSize,
|
|
// LOD: defaultLOD,
|
|
// "show aabb" : false,
|
|
// "Materials" : materials.rgb
|
|
//};
|
|
//
|
|
//var pLOD = gui.add(params, 'LOD', 0.5,20);
|
|
//pLOD.onChange(function(value){
|
|
// pointcloud.LOD = value;
|
|
//});
|
|
//
|
|
//var pPointSize = gui.add(params, 'PointSize', 0.01, 0.1);
|
|
//pPointSize.onChange(function(value){
|
|
// pointcloud.material.size = value;
|
|
//});
|
|
//
|
|
//var pMaterial = gui.add(params, 'Materials', [ "RGB", "Color", "Height" ]);
|
|
//pMaterial.onChange(function(value){
|
|
// var size = pointcloud.material.size;
|
|
// if(value === "RGB"){
|
|
// pointcloud.material = materials.rgb;
|
|
// }else if(value === "Color"){
|
|
// pointcloud.material = materials.color;
|
|
// }else if(value === "Height"){
|
|
// pointcloud.material = materials.height;
|
|
// }
|
|
//
|
|
// pointcloud.material.size = size;
|
|
//
|
|
// console.log(value);
|
|
//});
|
|
//
|
|
//var pBoundingBox = gui.add(params, 'show aabb');
|
|
//pBoundingBox.onChange(function(value){
|
|
// pointcloud.showBoundingBox = value;
|
|
//});
|
|
|
|
// stats
|
|
stats = new Stats();
|
|
stats.domElement.style.position = 'absolute';
|
|
stats.domElement.style.top = '0px';
|
|
stats.domElement.style.margin = '5px';
|
|
document.body.appendChild( stats.domElement );
|
|
|
|
}
|
|
|
|
function initThree(){
|
|
scene = new THREE.Scene();
|
|
sceneHUD = new THREE.Scene();
|
|
sceneTools = new THREE.Scene();
|
|
|
|
camera = new THREE.PerspectiveCamera(75, window.innerWidth/window.innerHeight, 0.1, 100000);
|
|
//cameraHUD = new THREE.OrthographicCamera( 500, 500, 500, 500, -1000, 1000);
|
|
//cameraHUD = new THREE.OrthographicCamera( -1.6, 5, 2, -2, -5, 1000 );
|
|
cameraHUD = new THREE.OrthographicCamera( -1, 1, 1, -1, -100, 1000 );
|
|
//cameraHUD = new THREE.PerspectiveCamera(75, window.innerWidth/window.innerHeight, 0.1, 100000);
|
|
//cameraHUD.position.set(0,0,100);
|
|
cameraHUD.lookAt( new THREE.Vector3(0,0,0));
|
|
floatingOrigin = new FloatingOrigin(camera);
|
|
|
|
renderer = new THREE.WebGLRenderer();
|
|
renderer.setSize(window.innerWidth, window.innerHeight);
|
|
renderer.autoClear = false;
|
|
document.body.appendChild(renderer.domElement);
|
|
|
|
skybox = Potree.utils.loadSkybox("../resources/textures/skybox/");
|
|
|
|
// camera and controls
|
|
camera.position.set(5, 10, 15);
|
|
controls = new THREE.FirstPersonControls(camera, renderer.domElement);
|
|
camera.rotation.order = 'ZYX';
|
|
camera.rotation.x = -0.5;
|
|
|
|
// materials
|
|
materials.rgb = new Potree.PointCloudRGBMaterial({ size: defaultPointSize});
|
|
materials.color = new Potree.PointCloudColorMaterial({size: defaultPointSize});
|
|
materials.height = new Potree.PointCloudHeightMaterial({size: defaultPointSize, min: 0, max: 10});
|
|
materials.height = new Potree.PointCloudHeightMaterial({size: defaultPointSize, min: 0, max: 10});
|
|
|
|
// load pointcloud
|
|
var pco = POCLoader.load(pointcloudPath, {toOrigin: true});
|
|
|
|
// create nodes for large coordinates
|
|
var count = 1;
|
|
for(var i = 0; i < count; i++){
|
|
var pointcloud = new Potree.PointCloudOctree(pco, materials.rgb);
|
|
pointcloud.LOD = defaultLOD;
|
|
pointcloud.rotation.set(Math.PI/2, 0.85* -Math.PI/2, -0.0);
|
|
pointcloud.position.set(0, 0, -Math.pow(2,i));
|
|
pointcloud.floatingOrigin = true;
|
|
|
|
pointclouds.push(pointcloud);
|
|
scene.add(pointcloud);
|
|
|
|
//var spritey = makeTextSprite( Potree.utils.addCommas(-pointcloud.position.z), { fontsize: 32, fontface: "Georgia", borderColor: {r:0, g:0, b:255, a:1.0} } );
|
|
var spritey = Potree.LabelHelper.createTextSprite( Potree.utils.addCommas(-pointcloud.position.z), { fontsize: 32, fontface: "Georgia", borderColor: {r:0, g:0, b:255, a:1.0} } );
|
|
spritey.position.set(0,0,pointcloud.position.z+3);
|
|
scene.add( spritey );
|
|
//milestones.push(spritey);
|
|
|
|
floatingOrigin.addReferenceFrame(pointcloud);
|
|
floatingOrigin.addReferenceFrame(spritey);
|
|
}
|
|
|
|
// create waypoints
|
|
var elWaypoints = document.getElementById("waypoints");
|
|
for(var i = 0; i < count; i++){
|
|
var pos = -Math.pow(2,i);
|
|
var div = document.createElement("div");
|
|
div.innerHTML = Potree.utils.addCommas(-pos);
|
|
//div.style.position = "absolute";
|
|
//div.style.top = 200 + 30*i;
|
|
//div.style.width = 120;
|
|
div.style.padding = "1 2 1 2";
|
|
div.style.margin = "1 2 1 5";
|
|
//div.style.border = "1px solid black";
|
|
div.style.float = "left";
|
|
div.style.textDecoration = "underline";
|
|
div.onclick = (function(pos){
|
|
|
|
return function(){
|
|
camera.position.z = -floatingOrigin.offset.z + pos + 25;
|
|
};
|
|
|
|
})(pos);
|
|
elWaypoints.appendChild(div);
|
|
}
|
|
|
|
|
|
document.addEventListener( 'mousemove', onDocumentMouseMove, false );
|
|
|
|
|
|
var profileGeometry = new THREE.BoxGeometry(1,1,1);
|
|
var profileMaterial = new THREE.MeshBasicMaterial( { color: 0xffffff, map: rtProfile } );
|
|
profileMaterial.depthTest = false;
|
|
//var profileMaterial = new THREE.MeshBasicMaterial( { color: 0xffffff } );
|
|
profile = new THREE.Mesh(profileGeometry, profileMaterial);
|
|
//profile.scale.set(0.1, 0.1, 0.1);
|
|
profile.scale.set(1,1,0.1);
|
|
|
|
profile.position.set(0, 0, 0);
|
|
sceneHUD.add(profile);
|
|
|
|
}
|
|
|
|
function onClick(event){
|
|
console.log("test");
|
|
if(event.which == 3){
|
|
onRightClick();
|
|
}
|
|
}
|
|
|
|
function onDocumentMouseMove( event ) {
|
|
event.preventDefault();
|
|
|
|
mouse.x = ( event.clientX / window.innerWidth ) * 2 - 1;
|
|
mouse.y = - ( event.clientY / window.innerHeight ) * 2 + 1;
|
|
}
|
|
|
|
function render() {
|
|
requestAnimationFrame(render);
|
|
|
|
var numVisibleNodes = 0;
|
|
var numVisiblePoints = 0;
|
|
for(var i = 0; i < pointclouds.length; i++){
|
|
var pointcloud = pointclouds[i];
|
|
|
|
|
|
numVisibleNodes += pointcloud.numVisibleNodes;
|
|
numVisiblePoints += pointcloud.numVisiblePoints;
|
|
pointcloud.update(camera);
|
|
}
|
|
|
|
document.getElementById("lblNumVisibleNodes").innerHTML = "visible nodes: " + numVisibleNodes;
|
|
document.getElementById("lblNumVisiblePoints").innerHTML = "visible points: " + Potree.utils.addCommas(numVisiblePoints);
|
|
stats.update();
|
|
|
|
controls.update(clock.getDelta());
|
|
|
|
floatingOrigin.update();
|
|
|
|
//var centroid = new THREE.Vector3(-2, -4 + 3*Math.sin(clock.getElapsedTime()), 3);
|
|
var centroid = new THREE.Vector3(-2, -4 , 3);
|
|
var forward = new THREE.Vector3(0, 1, 0);
|
|
var side = new THREE.Vector3(1, 0, 0);
|
|
|
|
|
|
//var centroid = new THREE.Vector3(0, -3, 3);
|
|
//var forward = new THREE.Vector3( 0, 0, 1 ).applyQuaternion(camera.quaternion);
|
|
//var side = new THREE.Vector3( 1, 0, 0 ).applyQuaternion(camera.quaternion);
|
|
|
|
calculateProfile(centroid, forward, side, 10, 10, 0.1);
|
|
profile.scale.x = 1;
|
|
profile.scale.y = renderer.domElement.clientWidth / renderer.domElement.clientHeight;
|
|
profile.scale.multiplyScalar(0.5);
|
|
profile.position.x = 0.7;
|
|
profile.position.y = 0.5;
|
|
|
|
|
|
// render skybox
|
|
skybox.camera.rotation.copy(camera.rotation);
|
|
renderer.render(skybox.scene, skybox.camera);
|
|
|
|
// render scenes
|
|
renderer.render(scene, camera);
|
|
renderer.render(sceneTools, camera);
|
|
renderer.render(sceneHUD, cameraHUD);
|
|
|
|
};
|
|
|
|
|
|
|
|
initThree();
|
|
initGUI();
|
|
render();
|
|
|
|
</script>
|
|
|
|
</body>
|
|
</html> |