ZBrushCentral

[TransformSet Gimbal Lock Workaround]

[EDIT: original question deleted]

I have sort of found a solution or workaround to the gimbal lock problem that allows you to circle around the mesh without flipping it using TransformSet. Basically what I do is to switch the Y-axis with the z-axis of the mesh. You can do that by applying a -90 degree X Rotation using the deformation slider(tool->deformation->rotate). You need to do this only ONCE prior to animation.

Then you can undo that transformation by calling TransformSet with an X-rotation of +90. You can freely circle around the mesh now using the Z component of TransformSet instead of the y component. For instance:
[TransformSet, (Document:Width*.5), (Document:Height*.5), 0, 100, 100, 100, 90, 0, 90]

this will rotate your mesh 90 degrees around the y axis without flipping it. Rotation around X axis can also be done you just have to always add 90 degrees to make up for the initial -90 degree deformation rotation.

When you got subtools you need to deform all of them using (tool->deformation->rotate) and then you need to (manually) reposition them again. You only have to do it once though prior to animation.

Hi there!

All of this is feasible with zscript yes. If you have ANY programming background zscript should be a breeze for you. The best place to start is probably here: http://www.pixologic.com/docs/index.php/ZScript_Command_Reference

This has all the available commands as well as links to the “Getting Started” guides.

As for tips on how to do the things you want…

-To manipulate the mesh on the canvas you will probably want to use the TransformGet and TransformSet command. To center it in the doc you could use Transform>Fit and and then TransformSet with a 0.5 scale.

-To save a Tiff file you will be using a command [FileNameSetNext] which will set the file name (obviously) for the next save action.

  • I would put all of the steps 1-5 in a [Routine] and then call the routine in the loop.

  • You can set the loop count to 35 and then adjust the TransformSet yrotation +10.

Let me know if you have any more question.

Thank you!

That’s already some information I can use. I will look into it and post again in case
I need some further assistance.

May the force be with you :+1:

Already got some first questions:
I am trying the SetTransform command and am I right to assume that this transforms only the mesh, right?
not the camera? Is there even a camera object in zbrush?
So this means that when I rotate the model using setTransform this is not the same as circling around the model
since the lighting setup will be the same for all viewpoints, right? What if I want the light to be recalculated
do I need to transform the lights position then?

And how do I transform all subtools of a mesh? is that even possible? or do I have to transform each subtool
individually?

SetTransform doesn’t work properly it turns my mesh upside down on some angles? So what is the best
way to get a transformation that works for all possible angles?

Yes TransformSet only transforms the mesh. No there isn’t a camera object that you can manipulate (other than FOV and stuff).

You are correct that the lighting will stay the same. I tried once to manipulate light position via script and it didn’t really work. I don’t think there is a way unless you carefully script some mouse strokes to move the light each time. Or you could save a lights file for each angle and load each one before the render. Both options are pretty crazy haha!

I thought Transform moves the entire Tool? It’s been a while since I used the Transform commands. I can’t remember exactly the quarks of it.

Probably the best way is to make sure the model doesn’t flip is to have the user snap the Tool to front and only adjust the y-rotation.

Have you thought about use using the native turntable features in Zbrush?

The problem with SetTransform seems to be that it uses euler angles for rotation and unfortunately these
suffer from the “gimbal lock”. If you rotate around the y-axis the mesh gets flipped at certain degrees.
But that’s not the only problem SetTransform seems to suffer from. When I execute my script again and
again it seems to offset the angles more and more…

No unfortunately both zbrush’s turntable function and the script turntable+ don’t offer the functionality I need.

I have sort of found a solution or workaround to the gimbal lock problem that allows you to circle around the mesh without flipping it using TransformSet. Basically what I do is to switch the Y-axis with the z-axis of the mesh. You can do that by applying a -90 degree X Rotation using the deformation slider(tool->deformation->rotate). You need to do this only ONCE prior to animation.

Then you can undo that transformation by calling TransformSet with an X-rotation of +90. You can freely circle around the mesh now using the Z component of TransformSet instead of the y component. For instance:
[TransformSet, (Document:Width*.5), (Document:Height*.5), 0, 100, 100, 100, 90, 0, 90]

this will rotate your mesh 90 degrees around the y axis without flipping it. Rotation around X axis can also be done you just have to always add 90 degrees to make up for the initial -90 degree deformation rotation.

When you got subtools you need to deform all of them using (tool->deformation->rotate) and then you need to (manually) reposition them again. You only have to do it once though prior to animation.

Turntable Plus uses a little trick to avoid gimbal lock. It simulates a mouse drag on the canvas to turn the model. You need to set the axis of rotation in the Transform palette (usually Y). You also need to set the Preferences:Interface:Rotate Speed to a suitable value depending on the amount of your mouse drag. And the canvas zoom used to affect the result so that should be set to ‘Actual’.

[IClick,1004,-4096,-4096,-4096+(shift),-4096]//‘1004’ is the numerical ID of the canvas

where ‘shift’ is the amount you want to drag the mouse. The negative values just keep the drag off the document.

Also, could you not edit your posts to change the content? Their usefulness for others is greatly reduced if they don’t know the original question. Start a new post if you have something new to ask.

Thanks,

Ah very cool.

Neat trick Marcus. I wouldn’t have thought about that. Is that the way you made the “Spinner” script that rotates the model with a hotkey?

Turntable Plus uses a little trick to avoid gimbal lock. It simulates a mouse drag on the canvas to turn the model. You need to set the axis of rotation in the Transform palette (usually Y). You also need to set the Preferences:Interface:Rotate Speed to a suitable value depending on the amount of your mouse drag. And the canvas zoom used to affect the result so that should be set to ‘Actual’.

[IClick,1004,-4096,-4096,-4096+(shift),-4096]//‘1004’ is the numerical ID of the canvas
where ‘shift’ is the amount you want to drag the mouse. The negative values just keep the drag off the document.

Yes I also tried this. But this is not something I could use since I needed to work with absolutely exact angles.

Also, could you not edit your posts to change the content? Their usefulness for others is greatly reduced if they don’t know the original question. Start a new post if you have something new to ask.

I usually don’t do that but in this case I changed it to contain only the essential information needed to complete the task. Anyone who wants to make a turntable or so will easily find the information that meshes can be rotated using TransformSet(and the other stuff I asked). And sooner or later that lucky guy will run into the gimbal lock problem just like me. And I did not find sufficiently explanatory information on the board here how to address this problem. So I figured it would be easier to find this way… but nevermind…