From a9ba96896a627688be3359bf6a9d7e25995aa631 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 20 Dec 2010 23:26:29 +0000 Subject: modified fix for commits r33811, 33812. - SSS Presets were not working on pinned materials. - added ability for save-presets to define variables to stop them becoming too verbose. - remove object.active_node_material --- release/scripts/op/presets.py | 126 ++++++++++++++++++------------ release/scripts/presets/sss/apple.py | 6 +- release/scripts/presets/sss/chicken.py | 6 +- release/scripts/presets/sss/cream.py | 6 +- release/scripts/presets/sss/ketchup.py | 6 +- release/scripts/presets/sss/marble.py | 6 +- release/scripts/presets/sss/potato.py | 6 +- release/scripts/presets/sss/skim_milk.py | 6 +- release/scripts/presets/sss/skin1.py | 6 +- release/scripts/presets/sss/skin2.py | 6 +- release/scripts/presets/sss/whole_milk.py | 6 +- 11 files changed, 114 insertions(+), 72 deletions(-) (limited to 'release') diff --git a/release/scripts/op/presets.py b/release/scripts/op/presets.py index 0ee20966fad..b0dd7de3f1c 100644 --- a/release/scripts/op/presets.py +++ b/release/scripts/op/presets.py @@ -69,6 +69,12 @@ class AddPresetBase(): file_preset = open(filepath, 'w') file_preset.write("import bpy\n") + if hasattr(self, "preset_defines"): + for rna_path in self.preset_defines: + exec(rna_path) + file_preset.write("%s\n" % rna_path) + file_preset.write("\n") + for rna_path in self.preset_values: value = eval(rna_path) # convert thin wrapped sequences to simple lists to repr() @@ -150,17 +156,21 @@ class AddPresetRender(AddPresetBase, bpy.types.Operator): bl_label = "Add Render Preset" preset_menu = "RENDER_MT_presets" + preset_defines = [ + "scene = bpy.context.scene" + ] + preset_values = [ - "bpy.context.scene.render.field_order", - "bpy.context.scene.render.fps", - "bpy.context.scene.render.fps_base", - "bpy.context.scene.render.pixel_aspect_x", - "bpy.context.scene.render.pixel_aspect_y", - "bpy.context.scene.render.resolution_percentage", - "bpy.context.scene.render.resolution_x", - "bpy.context.scene.render.resolution_y", - "bpy.context.scene.render.use_fields", - "bpy.context.scene.render.use_fields_still", + "scene.render.field_order", + "scene.render.fps", + "scene.render.fps_base", + "scene.render.pixel_aspect_x", + "scene.render.pixel_aspect_y", + "scene.render.resolution_percentage", + "scene.render.resolution_x", + "scene.render.resolution_y", + "scene.render.use_fields", + "scene.render.use_fields_still", ] preset_subdir = "render" @@ -172,20 +182,20 @@ class AddPresetSSS(AddPresetBase, bpy.types.Operator): bl_label = "Add SSS Preset" preset_menu = "MATERIAL_MT_sss_presets" + preset_defines = [ + "material = (bpy.context.material.active_node_material if bpy.context.material.active_node_material else bpy.context.material)" + ] + preset_values = [ - "bpy.context.material.subsurface_scattering.back", - "bpy.context.material.subsurface_scattering.color[0]", - "bpy.context.material.subsurface_scattering.color[1]", - "bpy.context.material.subsurface_scattering.color[2]", - "bpy.context.material.subsurface_scattering.color_factor", - "bpy.context.material.subsurface_scattering.error_threshold", - "bpy.context.material.subsurface_scattering.front", - "bpy.context.material.subsurface_scattering.ior", - "bpy.context.material.subsurface_scattering.radius[0]", - "bpy.context.material.subsurface_scattering.radius[1]", - "bpy.context.material.subsurface_scattering.radius[2]", - "bpy.context.material.subsurface_scattering.scale", - "bpy.context.material.subsurface_scattering.texture_factor", + "material.subsurface_scattering.back", + "material.subsurface_scattering.color", + "material.subsurface_scattering.color_factor", + "material.subsurface_scattering.error_threshold", + "material.subsurface_scattering.front", + "material.subsurface_scattering.ior", + "material.subsurface_scattering.radius", + "material.subsurface_scattering.scale", + "material.subsurface_scattering.texture_factor", ] preset_subdir = "sss" @@ -197,13 +207,17 @@ class AddPresetCloth(AddPresetBase, bpy.types.Operator): bl_label = "Add Cloth Preset" preset_menu = "CLOTH_MT_presets" + preset_defines = [ + "cloth = bpy.context.cloth" + ] + preset_values = [ - "bpy.context.cloth.settings.air_damping", - "bpy.context.cloth.settings.bending_stiffness", - "bpy.context.cloth.settings.mass", - "bpy.context.cloth.settings.quality", - "bpy.context.cloth.settings.spring_damping", - "bpy.context.cloth.settings.structural_stiffness", + "cloth.settings.air_damping", + "cloth.settings.bending_stiffness", + "cloth.settings.mass", + "cloth.settings.quality", + "cloth.settings.spring_damping", + "cloth.settings.structural_stiffness", ] preset_subdir = "cloth" @@ -215,20 +229,24 @@ class AddPresetSunSky(AddPresetBase, bpy.types.Operator): bl_label = "Add Sunsky Preset" preset_menu = "LAMP_MT_sunsky_presets" + preset_defines = [ + "sky = bpy.context.object.data.sky" + ] + preset_values = [ - "bpy.context.object.data.sky.atmosphere_extinction", - "bpy.context.object.data.sky.atmosphere_inscattering", - "bpy.context.object.data.sky.atmosphere_turbidity", - "bpy.context.object.data.sky.backscattered_light", - "bpy.context.object.data.sky.horizon_brightness", - "bpy.context.object.data.sky.spread", - "bpy.context.object.data.sky.sun_brightness", - "bpy.context.object.data.sky.sun_intensity", - "bpy.context.object.data.sky.sun_size", - "bpy.context.object.data.sky.use_sky_blend", - "bpy.context.object.data.sky.use_sky_blend_type", - "bpy.context.object.data.sky.use_sky_color_space", - "bpy.context.object.data.sky.use_sky_exposure", + "sky.atmosphere_extinction", + "sky.atmosphere_inscattering", + "sky.atmosphere_turbidity", + "sky.backscattered_light", + "sky.horizon_brightness", + "sky.spread", + "sky.sun_brightness", + "sky.sun_intensity", + "sky.sun_size", + "sky.use_sky_blend", + "sky.use_sky_blend_type", + "sky.use_sky_color_space", + "sky.use_sky_exposure", ] preset_subdir = "sunsky" @@ -240,17 +258,21 @@ class AddPresetInteraction(AddPresetBase, bpy.types.Operator): bl_label = "Add Interaction Preset" preset_menu = "USERPREF_MT_interaction_presets" + preset_defines = [ + "user_preferences = bpy.context.user_preferences" + ] + preset_values = [ - "bpy.context.user_preferences.edit.use_drag_immediately", - "bpy.context.user_preferences.edit.use_insertkey_xyz_to_rgb", - "bpy.context.user_preferences.inputs.invert_mouse_wheel_zoom", - "bpy.context.user_preferences.inputs.select_mouse", - "bpy.context.user_preferences.inputs.use_emulate_numpad", - "bpy.context.user_preferences.inputs.use_mouse_continuous", - "bpy.context.user_preferences.inputs.use_mouse_emulate_3_button", - "bpy.context.user_preferences.inputs.view_rotate_method", - "bpy.context.user_preferences.inputs.view_zoom_axis", - "bpy.context.user_preferences.inputs.view_zoom_method", + "user_preferences.edit.use_drag_immediately", + "user_preferences.edit.use_insertkey_xyz_to_rgb", + "user_preferences.inputs.invert_mouse_wheel_zoom", + "user_preferences.inputs.select_mouse", + "user_preferences.inputs.use_emulate_numpad", + "user_preferences.inputs.use_mouse_continuous", + "user_preferences.inputs.use_mouse_emulate_3_button", + "user_preferences.inputs.view_rotate_method", + "user_preferences.inputs.view_zoom_axis", + "user_preferences.inputs.view_zoom_method", ] preset_subdir = "interaction" diff --git a/release/scripts/presets/sss/apple.py b/release/scripts/presets/sss/apple.py index 52ed4642ac6..c5f60ee5095 100644 --- a/release/scripts/presets/sss/apple.py +++ b/release/scripts/presets/sss/apple.py @@ -1,3 +1,5 @@ import bpy -bpy.context.active_object.active_node_material.subsurface_scattering.radius = 11.605, 3.884, 1.754 -bpy.context.active_object.active_node_material.subsurface_scattering.color = 0.430, 0.210, 0.168 +material = (bpy.context.material.active_node_material if bpy.context.material.active_node_material else bpy.context.material) + +material.subsurface_scattering.radius = 11.605, 3.884, 1.754 +material.subsurface_scattering.color = 0.430, 0.210, 0.168 diff --git a/release/scripts/presets/sss/chicken.py b/release/scripts/presets/sss/chicken.py index 1891ef95555..9acc2f3e25f 100644 --- a/release/scripts/presets/sss/chicken.py +++ b/release/scripts/presets/sss/chicken.py @@ -1,3 +1,5 @@ import bpy -bpy.context.active_object.active_node_material.subsurface_scattering.radius = 9.436, 3.348, 1.790 -bpy.context.active_object.active_node_material.subsurface_scattering.color = 0.439, 0.216, 0.141 +material = (bpy.context.material.active_node_material if bpy.context.material.active_node_material else bpy.context.material) + +material.subsurface_scattering.radius = 9.436, 3.348, 1.790 +material.subsurface_scattering.color = 0.439, 0.216, 0.141 diff --git a/release/scripts/presets/sss/cream.py b/release/scripts/presets/sss/cream.py index c5e812ffd19..c03cc0243d9 100644 --- a/release/scripts/presets/sss/cream.py +++ b/release/scripts/presets/sss/cream.py @@ -1,3 +1,5 @@ import bpy -bpy.context.active_object.active_node_material.subsurface_scattering.radius = 15.028, 4.664, 2.541 -bpy.context.active_object.active_node_material.subsurface_scattering.color = 0.987, 0.943, 0.827 +material = (bpy.context.material.active_node_material if bpy.context.material.active_node_material else bpy.context.material) + +material.subsurface_scattering.radius = 15.028, 4.664, 2.541 +material.subsurface_scattering.color = 0.987, 0.943, 0.827 diff --git a/release/scripts/presets/sss/ketchup.py b/release/scripts/presets/sss/ketchup.py index d5674676282..b94c7cced27 100644 --- a/release/scripts/presets/sss/ketchup.py +++ b/release/scripts/presets/sss/ketchup.py @@ -1,3 +1,5 @@ import bpy -bpy.context.active_object.active_node_material.subsurface_scattering.radius = 4.762, 0.575, 0.394 -bpy.context.active_object.active_node_material.subsurface_scattering.color = 0.222, 0.008, 0.002 +material = (bpy.context.material.active_node_material if bpy.context.material.active_node_material else bpy.context.material) + +material.subsurface_scattering.radius = 4.762, 0.575, 0.394 +material.subsurface_scattering.color = 0.222, 0.008, 0.002 diff --git a/release/scripts/presets/sss/marble.py b/release/scripts/presets/sss/marble.py index ad753a7a770..c85719900e2 100644 --- a/release/scripts/presets/sss/marble.py +++ b/release/scripts/presets/sss/marble.py @@ -1,3 +1,5 @@ import bpy -bpy.context.active_object.active_node_material.subsurface_scattering.radius = 8.509, 5.566, 3.951 -bpy.context.active_object.active_node_material.subsurface_scattering.color = 0.925, 0.905, 0.884 +material = (bpy.context.material.active_node_material if bpy.context.material.active_node_material else bpy.context.material) + +material.subsurface_scattering.radius = 8.509, 5.566, 3.951 +material.subsurface_scattering.color = 0.925, 0.905, 0.884 diff --git a/release/scripts/presets/sss/potato.py b/release/scripts/presets/sss/potato.py index 3610c16198f..74807014bd3 100644 --- a/release/scripts/presets/sss/potato.py +++ b/release/scripts/presets/sss/potato.py @@ -1,3 +1,5 @@ import bpy -bpy.context.active_object.active_node_material.subsurface_scattering.radius = 14.266, 7.228, 2.036 -bpy.context.active_object.active_node_material.subsurface_scattering.color = 0.855, 0.740, 0.292 +material = (bpy.context.material.active_node_material if bpy.context.material.active_node_material else bpy.context.material) + +material.subsurface_scattering.radius = 14.266, 7.228, 2.036 +material.subsurface_scattering.color = 0.855, 0.740, 0.292 diff --git a/release/scripts/presets/sss/skim_milk.py b/release/scripts/presets/sss/skim_milk.py index eec84f72aa9..163659faf34 100644 --- a/release/scripts/presets/sss/skim_milk.py +++ b/release/scripts/presets/sss/skim_milk.py @@ -1,3 +1,5 @@ import bpy -bpy.context.active_object.active_node_material.subsurface_scattering.radius = 18.424, 10.443, 3.502 -bpy.context.active_object.active_node_material.subsurface_scattering.color = 0.889, 0.888, 0.796 +material = (bpy.context.material.active_node_material if bpy.context.material.active_node_material else bpy.context.material) + +material.subsurface_scattering.radius = 18.424, 10.443, 3.502 +material.subsurface_scattering.color = 0.889, 0.888, 0.796 diff --git a/release/scripts/presets/sss/skin1.py b/release/scripts/presets/sss/skin1.py index ba991f8d0d8..ef284019637 100644 --- a/release/scripts/presets/sss/skin1.py +++ b/release/scripts/presets/sss/skin1.py @@ -1,3 +1,5 @@ import bpy -bpy.context.active_object.active_node_material.subsurface_scattering.radius = 3.673, 1.367, 0.683 -bpy.context.active_object.active_node_material.subsurface_scattering.color = 0.574, 0.313, 0.174 +material = (bpy.context.material.active_node_material if bpy.context.material.active_node_material else bpy.context.material) + +material.subsurface_scattering.radius = 3.673, 1.367, 0.683 +material.subsurface_scattering.color = 0.574, 0.313, 0.174 diff --git a/release/scripts/presets/sss/skin2.py b/release/scripts/presets/sss/skin2.py index 6ac55633619..16a7d154309 100644 --- a/release/scripts/presets/sss/skin2.py +++ b/release/scripts/presets/sss/skin2.py @@ -1,3 +1,5 @@ import bpy -bpy.context.active_object.active_node_material.subsurface_scattering.radius = 4.821, 1.694, 1.090 -bpy.context.active_object.active_node_material.subsurface_scattering.color = 0.749, 0.571, 0.467 +material = (bpy.context.material.active_node_material if bpy.context.material.active_node_material else bpy.context.material) + +material.subsurface_scattering.radius = 4.821, 1.694, 1.090 +material.subsurface_scattering.color = 0.749, 0.571, 0.467 diff --git a/release/scripts/presets/sss/whole_milk.py b/release/scripts/presets/sss/whole_milk.py index 4421fc36004..c11b18557e3 100644 --- a/release/scripts/presets/sss/whole_milk.py +++ b/release/scripts/presets/sss/whole_milk.py @@ -1,3 +1,5 @@ import bpy -bpy.context.active_object.active_node_material.subsurface_scattering.radius = 10.899, 6.575, 2.508 -bpy.context.active_object.active_node_material.subsurface_scattering.color = 0.947, 0.931, 0.852 +material = (bpy.context.material.active_node_material if bpy.context.material.active_node_material else bpy.context.material) + +material.subsurface_scattering.radius = 10.899, 6.575, 2.508 +material.subsurface_scattering.color = 0.947, 0.931, 0.852 -- cgit v1.2.3