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

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorSergey Sharybin <sergey.vfx@gmail.com>2011-01-02 20:08:25 +0300
committerSergey Sharybin <sergey.vfx@gmail.com>2011-01-02 20:08:25 +0300
commit24e80665d8272198783cd6a634cb47a7d289fb1c (patch)
treed7a22936a1514c849e7415ac0e6a6cff1025497c /source
parent76f0569a862aa56c99cd25977fa2c2061de2a117 (diff)
New customdata layer callback: validate
Used to validate displacement allocation size after face copying to match face vertex and displacement corners count.
Diffstat (limited to 'source')
-rw-r--r--source/blender/blenkernel/BKE_customdata.h1
-rw-r--r--source/blender/blenkernel/intern/customdata.c34
-rw-r--r--source/blender/editors/mesh/editmesh.c1
-rw-r--r--source/blender/editors/mesh/editmesh_tools.c1
4 files changed, 36 insertions, 1 deletions
diff --git a/source/blender/blenkernel/BKE_customdata.h b/source/blender/blenkernel/BKE_customdata.h
index fb079d44bb5..e9118323682 100644
--- a/source/blender/blenkernel/BKE_customdata.h
+++ b/source/blender/blenkernel/BKE_customdata.h
@@ -144,6 +144,7 @@ void CustomData_em_copy_data(const struct CustomData *source,
void CustomData_bmesh_copy_data(const struct CustomData *source,
struct CustomData *dest,void *src_block,
void **dest_block);
+void CustomData_em_validate_data(struct CustomData *data, void *block, int sub_elements);
/* frees data in a CustomData object
* return 1 on success, 0 on failure
diff --git a/source/blender/blenkernel/intern/customdata.c b/source/blender/blenkernel/intern/customdata.c
index ee3477585f8..2d4e65f8f94 100644
--- a/source/blender/blenkernel/intern/customdata.c
+++ b/source/blender/blenkernel/intern/customdata.c
@@ -104,6 +104,11 @@ typedef struct LayerTypeInfo {
/* a function to determine file size */
size_t (*filesize)(CDataFile *cdf, void *data, int count);
+
+ /* a function to validate layer contents depending on
+ * sub-elements count
+ */
+ void (*validate)(void *source, int sub_elements);
} LayerTypeInfo;
static void layerCopy_mdeformvert(const void *source, void *dest,
@@ -517,6 +522,20 @@ static void layerCopy_mdisps(const void *source, void *dest, int count)
}
}
+static void layerValidate_mdisps(void *data, int sub_elements)
+{
+ MDisps *disps = data;
+ if(disps->disps) {
+ int corners = multires_mdisp_corners(disps);
+
+ if(corners != sub_elements) {
+ MEM_freeN(disps->disps);
+ disps->totdisp = disps->totdisp / corners * sub_elements;
+ disps->disps = MEM_callocN(3*disps->totdisp*sizeof(float), "layerValidate_mdisps");
+ }
+ }
+}
+
static void layerFree_mdisps(void *data, int count, int UNUSED(size))
{
int i;
@@ -768,7 +787,8 @@ const LayerTypeInfo LAYERTYPEINFO[CD_NUMTYPES] = {
{sizeof(MLoopCol), "MLoopCol", 1, "Col", NULL, NULL, layerInterp_mloopcol, NULL, layerDefault_mloopcol},
{sizeof(float)*3*4, "", 0, NULL, NULL, NULL, NULL, NULL, NULL},
{sizeof(MDisps), "MDisps", 1, NULL, layerCopy_mdisps,
- layerFree_mdisps, layerInterp_mdisps, layerSwap_mdisps, NULL, layerRead_mdisps, layerWrite_mdisps, layerFilesize_mdisps},
+ layerFree_mdisps, layerInterp_mdisps, layerSwap_mdisps, NULL, layerRead_mdisps, layerWrite_mdisps,
+ layerFilesize_mdisps, layerValidate_mdisps},
{sizeof(MCol)*4, "MCol", 4, "WeightCol", NULL, NULL, layerInterp_mcol,
layerSwap_mcol, layerDefault_mcol},
{sizeof(MCol)*4, "MCol", 4, "IDCol", NULL, NULL, layerInterp_mcol,
@@ -1691,6 +1711,18 @@ void CustomData_em_copy_data(const CustomData *source, CustomData *dest,
}
}
+void CustomData_em_validate_data(CustomData *data, void *block, int sub_elements)
+{
+ int i;
+ for(i = 0; i < data->totlayer; i++) {
+ const LayerTypeInfo *typeInfo = layerType_getInfo(data->layers[i].type);
+ char *leayer_data = (char*)block + data->layers[i].offset;
+
+ if(typeInfo->validate)
+ typeInfo->validate(leayer_data, sub_elements);
+ }
+}
+
void *CustomData_em_get(const CustomData *data, void *block, int type)
{
int layer_index;
diff --git a/source/blender/editors/mesh/editmesh.c b/source/blender/editors/mesh/editmesh.c
index 2a66e95bc77..5f7ccd1441b 100644
--- a/source/blender/editors/mesh/editmesh.c
+++ b/source/blender/editors/mesh/editmesh.c
@@ -380,6 +380,7 @@ EditFace *addfacelist(EditMesh *em, EditVert *v1, EditVert *v2, EditVert *v3, Ed
efa->mat_nr= example->mat_nr;
efa->flag= example->flag;
CustomData_em_copy_data(&em->fdata, &em->fdata, example->data, &efa->data);
+ CustomData_em_validate_data(&em->fdata, efa->data, efa->v4 ? 4 : 3);
}
else {
efa->mat_nr= em->mat_nr;
diff --git a/source/blender/editors/mesh/editmesh_tools.c b/source/blender/editors/mesh/editmesh_tools.c
index 7c3262f3747..d00b5ac6070 100644
--- a/source/blender/editors/mesh/editmesh_tools.c
+++ b/source/blender/editors/mesh/editmesh_tools.c
@@ -1519,6 +1519,7 @@ static void facecopy(EditMesh *em, EditFace *source, EditFace *target)
if (target->v4)
interp_weights_face_v3( w[3],v1, v2, v3, v4, target->v4->co);
+ CustomData_em_validate_data(&em->fdata, target->data, target->v4 ? 4 : 3);
CustomData_em_interp(&em->fdata, &source->data, NULL, (float*)w, 1, target->data);
}