MStatus tm_polySlot::doIt( const MArgList& ) // // Description: // implements the MEL tm_polySlot command. // // Arguments: // args - the argument list that was passes to the command from MEL // // Return Value: // MS::kSuccess - command succeeded // MS::kFailure - command failed (returning this value will cause the // MEL script that is being run to terminate unless the // error is caught using a "catch" statement. // { #ifdef _DEBUG cout << endl << "####################################################" << endl; cout << "tm_polySlot::doIt - DEBUG version info:" << endl; #endif MStatus status; // Parse the selection list for objects with selected UV components. // To simplify things, we only take the first object that we find with // selected UVs and operate on that object alone. // // All other objects are ignored and return warning messages indicating // this limitation. // MGlobal::getActiveSelectionList( oldSelList ); MItSelectionList selListIter( oldSelList ); selListIter.setFilter( MFn::kMesh ); // The tm_polySlot node only accepts a component list input, so we build // a component list using MFnComponentListData. // // MIntArrays could also be passed into the node to represent the edgesIds, // but are less storage efficient than component lists, since consecutive // components are bundled into a single entry in component lists. // MFnComponentListData compListFn; compListFn.create(); bool found = false; bool foundMultiple = false; for( ; !selListIter.isDone(); selListIter.next() ) { MDagPath dagPath; MObject component; selListIter.getDagPath( dagPath, component ); // Check for selected UV components // if( component.apiType() == MFn::kMeshEdgeComponent ) { if( !found ) { // The variable 'component' holds all selected components on the selected // object, thus only a single call to MFnComponentListData::add() is needed // to store the selected components for a given object. // compListFn.add( component ); // Copy the component list created by MFnComponentListData into our local // component list MObject member. // fComponentList = compListFn.object(); // Locally store the actual edgesIds of the selected Edges so that this command // can directly modify the mesh in the case when there is no history and // history is turned off. // MFnSingleIndexedComponent compFn( component ); compFn.getElements( fSelEdges ); // Ensure that this DAG path will point to the shape of our object. // Set the DAG path for the polyModifierCmd. // dagPath.extendToShape(); setMeshNode( dagPath ); found = true; } else { // Break once we have found a multiple object holding selected UVs, since // we are not interested in how many multiple objects there are, only // the fact that there are multiple objects. // foundMultiple = true; break; } } } if( foundMultiple ) { displayWarning("Found more than one object with selected Edges - Only operating on first found object."); } if( !found ) { displayError( "tm_polySlot command failed: Unable to find selected edges" ); return MStatus::kFailure; } // Initialize the polyModifierCmd node type - mesh node already set // setModifierNodeType( tm_polySlotNode::id ); //################################################################## alwaysWithConstructionHistory = true; status = doModifyPoly(); if( !status){displayError( "tm_polySlot command failed!" );return status;} //################################################################## get polymodifier node name and select it getModifierNodeName(); newSelList.add( modifierNodeName); MGlobal::setActiveSelectionList( newSelList);//, MGlobal::kAddToList); //################################################################## successResult(); return MStatus::kSuccess; }
//----------------------------------------------------------------- MStatus ByronsPolyTools::doIt(const MArgList& args) //----------------------------------------------------------------- { // Ist die version abgelaufen ? // #ifdef EXPIRES if( ! checkExpires() ) { MGlobal::displayError( "This AlphaVersion is expired. Scenes will still load properly. " ); return MS::kSuccess; } #endif MSelectionList sList; MStatus status; MArgDatabase argData(syntax(),args); if(argData.isFlagSet("-help")) { MGlobal::executeCommand("showBPTHelpWindow",false,false); return MS::kSuccess; } //SELECTION UEBERPRUEFEN // Selection holen // argData.getObjects(sList); // OrigList fuer UndoZwecke speichern origList = sList; // Check, ob ueberhaupt Objekt gewaehlt if ( (sList.length() == 0) ) { displayError("ONE mesh or its transform node must be selected."); return MStatus::kFailure; } //MDagPath meshDagPath; MItSelectionList sIter(sList);//,MFn::kMesh); bool meshOK = false,hasComps = false; INVIS(cout<<"SELECTIONLIST LAENGE: "<<sList.length()<<endl); for(; !sIter.isDone(); sIter.next()) { sIter.getDagPath(meshDagPath, components); //sList.getDagPath(0, meshDagPath, components); //if(!meshDagPath.hasFn(MFn::kPluginDependNode)) if(meshDagPath.apiType() == (MFn::kMesh)) { if(!meshDagPath.hasFn(MFn::kMesh) ) meshOK = false; else meshOK = true; if( components.apiType() == MFn::kInvalid ) hasComps = false; else { hasComps = true; break; } } } if(!meshOK) { displayError("Invalid type! Only a mesh or its transform with selected components can be specified!"); return MStatus::kFailure; } #ifdef DEMO MFnMesh meshFn(meshDagPath); if(meshFn.numPolygons() > 500) { MGlobal::displayError("This DEMO will only work on meshes with a maximum number of 500 polygons"); return MS::kFailure; } #endif if(!hasComps) { displayError("Please select some components to operate on"); return MStatus::kFailure; } // Flags und Argumente Holen //---------------------------------- if(argData.isFlagSet("-iv")) operationMode = 0; else operationMode = 1; //zuerst mal edgeComoponents holen - wenn welche vorhanden und -peb flag gesetzt, dann wird auf jeden Fall der case 0 mode verwendet getEdgeComponents(sList); if( argData.isFlagSet("-peb") && edgeIDs.length() != 0 ) operationMode = 0; //------------------------------------ // OPTIONS //------------------------------------ switch(operationMode) { case 0://insert Vtx mode { if(argData.isFlagSet("-ic")) argData.getFlagArgument("-ic",0,initialCount); else initialCount = 1; goto default_values; } case 1: //PolyToolsMode { //------------------------------------ // FLAGS //------------------------------------ smartSplitFlagSet = argData.isFlagSet("-smartSplit"); edgeLoopFlagSet = argData.isFlagSet("-edgeLoop"); edgeRingFlagSet = argData.isFlagSet("-edgeRing"); boundaryFlagSet = argData.isFlagSet("-boundary"); chamferFlagSet = argData.isFlagSet("-chamfer"); solidChamferFlagSet = argData.isFlagSet("-solidChamfer"); smcFlagSet = argData.isFlagSet("-smartMoveComponent"); growFlagSet = argData.isFlagSet("-gro"); schrinkFlagSet = argData.isFlagSet("-shr"); // abbruch, wenn flags nicht eindeutig und actionMode nicht gesetzt werden kann status = setActionMode(); if(status == MS::kFailure) return status; //-------------------ENDE----------------------------- goto default_values; } default: { default_values: avt = (argData.isFlagSet("-avf"))?true:false; avm = (argData.isFlagSet("-avm"))?true:false; options.setLength(10); options[0] = argData.isFlagSet("-connectEnds"); options[1] = argData.isFlagSet("-triangulateEnds"); if(argData.isFlagSet("-maxEdgeCount")) argData.getFlagArgument("-maxEdgeCount",0,options[2]); else options[2] = 16666666; options[3] = 0; //side ist standardmaessig 0: if(argData.isFlagSet("-snl") ) options[4] = 1; else options[4] = 0; options[5] = (argData.isFlagSet("-ast"))?1:0; options[6] = 0; if(argData.isFlagSet("-se")) options[6] = 1; if( CMDactionMode == 5 && argData.isFlagSet("-") ) options[6] += 3; if(argData.isFlagSet("-sf")) options[6] = 2; if(argData.isFlagSet("-sv")) options[6] = 5; //IV flag - wenn -peb aktiv ist, wird er auf jeden Fall gesetzt if( argData.isFlagSet("-peb") ) options[9] = 1; else options[9] = argData.isFlagSet("-civ")?true:false; //----------------------------------------OPTIONS ENDE slideIsRelative = argData.isFlagSet("-sir"); //slideIsRelative ist an, wenn Chamfer aktiv ist if(chamferFlagSet+solidChamferFlagSet > 0) slideIsRelative = 1; if(CMDactionMode == 6) slideIsRelative = true; normalIsRelative = argData.isFlagSet("-nir"); //slide soll automatisch auf gesetzt werden, wenn -peb aktiv (dies entspricht einem slidewert von 1 if( argData.isFlagSet("-peb") && edgeIDs.length() != 0) directSlide = 1; else { if(argData.isFlagSet("-slide")) argData.getFlagArgument("-slide",0,directSlide); else directSlide = 0.5; //defaultValue } } } //undoIndo sammeln MSelectionMask tmpMask(MGlobal::componentSelectionMask()); undoMask = tmpMask; /* CallWindowProc( (WNDPROC)(GetWindowLong(mayaWin, GWL_WNDPROC)), mayaWin, WM_CLOSE, NULL, NULL); DWORD dwStyle = WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN; //MessageBox(mayaWin, "Help", "Whatever", MB_OK); HWND myWin = CreateWindowEx( 0,"MyFirstWin","Lala" , dwStyle, 0, 0, 300, 400, mayaWin, NULL, NULL, NULL); ShowWindow(myWin, SW_SHOWNORMAL); SetFocus(myWin); UpdateWindow(myWin); */ //checken ob makeHistory aus ist. Wenn ja, dann wieder an machen, weil maya sonst crashed int result; MGlobal::executeCommand( "constructionHistory -q -tgl", result ); if(!result) MGlobal::executeCommand( "constructionHistory -tgl 1",false,false); meshDagPath.extendToShape(); // Mesh von polyModifierCommand setzen setMeshNode(meshDagPath); switch(operationMode) { case 0: { //getEdgeComponents(sList); convertToEdges(sList, argData.isFlagSet("-peb") ); // setCreateAnimCurves(false);//damit nicht versucht wird, auf dieser Node animCurves fuer tweak zu erstellen // Jetzt sind tweaks vonnten setModifierNodeType( BPT_InsertVtx::IVid ); break; } case 1: { // Komponenten herausfiltern und IntIDArrays schreiben //getEdgeComponents(sList); getVertComponents(sList); getPolyComponents(sList); setModifierNodeType( ByronsPolyToolsNode::id ); break; } } // Aktion ausfuehren if(CMDactionMode == 0 || CMDactionMode == 4 || CMDactionMode == 5 || CMDactionMode == 6 || operationMode == 0) { MGlobal::executeCommand("setToolTo selectSuperContext",false,false); status = doModifyPoly(); MFnDependencyNode depNodeFn(bptNode); setResult(depNodeFn.name()); if( !(status == MS::kSuccess) ) { MGlobal::displayError( "An error occoured." ); MGlobal::displayError( status.errorString() ); } } else { // Wenn mesh nicht veraendert wird, wird einfach so die Factory gerufen directModifier(meshDagPath.node()); //setResult( "BPTOperation succeeded" ); } //Command wird nur einmal verwendet, also muessen die Datenarrays auch m#keinen Speicher mehr verschwenden //.clear() wuerde sie nicht physisch loeschen polyIDs.setLength(0); edgeIDs.setLength(0); vertIDs.setLength(0); // return status; return MS::kSuccess; }
MStatus tm_polySplit::doIt( const MArgList& args) { #ifdef _DEBUG cout << endl << "####################################################" << endl; cout << "tm_polySplit::doIt - DEBUG version info:" << endl; #endif MStatus status; MGlobal::getActiveSelectionList( oldSelList ); MArgDatabase argData( syntax(), args); //parse flags // if(argData.isFlagSet( loop_Flag)) { cmd_flag_loop = true; argData.getFlagArgument( loop_Flag, 0, cmd_flag_loop_mode); argData.getFlagArgument( loop_Flag, 1, cmd_flag_loop_angle); // argData.getFlagArgument( loop_Flag, 2, cmd_flag_loop_maxcount); // - max count; } else if(argData.isFlagSet( sel_Flag)) { cmd_flag_loop = false; cmd_flag_sel = true; } MSelectionList selectionList; argData.getObjects( selectionList); MItSelectionList selListIter( selectionList ); selListIter.setFilter( MFn::kMesh ); // The tm_polySplit node only accepts a component list input, so we build // a component list using MFnComponentListData. // // MIntArrays could also be passed into the node to represent the edgesIds, // but are less storage efficient than component lists, since consecutive // components are bundled into a single entry in component lists. // MFnComponentListData compListFn; compListFn.create(); bool found = false; bool foundMultiple = false; MObject meshObj; for( ; !selListIter.isDone(); selListIter.next() ) { MDagPath dagPath; MObject component; selListIter.getDagPath( dagPath, component ); meshObj = dagPath.node(); // Check for selected Edges components // if( component.apiType() == MFn::kMeshEdgeComponent ) { if( !found ) { // The variable 'component' holds all selected components on the selected // object, thus only a single call to MFnComponentListData::add() is needed // to store the selected components for a given object. // compListFn.add( component ); // Copy the component list created by MFnComponentListData into our local // component list MObject member. // fComponentList = compListFn.object(); // Locally store the actual edgesIds of the selected Edges so that this command // can directly modify the mesh in the case when there is no history and // history is turned off. // MFnSingleIndexedComponent compFn( component ); compFn.getElements( fSelEdges ); // Ensure that this DAG path will point to the shape of our object. // Set the DAG path for the polyModifierCmd. // dagPath.extendToShape(); setMeshNode( dagPath ); found = true; } else { // Break once we have found a multiple object holding selected UVs, since // we are not interested in how many multiple objects there are, only // the fact that there are multiple objects. // foundMultiple = true; break; } } } #ifdef _DEBUG cout << endl << "########################## checking arguments:" << endl; cout << endl << "fSelEdges = ";for(unsigned i=0;i<fSelEdges.length();i++) cout << fSelEdges[i] << " ";cout << endl; #endif if( foundMultiple ) { displayWarning("Found more than one object with selected Edges - Only operating on first found object."); } if( !found ) { displayError( "tm_polySplit command failed: Unable to find selected edges" ); return MStatus::kFailure; } // Initialize the polyModifierCmd node type - mesh node already set // setModifierNodeType( tm_polySplitNode::id ); //################################################################## alwaysWithConstructionHistory = true; status = doModifyPoly(); if( !status){displayError( "tm_polySplit command failed!" );return status;} //################################################################## get polymodifier node name and select it getModifierNodeName(); newSelList.add( modifierNodeName); MGlobal::setActiveSelectionList( newSelList);//, MGlobal::kAddToList); //################################################################## setResult( modifierNodeName); return MStatus::kSuccess; /* cout<<endl<<"**********"<<endl;return MStatus::kSuccess; */ }
MStatus meshOp::doIt( const MArgList& argList ) // // Description: // implements the MEL meshOp command. // // Arguments: // argList - the argument list that was passes to the command from MEL // // Return Value: // MS::kSuccess - command succeeded // MS::kFailure - command failed (returning this value will cause the // MEL script that is being run to terminate unless the // error is caught using a "catch" statement. // { MStatus status; bool badArgument = false; // Only one parameter is expected to be passed to this command: the mesh // operation type. Get it, validate it or stop prematurely // if (argList.length() == 1) { int operationTypeArgument = argList.asInt(0); if (operationTypeArgument < 0 || operationTypeArgument > kMeshOperationCount - 1) { badArgument = true; } else { fOperation = (MeshOperation)operationTypeArgument; } } else badArgument = true; if (badArgument) { cerr << "Expecting one parameter: the operation type." << endl; cerr << "Valid types are: " << endl; cerr << " 0 - Subdivide edge(s)." << endl; cerr << " 1 - Subdivide face(s)." << endl; cerr << " 2 - Extrude edge(s)." << endl; cerr << " 3 - Extrude face(s)." << endl; cerr << " 4 - Collapse edge(s)." << endl; cerr << " 5 - Collapse face(s)." << endl; cerr << " 6 - Duplicate face(s)." << endl; cerr << " 7 - Extract face(s)." << endl; cerr << " 8 - Split face(s)." << endl; cerr << " 8 - Chamfer vertex(s)." << endl; displayError(" Expecting one parameter: the operation type."); return MS::kFailure; } // Each mesh operation only supports one type of components // MFn::Type componentType = meshOpFty::getExpectedComponentType(fOperation); // Parse the selection list for selected components of the right type. // To simplify things, we only take the first object that we find with // selected components and operate on that object alone. // // All other objects are ignored and return warning messages indicating // this limitation. // MSelectionList selList; MGlobal::getActiveSelectionList( selList ); MItSelectionList selListIter( selList ); selListIter.setFilter( MFn::kMesh ); // The meshOperation node only accepts a component list input, so we build // a component list using MFnComponentListData. // // MIntArrays could also be passed into the node to represent the ids, // but are less storage efficient than component lists, since consecutive // components are bundled into a single entry in component lists. // MFnComponentListData compListFn; compListFn.create(); bool found = false; bool foundMultiple = false; for( ; !selListIter.isDone(); selListIter.next() ) { MDagPath dagPath; MObject component; selListIter.getDagPath( dagPath, component ); // Check for selected components of the right type // if( component.apiType() == componentType ) { if( !found ) { // The variable 'component' holds all selected components // on the selected object, thus only a single call to // MFnComponentListData::add() is needed to store the selected // components for a given object. // compListFn.add( component ); // Copy the component list created by MFnComponentListData // into our local component list MObject member. // fComponentList = compListFn.object(); // Locally store the actual ids of the selected components so // that this command can directly modify the mesh in the case // when there is no history and history is turned off. // MFnSingleIndexedComponent compFn( component ); // Ensure that this DAG path will point to the shape // of our object. Set the DAG path for the polyModifierCmd. // dagPath.extendToShape(); setMeshNode( dagPath ); found = true; } else { // Break once we have found a multiple object holding // selected components, since we are not interested in how // many multiple objects there are, only the fact that there // are multiple objects. // foundMultiple = true; break; } } } if( foundMultiple ) { displayWarning("Found more than one object with selected components."); displayWarning("Only operating on first found object."); } // Initialize the polyModifierCmd node type - mesh node already set // setModifierNodeType( meshOpNode::id ); if( found ) { // Now, pass control over to the polyModifierCmd::doModifyPoly() method // to handle the operation. // status = doModifyPoly(); if( status == MS::kSuccess ) { setResult( "meshOp command succeeded!" ); } else { displayError( "meshOp command failed!" ); } } else { displayError( "meshOp command failed: Unable to find selected components" ); status = MS::kFailure; } return status; }