edits to quick effects scripts
authorCampbell Barton <ideasman42@gmail.com>
Mon, 25 Jul 2011 05:54:32 +0000 (05:54 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 25 Jul 2011 05:54:32 +0000 (05:54 +0000)
- use uv layer data api rather then operator.
- switch vector rotation order.
- made some style changes, use 80 width.

release/scripts/startup/bl_operators/object_quick_effects.py

index 074f204d50e6dea92067e8ed878d6920f91b8cfd..ef10bfd737db05693035bafa2797c9e7c09a2de3 100644 (file)
 #
 # ##### END GPL LICENSE BLOCK #####
 
-# <pep8 compliant>
+# <pep8-80 compliant>
 
 from mathutils import Vector
 import bpy
-from bpy.props import BoolProperty, EnumProperty, IntProperty, FloatProperty, FloatVectorProperty
+from bpy.props import (BoolProperty,
+                       EnumProperty,
+                       IntProperty,
+                       FloatProperty,
+                       FloatVectorProperty,
+                       )
 
 
 def object_ensure_material(obj, mat_name):
@@ -61,7 +66,8 @@ class QuickFur(bpy.types.Operator):
 
     def execute(self, context):
         fake_context = bpy.context.copy()
-        mesh_objects = [obj for obj in context.selected_objects if obj.type == 'MESH']
+        mesh_objects = [obj for obj in context.selected_objects
+                        if obj.type == 'MESH']
 
         if not mesh_objects:
             self.report({'ERROR'}, "Select at least one mesh object.")
@@ -92,7 +98,8 @@ class QuickFur(bpy.types.Operator):
             psys.settings.child_type = 'INTERPOLATED'
 
             obj.data.materials.append(mat)
-            obj.particle_systems[-1].settings.material = len(obj.data.materials)
+            obj.particle_systems[-1].settings.material = \
+                    len(obj.data.materials)
 
         return {'FINISHED'}
 
@@ -149,7 +156,10 @@ class QuickExplode(bpy.types.Operator):
 
         for obj in mesh_objects:
             if obj.particle_systems:
-                self.report({'ERROR'}, "Object %r already has a particle system" % obj.name)
+                self.report({'ERROR'},
+                            "Object %r already has a "
+                            "particle system" % obj.name)
+
                 return {'CANCELLED'}
 
         if self.fade:
@@ -184,9 +194,7 @@ class QuickExplode(bpy.types.Operator):
 
             if self.fade:
                 explode.show_dead = False
-                bpy.ops.mesh.uv_texture_add(fake_context)
-                uv = obj.data.uv_textures[-1]
-                uv.name = "Explode fade"
+                uv = obj.data.uv_textures.new("Explode fade")
                 explode.particle_uv = uv.name
 
                 mat = object_ensure_material(obj, "Explode Fade")
@@ -247,7 +255,7 @@ class QuickExplode(bpy.types.Operator):
 
 def obj_bb_minmax(obj, min_co, max_co):
     for i in range(0, 8):
-        bb_vec = Vector(obj.bound_box[i]) * obj.matrix_world
+        bb_vec = obj.matrix_world * Vector(obj.bound_box[i])
 
         min_co[0] = min(bb_vec[0], min_co[0])
         min_co[1] = min(bb_vec[1], min_co[1])
@@ -262,21 +270,26 @@ class QuickSmoke(bpy.types.Operator):
     bl_label = "Quick Smoke"
     bl_options = {'REGISTER', 'UNDO'}
 
-    style = EnumProperty(items=(
-                        ('STREAM', "Stream", ""),
-                        ('PUFF', "Puff", ""),
-                        ('FIRE', "Fire", "")),
-                name="Smoke Style",
-                description="",
-                default='STREAM')
-
-    show_flows = BoolProperty(name="Render Smoke Objects",
-                description="Keep the smoke objects visible during rendering.",
-                default=False)
+    style = EnumProperty(
+            items=(('STREAM', "Stream", ""),
+                   ('PUFF', "Puff", ""),
+                   ('FIRE', "Fire", ""),
+                   ),
+            name="Smoke Style",
+            description="",
+            default='STREAM',
+            )
+
+    show_flows = BoolProperty(
+            name="Render Smoke Objects",
+            description="Keep the smoke objects visible during rendering.",
+            default=False,
+            )
 
     def execute(self, context):
         fake_context = bpy.context.copy()
-        mesh_objects = [obj for obj in context.selected_objects if obj.type == 'MESH']
+        mesh_objects = [obj for obj in context.selected_objects
+                        if obj.type == 'MESH']
         min_co = Vector((100000.0, 100000.0, 100000.0))
         max_co = -min_co
 
@@ -336,21 +349,25 @@ class QuickSmoke(bpy.types.Operator):
         mat.volume.density = 0
         mat.volume.density_scale = 5
 
-        mat.texture_slots.add()
-        mat.texture_slots[0].texture = bpy.data.textures.new("Smoke Density", 'VOXEL_DATA')
-        mat.texture_slots[0].texture.voxel_data.domain_object = obj
-        mat.texture_slots[0].use_map_color_emission = False
-        mat.texture_slots[0].use_map_density = True
+        tex = bpy.data.textures.new("Smoke Density", 'VOXEL_DATA')
+        tex.voxel_data.domain_object = obj
+
+        tex_slot = mat.texture_slots.add()
+        tex_slot.texture = tex
+        tex_slot.use_map_color_emission = False
+        tex_slot.use_map_density = True
 
         # for fire add a second texture for emission and emission color
         if self.style == 'FIRE':
             mat.volume.emission = 5
-            mat.texture_slots.add()
-            mat.texture_slots[1].texture = bpy.data.textures.new("Smoke Heat", 'VOXEL_DATA')
-            mat.texture_slots[1].texture.voxel_data.domain_object = obj
-            mat.texture_slots[1].texture.use_color_ramp = True
+            tex = bpy.data.textures.new("Smoke Heat", 'VOXEL_DATA')
+            tex.voxel_data.domain_object = obj
+            tex.use_color_ramp = True
+
+            tex_slot = mat.texture_slots.add()
+            tex_slot.texture = tex
 
-            ramp = mat.texture_slots[1].texture.color_ramp
+            ramp = tex.color_ramp
 
             elem = ramp.elements.new(0.333)
             elem.color[0] = elem.color[3] = 1
@@ -371,28 +388,38 @@ class QuickFluid(bpy.types.Operator):
     bl_label = "Quick Fluid"
     bl_options = {'REGISTER', 'UNDO'}
 
-    style = EnumProperty(items=(
-                        ('INFLOW', "Inflow", ""),
-                        ('BASIC', "Basic", "")),
+    style = EnumProperty(
+            items=(('INFLOW', "Inflow", ""),
+                   ('BASIC', "Basic", ""),
+                   ),
                 name="Fluid Style",
                 description="",
-                default='BASIC')
-
-    initial_velocity = FloatVectorProperty(name="Initial Velocity",
-        description="Initial velocity of the fluid",
-        default=(0.0, 0.0, 0.0), min=-100.0, max=100.0, subtype='VELOCITY')
-
-    show_flows = BoolProperty(name="Render Fluid Objects",
-                description="Keep the fluid objects visible during rendering.",
-                default=False)
-
-    start_baking = BoolProperty(name="Start Fluid Bake",
-                description="Start baking the fluid immediately after creating the domain object.",
-                default=False)
+                default='BASIC',
+                )
+    initial_velocity = FloatVectorProperty(
+            name="Initial Velocity",
+            description="Initial velocity of the fluid",
+            default=(0.0, 0.0, 0.0),
+            min=-100.0,
+            max=100.0,
+            subtype='VELOCITY',
+            )
+    show_flows = BoolProperty(
+            name="Render Fluid Objects",
+            description="Keep the fluid objects visible during rendering.",
+            default=False,
+            )
+    start_baking = BoolProperty(
+            name="Start Fluid Bake",
+            description=("Start baking the fluid immediately "
+                         "after creating the domain object"),
+            default=False,
+            )
 
     def execute(self, context):
         fake_context = bpy.context.copy()
-        mesh_objects = [obj for obj in context.selected_objects if (obj.type == 'MESH' and not 0 in obj.dimensions)]
+        mesh_objects = [obj for obj in context.selected_objects
+                        if (obj.type == 'MESH' and not 0.0 in obj.dimensions)]
         min_co = Vector((100000, 100000, 100000))
         max_co = Vector((-100000, -100000, -100000))
 
@@ -405,7 +432,8 @@ class QuickFluid(bpy.types.Operator):
             # make each selected object a fluid
             bpy.ops.object.modifier_add(fake_context, type='FLUID_SIMULATION')
 
-            # fluid has to be before constructive modifiers, so it might not be the last modifier
+            # fluid has to be before constructive modifiers,
+            # so it might not be the last modifier
             for mod in obj.modifiers:
                 if mod.type == 'FLUID_SIMULATION':
                     break
@@ -429,10 +457,14 @@ class QuickFluid(bpy.types.Operator):
         obj = context.active_object
         obj.name = "Fluid Domain"
 
-        # give the fluid some room below the flows and scale with initial velocity
+        # give the fluid some room below the flows
+        # and scale with initial velocity
         v = 0.5 * self.initial_velocity
         obj.location = 0.5 * (max_co + min_co) + Vector((0.0, 0.0, -1.0)) + v
-        obj.scale = 0.5 * (max_co - min_co) + Vector((1.0, 1.0, 2.0)) + Vector((abs(v[0]), abs(v[1]), abs(v[2])))
+        obj.scale = (0.5 * (max_co - min_co) +
+                     Vector((1.0, 1.0, 2.0)) +
+                     Vector((abs(v[0]), abs(v[1]), abs(v[2])))
+                     )
 
         # setup smoke domain
         bpy.ops.object.modifier_add(type='FLUID_SIMULATION')