Introduction

When I first got into 3D programming (recently), I was overwhelmed with the complexity. For one thing, coding 3D is complex in itself, but I also found the workflow from designing a model in Max, exporting, loading and rendering was difficult. I created this page to share the little I learned so far, and hope that some of the clever guys in the community can add on to help us rookies out :)

Where do I start?

Before you start modeling anything, you have to decide what units to use. In Max, there are a bunch of options for setting units. They can really create problems unless properly set and managed. If you’re trying to merge Max files with different units can get some wierd results. So to make it simple, go to “Customize | Units Setup…” and select “Generic Units”. This will create a 1:1 correspondence between the dimensions you see in Max, with the dimensions in TV3D when you load the model.

So what is a unit? That’s for you to decide. I consider 1 unit equal to 1 meter, but you can pick anything you like; inches, feet or whatever. I strongly suggest that you stick with your units definition through all your projects, so all models will have the same units base. That will make life a lot easier for you!

If you plan to use Physics in TV3D, you should use metric units (Meter) as the Physics engine is based on that.

Modeling

When you start designing a model, be aware of your polygon count. If you have too many polygons, the frame rate will drop dramatically. Spend some time to learn about low poly modeling. Here are a few general advices when working in Max:

  • Read the tutorials “Modeling a low-Poly Character” and “Mapping a character” in Max tutorials. You’ll get a good idea on the workflow for creating a character and adding textures. The tutorial will result in a full figure soldier with 1362 polygons.
  • Consider how you’ll use your model. If it will be viewed from a distance, then make the polygon count very low. If you will have close ups you might want to have a more detailed model with more polygons.
  • If you create standard objects like pipes, spheres, boxes etc, always go to the parameters rollout and reduce the number of segments (they are pretty high per default). For instance, if you create a standard sphere, Max will assign 32 segments, in effect creating 960 polygons. You probably don’t need that many. Note that the tuorial mentioned above creates a complete character with only 1362 polygons!
  • Model as little as possible, and instead use textures to define the details. For instance, if you make a human character that will be viewed from a medium to long distance, don’t model all the details. Instead, create textures to show the details (more on texturing later).
  • Don’t use mesh smooth, subdivide and similar modifiers/operations. They’ll create a huge number of polygons!
  • If you press “7” on your keyboard, Max will show the number of polygons in your scene. Always have it on!
  • Always close your models, that is, make sure each mesh (or element of a mesh) don’t have any holes. That will create problems when you add shadows in TV3D.
  • If you edit geometry on the vertex level, make sure you delete isolated vertices and unused map Verts. You’ll find two buttons on the Edit Vertices rollout that does just that. If you don’t, you can get very strange effects (and even crashes) when you load your model in TV3D (as well as other tools).
  • When you’re happy with your model, make sure you collapse the model to an Editable poly object. This will bake the texture mapping coordinates so they get properly exported. If you don’t, exports to TV3D might give strange effects.
  • There is huge amount of possible modifiers in Max. Many of these don’t work when exporting a model, however, all the basic stuff works fine. To find out if a particular modifier will play, create a simple test program with TV3D and try to export and see what happens!

Organizing your models

You basically have two options here. Either you create one Max file per model, or you build a scene with several models. There are pros and cons with both approaches.

I usually create one Max file for all the geometry that will be rendered together. For static models (i.e. TVM models), that is the simplest approach, and enables the creation of Light maps for the entire scene (more on that later).

When it comes to actors with animations (i.e. TVA actors), I keep them in separate files and then X-ref them into the scene in Max to see how they look with the environment.

Texture mapping coordinates

When your model is done, you need to assign proper texture coordinates. In Max, you can get away without it, but you have to do it before exporting. Otherwise your textures will not be displayed properly, if they show up at all.

The simple way, relevant for simple surfaces like planes and boxes, is to use the “UVW Map” modifier.

For more complex surfaces like human body parts, you’ll have to use the Unwrap UVW” modifier. It’s a tedious task to unwrap UVW’s but there are really no shortcuts here.

When you are happy with the UVW’s, you have to collapse to “Editable poly” in order to bake the UVW’s into the mesh. Note, that even after you have collapsed a mesh, you can still apply a new “Unwrap UVW” modifier and change the UVW’s. This is a great feature of Max!

Texturing your model

Before you try to load your model in TV3D, you’ll need to add textures and define materials for your model. If you read the Max tutorials mentioned above, you should have a grip on how to do this.

Understanding textures and materials

In TV3D terminology there are textures and materials. Textures refer to images like a face or a brick wall pattern. Materials refer to how light is calculated on a surface. Both are very important to get realistic rendering, so you should spend time understanding these concepts. For more information on materials, "Introduction to Materials in TV3D" by Javin. However, note that you can get all the materials automatically loaded into TV3D from your exported model!

When you texture your model, be sure to use one of the following Max material formats:

  • Standard
  • Multi/Sub-Object

Other formats will not export properly! You’ll probably find working with Multi/Sub-Object to be the best options, as that will make it very easy to assign different materials to different elements in Max.

Use the standard Blinn shader in Max, as this will give a reasonable visual similarity on how Max renders geometry versus TV3D.

When you create meshes that requires more than one material/texture, you have two choices. Either you assign the material on the Element level or you assign material on the Poly level. Both works fine and will be properly exported. Here is a brief explanation on how to assign/change material for an Element in a mesh (the procedure is exactly the same for Polygon level):

  1. Create a Multi/Sub-Object material in Max
  2. Create your sub materials and set the ID parameter to 1, 2, 3 etc, for each sub material
  3. Assign the Multi/Sub-Object material to your mesh, on the top level
  4. Enter the Element level for the mesh
  5. In the “Element Properties” rollout, select the ID corresponding to the material you wish to assign.

Something that might be confusing when you later export the model is how different elements/polygons in Max relates to mesh groups in TV3D. Here is what I think is a correct definition:

  • Each Mesh will have it’s own group(s), based on the assigned Max material. This means if you have a Max material named MyWallMaterial and assign that material to two different meshes in Max, you have two different groups with two different materials, reflecting each mesh.
  • Within an exported Max mesh, each group in TV3D corresponds to a group of Polygons that shares the same Max material.

As of now, the names of the materials will not show up when you export from Max.

Textures

Diffuse textures and light maps (more on that later) are exported. If you are using any other maps, like Bump mapping or opacity, you’ll have to load and apply those explicitly in TV3D by coding it in.

So how big should the textures be? Big textures slow down your frame rate, so you should keep them as small as possible. To figure out the size, think like this: My model will occupy no more than 10% of the screen, and I design this game for 1024×768, so the total texture seen from one side should be around 102×76 pixels, so a size of 128×128 pixels seems reasonable. If you really want fast frame rates, you drop it to 64×64.

Another question you might ask yourself is what file format to use. I strongly recommend that you use DirectX native format DDS. DDS format is extremely versatile and has features like mip mapping and alpha layer. Another advantage is that the DDS format support hardware compression. This will accelerate rendering and also shorten load times compared JPG and other formats. You can use DDS images directly in Max. Microsoft DirectX SDK (freely downloadable) includes tools to convert virtually any image format to DDS. There are also free plug-ins for Photoshop available from NVIDIA, NVIDIA Developer Tools & SDK.

Materials

As mentioned, materials define how light is calculated. In Max, you’ll find those in the Material editor as well, and they will work just fine when you export. All Materials are exported except Ambient and Opacity. You’ll have to apply ambient material explicitly in TV3D by coding it in. The soften parameter for Specular highlights are not relevant as that is something that’s only used when you render in Max.

Exporting your models

First, install the Max exporters from TV3D tools. See the TV3D documentation on how to do that.

Exporting is straightforward. The only thing to look out for is that you have to first select a name (i.e. wall.tvm) and then select the proper format (i.e. TVM) in the Export dialog. It’s possible to export in TVM format to a file named wall.x!

Loading your models in TV3D

Loading in TV3D is very simple. But before you do, you should setup proper lighting in TV3D to get your models to render similar to what you had in Max. When loading your model, you must enable managed lighting for your model:

// C# code
 
// Enable specular light. 
//
LightEngine.SetSpecularLighting(true);
 
// This code creates one directional light that reflects the one I used in Max.
// Note: if you use “Generic units” in Max, the units will map 100%
//
TV_3DVECTOR lightPos = new TV_3DVECTOR(1000, 1000, -1000);
TV_3DVECTOR lightDir = new TV_3DVECTOR(0, 0, 0) - lightPos;
MathLib.TVVec3Normalize(ref lightDir, lightDir);
 
int Light = LightEngine.CreateDirectionalLight(lightDir, 1f, 1f, 1f);
LightEngine.EnableLight(Light, true);
 
// This will enable managed lightning. If you don’t, the materials will
// not be used, only the textures will be used. I also enabled shadows here,
// but be aware, stencil shadows are costly on the frame rate!
//
LightEngine.SetLightProperties(Light, true, true, false);
 
// Define Specular light. To get similar specular light to what you see 
// in Max, you need to increase the specular light to around 2.0f.
//
LightEngine.SetLightSpecularColor(Light, 2f, 2f, 2f);
 
// Create a mesh builder and load your model. Note that the second and third
// parameter in LoadTVM() tells TV3D to load textures and materials!
//
TVMesh Mesh = Scene.CreateMeshBuilder("test");
Mesh.LoadTVM("test.tvm", true, true);
 
// In order for TV3D to use your materials and lights, you must enable
// managed ightning for your model
//
Mesh.SetLightingMode(CONST_TV_LIGHTINGMODE.TV_LIGHTING_MANAGED);
 
// Finally, if you like, enable shadows for your mesh. But be warned,
// it’s a frame rate killer!
//
Mesh.SetShadowCast(true, true);

Rendering your model in TV3D

Rendering is straightforward. You need to do nothing more than you see in other examples, except that you need to add a call to render the shadows in the render loop (if you want shadows):

TVEngine.Clear(false);
Mesh.Render();
Scene.FinalizeShadows();
TVEngine.RenderToScreen();

Light maps

TBD

Animations

TBD

Credits

* West for additions on units and DDS format. * Mith for correcting my terrible grammar. * Sylvain for making the TV Exporter working.

 
tutorialsarticlesandexamples/getting_started_with_3dsmax_and_tv3d.txt · Last modified: 2013/11/22 13:32