Repository navigation
Expand file tree
/
Copy pathmoverKernels.cpp
More file actions
958 lines (885 loc) · 42.9 KB
/
Copy pathmoverKernels.cpp
File metadata and controls
958 lines (885 loc) · 42.9 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
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
// RigExec exec computations for solvers and mover operands.
// Weight objects publish computeWeightPacket, blend samples/inputs publish
// their descriptors, and the aggregate solvers publish
// computePointFrameArray. Point chains evaluate through the shared typed
// operation graph, not through callbacks here.
#include "rigExecSchema/schemaNames.h"
#include "types.h"
#include "moverGraph.h"
#include "frameExtraction.h"
#include "solverKernels.h"
#include "weightPackets.h"
#include "movers/moverExecCommon.h"
#include "rigExecMath/pointFrame.h"
#include "rigExecMath/envelope.h"
#include "rigExecMath/geometryKernels.h"
#include "rigExecMath/simdKernels.h"
#include "rigExecMath/solvers.h"
#include "rigExecMath/weightFields.h"
#include "pxr/pxr.h"
#include "pxr/base/tf/getenv.h"
#include "pxr/base/tf/staticTokens.h"
#include "pxr/exec/exec/builtinComputations.h"
#include "pxr/exec/exec/registerSchema.h"
#include "pxr/exec/vdf/context.h"
#include "pxr/exec/vdf/readIterator.h"
#include "pxr/exec/vdf/readWriteIterator.h"
#include <algorithm>
#include <cmath>
using rigExec::RigExecBlendChannel;
using rigExec::RigExecBlendSampleData;
using rigExec::RigExecMoverParameters;
using rigExec::RigExecPointFrame;
using rigExec::RigExecPointFrameArray;
using rigExec::RigExecPointsPacket;
using rigExec::RigExecWeightPacket;
PXR_NAMESPACE_USING_DIRECTIVE
TF_DEFINE_PRIVATE_TOKENS(
_tokens,
// Computation names.
(computeWeightPacket)
(computeBlendSampleData)
(computeBlendChannel)
(computeMoverParameters)
(computePointFrame)
(computeMatrix)
// Input names.
(previous)
(parameters)
(basePacket)
(samplePoints)
(sampleData)
(enabled)
(transform)
(weightPacket)
(blendChannels)
(basePoints)
// Attribute tokens.
((representation, rigExec::SchemaAttrText::rigExecRepresentation))
((rangePolicy, rigExec::SchemaAttrText::rigExecRangePolicy))
((values, rigExec::SchemaAttrText::rigExecValues))
((indices, rigExec::SchemaAttrText::rigExecIndices))
((defaultWeight, rigExec::SchemaAttrText::rigExecDefaultWeight))
((inputsDefaultWeight, rigExec::SchemaAttrText::inputsDefaultWeight))
((baseWeight, rigExec::SchemaAttrText::rigExecBaseWeight))
((inputsDriver, rigExec::SchemaAttrText::inputsDriver))
((inputsScale, rigExec::SchemaAttrText::inputsScale))
((inputsBias, rigExec::SchemaAttrText::inputsBias))
((activation, rigExec::SchemaAttrText::rigExecActivation))
((targetPoints, rigExec::SchemaAttrText::rigExecTargetPoints))
((samples, rigExec::SchemaAttrText::rigExecSamples))
((inputsWeight, rigExec::SchemaAttrText::inputsWeight))
((deltaSpace, rigExec::SchemaAttrText::rigExecDeltaSpace))
((moverRel, rigExec::SchemaAttrText::rigExecMover))
((weightObjectRel, rigExec::SchemaAttrText::rigExecWeightObject))
((inputsEnabled, rigExec::SchemaAttrText::inputsEnabled))
((resolvedTransform, rigExec::SchemaAttrText::rigExecResolvedTransform))
((resolvedBlendInputs, rigExec::SchemaAttrText::rigExecResolvedBlendInputs))
((resolvedBase, rigExec::SchemaAttrText::rigExecResolvedBase))
((resolvedFinalPoints, rigExec::SchemaAttrText::rigExecResolvedFinalPoints))
((resolvedTopologyCounts, rigExec::SchemaAttrText::rigExecResolvedTopologyCounts))
((resolvedTopologyIndices, rigExec::SchemaAttrText::rigExecResolvedTopologyIndices))
((resolvedCagePoints, rigExec::SchemaAttrText::rigExecResolvedCagePoints))
((resolvedSurfacePoints, rigExec::SchemaAttrText::rigExecResolvedSurfacePoints))
((resolvedBindCoords, rigExec::SchemaAttrText::rigExecResolvedBindCoords))
((resolvedDriverFrames, rigExec::SchemaAttrText::rigExecResolvedDriverFrames))
((computeDriverPoints, rigExec::SchemaAttrText::rigExecComputeDriverPoints))
((computeRestDriverPoints, rigExec::SchemaAttrText::rigExecComputeRestDriverPoints))
((resolvedWidths, rigExec::SchemaAttrText::rigExecResolvedWidths))
((restCagePointsAttr, rigExec::SchemaAttrText::rigExecRestCagePoints))
((divisionsAttr, rigExec::SchemaAttrText::rigExecDivisions))
((sampleCountAttr, rigExec::SchemaAttrText::rigExecSampleCount))
((joints, rigExec::SchemaAttrText::rigExecJoints))
(jointRests)
(computeRestFrame)
((modeAttr, rigExec::SchemaAttrText::rigExecMode))
((strengthAttr, rigExec::SchemaAttrText::inputsStrength))
(computePointFrameArray)
(finalPoints)
(topologyCounts)
(topologyIndices)
(cagePoints)
(surfacePoints)
(bindCoords)
(driverFrames)
(driverPoints)
(restDriver)
(widthsInput)
(computeMoverStatus)
(status)
(moverPath)
((outputsExpression, rigExec::SchemaAttrText::outputsExpression))
// Volumetric weight objects.
(computeFalloffLut)
(falloffLut)
(weightTargetPoints)
(sampleSourcePoints)
(curvePoints)
(inputPackets)
(selfMatrix)
((weightTargetRel, rigExec::SchemaAttrText::rigExecWeightTarget))
((sampleSourceRel, rigExec::SchemaAttrText::rigExecSampleSource))
((curveRel, rigExec::SchemaAttrText::rigExecCurve))
((inputWeightsRel, rigExec::SchemaAttrText::rigExecInputWeights))
((falloffMin, rigExec::SchemaAttrText::inputsFalloffMin))
((falloffMax, rigExec::SchemaAttrText::inputsFalloffMax))
((inputsInvert, rigExec::SchemaAttrText::inputsInvert))
((inputsScaleXPos, rigExec::SchemaAttrText::inputsScaleXPos))
((inputsScaleYPos, rigExec::SchemaAttrText::inputsScaleYPos))
((inputsScaleZPos, rigExec::SchemaAttrText::inputsScaleZPos))
((inputsScaleXNeg, rigExec::SchemaAttrText::inputsScaleXNeg))
((inputsScaleYNeg, rigExec::SchemaAttrText::inputsScaleYNeg))
((inputsScaleZNeg, rigExec::SchemaAttrText::inputsScaleZNeg))
((inputsScaleX, rigExec::SchemaAttrText::inputsScaleX))
((inputsScaleY, rigExec::SchemaAttrText::inputsScaleY))
((inputsScaleZ, rigExec::SchemaAttrText::inputsScaleZ))
((inputsExtentU, rigExec::SchemaAttrText::inputsExtentU))
((inputsExtentV, rigExec::SchemaAttrText::inputsExtentV))
((planeAxisAttr, rigExec::SchemaAttrText::rigExecPlaneAxis))
((planeBoundsAttr, rigExec::SchemaAttrText::rigExecPlaneBounds))
((combineModeAttr, rigExec::SchemaAttrText::rigExecCombineMode))
);
namespace {
// Immutable worker operands are constructed before computation dispatch.
const TfToken _workerConstant(rigExec::SchemaValueText::constant);
const TfToken _workerStrict(rigExec::SchemaValueText::strict);
const TfToken _workerDense(rigExec::SchemaValueText::dense);
const TfToken _workerClamp(rigExec::SchemaValueText::clamp);
const TfToken _workerSphereType(rigExec::SchemaTypeName::RigExecSphereWeight);
const TfToken _workerPlaneType(rigExec::SchemaTypeName::RigExecPlaneWeight);
const TfToken _workerYAxis(rigExec::SchemaValueText::y);
const TfToken _workerUnbounded(rigExec::SchemaValueText::unbounded);
const TfToken _workerBounded(rigExec::SchemaValueText::bounded);
const TfToken _workerCurveType(rigExec::SchemaTypeName::RigExecCurveWeight);
const TfToken _workerMultiply(rigExec::SchemaValueText::multiply);
// Weight objects.
// The packet arithmetic lives in weightPackets.h, not here: the baked
// evaluation program has to publish the identical packet from the values
// it bound at compile time, and the only way to guarantee that is one
// definition called from both sides. What is left below is the adapter --
// it turns a VdfContext into the plain values those kernels take, and
// nothing else.
// Absent inputs are defaulted HERE rather than inside the kernels,
// because exec distinguishes "the input has no value" from "the attribute
// is authored empty" and a kernel that collapsed the two would accept a
// rig exec rejects.
// Collects a vectorized GfVec3f input into a plain vector.
std::vector<GfVec3f>
_CollectPoints(const VdfContext &ctx, const TfToken &input)
{
std::vector<GfVec3f> points;
VdfReadIterator<GfVec3f> it(ctx, input);
points.reserve(it.ComputeSize());
for (; !it.IsAtEnd(); ++it) {
points.push_back(*it);
}
return points;
}
// The same for a vectorized scalar input (rigExec:values, rigExec:indices).
template <typename T>
std::vector<T>
_CollectScalars(const VdfContext &ctx, const TfToken &input)
{
std::vector<T> values;
VdfReadIterator<T> it(ctx, input);
values.reserve(it.ComputeSize());
for (; !it.IsAtEnd(); ++it) {
values.push_back(*it);
}
return values;
}
float
_Scalar(const VdfContext &ctx, const TfToken &input, float fallback)
{
const float *v = ctx.GetInputValuePtr<float>(input);
return v ? *v : fallback;
}
RigExecWeightPacket
_BuildStaticWeightPacket(const VdfContext &ctx)
{
const TfToken &constant = _workerConstant;
const TfToken &strict = _workerStrict;
rigExec::RigExecStaticWeightInputs inputs;
const TfToken *repr =
ctx.GetInputValuePtr<TfToken>(_tokens->representation);
const TfToken *policy = ctx.GetInputValuePtr<TfToken>(_tokens->rangePolicy);
inputs.representation = repr ? *repr : constant;
inputs.rangePolicy = policy ? *policy : strict;
const float *def = ctx.GetInputValuePtr<float>(_tokens->defaultWeight);
inputs.defaultWeight = def ? *def : 0.0f;
inputs.values = _CollectScalars<float>(ctx, _tokens->values);
// rigExec:indices pairs with the values in the sparse representation
// and means nothing in the other two, which is why the callback this
// replaced never dereferenced its iterator outside that arm either.
if (inputs.representation == rigExec::SchemaValueText::sparse) {
inputs.indices = _CollectScalars<int>(ctx, _tokens->indices);
}
return rigExec::RigExecBuildStaticWeightPacket(inputs);
}
RigExecWeightPacket
_BuildDynamicWeightPacket(const VdfContext &ctx)
{
const TfToken &constant = _workerConstant;
const TfToken &strict = _workerStrict;
rigExec::RigExecDynamicWeightInputs inputs;
const TfToken *repr =
ctx.GetInputValuePtr<TfToken>(_tokens->representation);
const TfToken *policy = ctx.GetInputValuePtr<TfToken>(_tokens->rangePolicy);
inputs.representation = repr ? *repr : constant;
inputs.rangePolicy = policy ? *policy : strict;
inputs.driver = _Scalar(ctx, _tokens->inputsDriver, 1.0f);
inputs.scale = _Scalar(ctx, _tokens->inputsScale, 1.0f);
inputs.bias = _Scalar(ctx, _tokens->inputsBias, 0.0f);
return rigExec::RigExecBuildDynamicWeightPacket(
inputs, ctx.GetInputValuePtr<RigExecWeightPacket>(_tokens->basePacket));
}
// Volumetric weight objects.
// The three shapes share a prologue (placement, band, sampled points) and
// differ only in the extra inputs their distance function needs, so the
// common half is read once here and each callback adds its own.
// Reads the band, the invert/strength pair, and the baked remap.
rigExec::RigExecFalloffParams
_ReadFalloffParams(const VdfContext &ctx)
{
rigExec::RigExecFalloffParams params;
params.falloffMin = _Scalar(ctx, _tokens->falloffMin, 0.0f);
params.falloffMax = _Scalar(ctx, _tokens->falloffMax, 1.0f);
params.invert = _Scalar(ctx, _tokens->inputsInvert, 0.0f);
params.strength = _Scalar(ctx, _tokens->strengthAttr, 1.0f);
if (const rigExec::RigExecFalloffLut *lut =
ctx.GetInputValuePtr<rigExec::RigExecFalloffLut>(
_tokens->falloffLut)) {
params.curve = lut->samples;
}
return params;
}
// Per-axis divisors. Whether they describe a volume at all is the
// kernel's judgement (see RigExecBuildVolumeWeightPacket); this reads.
void
_ReadAxisScales(const VdfContext &ctx, GfVec3f *scales)
{
(*scales)[0] = _Scalar(ctx, _tokens->inputsScaleX, 1.0f);
(*scales)[1] = _Scalar(ctx, _tokens->inputsScaleY, 1.0f);
(*scales)[2] = _Scalar(ctx, _tokens->inputsScaleZ, 1.0f);
}
// The inputs every volumetric shape reads, LESS the point arrays.
// The points are a whole mesh, so they are gathered separately, after
// RigExecVolumeWeightCanBuild has said the volume can produce a field at
// all -- the callbacks this replaced checked the placement before
// touching a single point for the same reason.
rigExec::RigExecVolumeWeightInputs
_ReadVolumeWeightInputs(const VdfContext &ctx)
{
const TfToken &dense = _workerDense;
const TfToken &clamp = _workerClamp;
rigExec::RigExecVolumeWeightInputs inputs;
const TfToken *repr =
ctx.GetInputValuePtr<TfToken>(_tokens->representation);
const TfToken *policy = ctx.GetInputValuePtr<TfToken>(_tokens->rangePolicy);
inputs.representation = repr ? *repr : dense;
inputs.rangePolicy = policy ? *policy : clamp;
// The placement comes from computePointFrame, NOT computeMatrix; see
// RigExecRigidWorldToLocal for why that distinction is load bearing.
if (const RigExecPointFrame *posed =
ctx.GetInputValuePtr<RigExecPointFrame>(_tokens->selfMatrix)) {
inputs.placement = *posed;
inputs.hasPlacement = true;
}
inputs.params = _ReadFalloffParams(ctx);
return inputs;
}
// The weighted domain and, when authored, the shape it is sampled on.
void
_ReadVolumeWeightPoints(const VdfContext &ctx,
rigExec::RigExecVolumeWeightInputs *inputs)
{
inputs->targetPoints = _CollectPoints(ctx, _tokens->weightTargetPoints);
inputs->samplePoints = _CollectPoints(ctx, _tokens->sampleSourcePoints);
}
RigExecWeightPacket
_BuildSphereWeightPacket(const VdfContext &ctx)
{
const TfToken &sphereType = _workerSphereType;
rigExec::RigExecVolumeWeightInputs inputs = _ReadVolumeWeightInputs(ctx);
_ReadAxisScales(ctx, &inputs.scales);
inputs.positiveScales[0] = _Scalar(ctx, _tokens->inputsScaleXPos, 1.0f);
inputs.positiveScales[1] = _Scalar(ctx, _tokens->inputsScaleYPos, 1.0f);
inputs.positiveScales[2] = _Scalar(ctx, _tokens->inputsScaleZPos, 1.0f);
inputs.negativeScales[0] = _Scalar(ctx, _tokens->inputsScaleXNeg, 1.0f);
inputs.negativeScales[1] = _Scalar(ctx, _tokens->inputsScaleYNeg, 1.0f);
inputs.negativeScales[2] = _Scalar(ctx, _tokens->inputsScaleZNeg, 1.0f);
if (rigExec::RigExecVolumeWeightCanBuild(sphereType, inputs)) {
_ReadVolumeWeightPoints(ctx, &inputs);
}
return rigExec::RigExecBuildVolumeWeightPacket(sphereType, inputs);
}
RigExecWeightPacket
_BuildPlaneWeightPacket(const VdfContext &ctx)
{
const TfToken &planeType = _workerPlaneType;
const TfToken &yAxis = _workerYAxis;
const TfToken &unbounded = _workerUnbounded;
const TfToken &bounded = _workerBounded;
rigExec::RigExecVolumeWeightInputs inputs = _ReadVolumeWeightInputs(ctx);
const TfToken *axis = ctx.GetInputValuePtr<TfToken>(_tokens->planeAxisAttr);
const TfToken *bounds =
ctx.GetInputValuePtr<TfToken>(_tokens->planeBoundsAttr);
inputs.planeAxis = axis ? *axis : yAxis;
inputs.planeBounds = bounds ? *bounds : unbounded;
// Only the bounded arm consults the extents; an unbounded plane is an
// infinite half-space gradient and a bad extent on one is a
// legibility problem, not a reason to invalidate the rig.
if (inputs.planeBounds == bounded) {
inputs.extentU = _Scalar(ctx, _tokens->inputsExtentU, 1.0f);
inputs.extentV = _Scalar(ctx, _tokens->inputsExtentV, 1.0f);
}
if (rigExec::RigExecVolumeWeightCanBuild(planeType, inputs)) {
_ReadVolumeWeightPoints(ctx, &inputs);
}
return rigExec::RigExecBuildVolumeWeightPacket(planeType, inputs);
}
RigExecWeightPacket
_BuildCurveWeightPacket(const VdfContext &ctx)
{
const TfToken &curveType = _workerCurveType;
rigExec::RigExecVolumeWeightInputs inputs = _ReadVolumeWeightInputs(ctx);
_ReadAxisScales(ctx, &inputs.scales);
if (rigExec::RigExecVolumeWeightCanBuild(curveType, inputs)) {
_ReadVolumeWeightPoints(ctx, &inputs);
inputs.curvePoints = _CollectPoints(ctx, _tokens->curvePoints);
}
return rigExec::RigExecBuildVolumeWeightPacket(curveType, inputs);
}
RigExecWeightPacket
_BuildCombineWeightPacket(const VdfContext &ctx)
{
const TfToken &dense = _workerDense;
const TfToken &clamp = _workerClamp;
const TfToken &multiply = _workerMultiply;
const TfToken *repr =
ctx.GetInputValuePtr<TfToken>(_tokens->representation);
const TfToken *policy = ctx.GetInputValuePtr<TfToken>(_tokens->rangePolicy);
const TfToken *mode =
ctx.GetInputValuePtr<TfToken>(_tokens->combineModeAttr);
// Authored target order is preserved: subtract and overlay are order
// dependent by design (see the schema doc).
std::vector<const RigExecWeightPacket *> inputs;
{
VdfReadIterator<RigExecWeightPacket> it(ctx, _tokens->inputPackets);
for (; !it.IsAtEnd(); ++it) {
inputs.push_back(&*it);
}
}
// rigExec:weightTarget is only ever read for its SIZE, when no input
// is dense enough to carry the cardinality itself -- so take the size
// and never the points.
VdfReadIterator<GfVec3f> target(ctx, _tokens->weightTargetPoints);
return rigExec::RigExecBuildCombineWeightPacket(
repr ? *repr : dense, policy ? *policy : clamp, mode ? *mode : multiply,
inputs, target.ComputeSize(), _Scalar(ctx, _tokens->strengthAttr, 1.0f),
_Scalar(ctx, _tokens->inputsInvert, 0.0f));
}
RigExecBlendSampleData
_BuildBlendSampleData(const VdfContext &ctx)
{
RigExecBlendSampleData data;
const float *activation = ctx.GetInputValuePtr<float>(_tokens->activation);
data.activation = activation ? *activation : 1.0f;
VdfReadIterator<GfVec3f> it(ctx, _tokens->samplePoints);
data.points.reserve(it.ComputeSize());
for (; !it.IsAtEnd(); ++it) {
data.points.push_back(*it);
}
return data;
}
RigExecBlendChannel
_BuildBlendChannel(const VdfContext &ctx)
{
RigExecBlendChannel channel;
const float *weight = ctx.GetInputValuePtr<float>(_tokens->inputsWeight);
channel.weight = weight ? *weight : 0.0f;
VdfReadIterator<RigExecBlendSampleData> it(ctx, _tokens->sampleData);
for (; !it.IsAtEnd(); ++it) {
channel.samples.push_back(*it);
}
std::sort(
channel.samples.begin(), channel.samples.end(),
[](const RigExecBlendSampleData &x, const RigExecBlendSampleData &y) {
return x.activation < y.activation;
});
return channel;
}
// Mover-owned parameter packets (every concrete mover schema
// owns a statically registered computeMoverParameters). The compiler's
// compiler helpers (RigExecResolvedMatrix and friends) author
// the rigExec:resolved* relationships in the generated session layer,
// binding each declared dependency to exactly one catalogued provider.
// The matrix mover builder and registration live in
// movers/matrixMover.cpp with the rest of the matrix mover.
// The blend-shape mover builder and registration live in
// movers/blendShapeMover.cpp with the rest of the blend-shape mover.
// The stock v26.08 callback form for a point3f[] application:
// reads the preceding vector with VdfReadIterator, allocates/writes the
// result with stock VDF vector APIs, and references the prior input
// directly for disabled/failure pass-through. Each host's kernel is fixed
// by its application schema — there is no runtime operation dispatch
// (no universal array host).
// Gate shared by both hosts: the scalar computeMoverStatus decides
// whether the kernel may apply.
bool
_StatusAllowsApply(const VdfContext &ctx)
{
const rigExec::RigExecMoverStatus *status =
ctx.GetInputValuePtr<rigExec::RigExecMoverStatus>(_tokens->status);
return status && status->AllowsApply();
}
void
_EvaluateMatrixPointArrayExpression(const VdfContext &ctx)
{
const RigExecMoverParameters *params =
ctx.GetInputValuePtr<RigExecMoverParameters>(_tokens->parameters);
VdfReadIterator<GfVec3f> previous(ctx, _tokens->previous);
const size_t count = previous.ComputeSize();
auto passThrough = [&ctx]() {
ctx.SetOutputToReferenceInput(_tokens->previous);
};
if (!_StatusAllowsApply(ctx) || !params || !params->valid ||
params->kind != "matrix") {
passThrough();
return;
}
// Resolve the common envelope first so a cardinality failure passes
// through before any output is written.
std::vector<float> weights;
if (!params->weights.ResolveAll(count, &weights)) {
passThrough();
return;
}
// CPU SIMD over the contiguous elements (spec 6.5): parity-gated
// against the scalar reference; RIGEXEC_ENABLE_SIMD=false forces the
// scalar path for debugging.
auto out = VdfReadWriteIterator<GfVec3f>::Allocate(ctx, count);
if (rigExec::RigExecSimdEnabled()) {
std::vector<GfVec3f> scratch;
scratch.reserve(count);
for (; !previous.IsAtEnd(); ++previous) {
scratch.push_back(*previous);
}
rigExec::RigExecApplyWeightedMatrixSimd(scratch.data(), scratch.data(),
weights.data(), count,
params->transform);
size_t i = 0;
for (; !out.IsAtEnd(); ++out, ++i) {
*out = scratch[i];
}
} else {
size_t i = 0;
for (; !previous.IsAtEnd(); ++previous, ++out, ++i) {
*out = GfVec3f(rigExec::RigExecApplyWeightedMatrix(
GfVec3d(*previous), params->transform, weights[i]));
}
}
}
void
_EvaluateBlendPointArrayExpression(const VdfContext &ctx)
{
const RigExecMoverParameters *params =
ctx.GetInputValuePtr<RigExecMoverParameters>(_tokens->parameters);
VdfReadIterator<GfVec3f> previous(ctx, _tokens->previous);
const size_t count = previous.ComputeSize();
auto passThrough = [&ctx]() {
ctx.SetOutputToReferenceInput(_tokens->previous);
};
if (!_StatusAllowsApply(ctx) || !params || !params->valid ||
params->kind != "blendShape") {
passThrough();
return;
}
if (params->blendDeltas.size() != count) {
passThrough();
return;
}
std::vector<float> envelope;
if (!params->weights.ResolveAll(count, &envelope)) {
passThrough();
return;
}
auto out = VdfReadWriteIterator<GfVec3f>::Allocate(ctx, count);
size_t i = 0;
for (; !previous.IsAtEnd(); ++previous, ++out, ++i) {
const GfVec3f preceding = *previous;
*out = rigExec::RigExecBlendEnvelope(
preceding, preceding + params->blendDeltas[i], envelope[i]);
}
}
// The smooth mover builder and registration live in
// movers/smoothMover.cpp with the rest of the smooth mover.
// The volume-correct mover builder and registration live in
// movers/volumeCorrectMover.cpp with the rest of the volume-correct mover.
// The lattice mover builder and registration live in
// movers/latticeMover.cpp with the rest of the lattice mover.
// The surface mover builder and registration live in
// movers/surfaceMover.cpp with the rest of the surface mover.
// The curve mover builder and registration live in
// movers/curveMover.cpp with the rest of the curve mover.
// Shared scratch-collect / kernel / write-back body for point3f[] hosts
// (transient scratch is released before the callback returns).
template <typename Kernel>
void
_EvaluateScratchKernel(const VdfContext &ctx, const TfToken &expectedKind,
Kernel &&kernel)
{
const RigExecMoverParameters *params =
ctx.GetInputValuePtr<RigExecMoverParameters>(_tokens->parameters);
VdfReadIterator<GfVec3f> previous(ctx, _tokens->previous);
auto passThrough = [&ctx]() {
ctx.SetOutputToReferenceInput(_tokens->previous);
};
if (!_StatusAllowsApply(ctx) || !params || !params->valid ||
params->kind != expectedKind) {
passThrough();
return;
}
std::vector<GfVec3f> scratch;
scratch.reserve(previous.ComputeSize());
for (; !previous.IsAtEnd(); ++previous) {
scratch.push_back(*previous);
}
const std::vector<GfVec3f> preceding = scratch;
if (!kernel(*params, &scratch)) {
passThrough();
return;
}
if (scratch.size() != preceding.size()) {
passThrough();
return;
}
std::vector<float> envelope;
if (!params->weights.ResolveAll(scratch.size(), &envelope)) {
passThrough();
return;
}
for (size_t i = 0; i < scratch.size(); ++i) {
scratch[i] = rigExec::RigExecBlendEnvelope(preceding[i], scratch[i],
envelope[i]);
}
auto out = VdfReadWriteIterator<GfVec3f>::Allocate(ctx, scratch.size());
size_t i = 0;
for (; !out.IsAtEnd(); ++out, ++i) {
*out = scratch[i];
}
}
// normal3f[] host: recomputed vertex normals from final same-generation
// points and standard topology.
// float3[] host: recomputed two-element extent from final points and the
// authoritative winning widths.
// RigExecRibbon solver: rotation-minimizing frame samples along the
// driver curve, published with paired rest frames. The rest
// driver points are the compiler-captured bind-time curve value.
// The sampling itself is RigExecSampleRibbonFrames, which the baked program
// calls as well; only the reads below are exec's.
RigExecPointFrameArray
_ComputeRibbonFrames(const VdfContext &ctx)
{
const int *countPtr = ctx.GetInputValuePtr<int>(_tokens->sampleCountAttr);
const int sampleCount = countPtr ? *countPtr : 5;
const RigExecPointsPacket *const posedPtr =
ctx.GetInputValuePtr<RigExecPointsPacket>(_tokens->driverPoints);
const RigExecPointsPacket *const restPtr =
ctx.GetInputValuePtr<RigExecPointsPacket>(_tokens->restDriver);
const std::vector<GfVec3f> posed =
posedPtr ? posedPtr->points : std::vector<GfVec3f>();
const std::vector<GfVec3f> rest =
restPtr ? restPtr->points : std::vector<GfVec3f>();
// The joints' rest references, in rigExec:joints order, and which of
// them a pose step BELOW the ribbon wrote (RigExecPointFrameLiveRest).
// A live one re-bases its sample so the step's frame is carried through
// the ribbon instead of replaced (spec 4.2); every other sample keeps the
// rest curve, which is what leaves an unstacked ribbon untouched.
std::vector<std::array<GfVec3d, 4>> jointRests;
std::vector<bool> jointRestLive;
{
VdfReadIterator<RigExecPointFrame> it(ctx, _tokens->jointRests);
for (; !it.IsAtEnd(); ++it) {
jointRests.push_back((*it).points);
jointRestLive.push_back(
((*it).flags & rigExec::RigExecPointFrameLiveRest) != 0);
}
}
return rigExec::RigExecSampleRibbonFrames(posed, rest, sampleCount,
jointRests, jointRestLive);
}
} // namespace
// Weight objects publish computeWeightPacket.
EXEC_REGISTER_COMPUTATIONS_FOR_SCHEMA(RigExecStaticWeight)
{
self.PrimComputation(_tokens->computeWeightPacket)
.Callback<RigExecWeightPacket>(&_BuildStaticWeightPacket)
.Inputs(AttributeValue<TfToken>(_tokens->representation),
AttributeValue<TfToken>(_tokens->rangePolicy),
AttributeValue<float>(_tokens->values),
AttributeValue<int>(_tokens->indices),
AttributeValue<float>(_tokens->defaultWeight));
}
EXEC_REGISTER_COMPUTATIONS_FOR_SCHEMA(RigExecDynamicWeight)
{
self.PrimComputation(_tokens->computeWeightPacket)
.Callback<RigExecWeightPacket>(&_BuildDynamicWeightPacket)
.Inputs(AttributeValue<TfToken>(_tokens->representation),
AttributeValue<TfToken>(_tokens->rangePolicy),
AttributeValue<float>(_tokens->inputsDriver),
AttributeValue<float>(_tokens->inputsScale),
AttributeValue<float>(_tokens->inputsBias),
Relationship(_tokens->baseWeight)
.TargetedObjects<RigExecWeightPacket>(
_tokens->computeWeightPacket)
.InputName(_tokens->basePacket));
}
// Volumetric weight objects.
// computeFalloffLut is a STUB that returns an empty (linear) table. The
// real bake -- a named analytic profile, or the resampled spline authored
// on rigExec:falloffCurve -- arrives as a RigExecValueOverride supplied
// once per compiled rig by the evaluator (see RigExecFalloffLut in
// types.h).
// The shared inputs are spelled out per concrete type rather than shared
// through a macro over the abstract base: the three shapes genuinely
// differ in what they read, and a registration that lied about its inputs
// would silently miss an invalidation.
#define RIGEXEC_VOLUME_WEIGHT_COMMON_INPUTS \
AttributeValue<TfToken>(_tokens->representation), \
AttributeValue<TfToken>(_tokens->rangePolicy), \
AttributeValue<float>(_tokens->falloffMin), \
AttributeValue<float>(_tokens->falloffMax), \
AttributeValue<float>(_tokens->inputsInvert), \
AttributeValue<float>(_tokens->strengthAttr), \
Computation<RigExecPointFrame>(_tokens->computePointFrame) \
.InputName(_tokens->selfMatrix) \
.Required(), \
Computation<rigExec::RigExecFalloffLut>(_tokens->computeFalloffLut) \
.InputName(_tokens->falloffLut), \
Relationship(_tokens->weightTargetRel) \
.TargetedObjects<GfVec3f>(ExecBuiltinComputations->computeValue) \
.InputName(_tokens->weightTargetPoints), \
Relationship(_tokens->sampleSourceRel) \
.TargetedObjects<GfVec3f>(ExecBuiltinComputations->computeValue) \
.InputName(_tokens->sampleSourcePoints)
#define RIGEXEC_VOLUME_WEIGHT_AXIS_SCALES \
AttributeValue<float>(_tokens->inputsScaleX), \
AttributeValue<float>(_tokens->inputsScaleY), \
AttributeValue<float>(_tokens->inputsScaleZ)
// The stub the evaluator overrides. Registered per concrete type for the
// same reason the packets are.
#define RIGEXEC_REGISTER_FALLOFF_LUT_STUB \
self.PrimComputation(_tokens->computeFalloffLut) \
.Callback<rigExec::RigExecFalloffLut>( \
+[](const VdfContext &) { return rigExec::RigExecFalloffLut(); })
EXEC_REGISTER_COMPUTATIONS_FOR_SCHEMA(RigExecSphereWeight)
{
RIGEXEC_REGISTER_FALLOFF_LUT_STUB;
self.PrimComputation(_tokens->computeWeightPacket)
.Callback<RigExecWeightPacket>(&_BuildSphereWeightPacket)
.Inputs(RIGEXEC_VOLUME_WEIGHT_COMMON_INPUTS,
RIGEXEC_VOLUME_WEIGHT_AXIS_SCALES,
AttributeValue<float>(_tokens->inputsScaleXPos),
AttributeValue<float>(_tokens->inputsScaleYPos),
AttributeValue<float>(_tokens->inputsScaleZPos),
AttributeValue<float>(_tokens->inputsScaleXNeg),
AttributeValue<float>(_tokens->inputsScaleYNeg),
AttributeValue<float>(_tokens->inputsScaleZNeg));
}
EXEC_REGISTER_COMPUTATIONS_FOR_SCHEMA(RigExecPlaneWeight)
{
RIGEXEC_REGISTER_FALLOFF_LUT_STUB;
self.PrimComputation(_tokens->computeWeightPacket)
.Callback<RigExecWeightPacket>(&_BuildPlaneWeightPacket)
.Inputs(RIGEXEC_VOLUME_WEIGHT_COMMON_INPUTS,
AttributeValue<TfToken>(_tokens->planeAxisAttr),
AttributeValue<TfToken>(_tokens->planeBoundsAttr),
AttributeValue<float>(_tokens->inputsExtentU),
AttributeValue<float>(_tokens->inputsExtentV));
}
EXEC_REGISTER_COMPUTATIONS_FOR_SCHEMA(RigExecCurveWeight)
{
RIGEXEC_REGISTER_FALLOFF_LUT_STUB;
self.PrimComputation(_tokens->computeWeightPacket)
.Callback<RigExecWeightPacket>(&_BuildCurveWeightPacket)
.Inputs(
RIGEXEC_VOLUME_WEIGHT_COMMON_INPUTS,
RIGEXEC_VOLUME_WEIGHT_AXIS_SCALES,
Relationship(_tokens->curveRel)
.TargetedObjects<GfVec3f>(ExecBuiltinComputations->computeValue)
.InputName(_tokens->curvePoints));
}
#undef RIGEXEC_REGISTER_FALLOFF_LUT_STUB
#undef RIGEXEC_VOLUME_WEIGHT_AXIS_SCALES
#undef RIGEXEC_VOLUME_WEIGHT_COMMON_INPUTS
EXEC_REGISTER_COMPUTATIONS_FOR_SCHEMA(RigExecCombineWeight)
{
self.PrimComputation(_tokens->computeWeightPacket)
.Callback<RigExecWeightPacket>(&_BuildCombineWeightPacket)
.Inputs(
AttributeValue<TfToken>(_tokens->representation),
AttributeValue<TfToken>(_tokens->rangePolicy),
AttributeValue<TfToken>(_tokens->combineModeAttr),
AttributeValue<float>(_tokens->strengthAttr),
AttributeValue<float>(_tokens->inputsInvert),
Relationship(_tokens->inputWeightsRel)
.TargetedObjects<RigExecWeightPacket>(
_tokens->computeWeightPacket)
.InputName(_tokens->inputPackets),
// Only ever read for its SIZE, when no input is dense enough
// to carry the cardinality itself.
Relationship(_tokens->weightTargetRel)
.TargetedObjects<GfVec3f>(ExecBuiltinComputations->computeValue)
.InputName(_tokens->weightTargetPoints));
}
// Blend descriptors.
EXEC_REGISTER_COMPUTATIONS_FOR_SCHEMA(RigExecBlendSample)
{
self.PrimComputation(_tokens->computeBlendSampleData)
.Callback<RigExecBlendSampleData>(&_BuildBlendSampleData)
.Inputs(
AttributeValue<float>(_tokens->activation),
Relationship(_tokens->targetPoints)
.TargetedObjects<GfVec3f>(ExecBuiltinComputations->computeValue)
.InputName(_tokens->samplePoints)
.Required());
}
EXEC_REGISTER_COMPUTATIONS_FOR_SCHEMA(RigExecBlendInput)
{
self.PrimComputation(_tokens->computeBlendChannel)
.Callback<RigExecBlendChannel>(&_BuildBlendChannel)
.Inputs(AttributeValue<float>(_tokens->inputsWeight),
Relationship(_tokens->samples)
.TargetedObjects<RigExecBlendSampleData>(
_tokens->computeBlendSampleData)
.InputName(_tokens->sampleData)
.Required());
}
// Operation/type-specific property applications: each
// host's frozen signature consumes the preceding exact-typed vector, the
// realizing mover's computeMoverParameters, and computeMoverStatus.
// RigExecPointFrameMoverApplication: one writer revision of a transform
// provider's point frame, publishing paired views.
// RigExecRibbon solver: frame samples from the driver curve.
EXEC_REGISTER_COMPUTATIONS_FOR_SCHEMA(RigExecRibbon)
{
// Driver-curve points, live and at bind time, as boxed single values.
// These callbacks return EMPTY and are meant to be overridden: the
// evaluator resolves rigExec:driverCurve to the target's points and
// supplies both, the same way a solver-bound joint's frame is supplied.
// A ribbon whose driver cannot be resolved therefore samples an empty
// curve and publishes no frames, rather than silently using stale data.
// Two exec constraints force this shape. A relationship accessor can
// request computations on its TARGETS but not a named attribute of them,
// so the points cannot be reached from the ribbon prim. And an override
// of a `point3f[]` attribute is type-checked against the ELEMENT type,
// so an array cannot be handed over that way -- hence the packet.
self.PrimComputation(_tokens->computeDriverPoints)
.Callback<RigExecPointsPacket>(
+[](const VdfContext &) { return RigExecPointsPacket(); });
self.PrimComputation(_tokens->computeRestDriverPoints)
.Callback<RigExecPointsPacket>(
+[](const VdfContext &) { return RigExecPointsPacket(); });
self.PrimComputation(_tokens->computePointFrameArray)
.Callback<rigExec::RigExecPointFrameArray>(&_ComputeRibbonFrames)
// Both point arrays arrive as VALUE OVERRIDES on schema-declared
// attributes, never from authored scene description. The evaluator
// resolves rigExec:driverCurve to the target's points attribute and
// supplies the live and bind-time values, exactly as a solver-bound
// joint receives its frame -- which is what let the last authoring
// pass, and the derived stage that held it, be deleted.
// A Relationship accessor cannot do this job: TargetedObjects
// requests a computation on the TARGETS, and rigExec:driverCurve
// targets the curve prim, not its points attribute.
.Inputs(
AttributeValue<int>(_tokens->sampleCountAttr),
Relationship(_tokens->joints)
.TargetedObjects<RigExecPointFrame>(_tokens->computeRestFrame)
.InputName(_tokens->jointRests),
Computation<RigExecPointsPacket>(_tokens->computeRestDriverPoints)
.InputName(_tokens->restDriver),
Computation<RigExecPointsPacket>(_tokens->computeDriverPoints)
.InputName(_tokens->driverPoints));
}
// Operation/type-specific Phase 3 property applications:
// each host's frozen signature consumes the preceding exact-typed vector,
// the realizing mover's computeMoverParameters, and computeMoverStatus.
#define RIGEXEC_REGISTER_ARRAY_HOST(HostSchema, KernelFn) \
EXEC_REGISTER_COMPUTATIONS_FOR_SCHEMA(HostSchema) \
{ \
self.AttributeExpression(_tokens->outputsExpression) \
.Callback<GfVec3f>(&KernelFn) \
.Inputs( \
Connections<GfVec3f>(ExecBuiltinComputations->computeValue) \
.InputName(_tokens->previous) \
.Required(), \
Prim() \
.Relationship(_tokens->moverRel) \
.TargetedObjects<RigExecMoverParameters>( \
_tokens->computeMoverParameters) \
.InputName(_tokens->parameters) \
.Required(), \
Prim() \
.Relationship(_tokens->moverRel) \
.TargetedObjects<rigExec::RigExecMoverStatus>( \
_tokens->computeMoverStatus) \
.InputName(_tokens->status) \
.Required()); \
}
// Synthesized derived-maintenance hosts: the host is
// self-realized — the compiler points rigExec:mover at the host itself,
// so the standard rel wiring resolves the host-owned parameter/status
// computations declared here.
#define RIGEXEC_REGISTER_DERIVED_HOST(HostSchema, KernelFn, ParamsFn) \
EXEC_REGISTER_COMPUTATIONS_FOR_SCHEMA(HostSchema) \
{ \
self.AttributeExpression(_tokens->outputsExpression) \
.Callback<GfVec3f>(&KernelFn) \
.Inputs( \
Connections<GfVec3f>(ExecBuiltinComputations->computeValue) \
.InputName(_tokens->previous) \
.Required(), \
Prim() \
.Relationship(_tokens->moverRel) \
.TargetedObjects<RigExecMoverParameters>( \
_tokens->computeMoverParameters) \
.InputName(_tokens->parameters) \
.Required(), \
Prim() \
.Relationship(_tokens->moverRel) \
.TargetedObjects<rigExec::RigExecMoverStatus>( \
_tokens->computeMoverStatus) \
.InputName(_tokens->status) \
.Required()); \
\
self.PrimComputation(_tokens->computeMoverParameters) \
.Callback<RigExecMoverParameters>(&ParamsFn) \
.Inputs(Relationship(_tokens->resolvedFinalPoints) \
.TargetedObjects<GfVec3f>( \
ExecBuiltinComputations->computeValue) \
.InputName(_tokens->finalPoints), \
Relationship(_tokens->resolvedTopologyCounts) \
.TargetedObjects<int>( \
ExecBuiltinComputations->computeValue) \
.InputName(_tokens->topologyCounts), \
Relationship(_tokens->resolvedTopologyIndices) \
.TargetedObjects<int>( \
ExecBuiltinComputations->computeValue) \
.InputName(_tokens->topologyIndices), \
Relationship(_tokens->resolvedWidths) \
.TargetedObjects<float>( \
ExecBuiltinComputations->computeValue) \
.InputName(_tokens->widthsInput)); \
\
self.PrimComputation(_tokens->computeMoverStatus) \
.Callback<rigExec::RigExecMoverStatus>( \
&rigExec::RigExecMoverBuildStatus) \
.Inputs(Computation<RigExecMoverParameters>( \
_tokens->computeMoverParameters) \
.Required(), \
Computation<SdfPath>(ExecBuiltinComputations->computePath) \
.InputName(_tokens->moverPath)); \
}
#undef RIGEXEC_REGISTER_DERIVED_HOST
#undef RIGEXEC_REGISTER_ARRAY_HOST