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

add initial support for 3d markers with plane movement #232

Merged
merged 3 commits into from
Aug 24, 2018
Merged
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
3 changes: 3 additions & 0 deletions src/Ros3D.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ ROS3D.INTERACTIVE_MARKER_MOVE_AXIS = 3;
ROS3D.INTERACTIVE_MARKER_MOVE_PLANE = 4;
ROS3D.INTERACTIVE_MARKER_ROTATE_AXIS = 5;
ROS3D.INTERACTIVE_MARKER_MOVE_ROTATE = 6;
ROS3D.INTERACTIVE_MARKER_MOVE_3D = 7;
ROS3D.INTERACTIVE_MARKER_ROTATE_3D = 8;
ROS3D.INTERACTIVE_MARKER_MOVE_ROTATE_3D = 9;

// Interactive marker rotation behavior
ROS3D.INTERACTIVE_MARKER_INHERIT = 0;
Expand Down
48 changes: 48 additions & 0 deletions src/interactivemarkers/InteractiveMarker.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,54 @@ ROS3D.InteractiveMarker.prototype.moveAxis = function(control, origAxis, event3d
}
};


/**
* Move with respect to the plane based on the contorl and event.
*
* @param control - the control to use
* @param origNormal - the normal of the origin
* @param event3d - the event that caused this
*/
ROS3D.InteractiveMarker.prototype.move3d = function(control, origNormal, event3d) {
// by default, move in a plane
if (this.dragging) {

if(control.isShift){
// this doesn't work
// // use the camera position and the marker position to determine the axis
// var newAxis = control.camera.position.clone();
// newAxis.sub(this.position);
// // now mimic same steps constructor uses to create origAxis
// var controlOri = new THREE.Quaternion(newAxis.x, newAxis.y,
// newAxis.z, 1);
// controlOri.normalize();
// var controlAxis = new THREE.Vector3(1, 0, 0);
// controlAxis.applyQuaternion(controlOri);
// origAxis = controlAxis;
}else{
// we want to use the origin plane that is closest to the camera
var cameraVector = control.camera.getWorldDirection();
var x = Math.abs(cameraVector.x);
var y = Math.abs(cameraVector.y);
var z = Math.abs(cameraVector.z);
var controlOri = new THREE.Quaternion(1, 0, 0, 1);
if(y > x && y > z){
// orientation for the control
controlOri = new THREE.Quaternion(0, 0, 1, 1);
}else if(z > x && z > y){
// orientation for the control
controlOri = new THREE.Quaternion(0, 1, 0, 1);
}
controlOri.normalize();

// transform x axis into local frame
origNormal = new THREE.Vector3(1, 0, 0);
origNormal.applyQuaternion(controlOri);
this.movePlane(control, origNormal, event3d);
}
}
};

/**
* Move with respect to the plane based on the contorl and event.
*
Expand Down
16 changes: 16 additions & 0 deletions src/interactivemarkers/InteractiveMarkerControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ ROS3D.InteractiveMarkerControl = function(options) {
this.loader = options.loader;
this.dragging = false;
this.startMousePos = new THREE.Vector2();
this.isShift = false;


// orientation for the control
var controlOri = new THREE.Quaternion(message.orientation.x, message.orientation.y,
Expand All @@ -43,6 +45,9 @@ ROS3D.InteractiveMarkerControl = function(options) {

// determine mouse interaction
switch (message.interaction_mode) {
case ROS3D.INTERACTIVE_MARKER_MOVE_ROTATE_3D:
case ROS3D.INTERACTIVE_MARKER_MOVE_3D:
this.addEventListener('mousemove', this.parent.move3d.bind(this.parent, this, controlAxis));
case ROS3D.INTERACTIVE_MARKER_MOVE_AXIS:
this.addEventListener('mousemove', this.parent.moveAxis.bind(this.parent, this, controlAxis));
this.addEventListener('touchmove', this.parent.moveAxis.bind(this.parent, this, controlAxis));
Expand Down Expand Up @@ -113,6 +118,17 @@ ROS3D.InteractiveMarkerControl = function(options) {
that.dispatchEvent(event3d);
}
});

window.addEventListener('keydown', function(event){
if(event.keyCode === 16){
that.isShift = true;
}
});
window.addEventListener('keyup', function(event){
if(event.keyCode === 16){
that.isShift = false;
}
});
}

// rotation behavior
Expand Down