forked from sideeffects/HoudiniEngineForMaya
-
Notifications
You must be signed in to change notification settings - Fork 0
/
InputMergeNode.C
133 lines (109 loc) · 3.42 KB
/
InputMergeNode.C
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
#include "InputMergeNode.h"
#include <maya/MFnMatrixAttribute.h>
#include <maya/MFnNumericAttribute.h>
#include "MayaTypeID.h"
#include "hapiutil.h"
#include "util.h"
MString InputMergeNode::typeName("houdiniInputMerge");
MTypeId InputMergeNode::typeId(MayaTypeID_HoudiniInputMergeNode);
MObject InputMergeNode::inputTransform;
MObject InputMergeNode::inputNode;
MObject InputMergeNode::outputNodeId;
void*
InputMergeNode::creator()
{
return new InputMergeNode();
}
MStatus
InputMergeNode::initialize()
{
MFnMatrixAttribute mAttr;
MFnNumericAttribute nAttr;
InputMergeNode::inputTransform = mAttr.create(
"inputTransform", "inputTransform"
);
addAttribute(InputMergeNode::inputTransform);
InputMergeNode::inputNode = nAttr.create(
"inputNode", "inputNode",
MFnNumericData::kInt,
-1
);
nAttr.setArray(true);
nAttr.setCached(false);
nAttr.setStorable(false);
addAttribute(InputMergeNode::inputNode);
InputMergeNode::outputNodeId = nAttr.create(
"outputNodeId", "outputNodeId",
MFnNumericData::kInt,
-1
);
nAttr.setCached(false);
nAttr.setStorable(false);
addAttribute(InputMergeNode::outputNodeId);
attributeAffects(InputMergeNode::inputTransform, InputMergeNode::outputNodeId);
attributeAffects(InputMergeNode::inputNode, InputMergeNode::outputNodeId);
return MStatus::kSuccess;
}
InputMergeNode::InputMergeNode() :
myGeometryNodeId(-1)
{
Util::PythonInterpreterLock pythonInterpreterLock;
CHECK_HAPI(HAPI_CreateNode(
Util::theHAPISession.get(),
-1,
"Sop/merge",
NULL,
false,
&myGeometryNodeId
));
if(!Util::statusCheckLoop())
{
DISPLAY_ERROR(MString("Unexpected error when creating merge node."));
}
}
InputMergeNode::~InputMergeNode()
{
// the merge is a sop, so it will have a parent geo
// and an objectMerge to remove as well
HAPI_NodeInfo node_info;
HAPI_GetNodeInfo(Util::theHAPISession.get(),
myGeometryNodeId,
&node_info);
if(node_info.parentId >= 0){
CHECK_HAPI(HAPI_DeleteNode(
Util::theHAPISession.get(),
node_info.parentId
));
}
}
MStatus
InputMergeNode::compute(
const MPlug &plug,
MDataBlock &dataBlock
)
{
if(plug == InputMergeNode::outputNodeId)
{
MArrayDataHandle inputNodeArrayHandle =
dataBlock.inputArrayValue(InputMergeNode::inputNode);
const unsigned int mergeCount = inputNodeArrayHandle.elementCount();
for(unsigned int i = 0; i < mergeCount; i++)
{
inputNodeArrayHandle.jumpToElement(i);
MDataHandle inputNodeHandle = inputNodeArrayHandle.inputValue();
HAPI_NodeId inputNode = inputNodeHandle.asInt();
CHECK_HAPI(HAPI_ConnectNodeInput(
Util::theHAPISession.get(),
myGeometryNodeId,
i,
inputNode,
0
));
}
MDataHandle outputNodeIdHandle =
dataBlock.outputValue(InputMergeNode::outputNodeId);
outputNodeIdHandle.setInt(myGeometryNodeId);
return MStatus::kSuccess;
}
return MPxNode::compute(plug, dataBlock);
}