Posted by: | Vincentt | |
Data created: | 23 December 2014 |
Hello,
I’m trying to select faces by Material ID. I found this method in the Object Browser: Autodesk.Max.IIGameMesh.GetFacesFromMatID(int matID). This seems to be exactly what I want, however I don’t seem to be able to cast any of my objects to IIGameMesh. IIGameMesh is apparently a “Simple wrapper for tri mesh objects.” I tried doing this:
for (int i = 0; i < iface.SelNodeCount; i++) { IINode node = iface.GetSelNode(i); ITriObject triObj = (ITriObject)node.EvalWorldState(0, true).Obj.ConvertToType(0, m_Global.TriObjectClassID); var mesh = triObj.Mesh; IIGameMesh doesntWork = mesh as IIGameMesh; .... }
Error: Object reference not set to an instance of an object. I thought since it was a simple wrapper I could cast the mesh I got from TriObj. I’m using Max2012 (64bit)(I found a similar question but with no answer unfortunately: http://www.ephere.com/autodesk/max/forums/general/thread_1852.html)
If there is another/better way of getting faces by Material ID I’d be all ears too :)
Thanks in advance, Vin | |
23 December 2014
#5676 | |
You would typically need to use GetInterface function to get an instance of IIGameMesh interface, however, I just checked and it is not UpCast(ed?) so I don't think that'll work. How about just iterating over the IMesh faces and looking at their material ids? Marsel Khadiyev (Software Developer, EPHERE Inc.) | |
23 December 2014
#5677 | |
Hey Marsel,
Thanks for you reply, I was already thinking of that as a work around, I'll try that! | |
24 December 2014
#5681 | |
I seem to be stuck at a certain point. The main idea of the program is to select faces by their Material ID and then move them. So far I have this:
I thought with this I would be saving the FaceID together with the MatID as key. So I'd be able to get a list of faceID's according to certain Key values (matID). However the index I'm saving is not the face index and I have no idea how to get it either. So now I'm wondering if anyone could help me finding the correct FaceID (the one you see when you select the face in Max or in the listener: $.EditablePoly.SetSelection #Face #{2} <-- "2"). Or am I wrong trying to get the same ID as maxscript and should I just use index to select my faces, but I also have no idea how...
**EDIT:
Any help would be appreciated! |