[Bf-blender-cvs] [7915d72] master: Per-material line color settings for Freestyle.

Tamito Kajiyama noreply at git.blender.org
Mon Jul 7 09:24:07 CEST 2014


Commit: 7915d7277ac8c605f016f30f943080556244fb59
Author: Tamito Kajiyama
Date:   Mon Jul 7 15:54:46 2014 +0900
https://developer.blender.org/rB7915d7277ac8c605f016f30f943080556244fb59

Per-material line color settings for Freestyle.

New properties 'line_color' and 'line_priority' are added to Material ID data blocks.

The 'line_color' property allows users to specify a per-material line color that can be
used as a Freestyle line color through Material color modifiers of line style settings.

The new line color property is intended to provide a solution for line color
stylization when a proper Freestyle support for Cycles is implemented (likely
as part of the upcoming Blender 2.72 release; see Patch D632).  Materials in
Cycles are usually set up using shader nodes, and Freestyle won't be capable
of retrieving colors and other properties from node-based materials any soon.

The new line color property of materials addresses this foreseen limitation by
providing artists with an intuitive alternative mean to specify line colors on a
per-material basis independently from node trees.

The 'line_priority' property gives users a way to control line colors at material
boundaries.  When a line is drawn along a feature edge at material boundaries,
one of the two materials on both sides of the edge has to be picked up to
determine the line color.  So far there was no way to control this selection
(which was in effect at random).  Now the material with a higher line color
priority will be selected.

The new per-material line settings are shown in the new Freestyle Line tab in
the Material context of the Properties window (only when Freestyle is enabled).

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

M	release/scripts/freestyle/modules/freestyle/functions.py
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/freestyle/intern/blender_interface/BlenderFileLoader.cpp
M	source/blender/freestyle/intern/python/BPy_FrsMaterial.cpp
M	source/blender/freestyle/intern/scene_graph/FrsMaterial.h
M	source/blender/makesdna/DNA_linestyle_types.h
M	source/blender/makesdna/DNA_material_types.h
M	source/blender/makesrna/intern/rna_linestyle.c
M	source/blender/makesrna/intern/rna_material.c

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

diff --git a/release/scripts/freestyle/modules/freestyle/functions.py b/release/scripts/freestyle/modules/freestyle/functions.py
index 773d04d..9e03f8f 100644
--- a/release/scripts/freestyle/modules/freestyle/functions.py
+++ b/release/scripts/freestyle/modules/freestyle/functions.py
@@ -98,14 +98,21 @@ from mathutils import Vector
 class CurveMaterialF0D(UnaryFunction0DMaterial):
     """
     A replacement of the built-in MaterialF0D for stroke creation.
-    MaterialF0D does not work with Curves and Strokes.
+    MaterialF0D does not work with Curves and Strokes.  Line color
+    priority is used to pick one of the two materials at material
+    boundaries.
     """
     def __call__(self, inter):
         cp = inter.object
         assert(isinstance(cp, CurvePoint))
         fe = cp.first_svertex.get_fedge(cp.second_svertex)
         assert(fe is not None), "CurveMaterialF0D: fe is None"
-        return fe.material if fe.is_smooth else fe.material_left
+        if fe.is_smooth:
+            return fe.material
+        elif fe.material_right.priority > fe.material_left.priority:
+            return fe.material_right
+        else:
+            return fe.material_left
 
 
 class pyInverseCurvature2DAngleF0D(UnaryFunction0DDouble):
diff --git a/release/scripts/freestyle/modules/parameter_editor.py b/release/scripts/freestyle/modules/parameter_editor.py
index 34645b9..3529221 100644
--- a/release/scripts/freestyle/modules/parameter_editor.py
+++ b/release/scripts/freestyle/modules/parameter_editor.py
@@ -447,7 +447,9 @@ def iter_material_color(stroke, material_attribute):
     it = stroke.stroke_vertices_begin()
     while not it.is_end:
         material = func(Interface0DIterator(it))
-        if material_attribute == 'DIFF':
+        if material_attribute == 'LINE':
+            color = material.line[0:3]
+        elif material_attribute == 'DIFF':
             color = material.diffuse[0:3]
         elif material_attribute == 'SPEC':
             color = material.specular[0:3]
@@ -462,7 +464,18 @@ def iter_material_value(stroke, material_attribute):
     it = stroke.stroke_vertices_begin()
     while not it.is_end:
         material = func(Interface0DIterator(it))
-        if material_attribute == 'DIFF':
+        if material_attribute == 'LINE':
+            r, g, b = material.line[0:3]
+            t = 0.35 * r + 0.45 * g + 0.2 * b
+        elif material_attribute == 'LINE_R':
+            t = material.line[0]
+        elif material_attribute == 'LINE_G':
+            t = material.line[1]
+        elif material_attribute == 'LINE_B':
+            t = material.line[2]
+        elif material_attribute == 'ALPHA':
+            t = material.line[3]
+        elif material_attribute == 'DIFF':
             r, g, b = material.diffuse[0:3]
             t = 0.35 * r + 0.45 * g + 0.2 * b
         elif material_attribute == 'DIFF_R':
@@ -482,8 +495,6 @@ def iter_material_value(stroke, material_attribute):
             t = material.specular[2]
         elif material_attribute == 'SPEC_HARDNESS':
             t = material.shininess
-        elif material_attribute == 'ALPHA':
-            t = material.diffuse[3]
         else:
             raise ValueError("unexpected material attribute: " + material_attribute)
         yield it, t
@@ -497,7 +508,7 @@ class ColorMaterialShader(ColorRampModifier):
         self.__use_ramp = use_ramp
 
     def shade(self, stroke):
-        if self.__material_attribute in {'DIFF', 'SPEC'} and not self.__use_ramp:
+        if self.__material_attribute in {'LINE', 'DIFF', 'SPEC'} and not self.__use_ramp:
             for it, b in iter_material_color(stroke, self.__material_attribute):
                 sv = it.object
                 a = sv.attribute.color
diff --git a/release/scripts/startup/bl_ui/properties_freestyle.py b/release/scripts/startup/bl_ui/properties_freestyle.py
index 31a638d..c5716df 100644
--- a/release/scripts/startup/bl_ui/properties_freestyle.py
+++ b/release/scripts/startup/bl_ui/properties_freestyle.py
@@ -344,7 +344,7 @@ class RENDERLAYER_PT_freestyle_linestyle(RenderLayerFreestyleEditorButtonsPanel,
                 row.prop(modifier, "material_attribute", text="")
                 sub = row.column()
                 sub.prop(modifier, "use_ramp")
-                if modifier.material_attribute in {'DIFF', 'SPEC'}:
+                if modifier.material_attribute in {'LINE', 'DIFF', 'SPEC'}:
                     sub.active = True
                     show_ramp = modifier.use_ramp
                 else:
@@ -691,5 +691,37 @@ class RENDERLAYER_PT_freestyle_linestyle(RenderLayerFreestyleEditorButtonsPanel,
             pass
 
 
+# Material properties
+
+class MaterialFreestyleButtonsPanel():
+    bl_space_type = 'PROPERTIES'
+    bl_region_type = 'WINDOW'
+    bl_context = "material"
+    # COMPAT_ENGINES must be defined in each subclass, external engines can add themselves here
+
+    @classmethod
+    def poll(cls, context):
+        scene = context.scene
+        material = context.material
+        with_freestyle = bpy.app.build_options.freestyle
+        return with_freestyle and material and scene and scene.render.use_freestyle and \
+            (scene.render.engine in cls.COMPAT_ENGINES)
+
+
+class MATERIAL_PT_freestyle_line(MaterialFreestyleButtonsPanel, Panel):
+    bl_label = "Freestyle Line"
+    bl_options = {'DEFAULT_CLOSED'}
+    COMPAT_ENGINES = {'BLENDER_RENDER'} # TODO: 'CYCLES'
+
+    def draw(self, context):
+        layout = self.layout
+
+        mat = context.material
+
+        row = layout.row()
+        row.prop(mat, "line_color", text="")
+        row.prop(mat, "line_priority", text="Priority")
+
+
 if __name__ == "__main__":  # only for live edit.
     bpy.utils.register_module(__name__)
diff --git a/source/blender/blenkernel/BKE_blender.h b/source/blender/blenkernel/BKE_blender.h
index 67d5b1e..0af45a1 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         271
-#define BLENDER_SUBVERSION      0
+#define BLENDER_SUBVERSION      1
 /* 262 was the last editmesh release but it has compatibility code for bmesh data */
 #define BLENDER_MINVERSION      270
 #define BLENDER_MINSUBVERSION   5
diff --git a/source/blender/blenkernel/intern/linestyle.c b/source/blender/blenkernel/intern/linestyle.c
index 8ef966a..d92fa32 100644
--- a/source/blender/blenkernel/intern/linestyle.c
+++ b/source/blender/blenkernel/intern/linestyle.c
@@ -279,7 +279,7 @@ LineStyleModifier *BKE_add_linestyle_color_modifier(FreestyleLineStyle *linestyl
 			break;
 		case LS_MODIFIER_MATERIAL:
 			((LineStyleColorModifier_Material *)m)->color_ramp = add_colorband(1);
-			((LineStyleColorModifier_Material *)m)->mat_attr = LS_MODIFIER_MATERIAL_DIFF;
+			((LineStyleColorModifier_Material *)m)->mat_attr = LS_MODIFIER_MATERIAL_LINE;
 			break;
 		default:
 			return NULL; /* unknown modifier type */
@@ -424,7 +424,7 @@ LineStyleModifier *BKE_add_linestyle_alpha_modifier(FreestyleLineStyle *linestyl
 		{
 			LineStyleAlphaModifier_Material *p = (LineStyleAlphaModifier_Material *)m;
 			p->curve = curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
-			p->mat_attr = LS_MODIFIER_MATERIAL_DIFF;
+			p->mat_attr = LS_MODIFIER_MATERIAL_ALPHA;
 			break;
 		}
 		default:
@@ -583,7 +583,7 @@ LineStyleModifier *BKE_add_linestyle_thickness_modifier(FreestyleLineStyle *line
 		{
 			LineStyleThicknessModifier_Material *p = (LineStyleThicknessModifier_Material *)m;
 			p->curve = curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
-			p->mat_attr = LS_MODIFIER_MATERIAL_DIFF;
+			p->mat_attr = LS_MODIFIER_MATERIAL_LINE;
 			p->value_min = 0.0f;
 			p->value_max = 1.0f;
 			break;
diff --git a/source/blender/blenloader/intern/versioning_270.c b/source/blender/blenloader/intern/versioning_270.c
index b812cf1..7fa9b4e 100644
--- a/source/blender/blenloader/intern/versioning_270.c
+++ b/source/blender/blenloader/intern/versioning_270.c
@@ -298,4 +298,16 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main)
 			}
 		}
 	}
+
+	if (!MAIN_VERSION_ATLEAST(main, 271, 1)) {
+		if (!DNA_struct_elem_find(fd->filesdna, "Material", "float", "line[4]")) {
+			Material *mat;
+
+			for (mat = main->mat.first; mat; mat = mat->id.next) {
+				mat->line_col[0] = mat->line_col[1] = mat->line_col[2] = 0.0f;
+				mat->line_col[3] = mat->alpha;
+			}
+		}
+
+	}
 }
diff --git a/source/blender/blenloader/intern/versioning_defaults.c b/source/blender/blenloader/intern/versioning_defaults.c
index 1e881eb..fdedd3f 100644
--- a/source/blender/blenloader/intern/versioning_defaults.c
+++ b/source/blender/blenloader/intern/versioning_defaults.c
@@ -35,6 +35,7 @@
 #include "DNA_space_types.h"
 #include "DNA_userdef_types.h"
 #include "DNA_mesh_types.h"
+#include "DNA_material_types.h"
 
 #include "BKE_main.h"
 
@@ -48,6 +49,7 @@ void BLO_update_defaults_startup_blend(Main *main)
 	SceneRenderLayer *srl;
 	FreestyleLineStyle *linestyle;
 	Mesh *me;
+	Material *mat;
 
 	for (scene = main->scene.first; scene; scene = scene->id.next) {
 		scene->r.im_format.planes = R_IMF_PLANES_RGBA;
@@ -86,5 +88,10 @@ void BLO_update_defaults_startup_blend(Main *main)
 	for (me = main->mesh.first; me; me = me->id.next) {
 		me->smoothresh = DEG2RADF(180.0f);
 	}
+
+	for (mat = main->mat.first; mat; mat = mat->id.next) {
+		mat->line_col[0] = mat->line_col[1] = mat->line_col[2] = 0.0f;
+		mat->line_col[3] = 1.0f;
+	}
 }
 
diff --git a/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp b/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp
index 26a304c..dbbc4f7 100644
--- a/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp
+++ b/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp
@@ -578,12 +578,14 @@ void BlenderFileLoader::insertShapeNode(ObjectInstanceRen *obi, int id)
 
 		Material *mat = vlr->mat;
 		if (mat) {
+			tmpMat.setLine(mat->line_col[0], mat->line_col[1], mat->line_col[2], mat->line_col[3]);
 			tmpMat.setDiffuse(mat->r, mat->g, mat->b, mat->alpha);
 			tmpMat.setSpecular(mat->specr, 

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list