Contents User Forum Source Index APIs by Task APIs by Level Data


G3D::MD2Model Class Reference

Quake II model class. More...

#include <MD2Model.h>

Inherits G3D::ReferenceCountedObject.

List of all members.

Public Types

enum  Animation {
  JUMP_UP = -6, CROUCH_WALK_BACKWARD = -13, RUN_BACKWARD = -1, STAND = 0,
  RUN = 1, ATTACK = 2, PAIN_A = 3, PAIN_B = 4,
  PAIN_C = 5, JUMP_DOWN = 6, FLIP = 7, SALUTE = 8,
  FALLBACK = 9, WAVE = 10, POINT = 11, CROUCH_STAND = 12,
  CROUCH_WALK = 13, CROUCH_ATTACK = 14, CROUCH_PAIN = 15, CROUCH_DEATH = 16,
  DEATH_FALLBACK = 17, DEATH_FALLFORWARD = 18, DEATH_FALLBACKSLOW = 19, JUMP = 20,
  MAX_ANIMATIONS = 21
}

Public Member Functions

void debugRenderWireframe (RenderDevice *renderDevice, const Pose &pose)
const Array< MeshAlg::Edge > & edges () const
const Array< MeshAlg::Face > & faces () const
virtual size_t mainMemorySize () const
std::string name () const
const BoxobjectSpaceBoundingBox () const
const SphereobjectSpaceBoundingSphere () const
PosedModel::Ref pose (const CoordinateFrame &cframe, const Pose &pose, const GMaterial &mat)
PosedModel::Ref pose (const CoordinateFrame &cframe, const Pose &pose)
void ReferenceCountedObject_zeroWeakPointers ()
virtual void setName (const std::string &n)
const Array< Vector2 > & texCoordArray () const
const Array< std::string > & textureFilenames () const
const Array< MeshAlg::Vertex > & vertices () const
const Array< MeshAlg::Edge > & weldedEdges () const
const Array< MeshAlg::Face > & weldedFaces () const
const Array< MeshAlg::Vertex > & weldedVertices () const
virtual ~MD2Model ()

Static Public Member Functions

static bool animationAttack (Animation a)
static bool animationCrouch (Animation a)
static bool animationDeath (Animation a)
static bool animationInterruptible (Animation a)
static bool animationJump (Animation a)
static GameTime animationLength (Animation a)
static bool animationLoops (Animation a)
static bool animationPain (Animation A)
static bool animationRun (Animation a)
static bool animationRunBackward (Animation a)
static bool animationRunForward (Animation a)
static bool animationStand (Animation a)
static MD2ModelRef G3D_DEPRECATED create (const std::string &filename, float scale=1.0f)
static MD2ModelRef fromFile (const std::string &filename, float scale=1.0f)
static int getFrameNumber (const Pose &pose)
static Texture::Ref textureFromFile (const std::string &filename)

Public Attributes

AtomicInt32 ReferenceCountedObject_refCount
_WeakPtrLinkedListReferenceCountedObject_weakPointer

Static Public Attributes

static const GameTime PRE_BLEND_TIME

Protected Types

enum  { NUM_VAR_AREAS = 10, NONE_ALLOCATED = -1 }

Protected Member Functions

void allocateVertexArrays (RenderDevice *renderDevice)
void computeTexCoords (const Array< Vector2int16 > &inCoords)
void getGeometry (const Pose &pose, MeshAlg::Geometry &geometry) const
void load (const std::string &filename, float scale)
void loadTextureFilenames (BinaryInput &b, int num, int offset)
 MD2Model ()
void render (RenderDevice *renderDevice, const Pose &pose)
virtual void reset ()
void sendGeometry (RenderDevice *rd, const Pose &pose) const

Static Protected Member Functions

static void computeFrameNumbers (const MD2Model::Pose &pose, int &kf0, int &kf1, double &alpha)
static void setNormalTable ()

Protected Attributes

std::string _name
Array< Vector2_texCoordArray
Array< std::string > _textureFilenames
Box animationBoundingBox [MAX_ANIMATIONS]
Sphere animationBoundingSphere [MAX_ANIMATIONS]
Box boundingBox
Sphere boundingSphere
Array< MeshAlg::EdgeedgeArray
Array< MeshAlg::FacefaceArray
Array< Vector3faceNormalArray
Array< int > indexArray
Array< PackedGeometrykeyFrame
int numBoundaryEdges
int numWeldedBoundaryEdges
Array< PrimitiveprimitiveArray
Vector2 texCoordScale
Array< MeshAlg::VertexvertexArray
Array< MeshAlg::EdgeweldedEdgeArray
Array< MeshAlg::FaceweldedFaceArray
Array< MeshAlg::VertexweldedVertexArray

Static Protected Attributes

static const MD2AnimInfo animationTable [MAX_ANIMATIONS]
static const double hangTimePct
static MeshAlg::Geometry interpolatedFrame
static MD2ModelinterpolatedModel
static Pose interpolatedPose
static int nextVarArea
static Vector3 normalTable [162]
static VARAreaRef varArea [NUM_VAR_AREAS]

Friends

class PosedMD2Model

Classes

class  MD2AnimInfo
class  PackedGeometry
class  Pose
class  PosedMD2Model
class  Primitive
 One RenderDevice primitive. More...


Detailed Description

Quake II model class.

See demos/MD2Model for an example of how to use this class.

Models are centered about their waist. To figure out where the feet are you might want to look at the bounding box for the stand/walk animations.

When available, this class uses SSE instructions for fast vertex blending. This cuts the time for getGeometry by a factor of 2.

This class is not threadsafe; you cannot even call methods on two different instances on different threads.

The posed model supplies texture coordinates and normals when rendering but the caller must bind a texture, set the object to world matrix, and set up lighting.

If VAR has been initialized for the renderDevice, the first time this is called (for any Model) a 512k VAR area is allocated. This memory is shared between all MD2 models.

Really huge MD2 models will not fit into this small VAR area and will revert to non-VAR rendering.

When getting geometry from the posed model, the normalArray values are interpolated and may have slightly less than unit length.


Member Enumeration Documentation

anonymous enum [protected]

Enumerator:
NUM_VAR_AREAS 
NONE_ALLOCATED 

These names are (mostly) from Quake II.

FLIP, SALUTE, FALLBACK, WAVE, and POINT are all taunts. A negative number means to run the specified animation backwards. The JUMP animation is Quake's jump animation backwards followed by the same animation forwards.

Enumerator:
JUMP_UP 
CROUCH_WALK_BACKWARD 
RUN_BACKWARD 
STAND 
RUN 
ATTACK 
PAIN_A 
PAIN_B 
PAIN_C 
JUMP_DOWN 
FLIP 
SALUTE 
FALLBACK 
WAVE 
POINT 
CROUCH_STAND 
CROUCH_WALK 
CROUCH_ATTACK 
CROUCH_PAIN 
CROUCH_DEATH 
DEATH_FALLBACK 
DEATH_FALLFORWARD 
DEATH_FALLBACKSLOW 
JUMP 
MAX_ANIMATIONS 


Constructor & Destructor Documentation

G3D::MD2Model::MD2Model (  )  [inline, protected]

Called from create.

virtual G3D::MD2Model::~MD2Model (  )  [inline, virtual]


Member Function Documentation

void G3D::MD2Model::allocateVertexArrays ( RenderDevice renderDevice  )  [protected]

Called from render() to create the vertex arrays.

Assumes VAR is available and the arrays are not initialized.

static bool G3D::MD2Model::animationAttack ( Animation  a  )  [static]

static bool G3D::MD2Model::animationCrouch ( Animation  a  )  [static]

Returns true for the crouching set of animations.

static bool G3D::MD2Model::animationDeath ( Animation  a  )  [static]

Returns true for the death animations.

static bool G3D::MD2Model::animationInterruptible ( Animation  a  )  [static]

True for actions that can be interrupted, like running or saluting.

Jumping (which is really more of a falling animation) is considered interruptible.

static bool G3D::MD2Model::animationJump ( Animation  a  )  [static]

static GameTime G3D::MD2Model::animationLength ( Animation  a  )  [static]

Returns the total time of the animation.

If the animation loops (e.g. walking) this is the time from the first frame until that frame repeats. If the animation does not loop (e.g. death) this is the time from the first frame until the last frame.

static bool G3D::MD2Model::animationLoops ( Animation  a  )  [static]

Returns true for standing, running, crouching, and crouch walking animations.

static bool G3D::MD2Model::animationPain ( Animation  A  )  [static]

static bool G3D::MD2Model::animationRun ( Animation  a  )  [static]

running, forward or backward, standing or crouching

static bool G3D::MD2Model::animationRunBackward ( Animation  a  )  [static]

static bool G3D::MD2Model::animationRunForward ( Animation  a  )  [static]

static bool G3D::MD2Model::animationStand ( Animation  a  )  [static]

STAND or CROUCH_STAND.

static void G3D::MD2Model::computeFrameNumbers ( const MD2Model::Pose pose,
int &  kf0,
int &  kf1,
double &  alpha 
) [static, protected]

Computes the previous and next frame indices and how far we are between them.

void G3D::MD2Model::computeTexCoords ( const Array< Vector2int16 > &  inCoords  )  [protected]

MD2 Models are stored with separate indices into texture coordinate and vertex arrays.

This means that some vertices must be duplicated in order to render with a single OpenGL-style vertex array.

Creates a texCoordArray to parallel the vertex and normal arrays, duplicating vertices in the keyframes as needed. Called from load().

Parameters:
inCoords Texture coords corresponding to the index array

static MD2ModelRef G3D_DEPRECATED G3D::MD2Model::create ( const std::string &  filename,
float  scale = 1.0f 
) [inline, static]

void G3D::MD2Model::debugRenderWireframe ( RenderDevice renderDevice,
const Pose pose 
)

Render the wireframe mesh.

const Array<MeshAlg::Edge>& G3D::MD2Model::edges (  )  const

const Array<MeshAlg::Face>& G3D::MD2Model::faces (  )  const

static MD2ModelRef G3D::MD2Model::fromFile ( const std::string &  filename,
float  scale = 1.0f 
) [static]

The tris.md2 file.

Note that most MD2 files are stored in two files, tris.md2 and weapon.md2. You will have to load both as separate models.

Parameters:
scale Optional scale factor to apply while loading.

static int G3D::MD2Model::getFrameNumber ( const Pose pose  )  [static]

Returns a value for MD2Model::Pose::preFrameNumber that will smoothly blend from this animation to the next one.

void G3D::MD2Model::getGeometry ( const Pose pose,
MeshAlg::Geometry geometry 
) const [protected]

Fills the geometry out from the pose.

Called from PosedMD2Model::getGeometry

void G3D::MD2Model::load ( const std::string &  filename,
float  scale 
) [protected]

Called from create.

void G3D::MD2Model::loadTextureFilenames ( BinaryInput b,
int  num,
int  offset 
) [protected]

virtual size_t G3D::MD2Model::mainMemorySize (  )  const [virtual]

Returns the approximate amount of main memory, not counting the texture, occupied by this data structure.

std::string G3D::MD2Model::name (  )  const [inline]

const Box& G3D::MD2Model::objectSpaceBoundingBox (  )  const [inline]

An oriented bounding box on the model.

Covers all vertices in all animations.

const Sphere& G3D::MD2Model::objectSpaceBoundingSphere (  )  const [inline]

A bounding sphere on the model.

Covers all vertices in all animations.

PosedModel::Ref G3D::MD2Model::pose ( const CoordinateFrame cframe,
const Pose pose,
const GMaterial mat 
)

You can also pose a model without a material.

A good example of why this is useful is the MD2Model_Demo, in which shadows are rendered by flattening a pose of the model. The shadow should not be textured!

PosedModel::Ref G3D::MD2Model::pose ( const CoordinateFrame cframe,
const Pose pose 
)

void G3D::ReferenceCountedObject::ReferenceCountedObject_zeroWeakPointers (  )  [inline, inherited]

Automatically called immediately before the object is deleted.

This is not called from the destructor because it needs to be invoked before the subclass destructor.

void G3D::MD2Model::render ( RenderDevice renderDevice,
const Pose pose 
) [protected]

Called from PosedMD2Model::render.

virtual void G3D::MD2Model::reset (  )  [protected, virtual]

Wipe all data structures.

Called from load.

void G3D::MD2Model::sendGeometry ( RenderDevice rd,
const Pose pose 
) const [protected]

virtual void G3D::MD2Model::setName ( const std::string &  n  )  [inline, virtual]

static void G3D::MD2Model::setNormalTable (  )  [static, protected]

Loads data into the normalTable.

const Array<Vector2>& G3D::MD2Model::texCoordArray (  )  const [inline]

const Array<std::string>& G3D::MD2Model::textureFilenames (  )  const [inline]

Filenames of textures this model can use.

static Texture::Ref G3D::MD2Model::textureFromFile ( const std::string &  filename  )  [static]

Loads a Quake2 character texture.

Same as:

     Texture::Settings settings;
     settings.wrapMode = Texture::CLAMP;

     Texture::PreProcess preprocess;
     preprocess.brighten = 2.0f;

     Texture::fromFile(filename, TextureFormat::AUTO, Texture::DIM_2D, settings, preprocess)
     

const Array<MeshAlg::Vertex>& G3D::MD2Model::vertices (  )  const

You must get the geometry for the vertex positions-- this only specifies adjacency.

const Array<MeshAlg::Edge>& G3D::MD2Model::weldedEdges (  )  const

const Array<MeshAlg::Face>& G3D::MD2Model::weldedFaces (  )  const

const Array<MeshAlg::Vertex>& G3D::MD2Model::weldedVertices (  )  const


Friends And Related Function Documentation

friend class PosedMD2Model [friend]


Member Data Documentation

std::string G3D::MD2Model::_name [protected]

Texture array that parallels vertex and normal arrays.

Set up by computeTexCoords

Array<std::string> G3D::MD2Model::_textureFilenames [protected]

Box G3D::MD2Model::animationBoundingBox[MAX_ANIMATIONS] [protected]

Sphere G3D::MD2Model::animationBoundingSphere[MAX_ANIMATIONS] [protected]

const MD2AnimInfo G3D::MD2Model::animationTable[MAX_ANIMATIONS] [static, protected]

Information relating Animations to keyFrames.

Used by computeFrameNumbers().

const double G3D::MD2Model::hangTimePct [static, protected]

How long we hold in the air as a fraction of jump time.

Array<int> G3D::MD2Model::indexArray [protected]

Triangle list array useful for generating all of the triangles, e.g.

for collision detection. Not used for rendering.

The pose currently stored in interpolatedFrame.

When the animation is MAX_ANIMATIONS interpolatedFrame is not yet initialized.

int G3D::MD2Model::nextVarArea [static, protected]

When NONE_ALLOCATED, the vertex arrays have not been allocated.

Vector3 G3D::MD2Model::normalTable[162] [static, protected]

Quake uses a set of canonical normal vectors.

Amount of time to blend between two animations.

The long name is to keep this from accidentally conflicting with a subclass's variable name.

Do not use or explicitly manipulate this value--its type may change in the future and is not part of the supported API.

Linked list of all weak pointers that reference this (some may be on the stack!).

Do not use or explicitly manipulate this value.

1/header.skinWidth, 1/header.skinHeight, used by computeTextureCoords

VARAreaRef G3D::MD2Model::varArea[NUM_VAR_AREAS] [static, protected]

Shared dynamic vertex arrays.

Allocated by allocateVertexArrays. We cycle through multiple VARAreas because the models are so small that we can send data to the card faster than it can be rendered and we end up spending all of our time waiting on the GPU.


The documentation for this class was generated from the following file:
Generated on Thu Aug 2 11:40:46 2007 for G3D by doxygen 1.5.2
Hosted by SourceForge.net Logo