[Bf-blender-cvs] [f962afa] soc-2013-paint: Support for node materials in texture painting.
Antony Riakiotakis
noreply at git.blender.org
Thu Apr 24 01:22:26 CEST 2014
Commit: f962afadf4620718e430dd4bcff994be9401e496
Author: Antony Riakiotakis
Date: Thu Apr 24 02:21:59 2014 +0300
https://developer.blender.org/rBf962afadf4620718e430dd4bcff994be9401e496
Support for node materials in texture painting.
This will just enamerate any image nodes in the node tree and use that.
===================================================================
M source/blender/blenkernel/BKE_material.h
M source/blender/blenkernel/intern/depsgraph.c
M source/blender/blenkernel/intern/material.c
M source/blender/editors/sculpt_paint/paint_image.c
M source/blender/editors/sculpt_paint/paint_image_proj.c
M source/blender/editors/uvedit/uvedit_ops.c
M source/blender/makesrna/intern/rna_material.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_material.h b/source/blender/blenkernel/BKE_material.h
index 2e2a349..365e04b 100644
--- a/source/blender/blenkernel/BKE_material.h
+++ b/source/blender/blenkernel/BKE_material.h
@@ -45,6 +45,8 @@ struct MTFace;
struct Scene;
struct Image;
struct MTex;
+struct ImageUser;
+struct bNode;
/* materials */
@@ -89,9 +91,9 @@ bool object_add_material_slot(struct Object *ob);
bool object_remove_material_slot(struct Object *ob);
bool get_mtex_slot_valid_texpaint(struct MTex *);
-void refresh_texpaint_image_cache(struct Material *ma);
+void refresh_texpaint_image_cache(struct Material *ma, bool use_nodes);
struct MTex *give_current_texpaint_slot(struct Material *ma);
-void refresh_object_texpaint_images(struct Object*);
+void refresh_object_texpaint_images(struct Object*, bool use_nodes);
/* rna api */
void BKE_material_resize_id(struct ID *id, short totcol, bool do_id_user);
diff --git a/source/blender/blenkernel/intern/depsgraph.c b/source/blender/blenkernel/intern/depsgraph.c
index d402a47..6126464 100644
--- a/source/blender/blenkernel/intern/depsgraph.c
+++ b/source/blender/blenkernel/intern/depsgraph.c
@@ -2473,11 +2473,11 @@ static void dag_id_flush_update(Main *bmain, Scene *sce, ID *id)
BKE_ptcache_object_reset(sce, obt, PTCACHE_RESET_DEPSGRAPH);
}
- if (idtype == ID_MA) {
+ if (ELEM(idtype, ID_MA, ID_TE)) {
for (obt = bmain->object.first; obt; obt = obt->id.next) {
if (obt->mode & OB_MODE_TEXTURE_PAINT) {
obt->recalc |= OB_RECALC_DATA;
- refresh_object_texpaint_images(obt);
+ refresh_object_texpaint_images(obt, BKE_scene_use_new_shading_nodes(sce));
lib_id_recalc_data_tag(bmain, &obt->id);
}
}
diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c
index 59ee5d6..4b5c3b0 100644
--- a/source/blender/blenkernel/intern/material.c
+++ b/source/blender/blenkernel/intern/material.c
@@ -1298,7 +1298,8 @@ bool get_mtex_slot_valid_texpaint(struct MTex *mtex)
mtex->tex->ima;
}
-void refresh_texpaint_image_cache(Material *ma)
+
+void refresh_texpaint_image_cache(Material *ma, bool use_nodes)
{
MTex **mtex;
short count = 0;
@@ -1307,41 +1308,73 @@ void refresh_texpaint_image_cache(Material *ma)
if (!ma)
return;
+ /* blender internal calculation goes here */
if (ma->texpaintslot) {
MEM_freeN (ma->texpaintslot);
ma->texpaintslot = NULL;
}
- for(mtex = ma->mtex, i = 0; i < MAX_MTEX; i++, mtex++) {
- if (get_mtex_slot_valid_texpaint(*mtex)) {
- count++;
+ if (use_nodes) {
+ bNode *node, *active_node;
+
+ if (!(ma->use_nodes && ma->nodetree))
+ return;
+
+ for (node = ma->nodetree->nodes.first; node; node = node->next) {
+ if (node->typeinfo->nclass == NODE_CLASS_TEXTURE)
+ count++;
}
- }
- ma->tot_slots = count;
+ ma->tot_slots = count;
- if (count == 0) {
- ma->paint_active_slot = 0;
- return;
+ if (count == 0) {
+ ma->paint_active_slot = 0;
+ return;
+ }
+ ma->texpaintslot = MEM_callocN(sizeof(*ma->texpaintslot) * count, "texpaint_slots");
+
+ active_node = nodeGetActiveTexture(ma->nodetree);
+
+ for (node = ma->nodetree->nodes.first; node; node = node->next) {
+ if (node->typeinfo->nclass == NODE_CLASS_TEXTURE) {
+ if (active_node == node)
+ ma->paint_active_slot = index;
+ ma->texpaintslot[index++].ima = (Image *)node->id;
+ }
+ }
}
+ else {
+ for(mtex = ma->mtex, i = 0; i < MAX_MTEX; i++, mtex++) {
+ if (get_mtex_slot_valid_texpaint(*mtex)) {
+ count++;
+ }
+ }
- ma->texpaintslot = MEM_callocN(sizeof(*ma->texpaintslot) * count, "texpaint_slots");
+ ma->tot_slots = count;
- for(mtex = ma->mtex, i = 0; i < MAX_MTEX; i++, mtex++) {
- if (get_mtex_slot_valid_texpaint(*mtex)) {
- ma->texpaintslot[index].ima = (*mtex)->tex->ima;
- BLI_strncpy(ma->texpaintslot[index++].uvname, (*mtex)->uvname, 64);
+ if (count == 0) {
+ ma->paint_active_slot = 0;
+ return;
+ }
+
+ ma->texpaintslot = MEM_callocN(sizeof(*ma->texpaintslot) * count, "texpaint_slots");
+
+ for(mtex = ma->mtex, i = 0; i < MAX_MTEX; i++, mtex++) {
+ if (get_mtex_slot_valid_texpaint(*mtex)) {
+ ma->texpaintslot[index].ima = (*mtex)->tex->ima;
+ BLI_strncpy(ma->texpaintslot[index++].uvname, (*mtex)->uvname, 64);
+ }
}
}
if (ma->paint_active_slot >= count) {
- ma->paint_active_slot = count - 1;
+ ma->paint_active_slot = count - 1;
}
return;
}
-void refresh_object_texpaint_images(struct Object *ob)
+void refresh_object_texpaint_images(struct Object *ob, bool use_nodes)
{
int i;
@@ -1350,7 +1383,7 @@ void refresh_object_texpaint_images(struct Object *ob)
for (i = 1; i < ob->totcol + 1; i++) {
Material *ma = give_current_material(ob, i);
- refresh_texpaint_image_cache(ma);
+ refresh_texpaint_image_cache(ma, use_nodes);
}
}
diff --git a/source/blender/editors/sculpt_paint/paint_image.c b/source/blender/editors/sculpt_paint/paint_image.c
index a61acb8..5b991e6 100644
--- a/source/blender/editors/sculpt_paint/paint_image.c
+++ b/source/blender/editors/sculpt_paint/paint_image.c
@@ -1410,9 +1410,10 @@ static int texture_paint_toggle_exec(bContext *C, wmOperator *op)
toggle_paint_cursor(C, 0);
}
else {
+ bool use_nodes = BKE_scene_use_new_shading_nodes(scene);
/* This has to stay here to regenerate the texture paint
* cache in case we are loading a file */
- refresh_object_texpaint_images(ob);
+ refresh_object_texpaint_images(ob, use_nodes);
paint_proj_mesh_data_ensure(C, ob);
diff --git a/source/blender/editors/sculpt_paint/paint_image_proj.c b/source/blender/editors/sculpt_paint/paint_image_proj.c
index 41e65fe..a2941b8 100644
--- a/source/blender/editors/sculpt_paint/paint_image_proj.c
+++ b/source/blender/editors/sculpt_paint/paint_image_proj.c
@@ -368,14 +368,9 @@ static Image *project_paint_face_image(const ProjPaintState *ps, int face_index)
static TexPaintSlot *project_paint_face_paint_slot(const ProjPaintState *ps, int face_index)
{
- if (ps->do_new_shading_nodes) { /* cached BKE_scene_use_new_shading_nodes result */
- return NULL;
- }
- else {
- MFace *mf = ps->dm_mface + face_index;
- Material *ma = ps->dm->mat[mf->mat_nr];
- return &ma->texpaintslot[ma->paint_active_slot];
- }
+ MFace *mf = ps->dm_mface + face_index;
+ Material *ma = ps->dm->mat[mf->mat_nr];
+ return &ma->texpaintslot[ma->paint_active_slot];
}
@@ -4808,9 +4803,11 @@ static EnumPropertyItem layer_type_items[] = {
bool proj_paint_add_slot(bContext *C, int type, Material *ma)
{
Object *ob = CTX_data_active_object(C);
+ Scene *scene = CTX_data_scene(C);
float color[4] = {0.0, 0.0, 0.0, 1.0};
int i;
ImagePaintSettings *imapaint = &CTX_data_tool_settings(C)->imapaint;
+ bool use_nodes = BKE_scene_use_new_shading_nodes(scene);
int width;
int height;
@@ -4830,43 +4827,49 @@ bool proj_paint_add_slot(bContext *C, int type, Material *ma)
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) {
- char imagename[FILE_MAX];
- char name[TEXNAME_MAX];
- Main *bmain = CTX_data_main(C);
- Image *ima;
-
- /* get the name of the texture layer type */
- for (i = 0; i < sizeof(layer_type_items); i++) {
- if (type == layer_type_items[i].value) {
- BLI_strncpy(name, layer_type_items[i].name, TEXNAME_MAX);
- break;
+
+ if (use_nodes) {
+ /* not supported for now */
+ }
+ else {
+ MTex *mtex = add_mtex_id(&ma->id, -1);
+
+ /* successful creation of mtex layer, now create set */
+ if (mtex) {
+ char imagename[FILE_MAX];
+ char name[TEXNAME_MAX];
+ Main *bmain = CTX_data_main(C);
+ Image *ima;
+
+ /* get the name of the texture layer type */
+ for (i = 0; i < sizeof(layer_type_items); i++) {
+ if (type == layer_type_items[i].value) {
+ BLI_strncpy(name, layer_type_items[i].name, TEXNAME_MAX);
+ break;
+ }
}
- }
- mtex->tex = add_texture(bmain, DATA_(name));
- mtex->mapto = type;
+ mtex->tex = add_texture(bmain, DATA_(name));
+ mtex->mapto = type;
- if (mtex->tex) {
- BLI_strncpy(imagename, &ma->id.name[2], FILE_MAX);
- BLI_strncat_utf8(imagename, "_", FILE_MAX);
- BLI_strncat_utf8(imagename, name, FILE_MAX);
- /* take the second letter to avoid the ID identifier */
+ if (mtex->tex) {
+ BLI_strncpy(imagename, &ma->id.name[2], FILE_MAX);
+ BLI_strncat_utf8(imagename, "_", FILE_MAX);
+ BLI_strncat_utf8(imagename, name, FILE_MAX);
+ /* take the second letter to avoid the ID identifier */
- ima = mtex->tex->ima = BKE_image_add_generated(bmain, width, height, imagename, 32, type == MAP_NORM, IMA_GENTYPE_BLANK, color);
+ ima = mtex->tex->ima = BKE_image_add_generated(bmain, width, height, imagename, 32, type == MAP_NORM, IMA_GENTYPE_BLANK, color);
- refresh_texpaint_image_cache(ma);
- 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_IMAGE | NA_ADDED, ima);
- ED_area_tag_redraw(CTX_wm_area(C));
- }
+ refresh_texpaint_image_cache(ma, false);
+ 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_IMAGE | NA_ADDED, ima);
+ ED_area_tag_redraw(CTX_wm_area(C));
+ }
- WM_event_add_notifier(C, NC_TEXTURE, CTX_data_scene(C));
- return true;
+ WM_event_add_notifier(C, NC_TEXTURE, CTX_data_scene(C));
+ return true;
+ }
}
}
diff --git a/source/blender/editors/uvedit/uvedit_ops.c b/source/blender/editors/uvedit/uvedit_ops.c
index 0706ac3..5cd917f 100644
--- a/source/blender/editors/uvedit/uvedit_ops.c
+++ b/source/blender/editors/uvedit/uvedit_ops.c
@@ -149,7 +149,7 @@ bool ED_object_get_active_image(Object *ob, int mat_nr,
if (r_node) *r_node = node;
return true;
}
-
+
if (r_ima) *r_ima = NULL;
if (r_iuser) *r_iuser = NULL;
if (r_node) *r_node = node;
diff --git a/source/blender/makesrna/intern/rna_material.c b/source/blender/makesrna/intern/rna_material.c
index 587a2d6..5a21d6a 100644
--- a/sou
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list