コード例 #1
0
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
MStatus CVsSkinnerCmd::GetSpecifiedSkinnerNodes(
	const MSelectionList &iList,
	MSelectionList &oList )
{
	MStatus retVal( MS::kFailure );

	oList.clear();

	MDagPath mDagPath;

	MSelectionList tmpList;

	for ( MItSelectionList sIt( iList ); !sIt.isDone(); sIt.next() )
	{
		if ( sIt.itemType() == MItSelectionList::kDagSelectionItem && sIt.getDagPath( mDagPath ) )
		{
			if ( FindSkinnerNodesInHierarchy( mDagPath, tmpList ) )
			{
				oList.merge( tmpList );
				retVal = MS::kSuccess;
			}
		}
	}

	return retVal;
}
コード例 #2
0
ファイル: volume_select.cpp プロジェクト: 3doki/Maya_API_RnD
	// convert input MSelectionList to the MSelectionlist w/ specified component
	// e.g from vtx MSelectionList to edge MSelectionList
	MSelectionList convertVtxSListToCompSList( MSelectionList& selList, int compType )
	{
		// Two step for conversion
		// 01. convert MSelecitionList to MItSelecitionList
		// 02. run MItMeshVertex

		// if switch to vertex, do nothing
		if (compType == 0)
			return selList;

		MObject vtxComp;
		MDagPath dPathMesh;
		MItSelectionList vertexCompIt( selList, MFn::kMeshVertComponent );
		
		// one-time for loop
		for ( ; !vertexCompIt.isDone(); vertexCompIt.next() )
		{
			vertexCompIt.getDagPath( dPathMesh ,vtxComp );
		}

		MItMeshVertex vertexIt( dPathMesh, vtxComp );
		MSelectionList resultSelList;

		// iterate mesh vertec to get tje connected component
		for( ; !vertexIt.isDone(); vertexIt.next() )
		{
			MSelectionList tmpSelList;
			MIntArray compIdArray;

			// if switch to edge, conver vertex to edge
			if( compType == 1 )
			{
				vertexIt.getConnectedEdges(compIdArray);
				tmpSelList = convertMIntArrToMselList( compIdArray, dPathMesh, MFn::kMeshEdgeComponent );
			}

			// if switch to face, conver vertex to face
			if( compType == 2 )
			{
				vertexIt.getConnectedFaces(compIdArray);
				tmpSelList = convertMIntArrToMselList( compIdArray, dPathMesh, MFn::kMeshPolygonComponent );
			}

			// merge new edge indice into current selection list 
			// if new item has exist, not merge it.
			resultSelList.merge(tmpSelList, MSelectionList::kMergeNormal);
		}

		return resultSelList;
	}
コード例 #3
0
ファイル: atomAnimLayers.cpp プロジェクト: BigRoy/Maya-devkit
//this function adds the layer objects in mAnimLayers to the start of the selection list.
//this is used when exporting to make sure the animationlayers come first
void atomAnimLayers::addLayersToStartOfSelectionList(MSelectionList &list)
{
	if(mAnimLayers.length() > 0 )
	{
		MSelectionList layers;
		for(unsigned int i =0; i<mAnimLayers.length();++i)
		{
			layers.add(mAnimLayers[i], true);
		}
		layers.merge(list);
		list = layers;
		
	}

}
コード例 #4
0
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
MStatus CVsSkinnerCmd::GetSpecifiedMeshes(
	const MSelectionList &iList,
	MSelectionList &oList )
{
	MStatus retVal( MS::kFailure );

	oList.clear();

	MDagPath mDagPath;

	for ( MItSelectionList sIt( iList ); !sIt.isDone(); sIt.next() )
	{
		if ( sIt.itemType() == MItSelectionList::kDagSelectionItem && sIt.getDagPath( mDagPath ) )
		{
			if ( mDagPath.hasFn( MFn::kMesh ) )
			{
				mDagPath.extendToShapeDirectlyBelow( 0 );
				oList.add( mDagPath, MObject::kNullObj, true );
				retVal = MS::kSuccess;
			}
		}
	}

	MSelectionList tmpList;

	for ( MItSelectionList sIt( iList ); !sIt.isDone(); sIt.next() )
	{
		if ( sIt.itemType() == MItSelectionList::kDagSelectionItem && sIt.getDagPath( mDagPath ) )
		{
			if ( FindMeshesInHierarchy( mDagPath, tmpList ) )
			{
				oList.merge( tmpList );
				retVal = MS::kSuccess;
			}
		}
	}

	return retVal;
}
コード例 #5
0
ファイル: volume_select.cpp プロジェクト: 3doki/Maya_API_RnD
	// ==========================================================================================================
	// ==========================================================================================================
	virtual MStatus compute(const MPlug& plug, MDataBlock& dataBlock)
	{

		// enable this node or not
		if ( dataBlock.inputValue(aEnable).asBool() == false )
		{
			return MS::kSuccess;
		}

		// check if the inpute attribute is connected
		// in Not, stop compute()
		// in order to avoid crash when disconnect input attributes on the fly 
		
		//cout << "isPlugConnect: " << isPlugConnect(aVolumeObj) << endl;
		
		if ( isPlugConnect(aSourceObj) == false || isPlugConnect(aVolumeObj) == false )
		{
			return MS::kSuccess;
		}

		// execution when output attr needs to be updated
		if ( plug == aOutValue || plug == aOutMesh || plug == aOutCompList )
		{
			// test if input source object is a valid type
			if ( dataBlock.inputValue(aSourceObj).type() != MFnData::kMesh )
			{
				MGlobal::displayInfo( MString("No Object Input!") ); 
				return MS::kSuccess;
			}

			MObject sourceObj = dataBlock.inputValue(aSourceObj).asMeshTransformed();

			MArrayDataHandle arrayHandle = dataBlock.inputValue(aVolumeObj);
			arrayHandle.jumpToArrayElement(0);

			MSelectionList sList;		// add the vertice every ligal loop 
			for ( int idx=0; idx < arrayHandle.elementCount(); idx++, arrayHandle.next() )
			{

				// first, check if the sub-plug is un-connected
				if ( isPlugConnect( aVolumeObj, idx ) == false  )
				{
					cout << "No Data " << idx << endl;
					continue;
				}

				// second, check if the input object is mesh
				if ( arrayHandle.inputValue().type() != MFnData::kMesh )
				{
					return MS::kSuccess;
					MGlobal::displayError( "input voulme objects is not mesh" );
				}

				// input volume object as Wrold mesh
				MObject volumeObj = arrayHandle.inputValue().asMeshTransformed();

				MFnMesh sourceMeshFn;
				MFnMesh volumeMeshFn;

				// third, test if the input obj is compatible with meshFn
				if ( volumeMeshFn.hasObj(sourceObj) && volumeMeshFn.hasObj(volumeObj) )
				{
					volumeMeshFn.setObject(volumeObj);

					// check if object is closed
					if ( isClosedMesh(volumeObj) == false )
					{
						if ( dataBlock.inputValue(aClosedObj).asBool() == true )
						{
							//MGlobal::displayInfo( MString("The volume object is not closed!") );
							continue;
						}
					}

					sourceMeshFn.setObject( sourceObj );
					int numVtx = sourceMeshFn.numVertices();

					vector<int> tmpCompArray;	// an temporary int array to store component index

					// do hit test
					// to check if each source's component is inside
					//
					for ( int i=0; i < numVtx; i++ )
					{
						// get each vertex of source object
						MPoint srcVtx;
						sourceMeshFn.getPoint( i, srcVtx, MSpace::kWorld );

						// Test how much hit is for each vertex 
						// declare parameters for allIntersection()
						MFloatPoint raySource;
						raySource.setCast(srcVtx);

						MFloatVector rayDirection(0, 0, 1);
						MFloatPointArray hitPoints;
						MIntArray hitFaces;

						bool hit = volumeMeshFn.allIntersections( raySource,
																	rayDirection,
																	NULL,
																	NULL,
																	false,
																	MSpace::kWorld,
																	99999,
																	false,
																	NULL,
																	true,
																	hitPoints,
																	NULL,
																	&hitFaces,
																	NULL,
																	NULL,
																	NULL,
																	1e-6 );

						if (hit)
						{
							int isInside = hitFaces.length() % 2;
							// cout << "isInside: " << isInside << endl;

							// if the mod is odd, it's inside
							if ( isInside > 0 )
							{
								tmpCompArray.push_back(i);
							}
						}
					}

					// declare a dynamic array to recieve All elements from tmpCompArray
					int* compArray = new int[tmpCompArray.size()];

					// copy array data from tmpCompArray --> compArray
					memcpy( &compArray[0], &tmpCompArray[0], sizeof( int ) * tmpCompArray.size() );


					// the below processes are to collect component data, and then select them in viewport
					//
					// first, get dagPath from the source object 
					MDagPath dPathSrcObj = getConnectNodeDagPath(aSourceObj);


					// second, get the selection list storing components by feeding comopnet array  
					MSelectionList vtxSelList = getVtxSelList( dPathSrcObj, compArray, tmpCompArray.size() );
					sList.merge(vtxSelList);

					delete [] compArray;
				}
			}
			// end of loop


			// if so, actively select these component
			int compType = dataBlock.inputValue(aComponentType).asInt();
			MSelectionList currCompSelList;

			if( dataBlock.inputValue(aKeepSel).asBool() == true )
			{
				// clear if last-time is not keep selection
				if (flag==0)
				{
					addSelComponentList.clear();
					flag = 1; 
				}
				else
				{
					addSelComponentList.merge(sList);	// merge the accumulative components
					currCompSelList = convertVtxSListToCompSList( addSelComponentList, compType );
					MGlobal::setActiveSelectionList( currCompSelList, MGlobal::kReplaceList );
					flag = 1;
				}
			}
			else
			{
				addSelComponentList.clear();	// celar all components
				addSelComponentList.merge(sList);
				currCompSelList = convertVtxSListToCompSList( addSelComponentList, compType );
				MGlobal::setActiveSelectionList( currCompSelList, MGlobal::kReplaceList );
				flag = 0;
			}

			// keep this node selecting 
			if ( dataBlock.inputValue(aFixPanel).asBool() == true )
				MGlobal::select( thisMObject(), MGlobal::kAddToList );


			// **** OUTPUT ATTRIBUTE ****
			MObject currCompList = getCompListFromSList( currCompSelList );
			
			MFnComponentListData compListDataFn;
			MObject currCompListData = compListDataFn.create();		// pointer to the component data
			compListDataFn.add( currCompList );

			dataBlock.outputValue(aOutCompList).set( currCompListData );
			
			// 
			MFnMeshData outMeshDataFn;
			MObject outObj = outMeshDataFn.create();
			MFnMesh outMeshFn( outObj );
			outMeshFn.copy( sourceObj, outObj );

			dataBlock.outputValue(aOutMesh).set( outObj );
		}		
		// end of if ( plug == aOutValue || plug == aOutMesh )

		return MS::kSuccess;
	}
コード例 #6
0
MStatus listLightLinks::doIt( const MArgList& args )
//
//	Description:
//		Implements the MEL listLightLinks command.  After parsing the 
//		information stored in Maya's light linker nodes, it examines
//		the first item on the selection list.  If the item is an object,
//		then the command selects all lights that are linked to that object.
//		If the item is a light, then it will select all of the objects 
//		that are linked to that light.
//
//	Arguments:
//		args - The argument list that was passes to the command from MEL.
//			   This command takes no arguments.
//
//	Return Value:
//		MS::kSuccess - command succeeded
//		MS::kFailure - command failed (returning this value will cause the 
//                     MEL script that is being run to terminate unless the
//                     error is caught using a "catch" statement.
//
{
	MStatus stat = MS::kSuccess;
	clearResult();

	// Parse the links on the current scene's light linker node(s).
	//
	MLightLinks lightLink;
	bool parseStatus;
	parseStatus = lightLink.parseLinks(MObject::kNullObj);

	if( !parseStatus )
	{
		setResult( "Error parsing light links\n" );
		return MS::kFailure;
	}

	// Get the first object (or component) on the selection list.
	//
	MSelectionList selectList;
    MDagPath dagPath;
    MObject component;
	MGlobal::getActiveSelectionList( selectList );
	selectList.getDagPath( 0, dagPath, component );
	dagPath.extendToShape();

	// Selection list to store entities linked to the selected light or
	// object.
	//
    MSelectionList newSelection;
    newSelection.clear();

	// Stores the command result.
	//
	char resultString[512];

	// If the object is a surface, we'll select all the lights linked to it.
	// If the object is a light, we'll select all the objects linked to it.
	//
	if( dagPath.hasFn( MFn::kLight ) )
	{
		// Select objects linked to this light.
		//
		MSelectionList objects;
		objects.clear();
		lightLink.getLinkedObjects( dagPath, objects );

		newSelection.merge( objects );

		sprintf( resultString, "Selecting objects linked to light %s", 
				 dagPath.fullPathName().asChar() );

	}
	else
	{
		// Select lights linked to this object.
		//
		MDagPathArray lights;
		lights.clear();
		lightLink.getLinkedLights( dagPath, component, lights );

		for( unsigned int j = 0; j < lights.length(); j++ )
		{
			const MDagPath& path = lights[j];
			newSelection.add( path );
		}

		sprintf( resultString, "Selecting lights linked to object %s", 
				 dagPath.fullPathName().asChar() );

	} 

	// Select the linked entities.
	//
	MGlobal::setActiveSelectionList( newSelection );

	setResult( resultString );
	return stat;
}