22 #include "precompiled.h"
48 : m_Flags(0), m_Anim(NULL), m_AnimTime(0), m_Simulation(simulation),
49 m_BoneMatrices(NULL), m_AmmoPropPoint(NULL), m_AmmoLoadedProp(0),
50 m_SkeletonAnimManager(skeletonAnimManager)
67 for (
size_t i = 0; i <
m_Props.size(); ++i)
83 size_t numBones = modeldef->GetNumBones();
86 size_t numBlends = modeldef->GetNumBlends();
91 for (
size_t i = 0; i < numBones + 1 + numBlends; ++i)
137 for (
size_t i=0;i<numverts;i++) {
180 for (
size_t i=0;i<numverts;i++)
198 for (
size_t i = 0; i <
m_Props.size(); ++i)
199 bounds +=
m_Props[i].m_Model->GetWorldBoundsRec();
208 for (
size_t i = 0; i <
m_Props.size(); ++i)
215 if (propSelectionBounds.
IsEmpty())
247 propSelectionBounds.
Transform(propObjectTransform, transformedPropSelectionBounds);
249 objBounds += transformedPropSelectionBounds;
269 if (actionpos == -1.f)
274 if (actionpos2 == -1.f)
279 if (soundpos == -1.f)
313 for (
size_t i = 0; i <
m_Props.size(); ++i)
314 m_Props[i].m_Model->InvalidatePosition();
351 for (
size_t i = 0; i <
m_pModelDef->GetNumBones(); i++)
367 bool worldSpaceBoneMatrices = !
g_Renderer.m_Options.m_GPUSkinning;
368 bool computeBlendMatrices = !
g_Renderer.m_Options.m_GPUSkinning;
374 for (
size_t i = 0; i <
m_pModelDef->GetNumBones(); i++)
383 for (
size_t j = 0; j <
m_Props.size(); ++j)
392 if (!worldSpaceBoneMatrices)
414 std::max(prop.
m_minHeight, propTerrain - objTerrain));
427 for (
size_t i = 0; i <
m_pModelDef->GetNumBones(); i++)
440 if (computeBlendMatrices)
476 LOGERROR(L
"Mismatch between model's skeleton and animation's skeleton (%lu model bones != %lu animation keys)",
530 AddProp(point, model, objectentry);
546 for (
size_t i = 0; i <
m_Props.size(); ++i)
561 for (
size_t i = 0; i <
m_Props.size(); ++i)
575 for (
size_t i = 0; i <
m_Props.size(); ++i)
600 for (
size_t i = 0; i <
m_Props.size(); i++)
634 for (
size_t i = 0; i <
m_Props.size(); ++i)
635 if (
m_Props[i].m_Model->ToCModel())
636 m_Props[i].m_Model->ToCModel()->AddFlagsRec(flags);
646 for (
size_t i = 0; i <
m_Props.size(); ++i)
648 if (
m_Props[i].m_Model->ToCModel())
649 m_Props[i].m_Model->ToCModel()->RemoveShadowsRec();
650 else if (
m_Props[i].m_Model->ToCModelDecal())
651 m_Props[i].m_Model->ToCModelDecal()->RemoveShadows();
664 for (std::vector<Prop>::iterator it =
m_Props.begin(); it !=
m_Props.end(); ++it)
665 it->m_Model->SetPlayerID(
id);
672 for (std::vector<Prop>::iterator it =
m_Props.begin(); it !=
m_Props.end(); ++it)
673 it->m_Model->SetShadingColor(colour);
u8 m_BoneIndex
Index of parent bone to which this prop point is relative, if any.
void Translate(float x, float y, float z)
void * rtl_AllocateAligned(size_t size, size_t align)
void Transform(const CMatrix3D &m, CBoundingBoxAligned &result) const
Transforms these bounds according to the specified transformation matrix m, and writes the axis-align...
CSkeletonAnimManager & m_SkeletonAnimManager
void HideAmmoProp()
Hide the ammo prop (if any), and show any other props on that prop point.
void AddShaderDefine(CStrIntern key, CStrIntern value)
Describes the position of a prop point within its parent model.
size_t GetNumKeys() const
void SetTranslation(float x, float y, float z)
virtual void SetPlayerID(player_id_t id)
CMatrix3D * m_BoneMatrices
Current state of all bones on this model; null if associated modeldef isn't skeletal.
const CMatrix3D & GetInvTransform() const
virtual const CBoundingBoxAligned GetWorldBoundsRec()
Returns world space bounds of this object and all child objects.
float GetFrameTime() const
virtual float GetExactGroundLevel(float x, float z)=0
#define RENDERDATA_UPDATE_VERTICES
virtual void SetTransform(const CMatrix3D &transform)
std::vector< Prop > m_Props
void UpdateTo(float time)
CSkeletonAnimDef * GetAnimation(const VfsPath &pathname)
CSkeletonAnimDef * m_AnimDef
#define MODELFLAG_IGNORE_LOS
void Rotate(const CQuaternion &quat)
bool m_PositionValid
True if both transform and and bone matrices are valid.
const entity_id_t SYSTEM_ENTITY
Entity ID for singleton 'system' components.
Public API for simulation system.
int32_t player_id_t
valid player IDs are non-negative (see ICmpOwnership)
const CMatrix3D * GetAnimatedBoneMatrices()
CSkeletonAnim * BuildAnimation(const VfsPath &pathname, const CStr &name, float speed, float actionpos, float actionpos2, float soundpos)
Load raw animation frame animation from given file, and build an animation specific to this model...
bool SetAnimation(CSkeletonAnim *anim, bool once=false)
#define ENSURE(expr)
ensure the expression <expr> evaluates to non-zero.
virtual void CalcBounds()
Overridden to calculate both the world-space and object-space bounds of this model, and stores the result in m_Bounds and m_ObjectBounds, respectively.
CBoundingBoxAligned m_WorldBounds
World-space bounds of this object.
bool InitModel(const CModelDefPtr &modeldef)
void BuildBoneMatrices(float time, CMatrix3D *matrices, bool loop) const
static CVector3D SkinPoint(const SModelVertex &vtx, const CMatrix3D newPoseMatrices[])
Transform the given vertex's position from the bind pose into the new pose.
CustomSelectionShape * m_CustomSelectionShape
Pointer to a descriptor for a custom-defined selection box shape.
void ShowAmmoProp()
Show the ammo prop (if any), and hide any other props on that prop point.
virtual CModelAbstract * Clone() const
virtual void ValidatePosition()
Ensure that both the transformation and the bone matrices are correct for this model and all its prop...
CModelAbstract * m_Model
Pointer to the model associated with this prop.
void SetDirty(u32 dirtyflags)
virtual void SetTransform(const CMatrix3D &transform)
Set transform of this object.
void AddProp(const SPropPoint *point, CModelAbstract *model, CObjectEntry *objectentry, float minHeight=0.f, float maxHeight=0.f)
Add a prop to the model on the given point.
size_t m_AmmoLoadedProp
If m_AmmoPropPoint is not NULL, then the index in m_Props of the ammo prop.
virtual const CBoundingBoxAligned GetObjectSelectionBoundsRec()
Reimplemented here since proper models should participate in selection boxes.
void AddAmmoProp(const SPropPoint *point, CModelAbstract *model, CObjectEntry *objectentry)
Add a prop to the model on the given point, and treat it as the ammo prop.
#define MODELFLAG_CASTSHADOWS
void CalcAnimatedObjectBounds(CSkeletonAnimDef *anim, CBoundingBoxAligned &result)
Auxiliary method; calculate object-space bounds encompassing all vertex positions for given animation...
size_t GetNumFrames() const
A simplified syntax for accessing entity components.
CBoundingBoxAligned m_ObjectBounds
CMatrix3D m_Transform
Object to parent space transformation.
CModelAbstract * FindFirstAmmoProp()
Find the first prop used for ammo, by this model or its own props.
const CBoundingBoxAligned & GetObjectBounds()
Returns the object-space bounds for this model, excluding its children.
const SPropPoint * m_Point
Location of the prop point within its parent model, relative to either a bone in the parent model or ...
void Concatenate(const CMatrix3D &m)
virtual const CBoundingBoxAligned GetObjectSelectionBoundsRec()
Returns the (object-space) bounds that should be used to construct a selection box for this model and...
Abstract base class for graphical objects that are used by units, or as props attached to other CMode...
CModel(CSkeletonAnimManager &skeletonAnimManager, CSimulation2 &simulation)
CBoundingBoxAligned m_ObjectBounds
float GetDuration() const
void rtl_FreeAligned(void *alignedPointer)
#define MODELFLAG_NOLOOPANIMATION
virtual void InvalidateBounds()
Marks the bounds as invalid.
const CMatrix3D & GetTransform() const
void CalcStaticObjectBounds()
Auxiliary method; calculates object space bounds of this model, based solely on vertex positions...
virtual void SetShadingColor(const CColor &colour)
CVector3D GetTranslation() const
bool m_SelectionBoxValid
Is the current selection box valid?
const CBoundingBoxAligned & GetWorldBounds()
Returns the world-space axis-aligned bounds of this object.
void RecomputeCombinedShaderDefines()
void SetPlayerID(player_id_t id)
CSimulation2 & m_Simulation
CObjectEntry * m_ObjectEntry
CModelAbstract * m_Parent
If non-null, points to the model that we are attached to.
const SPropPoint * m_AmmoPropPoint
The prop point to which the ammo prop is attached, or NULL if none.
virtual void ValidatePosition()=0
Ensure that both the transformation and the bone matrices are correct for this model and all its prop...
void CopyAnimationFrom(CModel *source)
virtual void SetShadingColor(const CColor &colour)
virtual void InvalidatePosition()
Mark this model's position and bone matrices, and all props' positions as invalid.
bool m_Hidden
Should this prop be temporarily removed from rendering?
void SetMaterial(const CMaterial &material)
boost::shared_ptr< CModelDef > CModelDefPtr
void AddFlagsRec(int flags)