-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcurvesGenNode.cpp
More file actions
196 lines (148 loc) · 5.17 KB
/
curvesGenNode.cpp
File metadata and controls
196 lines (148 loc) · 5.17 KB
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
//
// Copyright (C) hdd
//
// File: curvesGenNode.cpp
//
// Dependency Graph Node: curvesGen
//
// Author: Maya Plug-in Wizard 2.0
//
#include "curvesGenNode.h"
#include <cstdlib>
#include <cmath>
#include <maya/MPlug.h>
#include <maya/MDataBlock.h>
#include <maya/MDataHandle.h>
#include <maya/MArrayDataHandle.h>
#include <maya/MGlobal.h>
#include <maya/MFnTypedAttribute.h>
#include <maya/MFnMatrixAttribute.h>
#include <maya/MFnNurbsCurve.h>
#include <maya/MTransformationMatrix.h>
#include <maya/MMatrix.h>
#include <maya/MPoint.h>
#include <maya/MPointArray.h>
#include <maya/MFnNurbsCurveData.h>
#define PI 3.14159265
//#error change the following to a unique value and then erase this line
MTypeId curvesGen::id( 0x87005 );
MObject curvesGen::curvesInput;
MObject curvesGen::curvesOutput;
MObject curvesGen::numCurves;
MObject curvesGen::degree;
MPointArray curvesGen::PP;
curvesGen::curvesGen() {}
curvesGen::~curvesGen() {}
MStatus curvesGen::compute( const MPlug& plug, MDataBlock& data )
{
MStatus returnStatus;
if( plug == curvesOutput )
{
curvesGen::MPointArrayVector.clear();
curvesGen::FinalMPointArray.clear();
MArrayDataHandle inputCurvesData = data.inputArrayValue( curvesInput, &returnStatus );
MDataHandle inputNumCurvesData = data.inputValue( numCurves, &returnStatus );
MDataHandle degreeData = data.inputValue( degree, &returnStatus );
MArrayDataHandle outputCurvesData = data.outputArrayValue(curvesOutput,&returnStatus );
int numP = inputNumCurvesData.asInt();
int numCurves = inputCurvesData.elementCount();
int deg = degreeData.asInt();
if (PP.length() != numP){
PP=distributePoints(numP);
}
for (int i=0;i<numCurves;i++){
inputCurvesData.jumpToElement(i);
MDataHandle curveH = inputCurvesData.inputValue();
MMatrix curveM = curveH.asMatrix();
MPointArray PPM;
for (int p =0; p< PP.length();p++){
MPoint PM = PP[p]*curveM;
PPM.append(PM);
}
MPointArrayVector.push_back(PPM);
}
for (unsigned int j=0;j < curvesGen::MPointArrayVector.size();j++){
for (int k=0; k<numP ;k++){
MPoint finalP= MPointArrayVector[j][k];
curvesGen::FinalMPointArray.append(finalP);
}
}
for (int p=0;p<numP;p++){
MPointArray tmpArray;
for (int c=0; c < numCurves; c++){
tmpArray.append(FinalMPointArray[c*numP+p]);
}
MFnNurbsCurveData curveCreator;
MObject finalCurve = curveCreator.create();
MFnNurbsCurve finalCurveFn;
finalCurveFn.createWithEditPoints(tmpArray,deg,MFnNurbsCurve::kOpen,false,false,true,finalCurve);
outputCurvesData.jumpToArrayElement(p);
MDataHandle curveH = outputCurvesData.outputValue();
curveH.set(finalCurve);
}
data.setClean(plug);
} else {
return MS::kUnknownParameter;
}
return MS::kSuccess;
}
void* curvesGen::creator()
{
return new curvesGen();
}
MStatus curvesGen::initialize()
{
MFnNumericAttribute nAttr;
MFnMatrixAttribute mAttr;
MFnTypedAttribute tAttr;
MStatus stat;
numCurves = nAttr.create( "numCurves", "in", MFnNumericData::kInt, 10);
nAttr.setStorable(true);
nAttr.setKeyable(true);
degree = nAttr.create( "degree", "d", MFnNumericData::kInt, 3);
nAttr.setStorable(true);
nAttr.setKeyable(true);
curvesInput = mAttr.create( "inputCurvesM", "inC", MFnMatrixAttribute::kDouble);
mAttr.setStorable(true);
mAttr.setArray(true);
curvesOutput = tAttr.create( "outputCurves", "outC",MFnData::kNurbsCurve);
tAttr.setWritable(false);
//tAttr.setStorable(false);
tAttr.setArray(true);
stat = addAttribute( numCurves );
if (!stat) { stat.perror("addAttribute"); return stat;}
stat = addAttribute( degree );
if (!stat) { stat.perror("addAttribute"); return stat;}
stat = addAttribute( curvesInput );
if (!stat) { stat.perror("addAttribute"); return stat;}
stat = addAttribute( curvesOutput );
if (!stat) { stat.perror("addAttribute"); return stat;}
stat = attributeAffects( numCurves, curvesOutput );
if (!stat) { stat.perror("attributeAffects"); return stat;}
stat = attributeAffects( curvesInput, curvesOutput );
if (!stat) { stat.perror("attributeAffects"); return stat;}
stat = attributeAffects( degree, curvesOutput );
if (!stat) { stat.perror("attributeAffects"); return stat;}
return MS::kSuccess;
}
double randomRange(double min, double max)
{
return (double)((max - min) * rand()/(double)RAND_MAX + min);
}
MPointArray curvesGen::distributePoints(int numPoints){
/*
calcolo della distribuzioni dei punti in un cerchio
*/
MPointArray numPointsArray;
double radius=1.0;
for(int i=0; i<numPoints; i++){
double Rnd = randomRange(0.0,2.0*PI);
double rR = randomRange(0.0,1.0);
double x = (sqrt(rR)*cos(Rnd)*radius);
double z = (sqrt(rR)*sin(Rnd)*radius);
double y = 0;
MPoint P(x,y,z);
numPointsArray.append(P);
}
return numPointsArray;
}