[Closed] SDK: get all nodes that a node is dependent upon?
I have a node that is dependent on some other nodes. For example, its parent node, the bones in its skin modifier, etc.
Is there a quick way to get a collection of all those nodes?
I know that you can get the nodes that depends on a particular ref, but can you get the nodes that a ref is dependent upon? Basically the inverse of MXS “refs.dependentnodes”…
The practical example would be:
I have 5 skinned characters, each with their own independent skeleton. I want to loop through each character and invalidate the TMs of ONLY the bones that drive the skin of that particular character. Ideally I don’t want to have to loop through all objects in the scene and test if my skin depends on them. Just grabbing the bones out of the skin modifier won’t work, because they might have their own dependencies that I also need to invalidate.
Just guessing… but what about the class ReferenceMaker which has methods for accessing references?
it’s refs.dependson. the code is in the sdk. you need just slightly modify it to collect only nodes instead of any animatables
Hmm…maybe I’m missing something…I need a function that gets all possible node dependencies…but if I parent obj002 to obj001 and run “refs.dependson obj002”, obj001 doesn’t show up in the list. Even if obj002 is skinned to obj001, obj001 only shows up in a ‘dependson’ test when I specifically run it on the skin modifier…
Any way to do something like ‘refs.dependson node’ that returns all nodes it and its modifiers and controllers are dependent on?
Ok, I’ve got a quick and dirty version working in maxscript just by using some recursion. Won’t be hard to implement in the SDK. Maybe denisT sees some ways to optimize this script version?
fn depends obj theArr=
(
deps = refs.dependson obj
if isvalidnode obj then
(
parent = obj.parent
if parent != undefined then (appendifunique theArr parent)
)
for d in deps do
(
if isvalidnode d then (appendifunique theArr d)
depends d theArr
)
theArr
)
print (depends $ #())
in your case it probably should be a combination of ‘reference’ dependency(#1) and ‘hierarchy’ dependency(#2).
to find all #1 you have to call refs.dependson recursively.
to find all #2 you have to find all ancestors of this node…
but some of ancestors can have ‘reference’ dependency to something else… so i think that it will be easier to do TestForLoop for your animatable and all other (nodes, controls, whatever).
no. i was not a good idea
delete objects
for k=1 to 10000 do point()
gc()
(
t = timestamp()
h = heapfree
for k=1 to objects.count do
(
refs.DependencyLoopTest objects[1] objects[k]
)
format "time:% heap:%
" (timestamp() - t) (h - heapfree)
)
time:968 heap:640120L
it seems like easier and faster to update all nodes than find which ones have to be updated
And this?
(
st = timestamp(); sh = heapfree
objs = objects as array
for k = 2 to objs.count do refs.DependencyLoopTest objs[1] objs[k]
format "time:% ram:%
" (timestamp()-st) (sh-heapfree)
)
time:47 ram:2020696L
Or this:
(
st = timestamp(); sh = heapfree
obj = objects[1]
for k in objects do refs.DependencyLoopTest obj k
format "time:% ram:%
" (timestamp()-st) (sh-heapfree)
)
time:51 ram:2020752L
Of course! i’ve remembered that objects[n] is very slow mapping. i have a post about it on this forum
delete objects
for k=1 to 10000 do point()
gc()
(
t = timestamp()
h = heapfree
n0 = objects[1]
refs_DependencyLoopTest = refs.DependencyLoopTest
for obj in objects do
(
refs_DependencyLoopTest n0 obj
)
format "time:% heap:%
" (timestamp() - t) (h - heapfree)
)
time:25 heap:184L
i have to make a mxs extension of this method. it sounds like it has to be quick. and it’s pretty useful if it doesn’t take any time.