svn merge ^/trunk/blender -r48749:48754
[blender.git] / source / blender / blenkernel / intern / customdata.c
index 90a3e61747730d38d6bcd0bb26c88ca1e3182f60..8dd3b3da705e5d108695876ba2623fe21716d7f8 100644 (file)
@@ -337,12 +337,12 @@ static void layerSwap_tface(void *data, const int *corner_indices)
 
                copy_v2_v2(uv[j], tf->uv[source_index]);
 
-               // swap pinning flags around
+               /* swap pinning flags around */
                if (tf->unwrap & pin_flags[source_index]) {
                        unwrap |= pin_flags[j];
                }
 
-               // swap selection flags around
+               /* swap selection flags around */
                if (tf->flag & sel_flags[source_index]) {
                        flag |= sel_flags[j];
                }
@@ -992,6 +992,38 @@ static void layerInterp_shapekey(void **sources, float *weights,
        }
 }
 
+static void layerDefault_mvert_skin(void *data, int count)
+{
+       MVertSkin *vs = data;
+       int i;
+       
+       for (i = 0; i < count; i++) {
+               copy_v3_fl(vs[i].radius, 0.25f);
+               vs[i].flag = 0;
+       }
+}
+
+static void layerInterp_mvert_skin(void **sources, float *weights,
+                                   float *UNUSED(sub_weights),
+                                   int count, void *dest)
+{
+       float radius[3], w;
+       MVertSkin *vs;
+       int i;
+
+       zero_v3(radius);
+       for (i = 0; i < count; i++) {
+               w = weights ? weights[i] : 1.0f;
+               vs = sources[i];
+
+               madd_v3_v3fl(radius, vs->radius, w);
+       }
+
+       vs = dest;
+       copy_v3_v3(vs->radius, radius);
+       vs->flag &= ~MVERT_SKIN_ROOT;
+}
+
 static const LayerTypeInfo LAYERTYPEINFO[CD_NUMTYPES] = {
        /* 0: CD_MVERT */
        {sizeof(MVert), "MVert", 1, NULL, NULL, NULL, NULL, NULL, NULL},
@@ -1093,7 +1125,10 @@ static const LayerTypeInfo LAYERTYPEINFO[CD_NUMTYPES] = {
        {sizeof(float), "", 0, NULL, NULL, NULL, NULL, NULL, NULL},
        /* 35: CD_GRID_PAINT_MASK */
        {sizeof(GridPaintMask), "GridPaintMask", 1, NULL, layerCopy_grid_paint_mask,
-        layerFree_grid_paint_mask, NULL, NULL, NULL}
+        layerFree_grid_paint_mask, NULL, NULL, NULL},
+       /* 36: CD_SKIN_NODE */
+       {sizeof(MVertSkin), "MVertSkin", 1, "Skin", NULL, NULL,
+        layerInterp_mvert_skin, NULL, layerDefault_mvert_skin}
 };
 
 /* note, numbers are from trunk and need updating for bmesh */
@@ -1108,10 +1143,7 @@ static const char *LAYERTYPENAMES[CD_NUMTYPES] = {
 /* BMESH ONLY */
        /* 25-29 */ "CDMPoly", "CDMLoop", "CDShapeKeyIndex", "CDShapeKey", "CDBevelWeight",
        /* 30-34 */ "CDSubSurfCrease", "CDOrigSpaceLoop", "CDPreviewLoopCol", "CDBMElemPyPtr", "CDPaintMask",
-       /*    35 */ "CDGridPaintMask"
-
-/* END BMESH ONLY */
-
+       /* 35-36 */ "CDGridPaintMask", "CDMVertSkin"
 };
 
 
@@ -1123,26 +1155,26 @@ const CustomDataMask CD_MASK_MESH =
     CD_MASK_PROP_FLT | CD_MASK_PROP_INT | CD_MASK_PROP_STR | CD_MASK_MDISPS |
     CD_MASK_MLOOPUV | CD_MASK_MLOOPCOL | CD_MASK_MPOLY | CD_MASK_MLOOP |
     CD_MASK_MTEXPOLY | CD_MASK_NORMAL | CD_MASK_RECAST | CD_MASK_PAINT_MASK |
-    CD_MASK_GRID_PAINT_MASK;
+    CD_MASK_GRID_PAINT_MASK | CD_MASK_MVERT_SKIN;
 const CustomDataMask CD_MASK_EDITMESH =
     CD_MASK_MSTICKY | CD_MASK_MDEFORMVERT | CD_MASK_MTFACE | CD_MASK_MLOOPUV |
     CD_MASK_MLOOPCOL | CD_MASK_MTEXPOLY | CD_MASK_SHAPE_KEYINDEX |
     CD_MASK_MCOL | CD_MASK_PROP_FLT | CD_MASK_PROP_INT | CD_MASK_PROP_STR |
     CD_MASK_MDISPS | CD_MASK_SHAPEKEY | CD_MASK_RECAST | CD_MASK_PAINT_MASK |
-    CD_MASK_GRID_PAINT_MASK;
+    CD_MASK_GRID_PAINT_MASK | CD_MASK_MVERT_SKIN;
 const CustomDataMask CD_MASK_DERIVEDMESH =
     CD_MASK_MSTICKY | CD_MASK_MDEFORMVERT | CD_MASK_MTFACE |
     CD_MASK_MCOL | CD_MASK_PROP_FLT | CD_MASK_PROP_INT | CD_MASK_CLOTH_ORCO |
     CD_MASK_MLOOPUV | CD_MASK_MLOOPCOL | CD_MASK_MTEXPOLY | CD_MASK_PREVIEW_MLOOPCOL |
     CD_MASK_PROP_STR | CD_MASK_ORIGSPACE | CD_MASK_ORIGSPACE_MLOOP | CD_MASK_ORCO | CD_MASK_TANGENT |
     CD_MASK_PREVIEW_MCOL | CD_MASK_NORMAL | CD_MASK_SHAPEKEY | CD_MASK_RECAST |
-    CD_MASK_ORIGINDEX | CD_MASK_POLYINDEX;
+    CD_MASK_ORIGINDEX | CD_MASK_POLYINDEX | CD_MASK_MVERT_SKIN;
 const CustomDataMask CD_MASK_BMESH =
     CD_MASK_MLOOPUV | CD_MASK_MLOOPCOL | CD_MASK_MTEXPOLY |
     CD_MASK_MSTICKY | CD_MASK_MDEFORMVERT | CD_MASK_PROP_FLT | CD_MASK_PROP_INT |
     CD_MASK_PROP_STR | CD_MASK_SHAPEKEY | CD_MASK_SHAPE_KEYINDEX | CD_MASK_MDISPS |
     CD_MASK_CREASE | CD_MASK_BWEIGHT | CD_MASK_RECAST | CD_MASK_PAINT_MASK |
-    CD_MASK_GRID_PAINT_MASK;
+    CD_MASK_GRID_PAINT_MASK | CD_MASK_MVERT_SKIN;
 const CustomDataMask CD_MASK_FACECORNERS =
     CD_MASK_MTFACE | CD_MASK_MCOL | CD_MASK_MTEXPOLY | CD_MASK_MLOOPUV |
     CD_MASK_MLOOPCOL;
@@ -1161,6 +1193,18 @@ static const char *layerType_getName(int type)
        return LAYERTYPENAMES[type];
 }
 
+void customData_mask_layers__print(CustomDataMask mask)
+{
+       int i;
+
+       printf("mask=0x%lx:\n", (long unsigned int)mask);
+       for (i = 0; i < CD_NUMTYPES; i++) {
+               if (mask & CD_TYPE_AS_MASK(i)) {
+                       printf("  %s\n", layerType_getName(i));
+               }
+       }
+}
+
 /********************* CustomData functions *********************/
 static void customData_update_offsets(CustomData *data);
 
@@ -2175,6 +2219,48 @@ void CustomData_bmesh_update_active_layers(CustomData *fdata, CustomData *pdata,
        }
 }
 
+/* update active indices for active/render/clone/stencil custom data layers
+ * based on indices from fdata layers
+ * used by do_versions in readfile.c when creating pdata and ldata for pre-bmesh
+ * meshes and needed to preserve active/render/clone/stencil flags set in pre-bmesh files
+ */
+void CustomData_bmesh_do_versions_update_active_layers(CustomData *fdata, CustomData *pdata, CustomData *ldata)
+{
+       int act;
+
+       if (CustomData_has_layer(fdata, CD_MTFACE)) {
+               act = CustomData_get_active_layer(fdata, CD_MTFACE);
+               CustomData_set_layer_active(pdata, CD_MTEXPOLY, act);
+               CustomData_set_layer_active(ldata, CD_MLOOPUV, act);
+
+               act = CustomData_get_render_layer(fdata, CD_MTFACE);
+               CustomData_set_layer_render(pdata, CD_MTEXPOLY, act);
+               CustomData_set_layer_render(ldata, CD_MLOOPUV, act);
+
+               act = CustomData_get_clone_layer(fdata, CD_MTFACE);
+               CustomData_set_layer_clone(pdata, CD_MTEXPOLY, act);
+               CustomData_set_layer_clone(ldata, CD_MLOOPUV, act);
+
+               act = CustomData_get_stencil_layer(fdata, CD_MTFACE);
+               CustomData_set_layer_stencil(pdata, CD_MTEXPOLY, act);
+               CustomData_set_layer_stencil(ldata, CD_MLOOPUV, act);
+       }
+
+       if (CustomData_has_layer(fdata, CD_MCOL)) {
+               act = CustomData_get_active_layer(fdata, CD_MCOL);
+               CustomData_set_layer_active(ldata, CD_MLOOPCOL, act);
+
+               act = CustomData_get_render_layer(fdata, CD_MCOL);
+               CustomData_set_layer_render(ldata, CD_MLOOPCOL, act);
+
+               act = CustomData_get_clone_layer(fdata, CD_MCOL);
+               CustomData_set_layer_clone(ldata, CD_MLOOPCOL, act);
+
+               act = CustomData_get_stencil_layer(fdata, CD_MCOL);
+               CustomData_set_layer_stencil(ldata, CD_MLOOPCOL, act);
+       }
+}
+
 void CustomData_bmesh_init_pool(CustomData *data, int totelem, const char htype)
 {
        int chunksize;
@@ -2323,7 +2409,8 @@ void CustomData_bmesh_copy_data(const CustomData *source, CustomData *dest,
 
                /* if we found a matching layer, copy the data */
                if (dest->layers[dest_i].type == source->layers[src_i].type &&
-                   strcmp(dest->layers[dest_i].name, source->layers[src_i].name) == 0) {
+                   strcmp(dest->layers[dest_i].name, source->layers[src_i].name) == 0)
+               {
                        char *src_data = (char *)src_block + source->layers[src_i].offset;
                        char *dest_data = (char *)*dest_block + dest->layers[dest_i].offset;