Export AE Camera to Maya

All things .jsx

Moderator: Paul Tuersley

urbanspaceman
Posts: 54
Joined: December 12th, 2007, 9:56 am
Location: London
Contact:

This is one I've been working on for a while, and it appears idiot proof so far.

All you have to do highlight your camera, and the script does everything else, including outputting a .ma file for Maya. It shouldn't matter how your camera is animated (parented, with POI, with auto-orientation), whether you're in non-square pixels or not, or if you've animated your zoom value (focal length). This baby should handle all that.

http://www.urbanspaceman.net/shared/AEs ... ToMaya.jsx
nab
Posts: 203
Joined: November 29th, 2005, 3:00 am
Location: Royan
Contact:

Couple of remarks:
. the second parameter of valueAtTime should be true or false (true=preExpr), not an array of the dimension of the property (that's why you get NaN for some values).
. if you want to speed up things, you should consider looping through the comp frames only once (retrieving all data in one pass), instead of looping seven time or so through every frame.
(. simple UI for choosing the 3D app -I've seen your other script- would be cool :) )

I can't test it because I'm not a 3D guy, but you seem to have done a great job Image
urbanspaceman
Posts: 54
Joined: December 12th, 2007, 9:56 am
Location: London
Contact:

Hey nab,

The suggestion of looping only once is a good one. I hadn't thought of that. It's true if the animation is long that this script can be slow...without some kind of progress bar it can seem like things have frozen.

I'm working on a 3DS MAX version too...as usual, the rotations are getting me stuck again. But once I figure that out, I should be able to stick them all together as one script, which would be very handy. I've also done a null export for Lightwave, and am planning to do that for the other 3D packages too. Then you could do both cameras and nulls from After Effects to any 3D package.

I'll look into the valueAtTime thing. I hadn't noticed the NaNs popping up before....cheers.
nab
Posts: 203
Joined: November 29th, 2005, 3:00 am
Location: Royan
Contact:

You could store data as strings since the end result is written into a file.
Here is a squeleton that you could use as a basis...

(by the way, in CS3 there is a progressbar ui element)

Code: Select all

function DataContainer()
{
    var data = new Object();
    
    data.xpos = "";
    data.ypos = "";
    data.zpos = "";
    data.xrot = "";
    data.yrot = "";
    data.zrot = "";    
    data.flen = "";
    
    return data;
}

function getFocalLengthFromZoom(zoomVal)
{
    return 4; 
}

function getData(comp, layer, data)
{
    for (var t = 0; t < comp.duration; t += comp.frameDuration)
    {
        data.xpos += layer.position.valueAtTime(t, false)[0] + " ";
        data.ypos += layer.position.valueAtTime(t, false)[1] + " ";
        data.zpos += layer.position.valueAtTime(t, false)[2] + " ";
        data.xrot += layer.rotationX.valueAtTime(t, false) + " ";
        data.yrot += layer.rotationY.valueAtTime(t, false) + " ";
        data.zrot += layer.rotationZ.valueAtTime(t, false) + " ";
        data.flen += getFocalLengthFromZoom(layer.zoom.valueAtTime(t, false)) + " ";
    }
}

function writeData(data)
{
    alert("Writing data..."); 
    
    /* Check that everything is ok
    var file = new File("test.txt");
    if (file.open("w"))
    {
        file.writeln(data.xpos);
        file.writeln(data.ypos);
        file.writeln(data.zpos);
        file.writeln(data.xrot);
        file.writeln(data.yrot);
        file.writeln(data.zrot);
        file.writeln(data.flen);        
        file.close();
    }
    */
}

var comp = app.project.activeItem;
var layer = comp.layer(1);
var data = new DataContainer();

getData(comp, layer, data);
writeData(data);
urbanspaceman
Posts: 54
Joined: December 12th, 2007, 9:56 am
Location: London
Contact:

I took a shot at adding a progress bar to the script, and I've been struggling with the progressbar attribute for days now. I'm certain this is a bug, because it does not work properly in AE8. Has anyone reading this got it to work?

Part of my goal was to write something that would work for AE 6.5 and up...and I did create a progress bar successfully using the "edittext" box in 6.5. But in AE8 it simply looks like the window freezes, because it appears you cannot update a palette or window in the middle of a script.

I must say I've had nothing but problems with AE8 and I tend to return to AE6 or 6.5 to get my work done. I'm surprised I haven't come across more rants on the web about how full of bugs and how slow AE8 is on a Mac.
urbanspaceman
Posts: 54
Joined: December 12th, 2007, 9:56 am
Location: London
Contact:

Hey nab,
I experimented a bit with incorporating your code in my script. It is more efficient, but unfortunately there wasn't a big speed increase because writing the .ma file (what your code is doing, basically) wasn't what took that long...it's the code I'm using to imitate the "Covert Expression to Keyframes" assistant that is slow. I would either like to speed this up, or add a progress bar, but as both seem to beyond me at the moment I may have to leave it as is and just be happy that it works.

It's just a little disconcerting because there's no feedback while the script runs and it looks like AE has frozen....ah well.
ymmij
Posts: 28
Joined: December 1st, 2006, 1:20 pm

urbanspaceman wrote:I took a shot at adding a progress bar to the script, and I've been struggling with the progressbar attribute for days now. I'm certain this is a bug, because it does not work properly in AE8. Has anyone reading this got it to work?

Part of my goal was to write something that would work for AE 6.5 and up...and I did create a progress bar successfully using the "edittext" box in 6.5. But in AE8 it simply looks like the window freezes, because it appears you cannot update a palette or window in the middle of a script.

I must say I've had nothing but problems with AE8 and I tend to return to AE6 or 6.5 to get my work done. I'm surprised I haven't come across more rants on the web about how full of bugs and how slow AE8 is on a Mac.
I have been trying out the script with AE8 and Maya 2000. Did a simple camera move (small pull back and a little rotation). There is an error reported by Maya. I have looked at the file and have a number of 'Nan's listed under after the .ktv for Camera1_TranslateX and Camaera1_TranslateY. The data is there for everything else.

Looking at the move in Maya, I am clearly missing these translations.

Funny thing is that I did a similar test a couple of days earlier and all seemed to work fine. Can't seem to get passed it now.

Russ
urbanspaceman
Posts: 54
Joined: December 12th, 2007, 9:56 am
Location: London
Contact:

I believe it is fixed now, Russ. Try downloading the file again, and tell me how it goes...
ymmij
Posts: 28
Joined: December 1st, 2006, 1:20 pm

urbanspaceman wrote:I believe it is fixed now, Russ. Try downloading the file again, and tell me how it goes...
I downloaded the file from the link at the top of this the forum page (http://www.urbanspaceman.net/shared/AEs ... ToMaya.jsx). Unfortunately there is no identification of versioning, so I cannot tell if this is the same as what I already had.

Anyway...did a test and same result...got the 'NaN' for the translations.. Could be that I don't have the actual updated version. Could you please identify this as say 1.0.1 or something like that so that I can compare.

Thanks,


Russ
urbanspaceman
Posts: 54
Joined: December 12th, 2007, 9:56 am
Location: London
Contact:

Try the same link at the top, Russ. I've added the note v1.1 to the first line. I thought I knew what caused the error in the last post, but it just dawned on me what really it was. So please try it once again and let me know if it works. It works on my end so far, using both AE 6.5, AE 8, and Maya 7.
ymmij
Posts: 28
Joined: December 1st, 2006, 1:20 pm

urbanspaceman wrote:Try the same link at the top, Russ. I've added the note v1.1 to the first line. I thought I knew what caused the error in the last post, but it just dawned on me what really it was. So please try it once again and let me know if it works. It works on my end so far, using both AE 6.5, AE 8, and Maya 7.

Success....but not sure if any of your changes helped. I suspect that your changes may have improved the code, but ultimately the cure came from somewhere else.

If you recall, I mentioned that your script was working then bang...not working. Turns out the difference was whether or not I accessed your script by pulling down the 'run scripts file' in After Effects menu, or the use of the GUI add-on called Scriptlauncher by Jeff Almasol or http://www.redinery.com. When using 'ScriptLauncher' the file is written with the 'Nan' errors in the translation.

Sorry for causing the confusion....but better to find out this kind of info.

Would be great if you could get your script to work with 'ScriptLauncher'. I use this quite a bit to manage my scripts.

One other thing:

Had wrong layer selected when I ran the script. Got an error message telling me to pick the camera. Rather then returning to AE it went on to present the dialog box for saving. I hit cancel, and then the Extendscript application opened up and presented me with a line error.

Okay.....on with some real testing. Other then what's been reported....working great.

Russ


Russ
urbanspaceman
Posts: 54
Joined: December 12th, 2007, 9:56 am
Location: London
Contact:

I was able to reproduce the bug on my end, and I noticed why it only happened once and a while. I was referring to layers by name, but if you have the "Source Name" button clicked instead of the "Layer Name" it couldn't find the layer that had the position keyframes in it (the first part of the script puts the camera data into other layers, and then erases those layers)...I changed it so the the layers are referred to by number instead of name, and so that issue should go away.

I will see if I can reproduce the other bug. I did put two scripts together at one point, and I did forget to stop the first part before the second part started if an error came up....I'll add that.

I'm curious how others will make use of this, and what their workflows are. It seemed I was one of the few people out there who preferred to start a project in the rough in AE, working out my camera moves before moving on to a 3D package. There's been many times in the past where I would give an animatic to a 3D animator and ask him or her to reproduce what I'd done...but was always frustrated by the extra time it took and was extra disappointed if a 3D specialist didn't have the skills to do a smooth camera move. That's what motivated me to work on these scripts...I was tired of some 3D people telling me they couldn't recreate a camera move that I'd already finished in After Effects!!

So I'm wondering how may other artists like to work "backwards". : )
ymmij
Posts: 28
Joined: December 1st, 2006, 1:20 pm

urbanspaceman wrote: I'm curious how others will make use of this, and what their workflows are. It seemed I was one of the few people out there who preferred to start a project in the rough in AE, working out my camera moves before moving on to a 3D package. There's been many times in the past where I would give an animatic to a 3D animator and ask him or her to reproduce what I'd done...but was always frustrated by the extra time it took and was extra disappointed if a 3D specialist didn't have the skills to do a smooth camera move. That's what motivated me to work on these scripts...I was tired of some 3D people telling me they couldn't recreate a camera move that I'd already finished in After Effects!!

So I'm wondering how may other artists like to work "backwards". : )
I work in a shop that does have a strong 3D team. Consequently most of the camera moves start with Maya, and to be honest the 3D guys can never understand why you would want use AE at all when it comes to 3D.

What I like about your script is that it allows for the crossover to occur if a project started in AE and there is a directional change and suddenly there is a call for 3D components. You can either supply the 3D guys with the camera so far and continue and as a full 3D project, or you could continue on with AE and import some 3D elements from the 3D guys who have your camera for placement.

What is good here is that you don't have to know in advance how it is going to go. There are other "AE to 3D" solutions around, but you have to first set things up in a particular way. Your script lets the user animate the camera or a parented camera to a null. Pretty important. I have found that most AE animators fall toward animating nulls....camera is to hard to manage.

The next advance to the script would be to allow any 3D layers in AE to become a fixed tracking points. This way a 3D animator can pick up your camera and also use the placement of solids or nulls to position models in the scene. After this you might thing on also exporting an animated tracking point.

I have worked out the process in the reverse direction (Maya to AE) with 100% accuracy. This has become very useful in our shop. Going both ways is great.

Russ
ymmij
Posts: 28
Joined: December 1st, 2006, 1:20 pm

urbanspaceman wrote:I was able to reproduce the bug on my end, and I noticed why it only happened once and a while. I was referring to layers by name, but if you have the "Source Name" button clicked instead of the "Layer Name" it couldn't find the layer that had the position keyframes in it (the first part of the script puts the camera data into other layers, and then erases those layers)...I changed it so the the layers are referred to by number instead of name, and so that issue should go away.
Are you saying that you have made a change to version 1.1? If so I will try it...but again, pretty important to version the scripts after each modification.

Thanks,

Russ
urbanspaceman
Posts: 54
Joined: December 12th, 2007, 9:56 am
Location: London
Contact:

ymmij wrote:Are you saying that you have made a change to version 1.1?
Yes. I'm self taught in this programming thing, so I don't have a programmer's habits yet. I'll make a point of documenting my changes in the future, now that I know others are paying attention. : )
ymmij wrote:There are other "AE to 3D" solutions around, but you have to first set things up in a particular way.
Yup. That frustrated me to no end.
ymmij wrote:The next advance to the script would be to allow any 3D layers in AE to become a fixed tracking points.
Stay tuned. I have written a script for Lightwave to do just that, and used it on my last project. I haven't posted it just yet, because I want to merge it with the camera script first. Then I'll tackle this for Maya.
ymmij wrote:...and to be honest the 3D guys can never understand why you would want use AE at all when it comes to 3D.
Thanks for telling me about your workplace. I'm always curious. I've encountered the same attitude: "why would you want to do 3D in After Effects?".

In my experience it gets certain projects off the ground much faster, and since I work in TV that's very important. I seldom bother with storyboards anymore. I just sit down and animate, using simple graphics or photos in After Effects. When I show this animatic to a client, he or she gets something full rez that feels a lot like a final piece, already edited. I find this is very hard to quickly do in a full 3D package. Wireframe previews leave a lot to the imagination, and many preview renders look just horrible. After Effects is simply faster and more interactive, so it makes sense to me to start there.

If Adobe had built export features into AE, would more AE artists be doing this?
Post Reply