forked from ahmidou/SpliceSoftimage
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFabricSpliceOperators.cpp
More file actions
189 lines (155 loc) · 4.92 KB
/
Copy pathFabricSpliceOperators.cpp
File metadata and controls
189 lines (155 loc) · 4.92 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
#include <xsi_application.h>
#include <xsi_context.h>
#include <xsi_status.h>
#include <xsi_command.h>
#include <xsi_argument.h>
#include <xsi_factory.h>
#include <xsi_longarray.h>
#include <xsi_doublearray.h>
#include <xsi_math.h>
#include <xsi_customproperty.h>
#include <xsi_ppglayout.h>
#include <xsi_menu.h>
#include <xsi_selection.h>
#include <xsi_project.h>
#include <xsi_utils.h>
#include <xsi_customoperator.h>
#include <xsi_operatorcontext.h>
// project includes
#include "FabricSplicePlugin.h"
#include "FabricSpliceOperators.h"
#include "FabricSpliceBaseInterface.h"
using namespace XSI;
opUserData::opUserData(unsigned int objectID)
{
_objectID = objectID;
_interf = NULL;
}
FabricSpliceBaseInterface * opUserData::getInterf()
{
if(_interf == NULL)
_interf = FabricSpliceBaseInterface::getInstanceByObjectID(_objectID);
return _interf;
}
unsigned int opUserData::getObjectID()
{
return _objectID;
}
XSIPLUGINCALLBACK CStatus SpliceOp_Define(CRef & in_ctxt)
{
Context ctxt( in_ctxt );
CustomOperator oCustomOperator;
Parameter oParam;
CRef oPDef;
Factory oFactory = Application().GetFactory();
oCustomOperator = ctxt.GetSource();
oPDef = oFactory.CreateParamDef(L"evalID", CValue::siInt4, siReadOnly, L"evalID", L"evalID", 0, 0, 1000, 0, 1000);
oCustomOperator.AddParameter(oPDef,oParam);
oPDef = oFactory.CreateParamDef(L"persistenceData", CValue::siString, siReadOnly, L"persistenceData", L"persistenceData", "", "", "", "", "");
oCustomOperator.AddParameter(oPDef,oParam);
oPDef = oFactory.CreateParamDef(L"alwaysConvertMeshes", CValue::siBool, siPersistable, L"alwaysConvertMeshes", L"alwaysConvertMeshes", false, CValue(), CValue(), CValue(), CValue());
oCustomOperator.AddParameter(oPDef,oParam);
FabricSpliceBaseInterface::constructXSIParameters(oCustomOperator, oFactory);
oCustomOperator.PutAlwaysEvaluate(false);
oCustomOperator.PutDebug(0);
return CStatus::OK;
}
XSIPLUGINCALLBACK CStatus SpliceOp_DefineLayout(CRef & in_ctxt)
{
Context ctxt( in_ctxt );
PPGLayout oLayout;
PPGItem oItem;
oLayout = ctxt.GetSource();
// oLayout.Clear();
// layout can't be driven for now.
return CStatus::OK;
}
XSIPLUGINCALLBACK CStatus SpliceOp_Update(CRef & in_ctxt)
{
FabricSplice::Logging::AutoTimer("SpliceOp_Update");
OperatorContext ctxt( in_ctxt );
CValue udVal = ctxt.GetUserData();
opUserData * p = (opUserData*)(CValue::siPtrType)udVal;
if(p == NULL)
{
xsiLogErrorFunc("Missing SpliceOp UserData. Unexpected failure.");
return CStatus::OK;
}
XSISPLICE_CATCH_BEGIN()
FabricSpliceBaseInterface * interf = p->getInterf();
CRef opRef = Application().GetObjectFromID(p->getObjectID());
if(interf != NULL)
{
// When transfering the input values, we check for changes and only evaluate if
// one of the inputs has actually changed. The Softimage application will evaluate
// and operator multiple times if connected to multiple outputs(once for each connected outport).
// This requires that we manage the clean/dirty state of the operator else for complex operators
// driving many values in Softimage, the whole system slows to a crawl.
if(interf->transferInputPorts(opRef, ctxt))
{
interf->evaluate();
}
interf->transferOutputPort(ctxt);
}
else if(!xsiIsLoadingScene())
{
CRef opRef = Application().GetObjectFromID(p->getObjectID());
xsiLogErrorFunc("Missing FabricSpliceBaseInterface. Probably duplicated object. Please remove operator '"+opRef.GetAsText()+"'.");
return CStatus::OK;
}
XSISPLICE_CATCH_END_CSTATUS()
return CStatus::OK;
}
std::vector<opUserData*> gOperatorInstances;
XSIPLUGINCALLBACK CStatus SpliceOp_Init(CRef & in_ctxt)
{
Context ctxt( in_ctxt );
CustomOperator op(ctxt.GetSource());
XSISPLICE_CATCH_BEGIN()
CValue udVal = ctxt.GetUserData();
opUserData * p = (opUserData*)(CValue::siPtrType)udVal;
if(p != NULL){
return CStatus::OK;
}
p = new opUserData(op.GetObjectID());
CValue val = (CValue::siPtrType)p;
ctxt.PutUserData( val ) ;
gOperatorInstances.push_back(p);
XSISPLICE_CATCH_END_CSTATUS()
return CStatus::OK;
}
XSIPLUGINCALLBACK CStatus SpliceOp_Term(CRef & in_ctxt)
{
Context ctxt( in_ctxt );
XSISPLICE_CATCH_BEGIN()
CValue udVal = ctxt.GetUserData();
opUserData * p = (opUserData*)(CValue::siPtrType)udVal;
if(p != NULL)
{
FabricSpliceBaseInterface * interf = p->getInterf();
if(interf)
{
if(interf->needsDeletion())
delete(interf);
}
for(size_t i=0;i<gOperatorInstances.size();i++)
{
if(gOperatorInstances[i] == p)
{
std::vector<opUserData*>::iterator it = gOperatorInstances.begin();
it += i;
gOperatorInstances.erase(it);
break;
}
}
delete(p);
CValue val = (CValue::siPtrType)NULL;
ctxt.PutUserData( val ) ;
}
XSISPLICE_CATCH_END_CSTATUS()
return CStatus::OK;
}
std::vector<opUserData*> getXSIOperatorInstances()
{
return gOperatorInstances;
}