// grab the current mesh and setup the polygon sets void Mesh::SetMesh(const MDagPath &dPath) { MObjectArray fPolygonSets; MObjectArray fPolygonComponents; MDagPath dagPath(dPath); polySets.clear(); MFnMesh fMesh = MFnMesh(dagPath); //Have to make the path include the shape below it so that //we can determine if the underlying shape node is instanced. //By default, dag paths only include transform nodes. dagPath.extendToShape(); //If the shape is instanced then we need to determine which instance this path refers to. int instanceNum = 0; if (dagPath.isInstanced()) instanceNum = dagPath.instanceNumber(); //Get the connected sets and members - these will be used to determine texturing of different faces if (!fMesh.getConnectedSetsAndMembers(instanceNum, fPolygonSets, fPolygonComponents, true)) { MGlobal::displayError("MFnMesh::getConnectedSetsAndMembers"); return; } unsigned int setCount = fPolygonSets.length(); if (setCount > 1) setCount--; for (unsigned int i=0; i < setCount; i++) polySets.push_back(PolygonSet(dagPath, fPolygonComponents[i], fPolygonSets[i])); }
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; }
TheaSDK::Normal3D TheaRenderer::getSunDirection() { MFnDependencyNode depFn(getRenderGlobalsNode()); std::shared_ptr<RenderGlobals> renderGlobals = MayaTo::getWorldPtr()->worldRenderGlobalsPtr; std::shared_ptr<TheaRenderer> renderer = std::static_pointer_cast<TheaRenderer>(MayaTo::getWorldPtr()->worldRendererPtr); TheaSDK::Normal3D sunDir; MObjectArray nodeList; getConnectedInNodes(MString("sunLightConnection"), getRenderGlobalsNode(), nodeList); if( nodeList.length() > 0) { MVector lightDir(0,0,1); MFnDagNode sunDagNode(nodeList[0]); //lightDir *= this->mtth_renderGlobals->globalConversionMatrix.inverse(); lightDir *= sunDagNode.transformationMatrix(); lightDir *= renderGlobals->globalConversionMatrix; lightDir.normalize(); return TheaSDK::Normal3D(lightDir.x,lightDir.y,lightDir.z); } float sunDirX = 0.0f, sunDirY = 0.0f, sunDirZ = 1.0f; MPlug sunDirPlug = depFn.findPlug("sunDirection"); if (!sunDirPlug.isNull()) { sunDirX = sunDirPlug.child(0).asFloat(); sunDirY = sunDirPlug.child(1).asFloat(); sunDirZ = sunDirPlug.child(2).asFloat(); } return TheaSDK::Normal3D(sunDirX, sunDirY, sunDirZ); }
MStatus StrandLengthCount::doIt(const MArgList & args) { std::list<MObject> targets; MStatus status = ArgList_GetModelObjects(args, syntax(), "-b", targets); if (status != MStatus::kNotFound && status != MStatus::kSuccess) { HMEVALUATE_RETURN_DESCRIPTION("ArgList_GetModelObjects", status); } clearResult(); if (!targets.empty()) { for (std::list<MObject>::const_iterator it(targets.begin()); it != targets.end(); ++it) { Model::Base base(*it); Model::Strand strand(base); HPRINT("Calling with base: %s", base.getDagPath(status).fullPathName().asChar()); appendToResult(int(m_operation.length(strand))); } } else { MObjectArray objects; HMEVALUATE_RETURN(status = Model::Base::AllSelected(objects), status); for (unsigned int i = 0; i < objects.length(); ++i) { Model::Base base(objects[i]); Model::Strand strand(base); HPRINT("Calling with base: %s", base.getDagPath(status).fullPathName().asChar()); appendToResult(int(m_operation.length(strand))); } } return MStatus::kSuccess; }
void EntityNode::UnloadArt() { MStatus stat; // remove anything currently imported/referenced MFnDagNode dagFn( thisMObject() ); while( dagFn.childCount() ) { stat = MGlobal::deleteNode( dagFn.child( 0 ) ); MContinueErr( stat, ("Unable to delete" + dagFn.fullPathName() ).asChar() ); } ClearInstances(); MObjectArray forDelete; GetImportNodes( forDelete ); MFnDependencyNode depFn; u32 num = forDelete.length(); for( u32 i = 0; i < num; ++i ) { MObject& node = forDelete[i]; MObjectHandle handle( node ); if( !handle.isValid() ) continue; depFn.setObject( node ); stat = MGlobal::deleteNode( node ); MContinueErr( stat, ("Unable to delete" + depFn.name() ).asChar() ); } forDelete.clear(); }
void NeuronForMayaDevice::postConstructor() { MObjectArray attrArray; attrArray.append( NeuronForMayaDevice::outputTranslate ); setRefreshOutputAttributes( attrArray ); // we'll be reading one set of translate x,y, z's at a time createMemoryPools( 24, 15, sizeof(double)); }
MStatus GetSelectedObjectsOfType(MObjectArray & objects, MTypeId & type) { MStatus status; MSelectionList selectionList; if (!(status = MGlobal::getActiveSelectionList(selectionList))) { status.perror("MGlobal::getActiveSelectionList"); return status; } if (!(status = objects.clear())) { status.perror("MObjectArray::clear"); return status; } unsigned int selectionList_length = selectionList.length(&status); if (!status) { status.perror("MSelectionList::length"); return status; } for(unsigned int i = 0; i < selectionList_length; ++i) { //MDagPath dagPath; MObject object; if (!(status = selectionList.getDependNode(i, object))) { status.perror("MSelectionList::getDependNode"); return status; } MObject relative = GetObjectOrParentsOfType(object, type, status); if (!status) { status.perror("GetObjectOrParentsOfType"); return status; } if (relative != MObject::kNullObj) { /* * Make sure it's not already added */ bool contains = false; for(unsigned int i = 0; i < objects.length(); ++i) { if (objects[i] == object) { contains = true; break; } } if (!contains) objects.append(relative); } } return MStatus::kSuccess; }
void HesperisIO::LsChildren(MObjectArray & dst, const int & maxCount, const MObject & oparent) { MFnDagNode ppf(oparent); for(unsigned i = 0; i <ppf.childCount(); i++) { dst.append(ppf.child(i) ); if(dst.length() >= maxCount) return; } }
void EntityNode::Unselect( MSelectionList& list ) { MObjectArray importNodes; GetImportNodes( importNodes ); u32 len = importNodes.length(); for( u32 i = 0; i < len; ++i ) { MGlobal::unselect( importNodes[i] ); } }
void SocketJSObject::Send(const MObjectArray& args, MObjectContainer& resultContainer) { bool bResult = false; if(args.size() == 1) // data { MJSCoreObjectAbstract* dataObj = dynamic_cast<MJSCoreObjectAbstract* >(args.getAt(0)); string data = dataObj->toString(); bResult = Send(data); } resultContainer.set(MJSCoreObjectFactory::getMObject(bResult)); }
bool skinClusterWeights::isSkinClusterIncluded(MObject &node) { MStatus status; unsigned int i; if (skinClusterArray.length() == 0) return true; for (i = 0; i < skinClusterArray.length(); i++) { if (skinClusterArray[i] == node) return true; } return false; }
void SocketJSObject::Connect(const MObjectArray& args, MObjectContainer& resultContainer) { if (args.size() == 2) // server, port { MJSCoreObjectAbstract* serverObj = dynamic_cast<MJSCoreObjectAbstract* >(args.getAt(0)); MJSCoreObjectAbstract* portObj = dynamic_cast<MJSCoreObjectAbstract* >(args.getAt(1)); string server = serverObj->toString(); string port = portObj->toString(); bool bResult = Connect(server, port); resultContainer.set(MJSCoreObjectFactory::getMObject(bResult)); } resultContainer.set(MJSCoreObjectFactory::getMObject(false)); }
void SocketJSObject::removeEventListener(const MObjectArray& args, MObjectContainer& resultContainer) { if (args.size() == 2) // eventName, eventHandlerFunction { MJSCoreObjectAbstract * eventName = dynamic_cast<MJSCoreObjectAbstract* >(args.getAt(0)); MJSCoreObject * eventHandler = dynamic_cast<MJSCoreObject *>(args.getAt(1)); if (eventName && eventHandler) { bool bRet = RemoveEventListener(eventName->toString(), eventHandler); resultContainer.set(MJSCoreObjectFactory::getMObject(bRet)); } } resultContainer.set(MJSCoreObjectFactory::getMObject(false)); }
void printMaterials(const MDagPath& dagPath) { MFnMesh fnMesh(dagPath); unsigned instanceNumber = dagPath.instanceNumber(); MObjectArray sets; MObjectArray comps; fnMesh.getConnectedSetsAndMembers( instanceNumber, sets, comps, true ); // Print Material Names for(unsigned int i = 0; i < sets.length(); ++i) { MFnDependencyNode fnDepSGNode(sets[i]); std::cout << fnDepSGNode.name() << std::endl; } }
MStatus skinClusterWeights::undoIt() { MStatus status; for (unsigned i = 0; i < fDagPathArray.length(); i++) { MDagPath &dagPath = fDagPathArray[i]; MObject skinCluster = findSkinCluster(dagPath); if (!isSkinClusterIncluded(skinCluster)) { continue; } MFnSkinCluster skinClusterFn(skinCluster, &status); if (status != MS::kSuccess) { continue; } MObject &component = fComponentArray[i]; if (dagPath.isValid() && fInfluenceIndexArrayPtrArray[i].length() > 0 && fWeightsPtrArray[i].length() > 0) { skinClusterFn.setWeights(dagPath, component, fInfluenceIndexArrayPtrArray[i], fWeightsPtrArray[i]); } } fDagPathArray.clear(); fComponentArray.clear(); delete [] fInfluenceIndexArrayPtrArray; delete [] fWeightsPtrArray; fInfluenceIndexArrayPtrArray = NULL; fWeightsPtrArray = NULL; return MS::kSuccess; }
void dumpInfo( MObject fileNode, MFnDependencyNode& nodeFn, MObjectArray& nodePath ) { MObject currentNode; MObject fileAttr = nodeFn.attribute("fileTextureName"); MPlug plugToFile( fileNode, fileAttr ); MFnDependencyNode dgFn; MStatus stat; cerr << "Name: " << nodeFn.name() << endl; MObject fnameValue; stat = plugToFile.getValue( fnameValue ); if ( !stat ) { stat.perror("error getting value from plug"); } else { MFnStringData stringFn( fnameValue ); cerr << "Texture: " << stringFn.string() << endl; } cerr << "Path: "; for ( int i = nodePath.length()-1; i >= 0; i-- ) { currentNode = nodePath[i]; dgFn.setObject( currentNode ); cerr << dgFn.name() << "(" << dgFn.typeName() << ")"; if ( i > 0) cerr << " ->\n "; } cerr << endl; }
AlembicWriteJob::AlembicWriteJob(const MString &in_FileName, const MObjectArray &in_Selection, const MDoubleArray &in_Frames, bool use_ogawa, const std::vector<std::string> &in_prefixFilters, const std::set<std::string> &in_attributes, const std::vector<std::string> &in_userPrefixFilters, const std::set<std::string> &in_userAttributes) : useOgawa(use_ogawa), mPrefixFilters(in_prefixFilters), mAttributes(in_attributes), mUserPrefixFilters(in_userPrefixFilters), mUserAttributes(in_userAttributes) { // ensure to clear the isRefAnimated cache clearIsRefAnimatedCache(); mFileName = in_FileName; for (unsigned int i = 0; i < in_Selection.length(); i++) { mSelection.append(in_Selection[i]); } for (unsigned int i = 0; i < in_Frames.length(); i++) { mFrames.push_back(in_Frames[i]); } }
bool isIn(const MDagPath & dagPath, const MObject & referenceNode) { MDagPathArray rootDagPaths; MObjectArray subReferences; ReferenceManager::getRootObjects(referenceNode, rootDagPaths, subReferences); for (unsigned int i = 0; i < rootDagPaths.length(); ++i) { if (rootDagPaths[i] == dagPath) { return true; } } for (unsigned int i = 0; i < subReferences.length(); ++i) { if (isIn(dagPath, subReferences[i])) { return true; } } return false; }
bool isObjectInList(MObject obj, MObjectArray& objectArray) { for( uint oId = 0; oId < objectArray.length(); oId++) { if( objectArray[oId] == obj) return true; } return false; }
//------------------------------ void MaterialExporter::exportConnectedMaterials ( SceneElement* sceneElement ) { // If we have a external reference, we don't need to export the data here. if ( !sceneElement->getIsLocal() ) return; if ( !sceneElement->getIsExportNode () ) return; // Check if it is a mesh object and an export node if ( sceneElement->getType() == SceneElement::MESH ) { MDagPath dagPath = sceneElement->getPath(); // Attach a function set MStatus status; MFnMesh fnMesh ( dagPath.node(), &status ); if ( status != MStatus::kSuccess ) return; // Find how many shaders are used by this instance of the mesh MObjectArray shaders; MIntArray shaderIndices; unsigned instanceNumber = dagPath.instanceNumber(); fnMesh.getConnectedShaders ( instanceNumber, shaders, shaderIndices ); // Find the polygons that correspond to each materials and export them uint realShaderCount = ( uint ) shaders.length(); uint numShaders = ( uint ) std::max ( ( size_t ) 1, ( size_t ) shaders.length() ); for ( uint shaderPosition = 0; shaderPosition < numShaders; ++shaderPosition ) { if ( shaderPosition < realShaderCount ) { // Add shader-specific parameters (TexCoords sets). // Add symbolic name for the material used on this polygon set. MObject shadingEngine = shaders[shaderPosition]; exportMaterial ( shadingEngine ); } } } // recursive call for all the child elements for ( uint i=0; i<sceneElement->getChildCount(); ++i ) { SceneElement* childElement = sceneElement->getChild ( i ); exportConnectedMaterials ( childElement ); } }
// -------------------------------------- void ReferenceManager::getRootObjects( const MObject& referenceNode, MDagPathArray& rootPaths, MObjectArray& subReferences) { rootPaths.clear(); subReferences.clear(); MFnDependencyNode referenceNodeFn(referenceNode); // Get the paths of all the dag nodes included in this reference MStringArray nodeNames; MString command = MString("reference -rfn \"") + referenceNodeFn.name() + "\" -q -node -dp;"; MGlobal::executeCommand(command, nodeNames); uint nodeNameCount = nodeNames.length(); MDagPathArray nodePaths; for (uint j = 0; j < nodeNameCount; ++j) { MObject o = DagHelper::getNode(nodeNames[j]); MDagPath p = DagHelper::getShortestDagPath(o); if (p.length() > 0) { nodePaths.append(p); } else { if (o != MObject::kNullObj && o.apiType() == MFn::kReference && strstr(nodeNames[j].asChar(), "_UNKNOWN_REF_NODE") == NULL) { subReferences.append(o); } } } // Keep only the root transform for the reference in our path arrays uint nodePathCount = nodePaths.length(); for (uint j = 0; j < nodePathCount; ++j) { const MDagPath& p = nodePaths[j]; if ( !isRootTransform ( nodePaths, p ) ) continue; rootPaths.append(p); } }
void makeUniqueArray(MObjectArray& oa) { MObjectArray tmpArray; for (uint i = 0; i < oa.length(); i++) { bool found = false; for (uint k = 0; k < tmpArray.length(); k++) { if (oa[i] == tmpArray[k]) { found = true; break; } } if (!found) tmpArray.append(oa[i]); } oa = tmpArray; }
void uniqueMObjectArray(MObjectArray& cleanMe) { MObjectArray tmpArray; for (uint i = 0; i < cleanMe.length(); i++) { bool found = false; for (uint k = 0; k < tmpArray.length(); k++) { if (cleanMe[i] == tmpArray[k]) { found = true; break; } } if (!found) tmpArray.append(cleanMe[i]); } cleanMe = tmpArray; }
void SocketJSObject::Disconnect(const MObjectArray& args, MObjectContainer& resultContainer) { ::MessageBoxA(0, "SocketJSObject.Disconnect called.", "test", MB_OK); bool bResult = false; if (args.size() == 0) // No Arguments { bResult = Disconnect(); } resultContainer.set(MJSCoreObjectFactory::getMObject(bResult)); }
void SocketJSObject::construct(const MObjectArray& args, MObjectContainer& resultContainer) { // check for required arguments before creating the object if(args.size() == 0) { JSContextRef context = MJSCoreObjectFactory::getJSContext(); bool hasConstructor = false; resultContainer.set(new SocketJSObject(ctx, hasConstructor)); } // TODO: throw exception. }
bool CoronaRenderer::isSunLight(std::shared_ptr<MayaObject> obj) { // a sun light has a transform connection to the coronaGlobals.sunLightConnection plug MObject coronaGlobals = objectFromName(MString("coronaGlobals")); MObjectArray nodeList; MStatus stat; getConnectedInNodes(MString("sunLightConnection"), coronaGlobals, nodeList); if( nodeList.length() > 0) { MObject sunObj = nodeList[0]; if(sunObj.hasFn(MFn::kTransform)) { MFnDagNode sunDagNode(sunObj); MObject sunDagObj = sunDagNode.child(0, &stat); if( sunDagObj == obj->mobject) return true; } } return false; }
MStatus setupRGBShaders::doIt( const MArgList & args ) { unsigned int FIndex = args.flagIndex( "fp", "folderPath" ); unsigned int fIndex = args.flagIndex( "fn", "fileName" ); if( FIndex == MArgList::kInvalidArgIndex || fIndex == MArgList::kInvalidArgIndex ) { MGlobal::displayError( "Error specifying flag or flag values. \n-fp, -folderPath <folder_path> \t -fn, -fileName <file_name>" ); return MS::kFailure; } folderPath = args.asString( FIndex ); fileName = args.asString( fIndex ); MItDag meshIt( MItDag::kDepthFirst, MFn::kMesh ); for( ; !meshIt.isDone(); meshIt.next() ) { MDagPath dagPath; meshIt.getPath( dagPath ); meshObjs.append( dagPath.transform() ); } MItDag camIt( MItDag::kDepthFirst, MFn::kCamera ); for( ; !camIt.isDone(); camIt.next() ) { MDagPath dagPath; camIt.getPath( dagPath ); MFnDependencyNode camFn( dagPath.node() ); bool isRenderable; camFn.findPlug( "renderable" ).getValue( isRenderable ); if( isRenderable ) camObjs.append( dagPath.transform() ); } MGlobal::executeCommand( "setAttr miDefaultFramebuffer.datatype 5" ); return redoIt(); }
MStatus HelixBases_sort(MObjectArray & input, MObjectArray & result) { MStatus status; result.setSizeIncrement(input.length()); while(input.length() > 0) { double z = std::numeric_limits<double>::max(); unsigned int z_index = 0; for(unsigned int i = 0; i < input.length(); ++i) { MFnTransform transform(input[i]); MVector translation = transform.getTranslation(MSpace::kTransform, &status); if (!status) { status.perror("MFnTransform::getTranslation"); return status; } if (translation.z < z) { z = translation.z; z_index = i; } } result.append(input[z_index]); input.remove(z_index); } return MStatus::kSuccess; }
MStatus ParameterisedHolder<B>::removeUnecessaryAttributes() { MObjectArray toRemove; MFnDependencyNode fnDN( B::thisMObject() ); for( unsigned i=0; i<fnDN.attributeCount(); i++ ) { MObject attr = fnDN.attribute( i ); MFnAttribute fnAttr( attr ); MString attrName = fnAttr.name(); if( 0==strncmp( attrName.asChar(), g_attributeNamePrefix.c_str(), g_attributeNamePrefix.size() ) ) { if( m_attributeNamesToParameters.find( fnAttr.name() )==m_attributeNamesToParameters.end() ) { MPlug plug( B::thisMObject(), attr ); plug.setLocked( false ); // we can't remove things if they're locked if( fnAttr.parent().isNull() ) { toRemove.append( attr ); } else { // we don't need to remove attributes which are the children // of compounds as they'll be removed when their parent is removed } } } } for( unsigned i=0; i<toRemove.length(); i++ ) { MStatus s = fnDN.removeAttribute( toRemove[i] ); if( !s ) { return s; } } return MStatus::kSuccess; }
//for this attribute on this node add the following layer nodes and plugs it's associated with void atomNodeWithAnimLayers::addPlugWithLayer(MPlug &attrPlug, MObjectArray &layers, MPlugArray &plugs) { if(plugs.length() == layers.length()) { MObject attrObj = attrPlug.attribute(); MFnAttribute fnLeafAttr (attrObj); std::string attrStd(std::string(fnLeafAttr.name().asChar())); PlugsAndLayers plugsAndLayers; for(unsigned int i =0; i < layers.length(); ++i) { if(plugs[i].isNull()==false) //it's possible to not have a plug for the specified layer { if(layers[i].hasFn (MFn::kDependencyNode)) { MFnDependencyNode fnNode (layers[i]); MString layerName = fnNode.name(); plugsAndLayers.mLayerNames.append(layerName); plugsAndLayers.mPlugs.append(plugs[i]); fAttrLayers[attrStd] = plugsAndLayers; } } } } }