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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
|
//=============================================================================
// Copyright (C) 2002 Radical Entertainment Ltd. All rights reserved.
//
// File: FOVLocatorNode.cpp
//
// Description: Implement FOVLocatorNode
//
// History: 03/08/2002 + Created -- Cary Brisebois
//
//=============================================================================
//========================================
// System Includes
//========================================
#include "main/toolhack.h"
#include <toollib.hpp>
//========================================
// Project Includes
//========================================
#include "nodes/FOVLocatorNode.h"
#include "main/constants.h"
#include "main/worldbuilder.h"
#include "utility/glext.h"
#include "utility/mext.h"
#include "utility/nodehelper.h"
#include "nodes/triggervolumenode.h"
#include "resources/resource.h"
#include "../../../game/code/meta/locatortypes.h"
//******************************************************************************
//
// Global Data, Local Data, Local Classes
//
//******************************************************************************
MTypeId FOVLocatorNode::id( WBConstants::TypeIDPrefix, WBConstants::NodeIDs::FOVLocator );
const char* FOVLocatorNode::stringId = "FOVLocatorNode";
const char* FOVLocatorNode::TRIGGERS_NAME_SHORT = "trigs";
const char* FOVLocatorNode::TRIGGERS_NAME_LONG = "triggers";
MObject FOVLocatorNode::sTriggers;
const char* FOVLocatorNode::FOV_NAME_SHORT = "f";
const char* FOVLocatorNode::FOV_NAME_LONG = "fov";
MObject FOVLocatorNode::sFOV;
const char* FOVLocatorNode::TIME_NAME_SHORT = "tm";
const char* FOVLocatorNode::TIME_NAME_LONG = "time";
MObject FOVLocatorNode::sTime;
const char* FOVLocatorNode::RATE_NAME_SHORT = "ra";
const char* FOVLocatorNode::RATE_NAME_LONG = "rate";
MObject FOVLocatorNode::sRate;
const int FOVLocatorNode::ACTIVE_COLOUR = 15;
const int FOVLocatorNode::INACTIVE_COLOUR = 12;
const float FOVLocatorNode::SCALE = 1.0f * WBConstants::Scale;
char FOVLocatorNode::sNewName[MAX_NAME_LEN];
//******************************************************************************
//
// Callbacks
//
//******************************************************************************
BOOL CALLBACK FOVLocatorNameCallBack( HWND hWnd, UINT uMsg, UINT wParam, long lParam )
{
switch (uMsg)
{
case WM_INITDIALOG:
{
SetDlgItemText( hWnd, IDC_EDIT2, WorldBuilder::GetPrefix() );
return true;
}
break;
case WM_COMMAND:
{
if ( LOWORD(wParam) == IDC_BUTTON1 || LOWORD(wParam) == IDOK )
{
//Get the entry in the text field.
char name[FOVLocatorNode::MAX_NAME_LEN];
GetDlgItemText( hWnd, IDC_EDIT1, name, FOVLocatorNode::MAX_NAME_LEN );
if ( strcmp(name, "") == 0 )
{
MExt::DisplayWarning("You must input a new name for the FOV Locator!");
return false;
}
MString newName( WorldBuilder::GetPrefix() );
newName += MString( name );
FOVLocatorNode::SetNewName( newName.asChar() );
EndDialog( hWnd, 0 ); //this is how you close the window.
return true;
}
else if( LOWORD(wParam) == IDCANCEL )
{
FOVLocatorNode::SetNewName( "" );
EndDialog( hWnd, 0 ); //this is how you close the window.
return true;
}
return false;
}
break;
default:
{
return false;
}
break;
}
}
//******************************************************************************
//
// Public Member Functions
//
//******************************************************************************
//==============================================================================
// FOVLocatorNode::FOVLocatorNode
//==============================================================================
// Description: Constructor.
//
// Parameters: None.
//
// Return: N/A.
//
//==============================================================================
FOVLocatorNode::FOVLocatorNode()
{
}
//==============================================================================
// FOVLocatorNode::~FOVLocatorNode
//==============================================================================
// Description: Destructor.
//
// Parameters: None.
//
// Return: N/A.
//
//==============================================================================
FOVLocatorNode::~FOVLocatorNode()
{
}
//=============================================================================
// FOVLocatorNode::creator
//=============================================================================
// Description: Comment
//
// Parameters: ()
//
// Return: void
//
//=============================================================================
void* FOVLocatorNode::creator()
{
return new FOVLocatorNode();
}
//=============================================================================
// FOVLocatorNode::draw
//=============================================================================
// Description: Comment
//
// Parameters: ( M3dView& view, const MDagPath& path, M3dView::DisplayStyle displayStyle, M3dView::DisplayStatus displayStatus )
//
// Return: void
//
//=============================================================================
void FOVLocatorNode::draw( M3dView& view,
const MDagPath& path,
M3dView::DisplayStyle displayStyle,
M3dView::DisplayStatus displayStatus )
{
if ( WorldBuilder::GetDisplayLevel() & WorldBuilder::CARSTART_LOCATORS )
{
view.beginGL();
glPushAttrib( GL_CURRENT_BIT | GL_LINE_BIT | GL_POLYGON_BIT );
//When we are in render mode, we draw the lines between the nodes.
//If this was in GL_SELECTION_MODE, we would not draw the lines, so they won't interfere
//with selection.
GLint value;
glGetIntegerv( GL_RENDER_MODE, &value );
//Draw things here we don't want selectable.
if ( (value == GL_RENDER) )
{
}
if ( displayStatus == M3dView::kDormant )
{
int colour = NodeHelper::OverrideNodeColour( thisMObject(), INACTIVE_COLOUR );
view.setDrawColor( colour, M3dView::kDormantColors );
}
else
{
view.setDrawColor( ACTIVE_COLOUR, M3dView::kActiveColors );
}
//Draw a star to represent the locator.
GLExt::drawCrossHair3D( SCALE, 0,0,0, 5.0 );
glPopAttrib();
view.endGL();
}
}
//=============================================================================
// FOVLocatorNode::initialize
//=============================================================================
// Description: Comment
//
// Parameters: ()
//
// Return: MStatus
//
//=============================================================================
MStatus FOVLocatorNode::initialize()
{
MStatus status;
MFnMessageAttribute msgAttr;
sTriggers = msgAttr.create( TRIGGERS_NAME_LONG, TRIGGERS_NAME_SHORT, &status );
RETURN_STATUS_ON_FAILURE( status );
RETURN_STATUS_ON_FAILURE( msgAttr.setReadable( false ) );
RETURN_STATUS_ON_FAILURE( msgAttr.setWritable( true ) );
RETURN_STATUS_ON_FAILURE( msgAttr.setArray( true ) );
RETURN_STATUS_ON_FAILURE( msgAttr.setIndexMatters( false ) );
RETURN_STATUS_ON_FAILURE( addAttribute( sTriggers ) );
MFnNumericAttribute numAttr;
sFOV = numAttr.create( FOV_NAME_LONG, FOV_NAME_SHORT, MFnNumericData::kFloat, 90.0f, &status );
RETURN_STATUS_ON_FAILURE( status );
RETURN_STATUS_ON_FAILURE( numAttr.setReadable( true ) );
RETURN_STATUS_ON_FAILURE( numAttr.setWritable( true ) );
RETURN_STATUS_ON_FAILURE( numAttr.setMin(0.1f) );
RETURN_STATUS_ON_FAILURE( numAttr.setMax(180.0f) );
RETURN_STATUS_ON_FAILURE( addAttribute( sFOV ) );
sTime = numAttr.create( TIME_NAME_LONG, TIME_NAME_SHORT, MFnNumericData::kFloat, 2.0f, &status );
RETURN_STATUS_ON_FAILURE( status );
RETURN_STATUS_ON_FAILURE( numAttr.setReadable( true ) );
RETURN_STATUS_ON_FAILURE( numAttr.setWritable( true ) );
RETURN_STATUS_ON_FAILURE( numAttr.setMin(0.0f) );
RETURN_STATUS_ON_FAILURE( numAttr.setMax(10.0f) );
RETURN_STATUS_ON_FAILURE( addAttribute( sTime ) );
sRate = numAttr.create( RATE_NAME_LONG, RATE_NAME_SHORT, MFnNumericData::kFloat, 0.04f, &status );
RETURN_STATUS_ON_FAILURE( status );
RETURN_STATUS_ON_FAILURE( numAttr.setReadable( true ) );
RETURN_STATUS_ON_FAILURE( numAttr.setWritable( true ) );
RETURN_STATUS_ON_FAILURE( numAttr.setMin(0.0f) );
RETURN_STATUS_ON_FAILURE( numAttr.setMax(1.0f) );
RETURN_STATUS_ON_FAILURE( addAttribute( sRate ) );
return MStatus::kSuccess;
}
//=============================================================================
// FOVLocatorNode::postConstructor
//=============================================================================
// Description: Comment
//
// Parameters: ()
//
// Return: void
//
//=============================================================================
void FOVLocatorNode::postConstructor()
{
}
//=============================================================================
// FOVLocatorNode::Export
//=============================================================================
// Description: Comment
//
// Parameters: ( MObject& FOVLocatorNode )
//
// Return: tlDataChunk
//
//=============================================================================
tlDataChunk* FOVLocatorNode::Export( MObject& fovLocatorNode )
{
MFnDagNode fnNode( fovLocatorNode );
if ( fnNode.typeId() == FOVLocatorNode::id )
{
//Create a tlDataChunk and return it filled with the appropriate data.
tlWBLocatorChunk* locator = new tlWBLocatorChunk;
locator->SetName( fnNode.name().asChar() );
locator->SetType( LocatorType::FOV );
float fov = 90.0f;
float time = 2.0f;
float rate = 0.04f;
fnNode.findPlug( sFOV ).getValue( fov );
fnNode.findPlug( sTime ).getValue( time );
fnNode.findPlug( sRate ).getValue( rate );
unsigned long data[3];
memcpy( data, &fov, sizeof(float) );
memcpy( &(data[1]), &time, sizeof(float) );
memcpy( &(data[2]), &rate, sizeof(float) );
locator->SetDataElements( data, 3 );
locator->SetNumDataElements( 3 );
MPoint thisPosition;
MExt::GetWorldPosition( &thisPosition, fovLocatorNode );
//Set the values.
tlPoint point;
point[0] = thisPosition[0] / WBConstants::Scale;
point[1] = thisPosition[1] / WBConstants::Scale;
point[2] = -thisPosition[2] / WBConstants::Scale; //Maya vs. P3D...
locator->SetPosition( point );
//Make the trigger volumes a sub-chunk of the locator...
MPlugArray sources, targets;
MPlug triggersPlug = fnNode.findPlug( sTriggers );
MExt::ResolveConnections( &sources, &targets, triggersPlug, true, false );
unsigned int i;
for ( i = 0; i < sources.length(); ++i )
{
tlDataChunk* trigger = TriggerVolumeNode::Export( sources[ i ].node() );
assert( trigger );
locator->AppendSubChunk( trigger );
}
locator->SetNumTriggers( i );
return locator;
}
return NULL;
}
//******************************************************************************
//
// Private Member Functions
//
//******************************************************************************
|