[Closed] Materials, what are they
Looking to check what this material is then do some stuff. Im using the wrong functions…hrmm
for i = 1 to MeditMaterials.count do
(
if getMeditMaterial[i] = (Standard) then
(
do some stuff
)
if getMeditMaterial[i] = (Multimaterial) then
(
do some stuff
)
etc.
I thought this might work, but its still wrong
if (finditem meditMaterial[i]) == Standard then
(
)
You should use something like:
for i = 1 to MeditMaterials.count do
(
if classof MeditMaterials[i] == (Standard) do
(
do some stuff
)
if classof MeditMaterials[i] == (Multimaterial) do
(
do some stuff
)
- Meditmaterials is an internal array so you should be searching through that array.
- = sets a value, while ==, !=, <, >, etc tests between the 2 arguments.
- You want to test the classof the material since all Materials will be specific to a certain class.
- Use do in an if statement unless you plan on using the else, ie if … do (), or if … then () else ().
-Eric
ahh doubly thanks for the explanation of =, ==, if … do (), or if … then () else (). That helps alot and gets me thinking ahead on the code.
Ok, I want to make some changes to the multi-material, everything in the list. Assuming all the submaterials are going to be standard…
if classof MeditMaterials[sName] == (MultiMaterial) do
(
--theMat = multiMaterial()
--for i = 1 to theMat.materialList do
if classof materialList[i] == (Standard) do
(
white = (color 255 255 255)
materialList[i].diffuseMap = undefined --turn off texture/diffuse mapping
materialList[i].diffuse = white
)
)
its telling me no ==get== function for undefined
i guess I need to re-define the materialList array??
Again your code is all wrong. First MaterialList is not a class so you need to use the . syntax to add it to a class that the parameter exists. From the Maxscript help:
<multimaterial>.materialList ArrayParameter default: #(Standard, Standard, … Standard, Standard)
You have to have something.materialList. In your example MeditMaterials[sName].materialList[i]. The proper code should be:
if classof MeditMaterials[sName] == (MultiMaterial) do
(
for i in 1 to MeditMaterials[sName].MaterialList.count do -- you have to loop through each material in the Multi/Sub Material
(
if classof MeditMaterials[sName].materialList[i] == (Standard) do -- you have to check each material in the Multi/Sub Material
(
white = (color 255 255 255)
MeditMaterials[sName].materialList[i].diffuseMap = undefined --turn off texture/diffuse mapping
MeditMaterials[sName].materialList[i].diffuse = white
)
)
)
AGAIN GO THROUGH ALL THE MAXSCRIPT EXAMPLES USING MULTIMATERIAL IF YOU WANT TO WORK WITH IT!
-Eric
sorry I didn’t see any examples of the multimaterial scripts in the reference guide XD XD XD! Thanks for helping me!!
Simply search for “Multimaterial” in the help and look at the example “How do I Sort a MultiMaterial By Material ID?” every line is commented.
-Eric
Hi Bixel
I’m sorry to say, but agree with PiXeL_MoNKeY. The docs really have to be your first port of call.
Having said that, there are a number of things you really need to understand…
Precedence in max calls are a little odd (given the fact you don’t need to use
brackets to call functions)
-- This won't work, mostly due to the way max does it's
-- precedence calls
if classof MeditMaterials[sName] == (MultiMaterial) do
I’d also suggestion you look up “MaterialLibrary” in the docs, as this will explain how you get hold of the materials in the first place…
fn changeMaterial material = (
if (classof material) == MultiMaterial do (
-- Perhaps do a recursive call...
for subMaterial in material.materialList do (
changeMaterial subMaterial
)
) else if (classof material) == Standard do (
material.diffusemap = undefined
-- you could also use material.diffuseMapEnable = false
-- as this would preserve the diffusemap value
material.diffuse = (color 255 255 255)
)
)
It doesn’t need to be a function, but sName does need to be the <var_name> of a for loop. If it is then it will work fine the way I posted. This code should work just fine:
for sNAme in 1 to meditmaterials.count do (
if classof MeditMaterials[sName] == (MultiMaterial) do
(
for i in 1 to MeditMaterials[sName].MaterialList.count do -- you have to loop through each material in the Multi/Sub Material
(
if classof MeditMaterials[sName].materialList[i] == (Standard) do -- you have to check each material in the Multi/Sub Material
(
white = (color 255 255 255)
MeditMaterials[sName].materialList[i].diffuseMap = undefined --turn off texture/diffuse mapping
MeditMaterials[sName].materialList[i].diffuse = white
)
)
)
)
-Eric