forked from XutaxKamay/css_enhanced
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdmejoint.cpp
151 lines (113 loc) · 4.18 KB
/
dmejoint.cpp
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
145
146
147
148
149
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Dme version of a joint of a skeletal model (gets compiled into a MDL)
//
//=============================================================================
#include "movieobjects/dmejoint.h"
#include "datamodel/dmelementfactoryhelper.h"
#include "materialsystem/imaterialsystem.h"
#include "materialsystem/imesh.h"
#include "tier1/KeyValues.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
//-----------------------------------------------------------------------------
// Expose this class to the scene database
//-----------------------------------------------------------------------------
IMPLEMENT_ELEMENT_FACTORY( DmeJoint, CDmeJoint );
//-----------------------------------------------------------------------------
// Should I draw joints?
//-----------------------------------------------------------------------------
bool CDmeJoint::s_bDrawJoints = false;
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CDmeJoint::OnConstruction()
{
if ( !g_pMaterialSystem )
return;
KeyValues *pVMTKeyValues = new KeyValues( "wireframe" );
pVMTKeyValues->SetInt( "$vertexcolor", 1 );
pVMTKeyValues->SetInt( "$ignorez", 1 );
m_JointMaterial.Init( "__DmeJointMaterial", pVMTKeyValues );
}
void CDmeJoint::OnDestruction()
{
if ( !g_pMaterialSystem )
return;
m_JointMaterial.Shutdown();
}
//-----------------------------------------------------------------------------
// Activate, deactivate joint drawing
//-----------------------------------------------------------------------------
void CDmeJoint::DrawJointHierarchy( bool bDrawJoints )
{
s_bDrawJoints = bDrawJoints;
}
//-----------------------------------------------------------------------------
// For rendering joints
//-----------------------------------------------------------------------------
#define AXIS_SIZE 3.0f
void CDmeJoint::DrawJoints( )
{
if ( !g_pMaterialSystem )
return;
int cn = GetChildCount();
// Draw the joint hierarchy
PushDagTransform();
matrix3x4_t shapeToWorld;
GetShapeToWorldTransform( shapeToWorld );
CMatRenderContextPtr pRenderContext( g_pMaterialSystem );
pRenderContext->MatrixMode( MATERIAL_MODEL );
pRenderContext->LoadMatrix( shapeToWorld );
pRenderContext->Bind( m_JointMaterial );
IMesh *pMesh = pRenderContext->GetDynamicMesh( );
CMeshBuilder meshBuilder;
meshBuilder.Begin( pMesh, MATERIAL_LINES, 3 + cn );
for ( int ci = 0; ci < cn; ++ci )
{
CDmeJoint *pJoint = CastElement<CDmeJoint>( GetChild( ci ) );
if ( !pJoint )
continue;
Vector vecChildPosition = pJoint->GetTransform()->GetPosition();
meshBuilder.Position3f( 0.0f, 0.0f, 0.0f );
meshBuilder.Color4ub( 128, 128, 128, 255 );
meshBuilder.AdvanceVertex();
meshBuilder.Position3fv( vecChildPosition.Base() );
meshBuilder.Color4ub( 128, 128, 128, 255 );
meshBuilder.AdvanceVertex();
}
meshBuilder.Position3f( 0.0f, 0.0f, 0.0f );
meshBuilder.Color4ub( 255, 0, 0, 255 );
meshBuilder.AdvanceVertex();
meshBuilder.Position3f( AXIS_SIZE, 0.0f, 0.0f );
meshBuilder.Color4ub( 255, 0, 0, 255 );
meshBuilder.AdvanceVertex();
meshBuilder.Position3f( 0.0f, 0.0f, 0.0f );
meshBuilder.Color4ub( 0, 255, 0, 255 );
meshBuilder.AdvanceVertex();
meshBuilder.Position3f( 0.0f, AXIS_SIZE, 0.0f );
meshBuilder.Color4ub( 0, 255, 0, 255 );
meshBuilder.AdvanceVertex();
meshBuilder.Position3f( 0.0f, 0.0f, 0.0f );
meshBuilder.Color4ub( 0, 0, 255, 255 );
meshBuilder.AdvanceVertex();
meshBuilder.Position3f( 0.0f, 0.0f, AXIS_SIZE );
meshBuilder.Color4ub( 0, 0, 255, 255 );
meshBuilder.AdvanceVertex();
meshBuilder.End();
pMesh->Draw();
pRenderContext->MatrixMode( MATERIAL_MODEL );
pRenderContext->LoadIdentity();
PopDagTransform();
}
//-----------------------------------------------------------------------------
// Rendering method for the dag
//-----------------------------------------------------------------------------
void CDmeJoint::Draw( CDmeDrawSettings *pDrawSettings /* = NULL */ )
{
if ( s_bDrawJoints && IsVisible() )
{
DrawJoints();
}
BaseClass::Draw( pDrawSettings );
}