Spline vertex snap to home grid

Snap all the selected spline object's vertex to viewport homegrid.

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
barigazy's picture

I correct your script. Now

I correct your script. Now works only with E-Poly, E-Mesh, and E-Spline objects without modifiers assigned.

try(destroyDialog ::vertSnap)catch()
Rollout vertSnap "Vert Fixer"
(
	fn filtObj obj = (isKindOf obj Editable_Poly or isKindOf obj Editable_Mesh or isKindOf obj line or isKindOf obj SplineShape) and obj.modifiers.count == 0
	fn roundP3 val sc: = ([(floor (val.x+0.5))*sc, (floor (val.y+0.5))*sc, (floor (val.z+0.5))*sc])
	fn vertMove vs = if selection.count != 0 do
	(
		local poGetVert = polyop.getVert, poSetVert = polyop.setVert
		local moGetVert = meshop.getVert, moSetVert = meshop.setVert
		local ssGetKnot = getKnotPoint, ssSetKnot = setKnotPoint
		for obj in selection where filtObj obj do
		(
			case of
			(
				(classof obj == Editable_Poly):
				(
					for v = 1 to obj.numverts do
					(
						vpos = poGetVert obj v
						poSetVert obj v (roundP3 vpos sc:vs)
					)
					update obj
				)
				(classof obj == Editable_Mesh):
				(
					for v = 1 to obj.numverts do
					(
						vpos = moGetVert obj v
						moSetVert obj v (roundP3 vpos sc:vs)
					)
					update obj
				)				
				(classof obj == line or classof obj == SplineShape):
				(
					for s = 1 to (numSplines obj) do
					(
						for k = 1 to (numKnots obj s) do
						(	
							kpos = ssGetKnot obj s k
							ssSetKnot obj s k (roundP3 kpos sc:vs)
						)			
					)
					updateshape obj
				)				
			)
		)
	)	
	group "Snap verts:"
	(
		button fixVert1 "1 unit" width:60 across:3 align:#left
		button fixVert2 "10 units" width:60
		button fixVert3 "100 units" width:60
	)
	on fixVert1 pressed do vertMove 1
	on fixVert2 pressed do vertMove 10
	on fixVert3 pressed do vertMove 100
 
)
createDialog vertSnap 210 55

barigazy

tuxmask75's picture

Man this is a real life saver!

Can't thank you enough!

tuxmask75's picture

Actually

I have this here script that snaps Editable polygon vertex to grid points.
Anyone could help convert it to snap spline vertex in much the same way?
( Also this script seems to have a small issue,
Need to run it twice for it to work.
-----------------------------------------------
Rollout vertSnap "Vert Fixer"
(
group "Snap verts:"
(
button fixVert1 "1 unit" across:3
button fixVert2 "10 units"
button fixVert3 "100 units"
)

on fixVert1 pressed do vertMove 1
on fixVert2 pressed do vertMove 10
on fixVert3 pressed do vertMove 100

)
objEd = newRolloutFloater "Vert Editor" 245 450 50 50
addrollout vertSnap objEd

fn vertMove vertScale =
(
for K = 1 to selection.count do
(
if (selection[K].baseObject as string == "Editable Mesh") or
(selection[K].baseObject as string == "Editable Poly") do
(
for L = 1 to selection[K].numverts do
(
currentVert = polyop.getVert selection[K] L

currentVert.x = float currentVert.x/vertScale
currentVert.y = float currentVert.y/vertScale
currentVert.z = float currentVert.z/vertScale

if currentVert.x - (floor currentVert.x) < .5 then
currentVert.x = floor currentVert.x
else
currentVert.x = ceil currentVert.x

if currentVert.y - (floor currentVert.y) < .5 then
currentVert.y = floor currentVert.y
else
currentVert.y = ceil currentVert.y

if currentVert.z - (floor currentVert.z) < .5 then
currentVert.z = floor currentVert.z
else
currentVert.z = ceil currentVert.z

currentVert.x = currentVert.x*vertScale
currentVert.y = currentVert.y*vertScale
currentVert.z = currentVert.z*vertScale

polyop.setVert selection[K] L currentVert
)
update(selection[K])
)
)
)

barigazy's picture

Example from mxs help

Example from mxs help

new_z = 0 -- Z coordinate
for ss in selection where isKindOf ss line or isKindOf ss SplineShape do 
(
	for s = 1 to (numSplines ss) do
	(
		for k = 1 to (numKnots ss s) do
		(
			knt = getKnotPoint ss s k
			in_vec = getInVec ss s k
			out_vec = getOutVec ss s k
			knt.z = in_vec.z = out_vec.z = new_z
			setInVec ss s k in_vec
			setOutVec ss s k out_vec
			setKnotPoint ss s k knt
		)
	)
	updateshape ss
)

barigazy

tuxmask75's picture

Thanks but,, i made a mistake

Ops, Sorry, I guess that i should not have said homegrid.
should have said 2.5D snap to any viewport grid points.
So vertex snap to grid points. not just a flaten vertex to the home grid

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.