Home Technical Talk

[ZBrush] Is there a way to snap subtools vertex to vertex ?

RawData
polycounter lvl 3
Offline / Send Message
RawData polycounter lvl 3
Like a classic snap tool in every 3d package.

Replies

  • cryrid
    Options
    Offline / Send Message
    cryrid interpolator
    ZModeler : Point Actions : Stitch
  • RawData
    Options
    Offline / Send Message
    RawData polycounter lvl 3
    @cryrid not like that. I meant moving whole subtool to another position.
  • cryrid
    Options
    Offline / Send Message
    cryrid interpolator
    I see. 

    I don't know if such a feature actually exists in Zbrush (there are still things I'm still slowly learning about new Gizmo). But it seemed like the kind of thing scripting should be able to do so I set about creating this:

    [VarDef, xCenter, 0]
    	[VarDef, yCenter, 0]
    	[VarDef, zCenter, 0]
    	[VarDef, xSnap, 0]
    	[VarDef, ySnap, 0]
    	[VarDef, zSnap, 0]
    	[IButton,Transpose-Snapper,"Move a model from the starting point of a transpose line to the end point (to emulate vertex snapping)",
    		[If,[TransposeIsShown],
    			//get the X,Y,Z position of the Model1’s Center Point
    			[VarSet, xCenter, [IGet,Tool:Geometry:X Position]]
    			[VarSet, yCenter, [IGet,Tool:Geometry:Y Position]]
    			[VarSet, zCenter, [IGet,Tool:Geometry:Z Position]]
    			
    			//get the start and end coordinates of the Transpose line (Pos1 = PointA, Pos2 = PointB)		
    			[TransposeGet, xPos1, yPos1, zPos1, xPos2, yPos2, zPos2]
    	
    			[VarSet, xSnap, (xPos2 + (xCenter - xPos1))]
    			[VarSet, ySnap, (yPos2 + (yCenter - yPos1))]
    			[VarSet, zSnap, (zPos2 + (zCenter - zPos1))]
    			
    			//move model to this snapping position
    			[ISet,Tool:Geometry:X Position, xSnap]
    			[ISet,Tool:Geometry:Y Position, ySnap]
    			[ISet,Tool:Geometry:Z Position, zSnap]
    		]
    	]//end button
    


    This creates a button that will move an object/subtool from one end of a Transpose line (the starting point) to other, while attempting to account for the offset between the Transpose's position and the model's own center. Since Transpose snaps itself to vertex points, this should essentially let you choose the  first and second vertices you want to snap together.

    (Note: For full vertex snapping on both ends, you may need to use Tool: Subtool: Merge Visible to create a single temporary tool. Use that one to draw out the Transpose line so that you can touch both vertices that you want, and then switch back to the original tool. The transpose line should still be there).




    Disclaimer: I haven't done heavy testing on this yet, so it may or may not work for your needs. Hopefully it wont outright break anything. I'm not a programmer, but I did get one to go over it and help clean things up and make it more reusable than my first two attempts, so it should at least have some promise. If someone finds it useful, finds a way to break it, or finds a way to improve on it, let me know. 
  • RawData
    Options
    Offline / Send Message
    RawData polycounter lvl 3
    I will try it as soon as possible

    Edit: I tried it. After i merged subtools to move vertex to vertex, even one subtool masked they move together so distance between them stays same. If the subtools splitted it works like expected. So it only works when you duplicate the subtools and merge them then use this temp subtool like a grid. Script is so useful but if you can make some additions like one button for merging subtools it can be much more useful. (i dont know does zbrush has anything like combine last to selected objects or something if so it can be the thing)  Thanks for script!!!
  • cryrid
    Options
    Offline / Send Message
    cryrid interpolator
    To clarify, it is a script to snap one Subtool to another subtool, not to move unmasked items within a single subtool. The suggestion to temporarily merge subtools was so that Transpose would snap to vertices on both ends - you're supposed to switch back to the original tool afterwards to run the script. 
  • RawData
    Options
    Offline / Send Message
    RawData polycounter lvl 3
    @cryrid yes, i know. It worked well but it need so many clicks.
  • cryrid
    Options
    Offline / Send Message
    cryrid interpolator
    You could try something like this:

    	[VarDef, xCenter, 0]
    	[VarDef, yCenter, 0]
    	[VarDef, zCenter, 0]
    	[VarDef, xSnap, 0]
    	[VarDef, ySnap, 0]
    	[VarDef, zSnap, 0]
    	[VarDef, curTool, 0]
    	[VarDef, oriTool, 0]
    	[VarDef, mergedTool, 0]
    	[VarSet, mergedTool, [ToolGetCount]]
    	[VarSet, curTool, [ToolGetActiveIndex]]
    	
    	[IButton,01.Merge_Switch,"Merges visible subtools and automatically switches to this new tool.",	
    		[VarSet, oriTool, [ToolGetActiveIndex]]
    		[IPress,Tool:SubTool:MergeVisible]
    		[VarSet, mergedTool, ([ToolGetCount]-1)]
    		[ToolSelect, mergedTool]
    		[IPress,Transform:Move]
    		]//End of Button
    
    	[IButton,02.Now_Kiss,"Switches from a merged tool back to the previous tool, and snaps from one end of transpose to the other",
    		[If,[TransposeIsShown],
    			//get the X,Y,Z position of the Model1’s Center Point
    			[ToolSelect, oriTool]
    			[IPress,Transform:Move]
    			[VarSet, xCenter, [IGet,Tool:Geometry:X Position]]
    			[VarSet, yCenter, [IGet,Tool:Geometry:Y Position]]
    			[VarSet, zCenter, [IGet,Tool:Geometry:Z Position]]
    			
    			//get the start and end coordinates of the Transpose line (Pos1 = PointA, Pos2 = PointB)		
    			[ToolSelect, mergedTool]
    			[IPress,Transform:Move]
    			[TransposeGet, xPos1, yPos1, zPos1, xPos2, yPos2, zPos2]
    			[VarSet, xSnap, (xPos2 + (xCenter - xPos1))]
    			[VarSet, ySnap, (yPos2 + (yCenter - yPos1))]
    			[VarSet, zSnap, (zPos2 + (zCenter - zPos1))]
    			
    			//move model to this snapping position
    			[ToolSelect, oriTool]
    			[IPress,Transform:Move]
    			[ISet,Tool:Geometry:X Position, xSnap]
    			[ISet,Tool:Geometry:Y Position, ySnap]
    			[ISet,Tool:Geometry:Z Position, zSnap]
    
    			//clean up the merged tool
    			[ToolSelect, mergedTool]
    			[IPress,Tool:SubTool:Delete]
    			[ToolSelect, oriTool]
    			//end cleanup
    		]
    	]//end button
    
    

    Lets say you have a tool that has multiple subtools, and you want to snap the currently active subtool to another. 

    1. Press 01.Merge_Switch.
    ---This will merge visible subtools and immediately switch to the newly created tool, activating move mode for you in the process. 

    2. Drag the transpose line from the vertex you want to snap to the destination you want to snap it to. 
    ---This is all you, and can't be automated.

    3. Press 02.Now_Kiss
    ---This will automatically switch back to the original tool, change its position accordingly, then delete the temp merged tool for you. It may cause a confirmation prompt to appear if you don't have Always Ok enabled for deleting. 

    https://youtu.be/5XBsTonZj_U
  • RawData
    Options
    Offline / Send Message
    RawData polycounter lvl 3
    @cryrid Now it is an awesome script  :) . I have no experience about scripting. Is it hard to make simple things like this? I said simple because function is simple, I mean is it hard to code that? And thank you so much for the script.
  • cryrid
    Options
    Offline / Send Message
    cryrid interpolator
    The basics of it can be pretty simple. There's a reference library available, and you can also set zbrush to record all your actions and save it to a txt file (a great way to start for creating custom macros).  Toss in some variables, some IF statements, and some basic math, and you have a good recipe for some simple scripting. The challenge is figuring out what the limits of these commands are, and if your goal is possible through them then you have to figure out the math/logic needed to get it done. 


  • RawData
    Options
    Offline / Send Message
    RawData polycounter lvl 3
    @cryrid i see , thanks a lot. 
  • oXYnary
    Options
    Offline / Send Message
    oXYnary polycounter lvl 18
    Hey Cryrid,
    I found your youtube first and then this thread.  So per what I mentioned on it, here is an example of whats happening.  FWIW, Positioner is doing nearly the same thing when I try to align to center.  These were imported boxes from Max.

    This is in 2018.1? (Current)


    EDIT:  I tried your dropbox text file with the same results.
  • cryrid
    Options
    Offline / Send Message
    cryrid interpolator
    Near as I can tell its a scale issue from however you have it set up in Maya. That tool is scaled so large that it dwarves the floor grid and transpose wont even snap to the vertices. If I scale each subtool -100 five times each it works.  
  • oXYnary
    Options
    Offline / Send Message
    oXYnary polycounter lvl 18
    Max, but yeah, real world scales in the Max scene.  Damn.  You'd think Zbrush would "scale" its internal system to match.

    Thanks for taking a look.
Sign In or Register to comment.