[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [22240] branches/soc-2009-jaguarandi/ source/blender: experiences with memory organization ( store the vertexs coords on RayFace)

André Pinto andresusanopinto at gmail.com
Wed Aug 5 16:40:38 CEST 2009


Revision: 22240
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=22240
Author:   jaguarandi
Date:     2009-08-05 16:40:38 +0200 (Wed, 05 Aug 2009)

Log Message:
-----------
experiences with memory organization (store the vertexs coords on RayFace)

Modified Paths:
--------------
    branches/soc-2009-jaguarandi/source/blender/editors/armature/meshlaplacian.c
    branches/soc-2009-jaguarandi/source/blender/render/intern/include/rayobject.h
    branches/soc-2009-jaguarandi/source/blender/render/intern/source/rayobject.c
    branches/soc-2009-jaguarandi/source/blender/render/intern/source/rayshade.c

Removed Paths:
-------------
    branches/soc-2009-jaguarandi/source/blender/render/intern/source/rayobject_mesh.c

Modified: branches/soc-2009-jaguarandi/source/blender/editors/armature/meshlaplacian.c
===================================================================
--- branches/soc-2009-jaguarandi/source/blender/editors/armature/meshlaplacian.c	2009-08-05 14:38:15 UTC (rev 22239)
+++ branches/soc-2009-jaguarandi/source/blender/editors/armature/meshlaplacian.c	2009-08-05 14:40:38 UTC (rev 22240)
@@ -401,7 +401,8 @@
 	MFace *mface;
 	int a;
 
-	sys->heat.raytree = RE_rayobject_mesh_create(me, me);
+	assert(0); //TODO
+	//sys->heat.raytree = RE_rayobject_mesh_create(me, me);
 
 	sys->heat.vface = MEM_callocN(sizeof(MFace*)*me->totvert, "HeatVFaces");
 	for(a=0, mface=me->mface; a<me->totface; a++, mface++) {

Modified: branches/soc-2009-jaguarandi/source/blender/render/intern/include/rayobject.h
===================================================================
--- branches/soc-2009-jaguarandi/source/blender/render/intern/include/rayobject.h	2009-08-05 14:38:15 UTC (rev 22239)
+++ branches/soc-2009-jaguarandi/source/blender/render/intern/include/rayobject.h	2009-08-05 14:40:38 UTC (rev 22240)
@@ -34,6 +34,7 @@
 #endif
 
 #include "RE_raytrace.h"
+#include "render_types.h"
 #include <float.h>
 
 
@@ -75,16 +76,38 @@
 	You actually don't need to care about this if you are only using the API
 	described on RE_raytrace.h
  */
+
+/* defines where coordinates of rayface primitives are stored */
+#define RE_RAYFACE_COORDS_LOCAL
+//#define RE_RAYFACE_COORDS_POINTER
+//#define RE_RAYFACE_COORDS_VLAKREN
  
 typedef struct RayFace
 {
+#ifdef RE_RAYFACE_COORDS_LOCAL
+	float v1[4], v2[4], v3[4], v4[3];
+	int quad;
+	void *ob;
+	void *face;
+#elif defined(RE_RAYFACE_COORDS_POINTER)
 	float *v1, *v2, *v3, *v4;
-	
 	void *ob;
 	void *face;
+#elif defined(RE_RAYFACE_COORDS_VLAKREN)
+	void *ob;
+	void *face;
+#endif
 	
 } RayFace;
 
+#ifdef RE_RAYFACE_COORDS_LOCAL
+#	define RE_rayface_isQuad(a) ((a)->quad)
+#elif defined(RE_RAYFACE_COORDS_POINTER)
+#	define RE_rayface_isQuad(a) ((a)->v4)
+#elif defined(RE_RAYFACE_COORDS_VLAKREN)
+#endif
+
+
 struct RayObject
 {
 	struct RayObjectAPI *api;
@@ -121,6 +144,11 @@
 #define RayObject_isRayAPI(o)	((((intptr_t)o)&3) == 2)
 
 /*
+ * Loads a VlakRen on a RayFace
+ */
+void RE_rayface_from_vlak(RayFace *face, ObjectInstanceRen *obi, VlakRen *vlr);
+
+/*
  * Extend min/max coords so that the rayobject is inside them
  */
 void RE_rayobject_merge_bb(RayObject *ob, float *min, float *max);

Modified: branches/soc-2009-jaguarandi/source/blender/render/intern/source/rayobject.c
===================================================================
--- branches/soc-2009-jaguarandi/source/blender/render/intern/source/rayobject.c	2009-08-05 14:38:15 UTC (rev 22239)
+++ branches/soc-2009-jaguarandi/source/blender/render/intern/source/rayobject.c	2009-08-05 14:40:38 UTC (rev 22240)
@@ -165,7 +165,7 @@
 
 	VECCOPY(co1, face->v1);
 	VECCOPY(co2, face->v2);
-	if(face->v4)
+	if(RE_rayface_isQuad(face))
 	{
 		VECCOPY(co3, face->v4);
 		VECCOPY(co4, face->v3);
@@ -219,7 +219,7 @@
 		}
 	}
 
-	if(ok==0 && face->v4) {
+	if(ok==0 && RE_rayface_isQuad(face)) {
 
 		t20= co3[0]-co4[0];
 		t21= co3[1]-co4[1];
@@ -297,6 +297,33 @@
 	return 0;
 }
 
+void RE_rayface_from_vlak(RayFace *face, ObjectInstanceRen *obi, VlakRen *vlr)
+{
+#ifdef RE_RAYFACE_COORDS_LOCAL
+	VECCOPY(face->v1, vlr->v1->co);
+	VECCOPY(face->v2, vlr->v2->co);
+	VECCOPY(face->v3, vlr->v3->co);
+	if(vlr->v4)
+	{
+		VECCOPY(face->v4, vlr->v4->co);
+		face->quad = 1;
+	}
+	else
+	{
+		face->quad = 0;
+	}
+#elif defined(RE_RAYFACE_COORDS_POINTER)
+	face->v1 = vlr->v1->co;
+	face->v2 = vlr->v2->co;
+	face->v3 = vlr->v3->co;
+	face->v4 = vlr->v4 ? vlr->v4->co : NULL;
+#elif defined(RE_RAYFACE_COORDS_VLAKREN)
+#endif
+	face->ob   = obi;
+	face->face = vlr;
+}
+
+
 int RE_rayobject_raycast(RayObject *r, Isect *isec)
 {
 	int i;
@@ -390,7 +417,7 @@
 		DO_MINMAX( face->v1, min, max );
 		DO_MINMAX( face->v2, min, max );
 		DO_MINMAX( face->v3, min, max );
-		if(face->v4) DO_MINMAX( face->v4, min, max );
+		if(RE_rayface_isQuad(face)) DO_MINMAX( face->v4, min, max );
 	}
 	else if(RayObject_isRayAPI(r))
 	{

Deleted: branches/soc-2009-jaguarandi/source/blender/render/intern/source/rayobject_mesh.c
===================================================================
--- branches/soc-2009-jaguarandi/source/blender/render/intern/source/rayobject_mesh.c	2009-08-05 14:38:15 UTC (rev 22239)
+++ branches/soc-2009-jaguarandi/source/blender/render/intern/source/rayobject_mesh.c	2009-08-05 14:40:38 UTC (rev 22240)
@@ -1,132 +0,0 @@
-/**
- * $Id$
- *
- * ***** 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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
- *
- * The Original Code is Copyright (C) 2009 Blender Foundation.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): André Pinto.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-#include <assert.h>
- 
-#include "rayobject.h"
-
-#include "MEM_guardedalloc.h"
-#include "DNA_mesh_types.h"
-#include "DNA_meshdata_types.h"
-#include "BKE_utildefines.h"
-
-typedef struct RayMesh
-{
-	RayObject rayobj;
-	
-	Mesh *mesh;
-	void *ob;
-	
-	RayFace *faces;
-	int num_faces;
-	
-} RayMesh;
-
-static int  RayObject_mesh_intersect(RayObject *o, Isect *isec);
-static void RayObject_mesh_add(RayObject *o, RayObject *ob);
-static void RayObject_mesh_done(RayObject *o);
-static void RayObject_mesh_free(RayObject *o);
-static void RayObject_mesh_bb(RayObject *o, float *min, float *max);
-
-static RayObjectAPI mesh_api =
-{
-	RayObject_mesh_intersect,
-	RayObject_mesh_add,
-	RayObject_mesh_done,
-	RayObject_mesh_free,
-	RayObject_mesh_bb
-};
-
-
-static int  RayObject_mesh_intersect(RayObject *o, Isect *isec)
-{
-	RayMesh *rm= (RayMesh*)o;
-	int i, hit = 0;
-	for(i = 0; i<rm->num_faces; i++)
-		if(RE_rayobject_raycast( (RayObject*)rm->faces+i, isec ))
-		{
-			hit = 1;
-			if(isec->mode == RE_RAY_SHADOW)
-				break;
-		}
-
-	return hit;
-}
-
-static void RayObject_mesh_add(RayObject *o, RayObject *ob)
-{
-}
-
-static void RayObject_mesh_done(RayObject *o)
-{
-}
-
-static void RayObject_mesh_free(RayObject *o)
-{
-	RayMesh *rm= (RayMesh*)o;
-	MEM_freeN( rm->faces );
-	MEM_freeN( rm );
-}
-
-static void RayObject_mesh_bb(RayObject *o, float *min, float *max)
-{
-	RayMesh *rm= (RayMesh*)o;
-	int i;
-	for(i = 0; i<rm->mesh->totvert; i++)
-		DO_MINMAX( rm->mesh->mvert[i].co, min, max);
-}
-
-RayObject* RE_rayobject_mesh_create(Mesh *mesh, void *ob)
-{
-	RayMesh *rm= MEM_callocN(sizeof(RayMesh), "Octree");
-	int i;
-	RayFace *face;
-	MFace *mface;
-	
-	assert( RayObject_isAligned(rm) ); /* RayObject API assumes real data to be 4-byte aligned */	
-	
-	rm->rayobj.api = &mesh_api;
-	rm->mesh = mesh;
-	rm->faces = MEM_callocN(sizeof(RayFace)*mesh->totface, "octree rayobject nodes");
-	rm->num_faces = mesh->totface;
-	
-	face = rm->faces;
-	mface = mesh->mface;
-	for(i=0; i<mesh->totface; i++, face++, mface++)
-	{
-		face->v1 = mesh->mvert[mface->v1].co;
-		face->v2 = mesh->mvert[mface->v2].co;
-		face->v3 = mesh->mvert[mface->v3].co;
-		face->v4 = mface->v4 ? mesh->mvert[mface->v4].co : NULL;
-		
-		face->ob = ob;
-		face->face = (void*)i;
-	}
-	
-	return RayObject_unalignRayAPI((RayObject*) rm);
-}

Modified: branches/soc-2009-jaguarandi/source/blender/render/intern/source/rayshade.c
===================================================================
--- branches/soc-2009-jaguarandi/source/blender/render/intern/source/rayshade.c	2009-08-05 14:38:15 UTC (rev 22239)
+++ branches/soc-2009-jaguarandi/source/blender/render/intern/source/rayshade.c	2009-08-05 14:40:38 UTC (rev 22240)
@@ -220,16 +220,8 @@
 			VlakRen *vlr = obr->vlaknodes[v>>8].vlak + (v&255);
 			if(is_raytraceable_vlr(re, vlr))
 			{
-				face->v1 = vlr->v1->co;
-				face->v2 = vlr->v2->co;
-				face->v3 = vlr->v3->co;
-				face->v4 = vlr->v4 ? vlr->v4->co : NULL;
-				
-				face->ob   = obi;
-				face->face = vlr;
-				
+				RE_rayface_from_vlak( face, obi, vlr );				
 				RE_rayobject_add( raytree, RayObject_unalignRayFace(face) );
-				
 				face++;
 			}
 		}
@@ -347,16 +339,12 @@
 			for(v=0;v<obr->totvlak;v++)
 			{
 				VlakRen *vlr = obr->vlaknodes[v>>8].vlak + (v&255);
-				face->v1 = vlr->v1->co;
-				face->v2 = vlr->v2->co;
-				face->v3 = vlr->v3->co;
-				face->v4 = vlr->v4 ? vlr->v4->co : NULL;
-				
-				face->ob   = obi;
-				face->face = vlr;
-				
-				RE_rayobject_add( raytree, RayObject_unalignRayFace(face) );
-				face++;
+				if(is_raytraceable_vlr(re, vlr))
+				{
+					RE_rayface_from_vlak(face, obi, vlr);
+					RE_rayobject_add( raytree, RayObject_unalignRayFace(face) );
+					face++;
+				}
 			}
 		}
 	}





More information about the Bf-blender-cvs mailing list