Blender V5.3
BPy_FEdgeSmooth.cpp
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2004-2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "BPy_FEdgeSmooth.h"
10
11#include "../../BPy_Convert.h"
13
14#include "BLI_sys_types.hh"
15
16using namespace Freestyle;
17
19
20/*----------------------FEdgeSmooth methods ----------------------------*/
21
23 /* Wrap. */
24 FEdgeSmooth_doc,
25 "Class hierarchy: :class:`Interface1D` > :class:`FEdge` > :class:`FEdgeSmooth`\n"
26 "\n"
27 "Class defining a smooth edge. This kind of edge typically runs across\n"
28 "a face of the input mesh. It can be a silhouette, a ridge or valley,\n"
29 "a suggestive contour.\n"
30 "\n"
31 ".. method:: __init__(*args)\n"
32 "\n"
33 " Accepted call signatures:\n"
34 "\n"
35 " - ``__init__()``\n"
36 " - ``__init__(brother)``\n"
37 " - ``__init__(first_vertex, second_vertex)``\n"
38 "\n"
39 " Builds an :class:`FEdgeSmooth` using the default constructor,\n"
40 " copy constructor, or between two :class:`SVertex`.\n"
41 "\n"
42 " :param brother: An FEdgeSmooth object.\n"
43 " :type brother: :class:`FEdgeSmooth`\n"
44 " :param first_vertex: The first SVertex object.\n"
45 " :type first_vertex: :class:`SVertex`\n"
46 " :param second_vertex: The second SVertex object.\n"
47 " :type second_vertex: :class:`SVertex`\n");
48static int FEdgeSmooth_init(BPy_FEdgeSmooth *self, PyObject *args, PyObject *kwds)
49{
50 static const char *kwlist_1[] = {"brother", nullptr};
51 static const char *kwlist_2[] = {"first_vertex", "second_vertex", nullptr};
52 PyObject *obj1 = nullptr, *obj2 = nullptr;
53
54 if (PyArg_ParseTupleAndKeywords(args,
55 kwds,
56 "|" /* Optional arguments. */
57 "O!" /* `brother` */
58 ":__init__",
59 (char **)kwlist_1,
61 &obj1))
62 {
63 if (!obj1) {
64 self->fes = new FEdgeSmooth();
65 }
66 else {
67 self->fes = new FEdgeSmooth(*(((BPy_FEdgeSmooth *)obj1)->fes));
68 }
69 }
70 else if ((void)PyErr_Clear(),
71 PyArg_ParseTupleAndKeywords(args,
72 kwds,
73 "O!" /* `first_vertex` */
74 "O!" /* `second_vertex` */
75 ":__init__",
76 (char **)kwlist_2,
78 &obj1,
80 &obj2))
81 {
82 self->fes = new FEdgeSmooth(((BPy_SVertex *)obj1)->sv, ((BPy_SVertex *)obj2)->sv);
83 }
84 else {
85 PyErr_SetString(PyExc_TypeError, "invalid argument(s)");
86 return -1;
87 }
88 self->py_fe.fe = self->fes;
89 self->py_fe.py_if1D.if1D = self->fes;
90 self->py_fe.py_if1D.borrowed = false;
91 return 0;
92}
93
94/*----------------------mathutils callbacks ----------------------------*/
95
97{
98 if (!BPy_FEdgeSmooth_Check(bmo->cb_user)) {
99 return -1;
100 }
101 return 0;
102}
103
104static int FEdgeSmooth_mathutils_get(blender::BaseMathObject *bmo, int /*subtype*/)
105{
106 BPy_FEdgeSmooth *self = (BPy_FEdgeSmooth *)bmo->cb_user;
107 Vec3r p(self->fes->normal());
108 bmo->data[0] = p[0];
109 bmo->data[1] = p[1];
110 bmo->data[2] = p[2];
111 return 0;
112}
113
114static int FEdgeSmooth_mathutils_set(blender::BaseMathObject *bmo, int /*subtype*/)
115{
116 BPy_FEdgeSmooth *self = (BPy_FEdgeSmooth *)bmo->cb_user;
117 Vec3r p(bmo->data[0], bmo->data[1], bmo->data[2]);
118 self->fes->setNormal(p);
119 return 0;
120}
121
123 int /*subtype*/,
124 int index)
125{
126 BPy_FEdgeSmooth *self = (BPy_FEdgeSmooth *)bmo->cb_user;
127 Vec3r p(self->fes->normal());
128 bmo->data[index] = p[index];
129 return 0;
130}
131
133 int /*subtype*/,
134 int index)
135{
136 BPy_FEdgeSmooth *self = (BPy_FEdgeSmooth *)bmo->cb_user;
137 Vec3r p(self->fes->normal());
138 p[index] = bmo->data[index];
139 self->fes->setNormal(p);
140 return 0;
141}
142
150
152
157
158/*----------------------FEdgeSmooth get/setters ----------------------------*/
159
161 /* Wrap. */
162 FEdgeSmooth_normal_doc,
163 "The normal of the face that this FEdge is running across.\n"
164 "\n"
165 ":type: :class:`mathutils.Vector`\n");
166static PyObject *FEdgeSmooth_normal_get(BPy_FEdgeSmooth *self, void * /*closure*/)
167{
169}
170
171static int FEdgeSmooth_normal_set(BPy_FEdgeSmooth *self, PyObject *value, void * /*closure*/)
172{
173 float v[3];
174 if (blender::mathutils_array_parse(v, 3, 3, value, "value must be a 3-dimensional vector") == -1)
175 {
176 return -1;
177 }
178 Vec3r p(v[0], v[1], v[2]);
179 self->fes->setNormal(p);
180 return 0;
181}
182
184 /* Wrap. */
185 FEdgeSmooth_material_index_doc,
186 "The index of the material of the face that this FEdge is running across.\n"
187 "\n"
188 ":type: int\n");
189static PyObject *FEdgeSmooth_material_index_get(BPy_FEdgeSmooth *self, void * /*closure*/)
190{
191 return PyLong_FromLong(self->fes->frs_materialIndex());
192}
193
195 PyObject *value,
196 void * /*closure*/)
197{
198 uint i = PyLong_AsUnsignedLong(value);
199 if (PyErr_Occurred()) {
200 return -1;
201 }
202 self->fes->setFrsMaterialIndex(i);
203 return 0;
204}
205
207 /* Wrap. */
208 FEdgeSmooth_material_doc,
209 "The material of the face that this FEdge is running across.\n"
210 "\n"
211 ":type: :class:`Material`\n");
212static PyObject *FEdgeSmooth_material_get(BPy_FEdgeSmooth *self, void * /*closure*/)
213{
215}
216
218 /* Wrap. */
219 FEdgeSmooth_face_mark_doc,
220 "The face mark of the face that this FEdge is running across.\n"
221 "\n"
222 ":type: bool\n");
223static PyObject *FEdgeSmooth_face_mark_get(BPy_FEdgeSmooth *self, void * /*closure*/)
224{
225 return PyBool_from_bool(self->fes->faceMark());
226}
227
228static int FEdgeSmooth_face_mark_set(BPy_FEdgeSmooth *self, PyObject *value, void * /*closure*/)
229{
230 if (!PyBool_Check(value)) {
231 return -1;
232 }
233 self->fes->setFaceMark(bool_from_PyBool(value));
234 return 0;
235}
236
237static PyGetSetDef BPy_FEdgeSmooth_getseters[] = {
238 {"normal",
241 FEdgeSmooth_normal_doc,
242 nullptr},
243 {"material_index",
246 FEdgeSmooth_material_index_doc,
247 nullptr},
248 {"material",
250 (setter) nullptr,
251 FEdgeSmooth_material_doc,
252 nullptr},
253 {"face_mark",
256 FEdgeSmooth_face_mark_doc,
257 nullptr},
258 {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
259};
260
261/*-----------------------BPy_FEdgeSmooth type definition ------------------------------*/
262
263PyTypeObject FEdgeSmooth_Type = {
264 /*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0)
265 /*tp_name*/ "FEdgeSmooth",
266 /*tp_basicsize*/ sizeof(BPy_FEdgeSmooth),
267 /*tp_itemsize*/ 0,
268 /*tp_dealloc*/ nullptr,
269 /*tp_vectorcall_offset*/ 0,
270 /*tp_getattr*/ nullptr,
271 /*tp_setattr*/ nullptr,
272 /*tp_as_async*/ nullptr,
273 /*tp_repr*/ nullptr,
274 /*tp_as_number*/ nullptr,
275 /*tp_as_sequence*/ nullptr,
276 /*tp_as_mapping*/ nullptr,
277 /*tp_hash*/ nullptr,
278 /*tp_call*/ nullptr,
279 /*tp_str*/ nullptr,
280 /*tp_getattro*/ nullptr,
281 /*tp_setattro*/ nullptr,
282 /*tp_as_buffer*/ nullptr,
283 /*tp_flags*/ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
284 /*tp_doc*/ FEdgeSmooth_doc,
285 /*tp_traverse*/ nullptr,
286 /*tp_clear*/ nullptr,
287 /*tp_richcompare*/ nullptr,
288 /*tp_weaklistoffset*/ 0,
289 /*tp_iter*/ nullptr,
290 /*tp_iternext*/ nullptr,
291 /*tp_methods*/ nullptr,
292 /*tp_members*/ nullptr,
293 /*tp_getset*/ BPy_FEdgeSmooth_getseters,
294 /*tp_base*/ &FEdge_Type,
295 /*tp_dict*/ nullptr,
296 /*tp_descr_get*/ nullptr,
297 /*tp_descr_set*/ nullptr,
298 /*tp_dictoffset*/ 0,
299 /*tp_init*/ (initproc)FEdgeSmooth_init,
300 /*tp_alloc*/ nullptr,
301 /*tp_new*/ nullptr,
302};
303
bool bool_from_PyBool(PyObject *b)
PyObject * PyBool_from_bool(bool b)
PyObject * BPy_FrsMaterial_from_FrsMaterial(const FrsMaterial &m)
static int FEdgeSmooth_material_index_set(BPy_FEdgeSmooth *self, PyObject *value, void *)
static int FEdgeSmooth_mathutils_set(blender::BaseMathObject *bmo, int)
void FEdgeSmooth_mathutils_register_callback()
static PyObject * FEdgeSmooth_normal_get(BPy_FEdgeSmooth *self, void *)
static int FEdgeSmooth_normal_set(BPy_FEdgeSmooth *self, PyObject *value, void *)
static PyObject * FEdgeSmooth_material_index_get(BPy_FEdgeSmooth *self, void *)
static int FEdgeSmooth_mathutils_check(blender::BaseMathObject *bmo)
PyTypeObject FEdgeSmooth_Type
static PyObject * FEdgeSmooth_face_mark_get(BPy_FEdgeSmooth *self, void *)
static int FEdgeSmooth_init(BPy_FEdgeSmooth *self, PyObject *args, PyObject *kwds)
static uchar FEdgeSmooth_mathutils_cb_index
static int FEdgeSmooth_mathutils_set_index(blender::BaseMathObject *bmo, int, int index)
static PyObject * FEdgeSmooth_material_get(BPy_FEdgeSmooth *self, void *)
static int FEdgeSmooth_face_mark_set(BPy_FEdgeSmooth *self, PyObject *value, void *)
static PyGetSetDef BPy_FEdgeSmooth_getseters[]
static blender::Mathutils_Callback FEdgeSmooth_mathutils_cb
static int FEdgeSmooth_mathutils_get_index(blender::BaseMathObject *bmo, int, int index)
static int FEdgeSmooth_mathutils_get(blender::BaseMathObject *bmo, int)
#define BPy_FEdgeSmooth_Check(v)
PyTypeObject FEdge_Type
PyDoc_STRVAR(FalseBP1D___doc__, "Class hierarchy: :class:`freestyle.types.BinaryPredicate1D` > :class:`FalseBP1D`\n" "\n" ".. method:: __call__(inter1, inter2)\n" "\n" " Always returns false.\n" "\n" " :param inter1: The first Interface1D object.\n" " :type inter1: :class:`freestyle.types.Interface1D`\n" " :param inter2: The second Interface1D object.\n" " :type inter2: :class:`freestyle.types.Interface1D`\n" " :return: False.\n" " :rtype: bool\n")
PyTypeObject SVertex_Type
const Vec3r & normal()
void setNormal(const Vec3r &iNormal)
void setFrsMaterialIndex(uint i)
const FrsMaterial & frs_material() const
void setFaceMark(bool iFaceMark)
uint frs_materialIndex() const
#define index(i)
unsigned int uchar
VecMat::Vec3< real > Vec3r
Definition Geom.h:30
inherits from class Rep
Definition AppCanvas.cpp:20
PyObject * Vector_CreatePyObject_cb(PyObject *cb_user, int vec_num, uchar cb_type, uchar cb_subtype)
int mathutils_array_parse(float *array, int array_num_min, int array_num_max, PyObject *value, const char *error_prefix)
Definition mathutils.cc:97
Freestyle::FEdgeSmooth * fes
BPy_Interface1D py_if1D
Definition BPy_FEdge.h:23
Freestyle::FEdge * fe
Definition BPy_FEdge.h:24
PyObject_HEAD Freestyle::Interface1D * if1D