//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
MDagPath CVsSkinnerCmd::GetSpecifiedSkinnerNode()
{
	MSelectionList skinnerNodes;
	MSelectionList optSelectionList;

	m_undo.ArgDatabase().getObjects( optSelectionList );

	GetSpecifiedSkinnerNodes( optSelectionList, skinnerNodes );

	MDagPath mDagPath;

	if ( skinnerNodes.length() == 0U )
		return mDagPath;

	if ( skinnerNodes.length() > 1U )
	{
		skinnerNodes.getDagPath( 0U, mDagPath );

		mwarn << "Using vsSkinnerNode " << mDagPath.partialPathName() << ", ignoring extra vsSkinnerNode";
		if ( skinnerNodes.length() > 2U )
			mwarn << "s";
		mwarn << ":";

		for ( uint i( 1U ); i != skinnerNodes.length(); ++i )
		{
			skinnerNodes.getDagPath( i, mDagPath );
			mwarn << " " << mDagPath.partialPathName();
		}

		mwarn << std::endl;
	}

	skinnerNodes.getDagPath( 0U, mDagPath );
	return mDagPath;
}
AlembicObject::AlembicObject(SceneNodePtr eNode, AlembicWriteJob* in_Job,
                             Abc::OObject oParent)
    : mExoSceneNode(eNode),
      mJob(in_Job),
      mMyParent(oParent),
      mNumSamples(0),
      nodeName(eNode->dccIdentifier.c_str()),
      mHasParent(false)
{
  MSelectionList sl;
  sl.add(nodeName);
  MDagPath dagPath;
  sl.getDagPath(0, dagPath);

  MObject in_Ref = dagPath.node();
  AddRef(in_Ref);

  MFnDagNode dag(in_Ref);
  for (unsigned int i = 0; i < dag.parentCount(); ++i) {
    MObject parentRef = dag.parent(i);
    if (!parentRef.isNull()) {
      mHasParent = in_Job->ObjectExists(parentRef);
      if (mHasParent) {
        break;
      }
    }
  }
}
Beispiel #3
0
SceneInterfacePtr LiveScene::retrieveScene( const Path &path, MissingBehaviour missingBehaviour ) const
{
	tbb::mutex::scoped_lock l( s_mutex );
	
	if( path.size() == 0 )
	{
		MItDag it;
		MDagPath rootPath;
		it.getPath( rootPath );
		return duplicate( rootPath, true );
	}
	
	MString pathName;
	
	for( Path::const_iterator it=path.begin(); it != path.end(); ++it )
	{
		pathName += "|";
		pathName += std::string( *it ).c_str();
	}
	
	MSelectionList sel;
	MStatus st = sel.add( pathName );
	if( !st )
	{
		if( missingBehaviour == SceneInterface::ThrowIfMissing )
		{
			std::string pathName;
			for( size_t i = 0; i < path.size(); ++i )
			{
				pathName += std::string( path[i] ) + "/";
			}
			
			throw Exception( "IECoreMaya::LiveScene::retrieveScene: Couldn't find transform at specified path " + pathName );
		}
		return 0;
	}
	
	MDagPath dagPath;
	sel.getDagPath( 0, dagPath );
	
	if( dagPath.hasFn( MFn::kTransform ) )
	{
		return duplicate( dagPath );
	}
	else
	{
		if( missingBehaviour == SceneInterface::ThrowIfMissing )
		{
			std::string pathName;
			for( size_t i = 0; i < path.size(); ++i )
			{
				pathName += std::string( path[i] ) + "/";
			}
			
			throw Exception( "IECoreMaya::LiveScene::retrieveScene: Couldn't find transform at specified path " + pathName );
		}
		return 0;
	}
	
}
MStatus DDConvexHullCmd::doIt(const MArgList& args)
{
    if (args.length() != 1)
    {
        MGlobal::displayError("Needs at least 2 args");
        return MS::kFailure;
    }
    MString input = args.asString(0);
    MString output = args.asString(1);
    
    // Get the mObject for the input
    MSelectionList selList;
    selList.add(input);
    MDagPath inputMesh;
    selList.getDagPath(0, inputMesh);
    
    // Ensure we're looking at the shape
    inputMesh.extendToShape();

    // Create output object
    MDagModifier dm;
    MObject outMeshNode = dm.createNode(MFn::kMesh);
    MFnDependencyNode outMeshDag(outMeshNode);
    outMeshDag.setName("poopShape#");
    DDConvexHullUtils::hullOpts hullOptions;
    return DDConvexHullUtils::generateMayaHull(outMeshNode,
                                               inputMesh.node(), hullOptions);

}
Beispiel #5
0
IECore::SceneInterfacePtr LiveScene::retrieveChild( const Name &name, MissingBehaviour missingBehaviour ) const
{
	tbb::mutex::scoped_lock l( s_mutex );
	
	if( m_dagPath.length() == 0 && !m_isRoot )
	{
		throw Exception( "IECoreMaya::LiveScene::retrieveChild: Dag path no longer exists!" );
	}
	
	MSelectionList sel;
	sel.add( m_dagPath.fullPathName() + "|" + std::string( name ).c_str() );
	
	MDagPath path;
	sel.getDagPath( 0, path );
	
	if( !path.hasFn( MFn::kTransform ) )
	{
		if( missingBehaviour == SceneInterface::ThrowIfMissing )
		{
			throw Exception( "IECoreMaya::LiveScene::retrieveChild: Couldn't find transform at specified path " + std::string( path.fullPathName().asChar() ) );
		}
		return 0;
	}
	
	return duplicate( path );
}
    // ------------------------------------------------------------
    void SceneGraph::findForcedNodes()
    {
        MStatus status;

        if ( mExportSelectedOnly )
        {
            MSelectionList selectedItems;
            MGlobal::getActiveSelectionList ( selectedItems );
            uint selectedCount = selectedItems.length();
            MDagPathArray queue;

            for ( uint i = 0; i < selectedCount; ++i )
            {
                MDagPath selectedPath;
                status = selectedItems.getDagPath ( i, selectedPath );
                if ( status == MStatus::kSuccess ) queue.append ( selectedPath );
            }

            while ( queue.length() > 0 )
            {
                MDagPath selectedPath = queue[queue.length() - 1];
                queue.remove ( queue.length() - 1 );

                // Queue up the children.
                uint childCount = selectedPath.childCount();
                for ( uint i = 0; i < childCount; ++i )
                {
                    MObject node = selectedPath.child ( i );
                    MDagPath childPath = selectedPath;
                    childPath.push ( node );
                    queue.append ( childPath );
                }

                // Look for a mesh
                if ( selectedPath.node().hasFn ( MFn::kMesh ) )
                {
                    // export forced nodes in path
                    addForcedNodes ( selectedPath );
                }
            }
        }
        else
        {
            for ( MItDag dagIt ( MItDag::kBreadthFirst ); !dagIt.isDone(); dagIt.next() )
            {
                MDagPath currentPath;
                status = dagIt.getPath ( currentPath );
                if ( status == MStatus::kSuccess )
                {
                    MFnDagNode node ( currentPath );
                    String nodeName = node.name().asChar();
                    if ( currentPath.node().hasFn ( MFn::kMesh ) )
                    {
                        // export forced nodes in path
                        addForcedNodes ( currentPath );
                    }
                }
            }
        }
    }
    // --------------------------------------------------------------------
    MStatus SceneGraph::addInstancedDagPaths ( MSelectionList& selectionList )
    {
        MStatus status;
        int length = selectionList.length ( &status );
        if ( status != MStatus::kSuccess ) return MStatus::kFailure;

        for ( int i=0; i<length; i++ )
        {
            MDagPath dagPath;
            if ( selectionList.getDagPath ( i, dagPath ) != MStatus::kSuccess ) return MStatus::kFailure;

            if ( dagPath.isInstanced() )
            {
                int includedInstance=dagPath.instanceNumber ( &status );
                if ( status != MStatus::kSuccess ) return MStatus::kFailure;

                MObject object=dagPath.node ( &status );
                if ( status != MStatus::kSuccess ) return MStatus::kFailure;

                MDagPathArray paths;
                if ( MDagPath::getAllPathsTo ( object, paths ) != MStatus::kSuccess ) return MStatus::kFailure;

                int numPaths=paths.length();
                for ( int p=0; p<numPaths; p++ )
                    if ( p!=includedInstance )
                        selectionList.add ( paths[p] );
            }
        }

        return MStatus::kSuccess;
    }
Beispiel #8
0
MObject getRefFromFullName(const MString & in_Path)
{
   MSelectionList sl;
   sl.add(in_Path);
   MDagPath dag;
   sl.getDagPath(0,dag);
   return dag.node();
}
static MStatus getDagPathByName(const MString & name, MDagPath & dagPath)
{
  MSelectionList sList;
  MStatus status = sList.add(name);
  if (status == MS::kSuccess)
    status = sList.getDagPath(0, dagPath);
  return status;
}
Beispiel #10
0
MStatus GetDagPath(MString& name, MDagPath& path) {
  MStatus status;
  MSelectionList list;
  status = MGlobal::getSelectionListByName(name, list);
  CHECK_MSTATUS_AND_RETURN_IT(status);
  status = list.getDagPath(0, path);
  CHECK_MSTATUS_AND_RETURN_IT(status);
  return MS::kSuccess;
}
Beispiel #11
0
MStatus TransferUV::doIt(const MArgList& args)
{
    MStatus status;

    // if (args.length() != 1)
    // {
    //     MGlobal::displayError("Need 1 arg!");
    //     return MStatus::kFailure;
    // }

    MArgDatabase argData(syntax(), args);

    // arg
    // MString argument = args.asString(0, &status);
    // if (status != MS::kSuccess) {
    //     return MStatus::kFailure;
    // }
    // CHECK_MSTATUS_AND_RETURN_IT(status);

    if (argData.isFlagSet(sourceUvSetFlag)) {
        status = argData.getFlagArgument(sourceUvSetFlag, 0, sourceUvSet);
        CHECK_MSTATUS_AND_RETURN_IT(status);
    }

    if (argData.isFlagSet(targetUvSetFlag)) {
        status = argData.getFlagArgument(targetUvSetFlag, 0, targetUvSet);
        CHECK_MSTATUS_AND_RETURN_IT(status);
    }

    if (argData.isFlagSet(sourceMeshFlag)) {
        status = argData.getFlagArgument(sourceMeshFlag, 0, sourceMesh);
    } else {
        MGlobal::displayError(
            "Source mesh is not specified. -sm flag is required.");
        return MS::kFailure;
    }

    if (argData.isFlagSet(targetMeshFlag)) {
        status = argData.getFlagArgument(targetMeshFlag, 0, targetMesh);
    } else {
        MGlobal::displayError(
            "Target mesh is not specified. -tm flag is required.");
        return MS::kFailure;
    }

    MString info = "Copying uv from " + sourceUvSet + " to " + targetUvSet;
    MGlobal::displayInfo(info);

    MSelectionList mList;
    mList.add(sourceMesh);
    mList.add(targetMesh);

    mList.getDagPath(0, sourceDagPath);
    mList.getDagPath(1, targetDagPath);

    return redoIt();
}
Beispiel #12
0
bool atomImport::replaceNameAndFindPlug(const MString& origName,
										atomNodeNameReplacer& replacer,
										MPlug& replacedPlug)
{
	bool rtn = false;
	
	// get the node name
	//
	MStringArray nameParts;
	origName.split('.', nameParts);

	// Perform any necessary replacement
	//
	MString tmpName(nameParts[0]);
	// TODO: type & hierarchy info -- does the replacer store enough info
	// to help us find that out since in the case of export edits we don't
	// have that info for sources
	//
	if (replacer.findNode(atomNodeNameReplacer::eDag,tmpName,0,0)) {
		MString newName(tmpName);
		newName += (".");

		// add the attribute name(s) back on again
		//
		unsigned int ii;
		MString attrName;
		for (ii = 1; ii < nameParts.length(); ++ii) {
			if (ii > 1) {
				attrName += (".");
			}
			attrName += nameParts[ii];
		}
		newName += attrName;

		MSelectionList tmpList;
		if (MS::kSuccess == tmpList.add(newName)) {
			tmpList.getPlug(0,replacedPlug);
			rtn = !replacedPlug.isNull();
			if (!rtn) {
				// test for the special case of the pivot component
				//
				MDagPath path;
				MObject component;
				if (MS::kSuccess == tmpList.getDagPath(0,path,component) &&
					component.apiType() == MFn::kPivotComponent)
				{
					MObject node;
					tmpList.getDependNode(0,node);
					MFnDependencyNode fnNode(node);
					replacedPlug = fnNode.findPlug(attrName,false);
					rtn = !replacedPlug.isNull();
				}
			}
		}
	}
	return rtn;
}
Beispiel #13
0
void EntityInstanceNode::SelectionChangedCallback( void* clientData )
{
    MAYA_START_EXCEPTION_HANDLING();

    if( !s_ReplaceSelection )
    {
        return;
    }

    static bool inFunc = false;

    if( inFunc )
        return;
    else
        inFunc = true;

    MSelectionList list;
    MGlobal::getActiveSelectionList( list );

    MStatus stat;

    MSelectionList addList;
    bool added = false;
    u32 len = list.length();
    for( u32 i = 0; i < len; )
    {
        MDagPath path;
        list.getDagPath( i, path );

        MObject entityNode = EntityNodeParent( path );
        if( entityNode != MObject::kNullObj )
        {
            added = true;
            MFnDagNode nodeFn( entityNode );
            MDagPath instancePath;
            nodeFn.getPath( instancePath );
            addList.add( instancePath );
            list.remove( i );
        }
        else
        {
            ++i;
        }
    }

    if( added )
    {
        MGlobal::setActiveSelectionList( list, MGlobal::kReplaceList );
        MGlobal::setActiveSelectionList( addList, MGlobal::kAddToList );
    }

    inFunc = false;

    MAYA_FINISH_EXCEPTION_HANDLING();
}
Beispiel #14
0
AbcWriteJob::AbcWriteJob(const char * iFileName,
	std::set<double> & iTransFrames,
	Alembic::AbcCoreAbstract::TimeSamplingPtr iTransTime,
	const JobArgs & iArgs)
{
	MStatus status;
	mFileName = iFileName;
	mBoxIndex = 0;
	mArgs = iArgs;
	mTransSamples = 1;

	if (mArgs.useSelectionList)
	{
		bool emptyDagPaths = mArgs.dagPaths.empty();

		// get the active selection
		MSelectionList activeList;
		MGlobal::getActiveSelectionList(activeList);
		mSList = activeList;
		unsigned int selectionSize = activeList.length();
		for (unsigned int index = 0; index < selectionSize; index ++)
		{
			MDagPath dagPath;
			status = activeList.getDagPath(index, dagPath);
			if (status == MS::kSuccess)
			{
				unsigned int length = dagPath.length();
				while (--length)
				{
					dagPath.pop();
					mSList.add(dagPath, MObject::kNullObj, true);
				}

				if (emptyDagPaths)
				{
					mArgs.dagPaths.insert(dagPath);
				}
			}
		}
	}

	mTransFrames = iTransFrames;

	// only needed during creation of the transforms
	mTransTime = iTransTime;
	mTransTimeIndex = 0;

	// should have at least 1 value
	assert(!mTransFrames.empty());

	mFirstFrame = *(mTransFrames.begin());
	std::set<double>::iterator last = mTransFrames.end();
	last--;
	mLastFrame = *last;
}
MStatus SelectRingToolCmd2::doIt( const MArgList &args )
{
	//MGlobal::displayInfo( "doIt" );
	
	MStatus stat;

	MGlobal::getActiveSelectionList( prevSel );	

	// Initialize to default values
	selEdges = true;
	selFaces = false;
	selVertices = false;
	selEdgeObject = MDagPath();
	selEdgeComp = MObject::kNullObj;
	listAdjust = MGlobal::kReplaceList;
	selType = RING;
		
	// Get the options from the command line
	MArgDatabase argData( syntax(), args, &stat );
	if( !stat )
		return stat;

	if( argData.isFlagSet( edgeFlag ) )
	{
		MString edgeSpec;
		argData.getFlagArgument( edgeFlag, 0, edgeSpec );
		
		MSelectionList sel;
		sel.add( edgeSpec );
		sel.getDagPath( 0, selEdgeObject, selEdgeComp );
		//MFnSingleIndexedComponent si( selEdgeComp );
		//MGlobal::displayInfo( MString("doing stuff on ") + selEdgeObject.fullPathName() + " " + si.element(0) );
	}

	if( argData.isFlagSet( selEdgesFlag ) )
		argData.getFlagArgument( selEdgesFlag, 0, selEdges );
	
	if( argData.isFlagSet( selFacesFlag ) )
		argData.getFlagArgument( selFacesFlag, 0, selFaces );

	if( argData.isFlagSet( selVerticesFlag ) )
		argData.getFlagArgument( selVerticesFlag, 0, selVertices );

	if( argData.isFlagSet( listAdjustFlag ) )
	{
		unsigned value;
		argData.getFlagArgument( listAdjustFlag, 0, value );
		listAdjust = MGlobal::ListAdjustment( value );
	}

	if( argData.isFlagSet( selTypeFlag ) )
		argData.getFlagArgument( selTypeFlag, 0, selType );
	
	return redoIt();
}
Beispiel #16
0
	// extract the component from a MSelectionList
	MObject getCompListFromSList( MSelectionList& sList )
	{
		MDagPath dPath;
		MObject compList;
		sList.getDagPath( 0, dPath, compList );

		MStringArray strArr;
		MGlobal::getFunctionSetList( compList, strArr );
		MGlobal::displayInfo( MString("Array: ") + strArr[0] + strArr[1] );

		return compList;
	}
MStatus testSelectAddAttribute::doIt( const MArgList& args )

{
    MDagPath node;
    MObject component;
    MSelectionList list;
    MFnDagNode nodeFn;
    MGlobal::getActiveSelectionList( list );
    for ( unsigned int index = 0; index < list.length(); index++ )
    {
        list.getDagPath( index, node, component );
        nodeFn.setObject( node );
        cout<<nodeFn.name().asChar( ) << "is selected" << endl;
    }
    return MS::kSuccess;
}
Beispiel #18
0
// Remove any DAG object not in the selectedObjects list.
void ShapeMonitor::stopWatchingUnselectedDagObjects(MSelectionList& selectedObjects)
{
	// For each monitored object...
	for (int i = monitoredObjectsPtrArray.length()-1; i >= 0; i--)
	{
		MonitoredObject *pMonObject = monitoredObjectsPtrArray[i];

		MStatus stat;

		// Get an MObject for the MonitoredObject->mayaNodeName.
		MDagPath dagpath;
		MSelectionList selList;
		selList.add(pMonObject->mayaNodeName);
		stat = selList.getDagPath(0, dagpath);

		// If the MObject is a DAG node...
		if (stat)
		{
			bool found = false;

			// Check if the dag path is included in the selectedObjects list.
			// For example, say that dagpath = "|group1|group2|pSphere|pSphereShape",
			// selectedObjects contains "|group1|group2".
			// We first check if dagpath is included in selectedObjects. If that's not the
			// case, we pop() one component, so that dagpath = "|group1|group2|pSphere", then
			// check again. We do that until either the dagpath is found to be included in
			// the selectedObjects list, or until there's no component left in dagpath.
			while (!found && dagpath.length() > 0)
			{
				// Since we store the shape name (as opposed to the parent transform dagpath),
				// we need to pop() to get the parent transform dagpath.
				dagpath.pop();
				
				MObject component;

				// Check if the dag path is included in the objects list.
				if (selectedObjects.hasItemPartly(dagpath, component))
					found = true;
			}

			// If the object was not in the selectedObjects list, stop watching it.
			if (!found)
				stopWatching(pMonObject->mayaNodeName);
		}
	}
}
void skinClusterWeights::doItQuery()
{
    MStatus status;
    unsigned int i, j;

    MDoubleArray weights;
    // To allow "skinClusterWeights -q" to return empty double array
    setResult(weights);
    MSelectionList selList;
    for (i = 0; i < geometryArray.length(); i++) {
	MDagPath dagPath;
	MObject  component;
	  
	selList.clear();
	selList.add(geometryArray[i]);
	MStatus status = selList.getDagPath(0, dagPath, component);
	if (status != MS::kSuccess) {
	    continue;
	}
	if (component.isNull()) dagPath.extendToShape();
	  
	MObject skinCluster = findSkinCluster(dagPath);
	if (!isSkinClusterIncluded(skinCluster)) {
	    continue;
	}  

	MFnSkinCluster skinClusterFn(skinCluster, &status);
	if (status != MS::kSuccess) {
	    continue; 
	}

	MIntArray influenceIndexArray;
	populateInfluenceIndexArray(skinClusterFn, influenceIndexArray);
	  
	weights.clear();
	skinClusterFn.getWeights(dagPath, component, influenceIndexArray, weights);

	if (weights.length() > 0) {
	    for (j = 0; j < weights.length(); j++) {
		appendToResult(weights[j]);
	    }
	}
    }
}
MStatus liqWriteArchive::redoIt()
{
  try {
    MString objName = objectNames[0]; // TEMP - just handling one object at the moment

    // get a handle on the named object
    MSelectionList selList;
    selList.add(objName);
    MDagPath objDagPath;
    MStatus status = selList.getDagPath(0, objDagPath);
    if (!status) {
      MGlobal::displayError("Error retrieving object " + objName);
      return MS::kFailure;
    }

    // test that the output file is writable
    FILE *f = fopen(outputFilename.asChar(), "w");
    if (!f) {
      MGlobal::displayError("Error writing to output file " + outputFilename + ". Check file permissions there");
      return MS::kFailure;
    }
    fclose(f);

#if defined( PRMAN ) || defined( DELIGHT )
    // binary or ascii
    RtString format[1] = {"ascii"};
    if ( binaryRib ) format[0] = "binary";
    RiOption( "rib", "format", ( RtPointer )&format, RI_NULL);
#endif

    // write the RIB file
    RiBegin(const_cast<char*>(outputFilename.asChar()));

    writeObjectToRib(objDagPath, outputRootTransform);

    RiEnd();

  } catch (...) {
    MGlobal::displayError("Caught exception in liqWriteArchive::redoIt()");
    return MS::kFailure;
  }

  return MS::kSuccess;
}
void peltOverlap::createBoundingCircle(const MStringArray &flattenFaces, MFloatArray &center, MFloatArray &radius)
//
// Description
//     Represent a face by a center and radius, i.e.
//     center = {center1u, center1v, center2u, center2v, ... }
//     radius = {radius1, radius2,  ... }
//
{
    center.setLength(2 * flattenFaces.length());
    radius.setLength(flattenFaces.length());
    for(unsigned int i = 0; i < flattenFaces.length(); i++) {
        MSelectionList selList;
        selList.add(flattenFaces[i]);
        MDagPath dagPath;
        MObject  comp;
        selList.getDagPath(0, dagPath, comp);
        MItMeshPolygon iter(dagPath, comp);

        MFloatArray uArray, vArray;
        iter.getUVs(uArray, vArray);
        // Loop through all vertices to construct edges/rays
        float cu = 0.f;
        float cv = 0.f;
        unsigned int j;
        for(j = 0; j < uArray.length(); j++) {
            cu += uArray[j];
            cv += vArray[j];
        }
        cu = cu / uArray.length();
        cv = cv / vArray.length();
        float rsqr = 0.f;
        for(j = 0; j < uArray.length(); j++) {
            float du = uArray[j] - cu;
            float dv = vArray[j] - cv;
            float dsqr = du*du + dv*dv;
            rsqr = dsqr > rsqr ? dsqr : rsqr;
        }
        center[2*i]   = cu;
        center[2*i+1] = cv;
        radius[i]  = sqrt(rsqr);
    }
}
Beispiel #22
0
void btSPHCmd::getAABB(const MString &name, MPoint& min, MPoint &max)
{
    _LogFunctionCall("btSPHCmd::getAABB("<< name<<")");

    MStatus status = MS::kSuccess;

    MSelectionList sList;
    IfMErrorWarn(MGlobal::getSelectionListByName(name, sList));

    assert(sList.length()==1);
    MDagPath dp;
    IfMErrorWarn(sList.getDagPath(0, dp));
    IfMErrorWarn(dp.extendToShape());//particle shape

    MFnMesh meshFn( dp, &status );
    IfMErrorWarn(status);

    MPointArray positions;
    IfMErrorWarn(meshFn.getPoints(positions, MSpace::kWorld));

    const size_t LEN = positions.length();
    for(size_t i=0; i<LEN; ++i)
    {
        const MPoint &p = positions[i];
        if(p.x<min.x) min.x = p.x;
        if(p.y<min.y) min.y = p.y;
        if(p.z<min.z) min.z = p.z;

        if(p.x>max.x) max.x = p.x;
        if(p.y>max.y) max.y = p.y;
        if(p.z>max.z) max.z = p.z;
    }

// 	MPlug plug;
// 	getPlugValue_asDistance(min.x, meshFn, "boundingBoxMinX");
//  	getPlugValue_asDistance(min.y, meshFn, "boundingBoxMinY");
//  	getPlugValue_asDistance(min.z, meshFn, "boundingBoxMinZ");
//  	getPlugValue_asDistance(max.x, meshFn, "boundingBoxMaxX");
//  	getPlugValue_asDistance(max.y, meshFn, "boundingBoxMaxY");
//  	getPlugValue_asDistance(max.z, meshFn, "boundingBoxMaxZ");

}
//
// Method to add in a light "prune" list. Only selected
// lights will be have their shadows requested, and
// be used for the scene render shader override.
//
MStatus viewRenderOverrideShadows::updateLightList()
{
	mLightList.clear();

	shadowPrepass* shadowOp = (shadowPrepass*)mRenderOperations[kShadowPrePass];
	sceneRender* sceneOp = (sceneRender*)mRenderOperations[kMaya3dSceneRender];
	if (!shadowOp || !sceneOp)
		return MStatus::kFailure;

	// Scan selection list for active lights
	//
	MSelectionList selectList;
	MDagPath dagPath;
	MObject component;
	MGlobal::getActiveSelectionList( selectList );
	for (unsigned int i=0; i<selectList.length(); i++)
	{
		selectList.getDagPath( i, dagPath, component );
		dagPath.extendToShape();
		if ( dagPath.hasFn( MFn::kLight ) )
		{
			mLightList.add( dagPath );
		}
	}
	
	// Set light list to prune which lights to request shadows for
	//
	if (mLightList.length())
		shadowOp->setLightList( &mLightList );
	else
		shadowOp->setLightList( NULL );

	// Set light list to prune which lights to bind for scene shader
	//
	if (mLightList.length())
		sceneOp->setLightList( &mLightList );
	else
		sceneOp->setLightList( NULL );

	return MStatus::kSuccess;
}
void vixo_hairCacheExport::getInCurveInfo(map<int,int>& plugMapVID,MString vixoHairNode,map<int,MVectorArray>& inCurveShape)
{

	MSelectionList slist;
	MGlobal::getSelectionListByName(vixoHairNode,slist);
	MDagPath vixoHairNodeDag;
	slist.getDagPath(0,vixoHairNodeDag);
	vixoHairNodeDag.extendToShape();
	MFnDagNode fnVixoHair(vixoHairNodeDag);
	MPlug plugInCtrlCurveData=fnVixoHair.findPlug("inCtrlCurveData");

	map<int,int>::iterator iterPlugMapVID;
	for(iterPlugMapVID=plugMapVID.begin();iterPlugMapVID!=plugMapVID.end();iterPlugMapVID++)
	{
		MPlug inCurvePlug=plugInCtrlCurveData.elementByLogicalIndex(iterPlugMapVID->first);
		MFnVectorArrayData fnVector(inCurvePlug.asMObject());
		MVectorArray data=fnVector.array();
		MVectorArray tangent(data.length()-1);

		MPlugArray tempArr;
		inCurvePlug.connectedTo(tempArr,true,false);
		MFnDependencyNode fnHairSystem(tempArr[0].node());
		MPlug inputHairs=fnHairSystem.findPlug("inputHair");
		tempArr.clear();
		inputHairs.elementByLogicalIndex(iterPlugMapVID->first).connectedTo(tempArr,true,false);
		MFnDependencyNode fnFolli(tempArr[0].node());
		MFnMatrixData fnMatData(fnFolli.findPlug("worldMatrix[0]").asMObject());
		MMatrix mat=fnMatData.matrix();

		for(int i=0;i<data.length()-1;i++)
		{
			tangent[i]=data[i+1]*mat-data[i]*mat;
		}

		inCurveShape.insert(pair<int,MVectorArray>(iterPlugMapVID->second,tangent));
	}
	
}
bool peltOverlap::createRayGivenFace(const MString &face, MFloatArray &orig, MFloatArray &vec)
//
// Description
//     Represent a face by a series of edges(rays), i.e.
//     orig = {orig1u, orig1v, orig2u, orig2v, ... }
//     vec  = {vec1u,  vec1v,  vec2u,  vec2v,  ... }
//
//     return false if no valid uv's.
{
    MSelectionList selList;
    selList.add(face);
    MDagPath dagPath;
    MObject  comp;
    selList.getDagPath(0, dagPath, comp);
    MItMeshPolygon iter(dagPath, comp);

    MFloatArray uArray, vArray;
    iter.getUVs(uArray, vArray);

    if (uArray.length() == 0 || vArray.length() == 0) return false;

    orig.setLength(2 * uArray.length());
    vec.setLength( 2 * uArray.length());

    // Loop through all vertices to construct edges/rays
    float u = uArray[uArray.length() - 1];
    float v = vArray[vArray.length() - 1];
    for(unsigned int j = 0; j < uArray.length(); j++) {
        orig[2*j]   = uArray[j];
        orig[2*j+1] = vArray[j];
        vec[2*j]    = u - uArray[j];
        vec[2*j+1]  = v - vArray[j];
        u = uArray[j];
        v = vArray[j];
    }
    return true;
}
Beispiel #26
0
bool GDExporter::GetSelectedMeshTransformPath(MDagPath &transformPath)
{
	MSelectionList currSelection;
	MGlobal::getActiveSelectionList(currSelection);

	unsigned int selectionCount = currSelection.length();
	
	MFnMesh* exportingMesh = 0;

	for(unsigned int selectionIndex = 0; selectionIndex < selectionCount; ++selectionIndex )
	{
		MDagPath currPath;
		currSelection.getDagPath(selectionIndex, currPath);

		if( currPath.apiType() != MFn::kTransform )
			continue;

		MFnTransform currTransform(currPath);
		unsigned int childCount = currTransform.childCount();
		for(unsigned int childIndex = 0; childIndex < childCount; ++childIndex)
		{
			MObject childObject = currTransform.child(childIndex);
			if( childObject.apiType() == MFn::kMesh )
			{
				MFnMesh childMesh(childObject);
				if( childMesh.isIntermediateObject() )
					continue;

				currTransform.getPath(transformPath);
				return true;
			}
		}
	}

	return false;
}
Beispiel #27
0
	void IterateSelection()
	{
		unsigned int i;
		MSelectionList list;
		MDagPath dagpath;
		MFnDagNode fnnode;

		MGlobal::getActiveSelectionList(list);

		for(i = 0; i < list.length(); i++)
		{
			list.getDagPath(i, dagpath);
			fnnode.setObject(dagpath);
			cout << fnnode.name().asChar() << " of type " << fnnode.typeName().asChar() << " is selected" << endl;

			cout << "has " << fnnode.childCount() << " children" << endl;

			//Iterate the children
			for(int j = 0; j < fnnode.childCount(); j++)
			{
				MObject childobj;
				MFnDagNode fnchild;

				childobj = fnnode.child(j);
				fnchild.setObject(childobj);

				cout << "child " << j << " is a " << fnchild.typeName().asChar() << endl;

				//MFn::Type type = fnchild.type()
				//if(fnchild.type() == MFn::kMesh)
				//DumpMesh(dagpath);
				//DumpMesh2(dagpath);
				IterateWorldMeshesInSelection();
			}
		}
	}
MStatus clusterWeightFunctionCmd::doIt(const MArgList &argList)
{
	MStatus status;

	MSelectionList list;
	MGlobal::getActiveSelectionList(list);
	
	// Get the cluster
	MFnWeightGeometryFilter cluster;
	MObject dgNode;
	list.getDependNode(0, dgNode);
	if (!cluster.setObject(dgNode))
		return MS::kFailure;

	// Get the object
	MDagPath dagPath;
	MObject component;
	list.getDagPath(1, dagPath, component);

	status = parseArgs(argList);
	if (MS::kSuccess == status)
		status = performWeighting(cluster, dagPath, component);
	return status;
}
Beispiel #29
0
//
//	Check if the selected nodes exist in the scene->MayaObject lists. 
//
void mtth_MayaScene::mobjectListToMayaObjectList(std::vector<MObject>& mObjectList, std::vector<MayaObject *>& mtapObjectList)
{
	std::vector<MObject>::iterator moIter, moIterFound;
	std::vector<MayaObject *>::iterator mIter;
	std::vector<MObject> cleanMObjectList;
	std::vector<MObject> foundMObjectList;

	for( moIter = mObjectList.begin(); moIter != mObjectList.end(); moIter++)
	{
		bool found = false;
		MSelectionList select;
		MString objName = getObjectName(*moIter);
		logger.debug(MString("Object to modify:") + objName);
		select.add(objName);
		MDagPath dp;
		select.getDagPath(0, dp);
		//dp.extendToShape();
		MObject dagObj = dp.node();

		if( (*moIter).hasFn(MFn::kCamera))
		{
			for( mIter = this->camList.begin(); mIter != camList.end(); mIter++)
			{
				MayaObject *mo = *mIter;
				if( dagObj == mo->mobject)
				{
					mtapObjectList.push_back(mo);
					foundMObjectList.push_back(*moIter);
					found = true;
					break;
				}
			}		
			if( found )
				continue;
		}

		for( mIter = this->objectList.begin(); mIter != objectList.end(); mIter++)
		{
			MayaObject *mo = *mIter;
			if( dagObj == mo->mobject)
			{
				mtapObjectList.push_back(mo);
				foundMObjectList.push_back(*moIter);
				found = true;
				break;
			}
		}		
		if( found )
			continue;
		for( mIter = this->lightList.begin(); mIter != lightList.end(); mIter++)
		{
			MayaObject *mo = *mIter;
			if( dagObj == mo->mobject)
			{
				mtapObjectList.push_back(mo);
				foundMObjectList.push_back(*moIter);
				found = true;
				break;
			}
		}		
		if( found )
			continue;
	}

	for( moIter = mObjectList.begin(); moIter != mObjectList.end(); moIter++)
	{
		bool found = false;
		for( moIterFound = foundMObjectList.begin(); moIterFound != foundMObjectList.end(); moIterFound++)
		{
			if( *moIter == *moIterFound)
			{
				found = true;
				continue;
			}
		}
		if(!found)
			cleanMObjectList.push_back(*moIter);
	}

	mObjectList = cleanMObjectList;

}
Beispiel #30
0
MStatus atomExport::exportSelected(	ofstream &animFile, 
									MString &copyFlags,
									std::set<std::string> &attrStrings,
									bool includeChildren, 
									bool useSpecifiedTimes, 
									MTime &startTime,
									MTime &endTime,
									bool statics,
									bool cached,
									bool sdk,
									bool constraint,
									bool layers,
									const MString& exportEditsFile,
									atomTemplateReader &templateReader)
{
	MStatus status = MS::kFailure;

	//	If the selection list is empty, then there are no anim curves
	//	to export.
	//
	MSelectionList sList;
	std::vector<unsigned int> depths;


	SelectionGetter::getSelectedObjects(includeChildren,sList,depths);
	if (sList.isEmpty()) {
		MString msg = MStringResource::getString(kNothingSelected, status);
		MGlobal::displayError(msg);
		return (MS::kFailure);
	}
	//	Copy any anim curves to the API clipboard.
	//
	MString command(copyFlags);
	


	// Always write out header
	if (!fWriter.writeHeader(animFile,useSpecifiedTimes,
							 startTime,endTime)) {
		return (MS::kFailure);
	}


	atomAnimLayers animLayers;
	std::vector<atomNodeWithAnimLayers *> nodesWithAnimLayers;
	if(layers)
	{
		bool hasAnimLayers =  animLayers.getOrderedAnimLayers(); //any layers in the scene?
		hasAnimLayers = setUpAnimLayers(sList,animLayers, nodesWithAnimLayers,attrStrings,templateReader);
		//any layers on our selection?
		if(hasAnimLayers)
		{
			//add the layers to the sList...
			unsigned int oldLength = sList.length();
			animLayers.addLayersToStartOfSelectionList(sList);
			unsigned int diffLength = sList.length() - oldLength;
			atomNodeWithAnimLayers * nullPad = NULL;
			for(unsigned int k =0 ;k < diffLength;++k) //need to pad the beginning of the nodesWithAnimlayers with any layer that was added
			{
				nodesWithAnimLayers.insert(nodesWithAnimLayers.begin(),nullPad);
				depths.insert(depths.begin(),0);
			}
		}
	}
	
	//if caching is on, we pre iterate through the objects, find 
	//each plug that's cached and then cache the data all at once
	std::vector<atomCachedPlugs *> cachedPlugs;
	if(cached)
	{
		bool passed = setUpCache(sList,cachedPlugs,animLayers,sdk, constraint, layers, attrStrings,templateReader,startTime, endTime,
			fWriter.getAngularUnit(), fWriter.getLinearUnit()); //this sets it up and runs the cache;
		if(passed == false) //failed for some reason, one reason is that the user canceled the computation
		{
			//first delete everything though
			//delete any cachedPlugs objects that we created.
			for(unsigned int z = 0; z< cachedPlugs.size(); ++z)
			{
				if(cachedPlugs[z])
					delete cachedPlugs[z];
			}
			//and delete any any layers too
			for(unsigned int zz = 0; zz< nodesWithAnimLayers.size(); ++zz)
			{
				if(nodesWithAnimLayers[zz])
					delete nodesWithAnimLayers[zz];
			}
			MString msg = MStringResource::getString(kCachingCanceled, status);
			MGlobal::displayError(msg);
			return (MS::kFailure);
		}
	}

	unsigned int numObjects = sList.length();

	bool computationFinished = true;
	//not sure if in a headless mode we may want to not show the progress, should
	//still run if that's the case
	bool hasActiveProgress = false;
	if (MProgressWindow::reserve()) {
		hasActiveProgress = true;
		MProgressWindow::setInterruptable(true);
   		MProgressWindow::startProgress();
    	MProgressWindow::setProgressRange(0, numObjects);
		MProgressWindow::setProgress(0);
		MStatus stringStat;
		MString msg = MStringResource::getString(kExportProgress, stringStat);
		if(stringStat == MS::kSuccess)
			MProgressWindow::setTitle(msg);
	}

	if (exportEditsFile.length() > 0) {
		fWriter.writeExportEditsFilePresent(animFile);
	}

	if(layers)
	{
		animLayers.writeAnimLayers(animFile,fWriter);
	}

	bool haveAnyAnimatableStuff = false; //will remain false if no curves or statics
	for (unsigned int i = 0; i < numObjects; i++) 
	{
		if(hasActiveProgress)
			MProgressWindow::setProgress(i);
		MString localCommand;
		bool haveAnimatedCurves = false; //local flag, if true this node has animated curves
		bool haveAnimatableChannels = false; //local flag, if true node has some animatable statics

		MDagPath path;
		MObject node;
		if (sList.getDagPath (i, path) == MS::kSuccess) 
		{
			MString name = path.partialPathName();
			//if the name is in the template, only then write it out...
			if(templateReader.findNode(name)== false)
				continue;

			//we use this to both write out the cached plugs for this node but for also to not write out
			//the plugs which are cached when writing anim curves.
			atomCachedPlugs * cachedPlug = NULL;
			if(cached && i < cachedPlugs.size())
				cachedPlug = cachedPlugs[i];

			atomNodeWithAnimLayers  *layerPlug = NULL;
			if(layers && i < nodesWithAnimLayers.size())
				layerPlug = nodesWithAnimLayers[i];

			unsigned int depth = depths[i];
			unsigned int childCount = path.childCount();
			MObject object = path.node();
			atomNodeNameReplacer::NodeType nodeType = (object.hasFn(MFn::kShape)) ? atomNodeNameReplacer::eShape : atomNodeNameReplacer::eDag;
			fWriter.writeNodeStart(animFile,nodeType,name,depth,childCount);
			
			
			MPlugArray animatablePlugs;
			MSelectionList localList;
			localList.add(object);
			MAnimUtil::findAnimatablePlugs(localList,animatablePlugs);
			
			if(writeAnimCurves(animFile,name,cachedPlug, layerPlug, command, haveAnimatedCurves,templateReader) != MS::kSuccess )
			{
				return (MS::kFailure);
			}
			else if(haveAnimatedCurves)
			{
				haveAnyAnimatableStuff = true;
			}
			if(statics||cached)
			{
				writeStaticAndCached (animatablePlugs,cachedPlug,statics,cached,animFile,attrStrings,name,depth,childCount, haveAnimatableChannels,templateReader);
			}
			fWriter.writeNodeEnd(animFile);

		}
		else if (sList.getDependNode (i, node) == MS::kSuccess) {
			
			if (!node.hasFn (MFn::kDependencyNode)) {
				return (MS::kFailure);
			}
			MPlugArray animatablePlugs;
			MFnDependencyNode fnNode (node, &status);
			MString name = fnNode.name();
			atomNodeNameReplacer::NodeType nodeType = atomNodeNameReplacer::eDepend;
			atomNodeWithAnimLayers  *layerPlug = NULL;
			//if a layer we get our own attrs
			if(i< animLayers.length())
			{
				MPlugArray plugs;
				animLayers.getPlugs(i,animatablePlugs);
				nodeType = atomNodeNameReplacer::eAnimLayer;
			}
			else
			{
				if(templateReader.findNode(name)== false)
				{
					continue;
				}
				MSelectionList localList;
				localList.add(node);
				MAnimUtil::findAnimatablePlugs(localList,animatablePlugs);
				if(layers && i < nodesWithAnimLayers.size())
					layerPlug = nodesWithAnimLayers[i];
			}
			//we use this to both write out the cached plugs for this node but for also to not write out
			//the plugs which are cached when writing anim curves.
			atomCachedPlugs * cachedPlug = NULL;
			if(cached && i < cachedPlugs.size())
				cachedPlug = cachedPlugs[i];

			fWriter.writeNodeStart(animFile,nodeType,name);

			if(writeAnimCurves(animFile,name, cachedPlug,layerPlug,command, haveAnimatedCurves,templateReader) != MS::kSuccess )
			{
				return (MS::kFailure);
			}
			else if(haveAnimatedCurves)
			{
				haveAnyAnimatableStuff = true;
			}


			if(statics||cached)
			{
				writeStaticAndCached (animatablePlugs,cachedPlug,statics,cached,animFile,attrStrings,name,0,0,haveAnimatableChannels,templateReader);
			}
			fWriter.writeNodeEnd(animFile);
		}
		if(haveAnimatableChannels==true)
			haveAnyAnimatableStuff = true;

		if  (hasActiveProgress && MProgressWindow::isCancelled())
		{
			computationFinished = false;
			break;
		}
		
	}
	
	if (exportEditsFile.length() > 0) {
		fWriter.writeExportEditsFile(animFile,exportEditsFile);
	}
	
	//delete any cachedPlugs objects that we created.
	for(unsigned int z = 0; z< cachedPlugs.size(); ++z)
	{
		if(cachedPlugs[z])
			delete cachedPlugs[z];
	}
	//and delete any any layers too
	for(unsigned int zz = 0; zz< nodesWithAnimLayers.size(); ++zz)
	{
		if(nodesWithAnimLayers[zz])
			delete nodesWithAnimLayers[zz];
	}
	if(computationFinished == false) //failed for some reason, one reason is that the user canceled the computation
	{
		MString msg = MStringResource::getString(kSavingCanceled, status);
		MGlobal::displayError(msg);
		return (MS::kFailure);
	}

	if(hasActiveProgress)
		MProgressWindow::endProgress();

	if(haveAnyAnimatableStuff == false)
	{
		MString msg = MStringResource::getString(kAnimCurveNotFound, status);
		MGlobal::displayError(msg);
		return (MS::kFailure);
	}
	else return (MS::kSuccess);
}