Notifications
Clear all

[Closed] Instanced objects

Hi!

How can I find out if a scene node is an instance of another node?

Didn’t find an explanation in the MaxScript help (only the other way using InstanceMgr.GetInstances tp2 &instances)

Could anyone help me?

Thanks,
Christian

4 Replies
1 Reply
(@bobo)
Joined: 11 months ago

Posts: 0

What do you mean with “the other way” ?
Isn’t it the right method for what you are trying to do?
It returns the instances of the node you pass as argument in the by-reference array &instances.

But it will return both instances and references, so you might want to compare the modifier stacks to remove references.

The “other” way would be by using refs.dependents and passing the base object to it, then filtering out the nodes that depend on the base object and find out which have identical modifier stack, too…

I think the InstanceMgr.GetInstances method is easier…

if I create a box and clone it as an instance to another box, then InstanceMgr.GetInstances will give the same result for both boxes:

$Box:Quader02 @ [82.017746,0.000001,-15.392983]
 $Box:Quader01 @ [-26.213573,0.000001,-15.392983]

The refs.dependents function returns something like

#(ReferenceTarget:NodeSelection, ReferenceTarget:Animatable, ReferenceTarget:Animatable)

for the first box and

#(ReferenceTarget:NodeSelection, ReferenceTarget:Animatable)

for the second.

I’m trying to write a function that returns the orgininal object an instance is created from, like:

fn GetSourceObject node = (
    // return the first node in the hierarchy that is not an instance
  )

This function should return Box01 when called with Box02 of the example.

1 Reply
(@bobo)
Joined: 11 months ago

Posts: 0

The instance manager will return both, because an instance means the SAME object exists in the pipelines of two nodes, so it returns both nodes.

If you say
refs.dependents $Box01.baseobject

you will get
#($Box:Box02 @ [59.572437,17.005667,0.000000], $Box:Box01 @ [-31.075291,17.005667,0.000000], ReferenceTarget:NodeSelection, ReferenceTarget:Animatable, ReferenceTarget:Animatable)

because the base object is reused by both nodes. You still would need to compare modifier stacks to make sure it is not a Reference.

You cannot tell which is the “original” and which is the “instanced” (unless you would rely on naming, or ordering of the scene database which could change if you parent/unparent either object). So there is no way to tell which was first – once again, an instance is the SAME object pipeline (incl. baseobject and modifier stack) running through two or more nodes. There is no master and clone, both are the SAME object appearing in the scene multiple times.

This is why

$Box01.baseobject == $Box02.baseobject
–>true

(This is yet another way to detect instances and references – just loop through the scene and see who has the same baseobject, then deal with the stack if you want to throw away references and keep only “real” instances).

The only problem here is that a reference with no additional modifiers is essentially the same as the instance root, the difference being it has the potential to be different. Is there really no way to check if it is a reference?