Ejemplo n.º 1
0
def RunEx(bus):
    debug.Debug("RunEx()")

    try:
        Run(bus)
    except Exception as e:
        debug.ExceptionInfo(e)
        return "Run error: %s" % e

    return None
Ejemplo n.º 2
0
    def execute(self, context):
        debug.PrintInfo('Executing operator: "%s"' % self.bl_label)

        VRayScene = context.scene.vray
        VRayConverter = VRayScene.VRayConverter

        try:
            if VRayConverter.convert_from == 'INTERNAL':
                convert.convert_bi()
            convert.ConvertScene(context.scene)
        except Exception as e:
            debug.ExceptionInfo(e)
            self.report({'ERROR'}, "%s" % e)
            return {'CANCELLED'}

        return {'FINISHED'}
Ejemplo n.º 3
0
    def execute(self, context):
        VRayScene = context.scene.vray
        BatchBake = VRayScene.BatchBake
        VRayBake = VRayScene.BakeView

        # Copy selection
        selection = [ob for ob in context.selected_objects]

        formatDict = LibUtils.GetDefFormatDict()

        obList = None
        if BatchBake.work_mode == 'SELECTION':
            obList = selection
        elif BatchBake.work_mode == 'LIST':
            obList = [
                item.ob for item in BatchBake.list_items
                if item.use and item.ob
            ]

        numObjects = len(obList)

        # Backup some settings
        ValueBackup(VRayScene.SettingsOutput, 'img_dir')
        ValueBackup(VRayScene.SettingsOutput, 'img_file')
        ValueBackup(VRayScene.Exporter, 'autoclose')
        ValueBackup(VRayScene.Exporter, 'auto_save_render')

        if numObjects:
            VRayScene.Exporter.auto_save_render = True

            # We have to wait for render end
            # only if baking multiple objects
            if numObjects > 1:
                VRayScene.Exporter.wait = True
                VRayScene.Exporter.autoclose = True

            try:
                for ob in obList:
                    debug.PrintInfo("Baking: %s..." % ob.name)
                    VRayScene.Exporter.currentBakeObject = ob

                    # UV channel to use for baking
                    uv_channel = None

                    # Find UV map index
                    if BatchBake.uv_map == 'UV_DEFAULT':
                        if len(ob.data.uv_layers):
                            uv_channel = 0

                    elif BatchBake.uv_map == 'UV_VRAYBAKE':
                        uv_channel = GetUVChannelIndex(ob, "VRayBake")

                    # Add projection if need
                    elif BatchBake.uv_map.startswith('UV_NEW_'):
                        uvName = None
                        if BatchBake.uv_map == 'UV_NEW_SMART':
                            uvName = "VRayBakeSmart"
                        elif BatchBake.uv_map == 'UV_NEW_LM':
                            uvName = "VRayBakeLightmap"

                        uv_channel = GetUVChannelIndex(ob, uvName)
                        if uv_channel is None:
                            if ob.mode in {'EDIT'}:
                                bpy.ops.object.mode_set(mode='OBJECT')

                            bpy.ops.object.select_all(action='DESELECT')

                            ob.select = True
                            context.scene.objects.active = ob

                            if BatchBake.uv_map == 'UV_NEW_SMART':
                                bpy.ops.object.mode_set(mode='EDIT')
                                bpy.ops.mesh.select_all(action='SELECT')

                                layer = ob.data.uv_textures.new(name=uvName)
                                layer.active = True

                                bpy.ops.uv.smart_project(
                                    angle_limit=BatchBake.smart_uv.angle_limit,
                                    island_margin=BatchBake.smart_uv.
                                    island_margin,
                                    user_area_weight=BatchBake.smart_uv.
                                    user_area_weight,
                                )

                                bpy.ops.mesh.select_all(action='DESELECT')
                                bpy.ops.object.mode_set(mode='OBJECT')

                            elif BatchBake.uv_map == 'UV_NEW_LM':
                                bpy.ops.uv.lightmap_pack(
                                    PREF_CONTEXT='ALL_FACES',
                                    PREF_NEW_UVLAYER=True,
                                    PREF_BOX_DIV=BatchBake.lightmap_uv.
                                    PREF_BOX_DIV,
                                    PREF_MARGIN_DIV=BatchBake.lightmap_uv.
                                    PREF_MARGIN_DIV,
                                )
                                ob.data.uv_textures[-1].name = uvName

                            uv_channel = len(ob.data.uv_textures) - 1

                    if uv_channel is None:
                        debug.PrintError("UV Map is not found!")
                        continue

                    # Bake settings
                    VRayScene.BakeView.bake_node = ob.name
                    VRayScene.BakeView.uv_channel = uv_channel

                    # Setup vars
                    formatDict['$O'] = ("Object Name",
                                        LibUtils.CleanString(ob.name,
                                                             stripSigns=False))

                    # Render
                    VRayScene.SettingsOutput.img_file = LibUtils.FormatName(
                        BatchBake.output_filename, formatDict)
                    VRayScene.SettingsOutput.img_dir = LibUtils.FormatName(
                        BatchBake.output_dirpath, formatDict)

                    bpy.ops.render.render()

            except Exception as e:
                debug.PrintError("Erorr baking objects!")
                debug.ExceptionInfo(e)

        # Restore selection
        for ob in selection:
            ob.select = True

        RestoreSettings(context.scene)

        return {'FINISHED'}
Ejemplo n.º 4
0
def ExportEx(bus):
    debug.Debug("ExportEx()")

    err = None

    scene = bus['scene']
    engine = bus['engine']
    o = bus['output']

    VRayScene = scene.vray
    VRayExporter = VRayScene.Exporter
    VRayDR = VRayScene.VRayDR

    pm = VRayFilePaths()

    # Setting user defined value here
    # It could be overriden in 'initFromScene'
    # depending on VRayDR settings
    pm.setSeparateFiles(VRayExporter.useSeparateFiles)

    pm.initFromScene(engine, scene)
    pm.printInfo()

    fm = VRayExportFiles(pm)
    fm.setOverwriteGeometry(VRayExporter.auto_meshes)

    try:
        fm.init()
    except Exception as e:
        debug.ExceptionInfo(e)
        return "Error initing files!"

    o.setFileManager(fm)
    o.setPreview(engine.is_preview)

    bus['exporter'] = exp_init.InitExporter(bus)

    try:
        # We do everything here basically because we want to close files
        # if smth goes wrong...
        rtExporter = HAS_VB35 and engine.bl_idname == 'VRAY_RENDER_RT'
        if not rtExporter:
            err = Export(bus, scene, engine, engine.is_preview)
        else:
            if not VRayExporter.animation_mode in {'NONE', 'CAMERA_LOOP'}:
                o.setAnimation(True)
                o.setFrameStart(scene.frame_start)
                o.setFrameEnd(scene.frame_end)
                o.setFrameStep(scene.frame_step)
            elif VRayExporter.animation_mode == 'CAMERA_LOOP':
                cameraCount = len([
                    1 for o in scene.objects
                    if o.type == 'CAMERA' and o.data.vray.use_camera_loop
                ])
                o.setAnimation(True)
                o.setFrameStart(1)
                o.setFrameEnd(cameraCount)
                o.setFrameStep(1)

            init = {
                'context': bpy.context.as_pointer(),
                'engine': engine.as_pointer(),
                'data': bpy.data.as_pointer(),
                'scene': scene.as_pointer(),
                'mainFile': fm.getFileByPluginType('MAIN'),
                'objectFile': fm.getFileByPluginType('OBJECT'),
                'envFile': fm.getFileByPluginType('WORLD'),
                'geometryFile': fm.getFileByPluginType('GEOMETRY'),
                'lightsFile': fm.getFileByPluginType('LIGHT'),
                'materialFile': fm.getFileByPluginType('MATERIAL'),
                'textureFile': fm.getFileByPluginType('TEXTURE'),
                'cameraFile': fm.getFileByPluginType('CAMERA'),
            }

            # Free anything we have
            if engine.renderer:
                del engine.renderer

            renderer = _vray_for_blender_rt.init(**init)
            if renderer:
                # Write settings for new exporter.
                # TODO: Move this to cpp.
                exp_settings.ExportSettings(bus)

                setattr(engine, 'renderer', renderer)

                _vray_for_blender_rt.render(renderer)

    except Exception as e:
        debug.ExceptionInfo(e)
        err = str(e)
    finally:
        exp_init.ShutdownExporter(bus)
        o.done()

    return err