Notifications
Clear all

[Closed] Simple questions regarding materials

Hi,

I’m newbie in MaxScript, but not in programming. I have some simple doubts:

1) How to check if an object has one or more materials?

If the object has no material, then writing: obj.material will result in undefined

I would like to check something like this (just a reasoning):

if obj.material != undefined do
(

)

Please, how could I write the code above in a correct form?

2) How to know the number of materials used by an object?

The expression obj.material.count works only if the object has 2 or more materials.
Please, how could I write a code that returns the number of materials used by an object?

Thanks in advance

3 Replies

OK friends, I already got it.

 mat = obj.material 
if (classof mat == Standard) do
(
 format "1
"	-- number of materials (always 1)

 local amb = mat.ambient
 local dif = mat.diffuse
 local spe = mat.specular

 local sle = mat.specularLevel
 local glo = mat.glossiness
 local opa = mat.opacity
 
 local TextureFileName = "notexture"

 if classof mat.diffuseMap == Bitmaptexture then
 (
  TextureFileName = filenameFromPath mat.diffusemap.bitmap.filename
 )
 
 format "% % %
" amb.r amb.g amb.b
 format "% % %
" dif.r dif.g dif.b
 format "% % %
" spe.r spe.g spe.b
 format "% % %
" sle glo opa
 format "%

" TextureFileName
)

if (classof mat == Multimaterial) do
(
 format "%
" mat.count  -- number of materials (always more than 1)

 for m = 1 to mat.count do
 (
  local amb = mat[m].ambient
  local dif = mat[m].diffuse
  local spe = mat[m].specular

  local sle = mat[m].specularLevel
  local glo = mat[m].glossiness
  local opa = mat[m].opacity

  local TextureFileName = "notexture"

  if classof mat[m].diffuseMap == Bitmaptexture then
  (
   TextureFileName = filenameFromPath mat[m].diffusemap.bitmap.filename
  )
 
  format "% % %
" amb.r amb.g amb.b
  format "% % %
" dif.r dif.g dif.b
  format "% % %
" spe.r spe.g spe.b
  format "% % %
" sle glo opa
  format "%

" TextureFileName
 )
)

Just another simple question: How to clear the output window of MaxScript Listener by code?

Thanks again.

1 Reply
(@bobo)
Joined: 11 months ago

Posts: 0

Surprise!

clearListener()

Thank you very much, Bobo.