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/python/BPy_FrsMaterial.cpp
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/python/BPy_FrsMaterial.cpp')
-rw-r--r--source/blender/freestyle/intern/python/BPy_FrsMaterial.cpp92
1 files changed, 83 insertions, 9 deletions
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 */
};