svn merge ^/trunk/blender -r42009:42053
[blender.git] / source / blender / editors / render / render_shading.c
index 582a859..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>
 
@@ -65,6 +62,7 @@
 #include "BKE_scene.h"
 #include "BKE_texture.h"
 #include "BKE_world.h"
+#include "BKE_tessmesh.h"
 
 #include "IMB_imbuf.h"
 #include "IMB_imbuf_types.h"
@@ -78,6 +76,7 @@
 
 #include "ED_curve.h"
 #include "ED_mesh.h"
+#include "ED_node.h"
 #include "ED_render.h"
 #include "ED_screen.h"
 
@@ -165,13 +164,15 @@ static int material_slot_assign_exec(bContext *C, wmOperator *UNUSED(op))
 
        if(ob && ob->actcol>0) {
                if(ob->type == OB_MESH) {
-                       EditMesh *em= ((Mesh*)ob->data)->edit_mesh;
-                       EditFace *efa;
+                       BMEditMesh *em= ((Mesh*)ob->data)->edit_btmesh;
+                       BMFace *efa;
+                       BMIter iter;
 
                        if(em) {
-                               for(efa= em->faces.first; efa; efa=efa->next)
-                                       if(efa->f & SELECT)
+                               BM_ITER(efa, &iter, em->bm, BM_FACES_OF_MESH, NULL) {
+                                       if(BM_TestHFlag(efa, BM_SELECT))
                                                efa->mat_nr= ob->actcol-1;
+                               }
                        }
                }
                else if(ELEM(ob->type, OB_CURVE, OB_SURF)) {
@@ -224,13 +225,10 @@ static int material_slot_de_select(bContext *C, int select)
                return OPERATOR_CANCELLED;
 
        if(ob->type == OB_MESH) {
-               EditMesh *em= ((Mesh*)ob->data)->edit_mesh;
+               BMEditMesh *em= ((Mesh*)ob->data)->edit_btmesh;
 
                if(em) {
-                       if(select)
-                               EM_select_by_material(em, ob->actcol-1);
-                       else
-                               EM_deselect_by_material(em, ob->actcol-1);
+                       EDBM_deselect_by_material(em, ob->actcol-1, select);
                }
        }
        else if ELEM(ob->type, OB_CURVE, OB_SURF) {
@@ -365,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);
 
@@ -457,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);
 
@@ -505,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);
@@ -529,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);
        
@@ -665,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") )
@@ -687,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);
@@ -714,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);