MStatus ffdPlanar::getBoundingBox( MDataBlock& block, unsigned int multiIndex, MBoundingBox &boundingBoxOut ) { MStatus status = MS::kSuccess; MArrayDataHandle inputHandle = block.outputArrayValue( input ); inputHandle.jumpToElement( multiIndex ); MObject mesh = inputHandle.outputValue().child( inputGeom ).asMesh(); MBoundingBox boundingBox = MBoundingBox(); MFnMesh meshFn( mesh, &status ); MCheckErr( status, "Error getting mesh from mesh object\n" ); MPointArray pointArray = MPointArray(); meshFn.getPoints( pointArray, MSpace::kTransform ); for ( int i = 0; i < pointArray.length(); i++ ) { boundingBox.expand( pointArray[i] ); } boundingBoxOut = boundingBox; return status; }
MStatus HairToolContext::doPress( MEvent& event ) { // if we have a left mouse click if(event.mouseButton() == MEvent::kLeftMouse) { //Our Viewer m_View = M3dView::active3dView(); //Get Screen click position event.getPosition( m_storage[0], m_storage[1] ); screenPoints = vector<vec2>(); screenPoints.push_back(vec2(m_storage[0], m_storage[1])); //char buffer[200]; //sprintf(buffer, "print \"%i, %i\\n\"", m_storage[0], m_storage[1]); //MGlobal::executeCommand(buffer); //Camera stuff MPoint origin = MPoint(); MVector direction = MVector(); m_View.viewToWorld(m_storage[0], m_storage[1], origin, direction); //Iterate through meshes in scene bool intersection = false; MPointArray points = MPointArray(); MIntArray polygonIds = MIntArray(); MItDag dagIter = MItDag(MItDag::kBreadthFirst, MFn::kInvalid); for( ; !dagIter.isDone(); dagIter.next() ){ MDagPath dagPath; dagIter.getPath(dagPath); MFnDagNode dagNode( dagPath); //Object cannot be intermediate, it must be a mesh if( dagNode.isIntermediateObject() ) continue; if( !dagPath.hasFn(MFn::kMesh) ) continue; if( dagPath.hasFn(MFn::kTransform) ) continue; MGlobal::executeCommand(MString("print \"node is a mesh \\n\"")); //MFnMesh mesh = MFnMesh(dagPath); MFnMesh mesh(dagPath); points = MPointArray(); polygonIds = MIntArray(); intersection = mesh.intersect(origin, direction, points, 1e-010, MSpace::kWorld, &polygonIds); if(intersection){ break; } } if(intersection){ intersectionFound = true; MDagPath dagPath; dagIter.getPath(dagPath); // MFnMesh mesh = MFnMesh(dagPath); MFnMesh mesh(dagPath); //Polygon Normal MVector polygonNormal; mesh.getPolygonNormal(polygonIds[0], polygonNormal, MSpace::kWorld); if(polygonNormal.normal().angle(direction.normal()) < 20.0f){ //polygonNormal = mesh.get } //Camera Right m_View.getCamera(dagPath); MFnCamera camera(dagPath); MVector cameraRight = camera.rightDirection(MSpace::kWorld); //Resulting Plane //Point point = points[0]; //Normal normal = cameraRight^polygonNormal; //pushback point splinePoints = vector<MPoint>(); splinePoints.push_back(MPoint(points[0].x, points[0].y, points[0].z, points[0].w)); /*//Calculate Tvalue tValue = (points[0].x - origin.x)/direction.x;*/ } else{ intersectionFound = false; MGlobal::executeCommand("print \" No Intersection \\n\""); } // yay! return MS::kSuccess; } // just let the base class handle the event*/ return MPxContext::doPress(event); }
//setEdgeVertexIndexListShear //----------------------------------------------- void TesselationVisualization::setEdgeVertexPositionListShear(MDataBlock &data) { //clear edgeVertexPositionList drawData.edgeVertexPositionList.clear(); //inputGeo MObject oInputGeo = data.inputValue(aInputGeo).asMesh(); //fnMeshInputGeo MFnMesh fnMeshInputGeo(oInputGeo); //vertexPositionList MPointArray vertexPositionList; fnMeshInputGeo.getPoints(vertexPositionList); //itMeshPolyInputGeo MItMeshPolygon itMeshPolyInputGeo(oInputGeo); //for each poly while(!itMeshPolyInputGeo.isDone()) { //get edges MIntArray edgeIndexList; itMeshPolyInputGeo.getEdges(edgeIndexList); //edgeVertexIndices int2* edgeVertexIndices = new int2[4]; for(int index = 0; index < edgeIndexList.length(); index++) { fnMeshInputGeo.getEdgeVertices(edgeIndexList[index], edgeVertexIndices[index]); }; //edgeVertexIndicesNoDuplicates std::set<int> setEdgeVertexIndicesNoDuplicates; for(int index = 0; index < edgeIndexList.length(); index++) { setEdgeVertexIndicesNoDuplicates.insert(edgeVertexIndices[index][0]); setEdgeVertexIndicesNoDuplicates.insert(edgeVertexIndices[index][1]); }; //vecEdgeVertexIndicesNoDuplicates std::vector<int> vecEdgeVertexIndicesNoDuplicates(setEdgeVertexIndicesNoDuplicates.begin(), setEdgeVertexIndicesNoDuplicates.end()); //get faceVertexList MPointArray faceVertexPointList = MPointArray(4); for(int index = 0; index < edgeIndexList.length(); index++) { MPoint faceVertexPoint = vertexPositionList[vecEdgeVertexIndicesNoDuplicates[index]]; faceVertexPointList.set(faceVertexPoint, index); }; //edge01 std::vector<float> edge01; edge01.push_back(faceVertexPointList[0].x);edge01.push_back(faceVertexPointList[0].y);edge01.push_back(faceVertexPointList[0].z); edge01.push_back(faceVertexPointList[1].x);edge01.push_back(faceVertexPointList[1].y);edge01.push_back(faceVertexPointList[1].z); //edge13 std::vector<float> edge13; edge13.push_back(faceVertexPointList[1].x);edge13.push_back(faceVertexPointList[1].y);edge13.push_back(faceVertexPointList[1].z); edge13.push_back(faceVertexPointList[3].x);edge13.push_back(faceVertexPointList[3].y);edge13.push_back(faceVertexPointList[3].z); //edge32 std::vector<float> edge32; edge32.push_back(faceVertexPointList[3].x);edge32.push_back(faceVertexPointList[3].y);edge32.push_back(faceVertexPointList[3].z); edge32.push_back(faceVertexPointList[2].x);edge32.push_back(faceVertexPointList[2].y);edge32.push_back(faceVertexPointList[2].z); //edge20 std::vector<float> edge20; edge20.push_back(faceVertexPointList[2].x);edge20.push_back(faceVertexPointList[2].y);edge20.push_back(faceVertexPointList[2].z); edge20.push_back(faceVertexPointList[0].x);edge20.push_back(faceVertexPointList[0].y);edge20.push_back(faceVertexPointList[0].z); //edge03 std::vector<float> edge03; edge03.push_back(faceVertexPointList[0].x);edge03.push_back(faceVertexPointList[0].y);edge03.push_back(faceVertexPointList[0].z); edge03.push_back(faceVertexPointList[3].x);edge03.push_back(faceVertexPointList[3].y);edge03.push_back(faceVertexPointList[3].z); //edge12 std::vector<float> edge12; edge12.push_back(faceVertexPointList[1].x);edge12.push_back(faceVertexPointList[1].y);edge12.push_back(faceVertexPointList[1].z); edge12.push_back(faceVertexPointList[2].x);edge12.push_back(faceVertexPointList[2].y);edge12.push_back(faceVertexPointList[2].z); //add to drawData.edgeVertexPositionList drawData.edgeVertexPositionList.push_back(edge01); drawData.edgeVertexPositionList.push_back(edge13); drawData.edgeVertexPositionList.push_back(edge32); drawData.edgeVertexPositionList.push_back(edge20); drawData.edgeVertexPositionList.push_back(edge03); drawData.edgeVertexPositionList.push_back(edge12); //del edgeVertexIndices delete [] edgeVertexIndices; //Advance itMeshPolyInputGeo.next(); }; };