[Closed] Get faces from material ID?
I want to know if there is an efficient way to collect all of the faces of an editable poly that share the same material ID, without selecting them?
This was discussed before, but some years ago: http://forums.cgsociety.org/showthread.php?f=98&t=617356
As new features are constantly being added to Max, I figured it was worth asking again.
EDIT: On a somewhat related note, what is the best way to get a list of all the editable poly material IDs (i.e. not the ones related to an actual material, as Polygon: Material IDs can be applied even to an object with no material applied.)
decreasing faces as you go is probably the most efficient, something like…
fn CollectAllFacesWithMatID pObj =
(
faces = #{1..pObj.numfaces};
result = #();
do
(
matID = polyop.getfacematid pObj (faces as array)[1]; -- not ideal
matidfaces = #{};
matidfaces.count = pObj.numfaces;
for f in faces where (polyop.getfacematid pObj f) == matID do matidfaces[f] = true;
faces -= matidfaces;
append result matID;
append result matidfaces;
)while not faces.isEmpty;
result;
)
This is a quite balanced function. It runs 3-4 times faster and uses no memory at all.
fn GetNodeFacesByMatID node =
(
getfacematid = polyop.getfacematid
r=#(); ids=#{}
for f = 1 to node.numfaces do
(
id = getfacematid node f
if not ids[id] then r[id]=#{f} else r[id][f]=true; ids[id]=true
)
for j in ids collect #(j, r[j])
)
time:297 ram:51658240L faces:77188
time:93 ram:3368L faces:77188
For large amount of faces you might want something like the following function, which is around 5-6 times faster and uses a fixed 4Mb of memory:
fn GetNodeFacesByMatID node =
(
getfacematid = polyop.getfacematid
r = for j = 1 to 65535 collect #{}
for j = 1 to node.numfaces do append r[getfacematid node j] j
for j = 1 to r.count where not r[j].isempty collect #(j, r[j])
)
time:5817 ram:302312600L faces:1235008
time:1109 ram:4227304L faces:1235008
nice routines
and uses no memory at all.
what happens to memory usage if face 1 has a MatId of
65535 ?
Still same memory ussage (more or less) for both functions.
(
node = converttopoly (geosphere segs:200)
polyop.setfacematid node 1 65535
)
time:1029 ram:944L faces:800000 (first function)
time:609 ram:4238976L faces:800000 (second function)
If you wanted to use no scripting at all you can use the Volume Select modifier to select by Material ID / Face ID.
A nice little secret of max!