[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [57719] branches/soc-2013-bge/source/ blender: Adding code to detect when an LoD switch is needed in the viewport .

Daniel Stokes kupomail at gmail.com
Tue Jun 25 01:13:40 CEST 2013


Revision: 57719
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=57719
Author:   kupoman
Date:     2013-06-24 23:13:40 +0000 (Mon, 24 Jun 2013)
Log Message:
-----------
Adding code to detect when an LoD switch is needed in the viewport. It currently just prints to the console. This print will be replaced with actual switching code in the near future.

Modified Paths:
--------------
    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/space_view3d/view3d_draw.c
    branches/soc-2013-bge/source/blender/makesdna/DNA_object_types.h

Modified: branches/soc-2013-bge/source/blender/blenkernel/BKE_object.h
===================================================================
--- branches/soc-2013-bge/source/blender/blenkernel/BKE_object.h	2013-06-24 22:48:00 UTC (rev 57718)
+++ branches/soc-2013-bge/source/blender/blenkernel/BKE_object.h	2013-06-24 23:13:40 UTC (rev 57719)
@@ -86,6 +86,7 @@
 
 void BKE_object_lod_add(struct Object *ob);
 void BKE_object_lod_remove(struct Object *ob, int level);
+void BKE_object_lod_update(struct Object *ob, float camera_position[3]);
 
 struct Object *BKE_object_copy_ex(struct Main *bmain, struct Object *ob, int copy_caches);
 struct Object *BKE_object_copy(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-24 22:48:00 UTC (rev 57718)
+++ branches/soc-2013-bge/source/blender/blenkernel/intern/object.c	2013-06-24 23:13:40 UTC (rev 57719)
@@ -909,6 +909,7 @@
 	base->distance = 0.0;
 	base->use_logic = base->use_mat = base->use_mesh = 1;
 	base->source = ob;
+	ob->currentlod = base;
 
 	return ob;
 }
@@ -958,6 +959,45 @@
 	BLI_remlink(&ob->lodlevels, rem);
 }
 
+static LodLevel* lod_level_select(struct Object *ob, float cam_loc[3])
+{
+	LodLevel *current = ob->currentlod;
+	float ob_loc[3], delta[3];
+	float distance2;
+
+	if (!current) return NULL;
+
+	copy_v3_v3(ob_loc, ob->obmat[3]);
+	sub_v3_v3v3(delta, ob_loc, cam_loc);
+	distance2 = len_squared_v3(delta);
+
+	/* check for higher LoD */
+	if (distance2 < current->distance*current->distance) {
+		while (current->prev && distance2 > current->prev->distance*current->prev->distance) {
+			current = current->prev;
+		}
+	}
+	/* check for lower LoD */
+	else {
+		while (current->next && distance2 > current->next->distance*current->next->distance) {
+			current = current->next;
+		}
+	}
+
+	return current;
+}
+
+void BKE_object_lod_update(struct Object *ob, float camera_position[3])
+{
+	LodLevel* cur_level = ob->currentlod;
+	LodLevel* new_level = lod_level_select(ob, camera_position);
+
+	if (new_level != cur_level) {
+		printf("Level Switch!\n");
+		ob->currentlod = new_level;
+	}
+}
+
 SoftBody *copy_softbody(SoftBody *sb, int copy_caches)
 {
 	SoftBody *sbn;

Modified: branches/soc-2013-bge/source/blender/editors/space_view3d/view3d_draw.c
===================================================================
--- branches/soc-2013-bge/source/blender/editors/space_view3d/view3d_draw.c	2013-06-24 22:48:00 UTC (rev 57718)
+++ branches/soc-2013-bge/source/blender/editors/space_view3d/view3d_draw.c	2013-06-24 23:13:40 UTC (rev 57719)
@@ -3227,6 +3227,18 @@
 	}
 }
 
+static void update_lods(Scene *scene, float camera_pos[3])
+{
+	Scene *sce_iter;
+	Base *base;
+	Object *ob;
+
+	for (SETLOOPER(scene, sce_iter, base)) {
+		ob = base->object;
+		BKE_object_lod_update(ob, camera_pos);
+	}
+}
+
 /* warning: this function has duplicate drawing in ED_view3d_draw_offscreen() */
 static void view3d_main_area_draw_objects(const bContext *C, ARegion *ar, const char **grid_unit)
 {
@@ -3234,6 +3246,7 @@
 	View3D *v3d = CTX_wm_view3d(C);
 	RegionView3D *rv3d = CTX_wm_region_view3d(C);
 	Base *base;
+	float camera_pos[3];
 	unsigned int lay_used;
 
 	/* shadow buffers, before we setup matrices */
@@ -3249,6 +3262,10 @@
 	/* setup view matrices */
 	view3d_main_area_setup_view(scene, v3d, ar, NULL, NULL);
 
+	/* Make sure LoDs are up to date */
+	copy_v3_v3(camera_pos, rv3d->viewinv[3]);
+	update_lods(scene, camera_pos);
+
 	/* clear the background */
 	view3d_main_area_clear(scene, v3d, ar);
 

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-24 22:48:00 UTC (rev 57718)
+++ branches/soc-2013-bge/source/blender/makesdna/DNA_object_types.h	2013-06-24 23:13:40 UTC (rev 57719)
@@ -285,6 +285,7 @@
 	float ima_ofs[2];		/* offset for image empties */
 
 	ListBase lodlevels;		/* contains data for levels of detail */
+	LodLevel *currentlod;
 } Object;
 
 /* Warning, this is not used anymore because hooks are now modifiers */




More information about the Bf-blender-cvs mailing list