Exemple #1
0
    def submitCmd(self):
        VRayPreferences = bpy.context.user_preferences.addons[
            'vb30'].preferences

        cmd = [VRayPreferences.vray_cloud_binary, "job", "submit"]

        cmd.append("--project")
        cmd.append(self.project)

        cmd.append("--name")
        cmd.append(LibUtils.FormatName(self.name))

        cmd.append("--sceneFile")
        cmd.append(self.sceneFile)

        cmd.append("--renderMode")
        cmd.append(self.renderMode)

        cmd.append("--width")
        cmd.append(str(self.width))

        cmd.append("--height")
        cmd.append(str(self.height))

        if self.animation:
            cmd.append("--animation")

            cmd.append("--frameRange")
            cmd.append(self.frameRange)

            cmd.append("--frameStep")
            cmd.append(str(self.frameStep))

        if self.ignoreWarnings:
            cmd.append("--ignoreWarnings")

        return cmd
Exemple #2
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'}