-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRandomNodeDialog.mel
190 lines (159 loc) · 5.94 KB
/
RandomNodeDialog.mel
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
global string $nameObj_RN;
global string $numPoints_RN;
global string $minBoundX_RN;
global string $minBoundY_RN;
global string $minBoundZ_RN;
global string $maxBoundX_RN;
global string $maxBoundY_RN;
global string $maxBoundZ_RN;
global int $currNum_RN = 1;
global proc makeRandomNodeWindow() {
global string $nameObj_RN;
global string $numPoints_RN;
global string $minBoundX_RN;
global string $minBoundY_RN;
global string $minBoundZ_RN;
global string $maxBoundX_RN;
global string $maxBoundY_RN;
global string $maxBoundZ_RN;
string $window = `window -title "RandomNode"`;
paneLayout -configuration "horizontal2";
frameLayout -label "Create randomly placed instances of an object" -marginHeight 5 -marginWidth 5 -collapsable false -borderVisible false;
text -label "Name of Object to Duplicate:" -align "left" -font "obliqueLabelFont";
rowLayout -numberOfColumns 5 -adjustableColumn 1;
$nameObj_RN = `textField`;
text -label ", ";
button -label "Selected Object" -command "getSelectedShape";
text -label ", or ";
button -label "Create Sphere" -command "makeSphere";
setParent ..;
frameLayout -labelVisible false -marginHeight 5 -marginWidth 5 -collapsable false -backgroundShade true -borderVisible true;
columnLayout;
rowLayout -numberOfColumns 2;
text -label "Number of Points: ";
$numPoints_RN = `intField -minValue 1 -value 1`;
setParent ..;
rowLayout -numberOfColumns 4;
text -label "Minimum Bound: ";
$minBoundX_RN = `floatField -value -5.0`;
$minBoundY_RN = `floatField -value -5.0`;
$minBoundZ_RN = `floatField -value -5.0`;
setParent ..;
rowLayout -numberOfColumns 4;
text -label "Maximum Bound: ";
$maxBoundX_RN = `floatField -value 5.0`;
$maxBoundY_RN = `floatField -value 5.0`;
$maxBoundZ_RN = `floatField -value 5.0`;
setParent ..;
setParent ..;
setParent ..;
rowLayout -numberOfColumns 3 -adjustableColumn 2;
button -label "Create Instancer" -command "onCreateRandomNode";
text -label "";
button -label "Clear" -command "onClear";
setParent ..;
setParent ..;
showWindow $window;
}
makeRandomNodeWindow();
global proc getSelectedShape() {
global string $nameObj_RN;
string $selected[] = `ls -selection`;
int $listSize = `size $selected`;
if ($listSize == 1) {
textField -e -tx $selected[0] $nameObj_RN;
print($selected[0] + "\n");
}
else if ($listSize > 1) {
textField -e -tx "Choose One" $nameObj_RN;
print("Multiple Selected\n");
}
else {
textField -e -tx "None" $nameObj_RN;
print("None Selected\n");
}
}
global proc makeSphere()
{
global string $nameObj_RN;
global int $currNum_RN;
// Set up names
string $shapeName = "pSphere" + $currNum_RN;
print("Creating a sphere\n");
if(`objExists $shapeName` == false) {
string $sphereInfo[] = `polySphere -n $shapeName -r 1 -sx 10 -sy 10 -ax 0 1 0 -cuv 2 -ch 1`;
print($sphereInfo);
}
else {
select -r $shapeName;
}
textField -e -tx $shapeName $nameObj_RN;
}
global proc onCreateRandomNode()
{
global string $nameObj_RN;
global string $numPoints_RN;
global string $minBoundX_RN;
global string $minBoundY_RN;
global string $minBoundZ_RN;
global string $maxBoundX_RN;
global string $maxBoundY_RN;
global string $maxBoundZ_RN;
global int $currNum_RN;
print("Getting values from GUI\n");
int $numV = `intField -q -v $numPoints_RN`;
float $minX = `floatField -q -v $minBoundX_RN`;
float $minY = `floatField -q -v $minBoundY_RN`;
float $minZ = `floatField -q -v $minBoundZ_RN`;
float $maxX = `floatField -q -v $maxBoundX_RN`;
float $maxY = `floatField -q -v $maxBoundY_RN`;
float $maxZ = `floatField -q -v $maxBoundZ_RN`;
// Set up names
string $shapeName = `textField -q -tx $nameObj_RN`;
print(" " + $shapeName + "\n");
if(`objExists $shapeName`) {
// Names
string $instName = "instancer" + $currNum_RN;
string $nodeName = "randomNode" + $currNum_RN;
// Main objects
print("Creating Instancer\n");
string $currInst = `instancer -n $instName`;
string $currNode = `createNode randomNode -n $nodeName`;
print(" " + $currInst + "\n");
print(" " + $currNode + "\n");
// Attributes
print("Setting attributes\n");
setAttr ($currNode + ".minimumBoundX") $minX;
setAttr ($currNode + ".minimumBoundY") $minY;
setAttr ($currNode + ".minimumBoundZ") $minZ;
setAttr ($currNode + ".maximumBoundX") $maxX;
setAttr ($currNode + ".maximumBoundY") $maxY;
setAttr ($currNode + ".maximumBoundZ") $maxZ;
setAttr ($currNode + ".numberOfPoints") $numV;
// Connections
print("Setting Connections\n");
connectAttr ($currNode + ".outPoints") ($currInst + ".inputPoints");
connectAttr ($shapeName + ".matrix") ($currInst + ".inputHierarchy[0]");
//select $currInst;
$currNum_RN = $currNum_RN + 1;
print("finished mel\n");
}
else {
print("No Match\n");
textField -e -tx "No Match" $nameObj_RN;
}
}
global proc onClear() {
global int $currNum_RN;
// Reset the scene
print("Scene reset button pressed...\n");
string $result = `confirmDialog -title "Clear Scene"
-message "Clear and reset entire scene?"
-button "Yes" -button "No"
-cancelButton "No"-defaultButton "No"`;
if ($result == "Yes") {
$currNum_RN = 1;
file -f -new;
print("Scene Reset\n");
} else warning "Reset cancelled: scene preserved\n";
}