MStatus MannequinMoveManipulator::connectToDependNode(const MObject &dependNode) { MStatus status; MFnDependencyNode nodeFn(dependNode, &status); if (!status) return MS::kFailure; MPlug translatePlug = nodeFn.findPlug("translate", &status); if (!status) return MS::kFailure; int plugIndex = 0; status = connectPlugToValue(translatePlug, _translateIndex, plugIndex); if (!status) return MS::kFailure; MFnDagNode dagNodeFn(dependNode); MDagPath nodePath; dagNodeFn.getPath(nodePath); MTransformationMatrix m(nodePath.exclusiveMatrix()); _parentXform = m; MTransformationMatrix n(nodePath.inclusiveMatrix()); _childXform = n; finishAddingManips(); return MPxManipulatorNode::connectToDependNode(dependNode); }
MStatus customAttrManip::connectToDependNode(const MObject &node) // // Description // This method activates the manip on the given transform node. // { MStatus stat = MStatus::kSuccess; // Get the DAG path // MFnDagNode dagNodeFn(node); dagNodeFn.getPath(fNodePath); // Connect the plugs to the manip. MFnDependencyNode nodeFn(node); MFnDistanceManip distManipFn(fManip); MPlug cPlug = nodeFn.findPlug(customAttributeString, &stat); if( stat == MStatus::kSuccess ) distManipFn.connectToDistancePlug(cPlug); finishAddingManips(); updateManipLocations(); MPxManipContainer::connectToDependNode(node); return stat; }
//- This function is responsible to make the connection (association) //- between manipulators and the affected attributes. When a node in a scene //- is selected and user click on “show manipulator tool”, //- this function is called with the selected node. //- Arguments: //- dependNode - the node which is selected MStatus arrowLocatorManip::connectToDependNode(const MObject &dependNode) { MStatus status = MStatus::kSuccess; //- Find the "windDirection" plug on the selected node, which is the custom //- locator node. MFnDependencyNode fnDepNode(dependNode); MPlug rotationPlug = fnDepNode.findPlug(MString("windDirection"),&status); //- Connect the "windDirection" plug with the base disc manip MFnDiscManip fnDisc(fDiscManip,&status); status = fnDisc.connectToAnglePlug(rotationPlug); //- Set up affecting relationship using conversion callback function //- We are using addPlugToManipConversionCallback so that whenever //- the custom locator moves, the dis manip moves with it. MFnDagNode fnDagNode(dependNode); fnDagNode.getPath(fNodePath); unsigned int centerPointIndex = fnDisc.centerIndex(&status); addPlugToManipConversionCallback(centerPointIndex,(plugToManipConversionCallback)&arrowLocatorManip::centerPointCallback); //- The following two functions are mandatory inside your //- connectToDependNode() function status = finishAddingManips(); status = MPxManipContainer::connectToDependNode(dependNode); return status; }
//---------------------------------- MStatus moveManip::createChildren() //---------------------------------- { MString pointManipName("pointManip"); MString pointName("freePoint"); fFreePointManip = addFreePointTriadManip(pointManipName, pointName); fDiscManip = addDiscManip("discManip", "angle"); fDiscManip2 = addDiscManip("discManip2", "angle"); fStateManip = addStateManip("stateManipu","stateManip"); fToggleManip = addToggleManip("toggleManipu","toggler"); finishAddingManips(); //Merke: FinishAddingManips funzt hier viiiiel besser -> keine Abstürze mehr return MS::kSuccess; }
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; }
MStatus swissArmyLocatorManip::connectToDependNode(const MObject &node) { MStatus stat; // Get the DAG path // MFnDagNode dagNodeFn(node); dagNodeFn.getPath(fNodePath); MObject parentNode = dagNodeFn.parent(0); MFnDagNode parentNodeFn(parentNode); // Connect the plugs // MFnDependencyNode nodeFn; nodeFn.setObject(node); // FreePointTriadManip // MFnFreePointTriadManip freePointTriadManipFn(fFreePointTriadManip); MPlug translationPlug = parentNodeFn.findPlug("t", &stat); if (MStatus::kFailure != stat) { freePointTriadManipFn.connectToPointPlug(translationPlug); } // DirectionManip // MFnDirectionManip directionManipFn; directionManipFn.setObject(fDirectionManip); MPlug directionPlug = nodeFn.findPlug("arrow2Direction", &stat); if (MStatus::kFailure != stat) { directionManipFn.connectToDirectionPlug(directionPlug); unsigned startPointIndex = directionManipFn.startPointIndex(); addPlugToManipConversionCallback(startPointIndex, (plugToManipConversionCallback) &swissArmyLocatorManip::startPointCallback); } // DistanceManip // MFnDistanceManip distanceManipFn; distanceManipFn.setObject(fDistanceManip); MPlug sizePlug = nodeFn.findPlug("size", &stat); if (MStatus::kFailure != stat) { distanceManipFn.connectToDistancePlug(sizePlug); unsigned startPointIndex = distanceManipFn.startPointIndex(); addPlugToManipConversionCallback(startPointIndex, (plugToManipConversionCallback) &swissArmyLocatorManip::startPointCallback); } // CircleSweepManip // MFnCircleSweepManip circleSweepManipFn(fCircleSweepManip); MPlug arrow1AnglePlug = nodeFn.findPlug("arrow1Angle", &stat); if (MStatus::kFailure != stat) { circleSweepManipFn.connectToAnglePlug(arrow1AnglePlug); unsigned centerIndex = circleSweepManipFn.centerIndex(); addPlugToManipConversionCallback(centerIndex, (plugToManipConversionCallback) &swissArmyLocatorManip::startPointCallback); } // DiscManip // MFnDiscManip discManipFn(fDiscManip); MPlug arrow3AnglePlug = nodeFn.findPlug("arrow3Angle", &stat); if (MStatus::kFailure != stat) { discManipFn.connectToAnglePlug(arrow3AnglePlug); unsigned centerIndex = discManipFn.centerIndex(); addPlugToManipConversionCallback(centerIndex, (plugToManipConversionCallback) &swissArmyLocatorManip::startPointCallback); } // StateManip // MFnStateManip stateManipFn(fStateManip); MPlug statePlug = nodeFn.findPlug("state", &stat); if (MStatus::kFailure != stat) { stateManipFn.connectToStatePlug(statePlug); unsigned positionIndex = stateManipFn.positionIndex(); addPlugToManipConversionCallback(positionIndex, (plugToManipConversionCallback) &swissArmyLocatorManip::startPointCallback); } // ToggleManip // MFnToggleManip toggleManipFn(fToggleManip); MPlug togglePlug = nodeFn.findPlug("toggle", &stat); if (MStatus::kFailure != stat) { toggleManipFn.connectToTogglePlug(togglePlug); unsigned startPointIndex = toggleManipFn.startPointIndex(); addPlugToManipConversionCallback(startPointIndex, (plugToManipConversionCallback) &swissArmyLocatorManip::startPointCallback); } // Determine the transform node for the locator // MDagPath transformPath(fNodePath); transformPath.pop(); MFnTransform transformNode(transformPath); // RotateManip // MFnRotateManip rotateManipFn(fRotateManip); MPlug rotatePlug = transformNode.findPlug("rotate", &stat); if (MStatus::kFailure != stat) { rotateManipFn.connectToRotationPlug(rotatePlug); rotateManipFn.displayWithNode(node); } // ScaleManip // MFnScaleManip scaleManipFn(fScaleManip); MPlug scalePlug = transformNode.findPlug("scale", &stat); if (MStatus::kFailure != stat) { scaleManipFn.connectToScalePlug(scalePlug); scaleManipFn.displayWithNode(node); } finishAddingManips(); MPxManipContainer::connectToDependNode(node); return stat; }