Skip to content

Commit

Permalink
Fix 'look at object' for tracks, hits and muons
Browse files Browse the repository at this point in the history
  • Loading branch information
9inpachi committed Jun 15, 2020
1 parent 01676f7 commit 9ecf521
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 11 deletions.
4 changes: 3 additions & 1 deletion src/app/services/eventdisplay.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,11 +370,13 @@ export class EventdisplayService {
}

/**
* Move the camera to look at the object with the given uuid.
* Move the camera to look at the object with the given uuid
* and highlight it.
* @param uuid uuid of the object.
*/
public lookAtObject(uuid: string) {
this.graphicsLibrary.lookAtObject(uuid);
this.graphicsLibrary.highlightObject(uuid);
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/app/services/loaders/phoenix-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ export class PhoenixLoader implements EventDataLoader {
}
// uuid for selection of muons from the collections info panel
muonParams.uuid = muonScene.uuid;
muonScene.name = 'Muon';
// add to scene
return muonScene;
}
Expand Down
48 changes: 38 additions & 10 deletions src/app/services/three/controls-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,13 @@ export class ControlsManager {
getOverlayCamera(): Camera {
return this.overlayControls.object;
}
/**
* Get the main and overlay cameras.
* @returns An array containing the main and overlay cameras.
*/
getAllCameras(): Camera[] {
return [this.getMainCamera(), this.getOverlayCamera()];
}


// FUNCTIONS
Expand Down Expand Up @@ -256,18 +263,39 @@ export class ControlsManager {
* with the given uuid.
*/
public lookAtObject(uuid: string, objectsGroup: Object3D) {
const cameras = [this.getMainCamera(), this.getOverlayCamera()];
const origin = new Vector3(0, 0, 0);
objectsGroup.traverse((object: any) => {
if (object.uuid === uuid &&
object.position.distanceTo(origin) > 1) {
for (const camera of cameras) {
// Moving the camera to the object's position and then zooming out
new TWEEN.Tween(camera.position).to({
x: object.position.x * 1.1,
y: object.position.y * 1.1,
z: object.position.z * 1.1
}, 200).start();
if (object.uuid === uuid) {
let objectPosition = new Vector3();
if (['Track', 'Hit'].includes(object.name)) {
// Get the center of bounding sphere for Tracks and Hits
objectPosition = object.geometry.boundingSphere.center;
} else if (object.name === 'Muon') {
// Muon is a group of other event data so we traverse through it
object.traverse((muonObject: any) => {
if (muonObject.name === 'Track') {
// Get the max vector from the bounding box to accumulate with the clusters
objectPosition.add(
muonObject.geometry.boundingSphere.getBoundingBox().max
);
} else {
objectPosition.add(muonObject.position);
}
});
} else {
// Get the object position for all other elements
objectPosition = object.position;
}
// Check if the object is away from the origin
if (objectPosition.distanceTo(origin) > 1) {
for (const camera of this.getAllCameras()) {
// Moving the camera to the object's position and then zooming out
new TWEEN.Tween(camera.position).to({
x: objectPosition.x * 1.1,
y: objectPosition.y * 1.1,
z: objectPosition.z * 1.1
}, 200).start();
}
}
}
});
Expand Down

0 comments on commit 9ecf521

Please sign in to comment.