PDA

View Full Version : Automated Material Editing


Mike Truly
06-08-2009, 03:54 AM
I am not a scripter but I think this is a job for MAXscript but I'm wondering if some scripted tool already exists to do this kind of thing.

I have thousands of materials in a scene where each material has a 24bit JPG in the diffuse slot. I am creating a B/W GIF as an opacity map for each material. The GIFs will have the same exact name as the file in the diffuse slot only it will have a GIF extension.

Is there a tool that will load each material, copy the path/filename in the diffuse slot and insert it into the opacity map slot with a GIF extension and turn on the opacity map checkbox and save the material when done?

Thanks for any ideas!

Zbuffer
06-08-2009, 10:36 AM
Hi,

Try somthing around these lines:

(
mats= for m in sceneMaterials collect m
for m in mats do
(
Diff=m.diffuseMap
if classof Diff == bitmapTexture do
(
d=Diff.fileName
o=GetfileNamePath d + GetfileNameFile d + ".gif"
Opa = bitmapTexture filename:o
m.opacityMap = Opa
)
)
)


Note: this works for standard material ONLY...

Mike Truly
06-08-2009, 12:14 PM
Thanks so much for this! I'll give it a try.

Thanks again.

Mike Truly
06-09-2009, 01:59 AM
The script works great but there is one issue. The thousands of objects that this is run on currently have artifacts in the render because of the Blur value in the Texture Coordinates panel.

What is the Maxscript parameter that controls this blur value so that when added to this script will let me set the Blur value for both the Diffuse map and Opacity map?

Thanks again for this tool!

ZeBoxx2
06-09-2009, 02:13 AM
Diff.coords.blur = 0.0 (defaults to 1.0, I think)
-- Diff.coords.Blur_Offset = 0.0 (should default to 0.0 already)


Similar for 'Opa'

floopyb
06-09-2009, 02:14 AM
as far as the above script goes its: m.opacityMap.coords.blur

I built a script to do this type of mass editing like changing all blur settings. It wont do complex stuff like copying the diffusemap but you might find it useful:
http://www.scriptspot.com/3ds-max/modifier-modifier-zorb

Mike Truly
06-09-2009, 02:53 AM
Thanks very much for these pointers... greatly appreciated!

Thanks again.

Mike Truly
07-07-2009, 09:04 PM
OK, this script has been working great (thanks!) but now I need to change it slightly. I know this is simple but not being a scripter, I don't know how to do it.

The script modifies ALL scene materials. I need it to modify only the materials on the selected objects.

When I change 'sceneMaterials' to 'selection'... it bombs. What do I need to add to make it work on the selected objects only?

Thanks again!

Kramsurfer
07-07-2009, 10:34 PM
I haven't seen the code, but you need to collect the Materials on the selected objects just before the loop that effects them...



SelectedMaterials = #()
for SelObj in Selection do
if ( isProperty SelObj #material ) do
if ( SelObj.material != undefined ) do
append SelectedMaterials SelObj.material



Then replace sceneMaterials with the variable SelectedMaterials

MarcoBrunetta
07-07-2009, 10:37 PM
(
mats= for o in selection WHERE o.material != undefined collect o.material
for m in mats do
(
Diff=m.diffuseMap
if classof Diff == bitmapTexture do
(
d=Diff.fileName
o=GetfileNamePath d + GetfileNameFile d + ".gif"
Opa = bitmapTexture filename:o
m.opacityMap = Opa
)
)
)

The "sceneMaterials" variable holds materials, however the "selection" variable holds 3d Studio objects, so you need to access their material property. I also added a quick filter to skip objects that have no material assigned.

EDIT: woops, got here a second late =P. In any case, is it necessary to check that the node has a material property? I thought that everything that could be selected had a material property.

Kramsurfer
07-07-2009, 10:45 PM
Not sure.. But I do know, if I don't trap it they'll brake it somehow...

MarcoBrunetta
07-07-2009, 11:01 PM
Hehe, I understand, better safe than sorry.

Mike Truly
07-08-2009, 02:09 AM
Thanks for all the ideas!

Marco,

I tried editing the Macroscript and adding the modified line you had... it evaluates just fine but the result is still that ALL objects get the material modification instead of just the selected ones. There must be more that needs to be added beyond that first line.

For example, in my current scene I have ground objects and building objects. I select all the ground objects and execute the script and all seems fine. But when I go to test render... the complain dialog says it can't find the opacity maps for the building objects (which should have been unaffected).

Thanks again.

Kramsurfer
07-08-2009, 02:15 AM
could you post up the whole script you're using so we can look at it... thanks

Mike Truly
07-08-2009, 02:52 AM
Here's what I'm currently using:

macroScript Macro3
category:"DragAndDrop"
toolTip:""
(

(
mats= for o in selection WHERE o.material != undefined collect o.material
for m in mats do
(
Diff=m.diffuseMap
if classof Diff == bitmapTexture do
(
d=Diff.fileName
o=GetfileNamePath d + GetfileNameFile d + ".gif"
Opa = bitmapTexture filename:o
m.opacityMap = Opa
m.diffuseMap.coords.blur = 0.5
m.opacityMap.coords.blur = 0.0
)
)
)
)

Thanks!

MarcoBrunetta
07-08-2009, 03:06 AM
Well the script is correctly collecting the materials from the selection as far as I can tell. However if the ground objects use the same material as the building objects, then the script will affect both, since in max several objects can have an instance of the same material.

If that is the case then the script should create a copy of the material and assigning it to the selection, and then modifying those copies.

Mike Truly
07-08-2009, 01:01 PM
Let's see if I can explain this better.

I have 100 building objects and 100 ground objects in the scene. Each has a unique material. Each material name matches the object name. So 'building001' object has 'building001' material, etc.

If (before using the script) I examine one object of each type... the material of the ground objects have a single, diffuse map and the building objects also only have a single, diffuse map.

I select the ground objects only.

I run the script.

I re-examine the materials. BOTH the ground and building objects now have an opacity map added to their materials.

So it seems that not only the selected objects are being affected. Not sure why since I'm clueless when it comes to scripting.

Thanks!

Mike Truly
07-08-2009, 01:16 PM
Hmmmm. OK, I was doing something wrong.

Marco, your script modification DOES work... Thanks!

Here's what I don't understand. The previous script I have been using, I had dragged it to a toolbar and had been clicking it as a button. So when I wanted to add Marco's modification, I simply right-clicked on the button and chose Edit Macroscript. I edited the script and then chose Save and closed the editor window. And then I clicked the button again to run the script. This produced the results I described earlier... selected AND unselected objects got their materials modified.

But when I dragged the code to the toolbar (and a new button was made) and then clicked this button... I got the proper results where ONLY the selected objects had their materials modified.

Why did this happen? Shouldn't 'Edit Macroscript' have worked? Perhaps there was some other change I missed when editing the macroscript by hand?

Thanks again!

MarcoBrunetta
07-08-2009, 02:02 PM
Hehe, besides changing the script, you needed to re-evaluate it. Scripts need to be evaluated before they can be used (somewhat like how most programs need to be compiled before they can be run), dragging the code to the toolbar does that automatically. Restarting max also forces a re-evaluation of all scripts.

Mike Truly
07-08-2009, 02:58 PM
Ahhhh... so I was saving it but because I was not re-starting MAX it wasn't getting re-evaluated upon startup. And since I wasn't re-evaluating manually... it was still using the old script and not the new.

Thanks again!

MarcoBrunetta
07-08-2009, 03:02 PM
Exactly! Think of evaluating as "installing" the script if you want...

CGTalk Moderation
07-08-2009, 03:02 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.