material id question

material id question

Anonymous
Not applicable
308 Views
4 Replies
Message 1 of 5

material id question

Anonymous
Not applicable
hi

i am doing my first steps to a maxscript that exports a scene to my own format.

i am currently trying to export the faces of a mesh.
when i assign 2 or more materials to a mesh the material ids are just fine
but when i only have one material assigned to the object i get a different material id per face. (ids seem to not make any sense)..

here is what i do:


for i = 1 to mesh.numfaces do
(
face = getFace mesh i
matid = getFaceMatId mesh i
print matid
print face
)


can anyone tell me if i oversee something `?

thanks in advance
0 Likes
309 Views
4 Replies
Replies (4)
Message 2 of 5

Steve_Curley
Mentor
Mentor
2 things. The following refers to a simple box.

1) Each side (polygon) is actually 2 faces, so you'll get 12 items in the list, not 6.
2) A box is created with a different Material ID on each side (6 sides, 6 MatIDs). You code snippet will show that
So if you convert the Box to an Editable Mesh, Select all 6 sides (polygons) and assign them all the same MatID, then your code snippet will show that they all have the same ID.

I would replace (temporarily at least) your debug prints with the following line - somewhat less cluttered.


format "Face %, MatID %\n" i face

-- before changing the Mat IDs
face 1, Id 2
face 2, Id 2
face 3, Id 1
face 4, Id 1
face 5, Id 5
face 6, Id 5
face 7, Id 4
face 8, Id 4
face 9, Id 6
face 10, Id 6
face 11, Id 3
face 12, Id 3
OK

--after changing the Mat IDs
face 1, Id 7
face 2, Id 7
face 3, Id 7
face 4, Id 7
face 5, Id 7
face 6, Id 7
face 7, Id 7
face 8, Id 7
face 9, Id 7
face 10, Id 7
face 11, Id 7
face 12, Id 7
OK

Max 2016 (SP1/EXT1)
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 430.86).

0 Likes
Message 3 of 5

Anonymous
Not applicable
.A mesh with 1000 IDs but a single material assigned will show the same material on all faces, but an exporter would still see 1000 IDs. If you had a multi-sub material with two sub-materials and a mesh with a lot of IDs, each face will get a matID based on a modulo function - either the first or the second. So faces with odd IDs like 1,3,5,... 999 would get the SubMaterial will ID 1, the faces with even IDs would get the SubMat with ID 2 and so on.

When you ASSIGN a material to an active sub-object face selection in Max 2 or higher, Max automatically assigns new Material IDs to accommodate it. So it is possible to change IDs by assigning materials in Sub-Object level, but you will not be prompted about it...

As mentioned already, a Box is created with 6 pre-defined MatIDs on its 6 sides (it has been this way since Max 1.0). A Sphere on the other hand is always created with a single Material ID assigned to its faces, but it is not ID 1 as you would expect but ID 2 (don't ask me why). Material IDs are always there, even if there is no material assigned. They are just indices pointing at sub-materials of a MultiMaterial if available, but you can export a mesh and get Face Material IDs for each face even if there is no material or if it is a different class than MultiMaterial...

This is all pure Max knowledge and completely unrelated to scripting. It is just how MatIDs have always worked in Max even since the pre-scripting days...

Hope this helps.
0 Likes
Message 4 of 5

Anonymous
Not applicable
hi

thanks for your answers!

ok i guess i should have a look at the material stuff first 🙂

also i think i should check for multimaterial using "if classof obj.material == MultiMaterial" ?

bobo: i already knew your maxscript-exporter bff script. it is a big help for me to be able to read that source. thanks for that!!
0 Likes
Message 5 of 5

Anonymous
Not applicable
Don't forget that a multisub is only a container for materials and isn't a
material in the "traditional" sense.

the .materiallist property gives you the array of materials in the multimaterial.
0 Likes