Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTamito Kajiyama <rd6t-kjym@asahi-net.or.jp>2014-07-07 10:54:46 +0400
committerTamito Kajiyama <rd6t-kjym@asahi-net.or.jp>2014-07-07 11:19:51 +0400
commit7915d7277ac8c605f016f30f943080556244fb59 (patch)
tree4e137b5a4e98fad4911815a938cae8fd00783030 /source/blender/freestyle/intern
parentdc40928087e9b1183a6df2b38bb6a9a610e4ed13 (diff)
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).
Diffstat (limited to 'source/blender/freestyle/intern')
-rw-r--r--source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp2
-rw-r--r--source/blender/freestyle/intern/python/BPy_FrsMaterial.cpp92
-rw-r--r--source/blender/freestyle/intern/scene_graph/FrsMaterial.h97
3 files changed, 177 insertions, 14 deletions
diff --git a/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp b/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp
index 26a304ccf69..dbbc4f77c26 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, mat->specg, mat->specb, mat->spectra);
float s = 1.0 * (mat->har + 1) / 4 ; // in Blender: [1;511] => in OpenGL: [0;128]
if (s > 128.f)
s = 128.f;
tmpMat.setShininess(s);
+ tmpMat.setPriority(mat->line_priority);
}
if (meshFrsMaterials.empty()) {
diff --git a/source/blender/freestyle/intern/python/BPy_FrsMaterial.cpp b/source/blender/freestyle/intern/python/BPy_FrsMaterial.cpp
index f967fc64ac6..15cc4c3a0b0 100644
--- a/source/blender/freestyle/intern/python/BPy_FrsMaterial.cpp
+++ b/source/blender/freestyle/intern/python/BPy_FrsMaterial.cpp
@@ -64,11 +64,13 @@ PyDoc_STRVAR(FrsMaterial_doc,
" :arg brother: A Material object.\n"
" :type brother: :class:`Material`\n"
"\n"
-".. method:: __init__(diffuse, ambient, specular, emission, shininess)\n"
+".. method:: __init__(line, diffuse, ambient, specular, emission, shininess, priority)\n"
"\n"
-" Builds a Material from its diffuse, ambient, specular, emissive\n"
-" colors and a shininess coefficient.\n"
+" Builds a Material from its line, diffuse, ambient, specular, emissive\n"
+" colors, a shininess coefficient and line color priority.\n"
"\n"
+" :arg line: The line color.\n"
+" :type line: :class:`mathutils.Vector`, list or tuple of 4 float values\n"
" :arg diffuse: The diffuse color.\n"
" :type diffuse: :class:`mathutils.Vector`, list or tuple of 4 float values\n"
" :arg ambient: The ambient color.\n"
@@ -78,14 +80,17 @@ PyDoc_STRVAR(FrsMaterial_doc,
" :arg emission: The emissive color.\n"
" :type emission: :class:`mathutils.Vector`, list or tuple of 4 float values\n"
" :arg shininess: The shininess coefficient.\n"
-" :type shininess: :class:float");
+" :type shininess: :class:float\n"
+" :arg priority: The line color priority.\n"
+" :type priority: :class:int");
static int FrsMaterial_init(BPy_FrsMaterial *self, PyObject *args, PyObject *kwds)
{
static const char *kwlist_1[] = {"brother", NULL};
- static const char *kwlist_2[] = {"diffuse", "ambient", "specular", "emission", "shininess", NULL};
+ static const char *kwlist_2[] = {"line", "diffuse", "ambient", "specular", "emission", "shininess", "priority", NULL};
PyObject *brother = 0;
- float diffuse[4], ambient[4], specular[4], emission[4], shininess;
+ float line[4], diffuse[4], ambient[4], specular[4], emission[4], shininess;
+ int priority;
if (PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist_1, &FrsMaterial_Type, &brother)) {
if (!brother) {
@@ -101,14 +106,15 @@ static int FrsMaterial_init(BPy_FrsMaterial *self, PyObject *args, PyObject *kwd
}
}
else if (PyErr_Clear(),
- PyArg_ParseTupleAndKeywords(args, kwds, "O&O&O&O&f", (char **)kwlist_2,
+ PyArg_ParseTupleAndKeywords(args, kwds, "O&O&O&O&O&fi", (char **)kwlist_2,
+ convert_v4, line,
convert_v4, diffuse,
convert_v4, ambient,
convert_v4, specular,
convert_v4, emission,
- &shininess))
+ &shininess, &priority))
{
- self->m = new FrsMaterial(diffuse, ambient, specular, emission, shininess);
+ self->m = new FrsMaterial(line, diffuse, ambient, specular, emission, shininess, priority);
}
else {
PyErr_SetString(PyExc_TypeError, "invalid argument(s)");
@@ -135,6 +141,7 @@ static PyObject *FrsMaterial_repr(BPy_FrsMaterial *self)
#define MATHUTILS_SUBTYPE_SPECULAR 2
#define MATHUTILS_SUBTYPE_AMBIENT 3
#define MATHUTILS_SUBTYPE_EMISSION 4
+#define MATHUTILS_SUBTYPE_LINE 5
static int FrsMaterial_mathutils_check(BaseMathObject *bmo)
{
@@ -147,6 +154,12 @@ static int FrsMaterial_mathutils_get(BaseMathObject *bmo, int subtype)
{
BPy_FrsMaterial *self = (BPy_FrsMaterial *)bmo->cb_user;
switch (subtype) {
+ case MATHUTILS_SUBTYPE_LINE:
+ bmo->data[0] = self->m->lineR();
+ bmo->data[1] = self->m->lineG();
+ bmo->data[2] = self->m->lineB();
+ bmo->data[3] = self->m->lineA();
+ break;
case MATHUTILS_SUBTYPE_DIFFUSE:
bmo->data[0] = self->m->diffuseR();
bmo->data[1] = self->m->diffuseG();
@@ -181,6 +194,9 @@ static int FrsMaterial_mathutils_set(BaseMathObject *bmo, int subtype)
{
BPy_FrsMaterial *self = (BPy_FrsMaterial *)bmo->cb_user;
switch (subtype) {
+ case MATHUTILS_SUBTYPE_LINE:
+ self->m->setLine(bmo->data[0], bmo->data[1], bmo->data[2], bmo->data[3]);
+ break;
case MATHUTILS_SUBTYPE_DIFFUSE:
self->m->setDiffuse(bmo->data[0], bmo->data[1], bmo->data[2], bmo->data[3]);
break;
@@ -203,6 +219,12 @@ static int FrsMaterial_mathutils_get_index(BaseMathObject *bmo, int subtype, int
{
BPy_FrsMaterial *self = (BPy_FrsMaterial *)bmo->cb_user;
switch (subtype) {
+ case MATHUTILS_SUBTYPE_LINE:
+ {
+ const float *color = self->m->line();
+ bmo->data[index] = color[index];
+ }
+ break;
case MATHUTILS_SUBTYPE_DIFFUSE:
{
const float *color = self->m->diffuse();
@@ -238,6 +260,11 @@ static int FrsMaterial_mathutils_set_index(BaseMathObject *bmo, int subtype, int
BPy_FrsMaterial *self = (BPy_FrsMaterial *)bmo->cb_user;
float color[4];
switch (subtype) {
+ case MATHUTILS_SUBTYPE_LINE:
+ copy_v4_v4(color, self->m->line());
+ color[index] = bmo->data[index];
+ self->m->setLine(color[0], color[1], color[2], color[3]);
+ break;
case MATHUTILS_SUBTYPE_DIFFUSE:
copy_v4_v4(color, self->m->diffuse());
color[index] = bmo->data[index];
@@ -281,6 +308,28 @@ void FrsMaterial_mathutils_register_callback()
/*----------------------FrsMaterial get/setters ----------------------------*/
+PyDoc_STRVAR(FrsMaterial_line_doc,
+"RGBA components of the line color of the material.\n"
+"\n"
+":type: mathutils.Vector");
+
+static PyObject *FrsMaterial_line_get(BPy_FrsMaterial *self, void *UNUSED(closure))
+{
+ return Vector_CreatePyObject_cb((PyObject *)self, 4, FrsMaterial_mathutils_cb_index, MATHUTILS_SUBTYPE_LINE);
+}
+
+static int FrsMaterial_line_set(BPy_FrsMaterial *self, PyObject *value, void *UNUSED(closure))
+{
+ float color[4];
+ if (mathutils_array_parse(color, 4, 4, value,
+ "value must be a 4-dimensional vector") == -1)
+ {
+ return -1;
+ }
+ self->m->setLine(color[0], color[1], color[2], color[3]);
+ return 0;
+}
+
PyDoc_STRVAR(FrsMaterial_diffuse_doc,
"RGBA components of the diffuse color of the material.\n"
"\n"
@@ -390,7 +439,30 @@ static int FrsMaterial_shininess_set(BPy_FrsMaterial *self, PyObject *value, voi
return 0;
}
+PyDoc_STRVAR(FrsMaterial_priority_doc,
+"Line color priority of the material.\n"
+"\n"
+":type: int");
+
+static PyObject *FrsMaterial_priority_get(BPy_FrsMaterial *self, void *UNUSED(closure))
+{
+ return PyLong_FromLong(self->m->priority());
+}
+
+static int FrsMaterial_priority_set(BPy_FrsMaterial *self, PyObject *value, void *UNUSED(closure))
+{
+ int scalar;
+ if ((scalar = PyLong_AsLong(value)) == -1 && PyErr_Occurred()) {
+ PyErr_SetString(PyExc_TypeError, "value must be an integer");
+ return -1;
+ }
+ self->m->setPriority(scalar);
+ return 0;
+}
+
static PyGetSetDef BPy_FrsMaterial_getseters[] = {
+ {(char *)"line", (getter)FrsMaterial_line_get, (setter)FrsMaterial_line_set,
+ (char *)FrsMaterial_line_doc, NULL},
{(char *)"diffuse", (getter)FrsMaterial_diffuse_get, (setter)FrsMaterial_diffuse_set,
(char *)FrsMaterial_diffuse_doc, NULL},
{(char *)"specular", (getter)FrsMaterial_specular_get, (setter)FrsMaterial_specular_set,
@@ -401,6 +473,8 @@ static PyGetSetDef BPy_FrsMaterial_getseters[] = {
(char *)FrsMaterial_emission_doc, NULL},
{(char *)"shininess", (getter)FrsMaterial_shininess_get, (setter)FrsMaterial_shininess_set,
(char *)FrsMaterial_shininess_doc, NULL},
+ {(char *)"priority", (getter)FrsMaterial_priority_get, (setter)FrsMaterial_priority_set,
+ (char *)FrsMaterial_priority_doc, NULL},
{NULL, NULL, NULL, NULL, NULL} /* Sentinel */
};
diff --git a/source/blender/freestyle/intern/scene_graph/FrsMaterial.h b/source/blender/freestyle/intern/scene_graph/FrsMaterial.h
index 4d1fc4e69c9..a00f983bbcf 100644
--- a/source/blender/freestyle/intern/scene_graph/FrsMaterial.h
+++ b/source/blender/freestyle/intern/scene_graph/FrsMaterial.h
@@ -43,7 +43,10 @@ public:
/*! Default constructor */
inline FrsMaterial();
- /*! Builds a Material from its diffuse, ambiant, specular, emissive colors and a shininess coefficient.
+ /*! Builds a Material from its line, diffuse, ambiant, specular, emissive
+ * colors, a shininess coefficient and line color priority.
+ * \param iLine
+ * A 4 element float-array containing the line color.
* \param iDiffuse
* A 4 element float-array containing the diffuse color.
* \param iAmbiant
@@ -54,9 +57,11 @@ public:
* A 4 element float-array containing the emissive color.
* \param iShininess
* The shininess coefficient.
+ * \param iPriority
+ * The line color priority.
*/
- inline FrsMaterial(const float *iDiffuse, const float *iAmbiant, const float *iSpecular, const float *iEmission,
- const float iShininess);
+ inline FrsMaterial(const float *iLine, const float *iDiffuse, const float *iAmbiant, const float *iSpecular,
+ const float *iEmission, const float iShininess, const int iPriority);
/*! Copy constructor */
inline FrsMaterial(const FrsMaterial& m);
@@ -64,6 +69,35 @@ public:
/*! Destructor */
virtual ~FrsMaterial() {}
+ /*! Returns the line color as a 4 float array */
+ inline const float *line() const
+ {
+ return Line;
+ }
+
+ /*! Returns the red component of the line color */
+ inline const float lineR() const
+ {
+ return Line[0];
+ }
+
+ /*! Returns the green component of the line color */
+ inline const float lineG() const
+ {
+ return Line[1];
+ }
+
+ /*! Returns the blue component of the line color */
+ inline const float lineB() const
+ {
+ return Line[2];
+ }
+
+ /*! Returns the alpha component of the line color */
+ inline const float lineA() const
+ {
+ return Line[3];
+ }
/*! Returns the diffuse color as a 4 float array */
inline const float *diffuse() const
@@ -191,6 +225,24 @@ public:
return Shininess;
}
+ /*! Returns the line color priority */
+ inline const int priority() const
+ {
+ return Priority;
+ }
+
+ /*! Sets the line color.
+ * \param r
+ * Red component
+ * \param g
+ * Green component
+ * \param b
+ * Blue component
+ * \param a
+ * Alpha component
+ */
+ inline void setLine(const float r, const float g, const float b, const float a);
+
/*! Sets the diffuse color.
* \param r
* Red component
@@ -245,6 +297,12 @@ public:
*/
inline void setShininess(const float s);
+ /*! Sets the line color priority.
+ * \param priority
+ * Priority
+ */
+ inline void setPriority(const int priority);
+
/* operators */
inline FrsMaterial& operator=(const FrsMaterial& m);
inline bool operator!=(const FrsMaterial& m) const;
@@ -252,11 +310,13 @@ public:
private:
/*! Material properties */
+ float Line[4];
float Diffuse[4];
float Specular[4];
float Ambient[4];
float Emission[4];
float Shininess;
+ int Priority;
#ifdef WITH_CXX_GUARDEDALLOC
MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:FrsMaterial")
@@ -265,6 +325,9 @@ private:
FrsMaterial::FrsMaterial()
{
+ Line[0] = Line[1] = Line[2] = 0.0f;
+ Line[3] = 1.0f;
+
Ambient[0] = Ambient[1] = Ambient[2] = 0.2f;
Ambient[3] = 1.0f;
@@ -278,12 +341,14 @@ FrsMaterial::FrsMaterial()
Specular[3] = 1.0f;
Shininess = 0.0f;
+ Priority = 0;
}
-FrsMaterial::FrsMaterial(const float *iDiffuse, const float *iAmbiant, const float *iSpecular, const float *iEmission,
- const float iShininess)
+FrsMaterial::FrsMaterial(const float *iLine, const float *iDiffuse, const float *iAmbiant, const float *iSpecular,
+ const float *iEmission, const float iShininess, const int iPriority)
{
for (int i = 0; i < 4; i++) {
+ Line[i] = iLine[i];
Diffuse[i] = iDiffuse[i];
Specular[i] = iSpecular[i];
Ambient[i] = iAmbiant[i];
@@ -291,11 +356,13 @@ FrsMaterial::FrsMaterial(const float *iDiffuse, const float *iAmbiant, const flo
}
Shininess = iShininess;
+ Priority = iPriority;
}
FrsMaterial::FrsMaterial(const FrsMaterial& m)
{
for (int i = 0; i < 4; i++) {
+ Line[i] = m.line()[i];
Diffuse[i] = m.diffuse()[i];
Specular[i] = m.specular()[i];
Ambient[i] = m.ambient()[i];
@@ -303,6 +370,15 @@ FrsMaterial::FrsMaterial(const FrsMaterial& m)
}
Shininess = m.shininess();
+ Priority = m.priority();
+}
+
+void FrsMaterial::setLine(const float r, const float g, const float b, const float a)
+{
+ Line[0] = r;
+ Line[1] = g;
+ Line[2] = b;
+ Line[3] = a;
}
void FrsMaterial::setDiffuse(const float r, const float g, const float b, const float a)
@@ -342,9 +418,15 @@ void FrsMaterial::setShininess(const float s)
Shininess = s;
}
+void FrsMaterial::setPriority(const int priority)
+{
+ Priority = priority;
+}
+
FrsMaterial& FrsMaterial::operator=(const FrsMaterial& m)
{
for (int i = 0; i < 4; i++) {
+ Line[i] = m.line()[i];
Diffuse[i] = m.diffuse()[i];
Specular[i] = m.specular()[i];
Ambient[i] = m.ambient()[i];
@@ -352,6 +434,7 @@ FrsMaterial& FrsMaterial::operator=(const FrsMaterial& m)
}
Shininess = m.shininess();
+ Priority = m.priority();
return *this;
}
@@ -359,8 +442,12 @@ bool FrsMaterial::operator!=(const FrsMaterial& m) const
{
if (Shininess != m.shininess())
return true;
+ if (Priority != m.priority())
+ return true;
for (int i = 0; i < 4; i++) {
+ if (Line[i] != m.line()[i])
+ return true;
if (Diffuse[i] != m.diffuse()[i])
return true;
if (Specular[i] != m.specular()[i])