Skip to content
This repository has been archived by the owner on Oct 20, 2020. It is now read-only.

Commit

Permalink
Merge pull request #949 from cedricpinson/gizmo-local-origin
Browse files Browse the repository at this point in the history
Adds control for gizmo pivot centering
  • Loading branch information
cedricpinson authored Feb 9, 2018
2 parents c2ad0bf + 516221b commit 365f4d0
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion sources/osgUtil/NodeGizmo.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ var NodeGizmo = function(viewer) {
// we insert a matrixTransform that we are going to edit
// - otherwise we look for the nearest MatrixTransform with an editMask on the graph
this._autoInsertMT = false;
this._correctPivotOnAutoInsert = false;

this._viewer = viewer;
this._canvas = viewer.getGraphicContext().canvas;
Expand Down Expand Up @@ -178,6 +179,7 @@ NodeGizmo.PICK_PLANE_Y = 1 << 8;
NodeGizmo.PICK_PLANE_Z = 1 << 9;

NodeGizmo.NO_FULL_CIRCLE = 1 << 10; // don't display the full non pickable circle (visual cue)
NodeGizmo.CORRECT_PIVOT = 1 << 11; // recompute pivot to center of bound node instead of local origin

NodeGizmo.PICK_ARC = NodeGizmo.PICK_ARC_X | NodeGizmo.PICK_ARC_Y | NodeGizmo.PICK_ARC_Z;
NodeGizmo.PICK_ARROW = NodeGizmo.PICK_ARROW_X | NodeGizmo.PICK_ARROW_Y | NodeGizmo.PICK_ARROW_Z;
Expand Down Expand Up @@ -234,10 +236,18 @@ utils.createPrototypeNode(
this._autoInsertMT = bool;
},

setCorrectPivotOnAutoInsert: function(bool) {
this._correctPivotOnAutoInsert = bool;
},

isEditing: function() {
return this._isEditing;
},

getAttachedNode: function() {
return this._attachedNode;
},

init: function() {
this.getOrCreateStateSet().setAttributeAndModes(new Depth(Depth.DISABLE));
this.getOrCreateStateSet().setAttributeAndModes(new CullFace(CullFace.DISABLE));
Expand All @@ -261,7 +271,10 @@ utils.createPrototypeNode(

_insertEditNode: function(parent, node) {
var mtInsert = new MatrixTransform();

mtInsert.editMask = NodeGizmo.PICK_GIZMO;
if (this._correctPivotOnAutoInsert) mtInsert.editMask |= NodeGizmo.CORRECT_PIVOT;

parent.addChild(mtInsert);
parent.removeChild(node);
mtInsert.addChild(node);
Expand Down Expand Up @@ -332,7 +345,9 @@ utils.createPrototypeNode(
this._attachedNode = editNode;

if (userNode && userNode !== editNode) {
vec3.copy(this._pivotOffset, userNode.getBoundingSphere().center());
if (editNode.editMask & NodeGizmo.CORRECT_PIVOT) {
vec3.copy(this._pivotOffset, userNode.getBoundingSphere().center());
}
}

this.updateGizmoMask();
Expand Down

0 comments on commit 365f4d0

Please sign in to comment.