summaryrefslogtreecommitdiffstats
path: root/tools/globalcode/utility/MExt.h
blob: e4b6444d47a8389cf51bebf969b3e0fd62baf4aa (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
#include "precompiled/PCH.h"

#ifndef _MEXT_H
#define _MEXT_H
//-----------------------------------------------------------------------------
// Copyright (C) 2001 Radical Entertainment Ltd.  All rights reserved.
//
// MExt.h
//
// Description: Functions that extend the Maya API to perform other common 
//              tasks.
//
// Modification History:
//  + Created Aug 21, 2001 -- bkusy 
//-----------------------------------------------------------------------------

//----------------------------------------
// System Includes
//----------------------------------------
/* Using precompiled headers.
#include <maya/MStringArray.h>
#include <maya/MPoint.h>
#include <maya/MObject.h>
#include <maya/MPlug.h>
*/

//----------------------------------------
// Project Includes
//----------------------------------------
#include "MExt_template.h"

//----------------------------------------
// Forward References
//----------------------------------------
class MString;
class MDagPath;
class MArgList;
class MPlug;
class MObject;
class MSelectionList;
class MTypeId;
class MDoubleArray;

//----------------------------------------
// Macros
//----------------------------------------
#define RETURN_STATUS_ON_FAILURE( STATUS ) if ( ! (STATUS) ) return (STATUS)
#define RETURN_FALSE_ON_FAILURE( STATUS ) if ( ! (STATUS) ) return false

//These are used when dealing with plugs.
#define AS_DEST true, false
#define AS_SOURCE false, true
#define AS_BOTH true, true
//----------------------------------------
// Constants, Typedefs and Statics
//----------------------------------------



namespace MExt
{
    namespace Attr
    {
        void GetScaled( MPoint*, const MObject& node, const MObject& attr );

        void SetScaled( const MPoint&, MObject& node, MObject& attr );

        void SetScaled( const MPoint&, MObject& node, const MString& attr );

    } // namespace Attr

    namespace OptionVar
    {
        bool Get( char* buffer, unsigned int buffer_size, const char* symbol );

        void Set( const char* buffer, const char* symbol );

    } // namespace OptionVar


    class OptionParser
    {
        public:
        
            OptionParser( const char* command, const MArgList& args );
            ~OptionParser();

            void    setOptions( const char* optionSpec );
            int     nextOption();
            MString getArg();

        private:

            int m_argc;
            char** m_argv;
            char* m_opt;

    };


    void    AddChild( MObject& parentLocatorNode, MObject& childLocatorNode );

    void    Connect( MObject& node, 
                     MObject& attr,
                     MObject& otherNode,
                     MObject& otherAttr
                   );

    void    Connect( MObject& node, 
                     const char* attr,
                     MObject& otherNode,
                     const char* otherAttr
                   );
    

    void    CreateNode( MObject* node,
                        MObject* transform,
                        const MString& type,
                        const MString* name = 0,
                        const MObject& parent = MObject::kNullObj
                      );

    void    CreateNode( MObject& node,
                        MObject& transform,
                        const MString& type,
                        const MString* name = 0,
                        const MObject& parent = MObject::kNullObj
                      );


    void    CreateVertexAttribute( MObject* attr,
                                   const char* name,
                                   const char* brief_name
                                 );   

    void    DeleteNode( MObject& node, bool deleteParent );
                                 
    void    DisconnectAll( MObject& node, MObject& attr );   
    void    DisconnectAll( MObject& node, const char* attrName );

    int     DisplayError( const char* fmt, ... );

    int     DisplayWarning( const char* fmt, ... );

    int     DisplayInfo( const char* fmt, ... );
        
    void    FilterSelectionList( MSelectionList* filteredList,
                                 const MString& typeName,
                                 const MSelectionList& sourceList
                               );

    bool    FindAllSkeletonRoots( MObjectArray* objects );

    bool    FindAllTransforms( MObjectArray* transforms, const MObject& root );


    bool    FindDagNodeByName( MDagPath* path,
                               const MString& node,
                               const MObject& root = MObject::kNullObj
                             );

    bool    FindDagNodeByName( MDagPath* path,
                               const MString& node, 
                               const MString& root
                             );

    void    GetWorldPosition( MPoint*, const MObject& node );

    MPoint  GetWorldPositionBetween( MObject& node1, MObject& node2 );

    MMatrix GetWorldMatrix( MObject& node );

    bool    IsConnected( MObject& node, const char* attr );
    bool    IsConnected( MObject& node, MObject& attr );
    bool    IsConnected( MPlug& plug1, MPlug& plug2 );

    void    MakeNameUnique( MString* unique,
                            const MString& name,
                            const MObject& root = MObject::kNullObj
                          );

    void    MakeNameUnique( MString* unique,
                            const MString& name,
                            const MString& root
                          );

    bool    MeshClickIntersect( short xClick, short yClick, MPoint& intersect, bool closest = true );

    bool    MeshIntersectAlongVector( MPoint from, MPoint direction, MPoint& intersect, bool closest = true );

    bool    PlugHasConnection( MObject* connectedNode,
                               MPlug& plug,
                               bool asDst = true,
                               bool asSrc = true,
                               const char* type = 0
                             );

    bool    PlugHasConnection( MPlug* connectedPlug,
                               MPlug& plug,
                               bool asDst = true,
                               bool asSrc = true,
                               const char* type = 0
                             );


    void    ResolveConnections( MPlugArray* sources, 
                                MPlugArray* targets,
                                MPlug& plug,
                                bool asDst = true,
                                bool asSrc = true
                              );


    void    SelectNodesBelowRoot( MSelectionList* list,
                                  const MString& typeName,
                                  const MObject& root = MObject::kNullObj,
                                  MSelectionList* intersectionList = 0
                                );

    void    SetWorldPosition( const MPoint&, const MObject& node );

    void    ViewToWorldAtY( MPoint* world, MPoint& view, double y = 0.0  );

} // namespace MExt

#endif