3D Camera script question

Moho allows users to write new tools and plugins. Discuss scripting ideas and problems here.

Moderators: Víctor Paredes, Belgarath, slowtiger

Post Reply
User avatar
Rhoel
Posts: 844
Joined: Fri Feb 25, 2005 8:09 am
Location: Phnom Penh, Cambodia
Contact:

3D Camera script question

Post by Rhoel »

The current version has 3D output using the red/blue anaglyphic principle. This is fine for what it was intended to do.

In the last 18 months, real interest has returned to digital 3d, with Cameron and others making features in 3D using new encoding techniques. They are using dual full colour, normal HD frame formats. It immediately registered that AS has the jump here with its z axis, all we need is a method of outputting the dual stream.

My question is, is the camera directly addressable by a script: I am happy to do all my drafting done with the single standard camera: But just like the anaglyph output the camera is offset left and right by a predetermined amount to give the stereo view.

Ideally, I would like to render both steams automatically, but I have no problem in setting the 3D camera to Left, output one stream, change the camera script to Right, then output another image stream.

Is this possible and if so, what are the variables I need to be looking at.

TIA

Rhoel
User avatar
heyvern
Posts: 7035
Joined: Fri Sep 02, 2005 4:49 am

Post by heyvern »

Here's an idea that might work for you using batch render.

Create two identical copies of a project. One with the left eye camera position and one with the right. Render both using batch render.

------------------------

I am certain the camera is scriptable. I don't know off hand exactly where this is in the script reference. I think it is in the moho document section. For how this could be scripted... hmm...

Here's a thought. The script would render one frame from one eye direction. Then it changes the camera, updates a counter variable and "goes back" to that same frame and renders again. Then the camera is reset and on to the next frame.

I am pretty sure that AS will render whatever frame that is "selected" regardless of how it got there (through scripting or just by playing through). This is not a sure thing though. Not sure if the script would "wait" for the render to complete. I think it should work. Obviously AS is not going to the next frame till that one is finished. Going to the next frame would bounce it back... needs to be tested.

-vern
User avatar
Rhoel
Posts: 844
Joined: Fri Feb 25, 2005 8:09 am
Location: Phnom Penh, Cambodia
Contact:

Post by Rhoel »

Thanks Vern, I am currently searching through the LUA guide to see where variable might kept - might have to email Mike on this.

My feedback is there is some serious investment happening in Stereo at the moment, including in a system to permit personal headsets to plug directly into a BlueRay box - if that happens, there will be some very keen producers looking for children's animation ..........

I am happy to be able to have a script with selectable left and rights views, and have two separate renders to different folders. I am only looking at the png frame streams, not AVI or movie format.

Be very cool if we could have an interlacing renderer or a R_frame001, L_frame001, alongside the anaglyph module, heh hem ... Mike :D

I'll update what I find.


Rhoel.

NB: the advantage of one directory with the R_frame###, L_frame### is it is easy to lift each frame sequence out using the list alphabetically. frame001_l is a no no.
User avatar
heyvern
Posts: 7035
Joined: Fri Sep 02, 2005 4:49 am

Post by heyvern »

If you have the Moho Scripting Reference, click open the MOHO folder (the last folder) in the navigation. Then click open "Classes", scroll down to "MohoDoc".

At the bottom of that page are the member variables. All of the camera animation channels are there so they are scriptable. I've never scripted the camera so I don't have any examples handy. It should be similar to scripting motion of any other object in AS.

Next time I am working on scripting I will play with it and see. I'm using the right side of brain right now. ;)

-vern
User avatar
Rhoel
Posts: 844
Joined: Fri Feb 25, 2005 8:09 am
Location: Phnom Penh, Cambodia
Contact:

Post by Rhoel »

heyvern wrote:If you have the Moho Scripting Reference, click open the MOHO folder (the last folder) in the navigation. Then click open "Classes", scroll down to "MohoDoc".

At the bottom of that page are the member variables. All of the camera animation channels are there so they are scriptable. I've never scripted the camera so I don't have any examples handy. It should be similar to scripting motion of any other object in AS.

Next time I am working on scripting I will play with it and see. I'm using the right side of brain right now. ;)

-vern
Thank you - I was looking at this last night when my monitor did the classic collapse to the white center dot then shut down. I have now configured the laptop to this WiMax network and I'm back online.

I had looked in the Moho section but failed to see the camera references - now I know where to look.

Be interested to see how difficult it will be for ME to LUA program it - I'm good at php, Pascal and okay with Python, Lua is still a dark horse for me.

Regards

Rhoel
User avatar
J. Baker
Posts: 1063
Joined: Wed Mar 23, 2005 7:22 pm
Location: USA
Contact:

Post by J. Baker »

Hey Rhoel, can you explain more on why you want to do dual rendering? I didn't quite understand.

Also, I wrote a program that interlaced images so they could be imported in a video editor to create a interlaced video. So I might be of some help, if I new what you were trying to do exactly. ;)
User avatar
Rhoel
Posts: 844
Joined: Fri Feb 25, 2005 8:09 am
Location: Phnom Penh, Cambodia
Contact:

Post by Rhoel »

J. Baker wrote:Hey Rhoel, can you explain more on why you want to do dual rendering? I didn't quite understand.
In stereoscopy or 3D cinema, you have to have the left and right images. The latest techniques require HD/2K in full colour. THis means rendering two passes, one for the left image, one for the right. What I am trying to do is write a simple script which allows me to select one of three camera views - a central neutral camera (the standard one we have now), a Left view option and a right view option.

This way, I can render a 1/4 preview in the normal view, and if the animation is okay, to then render the full image sequence in two passes, one using the left view, one pass using the right setting.

I can combine the two image streams in post-production. IF it could be done so we have an interlaced output, brilliant, but at this stagem I am happy with just the 2 pass render. (BTW any interlace render would have to have a field one/field two (odd/even interlace) option as both systems are used).

Hoe this explains the principle better.

I am assuming there will be a way of adding a fCameraTrack = fCameraTrack + view-offset, where the offset is either -/+ the stereo setting. The current anaglyph is set at 0.08 but can be changed to more or less. The Moho function is fCameraTrack (AnimVec3)

The other option is to write a script which reads the anime file and simply adds the offset to each cameratrack position, then renames it Filename_Left.anime, filename_right.anime ... but this is the dirty hacky luddite approach. :-)


Rhoel.
Genete
Posts: 3483
Joined: Tue Oct 17, 2006 3:27 pm
Location: España / Spain

Post by Genete »

Hi Roel,
I would gladly help you in the construction of the requested scrip. But first I would like to set some basis.

1) To recreate a stereo camera you'll need that both cameras positions look at the same focus point. This means that not only need to move the camera position but also need to change the camera "look at" direction. If a person put both eyes looking in two parallel lines it would get a blurred view.
2) So as well as you should define the "view-offset" you should define the 3D poinst where the camera is looking to. The camera position and the target position would define all the camera settings: position, roll and tilt rotations. I think there is a built in script that makes the camera look at a certain taget. I cannot run AS now but look at it later.
3) Points 1) and 2) implies some 3D vector math that should be done and tested before run the script.
4) For the script itself I think it can be perfectly done with this idea:

a) Make the normal animation as usually. The camera would be animated as usual.
b) Run a menu script that makes an offset to the camera and all over the animation and keep the "look at" thing fixed from the original animation. It would be the right eye for example.
c) Do the same for the the left eye.

But you should provide some sort of focus point distance to recreate the 3D effect. From a single animation it is not possible to know were the camera is focusing unless you use the focal distance from the camera itself.

Sure all this speech sounds a little rare. I don't have AS at hand at the moment to test what I mean, so let me reply in other post later.

Best
-G
User avatar
Rhoel
Posts: 844
Joined: Fri Feb 25, 2005 8:09 am
Location: Phnom Penh, Cambodia
Contact:

Post by Rhoel »

Genete wrote:Hi Roel,
I would gladly help you in the construction of the requested scrip.
Glad to have your help - with my knowledge of Lua, I'll need all the help I can get.

RE: Changing the camera rotation to view: This had a fancy name like divergence, and has been hotly debated for near 50 years. The Russian (before the fall of the Soviet Bloc) were probably the world leaders on stereo, having a special government department to research the technology, build cameras and lenses and make 3D films. My handbook in is a box in the UK but from memory, it was they who came up with the theory divergence = 0, ie parallax. The reason is simple- you are trying to recreate the world, not the view. If you create negative divergence (ie, pointing in to a point 100m from camera), a point on the horizon will be beyond parallax - this forces the eye muscles to pull the eyes wider than looking at the natural infinity point: This is what led to headaches and eyestrain in early 3D movies.

There is an argument for positive divergence, that is aiming the camera a degree or two wide of the infinite point. When projected in parallax, objects appear in front of the screen plain.

For the version 1 on the script, I would be in favour of keeping it simple, making an engine from which to build upon.

The biggest question I have is what happens to the Camera x axis when the camera is panned (in the 3D camera space), Does the Y become the Z axis or does the orientation of the camera not affect the physical 3D space it occupies?. Having to calculate the XYZ coordination in relation to the rotation and tilt will be a real headache. Let's hope its the easy solution.

Hope this helps,.

Look forward to people thoughts on this.

Rhoel.
Genete
Posts: 3483
Joined: Tue Oct 17, 2006 3:27 pm
Location: España / Spain

Post by Genete »

Hi, this is the most general movement that can be done with the camera in a AS 3D animation (using current 3D capabilities of AS).
Consider that this is a 2D projection and that the frame 1 and frame 2 positions of the target and the camera are 3D vectors.

Image

Anyway, as you said, first make a simple script and work on it to fit requierements.

I'll feed back asap.

-G
User avatar
Rhoel
Posts: 844
Joined: Fri Feb 25, 2005 8:09 am
Location: Phnom Penh, Cambodia
Contact:

Post by Rhoel »

Just did a test to discover that the XZ axis affect the stereo view. At start the L-R offset becomes a forwards/backwards move when the camera rotates 90 degrees.

So we have to introduce a sub-calculation to offset the rotation - it lools like a SIN calculation, not dissimilar to the one I make for calculating fairings. I'll dig out that file and look at it again. What we have to do is add a Z increment, decrease the X increment as the camera rotates. It sounds tricky but in fact should be too much of a problem.

I am on the laptop today as my main machine monitor blew up last night. The programming tools are on the main machine.

Hopefully have some kind of rough calc finished by mid week - hardware permitting


Rhoel

edit
-----
Just ran a quick paper calculation and the principal of adding sin(radians) to X channel, subtracting cos(radians) to the Z channel seem to work elegantly. All I have to do is code it :shock:

I will use an extreme shift of +1 for the Right camera, turning only on the 0.0 coord axis. If the calculation is correct, I should start with X=1, Z=0, then turn the camera through 90 degrees to get X= 0, Z=1.

By drawing the camera positions on a graph, I can predict what all the +/- numbers should be.

If this is not making sense, I blame it on a cold :-(

Goodnight

Rhoel 23:55
Last edited by Rhoel on Mon Feb 11, 2008 2:46 pm, edited 1 time in total.
User avatar
Rhoel
Posts: 844
Joined: Fri Feb 25, 2005 8:09 am
Location: Phnom Penh, Cambodia
Contact:

Post by Rhoel »

Okay, I have a working formula - I just need to tidy the code up to make it presentable.

Basically the Cosine(x) is used of one axis, and the sin(x) is used to the other.

x is in Radians.

so

Right Camera X correction (RX)
RX = Cos(deg2rad(rotation)), RZ = Sin(deg2rad(rotation)).

Left Camera,
LX = Cos(deg2rad(180 + rotation)), LZ = Sin(deg2rad(180 + rotation)).

Simple and elegant.

The XZ numbers are simply multpled by the stereo offset then added to the camera X, Z coordinates. If the stereo separation is 1 (the left camera is -0.5, the right camera +0.5), then RX frame 0 = +0.5 * 1 or +0.5.


Any tilt has no effect on the visual space.

I'll post the full report tomorrow with diagrams (maybe?. I have a bad cold and it's making concentrating a struggle).

BTW: I haven't taken into account any roll of the camera: That will take more testing.

Rhoel



Here is a print out of the full rotation in 22,5 degree increments:

frame | rotation | Cam RX | Cam RZ ...... Cam LX | Cam LZ
01: . Rot: 000 . RX: 1.00 . RZ: 0.00 ........ LX: -1.00 . LZ: 0.00
02: . Rot: 022 . RX: 0.92 . RZ: 0.38 ........ LX: -0.92 . LZ: -0.38
03: . Rot: 045 . RX: 0.71 . RZ: 0.71 ........ LX: -0.71 . LZ: -0.71
04: . Rot: 067 . RX: 0.38 . RZ: 0.92 ........ LX: -0.38 . LZ: -0.92
05: . Rot: 090 . RX: 0.00 . RZ: 1.00 ........ LX: -0.00 . LZ: -1.00
06: . Rot: 112 . RX: -0.38 . RZ: 0.92 ........ LX: 0.38 . LZ: -0.92
07: . Rot: 135 . RX: -0.71 . RZ: 0.71 ........ LX: 0.71 . LZ: -0.71
08: . Rot: 157 . RX: -0.92 . RZ: 0.38 ........ LX: 0.92 . LZ: -0.38
09: . Rot: 180 . RX: -1.00 . RZ: 0.00 ........ LX: 1.00 . LZ: -0.00
10: . Rot: 202 . RX: -0.92 . RZ: -0.38 ........ LX: 0.92 . LZ: 0.38
11: . Rot: 225 . RX: -0.71 . RZ: -0.71 ........ LX: 0.71 . LZ: 0.71
12: . Rot: 247 . RX: -0.38 . RZ: -0.92 ........ LX: 0.38 . LZ: 0.92
13: . Rot: 270 . RX: -0.00 . RZ: -1.00 ........ LX: 0.00 . LZ: 1.00
14: . Rot: 292 . RX: 0.38 . RZ: -0.92 ........ LX: -0.38 . LZ: 0.92
15: . Rot: 315 . RX: 0.71 . RZ: -0.71 ........ LX: -0.71 . LZ: 0.71
16: . Rot: 337 . RX: 0.92 . RZ: -0.38 ........ LX: -0.92 . LZ: 0.38
17: . Rot: 360 . RX: 1.00 . RZ: -0.00 ........ LX: -1.00 . LZ: 0.00
User avatar
Rhoel
Posts: 844
Joined: Fri Feb 25, 2005 8:09 am
Location: Phnom Penh, Cambodia
Contact:

Post by Rhoel »

The roll of the camera will affect the output - in the extreme case where the camera is inverted, the L-R cameras will be reversed - that means we have to add the X,Y roll rotation to the maths.

Considering how infrequnently people use the roo, is this something we do now or later?

Rhoel
Post Reply