pnext / three-loader

Point cloud loader for ThreeJS, based on the core parts of Potree
Other
194 stars 88 forks source link

Clipping in world space #113

Open berry4u opened 2 years ago

berry4u commented 2 years ago

can anyone give hints about clipping in world space by using IClipBox? There's no code sample about it.

Thanks a lot

fahadm commented 2 years ago

I mean the IClipbox basically just works in world space, just populate the scale (diagonal of your matrix) and the position of your matrix (that is passed to the IClipBox), the position of the matrix will represent the position of the clip box and scale will determine its size in x,y and z. (note the Clipbox will have its centered around the matrix position)

berry4u commented 2 years ago

Thank you for answering. Despite making many attempts I could not get clipping to work. Could you please post a code snippet?

berry4u commented 1 year ago

OK, now it works. However, I noticed that an important clipmode is missing such as CLIP_INSIDE (very useful when overlapping point clouds with other models) despite being proposed here (https://github.com/pnext/three-loader/pull/43/files/a528b88ea4ae1100e389b2553075704b57022337) along with other improvements. is there any advancement on it?

mandre96 commented 10 months ago

I Wasn't able to make ClipBox Work.

When I activate it it clips all the point cloud, even tho I created a box geometry and assign it correctly to the IClipBox.

`
//Creates Geometry const boxGeometry = new THREE.BoxGeometry(1, 1, 1); boxGeometry.computeBoundingBox();

    const boxFrameGeometry = this.generateBoxFrameGeometry();
    const planeFrameGeometry = this.generatePlaneFrameGeometry();

    this._material = new THREE.MeshBasicMaterial( {
        color: 0x00ff00, 
        transparent: true, 
        opacity: 0.3,
        depthTest: true, 
        depthWrite: false} );

    //Box Mesh
    this._box = new THREE.Mesh(boxGeometry, this._material);
    this._box.geometry.computeBoundingBox();
    this.add(this._box);

    //Box Frame
    this._frame = new THREE.LineSegments( boxFrameGeometry, new THREE.LineBasicMaterial({color: 0x000000}));
    this.add(this._frame);
    this._planeFrame = new THREE.LineSegments( planeFrameGeometry, new THREE.LineBasicMaterial({color: 0xff0000}));
    this.add(this._planeFrame);

    // set default thickness
    this.setScaleZ(0.1);

    const mat = this._box.matrix.clone();
    const inverse = mat.invert();

    this._clipBox = {box: this._box.geometry.boundingBox!, inverse:inverse , matrix:this._box.matrix, position: this.position};
    }

public update(): void { this._box.geometry.computeBoundingBox(); const mat = this._box.matrix.clone(); const inverse = mat.invert();

    //updates clipbox
    this._clipBox.box = this._box.geometry.boundingBox!;
    this._clipBox.inverse = inverse;
    this._clipBox.position = this.position;

}

`

In my Large Clouds Manager:

`
public setClipMode(value:ClipMode) { for (let index = 0; index < this._largeScaleClouds.length; index++) { const potreeCloud = this._largeScaleClouds[index]; potreeCloud.material.clipMode = value } }

/**

`

Highlight inside:

https://freeimage.host/i/J9vqlUX