Skip to content

Commit 0369286

Browse files
ZielonHugo Campos
authored andcommitted
feat(point-cloud-octree): add pixelPosition and onBeforePickRender to pick params (#36)
- `pixelPosition`: If provided, the picking will use this pixel position instead of the `Ray` passed to the `pick` method. - `onBeforePickRender`: Function which gets called after a picking material has been created and setup and before the point cloud is rendered into the picking render target. This gives applications a chance to customize the renderTarget and the material.
1 parent 5e33a47 commit 0369286

1 file changed

Lines changed: 32 additions & 6 deletions

File tree

src/point-cloud-octree.ts

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,22 @@ import { byLevelAndIndex } from './utils/utils';
3535
export interface PickParams {
3636
pickWindowSize: number;
3737
pickOutsideClipRegion: boolean;
38+
/**
39+
* If provided, the picking will use this pixel position instead of the `Ray` passed to the `pick`
40+
* method.
41+
*/
42+
pixelPosition: Vector3;
43+
/**
44+
* Function which gets called after a picking material has been created and setup and before the
45+
* point cloud is rendered into the picking render target. This gives applications a chance to
46+
* customize the renderTarget and the material.
47+
*
48+
* @param material
49+
* The pick material.
50+
* @param renterTarget
51+
* The render target used for picking.
52+
*/
53+
onBeforePickRender: (material: PointCloudMaterial, renterTarget: WebGLRenderTarget) => void;
3854
}
3955

4056
interface IPickState {
@@ -405,13 +421,23 @@ export class PointCloudOctree extends PointCloudTree {
405421
this.updateMaterial(pickMaterial, nodes, camera, renderer);
406422
this.updatePickRenderTarget(this.pickState, width, height);
407423

408-
const pixelPos = helperVec3; // Use helper vector to prevent extra allocations.
409-
pixelPos.addVectors(camera.position, ray.direction).project(camera);
410-
pixelPos.x = (pixelPos.x + 1) * width * 0.5;
411-
pixelPos.y = (pixelPos.y + 1) * height * 0.5;
424+
if (params.onBeforePickRender) {
425+
params.onBeforePickRender(pickMaterial, pickState.renderTarget);
426+
}
427+
428+
const pixelPosition = helperVec3; // Use helper vector to prevent extra allocations.
429+
430+
if (params.pixelPosition) {
431+
pixelPosition.copy(params.pixelPosition);
432+
} else {
433+
pixelPosition.addVectors(camera.position, ray.direction).project(camera);
434+
pixelPosition.x = (pixelPosition.x + 1) * width * 0.5;
435+
pixelPosition.y = (pixelPosition.y + 1) * height * 0.5;
436+
}
437+
412438
const halfPickWndSize = (pickWndSize - 1) / 2;
413-
const x = Math.floor(clamp(pixelPos.x - halfPickWndSize, 0, width));
414-
const y = Math.floor(clamp(pixelPos.y - halfPickWndSize, 0, height));
439+
const x = Math.floor(clamp(pixelPosition.x - halfPickWndSize, 0, width));
440+
const y = Math.floor(clamp(pixelPosition.y - halfPickWndSize, 0, height));
415441

416442
// Render the intersected nodes onto the pick render target, clipping to a small pick window.
417443
renderer.setScissor(x, y, pickWndSize, pickWndSize);

0 commit comments

Comments
 (0)