Notifications
Clear all

[Closed] [REQUEST] Script to put CC Map in any Diffuse Map

I’m struggling to see how I can use replaceinstances in this case. Maybe a clue would help

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
		)
	)
)

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…

there was some problem with instancing… the copy of bitmap texture has to be used.

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…

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.

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

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)

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?

Probably because of his scenes have different types of materials and not only VrayMtl

Yes, it could be that. Also it will ignore all maps other than bitmapTexture in the diffuse slot.

1 Reply
(@gazybara)
Joined: 11 months ago

Posts: 0

Yep. I saw his concept for the whole script.He also need to add more materials and maps class
in the “checklist” for sure.

Page 2 / 2