Blender V5.3
BPy_FEdgeSharp.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_FEdgeSharp.h"
10
11#include "../../BPy_Convert.h"
13
14#include "BLI_sys_types.hh"
15
16using namespace Freestyle;
17
19
20/*----------------------FEdgeSharp methods ----------------------------*/
21
23 /* Wrap. */
24 FEdgeSharp_doc,
25 "Class hierarchy: :class:`Interface1D` > :class:`FEdge` > :class:`FEdgeSharp`\n"
26 "\n"
27 "Class defining a sharp FEdge. A Sharp FEdge corresponds to an initial\n"
28 "edge of the input mesh. It can be a silhouette, a crease or a border.\n"
29 "If it is a crease edge, then it is bordered by two faces of the mesh.\n"
30 "Face a lies on its right whereas Face b lies on its left. If it is a\n"
31 "border edge, then it doesn't have any face on its right, and thus Face\n"
32 "a is None.\n"
33 "\n"
34 ".. method:: __init__(*args)\n"
35 "\n"
36 " Accepted call signatures:\n"
37 "\n"
38 " - ``__init__()``\n"
39 " - ``__init__(brother)``\n"
40 " - ``__init__(first_vertex, second_vertex)``\n"
41 "\n"
42 " Builds an :class:`FEdgeSharp` using the default constructor,\n"
43 " copy constructor, or between two :class:`SVertex` objects.\n"
44 "\n"
45 " :param brother: An FEdgeSharp object.\n"
46 " :type brother: :class:`FEdgeSharp`\n"
47 " :param first_vertex: The first SVertex object.\n"
48 " :type first_vertex: :class:`SVertex`\n"
49 " :param second_vertex: The second SVertex object.\n"
50 " :type second_vertex: :class:`SVertex`\n");
51static int FEdgeSharp_init(BPy_FEdgeSharp *self, PyObject *args, PyObject *kwds)
52{
53 static const char *kwlist_1[] = {"brother", nullptr};
54 static const char *kwlist_2[] = {"first_vertex", "second_vertex", nullptr};
55 PyObject *obj1 = nullptr, *obj2 = nullptr;
56
57 if (PyArg_ParseTupleAndKeywords(args,
58 kwds,
59 "|" /* Optional arguments. */
60 "O!" /* `brother` */
61 ":__init__",
62 (char **)kwlist_1,
64 &obj1))
65 {
66 if (!obj1) {
67 self->fes = new FEdgeSharp();
68 }
69 else {
70 self->fes = new FEdgeSharp(*(((BPy_FEdgeSharp *)obj1)->fes));
71 }
72 }
73 else if ((void)PyErr_Clear(),
74 PyArg_ParseTupleAndKeywords(args,
75 kwds,
76 "O!" /* `first_vertex` */
77 "O!" /* `second_vertex` */
78 ":__init__",
79 (char **)kwlist_2,
81 &obj1,
83 &obj2))
84 {
85 self->fes = new FEdgeSharp(((BPy_SVertex *)obj1)->sv, ((BPy_SVertex *)obj2)->sv);
86 }
87 else {
88 PyErr_SetString(PyExc_TypeError, "invalid argument(s)");
89 return -1;
90 }
91 self->py_fe.fe = self->fes;
92 self->py_fe.py_if1D.if1D = self->fes;
93 self->py_fe.py_if1D.borrowed = false;
94 return 0;
95}
96
97/*----------------------mathutils callbacks ----------------------------*/
98
99/* subtype */
100#define MATHUTILS_SUBTYPE_NORMAL_A 1
101#define MATHUTILS_SUBTYPE_NORMAL_B 2
102
104{
105 if (!BPy_FEdgeSharp_Check(bmo->cb_user)) {
106 return -1;
107 }
108 return 0;
109}
110
112{
113 BPy_FEdgeSharp *self = (BPy_FEdgeSharp *)bmo->cb_user;
114 switch (subtype) {
116 Vec3r p(self->fes->normalA());
117 bmo->data[0] = p[0];
118 bmo->data[1] = p[1];
119 bmo->data[2] = p[2];
120 break;
121 }
123 Vec3r p(self->fes->normalB());
124 bmo->data[0] = p[0];
125 bmo->data[1] = p[1];
126 bmo->data[2] = p[2];
127 break;
128 }
129 default:
130 return -1;
131 }
132 return 0;
133}
134
136{
137 BPy_FEdgeSharp *self = (BPy_FEdgeSharp *)bmo->cb_user;
138 switch (subtype) {
140 Vec3r p(bmo->data[0], bmo->data[1], bmo->data[2]);
141 self->fes->setNormalA(p);
142 break;
143 }
145 Vec3r p(bmo->data[0], bmo->data[1], bmo->data[2]);
146 self->fes->setNormalB(p);
147 break;
148 }
149 default:
150 return -1;
151 }
152 return 0;
153}
154
156{
157 BPy_FEdgeSharp *self = (BPy_FEdgeSharp *)bmo->cb_user;
158 switch (subtype) {
160 Vec3r p(self->fes->normalA());
161 bmo->data[index] = p[index];
162 break;
163 }
165 Vec3r p(self->fes->normalB());
166 bmo->data[index] = p[index];
167 break;
168 }
169 default:
170 return -1;
171 }
172 return 0;
173}
174
176{
177 BPy_FEdgeSharp *self = (BPy_FEdgeSharp *)bmo->cb_user;
178 switch (subtype) {
180 Vec3r p(self->fes->normalA());
181 p[index] = bmo->data[index];
182 self->fes->setNormalA(p);
183 break;
184 }
186 Vec3r p(self->fes->normalB());
187 p[index] = bmo->data[index];
188 self->fes->setNormalB(p);
189 break;
190 }
191 default:
192 return -1;
193 }
194 return 0;
195}
196
204
206
211
212/*----------------------FEdgeSharp get/setters ----------------------------*/
213
215 /* Wrap. */
216 FEdgeSharp_normal_right_doc,
217 "The normal to the face lying on the right of the FEdge. If this FEdge\n"
218 "is a border, it has no Face on its right and therefore no normal.\n"
219 "\n"
220 ":type: :class:`mathutils.Vector`\n");
221static PyObject *FEdgeSharp_normal_right_get(BPy_FEdgeSharp *self, void * /*closure*/)
222{
225}
226
227static int FEdgeSharp_normal_right_set(BPy_FEdgeSharp *self, PyObject *value, void * /*closure*/)
228{
229 float v[3];
230 if (blender::mathutils_array_parse(v, 3, 3, value, "value must be a 3-dimensional vector") == -1)
231 {
232 return -1;
233 }
234 Vec3r p(v[0], v[1], v[2]);
235 self->fes->setNormalA(p);
236 return 0;
237}
238
240 /* Wrap. */
241 FEdgeSharp_normal_left_doc,
242 "The normal to the face lying on the left of the FEdge.\n"
243 "\n"
244 ":type: :class:`mathutils.Vector`\n");
245static PyObject *FEdgeSharp_normal_left_get(BPy_FEdgeSharp *self, void * /*closure*/)
246{
249}
250
251static int FEdgeSharp_normal_left_set(BPy_FEdgeSharp *self, PyObject *value, void * /*closure*/)
252{
253 float v[3];
254 if (blender::mathutils_array_parse(v, 3, 3, value, "value must be a 3-dimensional vector") == -1)
255 {
256 return -1;
257 }
258 Vec3r p(v[0], v[1], v[2]);
259 self->fes->setNormalB(p);
260 return 0;
261}
262
264 /* Wrap. */
265 FEdgeSharp_material_index_right_doc,
266 "The index of the material of the face lying on the right of the FEdge.\n"
267 "If this FEdge is a border, it has no Face on its right and therefore\n"
268 "no material.\n"
269 "\n"
270 ":type: int\n");
271static PyObject *FEdgeSharp_material_index_right_get(BPy_FEdgeSharp *self, void * /*closure*/)
272{
273 return PyLong_FromLong(self->fes->aFrsMaterialIndex());
274}
275
277 PyObject *value,
278 void * /*closure*/)
279{
280 uint i = PyLong_AsUnsignedLong(value);
281 if (PyErr_Occurred()) {
282 return -1;
283 }
284 self->fes->setaFrsMaterialIndex(i);
285 return 0;
286}
287
289 /* Wrap. */
290 FEdgeSharp_material_index_left_doc,
291 "The index of the material of the face lying on the left of the FEdge.\n"
292 "\n"
293 ":type: int\n");
294static PyObject *FEdgeSharp_material_index_left_get(BPy_FEdgeSharp *self, void * /*closure*/)
295{
296 return PyLong_FromLong(self->fes->bFrsMaterialIndex());
297}
298
300 PyObject *value,
301 void * /*closure*/)
302{
303 uint i = PyLong_AsUnsignedLong(value);
304 if (PyErr_Occurred()) {
305 return -1;
306 }
307 self->fes->setbFrsMaterialIndex(i);
308 return 0;
309}
310
312 /* Wrap. */
313 FEdgeSharp_material_right_doc,
314 "The material of the face lying on the right of the FEdge. If this FEdge\n"
315 "is a border, it has no Face on its right and therefore no material.\n"
316 "\n"
317 ":type: :class:`Material`\n");
318static PyObject *FEdgeSharp_material_right_get(BPy_FEdgeSharp *self, void * /*closure*/)
319{
321}
322
324 /* Wrap. */
325 FEdgeSharp_material_left_doc,
326 "The material of the face lying on the left of the FEdge.\n"
327 "\n"
328 ":type: :class:`Material`\n");
329static PyObject *FEdgeSharp_material_left_get(BPy_FEdgeSharp *self, void * /*closure*/)
330{
332}
333
335 /* Wrap. */
336 FEdgeSharp_face_mark_right_doc,
337 "The face mark of the face lying on the right of the FEdge. If this FEdge\n"
338 "is a border, it has no face on the right and thus this property is set to\n"
339 "false.\n"
340 "\n"
341 ":type: bool\n");
342static PyObject *FEdgeSharp_face_mark_right_get(BPy_FEdgeSharp *self, void * /*closure*/)
343{
344 return PyBool_from_bool(self->fes->aFaceMark());
345}
346
348 PyObject *value,
349 void * /*closure*/)
350{
351 if (!PyBool_Check(value)) {
352 return -1;
353 }
354 self->fes->setaFaceMark(bool_from_PyBool(value));
355 return 0;
356}
357
359 /* Wrap. */
360 FEdgeSharp_face_mark_left_doc,
361 "The face mark of the face lying on the left of the FEdge.\n"
362 "\n"
363 ":type: bool\n");
364static PyObject *FEdgeSharp_face_mark_left_get(BPy_FEdgeSharp *self, void * /*closure*/)
365{
366 return PyBool_from_bool(self->fes->bFaceMark());
367}
368
369static int FEdgeSharp_face_mark_left_set(BPy_FEdgeSharp *self, PyObject *value, void * /*closure*/)
370{
371 if (!PyBool_Check(value)) {
372 return -1;
373 }
374 self->fes->setbFaceMark(bool_from_PyBool(value));
375 return 0;
376}
377
378static PyGetSetDef BPy_FEdgeSharp_getseters[] = {
379 {"normal_right",
382 FEdgeSharp_normal_right_doc,
383 nullptr},
384 {"normal_left",
387 FEdgeSharp_normal_left_doc,
388 nullptr},
389 {"material_index_right",
392 FEdgeSharp_material_index_right_doc,
393 nullptr},
394 {"material_index_left",
397 FEdgeSharp_material_index_left_doc,
398 nullptr},
399 {"material_right",
401 (setter) nullptr,
402 FEdgeSharp_material_right_doc,
403 nullptr},
404 {"material_left",
406 (setter) nullptr,
407 FEdgeSharp_material_left_doc,
408 nullptr},
409 {"face_mark_right",
412 FEdgeSharp_face_mark_right_doc,
413 nullptr},
414 {"face_mark_left",
417 FEdgeSharp_face_mark_left_doc,
418 nullptr},
419 {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
420};
421
422/*-----------------------BPy_FEdgeSharp type definition ------------------------------*/
423
424PyTypeObject FEdgeSharp_Type = {
425 /*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0)
426 /*tp_name*/ "FEdgeSharp",
427 /*tp_basicsize*/ sizeof(BPy_FEdgeSharp),
428 /*tp_itemsize*/ 0,
429 /*tp_dealloc*/ nullptr,
430 /*tp_vectorcall_offset*/ 0,
431 /*tp_getattr*/ nullptr,
432 /*tp_setattr*/ nullptr,
433 /*tp_as_async*/ nullptr,
434 /*tp_repr*/ nullptr,
435 /*tp_as_number*/ nullptr,
436 /*tp_as_sequence*/ nullptr,
437 /*tp_as_mapping*/ nullptr,
438 /*tp_hash*/ nullptr,
439 /*tp_call*/ nullptr,
440 /*tp_str*/ nullptr,
441 /*tp_getattro*/ nullptr,
442 /*tp_setattro*/ nullptr,
443 /*tp_as_buffer*/ nullptr,
444 /*tp_flags*/ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
445 /*tp_doc*/ FEdgeSharp_doc,
446 /*tp_traverse*/ nullptr,
447 /*tp_clear*/ nullptr,
448 /*tp_richcompare*/ nullptr,
449 /*tp_weaklistoffset*/ 0,
450 /*tp_iter*/ nullptr,
451 /*tp_iternext*/ nullptr,
452 /*tp_methods*/ nullptr,
453 /*tp_members*/ nullptr,
454 /*tp_getset*/ BPy_FEdgeSharp_getseters,
455 /*tp_base*/ &FEdge_Type,
456 /*tp_dict*/ nullptr,
457 /*tp_descr_get*/ nullptr,
458 /*tp_descr_set*/ nullptr,
459 /*tp_dictoffset*/ 0,
460 /*tp_init*/ (initproc)FEdgeSharp_init,
461 /*tp_alloc*/ nullptr,
462 /*tp_new*/ nullptr,
463};
464
bool bool_from_PyBool(PyObject *b)
PyObject * PyBool_from_bool(bool b)
PyObject * BPy_FrsMaterial_from_FrsMaterial(const FrsMaterial &m)
static PyObject * FEdgeSharp_normal_left_get(BPy_FEdgeSharp *self, void *)
#define MATHUTILS_SUBTYPE_NORMAL_B
static blender::Mathutils_Callback FEdgeSharp_mathutils_cb
static int FEdgeSharp_normal_left_set(BPy_FEdgeSharp *self, PyObject *value, void *)
static int FEdgeSharp_mathutils_set(blender::BaseMathObject *bmo, int subtype)
static uchar FEdgeSharp_mathutils_cb_index
static int FEdgeSharp_mathutils_get_index(blender::BaseMathObject *bmo, int subtype, int index)
static int FEdgeSharp_face_mark_left_set(BPy_FEdgeSharp *self, PyObject *value, void *)
static PyObject * FEdgeSharp_material_left_get(BPy_FEdgeSharp *self, void *)
static PyObject * FEdgeSharp_face_mark_left_get(BPy_FEdgeSharp *self, void *)
static int FEdgeSharp_face_mark_right_set(BPy_FEdgeSharp *self, PyObject *value, void *)
static int FEdgeSharp_normal_right_set(BPy_FEdgeSharp *self, PyObject *value, void *)
static int FEdgeSharp_init(BPy_FEdgeSharp *self, PyObject *args, PyObject *kwds)
static PyObject * FEdgeSharp_normal_right_get(BPy_FEdgeSharp *self, void *)
static PyObject * FEdgeSharp_face_mark_right_get(BPy_FEdgeSharp *self, void *)
#define MATHUTILS_SUBTYPE_NORMAL_A
static int FEdgeSharp_material_index_right_set(BPy_FEdgeSharp *self, PyObject *value, void *)
static PyObject * FEdgeSharp_material_index_right_get(BPy_FEdgeSharp *self, void *)
static int FEdgeSharp_mathutils_check(blender::BaseMathObject *bmo)
static int FEdgeSharp_material_index_left_set(BPy_FEdgeSharp *self, PyObject *value, void *)
PyTypeObject FEdgeSharp_Type
static int FEdgeSharp_mathutils_set_index(blender::BaseMathObject *bmo, int subtype, int index)
static PyObject * FEdgeSharp_material_right_get(BPy_FEdgeSharp *self, void *)
static int FEdgeSharp_mathutils_get(blender::BaseMathObject *bmo, int subtype)
void FEdgeSharp_mathutils_register_callback()
static PyObject * FEdgeSharp_material_index_left_get(BPy_FEdgeSharp *self, void *)
static PyGetSetDef BPy_FEdgeSharp_getseters[]
#define BPy_FEdgeSharp_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 FrsMaterial & aFrsMaterial() const
void setaFaceMark(bool iFaceMark)
void setaFrsMaterialIndex(uint i)
uint aFrsMaterialIndex() const
const Vec3r & normalA()
bool bFaceMark() const
void setNormalB(const Vec3r &iNormal)
const FrsMaterial & bFrsMaterial() const
const Vec3r & normalB()
bool aFaceMark() const
void setbFrsMaterialIndex(uint i)
void setbFaceMark(bool iFaceMark)
void setNormalA(const Vec3r &iNormal)
uint bFrsMaterialIndex() 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::FEdgeSharp * fes
BPy_Interface1D py_if1D
Definition BPy_FEdge.h:23
Freestyle::FEdge * fe
Definition BPy_FEdge.h:24
PyObject_HEAD Freestyle::Interface1D * if1D