[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [57627] branches/soc-2013-bge: The start of the new level of detail system.

Daniel Stokes kupomail at gmail.com
Fri Jun 21 09:04:54 CEST 2013


Revision: 57627
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=57627
Author:   kupoman
Date:     2013-06-21 07:04:54 +0000 (Fri, 21 Jun 2013)
Log Message:
-----------
The start of the new level of detail system. The UI properly modifies level of detail information on the object, and allows for adding and removing levels of detail. No level of detail selection or switching occurs yet.

Modified Paths:
--------------
    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/CMakeLists.txt
    branches/soc-2013-bge/source/blender/editors/object/object_intern.h
    branches/soc-2013-bge/source/blender/editors/object/object_ops.c
    branches/soc-2013-bge/source/blender/makesdna/DNA_object_types.h
    branches/soc-2013-bge/source/blender/makesrna/intern/rna_object.c

Added Paths:
-----------
    branches/soc-2013-bge/source/blender/editors/object/object_lod.c

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-06-21 06:56:43 UTC (rev 57626)
+++ branches/soc-2013-bge/release/scripts/startup/bl_ui/properties_object.py	2013-06-21 07:04:54 UTC (rev 57627)
@@ -126,6 +126,33 @@
             sub.prop(ob, "lock_rotation_w", text="W")
 
 
+class OBJECT_PT_levels_of_detail(ObjectButtonsPanel, Panel):
+    bl_label = "Levels of Detail"
+
+    def draw(self, context):
+        layout = self.layout
+        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="")
+
+
 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-06-21 06:56:43 UTC (rev 57626)
+++ branches/soc-2013-bge/source/blender/blenkernel/BKE_object.h	2013-06-21 07:04:54 UTC (rev 57627)
@@ -84,6 +84,9 @@
 struct Object *BKE_object_add(struct Main *bmain, struct Scene *scene, int type);
 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);
+
 struct Object *BKE_object_copy_ex(struct Main *bmain, struct Object *ob, int copy_caches);
 struct Object *BKE_object_copy(struct Object *ob);
 void BKE_object_make_local(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-06-21 06:56:43 UTC (rev 57626)
+++ branches/soc-2013-bge/source/blender/blenkernel/intern/object.c	2013-06-21 07:04:54 UTC (rev 57627)
@@ -824,6 +824,7 @@
 Object *BKE_object_add_only_object(Main *bmain, int type, const char *name)
 {
 	Object *ob;
+	LodLevel *base;
 
 	if (!name)
 		name = get_obdata_defname(type);
@@ -902,6 +903,13 @@
 	/* Animation Visualization defaults */
 	animviz_settings_init(&ob->avs);
 
+	/* LoD defaults */
+	BKE_object_lod_add(ob);
+	base = BLI_findlink(&ob->lodlevels, 0);
+	base->distance = 0.0;
+	base->use_logic = base->use_mat = base->use_mesh = 1;
+	base->source = ob;
+
 	return ob;
 }
 
@@ -928,6 +936,28 @@
 	return ob;
 }
 
+void BKE_object_lod_add(struct Object *ob)
+{
+	LodLevel *lod = MEM_callocN(sizeof(LodLevel), "LoD Level");
+	LodLevel *last = ob->lodlevels.last;
+	
+	lod->distance = (last) ? last->distance + 10.0f : 10.0f;
+	lod->use_mesh = lod->use_mat = 1;
+
+	BLI_addtail(&ob->lodlevels, lod);
+}
+
+void BKE_object_lod_remove(struct Object *ob, int level)
+{
+	LodLevel *rem;
+
+	if (level < 1 || level > BLI_countlist(&ob->lodlevels))
+		return;
+
+	rem = BLI_findlink(&ob->lodlevels, level);
+	BLI_remlink(&ob->lodlevels, rem);
+}
+
 SoftBody *copy_softbody(SoftBody *sb, int copy_caches)
 {
 	SoftBody *sbn;

Modified: branches/soc-2013-bge/source/blender/editors/object/CMakeLists.txt
===================================================================
--- branches/soc-2013-bge/source/blender/editors/object/CMakeLists.txt	2013-06-21 06:56:43 UTC (rev 57626)
+++ branches/soc-2013-bge/source/blender/editors/object/CMakeLists.txt	2013-06-21 07:04:54 UTC (rev 57627)
@@ -47,6 +47,7 @@
 	object_group.c
 	object_hook.c
 	object_lattice.c
+	object_lod.c
 	object_modifier.c
 	object_ops.c
 	object_relations.c

Modified: branches/soc-2013-bge/source/blender/editors/object/object_intern.h
===================================================================
--- branches/soc-2013-bge/source/blender/editors/object/object_intern.h	2013-06-21 06:56:43 UTC (rev 57626)
+++ branches/soc-2013-bge/source/blender/editors/object/object_intern.h	2013-06-21 07:04:54 UTC (rev 57627)
@@ -240,5 +240,9 @@
 /* object_bake.c */
 void OBJECT_OT_bake_image(wmOperatorType *ot);
 
+/* object_lod.c */
+void OBJECT_OT_lod_add(struct wmOperatorType *ot);
+void OBJECT_OT_lod_remove(struct wmOperatorType *ot);
+
 #endif /* __OBJECT_INTERN_H__ */
 

Added: branches/soc-2013-bge/source/blender/editors/object/object_lod.c
===================================================================
--- branches/soc-2013-bge/source/blender/editors/object/object_lod.c	                        (rev 0)
+++ branches/soc-2013-bge/source/blender/editors/object/object_lod.c	2013-06-21 07:04:54 UTC (rev 57627)
@@ -0,0 +1,98 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) Blender Foundation
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/editors/object/object_lod.c
+ *  \ingroup edobj
+ */
+
+
+#include "DNA_object_types.h"
+
+#include "BKE_context.h"
+#include "BKE_object.h"
+
+#include "ED_screen.h"
+#include "ED_object.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+#include "RNA_access.h"
+#include "RNA_define.h"
+#include "RNA_enum_types.h"
+
+#include "object_intern.h"
+
+static int object_lod_add_exec(bContext *C, wmOperator *op)
+{
+	Object *ob = ED_object_context(C);
+	BKE_object_lod_add(ob);
+	return OPERATOR_FINISHED;
+}
+
+void OBJECT_OT_lod_add(wmOperatorType *ot)
+{
+	PropertyRNA *prop;
+
+	/* identifiers */
+	ot->name = "Add LoD";
+	ot->description = "Add a level of detail to this object";
+	ot->idname = "OBJECT_OT_lod_add";
+
+	/* api callbacks */
+	ot->exec = object_lod_add_exec;
+	ot->poll = ED_operator_objectmode;
+
+	/* flags */
+	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+}
+
+static int object_lod_remove_exec(bContext *C, wmOperator *op)
+{
+	Object *ob = ED_object_context(C);
+	int index = RNA_int_get(op->ptr, "index");
+	BKE_object_lod_remove(ob, index);
+	return OPERATOR_FINISHED;
+}
+
+void OBJECT_OT_lod_remove(wmOperatorType *ot)
+{
+	/* identifiers */
+	ot->name = "Remove LoD";
+	ot->description = "Remove a level of detail from this object";
+	ot->idname = "OBJECT_OT_lod_remove";
+
+	/* api callbacks */
+	ot->exec = object_lod_remove_exec;
+	ot->poll = ED_operator_objectmode;
+
+	/* flags */
+	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+
+	/* properties */
+	ot->prop = RNA_def_int(ot->srna, "index", 1, 1, INT_MAX, "Index", "", 1, INT_MAX);
+}
\ No newline at end of file

Modified: branches/soc-2013-bge/source/blender/editors/object/object_ops.c
===================================================================
--- branches/soc-2013-bge/source/blender/editors/object/object_ops.c	2013-06-21 06:56:43 UTC (rev 57626)
+++ branches/soc-2013-bge/source/blender/editors/object/object_ops.c	2013-06-21 07:04:54 UTC (rev 57627)
@@ -229,6 +229,9 @@
 
 	WM_operatortype_append(OBJECT_OT_bake_image);
 	WM_operatortype_append(OBJECT_OT_drop_named_material);
+
+	WM_operatortype_append(OBJECT_OT_lod_add);
+	WM_operatortype_append(OBJECT_OT_lod_remove);
 }
 
 void ED_operatormacros_object(void)

Modified: branches/soc-2013-bge/source/blender/makesdna/DNA_object_types.h
===================================================================
--- branches/soc-2013-bge/source/blender/makesdna/DNA_object_types.h	2013-06-21 06:56:43 UTC (rev 57626)
+++ branches/soc-2013-bge/source/blender/makesdna/DNA_object_types.h	2013-06-21 07:04:54 UTC (rev 57627)
@@ -102,6 +102,13 @@
 /* boundbox flag */
 #define OB_BB_DISABLED	1
 
+typedef struct LodLevel {
+	struct LodLevel *next, *prev;
+	struct Object *source;
+	char use_mesh, use_mat, use_logic, pad;
+	float distance;
+} LodLevel;
+
 typedef struct Object {
 	ID id;
 	struct AnimData *adt;		/* animation data (must be immediately after id for utilities to use it) */ 
@@ -276,6 +283,8 @@
 	struct RigidBodyCon *rigidbody_constraint;	/* settings for Bullet constraint */
 
 	float ima_ofs[2];		/* offset for image empties */
+
+	ListBase lodlevels;		/* contains data for levels of detail */
 } Object;
 
 /* Warning, this is not used anymore because hooks are now modifiers */

Modified: branches/soc-2013-bge/source/blender/makesrna/intern/rna_object.c
===================================================================
--- branches/soc-2013-bge/source/blender/makesrna/intern/rna_object.c	2013-06-21 06:56:43 UTC (rev 57626)
+++ branches/soc-2013-bge/source/blender/makesrna/intern/rna_object.c	2013-06-21 07:04:54 UTC (rev 57627)
@@ -2005,6 +2005,41 @@
 }
 
 
+static void rna_def_object_lodlevel(BlenderRNA* brna)
+{
+	StructRNA *srna;
+	PropertyRNA *prop;
+
+	srna = RNA_def_struct(brna, "LodLevel", NULL);
+	RNA_def_struct_sdna(srna, "LodLevel");
+
+	prop = RNA_def_property(srna, "distance", PROP_FLOAT, PROP_DISTANCE);
+	RNA_def_property_float_sdna(prop, NULL, "distance");
+	RNA_def_property_ui_text(prop, "Distance", "Distance to begin using this level of detail");
+
+	prop = RNA_def_property(srna, "object", PROP_POINTER, PROP_NONE);
+	RNA_def_property_pointer_sdna(prop, NULL, "source");
+	RNA_def_property_struct_type(prop, "Object");
+	RNA_def_property_flag(prop, PROP_EDITABLE);

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list