Header Sep

Java Tips, Tricks & Code

My Rating Score
Login to rate page

March 2005

Compliments of Digital Chocolate: 3D modeling tips

Below you will find a number of 3D modeling tips related to scaling in exporters, the use of skins, textures and vertex colors as well as object reuse, object location and setting UID's.

Modeling
A common problem in all exporters is which scale to choose for the model. All exporters seem to have different ways of handling how one unit in 3Dsmax corresponds to one unit in the game. The HI Corp Mascot exporter and Discreet M3G exporters snap all vertices to one 3Dsmax unit (i.e. 3.2f -> 3.0f).

Tips: Remember to always retain the unit scale of 3Dsmax as generic units. The scale of the models will be the same as one 3Dsmax unit (some exporters scale the model down by 100). In Mascot, one unit 3Dsmax will correspond to the value 1 (not fixed point one which is 4096). This means that the models will be very large from a 3Dsmax perspective. Due to Mascot fixed point math and 16-bit limitations, we have to keep all vertices within the -32000 +32000 range.

Skin
When using bones and skin you have to snap vertex weights to 0.0f or 1.0f. To ensure this, you can do the following:

  • Select skin, envelope.
  • Check "vertices".
  • Select all vertices (with the move tool).
  • Go down to "Weight properties" and check "Rigid".

Common notes

  • Remember to weld the vertices.
  • Collapse the stacks before exporting (not the skin modifier).
  • Make backups.


JSR-184 specific tips

Transforms
One of the main problems with JSR-184 is the scaling of nodes. Many artists like to use the scale tool to scale objects. However, the scale will not be applied to the object vertices. Instead, 3Dsmax applies scaling to the transform matrix of the mesh. This means that if you scale the object 10x and then export it, the mesh vertices will still be 1x and the scale will be applied to the transform matrix. When we add rotation and translation to the object, we'll get scenes that look ok in 3Dsmax, but will be messed up in the game.

The solution is to not use the scale tool on meshes. Instead, vertices should be scaled directly. If scaling is used for the meshes, the "Reset XForm" tool in 3Dsmax (found in the "Utilities tab") should be used. "Reset Xform" will set the rotation/translation matrix to unit matrix and "freeze" the vertices to their current position. Extra care should be taken when it's used because it will reset the scale, as well as the rotation of the node, and the vertices of the mesh will be rotated to world coordinates and the node transform is set to 0 degrees.

Also, remember to keep the modifier stack short and collapse it before exporting. Some modifiers may hold materials inside and this usually creates multi-materials, which as you may have guessed, won't be visible in 3Dsmax - but will mess up in the game.

UIDs
The meshes are found in the .m3g file with the find (int uid) method. The UIDs for the meshes can be set with the export tool or they can be generated automatically and retrieved by parsing the log file that the exporter uses. Setting UIDs in the export tool is a bit cumbersome, as at the moment the UIDs aren't saved between exports (a bug report has been sent to the developer). The best current solution is to rely on the object names in 3Dsmax, parse the log file and write a UID table for the game.

Object reuse
Generally, some sort of naming scheme in the 3Dsmax should be used. For example, "game_mesh" and "game_mesh01" can be identical meshes and inside the game it's natural to reuse the mesh to save space. Use a maxscript to remove duplicate meshes and only export the transform for the copies (in this case, we need to replace the original mesh with a small dummy mesh). Then generate a separate table for reuse that's based on the naming scheme.

Object location
The positions of the objects are exported to the .m3g file. Transform nodes can be retrieved in the following way:
myMesh.getTransformTo(theWorld, newTransform);

Textures
All textures in JSR-184 must be of the size 2^n x 2^n (e.g. 32x32, 128x64). Recommended maximum size is 256 x 256 (256 x 256 texture is usually the uppermost limit when it comes to heap memory). If textures have different properties, such as alpha channel (transparency), we should use different textures for each mode.

The UV coordinates have to be inside the range [0.0, 1.0f] in 3Dsmax (this is the blue square around the texture in UV-unwrap in the below image). If they're not inside this range, the Discreet exporter will generate a warning. The "tile bitmap" option in 3dsmax should always be turned off, as this prevents a user from accidentally dragging the UV coordinates out of the desired range.
 

Vertex Colors
To add pre-calculated lightning to a scene in 3Dsmax using vertex colors, do the following:
  • Set "Render/Environment/Global Lightning/Ambient" to black (default mode).
  • Add lights to the scene.
  • Select your meshes. Use the "Assign Vertex Colors" tool that is found in "Utilities tab/More". Select "Shaded" and press "Assign to Selected".
  • Remove the light from the scene.
  • Collapse the meshes.
  • Set "Render/Environment/Global Lightning/Ambient" to bright white.
  • Open the properties of the meshes by right-clicking on the mesh. Enable "Vertex Channel Display".
  • Export.
My Rating Score
Login to rate page