View Full Version : z-up to y-up crisis
davestewart 03-14-2008, 07:30 PM Hey everyone,
I've resurected some old export routines I used to use for max to After Effects for another project, but to be completely honest I'm a bit rusty on the ole 3D.
Position is fine, a simple case of swap the Y and the Z, then negate the Z in the new coordinate system.
What is really frying my noodle is the rotation though. There's this extra 90 degrees that comes from somewhere, and I'm not sure what to do with it. I've seen various bits of advice on the web, bu I'm not sure how to translate that into useable code.
Do I do the rotate just on the X value, or with an entire matrix?
I'd really appreciate some help here. I've said I can do the job, now I'm feeling under a lot of pressure to complete, and I'm hacking around and getting near, but not near enough.
Many thanks,
Dave
|
|
All you have to do is multiply your vector or matrix from the Z-up system with the transformation matrix which converts Z-up into Y-up:
yUp = someZupVectorOrMatrix * matrix3 [1,0,0] [0,0,1] [0,-1,0] [0,0,0]
This flips the axes by taking the +Z as +Y and the +Y as -Z and will convert rotation and scale parts correctly, too.
To convert from Y-up back to Z-up, just use the inverse() of the conversion matrix above which is
zUp = someYupVectorOrMatrix * matrix3 [1,0,0] [0,0,-1] [0,1,0] [0,0,0]
davestewart
03-14-2008, 09:19 PM
Hi Bobo,
Thanks for replying! I couldn't post for half an hour or so, but I'm checking it out now.
I'm sure I'll be back in a mo with another question... ;)
davestewart
03-14-2008, 10:08 PM
Hi Bobo,
Ok - the position looks great, but I just don't seem to be getting the rotations I'm apparently supposed to be getting.
According to the developer who's buildling the engine in Flash, if a FreeCamera is facing forwards (ie, looking the same way the front viewport is looking) it should have a rotation of [0,0,0].
However, with your matrix the rotation is [-180,0,0].
Adding 180 degrees solves the problem, and the camera then faces the other objects we've created, but then the world then appears upside down, and rotations in X appear to go the opposite way to the camera in max (ie, when it's supposed to look up, it looks down)!
Any ideas what I'm missing, or maybe he's missing?
Thanks,
Dave
davestewart
03-15-2008, 01:27 AM
Hello,
Not sure if anyone is looking at this, but I'm battling through my Friday night / Saturday morning here - it would be really great if someone could chime in.
Thanks,
Dave
Hi Bobo,
Ok - the position looks great, but I just don't seem to be getting the rotations I'm apparently supposed to be getting.
According to the developer who's buildling the engine in Flash, if a FreeCamera is facing forwards (ie, looking the same way the front viewport is looking) it should have a rotation of [0,0,0].
However, with your matrix the rotation is [-180,0,0].
Adding 180 degrees solves the problem, and the camera then faces the other objects we've created, but then the world then appears upside down, and rotations in X appear to go the opposite way to the camera in max (ie, when it's supposed to look up, it looks down)!
Any ideas what I'm missing, or maybe he's missing?
Thanks,
Dave
I might have provided the matrices incorrectly - try swapping the two and see if you are getting correct results. It was from top of my head, not tested...
davestewart
03-15-2008, 01:51 AM
Hi Bobo,
Now the Y rotation is flipped, and the Y position is also flipped.
It's almost like the result of the first solution needs to be reflected through the Y-Up Z axis (as when you look out on the scene through the newly transformed coordinates, the pitch up / down is flipped).
Imagine putting your arm through the screen as if you were pushing an inside-out sock the right way out - does that make sense?
Hi Bobo,
Now the Y rotation is flipped, and the Y position is also flipped.
It's almost like the result of the first solution needs to be reflected through the Y-Up Z axis (as when you look out on the scene through the newly transformed coordinates, the pitch up / down is flipped).
Imagine putting your arm through the screen as if you were pushing an inside-out sock the right way out - does that make sense?
Hmm.
If I create a free camera at the origin pointing DOWN the -Z axis and multiply its transformation by the matrix, I get a camera pointing along the +Y axis (which is the -Z axis in Y-up systems = Front). The Max camera, in order to look into the Front viewport, has to be rotated at 90 degrees to match its local -Z axis with the +Y of the world. By default, it just looks down.
Is the problem you are seeing related to ALL objects or just cameras?
Please note that I am leaving the office now and will be back online in about 2 hours.
davestewart
03-15-2008, 02:46 AM
Hi again Bobo.
I really appreciate you taking the time to help me out as I'm clearly out of my depth on this one!
I'm not sure if I can answer your question about ALL objects or only cameras, as the engine I'm working with only allows me to import 2 kinds of objects; a 15x15x2 tile that makes up a grid of tiles that gets blown around by exported PFlow particles, and a virtual camera to look at said particles.
(FYI the engine is called PaperVision 3D - you may have seen some 3D Flash sites recently - most of them, eg Sony Bravia, are taking advantage of this new engine).
With your camera example, I get the same results you do.
So if my camera is pointing into the front viewport (the same way I am looking at the screen), the rotation value in max is [90,0,0].
The equivilent rotation value in the Y-Up system (for the camera to be looking the same way - into the screen) woudl be as [0,0,0].
So, if I then run the first matrix, the max camera rotates 90 degrees, and points upwards, and the rotation reads [+/-180,0,0].
For position values that are not [0,0,0], the X, Y & Z position appear to be correctly swapped, but it's this +/-180 rotation that has me stumped, as it doesn't sit nicely with the "looking forward" ideal in the new system, of [0,0,0].
Actually - if I look closely at the camera now in max, it's FOV cone is now coming out the BACK of it!
Is it this initial 90 that is throwing everything out? I don't have the experience you have in this area to help too much :(
It's about 2:45am here, so probably best I hit the hay.
I'll catch up with this thread in the morning.
Cheers,
Dave
The Max Camera and the Y-up Camera are inherently different in respect to their worlds, and the funny thing is that this difference is caused by the fact that they are identical in their working!
A Free Max Camera with no transforms (identity matrix) always points down the -Z axis.
A Free Camera in any Y-up world looks at the Front view along the -Z axis of the Y-world.
The problem is that while the worlds have different axis configurations and the OBJECTS in them also align to these axes, the Cameras in both look at the world with their -Z axes, using the X as the width and the Y as the height of the projection plane.
In fact, the main reason for the existence of the Y-up world is to align to a default camera looking at the Front view instead of the Top!
Thus, if a teapot is created in Max with no transforms and converted to Y-up, its axes will change (the vertical axis will change from Z to Y, the Y will change to -Z and X will remain the same), but the mesh will convert correctly and it will LOOK the same in both worlds.
But in the case of a camera, a camera looking down in Max turns into a camera looking at Front in Y-up world, which is a difference of 90 degrees about the X axis. So you will have to compensate for these 90 degrees for Cameras only.
davestewart
03-15-2008, 02:55 PM
Aha... a full and more than satisfactory explanation! Thanks.
The only thing is - can you give me a clue as to how I would go about creating this "special case" for cameras!?
I hate to ask, but my export pipeline is such a pain - it feels like sword-juggling blindfolded - I don't have a choice what I can give the engine, so it's difficult / impossible to produce test scenes at this time.
Do I just add / subtract 90 to the world rotation value of the camera in X, or do I need to rotate the matrix? (I'm assuming the first solution, as a matrix solution would alter position, right?)
As well, I don't have the firmest grasp on cumulative transforms down a hierarchy. At the moment I'm doing everything in world space to try and resolve any hierarchical issues that will arise.
In the meantime, I'll be trying different solutions based on your input.
Thanks,
Dave
Just out of curiosity, have you tried NOT converting the camera at all? What orientation do you get?
davestewart
03-15-2008, 03:33 PM
I'm really not getting this now.
I'd been playing with rotateXMatrix -90 and had figured that it was the same as
matrix3 [1,0,0] [0,0,-1] [0,1,0] [0,0,0]
which is the inverse (that's right, isn't it?) of your original matrix.
So applying the first matrix: mainly good. Positions are correct, all rotations except X are also good.
Then applying the second matrix: the camera is reset to it's original TM, rather than just correcting the 90 degree switch.
I'm having a play with xFormMat, but I'm really just hacking.
davestewart
03-15-2008, 03:34 PM
Just out of curiosity, have you tried NOT converting the camera at all? What orientation do you get?
Hmm... I'll try this to see what happens.
(Most likely it will point down, and not front in the new coordinate system.)
Hmm... I'll try this to see what happens.
(Most likely it will point down, and not front in the new coordinate system.)
Actually, a camera in Max looking at the front view is equivalent to a camera looking down transformed by the Yup matrix (rotation at +90 degrees). So if a camera pointing down transforms into camera pointing Front, a camera pointing Front should transform 90 degrees more into a camera looking up. Thus, try multiplying by (rotateXmatrix -90) ONLY without the other transform and see what happens. That would turn a camera looking front in Zup into a camera looking down in Zup, which should result in a camera looking front in Yup.
davestewart
03-15-2008, 03:48 PM
Thus, try multiplying by (rotateXmatrix -90) ONLY without the other transform and see what happens.
I'm thinking the same thing. Perhaps I need to separate the two lots of transforms to get the correct data.
Also - does this help - I'm getting so pissed off with these rotations (Y and Z are fine, but X being inverted) that I asked the Flash dev to tell me what does what, so I could compare with Max:
A positive rotation on eaach axis causes the camera to look:
Max Papervision
X Up Up
Y Clockwise Right
Z Left Anti-clockwise
davestewart
03-15-2008, 04:00 PM
Perhaps I need to separate the two lots of transforms to get the correct data.
I'm doing some tests with separating the 2 transforms, using rotateXMatrix and things are looking positive. Only single axis and numebrs at the moment, and I'm needing to swap mnius signs here and there, but the figures look good (ie, I can relate them to the table above)....
davestewart
03-15-2008, 04:14 PM
Actually, a camera in Max looking at the front view is equivalent to a camera looking down transformed by the Yup matrix (rotation at +90 degrees). So if a camera pointing down transforms into camera pointing Front, a camera pointing Front should transform 90 degrees more into a camera looking up. Thus, try multiplying by (rotateXmatrix -90) ONLY without the other transform and see what happens. That would turn a camera looking front in Zup into a camera looking down in Zup, which should result in a camera looking front in Yup.
This is beginning to make sense to me now.
As the Max camera has already been rotated 90 degrees in max to make it look front, then is rotated again in the Y-up-export, it gets rotated a total of 180 degrees - just to do nothing!
Which is why I was needing to compensate in Flash...
katisss
03-17-2008, 12:22 AM
seems to work with maya, thank you a lot.
Except when the object has nonuniform negative scale.
Is it supposed to workfor that case, too?
gasmasocet
03-17-2008, 12:30 PM
I did camera transfer scripts, check the code, there are a lot of answers about rotations, btwn, did you check ROT ORDERS.....
http://scriptspot.com/3ds-max/camera-i-o
davestewart
03-17-2008, 12:43 PM
Hi Daniel,
Great! I'll have a check when I get home from work later.
Thanks for chiming in,
Dave
davestewart
03-20-2008, 10:21 PM
I just wanted to say thanks for your help Bobo. The split approach worked for me on this occasion. I basically grabbed the position and rotation separately, did differeing matrix transforms on each, then exported one of each for each frame of the animation.
I don't know if this is the best way, but it works when everything else didn't, and that's good enough for us.
Daniel, I haven't had a chance to dig through your files, but thank you also for another angle.
Cheers,
Dave
CGTalk Moderation
03-20-2008, 10:21 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.