OLD | NEW |
1 //-***************************************************************************** | 1 //-***************************************************************************** |
2 // | 2 // |
3 // Copyright (c) 2009-2011, | 3 // Copyright (c) 2009-2011, |
4 // Sony Pictures Imageworks Inc. and | 4 // Sony Pictures Imageworks Inc. and |
5 // Industrial Light & Magic, a division of Lucasfilm Entertainment Company Ltd. | 5 // Industrial Light & Magic, a division of Lucasfilm Entertainment Company Ltd. |
6 // | 6 // |
7 // All rights reserved. | 7 // All rights reserved. |
8 // | 8 // |
9 // Redistribution and use in source and binary forms, with or without | 9 // Redistribution and use in source and binary forms, with or without |
10 // modification, are permitted provided that the following conditions are | 10 // modification, are permitted provided that the following conditions are |
(...skipping 25 matching lines...) Expand all Loading... |
36 | 36 |
37 #include "MayaNurbsCurveWriter.h" | 37 #include "MayaNurbsCurveWriter.h" |
38 #include "MayaUtility.h" | 38 #include "MayaUtility.h" |
39 #include "MayaTransformWriter.h" | 39 #include "MayaTransformWriter.h" |
40 | 40 |
41 namespace | 41 namespace |
42 { | 42 { |
43 // get all the nurbs curves from below the given dagpath. | 43 // get all the nurbs curves from below the given dagpath. |
44 // the curve group is considered animated if at least one curve is animated | 44 // the curve group is considered animated if at least one curve is animated |
45 | 45 |
46 void collectNurbsCurves(const MDagPath &dagPath, MDagPathArray &dagPaths, | 46 void collectNurbsCurves(const MDagPath &dagPath, bool iExcludeInvisible, |
47 bool & oIsAnimated) | 47 MDagPathArray &dagPaths, bool & oIsAnimated) |
48 { | 48 { |
49 MStatus stat; | 49 MStatus stat; |
50 | 50 |
51 MItDag itDag(MItDag::kDepthFirst, MFn::kNurbsCurve, &stat); | 51 MItDag itDag(MItDag::kDepthFirst, MFn::kNurbsCurve, &stat); |
52 stat = itDag.reset(dagPath, MItDag::kDepthFirst, MFn::kNurbsCurve); | 52 stat = itDag.reset(dagPath, MItDag::kDepthFirst, MFn::kNurbsCurve); |
53 | 53 |
54 if (stat == MS::kSuccess) | 54 if (stat == MS::kSuccess) |
55 { | 55 { |
56 for (;!itDag.isDone();itDag.next()) | 56 for (;!itDag.isDone();itDag.next()) |
57 { | 57 { |
58 MDagPath curvePath; | 58 MDagPath curvePath; |
59 stat = itDag.getPath(curvePath); | 59 stat = itDag.getPath(curvePath); |
60 if (stat == MS::kSuccess) | 60 if (stat == MS::kSuccess) |
61 { | 61 { |
62 MObject curve = curvePath.node(); | 62 MObject curve = curvePath.node(); |
63 | 63 |
64 if ( !util::isIntermediate(curve) && | 64 if ( !util::isIntermediate(curve) && |
65 curve.hasFn(MFn::kNurbsCurve) ) | 65 curve.hasFn(MFn::kNurbsCurve) && |
| 66 (!iExcludeInvisible || util::isRenderable(curve)) ) |
66 { | 67 { |
67 dagPaths.append(curvePath); | 68 dagPaths.append(curvePath); |
68 } | 69 } |
69 // don't bother checking the animated state if the curve | 70 // don't bother checking the animated state if the curve |
70 // wasn't appended to the list | 71 // wasn't appended to the list |
71 else | 72 else |
72 { | 73 { |
73 continue; | 74 continue; |
74 } | 75 } |
| 76 |
75 // with the flag set to true, check the DagPath and it's | 77 // with the flag set to true, check the DagPath and it's |
76 // parent | 78 // parent |
77 if (util::isAnimated(curve, true)) | 79 if (util::isAnimated(curve, true)) |
78 { | 80 { |
79 oIsAnimated = true; | 81 oIsAnimated = true; |
80 } | 82 } |
81 } | 83 } |
82 } | 84 } |
83 } | 85 } |
84 } // end of function collectNurbsCurves | 86 } // end of function collectNurbsCurves |
85 } | 87 } |
86 | 88 |
87 MayaNurbsCurveWriter::MayaNurbsCurveWriter(MDagPath & iDag, | 89 MayaNurbsCurveWriter::MayaNurbsCurveWriter(MDagPath & iDag, |
88 Alembic::Abc::OObject & iParent, uint32_t iTimeIndex, bool iIsCurveGrp, | 90 Alembic::Abc::OObject & iParent, Alembic::Util::uint32_t iTimeIndex, |
89 bool iWriteVisibility, bool iForceStatic) : | 91 bool iIsCurveGrp, const JobArgs & iArgs) : |
90 mIsAnimated(false), mRootDagPath(iDag), mIsCurveGrp(iIsCurveGrp) | 92 mIsAnimated(false), mRootDagPath(iDag), mIsCurveGrp(iIsCurveGrp) |
91 { | 93 { |
92 MStatus stat; | 94 MStatus stat; |
93 MFnDependencyNode fnDepNode(iDag.node(), &stat); | 95 MFnDependencyNode fnDepNode(iDag.node(), &stat); |
94 MString name = fnDepNode.name(); | 96 MString name = fnDepNode.name(); |
95 | 97 |
96 if (mIsCurveGrp) | 98 if (mIsCurveGrp) |
97 { | 99 { |
98 collectNurbsCurves(mRootDagPath, mNurbsCurves, mIsAnimated); | 100 collectNurbsCurves(mRootDagPath, iArgs.excludeInvisible, |
| 101 mNurbsCurves, mIsAnimated); |
99 | 102 |
100 // if no curves were found bail early | 103 // if no curves were found bail early |
101 if (mNurbsCurves.length() == 0) | 104 if (mNurbsCurves.length() == 0) |
102 return; | 105 return; |
103 } | 106 } |
104 else | 107 else |
105 { | 108 { |
106 MObject curve = iDag.node(); | 109 MObject curve = iDag.node(); |
107 | 110 |
108 if (util::isAnimated(curve)) | 111 if (iTimeIndex != 0 && util::isAnimated(curve)) |
109 mIsAnimated = true; | 112 mIsAnimated = true; |
110 } | 113 } |
111 | 114 |
| 115 if (iArgs.stripNamespace) |
| 116 { |
| 117 name = util::stripNamespaces(name); |
| 118 } |
| 119 |
112 Alembic::AbcGeom::OCurves obj(iParent, name.asChar(), iTimeIndex); | 120 Alembic::AbcGeom::OCurves obj(iParent, name.asChar(), iTimeIndex); |
113 mSchema = obj.getSchema(); | 121 mSchema = obj.getSchema(); |
114 | 122 |
115 Alembic::Abc::OCompoundProperty cp = mSchema.getArbGeomParams(); | 123 Alembic::Abc::OCompoundProperty cp; |
| 124 if (AttributesWriter::hasAnyAttr(iDag, iArgs)) |
| 125 { |
| 126 cp = mSchema.getArbGeomParams(); |
| 127 } |
116 | 128 |
117 mAttrs = AttributesWriterPtr(new AttributesWriter(cp, iDag, | 129 mAttrs = AttributesWriterPtr(new AttributesWriter(cp, obj, iDag, |
118 iTimeIndex, iWriteVisibility, iForceStatic)); | 130 iTimeIndex, iArgs)); |
| 131 |
119 | 132 |
120 write(); | 133 write(); |
121 } | 134 } |
122 | 135 |
123 unsigned int MayaNurbsCurveWriter::getNumCVs() | 136 unsigned int MayaNurbsCurveWriter::getNumCVs() |
124 { | 137 { |
125 return mCVCount; | 138 return mCVCount; |
126 } | 139 } |
127 | 140 |
128 unsigned int MayaNurbsCurveWriter::getNumCurves() | 141 unsigned int MayaNurbsCurveWriter::getNumCurves() |
(...skipping 18 matching lines...) Expand all Loading... |
147 | 160 |
148 // if inheritTransform is on and the curve group is animated, | 161 // if inheritTransform is on and the curve group is animated, |
149 // bake the cv positions in the world space | 162 // bake the cv positions in the world space |
150 MMatrix exclusiveMatrixInv = mRootDagPath.exclusiveMatrixInverse(&stat); | 163 MMatrix exclusiveMatrixInv = mRootDagPath.exclusiveMatrixInverse(&stat); |
151 | 164 |
152 std::size_t numCurves = 1; | 165 std::size_t numCurves = 1; |
153 | 166 |
154 if (mIsCurveGrp) | 167 if (mIsCurveGrp) |
155 numCurves = mNurbsCurves.length(); | 168 numCurves = mNurbsCurves.length(); |
156 | 169 |
157 std::vector<Alembic::Util::uint32_t> nVertices(numCurves); | 170 std::vector<Alembic::Util::int32_t> nVertices(numCurves); |
158 std::vector<float> points; | 171 std::vector<float> points; |
159 std::vector<float> width; | 172 std::vector<float> width; |
160 | 173 |
161 MMatrix transformMatrix; | 174 MMatrix transformMatrix; |
162 bool useConstWidth = false; | 175 bool useConstWidth = false; |
163 | 176 |
164 MFnDependencyNode dep(mRootDagPath.transform()); | 177 MFnDependencyNode dep(mRootDagPath.transform()); |
165 MPlug constWidthPlug = dep.findPlug("constantwidth"); | 178 MPlug constWidthPlug = dep.findPlug("constantwidth"); |
166 | 179 |
167 if (!constWidthPlug.isNull()) | 180 if (!constWidthPlug.isNull()) |
(...skipping 28 matching lines...) Expand all Loading... |
196 if (curve.degree() == 3) | 209 if (curve.degree() == 3) |
197 { | 210 { |
198 samp.setType(Alembic::AbcGeom::kCubic); | 211 samp.setType(Alembic::AbcGeom::kCubic); |
199 } | 212 } |
200 else | 213 else |
201 { | 214 { |
202 samp.setType(Alembic::AbcGeom::kLinear); | 215 samp.setType(Alembic::AbcGeom::kLinear); |
203 } | 216 } |
204 } | 217 } |
205 | 218 |
206 Alembic::Util::uint32_t numCVs = curve.numCVs(&stat); | 219 Alembic::Util::int32_t numCVs = curve.numCVs(&stat); |
207 nVertices[i] = numCVs; | 220 nVertices[i] = numCVs; |
208 mCVCount += numCVs; | 221 mCVCount += numCVs; |
209 | 222 |
210 MPointArray cvArray; | 223 MPointArray cvArray; |
211 stat = curve.getCVs(cvArray, MSpace::kObject); | 224 stat = curve.getCVs(cvArray, MSpace::kObject); |
212 for (size_t j = 0; j < numCVs; j++) | 225 for (size_t j = 0; j < numCVs; j++) |
213 { | 226 { |
214 MPoint transformdPt; | 227 MPoint transformdPt; |
215 if (mIsCurveGrp) | 228 if (mIsCurveGrp) |
216 transformdPt = cvArray[j]*transformMatrix; | 229 transformdPt = cvArray[j]*transformMatrix; |
217 else | 230 else |
218 transformdPt = cvArray[j]; | 231 transformdPt = cvArray[j]; |
219 | 232 |
220 points.push_back(transformdPt.x); | 233 points.push_back(transformdPt.x); |
221 points.push_back(transformdPt.y); | 234 points.push_back(transformdPt.y); |
222 points.push_back(transformdPt.z); | 235 points.push_back(transformdPt.z); |
223 } | 236 } |
224 | 237 |
225 // width | 238 // width |
226 MPlug widthPlug = curve.findPlug("width"); | 239 MPlug widthPlug = curve.findPlug("width"); |
227 | 240 |
228 if (!useConstWidth && !widthPlug.isNull()) | 241 if (!useConstWidth && !widthPlug.isNull()) |
229 { | 242 { |
230 MObject widthObj; | 243 MObject widthObj; |
231 MStatus status = widthPlug.getValue(widthObj); | 244 MStatus status = widthPlug.getValue(widthObj); |
232 MFnDoubleArrayData fnDoubleArrayData(widthObj, &status); | 245 MFnDoubleArrayData fnDoubleArrayData(widthObj, &status); |
233 MDoubleArray doubleArrayData = fnDoubleArrayData.array(); | 246 MDoubleArray doubleArrayData = fnDoubleArrayData.array(); |
234 size_t arraySum = doubleArrayData.length(); | 247 size_t arraySum = doubleArrayData.length(); |
235 size_t correctVecLen = arraySum; | 248 size_t correctVecLen = arraySum; |
236 //if (samp.getForm() == 0) | |
237 // correctVecLen += 1; | |
238 if (arraySum == correctVecLen) | 249 if (arraySum == correctVecLen) |
239 { | 250 { |
240 for (size_t i = 0; i < arraySum; i++) | 251 for (size_t i = 0; i < arraySum; i++) |
241 { | 252 { |
242 width.push_back(doubleArrayData[i]); | 253 width.push_back(doubleArrayData[i]); |
243 } | 254 } |
244 } | 255 } |
245 else | 256 else |
246 { | 257 { |
247 MString msg = "Curve "; | 258 MString msg = "Curve "; |
248 msg += curve.partialPathName(); | 259 msg += curve.partialPathName(); |
249 msg += " has incorrect size for the width vector."; | 260 msg += " has incorrect size for the width vector."; |
250 msg += "\nUsing default constantwidth."; | 261 msg += "\nUsing default constantwidth."; |
251 MGlobal::displayWarning(msg); | 262 MGlobal::displayWarning(msg); |
252 | 263 |
253 width.clear(); | 264 width.clear(); |
254 width.push_back(0.1); | 265 width.push_back(0.1); |
255 useConstWidth = true; | 266 useConstWidth = true; |
256 } | 267 } |
257 } | 268 } |
258 else | 269 else |
259 { | 270 { |
260 // pick a default value | 271 // pick a default value |
261 width.clear(); | 272 width.clear(); |
262 width.push_back(0.1); | 273 width.push_back(0.1); |
263 useConstWidth = true; | 274 useConstWidth = true; |
264 } | 275 } |
265 } | 276 } |
266 | 277 |
267 samp.setCurvesNumVertices(Alembic::Abc::UInt32ArraySample(nVertices)); | 278 Alembic::AbcGeom::GeometryScope scope = Alembic::AbcGeom::kVertexScope; |
| 279 if (useConstWidth) |
| 280 scope = Alembic::AbcGeom::kConstantScope; |
| 281 |
| 282 samp.setCurvesNumVertices(Alembic::Abc::Int32ArraySample(nVertices)); |
268 samp.setPositions(Alembic::Abc::V3fArraySample( | 283 samp.setPositions(Alembic::Abc::V3fArraySample( |
269 (const Imath::V3f *)&points.front(), points.size() / 3 )); | 284 (const Imath::V3f *)&points.front(), points.size() / 3 )); |
270 samp.setWidths(Alembic::Abc::FloatArraySample(width)); | 285 samp.setWidths(Alembic::AbcGeom::OFloatGeomParam::Sample( |
| 286 Alembic::Abc::FloatArraySample(width), scope) ); |
271 mSchema.set(samp); | 287 mSchema.set(samp); |
272 } | 288 } |
OLD | NEW |