PDA

View Full Version : Davey, I need your big brain, I am flippin out!



Digits
10-03-01, 11:22 AM
Hi Davey

I am trying to write a flip routine and a mirror routine and I am running into a bit of a problem. I have deduced that an object can be rotated from -180 to 180 degrees on each of its axis thereby rotating it a full 360 degrees. However, when I try to set certain values the object seems to have a mind of its own and seems to cause other axis changes when certain values are entered for the object. This routine will show that. example try putting 45, 45, 45 into x,y, and z rotation and then flip it. You would think that (least my little brain thinks) that the answer should be -135, -135, -135

When you find the time perhaps you can give me the scoop on how this rotation rotates

Thanks!


<BLOCKQUOTE>quote:</font><HR>
[IButton,"Flip","Flip an object 180 degrees",
[RoutineCall,doFlip]
]
[RoutineDef,doFlip,
//Flip an object 180 degrees
[Vardef,rx,0]
[Vardef,ry,0]
[Vardef,rz,0]
[Vardef,rxs,0]
[Vardef,rys,0]
[Vardef,rzs,0]
[Vardef,rxr,0]
[Vardef,ryr,0]
[Vardef,rzr,0]
[if,[IsEnabled,transform:Move],
//get current rotation values
[TransformGet,rx,ry,rz,rxs,rys,rzs,rxr,ryr,rzr]
//add 180 degrees
[VarSet,rxr, rxr + 180]
[VarSet,ryr, ryr + 180]
[VarSet,rzr, rzr + 180]
[Note,"Add 180 ",,-1]
[note,"X ",,-1]
[note,rxr,,-1]
[note," Y ",,-1]
[note,ryr,,-1]
[note," Z ",,-1]
[note,rzr,,0]
//if greater than 180 bring it around to neg 180
[if,rxr &gt; 180,[VarSet,rxr,(rxr - 180) - 180]]
[if,ryr &gt; 180,[VarSet,ryr,(ryr - 180) - 180]]
[if,rzr &gt; 180,[VarSet,rzr,(rzr - 180) - 180]]
[note," Adj ",,-1]
[note,"X ",,-1]
[note,rxr,,-1]
[note," Y ",,-1]
[note,ryr,,-1]
[note," Z ",,-1]
[note,rzr,,0]

//set rotation to object
[TransformSet,rx,ry,rz,rxs,rys,rzs,rxr,ryr,rzr]
[note,"read result ",,-1]
[note,"X ",,-1]
[note,[Iget,transform:info:xcomponent],,-1]
[note," Y ",,-1]
[note,[Iget,transform:info:ycomponent],,-1]
[note," Z ",,-1]
[note,[Iget,transform:info:zcomponent],,0]
,//else
[Note,"Must be holding an object in either Move, Scale, or Rotate",,0]
]
]
<HR></BLOCKQUOTE>

Kathy
10-03-01, 12:55 PM
Wow.
Something went WHOOOSH!! right over my head and slammed into the wall behind me.... ;)

Digits, you are WAY too smart. :cool:

Digits
10-03-01, 01:50 PM
Sometimes I think it is too dangerous for the world if I get up in the morning, El Stoopido mi nombre.

First off, ridiculous to flip all 3 axis, turn a paper over left to right, then bottom to top, then turn in 180 like a steering wheel and you will see what I mean :)

Still there be mystery here, here is a new script with axis switches used for flip. Seems so far to be adequate to flip it the best using only the X axis

Also if you want to attempt to mirror the object press the mirror switch, doing so removes any functionality of the xyz switch but attempts to mirror the object by negating its current rotation values.

mirrortest.txt (http://www2.zbrushcentral.com/zbc_uploads/user_file-1002142007ktw.txt)

This appears to work sometimes depending on the object in world space. Maybe a few more cups of coffee, a can a coke and some stale moldy pizza will get the brain cells back in marching order.

Pixolator
10-03-01, 02:44 PM
Hi Digits :)
Here is the simplest ‘flip’ function…

[IButton,FlipXZ,,
[TransformGet,posX,posY,posZ,sizeX,sizeY,sizeZ]
[TransformSet, , , ,-sizeX, , -sizeZ]
]

This works because ZBrush (internally) allows scaling of an object to be negative, in essence, causing the object to be flipped on its specified local axis (unrealistic phenomena but mathematically acceptable).

You may use any combination of negative/positive axis and if the number of flipped axis is odd (1 or 3 axis flipped) you would need to flip the in/out facing polygons by pressing the Tool ::Modifiers ::Flip or activating the Tool ::Modifiers ::Double . Here is an example…

[IButton,FlipX,,
[IPress,Tool ::Modifiers ::Double]
[TransformGet,posX,posY,posZ,sizeX,sizeY,sizeZ]
[TransformSet, , , ,-sizeX]
]

I hope that this removes the need for the “stale moldy pizza” :)
-Pixolator

Digits
10-03-01, 03:19 PM
Thanks Pixolator! You saved me from my second slice :) Your solution is simple and elegant, just what I like!

No more holding up invisible cubes in front of my face and twisting them around, I have gotten more than a few puzzled looks from my fellow employees here :)

To celebrate I'm ordering new pizza!

davey
10-03-01, 03:49 PM
Ug! Hard question make big brain hurt!

Well, it looks like I've joined the conversation too late because I had to tank up on coffee and stale pizza first :)

You've clearly found your answer, either using the Mirror button (shown here) or changing the appropriate size components to negative values.
http://www2.zbrushcentral.com/zbc_uploads/user_image-1002148542kgk.jpg

If this helps, here's a brief explanation on what's going on with the angles in the Transform:Info sliders...

When you first draw a 3D object (here an Arrow3D) on a blank canvas, it's facing you dead on and looks like this:
http://www2.zbrushcentral.com/zbc_uploads/user_image-1002148610acv.jpg

You'll notice the X angle and the Y angle are both 0, and the Z angle is some number depending on how you drew it. Here it's 0.

To rotate it so it's pointing up and to the right, you don't need to change all 3 angles, just the X and the Y. Here's what 30,60,0 looks like:
http://www2.zbrushcentral.com/zbc_uploads/user_image-1002148720nbw.jpg

To illustrate, I'll put pushpins in each intersection of the Gyro:
http://www2.zbrushcentral.com/zbc_uploads/user_image-1002148761zbh.jpg

To get to this orientation, the cyan (X) pushpin was twirled 30 degrees, then the magenta (Y) pushpin was twirled 60 degrees.

Think of twirling the yellow pin (the Z axis) -- the orientation of the object doesn't change, it just spins around. To point it elsewhere, you should start with Z at 0, and twirl the cyan X and magenta Y pushpins to point it where you'd like it.

The reason the sliders act so screwy is that the rotation angles aren't stored in ZBrush; they're converted to trigonometric values (normals), and then converted back when you view the sliders.

My best advice when scripting the angles is, don't worry about the Z component, just use X and Y to change the object's orientation. Use Z to determine how much the object is "spun".

Believe me, I've wrestled with this dilemma before. Let me know how your efforts turn out. I'm sure you're much better at figuring out the math than I am -- most of my "big" brain is full of Gilligan's Island reruns.

dave

Digits
10-03-01, 04:46 PM
Thanks Davey, that sheds a little more light for me. I guess I should explain what I am trying to do, I can only blame my brain because it seems like it should be easy, maybe I should try those gilligan reruns instead of I Love Lucy, seems to work good for you.

Pixolator's inside out solution is great except when one of the uses I have planned for it involves Interpolation. This image shows what I want and shows what happens when you turn a cube inside out!

http://www2.zbrushcentral.com/zbc_uploads/user_image-1002152147jil.jpg

What I want to do is to be able to take an object no matter where it's axis is pointing and orientate it much like when you use the Flip Horizontal in the Layer:Modifications.

I have come real close just by making the rotation Axis values negative but it also depends on the starting orientation of the object. For instance if the object is pointed up and I flip the Xaxis the object is flipped but is looking down. Rotating 2 axis takes care of that but not for all cases. Maybe it will have to take some User Smarts to select the correct axis, hence axis switches because I haven't come up with a solution to automatically make the calculation. You have no idea how many Math courses I have flunked heheh, when I need math I look it up in a book. :) But this one doesn't seem to be in any books!

Just realized the above image doesn't accurately show what I am trying to do.
http://www2.zbrushcentral.com/zbc_uploads/user_image-1002154378bqe.jpg

the second cube is rotated 180 and then pointed down just like the first cube.

I realize it all can be accomplished pretty easily without code, but you know how it goes

davey
10-04-01, 11:38 AM
Still not sure if this'll solve your problem, but here's a try:
http://www2.zbrushcentral.com/zbc_uploads/user_image-1002220262lhd.jpg

The arrow isn't mirrored, but rotated by increments. In each line, the X and Z components don't change, just the Y component.

This is done with a ZScript (provided below); if you watch the slider values (after each arrow is drawn a note appears showing slider values), they get a little strange, but the simple answer is, don't worry about what the sliders say.

What you might try is this: check the Y rotate value after each transformation. The first time the sign changes (- to + or vice versa), press the Mirror button.

I imagine I've missed something in your post, but I humbly offer this as a beginning toward a solution.

Howz that?
dave

Nikko
10-04-01, 12:36 PM
This stuff is SO, SO far over my head.... :rolleyes:

Digits
10-04-01, 02:20 PM
Thanks so much Davey for pickin your noodle, I have learned answers to a few questions. Sorry that wasn't all too clear yesterday, seemed like more than one question interfering with the gist of it. I don't think it is possible to do what I envisioned unless it is a standard basic tool such as the Arrow3D for example. We know that the tip of the Arrow is aligned with the Z-Axis, and I have discovered one way to mirror its alignment is just to negate the Y Axis Rotation value, easy!

A User's tool for instance, a Modelled head may not have the Z-Axis aligned with the Pointy end, so to speak, and may even been moved during modelling so that it comes out the left nostril! Plus the thing is asymmetrical meaning more than one axis has to be taken in account. Trying to figure out an algorithm to produce a mirror I think is a hopeless endevour.

To use this function would mean that preparation would have to be taken to rotate the XYZ angles of the head to World Space in the Deformation Palette.

Pixolator's Inside Out solution is the real jewel of this thread!

http://www2.zbrushcentral.com/zbc_uploads/user_image-1002230354xhi.jpg

In this image you can see I can make the arrow mirror itself with not a proble. The head however works at a certain spot but not anywhere else :)

Anyhoo, I am sure I will have more questions, it is sure nice to be able to talk to the horses!