Diffuse Alpha Channel to Opacity Channel

I'm having to import over a thousand 3ds objects into max, each objects material (TGA) has an alpha channel. All I need to do is the Copy Diffuse slot to Opacity slot and set the mono channel output to alpha.
I've been trawling scriptspot for ages, there are lots of Material scripts, but I can't find one that will do this simple task.

I get this from listener.....

meditMaterials[1].opacityMap = Bitmaptexture fileName:"C:\Program Files\Infogrames\Grand Prix 4\Tracks\my_track\Import Full Track To Max Test Track\melborne2001\maps\melborne2001\page_335.tga"

meditMaterials[1][#Maps][#Opacity__Map__856__page_335_tga].monoOutput = 1

But I can't figure out how to just use it on the selected slot, or preferably all slots in the material editor, basically I need that little bit of script to work without looking for the specific tga image name.

btw I'm a Maxscript Luddite...go easy on me ;) [email protected] hoping script already exists

tia

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
asymptote's picture

Cool , works a treat once

Cool , works a treat once more, many thanks dude.
...but I did have to change the last line to mat.opacityMap.monoOutput = 1......again... ;)

@ juumax

full code is....

(
for Obj in objects where isValidNode obj do
(
local mat = obj.material
if superClassOf mat == material AND isproperty mat "diffuseMap" AND classOf mat.diffuseMap == bitMapTexture do
(
mat.opacityMap = copy mat.diffuseMap
mat.opacityMap.monoOutput = 1
)
)
)

Graph's picture

changed the last code i

changed the last code i posted..
it now checks if the diffuseMap property is present..
currently it uses isproperty .. if that dont work try hasProperty

have phun

Raphael 'Insanto' Steves
http://Graph.Net84.Net

asymptote's picture

Hmm, I just started using

Hmm, I just started using this in 2011 and the listener spits out this...

-- Error occurred in obj loop; filename: ; position: 145; line: 5
-- Frame:
-- obj: $shadow test
-- mat: Standard 14:Matte_Shadow
-- called in anonymous codeblock; filename: ; position: 258; line: 10
-- Frame:
-- Unknown property: "diffuseMap" in Standard 14:Matte_Shadow
-- Error occurred in obj loop; filename: ; position: 145; line: 5
-- Frame:
-- obj: $shadow07
-- mat: Standard_11:fR_Matte_Shadow
-- called in anonymous codeblock; filename: ; position: 258; line: 10
-- Frame:
-- Unknown property: "diffuseMap" in Standard_11:fR_Matte_Shadow

seems it doesn't like matte shadow materials in the scene ?
even when I'm running it on a standard material in the number 3 slot with no matte shadow......weird. Maybe when the check finds a matte shadow in the diffuse slot anywhere in the scene it freaks out.

What's your listener saying when you run it ?

juumax's picture

Hey I am trying to run this

Hey I am trying to run this script in max 2010 and I cant seem to get it to work. Do I have to rename my objects in a certain way? I run the script and nothing happens. I have a checker material in the diffuse of a standard material.

I quiet new to maxscript so I dont really understand why, I am trying to do a similar thing as the OP.

Graph's picture

yeah borpheus had a spare

yeah borpheus had a spare ;)
(not a typo)

Raphael 'Insanto' Steves
http://Graph.Net84.Net

asymptote's picture

Awesome...I like fail safes,

Awesome...I like fail safes, prevention is better than cure ;) Thanks I'll see if I can break it........

code was this ...... (from 1st post)

(
for Obj in objects do (
Obj.mat.opacityMap = copy Obj.mat.diffuseMap
Obj.mat.opacityMap.output.invert = true
)
)

 

which was working but for some reason stopped, (or worked sometimes and not others) but I needed it to work on the alpha, so I added this......

Obj.mat.opacityMap.monoOutput = 1

So the final code is....

(
    for Obj in objects where isValidNode obj do
    (
        local mat = obj.material
        if superClassOf mat == material AND classOf mat.diffuseMap == bitMapTexture do
        (
            mat.opacityMap = copy mat.diffuseMap
            mat.opacityMap.monoOutput = 1
        )
    )
)
...which works a treat.......I take it this code runs some checks first ?..., when you post code....i see this.......

gHFGHfghfghfgH&&%&9%^98%^*%^*5^*%^%$&45&4^8%&(5^7%^746*&(%6rtUrTRHJrfJRjRU %^*%76856*58%^8%685^8%6&£$5"FHR^846jFGmJ67(%^urtHR^&8%^*58%*%^8%6*4^&$5&%7 63%$74YRTh^%8&5967)&0^7(5^$%^*&$%8$*4%8$6(%7)6&*0-^8^7(46$£%&37$*5^95&0^)6

Graph's picture

if you see strange symbols

if you see strange symbols only .. how come you got the code i posted there? Wink

and yeah it runs some checks first.
-normally you'd check if the object has a material, then if the material has a diffuseMap and then if that mathes the class your trying to work with
-faster way is to check the classes of the values ;) cuz if something is undeFinedClass it aint a bitmapTexture or a material

Raphael 'Insanto' Steves
http://Graph.Net84.Net

asymptote's picture

I was just about to say

I was just about to say that......but you beat me to it  ...seriously tho' it feels more refined...you obviously took the red pill Cool

Graph's picture

o.0code plsif its the small

o.0
code pls

if its the small block up top then here it is again with failSafes

(
	for Obj in objects where isValidNode obj do 
	(
		local mat = obj.material
		if superClassOf mat == material AND isproperty mat "diffuseMap" AND classOf mat.diffuseMap == bitMapTexture do
		(
			mat.opacityMap = copy mat.diffuseMap
			mat.opacityMap.output.invert = true
		)
	)
)

Raphael 'Insanto' Steves
http://Graph.Net84.Net

asymptote's picture

Now says -- Unknown property:

Now says -- Unknown property: "material" in undefined :/

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.