View Full Version : Collecting BitmapTextures in Scene (m.filename == "")

01 January 2009, 12:48 PM
Ref. Thread:

I'm trying to collect 2 separate array's which both identify any bitmap textures in the scene which may have a "bitmap" assigned to any channel of say, a material, but it could also be the environment channel, etc, but the filepath has not been assigned. ie: m.filename == ""

The first array will collect any materials in the scene currently assigned to objects/environment, etc and the second array will collect any materials ONLY in the mat.editor, which are missing the bitmaptexture filepath.

So far, I have:

NONEBitmaps = for m in getClassInstances BitmapTexture where (m.filename == "") collect m

However, I'm getting a bit confused with regard the best approach to obtain the actual materials or mat.editor slots from these references...!

I'm thinking something along the lines of:

dependentRefs = for n in 1 to NONEBitmaps.count where (refs.dependents NONEBitmaps[n] != 0) collect n
mats = for i in dependentRefs where (superClassOf i == material) or (classof i == MaterialLibrary) collect i

But I'm still a bit of the mark...!

Any help, as always, would be appreciated!

01 January 2009, 01:58 PM
The biggest problem you're running into is that you are collecting 'n' in the 2nd line. 'n' is your loop counter, so you're just collecting numbers - not the references themselves.
Thus in the third line, the classof for that 'reference' will always be (in this case) integer :)

NONEBitmaps = for m in (getClassInstances BitmapTexture) where (m.filename == "") collect ( m )
dependentRefs = for noneBmp in NONEBitmaps collect ( refs.dependents noneBmp )
for i = 1 to dependentRefs.count do (
refs = dependentRefs[i]
newrefs = for r in refs where ((superClassOf r == material) OR (classOf r == Material_Editor)) collect ( r )
dependentRefs[i] = newrefs
-- now you've got two arrays...
-- NONEBitmaps that holds the bitmaps
-- dependentRefs that, for each bitmap, holds the valid references
-- where 'valid' means it's either a material, or the material editor (not library(!))
-- let's print the results out
for i = 1 to NONEBitmaps.count do (
format "Dependents for '%':\n" noneBitmaps[i]
for j = 1 to dependentRefs[i].count do (
format "\t%\n" dependentRefs[i][j]

However, I should 'warn' you, that getClassInstances doesn't always get all the required results (sure wish it would)... it will work on materials assigned to objects and the like, but good luck getting e.g. a Blur render effect's mask bitmap using getClassInstances.

Neil Blevins has functions in his soulburn library that loop over a scene in a more thorough manner that you might be able to use instead, if the above is a concern.

01 January 2009, 06:59 PM
Thanks Richard!

CGTalk Moderation
01 January 2009, 06:59 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.