Home Technical Talk

GetMaterial from face (3ds Max)

Hi,

To obtain the material that a face is mapped to (for an editable mesh) there is a function called: "getFaceMatID". However this function often gives me an ID that is higher than the material count assigned to the editable mesh.

My questions is thus, am i doing something wrong, is there a better way to obtain the mtaerial that a face maps to? Is it a bug?

All i want is have the script select me the material that the face is mapped to.

regards

Replies

  • cw
    Options
    Offline / Send Message
    cw polycounter lvl 17
    Hi,

    3dsmax does not apply materials directly to face. IF you apply material to subobject selection, internally (and perhaps unclearly and unhelpfully) 3dsmax creates a 'multi-sub' material and manipulates the ids and material assignment of your mesh so that you see the material you have applied on the faces you have chosen.

    The down side to this is that it does not work particularly intelligently, and can often make a bit of a mess of your material under the hood, with duplicates and so on.

    If you create your own multi-sub material, with your materials set up as you wish, then set the IDs by hand, you can easily apply this to your models and keep things clear.

    It is possible in maxscript to retrieve the material of a selected face, if this is still the route you wish to take, you will need to take the material of the selected object, the matID as you have retrieved it, and index into the material.materiallist property. The indices wrap around, so if your index is 7 and there are only 3 materials, it will be using the material for ID 1, you can use the 'mod' maxscript command to work this out easily.

    Good luck!
  • r_fletch_r
    Options
    Offline / Send Message
    r_fletch_r polycounter lvl 9
    if numberOfMaterialIds < faceMatID then
    (
    matID = (mod faceMatID numberOfMaterials) as integer
    )
    else
    (
    matID = faceMatID
    )
    So basically MOD gives you the remainder of faceMatID divided by numberOfMaterials as a float value. This remainder will be the wrapped around matID. Since mod returns a float value you cast it as an integer.
  • dikkop
    Options
    Offline / Send Message
    Ah, the modulo explains it, thanks a lot:)
Sign In or Register to comment.