MaxScript Render To Texture with Projection
This is a blog post written from utter frustration. I’ve spent way too much time trying to get RTT in max working with projection, and finally found the issue that was stopping everything.
The problem is that I kept getting useless bake results: a (red) wireframe, and not a proper bake!
I’d checked the help dozens of times, trawled all the forums,etc… Nothing helped.
Now after rebuilding the code again, I found the issue:
the INodeBakeProperties have almost nothing in the way of proper default settings. You have to explicitly set a few things, if you don’t, it doesn’t work without any explanation why.
Take the following sample code:
--set up bake properties
bp = obj.INodeBakeProperties
bp.bakeEnabled = true
bp.bakeChannel = 1
bp.nDilations = 1
This is the key piece of code. If you don’t set bakeEnabled, it won’t bake. Easily overlooked. Bakechannel I’m not sure of the default, but you most probably need to set this explicitely. nDilations was my problem: this is the “edge padding” value: not explicitely setting it results in useless bakes! There is not a single warning on this in the Max help anywhere!
bp.removeAllBakeElements() --clear all to be safe and clean
dbe = DiffuseMap()
dbe.enabled = true
dbe.outputSzX = 128
dbe.outputSzY = 128
dbe.filenameUnique = false
dbe.elementname = "test"
dbe.filename = "C:\\"
dbe.filetype = "test.tga"
For completion’s sake, here’s the rest of the essential code. The Bake elements have VERY generic class names such as “DiffuseMap”. They have to be enabled explicitely again.
The filename and filetype properties of the bake element are again very important: failure to set these and your bake element will not be able to create a bitmap. You’ll get a non-descriptive “Error Creating Bitmap” message. It doesn’t actually save them to that location though…
Also, very important to note: Edgepadding, or the ndilations value, is not applied when you set just “.tga” as filetype. If you set “filename.tga” it will apply them. The actual purpose of filetype vs filename is very vague and unclear.
Hopefully that will help out anyone who’s running into this same issue!
Leave a ReplyWant to join the discussion?
Feel free to contribute!