Example #1
0
def csaaScreenshot(useNVidiaAA, width, height, scene):
    try:
        csaaFmt = trinity.TRIMULTISAMPLE_8_SAMPLES if useNVidiaAA else trinity.TRIMULTISAMPLE_NONE
        csaaQty = 2 if useNVidiaAA else 0
        buffer = trinity.Tr2RenderTarget(width, height, 1,
                                         trinity.PIXEL_FORMAT.B8G8R8X8_UNORM,
                                         csaaFmt, csaaQty)
        depth = trinity.Tr2DepthStencil(width, height,
                                        trinity.DEPTH_STENCIL_FORMAT.D24S8,
                                        csaaFmt, csaaQty)
        job = trinity.CreateRenderJob('CSAA screenshot')
        job.SetRenderTarget(buffer)
        job.SetDepthStencil(depth)
        vp = trinity.TriViewport()
        vp.x = 0
        vp.y = 0
        vp.width = width
        vp.height = height
        job.SetViewport(vp)
        job.Clear((0, 0, 0, 0), 1.0)
        job.RenderScene(scene)
        trinity.SetPerspectiveProjection(trinity.GetFieldOfView(),
                                         trinity.GetFrontClip(),
                                         trinity.GetBackClip(), 1.0)
        job.ScheduleOnce()
        return (job, buffer)
    except Exception:
        return None
def csaaScreenshot(useNVidiaAA, width, height, scene):
    """
    Create a renderjob that will render the scene into a buffer using CSAA, if available.
    Returns ( job, buffer ) (which can be None if you ask for CSAA and it doesn't work).
    Use Tr2HostBitmap(buffer).Save or whatever to get to the data, after doing WaitForFinish if needed
    """
    try:
        csaaFmt = trinity.TRIMULTISAMPLE_8_SAMPLES if useNVidiaAA else trinity.TRIMULTISAMPLE_NONE
        csaaQty = 2 if useNVidiaAA else 0
        buffer = trinity.Tr2RenderTarget(width, height, 1,
                                         trinity.PIXEL_FORMAT.B8G8R8X8_UNORM,
                                         csaaFmt, csaaQty)
        depth = trinity.Tr2DepthStencil(width, height,
                                        trinity.DEPTH_STENCIL_FORMAT.D24S8,
                                        csaaFmt, csaaQty)
        job = trinity.CreateRenderJob('CSAA screenshot')
        job.SetRenderTarget(buffer)
        job.SetDepthStencil(depth)
        vp = trinity.TriViewport()
        vp.x = 0
        vp.y = 0
        vp.width = width
        vp.height = height
        job.SetViewport(vp)
        job.Clear((0, 0, 0, 0), 1.0)
        job.RenderScene(scene)
        trinity.SetPerspectiveProjection(trinity.GetFieldOfView(),
                                         trinity.GetFrontClip(),
                                         trinity.GetBackClip(), 1.0)
        job.ScheduleOnce()
        return (job, buffer)
    except Exception:
        return None
Example #3
0
 def PickObject(self, x, y):
     if self.sceneManager.GetActiveScene() != self.renderScene:
         return
     rescale = 1.0 / 10000.0
     projection = trinity.TriProjection()
     projection.PerspectiveFov(trinity.GetFieldOfView(),
                               trinity.GetAspectRatio(),
                               trinity.GetFrontClip(),
                               trinity.GetBackClip())
     view = trinity.TriView()
     view.transform = trinity.GetViewTransform()
     scaling, rotation, translation = geo2.MatrixDecompose(
         self.transform.worldTransform)
     pZ = geo2.Vec3Transform((0, 0, 1), self.transform.worldTransform)
     surfaceNormal = geo2.Subtract(pZ, translation)
     cameraZ = geo2.Vector(view.transform[0][2], view.transform[1][2],
                           view.transform[2][2])
     if geo2.Vec3Dot(surfaceNormal, cameraZ) < 0:
         return
     self.renderObject.translation = geo2.Vec3Scale(translation, rescale)
     self.renderObject.rotation = rotation
     self.renderObject.scaling = geo2.Vec3Scale(scaling, rescale)
     scaling, rotation, translation = geo2.MatrixDecompose(view.transform)
     translation = geo2.Vec3Scale(translation, rescale)
     view.transform = geo2.MatrixTransformation(None, None, scaling, None,
                                                rotation, translation)
     return self.renderObject.PickObject(x, y, projection, view,
                                         trinity.device.viewport)
Example #4
0
 def Callback():
     fovY = trinity.GetFieldOfView()
     focalLen = (1.0 / math.tan(fovY * 0.5) * aoHeight / aoWidth,
                 1.0 / math.tan(fovY * 0.5))
     invFocalLen = (1.0 / focalLen[0], 1.0 / focalLen[1])
     focalLengthParams = (focalLen[0], focalLen[1], invFocalLen[0],
                          invFocalLen[1])
     shaderSSAO.parameters['FocalLengthParams'].value = focalLengthParams
     zNear = trinity.GetFrontClip()
     zFar = trinity.GetBackClip()
     if zNear > 0 and zFar > 0:
         linA = 1.0 / zFar - 1.0 / zNear
         linB = 1.0 / zNear
     else:
         linA = 0.0
         linB = 0.0
     linearizeDepth.parameters['MiscParams'].z = linA
     linearizeDepth.parameters['MiscParams'].w = linB
     linearizeDepthAndPackAODepth.parameters['MiscParams'].z = linA
     linearizeDepthAndPackAODepth.parameters['MiscParams'].w = linB
     shaderSSAO.parameters['MiscParams'].z = linA
     shaderSSAO.parameters['MiscParams'].w = linB
Example #5
0
def WndProc(hwnd, message, wParam, lParam):
    dev = trinity.device
    if message == WM_DESTROY:
        blue.os.Terminate()
        return 0
    elif message == WM_CLOSE:
        blue.os.Terminate()
        return 0
    if message == WM_SIZE:
        if dev.GetWindow():
            rect = RECT()
            ctypes.windll.user32.GetClientRect(hwnd, ctypes.byref(rect))
            viewTrans = trinity.GetViewTransform()
            fov = trinity.GetFieldOfView()
            front = trinity.GetFrontClip()
            back = trinity.GetBackClip()
            w, h = rect.right, rect.bottom
            defaultBackBuffer = trinity.device.GetRenderContext().GetDefaultBackBuffer()
            if w == defaultBackBuffer.width and h == defaultBackBuffer.height:
                return 0
            asp = float(w) / float(h)
            dev.ChangeBackBufferSize(w, h)
            trinity.SetPerspectiveProjection(fov, front, back, asp)
            trinity.SetViewTransform(viewTrans)
    elif message == WM_LBUTTONDOWN:
        rect = RECT()
        ctypes.windll.user32.GetClientRect(hwnd, ctypes.byref(rect))
        offset = POINT()
        ctypes.windll.user32.ClientToScreen(hwnd, ctypes.byref(offset))
        ctypes.windll.user32.OffsetRect(ctypes.byref(rect), offset.x, offset.y)
        ctypes.windll.user32.ClipCursor(ctypes.byref(rect))
        PostOnMouse('LEFT_BUTTON_DOWN', wParam, lParam)
    elif message == WM_LBUTTONUP:
        ctypes.windll.user32.ClipCursor(0)
        PostOnMouse('LEFT_BUTTON_UP', wParam, lParam)
    elif message == WM_LBUTTONDBLCLK:
        PostOnMouse('LEFT_BUTTON_DBLCLK', wParam, lParam)
    elif message == WM_RBUTTONUP:
        PostOnMouse('RIGHT_BUTTON_UP', wParam, lParam)
    elif message == WM_RBUTTONDOWN:
        PostOnMouse('RIGHT_BUTTON_DOWN', wParam, lParam)
    elif message == WM_RBUTTONDBLCLK:
        PostOnMouse('RIGHT_BUTTON_DBLCLK', wParam, lParam)
    elif message == WM_MBUTTONUP:
        PostOnMouse('MIDDLE_BUTTON_UP', wParam, lParam)
    elif message == WM_MBUTTONDOWN:
        PostOnMouse('MIDDLE_BUTTON_DOWN', wParam, lParam)
    elif message == WM_MBUTTONDBLCLK:
        PostOnMouse('MIDDLE_BUTTON_DBLCLK', wParam, lParam)
    elif message == WM_MOUSEMOVE:
        PostOnMouse('MOUSE_MOVE', wParam, lParam)
    elif message == WM_MOUSEWHEEL:
        PostOnMouse('MOUSE_WHEEL', wParam, lParam)
    elif message == WM_ACTIVATE:
        if not (wParam == WA_ACTIVE and wParam == WA_CLICKACTIVE):
            ctypes.windll.user32.ClipCursor(0)
    elif message == WM_SYSCOMMAND:
        if wParam == SC_KEYMENU:
            return 0
    else:
        if message == WM_ERASEBKGND:
            return 0
        if message == WM_KEYDOWN:
            if OnKeyDown is not None and callable(OnKeyDown):
                OnKeyDown(wParam)
        elif message == WM_KEYUP:
            if OnKeyUp is not None and callable(OnKeyUp):
                OnKeyUp(wParam)
        elif message == WM_CHAR:
            if OnChar is not None and callable(OnChar):
                OnChar(wParam)
    if uilib is not None:
        try:
            return int(uilib.OnAppEvent(message, wParam, lParam))
        except:
            import traceback
            traceback.print_exc()

        return 0
    else:
        return ctypes.windll.user32.DefWindowProcA(ctypes.c_int(hwnd), ctypes.c_int(message), ctypes.c_int(wParam), ctypes.c_int(lParam))