Notifications
Clear all

[Closed] Need help with hierarchy

Hello I need to figure out a way to make 4 arrays which consist of Parent, Child, Next, and Previous mesh.

Currently the way my script works things is that it captures meshes and other data in this node “Layers”. They get sorted in there so when mesh is exported it should get sorted the same way that the arrays would be if they were made inside this code.

Parent_array=#()
Child_array=#()
Next_array=#()
Previous_array=#()
mcount=-1

clearlistener()
for i = 1 to LayerManager.count-1 do(
	(LayerManager.getlayer i).nodes &nodes
	for n in nodes do(
		if superclassof n == geometryclass do(
			mcount=mcount+1
                        print mcount
                        print n
		)
	)
)

so in the if superclass of n == geometryclass do thats where I need to make these arrays. A deeper explanation of each array would be that obviously Parent would be the current meshes parent mesh, Child would be same but Child mesh, Next would be mesh that is in the same scene level as the current mesh “this should only be counted once if there is another mesh on the same scene level as in the first mesh read then the next mesh should be read on the next mesh” and previous mesh works the same as next but previous.

Here is a visual sample of what I mean to further simplify things.

Take note that the sorting of the objects will probably be based on what the script loads first and not that of the diagram but the parent,child,next,previous SHOULD be exactly like that if the array was created in that order. Now the problem with this is that I do not need ANSII but instead numerical values which is where “mcount=mcount+1” comes into play, if you print mcount and n inside superclass of n == geometryclass do you can see what current object is being loaded first and its numerical value if you have mesh in your scene.

3 Replies

It’s unclear what you are trying to do and what the problem is.

Your chart does not accurately reflect what the hierarchy really is in the diagram.
for example object 8 lists parent as “undefined” in the chart but the parent of object8 in the diagram is object 1.

why would you NOT just export the hierarchy from the top node down?

never the less:

--make objects 1-8
for i = 1 to 8 do
(
	local obj=box()
	obj.name="object"+i as string
	obj.pos.x=i*50
)

--arrange heirarchy per diagram
$object7.parent=$object8.parent=$object1
$object2.parent=$object4.parent=$object7
$object3.parent=$object5.parent=$object6.parent=$object8

--fn to fill table
fn familyTable obj=(
	parent = obj.parent
	child= obj.children[1]
	if parent !=undefined then (
		siblings= obj.parent.children 
		if siblings !=undefined then (
			index= finditem siblings obj
			prev= try(siblings[index-1])catch(undefined)
			next= try(siblings[index+1])catch(undefined)
		)
	)
	format "	object: %
	parent: %
	child: %
	prev:%
	 next:%
" obj parent child prev next
)

--fill table 
for each in $object* do
(
	format "%
" each.name
	familyTable each
)

the reason why object8 does not include the parent is because its next on the list from object7 which already includes the parent IDK why but the game im making this script for does it in this way. I will look at this script tomorrow thanks for the reply I might try to figure out a better way to explain it I know its vague.

I think I understand. The previous /next thing is how some code handles arrays.

All I did was use existing Max .children and .parent functions to ‘look up” the values in your table.

for obj,
parent = obj.parent
child= obj.children[1] (first child in the array)
previous & next require us to find the index of obj within the array obj.parent.children, then
prev= obj.parent.children[index-1]
next =obj.parent.children[ index +1]

if .parent or .children is undefined,
or the index+/-1 values exceed the array bounds,
the code would break, so I added checks for that.