more housekeeping. move static declarations and definititions out of .h files.
tidy up initializers and c++ style comments.
This commit is contained in:
@@ -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;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
armature_iter = armature_iter->id.next;
|
||||
if (name)
|
||||
{ /* (name) - Search armature by name */
|
||||
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;
|
||||
}
|
||||
|
||||
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"));
|
||||
|
||||
PyList_SET_ITEM (armlist, index, pyobj);
|
||||
if (!pyobj)
|
||||
return (PythonReturnErrorObject (PyExc_MemoryError,
|
||||
"couldn't create PyString"));
|
||||
|
||||
armature_iter = armature_iter->id.next;
|
||||
index++;
|
||||
}
|
||||
PyList_SET_ITEM (armlist, index, pyobj);
|
||||
|
||||
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"));
|
||||
|
||||
PyOS_snprintf(buf, sizeof(buf), "%s", name);
|
||||
"expected string argument"));
|
||||
|
||||
rename_id(&self->armature->id, buf);
|
||||
PyOS_snprintf (buf, sizeof (buf), "%s", name);
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
rename_id (&self->armature->id, buf);
|
||||
|
||||
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 *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);
|
||||
|
||||
/* ... member with the given name was found */
|
||||
return (EXPP_ReturnIntError (PyExc_KeyError,
|
||||
"attribute not found"));
|
||||
}
|
||||
error = Armature_setBones (self, valtuple); */
|
||||
else
|
||||
{ /* Error */
|
||||
Py_DECREF (valtuple);
|
||||
|
||||
Py_DECREF(valtuple);
|
||||
|
||||
if (error != Py_None) return -1;
|
||||
/* ... member with the given name was found */
|
||||
return (EXPP_ReturnIntError (PyExc_KeyError, "attribute not found"));
|
||||
}
|
||||
|
||||
Py_DECREF(Py_None); /* was incref'ed by the called Armature_set* function */
|
||||
return 0; /* normal exit */
|
||||
Py_DECREF (valtuple);
|
||||
|
||||
if (error != Py_None)
|
||||
return -1;
|
||||
|
||||
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 */
|
||||
|
||||
@@ -43,701 +43,767 @@
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python API function prototypes for the Bone module. */
|
||||
/* Python API function prototypes for the Bone module. */
|
||||
/*****************************************************************************/
|
||||
static PyObject *M_Bone_New(PyObject *self, PyObject *args, PyObject *keywords);
|
||||
static PyObject *M_Bone_New (PyObject * self, PyObject * args,
|
||||
PyObject * keywords);
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* The following string definitions are used for documentation strings. */
|
||||
/* In Python these will be written to the console when doing a */
|
||||
/* Blender.Armature.Bone.__doc__ */
|
||||
/* The following string definitions are used for documentation strings. */
|
||||
/* In Python these will be written to the console when doing a */
|
||||
/* Blender.Armature.Bone.__doc__ */
|
||||
/*****************************************************************************/
|
||||
char M_Bone_doc[] =
|
||||
"The Blender Bone module\n\n\
|
||||
char M_Bone_doc[] = "The Blender Bone module\n\n\
|
||||
This module provides control over **Bone Data** objects in Blender.\n\n\
|
||||
Example::\n\n\
|
||||
from Blender import Armature.Bone\n\
|
||||
l = Armature.Bone.New()\n";
|
||||
|
||||
char M_Bone_New_doc[] =
|
||||
"(name) - return a new Bone of name 'name'.";
|
||||
char M_Bone_New_doc[] = "(name) - return a new Bone of name 'name'.";
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python method structure definition for Blender.Armature.Bone module: */
|
||||
/*****************************************************************************/
|
||||
struct PyMethodDef M_Bone_methods[] = {
|
||||
{"New",(PyCFunction)M_Bone_New, METH_VARARGS|METH_KEYWORDS,M_Bone_New_doc},
|
||||
{NULL, NULL, 0, NULL}
|
||||
{"New", (PyCFunction) M_Bone_New, METH_VARARGS | METH_KEYWORDS,
|
||||
M_Bone_New_doc},
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python BPy_Bone methods declarations: */
|
||||
/*****************************************************************************/
|
||||
static PyObject *Bone_getName(BPy_Bone *self);
|
||||
static PyObject *Bone_getRoll(BPy_Bone *self);
|
||||
static PyObject *Bone_getHead(BPy_Bone *self);
|
||||
static PyObject *Bone_getTail(BPy_Bone *self);
|
||||
static PyObject *Bone_getLoc(BPy_Bone *self);
|
||||
static PyObject *Bone_getSize(BPy_Bone *self);
|
||||
static PyObject *Bone_getQuat(BPy_Bone *self);
|
||||
static PyObject *Bone_getParent(BPy_Bone *self);
|
||||
static PyObject *Bone_hasParent(BPy_Bone *self);
|
||||
static PyObject *Bone_getChildren(BPy_Bone *self);
|
||||
static PyObject *Bone_setName(BPy_Bone *self, PyObject *args);
|
||||
static PyObject *Bone_setRoll(BPy_Bone *self, PyObject *args);
|
||||
static PyObject *Bone_setHead(BPy_Bone *self, PyObject *args);
|
||||
static PyObject *Bone_setTail(BPy_Bone *self, PyObject *args);
|
||||
static PyObject *Bone_setLoc(BPy_Bone *self, PyObject *args);
|
||||
static PyObject *Bone_setSize(BPy_Bone *self, PyObject *args);
|
||||
static PyObject *Bone_setQuat(BPy_Bone *self, PyObject *args);
|
||||
//static PyObject *Bone_setParent(BPy_Bone *self, PyObject *args);
|
||||
//static PyObject *Bone_setChildren(BPy_Bone *self, PyObject *args);
|
||||
static PyObject *Bone_getName (BPy_Bone * self);
|
||||
static PyObject *Bone_getRoll (BPy_Bone * self);
|
||||
static PyObject *Bone_getHead (BPy_Bone * self);
|
||||
static PyObject *Bone_getTail (BPy_Bone * self);
|
||||
static PyObject *Bone_getLoc (BPy_Bone * self);
|
||||
static PyObject *Bone_getSize (BPy_Bone * self);
|
||||
static PyObject *Bone_getQuat (BPy_Bone * self);
|
||||
static PyObject *Bone_getParent (BPy_Bone * self);
|
||||
static PyObject *Bone_hasParent (BPy_Bone * self);
|
||||
static PyObject *Bone_getChildren (BPy_Bone * self);
|
||||
static PyObject *Bone_setName (BPy_Bone * self, PyObject * args);
|
||||
static PyObject *Bone_setRoll (BPy_Bone * self, PyObject * args);
|
||||
static PyObject *Bone_setHead (BPy_Bone * self, PyObject * args);
|
||||
static PyObject *Bone_setTail (BPy_Bone * self, PyObject * args);
|
||||
static PyObject *Bone_setLoc (BPy_Bone * self, PyObject * args);
|
||||
static PyObject *Bone_setSize (BPy_Bone * self, PyObject * args);
|
||||
static PyObject *Bone_setQuat (BPy_Bone * self, PyObject * args);
|
||||
/* static PyObject *Bone_setParent(BPy_Bone *self, PyObject *args); */
|
||||
/* static PyObject *Bone_setChildren(BPy_Bone *self, PyObject *args); */
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python BPy_Bone methods table: */
|
||||
/* Python BPy_Bone methods table: */
|
||||
/*****************************************************************************/
|
||||
static PyMethodDef BPy_Bone_methods[] = {
|
||||
/* name, method, flags, doc */
|
||||
{"getName", (PyCFunction)Bone_getName, METH_NOARGS, "() - return Bone name"},
|
||||
{"getRoll", (PyCFunction)Bone_getRoll, METH_NOARGS, "() - return Bone roll"},
|
||||
{"getHead", (PyCFunction)Bone_getHead, METH_NOARGS, "() - return Bone head"},
|
||||
{"getTail", (PyCFunction)Bone_getTail, METH_NOARGS, "() - return Bone tail"},
|
||||
{"getLoc", (PyCFunction)Bone_getLoc, METH_NOARGS, "() - return Bone loc"},
|
||||
{"getSize", (PyCFunction)Bone_getSize, METH_NOARGS, "() - return Bone size"},
|
||||
{"getQuat", (PyCFunction)Bone_getQuat, METH_NOARGS, "() - return Bone quat"},
|
||||
{"getParent", (PyCFunction)Bone_getParent, METH_NOARGS,
|
||||
"() - return the parent bone of this one if it exists."
|
||||
" None if not found. You can check this condition with the "
|
||||
"hasParent() method."},
|
||||
{"hasParent", (PyCFunction)Bone_hasParent, METH_NOARGS,
|
||||
"() - return true if bone has a parent"},
|
||||
{"getChildren", (PyCFunction)Bone_getChildren, METH_NOARGS,
|
||||
"() - return Bone children list"},
|
||||
{"setName", (PyCFunction)Bone_setName, METH_VARARGS, "(str) - rename Bone"},
|
||||
{"setRoll", (PyCFunction)Bone_setRoll, METH_VARARGS,
|
||||
"(float) - set Bone roll"},
|
||||
{"setHead", (PyCFunction)Bone_setHead, METH_VARARGS,
|
||||
"(float,float,float) - set Bone head pos"},
|
||||
{"setTail", (PyCFunction)Bone_setTail, METH_VARARGS,
|
||||
"(float,float,float) - set Bone tail pos"},
|
||||
{"setLoc", (PyCFunction)Bone_setLoc, METH_VARARGS,
|
||||
"(float,float,float) - set Bone loc"},
|
||||
{"setSize", (PyCFunction)Bone_setSize, METH_VARARGS,
|
||||
"(float,float,float) - set Bone size"},
|
||||
{"setQuat", (PyCFunction)Bone_setQuat, METH_VARARGS,
|
||||
"(float,float,float,float) - set Bone quat"},
|
||||
/* {"setParent", (PyCFunction)Bone_setParent, METH_NOARGS, "() - set the Bone parent of this one."},
|
||||
{"setChildren", (PyCFunction)Bone_setChildren, METH_NOARGS, "() - replace the children list of the bone."},*/
|
||||
{0}
|
||||
/* name, method, flags, doc */
|
||||
{"getName", (PyCFunction) Bone_getName, METH_NOARGS,
|
||||
"() - return Bone name"},
|
||||
{"getRoll", (PyCFunction) Bone_getRoll, METH_NOARGS,
|
||||
"() - return Bone roll"},
|
||||
{"getHead", (PyCFunction) Bone_getHead, METH_NOARGS,
|
||||
"() - return Bone head"},
|
||||
{"getTail", (PyCFunction) Bone_getTail, METH_NOARGS,
|
||||
"() - return Bone tail"},
|
||||
{"getLoc", (PyCFunction) Bone_getLoc, METH_NOARGS, "() - return Bone loc"},
|
||||
{"getSize", (PyCFunction) Bone_getSize, METH_NOARGS,
|
||||
"() - return Bone size"},
|
||||
{"getQuat", (PyCFunction) Bone_getQuat, METH_NOARGS,
|
||||
"() - return Bone quat"},
|
||||
{"getParent", (PyCFunction) Bone_getParent, METH_NOARGS,
|
||||
"() - return the parent bone of this one if it exists."
|
||||
" None if not found. You can check this condition with the "
|
||||
"hasParent() method."},
|
||||
{"hasParent", (PyCFunction) Bone_hasParent, METH_NOARGS,
|
||||
"() - return true if bone has a parent"},
|
||||
{"getChildren", (PyCFunction) Bone_getChildren, METH_NOARGS,
|
||||
"() - return Bone children list"},
|
||||
{"setName", (PyCFunction) Bone_setName, METH_VARARGS,
|
||||
"(str) - rename Bone"},
|
||||
{"setRoll", (PyCFunction) Bone_setRoll, METH_VARARGS,
|
||||
"(float) - set Bone roll"},
|
||||
{"setHead", (PyCFunction) Bone_setHead, METH_VARARGS,
|
||||
"(float,float,float) - set Bone head pos"},
|
||||
{"setTail", (PyCFunction) Bone_setTail, METH_VARARGS,
|
||||
"(float,float,float) - set Bone tail pos"},
|
||||
{"setLoc", (PyCFunction) Bone_setLoc, METH_VARARGS,
|
||||
"(float,float,float) - set Bone loc"},
|
||||
{"setSize", (PyCFunction) Bone_setSize, METH_VARARGS,
|
||||
"(float,float,float) - set Bone size"},
|
||||
{"setQuat", (PyCFunction) Bone_setQuat, METH_VARARGS,
|
||||
"(float,float,float,float) - set Bone quat"},
|
||||
#if 0
|
||||
{"setParent", (PyCFunction) Bone_setParent, METH_NOARGS,
|
||||
"() - set the Bone parent of this one."},
|
||||
{"setChildren", (PyCFunction) Bone_setChildren, METH_NOARGS,
|
||||
"() - replace the children list of the bone."},
|
||||
#endif
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python TypeBone callback function prototypes: */
|
||||
/* Python TypeBone callback function prototypes: */
|
||||
/*****************************************************************************/
|
||||
static void Bone_dealloc (BPy_Bone *bone);
|
||||
static PyObject *Bone_getAttr (BPy_Bone *bone, char *name);
|
||||
static int Bone_setAttr (BPy_Bone *bone, char *name, PyObject *v);
|
||||
static int Bone_compare (BPy_Bone *a1, BPy_Bone *a2);
|
||||
static PyObject *Bone_repr (BPy_Bone *bone);
|
||||
static void Bone_dealloc (BPy_Bone * bone);
|
||||
static PyObject *Bone_getAttr (BPy_Bone * bone, char *name);
|
||||
static int Bone_setAttr (BPy_Bone * bone, char *name, PyObject * v);
|
||||
static int Bone_compare (BPy_Bone * a1, BPy_Bone * a2);
|
||||
static PyObject *Bone_repr (BPy_Bone * bone);
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python TypeBone structure definition: */
|
||||
/* Python TypeBone structure definition: */
|
||||
/*****************************************************************************/
|
||||
PyTypeObject Bone_Type =
|
||||
{
|
||||
PyObject_HEAD_INIT(NULL)
|
||||
0, /* ob_size */
|
||||
"Blender Bone", /* tp_name */
|
||||
sizeof (BPy_Bone), /* tp_basicsize */
|
||||
0, /* tp_itemsize */
|
||||
/* methods */
|
||||
(destructor)Bone_dealloc, /* tp_dealloc */
|
||||
0, /* tp_print */
|
||||
(getattrfunc)Bone_getAttr, /* tp_getattr */
|
||||
(setattrfunc)Bone_setAttr, /* tp_setattr */
|
||||
(cmpfunc)Bone_compare, /* tp_compare */
|
||||
(reprfunc)Bone_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_Bone_methods, /* tp_methods */
|
||||
0, /* tp_members */
|
||||
PyTypeObject Bone_Type = {
|
||||
PyObject_HEAD_INIT (NULL) 0, /* ob_size */
|
||||
"Blender Bone", /* tp_name */
|
||||
sizeof (BPy_Bone), /* tp_basicsize */
|
||||
0, /* tp_itemsize */
|
||||
/* methods */
|
||||
(destructor) Bone_dealloc, /* tp_dealloc */
|
||||
0, /* tp_print */
|
||||
(getattrfunc) Bone_getAttr, /* tp_getattr */
|
||||
(setattrfunc) Bone_setAttr, /* tp_setattr */
|
||||
(cmpfunc) Bone_compare, /* tp_compare */
|
||||
(reprfunc) Bone_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_Bone_methods, /* tp_methods */
|
||||
0, /* tp_members */
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Function: M_Bone_New */
|
||||
/* Python equivalent: Blender.Armature.Bone.New */
|
||||
/* Function: M_Bone_New */
|
||||
/* Python equivalent: Blender.Armature.Bone.New */
|
||||
/*****************************************************************************/
|
||||
static PyObject *M_Bone_New(PyObject *self, PyObject *args, PyObject *keywords)
|
||||
static PyObject *
|
||||
M_Bone_New (PyObject * self, PyObject * args, PyObject * keywords)
|
||||
{
|
||||
char *name_str = "BoneName";
|
||||
BPy_Bone *py_bone = NULL; /* for Bone Data object wrapper in Python */
|
||||
Bone *bl_bone = NULL; /* for actual Bone Data we create in Blender */
|
||||
char *name_str = "BoneName";
|
||||
BPy_Bone *py_bone = NULL; /* for Bone Data object wrapper in Python */
|
||||
Bone *bl_bone = NULL; /* for actual Bone Data we create in Blender */
|
||||
|
||||
if (!PyArg_ParseTuple(args, "|s", &name_str))
|
||||
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
|
||||
"expected string or empty argument"));
|
||||
if (!PyArg_ParseTuple (args, "|s", &name_str))
|
||||
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
|
||||
"expected string or empty argument"));
|
||||
|
||||
// Create the C structure for the newq bone
|
||||
bl_bone = (Bone*)malloc(sizeof(Bone));
|
||||
strncpy(bl_bone->name,name_str,sizeof(bl_bone->name));
|
||||
|
||||
if (bl_bone) /* now create the wrapper obj in Python */
|
||||
py_bone = (BPy_Bone *)PyObject_NEW(BPy_Bone, &Bone_Type);
|
||||
else
|
||||
return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
|
||||
"couldn't create Bone Data in Blender"));
|
||||
/* Create the C structure for the newq bone */
|
||||
bl_bone = (Bone *) malloc (sizeof (Bone));
|
||||
strncpy (bl_bone->name, name_str, sizeof (bl_bone->name));
|
||||
|
||||
if (py_bone == NULL)
|
||||
return (EXPP_ReturnPyObjError (PyExc_MemoryError,
|
||||
"couldn't create Bone Data object"));
|
||||
if (bl_bone) /* now create the wrapper obj in Python */
|
||||
py_bone = (BPy_Bone *) PyObject_NEW (BPy_Bone, &Bone_Type);
|
||||
else
|
||||
return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
|
||||
"couldn't create Bone Data in Blender"));
|
||||
|
||||
py_bone->bone = bl_bone; /* link Python bone wrapper with Blender Bone */
|
||||
if (py_bone == NULL)
|
||||
return (EXPP_ReturnPyObjError (PyExc_MemoryError,
|
||||
"couldn't create Bone Data object"));
|
||||
|
||||
if (strcmp(name_str, "BoneData") == 0)
|
||||
return (PyObject *)py_bone;
|
||||
else { /* user gave us a name for the bone, use it */
|
||||
// TODO: check that name is not already in use?
|
||||
PyOS_snprintf(bl_bone->name, sizeof(bl_bone->name), "%s", name_str);
|
||||
}
|
||||
py_bone->bone = bl_bone; /* link Python bone wrapper with Blender Bone */
|
||||
|
||||
return (PyObject *)py_bone;
|
||||
if (strcmp (name_str, "BoneData") == 0)
|
||||
return (PyObject *) py_bone;
|
||||
else
|
||||
{ /* user gave us a name for the bone, use it */
|
||||
/* TODO: check that name is not already in use? */
|
||||
PyOS_snprintf (bl_bone->name, sizeof (bl_bone->name), "%s", name_str);
|
||||
}
|
||||
|
||||
return (PyObject *) py_bone;
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Function: Bone_Init */
|
||||
/* Function: Bone_Init */
|
||||
/*****************************************************************************/
|
||||
PyObject *Bone_Init (void)
|
||||
PyObject *
|
||||
Bone_Init (void)
|
||||
{
|
||||
PyObject *submodule;
|
||||
PyObject *submodule;
|
||||
|
||||
Bone_Type.ob_type = &PyType_Type;
|
||||
Bone_Type.ob_type = &PyType_Type;
|
||||
|
||||
submodule = Py_InitModule3("Blender.Armature.Bone",
|
||||
M_Bone_methods, M_Bone_doc);
|
||||
submodule = Py_InitModule3 ("Blender.Armature.Bone",
|
||||
M_Bone_methods, M_Bone_doc);
|
||||
|
||||
return (submodule);
|
||||
return (submodule);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python BPy_Bone methods: */
|
||||
/* Python BPy_Bone methods: */
|
||||
/*****************************************************************************/
|
||||
static PyObject *Bone_getName(BPy_Bone *self)
|
||||
static PyObject *
|
||||
Bone_getName (BPy_Bone * self)
|
||||
{
|
||||
PyObject *attr=NULL;
|
||||
|
||||
if (!self->bone) (EXPP_ReturnPyObjError (PyExc_RuntimeError,
|
||||
"couldn't get attribute from a NULL bone"));
|
||||
|
||||
attr = PyString_FromString(self->bone->name);
|
||||
PyObject *attr = NULL;
|
||||
|
||||
if (attr) return attr;
|
||||
if (!self->bone)
|
||||
(EXPP_ReturnPyObjError (PyExc_RuntimeError,
|
||||
"couldn't get attribute from a NULL bone"));
|
||||
|
||||
return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
|
||||
"couldn't get Bone.name attribute"));
|
||||
attr = PyString_FromString (self->bone->name);
|
||||
|
||||
if (attr)
|
||||
return attr;
|
||||
|
||||
return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
|
||||
"couldn't get Bone.name attribute"));
|
||||
}
|
||||
|
||||
|
||||
static PyObject *Bone_getRoll(BPy_Bone *self)
|
||||
static PyObject *
|
||||
Bone_getRoll (BPy_Bone * self)
|
||||
{
|
||||
PyObject *attr=NULL;
|
||||
|
||||
if (!self->bone) (EXPP_ReturnPyObjError (PyExc_RuntimeError,
|
||||
"couldn't get attribute from a NULL bone"));
|
||||
|
||||
attr = Py_BuildValue("f", self->bone->roll);
|
||||
PyObject *attr = NULL;
|
||||
|
||||
if (attr) return attr;
|
||||
if (!self->bone)
|
||||
(EXPP_ReturnPyObjError (PyExc_RuntimeError,
|
||||
"couldn't get attribute from a NULL bone"));
|
||||
|
||||
return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
|
||||
"couldn't get Bone.roll attribute"));
|
||||
attr = Py_BuildValue ("f", self->bone->roll);
|
||||
|
||||
if (attr)
|
||||
return attr;
|
||||
|
||||
return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
|
||||
"couldn't get Bone.roll attribute"));
|
||||
}
|
||||
|
||||
|
||||
static PyObject *Bone_getHead(BPy_Bone *self)
|
||||
static PyObject *
|
||||
Bone_getHead (BPy_Bone * self)
|
||||
{
|
||||
PyObject *attr=NULL;
|
||||
|
||||
if (!self->bone) (EXPP_ReturnPyObjError (PyExc_RuntimeError,
|
||||
"couldn't get attribute from a NULL bone"));
|
||||
|
||||
attr = Py_BuildValue("[fff]", self->bone->head[0],self->bone->head[1],
|
||||
self->bone->head[2]);
|
||||
PyObject *attr = NULL;
|
||||
|
||||
if (attr) return attr;
|
||||
if (!self->bone)
|
||||
(EXPP_ReturnPyObjError (PyExc_RuntimeError,
|
||||
"couldn't get attribute from a NULL bone"));
|
||||
|
||||
return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
|
||||
"couldn't get Bone.head attribute"));
|
||||
attr = Py_BuildValue ("[fff]", self->bone->head[0], self->bone->head[1],
|
||||
self->bone->head[2]);
|
||||
|
||||
if (attr)
|
||||
return attr;
|
||||
|
||||
return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
|
||||
"couldn't get Bone.head attribute"));
|
||||
}
|
||||
|
||||
|
||||
static PyObject *Bone_getTail(BPy_Bone *self)
|
||||
static PyObject *
|
||||
Bone_getTail (BPy_Bone * self)
|
||||
{
|
||||
PyObject *attr=NULL;
|
||||
|
||||
if (!self->bone) (EXPP_ReturnPyObjError (PyExc_RuntimeError,
|
||||
"couldn't get attribute from a NULL bone"));
|
||||
|
||||
attr = Py_BuildValue("[fff]", self->bone->tail[0],self->bone->tail[1],
|
||||
self->bone->tail[2]);
|
||||
PyObject *attr = NULL;
|
||||
|
||||
if (attr) return attr;
|
||||
if (!self->bone)
|
||||
(EXPP_ReturnPyObjError (PyExc_RuntimeError,
|
||||
"couldn't get attribute from a NULL bone"));
|
||||
|
||||
return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
|
||||
"couldn't get Bone.tail attribute"));
|
||||
attr = Py_BuildValue ("[fff]", self->bone->tail[0], self->bone->tail[1],
|
||||
self->bone->tail[2]);
|
||||
|
||||
if (attr)
|
||||
return attr;
|
||||
|
||||
return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
|
||||
"couldn't get Bone.tail attribute"));
|
||||
}
|
||||
|
||||
|
||||
static PyObject *Bone_getLoc (BPy_Bone *self)
|
||||
static PyObject *
|
||||
Bone_getLoc (BPy_Bone * self)
|
||||
{
|
||||
PyObject *attr=NULL;
|
||||
|
||||
if (!self->bone) (EXPP_ReturnPyObjError (PyExc_RuntimeError,
|
||||
"couldn't get attribute from a NULL bone"));
|
||||
|
||||
attr = Py_BuildValue("[fff]", self->bone->loc[0],self->bone->loc[1],
|
||||
self->bone->loc[2]);
|
||||
PyObject *attr = NULL;
|
||||
|
||||
if (attr) return attr;
|
||||
if (!self->bone)
|
||||
(EXPP_ReturnPyObjError (PyExc_RuntimeError,
|
||||
"couldn't get attribute from a NULL bone"));
|
||||
|
||||
return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
|
||||
"couldn't get Bone.loc attribute"));
|
||||
attr = Py_BuildValue ("[fff]", self->bone->loc[0], self->bone->loc[1],
|
||||
self->bone->loc[2]);
|
||||
|
||||
if (attr)
|
||||
return attr;
|
||||
|
||||
return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
|
||||
"couldn't get Bone.loc attribute"));
|
||||
}
|
||||
|
||||
|
||||
static PyObject *Bone_getSize(BPy_Bone *self)
|
||||
static PyObject *
|
||||
Bone_getSize (BPy_Bone * self)
|
||||
{
|
||||
PyObject *attr=NULL;
|
||||
|
||||
if (!self->bone) (EXPP_ReturnPyObjError (PyExc_RuntimeError,
|
||||
"couldn't get attribute from a NULL bone"));
|
||||
|
||||
attr = Py_BuildValue("[fff]", self->bone->size[0],self->bone->size[1],
|
||||
self->bone->size[2]);
|
||||
PyObject *attr = NULL;
|
||||
|
||||
if (attr) return attr;
|
||||
if (!self->bone)
|
||||
(EXPP_ReturnPyObjError (PyExc_RuntimeError,
|
||||
"couldn't get attribute from a NULL bone"));
|
||||
|
||||
return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
|
||||
"couldn't get Bone.size attribute"));
|
||||
attr = Py_BuildValue ("[fff]", self->bone->size[0], self->bone->size[1],
|
||||
self->bone->size[2]);
|
||||
|
||||
if (attr)
|
||||
return attr;
|
||||
|
||||
return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
|
||||
"couldn't get Bone.size attribute"));
|
||||
}
|
||||
|
||||
|
||||
static PyObject *Bone_getQuat(BPy_Bone *self)
|
||||
static PyObject *
|
||||
Bone_getQuat (BPy_Bone * self)
|
||||
{
|
||||
PyObject *attr=NULL;
|
||||
|
||||
if (!self->bone) (EXPP_ReturnPyObjError (PyExc_RuntimeError,
|
||||
"couldn't get attribute from a NULL bone"));
|
||||
|
||||
attr = Py_BuildValue("[ffff]", self->bone->quat[0],self->bone->quat[1],
|
||||
self->bone->quat[2],self->bone->quat[3]);
|
||||
PyObject *attr = NULL;
|
||||
|
||||
if (attr) return attr;
|
||||
if (!self->bone)
|
||||
(EXPP_ReturnPyObjError (PyExc_RuntimeError,
|
||||
"couldn't get attribute from a NULL bone"));
|
||||
|
||||
return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
|
||||
"couldn't get Bone.tail attribute"));
|
||||
attr = Py_BuildValue ("[ffff]", self->bone->quat[0], self->bone->quat[1],
|
||||
self->bone->quat[2], self->bone->quat[3]);
|
||||
|
||||
if (attr)
|
||||
return attr;
|
||||
|
||||
return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
|
||||
"couldn't get Bone.tail attribute"));
|
||||
}
|
||||
|
||||
|
||||
static PyObject *Bone_hasParent(BPy_Bone *self)
|
||||
static PyObject *
|
||||
Bone_hasParent (BPy_Bone * self)
|
||||
{
|
||||
|
||||
if (!self->bone) (EXPP_ReturnPyObjError (PyExc_RuntimeError,
|
||||
"couldn't get attribute from a NULL bone"));
|
||||
|
||||
/*
|
||||
return Bone_CreatePyObject(self->bone->parent);
|
||||
*/
|
||||
if (self->bone->parent)
|
||||
{
|
||||
Py_INCREF(Py_True);
|
||||
return Py_True;
|
||||
}
|
||||
else
|
||||
{
|
||||
Py_INCREF(Py_False);
|
||||
return Py_False;
|
||||
}
|
||||
|
||||
if (!self->bone)
|
||||
(EXPP_ReturnPyObjError (PyExc_RuntimeError,
|
||||
"couldn't get attribute from a NULL bone"));
|
||||
|
||||
/*
|
||||
return Bone_CreatePyObject(self->bone->parent);
|
||||
*/
|
||||
if (self->bone->parent)
|
||||
{
|
||||
Py_INCREF (Py_True);
|
||||
return Py_True;
|
||||
}
|
||||
else
|
||||
{
|
||||
Py_INCREF (Py_False);
|
||||
return Py_False;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
static PyObject *Bone_getParent(BPy_Bone *self)
|
||||
static PyObject *
|
||||
Bone_getParent (BPy_Bone * self)
|
||||
{
|
||||
|
||||
if (!self->bone) (EXPP_ReturnPyObjError (PyExc_RuntimeError,
|
||||
"couldn't get attribute from a NULL bone"));
|
||||
|
||||
if (self->bone->parent) return Bone_CreatePyObject(self->bone->parent);
|
||||
else /*(EXPP_ReturnPyObjError (PyExc_RuntimeError,
|
||||
"couldn't get parent bone, because bone hasn't got a parent."));*/
|
||||
{
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
if (!self->bone)
|
||||
(EXPP_ReturnPyObjError (PyExc_RuntimeError,
|
||||
"couldn't get attribute from a NULL bone"));
|
||||
|
||||
if (self->bone->parent)
|
||||
return Bone_CreatePyObject (self->bone->parent);
|
||||
else /*(EXPP_ReturnPyObjError (PyExc_RuntimeError,
|
||||
"couldn't get parent bone, because bone hasn't got a parent.")); */
|
||||
{
|
||||
Py_INCREF (Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
static PyObject *Bone_getChildren(BPy_Bone *self)
|
||||
static PyObject *
|
||||
Bone_getChildren (BPy_Bone * self)
|
||||
{
|
||||
int totbones = 0;
|
||||
Bone* current = NULL;
|
||||
PyObject *listbones = NULL;
|
||||
int i;
|
||||
|
||||
if (!self->bone) (EXPP_ReturnPyObjError (PyExc_RuntimeError,
|
||||
"couldn't get attribute from a NULL bone"));
|
||||
|
||||
/* Count the number of bones to create the list */
|
||||
current = self->bone->childbase.first;
|
||||
for (;current; current=current->next) totbones++;
|
||||
int totbones = 0;
|
||||
Bone *current = NULL;
|
||||
PyObject *listbones = NULL;
|
||||
int i;
|
||||
|
||||
/* Create a list with a bone wrapper for each bone */
|
||||
current = self->bone->childbase.first;
|
||||
listbones = PyList_New(totbones);
|
||||
for (i=0; i<totbones; i++) {
|
||||
assert(current);
|
||||
PyList_SetItem(listbones, i, Bone_CreatePyObject(current));
|
||||
current = current->next;
|
||||
}
|
||||
if (!self->bone)
|
||||
(EXPP_ReturnPyObjError (PyExc_RuntimeError,
|
||||
"couldn't get attribute from a NULL bone"));
|
||||
|
||||
return listbones;
|
||||
/* Count the number of bones to create the list */
|
||||
current = self->bone->childbase.first;
|
||||
for (; current; current = current->next)
|
||||
totbones++;
|
||||
|
||||
/* Create a list with a bone wrapper for each bone */
|
||||
current = self->bone->childbase.first;
|
||||
listbones = PyList_New (totbones);
|
||||
for (i = 0; i < totbones; i++)
|
||||
{
|
||||
assert (current);
|
||||
PyList_SetItem (listbones, i, Bone_CreatePyObject (current));
|
||||
current = current->next;
|
||||
}
|
||||
|
||||
return listbones;
|
||||
}
|
||||
|
||||
|
||||
static PyObject *Bone_setName(BPy_Bone *self, PyObject *args)
|
||||
static PyObject *
|
||||
Bone_setName (BPy_Bone * self, PyObject * args)
|
||||
{
|
||||
char *name;
|
||||
char *name;
|
||||
|
||||
if (!self->bone) (EXPP_ReturnPyObjError (PyExc_RuntimeError,
|
||||
"couldn't get attribute from a NULL bone"));
|
||||
|
||||
if (!PyArg_ParseTuple(args, "s", &name))
|
||||
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
|
||||
"expected string argument"));
|
||||
|
||||
PyOS_snprintf(self->bone->name, sizeof(self->bone->name), "%s", name);
|
||||
if (!self->bone)
|
||||
(EXPP_ReturnPyObjError (PyExc_RuntimeError,
|
||||
"couldn't get attribute from a NULL bone"));
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
if (!PyArg_ParseTuple (args, "s", &name))
|
||||
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
|
||||
"expected string argument"));
|
||||
|
||||
PyOS_snprintf (self->bone->name, sizeof (self->bone->name), "%s", name);
|
||||
|
||||
Py_INCREF (Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
|
||||
PyObject *Bone_setRoll(BPy_Bone *self, PyObject *args)
|
||||
PyObject *
|
||||
Bone_setRoll (BPy_Bone * self, PyObject * args)
|
||||
{
|
||||
float roll;
|
||||
float roll;
|
||||
|
||||
if (!self->bone) (EXPP_ReturnPyObjError (PyExc_RuntimeError,
|
||||
"couldn't get attribute from a NULL bone"));
|
||||
|
||||
if (!PyArg_ParseTuple(args, "f", &roll))
|
||||
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
|
||||
"expected float argument"));
|
||||
|
||||
self->bone->roll = roll;
|
||||
if (!self->bone)
|
||||
(EXPP_ReturnPyObjError (PyExc_RuntimeError,
|
||||
"couldn't get attribute from a NULL bone"));
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
if (!PyArg_ParseTuple (args, "f", &roll))
|
||||
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
|
||||
"expected float argument"));
|
||||
|
||||
self->bone->roll = roll;
|
||||
|
||||
Py_INCREF (Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
|
||||
static PyObject *Bone_setHead(BPy_Bone *self, PyObject *args)
|
||||
static PyObject *
|
||||
Bone_setHead (BPy_Bone * self, PyObject * args)
|
||||
{
|
||||
float f1,f2,f3;
|
||||
int status;
|
||||
float f1, f2, f3;
|
||||
int status;
|
||||
|
||||
if (!self->bone) (EXPP_ReturnPyObjError (PyExc_RuntimeError,
|
||||
"couldn't get attribute from a NULL bone"));
|
||||
if (!self->bone)
|
||||
(EXPP_ReturnPyObjError (PyExc_RuntimeError,
|
||||
"couldn't get attribute from a NULL bone"));
|
||||
|
||||
if (PyObject_Length (args) == 3)
|
||||
status = PyArg_ParseTuple (args, "fff", &f1, &f2, &f3);
|
||||
else
|
||||
status = PyArg_ParseTuple (args, "(fff)", &f1, &f2, &f3);
|
||||
if (PyObject_Length (args) == 3)
|
||||
status = PyArg_ParseTuple (args, "fff", &f1, &f2, &f3);
|
||||
else
|
||||
status = PyArg_ParseTuple (args, "(fff)", &f1, &f2, &f3);
|
||||
|
||||
if (!status)
|
||||
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
|
||||
"expected 3 (or a list of 3) float arguments"));
|
||||
if (!status)
|
||||
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
|
||||
"expected 3 (or a list of 3) float arguments"));
|
||||
|
||||
self->bone->head[0] = f1;
|
||||
self->bone->head[1] = f2;
|
||||
self->bone->head[2] = f3;
|
||||
self->bone->head[0] = f1;
|
||||
self->bone->head[1] = f2;
|
||||
self->bone->head[2] = f3;
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
Py_INCREF (Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
|
||||
static PyObject *Bone_setTail(BPy_Bone *self, PyObject *args)
|
||||
static PyObject *
|
||||
Bone_setTail (BPy_Bone * self, PyObject * args)
|
||||
{
|
||||
float f1,f2,f3;
|
||||
int status;
|
||||
float f1, f2, f3;
|
||||
int status;
|
||||
|
||||
if (!self->bone) (EXPP_ReturnPyObjError (PyExc_RuntimeError,
|
||||
"couldn't get attribute from a NULL bone"));
|
||||
if (!self->bone)
|
||||
(EXPP_ReturnPyObjError (PyExc_RuntimeError,
|
||||
"couldn't get attribute from a NULL bone"));
|
||||
|
||||
if (PyObject_Length (args) == 3)
|
||||
status = PyArg_ParseTuple (args, "fff", &f1, &f2, &f3);
|
||||
else
|
||||
status = PyArg_ParseTuple (args, "(fff)", &f1, &f2, &f3);
|
||||
if (PyObject_Length (args) == 3)
|
||||
status = PyArg_ParseTuple (args, "fff", &f1, &f2, &f3);
|
||||
else
|
||||
status = PyArg_ParseTuple (args, "(fff)", &f1, &f2, &f3);
|
||||
|
||||
if (!status)
|
||||
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
|
||||
"expected 3 (or a list of 3) float arguments"));
|
||||
if (!status)
|
||||
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
|
||||
"expected 3 (or a list of 3) float arguments"));
|
||||
|
||||
self->bone->tail[0] = f1;
|
||||
self->bone->tail[1] = f2;
|
||||
self->bone->tail[2] = f3;
|
||||
self->bone->tail[0] = f1;
|
||||
self->bone->tail[1] = f2;
|
||||
self->bone->tail[2] = f3;
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
Py_INCREF (Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
|
||||
static PyObject *Bone_setLoc(BPy_Bone *self, PyObject *args)
|
||||
static PyObject *
|
||||
Bone_setLoc (BPy_Bone * self, PyObject * args)
|
||||
{
|
||||
float f1,f2,f3;
|
||||
int status;
|
||||
float f1, f2, f3;
|
||||
int status;
|
||||
|
||||
if (!self->bone) (EXPP_ReturnPyObjError (PyExc_RuntimeError,
|
||||
"couldn't get attribute from a NULL bone"));
|
||||
if (!self->bone)
|
||||
(EXPP_ReturnPyObjError (PyExc_RuntimeError,
|
||||
"couldn't get attribute from a NULL bone"));
|
||||
|
||||
if (PyObject_Length (args) == 3)
|
||||
status = PyArg_ParseTuple (args, "fff", &f1, &f2, &f3);
|
||||
else
|
||||
status = PyArg_ParseTuple (args, "(fff)", &f1, &f2, &f3);
|
||||
if (PyObject_Length (args) == 3)
|
||||
status = PyArg_ParseTuple (args, "fff", &f1, &f2, &f3);
|
||||
else
|
||||
status = PyArg_ParseTuple (args, "(fff)", &f1, &f2, &f3);
|
||||
|
||||
if (!status)
|
||||
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
|
||||
"expected 3 (or a list of 3) float arguments"));
|
||||
if (!status)
|
||||
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
|
||||
"expected 3 (or a list of 3) float arguments"));
|
||||
|
||||
self->bone->loc[0] = f1;
|
||||
self->bone->loc[1] = f2;
|
||||
self->bone->loc[2] = f3;
|
||||
self->bone->loc[0] = f1;
|
||||
self->bone->loc[1] = f2;
|
||||
self->bone->loc[2] = f3;
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
Py_INCREF (Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
|
||||
static PyObject *Bone_setSize(BPy_Bone *self, PyObject *args)
|
||||
static PyObject *
|
||||
Bone_setSize (BPy_Bone * self, PyObject * args)
|
||||
{
|
||||
float f1,f2,f3;
|
||||
int status;
|
||||
float f1, f2, f3;
|
||||
int status;
|
||||
|
||||
if (!self->bone) (EXPP_ReturnPyObjError (PyExc_RuntimeError,
|
||||
"couldn't get attribute from a NULL bone"));
|
||||
if (!self->bone)
|
||||
(EXPP_ReturnPyObjError (PyExc_RuntimeError,
|
||||
"couldn't get attribute from a NULL bone"));
|
||||
|
||||
if (PyObject_Length (args) == 3)
|
||||
status = PyArg_ParseTuple (args, "fff", &f1, &f2, &f3);
|
||||
else
|
||||
status = PyArg_ParseTuple (args, "(fff)", &f1, &f2, &f3);
|
||||
if (PyObject_Length (args) == 3)
|
||||
status = PyArg_ParseTuple (args, "fff", &f1, &f2, &f3);
|
||||
else
|
||||
status = PyArg_ParseTuple (args, "(fff)", &f1, &f2, &f3);
|
||||
|
||||
if (!status)
|
||||
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
|
||||
"expected 3 (or a list of 3) float arguments"));
|
||||
if (!status)
|
||||
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
|
||||
"expected 3 (or a list of 3) float arguments"));
|
||||
|
||||
self->bone->size[0] = f1;
|
||||
self->bone->size[1] = f2;
|
||||
self->bone->size[2] = f3;
|
||||
self->bone->size[0] = f1;
|
||||
self->bone->size[1] = f2;
|
||||
self->bone->size[2] = f3;
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
Py_INCREF (Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
|
||||
static PyObject *Bone_setQuat(BPy_Bone *self, PyObject *args)
|
||||
static PyObject *
|
||||
Bone_setQuat (BPy_Bone * self, PyObject * args)
|
||||
{
|
||||
float f1,f2,f3,f4;
|
||||
int status;
|
||||
float f1, f2, f3, f4;
|
||||
int status;
|
||||
|
||||
if (!self->bone) (EXPP_ReturnPyObjError (PyExc_RuntimeError,
|
||||
"couldn't get attribute from a NULL bone"));
|
||||
if (!self->bone)
|
||||
(EXPP_ReturnPyObjError (PyExc_RuntimeError,
|
||||
"couldn't get attribute from a NULL bone"));
|
||||
|
||||
if (PyObject_Length (args) == 4)
|
||||
status = PyArg_ParseTuple (args, "ffff", &f1, &f2, &f3, &f4);
|
||||
else
|
||||
status = PyArg_ParseTuple (args, "(ffff)", &f1, &f2, &f3, &f4);
|
||||
if (PyObject_Length (args) == 4)
|
||||
status = PyArg_ParseTuple (args, "ffff", &f1, &f2, &f3, &f4);
|
||||
else
|
||||
status = PyArg_ParseTuple (args, "(ffff)", &f1, &f2, &f3, &f4);
|
||||
|
||||
if (!status)
|
||||
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
|
||||
"expected 4 (or a list of 4) float arguments"));
|
||||
if (!status)
|
||||
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
|
||||
"expected 4 (or a list of 4) float arguments"));
|
||||
|
||||
self->bone->quat[0] = f1;
|
||||
self->bone->quat[1] = f2;
|
||||
self->bone->quat[2] = f3;
|
||||
self->bone->quat[3] = f4;
|
||||
self->bone->quat[0] = f1;
|
||||
self->bone->quat[1] = f2;
|
||||
self->bone->quat[2] = f3;
|
||||
self->bone->quat[3] = f4;
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
Py_INCREF (Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Function: Bone_dealloc */
|
||||
/* Description: This is a callback function for the BPy_Bone type. It is */
|
||||
/* the destructor function. */
|
||||
/* Function: Bone_dealloc */
|
||||
/* Description: This is a callback function for the BPy_Bone type. It is */
|
||||
/* the destructor function. */
|
||||
/*****************************************************************************/
|
||||
static void Bone_dealloc (BPy_Bone *self)
|
||||
static void
|
||||
Bone_dealloc (BPy_Bone * self)
|
||||
{
|
||||
PyObject_DEL (self);
|
||||
PyObject_DEL (self);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Function: Bone_getAttr */
|
||||
/* Description: This is a callback function for the BPy_Bone type. It is */
|
||||
/* the function that accesses BPy_Bone member variables and */
|
||||
/* methods. */
|
||||
/* Function: Bone_getAttr */
|
||||
/* Description: This is a callback function for the BPy_Bone type. It is */
|
||||
/* the function that accesses BPy_Bone member variables and */
|
||||
/* methods. */
|
||||
/*****************************************************************************/
|
||||
static PyObject* Bone_getAttr (BPy_Bone *self, char *name)
|
||||
static PyObject *
|
||||
Bone_getAttr (BPy_Bone * self, char *name)
|
||||
{
|
||||
PyObject *attr = Py_None;
|
||||
PyObject *attr = Py_None;
|
||||
|
||||
if (strcmp(name, "name") == 0)
|
||||
attr = Bone_getName(self);
|
||||
else if (strcmp(name, "roll") == 0)
|
||||
attr = Bone_getRoll(self);
|
||||
else if (strcmp(name, "head") == 0)
|
||||
attr = Bone_getHead(self);
|
||||
else if (strcmp(name, "tail") == 0)
|
||||
attr = Bone_getTail(self);
|
||||
else if (strcmp(name, "size") == 0)
|
||||
attr = Bone_getSize(self);
|
||||
else if (strcmp(name, "loc") == 0)
|
||||
attr = Bone_getLoc(self);
|
||||
else if (strcmp(name, "quat") == 0)
|
||||
attr = Bone_getQuat(self);
|
||||
else if (strcmp(name, "parent") == 0)
|
||||
// Skip the checks for Py_None as its a valid result to this call.
|
||||
return Bone_getParent(self);
|
||||
else if (strcmp(name, "children") == 0)
|
||||
attr = Bone_getChildren(self);
|
||||
else if (strcmp(name, "__members__") == 0) {
|
||||
/* 9 entries */
|
||||
attr = Py_BuildValue("[s,s,s,s,s,s,s,s,s]",
|
||||
"name","roll","head","tail","loc","size",
|
||||
"quat","parent","children");
|
||||
}
|
||||
if (strcmp (name, "name") == 0)
|
||||
attr = Bone_getName (self);
|
||||
else if (strcmp (name, "roll") == 0)
|
||||
attr = Bone_getRoll (self);
|
||||
else if (strcmp (name, "head") == 0)
|
||||
attr = Bone_getHead (self);
|
||||
else if (strcmp (name, "tail") == 0)
|
||||
attr = Bone_getTail (self);
|
||||
else if (strcmp (name, "size") == 0)
|
||||
attr = Bone_getSize (self);
|
||||
else if (strcmp (name, "loc") == 0)
|
||||
attr = Bone_getLoc (self);
|
||||
else if (strcmp (name, "quat") == 0)
|
||||
attr = Bone_getQuat (self);
|
||||
else if (strcmp (name, "parent") == 0)
|
||||
/* Skip the checks for Py_None as its a valid result to this call. */
|
||||
return Bone_getParent (self);
|
||||
else if (strcmp (name, "children") == 0)
|
||||
attr = Bone_getChildren (self);
|
||||
else if (strcmp (name, "__members__") == 0)
|
||||
{
|
||||
/* 9 entries */
|
||||
attr = Py_BuildValue ("[s,s,s,s,s,s,s,s,s]",
|
||||
"name", "roll", "head", "tail", "loc", "size",
|
||||
"quat", "parent", "children");
|
||||
}
|
||||
|
||||
if (!attr)
|
||||
return (EXPP_ReturnPyObjError (PyExc_MemoryError,
|
||||
"couldn't create PyObject"));
|
||||
if (!attr)
|
||||
return (EXPP_ReturnPyObjError (PyExc_MemoryError,
|
||||
"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_Bone_methods, (PyObject *)self, name);
|
||||
/* not an attribute, search the methods table */
|
||||
return Py_FindMethod (BPy_Bone_methods, (PyObject *) self, name);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Function: Bone_setAttr */
|
||||
/* Function: Bone_setAttr */
|
||||
/* Description: This is a callback function for the BPy_Bone type. It is the */
|
||||
/* function that changes Bone Data members values. If this */
|
||||
/* data is linked to a Blender Bone, it also gets updated. */
|
||||
/* function that changes Bone Data members values. If this */
|
||||
/* data is linked to a Blender Bone, it also gets updated. */
|
||||
/*****************************************************************************/
|
||||
static int Bone_setAttr (BPy_Bone *self, char *name, PyObject *value)
|
||||
static int
|
||||
Bone_setAttr (BPy_Bone * self, char *name, PyObject * value)
|
||||
{
|
||||
PyObject *valtuple;
|
||||
PyObject *error = NULL;
|
||||
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,
|
||||
"BoneSetAttr: couldn't create tuple");
|
||||
if (!valtuple)
|
||||
return EXPP_ReturnIntError (PyExc_MemoryError,
|
||||
"BoneSetAttr: couldn't create tuple");
|
||||
|
||||
if (strcmp (name, "name") == 0)
|
||||
error = Bone_setName (self, valtuple);
|
||||
else { /* Error */
|
||||
Py_DECREF(valtuple);
|
||||
|
||||
/* ... member with the given name was found */
|
||||
return (EXPP_ReturnIntError (PyExc_KeyError,
|
||||
"attribute not found"));
|
||||
}
|
||||
if (strcmp (name, "name") == 0)
|
||||
error = Bone_setName (self, valtuple);
|
||||
else
|
||||
{ /* Error */
|
||||
Py_DECREF (valtuple);
|
||||
|
||||
Py_DECREF(valtuple);
|
||||
|
||||
if (error != Py_None) return -1;
|
||||
/* ... member with the given name was found */
|
||||
return (EXPP_ReturnIntError (PyExc_KeyError, "attribute not found"));
|
||||
}
|
||||
|
||||
Py_DECREF(Py_None); /* was incref'ed by the called Bone_set* function */
|
||||
return 0; /* normal exit */
|
||||
Py_DECREF (valtuple);
|
||||
|
||||
if (error != Py_None)
|
||||
return -1;
|
||||
|
||||
Py_DECREF (Py_None); /* was incref'ed by the called Bone_set* function */
|
||||
return 0; /* normal exit */
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Function: Bone_repr */
|
||||
/* Description: This is a callback function for the BPy_Bone type. It */
|
||||
/* builds a meaninful string to represent bone objects. */
|
||||
/* Function: Bone_repr */
|
||||
/* Description: This is a callback function for the BPy_Bone type. It */
|
||||
/* builds a meaninful string to represent bone objects. */
|
||||
/*****************************************************************************/
|
||||
static PyObject *Bone_repr (BPy_Bone *self)
|
||||
static PyObject *
|
||||
Bone_repr (BPy_Bone * self)
|
||||
{
|
||||
if (self->bone)
|
||||
return PyString_FromFormat("[Bone \"%s\"]", self->bone->name);
|
||||
else return PyString_FromString("NULL");
|
||||
if (self->bone)
|
||||
return PyString_FromFormat ("[Bone \"%s\"]", self->bone->name);
|
||||
else
|
||||
return PyString_FromString ("NULL");
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/* Function: Bone_compare */
|
||||
/* Description: This is a callback function for the BPy_Bone type. It */
|
||||
/* compares the two bones: translate comparison to the */
|
||||
/* C pointers. */
|
||||
/* Function: Bone_compare */
|
||||
/* Description: This is a callback function for the BPy_Bone type. It */
|
||||
/* compares the two bones: translate comparison to the */
|
||||
/* C pointers. */
|
||||
/**************************************************************************/
|
||||
static int Bone_compare (BPy_Bone *a, BPy_Bone *b)
|
||||
static int
|
||||
Bone_compare (BPy_Bone * a, BPy_Bone * b)
|
||||
{
|
||||
Bone *pa = a->bone, *pb = b->bone;
|
||||
return (pa == pb) ? 0:-1;
|
||||
Bone *pa = a->bone, *pb = b->bone;
|
||||
return (pa == pb) ? 0 : -1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Function: Bone_CreatePyObject */
|
||||
/* Description: This function will create a new BlenBone from an existing */
|
||||
/* Bone structure. */
|
||||
/* Function: Bone_CreatePyObject */
|
||||
/* Description: This function will create a new BlenBone from an existing */
|
||||
/* Bone structure. */
|
||||
/*****************************************************************************/
|
||||
PyObject* Bone_CreatePyObject (struct Bone *obj)
|
||||
PyObject *
|
||||
Bone_CreatePyObject (struct Bone * obj)
|
||||
{
|
||||
BPy_Bone * blen_bone;
|
||||
BPy_Bone *blen_bone;
|
||||
|
||||
blen_bone = (BPy_Bone*)PyObject_NEW (BPy_Bone, &Bone_Type);
|
||||
blen_bone = (BPy_Bone *) PyObject_NEW (BPy_Bone, &Bone_Type);
|
||||
|
||||
if (blen_bone == NULL)
|
||||
{
|
||||
return (NULL);
|
||||
}
|
||||
blen_bone->bone = obj;
|
||||
return ((PyObject*)blen_bone);
|
||||
if (blen_bone == NULL)
|
||||
{
|
||||
return (NULL);
|
||||
}
|
||||
blen_bone->bone = obj;
|
||||
return ((PyObject *) blen_bone);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Function: Bone_CheckPyObject */
|
||||
/* Function: Bone_CheckPyObject */
|
||||
/* Description: This function returns true when the given PyObject is of the */
|
||||
/* type Bone. Otherwise it will return false. */
|
||||
/* type Bone. Otherwise it will return false. */
|
||||
/*****************************************************************************/
|
||||
int Bone_CheckPyObject (PyObject *py_obj)
|
||||
int
|
||||
Bone_CheckPyObject (PyObject * py_obj)
|
||||
{
|
||||
return (py_obj->ob_type == &Bone_Type);
|
||||
return (py_obj->ob_type == &Bone_Type);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Function: Bone_FromPyObject */
|
||||
/* Description: This function returns the Blender bone from the given */
|
||||
/* PyObject. */
|
||||
/* Function: Bone_FromPyObject */
|
||||
/* Description: This function returns the Blender bone from the given */
|
||||
/* PyObject. */
|
||||
/*****************************************************************************/
|
||||
struct Bone* Bone_FromPyObject (PyObject *py_obj)
|
||||
struct Bone *
|
||||
Bone_FromPyObject (PyObject * py_obj)
|
||||
{
|
||||
BPy_Bone * blen_obj;
|
||||
BPy_Bone *blen_obj;
|
||||
|
||||
blen_obj = (BPy_Bone*)py_obj;
|
||||
return (blen_obj->bone);
|
||||
blen_obj = (BPy_Bone *) py_obj;
|
||||
return (blen_obj->bone);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
if (bleffect == NULL)
|
||||
|
||||
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"));
|
||||
|
||||
pyeffect->effect = bleffect;
|
||||
if (pyeffect == NULL)
|
||||
return (EXPP_ReturnPyObjError (PyExc_MemoryError,
|
||||
"couldn't create Effect Data object"));
|
||||
|
||||
return (PyObject *)pyeffect;
|
||||
pyeffect->effect = bleffect;
|
||||
|
||||
return (PyObject *) pyeffect;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -130,58 +137,62 @@ 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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
BuildEff*ptr = (BuildEff*)self->build;
|
||||
PyObject *
|
||||
Build_setLen (BPy_Build * self, PyObject * args)
|
||||
{
|
||||
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)
|
||||
{
|
||||
BuildEff*ptr = (BuildEff*)self->build;
|
||||
PyObject *
|
||||
Build_setSfra (BPy_Build * self, PyObject * args)
|
||||
{
|
||||
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 *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");
|
||||
if (!valtuple)
|
||||
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);
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -35,185 +35,327 @@
|
||||
#include <BKE_library.h>
|
||||
#include <BLI_blenlib.h>
|
||||
|
||||
#include <Python.h>
|
||||
#include <DNA_camera_types.h>
|
||||
#include "constant.h"
|
||||
#include "gen_utils.h"
|
||||
#include "modules.h"
|
||||
|
||||
#include "Camera.h"
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* 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"},
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
/* 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);
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python Camera_Type structure definition: */
|
||||
/*****************************************************************************/
|
||||
PyTypeObject Camera_Type =
|
||||
{
|
||||
PyObject_HEAD_INIT(NULL)
|
||||
0, /* ob_size */
|
||||
"Blender Camera", /* tp_name */
|
||||
sizeof (BPy_Camera), /* tp_basicsize */
|
||||
0, /* tp_itemsize */
|
||||
/* methods */
|
||||
(destructor)Camera_dealloc, /* tp_dealloc */
|
||||
0, /* tp_print */
|
||||
(getattrfunc)Camera_getAttr, /* tp_getattr */
|
||||
(setattrfunc)Camera_setAttr, /* tp_setattr */
|
||||
(cmpfunc)Camera_compare, /* tp_compare */
|
||||
(reprfunc)Camera_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_Camera_methods, /* tp_methods */
|
||||
0, /* tp_members */
|
||||
PyTypeObject Camera_Type = {
|
||||
PyObject_HEAD_INIT (NULL) 0, /* ob_size */
|
||||
"Blender Camera", /* tp_name */
|
||||
sizeof (BPy_Camera), /* tp_basicsize */
|
||||
0, /* tp_itemsize */
|
||||
/* methods */
|
||||
(destructor) Camera_dealloc, /* tp_dealloc */
|
||||
0, /* tp_print */
|
||||
(getattrfunc) Camera_getAttr, /* tp_getattr */
|
||||
(setattrfunc) Camera_setAttr, /* tp_setattr */
|
||||
(cmpfunc) Camera_compare, /* tp_compare */
|
||||
(reprfunc) Camera_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_Camera_methods, /* tp_methods */
|
||||
0, /* tp_members */
|
||||
};
|
||||
|
||||
static PyObject *M_Camera_New(PyObject *self, PyObject *args, PyObject *kwords)
|
||||
static PyObject *
|
||||
M_Camera_New (PyObject * self, PyObject * args, PyObject * kwords)
|
||||
{
|
||||
char *type_str = "persp"; /* "persp" is type 0, "ortho" is type 1 */
|
||||
char *name_str = "CamData";
|
||||
static char *kwlist[] = {"type_str", "name_str", NULL};
|
||||
PyObject *pycam; /* for Camera Data object wrapper in Python */
|
||||
Camera *blcam; /* for actual Camera Data we create in Blender */
|
||||
char buf[21];
|
||||
char *type_str = "persp"; /* "persp" is type 0, "ortho" is type 1 */
|
||||
char *name_str = "CamData";
|
||||
static char *kwlist[] = { "type_str", "name_str", NULL };
|
||||
PyObject *pycam; /* for Camera Data object wrapper in Python */
|
||||
Camera *blcam; /* for actual Camera Data we create in Blender */
|
||||
char buf[21];
|
||||
|
||||
/* Parse the arguments passed in by the Python interpreter */
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwords, "|ss", kwlist,
|
||||
&type_str, &name_str))
|
||||
/* We expected string(s) (or nothing) as argument, but we didn't get that. */
|
||||
return EXPP_ReturnPyObjError (PyExc_AttributeError,
|
||||
"expected zero, one or two strings as arguments");
|
||||
/* Parse the arguments passed in by the Python interpreter */
|
||||
if (!PyArg_ParseTupleAndKeywords (args, kwords, "|ss", kwlist,
|
||||
&type_str, &name_str))
|
||||
/* We expected string(s) (or nothing) as argument, but we didn't get that. */
|
||||
return EXPP_ReturnPyObjError (PyExc_AttributeError,
|
||||
"expected zero, one or two strings as arguments");
|
||||
|
||||
blcam = add_camera(); /* first create the Camera Data in Blender */
|
||||
blcam = add_camera (); /* first create the Camera Data in Blender */
|
||||
|
||||
if (blcam) /* now create the wrapper obj in Python */
|
||||
pycam = Camera_CreatePyObject (blcam);
|
||||
else
|
||||
return EXPP_ReturnPyObjError (PyExc_RuntimeError,
|
||||
"couldn't create Camera Data in Blender");
|
||||
if (blcam) /* now create the wrapper obj in Python */
|
||||
pycam = Camera_CreatePyObject (blcam);
|
||||
else
|
||||
return EXPP_ReturnPyObjError (PyExc_RuntimeError,
|
||||
"couldn't create Camera Data in Blender");
|
||||
|
||||
/* let's return user count to zero, because ... */
|
||||
blcam->id.us = 0; /* ... add_camera() incref'ed it */
|
||||
/* XXX XXX Do this in other modules, too */
|
||||
/* let's return user count to zero, because ... */
|
||||
blcam->id.us = 0; /* ... add_camera() incref'ed it */
|
||||
/* XXX XXX Do this in other modules, too */
|
||||
|
||||
if (pycam == NULL)
|
||||
return EXPP_ReturnPyObjError (PyExc_MemoryError,
|
||||
"couldn't create Camera PyObject");
|
||||
if (pycam == NULL)
|
||||
return EXPP_ReturnPyObjError (PyExc_MemoryError,
|
||||
"couldn't create Camera PyObject");
|
||||
|
||||
if (strcmp (type_str, "persp") == 0) /* default, no need to set, so */
|
||||
/*blcam->type = (short)EXPP_CAM_TYPE_PERSP*/; /* we comment this line */
|
||||
else if (strcmp (type_str, "ortho") == 0)
|
||||
blcam->type = (short)EXPP_CAM_TYPE_ORTHO;
|
||||
else
|
||||
return EXPP_ReturnPyObjError (PyExc_AttributeError,
|
||||
"unknown camera type");
|
||||
if (strcmp (type_str, "persp") == 0) /* default, no need to set, so */
|
||||
/*blcam->type = (short)EXPP_CAM_TYPE_PERSP */ ;
|
||||
/* we comment this line */
|
||||
else if (strcmp (type_str, "ortho") == 0)
|
||||
blcam->type = (short) EXPP_CAM_TYPE_ORTHO;
|
||||
else
|
||||
return EXPP_ReturnPyObjError (PyExc_AttributeError,
|
||||
"unknown camera type");
|
||||
|
||||
if (strcmp (name_str, "CamData") == 0)
|
||||
return pycam;
|
||||
else { /* user gave us a name for the camera, use it */
|
||||
PyOS_snprintf (buf, sizeof(buf), "%s", name_str);
|
||||
rename_id (&blcam->id, buf); /* proper way in Blender */
|
||||
}
|
||||
if (strcmp (name_str, "CamData") == 0)
|
||||
return pycam;
|
||||
else
|
||||
{ /* user gave us a name for the camera, use it */
|
||||
PyOS_snprintf (buf, sizeof (buf), "%s", name_str);
|
||||
rename_id (&blcam->id, buf); /* proper way in Blender */
|
||||
}
|
||||
|
||||
return pycam;
|
||||
return pycam;
|
||||
}
|
||||
|
||||
static PyObject *M_Camera_Get(PyObject *self, PyObject *args)
|
||||
static PyObject *
|
||||
M_Camera_Get (PyObject * self, PyObject * args)
|
||||
{
|
||||
char *name = NULL;
|
||||
Camera *cam_iter;
|
||||
char *name = NULL;
|
||||
Camera *cam_iter;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "|s", &name))
|
||||
return EXPP_ReturnPyObjError (PyExc_TypeError,
|
||||
"expected string argument (or nothing)");
|
||||
if (!PyArg_ParseTuple (args, "|s", &name))
|
||||
return EXPP_ReturnPyObjError (PyExc_TypeError,
|
||||
"expected string argument (or nothing)");
|
||||
|
||||
cam_iter = G.main->camera.first;
|
||||
cam_iter = G.main->camera.first;
|
||||
|
||||
if (name) { /* (name) - Search camera by name */
|
||||
if (name)
|
||||
{ /* (name) - Search camera by name */
|
||||
|
||||
PyObject *wanted_cam = NULL;
|
||||
PyObject *wanted_cam = NULL;
|
||||
|
||||
while (cam_iter && !wanted_cam) {
|
||||
while (cam_iter && !wanted_cam)
|
||||
{
|
||||
|
||||
if (strcmp (name, cam_iter->id.name+2) == 0) {
|
||||
wanted_cam = Camera_CreatePyObject (cam_iter);
|
||||
break;
|
||||
}
|
||||
if (strcmp (name, cam_iter->id.name + 2) == 0)
|
||||
{
|
||||
wanted_cam = Camera_CreatePyObject (cam_iter);
|
||||
break;
|
||||
}
|
||||
|
||||
cam_iter = cam_iter->id.next;
|
||||
}
|
||||
|
||||
if (!wanted_cam) { /* Requested camera doesn't exist */
|
||||
char error_msg[64];
|
||||
PyOS_snprintf(error_msg, sizeof(error_msg),
|
||||
"Camera \"%s\" not found", name);
|
||||
return EXPP_ReturnPyObjError (PyExc_NameError, error_msg);
|
||||
}
|
||||
|
||||
return wanted_cam;
|
||||
cam_iter = cam_iter->id.next;
|
||||
}
|
||||
|
||||
else { /* () - return a list of wrappers for all cameras in the scene */
|
||||
int index = 0;
|
||||
PyObject *cam_pylist, *pyobj;
|
||||
|
||||
cam_pylist = PyList_New (BLI_countlist (&(G.main->camera)));
|
||||
|
||||
if (!cam_pylist)
|
||||
return PythonReturnErrorObject (PyExc_MemoryError,
|
||||
"couldn't create PyList");
|
||||
|
||||
while (cam_iter) {
|
||||
pyobj = Camera_CreatePyObject (cam_iter);
|
||||
|
||||
if (!pyobj)
|
||||
return PythonReturnErrorObject (PyExc_MemoryError,
|
||||
"couldn't create Camera PyObject");
|
||||
|
||||
PyList_SET_ITEM (cam_pylist, index, pyobj);
|
||||
|
||||
cam_iter = cam_iter->id.next;
|
||||
index++;
|
||||
}
|
||||
|
||||
return cam_pylist;
|
||||
if (!wanted_cam)
|
||||
{ /* Requested camera doesn't exist */
|
||||
char error_msg[64];
|
||||
PyOS_snprintf (error_msg, sizeof (error_msg),
|
||||
"Camera \"%s\" not found", name);
|
||||
return EXPP_ReturnPyObjError (PyExc_NameError, error_msg);
|
||||
}
|
||||
|
||||
return wanted_cam;
|
||||
}
|
||||
|
||||
else
|
||||
{ /* () - return a list of wrappers for all cameras in the scene */
|
||||
int index = 0;
|
||||
PyObject *cam_pylist, *pyobj;
|
||||
|
||||
cam_pylist = PyList_New (BLI_countlist (&(G.main->camera)));
|
||||
|
||||
if (!cam_pylist)
|
||||
return PythonReturnErrorObject (PyExc_MemoryError,
|
||||
"couldn't create PyList");
|
||||
|
||||
while (cam_iter)
|
||||
{
|
||||
pyobj = Camera_CreatePyObject (cam_iter);
|
||||
|
||||
if (!pyobj)
|
||||
return PythonReturnErrorObject (PyExc_MemoryError,
|
||||
"couldn't create Camera PyObject");
|
||||
|
||||
PyList_SET_ITEM (cam_pylist, index, pyobj);
|
||||
|
||||
cam_iter = cam_iter->id.next;
|
||||
index++;
|
||||
}
|
||||
|
||||
return cam_pylist;
|
||||
}
|
||||
}
|
||||
|
||||
PyObject *Camera_Init (void)
|
||||
PyObject *
|
||||
Camera_Init (void)
|
||||
{
|
||||
PyObject *submodule;
|
||||
PyObject *submodule;
|
||||
|
||||
Camera_Type.ob_type = &PyType_Type;
|
||||
Camera_Type.ob_type = &PyType_Type;
|
||||
|
||||
submodule = Py_InitModule3("Blender.Camera",
|
||||
M_Camera_methods, M_Camera_doc);
|
||||
submodule = Py_InitModule3 ("Blender.Camera",
|
||||
M_Camera_methods, M_Camera_doc);
|
||||
|
||||
return submodule;
|
||||
return submodule;
|
||||
}
|
||||
|
||||
/* Three Python Camera_Type helper functions needed by the Object module: */
|
||||
|
||||
PyObject *Camera_CreatePyObject (Camera *cam)
|
||||
PyObject *
|
||||
Camera_CreatePyObject (Camera * cam)
|
||||
{
|
||||
BPy_Camera *pycam;
|
||||
BPy_Camera *pycam;
|
||||
|
||||
pycam = (BPy_Camera *)PyObject_NEW (BPy_Camera, &Camera_Type);
|
||||
pycam = (BPy_Camera *) PyObject_NEW (BPy_Camera, &Camera_Type);
|
||||
|
||||
if (!pycam)
|
||||
return EXPP_ReturnPyObjError (PyExc_MemoryError,
|
||||
"couldn't create BPy_Camera PyObject");
|
||||
if (!pycam)
|
||||
return EXPP_ReturnPyObjError (PyExc_MemoryError,
|
||||
"couldn't create BPy_Camera PyObject");
|
||||
|
||||
pycam->camera = cam;
|
||||
pycam->camera = cam;
|
||||
|
||||
return (PyObject *)pycam;
|
||||
return (PyObject *) pycam;
|
||||
}
|
||||
|
||||
int Camera_CheckPyObject (PyObject *pyobj)
|
||||
int
|
||||
Camera_CheckPyObject (PyObject * pyobj)
|
||||
{
|
||||
return (pyobj->ob_type == &Camera_Type);
|
||||
return (pyobj->ob_type == &Camera_Type);
|
||||
}
|
||||
|
||||
Camera *Camera_FromPyObject (PyObject *pyobj)
|
||||
Camera *
|
||||
Camera_FromPyObject (PyObject * pyobj)
|
||||
{
|
||||
return ((BPy_Camera *)pyobj)->camera;
|
||||
return ((BPy_Camera *) pyobj)->camera;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
@@ -224,38 +366,41 @@ Camera *Camera_FromPyObject (PyObject *pyobj)
|
||||
/* The function will return NULL when no object with the given */
|
||||
/* name is found. */
|
||||
/*****************************************************************************/
|
||||
Camera * GetCameraByName (char * name)
|
||||
Camera *
|
||||
GetCameraByName (char *name)
|
||||
{
|
||||
Camera * cam_iter;
|
||||
Camera *cam_iter;
|
||||
|
||||
cam_iter = G.main->camera.first;
|
||||
while (cam_iter)
|
||||
cam_iter = G.main->camera.first;
|
||||
while (cam_iter)
|
||||
{
|
||||
if (StringEqual (name, GetIdName (&(cam_iter->id))))
|
||||
{
|
||||
if (StringEqual (name, GetIdName (&(cam_iter->id))))
|
||||
{
|
||||
return (cam_iter);
|
||||
}
|
||||
cam_iter = cam_iter->id.next;
|
||||
return (cam_iter);
|
||||
}
|
||||
cam_iter = cam_iter->id.next;
|
||||
}
|
||||
|
||||
/* There is no camera with the given name */
|
||||
return (NULL);
|
||||
/* There is no camera with the given name */
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python BPy_Camera methods: */
|
||||
/*****************************************************************************/
|
||||
|
||||
static PyObject *Camera_getIpo(BPy_Camera *self)
|
||||
static PyObject *
|
||||
Camera_getIpo (BPy_Camera * self)
|
||||
{
|
||||
struct Ipo *ipo = self->camera->ipo;
|
||||
struct Ipo *ipo = self->camera->ipo;
|
||||
|
||||
if (!ipo) {
|
||||
Py_INCREF (Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
if (!ipo)
|
||||
{
|
||||
Py_INCREF (Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
return Ipo_CreatePyObject (ipo);
|
||||
return Ipo_CreatePyObject (ipo);
|
||||
}
|
||||
|
||||
|
||||
@@ -263,163 +408,187 @@ static PyObject *Camera_getIpo(BPy_Camera *self)
|
||||
|
||||
|
||||
|
||||
static PyObject *Camera_getName(BPy_Camera *self)
|
||||
static PyObject *
|
||||
Camera_getName (BPy_Camera * self)
|
||||
{
|
||||
|
||||
PyObject *attr = PyString_FromString(self->camera->id.name+2);
|
||||
PyObject *attr = PyString_FromString (self->camera->id.name + 2);
|
||||
|
||||
if (attr) return attr;
|
||||
if (attr)
|
||||
return attr;
|
||||
|
||||
return EXPP_ReturnPyObjError (PyExc_RuntimeError,
|
||||
"couldn't get Camera.name attribute");
|
||||
return EXPP_ReturnPyObjError (PyExc_RuntimeError,
|
||||
"couldn't get Camera.name attribute");
|
||||
}
|
||||
|
||||
static PyObject *Camera_getType(BPy_Camera *self)
|
||||
static PyObject *
|
||||
Camera_getType (BPy_Camera * self)
|
||||
{
|
||||
PyObject *attr = PyInt_FromLong(self->camera->type);
|
||||
PyObject *attr = PyInt_FromLong (self->camera->type);
|
||||
|
||||
if (attr) return attr;
|
||||
if (attr)
|
||||
return attr;
|
||||
|
||||
return EXPP_ReturnPyObjError (PyExc_RuntimeError,
|
||||
"couldn't get Camera.type attribute");
|
||||
return EXPP_ReturnPyObjError (PyExc_RuntimeError,
|
||||
"couldn't get Camera.type attribute");
|
||||
}
|
||||
|
||||
static PyObject *Camera_getMode(BPy_Camera *self)
|
||||
static PyObject *
|
||||
Camera_getMode (BPy_Camera * self)
|
||||
{
|
||||
PyObject *attr = PyInt_FromLong(self->camera->flag);
|
||||
PyObject *attr = PyInt_FromLong (self->camera->flag);
|
||||
|
||||
if (attr) return attr;
|
||||
if (attr)
|
||||
return attr;
|
||||
|
||||
return EXPP_ReturnPyObjError (PyExc_RuntimeError,
|
||||
"couldn't get Camera.Mode attribute");
|
||||
return EXPP_ReturnPyObjError (PyExc_RuntimeError,
|
||||
"couldn't get Camera.Mode attribute");
|
||||
}
|
||||
|
||||
static PyObject *Camera_getLens(BPy_Camera *self)
|
||||
static PyObject *
|
||||
Camera_getLens (BPy_Camera * self)
|
||||
{
|
||||
PyObject *attr = PyFloat_FromDouble(self->camera->lens);
|
||||
PyObject *attr = PyFloat_FromDouble (self->camera->lens);
|
||||
|
||||
if (attr) return attr;
|
||||
if (attr)
|
||||
return attr;
|
||||
|
||||
return EXPP_ReturnPyObjError (PyExc_RuntimeError,
|
||||
"couldn't get Camera.lens attribute");
|
||||
return EXPP_ReturnPyObjError (PyExc_RuntimeError,
|
||||
"couldn't get Camera.lens attribute");
|
||||
}
|
||||
|
||||
static PyObject *Camera_getClipStart(BPy_Camera *self)
|
||||
static PyObject *
|
||||
Camera_getClipStart (BPy_Camera * self)
|
||||
{
|
||||
PyObject *attr = PyFloat_FromDouble(self->camera->clipsta);
|
||||
PyObject *attr = PyFloat_FromDouble (self->camera->clipsta);
|
||||
|
||||
if (attr) return attr;
|
||||
if (attr)
|
||||
return attr;
|
||||
|
||||
return EXPP_ReturnPyObjError (PyExc_RuntimeError,
|
||||
"couldn't get Camera.clipStart attribute");
|
||||
return EXPP_ReturnPyObjError (PyExc_RuntimeError,
|
||||
"couldn't get Camera.clipStart attribute");
|
||||
}
|
||||
|
||||
static PyObject *Camera_getClipEnd(BPy_Camera *self)
|
||||
static PyObject *
|
||||
Camera_getClipEnd (BPy_Camera * self)
|
||||
{
|
||||
PyObject *attr = PyFloat_FromDouble(self->camera->clipend);
|
||||
PyObject *attr = PyFloat_FromDouble (self->camera->clipend);
|
||||
|
||||
if (attr) return attr;
|
||||
if (attr)
|
||||
return attr;
|
||||
|
||||
return EXPP_ReturnPyObjError (PyExc_RuntimeError,
|
||||
"couldn't get Camera.clipEnd attribute");
|
||||
return EXPP_ReturnPyObjError (PyExc_RuntimeError,
|
||||
"couldn't get Camera.clipEnd attribute");
|
||||
}
|
||||
|
||||
static PyObject *Camera_getDrawSize(BPy_Camera *self)
|
||||
static PyObject *
|
||||
Camera_getDrawSize (BPy_Camera * self)
|
||||
{
|
||||
PyObject *attr = PyFloat_FromDouble(self->camera->drawsize);
|
||||
PyObject *attr = PyFloat_FromDouble (self->camera->drawsize);
|
||||
|
||||
if (attr) return attr;
|
||||
if (attr)
|
||||
return attr;
|
||||
|
||||
return EXPP_ReturnPyObjError (PyExc_RuntimeError,
|
||||
"couldn't get Camera.drawSize attribute");
|
||||
return EXPP_ReturnPyObjError (PyExc_RuntimeError,
|
||||
"couldn't get Camera.drawSize attribute");
|
||||
}
|
||||
|
||||
|
||||
|
||||
static PyObject *Camera_setIpo(BPy_Camera *self, PyObject *args)
|
||||
static PyObject *
|
||||
Camera_setIpo (BPy_Camera * self, PyObject * args)
|
||||
{
|
||||
PyObject *pyipo = 0;
|
||||
Ipo *ipo = NULL;
|
||||
Ipo *oldipo;
|
||||
PyObject *pyipo = 0;
|
||||
Ipo *ipo = NULL;
|
||||
Ipo *oldipo;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "O!", &Ipo_Type, &pyipo))
|
||||
return EXPP_ReturnPyObjError (PyExc_TypeError, "expected Ipo as argument");
|
||||
if (!PyArg_ParseTuple (args, "O!", &Ipo_Type, &pyipo))
|
||||
return EXPP_ReturnPyObjError (PyExc_TypeError,
|
||||
"expected Ipo as argument");
|
||||
|
||||
ipo = Ipo_FromPyObject(pyipo);
|
||||
ipo = Ipo_FromPyObject (pyipo);
|
||||
|
||||
if (!ipo) return EXPP_ReturnPyObjError (PyExc_RuntimeError, "null ipo!");
|
||||
if (!ipo)
|
||||
return EXPP_ReturnPyObjError (PyExc_RuntimeError, "null ipo!");
|
||||
|
||||
if (ipo->blocktype != ID_CA)
|
||||
return EXPP_ReturnPyObjError (PyExc_TypeError,
|
||||
"this ipo is not a camera data ipo");
|
||||
if (ipo->blocktype != ID_CA)
|
||||
return EXPP_ReturnPyObjError (PyExc_TypeError,
|
||||
"this ipo is not a camera data ipo");
|
||||
|
||||
oldipo = self->camera->ipo;
|
||||
if (oldipo) {
|
||||
ID *id = &oldipo->id;
|
||||
if (id->us > 0) id->us--;
|
||||
}
|
||||
oldipo = self->camera->ipo;
|
||||
if (oldipo)
|
||||
{
|
||||
ID *id = &oldipo->id;
|
||||
if (id->us > 0)
|
||||
id->us--;
|
||||
}
|
||||
|
||||
((ID *)&ipo->id)->us++;
|
||||
((ID *) & ipo->id)->us++;
|
||||
|
||||
self->camera->ipo = ipo;
|
||||
self->camera->ipo = ipo;
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
Py_INCREF (Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
static PyObject *Camera_clearIpo(BPy_Camera *self)
|
||||
static PyObject *
|
||||
Camera_clearIpo (BPy_Camera * self)
|
||||
{
|
||||
Camera *cam = self->camera;
|
||||
Ipo *ipo = (Ipo *)cam->ipo;
|
||||
Camera *cam = self->camera;
|
||||
Ipo *ipo = (Ipo *) cam->ipo;
|
||||
|
||||
if (ipo) {
|
||||
ID *id = &ipo->id;
|
||||
if (id->us > 0) id->us--;
|
||||
cam->ipo = NULL;
|
||||
if (ipo)
|
||||
{
|
||||
ID *id = &ipo->id;
|
||||
if (id->us > 0)
|
||||
id->us--;
|
||||
cam->ipo = NULL;
|
||||
|
||||
Py_INCREF (Py_True);
|
||||
return Py_True;
|
||||
}
|
||||
Py_INCREF (Py_True);
|
||||
return Py_True;
|
||||
}
|
||||
|
||||
Py_INCREF (Py_False); /* no ipo found */
|
||||
return Py_False;
|
||||
Py_INCREF (Py_False); /* no ipo found */
|
||||
return Py_False;
|
||||
}
|
||||
|
||||
static PyObject *Camera_setName(BPy_Camera *self, PyObject *args)
|
||||
static PyObject *
|
||||
Camera_setName (BPy_Camera * self, PyObject * args)
|
||||
{
|
||||
char *name;
|
||||
char buf[21];
|
||||
char *name;
|
||||
char buf[21];
|
||||
|
||||
if (!PyArg_ParseTuple(args, "s", &name))
|
||||
return EXPP_ReturnPyObjError (PyExc_TypeError,
|
||||
"expected string argument");
|
||||
if (!PyArg_ParseTuple (args, "s", &name))
|
||||
return EXPP_ReturnPyObjError (PyExc_TypeError,
|
||||
"expected string argument");
|
||||
|
||||
PyOS_snprintf(buf, sizeof(buf), "%s", name);
|
||||
PyOS_snprintf (buf, sizeof (buf), "%s", name);
|
||||
|
||||
rename_id(&self->camera->id, buf);
|
||||
rename_id (&self->camera->id, buf);
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
Py_INCREF (Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
static PyObject *Camera_setType(BPy_Camera *self, PyObject *args)
|
||||
static PyObject *
|
||||
Camera_setType (BPy_Camera * self, PyObject * args)
|
||||
{
|
||||
char *type;
|
||||
char *type;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "s", &type))
|
||||
return EXPP_ReturnPyObjError (PyExc_TypeError,
|
||||
"expected string argument");
|
||||
if (!PyArg_ParseTuple (args, "s", &type))
|
||||
return EXPP_ReturnPyObjError (PyExc_TypeError,
|
||||
"expected string argument");
|
||||
|
||||
if (strcmp (type, "persp") == 0)
|
||||
self->camera->type = (short)EXPP_CAM_TYPE_PERSP;
|
||||
else if (strcmp (type, "ortho") == 0)
|
||||
self->camera->type = (short)EXPP_CAM_TYPE_ORTHO;
|
||||
else
|
||||
return EXPP_ReturnPyObjError (PyExc_AttributeError,
|
||||
"unknown camera type");
|
||||
if (strcmp (type, "persp") == 0)
|
||||
self->camera->type = (short) EXPP_CAM_TYPE_PERSP;
|
||||
else if (strcmp (type, "ortho") == 0)
|
||||
self->camera->type = (short) EXPP_CAM_TYPE_ORTHO;
|
||||
else
|
||||
return EXPP_ReturnPyObjError (PyExc_AttributeError,
|
||||
"unknown camera type");
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
Py_INCREF (Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
/* This one is 'private'. It is not really a method, just a helper function for
|
||||
@@ -428,198 +597,217 @@ static PyObject *Camera_setType(BPy_Camera *self, PyObject *args)
|
||||
* the method setType expects a string ('persp' or 'ortho') or an empty
|
||||
* argument, this function should receive an int (0 or 1). */
|
||||
|
||||
static PyObject *Camera_setIntType(BPy_Camera *self, PyObject *args)
|
||||
static PyObject *
|
||||
Camera_setIntType (BPy_Camera * self, PyObject * args)
|
||||
{
|
||||
short value;
|
||||
short value;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "h", &value))
|
||||
return EXPP_ReturnPyObjError (PyExc_TypeError,
|
||||
"expected int argument: 0 or 1");
|
||||
if (!PyArg_ParseTuple (args, "h", &value))
|
||||
return EXPP_ReturnPyObjError (PyExc_TypeError,
|
||||
"expected int argument: 0 or 1");
|
||||
|
||||
if (value == 0 || value == 1)
|
||||
self->camera->type = value;
|
||||
else
|
||||
return EXPP_ReturnPyObjError (PyExc_ValueError,
|
||||
"expected int argument: 0 or 1");
|
||||
if (value == 0 || value == 1)
|
||||
self->camera->type = value;
|
||||
else
|
||||
return EXPP_ReturnPyObjError (PyExc_ValueError,
|
||||
"expected int argument: 0 or 1");
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
Py_INCREF (Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
static PyObject *Camera_setMode(BPy_Camera *self, PyObject *args)
|
||||
static PyObject *
|
||||
Camera_setMode (BPy_Camera * self, PyObject * args)
|
||||
{
|
||||
char *mode_str1 = NULL, *mode_str2 = NULL;
|
||||
short flag = 0;
|
||||
char *mode_str1 = NULL, *mode_str2 = NULL;
|
||||
short flag = 0;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "|ss", &mode_str1, &mode_str2))
|
||||
return EXPP_ReturnPyObjError (PyExc_AttributeError,
|
||||
"expected one or two strings as arguments");
|
||||
|
||||
if (mode_str1 != NULL) {
|
||||
if (strcmp(mode_str1, "showLimits") == 0)
|
||||
flag |= (short)EXPP_CAM_MODE_SHOWLIMITS;
|
||||
else if (strcmp(mode_str1, "showMist") == 0)
|
||||
flag |= (short)EXPP_CAM_MODE_SHOWMIST;
|
||||
else
|
||||
return EXPP_ReturnPyObjError (PyExc_AttributeError,
|
||||
"first argument is an unknown camera flag");
|
||||
if (!PyArg_ParseTuple (args, "|ss", &mode_str1, &mode_str2))
|
||||
return EXPP_ReturnPyObjError (PyExc_AttributeError,
|
||||
"expected one or two strings as arguments");
|
||||
|
||||
if (mode_str2 != NULL) {
|
||||
if (strcmp(mode_str2, "showLimits") == 0)
|
||||
flag |= (short)EXPP_CAM_MODE_SHOWLIMITS;
|
||||
else if (strcmp(mode_str2, "showMist") == 0)
|
||||
flag |= (short)EXPP_CAM_MODE_SHOWMIST;
|
||||
else
|
||||
return EXPP_ReturnPyObjError (PyExc_AttributeError,
|
||||
"second argument is an unknown camera flag");
|
||||
}
|
||||
if (mode_str1 != NULL)
|
||||
{
|
||||
if (strcmp (mode_str1, "showLimits") == 0)
|
||||
flag |= (short) EXPP_CAM_MODE_SHOWLIMITS;
|
||||
else if (strcmp (mode_str1, "showMist") == 0)
|
||||
flag |= (short) EXPP_CAM_MODE_SHOWMIST;
|
||||
else
|
||||
return EXPP_ReturnPyObjError (PyExc_AttributeError,
|
||||
"first argument is an unknown camera flag");
|
||||
|
||||
if (mode_str2 != NULL)
|
||||
{
|
||||
if (strcmp (mode_str2, "showLimits") == 0)
|
||||
flag |= (short) EXPP_CAM_MODE_SHOWLIMITS;
|
||||
else if (strcmp (mode_str2, "showMist") == 0)
|
||||
flag |= (short) EXPP_CAM_MODE_SHOWMIST;
|
||||
else
|
||||
return EXPP_ReturnPyObjError (PyExc_AttributeError,
|
||||
"second argument is an unknown camera flag");
|
||||
}
|
||||
}
|
||||
|
||||
self->camera->flag = flag;
|
||||
self->camera->flag = flag;
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
Py_INCREF (Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
/* Another helper function, for the same reason.
|
||||
* (See comment before Camera_setIntType above). */
|
||||
|
||||
static PyObject *Camera_setIntMode(BPy_Camera *self, PyObject *args)
|
||||
static PyObject *
|
||||
Camera_setIntMode (BPy_Camera * self, PyObject * args)
|
||||
{
|
||||
short value;
|
||||
short value;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "h", &value))
|
||||
return EXPP_ReturnPyObjError (PyExc_TypeError,
|
||||
"expected int argument in [0,3]");
|
||||
if (!PyArg_ParseTuple (args, "h", &value))
|
||||
return EXPP_ReturnPyObjError (PyExc_TypeError,
|
||||
"expected int argument in [0,3]");
|
||||
|
||||
if (value >= 0 && value <= 3)
|
||||
self->camera->flag = value;
|
||||
else
|
||||
return EXPP_ReturnPyObjError (PyExc_ValueError,
|
||||
"expected int argument in [0,3]");
|
||||
if (value >= 0 && value <= 3)
|
||||
self->camera->flag = value;
|
||||
else
|
||||
return EXPP_ReturnPyObjError (PyExc_ValueError,
|
||||
"expected int argument in [0,3]");
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
Py_INCREF (Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
static PyObject *Camera_setLens(BPy_Camera *self, PyObject *args)
|
||||
static PyObject *
|
||||
Camera_setLens (BPy_Camera * self, PyObject * args)
|
||||
{
|
||||
float value;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "f", &value))
|
||||
return EXPP_ReturnPyObjError (PyExc_TypeError,
|
||||
"expected float argument");
|
||||
|
||||
self->camera->lens = EXPP_ClampFloat (value,
|
||||
EXPP_CAM_LENS_MIN, EXPP_CAM_LENS_MAX);
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
float value;
|
||||
|
||||
if (!PyArg_ParseTuple (args, "f", &value))
|
||||
return EXPP_ReturnPyObjError (PyExc_TypeError, "expected float argument");
|
||||
|
||||
self->camera->lens = EXPP_ClampFloat (value,
|
||||
EXPP_CAM_LENS_MIN, EXPP_CAM_LENS_MAX);
|
||||
|
||||
Py_INCREF (Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
static PyObject *Camera_setClipStart(BPy_Camera *self, PyObject *args)
|
||||
static PyObject *
|
||||
Camera_setClipStart (BPy_Camera * self, PyObject * args)
|
||||
{
|
||||
float value;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "f", &value))
|
||||
return EXPP_ReturnPyObjError (PyExc_TypeError,
|
||||
"expected float argument");
|
||||
float value;
|
||||
|
||||
self->camera->clipsta = EXPP_ClampFloat (value,
|
||||
EXPP_CAM_CLIPSTART_MIN, EXPP_CAM_CLIPSTART_MAX);
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
if (!PyArg_ParseTuple (args, "f", &value))
|
||||
return EXPP_ReturnPyObjError (PyExc_TypeError, "expected float argument");
|
||||
|
||||
self->camera->clipsta = EXPP_ClampFloat (value,
|
||||
EXPP_CAM_CLIPSTART_MIN,
|
||||
EXPP_CAM_CLIPSTART_MAX);
|
||||
|
||||
Py_INCREF (Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
static PyObject *Camera_setClipEnd(BPy_Camera *self, PyObject *args)
|
||||
static PyObject *
|
||||
Camera_setClipEnd (BPy_Camera * self, PyObject * args)
|
||||
{
|
||||
float value;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "f", &value))
|
||||
return EXPP_ReturnPyObjError (PyExc_TypeError,
|
||||
"expected float argument");
|
||||
float value;
|
||||
|
||||
self->camera->clipend = EXPP_ClampFloat (value,
|
||||
EXPP_CAM_CLIPEND_MIN, EXPP_CAM_CLIPEND_MAX);
|
||||
if (!PyArg_ParseTuple (args, "f", &value))
|
||||
return EXPP_ReturnPyObjError (PyExc_TypeError, "expected float argument");
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
self->camera->clipend = EXPP_ClampFloat (value,
|
||||
EXPP_CAM_CLIPEND_MIN,
|
||||
EXPP_CAM_CLIPEND_MAX);
|
||||
|
||||
Py_INCREF (Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
static PyObject *Camera_setDrawSize(BPy_Camera *self, PyObject *args)
|
||||
static PyObject *
|
||||
Camera_setDrawSize (BPy_Camera * self, PyObject * args)
|
||||
{
|
||||
float value;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "f", &value))
|
||||
return EXPP_ReturnPyObjError (PyExc_TypeError,
|
||||
"expected a float number as argument");
|
||||
float value;
|
||||
|
||||
self->camera->drawsize = EXPP_ClampFloat (value,
|
||||
EXPP_CAM_DRAWSIZE_MIN, EXPP_CAM_DRAWSIZE_MAX);
|
||||
if (!PyArg_ParseTuple (args, "f", &value))
|
||||
return EXPP_ReturnPyObjError (PyExc_TypeError,
|
||||
"expected a float number as argument");
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
self->camera->drawsize = EXPP_ClampFloat (value,
|
||||
EXPP_CAM_DRAWSIZE_MIN,
|
||||
EXPP_CAM_DRAWSIZE_MAX);
|
||||
|
||||
Py_INCREF (Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
static void Camera_dealloc (BPy_Camera *self)
|
||||
static void
|
||||
Camera_dealloc (BPy_Camera * self)
|
||||
{
|
||||
PyObject_DEL (self);
|
||||
PyObject_DEL (self);
|
||||
}
|
||||
|
||||
static PyObject *Camera_getAttr (BPy_Camera *self, char *name)
|
||||
static PyObject *
|
||||
Camera_getAttr (BPy_Camera * self, char *name)
|
||||
{
|
||||
PyObject *attr = Py_None;
|
||||
PyObject *attr = Py_None;
|
||||
|
||||
if (strcmp(name, "name") == 0)
|
||||
attr = PyString_FromString(self->camera->id.name+2);
|
||||
else if (strcmp(name, "type") == 0)
|
||||
attr = PyInt_FromLong(self->camera->type);
|
||||
else if (strcmp(name, "mode") == 0)
|
||||
attr = PyInt_FromLong(self->camera->flag);
|
||||
else if (strcmp(name, "lens") == 0)
|
||||
attr = PyFloat_FromDouble(self->camera->lens);
|
||||
else if (strcmp(name, "clipStart") == 0)
|
||||
attr = PyFloat_FromDouble(self->camera->clipsta);
|
||||
else if (strcmp(name, "clipEnd") == 0)
|
||||
attr = PyFloat_FromDouble(self->camera->clipend);
|
||||
else if (strcmp(name, "drawSize") == 0)
|
||||
attr = PyFloat_FromDouble(self->camera->drawsize);
|
||||
else if (strcmp(name, "ipo") == 0) {
|
||||
Ipo *ipo = self->camera->ipo;
|
||||
if (ipo) attr = Ipo_CreatePyObject (ipo);
|
||||
}
|
||||
if (strcmp (name, "name") == 0)
|
||||
attr = PyString_FromString (self->camera->id.name + 2);
|
||||
else if (strcmp (name, "type") == 0)
|
||||
attr = PyInt_FromLong (self->camera->type);
|
||||
else if (strcmp (name, "mode") == 0)
|
||||
attr = PyInt_FromLong (self->camera->flag);
|
||||
else if (strcmp (name, "lens") == 0)
|
||||
attr = PyFloat_FromDouble (self->camera->lens);
|
||||
else if (strcmp (name, "clipStart") == 0)
|
||||
attr = PyFloat_FromDouble (self->camera->clipsta);
|
||||
else if (strcmp (name, "clipEnd") == 0)
|
||||
attr = PyFloat_FromDouble (self->camera->clipend);
|
||||
else if (strcmp (name, "drawSize") == 0)
|
||||
attr = PyFloat_FromDouble (self->camera->drawsize);
|
||||
else if (strcmp (name, "ipo") == 0)
|
||||
{
|
||||
Ipo *ipo = self->camera->ipo;
|
||||
if (ipo)
|
||||
attr = Ipo_CreatePyObject (ipo);
|
||||
}
|
||||
|
||||
else if (strcmp(name, "Types") == 0) {
|
||||
attr = Py_BuildValue("{s:h,s:h}", "persp", EXPP_CAM_TYPE_PERSP,
|
||||
"ortho", EXPP_CAM_TYPE_ORTHO);
|
||||
}
|
||||
else if (strcmp (name, "Types") == 0)
|
||||
{
|
||||
attr = Py_BuildValue ("{s:h,s:h}", "persp", EXPP_CAM_TYPE_PERSP,
|
||||
"ortho", EXPP_CAM_TYPE_ORTHO);
|
||||
}
|
||||
|
||||
else if (strcmp(name, "Modes") == 0) {
|
||||
attr = Py_BuildValue("{s:h,s:h}", "showLimits", EXPP_CAM_MODE_SHOWLIMITS,
|
||||
"showMist", EXPP_CAM_MODE_SHOWMIST);
|
||||
}
|
||||
else if (strcmp (name, "Modes") == 0)
|
||||
{
|
||||
attr =
|
||||
Py_BuildValue ("{s:h,s:h}", "showLimits", EXPP_CAM_MODE_SHOWLIMITS,
|
||||
"showMist", EXPP_CAM_MODE_SHOWMIST);
|
||||
}
|
||||
|
||||
else if (strcmp(name, "__members__") == 0) {
|
||||
attr = Py_BuildValue("[s,s,s,s,s,s,s,s,s,s]",
|
||||
"name", "type", "mode", "lens", "clipStart", "ipo",
|
||||
"clipEnd", "drawSize", "Types", "Modes");
|
||||
}
|
||||
else if (strcmp (name, "__members__") == 0)
|
||||
{
|
||||
attr = Py_BuildValue ("[s,s,s,s,s,s,s,s,s,s]",
|
||||
"name", "type", "mode", "lens", "clipStart",
|
||||
"ipo", "clipEnd", "drawSize", "Types", "Modes");
|
||||
}
|
||||
|
||||
if (!attr)
|
||||
return EXPP_ReturnPyObjError (PyExc_MemoryError,
|
||||
"couldn't create PyObject");
|
||||
if (!attr)
|
||||
return EXPP_ReturnPyObjError (PyExc_MemoryError,
|
||||
"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_Camera_methods, (PyObject *)self, name);
|
||||
/* not an attribute, search the methods table */
|
||||
return Py_FindMethod (BPy_Camera_methods, (PyObject *) self, name);
|
||||
}
|
||||
|
||||
static int Camera_setAttr (BPy_Camera *self, char *name, PyObject *value)
|
||||
static int
|
||||
Camera_setAttr (BPy_Camera * self, char *name, PyObject * value)
|
||||
{
|
||||
PyObject *valtuple;
|
||||
PyObject *error = NULL;
|
||||
PyObject *valtuple;
|
||||
PyObject *error = NULL;
|
||||
|
||||
/* We're playing a trick on the Python API users here. Even if they use
|
||||
* Camera.member = val instead of Camera.setMember(val), we end up using the
|
||||
@@ -628,60 +816,63 @@ static int Camera_setAttr (BPy_Camera *self, char *name, PyObject *value)
|
||||
|
||||
/* First we put "value" in a tuple, because we want to pass it to functions
|
||||
* that only accept PyTuples. */
|
||||
valtuple = Py_BuildValue("(O)", value);
|
||||
valtuple = Py_BuildValue ("(O)", value);
|
||||
|
||||
if (!valtuple) /* everything OK with our PyObject? */
|
||||
return EXPP_ReturnIntError(PyExc_MemoryError,
|
||||
"CameraSetAttr: couldn't create PyTuple");
|
||||
if (!valtuple) /* everything OK with our PyObject? */
|
||||
return EXPP_ReturnIntError (PyExc_MemoryError,
|
||||
"CameraSetAttr: couldn't create PyTuple");
|
||||
|
||||
/* Now we just compare "name" with all possible BPy_Camera member variables */
|
||||
if (strcmp (name, "name") == 0)
|
||||
error = Camera_setName (self, valtuple);
|
||||
else if (strcmp (name, "type") == 0)
|
||||
error = Camera_setIntType (self, valtuple); /* special case */
|
||||
else if (strcmp (name, "mode") == 0)
|
||||
error = Camera_setIntMode (self, valtuple); /* special case */
|
||||
else if (strcmp (name, "lens") == 0)
|
||||
error = Camera_setLens (self, valtuple);
|
||||
else if (strcmp (name, "clipStart") == 0)
|
||||
error = Camera_setClipStart (self, valtuple);
|
||||
else if (strcmp (name, "clipEnd") == 0)
|
||||
error = Camera_setClipEnd (self, valtuple);
|
||||
else if (strcmp (name, "drawSize") == 0)
|
||||
error = Camera_setDrawSize (self, valtuple);
|
||||
if (strcmp (name, "name") == 0)
|
||||
error = Camera_setName (self, valtuple);
|
||||
else if (strcmp (name, "type") == 0)
|
||||
error = Camera_setIntType (self, valtuple); /* special case */
|
||||
else if (strcmp (name, "mode") == 0)
|
||||
error = Camera_setIntMode (self, valtuple); /* special case */
|
||||
else if (strcmp (name, "lens") == 0)
|
||||
error = Camera_setLens (self, valtuple);
|
||||
else if (strcmp (name, "clipStart") == 0)
|
||||
error = Camera_setClipStart (self, valtuple);
|
||||
else if (strcmp (name, "clipEnd") == 0)
|
||||
error = Camera_setClipEnd (self, valtuple);
|
||||
else if (strcmp (name, "drawSize") == 0)
|
||||
error = Camera_setDrawSize (self, valtuple);
|
||||
|
||||
else { /* Error */
|
||||
Py_DECREF(valtuple);
|
||||
else
|
||||
{ /* Error */
|
||||
Py_DECREF (valtuple);
|
||||
|
||||
if ((strcmp (name, "Types") == 0) || /* user tried to change a */
|
||||
(strcmp (name, "Modes") == 0)) /* constant dict type ... */
|
||||
return EXPP_ReturnIntError (PyExc_AttributeError,
|
||||
"constant dictionary -- cannot be changed");
|
||||
if ((strcmp (name, "Types") == 0) || /* user tried to change a */
|
||||
(strcmp (name, "Modes") == 0)) /* constant dict type ... */
|
||||
return EXPP_ReturnIntError (PyExc_AttributeError,
|
||||
"constant dictionary -- cannot be changed");
|
||||
|
||||
else /* ... or no member with the given name was found */
|
||||
return EXPP_ReturnIntError (PyExc_KeyError,
|
||||
"attribute not found");
|
||||
}
|
||||
else /* ... or no member with the given name was found */
|
||||
return EXPP_ReturnIntError (PyExc_KeyError, "attribute not found");
|
||||
}
|
||||
|
||||
/* valtuple won't be returned to the caller, so we need to DECREF it */
|
||||
Py_DECREF (valtuple);
|
||||
Py_DECREF (valtuple);
|
||||
|
||||
if (error != Py_None) return -1;
|
||||
if (error != Py_None)
|
||||
return -1;
|
||||
|
||||
/* Py_None was incref'ed by the called Camera_set* function. We probably
|
||||
* don't need to decref Py_None (!), but since Python/C API manual tells us
|
||||
* to treat it like any other PyObject regarding ref counting ... */
|
||||
Py_DECREF (Py_None);
|
||||
return 0; /* normal exit */
|
||||
Py_DECREF (Py_None);
|
||||
return 0; /* normal exit */
|
||||
}
|
||||
|
||||
static int Camera_compare (BPy_Camera *a, BPy_Camera *b)
|
||||
static int
|
||||
Camera_compare (BPy_Camera * a, BPy_Camera * b)
|
||||
{
|
||||
Camera *pa = a->camera, *pb = b->camera;
|
||||
return (pa == pb) ? 0:-1;
|
||||
Camera *pa = a->camera, *pb = b->camera;
|
||||
return (pa == pb) ? 0 : -1;
|
||||
}
|
||||
|
||||
static PyObject *Camera_repr (BPy_Camera *self)
|
||||
static PyObject *
|
||||
Camera_repr (BPy_Camera * self)
|
||||
{
|
||||
return PyString_FromFormat("[Camera \"%s\"]", self->camera->id.name+2);
|
||||
return PyString_FromFormat ("[Camera \"%s\"]", self->camera->id.name + 2);
|
||||
}
|
||||
|
||||
@@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user