1 //-*****************************************************************************
2 //
3 // Copyright (c) 2009-2013,
4 // Sony Pictures Imageworks Inc. and
5 // Industrial Light & Magic, a division of Lucasfilm Entertainment Company Ltd.
6 //
7 // All rights reserved.
8 //
9 // Redistribution and use in source and binary forms, with or without
10 // modification, are permitted provided that the following conditions are
11 // met:
12 // * Redistributions of source code must retain the above copyright
13 // notice, this list of conditions and the following disclaimer.
14 // * Redistributions in binary form must reproduce the above
15 // copyright notice, this list of conditions and the following disclaimer
16 // in the documentation and/or other materials provided with the
17 // distribution.
18 // * Neither the name of Sony Pictures Imageworks, nor
19 // Industrial Light & Magic, nor the names of their contributors may be used
20 // to endorse or promote products derived from this software without specific
21 // prior written permission.
22 //
23 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 //
35 //-*****************************************************************************
36
37 #ifndef AlembicExport_MayaUtility_h
38 #define AlembicExport_MayaUtility_h
39
40 #include "Foundation.h"
41 #include <Alembic/Abc/OArrayProperty.h>
42 #include <Alembic/Abc/OScalarProperty.h>
43
44 namespace util
45 {
46
47 struct cmpDag
48 {
operatorcmpDag49 bool operator()( const MDagPath& lhs, const MDagPath& rhs ) const
50 {
51 std::string name1(lhs.fullPathName().asChar());
52 std::string name2(rhs.fullPathName().asChar());
53 return (name1.compare(name2) < 0);
54 }
55 };
56 typedef std::set< MDagPath, cmpDag > ShapeSet;
57
isFloat(MString str,const MString & usage)58 inline MStatus isFloat(MString str, const MString & usage)
59 {
60 MStatus status = MS::kSuccess;
61
62 if (!str.isFloat())
63 {
64 MGlobal::displayInfo(usage);
65 status = MS::kFailure;
66 }
67
68 return status;
69 }
70
isUnsigned(MString str,const MString & usage)71 inline MStatus isUnsigned(MString str, const MString & usage)
72 {
73 MStatus status = MS::kSuccess;
74
75 if (!str.isUnsigned())
76 {
77 MGlobal::displayInfo(usage);
78 status = MS::kFailure;
79 }
80
81 return status;
82 }
83
84 // safely inverse a scale component
inverseScale(double scale)85 inline double inverseScale(double scale)
86 {
87 const double kScaleEpsilon = 1.0e-12;
88
89 if (scale < kScaleEpsilon && scale >= 0.0)
90 return 1.0 / kScaleEpsilon;
91 else if (scale > -kScaleEpsilon && scale < 0.0)
92 return 1.0 / -kScaleEpsilon;
93 else
94 return 1.0 / scale;
95 }
96
97 // seconds per frame
98 double spf();
99
100 bool isAncestorDescendentRelationship(const MDagPath & path1,
101 const MDagPath & path2);
102
103 // returns 0 if static, 1 if sampled, and 2 if a curve
104 int getSampledType(const MPlug& iPlug);
105
106 // 0 dont write, 1 write static 0, 2 write anim 0, 3 write anim 1
107 int getVisibilityType(const MPlug & iPlug);
108
109 // determines what order we do the rotation in, returns false if iOrder is
110 // kInvalid or kLast
111 bool getRotOrder(MTransformationMatrix::RotationOrder iOrder,
112 unsigned int & oXAxis, unsigned int & oYAxis, unsigned int & oZAxis);
113
114 // determine if a Maya Object is animated or not
115 // copy from mayapit code (MayaPit.h .cpp)
116 bool isAnimated(MObject & object, bool checkParent = false);
117
118 // determine if a joint is driven by FBIK.
119 // The joint is animated but has no input connections.
120 bool isDrivenByFBIK(const MFnIkJoint & iJoint);
121
122 // determine if a joint is driven by a spline ik.
123 // The joint's is animated but has no input connections.
124 bool isDrivenBySplineIK(const MFnIkJoint & iJoint);
125
126 // determine if a Maya Object is intermediate
127 bool isIntermediate(const MObject & object);
128
129 // returns true for visible and lod invisible and not templated objects
130 bool isRenderable(const MObject & object);
131
132 // strip iDepth namespaces from the node name, go from taco:foo:bar to bar
133 // for iDepth > 1
134 MString stripNamespaces(const MString & iNodeName, unsigned int iDepth);
135
136 // returns the Help string for AbcExport
137 MString getHelpText();
138
139 } // namespace util
140
141
142 #define MCHECKERROR(_status) \
143 { \
144 MStatus _maya_status = (_status); \
145 if ( MStatus::kSuccess != _maya_status ) \
146 { \
147 std::cout << "\nAPI error detected in " << __FILE__ \
148 << " at line " << __LINE__ << std::endl; \
149 _maya_status.perror ( "" ); \
150 return (_status); \
151 } \
152 }
153
154 #define MCHECKERROR_NO_RET(_status) \
155 { \
156 MStatus _maya_status = (_status); \
157 if ( MStatus::kSuccess != _maya_status ) \
158 { \
159 std::cout << "\nAPI error detected in " << __FILE__ \
160 << " at line " << __LINE__ << std::endl; \
161 _maya_status.perror ( "" ); \
162 } \
163 }
164
165 struct PlugAndObjScalar
166 {
167 MPlug plug;
168 MObject obj;
169 Alembic::Abc::OScalarProperty prop;
170 };
171
172 struct PlugAndObjArray
173 {
174 MPlug plug;
175 MObject obj;
176 Alembic::Abc::OArrayProperty prop;
177 };
178
179 struct JobArgs
180 {
JobArgsJobArgs181 JobArgs()
182 {
183 excludeInvisible = false;
184 filterEulerRotations = false;
185 noNormals = false;
186 setFirstAnimShape = false;
187 stripNamespace = 0;
188 useSelectionList = false;
189 worldSpace = false;
190 writeVisibility = false;
191 writeUVs = false;
192 writeColorSets = false;
193 writeFaceSets = false;
194 writeUVSets = false;
195 writeGeometry = true;
196 writeCurvesGroup = true;
197 writeTransforms = true;
198 writeLocators = true;
199 writeParticles = true;
200 writeMeshes = true;
201 writeCameras = true;
202 writeNurbsSurfaces = true;
203 writeNurbsCurves = true;
204 autoSubd = false;
205 }
206
207 bool excludeInvisible;
208 bool filterEulerRotations;
209 bool noNormals;
210 bool setFirstAnimShape;
211 unsigned int stripNamespace;
212 bool useSelectionList;
213 bool writeGeometry;
214 bool worldSpace;
215 bool writeVisibility;
216 bool writeUVs;
217 bool writeColorSets;
218 bool writeFaceSets;
219 bool writeUVSets;
220 bool writeCurvesGroup;
221 bool writeTransforms;
222 bool writeLocators;
223 bool writeParticles;
224 bool writeMeshes;
225 bool writeCameras;
226 bool writeNurbsSurfaces;
227 bool writeNurbsCurves;
228 bool autoSubd;
229
230 std::string melPerFrameCallback;
231 std::string melPostCallback;
232 std::string pythonPerFrameCallback;
233 std::string pythonPostCallback;
234
235 // to put into .arbGeomParam
236 std::vector< std::string > prefixFilters;
237 std::set< std::string > attribs;
238
239 // to put into .userProperties
240 std::vector< std::string > userPrefixFilters;
241 std::set< std::string > userAttribs;
242
243 util::ShapeSet dagPaths;
244 };
245
246 struct FrameRangeArgs
247 {
FrameRangeArgsFrameRangeArgs248 FrameRangeArgs()
249 {
250 startTime = 0.0;
251 endTime = 0.0;
252 strideTime = 1.0;
253 preRoll = false;
254 }
255
256 double startTime;
257 double endTime;
258 double strideTime;
259
260 std::set< double > shutterSamples;
261
262 bool preRoll;
263 };
264
265 #endif // AlembicExport_MayaUtility_h
266