diff options
author | Campbell Barton <ideasman42@gmail.com> | 2010-02-22 15:25:58 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2010-02-22 15:25:58 +0300 |
commit | 4ef1fd1078bbdb8ecb905fc9cd3db60c378408b0 (patch) | |
tree | 408bbfb210658cae5a9075791d59dc4c7a4623a9 /source/blender/python | |
parent | dd03793f4edd455c09a1a2273e5e991dd3bd702b (diff) |
game engine support for recording animation back & some other minor changes.
Diffstat (limited to 'source/blender/python')
-rw-r--r-- | source/blender/python/intern/bpy_rna.c | 77 |
1 files changed, 56 insertions, 21 deletions
diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c index 29c262d5815..e9290b69265 100644 --- a/source/blender/python/intern/bpy_rna.c +++ b/source/blender/python/intern/bpy_rna.c @@ -1639,47 +1639,81 @@ static PyObject *pyrna_struct_values(BPy_PropertyRNA *self) return BPy_Wrap_GetValues(self->ptr.id.data, group); } -static PyObject *pyrna_struct_keyframe_insert(BPy_StructRNA *self, PyObject *args) +/* internal use for insert and delete */ +int pyrna_struct_keyframe_parse(PointerRNA *ptr, PyObject *args, char *error_prefix, + char **path_full, int *index, float *cfra) /* return values */ { - char *path, *path_full; - int index= -1; /* default to all */ - float cfra = CTX_data_scene(BPy_GetContext())->r.cfra; + char *path; PropertyRNA *prop; - PyObject *result; - if (!PyArg_ParseTuple(args, "s|if:keyframe_insert", &path, &index, &cfra)) - return NULL; + if (!PyArg_ParseTuple(args, "s|if", &path, &index, &cfra)) { + PyErr_Format(PyExc_TypeError, "%.200s: expected a string and optionally an int and float arguments", error_prefix); + return -1; + } - if (self->ptr.data==NULL) { - PyErr_Format( PyExc_TypeError, "keyframe_insert, this struct has no data, cant be animated", path); - return NULL; + if (ptr->data==NULL) { + PyErr_Format(PyExc_TypeError, "%.200s: this struct has no data, can't be animated", error_prefix); + return -1; } - prop = RNA_struct_find_property(&self->ptr, path); + prop = RNA_struct_find_property(ptr, path); if (prop==NULL) { - PyErr_Format( PyExc_TypeError, "keyframe_insert, property \"%s\" not found", path); - return NULL; + PyErr_Format( PyExc_TypeError, "%.200s: property \"%s\" not found", error_prefix, path); + return -1; } - if (!RNA_property_animateable(&self->ptr, prop)) { - PyErr_Format( PyExc_TypeError, "keyframe_insert, property \"%s\" not animatable", path); - return NULL; + if (!RNA_property_animateable(ptr, prop)) { + PyErr_Format( PyExc_TypeError, "%.200s: property \"%s\" not animatable", error_prefix, path); + return -1; } - path_full= RNA_path_from_ID_to_property(&self->ptr, prop); + *path_full= RNA_path_from_ID_to_property(ptr, prop); - if (path_full==NULL) { - PyErr_Format( PyExc_TypeError, "keyframe_insert, could not make path to \"%s\"", path); - return NULL; + if (*path_full==NULL) { + PyErr_Format( PyExc_TypeError, "%.200s: could not make path to \"%s\"", error_prefix, path); + return -1; } - result= PyBool_FromLong( insert_keyframe((ID *)self->ptr.id.data, NULL, NULL, path_full, index, cfra, 0)); + if(*cfra==FLT_MAX) + *cfra= CTX_data_scene(BPy_GetContext())->r.cfra; + + return 0; /* success */ +} + +static PyObject *pyrna_struct_keyframe_insert(BPy_StructRNA *self, PyObject *args) +{ + PyObject *result; + /* args, pyrna_struct_keyframe_parse handles these */ + char *path_full= NULL; + int index= -1; + float cfra= FLT_MAX; + + if(pyrna_struct_keyframe_parse(&self->ptr, args, "keyframe_insert", &path_full, &index, &cfra) == -1) + return NULL; + + result= PyBool_FromLong(insert_keyframe((ID *)self->ptr.id.data, NULL, NULL, path_full, index, cfra, 0)); MEM_freeN(path_full); return result; } +static PyObject *pyrna_struct_keyframe_delete(BPy_StructRNA *self, PyObject *args) +{ + PyObject *result; + /* args, pyrna_struct_keyframe_parse handles these */ + char *path_full= NULL; + int index= -1; + float cfra= FLT_MAX; + + if(pyrna_struct_keyframe_parse(&self->ptr, args, "keyframe_delete", &path_full, &index, &cfra) == -1) + return NULL; + + result= PyBool_FromLong(delete_keyframe((ID *)self->ptr.id.data, NULL, NULL, path_full, index, cfra, 0)); + MEM_freeN(path_full); + + return result; +} static PyObject *pyrna_struct_driver_add(BPy_StructRNA *self, PyObject *args) { @@ -2659,6 +2693,7 @@ static struct PyMethodDef pyrna_struct_methods[] = { /* maybe this become and ID function */ {"keyframe_insert", (PyCFunction)pyrna_struct_keyframe_insert, METH_VARARGS, NULL}, +// {"keyframe_delete", (PyCFunction)pyrna_struct_keyframe_delete, METH_VARARGS, NULL}, // WIP {"driver_add", (PyCFunction)pyrna_struct_driver_add, METH_VARARGS, NULL}, {"is_property_set", (PyCFunction)pyrna_struct_is_property_set, METH_VARARGS, NULL}, {"is_property_hidden", (PyCFunction)pyrna_struct_is_property_hidden, METH_VARARGS, NULL}, |