[Bf-blender-cvs] [eee0f75] particles_refactor: Added new python module 'bparticles' for implementing a full python API to define particle states. This is necessary because otherwise the RNA can only refer to data that already exists in the DNA library (bpy.data) but not create temporary structs. The state should be defined separately before replacing a particle system's state with it. This is similar to how bmesh works.

Lukas Tönne noreply at git.blender.org
Tue Apr 22 12:06:09 CEST 2014


Commit: eee0f75b1f58e4b7b5f5745655c17039331a8f33
Author: Lukas Tönne
Date:   Wed Dec 18 11:40:39 2013 +0100
https://developer.blender.org/rBeee0f75b1f58e4b7b5f5745655c17039331a8f33

Added new python module 'bparticles' for implementing a full python API
to define particle states. This is necessary because otherwise the RNA
can only refer to data that already exists in the DNA library (bpy.data)
but not create temporary structs. The state should be defined separately
before replacing a particle system's state with it. This is similar to
how bmesh works.

===================================================================

M	source/blender/python/CMakeLists.txt
A	source/blender/python/bparticles/CMakeLists.txt
A	source/blender/python/bparticles/bparticles_py_api.c
A	source/blender/python/bparticles/bparticles_py_api.h
M	source/blender/python/intern/bpy_interface.c
M	source/creator/CMakeLists.txt

===================================================================

diff --git a/source/blender/python/CMakeLists.txt b/source/blender/python/CMakeLists.txt
index e855f3a..7998d79 100644
--- a/source/blender/python/CMakeLists.txt
+++ b/source/blender/python/CMakeLists.txt
@@ -20,3 +20,4 @@ add_subdirectory(intern)
 add_subdirectory(generic)
 add_subdirectory(mathutils)
 add_subdirectory(bmesh)
+add_subdirectory(bparticles)
diff --git a/source/blender/python/CMakeLists.txt b/source/blender/python/bparticles/CMakeLists.txt
similarity index 72%
copy from source/blender/python/CMakeLists.txt
copy to source/blender/python/bparticles/CMakeLists.txt
index e855f3a..0de2edc 100644
--- a/source/blender/python/CMakeLists.txt
+++ b/source/blender/python/bparticles/CMakeLists.txt
@@ -14,9 +14,26 @@
 # 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 *****
 
-add_subdirectory(intern)
-add_subdirectory(generic)
-add_subdirectory(mathutils)
-add_subdirectory(bmesh)
+set(INC 
+	.
+	../../blenkernel
+	../../blenlib
+	../../makesdna
+	../../../../intern/guardedalloc
+)
+
+set(INC_SYS
+	${PYTHON_INCLUDE_DIRS}
+)
+
+set(SRC
+	bparticles_py_api.c
+
+	bparticles_py_api.h
+)
+
+blender_add_lib(bf_python_bparticles "${SRC}" "${INC}" "${INC_SYS}")
diff --git a/source/blender/python/bparticles/bparticles_py_api.c b/source/blender/python/bparticles/bparticles_py_api.c
new file mode 100644
index 0000000..8675428
--- /dev/null
+++ b/source/blender/python/bparticles/bparticles_py_api.c
@@ -0,0 +1,95 @@
+/*
+ * ***** 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) 2013 Blender Foundation.
+ * All rights reserved.
+ *
+ * Contributor(s): Lukas Toenne
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/python/bparticles/bparticles_py_api.c
+ *  \ingroup pybparticles
+ *
+ * This file defines the 'bparticles' module.
+ */
+
+#include <Python.h>
+
+#include "BLI_utildefines.h"
+
+#include "../generic/py_capi_utils.h"
+
+#include "bparticles_py_api.h" /* own include */
+
+static struct PyMethodDef BPy_BPAR_methods[] = {
+//	{"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},
+//	{"update_edit_mesh", (PyCFunction)bpy_bm_update_edit_mesh, METH_VARARGS | METH_KEYWORDS, bpy_bm_update_edit_mesh_doc},
+	{NULL, NULL, 0, NULL}
+};
+
+PyDoc_STRVAR(BPy_BPAR_doc,
+"This module provides access to blenders particle data structures.\n"
+"\n"
+".. include:: include__bparticles.rst\n"
+);
+static struct PyModuleDef BPy_BPAR_module_def = {
+	PyModuleDef_HEAD_INIT,
+	"bparticles",		/* m_name */
+	BPy_BPAR_doc,		/* m_doc */
+	0,					/* m_size */
+	BPy_BPAR_methods,	/* m_methods */
+	NULL,				/* m_reload */
+	NULL,				/* m_traverse */
+	NULL,				/* m_clear */
+	NULL,				/* m_free */
+};
+
+PyObject *BPyInit_bparticles(void)
+{
+	PyObject *mod;
+	PyObject *submodule;
+	PyObject *sys_modules = PyThreadState_GET()->interp->modules;
+
+//	BPy_BPAR_init_types();
+
+	mod = PyModule_Create(&BPy_BPAR_module_def);
+
+#if 0
+	/* bparticles.types */
+	PyModule_AddObject(mod, "types", (submodule = BPyInit_bmesh_types()));
+	PyDict_SetItemString(sys_modules, PyModule_GetName(submodule), submodule);
+	Py_INCREF(submodule);
+
+	PyModule_AddObject(mod, "ops", (submodule = BPyInit_bmesh_ops()));
+	/* PyDict_SetItemString(sys_modules, PyModule_GetName(submodule), submodule); */
+	PyDict_SetItemString(sys_modules, "bmesh.ops", submodule); /* fake module */
+	Py_INCREF(submodule);
+
+	PyModule_AddObject(mod, "utils", (submodule = BPyInit_bmesh_utils()));
+	PyDict_SetItemString(sys_modules, PyModule_GetName(submodule), submodule);
+	Py_INCREF(submodule);
+
+	PyModule_AddObject(mod, "geometry", (submodule = BPyInit_bmesh_geometry()));
+	PyDict_SetItemString(sys_modules, PyModule_GetName(submodule), submodule);
+	Py_INCREF(submodule);
+#endif
+
+	return mod;
+}
diff --git a/source/blender/python/bparticles/bparticles_py_api.h b/source/blender/python/bparticles/bparticles_py_api.h
new file mode 100644
index 0000000..a35b39a
--- /dev/null
+++ b/source/blender/python/bparticles/bparticles_py_api.h
@@ -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) 2013 Blender Foundation.
+ * All rights reserved.
+ *
+ * Contributor(s): Lukas Toenne
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/python/bparticles/bparticles_py_api.h
+ *  \ingroup pybparticles
+ */
+
+#ifndef __BPARTICLES_PY_API_H__
+#define __BPARTICLES_PY_API_H__
+
+PyObject *BPyInit_bparticles(void);
+
+#endif /* __BPARTICLES_PY_API_H__ */
diff --git a/source/blender/python/intern/bpy_interface.c b/source/blender/python/intern/bpy_interface.c
index 93bced3..2685401 100644
--- a/source/blender/python/intern/bpy_interface.c
+++ b/source/blender/python/intern/bpy_interface.c
@@ -78,6 +78,7 @@
 #include "../generic/blf_py_api.h"
 #include "../generic/idprop_py_api.h"
 #include "../bmesh/bmesh_py_api.h"
+#include "../bparticles/bparticles_py_api.h"
 #include "../mathutils/mathutils.h"
 
 
@@ -221,6 +222,7 @@ static struct _inittab bpy_internal_modules[] = {
 	// {(char *)"bmesh.types", BPyInit_bmesh_types},
 	// {(char *)"bmesh.utils", BPyInit_bmesh_utils},
 	// {(char *)"bmesh.utils", BPyInit_bmesh_geometry},
+	{(char *)"bparticles", BPyInit_bparticles},
 #ifdef WITH_AUDASPACE
 	{(char *)"aud", AUD_initPython},
 #endif
diff --git a/source/creator/CMakeLists.txt b/source/creator/CMakeLists.txt
index a7a3d60..8bde647 100644
--- a/source/creator/CMakeLists.txt
+++ b/source/creator/CMakeLists.txt
@@ -985,6 +985,7 @@ endif()
 		bf_python_ext
 		bf_python_mathutils
 		bf_python_bmesh
+		bf_python_bparticles
 		bf_freestyle
 		bf_ikplugin
 		bf_modifiers




More information about the Bf-blender-cvs mailing list