-
Notifications
You must be signed in to change notification settings - Fork 18
/
MFnDagNode.inl
419 lines (316 loc) · 14.4 KB
/
MFnDagNode.inl
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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
#define _doc_create R"pbdoc(create(type, name=None, parent=MObject.kNullObj) -> MObject\
\
Creates a new DAG node of the specified type, with the given name.\
The type may be either a type name or a type ID. If no name is given\
then a unique name will be generated by combining the type name with\
an integer.\
\
If a parent is given then the new node will be parented under it and\
the functionset will be attached to the newly-created node. The\
newly-created node will be returned.\
\
If no parent is given and the new node is a transform, it will be\
parented under the world and the functionset will be attached to the\
newly-created transform. The newly-created transform will be returned.\
\
If no parent is given and the new node is not a transform then a\
transform node will be created under the world, the new node will be\
parented under it, and the functionset will be attached to the\
transform. The transform will be returned.)pbdoc"
#define _doc_addChild R"pbdoc(addChild(child, index=FnDagNode.kNextPos, keepExistingParents=False)\
\
Makes this node a parent of `child`.)pbdoc"
#define _doc_child R"pbdoc(child(index) -> MObject\
\
Returns the specified child of this node.)pbdoc"
#define _doc_childCount R"pbdoc(childCount() -> int\
\
Returns the number of nodes which are children of this one.)pbdoc"
#define _doc_getConnectedSetsAndMembers R"pbdoc(getConnectedSetsAndMembers(instance, renderableSetsOnly) -> (MObjectArray, MObjectArray)\
\
Returns a tuple containing an array of sets and an array of the\
components of the DAG object which are in those sets. If the entire object is in a set, then the corresponding entry in the comps array will have no elements in it.\
)pbdoc"
#define _doc_dagPath R"pbdoc(dagPath() -> MDagPath\
\
Returns the DAG path to which this function set is attached. Raises a TypeError if the function set is attached to an MObject rather than a path.)pbdoc"
#define _doc_dagRoot R"pbdoc(dagRoot() -> MObject\
\
Returns the root node of the first path leading to this node.)pbdoc"
#define _doc_duplicate R"pbdoc(duplicate(instance=False, instanceLeaf=False) -> MObject\
\
Duplicates the DAG hierarchy rooted at the current node.)pbdoc"
#define _doc_fullPathName R"pbdoc(fullPathName() -> string\
\
Returns the full path of the attached object, from the root of the DAG on down.)pbdoc"
#define _doc_getAllPaths R"pbdoc(getAllPaths() -> MDagPathArray\
\
Returns all of the DAG paths which lead to the object to which this function set is attached.)pbdoc"
#define _doc_getPath R"pbdoc(getPath() -> MDagPath\
\
Returns the DAG path to which this function set is attached, or the first path to the node if the function set is attached to an MObject.)pbdoc"
#define _doc_hasChild R"pbdoc(hasChild(node) -> bool\
\
Returns True if the specified node is a child of this one.)pbdoc"
#define _doc_hasParent R"pbdoc(hasParent(node) -> bool\
\
Returns True if the specified node is a parent of this one.)pbdoc"
#define _doc_instanceCount R"pbdoc(instanceCount(indirect) -> int\
\
Returns the number of instances for this node.)pbdoc"
#define _doc_isChildOf R"pbdoc(isChildOf(node) -> bool\
\
Returns True if the specified node is a parent of this one.)pbdoc"
#define _doc_isInstanced R"pbdoc(isInstanced(indirect=True) -> bool\
\
Returns True if this node is instanced.)pbdoc"
#define _doc_isInstancedAttribute R"pbdoc(isInstancedAttribute(attr) -> bool\
\
Returns True if the specified attribute is an instanced attribute of this node.)pbdoc"
#define _doc_isParentOf R"pbdoc(isParentOf(node) -> bool\
\
Returns True if the specified node is a child of this one.)pbdoc"
#define _doc_parent R"pbdoc(parent(index) -> MObject\
\
Returns the specified parent of this node.)pbdoc"
#define _doc_parentCount R"pbdoc(parentCount() -> int\
\
Returns the number of parents this node has.)pbdoc"
#define _doc_partialPathName R"pbdoc(partialPathName() -> string\
\
Returns the minimum path string necessary to uniquely identify the attached object.)pbdoc"
#define _doc_removeChild R"pbdoc(removeChild(node) -> self\
\
Removes the child, specified by MObject, reparenting it under the world.)pbdoc"
#define _doc_removeChildAt R"pbdoc(removeChildAt(index) -> self\
\
Removes the child, specified by index, reparenting it under the world.)pbdoc"
#define _doc_setObject R"pbdoc(setObject(MObject or MDagPath) -> self\
\
Attaches the function set to the specified node or DAG path.)pbdoc"
#define _doc_setObject R"pbdoc(setObject(MObject or MDagPath) -> self\
\
Attaches the function set to the specified node or DAG path.)pbdoc"
#define _doc_transformationMatrix R"pbdoc(transformationMatrix() -> MMatrix\
\
Returns the object space transformation matrix for this DAG node.)pbdoc"
py::class_<MFnDagNode>(m, "FnDagNode")
.def_property_readonly_static("kNextPos", [](py::object /* self */) {
return static_cast<unsigned int>(MFnDagNode::kNextPos);
})
.def(py::init<>())
.def(py::init([](MObject& object) {
MStatus status;
MFnDagNode fn { object, &status };
if (!status) {
throw std::runtime_error(
"Invalid parameter passed for object - "
"not a DAG Node, "
"Node does not exist or "
"no valid pointer to Node"
);
}
return std::unique_ptr<MFnDagNode>(new MFnDagNode(object));
}))
.def(py::init([](MDagPath& dagPath) {
MStatus status;
MFnDagNode fn { dagPath, &status };
if (!status) {
throw std::runtime_error(
"Invalid parameter passed for object - "
"not a DAG Node, "
"Node does not exist or "
"no valid pointer to Node"
);
}
return std::unique_ptr<MFnDagNode>(new MFnDagNode(dagPath));
}))
.def("__repr__", [](const MObject &a) {
return "<cmdc.FnDagNode()>";
})
.def("addChild", [](MFnDagNode& self,
MObject& child,
unsigned int index = static_cast<unsigned int>(MFnDagNode::kNextPos),
bool keepExistingParents = false) {
MStatus status = self.addChild(child, index, keepExistingParents);
if (!status) {
/**
* There are three know possible reasons this might not work.
*
*/
// 1. Not a valid pointer
if (child.isNull()) {
throw std::runtime_error("MObject was null.");
}
// 2. Not a DAG node
if (!child.hasFn(MFn::kDagNode)) {
MFnDagNode fn { child };
MString message = fn.partialPathName();
message += " was not a DAG node.";
throw std::runtime_error(message.asChar());
}
// 3. Node does not exist
MObjectHandle handle { child };
if (!(handle.isValid() && handle.isAlive())) {
throw std::runtime_error("MObject did not exist");
}
// 4. The docs don't say why this happens
throw std::runtime_error("Undefined error occurred");
}
}, py::arg("child"),
py::arg("index") = static_cast<unsigned int>(MFnDagNode::kNextPos),
py::arg("keepExistingParents") = false,
_doc_addChild)
.def("boundingBox", [](MFnDagNode& self) -> MBoundingBox {
return self.boundingBox();
}, R"pbdoc(Node's bounding box, in object space.)pbdoc")
.def("child", [](MFnDagNode& self, unsigned int i) -> MObject {
return self.child(i);
}, _doc_child)
.def("childCount", [](MFnDagNode& self) -> int {
return self.childCount();
}, _doc_childCount)
.def("create", [](MFnDagNode& self, std::string type, MObject parent = MObject::kNullObj) -> MObject {
return self.create(type.c_str(), parent);
}, py::arg("type"),
py::arg("parent") = MObject::kNullObj,
_doc_create)
.def("create", [](MFnDagNode& self, std::string type, std::string name, MObject parent = MObject::kNullObj) -> MObject {
return self.create(type.c_str(), name.c_str(), parent);
}, py::arg("type"),
py::arg("name"),
py::arg("parent") = MObject::kNullObj,
_doc_create)
.def("create", [](MFnDagNode& self, MTypeId typeId, MObject parent = MObject::kNullObj) -> MObject {
return self.create(typeId, parent);
}, py::arg("type"),
py::arg("parent") = MObject::kNullObj,
_doc_create)
.def("create", [](MFnDagNode& self, MTypeId typeId, std::string name, MObject parent = MObject::kNullObj) -> MObject {
return self.create(typeId, name.c_str(), parent);
}, py::arg("type"),
py::arg("name"),
py::arg("parent") = MObject::kNullObj,
_doc_create)
.def("dagPath", [](MFnDagNode& self) -> MDagPath {
return self.dagPath();
}, _doc_dagPath)
.def("dagRoot", [](MFnDagNode& self) -> MObject {
return self.dagRoot();
}, _doc_dagRoot)
.def("duplicate", [](MFnDagNode& self, bool instance = false, bool instanceLeaf = false) -> MObject {
return self.duplicate(instance, instanceLeaf);
}, py::arg("instance") = false,
py::arg("instanceLeaf") = false,
_doc_duplicate)
.def("fullPathName", [](MFnDagNode& self) -> std::string {
return self.fullPathName().asChar();
}, _doc_fullPathName)
.def("getAllPaths", [](MFnDagNode& self) -> MDagPathArray {
// Need MDagPathArray
throw std::logic_error{"Function not yet implemented."};
}, _doc_getAllPaths)
.def("getConnectedSetsAndMembers", [](MFnDagNode& self, unsigned int instanceNumber, bool renderableSetsOnly) -> std::tuple<MObjectArray, MObjectArray> {
// Need std::tuple<MObjectArray, MObjectArray>
throw std::logic_error{"Function not yet implemented."};
}, _doc_getConnectedSetsAndMembers)
.def("getPath", [](MFnDagNode& self) -> MDagPath {
MDagPath path;
const MStatus status = self.getPath(path);
if (!status) {
throw std::runtime_error(
"No valid DAG Node attached to Function Set"
);
}
return path;
}, _doc_getPath)
.def("hasChild", [](MFnDagNode& self, MObject node) -> bool {
return self.hasChild(node);
}, py::arg("node"), _doc_hasChild)
.def("hasParent", [](MFnDagNode& self, MObject node) -> bool {
return self.hasParent(node);
}, py::arg("node"), _doc_hasParent)
.def("inModel", [](MFnDagNode& self) -> bool {
return self.inModel();
}, R"pbdoc(True if the node has been added to the model.)pbdoc")
.def("inUnderWorld", [](MFnDagNode& self) -> bool {
return self.inUnderWorld();
}, R"pbdoc(True if this node is in the underworld of another node (e.g. a curve on surface is in the underworld of the surface).)pbdoc")
.def("instanceCount", [](MFnDagNode& self, bool total) -> int {
return self.instanceCount(total);
}, py::arg("total"), _doc_instanceCount)
.def("isChildOf", [](MFnDagNode& self, MObject node) -> bool {
return self.isChildOf(node);
}, py::arg("node"), _doc_isChildOf)
.def("isInstanceable", [](MFnDagNode& self) -> bool {
return self.isInstanceable();
}, R"pbdoc(True if instancing is allowed for this node.)pbdoc")
.def("isInstanced", [](MFnDagNode& self, bool indirect = true) -> bool {
return self.isInstanced(indirect);
}, py::arg("indirect"), _doc_isInstanced)
.def("isInstancedAttribute", [](MFnDagNode& self, MObject attr) -> bool {
return self.isInstancedAttribute(attr);
}, py::arg("attr"), _doc_isInstancedAttribute)
.def("isIntermediateObject", [](MFnDagNode& self) -> bool {
return self.isIntermediateObject();
}, R"pbdoc(True if this node is just an intermediate in part of a larger calculation (e.g. input to a deformer).)pbdoc")
.def("isParentOf", [](MFnDagNode& self, MObject node) -> bool {
return self.isParentOf(node);
}, py::arg("node"), _doc_isParentOf)
.def("objectColorRGB", [](MFnDagNode& self) -> MColor {
return self.objectColorRGB();
}, R"pbdoc(RGB value indicating the color in which the node is to be drawn when inactive, assuming that it is drawable.)pbdoc")
.def("objectColorType", [](MFnDagNode& self) -> MFnDagNode::MObjectColorType {
return self.objectColorType();
}, R"pbdoc(Determines whether the default color, indexed object color, orRGB object color is used for this object.)pbdoc")
.def("parent", [](MFnDagNode& self, unsigned int i) -> MObject {
return self.parent(i);
}, _doc_parent)
.def("parentCount", [](MFnDagNode& self) -> int {
return self.parentCount();
}, _doc_parentCount)
.def("partialPathName", [](MFnDagNode& self) -> std::string {
return self.partialPathName().asChar();
}, _doc_partialPathName)
.def("removeChild", [](MFnDagNode& self, MObject& child) -> void {
MStatus status = self.removeChild(child);
if (status == MStatus::kSuccess) { return; }
else if (status == MStatus::kInvalidParameter) {
throw std::runtime_error(
"Invalid parameter passed as child - not a DAG Node, Node does not exist or no valid pointer to Nod"
);
}
else if (status == MStatus::kFailure) {
throw std::runtime_error(
"No valid DAG Node attached to Function Set"
);
}
else {
throw std::runtime_error(
"Unknown error occurred."
);
}
}, _doc_removeChild)
.def("removeChildAt", [](MFnDagNode& self, unsigned int index) {
return self.removeChildAt(index);
}, py::arg("index"), _doc_removeChildAt)
.def("setObject", [](MFnDagNode& self, MObject& object) -> void {
if (!self.setObject(object)) throw std::runtime_error(
"Invalid parameter passed for node - "
"not a DAG Node, "
"Node does not exist or "
"no valid pointer to Node"
);
}, _doc_setObject)
.def("setObject", [](MFnDagNode& self, MDagPath path) {
if (!self.setObject(path)) throw std::runtime_error(
"Invalid parameter passed for objectPath - "
"invalid Path or "
"target Node is not a DAG Node, "
"does not exist or "
"has no accessible pointer "
);
}, py::arg("path"), _doc_setObject)
.def("transformationMatrix", [](MFnDagNode& self) -> MMatrix {
return self.transformationMatrix();
}, _doc_transformationMatrix);