diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2006-11-20 07:28:02 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2006-11-20 07:28:02 +0300 |
commit | e435fbc3c5a00e5b63c1cd2609ab6828187660d3 (patch) | |
tree | 3f1da9c51451dee55a203cd001d37f8774d2582f /source/blender/radiosity | |
parent | 0a7c43c6e5fc7d5d75a4645eca1164cede2d03a6 (diff) |
Added custom vertex/edge/face data for meshes:
All data layers, including MVert/MEdge/MFace, are now managed as custom
data layers. The pointers like Mesh.mvert, Mesh.dvert or Mesh.mcol are
still used of course, but allocating, copying or freeing these arrays
should be done through the CustomData API.
Work in progress documentation on this is here:
http://mediawiki.blender.org/index.php/BlenderDev/BlenderArchitecture/CustomData
Replaced TFace by MTFace:
This is the same struct, except that it does not contain color, that now
always stays separated in MCol. This was not a good design decision to
begin with, and it is needed for adding multiple color layers later. Note
that this does mean older Blender versions will not be able to read UV
coordinates from the next release, due to an SDNA limitation.
Removed DispListMesh:
This now fully replaced by DerivedMesh. To provide access to arrays of
vertices, edges and faces, like DispListMesh does. The semantics of the
DerivedMesh.getVertArray() and similar functions were changed to return
a pointer to an array if one exists, or otherwise allocate a temporary
one. On releasing the DerivedMesh, this temporary array will be removed
automatically.
Removed ssDM and meshDM DerivedMesh backends:
The ssDM backend was for DispListMesh, so that became obsolete automatically.
The meshDM backend was replaced by the custom data backend, that now figures
out which layers need to be modified, and only duplicates those.
This changes code in many places, and overall removes 2514 lines of code.
So, there's a good chance this might break some stuff, although I've been
testing it for a few days now. The good news is, adding multiple color and
uv layers should now become easy.
Diffstat (limited to 'source/blender/radiosity')
4 files changed, 57 insertions, 77 deletions
diff --git a/source/blender/radiosity/extern/include/radio_types.h b/source/blender/radiosity/extern/include/radio_types.h index 23ce17d9611..c9a0726e0d8 100644 --- a/source/blender/radiosity/extern/include/radio_types.h +++ b/source/blender/radiosity/extern/include/radio_types.h @@ -42,7 +42,7 @@ #include "DNA_material_types.h" struct Render; -struct TFace; +struct CustomData; #define DTWIRE 0 #define DTGOUR 2 @@ -88,14 +88,14 @@ typedef struct RNode { /* length: 104 */ float totrad[3], area; unsigned int col; - unsigned int orig; /* index in face elem data */ + int orig; /* index in custom face data */ } RNode; typedef struct Face { /* length: 52 */ float *v1, *v2, *v3, *v4; unsigned int col, matindex; - unsigned int orig; /* index in face elem data */ + int orig; /* index in custom face data */ } Face; /* rp->f1 */ @@ -156,8 +156,10 @@ typedef struct { Material *matar[MAXMAT]; int totmat; - struct RNode **mfdatanodes; /* nodes associated with the mfdata */ - struct TFace *tface; + /* for preserving face data */ + int mfdatatot; + struct CustomData *mfdata; + struct RNode **mfdatanodes; /* this part is a copy of struct Radio */ short hemires, maxiter; diff --git a/source/blender/radiosity/intern/source/radio.c b/source/blender/radiosity/intern/source/radio.c index 6426592244a..8d08632aedb 100644 --- a/source/blender/radiosity/intern/source/radio.c +++ b/source/blender/radiosity/intern/source/radio.c @@ -87,6 +87,7 @@ #include "DNA_scene_types.h" #include "DNA_screen_types.h" +#include "BKE_customdata.h" #include "BKE_global.h" #include "BKE_main.h" @@ -144,13 +145,13 @@ void freeAllRad() RG.facebase= 0; } - if(RG.mfdatanodes) { + if(RG.mfdata) { + CustomData_free(RG.mfdata, RG.mfdatatot); + MEM_freeN(RG.mfdata); MEM_freeN(RG.mfdatanodes); RG.mfdatanodes= NULL; - if(RG.tface) { - MEM_freeN(RG.tface); - RG.tface= NULL; - } + RG.mfdata= NULL; + RG.mfdatatot= 0; } RG.totelem= RG.totpatch= RG.totvert= RG.totface= RG.totlamp= RG.totmat= 0; } diff --git a/source/blender/radiosity/intern/source/radpostprocess.c b/source/blender/radiosity/intern/source/radpostprocess.c index 16de4918742..36ac0445933 100644 --- a/source/blender/radiosity/intern/source/radpostprocess.c +++ b/source/blender/radiosity/intern/source/radpostprocess.c @@ -60,6 +60,7 @@ #include "DNA_object_types.h" #include "DNA_radio_types.h" +#include "BKE_customdata.h" #include "BKE_global.h" #include "BKE_main.h" #include "BKE_material.h" @@ -71,7 +72,6 @@ #include "BIF_editview.h" /* deselectall */ #include "BDR_editobject.h" /* delete_obj */ -#include "BDR_editface.h" /* default_tface */ #include "radio.h" @@ -684,23 +684,6 @@ void removeEqualNodes(short limit) waitcursor(0); } -static void rad_interp_uv(float *v1, float *v2, float *v3, float *v4, float *co, TFace *tf, TFace *outtf, int j) -{ - float *uv, w[4]; - - uv = (float*)outtf->uv[j]; - - InterpWeightsQ3Dfl(v1, v2, v3, v4, co, w); - - uv[0]= w[0]*tf->uv[0][0] + w[1]*tf->uv[1][0] + w[2]*tf->uv[2][0]; - uv[1]= w[0]*tf->uv[0][1] + w[1]*tf->uv[1][1] + w[2]*tf->uv[2][1]; - - if (v4) { - uv[0] += w[3]*tf->uv[3][0]; - uv[1] += w[3]*tf->uv[3][1]; - } -} - void rad_addmesh(void) { Face *face = NULL; @@ -708,11 +691,11 @@ void rad_addmesh(void) Mesh *me; MVert *mvert; MFace *mf; - TFace *tf; Material *ma=0; float **vco, **vertexco; float cent[3], min[3], max[3]; int a, nvert, i; + unsigned int *mcol; if(RG.totface==0) return; @@ -727,8 +710,11 @@ void rad_addmesh(void) me->totvert= 0; me->totface= RG.totface; me->flag= 0; - me->mface= MEM_callocN(me->totface*sizeof(MFace), "mface"); - me->tface= MEM_callocN(me->totface*sizeof(TFace), "tface"); + me->mface= CustomData_add_layer(&me->fdata, CD_MFACE, 0, NULL, me->totface); + me->mcol= CustomData_add_layer(&me->fdata, CD_MCOL, 0, NULL, me->totface); + + CustomData_merge(RG.mfdata, &me->fdata, CD_MASK_MESH, CD_CALLOC, me->totface); + mesh_update_customdata_pointers(me); /* create materials and set vertex color flag */ for(a=0; a<RG.totmat; a++) { @@ -737,21 +723,18 @@ void rad_addmesh(void) if(ma) ma->mode |= MA_VERTEXCOL; } - /* load Face vertex colors into TFace, with alpha added */ - tf= me->tface; - for(a=0; a<me->totface; a++, tf++) { + /* copy face data, load Face vertex colors into mcol, with alpha added */ + mcol= (unsigned int*)me->mcol; + for(a=0; a<me->totface; a++, mcol+=4) { RAD_NEXTFACE(a); - if (RG.tface) - *tf= RG.tface[face->orig]; - else - default_tface(tf); + CustomData_copy_data(RG.mfdata, &me->fdata, face->orig, a, 1); - tf->col[0]= *((unsigned int*)face->v1+3) | 0x1000000; - tf->col[1]= *((unsigned int*)face->v2+3) | 0x1000000; - tf->col[2]= *((unsigned int*)face->v3+3) | 0x1000000; + mcol[0]= *((unsigned int*)face->v1+3) | 0x1000000; + mcol[1]= *((unsigned int*)face->v2+3) | 0x1000000; + mcol[2]= *((unsigned int*)face->v3+3) | 0x1000000; if(face->v4) - tf->col[3]= *((unsigned int*)face->v4+3) | 0x1000000; + mcol[3]= *((unsigned int*)face->v4+3) | 0x1000000; } /* clear Face vertex color memory for vertex index assignment */ @@ -789,7 +772,8 @@ void rad_addmesh(void) } /* create vertices */ - mvert= me->mvert= MEM_callocN(me->totvert*sizeof(MVert), "mverts"); + me->mvert= CustomData_add_layer(&me->vdata, CD_MVERT, 0, NULL, me->totvert); + mvert= me->mvert; for(vco=vertexco, a=0; a<me->totvert; a++, mvert++, vco++) { VECCOPY(mvert->co, *vco); } @@ -798,11 +782,10 @@ void rad_addmesh(void) /* assign face data */ mf= me->mface; - tf= me->tface; - for(a=0; a<me->totface; a++, mf++, tf++) { - TFace *origtf; + for(a=0; a<me->totface; a++, mf++ ) { RNode *orignode; + float w[4][4]; float *subco; RAD_NEXTFACE(a); @@ -811,34 +794,31 @@ void rad_addmesh(void) /* copy */ mf->mat_nr= face->matindex; - /* UV interpolation */ - if (RG.tface) { - origtf= &RG.tface[face->orig]; - - orignode= RG.mfdatanodes[face->orig]; + orignode= RG.mfdatanodes[face->orig]; - for(i=0; i<nvert; i++) { - subco= (me->mvert + ((unsigned int*)&mf->v1)[i])->co; + for(i=0; i<nvert; i++) { + subco= (me->mvert + ((unsigned int*)&mf->v1)[i])->co; - rad_interp_uv(orignode->v1, orignode->v2, orignode->v3, - orignode->v4, subco, origtf, tf, i); - } + InterpWeightsQ3Dfl(orignode->v1, orignode->v2, orignode->v3, + orignode->v4, subco, w[i]); } + + CustomData_interp(RG.mfdata, &me->fdata, &face->orig, NULL, (float*)w, 1, a); } /* restore vertex colors, and test_index */ mf= me->mface; - tf= me->tface; - for(a=0; a<me->totface; a++, mf++, tf++) { + mcol= (unsigned int*)me->mcol; + for(a=0; a<me->totface; a++, mf++, mcol+=4) { RAD_NEXTFACE(a); - *((unsigned int*)face->v1+3)= tf->col[0]; - *((unsigned int*)face->v2+3)= tf->col[1]; - *((unsigned int*)face->v3+3)= tf->col[2]; + *((unsigned int*)face->v1+3)= mcol[0]; + *((unsigned int*)face->v2+3)= mcol[1]; + *((unsigned int*)face->v3+3)= mcol[2]; if(face->v4) - *((unsigned int*)face->v4+3)= tf->col[3]; + *((unsigned int*)face->v4+3)= mcol[3]; - test_index_face(mf, NULL, tf, face->v4? 4: 3); + test_index_face(mf, &me->fdata, a, face->v4? 4: 3); } /* boundbox and centre new */ diff --git a/source/blender/radiosity/intern/source/radpreprocess.c b/source/blender/radiosity/intern/source/radpreprocess.c index 1a1cc6e76b3..6fe0e2bfdac 100644 --- a/source/blender/radiosity/intern/source/radpreprocess.c +++ b/source/blender/radiosity/intern/source/radpreprocess.c @@ -57,6 +57,7 @@ #include "DNA_scene_types.h" #include "DNA_view3d_types.h" +#include "BKE_customdata.h" #include "BKE_global.h" #include "BKE_main.h" #include "BKE_material.h" @@ -309,13 +310,13 @@ void rad_collect_meshes() Mesh *me; MVert *mvert; MFace *mface; - TFace *tf, *tface; + MTFace *tf, *tface; Material *ma = NULL, *noma= NULL; RPatch *rp; RNode *rn; VeNoCo *vnc, **nodevert; float *vd, *v1, *v2, *v3, *v4 = NULL; - int a, b, offs, index, mfdatatot, hastface = 0; + int a, b, offs, index, mfdatatot; if (G.vd==NULL) { printf("Error, trying to collect radiosity meshes with no 3d view\n"); @@ -402,8 +403,6 @@ void rad_collect_meshes() } mfdatatot += me->totface; - if (me->tface) - hastface= 1; } } base= base->next; @@ -417,9 +416,9 @@ void rad_collect_meshes() RG.size[2]= (RG.max[2]- RG.min[2]); RG.maxsize= MAX3(RG.size[0],RG.size[1],RG.size[2]); + RG.mfdata= MEM_callocN(sizeof(CustomData), "radiomfdata"); RG.mfdatanodes= MEM_mallocN(sizeof(RNode*)*mfdatatot, "radiomfdatanodes"); - if (hastface) - RG.tface= MEM_mallocN(sizeof(TFace)*mfdatatot, "radiotface"); + RG.mfdatatot= mfdatatot; /* make patches */ @@ -435,10 +434,13 @@ void rad_collect_meshes() ob= base->object; me= ob->data; mface= me->mface; - tface= me->tface; + tface= me->mtface; index= -1; + CustomData_merge(&me->fdata, RG.mfdata, CD_MASK_DERIVEDMESH, + CD_DEFAULT, mfdatatot); + for(a=0; a<me->totface; a++, mface++) { tf= tface? tface+a: NULL; @@ -523,13 +525,8 @@ void rad_collect_meshes() rn->orig= RG.totelem; RG.mfdatanodes[RG.totelem]= rn; - if (RG.tface) { - if (tf) - RG.tface[RG.totelem]= *tf; - else - default_tface(&RG.tface[RG.totelem]); - } - + CustomData_copy_data(&me->fdata, RG.mfdata, a, RG.totelem, 1); + RG.totelem++; RG.totpatch++; } |