UI: Improve default position of shader nodes
After creating a new shading material, the new node tree might become invisible and the user has to scroll down to see the nodes. The idea of this PR is to create nodes with x-positions centered around zero, such that they are always visible no matter the screen size or workspace setup. Ideally, the nodes' position should depend on the region's zoom and pan. However, the node creation code currently does not depend on `SpaceNode`, so such solution would complicate the code a bit. Also, this heuristic seem to work well enough for most cases. Note: this only affects newly created materials. The material of the default cube and the default world material still have invisible nodes sometimes. This is because they are saved in the startup file, which will be addressed in a different patch. Pull Request: https://projects.blender.org/blender/blender/pulls/136926
This commit is contained in:
@@ -1937,17 +1937,17 @@ void BKE_linestyle_default_shader(const bContext *C, FreestyleLineStyle *linesty
|
||||
nullptr, &linestyle->id, "stroke_shader", "ShaderNodeTree");
|
||||
|
||||
uv_along_stroke = blender::bke::node_add_static_node(C, *ntree, SH_NODE_UVALONGSTROKE);
|
||||
uv_along_stroke->location[0] = 0.0f;
|
||||
uv_along_stroke->location[1] = 300.0f;
|
||||
uv_along_stroke->location[0] = -200.0f;
|
||||
uv_along_stroke->location[1] = 100.0f;
|
||||
uv_along_stroke->custom1 = 0; /* use_tips */
|
||||
|
||||
input_texture = blender::bke::node_add_static_node(C, *ntree, SH_NODE_TEX_IMAGE);
|
||||
input_texture->location[0] = 200.0f;
|
||||
input_texture->location[1] = 300.0f;
|
||||
input_texture->location[0] = 0.0f;
|
||||
input_texture->location[1] = 100.0f;
|
||||
|
||||
output_linestyle = blender::bke::node_add_static_node(C, *ntree, SH_NODE_OUTPUT_LINESTYLE);
|
||||
output_linestyle->location[0] = 400.0f;
|
||||
output_linestyle->location[1] = 300.0f;
|
||||
output_linestyle->location[0] = 300.0f;
|
||||
output_linestyle->location[1] = 100.0f;
|
||||
output_linestyle->custom1 = MA_RAMP_BLEND;
|
||||
output_linestyle->custom2 = 0; /* use_clamp */
|
||||
|
||||
|
||||
@@ -2056,10 +2056,10 @@ static void material_default_surface_init(Material *ma)
|
||||
*output,
|
||||
*blender::bke::node_find_socket(*output, SOCK_IN, "Surface"));
|
||||
|
||||
principled->location[0] = 10.0f;
|
||||
principled->location[1] = 300.0f;
|
||||
output->location[0] = 300.0f;
|
||||
output->location[1] = 300.0f;
|
||||
principled->location[0] = -200.0f;
|
||||
principled->location[1] = 100.0f;
|
||||
output->location[0] = 200.0f;
|
||||
output->location[1] = 100.0f;
|
||||
|
||||
blender::bke::node_set_active(*ntree, *output);
|
||||
}
|
||||
@@ -2082,10 +2082,10 @@ static void material_default_volume_init(Material *ma)
|
||||
*output,
|
||||
*blender::bke::node_find_socket(*output, SOCK_IN, "Volume"));
|
||||
|
||||
principled->location[0] = 10.0f;
|
||||
principled->location[1] = 300.0f;
|
||||
output->location[0] = 300.0f;
|
||||
output->location[1] = 300.0f;
|
||||
principled->location[0] = -200.0f;
|
||||
principled->location[1] = 100.0f;
|
||||
output->location[0] = 200.0f;
|
||||
output->location[1] = 100.0f;
|
||||
|
||||
blender::bke::node_set_active(*ntree, *output);
|
||||
}
|
||||
|
||||
@@ -627,10 +627,10 @@ void ED_node_shader_default(const bContext *C, ID *id)
|
||||
*blender::bke::node_find_socket(*output, SOCK_IN, "Surface"));
|
||||
}
|
||||
|
||||
shader->location[0] = 10.0f;
|
||||
shader->location[1] = 300.0f;
|
||||
output->location[0] = 300.0f;
|
||||
output->location[1] = 300.0f;
|
||||
shader->location[0] = -200.0f;
|
||||
shader->location[1] = 100.0f;
|
||||
output->location[0] = 200.0f;
|
||||
output->location[1] = 100.0f;
|
||||
blender::bke::node_set_active(*ntree, *output);
|
||||
BKE_ntree_update_after_single_tree_change(*bmain, *ntree);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user