void CoronaRenderer::defineMaterial(Corona::IInstance* instance, std::shared_ptr<MayaObject> mobj) { std::shared_ptr<mtco_MayaObject> obj = std::static_pointer_cast<mtco_MayaObject>(mobj); getObjectShadingGroups(obj->dagPath, obj->perFaceAssignments, obj->shadingGroups, false); if( obj->shadingGroups.length() > 0) { for (uint sgId = 0; sgId < obj->shadingGroups.length(); sgId++) { MObject shadingGroup = obj->shadingGroups[sgId]; Logging::debug(MString("---------- Check shading group: ") + getObjectName(shadingGroup) + " for existence on object named " + obj->fullName); if (assingExistingMat(shadingGroup, obj)) return; MObject surfaceShader = getConnectedInNode(shadingGroup, "surfaceShader"); // check obj set overrides MObject connectedSet = getConnectedObjSet(obj->dagPath); if (connectedSet != MObject::kNullObj) { MFnDependencyNode setFn(connectedSet); Logging::debug(MString("Found connected object set:") + setFn.name()); MPlug shaderOverride = setFn.findPlug("mtco_mtlOverride"); if (!shaderOverride.isNull()) { MObject connectedObject = getConnectedInNode(shaderOverride); if (connectedObject != MObject::kNullObj) surfaceShader = connectedObject; } } // raytype shader is a special case. Here a material set gets different materials, so I have to call defineCoronaMaterial several times MFnDependencyNode shaderMat(surfaceShader); Corona::SharedPtr<Corona::IMaterial> base = nullptr; Corona::SharedPtr<Corona::IMaterial> reflect = nullptr; Corona::SharedPtr<Corona::IMaterial> refract = nullptr; Corona::SharedPtr<Corona::IMaterial> direct = nullptr; if (shaderMat.typeName() == "CoronaRaytype") { MPlug basePlug = shaderMat.findPlug("base"); MPlug reflectPlug = shaderMat.findPlug("reflect"); MPlug refractPlug = shaderMat.findPlug("refract"); MPlug directPlug = shaderMat.findPlug("direct"); if (basePlug.isConnected()) { MObject inNode = getConnectedInNode(basePlug); base = defineCoronaMaterial(inNode, nullptr); } if (reflectPlug.isConnected()) { MObject inNode = getConnectedInNode(reflectPlug); reflect = defineCoronaMaterial(inNode, nullptr); } if (refractPlug.isConnected()) { MObject inNode = getConnectedInNode(refractPlug); refract = defineCoronaMaterial(inNode, nullptr); } if (directPlug.isConnected()) { MObject inNode = getConnectedInNode(directPlug); direct = defineCoronaMaterial(inNode, nullptr); } } else{ base = defineCoronaMaterial(surfaceShader, obj); } Corona::IMaterialSet ms = Corona::IMaterialSet(base); ms.overrides.direct = direct; ms.overrides.reflect = reflect; ms.overrides.refract = refract; setRenderStats(ms, obj); obj->instance->addMaterial(ms); } } else{ Corona::SharedPtr<Corona::IMaterial> mat = defineCoronaMaterial(MObject::kNullObj, nullptr); Corona::IMaterialSet ms = Corona::IMaterialSet(mat); setRenderStats(ms, obj); obj->instance->addMaterial(ms); } }
bool tm_polyExtract::extractFaces_Func( MSelectionList &selectionList, MStringArray &node_names) { MStatus status; MObject meshObj; status = selectionList.getDependNode( 0, meshObj); if(!status){MGlobal::displayError("tm_polyExtract::extractFaces_Func: Can't find object !");return false;} MFnMesh meshFn( meshObj, &status); if(!status){MGlobal::displayError("tm_polyExtract::extractFaces_Func: Non mesh object founded !");return false;} MDagPath meshDagPath_first, meshDagPath; selectionList.getDagPath( 0, meshDagPath_first); MObject multiFaceComponent; MIntArray inputFacesArray; inputFacesArray.clear(); inputFacesArray.setSizeIncrement( 4096); MFnComponentListData compListFn; compListFn.create(); for (MItSelectionList faceComponentIter(selectionList, MFn::kMeshPolygonComponent); !faceComponentIter.isDone(); faceComponentIter.next()) { faceComponentIter.getDagPath(meshDagPath, multiFaceComponent); if(!(meshDagPath_first == meshDagPath)) { MGlobal::displayError("tm_polyExtract::extractFaces_Func: Different meshes faces founded !"); return false; } if (!multiFaceComponent.isNull()) { for (MItMeshPolygon faceIter(meshDagPath, multiFaceComponent); !faceIter.isDone(); faceIter.next()) { int faceIndex = faceIter.index(); #ifdef _DEBUG infoMStr += faceIndex; infoMStr += " "; #endif inputFacesArray.append( faceIndex); compListFn.add( multiFaceComponent ); } } } if( inputFacesArray.length() == 0) { MGlobal::displayError("tm_polyExtract::extractFaces_Func: No faces founded !"); return false; } #ifdef _DEBUG MGlobal::displayInfo( infoMStr); #endif meshFn.setObject( meshDagPath_first); meshObj = meshFn.object(); // MDagModifier dagModifier; MFnDagNode meshDagNodeFn; MFnDependencyNode depNodeFn; meshDagNodeFn.setObject( meshDagPath_first); MString meshName = meshDagNodeFn.name(); MObject outMesh_attrObject = meshDagNodeFn.attribute( "outMesh"); // ----------------------------------- duplicate shape MObject duplicated_meshObjectA; MObject duplicated_meshObjectB; MObject inMesh_attrObjectA; MObject inMesh_attrObjectB; /* MStringArray commandResult; MSelectionList selList; MGlobal::executeCommand( "duplicate " + meshDagNodeFn.name(), commandResult, 1, 1); selList.add( commandResult[0]); selList.getDependNode( 0, duplicated_meshObjectA); meshDagNodeFn.setObject( duplicated_meshObjectA); meshDagNodeFn.setName( meshName + "_tA"); duplicated_meshObjectA = meshDagNodeFn.child(0); meshDagNodeFn.setObject( duplicated_meshObjectA); meshDagNodeFn.setName( meshName + "_sA"); inMesh_attrObjectA = meshDagNodeFn.attribute( "inMesh"); meshDagNodeFn.setObject( meshDagPath_first); selList.clear(); MGlobal::executeCommand( "duplicate " + meshDagNodeFn.name(), commandResult, 1, 1); selList.add( commandResult[0]); selList.getDependNode( 0, duplicated_meshObjectB); meshDagNodeFn.setObject( duplicated_meshObjectB); meshDagNodeFn.setName( meshName + "_tB"); duplicated_meshObjectB = meshDagNodeFn.child(0); meshDagNodeFn.setObject( duplicated_meshObjectB); meshDagNodeFn.setName( meshName + "_sB"); inMesh_attrObjectB = meshDagNodeFn.attribute( "inMesh"); */ duplicated_meshObjectA = meshDagNodeFn.duplicate(); meshDagNodeFn.setObject( duplicated_meshObjectA); meshDagNodeFn.setName( meshName + "_tA"); duplicated_meshObjectA = meshDagNodeFn.child(0); meshDagNodeFn.setObject( duplicated_meshObjectA); meshDagNodeFn.setName( meshName + "_sA"); inMesh_attrObjectA = meshDagNodeFn.attribute( "inMesh"); meshDagNodeFn.setObject( meshDagPath_first); duplicated_meshObjectB = meshDagNodeFn.duplicate(); meshDagNodeFn.setObject( duplicated_meshObjectB); meshDagNodeFn.setName( meshName + "_tB"); duplicated_meshObjectB = meshDagNodeFn.child(0); meshDagNodeFn.setObject( duplicated_meshObjectB); meshDagNodeFn.setName( meshName + "_sB"); inMesh_attrObjectB = meshDagNodeFn.attribute( "inMesh"); // ----------------------------------- create node deleteComponent MDGModifier dgModifier; MObject deleteComponent_nodeObjectA = dgModifier.createNode( MString("deleteComponent")); depNodeFn.setObject( deleteComponent_nodeObjectA ); MObject deleteComponent_attrObjectA( depNodeFn.attribute( "deleteComponents" )); MObject inputGeometry_attrObjectA( depNodeFn.attribute( "inputGeometry" )); MObject outputGeometry_attrObjectA( depNodeFn.attribute( "outputGeometry" )); dgModifier.doIt(); depNodeFn.setName( "dfA_" + meshName); node_names.append( depNodeFn.name()); MObject deleteComponent_nodeObjectB = dgModifier.createNode( MString("deleteComponent")); depNodeFn.setObject( deleteComponent_nodeObjectB ); MObject deleteComponent_attrObjectB( depNodeFn.attribute( "deleteComponents" )); MObject inputGeometry_attrObjectB( depNodeFn.attribute( "inputGeometry" )); MObject outputGeometry_attrObjectB( depNodeFn.attribute( "outputGeometry" )); dgModifier.doIt(); depNodeFn.setName( "dfB_" + meshName); node_names.append( depNodeFn.name()); // ----------------------------------- set attribute deleteComponent.deleteComponents MObject componentList_object = compListFn.object(); MPlug deleteComponents_plugA( deleteComponent_nodeObjectA, deleteComponent_attrObjectA ); status = deleteComponents_plugA.setValue( componentList_object ); MIntArray invertedFaces; int numPolygons = meshFn.numPolygons(); invertedFaces.setLength( numPolygons - inputFacesArray.length()); int selFace = 0; int invFace = 0; for( int f = 0; f < numPolygons; f++) { if( f == inputFacesArray[selFace]) selFace++; else invertedFaces[invFace++] = f; } MFnSingleIndexedComponent singleIndexedComponentFn( meshObj); singleIndexedComponentFn.create( MFn::kMeshPolygonComponent); singleIndexedComponentFn.addElements( invertedFaces); compListFn.clear(); compListFn.create(); componentList_object = singleIndexedComponentFn.object(); compListFn.add( componentList_object); componentList_object = compListFn.object(); MPlug deleteComponents_plugB( deleteComponent_nodeObjectB, deleteComponent_attrObjectB ); status = deleteComponents_plugB.setValue( componentList_object ); // ------------------------------------- connecting plugs /**/ dgModifier.connect( meshObj, outMesh_attrObject, deleteComponent_nodeObjectA, inputGeometry_attrObjectA ); dgModifier.connect( deleteComponent_nodeObjectA, outputGeometry_attrObjectA, duplicated_meshObjectA, inMesh_attrObjectA ); dgModifier.connect( meshObj, outMesh_attrObject, deleteComponent_nodeObjectB, inputGeometry_attrObjectB ); dgModifier.connect( deleteComponent_nodeObjectB, outputGeometry_attrObjectB, duplicated_meshObjectB, inMesh_attrObjectB ); dgModifier.doIt(); // ---------------------------------- assigning shading group /**/ meshDagNodeFn.setObject( meshDagPath_first); MObject instObjGroups_attrObject = meshDagNodeFn.attribute( "instObjGroups"); MPlug instObjGroups_plug( meshObj, instObjGroups_attrObject); instObjGroups_plug = instObjGroups_plug.elementByPhysicalIndex(0); MPlugArray instObjGroups_plug_connectionsArray; instObjGroups_plug.connectedTo( instObjGroups_plug_connectionsArray, false, true); if( instObjGroups_plug_connectionsArray.length() > 0) { MPlug dagSetMembers_plug = instObjGroups_plug_connectionsArray[0]; MObject shadingSetNode_object = dagSetMembers_plug.node(); MFnSet setFn( shadingSetNode_object); setFn.addMember( duplicated_meshObjectA); setFn.addMember( duplicated_meshObjectB); //depNodeFn.setObject(shadingSetNode_object); //MGlobal::displayInfo( depNodeFn.name()); } // ------------------------------------------------------------ return true; }
MStatus exportJointClusterData::doIt( const MArgList& args ) // // Process the command // 1. parse the args // 2. find the jointClusters in the scene // 3. iterate over their members, writing their weight data out to file // { // parse args to get the file name from the command-line // MStatus stat = parseArgs(args); if (stat != MS::kSuccess) { return stat; } // count the processed jointClusters // unsigned int jcCount = 0; // Iterate through graph and search for jointCluster nodes // MItDependencyNodes iter( MFn::kJointCluster); for ( ; !iter.isDone(); iter.next() ) { MObject object = iter.item(); MFnWeightGeometryFilter jointCluster(object); // get the joint driving this cluster // MObject joint = jointForCluster(object); if (joint.isNull()) { displayError("Joint is not attached to cluster."); continue; } MObject deformSet = jointCluster.deformerSet(&stat); CheckError(stat,"Error getting deformer set."); MFnSet setFn(deformSet, &stat); //need the fn to get the members CheckError(stat,"Error getting deformer set fn."); MSelectionList clusterSetList; //get all the members // stat = setFn.getMembers(clusterSetList, true); CheckError(stat,"Could not make member list with getMembers."); // print out the name of joint and the number of associated skins // MFnDependencyNode fnJoint(joint); fprintf(file,"%s %u\n",fnJoint.name().asChar(), clusterSetList.length()); for (unsigned int kk = 0; kk < clusterSetList.length(); ++kk) { MDagPath skinpath; MObject components; MFloatArray weights; clusterSetList.getDagPath(kk,skinpath,components); jointCluster.getWeights(skinpath,components,weights); // print out the path name of the skin & the weight count // fprintf(file, "%s %u\n",skinpath.partialPathName().asChar(), weights.length()); // loop through the components and print their index and weight // unsigned counter =0; MItGeometry gIter(skinpath,components); for (/* nothing */ ; !gIter.isDone() && counter < weights.length(); gIter.next()) { fprintf(file,"%d %f\n",gIter.index(),weights[counter]); counter++; } } jcCount++; } fclose(file); if (0 == jcCount) { displayError("No jointClusters found in this scene."); return MS::kFailure; } return MS::kSuccess; }
void Editor::autoCalc() { if( !d->autoCalcEnabled ) return; QString str = Evaluator::autoFix( text() ); if( str.isEmpty() ) return; // too short? do not bother... Tokens tokens = Evaluator::scan( str ); if( tokens.count() < 2 ) return; // If we're using set for a function don't try. QRegExp setFn("\\s*set.*\\(.*="); if( str.find(setFn) != -1 ) return; // strip off assignment operator, e.g. "x=1+2" becomes "1+2" only // the reason is that we want only to evaluate (on the fly) the expression, // not to update (put the result in) the variable if( tokens.count() > 2 && tokens[0].isIdentifier() && tokens[1].asOperator() == Token::Equal ) { Tokens::const_iterator it = tokens.begin(); ++it; ++it; // Skip first two tokens. // Reconstruct string to evaluate using the tokens. str = ""; while(it != tokens.end()) { str += (*it).text(); str += ' '; ++it; } } Abakus::number_t result = parseString(str.latin1()); if( Result::lastResult()->type() == Result::Value ) { QString ss = i18n("Result: <b>%2</b>", result.toString()); d->autoCalcLabel->setText( ss ); d->autoCalcLabel->adjustSize(); // reposition nicely QPoint pos = mapToGlobal( QPoint( 0, 0 ) ); pos.setY( pos.y() - d->autoCalcLabel->height() - 1 ); d->autoCalcLabel->move( pos ); d->autoCalcLabel->show(); d->autoCalcLabel->raise(); // do not show it forever QTimer::singleShot( 5000, d->autoCalcLabel, SLOT( hide()) ); } else { // invalid expression d->autoCalcLabel->hide(); } }