updated to latest three.js dev build, added skybox demo
This commit is contained in:
parent
57453ac943
commit
7c3d1542f5
196
index.html
Normal file
196
index.html
Normal file
@ -0,0 +1,196 @@
|
||||
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<title>My first Three.js app</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/loader/POCLoader.js"></script>
|
||||
<script src="src/loader/PointAttributes.js"></script>
|
||||
<script src="src/utils.js"></script>
|
||||
<script src="src/CustomBoxHelper.js"></script>
|
||||
<script>
|
||||
var renderer;
|
||||
var camera;
|
||||
var cube;
|
||||
var scene;
|
||||
var octreeNodesVisible = 0;
|
||||
var pointCloud;
|
||||
var raycaster = new THREE.Raycaster();
|
||||
var projector = new THREE.Projector();
|
||||
var pointClouds = [];
|
||||
|
||||
function initThree(){
|
||||
scene = new THREE.Scene();
|
||||
camera = new THREE.PerspectiveCamera(75, window.innerWidth/window.innerHeight, 0.1, 1000);
|
||||
|
||||
renderer = new THREE.WebGLRenderer();
|
||||
renderer.setSize(window.innerWidth, window.innerHeight);
|
||||
document.body.appendChild(renderer.domElement);
|
||||
|
||||
camera.position.z = 6;
|
||||
camera.position.y = 4;
|
||||
camera.position.x = 4;
|
||||
|
||||
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.ParticleSystemMaterial( { size: 0.02, vertexColors: true } );
|
||||
var pco = POCLoader.load("resources/pointclouds/lion_takanawa/cloud.js");
|
||||
|
||||
// pointCloud = new Potree.PointCloudOctree(pco, material);
|
||||
// pointCloud.LODDistance = 80;
|
||||
// pointCloud.rotation.x = Math.PI;
|
||||
// pointCloud.position.x = 8;
|
||||
// pointCloud.position.z = -2;
|
||||
// pointCloud.position.y = 4;
|
||||
// scene.add(pointCloud);
|
||||
|
||||
var min =0;
|
||||
max = 1;
|
||||
for(var i = min; i < max; i++){
|
||||
for(var j = min; j < max; j++){
|
||||
var pointCloud = new Potree.PointCloudOctree(pco, material);
|
||||
pointCloud.LODDistance = 80;
|
||||
pointCloud.rotation.x = Math.PI;
|
||||
pointCloud.position.x = 8 + 7*i;
|
||||
pointCloud.position.z = -2 - 7*j;
|
||||
pointCloud.position.y = 4;
|
||||
scene.add(pointCloud);
|
||||
pointClouds.push(pointCloud);
|
||||
}
|
||||
}
|
||||
|
||||
renderer.domElement.addEventListener('click', function(event){
|
||||
var start = new Date().getTime();
|
||||
|
||||
vector = new THREE.Vector3( mouse.x, mouse.y, 0.5 );
|
||||
projector.unprojectVector( vector, camera );
|
||||
raycaster.ray.set( camera.position, vector.sub( camera.position ).normalize() );
|
||||
|
||||
var intersects = [];
|
||||
for(var i = 0; i < pointClouds.length; i++){
|
||||
var pointCloud = pointClouds[i];
|
||||
var tis = raycaster.intersectObject(pointCloud.root, true);
|
||||
for(var j = 0; j < tis.length; j++){
|
||||
var ti = tis[j];
|
||||
ti.node = pointCloud;
|
||||
intersects.push(ti);
|
||||
}
|
||||
}
|
||||
|
||||
var closest = intersects.length > 0 ? intersects[0] : null;
|
||||
for(var i = 0; i < intersects.length; i++){
|
||||
if(intersects[i].distance < closest.distance){
|
||||
closest = intersects[i];
|
||||
}
|
||||
}
|
||||
|
||||
if(closest != null){
|
||||
var clickPos = new THREE.Vector3().copy(raycaster.ray.direction).multiplyScalar(closest.distance);
|
||||
clickPos.add(raycaster.ray.origin);
|
||||
|
||||
var geometry = new THREE.SphereGeometry(0.1);
|
||||
var material = new THREE.MeshLambertMaterial();
|
||||
var sphere = new THREE.Mesh(geometry, material);
|
||||
sphere.position = closest.point;
|
||||
closest.node.add(sphere);
|
||||
}
|
||||
|
||||
var end = new Date().getTime();
|
||||
var time = end - start;
|
||||
console.log('intersect all duration: ' + time);
|
||||
});
|
||||
document.addEventListener( 'mousemove', onDocumentMouseMove, false );
|
||||
|
||||
|
||||
scene.add(createGrid(8,8,1));
|
||||
}
|
||||
|
||||
function onDocumentMouseMove( event ) {
|
||||
event.preventDefault();
|
||||
|
||||
mouse.x = ( event.clientX / window.innerWidth ) * 2 - 1;
|
||||
mouse.y = - ( event.clientY / window.innerHeight ) * 2 + 1;
|
||||
}
|
||||
|
||||
function createGrid(width, length, spacing){
|
||||
var material = new THREE.LineBasicMaterial({
|
||||
color: 0xBBBBBB
|
||||
});
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
var toggle = 0;
|
||||
var mouse = { x: 1, y: 1 };
|
||||
function render() {
|
||||
|
||||
requestAnimationFrame(render);
|
||||
|
||||
vector = new THREE.Vector3( mouse.x, mouse.y, 0.5 );
|
||||
projector.unprojectVector( vector, camera );
|
||||
|
||||
toggle += 0.1;
|
||||
if(toggle > 0.2){
|
||||
octreeNodesVisible = 0;
|
||||
scene.traverse( function ( object ) {
|
||||
if ( object instanceof Potree.PointCloudOctree ) {
|
||||
object.update( camera );
|
||||
}
|
||||
} );
|
||||
toggle = 0;
|
||||
}
|
||||
|
||||
|
||||
renderer.render(scene, camera);
|
||||
|
||||
document.getElementById("lblNumVisibleNodes").innerHTML = "visible nodes: " + octreeNodesVisible;
|
||||
|
||||
};
|
||||
|
||||
initThree();
|
||||
render();
|
||||
|
||||
</script>
|
||||
|
||||
<div id="lblNumVisibleNodes" style="position:absolute; left: 10px; top: 30px; width: 200px; color: white">visible nodes: 0</div>
|
||||
<div id="lblInfo" style="position:absolute; left: 0px; top: 00px; right: 0px; height: 20px; background-color: #aaaaaa">
|
||||
Rewriting <a href="http://potree.org/" target="_blank">potree</a> point cloud renderer from scratch using <a href="http://threejs.org/" target="_blank">three.js</a>
|
||||
</div>
|
||||
<div id="lblControl" style="position:absolute; left: 10px; top: 60px; width: 400px; color: white">
|
||||
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>
|
||||
File diff suppressed because it is too large
Load Diff
37994
libs/three.js/build/three.min.js
vendored
37994
libs/three.js/build/three.min.js
vendored
File diff suppressed because one or more lines are too long
@ -53,7 +53,7 @@
|
||||
camera.lookAt(new THREE.Vector3(0,3,0));
|
||||
|
||||
// pointcloud
|
||||
var material = new THREE.ParticleSystemMaterial( { size: 0.02, vertexColors: true } );
|
||||
var material = new THREE.PointCloudMaterial( { size: 0.04, vertexColors: true } );
|
||||
var pco = POCLoader.load("resources/pointclouds/lion_takanawa/cloud.js");
|
||||
|
||||
var min = -1;
|
||||
@ -76,6 +76,7 @@
|
||||
vector = new THREE.Vector3( mouse.x, mouse.y, 0.5 );
|
||||
projector.unprojectVector( vector, camera );
|
||||
var recursive = document.getElementById("chkRecursive").checked;
|
||||
raycaster.params = {"PointCloud" : {threshold: 0.04}};
|
||||
|
||||
var start = new Date().getTime();
|
||||
|
||||
@ -115,7 +116,7 @@
|
||||
var material = new THREE.MeshLambertMaterial({color: 0xff0000});
|
||||
var sphere = new THREE.Mesh(geometry, material);
|
||||
sphere.position = closest.point;
|
||||
closest.node.add(sphere);
|
||||
scene.add(sphere);
|
||||
}
|
||||
|
||||
|
||||
|
||||
BIN
resources/textures/skyboxsun25degtest.png
Normal file
BIN
resources/textures/skyboxsun25degtest.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.8 MiB |
1
resources/textures/skyboxsun25degtest.txt
Normal file
1
resources/textures/skyboxsun25degtest.txt
Normal file
@ -0,0 +1 @@
|
||||
http://reije081.home.xs4all.nl/skyboxes/
|
||||
197
skybox.html
Normal file
197
skybox.html
Normal file
@ -0,0 +1,197 @@
|
||||
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<title>My first Three.js app</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/loader/POCLoader.js"></script>
|
||||
<script src="src/loader/PointAttributes.js"></script>
|
||||
<script src="src/utils.js"></script>
|
||||
<script src="src/CustomBoxHelper.js"></script>
|
||||
<script>
|
||||
var renderer;
|
||||
var camera;
|
||||
var cube;
|
||||
var scene;
|
||||
var octreeNodesVisible = 0;
|
||||
var pointsVisible = 0;
|
||||
var pointCloud;
|
||||
var raycaster = new THREE.Raycaster();
|
||||
var projector = new THREE.Projector();
|
||||
var pointClouds = [];
|
||||
|
||||
function loadSkybox(){
|
||||
// load skybox
|
||||
var cubeMap = new THREE.Texture( [] );
|
||||
cubeMap.format = THREE.RGBFormat;
|
||||
cubeMap.flipY = false;
|
||||
|
||||
var loader = new THREE.ImageLoader();
|
||||
loader.load( 'resources/textures/skyboxsun25degtest.png', function ( image ) {
|
||||
|
||||
var getSide = function ( x, y ) {
|
||||
|
||||
var size = 1024;
|
||||
|
||||
var canvas = document.createElement( 'canvas' );
|
||||
canvas.width = size;
|
||||
canvas.height = size;
|
||||
|
||||
var context = canvas.getContext( '2d' );
|
||||
context.drawImage( image, - x * size, - y * size );
|
||||
|
||||
return canvas;
|
||||
|
||||
};
|
||||
|
||||
cubeMap.image[ 0 ] = getSide( 2, 1 ); // px
|
||||
cubeMap.image[ 1 ] = getSide( 0, 1 ); // nx
|
||||
cubeMap.image[ 2 ] = getSide( 1, 0 ); // py
|
||||
cubeMap.image[ 3 ] = getSide( 1, 2 ); // ny
|
||||
cubeMap.image[ 4 ] = getSide( 1, 1 ); // pz
|
||||
cubeMap.image[ 5 ] = getSide( 3, 1 ); // nz
|
||||
cubeMap.needsUpdate = true;
|
||||
|
||||
} );
|
||||
|
||||
var cubeShader = THREE.ShaderLib['cube'];
|
||||
cubeShader.uniforms['tCube'].value = cubeMap;
|
||||
|
||||
var skyBoxMaterial = new THREE.ShaderMaterial( {
|
||||
fragmentShader: cubeShader.fragmentShader,
|
||||
vertexShader: cubeShader.vertexShader,
|
||||
uniforms: cubeShader.uniforms,
|
||||
depthWrite: false,
|
||||
side: THREE.BackSide
|
||||
});
|
||||
|
||||
var skyBox = new THREE.Mesh(
|
||||
new THREE.BoxGeometry( 10000, 10000, 10000 ),
|
||||
skyBoxMaterial
|
||||
);
|
||||
|
||||
scene.add( skyBox );
|
||||
}
|
||||
|
||||
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);
|
||||
document.body.appendChild(renderer.domElement);
|
||||
|
||||
loadSkybox();
|
||||
|
||||
camera.position.z = 60;
|
||||
camera.position.y = 4;
|
||||
camera.position.x = 4;
|
||||
|
||||
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.03, vertexColors: true } );
|
||||
// var pco = POCLoader.load("resources/pointclouds/lion_takanawa/cloud.js");
|
||||
var pco = POCLoader.load("../../../pointclouds/converted/skatepark/cloud.js");
|
||||
|
||||
var pointCloud = new Potree.PointCloudOctree(pco, material);
|
||||
pointCloud.LODDistance = 1280;
|
||||
pointCloud.rotation.x = -Math.PI/2;
|
||||
pointCloud.position.y = -200;
|
||||
scene.add(pointCloud);
|
||||
pointClouds.push(pointCloud);
|
||||
|
||||
scene.add(createGrid(8,8,1));
|
||||
}
|
||||
|
||||
function onDocumentMouseMove( event ) {
|
||||
event.preventDefault();
|
||||
|
||||
mouse.x = ( event.clientX / window.innerWidth ) * 2 - 1;
|
||||
mouse.y = - ( event.clientY / window.innerHeight ) * 2 + 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;
|
||||
}
|
||||
|
||||
|
||||
var toggle = 0;
|
||||
var mouse = { x: 1, y: 1 };
|
||||
function render() {
|
||||
|
||||
requestAnimationFrame(render);
|
||||
|
||||
vector = new THREE.Vector3( mouse.x, mouse.y, 0.5 );
|
||||
projector.unprojectVector( vector, camera );
|
||||
|
||||
toggle += 0.1;
|
||||
if(toggle > 0.2){
|
||||
octreeNodesVisible = 0;
|
||||
pointsVisible = 0;
|
||||
scene.traverse( function ( object ) {
|
||||
if ( object instanceof Potree.PointCloudOctree ) {
|
||||
object.update( camera );
|
||||
}
|
||||
} );
|
||||
toggle = 0;
|
||||
}
|
||||
|
||||
|
||||
renderer.render(scene, camera);
|
||||
|
||||
document.getElementById("lblNumVisibleNodes").innerHTML = "visible nodes: " + octreeNodesVisible;
|
||||
document.getElementById("lblNumVisiblePoints").innerHTML = "visible points: " + pointsVisible;
|
||||
|
||||
};
|
||||
|
||||
initThree();
|
||||
render();
|
||||
|
||||
</script>
|
||||
|
||||
<div id="lblNumVisibleNodes" style="position:absolute; left: 10px; top: 30px; width: 200px; color: black">visible nodes: 0</div>
|
||||
<div id="lblNumVisiblePoints" style="position:absolute; left: 10px; top: 50px; width: 200px; color: black">visible nodes: 0</div>
|
||||
<div id="lblInfo" style="position:absolute; left: 0px; top: 00px; right: 0px; height: 20px; background-color: #aaaaaa">
|
||||
Rewriting <a href="http://potree.org/" target="_blank">potree</a> point cloud renderer from scratch using <a href="http://threejs.org/" target="_blank">three.js</a>
|
||||
</div>
|
||||
<div id="lblControl" style="position:absolute; left: 10px; top: 80px; 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>
|
||||
@ -54,11 +54,13 @@ Potree.PointCloudOctreeGeometryNode.prototype.bufferLoaded = function(buffer){
|
||||
var geometry = new THREE.BufferGeometry();
|
||||
var numPoints = buffer.byteLength / 16;
|
||||
|
||||
geometry.addAttribute('position', Float32Array, numPoints*3, 3);
|
||||
geometry.addAttribute('color', Float32Array, numPoints*3, 3);
|
||||
// geometry.addAttribute('position', Float32Array, numPoints*3, 3);
|
||||
// geometry.addAttribute('color', Float32Array, numPoints*3, 3);
|
||||
|
||||
var positions = geometry.attributes.position.array;
|
||||
var colors = geometry.attributes.color.array;
|
||||
var positions = new Float32Array(numPoints*3);
|
||||
var colors = new Float32Array(numPoints*3);
|
||||
// var positions = geometry.attributes.position.array;
|
||||
// var colors = geometry.attributes.color.array;
|
||||
var color = new THREE.Color();
|
||||
|
||||
var fView = new Float32Array(buffer);
|
||||
@ -74,6 +76,9 @@ Potree.PointCloudOctreeGeometryNode.prototype.bufferLoaded = function(buffer){
|
||||
colors[3*i+1] = color.g / 255;
|
||||
colors[3*i+2] = color.b / 255;
|
||||
}
|
||||
|
||||
geometry.addAttribute('position', new THREE.Float32Attribute(positions, 3));
|
||||
geometry.addAttribute('color', new THREE.Float32Attribute(colors, 3));
|
||||
geometry.boundingBox = this.boundingBox;
|
||||
this.geometry = geometry;
|
||||
this.loaded = true;
|
||||
@ -97,7 +102,7 @@ Potree.PointCloudOctreeGeometryNode.prototype.bufferLoaded = function(buffer){
|
||||
* If a proxy node becomes visible and its geometry has not been loaded,
|
||||
* loading will begin.
|
||||
* If it is visible and the geometry has been loaded, the proxy node will
|
||||
* be replaced with a point cloud node (THREE.ParticleSystem as of now)
|
||||
* be replaced with a point cloud node (THREE.PointCloud as of now)
|
||||
*/
|
||||
Potree.PointCloudOctreeProxyNode = function(geometryNode){
|
||||
THREE.Object3D.call( this );
|
||||
@ -123,7 +128,7 @@ Potree.PointCloudOctree = function(geometry, material){
|
||||
|
||||
this.pcoGeometry = geometry;
|
||||
this.boundingBox = this.pcoGeometry.boundingBox;
|
||||
//this.material = new THREE.ParticleSystemMaterial( { size: 0.01, vertexColors: true } );
|
||||
//this.material = new THREE.PointCloudMaterial( { size: 0.01, vertexColors: true } );
|
||||
this.material = material;
|
||||
this.maxVisibleNodes = 300;
|
||||
this.level = 0;
|
||||
@ -141,9 +146,10 @@ Potree.PointCloudOctree.prototype.update = function(camera){
|
||||
|
||||
var groot = this.pcoGeometry.root;
|
||||
if(groot != undefined && groot.loaded == true && this.root === undefined){
|
||||
var root = new THREE.ParticleSystem(groot.geometry, this.material);
|
||||
var root = new THREE.PointCloud(groot.geometry, this.material);
|
||||
root.level = 0;
|
||||
root.name = groot.name;
|
||||
root.numPoints = groot.numPoints;
|
||||
root.boundingBox = groot.boundingBox;
|
||||
this.add(root);
|
||||
this.root = root;
|
||||
@ -153,6 +159,7 @@ Potree.PointCloudOctree.prototype.update = function(camera){
|
||||
var child = groot.children[i];
|
||||
var childProxy = new Potree.PointCloudOctreeProxyNode(child);
|
||||
childProxy.level = child.level;
|
||||
childProxy.numPoints = child.numPoints;
|
||||
root.add(childProxy);
|
||||
}
|
||||
}
|
||||
@ -160,7 +167,7 @@ Potree.PointCloudOctree.prototype.update = function(camera){
|
||||
var _this = this;
|
||||
this.traverseBreadthFirst(function(object){
|
||||
|
||||
if(object instanceof THREE.ParticleSystem){
|
||||
if(object instanceof THREE.PointCloud){
|
||||
// var distance = new THREE.Vector3().subVectors(camera.position, object.position).length();
|
||||
var boxWorld = Potree.utils.computeTransformedBoundingBox(object.boundingBox, object.matrixWorld);
|
||||
var camWorldPos = new THREE.Vector3().setFromMatrixPosition( camera.matrixWorld );
|
||||
@ -191,11 +198,14 @@ Potree.PointCloudOctree.prototype.update = function(camera){
|
||||
if(!visible){
|
||||
return false;
|
||||
}
|
||||
|
||||
pointsVisible += object.numPoints;
|
||||
}else if (object instanceof Potree.PointCloudOctreeProxyNode) {
|
||||
_this.replaceProxy(object);
|
||||
}
|
||||
|
||||
octreeNodesVisible++;
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
@ -210,9 +220,10 @@ Potree.PointCloudOctree.prototype.replaceProxy = function(proxy){
|
||||
var geometryNode = proxy.geometryNode;
|
||||
if(geometryNode.loaded === true){
|
||||
var geometry = geometryNode.geometry;
|
||||
var node = new THREE.ParticleSystem(geometry, this.material);
|
||||
var node = new THREE.PointCloud(geometry, this.material);
|
||||
node.name = proxy.name;
|
||||
node.level = proxy.level;
|
||||
node.numPoints = proxy.numPoints;
|
||||
node.boundingBox = geometry.boundingBox;
|
||||
var parent = proxy.parent;
|
||||
parent.remove(proxy);
|
||||
@ -250,6 +261,7 @@ Potree.PointCloudOctree.prototype.replaceProxy = function(proxy){
|
||||
var childProxy = new Potree.PointCloudOctreeProxyNode(child);
|
||||
childProxy.name = child.name;
|
||||
childProxy.level = child.level;
|
||||
childProxy.numPoints = child.numPoints;
|
||||
node.add(childProxy);
|
||||
}
|
||||
}
|
||||
@ -278,61 +290,6 @@ THREE.Object3D.prototype.traverseBreadthFirst = function(callback){
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* see http://en.wikipedia.org/wiki/Distance_from_a_point_to_a_line
|
||||
*/
|
||||
THREE.Ray.prototype.intersectParticleSystem = function(points, eps){
|
||||
var geometry = points.geometry;
|
||||
var attributes = geometry.attributes;
|
||||
var positions = attributes.position.array;
|
||||
var n = positions.length;
|
||||
console.log("testing " + n + " points");
|
||||
|
||||
// var P = [0,0,0];
|
||||
// var O = [this.origin.x, this.origin.y, this.origin.z];
|
||||
// var N = [this.direction.x, this.direction.y, this.direction.z];
|
||||
var P = new THREE.Vector3();
|
||||
var O = this.origin;
|
||||
var N = this.direction;
|
||||
var tmp1 = new THREE.Vector3();
|
||||
var tmp2 = new THREE.Vector3();
|
||||
var PO = new THREE.Vector3();
|
||||
var nearest = Infinity;
|
||||
for(var i = 0; i < n; i++){
|
||||
P.x = positions[i*3+0];
|
||||
P.y = positions[i*3+1];
|
||||
P.z = positions[i*3+2];
|
||||
|
||||
PO.subVectors(O,P);
|
||||
tmp1.copy(PO).dot(N).multiply(N);
|
||||
tmp2.subVectors(PO, tmp1);
|
||||
var distance = tmp2.length();
|
||||
if(distance < eps){
|
||||
nearest = Math.min(nearest, PO.length());
|
||||
}
|
||||
}
|
||||
|
||||
return nearest;
|
||||
}
|
||||
|
||||
//THREE.Object3D.prototype.traverse = function(callback){
|
||||
// var stack = [];
|
||||
// stack.push(this);
|
||||
//
|
||||
// while(stack.length > 0){
|
||||
// var current = stack.pop();
|
||||
//
|
||||
// callback(current);
|
||||
//
|
||||
// for(var i = 0; i < current.children.length; i++){
|
||||
// stack.push(current.children[i]);
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -43,6 +43,7 @@ POCLoader.load = function load(url) {
|
||||
|
||||
var root = new Potree.PointCloudOctreeGeometryNode(name, pco, boundingBox);
|
||||
root.level = 0;
|
||||
root.numPoints = fMno.hierarchy[0][1];
|
||||
pco.root = root;
|
||||
pco.root.load();
|
||||
nodes[name] = root;
|
||||
@ -51,6 +52,7 @@ POCLoader.load = function load(url) {
|
||||
// load remaining hierarchy
|
||||
for( var i = 1; i < fMno.hierarchy.length; i++){
|
||||
var name = fMno.hierarchy[i][0];
|
||||
var numPoints = fMno.hierarchy[i][1];
|
||||
var index = parseInt(name.charAt(name.length-1));
|
||||
var parentName = name.substring(0, name.length-1);
|
||||
var parentNode = nodes[parentName];
|
||||
@ -60,6 +62,7 @@ POCLoader.load = function load(url) {
|
||||
|
||||
var node = new Potree.PointCloudOctreeGeometryNode(name, pco, boundingBox);
|
||||
node.level = level;
|
||||
node.numPoints = numPoints;
|
||||
parentNode.addChild(node);
|
||||
nodes[name] = node;
|
||||
}
|
||||
|
||||
@ -59,8 +59,8 @@
|
||||
// pointCloud.position.y = 4;
|
||||
// scene.add(pointCloud);
|
||||
|
||||
var min = -1;
|
||||
max = 2;
|
||||
var min =0;
|
||||
max = 1;
|
||||
for(var i = min; i < max; i++){
|
||||
for(var j = min; j < max; j++){
|
||||
var pointCloud = new Potree.PointCloudOctree(pco, material);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user