bmesh py api: add bmesh.update_edit_mode(), there was no way to redraw the 3d view or re-calculate face tessellation from python.
add py template for editing meshes in editmode. also remove double call to CTX_wm_region which does a string lookup.
This commit is contained in:
23
release/scripts/templates/bmesh_simple_editmode.py
Normal file
23
release/scripts/templates/bmesh_simple_editmode.py
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
# This example assumes we have a mesh object in edit-mode
|
||||||
|
|
||||||
|
import bpy
|
||||||
|
import bmesh
|
||||||
|
|
||||||
|
# Get the active mesh
|
||||||
|
obj = bpy.context.edit_object
|
||||||
|
me = obj.data
|
||||||
|
|
||||||
|
|
||||||
|
# Get a BMesh representation
|
||||||
|
bm = bmesh.from_edit_mesh(me)
|
||||||
|
|
||||||
|
bm.faces.active = None
|
||||||
|
|
||||||
|
# Modify the BMesh, can do anything here...
|
||||||
|
for v in bm.verts:
|
||||||
|
v.co.x += 1.0
|
||||||
|
|
||||||
|
|
||||||
|
# Show the updates in the viewport
|
||||||
|
# and recalculate n-gon tessellation.
|
||||||
|
bmesh.update_edit_mesh(me, True)
|
@@ -581,8 +581,7 @@ static BMOpDefine bmo_edgenet_prepare_def = {
|
|||||||
/*
|
/*
|
||||||
* Rotate.
|
* Rotate.
|
||||||
*
|
*
|
||||||
* Rotate vertices around a center, using a 3x3 rotation
|
* Rotate vertices around a center, using a 3x3 rotation matrix.
|
||||||
* matrix. Equivalent of the old rotateflag function.
|
|
||||||
*/
|
*/
|
||||||
static BMOpDefine bmo_rotate_def = {
|
static BMOpDefine bmo_rotate_def = {
|
||||||
"rotate",
|
"rotate",
|
||||||
@@ -600,8 +599,7 @@ static BMOpDefine bmo_rotate_def = {
|
|||||||
/*
|
/*
|
||||||
* Translate.
|
* Translate.
|
||||||
*
|
*
|
||||||
* Translate vertices by an offset. Equivalent of the
|
* Translate vertices by an offset.
|
||||||
* old translateflag function.
|
|
||||||
*/
|
*/
|
||||||
static BMOpDefine bmo_translate_def = {
|
static BMOpDefine bmo_translate_def = {
|
||||||
"translate",
|
"translate",
|
||||||
|
@@ -51,7 +51,6 @@
|
|||||||
|
|
||||||
#include "bmesh_py_api.h" /* own include */
|
#include "bmesh_py_api.h" /* own include */
|
||||||
|
|
||||||
|
|
||||||
PyDoc_STRVAR(bpy_bm_new_doc,
|
PyDoc_STRVAR(bpy_bm_new_doc,
|
||||||
".. method:: new()\n"
|
".. method:: new()\n"
|
||||||
"\n"
|
"\n"
|
||||||
@@ -73,6 +72,8 @@ PyDoc_STRVAR(bpy_bm_from_edit_mesh_doc,
|
|||||||
"\n"
|
"\n"
|
||||||
" Return a BMesh from this mesh, currently the mesh must already be in editmode.\n"
|
" Return a BMesh from this mesh, currently the mesh must already be in editmode.\n"
|
||||||
"\n"
|
"\n"
|
||||||
|
" :arg mesh: The editmode mesh.\n"
|
||||||
|
" :type mesh: :class:`bpy.types.Mesh`\n"
|
||||||
" :return: the BMesh associated with this mesh.\n"
|
" :return: the BMesh associated with this mesh.\n"
|
||||||
" :rtype: :class:`bmesh.types.BMesh`\n"
|
" :rtype: :class:`bmesh.types.BMesh`\n"
|
||||||
);
|
);
|
||||||
@@ -96,9 +97,56 @@ static PyObject *bpy_bm_from_edit_mesh(PyObject *UNUSED(self), PyObject *value)
|
|||||||
return BPy_BMesh_CreatePyObject(bm, BPY_BMFLAG_IS_WRAPPED);
|
return BPy_BMesh_CreatePyObject(bm, BPY_BMFLAG_IS_WRAPPED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PyDoc_STRVAR(bpy_bm_update_edit_mesh_doc,
|
||||||
|
".. method:: update_edit_mesh(mesh, tessface=True)\n"
|
||||||
|
"\n"
|
||||||
|
" Update the mesh after changes to the BMesh in editmode, \n"
|
||||||
|
" optionally recalculating n-gon tessellation.\n"
|
||||||
|
"\n"
|
||||||
|
" :arg mesh: The editmode mesh.\n"
|
||||||
|
" :type mesh: :class:`bpy.types.Mesh`\n"
|
||||||
|
" :arg tessface: Option to recalculate n-gon tessellation.\n"
|
||||||
|
" :type tessface: boolean\n"
|
||||||
|
);
|
||||||
|
static PyObject *bpy_bm_update_edit_mesh(PyObject *UNUSED(self), PyObject *args)
|
||||||
|
{
|
||||||
|
PyObject *py_me;
|
||||||
|
Mesh *me;
|
||||||
|
int do_tessface = TRUE;
|
||||||
|
|
||||||
|
if (!PyArg_ParseTuple(args, "O|i:update_edit_mesh", &py_me, &do_tessface)) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
me = PyC_RNA_AsPointer(py_me, "Mesh");
|
||||||
|
|
||||||
|
if (me == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (me->edit_btmesh == NULL) {
|
||||||
|
PyErr_SetString(PyExc_ValueError,
|
||||||
|
"The mesh must be in editmode");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
/* XXX, not great - infact this function could just not use the context at all
|
||||||
|
* postpone that change until after release: BMESH_TODO - campbell */
|
||||||
|
extern struct bContext *BPy_GetContext(void);
|
||||||
|
extern void EDBM_update_generic(struct bContext *C, BMEditMesh *em, const short do_tessface);
|
||||||
|
|
||||||
|
struct bContext *C = BPy_GetContext();
|
||||||
|
EDBM_update_generic(C, me->edit_btmesh, do_tessface);
|
||||||
|
}
|
||||||
|
|
||||||
|
Py_RETURN_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
static struct PyMethodDef BPy_BM_methods[] = {
|
static struct PyMethodDef BPy_BM_methods[] = {
|
||||||
{"new", (PyCFunction)bpy_bm_new, METH_NOARGS, bpy_bm_new_doc},
|
{"new", (PyCFunction)bpy_bm_new, METH_NOARGS, bpy_bm_new_doc},
|
||||||
{"from_edit_mesh", (PyCFunction)bpy_bm_from_edit_mesh, METH_O, bpy_bm_from_edit_mesh_doc},
|
{"from_edit_mesh", (PyCFunction)bpy_bm_from_edit_mesh, METH_O, bpy_bm_from_edit_mesh_doc},
|
||||||
|
{"update_edit_mesh", (PyCFunction)bpy_bm_update_edit_mesh, METH_VARARGS, bpy_bm_update_edit_mesh_doc},
|
||||||
{NULL, NULL, 0, NULL}
|
{NULL, NULL, 0, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -135,6 +135,7 @@ static int wm_test_duplicate_notifier(wmWindowManager *wm, unsigned int type, vo
|
|||||||
/* XXX: in future, which notifiers to send to other windows? */
|
/* XXX: in future, which notifiers to send to other windows? */
|
||||||
void WM_event_add_notifier(const bContext *C, unsigned int type, void *reference)
|
void WM_event_add_notifier(const bContext *C, unsigned int type, void *reference)
|
||||||
{
|
{
|
||||||
|
ARegion *ar;
|
||||||
wmNotifier *note = MEM_callocN(sizeof(wmNotifier), "notifier");
|
wmNotifier *note = MEM_callocN(sizeof(wmNotifier), "notifier");
|
||||||
|
|
||||||
note->wm = CTX_wm_manager(C);
|
note->wm = CTX_wm_manager(C);
|
||||||
@@ -142,8 +143,9 @@ void WM_event_add_notifier(const bContext *C, unsigned int type, void *reference
|
|||||||
|
|
||||||
note->window = CTX_wm_window(C);
|
note->window = CTX_wm_window(C);
|
||||||
|
|
||||||
if (CTX_wm_region(C))
|
ar = CTX_wm_region(C);
|
||||||
note->swinid = CTX_wm_region(C)->swinid;
|
if (ar)
|
||||||
|
note->swinid = ar->swinid;
|
||||||
|
|
||||||
note->category = type & NOTE_CATEGORY;
|
note->category = type & NOTE_CATEGORY;
|
||||||
note->data = type & NOTE_DATA;
|
note->data = type & NOTE_DATA;
|
||||||
|
Reference in New Issue
Block a user