Blender to Apple Motion export script

(osxrules) #1

Similar to the Maya Ascii script, I have developed one for Apple’s Motion program. Motion has a number of nice features and is very cheap. It is £35 as opposed to £750+ for After Effects. It’s also entirely hardware-accelerated so is fairly quick at rendering. It also integrates with Final Cut Pro so you can make up Motion templates with drop-zones and reuse clips.

The script is available here:

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

There’s a video that follows showing how the process works between Cinema 4D and Motion:

You should be able to achieve the same thing with this Blender script.

If you run the script in the text editor, it will put an entry into the file > export menu to Apple Motion (.motn). When you select this, it will ask for an export location and save out a Motion project file with a .motn extension.

You would render your Blender animation out with appropriate masks and save it in a format that Motion will recognise. Then open the .motn file by double-clicking. To get round some stability issues with IDs in the file, it is setup as a Motion 3 file so will ask to upgrade it, which is fine - when you save the file, it adds all the required data back in. Hopefully this means it will work in Motion 3, 4 and 5 but I only tested it in version 5.

You import your rendered clip into Motion and drop it into the scene on a new layer and set this layer to not be a 3D layer. Any objects you add into the scene as 3D layers should then follow the camera movement and match the rendered footage.

This export is a bit different from the Maya one and I was able to exclude more redundant keyframes so should hopefully be faster and less memory intensive but naturally with changes, there’s a chance it’s messed up some things so if you can test it out and let me know if anything has gone wrong, I’ll try and get it to a state where it’s reliable to use.

0 Likes

(Deyson) #2

Thank you so much for taking the time to create this script.

I opened Blender 2.58 made a very simple camera moving in and out to test. I then ran the script in the text editor and I get a Python script fail that reads: from io_utils import ExportHelper

Let me know if you any further information. Thank you an have a wonderful day! :slight_smile:

Deyson

0 Likes

(zeffii) #3

make it


from bpy_extras.io_utils import ExportHelper

0 Likes

(osxrules) #4

Looks like Cambo broke everything (as usual ;)):

http://permalink.gmane.org/gmane.comp.video.blender.devel/31096

I have updated the script for 2.58 but it does mean that now it doesn’t work with 2.57 or less. No big deal really.

One thing I did notice is if you upgrade Blender, it doesn’t keep your settings because the .B.blend files are stored per version now.

On the Mac, you have to rename the folders in /Users/username/Library/Application Support/Blender to the latest version. That’s probably going to get annoying.

Anyway, it should be working properly now.

0 Likes

(Deyson) #5

Thank you. :slight_smile:

One question, will this script allow you to link object nodes, so if I want something animated, like drop zones, the movement can be translated into Motion and then attached to a 3D layer.

In Cinema you can select an object and have the object’s animation come into Motion.

Thank you so much, I will give this a try over the weekend.

0 Likes

(osxrules) #6

By default, it takes in all object positions and all animations. So, you don’t have to select what you want in the scene. If you feel too much is being exported, you put what you don’t want to export into a layer and hide it and then it won’t export.

I also have some code in there to automatically remove redundant keyframes, which helps keep the data size down. Normally, baked data has a key for every frame but if an object moves a little and then stops for 100 frames, you don’t need 100 fixed keyframes. It makes sure to pad out the endpoints so as not to make the animation curve inaccurate.

If you make anything nice, it would be good to see so please post a video if you can. Someone used the Maya script for integrating text on some motion graphics here:

http://twentyfourbecks.wordpress.com/2009/08/28/blender-to-ae-maya-ascii-camera-export-script-update-and-enhancement/

0 Likes

(Deyson) #7

Hello OSX, I had a full day of playing with the script. Either I am doing something wrong or I am missing something. :slight_smile:

I created a new blender file, when I add an animation to an object and bring into Motion, it seems to be out of alignment.

I was able to make it look better by increasing the cameras z direction by -2300. and the placeholder was still a little off.
A quick way to test this is to add an object in Blender and animate it from one corner of the screen to the other corner diagonally, when you go to Motion the direction is correct but the distance is incorrect, that is the reason I had to zoom in with the camera to try to match the distance.

I was wondering if maybe I can look at one of your test bender files to see if my settings match or to see what I am doing wrong.

There are many things that I like, for example that every object selected goes into motion as a layer, so I can have multiple placeholders without having to link anything, I just drop in what I need.

Now another challenge I have, is in Cinema I can assign an object for multipass, so when I render Cinema renders a lumamatte for each object selected for later compositing in Motion. Is there a way to do this in Blender.

I have used Cinema more steadily being that it is the only 3D app that integrates with Motion, but I would much rather use Blender so I have some learning curve.

Thank you :slight_smile:

0 Likes

(osxrules) #8

Do you have a screenshot of your 3D scene setup and also what are your render settings (resolution, aspect, fps etc) as well as camera settings?

I’ll do some more tests. I know AE required scaling by 100 to match the units, maybe Motion is the same.

You should be able to use render layers for this so you’d put your foreground items into their own layer and background layers into another and render them separately. You can then put composited items between them.

0 Likes

(Deyson) #9

The only thing I did in blender was open a fresh file, reset the camera position and rotation in blender to all 0 in position and all 0 rotation except for X which I left a 90% so it looks up along the grid.

In motion I did no changes to camera or project settings. The only thing I did was add a dropzone to the plane group that was created in blender, and then I had to increase the plane scale since it came in at 0 from blender. From what I can tell everything looks fine except in Motion the plane’s motion path is much smaller than in bender.

I attached a download zip of screenshots, a blender file and a Motion file. In blender I had the plane’s center move on the parameter of the camera and in Motion you can see that Path does not match up.

Here is the link: http://deysonortiz.com/blender_test/Blender_motion_test.zip

You should be able to use render layers for this so you’d put your foreground items into their own layer and background layers into another and render them separately. You can then put composited items between them.

The reason I like to use luma Mattes is to keep the file size down, as I like to make one render in grayscale, then luma matte all the objects to composite the layers later and add color in Motion.

The reason being that alpha movies are larger and luma mattes being flat and with no color are much smaller. I figured how to use render layers. No I would like to figure out how to get Luma Mattes out of blender for each object for compositing in Motion.

Thank you for everything! :slight_smile: I am very excited to see this work :slight_smile: You rock!

0 Likes

(osxrules) #10

One scaling issue is because your render settings are 1080p but you are rendering at 50% - I think this is the Blender defaults. The script doesn’t take account of the scaling so it uses 1080p as the resolution. I remember someone asking for that feature on the Maya script. If you render at 100% at the frame size you want, it should match. It is more convenient using the scaling in some scenarios so I’ll add it in.

There is another issue though in that I’m exporting the camera lens millimetre value where Motion uses degrees so the angle is wrong and it uses a different camera framing type from Blender - default is ‘framing’ where Blender uses ‘viewpoint’. I’ll make those fixes and hopefully that should align it all properly.

I also noticed it defaults to setting the interlacing fields for output, which creates interlaced footage on export so I’ll need to set that off by default so that it outputs progressive footage.

You can render out just the alpha channels using nodes. There’s a page here about using render passes:

http://wiki.blender.org/index.php/Doc:Manual/Render/Passes

0 Likes

(Deyson) #11

Thank you very much, I will be eagerly looking forward to the fixes.

In the meantime I will read up on render passes. Correct me if I am wrong is Blender’s Alpha pass the same as a Luma matte pass?

Thank you so much. I am so excited! You ROCK! :slight_smile:

0 Likes

(osxrules) #12

That should be it now - download from the same link above.

I noticed another issue to do with object scaling. It seems to bring some objects in as zero but I checked the code and that’s what the function call matrix.to_scale() returns so I don’t know if that’s a bug.

In your example, your plane is set as scale 0.5, 0.5, 0. When z is 0, matrix.to_scale() returns 0 for x and y too. If it’s anything above zero e.g 0.0001, it will return the correct values for x and y.

Yes - the only difference between a luma matte and alpha matte is the channel the data is placed in. So if you render out an RGBA image, it’s an image with an alpha matte. If you render out the alpha on its own into an RGB image then it’s a luma matte.

It actually doesn’t matter which way you render it as it’s the same data, you just have to flip a different switch in the compositor. If you’ve used trackmattes in AE, you will have seen the options: alpha matte, alpha inverted matte, luma matte, luma inverted matte, which basically tells the track matte to look at either the alpha channel or the colour/luminance channels.

AE uses the 3 RGB channels together for a luma matte. In compositors like Shake and Nuke, you can specify an individual channel e.g R or G or B or A etc.

0 Likes

(Deyson) #13

I did a quick test going corner from corner and it worked great. Next I will do a more in depth test.

Thank you very much. I will keep you posted!.

You rock!

0 Likes

(Deyson) #14

Question. What size should I set the plane to in blender, so in Motion I can drop a drop zone object and it will match a 16x9 aspect ratio in blender. So I want to create a 16x9 plane in blender and when I bring it into motion and the Plane layer will just take the drop zone object and not need to scale.

Right now if I drop in a drop zone to the plane group in motion the drop zone is huge so I have to scale it down to match.

0 Likes

(osxrules) #15

The layer scale values in Motion will be considered relative to the frame size but the scale values on objects are relative to their original size, which Motion won’t know. So there’s not really a way to get the scale exact without scaling manually in Motion unfortunately.

The aspect ratio you can do by setting the scale of the plane to 16:9 e.g 1.6 units wide by 0.9 units tall (again make sure z is non-zero).

I’ll check out the other issues you mentioned in PM. Thanks for testing.

0 Likes

(Deyson) #16

Thank you for giving me something to test :slight_smile:

0 Likes

(osxrules) #17

I checked out the issue with the rotation flipping and it will take a bit of work to fix. In order to get the baked animation data, you just take the world_space matrix for a given frame. But, this matrix understandably doesn’t take account of multiple rotations as it’s really a combined matrix so it keeps mapping to [-180,180].

I’ll have to write a Euler Filter like Maya has for this to ease out the discontinuity:

I’ll need to update the Maya script with this too as it will be susceptible to the same problem.

0 Likes

(Deyson) #18

Keep me posted, I am looking forward to it as I love to fly around objects :slight_smile:

0 Likes

(Deyson) #19

Hello, I just noticed that the blender file that I created at 29.97 opens up as 30FPS in Motion.

Thank you :slight_smile:

0 Likes

(Deyson) #20

I kept this template very simple to test out this export script and I am simply in love with it! Thank you OSXRules!

http://motion-master-templates.com/member-templates/desktop-zoom

I also added a special thanks to you OSXRules on my blog: http://deysonortiz.com/blog/motion-master-templates/new-motion-template-desktop-zoom/

Have an awesome day!

0 Likes