// Callback function MManipData rotationChangedCallback(object sender, ManipConversionArgs args) { MObject obj = MObject.kNullObj; // If we entered the callback with an invalid index, print an error and // return. Since we registered the callback only for one plug, all // invocations of the callback should be for that plug. // MFnNumericData numericData = new MFnNumericData(); if (args.ManipIndex != rotatePlugIndex) { MGlobal.displayError("Invalid index in rotation changed callback!"); // For invalid indices, return vector of 0's obj = numericData.create(MFnNumericData.Type.k3Double); numericData.setData(0.0, 0.0, 0.0); return new MManipData(obj); } // Assign function sets to the manipulators // MFnStateManip stateManip = new MFnStateManip(fStateManip); MFnRotateManip rotateManip = new MFnRotateManip(fRotateManip); // Adjust settings on the rotate manip based on the state of the state // manip. // uint mode = stateManip.state; if (mode != 3) { rotateManip.setRotateMode((MFnRotateManip.RotateMode)stateManip.state); rotateManip.setSnapMode(false); } else { // State 3 enables snapping for an object space manip. In this case, // we snap every 15.0 degrees. // rotateManip.setRotateMode(MFnRotateManip.RotateMode.kObjectSpace); rotateManip.setSnapMode(true); rotateManip.snapIncrement = 15.0; } // The following code creates a data object to be returned in the // MManipData. In this case, the plug to be computed must be a 3-component // vector, so create data as MFnNumericData::k3Double // obj = numericData.create(MFnNumericData.Type.k3Double); // Retrieve the value for the rotation from the manipulator and return it // directly without modification. If the manipulator should eg. slow down // rotation, this method would need to do some math with the value before // returning it. // MEulerRotation manipRotation = new MEulerRotation(); try { getConverterManipValue(rotateManip.rotationIndex, manipRotation); numericData.setData(manipRotation.x, manipRotation.y, manipRotation.z); } catch (System.Exception) { MGlobal.displayError("Error retrieving manip value"); numericData.setData(0.0, 0.0, 0.0); } return new MManipData(obj); }
// Callback function MManipData rotationChangedCallback(object sender, ManipConversionArgs args) { MObject obj = MObject.kNullObj; // If we entered the callback with an invalid index, print an error and // return. Since we registered the callback only for one plug, all // invocations of the callback should be for that plug. // MFnNumericData numericData = new MFnNumericData(); if (args.ManipIndex != rotatePlugIndex) { MGlobal.displayError("Invalid index in rotation changed callback!"); // For invalid indices, return vector of 0's obj = numericData.create(MFnNumericData.Type.k3Double); numericData.setData(0.0, 0.0, 0.0); return(new MManipData(obj)); } // Assign function sets to the manipulators // MFnStateManip stateManip = new MFnStateManip(fStateManip); MFnRotateManip rotateManip = new MFnRotateManip(fRotateManip); // Adjust settings on the rotate manip based on the state of the state // manip. // uint mode = stateManip.state; if (mode != 3) { rotateManip.setRotateMode((MFnRotateManip.RotateMode)stateManip.state); rotateManip.setSnapMode(false); } else { // State 3 enables snapping for an object space manip. In this case, // we snap every 15.0 degrees. // rotateManip.setRotateMode(MFnRotateManip.RotateMode.kObjectSpace); rotateManip.setSnapMode(true); rotateManip.snapIncrement = 15.0; } // The following code creates a data object to be returned in the // MManipData. In this case, the plug to be computed must be a 3-component // vector, so create data as MFnNumericData::k3Double // obj = numericData.create(MFnNumericData.Type.k3Double); // Retrieve the value for the rotation from the manipulator and return it // directly without modification. If the manipulator should eg. slow down // rotation, this method would need to do some math with the value before // returning it. // MEulerRotation manipRotation = new MEulerRotation(); try { getConverterManipValue(rotateManip.rotationIndex, manipRotation); numericData.setData(manipRotation.x, manipRotation.y, manipRotation.z); } catch (System.Exception) { MGlobal.displayError("Error retrieving manip value"); numericData.setData(0.0, 0.0, 0.0); } return(new MManipData(obj)); }