Skip to content

Commit 014aa80

Browse files
Allow camera to have initial position and look-at vectors. (#5452)
Currently in mesh plugin camera is positioned automatically which may not be convenient for applications where the model predicts both scene mesh/point cloud as well as camera position and orientation. This PR will allow to specify initial camera position and orientation as following: ``` const plugin_config = { 'camera': { 'position': [0, 0, 0], 'look_at': [1, 1, 1] } } ``` Co-authored-by: Stephan Lee <[email protected]>
1 parent 4568e2b commit 014aa80

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

tensorboard/plugins/mesh/tf_mesh_dashboard/mesh-viewer.ts

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ export class MeshViewer extends THREE.EventDispatcher {
5050
private _animationFrameIndex?: number;
5151

5252
private _camera?: THREE.PerspectiveCamera;
53+
private initCameraPosition?: THREE.Vector3;
54+
private initCameraLookAt?: THREE.Vector3;
5355
private _cameraControls?: OrbitControls;
5456
private _renderer: THREE.WebGLRenderer;
5557

@@ -156,6 +158,21 @@ export class MeshViewer extends THREE.EventDispatcher {
156158
config.camera.far
157159
);
158160
this._camera = camera;
161+
162+
this.initCameraPosition = null;
163+
if (config.camera.position) {
164+
this.initCameraPosition = new THREE.Vector3().fromArray(
165+
config.camera.position
166+
);
167+
}
168+
169+
this.initCameraLookAt = null;
170+
if (config.camera.lookAt) {
171+
this.initCameraLookAt = new THREE.Vector3().fromArray(
172+
config.camera.lookAt
173+
);
174+
}
175+
159176
var camControls = new OrbitControls(camera, domElement);
160177
const anyCamControls = camControls as any;
161178
// TODO(tensorboard-team): check whether these are depreacted; they no longer exist
@@ -411,11 +428,11 @@ export class MeshViewer extends THREE.EventDispatcher {
411428
// Make sure that even after arbitrary rotation mesh won't be clipped.
412429
const camera_to_far_edge = min_z < 0 ? -min_z + camera_z : camera_z - min_z;
413430
// Set camera position and orientation.
414-
this.setCameraViewpoint(
415-
{x: center.x, y: center.y, z: camera_z},
416-
camera_to_far_edge * 3,
417-
center
418-
);
431+
const cameraPosition =
432+
this.initCameraPosition ??
433+
new THREE.Vector3(center.x, center.y, camera_z);
434+
const lookAt = this.initCameraLookAt ?? center;
435+
this.setCameraViewpoint(cameraPosition, camera_to_far_edge * 3, lookAt);
419436
}
420437
/**
421438
* Creates mesh geometry for current step data.

0 commit comments

Comments
 (0)