[Closed] remoove submaterial from multimaterial
Is there a way to remoove submaterial with ID i from multimaterial? I maxscript documentation haven´t found such posibility.
I’m not sure what are you trying to do, the most simple solution I can think of is:
fn removeSubmaterial mat id = (
for i = 1 to mat.materialList.count do (
if (mat.materialIDList[i] == id) do (
mat.materialList[i] = undefined
)
)
)
-- remove ID 4
removeSubmaterial $.material 4
Sorry people, but I asked how to remoove submaterial from multimaterial, not set submaterial. Remoove specialy means that the number of submaterials will shrink.
fn RemoveSubMaterial mtl ID = if isKindOf mtl Multimaterial do (
index = findItem mtl.materialIDList ID
if index > 0 do
(
deleteItem mtl.materialList index
deleteItem mtl.materialIDList index
deleteItem mtl.names index
)
)
Sorry, but what is ID in your code? Isn´t ID the same as index? Also don´t I need to do this to?
fn RemoveSubMaterial mtl ID = if isKindOf mtl Multimaterial do (
index = findItem mtl.materialIDList ID
if index > 0 do
(
deleteItem mtl.materialList index
deleteItem mtl.materialIDList index
[b]deleteItem mtl.[i]names[/i] index[/b]
)
)
ID is the face material ID
index is the material index in materiallist
And yes, you definitely need to delete names as well.
OK thanks, just to make it more clear, let say I have multimaterial with materialIDList looking like this: (1, 2, 3, 4) and I delete the submaterial with ID 3, will it bekome (1, 2, 4)?
Looks like we also forgot about mapEnabled array, so think the code must look so:
fn RemoveSubMaterial mtl ID = if isKindOf mtl Multimaterial do (
index = findItem mtl.materialIDList ID
if index > 0 do
(
deleteItem mtl.materialList index
deleteItem mtl.materialIDList index
deleteItem mtl.names index
deleteItem mtl.mapEnabled index
)
)
Not easy to delete submaterial.