PDA

View Full Version : <Bitmaptexture>.filename doesn't get bitmap


soulburn3d
06-22-2008, 04:41 PM
Found a bit of oddness that maybe someone has a workaround for. Say I have a bitmap in my material editor, and it's pointing to c:\foo.tga. Now say foo.tga doesn't exist in c:\, but it does exist in c:\ogg\, and c:\ogg\ is in my bitmap path variable. So in the material editor, it finds the bitmap (since the location of the bitmap is in my path), but when I use the maxscript function...

<Bitmaptexture>.filename

It returns the filename of a non existant bitmap. Is there any way to get the actual location of the bitmap without doing a search through all the mapPaths for a bitmap of similar name?

- Neil

ZeBoxx2
06-22-2008, 06:12 PM
I'm sure somebody (PiX!) will throw ATSops at you, so here's my stab...


myBmp = meditmaterials[1]
Map #1:Bitmap
myBmp.filename = "c:\\OAKLEAF.TGA"
"c:\OAKLEAF.TGA"
myBmp.filename
"c:\OAKLEAF.TGA"

getFiles myBmp.filename
#()

fn getBmpFilePath bmpMap = (
local f = bmpMap.filename
local result
if (f == "") then ( result = f )
else if (doesFileExist f) then ( result = f )
else (
local bmp = openBitmap ((getFilenameFile f) + (getFilenameType f))
if (bmp == undefined) then ( result = undefined )
else ( result = bmp.filename )
)
result
)
getBmpFilePath()

getBmpFilePath myBmp
"c:\3dsmax11\Maps\OAKLEAF.TGA"


The above relies on openBitmap scanning bitmap paths just as well as max itself would. Whether it does or not...?

Edit: and here's the thing you wanted to avoid, just in case:

-- function to try and find a bitmap filename
-- function to get all subfolders of a given folder
fn getSubDirs startdir dirArray: = (
-- get all those subfolders using the standard maxscript function
local subDirs = getDirectories (startdir + "*")
-- loop over them
for dir in subDirs do (
-- append each to our results array
append dirArray dir
-- and recursively call this function itself on each of those folders
getSubDirs dir dirArray:dirArray
)
)

fn findMapFile f = (
-- create a variable to hold all folders
myDirs = #()
-- check if there the current max file is saved and thus has a path
if (maxFilePath != "") then (
-- get all its subdirs
local myDirs = #(maxFilePath)
getSubDirs myDirs[1] dirArray:myDirs
)

-- next, append all map paths
for i = 1 to (mapPaths.count()) do (
d = mapPaths.get i
append myDirs d
getSubDirs d dirArray:myDirs
)

-- now loop over all those folders
for dir in myDirs do (
-- and check if the file is in it
if ((getFiles (dir + f)).count != 0) then (
-- if it is, then return that as the result
return (dir + f)
)
)

-- if the file wasn't found, return false
return false
)

MoonDoggie
06-23-2008, 03:39 AM
Maybe my relink-bitmaps script would help?

http://www.scriptspot.com/3ds-max/relink-bitmaps

-Colin

MarcoBrunetta
06-23-2008, 01:13 PM
I came about the same problem a few weeks ago. What I found is that you can use mapPaths.getFullFilePath <filename>. This will return the full path of a bitmap if it exists on any of the pre-defined bitmap paths.

Not a perfect solution as there is no way to feed it a specific bitmap... it will just look for that filename in the bitmap paths, but still works ok and it's pretty clean.

soulburn3d
06-23-2008, 03:27 PM
Thanks everyone.

Marco, that's a good function to know, although since it got added in max9 and I'm still in max8, it won't work till I upgrade all my stuff. But thanks for the info.

Ze, a little question about your second chunk of code. I think I remember running into this, but just want to confirm. If the bitmap exists in the directory the maxfile is in, or any subdirectory of that directory, it gets found, is that correct?

- Neil

ZeBoxx2
06-23-2008, 04:00 PM
Ze, a little question about your second chunk of code. I think I remember running into this, but just want to confirm. If the bitmap exists in the directory the maxfile is in, or any subdirectory of that directory, it gets found, is that correct?

That appears to be the behavior of max, yeah; that's why I check if the max filename is non-null and then check the path it's in, etc. It might be missing some other bit, don't know. The only reasons I've used it is 1. pre-R9 support, 2. faster than openBitmap if it's a lot of maps.

soulburn3d
06-24-2008, 09:33 PM
Just to fnish off the topic for anyone who's interested, it's even more contorted. Max first looks at the path hard coded into the bitmap map. If it can't find it there, it next looks in the path the maxfile is in. If it can't find it there, it looks in the map paths. If it still can't find it, it looks in the subdirs of the maxfile directory.

- Neil

CGTalk Moderation
06-24-2008, 09:33 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.