Home Technical Talk

Max question for the week

polycounter lvl 11
Offline / Send Message
Murdoc polycounter lvl 11
Ok, using Max grids and snapping agian and usually things go alright.

This time it did not, now all my verts are just a little off here and there, but I don't want to go in one by one making sure they align to the grid... is there anyway or tool out there that allows me to select all my verts at once and have them snap to the nearest grid point?

Thanks,

EDIT:

Found one, just also need something out of blur scripts:

http://www.ricoholmes.com/OtherStuff/Downloads/VertexPlacer_3.mcr

http://www.neilblevins.com/blurscripts/blurscripts.htm - you need bslib.ms

Replies

  • MoP
    Offline / Send Message
    MoP polycounter lvl 18
    Thanks for the links :)

    I actually wrote a Maxscript which does the same thing last year (called it "Gridify"), except instead of working off the grid it just worked from whatever arbitrary number you entered - the selected verts would be moved on X/Y/Z to the nearest multiple of that number.

    I should probably clean it up and release it when I get my new site design together.
  • renderhjs
    Offline / Send Message
    renderhjs sublime tool
    I was about to script a custom maxscript myself soon for pretty much the same idea: snapping slected vertex pointson custom unit intervalls either on either single, double or tripple pair of axes.
    progress_02_maxscript_tools.gif
    though I have not yet really started (lots of other things to do first)- I found a usefull tutorial script that does the same but more simplified as the blur script:
    http://www.rubengarza.com/maxscript-T02-FirstScript.htm

    the reason I need it is so that vertex points better snap on tiles that are placed together in a edtitor outside of 3dsmax. So when I export my tile- polygons/ prefabs I need to be sure that they continue seamless to the other objects.
  • renderhjs
    Offline / Send Message
    renderhjs sublime tool
    somehow got interested in this and started a function that snaps the vertex points on the grid:
    function vertex_snap obj snap_units xAxisUse yAxisUse zAxisUse = (
    	if (classof obj == Editable_Poly) then(
    
    		local num_verts = polyop.getNumVerts obj;
    		
    		for i = 1 to num_verts do(--loop through the vertex points
    			local v = polyop.getVert obj i;--get the vertex point
    
    			if (xAxisUse == true) then(
    				v.x = float v.x/snap_units;
    				if v.x - (floor v.x) < .5 then(
    					v.x = floor v.x;
    				)else(
    					v.x = ceil v.x;
    				)
    				v.x = v.x*snap_units;
    			)
    			if (yAxisUse == true) then(
    				v.y = float v.y/snap_units;
    				if v.y - (floor v.y) < .5 then(
    					v.y = floor v.y;
    				)else(
    					v.y = ceil v.y;
    				)
    				v.y = v.y*snap_units;
    			)
    			if (zAxisUse == true) then(
    				v.z = float v.z/snap_units;
    				if v.z - (floor v.z) < .5 then(
    					v.z = floor v.z;
    				)else(
    					v.z = ceil v.z;
    				)
    				v.z = v.z*snap_units;
    			)
    
    			polyop.setVert obj i v;--update the vertex poistion
    
    		)
    	)
    )
    vertex_snap selection[1] 16 true true false;--object 1 x,y
    

    you use it like
    vertex_snap objectNode:ObjectNode snapRadius:Integer snapOnXAxis:Boolean snapOnYAxis:Boolean snapOnZAxis:Boolean

    but unfortunately it doesn't take selection into account- which is what I will add next
  • renderhjs
    Offline / Send Message
    renderhjs sublime tool
    update, now it incorparates the selection of a poly object

    under the following conditions it will snap all verts of the poly object
    - you are in sub object mode 1 (vertex level) but no vertex is selected
    - you are not in sub object mode 1 - or not in one at all

    at any other case meaning that if you selected a few verts it will snap only those
    function vertex_snap obj snap_units xAxisUse yAxisUse zAxisUse = (
    	if (classof obj == Editable_Poly) then(
    		
    		local num_verts = polyop.getNumVerts obj;
    		local vert_selct = polyOp.getVertSelection obj;
    		local selected_verts_count = 0;
    		
    		for i = 1 to vert_selct.count do(--check how many verts are selected
    			if ( vert_selct[i] == true)then(
    				selected_verts_count+=1;
    			)
    		)
    		if (selected_verts_count == 0 or subobjectlevel != 1)then(--set selection to all
    			print("select ALLL");
    			vert_selct = #{1..num_verts};--set all selected to true in this byteArray
    			for i = 1 to num_verts do(
    				vert_selct[i] = true;
    			)
    			
    		)
    
    		for i = 1 to vert_selct.count do(
    			if ( vert_selct[i] == true)then(
    
    				local v = polyop.getVert obj i;--get the vertex point
    	
    				if (xAxisUse == true) then(
    					v.x = float v.x/snap_units;
    					if v.x - (floor v.x) < .5 then(
    						v.x = floor v.x;
    					)else(
    						v.x = ceil v.x;
    					)
    					v.x = v.x*snap_units;
    				)
    				if (yAxisUse == true) then(
    					v.y = float v.y/snap_units;
    					if v.y - (floor v.y) < .5 then(
    						v.y = floor v.y;
    					)else(
    						v.y = ceil v.y;
    					)
    					v.y = v.y*snap_units;
    				)
    				if (zAxisUse == true) then(
    					v.z = float v.z/snap_units;
    					if v.z - (floor v.z) < .5 then(
    						v.z = floor v.z;
    					)else(
    						v.z = ceil v.z;
    					)
    					v.z = v.z*snap_units;
    				)
    	
    				polyop.setVert obj i v;--update the vertex poistion
    			)
    		)
    	)
    )
    vertex_snap selection[1] 8 true true false;--object 1 x,y
    
Sign In or Register to comment.