Page 1 of 1

Automatic creation of materials

Posted: Mon May 12, 2008 1:06 pm
by JTB
First, let me say that I have no experience of Maxscript.... My question is this:
How can someone automatically create materials in Max, from a list of images?
I mean, something like the actions in photoshop.....
I guess it is possible with maxscript, but I have no idea how...
Is there any tool that can create many materials, assigning textures? A batch material creator?
What I need is this....
I have a list of pictures of people. I want to create a crowd. Using forestpack, this is really easy... The boring part is to make many materials that will be assigned to each plane or group of planes to simulate a crowd. I just need something to make a list of materials automatically. Even if it only makes standard materials.

Posted: Mon May 12, 2008 4:31 pm
by Bogdan Coroi
Here is a small script that can be used as a reference for what are you trying to do.

With this script, you can assign textures from a specified directory to all objects from the current selected objects in the scene. The material used to store all textures is a default MaxwellMaterial. That means, you'll end up with all selected objects having a default maxwell material with reflectance 0 as the storage node for the textures specified.

As you can see, you can modify the textures directory. In my case is "C:\\textures\\" and textures are JPEGs.
Code: Select all
-- get all texture names and place them in variable 'files'
files = getFiles "c:\\textures\\*.jpg"
i = 1
-- get all selected objects from scene
sel = selection as array
for obj in sel do
(
	-- create a default material.
	m = MaxwellMaterial()

	-- create a bitmap node and assign the i-th texture from 'files' variable
	bmt = BitmapTexture()
	bmt.fileName = files[i]
	i = i+1
	
	-- assign it to Maxwell Reflectan 0 texmap
	m.'BSDF_Reflected_Color_Texture' = bmt
	
	-- assing Maxwell Material to a selected object from the list
	obj.material = m
	
	-- show it in viewport
	showTextureMap m bmt on
)
Grab this script - copy/paste - and after you modify the textures path, select some objects from the scene and run the script.

Posted: Mon May 12, 2008 5:44 pm
by Fernando Tella
Thanks Bogdan! That looks very useful.

Posted: Mon May 12, 2008 6:05 pm
by JTB
Thanks a lot! Although I don't need the last part, this will be great help for me!!!
My need is just to make a list of materials.
Actually I will need to add the alpha channel too, so I will have to find a way to automatically assign the relative alpha image....
I had some programming experience with Turbo Pascal and AutoLISP but nothing similar to Maxscript...