def Initialize(self, scene): self.uiBackdropScene = trinity.Tr2Sprite2dScene() self.uiBackdropScene.isFullscreen = True self.uiBackdropScene.backgroundColor = (0, 0, 0, 1) self.characterRenderJob.Set2DBackdropScene(self.uiBackdropScene) self.primaryJob = SceneContext(scene=scene, renderJob=self.fisRenderJob)
def CreateSceneWithUI(): del trinity.renderJobs.recurring[:] scene2d = trinity.Tr2Sprite2dScene() scene2d.width = 512 scene2d.height = 512 scene2d.clearBackground = True scene2d.isFullScreen = False tex = trinity.Tr2RenderTarget(512, 512, 1, trinity.PIXEL_FORMAT.B8G8R8A8_UNORM) scene, screen = CreateScene3d(trinity.TriTextureRes(tex)) scene2d.translation = screen.translation scene2d.rotation = screen.rotation scene2d.scaling = screen.scaling SetupAnimation(scene2d) rj = trinity.CreateRenderJob() rj.name = 'Scene with UI' rj.Update(scene).name = 'Update 3D scene' rj.Update(scene2d).name = 'Update 2D scene' rj.SetPushRenderTarget(tex).name = 'Set texture as render target' rj.RenderScene(scene2d).name = 'Render 2D scene' rj.SetPopRenderTarget().name = 'Set framebuffer as render target' rj.RenderScene(scene).name = 'Render 3D scene' rj.ScheduleRecurring() picker = Scene2dPicker(scene2d) trinity.device.tickInterval = 0
def Show(self, width=800, height=600): displayMode = trinity.adapters.GetCurrentDisplayMode(0) trinity.app.width = width trinity.app.height = height trinity.app.left = (displayMode.width - trinity.app.width) / 2 trinity.app.top = (displayMode.height - trinity.app.height) / 2 trinity.app.windowed = True trinity.app.AdjustWindowForChange(True, True) trinity.app.Create() pp = { 'BackBufferWidth': trinity.app.width, 'BackBufferHeight': trinity.app.height, 'Windowed': True, 'EnableAutoDepthStencil': True, 'AutoDepthStencilFormat': trinity.DEPTH_STENCIL_FORMAT.D24S8, 'BackBufferFormat': trinity.PIXEL_FORMAT.B8G8R8A8_UNORM, 'PresentationInterval': trinity.PRESENT_INTERVAL.IMMEDIATE } trinity.app.ChangeDevice(0, 0, 0, pp) self.renderjob = trinity.CreateRenderJob('LoadingScreen') scene = trinity.Tr2Sprite2dScene() scene.isFullscreen = True scene.clearBackground = True scene.backgroundColor = (0, 0, 0, 0) self.renderjob.Update(scene) self.renderjob.RenderScene(scene) self.renderjob.ScheduleRecurring() sprite = trinity.Tr2Sprite2d() sprite.displayWidth = 32 sprite.displayHeight = 32 sprite.spriteEffect = trinity.TR2_SFX_FILL sprite.color = (1, 1, 1, 1) scene.children.append(sprite) def loading_screen(): x = 100 dx = 4 y = height * 2 / 3 while self.active: sprite.displayX = x sprite.displayY = y x += dx if x > width - 100 - sprite.displayWidth: dx = -dx if x < 100: dx = -dx blue.synchro.Yield() self.active = True uthread2.StartTasklet(loading_screen) blue.os.Pump() blue.os.Pump() blue.os.Pump()
def GetPortraitTexture(self, portraitID): size = 512 sceneManager = sm.GetService('sceneManager') scene = sceneManager.GetActiveScene() backdropPath = self.backdropPath if backdropPath: backdropScene = trinity.Tr2Sprite2dScene() backdropScene.displayWidth = size backdropScene.displayHeight = size sprite = trinity.Tr2Sprite2d() sprite.texturePrimary = trinity.Tr2Sprite2dTexture() sprite.texturePrimary.resPath = backdropPath sprite.displayWidth = size sprite.displayHeight = size backdropScene.children.append(sprite) target = trinity.Tr2RenderTarget(size, size, 1, trinity.PIXEL_FORMAT.B8G8R8X8_UNORM) depth = trinity.Tr2DepthStencil(size, size, trinity.DEPTH_STENCIL_FORMAT.AUTO) renderJob = trinity.CreateRenderJob('TakeSnapShot') renderJob.PushRenderTarget(target) renderJob.PushDepthStencil(depth) projection = trinity.TriProjection() projection.PerspectiveFov(self.camera.fieldOfView, 1, 0.1, 5.0) view = self.camera.viewMatrix renderJob.Clear((0.0, 0.0, 0.0, 1.0), 1.0) renderJob.SetProjection(projection) renderJob.SetView(view) if backdropPath: renderJob.Update(backdropScene) renderJob.RenderScene(backdropScene) renderJob.RenderScene(scene) trinity.WaitForResourceLoads() renderJob.PopDepthStencil() renderJob.PopRenderTarget() renderJob.ScheduleOnce() renderJob.WaitForFinish() filename = self.GetPortraitSnapshotPath(portraitID) trinity.Tr2HostBitmap(target).Save(filename) path = 'cache:/Pictures/Portraits/PortraitSnapshot_%s_%s.jpg' % ( portraitID, session.userid) blue.motherLode.Delete(path) tex = blue.resMan.GetResource(path, 'atlas') return tex
def CreateRenderJob(size, view, projection, bgColor=None, transparent=False, postProcessingQuality=2, antiAliasingQuality=3): """ Creates a Jessica render job and adds functionality for 2D sprite background and overlays. """ def _GetRenderStepPosition(renderJob, name): for i, each in enumerate(renderJob.steps): if each.name == name: return i return i if transparent: clearColor = bgColor or (0.0, 0.0, 0.0, 0.0) format = trinity.PIXEL_FORMAT.B8G8R8A8_UNORM else: clearColor = bgColor or (0.0, 0.0, 0.0, 1.0) format = trinity.PIXEL_FORMAT.B8G8R8X8_UNORM rt = trinity.Tr2RenderTarget(size, size, 1, format) rt.name = 'MyRT' ds = trinity.Tr2DepthStencil() ds.Create(size, size, trinity.DEPTH_STENCIL_FORMAT.D24S8, 0, 0) ds.name = 'MyDS' vp = trinity.TriViewport() vp.width = size vp.height = size renderJob = CreateJessicaSpaceRenderJob() renderJob.updateJob = None renderJob.CreateBasicRenderSteps() renderJob.OverrideSettings('hdrEnabled', True) settings = renderJob.GetSettings() settings['postProcessingQuality'] = postProcessingQuality settings['aaQuality'] = antiAliasingQuality renderJob.SetSettings(settings) renderJob.SetClearColor(clearColor) renderJob.OverrideSettings('bbFormat', format) renderJob.SetActiveCamera(view=view, projection=projection) renderJob.SetViewport(vp) renderJob.OverrideBuffers(rt, ds) renderJob.Enable(False) bgStep = trinity.TriStepRenderScene() bgStep.name = 'BACKGROUND_SPRITE' bgSprite1 = CreateSprite(1.0, size) bgSprite2 = CreateSprite(1.0, size) bgSpriteScene = trinity.Tr2Sprite2dScene() bgSpriteScene.children.append(bgSprite1) bgSpriteScene.children.append(bgSprite2) bgStep.scene = bgSpriteScene pos = _GetRenderStepPosition(renderJob, 'CLEAR') renderJob.steps.insert(pos + 1, bgStep) setattr(renderJob, 'iconTexture', bgSprite1.texturePrimary) setattr(renderJob, 'backgroundTexture', bgSprite2.texturePrimary) oStep = trinity.TriStepRenderScene() oStep.name = 'OVERLAY_SPRITES' oSprite1 = CreateSprite(1.0, size) oSprite1.blendMode = 2 oSprite2 = CreateSprite(16.0 / size, size) oSpriteScene = trinity.Tr2Sprite2dScene() oSpriteScene.children.append(oSprite1) oSpriteScene.children.append(oSprite2) oStep.scene = oSpriteScene pos2 = _GetRenderStepPosition(renderJob, 'END_RENDERING') renderJob.steps.insert(pos2 + 1, oStep) setattr(renderJob, 'overlayTexture', oSprite1.texturePrimary) setattr(renderJob, 'techTexture', oSprite2.texturePrimary) setattr(renderJob, 'renderTarget', rt) return renderJob