2011-03-13 20:22:05 +01:00
|
|
|
/* Copyright (C) 2011 Wildfire Games.
|
2009-04-18 19:00:33 +02:00
|
|
|
* This file is part of 0 A.D.
|
|
|
|
*
|
|
|
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 0 A.D. is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2009-04-18 19:51:05 +02:00
|
|
|
/*
|
|
|
|
* Mesh object with texture and skinning information
|
2007-05-07 18:33:24 +02:00
|
|
|
*/
|
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>
|
|
|
|
|
2011-03-13 20:22:05 +01:00
|
|
|
#include "graphics/Texture.h"
|
|
|
|
#include "graphics/Material.h"
|
|
|
|
#include "graphics/MeshManager.h"
|
|
|
|
#include "graphics/ModelAbstract.h"
|
2006-06-02 04:10:27 +02:00
|
|
|
#include "ps/Overlay.h"
|
2010-06-05 02:49:14 +02:00
|
|
|
|
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)
|
2011-03-18 17:57:54 +01:00
|
|
|
#define MODELFLAG_SILHOUETTE_DISPLAY (1<<2)
|
|
|
|
#define MODELFLAG_SILHOUETTE_OCCLUDER (1<<3)
|
|
|
|
|
2004-05-30 02:46:58 +02:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// CModel: basically, a mesh object - holds the texturing and skinning
|
|
|
|
// information for a model in game
|
2011-03-13 20:22:05 +01:00
|
|
|
class CModel : public CModelAbstract
|
2004-05-30 02:46:58 +02:00
|
|
|
{
|
2009-01-03 19:40:28 +01:00
|
|
|
NONCOPYABLE(CModel);
|
|
|
|
|
2004-05-30 02:46:58 +02:00
|
|
|
public:
|
2010-06-05 02:49:14 +02:00
|
|
|
struct Prop
|
|
|
|
{
|
|
|
|
Prop() : m_Point(0), m_Model(0), m_ObjectEntry(0), m_Hidden(false) {}
|
2004-10-06 20:45:59 +02:00
|
|
|
|
2010-11-20 21:16:06 +01:00
|
|
|
const SPropPoint* m_Point;
|
2011-03-13 20:22:05 +01:00
|
|
|
CModelAbstract* m_Model;
|
2006-04-24 00:22:18 +02:00
|
|
|
CObjectEntry* m_ObjectEntry;
|
2010-06-05 02:49:14 +02:00
|
|
|
|
|
|
|
bool m_Hidden; // temporarily removed from rendering
|
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();
|
|
|
|
|
2011-03-13 20:22:05 +01:00
|
|
|
/// Dynamic cast
|
|
|
|
virtual CModel* ToCModel()
|
|
|
|
{
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2004-05-30 02:46:58 +02:00
|
|
|
// setup model from given geometry
|
2008-07-17 16:23:51 +02:00
|
|
|
bool InitModel(const CModelDefPtr& modeldef);
|
2004-05-30 02:46:58 +02:00
|
|
|
// calculate the world space bounds of this model
|
2011-03-13 20:22:05 +01:00
|
|
|
virtual void CalcBounds();
|
2010-06-05 02:49:14 +02:00
|
|
|
// update this model's state; 'time' is the absolute time since the start of the animation, in MS
|
|
|
|
void UpdateTo(float time);
|
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
|
2010-09-10 23:02:10 +02:00
|
|
|
void SetTexture(const CTexturePtr& tex) { m_Texture=tex; }
|
2005-04-07 06:29:07 +02:00
|
|
|
// set the model's material
|
|
|
|
void SetMaterial(const CMaterial &material);
|
2010-06-03 03:29:43 +02:00
|
|
|
// set the model's player ID, recursively through props
|
2011-03-18 17:57:54 +01:00
|
|
|
void SetPlayerID(player_id_t id);
|
2005-09-06 10:25:41 +02:00
|
|
|
// set the models mod color
|
2011-03-13 20:22:05 +01:00
|
|
|
virtual void SetShadingColor(const CColor& colour);
|
2004-05-30 02:46:58 +02:00
|
|
|
// get the model's texture
|
2010-09-10 23:02:10 +02:00
|
|
|
CTexturePtr& GetTexture() { return m_Texture; }
|
|
|
|
// get the model's material
|
|
|
|
CMaterial& GetMaterial() { return m_Material; }
|
2004-05-30 02:46:58 +02:00
|
|
|
|
|
|
|
// set the given animation as the current animation on this model
|
2010-06-05 02:49:14 +02:00
|
|
|
bool SetAnimation(CSkeletonAnim* anim, bool once = false);
|
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
|
had to remove uint and ulong from lib/types.h due to conflict with other library.
this snowballed into a massive search+destroy of the hodgepodge of
mostly equivalent types we had in use (int, uint, unsigned, unsigned
int, i32, u32, ulong, uintN).
it is more efficient to use 64-bit types in 64-bit mode, so the
preferred default is size_t (for anything remotely resembling a size or
index). tile coordinates are ssize_t to allow more efficient conversion
to/from floating point. flags are int because we almost never need more
than 15 distinct bits, bit test/set is not slower and int is fastest to
type. finally, some data that is pretty much directly passed to OpenGL
is now typed accordingly.
after several hours, the code now requires fewer casts and less
guesswork.
other changes:
- unit and player IDs now have an "invalid id" constant in the
respective class to avoid casting and -1
- fix some endian/64-bit bugs in the map (un)packing. added a
convenience function to write/read a size_t.
- ia32: change CPUID interface to allow passing in ecx (required for
cache topology detection, which I need at work). remove some unneeded
functions from asm, replace with intrinsics where possible.
This was SVN commit r5942.
2008-05-11 20:48:32 +02:00
|
|
|
void SetFlags(int flags) { m_Flags=flags; }
|
2004-10-06 20:45:59 +02:00
|
|
|
// get object flags
|
had to remove uint and ulong from lib/types.h due to conflict with other library.
this snowballed into a massive search+destroy of the hodgepodge of
mostly equivalent types we had in use (int, uint, unsigned, unsigned
int, i32, u32, ulong, uintN).
it is more efficient to use 64-bit types in 64-bit mode, so the
preferred default is size_t (for anything remotely resembling a size or
index). tile coordinates are ssize_t to allow more efficient conversion
to/from floating point. flags are int because we almost never need more
than 15 distinct bits, bit test/set is not slower and int is fastest to
type. finally, some data that is pretty much directly passed to OpenGL
is now typed accordingly.
after several hours, the code now requires fewer casts and less
guesswork.
other changes:
- unit and player IDs now have an "invalid id" constant in the
respective class to avoid casting and -1
- fix some endian/64-bit bugs in the map (un)packing. added a
convenience function to write/read a size_t.
- ia32: change CPUID interface to allow passing in ecx (required for
cache topology detection, which I need at work). remove some unneeded
functions from asm, replace with intrinsics where possible.
This was SVN commit r5942.
2008-05-11 20:48:32 +02:00
|
|
|
int GetFlags() const { return m_Flags; }
|
2011-03-18 17:57:54 +01:00
|
|
|
// add object flags, recursively through props
|
|
|
|
void AddFlagsRec(int flags);
|
2004-10-06 20:45:59 +02:00
|
|
|
|
|
|
|
// recurse down tree setting dirty bits
|
2011-03-13 20:22:05 +01:00
|
|
|
virtual void SetDirtyRec(int dirtyflags) {
|
2004-10-06 20:45:59 +02:00
|
|
|
SetDirty(dirtyflags);
|
|
|
|
for (size_t i=0;i<m_Props.size();i++) {
|
|
|
|
m_Props[i].m_Model->SetDirtyRec(dirtyflags);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-13 20:22:05 +01:00
|
|
|
virtual void SetTerrainDirty(ssize_t i0, ssize_t j0, ssize_t i1, ssize_t j1)
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < m_Props.size(); ++i)
|
|
|
|
m_Props[i].m_Model->SetTerrainDirty(i0, j0, i1, j1);
|
|
|
|
}
|
|
|
|
|
2011-04-06 02:11:40 +02:00
|
|
|
virtual void SetEntityVariable(const std::string& name, float value)
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < m_Props.size(); ++i)
|
|
|
|
m_Props[i].m_Model->SetEntityVariable(name, value);
|
|
|
|
}
|
|
|
|
|
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.
|
2011-03-13 20:22:05 +01:00
|
|
|
*
|
2005-10-26 03:03:28 +02:00
|
|
|
* @note In order to ensure that all child props are updated properly,
|
|
|
|
* you must call ValidatePosition().
|
|
|
|
*/
|
2011-03-13 20:22:05 +01:00
|
|
|
virtual 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
|
|
|
}
|
|
|
|
|
2010-04-06 01:09:34 +02:00
|
|
|
/**
|
|
|
|
* Load raw animation frame animation from given file, and build an
|
|
|
|
* animation specific to this model.
|
|
|
|
* @param pathname animation file to load
|
|
|
|
* @param name animation name (e.g. "idle")
|
|
|
|
* @param speed animation speed as a factor of the default animation speed
|
|
|
|
* @param actionpos offset of 'action' event, in range [0, 1]
|
|
|
|
* @param actionpos2 offset of 'action2' event, in range [0, 1]
|
|
|
|
* @return new animation, or NULL on error
|
|
|
|
*/
|
2011-02-17 21:08:20 +01:00
|
|
|
CSkeletonAnim* BuildAnimation(const VfsPath& pathname, const CStr& name, float speed, float actionpos, float actionpos2);
|
2004-05-30 02:46:58 +02:00
|
|
|
|
2010-06-05 02:49:14 +02:00
|
|
|
/**
|
|
|
|
* Add a prop to the model on the given point.
|
|
|
|
*/
|
2011-03-13 20:22:05 +01:00
|
|
|
void AddProp(const SPropPoint* point, CModelAbstract* model, CObjectEntry* objectentry);
|
2010-06-05 02:49:14 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a prop to the model on the given point, and treat it as the ammo prop.
|
|
|
|
* The prop will be hidden by default.
|
|
|
|
*/
|
2011-03-13 20:22:05 +01:00
|
|
|
void AddAmmoProp(const SPropPoint* point, CModelAbstract* model, CObjectEntry* objectentry);
|
2010-06-05 02:49:14 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the ammo prop (if any), and hide any other props on that prop point.
|
|
|
|
*/
|
|
|
|
void ShowAmmoProp();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hide the ammo prop (if any), and show any other props on that prop point.
|
|
|
|
*/
|
|
|
|
void HideAmmoProp();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Find the first prop used for ammo, by this model or its own props.
|
|
|
|
*/
|
2011-03-13 20:22:05 +01:00
|
|
|
CModelAbstract* FindFirstAmmoProp();
|
2010-06-05 02:49:14 +02:00
|
|
|
|
2004-05-30 02:46:58 +02:00
|
|
|
// 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
|
2011-03-13 20:22:05 +01:00
|
|
|
virtual CModelAbstract* Clone() const;
|
2004-05-30 02:46:58 +02:00
|
|
|
|
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.
|
|
|
|
*/
|
2011-03-13 20:22:05 +01:00
|
|
|
virtual void ValidatePosition();
|
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.
|
|
|
|
*/
|
2011-03-13 20:22:05 +01:00
|
|
|
virtual void InvalidatePosition();
|
|
|
|
|
|
|
|
private:
|
|
|
|
// delete anything allocated by the model
|
|
|
|
void ReleaseData();
|
2004-05-30 02:46:58 +02:00
|
|
|
|
2004-10-06 20:45:59 +02:00
|
|
|
// object flags
|
had to remove uint and ulong from lib/types.h due to conflict with other library.
this snowballed into a massive search+destroy of the hodgepodge of
mostly equivalent types we had in use (int, uint, unsigned, unsigned
int, i32, u32, ulong, uintN).
it is more efficient to use 64-bit types in 64-bit mode, so the
preferred default is size_t (for anything remotely resembling a size or
index). tile coordinates are ssize_t to allow more efficient conversion
to/from floating point. flags are int because we almost never need more
than 15 distinct bits, bit test/set is not slower and int is fastest to
type. finally, some data that is pretty much directly passed to OpenGL
is now typed accordingly.
after several hours, the code now requires fewer casts and less
guesswork.
other changes:
- unit and player IDs now have an "invalid id" constant in the
respective class to avoid casting and -1
- fix some endian/64-bit bugs in the map (un)packing. added a
convenience function to write/read a size_t.
- ia32: change CPUID interface to allow passing in ecx (required for
cache topology detection, which I need at work). remove some unneeded
functions from asm, replace with intrinsics where possible.
This was SVN commit r5942.
2008-05-11 20:48:32 +02:00
|
|
|
int m_Flags;
|
2004-05-30 02:46:58 +02:00
|
|
|
// texture used by model
|
2010-09-10 23:02:10 +02:00
|
|
|
CTexturePtr 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;
|
|
|
|
// 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
|
|
|
|
2010-06-05 02:49:14 +02:00
|
|
|
/**
|
|
|
|
* The prop point to which the ammo prop is attached, or NULL if none
|
|
|
|
*/
|
2010-11-20 21:16:06 +01:00
|
|
|
const SPropPoint* m_AmmoPropPoint;
|
2010-06-05 02:49:14 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* If m_AmmoPropPoint is not NULL, then the index in m_Props of the ammo prop
|
|
|
|
*/
|
|
|
|
size_t m_AmmoLoadedProp;
|
|
|
|
|
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
|