[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [58056] branches/soc-2013-bge: Reworking the level of detail UI so that the add button is on the bottom and a menu has been added for level of detail tools .

Daniel Stokes kupomail at gmail.com
Sun Jul 7 07:19:29 CEST 2013


Revision: 58056
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=58056
Author:   kupoman
Date:     2013-07-07 05:19:28 +0000 (Sun, 07 Jul 2013)
Log Message:
-----------
Reworking the level of detail UI so that the add button is on the bottom and a menu has been added for level of detail tools. So far these tools include a set by name operator that finds appropriately named models in the scene to use for detail levels, and a clear all operator for removing all levels of detail from an object.

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
    branches/soc-2013-bge/source/blender/blenkernel/BKE_object.h
    branches/soc-2013-bge/source/blender/blenkernel/intern/object.c
    branches/soc-2013-bge/source/blender/editors/object/object_lod.c

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-07 03:58:34 UTC (rev 58055)
+++ branches/soc-2013-bge/release/scripts/startup/bl_operators/object.py	2013-07-07 05:19:28 UTC (rev 58056)
@@ -775,3 +775,77 @@
         ob.users_group[group].dupli_offset = scene.cursor_location
 
         return {'FINISHED'}
+
+
+
+class LodByName(Operator):
+    """Add levels of detail to this object based on object names"""
+    bl_idname = "object.lod_by_name"
+    bl_label = "Setup Level of Details By Name"
+    bl_options = {'REGISTER', 'UNDO'}
+
+    @classmethod
+    def poll(cls, context):
+        return (context.active_object is not None)
+
+    def execute(self, context):
+        scene = context.scene
+        ob = context.active_object
+        
+        prefix = ""
+        suffix = ""
+        name = ""
+        ob.name.lower()
+        if ob.name.lower().startswith("lod0"):
+            prefix = ob.name[:4]
+            name = ob.name[4:]
+        elif ob.name.lower().endswith("lod0"):
+            name = ob.name[:-4]
+            suffix = ob.name[-4:]
+        else:
+            return {'CANCELLED'}
+
+        level = 0
+        while True:
+            level += 1
+
+            if prefix:
+                prefix = prefix[:3] + str(level)
+            if suffix:
+                suffix = suffix[:3] + str(level)
+
+            lod = None
+            try:
+                lod = bpy.data.objects[prefix + name + suffix]
+            except KeyError:
+                break
+
+            try:
+                ob.lod_levels[level]
+            except IndexError:
+                bpy.ops.object.lod_add()
+
+            ob.lod_levels[level].object = lod
+
+        return {'FINISHED'}
+
+
+class LodClearAll(Operator):
+    """Remove all levels of detail from this object"""
+    bl_idname = "object.lod_clear_all"
+    bl_label = "Clear All Levels of Detail"
+    bl_options = {'REGISTER', 'UNDO'}
+
+    @classmethod
+    def poll(cls, context):
+        return (context.active_object is not None)
+
+    def execute(self, context):
+        scene = context.scene
+        ob = context.active_object
+
+        if ob.lod_levels:
+            while 'CANCELLED' not in bpy.ops.object.lod_remove():
+                pass
+
+        return {'FINISHED'}
\ No newline at end of file

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-07 03:58:34 UTC (rev 58055)
+++ branches/soc-2013-bge/release/scripts/startup/bl_ui/properties_object.py	2013-07-07 05:19:28 UTC (rev 58056)
@@ -18,7 +18,7 @@
 
 # <pep8 compliant>
 import bpy
-from bpy.types import Panel
+from bpy.types import Menu, Panel
 from rna_prop_ui import PropertyPanel
 
 
@@ -126,6 +126,17 @@
             sub.prop(ob, "lock_rotation_w", text="W")
 
 
+class OBJECT_MT_lod_tools(Menu):
+    bl_label = "Level Of Detail Tools"
+
+    def draw(self, context):
+        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_clear_all", text="Clear All", icon='PANEL_CLOSE')
+
+
 class OBJECT_PT_levels_of_detail(ObjectButtonsPanel, Panel):
     bl_label = "Levels of Detail"
 
@@ -134,25 +145,25 @@
         ob = context.object
 
         col = layout.column()
-        col.operator("object.lod_add", text="Add Level of Detail", icon='ZOOMIN')
 
         for i, level in enumerate(ob.lod_levels):
             if i == 0: continue
-            # col.label("LOD%d:" %(i))
             box = col.box()
             row = box.row()
             row.prop(level, "object", text="")
             row.operator("object.lod_remove", text="", icon='PANEL_CLOSE').index = i
 
-            # split = box.split(0.6)
             row = box.row()
             row.prop(level, "distance")
             row = row.row(align=True)
             row.prop(level, "use_mesh", text="")
             row.prop(level, "use_material", text="")
-            # row.prop(level, "use_logic", text="")
 
+        row = col.row(align=True)
+        row.operator("object.lod_add", text="Add", icon='ZOOMIN')
+        row.menu("OBJECT_MT_lod_tools", text="", icon='TRIA_DOWN')
 
+
 class OBJECT_PT_relations(ObjectButtonsPanel, Panel):
     bl_label = "Relations"
 

Modified: branches/soc-2013-bge/source/blender/blenkernel/BKE_object.h
===================================================================
--- branches/soc-2013-bge/source/blender/blenkernel/BKE_object.h	2013-07-07 03:58:34 UTC (rev 58055)
+++ branches/soc-2013-bge/source/blender/blenkernel/BKE_object.h	2013-07-07 05:19:28 UTC (rev 58056)
@@ -84,7 +84,7 @@
 void *BKE_object_obdata_add_from_type(struct Main *bmain, int type);
 
 void BKE_object_lod_add(struct Object *ob);
-void BKE_object_lod_remove(struct Object *ob, int level);
+bool BKE_object_lod_remove(struct Object *ob, int level);
 bool BKE_object_lod_update(struct Object *ob, float camera_position[3]);
 bool BKE_object_lod_check(struct Object *ob, struct Scene *scene);
 struct Object *BKE_object_lod_meshob_get(struct Object *ob);

Modified: branches/soc-2013-bge/source/blender/blenkernel/intern/object.c
===================================================================
--- branches/soc-2013-bge/source/blender/blenkernel/intern/object.c	2013-07-07 03:58:34 UTC (rev 58055)
+++ branches/soc-2013-bge/source/blender/blenkernel/intern/object.c	2013-07-07 05:19:28 UTC (rev 58056)
@@ -975,12 +975,12 @@
 	BLI_addtail(&ob->lodlevels, lod);
 }
 
-void BKE_object_lod_remove(struct Object *ob, int level)
+bool BKE_object_lod_remove(struct Object *ob, int level)
 {
 	LodLevel *rem;
 
-	if (level < 1 || level > BLI_countlist(&ob->lodlevels))
-		return;
+	if (level < 1 || level > BLI_countlist(&ob->lodlevels) - 1)
+		return false;
 
 	rem = BLI_findlink(&ob->lodlevels, level);
 
@@ -990,6 +990,8 @@
 
 	BLI_remlink(&ob->lodlevels, rem);
 	MEM_freeN(rem);
+
+	return true;
 }
 
 static LodLevel* lod_level_select(struct Object *ob, float cam_loc[3])

Modified: branches/soc-2013-bge/source/blender/editors/object/object_lod.c
===================================================================
--- branches/soc-2013-bge/source/blender/editors/object/object_lod.c	2013-07-07 03:58:34 UTC (rev 58055)
+++ branches/soc-2013-bge/source/blender/editors/object/object_lod.c	2013-07-07 05:19:28 UTC (rev 58056)
@@ -76,7 +76,8 @@
 {
 	Object *ob = ED_object_context(C);
 	int index = RNA_int_get(op->ptr, "index");
-	BKE_object_lod_remove(ob, index);
+	if(!BKE_object_lod_remove(ob, index))
+		return OPERATOR_CANCELLED;
 
 	WM_event_add_notifier(C, NC_LOD, CTX_wm_view3d(C));
 	return OPERATOR_FINISHED;




More information about the Bf-blender-cvs mailing list