[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [3026] trunk/py/scripts/addons/ object_cloud_gen.py: removed warning (works in trunk now), also made pep8 edits

Campbell Barton ideasman42 at gmail.com
Mon Feb 27 12:34:11 CET 2012


Revision: 3026
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=3026
Author:   campbellbarton
Date:     2012-02-27 11:34:02 +0000 (Mon, 27 Feb 2012)
Log Message:
-----------
removed warning (works in trunk now), also made pep8 edits

Modified Paths:
--------------
    trunk/py/scripts/addons/object_cloud_gen.py

Modified: trunk/py/scripts/addons/object_cloud_gen.py
===================================================================
--- trunk/py/scripts/addons/object_cloud_gen.py	2012-02-27 04:40:59 UTC (rev 3025)
+++ trunk/py/scripts/addons/object_cloud_gen.py	2012-02-27 11:34:02 UTC (rev 3026)
@@ -16,23 +16,24 @@
 #
 # ##### END GPL LICENSE BLOCK #####
 
+# <pep8 compliant>
+
 bl_info = {
     "name": "Cloud Generator",
     "author": "Nick Keeline(nrk)",
-    "version": (1,0),
+    "version": (1, 0),
     "blender": (2, 5, 9),
     "location": "View3D > Tool Shelf > Cloud Generator Panel",
     "description": "Creates Volumetric Clouds",
-    "warning": "broken with bmesh",
-    "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.5/Py/"\
-        "Scripts/Object/Cloud_Gen",
-    "tracker_url": "https://projects.blender.org/tracker/index.php?"\
-        "func=detail&aid=22015",
+    "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.5/Py/"
+                "Scripts/Object/Cloud_Gen",
+    "tracker_url": "https://projects.blender.org/tracker/index.php?"
+                   "func=detail&aid=22015",
     "category": "Object"}
 
 import bpy
-from math import *
-from bpy.props import *
+from bpy.props import BoolProperty, EnumProperty
+from bpy.types import Operator, Panel
 
 
 # This routine takes an object and deletes all of the geometry in it
@@ -40,24 +41,25 @@
 # It will add or subtract the bound box size by the variable sizeDifference.
 
 def getMeshandPutinEditMode(scene, object):
-    
-     # Go into Object Mode
-    bpy.ops.object.mode_set(mode='OBJECT')   
-    
+
+    # Go into Object Mode
+    bpy.ops.object.mode_set(mode='OBJECT')
+
     # Deselect All
     bpy.ops.object.select_all(action='DESELECT')
 
     # Select the object
     object.select = True
     scene.objects.active = object
-    
+
     # Go into Edit Mode
     bpy.ops.object.mode_set(mode='EDIT')
 
     return object.data
-   
+
+
 def maxAndMinVerts(scene, object):
-    
+
     mesh = getMeshandPutinEditMode(scene, object)
     verts = mesh.vertices
 
@@ -82,12 +84,14 @@
             minVert[1] = vert.co[1]
         if vert.co[2] < minVert[2]:
             minVert[2] = vert.co[2]
-            
+
     return [maxVert, minVert]
-    
+
+
 def makeObjectIntoBoundBox(scene, object, sizeDifference, takeFromObject):
-    
-    #Let's find the max and min of the reference object, it can be the same as the destination object
+
+    # Let's find the max and min of the reference object,
+    # it can be the same as the destination object
     [maxVert, minVert] = maxAndMinVerts(scene, takeFromObject)
 
     #get objects mesh
@@ -144,6 +148,7 @@
     # Update the mesh
     mesh.update()
 
+
 def applyScaleRotLoc(scene, obj):
     # Deselect All
     bpy.ops.object.select_all(action='DESELECT')
@@ -153,7 +158,8 @@
     scene.objects.active = obj
 
     bpy.ops.object.transform_apply(location=True, rotation=True, scale=True)
-   
+
+
 def totallyDeleteObject(scene, obj):
     scene.objects.unlink(obj)
     bpy.data.objects.remove(obj)
@@ -184,17 +190,19 @@
 
     return ob_new
 
+
 def getpdensitytexture(object):
-    
+
     for mslot in object.material_slots:
         mat = mslot.material
         for tslot in mat.texture_slots:
-            if tslot!= 'NoneType':
+            if tslot != 'NoneType':
                 tex = tslot.texture
                 if tex.type == 'POINT_DENSITY':
                     if tex.point_density.point_source == 'PARTICLE_SYSTEM':
                         return tex
-    
+
+
 def removeParticleSystemFromObj(scene, object):
 
     # Deselect All
@@ -208,16 +216,17 @@
 
     # Deselect All
     bpy.ops.object.select_all(action='DESELECT')
-    
+
+
 def convertParticlesToMesh(scene, particlesobj, destobj, replacemesh):
-    
+
     # Select the Destination object.
     destobj.select = True
     scene.objects.active = destobj
-    
+
     #Go to Edit Mode
-    bpy.ops.object.mode_set(mode='EDIT',toggle=False)
-    
+    bpy.ops.object.mode_set(mode='EDIT', toggle=False)
+
     #Delete everything in mesh if replace true
     if replacemesh:
         bpy.ops.mesh.select_all(action='SELECT')
@@ -240,6 +249,7 @@
     # Update the mesh.
     meshPnts.update()
 
+
 def combineObjects(scene, combined, listobjs):
     # scene is the current scene
     # combined is the object we want to combine everything into
@@ -266,9 +276,10 @@
             # Apply modifier
             bpy.ops.object.modifier_apply(apply_as='DATA', modifier=union[0].name)
 
+
 # Returns the action we want to take
 def getActionToDo(obj):
-    
+
     if not obj or obj.type != 'MESH':
         return 'NOT_OBJ_DO_NOTHING'
     elif obj is None:
@@ -276,7 +287,7 @@
     elif "CloudMember" in obj:
         if obj["CloudMember"] != None:
             if obj["CloudMember"] == "MainObj":
-                return 'DEGENERATE'            
+                return 'DEGENERATE'
             elif obj["CloudMember"] == "CreatedObj" and len(obj.particle_systems) > 0:
                 return 'CLOUD_CONVERT_TO_MESH'
             else:
@@ -286,7 +297,8 @@
     else:
         return 'DO_NOTHING'
 
-class VIEW3D_PT_tools_cloud(bpy.types.Panel):
+
+class VIEW3D_PT_tools_cloud(Panel):
     bl_space_type = 'VIEW_3D'
     bl_region_type = 'TOOLS'
 
@@ -314,7 +326,7 @@
         elif WhatToDo == 'CLOUD_DO_NOTHING':
             col.label(text="Must select")
             col.label(text="bound box")
-           
+
         elif WhatToDo == 'GENERATE':
             col.operator("cloud.generate_cloud", text="Generate Cloud")
 
@@ -327,10 +339,10 @@
             col.label(text="a cloud")
 
 
-class GenerateCloud(bpy.types.Operator):
+class GenerateCloud(Operator):
+    """Create a Cloud,Undo Cloud, or convert to Mesh Cloud depending on selection"""
     bl_idname = "cloud.generate_cloud"
     bl_label = "Generate Cloud"
-    bl_description = "Create a Cloud,Undo Cloud, or convert to Mesh Cloud depending on selection"
     bl_register = True
     bl_undo = True
 
@@ -339,7 +351,7 @@
         if not context.active_object:
             return False
         else:
-            return (context.active_object.type=='MESH')
+            return (context.active_object.type == 'MESH')
 
     def execute(self, context):
         # Make variable that is the current .blend file main data blocks
@@ -367,29 +379,29 @@
         if WhatToDo == 'DEGENERATE':
             # Degenerate Cloud
             mainObj = active_object
- 
+
             cloudMembers = active_object.children
- 
+
             createdObjects = []
-            definitionObjects  = []
+            definitionObjects = []
             for member in cloudMembers:
                 applyScaleRotLoc(scene, member)
                 if member["CloudMember"] == "CreatedObj":
                     createdObjects.append(member)
                 else:
                     definitionObjects.append(member)
- 
+
             for defObj in definitionObjects:
                 # Delete cloudmember data from objects
                 if "CloudMember" in defObj:
                     del(defObj["CloudMember"])
- 
+
             for createdObj in createdObjects:
                 totallyDeleteObject(scene, createdObj)
- 
+
             # Delete the blend_data object
             totallyDeleteObject(scene, mainObj)
- 
+
             # Select all of the left over boxes so people can immediately
             # press generate again if they want.
             for eachMember in definitionObjects:
@@ -400,18 +412,18 @@
         elif WhatToDo == 'CLOUD_CONVERT_TO_MESH':
 
             cloudParticles = active_object.particle_systems.active
-            
+
             bounds = active_object.parent
-            
+
             ###############Create CloudPnts for putting points in#########
             # Create a new object cloudPnts
             cloudPnts = addNewObject(scene, "CloudPoints", bounds)
             cloudPnts["CloudMember"] = "CreatedObj"
             cloudPnts.draw_type = 'WIRE'
             cloudPnts.hide_render = True
- 
-            makeParent(bounds, cloudPnts, scene) 
 
+            makeParent(bounds, cloudPnts, scene)
+
             convertParticlesToMesh(scene, cloudParticles, cloudPnts, True)
 
             removeParticleSystemFromObj(scene, active_object)
@@ -421,7 +433,7 @@
             pDensity.point_density.object = cloudPnts
 
             #Let's resize the bound box to be more accurate.
-            how_much_bigger =  pDensity.point_density.radius 
+            how_much_bigger = pDensity.point_density.radius
             makeObjectIntoBoundBox(scene, bounds, how_much_bigger, cloudPnts)
 
         else:
@@ -484,9 +496,9 @@
 
             bpy.ops.object.editmode_toggle()
             bpy.ops.mesh.select_all(action='SELECT')
-            
+
             #Don't subdivide object or smooth if smoothing box not checked.
-            if scene.cloudsmoothing:            
+            if scene.cloudsmoothing:
                 bpy.ops.mesh.subdivide(number_cuts=2, fractal=0, smoothness=1)
  #               bpy.ops.object.transform_apply(location=True)
                 bpy.ops.mesh.vertices_smooth(repeat=20)
@@ -518,7 +530,7 @@
             #Gravity does not effect the particle system
             eWeights = cloudParticles.settings.effector_weights
             eWeights.gravity = 0
-                
+
             ####################Create Volume Material####################
             # Deselect All
             bpy.ops.object.select_all(action='DESELECT')
@@ -528,7 +540,7 @@
             scene.objects.active = bounds
 
             # Turn bounds object into a box.  Use itself as a reference.
-            makeObjectIntoBoundBox(scene, bounds,  1.0, bounds)
+            makeObjectIntoBoundBox(scene, bounds, 1.0, bounds)
 
             # Delete all material slots in bounds object.
             for i in range(len(bounds.material_slots)):
@@ -547,7 +559,7 @@
             mVolume.scattering = scattering
             mVolume.density = 0
             mVolume.density_scale = densityScale
-            mVolume.transmission_color = [3, 3, 3]
+            mVolume.transmission_color = 3.0, 3.0, 3.0
             mVolume.step_size = 0.1
             mVolume.use_light_cache = True
             mVolume.cache_resolution = 45
@@ -567,7 +579,7 @@
 
             # Add a Point Density texture
             pDensity = blend_data.textures.new("CloudPointDensity", 'POINT_DENSITY')
-            
+
             mtex = cloudMaterial.texture_slots.add()
             mtex.texture = pDensity
             mtex.texture_coords = 'GLOBAL'

@@ Diff output truncated at 10240 characters. @@


More information about the Bf-extensions-cvs mailing list