[Closed] Get/Set all bitmaps in specific material
I’m looking for a general purpose way to get and replace bitmaps in materials that use them instead of bitmapTextures. For bitmapTextures it’s easy:
theTextureFile = (getClassInstances bitmaptex target:$)[1] –Get
theTextureFile.filename = “c:
ewmap.tga” –Set
But for bitmaps (like used in DirectX materials) I’m lost. I can get the paths via “usedMaps”, but that alone doesn’t help me changing them to new ones. enumerateFiles seems like it might help, but I’m still just not getting it…
you have to assign new bitmap to bitmap property…
let’s say its DirectX shader with StandardFX11.fx effect file, and you need to change “bottom texture” bitmap:
<mat>.g_BottomTexture = openbitmap "the_path_to_the_texture"
So then, I suppose you’d iterate through all the properties in a material (since the script wont automatically know the properties to use), see what each return, and if it’s a bitmap replace it.
Seems like it would work, but would be sort of slow, especially with more complex materials. Is there any faster way?
there is no easy way to get all bitmap properties of a max object (a material for example)
you can go through all props but if the bitmap property is not assigned it returns undefined, and it tells you nothing.
so the way i’ve already showed is to parse “showproperties” result:
something like:
fn getMaterialBitmapProperties mat =
(
fn trimSpaces str = trimRight (trimLeft str " .") " ."
ss = stringStream ""
showproperties mat to:ss
seek ss 0
props = #()
while not eof ss do
(
if (str = readline ss) != undefined do
(
parts = filterstring str ":"
parts = for part in parts collect (trimSpaces part)
if parts[2] == "bitmap" do append props parts[1]
)
)
free ss
props
)
-- getMaterialBitmapProperties meditmaterials[1]
it’s not very quick but it’s fast enough