Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorAndre Susano Pinto <andresusanopinto@gmail.com>2009-08-05 18:40:38 +0400
committerAndre Susano Pinto <andresusanopinto@gmail.com>2009-08-05 18:40:38 +0400
commite4e9b569e1b766dc07ae074439a894be8d7cda49 (patch)
treec8ae6e0f28df05034c80a28076cfd2db020dad0e /source
parentbbdba89d06496e1e9a2bc63ce0f70aac8b8cc3f3 (diff)
experiences with memory organization (store the vertexs coords on RayFace)
Diffstat (limited to 'source')
-rw-r--r--source/blender/editors/armature/meshlaplacian.c3
-rw-r--r--source/blender/render/intern/include/rayobject.h30
-rw-r--r--source/blender/render/intern/source/rayobject.c33
-rw-r--r--source/blender/render/intern/source/rayobject_mesh.c132
-rw-r--r--source/blender/render/intern/source/rayshade.c26
5 files changed, 68 insertions, 156 deletions
diff --git a/source/blender/editors/armature/meshlaplacian.c b/source/blender/editors/armature/meshlaplacian.c
index 7a0eda16d39..ff3fed6be34 100644
--- a/source/blender/editors/armature/meshlaplacian.c
+++ b/source/blender/editors/armature/meshlaplacian.c
@@ -401,7 +401,8 @@ static void heat_ray_tree_create(LaplacianSystem *sys)
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++) {
diff --git a/source/blender/render/intern/include/rayobject.h b/source/blender/render/intern/include/rayobject.h
index 6f8debead19..dddeebd5048 100644
--- a/source/blender/render/intern/include/rayobject.h
+++ b/source/blender/render/intern/include/rayobject.h
@@ -34,6 +34,7 @@ extern "C" {
#endif
#include "RE_raytrace.h"
+#include "render_types.h"
#include <float.h>
@@ -75,16 +76,38 @@ extern "C" {
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 @@ typedef struct RayObjectAPI
#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);
diff --git a/source/blender/render/intern/source/rayobject.c b/source/blender/render/intern/source/rayobject.c
index 2e63dc78c0e..c0c2c36fe13 100644
--- a/source/blender/render/intern/source/rayobject.c
+++ b/source/blender/render/intern/source/rayobject.c
@@ -165,7 +165,7 @@ static int intersect_rayface(RayFace *face, Isect *is)
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 @@ static int intersect_rayface(RayFace *face, Isect *is)
}
}
- 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 @@ static int intersect_rayface(RayFace *face, Isect *is)
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 @@ void RE_rayobject_merge_bb(RayObject *r, float *min, float *max)
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))
{
diff --git a/source/blender/render/intern/source/rayobject_mesh.c b/source/blender/render/intern/source/rayobject_mesh.c
deleted file mode 100644
index 538c245988d..00000000000
--- a/source/blender/render/intern/source/rayobject_mesh.c
+++ /dev/null
@@ -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);
-}
diff --git a/source/blender/render/intern/source/rayshade.c b/source/blender/render/intern/source/rayshade.c
index 58bfa506e2b..685b82d9da2 100644
--- a/source/blender/render/intern/source/rayshade.c
+++ b/source/blender/render/intern/source/rayshade.c
@@ -220,16 +220,8 @@ RayObject* makeraytree_object(Render *re, ObjectInstanceRen *obi)
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 @@ static void makeraytree_single(Render *re)
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++;
+ }
}
}
}