summaryrefslogtreecommitdiffstats
path: root/tools/trackeditor/code/nodes/pedpath.cpp
blob: 682f00402f849e26dce8ffbbc6bbb2bb6b4bced5 (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
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
#include "pedpath.h"
#include "walllocator.h"
#include "utility/mext.h"

#include <toollib.hpp>

MTypeId PedPathNode::id(  TEConstants::TypeIDPrefix, TEConstants::NodeIDs::PedPath );
const char*  PedPathNode::stringId = "PedPath";

//==============================================================================
// PedPathNode::PedPathNode
//==============================================================================
// Description: Comment
//
// Parameters:  ()
//
// Return:      PedPathNode
//
//==============================================================================
PedPathNode::PedPathNode() {}

//==============================================================================
// PedPathNode::~PedPathNode
//==============================================================================
// Description: Comment
//
// Parameters:  ()
//
// Return:      PedPathNode
//
//==============================================================================
PedPathNode::~PedPathNode() {}

//==============================================================================
// PedPathNode::creator
//==============================================================================
// Description: Comment
//
// Parameters:  ()
//
// Return:      void
//
//==============================================================================
void* PedPathNode::creator()
{
    return new PedPathNode();
}

//==============================================================================
// PedPathNode::initialize
//==============================================================================
// Description: Comment
//
// Parameters:  ()
//
// Return:      MStatus 
//
//==============================================================================
MStatus PedPathNode::initialize()
{
    return MS::kSuccess;
}

//==============================================================================
// PedPathNode::postConstructor
//==============================================================================
// Description: Comment
//
// Parameters:  ()
//
// Return:      void 
//
//==============================================================================
void PedPathNode::postConstructor()
{
    //No moving the pedpath.
    MPlug lPlug( thisMObject(), localPosition );
    lPlug.setLocked( true );

    MPlug wPlug( thisMObject(), worldPosition );
    wPlug.setLocked( true );
}

//This is how you export one of these.
//==============================================================================
// PedPathNode::Export
//==============================================================================
// Description: Comment
//
// Parameters:  ( MObject& pedNode, tlHistory& history )
//
// Return:      tlDataChunk
//
//==============================================================================
tlDataChunk* PedPathNode::Export( MObject& pedNode, tlHistory& history )
{
    //This fenceline assumes that there are fences below it.
    MFnDagNode fnNode( pedNode );

    if ( fnNode.typeId() == PedPathNode::id )
    {
        //Create a tlDataChunk and return it filled with the appropriate data.
        tlPedpathChunk* pedPath = new tlPedpathChunk;

        //Go through all it's children and add them to the chunk incrementing the 
        //count.

        unsigned int childCount = 0;
        MItDag dagIt( MItDag::kDepthFirst, MFn::kLocator );

        MFnDagNode fnDag( pedNode );
        MObject fenceT = fnDag.parent( 0 );

        dagIt.reset( fenceT );

        tlDataChunk tempChunk;

        while ( !dagIt.isDone() )
        { 
            MFnDependencyNode fnNode( dagIt.item() );
            MTypeId id = fnNode.typeId();

            if ( id == WallLocatorNode::id )
            {
                //Export a wall locator;
                tlWallChunk* newChunk = reinterpret_cast<tlWallChunk*>(WallLocatorNode::Export( dagIt.item(), history ));

                //Append this to the fence line
                tempChunk.AppendSubChunk( newChunk );

                ++childCount;
            }

            dagIt.next();
        }

        if ( childCount )
        {
            tlPoint* points = new tlPoint[childCount + 1];

            unsigned int i;
//            for ( i = 0; i < tempChunk.SubChunkCount(); i++ )
//            {
//                points[i] = reinterpret_cast<tlWallChunk*>(tempChunk.GetSubChunk( i ))->GetStart();
//
//                if ( i == tempChunk.SubChunkCount() - 1 )
//                {
//                    points[childCount] = reinterpret_cast<tlWallChunk*>(tempChunk.GetSubChunk( i ))->GetEnd();
//                }
//            }

            //Okay, we need to order the points...  If there was a split, the points will
            //be badly ordered.
            points[0] = reinterpret_cast<tlWallChunk*>(tempChunk.GetSubChunk( 0 ))->GetStart();  //First point is always good.

            //This is the testing point for the loop below.
            tlPoint testPoint = reinterpret_cast<tlWallChunk*>(tempChunk.GetSubChunk( 0 ))->GetEnd();
            tempChunk.RemoveSubChunk( 0 );
            
            unsigned int remainingChunks = childCount - 1;
            unsigned int foundCount = 1;


            while ( foundCount < childCount )
            {
                bool found = false;
                unsigned int chunkIndex = 0;
                for ( i = 0; i < remainingChunks; ++i )
                {
                    if ( !found && reinterpret_cast<tlWallChunk*>(tempChunk.GetSubChunk( i ))->GetStart() == testPoint )
                    {
                        points[foundCount] = reinterpret_cast<tlWallChunk*>(tempChunk.GetSubChunk( i ))->GetStart();
                        found = true;
                        foundCount++;

                        //heheh
                        if ( foundCount == childCount )
                        {
                            points[foundCount] = reinterpret_cast<tlWallChunk*>(tempChunk.GetSubChunk( i ))->GetEnd();
                            foundCount++;                        
                        }

                        chunkIndex = i;
                    }
                }

                if ( found )
                {
                    testPoint = reinterpret_cast<tlWallChunk*>(tempChunk.GetSubChunk( chunkIndex ))->GetEnd();

                    tempChunk.RemoveSubChunk( chunkIndex );
                    remainingChunks--;
                }
                else
                {
                    MExt::DisplayError("WHOA!  Big error, get Cary!!!!  Looks like ped paths are screwy..");
                    break;
                }
            }



            pedPath->SetPoints( points, childCount + 1 );
            pedPath->SetNumPoints( childCount + 1 );

            delete[] points;
            points = NULL;
        }
        else
        {
            delete pedPath;
            return NULL;
        }

        return pedPath;
    }

    assert( false );
    return NULL;
}

//==============================================================================
// PedPathNode::AddWall
//==============================================================================
// Description: Comment
//
// Parameters:  ( MObject& pedPath, MObject& wall )
//
// Return:      void 
//
//==============================================================================
void PedPathNode::AddWall( MObject& pedPath, MObject& wall )
{
    //Test to make sure the fenceLine passed in is an obj, not a transform.
    MFnDagNode fnDag( pedPath );
    if ( fnDag.typeId() == PedPathNode::id )
    {
        MExt::AddChild( pedPath, wall );
    }
    else
    {
        if ( pedPath.apiType() == MFn::kTransform )
        {
            //We need to find the FenceLine node that is the child of this transform.
            unsigned int childCount = fnDag.childCount();

            unsigned int i;

            MObject child;
            MFnDagNode fnDagChild;

            for ( i = 0; i < childCount; ++i )
            {
                child = fnDag.child( i );

                fnDagChild.setObject( child );

                if ( fnDagChild.typeId() == PedPathNode::id )
                {
                    //This is the child.
                    MExt::AddChild( child, wall );
                    return;
                }
            }

            MExt::DisplayError( "Tried to parent something strange to pedPath" );
            assert(false);
        }
    }
}