//---------------------------------------------------------------------------- MStatus BPT_InsertVtx::doCompleteCompute( MDataBlock& data ) //---------------------------------------------------------------------------- { SPEED("Berechne EdgeSplit neu: "); MStatus status; MPRINT("MACHE KOMPLETTE BERECHNUNG") MDataHandle inMeshHandle = data.inputValue(IVinMesh); MDataHandle outMeshHandle = data.outputValue(IVoutMesh); //splitCount setzen MDataHandle countHandle = data.inputValue(IVcount); fIVfty.setCount(countHandle.asInt()); MDataHandle spinHandle = data.inputValue(IVspin); fIVfty.setSpin(spinHandle.asInt()); int initialVtxCount; //wird spueueter benueuetigt, um das ValidIndicesArray gleich in der rictigen grueueueuee zu erstellen und zu schreiben //gleich zu beginn muss der MeshPath initialisiert werden, damit der MeshPath an die fty ueuebergeben werden kann // Dies geschieht besser durch die STE - sie ist darauf ausgelegt softTransformationEngine::gatherAttributeObjects(thisMObject()); softTransformationEngine::saveMeshPathes(); fIVfty.setMeshPath(meshPath); MDataHandle rHandle = data.inputValue(IVslideRelative); fIVfty.setRelative(rHandle.asInt()); MDataHandle nRelativeHandle = data.inputValue(IVnormalRelative); fIVfty.setNormalRelative(nRelativeHandle.asInt()); //selection setzen MFnIntArrayData intDataArray; MDataHandle arrayHandle = data.inputValue(IVselEdgeIDs); intDataArray.setObject(arrayHandle.data()); fIVfty.setEdgeIDs( intDataArray.array() ); arrayHandle = data.inputValue(IVselVertIDs); intDataArray.setObject(arrayHandle.data()); fIVfty.setVertIDs(intDataArray.array()); // optionen holen arrayHandle = data.inputValue(IVoptions); intDataArray.setObject(arrayHandle.data()); MIntArray optionsArray(intDataArray.array()); fIVfty.setOptions(optionsArray); MDataHandle slideHandle = data.inputValue(IVslide); fIVfty.setSlide(slideHandle.asDouble()); //whichSide attribute wird nur fueuer SLide selbst verwendet und kann nicht bereits beim command gestetzt werden MObject inMeshRef = inMeshHandle.asMesh(); fIVfty.setMesh(inMeshRef); MFnMesh meshFn(inMeshHandle.asMesh()); initialVtxCount = meshFn.numVertices(); //ACTION try { status = fIVfty.doIt(); } catch(...) { MGlobal::displayError(" An unknown, severe, error occoured.\nIf it happens again in this situation, please write a bug report.\nPlease undo the operation and save your work!"); return MS::kUnknownParameter; } MObject newOutMesh = fIVfty.getMesh(); outMeshHandle.set(newOutMesh); // --------------------- // SOFT TRANSFORMATION // --------------------- // VtxSet setzen - hier reicht es, wenn er einfach die neuen Vtx nimmt softTransformationEngine::setVtxSet(data); //------------SELECTION ROUTINE---------------------- //nur wenn sich spin nicht verueuendert hat, darf ne neue selection gemacht werden - dies wird auch von der IV berueuecksichtigt //die selection wird nur noch einmal ausgefueuehrt, weshalb scriptJobInitiated nicht mehr gesetzt wird vom scriptjob if( optionsArray[6] && !scriptJobInitated && !(meshPath.apiType() == MFn::kInvalid) ) { //auf jeden Fall erstmal die neuen Vertizen holen, damit die anderen prozeduren auch darauf arbeiten kueuennen //alles neuen Vertces sollen gewueuehlt werden, also einfach alle Indices eintragen vom initialVtxCount //bis zum jetzigen VtxCount MIntArray validEdges, validFaces; componentConverter CC(newOutMesh); int i = 0; meshFn.setObject(newOutMesh); int newCount = meshFn.numVertices(); validIndices.clear(); validIndices.setLength(newCount - initialVtxCount); for(; initialVtxCount < newCount; initialVtxCount++) validIndices[i++] = initialVtxCount; if(optionsArray[6] == 1 || optionsArray[6] == 2) //select edges { CC.getContainedEdges(validIndices,validEdges); } BPT_Helpers helper; if(optionsArray[6] == 2) //select Faces { CC.getConnectedFaces(validEdges,validFaces); //jetzt kann gleich alles beendet werden, da hiernach keine componente mehr kommt, in die man faces umwandeln mueuesste validIndices.clear(); validIndices.append(2); helper.addIntArrayToLHS(validIndices,validFaces); } if(optionsArray[6] == 1) {//edges fertigmachen validIndices.clear(); validIndices.append(1); helper.addIntArrayToLHS(validIndices,validEdges); } else if(optionsArray[6] == 5) validIndices.insert(3,0); //component Mode umschalten bei bedarf if(optionsArray[5]) { MSelectionMask::SelectionType type = MSelectionMask::kSelectMeshVerts; if(optionsArray[6] == 5) { type = MSelectionMask::kSelectMeshVerts; } else if(optionsArray[6] == 2) { type = MSelectionMask::kSelectMeshFaces; } else if(optionsArray[6] == 1) { type = MSelectionMask::kSelectMeshEdges; } MSelectionMask mask(type); MGlobal:: setComponentSelectionMask(mask); } eID = MEventMessage::addEventCallback("idle",IV_makeSelection,this); scriptJobInitated = true; } else {//ansonsten muss die SelectionList neu aufgebaut werden, allerdings ohne komponenten //diese Aktion solte auch nur einmal ausgefueuehrt werden //gegenwueuertige selection holen MSelectionList currentList; MSelectionList newList; MGlobal::getActiveSelectionList(currentList); //durch die Liste iterieren und Komponenten Filtern MItSelectionList selIter(currentList); MObject currentObj; for( ; !selIter.isDone();selIter.next() ) { selIter.getDependNode(currentObj); newList.add(currentObj); } MGlobal::setActiveSelectionList(newList, MGlobal::kAddToList); } return status; }
MStatus SelectRingContext2::doRelease( MEvent &event ) { // Get the mouse release position event.getPosition( releaseX, releaseY ); // Didn't select a single point if( abs(pressX - releaseX) > 1 || abs(pressY - releaseY) > 1 ) { MGlobal::displayWarning( "Click on a single edge" ); return MS::kFailure; } // Set the selection surface area int halfClickBoxSize = clickBoxSize / 2; pressX -= halfClickBoxSize; pressY -= halfClickBoxSize; releaseX = pressX + clickBoxSize; releaseY = pressY + clickBoxSize; // Get the current selection MSelectionList curSel; MGlobal::getActiveSelectionList( curSel ); //MGlobal::displayInfo( MString("Dim: ") + start_x + " " + start_y + " " + last_x + " " + last_y ); // Change to object selection mode MGlobal::setSelectionMode( MGlobal::kSelectObjectMode ); MGlobal::setComponentSelectionMask( MSelectionMask( MSelectionMask::kSelectObjectsMask ) ); // Select the object under the selection area MGlobal::selectFromScreen( pressX, pressY, releaseX, releaseY, MGlobal::kReplaceList); MGlobal::executeCommand( "hilite" ); // Change selection mode to mesh edges MGlobal::setSelectionMode( MGlobal::kSelectComponentMode ); MGlobal::setComponentSelectionMask( MSelectionMask( MSelectionMask::kSelectMeshEdges ) ); // Select the edges MGlobal::selectFromScreen( pressX, pressY, releaseX, releaseY, MGlobal::kReplaceList ); // Get the list of selected edges MSelectionList origEdgesSel; MGlobal::getActiveSelectionList( origEdgesSel ); // Only use the first edge in the selection MItSelectionList selIter( origEdgesSel, MFn::kMeshEdgeComponent ); if( !selIter.isDone() ) { MDagPath dagPath; MObject component; selIter.getDagPath( dagPath, component ); SelectRingToolCmd2 &cmd = *(SelectRingToolCmd2 *) newToolCommand(); cmd.setCurrentSelection( curSel ); cmd.setSelectedEdgeObject( dagPath ); cmd.setSelectedEdgeComponent( component ); cmd.setListAdjust( listAdjust ); cmd.setSelEdges( selEdges ); cmd.setSelFaces( selFaces ); cmd.setSelVertices( selVertices ); cmd.setSelType( SelectRingToolCmd2::SelType(selType) ); cmd.redoIt(); cmd.finalize(); } return MS::kSuccess; }
MStatus SelectRingContext1::doRelease( MEvent &event ) { // Get the mouse release position event.getPosition( releaseX, releaseY ); // Didn't select a single point if( abs(pressX - releaseX) > 1 || abs(pressY - releaseY) > 1 ) { MGlobal::displayWarning( "Click on a single edge" ); return MS::kFailure; } // Set the selection surface area int halfClickBoxSize = clickBoxSize / 2; pressX -= halfClickBoxSize; pressY -= halfClickBoxSize; releaseX = pressX + clickBoxSize; releaseY = pressY + clickBoxSize; /* // Record previous selection state prevSelMode = MGlobal::selectionMode(); prevCompMask = MGlobal::componentSelectionMask(); */ // Get the current selection MSelectionList curSel; MGlobal::getActiveSelectionList( curSel ); //MGlobal::displayInfo( MString("Dim: ") + start_x + " " + start_y + " " + last_x + " " + last_y ); // Change to object selection mode MGlobal::setSelectionMode( MGlobal::kSelectObjectMode ); MGlobal::setComponentSelectionMask( MSelectionMask( MSelectionMask::kSelectObjectsMask ) ); // Select the object under the selection area MGlobal::selectFromScreen( pressX, pressY, releaseX, releaseY, MGlobal::kReplaceList); MGlobal::executeCommand( "hilite" ); // Change selection mode to mesh edges MGlobal::setSelectionMode( MGlobal::kSelectComponentMode ); MGlobal::setComponentSelectionMask( MSelectionMask( MSelectionMask::kSelectMeshEdges ) ); // Select the edges MGlobal::selectFromScreen( pressX, pressY, releaseX, releaseY, MGlobal::kReplaceList ); // Get the list of selected edges MSelectionList origEdgesSel; MGlobal::getActiveSelectionList( origEdgesSel ); MSelectionList newEdgesSel; MDagPath dagPath; MObject component; // Only use the first edge in the selection MItSelectionList selIter( origEdgesSel, MFn::kMeshEdgeComponent ); if( !selIter.isDone() ) { selIter.getDagPath( dagPath, component ); MIntArray faces; MItMeshEdge edgeIter( dagPath, component ); MIntArray edgesVisited, facesVisited; int edgeIndex, faceIndex; int prevIndex; unsigned int i; bool finished = false; while( !finished ) { edgeIndex = edgeIter.index(); edgesVisited.append( edgeIndex ); // Create an edge component the current edge MFnSingleIndexedComponent indexedCompFn; MObject newComponent = indexedCompFn.create( MFn::kMeshEdgeComponent ); indexedCompFn.addElement( edgeIndex ); newEdgesSel.add( dagPath, newComponent ); //MGlobal::displayInfo( MString("ADDING: ") + edgeIter.index() ); edgeIter.getConnectedFaces( faces ); faceIndex = faces[0]; if( faces.length() > 1 ) { // Select the face that hasn't already been visited for( i=0; i < facesVisited.length(); i++ ) { if( faceIndex == facesVisited[i] ) { faceIndex = faces[1]; break; } } } //MGlobal::displayInfo( MString("FACE: ") + faceIndex ); facesVisited.append( faceIndex ); MItMeshPolygon polyIter( dagPath ); polyIter.setIndex( faceIndex, prevIndex ); //MGlobal::displayInfo( MString( "faces: " ) + faces[0] + " " + faces[1] ); MIntArray edges; polyIter.getEdges( edges ); // Determine the face-relative index of the current // edge unsigned int edgeFaceIndex = 0; for( i=0; i < edges.length(); i++ ) { if( edges[i] == edgeIter.index() ) { edgeFaceIndex = i; break; } } // Determine the edge that is opposite the current edge edgeIndex = edges[ (edgeFaceIndex + (edges.length() / 2) ) % edges.length() ]; //int index = edgeIter.index(); //MGlobal::displayInfo( MString( "sel edge index: " ) + index + " next edge: " + edgeIndex ); // Set the current edge to the opposite edge edgeIter.setIndex( edgeIndex, prevIndex ); // Determine if the edge has already been visited for( i=0; i < edgesVisited.length(); i++ ) { if( edgeIndex == edgesVisited[i] ) { finished = true; break; } } } } // Set the active selection to the one previous to edge loop selection MGlobal::setActiveSelectionList( curSel, MGlobal::kReplaceList); // Update this selection based on the list adjustment setting MGlobal::selectCommand( newEdgesSel, listAdjust ); return MS::kSuccess; }