ScriptSpot

Forum topic · Scripts Wanted

I need help rounding editable poly vertex to a certain amount of precision.

By Alpinatore · 2018-09-04

Description

Hello, I’m new to Maxscript and I’m looking for a way to limit the amount of decimals in which I can move vertexs/objects. For example, I want to round the position of all of the vertex of an Editable Poly. Let’s say that I have one vertex at position (1’432721m, 3’296012m, 12’039863), I want to find a way to round his position to dc-> (1’4m, 3’3m, 12m), cm-> (1’43m, 3’3m, 12’04m), mm-> (1’433m, 3’3m, 12’041), etc. Can anyone help me please? I was trying to make my own script but i dont know how to transform the position with world coordinates...

Comments (1)

.

miauu · 2018-09-09


(
	local poGetNumVerts = polyop.getNumVerts
	local poGetVert = polyop.getVert
	local poSetVert = polyop.setVert
	
	local decimalPrecision = 0
	
	function RoundFloat val = 
	(
		(floor ((val * 10.0 ^ decimalPrecision) + 0.5))/ 10.0 ^ decimalPrecision
	)
	
	if selection.count == 1 do
	(
		curO = selection[1]
		if classOf curO == Editable_Poly do
		(
			selVertsBA = #{1..(poGetNumVerts curO)}
			for v in selVertsBA do
			(
				vPos = poGetVert curO v
				poSetVert curO v [RoundFloat vPos.x, RoundFloat vPos.y, RoundFloat vPos.z]
			)
		)
	)
	
)