Skip to content

Commit

Permalink
fix: apply clipping planes on newly loaded point clouds (#3433)
Browse files Browse the repository at this point in the history
  • Loading branch information
haakonflatval-cognite authored Jun 27, 2023
1 parent e0a533e commit d197669
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
7 changes: 6 additions & 1 deletion viewer/packages/pointclouds/src/PointCloudManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export class PointCloudManager {
private readonly _loadingStateHandler: PointCloudLoadingStateHandler;
private readonly _potreeInstance: Potree;
private readonly _pointCloudNodes: PointCloudNode[] = [];
private _globalClippingPlanes: THREE.Plane[] = [];

private readonly _cameraSubject: Subject<THREE.PerspectiveCamera> = new Subject();
private readonly _modelSubject: Subject<{ modelIdentifier: ModelIdentifier; operation: 'add' | 'remove' }> =
Expand Down Expand Up @@ -94,6 +95,7 @@ export class PointCloudManager {
}

set clippingPlanes(planes: THREE.Plane[]) {
this._globalClippingPlanes = planes;
this._pointCloudNodes.forEach(node => node.octree.setGlobalClippingPlane(planes));
this.requestRedraw();
}
Expand Down Expand Up @@ -131,7 +133,10 @@ export class PointCloudManager {
this._loadingStateHandler.onModelAdded();

this._modelSubject.next({ modelIdentifier, operation: 'add' });
this._materialManager.initializeClippingPlanesForPointCloud(modelIdentifier.revealInternalId);
this._materialManager.initializeClippingPlanesForPointCloud(
modelIdentifier.revealInternalId,
this._globalClippingPlanes
);

return pointCloudNode;
}
Expand Down
7 changes: 4 additions & 3 deletions viewer/packages/rendering/src/PointCloudMaterialManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import { PointCloudObjectIdMaps } from './pointcloud-rendering/PointCloudObjectIdMaps';
import { PointCloudMaterial } from './pointcloud-rendering';
import { PointCloudMaterialParameters } from './render-passes/types';
import { Plane } from 'three';

export class PointCloudMaterialManager {
private readonly _modelsMaterialsMap: Map<symbol, PointCloudMaterial> = new Map();
Expand Down Expand Up @@ -38,16 +39,16 @@ export class PointCloudMaterialManager {
return material;
}

initializeClippingPlanesForPointCloud(modelIdentifier: symbol): void {
initializeClippingPlanesForPointCloud(modelIdentifier: symbol, clippingPlanes: Plane[]): void {
const material = this.getModelMaterial(modelIdentifier);

material.clipping = true;
material.clipIntersection = false;
material.clippingPlanes = [];
material.clippingPlanes = [...clippingPlanes];

material.defines = {
...material.defines,
NUM_CLIPPING_PLANES: 0,
NUM_CLIPPING_PLANES: clippingPlanes.length,
UNION_CLIPPING_PLANES: 0
};
}
Expand Down

0 comments on commit d197669

Please sign in to comment.