diff options
Diffstat (limited to 'release/scripts/startup/bl_operators')
8 files changed, 268 insertions, 76 deletions
diff --git a/release/scripts/startup/bl_operators/object.py b/release/scripts/startup/bl_operators/object.py index 29b75e64fca..c1f75c74bb4 100644 --- a/release/scripts/startup/bl_operators/object.py +++ b/release/scripts/startup/bl_operators/object.py @@ -249,9 +249,9 @@ class SubdivisionSet(Operator): if mod.type == 'MULTIRES': if not relative: if level > mod.total_levels: - sub = level - mod.total_levels - for i in range (0, sub): - bpy.ops.object.multires_subdivide(modifier="Multires") + sub = level - mod.total_levels + for i in range (0, sub): + bpy.ops.object.multires_subdivide(modifier="Multires") if obj.mode == 'SCULPT': if mod.sculpt_levels != level: @@ -775,22 +775,15 @@ class DupliOffsetFromCursor(Operator): bl_label = "Set Offset From Cursor" bl_options = {'REGISTER', 'UNDO'} - group = IntProperty( - name="Group", - description="Group index to set offset for", - default=0, - ) - @classmethod def poll(cls, context): return (context.active_object is not None) def execute(self, context): scene = context.scene - ob = context.active_object - group = self.group + group = context.group - ob.users_group[group].dupli_offset = scene.cursor_location + group.dupli_offset = scene.cursor_location return {'FINISHED'} diff --git a/release/scripts/startup/bl_operators/object_quick_effects.py b/release/scripts/startup/bl_operators/object_quick_effects.py index 556d34bb0ac..32688299b76 100644 --- a/release/scripts/startup/bl_operators/object_quick_effects.py +++ b/release/scripts/startup/bl_operators/object_quick_effects.py @@ -289,6 +289,10 @@ def obj_bb_minmax(obj, min_co, max_co): max_co[0] = max(bb_vec[0], max_co[0]) max_co[1] = max(bb_vec[1], max_co[1]) max_co[2] = max(bb_vec[2], max_co[2]) + + +def grid_location(x, y): + return (x * 200, y * 150) class QuickSmoke(Operator): @@ -298,10 +302,11 @@ class QuickSmoke(Operator): style = EnumProperty( name="Smoke Style", - items=(('STREAM', "Stream", ""), + items=(('SMOKE', "Smoke", ""), ('FIRE', "Fire", ""), + ('BOTH', "Smoke + Fire", ""), ), - default='STREAM', + default='SMOKE', ) show_flows = BoolProperty( @@ -327,8 +332,8 @@ class QuickSmoke(Operator): bpy.ops.object.modifier_add(fake_context, type='SMOKE') obj.modifiers[-1].smoke_type = 'FLOW' - if self.style == 'FIRE': - obj.modifiers[-1].flow_settings.smoke_flow_type = 'FIRE' + # set type + obj.modifiers[-1].flow_settings.smoke_flow_type = self.style if not self.show_flows: obj.draw_type = 'WIRE' @@ -348,57 +353,177 @@ class QuickSmoke(Operator): # setup smoke domain bpy.ops.object.modifier_add(type='SMOKE') obj.modifiers[-1].smoke_type = 'DOMAIN' - if self.style == 'FIRE': + if self.style == 'FIRE' or self.style == 'BOTH': obj.modifiers[-1].domain_settings.use_high_resolution = True - # create a volume material with a voxel data texture for the domain - bpy.ops.object.material_slot_add() + # Setup material + + # Cycles + if context.scene.render.use_shading_nodes: + bpy.ops.object.material_slot_add() + + mat = bpy.data.materials.new("Smoke Domain Material") + obj.material_slots[0].material = mat + + # Make sure we use nodes + mat.use_nodes = True + + # Set node variables and clear the default nodes + tree = mat.node_tree + nodes = tree.nodes + links = tree.links + + nodes.clear() + + # Create shader nodes + + # Material output + node_out = nodes.new(type='ShaderNodeOutputMaterial') + node_out.location = grid_location(6, 1) + + # Add shader 1 + node_add_shader_1 = nodes.new(type='ShaderNodeAddShader') + node_add_shader_1.location = grid_location(5, 1) + links.new(node_add_shader_1.outputs["Shader"], + node_out.inputs["Volume"]) + + # Smoke + + # Add shader 2 + node_add_shader_2 = nodes.new(type='ShaderNodeAddShader') + node_add_shader_2.location = grid_location(4, 2) + links.new(node_add_shader_2.outputs["Shader"], + node_add_shader_1.inputs[0]) + + # Volume scatter + node_scatter = nodes.new(type='ShaderNodeVolumeScatter') + node_scatter.location = grid_location(3, 3) + links.new(node_scatter.outputs["Volume"], + node_add_shader_2.inputs[0]) + + # Volume absorption + node_absorption = nodes.new(type='ShaderNodeVolumeAbsorption') + node_absorption.location = grid_location(3, 2) + links.new(node_absorption.outputs["Volume"], + node_add_shader_2.inputs[1]) + + # Density Multiplier + node_densmult = nodes.new(type='ShaderNodeMath') + node_densmult.location = grid_location(2, 2) + node_densmult.operation = 'MULTIPLY' + node_densmult.inputs[1].default_value = 5.0 + links.new(node_densmult.outputs["Value"], + node_scatter.inputs["Density"]) + links.new(node_densmult.outputs["Value"], + node_absorption.inputs["Density"]) + + # Attribute "density" + node_attrib_density = nodes.new(type='ShaderNodeAttribute') + node_attrib_density.attribute_name = "density" + node_attrib_density.location = grid_location(1, 2) + links.new(node_attrib_density.outputs["Fac"], + node_densmult.inputs[0]) + + # Attribute "color" + node_attrib_color = nodes.new(type='ShaderNodeAttribute') + node_attrib_color.attribute_name = "color" + node_attrib_color.location = grid_location(2, 3) + links.new(node_attrib_color.outputs["Color"], + node_scatter.inputs["Color"]) + links.new(node_attrib_color.outputs["Color"], + node_absorption.inputs["Color"]) + + # Fire + + # Emission + node_emission = nodes.new(type='ShaderNodeEmission') + node_emission.inputs["Color"].default_value = (0.8, 0.1, 0.01, 1.0) + node_emission.location = grid_location(4, 1) + links.new(node_emission.outputs["Emission"], + node_add_shader_1.inputs[1]) + + # Flame strength multiplier + node_flame_strength_mult = nodes.new(type='ShaderNodeMath') + node_flame_strength_mult.location = grid_location(3, 1) + node_flame_strength_mult.operation = 'MULTIPLY' + node_flame_strength_mult.inputs[1].default_value = 2.5 + links.new(node_flame_strength_mult.outputs["Value"], + node_emission.inputs["Strength"]) + + # Color ramp Flame + node_flame_ramp = nodes.new(type='ShaderNodeValToRGB') + node_flame_ramp.location = grid_location(1, 1) + ramp = node_flame_ramp.color_ramp + ramp.interpolation = 'EASE' + + # orange + elem = ramp.elements.new(0.5) + elem.color = (1.0, 0.128, 0.0, 1.0) + + # yellow + elem = ramp.elements.new(0.9) + elem.color = (0.9, 0.6, 0.1, 1.0) + + links.new(node_flame_ramp.outputs["Color"], + node_emission.inputs["Color"]) + + # Attribute "flame" + node_attrib_flame = nodes.new(type='ShaderNodeAttribute') + node_attrib_flame.attribute_name = "flame" + node_attrib_flame.location = grid_location(0, 1) + links.new(node_attrib_flame.outputs["Fac"], + node_flame_ramp.inputs["Fac"]) + links.new(node_attrib_flame.outputs["Fac"], + node_flame_strength_mult.inputs[0]) + + # Blender Internal + else: + # create a volume material with a voxel data texture for the domain + bpy.ops.object.material_slot_add() + + mat = bpy.data.materials.new("Smoke Domain Material") + obj.material_slots[0].material = mat + mat.type = 'VOLUME' + mat.volume.density = 0 + mat.volume.density_scale = 5 + mat.volume.step_size = 0.1 + + tex = bpy.data.textures.new("Smoke Density", 'VOXEL_DATA') + tex.voxel_data.domain_object = obj + tex.voxel_data.interpolation = 'TRICUBIC_BSPLINE' + + tex_slot = mat.texture_slots.add() + tex_slot.texture = tex + tex_slot.texture_coords = 'ORCO' + tex_slot.use_map_color_emission = False + tex_slot.use_map_density = True + tex_slot.use_map_color_reflection = True + + # for fire add a second texture for flame emission + mat.volume.emission_color = Vector((0.0, 0.0, 0.0)) + tex = bpy.data.textures.new("Flame", 'VOXEL_DATA') + tex.voxel_data.domain_object = obj + tex.voxel_data.smoke_data_type = 'SMOKEFLAME' + tex.voxel_data.interpolation = 'TRICUBIC_BSPLINE' + tex.use_color_ramp = True - mat = bpy.data.materials.new("Smoke Domain Material") - obj.material_slots[0].material = mat - mat.type = 'VOLUME' - mat.volume.density = 0 - mat.volume.density_scale = 5 - mat.volume.step_size = 0.1 - - tex = bpy.data.textures.new("Smoke Density", 'VOXEL_DATA') - tex.voxel_data.domain_object = obj - tex.voxel_data.interpolation = 'TRICUBIC_BSPLINE' - - tex_slot = mat.texture_slots.add() - tex_slot.texture = tex - tex_slot.use_map_color_emission = False - tex_slot.use_map_density = True - tex_slot.use_map_color_reflection = True - - # for fire add a second texture for flame emission - mat.volume.emission_color = Vector((0.0, 0.0, 0.0)) - tex = bpy.data.textures.new("Flame", 'VOXEL_DATA') - tex.voxel_data.domain_object = obj - tex.voxel_data.smoke_data_type = 'SMOKEFLAME' - tex.voxel_data.interpolation = 'TRICUBIC_BSPLINE' - tex.use_color_ramp = True - - tex_slot = mat.texture_slots.add() - tex_slot.texture = tex - - # add color ramp for flame color - ramp = tex.color_ramp - # dark orange - elem = ramp.elements.new(0.333) - elem.color[0] = 0.2 - elem.color[1] = 0.03 - elem.color[2] = 0 - elem.color[3] = 1 - # yellow glow - elem = ramp.elements.new(0.666) - elem.color[0] = elem.color[3] = 1 - elem.color[1] = 0.65 - elem.color[2] = 0.25 - - mat.texture_slots[1].use_map_density = True - mat.texture_slots[1].use_map_emission = True - mat.texture_slots[1].emission_factor = 5 + tex_slot = mat.texture_slots.add() + tex_slot.texture = tex + tex_slot.texture_coords = 'ORCO' + + # add color ramp for flame color + ramp = tex.color_ramp + # dark orange + elem = ramp.elements.new(0.333) + elem.color = (0.2, 0.03, 0.0, 1.0) + + # yellow glow + elem = ramp.elements.new(0.666) + elem.color = (1, 0.65, 0.25, 1.0) + + mat.texture_slots[1].use_map_density = True + mat.texture_slots[1].use_map_emission = True + mat.texture_slots[1].emission_factor = 5 return {'FINISHED'} diff --git a/release/scripts/startup/bl_operators/presets.py b/release/scripts/startup/bl_operators/presets.py index 8b0ed7d9942..f89792bea6e 100644 --- a/release/scripts/startup/bl_operators/presets.py +++ b/release/scripts/startup/bl_operators/presets.py @@ -253,7 +253,7 @@ class AddPresetCamera(AddPresetBase, Operator): preset_menu = "CAMERA_MT_presets" preset_defines = [ - "cam = bpy.context.object.data" + "cam = bpy.context.camera" ] preset_subdir = "camera" @@ -352,7 +352,7 @@ class AddPresetSunSky(AddPresetBase, Operator): preset_menu = "LAMP_MT_sunsky_presets" preset_defines = [ - "sky = bpy.context.object.data.sky" + "sky = bpy.context.lamp.sky" ] preset_values = [ diff --git a/release/scripts/startup/bl_operators/uvcalc_lightmap.py b/release/scripts/startup/bl_operators/uvcalc_lightmap.py index 6f54c051c0b..8f618e0632e 100644 --- a/release/scripts/startup/bl_operators/uvcalc_lightmap.py +++ b/release/scripts/startup/bl_operators/uvcalc_lightmap.py @@ -470,9 +470,7 @@ def lightmap_uvpack(meshes, pretty_faces.append(pf_parent) w, h = pf_parent.width, pf_parent.height - - if w > h: - raise "error" + assert(w <= h) if w == h: even_dict.setdefault(w, []).append(pf_parent) diff --git a/release/scripts/startup/bl_operators/uvcalc_smart_project.py b/release/scripts/startup/bl_operators/uvcalc_smart_project.py index bf8b10ac4af..aa8a1742c1e 100644 --- a/release/scripts/startup/bl_operators/uvcalc_smart_project.py +++ b/release/scripts/startup/bl_operators/uvcalc_smart_project.py @@ -634,7 +634,7 @@ def packIslands(islandList): # print 'Box Packing Time:', time.time() - time1 #if len(pa ckedLs) != len(islandList): - # raise "Error packed boxes differs from original length" + # raise ValueError("Packed boxes differs from original length") #print '\tWriting Packed Data to faces' #XXX Window.DrawProgressBar(0.8, "Writing Packed Data to faces") diff --git a/release/scripts/startup/bl_operators/vertexpaint_dirt.py b/release/scripts/startup/bl_operators/vertexpaint_dirt.py index 68c9bc143be..ecb1ecf7f47 100644 --- a/release/scripts/startup/bl_operators/vertexpaint_dirt.py +++ b/release/scripts/startup/bl_operators/vertexpaint_dirt.py @@ -109,7 +109,7 @@ def applyVertexDirt(me, blur_iterations, blur_strength, clamp_dirt, clamp_clean, active_col_layer = me.vertex_colors[0].data if not active_col_layer: - return + return {'CANCELLED'} use_paint_mask = me.use_paint_mask diff --git a/release/scripts/startup/bl_operators/view3d.py b/release/scripts/startup/bl_operators/view3d.py index 85cc9210c2d..df4a93bb87f 100644 --- a/release/scripts/startup/bl_operators/view3d.py +++ b/release/scripts/startup/bl_operators/view3d.py @@ -169,6 +169,13 @@ class VIEW3D_OT_select_or_deselect_all(Operator): default=False, ) + @classmethod + def poll(cls, context): + active_object = context.active_object + if active_object: + return active_object.mode in {'EDIT', 'OBJECT', 'POSE'} + return True + def invoke(self, context, event): x = event.mouse_region_x y = event.mouse_region_y diff --git a/release/scripts/startup/bl_operators/wm.py b/release/scripts/startup/bl_operators/wm.py index 4281c908afd..5c3f94a8739 100644 --- a/release/scripts/startup/bl_operators/wm.py +++ b/release/scripts/startup/bl_operators/wm.py @@ -527,7 +527,76 @@ class WM_OT_context_menu_enum(Operator): context.window_manager.popup_menu(draw_func=draw_cb, title=prop.name, icon=prop.icon) - return {'PASS_THROUGH'} + return {'FINISHED'} + + +class WM_OT_context_pie_enum(Operator): + bl_idname = "wm.context_pie_enum" + bl_label = "Context Enum Pie" + bl_options = {'UNDO', 'INTERNAL'} + data_path = rna_path_prop + + def invoke(self, context, event): + wm = context.window_manager + data_path = self.data_path + value = context_path_validate(context, data_path) + + if value is Ellipsis: + return {'PASS_THROUGH'} + + base_path, prop_string = data_path.rsplit(".", 1) + value_base = context_path_validate(context, base_path) + prop = value_base.bl_rna.properties[prop_string] + + def draw_cb(self, context): + layout = self.layout + layout.prop(value_base, prop_string, expand=True) + + wm.popup_menu_pie(draw_func=draw_cb, title=prop.name, icon=prop.icon, event=event) + + return {'FINISHED'} + + +class WM_OT_operator_pie_enum(Operator): + bl_idname = "wm.operator_pie_enum" + bl_label = "Operator Enum Pie" + bl_options = {'UNDO', 'INTERNAL'} + data_path = StringProperty( + name="Operator", + description="Operator name (in python as string)", + maxlen=1024, + ) + prop_string = StringProperty( + name="Property", + description="Property name (as a string)", + maxlen=1024, + ) + + def invoke(self, context, event): + wm = context.window_manager + + data_path = self.data_path + prop_string = self.prop_string + + # same as eval("bpy.ops." + data_path) + op_mod_str, ob_id_str = data_path.split(".", 1) + op = getattr(getattr(bpy.ops, op_mod_str), ob_id_str) + del op_mod_str, ob_id_str + + try: + op_rna = op.get_rna() + except KeyError: + self.report({'ERROR'}, "Operator not found: bpy.ops.%s" % data_path) + return {'CANCELLED'} + + def draw_cb(self, context): + layout = self.layout + pie = layout.menu_pie() + pie.operator_enum(data_path, prop_string) + + wm.popup_menu_pie(draw_func=draw_cb, title=op_rna.bl_rna.name, event=event) + + return {'FINISHED'} class WM_OT_context_set_id(Operator): @@ -1033,13 +1102,13 @@ rna_property = StringProperty( rna_min = FloatProperty( name="Min", - default=0.0, + default=-10000.0, precision=3, ) rna_max = FloatProperty( name="Max", - default=1.0, + default=10000.0, precision=3, ) @@ -1883,7 +1952,7 @@ class WM_OT_addon_install(Operator): addons_old = {mod.__name__ for mod in addon_utils.modules()} - #check to see if the file is in compressed format (.zip) + # check to see if the file is in compressed format (.zip) if zipfile.is_zipfile(pyfile): try: file_to_extract = zipfile.ZipFile(pyfile, 'r') @@ -1916,7 +1985,7 @@ class WM_OT_addon_install(Operator): self.report({'WARNING'}, "File already installed to %r\n" % path_dest) return {'CANCELLED'} - #if not compressed file just copy into the addon path + # if not compressed file just copy into the addon path try: shutil.copyfile(pyfile, path_dest) |