Skip to content

Commit

Permalink
Support for camera operations on the viewer/js side
Browse files Browse the repository at this point in the history
  • Loading branch information
aymanhab committed Jun 18, 2024
1 parent 6118de4 commit 03eed26
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions editor/js/OpenSimEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -1417,11 +1417,42 @@ OpenSimEditor.prototype = {
console.log(this.camera.matrix)
this.camera.updateProjectionMatrix()
// need to update the camera control in sync
this.signals.cameraChanged.dispatch(this.camera);
var changeEvent = { type: 'change' };
this.control.dispatchEvent( changeEvent );
}
break;
case "moveto":
let moveToCamName = json.targetCam
targetCamJSON = this.savedCameras[moveToCamName]
if (targetCamJSON !== undefined) {
let mat4 = new THREE.Matrix4().set(
targetCamJSON.object.matrix[0], targetCamJSON.object.matrix[4], targetCamJSON.object.matrix[8], targetCamJSON.object.matrix[12],
targetCamJSON.object.matrix[1], targetCamJSON.object.matrix[5], targetCamJSON.object.matrix[9], targetCamJSON.object.matrix[13],
targetCamJSON.object.matrix[2], targetCamJSON.object.matrix[6], targetCamJSON.object.matrix[10], targetCamJSON.object.matrix[14],
targetCamJSON.object.matrix[3], targetCamJSON.object.matrix[7], targetCamJSON.object.matrix[11], targetCamJSON.object.matrix[15]
)
var targetPos = new THREE.Vector3(0., 0., 0.)
var targetScale = new THREE.Vector3(1., 1., 1.)
var targetQuat = new THREE.Quaternion()
mat4.decompose(targetPos, targetQuat, targetScale)
this.signals.moveCameraTo.dispatch(targetPos, new THREE.Vector3(0., 0., 0.), targetQuat);
}
break;
case "toJson":
let dictionaryJson = JSON.stringify(this.savedCameras)
const a = document.createElement('a');
const blob = new Blob([JSON.stringify(dictionaryJson)]);
a.href = URL.createObjectURL(blob);
a.download = 'save_cameras.json'; //filename to download
a.click();
break;
case "fromJson":
let camsList = json.cameras
let camsDictionary = JSON.parse(camsList)
// Populate this.savedCameras from camsDictionary

break;

}
}
Expand Down

0 comments on commit 03eed26

Please sign in to comment.