-
Notifications
You must be signed in to change notification settings - Fork 0
/
deform_pgmvc.cpp
195 lines (161 loc) · 4.86 KB
/
deform_pgmvc.cpp
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
#include <UT/UT_DSOVersion.h>
#include <UT/UT_Matrix3.h>
#include <GU/GU_Detail.h>
#include <GU/GU_PrimPoly.h>
#include <PRM/PRM_Include.h>
#include <OP/OP_Operator.h>
#include <OP/OP_OperatorTable.h>
#include <SOP/SOP_Guide.h>
#include <UT/UT_ErrorManager.h>
#include <OP/OP_Director.h>
#include <UT/UT_Vector3.h>
#include <UT/UT_Interrupt.h>
#include <GEO/GEO_Detail.h>
#include <GEO/GEO_Point.h>
#include <GEO/GEO_Vertex.h>
#include <SYS/SYS_Math.h>
#include <GA/GA_AIFBlob.h>
#include "deform_pgmvc.h"
#include "sparse_data.h"
void
newSopOperator( OP_OperatorTable *table )
{
table->addOperator
(
new OP_Operator
(
"deform_pgmvc_all", // Internal name
"deform_pgmvc_all", // UI name
SOP_PGMVC_deform::myConstructor, //
SOP_PGMVC_deform::myTemplateList, //
2, // Min Inputs
2, // Max Inputs
0 // Local Variables
//OP_FLAG_* // Additional Flag
)
);
}
static PRM_Name names[] =
{
PRM_Name( "delatt", "Delete capture attributes" ),
PRM_Name( 0 )
};
// How to make choices for a menu.
PRM_Template
SOP_PGMVC_deform::myTemplateList[] =
{
PRM_Template(PRM_TOGGLE, 1, &names[0]),
PRM_Template(),
};
const char *
SOP_PGMVC_deform::inputLabel( unsigned int input) const
{
switch (input) {
case 0:
return "Geometry To Deform";
break;
case 1:
return "Deformed Mesh";
break;
default:
return "Something";
break;
}
}
//overriding constructor
OP_Node *
SOP_PGMVC_deform::myConstructor( OP_Network *net, const char *name, OP_Operator *op )
{
return new SOP_PGMVC_deform( net, name, op );
}
SOP_PGMVC_deform::SOP_PGMVC_deform( OP_Network *net, const char *name, OP_Operator *op )
: SOP_Node( net, name, op )
{
mySopFlags.setNeedGuide1( 1 );
}
//destructor
SOP_PGMVC_deform::~SOP_PGMVC_deform() {}
//don't even disable or enable anything
unsigned
SOP_PGMVC_deform::disableParms()
{
return 0;
}
//cook method
OP_ERROR
SOP_PGMVC_deform::cookMySop( OP_Context &context )
{
int i;
float weight;
UT_Vector3 new_pos;
GA_Offset off;
UT_Vector3 pos;
const GU_Detail *deform;
// Before we do anything, we must lock our inputs. Before returning,
// we have to make sure that the inputs get unlocked.
if( lockInputs( context ) >= UT_ERROR_ABORT ) return error();
if( (deform = inputGeo(1,context)) == NULL ) return error();
duplicateSource( 0, context );
GA_RWHandleF wCapt_gah(gdp, GA_ATTRIB_POINT, "PGMVCweights");
// Sparse version
const GA_Attribute * a = gdp->findAttribute(GA_ATTRIB_POINT, GA_SCOPE_PUBLIC, "blob");
if (a){
const GA_AIFBlob *aif = a->getAIFBlob();
GA_Offset cage_off;
GA_FOR_ALL_PTOFF(gdp, off) {
new_pos = UT_Vector3(0,0,0);
GA_BlobRef blob = aif->getBlob(a, off);
if (blob) {
SparseData *bb = static_cast<SparseData*>(&(*blob));
// std::cout << "point index: "<< gdp->pointIndex(off) << std::endl;
for (const auto i : bb->weights){
// std::cout << "cage point: "<< i.first << " " << i.second << std::endl;
weight = i.second;
cage_off = deform->pointOffset(i.first);
pos = deform->getPos3(cage_off);
new_pos += weight * pos;
}
// std::cout << "---" << std::endl;
}
gdp->setPos3(off, new_pos);
}
}
else {
if(!wCapt_gah.isValid()) {
addError(SOP_ERR_INVALID_SRC , "input 1 is not captured");
unlockInputs();
return error();
}
GA_Offset cage_off;
GA_FOR_ALL_PTOFF(gdp, off) {
new_pos = UT_Vector3(0,0,0);
i = 0;
GA_FOR_ALL_PTOFF(deform, cage_off) {
weight = wCapt_gah.get(off, i);
if (weight > 0) {
pos = deform->getPos3(cage_off);
new_pos += weight * pos;
}
i++;
}
gdp->setPos3(off, new_pos);
}
}
if (DELATT()) {
if (wCapt_gah.isValid()) {
gdp->destroyPointAttrib("PGMVCweights");
}
}
unlockInputs();
return error();
}
OP_ERROR
SOP_PGMVC_deform::cookMyGuide1( OP_Context &context )
{
if ( lockInputs( context ) >= UT_ERROR_ABORT ) return error();
GU_Detail *in_gdp = (GU_Detail *)inputGeo(1, context);
if (in_gdp)
myGuide1->copy(*in_gdp);
unlockInputs();
return error();
}