Skip to content

Commit 769c19b

Browse files
authored
Merge pull request #66 from jun-sironamedical/feature/focalpoint_prop
Added focalPoint as prop and setting on update
2 parents 6a99b70 + ce8c428 commit 769c19b

1 file changed

Lines changed: 33 additions & 7 deletions

File tree

src/core/View.js

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,9 @@ export default class View extends Component {
430430
interactive,
431431
cameraPosition,
432432
cameraViewUp,
433+
cameraFocalPoint,
433434
cameraParallelProjection,
435+
autoResetCamera,
434436
triggerRender,
435437
triggerResetCamera,
436438
showCubeAxes,
@@ -454,23 +456,31 @@ export default class View extends Component {
454456
) {
455457
const camera = this.renderer.getActiveCamera();
456458
camera.setParallelProjection(cameraParallelProjection);
457-
if (previous) {
459+
if (previous && autoResetCamera) {
458460
this.resetCamera();
459461
}
460462
}
461463
if (
462-
cameraPosition &&
463-
(!previous ||
464-
JSON.stringify(cameraPosition) !==
465-
JSON.stringify(previous.cameraPosition))
464+
(cameraPosition &&
465+
(!previous ||
466+
JSON.stringify(cameraPosition) !==
467+
JSON.stringify(previous.cameraPosition))) ||
468+
(cameraViewUp &&
469+
(!previous ||
470+
JSON.stringify(cameraViewUp) !==
471+
JSON.stringify(previous.cameraViewUp))) ||
472+
(cameraFocalPoint &&
473+
(!previous ||
474+
JSON.stringify(cameraFocalPoint) !==
475+
JSON.stringify(previous.cameraFocalPoint)))
466476
) {
467477
const camera = this.renderer.getActiveCamera();
468478
camera.set({
469479
position: cameraPosition,
470480
viewUp: cameraViewUp,
471-
focalPoint: [0, 0, 0],
481+
focalPoint: cameraFocalPoint,
472482
});
473-
if (previous) {
483+
if (previous && autoResetCamera) {
474484
this.resetCamera();
475485
}
476486
}
@@ -676,6 +686,8 @@ View.defaultProps = {
676686
background: [0.2, 0.3, 0.4],
677687
cameraPosition: [0, 0, 1],
678688
cameraViewUp: [0, 1, 0],
689+
cameraFocalPoint: [0, 0, 0],
690+
autoResetCamera: true,
679691
cameraParallelProjection: false,
680692
triggerRender: 0,
681693
triggerResetCamera: 0,
@@ -759,6 +771,11 @@ View.propTypes = {
759771
*/
760772
cameraPosition: PropTypes.array,
761773

774+
/**
775+
* Initial camera focal point from an object in [0,0,0]
776+
*/
777+
cameraFocalPoint: PropTypes.array,
778+
762779
/**
763780
* Initial camera position from an object in [0,0,0]
764781
*/
@@ -769,6 +786,15 @@ View.propTypes = {
769786
*/
770787
cameraParallelProjection: PropTypes.bool,
771788

789+
/**
790+
* Whether to automatically call resetCamera() (default: true)
791+
*
792+
* When set to false, the user must explicitly provide camera
793+
* properties. Note that the initial resetCamera() call will
794+
* still occur upon component mount.
795+
*/
796+
autoResetCamera: PropTypes.bool,
797+
772798
/**
773799
* Property use to trigger a render when changing.
774800
*/

0 commit comments

Comments
 (0)