Difference between revisions of "MD2"

From 3DGE Wiki
Jump to: navigation, search
(Limitations: Changed, since we have a lighting system that affects models now.)
m (Features: MD2 clarifications)
 
Line 22: Line 22:
 
Both ports can utilize MD2, but there are a few key additions that become helpful, as the engine supports higher-resolution/color textures,  
 
Both ports can utilize MD2, but there are a few key additions that become helpful, as the engine supports higher-resolution/color textures,  
 
==Features==
 
==Features==
EDGE, and by extension, 3DGE, can load MD2s from either a LUMP in the wadfile, or externally as a plain file. While Quake 2 imposes harsh limits on the format, 3DGE enhances it beyond what was normally capable:
+
[[EDGE]], and by extension, 3DGE, can load MD2s from either a LUMP in the wadfile, or externally as a plain file. While Quake 2 imposes harsh limits on the format, 3DGE enhances it beyond what was normally capable:
  
 
* Ability to use PNG, JPG, and TGA file formats for skins (original PCX is not supported)
 
* Ability to use PNG, JPG, and TGA file formats for skins (original PCX is not supported)
Line 32: Line 32:
 
While those features are handy, there are currently limitations of the format:
 
While those features are handy, there are currently limitations of the format:
  
* No linear interpolation, so the "jelly-like" vertex animation carries over from Quake 2
+
* No linear interpolation implementation, so the "jelly-like" vertex animation carries over from Quake 2
  
 
==Explanation==
 
==Explanation==
Line 39: Line 39:
  
 
Examples:
 
Examples:
<TABLE WIDTH=95% BORDER=1 CELLSPACING=0 CELLPADDING=3 FRAME="box" BGCOLOR="#C2D6D6" >
+
<TABLE width="95%" border="1" cellspacing="0" cellpadding="3" frame="box" bgcolor="#C2D6D6">
 
<TR><TD>
 
<TR><TD>
<FONT SIZE=2>
+
<FONT size="2">
 
STATES(IDLE)=TROO:@5:7:NORMAL:NOTHING;  // the 5th frame
 
STATES(IDLE)=TROO:@5:7:NORMAL:NOTHING;  // the 5th frame
  
Line 61: Line 61:
  
 
===THINGS.DDF===
 
===THINGS.DDF===
{| border="1" cellpadding="2" BGCOLOR="#C8F4FF"
+
{| border="1" cellpadding="2" bgcolor="#C8F4FF"
 
! COMMAND
 
! COMMAND
 
! EXPLANATION
 
! EXPLANATION
Line 74: Line 74:
 
| add this to every z coordinate: MODEL_BIAS=24.0; Useful if you don't want to position from Quake 2's original 24 units in an external editor.
 
| add this to every z coordinate: MODEL_BIAS=24.0; Useful if you don't want to position from Quake 2's original 24 units in an external editor.
 
|}
 
|}
 
  
 
===WEAPONS.DDF===
 
===WEAPONS.DDF===
  
{| border="1" cellpadding="2" BGCOLOR="#C8F4FF"
+
{| border="1" cellpadding="2" bgcolor="#C8F4FF"
 
! COMMAND
 
! COMMAND
 
! EXPLANATION
 
! EXPLANATION

Latest revision as of 11:54, 31 August 2017

The MD2 model file format was introduced by id Software when releasing Quake 2 in November 1997. It's a file format quite simple to use and understand. MD2 models' characteristics are these:

  • Model's geometric data (triangles);
  • Frame-by-frame animations;
  • Structured data for drawing the model using GL_TRIANGLE_FAN and GL_TRIANGLE_STRIP primitives (called “OpenGL commands”).
  • Model's texture is in a separate file. One MD2 model can have only one texture at the same time.

MD2 model file's extension is “md2”. A MD2 file is a binary file divided in two part: the header dans the data. The header contains all information needed to use and manipulate the data.

Constants

Here are some constant values defining maximal dimensions, so do not exceed these amounts, or 3DGE will fail to render the model:

  • Maximum number of triangles: 4096
  • Maximum number of vertices: 2048
  • Maximum number of texture coordinates: 2048
  • Maximum number of frames: 512
  • Maximum number of skins: 32
  • Number of precalculated normal vectors: 162

Use in 3DGE

Both ports can utilize MD2, but there are a few key additions that become helpful, as the engine supports higher-resolution/color textures,

Features

EDGE, and by extension, 3DGE, can load MD2s from either a LUMP in the wadfile, or externally as a plain file. While Quake 2 imposes harsh limits on the format, 3DGE enhances it beyond what was normally capable:

  • Ability to use PNG, JPG, and TGA file formats for skins (original PCX is not supported)
  • Able to define up to 9 skins-per-model and switch them out on-the-fly through DDF
  • Able to use animations as either frame number or reference name, or both if desired
  • Can control the bias, aspect, scale, and placement of the model, both for environment and HUD (weapons)

Limitations

While those features are handy, there are currently limitations of the format:

  • No linear interpolation implementation, so the "jelly-like" vertex animation carries over from Quake 2

Explanation

Model

Any state frame can specify a model by using the special '@123' or '@framename' syntax for the frame (instead of a letter). The number is the absolute frame number in the MD2 model, beginning at 1, or you can use the frame name.

Examples:

STATES(IDLE)=TROO:@5:7:NORMAL:NOTHING; // the 5th frame

STATES(IDLE)=TROO:@run3:7:NORMAL:NOTHING; // frame called "run3"

The model itself must be stored in a wad, and the lump name is the sprite base ("TROO") plus "MD2" on the end --> "TROOMD2".

Skins

The skin of the model is the sprite base ("TROO") plus "SKN1" on the end --> "TROOSKN1". There should be a definition for it in IMAGES.DDF using the sprite namespace --> [spr:TROOSKN1].

Normal and specular maps can be applied to skins. The normal/spec map name id the sprite base ("TROO") plus "NRM" or "SPC" respectively on the end --> "TROONRM1" / "TROOSPC1".

Other skins can be used. The command "MODEL_SKIN=3" in a thing or weapon definition will use the third skin --> "TROOSKN3". Up to nine skins can currently be used (1 to 9). The skin can also be changed dynamically by using the SET_SKIN(##) action in the state frames.

USAGE

Below describes the commands needed to manipulate and use the models in the game engine via DDF:

THINGS.DDF

COMMAND EXPLANATION
MODEL_SCALE Draw the model bigger, for example: MODEL_SCALE=1.5;
MODEL_ASPECT make the model fatter/skinnier: MODEL_ASPECT=0.7;
MODEL_BIAS add this to every z coordinate: MODEL_BIAS=24.0; Useful if you don't want to position from Quake 2's original 24 units in an external editor.

WEAPONS.DDF

COMMAND EXPLANATION
MODEL_ASPECT make the weapon fatter/skinnier
MODEL_BIAS add this to every z coordinate
MODEL_FORWARD move the weapon forward/backward: MODEL_FORWARD=2.2;
MODEL_SIDE move the weapon right/left: MODEL_SIDE=-3.5;
Note: there is no MODEL_SCALE command for WEAPONS.DDF (scaling has no effect because the model is drawn at the camera point). Changing MODEL_FORWARD, MODEL_SIDE and/or MODEL_BIAS can have a huge impact on the apparent size of the weapon.

Also see MD3 and MD5.