How do I record solver data using Python?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
We're trying to use MB in our pipeline to drive certain physics related animation.
For instance, an enemy drops their weapon at a particular frame when it's parented to a joint for every frame before that moment. In our custom tools, we mark the frame that the weapon should drop and we re-process the FBX in our MB pipeline. The goal is to switch from the parented bone animation to the simulated drop of the weapon at a particular frame.
I feel like I'm jumping through hoops trying to trick MB into doing what we need. I must be doing something wrong.
In order to make this work in our automated pipeline:
- I duplicate the weapon geometry at the drop frame
- I create a solver/body and connect all of the things
- I execute my_solver.evaluate_simulation(weapon_geo, start_fb_time, end_fb_time)
Of course that third step doesn't work because there is no such function on solvers.
Instead, my third step looks something like this:
- FBSystem().Scene.Evaluate()
- player.DeleteAllGlobalTimeMarks()
- mark_index = self.player.AddGlobalTimeMark(FBTime( 0, 0, 0, self.end_frame))
- player.SetGlobalTimeMarkAction(mark_index, FBTimeMarkAction.kFBTimeMarkAction_Stop)
- select(self.weapon_dummy)
- player.LoopActive = True
- solver.Active = True'
- solver.Live = True
- player.Play(True)
- player.Record(True)
- FBSystem().Scene.Evaluate()
- FBSleep(1000)
- while player.IsPlaying:
- FBSleep(500)
- FBSystem().Scene.Evaluate()
- solver.Active = False
- solver.Live = False
- player.DeleteAllGlobalTimeMarks()
- FBSystem().Scene.Evaluate()
While this does technically bake some keys to the default animation layer (not the selected or active one, for some reason), it completely breaks everything afterwards. I can't do anything else in Python because the main thread never evaluates anything until my Python script has terminated.
I have tried an embarrassing number of hacks to try and get this to work. I even tried saving the file and opening it once the timeline stops play. But, alas, the baked keys don't exist in the saved file because MB never seems to re-evaluate after my Play() call.
What am I doing wrong?
Certainly there is some better way to bake simulation data, right?
I am delirious, I assume this post isn't even clear. I'll provide more information if needed. I'll send gifts. Please help me.