Skip to content

Commit

Permalink
Merge pull request #434 from simularium/feature/bounding-box-tweakpane
Browse files Browse the repository at this point in the history
Bounding box toggle in tweakpane
  • Loading branch information
frasercl authored Dec 7, 2024
2 parents cf905dd + 18e96ce commit 725c733
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/visGeometry/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ class VisGeometry {
public hemiLight: HemisphereLight;
public boundingBox!: Box3;
public boundingBoxMesh!: Box3Helper;
public showBounds: boolean;
public tickMarksMesh!: LineSegments;
public tickIntervalLength: number;
// front and back of transformed bounds in camera space
Expand Down Expand Up @@ -227,6 +228,7 @@ class VisGeometry {
this.instancedMeshGroup.name = "instanced meshes for agents";
this.scene.add(this.instancedMeshGroup);

this.showBounds = true;
this.resetBounds(DEFAULT_VOLUME_DIMENSIONS);

this.dl = new DirectionalLight(0xffffff, 0.6);
Expand Down Expand Up @@ -439,6 +441,7 @@ class VisGeometry {
g: this.backgroundColor.g * 255,
b: this.backgroundColor.b * 255,
},
showBounds: true,
};

this.gui.addInput(settings, "bgcolor").on("change", (event) => {
Expand All @@ -448,6 +451,9 @@ class VisGeometry {
event.value.b / 255.0,
]);
});
this.gui.addInput(settings, "showBounds").on("change", (event) => {
this.setShowBounds(event.value);
});
this.gui.addButton({ title: "Capture Frame" }).on("click", () => {
this.render(0);
const dataUrl =
Expand Down Expand Up @@ -1064,8 +1070,8 @@ class VisGeometry {
);

// final pass, add extra stuff on top: bounding box and line paths
this.boundingBoxMesh.visible = true;
this.tickMarksMesh.visible = true;
this.boundingBoxMesh.visible = this.showBounds;
this.tickMarksMesh.visible = this.showBounds;
this.agentPathGroup.visible = true;

this.threejsrenderer.autoClear = false;
Expand Down Expand Up @@ -1241,7 +1247,6 @@ class VisGeometry {
boundsAsTuple: Bounds
): void {
const [minX, minY, minZ, maxX, maxY, maxZ] = boundsAsTuple;
const visible = this.tickMarksMesh ? this.tickMarksMesh.visible : true;

const longestEdgeLength = Math.max(...volumeDimensions);
// Use the length of the longest bounding box edge to determine the tick interval (scale bar) length
Expand Down Expand Up @@ -1371,14 +1376,11 @@ class VisGeometry {
color: BOUNDING_BOX_COLOR,
});
this.tickMarksMesh = new LineSegments(lineGeometry, lineMaterial);
this.tickMarksMesh.visible = visible;
this.tickMarksMesh.visible = this.showBounds;
}

public createBoundingBox(boundsAsTuple: Bounds): void {
const [minX, minY, minZ, maxX, maxY, maxZ] = boundsAsTuple;
const visible = this.boundingBoxMesh
? this.boundingBoxMesh.visible
: true;
this.boundingBox = new Box3(
new Vector3(minX, minY, minZ),
new Vector3(maxX, maxY, maxZ)
Expand All @@ -1387,7 +1389,7 @@ class VisGeometry {
this.boundingBox,
BOUNDING_BOX_COLOR
);
this.boundingBoxMesh.visible = visible;
this.boundingBoxMesh.visible = this.showBounds;
}

public resetBounds(volumeDimensions?: number[]): void {
Expand Down Expand Up @@ -1873,8 +1875,7 @@ class VisGeometry {
}

public setShowBounds(showBounds: boolean): void {
this.boundingBoxMesh.visible = showBounds;
this.tickMarksMesh.visible = showBounds;
this.showBounds = showBounds;
}

public showPathForAgent(id: number, visible: boolean): void {
Expand Down

0 comments on commit 725c733

Please sign in to comment.