-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathverticesMapperNode.cpp
354 lines (286 loc) · 9.79 KB
/
verticesMapperNode.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
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
//
// Copyright (C) cedric BAZILLOU
//
// File: verticesMapperNode.cpp
//
// Dependency Graph Node: verticesMapper
//
// 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>
class verticesMapper : public MPxNode
{
public:
verticesMapper();
virtual ~verticesMapper();
virtual MStatus compute( const MPlug& plug, MDataBlock& data );
static void* creator();
static MStatus initialize();
public:
static MObject inputCurve;
static MObject inputSurface;
static MObject inMesh;
static MObject weightList;
static MObject weights;
static MObject bindMode;
static MObject weightMode;
static MObject rampWeight;
static MObject rampColor;
static MObject inputColor;
static MObject weightDriver;
static MTypeId id;
bool verticesMapper::InputShape_Connected ( MObject & inputMeshObj );
void verticesMapper::compute_spline_u_mapping( MFnNurbsCurve & incurveFn, MPointArray & inPnts_List , MFloatArray & uvMap_List);
};
MTypeId verticesMapper::id( 0x452AA21 );
MObject verticesMapper::inputCurve;
MObject verticesMapper::inputSurface;
MObject verticesMapper::inMesh;
MObject verticesMapper::weightList;
MObject verticesMapper::weights;
MObject verticesMapper::bindMode;
MObject verticesMapper::weightMode;
MObject verticesMapper::rampWeight;
MObject verticesMapper::rampColor;
MObject verticesMapper::inputColor;
MObject verticesMapper::weightDriver;
verticesMapper::verticesMapper() {}
verticesMapper::~verticesMapper() {}
bool verticesMapper::InputShape_Connected ( MObject & inputMeshObj )
{
bool inputMeshConnected = false;
if (inputMeshObj.isNull() == false )
{
inputMeshConnected = true;
}
return inputMeshConnected;
}
void verticesMapper::compute_spline_u_mapping( MFnNurbsCurve & incurveFn, MPointArray & inPnts_List , MFloatArray & uvMap_List)
{
double param = 0.0;
MPoint clsPnt;
double spanNum = incurveFn.numSpans()*1.0;
for ( unsigned k=0; k<uvMap_List.length();++k)
{
clsPnt = incurveFn.closestPoint(inPnts_List[k],¶m,0.00001,MSpace::kObject);
uvMap_List.set(param/spanNum,k);
}
}
MStatus verticesMapper::compute( const MPlug& plug, MDataBlock& data )
{
MStatus returnStatus;
if( plug == weightList || plug.parent() == weights || plug == weights )
{
MDataHandle inputCurveHandle = data.inputValue(inputCurve,&returnStatus);
MDataHandle inputSurfaceHandle = data.inputValue(inputSurface,&returnStatus);
MDataHandle inMeshHandle = data.inputValue(inMesh,&returnStatus);
MDataHandle bindModeHandle = data.inputValue(bindMode,&returnStatus);
MDataHandle weightModeHandle = data.inputValue(weightMode,&returnStatus);
MDataHandle weightListHandle = data.outputValue(weightList,&returnStatus);
MArrayDataHandle weightsHandle = data.outputArrayValue(weights,&returnStatus);
short bindMode_value = bindModeHandle.asShort();
short weightMode_value = weightModeHandle.asShort();
MObject inMeshObj = inMeshHandle.asMesh();
MObject inputCurveObj = inputCurveHandle.asNurbsCurve();
MObject inputSurfaceObj = inputSurfaceHandle.asNurbsSurface();
bool checkMeshInput = InputShape_Connected(inMeshObj);
bool checkcurveInput = InputShape_Connected(inputCurveObj);
bool checkSurfaceInput = InputShape_Connected(inputSurfaceObj);
cout << checkMeshInput << checkcurveInput << checkSurfaceInput;
MObject thisNode = thisMObject();
MRampAttribute rampWeightData(thisNode, rampWeight );
MRampAttribute rampColorData(thisNode, rampColor );
if ( checkMeshInput == false ) // Before computing data from the current binding method we at the minimum required that an input mesh flow in this node
{
return MS::kUnknownParameter;
} else {
MFnMesh inMeshFn(inMeshObj);
MPointArray inPnts_List ;
MDoubleArray vertexWeigths ;
inMeshFn.getPoints( inPnts_List, MSpace::kObject );
unsigned int vecLength = inPnts_List.length();
vertexWeigths.clear();
vertexWeigths.setLength(vecLength);
if ( bindMode_value == 0)// Curve bind Mode
{
if ( checkcurveInput == false )
{
return MS::kUnknownParameter;
} else {
MFnNurbsCurve incurveFn(inputCurveObj);
MFloatArray uvMap_List;
uvMap_List.clear();
uvMap_List.setLength(vecLength);
// in curve bind mode
compute_spline_u_mapping( incurveFn, inPnts_List , uvMap_List);
float rampVal = -1;
for ( unsigned k=0; k<vecLength;++k)
{
rampWeightData.getValueAtPosition(uvMap_List[k], rampVal );
vertexWeigths.set(rampVal,k);
}
MFnDoubleArrayData extractDoubleArrayFn;
MObject DoubleArrayObj = extractDoubleArrayFn.create(vertexWeigths) ;
weightListHandle.set(DoubleArrayObj) ;
weightListHandle.setClean();
//cout << "\n" << vertexWeigths;
}
}
if ( bindMode_value == 1)// surface bind Mode
{
if ( checkSurfaceInput == false )
{
return MS::kUnknownParameter;
} else {
///////////////////////
}
}
if ( bindMode_value == 2)// UV bind Mode
{
///
}
}
} else {
return MS::kUnknownParameter;
}
return MS::kSuccess;
}
void* verticesMapper::creator()
{
return new verticesMapper();
}
MStatus verticesMapper::initialize()
{
MFnNumericAttribute nAttr;
MFnTypedAttribute typed_Attr;
MFnEnumAttribute mode_Attr;
MStatus stat;
bindMode = mode_Attr.create( "bindMode", "bMd", 0 );
mode_Attr.addField("curve",0);
mode_Attr.addField("surface",1);
mode_Attr.addField("uv_map",2);
mode_Attr.setStorable(1);
mode_Attr.setKeyable(1);
mode_Attr.setHidden(0);
addAttribute(bindMode);
weightMode = mode_Attr.create( "weightMode", "wMd", 0 );
mode_Attr.addField("U_Propagation",0);
mode_Attr.addField("UV_Space",1);
mode_Attr.setStorable(1);
mode_Attr.setKeyable(1);
mode_Attr.setHidden(0);
addAttribute(weightMode);
weightDriver = mode_Attr.create( "weightDriver", "wDr", 0 );
mode_Attr.addField("curveRamp",0);
mode_Attr.addField("colorRamp",1);
mode_Attr.addField("texture",2);
mode_Attr.setStorable(1);
mode_Attr.setKeyable(1);
mode_Attr.setHidden(0);
addAttribute(weightDriver);
inputCurve = typed_Attr.create( "inputCurve", "inCrv", MFnNurbsCurveData::kNurbsCurve );
typed_Attr.setStorable(0);
typed_Attr.setKeyable(0);
typed_Attr.setHidden(1);
inputSurface = typed_Attr.create( "inputSurface", "inSrf", MFnNurbsSurfaceData::kNurbsSurface );
typed_Attr.setStorable(0);
typed_Attr.setKeyable(0);
typed_Attr.setHidden(1);
inMesh = typed_Attr.create( "inMesh", "in", MFnMeshData::kMesh);
typed_Attr.setStorable(0);
typed_Attr.setKeyable(0);
typed_Attr.setHidden(1);
MRampAttribute rmp_Attr ;
rampWeight = rmp_Attr.createCurveRamp ("rampWeight", "rWg") ;
rampColor = rmp_Attr.createColorRamp("rampColor", "rCl") ;
inputColor = nAttr.createColor( "inputColor", "iCl" );
nAttr.setDefault(0.0f, 1.0f, 0.0f);
nAttr.setKeyable(true);
nAttr.setStorable(true);
nAttr.setUsedAsColor(true);
nAttr.setReadable(true);
nAttr.setWritable(true);
weightList = typed_Attr.create( "weightList", "wLs",MFnData::kDoubleArray );
typed_Attr.setStorable(1);
typed_Attr.setWritable(false);
typed_Attr.setKeyable(0);
typed_Attr.setHidden(1) ;
weights = nAttr.create( "weights", "ws", MFnNumericData::kDouble, 0.0 );
nAttr.setWritable(false);
nAttr.setStorable(1);
nAttr.setArray(false);
nAttr.setUsesArrayDataBuilder(true);
nAttr.setConnectable(true) ;
nAttr.setHidden(1) ;
stat = addAttribute( inputCurve );
if (!stat) { stat.perror("fail to add inputCurve attribute"); return stat;}
stat = addAttribute( inputSurface );
if (!stat) { stat.perror("fail to add inputSurface attribute"); return stat;}
stat = addAttribute( inMesh );
if (!stat) { stat.perror("fail to add inMesh attribute"); return stat;}
stat = addAttribute( rampWeight );
if (!stat) { stat.perror("fail to add rampWeight attribute"); return stat;}
stat = addAttribute( rampColor );
if (!stat) { stat.perror("fail to add rampColor attribute"); return stat;}
stat = addAttribute( inputColor );
if (!stat) { stat.perror("fail to add inputColor attribute"); return stat;}
stat = addAttribute( weightList );
if (!stat) { stat.perror("fail to add weightList attribute"); return stat;}
stat = addAttribute( weights );
if (!stat) { stat.perror("fail to add weights attribute"); return stat;}
attributeAffects( inputCurve , weightList );
attributeAffects( inputSurface , weightList );
attributeAffects( inMesh , weightList );
attributeAffects( inputCurve , weights );
attributeAffects( inputSurface , weights );
attributeAffects( inMesh , weights );
return MS::kSuccess;
}
MStatus initializePlugin( MObject obj )
{
MStatus status;
MFnPlugin plugin( obj, "cedric BAZILLOU", "0.1", "Any");
status = plugin.registerNode( "verticesMapper", verticesMapper::id, verticesMapper::creator,
verticesMapper::initialize );
if (!status) {
status.perror("registerNode");
return status;
}
return status;
}
MStatus uninitializePlugin( MObject obj)
{
MStatus status;
MFnPlugin plugin( obj );
status = plugin.deregisterNode( verticesMapper::id );
if (!status) {
status.perror("deregisterNode");
return status;
}
return status;
}