[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [48505] trunk/blender/source/blender: add bmesh/python operator support for vector and matrix args.
Campbell Barton
ideasman42 at gmail.com
Mon Jul 2 22:28:58 CEST 2012
Revision: 48505
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=48505
Author: campbellbarton
Date: 2012-07-02 20:28:43 +0000 (Mon, 02 Jul 2012)
Log Message:
-----------
add bmesh/python operator support for vector and matrix args.
also rename BMO_OP_SLOT_PNT to BMO_OP_SLOT_PTR (matches RNA and sounds less like 'point')
Modified Paths:
--------------
trunk/blender/source/blender/bmesh/intern/bmesh_opdefines.c
trunk/blender/source/blender/bmesh/intern/bmesh_operator_api.h
trunk/blender/source/blender/bmesh/intern/bmesh_operators.c
trunk/blender/source/blender/python/bmesh/bmesh_py_ops.c
Modified: trunk/blender/source/blender/bmesh/intern/bmesh_opdefines.c
===================================================================
--- trunk/blender/source/blender/bmesh/intern/bmesh_opdefines.c 2012-07-02 20:05:28 UTC (rev 48504)
+++ trunk/blender/source/blender/bmesh/intern/bmesh_opdefines.c 2012-07-02 20:28:43 UTC (rev 48505)
@@ -528,8 +528,8 @@
*/
static BMOpDefine bmo_object_load_bmesh_def = {
"object_load_bmesh",
- {{BMO_OP_SLOT_PNT, "scene"},
- {BMO_OP_SLOT_PNT, "object"},
+ {{BMO_OP_SLOT_PTR, "scene"},
+ {BMO_OP_SLOT_PTR, "object"},
{0, /* null-terminating sentinel */}},
bmo_object_load_bmesh_exec,
0,
@@ -543,8 +543,8 @@
*/
static BMOpDefine bmo_bmesh_to_mesh_def = {
"bmesh_to_mesh",
- {{BMO_OP_SLOT_PNT, "mesh"}, //pointer to a mesh structure to fill in
- {BMO_OP_SLOT_PNT, "object"}, //pointer to an object structure
+ {{BMO_OP_SLOT_PTR, "mesh"}, //pointer to a mesh structure to fill in
+ {BMO_OP_SLOT_PTR, "object"}, //pointer to an object structure
{BMO_OP_SLOT_BOOL, "notessellation"}, //don't calculate mfaces
{0, /* null-terminating sentinel */}},
bmo_bmesh_to_mesh_exec,
@@ -559,8 +559,8 @@
*/
static BMOpDefine bmo_mesh_to_bmesh_def = {
"mesh_to_bmesh",
- {{BMO_OP_SLOT_PNT, "mesh"}, //pointer to a Mesh structure
- {BMO_OP_SLOT_PNT, "object"}, //pointer to an Object structure
+ {{BMO_OP_SLOT_PTR, "mesh"}, //pointer to a Mesh structure
+ {BMO_OP_SLOT_PTR, "object"}, //pointer to an Object structure
{BMO_OP_SLOT_BOOL, "set_shapekey"}, //load active shapekey coordinates into verts
{0, /* null-terminating sentinel */}},
bmo_mesh_to_bmesh_exec,
@@ -737,7 +737,7 @@
{BMO_OP_SLOT_MAPPING, "facemap"},
{BMO_OP_SLOT_MAPPING, "boundarymap"},
{BMO_OP_SLOT_MAPPING, "isovertmap"},
- {BMO_OP_SLOT_PNT, "dest"}, /* destination bmesh, if NULL will use current on */
+ {BMO_OP_SLOT_PTR, "dest"}, /* destination bmesh, if NULL will use current on */
{0} /* null-terminating sentinel */},
bmo_duplicate_exec,
0
@@ -749,7 +749,7 @@
{BMO_OP_SLOT_ELEMENT_BUF, "geomout"},
{BMO_OP_SLOT_MAPPING, "boundarymap"},
{BMO_OP_SLOT_MAPPING, "isovertmap"},
- {BMO_OP_SLOT_PNT, "dest"}, /* destination bmesh, if NULL will use current on */
+ {BMO_OP_SLOT_PTR, "dest"}, /* destination bmesh, if NULL will use current on */
{BMO_OP_SLOT_BOOL, "use_only_faces"}, /* when enabled. don't duplicate loose verts/edges */
{0} /* null-terminating sentinel */},
bmo_split_exec,
Modified: trunk/blender/source/blender/bmesh/intern/bmesh_operator_api.h
===================================================================
--- trunk/blender/source/blender/bmesh/intern/bmesh_operator_api.h 2012-07-02 20:05:28 UTC (rev 48504)
+++ trunk/blender/source/blender/bmesh/intern/bmesh_operator_api.h 2012-07-02 20:28:43 UTC (rev 48505)
@@ -99,7 +99,7 @@
/* normally store pointers to object, scene,
* _never_ store arrays corresponding to mesh elements with this */
- BMO_OP_SLOT_PNT = 4,
+ BMO_OP_SLOT_PTR = 4,
BMO_OP_SLOT_MAT = 5,
BMO_OP_SLOT_VEC = 8,
Modified: trunk/blender/source/blender/bmesh/intern/bmesh_operators.c
===================================================================
--- trunk/blender/source/blender/bmesh/intern/bmesh_operators.c 2012-07-02 20:05:28 UTC (rev 48504)
+++ trunk/blender/source/blender/bmesh/intern/bmesh_operators.c 2012-07-02 20:28:43 UTC (rev 48505)
@@ -378,8 +378,8 @@
void BMO_slot_ptr_set(BMOperator *op, const char *slot_name, void *p)
{
BMOpSlot *slot = BMO_slot_get(op, slot_name);
- BLI_assert(slot->slot_type == BMO_OP_SLOT_PNT);
- if (!(slot->slot_type == BMO_OP_SLOT_PNT))
+ BLI_assert(slot->slot_type == BMO_OP_SLOT_PTR);
+ if (!(slot->slot_type == BMO_OP_SLOT_PTR))
return;
slot->data.p = p;
@@ -430,8 +430,8 @@
void *BMO_slot_ptr_get(BMOperator *op, const char *slot_name)
{
BMOpSlot *slot = BMO_slot_get(op, slot_name);
- BLI_assert(slot->slot_type == BMO_OP_SLOT_PNT);
- if (!(slot->slot_type == BMO_OP_SLOT_PNT))
+ BLI_assert(slot->slot_type == BMO_OP_SLOT_PTR);
+ if (!(slot->slot_type == BMO_OP_SLOT_PTR))
return NULL;
return slot->data.p;
Modified: trunk/blender/source/blender/python/bmesh/bmesh_py_ops.c
===================================================================
--- trunk/blender/source/blender/python/bmesh/bmesh_py_ops.c 2012-07-02 20:05:28 UTC (rev 48504)
+++ trunk/blender/source/blender/python/bmesh/bmesh_py_ops.c 2012-07-02 20:28:43 UTC (rev 48505)
@@ -163,6 +163,7 @@
PyErr_Format(PyExc_TypeError,
"%.200s: keyword \"%.200s\" expected an int, not %.200s",
self->opname, slot_name, Py_TYPE(value)->tp_name);
+ return NULL;
}
else {
slot->data.i = (int)param;
@@ -176,12 +177,47 @@
PyErr_Format(PyExc_TypeError,
"%.200s: keyword \"%.200s\" expected a float, not %.200s",
self->opname, slot_name, Py_TYPE(value)->tp_name);
+ return NULL;
}
else {
slot->data.f = param;
}
break;
}
+ case BMO_OP_SLOT_MAT:
+ {
+ /* XXX - BMesh operator design is crappy here, operator slot should define matrix size,
+ * not the caller! */
+ unsigned short size;
+ if (!MatrixObject_Check(value)) {
+ PyErr_Format(PyExc_TypeError,
+ "%.200s: keyword \"%.200s\" expected a Matrix, not %.200s",
+ self->opname, slot_name, Py_TYPE(value)->tp_name);
+ return NULL;
+ }
+ else if (BaseMath_ReadCallback((MatrixObject *)value) == -1) {
+ return NULL;
+ }
+ else if (((size = ((MatrixObject *)value)->num_col) != ((MatrixObject *)value)->num_row) ||
+ (ELEM(size, 3, 4) == FALSE))
+ {
+ PyErr_Format(PyExc_TypeError,
+ "%.200s: keyword \"%.200s\" expected a 3x3 or 4x4 matrix Matrix",
+ self->opname, slot_name);
+ return NULL;
+ }
+
+ BMO_slot_mat_set(&bmop, slot_name, ((MatrixObject *)value)->matrix, size);
+ break;
+ }
+ case BMO_OP_SLOT_VEC:
+ {
+ /* passing slot name here is a bit non-descriptive */
+ if (mathutils_array_parse(slot->data.vec, 3, 3, value, slot_name) == -1) {
+ return NULL;
+ }
+ break;
+ }
case BMO_OP_SLOT_ELEMENT_BUF:
{
/* there are many ways we could interpret arguments, for now...
@@ -194,12 +230,12 @@
* ('VERT', {'TAG'})
*/
-#define BPY_BM_GENERIC_MESH_TEST(type_string) \
+#define BPY_BM_GENERIC_MESH_TEST(type_string) \
if (((BPy_BMGeneric *)value)->bm != bm) { \
- PyErr_Format(PyExc_NotImplementedError, \
- "%.200s: keyword \"%.200s\" " type_string " are from another bmesh", \
- self->opname, slot_name, slot->slot_type); \
- return NULL; \
+ PyErr_Format(PyExc_NotImplementedError, \
+ "%.200s: keyword \"%.200s\" " type_string " are from another bmesh", \
+ self->opname, slot_name, slot->slot_type); \
+ return NULL; \
} (void)0
if (BPy_BMVertSeq_Check(value)) {
@@ -258,6 +294,7 @@
"%.200s: keyword \"%.200s\" expected "
"a bmesh sequence, list, (htype, flag) pair, not %.200s",
self->opname, slot_name, Py_TYPE(value)->tp_name);
+ return NULL;
}
#undef BPY_BM_GENERIC_MESH_TEST
More information about the Bf-blender-cvs
mailing list