
Lightmaps in Director


Quicklinks
- Introduction
- How does it work?
- Advantages/disadvantages
- How to use it? (files downloadable here!)
- Finally...
Introduction go to top
Every now and then the question about lightmaps and/or multiple texture coordinates (UV sets) arises both on the dir-lists and the forums. Although Director 3D does supports models with multiple UV sets it is nowhere near as good as it should be. For example how multiple UV sets are handled in 3ds Max itself or i.e. Virtools. Adding a extra texture channel and texture in Director is absolutely no problem. It is getting and adding a correct 2nd UV set, preferably from out 3ds Max, that can be the hard part. Let’s keep hoping for a big Director 3D update with a new exporter and decent native support for multiple UV sets ;)Most developers and hobbyist soon find out that you have to work with Directors “features” and work around the missing ones. This document is a workaround for adding lightmaps fast and easy. This is by no means a “wonder” solution. It comes with some serious downsides, but it has been a solution that has always worked for us, without any problems and great end results.
This “solution” is based upon a 3ds Max (8) script. It is not very complex and the theory behind could possibly be converted to other 3d packages as well.
How does it work? go to top
This part might be a bit technical and/or boring. If you want you can just skip ahead.First of all, you can just model, unwrap and texture everything in 3ds Max as you usually do. You can add a second UV set and create your lightmaps with 3ds Max as well. I will not go into details about this, check the manual or some online tutorials on the subject. The script is actually just a macro recording of something that can be done manually as well. Although that can be a lot of work.
When you run the script all models will be triangulated. All vertices will be broken (each vertex will be broken into 3 new ones). This is only done to models with more than 1 UV channel. The 3ds Max export dialog will show up for the first time. You’ll export your file to a .w3d like you normally do. After this is done the script will copy the UV set of the second channel to the first one. Models with only one channel will be hidden. The 3ds Max export dialog will show up for a second time. Export to a .w3d file as normal. You can turn off a lot of features, because this file will only be used to retrieve the texture coordinates for the second channel. The hidden models will show up as groups in the .w3d file, but this is no problem. After the export you’re done in 3ds Max. Your model/world will probably look distorted so it might be a good idea to save before you export. I removed the auto undo from the script because it was a bit buggy initially.
You can save the “distorted” file, after exporting, for future exports of the second channel. No guarantees though, I had some troubles with this in the past. It almost seemed that 3ds Max had a different way of exporting models (vertex ID’s and positions) with each instance it was running. That is why this “double” exporting in a single click was made for originally.
There is one last thing I’d like to add. Obviously, some of you will now ask yourself the following question. “Why not only break the vertices that are needed to be broken? You’ll save yourself an unnecessary large data set of vertices. Which is slower etcetera etc.” Although I intentionally wanted to do this I soon found out that in most cases I would end up with all vertices broken anyway. Just because of the way you normally unwrap and texture your model. First channel tilling and the second channel an optimised unwrap with as least seams as possible. Furthermore, I noticed some odd export results in some circumstances with other techniques (i.e. breaking only necessary vertices using the unwrap UVW modifier). For example, a standard triangulated teapot has 1024 faces. When all vertices are broken it should have 3072 (1024 x 3) vertices. When the vertices were broken in the unwrap I ended up with more vertices (over 3100) in Director. This bothered me a bit and as you can understand for this technique to work the amount of vertices need to be exactly the same in both files. I couldn’t get this right with any other method. That is why the “breaking” is done. It’ll create a “correct” amount of vertices in all cases.
Advantages/Disadvantages go to top
Like I mentioned before there are some downsides when using this script or “solution”.Let me first start of by mentioning the advantages so you won’t get scared ;)
Advantages
- Lightmaps!
- You can use 3ds Max and all it’s features to create the lightmaps (i.e. use an optimized unwrap for your 2nd channel, GI, color bleeding, etc.)
- Fast to initialize and use in Director. No need for advanced scripting.
- You can use this method to add even more different UV sets for other channels as well.
Disadvantages
- No more shading. This is unfortunately a big downside. When breaking the vertices all smoothing will be lost and the model will appear “flat” shaded (it actually isn’t, because smoothing groups are still intact). It can’t seem to be fixed by using 3ds Max when for example using the “edit normals” modifier. These modifier settings (even when the model is collapsed) just seem to be reset or ignored upon exporting. I do think that you can average or re-set the normals in Director. Initial test have shown some decent results here. We don’t think this issue might be a very big problem because most of the time a lightmapped model has full emissive or the texturemode for the first channel set to “replace” in project anyways. Do set the shader to “flat” shaded. It’ll same you some processing power. We might look in other solutions for this and hopefully the script can be adjusted to fix this automatically.
- Obviously, complex models can get reasonable large vertex lists and additional data.
- The script only works on “editable mesh” or “editable poly” models. It’ll crash on any other models, like primitives.
How to use it? go to top
Files to download:
- The script – XformLightmapper.rar
- The 3d source files – SourceFiles3D.rar
- The director source file – SourceFilesDirector.rar
Ok, now how do you use it? I’ve already talked a lot so I’ll try to make this as short as possible. It is not very difficult anyway.
Installing the script.
- Download the XformLightmapper.rar.
- Copy the XformLightmapper.mcr to ../3dsmax8/ui/macroscripts where ../3dsmax8 is your Max folder
- Copy the icon files (4 .bmp files) to ../ui/icons.
- (Re)Start Max. Go to “Customize” then “Customize User Interface…”
- Click the “Toolbar” tab. You can find the script under “Category” rollout -> “Xform Tools”
- If you already have a toolbar somewhere you can simple drag and drop the script (Xform Lightmapper v0.9) on your toolbar. A button will be created. If you don’t have a toolbar anywhere create a new one by clicking the “New” button in the top-middle/right. Give it a name, click “Ok”, then drag and drop the script on your newly created toolbar.
- That’s it. Ready to be used…
Preparing and exporting your 3d model or 3d world.
- Model and texture everything like you normally do. Add a second channel, bake lightmap, etc. You can find a lot of good tutorials and tips in the manual and in online tutorials. If you just want to give it a test run you can download some source files: SourceFiles3D.rar
- You don’t need 3ds Max to create new materials for your texture and lightmap when texturebaking! When using the “render to texture” function in max tick the “Render to files only” box! Just make sure that when you export each model has a standard shader… or no shader at all if you wish to add them in Director yourself.
- Before exporting check if you don’t have any other models than “mesh” or “poly”. Small tip: the script will triangulat your model. Keep this in mind and only model in “triangles” or “quads”, otherwise you can get unpredictable results because of polygons created with 5 vertices or more.
- Click the button on your (new) toolbar. Save your files. Name the first one i.e. Scene.w3d and the second Scene_Lightmap.w3d. Give the files a least a recognizable name so you’ll know which one to use to retrieve the texture coordinates.
Initializing and assigning the lightmaps.
- I am not spelling out all the code to write ;) Simply download SourceFilesDirector.rar, open Lightmaps.dir and give it a quick glance.
- As you can see the amount of code to initialize and assign it is very small. Study it a bit. It is not very complicated at all. In this example the texture coordinates are retrieved from the Scene_Lightmap.w3d member each time the movie is run. Better is it to retrieve those once and put them in a textmember. You won’t be needing the .w3d anymore and it’s faster to use. But I’ll let you figure out how to do that yourself ;)
- Done!
It doesn’t work/I get errors/Other stuff.
- The maxscript is the first serious one I ever wrote. Don’t laugh! it’s very simplistic and can be buggy. If you get an error when exporting just close the script window. You’ll probable have a non “mesh” or “poly” model. For example a “plane” primitive.
- In Director: Be sure to turn off all (auto)lod of your models in both files! If you don’t do so the vertexcount won’t match up and the end result will be “unpredictable”.
- Don't change names after you've exported your scene/world. The names are used for getting and setting the texture coordinates on the second channel in this example. Feel free to rewrite or add your own code.
Finally… go to top
So, finally at the end... I did write a lot more than I intended, but I’ll hope it’ll make the use of this “solution” clear. We do hope that people will have use for this method to create great looking 3d worlds and models in Director. Drop us a line if you do so! If some of you think we should add or correct something to this document. Probably a bug, error or some other vital information for the use of the script/method, don’t hesitate to contact me!
Good luck and have fun!