-
Notifications
You must be signed in to change notification settings - Fork 59
/
InputCurve.C
151 lines (123 loc) · 4.3 KB
/
InputCurve.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
#include "InputCurve.h"
#include <sstream>
#include <maya/MDataBlock.h>
#include <maya/MFnNurbsCurve.h>
#include <maya/MMatrix.h>
#include <maya/MPointArray.h>
#include <HAPI/HAPI.h>
#include "util.h"
InputCurve::InputCurve() : Input()
{
Util::PythonInterpreterLock pythonInterpreterLock;
HAPI_NodeId nodeId;
CHECK_HAPI(HAPI_CreateNode(
Util::theHAPISession.get(), -1, "Sop/curve", NULL, false, &nodeId));
if (!Util::statusCheckLoop())
{
DISPLAY_ERROR(MString("Unexpected error when creating input curve."));
}
HAPI_GetNodeInfo(Util::theHAPISession.get(), nodeId, &myCurveNodeInfo);
setTransformNodeId(myCurveNodeInfo.parentId);
setGeometryNodeId(nodeId);
}
InputCurve::~InputCurve()
{
if (!Util::theHAPISession.get())
return;
HAPI_DeleteNode(Util::theHAPISession.get(), geometryNodeId());
}
InputCurve::AssetInputType
InputCurve::assetInputType() const
{
return Input::AssetInputType_Curve;
}
void
InputCurve::setInputGeo(MDataBlock &dataBlock, const MPlug &plug)
{
MDataHandle dataHandle = dataBlock.inputValue(plug);
MObject curveObj = dataHandle.asNurbsCurve();
if (curveObj.isNull())
{
return;
}
// find coords parm
std::vector<HAPI_ParmInfo> parms(myCurveNodeInfo.parmCount);
HAPI_GetParameters(Util::theHAPISession.get(), myCurveNodeInfo.id,
&parms[0], 0, myCurveNodeInfo.parmCount);
int typeParmIndex = Util::findParm(parms, "type");
int coordsParmIndex = Util::findParm(parms, "coords");
int orderParmIndex = Util::findParm(parms, "order");
int closeParmIndex = Util::findParm(parms, "close");
if (coordsParmIndex < 0 || coordsParmIndex < 0 || orderParmIndex < 0 ||
closeParmIndex < 0)
{
return;
}
const HAPI_ParmInfo &typeParm = parms[typeParmIndex];
const HAPI_ParmInfo &coordsParm = parms[coordsParmIndex];
const HAPI_ParmInfo &orderParm = parms[orderParmIndex];
const HAPI_ParmInfo &closeParm = parms[closeParmIndex];
MFnNurbsCurve curveFn(curveObj);
// type
{
const char *type = "nurbs";
if (curveObj.apiType() == MFn::kBezierCurveData)
{
type = "bezier";
}
HAPI_ParmChoiceInfo *choices =
new HAPI_ParmChoiceInfo[typeParm.choiceCount];
HAPI_GetParmChoiceLists(Util::theHAPISession.get(), myCurveNodeInfo.id,
choices, typeParm.choiceIndex,
typeParm.choiceCount);
int nurbsIdx = -1;
for (int i = 0; i < typeParm.choiceCount; i++)
{
if (Util::HAPIString(choices[i].valueSH) == type)
{
nurbsIdx = i;
break;
}
}
delete[] choices;
if (nurbsIdx < 0)
{
return;
}
HAPI_SetParmIntValues(Util::theHAPISession.get(), myCurveNodeInfo.id,
&nurbsIdx, typeParm.intValuesIndex, 1);
}
// coords
{
MPointArray cvs;
curveFn.getCVs(cvs);
// Maya has curveFn.degree() more cvs in it's data definition
// than houdini for periodic curves--but they are conincident
// with the first ones. Houdini ignores them, so we don't
// output them.
int num_houdini_cvs = cvs.length();
if (curveFn.form() == MFnNurbsCurve::kPeriodic)
num_houdini_cvs -= curveFn.degree();
std::ostringstream coords;
for (unsigned int i = 0; i < (unsigned int)num_houdini_cvs; i++)
{
const MPoint &pt = cvs[i];
coords << pt.x << "," << pt.y << "," << pt.z << " ";
}
HAPI_SetParmStringValue(Util::theHAPISession.get(), myCurveNodeInfo.id,
coords.str().c_str(), coordsParm.id,
coordsParm.stringValuesIndex);
}
// order
{
int order = curveFn.degree() + 1;
HAPI_SetParmIntValues(Util::theHAPISession.get(), myCurveNodeInfo.id,
&order, orderParm.intValuesIndex, 1);
}
// periodicity
{
int close = curveFn.form() == MFnNurbsCurve::kPeriodic;
HAPI_SetParmIntValues(Util::theHAPISession.get(), myCurveNodeInfo.id,
&close, closeParm.intValuesIndex, 1);
}
}