Many cups of COFFEE later:
I can't tell you how much pain I went through trying to write the COFFEE side of the script. It was a similar experience to when I started learning AE scripting and mainly for the same reason, a lack of available real world examples of COFFEE code. There is some stuff out there, but not much.
That's not the case with AE scripting anymore. Thanks to AEnhancers and a number of other sites, there's a lot of code out there, which is a great reference for usage examples when you hit something new. In C4D, it seems that you can keep your script as a regular COFFEE script (like mine, ending in .CSC) or turn it into a plugin (source = .COF, compiled = .COB). Unfortunately, most COFFEE scripters seem to favour the compiled .COB format, so there's no chance to study their code.
The COFFEE language:
Apparently COFFEE's a bit like C++ (which I don't know) and Javascript (like AE scripting) but possibly more like C++. I can tell you one thing, it certainly seems a lot fussier that AE scripting for things like arrays, variable types and basic syntax. And I stayed well clear of classes.
Here are links to the COFFEE 9.5 SDK and the main forums I searched for answers:
http://www.maxon.net/pages/support/plug ... ads_e.html
http://www.plugincafe.com/forum/default.asp
http://www.c4dcafe.com/ipb/lofiversion/index.php/
http://forums.cgsociety.org/forumdisplay.php?f=182
http://www.3dattack.net/forum/index.php
http://xpresso24.com
Problem - Recording Position keyframes:
The first major problem I had was simply finding a way to set the Position keyframes. I couldn't find a single usage example of someone using COFFEE to set a sequence of Position keyframes and from what I read, it seems C4D 9.5 COFFEE has some surprising limitations in this area.
I eventually found I could cheat by using CallCommand() which behaves similarly to AE scripting's app.executeCommand() for accessing menu commands. So my workaround for setting keyframes using COFFEE is basically to get the script to press the "Next Frame" button, then change the X, Y and Z values before hitting the "Big Red Record" button. It's dumb, but it works.
Problem - Doing the same for rotation:
I thought that'd be simple, but once I got the script to hit the "Goto Start Frame" button and repeated the process for the Rotation values, the keyframes came in ok, but now the "Big Red Record" button was also resetting the Position keys I'd already set. I eventually fixed it by storing the Position values in an array and applying the Position and Rotation keyframes at the same time.
Problem - Rotation order:
It was finally time to investigate the rotation order issue. I remembered Stu Maschwitz had posted a solution to AE's "wrong" rotation order on creative-workflow-hacks.com for Dale Bradshaw's auto camera rig creation script:
http://www.creative-workflow-hacks.com/ ... r-effects/
It was my lucky day. Stu's AE camera rig uses the same rotation order as C4D!!!! So that's why, for the time being, this script requires you to use that camera rig. I'm fairly sure I know enough now to create an inverse rig in C4D instead, but once you've used the rig, you may find you prefer it. If you pan then tilt AE's normal camera, you'll find the view is no longer level with the horizon. That doesn't happen with the camera rig or in C4D.
What's next?
So here I am, a week later, with what will hopefully prove to be a useful script. Depending on the demand, there are a lot of improvements that should be possible. Automatically setting the duration and frame rate in C4D, exporting other things like nulls, lights and layers (as reference planes). If someone can help me with the math, I can probably sort out zoom / field of view too.
One possible snag is I've heard the animation system has been overhauled in C4D R10. So it's quite possible this script won't work in it. There's no SDK available for COFFEE in R10 yet either so I have no idea what's changed.
Well that's it, if you've made it to the end, thanks for taking the time. And if you try the script, let me know how it works out for you.
cheers,
Paul Tuersley