[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [44316] trunk/blender/source: initial bmesh python api.

Campbell Barton ideasman42 at gmail.com
Wed Feb 22 10:19:54 CET 2012


Revision: 44316
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=44316
Author:   campbellbarton
Date:     2012-02-22 09:19:53 +0000 (Wed, 22 Feb 2012)
Log Message:
-----------
initial bmesh python api.

corrently allows to create and loop over verts/edges/faces, access selection and selection modes.

this is still WIP, access to face, edge verts is still missing, no access to UV's, no access to editing operations yet.

When the api is ready it will be documented by sphinx like mathutils, blf, aud.

Modified Paths:
--------------
    trunk/blender/source/blender/python/CMakeLists.txt
    trunk/blender/source/blender/python/SConscript
    trunk/blender/source/blender/python/intern/bpy_interface.c
    trunk/blender/source/creator/CMakeLists.txt

Added Paths:
-----------
    trunk/blender/source/blender/python/bmesh/
    trunk/blender/source/blender/python/bmesh/CMakeLists.txt
    trunk/blender/source/blender/python/bmesh/bmesh_py_api.c
    trunk/blender/source/blender/python/bmesh/bmesh_py_api.h
    trunk/blender/source/blender/python/bmesh/bmesh_py_types.c
    trunk/blender/source/blender/python/bmesh/bmesh_py_types.h

Modified: trunk/blender/source/blender/python/CMakeLists.txt
===================================================================
--- trunk/blender/source/blender/python/CMakeLists.txt	2012-02-22 09:15:46 UTC (rev 44315)
+++ trunk/blender/source/blender/python/CMakeLists.txt	2012-02-22 09:19:53 UTC (rev 44316)
@@ -19,3 +19,4 @@
 add_subdirectory(intern)
 add_subdirectory(generic)
 add_subdirectory(mathutils)
+add_subdirectory(bmesh)

Modified: trunk/blender/source/blender/python/SConscript
===================================================================
--- trunk/blender/source/blender/python/SConscript	2012-02-22 09:15:46 UTC (rev 44315)
+++ trunk/blender/source/blender/python/SConscript	2012-02-22 09:19:53 UTC (rev 44316)
@@ -5,12 +5,18 @@
 Import ('env')
 
 incs = '. ../editors/include ../makesdna ../makesrna ../blenfont ../blenlib ../blenkernel ../nodes'
-incs += ' ../imbuf ../blenloader ../gpu ../render/extern/include ../windowmanager'
+incs += ' ../imbuf ../blenloader ../bmesh ../gpu ../render/extern/include ../windowmanager'
 incs += ' #intern/guardedalloc #intern/memutil #extern/glew/include #intern/cycles/blender'
 incs += ' #intern/audaspace/intern ' + env['BF_PYTHON_INC']
 
 is_debug = (env['OURPLATFORM'] in ('win32-mingw', 'win32-vc','win64-vc') and env['BF_DEBUG'])
 
+# bmesh
+defs = []
+
+sources = env.Glob('bmesh/*.c')
+env.BlenderLib( libname = 'bf_python_bmesh', sources = Split(sources), includes = Split(incs), defines = defs, libtype = ['core','player'], priority = [362,165])
+
 # generic
 defs = []
 

Added: trunk/blender/source/blender/python/bmesh/CMakeLists.txt
===================================================================
--- trunk/blender/source/blender/python/bmesh/CMakeLists.txt	                        (rev 0)
+++ trunk/blender/source/blender/python/bmesh/CMakeLists.txt	2012-02-22 09:19:53 UTC (rev 44316)
@@ -0,0 +1,43 @@
+# ***** BEGIN GPL LICENSE BLOCK *****
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# Contributor(s): Campbell Barton
+#
+# ***** END GPL LICENSE BLOCK *****
+
+set(INC 
+	.
+	../../bmesh
+	../../blenkernel
+	../../blenlib
+	../../blenloader
+	../../makesdna
+	../../../../intern/guardedalloc
+)
+
+set(INC_SYS
+	${PYTHON_INCLUDE_DIRS}
+)
+
+set(SRC
+	bmesh_py_api.c
+	bmesh_py_types.c
+
+	bmesh_py_api.h
+	bmesh_py_types.h
+)
+
+blender_add_lib(bf_python_bmesh "${SRC}" "${INC}" "${INC_SYS}")

Added: trunk/blender/source/blender/python/bmesh/bmesh_py_api.c
===================================================================
--- trunk/blender/source/blender/python/bmesh/bmesh_py_api.c	                        (rev 0)
+++ trunk/blender/source/blender/python/bmesh/bmesh_py_api.c	2012-02-22 09:19:53 UTC (rev 44316)
@@ -0,0 +1,97 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2011 Blender Foundation.
+ * All rights reserved.
+ *
+ * Contributor(s): Campbell Barton
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/python/generic/blf_py_api.c
+ *  \ingroup pygen
+ *
+ * This file defines the 'bme' bmesh main module.
+ */
+
+#include <Python.h>
+
+#include "bmesh.h"
+
+#include "bmesh_py_types.h"
+
+#include "BLI_utildefines.h"
+
+#include "BKE_tessmesh.h"
+
+#include "DNA_mesh_types.h"
+
+#include "../generic/py_capi_utils.h"
+
+#include "bmesh_py_api.h" /* own include */
+
+PyDoc_STRVAR(bpy_bm_from_mesh_doc,
+".. method:: from_mesh(mesh)\n"
+"\n"
+"   todo.\n"
+);
+
+static PyObject *bpy_bm_from_mesh(PyObject *UNUSED(self), PyObject *value)
+{
+	Mesh *me = PyC_RNA_AsPointer(value, "Mesh");
+
+	/* temp! */
+	if (!me->edit_btmesh) {
+		PyErr_SetString(PyExc_ValueError,
+		                "Mesh is not in editmode");
+		return NULL;
+	}
+
+	return BPy_BMesh_CreatePyObject(me->edit_btmesh->bm);
+}
+
+static struct PyMethodDef BPy_BM_methods[] = {
+	{"from_mesh", (PyCFunction)bpy_bm_from_mesh, METH_O, bpy_bm_from_mesh_doc},
+	{NULL, NULL, 0, NULL}
+};
+
+PyDoc_STRVAR(BPy_BM_doc,
+"This module provides access to blenders bmesh data structures."
+);
+static struct PyModuleDef BPy_BM_module_def = {
+	PyModuleDef_HEAD_INIT,
+	"bme",  /* m_name */
+	BPy_BM_doc,  /* m_doc */
+	0,  /* m_size */
+	BPy_BM_methods,  /* m_methods */
+	NULL,  /* m_reload */
+	NULL,  /* m_traverse */
+	NULL,  /* m_clear */
+	NULL,  /* m_free */
+};
+
+PyObject *BPyInit_bmesh(void)
+{
+	PyObject *submodule;
+
+	BPy_BM_init_types();
+
+	submodule = PyModule_Create(&BPy_BM_module_def);
+
+	return submodule;
+}

Added: trunk/blender/source/blender/python/bmesh/bmesh_py_api.h
===================================================================
--- trunk/blender/source/blender/python/bmesh/bmesh_py_api.h	                        (rev 0)
+++ trunk/blender/source/blender/python/bmesh/bmesh_py_api.h	2012-02-22 09:19:53 UTC (rev 44316)
@@ -0,0 +1,35 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2011 Blender Foundation.
+ * All rights reserved.
+ *
+ * Contributor(s): Campbell Barton
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/python/bmesh/bme.h
+ *  \ingroup pybmesh
+ */
+
+#ifndef __BMESH_PY_API_H__
+#define __BMESH_PY_API_H__
+
+PyObject *BPyInit_bmesh(void);
+
+#endif /* __BMESH_PY_API_H__ */

Added: trunk/blender/source/blender/python/bmesh/bmesh_py_types.c
===================================================================
--- trunk/blender/source/blender/python/bmesh/bmesh_py_types.c	                        (rev 0)
+++ trunk/blender/source/blender/python/bmesh/bmesh_py_types.c	2012-02-22 09:19:53 UTC (rev 44316)
@@ -0,0 +1,1310 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2011 Blender Foundation.
+ * All rights reserved.
+ *
+ * Contributor(s): Campbell Barton
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/python/bmesh/bme_types.c
+ *  \ingroup pybmesh
+ */
+
+#include <Python.h>
+
+#include "BLI_math.h"
+
+#include "bmesh.h"
+
+#include "../mathutils/mathutils.h"
+
+#include "../generic/py_capi_utils.h"
+
+#include "bmesh_py_types.h" /* own include */
+
+/* Common Flags
+ * ************ */
+
+/* scene does not use BM_* flags. */
+PyC_FlagSet bpy_bm_scene_vert_edge_face_flags[] = {
+	{1, "VERT"},
+	{2, "EDGE"},
+	{4, "FACE"},
+	{0, NULL}
+};
+
+PyC_FlagSet bpy_bm_htype_vert_edge_face_flags[] = {
+	{BM_VERT, "VERT"},
+	{BM_EDGE, "EDGE"},
+	{BM_FACE, "FACE"},
+	{0, NULL}
+};
+
+PyC_FlagSet bpy_bm_htype_all_flags[] = {
+	{BM_VERT, "VERT"},
+	{BM_LOOP, "EDGE"},
+	{BM_FACE, "FACE"},
+	{BM_LOOP, "LOOP"},
+	{0, NULL}
+};
+
+PyC_FlagSet bpy_bm_hflag_all_flags[] = {
+	{BM_ELEM_SELECT,  "SELECT"},
+	{BM_ELEM_HIDDEN,  "HIDE"},
+	{BM_ELEM_SEAM,    "SEAM"},
+	{BM_ELEM_SMOOTH,  "SMOOTH"},
+	{BM_ELEM_TAG,     "TAG"},
+	{0, NULL}
+};
+
+/* py-type definitions
+ * ******************* */
+
+/* getseters
+ * ========= */
+
+
+/* bmesh elems
+ * ----------- */
+
+PyDoc_STRVAR(bpy_bm_elem_select_doc, "Selected state of this element (boolean)");
+PyDoc_STRVAR(bpy_bm_elem_hide_doc, "Hidden state of this element (boolean)");
+PyDoc_STRVAR(bpy_bm_elem_tag_doc, "Tag state of this element (boolean)");
+PyDoc_STRVAR(bpy_bm_elem_smooth_doc, "Smooth state of this element (boolean)");
+PyDoc_STRVAR(bpy_bm_elem_index_doc, "Index of this element");
+
+
+static PyObject *bpy_bm_elem_hflag_get(BPy_BMElem *self, void *flag)
+{
+	const char hflag = (char)GET_INT_FROM_POINTER(flag);
+
+	BPY_BM_CHECK_OBJ(self);
+
+	return PyBool_FromLong(BM_elem_flag_test(self->ele, hflag));
+}
+
+static int bpy_bm_elem_hflag_set(BPy_BMElem *self, PyObject *value, void *flag)
+{
+	const char hflag = (char)GET_INT_FROM_POINTER(flag);
+	int param;
+
+	BPY_BM_CHECK_INT(self);
+
+	param = PyLong_AsLong(value);
+

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list