PDA

View Full Version : Billboards from all bitmaps in a folder


jonahhawk
07-24-2008, 03:24 AM
I am working on a script to build image planes from tif files (could be anything with an alpha). I have learned and pieced it together from several other scripts. You can see I'm using VRay. That part should be easy for anyone to adopt to their own renerer.

I had it working and created 100 billboards, but after restarting max, the script no longer works. I had help from our scripting guy along the way but he has gone home. I obviously had defined some global that it still was using... but now I can't remember what it was...

I'm sure it is something simple.
(I can't include the full path here, subsituted part of it. I also tried to shorten the indents to make it read better here)

files = getFiles "\\\\--UNC_Path\\resources\\materials\\images\\People\\RealWorldImagry\\urbanmoods\\32bitTIFimages\\temp\\*.tif" --will be variable later
(for f = 1 to files.count do
(
local theMap = bitmap 10 10 color:white
theMap.filename = files[f]


-- Get the ratio of the bitmap and set the length and width acordingly
local planeRatio = (theMap.width as float)/(theMap.height as float)

(
local theLength = 68 --will be variable later
local theWidth = theLength*PlaneRatio
)

--Set naming
local refPlaneName = (getFilenameFile theMap.filename)

--build material
local matName = (getFilenameFile theMap.filename)
local theMaterial = VRayMtl() name = refPlaneName
theMaterial.texmap_diffuse = Bitmaptex bitmap:theMap name:(refPlaneName + "_Diffuse")
theMaterial.texmap_diffuse.coords.blur = 0.01
theMaterial.texmap_opacity = Bitmaptex bitmap:theMap name:(refPlaneName + "_Opacity")
theMaterial.texmap_opacity.rgboutput = 1
theMaterial.texmap_opacity.monooutput = 1
theMaterial.texmap_opacity.coords.blur = 0.01
showTextureMap theMaterial theMaterial.texmap_diffuse on

--build plane
local refPlane = plane name:refPlaneName length:theLength width:theWidth lsegs:1 wsegs:1 mapCoords:true
refplane.material = theMaterial
refplane.realWorldMapSize = off
refplane.lengthsegs = 1
refplane.widthsegs = 1

--position the plane
in coordsys (transmatrix refplane.transform.pos) refplane.rotation = (eulerangles -90 0 0)
ResetXForm refplane ; CollapseStack refplane
refplane.pivot = [(refplane.max.x+refplane.min.x)/2, refplane.min.y, refplane.min.z]
refplane.pos = [0,0,0]
)
)

I get the error:

#("\\--UNC_Path\resources\materials\images\People\RealWorldImagry\urbanmoods\32bitTIFimages\temp\peopl400.tif", "\\--UNC_Path\resources\materials\images\People\RealWorldImagry\urbanmoods\32bitTIFimages\temp\peopl401.tif", "\\--UNC_Path\resources\materials\images\People\RealWorldImagry\urbanmoods\32bitTIFimages\temp\peopl402.tif", "\\--UNC_Path\resources\materials\images\People\RealWorldImagry\urbanmoods\32bitTIFimages\temp\peopl403.tif", "\\--UNC_Path\resources\materials\images\People\RealWorldImagry\urbanmoods\32bitTIFimages\temp\peopl404.tif", "\\--UNC_Path\resources\materials\images\People\RealWorldImagry\urbanmoods\32bitTIFimages\temp\peopl405.tif")
-- Error occurred in f loop; filename: C:\Program Files (x86)\Autodesk\3ds Max 9\Scripts\UserScripts\MyTools_BitmapPlanesFromFiles.ms; position: 817
-- Frame:
-- theMaterial: VRayMtl:VRayMtl
-- planeRatio: 1.33333
-- refPlane: undefined
-- refPlaneName: "peopl400"
-- name: "peopl400"
-- matname: "peopl400"
-- theLength: 68
-- thewidth: 90.6667
-- f: 1
-- called in anonymous codeblock
-- Frame:
-- Runtime error: Assignment failed, the bitmap should be saved first, BitMap:\\--UNC_Path\resources\materials\images\People\RealWorldImagry\urbanmoods\32bitTIFimages\temp\peopl400.tif
OK


Any help would be primo,

Thanks,

Jonah

thatoneguy
07-24-2008, 03:38 AM
Only thing unusual I see is the length and width being defined as "local" and inside () but somehow being seen outside. I would have expected them to be local to the () but somehow they're escaping. what happens if yout ake the length and width definitions outside of the ()?

Can you add some "print "1"" "Print "2"" declarations along the way to determine exactly where it's failling? Or does it highlight a specific line?

jonahhawk
07-24-2008, 03:40 AM
wow thanks for the fast reply.

same error

-- Error occurred in f loop; filename: C:\Program Files (x86)\Autodesk\3ds Max 9\Scripts\UserScripts\MyTools_BitmapPlanesFromFiles.ms; position: 856
-- Frame:
-- theMaterial: VRayMtl:VRayMtl
-- theMap: BitMap:------\resources\materials\images\People\RealWorldImagry\urbanmoods\32bitTIFimages\temp\peopl400.tif
-- planeRatio: 1.0
-- refPlane: undefined
-- refPlaneName: "peopl400"
-- name: "peopl400"
-- matname: "peopl400"
-- theLength: 68
-- thewidth: 68.0
-- f: 1
-- called in anonymous codeblock
-- Frame:
-- Runtime error: Assignment failed, the bitmap should be saved first, BitMap:

jonahhawk
07-24-2008, 03:44 AM
I should have credited Jon Seagull for his script Proportional Planes

http://www.scriptspot.com/3ds-max/proportional-plane (http://www.scriptspot.com/3ds-max/proportional-plane)

thatoneguy
07-24-2008, 03:46 AM
I'm a bit confused as to which line it's happening on.

It looks like it's happening after the VRay Material is defined but *before the plane is created.

Could you verify that by inserting a couple of print statements to see what the last printed print statement is?

jonahhawk
07-24-2008, 03:50 AM
I could if I knew what you meant...:hmm:

I assume you mean, for example:

print theMaterial

which variables should I print?

thatoneguy
07-24-2008, 03:51 AM
local theMaterial = VRayMtl() name = refPlaneName


I'm suspicious of this line. That isn't proper Maxscript grammar.

It should be something like

thematerial = VrayMtl()
thematrial.name = refPlaneName


or

TheMaterial = VrayMtl name:refPlaneName

No need to print specific variables. Just print "Hello 1" "hello 2" "hello 3"

What's important is where the last print successfully executed before crashing not what it prints.

jonahhawk
07-24-2008, 03:57 AM
that looks familiar... like i had that somewhere before...

This is what I get for butchering other people's work.

I'll give it a go and get back...

jonahhawk
07-24-2008, 04:03 AM
Thanks for the continued help.

It looks like it is breaking on the next line now

theMaterial.texmap_diffuse = Bitmaptex bitmap:theMap name:(refPlaneName + "_Diffuse")


Error:
Runtime error: Assignment failed, the bitmap should be saved first, BitMap:....\resources\materials\images\People\RealWorldImagry\urbanmoods\32bitTIFimages\temp\peopl400.tif


this was all working an hour ago. I have a scene file with 100 planes with materials and maps named accordingly...

EDIT: I see what you mean with the printing. that helps to see how far into the script it gets and wheather or not the results are as expected. Nice tip for the nooby me.

thatoneguy
07-24-2008, 04:06 AM
What's the error? I don't have VRay so I can't help on any VRay Mat specific stuff.

Ok I just rewrote it to work with standard and I get the same error as you are getting... weird... It's not Vray related and it's definitely in that BitmapTex line.

thatoneguy
07-24-2008, 04:20 AM
DOH!

bitmaptex filename:map.filename name:""

assign a filename not a bitmap to the bitmaptex.

*beats head on desk.*

jonahhawk
07-24-2008, 04:24 AM
I'm getting closer I can feel it!

for starters I did have the vray version of bitmaptex wrong...

( for f = 1 to files.count do
(
local theMap = bitmap 10 10 color:white
theMap.filename = files[f]


-- Get the ratio of the bitmap and set the length and width acordingly
local planeRatio = (theMap.width as float)/(theMap.height as float)

local theLength = 68 --will be variable later
local theWidth = theLength*PlaneRatio


--Set naming
local refPlaneName = (getFilenameFile theMap.filename)

print refplaneName

--build material
local matName = (getFilenameFile theMap.filename)
local theMaterial = VRayMtl()
theMaterial.name = refPlaneName
theMaterial.texmap_diffuse = Bitmaptexture fileName:theMap
theMaterial.texmap_diffuse.name = (refPlaneName + "_Diffuse")
theMaterial.texmap_diffuse.coords.blur = 0.01
theMaterial.texmap_opacity = Bitmaptexture fileName:
theMaterial.texmap_opacity.name = (refPlaneName + "_Opacity")
theMaterial.texmap_opacity.rgboutput = 1
theMaterial.texmap_opacity.monooutput = 1
theMaterial.texmap_opacity.coords.blur = 0.01
showTextureMap theMaterial theMaterial.texmap_diffuse on

print matName
print theMaterial

--build plane
local refPlane = plane name:refPlaneName length:theLength width:theWidth lsegs:1 wsegs:1 mapCoords:true
refplane.material = theMaterial
refplane.realWorldMapSize = off
refplane.lengthsegs = 1
refplane.widthsegs = 1

--position the plane
in coordsys (transmatrix refplane.transform.pos) refplane.rotation = (eulerangles -90 0 0)
ResetXForm refplane ; CollapseStack refplane
refplane.pivot = [(refplane.max.x+refplane.min.x)/2, refplane.min.y, refplane.min.z]
refplane.pos = [0,0,0]
)
)

Error:

#("...\3D\resources\materials\images\People\RealWorldImagry\urbanmoods\32bitTIFimages\temp\peopl400.tif", "...\resources\materials\images\People\RealWorldImagry\urbanmoods\32bitTIFimages\temp\peopl401.tif", "...\resources\materials\images\People\RealWorldImagry\urbanmoods\32bitTIFimages\temp\peopl402.tif", "...\resources\materials\images\People\RealWorldImagry\urbanmoods\32bitTIFimages\temp\peopl403.tif", "...\resources\materials\images\People\RealWorldImagry\urbanmoods\32bitTIFimages\temp\peopl404.tif", "...\resources\materials\images\People\RealWorldImagry\urbanmoods\32bitTIFimages\temp\peopl405.tif")
"peopl400"
-- Error occurred in f loop; filename: C:\Program Files (x86)\Autodesk\3ds Max 9\Scripts\UserScripts\MyTools_BitmapPlanesFromFiles.ms; position: 893
-- Frame:
-- theMaterial: peopl400:VRayMtl
-- theMap: BitMap:...\resources\materials\images\People\RealWorldImagry\urbanmoods\32bitTIFimages\temp\peopl400.tif
-- planeRatio: 1.0
-- refPlane: undefined
-- refPlaneName: "peopl400"
-- matname: "peopl400"
-- theLength: 68
-- thewidth: 68.0
-- f: 1
-- called in anonymous codeblock
-- Frame:
-- Unable to convert: BitMap:...\resources\materials\images\People\RealWorldImagry\urbanmoods\32bitTIFimages\temp\peopl400.tif to type: FileName
OK

thatoneguy
07-24-2008, 04:26 AM
You're trying to feed a bitmap class into a string (Filename) slot.

Don't feed it the whole themap bitmap just feed it themap.filename

jonahhawk
07-24-2008, 04:30 AM
BINGO BABY!!!:bounce:

You rock!!!

Sometimes I get on a roll with scripting and everything works. Most of the time I hit the wall and my brain freezes. Thanks so much for the help.

When (if) I get the rollout setup I'll post the completed script. I haven't found anything exactly like this out there. I'm sure someone has written it somewhere.

thatoneguy
07-24-2008, 04:34 AM
BINGO BABY!!!:bounce:

You rock!!!

Sometimes I get on a roll with scripting and everything works. Most of the time I hit the wall and my brain freezes. Thanks so much for the help.

When (if) I get the rollout setup I'll post the completed script. I haven't found anything exactly like this out there. I'm sure someone has written it somewhere.

Hehe... I actually have one on my toolbar at work that I wrote. I just tend to reuse code over and over instead of writing from scratch. Creating a material is one of those little blocks of code I just usually copy paste. Evidently I need to write it from scratch more often.

jonahhawk
07-24-2008, 04:45 AM
For anyone who happens upon this before I get the whole thing posted, here is a functioning version of my mess above.


files = getFiles "\\\\insert your own path here\\*.tif" --will be variable later
( for f = 1 to files.count do
(
theMap = openBitMap files[f]
theMap.filename = files[f]


-- Get the ratio of the bitmap and set the length and width acordingly
local planeRatio = (theMap.width as float)/(theMap.height as float)
(
local theLength = 68 --will be variable later
local theWidth = theLength*PlaneRatio
)

--Set naming
local refPlaneName = (getFilenameFile theMap.filename)

print refplaneName

--build material
local matName = (getFilenameFile theMap.filename)
local theMaterial = VRayMtl()
theMaterial.name = refPlaneName
theMaterial.texmap_diffuse = Bitmaptexture fileName:theMap.filename
theMaterial.texmap_diffuse.name = (refPlaneName + "_Diffuse")
theMaterial.texmap_diffuse.coords.blur = 0.01
theMaterial.texmap_opacity = Bitmaptexture fileName:theMap.filename
theMaterial.texmap_opacity.name = (refPlaneName + "_Opacity")
theMaterial.texmap_opacity.rgboutput = 1
theMaterial.texmap_opacity.monooutput = 1
theMaterial.texmap_opacity.coords.blur = 0.01
showTextureMap theMaterial theMaterial.texmap_diffuse on

print matName
print theMaterial

--build plane
local refPlane = plane name:refPlaneName length:theLength width:theWidth lsegs:1 wsegs:1 mapCoords:true
refplane.material = theMaterial
refplane.realWorldMapSize = off
refplane.lengthsegs = 1
refplane.widthsegs = 1

--position the plane
in coordsys (transmatrix refplane.transform.pos) refplane.rotation = (eulerangles -90 0 0)
ResetXForm refplane ; CollapseStack refplane
refplane.pivot = [(refplane.max.x+refplane.min.x)/2, refplane.min.y, refplane.min.z]
refplane.pos = [0,0,0]
)
)

jonahhawk
07-24-2008, 04:49 AM
For me this was more about building the image planes at the proportion of the bitmaps and at a specified height.

I have NodeJoe (http://www.nodejoe.com) for materials. I highly recommend this to anyone. It has boosted my creativity in building materials. It's my favorite tool by far.

CGTalk Moderation
07-24-2008, 04:49 AM
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.