(C++ SDK) Create EditNormals modifier

(C++ SDK) Create EditNormals modifier

liam.jacksonFCFHA
Observer Observer
588 Views
5 Replies
Message 1 of 6

(C++ SDK) Create EditNormals modifier

liam.jacksonFCFHA
Observer
Observer

Please excuse my amateurish knowledge, I am very new to 3DS Max as a DCC and it's C++ SDK. Assuming I have the iNode of mesh, I would like to add an EditNormals modifier to it, and perform some operations on it. I can find some examples for some other modifiers like MaxMorph, but it seems like this modifier's behaviour on the backend is quite different. The only resource I can seem to find on it is IEditNormalsMod, but no example of how to properly initialize/use it, and I'm not even sure if that is the correct path. I don't suppose anyone can point me to a resource, or provide a small example of adding this modifier.

 

My end goal is simply to reset/recalculate the normals, which looks like can be done via the Unify operation on the EditNormals modifier.

 

Thank you

0 Likes
589 Views
5 Replies
Replies (5)
Message 2 of 6

klvnk
Collaborator
Collaborator

something like this should do the job....

 

 

 

 

#include "iEditNormals.h"

#define EDIT_NORMALS_CLASS_ID Class_ID(0x4aa52ae3, 0x35ca1cde)

Modifier* mod = (Modifier*)CreateInstance(OSM_CLASS_ID, EDIT_NORMALS_CLASS_ID);
if (mod)
{
	IEditNormalsMod* eni = (IEditNormalsMod*)mod->GetInterface(EDIT_NORMALS_MOD_INTERFACE);
	if (eni)
	{

		
		IDerivedObject* dobj = CreateDerivedObject(obj);
		dobj->AddModifier(mod);
		node->SetObjectRef(dobj);
		mod->NotifyDependents(FOREVER, PART_ALL, REFMSG_CHANGE);
		mod->NotifyDependents(FOREVER, PART_ALL, REFMSG_NUM_SUBOBJECTTYPES_CHANGED);
        eni->EnfnUnifyNormals();
		....
	}
}

 

 

though there are easier and faster ways to reset an objects normals

0 Likes
Message 3 of 6

istan
Advisor
Advisor

I would use

BOOL needDel;
TriObject* tri = GetTriObjectFromNode(node, t, needDel);
if (!tri) return;
Mesh* mesh = &tri->GetMesh();
mesh->buildNormals();

 without a modifier.

0 Likes
Message 4 of 6

liam.jacksonFCFHA
Observer
Observer

Thank you very much! Of the two solutions here, this is the one that worked for me slight modifications. I do have a couple of followup questions if you don't mind.

 

1. How did you know which hex value to use for the Class_ID? Is there some lookup table for Mod ID's I'm missing?

2. While this works, and the normals are getting updated, it only works if I'm selecting the modifier, otherwise it won't update the viewport with the changes until I select the modifier. I've tried playing around with the NotifyDependents logic but unfortunately they don't seem to work. Is there another call I need to do to have it render the result without being on the modifier?

 

Thanks!

0 Likes
Message 5 of 6

liam.jacksonFCFHA
Observer
Observer

Unfortunately this doesn't seem to work for me as the mesh attribute of the TriObject is not getting initialized properly. I really appreciate you answering here though!

0 Likes
Message 6 of 6

klvnk
Collaborator
Collaborator

the Class ID is in the source code.... maxsdk\samples\mesh\EditNormals.cpp or you can just get it from maxscript i.e.

 

 

$.modifiers[1].classid

 

 

yeah the having to have the modifier selected is one of the issues of EditNormals modifier, the code post by Istan should work. Are you trying to clear normals previously created by an EditNormals modifier ?

 

if so then....

 

obj->GetMesh().ClearSpecifiedNormals();

 

should do the trick

 

0 Likes