[Bf-blender-cvs] [f60a66f] master: Freestyle: New options for sorting to arrange the stacking order of lines.

Tamito Kajiyama noreply at git.blender.org
Fri Apr 18 08:03:27 CEST 2014


Commit: f60a66f41784de388a01c4c882c969730d675375
Author: Tamito Kajiyama
Date:   Fri Apr 18 14:59:02 2014 +0900
https://developer.blender.org/rBf60a66f41784de388a01c4c882c969730d675375

Freestyle: New options for sorting to arrange the stacking order of lines.

Line styles now have a set of new options for rearranging the stacking order of lines.
This gives artists more control to determine which lines should be drawn on top of others.
Two available sort keys are the distance from camera and curvilinear 2D length.
Since the distance of a line from camera may vary over vertices, another option called
integration type is used to compute the sort key for a line from the values computed at
individual vertices.  Available integration types are MEAN, MIN, MAX, FIRST and LAST
(see the tool tips for more detail).

===================================================================

M	release/scripts/freestyle/modules/parameter_editor.py
M	release/scripts/startup/bl_ui/properties_freestyle.py
M	source/blender/blenkernel/BKE_blender.h
M	source/blender/blenkernel/intern/linestyle.c
M	source/blender/blenloader/intern/versioning_270.c
M	source/blender/blenloader/intern/versioning_defaults.c
M	source/blender/makesdna/DNA_linestyle_types.h
M	source/blender/makesrna/intern/rna_linestyle.c

===================================================================

diff --git a/release/scripts/freestyle/modules/parameter_editor.py b/release/scripts/freestyle/modules/parameter_editor.py
index ce15028..73ae0f4 100644
--- a/release/scripts/freestyle/modules/parameter_editor.py
+++ b/release/scripts/freestyle/modules/parameter_editor.py
@@ -23,6 +23,7 @@
 
 from freestyle.types import (
     BinaryPredicate1D,
+    IntegrationType,
     Interface0DIterator,
     Nature,
     Noise,
@@ -51,6 +52,8 @@ from freestyle.predicates import (
     ExternalContourUP1D,
     FalseBP1D,
     FalseUP1D,
+    Length2DBP1D,
+    NotBP1D,
     NotUP1D,
     OrUP1D,
     QuantitativeInvisibilityUP1D,
@@ -58,6 +61,7 @@ from freestyle.predicates import (
     TrueUP1D,
     WithinImageBoundaryUP1D,
     pyNatureUP1D,
+    pyZBP1D,
     )
 from freestyle.shaders import (
     BackboneStretcherShader,
@@ -1163,6 +1167,14 @@ class StrokeCleaner(StrokeShader):
         stroke.update_length()
 
 
+integration_types = {
+    'MEAN': IntegrationType.MEAN,
+    'MIN': IntegrationType.MIN,
+    'MAX': IntegrationType.MAX,
+    'FIRST': IntegrationType.FIRST,
+    'LAST': IntegrationType.LAST}
+
+
 # main function for parameter processing
 
 def process(layer_name, lineset_name):
@@ -1291,6 +1303,16 @@ def process(layer_name, lineset_name):
         length_min = linestyle.length_min if linestyle.use_length_min else None
         length_max = linestyle.length_max if linestyle.use_length_max else None
         Operators.select(LengthThresholdUP1D(length_min, length_max))
+    # sort selected chains
+    if linestyle.use_sorting:
+        integration = integration_types.get(linestyle.integration_type, IntegrationType.MEAN)
+        if linestyle.sort_key == 'DISTANCE_FROM_CAMERA':
+            bpred = pyZBP1D(integration)
+        elif linestyle.sort_key == '2D_LENGTH':
+            bpred = Length2DBP1D()
+        if linestyle.sort_order == 'REVERSE':
+            bpred = NotBP1D(bpred)
+        Operators.sort(bpred)
     # prepare a list of stroke shaders
     shaders_list = []
     ###
diff --git a/release/scripts/startup/bl_ui/properties_freestyle.py b/release/scripts/startup/bl_ui/properties_freestyle.py
index 197b0d2..bedee24 100644
--- a/release/scripts/startup/bl_ui/properties_freestyle.py
+++ b/release/scripts/startup/bl_ui/properties_freestyle.py
@@ -603,6 +603,18 @@ class RENDERLAYER_PT_freestyle_linestyle(RenderLayerFreestyleEditorButtonsPanel,
             sub.active = linestyle.use_length_max
             sub.prop(linestyle, "length_max")
 
+            ## Sorting
+            layout.prop(linestyle, "use_sorting", text="Sorting:")
+            col = layout.column()
+            col.active = linestyle.use_sorting
+            row = col.row(align=True)
+            row.prop(linestyle, "sort_key", text="")
+            sub = row.row()
+            sub.active = linestyle.sort_key in {'DISTANCE_FROM_CAMERA'}
+            sub.prop(linestyle, "integration_type", text="")
+            row = col.row(align=True)
+            row.prop(linestyle, "sort_order", expand=True)
+
             ## Caps
             layout.label(text="Caps:")
             row = layout.row(align=True)
diff --git a/source/blender/blenkernel/BKE_blender.h b/source/blender/blenkernel/BKE_blender.h
index 9a67284..e29aa14 100644
--- a/source/blender/blenkernel/BKE_blender.h
+++ b/source/blender/blenkernel/BKE_blender.h
@@ -42,7 +42,7 @@ extern "C" {
  * and keep comment above the defines.
  * Use STRINGIFY() rather than defining with quotes */
 #define BLENDER_VERSION         270
-#define BLENDER_SUBVERSION      2
+#define BLENDER_SUBVERSION      3
 /* 262 was the last editmesh release but it has compatibility code for bmesh data */
 #define BLENDER_MINVERSION      262
 #define BLENDER_MINSUBVERSION   0
diff --git a/source/blender/blenkernel/intern/linestyle.c b/source/blender/blenkernel/intern/linestyle.c
index f826e61..78d062c 100644
--- a/source/blender/blenkernel/intern/linestyle.c
+++ b/source/blender/blenkernel/intern/linestyle.c
@@ -81,7 +81,7 @@ static void default_linestyle_settings(FreestyleLineStyle *linestyle)
 	linestyle->thickness = 3.0f;
 	linestyle->thickness_position = LS_THICKNESS_CENTER;
 	linestyle->thickness_ratio = 0.5f;
-	linestyle->flag = LS_SAME_OBJECT;
+	linestyle->flag = LS_SAME_OBJECT | LS_NO_SORTING;
 	linestyle->chaining = LS_CHAINING_PLAIN;
 	linestyle->rounds = 3;
 	linestyle->min_angle = DEG2RADF(0.0f);
@@ -89,6 +89,8 @@ static void default_linestyle_settings(FreestyleLineStyle *linestyle)
 	linestyle->min_length = 0.0f;
 	linestyle->max_length = 10000.0f;
 	linestyle->split_length = 100;
+	linestyle->sort_key = LS_SORT_KEY_DISTANCE_FROM_CAMERA;
+	linestyle->integration_type = LS_INTEGRATION_MEAN;
 
 	BLI_listbase_clear(&linestyle->color_modifiers);
 	BLI_listbase_clear(&linestyle->alpha_modifiers);
diff --git a/source/blender/blenloader/intern/versioning_270.c b/source/blender/blenloader/intern/versioning_270.c
index 2dd227e..41b9506 100644
--- a/source/blender/blenloader/intern/versioning_270.c
+++ b/source/blender/blenloader/intern/versioning_270.c
@@ -43,6 +43,7 @@
 #include "DNA_mesh_types.h"
 #include "DNA_modifier_types.h"
 #include "DNA_sdna_types.h"
+#include "DNA_linestyle_types.h"
 
 #include "DNA_genfile.h"
 
@@ -171,4 +172,14 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main)
 			me->smoothresh = DEG2RADF(me->smoothresh);
 		}
 	}
+
+	if (!MAIN_VERSION_ATLEAST(main, 270, 3)) {
+		FreestyleLineStyle *linestyle;
+
+		for (linestyle = main->linestyle.first; linestyle; linestyle = linestyle->id.next) {
+			linestyle->flag |= LS_NO_SORTING;
+			linestyle->sort_key = LS_SORT_KEY_DISTANCE_FROM_CAMERA;
+			linestyle->integration_type = LS_INTEGRATION_MEAN;
+		}
+	}
 }
diff --git a/source/blender/blenloader/intern/versioning_defaults.c b/source/blender/blenloader/intern/versioning_defaults.c
index d6caf16..b455ef0 100644
--- a/source/blender/blenloader/intern/versioning_defaults.c
+++ b/source/blender/blenloader/intern/versioning_defaults.c
@@ -59,8 +59,11 @@ void BLO_update_defaults_startup_blend(Main *main)
 		}
 	}
 
-	for (linestyle = main->linestyle.first; linestyle; linestyle = linestyle->id.next)
-		linestyle->flag = LS_SAME_OBJECT;
+	for (linestyle = main->linestyle.first; linestyle; linestyle = linestyle->id.next) {
+		linestyle->flag = LS_SAME_OBJECT | LS_NO_SORTING;
+		linestyle->sort_key = LS_SORT_KEY_DISTANCE_FROM_CAMERA;
+		linestyle->integration_type = LS_INTEGRATION_MEAN;
+	}
 
 	{
 		bScreen *screen;
diff --git a/source/blender/makesdna/DNA_linestyle_types.h b/source/blender/makesdna/DNA_linestyle_types.h
index 19c4e05..8d5f81e 100644
--- a/source/blender/makesdna/DNA_linestyle_types.h
+++ b/source/blender/makesdna/DNA_linestyle_types.h
@@ -368,6 +368,8 @@ typedef struct LineStyleThicknessModifier_Calligraphy {
 #define LS_MAX_2D_ANGLE       (1 <<  8)
 #define LS_SPLIT_LENGTH       (1 <<  9)
 #define LS_SPLIT_PATTERN      (1 << 10)
+#define LS_NO_SORTING         (1 << 11)
+#define LS_REVERSE_ORDER      (1 << 12)  /* for sorting */
 
 /* FreestyleLineStyle::chaining */
 #define LS_CHAINING_PLAIN    1
@@ -384,6 +386,17 @@ typedef struct LineStyleThicknessModifier_Calligraphy {
 #define LS_THICKNESS_OUTSIDE   3
 #define LS_THICKNESS_RELATIVE  4 /* thickness_ratio is used */
 
+/* FreestyleLineStyle::sort_key */
+#define LS_SORT_KEY_DISTANCE_FROM_CAMERA  1
+#define LS_SORT_KEY_2D_LENGTH             2
+
+/* FreestyleLineStyle::integration_type */
+#define LS_INTEGRATION_MEAN   1
+#define LS_INTEGRATION_MIN    2
+#define LS_INTEGRATION_MAX    3
+#define LS_INTEGRATION_FIRST  4
+#define LS_INTEGRATION_LAST   5
+
 typedef struct FreestyleLineStyle {
 	ID id;
 	struct AnimData *adt;
@@ -401,6 +414,7 @@ typedef struct FreestyleLineStyle {
 	unsigned short split_dash1, split_gap1;
 	unsigned short split_dash2, split_gap2;
 	unsigned short split_dash3, split_gap3;
+	int sort_key, integration_type;
 	int pad;
 	unsigned short dash1, gap1, dash2, gap2, dash3, gap3;
 	int panel; /* for UI */
diff --git a/source/blender/makesrna/intern/rna_linestyle.c b/source/blender/makesrna/intern/rna_linestyle.c
index 0619bb0..e97f3c2 100644
--- a/source/blender/makesrna/intern/rna_linestyle.c
+++ b/source/blender/makesrna/intern/rna_linestyle.c
@@ -915,6 +915,24 @@ static void rna_def_linestyle(BlenderRNA *brna)
 		{LS_THICKNESS_RELATIVE, "RELATIVE", 0, "Relative", "Stroke thickness is split by a user-defined ratio"},
 		{0, NULL, 0, NULL, NULL}
 	};
+	static EnumPropertyItem sort_key_items[] = {
+		{LS_SORT_KEY_DISTANCE_FROM_CAMERA, "DISTANCE_FROM_CAMERA", 0, "Distance from Camera", "Sort by distance from camera (closer lines lie on top of further lines)"},
+		{LS_SORT_KEY_2D_LENGTH, "2D_LENGTH", 0, "2D Length", "Sort by curvilinear 2D length (longer lines lie on top of shorter lines)"},
+		{0, NULL, 0, NULL, NULL}
+	};
+	static EnumPropertyItem sort_order_items[] = {
+		{0, "DEFAULT", 0, "Default", "Default order of the sort key"},
+		{LS_REVERSE_ORDER, "REVERSE", 0, "Reverse", "Reverse order"},
+		{0, NULL, 0, NULL, NULL}
+	};
+	static EnumPropertyItem integration_type_items[] = {
+		{LS_INTEGRATION_MEAN, "MEAN", 0, "Mean", "The value computed for the chain is the mean of the values obtained for chain vertices"},
+		{LS_INTEGRATION_MIN, "MIN", 0, "Min", "The value computed for the chain is the minimum of the values obtained for chain vertices"},
+		{LS_INTEGRATION_MAX, "MAX", 0, "Max", "The value computed for the chain is the maximum of the values obtained for chain vertices"},
+		{LS_INTEGRATION_FIRST, "FIRST", 0, "First", "The value computed for the chain is the value obtained for the first chain vertex"},
+		{LS_INTEGRATION_LAST, "LAST", 0, "Last", "The value computed for the chain is the value obtained for the last chain vertex"},
+		{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");
@@ -1104,6 +1122,29 @@ static void rna_def_linestyle(BlenderRNA *brna)
 	RNA_def_property_ui_text(prop, "Material Boundary", "If true, chains of feature edges are split at material boundaries");
 	RNA_def_property_update(prop, NC_LINESTYLE, NULL);
 
+	prop = RNA_def_property(srna, "use

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list