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
|
#include "precompiled/PCH.h"
#include "intersection.h"
#include "main/constants.h"
#include "utility/glext.h"
#include "utility/mext.h"
#include "utility/nodehelper.h"
#include "utility/transformmatrix.h"
#include <toollib.hpp>
MTypeId IntersectionLocatorNode::id( TEConstants::TypeIDPrefix, TEConstants::NodeIDs::Intersection );
const char* IntersectionLocatorNode::stringId = "IntersectionLocatorNode";
//Attribute
const char* IntersectionLocatorNode::TYPE_NAME_LONG = "IntersectionType";
const char* IntersectionLocatorNode::TYPE_NAME_SHORT = "it";
MObject IntersectionLocatorNode::mType;
const char* IntersectionLocatorNode::ROAD_LONG = "Roads";
const char* IntersectionLocatorNode::ROAD_SHORT = "R";
MObject IntersectionLocatorNode::mRoads;
const int IntersectionLocatorNode::ACTIVE_COLOUR = 13;
const int IntersectionLocatorNode::INACTIVE_COLOUR = 22;
const float IntersectionLocatorNode::SCALE = 1.0f * TEConstants::Scale;
IntersectionLocatorNode::IntersectionLocatorNode() {};
IntersectionLocatorNode::~IntersectionLocatorNode() {};
//==============================================================================
// IntersectionLocatorNode::creator
//==============================================================================
// Description: Comment
//
// Parameters: ()
//
// Return: void
//
//==============================================================================
void* IntersectionLocatorNode::creator()
{
return new IntersectionLocatorNode();
}
//==============================================================================
// IntersectionLocatorNode::initialize
//==============================================================================
// Description: Comment
//
// Parameters: ()
//
// Return: MStatus
//
//==============================================================================
MStatus IntersectionLocatorNode::initialize()
{
MStatus status;
MFnTypedAttribute fnTyped;
MFnMessageAttribute fnMessage;
mType = fnTyped.create( TYPE_NAME_LONG, TYPE_NAME_SHORT, MFnData::kString, MObject::kNullObj, &status );
RETURN_STATUS_ON_FAILURE( status );
RETURN_STATUS_ON_FAILURE( addAttribute( mType ) );
mRoads = fnMessage.create( ROAD_LONG, ROAD_SHORT, &status );
RETURN_STATUS_ON_FAILURE( status );
RETURN_STATUS_ON_FAILURE( fnMessage.setReadable( false ) );
RETURN_STATUS_ON_FAILURE( fnMessage.setWritable( true ) );
RETURN_STATUS_ON_FAILURE( fnMessage.setArray( true ) );
RETURN_STATUS_ON_FAILURE( fnMessage.setIndexMatters( false ) );
RETURN_STATUS_ON_FAILURE( addAttribute( mRoads ) );
return MS::kSuccess;
}
//==============================================================================
// IntersectionLocatorNode::postConstructor
//==============================================================================
// Description: Comment
//
// Parameters: ()
//
// Return: void
//
//==============================================================================
void IntersectionLocatorNode::postConstructor()
{
}
//==============================================================================
// IntersectionLocatorNode::draw
//==============================================================================
// Description: Comment
//
// Parameters: draw( M3dView & view,
// const MDagPath & path,
// M3dView::DisplayStyle style,
// M3dView::DisplayStatus status )
//
// Return: void
//
//==============================================================================
void IntersectionLocatorNode::draw( M3dView & view,
const MDagPath & path,
M3dView::DisplayStyle style,
M3dView::DisplayStatus status )
{
view.beginGL();
glPushAttrib( GL_CURRENT_BIT | GL_LINE_BIT | GL_POLYGON_BIT );
if ( status == 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::drawI( TEConstants::Scale );
GLExt::drawSphere( SCALE );
glPopAttrib();
view.endGL();
}
//==============================================================================
// IntersectionLocatorNode::Export
//==============================================================================
// Description: Comment
//
// Parameters: ( MObject& intersectionLocatorNode, tlHistory& history )
//
// Return: tlDataChunk
//
//==============================================================================
tlDataChunk* IntersectionLocatorNode::Export( MObject& intersectionLocatorNode,
tlHistory& history )
{
MFnDagNode fnNode( intersectionLocatorNode );
if ( fnNode.typeId() == IntersectionLocatorNode::id )
{
tlIntersectionChunk* intersectionChunk = new tlIntersectionChunk;
intersectionChunk->SetName( fnNode.name().asChar() );
MPoint thisPosition;
MExt::GetWorldPosition( &thisPosition, intersectionLocatorNode );
tlPoint point;
point[0] = thisPosition[0] / TEConstants::Scale;
point[1] = thisPosition[1] / TEConstants::Scale;
point[2] = -thisPosition[2] / TEConstants::Scale; //Maya vs. P3D...
intersectionChunk->SetCentre( rmt::Vector( point ) );
//GetScale...
MObject transform;
transform = fnNode.parent( 0 );
MFnTransform fnTransform( transform );
MDagPath dagPath;
MExt::FindDagNodeByName( &dagPath, fnTransform.name() );
TransformMatrix tm( dagPath );
double scaleX;
fnTransform.findPlug( MString( "sx" ) ).getValue( scaleX );
intersectionChunk->SetRadius( (float)scaleX );
MPlug typePlug = fnNode.findPlug( mType );
MString type;
typePlug.getValue( type );
if ( MString("NoStop") == type )
{
intersectionChunk->SetType( 0 );
}
else if ( MString("NWay") == type )
{
intersectionChunk->SetType( 1 );
}
else if ( MString("FourWay") == type )
{
intersectionChunk->SetType( 2 );
}
else if ( MString("NoStopN") == type )
{
intersectionChunk->SetType( 3 );
}
else //if ( MString("NWay") == type )
{
intersectionChunk->SetType( 4 );
}
return intersectionChunk;
}
assert( false );
return NULL;
}
|