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>2018-10-05 16:57:50 +0300
committerBrecht Van Lommel <brechtvanlommel@gmail.com>2018-10-05 21:09:59 +0300
commit84f8862b06ddcc4aca87492414cacdd583396e73 (patch)
tree8abfcda8b5d1dc34727b597cf5ebdcc4fdf27b5a /source/blender/editors/sculpt_paint/paint_image_proj.c
parent975af239ed6dcc7ad987f06df171dc2f7be884d0 (diff)
Texture Paint: automatically set default color when adding texture slot.
Diffstat (limited to 'source/blender/editors/sculpt_paint/paint_image_proj.c')
-rw-r--r--source/blender/editors/sculpt_paint/paint_image_proj.c60
1 files changed, 58 insertions, 2 deletions
diff --git a/source/blender/editors/sculpt_paint/paint_image_proj.c b/source/blender/editors/sculpt_paint/paint_image_proj.c
index 898826ff273..b5f9104f023 100644
--- a/source/blender/editors/sculpt_paint/paint_image_proj.c
+++ b/source/blender/editors/sculpt_paint/paint_image_proj.c
@@ -5660,6 +5660,57 @@ static Image *proj_paint_image_create(wmOperator *op, Main *bmain)
return ima;
}
+static void proj_paint_default_color(wmOperator *op, int type, Material *ma)
+{
+ if (RNA_struct_property_is_set(op->ptr, "color")) {
+ return;
+ }
+
+ bNode *in_node = ntreeFindType(ma->nodetree, SH_NODE_BSDF_PRINCIPLED);
+ if (in_node == NULL) {
+ return;
+ }
+
+ float color[4];
+
+ if (type >= LAYER_BASE_COLOR && type < LAYER_NORMAL) {
+ /* Copy color from node, so result is unchanged after assigning textures. */
+ bNodeSocket *in_sock = nodeFindSocket(in_node, SOCK_IN, layer_type_items[type].name);
+
+ switch (in_sock->type) {
+ case SOCK_FLOAT: {
+ bNodeSocketValueFloat *socket_data = in_sock->default_value;
+ copy_v3_fl(color, socket_data->value);
+ color[3] = 1.0f;
+ break;
+ }
+ case SOCK_VECTOR:
+ case SOCK_RGBA: {
+ bNodeSocketValueRGBA *socket_data = in_sock->default_value;
+ copy_v3_v3(color, socket_data->value);
+ color[3] = 1.0f;
+ break;
+ }
+ default: {
+ return;
+ }
+ }
+ }
+ else if (type == LAYER_NORMAL) {
+ /* Neutral tangent space normal map. */
+ rgba_float_args_set(color, 0.5f, 0.5f, 1.0f, 1.0f);
+ }
+ else if (ELEM(type, LAYER_BUMP, LAYER_DISPLACEMENT)) {
+ /* Neutral displacement and bump map. */
+ rgba_float_args_set(color, 0.5f, 0.5f, 0.5f, 1.0f);
+ }
+ else {
+ return;
+ }
+
+ RNA_float_set_array(op->ptr, "color", color);
+}
+
static bool proj_paint_add_slot(bContext *C, wmOperator *op)
{
Object *ob = ED_object_active_context(C);
@@ -5695,9 +5746,8 @@ static bool proj_paint_add_slot(bContext *C, wmOperator *op)
nodeSetActive(ntree, imanode);
/* Connect to first available principled bsdf node. */
- bNode *in_node;
+ bNode *in_node = ntreeFindType(ntree, SH_NODE_BSDF_PRINCIPLED);
bNode *out_node = imanode;
- in_node = ntreeFindType(ntree, SH_NODE_BSDF_PRINCIPLED);
if (in_node != NULL) {
bNodeSocket *out_sock = nodeFindSocket(out_node, SOCK_OUT, "Color");
@@ -5802,6 +5852,12 @@ static int texture_paint_add_texture_paint_slot_invoke(bContext *C, wmOperator *
assign_material(bmain, ob, ma, ob->actcol, BKE_MAT_ASSIGN_USERPREF);
}
+ if (!ma->nodetree) {
+ ED_node_shader_default(C, &ma->id);
+ }
+
+ proj_paint_default_color(op, type, ma);
+
type = RNA_enum_from_value(layer_type_items, type);
/* get the name of the texture layer type */