示例#1
0
    def update(self, data, scene):
        self.update_stats("", "Setting up render")
        if not self.is_preview:
            scene.frame_set(scene.frame_current)

        self.scene = scene
        render = scene.render

        fp = bpy.path.abspath(render.filepath)
        fp = os.path.realpath(fp)
        fp = os.path.normpath(fp)

        [
            self.sizeX, self.sizeY, self.bStartX, self.bStartY, self.bsizeX,
            self.bsizeY, camDummy
        ] = yaf_scene.getRenderCoords(scene)

        if render.use_border:
            self.resX = self.bsizeX
            self.resY = self.bsizeY
        else:
            self.resX = self.sizeX
            self.resY = self.sizeY

        if scene.gs_type_render == "file":
            self.setInterface(yafrayinterface.yafrayInterface_t())
            self.yi.setInputGamma(scene.gs_gamma_input, True)
            self.outputFile, self.output, self.file_type = self.decideOutputFileName(
                fp, scene.img_output)
            self.yi.paramsClearAll()
            self.yi.paramsSetString("type", self.file_type)
            self.yi.paramsSetBool("alpha_channel",
                                  render.image_settings.color_mode == "RGBA")
            self.yi.paramsSetBool("z_channel", scene.gs_z_channel)
            self.yi.paramsSetInt("width", self.resX)
            self.yi.paramsSetInt("height", self.resY)
            self.ih = self.yi.createImageHandler("outFile")
            self.co = yafrayinterface.imageOutput_t(self.ih,
                                                    str(self.outputFile), 0, 0)

        elif scene.gs_type_render == "xml":
            self.setInterface(yafrayinterface.xmlInterface_t())
            self.yi.setInputGamma(scene.gs_gamma_input, True)
            self.outputFile, self.output, self.file_type = self.decideOutputFileName(
                fp, 'XML')
            self.yi.paramsClearAll()
            self.co = yafrayinterface.imageOutput_t()
            self.yi.setOutfile(self.outputFile)

        else:
            self.setInterface(yafrayinterface.yafrayInterface_t())
            self.yi.setInputGamma(scene.gs_gamma_input, True)

        self.yi.startScene()
        self.exportScene()
        self.yaf_integrator.exportIntegrator(self.scene)
        self.yaf_integrator.exportVolumeIntegrator(self.scene)

        # must be called last as the params from here will be used by render()
        yaf_scene.exportRenderSettings(self.yi, self.scene)
示例#2
0
文件: scene.py 项目: tpaviot/occray
    def __init__(self, useXML=False):
        self.background = occray.background.ConstantBackground()
        self.renderer = occray.renderer.Renderer()
        self.camera = occray.camera.Perspective()
        self.objects = []
        self.lights = []

        self.haveQt = True
        self.useXML = useXML
        self.renderer.xml = useXML

        if self.useXML:
            self.yi = yafrayinterface.xmlInterface_t()
            outputFile = self.getOutputFilename(None, False)
            outputFile += '.xml'
            self.yi.setOutfile(outputFile)
        else:
            self.yi = yafrayinterface.yafrayInterface_t()

        self.yi.loadPlugins(dllPath)

        self.materials = dict()
        self.materialMap = dict()
        #add default material
        defaultMat = occray.material.Material()
        self.add_material(defaultMat)

        #self.yTexture = yafTexture(self.yi)
        #self.yMaterial = yafMaterial(self.yi, self.materialMap)
        self.inputGamma = 1.0
示例#3
0
    def update(self, data, scene):
        # callback to export the scene
        self.update_stats("", "Setting up render")
        if not self.is_preview:
            scene.frame_set(scene.frame_current)

        self.scene = scene
        render = scene.render

        filePath = bpy.path.abspath(render.filepath)
        filePath = os.path.realpath(filePath)
        filePath = os.path.normpath(filePath)

        [self.sizeX, self.sizeY, self.bStartX, self.bStartY, self.bsizeX, self.bsizeY, camDummy] = tby_scene.getRenderCoords(scene)

        if render.use_border:
            self.resX = self.bsizeX
            self.resY = self.bsizeY
        else:
            self.resX = self.sizeX
            self.resY = self.sizeY
        # render type setup
        if scene.bounty.gs_type_render == "file":
            self.setInterface(yafrayinterface.yafrayInterface_t())
            self.yi.setInputGamma(scene.bounty.gs_gamma_input, scene.bounty.sc_apply_gammaInput)
            self.outputFile, self.output, self.file_type = self.decideOutputFileName(filePath, scene.bounty.img_output)
            self.yi.paramsClearAll()
            self.yi.paramsSetString("type", self.file_type)
            self.yi.paramsSetBool("alpha_channel", render.image_settings.color_mode == "RGBA")
            self.yi.paramsSetBool("z_channel", scene.bounty.gs_z_channel)
            self.yi.paramsSetInt("width", self.resX)
            self.yi.paramsSetInt("height", self.resY)
            self.ih = self.yi.createImageHandler("outFile")
            self.co = yafrayinterface.imageOutput_t(self.ih, str(self.outputFile), 0, 0)

        elif scene.bounty.gs_type_render == "xml":
            self.setInterface(yafrayinterface.xmlInterface_t())
            self.yi.setInputGamma(scene.bounty.gs_gamma_input, scene.bounty.sc_apply_gammaInput)
            self.outputFile, self.output, self.file_type = self.decideOutputFileName(filePath, 'XML')
            self.yi.paramsClearAll()
            self.co = yafrayinterface.imageOutput_t()
            self.yi.setOutfile(self.outputFile)

        else:
            self.setInterface(yafrayinterface.yafrayInterface_t())
            self.yi.setInputGamma(scene.bounty.gs_gamma_input, scene.bounty.sc_apply_gammaInput)

        self.yi.startScene()
        self.exportScene()# to above, line 92
        self.lightIntegrator.exportIntegrator(self.scene.bounty) # lightIntegrator, line 26
        self.lightIntegrator.exportVolumeIntegrator(self.scene)

        # must be called last as the params from here will be used by render()
        tby_scene.exportRenderSettings(self.yi, self.scene)
    def update(self, data, scene):
        self.update_stats("", "Setting up render")
        if not self.is_preview:
            scene.frame_set(scene.frame_current)

        self.scene = scene
        render = scene.render

        fp = bpy.path.abspath(render.filepath)
        fp = os.path.realpath(fp)
        fp = os.path.normpath(fp)

        [self.sizeX, self.sizeY, self.bStartX, self.bStartY, self.bsizeX, self.bsizeY, camDummy] = yaf_scene.getRenderCoords(scene)

        if render.use_border:
            self.x = self.bsizeX
            self.y = self.bsizeY
        else:
            self.x = self.sizeX
            self.y = self.sizeY        

        if scene.gs_type_render == "file":
            self.setInterface(yafrayinterface.yafrayInterface_t())
            self.yi.setInputGamma(scene.gs_gamma_input, True)
            self.outputFile, self.output, self.file_type = self.decideOutputFileName(fp, scene.img_output)
            self.yi.paramsClearAll()
            self.yi.paramsSetString("type", self.file_type)
            self.yi.paramsSetBool("alpha_channel", render.image_settings.color_mode == "RGBA")
            self.yi.paramsSetBool("z_channel", scene.gs_z_channel)
            self.yi.paramsSetInt("width", self.x + self.bStartX)
            self.yi.paramsSetInt("height", self.y + self.bStartY)
            self.ih = self.yi.createImageHandler("outFile")
            self.co = yafrayinterface.imageOutput_t(self.ih, str(self.outputFile), 0, 0)

        elif scene.gs_type_render == "xml":
            self.setInterface(yafrayinterface.xmlInterface_t())
            self.yi.setInputGamma(scene.gs_gamma_input, True)
            self.outputFile, self.output, self.file_type = self.decideOutputFileName(fp, 'XML')
            self.yi.paramsClearAll()
            self.co = yafrayinterface.imageOutput_t()
            self.yi.setOutfile(self.outputFile)

        else:
            self.setInterface(yafrayinterface.yafrayInterface_t())
            self.yi.setInputGamma(scene.gs_gamma_input, True)

        self.yi.startScene()
        self.exportScene()
        self.yaf_integrator.exportIntegrator(self.scene)
        self.yaf_integrator.exportVolumeIntegrator(self.scene)

        # must be called last as the params from here will be used by render()
        yaf_scene.exportRenderSettings(self.yi, self.scene)
def yafarayRenderer(obj, app, settings):
    """
  This function exports data in a format that can be used to reconstruct the humanoid 
  object in YafaRay. It supports a range of options that can be specified in the Python 
  script file mh2yafaray_ini.py, which is reloaded each time this function is run. This 
  enables these options to be changed while the MakeHuman application is still running.
  
  Parameters
  ----------
  
  obj:
      *3D object*. The object to export. This should be the humanoid object with
      uv-mapping data and Face Groups defined.

  camera:
      *Camera object*. The camera to render from 
  
  """

    print 'YafaRay Export of object: ', obj.name

    # Read settings from an ini file. This reload enables the settings to be
    # changed dynamically without forcing the user to restart the MH
    # application for the changes to take effect.
  
    camera = app.modelCamera
    resolution = (app.settings.get('rendering_width', 800), app.settings.get('rendering_height', 600))

    reload(mh2yafaray_ini) 
    path = os.path.join(mh.getPath('render'), mh2yafaray_ini.outputpath)
    source = mh2yafaray_ini.source if settings['source'] == 'gui' else settings['source']
    action = mh2yafaray_ini.action 
    lighting = mh2yafaray_ini.lighting if settings['lighting'] == 'dl' else settings['lighting']
    world = mh2yafaray_ini.world if settings['world'] == 'texture' else settings['world']
    image_path = mh2yafaray_ini.yafaray_path 
        
    if action == 'render':
        
        if source == 'xml':
            yi = yafrayinterface.xmlInterface_t()
        else:
            yi = yafrayinterface.yafrayInterface_t()
            yi.loadPlugins(mh2yafaray_ini.PLUGIN_PATH)
        
        #--
        yi.startScene()
        
        #-- texture ----
        yafarayTexture(yi, image_path)
                
        #-- create material ----
        yafarayMaterial(yi)
             
        #-- lights ----
        yafarayLights(yi)
                
        #-- geometry ----
        yafarayGeometry(yi, obj)

        #-- create cam ----
        yafarayCameraData(yi, camera, resolution)
        
        #-- background ----
        yafarayBackground(yi, world)
        
        #-- integrator ----
        yafarayIntegrators(yi, lighting)
        
        #-- output ----
        if source == 'console':
            
            yi.paramsClearAll()
            path_net = str(path).replace("\"","/") # use / for campatibility by Unix systems ?
            file_type = 'tga' # To do; create option in GUI ?
            yi.paramsSetString("type", file_type)
            yi.paramsSetBool("alpha_channel", False)
            yi.paramsSetBool("z_channel", False)
            yi.paramsSetInt("width", resolution[0])
            yi.paramsSetInt("height", resolution[1])
            ih = yi.createImageHandler("outFile")
            output = yafrayinterface.imageOutput_t(ih, path_net + 'test.tga', 0, 0) # Todo; revised for Unix systems
        
        #
        if source == 'xml':
            output = yafrayinterface.imageOutput_t()
        
        #-- render options ----
        yafarayRender(yi, resolution)
        
        #-- QT interface ----
        if source == 'gui':
            import yafqt
            yafqt.initGui()
            guiSettings = yafqt.Settings()
            guiSettings.autoSave = False
            guiSettings.closeAfterFinish = False
            guiSettings.mem = None
            #guiSettings.fileName = 'test.png'
            guiSettings.autoSaveAlpha = False
            #-- create render window
            yafqt.createRenderWidget(yi, resolution[0], resolution[1], 0, 0, guiSettings)
        else:
            yi.render(output)
 
        yi.clearAll()
    def render(self, scene):

        self.preview = (scene.name == "preview")
        self.bl_use_postprocess = False
        self.update_stats("", "Setting up render")

        if not self.preview:
            scene.frame_set(scene.frame_current)

        self.scene = scene
        r = scene.render

        [sizeX, sizeY, bStartX, bStartY, bsizeX, bsizeY,
         camDummy] = yaf_scene.getRenderCoords(scene)

        if r.use_border:
            x = bsizeX
            y = bsizeY
        else:
            x = sizeX
            y = sizeY

        self.setInterface(yafrayinterface.yafrayInterface_t())

        self.yi.setInputGamma(scene.gs_gamma_input, True)

        rfilepath = bpy.path.abspath(r.filepath)
        rfilepath = os.path.realpath(rfilepath)
        rfilepath = os.path.normpath(rfilepath)

        if bpy.types.YAFA_RENDER.render_Animation:
            absolute_outpath = os.path.abspath(
                os.path.join(rfilepath, 'yaf_ani')
            )  # output folder for animation imagefiles saving from yafaray
        else:
            absolute_outpath = os.path.abspath(
                os.path.join(rfilepath, 'yaf_tmp')
            )  # output folder for tmp imagefile saving from yafaray

        if scene.gs_type_render == "file":
            outputFile, output, file_type = self.decideOutputFileName(
                absolute_outpath, scene.img_output)
            self.yi.paramsClearAll()
            self.yi.paramsSetString("type", file_type)
            self.yi.paramsSetBool("alpha_channel", r.color_mode == "RGBA")
            self.yi.paramsSetBool("z_channel", scene.gs_z_channel)
            self.yi.paramsSetInt("width", x + bStartX)
            self.yi.paramsSetInt("height", y + bStartY)
            ih = self.yi.createImageHandler("outFile")
            co = yafrayinterface.imageOutput_t(ih, str(outputFile), 0, 0)

        if scene.gs_type_render == "xml":  # Export the Scene to XML File
            absolute_outpath = os.path.abspath(
                os.path.join(rfilepath, 'yaf_xml')
            )  # output folder for xml file saving from yafaray
            outputFile, output, file_type = self.decideOutputFileName(
                absolute_outpath, 'XML')
            self.setInterface(yafrayinterface.xmlInterface_t())
            co = yafrayinterface.imageOutput_t()
            self.yi.setOutfile(outputFile)

        self.yi.startScene()
        self.exportScene()
        self.yaf_integrator.exportIntegrator(self.scene)
        self.yaf_integrator.exportVolumeIntegrator(self.scene)

        yaf_scene.exportRenderSettings(
            self.yi, self.scene
        )  # must be called last as the params from here will be used by render()

        if scene.gs_type_render == "file":
            self.yi.printInfo("Exporter: Rendering to file " + outputFile)
            self.update_stats("", "Rendering to %s" % outputFile)
            self.yi.render(co)
            result = self.begin_result(bStartX, bStartY, x + bStartX,
                                       y + bStartY)
            lay = result.layers[0]

            if scene.gs_z_channel and not scene.img_output == 'OPEN_EXR':  # exr format has z-buffer included, so no need to load '_zbuffer' - file
                lay.load_from_file(output + '_zbuffer.' + file_type)
            else:
                lay.load_from_file(outputFile)

            self.end_result(result)

        if scene.gs_type_render == "xml":  # Export the Scene to XML File
            self.yi.printInfo("Exporter: Writing XML to file " + outputFile)
            self.yi.render(co)

        elif scene.gs_type_render == "into_blender":
            import threading

            def progressCallback(command, *args):
                if not self.test_break():
                    if command == "tag":
                        self.tag = args[0]
                    elif command == "progress":
                        self.prog = args[0]
                    self.update_stats("YafaRay Rendering... ",
                                      "%s - %.2f %%" % (self.tag, self.prog))

            def drawAreaCallback(*args):
                x, y, w, h, tile = args
                res = self.begin_result(x, y, w, h)
                try:
                    res.layers[0].rect = tile
                    #res.layers[0].passes[0].rect = tile
                except:
                    pass
                self.end_result(res)

            def flushCallback(*args):
                w, h, tile = args
                res = self.begin_result(0, 0, w, h)
                try:
                    res.layers[0].rect = tile
                    #res.layers[0].passes[0].rect = tile
                except BaseException as e:
                    pass
                self.end_result(res)

            t = threading.Thread(target=self.yi.render,
                                 args=(sizeX, sizeY, 0, 0, self.preview,
                                       drawAreaCallback, flushCallback,
                                       progressCallback))
            t.start()

            while t.isAlive() and not self.test_break():
                time.sleep(0.2)

            if t.isAlive():
                self.update_stats("", "Aborting...")
                self.yi.abort()
                t.join()
                self.yi.clearAll()
                del self.yi
                self.update_stats("", "Render is aborted")
                self.bl_use_postprocess = True
                return

        self.update_stats("", "Done!")
        self.yi.clearAll()
        del self.yi

        self.bl_use_postprocess = True
    def render(self, scene):

        self.preview = (scene.name == "preview")
        self.bl_use_postprocess = False
        self.update_stats("", "Setting up render")

        if not self.preview:
            scene.frame_set(scene.frame_current)

        self.scene = scene
        r = scene.render

        [sizeX, sizeY, bStartX, bStartY, bsizeX, bsizeY, camDummy] = yaf_scene.getRenderCoords(scene)

        if r.use_border:
            x = bsizeX
            y = bsizeY
        else:
            x = sizeX
            y = sizeY

        self.setInterface(yafrayinterface.yafrayInterface_t())

        self.yi.setInputGamma(scene.gs_gamma_input, True)

        rfilepath = bpy.path.abspath(r.filepath)
        rfilepath = os.path.realpath(rfilepath)
        rfilepath = os.path.normpath(rfilepath)

        if bpy.types.YAFA_RENDER.render_Animation:
            absolute_outpath = os.path.abspath(os.path.join(rfilepath, 'yaf_ani'))  # output folder for animation imagefiles saving from yafaray
        else:
            absolute_outpath = os.path.abspath(os.path.join(rfilepath, 'yaf_tmp'))  # output folder for tmp imagefile saving from yafaray

        if scene.gs_type_render == "file":
            outputFile, output, file_type = self.decideOutputFileName(absolute_outpath, scene.img_output)
            self.yi.paramsClearAll()
            self.yi.paramsSetString("type", file_type)
            self.yi.paramsSetBool("alpha_channel", r.color_mode == "RGBA")
            self.yi.paramsSetBool("z_channel", scene.gs_z_channel)
            self.yi.paramsSetInt("width", x + bStartX)
            self.yi.paramsSetInt("height", y + bStartY)
            ih = self.yi.createImageHandler("outFile")
            co = yafrayinterface.imageOutput_t(ih, str(outputFile), 0, 0)

        if scene.gs_type_render == "xml":  # Export the Scene to XML File
            absolute_outpath = os.path.abspath(os.path.join(rfilepath, 'yaf_xml'))  # output folder for xml file saving from yafaray
            outputFile, output, file_type = self.decideOutputFileName(absolute_outpath, 'XML')
            self.setInterface(yafrayinterface.xmlInterface_t())
            co = yafrayinterface.imageOutput_t()
            self.yi.setOutfile(outputFile)

        self.yi.startScene()
        self.exportScene()
        self.yaf_integrator.exportIntegrator(self.scene)
        self.yaf_integrator.exportVolumeIntegrator(self.scene)

        yaf_scene.exportRenderSettings(self.yi, self.scene)  # must be called last as the params from here will be used by render()

        if scene.gs_type_render == "file":
            self.yi.printInfo("Exporter: Rendering to file " + outputFile)
            self.update_stats("", "Rendering to %s" % outputFile)
            self.yi.render(co)
            result = self.begin_result(bStartX, bStartY, x + bStartX, y + bStartY)
            lay = result.layers[0]

            if scene.gs_z_channel and not scene.img_output == 'OPEN_EXR':  # exr format has z-buffer included, so no need to load '_zbuffer' - file
                lay.load_from_file(output + '_zbuffer.' + file_type)
            else:
                lay.load_from_file(outputFile)

            self.end_result(result)

        if scene.gs_type_render == "xml":  # Export the Scene to XML File
            self.yi.printInfo("Exporter: Writing XML to file " + outputFile)
            self.yi.render(co)

        elif scene.gs_type_render == "into_blender":
            import threading

            def progressCallback(command, *args):
                if not self.test_break():
                    if command == "tag":
                        self.tag = args[0]
                    elif command == "progress":
                        self.prog = args[0]
                    self.update_stats("YafaRay Rendering... ", "%s - %.2f %%" % (self.tag, self.prog))

            def drawAreaCallback(*args):
                x, y, w, h, tile = args
                res = self.begin_result(x, y, w, h)
                try:
                    res.layers[0].rect = tile
                    #res.layers[0].passes[0].rect = tile
                except:
                    pass
                self.end_result(res)

            def flushCallback(*args):
                w, h, tile = args
                res = self.begin_result(0, 0, w, h)
                try:
                    res.layers[0].rect = tile
                    #res.layers[0].passes[0].rect = tile
                except BaseException as e:
                    pass
                self.end_result(res)

            t = threading.Thread(target = self.yi.render,
                                 args = (sizeX, sizeY, 0, 0,
                                 self.preview,
                                 drawAreaCallback,
                                 flushCallback,
                                 progressCallback)
                                 )
            t.start()

            while t.isAlive() and not self.test_break():
                time.sleep(0.2)

            if t.isAlive():
                self.update_stats("", "Aborting...")
                self.yi.abort()
                t.join()
                self.yi.clearAll()
                del self.yi
                self.update_stats("", "Render is aborted")
                self.bl_use_postprocess = True
                return

        self.update_stats("", "Done!")
        self.yi.clearAll()
        del self.yi

        self.bl_use_postprocess = True