[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [23645] branches/soc-2009-jaguarandi/ source/blender/render/intern/source/rayobject_blibvh.c: blibvh safe for 64bits

Andre Susano Pinto andresusanopinto at gmail.com
Tue Oct 6 01:30:03 CEST 2009


Revision: 23645
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=23645
Author:   jaguarandi
Date:     2009-10-06 01:30:00 +0200 (Tue, 06 Oct 2009)

Log Message:
-----------
blibvh safe for 64bits

Modified Paths:
--------------
    branches/soc-2009-jaguarandi/source/blender/render/intern/source/rayobject_blibvh.c

Modified: branches/soc-2009-jaguarandi/source/blender/render/intern/source/rayobject_blibvh.c
===================================================================
--- branches/soc-2009-jaguarandi/source/blender/render/intern/source/rayobject_blibvh.c	2009-10-05 23:04:40 UTC (rev 23644)
+++ branches/soc-2009-jaguarandi/source/blender/render/intern/source/rayobject_blibvh.c	2009-10-05 23:30:00 UTC (rev 23645)
@@ -67,6 +67,7 @@
 typedef struct BVHObject
 {
 	RayObject rayobj;
+	RayObject **leafs, **next_leaf;
 	BVHTree *bvh;
 	float bb[2][3];
 
@@ -80,15 +81,23 @@
 	
 	obj->rayobj.api = &bvh_api;
 	obj->bvh = BLI_bvhtree_new(size, 0.0, 4, 6);
+	obj->next_leaf = obj->leafs = (RayObject**)MEM_callocN(size*sizeof(RayObject*), "BVHObject leafs");
 	
 	INIT_MINMAX(obj->bb[0], obj->bb[1]);
 	return RE_rayobject_unalignRayAPI((RayObject*) obj);
 }
 
+struct BVHCallbackUserData
+{
+	Isect *isec;
+	RayObject **leafs;
+};
+
 static void bvh_callback(void *userdata, int index, const BVHTreeRay *ray, BVHTreeRayHit *hit)
 {
-	Isect *isec = (Isect*)userdata;
-	RayObject *face = (RayObject*)index;
+	struct BVHCallbackUserData *data = (struct BVHCallbackUserData*)userdata;
+	Isect *isec = data->isec;
+	RayObject *face = data->leafs[index];
 	
 	if(RE_rayobject_intersect(face,isec))
 	{
@@ -106,6 +115,9 @@
 	BVHObject *obj = (BVHObject*)o;
 	BVHTreeRayHit hit;
 	float dir[3];
+	struct BVHCallbackUserData data;
+	data.isec = isec;
+	data.leafs = obj->leafs;
 
 	VECCOPY(dir, isec->vec);
 	Normalize(dir);
@@ -113,7 +125,7 @@
 	hit.index = 0;
 	hit.dist = isec->labda*isec->dist;
 	
-	return BLI_bvhtree_ray_cast(obj->bvh, isec->start, dir, 0.0, &hit, bvh_callback, isec);
+	return BLI_bvhtree_ray_cast(obj->bvh, isec->start, dir, 0.0, &hit, bvh_callback, (void*)&data);
 }
 
 static void RE_rayobject_blibvh_add(RayObject *o, RayObject *ob)
@@ -126,7 +138,8 @@
 	DO_MIN(min_max  , obj->bb[0]);
 	DO_MAX(min_max+3, obj->bb[1]);
 	
-	BLI_bvhtree_insert(obj->bvh, (int)ob, min_max, 2 );	
+	BLI_bvhtree_insert(obj->bvh, obj->next_leaf - obj->leafs, min_max, 2 );	
+	*(obj->next_leaf++) = ob;
 }
 
 static void RE_rayobject_blibvh_done(RayObject *o)
@@ -142,6 +155,9 @@
 	if(obj->bvh)
 		BLI_bvhtree_free(obj->bvh);
 
+	if(obj->leafs)
+		MEM_freeN(obj->leafs);
+
 	MEM_freeN(obj);
 }
 





More information about the Bf-blender-cvs mailing list