diff options
author | Campbell Barton <ideasman42@gmail.com> | 2008-06-04 20:19:15 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2008-06-04 20:19:15 +0400 |
commit | e26323bcdd89f992ab772cb8860502e2bfe2e681 (patch) | |
tree | 894fba604a6c3b19156eae4ca00469c688b5817f /source/blender/python | |
parent | d565e8a02f94e61fbebcfbcdcef1f547b4e6b65b (diff) |
Python API object.parentVertexIndex - access vertex parent indicies
Diffstat (limited to 'source/blender/python')
-rw-r--r-- | source/blender/python/api2_2x/Object.c | 92 | ||||
-rw-r--r-- | source/blender/python/api2_2x/doc/Object.py | 2 |
2 files changed, 94 insertions, 0 deletions
diff --git a/source/blender/python/api2_2x/Object.c b/source/blender/python/api2_2x/Object.c index 1a806932bdb..3db9664d47d 100644 --- a/source/blender/python/api2_2x/Object.c +++ b/source/blender/python/api2_2x/Object.c @@ -360,6 +360,8 @@ static PyObject *Object_getMatrix( BPy_Object * self, PyObject * args ); static PyObject *Object_getParent( BPy_Object * self ); static PyObject *Object_getParentBoneName( BPy_Object * self ); static int Object_setParentBoneName( BPy_Object * self, PyObject * value ); +static PyObject *Object_getParentVertexIndex( BPy_Object * self ); +static int Object_setParentVertexIndex( BPy_Object * self, PyObject * value ); static PyObject *Object_getSize( BPy_Object * self, PyObject * args ); static PyObject *Object_getTimeOffset( BPy_Object * self ); static PyObject *Object_getTracked( BPy_Object * self ); @@ -1491,6 +1493,92 @@ static int Object_setParentBoneName( BPy_Object * self, PyObject *value ) return 0; } +static PyObject *Object_getParentVertexIndex( BPy_Object * self ) +{ + PyObject *pyls = NULL; + + if( self->object->parent) { + if (self->object->partype==PARVERT1) { + pyls = PyList_New(1); + PyList_SET_ITEM( pyls, 0, PyInt_FromLong( self->object->par1 )); + return pyls; + } else if (self->object->partype==PARVERT3) { + pyls = PyList_New(3); + PyList_SET_ITEM( pyls, 0, PyInt_FromLong( self->object->par1 )); + PyList_SET_ITEM( pyls, 1, PyInt_FromLong( self->object->par2 )); + PyList_SET_ITEM( pyls, 2, PyInt_FromLong( self->object->par3 )); + return pyls; + } + } + return PyList_New(0); +} + +static int Object_setParentVertexIndex( BPy_Object * self, PyObject *value ) +{ + PyObject *item; + int val[3] = {0,0,0}; + if( !self->object->parent) { + return EXPP_ReturnIntError( PyExc_RuntimeError, + "This object has no vertex parent, cant set the vertex parent indicies" ); + } + if (self->object->partype==PARVERT1) { + if (PySequence_Length(value) != 1) + return EXPP_ReturnIntError( PyExc_RuntimeError, + "Vertex parented to 1 vertex, can only assign a sequence with 1 vertex parent index" ); + item = PySequence_GetItem(value, 0); + if (item) { + val[0] = PyInt_AsLong(item); + Py_DECREF(item); + } + } else if (self->object->partype==PARVERT3) { + int i; + if (PySequence_Length(value) != 3) + return EXPP_ReturnIntError( PyExc_RuntimeError, + "Vertex parented to 3 verts, can only assign a sequence with 3 verts parent index" ); + + for (i=0; i<3; i++) { + item = PySequence_GetItem(value, i); + if (item) { + val[i] = PyInt_AsLong(item); + Py_DECREF(item); + } + } + } else { + return EXPP_ReturnIntError( PyExc_RuntimeError, + "This object has no vertex parent, cant set the vertex parent indicies" ); + } + + if (PyErr_Occurred()) { + return EXPP_ReturnIntError( PyExc_RuntimeError, + "This object has no vertex parent, cant set the vertex parent indicies" ); + } else { + if (self->object->partype==PARVERT1) { + if (val[0] < 0) { + return EXPP_ReturnIntError( PyExc_RuntimeError, + "vertex index less then zero" ); + } + + self->object->par1 = val[0]; + } else if (self->object->partype==PARVERT3) { + if (val[0]==val[1] || val[0]==val[2] || val[1]==val[2]) { + return EXPP_ReturnIntError( PyExc_RuntimeError, + "duplicate indicies in vertex parent assignment" ); + } + if (val[0] < 0 || val[1] < 0 || val[2] < 0) { + return EXPP_ReturnIntError( PyExc_RuntimeError, + "vertex index less then zero" ); + } + + self->object->par1 = val[0]; + self->object->par2 = val[1]; + self->object->par3 = val[2]; + } + } + + return 0; +} + + static PyObject *Object_getSize( BPy_Object * self, PyObject * args ) { char *space = "localspace"; /* default to local */ @@ -4916,6 +5004,10 @@ static PyGetSetDef BPy_Object_getseters[] = { (getter)Object_getParentBoneName, (setter)Object_setParentBoneName, "The object's parent object's sub name", NULL}, + {"parentVertexIndex", + (getter)Object_getParentVertexIndex, (setter)Object_setParentVertexIndex, + "Indicies used for vertex parents", + NULL}, {"track", (getter)Object_getTracked, (setter)Object_setTracked, "The object's tracked object", diff --git a/source/blender/python/api2_2x/doc/Object.py b/source/blender/python/api2_2x/doc/Object.py index 09167c0e117..2e4850aeb14 100644 --- a/source/blender/python/api2_2x/doc/Object.py +++ b/source/blender/python/api2_2x/doc/Object.py @@ -389,6 +389,8 @@ class Object: @ivar parentbonename: The string name of the parent bone (if defined). This can be set to another bone in the armature if the object already has a bone parent. @type parentbonename: string or None + @ivar parentVertexIndex: A list of vertex parent indicies, with a length of 0, 1 or 3. When there are 1 or 3 vertex parents, the indicies can be assigned to a sequence of the same length. + @type parentVertexIndex: list @ivar protectFlags: The "transform locking" bitfield flags for the object. See L{ProtectFlags} const dict for values. @type protectFlags: int |