diff --git a/editor/js/OpenSimEditor.js b/editor/js/OpenSimEditor.js index dac3d4ddb7d01a..80b18140e714fd 100644 --- a/editor/js/OpenSimEditor.js +++ b/editor/js/OpenSimEditor.js @@ -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 @@ -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 = { @@ -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.); @@ -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); @@ -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; } }; diff --git a/editor/websocket.js b/editor/websocket.js index 1a4e651a9665a8..e49fbfdd8c793b 100644 --- a/editor/websocket.js +++ b/editor/websocket.js @@ -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) }; @@ -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; @@ -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;