Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrecht Van Lommel <brechtvanlommel@gmail.com>2019-02-28 16:09:19 +0300
committerBrecht Van Lommel <brechtvanlommel@gmail.com>2019-02-28 21:17:16 +0300
commitda1323d1c95095feff98e8aa054d73fd323c363d (patch)
tree021ec89b4a50696ba8b6ae02df82f278354812cf /source/blender/blenkernel
parentacd462347196fef9450115f28ac2594cb12b0226 (diff)
Fix T60366: texture paint slots not updating when editing material.
Now always refresh when the material changes. Depsgraph tag moved out of the refresh function since that gets called on depsgraph update, which should not trigger a second depsgraph update.
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r--source/blender/blenkernel/BKE_material.h4
-rw-r--r--source/blender/blenkernel/intern/material.c83
2 files changed, 33 insertions, 54 deletions
diff --git a/source/blender/blenkernel/BKE_material.h b/source/blender/blenkernel/BKE_material.h
index 1c171ef6e7c..84760a522f3 100644
--- a/source/blender/blenkernel/BKE_material.h
+++ b/source/blender/blenkernel/BKE_material.h
@@ -83,8 +83,8 @@ bool BKE_object_material_slot_remove(struct Main *bmain, struct Object *ob);
struct MaterialGPencilStyle *BKE_material_gpencil_settings_get(struct Object *ob, short act);
-void BKE_texpaint_slot_refresh_cache(struct Scene *scene, struct Material *ma);
-void BKE_texpaint_slots_refresh_object(struct Scene *scene, struct Object *ob);
+void BKE_texpaint_slot_refresh_cache(struct Material *ma);
+void BKE_texpaint_slots_refresh_object(struct Object *ob);
/* rna api */
void BKE_material_resize_id(struct Main *bmain, struct ID *id, short totcol, bool do_id_user);
diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c
index f6bd5a8cd06..138a6426b39 100644
--- a/source/blender/blenkernel/intern/material.c
+++ b/source/blender/blenkernel/intern/material.c
@@ -228,6 +228,7 @@ Material *BKE_material_localize(Material *ma)
Material *man = BKE_libblock_copy_for_localize(&ma->id);
man->texpaintslot = NULL;
+ man->tot_slots = 0;
man->preview = NULL;
if (ma->nodetree != NULL) {
@@ -1046,7 +1047,7 @@ static int count_texture_nodes_recursive(bNodeTree *nodetree)
return tex_nodes;
}
-static void fill_texpaint_slots_recursive(bNodeTree *nodetree, bNode *active_node, Material *ma, int *index)
+static void fill_texpaint_slots_recursive(bNodeTree *nodetree, bNode *active_node, Material *ma, TexPaintSlot *slots, int *index)
{
for (bNode *node = nodetree->nodes.first; node; node = node->next) {
if (node->typeinfo->nclass == NODE_CLASS_TEXTURE && node->typeinfo->type == SH_NODE_TEX_IMAGE && node->id) {
@@ -1054,99 +1055,77 @@ static void fill_texpaint_slots_recursive(bNodeTree *nodetree, bNode *active_nod
ma->paint_active_slot = *index;
}
- ma->texpaintslot[*index].ima = (Image *)node->id;
- ma->texpaintslot[*index].interp = ((NodeTexImage *)node->storage)->interpolation;
+ slots[*index].ima = (Image *)node->id;
+ slots[*index].interp = ((NodeTexImage *)node->storage)->interpolation;
/* for new renderer, we need to traverse the treeback in search of a UV node */
bNode *uvnode = nodetree_uv_node_recursive(node);
if (uvnode) {
NodeShaderUVMap *storage = (NodeShaderUVMap *)uvnode->storage;
- ma->texpaintslot[*index].uvname = storage->uv_map;
+ slots[*index].uvname = storage->uv_map;
/* set a value to index so UI knows that we have a valid pointer for the mesh */
- ma->texpaintslot[*index].valid = true;
+ slots[*index].valid = true;
}
else {
/* just invalidate the index here so UV map does not get displayed on the UI */
- ma->texpaintslot[*index].valid = false;
+ slots[*index].valid = false;
}
(*index)++;
}
else if (node->type == NODE_GROUP) {
/* recurse into the node group and see if it contains any textures */
- fill_texpaint_slots_recursive((bNodeTree *)node->id, active_node, ma, index);
+ fill_texpaint_slots_recursive((bNodeTree *)node->id, active_node, ma, slots, index);
}
}
}
-void BKE_texpaint_slot_refresh_cache(Scene *scene, Material *ma)
+void BKE_texpaint_slot_refresh_cache(Material *ma)
{
- int count = 0;
- int index = 0;
-
- if (!ma)
- return;
-
- /* COW needed when adding texture slot on an object with no materials. */
- DEG_id_tag_update(&ma->id, ID_RECALC_SHADING | ID_RECALC_COPY_ON_WRITE);
-
- if (ma->texpaintslot) {
- MEM_freeN(ma->texpaintslot);
- ma->tot_slots = 0;
- ma->texpaintslot = NULL;
- }
-
- if (scene->toolsettings->imapaint.mode == IMAGEPAINT_MODE_IMAGE) {
- ma->paint_active_slot = 0;
- ma->paint_clone_slot = 0;
+ if (ma == NULL) {
return;
}
- if (!(ma->nodetree)) {
- ma->paint_active_slot = 0;
- ma->paint_clone_slot = 0;
- return;
- }
+ /* Compute texture paint slots. */
+ TexPaintSlot *texpaintslot = NULL;
+ int tot_slots = (ma->nodetree) ? count_texture_nodes_recursive(ma->nodetree) : 0;
- count = count_texture_nodes_recursive(ma->nodetree);
+ if (tot_slots) {
+ texpaintslot = MEM_callocN(sizeof(*texpaintslot) * tot_slots, "texpaint_slots");
- if (count == 0) {
- ma->paint_active_slot = 0;
- ma->paint_clone_slot = 0;
- return;
+ bNode *active_node = nodeGetActiveTexture(ma->nodetree);
+ int index = 0;
+ fill_texpaint_slots_recursive(ma->nodetree, active_node, ma, texpaintslot, &index);
}
- ma->texpaintslot = MEM_callocN(sizeof(*ma->texpaintslot) * count, "texpaint_slots");
-
- bNode *active_node = nodeGetActiveTexture(ma->nodetree);
-
- fill_texpaint_slots_recursive(ma->nodetree, active_node, ma, &index);
-
- ma->tot_slots = count;
-
+ /* Keep active slots within range. */
+ if (ma->paint_active_slot >= tot_slots) {
+ ma->paint_active_slot = MAX2(tot_slots - 1, 0);
+ }
- if (ma->paint_active_slot >= count) {
- ma->paint_active_slot = count - 1;
+ if (ma->paint_clone_slot >= tot_slots) {
+ ma->paint_clone_slot = MAX2(tot_slots - 1, 0);
}
- if (ma->paint_clone_slot >= count) {
- ma->paint_clone_slot = count - 1;
+ /* Replace slots. */
+ if (ma->texpaintslot) {
+ MEM_freeN(ma->texpaintslot);
}
- return;
+ ma->texpaintslot = texpaintslot;
+ ma->tot_slots = tot_slots;
}
-void BKE_texpaint_slots_refresh_object(Scene *scene, struct Object *ob)
+void BKE_texpaint_slots_refresh_object(struct Object *ob)
{
int i;
for (i = 1; i < ob->totcol + 1; i++) {
Material *ma = give_current_material(ob, i);
- BKE_texpaint_slot_refresh_cache(scene, ma);
+ BKE_texpaint_slot_refresh_cache(ma);
}
}
-
/* r_col = current value, col = new value, (fac == 0) is no change */
void ramp_blend(int type, float r_col[3], const float fac, const float col[3])
{