new function for the Metaball objects : addMetaelem, which allows users to create Metaballs from python.
modified doc/Metaball.py to add this function modified Object.c to allow the creation of Metaball objects
This commit is contained in:
@@ -31,6 +31,10 @@
|
||||
|
||||
#include "Metaball.h"
|
||||
|
||||
PyObject * Metaball_Init (void);
|
||||
PyObject * Metaball_CreatePyObject (MetaBall *metaball);
|
||||
MetaBall * Metaball_FromPyObject (PyObject *py_obj);
|
||||
int Metaball_CheckPyObject (PyObject *py_obj);
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python Metaball_Type structure definition: */
|
||||
@@ -177,9 +181,63 @@ PyObject *Metaball_Init (void)
|
||||
return (submodule);
|
||||
}
|
||||
|
||||
int
|
||||
Metaball_CheckPyObject (PyObject * pyobj)
|
||||
{
|
||||
return (pyobj->ob_type == &Metaball_Type);
|
||||
}
|
||||
|
||||
|
||||
MetaBall * Metaball_FromPyObject (PyObject * pyobj)
|
||||
{
|
||||
return ((BPy_Metaball *) pyobj)->metaball;
|
||||
}
|
||||
|
||||
/*******************************************************************************/
|
||||
/* Python BPy_Metaball methods: */
|
||||
/*******************************************************************************/
|
||||
void*MEM_callocN(unsigned int,char*);
|
||||
void allqueue(unsigned short,short);
|
||||
|
||||
static PyObject *Metaball_addMetaelem(BPy_Metaball *self,PyObject*args)
|
||||
{
|
||||
MetaElem *ml;
|
||||
PyObject *listargs=0;
|
||||
int type,lay;
|
||||
float x,y,z,rad,s,expx,expy,expz;
|
||||
if (!PyArg_ParseTuple(args, "O", &listargs))
|
||||
return (EXPP_ReturnPyObjError(PyExc_TypeError,"expected a list"));
|
||||
if (!PyList_Check(listargs))
|
||||
return (EXPP_ReturnPyObjError(PyExc_TypeError,"expected a list"));
|
||||
|
||||
|
||||
type = PyInt_AsLong( PyList_GetItem(listargs,0));
|
||||
x = PyFloat_AsDouble(PyList_GetItem(listargs,1));
|
||||
y = PyFloat_AsDouble(PyList_GetItem(listargs,2));
|
||||
z = PyFloat_AsDouble(PyList_GetItem(listargs,3));
|
||||
rad = PyFloat_AsDouble(PyList_GetItem(listargs,4));
|
||||
lay = PyInt_AsLong(PyList_GetItem(listargs,5));
|
||||
s = PyFloat_AsDouble(PyList_GetItem(listargs,6));
|
||||
expx = PyFloat_AsDouble(PyList_GetItem(listargs,7));
|
||||
expy = PyFloat_AsDouble(PyList_GetItem(listargs,8));
|
||||
expz = PyFloat_AsDouble(PyList_GetItem(listargs,9));
|
||||
|
||||
ml= MEM_callocN(sizeof(MetaElem), "metaelem");
|
||||
BLI_addhead(&(self->metaball->elems), ml);
|
||||
|
||||
ml->x= x;ml->y= y;ml->z= z;
|
||||
ml->rad= rad;
|
||||
ml->lay= lay;
|
||||
ml->s= s;
|
||||
ml->flag= SELECT;
|
||||
ml->type = type;
|
||||
ml->expx= expx;ml->expy= expy;ml->expz= expz;
|
||||
ml->type = type;
|
||||
allqueue(0X4013, 0);
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
static PyObject *Metaball_getName(BPy_Metaball *self)
|
||||
{
|
||||
|
||||
|
||||
@@ -82,6 +82,7 @@ struct PyMethodDef M_Metaball_methods[] = {
|
||||
/*****************************************************************************/
|
||||
/* Python BPy_Metaball methods declarations: */
|
||||
/*****************************************************************************/
|
||||
static PyObject *Metaball_addMetaelem(BPy_Metaball *self,PyObject*args);
|
||||
static PyObject *Metaball_getBbox(BPy_Metaball *self);
|
||||
static PyObject *Metaball_getName(BPy_Metaball *self);
|
||||
static PyObject *Metaball_setName(BPy_Metaball *self,PyObject*args);
|
||||
@@ -120,6 +121,8 @@ static PyMethodDef BPy_Metaball_methods[] = {
|
||||
/* name, method, flags, doc */
|
||||
{"getName", (PyCFunction)Metaball_getName,\
|
||||
METH_NOARGS, "() - Return Metaball name"},
|
||||
{"addMetaelem", (PyCFunction)Metaball_addMetaelem,\
|
||||
METH_VARARGS, "() -Adds a metaelem to the metaball"},
|
||||
{"setName", (PyCFunction)Metaball_setName,\
|
||||
METH_VARARGS, "() - Sets Metaball name"},
|
||||
{"getWiresize", (PyCFunction)Metaball_getWiresize,\
|
||||
|
||||
@@ -300,7 +300,7 @@ PyObject *M_Object_New(PyObject *self, PyObject *args)
|
||||
/* else if (strcmp (str_type, "Ika") == 0) type = OB_IKA; */
|
||||
else if (strcmp (str_type, "Lamp") == 0) type = OB_LAMP;
|
||||
else if (strcmp (str_type, "Lattice") == 0) type = OB_LATTICE;
|
||||
/* else if (strcmp (str_type, "Mball") == 0) type = OB_MBALL; */
|
||||
else if (strcmp (str_type, "Mball") == 0) type = OB_MBALL;
|
||||
else if (strcmp (str_type, "Mesh") == 0) type = OB_MESH;
|
||||
else if (strcmp (str_type, "Surf") == 0) type = OB_SURF;
|
||||
/* else if (strcmp (str_type, "Wave") == 0) type = OB_WAVE; */
|
||||
@@ -627,6 +627,9 @@ int EXPP_add_obdata(struct Object *object)
|
||||
object->data = (void *)add_lattice();
|
||||
object->dt = OB_WIRE;
|
||||
break;
|
||||
case OB_MBALL:
|
||||
object->data = add_mball();
|
||||
break;
|
||||
|
||||
/* TODO the following types will be supported later
|
||||
case OB_SURF:
|
||||
@@ -636,9 +639,6 @@ int EXPP_add_obdata(struct Object *object)
|
||||
case OB_FONT:
|
||||
object->data = add_curve(OB_FONT);
|
||||
break;
|
||||
case OB_MBALL:
|
||||
object->data = add_mball();
|
||||
break;
|
||||
case OB_IKA:
|
||||
object->data = add_ika();
|
||||
object->dt = OB_WIRE;
|
||||
@@ -1092,6 +1092,8 @@ static PyObject *Object_link (BPy_Object *self, PyObject *args)
|
||||
data = (void *)Mesh_FromPyObject (py_data, self->object);
|
||||
if (Lattice_CheckPyObject (py_data))
|
||||
data = (void *)Lattice_FromPyObject (py_data);
|
||||
if (Metaball_CheckPyObject (py_data))
|
||||
data = (void *)Metaball_FromPyObject (py_data);
|
||||
|
||||
/* have we set data to something good? */
|
||||
if( !data )
|
||||
@@ -1148,6 +1150,13 @@ static PyObject *Object_link (BPy_Object *self, PyObject *args)
|
||||
"The 'link' object is incompatible with the base object"));
|
||||
}
|
||||
break;
|
||||
case ID_MB:
|
||||
if (self->object->type != OB_MBALL)
|
||||
{
|
||||
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
|
||||
"The 'link' object is incompatible with the base object"));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
|
||||
"Linking this object type is not supported"));
|
||||
|
||||
@@ -5,12 +5,19 @@ The Blender.Metaball submodule
|
||||
|
||||
This module provides access to the B{Metaball Data} in Blender.
|
||||
|
||||
Example::
|
||||
import Blender
|
||||
scene = Blender.Scene.getCurrent () # get the current scene
|
||||
ob = Blender.Metaball.New ('mball') # make metaball
|
||||
Example:
|
||||
import Blender
|
||||
|
||||
ob = Blender.Object.New("Mball","mb")
|
||||
mb = Blender.Metaball.New()
|
||||
for i in range(20):
|
||||
mb.addMetaelem([0, float(i),1.0,1.0, 2.0,1,2.0,1.0,1.0,1.0])
|
||||
ob.link(mb)
|
||||
sc = Blender.Scene.getCurrent()
|
||||
sc.link(ob)
|
||||
"""
|
||||
|
||||
|
||||
def New (name):
|
||||
"""
|
||||
Creates a new Metaball.
|
||||
@@ -42,7 +49,31 @@ class Metaball:
|
||||
@cvar rot: The rotation of the metaball.
|
||||
@cvar size: The size of the metaball.
|
||||
"""
|
||||
def addMetaelem(paramslist):
|
||||
"""
|
||||
Sets the name of a metaball object
|
||||
@type name: list
|
||||
@param name : the list of the parameters for creating a new metaelem
|
||||
This list has ten elements :
|
||||
param 1 : int : metaelem type
|
||||
0 for a sphere
|
||||
1 for a tubex
|
||||
2 for a tubey
|
||||
3 for a tubez
|
||||
4 for a regular tube
|
||||
5 for a plane
|
||||
6 for an ellipsoid
|
||||
7 for a cube
|
||||
params 2,3,4 : floats, the x, y and z coordinates of the metaelem
|
||||
param 5 : float, the rad value of the metaelem
|
||||
param 6 : int, the lay value.
|
||||
param 7 : float the s value of the metaelem
|
||||
params 8,9,10 : the expx, expy and expz values of the metaelem.
|
||||
|
||||
@rtype: PyNone
|
||||
@return: PyNone
|
||||
"""
|
||||
|
||||
def getName():
|
||||
"""
|
||||
Retreives the name of a metaball object
|
||||
|
||||
Reference in New Issue
Block a user