ScriptSpot

Forum topic · Scripts Wanted

Multi/Sub-object material creator

By ranman38 · 2007-06-22

Description

I would like a script that assigns a new material ID to each polygon, according to the texture assigned to it, and then create a multi-subobject material. This would be useful for when I want to create materials that have different textures for the same model. I realize that I should probably assign mat ids while i am making the model, but sometimes I forget. Thanks. I currently use Max 7.

Comments (1)

mobeen · 2007-07-06

Try this script it will replace the existing materials on an editable poly object with a single multisub material.

--:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::--
--:: This script replaces existing materials on an editable poly ::--
--:: and replaces it with a single multisub material. Helps when ::--
--:: you are short of material editor slots ;-)                  ::--
--:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::--
--:: Author :: Muhammad Mobeen Movania ::::::::::::::::::::::::::::--
--:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::--
try(destroydialog r_Test)
catch()
rollout r_Test "MultiSub-Material"
(
   button btn "Create Multi-Sub Material"
   
   on btn pressed do
   (
      --Ensure at least something is selected
      if ( $ != undefined ) then
	  (  
	     --See if we have a valid object
		 if(classof $ == Editable_Poly) then
		 (		    
		    --Create a new multisub material 
		    multiMat = Multimaterial numsubs:($.numFaces)
			
			--Loop through all faces of the mesh
		    for i=1 to $.numFaces do
			(		   
			   -- Get the material index of the current mesh face
			   index = ($.GetFaceMaterial i)
			   
			   --Add to our multisub material
			   multiMat.materialList[i] =  meditmaterials[index]
			   
			   --Create a new material to replace it in material editor slot
			   meditmaterials[index] = standard()
			   
			   --Give it a new name
			   assignNewName meditmaterials[index]
			)
						
			--Place our new material in the material editor slot			
			meditMaterials[sceneMaterials.count] = multiMat		

			--Assign to the current mesh the new multisub material	
			$.material = multiMat
		 )
		 else
		    messagebox "Required an editable poly object having materials assigned"

	  )
	  else
	     messagebox "Nothing selected"
   )
)
CreateDialog r_Test 200 60

Hope this helps
Mobeen