Revision: 41204
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=41204
Author:   blendix
Date:     2011-10-22 18:51:45 +0000 (Sat, 22 Oct 2011)
Log Message:
-----------
Cycles: when creating nodes from a blender material, set the diffuse color in
the diffuse node, similar for lamps and world.

Modified Paths:
--------------
    branches/cycles/intern/cycles/blender/addon/ui.py
    branches/cycles/source/blender/editors/space_node/node_edit.c

Modified: branches/cycles/intern/cycles/blender/addon/ui.py
===================================================================
--- branches/cycles/intern/cycles/blender/addon/ui.py   2011-10-22 18:08:26 UTC 
(rev 41203)
+++ branches/cycles/intern/cycles/blender/addon/ui.py   2011-10-22 18:51:45 UTC 
(rev 41204)
@@ -348,7 +348,7 @@
 
 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 @@
 
     @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 @@
 
     @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 @@
 
     @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

Modified: branches/cycles/source/blender/editors/space_node/node_edit.c
===================================================================
--- branches/cycles/source/blender/editors/space_node/node_edit.c       
2011-10-22 18:08:26 UTC (rev 41203)
+++ branches/cycles/source/blender/editors/space_node/node_edit.c       
2011-10-22 18:51:45 UTC (rev 41204)
@@ -283,16 +283,18 @@
 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 @@
                                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 @@
        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;
                }
        }
        

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to