-
Notifications
You must be signed in to change notification settings - Fork 60
/
InputMergeNode.C
157 lines (124 loc) · 4.84 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#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;
MObject InputMergeNode::packBeforeMerge;
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);
InputMergeNode::packBeforeMerge = nAttr.create(
"packBeforeMerge", "packBeforeMerge", MFnNumericData::kBoolean, false);
nAttr.setCached(false);
nAttr.setStorable(true);
addAttribute(InputMergeNode::packBeforeMerge);
attributeAffects(
InputMergeNode::inputTransform, InputMergeNode::outputNodeId);
attributeAffects(InputMergeNode::inputNode, InputMergeNode::outputNodeId);
attributeAffects(InputMergeNode::packBeforeMerge, InputMergeNode::outputNodeId);
return MStatus::kSuccess;
}
InputMergeNode::InputMergeNode() : myGeometryNodeId(-1) {}
InputMergeNode::~InputMergeNode()
{
if (!Util::theHAPISession.get())
return;
// the merge is a sop, so it will have a parent geo
// and an objectMerge to remove as well
HAPI_NodeInfo node_info;
HoudiniApi::GetNodeInfo(Util::theHAPISession.get(), myGeometryNodeId, &node_info);
if (node_info.parentId >= 0)
{
CHECK_HAPI(
HoudiniApi::DeleteNode(Util::theHAPISession.get(), node_info.parentId));
}
}
MStatus
InputMergeNode::compute(const MPlug &plug, MDataBlock &dataBlock)
{
if (myGeometryNodeId == -1)
{
Util::PythonInterpreterLock pythonInterpreterLock;
MFnDependencyNode mergeNodeFn(thisMObject());
MPlug frozenPlug = mergeNodeFn.findPlug("frozen", true);
bool frozen = frozenPlug.asBool();
if (!frozen)
{
CHECK_HAPI(HoudiniApi::CreateNode(Util::theHAPISession.get(), -1,
"Sop/merge", NULL, false,
&myGeometryNodeId));
if (!Util::statusCheckLoop())
{
DISPLAY_ERROR(
MString("Unexpected error when creating merge node."));
}
}
else
{
// if the node has been frozen ever since file open
// we don't create a merge or compute
return MStatus::kSuccess;
}
}
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(HoudiniApi::ConnectNodeInput(
Util::theHAPISession.get(), myGeometryNodeId, i, inputNode, 0));
}
// Get the object merges connected to this merge node
HAPI_NodeInfo mergeNodeInfo;
CHECK_HAPI(HoudiniApi::GetNodeInfo(Util::theHAPISession.get(),
myGeometryNodeId, &mergeNodeInfo));
MPlug packBeforeMergePlug(thisMObject(), InputMergeNode::packBeforeMerge);
bool packBeforeMerge = packBeforeMergePlug.asBool();
for (int i = 0; i < mergeNodeInfo.inputCount; i++)
{
HAPI_NodeId objectMergeId;
if (HoudiniApi::QueryNodeInput(Util::theHAPISession.get(), myGeometryNodeId,
i, &objectMergeId) != HAPI_RESULT_SUCCESS || objectMergeId < 0)
break;
CHECK_HAPI(HoudiniApi::SetParmIntValue(Util::theHAPISession.get(),
objectMergeId, "pack", 0, (int)packBeforeMerge));
}
MDataHandle outputNodeIdHandle =
dataBlock.outputValue(InputMergeNode::outputNodeId);
outputNodeIdHandle.setInt(myGeometryNodeId);
return MStatus::kSuccess;
}
return MPxNode::compute(plug, dataBlock);
}