MAXSCRIPT: Reset Normals

Written by Chris

3Ds Max 2018

Sometimes meshes created in Maya can’t be smoothed out in Max, the normals are handled differently in each software package, this script allows to take any mesh (maya or max) and smooth it out. Also it allows you to skip the multiple steps to add modifiers and so on.

  • The check mark tells the script to xform or not
  • the <) is the custom angle that you’d like to smooth the mesh
  • ResetNormalsC – reset the normals using angle <)
  • All the other buttons use an predetermined angle, stated in each.

Here is an example of mesh created in Maya and brought into Max with Normals issues.

Here is an example of any mesh been smoothed out by the script, skipping menu and modifiers.

--author: Christian Pulla
--FUNCTION, this validates the input
fn InputValidator inputTxt = (
	--check if there is anything
	if inputTxt != "" do
	(
		--check if it's a number
		if (trimLeft inputTxt "0123456789.").count == 0 do
		(
			--it's a valid input
			return true;
		)
	)
	--it's an invalid input
	return false;		
)

--FUNCTION, this has multiple purposes, should be broken up, but to keep it simple everything goes in here
--   make sure we are selecting the whole mesh
--   reset all the normals of all the faces
--   xform it, if requested
--   smooth at requested angle.
fn resetNormals smoothValue xFormMe = (

		myPolyName = $

		--RESET NORMALS
		modPanel.addModToSelection (Edit_Normals ()) ui:on
		subobjectLevel = 1
			
		myPolyName.modifiers[#Edit_Normals].EditNormalsMod.Select #{1..(myPolyName.modifiers[#Edit_Normals].EditNormalsMod.GetNumNormals())}	
		myPolyName.modifiers[#Edit_Normals].EditNormalsMod.Reset ()	

		maxOps.CollapseNode myPolyName off	
		
		--XFORM
		if xFormMe == true do
		(
			macros.run "PolyTools" "ResetXForm"
			print "xForm applied"
		)

		--SMOOTH AT ANGLE
		subobjectLevel = 4
		myPolyName.selectedfaces = #{1..myPolyName.faces.count}	
		myPolyName.autoSmoothThreshold = smoothValue	
		myPolyName.EditablePoly.autosmooth ()	
		
		--keep mesh selected.
		subobjectLevel = 0	
	)	


rollout boxCreator "ResetNormals"
(

	local NormalAngle = 1
	local xFormMe = False

	--set up UI
	checkbox ckbx1 "XForm" checked:false
	edittext angle_txt1 "<)" fieldWidth:50 labelOnTop:false
	button b1 "ResetNormals C"
	button b2 "ResetNormals 30"
	button b3 "ResetNormals 45"
	button b4 "ResetNormals 60"
	button b5 "ResetNormals 90"
	
	
	--when information is entered..
	on angle_txt1 entered txt do
	(
		--to avoid multiple if's and ensure it has a base angle
		NormalAngle = 30
		--test input and if valid assign it to be used
		if (InputValidator txt) do
			NormalAngle = txt
	)
	
	--check if xForm is requested.
	on ckbx1 changed theState do
	(
		if ckbx1.state == true then
		(
			xFormMe = true
		)
		else
		(
			xFormMe = false
		)	
	)
	
	
	--these are the buttons that trigger the normal reset
	--by requested angle.
	on b1 pressed do
	(
		smoothValue = NormalAngle as float
		resetNormals smoothValue xFormMe
	)
	
	on b2 pressed do
	(
		smoothValue = 30
		resetNormals smoothValue xFormMe
	)
	
	on b3 pressed do
	(
		smoothValue = 45
		resetNormals smoothValue xFormMe
	)	
	on b4 pressed do
	(
		smoothValue = 60
		resetNormals smoothValue xFormMe
	)
	
	on b5 pressed do
	(
		smoothValue = 90
		resetNormals smoothValue xFormMe
	)
		
	
)
createDialog boxCreator 120 180 --create a Dialog from the rollout