2010-04-06 01:09:34 +02:00
|
|
|
/* Copyright (C) 2010 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>
|
|
|
|
|
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
|
2009-01-03 19:40:28 +01:00
|
|
|
class CModel : public CRenderableObject
|
2004-05-30 02:46:58 +02:00
|
|
|
{
|
2009-01-03 19:40:28 +01:00
|
|
|
NONCOPYABLE(CModel);
|
|
|
|
|
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
|
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
|
|
|
|
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;
|
2010-04-06 01:09:34 +02:00
|
|
|
// sets the bool& arguments if the given time update will cross the trigger points for those actions;
|
|
|
|
// otherwise leaves the arguments unchanged
|
|
|
|
void CheckActionTriggers(float time, bool& action, bool& action2) 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.
|
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 SetPlayerID(size_t id);
|
2005-04-07 06:29:07 +02:00
|
|
|
// set the model's player colour
|
2010-03-17 23:51:47 +01:00
|
|
|
void SetPlayerColor(const CColor& colour);
|
2005-09-06 10:25:41 +02:00
|
|
|
// set the models mod color
|
2010-03-17 23:51:47 +01:00
|
|
|
void SetShadingColor(const 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
|
2010-04-06 01:09:34 +02:00
|
|
|
bool SetAnimation(CSkeletonAnim* anim, bool once = false, 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
|
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; }
|
2004-10-06 20:45:59 +02:00
|
|
|
|
|
|
|
// recurse down tree setting dirty bits
|
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 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
CSkeletonAnim* BuildAnimation(const VfsPath& pathname, const char* name, float speed, float actionpos, float 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);
|
2009-02-18 11:36:27 +01:00
|
|
|
// remove any props from the given point
|
2004-05-30 02:46:58 +02:00
|
|
|
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
|
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
|
|
|
|
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;
|
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
|