Support Forum       G3D Web Page     
Classes | Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Static Protected Member Functions | Protected Attributes | List of all members
G3D::MD2Model Class Reference


Quake II model class primarily used for low-polygon keyframe animated characters. More...

Inherits G3D::Model.

Classes

class  MD2AnimInfo
 
class  Part
 
class  Pose
 
class  Specification
 

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
}
 
These names are (mostly) from Quake II. More...
 

Public Member Functions

virtual const StringclassName () const override
 Name of the G3D::Model subclass. More...
 
virtual bool intersect (const Ray &ray, const CoordinateFrame &cframe, float &maxDistance, Model::HitInfo &info=Model::HitInfo::ignore, const Entity *entity=nullptr, const Model::Pose *pose=nullptr) const override
 Determines if the ray intersects the heightfield and fills the info with the proper information. More...
 
virtual const Stringname () const override
 Name of the instance (usually based on the filename it is loaded from) More...
 
int numParts () const
 Either 1 or 2, depending on whether a weapon is present. More...
 
int numTriangles () const
 Total number of triangles in the mesh. More...
 
void pose (Array< shared_ptr< Surface > > &surfaceArray, const CFrame &rootFrame, const CFrame &prevFrame, const shared_ptr< Entity > &entity, const Model::Pose *pose, const Model::Pose *prevPose, const Surface::ExpressiveLightScatteringProperties &e) override
 The current implementation does not reflect character animation in GBuffer::SS_POSITION_CHANGE, only root motion. More...
 

Static Public Member Functions

static bool animationAttack (Animation a)
 
static bool animationCrouch (Animation a)
 
Returns true for the crouching set of animations. More...
 
static bool animationDeath (Animation a)
 
Returns true for the death animations More...
 
static bool animationInterruptible (Animation a)
 True for actions that can be interrupted, like running or saluting. More...
 
static bool animationJump (Animation a)
 
static SimTime animationLength (Animation a)
 
Returns the total time of the animation. More...
 
static bool animationLoops (Animation a)
 
Returns true for standing, running, crouching, and crouch walking animations. More...
 
static bool animationPain (Animation A)
 
static bool animationRun (Animation a)
 
running, forward or backward, standing or crouching More...
 
static bool animationRunBackward (Animation a)
 
static bool animationRunForward (Animation a)
 
static bool animationStand (Animation a)
 
STAND or CROUCH_STAND. More...
 
static void computeFrameNumbers (const Pose &pose, int &kf0, int &kf1, float &alpha)
 
Computes the previous and next frame indices and how far we are between them. More...
 
static shared_ptr< MD2Modelcreate (const Specification &s, const String &name="")
 Create a new MD2Model. More...
 
static int getFrameNumber (const Pose &pose)
 
Returns a value for MD2Model::Pose::preFrameNumber that will smoothly blend from this animation to the next one. More...
 
static lazy_ptr< ModellazyCreate (const Specification &s, const String &name="")
 
static lazy_ptr< ModellazyCreate (const String &name, const Any &any)
 
static void setNormalTable ()
 Loads data into the normalTable. More...
 
static void setUseOptimizedIntersect (bool b)
 If true, complex models should use TriTree to accelerate intersect() calls where possible. More...
 
static bool useOptimizedIntersect ()
 

Static Public Attributes

static const MD2AnimInfo animationTable [MAX_ANIMATIONS]
 
Information relating Animations to keyFrames. More...
 
static const float hangTimePct
 How long we hold in the air as a fraction of jump time. More...
 
static Vector3 normalTable [162]
 
Quake uses a set of canonical normal vectors. More...
 
static const SimTime PRE_BLEND_TIME
 
Amount of time to blend between two animations. More...
 

Static Protected Member Functions

template<class T , class ... ArgTypes>
static shared_ptr< T > createShared (ArgTypes &&... args)
 Like std::make_shared, but works for protected constructors. More...
 
static MD2Model::Animation getAnimationCorrespondingToFrame (int frameNum)
 Returns the animation corresponding to the frame number (always the forward version of the animation) Used for computing conservative bounds. More...
 

Protected Attributes

String m_name
 
int m_numTriangles
 
Array< shared_ptr< Part > > m_part
 
bool negateNormals
 If true, negate the normal direction on this object when rendering. More...
 

Detailed Description


Quake II model class primarily used for low-polygon keyframe animated characters.

Quake II models contain up to two parts, where the second part is typically a weapon. Each part is a single mesh that is keyframe animated. Because the vertex positions and normals are highly quantized, these models tend to distort a bit under animation.

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.

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

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

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

Sample posing code:

MD2Model::Pose::Action a;
a.movingForward = true;
pose.onSimulation(dt, a);

You can specify multiple fields of the Action and the onSimulation method will resolve the best underlying animation.

See also
G3D::MD3Model, G3D::ArticulatedModel, G3D::IFSModel, G3D::Entity

Member Enumeration Documentation

◆ Animation


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 

Member Function Documentation

◆ animationAttack()

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

◆ animationCrouch()

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


Returns true for the crouching set of animations.

◆ animationDeath()

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


Returns true for the death animations

◆ animationInterruptible()

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.

◆ animationJump()

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

◆ animationLength()

static SimTime 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.

◆ animationLoops()

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


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

◆ animationPain()

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

◆ animationRun()

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


running, forward or backward, standing or crouching

◆ animationRunBackward()

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

◆ animationRunForward()

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

◆ animationStand()

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


STAND or CROUCH_STAND.

◆ className()

virtual const String& G3D::MD2Model::className ( ) const
overridevirtual

Name of the G3D::Model subclass.

Implements G3D::Model.

◆ computeFrameNumbers()

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


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

◆ create()

static shared_ptr<MD2Model> G3D::MD2Model::create ( const Specification s,
const String name = "" 
)
static

Create a new MD2Model.

Note that this can also be invoked with the path name of a single tris.md2 file as an String, which will automatically cast to a MD2Model::Specification.

Referenced by lazyCreate().

◆ createShared()

template<class T , class ... ArgTypes>
static shared_ptr<T> G3D::ReferenceCountedObject::createShared ( ArgTypes &&...  args)
inlinestaticprotectedinherited

Like std::make_shared, but works for protected constructors.

Call as createShared<myclass>.

◆ getAnimationCorrespondingToFrame()

static MD2Model::Animation G3D::MD2Model::getAnimationCorrespondingToFrame ( int  frameNum)
staticprotected

Returns the animation corresponding to the frame number (always the forward version of the animation) Used for computing conservative bounds.

◆ getFrameNumber()

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.

◆ intersect()

virtual bool G3D::MD2Model::intersect ( const Ray ray,
const CoordinateFrame cframe,
float &  maxDistance,
Model::HitInfo info = Model::HitInfo::ignore,
const Entity entity = nullptr,
const Model::Pose pose = nullptr 
) const
overridevirtual

Determines if the ray intersects the heightfield and fills the info with the proper information.

Parameters
maxDistanceMax distance to trace to on input, hit distance written on output if hit

Reimplemented from G3D::Model.

◆ lazyCreate() [1/2]

static lazy_ptr<Model> G3D::MD2Model::lazyCreate ( const Specification s,
const String name = "" 
)
inlinestatic

Referenced by lazyCreate().

◆ lazyCreate() [2/2]

static lazy_ptr<Model> G3D::MD2Model::lazyCreate ( const String name,
const Any any 
)
inlinestatic

◆ name()

virtual const String& G3D::MD2Model::name ( ) const
inlineoverridevirtual

Name of the instance (usually based on the filename it is loaded from)

Implements G3D::Model.

Referenced by lazyCreate().

◆ numParts()

int G3D::MD2Model::numParts ( ) const
inline

Either 1 or 2, depending on whether a weapon is present.

◆ numTriangles()

int G3D::MD2Model::numTriangles ( ) const
inline

Total number of triangles in the mesh.

◆ pose()

void G3D::MD2Model::pose ( Array< shared_ptr< Surface > > &  surfaceArray,
const CFrame rootFrame,
const CFrame prevFrame,
const shared_ptr< Entity > &  entity,
const Model::Pose pose,
const Model::Pose prevPose,
const Surface::ExpressiveLightScatteringProperties e 
)
overridevirtual

The current implementation does not reflect character animation in GBuffer::SS_POSITION_CHANGE, only root motion.

Implements G3D::Model.

◆ setNormalTable()

static void G3D::MD2Model::setNormalTable ( )
static

Loads data into the normalTable.

◆ setUseOptimizedIntersect()

static void G3D::Model::setUseOptimizedIntersect ( bool  b)
inlinestaticinherited

If true, complex models should use TriTree to accelerate intersect() calls where possible.

This can make the first intersect() call very slow for the tree build and can make loading slow. It may not affect performance of skinned or articulated models that animate.

This value should be set before the models are loaded. If it is changed after a model is loaded, the Model is not required to respond to it.

Default: false

◆ useOptimizedIntersect()

static bool G3D::Model::useOptimizedIntersect ( )
inlinestaticinherited

Member Data Documentation

◆ animationTable

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


Information relating Animations to keyFrames.

Used by computeFrameNumbers().

◆ hangTimePct

const float G3D::MD2Model::hangTimePct
static

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

◆ m_name

String G3D::MD2Model::m_name
protected

Referenced by name().

◆ m_numTriangles

int G3D::MD2Model::m_numTriangles
protected

Referenced by numTriangles().

◆ m_part

Array<shared_ptr<Part> > G3D::MD2Model::m_part
protected

Referenced by numParts().

◆ negateNormals

bool G3D::MD2Model::negateNormals
protected

If true, negate the normal direction on this object when rendering.

◆ normalTable

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


Quake uses a set of canonical normal vectors.

◆ PRE_BLEND_TIME

const SimTime G3D::MD2Model::PRE_BLEND_TIME
static


Amount of time to blend between two animations.


documentation generated on Wed Nov 24 2021 08:01:58 using doxygen 1.8.15