diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2006-12-13 00:29:09 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2006-12-13 00:29:09 +0300 |
commit | 80ee52e444f05a6fd7a45f2ddfe72720648fbab8 (patch) | |
tree | 577238b0fdb738813ca560f0c5fc08dd6b945956 | |
parent | 47adee414c7848f6ad898e9029205e804b9d6601 (diff) |
Multiple UV and vertex color layers: (still work in progress)
These can be created and deleted in the Mesh panel in the same place as
before. There is always one active UV and vertex color layer, that is
edited and displayed.
Important things to do:
- Render engine, material support
- Multires and NMesh now lose non active layers
Also CustomData changes to support muliple layers of the same type, and
changes to layer allocation, updated documentation is here:
http://mediawiki.blender.org/index.php/BlenderDev/BlenderArchitecture/CustomData
29 files changed, 769 insertions, 656 deletions
diff --git a/source/blender/blenkernel/BKE_DerivedMesh.h b/source/blender/blenkernel/BKE_DerivedMesh.h index f7c771394b8..872717fdb9b 100644 --- a/source/blender/blenkernel/BKE_DerivedMesh.h +++ b/source/blender/blenkernel/BKE_DerivedMesh.h @@ -304,16 +304,14 @@ void DM_set_only_copy(DerivedMesh *dm, CustomDataMask mask); /* adds a vertex/edge/face custom data layer to a DerivedMesh, optionally * backed by an external data array - * if layer != NULL, it is used as the layer data array, otherwise new memory - * is allocated - * the layer data will be freed by dm->release unless - * (flag & LAYERFLAG_NOFREE) is true + * alloctype defines how the layer is allocated or copied, and how it is + * freed, see BKE_customdata.h for the different options */ -void DM_add_vert_layer(struct DerivedMesh *dm, int type, int flag, +void DM_add_vert_layer(struct DerivedMesh *dm, int type, int alloctype, void *layer); -void DM_add_edge_layer(struct DerivedMesh *dm, int type, int flag, +void DM_add_edge_layer(struct DerivedMesh *dm, int type, int alloctype, void *layer); -void DM_add_face_layer(struct DerivedMesh *dm, int type, int flag, +void DM_add_face_layer(struct DerivedMesh *dm, int type, int alloctype, void *layer); /* custom data access functions @@ -355,7 +353,7 @@ void DM_copy_face_data(struct DerivedMesh *source, struct DerivedMesh *dest, /* custom data free functions * free count elements, starting at index - * they free all layers for which the LAYERFLAG_NOFREE flag is not set + * they free all layers for which the CD_FLAG_NOCOPY flag is not set */ void DM_free_vert_data(struct DerivedMesh *dm, int index, int count); void DM_free_edge_data(struct DerivedMesh *dm, int index, int count); diff --git a/source/blender/blenkernel/BKE_customdata.h b/source/blender/blenkernel/BKE_customdata.h index d48340998e0..e6cf16a41e2 100644 --- a/source/blender/blenkernel/BKE_customdata.h +++ b/source/blender/blenkernel/BKE_customdata.h @@ -48,11 +48,13 @@ extern const CustomDataMask CD_MASK_DERIVEDMESH; * memory space for totelem elements. mask must be an array of length * CD_NUMTYPES elements, that indicate if a layer can be copied. */ -/* copy/merge allocation types */ -#define CD_CALLOC 0 /* allocate blank memory for all layers */ -#define CD_DEFAULT 1 /* allocate layers and set them to their defaults */ -#define CD_DUPLICATE 2 /* do a full copy of all layer */ -#define CD_REFERENCE 3 /* reference original pointers, set layer flag NOFREE */ +/* add/copy/merge allocation types */ +#define CD_ASSIGN 0 /* use the data pointer */ +#define CD_CALLOC 1 /* allocate blank memory */ +#define CD_DEFAULT 2 /* allocate and set to default */ +#define CD_REFERENCE 3 /* use data pointers, set layer flag NOFREE */ +#define CD_DUPLICATE 4 /* do a full copy of all layers, only allowed if source + has same number of elements */ /* initialises a CustomData object with the same layer setup as source. * mask is a bitfield where (mask & (1 << (layer type))) indicates @@ -60,8 +62,8 @@ extern const CustomDataMask CD_MASK_DERIVEDMESH; void CustomData_copy(const struct CustomData *source, struct CustomData *dest, CustomDataMask mask, int alloctype, int totelem); -/* same as the above, except that will preserve existing layers, and only add - * the layers that were not there yet */ +/* same as the above, except that this will preserve existing layers, and only + * add the layers that were not there yet */ void CustomData_merge(const struct CustomData *source, struct CustomData *dest, CustomDataMask mask, int alloctype, int totelem); @@ -70,38 +72,34 @@ void CustomData_merge(const struct CustomData *source, struct CustomData *dest, */ void CustomData_free(struct CustomData *data, int totelem); -/* frees all layers with flag LAYERFLAG_TEMPORARY */ +/* frees all layers with CD_FLAG_TEMPORARY */ void CustomData_free_temporary(struct CustomData *data, int totelem); /* adds a data layer of the given type to the CustomData object, optionally - * backed by an external data array - * if layer != NULL, it is used as the layer data array, otherwise new memory - * is allocated - * the layer data will be freed by CustomData_free unless - * (flag & LAYERFLAG_NOFREE) is true - * returns the data of the layer + * backed by an external data array. the different allocation types are + * defined above. returns the data of the layer. * * in editmode, use EM_add_data_layer instead of this function */ -void *CustomData_add_layer(struct CustomData *data, int type, int flag, +void *CustomData_add_layer(struct CustomData *data, int type, int alloctype, void *layer, int totelem); -/* frees the first data layer with the give type. +/* frees the active or first data layer with the give type. * returns 1 on succes, 0 if no layer with the given type is found * * in editmode, use EM_free_data_layer instead of this function */ int CustomData_free_layer(struct CustomData *data, int type, int totelem); -/* returns 1 if the two objects are compatible (same layer types and - * flags in the same order), 0 if not - */ -int CustomData_compat(const struct CustomData *data1, - const struct CustomData *data2); +/* same as above, but free all layers with type */ +void CustomData_free_layers(struct CustomData *data, int type, int totelem); /* returns 1 if a layer with the specified type exists */ int CustomData_has_layer(const struct CustomData *data, int type); +/* returns the number of layers with this type */ +int CustomData_number_of_layers(const struct CustomData *data, int type); + /* duplicate data of a layer with flag NOFREE, and remove that flag. * returns the layer data */ void *CustomData_duplicate_referenced_layer(struct CustomData *data, int type); @@ -162,15 +160,11 @@ void CustomData_swap(struct CustomData *data, int index, int *corner_indices); void *CustomData_get(const struct CustomData *data, int index, int type); void *CustomData_em_get(const struct CustomData *data, void *block, int type); -/* gets a pointer to the first layer of type +/* gets a pointer to the active or first layer of type * returns NULL if there is no layer of type */ void *CustomData_get_layer(const struct CustomData *data, int type); - -/* set the pointer of to the first layer of type. the old data is not freed. - * returns the value of ptr if the layer is found, NULL otherwise - */ -void *CustomData_set_layer(const struct CustomData *data, int type, void *ptr); +void *CustomData_get_layer_n(const struct CustomData *data, int type, int n); /* copies the data from source to the data element at index in the first * layer of type @@ -181,15 +175,23 @@ void CustomData_set(const struct CustomData *data, int index, int type, void CustomData_em_set(struct CustomData *data, void *block, int type, void *source); -/* set data layers that have a non-zero default value to their defaults */ -void CustomData_set_default(struct CustomData *data, int index, int count); +/* set the pointer of to the first layer of type. the old data is not freed. + * returns the value of ptr if the layer is found, NULL otherwise + */ +void *CustomData_set_layer(const struct CustomData *data, int type, void *ptr); + +/* sets the nth layer of type as active */ +void CustomData_set_layer_active(struct CustomData *data, int type, int n); + +/* adds flag to the layer flags */ +void CustomData_set_layer_flag(struct CustomData *data, int type, int flag); /* alloc/free a block of custom data attached to one element in editmode */ void CustomData_em_set_default(struct CustomData *data, void **block); void CustomData_em_free_block(struct CustomData *data, void **block); /* copy custom data to/from layers as in mesh/derivedmesh, to editmesh - blocks of data. the CustomData's must be compatible */ + blocks of data. the CustomData's must not be compatible */ void CustomData_to_em_block(const struct CustomData *source, struct CustomData *dest, int index, void **block); void CustomData_from_em_block(const struct CustomData *source, diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c index 8c3e807abd9..972be1b6c68 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.c +++ b/source/blender/blenkernel/intern/DerivedMesh.c @@ -98,8 +98,9 @@ MVert *dm_getVertArray(DerivedMesh *dm) MVert *mvert = CustomData_get_layer(&dm->vertData, CD_MVERT); if (!mvert) { - mvert = CustomData_add_layer(&dm->vertData, CD_MVERT, - CD_FLAG_TEMPORARY, NULL, dm->getNumVerts(dm)); + mvert = CustomData_add_layer(&dm->vertData, CD_MVERT, CD_CALLOC, NULL, + dm->getNumVerts(dm)); + CustomData_set_layer_flag(&dm->vertData, CD_MVERT, CD_FLAG_TEMPORARY); dm->copyVertArray(dm, mvert); } @@ -111,8 +112,9 @@ MEdge *dm_getEdgeArray(DerivedMesh *dm) MEdge *medge = CustomData_get_layer(&dm->edgeData, CD_MEDGE); if (!medge) { - medge = CustomData_add_layer(&dm->edgeData, CD_MEDGE, - CD_FLAG_TEMPORARY, NULL, dm->getNumEdges(dm)); + medge = CustomData_add_layer(&dm->edgeData, CD_MEDGE, CD_CALLOC, NULL, + dm->getNumEdges(dm)); + CustomData_set_layer_flag(&dm->edgeData, CD_MEDGE, CD_FLAG_TEMPORARY); dm->copyEdgeArray(dm, medge); } @@ -124,8 +126,9 @@ MFace *dm_getFaceArray(DerivedMesh *dm) MFace *mface = CustomData_get_layer(&dm->faceData, CD_MFACE); if (!mface) { - mface = CustomData_add_layer(&dm->faceData, CD_MFACE, - CD_FLAG_TEMPORARY, NULL, dm->getNumFaces(dm)); + mface = CustomData_add_layer(&dm->faceData, CD_MFACE, CD_CALLOC, NULL, + dm->getNumFaces(dm)); + CustomData_set_layer_flag(&dm->faceData, CD_MFACE, CD_FLAG_TEMPORARY); dm->copyFaceArray(dm, mface); } @@ -183,9 +186,9 @@ void DM_init_funcs(DerivedMesh *dm) void DM_init(DerivedMesh *dm, int numVerts, int numEdges, int numFaces) { - CustomData_add_layer(&dm->vertData, CD_ORIGINDEX, 0, NULL, numVerts); - CustomData_add_layer(&dm->edgeData, CD_ORIGINDEX, 0, NULL, numEdges); - CustomData_add_layer(&dm->faceData, CD_ORIGINDEX, 0, NULL, numFaces); + CustomData_add_layer(&dm->vertData, CD_ORIGINDEX, CD_CALLOC, NULL, numVerts); + CustomData_add_layer(&dm->edgeData, CD_ORIGINDEX, CD_CALLOC, NULL, numEdges); + CustomData_add_layer(&dm->faceData, CD_ORIGINDEX, CD_CALLOC, NULL, numFaces); dm->numVertData = numVerts; dm->numEdgeData = numEdges; @@ -254,11 +257,11 @@ void DM_to_mesh(DerivedMesh *dm, Mesh *me) /* not all DerivedMeshes store their verts/edges/faces in CustomData, so we set them here in case they are missing */ if(!CustomData_has_layer(&tmp.vdata, CD_MVERT)) - CustomData_add_layer(&tmp.vdata, CD_MVERT, 0, dm->dupVertArray(dm), totvert); + CustomData_add_layer(&tmp.vdata, CD_MVERT, CD_ASSIGN, dm->dupVertArray(dm), totvert); if(!CustomData_has_layer(&tmp.edata, CD_MEDGE)) - CustomData_add_layer(&tmp.edata, CD_MEDGE, 0, dm->dupEdgeArray(dm), totedge); + CustomData_add_layer(&tmp.edata, CD_MEDGE, CD_ASSIGN, dm->dupEdgeArray(dm), totedge); if(!CustomData_has_layer(&tmp.fdata, CD_MFACE)) - CustomData_add_layer(&tmp.fdata, CD_MFACE, 0, dm->dupFaceArray(dm), totface); + CustomData_add_layer(&tmp.fdata, CD_MFACE, CD_ASSIGN, dm->dupFaceArray(dm), totface); mesh_update_customdata_pointers(&tmp); @@ -282,19 +285,19 @@ void DM_set_only_copy(DerivedMesh *dm, CustomDataMask mask) CustomData_set_only_copy(&dm->faceData, mask); } -void DM_add_vert_layer(DerivedMesh *dm, int type, int flag, void *layer) +void DM_add_vert_layer(DerivedMesh *dm, int type, int alloctype, void *layer) { - CustomData_add_layer(&dm->vertData, type, flag, layer, dm->numVertData); + CustomData_add_layer(&dm->vertData, type, alloctype, layer, dm->numVertData); } -void DM_add_edge_layer(DerivedMesh *dm, int type, int flag, void *layer) +void DM_add_edge_layer(DerivedMesh *dm, int type, int alloctype, void *layer) { - CustomData_add_layer(&dm->edgeData, type, flag, layer, dm->numEdgeData); + CustomData_add_layer(&dm->edgeData, type, alloctype, layer, dm->numEdgeData); } -void DM_add_face_layer(DerivedMesh *dm, int type, int flag, void *layer) +void DM_add_face_layer(DerivedMesh *dm, int type, int alloctype, void *layer) { - CustomData_add_layer(&dm->faceData, type, flag, layer, dm->numFaceData); + CustomData_add_layer(&dm->faceData, type, alloctype, layer, dm->numFaceData); } void *DM_get_vert_data(DerivedMesh *dm, int index, int type) @@ -954,7 +957,7 @@ static DerivedMesh *getEditMeshDerivedMesh(EditMesh *em, Object *ob, EditVert *eve; int i; - DM_add_vert_layer(&emdm->dm, CD_MDEFORMVERT, 0, NULL); + DM_add_vert_layer(&emdm->dm, CD_MDEFORMVERT, CD_CALLOC, NULL); for(eve = em->verts.first, i = 0; eve; eve = eve->next, ++i) DM_set_vert_data(&emdm->dm, i, CD_MDEFORMVERT, @@ -2103,29 +2106,19 @@ static void mesh_build_data(Object *ob, CustomDataMask dataMask) int needMapping = editing && (ob==obact); if( (G.f & G_WEIGHTPAINT) && ob==obact ) { - MCol *mcol = me->mcol; MCol *wpcol = (MCol*)calc_weightpaint_colors(ob); + int layernum = CustomData_number_of_layers(&me->fdata, CD_MCOL); - /* ugly hack here, we replace mcol with weight paint colors, then - CDDM_from_mesh duplicates it, and uses that instead of mcol */ - if (mcol) { - CustomData_set_layer(&me->fdata, CD_MCOL, NULL); - CustomData_free_layer(&me->fdata, CD_MCOL, me->totface); - } - - CustomData_add_layer(&me->fdata, CD_MCOL, CD_FLAG_NOFREE, wpcol, me->totface); - me->mcol= wpcol; + /* ugly hack here, we temporarily add a new active mcol layer with + weightpaint colors in it, that is then duplicated in CDDM_from_mesh */ + CustomData_add_layer(&me->fdata, CD_MCOL, CD_ASSIGN, wpcol, me->totface); + CustomData_set_layer_active(&me->fdata, CD_MCOL, layernum); mesh_calc_modifiers(ob, NULL, &ob->derivedDeform, &ob->derivedFinal, 0, 1, needMapping, dataMask); CustomData_free_layer(&me->fdata, CD_MCOL, me->totface); - if (wpcol) MEM_freeN(wpcol); - - if (mcol) - me->mcol= CustomData_add_layer(&me->fdata, CD_MCOL, 0, mcol, me->totface); - me->mcol= mcol; } else { mesh_calc_modifiers(ob, NULL, &ob->derivedDeform, &ob->derivedFinal, 0, 1, @@ -2222,7 +2215,6 @@ DerivedMesh *mesh_create_derived_render(Object *ob, CustomDataMask dataMask) { DerivedMesh *final; Mesh *m= get_mesh(ob); - unsigned i; /* Goto the pin level for multires */ if(m->mr) { @@ -2236,9 +2228,7 @@ DerivedMesh *mesh_create_derived_render(Object *ob, CustomDataMask dataMask) if(m->mr) { if(final->getNumVerts(final) == m->totvert && final->getNumFaces(final) == m->totface) { - for(i=0; i<m->totvert; ++i) - memcpy(&m->mvert[i], CustomData_get(&final->vertData, i, CD_MVERT), sizeof(MVert)); - + final->copyVertArray(final, m->mvert); final->release(final); m->mr->newlvl= m->mr->renderlvl; @@ -2520,7 +2510,6 @@ void initElbeemMesh(struct Object *ob, dm = mesh_create_derived_render(ob, CD_MASK_BAREMESH); //dm = mesh_create_derived_no_deform(ob,NULL); - if(!dm) { *numVertices = *numTriangles = 0; *triangles=NULL; *vertices=NULL; } mvert = dm->getVertArray(dm); mface = dm->getFaceArray(dm); @@ -2624,7 +2613,7 @@ Mesh* readBobjgz(char *filename, Mesh *orgmesh, float* bbstart, float *bbsize) / //if(sizeof(wri)!=4) { snprintf(debugStrBuffer,256,"Reading GZ_BOBJ, Invalid int size %d...\n", wri); return NULL; } // paranoia check gotBytes = gzread(gzf, &wri, sizeof(wri)); newmesh->totvert = wri; - newmesh->mvert = CustomData_add_layer(&newmesh->vdata, CD_MVERT, 0, NULL, newmesh->totvert); + newmesh->mvert = CustomData_add_layer(&newmesh->vdata, CD_MVERT, CD_CALLOC, NULL, newmesh->totvert); if(debugBobjRead){ snprintf(debugStrBuffer,256,"#vertices %d ", newmesh->totvert); elbeemDebugOut(debugStrBuffer); } //DEBUG for(i=0; i<newmesh->totvert;i++) { //if(debugBobjRead) snprintf(debugStrBuffer,256,"V %d = ",i); @@ -2660,7 +2649,7 @@ Mesh* readBobjgz(char *filename, Mesh *orgmesh, float* bbstart, float *bbsize) / /* compute no. of triangles */ gotBytes = gzread(gzf, &wri, sizeof(wri)); newmesh->totface = wri; - newmesh->mface = CustomData_add_layer(&newmesh->fdata, CD_MFACE, 0, NULL, newmesh->totface); + newmesh->mface = CustomData_add_layer(&newmesh->fdata, CD_MFACE, CD_CALLOC, NULL, newmesh->totface); if(debugBobjRead){ snprintf(debugStrBuffer,256,"#faces %d ", newmesh->totface); elbeemDebugOut(debugStrBuffer); } //DEBUG fsface = newmesh->mface; for(i=0; i<newmesh->totface; i++) { @@ -2927,13 +2916,15 @@ void fluidsimGetAxisAlignedBB(struct Mesh *mesh, float obmat[][4], else { newmesh = *bbmesh; } newmesh->totvert = 8; - if(!newmesh->mvert) newmesh->mvert = CustomData_add_layer(&newmesh->vdata, CD_MVERT, 0, NULL, newmesh->totvert); + if(!newmesh->mvert) + newmesh->mvert = CustomData_add_layer(&newmesh->vdata, CD_MVERT, CD_CALLOC, NULL, newmesh->totvert); for(i=0; i<8; i++) { for(j=0; j<3; j++) newmesh->mvert[i].co[j] = start[j]; } newmesh->totface = 6; - if(!newmesh->mface) newmesh->mface = CustomData_add_layer(&newmesh->fdata, CD_MFACE, 0, NULL, newmesh->totface); + if(!newmesh->mface) + newmesh->mface = CustomData_add_layer(&newmesh->fdata, CD_MFACE, CD_CALLOC, NULL, newmesh->totface); *bbmesh = newmesh; } diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c index 9538deadd5b..d2b7ecaf881 100644 --- a/source/blender/blenkernel/intern/cdderivedmesh.c +++ b/source/blender/blenkernel/intern/cdderivedmesh.c @@ -725,9 +725,13 @@ DerivedMesh *CDDM_new(int numVerts, int numEdges, int numFaces) DM_init(dm, numVerts, numEdges, numFaces); - cddm->mvert = CustomData_add_layer(&dm->vertData, CD_MVERT, 0, 0, numVerts); - cddm->medge = CustomData_add_layer(&dm->edgeData, CD_MEDGE, 0, 0, numEdges); - cddm->mface = CustomData_add_layer(&dm->faceData, CD_MFACE, 0, 0, numFaces); + CustomData_add_layer(&dm->vertData, CD_MVERT, CD_CALLOC, NULL, numVerts); + CustomData_add_layer(&dm->edgeData, CD_MEDGE, CD_CALLOC, NULL, numEdges); + CustomData_add_layer(&dm->faceData, CD_MFACE, CD_CALLOC, NULL, numFaces); + + cddm->mvert = CustomData_get_layer(&dm->vertData, CD_MVERT); + cddm->medge = CustomData_get_layer(&dm->edgeData, CD_MEDGE); + cddm->mface = CustomData_get_layer(&dm->faceData, CD_MFACE); return dm; } @@ -765,8 +769,8 @@ DerivedMesh *CDDM_from_mesh(Mesh *mesh, Object *ob) for(i = 0; i < mesh->totface; ++i, ++index) *index = i; - /* works in conjunction with hack during modifier calc, where mcol is - temporarily replaced by weight paint colors */ + /* works in conjunction with hack during modifier calc, where active mcol + layer with weight paint colors is temporarily added */ if ((G.f & G_WEIGHTPAINT) && (ob && ob==(G.scene->basact?G.scene->basact->object:NULL))) CustomData_duplicate_referenced_layer(&dm->faceData, CD_MCOL); @@ -889,9 +893,9 @@ DerivedMesh *CDDM_copy(DerivedMesh *source) cddm->medge = source->dupEdgeArray(source); cddm->mface = source->dupFaceArray(source); - CustomData_add_layer(&dm->vertData, CD_MVERT, 0, cddm->mvert, numVerts); - CustomData_add_layer(&dm->edgeData, CD_MEDGE, 0, cddm->medge, numEdges); - CustomData_add_layer(&dm->faceData, CD_MFACE, 0, cddm->mface, numFaces); + CustomData_add_layer(&dm->vertData, CD_MVERT, CD_ASSIGN, cddm->mvert, numVerts); + CustomData_add_layer(&dm->edgeData, CD_MEDGE, CD_ASSIGN, cddm->medge, numEdges); + CustomData_add_layer(&dm->faceData, CD_MFACE, CD_ASSIGN, cddm->mface, numFaces); return dm; } @@ -906,9 +910,13 @@ DerivedMesh *CDDM_from_template(DerivedMesh *source, DM_from_template(dm, source, numVerts, numEdges, numFaces); /* now add mvert/medge/mface layers */ - cddm->mvert = CustomData_add_layer(&dm->vertData, CD_MVERT, 0, 0, numVerts); - cddm->medge = CustomData_add_layer(&dm->edgeData, CD_MEDGE, 0, 0, numEdges); - cddm->mface = CustomData_add_layer(&dm->faceData, CD_MFACE, 0, 0, numFaces); + CustomData_add_layer(&dm->vertData, CD_MVERT, CD_CALLOC, NULL, numVerts); + CustomData_add_layer(&dm->edgeData, CD_MEDGE, CD_CALLOC, NULL, numEdges); + CustomData_add_layer(&dm->faceData, CD_MFACE, CD_CALLOC, NULL, numFaces); + + cddm->mvert = CustomData_get_layer(&dm->vertData, CD_MVERT); + cddm->medge = CustomData_get_layer(&dm->edgeData, CD_MEDGE); + cddm->mface = CustomData_get_layer(&dm->faceData, CD_MFACE); return dm; } @@ -965,8 +973,8 @@ void CDDM_calc_normals(DerivedMesh *dm) /* make a face normal layer if not present */ face_nors = CustomData_get_layer(&dm->faceData, CD_NORMAL); if(!face_nors) - face_nors = CustomData_add_layer(&dm->faceData, CD_NORMAL, 0, NULL, - dm->numFaceData); + face_nors = CustomData_add_layer(&dm->faceData, CD_NORMAL, CD_CALLOC, + NULL, dm->numFaceData); /* calculate face normals and add to vertex normals */ mf = CDDM_get_faces(dm); @@ -1035,11 +1043,12 @@ void CDDM_calc_edges(DerivedMesh *dm) /* write new edges into a temporary CustomData */ memset(&edgeData, 0, sizeof(edgeData)); - CustomData_add_layer(&edgeData, CD_MEDGE, 0, NULL, numEdges); - index = CustomData_add_layer(&edgeData, CD_ORIGINDEX, 0, NULL, numEdges); + CustomData_add_layer(&edgeData, CD_MEDGE, CD_CALLOC, NULL, numEdges); + CustomData_add_layer(&edgeData, CD_ORIGINDEX, CD_CALLOC, NULL, numEdges); ehi = BLI_edgehashIterator_new(eh); med = CustomData_get_layer(&edgeData, CD_MEDGE); + index = CustomData_get_layer(&edgeData, CD_ORIGINDEX); for(i = 0; !BLI_edgehashIterator_isDone(ehi); BLI_edgehashIterator_step(ehi), ++i, ++med, ++index) { BLI_edgehashIterator_getKey(ehi, (int*)&med->v1, (int*)&med->v2); @@ -1062,7 +1071,7 @@ void CDDM_calc_edges(DerivedMesh *dm) void CDDM_lower_num_verts(DerivedMesh *dm, int numVerts) { if (numVerts < dm->numVertData) - CustomData_free_elem(&dm->vertData, numVerts, dm->numVertData - numVerts); + CustomData_free_elem(&dm->vertData, numVerts, dm->numVertData-numVerts); dm->numVertData = numVerts; } @@ -1070,7 +1079,7 @@ void CDDM_lower_num_verts(DerivedMesh *dm, int numVerts) void CDDM_lower_num_edges(DerivedMesh *dm, int numEdges) { if (numEdges < dm->numEdgeData) - CustomData_free_elem(&dm->edgeData, numEdges, dm->numEdgeData - numEdges); + CustomData_free_elem(&dm->edgeData, numEdges, dm->numEdgeData-numEdges); dm->numEdgeData = numEdges; } @@ -1078,7 +1087,7 @@ void CDDM_lower_num_edges(DerivedMesh *dm, int numEdges) void CDDM_lower_num_faces(DerivedMesh *dm, int numFaces) { if (numFaces < dm->numFaceData) - CustomData_free_elem(&dm->faceData, numFaces, dm->numFaceData - numFaces); + CustomData_free_elem(&dm->faceData, numFaces, dm->numFaceData-numFaces); dm->numFaceData = numFaces; } diff --git a/source/blender/blenkernel/intern/customdata.c b/source/blender/blenkernel/intern/customdata.c index 508021ef74c..65688f9529e 100644 --- a/source/blender/blenkernel/intern/customdata.c +++ b/source/blender/blenkernel/intern/customdata.c @@ -55,11 +55,9 @@ typedef struct LayerTypeInfo { /* a function to copy count elements of this layer's data * (deep copy if appropriate) - * size should be the size of one element of this layer's data (e.g. - * LayerTypeInfo.size) * if NULL, memcpy is used */ - void (*copy)(const void *source, void *dest, int count, int size); + void (*copy)(const void *source, void *dest, int count); /* a function to free any dynamically allocated components of this * layer's data (note the data pointer itself should not be freed) @@ -89,9 +87,9 @@ typedef struct LayerTypeInfo { } LayerTypeInfo; static void layerCopy_mdeformvert(const void *source, void *dest, - int count, int size) + int count) { - int i; + int i, size = sizeof(MDeformVert); memcpy(dest, source, count * size); @@ -205,7 +203,7 @@ static void layerInterp_msticky(void **sources, float *weights, } -static void layerCopy_tface(const void *source, void *dest, int count, int size) +static void layerCopy_tface(const void *source, void *dest, int count) { const MTFace *source_tf = (const MTFace*)source; MTFace *dest_tf = (MTFace*)dest; @@ -354,16 +352,17 @@ static void layerDefault_mcol(void *data, int count) const LayerTypeInfo LAYERTYPEINFO[CD_NUMTYPES] = { {sizeof(MVert), "MVert", 1, NULL, NULL, NULL, NULL, NULL}, - {sizeof(MSticky), "MSticky", 1, NULL, NULL, layerInterp_msticky, NULL, NULL}, + {sizeof(MSticky), "MSticky", 1, NULL, NULL, layerInterp_msticky, NULL, + NULL}, {sizeof(MDeformVert), "MDeformVert", 1, layerCopy_mdeformvert, layerFree_mdeformvert, layerInterp_mdeformvert, NULL, NULL}, {sizeof(MEdge), "MEdge", 1, NULL, NULL, NULL, NULL, NULL}, {sizeof(MFace), "MFace", 1, NULL, NULL, NULL, NULL, NULL}, - {sizeof(MTFace), "MTFace", 1, layerCopy_tface, NULL, layerInterp_tface, - layerSwap_tface, layerDefault_tface}, + {sizeof(MTFace), "MTFace", 1, layerCopy_tface, NULL, + layerInterp_tface, layerSwap_tface, layerDefault_tface}, /* 4 MCol structs per face */ - {sizeof(MCol)*4, "MCol", 4, NULL, NULL, layerInterp_mcol, layerSwap_mcol, - layerDefault_mcol}, + {sizeof(MCol)*4, "MCol", 4, NULL, NULL, layerInterp_mcol, + layerSwap_mcol, layerDefault_mcol}, {sizeof(int), "", 0, NULL, NULL, NULL, NULL, NULL}, /* 3 floats per normal vector */ {sizeof(float)*3, "", 0, NULL, NULL, NULL, NULL, NULL}, @@ -401,58 +400,46 @@ static const char *layerType_getName(int type) } /********************* CustomData functions *********************/ -static void CustomData_update_offsets(CustomData *data) -{ - const LayerTypeInfo *typeInfo; - int i, offset = 0; - - for(i = 0; i < data->totlayer; ++i) { - typeInfo = layerType_getInfo(data->layers[i].type); +static void customData_update_offsets(CustomData *data); - data->layers[i].offset = offset; - offset += typeInfo->size; - } - - data->totsize = offset; -} +static CustomDataLayer *customData_add_layer__internal(CustomData *data, + int type, int alloctype, void *layerdata, int totelem); void CustomData_merge(const struct CustomData *source, struct CustomData *dest, CustomDataMask mask, int alloctype, int totelem) { const LayerTypeInfo *typeInfo; - CustomDataLayer *layer; - int i, flag, type; - void *data; + CustomDataLayer *layer, *newlayer; + int i, type, number = 0, lasttype = -1, lastactive = 0; for(i = 0; i < source->totlayer; ++i) { layer = &source->layers[i]; typeInfo = layerType_getInfo(layer->type); - if(layer->flag & CD_FLAG_NOCOPY) continue; - else if(!(mask & (1 << layer->type))) continue; - else if(CustomData_has_layer(dest, layer->type)) continue; - type = layer->type; - flag = layer->flag & ~CD_FLAG_NOFREE; - data = layer->data; - if (alloctype == CD_CALLOC || alloctype == CD_DUPLICATE) { - CustomData_add_layer(dest, type, flag, NULL, totelem); + if (type != lasttype) { + number = 0; + lastactive = layer->active; + lasttype = type; } - else if (alloctype == CD_REFERENCE) { - CustomData_add_layer(dest, type, flag|CD_FLAG_NOFREE, data, totelem); - } - else if (alloctype == CD_DEFAULT) { - data = CustomData_add_layer(dest, type, flag, NULL, totelem); - if(typeInfo->set_default) - typeInfo->set_default((char*)data, totelem); - } - } + else + number++; - if (alloctype == CD_DUPLICATE) - CustomData_copy_data(source, dest, 0, 0, totelem); + if(layer->flag & CD_FLAG_NOCOPY) continue; + else if(!(mask & (1 << type))) continue; + else if(number < CustomData_number_of_layers(dest, type)) continue; - CustomData_update_offsets(dest); + if((alloctype == CD_ASSIGN) && (layer->flag & CD_FLAG_NOFREE)) + newlayer = customData_add_layer__internal(dest, type, CD_REFERENCE, + layer->data, totelem); + else + newlayer = customData_add_layer__internal(dest, type, alloctype, + layer->data, totelem); + + if(newlayer) + newlayer->active = lastactive; + } } void CustomData_copy(const struct CustomData *source, struct CustomData *dest, @@ -463,7 +450,7 @@ void CustomData_copy(const struct CustomData *source, struct CustomData *dest, CustomData_merge(source, dest, mask, alloctype, totelem); } -static void CustomData_free_layer__internal(CustomDataLayer *layer, int totelem) +static void customData_free_layer__internal(CustomDataLayer *layer, int totelem) { const LayerTypeInfo *typeInfo; @@ -483,7 +470,7 @@ void CustomData_free(CustomData *data, int totelem) int i; for(i = 0; i < data->totlayer; ++i) - CustomData_free_layer__internal(&data->layers[i], totelem); + customData_free_layer__internal(&data->layers[i], totelem); if(data->layers) MEM_freeN(data->layers); @@ -491,24 +478,61 @@ void CustomData_free(CustomData *data, int totelem) memset(data, 0, sizeof(*data)); } +static void customData_update_offsets(CustomData *data) +{ + const LayerTypeInfo *typeInfo; + int i, offset = 0; + + for(i = 0; i < data->totlayer; ++i) { + typeInfo = layerType_getInfo(data->layers[i].type); -/* gets index of first layer matching type after start_index - * if start_index < 0, starts searching at 0 - * returns -1 if there is no layer of type - */ -static int CustomData_find_next(const CustomData *data, int type, - int start_index) + data->layers[i].offset = offset; + offset += typeInfo->size; + } + + data->totsize = offset; +} + +static int CustomData_get_layer_index(const struct CustomData *data, int type) { - int i = start_index + 1; + int i; - if(i < 0) i = 0; + for(i=0; i < data->totlayer; ++i) + if(data->layers[i].type == type) + return i; - for(; i < data->totlayer; ++i) - if(data->layers[i].type == type) return i; + return -1; +} + +static int CustomData_get_active_layer_index(const CustomData *data, int type) +{ + int i; + + for(i=0; i < data->totlayer; ++i) + if(data->layers[i].type == type) + return i + data->layers[i].active; return -1; } +void CustomData_set_layer_active(CustomData *data, int type, int n) +{ + int i; + + for(i=0; i < data->totlayer; ++i) + if(data->layers[i].type == type) + data->layers[i].active = n; +} + +void CustomData_set_layer_flag(struct CustomData *data, int type, int flag) +{ + int i; + + for(i=0; i < data->totlayer; ++i) + if(data->layers[i].type == type) + data->layers[i].flag |= flag; +} + static int customData_resize(CustomData *data, int amount) { CustomDataLayer *tmp = MEM_callocN(sizeof(*tmp)*(data->maxlayer + amount), @@ -525,14 +549,42 @@ static int customData_resize(CustomData *data, int amount) return 1; } -static int customData_add_layer__internal(CustomData *data, int type, int flag, - void *layer) +static CustomDataLayer *customData_add_layer__internal(CustomData *data, + int type, int alloctype, void *layerdata, int totelem) { - int index = data->totlayer; + const LayerTypeInfo *typeInfo= layerType_getInfo(type); + int size = typeInfo->size * totelem, flag = 0, index = data->totlayer; + void *newlayerdata; - if(index >= data->maxlayer) - if(!customData_resize(data, CUSTOMDATA_GROW)) - return 0; + if((alloctype == CD_ASSIGN) || (alloctype == CD_REFERENCE)) { + newlayerdata = layerdata; + } + else { + newlayerdata = MEM_callocN(size, layerType_getName(type)); + if(!newlayerdata) + return NULL; + } + + if (alloctype == CD_DUPLICATE) { + if(typeInfo->copy) + typeInfo->copy(layerdata, newlayerdata, totelem); + else + memcpy(newlayerdata, layerdata, size); + } + else if (alloctype == CD_DEFAULT) { + if(typeInfo->set_default) + typeInfo->set_default((char*)newlayerdata, totelem); + } + else if (alloctype == CD_REFERENCE) + flag |= CD_FLAG_NOFREE; + + if(index >= data->maxlayer) { + if(!customData_resize(data, CUSTOMDATA_GROW)) { + if(newlayerdata != layerdata) + MEM_freeN(newlayerdata); + return NULL; + } + } /* keep layers ordered by type */ for( ; index > 0 && data->layers[index - 1].type > type; --index) @@ -540,61 +592,88 @@ static int customData_add_layer__internal(CustomData *data, int type, int flag, data->layers[index].type = type; data->layers[index].flag = flag; - data->layers[index].data = layer; + data->layers[index].data = newlayerdata; + + if(index > 0 && data->layers[index-1].type == type) + data->layers[index].active = data->layers[index-1].active; + else + data->layers[index].active = 0; data->totlayer++; - CustomData_update_offsets(data); + customData_update_offsets(data); - return 1; + return &data->layers[index]; } -void *CustomData_add_layer(CustomData *data, int type, int flag, +void *CustomData_add_layer(CustomData *data, int type, int alloctype, void *layerdata, int totelem) { - int size = layerType_getInfo(type)->size * totelem; - void *tmpdata = layerdata; + CustomDataLayer *layer; + + layer = customData_add_layer__internal(data, type, alloctype, layerdata, + totelem); - if(totelem > 0) { - if(!tmpdata) - tmpdata = MEM_callocN(size, layerType_getName(type)); - if(!tmpdata) - return NULL; - } + if(layer) + return layer->data; - if(!customData_add_layer__internal(data, type, flag, tmpdata)) { - if(tmpdata) - MEM_freeN(tmpdata); - return NULL; - } - - return tmpdata; + return NULL; } int CustomData_free_layer(CustomData *data, int type, int totelem) { - int index = CustomData_find_next(data, type, -1); + int index = 0, i; + CustomDataLayer *layer; + index = CustomData_get_active_layer_index(data, type); if (index < 0) return 0; - CustomData_free_layer__internal(&data->layers[index], totelem); + layer = &data->layers[index]; + + customData_free_layer__internal(&data->layers[index], totelem); - for(++index; index < data->totlayer; ++index) - data->layers[index - 1] = data->layers[index]; + for (i=index+1; i < data->totlayer; ++i) + data->layers[i-1] = data->layers[i]; data->totlayer--; - if(data->totlayer <= data->maxlayer-CUSTOMDATA_GROW) + /* if layer was last of type in array, set new active layer */ + if ((index >= data->totlayer) || (data->layers[index].type != type)) { + i = CustomData_get_layer_index(data, type); + + if (i >= 0) + for (; i < data->totlayer && data->layers[i].type == type; i++) + data->layers[i].active--; + } + + if (data->totlayer <= data->maxlayer-CUSTOMDATA_GROW) customData_resize(data, -CUSTOMDATA_GROW); - CustomData_update_offsets(data); + customData_update_offsets(data); return 1; } +void CustomData_free_layers(CustomData *data, int type, int totelem) +{ + while (CustomData_has_layer(data, type)) + CustomData_free_layer(data, type, totelem); +} + int CustomData_has_layer(const CustomData *data, int type) { - return (CustomData_find_next(data, type, -1) != -1); + return (CustomData_get_layer_index(data, type) != -1); +} + +int CustomData_number_of_layers(const CustomData *data, int type) +{ + int i, number = 0; + + for(i = 0; i < data->totlayer; i++) + if(data->layers[i].type == type) + number++; + + return number; } void *CustomData_duplicate_referenced_layer(struct CustomData *data, int type) @@ -603,7 +682,7 @@ void *CustomData_duplicate_referenced_layer(struct CustomData *data, int type) int layer_index; /* get the layer index of the first layer of type */ - layer_index = CustomData_find_next(data, type, -1); + layer_index = CustomData_get_active_layer_index(data, type); if(layer_index < 0) return NULL; layer = &data->layers[layer_index]; @@ -628,7 +707,7 @@ void CustomData_free_temporary(CustomData *data, int totelem) data->layers[j] = data->layers[i]; if ((layer->flag & CD_FLAG_TEMPORARY) == CD_FLAG_TEMPORARY) - CustomData_free_layer__internal(layer, totelem); + customData_free_layer__internal(layer, totelem); else j++; } @@ -638,21 +717,7 @@ void CustomData_free_temporary(CustomData *data, int totelem) if(data->totlayer <= data->maxlayer-CUSTOMDATA_GROW) customData_resize(data, -CUSTOMDATA_GROW); - CustomData_update_offsets(data); -} - -int CustomData_compat(const CustomData *data1, const CustomData *data2) -{ - int i; - - if(data1->totlayer != data2->totlayer) return 0; - - for(i = 0; i < data1->totlayer; ++i) { - if(data1->layers[i].type != data2->layers[i].type) return 0; - if(data1->layers[i].flag != data2->layers[i].flag) return 0; - } - - return 1; + customData_update_offsets(data); } void CustomData_set_only_copy(const struct CustomData *data, @@ -668,7 +733,7 @@ void CustomData_set_only_copy(const struct CustomData *data, void CustomData_copy_data(const CustomData *source, CustomData *dest, int source_index, int dest_index, int count) { - const LayerTypeInfo *type_info; + const LayerTypeInfo *typeInfo; int src_i, dest_i; int src_offset; int dest_offset; @@ -676,7 +741,6 @@ void CustomData_copy_data(const CustomData *source, CustomData *dest, /* copies a layer at a time */ dest_i = 0; for(src_i = 0; src_i < source->totlayer; ++src_i) { - if(source->layers[src_i].flag & CD_FLAG_NOCOPY) continue; /* find the first dest layer with type >= the source type * (this should work because layers are ordered by type) @@ -693,19 +757,19 @@ void CustomData_copy_data(const CustomData *source, CustomData *dest, char *src_data = source->layers[src_i].data; char *dest_data = dest->layers[dest_i].data; - type_info = layerType_getInfo(source->layers[src_i].type); + typeInfo = layerType_getInfo(source->layers[src_i].type); - src_offset = source_index * type_info->size; - dest_offset = dest_index * type_info->size; + src_offset = source_index * typeInfo->size; + dest_offset = dest_index * typeInfo->size; - if(type_info->copy) - type_info->copy(src_data + src_offset, + if(typeInfo->copy) + typeInfo->copy(src_data + src_offset, dest_data + dest_offset, - count, type_info->size); + count); else memcpy(dest_data + dest_offset, src_data + src_offset, - count * type_info->size); + count * typeInfo->size); /* if there are multiple source & dest layers of the same type, * we don't want to copy all source layers to the same dest, so @@ -755,24 +819,39 @@ void CustomData_interp(const CustomData *source, CustomData *dest, "CustomData_interp sources"); /* interpolates a layer at a time */ + dest_i = 0; for(src_i = 0; src_i < source->totlayer; ++src_i) { - CustomDataLayer *source_layer = &source->layers[src_i]; - const LayerTypeInfo *type_info = - layerType_getInfo(source_layer->type); + const LayerTypeInfo *typeInfo= layerType_getInfo(source->layers[src_i].type); + if(!typeInfo->interp) continue; - dest_i = CustomData_find_next(dest, source_layer->type, -1); + /* find the first dest layer with type >= the source type + * (this should work because layers are ordered by type) + */ + while(dest_i < dest->totlayer + && dest->layers[dest_i].type < source->layers[src_i].type) + ++dest_i; + + /* if there are no more dest layers, we're done */ + if(dest_i >= dest->totlayer) return; - if(dest_i >= 0 && type_info->interp) { - void *src_data = source_layer->data; + /* if we found a matching layer, copy the data */ + if(dest->layers[dest_i].type == source->layers[src_i].type) { + void *src_data = source->layers[src_i].data; for(j = 0; j < count; ++j) sources[j] = (char *)src_data - + type_info->size * src_indices[j]; + + typeInfo->size * src_indices[j]; - dest_offset = dest_index * type_info->size; + dest_offset = dest_index * typeInfo->size; - type_info->interp(sources, weights, sub_weights, count, - (char *)dest->layers[dest_i].data + dest_offset); + typeInfo->interp(sources, weights, sub_weights, count, + (char *)dest->layers[dest_i].data + dest_offset); + + /* if there are multiple source & dest layers of the same type, + * we don't want to copy all source layers to the same dest, so + * increment dest_i + */ + ++dest_i; } } @@ -800,8 +879,8 @@ void *CustomData_get(const CustomData *data, int index, int type) int offset; int layer_index; - /* get the layer index of the first layer of type */ - layer_index = CustomData_find_next(data, type, -1); + /* get the layer index of the active layer of type */ + layer_index = CustomData_get_active_layer_index(data, type); if(layer_index < 0) return NULL; /* get the offset of the desired element */ @@ -812,18 +891,26 @@ void *CustomData_get(const CustomData *data, int index, int type) void *CustomData_get_layer(const CustomData *data, int type) { - /* get the layer index of the first layer of type */ - int layer_index = CustomData_find_next(data, type, -1); - + /* get the layer index of the active layer of type */ + int layer_index = CustomData_get_active_layer_index(data, type); if(layer_index < 0) return NULL; return data->layers[layer_index].data; } +void *CustomData_get_layer_n(const CustomData *data, int type, int n) +{ + /* get the layer index of the active layer of type */ + int layer_index = CustomData_get_layer_index(data, type); + if(layer_index < 0) return NULL; + + return data->layers[layer_index+n].data; +} + void *CustomData_set_layer(const CustomData *data, int type, void *ptr) { /* get the layer index of the first layer of type */ - int layer_index = CustomData_find_next(data, type, -1); + int layer_index = CustomData_get_active_layer_index(data, type); if(layer_index < 0) return NULL; @@ -835,30 +922,14 @@ void *CustomData_set_layer(const CustomData *data, int type, void *ptr) void CustomData_set(const CustomData *data, int index, int type, void *source) { void *dest = CustomData_get(data, index, type); - const LayerTypeInfo *type_info = layerType_getInfo(type); + const LayerTypeInfo *typeInfo = layerType_getInfo(type); if(!dest) return; - if(type_info->copy) - type_info->copy(source, dest, 1, type_info->size); + if(typeInfo->copy) + typeInfo->copy(source, dest, 1); else - memcpy(dest, source, type_info->size); -} - -void CustomData_set_default(CustomData *data, int index, int count) -{ - const LayerTypeInfo *typeInfo; - int i; - - for(i = 0; i < data->totlayer; ++i) { - typeInfo = layerType_getInfo(data->layers[i].type); - - if(typeInfo->set_default) { - int offset = typeInfo->size * index; - - typeInfo->set_default((char *)data->layers[i].data + offset, count); - } - } + memcpy(dest, source, typeInfo->size); } /* EditMesh functions */ @@ -901,7 +972,7 @@ static void CustomData_em_alloc_block(CustomData *data, void **block) void CustomData_em_copy_data(const CustomData *source, CustomData *dest, void *src_block, void **dest_block) { - const LayerTypeInfo *type_info; + const LayerTypeInfo *typeInfo; int dest_i, src_i; if (!*dest_block) @@ -910,7 +981,6 @@ void CustomData_em_copy_data(const CustomData *source, CustomData *dest, /* copies a layer at a time */ dest_i = 0; for(src_i = 0; src_i < source->totlayer; ++src_i) { - if(source->layers[src_i].flag & CD_FLAG_NOCOPY) continue; /* find the first dest layer with type >= the source type * (this should work because layers are ordered by type) @@ -927,12 +997,12 @@ void CustomData_em_copy_data(const CustomData *source, CustomData *dest, char *src_data = (char*)src_block + source->layers[src_i].offset; char *dest_data = (char*)*dest_block + dest->layers[dest_i].offset; - type_info = layerType_getInfo(source->layers[src_i].type); + typeInfo = layerType_getInfo(source->layers[src_i].type); - if(type_info->copy) - type_info->copy(src_data, dest_data, 1, type_info->size); + if(typeInfo->copy) + typeInfo->copy(src_data, dest_data, 1); else - memcpy(dest_data, src_data, type_info->size); + memcpy(dest_data, src_data, typeInfo->size); /* if there are multiple source & dest layers of the same type, * we don't want to copy all source layers to the same dest, so @@ -948,7 +1018,7 @@ void *CustomData_em_get(const CustomData *data, void *block, int type) int layer_index; /* get the layer index of the first layer of type */ - layer_index = CustomData_find_next(data, type, -1); + layer_index = CustomData_get_active_layer_index(data, type); if(layer_index < 0) return NULL; return (char *)block + data->layers[layer_index].offset; @@ -957,14 +1027,14 @@ void *CustomData_em_get(const CustomData *data, void *block, int type) void CustomData_em_set(CustomData *data, void *block, int type, void *source) { void *dest = CustomData_em_get(data, block, type); - const LayerTypeInfo *type_info = layerType_getInfo(type); + const LayerTypeInfo *typeInfo = layerType_getInfo(type); if(!dest) return; - if(type_info->copy) - type_info->copy(source, dest, 1, type_info->size); + if(typeInfo->copy) + typeInfo->copy(source, dest, 1); else - memcpy(dest, source, type_info->size); + memcpy(dest, source, typeInfo->size); } void CustomData_em_interp(CustomData *data, void **src_blocks, float *weights, @@ -984,13 +1054,13 @@ void CustomData_em_interp(CustomData *data, void **src_blocks, float *weights, /* interpolates a layer at a time */ for(i = 0; i < data->totlayer; ++i) { CustomDataLayer *layer = &data->layers[i]; - const LayerTypeInfo *type_info = layerType_getInfo(layer->type); + const LayerTypeInfo *typeInfo = layerType_getInfo(layer->type); - if(type_info->interp) { + if(typeInfo->interp) { for(j = 0; j < count; ++j) sources[j] = (char *)src_blocks[j] + layer->offset; - type_info->interp(sources, weights, sub_weights, count, + typeInfo->interp(sources, weights, sub_weights, count, (char *)dest_block + layer->offset); } } @@ -1000,7 +1070,7 @@ void CustomData_em_interp(CustomData *data, void **src_blocks, float *weights, void CustomData_em_set_default(CustomData *data, void **block) { - const LayerTypeInfo *type_info; + const LayerTypeInfo *typeInfo; int i; if (!*block) @@ -1009,17 +1079,17 @@ void CustomData_em_set_default(CustomData *data, void **block) for(i = 0; i < data->totlayer; ++i) { int offset = data->layers[i].offset; - type_info = layerType_getInfo(data->layers[i].type); + typeInfo = layerType_getInfo(data->layers[i].type); - if(type_info->set_default) - type_info->set_default((char*)*block + offset, 1); + if(typeInfo->set_default) + typeInfo->set_default((char*)*block + offset, 1); } } void CustomData_to_em_block(const CustomData *source, CustomData *dest, int src_index, void **dest_block) { - const LayerTypeInfo *type_info; + const LayerTypeInfo *typeInfo; int dest_i, src_i, src_offset; if (!*dest_block) @@ -1028,7 +1098,6 @@ void CustomData_to_em_block(const CustomData *source, CustomData *dest, /* copies a layer at a time */ dest_i = 0; for(src_i = 0; src_i < source->totlayer; ++src_i) { - if(source->layers[src_i].flag & CD_FLAG_NOCOPY) continue; /* find the first dest layer with type >= the source type * (this should work because layers are ordered by type) @@ -1046,14 +1115,13 @@ void CustomData_to_em_block(const CustomData *source, CustomData *dest, char *src_data = source->layers[src_i].data; char *dest_data = (char*)*dest_block + offset; - type_info = layerType_getInfo(dest->layers[dest_i].type); - src_offset = src_index * type_info->size; + typeInfo = layerType_getInfo(dest->layers[dest_i].type); + src_offset = src_index * typeInfo->size; - if(type_info->copy) - type_info->copy(src_data + src_offset, dest_data, 1, - type_info->size); + if(typeInfo->copy) + typeInfo->copy(src_data + src_offset, dest_data, 1); else - memcpy(dest_data, src_data + src_offset, type_info->size); + memcpy(dest_data, src_data + src_offset, typeInfo->size); /* if there are multiple source & dest layers of the same type, * we don't want to copy all source layers to the same dest, so @@ -1067,13 +1135,12 @@ void CustomData_to_em_block(const CustomData *source, CustomData *dest, void CustomData_from_em_block(const CustomData *source, CustomData *dest, void *src_block, int dest_index) { - const LayerTypeInfo *type_info; + const LayerTypeInfo *typeInfo; int dest_i, src_i, dest_offset; /* copies a layer at a time */ dest_i = 0; for(src_i = 0; src_i < source->totlayer; ++src_i) { - if(source->layers[src_i].flag & CD_FLAG_NOCOPY) continue; /* find the first dest layer with type >= the source type * (this should work because layers are ordered by type) @@ -1091,14 +1158,13 @@ void CustomData_from_em_block(const CustomData *source, CustomData *dest, char *src_data = (char*)src_block + offset; char *dest_data = dest->layers[dest_i].data; - type_info = layerType_getInfo(dest->layers[dest_i].type); - dest_offset = dest_index * type_info->size; + typeInfo = layerType_getInfo(dest->layers[dest_i].type); + dest_offset = dest_index * typeInfo->size; - if(type_info->copy) - type_info->copy(src_data, dest_data + dest_offset, 1, - type_info->size); + if(typeInfo->copy) + typeInfo->copy(src_data, dest_data + dest_offset, 1); else - memcpy(dest_data + dest_offset, src_data, type_info->size); + memcpy(dest_data + dest_offset, src_data, typeInfo->size); /* if there are multiple source & dest layers of the same type, * we don't want to copy all source layers to the same dest, so @@ -1112,17 +1178,17 @@ void CustomData_from_em_block(const CustomData *source, CustomData *dest, void CustomData_file_write_info(int type, char **structname, int *structnum) { - const LayerTypeInfo *type_info = layerType_getInfo(type); + const LayerTypeInfo *typeInfo = layerType_getInfo(type); - *structname = type_info->structname; - *structnum = type_info->structnum; + *structname = typeInfo->structname; + *structnum = typeInfo->structnum; } int CustomData_sizeof(int type) { - const LayerTypeInfo *type_info = layerType_getInfo(type); + const LayerTypeInfo *typeInfo = layerType_getInfo(type); - return type_info->size; + return typeInfo->size; } const char *CustomData_layertype_name(int type) diff --git a/source/blender/blenkernel/intern/exotic.c b/source/blender/blenkernel/intern/exotic.c index 4946066e4b3..40c876d1d16 100644 --- a/source/blender/blenkernel/intern/exotic.c +++ b/source/blender/blenkernel/intern/exotic.c @@ -300,9 +300,9 @@ static void read_stl_mesh_binary(char *str) me= ob->data; me->totvert = totvert; me->totface = totface; - me->mvert = CustomData_add_layer(&me->vdata, CD_MVERT, 0, + me->mvert = CustomData_add_layer(&me->vdata, CD_MVERT, CD_ASSIGN, vertdata, totvert); - me->mface = CustomData_add_layer(&me->fdata, CD_MFACE, 0, + me->mface = CustomData_add_layer(&me->fdata, CD_MFACE, CD_ASSIGN, facedata, totface); mesh_add_normals_flags(me); @@ -444,9 +444,9 @@ static void read_stl_mesh_ascii(char *str) me->totface = totface; me->totvert = totvert; - me->mvert = CustomData_add_layer(&me->vdata, CD_MVERT, 0, + me->mvert = CustomData_add_layer(&me->vdata, CD_MVERT, CD_CALLOC, NULL, totvert); - me->mface = CustomData_add_layer(&me->fdata, CD_MFACE, 0, + me->mface = CustomData_add_layer(&me->fdata, CD_MFACE, CD_CALLOC, NULL, totface); /* Copy vert coords and create topology */ @@ -563,9 +563,9 @@ static void read_videoscape_mesh(char *str) me->totvert= verts; me->totface= totedge+tottria+totquad; - me->mvert= CustomData_add_layer(&me->vdata, CD_MVERT, 0, + me->mvert= CustomData_add_layer(&me->vdata, CD_MVERT, CD_CALLOC, NULL, me->totvert); - me->mface= CustomData_add_layer(&me->fdata, CD_MFACE, 0, + me->mface= CustomData_add_layer(&me->fdata, CD_MFACE, CD_CALLOC, NULL, me->totface); /* colors */ @@ -770,9 +770,9 @@ static void read_radiogour(char *str) me->totface= totedge+tottria+totquad; me->flag= 0; - me->mvert= CustomData_add_layer(&me->vdata, CD_MVERT, 0, + me->mvert= CustomData_add_layer(&me->vdata, CD_MVERT, CD_CALLOC, NULL, me->totvert); - me->mface= CustomData_add_layer(&me->fdata, CD_MFACE, 0, + me->mface= CustomData_add_layer(&me->fdata, CD_MFACE, CD_CALLOC, NULL, me->totface); /* verts */ @@ -2067,9 +2067,9 @@ static void displist_to_mesh(DispList *dlfirst) me->totvert= totvert; me->totface= totface; - me->mvert= CustomData_add_layer(&me->vdata, CD_MVERT, 0, + me->mvert= CustomData_add_layer(&me->vdata, CD_MVERT, CD_CALLOC, NULL, me->totvert); - me->mface= CustomData_add_layer(&me->fdata, CD_MFACE, 0, + me->mface= CustomData_add_layer(&me->fdata, CD_MFACE, CD_CALLOC, NULL, me->totface); maxvertidx= totvert-1; @@ -3640,8 +3640,8 @@ static void dxf_get_mesh(Mesh** m, Object** o, int noob) } me->totvert=0; me->totface=0; - me->mvert= CustomData_add_layer(&me->vdata, CD_MVERT, 0, NULL, 0); - me->mface= CustomData_add_layer(&me->fdata, CD_MFACE, 0, NULL, 0); + me->mvert= CustomData_add_layer(&me->vdata, CD_MVERT, CD_CALLOC, NULL, 0); + me->mface= CustomData_add_layer(&me->fdata, CD_MFACE, CD_CALLOC, NULL, 0); } static void dxf_read_point(int noob) { diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c index 52c094acca4..2556c2d734a 100644 --- a/source/blender/blenkernel/intern/mesh.c +++ b/source/blender/blenkernel/intern/mesh.c @@ -247,7 +247,8 @@ Mesh *add_mesh() Mesh *copy_mesh(Mesh *me) { Mesh *men; - int a; + MTFace *tface; + int a, i; men= copy_libblock(me); @@ -262,12 +263,15 @@ Mesh *copy_mesh(Mesh *me) CustomData_copy(&me->fdata, &men->fdata, CD_MASK_MESH, CD_DUPLICATE, men->totface); mesh_update_customdata_pointers(men); - if (me->mtface){ - /* ensure indirect linked data becomes lib-extern */ - MTFace *tface= me->mtface; - for(a=0; a<me->totface; a++, tface++) - if(tface->tpage) - id_lib_extern((ID*)tface->tpage); + /* ensure indirect linked data becomes lib-extern */ + for(i=0; i<me->fdata.totlayer; i++) { + if(me->fdata.layers[i].type == CD_MTFACE) { + tface= (MTFace*)me->fdata.layers[i].data; + + for(a=0; a<me->totface; a++, tface++) + if(tface->tpage) + id_lib_extern((ID*)tface->tpage); + } } if(me->mr) @@ -291,26 +295,25 @@ void make_local_tface(Mesh *me) { MTFace *tface; Image *ima; - int a; + int a, i; - if(me->mtface==0) return; - - a= me->totface; - tface= me->mtface; - while(a--) { - - /* special case: ima always local immediately */ - if(tface->tpage) { - ima= tface->tpage; - if(ima->id.lib) { - ima->id.lib= 0; - ima->id.flag= LIB_LOCAL; - new_id(0, (ID *)ima, 0); + for(i=0; i<me->fdata.totlayer; i++) { + if(me->fdata.layers[i].type == CD_MTFACE) { + tface= (MTFace*)me->fdata.layers[i].data; + + for(a=0; a<me->totface; a++, tface++) { + /* special case: ima always local immediately */ + if(tface->tpage) { + ima= tface->tpage; + if(ima->id.lib) { + ima->id.lib= 0; + ima->id.flag= LIB_LOCAL; + new_id(0, (ID *)ima, 0); + } + } } } - tface++; } - } void make_local_mesh(Mesh *me) @@ -687,7 +690,8 @@ void make_edges(Mesh *me, int old) final++; - medge= me->medge= CustomData_add_layer(&me->edata, CD_MEDGE, 0, NULL, final); + medge= CustomData_add_layer(&me->edata, CD_MEDGE, CD_CALLOC, NULL, final); + me->medge= medge; me->totedge= final; for(a=totedge, ed=edsort; a>1; a--, ed++) { @@ -750,8 +754,8 @@ void mball_to_mesh(ListBase *lb, Mesh *me) me->totvert= dl->nr; me->totface= dl->parts; - mvert= CustomData_add_layer(&me->vdata, CD_MVERT, 0, NULL, dl->nr); - mface= CustomData_add_layer(&me->fdata, CD_MFACE, 0, NULL, dl->parts); + mvert= CustomData_add_layer(&me->vdata, CD_MVERT, CD_CALLOC, NULL, dl->nr); + mface= CustomData_add_layer(&me->fdata, CD_MFACE, CD_CALLOC, NULL, dl->parts); me->mvert= mvert; me->mface= mface; @@ -841,8 +845,8 @@ void nurbs_to_mesh(Object *ob) cu->mat= 0; cu->totcol= 0; - mvert= CustomData_add_layer(&me->vdata, CD_MVERT, 0, NULL, me->totvert); - mface= CustomData_add_layer(&me->fdata, CD_MFACE, 0, NULL, me->totface); + mvert= CustomData_add_layer(&me->vdata, CD_MVERT, CD_CALLOC, NULL, me->totvert); + mface= CustomData_add_layer(&me->fdata, CD_MFACE, CD_CALLOC, NULL, me->totface); me->mvert= mvert; me->mface= mface; diff --git a/source/blender/blenkernel/intern/modifier.c b/source/blender/blenkernel/intern/modifier.c index 43c513aaa1b..17a059c01da 100644 --- a/source/blender/blenkernel/intern/modifier.c +++ b/source/blender/blenkernel/intern/modifier.c @@ -71,6 +71,7 @@ #include "BKE_main.h" #include "BKE_anim.h" #include "BKE_bad_level_calls.h" +#include "BKE_customdata.h" #include "BKE_global.h" #include "BKE_utildefines.h" #include "BKE_cdderivedmesh.h" @@ -2612,7 +2613,7 @@ static DerivedMesh *uvprojectModifier_do(UVProjectModifierData *umd, if(!tface) { if(!(umd->flags & MOD_UVPROJECT_ADDUVS)) return dm; - DM_add_face_layer(dm, CD_MTFACE, 0, NULL); + DM_add_face_layer(dm, CD_MTFACE, CD_CALLOC, NULL); tface = dm->getFaceDataArray(dm, CD_MTFACE); new_tfaces = 1; } diff --git a/source/blender/blenkernel/intern/subsurf_ccg.c b/source/blender/blenkernel/intern/subsurf_ccg.c index d44a0a2901f..7f3c5ddf8a7 100644 --- a/source/blender/blenkernel/intern/subsurf_ccg.c +++ b/source/blender/blenkernel/intern/subsurf_ccg.c @@ -211,42 +211,6 @@ static int getFaceIndex(CCGSubSurf *ss, CCGFace *f, int S, int x, int y, int edg } } -static float *getFaceUV(CCGSubSurf *ss, CCGFace *f, int S, int x, int y, int edgeSize, int gridSize) -{ - int numVerts = ccgSubSurf_getFaceNumVerts(ss, f); - - if (x==gridSize-1 && y==gridSize-1) { - CCGVert *v = ccgSubSurf_getFaceVert(ss, f, S); - return ccgSubSurf_getVertData(ss, v); - } - else if (x==gridSize-1) { - CCGVert *v = ccgSubSurf_getFaceVert(ss, f, S); - CCGEdge *e = ccgSubSurf_getFaceEdge(ss, f, S); - - if (v==ccgSubSurf_getEdgeVert0(ss, e)) - return ccgSubSurf_getEdgeData(ss, e, gridSize-1-y); - else - return ccgSubSurf_getEdgeData(ss, e, (edgeSize-2-1)-(gridSize-1-y-2)); - } - else if (y==gridSize-1) { - CCGVert *v = ccgSubSurf_getFaceVert(ss, f, S); - CCGEdge *e = ccgSubSurf_getFaceEdge(ss, f, (S+numVerts-1)%numVerts); - - if (v==ccgSubSurf_getEdgeVert0(ss, e)) - return ccgSubSurf_getEdgeData(ss, e, gridSize-1-x); - else - return ccgSubSurf_getEdgeData(ss, e, (edgeSize-2-1)-(gridSize-1-x-2)); - } - else if (x==0 && y==0) - return ccgSubSurf_getFaceCenterData(ss, f); - else if (x==0) - return ccgSubSurf_getFaceGridEdgeData(ss, f, (S+numVerts-1)%numVerts, y); - else if (y==0) - return ccgSubSurf_getFaceGridEdgeData(ss, f, S, x); - else - return ccgSubSurf_getFaceGridData(ss, f, S, x, y); -} - static void get_face_uv_map_vert(UvVertMap *vmap, struct MFace *mf, int fi, CCGVertHDL *fverts) { unsigned int *fv = &mf->v1; UvMapVert *v, *nv; @@ -264,10 +228,9 @@ static void get_face_uv_map_vert(UvVertMap *vmap, struct MFace *mf, int fi, CCGV } } -static int ss_sync_from_uv(CCGSubSurf *ss, CCGSubSurf *origss, DerivedMesh *dm) { +static int ss_sync_from_uv(CCGSubSurf *ss, CCGSubSurf *origss, DerivedMesh *dm, MTFace *tface) { MFace *mface = dm->getFaceArray(dm); MVert *mvert = dm->getVertArray(dm); - MTFace *tface = dm->getFaceDataArray(dm, CD_MTFACE); int totvert = dm->getNumVerts(dm); int totface = dm->getNumFaces(dm); int i, j, seam; @@ -362,6 +325,76 @@ static int ss_sync_from_uv(CCGSubSurf *ss, CCGSubSurf *origss, DerivedMesh *dm) return 1; } +static void set_subsurf_uv(CCGSubSurf *ss, DerivedMesh *dm, DerivedMesh *result, int n) +{ + CCGSubSurf *uvss; + CCGFace **faceMap; + MTFace *tf; + CCGFaceIterator *fi; + int index, gridSize, gridFaces, edgeSize, totface, x, y, S; + MTFace *dmtface = CustomData_get_layer_n(&dm->faceData, CD_MTFACE, n); + MTFace *tface = CustomData_get_layer_n(&result->faceData, CD_MTFACE, n); + + + if(!dmtface || !tface) + return; + + /* create a CCGSubsurf from uv's */ + uvss = _getSubSurf(NULL, ccgSubSurf_getSubdivisionLevels(ss), 0, 1, 0); + + if(!ss_sync_from_uv(uvss, ss, dm, dmtface)) { + ccgSubSurf_free(uvss); + return; + } + + /* get some info from CCGSubsurf */ + totface = ccgSubSurf_getNumFaces(uvss); + edgeSize = ccgSubSurf_getEdgeSize(uvss); + gridSize = ccgSubSurf_getGridSize(uvss); + gridFaces = gridSize - 1; + + /* make a map from original faces to CCGFaces */ + faceMap = MEM_mallocN(totface*sizeof(*faceMap), "facemapuv"); + + fi = ccgSubSurf_getFaceIterator(uvss); + for(; !ccgFaceIterator_isStopped(fi); ccgFaceIterator_next(fi)) { + CCGFace *f = ccgFaceIterator_getCurrent(fi); + faceMap[(int) ccgSubSurf_getFaceFaceHandle(uvss, f)] = f; + } + ccgFaceIterator_free(fi); + + /* load coordinates from uvss into tface */ + tf= tface; + + for(index = 0; index < totface; index++) { + CCGFace *f = faceMap[index]; + int numVerts = ccgSubSurf_getFaceNumVerts(uvss, f); + + for (S=0; S<numVerts; S++) { + VertData *faceGridData= ccgSubSurf_getFaceGridDataArray(uvss, f, S); + + for(y = 0; y < gridFaces; y++) { + for(x = 0; x < gridFaces; x++) { + float *a = faceGridData[(y + 0)*gridSize + x + 0].co; + float *b = faceGridData[(y + 0)*gridSize + x + 1].co; + float *c = faceGridData[(y + 1)*gridSize + x + 1].co; + float *d = faceGridData[(y + 1)*gridSize + x + 0].co; + + tf->uv[0][0] = a[0]; tf->uv[0][1] = a[1]; + tf->uv[1][0] = d[0]; tf->uv[1][1] = d[1]; + tf->uv[2][0] = c[0]; tf->uv[2][1] = c[1]; + tf->uv[3][0] = b[0]; tf->uv[3][1] = b[1]; + + tf++; + } + } + } + } + + ccgSubSurf_free(uvss); + MEM_freeN(faceMap); +} + #if 0 static unsigned int ss_getEdgeFlags(CCGSubSurf *ss, CCGEdge *e, int ssFromEditmesh, DispListMesh *dlm, MEdge *medge, MTFace *tface) { @@ -393,7 +426,7 @@ static unsigned int ss_getEdgeFlags(CCGSubSurf *ss, CCGEdge *e, int ssFromEditme } #endif -/* face weighting - taken from Brecht's element data patch */ +/* face weighting */ static void calc_ss_weights(int gridFaces, FaceVertWeight **qweight, FaceVertWeight **tweight) { @@ -451,15 +484,13 @@ DerivedMesh *ss_to_cdderivedmesh(CCGSubSurf *ss, int ssFromEditmesh, CCGVertIterator *vi; CCGEdgeIterator *ei; CCGFaceIterator *fi; - CCGFace **faceMap2, **faceMap2Uv = NULL; + CCGFace **faceMap2; CCGEdge **edgeMap2; CCGVert **vertMap2; int totvert, totedge, totface; MVert *mvert; MEdge *med; MFace *mf; - MTFace *tface; - CCGSubSurf *uvss = NULL; int *origIndex; FaceVertWeight *qweight, *tweight; @@ -499,29 +530,10 @@ DerivedMesh *ss_to_cdderivedmesh(CCGSubSurf *ss, int ssFromEditmesh, result = CDDM_from_template(dm, ccgSubSurf_getNumFinalVerts(ss), ccgSubSurf_getNumFinalEdges(ss), ccgSubSurf_getNumFinalFaces(ss)); - tface = dm->getFaceDataArray(dm, CD_MTFACE); } else { result = CDDM_new(ccgSubSurf_getNumFinalVerts(ss), ccgSubSurf_getNumFinalEdges(ss), ccgSubSurf_getNumFinalFaces(ss)); - tface = NULL; - } - - if(useSubsurfUv && result->getFaceDataArray(result, CD_MTFACE)) { - uvss = _getSubSurf(NULL, ccgSubSurf_getSubdivisionLevels(ss), - 0, 1, 0); - - if(ss_sync_from_uv(uvss, ss, dm)) { - faceMap2Uv = MEM_mallocN(totface * sizeof(*faceMap2Uv), - "facemapuv"); - - fi = ccgSubSurf_getFaceIterator(uvss); - for(; !ccgFaceIterator_isStopped(fi); ccgFaceIterator_next(fi)) { - CCGFace *f = ccgFaceIterator_getCurrent(fi); - faceMap2Uv[(int) ccgSubSurf_getFaceFaceHandle(uvss, f)] = f; - } - ccgFaceIterator_free(fi); - } } // load verts @@ -718,7 +730,6 @@ DerivedMesh *ss_to_cdderivedmesh(CCGSubSurf *ss, int ssFromEditmesh, for(index = 0; index < totface; index++) { CCGFace *f = faceMap2[index]; - CCGFace *uvf = faceMap2Uv ? faceMap2Uv[index] : NULL; int numVerts = ccgSubSurf_getFaceNumVerts(ss, f); int mat_nr; int flag; @@ -771,25 +782,6 @@ DerivedMesh *ss_to_cdderivedmesh(CCGSubSurf *ss, int ssFromEditmesh, weight++; } - if(uvf) { - MTFace *tf = DM_get_face_data(result, i, - CD_MTFACE); - float *newuv; - - newuv = getFaceUV(uvss, uvf, S, x + 0, y + 0, - edgeSize, gridSize); - tf->uv[0][0] = newuv[0]; tf->uv[0][1] = newuv[1]; - newuv = getFaceUV(uvss, uvf, S, x + 0, y + 1, - edgeSize, gridSize); - tf->uv[1][0] = newuv[0]; tf->uv[1][1] = newuv[1]; - newuv = getFaceUV(uvss, uvf, S, x + 1, y + 1, - edgeSize, gridSize); - tf->uv[2][0] = newuv[0]; tf->uv[2][1] = newuv[1]; - newuv = getFaceUV(uvss, uvf, S, x + 1, y + 0, - edgeSize, gridSize); - tf->uv[3][0] = newuv[0]; tf->uv[3][1] = newuv[1]; - } - *origIndex = mapIndex; ++mf; ++origIndex; @@ -806,9 +798,14 @@ DerivedMesh *ss_to_cdderivedmesh(CCGSubSurf *ss, int ssFromEditmesh, MEM_freeN(tweight); MEM_freeN(qweight); - if(uvss) { - ccgSubSurf_free(uvss); - MEM_freeN(faceMap2Uv); + if(useSubsurfUv) { + CustomData *fdata = &result->faceData; + CustomData *dmfdata = &dm->faceData; + int numlayer = CustomData_number_of_layers(fdata, CD_MTFACE); + int dmnumlayer = CustomData_number_of_layers(dmfdata, CD_MTFACE); + + for (i=0; i<numlayer && i<dmnumlayer; i++) + set_subsurf_uv(ss, dm, result, i); } CDDM_calc_normals(result); @@ -2060,25 +2057,21 @@ static CCGDerivedMesh *getCCGDerivedMesh(CCGSubSurf *ss, MVert *mvert = NULL; MEdge *medge = NULL; MFace *mface = NULL; - MTFace *tface; - CCGSubSurf *uvss = NULL; - CCGFace **faceMap2Uv = NULL; FaceVertWeight *qweight, *tweight; if(dm) { DM_from_template(&ccgdm->dm, dm, ccgSubSurf_getNumFinalVerts(ss), ccgSubSurf_getNumFinalEdges(ss), ccgSubSurf_getNumFinalFaces(ss)); - tface = dm->getFaceDataArray(dm, CD_MTFACE); - DM_add_face_layer(&ccgdm->dm, CD_FLAGS, CD_FLAG_NOCOPY, NULL); - DM_add_edge_layer(&ccgdm->dm, CD_FLAGS, CD_FLAG_NOCOPY, NULL); + DM_add_face_layer(&ccgdm->dm, CD_FLAGS, CD_CALLOC, NULL); + DM_add_edge_layer(&ccgdm->dm, CD_FLAGS, CD_CALLOC, NULL); + + CustomData_set_layer_flag(&ccgdm->dm.faceData, CD_FLAGS, CD_FLAG_NOCOPY); + CustomData_set_layer_flag(&ccgdm->dm.edgeData, CD_FLAGS, CD_FLAG_NOCOPY); } else { DM_init(&ccgdm->dm, ccgSubSurf_getNumFinalVerts(ss), ccgSubSurf_getNumFinalEdges(ss), ccgSubSurf_getNumFinalFaces(ss)); - - if(me) tface = me->mtface; - else tface = NULL; } ccgdm->dm.getMinMax = ccgDM_getMinMax; @@ -2152,24 +2145,6 @@ static CCGDerivedMesh *getCCGDerivedMesh(CCGSubSurf *ss, } ccgFaceIterator_free(fi); - if(useSubsurfUv && dm->getFaceDataArray(&ccgdm->dm, CD_MTFACE)) { - /* not for editmesh currently */ - uvss = _getSubSurf(NULL, ccgSubSurf_getSubdivisionLevels(ss), - 0, 1, 0); - - if(ss_sync_from_uv(uvss, ss, dm)) { - faceMap2Uv = MEM_mallocN(totface * sizeof(*faceMap2Uv), - "facemapuv"); - - fi = ccgSubSurf_getFaceIterator(uvss); - for(; !ccgFaceIterator_isStopped(fi); ccgFaceIterator_next(fi)) { - CCGFace *f = ccgFaceIterator_getCurrent(fi); - faceMap2Uv[(int) ccgSubSurf_getFaceFaceHandle(uvss, f)] = f; - } - ccgFaceIterator_free(fi); - } - } - edgeSize = ccgSubSurf_getEdgeSize(ss); gridSize = ccgSubSurf_getGridSize(ss); gridFaces = gridSize - 1; @@ -2202,7 +2177,6 @@ static CCGDerivedMesh *getCCGDerivedMesh(CCGSubSurf *ss, for(index = 0; index < totface; ++index) { CCGFace *f = ccgdm->faceMap[index].face; - CCGFace *uvf = faceMap2Uv ? faceMap2Uv[index] : NULL; int numVerts = ccgSubSurf_getFaceNumVerts(ss, f); int numFinalEdges = numVerts * (gridSideEdges + gridInternalEdges); int mapIndex = ccgDM_getFaceMapIndex(ccgdm, ss, f); @@ -2295,25 +2269,6 @@ static CCGDerivedMesh *getCCGDerivedMesh(CCGSubSurf *ss, &w, 1, faceNum); weight++; - if(uvf) { - MTFace *tf = DM_get_face_data(&ccgdm->dm, faceNum, - CD_MTFACE); - float *newuv; - - newuv = getFaceUV(uvss, uvf, S, x + 0, y + 0, - edgeSize, gridSize); - tf->uv[0][0] = newuv[0]; tf->uv[0][1] = newuv[1]; - newuv = getFaceUV(uvss, uvf, S, x + 0, y + 1, - edgeSize, gridSize); - tf->uv[1][0] = newuv[0]; tf->uv[1][1] = newuv[1]; - newuv = getFaceUV(uvss, uvf, S, x + 1, y + 1, - edgeSize, gridSize); - tf->uv[2][0] = newuv[0]; tf->uv[2][1] = newuv[1]; - newuv = getFaceUV(uvss, uvf, S, x + 1, y + 0, - edgeSize, gridSize); - tf->uv[3][0] = newuv[0]; tf->uv[3][1] = newuv[1]; - } - *faceOrigIndex = mapIndex; ++faceOrigIndex; @@ -2327,9 +2282,14 @@ static CCGDerivedMesh *getCCGDerivedMesh(CCGSubSurf *ss, edgeNum += numFinalEdges; } - if(uvss) { - ccgSubSurf_free(uvss); - MEM_freeN(faceMap2Uv); + if(useSubsurfUv) { + CustomData *fdata = &ccgdm->dm.faceData; + CustomData *dmfdata = &dm->faceData; + int numlayer = CustomData_number_of_layers(fdata, CD_MTFACE); + int dmnumlayer = CustomData_number_of_layers(dmfdata, CD_MTFACE); + + for (i=0; i<numlayer && i<dmnumlayer; i++) + set_subsurf_uv(ss, dm, &ccgdm->dm, i); } edgeFlags = DM_get_edge_data_layer(&ccgdm->dm, CD_FLAGS); diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index e593036725d..c672ef80c03 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -2460,9 +2460,9 @@ static void direct_link_customdata(FileData *fd, CustomData *data, int count) i++; } else { - /* delete layer with unknown type */ + /* delete layers with unknown type */ layer->data = NULL; - CustomData_free_layer(data, layer->type, 0); + CustomData_free_layers(data, layer->type, 0); } } } @@ -4189,25 +4189,26 @@ static void customdata_version_242(Mesh *me) int a; if (!me->vdata.totlayer) { - CustomData_add_layer(&me->vdata, CD_MVERT, 0, me->mvert, me->totvert); + CustomData_add_layer(&me->vdata, CD_MVERT, CD_ASSIGN, me->mvert, me->totvert); if (me->msticky) - CustomData_add_layer(&me->vdata, CD_MSTICKY, 0, me->msticky, me->totvert); + CustomData_add_layer(&me->vdata, CD_MSTICKY, CD_ASSIGN, me->msticky, me->totvert); if (me->dvert) - CustomData_add_layer(&me->vdata, CD_MDEFORMVERT, 0, me->dvert, me->totvert); + CustomData_add_layer(&me->vdata, CD_MDEFORMVERT, CD_ASSIGN, me->dvert, me->totvert); } if (!me->edata.totlayer) - CustomData_add_layer(&me->edata, CD_MEDGE, 0, me->medge, me->totedge); + CustomData_add_layer(&me->edata, CD_MEDGE, CD_ASSIGN, me->medge, me->totedge); if (!me->fdata.totlayer) { - CustomData_add_layer(&me->fdata, CD_MFACE, 0, me->mface, me->totface); + CustomData_add_layer(&me->fdata, CD_MFACE, CD_ASSIGN, me->mface, me->totface); - if (me->mcol || me->tface) - me->mcol= CustomData_add_layer(&me->fdata, CD_MCOL, 0, me->mcol, me->totface); - - if (me->tface) { - me->mtface= CustomData_add_layer(&me->fdata, CD_MTFACE, 0, NULL, me->totface); + if (me->mcol) { + me->mcol= CustomData_add_layer(&me->fdata, CD_MCOL, CD_ASSIGN, me->mcol, me->totface); + } + else if (me->tface) { + me->mcol= CustomData_add_layer(&me->fdata, CD_MCOL, CD_CALLOC, NULL, me->totface); + me->mtface= CustomData_add_layer(&me->fdata, CD_MTFACE, CD_CALLOC, NULL, me->totface); mtf= me->mtface; mcol= me->mcol; diff --git a/source/blender/include/BDR_editface.h b/source/blender/include/BDR_editface.h index 5501709914e..edb54325ff4 100644 --- a/source/blender/include/BDR_editface.h +++ b/source/blender/include/BDR_editface.h @@ -40,7 +40,6 @@ struct MCol; struct MTFace *get_active_tface(struct MCol **mcol); void calculate_uv_map(unsigned short mapmode); void default_uv(float uv[][2], float size); -void default_tface(struct MTFace *tface); void make_tfaces(struct Mesh *me); void reveal_tface(void); void hide_tface(void); diff --git a/source/blender/include/butspace.h b/source/blender/include/butspace.h index c82fa6faf08..bd0b2adaa31 100644 --- a/source/blender/include/butspace.h +++ b/source/blender/include/butspace.h @@ -389,22 +389,24 @@ void curvemap_buttons(struct uiBlock *block, struct CurveMapping *cumap, char la #define B_FRACSUBDIV 2059 #define B_XSORT 2060 #define B_HASH 2061 -#define B_DELSTICKY 2062 -#define B_DELVERTCOL 2063 -#define B_MAKE_TFACES 2064 -#define B_TOSPHERE 2065 -#define B_DEL_TFACES 2066 +#define B_MAKESTICKY 2062 +#define B_DELSTICKY 2063 +#define B_NEWMCOL 2064 +#define B_DELMCOL 2065 +#define B_TOSPHERE 2066 #define B_DECIM_FACES 2067 #define B_DECIM_CANCEL 2068 #define B_DECIM_APPLY 2069 /* B_SLOWERDRAW and B_FASTERDRAW removed */ #define B_VERTEXNOISE 2072 #define B_VERTEXSMOOTH 2073 -#define B_MAKESTICKY 2074 -#define B_MAKEVERTCOL 2075 +#define B_NEWTFACE 2074 +#define B_DELTFACE 2075 #define B_CHROMADEPTH 2076 #define B_DRAWEDGES 2077 #define B_DRAWCREASES 2078 +#define B_SETTFACE 2079 +#define B_SETMCOL 2080 /* *********************** */ #define B_VGROUPBUTS 2100 diff --git a/source/blender/makesdna/DNA_customdata_types.h b/source/blender/makesdna/DNA_customdata_types.h index 00c303c0357..83111f58c67 100644 --- a/source/blender/makesdna/DNA_customdata_types.h +++ b/source/blender/makesdna/DNA_customdata_types.h @@ -36,13 +36,14 @@ typedef struct CustomDataLayer { int type; /* type of data in layer */ int offset; /* in editmode, offset of layer in block */ - int flag, pad; /* general purpose flag */ + int flag; /* general purpose flag */ + int active; /* number of the active layer of this type */ void *data; /* layer data */ } CustomDataLayer; /* structure which stores custom element data associated with mesh elements * (vertices, edges or faces). The custom data is organised into a series of - * layers, each with a data type (e.g. TFace, MDeformVert, etc.). */ + * layers, each with a data type (e.g. MTFace, MDeformVert, etc.). */ typedef struct CustomData { CustomDataLayer *layers; /* CustomDataLayers, ordered by type */ int totlayer, maxlayer; /* number of layers, size of layers array */ diff --git a/source/blender/python/api2_2x/Mesh.c b/source/blender/python/api2_2x/Mesh.c index 8e0d5e93284..5e75d09b669 100644 --- a/source/blender/python/api2_2x/Mesh.c +++ b/source/blender/python/api2_2x/Mesh.c @@ -332,7 +332,7 @@ static void delete_verts( Mesh *mesh, unsigned int *vert_table, int to_delete ) ++count; } else { if( count ) { - CustomData_copy_data( &mesh->vdata, &vdata, i, + CustomData_copy_data( &mesh->vdata, &vdata, i-count, dstindex, count ); dstindex += count; } @@ -344,7 +344,7 @@ static void delete_verts( Mesh *mesh, unsigned int *vert_table, int to_delete ) /* if we were gathering verts at the end of the loop, copy those */ if( state && count ) - CustomData_copy_data( &mesh->vdata, &vdata, i, dstindex, count ); + CustomData_copy_data( &mesh->vdata, &vdata, i-count, dstindex, count ); /* delete old vertex list, install the new one, update vertex count */ CustomData_free( &mesh->vdata, mesh->totvert ); @@ -402,7 +402,7 @@ static void delete_edges( Mesh *mesh, unsigned int *vert_table, int to_delete ) ++count; } else { if( count ) { - CustomData_copy_data( &mesh->edata, &edata, i, + CustomData_copy_data( &mesh->edata, &edata, i-count, dstindex, count ); dstindex += count; } @@ -415,7 +415,8 @@ static void delete_edges( Mesh *mesh, unsigned int *vert_table, int to_delete ) /* copy any pending good edges */ if( state && count ) - CustomData_copy_data( &mesh->edata, &edata, i, dstindex, count ); + CustomData_copy_data( &mesh->edata, &edata, i-count, dstindex, + count ); /* delete old edge list, install the new one, update vertex count */ CustomData_free( &mesh->edata, mesh->totedge ); @@ -472,7 +473,7 @@ static void delete_faces( Mesh *mesh, unsigned int *vert_table, int to_delete ) ++count; } else { if( count ) { - CustomData_copy_data( &mesh->fdata, &fdata, i, + CustomData_copy_data( &mesh->fdata, &fdata, i-count, dstindex, count ); dstindex += count; } @@ -485,7 +486,8 @@ static void delete_faces( Mesh *mesh, unsigned int *vert_table, int to_delete ) /* if we were gathering faces at the end of the loop, copy those */ if ( state && count ) - CustomData_copy_data( &mesh->fdata, &fdata, i, dstindex, count ); + CustomData_copy_data( &mesh->fdata, &fdata, i-count, dstindex, + count ); /* delete old face list, install the new one, update face count */ @@ -1690,12 +1692,11 @@ static PyObject *MVertSeq_extend( BPy_MVertSeq * self, PyObject *args ) /* create custom vertex data arrays and copy existing vertices into it */ newlen = mesh->totvert + len; - CustomData_copy( &mesh->vdata, &vdata, CD_MASK_MESH, CD_CALLOC, newlen ); + CustomData_copy( &mesh->vdata, &vdata, CD_MASK_MESH, CD_DEFAULT, newlen ); CustomData_copy_data( &mesh->vdata, &vdata, 0, 0, mesh->totvert ); - CustomData_set_default( &vdata, mesh->totvert, len ); if ( !CustomData_has_layer( &vdata, CD_MVERT ) ) - CustomData_add_layer( &vdata, CD_MVERT, 0, NULL, newlen ); + CustomData_add_layer( &vdata, CD_MVERT, CD_CALLOC, NULL, newlen ); newvert = CustomData_get_layer( &vdata, CD_MVERT ); @@ -2860,12 +2861,11 @@ static PyObject *MEdgeSeq_extend( BPy_MEdgeSeq * self, PyObject *args ) int totedge = mesh->totedge+good_edges; /* create custom edge data arrays and copy existing edges into it */ - CustomData_copy( &mesh->edata, &edata, CD_MASK_MESH, CD_CALLOC, totedge ); + CustomData_copy( &mesh->edata, &edata, CD_MASK_MESH, CD_DEFAULT, totedge ); CustomData_copy_data( &mesh->edata, &edata, 0, 0, mesh->totedge ); - CustomData_set_default( &edata, mesh->totedge, good_edges ); if ( !CustomData_has_layer( &edata, CD_MEDGE ) ) - CustomData_add_layer( &edata, CD_MEDGE, 0, NULL, totedge ); + CustomData_add_layer( &edata, CD_MEDGE, CD_CALLOC, NULL, totedge ); /* replace old with new data */ CustomData_free( &mesh->edata, mesh->totedge ); @@ -4804,12 +4804,11 @@ static PyObject *MFaceSeq_extend( BPy_MEdgeSeq * self, PyObject *args, int totface = mesh->totface+good_faces; /* new face count */ CustomData fdata; - CustomData_copy( &mesh->fdata, &fdata, CD_MASK_MESH, CD_CALLOC, totface ); + CustomData_copy( &mesh->fdata, &fdata, CD_MASK_MESH, CD_DEFAULT, totface ); CustomData_copy_data( &mesh->fdata, &fdata, 0, 0, mesh->totface ); - CustomData_set_default( &fdata, mesh->totface, good_faces ); if ( !CustomData_has_layer( &fdata, CD_MFACE ) ) - CustomData_add_layer( &fdata, CD_MFACE, 0, NULL, totface ); + CustomData_add_layer( &fdata, CD_MFACE, CD_CALLOC, NULL, totface ); CustomData_free( &mesh->fdata, mesh->totface ); mesh->fdata = fdata; @@ -6822,7 +6821,7 @@ static PyObject *Mesh_getFlag( BPy_Mesh * self, void *type ) static int Mesh_setFlag( BPy_Mesh * self, PyObject *value, void *type ) { - int param, i; + int param; Mesh *mesh = self->mesh; param = PyObject_IsTrue( value ); @@ -6837,7 +6836,7 @@ static int Mesh_setFlag( BPy_Mesh * self, PyObject *value, void *type ) case MESH_HASFACEUV: if( !param ) { if( mesh->mtface ) { - CustomData_free_layer( &mesh->fdata, CD_MTFACE, mesh->totface ); + CustomData_free_layers( &mesh->fdata, CD_MTFACE, mesh->totface ); mesh->mtface = NULL; } } else if( !mesh->mtface ) { @@ -6850,15 +6849,13 @@ static int Mesh_setFlag( BPy_Mesh * self, PyObject *value, void *type ) case MESH_HASMCOL: if( !param ) { if( mesh->mcol ) { - CustomData_free_layer( &mesh->fdata, CD_MCOL, mesh->totface ); + CustomData_free_layers( &mesh->fdata, CD_MCOL, mesh->totface ); mesh->mcol = NULL; } } else if( !mesh->mcol ) { /* TODO: mesh_create_shadedColors */ - mesh->mcol = CustomData_add_layer( &mesh->fdata, CD_MCOL, 0, NULL, - mesh->totface ); - for( i = 0; i < mesh->totface*4; i++ ) - mesh->mcol[i].a = 255; + mesh->mcol = CustomData_add_layer( &mesh->fdata, CD_MCOL, + CD_DEFAULT, NULL, mesh->totface ); } return 0; case MESH_HASVERTUV: @@ -6870,7 +6867,7 @@ static int Mesh_setFlag( BPy_Mesh * self, PyObject *value, void *type ) } else { if( !mesh->msticky ) { mesh->msticky = CustomData_add_layer( &mesh->vdata, CD_MSTICKY, - 0, NULL, mesh->totvert ); + CD_CALLOC, NULL, mesh->totvert ); memset( mesh->msticky, 255, mesh->totvert*sizeof( MSticky ) ); /* TODO: rework RE_make_sticky() so we can calculate */ } diff --git a/source/blender/python/api2_2x/NMesh.c b/source/blender/python/api2_2x/NMesh.c index 7cd3d74673f..f7728234ad8 100644 --- a/source/blender/python/api2_2x/NMesh.c +++ b/source/blender/python/api2_2x/NMesh.c @@ -2778,8 +2778,8 @@ static int unlink_existingMeshData( Mesh * mesh ) mesh_update_customdata_pointers( mesh ); if(dvert) - mesh->dvert= CustomData_add_layer( &mesh->vdata, CD_MDEFORMVERT, 0, - dvert, mesh->totvert ); + mesh->dvert= CustomData_add_layer( &mesh->vdata, CD_MDEFORMVERT, + CD_ASSIGN, dvert, mesh->totvert ); mesh->totedge = 0; @@ -2939,7 +2939,9 @@ static void fill_medge_from_nmesh(Mesh * mesh, BPy_NMesh * nmesh) /* Now we have the total count of valid edges */ mesh->totedge=tot_valid_nmedges+tot_valid_faces_edges; - mesh->medge= CustomData_add_layer(&mesh->edata, CD_MEDGE, 0, NULL, mesh->totedge); + mesh->medge= CustomData_add_layer( &mesh->edata, CD_MEDGE, CD_CALLOC, NULL, + mesh->totedge ); + for ( i = 0; i < tot_valid_nmedges; ++i ) { BPy_NMEdge *edge=valid_nmedges[i]; @@ -3013,11 +3015,11 @@ static int convert_NMeshToMesh( Mesh * mesh, BPy_NMesh * nmesh) mesh->totvert = PySequence_Length( nmesh->verts ); if( mesh->totvert ) { if( nmesh->flags & NMESH_HASVERTUV ) - mesh->msticky = CustomData_add_layer( &mesh->vdata, CD_MSTICKY, 0, - NULL, mesh->totvert ); + mesh->msticky = CustomData_add_layer( &mesh->vdata, CD_MSTICKY, + CD_CALLOC, NULL, mesh->totvert ); - mesh->mvert = CustomData_add_layer( &mesh->vdata, CD_MVERT, 0, NULL, - mesh->totvert ); + mesh->mvert = CustomData_add_layer( &mesh->vdata, CD_MVERT, CD_CALLOC, + NULL, mesh->totvert ); } if( mesh->totvert ) @@ -3027,11 +3029,11 @@ static int convert_NMeshToMesh( Mesh * mesh, BPy_NMesh * nmesh) if( mesh->totface ) { if( nmesh->flags & NMESH_HASMCOL ) - mesh->mcol = CustomData_add_layer( &mesh->fdata, CD_MCOL, 0, NULL, - mesh->totface ); + mesh->mcol = CustomData_add_layer( &mesh->fdata, CD_MCOL, + CD_DEFAULT, NULL, mesh->totface ); - mesh->mface = CustomData_add_layer( &mesh->fdata, CD_MFACE, 0, NULL, - mesh->totface ); + mesh->mface = CustomData_add_layer( &mesh->fdata, CD_MFACE, CD_CALLOC, + NULL, mesh->totface ); } /*@ This stuff here is to tag all the vertices referenced diff --git a/source/blender/radiosity/intern/source/radpostprocess.c b/source/blender/radiosity/intern/source/radpostprocess.c index b75f94dcf0a..28fd43367d2 100644 --- a/source/blender/radiosity/intern/source/radpostprocess.c +++ b/source/blender/radiosity/intern/source/radpostprocess.c @@ -731,9 +731,9 @@ void rad_addmesh(void) me->totface= RG.totface; me->flag= 0; - me->mvert= CustomData_add_layer(&me->vdata, CD_MVERT, 0, NULL, me->totvert); - 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_add_layer(&me->vdata, CD_MVERT, CD_CALLOC, NULL, me->totvert); + CustomData_add_layer(&me->fdata, CD_MFACE, CD_CALLOC, NULL, me->totface); + CustomData_add_layer(&me->fdata, CD_MCOL, CD_CALLOC, NULL, me->totface); CustomData_merge(RG.mfdata, &me->fdata, CD_MASK_MESH, CD_CALLOC, me->totface); mesh_update_customdata_pointers(me); diff --git a/source/blender/render/intern/source/convertblender.c b/source/blender/render/intern/source/convertblender.c index a9294d46c6a..c6845754a7d 100644 --- a/source/blender/render/intern/source/convertblender.c +++ b/source/blender/render/intern/source/convertblender.c @@ -4072,7 +4072,8 @@ void RE_make_sticky(void) mvert= me->mvert; if(me->msticky) CustomData_free_layer(&me->vdata, CD_MSTICKY, me->totvert); - me->msticky= CustomData_add_layer(&me->vdata, CD_MSTICKY, 0, NULL, me->totvert); + me->msticky= CustomData_add_layer(&me->vdata, CD_MSTICKY, + CD_CALLOC, NULL, me->totvert); where_is_object(ob); Mat4MulMat4(mat, ob->obmat, re->viewmat); diff --git a/source/blender/src/booleanops.c b/source/blender/src/booleanops.c index 2b412eedb77..bbac4984231 100644 --- a/source/blender/src/booleanops.c +++ b/source/blender/src/booleanops.c @@ -339,10 +339,10 @@ static DerivedMesh *ConvertCSGDescriptorsToDerivedMesh( // create a new DerivedMesh dm = CDDM_new(vertex_it->num_elements, 0, face_it->num_elements); - CustomData_merge(&me1->fdata, &dm->faceData, CD_MASK_DERIVEDMESH, CD_DEFAULT, - face_it->num_elements); - CustomData_merge(&me2->fdata, &dm->faceData, CD_MASK_DERIVEDMESH, CD_DEFAULT, - face_it->num_elements); + CustomData_merge(&me1->fdata, &dm->faceData, CD_MASK_DERIVEDMESH, + CD_DEFAULT, face_it->num_elements); + CustomData_merge(&me2->fdata, &dm->faceData, CD_MASK_DERIVEDMESH, + CD_DEFAULT, face_it->num_elements); // step through the vertex iterators: for (i = 0; !vertex_it->Done(vertex_it->it); i++) { diff --git a/source/blender/src/buttons_editing.c b/source/blender/src/buttons_editing.c index 72b39ee0791..cb8ff245199 100644 --- a/source/blender/src/buttons_editing.c +++ b/source/blender/src/buttons_editing.c @@ -167,8 +167,9 @@ #include "butspace.h" // own module #include "multires.h" -static float editbutweight=1.0; -float editbutvweight=1; +static float editbutweight= 1.0; +float editbutvweight= 1; +static int actmcol= 0, acttface= 0; extern ListBase editNurb; @@ -670,11 +671,40 @@ void do_common_editbuts(unsigned short event) // old name, is a mix of object an /* *************************** MESH ******************************** */ +static void customdata_buttons(uiBlock *block, CustomData *data, int type, int *activep, int setevt, int newevt, int delevt, char *label, char *shortlabel, char *browsetip, char *newtip, char *deltip, int x, int y) +{ + CustomDataLayer *layer; + int i, count= 0; + + *activep = 1; + + for (i=0; i<data->totlayer; i++) { + layer= &data->layers[i]; + + if(layer->type == type) { + if(count == layer->active) + *activep = count+1; + count++; + } + } + + uiBlockBeginAlign(block); + if (count == 0) + uiDefBut(block, LABEL, 0, label, x,y,140,20, 0, 0.0, 0, 0, 0, ""); + else + uiDefButI(block, NUM, setevt, shortlabel, x,y,140,20, activep, 1, count, 0, 0, browsetip); + + uiDefBut(block, BUT, newevt, "New", x+140,y,52,20, 0,0,0,0,0, newtip); + uiDefBut(block, BUT, delevt, "Delete", x+182,y,68,20, 0,0,0,0,0, deltip); + uiBlockEndAlign(block); +} + static void editing_panel_mesh_type(Object *ob, Mesh *me) { uiBlock *block; uiBut *but; float val; + CustomData *fdata; block= uiNewBlock(&curarea->uiblocks, "editing_panel_mesh_type", UI_EMBOSS, UI_HELV, curarea->win); if( uiNewPanel(curarea, block, "Mesh", "Editing", 320, 0, 318, 204)==0) return; @@ -682,6 +712,7 @@ static void editing_panel_mesh_type(Object *ob, Mesh *me) uiBlockBeginAlign(block); uiDefButBitS(block, TOG, ME_AUTOSMOOTH, REDRAWVIEW3D, "Auto Smooth",10,180,154,19, &me->flag, 0, 0, 0, 0, "Treats all set-smoothed faces with angles less than Degr: as 'smooth' during render"); uiDefButS(block, NUM, B_DIFF, "Degr:", 10,160,154,19, &me->smoothresh, 1, 80, 0, 0, "Defines maximum angle between face normals that 'Auto Smooth' will operate on"); + uiBlockEndAlign(block); /* Retopo */ if(G.obedit) { @@ -694,36 +725,33 @@ static void editing_panel_mesh_type(Object *ob, Mesh *me) but= uiDefBut(block,BUT,B_NOP,"Retopo All", 60,110,104,19, 0,0,0,0,0, "Apply the re-topology tool to all selected vertices"); uiButSetFunc(but,retopo_do_all,ob,me); } + uiBlockEndAlign(block); } - uiBlockBeginAlign(block); uiBlockSetCol(block, TH_AUTO); - if(me->mcol) val= 1.0; else val= 0.0; - uiDefBut(block, LABEL, 0, "VertCol", 10,50,70,20, 0, val, 0, 0, 0, ""); - if(me->mcol==NULL) { - uiDefBut(block, BUT, B_MAKEVERTCOL, "Make", 80,50,84,19, 0, 0, 0, 0, 0, "Enables vertex color painting on active Mesh"); - } - else uiDefBut(block, BUT, B_DELVERTCOL, "Delete", 80,50,84,19, 0, 0, 0, 0, 0, "Deletes vertex colors on active Mesh"); + uiDefIDPoinBut(block, test_meshpoin_but, ID_ME, B_REDR, "TexMesh: ", 180,180,230,19, &me->texcomesh, "Derive texture coordinates from another mesh."); - if(me->mtface) val= 1.0; else val= 0.0; - uiDefBut(block, LABEL, 0, "TexFace", 10,30,70,20, 0, val, 0, 0, 0, ""); - if(me->mtface==NULL) { - uiDefBut(block, BUT, B_MAKE_TFACES, "Make", 80,30,84,19, 0, 0, 0, 0, 0, "Enables the active Mesh's faces for UV coordinate mapping"); - } - else uiDefBut(block, BUT, B_DEL_TFACES, "Delete", 80,30,84,19, 0, 0, 0, 0, 0, "Deletes UV coordinates for active Mesh's faces"); + fdata= (G.obedit)? &G.editMesh->fdata: &me->fdata; + customdata_buttons(block, fdata, CD_MCOL, &actmcol, B_SETMCOL, + B_NEWMCOL, B_DELMCOL, "Vert Color", "Vert Color:", + "Sets active vertex color layer", "Creates a new vertex color layer", + "Removes the current vertex color layer", 10, 60); + + customdata_buttons(block, fdata, CD_MTFACE, &acttface, B_SETTFACE, + B_NEWTFACE, B_DELTFACE, "UV Texture", "UV Texture:", + "Set active UV texture", "Creates a new UV texture layer", + "Removes the current UV texture layer", 10, 35); + uiBlockBeginAlign(block); if(me->msticky) val= 1.0; else val= 0.0; - uiDefBut(block, LABEL, 0, "Sticky", 10,10,70,20, 0, val, 0, 0, 0, ""); + uiDefBut(block, LABEL, 0, "Sticky", 10,10,140,20, 0, val, 0, 0, 0, ""); if(me->msticky==NULL) { - uiDefBut(block, BUT, B_MAKESTICKY, "Make", 80,10,84,19, 0, 0, 0, 0, 0, "Creates Sticky coordinates for the active Mesh from the current camera view background picture"); + uiDefBut(block, BUT, B_MAKESTICKY, "Make", 150,10,110,20, 0, 0, 0, 0, 0, "Creates Sticky coordinates from the current camera view background picture"); } - else uiDefBut(block, BUT, B_DELSTICKY, "Delete", 80,10,84,19, 0, 0, 0, 0, 0, "Deletes Sticky texture coordinates"); - + else uiDefBut(block, BUT, B_DELSTICKY, "Delete", 150,10,110,20, 0, 0, 0, 0, 0, "Deletes Sticky texture coordinates"); uiBlockEndAlign(block); - uiDefIDPoinBut(block, test_meshpoin_but, ID_ME, B_REDR, "TexMesh: ", 175,124,230,19, &me->texcomesh, "Derive texture coordinates from another mesh."); - uiBlockBeginAlign(block); uiDefBut(block, BUT,B_DOCENTRE, "Centre", 275, 95, 130, 19, 0, 0, 0, 0, 0, "Shifts object data to be centered about object's origin"); uiDefBut(block, BUT,B_DOCENTRENEW, "Centre New", 275, 75, 130, 19, 0, 0, 0, 0, 0, "Shifts object's origin to center of object data"); @@ -733,7 +761,6 @@ static void editing_panel_mesh_type(Object *ob, Mesh *me) uiDefButBitS(block, TOG, ME_TWOSIDED, REDRAWVIEW3D, "Double Sided", 275,30,130,19, &me->flag, 0, 0, 0, 0, "Render/display the mesh as double or single sided"); uiDefButBitS(block, TOG, ME_NOPUNOFLIP, REDRAWVIEW3D, "No V.Normal Flip",275,10,130,19, &me->flag, 0, 0, 0, 0, "Disables flipping of vertexnormals during render"); uiBlockEndAlign(block); - } /* *************************** MODIFIERS ******************************** */ @@ -3551,8 +3578,11 @@ void do_meshbuts(unsigned short event) { Object *ob; Mesh *me; + MCol *mcol; + EditMesh *em= G.editMesh; float fac; int count; /* store num of changes made to see if redraw & undo are needed*/ + int layernum; short randfac; ob= OBACT; @@ -3573,50 +3603,113 @@ void do_meshbuts(unsigned short event) RE_make_sticky(); allqueue(REDRAWBUTSEDIT, 0); break; - - case B_MAKEVERTCOL: - if(G.obedit) - EM_add_data_layer(&G.editMesh->fdata, CD_MCOL); - else - make_vertexcol(1); + + case B_NEWMCOL: + if(G.obedit) { + layernum= CustomData_number_of_layers(&em->fdata, CD_MCOL); + EM_add_data_layer(&em->fdata, CD_MCOL); + CustomData_set_layer_active(&em->fdata, CD_MCOL, layernum); + } + else if(me) { + mcol= me->mcol; + layernum= CustomData_number_of_layers(&me->fdata, CD_MCOL); + + if(mcol) + CustomData_add_layer(&me->fdata, CD_MCOL, CD_DUPLICATE, + mcol, me->totface); + else + CustomData_add_layer(&me->fdata, CD_MCOL, CD_CALLOC, + NULL, me->totface); + + CustomData_set_layer_active(&me->fdata, CD_MCOL, layernum); + mesh_update_customdata_pointers(me); + + if(!mcol) + shadeMeshMCol(ob, me); + } + DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA); + allqueue(REDRAWVIEW3D, 0); + allqueue(REDRAWBUTSEDIT, 0); break; - case B_DELVERTCOL: + case B_DELMCOL: if(G.obedit) { - EM_free_data_layer(&G.editMesh->fdata, CD_MCOL); + EM_free_data_layer(&em->fdata, CD_MCOL); } - else { + else if(me) { CustomData_free_layer(&me->fdata, CD_MCOL, me->totface); - me->mcol= NULL; + me->mcol= CustomData_get_layer(&me->fdata, CD_MCOL); } - G.f &= ~G_VERTEXPAINT; + + if((me && me->mcol == NULL) && (G.f & G_VERTEXPAINT)) + G.f &= ~G_VERTEXPAINT; /* get out of vertexpaint mode */ + DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA); - allqueue(REDRAWBUTSEDIT, 0); allqueue(REDRAWVIEW3D, 0); + allqueue(REDRAWBUTSEDIT, 0); break; + case B_SETMCOL: + if (G.obedit || me) { + CustomData *fdata= (G.obedit)? &em->fdata: &me->fdata; + CustomData_set_layer_active(fdata, CD_MCOL, actmcol-1); + mesh_update_customdata_pointers(me); + + DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA); + allqueue(REDRAWVIEW3D, 0); + allqueue(REDRAWBUTSEDIT, 0); + } + break; + + case B_NEWTFACE: + if(G.obedit) { + layernum= CustomData_number_of_layers(&em->fdata, CD_MTFACE); + EM_add_data_layer(&em->fdata, CD_MTFACE); + CustomData_set_layer_active(&em->fdata, CD_MTFACE, layernum); + } + else if(me) { + layernum= CustomData_number_of_layers(&me->fdata, CD_MTFACE); + + if(me->mtface) + CustomData_add_layer(&me->fdata, CD_MTFACE, CD_DUPLICATE, + me->mtface, me->totface); + else + CustomData_add_layer(&me->fdata, CD_MTFACE, CD_DEFAULT, + NULL, me->totface); + + CustomData_set_layer_active(&me->fdata, CD_MTFACE, layernum); + mesh_update_customdata_pointers(me); + } - case B_MAKE_TFACES: - if(G.obedit) - EM_add_data_layer(&G.editMesh->fdata, CD_MTFACE); - else - make_tfaces(me); DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA); + allqueue(REDRAWVIEW3D, 0); allqueue(REDRAWBUTSEDIT, 0); break; - - case B_DEL_TFACES: + case B_DELTFACE: if(G.obedit) { - EM_free_data_layer(&G.editMesh->fdata, CD_MTFACE); + EM_free_data_layer(&em->fdata, CD_MTFACE); } - else { + else if(me) { CustomData_free_layer(&me->fdata, CD_MTFACE, me->totface); - me->mtface= NULL; + me->mtface= CustomData_get_layer(&me->fdata, CD_MTFACE); } - G.f &= ~G_FACESELECT; + + if((me && me->mtface == NULL) && (G.f & G_FACESELECT)) + set_faceselect(); /* get out of vertexpaint mode */ + DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA); - allqueue(REDRAWBUTSEDIT, 0); allqueue(REDRAWVIEW3D, 0); - allqueue(REDRAWIMAGE, 0); + allqueue(REDRAWBUTSEDIT, 0); + break; + case B_SETTFACE: + if (G.obedit || me) { + CustomData *fdata= (G.obedit)? &em->fdata: &me->fdata; + CustomData_set_layer_active(fdata, CD_MTFACE, acttface-1); + mesh_update_customdata_pointers(me); + + DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA); + allqueue(REDRAWVIEW3D, 0); + allqueue(REDRAWBUTSEDIT, 0); + } break; case B_FLIPNORM: diff --git a/source/blender/src/editdeform.c b/source/blender/src/editdeform.c index 37055bbe0fd..4df058995bc 100644 --- a/source/blender/src/editdeform.c +++ b/source/blender/src/editdeform.c @@ -267,7 +267,7 @@ void create_dverts(ID *id) if( GS(id->name)==ID_ME) { Mesh *me= (Mesh *)id; - me->dvert= CustomData_add_layer(&me->vdata, CD_MDEFORMVERT, 0, NULL, me->totvert); + me->dvert= CustomData_add_layer(&me->vdata, CD_MDEFORMVERT, CD_CALLOC, NULL, me->totvert); } else if( GS(id->name)==ID_LT) { Lattice *lt= (Lattice *)id; diff --git a/source/blender/src/editface.c b/source/blender/src/editface.c index e0d5a403568..f118c14bf25 100644 --- a/source/blender/src/editface.c +++ b/source/blender/src/editface.c @@ -74,6 +74,7 @@ #include "BIF_interface.h" #include "BIF_mywindow.h" #include "BIF_toolbox.h" +#include "BIF_resources.h" #include "BIF_screen.h" #include "BIF_gl.h" #include "BIF_graphics.h" @@ -607,33 +608,13 @@ void default_uv(float uv[][2], float size) uv[3][1]= size+dy; } -void default_tface(MTFace *tface) -{ - default_uv(tface->uv, 1.0); - - tface->mode= TF_TEX; - tface->mode= 0; - tface->flag= TF_SELECT; - tface->tpage= 0; - tface->mode |= TF_DYNAMIC; -} - void make_tfaces(Mesh *me) { - MTFace *tf; - int a; - - if(me->mtface) - return; - - me->mtface= CustomData_add_layer(&me->fdata, CD_MTFACE, 0, 0, me->totface); - - tf= me->mtface; - for (a=0; a<me->totface; a++, tf++) - default_tface(tf); + if(!me->mtface) + me->mtface= CustomData_add_layer(&me->fdata, CD_MTFACE, CD_DEFAULT, + NULL, me->totface); } - void reveal_tface() { Mesh *me; @@ -1547,7 +1528,7 @@ static int texpaint_projected_verts(Object *ob, MFace *mf, MTFace *tf, MVert *mv persp(PERSP_VIEW); - /* get the need opengl matrices */ + /* get the needed opengl matrices */ glGetIntegerv(GL_VIEWPORT, view); glGetDoublev(GL_MODELVIEW_MATRIX, model); glGetDoublev(GL_PROJECTION_MATRIX, proj); diff --git a/source/blender/src/editmesh.c b/source/blender/src/editmesh.c index c962bc0f889..b4f1bddc716 100644 --- a/source/blender/src/editmesh.c +++ b/source/blender/src/editmesh.c @@ -1004,9 +1004,8 @@ void load_editMesh(void) oldverts= me->mvert; ototvert= me->totvert; - for (i=0; i<me->vdata.totlayer; i++) - if (me->vdata.layers[i].type == CD_MVERT) - me->vdata.layers[i].flag |= CD_FLAG_NOFREE; + /* don't free this yet */ + CustomData_set_layer(&me->vdata, CD_MVERT, NULL); /* free custom data */ CustomData_free(&me->vdata, me->totvert); @@ -1021,10 +1020,9 @@ void load_editMesh(void) CustomData_copy(&em->vdata, &me->vdata, CD_MASK_MESH, CD_CALLOC, me->totvert); CustomData_copy(&em->fdata, &me->fdata, CD_MASK_MESH, CD_CALLOC, me->totface); - me->mvert= CustomData_add_layer(&me->vdata, CD_MVERT, 0, mvert, me->totvert); - me->medge= CustomData_add_layer(&me->edata, CD_MEDGE, 0, medge, me->totedge); - me->mface= CustomData_add_layer(&me->fdata, CD_MFACE, 0, mface, me->totface); - + CustomData_add_layer(&me->vdata, CD_MVERT, CD_ASSIGN, mvert, me->totvert); + CustomData_add_layer(&me->edata, CD_MEDGE, CD_ASSIGN, medge, me->totedge); + CustomData_add_layer(&me->fdata, CD_MFACE, CD_ASSIGN, mface, me->totface); mesh_update_customdata_pointers(me); /* the vertices, use ->tmp.l as counter */ @@ -1095,7 +1093,7 @@ void load_editMesh(void) mface->v2= (unsigned int) efa->v2->tmp.l; mface->v3= (unsigned int) efa->v3->tmp.l; if (efa->v4) mface->v4 = (unsigned int) efa->v4->tmp.l; - + mface->mat_nr= efa->mat_nr; mface->flag= efa->flag; @@ -1331,7 +1329,7 @@ void load_editMesh(void) } } } - + mesh_calc_normals(me->mvert, me->totvert, me->mface, me->totface, NULL); } diff --git a/source/blender/src/editmesh_lib.c b/source/blender/src/editmesh_lib.c index 6e9fc7260f6..5732b30b664 100644 --- a/source/blender/src/editmesh_lib.c +++ b/source/blender/src/editmesh_lib.c @@ -775,6 +775,7 @@ static void update_data_blocks(CustomData *olddata, CustomData *data) if (data == &G.editMesh->vdata) { for(eve= em->verts.first; eve; eve= eve->next) { block = NULL; + CustomData_em_set_default(data, &block); CustomData_em_copy_data(olddata, data, eve->data, &block); CustomData_em_free_block(olddata, &eve->data); eve->data= block; @@ -783,6 +784,7 @@ static void update_data_blocks(CustomData *olddata, CustomData *data) else if (data == &G.editMesh->fdata) { for(efa= em->faces.first; efa; efa= efa->next) { block = NULL; + CustomData_em_set_default(data, &block); CustomData_em_copy_data(olddata, data, efa->data, &block); CustomData_em_free_block(olddata, &efa->data); efa->data= block; @@ -794,12 +796,9 @@ void EM_add_data_layer(CustomData *data, int type) { CustomData olddata; - if (CustomData_has_layer(data, type)) - return; - olddata= *data; olddata.layers= (olddata.layers)? MEM_dupallocN(olddata.layers): NULL; - CustomData_add_layer(data, type, 0, NULL, 0); + CustomData_add_layer(data, type, CD_CALLOC, NULL, 0); update_data_blocks(&olddata, data); if (olddata.layers) MEM_freeN(olddata.layers); @@ -809,9 +808,6 @@ void EM_free_data_layer(CustomData *data, int type) { CustomData olddata; - if (!CustomData_has_layer(data, type)) - return; - olddata= *data; olddata.layers= (olddata.layers)? MEM_dupallocN(olddata.layers): NULL; CustomData_free_layer(data, type, 0); diff --git a/source/blender/src/filesel.c b/source/blender/src/filesel.c index 815c9f8ebbd..bcee676ae90 100644 --- a/source/blender/src/filesel.c +++ b/source/blender/src/filesel.c @@ -1759,19 +1759,20 @@ static void replace_image(ID *oldblock, ID *newblock) { } for (me= G.main->mesh.first; me; me= me->id.next) { - MTFace *tfaces= me->mtface; - - if (tfaces) { - int i; - - for (i=0; i<me->totface; i++) { - MTFace *tf= &tfaces[i]; - - if (tf->tpage == oldima) { - /* not change_id_link, tpage's aren't owners :( - * see hack below. - */ - tf->tpage= newima; + int i, a; + MTFace *tface; + + for(i=0; i<me->fdata.totlayer; i++) { + if(me->fdata.layers[i].type == CD_MTFACE) { + tface= (MTFace*)me->fdata.layers[i].data; + + for (a=0; a<me->totface; a++, tface++) { + if (tface->tpage == oldima) { + /* not change_id_link, tpage's aren't owners :( + * see hack below. + */ + tface->tpage= newima; + } } } } diff --git a/source/blender/src/meshtools.c b/source/blender/src/meshtools.c index 7d07b3f89d5..1a97a3d594f 100644 --- a/source/blender/src/meshtools.c +++ b/source/blender/src/meshtools.c @@ -255,14 +255,17 @@ int join_mesh(void) memset(&edata, 0, sizeof(edata)); memset(&fdata, 0, sizeof(fdata)); - mvertmain= mvert= CustomData_add_layer(&vdata, CD_MVERT, 0, NULL, totvert); - medgemain= medge= CustomData_add_layer(&edata, CD_MEDGE, 0, NULL, totedge); - mfacemain= mface= CustomData_add_layer(&fdata, CD_MFACE, 0, NULL, totface); + mvert= CustomData_add_layer(&vdata, CD_MVERT, CD_CALLOC, NULL, totvert); + medge= CustomData_add_layer(&edata, CD_MEDGE, CD_CALLOC, NULL, totedge); + mface= CustomData_add_layer(&fdata, CD_MFACE, CD_CALLOC, NULL, totface); + mvertmain= mvert; + medgemain= medge; + mfacemain= mface; /* inverse transorm all selected meshes in this object */ Mat4Invert(imat, ob->obmat); - + vertofs= 0; edgeofs= 0; faceofs= 0; diff --git a/source/blender/src/multires.c b/source/blender/src/multires.c index b0fa53e40fc..f8b4572aebc 100644 --- a/source/blender/src/multires.c +++ b/source/blender/src/multires.c @@ -565,7 +565,7 @@ void multires_update_deformverts(Multires *mr, CustomData *src) CustomData_free(&mr->vdata, lvl->totvert); - if(CustomData_has_layer(src, CD_MDEFORMVERT)) { + if(CustomData_has_layer(src, CD_MDEFORMVERT)) { if(G.obedit) { EditVert *eve= G.editMesh->verts.first; CustomData_add_layer(&mr->vdata, CD_MDEFORMVERT, 0, NULL, lvl->totvert); @@ -1054,17 +1054,17 @@ void multires_level_to_mesh(Object *ob, Mesh *me) 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); + CustomData_free_layers(&me->fdata, CD_MTFACE, me->totface); + CustomData_free_layers(&me->fdata, CD_MCOL, me->totface); me->totvert= lvl->totvert; me->totface= lvl->totface; me->totedge= lvl->totedge; - 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); + CustomData_add_layer(&me->vdata, CD_MVERT, CD_CALLOC, NULL, me->totvert); + CustomData_add_layer(&me->edata, CD_MEDGE, CD_CALLOC, NULL, me->totedge); + CustomData_add_layer(&me->fdata, CD_MFACE, CD_CALLOC, NULL, me->totface); + mesh_update_customdata_pointers(me); } /* Vertices/Edges/Faces */ @@ -1184,8 +1184,8 @@ void multires_level_to_mesh(Object *ob, Mesh *me) efa= em->faces.first; } else { - if(me->mr->use_col) me->mcol= CustomData_add_layer(src, CD_MCOL, 0, NULL, me->totface); - if(me->mr->use_tex) me->mtface= CustomData_add_layer(src, CD_MTFACE, 0, NULL, me->totface); + if(me->mr->use_col) me->mcol= CustomData_add_layer(src, CD_MCOL, CD_CALLOC, NULL, me->totface); + if(me->mr->use_tex) me->mtface= CustomData_add_layer(src, CD_MTFACE, CD_CALLOC, NULL, me->totface); } for(i=0; i<lvl->totface; ++i) { diff --git a/source/blender/src/sculptmode.c b/source/blender/src/sculptmode.c index 6d2e96a1243..f6ea27a5ab8 100644 --- a/source/blender/src/sculptmode.c +++ b/source/blender/src/sculptmode.c @@ -379,7 +379,7 @@ void sculptmode_undo_update(SculptUndoStep *newcur) if(newcur->verts) { CustomData_free_layer(&me->vdata, CD_MVERT, me->totvert); me->mvert= MEM_dupallocN(newcur->verts); - CustomData_add_layer(&me->vdata, CD_MVERT, 0, me->mvert, newcur->totvert); + CustomData_add_layer(&me->vdata, CD_MVERT, CD_ASSIGN, me->mvert, newcur->totvert); } /* Check if faces/edges have been modified between oldcur and newcur */ @@ -405,8 +405,8 @@ void sculptmode_undo_update(SculptUndoStep *newcur) me->medge= MEM_dupallocN(sus->edges); me->mface= MEM_dupallocN(sus->faces); - CustomData_add_layer(&me->edata, CD_MEDGE, 0, me->medge, sus->totedge); - CustomData_add_layer(&me->fdata, CD_MFACE, 0, me->mface, sus->totface); + CustomData_add_layer(&me->edata, CD_MEDGE, CD_ASSIGN, me->medge, sus->totedge); + CustomData_add_layer(&me->fdata, CD_MFACE, CD_ASSIGN, me->mface, sus->totface); me->totvert= sus->totvert; me->totedge= sus->totedge; @@ -1799,9 +1799,10 @@ void sculptmode_revert_pmv(Mesh *me) CustomData_free_layer(&me->edata, CD_MEDGE, me->totedge); CustomData_free_layer(&me->fdata, CD_MFACE, me->totface); - me->mvert= CustomData_add_layer(&me->vdata, CD_MVERT, 0, old_verts, me->pv->totvert); - me->medge= CustomData_add_layer(&me->edata, CD_MEDGE, 0, me->pv->old_edges, me->pv->totedge); - me->mface= CustomData_add_layer(&me->fdata, CD_MFACE, 0, me->pv->old_faces, me->pv->totface); + CustomData_add_layer(&me->vdata, CD_MVERT, CD_ASSIGN, old_verts, me->pv->totvert); + CustomData_add_layer(&me->edata, CD_MEDGE, CD_ASSIGN, me->pv->old_edges, me->pv->totedge); + CustomData_add_layer(&me->fdata, CD_MFACE, CD_ASSIGN, me->pv->old_faces, me->pv->totface); + mesh_update_customdata_pointers(me); me->totvert= me->pv->totvert; me->totedge= me->pv->totedge; @@ -1933,7 +1934,7 @@ void sculptmode_do_pmv(Object *ob, rcti *hb_2d, int mode) } } CustomData_free_layer(&me->vdata, CD_MVERT, me->pv->totvert); - me->mvert= CustomData_add_layer(&me->vdata, CD_MVERT, 0, nve, me->totvert); + me->mvert= CustomData_add_layer(&me->vdata, CD_MVERT, CD_ASSIGN, nve, me->totvert); /* Create new face array */ me->pv->old_faces= me->mface; diff --git a/source/blender/src/verse_mesh.c b/source/blender/src/verse_mesh.c index 8a752150540..b28585bf204 100644 --- a/source/blender/src/verse_mesh.c +++ b/source/blender/src/verse_mesh.c @@ -1429,8 +1429,12 @@ void create_meshdata_from_geom_node(Mesh *me, VNode *vnode) me->totface = face_vlayer->dl.da.count; me->totselect = 0; - mvert = me->mvert = CustomData_add_layer(&me->vdata, CD_MVERT, 0, NULL, me->totvert); - mface = me->mface = CustomData_add_layer(&me->fdata, CD_MFACE, 0, NULL, me->totface); + CustomData_add_layer(&me->vdata, CD_MVERT, CD_CALLOC, NULL, me->totvert); + CustomData_add_layer(&me->fdata, CD_MFACE, CD_CALLOC, NULL, me->totface); + mesh_update_customdata_pointers(me); + + mvert = me->mvert; + mface = me->mface; index = 0; vvert = vert_vlayer->dl.lb.first; @@ -1484,7 +1488,7 @@ void create_meshdata_from_geom_node(Mesh *me, VNode *vnode) if(me->totedge) { EdgeHashIterator *i; - MEdge *medge = me->medge = CustomData_add_layer(&me->edata, CD_MEDGE, 0, NULL, me->totedge); + MEdge *medge = me->medge = CustomData_add_layer(&me->edata, CD_MEDGE, CD_CALLOC, NULL, me->totedge); for(i = BLI_edgehashIterator_new(edges); !BLI_edgehashIterator_isDone(i); BLI_edgehashIterator_step(i), ++medge) { BLI_edgehashIterator_getKey(i, (int*)&medge->v1, (int*)&medge->v2); diff --git a/source/blender/src/vpaint.c b/source/blender/src/vpaint.c index 6ee817aeb5f..95d4ae4dd55 100644 --- a/source/blender/src/vpaint.c +++ b/source/blender/src/vpaint.c @@ -239,8 +239,10 @@ void make_vertexcol(int shade) /* single ob */ if(me==0) return; /* copies from shadedisplist to mcol */ - if(me->mcol == NULL) - me->mcol = CustomData_add_layer(&me->fdata, CD_MCOL, 0, NULL, me->totface); + if(!me->mcol) { + CustomData_add_layer(&me->fdata, CD_MCOL, CD_CALLOC, NULL, me->totface); + mesh_update_customdata_pointers(me); + } if(shade) shadeMeshMCol(ob, me); |