Anim8or Community

Please login or register.

Login with username, password and session length
Advanced search  

News:

Ian Ross has just released a book on Anim8or. It's perect for a beginner and a good reference for experienced users. It contains detailed chapters on every aspect, with many examples. Get your own copy here: "Anim8or Tutorial Book"

Author Topic: RIBRobin  (Read 15322 times)

Raxx

  • Administrator
  • Hero Member
  • *****
  • Posts: 1482
    • View Profile
RIBRobin
« on: December 16, 2008, 01:26:36 pm »

For a while I've been wanting to dive into ASL and learn how to make useful stuff.

For a while I've been wanting to make a .rib converter for anim8or.

So I'm finally getting something done about it...it's nowhere near finished but I've got one good part done, actual meshes export properly (big thanks to Steve's export scripts as a foundation...the ASL documentation finally makes sense!).

My plan is to make it a toolset that allows you to use the object editor as a scene editor to make very nice still renders. I'll build shape plugin scripts where you can make a camera shape, light shapes, dummy shapes, etc where you can specify different parameters like camera FOV, light types and colors, shadows, and move and rotate the camera and lights like it was a real scene and it'll export it accordingly.


I might go one-sided and make it support only the Aqsis renderer (or something else I find) since it's free and easy to install. Making it dependent on a single renderman renderer will allow me to utilize the wowee features that are specifically built for them ;) but that's way in the future.

I'm not releasing anything yet. Once I get to the stage where it'll actually become halfway useful, then I'll start releasing the stuff. I'm just posting here my updates as I go along to keep things interesting.

I know one of you ASL/programmer junkies could probably whip out something better than what I've got so far like it's nothing but you just wait and see :P
Logged

mcheccyb

  • Full Member
  • ***
  • Posts: 173
    • View Profile
Re: RIBRobin
« Reply #1 on: December 17, 2008, 12:23:53 pm »

inspired by my post on CGN?

nice going so far. Looks very promising.

how will things like reflections and glass be configured?
Logged

Raxx

  • Administrator
  • Hero Member
  • *****
  • Posts: 1482
    • View Profile
Re: RIBRobin
« Reply #2 on: December 17, 2008, 06:13:57 pm »

Don't give yourself too much credit ;) I've been a fan of .rib rendering since the days of MarkW's standalone ManifoldLab application.

For now I'll be trying to read as much information as possible from the materials and translating that over. Then based on that I'll either let users customize attributes via attributes or generate dummy parametric shapes to handle the data.

I'm having a heck of a time with making a camera shape, a very nice learning experience for making cubes and cylinders to make a nice camera object. I keep getting inverted normals because of sloppy face creation though -_-

I have a general question...Is there something wrong with converting from int to float or using two ints in an expression to create a float, or something?

Say I have this:

Code: [Select]
int $width, $height;
float $aratio;
$width = 640;
$height = 480;

$aratio = $width/$height;

That should return "1.33333" but it seems to do something else entirely...when I output to console it gives me "<<int>>" and when I try using it in another expression it doesn't give me expected results. Maybe this is a basic or something where I need to convert between types so can someone point me in the right direction?

Logged

Kubajzz

  • Flying Platypus
  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 548
  • Little doggie ate my avatar...
    • View Profile
Re: RIBRobin
« Reply #3 on: December 17, 2008, 06:29:03 pm »

There are 2 ways to fix your problem. First, you can use float variables instead of int for width and height, but that's probably not what you want to do...

What you need is to make Anim8or evaluate your int expression as a float expression. This is what I usually do:
Code: [Select]
int $width, $height;
float $aratio;
$width = 640;
$height = 480;

$aratio = $width/($height*1.0);

I hope it helped... Good luck with your project!
Logged

Raxx

  • Administrator
  • Hero Member
  • *****
  • Posts: 1482
    • View Profile
Re: RIBRobin
« Reply #4 on: December 18, 2008, 07:04:33 am »

Thanks! I had a feeling it'd be something like that.


The only difference in look and feel between this camera and the scene camera are the reels on top

Camera shape is done and allows you to set the width, height, FOV, near clip, and far clip and when doing so the shape updates accordingly...now I'm stalled by the fact that you can't grab parameters from parametric shapes via scripts other than plugin scripts. This should be extended to any script! I've got some tricks to bypass the problem but it makes it 2x more difficult for me :P
Logged

Steve

  • Administrator
  • Hero Member
  • *****
  • Posts: 2124
    • View Profile
Re: RIBRobin
« Reply #5 on: December 19, 2008, 12:09:32 pm »

Good work Raxx.  (But camera "ears" are stealing something I have added for the next release!)
Logged

Francesco

  • Full Member
  • ***
  • Posts: 182
    • View Profile
Re: RIBRobin
« Reply #6 on: December 19, 2008, 01:26:05 pm »

Very good idea Raxx, wish you good time coding it - and by the way, there is always "a better way", so, as long as the program does the work, I wouldn't mind about getting it earlier or later, and neither I would mind about it being the "neatest" or the "hardest crucher" ;)

The model is great!
Logged

Raxx

  • Administrator
  • Hero Member
  • *****
  • Posts: 1482
    • View Profile
Re: RIBRobin, Help! (math)
« Reply #7 on: December 20, 2008, 01:39:04 pm »

Cool Steve, looks like we're on the same page ;) Nah, it just means I'll have to adjust my "ears" to fit yours exactly once you release it!

Francesco, thanks :) I know there's a better way and I'm stuck on a problem, perhaps some of you math/3d coordinate geniuses could help me out!

The problem is this: Apparently how the renderman spec works is that instead of moving and rotating the camera around the coordinate system, the entire coordinate system moves and rotates around the camera.

So I need help reverse calculating the camera's position and orientation and instead applying it to the 3D coordinate system. I've been looking up math formulas online but the stuff is just flying right over my head and I have yet to find something with all factors tied in...any pointers would be a great help.

If you guys are interested, here's some sample code to play with if you have ideas on how to turn it into the right equations and such:

Code: [Select]
shape $shape, $Cameras[0];
quaternion $orientation;
point2 $uv;
point3 $location, $CamRot;
int $width, $height;
float $FOV, $nearClip, $farClip;

/* Objects were sorted out beforehand and */
/* this chunk of code deals with the camera */

if ($Cameras.size == 1)
{
$shape = $Cameras.pop();

/* Since I couldn't read parameters from parametric shapes, */
/* I made the shape embed the data into the uv coords, and  */
/* it gets read by the export script                        */

/* Get meshdata and read the UV coords as parameters*/
$mdata = $shape.GetMeshData();
$uv = $mdata.GetTexCoord(0);
$width = $uv.x;
$height = $uv.y;
$uv = $mdata.GetTexCoord(1);
$FOV = $uv.x;
$nearClip = $uv.y;
$uv = $mdata.GetTexCoord(2);
$farClip = $uv.x;

/* Our camera's location and orientation */
$location = $shape.loc;
$orientation = $shape.orientation;

/* Code to convert the rotation quaternion into euler */
/* Special thanks to Leslie's post at                 */
/* http://www.anim8or.com/ubb/Forum1/HTML/014922.html */
$CamRot = (-atan2(2*$orientation.x*$orientation.w-2*$orientation.y*$orientation.z , 1 - 2*$orientation.x*$orientation.x - 2*$orientation.z*$orientation.z),
-atan2(2*$orientation.y*$orientation.w-2*$orientation.x*$orientation.z , 1 - 2*$orientation.y*$orientation.y - 2*$orientation.z*$orientation.z),
-asin(2*($orientation.x*$orientation.y + $orientation.z*$orientation.w)));

/* Convert from radians to degrees */
$CamRot = ($CamRot.x*(180/PI), $CamRot.y*(180/PI), $CamRot.z*(180/PI));
}
So pretty much the main things you have to work with is the point3 $location which is the x,y,z coordinates of the camera's origin, and the point3 $CamRot which is the x,y,z rotation for the camera. So now we have to pretend that the camera is the one staying still and instead the entire world around the camera is moving and rotating around it. Of course if it's easier then the quaternions can be worked on before being converted to eulers.

Note that all other shapes already have their relative offsets and rotations applied to them (via float4x4 transform matrix).

The way the camera/coordinate system in .rib files is written out is:
Code: [Select]
Translate X Y Z
The coordinate system moves to that position away from the camera

Code: [Select]
Rotate [Angle] X Y Z
I can't really tell if this is equal to an axis angle system or just eulers. Put in the angle it rotated on an axis, and set 1 for the axis it represents and 0 for the others. So if rotating the entire world 45 degrees on the X-axis, you do "Rotate 45 1 0 0"

Any hints, links or just plain solving would be greatly appreciated, and of course I'll give you credit in the script like I'm doing for Leslie :)
Logged

Francesco

  • Full Member
  • ***
  • Posts: 182
    • View Profile
Re: RIBRobin
« Reply #8 on: December 20, 2008, 02:21:10 pm »

Unfortunately I'm stuck on the inverse problem (converting from eulers to quaternion) for my BVH->AN8 conversion, and being that I'm not on firm ground with quaternions, I could really help to mess things up instead ;)

Let's hope on a tip falling from higher floors ;)
Logged

Francesco

  • Full Member
  • ***
  • Posts: 182
    • View Profile
Re: RIBRobin
« Reply #9 on: December 20, 2008, 02:41:36 pm »

Wait, I think I mistaken your problem.

If I got it right, you already have cam's orientation and position worked out, correct? Now the thing you want to do is to calculate the inverse orientation and offset of the entire scene (if I got it right once again).

I met a similar problem while working on the magnet scripts, and I ended up with this code (snipping another post of mine):

quaternion $mag_q, $clay_q;
$mag_q = $magnet.orientation;
$clay_q = $clay.orientation;

float4x4 $mag_rotmat, $clay_rotmat;
$mag_rotmat = toFloat4x4($mag_q);
$clay_rotmat = toFloat4x4($clay_q);

/* invert orientation quaternion for building inverse transformation */
$mag_q = ( -$mag_q.x, -$mag_q.y, -$mag_q.z, $mag_q.w);
$clay_q = ( -$clay_q.x, -$clay_q.y, -$clay_q.z, $clay_q.w);

float4x4 $mag_inv_rotmat, $clay_inv_rotmat;
$mag_inv_rotmat = toFloat4x4($mag_q);
$clay_inv_rotmat = toFloat4x4($clay_q);



If you want to, you can change a simple point go back and forth on the two systems using code like this:

/* translate clay point to magnet's coordinates */
$clay_p = $clay_rotmat.Project($clay_p) + $clay_l - $mag_l;
$clay_p = $mag_inv_rotmat.Project($clay_p);

...and back:
/* translate back clay point to clay's coordinates */
$clay_p = $mag_rotmat.Project($clay_p) - $clay_l + $mag_l;
$clay_p = $clay_inv_rotmat.Project($clay_p);


But if your problem involves changing the orientation quaternion of each object, then I think this link could help you more than me:
http://www.flipcode.com/documents/matrfaq.html

I did not face nor dig this passage in particular, but I think it's about multiplicating quaternions together... have a look and good continuation.

Logged