Blender to Apple Motion export script

Hello Andrew and good day! I hope all is well in Scotland.

I am sad to inform you that it seems I might have found a bug. But I could be wrong.

The animation was created with lots of rotations. But when I open it up in Motion 5 it crashes as soon as click on any layer group that has complete rotations in the animation.

It was discovered that if I delete the keyframes before the rotate completes inside of Blender I do not get a crash. I then was able to manually add in keyframes in Motion, but I thought you may want to know about this as recreating the animation is not easy. :slight_smile:

I will PM you the Blender file.

Thank you for all the great work go0d sir! Please let me know if there is anything you may need and have an amazing day! :slight_smile:

Hi, thanks for your testing on the script. If the crash is happening due to Motion, I might not be able to fix it but I’ll have a look. One thing to try would be to open the exported file first, save out the .motion file, close it (maybe even quit Motion after saving) and reopen it and then try clicking the layer. The exported file from Blender is reverse-engineered as Motion doesn’t have an API for importing data as far as I know and when Motion saves the file out, it generates extra data.

I added some things to the script a while ago so that it could be bundled with Blender if needs be but haven’t uploaded it. I added some GPL text to it and code to make it work like a plugin/extension. I then tried to integrate an Euler filter to correct the rotation flipping but I couldn’t figure out how to do it. The problem is that when you have inherited transforms, it flattens everything into the (-180,180) range, there’s no place that I can see where it can store a composite rotation for multiple turns. So if you have extreme rotations like multiple rotations within a single frame, even an Euler filter applied to individual frame keys isn’t going to get the correct output. I tried to come up with a way around this by doing sub-frame sampling to check if there was an extreme rotation happening but I still don’t think that would be reliable in all cases because it’s still flattening the transforms but it would at least let me know for example, that if the rotation at frame x is 30 degrees and it’s 80 degrees at frame x+0.1 then there’s an extreme rotation happening (500 degrees in one frame, almost 1.5 turns). I’m not sure how to then use that data throughout the whole sequence of keyframes as the modifications have to be applied right through the whole curve.

Maybe the following would work:
check rotation at whole frame x, e.g 30 degrees
check rotation at whole frame plus small enough increment to allow for fast rotation e.g frame x + 0.1 (maybe smaller) = 80 degrees
if (increment rotation minus whole frame rotation)/increment is enough to exceed (-180,180) then it will cause a flip e.g 80-30/0.1 = 500 degrees in 1 frame so next frame should in fact represent 530 degrees rather than what it will be reported as (170?).
This rotation count then needs to be stored and added to the next keyframe regardless of further flipping.

The other thing you mentioned about exporting cameras as layers should be possible to do. The reason for the single camera setup is because only the main camera is useful. If you render out a sequence of images, the other cameras are not useful as cameras. Is this perhaps a setup where the camera is being switched during the animation? If so, I might have to do more than just export the cameras as camera objects and actually change the setting on which is the active camera at which point in time. I can always have a switch to let you export them as camera objects or layers.

Hello Andrew and thank you such a quick reply. I hope all is well. :slight_smile:

I tried saving the Motion file and then closing the app and it still crashed. :frowning:

Be aware that I was able to get lucky with the last animation as the full rotations happened off camera and I deleted the off camera keyframes after I render for the Motion export. I only had to recreate 2 of the object rotations inside of Motion frame by frame. :slight_smile:

Please keep me posted on your progress.

Also, I could create a simple animation to do testing if you would like next week. Let me know how I can help.

Thank you very much for all your hard work and please let me know of how I can be of any assistance. Have an amazing day good sir and keep on rocking! :slight_smile:

I haven’t been able to get Motion 5 to crash with the test file you sent and clicking through all the animation curves. Do you have a crash log for Motion? It will be in the report button after it crashes.

I noticed that there were a lot of keyframes in the export that were very close together in value so I added a parameter to the script to round to a certain number of decimal places. Rounding to 4 decimals cuts out about half the keyframes so that might be a bit more stable. Hopefully it won’t affect the pixel accuracy of the render in Motion but it can be increased as needed.

The curve flipping is strange. I noticed a lot of discontinuities in the export but they happen at very odd places. Like one of the exports has a rotation of 69.8 degrees on one frame and the next, it flips to -96.9 degrees but if you add 180 to that, it’s 83.1 degrees, which I wouldn’t expect to flip because it’s within the (-180, 180) range. Also, one of the curves is supposed to start at 0 degrees but comes out -90 degrees.

That means the subframe test I was going to use won’t work because there’s no way to know when it will flip. I’ll just have to base it on the difference between one frame and the next. The reason I didn’t want to rely on that check is that I assume it would try to correct legitimate large rotation changes in a single frame but I guess that will be rare enough to not be a problem.

I’ll try and get the Euler filter correcting the animation curves soon. I changed the cameras to export as cameras but haven’t tested switching between active cameras. It doesn’t look like there’s a way to keyframe this very easily in Blender - it seems as though you add a marker and then link the cameras into the marker. I’d have expected the camera objects to have an isActive property that gets keyframed and when Blender interprets the first camera per frame that has that set, it turns all other cameras to inactive, which allows for overlapping keyframes. I’ll leave it alone for now. This can be done manually in Motion if necessary as long as the camera objects are exported as cameras.

Thank you Andrew for all your help. :slight_smile:

The camera export is not as important as we could always export different version for each camera as a workaround.

Here is the crash report you requested: https://cldup.com/mI9Tssgw4P.txt

Please let me know when you want me to test the new script. Do you add the link when you have a new one ready or do you replace the older links you have on this forum thread?

Also, please let me know what limitations the script has on rotations, so I do not get too crazy with it. :slight_smile:

Thank you for all your great work good sir and have an amazing day! :slight_smile:

That’s crashing here:

Thread 8 Crashed:: com.apple.helium.rq.gpu-ru0.vs0
0 com.apple.ozone.framework OZRigBehavior::solveNode(unsigned int, CMTime const&, double, double) + 132
1 com.apple.prochannel.framework OZCurve::getValue(CMTime const&, double) + 899
2 com.apple.prochannel.framework OZCurve::getPoint(CMTime const&, double, double*) + 23
3 com.apple.prochannel.framework OZChannel::getValueAsDouble(CMTime const&, double) const + 226
4 com.apple.motion.TextFramework TXSequenceBehavior::getSelectionValue(CMTime const&, double, OZChannel*, double) + 81
5 com.apple.motion.TextFramework TXSequenceCurveNode::solveNode(CMTime const&, double, double) + 190
6 com.apple.prochannel.framework OZCurve::getValue(CMTime const&, double) + 899
7 com.apple.prochannel.framework OZCurve::getPoint(CMTime const&, double, double*) + 23
8 com.apple.prochannel.framework OZChannel::getValueAsDouble(CMTime const&, double) const + 226
9 com.apple.motion.TextFramework TXTextObject::getTransformMatrix(PCMatrix44Tmpl<double>&, OZRenderParams const&, bool, bool, double, double, PCMatrix44Tmpl<double>) const + 1836
10 com.apple.motion.TextFramework TXTextLayout::getProjectedBounds(PCRect<double>
, PCMatrix44Tmpl<double> const&, OZRenderState const&) + 1603

It is mentioning text objects. Have you attached text items to any of the moving elements? If so, try removing them to see if those are what’s causing it to crash or if it’s happening with the Motion file as soon as you open it and click on things.

I’ll overwrite the old one when it’s tested and working ok but I’ll give you a test version. Here’s one without the Euler filter but with camera objects and with the rounded export values:

http://www.dev-art.co.uk/files/motion_test.zip

If you add multiple cameras, you need to make the render camera the top one in the scene list to become the active camera. For now, I’ve added the tag ‘(render)’ to the active camera name.

This is also formatted as a Blender addon now with the GPL text so it can be bundled with Blender. You can probably install it using the user prefs but what I do to make it easy to update is make a folder somewhere and set that as the scripts folder in user prefs. To update the script you just put the new script in the folder and then uncheck and recheck the addon.

I’m not sure what the limit would be but it probably can’t handle more than 1 full rotation in 1 frame. I was hoping there might be a way round that by doing subframe sampling but it just flips at random - I was trying to check for the composite angle flipping but it will map any of the transforms used in the composite to (-180,180) so there’s not really an easy way to check that. This is only important if you were doing something like post-production motion blur on something spinning really fast like a spinning top, car wheel or something like that. Say you added a logo to a spinning top, if it was rotating so fast that it did more than a single rotation in a frame, it would only be able to guess a single turn so the logo you added in Motion would be in the right place relative to the object but it wouldn’t be rotating fast enough and wouldn’t motion blur properly. This is pretty rare though and would only happen above about 1500 rpm and it can be corrected manually.

Hello Andrew and good day! :slight_smile:

It is mentioning text objects. Have you attached text items to any of the moving elements? If so, try removing them to see if those are what’s causing it to crash or if it’s happening with the Motion file as soon as you open it and click on things.

For this template I have not used any text objects. As of now I do not create any text in Blender since I want people to be able to customize and change text inside of Motion. The crash happens after I open motion and click on the layers that have a full rotation on them. Maybe when you opened it you were lucky and clicked on one of the layers that did not cause the crash. :slight_smile:

Here is an idea I wanted to test with the rotation is have a phone spin about 3 or 4 times towards the camera in about 2 seconds time. I have not used any motion blurs in the renders to save render time and because the drop zones in Motion would also have to match the motion blur of Blender. However I would love to bring some Motion Blurs into my renders for more realism.

I am wrapping up a new templates today ( I kept it simple ) I should be able to start testing out the test script tomorrow.

Thank you again for all your amazing work good sir! As always you rock! :slight_smile:

Hello Andrew.

I did a test with an object spinning a few times and the render looks great. Plus no crashes in Motion! :slight_smile:
The render was a rough draft and I just uploaded the file to the Render Cloud for a full render for full quality.

I will keep you posted as soon the video is ready. Thank you again for all your great work and have an amazing week! :slight_smile:

Hello Andrew and good day. Here is the link of the latest animation I made. I added extra rotations to test the new script. SO far so good. Plus the keyframes did not look so busy. :slight_smile:

Thank you and have an amazing day! :slight_smile:

That looks great. You’ve done a good job putting all your animations together. It really helps show off what people can do with compositing.

Thank you Andrew! :slight_smile:

I would like to eventually make a tutorial to help people make their own templates. However I would love it if you could help me out as I am sure I am doing some things wrong or there are easier ways to do it. :slight_smile:

I’d be happy to help put together a tutorial for it. A scene that lets you set up the colour pickers and adjust the colours of objects in post would be good as well as have overlays on top of content that’s inserted. The iPad one you made would be an example but it can be a new scene with a simpler model. The one with the photo frame and the cloth being pulled back was good but an animated reflection on top of the images that people insert.

We may have to break it up into a few parts though. Part one can be setting up in Blender and getting the script working and part 2 could be prepping up the alpha channels and rendering. Part 3 could be setting up inside of Motion.

I think we may want to do a super simple model. The cloth one looks cool but it dives into simulations and we may loose some people that are new to Blender.

Maybe we can create a simple model so people can follow along easier. and keep the render times low Something as simple as a beveled box.

I am not so strong in Blender since I do not use it as much as hope to another reason to keep it simple. :slight_smile:

Well this looks like fun, I want to play too :wink:

OS X Rules I sent you a PM.

Hello everyone I created a tutorial on how to use this amazing script:

More information here: http://deyson.com/learning/blender-to-motion-tutorial/

That’s a nice tutorial, thanks for doing that. I missed the PM, my internet has been out the past few days, hopefully that’s it sorted out.

I’ll try and get the script suitable for bundling with Blender so people don’t have to download it manually. I might need to develop a small UI to switch between some of the options like rounding accuracy to save people doing it in the script itself.

I had started working on the Euler filter to correct rotations and didn’t manage to get it finished so I left it. I’ll have another look at that and see if I can get it sorted and I can then bundle it with Blender.

I am glad you like it. Thank you for the creation of such a great script! :slight_smile:

Please let me know if you need any testing with the updated script you are working on.

As always keep up the amazing work and have a wonderful day! :slight_smile:

Wow, this is so super useful. Blender is going to be a killer addon for Motion when the 3D View Effects are finished :wink:

The OpenGL is already pretty amazing, shame we can’t render it as a core render engine :frowning:

Hello, what do you mean 3D View Effects? Is this in Blender or Motion? :slight_smile: