From 586c631c88d7a4ea24810bf18ab96ed7ec542d37 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Sat, 22 Oct 2011 18:51:45 +0000 Subject: Cycles: when creating nodes from a blender material, set the diffuse color in the diffuse node, similar for lamps and world. --- intern/cycles/blender/addon/ui.py | 11 ++++--- source/blender/editors/space_node/node_edit.c | 46 ++++++++++++++++++++------- 2 files changed, 41 insertions(+), 16 deletions(-) diff --git a/intern/cycles/blender/addon/ui.py b/intern/cycles/blender/addon/ui.py index 94a48e6c42d..d894f66c32e 100644 --- a/intern/cycles/blender/addon/ui.py +++ b/intern/cycles/blender/addon/ui.py @@ -348,7 +348,7 @@ def find_node_input(node, name): def panel_node_draw(layout, id, output_type, input_name): if not id.node_tree: - layout.prop(id, "use_nodes") + layout.prop(id, "use_nodes", icon='NODETREE') return ntree = id.node_tree @@ -435,7 +435,8 @@ class CyclesWorld_PT_volume(CyclesButtonsPanel, Panel): @classmethod def poll(cls, context): - return context.world and CyclesButtonsPanel.poll(context) + world = context.world + return world and world.node_tree and CyclesButtonsPanel.poll(context) def draw(self, context): layout = self.layout @@ -465,7 +466,8 @@ class CyclesMaterial_PT_volume(CyclesButtonsPanel, Panel): @classmethod def poll(cls, context): - return context.material and CyclesButtonsPanel.poll(context) + mat = context.material + return mat and mat.node_tree and CyclesButtonsPanel.poll(context) def draw(self, context): layout = self.layout @@ -484,7 +486,8 @@ class CyclesMaterial_PT_displacement(CyclesButtonsPanel, Panel): @classmethod def poll(cls, context): - return context.material and CyclesButtonsPanel.poll(context) + mat = context.material + return mat and mat.node_tree and CyclesButtonsPanel.poll(context) def draw(self, context): layout = self.layout diff --git a/source/blender/editors/space_node/node_edit.c b/source/blender/editors/space_node/node_edit.c index 10c5ca7ee1a..83f15243ebe 100644 --- a/source/blender/editors/space_node/node_edit.c +++ b/source/blender/editors/space_node/node_edit.c @@ -283,16 +283,18 @@ bNode *node_tree_get_editgroup(bNodeTree *nodetree) void ED_node_shader_default(Scene *scene, ID *id) { bNode *in, *out; - bNodeSocket *fromsock, *tosock; + bNodeSocket *fromsock, *tosock, *sock; bNodeTree *ntree; bNodeTemplate ntemp; int output_type, shader_type; + float color[3], strength = 1.0f; ntree= ntreeAddTree("Shader Nodetree", NTREE_SHADER, 0); switch(GS(id->name)) { - case ID_MA: - ((Material*)id)->nodetree = ntree; + case ID_MA: { + Material *ma= (Material*)id; + ma->nodetree = ntree; if(scene_use_new_shading_nodes(scene)) { output_type = SH_NODE_OUTPUT_MATERIAL; @@ -302,17 +304,36 @@ void ED_node_shader_default(Scene *scene, ID *id) output_type = SH_NODE_OUTPUT; shader_type = SH_NODE_MATERIAL; } + + copy_v3_v3(color, &ma->r); + strength= 0.0f; break; - case ID_WO: - ((World*)id)->nodetree = ntree; + } + case ID_WO: { + World *wo= (World*)id; + + wo->nodetree = ntree; output_type = SH_NODE_OUTPUT_WORLD; shader_type = SH_NODE_BACKGROUND; + + copy_v3_v3(color, &wo->horr); + strength= 1.0f; break; - case ID_LA: + } + case ID_LA: { + Lamp *la= (Lamp*)id; + ((Lamp*)id)->nodetree = ntree; output_type = SH_NODE_OUTPUT_LAMP; shader_type = SH_NODE_EMISSION; + + copy_v3_v3(color, &la->r); + if(la->type == LA_LOCAL || la->type == LA_SPOT || la->type == LA_AREA) + strength= 100.0f; + else + strength= 1.0f; break; + } default: printf("ED_node_shader_default called on wrong ID type.\n"); return; @@ -332,13 +353,14 @@ void ED_node_shader_default(Scene *scene, ID *id) tosock= out->inputs.first; nodeAddLink(ntree, in, fromsock, out, tosock); - if(GS(id->name) == ID_LA) { - Lamp *la= (Lamp*)id; + /* default values */ + if(scene_use_new_shading_nodes(scene)) { + sock= in->inputs.first; + copy_v3_v3(((bNodeSocketValueRGBA*)sock->default_value)->value, color); - if(la->type == LA_LOCAL || la->type == LA_SPOT || la->type == LA_AREA) { - bNodeSocket *sock= in->inputs.last; - bNodeSocketValueFloat *default_value= sock->default_value; - default_value->value= 100.0f; + if(strength != 0.0f) { + sock= in->inputs.last; + ((bNodeSocketValueFloat*)sock->default_value)->value= strength; } } -- cgit v1.2.3