[Closed] is there a material count limit for single mesh?
I have a mesh that has about 300 materials, the mesh is stored in a file and I have a script to import it into max, but after importing I can
see only 256 materials inside material editor and some meshes seem to
have wrong materials.
Is there a material count limit for single mesh? If so can it be fixed?
That clearly means that a mesh can have more than 256 materials.
Have you considered the possibility that there may be something wrong in your export/import routines?
Meshes in 3dsmax store materialIDs as unsigned short values, which means the most number of theoretical materials applied to a mesh is 65536.
What filetype are you saving/importing your mesh as? It’s possible you’re using a format that limits materialID values to the range of an unsigned char, which is 256.
I have writen my own script to import that file and inside the file there are no limitations for materialID.
The script defenetly reads the right number of materials, as I have included format line that prints the value of mat.count, where mat is my multimaterial.
(
gc()
delete objects
obj = converttopoly (plane length:100 width:100 lengthsegs:20 widthsegs:20)
mat = multimaterial numsubs:400
for j = 1 to 400 do
(
c = random black white
c.s = 64
mat[j] = standardmaterial diffuse:c
polyop.setfacematid obj j j
)
mat[1].diffuse = green
mat[400].diffuse = red
obj.mat = mat
for j = 1 to 400 do
(
id = polyop.getfacematid obj j
format "face:% matid:%
" j id
)
)
Will try this code. Have to mention that in my code I am using meshop and not polyop, can this be the reason for my problem?
It shouldn’t be a problem.
(
gc()
delete objects
obj = converttomesh (plane length:100 width:100 lengthsegs:20 widthsegs:20)
mat = multimaterial numsubs:400
for j = 1 to 800 by 2 do
(
c = random black white
c.s = 64
id = (j/2)+1
mat[id] = standardmaterial diffuse:c
setfacematid obj j id
setfacematid obj (j+1) id
)
mat[1].diffuse = green
mat[400].diffuse = red
obj.mat = mat
for j = 1 to 800 do
(
id = getfacematid obj j
format "face:% matid:%
" j id
)
)
Would it be helpfull, if i upload my script with the coresponding file, that produces the problem?
I can’t warrantee that I will be able to fix the code (if it needs to be fixed). But if you feel posting the code here just do it. I will take a look at it and I am sure other will do so.
BTW, what happens if you export the plane created with the last code and the import it? Does it work?
as i know the MultiMaterial has a limitation of sub-materials. But it’s 1000
Yes.
(
mat = multimaterial numsubs:2000
format "numsubs:%
" mat.numsubs
mat[1000] = standardmaterial diffuse:red
mat[1001] = standardmaterial diffuse:blue
)
numsubs:1000
-- Type error: Submaterial index out of range, got: 1001
However you can still set a face material ID up to 65535.
Sorry for the misunderstanding, I meaned that the mesh inside the file has more then 256 materials
I never exclude the possibility that there may be something wrong in my script, but since the script worcks fine with other files, having less then 256 materials, I don´t think it´s the reason.
OK, looks like I finally know what the problem is, the mesh inside the file is f*cked up. There is a code in my script like this:
rot_obj = eulerangles 90 0 0
rotate msh rot_obj
msh2=mesh numverts:0 numfaces:0
meshop.attach msh2 msh attachMat:#IDToMat condenseMat:true deleteSourceNode:true
where msh is the mesh I have read from the file. This code should fix the wrong axis. However msh2.material.count is 256, so it looks like attach remooves unused materials. I checked for faces with materialID > 256 inside the file and there are none.