Back to Tools and Commands

Node Move

The nodeMove command handles object movement inside the scene. To activate this command, call:

api.commands.activateCommand('nodeMove')

options

The default options are:

options: {
  displayGizmo: true,
  mode: 'free',

  //default plane is the x-z plane
  plane: {
    normal: { x: 0, y: 1, z: 0 }, //normal direction
    constant: 0, //distance to original
  },
  surfaceNodeIds: [],
  onChange: undefined,
  onEnd: undefined,
  updatePosition: undefined,
  shouldMove: undefined,
},

displayGizmo

Control whether or not to display the widget around the selected node. The widget can be used to move the object along the x, y and z-axis.

mode

There are three different modes: free, plane and surface. Corresponding to move node freely in the scene, move the node along a given plane, and move node on given objects' surface respectively.

plane

An object representing a plane and only used when setting the mode to plane. See Move Node On Plane.

surfaceNodeIds

An array of node ids, used only when setting the mode to surface. See Move Node On Object.

shouldMove

The first custom function will be called at every single frame when an object is moving. The mouse event and new position (world space) of the node will be passed as first two arguments. In surface mode, target mesh surface information will be passed as the third argument. Return true/false to enable/disable the move in the current frame.

Note: The updatePosition and onChange will not the called if shouldMove return false.

updatePosition

The second custom function that will be called at each frame. The first parameter is the new position (world space) the node will be moved to. In surface mode, target mesh surface information will be passed as the second argument. To update the position, simply change the first argument direction.

// fix the node y coordinate while moving
function updatePosition(position) {
  position.y = 0;
}

onChange

A custom function that will be called at each frame after the node moved to the new position. It is a good place to get node new local transform. The mouse event is passed as the first argument. In surface mode, target mesh surface information will be passed as the second argument. See Attach Object.

onEnd

A custom function will be called at the end of the object movement.

var opts = {
  onEnd: function(ev) {
    console.log('move end at', ev.clientX, ev.clientY);
  },
};
setCommandOptions('nodeMove',opts);