//------------------------------------------------------------------------------ // void GLPickingSelect::processTriangles( const SubNode::Ptr rootNode, const double seconds, const size_t numTriangles, VBOProxy::VBOMode vboMode ) { const unsigned int bufferSize = (unsigned int)std::min(numTriangles,size_t(100000)); boost::shared_array<GLuint>buffer (new GLuint[bufferSize*4]); M3dView view = fSelectInfo.view(); MMatrix projMatrix; view.projectionMatrix(projMatrix); MMatrix modelViewMatrix; view.modelViewMatrix(modelViewMatrix); unsigned int x, y, w, h; view.viewport(x, y, w, h); double viewportX = static_cast<int>(x); // can be less than 0 double viewportY = static_cast<int>(y); // can be less than 0 double viewportW = w; double viewportH = h; fSelectInfo.selectRect(x, y, w, h); double selectX = static_cast<int>(x); // can be less than 0 double selectY = static_cast<int>(y); // can be less than 0 double selectW = w; double selectH = h; MMatrix selectAdjustMatrix; selectAdjustMatrix[0][0] = viewportW / selectW; selectAdjustMatrix[1][1] = viewportH / selectH; selectAdjustMatrix[3][0] = ((viewportX + viewportW/2.0) - (selectX + selectW/2.0)) / viewportW * 2.0 * selectAdjustMatrix[0][0]; selectAdjustMatrix[3][1] = ((viewportY + viewportH/2.0) - (selectY + selectH/2.0)) / viewportH * 2.0 * selectAdjustMatrix[1][1]; MMatrix localToPort = modelViewMatrix * projMatrix * selectAdjustMatrix; view.beginSelect(buffer.get(), bufferSize*4); view.pushName(0); { Frustum frustum(localToPort.inverse()); MMatrix xform(modelViewMatrix); DrawShadedState state(frustum, seconds, vboMode); DrawShadedTraversal traveral(state, xform, false, Frustum::kUnknown); rootNode->accept(traveral); } view.popName(); int nbPick = view.endSelect(); if (nbPick > 0) { unsigned int Zdepth = closestElem(nbPick, buffer.get()); float depth = float(Zdepth)/MAX_HW_DEPTH_VALUE; fMinZ = std::min(depth,fMinZ); } }
MStatus PluginTestUserOperation::execute(const MHWRender::MDrawContext & drawContext) { //return MStatus::kSuccess; M3dView view; if(M3dView::getM3dViewFromModelPanel(panelName, view) == MStatus::kSuccess) { // Get the current viewport and scale it relative to that // int targetW, targetH; drawContext.getRenderTargetSize(targetW, targetH); // Some user drawing of scene bounding boxes // MDagPath cameraPath; MFnCamera fnCamera; view.getCamera(cameraPath); MMatrix m3dViewProjection, m3dViewModelView; view.projectionMatrix(m3dViewProjection); view.modelViewMatrix(m3dViewModelView); MFloatMatrix m3dFloatViewProjection(m3dViewProjection.matrix); MFloatMatrix m3dFloatViewModelView(m3dViewModelView.matrix); MFloatMatrix viewProjection = m3dFloatViewModelView * m3dFloatViewProjection; SurfaceDrawTraversal traversal; traversal.enableFiltering(true); traversal.setFrustum(cameraPath, targetW, targetH); traversal.traverse(); unsigned int numItems = traversal.numberOfItems(); MFnMesh fnMesh; for (int i = 0; i < numItems; i++) { MDagPath path; traversal.itemPath(i, path); if (path.hasFn(MFn::kMesh)) { fnMesh.setObject(path); MFloatMatrix modelWorld(path.inclusiveMatrix().matrix); MTransformationMatrix transformMatrix; MFloatMatrix modelViewProjection = modelWorld * viewProjection; modelViewProjection = modelViewProjection.transpose(); MIntArray triangleCounts; MIntArray triangleVertices; // This is the index list for all the triangles in the mesh in one big list. Ie. first 3 are for tri 1 etc. Index into getPoints() fnMesh.getTriangles(triangleCounts, triangleVertices); //int indices[100]; //triangleVertices.get(indices); MFloatPointArray vertexArray; //float points[1000][4]; fnMesh.getPoints(vertexArray); //vertexArray.get(points); UserSceneRenderer::get()->render(triangleVertices, vertexArray, modelViewProjection); } } } return MStatus::kSuccess; }
//------------------------------------------------------------------------------ // void RasterSelect::processTriangles( const SubNode::Ptr rootNode, double seconds, size_t /* numTriangles */, VBOProxy::VBOMode vboMode ) { M3dView view = fSelectInfo.view(); MMatrix projMatrix; view.projectionMatrix(projMatrix); MMatrix modelViewMatrix; view.modelViewMatrix(modelViewMatrix); unsigned int x, y, w, h; view.viewport(x, y, w, h); double viewportX = static_cast<int>(x); // can be less than 0 double viewportY = static_cast<int>(y); // can be less than 0 double viewportW = w; double viewportH = h; fSelectInfo.selectRect(x, y, w, h); double selectX = static_cast<int>(x); // can be less than 0 double selectY = static_cast<int>(y); // can be less than 0 double selectW = w; double selectH = h; MMatrix selectAdjustMatrix; selectAdjustMatrix[0][0] = viewportW / selectW; selectAdjustMatrix[1][1] = viewportH / selectH; selectAdjustMatrix[3][0] = ((viewportX + viewportW/2.0) - (selectX + selectW/2.0)) / viewportW * 2.0 * selectAdjustMatrix[0][0]; selectAdjustMatrix[3][1] = ((viewportY + viewportH/2.0) - (selectY + selectH/2.0)) / viewportH * 2.0 * selectAdjustMatrix[1][1]; MMatrix localToPort = modelViewMatrix * projMatrix * selectAdjustMatrix; { Frustum frustum(localToPort.inverse()); MMatrix xform(modelViewMatrix); DrawShadedState state(frustum, seconds, vboMode); DrawShadedTraversal traveral(state, xform, false, Frustum::kUnknown); rootNode->accept(traveral); } }
void UsdMayaGLBatchRenderer::Draw( const MDrawRequest& request, M3dView &view ) { // VP 1.0 Implementation // MDrawData drawData = request.drawData(); _BatchDrawUserData* batchData = static_cast<_BatchDrawUserData*>(drawData.geometry()); if( !batchData ) return; MMatrix projectionMat; view.projectionMatrix(projectionMat); MMatrix modelViewMat; view.modelViewMatrix(modelViewMat); if( batchData->_bounds ) { px_vp20Utils::RenderBoundingBox(*(batchData->_bounds), *(batchData->_wireframeColor), modelViewMat, projectionMat); } if( batchData->_drawShape && !_renderQueue.empty() ) { MMatrix viewMat( request.matrix().inverse() * modelViewMat ); unsigned int viewX, viewY, viewWidth, viewHeight; view.viewport(viewX, viewY, viewWidth, viewHeight); GfVec4d viewport(viewX, viewY, viewWidth, viewHeight); // Only the first call to this will do anything... After that the batch // queue is cleared. // _RenderBatches( NULL, viewMat, projectionMat, viewport ); } // Clean up the _BatchDrawUserData! delete batchData; }