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);
}
Exemple #2
0
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;
}
DagNodeExporter* NodeExporterFactory::createDagNodeExporter(
    const MDagPath&                 path,
    asr::Project&                   project,
    AppleseedSession::SessionMode   sessionMode)
{
    MFnDagNode dagNodeFn(path);
    CreateDagExporterMapType::const_iterator it = gDagNodeExporters.find(dagNodeFn.typeName());

    if(it == gDagNodeExporters.end())
    {
        //throw NoExporterForNode();
        return 0;
    }

    return it->second(path, project, sessionMode);
}
Exemple #4
0
//
// Write out a "select" command.
//
void maTranslator::writeSelectNode(fstream& f, const MObject& node)
{
	MStatus				status;
	MFnDependencyNode	nodeFn(node);
	MString				nodeName;

	//
	// If the node has a unique name, then we can just go ahead and use
	// that.  Otherwise we will have to use part of its DAG path to to
	// distinguish it from the others with the same name.
	//
	if (nodeFn.hasUniqueName())
		nodeName = nodeFn.name();
	else
	{
		//
		// Only DAG nodes are allowed to have duplicate names.
		//
		MFnDagNode	dagNodeFn(node, &status);

		if (!status)
		{
			MGlobal::displayWarning(
				MString("Node '") + nodeFn.name()
				+ "' has a non-unique name but claimes to not be a DAG node.\n"
				+ "Using non-unique name."
			);

			nodeName = nodeFn.name();
		}
		else
			nodeName = dagNodeFn.partialPathName();
	}

	//
	// We use the "-ne/noExpand" flag so that if the node is a set, we
	// actually select the set itself, rather than its members.
	//
	f << "select -ne ";

	//
	// Default nodes get a colon slapped onto the start of their names.
	//
	if (nodeFn.isDefaultNode()) f << ":";

	f << nodeName.asChar() << ";\n";
}
//-------------------------------------------------
MDagPath	moveManip::findMeshPath(const MObject& node) const
//-------------------------------------------------
{
	MFnDependencyNode depNodeFn(node);

	MPlugArray	plugArray;
	
	depNodeFn.findPlug("outMesh").connectedTo(plugArray,false, true);

	MFnDagNode dagNodeFn(plugArray[0].node());

	MDagPath path;

	dagNodeFn.getPath(path);

	return path;
}
MStatus vixo_visImport::connectionMade(const MPlug& plug,const MPlug& otherPlug,bool asSrc)
{
	if(plug.array()==this->vis)
	{
		//cout<<plug.info().asChar()<<" "<<plug.array().name().asChar()<<" "<<plug.logicalIndex()<<endl;
		MPlugArray arr;
		plug.connectedTo(arr,false,true);
		MFnDagNode dagNodeFn(arr[0].node());
		if(dagNodeFn.parentCount()<=0)
			return MS::kSuccess;
		//MFnDagNode transformFn(dagNodeFn.parent(0));
		MStringArray tempArray;
		dagNodeFn.name().split(':',tempArray);
		if(tempArray.length()<2)
			return MS::kSuccess;
		//cout<<tempArray[tempArray.length()-1].asChar()<<endl;
		mapObjName.insert(pair<int,string>(plug.logicalIndex(),tempArray[tempArray.length()-1].asChar()));
		return MS::kSuccess;
	}
	return MPxNode::connectionMade( plug, otherPlug, asSrc );

}
Exemple #7
0
void maTranslator::writeDagNodes(fstream& f)
{
	fParentingRequired.clear();

	MItDag		dagIter;

	dagIter.traverseUnderWorld(true);

	MDagPath	worldPath;

	dagIter.getPath(worldPath);

	//
	// We step over the world node before starting the loop, because it
	// doesn't get written out.
	//
	for (dagIter.next(); !dagIter.isDone(); dagIter.next())
	{
		MDagPath	path;
		dagIter.getPath(path);

		//
		// If the node has already been written, then all of its descendants
		// must have been written, or at least checked, as well, so prune
		// this branch of the tree from the iteration.
		//
		MFnDagNode	dagNodeFn(path);

		if (dagNodeFn.isFlagSet(fCreateFlag))
		{
			dagIter.prune();
			continue;
		}

		//
		// If this is a default node, it will be written out later, so skip
		// it.
		//
		if (dagNodeFn.isDefaultNode()) continue;

		//
		// If this node is not writable, and is not a shared node, then mark
		// it as having been written, and skip it.
		//
		if (!dagNodeFn.canBeWritten() && !dagNodeFn.isShared())
		{
			dagNodeFn.setFlag(fCreateFlag, true);
			continue;
		}

		unsigned int	numParents = dagNodeFn.parentCount();

		if (dagNodeFn.isFromReferencedFile())
		{
			//
			// We don't issue 'creatNode' commands for nodes from referenced
			// files, but if the node has any parents which are not from
			// referenced files, other than the world, then make a note that
			// we'll need to issue extra 'parent' commands for it later on.
			//
			unsigned int i;

			for (i = 0; i < numParents; i++)
			{
				MObject		altParent = dagNodeFn.parent(i);
				MFnDagNode	altParentFn(altParent);

				if (!altParentFn.isFromReferencedFile()
				&&	(altParentFn.object() != worldPath.node()))
				{
					fParentingRequired.append(path);
					break;
				}
			}
		}
		else
		{
			//
			// Find the node's parent.
			//
			MDagPath	parentPath = worldPath;

			if (path.length() > 1)
			{
				//
				// Get the parent's path.
				//
				parentPath = path;
				parentPath.pop();

				//
				// If the parent is in the underworld, then find the closest
				// ancestor which is not.
				//
				if (parentPath.pathCount() > 1)
				{
					//
					// The first segment of the path contains whatever
					// portion of the path exists in the world.  So the closest
					// worldly ancestor is simply the one at the end of that
					// first path segment.
					//
					path.getPath(parentPath, 0);
				}
			}

			MFnDagNode	parentNodeFn(parentPath);

			if (parentNodeFn.isFromReferencedFile())
			{
				//
				// We prefer to parent to a non-referenced node.  So if this
				// node has any other parents, which are not from referenced
				// files and have not already been processed, then we'll
				// skip this instance and wait for an instance through one
				// of those parents.
				//
				unsigned i;

				for (i = 0; i < numParents; i++)
				{
					if (dagNodeFn.parent(i) != parentNodeFn.object())
					{
						MObject		altParent = dagNodeFn.parent(i);
						MFnDagNode	altParentFn(altParent);

						if (!altParentFn.isFromReferencedFile()
						&&	!altParentFn.isFlagSet(fCreateFlag))
						{
							break;
						}
					}
				}

				if (i < numParents) continue;

				//
				// This node only has parents within referenced files, so
				// create it without a parent and note that we need to issue
				// 'parent' commands for it later on.
				//
				writeCreateNode(f, path, worldPath);

				fParentingRequired.append(path);
			}
			else
			{
				writeCreateNode(f, path, parentPath);

				//
				// Let's see if this node has any parents from referenced
				// files, or any parents other than this one which are not
				// from referenced files.
				//
				unsigned	int i;
				bool		hasRefParents = false;
				bool		hasOtherNonRefParents = false;

				for (i = 0; i < numParents; i++)
				{
					if (dagNodeFn.parent(i) != parentNodeFn.object())
					{
						MObject		altParent = dagNodeFn.parent(i);
						MFnDagNode	altParentFn(altParent);

						if (altParentFn.isFromReferencedFile())
							hasRefParents = true;
						else
							hasOtherNonRefParents = true;

						//
						// If we've already got positives for both tests,
						// then there's no need in continuing.
						//
						if (hasRefParents && hasOtherNonRefParents) break;
					}
				}

				//
				// If this node has parents from referenced files, then
				// make note that we will have to issue 'parent' commands
				// later on.
				//
				if (hasRefParents) fParentingRequired.append(path);

				//
				// If this node has parents other than this one which are
				// not from referenced files, then make note that the
				// parenting for the other instances still has to be done.
				//
				if (hasOtherNonRefParents)
				{
					fInstanceChildren.append(path);
					fInstanceParents.append(parentPath);
				}
			}

			//
			// Write out the node's 'addAttr', 'setAttr' and 'lockNode'
			// commands.
			//
			writeNodeAttrs(f, path.node(), true);
			writeLockNode(f, path.node());
		}

		//
		// Mark the node as having been written.
		//
		dagNodeFn.setFlag(fCreateFlag, true);
	}

	//
	// Write out the parenting for instances.
	//
	writeInstances(f);
}
Exemple #8
0
//
// Write out all of the connections in the scene.
//
void maTranslator::writeConnections(fstream& f)
{
	//
	// If the scene has broken any connections which were made in referenced
	// files, handle those first so that the attributes are free for any new
	// connections which may come along.
	//
	writeBrokenRefConnections(f);

	//
	// We're about to write out the scene's connections in three parts: DAG
	// nodes, non-DAG non-default nodes, then default nodes.
	//
	// It's really not necessary that we group them like this and would in
	// fact be more efficient to do them all in one MItDependencyNodes
	// traversal.  However, this is the order in which the normal MayaAscii
	// translator does them, so this makes it easier to compare the output
	// of this translator to Maya's output.
	//

	//
	// Write out connections for the DAG nodes first.
	//
	MItDag	dagIter;
	dagIter.traverseUnderWorld(true);

	for (dagIter.next(); !dagIter.isDone(); dagIter.next())
	{
		MObject		node = dagIter.item();
		MFnDagNode	dagNodeFn(node);

		if (!dagNodeFn.isFlagSet(fConnectionFlag)
		&&	dagNodeFn.canBeWritten()
		&&	!dagNodeFn.isDefaultNode())
		{
			writeNodeConnections(f, dagIter.item());
			dagNodeFn.setFlag(fConnectionFlag, true);
		}
	}

	//
	// Now do the non-DAG, non-default nodes.
	//
	MItDependencyNodes	nodeIter;

	for (; !nodeIter.isDone(); nodeIter.next())
	{
		MFnDependencyNode	nodeFn(nodeIter.item());

		if (!nodeFn.isFlagSet(fConnectionFlag)
		&&	nodeFn.canBeWritten()
		&&	!nodeFn.isDefaultNode())
		{
			writeNodeConnections(f, nodeIter.item());
			nodeFn.setFlag(fConnectionFlag, true);
		}
	}

	//
	// And finish up with the default nodes.
	//
	unsigned int	numNodes = fDefaultNodes.length();
	unsigned int	i;

	for (i = 0; i < numNodes; i++)
	{
		MFnDependencyNode	nodeFn(fDefaultNodes[i]);

		if (!nodeFn.isFlagSet(fConnectionFlag)
		&&	nodeFn.canBeWritten()
		&&	nodeFn.isDefaultNode())
		{
			writeNodeConnections(f, fDefaultNodes[i]);
			nodeFn.setFlag(fConnectionFlag, true);
		}
	}
}
Exemple #9
0
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;
}