2007-05-07 18:33:24 +02:00
|
|
|
/**
|
|
|
|
* =========================================================================
|
|
|
|
* File : Model.h
|
|
|
|
* Project : 0 A.D.
|
|
|
|
* Description : Mesh object with texture and skinning information
|
|
|
|
* =========================================================================
|
|
|
|
*/
|
2004-05-30 02:46:58 +02:00
|
|
|
|
2007-05-07 18:33:24 +02:00
|
|
|
#ifndef INCLUDED_MODEL
|
|
|
|
#define INCLUDED_MODEL
|
2004-05-30 02:46:58 +02:00
|
|
|
|
2004-06-03 03:43:33 +02:00
|
|
|
#include <vector>
|
|
|
|
|
2004-05-30 02:46:58 +02:00
|
|
|
#include "Texture.h"
|
2004-12-12 19:40:00 +01:00
|
|
|
#include "MeshManager.h"
|
2004-05-30 02:46:58 +02:00
|
|
|
#include "RenderableObject.h"
|
2004-09-24 05:52:03 +02:00
|
|
|
#include "Material.h"
|
2006-06-02 04:10:27 +02:00
|
|
|
#include "ps/Overlay.h"
|
2004-12-12 20:43:55 +01:00
|
|
|
struct SPropPoint;
|
2006-04-24 00:22:18 +02:00
|
|
|
class CObjectEntry;
|
|
|
|
class CSkeletonAnim;
|
|
|
|
class CSkeletonAnimDef;
|
2007-03-01 19:52:53 +01:00
|
|
|
class CSkeletonAnimManager;
|
2004-05-30 02:46:58 +02:00
|
|
|
|
2004-10-06 20:45:59 +02:00
|
|
|
#define MODELFLAG_CASTSHADOWS (1<<0)
|
2004-11-11 08:09:32 +01:00
|
|
|
#define MODELFLAG_NOLOOPANIMATION (1<<1)
|
2004-05-30 02:46:58 +02:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// CModel: basically, a mesh object - holds the texturing and skinning
|
|
|
|
// information for a model in game
|
2007-03-01 19:52:53 +01:00
|
|
|
class CModel : public CRenderableObject, boost::noncopyable
|
2004-05-30 02:46:58 +02:00
|
|
|
{
|
2007-02-10 04:09:52 +01:00
|
|
|
friend class CUnitAnimation;
|
|
|
|
// HACK - we should probably move the rest of this class's animation state
|
|
|
|
// into the animation class, then it wouldn't need friend access
|
|
|
|
|
2004-05-30 02:46:58 +02:00
|
|
|
public:
|
|
|
|
struct Prop {
|
2006-04-24 00:22:18 +02:00
|
|
|
Prop() : m_Point(0), m_Model(0), m_ObjectEntry(0) {}
|
2004-10-06 20:45:59 +02:00
|
|
|
|
2004-05-30 02:46:58 +02:00
|
|
|
SPropPoint* m_Point;
|
|
|
|
CModel* m_Model;
|
2006-04-24 00:22:18 +02:00
|
|
|
CObjectEntry* m_ObjectEntry;
|
2004-05-30 02:46:58 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
public:
|
|
|
|
// constructor
|
2007-03-01 19:52:53 +01:00
|
|
|
CModel(CSkeletonAnimManager& skeletonAnimManager);
|
2004-05-30 02:46:58 +02:00
|
|
|
// destructor
|
|
|
|
~CModel();
|
|
|
|
|
|
|
|
// setup model from given geometry
|
2004-12-12 19:40:00 +01:00
|
|
|
bool InitModel(CModelDefPtr modeldef);
|
2004-05-30 02:46:58 +02:00
|
|
|
// calculate the world space bounds of this model
|
|
|
|
void CalcBounds();
|
|
|
|
// update this model's state; 'time' is the time since the last update, in MS
|
|
|
|
void Update(float time);
|
2007-02-10 04:09:52 +01:00
|
|
|
// returns true if Update(time) will require a new animation (due to the
|
|
|
|
// current one ending)
|
|
|
|
bool NeedsNewAnim(float time) const;
|
2004-05-30 02:46:58 +02:00
|
|
|
|
|
|
|
// get the model's geometry data
|
2004-12-12 19:40:00 +01:00
|
|
|
CModelDefPtr GetModelDef() { return m_pModelDef; }
|
2004-05-30 02:46:58 +02:00
|
|
|
|
|
|
|
// set the model's texture
|
|
|
|
void SetTexture(const CTexture& tex) { m_Texture=tex; }
|
2005-04-07 06:29:07 +02:00
|
|
|
// set the model's material
|
|
|
|
void SetMaterial(const CMaterial &material);
|
2006-03-17 04:59:49 +01:00
|
|
|
// set the model's player ID, recursively through props. CUnit::SetPlayerID
|
|
|
|
// should normally be used instead.
|
2005-04-07 06:29:07 +02:00
|
|
|
void SetPlayerID(int id);
|
|
|
|
// set the model's player colour
|
|
|
|
void SetPlayerColor(CColor& colour);
|
2005-09-06 10:25:41 +02:00
|
|
|
// set the models mod color
|
|
|
|
void SetShadingColor(CColor& colour);
|
2004-05-30 02:46:58 +02:00
|
|
|
// get the model's texture
|
|
|
|
CTexture* GetTexture() { return &m_Texture; }
|
2005-04-07 06:29:07 +02:00
|
|
|
// get the models material
|
|
|
|
CMaterial &GetMaterial() { return m_Material; }
|
2005-09-06 10:25:41 +02:00
|
|
|
// get the model's texture
|
|
|
|
CColor GetShadingColor() { return m_ShadingColor; }
|
2004-05-30 02:46:58 +02:00
|
|
|
|
|
|
|
// set the given animation as the current animation on this model
|
2006-03-17 04:59:49 +01:00
|
|
|
bool SetAnimation(CSkeletonAnim* anim, bool once = false, float speed = 1000.0f, CSkeletonAnim* next = NULL);
|
2005-05-27 02:38:30 +02:00
|
|
|
|
2004-05-30 02:46:58 +02:00
|
|
|
// get the currently playing animation, if any
|
2007-02-10 04:09:52 +01:00
|
|
|
CSkeletonAnim* GetAnimation() const { return m_Anim; }
|
2004-05-30 02:46:58 +02:00
|
|
|
|
2006-09-27 18:54:23 +02:00
|
|
|
// set the animation state to be the same as from another; both models should
|
|
|
|
// be compatible types (same type of skeleton)
|
|
|
|
void CopyAnimationFrom(CModel* source);
|
|
|
|
|
2004-10-06 20:45:59 +02:00
|
|
|
// set object flags
|
|
|
|
void SetFlags(u32 flags) { m_Flags=flags; }
|
|
|
|
// get object flags
|
|
|
|
u32 GetFlags() const { return m_Flags; }
|
|
|
|
|
|
|
|
// recurse down tree setting dirty bits
|
|
|
|
void SetDirtyRec(u32 dirtyflags) {
|
|
|
|
SetDirty(dirtyflags);
|
|
|
|
for (size_t i=0;i<m_Props.size();i++) {
|
|
|
|
m_Props[i].m_Model->SetDirtyRec(dirtyflags);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-05-30 02:46:58 +02:00
|
|
|
// calculate object space bounds of this model, based solely on vertex positions
|
|
|
|
void CalcObjectBounds();
|
|
|
|
// calculate bounds encompassing all vertex positions for given animation
|
|
|
|
void CalcAnimatedObjectBound(CSkeletonAnimDef* anim,CBound& result);
|
|
|
|
|
2005-10-26 03:03:28 +02:00
|
|
|
/**
|
2006-12-15 17:09:30 +01:00
|
|
|
* Set transform of this object.
|
2005-10-26 03:03:28 +02:00
|
|
|
*
|
|
|
|
* @note In order to ensure that all child props are updated properly,
|
|
|
|
* you must call ValidatePosition().
|
|
|
|
*/
|
2004-05-30 02:46:58 +02:00
|
|
|
void SetTransform(const CMatrix3D& transform);
|
|
|
|
|
2006-12-15 17:09:30 +01:00
|
|
|
/**
|
|
|
|
* Return whether this is a skinned/skeletal model. If it is, Get*BoneMatrices()
|
|
|
|
* will return valid non-NULL arrays.
|
|
|
|
*/
|
|
|
|
bool IsSkinned() { return (m_BoneMatrices != NULL); }
|
|
|
|
|
2004-05-30 02:46:58 +02:00
|
|
|
// return the models bone matrices
|
2006-12-15 17:09:30 +01:00
|
|
|
const CMatrix3D* GetAnimatedBoneMatrices() {
|
2005-10-26 03:03:28 +02:00
|
|
|
debug_assert(m_PositionValid);
|
2004-05-30 02:46:58 +02:00
|
|
|
return m_BoneMatrices;
|
|
|
|
}
|
2006-12-15 17:09:30 +01:00
|
|
|
const CMatrix3D* GetInverseBindBoneMatrices() {
|
|
|
|
return m_InverseBindBoneMatrices;
|
2004-05-30 02:46:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// load raw animation frame animation from given file, and build a
|
|
|
|
// animation specific to this model
|
2005-05-21 03:40:32 +02:00
|
|
|
CSkeletonAnim* BuildAnimation(const char* filename, const char* name, float speed, double actionpos, double actionpos2);
|
2004-05-30 02:46:58 +02:00
|
|
|
|
|
|
|
// add a prop to the model on the given point
|
2006-04-24 00:22:18 +02:00
|
|
|
void AddProp(SPropPoint* point, CModel* model, CObjectEntry* objectentry);
|
2004-05-30 02:46:58 +02:00
|
|
|
// remove a prop from the given point
|
|
|
|
void RemoveProp(SPropPoint* point);
|
|
|
|
// return prop list
|
2004-10-06 20:45:59 +02:00
|
|
|
std::vector<Prop>& GetProps() { return m_Props; }
|
|
|
|
const std::vector<Prop>& GetProps() const { return m_Props; }
|
2004-05-30 02:46:58 +02:00
|
|
|
|
|
|
|
// return a clone of this model
|
|
|
|
CModel* Clone() const;
|
|
|
|
|
2005-10-26 03:03:28 +02:00
|
|
|
/**
|
2006-12-15 17:09:30 +01:00
|
|
|
* Ensure that both the transformation and the bone
|
2005-10-26 03:03:28 +02:00
|
|
|
* matrices are correct for this model and all its props.
|
|
|
|
*/
|
|
|
|
void ValidatePosition();
|
|
|
|
|
2004-05-30 02:46:58 +02:00
|
|
|
private:
|
|
|
|
// delete anything allocated by the model
|
|
|
|
void ReleaseData();
|
2005-10-26 03:03:28 +02:00
|
|
|
|
|
|
|
/**
|
2006-12-15 17:09:30 +01:00
|
|
|
* Mark this model's position and bone matrices,
|
2005-10-26 03:03:28 +02:00
|
|
|
* and all props' positions as invalid.
|
|
|
|
*/
|
|
|
|
void InvalidatePosition();
|
|
|
|
|
2005-10-28 21:25:47 +02:00
|
|
|
/**
|
2006-12-15 17:09:30 +01:00
|
|
|
* If non-null, m_Parent points to the model that we
|
2005-10-26 03:03:28 +02:00
|
|
|
* are attached to.
|
|
|
|
*/
|
|
|
|
CModel* m_Parent;
|
2004-05-30 02:46:58 +02:00
|
|
|
|
2004-10-06 20:45:59 +02:00
|
|
|
// object flags
|
|
|
|
u32 m_Flags;
|
2004-05-30 02:46:58 +02:00
|
|
|
// texture used by model
|
|
|
|
CTexture m_Texture;
|
2005-04-07 06:29:07 +02:00
|
|
|
// model's material
|
|
|
|
CMaterial m_Material;
|
2004-05-30 02:46:58 +02:00
|
|
|
// pointer to the model's raw 3d data
|
2004-12-12 19:40:00 +01:00
|
|
|
CModelDefPtr m_pModelDef;
|
2004-05-30 02:46:58 +02:00
|
|
|
// object space bounds of model - accounts for bounds of all possible animations
|
2005-02-10 00:19:48 +01:00
|
|
|
// that can play on a model. Not always up-to-date - currently CalcBounds()
|
|
|
|
// updates it when necessary.
|
2004-05-30 02:46:58 +02:00
|
|
|
CBound m_ObjectBounds;
|
|
|
|
// animation currently playing on this model, if any
|
|
|
|
CSkeletonAnim* m_Anim;
|
2005-05-27 02:38:30 +02:00
|
|
|
// animation to switch back to when the current one finishes
|
|
|
|
CSkeletonAnim* m_NextAnim;
|
|
|
|
// rate at which the animation should play
|
|
|
|
float m_AnimSpeed;
|
2004-05-30 02:46:58 +02:00
|
|
|
// time (in MS) into the current animation
|
|
|
|
float m_AnimTime;
|
|
|
|
// current state of all bones on this model; null if associated modeldef isn't skeletal
|
|
|
|
CMatrix3D* m_BoneMatrices;
|
2006-12-15 17:09:30 +01:00
|
|
|
// inverse matrices for the bind pose's bones; null if not skeletal
|
|
|
|
CMatrix3D* m_InverseBindBoneMatrices;
|
2004-05-30 02:46:58 +02:00
|
|
|
// list of current props on model
|
|
|
|
std::vector<Prop> m_Props;
|
2005-09-06 10:25:41 +02:00
|
|
|
|
2005-10-26 03:03:28 +02:00
|
|
|
/**
|
2006-12-15 17:09:30 +01:00
|
|
|
* true if both transform and and bone matrices are valid.
|
2005-10-26 03:03:28 +02:00
|
|
|
*/
|
|
|
|
bool m_PositionValid;
|
|
|
|
|
2005-09-06 10:25:41 +02:00
|
|
|
// modulating color
|
|
|
|
CColor m_ShadingColor;
|
2007-03-01 19:52:53 +01:00
|
|
|
|
|
|
|
// manager object which can load animations for us
|
|
|
|
CSkeletonAnimManager& m_SkeletonAnimManager;
|
2004-05-30 02:46:58 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|