Exemplo n.º 1
0
    def execute(self, context):
        preset_menu_class = getattr(bpy.types, self.preset_menu)
        preset_type = preset_menu_class.preset_subdir

        presetSubdir = PathUtils.CreateDirectory(os.path.join(SysUtils.GetUserConfigDir(), "presets"))
        exportPath   = PathUtils.CreateDirectory(os.path.join(presetSubdir, preset_type))

        presetName = preset_menu_class.bl_label if self.remove_active else self.name

        fileName = "%s.vrscene" % LibUtils.CleanString(bpy.path.display_name(presetName))

        outputFilepath = os.path.normpath(os.path.join(exportPath, fileName))

        if self.remove_active:
            # NOTE: Remove function is locked to user config directory,
            # so system settings are safe

            debug.PrintInfo('Removing preset file: "%s"' % outputFilepath)
            if not os.path.exists(outputFilepath):
                return {'CANCELLED'}
            try:
                os.remove(outputFilepath)
            except:
                debug.PrintError('Error removing preset file: "%s"!' % outputFilepath)

            # Set default menu name
            preset_menu_class.bl_label = bpy.path.display_name(preset_type)

        else:
            bus = {
                'output' : VRayStream.VRaySimplePluginExporter(outputFilepath),
                'scene'  : context.scene,
                'camera' : context.scene.camera,
                'preview' : False,
            }

            pluginPresetIDs = None
            if preset_type == 'global':
                pluginPresetIDs = (pID for pID in sorted(PLUGINS['SETTINGS']))
            else:
                pluginPresetIDs = PresetTypePlugins[preset_type]

            for pluginID in pluginPresetIDs:
                pluginModule = PLUGINS_ID.get(pluginID)
                if pluginModule is None:
                    continue

                if not hasattr(context.scene.vray, pluginID):
                    continue

                propGroup = getattr(context.scene.vray, pluginID)

                ExportUtils.WritePlugin(bus, pluginModule, pluginID.lower(), propGroup, {})

        return {'FINISHED'}
def ExportCamera(bus):
    scene = bus['scene']
    camera = bus['camera']
    engine = bus['engine']

    scene, camera = BlenderUtils.GetSceneAndCamera(bus)

    VRayScene = scene.vray
    VRayCamera = camera.data.vray

    # NOTE: Order is vital here
    cameraPlugins = (
        'SettingsMotionBlur',
        'SettingsCameraDof',
        'SettingsCamera',
        'CameraPhysical',
        'RenderView',
        'BakeView',
        'CameraStereoscopic',
        'VRayStereoscopicSettings',
    )

    for pluginName in cameraPlugins:
        propGroup = None
        overrideParams = {}

        if pluginName == 'VRayStereoscopicSettings':
            propGroup = getattr(VRayScene, pluginName)
        elif pluginName == 'CameraStereoscopic':
            PLUGINS_ID['CameraStereoscopic'].write(bus)
            continue
        elif pluginName == 'BakeView':
            propGroup = getattr(VRayScene, pluginName)
        else:
            propGroup = getattr(VRayCamera, pluginName)

        if not propGroup:
            continue

        enabled = True
        for enableAttr in {'use', 'on'}:
            if hasattr(propGroup, enableAttr):
                enabled = getattr(propGroup, enableAttr)
        if not enabled:
            continue

        pluginModule = PLUGINS_ID[pluginName]

        ExportUtils.WritePlugin(bus, pluginModule, pluginName, propGroup,
                                overrideParams)
def ExportSettingsPlugin(bus, pluginType, pluginName):
    scene = bus['scene']

    VRayPreferences = bpy.context.user_preferences.addons['vb30'].preferences

    VRayScene = scene.vray
    VRayExporter   = VRayScene.Exporter
    VRayDR         = VRayScene.VRayDR
    SettingsOutput = VRayScene.SettingsOutput
    SettingsGI     = VRayScene.SettingsGI
    SettingsImageSampler = VRayScene.SettingsImageSampler

    pluginModule = PLUGINS_ID[pluginName]

    propGroup      = None
    overrideParams = {}

    if pluginName == 'SettingsRegionsGenerator':
        propGroup = getattr(VRayScene, pluginName)

        overrideParams = {
            'xc' : propGroup.xc,
            'yc' : propGroup.xc if propGroup.lock_size else propGroup.yc,
        }

    elif pluginName.startswith('Filter'):
        propGroup = getattr(VRayScene, pluginName)
        if SettingsImageSampler.filter_type != pluginName:
            return

    elif pluginName in {'SphericalHarmonicsExporter', 'SphericalHarmonicsRenderer'}:
        propGroup = getattr(VRayScene, pluginName)

        if SettingsGI.primary_engine != '4':
            return

        if VRayExporter.spherical_harmonics == 'BAKE':
            if pluginName == 'SphericalHarmonicsRenderer':
                return
        else:
            if pluginName == 'SphericalHarmonicsExporter':
                return
    else:
        propGroup = getattr(VRayScene, pluginName)

    if not propGroup:
        return

    ExportUtils.WritePlugin(bus, pluginModule, pluginName, propGroup, overrideParams)