[Bf-blender-cvs] [77d1fe9] cycles-ptex-12: Add operators to add/remove Ptex layer

Nicholas Bishop noreply at git.blender.org
Mon Jan 26 02:05:06 CET 2015


Commit: 77d1fe9e6ac0667a8877a7ba3579c6543911b9b9
Author: Nicholas Bishop
Date:   Wed Jan 21 22:18:01 2015 +0100
Branches: cycles-ptex-12
https://developer.blender.org/rB77d1fe9e6ac0667a8877a7ba3579c6543911b9b9

Add operators to add/remove Ptex layer

Copy pasting :(

===================================================================

M	source/blender/editors/mesh/mesh_data.c
M	source/blender/editors/mesh/mesh_intern.h
M	source/blender/editors/mesh/mesh_ops.c

===================================================================

diff --git a/source/blender/editors/mesh/mesh_data.c b/source/blender/editors/mesh/mesh_data.c
index 152d055..4b6eea5 100644
--- a/source/blender/editors/mesh/mesh_data.c
+++ b/source/blender/editors/mesh/mesh_data.c
@@ -47,6 +47,7 @@
 #include "BKE_main.h"
 #include "BKE_mesh.h"
 #include "BKE_paint.h"
+#include "BKE_ptex.h"
 #include "BKE_report.h"
 #include "BKE_editmesh.h"
 
@@ -129,7 +130,7 @@ static void delete_customdata_layer(Mesh *me, CustomDataLayer *layer)
 	CustomData *data;
 	int layer_index, tot, n;
 
-	data = mesh_customdata_get_type(me, (ELEM(type, CD_MLOOPUV, CD_MLOOPCOL)) ? BM_LOOP : BM_FACE, &tot);
+	data = mesh_customdata_get_type(me, (ELEM(type, CD_MLOOPUV, CD_MLOOPCOL, CD_LOOP_PTEX)) ? BM_LOOP : BM_FACE, &tot);
 	layer_index = CustomData_get_layer_index(data, type);
 	n = (layer - &data->layers[layer_index]);
 	BLI_assert(n >= 0 && (n + layer_index) < data->totlayer);
@@ -715,6 +716,151 @@ void MESH_OT_vertex_color_remove(wmOperatorType *ot)
 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 }
 
+/*** ptex operator ***/
+
+static int mesh_ptex_add(Mesh *me, const char *name, const bool active_set)
+{
+	int layernum = 0;
+
+	if (me->edit_btmesh) {
+		/* TODO */
+		assert(!me->edit_btmesh);
+	}
+	else {
+		MLoopPtex *layer_data;
+
+		layernum = CustomData_number_of_layers(&me->ldata, CD_LOOP_PTEX);
+
+		/* TODO: duplicate current layer? */
+		layer_data = CustomData_add_layer_named(&me->ldata, CD_LOOP_PTEX,
+												CD_DEFAULT, NULL,
+												me->totloop, name);
+
+		{
+			// TODO
+			int i;
+			for (i = 0; i < me->totloop; i++) {
+				BKE_loop_ptex_init(&layer_data[i], MPTEX_DATA_TYPE_UINT8,
+								   4, 5, 5);
+			}
+		}
+
+		/* TODO */
+		if (0) {
+			MLoopPtexUV *data = CustomData_add_layer_named(&me->ldata, CD_LOOP_PTEX_UV, CD_DEFAULT, NULL, me->totloop, name);
+			int i, j;
+			int cur_ptex_id = 0;
+			for (i = 0; i < me->totpoly; i++) {
+				const MPoly *p = &me->mpoly[i];
+				const bool constant = p->totloop == 4;
+				for (j = 0; j < p->totloop; j++) {
+					data[p->loopstart + j].id = cur_ptex_id;
+					if (!constant) {
+						cur_ptex_id++;
+					}
+				}
+				if (constant) {
+					cur_ptex_id++;
+				}
+			}
+		}
+
+		if (active_set || layernum == 0) {
+			CustomData_set_layer_active(&me->ldata, CD_LOOP_PTEX, layernum);
+		}
+
+		BKE_mesh_update_customdata_pointers(me, true);
+	}
+
+	DAG_id_tag_update(&me->id, 0);
+	WM_main_add_notifier(NC_GEOM | ND_DATA, me);
+
+	return layernum;
+}
+
+static int mesh_ptex_add_exec(bContext *C, wmOperator *UNUSED(op))
+{
+	Object *ob = ED_object_context(C);
+	Mesh *me = ob->data;
+
+	if (mesh_ptex_add(me, NULL, true) == -1)
+		return OPERATOR_CANCELLED;
+
+	return OPERATOR_FINISHED;
+}
+
+void MESH_OT_ptex_add(wmOperatorType *ot)
+{
+	/* identifiers */
+	ot->name = "Add Ptex";
+	ot->description = "Add Ptex layer";
+	ot->idname = "MESH_OT_ptex_add";
+	
+	/* api callbacks */
+	ot->poll = layers_poll;
+	ot->exec = mesh_ptex_add_exec;
+
+	/* flags */
+	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+}
+
+static bool mesh_ptex_remove_index(Mesh *me, const int n)
+{
+	CustomData *ldata = GET_CD_DATA(me, ldata);
+	CustomDataLayer *cdl;
+	int index;
+
+	index = CustomData_get_layer_index_n(ldata, CD_LOOP_PTEX, n);
+	cdl = (index == -1) ? NULL : &ldata->layers[index];
+
+	if (!cdl)
+		return false;
+
+	delete_customdata_layer(me, cdl);
+	DAG_id_tag_update(&me->id, 0);
+	WM_main_add_notifier(NC_GEOM | ND_DATA, me);
+
+	return true;
+}
+
+static bool mesh_ptex_remove_active(Mesh *me)
+{
+	CustomData *ldata = GET_CD_DATA(me, ldata);
+	const int n = CustomData_get_active_layer(ldata, CD_LOOP_PTEX);
+	if (n != -1) {
+		return mesh_ptex_remove_index(me, n);
+	}
+	else {
+		return false;
+	}
+}
+
+static int mesh_ptex_remove_exec(bContext *C, wmOperator *UNUSED(op))
+{
+	Object *ob = ED_object_context(C);
+	Mesh *me = ob->data;
+
+	if (!mesh_ptex_remove_active(me))
+		return OPERATOR_CANCELLED;
+
+	return OPERATOR_FINISHED;
+}
+
+void MESH_OT_ptex_remove(wmOperatorType *ot)
+{
+	/* identifiers */
+	ot->name = "Remove Ptex";
+	ot->description = "Remove Ptex layer";
+	ot->idname = "MESH_OT_ptex_remove";
+	
+	/* api callbacks */
+	ot->exec = mesh_ptex_remove_exec;
+	ot->poll = layers_poll;
+
+	/* flags */
+	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+}
+
 /* *** CustomData clear functions, we need an operator for each *** */
 
 static int mesh_customdata_clear_exec__internal(bContext *C,
diff --git a/source/blender/editors/mesh/mesh_intern.h b/source/blender/editors/mesh/mesh_intern.h
index 6ba9109..13879d1 100644
--- a/source/blender/editors/mesh/mesh_intern.h
+++ b/source/blender/editors/mesh/mesh_intern.h
@@ -234,6 +234,8 @@ void MESH_OT_uv_texture_add(struct wmOperatorType *ot);
 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_ptex_add(struct wmOperatorType *ot);
+void MESH_OT_ptex_remove(struct wmOperatorType *ot);
 /* no create_mask yet */
 void MESH_OT_customdata_clear_mask(struct wmOperatorType *ot);
 void MESH_OT_customdata_clear_skin(struct wmOperatorType *ot);
diff --git a/source/blender/editors/mesh/mesh_ops.c b/source/blender/editors/mesh/mesh_ops.c
index e7dc5a6..8d41593 100644
--- a/source/blender/editors/mesh/mesh_ops.c
+++ b/source/blender/editors/mesh/mesh_ops.c
@@ -151,6 +151,8 @@ void ED_operatortypes_mesh(void)
 	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_ptex_add);
+	WM_operatortype_append(MESH_OT_ptex_remove);
 	WM_operatortype_append(MESH_OT_customdata_clear_mask);
 	WM_operatortype_append(MESH_OT_customdata_clear_skin);
 	WM_operatortype_append(MESH_OT_drop_named_image);




More information about the Bf-blender-cvs mailing list