Parent/Child searches in a model

Blitz3D Forums/Blitz3D Beginners Area/Parent/Child searches in a model

CodeOrc(Posted 2006) [#1]
Hi all,

How do I find the names of all the "child" components in a .b3d model?


Beaker(Posted 2006) [#2]
Adapt my code from the archive to this:
alien = LoadAnimMesh("alien.b3d")

ent = alien
While ent
	DebugLog EntityName(ent)
	ent = NextChild(ent)
Wend


Function NextChild(ent)
	If CountChildren(ent)>0
		Return GetChild(ent,1)
	EndIf

	Local foundunused=False
	Local foundent = 0, parent,sibling
	While foundunused=False And ent<>0
		parent = GetParent(ent)
		If parent<>0
			If CountChildren(parent)>1
				If GetChild(parent,CountChildren(parent))<>ent
					For siblingcnt = 1 To CountChildren(parent)
						sibling = GetChild(parent,siblingcnt)
						If sibling=ent
							foundunused = True
							foundent = GetChild(parent,siblingcnt+1)
						EndIf
					Next
				EndIf
			EndIf
		EndIf
		ent = parent
	Wend
	Return foundent
End Function

There are other ways, but I like mine.


CodeOrc(Posted 2006) [#3]
thank you, it works great !


puki(Posted 2006) [#4]
For anyone who tries this and runs into problems - if you are using a static mesh (ie no animations) still use 'LoadAnimMesh' as opposed to 'LoadMesh'.

I mention this as I initially didn't realise this until I solved it with logic.


markcw(Posted 2006) [#5]
thanks puki.

i tried this in order to use: getsurface(mesh,1)
but i couldn't figure it out so i gave up and started something else.