Пример #1
0
    def renderFacsPicture(self,
                          dir_images=None,
                          pic_file=None,
                          pic_file_reverse=None):
        #self.facs_human.applyAllTargets()
        #self.refreshAuSmoothSetting()
        self.renderingWidth = '500'
        self.renderingHeight = '500'

        self.grabPath = mh.getPath('grab')
        #log.message('self.grabPath = %s', self.grabPath)
        grabName = datetime.datetime.now().strftime(
            'grab_%Y-%m-%d_%H.%M.%S.png')
        pic_file = os.path.join(self.grabPath, 'test', grabName)

        img_width, img_height = int(self.renderingWidth), int(
            self.renderingHeight)
        glmodule.draw(False)
        img = glmodule.renderToBuffer(img_width, img_height)
        #log.message('img type = %s'. type(img))
        alphaImg = glmodule.renderAlphaMask(int(img_width), int(img_height))
        img = imgop.addAlpha(img, imgop.getChannel(alphaImg, 0))
        img = img.toQImage()
        img.save(pic_file)
        log.message("Image saved to %s", pic_file)
        del alphaImg
        del img
    def renderSurveyImg(self,
                        i4,
                        i7,
                        i9,
                        i10,
                        dir_images=None,
                        pic_file=None,
                        pic_file_reverse=None):
        self.facs_human.applyAllTargets()
        self.refreshAuSmoothSetting()

        grabPath = mh.getPath('grab')
        if not os.path.exists(grabPath):
            os.makedirs(grabPath)

        if pic_file is not None:
            dir_pic_file = os.path.join(grabPath, dir_images)
            pic_file = pic_file + '.png'
            pic_file = os.path.join(dir_pic_file, pic_file)
            if pic_file_reverse is not None:
                pic_file_reverse = pic_file_reverse + '.png'
                pic_file_reverse = os.path.join(dir_pic_file, pic_file_reverse)
        else:
            grabName = str(i4) + str(i7) + str(i9) + str(i10) + '.png'
            pic_file = os.path.join(grabPath, grabName)

        if self.renderingWidth == '' or self.renderingHeight == '':
            G.app.prompt('Warning', 'Nothing to render check the image size.',
                         'Ok')
        else:
            img_width, img_height = 2000, 2000  #int(self.renderingWidth), int(self.renderingHeight)
            glmodule.draw(False)
            img = glmodule.renderToBuffer(img_width, img_height)
            alphaImg = glmodule.renderAlphaMask(img_width, img_height)
            img = imgop.addAlpha(img, imgop.getChannel(alphaImg, 0))
            img = img.toQImage()
            if pic_file is not None:
                img.save(pic_file)
                log.message("Image saved to %s", pic_file)
            if pic_file_reverse is not None:
                img.save(pic_file_reverse)
                log.message("Image saved to %s", pic_file_reverse)
            del alphaImg
            del img

            gui3d.app.statusPersist("Image saved to %s", pic_file)
Пример #3
0
def my_render(settings=None):
    if settings is None:
        settings = {'AA': True, 'lightmapSSS': False, 'scene': G.app.scene, 'dimensions': (230, 230)}

    if settings['lightmapSSS']:
        human = G.app.selectedHuman
        material_backup = material.Material(human.material)

        diffuse = imgop.Image(data=human.material.diffuseTexture)
        lmap = projection.mapSceneLighting(settings['scene'], border=human.material.sssRScale)
        lmapG = imgop.blurred(lmap, human.material.sssGScale, 13)
        lmapR = imgop.blurred(lmap, human.material.sssRScale, 13)
        lmap = imgop.compose([lmapR, lmapG, lmap])

        if not diffuse.isEmpty:
            lmap = imgop.resized(lmap, diffuse.width, diffuse.height, filter=image.FILTER_BILINEAR)
            lmap = imgop.multiply(lmap, diffuse)
            lmap.sourcePath = "Internal_Renderer_Lightmap_SSS_Texture"

        human.material.diffuseTexture = lmap
        human.configureShading(diffuse=True)
        human.shadeless = True

    if not mh.hasRenderToRenderbuffer():
        img = mh.grabScreen(0, 0, G.windowWidth, G.windowHeight)
        alphaImg = None
    else:
        width, height = settings['dimensions']
        if settings['AA']:
            width *= 2
            height *= 2

            img = mh.renderToBuffer(width, height)
            alphaImg = mh.renderAlphaMask(width, height)
            img = imgop.addAlpha(img, imgop.getChannel(alphaImg, 0))

        if settings['AA']:
            img = img.resized(width/2, height/2, filter=image.FILTER_BILINEAR)
            img.data[:, :, :] = img.data[:, :, (2, 1, 0, 3)]

    if settings['lightmapSSS']:
        human.material = material_backup

    return img
Пример #4
0
def Render(settings):
    progress = Progress.begin()

    if not mh.hasRenderToRenderbuffer():
        settings['dimensions'] = (G.windowWidth, G.windowHeight)

    if settings['lightmapSSS']:
        progress(0, 0.05, "Storing data")
        import material
        human = G.app.selectedHuman
        materialBackup = material.Material(human.material)

        progress(0.05, 0.1, "Projecting lightmaps")
        diffuse = imgop.Image(data=human.material.diffuseTexture)
        lmap = projection.mapSceneLighting(settings['scene'],
                                           border=human.material.sssRScale)
        progress(0.1, 0.4, "Applying medium scattering")
        lmapG = imgop.blurred(lmap, human.material.sssGScale, 13)
        progress(0.4, 0.7, "Applying high scattering")
        lmapR = imgop.blurred(lmap, human.material.sssRScale, 13)
        lmap = imgop.compose([lmapR, lmapG, lmap])
        if not diffuse.isEmpty:
            progress(0.7, 0.8, "Combining textures")
            lmap = imgop.resized(lmap,
                                 diffuse.width,
                                 diffuse.height,
                                 filter=image.FILTER_BILINEAR)
            progress(0.8, 0.9)
            lmap = imgop.multiply(lmap, diffuse)
        lmap.sourcePath = "Internal_Renderer_Lightmap_SSS_Texture"

        progress(0.9, 0.95, "Setting up renderer")
        human.material.diffuseTexture = lmap
        human.configureShading(diffuse=True)
        human.shadeless = True
        progress(0.95, 0.98, None)
    else:
        progress(0, 0.99, None)

    if not mh.hasRenderToRenderbuffer():
        # Limited fallback mode, read from screen buffer
        log.message("Fallback render: grab screen")
        img = mh.grabScreen(0, 0, G.windowWidth, G.windowHeight)
        alphaImg = None
    else:
        # Render to framebuffer object
        renderprog = Progress()
        renderprog(0, 0.99 - 0.59 * settings['AA'], "Rendering")
        width, height = settings['dimensions']
        log.message("Rendering at %sx%s", width, height)
        if settings['AA']:
            width = width * 2
            height = height * 2
        img = mh.renderToBuffer(width, height)
        alphaImg = mh.renderAlphaMask(width, height)
        img = imgop.addAlpha(img, imgop.getChannel(alphaImg, 0))

        if settings['AA']:
            renderprog(0.4, 0.99, "AntiAliasing")
            # Resize to 50% using bi-linear filtering
            img = img.resized(width / 2,
                              height / 2,
                              filter=image.FILTER_BILINEAR)
            # TODO still haven't figured out where components get swapped, but this hack appears to be necessary
            img.data[:, :, :] = img.data[:, :, (2, 1, 0, 3)]
        renderprog.finish()

    if settings['lightmapSSS']:
        progress(0.98, 0.99, "Restoring data")
        human.material = materialBackup

    progress(1, None, 'Rendering complete')

    gui3d.app.getCategory('Rendering').getTaskByName('Viewer').setImage(img)
    mh.changeTask('Rendering', 'Viewer')
    gui3d.app.statusPersist('Rendering complete')
Пример #5
0
def Render(settings):
    progress = Progress.begin()

    if not mh.hasRenderToRenderbuffer():
        settings['dimensions'] = (G.windowWidth, G.windowHeight)

    if settings['lightmapSSS']:
        progress(0, 0.05, "Storing data")
        import material
        human = G.app.selectedHuman
        materialBackup = material.Material(human.material)

        progress(0.05, 0.1, "Projecting lightmaps")
        diffuse = imgop.Image(data=human.material.diffuseTexture)
        lmap = projection.mapSceneLighting(settings['scene'],
                                           border=human.material.sssRScale)
        progress(0.1, 0.4, "Applying medium scattering")
        lmapG = imgop.blurred(lmap, human.material.sssGScale, 13)
        progress(0.4, 0.7, "Applying high scattering")
        lmapR = imgop.blurred(lmap, human.material.sssRScale, 13)
        lmap = imgop.compose([lmapR, lmapG, lmap])
        if not diffuse.isEmpty:
            progress(0.7, 0.8, "Combining textures")
            lmap = imgop.resized(lmap, diffuse.width, diffuse.height)
            progress(0.8, 0.9)
            lmap = imgop.multiply(lmap, diffuse)
        lmap.sourcePath = "Internal_Renderer_Lightmap_SSS_Texture"

        progress(0.9, 0.95, "Setting up renderer")
        human.material.diffuseTexture = lmap
        human.mesh.configureShading(diffuse=True)
        human.mesh.shadeless = True
        progress(0.95, 0.98, None)
    else:
        progress(0, 0.99, None)

    if not mh.hasRenderToRenderbuffer():
        # Limited fallback mode, read from screen buffer
        log.message("Fallback render: grab screen")
        img = mh.grabScreen(0, 0, G.windowWidth, G.windowHeight)
        alphaImg = None
    else:
        # Render to framebuffer object
        renderprog = Progress()
        renderprog(0, 0.99 - 0.59 * settings['AA'], "Rendering")
        width, height = settings['dimensions']
        log.message("Rendering at %sx%s", width, height)
        if settings['AA']:
            width = width * 2
            height = height * 2
        img = mh.renderToBuffer(width, height)
        alphaImg = mh.renderAlphaMask(width, height)
        img = imgop.addAlpha(img, imgop.getChannel(alphaImg, 0))

        if settings['AA']:
            renderprog(0.4, 0.99, "AntiAliasing")
            # Resize to 50% using Qt image class
            qtImg = img.toQImage()
            del img
            # Bilinear filtered resize for anti-aliasing
            scaledImg = qtImg.scaled(
                width / 2,
                height / 2,
                transformMode=gui.QtCore.Qt.SmoothTransformation)
            del qtImg
            img = scaledImg
            #img = image.Image(scaledImg)    # Convert back to MH image
            #del scaledImg
        renderprog.finish()

    if settings['lightmapSSS']:
        progress(0.98, 0.99, "Restoring data")
        human.material = materialBackup

    progress(1, None, 'Rendering complete')

    gui3d.app.getCategory('Rendering').getTaskByName('Viewer').setImage(img)
    mh.changeTask('Rendering', 'Viewer')
    gui3d.app.statusPersist('Rendering complete.')
Пример #6
0
def Render(settings):
    progress = Progress.begin()
    
    if not mh.hasRenderToRenderbuffer():
        settings['dimensions'] = (G.windowWidth, G.windowHeight)

    if settings['lightmapSSS']:
        progress(0, 0.05, "Storing data")
        import material
        human = G.app.selectedHuman
        materialBackup = material.Material(human.material)

        progress(0.05, 0.1, "Projecting lightmaps")
        diffuse = imgop.Image(data = human.material.diffuseTexture)
        lmap = projection.mapSceneLighting(
            settings['scene'], border = human.material.sssRScale)
        progress(0.1, 0.4, "Applying medium scattering")
        lmapG = imgop.blurred(lmap, human.material.sssGScale, 13)
        progress(0.4, 0.7, "Applying high scattering")
        lmapR = imgop.blurred(lmap, human.material.sssRScale, 13)
        lmap = imgop.compose([lmapR, lmapG, lmap])
        if not diffuse.isEmpty:
            progress(0.7, 0.8, "Combining textures")
            lmap = imgop.resized(lmap, diffuse.width, diffuse.height, filter=image.FILTER_BILINEAR)
            progress(0.8, 0.9)
            lmap = imgop.multiply(lmap, diffuse)
        lmap.sourcePath = "Internal_Renderer_Lightmap_SSS_Texture"

        progress(0.9, 0.95, "Setting up renderer")
        human.material.diffuseTexture = lmap
        human.configureShading(diffuse = True)
        human.shadeless = True
        progress(0.95, 0.98, None)
    else:
        progress(0, 0.99, None)
        
    if not mh.hasRenderToRenderbuffer():
        # Limited fallback mode, read from screen buffer
        log.message("Fallback render: grab screen")
        img = mh.grabScreen(0, 0, G.windowWidth, G.windowHeight)
        alphaImg = None
    else:
        # Render to framebuffer object
        renderprog = Progress()
        renderprog(0, 0.99 - 0.59 * settings['AA'], "Rendering")
        width, height = settings['dimensions']
        log.message("Rendering at %sx%s", width, height)
        if settings['AA']:
            width = width * 2
            height = height * 2
        img = mh.renderToBuffer(width, height)
        alphaImg = mh.renderAlphaMask(width, height)
        img = imgop.addAlpha(img, imgop.getChannel(alphaImg, 0))

        if settings['AA']:
            renderprog(0.4, 0.99, "AntiAliasing")
            # Resize to 50% using bi-linear filtering
            img = img.resized(width/2, height/2, filter=image.FILTER_BILINEAR)
            # TODO still haven't figured out where components get swapped, but this hack appears to be necessary
            img.data[:,:,:] = img.data[:,:,(2,1,0,3)]
        renderprog.finish()

    if settings['lightmapSSS']:
        progress(0.98, 0.99, "Restoring data")
        human.material = materialBackup

    progress(1, None, 'Rendering complete')

    gui3d.app.getCategory('Rendering').getTaskByName('Viewer').setImage(img)
    mh.changeTask('Rendering', 'Viewer')
    gui3d.app.statusPersist('Rendering complete')