Game Development Community

Free Resource for 3dsmax Users

by Ryan Mounts · 01/08/2008 (9:11 pm) · 16 comments

Here is a set of two macroscripts for 3dsmax that I'd like to share with all who might find them useful. They were developed out of a desire to create interiors directly in 3dsmax, where I could take advantage of max's advanced feature set, especially in the UV mapping department. After trying many different pipelines, each involving several conversions, I could never get my geometry into Constructor with the texture coordinates preserved. So I wrote my own script, called "Max2Ctor", to export a max scene directly to the Constructor format (.csx). The second is a helper script, called "Explode Brushes", particularly used to aid in texture baking. It allows you to attach multiple brushes into one object, bake the materials and lighting into one or more textures, and then "explode" the brushes back out before exporting while preserving the texture coordinates. I use these scripts in 3dsmax 9, but I think they should work back to version 5.

Below is an example of a simple house (included in the zip file) with global illumination baked into a single 1024x1024 texture. Since the lighting is in the texture, I checked "useGLLighting" in the World Editor Inspector after dropping the interior into Torque to disable its lightmap.

www.geocities.com/rmounts79/radiosity.jpg
As a side note, you can also use max2ctor to export spheres properly into Constructor, which could be helpful since Constructor's sphere tool is not very robust yet. Feel free to add comments or suggestions. Hope someone finds these useful!!

Max2Ctor_103.zip

#1
01/09/2008 (5:12 am)
Wow, cool!
I will try this out immediatly :D!
Sounds really helpfull, thanks.
Btw, what does the explode brush script exactly do, I don't quite understand it.
You said it aids in texture baking, but the torque engine bakes the lightning map in, when it is doing the lightning mission right?
Or is this something that bakes the lightning straight into the texture?
#2
01/09/2008 (6:18 am)
Really really cool, Do you think this will work in combination with the Game Level Builder 3 pluggin ?
#3
01/09/2008 (7:16 am)
Yeah, I just realized this morning that I shoulda explained that better. :)

Here's the workflow I used to create that house above... first I created the geometry, which is just 11 boxes ("convex brushes") just like how you'd expect to see it in Constructor. Then I converted them all to editable poly and used the "Attach" command to combine them all into one object. That is so I can bake one large texture for the whole house. Then I applied a Multi-subobject material to the house object with 7 different textures. I went in by hand and selected the house's polygons and gave them the corresponding material ID. Then in the Modifier panel, I added a Poly Select, selected the polys with a material ID of 1 and applied a UVWmap. This allows you to tile, rotate, or shift the texture, or change the mapping to planar, box, etc for just material 1. When I got that material looking right, I added another Poly Select, selected all polys with material ID 2, added a UVWmap... well, you get the idea. I just continued that process until I had all the UV's mapped the way I wanted. Now here's the trick. The very last modifier should be an UnwrapUVW with a Map Channel that's different from the UVWmap modifiers (I used a Map Channel of 2). In UnwrapUVW I selected all the polys that a player would see ingame (not the small faces between touching brushes), and in Edit mode selected Mapping > Flatten Mapping. Then I clicked Select > Select Inverted Faces and scaled these way down and moved them to a small unused portion of the texture. We don't want unseen polys using up our valuable texture realistate! Now I lit the scene the way I wanted, using V-Ray to do the GI. Mental Ray can only bake occlusion maps properly. Then I used Render To Texture with Channel 2 selected under Mapping Coordinates (the channel the UVWunwrap is using). This allowed me to bake all the texture and advanced lighting into a singe 1024x1024 texture. After baking, I created a new Standard material with my baked texture in the diffuse slot (Map Channel 2) and applied it to the house object. Whew, almost done...

Here's where those scripts come into play. I selected the house object and used "Explode Brushes" to break it back out into individual brushes, without disturbing my baked texture. Then I used "Max2Ctor" with Map Channel set to 2 to export the house to Constructor (Note: you have to load the texture into the material library in Constructor). Now just export to Dif! If you bake the lighting into the texture like this, you need to set "useGLLighting" in Torque to disable its lightmap.

Now, you don't have to use these scripts to bake advanced lighting into your textures... that's just one of the cool tricks. :) Max2Ctor is a simple standalone exporter. Simply create some objects, texture them with either Standard or Multi-subobject materials and your choice of UV mapping, maybe add some lights, and export them! This might be useful if you want to use 3dsmax's powerful tools to create your interior, like snaps, advanced array, maxscripting, Paritcle Flow, UVWunwrap, precise and easy placement/alignment, etc. Explode Brushes is used specifically for the workflow outlined above, to take advantage of advanced lighting and Render To Texture. Of course you could have just baked each object individually, but then you would have ended up with 11 textures instead of just 1, which would quickly eat up texture memory ingame for a complex interior. It's more efficient to bake a few larger textures. Hope that helps. I might try to write up a short tutorial or something later... :)
#4
01/09/2008 (7:23 am)
@ Surge

Sure, you can create your geometry any way you choose. Max2Ctor will simply export any visible geometry and omni lights. And you can do your texture mapping either in max or Constructor, whatever your preference. If you texture map in max, you have to make sure your textures are loaded in Constructor's material library for them to show up.
#5
01/09/2008 (7:30 am)
This is VERY cool!
#6
01/09/2008 (7:59 am)
Thanks Ryan - I will be putting your macroscripts to the test this week/week end. Very useful Thank-You!
#7
01/09/2008 (8:08 am)
Going to try this ASAP...THANKS!!! I thought of something like this a while ago, I just don't know MAX script;)
#8
01/10/2008 (10:53 am)
sphere export = ORGASM
you just made my newyears very happy =)
#9
01/10/2008 (2:43 pm)
download of zip file isn't working anyone know where I might be able to get this.
#10
01/10/2008 (4:30 pm)
For those of you having trouble downloading, Orion has kindly offered to host the files. Sorry for the initial trouble.
#11
01/10/2008 (8:54 pm)
There is a commercial tool, RTGroup which solves similiar problems what mentioned above to bake textures:
www.rendertotexture.com/

Cheers,
#12
01/11/2008 (1:16 pm)
Awesome!
#13
01/26/2008 (5:48 am)
It look great, thanks for the effort
#14
10/05/2008 (10:15 pm)
Extreme Awesome for max user`s;)
#15
12/07/2008 (6:34 pm)
Thanks for this plugin I'll use it, and I wish that resolve my problem with the interiors, I can't get them C ya!
#16
01/14/2009 (8:35 am)
The link doesnt work : (
could someone upload it to anohter host?
Thanks