committed Tamito Kajiyama's RNA and GUI patch for Freestyle integration into Blender...
authorMaxime Curioni <maxime.curioni@gmail.com>
Wed, 7 Oct 2009 05:16:23 +0000 (05:16 +0000)
committerMaxime Curioni <maxime.curioni@gmail.com>
Wed, 7 Oct 2009 05:16:23 +0000 (05:16 +0000)
release/scripts/ui/buttons_scene.py
source/blender/editors/CMakeLists.txt
source/blender/editors/render/SConscript
source/blender/editors/render/render_intern.h
source/blender/editors/render/render_ops.c
source/blender/editors/render/render_shading.c
source/blender/freestyle/FRS_freestyle.h
source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp
source/blender/makesdna/DNA_freestyle_types.h
source/blender/makesrna/RNA_access.h
source/blender/makesrna/intern/rna_scene.c

index 666bbacea5004938eb51f31f6565474f971b1f93..e6091af9f006356003157e63afe7998455fff136 100644 (file)
@@ -80,11 +80,12 @@ class SCENE_PT_layers(RenderButtonsPanel):
                col.itemR(rl, "solid")
                col.itemR(rl, "halo")
                col.itemR(rl, "ztransp")
+               col.itemR(rl, "sky")
 
                col = split.column()
-               col.itemR(rl, "sky")
                col.itemR(rl, "edge")
                col.itemR(rl, "strand")
+               col.itemR(rl, "freestyle")
 
                if rl.zmask:
                        split = layout.split()
@@ -125,6 +126,33 @@ class SCENE_PT_layers(RenderButtonsPanel):
                row.itemR(rl, "pass_refraction")
                row.itemR(rl, "pass_refraction_exclude", text="", icon='ICON_X')
 
+               if rl.freestyle:
+                       layout.itemS()
+
+                       split = layout.split()
+
+                       col = split.column()
+                       col.itemL(text="Freestyle:")
+                       freestyle = rl.freestyle_settings
+                       col.itemR(freestyle, "sphere_radius", text="Sphere Radius")
+                       col.itemR(freestyle, "ridges_and_valleys", text="Ridges and Valleys")
+                       col.itemR(freestyle, "suggestive_contours", text="Suggestive Contours")
+                       col.itemR(freestyle, "dkr_epsilon", text="Dkr Epsilon")
+
+                       col.itemO("scene.freestyle_module_add", text="Add Style Module")
+
+                       for i, module in enumerate(freestyle.modules):
+                               box = layout.box()
+                               box.set_context_pointer("freestyle_module", module)
+                               row = box.row(align=True)
+                               row.itemR(module, "is_displayed", text="")
+                               row.itemR(module, "module_path", text="")
+                               row.itemO("scene.freestyle_module_remove", icon='ICON_X', text="")
+                               props = row.itemO("scene.freestyle_module_move_up", icon='VICON_MOVE_UP', text="", properties=True)
+                               props.active = (i > 0)
+                               props = row.itemO("scene.freestyle_module_move_down", icon='VICON_MOVE_DOWN', text="", properties=True)
+                               props.active = (i < len(freestyle.modules) - 1)
+
 class SCENE_PT_shading(RenderButtonsPanel):
        __label__ = "Shading"
        COMPAT_ENGINES = set(['BLENDER_RENDER'])
@@ -224,6 +252,13 @@ class SCENE_PT_post_processing(RenderButtonsPanel):
                sub.itemR(rd, "edge_threshold", text="Threshold", slider=True)
                sub.itemR(rd, "edge_color", text="")
                
+               layout.itemS()
+
+               split = layout.split()
+               col = split.column()
+               col.itemR(rd, "freestyle", text="Freestyle")
+
+
 class SCENE_PT_output(RenderButtonsPanel):
        __label__ = "Output"
        COMPAT_ENGINES = set(['BLENDER_RENDER'])
index d13d7ce2ff25e51bb0f85005d912258a9c6b2ec1..bba441fd2a7a28aa393f328d3c745e985724faf7 100644 (file)
@@ -39,6 +39,7 @@ SET(INC ../windowmanager
        ../../../intern/audaspace/intern
        ../nodes
        ../gpu
+       ../freestyle
        ../blenfont
        ../ikplugin
 )
index bddc5ed10e032ad6b21805031d122553071525d4..ab1c0d1169123d4b1e0a0e77782fac4e0aedf4d1 100644 (file)
@@ -5,7 +5,7 @@ sources = env.Glob('*.c')
 
 incs = '../include ../../blenlib ../../blenkernel ../../makesdna ../../imbuf'
 incs += ' ../../windowmanager #/intern/guardedalloc #/extern/glew/include'
-incs += ' #/intern/guardedalloc ../../gpu'
+incs += ' #/intern/guardedalloc ../../gpu ../../freestyle'
 incs += ' ../../makesrna ../../render/extern/include  #/intern/elbeem/extern'
 incs += ' ../../blenloader'
 
index dccc2d360028ee78660ebb0bb89235dc5deeb690..e62bc175416f38c4aed73822d4af8335f8bfd690 100644 (file)
@@ -44,6 +44,10 @@ void WORLD_OT_new(struct wmOperatorType *ot);
 
 void SCENE_OT_render_layer_add(struct wmOperatorType *ot);
 void SCENE_OT_render_layer_remove(struct wmOperatorType *ot);
+void SCENE_OT_freestyle_module_add(struct wmOperatorType *ot);
+void SCENE_OT_freestyle_module_remove(struct wmOperatorType *ot);
+void SCENE_OT_freestyle_module_move_up(struct wmOperatorType *ot);
+void SCENE_OT_freestyle_module_move_down(struct wmOperatorType *ot);
 
 #endif /* RENDER_INTERN_H */
 
index 8b60582d4662ffe4fd68ac6969e994da1931b019..7935b4f248b0af885da1929ed3686dda1215f3c1 100644 (file)
@@ -50,5 +50,9 @@ void ED_operatortypes_render(void)
 
        WM_operatortype_append(SCENE_OT_render_layer_add);
        WM_operatortype_append(SCENE_OT_render_layer_remove);
+       WM_operatortype_append(SCENE_OT_freestyle_module_add);
+       WM_operatortype_append(SCENE_OT_freestyle_module_remove);
+       WM_operatortype_append(SCENE_OT_freestyle_module_move_up);
+       WM_operatortype_append(SCENE_OT_freestyle_module_move_down);
 }
 
index 56605ad097040acac6213516bcc527eaa062ff6d..815bc8cee0bb8d10235e8331e90dafaa9b096bfa 100644 (file)
@@ -58,6 +58,8 @@
 
 #include "GPU_material.h"
 
+#include "FRS_freestyle.h"
+
 #include "RNA_access.h"
 #include "RNA_enum_types.h"
 
@@ -643,3 +645,122 @@ void SCENE_OT_render_layer_remove(wmOperatorType *ot)
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 }
 
+static int freestyle_module_add_exec(bContext *C, wmOperator *op)
+{
+       Scene *scene= CTX_data_scene(C);
+
+       printf("freestyle_module_add_exec\n");
+       FRS_add_module();
+
+       WM_event_add_notifier(C, NC_SCENE|ND_RENDER_OPTIONS, scene);
+       
+       return OPERATOR_FINISHED;
+}
+
+void SCENE_OT_freestyle_module_add(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Add Freestyle Module";
+       ot->idname= "SCENE_OT_freestyle_module_add";
+       ot->description="Add a style module into the list of modules.";
+       
+       /* api callbacks */
+       ot->exec= freestyle_module_add_exec;
+
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+}
+
+static int freestyle_module_remove_exec(bContext *C, wmOperator *op)
+{
+       Scene *scene= CTX_data_scene(C);
+       PointerRNA ptr= CTX_data_pointer_get_type(C, "freestyle_module", &RNA_FreestyleModuleSettings);
+       FreestyleModuleConfig *module= ptr.data;
+
+       printf("freestyle_module_remove_exec\n");
+       FRS_delete_module(module, NULL);
+
+       WM_event_add_notifier(C, NC_SCENE|ND_RENDER_OPTIONS, scene);
+       
+       return OPERATOR_FINISHED;
+}
+
+void SCENE_OT_freestyle_module_remove(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Remove Freestyle Module";
+       ot->idname= "SCENE_OT_freestyle_module_remove";
+       ot->description="Remove the style module from the stack.";
+       
+       /* api callbacks */
+       ot->exec= freestyle_module_remove_exec;
+
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+}
+
+static int freestyle_module_move_up_exec(bContext *C, wmOperator *op)
+{
+       Scene *scene= CTX_data_scene(C);
+       PointerRNA ptr= CTX_data_pointer_get_type(C, "freestyle_module", &RNA_FreestyleModuleSettings);
+       FreestyleModuleConfig *module= ptr.data;
+       int active = RNA_boolean_get(op->ptr, "active");
+
+       printf("freestyle_module_move_up_exec\n");
+       if(active)
+               FRS_move_up_module(module, NULL);
+
+       WM_event_add_notifier(C, NC_SCENE|ND_RENDER_OPTIONS, scene);
+       
+       return OPERATOR_FINISHED;
+}
+
+void SCENE_OT_freestyle_module_move_up(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Move Up Freestyle Module";
+       ot->idname= "SCENE_OT_freestyle_module_move_up";
+       ot->description="Move the style module up in the stack.";
+       
+       /* api callbacks */
+       ot->exec= freestyle_module_move_up_exec;
+
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+
+       /* props */
+       RNA_def_boolean(ot->srna, "active", 0, "Active", "True if the operator is enabled.");
+}
+
+static int freestyle_module_move_down_exec(bContext *C, wmOperator *op)
+{
+       Scene *scene= CTX_data_scene(C);
+       PointerRNA ptr= CTX_data_pointer_get_type(C, "freestyle_module", &RNA_FreestyleModuleSettings);
+       FreestyleModuleConfig *module= ptr.data;
+       int active = RNA_boolean_get(op->ptr, "active");
+
+       printf("freestyle_module_move_down_exec\n");
+       if(active)
+               FRS_move_down_module(module, NULL);
+
+       WM_event_add_notifier(C, NC_SCENE|ND_RENDER_OPTIONS, scene);
+       
+       return OPERATOR_FINISHED;
+}
+
+void SCENE_OT_freestyle_module_move_down(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Move Down Freestyle Module";
+       ot->idname= "SCENE_OT_freestyle_module_move_down";
+       ot->description="Move the style module down in the stack.";
+       
+       /* api callbacks */
+       ot->exec= freestyle_module_move_down_exec;
+
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+
+       /* props */
+       RNA_def_boolean(ot->srna, "active", 0, "Active", "True if the operator is enabled.");
+}
index 9d20c2c47638d553d9deef61b137af879af2701f..96696b9cc1f54725f412750f0535920241535a0f 100644 (file)
@@ -1,9 +1,6 @@
 #ifndef FRS_FREESTYLE_H
 #define FRS_FREESTYLE_H
 
-#define FREESTYLE_SUGGESTIVE_CONTOURS_FLAG  1
-#define FREESTYLE_RIDGES_AND_VALLEYS_FLAG   2
-
 #ifdef __cplusplus
 extern "C" {
 #endif 
index 74c9e377a15745868b59629a8bbf7feb627057c1..6346c05b0d68a66cc12aa962ef7ee91eb2635d41 100644 (file)
@@ -295,22 +295,22 @@ extern "C" {
        
        void FRS_delete_module(void *module_index_ptr, void *unused)
        {
-               FreestyleModuleConfig* module_conf = (FreestyleModuleConfig*) BLI_findlink(freestyle_modules, (intptr_t)module_index_ptr);
+               FreestyleModuleConfig* module_conf = (FreestyleModuleConfig*) module_index_ptr;
 
                BLI_freelinkN( freestyle_modules, module_conf);
        }
        
        void FRS_move_up_module(void *module_index_ptr, void *unused)
        {
-               FreestyleModuleConfig* module_conf = (FreestyleModuleConfig*) BLI_findlink(freestyle_modules, (intptr_t)module_index_ptr);
-               
+               FreestyleModuleConfig* module_conf = (FreestyleModuleConfig*) module_index_ptr;
+
                BLI_remlink(freestyle_modules, module_conf);
                BLI_insertlink(freestyle_modules, module_conf->prev->prev, module_conf);
        }
        
        void FRS_move_down_module(void *module_index_ptr, void *unused)
        {                       
-               FreestyleModuleConfig* module_conf = (FreestyleModuleConfig*) BLI_findlink(freestyle_modules, (intptr_t)module_index_ptr);
+               FreestyleModuleConfig* module_conf = (FreestyleModuleConfig*) module_index_ptr;
                
                BLI_remlink(freestyle_modules, module_conf);
                BLI_insertlink(freestyle_modules, module_conf->next, module_conf);
index 14c59d5adb23d393f24b42451f69aa0b9c49bc57..fb07f33b533fc1b500905a5a36ec0be438abe194 100644 (file)
@@ -3,6 +3,9 @@
 
 #include "DNA_listBase.h"
 
+#define FREESTYLE_SUGGESTIVE_CONTOURS_FLAG  1
+#define FREESTYLE_RIDGES_AND_VALLEYS_FLAG   2
+
 typedef struct FreestyleModuleConfig {
        struct FreestyleModuleConfig *next, *prev;
        
index 9ea7725b85549e2b7a11171c390a28a9695b1e60..05a17f5eefdc4872bad5fdd5bd503d7684b2943a 100644 (file)
@@ -203,6 +203,7 @@ extern StructRNA RNA_FluidFluidSettings;
 extern StructRNA RNA_FluidSettings;
 extern StructRNA RNA_FluidSimulationModifier;
 extern StructRNA RNA_FollowPathConstraint;
+extern StructRNA RNA_FreestyleModuleSettings;
 extern StructRNA RNA_Function;
 extern StructRNA RNA_GameBooleanProperty;
 extern StructRNA RNA_GameFloatProperty;
index 9eea920e37178f0abb57bfc6b42089f853a20927..c1d2cd802ec72a14b1288ba07597163cfea02c9b 100644 (file)
@@ -711,6 +711,12 @@ void rna_def_render_layer_common(StructRNA *srna, int scene)
        if(scene) RNA_def_property_update(prop, NC_SCENE|ND_RENDER_OPTIONS, NULL);
        else RNA_def_property_clear_flag(prop, PROP_EDITABLE);
 
+       prop= RNA_def_property(srna, "freestyle", PROP_BOOLEAN, PROP_NONE);
+       RNA_def_property_boolean_sdna(prop, NULL, "layflag", SCE_LAY_FRS);
+       RNA_def_property_ui_text(prop, "Freestyle", "Render stylized strokes in this Layer.");
+       if(scene) RNA_def_property_update(prop, NC_SCENE|ND_RENDER_OPTIONS, NULL);
+       else RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+
        /* passes */
        prop= RNA_def_property(srna, "pass_combined", PROP_BOOLEAN, PROP_NONE);
        RNA_def_property_boolean_sdna(prop, NULL, "passflag", SCE_PASS_COMBINED);
@@ -827,6 +833,62 @@ void rna_def_render_layer_common(StructRNA *srna, int scene)
        else RNA_def_property_clear_flag(prop, PROP_EDITABLE);
 }
 
+static void rna_def_freestyle_settings(BlenderRNA *brna)
+{
+       StructRNA *srna;
+       PropertyRNA *prop;
+
+       /* FreestyleModuleSettings */
+
+       srna= RNA_def_struct(brna, "FreestyleModuleSettings", NULL);
+       RNA_def_struct_sdna(srna, "FreestyleModuleConfig");
+       RNA_def_struct_ui_text(srna, "Freestyle Module", "Style module configuration for specifying a style module.");
+
+       prop= RNA_def_property(srna, "module_path", PROP_STRING, PROP_FILEPATH);
+       RNA_def_property_string_sdna(prop, NULL, "module_path");
+       RNA_def_property_ui_text(prop, "Module Path", "Path to a style module file.");
+       RNA_def_property_update(prop, NC_SCENE, NULL);
+
+       prop= RNA_def_property(srna, "is_displayed", PROP_BOOLEAN, PROP_NONE);
+       RNA_def_property_boolean_sdna(prop, NULL, "is_displayed", 1);
+       RNA_def_property_ui_text(prop, "Is Displayed", "Enable this style module during the rendering.");
+       RNA_def_property_update(prop, NC_SCENE, NULL);
+
+       /* FreestyleSettings */
+
+       srna= RNA_def_struct(brna, "FreestyleSettings", NULL);
+       RNA_def_struct_sdna(srna, "FreestyleConfig");
+       RNA_def_struct_nested(brna, srna, "SceneRenderLayer");
+       RNA_def_struct_ui_text(srna, "Frestyle Settings", "Freestyle settings for a SceneRenderLayer datablock.");
+
+       prop= RNA_def_property(srna, "modules", PROP_COLLECTION, PROP_NONE);
+       RNA_def_property_collection_sdna(prop, NULL, "modules", NULL);
+       RNA_def_property_struct_type(prop, "FreestyleModuleSettings");
+       RNA_def_property_ui_text(prop, "Style modules", "A list of style modules (to be applied from top to bottom).");
+
+       prop= RNA_def_property(srna, "suggestive_contours", PROP_BOOLEAN, PROP_NONE);
+       RNA_def_property_boolean_sdna(prop, NULL, "flags", FREESTYLE_SUGGESTIVE_CONTOURS_FLAG);
+       RNA_def_property_ui_text(prop, "Suggestive Contours", "Enable suggestive contours.");
+       RNA_def_property_update(prop, NC_SCENE, NULL);
+
+       prop= RNA_def_property(srna, "ridges_and_valleys", PROP_BOOLEAN, PROP_NONE);
+       RNA_def_property_boolean_sdna(prop, NULL, "flags", FREESTYLE_RIDGES_AND_VALLEYS_FLAG);
+       RNA_def_property_ui_text(prop, "Ridges and Valleys", "Enable ridges and valleys.");
+       RNA_def_property_update(prop, NC_SCENE, NULL);
+
+       prop= RNA_def_property(srna, "sphere_radius", PROP_FLOAT, PROP_NONE);
+       RNA_def_property_float_sdna(prop, NULL, "sphere_radius");
+       RNA_def_property_range(prop, 0.0, 1000.0);
+       RNA_def_property_ui_text(prop, "Sphere Radius", "*TBD*");
+       RNA_def_property_update(prop, NC_SCENE, NULL);
+
+       prop= RNA_def_property(srna, "dkr_epsilon", PROP_FLOAT, PROP_NONE);
+       RNA_def_property_float_sdna(prop, NULL, "dkr_epsilon");
+       RNA_def_property_range(prop, 0.0, 1000.0);
+       RNA_def_property_ui_text(prop, "Dkr Epsilon", "*TBD*");
+       RNA_def_property_update(prop, NC_SCENE, NULL);
+}
+
 static void rna_def_scene_game_data(BlenderRNA *brna)
 {
        StructRNA *srna;
@@ -1115,11 +1177,22 @@ static void rna_def_scene_game_data(BlenderRNA *brna)
 static void rna_def_scene_render_layer(BlenderRNA *brna)
 {
        StructRNA *srna;
+       PropertyRNA *prop;
 
        srna= RNA_def_struct(brna, "SceneRenderLayer", NULL);
        RNA_def_struct_ui_text(srna, "Scene Render Layer", "Render layer.");
 
        rna_def_render_layer_common(srna, 1);
+
+       /* Freestyle */
+
+       rna_def_freestyle_settings(brna);
+
+       prop= RNA_def_property(srna, "freestyle_settings", PROP_POINTER, PROP_NONE);
+       RNA_def_property_flag(prop, PROP_NEVER_NULL);
+       RNA_def_property_pointer_sdna(prop, NULL, "freestyleConfig");
+       RNA_def_property_struct_type(prop, "FreestyleSettings");
+       RNA_def_property_ui_text(prop, "Freestyle Settings", "");
 }
 
 static void rna_def_scene_render_data(BlenderRNA *brna)
@@ -1714,6 +1787,11 @@ static void rna_def_scene_render_data(BlenderRNA *brna)
        RNA_def_property_ui_text(prop, "Edge Color", "");
        RNA_def_property_update(prop, NC_SCENE|ND_RENDER_OPTIONS, NULL);
        
+       prop= RNA_def_property(srna, "freestyle", PROP_BOOLEAN, PROP_NONE);
+       RNA_def_property_boolean_sdna(prop, NULL, "mode", R_EDGE_FRS);
+       RNA_def_property_ui_text(prop, "Edge", "Draw stylized strokes using Freestyle.");
+       RNA_def_property_update(prop, NC_SCENE|ND_RENDER_OPTIONS, NULL);
+
        prop= RNA_def_property(srna, "threads", PROP_INT, PROP_NONE);
        RNA_def_property_int_sdna(prop, NULL, "threads");
        RNA_def_property_range(prop, 1, 8);
@@ -2244,6 +2322,12 @@ void RNA_def_scene(BlenderRNA *brna)
        RNA_def_property_flag(prop, PROP_EDITABLE);
        RNA_def_property_struct_type(prop, "GreasePencil");
        RNA_def_property_ui_text(prop, "Grease Pencil Data", "Grease Pencil datablock");
+
+       /* Freestyle */
+       prop= RNA_def_property(srna, "freestyle_current_layer_number", PROP_INT, PROP_NONE);
+       RNA_def_property_int_sdna(prop, NULL, "freestyle_current_layer_number");
+       RNA_def_property_ui_text(prop, "Freestyle Current Layer Number", "Number of current layers in Freestyle.");
+       RNA_def_property_update(prop, NC_SCENE, NULL);
        
        /* Nestled Data  */
        rna_def_tool_settings(brna);