[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [34007] trunk/blender/source/blender: New customdata layer callback: validate
Sergey Sharybin
g.ulairi at gmail.com
Sun Jan 2 18:08:25 CET 2011
Revision: 34007
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=34007
Author: nazgul
Date: 2011-01-02 18:08:25 +0100 (Sun, 02 Jan 2011)
Log Message:
-----------
New customdata layer callback: validate
Used to validate displacement allocation size after face copying
to match face vertex and displacement corners count.
Modified Paths:
--------------
trunk/blender/source/blender/blenkernel/BKE_customdata.h
trunk/blender/source/blender/blenkernel/intern/customdata.c
trunk/blender/source/blender/editors/mesh/editmesh.c
Modified: trunk/blender/source/blender/blenkernel/BKE_customdata.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_customdata.h 2011-01-02 16:43:28 UTC (rev 34006)
+++ trunk/blender/source/blender/blenkernel/BKE_customdata.h 2011-01-02 17:08:25 UTC (rev 34007)
@@ -144,6 +144,7 @@
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
Modified: trunk/blender/source/blender/blenkernel/intern/customdata.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/customdata.c 2011-01-02 16:43:28 UTC (rev 34006)
+++ trunk/blender/source/blender/blenkernel/intern/customdata.c 2011-01-02 17:08:25 UTC (rev 34007)
@@ -104,6 +104,11 @@
/* 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 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 @@
{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_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;
Modified: trunk/blender/source/blender/editors/mesh/editmesh.c
===================================================================
--- trunk/blender/source/blender/editors/mesh/editmesh.c 2011-01-02 16:43:28 UTC (rev 34006)
+++ trunk/blender/source/blender/editors/mesh/editmesh.c 2011-01-02 17:08:25 UTC (rev 34007)
@@ -380,6 +380,7 @@
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;
More information about the Bf-blender-cvs
mailing list