Node added signal
Hi.
I'm looking for information about the chain of events triggered in Studio when a node is added.
There is a nodeAdded() signal in DzScene but that signal is emitted at the beginning of the procedure. In the case of a figure, the signal is emitted and then Studio starts adding nodes to it. This makes it hard to use for running tasks that depend on the figure being ready and complete.
In addition, when using the Auto-fit plugin it seems that the scene hierarchy is transformed substantially. First the clothing is added as a figure and then it's converted and the series of objects connected to it changes. This is at least how I figured it out.
Is there a way of receiving signals when a node is completely added to the scene? In other words, when the operation of adding it is completed?
Thanks in advance.
Comments
You'll want to connect to DzScene::sceneLoadStarting() and use it to increment an int member, to keep count of how many loads are in progress. You'll also want to connect to DzScene::sceneLoaded() and use it to decrement the int member, to keep count of how many loads need to finish... blocking against the posting of a custom event until the count reaches 0 (more on that in a moment), and against more than one event in the stack at a time. You'll also want to connect to DzScene::nodeAdded() and DzScene::aboutToRemoveNode() so that you can capture/maintain a DzNodeList while the scene is busy loading. Once the loading is finished (i.e. the int member reaches 0), post a custom event - to allow any remaining events before it to be processed. Then, in your event handler, process the list of DzNode you've collected.
-Rob
Hi Rob.
Thank you very much for the detailed explanation and code mock-up, it's very much appreciated.
This is an interesting logic. I have already connections to the sceneLoadStarting() and other signals to handle the merging of scenes. This is an interesting "wrinkle" to explore.
Does this system work also for .CR2 and for things like the Studio primitives (Cube, Torus etc.)?
Thanks again.
One more question.
Your suggestion to use a counter implies that there loads can be nested. Can you provide an example of when that happens?
Also, I tested the method with CR2s (V4) and it works but it doe not work with the primitives.
Cheers.
Hi Rob.
Just wanted to let you know that your suggestion worked perfectly. The primitives will have to be handled via the nodeAdded() signal but that is not an issue.
Thanks again.