[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [50782] trunk/blender: There was no way to remove mesh data layers from the interface - add a panel that works in object an editmode .

Campbell Barton ideasman42 at gmail.com
Fri Sep 21 05:41:59 CEST 2012


Revision: 50782
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=50782
Author:   campbellbarton
Date:     2012-09-21 03:41:59 +0000 (Fri, 21 Sep 2012)
Log Message:
-----------
There was no way to remove mesh data layers from the interface - add a panel that works in object an editmode.
currently can remove sticky/mask/skin vertex layers.

regarding the skin layer - while adding and removing the modifier normally works fine, its not 100% reliable since the mesh may be linked into another scene, or be a linked duplicate and the object with the modifier deleted.

Modified Paths:
--------------
    trunk/blender/release/scripts/startup/bl_ui/properties_data_mesh.py
    trunk/blender/source/blender/editors/mesh/mesh_data.c
    trunk/blender/source/blender/editors/mesh/mesh_intern.h
    trunk/blender/source/blender/editors/mesh/mesh_ops.c

Modified: trunk/blender/release/scripts/startup/bl_ui/properties_data_mesh.py
===================================================================
--- trunk/blender/release/scripts/startup/bl_ui/properties_data_mesh.py	2012-09-20 18:55:44 UTC (rev 50781)
+++ trunk/blender/release/scripts/startup/bl_ui/properties_data_mesh.py	2012-09-21 03:41:59 UTC (rev 50782)
@@ -316,10 +316,28 @@
             layout.prop(lay, "name")
 
 
+class DATA_PT_customdata(MeshButtonsPanel, Panel):
+    bl_label = "Geometry Data"
+    bl_options = {'DEFAULT_CLOSED'}
+    COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
+
+    def draw(self, context):
+        layout = self.layout
+
+        # me = context.mesh
+        col = layout.column(align=True)
+        # row = col.row(align=True)
+        # row.operator("mesh.customdata_add_sticky", icon='ZOOMIN')
+        col.operator("mesh.customdata_clear_sticky", icon='X')
+        col.operator("mesh.customdata_clear_mask", icon='X')
+        col.operator("mesh.customdata_clear_skin", icon='X')
+
+
 class DATA_PT_custom_props_mesh(MeshButtonsPanel, PropertyPanel, Panel):
     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
     _context_path = "object.data"
     _property_type = bpy.types.Mesh
 
+
 if __name__ == "__main__":  # only for live edit.
     bpy.utils.register_module(__name__)

Modified: trunk/blender/source/blender/editors/mesh/mesh_data.c
===================================================================
--- trunk/blender/source/blender/editors/mesh/mesh_data.c	2012-09-20 18:55:44 UTC (rev 50781)
+++ trunk/blender/source/blender/editors/mesh/mesh_data.c	2012-09-21 03:41:59 UTC (rev 50782)
@@ -74,6 +74,64 @@
 
 #include "mesh_intern.h"
 
+static CustomData *mesh_customdata_get_type(Mesh *me, const char htype, int *r_tot)
+{
+	CustomData *data;
+	BMesh *bm = (me->edit_btmesh) ? me->edit_btmesh->bm : NULL;
+	int tot;
+
+	/* this  */
+	switch (htype) {
+		case BM_VERT:
+			if (bm) {
+				data = &bm->vdata;
+				tot  = bm->totvert;
+			}
+			else {
+				data = &me->vdata;
+				tot  = me->totvert;
+			}
+			break;
+		case BM_EDGE:
+			if (bm) {
+				data = &bm->edata;
+				tot  = bm->totedge;
+			}
+			else {
+				data = &me->edata;
+				tot  = me->totedge;
+			}
+			break;
+		case BM_LOOP:
+			if (bm) {
+				data = &bm->ldata;
+				tot  = bm->totloop;
+			}
+			else {
+				data = &me->ldata;
+				tot  = me->totloop;
+			}
+			break;
+		case BM_FACE:
+			if (bm) {
+				data = &bm->pdata;
+				tot  = bm->totface;
+			}
+			else {
+				data = &me->pdata;
+				tot  = me->totpoly;
+			}
+			break;
+		default:
+			BLI_assert(0);
+			tot = 0;
+			data = NULL;
+	}
+
+	*r_tot = tot;
+	return data;
+}
+
 #define GET_CD_DATA(me, data) (me->edit_btmesh ? &me->edit_btmesh->bm->data : &me->data)
 static void delete_customdata_layer(bContext *C, Object *ob, CustomDataLayer *layer)
 {
@@ -703,6 +761,7 @@
 
 /*********************** sticky operators ************************/
 
+/* FIXME - this operator is broken - only updates active but operates on selected */
 static int mesh_sticky_add_exec(bContext *C, wmOperator *UNUSED(op))
 {
 	Scene *scene = CTX_data_scene(C);
@@ -724,12 +783,12 @@
 	return OPERATOR_FINISHED;
 }
 
-void MESH_OT_sticky_add(wmOperatorType *ot)
+void MESH_OT_customdata_add_sticky(wmOperatorType *ot)
 {
 	/* identifiers */
 	ot->name = "Add Sticky";
 	ot->description = "Add sticky UV texture layer";
-	ot->idname = "MESH_OT_sticky_add";
+	ot->idname = "MESH_OT_customdata_add_sticky";
 	
 	/* api callbacks */
 	ot->poll = layers_poll;
@@ -739,38 +798,144 @@
 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 }
 
-static int mesh_sticky_remove_exec(bContext *C, wmOperator *UNUSED(op))
+/* *** CustomData clear functions, we need an operator for each *** */
+
+static int mesh_customdata_clear_exec__internal(bContext *C,
+                                                char htype, int type)
 {
-	Object *ob = ED_object_context(C);
-	Mesh *me = ob->data;
+	Object *obedit = ED_object_context(C);
+	Mesh       *me = obedit->data;
 
-	if (!me->msticky)
-		return OPERATOR_CANCELLED;
+	int tot;
+	CustomData *data = mesh_customdata_get_type(me, htype, &tot);
 
-	CustomData_free_layer_active(&me->vdata, CD_MSTICKY, me->totvert);
-	me->msticky = NULL;
+	BLI_assert(CustomData_layertype_is_singleton(type) == TRUE);
 
+	CustomData_free_layers(data, type, tot);
+
 	DAG_id_tag_update(&me->id, 0);
 	WM_event_add_notifier(C, NC_GEOM | ND_DATA, me);
 
+	/* clears points such as me->sticky */
+	mesh_update_customdata_pointers(me, FALSE);
+
 	return OPERATOR_FINISHED;
 }
 
-void MESH_OT_sticky_remove(wmOperatorType *ot)
+/* Clear Mask */
+static int mesh_customdata_clear_mask_poll(bContext *C)
 {
+	Object *ob = ED_object_context(C);
+
+	/* special case - can't run this if we're in sculpt mode */
+	if (ob->mode & OB_MODE_SCULPT) {
+		return FALSE;
+	}
+
+	if (ob && ob->type == OB_MESH) {
+		Mesh *me = ob->data;
+		if (me->id.lib == NULL) {
+			CustomData *data = GET_CD_DATA(me, vdata);
+			if (CustomData_has_layer(data, CD_PAINT_MASK)) {
+				return TRUE;
+			}
+		}
+	}
+	return FALSE;
+}
+static int mesh_customdata_clear_mask_exec(bContext *C, wmOperator *UNUSED(op))
+{
+	return mesh_customdata_clear_exec__internal(C, BM_VERT, CD_PAINT_MASK);
+}
+
+void MESH_OT_customdata_clear_mask(wmOperatorType *ot)
+{
+
 	/* identifiers */
-	ot->name = "Remove Sticky";
-	ot->description = "Remove sticky UV texture layer";
-	ot->idname = "MESH_OT_sticky_remove";
-	
+	ot->name = "Clear Sculpt-Mask Data";
+	ot->idname = "MESH_OT_customdata_clear_mask";
+	ot->description = "Clear vertex sculpt masking data from the mesh";
+
 	/* api callbacks */
-	ot->poll = layers_poll;
-	ot->exec = mesh_sticky_remove_exec;
+	ot->exec = mesh_customdata_clear_mask_exec;
+	ot->poll = mesh_customdata_clear_mask_poll;
 
 	/* flags */
 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 }
 
+/* Clear Sticky */
+static int mesh_customdata_clear_sticky_poll(bContext *C)
+{
+	Object *ob = ED_object_context(C);
+
+	if (ob && ob->type == OB_MESH) {
+		Mesh *me = ob->data;
+		if (me->id.lib == NULL) {
+			CustomData *data = GET_CD_DATA(me, vdata);
+			if (CustomData_has_layer(data, CD_MSTICKY)) {
+				return TRUE;
+			}
+		}
+	}
+	return FALSE;
+}
+static int mesh_customdata_clear_sticky_exec(bContext *C, wmOperator *UNUSED(op))
+{
+	return mesh_customdata_clear_exec__internal(C, BM_VERT, CD_MSTICKY);
+}
+
+void MESH_OT_customdata_clear_sticky(wmOperatorType *ot)
+{
+	/* identifiers */
+	ot->name = "Clear Sticky Data";
+	ot->idname = "MESH_OT_customdata_clear_sticky";
+	ot->description = "Clear vertex sticky UV texture layer";
+
+	/* api callbacks */
+	ot->exec = mesh_customdata_clear_sticky_exec;
+	ot->poll = mesh_customdata_clear_sticky_poll;
+
+	/* flags */
+	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+}
+
+/* Clear Skin */
+static int mesh_customdata_clear_skin_poll(bContext *C)
+{
+	Object *ob = ED_object_context(C);
+
+	if (ob && ob->type == OB_MESH) {
+		Mesh *me = ob->data;
+		if (me->id.lib == NULL) {
+			CustomData *data = GET_CD_DATA(me, vdata);
+			if (CustomData_has_layer(data, CD_MVERT_SKIN)) {
+				return TRUE;
+			}
+		}
+	}
+	return FALSE;
+}
+static int mesh_customdata_clear_skin_exec(bContext *C, wmOperator *UNUSED(op))
+{
+	return mesh_customdata_clear_exec__internal(C, BM_VERT, CD_MVERT_SKIN);
+}
+
+void MESH_OT_customdata_clear_skin(wmOperatorType *ot)
+{
+	/* identifiers */
+	ot->name = "Clear Skin Data";
+	ot->idname = "MESH_OT_customdata_clear_skin";
+	ot->description = "Clear vertex skin layer";
+
+	/* api callbacks */
+	ot->exec = mesh_customdata_clear_skin_exec;
+	ot->poll = mesh_customdata_clear_skin_poll;
+
+	/* flags */
+	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+}
+
 /************************** Add Geometry Layers *************************/
 
 void ED_mesh_update(Mesh *mesh, bContext *C, int calc_edges, int calc_tessface)

Modified: trunk/blender/source/blender/editors/mesh/mesh_intern.h
===================================================================
--- trunk/blender/source/blender/editors/mesh/mesh_intern.h	2012-09-20 18:55:44 UTC (rev 50781)
+++ trunk/blender/source/blender/editors/mesh/mesh_intern.h	2012-09-21 03:41:59 UTC (rev 50782)
@@ -187,8 +187,12 @@
 void MESH_OT_uv_texture_remove(struct wmOperatorType *ot);
 void MESH_OT_vertex_color_add(struct wmOperatorType *ot);
 void MESH_OT_vertex_color_remove(struct wmOperatorType *ot);
-void MESH_OT_sticky_add(struct wmOperatorType *ot);
-void MESH_OT_sticky_remove(struct wmOperatorType *ot);
+void MESH_OT_customdata_add_sticky(struct wmOperatorType *ot);
+void MESH_OT_customdata_clear_sticky(struct wmOperatorType *ot);
+/* no add mask yet */
+void MESH_OT_customdata_clear_mask(struct wmOperatorType *ot);
+void MESH_OT_customdata_clear_skin(struct wmOperatorType *ot);
+
 void MESH_OT_drop_named_image(struct wmOperatorType *ot);
 
 /* ************* bmesh_tools.c ***********/

Modified: trunk/blender/source/blender/editors/mesh/mesh_ops.c
===================================================================
--- trunk/blender/source/blender/editors/mesh/mesh_ops.c	2012-09-20 18:55:44 UTC (rev 50781)
+++ trunk/blender/source/blender/editors/mesh/mesh_ops.c	2012-09-21 03:41:59 UTC (rev 50782)
@@ -143,8 +143,10 @@
 	WM_operatortype_append(MESH_OT_uv_texture_remove);
 	WM_operatortype_append(MESH_OT_vertex_color_add);
 	WM_operatortype_append(MESH_OT_vertex_color_remove);
-	WM_operatortype_append(MESH_OT_sticky_add);
-	WM_operatortype_append(MESH_OT_sticky_remove);
+	WM_operatortype_append(MESH_OT_customdata_add_sticky);
+	WM_operatortype_append(MESH_OT_customdata_clear_sticky);
+	WM_operatortype_append(MESH_OT_customdata_clear_mask);
+	WM_operatortype_append(MESH_OT_customdata_clear_skin);
 	WM_operatortype_append(MESH_OT_drop_named_image);
 
 	WM_operatortype_append(MESH_OT_edgering_select);




More information about the Bf-blender-cvs mailing list