Reset object and remove mesh normals?

Reset object and remove mesh normals?

KasperFilipsen
Enthusiast Enthusiast
2,273 Views
15 Replies
Message 1 of 16

Reset object and remove mesh normals?

KasperFilipsen
Enthusiast
Enthusiast

I have a script that I use to reset objects, so all transforms and normals are removed from a mesh.

 

I've been using the code snippet below in Max 2021, which works fine. But it doesn't seem to work in 2024, the explicit normals aren't removed.

 

Does anyone know of a foolproof way to remove mesh normals from a mesh, that ideally doesn't require me to be in the modify panel, so I could use it even if the Max interface isn't active.

 

Alternatively, is there is another way to reset and object that I don't know of?

 

(
	local myArray = getCurrentSelection()
	for obj in myArray do (
		convertTo obj PolyMeshObject

		-- Adding a 'Mesh_Select' and disable it in rendering.
		local newMeshSelect = Mesh_Select()
		addModifier obj newMeshSelect
		newMeshSelect.enabledInRenders = false

		-- Add 2x Normal Modifiers on top.
		addModifier obj (Normalmodifier())
		addModifier obj (Normalmodifier())

		-- The method I would like to avoid using
		-- Requires the UI to be active in the Modify panel
		local newEditNormals = Edit_Normals()
		addModifier obj newEditNormals
		select obj
		local normCount = newEditNormals.EditNormalsMod.GetNumNormals()
		local normArray = #{ 1..normCount }
		newEditNormals.EditNormalsMod.SelLevel = #object -- Exit sub-object level
		newEditNormals.EditNormalsMod.Reset selection:normArray -- Edit Normals Reset

		-- ResetXForm with PreserverNormals off
		-- Doesn't seem to make a difference
		ResetXForm obj
		obj.modifiers[1].PreserveNormals = false

		convertTo obj PolyMeshObject

		-- Create an empty object and attach the 'obj'
		local tempSpline = line()
		convertTo tempSpline PolyMeshObject
		tempSpline.EditablePoly.attach obj tempSpline
		convertTo tempSpline PolyMeshObject
	)
)

 

0 Likes
2,274 Views
15 Replies
Replies (15)
Message 2 of 16

MartinBeh
Advisor
Advisor

Hi,

 

I am not sure I entirely understand your issue but the Edit_Normals modifier is the place to go for modifying normals, and ironically the Autodesk developers have gone to great lengths to make sure explicit normals do not get reset by the various modifiers, like in the old days where a "Turn to Poly" would recalculate all normals.

 

Your code does multiple things but if I focus only on the normals aspect, this code snippet seems to do the job for me:

fn resetNormals theNode = (
	local m = Edit_Normals()
	addModifier theNode m
	
	select theNode
	max modify mode
	
	local normCount = m.EditNormalsMod.GetNumNormals()
	m.EditNormalsMod.SetSelection #{1..normCount}
	m.EditNormalsMod.Reset()
	convertTo theNode Editable_Poly
)

... which is fairly similar to what you already have, but as you wrote in your message (and your code comment), this does indeed include to switch to Modify mode, with the object selected, which can be rather slow. But as far as I know that is a limitation of the Edit_Normals modifier.

Martin B   EESignature
→ please 'Like' posts that are helpful; if a post answers your question please click the "Accept Solution" button.
0 Likes
Message 3 of 16

MartinBeh
Advisor
Advisor

Short update:

Here is a fast way to nuke all the normals. It might be a tiny bit dangerous if you have some geometry with unwelded vertices but otherwise it seems fast and does not need the Modify panel 😉

fn killExplicitNormals theNode = (
	addModifier theNode (Vertex_Weld threshold:0.0)
	convertTo theNode Editable_Poly
)

 

Does that solve your problem?

Martin B   EESignature
→ please 'Like' posts that are helpful; if a post answers your question please click the "Accept Solution" button.
0 Likes
Message 4 of 16

klvnk
Collaborator
Collaborator

the Turn To Poly Modifier doesn't support (or never used to) expilicit normals so will remove them and as you're converting to editable poly anyway. 

0 Likes
Message 5 of 16

MartinBeh
Advisor
Advisor

@klvnk  schrieb:

the Turn To Poly Modifier doesn't support (or never used to) expilicit normals so will remove them and as you're converting to editable poly anyway. 


This works for older versions of 3ds Max but as far as I remember this was fixed with the newest releases of 3ds Max, so Turn To Poly (and most other modifiers) will not longer invalidate explicit normals.

Martin B   EESignature
→ please 'Like' posts that are helpful; if a post answers your question please click the "Accept Solution" button.
0 Likes
Message 6 of 16

denisT.MaxDoctor
Advisor
Advisor

We know what you want to remove(reset) - transforms and specified normals. The question is, what do you want to keep? 🙂

0 Likes
Message 7 of 16

denisT.MaxDoctor
Advisor
Advisor

deleted

0 Likes
Message 8 of 16

klvnk
Collaborator
Collaborator

 but as far as I remember this was fixed with the newest releases of 3ds Max

 

looking at the source code between 2010 and 2025 there is no difference, but should be pretty easy to for someone with 2023/24/25 to check. It still strips explicit normals in 2020 btw.

0 Likes
Message 9 of 16

denisT.MaxDoctor
Advisor
Advisor

MAX 2023 ... the Turn to Poly preserves specified normal now. There is no option to reset

0 Likes
Message 10 of 16

denisT.MaxDoctor
Advisor
Advisor

@MartinBeh wrote:

 

 

fn killExplicitNormals theNode = (
	addModifier theNode (Vertex_Weld threshold:0.0)
	convertTo theNode Editable_Poly
)

 

 

Does that solve your problem?


 

Of course, that can't be the solution. It just welds normals, which is no close to reset.

0 Likes
Message 11 of 16

denisT.MaxDoctor
Advisor
Advisor
g = (dotnetclass "autodesk.max.globalinterface").instance
inode = g.COREInterface14.GetINodeByHandle $.inode.handle
obj = (inode.EvalWorldState g.COREInterface.Time true).Obj
obj.Mesh__TriObject.ClearSpecifiedNormals()
update $
Message 12 of 16

klvnk
Collaborator
Collaborator

MAX 2023 ... the Turn to Poly preserves specified normal now. There is no option to reset

 

yeah looks like it's been added to the MNMesh Copy assignment operator and AddTri i guess.

0 Likes
Message 13 of 16

MartinBeh
Advisor
Advisor

@denisT.MaxDoctor  schrieb:

@MartinBeh wrote:
fn killExplicitNormals theNode = (
	addModifier theNode (Vertex_Weld threshold:0.0)
	convertTo theNode Editable_Poly
)

Does that solve your problem?


 

Of course, that can't be the solution. It just welds normals, which is no close to reset.


Of course it is a hack, but I am not seeing it "welding normals", rather welding vertices (at zero distance threshold) and recomputing normals. And isn't that what is needed here? 

mbreidt_0-1721632517136.png

mbreidt_1-1721633023965.png

The result of "weld 0.0" looks identical to the result of the dotNet code you posted.

 

 

 

 

Martin B   EESignature
→ please 'Like' posts that are helpful; if a post answers your question please click the "Accept Solution" button.
0 Likes
Message 14 of 16

denisT.MaxDoctor
Advisor
Advisor

Well... It looks like your trick is working. To be safe, we can add “Don't Weld Sel Edges” and select them all.

 

I hadn't considered welding the vertices for obvious reasons, but I forgot about the “protection option” for the selected edges.

 

Message 15 of 16

denisT.MaxDoctor
Advisor
Advisor

Now in the context of the improvements made to preserving specified normals in several modifiers, we should probably consider the work of the Welder as a bug and report it as a bug 😜

 

0 Likes
Message 16 of 16

KasperFilipsen
Enthusiast
Enthusiast

I mainly want to just keep the mesh, the smoothing groups and the UV's, everything else should be disregarded.

0 Likes