// ------------------------------------------------------------
    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 );
                    }
                }
            }
        }
    }
void liqIPRNodeMessage::onOtherNode(const MString &node, std::vector<MString> &updateObjectName)
{
	MStringArray descendents;
	MString cmd("listRelatives -allDescendents "+node);
	MGlobal::executeCommand(cmd, descendents);

	for(int i=0; i<descendents.length(); ++i)
	{
		addUpdateObject(updateObjectName, descendents[i]);//record descendents[i]
		
		MDagPath dagPath;
		getDagPathByName(dagPath, descendents[i].asChar());

		if( dagPath.node().hasFn(MFn::kTransform) )
		{
			onOtherNode(descendents[i], updateObjectName);//visit descendents[i]
		}
		else if( dagPath.node().hasFn(MFn::kMesh) )
		{
			std::vector<std::string> shaderPlugs;
			liquid::RendererMgr::getInstancePtr()->
				getRenderer()->getValidShaderPlugsInShadingGroup(shaderPlugs);


			IfMErrorWarn(dagPath.extendToShape());//extend to shape

			std::vector<std::string> shadingGroups;
			getShadingGroups(dagPath.fullPathName(), shadingGroups);
			for(std::size_t j=0; j<shadingGroups.size(); ++j)//for each shading group
			{
				MString shadingGroup(shadingGroups[j].c_str());

				for(std::size_t k=0; k<shaderPlugs.size(); ++k)//for each shader plug
				{
					MString shaderPlug(shaderPlugs[k].c_str());

					int isShaderPlugExist;
					cmd = "attributeQuery -node \""+shadingGroup+"\" -ex \""+shaderPlug+"\"";
					IfMErrorMsgWarn(MGlobal::executeCommand( cmd, isShaderPlugExist), cmd);
					if( isShaderPlugExist )
					{
						//get the source shade node of $shadingGroup.$shaderPlug
						MStringArray shaders;
						cmd = "listConnections -s true -d false -plugs false (\""+shadingGroup+"\" + \"."+shaderPlug+"\")";
						IfMErrorMsgWarn(MGlobal::executeCommand( cmd, shaders), cmd);
						
						if( shaders.length() > 0 )//has source shader node
						{
							onShaderNode(shaders[0], updateObjectName);
						}//if( shaders.length() > 0 )//has source shader node

					}//if( isShaderPlugExist )
				}//for each shader plug


			}//for each shading group
		}//kMesh
	}//for(int i=0; i<descendents.length(); ++i)

}
Example #3
0
bool getObjectShadingGroups(const MDagPath& shapeObjectDP, MObject& shadingGroup)
{
    // if obj is a light, simply return the mobject
    if (shapeObjectDP.hasFn(MFn::kLight))
        shadingGroup = shapeObjectDP.node();

    if (shapeObjectDP.hasFn(MFn::kMesh))
    {
        // Find the Shading Engines Connected to the SourceNode
        MFnMesh fnMesh(shapeObjectDP.node());

        // A ShadingGroup will have a MFnSet
        MObjectArray sets, comps;
        fnMesh.getConnectedSetsAndMembers(shapeObjectDP.instanceNumber(), sets, comps, true);

        // Each set is a Shading Group. Loop through them
        for (unsigned int i = 0; i < sets.length(); ++i)
        {
            shadingGroup = sets[i];
            return true;
        }
    }

    if (shapeObjectDP.hasFn(MFn::kNurbsSurface)||shapeObjectDP.hasFn(MFn::kParticle)||shapeObjectDP.hasFn(MFn::kNParticle))
    {

        MObject instObjGroupsAttr;
        if (shapeObjectDP.hasFn(MFn::kNurbsSurface))
        {
            MFnNurbsSurface fnNurbs(shapeObjectDP.node());
            instObjGroupsAttr = fnNurbs.attribute("instObjGroups");
        }
        if (shapeObjectDP.hasFn(MFn::kParticle)||shapeObjectDP.hasFn(MFn::kNParticle))
        {
            MFnParticleSystem fnPart(shapeObjectDP.node());
            instObjGroupsAttr = fnPart.attribute("instObjGroups");
        }
        MPlug instPlug(shapeObjectDP.node(), instObjGroupsAttr);

        // Get the instance that our node is referring to;
        // In other words get the Plug for instObjGroups[intanceNumber];
        MPlug instPlugElem = instPlug.elementByLogicalIndex(shapeObjectDP.instanceNumber());

        // Find the ShadingGroup plugs that we are connected to as Source
        MPlugArray SGPlugArray;
        instPlugElem.connectedTo(SGPlugArray, false, true);

        // Loop through each ShadingGroup Plug
        for (unsigned int i=0; i < SGPlugArray.length(); ++i)
        {
            shadingGroup = SGPlugArray[i].node();
            return true;
        }
    }
    return false;
}
Example #4
0
    // In order to correctly extract skinweights we first
    // need to go into bindpose. (and we need to remember the current
    // pose, to be able to undo it).
    //
    // I know: nearly no error-checking.
    void
    BindPoseTool::GoIntoBindPose()
    {
		MStatus status;
        std::cout << " Going into bindpose ";
        // == turn IK off
        // save current state
        undoInfo.ikSnap = MIkSystem::isGlobalSnap(&status);
        undoInfo.ikSolve = MIkSystem::isGlobalSolve();
        // turn it off
        MIkSystem::setGlobalSnap(false);
        MIkSystem::setGlobalSolve(false);

        // == put joints into bindPose
        for (MItDag dagIt(MItDag::kDepthFirst, MFn::kJoint);
             !dagIt.isDone();
             dagIt.next())
        {
            std::cout << ".";
            MDagPath jointPath;
            dagIt.getPath(jointPath);
            if (jointPath.isInstanced())
            { // we only work on the first instance of an instanced joint.
                if (jointPath.instanceNumber() != 0)
                    continue;
            }

            BindPoseUndoInformation::JointMatrixVector::value_type joint2transform;

            MFnIkJoint joint(jointPath.node());

            MTransformationMatrix currentTransform = joint.transformation(&status);

            joint2transform.first = jointPath.node();
            joint2transform.second = currentTransform;
            undoInfo.savedTransforms.push_back(joint2transform);

            MMatrix bindPoseMatrix = getBindPoseMatrix(joint);
            joint.set(bindPoseMatrix);
        }
        std::cout << std::endl;

        //cout << "bindPose end" << endl;
        // don't know, if this is really necessary, but MS xporttranslator
        // does it...
        syncMeshes();

	// remember the change
	inBindPose = true;
    }
//-----------------------------------------------------------------------------
// This is here for reference. It isn't currently used
//-----------------------------------------------------------------------------
void CVsSkinnerCmd::DoConnectGeometry(
	const MDagPath &skinnerPath,
	const MDagPath &gDagPath )
{
	MObject skinnerObj( skinnerPath.node() );
	const MFnDependencyNode vsSkinnerFn( skinnerObj );
	const MFnMesh meshFn( gDagPath );

	// Connect things up

	MPlug sP;
	MPlug dP;

	MDagModifier &mDagModifier( m_undo.DagModifier() );

	// Connect mesh.worldMatrix[#] vsSkinner.geometryWorldMatrix
	sP = meshFn.findPlug( "worldMatrix" );
	sP = sP.elementByLogicalIndex( gDagPath.instanceNumber() );
	dP = vsSkinnerFn.findPlug( "geometryWorldMatrix" );
	mDagModifier.connect( sP, dP );

	sP = meshFn.findPlug( "outMesh" );
	dP = vsSkinnerFn.findPlug( "inputGeometry" );
	mDagModifier.connect( sP, dP );

	mDagModifier.doIt();

	// Add the default volume
	MSelectionList emptyList;
	MGlobal::setActiveSelectionList( DoNewVolumes( skinnerPath, emptyList ), MGlobal::kReplaceList );
}
Example #6
0
bool IsLayerVisible(MDagPath& dp)
{
   MStatus stat = MStatus::kSuccess;
   MDagPath dagPath = dp;
   while (stat == MStatus::kSuccess)
   {
      MFnDependencyNode node(dagPath.node());
	  MPlug doPlug = node.findPlug("drawOverride", &stat);
	  if( stat )
	  {
		  MObject layer = getOtherSideNode(doPlug);
		  MFnDependencyNode layerNode(layer, &stat);
		  if( stat )
		  {
			  MGlobal::displayInfo(MString("check layer ") + layerNode.name() + " for node " + dagPath.fullPathName());
			  bool visibility = true;
			  if(getBool("visibility", layerNode, visibility))
				  if(!visibility)
					  return false;
		  }
	  }
      stat = dagPath.pop();
   }
   return true;
}
/// Returns STATIC or ANIMATED if an extra translate is needed to compensate for
/// Maya's instancer translation behavior on the given prototype DAG node.
/// (This function may return false positives, which are OK but will simply
/// contribute extra data. It should never return false negatives, which
/// would cause correctness problems.)
bool
PxrUsdTranslators_InstancerWriter::_NeedsExtraInstancerTranslate(
        const MDagPath& prototypeDagPath,
        bool* instancerTranslateAnimated) const
{
    // XXX: Maybe we could be smarter here and figure out if the animation
    // affects instancerTranslate?
    bool animated = !_GetExportArgs().timeSamples.empty() &&
            MAnimUtil::isAnimated(prototypeDagPath.node(), false);
    if (animated) {
        *instancerTranslateAnimated = true;
        return true;
    }

    GfVec3d origin;
    bool translated =
            _GetTransformedOriginInLocalSpace(prototypeDagPath, &origin) &&
            !GfIsClose(origin, GfVec3d(0.0), _EPSILON);
    if (translated) {
        *instancerTranslateAnimated = false;
        return true;
    }

    return false;
}
Example #8
0
bool IsVisible(MDagPath& node)
{
    MFnDagNode dagNode(node.node());
    if (!IsVisible(dagNode) || IsTemplated(dagNode) || IsPathTemplated(node)  || !IsInRenderLayer(node) || !IsPathVisible(node) || !IsLayerVisible(node))
        return false;
    return true;
}
bool AbcWriteJob::checkCurveGrp()
{
    MItDag itDag(MItDag::kBreadthFirst, MFn::kNurbsCurve);
    itDag.reset(mCurDag, MItDag::kBreadthFirst, MFn::kNurbsCurve);

    bool init = false;
    int degree = 0;
    MFnNurbsCurve::Form form = MFnNurbsCurve::kInvalid;
    for (; !itDag.isDone(); itDag.next())
    {
        MDagPath curvePath;
        if (itDag.getPath(curvePath) == MS::kSuccess)
        {
            MObject curve = curvePath.node();
            if (!util::isIntermediate(curve) && curve.hasFn(MFn::kNurbsCurve))
            {
                MFnNurbsCurve fn(curvePath);
                if (!init)
                {
                    degree = fn.degree();
                    form = fn.form();
                    init = true;
                }
                else
                {
                    if (degree != fn.degree() || form != fn.form())
                        return false;
                }
            }
        }
    }
    return true;
}
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);

}
Example #11
0
void ProxyViz::updateViewFrustum(const MDagPath & cameraPath)
{
	MMatrix cameraMat = cameraPath.inclusiveMatrix();
	AHelper::ConvertToMatrix44F(*cameraSpaceR(), cameraMat);
	MMatrix cameraInvMat = cameraPath.inclusiveMatrixInverse();
	AHelper::ConvertToMatrix44F(*cameraInvSpaceR(), cameraInvMat);
	float peye[3];
	peye[0] = cameraMat.matrix[3][0];
	peye[1] = cameraMat.matrix[3][1];
	peye[2] = cameraMat.matrix[3][2];
	setEyePosition(peye);
	
    float farClip = -20.f;
    if(numPlants() > 0) getFarClipDepth(farClip, gridBoundingBox() );
    
	MFnCamera fcam(cameraPath.node() );
	if(fcam.isOrtho() ) {
		float orthoW = fcam.orthoWidth();
		float orthoH = orthoW * fcam.aspectRatio();
		setOrthoFrustum(orthoW, orthoH, -10.f, farClip );
		
	} else {
		float hfa = fcam.horizontalFilmAperture();
		float vfa = fcam.verticalFilmAperture();
		float fl = fcam.focalLength();
	
		setFrustum(hfa, vfa, fl, -10.f, farClip );
	}
	setOverscan(fcam.overscan() );
}
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;
      }
    }
  }
}
Example #13
0
MStatus polyModifierCmd::cacheMeshData()
{
	MStatus status = MS::kSuccess;

	MFnDependencyNode depNodeFn;
	MFnDagNode dagNodeFn;

	MObject meshNode = fDagPath.node();
	MObject dupMeshNode;
	MPlug dupMeshNodeOutMeshPlug;

	// Duplicate the mesh
	//
	dagNodeFn.setObject( meshNode );
	dupMeshNode = dagNodeFn.duplicate();

	MDagPath dupMeshDagPath;
	MDagPath::getAPathTo( dupMeshNode, dupMeshDagPath );
	dupMeshDagPath.extendToShape();

	depNodeFn.setObject( dupMeshDagPath.node() );
	dupMeshNodeOutMeshPlug = depNodeFn.findPlug( "outMesh", &status );
	MCheckStatus( status, "Could not retrieve outMesh" );

	// Retrieve the meshData
	//
	status = dupMeshNodeOutMeshPlug.getValue( fMeshData );
	MCheckStatus( status, "Could not retrieve meshData" );

	// Delete the duplicated node
	//
	MGlobal::deleteNode( dupMeshNode );

	return status;
}
Example #14
0
//
// Write out a 'createNode' command for a DAG node.
//
void maTranslator::writeCreateNode(
		fstream& f, const MDagPath& nodePath, const MDagPath& parentPath
)
{
	MObject		node(nodePath.node());
	MFnDagNode	nodeFn(node);

	//
	// Write out the 'createNode' command for this node.
	//
	f << "createNode " << nodeFn.typeName().asChar();

	//
	// If the node is shared, then add a "-s/shared" flag to the command.
	//
	if (nodeFn.isShared()) f << " -s";

	f << " -n \"" << nodeFn.name().asChar() << "\"";

	//
	// If this is not a top-level node, then include its first parent in the
	// command.
	//
	if (parentPath.length() > 0)
		f << " -p \"" << parentPath.partialPathName().asChar() << "\"";
   
	f << ";" << endl;
}
Example #15
0
bool IsLayerVisible(MDagPath& dp)
{
    MStatus stat = MStatus::kSuccess;
    MDagPath dagPath = dp;
    while (stat == MStatus::kSuccess)
    {
        MFnDependencyNode node(dagPath.node());
        MPlug doPlug = node.findPlug("drawOverride", &stat);
        if (stat)
        {
            MObject layer = getOtherSideNode(doPlug);
            MFnDependencyNode layerNode(layer, &stat);
            if (stat)
            {
                bool visibility = true;
                if (getBool("visibility", layerNode, visibility))
                    if (!visibility)
                        return false;
                if (getEnumInt("displayType", layerNode) == 1) // template
                    return false;
            }
        }
        stat = dagPath.pop();
    }
    return true;
}
Example #16
0
bool usdWriteJob::needToTraverse(const MDagPath& curDag)
{
    MObject ob = curDag.node();
    // NOTE: Already skipping all intermediate objects
    // skip all intermediate nodes (and their children)
    if (PxrUsdMayaUtil::isIntermediate(ob)) {
        return false;
    }

    // skip nodes that aren't renderable (and their children)

    if (mJobCtx.mArgs.excludeInvisible && !PxrUsdMayaUtil::isRenderable(ob)) {
        return false;
    }

    if (!mJobCtx.mArgs.exportDefaultCameras && ob.hasFn(MFn::kTransform)) {
        // Ignore transforms of default cameras 
        MString fullPathName = curDag.fullPathName();
        if (fullPathName == "|persp" ||
            fullPathName == "|top" ||
            fullPathName == "|front" ||
            fullPathName == "|side") {
            return false;
        }
    }

    return true;
}
MayaPointPrimitiveWriter::MayaPointPrimitiveWriter(
    double iFrame, MDagPath & iDag, Alembic::AbcGeom::OObject & iParent,
    Alembic::Util::uint32_t iTimeIndex,
    const JobArgs & iArgs) :
    mIsAnimated(false), mDagPath(iDag)
{
    MFnParticleSystem particle(mDagPath);
    MString name = particle.name();

    name = util::stripNamespaces(name, iArgs.stripNamespace);

    Alembic::AbcGeom::OPoints obj(iParent, name.asChar(),
        iTimeIndex);
    mSchema = obj.getSchema();

    Alembic::Abc::OCompoundProperty cp;
    Alembic::Abc::OCompoundProperty up;
    if (AttributesWriter::hasAnyAttr(particle, iArgs))
    {
        cp = mSchema.getArbGeomParams();
        up = mSchema.getUserProperties();
    }

    mAttrs = AttributesWriterPtr(new AttributesWriter(cp, up, obj, particle,
        iTimeIndex, iArgs));

    MObject object = iDag.node();
    if (iTimeIndex != 0 && util::isAnimated(object))
        mIsAnimated = true;

    write(iFrame);
}
Example #18
0
void SceneShapeUI::selectionRayToWorldSpacePoint( const MDagPath &camera, const MSelectInfo &selectInfo, float depth, MPoint &worldIntersectionPoint ) const
{
	MPoint localRayOrigin;
	MVector localRayDirection;
	selectInfo.getLocalRay( localRayOrigin, localRayDirection );

	MFnCamera fnCamera( camera.node() );
	float near = fnCamera.nearClippingPlane();
	float far = fnCamera.farClippingPlane();
	float z = -1;

	if( fnCamera.isOrtho() )
	{
		z = Imath::lerp( near, far, depth );
	}
	else
	{
		// perspective camera - depth isn't linear so linearise to get z
		float a = far / ( far - near );
		float b = far * near / ( near - far );
		z = b / ( depth - a );
	}	

	MMatrix localToCamera = selectInfo.selectPath().inclusiveMatrix() * camera.inclusiveMatrix().inverse();	
	MPoint cameraRayOrigin = localRayOrigin * localToCamera;
	MVector cameraRayDirection = localRayDirection * localToCamera;

	MPoint cameraIntersectionPoint = cameraRayOrigin + cameraRayDirection * ( -( z - near ) / cameraRayDirection.z );
	worldIntersectionPoint = cameraIntersectionPoint * camera.inclusiveMatrix();
}
Example #19
0
void LiveScene::getChildDags( const MDagPath& dagPath, MDagPathArray& paths ) const
{
	for( unsigned i=0; i < dagPath.childCount(); ++i )
	{
		MDagPath childPath = dagPath;
		childPath.push( dagPath.child( i ) );
		
		if( dagPath.length() == 0 )
		{
			// bizarrely, this iterates through things like the translate manipulator and
			// the view cube too, so lets skip them so they don't show up:
			if( childPath.node().hasFn( MFn::kManipulator3D ) )
			{
				continue;
			}

			// looks like it also gives us the ground plane, so again, lets skip that:
			if( childPath.fullPathName() == "|groundPlane_transform" )
			{
				continue;
			}
		}
		
		paths.append( childPath );
	}
}
Example #20
0
void tm_polySlot::getMeshUVs()
{
	MDagPath dagPath = getMeshNode();
	MObject meshObject = dagPath.node();
	MFnMesh meshFn( meshObject);

	MStringArray uvSetNames;
	MString currentUVSetName;
	MFloatArray *p_uArray = NULL;
	MFloatArray *p_vArray = NULL;
	MIntArray *p_uvCounts = NULL;
	MIntArray *p_uvIds = NULL;
	unsigned uvSetsCount = meshFn.numUVSets();
	if(uvSetsCount > 0)
	{
		meshFn.getUVSetNames( uvSetNames);
		p_uArray = new MFloatArray[uvSetsCount];
		p_vArray = new MFloatArray[uvSetsCount];
		p_uvCounts = new MIntArray[uvSetsCount];
		p_uvIds = new MIntArray[uvSetsCount];
		meshFn.getCurrentUVSetName( currentUVSetName);
		for( unsigned i = 0; i < uvSetsCount; i++)
		{
			meshFn.getUVs( p_uArray[i], p_vArray[i], &uvSetNames[i]);
			meshFn.getAssignedUVs( p_uvCounts[i], p_uvIds[i], &uvSetNames[i]); 
		}
	}
#ifdef _DEBUG
MString msg;
msg = "Old uvSetsCount = " + uvSetsCount;
msg += "UvSetNames = ";
for(unsigned i=0;i<uvSetNames.length();i++) msg += uvSetNames[i] + ", ";
MGlobal::displayInfo( msg);
#endif
}
Example #21
0
MObjectArray getOutConnectedSG( const MDagPath &shapeDPath )
{
    MStatus status;

    // Array of connected Shaging Engines
    MObjectArray connSG;

    // Iterator through the dependency graph to find if there are
    // shading engines connected
    MObject obj(shapeDPath.node()); // non const MObject
    MItDependencyGraph itDG( obj, MFn::kShadingEngine,
                             MItDependencyGraph::kDownstream,
                             MItDependencyGraph::kBreadthFirst,
                             MItDependencyGraph::kNodeLevel, &status );

    if( status == MS::kFailure )
        return connSG;

    // we want to prune the iteration if the node is not a shading engine
    itDG.enablePruningOnFilter();

    // iterate through the output connected shading engines
    for( ; itDG.isDone()!= true; itDG.next() )
        connSG.append( itDG.thisNode() );

    return connSG;
}
    // --------------------------------------------------------------------
    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;
    }
Example #23
0
bool
MayaPrimWriter::writePrimAttrs(const MDagPath &dagT, const UsdTimeCode &usdTime, UsdGeomImageable &primSchema) 
{
    MStatus status;
    MFnDependencyNode depFn(getDagPath().node());
    MFnDependencyNode depFn2(dagT.node()); // optionally also scan a shape's transform if merging transforms

    if (getArgs().exportVisibility) {
        bool isVisible  = true;   // if BOTH shape or xform is animated, then visible
        bool isAnimated = false;  // if either shape or xform is animated, then animated

        PxrUsdMayaUtil::getPlugValue(depFn, "visibility", &isVisible, &isAnimated);

        if ( dagT.isValid() ) {
            bool isVis, isAnim;
            if (PxrUsdMayaUtil::getPlugValue(depFn2, "visibility", &isVis, &isAnim)){
                isVisible = isVisible and isVis;
                isAnimated = isAnimated or isAnim;
            }
        }

        TfToken const &visibilityTok = (isVisible ? UsdGeomTokens->inherited : 
                                        UsdGeomTokens->invisible);
        if (usdTime.IsDefault() != isAnimated ) {
            if (usdTime.IsDefault())
                primSchema.CreateVisibilityAttr(VtValue(visibilityTok), true);
            else
                primSchema.CreateVisibilityAttr().Set(visibilityTok, usdTime);
        }
    }

    UsdPrim usdPrim = primSchema.GetPrim();

    // There is no Gprim abstraction in this module, so process the few
    // gprim attrs here.
    UsdGeomGprim gprim = UsdGeomGprim(usdPrim);
    if (gprim and usdTime.IsDefault()){

        PxrUsdMayaPrimWriterContext* unused = NULL;
        PxrUsdMayaTranslatorGprim::Write(
                getDagPath().node(),
                gprim,
                unused);

    }

    _writeUsdInfo(dagT, usdTime, usdPrim);
    
    // Write user-tagged export attributes. Write attributes on the transform
    // first, and then attributes on the shape node. This means that attribute
    // name collisions will always be handled by taking the shape node's value
    // if we're merging transforms and shapes.
    if (dagT.isValid() and !(dagT == getDagPath())) {
        PxrUsdMayaWriteUtil::WriteUserExportedAttributes(dagT, usdPrim, usdTime);
    }
    PxrUsdMayaWriteUtil::WriteUserExportedAttributes(getDagPath(), usdPrim, usdTime);

    return true;
}
Example #24
0
MObject getRefFromFullName(const MString & in_Path)
{
   MSelectionList sl;
   sl.add(in_Path);
   MDagPath dag;
   sl.getDagPath(0,dag);
   return dag.node();
}
Example #25
0
cgfxStructureCache::Entry::Entry(
    const MDagPath& shape, const MString& name, int stride, int count
)
  : fShape(shape.node()),
    fName(name),
    fData(new char[ stride * count])
{
}
    // ------------------------------------------------------------
    void SceneGraph::appendForcedNodeToList ( const MDagPath& dagPath )
    {
        // Attach a function set
        MFnDependencyNode fn ( dagPath.node() );
        String theNodeName = fn.name().asChar();

        MDagPath dagPathCopy = dagPath;
        while ( dagPathCopy.length() > 0 && !isForcedNode ( dagPathCopy ) )
        {
            // Attach a function set
            MFnDependencyNode fn ( dagPathCopy.node() );
            String theNodeName = fn.name().asChar();

            mForcedNodes.append ( dagPathCopy );
            dagPathCopy.pop();
        }
    }
Example #27
0
MStatus HelloWorld::doIt(const MArgList& argList) {
	MGlobal::displayInfo("Hello World!");
	//Get list of selected items
	MSelectionList selectedItem;
	//Get list of selected items for realsies
	MGlobal::getActiveSelectionList(selectedItem);
	MStatus stat;
	//Iterate through them.
	MItSelectionList it(selectedItem);

	while (!it.isDone() ) {
		MDagPath dagPath;	//Will hold a path to the indexed object
		MObject component;	//List of selected components

		it.getDagPath(dagPath, component);

		MFnDependencyNode fn(dagPath.node());
		MString status = "OBJECT: ";
		status += fn.name().asChar();
		MGlobal::displayInfo(status);

		if (!component.isNull()) {
			MGlobal::displayInfo("Is not null!");
			MItMeshVertex itVert(dagPath, component, &stat);

			if (stat == MS::kSuccess)
			{
				while (!itVert.isDone())
				{
					
					MPoint point = itVert.position(MSpace::kWorld);
					MString pointStr;
					pointStr += itVert.index();
					pointStr += "\t";
					pointStr += point.x;
					point.x += 10;
					pointStr += "\t";
					pointStr += point.y;
					pointStr += "\t";
					pointStr += point.z;
					MGlobal::displayInfo(pointStr);
					itVert.setPosition(point, MSpace::kWorld);

					itVert.next();
				}
			}
		}
		else{
			MGlobal::displayInfo("Is null.. :(");
		}
		it.next();

	}



	return MS::kSuccess;
}
Example #28
0
MStatus updateTCCData::getTCCNode( MSelectionList &selList )
{
    MStatus status; 
    MItSelectionList selListIter( selList );
    selListIter.setFilter( MFn::kMesh );
    
    for( ; !selListIter.isDone(); selListIter.next() )
    {
        MDagPath dagPath;
        MObject component;
        selListIter.getDagPath( dagPath, component );
        status = dagPath.extendToShape();
    
        if (status == MS::kSuccess)
        {
            MFnDependencyNode meshShapeFn(dagPath.node());
            
            MObject outMeshAttr = meshShapeFn.attribute( "outMesh" );
            MPlug outMeshPlug(dagPath.node(), outMeshAttr );
//            worldMeshPlug = worldMeshPlug.elementByLogicalIndex( 0 );
            cout<<"inMesh-connected dagnode name: "<<endl<<" > "<<outMeshPlug.info().asChar()<<endl;
            
            MPlugArray plugArray;
            outMeshPlug.connectedTo(plugArray, true, true);
            cout<<"connected attrs: "<<plugArray.length()<<endl;
            
            for (size_t k=0; k<plugArray.length(); k++)
            {
                MObject TCCnode(plugArray[k].node());
                MFnDependencyNode TCCDepNode( TCCnode );
                
                cout<<"Dependency node type: "<<TCCDepNode.typeName().asChar()<<endl;
                if (TCCDepNode.typeName() == "TCC")
                {
                    fSrcDagPath = dagPath;
                    fTCCnode = TCCnode;
                    fComponent = component;
                    return MS::kSuccess;
                }
            }
        }
    }    
    
    return MS::kFailure;
}
Example #29
0
osg::ref_ptr<osg::Node> Group::exporta(MDagPath &dp)
{
	osg::ref_ptr<osg::Group> osggroup;

	// Get the node of this path
	MObject node = dp.node();

	// 1. Create the adequate type of node
	if( node.hasFn(MFn::kEmitter) ) {
		// Emitters are subclasses of Transform
		// We build the transform and then add the emitter as a child
		osggroup = Transform::exporta(node);
		osggroup->addChild( PointEmitter::exporta(node).get() );
	}
	else if( node.hasFn(MFn::kTransform) ){
		osggroup = Transform::exporta(node);
	}
	else {
		// Generic group (kWorld)
		osggroup = new osg::Group();
	}

	// 2. Process and add children
	for(int i=0; i<dp.childCount(); i++){
		// Add child to the path and recursively call the exportation function
		MDagPath dpc(dp);
		dpc.push(dp.child(i));
		osg::ref_ptr<osg::Node> child = DAGNode::exporta(dpc);
		if(child.valid()){
			// ** Check ** If any children is a LightSource, deactivate culling 
			// for this group in order to apply the light even though it is not
			// directly visible
			if( dynamic_cast<osg::LightSource *>(child.get()) != NULL )
				osggroup->setCullingActive(false);
			osggroup->addChild(child.get());
		}
	}

	// 3. If there are no children, the node is ignored
	if( osggroup->getNumChildren() == 0 ){
		// Buuuuuuut, if there is an animation, it is saved to disk
		// because it can be a useful camera animation
		osg::AnimationPathCallback *cb = dynamic_cast< osg::AnimationPathCallback * >(osggroup->getUpdateCallback());
		if(cb){
			MFnDependencyNode dn(node);
			std::cout << "EXPORTING CAMERA ANIMATION: " << dn.name().asChar() << std::endl;
            CameraAnimation::save(cb->getAnimationPath(), Config::instance()->getSceneFilePath().getDirectory() + "/" + Config::instance()->getSceneFilePath().getFileBaseName() + "_" + std::string(dn.name().asChar()) + ".path" );
		}
		return NULL;
	}

    // Name the node (mesh)
	MFnDependencyNode dnodefn(node);
	osggroup->setName( dnodefn.name().asChar() );

	return (osg::Node *)osggroup.get();
}
IECore::PrimitivePtr FromMayaCurveConverter::doPrimitiveConversion( const MDagPath &dagPath, IECore::ConstCompoundObjectPtr operands ) const
{
	MFnNurbsCurve fnCurve( dagPath );
	if( !fnCurve.hasObj( dagPath.node() ) )
	{
		throw IECore::InvalidArgumentException( "FromMayaCurveConverter::doPrimitiveConversion : not a nurbs curve." );
	}
	return doPrimitiveConversion( fnCurve );
}