MStatus componentScaleManip::connectToDependNode(const MObject &node) { MStatus stat; MFnComponent componentFn(component); if (componentFn.elementCount() > numComponents) { delete [] initialPositions; delete [] initialControlPoint; numComponents = componentFn.elementCount(); initialPositions = new MPoint[numComponents]; initialControlPoint = new MPoint[numComponents]; } // Iterate through the components, storing initial positions and find the // centroid. Add manipToPlug callbacks for each component. // int i = 0; for (MItSurfaceCV iter(surfaceDagPath, component); !iter.isDone(); iter.next(), i++) { if (i >= numComponents) { MGlobal::displayWarning("More components found than expected."); break; } initialPositions[i] = iter.position(MSpace::kWorld); centroid += initialPositions[i]; // // Create a manipToPlug callback that is invoked whenever the manipVal // changes. The callback is added for every selected CV. // MFnDependencyNode nodeFn(node); MPlug controlPointArrayPlug = nodeFn.findPlug("controlPoints", &stat); if (controlPointArrayPlug.isNull()) { MGlobal::displayError("Control point plug not found on node."); return MS::kFailure; } // The logical index from the component iterator is the same as the // logical index into the control points array. // MPlug controlPointPlug = controlPointArrayPlug.elementByLogicalIndex(iter.index(), &stat); if (controlPointPlug.isNull()) { MGlobal::displayError("Control point element not found."); return MS::kFailure; } // Store the initial value of the control point. // initialControlPoint[i] = vectorPlugValue(controlPointPlug); unsigned plugIndex = addManipToPlugConversion(controlPointPlug); // Plug indices should be allocated sequentially, starting at 0. Each // manip container will have its own set of plug indices. This code // relies on the sequential allocation of indices, so trigger an error // if the indices are found to be different. // if (plugIndex != (unsigned)i) { MGlobal::displayError("Unexpected plug index returned."); return MS::kFailure; } } centroid = centroid / numComponents; MFnScaleManip scaleManip(fScaleManip); // Create a plugToManip callback that places the manipulator at the // centroid of the CVs. // addPlugToManipConversion(scaleManip.scaleCenterIndex()); finishAddingManips(); MPxManipContainer::connectToDependNode(node); return stat; }
MStatus exampleRotateManip::connectToDependNode(const MObject &node) { MStatus stat; // Find the rotate and rotatePivot plugs on the node. These plugs will // be attached either directly or indirectly to the manip values on the // rotate manip. // MFnDependencyNode nodeFn(node); MPlug rPlug = nodeFn.findPlug("rotate", &stat); if (!stat) { MGlobal::displayError("Could not find rotate plug on node"); return stat; } MPlug rcPlug = nodeFn.findPlug("rotatePivot", &stat); if (!stat) { MGlobal::displayError("Could not find rotatePivot plug on node"); return stat; } // If the translate pivot exists, it will be used to move the state manip // to a convenient location. // MPlug tPlug = nodeFn.findPlug("translate", &stat); // To avoid having the object jump back to the default rotation when the // manipulator is first used, extract the existing rotation from the node // and set it as the initial rotation on the manipulator. // MEulerRotation existingRotation(vectorPlugValue(rPlug)); MVector existingTranslation(vectorPlugValue(tPlug)); // // The following code configures default settings for the rotate // manipulator. // MFnRotateManip rotateManip(fRotateManip); rotateManip.setInitialRotation(existingRotation); rotateManip.setRotateMode(MFnRotateManip::kObjectSpace); rotateManip.displayWithNode(node); // Add a callback function to be called when the rotation value changes // rotatePlugIndex = addManipToPlugConversionCallback( rPlug, (manipToPlugConversionCallback) &exampleRotateManip::rotationChangedCallback ); // Create a direct (1-1) connection to the rotation center plug // rotateManip.connectToRotationCenterPlug(rcPlug); // Place the state manip at a distance of 2.0 units away from the object // along the X-axis. // MFnStateManip stateManip(fStateManip); stateManip.setTranslation(existingTranslation+MVector(2,0,0), MSpace::kTransform); // add the rotate XYZ plugs to the In-View Editor // MPlug rxPlug = rPlug.child( 0 ); addPlugToInViewEditor( rxPlug ); MPlug ryPlug = rPlug.child( 1 ); addPlugToInViewEditor( ryPlug ); MPlug rzPlug = rPlug.child( 2 ); addPlugToInViewEditor( rzPlug ); finishAddingManips(); MPxManipContainer::connectToDependNode(node); return stat; }