[Bf-blender-cvs] [772b08b] particles_refactor: Added new bparticles function for copying the current particle state instead of just creating a new empty state. Also clear the py_handle when copying the state, otherwise the PyObject is invalid.
Lukas Tönne
noreply at git.blender.org
Tue Apr 22 12:06:52 CEST 2014
Commit: 772b08b8aa016763e50cd458e28cc0f979281d2f
Author: Lukas Tönne
Date: Thu Jan 2 11:20:21 2014 +0100
https://developer.blender.org/rB772b08b8aa016763e50cd458e28cc0f979281d2f
Added new bparticles function for copying the current particle state
instead of just creating a new empty state. Also clear the py_handle
when copying the state, otherwise the PyObject is invalid.
===================================================================
M source/blender/blenkernel/intern/nparticle.c
M source/blender/python/bparticles/bparticles_py_api.c
===================================================================
diff --git a/source/blender/blenkernel/intern/nparticle.c b/source/blender/blenkernel/intern/nparticle.c
index 698f011..e300e9c 100644
--- a/source/blender/blenkernel/intern/nparticle.c
+++ b/source/blender/blenkernel/intern/nparticle.c
@@ -241,6 +241,8 @@ NParticleState *BKE_nparticle_state_copy(NParticleState *state)
attrstate = attrstate->next, nattrstate = nattrstate->next)
nparticle_attribute_state_copy(nattrstate, attrstate);
+ nstate->py_handle = NULL;
+
return nstate;
}
diff --git a/source/blender/python/bparticles/bparticles_py_api.c b/source/blender/python/bparticles/bparticles_py_api.c
index d463ef7..3bc92694 100644
--- a/source/blender/python/bparticles/bparticles_py_api.c
+++ b/source/blender/python/bparticles/bparticles_py_api.c
@@ -65,6 +65,30 @@ static PyObject *bpy_bpar_new(PyObject *UNUSED(self), PyObject *value)
return BPy_NParticleState_CreatePyObject(state);
}
+PyDoc_STRVAR(bpy_bpar_copy_doc,
+".. method:: copy()\n"
+"\n"
+" :arg psys: The particle system.\n"
+" :type psys: :class:`bpy.types.NParticleSystem`\n"
+" :return: Return a copy of the current NParticleState.\n"
+" :rtype: :class:`bparticles.types.NParticleState`\n"
+);
+static PyObject *bpy_bpar_copy(PyObject *UNUSED(self), PyObject *value)
+{
+ NParticleSystem *psys = PyC_RNA_AsPointer(value, "NParticleSystem");
+ NParticleState *state;
+
+ if (!psys)
+ return NULL;
+
+ if (psys->state)
+ state = BKE_nparticle_state_copy(psys->state);
+ else
+ state = BKE_nparticle_state_new(psys);
+
+ return BPy_NParticleState_CreatePyObject(state);
+}
+
PyDoc_STRVAR(bpy_bpar_set_current_state_doc,
".. method:: set_current_state()\n"
"\n"
@@ -102,6 +126,7 @@ static PyObject *bpy_bpar_set_current_state(PyObject *UNUSED(self), PyObject *ar
static struct PyMethodDef BPy_BPAR_methods[] = {
{"new", (PyCFunction)bpy_bpar_new, METH_O, bpy_bpar_new_doc},
+ {"copy", (PyCFunction)bpy_bpar_copy, METH_O, bpy_bpar_copy_doc},
{"set_current_state", (PyCFunction)bpy_bpar_set_current_state, METH_VARARGS | METH_KEYWORDS, bpy_bpar_set_current_state_doc},
{NULL, NULL, 0, NULL}
};
More information about the Bf-blender-cvs
mailing list