[Zbrush] [Zscript] Align camera to plane script -HELP!

insane polycounter
Offline / Send Message
TeriyakiStyle insane polycounter
Basically hoping someone can chime in and help me complete this script

EDIT> Solved down below 


Replies

  • TeriyakiStyle
    Offline / Send Message
    TeriyakiStyle insane polycounter


    I figured I only have to solve for x,y rotation to get what I want.

    When getting the normal info of a pixol under the cursor the ranges are x(-1 to 1) and y(-1 to 1)



    I can orient the values to 0,0,0 - The pixol is looking straight down the camera, and the camera is zeroed.



    The value ranges for xRot is -90 to 90
    Range for yRot is -90 to 180 (a little confusing as to why)

    Order of events I am planning so far:

    //Define Variables
    //Get Pixol normal info of x,y values "Px,Py"
    //Get current camera rotation of x,y "Xrot,Yrot"
    //Check <> of values to determine direction of rotations (plus or minus from Xrot, Yrot)
    //Convert Px and Py to rotation friendly values
    //Based on check results either add or subtract from the current rotation values.

    Result: View rotates X and Y to align the view to the sampled normal.

    Any help would be great - I'm learning this as I go thanks!
  • nyx702
    Offline / Send Message
    nyx702 Polycount Sponsor
    I'v tried messing with the weird transforms of zb before and I can never quite figure it out. I'v tried getting the normals of the transpose line and aligning stuff to that and it never works 100% either. I have not tried using the Pixol pick before however. 

    There are a few threads on ZBC about gimbal lock that I will re-read and then give up. 
  • TeriyakiStyle
    Offline / Send Message
    TeriyakiStyle insane polycounter
    Glad you showed up Nick save me!  I think I have the right data as in the normal direction of the pixol vs. the current rotation of the tool.  Just need to get them to talk to eachother.

    So for Xrot I think:
    If you get PixolX angle of .5 
    and multiply it by 90 = 45
    you then rotate the tool current rotation +/-45 to align to X
    could it be that simple?
  • TeriyakiStyle
    Offline / Send Message
    TeriyakiStyle insane polycounter


    pixols=px,py
    rotation=cx,xy

    so like... check 
    if py<0 rotate -cx
    else rotate cx
    if px<0 rotate cy
    else rotate -cy

    ??? <__<



    Result:

  • TeriyakiStyle
    Offline / Send Message
    TeriyakiStyle insane polycounter
    
    
    [IButton,???,"Rotate Y 15 Degrees",
    //Get current rotation X
    [TransformGet, xPos, yPos, zPos, xSc, ySc, zSc, xRot, yRot, zRot]
    //Check xRot and Rotate Y
    [If, xRot<0,[TransformSet, , , , , , , , yRot+15, zRot],
    [TransformSet, , , , , , , , yRot-15, zRot]]
    //Bind this to Numpad Hotkey
    ]
  • TeriyakiStyle
    Offline / Send Message
    TeriyakiStyle insane polycounter


    Tried to get xRot to work and it's getting stuck here, not sure why.

    [IButton,???,"Rotate 15 Degrees",
    //Get current rotation X,Y
    [TransformGet, xPos, yPos, zPos, xSc, ySc, zSc, xRot, yRot, zRot]
    //Check yRot and rotate x
    [If, yRot>0,[TransformSet, , , , , , , xRot+15, , zRot],
    [TransformSet, , , , , , , xRot-15, , zRot]]
    //Bind to Numpad Hotkey
    ]
  • TeriyakiStyle
    Offline / Send Message
    TeriyakiStyle insane polycounter


    This is as close as I got so far - bound to numpad 0. Can't seem to get the alignment right.

    [IButton,???,"Align View to Plane",


    [VarSet,xNorm,0]
    [VarSet,yNorm,0]
    [TransformGet, xPos, yPos, zPos, xSc, ySc, zSc, xRot, yRot, zRot]

    [VarSet,z,[PixolPick,1,[MouseHPos],[MouseVPos]]] 
    [If,z < 2800,

    [VarSet,xNorm,[PixolPick,6,[MouseHPos],[MouseVPos]]]
    [VarSet,yNorm,[PixolPick,7,[MouseHPos],[MouseVPos]]]

    ]

    [If,xNorm < 0,
    [TransformSet, , , , , , , , ((yRot)+(xNorm*90)), zRot]
    ,
    [TransformSet, , , , , , , , ((yRot)-(xNorm*90)), zRot]

    ]

    [If,yNorm < 0,
    [TransformSet, , , , , , , ((xRot)-(yNorm*90)), , zRot]
    ,
    [TransformSet, , , , , , , ((xRot)+(yNorm*90)), , zRot]

    ]

    ]
  • TeriyakiStyle
    Offline / Send Message
    TeriyakiStyle insane polycounter
    Hey Nick! - Maybe you can help me clean this up?
    Check out this zbc thread too - getting some interesting contributions from Marcus_Civus: http://www.zbrushcentral.com/showthread.php?203783-Orienting-View-based-on-Transpose-Action-Line


    Getting some help on the zbrush forums - I decided to try using canvasclick and I think it's starting to pay off.

    Did some testing and found 0 to 100 of canvasclick was pretty damn close to a 90 degree rotation.

    So I moved the decimal of the -1 to 1 return values of the Pixol Normal and input that as canvasclick drag. 

    Seems to work?! I only have it working on one axis now but maybe you can help me hook it up better?

    Here's my junky script so far:

    [IButton,???,"Angle Snap",
    //Get Pixol Info Location and Normal (X -1 to 1 and Y -1 to 1)


    [VarSet,z,[PixolPick,1,[MouseHPos],[MouseVPos]]]    
    [If,z < 2800,


    [VarSet,xNorm,[PixolPick,6,[MouseHPos],[MouseVPos]]]
    [VarSet,yNorm,[PixolPick,7,[MouseHPos],[MouseVPos]]]


    ]


    //Canvas Drag to Rotate X,Y based on Normal Info


    [CanvasClick, (Document:Width*.02), (Document:Width*.02), ((Document:Width*.02)+(xNorm*100)), ((Document:Width*.02)-(yNorm*100)) ]


    ]
  • Scruples
    Offline / Send Message
    Scruples polycounter lvl 6
    @fuzzzzzz @kidult® summoning the only zscript users I'm aware of.
  • TeriyakiStyle
    Offline / Send Message
    TeriyakiStyle insane polycounter

    marcus_civus and dargelos on the ZBC forums posted some nice solutions.  I chose my favorite and will be using it for my hard surfacing.



    If you want to try this out download the .txt and place it in your Zstartup/Macros folder, Bind it to any hotkey you like and while your mouse is over the model hit the hotkey to snap the plane to view.  Now all your clipcurves etc.  will be true to that plane regardless of its orientation!

    https://dl.dropboxusercontent.com/u/1959501/ZB_Scripts/SnapP.txt
  • cptSwing
    Offline / Send Message
    cptSwing polycounter lvl 6
    That sounds pretty cool, thanks :)
Sign In or Register to comment.