#include <maya/MFnPlugin.h>
#include <maya/MDagPath.h>
#include <maya/MFnMesh.h>
#include <maya/MItSelectionList.h>
#include <maya/MItMeshPolygon.h>
#include <maya/MObject.h>
#include <maya/MSelectionList.h>
#include <maya/MArgList.h>
#include <maya/MFloatPoint.h>
#include <maya/MFnDependencyNode.h>
#include <maya/MFnSpotLight.h>
#include <maya/MFloatPointArray.h>
#include <maya/MPxCommand.h>
#include <maya/MDGModifier.h>
#include <maya/MFnDagNode.h>
#include <maya/MDagPath.h>
#include <maya/MGlobal.h>
#ifndef INTERSECTCMD
#define INTERSECTCMD
#define MERR_CHK(stat,msg) if ( !stat ) { MGlobal::displayError(msg); } // cerr << msg << endl; }
{
public:
intersectCmd();
~intersectCmd() override;
static void* creator();
};
#endif
intersectCmd::intersectCmd()
{
}
intersectCmd::~intersectCmd()
{
}
void* intersectCmd::creator()
{
return new intersectCmd;
}
bool intersectCmd::isUndoable() const
{
return false;
}
{
{
}
int i;
for ( i = 0; i < 2; i++)
{
stat = args.
get(i, strCurrSelection);
}
float fX = 0;
float fY = 0;
float fZ = 0;
for ( ; !iter.isDone(); iter.next() )
{
MObject tempObjectParent, tempObjectChild;
iter.getDependNode(tempObjectParent);
{
tempObjectChild = dagNod.
child(0, &stat);
}
{
MERR_CHK(
MDagPath::getAPathTo(tempObjectParent, pathToLight),
"Couldn't get a path to the spotlight");
MERR_CHK(fnLight.
setObject(pathToLight),
"Failure on assigning light");
{
}
pTempPlug = fnDN.
findPlug(
"translateY",
true, &stat);
{
}
pTempPlug = fnDN.
findPlug(
"translateZ",
true, &stat);
{
}
}
{
MERR_CHK(
MDagPath::getAPathTo(tempObjectChild, pathToMesh),
"Couldn't get a path to the spotlight");
MERR_CHK(fnMesh.
setObject(pathToMesh),
"Failure on assigning light");
}
else
{
}
}
float fHitRayParam, fHitBary1, fHitBary2;
int nHitFace, nHitTriangle;
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)
{
return stat;
}
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)
{
return stat;
}
unsigned int nNumberHitPoints = hitPoints.
length();
if (! nNumberHitPoints)
{
}
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++)
{
x = hitPoints[i][0];
y = hitPoints[i][1];
z = hitPoints[i][2];
strCommandString += "setAttr ($strBallName + \".tx\") ";
strCommandString += x;
strCommandString += ";";
strCommandString += "setAttr ($strBallName + \".ty\") ";
strCommandString += y;
strCommandString += ";";
strCommandString += "setAttr ($strBallName + \".tz\") ";
strCommandString += z;
strCommandString += ";";
}
return stat;
}
{
return status;
}
{
MFnPlugin plugin(obj, PLUGIN_COMPANY,
"6.5",
"Any");
status = plugin.registerCommand("intersectCmd", intersectCmd::creator);
return status;
}
{
plugin.deregisterCommand("intersectCmd");
return status;
}