After Effects To Blender 2.70a Javascript Python Generator

(Atom) #21

I have changed the script to make the camera move up instead of down. (redownoad from link on first post)

Your After Effects scenes do point out that the camera and z-distance calculations are off. I am not sure how to correct it at this time.

When I made the 2.49 version of this script I simply cloned an existing exporter that supported Maya, Max and Lightwave. Lightwave was the closest match at that time. So the camera math is essentially for lightwave. I made this script public with the hope that someone a bit more savy on calculations might be able to offer up some suggestions. But all I can offer at this time is to say “play with the camera sensor size and focal length”.

I have wanted to revisit the concept of how to implement a Blender unit in After Effects I just have not had the time.

(loogas) #22

Thank you for the update :slight_smile: I understand that you’re busy, that’s what makes me thankful even more :wink: I often think that many people posting here (or in other places, doing regular tutorials, writing free plugins, scripts etc.) are almost like superheroes :wink:

I wish I could help more. There’s one more thing that comes to my mind - I had a chance to check PFHoe by Pixel Farm (it was the cheapest tracking solution at one moment) in the past and it had the ability to export script files for Blender 2.49. There were feature requests on their forum to update for 2.5 but they haven’t done it so far. This software is now discontinued so I think that’s it. But maybe there is something in the code that PFHoe was producing which could help here. I don’t know, maybe it’s AE problem. If you want to look into the code here’s an example script file I got some time ago:

It’s for 2.49 however, so I possibly it’s useless. Thanks again :wink:

(Vilperi) #23

This is awesome!

I’m trying to export a panning camera from AE CS6 but the Blender camera is off-kilter for me too.

I attached the AE file. Can you figure this out?


Attachments (48.3 KB)

(loogas) #24

Well, Atom said the script is not finished, updating it would take much time. I guess we just have to wait, maybe somebody comes up with a solution. I really need that functionality too. Someday we’ll get there.
Atom, if you’re reading this - have you archived the old version somewhere? The one which was working with blender 2.49? I googled like crazy but all the links are dead. We can still use it, save the file then open in new Blender. I thinks it’s a good workaround for now. Thanks :slight_smile:

(BartekSkorupa) #25

I’d gladly help with this script, but I’m not good enough with jsx. I tried to go through this several times and gave up.
I think that the math here is a bit too complex and conversion can be done easier. For example I noticed that angles are used to convert AE’s lens to blender’s lens. This is not necessary. I’m sure about it, because I made all the calculations myself for the exporter from Blender to AE which is included in Blender. I didn’t at all use angles and everything sits precisely where it should.
I can do all the math, but I would have problems implementing it into existing script that I don’t quite understand.

(loogas) #26

Wow! Bartek Skorupa and Atom in one thread :slight_smile: I’m crazy about using two-way workflow between Blender and After Effects so your script Bartek is just sooooo useful. Now we need the other half :wink: I’ve used the contact form on your website some time ago to ask you about any solutions but I don’t know if the form is working. Do you remember getting my message? If you didn’t have time to answer no problem - we’re all so busy these days.
Back to the topic - I don’t have any programming skills, I’m just a user that needs some features, so I cannot really help. I can test, I can feedback. I really think we need those scripts, tracking in AE is just so easy and fast (if there’s a problem we can use the Foundry’s plugin which helps even more). It would be great to take that data into Blender.
Bartek - I’ve published in this thread an old code exported from PFhoe. It was a cheap tracking software which could export data to Blender. It was Blender 2.49, however, so I don’t know how useful is this data.

(Atom) #27

I am willing to field questions for the parts of the code that are confusing. Remember, I built this from an existing working exporter for Maya, Max and Light Wave. So some math conversions for the camera may have been needed for those applications.

collectValueAtCurrentTime_XZY_Camera is where all animations data that will be written out for the camera is collected, calculated and returned to the caller. Put override values here to test your ability to alter the output stream.

Also getFLenOrFOVorZFacFromZoom has some math I do not understand.

You can ignore anything related to Masking at this time. It was a work in progress even in the 2.49 script. I left some code in there so I would not have to look it up again.

I wrote a javscript version of our beloved python dir() function and it is available in the script. It is called pythonDIR (). If you want to examine a javascript variable you can pass it to pythonDir and it will try to return a string of attributes like dir. You can pass the results to a javascript alert() function to popup a message box with that variables attributes.

myStr = pythonDir(unknownVar);

Be warned not to leave an alert inside a loop, there is no way to stop a javascript once it is lanuched under After Effects.

(Shane) #28

Thanks for working on this. I’ve been using AE CS6, which has built in 3D camera tracking that works quite well, not to mention easily and quickly. I’d love to be able to build my composition in AE, and export a camera and some nulls to Blender in order to create some 3D text or objects with Cycles rendering.

(Madog) #29

Life saving thing. Good Work!

(Atom) #30

@loogas: Sorry for the late reply, but I am finally looking back into making this script work better. After some research I realize that the script is missing the sensor size for your footage. While the script can look at the After Effects camera sensor size, it can’t really know what sensor size the footage was shot with. Do you happen to know what camera was used to for the footage you have posted? If so, it might be possible to simply set the After Effects lens and sensor size to match the lens and sensor of the camera that shot your footage.

(loogas) #31

Thank you Atom for any effort any time :slight_smile: For my footage I use Canon 550d but in the one posted Canon 5d Mark II was used, here are the specs:

As a side note (if you happen to have some time to read it ;)):
I’ve been checking online tutorials to look into camera “interchangeability” between different packages - 3dmsax, maya, pftrack, nuke, after effects, cinema4d - and this functionality is there. I wonder how they achieved in on the coding side. I mean you don’t even have to know what was the camera that the footage was shot with etc.

I don’t know how many people would need this functionality in Blender but something like this was a major feature in the last 3dsmax (you can import whole scene data into AE and back) and is being advertised for the upcoming update of AE (great interoperability with Cinema 4d). I really don’t want to leave Blender and learn another package, all over again :wink:

Thanks again Atom! :slight_smile:

(Atom) #32

Thanks for the info, I see the Canon is a 36mm x 24mm sensor now. I was digging around in the After Effects javascript API and I just can’t find any reference to the sensor size, after the camera is created in After Effects. All you have is zoom and FOV. I have a math request posted on and hope someone chimes in. But I think for worst case scenario, the exporter can still work for motion graphics even if the camera is off for footage tracking. I was looking into Bartek Skorupa’s exporter code hoping to reverse engineer his camera export, but it is still a work-in-progress.

(zhajym) #33

wow, this is awesome! couldn’t get it to work in blender 2.66, but it works perfectly in 2.63…

this is just what i needed right now! thank you atom!!

(Veggiet) #34

Woah, cool… I can’t wait to see what comes of this

Now if only premiere was more compatible with After Effects. Premiere -> Blender would be awesome

(Atom) #35

Hi All,

I have revised the After Effects To Blender exporter to update it for Blender 2.6.6 api changes.

Instead of trying to match the camera to one type of footage or lens I decided to match the After Effects Camera to Bartek Skorupa’s Blender To After Effects Export script. I think this makes the most sense for us Blender users because it is in the official release of Blender. The CS5 version of this javascript will now reliably transfer a camera back to Blender with the lens settings matching Bartek’s Exporter. So you can export using Bartek’s script to After Effects, make changes and send it back to Blender with this CS5 version of the javascript and there should be no camera distortion. This should give more confidence to the two-way pipeline from Blender to After Effects and back to Blender for Motionographers.

As far as tracking and camera matching tasks, however, we are still in untested waters.

For example I noticed that angles are used to convert AE’s lens to blender’s lens. This is not necessary.

@Bartek: Thanks for the tip, I have revised the lens zoom calculation with a magic # that seems to match your export code for tested camera zooms. I transfered 5 cameras with different zoom values from Blender2AE2Blender without any distortion to the lens or LOC/ROT of the cameras.

There is a lot of math in the exporter that I don’t understand either, having taken it from the Maya/Max/Lightwave exporter years ago. Internally I think the original authors of that script turned After Effects zoom values in to radians for internal calculations and thus it needs converted back for final output.

"ca.lens = " + radiansToDegrees(G.CAMERA_ZOOM) / 6.3662  // Magic #

(BartekSkorupa) #36

@Atom: Let’s assume that I do all the math. If I do it and give you all the formulas, would you be able to implement this in your exporter?

Let’s say I give you data like this:

location.x = AE_position_x * something minus something else plus comp_width
location.y = blabliblebli.

When it comes to camera data, I’d assume using default camera settings (I mean sensor, “fit” etc.) and match all the math to those settings.
Math here should be easy. I’d assume that we have the access to “zoom” value in AE. If so - I can easily create a proper equation, like:

blender_lens = comp_width * something minus something times zoom.

Will it help?
Maybe this way we could somehow ignore all those crazy “RadiansToDegreesToRadiansAgainToAnythingElseThatIsNotNeeded” stuff?

(Atom) #37

There are still some things going on in the javascript exporter that I am not sure about (like layers being created on-the-fly and then discarded). So I’d rather not try to fix something until it is broken. At this point all we need is more testing to identify any camera cases, if any, that are still not working.

I agree the javascript code I present is cluttered and messy. I left a lot of experimental code in the script, but commented out, hoping to return to it when I get more time. Mainly I do think it is possible to extract mask information in After Effects and translate it into curve objects inside Blender. However, my adventures into trying to extract particle data from Particular have lead to a deadend due to Trapcode’s failure to expose properties to the After Effects API.

(loogas) #38

It’s nice to see you’re still trying to figure things out guys :slight_smile:

Well, the only thing I can do to help is to keep testing, so I did. It’s better but still something is off.

First of all, you have to know I didn’t export anything from Blender, then back to Blender. I’ve used a situation I face almost every day - I’ve tracked the footage inside AE (fast track, not fully tested), created a scene, a camera and some 3d solids for reference.
Let’s say I want to take this to Blender (it’s an unused shot from a tornadoes and destruction music video I did a while ago), add stuff to the ground, the building in the background, and then render to compose in AE.

I’ve run the script (I hope I’ve used the correct version, the bottom one from the first page of this thread: ATOM_AE2Blender26_04162013.jsx) in CS6 and CS5. Then I tried to use the resulting .py files in Blender 2.66a - it doesn’t work, some error. But this doesn’t matter - we cannot expect Atom to keep updating it all the time :wink: I’ve run it in Blender 2.63a and here it works, it creates the scene and stuff. The camera seems to be shifted in its position to the right. What’s more, if I use the ouput from CS6, the camera is below the ground (but again, let’s leave CS6 for now, if it works at least in CS5 that’s gonna be great).
I thought first that maybe camera parenting to a scene-controlling null is a problem, but if you unparent it so it displays it’s true position in space and then export, you get the same result.

Here are some screengrabs:

CS5 scene:

CS5 to Blender 2.63a result:

CS6 to Blender 2.63a result:

I hope this doesn’t discourage you Atom (and Bartek ;)). Zhajym reported it works for him - could you tell us more? Have you created a scene in Blender, went to AE, then back to Blender, or it all started in AE?

If you need the scene and my files to look into them, like with the previous case you’ve checked, you can find them here:

By the way:

Even though I don’t like marketing mumbo jumbo about how great the dynamic link between AE and Premiere is (it can fail you in some really demanding situations) it usually works nice, so what do you mean Veggiet by saying that AE is not compatible with Premiere? They work great together. Premiere is and editing software - why would you like to export to Blender? Or maybe you’re talking about Blender’s sequencer, not 3d space? That would be a completely different matter :wink:

(Atom) #39

Thanks for the test files, verified, the script does not work. I just don’t know enough about the math to make the camera work correctly. The objects seem to be in the correct location. But the camera is just fracked.

(loogas) #40

No problem. Thanks for coming back to this - maybe some solution will come up eventually. By the way - do you still have the older version of your script which worked for Blender 2.49 and AE CS3? All links are dead but I think it could be used as workaround for now. Thanks in advance :wink: