tentone / potree-core

Potree point cloud viewer library core components for easier integration in a three.js project.
https://tentone.github.io/potree-core/
Other
171 stars 53 forks source link

i want to use measurement tools #9

Closed smeeteday closed 4 years ago

smeeteday commented 4 years ago

Is there anyone who can use measurement tools in potree-core?

tentone commented 4 years ago

Hello

There are no measurement tools in potree-core but you can use any measurement tools made for threejs projects.

Potree-core focus on bringing the point cloud tech from potree to any threejs project. Can be easily implemented using raycasting.

Cheers

leefsmp commented 4 years ago

Could you post an example about raycasting the pointcloud? I'm using the following code but cannot get an intersection result:

loadPointCloud(
  url, name, ({pointcloud}) => {

  const {material} =  pointcloud

  //RGB | DEPTH | HEIGHT | POINT_INDEX | LOD | CLASSIFICATION
  material.pointColorType = PointColorType.RGB
  //ADAPTIVE | FIXED
  material.pointSizeType = PointSizeType.ADAPTIVE
  //CIRCLE | SQUARE
  material.shape = PointShape.CIRCLE
  material.logarithmicDepthBuffer = true
  material.rgbGamma = gamma
  material.size = pointSize     

  this.selectables.push(pointcloud)
})

getIntersects = (pointer) => {

  const {clientX, clientY} = pointer

  const rect = this.viewer.container.getBoundingClientRect()

  const x =  ((clientX - rect.left) / rect.width)  * 2 - 1
  const y = -((clientY - rect.top)  / rect.height) * 2 + 1

  const pos = new Three.Vector3(x, y, 0.5)

  const raycaster =  new Three.Raycaster()  

  raycaster.setFromCamera(
  pos, this.viewer.camera)

  //raycaster.linePrecision = 0.2

  // returns [] no matter what ...
  return raycaster.intersectObjects(
    this.selectables)
}
tentone commented 4 years ago

There is an examplem in the potree-core repository, the only thing that dones not seem corrent is the fact that youre passnig a Vector3 to the setFromCamera method, but it should not have any impact in the resource, since it has the correct parameters.

var raycaster = new THREE.Raycaster();
raycaster.params.Points.threshold = 1e-2;
var normalized = new THREE.Vector2();

canvas.onmousemove = function(event)
{
    normalized.set((event.clientX / canvas.width) * 2 - 1, -(event.clientY / canvas.height) * 2 + 1);
    raycaster.setFromCamera(normalized, camera);
}

canvas.ondblclick = function(event)
{
    var intesects = raycaster.intersectObject(scene, true);

    if(intesects.length > 0)
    {
        // TODO STUFF
    }
}
leefsmp commented 4 years ago

Thanks for the quick reply, I dont want to test intersection with the entire scene, I just want to test a specific pointcloud loaded as described above.

tentone commented 4 years ago

Its the same process, just pass the pointcloud to raycaster.intersectObject(scene, true); instead of scene.

leefsmp commented 4 years ago

Found the solution for that: I had to call the intersectObjects with recursive flag set to true because the top level pointcloud returned by the load method has no geometry itself, the raycastable geometry is located in the child nodes.

raycaster.intersectObjects(
   [pointcloud], /*recursive*/ true)