2023-08-16 00:20:26 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2004-2023 Blender Authors
|
2023-06-14 23:30:43 +10:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2013-02-23 18:32:28 +00:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup freestyle
|
2013-02-23 18:32:28 +00:00
|
|
|
*/
|
|
|
|
|
|
2008-08-01 02:25:21 +00:00
|
|
|
#include "BPy_FrsMaterial.h"
|
2008-07-31 11:59:06 +00:00
|
|
|
|
|
|
|
|
#include "BPy_Convert.h"
|
|
|
|
|
|
2024-02-02 19:55:06 +01:00
|
|
|
#include "BLI_hash_mm2a.hh"
|
Cleanup: reduce amount of math-related includes
Using ClangBuildAnalyzer on the whole Blender build, it was pointing
out that BLI_math.h is the heaviest "header hub" (i.e. non tiny file
that is included a lot).
However, there's very little (actually zero) source files in Blender
that need "all the math" (base, colors, vectors, matrices,
quaternions, intersection, interpolation, statistics, solvers and
time). A common use case is source files needing just vectors, or
just vectors & matrices, or just colors etc. Actually, 181 files
were including the whole math thing without needing it at all.
This change removes BLI_math.h completely, and instead in all the
places that need it, includes BLI_math_vector.h or BLI_math_color.h
and so on.
Change from that:
- BLI_math_color.h was included 1399 times -> now 408 (took 114.0sec
to parse -> now 36.3sec)
- BLI_simd.h 1403 -> 418 (109.7sec -> 34.9sec).
Full rebuild of Blender (Apple M1, Xcode, RelWithDebInfo) is not
affected much (342sec -> 334sec). Most of benefit would be when
someone's changing BLI_simd.h or BLI_math_color.h or similar files,
that now there's 3x fewer files result in a recompile.
Pull Request #110944
2023-08-09 11:39:20 +03:00
|
|
|
#include "BLI_math_vector.h"
|
|
|
|
|
|
2021-02-08 17:28:15 +02:00
|
|
|
using namespace Freestyle;
|
|
|
|
|
|
2008-07-31 11:59:06 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
//-------------------MODULE INITIALIZATION--------------------------------
|
2013-02-21 02:57:44 +00:00
|
|
|
int FrsMaterial_Init(PyObject *module)
|
2008-07-31 11:59:06 +00:00
|
|
|
{
|
2020-11-06 17:49:09 +01:00
|
|
|
if (module == nullptr) {
|
2009-09-27 00:32:20 +00:00
|
|
|
return -1;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2008-07-31 11:59:06 +00:00
|
|
|
|
2019-05-31 22:51:19 +10:00
|
|
|
if (PyType_Ready(&FrsMaterial_Type) < 0) {
|
2009-09-27 00:32:20 +00:00
|
|
|
return -1;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2024-09-26 17:07:06 +10:00
|
|
|
PyModule_AddObjectRef(module, "Material", (PyObject *)&FrsMaterial_Type);
|
2013-02-03 17:01:21 +00:00
|
|
|
|
|
|
|
|
FrsMaterial_mathutils_register_callback();
|
2013-02-14 23:50:30 +00:00
|
|
|
|
2009-09-27 00:32:20 +00:00
|
|
|
return 0;
|
2008-07-31 11:59:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//------------------------INSTANCE METHODS ----------------------------------
|
|
|
|
|
|
2013-02-14 23:50:30 +00:00
|
|
|
PyDoc_STRVAR(
|
2024-01-25 10:22:16 +11:00
|
|
|
/* Wrap. */
|
2013-02-14 23:50:30 +00:00
|
|
|
FrsMaterial_doc,
|
2010-04-17 23:47:47 +00:00
|
|
|
"Class defining a material.\n"
|
|
|
|
|
"\n"
|
|
|
|
|
".. method:: __init__()\n"
|
2020-10-22 17:20:57 -04:00
|
|
|
" __init__(brother)\n"
|
|
|
|
|
" __init__(line, diffuse, ambient, specular, emission, shininess, priority)\n"
|
2010-04-17 23:47:47 +00:00
|
|
|
"\n"
|
2020-10-22 17:20:57 -04:00
|
|
|
" Creates a :class:`FrsMaterial` using either default constructor,\n"
|
|
|
|
|
" copy constructor, or an overloaded constructor\n"
|
2010-04-17 23:47:47 +00:00
|
|
|
"\n"
|
2020-10-22 17:20:57 -04:00
|
|
|
" :arg brother: A Material object to be used as a copy constructor.\n"
|
2013-02-21 02:57:44 +00:00
|
|
|
" :type brother: :class:`Material`\n"
|
2014-07-07 15:54:46 +09:00
|
|
|
" :arg line: The line color.\n"
|
2024-11-03 15:42:19 +11:00
|
|
|
" :type line: :class:`mathutils.Vector` | tuple[float, float, float, float] | list[float]\n"
|
2013-02-21 02:57:44 +00:00
|
|
|
" :arg diffuse: The diffuse color.\n"
|
2024-11-03 15:42:19 +11:00
|
|
|
" :type diffuse: \n"
|
2013-02-21 02:57:44 +00:00
|
|
|
" :arg ambient: The ambient color.\n"
|
2024-11-03 15:42:19 +11:00
|
|
|
" :type ambient: :class:`mathutils.Vector` | tuple[float, float, float, float] | "
|
|
|
|
|
"list[float]\n"
|
2013-02-21 02:57:44 +00:00
|
|
|
" :arg specular: The specular color.\n"
|
2024-11-03 15:42:19 +11:00
|
|
|
" :type specular: :class:`mathutils.Vector` | tuple[float, float, float, float] | "
|
|
|
|
|
"list[float]\n"
|
2013-02-21 02:57:44 +00:00
|
|
|
" :arg emission: The emissive color.\n"
|
2024-11-03 15:42:19 +11:00
|
|
|
" :type emission: :class:`mathutils.Vector` | tuple[float, float, float, float] | "
|
|
|
|
|
"list[float]\n"
|
2013-02-21 02:57:44 +00:00
|
|
|
" :arg shininess: The shininess coefficient.\n"
|
2014-09-19 13:22:20 +09:00
|
|
|
" :type shininess: float\n"
|
2014-07-07 15:54:46 +09:00
|
|
|
" :arg priority: The line color priority.\n"
|
2025-08-22 14:05:28 +10:00
|
|
|
" :type priority: int\n");
|
2013-02-14 23:50:30 +00:00
|
|
|
static int FrsMaterial_init(BPy_FrsMaterial *self, PyObject *args, PyObject *kwds)
|
2008-07-31 11:59:06 +00:00
|
|
|
{
|
2020-11-06 17:49:09 +01:00
|
|
|
static const char *kwlist_1[] = {"brother", nullptr};
|
2014-07-07 15:54:46 +09:00
|
|
|
static const char *kwlist_2[] = {
|
2020-11-06 17:49:09 +01:00
|
|
|
"line", "diffuse", "ambient", "specular", "emission", "shininess", "priority", nullptr};
|
|
|
|
|
PyObject *brother = nullptr;
|
2014-07-07 15:54:46 +09:00
|
|
|
float line[4], diffuse[4], ambient[4], specular[4], emission[4], shininess;
|
|
|
|
|
int priority;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-02-21 02:57:44 +00:00
|
|
|
if (PyArg_ParseTupleAndKeywords(
|
2024-01-02 18:12:54 +01:00
|
|
|
args, kwds, "|O!", (char **)kwlist_1, &FrsMaterial_Type, &brother))
|
|
|
|
|
{
|
2013-02-21 02:57:44 +00:00
|
|
|
if (!brother) {
|
|
|
|
|
self->m = new FrsMaterial();
|
2013-03-07 23:17:23 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2013-02-21 02:57:44 +00:00
|
|
|
FrsMaterial *m = ((BPy_FrsMaterial *)brother)->m;
|
|
|
|
|
if (!m) {
|
|
|
|
|
PyErr_SetString(PyExc_RuntimeError, "invalid Material object");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
self->m = new FrsMaterial(*m);
|
2009-08-02 17:38:51 +00:00
|
|
|
}
|
2013-02-21 02:57:44 +00:00
|
|
|
}
|
2020-07-29 10:53:00 +10:00
|
|
|
else if ((void)PyErr_Clear(),
|
2014-07-07 15:54:46 +09:00
|
|
|
PyArg_ParseTupleAndKeywords(args,
|
|
|
|
|
kwds,
|
|
|
|
|
"O&O&O&O&O&fi",
|
|
|
|
|
(char **)kwlist_2,
|
|
|
|
|
convert_v4,
|
|
|
|
|
line,
|
2013-02-21 02:57:44 +00:00
|
|
|
convert_v4,
|
|
|
|
|
diffuse,
|
|
|
|
|
convert_v4,
|
|
|
|
|
ambient,
|
|
|
|
|
convert_v4,
|
|
|
|
|
specular,
|
|
|
|
|
convert_v4,
|
|
|
|
|
emission,
|
2014-07-07 15:54:46 +09:00
|
|
|
&shininess,
|
|
|
|
|
&priority))
|
|
|
|
|
{
|
|
|
|
|
self->m = new FrsMaterial(line, diffuse, ambient, specular, emission, shininess, priority);
|
2013-02-21 02:57:44 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2009-08-02 17:38:51 +00:00
|
|
|
PyErr_SetString(PyExc_TypeError, "invalid argument(s)");
|
2008-07-31 11:59:06 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-07 23:17:23 +00:00
|
|
|
static void FrsMaterial_dealloc(BPy_FrsMaterial *self)
|
2008-07-31 11:59:06 +00:00
|
|
|
{
|
2013-02-16 17:13:59 +00:00
|
|
|
delete self->m;
|
2013-03-07 23:17:23 +00:00
|
|
|
Py_TYPE(self)->tp_free((PyObject *)self);
|
2008-07-31 11:59:06 +00:00
|
|
|
}
|
|
|
|
|
|
2013-03-07 23:17:23 +00:00
|
|
|
static PyObject *FrsMaterial_repr(BPy_FrsMaterial *self)
|
2008-07-31 11:59:06 +00:00
|
|
|
{
|
2013-02-14 23:50:30 +00:00
|
|
|
return PyUnicode_FromFormat("Material - address: %p", self->m);
|
2008-07-31 11:59:06 +00:00
|
|
|
}
|
|
|
|
|
|
2013-02-03 17:01:21 +00:00
|
|
|
/*----------------------mathutils callbacks ----------------------------*/
|
2010-04-17 23:47:47 +00:00
|
|
|
|
2013-02-03 17:01:21 +00:00
|
|
|
/* subtype */
|
|
|
|
|
#define MATHUTILS_SUBTYPE_DIFFUSE 1
|
|
|
|
|
#define MATHUTILS_SUBTYPE_SPECULAR 2
|
|
|
|
|
#define MATHUTILS_SUBTYPE_AMBIENT 3
|
|
|
|
|
#define MATHUTILS_SUBTYPE_EMISSION 4
|
2014-07-07 15:54:46 +09:00
|
|
|
#define MATHUTILS_SUBTYPE_LINE 5
|
2008-07-31 11:59:06 +00:00
|
|
|
|
2013-02-03 17:01:21 +00:00
|
|
|
static int FrsMaterial_mathutils_check(BaseMathObject *bmo)
|
|
|
|
|
{
|
2019-05-31 22:51:19 +10:00
|
|
|
if (!BPy_FrsMaterial_Check(bmo->cb_user)) {
|
2013-02-03 17:01:21 +00:00
|
|
|
return -1;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2013-02-03 17:01:21 +00:00
|
|
|
return 0;
|
2008-07-31 11:59:06 +00:00
|
|
|
}
|
|
|
|
|
|
2013-02-03 17:01:21 +00:00
|
|
|
static int FrsMaterial_mathutils_get(BaseMathObject *bmo, int subtype)
|
|
|
|
|
{
|
|
|
|
|
BPy_FrsMaterial *self = (BPy_FrsMaterial *)bmo->cb_user;
|
|
|
|
|
switch (subtype) {
|
2018-08-30 01:31:20 +10:00
|
|
|
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();
|
|
|
|
|
bmo->data[2] = self->m->diffuseB();
|
|
|
|
|
bmo->data[3] = self->m->diffuseA();
|
|
|
|
|
break;
|
|
|
|
|
case MATHUTILS_SUBTYPE_SPECULAR:
|
|
|
|
|
bmo->data[0] = self->m->specularR();
|
|
|
|
|
bmo->data[1] = self->m->specularG();
|
|
|
|
|
bmo->data[2] = self->m->specularB();
|
|
|
|
|
bmo->data[3] = self->m->specularA();
|
|
|
|
|
break;
|
|
|
|
|
case MATHUTILS_SUBTYPE_AMBIENT:
|
|
|
|
|
bmo->data[0] = self->m->ambientR();
|
|
|
|
|
bmo->data[1] = self->m->ambientG();
|
|
|
|
|
bmo->data[2] = self->m->ambientB();
|
|
|
|
|
bmo->data[3] = self->m->ambientA();
|
|
|
|
|
break;
|
|
|
|
|
case MATHUTILS_SUBTYPE_EMISSION:
|
|
|
|
|
bmo->data[0] = self->m->emissionR();
|
|
|
|
|
bmo->data[1] = self->m->emissionG();
|
|
|
|
|
bmo->data[2] = self->m->emissionB();
|
|
|
|
|
bmo->data[3] = self->m->emissionA();
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return -1;
|
2013-02-03 17:01:21 +00:00
|
|
|
}
|
|
|
|
|
return 0;
|
2008-07-31 11:59:06 +00:00
|
|
|
}
|
|
|
|
|
|
2013-02-03 17:01:21 +00:00
|
|
|
static int FrsMaterial_mathutils_set(BaseMathObject *bmo, int subtype)
|
|
|
|
|
{
|
|
|
|
|
BPy_FrsMaterial *self = (BPy_FrsMaterial *)bmo->cb_user;
|
|
|
|
|
switch (subtype) {
|
2018-08-30 01:31:20 +10:00
|
|
|
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;
|
|
|
|
|
case MATHUTILS_SUBTYPE_SPECULAR:
|
|
|
|
|
self->m->setSpecular(bmo->data[0], bmo->data[1], bmo->data[2], bmo->data[3]);
|
|
|
|
|
break;
|
|
|
|
|
case MATHUTILS_SUBTYPE_AMBIENT:
|
|
|
|
|
self->m->setAmbient(bmo->data[0], bmo->data[1], bmo->data[2], bmo->data[3]);
|
|
|
|
|
break;
|
|
|
|
|
case MATHUTILS_SUBTYPE_EMISSION:
|
|
|
|
|
self->m->setEmission(bmo->data[0], bmo->data[1], bmo->data[2], bmo->data[3]);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return -1;
|
2013-02-03 17:01:21 +00:00
|
|
|
}
|
|
|
|
|
return 0;
|
2008-07-31 11:59:06 +00:00
|
|
|
}
|
|
|
|
|
|
2013-02-03 17:01:21 +00:00
|
|
|
static int FrsMaterial_mathutils_get_index(BaseMathObject *bmo, int subtype, int index)
|
|
|
|
|
{
|
|
|
|
|
BPy_FrsMaterial *self = (BPy_FrsMaterial *)bmo->cb_user;
|
|
|
|
|
switch (subtype) {
|
2018-08-30 01:31:20 +10:00
|
|
|
case MATHUTILS_SUBTYPE_LINE: {
|
|
|
|
|
const float *color = self->m->line();
|
|
|
|
|
bmo->data[index] = color[index];
|
2023-09-23 21:10:22 +10:00
|
|
|
break;
|
|
|
|
|
}
|
2018-08-30 01:31:20 +10:00
|
|
|
case MATHUTILS_SUBTYPE_DIFFUSE: {
|
|
|
|
|
const float *color = self->m->diffuse();
|
|
|
|
|
bmo->data[index] = color[index];
|
2023-09-23 21:10:22 +10:00
|
|
|
break;
|
|
|
|
|
}
|
2018-08-30 01:31:20 +10:00
|
|
|
case MATHUTILS_SUBTYPE_SPECULAR: {
|
|
|
|
|
const float *color = self->m->specular();
|
|
|
|
|
bmo->data[index] = color[index];
|
2023-09-23 21:10:22 +10:00
|
|
|
break;
|
|
|
|
|
}
|
2018-08-30 01:31:20 +10:00
|
|
|
case MATHUTILS_SUBTYPE_AMBIENT: {
|
|
|
|
|
const float *color = self->m->ambient();
|
|
|
|
|
bmo->data[index] = color[index];
|
2023-09-23 21:10:22 +10:00
|
|
|
break;
|
|
|
|
|
}
|
2018-08-30 01:31:20 +10:00
|
|
|
case MATHUTILS_SUBTYPE_EMISSION: {
|
|
|
|
|
const float *color = self->m->emission();
|
|
|
|
|
bmo->data[index] = color[index];
|
2023-09-23 21:10:22 +10:00
|
|
|
break;
|
|
|
|
|
}
|
2018-08-30 01:31:20 +10:00
|
|
|
default:
|
|
|
|
|
return -1;
|
2013-02-03 17:01:21 +00:00
|
|
|
}
|
|
|
|
|
return 0;
|
2008-07-31 11:59:06 +00:00
|
|
|
}
|
|
|
|
|
|
2013-02-03 17:01:21 +00:00
|
|
|
static int FrsMaterial_mathutils_set_index(BaseMathObject *bmo, int subtype, int index)
|
|
|
|
|
{
|
|
|
|
|
BPy_FrsMaterial *self = (BPy_FrsMaterial *)bmo->cb_user;
|
|
|
|
|
float color[4];
|
|
|
|
|
switch (subtype) {
|
2018-08-30 01:31:20 +10:00
|
|
|
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];
|
|
|
|
|
self->m->setDiffuse(color[0], color[1], color[2], color[3]);
|
|
|
|
|
break;
|
|
|
|
|
case MATHUTILS_SUBTYPE_SPECULAR:
|
|
|
|
|
copy_v4_v4(color, self->m->specular());
|
|
|
|
|
color[index] = bmo->data[index];
|
|
|
|
|
self->m->setSpecular(color[0], color[1], color[2], color[3]);
|
|
|
|
|
break;
|
|
|
|
|
case MATHUTILS_SUBTYPE_AMBIENT:
|
|
|
|
|
copy_v4_v4(color, self->m->ambient());
|
|
|
|
|
color[index] = bmo->data[index];
|
|
|
|
|
self->m->setAmbient(color[0], color[1], color[2], color[3]);
|
|
|
|
|
break;
|
|
|
|
|
case MATHUTILS_SUBTYPE_EMISSION:
|
|
|
|
|
copy_v4_v4(color, self->m->emission());
|
|
|
|
|
color[index] = bmo->data[index];
|
|
|
|
|
self->m->setEmission(color[0], color[1], color[2], color[3]);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return -1;
|
2013-02-03 17:01:21 +00:00
|
|
|
}
|
|
|
|
|
return 0;
|
2008-07-31 11:59:06 +00:00
|
|
|
}
|
|
|
|
|
|
2013-02-03 17:01:21 +00:00
|
|
|
static Mathutils_Callback FrsMaterial_mathutils_cb = {
|
|
|
|
|
FrsMaterial_mathutils_check,
|
|
|
|
|
FrsMaterial_mathutils_get,
|
|
|
|
|
FrsMaterial_mathutils_set,
|
|
|
|
|
FrsMaterial_mathutils_get_index,
|
2019-02-03 14:01:45 +11:00
|
|
|
FrsMaterial_mathutils_set_index,
|
2013-02-03 17:01:21 +00:00
|
|
|
};
|
2008-07-31 11:59:06 +00:00
|
|
|
|
2022-09-25 17:04:52 +10:00
|
|
|
static uchar FrsMaterial_mathutils_cb_index = -1;
|
2010-04-17 23:47:47 +00:00
|
|
|
|
2013-02-03 17:01:21 +00:00
|
|
|
void FrsMaterial_mathutils_register_callback()
|
|
|
|
|
{
|
|
|
|
|
FrsMaterial_mathutils_cb_index = Mathutils_RegisterCallback(&FrsMaterial_mathutils_cb);
|
2008-07-31 11:59:06 +00:00
|
|
|
}
|
|
|
|
|
|
2013-02-03 17:01:21 +00:00
|
|
|
/*----------------------FrsMaterial get/setters ----------------------------*/
|
2008-07-31 11:59:06 +00:00
|
|
|
|
2024-01-25 10:22:16 +11:00
|
|
|
PyDoc_STRVAR(
|
|
|
|
|
/* Wrap. */
|
|
|
|
|
FrsMaterial_line_doc,
|
|
|
|
|
"RGBA components of the line color of the material.\n"
|
|
|
|
|
"\n"
|
2025-08-22 14:05:28 +10:00
|
|
|
":type: :class:`mathutils.Vector`\n");
|
2022-10-03 17:37:25 -05:00
|
|
|
static PyObject *FrsMaterial_line_get(BPy_FrsMaterial *self, void * /*closure*/)
|
2014-07-07 15:54:46 +09:00
|
|
|
{
|
|
|
|
|
return Vector_CreatePyObject_cb(
|
|
|
|
|
(PyObject *)self, 4, FrsMaterial_mathutils_cb_index, MATHUTILS_SUBTYPE_LINE);
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-03 17:37:25 -05:00
|
|
|
static int FrsMaterial_line_set(BPy_FrsMaterial *self, PyObject *value, void * /*closure*/)
|
2014-07-07 15:54:46 +09:00
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-25 10:22:16 +11:00
|
|
|
PyDoc_STRVAR(
|
|
|
|
|
/* Wrap. */
|
|
|
|
|
FrsMaterial_diffuse_doc,
|
|
|
|
|
"RGBA components of the diffuse color of the material.\n"
|
|
|
|
|
"\n"
|
2025-08-22 14:05:28 +10:00
|
|
|
":type: :class:`mathutils.Vector`\n");
|
2022-10-03 17:37:25 -05:00
|
|
|
static PyObject *FrsMaterial_diffuse_get(BPy_FrsMaterial *self, void * /*closure*/)
|
2013-02-03 17:01:21 +00:00
|
|
|
{
|
|
|
|
|
return Vector_CreatePyObject_cb(
|
|
|
|
|
(PyObject *)self, 4, FrsMaterial_mathutils_cb_index, MATHUTILS_SUBTYPE_DIFFUSE);
|
2008-07-31 11:59:06 +00:00
|
|
|
}
|
|
|
|
|
|
2022-10-03 17:37:25 -05:00
|
|
|
static int FrsMaterial_diffuse_set(BPy_FrsMaterial *self, PyObject *value, void * /*closure*/)
|
2013-02-03 17:01:21 +00:00
|
|
|
{
|
|
|
|
|
float color[4];
|
2014-06-24 22:48:15 +09:00
|
|
|
if (mathutils_array_parse(color, 4, 4, value, "value must be a 4-dimensional vector") == -1) {
|
2013-02-03 17:01:21 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
self->m->setDiffuse(color[0], color[1], color[2], color[3]);
|
|
|
|
|
return 0;
|
2008-07-31 11:59:06 +00:00
|
|
|
}
|
|
|
|
|
|
2024-01-25 10:22:16 +11:00
|
|
|
PyDoc_STRVAR(
|
|
|
|
|
/* Wrap. */
|
|
|
|
|
FrsMaterial_specular_doc,
|
|
|
|
|
"RGBA components of the specular color of the material.\n"
|
|
|
|
|
"\n"
|
2025-08-22 14:05:28 +10:00
|
|
|
":type: :class:`mathutils.Vector`\n");
|
2022-10-03 17:37:25 -05:00
|
|
|
static PyObject *FrsMaterial_specular_get(BPy_FrsMaterial *self, void * /*closure*/)
|
2013-02-03 17:01:21 +00:00
|
|
|
{
|
|
|
|
|
return Vector_CreatePyObject_cb(
|
|
|
|
|
(PyObject *)self, 4, FrsMaterial_mathutils_cb_index, MATHUTILS_SUBTYPE_SPECULAR);
|
2008-07-31 11:59:06 +00:00
|
|
|
}
|
|
|
|
|
|
2022-10-03 17:37:25 -05:00
|
|
|
static int FrsMaterial_specular_set(BPy_FrsMaterial *self, PyObject *value, void * /*closure*/)
|
2013-02-03 17:01:21 +00:00
|
|
|
{
|
|
|
|
|
float color[4];
|
2014-06-24 22:48:15 +09:00
|
|
|
if (mathutils_array_parse(color, 4, 4, value, "value must be a 4-dimensional vector") == -1) {
|
2013-02-03 17:01:21 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
self->m->setSpecular(color[0], color[1], color[2], color[3]);
|
|
|
|
|
return 0;
|
2008-07-31 11:59:06 +00:00
|
|
|
}
|
|
|
|
|
|
2024-01-25 10:22:16 +11:00
|
|
|
PyDoc_STRVAR(
|
|
|
|
|
/* Wrap. */
|
|
|
|
|
FrsMaterial_ambient_doc,
|
|
|
|
|
"RGBA components of the ambient color of the material.\n"
|
|
|
|
|
"\n"
|
2025-08-22 14:05:28 +10:00
|
|
|
":type: :class:`mathutils.Color`\n");
|
2022-10-03 17:37:25 -05:00
|
|
|
static PyObject *FrsMaterial_ambient_get(BPy_FrsMaterial *self, void * /*closure*/)
|
2013-02-03 17:01:21 +00:00
|
|
|
{
|
|
|
|
|
return Vector_CreatePyObject_cb(
|
|
|
|
|
(PyObject *)self, 4, FrsMaterial_mathutils_cb_index, MATHUTILS_SUBTYPE_AMBIENT);
|
2008-07-31 11:59:06 +00:00
|
|
|
}
|
|
|
|
|
|
2022-10-03 17:37:25 -05:00
|
|
|
static int FrsMaterial_ambient_set(BPy_FrsMaterial *self, PyObject *value, void * /*closure*/)
|
2013-02-03 17:01:21 +00:00
|
|
|
{
|
|
|
|
|
float color[4];
|
2014-06-24 22:48:15 +09:00
|
|
|
if (mathutils_array_parse(color, 4, 4, value, "value must be a 4-dimensional vector") == -1) {
|
2013-02-03 17:01:21 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
self->m->setAmbient(color[0], color[1], color[2], color[3]);
|
|
|
|
|
return 0;
|
2008-07-31 11:59:06 +00:00
|
|
|
}
|
|
|
|
|
|
2024-01-25 10:22:16 +11:00
|
|
|
PyDoc_STRVAR(
|
|
|
|
|
/* Wrap. */
|
|
|
|
|
FrsMaterial_emission_doc,
|
|
|
|
|
"RGBA components of the emissive color of the material.\n"
|
|
|
|
|
"\n"
|
2025-08-22 14:05:28 +10:00
|
|
|
":type: :class:`mathutils.Color`\n");
|
2022-10-03 17:37:25 -05:00
|
|
|
static PyObject *FrsMaterial_emission_get(BPy_FrsMaterial *self, void * /*closure*/)
|
2013-02-03 17:01:21 +00:00
|
|
|
{
|
|
|
|
|
return Vector_CreatePyObject_cb(
|
|
|
|
|
(PyObject *)self, 4, FrsMaterial_mathutils_cb_index, MATHUTILS_SUBTYPE_EMISSION);
|
2008-07-31 11:59:06 +00:00
|
|
|
}
|
|
|
|
|
|
2022-10-03 17:37:25 -05:00
|
|
|
static int FrsMaterial_emission_set(BPy_FrsMaterial *self, PyObject *value, void * /*closure*/)
|
2013-02-03 17:01:21 +00:00
|
|
|
{
|
|
|
|
|
float color[4];
|
2014-06-24 22:48:15 +09:00
|
|
|
if (mathutils_array_parse(color, 4, 4, value, "value must be a 4-dimensional vector") == -1) {
|
2013-02-03 17:01:21 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
self->m->setEmission(color[0], color[1], color[2], color[3]);
|
|
|
|
|
return 0;
|
2008-07-31 11:59:06 +00:00
|
|
|
}
|
|
|
|
|
|
2024-01-25 10:22:16 +11:00
|
|
|
PyDoc_STRVAR(
|
|
|
|
|
/* Wrap. */
|
|
|
|
|
FrsMaterial_shininess_doc,
|
|
|
|
|
"Shininess coefficient of the material.\n"
|
|
|
|
|
"\n"
|
2025-08-22 14:05:28 +10:00
|
|
|
":type: float\n");
|
2022-10-03 17:37:25 -05:00
|
|
|
static PyObject *FrsMaterial_shininess_get(BPy_FrsMaterial *self, void * /*closure*/)
|
2013-02-03 17:01:21 +00:00
|
|
|
{
|
|
|
|
|
return PyFloat_FromDouble(self->m->shininess());
|
2008-07-31 11:59:06 +00:00
|
|
|
}
|
|
|
|
|
|
2022-10-03 17:37:25 -05:00
|
|
|
static int FrsMaterial_shininess_set(BPy_FrsMaterial *self, PyObject *value, void * /*closure*/)
|
2013-02-03 17:01:21 +00:00
|
|
|
{
|
|
|
|
|
float scalar;
|
2019-07-10 14:41:19 +10:00
|
|
|
if ((scalar = PyFloat_AsDouble(value)) == -1.0f && PyErr_Occurred()) {
|
|
|
|
|
/* parsed item not a number */
|
2013-02-03 17:01:21 +00:00
|
|
|
PyErr_SetString(PyExc_TypeError, "value must be a number");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
self->m->setShininess(scalar);
|
|
|
|
|
return 0;
|
2008-07-31 11:59:06 +00:00
|
|
|
}
|
|
|
|
|
|
2024-01-25 10:22:16 +11:00
|
|
|
PyDoc_STRVAR(
|
|
|
|
|
/* Wrap. */
|
|
|
|
|
FrsMaterial_priority_doc,
|
|
|
|
|
"Line color priority of the material.\n"
|
|
|
|
|
"\n"
|
2025-08-22 14:05:28 +10:00
|
|
|
":type: int\n");
|
2022-10-03 17:37:25 -05:00
|
|
|
static PyObject *FrsMaterial_priority_get(BPy_FrsMaterial *self, void * /*closure*/)
|
2014-07-07 15:54:46 +09:00
|
|
|
{
|
|
|
|
|
return PyLong_FromLong(self->m->priority());
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-03 17:37:25 -05:00
|
|
|
static int FrsMaterial_priority_set(BPy_FrsMaterial *self, PyObject *value, void * /*closure*/)
|
2014-07-07 15:54:46 +09:00
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-03 17:01:21 +00:00
|
|
|
static PyGetSetDef BPy_FrsMaterial_getseters[] = {
|
2019-12-20 10:42:57 +11:00
|
|
|
{"line",
|
2014-07-07 15:54:46 +09:00
|
|
|
(getter)FrsMaterial_line_get,
|
|
|
|
|
(setter)FrsMaterial_line_set,
|
2019-12-20 10:42:57 +11:00
|
|
|
FrsMaterial_line_doc,
|
2020-11-06 17:49:09 +01:00
|
|
|
nullptr},
|
2019-12-20 10:42:57 +11:00
|
|
|
{"diffuse",
|
2013-03-07 23:17:23 +00:00
|
|
|
(getter)FrsMaterial_diffuse_get,
|
|
|
|
|
(setter)FrsMaterial_diffuse_set,
|
2019-12-20 10:42:57 +11:00
|
|
|
FrsMaterial_diffuse_doc,
|
2020-11-06 17:49:09 +01:00
|
|
|
nullptr},
|
2019-12-20 10:42:57 +11:00
|
|
|
{"specular",
|
2013-03-07 23:17:23 +00:00
|
|
|
(getter)FrsMaterial_specular_get,
|
|
|
|
|
(setter)FrsMaterial_specular_set,
|
2019-12-20 10:42:57 +11:00
|
|
|
FrsMaterial_specular_doc,
|
2020-11-06 17:49:09 +01:00
|
|
|
nullptr},
|
2019-12-20 10:42:57 +11:00
|
|
|
{"ambient",
|
2013-03-07 23:17:23 +00:00
|
|
|
(getter)FrsMaterial_ambient_get,
|
|
|
|
|
(setter)FrsMaterial_ambient_set,
|
2019-12-20 10:42:57 +11:00
|
|
|
FrsMaterial_ambient_doc,
|
2020-11-06 17:49:09 +01:00
|
|
|
nullptr},
|
2019-12-20 10:42:57 +11:00
|
|
|
{"emission",
|
2013-03-07 23:17:23 +00:00
|
|
|
(getter)FrsMaterial_emission_get,
|
|
|
|
|
(setter)FrsMaterial_emission_set,
|
2019-12-20 10:42:57 +11:00
|
|
|
FrsMaterial_emission_doc,
|
2020-11-06 17:49:09 +01:00
|
|
|
nullptr},
|
2019-12-20 10:42:57 +11:00
|
|
|
{"shininess",
|
2013-03-07 23:17:23 +00:00
|
|
|
(getter)FrsMaterial_shininess_get,
|
|
|
|
|
(setter)FrsMaterial_shininess_set,
|
2019-12-20 10:42:57 +11:00
|
|
|
FrsMaterial_shininess_doc,
|
2020-11-06 17:49:09 +01:00
|
|
|
nullptr},
|
2019-12-20 10:42:57 +11:00
|
|
|
{"priority",
|
2014-07-07 15:54:46 +09:00
|
|
|
(getter)FrsMaterial_priority_get,
|
|
|
|
|
(setter)FrsMaterial_priority_set,
|
2019-12-20 10:42:57 +11:00
|
|
|
FrsMaterial_priority_doc,
|
2020-11-06 17:49:09 +01:00
|
|
|
nullptr},
|
|
|
|
|
{nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
|
2010-04-17 23:47:47 +00:00
|
|
|
};
|
|
|
|
|
|
2015-05-31 17:46:58 +09:00
|
|
|
static PyObject *BPy_FrsMaterial_richcmpr(PyObject *objectA,
|
|
|
|
|
PyObject *objectB,
|
|
|
|
|
int comparison_type)
|
|
|
|
|
{
|
2020-11-06 17:49:09 +01:00
|
|
|
const BPy_FrsMaterial *matA = nullptr, *matB = nullptr;
|
2020-11-06 14:25:30 +01:00
|
|
|
bool result = false;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-05-31 17:46:58 +09:00
|
|
|
if (!BPy_FrsMaterial_Check(objectA) || !BPy_FrsMaterial_Check(objectB)) {
|
|
|
|
|
if (comparison_type == Py_NE) {
|
|
|
|
|
Py_RETURN_TRUE;
|
|
|
|
|
}
|
2020-08-07 12:39:05 +02:00
|
|
|
|
|
|
|
|
Py_RETURN_FALSE;
|
2015-05-31 17:46:58 +09:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-05-31 17:46:58 +09:00
|
|
|
matA = (BPy_FrsMaterial *)objectA;
|
|
|
|
|
matB = (BPy_FrsMaterial *)objectB;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-05-31 17:46:58 +09:00
|
|
|
switch (comparison_type) {
|
|
|
|
|
case Py_NE:
|
|
|
|
|
result = (*matA->m) != (*matB->m);
|
|
|
|
|
break;
|
|
|
|
|
case Py_EQ:
|
|
|
|
|
result = (*matA->m) == (*matB->m);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
PyErr_SetString(PyExc_TypeError, "Material does not support this comparison type");
|
2020-11-06 17:49:09 +01:00
|
|
|
return nullptr;
|
2015-05-31 17:46:58 +09:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-05-31 17:46:58 +09:00
|
|
|
if (result == true) {
|
|
|
|
|
Py_RETURN_TRUE;
|
|
|
|
|
}
|
2020-08-07 12:39:05 +02:00
|
|
|
|
|
|
|
|
Py_RETURN_FALSE;
|
2015-05-31 17:46:58 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static Py_hash_t FrsMaterial_hash(PyObject *self)
|
|
|
|
|
{
|
2022-09-25 17:04:52 +10:00
|
|
|
return (Py_uhash_t)BLI_hash_mm2((const uchar *)self, sizeof(*self), 0);
|
2015-05-31 17:46:58 +09:00
|
|
|
}
|
2010-04-17 23:47:47 +00:00
|
|
|
/*-----------------------BPy_FrsMaterial type definition ------------------------------*/
|
|
|
|
|
|
|
|
|
|
PyTypeObject FrsMaterial_Type = {
|
2023-07-16 17:43:31 +10:00
|
|
|
/*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0)
|
2022-11-07 22:34:35 +11:00
|
|
|
/*tp_name*/ "Material",
|
|
|
|
|
/*tp_basicsize*/ sizeof(BPy_FrsMaterial),
|
|
|
|
|
/*tp_itemsize*/ 0,
|
|
|
|
|
/*tp_dealloc*/ (destructor)FrsMaterial_dealloc,
|
|
|
|
|
/*tp_vectorcall_offset*/ 0,
|
|
|
|
|
/*tp_getattr*/ nullptr,
|
|
|
|
|
/*tp_setattr*/ nullptr,
|
|
|
|
|
/*tp_as_async*/ nullptr,
|
|
|
|
|
/*tp_repr*/ (reprfunc)FrsMaterial_repr,
|
|
|
|
|
/*tp_as_number*/ nullptr,
|
|
|
|
|
/*tp_as_sequence*/ nullptr,
|
|
|
|
|
/*tp_as_mapping*/ nullptr,
|
|
|
|
|
/*tp_hash*/ (hashfunc)FrsMaterial_hash,
|
|
|
|
|
/*tp_call*/ nullptr,
|
|
|
|
|
/*tp_str*/ nullptr,
|
|
|
|
|
/*tp_getattro*/ nullptr,
|
|
|
|
|
/*tp_setattro*/ nullptr,
|
|
|
|
|
/*tp_as_buffer*/ nullptr,
|
|
|
|
|
/*tp_flags*/ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
|
|
|
|
|
/*tp_doc*/ FrsMaterial_doc,
|
|
|
|
|
/*tp_traverse*/ nullptr,
|
|
|
|
|
/*tp_clear*/ nullptr,
|
|
|
|
|
/*tp_richcompare*/ (richcmpfunc)BPy_FrsMaterial_richcmpr,
|
|
|
|
|
/*tp_weaklistoffset*/ 0,
|
|
|
|
|
/*tp_iter*/ nullptr,
|
|
|
|
|
/*tp_iternext*/ nullptr,
|
|
|
|
|
/*tp_methods*/ nullptr,
|
|
|
|
|
/*tp_members*/ nullptr,
|
|
|
|
|
/*tp_getset*/ BPy_FrsMaterial_getseters,
|
|
|
|
|
/*tp_base*/ nullptr,
|
|
|
|
|
/*tp_dict*/ nullptr,
|
|
|
|
|
/*tp_descr_get*/ nullptr,
|
|
|
|
|
/*tp_descr_set*/ nullptr,
|
|
|
|
|
/*tp_dictoffset*/ 0,
|
|
|
|
|
/*tp_init*/ (initproc)FrsMaterial_init,
|
|
|
|
|
/*tp_alloc*/ nullptr,
|
|
|
|
|
/*tp_new*/ PyType_GenericNew,
|
2010-04-17 23:47:47 +00:00
|
|
|
};
|
|
|
|
|
|
2008-07-31 11:59:06 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////
|