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

Bounding box toggle in tweakpane #434

Merged
merged 2 commits into from
Dec 7, 2024
Merged
Changes from all commits
Commits
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
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
Loading