152 lines
4.4 KiB
HTML
152 lines
4.4 KiB
HTML
|
|
|
|
<html>
|
|
<head>
|
|
<title>Skybox</title>
|
|
<style>canvas { width: 100%; height: 100% }</style>
|
|
</head>
|
|
<body style="margin: 0; padding: 0">
|
|
<script src="../libs/three.js/build/three.js"></script>
|
|
<script src="../libs/other/OrbitControls.js"></script>
|
|
<script src="../src/Potree.js"></script>
|
|
<script src="../src/PointCloudOctree.js"></script>
|
|
<script src="../src/PointCloudOctreeGeometry.js"></script>
|
|
<script src="../src/loader/POCLoader.js"></script>
|
|
<script src="../src/loader/PointAttributes.js"></script>
|
|
<script src="../src/utils.js"></script>
|
|
<script src="../src/LRU.js"></script>
|
|
<script>
|
|
var renderer;
|
|
var camera;
|
|
var cube;
|
|
var scene;
|
|
var pointCloud;
|
|
var cameraCube, sceneCube;
|
|
|
|
/**
|
|
* see three.js cubemap examples
|
|
*/
|
|
function loadSkybox(){
|
|
cameraCube = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 1, 100000 );
|
|
sceneCube = new THREE.Scene();
|
|
|
|
var path = "../resources/textures/skybox/";
|
|
var format = ".jpg";
|
|
var urls = [
|
|
path + 'px' + format, path + 'nx' + format,
|
|
path + 'py' + format, path + 'ny' + format,
|
|
path + 'pz' + format, path + 'nz' + format
|
|
];
|
|
|
|
var textureCube = THREE.ImageUtils.loadTextureCube( urls, new THREE.CubeRefractionMapping() );
|
|
var material = new THREE.MeshBasicMaterial( { color: 0xffffff, envMap: textureCube, refractionRatio: 0.95 } );
|
|
|
|
var shader = THREE.ShaderLib[ "cube" ];
|
|
shader.uniforms[ "tCube" ].value = textureCube;
|
|
|
|
var material = new THREE.ShaderMaterial( {
|
|
|
|
fragmentShader: shader.fragmentShader,
|
|
vertexShader: shader.vertexShader,
|
|
uniforms: shader.uniforms,
|
|
depthWrite: false,
|
|
side: THREE.BackSide
|
|
|
|
} ),
|
|
|
|
mesh = new THREE.Mesh( new THREE.BoxGeometry( 100, 100, 100 ), material );
|
|
sceneCube.add( mesh );
|
|
}
|
|
|
|
function initThree(){
|
|
scene = new THREE.Scene();
|
|
camera = new THREE.PerspectiveCamera(75, window.innerWidth/window.innerHeight, 0.1, 100000);
|
|
|
|
renderer = new THREE.WebGLRenderer();
|
|
renderer.setSize(window.innerWidth, window.innerHeight);
|
|
renderer.autoClear = false;
|
|
document.body.appendChild(renderer.domElement);
|
|
|
|
loadSkybox();
|
|
|
|
camera.position.z = 5;
|
|
camera.position.y = 5;
|
|
camera.position.x = -6;
|
|
|
|
var pointLight = new THREE.PointLight(0xffffff);
|
|
pointLight.position.set(10, 10, 10);
|
|
scene.add(pointLight);
|
|
|
|
var ambientLight = new THREE.AmbientLight(0x111111);
|
|
scene.add(ambientLight);
|
|
|
|
controls = new THREE.OrbitControls(camera);
|
|
controls.target.set( 0, 3, 0 );
|
|
camera.lookAt(new THREE.Vector3(0,3,0));
|
|
|
|
var material = new THREE.PointCloudMaterial( { size: 0.05, vertexColors: true } );
|
|
var pco = POCLoader.load("../resources/pointclouds/lion_takanawa/cloud.js");
|
|
|
|
var pointCloud = new Potree.PointCloudOctree(pco, material);
|
|
pointCloud.LODDistance = 80;
|
|
pointCloud.rotation.x = Math.PI;
|
|
pointCloud.rotation.y = 2;
|
|
pointCloud.position.x = -2;
|
|
pointCloud.position.z = 8;
|
|
pointCloud.position.y = 4;
|
|
scene.add(pointCloud);
|
|
|
|
scene.add(createGrid(8,8,1));
|
|
}
|
|
|
|
function createGrid(width, length, spacing){
|
|
var material = new THREE.LineBasicMaterial({
|
|
color: 0x666666
|
|
});
|
|
|
|
var geometry = new THREE.Geometry();
|
|
for(var i = 0; i <= length; i++){
|
|
geometry.vertices.push(new THREE.Vector3(-(spacing*width)/2, 0, i*spacing-(spacing*length)/2));
|
|
geometry.vertices.push(new THREE.Vector3(+(spacing*width)/2, 0, i*spacing-(spacing*length)/2));
|
|
}
|
|
|
|
for(var i = 0; i <= width; i++){
|
|
geometry.vertices.push(new THREE.Vector3(i*spacing-(spacing*width)/2, 0, -(spacing*length)/2));
|
|
geometry.vertices.push(new THREE.Vector3(i*spacing-(spacing*width)/2, 0, +(spacing*length)/2));
|
|
}
|
|
|
|
var line = new THREE.Line(geometry, material, THREE.LinePieces);
|
|
line.receiveShadow = true;
|
|
return line;
|
|
}
|
|
|
|
function render() {
|
|
|
|
requestAnimationFrame(render);
|
|
|
|
scene.traverse( function ( object ) {
|
|
if ( object instanceof Potree.PointCloudOctree ) {
|
|
object.update( camera );
|
|
}
|
|
} );
|
|
|
|
cameraCube.rotation.copy( camera.rotation );
|
|
renderer.render( sceneCube, cameraCube );
|
|
renderer.render(scene, camera);
|
|
|
|
};
|
|
|
|
initThree();
|
|
render();
|
|
|
|
</script>
|
|
|
|
<div id="lblControl" style="position:absolute; left: 10px; top: 10px; width: 400px; color: black">
|
|
Orbit Controls:<br>
|
|
left mouse button: rotate object<br>
|
|
right mouse button: pan the screen<br>
|
|
scrool wheel: zoom in and out
|
|
</div>
|
|
|
|
</body>
|
|
</html> |