[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [59663] branches/soc-2013-paint: Add layer operator in projective texture paint layer panel.
Antony Riakiotakis
kalast at gmail.com
Fri Aug 30 16:49:20 CEST 2013
Revision: 59663
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=59663
Author: psy-fi
Date: 2013-08-30 14:49:20 +0000 (Fri, 30 Aug 2013)
Log Message:
-----------
Add layer operator in projective texture paint layer panel.
This commit adds a new mtex slot of type image, using UV mapping on
active material. It also allocates a new image for it. Size is fixed
currently (1024x1024) but this can change later.
This code can surely be useful to enforce a working texture paint system
as soon as user enters.I hope resource management is done right here, it
looks like it works (tm).
Modified Paths:
--------------
branches/soc-2013-paint/release/scripts/startup/bl_ui/space_view3d_toolbar.py
branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image_proj.c
branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_intern.h
branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_ops.c
Modified: branches/soc-2013-paint/release/scripts/startup/bl_ui/space_view3d_toolbar.py
===================================================================
--- branches/soc-2013-paint/release/scripts/startup/bl_ui/space_view3d_toolbar.py 2013-08-30 13:24:16 UTC (rev 59662)
+++ branches/soc-2013-paint/release/scripts/startup/bl_ui/space_view3d_toolbar.py 2013-08-30 14:49:20 UTC (rev 59663)
@@ -545,6 +545,8 @@
col.label("Available Paint layers")
col.template_list("TEXTURE_UL_texpaintslots", "", mat, "texture_paint_slots", mat, "active_paint_texture_index", rows=2)
#col.label("Only slots with UV mapping and image textures are available")
+
+ col.operator_menu_enum("paint.add_layer", "type")
class VIEW3D_PT_tools_brush(Panel, View3DPaintPanel):
Modified: branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image_proj.c
===================================================================
--- branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image_proj.c 2013-08-30 13:24:16 UTC (rev 59662)
+++ branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image_proj.c 2013-08-30 14:49:20 UTC (rev 59663)
@@ -48,6 +48,8 @@
#include "BLI_threads.h"
#include "BLI_utildefines.h"
+#include "BLF_translation.h"
+
#include "PIL_time.h"
#include "IMB_imbuf.h"
@@ -83,6 +85,7 @@
#include "BIF_glutil.h"
#include "UI_view2d.h"
+#include "UI_interface.h"
#include "ED_image.h"
#include "ED_screen.h"
@@ -4771,3 +4774,108 @@
RNA_def_string_file_name(ot->srna, "filepath", "", FILE_MAX, "File Path", "Name of the file");
}
+
+static EnumPropertyItem layer_type_items[] = {
+ {MAP_COL, "DIFFUSE_COLOR", 0, "Diffuse Color", ""},
+ {MAP_REF, "DIFFUSE_INTENSITY", 0, "Diffuse Intensity", ""},
+ {MAP_ALPHA, "ALPHA", 0, "Alpha", ""},
+ {MAP_TRANSLU, "TRANSLUCENCY", 0, "Translucency", ""},
+ {MAP_COLSPEC, "SPECULAR_COLOR", 0, "Specular Color", ""},
+ {MAP_SPEC, "SPECULAR_INTENSITY", 0, "Specular Intensity", ""},
+ {MAP_HAR, "SPECULAR_HARDNESS", 0, "Specular Hardness", ""},
+ {MAP_AMB, "AMBIENT", 0, "Ambient", ""},
+ {MAP_EMIT, "EMMIT", 0, "Emmit", ""},
+ {MAP_COLMIR, "MIRROR_COLOR", 0, "Mirror Color", ""},
+ {MAP_RAYMIRR, "RAYMIRROR", 0, "Ray Mirror", ""},
+ {MAP_NORM, "NORMAL", 0, "Normal", ""},
+ {MAP_WARP, "WARP", 0, "Warp", ""},
+ {MAP_DISPLACE, "DISPLACE", 0, "Displace", ""},
+ {0, NULL, 0, NULL, NULL}
+};
+
+static int texture_paint_add_layer_exec(bContext *C, wmOperator *op)
+{
+ Material *ma;
+ Object *ob = CTX_data_active_object(C);
+ /* hardcoded for now, allow options later */
+ int width = 1024;
+ int height = 1024;
+ float color[4] = {0.0, 0.0, 0.0, 1.0};
+
+ int type = RNA_enum_get(op->ptr, "type");
+
+ if (!ob)
+ return OPERATOR_CANCELLED;
+
+ ma = give_current_material(ob, ob->actcol);
+
+ if (ma) {
+ MTex *mtex = add_mtex_id(&ma->id, -1);
+
+ /* successful creation of mtex layer, now create set */
+ if (mtex) {
+ PointerRNA ptr, idptr;
+ PropertyRNA *prop;
+ Main *bmain = CTX_data_main(C);
+ Image *ima;
+
+ mtex->tex = add_texture(bmain, DATA_("Texture"));
+ mtex->mapto = type;
+
+ if (mtex->tex) {
+ /* hook into UI */
+ uiIDContextProperty(C, &ptr, &prop);
+
+ if (prop) {
+ /* when creating new ID blocks, use is already 1, but RNA
+ * pointer se also increases user, so this compensates it */
+ mtex->tex->id.us--;
+
+ RNA_id_pointer_create(&mtex->tex->id, &idptr);
+ RNA_property_pointer_set(&ptr, prop, idptr);
+ RNA_property_update(C, &ptr, prop);
+ }
+
+ ima = mtex->tex->ima = BKE_image_add_generated(bmain, width, height, "layer_texture", 32, 0, IMA_GENTYPE_BLANK, color);
+
+ uiIDContextProperty(C, &ptr, &prop);
+
+ if (prop) {
+ /* when creating new ID blocks, use is already 1, but RNA
+ * pointer se also increases user, so this compensates it */
+ ima->id.us--;
+
+ RNA_id_pointer_create(&ima->id, &idptr);
+ RNA_property_pointer_set(&ptr, prop, idptr);
+ RNA_property_update(C, &ptr, prop);
+ }
+
+ BKE_image_signal(ima, NULL, IMA_SIGNAL_USER_NEW_IMAGE);
+ WM_event_add_notifier(C, NC_TEXTURE | NA_ADDED, mtex->tex);
+ }
+
+ WM_event_add_notifier(C, NC_TEXTURE, CTX_data_scene(C));
+ return OPERATOR_FINISHED;
+ }
+ }
+
+ return OPERATOR_CANCELLED;
+}
+
+void PAINT_OT_add_layer(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "Add Paint Layer";
+ ot->description = "Add a paint layer";
+ ot->idname = "PAINT_OT_add_layer";
+
+ /* api callbacks */
+ ot->exec = texture_paint_add_layer_exec;
+ ot->poll = ED_operator_region_view3d_active;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+
+ /* properties */
+ ot->prop = RNA_def_enum(ot->srna, "type", layer_type_items, 0, "Type", "Merge method to use");
+}
Modified: branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_intern.h
===================================================================
--- branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_intern.h 2013-08-30 13:24:16 UTC (rev 59662)
+++ branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_intern.h 2013-08-30 14:49:20 UTC (rev 59663)
@@ -176,7 +176,7 @@
void PAINT_OT_texture_paint_toggle(struct wmOperatorType *ot);
void PAINT_OT_project_image(struct wmOperatorType *ot);
void PAINT_OT_image_from_view(struct wmOperatorType *ot);
-
+void PAINT_OT_add_layer(struct wmOperatorType *ot);
/* new texture painting */
void PAINT_OT_image_paint(struct wmOperatorType *ot);
Modified: branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_ops.c
===================================================================
--- branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_ops.c 2013-08-30 13:24:16 UTC (rev 59662)
+++ branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_ops.c 2013-08-30 14:49:20 UTC (rev 59663)
@@ -1030,6 +1030,7 @@
WM_operatortype_append(PAINT_OT_project_image);
WM_operatortype_append(PAINT_OT_image_from_view);
WM_operatortype_append(PAINT_OT_brush_colors_flip);
+ WM_operatortype_append(PAINT_OT_add_layer);
/* weight */
WM_operatortype_append(PAINT_OT_weight_paint_toggle);
More information about the Bf-blender-cvs
mailing list