Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support lookat commands #93

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 44 additions & 6 deletions editor/js/OpenSimEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var OpenSimEditor = function () {
this.dolly_object = new THREE.Object3D();
this.dolly_object.name = 'Dolly';
this.dolly_object.position.y = 0;
this.recording = false;
this.recording = false;

this.models = [];
this.currentModel = undefined; //uuid of current model call getCurrentModel for actualobject
Expand All @@ -28,7 +28,7 @@ var OpenSimEditor = function () {
var supportedOpenSimTypes = ["PathPoint", "Marker"];
//this.cameraEye = new THREE.Mesh(new THREE.SphereGeometry(50), new THREE.MeshBasicMaterial({ color: 0xdddddd }));
//this.cameraEye.name = 'CameraEye';

var cameraOffset;
var Signal = signals.Signal;

this.signals = {
Expand Down Expand Up @@ -937,14 +937,19 @@ OpenSimEditor.prototype = {
this.signals.defaultCameraApplied.dispatch(aabbCenter);

},
processViewCommand: function (command) {
this.handleKey(command.charAt(0));
},
handleKey: function (keyCode) {
var positionOffset = new THREE.Vector3();
switch (keyCode) {
case 73:
this.viewZoom(100.0);
case 73:
case "i":
this.viewZoom(100.0);
return;
case 79:
this.viewZoom(-100.0);
case 79:
case "o":
this.viewZoom(-100.0);
return;
case 37:
positionOffset.set(100, 0., 0.);
Expand All @@ -958,6 +963,9 @@ OpenSimEditor.prototype = {
case 40:
positionOffset.set(0, 100., 0.);
break;
case 40:
positionOffset.set(0, 100., 0.);
break;
}
positionOffset.applyQuaternion(this.camera.quaternion);
this.camera.position.add(positionOffset);
Expand Down Expand Up @@ -1127,6 +1135,36 @@ OpenSimEditor.prototype = {
refresh: function() {
var changeEvent = { type: 'change' };
this.control.dispatchEvent( changeEvent );
},
processCameraCommand: function (commandJson) {
var cmd = commandJson.Command;
var target = commandJson.Target;
if (target !== undefined) {
if (cmd === "LookAt") {
var o = editor.objectByUuid(target);
var v1 = new THREE.Vector3();
v1.setFromMatrixPosition(o.matrixWorld);
editor.camera.position.x = v1.x;
editor.camera.position.y = v1.y;
editor.camera.lookAt(v1);
editor.camera.updateProjectionMatrix();
editor.refresh();
}
}
},
cameraFollow: function (followedObject) {
followedObject.updateMatrixWorld();
var v1 = new THREE.Vector3();
v1.setFromMatrixPosition(followedObject.matrixWorld);
var positionOffset = new THREE.Vector3(v1.x, 0, 0);
positionOffset.applyQuaternion(this.camera.quaternion);
this.camera.position.x = v1.x + this.cameraOffset;
this.camera.updateProjectionMatrix();
// Send offset along so that rotation center is updated by EditorControl
this.signals.cameraChanged.dispatch(this.camera, positionOffset);
},
cameraSaveOffset: function () {
this.cameraOffset = this.camera.position.x;
}

};
20 changes: 19 additions & 1 deletion editor/websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ var wsUri = "ws://" + document.location.host + "/visEndpoint";
var websocket = new WebSocket(wsUri);

var processing = false;
var following = false;
var followedObject = undefined;
var totalTime = 0.0;
var numFrames = 0;
websocket.onerror = function(evt) { onError(evt) };
Expand Down Expand Up @@ -62,6 +64,9 @@ function onMessage(evt) {
editor.updatePath(paths[p]);
}
}
if (following) {
editor.cameraFollow(followedObject);
}
editor.refresh();
var t1 = performance.now() - t0;
totalTime +=t1;
Expand Down Expand Up @@ -102,7 +107,20 @@ function onMessage(evt) {
case "PathOperation":
editor.processPathEdit(msg);
break;
case "startAnimation":
case "View":
editor.processViewCommand(msg.Command);
break;
case "Camera":
if (msg.Command === "Follow" && msg.Target != undefined) {
following = true;
followedObject = editor.objectByUuid(msg.Target);
editor.cameraSaveOffset();
}
else
following = false;
editor.processCameraCommand(msg);
break;
case "startAnimation":
totalTime=0.0;
numFrames = 0;
break;
Expand Down