def RenderToDrawBuffer_SceneBoxWire(self, vpMat: QMatrix4x4, boxSize: QVector3D): with uglw.VAOBound(self._vao_blank): with uglw.ProgBound(self._sceneBoxWireProgramInfo.__progHandle__): glUniform3fv(self._sceneBoxWireProgramInfo.boxSize, 1, utyp.GetTuple(boxSize)) glUniformMatrix4fv(self._sceneBoxWireProgramInfo.vpMat, 1, GL_FALSE, vpMat.data()) glDrawArrays(GL_LINES, 0, 24)
def __init__(self, fieldSize: T.Tuple[int, int, int]): self._fieldSize = fieldSize self._vao_blank = glGenVertexArrays(1) self._velocityLineProgramInfo = BuildPipelineProgram( glsw.v, glsw.f, ("GRID", )) self._sceneBoxWireProgramInfo = BuildPipelineProgram( glsw.v, glsw.f, ("SCENEBOX", "LINE")) self._sceneBoxSurfProgramInfo = BuildPipelineProgram( glsw.v, glsw.f, ("SCENEBOX", "SURF")) self._depthInteractionBuffer = OffScreenDepthFramebuffer() with uglw.ProgBound(self._velocityLineProgramInfo.__progHandle__): glUniform3iv(self._velocityLineProgramInfo.gridN, 1, fieldSize)
def _Step_ExecBoundary_UseProg(self, scale: float, targetTexname): glViewport(0, 0, self._gridSize[0], self._gridSize[1]) with uglw.TextureBound(GL_TEXTURE_3D, targetTexname): with uglw.ProgBound(self._iprog_boundaryLn.__progHandle__): glUniform1fv(self._iprog_boundaryLn.scale, 1, scale) for operating_z in range(1, self._gridSize[2] - 1): _BindFBOwithTex3DatLayer(targetTexname, operating_z) glUniform1i(self._iprog_boundaryLn.operating_z, operating_z) glDrawArrays(GL_TRIANGLES, 0, 24) with uglw.ProgBound(self._iprog_boundaryQd.__progHandle__): glUniform1fv(self._iprog_boundaryQd.scale, 1, scale) _BindFBOwithTex3DatLayer(targetTexname, 0) glUniform1i(self._iprog_boundaryQd.operating_z, 0) glUniform3iv(self._iprog_boundaryQd.offset, 1, (0, 0, 1)) glDrawArrays(GL_TRIANGLES, 0, 6) _BindFBOwithTex3DatLayer(targetTexname, self._gridSize[2] - 1) glUniform1i(self._iprog_boundaryQd.operating_z, self._gridSize[2] - 1) glUniform3iv(self._iprog_boundaryQd.offset, 1, (0, 0, -1)) glDrawArrays(GL_TRIANGLES, 0, 6)
def SetGrid(self, size: T.Tuple[int, int, int], cellScale): ONE_3D = QVector3D(1, 1, 1) rDx = 1 / cellScale with uglw.ProgBound(self._iprog_advection.__progHandle__): glUniform3fv(self._iprog_advection.rGridsize, 1, utyp.GetTuple(ONE_3D / QVector3D(*size))) with uglw.ProgBound(self._iprog_divergence.__progHandle__): glUniform1fv(self._iprog_divergence.halfRdx, 1, 0.5 * rDx) with uglw.ProgBound(self._iprog_gradsub.__progHandle__): glUniform1fv(self._iprog_gradsub.halfRdx, 1, 0.5 * rDx) glUniform1iv(self._iprog_gradsub.u3_1, 1, 0) glUniform1iv(self._iprog_gradsub._3p1, 1, 1) with uglw.ProgBound(self._iprog_jacobi.__progHandle__): glUniform1iv(self._iprog_jacobi.fieldX, 1, 0) glUniform1iv(self._iprog_jacobi.fieldB, 1, 1) glUniform2fv(self._iprog_jacobi.alphaRbeta, 1, (-cellScale * cellScale, 1 / 6)) self._rDx = rDx self._gridSize = size
def RenderToDrawBuffer_VelocityLine(self, vpMat: QMatrix4x4, tex3DName_velocity: GLuint, cellScale: float, lineScale: float): with uglw.VAOBound(self._vao_blank): with uglw.TextureBound(GL_TEXTURE_3D, tex3DName_velocity): with uglw.ProgBound( self._velocityLineProgramInfo.__progHandle__): cellNx2 = self._fieldSize[0] * self._fieldSize[ 1] * self._fieldSize[2] * 2 glUniform1fv(self._velocityLineProgramInfo.lineScale, 1, lineScale) glUniform1fv(self._velocityLineProgramInfo.cellScale, 1, cellScale) glUniformMatrix4fv(self._velocityLineProgramInfo.vpMat, 1, GL_FALSE, vpMat.data()) glDrawArrays(GL_LINES, 0, cellNx2) glDrawArrays(GL_POINTS, 0, cellNx2)
def GetSceneBoxCursorIntersection(self, vpMat: QMatrix4x4, boxSize: QVector3D, winspaceCursorPos: QPoint, winspaceDimension: QPoint) -> QVector3D: """ :param winspaceCursorPos: lower-left corner as origin :return: 3D world position of cursor interaction """ # render depthImage and get depthValue ------------------------------------------------------------------------- self._depthInteractionBuffer.RequestBindFBO(winspaceDimension) glViewport(0, 0, winspaceDimension.x(), winspaceDimension.y()) with uglw.VAOBound(self._vao_blank): with uglw.ProgBound(self._sceneBoxSurfProgramInfo.__progHandle__): with uglw.EnableScope(GL_DEPTH_TEST): glClearBufferfv(GL_DEPTH, 0, (1., )) glUniform3fv(self._sceneBoxSurfProgramInfo.boxSize, 1, utyp.GetTuple(boxSize)) glUniformMatrix4fv(self._sceneBoxSurfProgramInfo.vpMat, 1, GL_FALSE, vpMat.data()) glDrawArrays(GL_TRIANGLES, 0, 3 * 2 * 6) winspaceCursorDepthValue = glReadPixels(winspaceCursorPos.x(), winspaceCursorPos.y(), 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT)[0][0] # print( winspaceCursorDepthValue ) glBindFramebuffer(GL_FRAMEBUFFER, 0) # unproject cursor into worldCoord ----------------------------------------------------------------------------- if winspaceCursorDepthValue == 1.0: raise ValueError # cursor ray hit background, no object to manipulate return self.GetUnprojection(winspaceCursorPos, winspaceCursorDepthValue, winspaceDimension, vpMat)