forked from bartvdbraak/blender
more housekeeping. move static declarations and definititions out of .h files.
tidy up initializers and c++ style comments.
This commit is contained in:
parent
fa0196b8f9
commit
79ecc08b89
@ -32,94 +32,219 @@
|
||||
#include "Armature.h"
|
||||
#include "Bone.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <BKE_main.h>
|
||||
#include <BKE_global.h>
|
||||
#include <BKE_object.h>
|
||||
#include <BKE_armature.h>
|
||||
#include <BKE_library.h>
|
||||
#include <BLI_blenlib.h>
|
||||
|
||||
#include "constant.h"
|
||||
#include "gen_utils.h"
|
||||
#include "modules.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python API function prototypes for the Armature module. */
|
||||
/*****************************************************************************/
|
||||
static PyObject *M_Armature_New (PyObject * self, PyObject * args,
|
||||
PyObject * keywords);
|
||||
static PyObject *M_Armature_Get (PyObject * self, PyObject * args);
|
||||
PyObject *Armature_Init (void);
|
||||
|
||||
/*****************************************************************************/
|
||||
/* The following string definitions are used for documentation strings. */
|
||||
/* In Python these will be written to the console when doing a */
|
||||
/* Blender.Armature.__doc__ */
|
||||
/*****************************************************************************/
|
||||
char M_Armature_doc[] = "The Blender Armature module\n\n\
|
||||
This module provides control over **Armature Data** objects in Blender.\n";
|
||||
|
||||
char M_Armature_New_doc[] = "(name) - return a new Armature datablock of \n\
|
||||
optional name 'name'.";
|
||||
|
||||
char M_Armature_Get_doc[] =
|
||||
"(name) - return the armature with the name 'name', \
|
||||
returns None if not found.\n If 'name' is not specified, \
|
||||
it returns a list of all armatures in the\ncurrent scene.";
|
||||
|
||||
char M_Armature_get_doc[] = "(name) - DEPRECATED. Use 'Get' instead. \
|
||||
return the armature with the name 'name', \
|
||||
returns None if not found.\n If 'name' is not specified, \
|
||||
it returns a list of all armatures in the\ncurrent scene.";
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python method structure definition for Blender.Armature module: */
|
||||
/*****************************************************************************/
|
||||
struct PyMethodDef M_Armature_methods[] = {
|
||||
{"New", (PyCFunction) M_Armature_New, METH_VARARGS | METH_KEYWORDS,
|
||||
M_Armature_New_doc},
|
||||
{"Get", M_Armature_Get, METH_VARARGS, M_Armature_Get_doc},
|
||||
{"get", M_Armature_Get, METH_VARARGS, M_Armature_get_doc},
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python BPy_Armature methods declarations: */
|
||||
/*****************************************************************************/
|
||||
static PyObject *Armature_getName (BPy_Armature * self);
|
||||
static PyObject *Armature_getBones (BPy_Armature * self);
|
||||
static PyObject *Armature_setName (BPy_Armature * self, PyObject * args);
|
||||
/* static PyObject *Armature_setBones(BPy_Armature *self, PyObject *args); */
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python BPy_Armature methods table: */
|
||||
/*****************************************************************************/
|
||||
static PyMethodDef BPy_Armature_methods[] = {
|
||||
/* name, method, flags, doc */
|
||||
{"getName", (PyCFunction) Armature_getName, METH_NOARGS,
|
||||
"() - return Armature name"},
|
||||
{"getBones", (PyCFunction) Armature_getBones, METH_NOARGS,
|
||||
"() - return Armature root bones"},
|
||||
{"setName", (PyCFunction) Armature_setName, METH_VARARGS,
|
||||
"(str) - rename Armature"},
|
||||
/* {"setBones", (PyCFunction)Armature_setBones, METH_VARARGS,
|
||||
"(list of bones) - replace the whole bone list of the armature"},
|
||||
*/
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python TypeArmature callback function prototypes: */
|
||||
/*****************************************************************************/
|
||||
static void Armature_dealloc (BPy_Armature * armature);
|
||||
static PyObject *Armature_getAttr (BPy_Armature * armature, char *name);
|
||||
static int Armature_setAttr (BPy_Armature * armature, char *name,
|
||||
PyObject * v);
|
||||
static int Armature_compare (BPy_Armature * a1, BPy_Armature * a2);
|
||||
static PyObject *Armature_repr (BPy_Armature * armature);
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python TypeArmature structure definition: */
|
||||
/*****************************************************************************/
|
||||
PyTypeObject Armature_Type = {
|
||||
PyObject_HEAD_INIT (NULL) 0, /* ob_size */
|
||||
"Blender Armature", /* tp_name */
|
||||
sizeof (BPy_Armature), /* tp_basicsize */
|
||||
0, /* tp_itemsize */
|
||||
/* methods */
|
||||
(destructor) Armature_dealloc, /* tp_dealloc */
|
||||
0, /* tp_print */
|
||||
(getattrfunc) Armature_getAttr, /* tp_getattr */
|
||||
(setattrfunc) Armature_setAttr, /* tp_setattr */
|
||||
(cmpfunc) Armature_compare, /* tp_compare */
|
||||
(reprfunc) Armature_repr, /* tp_repr */
|
||||
0, /* tp_as_number */
|
||||
0, /* tp_as_sequence */
|
||||
0, /* tp_as_mapping */
|
||||
0, /* tp_as_hash */
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, /* tp_doc */
|
||||
0, 0, 0, 0, 0, 0,
|
||||
BPy_Armature_methods, /* tp_methods */
|
||||
0, /* tp_members */
|
||||
};
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Function: M_Armature_New */
|
||||
/* Python equivalent: Blender.Armature.New */
|
||||
/*****************************************************************************/
|
||||
static PyObject *M_Armature_New(PyObject *self, PyObject *args,
|
||||
PyObject *keywords)
|
||||
static PyObject *
|
||||
M_Armature_New (PyObject * self, PyObject * args, PyObject * keywords)
|
||||
{
|
||||
char *type_str = "Armature";
|
||||
char *name_str = "ArmatureData";
|
||||
static char *kwlist[] = {"type_str", "name_str", NULL};
|
||||
BPy_Armature *py_armature; /* for Armature Data object wrapper in Python */
|
||||
bArmature *bl_armature; /* for actual Armature Data we create in Blender */
|
||||
char buf[21];
|
||||
char *type_str = "Armature";
|
||||
char *name_str = "ArmatureData";
|
||||
static char *kwlist[] = { "type_str", "name_str", NULL };
|
||||
BPy_Armature *py_armature; /* for Armature Data object wrapper in Python */
|
||||
bArmature *bl_armature; /* for actual Armature Data we create in Blender */
|
||||
char buf[21];
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords(args, keywords, "|ss", kwlist,
|
||||
&type_str, &name_str))
|
||||
if (!PyArg_ParseTupleAndKeywords (args, keywords, "|ss", kwlist,
|
||||
&type_str, &name_str))
|
||||
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
|
||||
"expected string(s) or empty argument"));
|
||||
"expected string(s) or empty argument"));
|
||||
|
||||
bl_armature = add_armature(); /* first create in Blender */
|
||||
if (bl_armature){
|
||||
/* return user count to zero because add_armature() inc'd it */
|
||||
bl_armature->id.us = 0;
|
||||
/* now create the wrapper obj in Python */
|
||||
py_armature = (BPy_Armature *)PyObject_NEW(BPy_Armature, &Armature_Type);
|
||||
}
|
||||
bl_armature = add_armature (); /* first create in Blender */
|
||||
if (bl_armature)
|
||||
{
|
||||
/* return user count to zero because add_armature() inc'd it */
|
||||
bl_armature->id.us = 0;
|
||||
/* now create the wrapper obj in Python */
|
||||
py_armature =
|
||||
(BPy_Armature *) PyObject_NEW (BPy_Armature, &Armature_Type);
|
||||
}
|
||||
else
|
||||
return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
|
||||
"couldn't create Armature Data in Blender"));
|
||||
"couldn't create Armature Data in Blender"));
|
||||
|
||||
if (py_armature == NULL)
|
||||
return (EXPP_ReturnPyObjError (PyExc_MemoryError,
|
||||
"couldn't create Armature Data object"));
|
||||
"couldn't create Armature Data object"));
|
||||
|
||||
/* link Python armature wrapper with Blender Armature: */
|
||||
py_armature->armature = bl_armature;
|
||||
|
||||
if (strcmp(name_str, "ArmatureData") == 0)
|
||||
return (PyObject *)py_armature;
|
||||
else { /* user gave us a name for the armature, use it */
|
||||
PyOS_snprintf(buf, sizeof(buf), "%s", name_str);
|
||||
rename_id(&bl_armature->id, buf);
|
||||
}
|
||||
if (strcmp (name_str, "ArmatureData") == 0)
|
||||
return (PyObject *) py_armature;
|
||||
else
|
||||
{ /* user gave us a name for the armature, use it */
|
||||
PyOS_snprintf (buf, sizeof (buf), "%s", name_str);
|
||||
rename_id (&bl_armature->id, buf);
|
||||
}
|
||||
|
||||
return (PyObject *)py_armature;
|
||||
return (PyObject *) py_armature;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Function: M_Armature_Get */
|
||||
/* Python equivalent: Blender.Armature.Get */
|
||||
/*****************************************************************************/
|
||||
static PyObject *M_Armature_Get(PyObject *self, PyObject *args)
|
||||
static PyObject *
|
||||
M_Armature_Get (PyObject * self, PyObject * args)
|
||||
{
|
||||
char *name = NULL;
|
||||
bArmature *armature_iter;
|
||||
char *name = NULL;
|
||||
bArmature *armature_iter;
|
||||
BPy_Armature *wanted_armature;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "|s", &name))
|
||||
if (!PyArg_ParseTuple (args, "|s", &name))
|
||||
return (EXPP_ReturnPyObjError (PyExc_TypeError,
|
||||
"expected string argument (or nothing)"));
|
||||
"expected string argument (or nothing)"));
|
||||
|
||||
armature_iter = G.main->armature.first;
|
||||
|
||||
/* Use the name to search for the armature requested. */
|
||||
|
||||
if (name) { /* (name) - Search armature by name */
|
||||
wanted_armature = NULL;
|
||||
if (name)
|
||||
{ /* (name) - Search armature by name */
|
||||
wanted_armature = NULL;
|
||||
|
||||
while ((armature_iter) && (wanted_armature == NULL)) {
|
||||
while ((armature_iter) && (wanted_armature == NULL))
|
||||
{
|
||||
|
||||
if (strcmp (name, armature_iter->id.name+2) == 0) {
|
||||
wanted_armature = (BPy_Armature *)PyObject_NEW(BPy_Armature, &Armature_Type);
|
||||
if (wanted_armature) wanted_armature->armature = armature_iter;
|
||||
}
|
||||
if (strcmp (name, armature_iter->id.name + 2) == 0)
|
||||
{
|
||||
wanted_armature =
|
||||
(BPy_Armature *) PyObject_NEW (BPy_Armature, &Armature_Type);
|
||||
if (wanted_armature)
|
||||
wanted_armature->armature = armature_iter;
|
||||
}
|
||||
|
||||
armature_iter = armature_iter->id.next;
|
||||
armature_iter = armature_iter->id.next;
|
||||
}
|
||||
|
||||
if (wanted_armature == NULL)
|
||||
{ /* Requested Armature doesn't exist */
|
||||
char error_msg[64];
|
||||
PyOS_snprintf (error_msg, sizeof (error_msg),
|
||||
"Armature \"%s\" not found", name);
|
||||
return (EXPP_ReturnPyObjError (PyExc_NameError, error_msg));
|
||||
}
|
||||
|
||||
return (PyObject *) wanted_armature;
|
||||
}
|
||||
|
||||
if (wanted_armature == NULL) {/* Requested Armature doesn't exist */
|
||||
char error_msg[64];
|
||||
PyOS_snprintf(error_msg, sizeof(error_msg),
|
||||
"Armature \"%s\" not found", name);
|
||||
return (EXPP_ReturnPyObjError (PyExc_NameError, error_msg));
|
||||
}
|
||||
|
||||
return (PyObject*)wanted_armature;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
/* Return a list of with armatures in the scene */
|
||||
@ -129,21 +254,22 @@ static PyObject *M_Armature_Get(PyObject *self, PyObject *args)
|
||||
armlist = PyList_New (BLI_countlist (&(G.main->armature)));
|
||||
|
||||
if (armlist == NULL)
|
||||
return (PythonReturnErrorObject (PyExc_MemoryError,
|
||||
"couldn't create PyList"));
|
||||
return (PythonReturnErrorObject (PyExc_MemoryError,
|
||||
"couldn't create PyList"));
|
||||
|
||||
while (armature_iter) {
|
||||
pyobj = Armature_CreatePyObject (armature_iter);
|
||||
while (armature_iter)
|
||||
{
|
||||
pyobj = Armature_CreatePyObject (armature_iter);
|
||||
|
||||
if (!pyobj)
|
||||
return (PythonReturnErrorObject (PyExc_MemoryError,
|
||||
"couldn't create PyString"));
|
||||
if (!pyobj)
|
||||
return (PythonReturnErrorObject (PyExc_MemoryError,
|
||||
"couldn't create PyString"));
|
||||
|
||||
PyList_SET_ITEM (armlist, index, pyobj);
|
||||
PyList_SET_ITEM (armlist, index, pyobj);
|
||||
|
||||
armature_iter = armature_iter->id.next;
|
||||
index++;
|
||||
}
|
||||
armature_iter = armature_iter->id.next;
|
||||
index++;
|
||||
}
|
||||
|
||||
return (armlist);
|
||||
}
|
||||
@ -153,19 +279,20 @@ static PyObject *M_Armature_Get(PyObject *self, PyObject *args)
|
||||
/*****************************************************************************/
|
||||
/* Function: Armature_Init */
|
||||
/*****************************************************************************/
|
||||
PyObject *Armature_Init (void)
|
||||
PyObject *
|
||||
Armature_Init (void)
|
||||
{
|
||||
PyObject *submodule;
|
||||
PyObject *dict;
|
||||
PyObject *submodule;
|
||||
PyObject *dict;
|
||||
|
||||
Armature_Type.ob_type = &PyType_Type;
|
||||
|
||||
submodule = Py_InitModule3("Blender.Armature",
|
||||
M_Armature_methods, M_Armature_doc);
|
||||
submodule = Py_InitModule3 ("Blender.Armature",
|
||||
M_Armature_methods, M_Armature_doc);
|
||||
|
||||
/* Add the Bone submodule to this module */
|
||||
dict = PyModule_GetDict (submodule);
|
||||
PyDict_SetItemString (dict, "Bone", Bone_Init());
|
||||
PyDict_SetItemString (dict, "Bone", Bone_Init ());
|
||||
|
||||
return (submodule);
|
||||
}
|
||||
@ -173,76 +300,85 @@ PyObject *Armature_Init (void)
|
||||
/*****************************************************************************/
|
||||
/* Python BPy_Armature methods: */
|
||||
/*****************************************************************************/
|
||||
static PyObject *Armature_getName(BPy_Armature *self)
|
||||
static PyObject *
|
||||
Armature_getName (BPy_Armature * self)
|
||||
{
|
||||
PyObject *attr = PyString_FromString(self->armature->id.name+2);
|
||||
PyObject *attr = PyString_FromString (self->armature->id.name + 2);
|
||||
|
||||
if (attr) return attr;
|
||||
if (attr)
|
||||
return attr;
|
||||
|
||||
return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
|
||||
"couldn't get Armature.name attribute"));
|
||||
"couldn't get Armature.name attribute"));
|
||||
}
|
||||
|
||||
|
||||
/** Create and return a list of the root bones for this armature. */
|
||||
static PyObject *Armature_getBones(BPy_Armature *self)
|
||||
static PyObject *
|
||||
Armature_getBones (BPy_Armature * self)
|
||||
{
|
||||
int totbones = 0;
|
||||
PyObject *listbones = NULL;
|
||||
Bone* current = NULL;
|
||||
Bone *current = NULL;
|
||||
int i;
|
||||
|
||||
/* Count the number of bones to create the list */
|
||||
current = self->armature->bonebase.first;
|
||||
for (;current; current=current->next) totbones++;
|
||||
for (; current; current = current->next)
|
||||
totbones++;
|
||||
|
||||
/* Create a list with a bone wrapper for each bone */
|
||||
current = self->armature->bonebase.first;
|
||||
listbones = PyList_New(totbones);
|
||||
for (i=0; i<totbones; i++) {
|
||||
/* Wrap and set to corresponding element of the list. */
|
||||
PyList_SetItem(listbones, i, Bone_CreatePyObject(current) );
|
||||
current = current->next;
|
||||
}
|
||||
listbones = PyList_New (totbones);
|
||||
for (i = 0; i < totbones; i++)
|
||||
{
|
||||
/* Wrap and set to corresponding element of the list. */
|
||||
PyList_SetItem (listbones, i, Bone_CreatePyObject (current));
|
||||
current = current->next;
|
||||
}
|
||||
|
||||
return listbones;
|
||||
}
|
||||
|
||||
|
||||
static PyObject *Armature_setName(BPy_Armature *self, PyObject *args)
|
||||
static PyObject *
|
||||
Armature_setName (BPy_Armature * self, PyObject * args)
|
||||
{
|
||||
char *name;
|
||||
char buf[21];
|
||||
|
||||
if (!PyArg_ParseTuple(args, "s", &name))
|
||||
if (!PyArg_ParseTuple (args, "s", &name))
|
||||
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
|
||||
"expected string argument"));
|
||||
"expected string argument"));
|
||||
|
||||
PyOS_snprintf(buf, sizeof(buf), "%s", name);
|
||||
PyOS_snprintf (buf, sizeof (buf), "%s", name);
|
||||
|
||||
rename_id(&self->armature->id, buf);
|
||||
rename_id (&self->armature->id, buf);
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
Py_INCREF (Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
/*
|
||||
static PyObject *Armature_setBones(BPy_Armature *self, PyObject *args)
|
||||
{
|
||||
// TODO: Implement me!
|
||||
printf("ERROR: Armature_setBones NOT implemented yet!\n");
|
||||
Py_INCREF(Py_None);
|
||||
|
||||
#if 0
|
||||
static PyObject *
|
||||
Armature_setBones (BPy_Armature * self, PyObject * args)
|
||||
{
|
||||
/* TODO: Implement me! */
|
||||
printf ("ERROR: Armature_setBones NOT implemented yet!\n");
|
||||
Py_INCREF (Py_None);
|
||||
return Py_None;
|
||||
|
||||
}
|
||||
*/
|
||||
}
|
||||
#endif
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Function: Armature_dealloc */
|
||||
/* Description: This is a callback function for the BPy_Armature type. It is */
|
||||
/* the destructor function. */
|
||||
/*****************************************************************************/
|
||||
static void Armature_dealloc (BPy_Armature *self)
|
||||
static void
|
||||
Armature_dealloc (BPy_Armature * self)
|
||||
{
|
||||
PyObject_DEL (self);
|
||||
}
|
||||
@ -253,28 +389,30 @@ static void Armature_dealloc (BPy_Armature *self)
|
||||
/* the function that accesses BPy_Armature member variables and */
|
||||
/* methods. */
|
||||
/*****************************************************************************/
|
||||
static PyObject* Armature_getAttr (BPy_Armature *self, char *name)
|
||||
static PyObject *
|
||||
Armature_getAttr (BPy_Armature * self, char *name)
|
||||
{
|
||||
PyObject *attr = Py_None;
|
||||
|
||||
if (strcmp(name, "name") == 0)
|
||||
attr = Armature_getName(self);
|
||||
if (strcmp(name, "bones") == 0)
|
||||
attr = Armature_getBones(self);
|
||||
else if (strcmp(name, "__members__") == 0) {
|
||||
/* 2 entries */
|
||||
attr = Py_BuildValue("[s,s]",
|
||||
"name", "bones");
|
||||
}
|
||||
if (strcmp (name, "name") == 0)
|
||||
attr = Armature_getName (self);
|
||||
if (strcmp (name, "bones") == 0)
|
||||
attr = Armature_getBones (self);
|
||||
else if (strcmp (name, "__members__") == 0)
|
||||
{
|
||||
/* 2 entries */
|
||||
attr = Py_BuildValue ("[s,s]", "name", "bones");
|
||||
}
|
||||
|
||||
if (!attr)
|
||||
return (EXPP_ReturnPyObjError (PyExc_MemoryError,
|
||||
"couldn't create PyObject"));
|
||||
"couldn't create PyObject"));
|
||||
|
||||
if (attr != Py_None) return attr; /* member attribute found, return it */
|
||||
if (attr != Py_None)
|
||||
return attr; /* member attribute found, return it */
|
||||
|
||||
/* not an attribute, search the methods table */
|
||||
return Py_FindMethod(BPy_Armature_methods, (PyObject *)self, name);
|
||||
return Py_FindMethod (BPy_Armature_methods, (PyObject *) self, name);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
@ -284,35 +422,37 @@ static PyObject* Armature_getAttr (BPy_Armature *self, char *name)
|
||||
/* this data is linked to a Blender Armature, it also gets */
|
||||
/* updated. */
|
||||
/*****************************************************************************/
|
||||
static int Armature_setAttr (BPy_Armature *self, char *name, PyObject *value)
|
||||
static int
|
||||
Armature_setAttr (BPy_Armature * self, char *name, PyObject * value)
|
||||
{
|
||||
PyObject *valtuple;
|
||||
PyObject *error = NULL;
|
||||
|
||||
valtuple = Py_BuildValue("(O)", value); /*the set* functions expect a tuple*/
|
||||
valtuple = Py_BuildValue ("(O)", value); /*the set* functions expect a tuple */
|
||||
|
||||
if (!valtuple)
|
||||
return EXPP_ReturnIntError(PyExc_MemoryError,
|
||||
"ArmatureSetAttr: couldn't create tuple");
|
||||
return EXPP_ReturnIntError (PyExc_MemoryError,
|
||||
"ArmatureSetAttr: couldn't create tuple");
|
||||
|
||||
if (strcmp (name, "name") == 0)
|
||||
error = Armature_setName (self, valtuple);
|
||||
/* if (strcmp (name, "bones") == 0)
|
||||
error = Armature_setBones (self, valtuple);*/
|
||||
else { /* Error */
|
||||
Py_DECREF(valtuple);
|
||||
error = Armature_setBones (self, valtuple); */
|
||||
else
|
||||
{ /* Error */
|
||||
Py_DECREF (valtuple);
|
||||
|
||||
/* ... member with the given name was found */
|
||||
return (EXPP_ReturnIntError (PyExc_KeyError,
|
||||
"attribute not found"));
|
||||
}
|
||||
/* ... member with the given name was found */
|
||||
return (EXPP_ReturnIntError (PyExc_KeyError, "attribute not found"));
|
||||
}
|
||||
|
||||
Py_DECREF(valtuple);
|
||||
Py_DECREF (valtuple);
|
||||
|
||||
if (error != Py_None) return -1;
|
||||
if (error != Py_None)
|
||||
return -1;
|
||||
|
||||
Py_DECREF(Py_None); /* was incref'ed by the called Armature_set* function */
|
||||
return 0; /* normal exit */
|
||||
Py_DECREF (Py_None); /* was incref'ed by the called Armature_set* function */
|
||||
return 0; /* normal exit */
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
@ -320,9 +460,11 @@ static int Armature_setAttr (BPy_Armature *self, char *name, PyObject *value)
|
||||
/* Description: This is a callback function for the BPy_Armature type. It */
|
||||
/* builds a meaninful string to represent armature objects. */
|
||||
/*****************************************************************************/
|
||||
static PyObject *Armature_repr (BPy_Armature *self)
|
||||
static PyObject *
|
||||
Armature_repr (BPy_Armature * self)
|
||||
{
|
||||
return PyString_FromFormat("[Armature \"%s\"]", self->armature->id.name+2);
|
||||
return PyString_FromFormat ("[Armature \"%s\"]",
|
||||
self->armature->id.name + 2);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
@ -331,10 +473,11 @@ static PyObject *Armature_repr (BPy_Armature *self)
|
||||
/* compares the two armatures: translate comparison to the */
|
||||
/* C pointers. */
|
||||
/*****************************************************************************/
|
||||
static int Armature_compare (BPy_Armature *a, BPy_Armature *b)
|
||||
static int
|
||||
Armature_compare (BPy_Armature * a, BPy_Armature * b)
|
||||
{
|
||||
bArmature *pa = a->armature, *pb = b->armature;
|
||||
return (pa == pb) ? 0:-1;
|
||||
return (pa == pb) ? 0 : -1;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
@ -342,18 +485,20 @@ static int Armature_compare (BPy_Armature *a, BPy_Armature *b)
|
||||
/* Description: This function will create a new BlenArmature from an */
|
||||
/* existing Armature structure. */
|
||||
/*****************************************************************************/
|
||||
PyObject* Armature_CreatePyObject (struct bArmature *obj)
|
||||
PyObject *
|
||||
Armature_CreatePyObject (struct bArmature * obj)
|
||||
{
|
||||
BPy_Armature * blen_armature;
|
||||
BPy_Armature *blen_armature;
|
||||
|
||||
blen_armature = (BPy_Armature*)PyObject_NEW (BPy_Armature, &Armature_Type);
|
||||
blen_armature =
|
||||
(BPy_Armature *) PyObject_NEW (BPy_Armature, &Armature_Type);
|
||||
|
||||
if (blen_armature == NULL)
|
||||
{
|
||||
return (NULL);
|
||||
}
|
||||
blen_armature->armature = obj;
|
||||
return ((PyObject*)blen_armature);
|
||||
return ((PyObject *) blen_armature);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
@ -361,7 +506,8 @@ PyObject* Armature_CreatePyObject (struct bArmature *obj)
|
||||
/* Description: This function returns true when the given PyObject is of the */
|
||||
/* type Armature. Otherwise it will return false. */
|
||||
/*****************************************************************************/
|
||||
int Armature_CheckPyObject (PyObject *py_obj)
|
||||
int
|
||||
Armature_CheckPyObject (PyObject * py_obj)
|
||||
{
|
||||
return (py_obj->ob_type == &Armature_Type);
|
||||
}
|
||||
@ -371,10 +517,11 @@ int Armature_CheckPyObject (PyObject *py_obj)
|
||||
/* Description: This function returns the Blender armature from the given */
|
||||
/* PyObject. */
|
||||
/*****************************************************************************/
|
||||
struct bArmature* Armature_FromPyObject (PyObject *py_obj)
|
||||
struct bArmature *
|
||||
Armature_FromPyObject (PyObject * py_obj)
|
||||
{
|
||||
BPy_Armature * blen_obj;
|
||||
BPy_Armature *blen_obj;
|
||||
|
||||
blen_obj = (BPy_Armature*)py_obj;
|
||||
blen_obj = (BPy_Armature *) py_obj;
|
||||
return (blen_obj->armature);
|
||||
}
|
||||
|
@ -33,135 +33,16 @@
|
||||
#define EXPP_ARMATURE_H
|
||||
|
||||
#include <Python.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <BKE_main.h>
|
||||
#include <BKE_global.h>
|
||||
#include <BKE_object.h>
|
||||
#include <BKE_armature.h>
|
||||
#include <BKE_library.h>
|
||||
#include <BLI_blenlib.h>
|
||||
#include <DNA_armature_types.h>
|
||||
|
||||
#include "constant.h"
|
||||
#include "gen_utils.h"
|
||||
#include "modules.h"
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python API function prototypes for the Armature module. */
|
||||
/*****************************************************************************/
|
||||
static PyObject *M_Armature_New (PyObject *self, PyObject *args,
|
||||
PyObject *keywords);
|
||||
static PyObject *M_Armature_Get (PyObject *self, PyObject *args);
|
||||
PyObject *Armature_Init (void);
|
||||
|
||||
/*****************************************************************************/
|
||||
/* The following string definitions are used for documentation strings. */
|
||||
/* In Python these will be written to the console when doing a */
|
||||
/* Blender.Armature.__doc__ */
|
||||
/*****************************************************************************/
|
||||
char M_Armature_doc[] =
|
||||
"The Blender Armature module\n\n\
|
||||
This module provides control over **Armature Data** objects in Blender.\n";
|
||||
|
||||
char M_Armature_New_doc[] =
|
||||
"(name) - return a new Armature datablock of \n\
|
||||
optional name 'name'.";
|
||||
|
||||
char M_Armature_Get_doc[] =
|
||||
"(name) - return the armature with the name 'name', \
|
||||
returns None if not found.\n If 'name' is not specified, \
|
||||
it returns a list of all armatures in the\ncurrent scene.";
|
||||
|
||||
char M_Armature_get_doc[] =
|
||||
"(name) - DEPRECATED. Use 'Get' instead. \
|
||||
return the armature with the name 'name', \
|
||||
returns None if not found.\n If 'name' is not specified, \
|
||||
it returns a list of all armatures in the\ncurrent scene.";
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python method structure definition for Blender.Armature module: */
|
||||
/*****************************************************************************/
|
||||
struct PyMethodDef M_Armature_methods[] = {
|
||||
{"New",(PyCFunction)M_Armature_New, METH_VARARGS|METH_KEYWORDS,
|
||||
M_Armature_New_doc},
|
||||
{"Get", M_Armature_Get, METH_VARARGS, M_Armature_Get_doc},
|
||||
{"get", M_Armature_Get, METH_VARARGS, M_Armature_get_doc},
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python BPy_Armature structure definition: */
|
||||
/*****************************************************************************/
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
bArmature *armature;
|
||||
} BPy_Armature;
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python BPy_Armature methods declarations: */
|
||||
/*****************************************************************************/
|
||||
static PyObject *Armature_getName(BPy_Armature *self);
|
||||
static PyObject *Armature_getBones(BPy_Armature *self);
|
||||
static PyObject *Armature_setName(BPy_Armature *self, PyObject *args);
|
||||
//static PyObject *Armature_setBones(BPy_Armature *self, PyObject *args);
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python BPy_Armature methods table: */
|
||||
/*****************************************************************************/
|
||||
static PyMethodDef BPy_Armature_methods[] = {
|
||||
/* name, method, flags, doc */
|
||||
{"getName", (PyCFunction)Armature_getName, METH_NOARGS,
|
||||
"() - return Armature name"},
|
||||
{"getBones", (PyCFunction)Armature_getBones, METH_NOARGS,
|
||||
"() - return Armature root bones"},
|
||||
{"setName", (PyCFunction)Armature_setName, METH_VARARGS,
|
||||
"(str) - rename Armature"},
|
||||
/* {"setBones", (PyCFunction)Armature_setBones, METH_VARARGS,
|
||||
"(list of bones) - replace the whole bone list of the armature"},
|
||||
*/
|
||||
{0}
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python TypeArmature callback function prototypes: */
|
||||
/*****************************************************************************/
|
||||
static void Armature_dealloc (BPy_Armature *armature);
|
||||
static PyObject *Armature_getAttr (BPy_Armature *armature, char *name);
|
||||
static int Armature_setAttr (BPy_Armature *armature, char *name, PyObject *v);
|
||||
static int Armature_compare (BPy_Armature *a1, BPy_Armature *a2);
|
||||
static PyObject *Armature_repr (BPy_Armature *armature);
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python TypeArmature structure definition: */
|
||||
/*****************************************************************************/
|
||||
PyTypeObject Armature_Type =
|
||||
typedef struct
|
||||
{
|
||||
PyObject_HEAD_INIT(NULL)
|
||||
0, /* ob_size */
|
||||
"Blender Armature", /* tp_name */
|
||||
sizeof (BPy_Armature), /* tp_basicsize */
|
||||
0, /* tp_itemsize */
|
||||
/* methods */
|
||||
(destructor)Armature_dealloc, /* tp_dealloc */
|
||||
0, /* tp_print */
|
||||
(getattrfunc)Armature_getAttr, /* tp_getattr */
|
||||
(setattrfunc)Armature_setAttr, /* tp_setattr */
|
||||
(cmpfunc)Armature_compare, /* tp_compare */
|
||||
(reprfunc)Armature_repr, /* tp_repr */
|
||||
0, /* tp_as_number */
|
||||
0, /* tp_as_sequence */
|
||||
0, /* tp_as_mapping */
|
||||
0, /* tp_as_hash */
|
||||
0,0,0,0,0,0,
|
||||
0, /* tp_doc */
|
||||
0,0,0,0,0,0,
|
||||
BPy_Armature_methods, /* tp_methods */
|
||||
0, /* tp_members */
|
||||
};
|
||||
|
||||
|
||||
|
||||
PyObject_HEAD bArmature * armature;
|
||||
}
|
||||
BPy_Armature;
|
||||
|
||||
#endif /* EXPP_ARMATURE_H */
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -41,14 +41,15 @@ PyObject *Bone_Init (void);
|
||||
|
||||
|
||||
/** Python BPy_Bone structure definition. */
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
Bone *bone;
|
||||
} BPy_Bone;
|
||||
typedef struct
|
||||
{
|
||||
PyObject_HEAD Bone *bone;
|
||||
}
|
||||
BPy_Bone;
|
||||
|
||||
|
||||
PyObject* Bone_CreatePyObject (struct Bone *obj);
|
||||
int Bone_CheckPyObject (PyObject *py_obj);
|
||||
Bone* Bone_FromPyObject (PyObject *py_obj);
|
||||
PyObject *Bone_CreatePyObject (struct Bone *obj);
|
||||
int Bone_CheckPyObject (PyObject * py_obj);
|
||||
Bone *Bone_FromPyObject (PyObject * py_obj);
|
||||
|
||||
#endif
|
||||
|
@ -31,49 +31,57 @@
|
||||
|
||||
#include "Build.h"
|
||||
#include "Effect.h"
|
||||
#include "gen_utils.h"
|
||||
|
||||
#include <BLI_arithb.h>
|
||||
#include <BLI_blenlib.h>
|
||||
#include <BKE_main.h>
|
||||
#include <BKE_global.h>
|
||||
#include <BKE_object.h>
|
||||
#include <BKE_library.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python BPy_Build methods table: */
|
||||
/*****************************************************************************/
|
||||
static PyMethodDef BPy_Build_methods[] = {
|
||||
{"getLen",(PyCFunction)Build_getLen,
|
||||
METH_NOARGS,"()-Return Build len"},
|
||||
{"setLen",(PyCFunction)Build_setLen, METH_VARARGS,
|
||||
"()- Sets Build len"},
|
||||
{"getSfra",(PyCFunction)Build_getSfra,
|
||||
METH_NOARGS,"()-Return Build sfra"},
|
||||
{"setSfra",(PyCFunction)Build_setSfra, METH_VARARGS,
|
||||
"()- Sets Build sfra"},
|
||||
{0}
|
||||
{"getLen", (PyCFunction) Build_getLen,
|
||||
METH_NOARGS, "()-Return Build len"},
|
||||
{"setLen", (PyCFunction) Build_setLen, METH_VARARGS,
|
||||
"()- Sets Build len"},
|
||||
{"getSfra", (PyCFunction) Build_getSfra,
|
||||
METH_NOARGS, "()-Return Build sfra"},
|
||||
{"setSfra", (PyCFunction) Build_setSfra, METH_VARARGS,
|
||||
"()- Sets Build sfra"},
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python Build_Type structure definition: */
|
||||
/*****************************************************************************/
|
||||
PyTypeObject Build_Type =
|
||||
{
|
||||
PyObject_HEAD_INIT(NULL)
|
||||
0, /* ob_size */
|
||||
"Build", /* tp_name */
|
||||
sizeof (BPy_Build), /* tp_basicsize */
|
||||
0, /* tp_itemsize */
|
||||
PyTypeObject Build_Type = {
|
||||
PyObject_HEAD_INIT (NULL) 0, /* ob_size */
|
||||
"Build", /* tp_name */
|
||||
sizeof (BPy_Build), /* tp_basicsize */
|
||||
0, /* tp_itemsize */
|
||||
/* methods */
|
||||
(destructor)BuildDeAlloc, /* tp_dealloc */
|
||||
0, /* tp_print */
|
||||
(getattrfunc)BuildGetAttr, /* tp_getattr */
|
||||
(setattrfunc)BuildSetAttr, /* tp_setattr */
|
||||
0, /* tp_compare */
|
||||
(reprfunc)BuildRepr, /* tp_repr */
|
||||
0, /* tp_as_number */
|
||||
0, /* tp_as_sequence */
|
||||
0, /* tp_as_mapping */
|
||||
0, /* tp_as_hash */
|
||||
0,0,0,0,0,0,
|
||||
0, /* tp_doc */
|
||||
0,0,0,0,0,0,
|
||||
BPy_Build_methods, /* tp_methods */
|
||||
0, /* tp_members */
|
||||
(destructor) BuildDeAlloc, /* tp_dealloc */
|
||||
0, /* tp_print */
|
||||
(getattrfunc) BuildGetAttr, /* tp_getattr */
|
||||
(setattrfunc) BuildSetAttr, /* tp_setattr */
|
||||
0, /* tp_compare */
|
||||
(reprfunc) BuildRepr, /* tp_repr */
|
||||
0, /* tp_as_number */
|
||||
0, /* tp_as_sequence */
|
||||
0, /* tp_as_mapping */
|
||||
0, /* tp_as_hash */
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, /* tp_doc */
|
||||
0, 0, 0, 0, 0, 0,
|
||||
BPy_Build_methods, /* tp_methods */
|
||||
0, /* tp_members */
|
||||
};
|
||||
|
||||
|
||||
@ -84,16 +92,13 @@ PyTypeObject Build_Type =
|
||||
/* Blender.Camera.__doc__ */
|
||||
/*****************************************************************************/
|
||||
|
||||
static char M_Build_doc[] =
|
||||
"The Blender Build module\n\
|
||||
static char M_Build_doc[] = "The Blender Build module\n\
|
||||
This module provides access to **Build Data** objects in Blender\n";
|
||||
|
||||
static char M_Build_New_doc[] =
|
||||
"Build.New ():\n\
|
||||
static char M_Build_New_doc[] = "Build.New ():\n\
|
||||
Return a new Build Data object with the given type and name.";
|
||||
|
||||
static char M_Build_Get_doc[] =
|
||||
"Build.Get (name = None):\n\
|
||||
static char M_Build_Get_doc[] = "Build.Get (name = None):\n\
|
||||
Return the build data with the given 'name', None if not found, or\n\
|
||||
Return a list with all Build Data objects in the current scene,\n\
|
||||
if no argument was given.";
|
||||
@ -102,27 +107,29 @@ static char M_Build_Get_doc[] =
|
||||
/* Function: M_Build_New */
|
||||
/* Python equivalent: Blender.Effect.Build.New */
|
||||
/*****************************************************************************/
|
||||
PyObject *M_Build_New(PyObject *self, PyObject *args)
|
||||
PyObject *
|
||||
M_Build_New (PyObject * self, PyObject * args)
|
||||
{
|
||||
int type = EFF_BUILD;
|
||||
BPy_Effect *pyeffect;
|
||||
Effect *bleffect = 0;
|
||||
int type = EFF_BUILD;
|
||||
BPy_Effect *pyeffect;
|
||||
Effect *bleffect = 0;
|
||||
|
||||
|
||||
bleffect = add_effect(type);
|
||||
bleffect = add_effect (type);
|
||||
if (bleffect == NULL)
|
||||
return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
|
||||
"couldn't create Effect Data in Blender"));
|
||||
"couldn't create Effect Data in Blender"));
|
||||
|
||||
pyeffect = (BPy_Effect *)PyObject_NEW(BPy_Effect, &Effect_Type);
|
||||
pyeffect = (BPy_Effect *) PyObject_NEW (BPy_Effect, &Effect_Type);
|
||||
|
||||
|
||||
if (pyeffect == NULL) return (EXPP_ReturnPyObjError (PyExc_MemoryError,
|
||||
"couldn't create Effect Data object"));
|
||||
if (pyeffect == NULL)
|
||||
return (EXPP_ReturnPyObjError (PyExc_MemoryError,
|
||||
"couldn't create Effect Data object"));
|
||||
|
||||
pyeffect->effect = bleffect;
|
||||
|
||||
return (PyObject *)pyeffect;
|
||||
return (PyObject *) pyeffect;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -130,26 +137,28 @@ int type = EFF_BUILD;
|
||||
/* Function: M_Build_Get */
|
||||
/* Python equivalent: Blender.Effect.Build.Get */
|
||||
/*****************************************************************************/
|
||||
PyObject *M_Build_Get(PyObject *self, PyObject *args)
|
||||
PyObject *
|
||||
M_Build_Get (PyObject * self, PyObject * args)
|
||||
{
|
||||
/*arguments : string object name
|
||||
int : position of effect in the obj's effect list */
|
||||
char *name = 0;
|
||||
Object *object_iter;
|
||||
int : position of effect in the obj's effect list */
|
||||
char *name = 0;
|
||||
Object *object_iter;
|
||||
Effect *eff;
|
||||
BPy_Build *wanted_eff;
|
||||
int num,i;
|
||||
if (!PyArg_ParseTuple(args, "si", &name, &num ))
|
||||
return(EXPP_ReturnPyObjError(PyExc_AttributeError,\
|
||||
"expected string int argument"));
|
||||
int num, i;
|
||||
if (!PyArg_ParseTuple (args, "si", &name, &num))
|
||||
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
|
||||
"expected string int argument"));
|
||||
|
||||
object_iter = G.main->object.first;
|
||||
if (!object_iter)return(EXPP_ReturnPyObjError(PyExc_AttributeError,\
|
||||
"Scene contains no object"));
|
||||
if (!object_iter)
|
||||
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
|
||||
"Scene contains no object"));
|
||||
|
||||
while (object_iter)
|
||||
{
|
||||
if (strcmp(name,object_iter->id.name+2))
|
||||
if (strcmp (name, object_iter->id.name + 2))
|
||||
{
|
||||
object_iter = object_iter->id.next;
|
||||
continue;
|
||||
@ -159,29 +168,31 @@ PyObject *M_Build_Get(PyObject *self, PyObject *args)
|
||||
if (object_iter->effect.first != NULL)
|
||||
{
|
||||
eff = object_iter->effect.first;
|
||||
for(i = 0;i<num;i++)
|
||||
for (i = 0; i < num; i++)
|
||||
{
|
||||
if (eff->type != EFF_BUILD)continue;
|
||||
if (eff->type != EFF_BUILD)
|
||||
continue;
|
||||
eff = eff->next;
|
||||
if (!eff)
|
||||
return(EXPP_ReturnPyObjError(PyExc_AttributeError,"object not created"));
|
||||
return (EXPP_ReturnPyObjError
|
||||
(PyExc_AttributeError, "object not created"));
|
||||
}
|
||||
wanted_eff = (BPy_Build *)PyObject_NEW(BPy_Build, &Build_Type);
|
||||
wanted_eff = (BPy_Build *) PyObject_NEW (BPy_Build, &Build_Type);
|
||||
wanted_eff->build = eff;
|
||||
return (PyObject*)wanted_eff;
|
||||
return (PyObject *) wanted_eff;
|
||||
}
|
||||
object_iter = object_iter->id.next;
|
||||
}
|
||||
Py_INCREF(Py_None);
|
||||
Py_INCREF (Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
|
||||
|
||||
struct PyMethodDef M_Build_methods[] = {
|
||||
{"New",(PyCFunction)M_Build_New, METH_VARARGS, M_Build_New_doc},
|
||||
{"Get", M_Build_Get, METH_VARARGS, M_Build_Get_doc},
|
||||
{"get", M_Build_Get, METH_VARARGS,M_Build_Get_doc},
|
||||
{"New", (PyCFunction) M_Build_New, METH_VARARGS, M_Build_New_doc},
|
||||
{"Get", M_Build_Get, METH_VARARGS, M_Build_Get_doc},
|
||||
{"get", M_Build_Get, METH_VARARGS, M_Build_Get_doc},
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
@ -189,12 +200,13 @@ struct PyMethodDef M_Build_methods[] = {
|
||||
/* Function: Build_Init */
|
||||
/*****************************************************************************/
|
||||
|
||||
PyObject *Build_Init (void)
|
||||
PyObject *
|
||||
Build_Init (void)
|
||||
{
|
||||
PyObject *submodule;
|
||||
PyObject *submodule;
|
||||
|
||||
Build_Type.ob_type = &PyType_Type;
|
||||
submodule = Py_InitModule3("Blender.Build",M_Build_methods,M_Build_doc );
|
||||
submodule = Py_InitModule3 ("Blender.Build", M_Build_methods, M_Build_doc);
|
||||
return (submodule);
|
||||
}
|
||||
|
||||
@ -202,41 +214,46 @@ PyObject *Build_Init (void)
|
||||
/* Python BPy_Build methods: */
|
||||
/*****************************************************************************/
|
||||
|
||||
PyObject *Build_getLen(BPy_Build *self)
|
||||
PyObject *
|
||||
Build_getLen (BPy_Build * self)
|
||||
{
|
||||
BuildEff*ptr = (BuildEff*)self->build;
|
||||
return PyFloat_FromDouble(ptr->len);
|
||||
BuildEff *ptr = (BuildEff *) self->build;
|
||||
return PyFloat_FromDouble (ptr->len);
|
||||
}
|
||||
|
||||
|
||||
PyObject *Build_setLen(BPy_Build *self,PyObject *args)
|
||||
PyObject *
|
||||
Build_setLen (BPy_Build * self, PyObject * args)
|
||||
{
|
||||
BuildEff*ptr = (BuildEff*)self->build;
|
||||
BuildEff *ptr = (BuildEff *) self->build;
|
||||
float val = 0;
|
||||
if (!PyArg_ParseTuple(args, "f", &val ))
|
||||
return(EXPP_ReturnPyObjError(PyExc_AttributeError,\
|
||||
"expected float argument"));
|
||||
if (!PyArg_ParseTuple (args, "f", &val))
|
||||
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
|
||||
"expected float argument"));
|
||||
ptr->len = val;
|
||||
Py_INCREF(Py_None);
|
||||
Py_INCREF (Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
|
||||
PyObject *Build_getSfra(BPy_Build *self)
|
||||
PyObject *
|
||||
Build_getSfra (BPy_Build * self)
|
||||
{
|
||||
BuildEff*ptr = (BuildEff*)self->build;
|
||||
return PyFloat_FromDouble(ptr->sfra);
|
||||
BuildEff *ptr = (BuildEff *) self->build;
|
||||
return PyFloat_FromDouble (ptr->sfra);
|
||||
}
|
||||
|
||||
PyObject *Build_setSfra(BPy_Build *self,PyObject *args)
|
||||
PyObject *
|
||||
Build_setSfra (BPy_Build * self, PyObject * args)
|
||||
{
|
||||
BuildEff*ptr = (BuildEff*)self->build;
|
||||
BuildEff *ptr = (BuildEff *) self->build;
|
||||
float val = 0;
|
||||
if (!PyArg_ParseTuple(args, "f", &val ))
|
||||
return(EXPP_ReturnPyObjError(PyExc_AttributeError,"expected float argument"));
|
||||
if (!PyArg_ParseTuple (args, "f", &val))
|
||||
return (EXPP_ReturnPyObjError
|
||||
(PyExc_AttributeError, "expected float argument"));
|
||||
|
||||
ptr->sfra = val;
|
||||
Py_INCREF(Py_None);
|
||||
Py_INCREF (Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
@ -245,9 +262,10 @@ PyObject *Build_setSfra(BPy_Build *self,PyObject *args)
|
||||
/* Description: This is a callback function for the BPy_Build type. It is */
|
||||
/* the destructor function. */
|
||||
/*****************************************************************************/
|
||||
void BuildDeAlloc (BPy_Build *self)
|
||||
void
|
||||
BuildDeAlloc (BPy_Build * self)
|
||||
{
|
||||
BuildEff*ptr = (BuildEff*)self;
|
||||
BuildEff *ptr = (BuildEff *) self;
|
||||
PyObject_DEL (ptr);
|
||||
}
|
||||
|
||||
@ -258,11 +276,14 @@ void BuildDeAlloc (BPy_Build *self)
|
||||
/* methods. */
|
||||
/*****************************************************************************/
|
||||
|
||||
PyObject *BuildGetAttr (BPy_Build *self, char *name)
|
||||
PyObject *
|
||||
BuildGetAttr (BPy_Build * self, char *name)
|
||||
{
|
||||
if (!strcmp(name,"sfra"))return Build_getSfra( self);
|
||||
if (!strcmp(name,"len"))return Build_getLen( self);
|
||||
return Py_FindMethod(BPy_Build_methods, (PyObject *)self, name);
|
||||
if (!strcmp (name, "sfra"))
|
||||
return Build_getSfra (self);
|
||||
if (!strcmp (name, "len"))
|
||||
return Build_getLen (self);
|
||||
return Py_FindMethod (BPy_Build_methods, (PyObject *) self, name);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
@ -270,30 +291,34 @@ PyObject *BuildGetAttr (BPy_Build *self, char *name)
|
||||
/* Description: This is a callback function for the BPy_Build type. It is the */
|
||||
/* function that sets Build Data attributes (member variables). */
|
||||
/*****************************************************************************/
|
||||
int BuildSetAttr (BPy_Build *self, char *name, PyObject *value)
|
||||
int
|
||||
BuildSetAttr (BPy_Build * self, char *name, PyObject * value)
|
||||
{
|
||||
PyObject *valtuple;
|
||||
PyObject *error = NULL;
|
||||
valtuple = Py_BuildValue("(N)", value);
|
||||
valtuple = Py_BuildValue ("(N)", value);
|
||||
|
||||
if (!valtuple)
|
||||
return EXPP_ReturnIntError(PyExc_MemoryError,
|
||||
"CameraSetAttr: couldn't create PyTuple");
|
||||
return EXPP_ReturnIntError (PyExc_MemoryError,
|
||||
"CameraSetAttr: couldn't create PyTuple");
|
||||
|
||||
if (!strcmp (name, "sfra")) error = Build_setSfra (self, valtuple);
|
||||
else if (!strcmp (name, "len")) error = Build_setLen (self, valtuple);
|
||||
if (!strcmp (name, "sfra"))
|
||||
error = Build_setSfra (self, valtuple);
|
||||
else if (!strcmp (name, "len"))
|
||||
error = Build_setLen (self, valtuple);
|
||||
|
||||
else {
|
||||
Py_DECREF(valtuple);
|
||||
return (EXPP_ReturnIntError (PyExc_KeyError,
|
||||
"attribute not found"));
|
||||
}
|
||||
else
|
||||
{
|
||||
Py_DECREF (valtuple);
|
||||
return (EXPP_ReturnIntError (PyExc_KeyError, "attribute not found"));
|
||||
}
|
||||
|
||||
/* Py_DECREF(valtuple);*/
|
||||
/* Py_DECREF(valtuple); */
|
||||
|
||||
if (error != Py_None) return -1;
|
||||
if (error != Py_None)
|
||||
return -1;
|
||||
|
||||
Py_DECREF(Py_None);
|
||||
Py_DECREF (Py_None);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -313,39 +338,42 @@ int BuildPrint(BPy_Build *self, FILE *fp, int flags)
|
||||
/* Description: This is a callback function for the BPy_Build type. It */
|
||||
/* builds a meaninful string to represent build objects. */
|
||||
/*****************************************************************************/
|
||||
PyObject *BuildRepr (BPy_Build *self)
|
||||
PyObject *
|
||||
BuildRepr (BPy_Build * self)
|
||||
{
|
||||
return PyString_FromString("Build effect");
|
||||
return PyString_FromString ("Build effect");
|
||||
}
|
||||
|
||||
PyObject* BuildCreatePyObject (struct Effect *build)
|
||||
PyObject *
|
||||
BuildCreatePyObject (struct Effect * build)
|
||||
{
|
||||
BPy_Build * blen_object;
|
||||
BPy_Build *blen_object;
|
||||
|
||||
|
||||
blen_object = (BPy_Build*)PyObject_NEW (BPy_Build, &Build_Type);
|
||||
blen_object = (BPy_Build *) PyObject_NEW (BPy_Build, &Build_Type);
|
||||
|
||||
if (blen_object == NULL)
|
||||
if (blen_object == NULL)
|
||||
{
|
||||
return (NULL);
|
||||
return (NULL);
|
||||
}
|
||||
blen_object->build = build;
|
||||
return ((PyObject*)blen_object);
|
||||
blen_object->build = build;
|
||||
return ((PyObject *) blen_object);
|
||||
|
||||
}
|
||||
|
||||
int BuildCheckPyObject (PyObject *py_obj)
|
||||
int
|
||||
BuildCheckPyObject (PyObject * py_obj)
|
||||
{
|
||||
return (py_obj->ob_type == &Build_Type);
|
||||
return (py_obj->ob_type == &Build_Type);
|
||||
}
|
||||
|
||||
|
||||
struct Build* BuildFromPyObject (PyObject *py_obj)
|
||||
struct Build *
|
||||
BuildFromPyObject (PyObject * py_obj)
|
||||
{
|
||||
BPy_Build * blen_obj;
|
||||
BPy_Build *blen_obj;
|
||||
|
||||
blen_obj = (BPy_Build*)py_obj;
|
||||
return ((struct Build*)blen_obj->build);
|
||||
blen_obj = (BPy_Build *) py_obj;
|
||||
return ((struct Build *) blen_obj->build);
|
||||
|
||||
}
|
||||
|
||||
|
@ -33,49 +33,44 @@
|
||||
#define EXPP_BUILD_H
|
||||
|
||||
#include <Python.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <BLI_arithb.h>
|
||||
#include <BLI_blenlib.h>
|
||||
#include <BKE_main.h>
|
||||
#include <BKE_global.h>
|
||||
#include <BKE_object.h>
|
||||
#include <BKE_library.h>
|
||||
|
||||
|
||||
#include <DNA_effect_types.h>
|
||||
|
||||
#include "gen_utils.h"
|
||||
|
||||
#include "bpy_types.h"
|
||||
#include "Effect.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python API function prototypes for the Build module. */
|
||||
/*****************************************************************************/
|
||||
PyObject *M_Build_New (PyObject *self, PyObject *args);
|
||||
PyObject *M_Build_Get (PyObject *self, PyObject *args);
|
||||
PyObject *M_Build_New (PyObject * self, PyObject * args);
|
||||
PyObject *M_Build_Get (PyObject * self, PyObject * args);
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python BPy_Build methods declarations: */
|
||||
/*****************************************************************************/
|
||||
PyObject *Build_getLen(BPy_Build *self);
|
||||
PyObject *Build_setLen(BPy_Build *self,PyObject*a);
|
||||
PyObject *Build_getSfra(BPy_Build *self);
|
||||
PyObject *Build_setSfra(BPy_Build *self,PyObject*a);
|
||||
PyObject *Build_getLen (BPy_Build * self);
|
||||
PyObject *Build_setLen (BPy_Build * self, PyObject * a);
|
||||
PyObject *Build_getSfra (BPy_Build * self);
|
||||
PyObject *Build_setSfra (BPy_Build * self, PyObject * a);
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python Build_Type callback function prototypes: */
|
||||
/*****************************************************************************/
|
||||
void BuildDeAlloc (BPy_Build *msh);
|
||||
void BuildDeAlloc (BPy_Build * msh);
|
||||
//int BuildPrint (BPy_Build *msh, FILE *fp, int flags);
|
||||
int BuildSetAttr (BPy_Build *msh, char *name, PyObject *v);
|
||||
PyObject *BuildGetAttr (BPy_Build *msh, char *name);
|
||||
PyObject *BuildRepr (BPy_Build *msh);
|
||||
PyObject* BuildCreatePyObject (struct Effect *build);
|
||||
int BuildCheckPyObject (PyObject *py_obj);
|
||||
struct Build* BuildFromPyObject (PyObject *py_obj);
|
||||
int BuildSetAttr (BPy_Build * msh, char *name, PyObject * v);
|
||||
PyObject *BuildGetAttr (BPy_Build * msh, char *name);
|
||||
PyObject *BuildRepr (BPy_Build * msh);
|
||||
PyObject *BuildCreatePyObject (struct Effect *build);
|
||||
int BuildCheckPyObject (PyObject * py_obj);
|
||||
struct Build *BuildFromPyObject (PyObject * py_obj);
|
||||
|
||||
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -32,12 +32,7 @@
|
||||
#ifndef EXPP_CAMERA_H
|
||||
#define EXPP_CAMERA_H
|
||||
|
||||
#include <Python.h>
|
||||
#include <DNA_camera_types.h>
|
||||
#include "constant.h"
|
||||
#include "gen_utils.h"
|
||||
#include "modules.h"
|
||||
#include "bpy_types.h" /* where the BPy_Camera struct is declared */
|
||||
#include "bpy_types.h" /* where the BPy_Camera struct is declared */
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python BPy_Camera defaults: */
|
||||
@ -64,129 +59,6 @@
|
||||
#define EXPP_CAM_DRAWSIZE_MIN 0.1
|
||||
#define EXPP_CAM_DRAWSIZE_MAX 10.0
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python API function prototypes for the Camera module. */
|
||||
/*****************************************************************************/
|
||||
static PyObject *M_Camera_New (PyObject *self, PyObject *args,
|
||||
PyObject *keywords);
|
||||
static PyObject *M_Camera_Get (PyObject *self, PyObject *args);
|
||||
|
||||
/*****************************************************************************/
|
||||
/* The following string definitions are used for documentation strings. */
|
||||
/* In Python these will be written to the console when doing a */
|
||||
/* Blender.Camera.__doc__ */
|
||||
/*****************************************************************************/
|
||||
static char M_Camera_doc[] =
|
||||
"The Blender Camera module\n\
|
||||
\n\
|
||||
This module provides access to **Camera Data** objects in Blender\n\
|
||||
\n\
|
||||
Example::\n\
|
||||
\n\
|
||||
from Blender import Camera, Object, Scene\n\
|
||||
c = Camera.New('ortho') # create new ortho camera data\n\
|
||||
c.lens = 35.0 # set lens value\n\
|
||||
cur = Scene.getCurrent() # get current Scene\n\
|
||||
ob = Object.New('Camera') # make camera object\n\
|
||||
ob.link(c) # link camera data with this object\n\
|
||||
cur.link(ob) # link object into scene\n\
|
||||
cur.setCurrentCamera(ob) # make this camera the active";
|
||||
|
||||
static char M_Camera_New_doc[] =
|
||||
"Camera.New (type = 'persp', name = 'CamData'):\n\
|
||||
Return a new Camera Data object with the given type and name.";
|
||||
|
||||
static char M_Camera_Get_doc[] =
|
||||
"Camera.Get (name = None):\n\
|
||||
Return the camera data with the given 'name', None if not found, or\n\
|
||||
Return a list with all Camera Data objects in the current scene,\n\
|
||||
if no argument was given.";
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python method structure definition for Blender.Camera module: */
|
||||
/*****************************************************************************/
|
||||
struct PyMethodDef M_Camera_methods[] = {
|
||||
{"New",(PyCFunction)M_Camera_New, METH_VARARGS|METH_KEYWORDS,
|
||||
M_Camera_New_doc},
|
||||
{"Get", M_Camera_Get, METH_VARARGS, M_Camera_Get_doc},
|
||||
{"get", M_Camera_Get, METH_VARARGS, M_Camera_Get_doc},
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python BPy_Camera methods declarations: */
|
||||
/*****************************************************************************/
|
||||
static PyObject *Camera_getIpo(BPy_Camera *self);
|
||||
static PyObject *Camera_getName(BPy_Camera *self);
|
||||
static PyObject *Camera_getType(BPy_Camera *self);
|
||||
static PyObject *Camera_getMode(BPy_Camera *self);
|
||||
static PyObject *Camera_getLens(BPy_Camera *self);
|
||||
static PyObject *Camera_getClipStart(BPy_Camera *self);
|
||||
static PyObject *Camera_getClipEnd(BPy_Camera *self);
|
||||
static PyObject *Camera_getDrawSize(BPy_Camera *self);
|
||||
static PyObject *Camera_setIpo(BPy_Camera *self, PyObject *args);
|
||||
static PyObject *Camera_clearIpo(BPy_Camera *self);
|
||||
static PyObject *Camera_setName(BPy_Camera *self, PyObject *args);
|
||||
static PyObject *Camera_setType(BPy_Camera *self, PyObject *args);
|
||||
static PyObject *Camera_setIntType(BPy_Camera *self, PyObject *args);
|
||||
static PyObject *Camera_setMode(BPy_Camera *self, PyObject *args);
|
||||
static PyObject *Camera_setIntMode(BPy_Camera *self, PyObject *args);
|
||||
static PyObject *Camera_setLens(BPy_Camera *self, PyObject *args);
|
||||
static PyObject *Camera_setClipStart(BPy_Camera *self, PyObject *args);
|
||||
static PyObject *Camera_setClipEnd(BPy_Camera *self, PyObject *args);
|
||||
static PyObject *Camera_setDrawSize(BPy_Camera *self, PyObject *args);
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python BPy_Camera methods table: */
|
||||
/*****************************************************************************/
|
||||
static PyMethodDef BPy_Camera_methods[] = {
|
||||
/* name, method, flags, doc */
|
||||
{"getIpo", (PyCFunction)Camera_getIpo, METH_NOARGS,
|
||||
"() - Return Camera Data Ipo"},
|
||||
{"getName", (PyCFunction)Camera_getName, METH_NOARGS,
|
||||
"() - Return Camera Data name"},
|
||||
{"getType", (PyCFunction)Camera_getType, METH_NOARGS,
|
||||
"() - Return Camera type - 'persp':0, 'ortho':1"},
|
||||
{"getMode", (PyCFunction)Camera_getMode, METH_NOARGS,
|
||||
"() - Return Camera mode flags (or'ed value) -\n"
|
||||
" 'showLimits':1, 'showMist':2"},
|
||||
{"getLens", (PyCFunction)Camera_getLens, METH_NOARGS,
|
||||
"() - Return Camera lens value"},
|
||||
{"getClipStart", (PyCFunction)Camera_getClipStart, METH_NOARGS,
|
||||
"() - Return Camera clip start value"},
|
||||
{"getClipEnd", (PyCFunction)Camera_getClipEnd, METH_NOARGS,
|
||||
"() - Return Camera clip end value"},
|
||||
{"getDrawSize", (PyCFunction)Camera_getDrawSize, METH_NOARGS,
|
||||
"() - Return Camera draw size value"},
|
||||
{"setIpo", (PyCFunction)Camera_setIpo, METH_VARARGS,
|
||||
"(Blender Ipo) - Set Camera Ipo"},
|
||||
{"clearIpo", (PyCFunction)Camera_clearIpo, METH_NOARGS,
|
||||
"() - Unlink Ipo from this Camera."},
|
||||
{"setName", (PyCFunction)Camera_setName, METH_VARARGS,
|
||||
"(s) - Set Camera Data name"},
|
||||
{"setType", (PyCFunction)Camera_setType, METH_VARARGS,
|
||||
"(s) - Set Camera type, which can be 'persp' or 'ortho'"},
|
||||
{"setMode", (PyCFunction)Camera_setMode, METH_VARARGS,
|
||||
"(<s<,s>>) - Set Camera mode flag(s): 'showLimits' and 'showMist'"},
|
||||
{"setLens", (PyCFunction)Camera_setLens, METH_VARARGS,
|
||||
"(f) - Set Camera lens value"},
|
||||
{"setClipStart", (PyCFunction)Camera_setClipStart, METH_VARARGS,
|
||||
"(f) - Set Camera clip start value"},
|
||||
{"setClipEnd", (PyCFunction)Camera_setClipEnd, METH_VARARGS,
|
||||
"(f) - Set Camera clip end value"},
|
||||
{"setDrawSize", (PyCFunction)Camera_setDrawSize, METH_VARARGS,
|
||||
"(f) - Set Camera draw size value"},
|
||||
{0}
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python Camera_Type callback function prototypes: */
|
||||
/*****************************************************************************/
|
||||
static void Camera_dealloc (BPy_Camera *self);
|
||||
static int Camera_setAttr (BPy_Camera *self, char *name, PyObject *v);
|
||||
static int Camera_compare (BPy_Camera *a, BPy_Camera *b);
|
||||
static PyObject *Camera_getAttr (BPy_Camera *self, char *name);
|
||||
static PyObject *Camera_repr (BPy_Camera *self);
|
||||
|
||||
|
||||
#endif /* EXPP_CAMERA_H */
|
||||
|
Loading…
Reference in New Issue
Block a user