Пример #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
    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)
Пример #3
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.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)
Пример #4
0
    def startScene(self, renderCoords, frameNumber=None):
        self.inputGamma = self.scene.properties["YafRay"]["Renderer"][
            "gammaInput"]
        self.yi.setInputGamma(self.inputGamma, True)

        [sizeX, sizeY, bStartX, bStartY, bsizeX, bsizeY] = renderCoords

        if self.scene.properties["YafRay"]["Renderer"][
                "output_method"] == "XML":
            co = yafrayinterface.imageOutput_t()
            outputFile = self.getOutputFilename(frameNumber, False)
            outputFile += '.xml'
            self.yi.printInfo("Exporter: Writing XML " + outputFile)
            self.yi.setOutfile(outputFile)
        elif self.scene.properties["YafRay"]["Renderer"][
                "output_method"] == "GUI" and haveQt:
            co = None
            outputFile = self.getOutputFilename(frameNumber)
            outputFile += '.png'
            self.yi.printInfo("Exporter: Rendering to " + outputFile)
        else:
            outputFile = self.getOutputFilename(frameNumber)

            format = self.yi.getImageFormatFromFullName(
                self.scene.properties["YafRay"]["Renderer"]["file_type"])
            outputFile += '.' + format

            self.yi.paramsClearAll()
            self.yi.paramsSetString("type", format)
            self.yi.paramsSetInt("width", sizeX)
            self.yi.paramsSetInt("height", sizeY)
            self.yi.paramsSetBool("alpha_channel", False)
            self.yi.paramsSetBool(
                "z_channel",
                self.scene.properties["YafRay"]["Renderer"]["z_channel"])

            ih = self.yi.createImageHandler("outFile")
            co = yafrayinterface.imageOutput_t(ih, outputFile, bStartX,
                                               bStartY)

            self.yi.printInfo("Exporter: Rendering to file " + outputFile)

        self.yi.startScene()

        return [co, outputFile]
Пример #5
0
    def render(self, scene):
        
        if scene.name != 'preview':
            
            #scene.set_frame(scene.frame_current)
            scene.update()
            self.scene = scene
        
            r = scene.render
 

            # compute resolution
            x= int(r.resolution_x*r.resolution_percentage*0.01)
            y= int(r.resolution_y*r.resolution_percentage*0.01)
        
            self.setInterface(yafrayinterface.yafrayInterface_t())
                        
            
            outputFile,output,file_type = self.decideOutputFileName(r.filepath, r.file_format)
                        
            self.yi.paramsClearAll()
            self.yi.paramsSetString("type", file_type)
            self.yi.paramsSetInt("width", x)
            self.yi.paramsSetInt("height", y)
            self.yi.paramsSetBool("alpha_channel", False)
            self.yi.paramsSetBool("z_channel", scene.gs_z_channel)
                        
            ih = self.yi.createImageHandler("outFile")
            co = yafrayinterface.imageOutput_t(ih, outputFile, 0, 0)
                        
            self.yi.printInfo("Exporter: Rendering to file " + outputFile)
                
            self.yi.startScene()
            
            
            self.exportObjects()
            self.configureRender()
            
            
            # get a render result to write into
            result = self.begin_result(0, 0, x, y)
            lay = result.layers[0]
            
            # here we export blender scene and renders using yafaray
            
            self.update_stats("", "Rendering to %s" % outputFile)
            print("Rendering to %s" % outputFile)
            
            self.yi.render(co)
            
            if scene.gs_z_channel:
                lay.load_from_file(output + '_zbuffer.' + file_type)
            else:
                lay.load_from_file(outputFile)
            # done
            self.end_result(result)
            self.update_stats("", "Done!")
	def startScene(self, renderCoords, frameNumber = None):
		self.inputGamma = self.scene.properties["YafRay"]["Renderer"]["gammaInput"]
		self.yi.setInputGamma(self.inputGamma, True)

		[sizeX, sizeY, bStartX, bStartY, bsizeX, bsizeY] = renderCoords

		if self.scene.properties["YafRay"]["Renderer"]["output_method"] == "XML":
			co = yafrayinterface.imageOutput_t()
			outputFile = self.getOutputFilename(frameNumber, False)
			outputFile += '.xml'
			self.yi.printInfo("Exporter: Writing XML " + outputFile)
			self.yi.setOutfile(outputFile)
		elif self.scene.properties["YafRay"]["Renderer"]["output_method"] == "GUI" and haveQt:
			co = None
			outputFile = self.getOutputFilename(frameNumber)
			outputFile += '.png'
			self.yi.printInfo("Exporter: Rendering to " + outputFile)
		else:
			outputFile = self.getOutputFilename(frameNumber)
			
			format = self.yi.getImageFormatFromFullName(self.scene.properties["YafRay"]["Renderer"]["file_type"])
			outputFile += '.' + format
			
			self.yi.paramsClearAll()
			self.yi.paramsSetString("type", format)
			self.yi.paramsSetInt("width", sizeX)
			self.yi.paramsSetInt("height", sizeY)
			self.yi.paramsSetBool("alpha_channel", False)
			self.yi.paramsSetBool("z_channel", self.scene.properties["YafRay"]["Renderer"]["z_channel"])
			
			ih = self.yi.createImageHandler("outFile")
			co = yafrayinterface.imageOutput_t(ih, outputFile, bStartX, bStartY)
			
			self.yi.printInfo("Exporter: Rendering to file " + outputFile)
		
		self.yi.startScene()
		
		return [co, outputFile]
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()
Пример #8
0
    def render(self, scene):

        self.preview = (scene.name == "preview")

        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())

        if scene.gs_type_render == "file":
            outputFile, output, file_type = self.decideOutputFileName(
                r.filepath, r.file_format)
            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)

        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:
                lay.load_from_file(output + '_zbuffer.' + file_type)
            else:
                lay.load_from_file(outputFile)

            self.end_result(result)

        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("",
                                      "%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
                except:
                    pass
                self.update_result(res)

            def flushCallback(*args):
                w, h, tile = args
                res = self.begin_result(0, 0, w, h)
                try:
                    res.layers[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")
                return

        self.update_stats("", "Done!")

        self.yi.clearAll()
        del self.yi
    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
Пример #11
0
    def render(self, scene):
        self.update_stats("", "Setting up render")
            
        scene.frame_set(scene.frame_current)
        self.scene = scene
        r = scene.render

        # compute resolution
        x= int(r.resolution_x*r.resolution_percentage*0.01)
        y= int(r.resolution_y*r.resolution_percentage*0.01)
    
        self.setInterface(yafrayinterface.yafrayInterface_t())
        
        outputFile,output,file_type = self.decideOutputFileName(r.filepath, r.file_format)
                    
        self.yi.paramsClearAll()
        self.yi.paramsSetString("type", file_type)
        self.yi.paramsSetInt("width", x)
        self.yi.paramsSetInt("height", y)
        self.yi.paramsSetBool("alpha_channel", False)
        self.yi.paramsSetBool("z_channel", scene.gs_z_channel)
                    
        self.yi.startScene()
        self.exportObjects()
        self.configureRender()
        
        tag = ""
        progress = 0.0;
        def prog_callback(command, *args):
            global tag, progress
            if command == "tag":
                tag = args[0]
            elif command == "progress":
                progress = args[0]
            self.update_stats("", "%s - %.2f %%" % (tag, progress))
        
        def tile_callback(command, *args):
            if command == "flushArea":
                x0, y0, x1, y1, tile = args
                res = self.begin_result(x0, y0, x1-x0, y1-y0)
                try:
                    res.layers[0].rect = tile
                except BaseException as e:
                    print("Exception in tile callback:", e)
                    print(args, len(tile))
                self.end_result(res)
                
        self.yi.paramsSetString("type", file_type)
        self.yi.paramsSetBool("drawParams", True)
        ih = self.yi.createImageHandler("outFile")
        co = yafrayinterface.imageOutput_t(ih, str(outputFile), 0, 0)
                        
        self.yi.printInfo("Exporter: Rendering to file " + outputFile)
                    
        # get a render result to write into
        result = self.begin_result(0, 0, x, y)
        lay = result.layers[0]
        
        # here we export blender scene and renders using yafaray
        
        self.update_stats("", "Rendering to %s" % outputFile)
        print("Rendering to %s" % outputFile)
        
        self.yi.render(co)
        
        if scene.gs_z_channel:
            lay.load_from_file(output + '_zbuffer.' + file_type)
        else:
            lay.load_from_file(outputFile)
        # done
        self.end_result(result)
        #import threading
        #t = threading.Thread(target=self.yi.render, args=(x, y, tile_callback, prog_callback))
        #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.update_stats("", "Render is aborted")
        #    return
            
        self.update_stats("", "Done!")
Пример #12
0
    def render(self, scene):

        self.preview = (scene.name == "preview")

        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())

        if scene.gs_type_render == "file":
            outputFile, output, file_type = self.decideOutputFileName(r.filepath, r.file_format)
            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)


        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:
                lay.load_from_file(output + '_zbuffer.' + file_type)
            else:
                lay.load_from_file(outputFile)

            self.end_result(result)

        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("", "%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
                except:
                    pass
                self.update_result(res)

            def flushCallback(*args):
                w, h, tile = args
                res = self.begin_result(0, 0, w, h)
                try:
                    res.layers[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")
                return

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