aboutsummaryrefslogtreecommitdiff
path: root/mayaPlug/shaveVraySharedFunctions.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'mayaPlug/shaveVraySharedFunctions.cpp')
-rw-r--r--mayaPlug/shaveVraySharedFunctions.cpp258
1 files changed, 258 insertions, 0 deletions
diff --git a/mayaPlug/shaveVraySharedFunctions.cpp b/mayaPlug/shaveVraySharedFunctions.cpp
new file mode 100644
index 0000000..f6748f3
--- /dev/null
+++ b/mayaPlug/shaveVraySharedFunctions.cpp
@@ -0,0 +1,258 @@
+// Shave and a Haircut
+// (c) 2019 Epic Games
+// US Patent 6720962
+
+/**********************************************************************
+ *<
+ FILE: shaveVraySharedFunctions.h
+
+ DESCRIPTION: Various shared functions
+
+ HISTORY: created 21-08-2008 ( as part of 3ds Max + VRay hair shaders)
+ merged 31-03-2010
+
+ *>
+ **********************************************************************/
+
+#include "shaveVraySharedFunctions.h"
+
+#include <maya/MItDependencyGraph.h>
+#include <maya/MDagPath.h>
+#include <maya/MArgList.h>
+#include <maya/MSelectionList.h>
+#include <maya/MFnDependencyNode.h>
+#include <maya/MFnDagNode.h>
+#include <maya/MPlugArray.h>
+#include <maya/MItSelectionList.h>
+#include <maya/MItDependencyGraph.h>
+#include <maya/MItDependencyNodes.h>
+
+#include <assert.h>
+
+#ifdef USE_VRAY
+
+MObject getNodeByName(const char *nodeName)
+{
+ MString name(nodeName);
+ MSelectionList sList;
+ MGlobal::getSelectionListByName(name, sList);
+ if (sList.length() < 1) return MObject();
+ MObject obj;
+ sList.getDependNode(0, obj);
+ return obj;
+}
+
+bool getSourcePlugFromPlug(const MPlug destPlug, MPlug &plug)
+{
+ MPlugArray plugSources;
+ destPlug.connectedTo(plugSources, true, false);
+
+ bool foundSource = false;
+ int len=plugSources.length();
+ if (len == 1)
+ {
+ foundSource = true;
+ plug = plugSources[0];
+ }
+ return foundSource;
+}
+
+bool FindCurrentShaveShape(MObject &shShape)
+{
+ MStatus stat = MStatus::kSuccess;
+
+ MDagPath nodePath;
+ MObject component;
+ MSelectionList list;
+
+ MGlobal::getActiveSelectionList( list );
+
+
+ for ( MItSelectionList listIter( list ); !listIter.isDone(); listIter.next() )
+ {
+ MObject depNode;
+ listIter.getDependNode( depNode );
+
+ if( FindConnectedShaveShape ( depNode, shShape))
+ return true;
+
+ if(depNode.hasFn( MFn::kDagNode ))
+ {
+ MFnDagNode dagFn(depNode);
+ for(unsigned int i = 0; i < dagFn.childCount(); i++)
+ if( FindConnectedShaveShape( dagFn.child(i), shShape))
+ return true;
+ }
+ }
+
+#ifdef _DEBUG
+ MGlobal::displayInfo(MString("shaveVray: shaveShape not found."));
+#endif
+ return false;
+
+}
+
+bool FindConnectedShaveShape(MObject depNode, MObject &shShape)
+{
+ MStatus stat;
+ {
+ MItDependencyGraph graphIt(depNode,
+ MFn::kInvalid,
+ MItDependencyGraph::kUpstream,
+ MItDependencyGraph::kDepthFirst,
+ MItDependencyGraph::kNodeLevel,
+ &stat);
+
+ if(stat == MStatus::kSuccess)
+ {
+ for ( ; ! graphIt.isDone(); graphIt.next() )
+ {
+ MObject itNode = graphIt.thisNode();
+
+ MFnDependencyNode itFn(itNode);
+
+ if(itFn.typeId() == MTypeId(0x001029B7)) //shaveHairShape type id
+ {
+ shShape = itNode;
+ #ifdef _DEBUG
+ MGlobal::displayInfo(MString("shaveVray: shaveShape found: ") + itFn.name());
+ #endif
+ return true;
+ }
+
+ }
+ }
+ }
+ {
+ MItDependencyGraph graphIt(depNode,
+ MFn::kInvalid,
+ MItDependencyGraph::kDownstream,
+ MItDependencyGraph::kDepthFirst,
+ MItDependencyGraph::kNodeLevel,
+ &stat);
+
+ if(stat == MStatus::kSuccess)
+ {
+ for ( ; ! graphIt.isDone(); graphIt.next() )
+ {
+ MObject itNode = graphIt.thisNode();
+
+ //if(itNode.apiType() == MFn::kShape)
+ {
+ MFnDependencyNode itFn(itNode);
+
+ if(itFn.typeId() == MTypeId(0x001029B7)) //shaveHairShape type id
+ {
+ shShape = itNode;
+ #ifdef _DEBUG
+ MGlobal::displayInfo(MString("shaveVray: shaveShape found: ") + itFn.name());
+ #endif
+ return true;
+ }
+ }
+ }
+ }
+ }
+ return false;
+}
+
+void FindNodesByTypeId(MTypeId nodeType, MObjectArray& nodes)
+{
+ MItDependencyNodes iter;
+
+ nodes.clear();
+
+ for (; !iter.isDone(); iter.next())
+ {
+ MObject node = iter.item();
+ MFnDependencyNode nodeFn(node);
+
+ if (nodeFn.typeId() == nodeType) nodes.append(node);
+ }
+}
+
+void FindNodesByApiType(MFn::Type type, MObjectArray& nodes)
+{
+ MItDependencyNodes iter;
+
+ nodes.clear();
+
+ for (; !iter.isDone(); iter.next())
+ {
+ MObject node = iter.item();
+ if (node.hasFn(type)) nodes.append(node);
+ }
+}
+
+bool FindAllShaveShapes(MObjectArray& shShapes)
+{
+ FindNodesByTypeId(MTypeId(0x001029B7),shShapes);
+ return shShapes.length() != 0;
+}
+
+bool EnumDownNodes(MObject thisNode, MObjectArray& nodes)
+{
+ MStatus stat;
+ MItDependencyGraph graphIt(thisNode,
+ MFn::kInvalid,
+ MItDependencyGraph::kDownstream,
+ MItDependencyGraph::kDepthFirst,
+ MItDependencyGraph::kNodeLevel,
+ &stat);
+
+ if(stat == MStatus::kSuccess)
+ {
+ for ( ; ! graphIt.isDone(); graphIt.next() )
+ {
+ MObject itNode = graphIt.thisNode();
+ nodes.append(itNode);
+ }
+ }
+ return nodes.length() != 0;
+}
+
+bool GetLibPathEnv(const MString vrayVersion, MString &var)
+{
+ MStatus stat;
+#if MAYA_API_VERSION < 20180000
+ int apiMajor = MAYA_API_VERSION/100;
+#else
+ int apiMajor = MAYA_API_VERSION/10000;
+#endif
+ char envVarBuf[256] = {'\0'};
+ int vrayMajorVersion = vrayVersion.substring(0, vrayVersion.index('.')-1).asInt();
+
+ if (vrayMajorVersion < 4)
+ {
+ sprintf(envVarBuf,"VRAY_FOR_MAYA%i_PLUGINS_x64",apiMajor);
+ }
+ else
+ {
+ sprintf(envVarBuf,"VRAY_FOR_MAYA%i_PLUGINS",apiMajor);
+ }
+
+ //printf("V-Ray plug-ins dir eviornment variable %s\n",envVarBuf);
+
+ var = envVarBuf;
+ return true;
+}
+
+bool GetLibPath(const MString vrayVersion, MString &path)
+{
+ MStatus stat;
+ MString pathVar;
+
+ GetLibPathEnv(vrayVersion, pathVar);
+
+ char* vrayPlugDir = getenv(pathVar.asChar());
+ if(!vrayPlugDir)
+ return false;
+
+ //printf("V-Ray plug-ins dir %s\n",vrayPlugDir);
+
+ path = MString(vrayPlugDir);
+
+ return true;
+}
+
+#endif //USE_VRAY