Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorJoseph Gilbert <ascotan@gmail.com>2004-04-05 08:17:01 +0400
committerJoseph Gilbert <ascotan@gmail.com>2004-04-05 08:17:01 +0400
commit136b66c19f59a2d8b63521b442d73aa485eeafd3 (patch)
treec94b2314159ad291a1fac3e408c5f4cb3036d0a5 /source
parent09b19aead2842b904406c657b5444673c51910ad (diff)
- getBones() fixed - returns all armature bones including children
Diffstat (limited to 'source')
-rw-r--r--source/blender/python/api2_2x/Armature.c48
-rw-r--r--source/blender/python/api2_2x/Bone.c29
2 files changed, 40 insertions, 37 deletions
diff --git a/source/blender/python/api2_2x/Armature.c b/source/blender/python/api2_2x/Armature.c
index a5b24bcada5..b10fb6574d0 100644
--- a/source/blender/python/api2_2x/Armature.c
+++ b/source/blender/python/api2_2x/Armature.c
@@ -314,29 +314,37 @@ Armature_getName (BPy_Armature * self)
}
-/** Create and return a list of the root bones for this armature. */
+static void
+append_childrenToList(Bone *parent, PyObject *listbones)
+{
+ Bone *child = NULL;
+
+ //append children
+ for(child = parent->childbase.first; child; child = child->next){
+ PyList_Append (listbones, Bone_CreatePyObject (child));
+ if(child->childbase.first){ //has children?
+ append_childrenToList(child, listbones);
+ }
+ }
+
+}
+
static PyObject *
Armature_getBones (BPy_Armature * self)
{
- int totbones = 0;
+
PyObject *listbones = 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++;
-
- /* 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;
- }
+ Bone *parent = NULL;
+
+ listbones = PyList_New(0);
+
+ //append root bones
+ for (parent = self->armature->bonebase.first; parent; parent = parent->next){
+ PyList_Append (listbones, Bone_CreatePyObject (parent));
+ if(parent->childbase.first){ //has children?
+ append_childrenToList(parent, listbones);
+ }
+ }
return listbones;
}
@@ -525,8 +533,6 @@ Armature_setAttr (BPy_Armature * self, char *name, PyObject * value)
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);
diff --git a/source/blender/python/api2_2x/Bone.c b/source/blender/python/api2_2x/Bone.c
index e5484b738ed..faf60a30338 100644
--- a/source/blender/python/api2_2x/Bone.c
+++ b/source/blender/python/api2_2x/Bone.c
@@ -653,9 +653,9 @@ Bone_setParent(BPy_Bone *self, PyObject *args)
}
/*****************************************************************************/
-/* Function: Bone_dealloc */
+/* Function: Bone_dealloc */
/* Description: This is a callback function for the BPy_Bone type. It is */
-/* the destructor function. */
+/* the destructor function. */
/*****************************************************************************/
static void
Bone_dealloc (BPy_Bone * self)
@@ -665,7 +665,7 @@ Bone_dealloc (BPy_Bone * self)
}
/*****************************************************************************/
-/* Function: Bone_getAttr */
+/* 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. */
@@ -714,7 +714,7 @@ Bone_getAttr (BPy_Bone * self, char *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. */
@@ -751,7 +751,7 @@ Bone_setAttr (BPy_Bone * self, char *name, PyObject * value)
}
/*****************************************************************************/
-/* Function: Bone_repr */
+/* Function: Bone_repr */
/* Description: This is a callback function for the BPy_Bone type. It */
/* builds a meaninful string to represent bone objects. */
/*****************************************************************************/
@@ -765,10 +765,10 @@ Bone_repr (BPy_Bone * self)
}
/**************************************************************************/
-/* Function: Bone_compare */
+/* 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. */
+/* C pointers. */
/**************************************************************************/
static int
Bone_compare (BPy_Bone * a, BPy_Bone * b)
@@ -777,13 +777,10 @@ Bone_compare (BPy_Bone * a, BPy_Bone * b)
return (pa == pb) ? 0 : -1;
}
-
-
-
/*****************************************************************************/
-/* Function: Bone_CreatePyObject */
+/* Function: Bone_CreatePyObject */
/* Description: This function will create a new BlenBone from an existing */
-/* Bone structure. */
+/* Bone structure. */
/*****************************************************************************/
PyObject *
Bone_CreatePyObject (struct Bone * obj)
@@ -801,9 +798,9 @@ Bone_CreatePyObject (struct Bone * obj)
}
/*****************************************************************************/
-/* 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)
@@ -812,9 +809,9 @@ Bone_CheckPyObject (PyObject * py_obj)
}
/*****************************************************************************/
-/* Function: Bone_FromPyObject */
+/* Function: Bone_FromPyObject */
/* Description: This function returns the Blender bone from the given */
-/* PyObject. */
+/* PyObject. */
/*****************************************************************************/
struct Bone *
Bone_FromPyObject (PyObject * py_obj)