[Bf-blender-cvs] [830d9bc] cycles-ptex-24: Add operator to resize Ptex data
Nicholas Bishop
noreply at git.blender.org
Fri Jan 30 18:00:48 CET 2015
Commit: 830d9bcfb30c2c2baae99350a541ee5077045172
Author: Nicholas Bishop
Date: Mon Jan 26 15:33:57 2015 +0100
Branches: cycles-ptex-24
https://developer.blender.org/rB830d9bcfb30c2c2baae99350a541ee5077045172
Add operator to resize Ptex data
===================================================================
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 09e760c..a63a721 100644
--- a/source/blender/editors/mesh/mesh_data.c
+++ b/source/blender/editors/mesh/mesh_data.c
@@ -51,6 +51,7 @@
#include "BKE_report.h"
#include "BKE_editmesh.h"
+#include "RNA_access.h"
#include "RNA_define.h"
#include "WM_api.h"
@@ -746,26 +747,6 @@ static int mesh_ptex_add(Mesh *me, const char *name, const bool active_set)
}
}
- /* 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);
}
@@ -862,6 +843,89 @@ void MESH_OT_ptex_remove(wmOperatorType *ot)
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}
+typedef enum {
+ PTEX_RES_CHANGE_MODE_HALVE,
+ PTEX_RES_CHANGE_MODE_DOUBLE
+} PtexResChangeMode;
+
+static MPtexLogRes mesh_ptex_new_logres_calc(const PtexResChangeMode mode,
+ const MPtexLogRes old_res)
+{
+ MPtexLogRes new_res = {0, 0};
+ const int limit = 24;
+ switch (mode) {
+ case PTEX_RES_CHANGE_MODE_HALVE:
+ new_res.u = (old_res.u > 0) ? old_res.u - 1 : 0;
+ new_res.v = (old_res.v > 0) ? old_res.v - 1 : 0;
+ break;
+
+ case PTEX_RES_CHANGE_MODE_DOUBLE:
+ new_res.u = (old_res.u < limit) ? old_res.u + 1 : old_res.u;
+ new_res.v = (old_res.v < limit) ? old_res.v + 1 : old_res.v;
+ break;
+ }
+ return new_res;
+}
+
+static int mesh_ptex_res_change_exec(bContext *C, wmOperator *op)
+{
+ Object *ob = ED_object_context(C);
+ Mesh *me = ob->data;
+ int i;
+
+ MLoopPtex *loop_ptex = CustomData_get_layer(&me->ldata, CD_LOOP_PTEX);
+ const PtexResChangeMode mode = RNA_enum_get(op->ptr, "mode");
+
+ for (i = 0; i < me->totpoly; i++) {
+ const MPoly *poly = &me->mpoly[i];
+ int j;
+
+ if (poly->flag & ME_FACE_SEL) {
+ for (j = 0; j < poly->totloop; j++) {
+ const int loop_index = poly->loopstart + j;
+ MLoopPtex *lp = &loop_ptex[loop_index];
+
+ const MPtexLogRes new_logres =
+ mesh_ptex_new_logres_calc(mode, lp->logres);
+
+ BKE_loop_ptex_resize(lp, new_logres);
+ }
+ }
+ }
+
+ /* TODO, not sure how this will look yet */
+ loop_ptex[0].image = NULL;
+
+ DAG_id_tag_update(&me->id, 0);
+ WM_main_add_notifier(NC_GEOM | ND_DATA, me);
+
+ return OPERATOR_FINISHED;
+}
+
+void MESH_OT_ptex_res_change(wmOperatorType *ot)
+{
+ static const EnumPropertyItem mode_items[3] = {
+ {PTEX_RES_CHANGE_MODE_HALVE, "HALVE", 0, "Halve"},
+ {PTEX_RES_CHANGE_MODE_DOUBLE, "DOUBLE", 0, "Double"},
+ {0, NULL, 0, NULL, NULL}
+ };
+
+ /* identifiers */
+ ot->name = "Change Ptex Resolution";
+ ot->description = "Increase or decrease the Ptex resolution of selected faces";
+ ot->idname = "MESH_OT_ptex_res_change";
+
+ /* api callbacks */
+ ot->poll = layers_poll;
+ ot->exec = mesh_ptex_res_change_exec;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+
+ RNA_def_enum(ot->srna, "mode", mode_items,
+ PTEX_RES_CHANGE_MODE_HALVE, "Mode", "");
+}
+
/* *** 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 13879d1..ddf0f7b 100644
--- a/source/blender/editors/mesh/mesh_intern.h
+++ b/source/blender/editors/mesh/mesh_intern.h
@@ -236,6 +236,7 @@ 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);
+void MESH_OT_ptex_res_change(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 8d41593..d8a5fb8 100644
--- a/source/blender/editors/mesh/mesh_ops.c
+++ b/source/blender/editors/mesh/mesh_ops.c
@@ -153,6 +153,7 @@ void ED_operatortypes_mesh(void)
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_ptex_res_change);
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