Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[Hackathon] Faster On-Hover Raycasting in 3D viewport #8106

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
8822f1d
Upgrade threejs to v0.169. Add three-mesh-bvh library and use it to s…
daniel-wer Sep 30, 2024
fcc3f3b
log timing
fm3 Sep 30, 2024
2afee22
log duration for raycaster
fm3 Sep 30, 2024
0e2636a
save some backend perf in chunk list request
fm3 Sep 30, 2024
a5efc3a
Update BufferGeometryUtils. Merge all geometries of a precomputed mes…
daniel-wer Sep 30, 2024
05b6647
Merge branch 'faster-caster' of github.com:scalableminds/webknossos i…
daniel-wer Sep 30, 2024
852fc2f
Merge all geometries of each mesh respectively
daniel-wer Sep 30, 2024
36f5c0f
throttling delay 0, weil das ja klar is
fm3 Sep 30, 2024
b87610b
Revert "throttling delay 0, weil das ja klar is"
daniel-wer Sep 30, 2024
2bbd009
remove logging in raycaster
fm3 Sep 30, 2024
80a53fe
Merge branch 'faster-caster' of github.com:scalableminds/webknossos i…
fm3 Sep 30, 2024
5f279e7
Revert "Merge all geometries of each mesh respectively"
daniel-wer Oct 1, 2024
65cbc5e
revert mesh merging
daniel-wer Oct 1, 2024
8a2bea9
Merge branch 'faster-caster' of github.com:scalableminds/webknossos i…
daniel-wer Oct 1, 2024
77f2986
fix mergeBufferGeometries
daniel-wer Oct 1, 2024
08e8de3
fix mergeBufferGeometries
daniel-wer Oct 1, 2024
67cd905
Remove unnecessary react-debounce-render lib
daniel-wer Oct 1, 2024
915e589
optimize chunkinfo merge, chunk request reads
fm3 Oct 1, 2024
a0d8734
further optimize chunk loading reads
fm3 Oct 1, 2024
81f8de7
restore file exists check
fm3 Oct 1, 2024
1d7acef
Merge branch 'faster-caster' of github.com:scalableminds/webknossos i…
daniel-wer Oct 1, 2024
4c899bb
Revert "revert mesh merging"
daniel-wer Oct 1, 2024
57c1522
Reapply "Merge all geometries of each mesh respectively"
daniel-wer Oct 1, 2024
bc9d8e1
Add window.DEBUG_BVH flag and don't use groups when merging geometrie…
daniel-wer Oct 1, 2024
7fb264d
less logging
fm3 Oct 1, 2024
c5c3e94
remove backend changes from this PR, they are moved to https://github…
fm3 Oct 2, 2024
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,274 changes: 905 additions & 369 deletions frontend/javascripts/libs/BufferGeometryUtils.ts

Large diffs are not rendered by default.

13 changes: 9 additions & 4 deletions frontend/javascripts/libs/visibility_aware_raycaster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ export default class VisibilityAwareRaycaster extends THREE.Raycaster {
recursive?: boolean,
intersects: THREE.Intersection<TIntersected>[] = [],
): THREE.Intersection<TIntersected>[] {
let duration = 0;
for (let i = 0, l = objects.length; i < l; i++) {
if (objects[i].visible) {
this.intersectObject(objects[i], recursive, intersects);
duration += this.intersectObject(objects[i], recursive, intersects);
}
}

Expand All @@ -30,23 +31,27 @@ export default class VisibilityAwareRaycaster extends THREE.Raycaster {
object: THREE.Object3D,
recursive?: boolean,
intersects: THREE.Intersection<TIntersected>[] = [],
): THREE.Intersection<TIntersected>[] {
): number {
let duration = 0;
if (object.layers.test(this.layers)) {
const before = performance.now();
object.raycast(this, intersects);
const after = performance.now();
duration = after - before;
}

if (recursive === true) {
const children = object.children;

for (let i = 0, l = children.length; i < l; i++) {
if (children[i].visible) {
this.intersectObject(children[i], true, intersects);
duration += this.intersectObject(children[i], true, intersects);
}
}
}

intersects.sort(ascSort);

return intersects;
return duration;
}
}
1 change: 1 addition & 0 deletions frontend/javascripts/oxalis/controller/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ if (typeof window !== "undefined") {
}
// @ts-ignore
window.testContextLoss = testContextLoss;
window.getRenderer = getRenderer;
}

export { getRenderer };
Expand Down
32 changes: 14 additions & 18 deletions frontend/javascripts/oxalis/controller/segment_mesh_controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ import { NO_LOD_MESH_INDEX } from "oxalis/model/sagas/mesh_saga";
import Store from "oxalis/store";
import type { AdditionalCoordinate } from "types/api_flow_types";
import { getAdditionalCoordinatesAsString } from "oxalis/model/accessors/flycam_accessor";
import { MeshBVH, MeshBVHHelper, acceleratedRaycast, getBVHExtremes } from "three-mesh-bvh";

// Add the raycast function. Assumes the BVH is available on
// the `boundsTree` variable
THREE.Mesh.prototype.raycast = acceleratedRaycast;

const ACTIVATED_COLOR = [0.7, 0.5, 0.1] as const;
const HOVERED_COLOR = [0.65, 0.5, 0.1] as const;
Expand Down Expand Up @@ -89,7 +94,6 @@ export default class SegmentMeshController {
bufferGeometry as BufferGeometryWithInfo,
segmentId,
null,
null,
NO_LOD_MESH_INDEX,
layerName,
additionalCoordinates,
Expand Down Expand Up @@ -123,7 +127,7 @@ export default class SegmentMeshController {
{
opacity: 1,
},
500,
100,
)
.onUpdate(function onUpdate(this: { opacity: number }) {
meshMaterial.opacity = this.opacity;
Expand All @@ -144,7 +148,6 @@ export default class SegmentMeshController {
addMeshFromGeometries(
geometries: BufferGeometryWithInfo[],
segmentId: number,
offset: Vector3 | null = null,
scale: Vector3 | null = null,
lod: number,
layerName: string,
Expand Down Expand Up @@ -174,16 +177,18 @@ export default class SegmentMeshController {
}
const meshChunks = geometries.map((geometry) => {
const meshChunk = this.constructMesh(segmentId, layerName, geometry);
if (offset) {
meshChunk.translateX(offset[0]);
meshChunk.translateY(offset[1]);
meshChunk.translateZ(offset[2]);
}
meshChunk.geometry.boundsTree = new MeshBVH(meshChunk.geometry);
console.log(getBVHExtremes(meshChunk.geometry.boundsTree));
return meshChunk;
});
const group = new THREE.Group() as SceneGroupForMeshes;
for (const meshChunk of meshChunks) {
group.add(meshChunk);
if (window.DEBUG_BVH) {
const bvhHelper = new MeshBVHHelper(meshChunk);
bvhHelper.displayParents = true;
group.add(bvhHelper);
}
}
group.segmentId = segmentId;
this.addMeshToMeshGroups(additionalCoordinatesString, layerName, segmentId, lod, group);
Expand All @@ -199,21 +204,12 @@ export default class SegmentMeshController {
addMeshFromGeometry(
geometry: BufferGeometryWithInfo,
segmentId: number,
offset: Vector3 | null = null,
scale: Vector3 | null = null,
lod: number,
layerName: string,
additionalCoordinates: AdditionalCoordinate[] | null | undefined,
): void {
this.addMeshFromGeometries(
[geometry],
segmentId,
offset,
scale,
lod,
layerName,
additionalCoordinates,
);
this.addMeshFromGeometries([geometry], segmentId, scale, lod, layerName, additionalCoordinates);
}

removeMeshById(segmentId: number, layerName: string): void {
Expand Down
2 changes: 1 addition & 1 deletion frontend/javascripts/oxalis/controller/td_controller.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ class TDController extends React.PureComponent<Props> {
return;
}

this.props.planeView.throttledPerformMeshHitTest([position.x, position.y]);
this.props.planeView.performMeshHitTest([position.x, position.y]);
},
leftClick: (pos: Point2, plane: OrthoView, event: MouseEvent, isTouch: boolean) => {
if (skeletonControls != null) {
Expand Down
Loading