-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHoudiniEngine_gui.cpp
More file actions
240 lines (223 loc) · 7.54 KB
/
HoudiniEngine_gui.cpp
File metadata and controls
240 lines (223 loc) · 7.54 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
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
#include "HoudiniEngine.h"
#include "HoudiniEngine_util.h"
#include "HoudiniEngine_gui.h"
#include <maxscript\maxscript.h>
#include <sstream>
#define ECR <<"\n";
#define SYNC_PARAMS "if this.delegate.autoupdate do this.delegate.autoupdate = True"
static bool GetParmParentVisible( std::vector<hapi::Parm>& parms, int id )
{
if ( id < 0 )
return false;
for (int i=0; i < int(parms.size()); ++i)
{
hapi::Parm &parm = parms[i];
if ( parm.info().id == id )
{
if ( parm.info().invisible )
return true;
if ( parm.info().parentId >= 0 && GetParmParentVisible( parms, parm.info().parentId ) )
return true;
}
}
return false;
}
bool GenerateScriptPlugin(std::string& otl_path, std::string& name, std::string& category, std::string& texture_path, std::string& classid, std::string& code )
{
int asset_id = -1;
hapi::Engine* engine = hapi::Engine::instance();
if (engine)
{
// loading asset
int library_id = engine->loadAssetLibrary(otl_path.c_str());
if (library_id >= 0)
{
std::string asset_name = engine->getAssetName(library_id, 0);
asset_id = engine->instantiateAsset(asset_name.c_str(), false);
}
}
hapi::Asset asset(asset_id);
if (asset.isValid())
{
std::stringstream mxs;
mxs << "plugin geometry " << name ECR
mxs << "name:\"" << name << "\"" ECR
mxs << "extends:HEMesh" ECR
mxs << "classID:" << classid ECR
mxs << "category:\"" << category << "\"" ECR
mxs << "(" ECR
// Inputs
if (asset.info().geoInputCount)
{
const int getInputs = asset.info().geoInputCount;
mxs << "\tparameters pblock rollout:inputs" ECR
mxs << "\t(" ECR
for (int i = 0; i < getInputs; ++i)
{
mxs << "\t\t __he_input" << i << " type:#node ui:__he_input" << i ECR
}
mxs << "\t)" ECR
mxs << "\trollout inputs \"Inputs\"" ECR
mxs << "\t(" ECR
for (int i = 0; i < getInputs; ++i)
{
std::string inputname = asset.getInputName(i);
mxs << "\t\t" << "label label_he_input" << i << " \"" << inputname << "\" width:140" ECR
mxs << "\t\t" << "pickbutton __he_input" << i << " \"" << "Pick Node" << "\" width:140" ECR
}
for (int i = 0; i < getInputs; ++i)
{
mxs << "\t\ton __he_input" << i << " picked obj do (\n\t\t\t__he_input" << i << ".text=obj.name\n\t\t\t" SYNC_PARAMS "\n\t\t)" ECR
}
mxs << "\t\ton inputs open do\n\t\t(" ECR
for (int i = 0; i < getInputs; ++i)
{
mxs << "\t\t\tif __he_input" << i << ".object != undefined do __he_input" << i << ".text = __he_input" << i << ".object.name" ECR
}
mxs << "\t\t)" ECR
mxs << "\t)" ECR
}
mxs << "\tparameters pblock rollout:params" ECR
mxs << "\t(" ECR
// Parameters
std::vector<hapi::Parm> _parms = asset.parms();
for (int i = 0; i < int(_parms.size()); ++i)
{
hapi::Parm &parm = _parms[i];
if (parm.info().invisible || GetParmParentVisible(_parms, parm.info().parentId))
continue;
if (parm.info().type == HAPI_PARMTYPE_TOGGLE)
{
std::string name = parm.name();
int value = parm.getIntValue(0);
mxs << "\t\t" << name << "0 type:#integer ui:" << name << "0 default:" << value ECR
}
else if (HAPI_ParmInfo_IsInt(&parm.info()))
{
std::string name = parm.name();
for (int sub_index = 0; sub_index < parm.info().size; ++sub_index)
{
int value = parm.getIntValue(sub_index);
mxs << "\t\t" << name << sub_index << " type:#integer animatable:true ui:" << name << sub_index << " default:" << value ECR
}
}
else if (HAPI_ParmInfo_IsFloat(&parm.info()))
{
std::string name = parm.name();
for (int sub_index = 0; sub_index < parm.info().size; ++sub_index)
{
float value = parm.getFloatValue(sub_index);
mxs << "\t\t" << name << sub_index << " type:#float animatable:true ui:" << name << sub_index << " default:" << value ECR
}
}
else if (HAPI_ParmInfo_IsString(&parm.info()))
{
std::string name = parm.name();
for (int sub_index = 0; sub_index < parm.info().size; ++sub_index)
{
std::string value = parm.getStringValue(sub_index);
mxs << "\t\t" << name << sub_index << " type:#string ui:" << name << sub_index << " default:\"" << value << "\"" ECR
}
}
}
mxs << "\t)" ECR
mxs << "\trollout params \"Parameters\"" ECR
mxs << "\t(" ECR
for (int i = 0; i < int(_parms.size()); ++i)
{
hapi::Parm &parm = _parms[i];
if (parm.info().invisible || GetParmParentVisible(_parms, parm.info().parentId))
continue;
std::string label = parm.label();
if (parm.info().type == HAPI_PARMTYPE_TOGGLE)
{
std::string name = parm.name();
mxs << "\t\t" << "checkbox " << name << "0 \"" << label << "\"" ECR
}
else if (HAPI_ParmInfo_IsInt(&parm.info()))
{
std::string name = parm.name();
for (int sub_index = 0; sub_index < parm.info().size; ++sub_index)
{
if (sub_index == 0)
mxs << "\t\t" << "spinner " << name << sub_index << " \"" << label << "\" type:#integer" ECR
else
mxs << "\t\t" << "spinner " << name << sub_index << " \"\" type:#integer" ECR
}
}
else if (HAPI_ParmInfo_IsFloat(&parm.info()))
{
std::string name = parm.name();
for (int sub_index = 0; sub_index < parm.info().size; ++sub_index)
{
if (sub_index == 0)
mxs << "\t\t" << "spinner " << name << sub_index << " \"" << label << "\" type:#float" ECR
else
mxs << "\t\t" << "spinner " << name << sub_index << " \"\" type:#float" ECR
}
}
else if (HAPI_ParmInfo_IsString(&parm.info()))
{
std::string name = parm.name();
for (int sub_index = 0; sub_index < parm.info().size; ++sub_index)
{
if (sub_index == 0)
mxs << "\t\t" << "edittext " << name << sub_index << " \"" << label << "\" fieldWidth:140 labelOnTop:true" ECR
else
mxs << "\t\t" << "edittext " << name << sub_index << " fieldWidth:140 labelOnTop:false" ECR
}
}
}
for (int i = 0; i < int(_parms.size()); ++i)
{
hapi::Parm &parm = _parms[i];
if (parm.info().invisible || GetParmParentVisible(_parms, parm.info().parentId))
continue;
std::string label = parm.label();
if (parm.info().type == HAPI_PARMTYPE_TOGGLE)
{
std::string name = parm.name();
mxs << "\t\ton " << name << "0 changed val do " SYNC_PARAMS ECR
}
else if (HAPI_ParmInfo_IsInt(&parm.info()))
{
std::string name = parm.name();
for (int sub_index = 0; sub_index < parm.info().size; ++sub_index)
{
mxs << "\t\ton " << name << sub_index << " changed val do " SYNC_PARAMS ECR
}
}
else if (HAPI_ParmInfo_IsFloat(&parm.info()))
{
std::string name = parm.name();
for (int sub_index = 0; sub_index < parm.info().size; ++sub_index)
{
mxs << "\t\ton " << name << sub_index << " changed val do " SYNC_PARAMS ECR
}
}
else if (HAPI_ParmInfo_IsString(&parm.info()))
{
std::string name = parm.name();
for (int sub_index = 0; sub_index < parm.info().size; ++sub_index)
{
mxs << "\t\ton " << name << sub_index << " entered val do " SYNC_PARAMS ECR
}
}
}
mxs << "\t)" ECR
mxs << "\ton create do" ECR
mxs << "\t(" ECR
mxs << "\t\tthis.delegate.filename = @\"" << otl_path << "\"" ECR
mxs << "\t\tthis.delegate.update_time = true" ECR
mxs << "\t\tthis.delegate.conv_unit_scale_i = true" ECR
mxs << "\t\tthis.delegate.conv_unit_scale_o = true" ECR
mxs << "\t\tthis.delegate.texture_path = @\"" << texture_path << "\"" ECR
mxs << "\t)" ECR
mxs << ")" ECR
code = mxs.str();
// Release Asset
engine->destroyAsset(asset_id);
return true;
}
return false;
}