svn merge ^/trunk/blender -r42009:42053
[blender.git] / source / blender / editors / render / render_shading.c
index 72506e8..ba73bbd 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * $Id$
- *
  * ***** BEGIN GPL LICENSE BLOCK *****
  *
  * This program is free software; you can redistribute it and/or
@@ -28,7 +26,6 @@
  *  \ingroup edrend
  */
 
-
 #include <stdlib.h>
 #include <string.h>
 
@@ -47,7 +44,6 @@
 #include "BLI_blenlib.h"
 #include "BLI_math.h"
 #include "BLI_editVert.h"
-#include "BLI_listbase.h"
 #include "BLI_utildefines.h"
 
 #include "BKE_animsys.h"
@@ -80,6 +76,7 @@
 
 #include "ED_curve.h"
 #include "ED_mesh.h"
+#include "ED_node.h"
 #include "ED_render.h"
 #include "ED_screen.h"
 
@@ -366,16 +363,24 @@ void OBJECT_OT_material_slot_copy(wmOperatorType *ot)
 
 static int new_material_exec(bContext *C, wmOperator *UNUSED(op))
 {
+       Scene *scene= CTX_data_scene(C);
        Material *ma= CTX_data_pointer_get_type(C, "material", &RNA_Material).data;
        PointerRNA ptr, idptr;
        PropertyRNA *prop;
 
        /* add or copy material */
-       if(ma)
+       if(ma) {
                ma= copy_material(ma);
-       else
+       }
+       else {
                ma= add_material("Material");
 
+               if(scene_use_new_shading_nodes(scene)) {
+                       ED_node_shader_default(scene, &ma->id);
+                       ma->use_nodes= 1;
+               }
+       }
+
        /* hook into UI */
        uiIDContextProperty(C, &ptr, &prop);
 
@@ -458,16 +463,24 @@ void TEXTURE_OT_new(wmOperatorType *ot)
 
 static int new_world_exec(bContext *C, wmOperator *UNUSED(op))
 {
+       Scene *scene= CTX_data_scene(C);
        World *wo= CTX_data_pointer_get_type(C, "world", &RNA_World).data;
        PointerRNA ptr, idptr;
        PropertyRNA *prop;
 
        /* add or copy world */
-       if(wo)
+       if(wo) {
                wo= copy_world(wo);
-       else
+       }
+       else {
                wo= add_world("World");
 
+               if(scene_use_new_shading_nodes(scene)) {
+                       ED_node_shader_default(scene, &wo->id);
+                       wo->use_nodes= 1;
+               }
+       }
+
        /* hook into UI */
        uiIDContextProperty(C, &ptr, &prop);
 
@@ -506,7 +519,7 @@ static int render_layer_add_exec(bContext *C, wmOperator *UNUSED(op))
 {
        Scene *scene= CTX_data_scene(C);
 
-       scene_add_render_layer(scene);
+       scene_add_render_layer(scene, NULL);
        scene->r.actlay= BLI_countlist(&scene->r.layers) - 1;
 
        WM_event_add_notifier(C, NC_SCENE|ND_RENDER_OPTIONS, scene);
@@ -530,32 +543,11 @@ void SCENE_OT_render_layer_add(wmOperatorType *ot)
 
 static int render_layer_remove_exec(bContext *C, wmOperator *UNUSED(op))
 {
-       Scene *scene = CTX_data_scene(C), *sce;
-       SceneRenderLayer *rl;
-       int act= scene->r.actlay;
+       Scene *scene = CTX_data_scene(C);
+       SceneRenderLayer *rl = BLI_findlink(&scene->r.layers, scene->r.actlay);
 
-       if(BLI_countlist(&scene->r.layers) <= 1)
+       if(!scene_remove_render_layer(CTX_data_main(C), scene, rl))
                return OPERATOR_CANCELLED;
-       
-       rl= BLI_findlink(&scene->r.layers, scene->r.actlay);
-       BLI_remlink(&scene->r.layers, rl);
-       MEM_freeN(rl);
-
-       scene->r.actlay= 0;
-
-       for(sce = CTX_data_main(C)->scene.first; sce; sce = sce->id.next) {
-               if(sce->nodetree) {
-                       bNode *node;
-                       for(node = sce->nodetree->nodes.first; node; node = node->next) {
-                               if(node->type==CMP_NODE_R_LAYERS && (Scene*)node->id==scene) {
-                                       if(node->custom1==act)
-                                               node->custom1= 0;
-                                       else if(node->custom1>act)
-                                               node->custom1--;
-                               }
-                       }
-               }
-       }
 
        WM_event_add_notifier(C, NC_SCENE|ND_RENDER_OPTIONS, scene);
        
@@ -666,7 +658,7 @@ void TEXTURE_OT_slot_move(wmOperatorType *ot)
 
 /********************** environment map operators *********************/
 
-static int save_envmap(wmOperator *op, Scene *scene, EnvMap *env, char *path, int imtype)
+static int save_envmap(wmOperator *op, Scene *scene, EnvMap *env, char *path, const char imtype)
 {
        float layout[12];
        if ( RNA_struct_find_property(op->ptr, "layout") )
@@ -688,7 +680,7 @@ static int envmap_save_exec(bContext *C, wmOperator *op)
        Tex *tex= CTX_data_pointer_get_type(C, "texture", &RNA_Texture).data;
        Scene *scene = CTX_data_scene(C);
        //int imtype = RNA_enum_get(op->ptr, "file_type");
-       int imtype = scene->r.imtype;
+       char imtype = scene->r.im_format.imtype;
        char path[FILE_MAX];
        
        RNA_string_get(op->ptr, "filepath", path);
@@ -715,7 +707,7 @@ static int envmap_save_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event
        if(RNA_property_is_set(op->ptr, "filepath"))
                return envmap_save_exec(C, op);
 
-       //RNA_enum_set(op->ptr, "file_type", scene->r.imtype);
+       //RNA_enum_set(op->ptr, "file_type", scene->r.im_format.imtype);
        RNA_string_set(op->ptr, "filepath", G.main->name);
        WM_event_add_fileselect(C, op);