[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [58161] branches/soc-2013-bge/release/ scripts/startup: Adding an operator to generate levels of detail from the selected object using the decimate modifier .

Daniel Stokes kupomail at gmail.com
Thu Jul 11 03:05:17 CEST 2013


Revision: 58161
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=58161
Author:   kupoman
Date:     2013-07-11 01:05:14 +0000 (Thu, 11 Jul 2013)
Log Message:
-----------
Adding an operator to generate levels of detail from the selected object using the decimate modifier. This operator has options to control the number of levels, the amount of reduction, and whether or not to "package" the levels. Packaging means the levels of details are generated in such a way that they can easily be used as dupligroups.

Modified Paths:
--------------
    branches/soc-2013-bge/release/scripts/startup/bl_operators/object.py
    branches/soc-2013-bge/release/scripts/startup/bl_ui/properties_object.py

Modified: branches/soc-2013-bge/release/scripts/startup/bl_operators/object.py
===================================================================
--- branches/soc-2013-bge/release/scripts/startup/bl_operators/object.py	2013-07-10 20:29:34 UTC (rev 58160)
+++ branches/soc-2013-bge/release/scripts/startup/bl_operators/object.py	2013-07-11 01:05:14 UTC (rev 58161)
@@ -848,4 +848,79 @@
             while 'CANCELLED' not in bpy.ops.object.lod_remove():
                 pass
 
-        return {'FINISHED'}
\ No newline at end of file
+        return {'FINISHED'}
+
+
+class LodGenerate(Operator):
+    """Generates levels of detail using the decimate modifier"""
+    bl_idname = "object.lod_generate"
+    bl_label = "Generate Levels of Detail"
+    bl_options = {'REGISTER', 'UNDO'}
+
+    count = bpy.props.IntProperty(name="Count", default=3)
+    target = bpy.props.FloatProperty(name="Target Size", default=0.1)
+    package = bpy.props.BoolProperty(name="Package into Group", default=False)
+    
+    @classmethod
+    def poll(cls, context):
+        return (context.active_object is not None)
+
+    def execute(self, context):
+        scene = bpy.context.scene
+        ob = scene.objects.active
+
+        lod_name = ob.name
+        lod_suffix = "lod"
+        lod_prefix = ""
+        if lod_name.lower().endswith("lod0"):
+            lod_suffix = lod_name[-3:-1]
+            lod_name = lod_name[:-3]
+        elif lod_name.lower().startswith("lod0"):
+            lod_suffix = ""
+            lod_prefix = lod_name[:3]
+            lod_name = lod_name[4:]
+
+        group_name = lod_name.strip(' ._')
+        if self.package:
+            try:
+                bpy.ops.object.group_link(group=group_name)
+            except TypeError:
+                bpy.ops.group.create(name=group_name)
+
+        step = (1.0 - self.target) / (self.count - 1)
+        for i in range(1, self.count):
+            scene.objects.active = ob
+            bpy.ops.object.duplicate()
+            bpy.ops.object.lod_add()
+            lod = bpy.context.selected_objects[0]
+
+            if lod_prefix:
+                lod.name = lod_prefix + str(i) + lod_name
+            else:
+                lod.name = lod_name + lod_suffix  + str(i)
+
+            lod.location.y = ob.location.y + 3.0 * i
+
+            if i == 1:
+                modifier = lod.modifiers.new("lod_decimate", "DECIMATE")
+            else:
+                modifier = lod.modifiers[-1]
+                
+            modifier.ratio = 1.0 - step*(i)
+
+            ob.lod_levels[i].object = lod
+
+            if self.package:
+                bpy.ops.object.group_link(group=group_name)
+                lod.parent = ob
+
+        if self.package:
+            for level in ob.lod_levels[1:]:
+                level.object.hide = level.object.hide_render = True
+
+        lod.select = False
+        ob.select = True
+        scene.objects.active = ob
+
+        return {'FINISHED'}
+

Modified: branches/soc-2013-bge/release/scripts/startup/bl_ui/properties_object.py
===================================================================
--- branches/soc-2013-bge/release/scripts/startup/bl_ui/properties_object.py	2013-07-10 20:29:34 UTC (rev 58160)
+++ branches/soc-2013-bge/release/scripts/startup/bl_ui/properties_object.py	2013-07-11 01:05:14 UTC (rev 58161)
@@ -133,7 +133,7 @@
         layout = self.layout
         
         layout.operator("object.lod_by_name", text="Set By Name")
-        # layout.operator("object.lod_by_name", text="Generate")
+        layout.operator("object.lod_generate", text="Generate")
         layout.operator("object.lod_clear_all", text="Clear All", icon='PANEL_CLOSE')
 
 




More information about the Bf-blender-cvs mailing list