summaryrefslogtreecommitdiff
path: root/hammer/studiomodel.h
blob: 13b583916f33a726064e79905840dcf0644ec9f2 (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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
// $NoKeywords: $
//=============================================================================//
#ifndef STUDIOMODEL_H
#define STUDIOMODEL_H

#ifdef _WIN32
#pragma once
#endif

#ifndef byte
typedef unsigned char byte;
#endif // byte

#include "hammer_mathlib.h"
#include "studio.h"
#include "utlvector.h"
#include "datacache/imdlcache.h"
#include "FileChangeWatcher.h"


class StudioModel;
class CMaterial;
class CRender3D;
class CRender2D;


struct ModelCache_t
{
	StudioModel *pModel;
	char *pszPath;
	int nRefCount;
};


//-----------------------------------------------------------------------------
// Purpose: Defines an interface to a cache of studio models.
//-----------------------------------------------------------------------------
class CStudioModelCache
{
	public:

		static StudioModel *FindModel(const char *pszModelPath);
		static StudioModel *CreateModel(const char *pszModelPath);
		static void AddRef(StudioModel *pModel);
		static void Release(StudioModel *pModel);
		static void AdvanceAnimation(float flInterval);

	protected:

		static BOOL AddModel(StudioModel *pModel, const char *pszModelPath);
		static void RemoveModel(StudioModel *pModel);

		static ModelCache_t m_Cache[1024];
		static int m_nItems;
};


// Calling these will monitor the filesystem for changes to model files and automatically 
// incorporate changes to the models.
void InitStudioFileChangeWatcher();
void UpdateStudioFileChangeWatcher();


class StudioModel
{
public:

	static bool				Initialize( void );
	static void				Shutdown( void ); // garymcthack - need to call this.

	StudioModel(void);
	~StudioModel(void);

	void					FreeModel ();
	bool					LoadModel( const char *modelname );
	bool					PostLoadModel ( const char *modelname );
	void					DrawModel3D( CRender3D *pRender, float flAlpha, bool bWireframe);
	void					DrawModel2D( CRender2D *pRender, float flAlpha, bool bWireFrame);
	void					AdvanceFrame( float dt );

	void					ExtractBbox( Vector &mins, Vector &maxs );
	void					ExtractClippingBbox( Vector &mins, Vector &maxs );
	void					ExtractMovementBbox( Vector &mins, Vector &maxs );
	void					RotateBbox( Vector &Mins, Vector &Maxs, const QAngle &Angles );

	int						SetSequence( int iSequence );
	int						GetSequence( void );
	int						GetSequenceCount( void );
	void					GetSequenceName( int nIndex, char *szName );
	void					GetSequenceInfo( float *pflFrameRate, float *pflGroundSpeed );

	int						SetBodygroup( int iGroup, int iValue );
	int						SetSkin( int iValue );
	void					SetOrigin( float x, float y, float z );
	void					GetOrigin( float &x, float &y, float &z );
	void					SetOrigin( const Vector &v );
	void					GetOrigin( Vector &v );
	void					SetAngles( QAngle& pfAngles );
	bool					IsTranslucent();

private:
	CStudioHdr				*m_pStudioHdr;
	CStudioHdr				*GetStudioHdr() const;
	studiohdr_t*			GetStudioRenderHdr() const;
	studiohwdata_t*			GetHardwareData();

	// entity settings
	Vector					m_origin;
	QAngle					m_angles;	
	int						m_sequence;			// sequence index
	float					m_cycle;			// pos in animation cycle
	int						m_bodynum;			// bodypart selection	
	int						m_skinnum;			// skin group selection
	byte					m_controller[MAXSTUDIOBONECTRLS];	// bone controllers
	float					m_poseParameter[MAXSTUDIOPOSEPARAM];		// animation blending
	byte					m_mouth;			// mouth position
	char*					m_pModelName;		// model file name

	Vector					*m_pPosePos;
	Quaternion				*m_pPoseAng;

	// internal data
	MDLHandle_t				m_MDLHandle;
	mstudiomodel_t			*m_pModel;	

	void					SetUpBones ( bool bUpdatePose, matrix3x4_t*	pBoneToWorld );
	void					SetupModel ( int bodypart );

	void					LoadStudioRender( void );

	bool					LoadVVDFile( const char *modelname );
	bool					LoadVTXFile( const char *modelname );
};


extern Vector g_vright;		// needs to be set to viewer's right in order for chrome to work
extern float g_lambert;		// modifier for pseudo-hemispherical lighting


#endif // STUDIOMODEL_H