Skip to content

Commit

Permalink
Merge pull request #27 from concord-consortium/188086293-fix-tilt-slider
Browse files Browse the repository at this point in the history
Fix tilt slider in Close-up view and animation playing
  • Loading branch information
bacalj authored Aug 20, 2024
2 parents 28e5c70 + 9117f09 commit 1524511
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 deletions src/grasp-seasons/3d-views/orbit-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,26 @@ export default class OrbitView extends BaseView {
desiredCameraLookAt?: THREE.Vector3;
cameraSwitchTimestamp?: number;

_suppressCameraChangeEvent = false;

constructor(parentEl: HTMLElement, props = DEF_PROPERTIES) {
super(parentEl, props, "orbit-view");
this.registerInteractionHandler(this.earthDraggingInteraction);

this.controls.addEventListener("change", () => {
if (this._suppressCameraChangeEvent) {
return;
}
this.dispatch.emit("props.change", { cameraTiltAngle: this.getCameraTiltAngle() });
});
}

suppressCameraChangeEvent(callback: () => void) {
this._suppressCameraChangeEvent = true;
callback();
this._suppressCameraChangeEvent = false;
}

setViewAxis(vec3: THREE.Vector3) {
this.cameraSymbol.lookAt(vec3);
this.cameraSymbol.rotateX(Math.PI * 0.5);
Expand Down Expand Up @@ -223,14 +234,20 @@ export default class OrbitView extends BaseView {
const oldEarthPosition = this.earth.posObject.position.clone();
super._updateDay();
if (this.props.earthCloseUpView) {
const positionDiff = this.earth.posObject.position.clone().sub(oldEarthPosition);
if (this.desiredCameraPos && this.desiredCameraLookAt) {
this.desiredCameraPos.add(positionDiff);
this.desiredCameraLookAt.add(positionDiff);
} else {
this.camera.position.add(positionDiff);
this.controls.target.add(positionDiff);
}
const positionDiff = this.earth.posObject.position.clone().sub(oldEarthPosition);
if (this.desiredCameraPos && this.desiredCameraLookAt) {
this.desiredCameraPos.add(positionDiff);
this.desiredCameraLookAt.add(positionDiff);
} else {
// It is necessary to suppress the camera change event to avoid conflicts with the camera position update
// triggered by the tilt angle slider. This is acceptable, as the daily update will never change the camera
// tilt angle.
this.suppressCameraChangeEvent(() => {
this.camera.position.add(positionDiff);
this.controls.target.add(positionDiff);
this.controls.update(); // Immediately flush the change event that will be suppressed.
});
}
}
}

Expand Down

0 comments on commit 1524511

Please sign in to comment.