ZBrushCentral

Question: Why can't I programmatically click on the Rotate button to rotate the tool

I was trying to simulate the Rotate button being clicked and dragged in order to rotate the current tool on the screen.

I tried the following line of code

//buttonCenterX,buttonCenterY are set to the center of the button. that code
//not shown here

[IClick, Transform:Rotate Edit, buttonCenterX, buttonCenterY, buttonCenterX + 10, buttonCenterY + 10]

I can see that the Rotate button is pressed since it gets a little selection rectangle around it…but the object never rotates.

Any ideas for how to solve this is as always greatly appreciated.

Thanks,

mobbe

Yes, that won’t work (I don’t know why not). The alternative is to use a CanvasClick, making sure it’s off the canvas so it doesn’t affect the model:

[IButton,Rotate,,
[VarSet,amount,10]//set to pixel value you want
[CanvasClick,-4096,-4096,-4096+#amount,-4096+#amount]//drags mouse off canvas
]

You can use the Rotate on Axis buttons to set different rotate options if you wish, or different ‘amount’ variable seetings for H and V.

Thanks for your suggestion.

What I really wanted to do was to implement a virtual trackball…and instead of messing with rotate code I thought I could “cheat” and simulate clicking on the Rotate button. It probably would be more elegant to do this in code but I am having issues with the rotation scripts that I have found so far. I tried to use a script called PointFromTo that I think Pixolator created a long time ago but I am unable to get this to work for me.

Do you know of any scripts out there that implements a virtual trackball?

Your canvasclick idea works great for me though. This way I dont need to worry about all the issues regarding 3d rotation and just let zBrush figure that out instead…:slight_smile:

There’s no zscript way of doing what you want. Otherwise I think the only way you could do it is to create a separate application which simulates mouse movement in the ZBrush window.

Actually your reply in post #2 worked for me. I am able to rotate the tools (normal plus zSpheres) just fine using that technique. I took it a step further and wrapped the call in a IKeyPress with Shift as a modifier so I could get that snap to orthogonal effect. This also works good for regular tools.

However, I have an issue with the Shift and rotate when it comes to zSpheres. It doesn’t seem to want to snap to orthogonal angles it basically just stops whenever the shift is pressed.

I am trying to figure out a workaround but in the mean time if you have any ideas I could try out I definitely appreciate it. Is the logic of figuring out what orthogonal angle to snap to maybe easier than the more generic trackball algorithm I was looking for earlier?

Thanks,

mobbe.

If you want to set specific angles then it’s probably simpler to use the [TransformSet] command.

Yep. That is what I was thinking too. I would like to simulate the snapping to orthogonal though. However, currently I am not really sure how that algorithm would work. I wonder how ZBrush calculates which angle to snap to? I do have access to the tools’ X,Y,Z rotation so I know what direction the tool is facing…but how would you then know which orthogonal angle to snap too…

I tried the following and it almost works :-)…

I do the rotation using the method in post #2. I then check each rotation angle (x,y,z) and snap the angle to either 0,90,180 or 270 degrees and then uses the TransformSet method to set the new angles. This actually works pretty good but at certain times it looks like the “gimbal lock” makes its appearance and flips the model on its head. Maybe I can take my newly snapped angles and run them through Pixolator’s script where he accounts for the Gimbal lock. I know I have seen that script being referenced before so I will do some looking…

Just a quick update. I have the rotation working fine if I rotate around the X axis or the Y axis but problem when I have rotated first around the Y axis 90 degrees and then start rotating around the Z axis.

I check to see if the Y angle is ±90 degrees and in that case I set the Z angle to 180 degree. This makes it so that the model doesn’t flip when I have rotated around the Y axis.m If you picture the DemoSoldier model this is when the soldier has rotated facing the side but is still upright. If I start rotating him around the Z axis from this position then my snap logic doesn’t seem to work. The Z angle that ZBrush reports seems to be random as well. The same position can report multiple different Z values so I can’t really apply any logic here to compensate with a different value. First I thought that I could see how much rotation I had around the Z axis and based on that apply a compensation factor but since the values are inconsistent there is not much I can do…

I guess the gimbal lock issue has won this round…

/mobbe