Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

doc: add documentation with example for clipping planes #1219

Merged
merged 37 commits into from
Nov 2, 2020
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
d776434
example: improve clipping example
larsmoa Oct 16, 2020
d4074d4
doc: initial clipping documentation
larsmoa Oct 16, 2020
1f8e0da
chore: unused import
larsmoa Oct 16, 2020
640e3a0
doc: update example
larsmoa Oct 16, 2020
dbefecf
doc: add example for animated slicing plane
larsmoa Oct 17, 2020
c668ba5
feat: add Cognite3dViewer.cameraControlsEnabled to allow disabling na…
larsmoa Oct 19, 2020
aa6a53f
fix: oops - commented code that should have been commented
larsmoa Oct 19, 2020
3409831
Merge refs/heads/master into larsmoa/doc-clipping
cognite-bulldozer[bot] Oct 19, 2020
5c05abe
Merge remote-tracking branch 'refs/remotes/origin/larsmoa/doc-clippin…
larsmoa Oct 19, 2020
6b1ff34
Merge refs/heads/master into larsmoa/doc-clipping
cognite-bulldozer[bot] Oct 19, 2020
35119f7
Merge refs/heads/master into larsmoa/doc-clipping
cognite-bulldozer[bot] Oct 19, 2020
4369bad
Merge refs/heads/master into larsmoa/doc-clipping
cognite-bulldozer[bot] Oct 19, 2020
3cdacea
Merge refs/heads/master into larsmoa/doc-clipping
cognite-bulldozer[bot] Oct 19, 2020
c1b2001
doc: update example with draggable clip plane
larsmoa Oct 19, 2020
0cc1228
Merge branch 'larsmoa/doc-clipping' of github.com:cognitedata/reveal …
larsmoa Oct 19, 2020
28f84f0
Apply suggestions from code review
larsmoa Oct 20, 2020
8c44570
doc: cleanup clipping example code
larsmoa Oct 20, 2020
5a39eee
doc: update example
larsmoa Oct 20, 2020
057944a
doc: clarifications
larsmoa Oct 21, 2020
b3f69be
doc: document geometry filters
larsmoa Oct 21, 2020
fd63fe0
Merge refs/heads/master into larsmoa/doc-clipping
cognite-bulldozer[bot] Oct 23, 2020
1ee4b66
Merge refs/heads/master into larsmoa/doc-clipping
cognite-bulldozer[bot] Oct 23, 2020
0f008c3
Merge refs/heads/master into larsmoa/doc-clipping
cognite-bulldozer[bot] Oct 23, 2020
f1674f6
Merge refs/heads/master into larsmoa/doc-clipping
cognite-bulldozer[bot] Oct 23, 2020
414d523
Merge refs/heads/master into larsmoa/doc-clipping
cognite-bulldozer[bot] Oct 26, 2020
bb58178
Merge refs/heads/master into larsmoa/doc-clipping
cognite-bulldozer[bot] Oct 28, 2020
327beb1
Merge refs/heads/master into larsmoa/doc-clipping
cognite-bulldozer[bot] Oct 28, 2020
7e6903d
Merge remote-tracking branch 'origin' into larsmoa/doc-clipping
larsmoa Oct 30, 2020
5f8b989
fix: duplicate example after merge
larsmoa Oct 30, 2020
e43509b
doc: adjust clipping doc
larsmoa Oct 30, 2020
f07244f
doc: usage instructions
larsmoa Oct 30, 2020
dde4ad6
Merge refs/heads/master into larsmoa/doc-clipping
cognite-bulldozer[bot] Oct 30, 2020
4535445
Merge refs/heads/master into larsmoa/doc-clipping
cognite-bulldozer[bot] Oct 30, 2020
e5695ea
Merge refs/heads/master into larsmoa/doc-clipping
cognite-bulldozer[bot] Nov 2, 2020
ef854f7
fix: use customScope over window variable to expose DragControls
larsmoa Nov 2, 2020
85b2287
Merge refs/heads/master into larsmoa/doc-clipping
cognite-bulldozer[bot] Nov 2, 2020
54f3583
Merge refs/heads/master into larsmoa/doc-clipping
cognite-bulldozer[bot] Nov 2, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions documentation/docs/demos/Cognite3DViewerDemo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {

import { CanvasWrapper } from '@site/src/components/styled';
import { DemoProps } from '@site/src/components/DemoProps';
import { DragControls } from 'three/examples/jsm/controls/DragControls';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import { DragControls } from 'three/examples/jsm/controls/DragControls';


type OwnProps = {
modelType?: SupportedModelTypes;
Expand Down
88 changes: 62 additions & 26 deletions documentation/docs/examples/clipping.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ to be loaded (or rather loaded in a lower detail level).
<source src={useBaseUrl('/img/cad-clipping.webm')} />
</video>

:::warning
Clipping planes are currently not supported by point cloud models.
:::caution
Slicing planes are currently not supported by point cloud models.
:::

## Examples
Expand All @@ -33,8 +33,9 @@ replaces any active slicing planes.

Typically, [setFromNormalAndCoplanarPoint](https://threejs.org/docs/#api/en/math/Plane.setFromNormalAndCoplanarPoint)
is used to create slicing planes. This function accepts a direction that defines the orientation of
the plane and a point on the plane. For example will the following
code create a slicing plane that only accepts geometry below `Y = 55`:
the plane and a point on the plane. For example, the following
code will create a slicing plane that only accepts geometry below `Y = 55`:

```jsx runnable
const orientation = new THREE.Vector3(0, -1, 0);
const point = new THREE.Vector3(0, 55, 0);
Expand All @@ -44,8 +45,8 @@ viewer.setSlicingPlanes([plane]);

### Animated slicing plane

Planes can be manipulated runtime and effects will have effect in the viewer. Note however that rendering must be
triggered after updating the plane before the change will have visual effect. This can be done using
Planes can be manipulated runtime and effects will have an effect in the viewer. Note however that rendering must be
triggered after updating the plane before the change will have a visual effect. This can be done using
`Cognite3DViewer.forceRerender()`.

Below is an example animates a slicing plane by ping-ponging the plane in the vertical direction.
Expand All @@ -70,42 +71,77 @@ setInterval(() => {
viewer.forceRerender();
}, 1000 / 60);
```
:::info
Updating `THREE.Plane`-instances will not trigger data loading. Typically you will need to trigger data loading if
you do substantial changes to the slicing planes. In these cases, use `Cognite3DViewer.setSlicingPlanes`. The example
above performs substantial changes to the planes without loading data. In a real application it's recommended to
not load data during animation, but initiate data after an animation is completed.

:::note
Updating `THREE.Plane`-instances will not trigger data loading. To manually trigger data loading after doing
substantial changes to the slicing planes, use `Cognite3DViewer.setSlicingPlanes`. Note that the example
above performs substantial changes to the planes without loading data. In a real application it's recommended
to not load data during animation, but initiate data after an animation is completed.
:::

### CAD geometry filter
### Interactable slicing planes

Often it's required to have interactive slicing planes that the user can modify. The following example
show how [ThreeJS DragControls](https://threejs.org/docs/#examples/en/controls/DragControls) can be used
to manipulate the slicing planes.

After running this snippet the slicing plane can be manipulated by dragging the white manipulator.

```js runnable
// import { DragControls } from 'three/examples/jsm/controls/DragControls';

const bounds = model.getModelBoundingBox();

// Create draggable cone at center of bounds
const center = bounds.getCenter(new THREE.Vector3());
var geometry = new THREE.BoxBufferGeometry(10, 10, 10);
var mesh = new THREE.Mesh(geometry, new THREE.MeshBasicMaterial({ color: 'green' }));
mesh.position.copy(center);
viewer.addObject3D(mesh);

// Prepare a clipping plane
const initialDragPosition = new THREE.Vector3(bounds.min.x, 0.5*(bounds.max.y + bounds.min.y), bounds.min.z);
const draggerGeometry = new THREE.SphereBufferGeometry(5);
const draggerMaterial = new THREE.MeshBasicMaterial({ color: 'white' });
const draggerMesh = new THREE.Mesh(draggerGeometry, draggerMaterial);
draggerMesh.position.copy(initialDragPosition);
viewer.addObject3D(draggerMesh);

// Prepare a slicing plane
const orientation = new THREE.Vector3(0, -1, 0);
const point = new THREE.Vector3(0, center.y, 0);
const plane = new THREE.Plane();
plane.setFromNormalAndCoplanarPoint(orientation, point);
plane.setFromNormalAndCoplanarPoint(orientation, initialDragPosition);
viewer.setSlicingPlanes([plane]);

const controls = new DragControls([mesh], viewer.getCamera(), viewer.domElement);
// Handle drag events
const controls = new DragControls([draggerMesh], viewer.getCamera(), viewer.domElement);
controls.addEventListener('drag', () => {
// Fix XZ-poistion
mesh.position.set(center.x, mesh.position.y, center.z);
draggerMesh.position.set(initialDragPosition.x, draggerMesh.position.y, initialDragPosition.z);
// Update slicing plane
plane.setFromNormalAndCoplanarPoint(new THREE.Vector3(0, -1, 0), mesh.position);
plane.setFromNormalAndCoplanarPoint(new THREE.Vector3(0, -1, 0), draggerMesh.position);
viewer.forceRerender();
});
controls.addEventListener('dragstart', () => viewer.cameraControlsEnabled = false);
controls.addEventListener('dragend', () => viewer.cameraControlsEnabled = true);
controls.addEventListener('dragstart', () => {
draggerMaterial.color = new THREE.Color('gray');
viewer.cameraControlsEnabled = false;
});
controls.addEventListener('dragend', () => {
draggerMaterial.color = new THREE.Color('white');
viewer.cameraControlsEnabled = true;
});
```

### CAD geometry filter

A special type of slicing is to provide a "geometry filter" when loading the model. A geometry filter restricts the
area to load geometry for and is specified when the model is created.

```js
const min = new THREE.Vector3(10, 20, 30);
const max = new THREE.Vector3(20, 30, 40);
viewer.addModel({
modelId,
revisionId,
geometryFilter: {
boundingBox: new THREE.Box3(min, max)
}
});
```

:::note
Geometry filters are static and cannot be changed after creating the model.
:::
2 changes: 1 addition & 1 deletion documentation/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ module.exports = {
'examples/node-visiting',
'examples/cad-nodefiltering',
'examples/cad-preview',
'examples/pointcloud',
'examples/clipping',
'examples/pointcloud',
],
},
{
Expand Down