PDA

View Full Version : [REQUEST] Script to put CC Map in any Diffuse Map


cecofuli
04-12-2012, 12:40 PM
Hi all,
I want to ask if there is come guy who want to write a script for us. It's very simple, I think

Put in front of every existing map in the diffuse channel (for now only diffuse channel) a CC map with Advanced Mode turn on. For all OBJ in the scene or for a selected OBJ

For example, if in a scene I've a material something like that:

CONCRETE
- Concrete diffuse -> Bitmap (only bitmap, for now)

I could to be nice to be:

CONCRETE
- Concrete diffuse -> Color Correct Map -> Bitmap

If we have 100 objects and 300 shaders it's a very time consuming task to do by hand!

Raytracer05
04-12-2012, 04:21 PM
What type are the materials, VRay, standard or ..?

cecofuli
04-12-2012, 04:27 PM
I Raytracer05 (http://forums.cgsociety.org/member.php?u=431129)

thanks for your interest. Here we use 100% VRayMat :)

Raytracer05
04-12-2012, 05:07 PM
This should work for selected objects:
--CC Map in diffuse slot of vray materials on SELECTED objects (should get those inside multiMats, blends etc.)
(
objs = getCurrentSelection()

for obj in objs do
(
bmtArr = getClassInstances Bitmaptexture target:obj

for bmt in bmtArr do
(
rfs = refs.dependents bmt

for rf in rfs do
(
if isKindOf rf vrayMtl then
(
if (isKindOf rf.texmap_diffuse Bitmaptexture) and (rf.texmap_diffuse == bmt) then
(
cc = ColorCorrection map:bmt lightnessMode:1
rf.texmap_diffuse = cc
)
)
)
)
)
)
And this is for all scene vray materials:
--CC Map in diffuse slot of ALL VRay Materials where a bitmap is present (should get those inside multiMats, blends etc.)
(
bmtArr = getClassInstances Bitmaptexture

for bmt in bmtArr do
(
rfs = refs.dependents bmt

for rf in rfs do
(
if isKindOf rf vrayMtl then
(
if (isKindOf rf.texmap_diffuse Bitmaptexture) and (rf.texmap_diffuse == bmt) then
(
cc = ColorCorrection map:bmt lightnessMode:1
rf.texmap_diffuse = cc
)
)
)
)
)

cecofuli
04-12-2012, 05:20 PM
Hi Raytracer05,

wow... thanks! Works very well! This is so useful for every scene or objects we import. In our work-flow we use a CC map before every diffuse map to avoid PS task (when we can) . Now it's just one-click! I don't know how say you thanks ))) :beer:

Raytracer05
04-12-2012, 05:30 PM
Not a problem, I'm sure many of your posts over on the Chaos forum have been useful to me over the years.

cecofuli
04-12-2012, 06:09 PM
That's nice ^___^

Raytracer05
04-13-2012, 10:47 AM
I don't know what I'd been smoking yesterday but it didn't help my already limited maxscript ability :p
Anyway, I've simplified them so they should be much faster in large scenes.

Add CC map to selected objects:
--CC Map in diffuse slot of SELECTED objects
(
objs = getCurrentSelection()

for obj in objs do
(
vrmArr = getClassInstances vrayMtl target:obj

for vrm in vrmArr do
(
if isKindOf vrm.texmap_diffuse Bitmaptexture then
(
cc = ColorCorrection map:(vrm.texmap_diffuse) lightnessMode:1
vrm.texmap_diffuse = cc
)
)
)
)
Add CC map to all VRay materials:
--CC Map in diffuse slot of ALL VRay Materials where a bitmap is present
(
if queryBox "Add CC Map to ALL VRay Materials?" do
(
vrmArr = getClassInstances vrayMtl
for vrm in vrmArr do
(
if isKindOf vrm.texmap_diffuse Bitmaptexture then
(
cc = ColorCorrection map:(vrm.texmap_diffuse) lightnessMode:1
vrm.texmap_diffuse = cc
)
)
)
)

And if you want to add the tools as buttons on a toolbar etc. save this as a .mcr file and drag and drop it over a max viewport. You'll find them under the VRay catagory in customize ui.
macroScript CC_All category:"VRay" tooltip:"Add CC Map to all VRay Materials" buttontext: "CC All"
(
--CC Map in diffuse slot of ALL VRay Materials where a bitmap is present
if queryBox "Add CC Map to ALL VRay Materials?" do
(
vrmArr = getClassInstances vrayMtl
for vrm in vrmArr do
(
if isKindOf vrm.texmap_diffuse Bitmaptexture then
(
cc = ColorCorrection map:(vrm.texmap_diffuse) lightnessMode:1
vrm.texmap_diffuse = cc
)
)
)
)

macroScript CC_Selected category:"VRay" tooltip:"Add CC Map to Selected" buttontext: "CC Selected"
(
--CC Map in diffuse slot of SELECTED objects
objs = getCurrentSelection()

for obj in objs do
(
vrmArr = getClassInstances vrayMtl target:obj

for vrm in vrmArr do
(
if isKindOf vrm.texmap_diffuse Bitmaptexture then
(
cc = ColorCorrection map:(vrm.texmap_diffuse) lightnessMode:1
vrm.texmap_diffuse = cc
)
)
)
)

cecofuli
04-13-2012, 07:15 PM
Much better now! Thanks again ;) :thumbsup:

denisT
04-14-2012, 04:18 AM
I don't know what I'd been smoking yesterday but it didn't help my already limited maxscript ability :p
Anyway, I've simplified them so they should be much faster in large scenes.

how is about to make it better with the using of replaceinstances? ;)

Raytracer05
04-16-2012, 02:39 PM
how is about to make it better with the using of replaceinstances? ;)I'm struggling to see how I can use replaceinstances in this case. Maybe a clue would help :D

The only possible improvement I can see is to lose the if statement and use where to filter the array of materials:
(
if queryBox "Add CC Map to ALL VRay Materials?" do with undo "CC All" on
(
vrmArr = getClassInstances vrayMtl
for vrm in vrmArr where isKindOf vrm.texmap_diffuse Bitmaptexture do
(
cc = ColorCorrection map:(vrm.texmap_diffuse) lightnessMode:1
vrm.texmap_diffuse = cc
)
)
)

denisT
04-16-2012, 03:27 PM
I'm struggling to see how I can use replaceinstances in this case. Maybe a clue would help :D

i want to say first that your method is faster and better than mine in this particular case. I just want to show the alternative way that might work better in some other situations:

fn replaceTexturemaps =
(
for tx in (getclassinstances bitmaptexture astrackviewpick:on) do
for mat in (refs.dependents tx.client immediateOnly:on) where iskindof mat Standard do
(
if matchpattern (getSubAnimName tx.client tx.subnum) pattern:"diffuse_color__map_*" do replaceinstances tx.anim (ColorCorrection map:(copy tx.anim))
)
)

this sample is more about how to find a texturemap by material class and it's property...

edit: has to work now...

denisT
04-16-2012, 04:20 PM
there was some problem with instancing... the copy of bitmap texture has to be used.

Raytracer05
04-16-2012, 05:28 PM
Thanks for posting your alternative, it's always useful to see a different approach.

My first attempt was to find all bitmapTextures because I started working on a solution before I read the OP's reply that he only needed to find bitmaps on VRay materials. However I don't fully understand what withTrackViewPick:true does or how to use the .client property so my solution was a bit untidy. Need to do some more reading...

denisT
04-16-2012, 05:43 PM
here is a basic idea behind my method...

we have two materials which share the bitmap texture as their diffuse maps.
so both texture maps are instances of the same object.
well... when we change them using my method we keep instancing for their subanim values.
both materials have the instances of the same ColorCorrection object.

weixiong
05-19-2012, 09:49 AM
I don't know what I'd been smoking yesterday but it didn't help my already limited maxscript ability :p
Anyway, I've simplified them so they should be much faster in large scenes.

Add CC map to selected objects:
--CC Map in diffuse slot of SELECTED objects
(
objs = getCurrentSelection()

for obj in objs do
(
vrmArr = getClassInstances vrayMtl target:obj

for vrm in vrmArr do
(
if isKindOf vrm.texmap_diffuse Bitmaptexture then
(
cc = ColorCorrection map:(vrm.texmap_diffuse) lightnessMode:1
vrm.texmap_diffuse = cc
)
)
)
)


oh,unfortunately, "Add CC map to selected objects:"
this is invalid,any one can fix it?

gazybara
05-19-2012, 10:25 AM
This is my "not perfect" solution (it's slow)

try (destroydialog ::AddCCMapRoll) catch()
rollout AddCCMapRoll "Add CC Map"
(
fn addCCMap mtl =
(
case classof mtl of (
(VRayMtl): (
if mtl.texmap_diffuse != undefined and classof mtl.texmap_diffuse != Color_Correction do
(
local curMap = mtl.texmap_diffuse
mtl.texmap_diffuse = Color_Correction name:"CC_Map" map:curMap
)
)
(Standardmaterial): (
if mtl.diffuseMap != undefined and classof mtl.diffuseMap != Color_Correction do
(
local curMap = mtl.diffuseMap
mtl.diffuseMap = Color_Correction name:"CC_Map" map:curMap
)
)
(Arch___Design__mi): (
if mtl.mapM0 != undefined and classof mtl.mapM0 != Color_Correction do
(
local curMap = mtl.mapM0
mtl.mapM0 = Color_Correction name:"CC_Map" map:curMap
)
)
) ; mtl.showInViewport = true
)
button adjustmap "Adjust map" pos:[5,5] width:90 height: 20
on adjustmap pressed do
(
local mtlslistArr = #(Multimaterial, VrayMtl, Arch___Design__mi, Standardmaterial)
for obj in selection do
(
local mtl = obj.material
if finditem mtlslistArr (classof mtl) == 1 then
(
for sm in mtl.materialList where finditem mtlslistArr (classof sm) > 1 do addCCMap sm
)
else if finditem mtlslistArr (classof mtl) > 1 do addCCMap mtl
)
)
)
createdialog AddCCMapRoll 100 30 style:#(#style_titlebar, #style_sysmenu, #style_toolwindow)

Raytracer05
05-22-2012, 11:09 AM
oh,unfortunately, "Add CC map to selected objects:"
this is invalid,any one can fix it?Why is it 'invalid'?
Do you get an error message?

gazybara
05-22-2012, 11:38 AM
Why is it 'invalid'?
Do you get an error message?
Probably because of his scenes have different types of materials and not only VrayMtl

Raytracer05
05-22-2012, 11:59 AM
Yes, it could be that. Also it will ignore all maps other than bitmapTexture in the diffuse slot.

gazybara
05-22-2012, 12:19 PM
Yes, it could be that. Also it will ignore all maps other than bitmapTexture in the diffuse slot.
Yep. I saw his concept for the whole script.He also need to add more materials and maps class
in the "checklist" for sure.

CGTalk Moderation
05-22-2012, 12:19 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.