-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathvertexBlendNode.cpp
259 lines (194 loc) · 6.01 KB
/
vertexBlendNode.cpp
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
//
// Copyright (C) cedric BAZILLOU
//
// File: vertexBlendNode.cpp
//
// Dependency Graph Node: vertexBlend
//
// Author: Maya Plug-in Wizard 2.0
//
#include <string.h>
#include <maya/MIOStream.h>
#include <math.h>
#include <maya/MPlug.h>
#include <maya/MDataBlock.h>
#include <maya/MDataHandle.h>
#include <maya/MArrayDataHandle.h>
#include <maya/MGlobal.h>
#include <maya/MPxNode.h>
#include <maya/MFnNumericAttribute.h>
#include <maya/MTypeId.h>
#include <maya/MFnPlugin.h>
#include <maya/MFnTypedAttribute.h>
#include <maya/MFnNurbsCurveData.h>
#include <maya/MFnNurbsSurfaceData.h>
#include <maya/MFnMeshData.h>
#include <maya/MFnData.h>
#include <maya/MFnEnumAttribute.h>
#include <maya/MFnMesh.h>
#include <maya/MRampAttribute.h>
#include <maya/MPointArray.h>
#include <maya/MPoint.h>
#include <maya/MFnNurbsCurve.h>
#include <maya/MFloatArray.h>
#include <maya/MDoubleArray.h>
#include <maya/MFnDoubleArrayData.h>
#include <maya/MArrayDataBuilder.h>
#include <maya/MFnCompoundAttribute.h>
#include <maya/MFnMeshData.h>
class vertexBlend : public MPxNode
{
public:
vertexBlend();
virtual ~vertexBlend();
virtual MStatus compute( const MPlug& plug, MDataBlock& data );
static void* creator();
static MStatus initialize();
public:
static MObject inMesh;
static MObject targetMesh;
static MObject outMesh;
static MObject weightList;
static MTypeId id;
bool vertexBlend::InputShape_Connected ( MObject & inputMeshObj );
};
MTypeId vertexBlend::id( 0x454AA23 );
MObject vertexBlend::inMesh;
MObject vertexBlend::targetMesh;
MObject vertexBlend::outMesh;
MObject vertexBlend::weightList;
vertexBlend::vertexBlend() {}
vertexBlend::~vertexBlend() {}
bool vertexBlend::InputShape_Connected ( MObject & inputMeshObj )
{
bool inputMeshConnected = false;
if (inputMeshObj.isNull() == false )
{
inputMeshConnected = true;
}
return inputMeshConnected;
}
MStatus vertexBlend::compute( const MPlug& plug, MDataBlock& data )
{
MStatus returnStatus;
if( plug == outMesh )
{
MDataHandle inMeshHandle = data.inputValue(inMesh,&returnStatus);
MDataHandle targetMeshHandle = data.inputValue(targetMesh,&returnStatus);
MDataHandle weightListHandle = data.inputValue(weightList,&returnStatus);
MDataHandle outMeshHandle = data.outputValue(outMesh,&returnStatus);
MObject inMeshObj = inMeshHandle.data();
MObject targetMeshObj = targetMeshHandle.data();
MObject weightListObj = weightListHandle.data();
bool check_inMesh = InputShape_Connected(inMeshObj);
bool check_targetMesh = InputShape_Connected(targetMeshObj);
bool check_weightList = InputShape_Connected(weightListObj);
MFnDoubleArrayData extractDoubleArrayFn;
if ( check_inMesh == true &&check_targetMesh == true && check_weightList == true )
{
MDoubleArray vertexWeigths;
vertexWeigths.clear();
extractDoubleArrayFn.setObject(weightListObj);
vertexWeigths = extractDoubleArrayFn.array();
MFnMesh inMeshFn(inMeshObj);
MFnMesh trgMeshFn(targetMeshObj);
MPointArray inPnts_List;
MPointArray trgPnts_List;
MVectorArray ofssetlist;
inMeshFn.getPoints( inPnts_List,MSpace::kObject );
trgMeshFn.getPoints( trgPnts_List,MSpace::kObject ) ;
unsigned int vecLength = inPnts_List.length();
if ( vertexWeigths.length() != vecLength)
{
MGlobal::displayError("\n****************** InputMesh and vertexWeigths dont have the same number of elements..." );
return MS::kUnknownParameter;
} else {
if ( trgPnts_List.length() != vecLength)
{
MGlobal::displayError("\n****************** InputMesh and target mesh dont have the same number of points..." );
return MS::kUnknownParameter;
} else {
ofssetlist.setLength(vecLength);
for ( unsigned k=0; k< vecLength;++k)
{
ofssetlist.set(trgPnts_List[k]-inPnts_List[k],k);
}
MFnMesh ouputMeshFn;
MFnMeshData meshDataFn ;
MObject newMeshObj = meshDataFn.create() ;
ouputMeshFn.copy( inMeshObj, newMeshObj ) ;
MPointArray trgPnts_ListB ;
trgPnts_ListB.setLength(vecLength);
for ( unsigned k=0; k< vecLength;++k)
{
trgPnts_ListB.set( inPnts_List[k]+ofssetlist[k]*vertexWeigths[k] , k);
}
ouputMeshFn.setPoints( trgPnts_ListB, MSpace::kObject ) ;
outMeshHandle.set(newMeshObj);
data.setClean(plug);
}
}
}
} else {
return MS::kUnknownParameter;
}
return MS::kSuccess;
}
void* vertexBlend::creator()
{
return new vertexBlend();
}
MStatus vertexBlend::initialize()
{
MFnNumericAttribute nAttr;
MFnTypedAttribute typed_Attr;
MFnEnumAttribute mode_Attr;
MStatus stat;
inMesh = typed_Attr.create( "inMesh", "in", MFnMeshData::kMesh);
typed_Attr.setStorable(0);
typed_Attr.setKeyable(0);
typed_Attr.setHidden(1);
targetMesh = typed_Attr.create( "targetMesh", "trg", MFnMeshData::kMesh);
typed_Attr.setStorable(0);
typed_Attr.setKeyable(0);
typed_Attr.setHidden(1);
outMesh = typed_Attr.create( "outMesh", "ou", MFnMeshData::kMesh);
typed_Attr.setStorable(0);
typed_Attr.setKeyable(0);
typed_Attr.setHidden(1);
weightList = typed_Attr.create( "weightList", "wLs",MFnData::kDoubleArray );
typed_Attr.setStorable(1);
typed_Attr.setKeyable(0);
typed_Attr.setHidden(1) ;
addAttribute( weightList );
addAttribute( inMesh );
addAttribute( targetMesh );
addAttribute( outMesh );
attributeAffects( weightList , outMesh );
attributeAffects( inMesh ,outMesh );
attributeAffects( targetMesh ,outMesh );
return MS::kSuccess;
}
MStatus initializePlugin( MObject obj )
{
MStatus status;
MFnPlugin plugin( obj, "cedric BAZILLOU", "0.1", "Any");
status = plugin.registerNode( "vertexBlend", vertexBlend::id, vertexBlend::creator,
vertexBlend::initialize );
if (!status) {
status.perror("registerNode");
return status;
}
return status;
}
MStatus uninitializePlugin( MObject obj)
{
MStatus status;
MFnPlugin plugin( obj );
status = plugin.deregisterNode( vertexBlend::id );
if (!status) {
status.perror("deregisterNode");
return status;
}
return status;
}