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
diff options
context:
space:
mode:
authorBrecht Van Lommel <brechtvanlommel@pandora.be>2006-11-20 07:28:02 +0300
committerBrecht Van Lommel <brechtvanlommel@pandora.be>2006-11-20 07:28:02 +0300
commite435fbc3c5a00e5b63c1cd2609ab6828187660d3 (patch)
tree3f1da9c51451dee55a203cd001d37f8774d2582f /source/blender/src/multires.c
parent0a7c43c6e5fc7d5d75a4645eca1164cede2d03a6 (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/src/multires.c')
-rw-r--r--source/blender/src/multires.c98
1 files changed, 46 insertions, 52 deletions
diff --git a/source/blender/src/multires.c b/source/blender/src/multires.c
index b3bbd0f2972..ab5532b1ee3 100644
--- a/source/blender/src/multires.c
+++ b/source/blender/src/multires.c
@@ -43,6 +43,7 @@
#include "DNA_scene_types.h"
#include "DNA_vec_types.h"
+#include "BKE_customdata.h"
#include "BKE_depsgraph.h"
#include "BKE_global.h"
#include "BKE_mesh.h"
@@ -303,9 +304,8 @@ void convert_to_multires_col(MultiresCol *mrc, MCol *mcol)
mrc->g= mcol->g;
mrc->b= mcol->b;
}
-void convert_to_multires_uvcol(MultiresCol *mrc, TFace *t, const unsigned char j)
+void convert_to_multires_uv(MultiresCol *mrc, MTFace *t, const unsigned char j)
{
- convert_to_multires_col(mrc, (MCol*)(&t->col[j]));
mrc->u= t->uv[j][0];
mrc->v= t->uv[j][1];
}
@@ -335,11 +335,10 @@ void convert_from_multires_col(MultiresCol *mrc, MCol *mcol)
mcol->g= clamp_component(mrc->g);
mcol->b= clamp_component(mrc->b);
}
-void texcolface_to_tface(MultiresTexColFace *f, TFace *t)
+void texcolface_to_tface(MultiresTexColFace *f, MTFace *t)
{
unsigned i;
for(i=0; i<4; ++i) {
- convert_from_multires_col(&f->col[i], (MCol*)(&t->col[i]));
t->uv[i][0]= f->col[i].u;
t->uv[i][1]= f->col[i].v;
}
@@ -416,27 +415,21 @@ void multires_load_cols(Mesh *me)
MultiresLevel *lvl= BLI_findlink(&me->mr->levels,me->mr->current-1), *cur;
unsigned i,j;
- if(!me->mcol && !me->tface) return;
+ if(!me->mcol && !me->mtface) return;
/* Add texcol data */
for(cur= me->mr->levels.first; cur; cur= cur->next)
if(!cur->texcolfaces)
cur->texcolfaces= MEM_callocN(sizeof(MultiresTexColFace)*cur->totface,"TexColFaces");
- if(me->mcol) {
- me->mr->use_col= 1;
- for(i=0; i<me->totface; ++i)
- for(j=0; j<4; ++j)
- convert_to_multires_col(&lvl->texcolfaces[i].col[j],&me->mcol[i*4+j]);
- }
+ me->mr->use_col= (me->mcol != NULL);
+ me->mr->use_tex= (me->mtface != NULL);
- if(me->tface) {
- me->mr->use_tex= 1;
- for(i=0; i<me->totface; ++i) {
- MultiresTexColFace *f= &lvl->texcolfaces[i];
- TFace *t= &me->tface[i];
- for(j=0; j<4; ++j)
- convert_to_multires_uvcol(&f->col[j],t,j);
+ for(i=0; i<me->totface; ++i) {
+ MultiresTexColFace *f= &lvl->texcolfaces[i];
+
+ if(me->mtface) {
+ MTFace *t= &me->mtface[i];
f->tex_page= t->tpage;
f->tex_transp= t->transp;
@@ -444,6 +437,13 @@ void multires_load_cols(Mesh *me)
f->tex_tile= t->tile;
f->tex_unwrap= t->unwrap;
}
+
+ for(j=0; j<4; ++j) {
+ if(me->mcol)
+ convert_to_multires_col(&f->col[j],&me->mcol[i*4+j]);
+ if(me->mtface)
+ convert_to_multires_uv(&f->col[j],&me->mtface[i],j);
+ }
}
/* Update higher levels */
@@ -686,9 +686,9 @@ void check_colors(Mesh *me)
}
/* Check if texfaces have been deleted or added */
- if(me->mr->use_tex && !me->tface)
+ if(me->mr->use_tex && !me->mtface)
me->mr->use_tex= 0;
- else if(!me->mr->use_tex && me->tface) {
+ else if(!me->mr->use_tex && me->mtface) {
me->mr->use_tex= 1;
multires_load_cols(me);
}
@@ -911,18 +911,21 @@ void multires_level_to_mesh(Object *ob, Mesh *me)
int i,sm= G.f & G_SCULPTMODE;
if(sm) set_sculptmode();
- if(me->mvert) MEM_freeN(me->mvert);
- if(me->mface) MEM_freeN(me->mface);
- if(me->medge) MEM_freeN(me->medge);
- free_dverts(me->dvert, me->totvert);
+ CustomData_free_layer(&me->vdata, CD_MVERT, me->totvert);
+ CustomData_free_layer(&me->edata, CD_MEDGE, me->totedge);
+ CustomData_free_layer(&me->fdata, CD_MFACE, me->totface);
+ CustomData_free_layer(&me->vdata, CD_MDEFORMVERT, me->totvert);
+ CustomData_free_layer(&me->fdata, CD_MTFACE, me->totface);
+ CustomData_free_layer(&me->fdata, CD_MCOL, me->totface);
+ mesh_update_customdata_pointers(me);
me->totvert= lvl->totvert;
me->totface= lvl->totface;
me->totedge= lvl->totedge;
- me->mvert= MEM_callocN(sizeof(MVert)*me->totvert, "multires dlm mverts");
- me->mface= MEM_callocN(sizeof(MFace)*me->totface, "multires dlm mfaces");
- me->medge= MEM_callocN(sizeof(MEdge)*me->totedge, "multires dlm medges");
+ me->mvert= CustomData_add_layer(&me->vdata, CD_MVERT, 0, NULL, me->totvert);
+ me->medge= CustomData_add_layer(&me->edata, CD_MEDGE, 0, NULL, me->totedge);
+ me->mface= CustomData_add_layer(&me->fdata, CD_MFACE, 0, NULL, me->totface);
/* Vertices/Edges/Faces */
for(i=0; i<lvl->totvert; ++i)
@@ -941,7 +944,7 @@ void multires_level_to_mesh(Object *ob, Mesh *me)
/* Vertex groups */
if(me->mr->dverts && lvl==me->mr->levels.first) {
- me->dvert= MEM_mallocN(sizeof(MDeformVert)*me->totvert, "MDeformVert");
+ me->dvert= CustomData_add_layer(&me->vdata, CD_MDEFORMVERT, 0, NULL, me->totvert);
copy_dverts(me->dvert, me->mr->dverts, lvl->totvert);
} else if(me->mr->dverts) {
MultiresLevel *dlvl, *lvl1= me->mr->levels.first;
@@ -987,21 +990,20 @@ void multires_level_to_mesh(Object *ob, Mesh *me)
MEM_freeN(lvl_dverts[i]);
}
- me->dvert= lvl_dverts[dlvl_ndx-1];
+ me->dvert= CustomData_add_layer(&me->vdata, CD_MDEFORMVERT, 0, lvl_dverts[dlvl_ndx-1], me->totvert);
MEM_freeN(lvl_dverts);
}
if(me->mr->use_tex) {
- if(me->tface) MEM_freeN(me->tface);
- me->tface= MEM_callocN(sizeof(TFace)*me->totface, "multires dlm tface");
+ me->mtface= CustomData_add_layer(&me->fdata, CD_MTFACE, 0, NULL, me->totface);
for(i=0; i<lvl->totface; ++i)
- texcolface_to_tface(&lvl->texcolfaces[i],&me->tface[i]);
+ texcolface_to_tface(&lvl->texcolfaces[i],&me->mtface[i]);
- } else if(me->mr->use_col) {
- if(me->mcol) MEM_freeN(me->mcol);
- me->mcol= MEM_callocN(sizeof(MCol)*me->totface*4, "multires dlm mcol");
+ }
+ if(me->mr->use_col) {
+ me->mcol= CustomData_add_layer(&me->fdata, CD_MCOL, 0, NULL, me->totface);
for(i=0; i<lvl->totface; ++i)
multirestexcol_to_mcol(&lvl->texcolfaces[i], &me->mcol[i*4]);
@@ -1027,22 +1029,14 @@ void multires_update_colors(Mesh *me)
if(me->mr->use_col || me->mr->use_tex) {
/* Calc initial deltas */
cr_deltas= MEM_callocN(sizeof(MultiresCol)*lvl->totface*4,"initial color/uv deltas");
- if(me->mr->use_tex) {
- for(i=0; i<lvl->totface; ++i) {
- for(j=0; j<4; ++j) {
- MultiresCol col;
- convert_to_multires_uvcol(&col,&me->tface[i],j);
- cr_deltas[i*4+j].a= col.a - lvl->texcolfaces[i].col[j].a;
- cr_deltas[i*4+j].r= col.r - lvl->texcolfaces[i].col[j].r;
- cr_deltas[i*4+j].g= col.g - lvl->texcolfaces[i].col[j].g;
- cr_deltas[i*4+j].b= col.b - lvl->texcolfaces[i].col[j].b;
- cr_deltas[i*4+j].u= col.u - lvl->texcolfaces[i].col[j].u;
- cr_deltas[i*4+j].v= col.v - lvl->texcolfaces[i].col[j].v;
+
+ for(i=0; i<lvl->totface; ++i) {
+ for(j=0; j<4; ++j) {
+ if(me->mr->use_tex) {
+ cr_deltas[i*4+j].u= me->mtface[i].uv[j][0] - lvl->texcolfaces[i].col[j].u;
+ cr_deltas[i*4+j].v= me->mtface[i].uv[j][1] - lvl->texcolfaces[i].col[j].v;
}
- }
- } else if(me->mr->use_col) {
- for(i=0; i<lvl->totface; ++i) {
- for(j=0; j<4; ++j) {
+ if(me->mr->use_col) {
cr_deltas[i*4+j].a= me->mcol[i*4+j].a - lvl->texcolfaces[i].col[j].a;
cr_deltas[i*4+j].r= me->mcol[i*4+j].r - lvl->texcolfaces[i].col[j].r;
cr_deltas[i*4+j].g= me->mcol[i*4+j].g - lvl->texcolfaces[i].col[j].g;
@@ -1055,8 +1049,8 @@ void multires_update_colors(Mesh *me)
for(i=0; i<lvl->totface; ++i) {
for(j=0; j<4; ++j) {
if(me->mr->use_tex)
- convert_to_multires_uvcol(&lvl->texcolfaces[i].col[j],&me->tface[i],j);
- else
+ convert_to_multires_uv(&lvl->texcolfaces[i].col[j],&me->mtface[i],j);
+ if(me->mr->use_col)
convert_to_multires_col(&lvl->texcolfaces[i].col[j],&me->mcol[i*4+j]);
}
}