ScriptSpot home

Forum topic · General Scripting

access texturemap from VRayDirt

By tonny antou · 2013-10-15

Description

Hi I have a problem for getting texturmap from vraydirt that already inside some object.if i using $.material.diffusemap.vraydirt.texmap_occluded_color.bitmaptexture.filename
it result error Unknown property: "texmap_occluded_color" in .
I would be realy greatfull if someone could help me to solve this problem since i have so many material i have to change.

Comments (21)
tonny antou

Nice one, It works thanks a lot guys its save my time :D

Reply to Budi Gunawan
Branko Živković

"collect all DIRT maps from selected objects"

Ok.
In order to collect all VRayDirt Maps on the scene we can use


getClassInstances VRayDirt

But that is easy. Now answer for the post title :


--collect all DIRT maps from selected objects FN
fn getDirtOf objMtl &inTrashCan =
(
	for m in (refs.dependsOn objMtl) do
	(
		case (superclassof m) of
		(
			material: getDirtOf m &inTrashCan
			textureMap: if isKindOf m VRayDirt and (for t in inTrashCan where t.name == m.name collect m).count == 0 do append inTrashCan m
		)
	)
)

-- Select some objects and run next
dirtMaps = #() -- here we collect all dirt :)
for obj in selection where obj.material != null do getDirt obj.material &dirtMaps
dirtMaps -- result

-- Now when the trash can is full we can do whatever we want
for dm in dirtMaps do
(
	format "vrDirt Name : %\n" dm.name
	format "\tObjects : %\n" (for n in (refs.dependentNodes dm) collect n.name)
	for p in getPropNames dm where isKindOf (gp = getProperty dm p) textureMap do
		format ("\t" + toUpper (p as string) + " : %\n") gp
-- etc.
)

Hope this is not too difficult to understand

;) Cheers!

Reply to Branko Živković
Budi Gunawan

Branko
run your script , got an error ...

you wrote :


for obj in selection where obj.material != null do getDirt obj.material &dirtMaps

- What is the value of 'null' ?
- You don't have getDirt() function, probably mean is getDirtOf() , is it right ?

Reply to Budi Gunawan
Branko Živković

Yup getDirtOf(). I changed name of fn but forgot to change in for-loop.
null is undefined variable. U can put any word or simple use predefined 'undefined'

fn getDirtOf objMtl &inTrashCan =
(
for m in (refs.dependsOn objMtl) do
(
case (superclassof m) of
(
material: getDirtOf m &inTrashCan
textureMap: if isKindOf m VRayDirt and (for t in inTrashCan where t.name == m.name collect m).count == 0 do append inTrashCan m
)
)
)
-- now select some objects and run next
dirtMaps = #()
for o in selection where o.material != undefined do getDirtOf o.material &dirtMaps
dirtMaps
for dm in dirtMaps do
(
format "vrDirt Name : %\n" dm.name
format "\tObjects : %\n" (for n in (refs.dependentNodes dm) collect n.name)
for p in getPropNames dm where isKindOf (gp = getProperty dm p) textureMap do
format ("\t" + toUpper (p as string) + " : %\n") gp
)

Reply to Branko Živković
Budi Gunawan

ok, now a script works,...sound good.

hmm in this case you just collect the vray dirt map, not the filename as he need.
such as:

format ("\t" + toUpper (p as string) + " : %\n") gp.filename

and it will be better to need more filters because the vray dirt map can apply to standard material or multi material.

btw about standard material, is a different method than vray material if we use this methods.

Reply to Budi Gunawan
Branko Živković

This supports any type of material. And I placed "--etc." at the end, so you can add below that anything even to look for filenames. Also in some cases users not use only bitmap textures but other procedural maps.
The main problem is to collect VRayDirt maps from selected objects materials and after that everything is easy. :)
Now next step is to collect all bitmap textures which are directly asigned to VRayDirt maps slot, or indirecty (combined with procedurals)
Now is your turn, Budi :)

Reply to Branko Živković
Branko Živković

The next solution can be related not only to VRayDirt map but any other map type.
As U see I used *superclasses not *classes that why I not needed more filters
Best way is to use RECURSIVE FN.
I already posted a solution how to collect all nested bitmaps on this forum

Reply to Branko Živković
Budi Gunawan

Get all Vray Dirt Maps Filename

Yup, Recursive functions can be faster.

(--start
    fn GrabAllMaps mat arr = 
	(
		if mat.numsubs != 0 then (
			for i = 1 to mat.numsubs do (
				if mat[i] != undefined then (
					if classof mat[i] == SubAnim then (
						if superclassof mat[i].object == textureMap then (
							if mat[i].object != undefined then append arr mat[i].object
						)
					)
				GrabAllMaps mat[i] arr
				)
			)
		)
	) -- This function taken from BlurScripts by Neil Blevins, I found in ColinScripts a few years ago. ( Thanks for Them )
  -----------------------------------------------------------------------------------------------------------
  fn GrabVdirtMaps mat =
  (
     if mat != undefined then 
	 (
        local AllMaps=#(), VrayDirtMapFile=#(), x,p
	    GrabAllMaps mat AllMaps 
		for x=1 to AllMaps.count where (classof AllMaps[x])==VRayDirt do
		(
		  for p in (getPropNames AllMaps[x]) where superclassof (prop = getProperty AllMaps[x] p) == textureMap do append VrayDirtMapFile prop.filename
		)
	   VrayDirtMapFile
     )
   )
   --------------------------------------------------------------------- execute as example
   for obj in selection do print (GrabVdirtMaps obj.material)
)--end
Reply to Budi Gunawan
Branko Živković

Yup. Thats the one. I used this fn a couple of times but when the scene is complex (with many textures) then is also very slow.
We can optimize this a bit more but requester not asked for more. So... :)
Regards!

Reply to Branko Živković
Budi Gunawan

oh, it's Ok Branko...
I hope to see you to optimize this method. If you don't mind :)

I just think it could use a INI file or xml to handle Memory allocation.

Reply to Budi Gunawan
Branko Živković

Ok. I have a suggestion.
Open new thread and then we can start a discussion about universal solution (fn) which can be related to any map or material type.
First we have to setup basic concept (what we need to do in order to solve the problem) without snippets.
This fn must found all fileNames in (Bitmap, VRayHDRI, VRayBmpFilter etc.) of specified map class (VRayDirt, Noise, Composite, ColorCorrection etc.) assigned to the any material (Standard, VRayMtl, Arch&Design, Blend, Multimaterial etc.)
Also are we need to consider only selected objects or whole scene
Uh... :)
Are you agree?

Budi Gunawan

Hi..
try this one
You don't need to write 'vraydirt' and 'bitmaptexture', such as:


$.material.diffusemap.texmap_occluded_color.filename
Reply to Budi Gunawan
Branko Živković

If you have many objects and you want to collect all maps in VrayDirt map then
u can try this. Also this works only if dirt map is in diffuse slot of VRayMtl

fn findDirtMaps obj = if obj.material != undefined do
(
local props = #(#texmap_radius, #texmap_occluded_color, #texmap_unoccluded_color, #texmap_reflection_glossiness)
if isKindOf (mtl = obj.material) VRayMtl do
if isKindOf (dirt = mtl.texmap_diffuse) VRayDirt do
for p in props where (map = getProperty dirt p) != undefined collect map
)
findDirtMaps $

Reply to Branko Živković
Branko Živković

Function will be more complex if you need to support different material types and any map slot.

Reply to Budi Gunawan
Branko Živković

Hey Budi
how about more complex solution ei. "collect all DIRT maps from selection". :)
Post if you have something and we can talk about

Reply to Branko Živković
Budi Gunawan

I have this one

This is Collect v dirt of diffuse map only


( -- start script
	
local VdirtMapsCollection =#() -- Init
	
fn getVdirtMapFilename diff =
(
	local map_filename=#(), propname, prop, map
    if classof diff == VRayDirt then 
    (
      propname = getPropNames diff
      for prop in propname do
      (
	    map = getProperty diff prop
        if classof map == Bitmaptexture then
        ( if map !=undefined then if map.filename !="" then append map_filename map.filename )
      )
    )
	map_filename
) -- fn

fn GrabVdirtMaps mat =
(
  if classof mat == Standardmaterial  then
  (
    if classof mat.diffusemap == VRayDirt then ( VdirtMapsCollection += getVdirtMapFilename mat.diffusemap )
  ) else
  (
	if classof mat == VRayMtl  then
	(
		if classof mat.texmap_diffuse == VRayDirt then ( VdirtMapsCollection += getVdirtMapFilename mat.texmap_diffuse )
	) else
	(
		if classof mat == MultiMaterial  then 
		(
		  if mat.numsubs != 0 then for index=1 to mat.numsubs do (GrabVdirtMaps mat[index])
		)
	)
  )
) -- fn

   ----------------------------------------------execute
   GrabVdirtMaps $.material
   --clearlistener()
   VdirtMapsCollection -- this is All Collection of Vray dirt
) --end script

do you want optimize it ? :)

Branko Živković


fn findDirtOccludedMap obj =
(
if isKindOf (mtl = obj.material) VRayMtl do
if isKindOf (dirt = mtl.texmap_diffuse) VRayDirt do
if isKindOf (tex = dirt.texmap_occluded_color) Bitmaptexture do
format "bitmap = %\nfilename = %\n" tex.bitmap tex.filename
)
findDirtOccludedMap $