Friday, April 5, 2013

Deleting objects in motionbuilder




I am working more and more with motionbuilder and one recent challenge involved dealing with

"referencing"* rigs. One of the biggest challenges here was to "de-ref"* an entire rig, which means I have to delete a large number of objects.

Sounds simple right? Unfortunately simple things are never easy in motionbuilder. 


The reason is because there are dependencies between different objects, that are not properly garbagecollected. Thats bad, hence the crash.

Here is a solution that you should not be proud of, but it works. The key is to delete objects by their type in a very specific order.

* There is no real referencing in motionbuilder :)













16 comments:

  1. Good to know. I've had to do very similar things in maxscript when deleting objects with script controllers that had node references. Thanks for sharing!

    ReplyDelete
  2. This is an awesome script. I've recently been exposed to functional programming, so I couldn't resist the urge to rewrite it in a different style: https://gist.github.com/awforsythe/5322163

    ReplyDelete
  3. Awesome Alex, I love it!! Lambda is something I barely use, mostly because I cant quite identify areas to use it. This helped me understand it a lot,so thanks, very inspiring!

    ReplyDelete
  4. Hi Marcus,

    what do you mean by referencing rigs in mobu?
    Does 2013 allow you to reference from other fbx scenes?

    It did not find any time looking into mobu 2013 yet, but if referencing is allowed it makes live a lot easier, especially for environment sets. :)

    ReplyDelete
    Replies
    1. Hey Chris,

      There is not real referencing, but by having a node in your scene that holds a reference to all objects in the scene, you can sort of get the behaviour of referencing. I might actually do a post on this in the future, if there is an interest.

      Delete
  5. Thanks for sharing that :-)

    "Unfortunately simple things are never easy in Motionbuilder"

    Too true!

    I wrote about the same script a year or two ago (figuring out the node type deleting order and such). However I quickly realized that while deleting a character from a one character scene would take about 40 seconds, deleting a character out of a cinema scene with 3 characters (with custom face rigging) and some background geo, the "delete" process was still running 40 minutes later (for 1 character!)…

    I talked to subscription about this and the answer was: “deleting objects with the SDK is currently a challenge”. This was on MotionBuilder 2011 advantage pack, so this might have changed for the newer versions. However unless you have already done this, I would torture test this before committing to it as a long term solution.

    Wanting “referencing” is obvious, especially if you have a Maya background. But most old hand MotionBuilder people I have met have a “scene re-building” workflow, meaning they save out all animation, then re-build the scene with fresh assets and apply the animation. I heard one of the Crytek studios have scripts for doing exactly this for their cinemas (you might know?). So that might be an alternative solution.

    I would love to know if the solution scales well for large scene, or if that’s still an issue?

    Cheers,
    Sune

    ReplyDelete
    Replies
    1. I tested this with a few characters in a scene and it worked fine, Ill give this a test run with a lot more characters soon. Btw, in 2013 you have a function called NamespaceDelete() which was supposed to fix this, but I still have to use my own function to do that

      Delete
  6. For what it's worth, it looks like MotionBuilder 2014 SDK adds support for actual referencing of FBX files: http://autode.sk/14QpYd7

    ReplyDelete
    Replies
    1. Yeah, I've seen a demo of it, and it seems like unfortunately it doesn't support characters

      Delete
    2. Actually it does support characters, but in all fairness, not very gracefully. There r still some limitations and I haven't been as involved in the beta testing as I had initially hoped. Anyway, the "work around" (ever heard that word used? *sarcasm*) is to reference a file that only contains the skinned mesh & the skeleton (no rig or characterization) into a file that contains a duplicate of the same hierarchy which IS characterized. Parent constrain each joint to its correlating joint of each hierarchy (like a slave skeleton). Proper namespacing of each skeletal hierarchy is your friend. Any updates to the mesh will be reflected, updated & remain current. There are some caveats regarding changes to the hierarchy of the referenced skeleton & mesh, contrary to the documentation when dealing with hierarchies of the complexity, but still gets the job done.

      Delete
    3. Good tips there, Jason! Thanks!

      Delete
  7. I'm happy to report that removing a character from a dense scene with your code, is down from "Not going to happen" to around 3 minutes - still in MoBu 2011. I'm assuming it's the specific order that things are removed in that makes the difference. Now I just need to get rid of those pesky pop-ups related to relation constraint macros.

    Cheers,
    Sune

    ReplyDelete
  8. for node in FBSystem().Scene.Constraints:
    if ( myName in node.LongName ):
    myList.append(node)

    # Delete them pesky boxes
    if isinstance(node, FBConstraintRelation):
    while len(node.Boxes) > 0:
    map(FBComponent.FBDelete, node.Boxes)

    map( FBComponent.FBDelete, myList )

    ReplyDelete
  9. Just discovered this:

    FBSystem().Scene.NamespaceDeleteContent('MyNamespace', FBPlugModificationFlag.kFBPlugAllContent, True)

    Fast and easy and seems to work well.

    ReplyDelete
    Replies
    1. Wow, it does work. Thanks for sharing Sune!

      Delete
  10. Hi Marcus,

    I would be interested in finding out about your referencing work around. If you have time to post, that would be awesome!

    Thanks

    ReplyDelete