[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [15656] trunk/blender/source/gameengine: GameObject functions getChildren() and getChildrenRecursive()

Campbell Barton ideasman42 at gmail.com
Sun Jul 20 19:18:46 CEST 2008


Revision: 15656
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=15656
Author:   campbellbarton
Date:     2008-07-20 19:18:46 +0200 (Sun, 20 Jul 2008)

Log Message:
-----------
GameObject functions getChildren() and getChildrenRecursive()

Modified Paths:
--------------
    trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp
    trunk/blender/source/gameengine/Ketsji/KX_GameObject.h
    trunk/blender/source/gameengine/PyDoc/KX_GameObject.py

Modified: trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp	2008-07-20 16:35:21 UTC (rev 15655)
+++ trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp	2008-07-20 17:18:46 UTC (rev 15656)
@@ -886,6 +886,8 @@
 	{"getParent", (PyCFunction)KX_GameObject::sPyGetParent,METH_NOARGS},
 	{"setParent", (PyCFunction)KX_GameObject::sPySetParent,METH_O},
 	{"removeParent", (PyCFunction)KX_GameObject::sPyRemoveParent,METH_NOARGS},
+	{"getChildren", (PyCFunction)KX_GameObject::sPyGetChildren,METH_NOARGS},
+	{"getChildrenRecursive", (PyCFunction)KX_GameObject::sPyGetChildrenRecursive,METH_NOARGS},
 	{"getMesh", (PyCFunction)KX_GameObject::sPyGetMesh,METH_VARARGS},
 	{"getPhysicsId", (PyCFunction)KX_GameObject::sPyGetPhysicsId,METH_NOARGS},
 	{"getPropertyNames", (PyCFunction)KX_GameObject::sPyGetPropertyNames,METH_NOARGS},
@@ -1303,6 +1305,43 @@
 	Py_RETURN_NONE;
 }
 
+
+static void walk_children(SG_Node* node, PyObject *list, bool recursive)
+{
+	NodeList& children = node->GetSGChildren();
+
+	for (NodeList::iterator childit = children.begin();!(childit==children.end());++childit)
+	{
+		SG_Node* childnode = (*childit);
+		KX_GameObject* childobj = (KX_GameObject*)childnode->GetSGClientObject();
+		if (childobj != NULL) // This is a GameObject
+		{
+			// add to the list
+			PyList_Append(list, (PyObject *)childobj);
+		}
+		
+		// if the childobj is NULL then this may be an inverse parent link
+		// so a non recursive search should still look down this node.
+		if (recursive || childobj==NULL) {
+			walk_children(childnode, list, recursive);
+		}
+	}
+}
+
+PyObject* KX_GameObject::PyGetChildren(PyObject* self)
+{
+	PyObject * list = PyList_New(0);
+	walk_children(m_pSGNode, list, 0);
+	return list;
+}
+
+PyObject* KX_GameObject::PyGetChildrenRecursive(PyObject* self)
+{
+	PyObject * list = PyList_New(0);
+	walk_children(m_pSGNode, list, 1);
+	return list;
+}
+
 PyObject* KX_GameObject::PyGetMesh(PyObject* self, 
 								   PyObject* args, 
 								   PyObject* kwds)

Modified: trunk/blender/source/gameengine/Ketsji/KX_GameObject.h
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_GameObject.h	2008-07-20 16:35:21 UTC (rev 15655)
+++ trunk/blender/source/gameengine/Ketsji/KX_GameObject.h	2008-07-20 17:18:46 UTC (rev 15656)
@@ -746,6 +746,8 @@
 	KX_PYMETHOD_NOARGS(KX_GameObject,GetParent);
 	KX_PYMETHOD_O(KX_GameObject,SetParent);
 	KX_PYMETHOD_NOARGS(KX_GameObject,RemoveParent);
+	KX_PYMETHOD_NOARGS(KX_GameObject,GetChildren);	
+	KX_PYMETHOD_NOARGS(KX_GameObject,GetChildrenRecursive);
 	KX_PYMETHOD(KX_GameObject,GetMesh);
 	KX_PYMETHOD_NOARGS(KX_GameObject,GetPhysicsId);
 	KX_PYMETHOD_NOARGS(KX_GameObject,GetPropertyNames);

Modified: trunk/blender/source/gameengine/PyDoc/KX_GameObject.py
===================================================================
--- trunk/blender/source/gameengine/PyDoc/KX_GameObject.py	2008-07-20 16:35:21 UTC (rev 15655)
+++ trunk/blender/source/gameengine/PyDoc/KX_GameObject.py	2008-07-20 17:18:46 UTC (rev 15656)
@@ -214,6 +214,18 @@
 		"""
 		Removes this objects parent.
 		"""
+	def getChildren():
+		"""
+		Return a list of immediate children of this object.
+		@rtype: list
+		@return: a list of all this objects children.
+		"""
+	def getChildrenRecursive():
+		"""
+		Return a list of children of this object, including all their childrens children.
+		@rtype: list
+		@return: a list of all this objects children recursivly.
+		"""
 	def getMesh(mesh):
 		"""
 		Gets the mesh object for this object.





More information about the Bf-blender-cvs mailing list