summaryrefslogtreecommitdiffstats
path: root/tools/worldbuilder/code/nodes/wbspline.cpp
blob: d0673f7c7b0a6446e938e7609d0bd1c989f0fa7c (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
//=============================================================================
// Copyright (C) 2002 Radical Entertainment Ltd.  All rights reserved.
//
// File:        WBSpline.cpp
//
// Description: Implement WBSpline
//
// History:     05/06/2002 + Created -- Cary Brisebois
//
//=============================================================================

//========================================
// System Includes
//========================================
#include "main/toolhack.h"
#include <toollib.hpp>

//========================================
// Project Includes
//========================================
#include "nodes/WBSpline.h"
#include "nodes/triggervolumenode.h"
#include "main/constants.h"


//******************************************************************************
//
// Global Data, Local Data, Local Classes
//
//******************************************************************************
char WBSpline::sName[MAX_NAME_LEN];


//******************************************************************************
//
// Public Member Functions
//
//******************************************************************************

void WBSpline::SetName( const char* name )
{
    strncpy( sName, name, MAX_NAME_LEN );
}

const char* const WBSpline::GetName()
{
    return sName;
}

//=============================================================================
// WBSpline::Export
//=============================================================================
// Description: Comment
//
// Parameters:  ( MObject& obj )
//
// Return:      tlDataChunk
//
//=============================================================================
tlDataChunk* WBSpline::Export( MObject& obj )
{
    MStatus status;

    MFnDagNode fnDagNode( obj );
    MDagPath dagPath;
    fnDagNode.getPath( dagPath );

    MFnNurbsCurve fnNurbs( dagPath, &status );
    assert( status );

    if ( status )
    {
       //Create a tlDataChunk and return it filled with the appropriate data.
        tlWBSplineChunk* spline = new tlWBSplineChunk;

        spline->SetName( fnNurbs.name().asChar() );

        int numCVs = fnNurbs.numCVs( &status );
        assert( status );

        MPointArray cvs;
        fnNurbs.getCVs( cvs, MSpace::kWorld );

        tlPoint* tlCVs = new tlPoint[numCVs];

        int i;
        for ( i = 0; i < numCVs; ++i )
        {
            tlCVs[i].x = cvs[i].x / WBConstants::Scale;
            tlCVs[i].y = cvs[i].y / WBConstants::Scale;
            tlCVs[i].z = -cvs[i].z / WBConstants::Scale;
        }

        spline->SetCVs( tlCVs, numCVs );
        spline->SetNumCVs( numCVs );

        delete[] tlCVs;

        return spline;
    }

    return NULL;
}

//******************************************************************************
//
// Private Member Functions
//
//******************************************************************************