本文整理汇总了C++中MFnMesh::allIntersections方法的典型用法代码示例。如果您正苦于以下问题:C++ MFnMesh::allIntersections方法的具体用法?C++ MFnMesh::allIntersections怎么用?C++ MFnMesh::allIntersections使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MFnMesh
的用法示例。
在下文中一共展示了MFnMesh::allIntersections方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: doIt
//.........这里部分代码省略.........
pTempPlug = fnDN.findPlug("translateY", &stat);
if (MStatus::kSuccess == stat)
{
pTempPlug.getValue(fY);
}
pTempPlug = fnDN.findPlug("translateZ", &stat);
if (MStatus::kSuccess == stat)
{
pTempPlug.getValue(fZ);
}
}
else if (tempObjectChild.apiType() == MFn::kMesh)
{
MDagPath pathToMesh;
MERR_CHK(MDagPath::getAPathTo(tempObjectChild, pathToMesh), "Couldn't get a path to the spotlight");
MERR_CHK(fnMesh.setObject(pathToMesh), "Failure on assigning light");
}
else
{
MGlobal::displayError("Need a spotlight and a mesh");
return MStatus::kFailure;
}
}
MFloatPoint fpSource(fX, fY, fZ);
MFloatVector fvRayDir = fnLight.lightDirection(0, MSpace::kWorld, &stat);
MFloatPoint hitPoint;
MMeshIsectAccelParams mmAccelParams = fnMesh.autoUniformGridParams();
float fHitRayParam, fHitBary1, fHitBary2;
int nHitFace, nHitTriangle;
// a large positive number is used here for the maxParam parameter
bool bAnyIntersection = fnMesh.anyIntersection(fpSource, fvRayDir, NULL, NULL, false, MSpace::kWorld, (float)9999, false, &mmAccelParams, hitPoint, &fHitRayParam, &nHitFace, &nHitTriangle, &fHitBary1, &fHitBary2, (float)1e-6, &stat);
if (! bAnyIntersection)
{
MGlobal::displayInfo("There were no intersection points detected");
return stat;
}
MFloatPointArray hitPoints;
MFloatArray faHitRayParams;
MIntArray iaHitFaces;
MIntArray iaHitTriangles;
MFloatArray faHitBary1;
MFloatArray faHitBary2;
bool bAllIntersections = fnMesh.allIntersections(fpSource, fvRayDir, NULL, NULL, false, MSpace::kWorld, 9999, false, NULL, false, hitPoints, &faHitRayParams, &iaHitFaces, &iaHitTriangles, &faHitBary1, &faHitBary2, 0.000001f, &stat);
if (! bAllIntersections)
{
MGlobal::displayInfo("Error getting all intersections");
return stat;
}
// check how many intersections are found
unsigned int nNumberHitPoints = hitPoints.length();
if (! nNumberHitPoints)
{
MGlobal::displayInfo("No hit points detected");
return MStatus::kSuccess;
}
// Intersection exists; display intersections as spheres
MString strCommandString = "string $strBall[] = `polySphere -r 0.5`;";
strCommandString += "$strBallName = $strBall[0];";
float x = 0;
float y = 0;
float z = 0;
for (i = 0; i < (int)nNumberHitPoints; i++)
{
// get the points
x = hitPoints[i][0];
y = hitPoints[i][1];
z = hitPoints[i][2];
// execute some MEL to create a small sphere
strCommandString += "setAttr ($strBallName + \".tx\") ";
strCommandString += x;
strCommandString += ";";
strCommandString += "setAttr ($strBallName + \".ty\") ";
strCommandString += y;
strCommandString += ";";
strCommandString += "setAttr ($strBallName + \".tz\") ";
strCommandString += z;
strCommandString += ";";
MGlobal::executeCommand(strCommandString);
}
return stat;
}
示例2: compute
// ==========================================================================================================
// ==========================================================================================================
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,
//.........这里部分代码省略.........