ZBrushCentral

Question: Why TransformSet is rotating the model in other directions?

Hi, this is my first post here and also my first time creating a Zplugin.

Im developing a plugin to export Turn Around images of the model for showing advance to supervisors.

Im starting a new document size and creating 4 consecutive snapshots of the model rotating in the canvas. For doing this Im using a Loop that increments the rotation of the TransformSet by 90 degrees Y in each loop, but Im having something weird happening. The TransformSet at 90 and 180 degrees is rotating the model also in Z by 180 degrees and I can not figure why. ( Example image below)

My loop code is this one:

[Loop, 4,

            [CanvasClick,0,0,0,4]

            /* If it is the last view, turn in only 35 degrees for a 3/4 view */

            [If, LoopCount==3,

                [TransformSet,

                ([IGet, "Tool:Turn Around Snapshot:Left Padding"]+(LoopCount*[IGet, "Tool:Turn Around Snapshot:Offset"])),[IGet, "Tool:Turn Around Snapshot:Top Padding"],0,

                [IGet, "Tool:Turn Around Snapshot:Scale"],[IGet, "Tool:Turn Around Snapshot:Scale"],[IGet, "Tool:Turn Around Snapshot:Scale"],

                0,-35,0

                ],

                //else keep rotating the model 90 degrees for the other views.

                    [TransformSet,

                    ([IGet, "Tool:Turn Around Snapshot:Left Padding"]+(LoopCount*[IGet, "Tool:Turn Around Snapshot:Offset"])),[IGet, "Tool:Turn Around Snapshot:Top Padding"],0,

                    [IGet, "Tool:Turn Around Snapshot:Scale"],[IGet, "Tool:Turn Around Snapshot:Scale"],[IGet, "Tool:Turn Around Snapshot:Scale"],

                    0,LoopCount*90,0

                    ]

                    

            ]

            /* New Polygroup color */

            [IPress, "Tool:Polygroups:Group Masked Clear Mask"]

            /* Take snapshot */

            [IPress, "Transform:Snapshot"]

            ,LoopCount

        ]

Im using the sliders values to calculate de offset and scale of each view in the canvas, but the rotation values of TransformSet are the ones causing the problem. As you can see, when is the last view it only rotates the model -35 degrees to get a 3/4 view, but the other 3 views rotation is controled by the counter inside the loop multiplied by 90 degrees (LoopCount*90). So in the first loop rotation in Y is 0, second loop is 90 and third loop 180.

I was curious about why so I incremented the Loop loops (hehe) and something interesting happened. Every two views the rotation is changed also in Z, the 90 and 180 degree ones.
image

Does someone have a clue about what could be happening here?

Thanks in advance.
Ness.

Hi @Nesskap,
I had been able to reproduce your issue with a custom script,

Note for (@marcus_civis)
transformSet for xrot and yrot do not works, but only on zrot
I use the MTranformGet /MTranformSet instead, then it works like you on X/Y and Z axis.

The Issue which happen here with the transform set is the global lock issue like explained here in that old topic :


the issue happen on yrot in the approximated range of ~90 to ~225 degree.
So the idea in my script is to compensate on the Z Axis to reverse the model if yrot is between 90 and 225 degree.

Here is my

[IButton, "???", "Snapshot capture model rotation of 45 degrees and and offset of 150.",

    [VarSet, offset, 150]
    [VarSet, ratio, 45]

    [MVarDef, canvas_transform, 9, 0]
    [MTransformGet,canvas_transform]
    
    [VarSet, a, [MVarGet,canvas_transform,0]]
    [VarSet, b, [MVarGet,canvas_transform,7]]
    [VarSet, c, [MVarGet,canvas_transform,8]]

    [Loop, 9,
        [If, (n == 0),
            ,//else
            [VarSet, a, [Val,INT(a+offset)]]
            [VarSet, b, [Val,INT(b+ratio)]]
            // when 360 then set to 0
            [If, b == 360, [VarSet, b, 0]]
            // prevent grimbal lock issue
            [If, b == 90,
                [VarSet, c, -180]
            ]
            [If, b == 270,
                [VarSet, c, c-180]
            ]
           [Note, [StrMerge, "a::", a, ">", "b::", b, ">", "c::", c, "\n"],,-1]
	    [MVarSet, canvas_transform, 0,ABS(a)] 
	    [MVarSet, canvas_transform, 7,ABS(b)]
            [MVarSet, canvas_transform, 8, c]
            [MTransformSet, canvas_transform, 0]
        ]
        [IPress, "Transform:Snapshot"]
    ,n]
    [Note,]
    [MemDelete, canvas_transform]
,,1]

Note, there is a note, so you can see the value for each iteration of the loop.
comment or delete if if you don’t need it anymore.

Hope it helps!
Nicolas

1 Like

Hi @Facelessmindz !

Thanks a lot for your response, actually after some research I also found that old post mentioning the gimbal lock problem but I was not sure how to make it work. Now that I see how you solved changing the Z if the angle is between a range of values make a lot of sense.

My fast solution was to make every snapshot its own but I was not happy about knowing that with a loop I can write once the code. Again, thanks, I will try this now and update my script, also with the MTranformGet /MTranformSet I did not know existed, its more clean.

Have a great day!
Ness.