forked from ahmidou/SpliceSoftimage
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFabricDFGMenu.cpp
More file actions
320 lines (282 loc) · 10.2 KB
/
Copy pathFabricDFGMenu.cpp
File metadata and controls
320 lines (282 loc) · 10.2 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
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
#include <xsi_application.h>
#include <xsi_context.h>
#include <xsi_menu.h>
#include <xsi_model.h>
#include <xsi_customoperator.h>
#include <xsi_x3dobject.h>
#include <xsi_uitoolkit.h>
#include <xsi_null.h>
#include <xsi_vector3.h>
#include <xsi_selection.h>
#include <xsi_string.h>
#include "FabricDFGTools.h"
using namespace XSI;
XSIPLUGINCALLBACK CStatus Fabric_Init( CRef &in_ctxt )
{
Menu menu = Context(in_ctxt).GetSource();
MenuItem item;
menu.AddCallbackItem("Create Graph", "FabricCanvas_Menu_CreateDFGOp", item);
menu.AddSeparatorItem();
menu.AddCallbackItem("Create Null with Graph", "FabricCanvas_Menu_CreateNullWithOp", item);
menu.AddCallbackItem("Create Polymesh with Graph", "FabricCanvas_Menu_CreatePolymeshWithOp", item);
menu.AddSeparatorItem();
menu.AddCallbackItem("Inspect Canvas Op", "FabricCanvas_Menu_InspectCanvasOp", item);
menu.AddSeparatorItem();
menu.AddCallbackItem("Load Graph", "FabricCanvas_Menu_ImportGraph", item);
menu.AddCallbackItem("Save Graph", "FabricCanvas_Menu_ExportGraph", item);
menu.AddSeparatorItem();
menu.AddCallbackItem("Splice Editor (legacy)", "FabricSplice_Menu_Editor", item);
menu.AddCallbackItem("Load Splice Preset (legacy)", "FabricSplice_Menu_LoadSplice", item);
menu.AddSeparatorItem();
menu.AddCallbackItem("Toggle Manipulation", "FabricSplice_Menu_Manipulation", item);
menu.AddSeparatorItem();
menu.AddCallbackItem("Toggle Renderer", "FabricSplice_Menu_Renderer", item);
menu.AddSeparatorItem();
menu.AddCallbackItem("Online Help", "FabricCanvas_Menu_OnlineHelp", item);
menu.AddCallbackItem("ThirdParty Licenses", "FabricSplice_Menu_ThirdPartyLicenses", item);
menu.AddCallbackItem("Log Status", "FabricCanvas_Menu_LogStatus", item);
return CStatus::OK;
}
SICALLBACK FabricCanvas_Menu_CreateDFGOp(XSI::CRef&)
{
// init and fill array of target objects.
CStringArray targetObjects;
{
Selection sel = Application().GetSelection();
if (sel.GetCount() <= 0)
{
// nothing is selected
// => fill targetObjects from picking session.
CValueArray args(7);
args[0] = siGenericObjectFilter;
args[1] = CString(L"Pick Object");
args[2] = CString(L"Pick Object");
args[5] = 0;
CString command(L"PickElement");
CValue value;
while (true)
{
// pick session failed?
if (Application().ExecuteCommand(command, args, value) == CStatus::Fail)
break;
// right button?
if ((LONG)args[4] == 0)
break;
// add CRef of picked object to targetObjects.
CRef ref = args[3];
targetObjects.Add(ref.GetAsText());
}
}
else
{
// there are selected objects
// => fill targetObjects from selection.
for (int i=0;i<sel.GetCount();i++)
targetObjects.Add(sel[i].GetAsText());
}
}
// execute command for all elements in targetObjects.
for (int i=0;i<targetObjects.GetCount();i++)
{
CValueArray args;
CValue val;
args.Add(targetObjects[i]);
args.Add(L"");
args.Add(true);
Application().ExecuteCommand(L"FabricCanvasOpApply", args, val);
}
// done.
dfgTools::ClearUndoHistory();
return CStatus::OK;
}
SICALLBACK FabricCanvas_Menu_CreateNullWithOp(XSI::CRef&)
{
// create a null.
Null obj;
if (Application().GetActiveSceneRoot().AddNull(L"null", obj) != CStatus::OK)
{ Application().LogMessage(L"failed to create a null", siErrorMsg);
return CStatus::OK; }
// select it.
Selection sel = Application().GetSelection();
sel.Clear();
sel.Add(obj.GetRef());
// execute command.
CValueArray args;
CValue val;
args.Add(obj.GetFullName());
args.Add(L"");
args.Add(true);
Application().ExecuteCommand(L"FabricCanvasOpApply", args, val);
// done.
dfgTools::ClearUndoHistory();
return CStatus::OK;
}
SICALLBACK FabricCanvas_Menu_CreatePolymeshWithOp(XSI::CRef&)
{
// create an empty polygon mesh.
X3DObject obj;
if (Application().GetActiveSceneRoot().AddPolygonMesh(MATH::CVector3Array(), CLongArray(), L"polymsh", obj) != CStatus::OK)
{ Application().LogMessage(L"failed to create an empty polygon mesh", siErrorMsg);
return CStatus::OK; }
// select it.
Selection sel = Application().GetSelection();
sel.Clear();
sel.Add(obj.GetRef());
// execute command.
CValueArray args;
CValue val;
args.Add(obj.GetFullName());
args.Add(L"");
args.Add(true);
Application().ExecuteCommand(L"FabricCanvasOpApply", args, val);
// done.
dfgTools::ClearUndoHistory();
return CStatus::OK;
}
SICALLBACK FabricCanvas_Menu_InspectCanvasOp(XSI::CRef&)
{
// execute command.
CValueArray args;
CValue val;
Application().ExecuteCommand(L"FabricCanvasInspectOp", args, val);
// done.
return CStatus::OK;
}
SICALLBACK FabricCanvas_Menu_OnlineHelp(XSI::CRef&)
{
CValueArray args;
CValue val;
args.Add(L"http://docs.fabric-engine.com/FabricEngine/latest/HTML/");
args.Add(true);
args.Add((LONG)1);
Application().ExecuteCommand(L"OpenNetView", args, val);
return CStatus::OK;
}
SICALLBACK FabricCanvas_Menu_ImportGraph(XSI::CRef&)
{
LONG ret;
UIToolkit toolkit = Application().GetUIToolkit();
CString msgBoxtitle = L"Import graph";
// get/check current selection.
CRef selRef;
{
Selection sel = Application().GetSelection();
if (sel.GetCount() < 1)
{ toolkit.MsgBox(L"Nothing selected.\nPlease select an object or operator and try again.", siMsgOkOnly | siMsgInformation, msgBoxtitle, ret);
return CStatus::OK; }
if (sel.GetCount() > 1)
{ toolkit.MsgBox(L"More than one object selected.\nPlease select a single object or operator and try again.", siMsgOkOnly | siMsgInformation, msgBoxtitle, ret);
return CStatus::OK; }
selRef = sel.GetArray()[0];
}
// get operator from selection.
CustomOperator op;
if (selRef.GetClassID() == siCustomOperatorID)
{
op.SetObject(selRef);
if (!op.IsValid())
{ toolkit.MsgBox(L"The selection cannot be used for this operation.", siMsgOkOnly | siMsgInformation, msgBoxtitle, ret);
return CStatus::OK; }
}
else
{
X3DObject obj(selRef);
if (!obj.IsValid())
{ toolkit.MsgBox(L"The selection cannot be used for this operation.", siMsgOkOnly | siMsgInformation, msgBoxtitle, ret);
return CStatus::OK; }
CRefArray opRefs;
CString canvasOpName(L"CanvasOp");
int numOps = dfgTools::GetRefsAtOps(obj, canvasOpName, opRefs);
if (numOps < 1)
{ toolkit.MsgBox(L"No valid custom operator found to perform this operation.", siMsgOkOnly | siMsgInformation, msgBoxtitle, ret);
return CStatus::OK; }
if (numOps > 1)
{ toolkit.MsgBox(L"The selection contains more than one custom operator.\nPlease select a single operator and try again.", siMsgOkOnly | siMsgInformation, msgBoxtitle, ret);
return CStatus::OK; }
op.SetObject(opRefs[0]);
if (!op.IsValid())
{ toolkit.MsgBox(L"Failed to get custom operator.", siMsgOkOnly | siMsgInformation, msgBoxtitle, ret);
return CStatus::OK; }
}
// open file browser.
CString fileName;
if (!dfgTools::FileBrowserJSON(false, fileName))
{ Application().LogMessage(L"aborted by user.", siWarningMsg);
return CStatus::OK; }
// execute command.
CValueArray args;
CValue val;
args.Add(op.GetUniqueName());
args.Add(fileName);
Application().ExecuteCommand(L"FabricCanvasImportGraph", args, val);
// done.
dfgTools::ClearUndoHistory();
return CStatus::OK;
}
SICALLBACK FabricCanvas_Menu_ExportGraph(XSI::CRef&)
{
LONG ret;
UIToolkit toolkit = Application().GetUIToolkit();
CString msgBoxtitle = L"Export Graph";
// get/check current selection.
CRef selRef;
{
Selection sel = Application().GetSelection();
if (sel.GetCount() < 1)
{ toolkit.MsgBox(L"Nothing selected.\nPlease select an object or operator and try again.", siMsgOkOnly | siMsgInformation, msgBoxtitle, ret);
return CStatus::OK; }
if (sel.GetCount() > 1)
{ toolkit.MsgBox(L"More than one object selected.\nPlease select a single object or operator and try again.", siMsgOkOnly | siMsgInformation, msgBoxtitle, ret);
return CStatus::OK; }
selRef = sel.GetArray()[0];
}
// get operator from selection.
CustomOperator op;
if (selRef.GetClassID() == siCustomOperatorID)
{
op.SetObject(selRef);
if (!op.IsValid())
{ toolkit.MsgBox(L"The selection cannot be used for this operation.", siMsgOkOnly | siMsgInformation, msgBoxtitle, ret);
return CStatus::OK; }
}
else
{
X3DObject obj(selRef);
if (!obj.IsValid())
{ toolkit.MsgBox(L"The selection cannot be used for this operation.", siMsgOkOnly | siMsgInformation, msgBoxtitle, ret);
return CStatus::OK; }
CRefArray opRefs;
CString canvasOpName(L"CanvasOp");
int numOps = dfgTools::GetRefsAtOps(obj, canvasOpName, opRefs);
if (numOps < 1)
{ toolkit.MsgBox(L"No valid custom operator found to perform this operation.", siMsgOkOnly | siMsgInformation, msgBoxtitle, ret);
return CStatus::OK; }
if (numOps > 1)
{ toolkit.MsgBox(L"The selection contains more than one custom operator.\nPlease select a single operator and try again.", siMsgOkOnly | siMsgInformation, msgBoxtitle, ret);
return CStatus::OK; }
op.SetObject(opRefs[0]);
if (!op.IsValid())
{ toolkit.MsgBox(L"Failed to get custom operator.", siMsgOkOnly | siMsgInformation, msgBoxtitle, ret);
return CStatus::OK; }
}
// open file browser.
CString fileName;
if (!dfgTools::FileBrowserJSON(true, fileName))
{ Application().LogMessage(L"aborted by user.", siWarningMsg);
return CStatus::OK; }
// execute command.
CValueArray args;
CValue val;
args.Add(op.GetUniqueName());
args.Add(fileName);
Application().ExecuteCommand(L"FabricCanvasExportGraph", args, val);
// done.
return CStatus::OK;
}
SICALLBACK FabricCanvas_Menu_LogStatus(XSI::CRef&)
{
CValueArray args;
CValue val;
Application().ExecuteCommand(L"FabricCanvasLogStatus", args, val);
return CStatus::OK;
}