[Bf-blender-cvs] [9701130] particles_refactor: New API function for replacing the current particle system's state. ATM this creates a full copy of the given state, so the reference can be used further. This may need some more thought.
Lukas Tönne
noreply at git.blender.org
Tue Apr 22 12:06:21 CEST 2014
Commit: 97011304e4fed1953716857f3f4518f3ac940817
Author: Lukas Tönne
Date: Fri Dec 20 16:03:22 2013 +0100
https://developer.blender.org/rB97011304e4fed1953716857f3f4518f3ac940817
New API function for replacing the current particle system's state. ATM
this creates a full copy of the given state, so the reference can be
used further. This may need some more thought.
===================================================================
M source/blender/blenkernel/BKE_nparticle.h
M source/blender/blenkernel/intern/nparticle.c
M source/blender/python/bparticles/bparticles_py_api.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_nparticle.h b/source/blender/blenkernel/BKE_nparticle.h
index a9978b8..3b724dc 100644
--- a/source/blender/blenkernel/BKE_nparticle.h
+++ b/source/blender/blenkernel/BKE_nparticle.h
@@ -47,6 +47,8 @@ struct NParticleSystem *BKE_nparticle_system_new(void);
void BKE_nparticle_system_free(struct NParticleSystem *psys);
struct NParticleSystem *BKE_nparticle_system_copy(struct NParticleSystem *psys);
+void BKE_nparticle_system_set_state(struct NParticleSystem *psys, struct NParticleState *state);
+
struct NParticleState *BKE_nparticle_state_new(struct NParticleSystem *psys);
struct NParticleState *BKE_nparticle_state_copy(struct NParticleState *state);
void BKE_nparticle_state_free(struct NParticleState *state);
diff --git a/source/blender/blenkernel/intern/nparticle.c b/source/blender/blenkernel/intern/nparticle.c
index 579f816..2bc419a 100644
--- a/source/blender/blenkernel/intern/nparticle.c
+++ b/source/blender/blenkernel/intern/nparticle.c
@@ -200,6 +200,16 @@ NParticleSystem *BKE_nparticle_system_copy(NParticleSystem *psys)
return npsys;
}
+void BKE_nparticle_system_set_state(NParticleSystem *psys, NParticleState *state)
+{
+ if (state) {
+ if (psys->state)
+ BKE_nparticle_state_free(psys->state);
+
+ psys->state = BKE_nparticle_state_copy(state);
+ }
+}
+
NParticleState *BKE_nparticle_state_new(NParticleSystem *psys)
{
diff --git a/source/blender/python/bparticles/bparticles_py_api.c b/source/blender/python/bparticles/bparticles_py_api.c
index 9132f03..d463ef7 100644
--- a/source/blender/python/bparticles/bparticles_py_api.c
+++ b/source/blender/python/bparticles/bparticles_py_api.c
@@ -42,16 +42,16 @@
#include "../generic/py_capi_utils.h"
#include "bparticles_py_api.h" /* own include */
+#include "bparticles_py_types.h"
PyDoc_STRVAR(bpy_bpar_new_doc,
".. method:: new()\n"
"\n"
" :arg psys: The particle system.\n"
-" :type mesh: :class:`bpy.types.NParticleSystem`\n"
+" :type psys: :class:`bpy.types.NParticleSystem`\n"
" :return: Return a new, empty NParticleState.\n"
" :rtype: :class:`bparticles.types.NParticleState`\n"
);
-
static PyObject *bpy_bpar_new(PyObject *UNUSED(self), PyObject *value)
{
NParticleSystem *psys = PyC_RNA_AsPointer(value, "NParticleSystem");
@@ -65,8 +65,44 @@ static PyObject *bpy_bpar_new(PyObject *UNUSED(self), PyObject *value)
return BPy_NParticleState_CreatePyObject(state);
}
+PyDoc_STRVAR(bpy_bpar_set_current_state_doc,
+".. method:: set_current_state()\n"
+"\n"
+" :arg psys: The particle system.\n"
+" :type psys: :class:`bpy.types.NParticleSystem`\n"
+" :arg state: The particle state.\n"
+" :type state: :class:`bparticles.types.NParticleState`\n"
+);
+static PyObject *bpy_bpar_set_current_state(PyObject *UNUSED(self), PyObject *args, PyObject *kw)
+{
+ static const char *kwlist[] = {"psys", "state", NULL};
+ PyObject *py_psys;
+ BPy_NParticleState *py_state;
+ NParticleSystem *psys;
+ NParticleState *state;
+
+ if (!PyArg_ParseTupleAndKeywords(args, kw, "OO:set_current_state", (char **)kwlist,
+ &py_psys, &py_state))
+ {
+ return NULL;
+ }
+
+ psys = PyC_RNA_AsPointer(py_psys, "NParticleSystem");
+ state = BPy_NParticleState_Check(py_state) ? py_state->state : NULL;
+
+ if (psys == NULL || state == NULL) {
+ return NULL;
+ }
+
+ /* XXX currently makes a full copy of the state ... */
+ BKE_nparticle_system_set_state(psys, state);
+
+ Py_RETURN_NONE;
+}
+
static struct PyMethodDef BPy_BPAR_methods[] = {
{"new", (PyCFunction)bpy_bpar_new, METH_O, bpy_bpar_new_doc},
+ {"set_current_state", (PyCFunction)bpy_bpar_set_current_state, METH_VARARGS | METH_KEYWORDS, bpy_bpar_set_current_state_doc},
{NULL, NULL, 0, NULL}
};
@@ -102,20 +138,5 @@ PyObject *BPyInit_bparticles(void)
PyDict_SetItemString(sys_modules, PyModule_GetName(submodule), submodule);
Py_INCREF(submodule);
-#if 0
- 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;
}
More information about the Bf-blender-cvs
mailing list