summaryrefslogtreecommitdiff
path: root/public/movieobjects/dmemodel.h
blob: fd181a1ff4338b992dc3906e556fc572a60ef544 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Dme version of a skeletal model (gets compiled into a MDL)
//
//===========================================================================//

#ifndef DMEMODEL_H
#define DMEMODEL_H

#ifdef _WIN32
#pragma once
#endif

#include "tier1/utlstack.h"
#include "movieobjects/dmejoint.h"
#include "movieobjects/dmetransformlist.h"


class CDmeDrawSettings;

//-----------------------------------------------------------------------------
// A class representing a skeletal model
//-----------------------------------------------------------------------------
class CDmeModel : public CDmeDag
{
	DEFINE_ELEMENT( CDmeModel, CDmeDag );

public:
	// Add joint
	CDmeJoint *AddJoint( const char *pJointName, CDmeDag *pParent = NULL );
	int AddJoint( CDmeDag *pJoint );

	// Returns the number of joint transforms we know about
	int GetJointTransformCount() const;

	// Determines joint transform index	given a joint name
	int GetJointTransformIndex( CDmeTransform *pTransform ) const;

	// Determines joint transform index	given a joint
	int GetJointTransformIndex( CDmeDag *pJoint ) const;

	// Determines joint transform index	given a joint name
	CDmeTransform *GetJointTransform( int nIndex );
	const CDmeTransform *GetJointTransform( int nIndex ) const;

	// Captures the current joint transforms into a base state
	void CaptureJointsToBaseState( const char *pBaseStateName );

	// Finds a base state by name, returns NULL if not found
	CDmeTransformList *FindBaseState( const char *pBaseStateName );

	// Recursively render the Dag hierarchy
	virtual void Draw( CDmeDrawSettings *pDrawSettings = NULL );

	// Set if Z is the up axis of the model
	void ZUp( bool bYUp );

	// Returns true if the DmeModel is Z Up.
	bool IsZUp() const;

protected:
	// The order in which the joint transform names appear in this list
	// indicates the joint index for each dag
	CDmaElementArray<CDmeTransform> m_JointTransforms;

	// Stores a list of base poses for all the joint transforms
	CDmaElementArray<CDmeTransformList> m_BaseStates;

private:
	enum SetupBoneRetval_t
	{
		NO_SKIN_DATA = 0,
		TOO_MANY_BONES,
		BONES_SET_UP
	};

	// Sets up the render state for the model
	SetupBoneRetval_t SetupBoneMatrixState( const matrix3x4_t& shapeToWorld, bool bForceSoftwareSkin );

	// Loads up joint transforms for this model
	void LoadJointTransform( CDmeDag *pJoint, CDmeTransformList *pBindPose, const matrix3x4_t &parentToWorld, const matrix3x4_t &parentToBindPose, bool bSetHardwareState );

	// Sets up the render state for the model
	static matrix3x4_t *SetupModelRenderState( const matrix3x4_t& shapeToWorld, bool bHasSkinningData, bool bForceSoftwareSkin );
	static void CleanupModelRenderState();

	// Stack of DmeModels currently being rendered. Used to set up render state
	static CUtlStack< CDmeModel * > s_ModelStack;

	friend class CDmeMesh;
};


#endif // DMEMODEL_H