Ensure skin nodes get created when adding modifier.
authorNicholas Bishop <nicholasbishop@gmail.com>
Tue, 22 May 2012 15:29:37 +0000 (15:29 +0000)
committerNicholas Bishop <nicholasbishop@gmail.com>
Tue, 22 May 2012 15:29:37 +0000 (15:29 +0000)
Skin modifier documentation:
http://wiki.blender.org/index.php/User:Nicholasbishop/SkinModifier

source/blender/editors/object/object_modifier.c

index 47748fb..60a11f5 100644 (file)
@@ -85,6 +85,8 @@
 
 #include "object_intern.h"
 
+static void modifier_skin_customdata_ensure(struct Object *ob);
+
 /******************************** API ****************************/
 
 ModifierData *ED_object_modifier_add(ReportList *reports, Main *bmain, Scene *scene, Object *ob, const char *name, int type)
@@ -157,6 +159,10 @@ ModifierData *ED_object_modifier_add(ReportList *reports, Main *bmain, Scene *sc
                        /* ensure that grid paint mask layer is created */
                        ED_sculpt_mask_layers_ensure(ob, (MultiresModifierData *)new_md);
                }
+               else if(type == eModifierType_Skin) {
+                       /* ensure skin-node customdata exists */
+                       modifier_skin_customdata_ensure(ob);
+               }
        }
 
        DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
@@ -1327,6 +1333,41 @@ void OBJECT_OT_multires_base_apply(wmOperatorType *ot)
 }
 
 
+/************************** skin modifier ***********************/
+
+static void modifier_skin_customdata_ensure(Object *ob)
+{
+       Mesh *me = ob->data;
+       BMesh *bm = me->edit_btmesh ? me->edit_btmesh->bm : NULL;
+       MVertSkin *vs;
+
+       if (bm && !CustomData_has_layer(&bm->vdata, CD_MVERT_SKIN)) {
+               BMVert *v;
+               BMIter iter;
+
+               BM_data_layer_add(bm, &bm->vdata, CD_MVERT_SKIN);
+               
+               /* Mark an arbitrary vertex as root */
+               BM_ITER_MESH(v, &iter, bm, BM_VERTS_OF_MESH) {
+                       vs = CustomData_bmesh_get(&bm->vdata, v->head.data,
+                                                                         CD_MVERT_SKIN);
+                       vs->flag |= MVERT_SKIN_ROOT;
+                       break;
+               }
+       }
+       else if (!CustomData_has_layer(&me->vdata, CD_MVERT_SKIN)) {
+               vs = CustomData_add_layer(&me->vdata,
+                                                                 CD_MVERT_SKIN,
+                                                                 CD_DEFAULT,
+                                                                 NULL,
+                                                                 me->totvert);
+
+               /* Mark an arbitrary vertex as root */
+               vs->flag |= MVERT_SKIN_ROOT;
+       }
+}
+
+
 /************************ mdef bind operator *********************/
 
 static int meshdeform_poll(bContext *C)