Cycles: when creating nodes from a blender material, set the diffuse color in
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Sat, 22 Oct 2011 18:51:45 +0000 (18:51 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Sat, 22 Oct 2011 18:51:45 +0000 (18:51 +0000)
the diffuse node, similar for lamps and world.

intern/cycles/blender/addon/ui.py
source/blender/editors/space_node/node_edit.c

index 94a48e6c42d02c68f959ceedffe63beff001de2c..d894f66c32ee77306f884cfa55029d41153243cf 100644 (file)
@@ -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
index 10c5ca7ee1a8bf655f021b1b6b40bf9fc6fda599..83f15243ebe000c1f5dfde51fb187c3ba05920c7 100644 (file)
@@ -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;
                }
        }