Friday, February 10, 2006

Surface namespaces in LightWave

Okay, I've been doing some experimenting with textures when going from Lightwave to Shockwave3D, and here are some things I've discovered and some recommendations for avoiding trouble.

It involves name spaces for UV Maps and Textures.

When you export Shockwave3D to Lightwave, it collapses all surfaces with the same name into a single surface. Thus, if we have two objects in a scene that have surfaces with the same name, those surfaces will be forced to look the same. This is good, because it means that no matter how many times we use a texture, it only needs to be put into the Shockwave3D file once.

The down side, though, is if we have conflicting surface names. If you create a model with a surface name of "floor" that is red and I make another one named "floor" that is blue, then when we put them into the same scene, they will both look blue (or red, depending on the order they were loaded in) because there can be only one "floor" surface.

Furthermore, even if you want two models to use the same image, you can't have more than one UV map name for a surface, because the surface in Lightwave can only have a single UV Map name. So if you import two models with the same surface name that use different UV map names, the UV map on one of the models is going to go all screwy.

For this reason, we're adopting the following conventions to avoid trouble:
  • First, we're making sure our texture images have unique names across all of us by using namespaces. We prefix all our textures with a descriptor (like a tileset name), so that we have "sandstone_floor.png" and "graystone_floor.png" instead of just "floor.png".
  • Second, we're reusing texture files where possible. This will help save on final file size and texture memory. The key is to think ahead to the different ways textures might be used and separate textures that are able to be generically used from specific use textures. For instance, wood paneling might deserve its own texture, since it can be repeated over and over again to cover a large wood-paneled area, even though it could be included as part of a "pirate ship" texture.
  • Third, the surface name equals the file name minus extension. For instance, if the texture image is "wood_panels.png", then the surface name would be "wood_panels". All textures that use the "wood_panels.png" file would have this texture name.
  • Fourth, the UV Map is the same name as the surface. All objects that use the "wood_panels" texture will use a UV Map named "wood_panels" so that multiple objects can define their UV mapping.
  • And finally, because of the above two items, all surfaces that use textures will just use UV Maps. You can mimic the mapping effects like "spherical" and "cylindrical" by selecting these when you create UV maps for your points, so we shouldn't ever need to NOT use UV maps.
You can rename surfaces using the Surface Editor. Choose the surface you want to rename from the surface listing, and click "Rename" at the top of the dialogue.

You can rename maps by going to the "Map" tab, selecting the map you want to rename clicking the "T" in the lower right corner and selecting the UV Map name from the popup there, and then going to the "Edit Maps..." menu to select "Rename map...".

No comments: