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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================//
#include "cbase.h"
#include "mathlib/vmatrix.h"
#include "functionproxy.h"
#include "materialsystem/imaterialvar.h"
#include <KeyValues.h>
#include "materialsystem/imaterial.h"
#include "toolframework_client.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
// forward declarations
void ToolFramework_RecordMaterialParams( IMaterial *pMaterial );
class C_BaseEntity;
//-----------------------------------------------------------------------------
// Texture transform proxy
//-----------------------------------------------------------------------------
class CTextureTransformProxy : public CResultProxy
{
public:
bool Init( IMaterial *pMaterial, KeyValues *pKeyValues );
void OnBind( void *pC_BaseEntity );
private:
IMaterialVar *m_pCenterVar;
IMaterialVar *m_pScaleVar;
IMaterialVar *m_pRotateVar;
IMaterialVar *m_pTranslateVar;
};
bool CTextureTransformProxy::Init( IMaterial *pMaterial, KeyValues *pKeyValues )
{
// All are optional...
m_pCenterVar = NULL;
m_pScaleVar = NULL;
m_pRotateVar = NULL;
m_pTranslateVar = NULL;
bool bFoundVar;
char const* pVarName = pKeyValues->GetString( "centerVar" );
if( pVarName && pVarName[0] )
{
m_pCenterVar = pMaterial->FindVar( pVarName, &bFoundVar, false );
}
pVarName = pKeyValues->GetString( "scaleVar" );
if( pVarName && pVarName[0] )
{
m_pScaleVar = pMaterial->FindVar( pVarName, &bFoundVar, false );
}
pVarName = pKeyValues->GetString( "rotateVar" );
if( pVarName && pVarName[0] )
{
m_pRotateVar = pMaterial->FindVar( pVarName, &bFoundVar, false );
}
pVarName = pKeyValues->GetString( "translateVar" );
if( pVarName && pVarName[0] )
{
m_pTranslateVar = pMaterial->FindVar( pVarName, &bFoundVar, false );
}
return CResultProxy::Init( pMaterial, pKeyValues );
}
void CTextureTransformProxy::OnBind( void *pC_BaseEntity )
{
Vector2D center( 0.5, 0.5 );
Vector2D translation( 0, 0 );
VMatrix mat, temp;
if (m_pCenterVar)
{
m_pCenterVar->GetVecValue( center.Base(), 2 );
}
MatrixBuildTranslation( mat, -center.x, -center.y, 0.0f );
if (m_pScaleVar)
{
Vector2D scale;
m_pScaleVar->GetVecValue( scale.Base(), 2 );
MatrixBuildScale( temp, scale.x, scale.y, 1.0f );
MatrixMultiply( temp, mat, mat );
}
if (m_pRotateVar)
{
float angle = m_pRotateVar->GetFloatValue( );
MatrixBuildRotateZ( temp, angle );
MatrixMultiply( temp, mat, mat );
}
MatrixBuildTranslation( temp, center.x, center.y, 0.0f );
MatrixMultiply( temp, mat, mat );
if (m_pTranslateVar)
{
m_pTranslateVar->GetVecValue( translation.Base(), 2 );
MatrixBuildTranslation( temp, translation.x, translation.y, 0.0f );
MatrixMultiply( temp, mat, mat );
}
m_pResult->SetMatrixValue( mat );
if ( ToolsEnabled() )
{
ToolFramework_RecordMaterialParams( GetMaterial() );
}
}
EXPOSE_INTERFACE( CTextureTransformProxy, IMaterialProxy, "TextureTransform" IMATERIAL_PROXY_INTERFACE_VERSION );
//-----------------------------------------------------------------------------
// Rotation proxy
//-----------------------------------------------------------------------------
class CMatrixRotateProxy : public CResultProxy
{
public:
bool Init( IMaterial *pMaterial, KeyValues *pKeyValues );
void OnBind( void *pC_BaseEntity );
private:
CFloatInput m_Angle;
IMaterialVar *m_pAxisVar;
};
bool CMatrixRotateProxy::Init( IMaterial *pMaterial, KeyValues *pKeyValues )
{
// All are optional...
m_pAxisVar = NULL;
bool bFoundVar;
char const* pVarName = pKeyValues->GetString( "axisVar" );
if( pVarName && pVarName[0] )
{
m_pAxisVar = pMaterial->FindVar( pVarName, &bFoundVar, false );
}
if (!m_Angle.Init( pMaterial, pKeyValues, "angle", 0 ))
return false;
return CResultProxy::Init( pMaterial, pKeyValues );
}
void CMatrixRotateProxy::OnBind( void *pC_BaseEntity )
{
VMatrix mat;
Vector axis( 0, 0, 1 );
if (m_pAxisVar)
{
m_pAxisVar->GetVecValue( axis.Base(), 3 );
if (VectorNormalize( axis ) < 1e-3)
{
axis.Init( 0, 0, 1 );
}
}
MatrixBuildRotationAboutAxis( mat, axis, m_Angle.GetFloat() );
m_pResult->SetMatrixValue( mat );
if ( ToolsEnabled() )
{
ToolFramework_RecordMaterialParams( GetMaterial() );
}
}
EXPOSE_INTERFACE( CMatrixRotateProxy, IMaterialProxy, "MatrixRotate" IMATERIAL_PROXY_INTERFACE_VERSION );
|