diff options
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenkernel/BKE_linestyle.h | 18 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/linestyle.c | 247 | ||||
-rw-r--r-- | source/blender/blenloader/intern/readfile.c | 1 | ||||
-rw-r--r-- | source/blender/blenloader/intern/writefile.c | 1 | ||||
-rw-r--r-- | source/blender/editors/render/render_intern.h | 6 | ||||
-rw-r--r-- | source/blender/editors/render/render_ops.c | 6 | ||||
-rw-r--r-- | source/blender/editors/render/render_shading.c | 277 | ||||
-rw-r--r-- | source/blender/freestyle/FRS_freestyle.h | 30 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_freestyle_types.h | 41 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_linestyle_types.h | 192 | ||||
-rw-r--r-- | source/blender/makesdna/intern/makesdna.c | 2 | ||||
-rw-r--r-- | source/blender/makesrna/RNA_access.h | 13 | ||||
-rw-r--r-- | source/blender/makesrna/RNA_enum_types.h | 4 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_linestyle.c | 377 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_scene.c | 1 |
15 files changed, 1205 insertions, 11 deletions
diff --git a/source/blender/blenkernel/BKE_linestyle.h b/source/blender/blenkernel/BKE_linestyle.h index df7808c1a2b..0514cb73e5b 100644 --- a/source/blender/blenkernel/BKE_linestyle.h +++ b/source/blender/blenkernel/BKE_linestyle.h @@ -32,11 +32,27 @@ #ifndef BKE_LINESTYLE_H #define BKE_LINESTYLE_H -#include "DNA_freestyle_types.h" +#include "DNA_linestyle_types.h" + +#define LS_MODIFIER_TYPE_COLOR 1 +#define LS_MODIFIER_TYPE_ALPHA 2 +#define LS_MODIFIER_TYPE_THICKNESS 3 struct Main; FreestyleLineStyle *FRS_new_linestyle(char *name, struct Main *main); void FRS_free_linestyle(FreestyleLineStyle *linestyle); +int FRS_add_linestyle_color_modifier(FreestyleLineStyle *linestyle, int type); +int FRS_add_linestyle_alpha_modifier(FreestyleLineStyle *linestyle, int type); +int FRS_add_linestyle_thickness_modifier(FreestyleLineStyle *linestyle, int type); + +void FRS_remove_linestyle_color_modifier(FreestyleLineStyle *linestyle, LineStyleModifier *modifier); +void FRS_remove_linestyle_alpha_modifier(FreestyleLineStyle *linestyle, LineStyleModifier *modifier); +void FRS_remove_linestyle_thickness_modifier(FreestyleLineStyle *linestyle, LineStyleModifier *modifier); + +void FRS_move_linestyle_color_modifier(FreestyleLineStyle *linestyle, LineStyleModifier *modifier, int direction); +void FRS_move_linestyle_alpha_modifier(FreestyleLineStyle *linestyle, LineStyleModifier *modifier, int direction); +void FRS_move_linestyle_thickness_modifier(FreestyleLineStyle *linestyle, LineStyleModifier *modifier, int direction); + #endif diff --git a/source/blender/blenkernel/intern/linestyle.c b/source/blender/blenkernel/intern/linestyle.c index 1f768fee0ec..1bdd735d1bd 100644 --- a/source/blender/blenkernel/intern/linestyle.c +++ b/source/blender/blenkernel/intern/linestyle.c @@ -33,14 +33,33 @@ #include "MEM_guardedalloc.h" +#include "DNA_material_types.h" /* for ramp blend */ + #include "BKE_global.h" #include "BKE_library.h" #include "BKE_linestyle.h" #include "BKE_main.h" +#include "BKE_texture.h" +#include "BKE_colortools.h" + +#include "BLI_blenlib.h" + +static char *modifier_name[LS_MODIFIER_NUM] = { + NULL, + "Along Stroke", + "Distance from Camera", + "Distance from Object"}; static void default_linestyle_settings(FreestyleLineStyle *linestyle) { + linestyle->panel = LS_PANEL_COLOR; + linestyle->r = linestyle->g = linestyle->b = 1.0; + linestyle->alpha = 1.0; + linestyle->thickness = 1.0; + linestyle->color_modifiers.first = linestyle->color_modifiers.last = NULL; + linestyle->alpha_modifiers.first = linestyle->alpha_modifiers.last = NULL; + linestyle->thickness_modifiers.first = linestyle->thickness_modifiers.last = NULL; } FreestyleLineStyle *FRS_new_linestyle(char *name, struct Main *main) @@ -59,5 +78,233 @@ FreestyleLineStyle *FRS_new_linestyle(char *name, struct Main *main) void FRS_free_linestyle(FreestyleLineStyle *linestyle) { + LineStyleModifier *m; + + while ((m = (LineStyleModifier *)linestyle->color_modifiers.first)) + FRS_remove_linestyle_color_modifier(linestyle, m); + while ((m = (LineStyleModifier *)linestyle->alpha_modifiers.first)) + FRS_remove_linestyle_alpha_modifier(linestyle, m); + while ((m = (LineStyleModifier *)linestyle->thickness_modifiers.first)) + FRS_remove_linestyle_thickness_modifier(linestyle, m); +} + +static LineStyleModifier *new_modifier(int type, size_t size) +{ + LineStyleModifier *m; + + m = (LineStyleModifier *)MEM_callocN(size, "line style modifier"); + if (m) { + m->type = type; + strcpy(m->name, modifier_name[type]); + m->influence = 1.0f; + m->flags = LS_MODIFIER_ENABLED | LS_MODIFIER_EXPANDED; + } + return m; +} + +static void add_to_modifier_list(ListBase *lb, LineStyleModifier *m) +{ + BLI_addtail(lb, (void *)m); + BLI_uniquename(lb, m, modifier_name[m->type], '.', BLI_STRUCT_OFFSET(LineStyleModifier, name), sizeof(m->name)); +} + +int FRS_add_linestyle_color_modifier(FreestyleLineStyle *linestyle, int type) +{ + static size_t modifier_size[LS_MODIFIER_NUM] = { + 0, + sizeof(LineStyleColorModifier_AlongStroke), + sizeof(LineStyleColorModifier_DistanceFromCamera), + sizeof(LineStyleColorModifier_DistanceFromObject) + }; + LineStyleModifier *m; + + if (type <= 0 || type >= LS_MODIFIER_NUM || modifier_size[type] == 0) + return -1; + m = new_modifier(type, modifier_size[type]); + if (!m) + return -1; + switch (type) { + case LS_MODIFIER_ALONG_STROKE: + ((LineStyleColorModifier_AlongStroke *)m)->color_ramp = add_colorband(1); + ((LineStyleColorModifier_AlongStroke *)m)->blend = MA_RAMP_BLEND; + break; + case LS_MODIFIER_DISTANCE_FROM_CAMERA: + ((LineStyleColorModifier_DistanceFromCamera *)m)->color_ramp = add_colorband(1); + ((LineStyleColorModifier_DistanceFromCamera *)m)->blend = MA_RAMP_BLEND; + ((LineStyleColorModifier_DistanceFromCamera *)m)->range_min = 0.0f; + ((LineStyleColorModifier_DistanceFromCamera *)m)->range_max = 10000.0f; + break; + case LS_MODIFIER_DISTANCE_FROM_OBJECT: + ((LineStyleColorModifier_DistanceFromObject *)m)->target = NULL; + ((LineStyleColorModifier_DistanceFromObject *)m)->color_ramp = add_colorband(1); + ((LineStyleColorModifier_DistanceFromObject *)m)->blend = MA_RAMP_BLEND; + ((LineStyleColorModifier_DistanceFromObject *)m)->range_min = 0.0f; + ((LineStyleColorModifier_DistanceFromObject *)m)->range_max = 10000.0f; + break; + default: + return -1; /* unknown modifier type */ + } + add_to_modifier_list(&linestyle->color_modifiers, m); + + return 0; +} + +void FRS_remove_linestyle_color_modifier(FreestyleLineStyle *linestyle, LineStyleModifier *m) +{ + switch (m->type) { + case LS_MODIFIER_ALONG_STROKE: + MEM_freeN(((LineStyleColorModifier_AlongStroke *)m)->color_ramp); + break; + case LS_MODIFIER_DISTANCE_FROM_CAMERA: + MEM_freeN(((LineStyleColorModifier_DistanceFromCamera *)m)->color_ramp); + break; + case LS_MODIFIER_DISTANCE_FROM_OBJECT: + MEM_freeN(((LineStyleColorModifier_DistanceFromObject *)m)->color_ramp); + break; + } + BLI_freelinkN(&linestyle->color_modifiers, m); +} + +int FRS_add_linestyle_alpha_modifier(FreestyleLineStyle *linestyle, int type) +{ + static size_t modifier_size[LS_MODIFIER_NUM] = { + 0, + sizeof(LineStyleAlphaModifier_AlongStroke), + sizeof(LineStyleAlphaModifier_DistanceFromCamera), + sizeof(LineStyleAlphaModifier_DistanceFromObject) + }; + LineStyleModifier *m; + + if (type <= 0 || type >= LS_MODIFIER_NUM || modifier_size[type] == 0) + return -1; + m = new_modifier(type, modifier_size[type]); + if (!m) + return -1; + switch (type) { + case LS_MODIFIER_ALONG_STROKE: + ((LineStyleAlphaModifier_AlongStroke *)m)->curve = curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f); + ((LineStyleAlphaModifier_AlongStroke *)m)->blend = LS_VALUE_ADD; + break; + case LS_MODIFIER_DISTANCE_FROM_CAMERA: + ((LineStyleAlphaModifier_DistanceFromCamera *)m)->curve = curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f); + ((LineStyleAlphaModifier_DistanceFromCamera *)m)->blend = LS_VALUE_ADD; + ((LineStyleAlphaModifier_DistanceFromCamera *)m)->range_min = 0.0f; + ((LineStyleAlphaModifier_DistanceFromCamera *)m)->range_max = 10000.0f; + break; + case LS_MODIFIER_DISTANCE_FROM_OBJECT: + ((LineStyleAlphaModifier_DistanceFromObject *)m)->target = NULL; + ((LineStyleAlphaModifier_DistanceFromObject *)m)->curve = curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f); + ((LineStyleAlphaModifier_DistanceFromObject *)m)->blend = LS_VALUE_ADD; + ((LineStyleAlphaModifier_DistanceFromObject *)m)->range_min = 0.0f; + ((LineStyleAlphaModifier_DistanceFromObject *)m)->range_max = 10000.0f; + break; + default: + return -1; /* unknown modifier type */ + } + add_to_modifier_list(&linestyle->alpha_modifiers, m); + + return 0; +} + +void FRS_remove_linestyle_alpha_modifier(FreestyleLineStyle *linestyle, LineStyleModifier *m) +{ + switch (m->type) { + case LS_MODIFIER_ALONG_STROKE: + curvemapping_free(((LineStyleAlphaModifier_AlongStroke *)m)->curve); + break; + case LS_MODIFIER_DISTANCE_FROM_CAMERA: + curvemapping_free(((LineStyleAlphaModifier_DistanceFromCamera *)m)->curve); + break; + case LS_MODIFIER_DISTANCE_FROM_OBJECT: + curvemapping_free(((LineStyleAlphaModifier_DistanceFromObject *)m)->curve); + break; + } + BLI_freelinkN(&linestyle->alpha_modifiers, m); +} + +int FRS_add_linestyle_thickness_modifier(FreestyleLineStyle *linestyle, int type) +{ + static size_t modifier_size[LS_MODIFIER_NUM] = { + 0, + sizeof(LineStyleThicknessModifier_AlongStroke), + sizeof(LineStyleThicknessModifier_DistanceFromCamera), + sizeof(LineStyleThicknessModifier_DistanceFromObject) + }; + LineStyleModifier *m; + + if (type <= 0 || type >= LS_MODIFIER_NUM || modifier_size[type] == 0) + return -1; + m = new_modifier(type, modifier_size[type]); + if (!m) + return -1; + switch (type) { + case LS_MODIFIER_ALONG_STROKE: + ((LineStyleThicknessModifier_AlongStroke *)m)->curve = curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f); + ((LineStyleThicknessModifier_AlongStroke *)m)->blend = LS_VALUE_ADD; + ((LineStyleThicknessModifier_AlongStroke *)m)->value_min = 0.0f; + ((LineStyleThicknessModifier_AlongStroke *)m)->value_max = 1.0f; + break; + case LS_MODIFIER_DISTANCE_FROM_CAMERA: + ((LineStyleThicknessModifier_DistanceFromCamera *)m)->curve = curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f); + ((LineStyleThicknessModifier_DistanceFromCamera *)m)->blend = LS_VALUE_ADD; + ((LineStyleThicknessModifier_DistanceFromCamera *)m)->range_min = 0.0f; + ((LineStyleThicknessModifier_DistanceFromCamera *)m)->range_max = 1000.0f; + ((LineStyleThicknessModifier_DistanceFromCamera *)m)->value_min = 0.0f; + ((LineStyleThicknessModifier_DistanceFromCamera *)m)->value_max = 1.0f; + break; + case LS_MODIFIER_DISTANCE_FROM_OBJECT: + ((LineStyleThicknessModifier_DistanceFromObject *)m)->target = NULL; + ((LineStyleThicknessModifier_DistanceFromObject *)m)->curve = curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f); + ((LineStyleThicknessModifier_DistanceFromObject *)m)->blend = LS_VALUE_ADD; + ((LineStyleThicknessModifier_DistanceFromObject *)m)->range_min = 0.0f; + ((LineStyleThicknessModifier_DistanceFromObject *)m)->range_max = 1000.0f; + ((LineStyleThicknessModifier_DistanceFromObject *)m)->value_min = 0.0f; + ((LineStyleThicknessModifier_DistanceFromObject *)m)->value_max = 1.0f; + break; + default: + return -1; /* unknown modifier type */ + } + add_to_modifier_list(&linestyle->thickness_modifiers, m); + + return 0; +} +void FRS_remove_linestyle_thickness_modifier(FreestyleLineStyle *linestyle, LineStyleModifier *m) +{ + switch (m->type) { + case LS_MODIFIER_ALONG_STROKE: + curvemapping_free(((LineStyleThicknessModifier_AlongStroke *)m)->curve); + break; + case LS_MODIFIER_DISTANCE_FROM_CAMERA: + curvemapping_free(((LineStyleThicknessModifier_DistanceFromCamera *)m)->curve); + break; + case LS_MODIFIER_DISTANCE_FROM_OBJECT: + curvemapping_free(((LineStyleThicknessModifier_DistanceFromObject *)m)->curve); + break; + } + BLI_freelinkN(&linestyle->thickness_modifiers, m); +} + +static void move_modifier(ListBase *lb, LineStyleModifier *modifier, int direction) +{ + BLI_remlink(lb, modifier); + if (direction > 0) + BLI_insertlinkbefore(lb, modifier->prev, modifier); + else + BLI_insertlinkafter(lb, modifier->next, modifier); +} + +void FRS_move_linestyle_color_modifier(FreestyleLineStyle *linestyle, LineStyleModifier *modifier, int direction) +{ + move_modifier(&linestyle->color_modifiers, modifier, direction); +} + +void FRS_move_linestyle_alpha_modifier(FreestyleLineStyle *linestyle, LineStyleModifier *modifier, int direction) +{ + move_modifier(&linestyle->alpha_modifiers, modifier, direction); +} + +void FRS_move_linestyle_thickness_modifier(FreestyleLineStyle *linestyle, LineStyleModifier *modifier, int direction) +{ + move_modifier(&linestyle->thickness_modifiers, modifier, direction); } diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 516515ba014..79d0d37a342 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -70,6 +70,7 @@ #include "DNA_key_types.h" #include "DNA_lattice_types.h" #include "DNA_lamp_types.h" +#include "DNA_linestyle_types.h" #include "DNA_meta_types.h" #include "DNA_material_types.h" #include "DNA_mesh_types.h" diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index 27832243ceb..1d429c45e30 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -110,6 +110,7 @@ Any case: direct data is ALWAYS after the lib block #include "DNA_lattice_types.h" #include "DNA_listBase.h" /* for Listbase, the type of samples, ...*/ #include "DNA_lamp_types.h" +#include "DNA_linestyle_types.h" #include "DNA_meta_types.h" #include "DNA_mesh_types.h" #include "DNA_meshdata_types.h" diff --git a/source/blender/editors/render/render_intern.h b/source/blender/editors/render/render_intern.h index 2f0ce71a4e5..2924748013b 100644 --- a/source/blender/editors/render/render_intern.h +++ b/source/blender/editors/render/render_intern.h @@ -57,6 +57,12 @@ void SCENE_OT_freestyle_lineset_add(struct wmOperatorType *ot); void SCENE_OT_freestyle_lineset_remove(struct wmOperatorType *ot); void SCENE_OT_freestyle_lineset_move(struct wmOperatorType *ot); void SCENE_OT_freestyle_linestyle_new(struct wmOperatorType *ot); +void SCENE_OT_freestyle_color_modifier_add(struct wmOperatorType *ot); +void SCENE_OT_freestyle_alpha_modifier_add(struct wmOperatorType *ot); +void SCENE_OT_freestyle_thickness_modifier_add(struct wmOperatorType *ot); +void SCENE_OT_freestyle_modifier_toggle_fold(struct wmOperatorType *ot); +void SCENE_OT_freestyle_modifier_remove(struct wmOperatorType *ot); +void SCENE_OT_freestyle_modifier_move(struct wmOperatorType *ot); void TEXTURE_OT_slot_copy(struct wmOperatorType *ot); diff --git a/source/blender/editors/render/render_ops.c b/source/blender/editors/render/render_ops.c index 5a228ba5242..42bc120eac4 100644 --- a/source/blender/editors/render/render_ops.c +++ b/source/blender/editors/render/render_ops.c @@ -64,6 +64,12 @@ void ED_operatortypes_render(void) WM_operatortype_append(SCENE_OT_freestyle_lineset_remove); WM_operatortype_append(SCENE_OT_freestyle_lineset_move); WM_operatortype_append(SCENE_OT_freestyle_linestyle_new); + WM_operatortype_append(SCENE_OT_freestyle_color_modifier_add); + WM_operatortype_append(SCENE_OT_freestyle_alpha_modifier_add); + WM_operatortype_append(SCENE_OT_freestyle_thickness_modifier_add); + WM_operatortype_append(SCENE_OT_freestyle_modifier_toggle_fold); + WM_operatortype_append(SCENE_OT_freestyle_modifier_remove); + WM_operatortype_append(SCENE_OT_freestyle_modifier_move); #if (defined(WITH_QUICKTIME) && !defined(USE_QTKIT)) WM_operatortype_append(SCENE_OT_render_data_set_quicktime_codec); diff --git a/source/blender/editors/render/render_shading.c b/source/blender/editors/render/render_shading.c index 81f32c402da..2d75af47a44 100644 --- a/source/blender/editors/render/render_shading.c +++ b/source/blender/editors/render/render_shading.c @@ -46,6 +46,7 @@ #include "BKE_icons.h" #include "BKE_image.h" #include "BKE_library.h" +#include "BKE_linestyle.h" #include "BKE_main.h" #include "BKE_material.h" #include "BKE_node.h" @@ -68,6 +69,7 @@ #include "FRS_freestyle.h" #include "RNA_access.h" +#include "RNA_enum_types.h" #include "WM_api.h" #include "WM_types.h" @@ -828,6 +830,14 @@ void SCENE_OT_freestyle_lineset_add(wmOperatorType *ot) ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; } +static int freestyle_active_lineset_poll(bContext *C) +{ + Scene *scene= CTX_data_scene(C); + SceneRenderLayer *srl = (SceneRenderLayer*) BLI_findlink(&scene->r.layers, scene->r.actlay); + + return FRS_get_active_lineset(&srl->freestyleConfig) != NULL; +} + static int freestyle_lineset_remove_exec(bContext *C, wmOperator *op) { Scene *scene= CTX_data_scene(C); @@ -849,6 +859,7 @@ void SCENE_OT_freestyle_lineset_remove(wmOperatorType *ot) /* api callbacks */ ot->exec= freestyle_lineset_remove_exec; + ot->poll= freestyle_active_lineset_poll; /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; @@ -885,6 +896,7 @@ void SCENE_OT_freestyle_lineset_move(wmOperatorType *ot) /* api callbacks */ ot->exec= freestyle_lineset_move_exec; + ot->poll= freestyle_active_lineset_poll; /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; @@ -899,6 +911,10 @@ static int freestyle_linestyle_new_exec(bContext *C, wmOperator *op) SceneRenderLayer *srl = (SceneRenderLayer*) BLI_findlink(&scene->r.layers, scene->r.actlay); FreestyleLineSet *lineset = FRS_get_active_lineset(&srl->freestyleConfig); + if (!lineset) { + BKE_report(op->reports, RPT_ERROR, "No active lineset to add a new line style to."); + return OPERATOR_CANCELLED; + } lineset->linestyle->id.us--; lineset->linestyle = FRS_new_linestyle("LineStyle", NULL); @@ -916,11 +932,272 @@ void SCENE_OT_freestyle_linestyle_new(wmOperatorType *ot) /* api callbacks */ ot->exec= freestyle_linestyle_new_exec; + ot->poll= freestyle_active_lineset_poll; /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; } +static int freestyle_color_modifier_add_exec(bContext *C, wmOperator *op) +{ + Scene *scene= CTX_data_scene(C); + SceneRenderLayer *srl = (SceneRenderLayer*) BLI_findlink(&scene->r.layers, scene->r.actlay); + FreestyleLineSet *lineset = FRS_get_active_lineset(&srl->freestyleConfig); + int type= RNA_enum_get(op->ptr, "type"); + + if (!lineset) { + BKE_report(op->reports, RPT_ERROR, "No active lineset and associated line style to add the modifier to."); + return OPERATOR_CANCELLED; + } + if (FRS_add_linestyle_color_modifier(lineset->linestyle, type) < 0) { + BKE_report(op->reports, RPT_ERROR, "Unknown line color modifier type."); + return OPERATOR_CANCELLED; + } + WM_event_add_notifier(C, NC_SCENE|ND_RENDER_OPTIONS, scene); + + return OPERATOR_FINISHED; +} + +void SCENE_OT_freestyle_color_modifier_add(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Add Line Color Modifier"; + ot->idname= "SCENE_OT_freestyle_color_modifier_add"; + ot->description = "Add a line color modifier to the line style associated with the active lineset."; + + /* api callbacks */ + ot->invoke= WM_menu_invoke; + ot->exec= freestyle_color_modifier_add_exec; + ot->poll= freestyle_active_lineset_poll; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + + /* properties */ + ot->prop= RNA_def_enum(ot->srna, "type", linestyle_color_modifier_type_items, 0, "Type", ""); +} + +static int freestyle_alpha_modifier_add_exec(bContext *C, wmOperator *op) +{ + Scene *scene= CTX_data_scene(C); + SceneRenderLayer *srl = (SceneRenderLayer*) BLI_findlink(&scene->r.layers, scene->r.actlay); + FreestyleLineSet *lineset = FRS_get_active_lineset(&srl->freestyleConfig); + int type= RNA_enum_get(op->ptr, "type"); + + if (!lineset) { + BKE_report(op->reports, RPT_ERROR, "No active lineset and associated line style to add the modifier to."); + return OPERATOR_CANCELLED; + } + if (FRS_add_linestyle_alpha_modifier(lineset->linestyle, type) < 0) { + BKE_report(op->reports, RPT_ERROR, "Unknown alpha transparency modifier type."); + return OPERATOR_CANCELLED; + } + WM_event_add_notifier(C, NC_SCENE|ND_RENDER_OPTIONS, scene); + + return OPERATOR_FINISHED; +} + +void SCENE_OT_freestyle_alpha_modifier_add(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Add Alpha Transparency Modifier"; + ot->idname= "SCENE_OT_freestyle_alpha_modifier_add"; + ot->description = "Add an alpha transparency modifier to the line style associated with the active lineset."; + + /* api callbacks */ + ot->invoke= WM_menu_invoke; + ot->exec= freestyle_alpha_modifier_add_exec; + ot->poll= freestyle_active_lineset_poll; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + + /* properties */ + ot->prop= RNA_def_enum(ot->srna, "type", linestyle_alpha_modifier_type_items, 0, "Type", ""); +} + +static int freestyle_thickness_modifier_add_exec(bContext *C, wmOperator *op) +{ + Scene *scene= CTX_data_scene(C); + SceneRenderLayer *srl = (SceneRenderLayer*) BLI_findlink(&scene->r.layers, scene->r.actlay); + FreestyleLineSet *lineset = FRS_get_active_lineset(&srl->freestyleConfig); + int type= RNA_enum_get(op->ptr, "type"); + + if (!lineset) { + BKE_report(op->reports, RPT_ERROR, "No active lineset and associated line style to add the modifier to."); + return OPERATOR_CANCELLED; + } + if (FRS_add_linestyle_thickness_modifier(lineset->linestyle, type) < 0) { + BKE_report(op->reports, RPT_ERROR, "Unknown line thickness modifier type."); + return OPERATOR_CANCELLED; + } + WM_event_add_notifier(C, NC_SCENE|ND_RENDER_OPTIONS, scene); + + return OPERATOR_FINISHED; +} + +void SCENE_OT_freestyle_thickness_modifier_add(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Add Line Thickness Modifier"; + ot->idname= "SCENE_OT_freestyle_thickness_modifier_add"; + ot->description = "Add a line thickness modifier to the line style associated with the active lineset."; + + /* api callbacks */ + ot->invoke= WM_menu_invoke; + ot->exec= freestyle_thickness_modifier_add_exec; + ot->poll= freestyle_active_lineset_poll; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + + /* properties */ + ot->prop= RNA_def_enum(ot->srna, "type", linestyle_thickness_modifier_type_items, 0, "Type", ""); +} + +static int freestyle_modifier_toggle_fold_exec(bContext *C, wmOperator *op) +{ + Scene *scene= CTX_data_scene(C); + PointerRNA ptr= CTX_data_pointer_get_type(C, "modifier", &RNA_LineStyleModifier); + LineStyleModifier *modifier= ptr.data; + + if (modifier->flags & LS_MODIFIER_EXPANDED) + modifier->flags &= ~LS_MODIFIER_EXPANDED; + else + modifier->flags |= LS_MODIFIER_EXPANDED; + + WM_event_add_notifier(C, NC_SCENE|ND_RENDER_OPTIONS, scene); + + return OPERATOR_FINISHED; +} + +void SCENE_OT_freestyle_modifier_toggle_fold(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Toggle Modifier Fold"; + ot->idname= "SCENE_OT_freestyle_modifier_toggle_fold"; + ot->description="Fold/expand the modifier tab."; + + /* api callbacks */ + ot->exec= freestyle_modifier_toggle_fold_exec; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} + +static int freestyle_get_modifier_type(PointerRNA *ptr) +{ + if (RNA_struct_is_a(ptr->type, &RNA_LineStyleColorModifier)) + return LS_MODIFIER_TYPE_COLOR; + else if (RNA_struct_is_a(ptr->type, &RNA_LineStyleAlphaModifier)) + return LS_MODIFIER_TYPE_ALPHA; + else if (RNA_struct_is_a(ptr->type, &RNA_LineStyleThicknessModifier)) + return LS_MODIFIER_TYPE_THICKNESS; + return -1; +} + +static int freestyle_modifier_remove_exec(bContext *C, wmOperator *op) +{ + Scene *scene= CTX_data_scene(C); + SceneRenderLayer *srl = (SceneRenderLayer*) BLI_findlink(&scene->r.layers, scene->r.actlay); + FreestyleLineSet *lineset = FRS_get_active_lineset(&srl->freestyleConfig); + PointerRNA ptr= CTX_data_pointer_get_type(C, "modifier", &RNA_LineStyleModifier); + LineStyleModifier *modifier= ptr.data; + + if (!lineset) { + BKE_report(op->reports, RPT_ERROR, "No active lineset and associated line style the modifier belongs to."); + return OPERATOR_CANCELLED; + } + switch (freestyle_get_modifier_type(&ptr)) { + case LS_MODIFIER_TYPE_COLOR: + FRS_remove_linestyle_color_modifier(lineset->linestyle, modifier); + break; + case LS_MODIFIER_TYPE_ALPHA: + FRS_remove_linestyle_alpha_modifier(lineset->linestyle, modifier); + break; + case LS_MODIFIER_TYPE_THICKNESS: + FRS_remove_linestyle_thickness_modifier(lineset->linestyle, modifier); + break; + default: + BKE_report(op->reports, RPT_ERROR, "The object the data pointer refers to is not a valid modifier."); + return OPERATOR_CANCELLED; + } + WM_event_add_notifier(C, NC_SCENE|ND_RENDER_OPTIONS, scene); + + return OPERATOR_FINISHED; +} + +void SCENE_OT_freestyle_modifier_remove(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Remove Modifier"; + ot->idname= "SCENE_OT_freestyle_modifier_remove"; + ot->description="Remove the modifier from the list of modifiers."; + + /* api callbacks */ + ot->exec= freestyle_modifier_remove_exec; + ot->poll= freestyle_active_lineset_poll; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} + +static int freestyle_modifier_move_exec(bContext *C, wmOperator *op) +{ + Scene *scene= CTX_data_scene(C); + SceneRenderLayer *srl = (SceneRenderLayer*) BLI_findlink(&scene->r.layers, scene->r.actlay); + FreestyleLineSet *lineset = FRS_get_active_lineset(&srl->freestyleConfig); + PointerRNA ptr= CTX_data_pointer_get_type(C, "modifier", &RNA_LineStyleModifier); + LineStyleModifier *modifier= ptr.data; + int dir= RNA_enum_get(op->ptr, "direction"); + + if (!lineset) { + BKE_report(op->reports, RPT_ERROR, "No active lineset and associated line style the modifier belongs to."); + return OPERATOR_CANCELLED; + } + switch (freestyle_get_modifier_type(&ptr)) { + case LS_MODIFIER_TYPE_COLOR: + FRS_move_linestyle_color_modifier(lineset->linestyle, modifier, dir); + break; + case LS_MODIFIER_TYPE_ALPHA: + FRS_move_linestyle_alpha_modifier(lineset->linestyle, modifier, dir); + break; + case LS_MODIFIER_TYPE_THICKNESS: + FRS_move_linestyle_thickness_modifier(lineset->linestyle, modifier, dir); + break; + default: + BKE_report(op->reports, RPT_ERROR, "The object the data pointer refers to is not a valid modifier."); + return OPERATOR_CANCELLED; + } + WM_event_add_notifier(C, NC_SCENE|ND_RENDER_OPTIONS, scene); + + return OPERATOR_FINISHED; +} + +void SCENE_OT_freestyle_modifier_move(wmOperatorType *ot) +{ + static EnumPropertyItem direction_items[] = { + {1, "UP", 0, "Up", ""}, + {-1, "DOWN", 0, "Down", ""}, + {0, NULL, 0, NULL, NULL} + }; + + /* identifiers */ + ot->name= "Move Modifier"; + ot->idname= "SCENE_OT_freestyle_modifier_move"; + ot->description="Move the modifier within the list of modifiers."; + + /* api callbacks */ + ot->exec= freestyle_modifier_move_exec; + ot->poll= freestyle_active_lineset_poll; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + + /* props */ + RNA_def_enum(ot->srna, "direction", direction_items, 0, "Direction", "Direction to move, UP or DOWN"); +} + static int texture_slot_move(bContext *C, wmOperator *op) { ID *id= CTX_data_pointer_get_type(C, "texture_slot", &RNA_TextureSlot).id.data; diff --git a/source/blender/freestyle/FRS_freestyle.h b/source/blender/freestyle/FRS_freestyle.h index 98f7f820715..18fdb08e75b 100644 --- a/source/blender/freestyle/FRS_freestyle.h +++ b/source/blender/freestyle/FRS_freestyle.h @@ -1,3 +1,33 @@ +/* FRS_freestyle.h + * + * $Id$ + * + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2010 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + */ + #ifndef FRS_FREESTYLE_H #define FRS_FREESTYLE_H diff --git a/source/blender/makesdna/DNA_freestyle_types.h b/source/blender/makesdna/DNA_freestyle_types.h index e415d580c4d..bf8b77e8a08 100644 --- a/source/blender/makesdna/DNA_freestyle_types.h +++ b/source/blender/makesdna/DNA_freestyle_types.h @@ -1,8 +1,39 @@ +/* DNA_freestyle_types.h + * + * $Id$ + * + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2010 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + */ + #ifndef DNA_FREESTYLE_TYPES_H #define DNA_FREESTYLE_TYPES_H #include "DNA_listBase.h" -#include "DNA_ID.h" + +struct FreestyleLineStyle; /* FreestyleConfig::flags */ #define FREESTYLE_SUGGESTIVE_CONTOURS_FLAG 1 @@ -39,11 +70,6 @@ #define FREESTYLE_QI_HIDDEN 2 #define FREESTYLE_QI_RANGE 3 -typedef struct FreestyleLineStyle { - ID id; - -} FreestyleLineStyle; - typedef struct FreestyleLineSet { struct FreestyleLineSet *next, *prev; @@ -56,7 +82,7 @@ typedef struct FreestyleLineSet { int qi_start, qi_end; int edge_types; /* feature edge types */ - FreestyleLineStyle *linestyle; /* line style */ + struct FreestyleLineStyle *linestyle; ListBase objects; /* target objects on which stylized lines are drawn */ @@ -86,4 +112,3 @@ typedef struct FreestyleConfig { } FreestyleConfig; #endif - diff --git a/source/blender/makesdna/DNA_linestyle_types.h b/source/blender/makesdna/DNA_linestyle_types.h new file mode 100644 index 00000000000..2d6f4951875 --- /dev/null +++ b/source/blender/makesdna/DNA_linestyle_types.h @@ -0,0 +1,192 @@ +/* DNA_linestyle_types.h + * + * $Id$ + * + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2010 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#ifndef DNA_LINESTYLE_TYPES_H +#define DNA_LINESTYLE_TYPES_H + +#include "DNA_listBase.h" +#include "DNA_ID.h" + +struct ColorBand; +struct CurveMapping; + +typedef struct LineStyleModifier { + struct LineStyleModifier *next, *prev; + + char name[32]; + int type; + float influence; + int flags; + int pad; +} LineStyleModifier; + +/* LineStyleColorModifier::type */ +#define LS_MODIFIER_ALONG_STROKE 1 +#define LS_MODIFIER_DISTANCE_FROM_CAMERA 2 +#define LS_MODIFIER_DISTANCE_FROM_OBJECT 3 +#define LS_MODIFIER_NUM 4 + +/* LineStyleColorModifier::flags */ +#define LS_MODIFIER_ENABLED 1 +#define LS_MODIFIER_EXPANDED 2 + +/* flags (for alpha & thickness) */ +#define LS_MODIFIER_USE_CURVE 1 +#define LS_MODIFIER_INVERT 2 + +/* blend (for alpha & thickness) */ +#define LS_VALUE_ADD 1 +#define LS_VALUE_MUL 2 +#define LS_VALUE_SUB 3 +#define LS_VALUE_DIV 4 +#define LS_VALUE_MIN 5 +#define LS_VALUE_MAX 6 + +/* Along Stroke modifiers */ + +typedef struct LineStyleColorModifier_AlongStroke { + struct LineStyleModifier modifier; + + struct ColorBand *color_ramp; + int blend; + int pad; + +} LineStyleColorModifier_AlongStroke; + +typedef struct LineStyleAlphaModifier_AlongStroke { + struct LineStyleModifier modifier; + + struct CurveMapping *curve; + int blend; + int flags; + +} LineStyleAlphaModifier_AlongStroke; + +typedef struct LineStyleThicknessModifier_AlongStroke { + struct LineStyleModifier modifier; + + struct CurveMapping *curve; + int blend; + int flags; + float value_min, value_max; + +} LineStyleThicknessModifier_AlongStroke; + +/* Distance from Camera modifiers */ + +typedef struct LineStyleColorModifier_DistanceFromCamera { + struct LineStyleModifier modifier; + + struct ColorBand *color_ramp; + int blend; + float range_min, range_max; + int pad; + +} LineStyleColorModifier_DistanceFromCamera; + +typedef struct LineStyleAlphaModifier_DistanceFromCamera { + struct LineStyleModifier modifier; + + struct CurveMapping *curve; + int blend; + int flags; + float range_min, range_max; + +} LineStyleAlphaModifier_DistanceFromCamera; + +typedef struct LineStyleThicknessModifier_DistanceFromCamera { + struct LineStyleModifier modifier; + + struct CurveMapping *curve; + int blend; + int flags; + float range_min, range_max; + float value_min, value_max; + +} LineStyleThicknessModifier_DistanceFromCamera; + +/* Distance from Object modifiers */ + +typedef struct LineStyleColorModifier_DistanceFromObject { + struct LineStyleModifier modifier; + + struct Object *target; + struct ColorBand *color_ramp; + int blend; + float range_min, range_max; + int pad; + +} LineStyleColorModifier_DistanceFromObject; + +typedef struct LineStyleAlphaModifier_DistanceFromObject { + struct LineStyleModifier modifier; + + struct Object *target; + struct CurveMapping *curve; + int blend; + int flags; + float range_min, range_max; + +} LineStyleAlphaModifier_DistanceFromObject; + +typedef struct LineStyleThicknessModifier_DistanceFromObject { + struct LineStyleModifier modifier; + + struct Object *target; + struct CurveMapping *curve; + int blend; + int flags; + float range_min, range_max; + float value_min, value_max; + +} LineStyleThicknessModifier_DistanceFromObject; + +/* FreestyleLineStyle::panel */ +#define LS_PANEL_COLOR 1 +#define LS_PANEL_ALPHA 2 +#define LS_PANEL_THICKNESS 3 +#define LS_PANEL_STROKES 4 +#define LS_PANEL_DISTORT 5 +#define LS_PANEL_MISC 6 + +typedef struct FreestyleLineStyle { + ID id; + + float r, g, b, alpha; + float thickness; + int panel; /* for UI */ + + ListBase color_modifiers; + ListBase alpha_modifiers; + ListBase thickness_modifiers; + +} FreestyleLineStyle; + +#endif diff --git a/source/blender/makesdna/intern/makesdna.c b/source/blender/makesdna/intern/makesdna.c index ba038869027..f5b05c193d0 100644 --- a/source/blender/makesdna/intern/makesdna.c +++ b/source/blender/makesdna/intern/makesdna.c @@ -130,6 +130,7 @@ char *includefiles[] = { "DNA_boid_types.h", "DNA_smoke_types.h", "DNA_freestyle_types.h", + "DNA_linestyle_types.h", // empty string to indicate end of includefiles "" @@ -1175,4 +1176,5 @@ int main(int argc, char ** argv) #include "DNA_boid_types.h" #include "DNA_smoke_types.h" #include "DNA_freestyle_types.h" +#include "DNA_linestyle_types.h" /* end of list */ diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h index 8e12ad588d0..39281a54325 100644 --- a/source/blender/makesrna/RNA_access.h +++ b/source/blender/makesrna/RNA_access.h @@ -277,6 +277,19 @@ extern StructRNA RNA_LimitDistanceConstraint; extern StructRNA RNA_LimitLocationConstraint; extern StructRNA RNA_LimitRotationConstraint; extern StructRNA RNA_LimitScaleConstraint; +extern StructRNA RNA_LineStyleAlphaModifier; +extern StructRNA RNA_LineStyleAlphaModifier_AlongStroke; +extern StructRNA RNA_LineStyleAlphaModifier_DistanceFromCamera; +extern StructRNA RNA_LineStyleAlphaModifier_DistanceFromObject; +extern StructRNA RNA_LineStyleColorModifier; +extern StructRNA RNA_LineStyleColorModifier_AlongStroke; +extern StructRNA RNA_LineStyleColorModifier_DistanceFromCamera; +extern StructRNA RNA_LineStyleColorModifier_DistanceFromObject; +extern StructRNA RNA_LineStyleModifier; +extern StructRNA RNA_LineStyleThicknessModifier; +extern StructRNA RNA_LineStyleThicknessModifier_AlongStroke; +extern StructRNA RNA_LineStyleThicknessModifier_DistanceFromCamera; +extern StructRNA RNA_LineStyleThicknessModifier_DistanceFromObject; extern StructRNA RNA_LockedTrackConstraint; extern StructRNA RNA_Macro; extern StructRNA RNA_MagicTexture; diff --git a/source/blender/makesrna/RNA_enum_types.h b/source/blender/makesrna/RNA_enum_types.h index bb0a1ba2c52..2cf2094e19d 100644 --- a/source/blender/makesrna/RNA_enum_types.h +++ b/source/blender/makesrna/RNA_enum_types.h @@ -90,6 +90,10 @@ extern EnumPropertyItem property_unit_items[]; extern EnumPropertyItem viewport_shading_items[]; +extern EnumPropertyItem linestyle_color_modifier_type_items[]; +extern EnumPropertyItem linestyle_alpha_modifier_type_items[]; +extern EnumPropertyItem linestyle_thickness_modifier_type_items[]; + struct bContext; struct PointerRNA; EnumPropertyItem *rna_TransformOrientation_itemf(struct bContext *C, struct PointerRNA *ptr, int *free); diff --git a/source/blender/makesrna/intern/rna_linestyle.c b/source/blender/makesrna/intern/rna_linestyle.c index f686d0cecda..d0cf19ca86a 100644 --- a/source/blender/makesrna/intern/rna_linestyle.c +++ b/source/blender/makesrna/intern/rna_linestyle.c @@ -29,29 +29,402 @@ #include "rna_internal.h" -#include "DNA_freestyle_types.h" +#include "DNA_linestyle_types.h" +#include "DNA_material_types.h" #include "WM_types.h" #include "WM_api.h" +EnumPropertyItem linestyle_color_modifier_type_items[] ={ + {LS_MODIFIER_ALONG_STROKE, "ALONG_STROKE", ICON_MODIFIER, "Along Stroke", ""}, + {LS_MODIFIER_DISTANCE_FROM_CAMERA, "DISTANCE_FROM_CAMERA", ICON_MODIFIER, "Distance from Camera", ""}, + {LS_MODIFIER_DISTANCE_FROM_OBJECT, "DISTANCE_FROM_OBJECT", ICON_MODIFIER, "Distance from Object", ""}, + {0, NULL, 0, NULL, NULL}}; + +EnumPropertyItem linestyle_alpha_modifier_type_items[] ={ + {LS_MODIFIER_ALONG_STROKE, "ALONG_STROKE", ICON_MODIFIER, "Along Stroke", ""}, + {LS_MODIFIER_DISTANCE_FROM_CAMERA, "DISTANCE_FROM_CAMERA", ICON_MODIFIER, "Distance from Camera", ""}, + {LS_MODIFIER_DISTANCE_FROM_OBJECT, "DISTANCE_FROM_OBJECT", ICON_MODIFIER, "Distance from Object", ""}, + {0, NULL, 0, NULL, NULL}}; + +EnumPropertyItem linestyle_thickness_modifier_type_items[] ={ + {LS_MODIFIER_ALONG_STROKE, "ALONG_STROKE", ICON_MODIFIER, "Along Stroke", ""}, + {LS_MODIFIER_DISTANCE_FROM_CAMERA, "DISTANCE_FROM_CAMERA", ICON_MODIFIER, "Distance from Camera", ""}, + {LS_MODIFIER_DISTANCE_FROM_OBJECT, "DISTANCE_FROM_OBJECT", ICON_MODIFIER, "Distance from Object", ""}, + {0, NULL, 0, NULL, NULL}}; + #ifdef RNA_RUNTIME +static StructRNA *rna_LineStyle_color_modifier_refine(struct PointerRNA *ptr) +{ + LineStyleModifier *m = (LineStyleModifier *)ptr->data; + + switch(m->type) { + case LS_MODIFIER_ALONG_STROKE: + return &RNA_LineStyleColorModifier_AlongStroke; + case LS_MODIFIER_DISTANCE_FROM_CAMERA: + return &RNA_LineStyleColorModifier_DistanceFromCamera; + case LS_MODIFIER_DISTANCE_FROM_OBJECT: + return &RNA_LineStyleColorModifier_DistanceFromObject; + default: + return &RNA_LineStyleColorModifier; + } +} + +static StructRNA *rna_LineStyle_alpha_modifier_refine(struct PointerRNA *ptr) +{ + LineStyleModifier *m = (LineStyleModifier *)ptr->data; + + switch(m->type) { + case LS_MODIFIER_ALONG_STROKE: + return &RNA_LineStyleAlphaModifier_AlongStroke; + case LS_MODIFIER_DISTANCE_FROM_CAMERA: + return &RNA_LineStyleAlphaModifier_DistanceFromCamera; + case LS_MODIFIER_DISTANCE_FROM_OBJECT: + return &RNA_LineStyleAlphaModifier_DistanceFromObject; + default: + return &RNA_LineStyleAlphaModifier; + } +} + +static StructRNA *rna_LineStyle_thickness_modifier_refine(struct PointerRNA *ptr) +{ + LineStyleModifier *m = (LineStyleModifier *)ptr->data; + + switch(m->type) { + case LS_MODIFIER_ALONG_STROKE: + return &RNA_LineStyleThicknessModifier_AlongStroke; + case LS_MODIFIER_DISTANCE_FROM_CAMERA: + return &RNA_LineStyleThicknessModifier_DistanceFromCamera; + case LS_MODIFIER_DISTANCE_FROM_OBJECT: + return &RNA_LineStyleThicknessModifier_DistanceFromObject; + default: + return &RNA_LineStyleThicknessModifier; + } +} + #else +#include "DNA_material_types.h" + +static void rna_def_modifier_type_common(StructRNA *srna, EnumPropertyItem *modifier_type_items) +{ + PropertyRNA *prop; + + prop= RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_sdna(prop, NULL, "modifier.type"); + RNA_def_property_enum_items(prop, modifier_type_items); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); + RNA_def_property_ui_text(prop, "Modifier Type", "Type of the modifier."); + + prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE); + RNA_def_property_string_sdna(prop, NULL, "modifier.name"); + RNA_def_property_ui_text(prop, "Modifier Name", "Name of the modifier."); + RNA_def_property_update(prop, NC_SCENE, NULL); + RNA_def_struct_name_property(srna, prop); + + prop= RNA_def_property(srna, "influence", PROP_FLOAT, PROP_FACTOR); + RNA_def_property_float_sdna(prop, NULL, "modifier.influence"); + RNA_def_property_range(prop, 0.0f, 1.0f); + RNA_def_property_ui_text(prop, "Influence", "Influence factor by which the modifier changes the property."); + RNA_def_property_update(prop, NC_SCENE, NULL); + + prop= RNA_def_property(srna, "enabled", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "modifier.flags", LS_MODIFIER_ENABLED); + RNA_def_property_ui_text(prop, "Enabled", "True if the modifier is enabled."); + + prop= RNA_def_property(srna, "expanded", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "modifier.flags", LS_MODIFIER_EXPANDED); + RNA_def_property_ui_text(prop, "Expanded", "True if the modifier tab is expanded."); +} + +static void rna_def_color_modifier(StructRNA *srna) +{ + rna_def_modifier_type_common(srna, linestyle_color_modifier_type_items); +} + +static void rna_def_alpha_modifier(StructRNA *srna) +{ + rna_def_modifier_type_common(srna, linestyle_alpha_modifier_type_items); +} + +static void rna_def_thickness_modifier(StructRNA *srna) +{ + rna_def_modifier_type_common(srna, linestyle_thickness_modifier_type_items); +} + +static void rna_def_modifier_color_common(StructRNA *srna, int range) +{ + PropertyRNA *prop; + + static EnumPropertyItem ramp_blend_items[] = { + {MA_RAMP_BLEND, "MIX", 0, "Mix", ""}, + {MA_RAMP_ADD, "ADD", 0, "Add", ""}, + {MA_RAMP_MULT, "MULTIPLY", 0, "Multiply", ""}, + {MA_RAMP_SUB, "SUBTRACT", 0, "Subtract", ""}, + {MA_RAMP_SCREEN, "SCREEN", 0, "Screen", ""}, + {MA_RAMP_DIV, "DIVIDE", 0, "Divide", ""}, + {MA_RAMP_DIFF, "DIFFERENCE", 0, "Difference", ""}, + {MA_RAMP_DARK, "DARKEN", 0, "Darken", ""}, + {MA_RAMP_LIGHT, "LIGHTEN", 0, "Lighten", ""}, + {MA_RAMP_OVERLAY, "OVERLAY", 0, "Overlay", ""}, + {MA_RAMP_DODGE, "DODGE", 0, "Dodge", ""}, + {MA_RAMP_BURN, "BURN", 0, "Burn", ""}, + {MA_RAMP_HUE, "HUE", 0, "Hue", ""}, + {MA_RAMP_SAT, "SATURATION", 0, "Saturation", ""}, + {MA_RAMP_VAL, "VALUE", 0, "Value", ""}, + {MA_RAMP_COLOR, "COLOR", 0, "Color", ""}, + {MA_RAMP_SOFT, "SOFT LIGHT", 0, "Soft Light", ""}, + {MA_RAMP_LINEAR, "LINEAR LIGHT", 0, "Linear Light", ""}, + {0, NULL, 0, NULL, NULL}}; + + prop= RNA_def_property(srna, "color_ramp", PROP_POINTER, PROP_NONE); + RNA_def_property_pointer_sdna(prop, NULL, "color_ramp"); + RNA_def_property_struct_type(prop, "ColorRamp"); + RNA_def_property_ui_text(prop, "Color Ramp", "Color ramp used to change line color."); + RNA_def_property_update(prop, NC_SCENE, NULL); + + prop= RNA_def_property(srna, "blend", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_sdna(prop, NULL, "blend"); + RNA_def_property_enum_items(prop, ramp_blend_items); + RNA_def_property_ui_text(prop, "Ramp Blend", "Specify how the color ramp and line color are blended."); + RNA_def_property_update(prop, NC_SCENE, NULL); + + if (range) { + prop= RNA_def_property(srna, "range_min", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "range_min"); + RNA_def_property_ui_text(prop, "Range Min", "Lower bound of the input range the mapping is applied."); + RNA_def_property_update(prop, NC_SCENE, NULL); + + prop= RNA_def_property(srna, "range_max", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "range_max"); + RNA_def_property_ui_text(prop, "Range Max", "Upper bound of the input range the mapping is applied."); + RNA_def_property_update(prop, NC_SCENE, NULL); + } +} + +static void rna_def_modifier_curve_common(StructRNA *srna, int range, int value) +{ + PropertyRNA *prop; + + static EnumPropertyItem mapping_items[] = { + {0, "LINEAR", 0, "Linear", "Use linear mapping."}, + {LS_MODIFIER_USE_CURVE, "CURVE", 0, "Curve", "Use curve mapping."}, + {0, NULL, 0, NULL, NULL}}; + + static EnumPropertyItem value_blend_items[] = { + {LS_VALUE_ADD, "ADD", 0, "Addd", ""}, + {LS_VALUE_MUL, "MULTIPLY", 0, "Multiply", ""}, + {LS_VALUE_SUB, "SUBTRACT", 0, "Subtract", ""}, + {LS_VALUE_DIV, "DIVIDE", 0, "Divide", ""}, + {LS_VALUE_MIN, "MININUM", 0, "Minimum", ""}, + {LS_VALUE_MAX, "MAXIMUM", 0, "Maximum", ""}, + {0, NULL, 0, NULL, NULL}}; + + prop= RNA_def_property(srna, "mapping", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_bitflag_sdna(prop, NULL, "flags"); + RNA_def_property_enum_items(prop, mapping_items); + RNA_def_property_ui_text(prop, "Mapping", "Select the mapping type."); + RNA_def_property_update(prop, NC_SCENE, NULL); + + prop= RNA_def_property(srna, "invert", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "flags", LS_MODIFIER_INVERT); + RNA_def_property_ui_text(prop, "Invert", "Invert the fade-out direction of the linear mapping."); + RNA_def_property_update(prop, NC_SCENE, NULL); + + prop = RNA_def_property(srna, "curve", PROP_POINTER, PROP_NONE); + RNA_def_property_pointer_sdna(prop, NULL, "curve"); + RNA_def_property_struct_type(prop, "CurveMapping"); + RNA_def_property_ui_text(prop, "Curve", "Curve used for the curve mapping."); + RNA_def_property_update(prop, NC_SCENE, NULL); + + prop= RNA_def_property(srna, "blend", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_sdna(prop, NULL, "blend"); + RNA_def_property_enum_items(prop, value_blend_items); + RNA_def_property_ui_text(prop, "Blend", "Specify how the mapping value and property value are blended."); + RNA_def_property_update(prop, NC_SCENE, NULL); + + if (range) { + prop= RNA_def_property(srna, "range_min", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "range_min"); + RNA_def_property_ui_text(prop, "Range Min", "Lower bound of the input range the mapping is applied."); + RNA_def_property_update(prop, NC_SCENE, NULL); + + prop= RNA_def_property(srna, "range_max", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "range_max"); + RNA_def_property_ui_text(prop, "Range Max", "Upper bound of the input range the mapping is applied."); + RNA_def_property_update(prop, NC_SCENE, NULL); + } + + if (value) { + prop= RNA_def_property(srna, "value_min", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "value_min"); + RNA_def_property_ui_text(prop, "Value Min", "Minimum output value of the mapping."); + RNA_def_property_update(prop, NC_SCENE, NULL); + + prop= RNA_def_property(srna, "value_max", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "value_max"); + RNA_def_property_ui_text(prop, "Value Max", "Maximum output value of the mapping."); + RNA_def_property_update(prop, NC_SCENE, NULL); + } +} + +static void rna_def_linestyle_modifiers(BlenderRNA *brna) +{ + StructRNA *srna; + PropertyRNA *prop; + + srna= RNA_def_struct(brna, "LineStyleModifier", NULL); + RNA_def_struct_ui_text(srna, "Line Style Modifier", "Base type to define modifiers."); + + /* line color modifiers */ + + srna= RNA_def_struct(brna, "LineStyleColorModifier", "LineStyleModifier"); + RNA_def_struct_sdna(srna, "LineStyleModifier"); + RNA_def_struct_refine_func(srna, "rna_LineStyle_color_modifier_refine"); + RNA_def_struct_ui_text(srna, "Line Style Color Modifier", "Base type to define line color modifiers."); + + srna= RNA_def_struct(brna, "LineStyleColorModifier_AlongStroke", "LineStyleColorModifier"); + RNA_def_struct_ui_text(srna, "Along Stroke", "Change line color along stroke."); + rna_def_color_modifier(srna); + rna_def_modifier_color_common(srna, 0); + + srna= RNA_def_struct(brna, "LineStyleColorModifier_DistanceFromCamera", "LineStyleColorModifier"); + RNA_def_struct_ui_text(srna, "Distance from Camera", "Change line color based on the distance from the camera."); + rna_def_color_modifier(srna); + rna_def_modifier_color_common(srna, 1); + + srna= RNA_def_struct(brna, "LineStyleColorModifier_DistanceFromObject", "LineStyleColorModifier"); + RNA_def_struct_ui_text(srna, "Distance from Object", "Change line color based on the distance from an object."); + rna_def_color_modifier(srna); + rna_def_modifier_color_common(srna, 1); + + prop= RNA_def_property(srna, "target", PROP_POINTER, PROP_NONE); + RNA_def_property_pointer_sdna(prop, NULL, "target"); + RNA_def_property_struct_type(prop, "Object"); + RNA_def_property_ui_text(prop, "Target", "Target object from which the distance is measured."); + RNA_def_property_update(prop, NC_SCENE, NULL); + + /* alpha transparency modifiers */ + + srna= RNA_def_struct(brna, "LineStyleAlphaModifier", "LineStyleModifier"); + RNA_def_struct_sdna(srna, "LineStyleModifier"); + RNA_def_struct_refine_func(srna, "rna_LineStyle_alpha_modifier_refine"); + RNA_def_struct_ui_text(srna, "Line Style Alpha Modifier", "Base type to define alpha transparency modifiers."); + + srna= RNA_def_struct(brna, "LineStyleAlphaModifier_AlongStroke", "LineStyleAlphaModifier"); + RNA_def_struct_ui_text(srna, "Along Stroke", "Change alpha transparency along stroke."); + rna_def_alpha_modifier(srna); + rna_def_modifier_curve_common(srna, 0, 0); + + srna= RNA_def_struct(brna, "LineStyleAlphaModifier_DistanceFromCamera", "LineStyleAlphaModifier"); + RNA_def_struct_ui_text(srna, "Distance from Camera", "Change alpha transparency based on the distance from the camera."); + rna_def_alpha_modifier(srna); + rna_def_modifier_curve_common(srna, 1, 0); + + srna= RNA_def_struct(brna, "LineStyleAlphaModifier_DistanceFromObject", "LineStyleAlphaModifier"); + RNA_def_struct_ui_text(srna, "Distance from Object", "Change alpha transparency based on the distance from an object."); + rna_def_alpha_modifier(srna); + rna_def_modifier_curve_common(srna, 1, 0); + + prop= RNA_def_property(srna, "target", PROP_POINTER, PROP_NONE); + RNA_def_property_pointer_sdna(prop, NULL, "target"); + RNA_def_property_struct_type(prop, "Object"); + RNA_def_property_ui_text(prop, "Target", "Target object from which the distance is measured."); + RNA_def_property_update(prop, NC_SCENE, NULL); + + /* line thickness modifiers */ + + srna= RNA_def_struct(brna, "LineStyleThicknessModifier", "LineStyleModifier"); + RNA_def_struct_sdna(srna, "LineStyleModifier"); + RNA_def_struct_refine_func(srna, "rna_LineStyle_thickness_modifier_refine"); + RNA_def_struct_ui_text(srna, "Line Style Thickness Modifier", "Base type to define line thickness modifiers."); + + srna= RNA_def_struct(brna, "LineStyleThicknessModifier_AlongStroke", "LineStyleThicknessModifier"); + RNA_def_struct_ui_text(srna, "Along Stroke", "Change line thickness along stroke."); + rna_def_thickness_modifier(srna); + rna_def_modifier_curve_common(srna, 0, 1); + + srna= RNA_def_struct(brna, "LineStyleThicknessModifier_DistanceFromCamera", "LineStyleThicknessModifier"); + RNA_def_struct_ui_text(srna, "Distance from Camera", "Change line thickness based on the distance from the camera."); + rna_def_thickness_modifier(srna); + rna_def_modifier_curve_common(srna, 1, 1); + + srna= RNA_def_struct(brna, "LineStyleThicknessModifier_DistanceFromObject", "LineStyleThicknessModifier"); + RNA_def_struct_ui_text(srna, "Distance from Object", "Change line thickness based on the distance from an object."); + rna_def_thickness_modifier(srna); + rna_def_modifier_curve_common(srna, 1, 1); + + prop= RNA_def_property(srna, "target", PROP_POINTER, PROP_NONE); + RNA_def_property_pointer_sdna(prop, NULL, "target"); + RNA_def_property_struct_type(prop, "Object"); + RNA_def_property_ui_text(prop, "Target", "Target object from which the distance is measured."); + RNA_def_property_update(prop, NC_SCENE, NULL); + +} + static void rna_def_linestyle(BlenderRNA *brna) { StructRNA *srna; PropertyRNA *prop; + static EnumPropertyItem panel_items[] = { + {LS_PANEL_COLOR, "COLOR", 0, "Color", "Show the panel for line color options."}, + {LS_PANEL_ALPHA, "ALPHA", 0, "Alpha", "Show the panel for alpha transparency options."}, + {LS_PANEL_THICKNESS, "THICKNESS", 0, "Thickness", "Show the panel for line thickness options."}, + {LS_PANEL_STROKES, "STROKES", 0, "Strokes", "Show the panel for stroke construction."}, + {LS_PANEL_DISTORT, "DISTORT", 0, "Distort", "Show the panel for stroke distortion."}, + {LS_PANEL_MISC, "MISC", 0, "Misc", "Show the panel for miscellaneous options."}, + {0, NULL, 0, NULL, NULL}}; + srna= RNA_def_struct(brna, "FreestyleLineStyle", "ID"); RNA_def_struct_ui_text(srna, "Freestyle Line Style", "Freestyle line style, reusable by multiple line sets"); + prop= RNA_def_property(srna, "panel", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_bitflag_sdna(prop, NULL, "panel"); + RNA_def_property_enum_items(prop, panel_items); + RNA_def_property_ui_text(prop, "Panel", "Select the property panel to be shown."); + RNA_def_property_update(prop, NC_SCENE, NULL); + + prop= RNA_def_property(srna, "color", PROP_FLOAT, PROP_COLOR); + RNA_def_property_float_sdna(prop, NULL, "r"); + RNA_def_property_array(prop, 3); + RNA_def_property_ui_text(prop, "Color", "Base line color, possibly modified by line color modifiers."); + RNA_def_property_update(prop, NC_SCENE, NULL); + + prop= RNA_def_property(srna, "alpha", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "alpha"); + RNA_def_property_range(prop, 0.0f, 1.0f); + RNA_def_property_ui_text(prop, "Alpha", "Base alpha transparency, possibly modified by alpha transparency modifiers."); + RNA_def_property_update(prop, NC_SCENE, NULL); + + prop= RNA_def_property(srna, "thickness", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "thickness"); + RNA_def_property_range(prop, 0.0f, 10000.0f); + RNA_def_property_ui_text(prop, "Thickness", "Base line thickness, possibly modified by line thickness modifiers."); + RNA_def_property_update(prop, NC_SCENE, NULL); + + prop= RNA_def_property(srna, "color_modifiers", PROP_COLLECTION, PROP_NONE); + RNA_def_property_collection_sdna(prop, NULL, "color_modifiers", NULL); + RNA_def_property_struct_type(prop, "LineStyleColorModifier"); + RNA_def_property_ui_text(prop, "Color Modifiers", "List of line color modifiers."); + + prop= RNA_def_property(srna, "alpha_modifiers", PROP_COLLECTION, PROP_NONE); + RNA_def_property_collection_sdna(prop, NULL, "alpha_modifiers", NULL); + RNA_def_property_struct_type(prop, "LineStyleAlphaModifier"); + RNA_def_property_ui_text(prop, "Alpha Modifiers", "List of alpha trancparency modifiers."); + + prop= RNA_def_property(srna, "thickness_modifiers", PROP_COLLECTION, PROP_NONE); + RNA_def_property_collection_sdna(prop, NULL, "thickness_modifiers", NULL); + RNA_def_property_struct_type(prop, "LineStyleThicknessModifier"); + RNA_def_property_ui_text(prop, "Thickness Modifiers", "List of line thickness modifiers."); + } void RNA_def_linestyle(BlenderRNA *brna) { + rna_def_linestyle_modifiers(brna); rna_def_linestyle(brna); } #endif - diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c index 2e4b0ee1c66..d7b60e153f9 100644 --- a/source/blender/makesrna/intern/rna_scene.c +++ b/source/blender/makesrna/intern/rna_scene.c @@ -34,6 +34,7 @@ #include "DNA_particle_types.h" #include "DNA_scene_types.h" #include "DNA_userdef_types.h" +#include "DNA_linestyle_types.h" /* Include for Bake Options */ #include "RE_pipeline.h" |