Repository navigation
Expand file tree
/
Copy pathcomputations.cpp
More file actions
1413 lines (1334 loc) · 67.7 KB
/
Copy pathcomputations.cpp
File metadata and controls
1413 lines (1334 loc) · 67.7 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
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// RigExec OpenExec computation registrations.
// Every semantically addressable transform provider publishes paired
// computePointFrame / computeMatrix. Packed solver boundaries publish the
// aggregate computePointFrameArray; scalar scene-addressable providers
// (joints, views) consume the aggregate and publish scalar frames.
#include "rigExecSchema/schemaNames.h"
#include "types.h"
#include "frameExtraction.h"
#include "solverKernels.h"
#include "rigExecMath/avarScale.h"
#include "rigExecMath/pointFrame.h"
#include "rigExecMath/solvers.h"
#include "rigExecMath/splineIk.h"
#include "pxr/pxr.h"
#include "pxr/base/gf/math.h"
#include "pxr/base/gf/rotation.h"
#include "pxr/base/gf/vec4d.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>
#include <limits>
using rigExec::RigExecPointFrame;
using rigExec::RigExecPointFrameArray;
// EXEC_REGISTER_COMPUTATIONS_FOR_SCHEMA opens/closes the pxr namespace
// itself, so this file stays at global scope with a using-directive.
PXR_NAMESPACE_USING_DIRECTIVE
TF_DEFINE_PRIVATE_TOKENS(
_tokens,
// Computation names.
(computePointFrame)
(computeMatrix)
(computeRestFrame)
(computeDefaultFrame)
(computePointFrameArray)
(computedDefaultSpace)
(computedParentDefaultSpace)
(computedParentSpace)
(computedAvarDefaultSpace)
(computedPosedDefaultSpace)
(rawSpace)
(connectedSpace)
(fallbackSpace)
(parentDefaultFrame)
// Input names.
(parentFrame)
(controlFrames)
(controlRests)
(rootFrame)
(rootRest)
(effectorFrame)
(effectorRest)
(poleFrame)
(inputAFrames)
(inputBFrames)
(startFrame)
(startRest)
(endFrame)
(endRest)
(midFrame)
(midRest)
(jointRests)
// Attribute tokens.
((controls, rigExec::SchemaAttrText::rigExecControls))
((controlSpace, rigExec::SchemaAttrText::rigExecControlSpace))
((controlSpaceWorld, rigExec::SchemaValueText::world))
((controlSpaceParentRelative, rigExec::SchemaValueText::parentRelative))
((rootControl, rigExec::SchemaAttrText::rigExecRootControl))
((effectorControl, rigExec::SchemaAttrText::rigExecEffectorControl))
((poleControl, rigExec::SchemaAttrText::rigExecPoleControl))
((preferredBendRadians, rigExec::SchemaAttrText::rigExecPreferredBendRadians))
((inputA, rigExec::SchemaAttrText::rigExecInputA))
((inputB, rigExec::SchemaAttrText::rigExecInputB))
((rotationBlend, rigExec::SchemaAttrText::rigExecRotationBlend))
((scaleBlend, rigExec::SchemaAttrText::rigExecScaleBlend))
((startRel, rigExec::SchemaAttrText::rigExecStart))
((startFrameRel, rigExec::SchemaAttrText::rigExecStartFrame))
((endRel, rigExec::SchemaAttrText::rigExecEnd))
((weights, rigExec::SchemaAttrText::rigExecWeights))
((count, rigExec::SchemaAttrText::rigExecCount))
((twistTurns, rigExec::SchemaAttrText::inputsTwistTurns))
((joints, rigExec::SchemaAttrText::rigExecJoints))
((jointElements, rigExec::SchemaAttrText::rigExecJointElements))
((space, rigExec::SchemaAttrText::rigExecSpace))
((spaceFrame, "spaceFrame"))
((spaceRest, "spaceRest"))
((spaceMatrix, rigExec::SchemaAttrText::rigExecSpaceMatrix))
((upperLengthOffset, rigExec::SchemaAttrText::rigExecUpperLengthOffset))
((lowerLengthOffset, rigExec::SchemaAttrText::rigExecLowerLengthOffset))
((inputsWeight, rigExec::SchemaAttrText::inputsWeight))
((inputsStretch, rigExec::SchemaAttrText::inputsStretch))
((inputsSoftness, rigExec::SchemaAttrText::inputsSoftness))
((inputsPin, rigExec::SchemaAttrText::inputsPin))
((inputsUpperScale, rigExec::SchemaAttrText::inputsUpperScale))
((inputsLowerScale, rigExec::SchemaAttrText::inputsLowerScale))
((inputsSoftDistance, rigExec::SchemaAttrText::inputsSoftDistance))
((scaleCalibration, rigExec::SchemaAttrText::rigExecScaleCalibration))
((stretchPolicy, rigExec::SchemaAttrText::rigExecStretchPolicy))
((segmentScale, rigExec::SchemaAttrText::rigExecSegmentScale))
((softDistance, rigExec::SchemaValueText::softDistance))
((toChild, rigExec::SchemaValueText::toChild))
((midControl, rigExec::SchemaAttrText::rigExecMidControl))
((endControl, rigExec::SchemaAttrText::rigExecEndControl))
((volumeWeights, rigExec::SchemaAttrText::rigExecVolumeWeights))
((restLength, rigExec::SchemaAttrText::rigExecRestLength))
((inputsPreserveVolume, rigExec::SchemaAttrText::inputsPreserveVolume))
((inputsMidFollowWeight, rigExec::SchemaAttrText::inputsMidFollowWeight))
((inputsMinLengthRatio, rigExec::SchemaAttrText::inputsMinLengthRatio))
((rootTangent, rigExec::SchemaAttrText::rigExecRootTangent))
((inputsRoll, rigExec::SchemaAttrText::inputsRoll))
((inputsTwist, rigExec::SchemaAttrText::inputsTwist))
// Ir-aligned joint contract (IrXformable mirror).
((restSpace, rigExec::SchemaAttrText::restSpace))
((posedSpace, rigExec::SchemaAttrText::posedSpace))
((restTx, rigExec::SchemaAttrText::restTx))
((restTy, rigExec::SchemaAttrText::restTy))
((restTz, rigExec::SchemaAttrText::restTz))
((restRx, rigExec::SchemaAttrText::restRx))
((restRy, rigExec::SchemaAttrText::restRy))
((restRz, rigExec::SchemaAttrText::restRz))
((defaultSpace, rigExec::SchemaAttrText::defaultSpace))
((defaultTx, rigExec::SchemaAttrText::defaultTx))
((defaultTy, rigExec::SchemaAttrText::defaultTy))
((defaultTz, rigExec::SchemaAttrText::defaultTz))
((defaultRx, rigExec::SchemaAttrText::defaultRx))
((defaultRy, rigExec::SchemaAttrText::defaultRy))
((defaultRz, rigExec::SchemaAttrText::defaultRz))
((posedDefaultSpace, rigExec::SchemaAttrText::posedDefaultSpace))
((avarDefaultSpace, rigExec::SchemaAttrText::avarsDefaultSpace))
((avarUnitScaleFactor, rigExec::SchemaAttrText::avarsUnitScaleFactor))
((parentSpace, rigExec::SchemaAttrText::parentSpace))
((parentDefaultSpace, rigExec::SchemaAttrText::parentDefaultSpace))
((avarTx, rigExec::SchemaAttrText::avarsTx))
((avarTy, rigExec::SchemaAttrText::avarsTy))
((avarTz, rigExec::SchemaAttrText::avarsTz))
((avarSx, rigExec::SchemaAttrText::avarsSx))
((avarSy, rigExec::SchemaAttrText::avarsSy))
((avarSz, rigExec::SchemaAttrText::avarsSz))
((avarRx, rigExec::SchemaAttrText::avarsRx))
((avarRy, rigExec::SchemaAttrText::avarsRy))
((avarRz, rigExec::SchemaAttrText::avarsRz))
((avarRspin, rigExec::SchemaAttrText::avarsRspin))
((avarRotationOrder, rigExec::SchemaAttrText::avarsRotationOrder))
((avarRotationSign, rigExec::SchemaAttrText::avarsRotationSign))
(posedConnected)
(parentPosedFrame)
(parentRestFrame)
(selfRestFrame)
);
namespace {
const TfToken _avarOrderXYZ(rigExec::SchemaValueText::xyz);
const GfVec3d _avarAxes[3] = {GfVec3d(1, 0, 0), GfVec3d(0, 1, 0),
GfVec3d(0, 0, 1)};
std::array<GfVec3d, 4>
_IdentityLandmarks()
{
return {GfVec3d(0, 0, 0), GfVec3d(1, 0, 0), GfVec3d(0, 1, 0),
GfVec3d(0, 0, 1)};
}
} // namespace
// RigExecControl and RigExecJoint both register the shared Ir-xformable
// computations below: animation lives on avars / posed:space, and the rest
// frame comes from rest:space plus the rest avars. There is no landmark-based
// provider path.
// RigExecJoint (IrXformable mirror):
// matrix4d rest/posed spaces with scalar avars. A solver-posed joint's frame
// arrives as a value override from RigExecRigEvaluator (exec cannot traverse
// the solver's rigExec:joints backwards, so the binding lives in the compiled
// graph); otherwise the posed space comes from a posed:space connection, and
// an unconnected joint follows its namespace-parent joint's posed space with
// its local rest offset and avars applied. Point frames stay the internal
// value type: the spaces convert to landmark frames at this boundary.
static double
_ScalarInput(const VdfContext &ctx, const TfToken &name, double fallback)
{
const double *value = ctx.GetInputValuePtr<double>(name);
return value ? *value : fallback;
}
// Composes a local avar transform: per-axis scale, rotations applied in
// avars:rotationOrder sequence, rspin about the +X aim axis, then translation
// (row-vector convention: leftmost factor applies first).
static GfMatrix4d
_ComposeAvars(double tx, double ty, double tz, double sx, double sy, double sz,
double rx, double ry, double rz, double rspin,
const TfToken &order)
{
const auto &axes = _avarAxes;
const double angles[3] = {rx, ry, rz};
std::string sequence = order.GetString();
if (sequence.size() != 3) {
sequence = rigExec::SchemaValueText::xyz;
}
GfMatrix4d m(1.0);
m.SetScale(GfVec3d(rigExec::RigExecNormalizeAvarScale(sx),
rigExec::RigExecNormalizeAvarScale(sy),
rigExec::RigExecNormalizeAvarScale(sz)));
for (const char axis : sequence) {
const int index = axis == 'X' ? 0 : axis == 'Y' ? 1 : 2;
if (angles[index] != 0.0) {
m = m *
GfMatrix4d(GfRotation(axes[index], angles[index]), GfVec3d(0));
}
}
if (rspin != 0.0) {
m = m * GfMatrix4d(GfRotation(axes[0], rspin), GfVec3d(0));
}
GfMatrix4d t(1.0);
t.SetTranslate(GfVec3d(tx, ty, tz));
return m * t;
}
// Shared with RigExecRigEvaluator, which extracts joint frames directly from
// a solver's aggregate using its in-memory binding (frameExtraction.h). One
// definition, so the two paths cannot drift.
static RigExecPointFrame
_FrameFromMatrix(const GfMatrix4d &m)
{
return rigExec::RigExecFrameFromMatrix(m);
}
// The selected aggregate element's posed frame as a local-to-world matrix:
// normalized posed axes scaled by the posed/rest axis-length ratios (rest
// spaces are orthonormalized per the Ir contract, so the ratio is what
// carries stretch). Identity when the element is absent or degenerate.
// View-free per-element extraction of a solver aggregate element.
static GfMatrix4d
_ElementOutSpace(const RigExecPointFrameArray *source, size_t index)
{
return rigExec::RigExecElementOutSpace(source, index);
}
static GfMatrix4d
_SpaceFromFrame(const RigExecPointFrame *frame)
{
GfMatrix4d result(1.0);
if (frame) {
if (!frame->IsValid() || frame->IsDegenerate() ||
!rigExec::RigExecPointsToMatrix(_IdentityLandmarks(), frame->points,
&result)) {
// Missing ancestors select identity; an existing invalid frame
// must retain failure through the matrix-typed space expressions.
// FrameFromMatrix will classify this sentinel as degenerate.
result[3][0] = std::numeric_limits<double>::quiet_NaN();
}
}
return result;
}
// Rest space relative to the namespace frame provider: the authored
// rest:space with the rest avars as a preceding local delta (all-default
// avars leave rest:space authoritative), carried into the parent's rest
// frame. A provider with no RigExec ancestor resolves against identity --
// _SpaceFromFrame returns it for a null frame -- so a top-level rest keeps
// its authored local-to-world meaning.
static GfMatrix4d
_JointRestSpace(const VdfContext &ctx)
{
const GfMatrix4d *space =
ctx.GetInputValuePtr<GfMatrix4d>(_tokens->restSpace);
const GfMatrix4d local = _ComposeAvars(
_ScalarInput(ctx, _tokens->restTx, 0),
_ScalarInput(ctx, _tokens->restTy, 0),
_ScalarInput(ctx, _tokens->restTz, 0), 1.0, 1.0, 1.0,
_ScalarInput(ctx, _tokens->restRx, 0),
_ScalarInput(ctx, _tokens->restRy, 0),
_ScalarInput(ctx, _tokens->restRz, 0), 0.0, _avarOrderXYZ);
GfMatrix4d rest = local * (space ? *space : GfMatrix4d(1.0));
// Rest spaces are always orthonormalized (Ir contract). Orthonormalize
// the local factor BEFORE the parent multiply: the parent's frame is
// already orthonormal, so the product is too, and an invalid ancestor's
// NaN sentinel survives the multiply instead of being scrubbed by it.
rest.Orthonormalize(/* issueWarning = */ false);
return rest * _SpaceFromFrame(ctx.GetInputValuePtr<RigExecPointFrame>(
_tokens->parentRestFrame));
}
static RigExecPointFrame
_ComputeJointRestFrame(const VdfContext &ctx)
{
return _FrameFromMatrix(_JointRestSpace(ctx));
}
// Matrix spaces preserve the existing posed:space convention: a connection
// (including identity) is authoritative, a non-identity authored value is an
// explicit space, and the schema identity selects the computed fallback.
static GfMatrix4d
_ComputeSpaceExpression(const VdfContext &ctx)
{
if (const auto *connected =
ctx.GetInputValuePtr<GfMatrix4d>(_tokens->connectedSpace)) {
return *connected;
}
if (const auto *raw = ctx.GetInputValuePtr<GfMatrix4d>(_tokens->rawSpace)) {
if (*raw != GfMatrix4d(1.0))
return *raw;
}
const auto *fallback =
ctx.GetInputValuePtr<GfMatrix4d>(_tokens->fallbackSpace);
return fallback ? *fallback : GfMatrix4d(1.0);
}
static GfMatrix4d
_ComputeDefaultSpace(const VdfContext &ctx)
{
const GfMatrix4d rest = _SpaceFromFrame(
ctx.GetInputValuePtr<RigExecPointFrame>(_tokens->selfRestFrame));
const GfMatrix4d parentRest = _SpaceFromFrame(
ctx.GetInputValuePtr<RigExecPointFrame>(_tokens->parentRestFrame));
const auto *parentDefault =
ctx.GetInputValuePtr<GfMatrix4d>(_tokens->parentDefaultSpace);
const GfMatrix4d offset = _ComposeAvars(
_ScalarInput(ctx, _tokens->defaultTx, 0),
_ScalarInput(ctx, _tokens->defaultTy, 0),
_ScalarInput(ctx, _tokens->defaultTz, 0), 1, 1, 1,
_ScalarInput(ctx, _tokens->defaultRx, 0),
_ScalarInput(ctx, _tokens->defaultRy, 0),
_ScalarInput(ctx, _tokens->defaultRz, 0), 0, _avarOrderXYZ);
return offset * rest * parentRest.GetInverse() *
(parentDefault ? *parentDefault : GfMatrix4d(1.0));
}
static RigExecPointFrame
_ComputeXformablePointFrame(const VdfContext &ctx, bool readScaleAvars)
{
// A solver-posed joint never reaches this callback: RigExecRigEvaluator
// supplies its frame as a value override, because exec cannot traverse
// the solver's rigExec:joints backwards to find it. What remains here is
// every other way a joint gets posed.
// 1. Connected posed:space (a provider's out:space) is authoritative.
if (const GfMatrix4d *connected =
ctx.GetInputValuePtr<GfMatrix4d>(_tokens->posedConnected)) {
return _FrameFromMatrix(*connected);
}
// 2. A non-identity authored posed:space is used directly.
const GfMatrix4d *authored =
ctx.GetInputValuePtr<GfMatrix4d>(_tokens->posedSpace);
if (authored && *authored != GfMatrix4d(1.0)) {
return _FrameFromMatrix(*authored);
}
// 3. Start from the effective default pose, follow the selected parent,
// then apply local avars. With unmodified default channels this reduces
// exactly to avars * rest * parentRest^-1 * parentPosed.
const auto *defaultSpace =
ctx.GetInputValuePtr<GfMatrix4d>(_tokens->posedDefaultSpace);
const auto *parentDefault =
ctx.GetInputValuePtr<GfMatrix4d>(_tokens->parentDefaultSpace);
const auto *parentPosed =
ctx.GetInputValuePtr<GfMatrix4d>(_tokens->parentSpace);
const double units = _ScalarInput(ctx, _tokens->avarUnitScaleFactor, 1);
const TfToken *order =
ctx.GetInputValuePtr<TfToken>(_tokens->avarRotationOrder);
// avars:rotationSign mirrors a limb's rotation channels (see the schema).
// It multiplies the avar, never the frame, so it is the identity at rest.
const GfVec3d *signAvar =
ctx.GetInputValuePtr<GfVec3d>(_tokens->avarRotationSign);
const GfVec3d sign =
signAvar
? GfVec3d(rigExec::RigExecNormalizeRotationSign((*signAvar)[0]),
rigExec::RigExecNormalizeRotationSign((*signAvar)[1]),
rigExec::RigExecNormalizeRotationSign((*signAvar)[2]))
: GfVec3d(1, 1, 1);
const GfMatrix4d avars = _ComposeAvars(
_ScalarInput(ctx, _tokens->avarTx, 0) * units,
_ScalarInput(ctx, _tokens->avarTy, 0) * units,
_ScalarInput(ctx, _tokens->avarTz, 0) * units,
readScaleAvars ? _ScalarInput(ctx, _tokens->avarSx, 1) : 1.0,
readScaleAvars ? _ScalarInput(ctx, _tokens->avarSy, 1) : 1.0,
readScaleAvars ? _ScalarInput(ctx, _tokens->avarSz, 1) : 1.0,
_ScalarInput(ctx, _tokens->avarRx, 0) * sign[0],
_ScalarInput(ctx, _tokens->avarRy, 0) * sign[1],
_ScalarInput(ctx, _tokens->avarRz, 0) * sign[2],
_ScalarInput(ctx, _tokens->avarRspin, 0) * sign[0],
order ? *order : _avarOrderXYZ);
return _FrameFromMatrix(
avars * (defaultSpace ? *defaultSpace : GfMatrix4d(1.0)) *
(parentDefault ? parentDefault->GetInverse() : GfMatrix4d(1.0)) *
(parentPosed ? *parentPosed : GfMatrix4d(1.0)));
}
static RigExecPointFrame
_ComputeJointPointFrame(const VdfContext &ctx)
{
return _ComputeXformablePointFrame(ctx, /* readScaleAvars = */ true);
}
static RigExecPointFrame
_ComputeVolumeWeightPointFrame(const VdfContext &ctx)
{
// Volume shape is owned exclusively by inputs:scaleX/Y/Z. Its placement
// contract is rigid, so do not expose transform-scale avars as silent
// no-ops on RigExecVolumeWeight.
return _ComputeXformablePointFrame(ctx, /* readScaleAvars = */ false);
}
static GfMatrix4d
_ComputeJointMatrix(const VdfContext &ctx)
{
// The rest->posed target-local map: identical
// semantics to the landmark-based PointsToMatrix path.
const RigExecPointFrame *rest =
ctx.GetInputValuePtr<RigExecPointFrame>(_tokens->selfRestFrame);
const RigExecPointFrame *posed =
ctx.GetInputValuePtr<RigExecPointFrame>(_tokens->computePointFrame);
GfMatrix4d m(1.0);
if (!rest || !rest->IsValid() || !posed || !posed->IsValid()) {
ctx.Warn("joint computeMatrix: missing or degenerate frames");
return m;
}
rigExec::RigExecPointsToMatrix(rest->points, posed->points, &m);
return m;
}
#define RIGEXEC_AVAR_SCALE_INPUTS \
AttributeValue<double>(_tokens->avarSx), \
AttributeValue<double>(_tokens->avarSy), \
AttributeValue<double>(_tokens->avarSz),
#define RIGEXEC_NO_AVAR_SCALE_INPUTS
#define RIGEXEC_SPACE_EXPRESSION(AttributeToken, FallbackComputation) \
self.AttributeExpression(AttributeToken) \
.Callback<GfMatrix4d>(&_ComputeSpaceExpression) \
.Inputs(Computation<GfMatrix4d>( \
ExecBuiltinComputations->computeResolvedValue) \
.InputName(_tokens->rawSpace), \
Connections<GfMatrix4d>(ExecBuiltinComputations->computeValue) \
.InputName(_tokens->connectedSpace), \
Prim() \
.Computation<GfMatrix4d>(FallbackComputation) \
.InputName(_tokens->fallbackSpace));
#define RIGEXEC_REGISTER_XFORMABLE(SchemaName, PointFrameCallback, \
ScaleInputs) \
EXEC_REGISTER_COMPUTATIONS_FOR_SCHEMA(SchemaName) \
{ \
self.PrimComputation(_tokens->computeRestFrame) \
.Callback<RigExecPointFrame>(&_ComputeJointRestFrame) \
.Inputs(AttributeValue<GfMatrix4d>(_tokens->restSpace), \
AttributeValue<double>(_tokens->restTx), \
AttributeValue<double>(_tokens->restTy), \
AttributeValue<double>(_tokens->restTz), \
AttributeValue<double>(_tokens->restRx), \
AttributeValue<double>(_tokens->restRy), \
AttributeValue<double>(_tokens->restRz), \
NamespaceAncestor<RigExecPointFrame>( \
_tokens->computeRestFrame) \
.InputName(_tokens->parentRestFrame)); \
self.PrimComputation(_tokens->computedDefaultSpace) \
.Callback<GfMatrix4d>(&_ComputeDefaultSpace) \
.Inputs(Computation<RigExecPointFrame>(_tokens->computeRestFrame) \
.InputName(_tokens->selfRestFrame), \
NamespaceAncestor<RigExecPointFrame>( \
_tokens->computeRestFrame) \
.InputName(_tokens->parentRestFrame), \
AttributeValue<GfMatrix4d>(_tokens->parentDefaultSpace), \
AttributeValue<double>(_tokens->defaultTx), \
AttributeValue<double>(_tokens->defaultTy), \
AttributeValue<double>(_tokens->defaultTz), \
AttributeValue<double>(_tokens->defaultRx), \
AttributeValue<double>(_tokens->defaultRy), \
AttributeValue<double>(_tokens->defaultRz)); \
self.PrimComputation(_tokens->computeDefaultFrame) \
.Callback<RigExecPointFrame>(+[](const VdfContext &ctx) { \
return _FrameFromMatrix( \
ctx.GetInputValue<GfMatrix4d>(_tokens->defaultSpace)); \
}) \
.Inputs(AttributeValue<GfMatrix4d>(_tokens->defaultSpace)); \
self.PrimComputation(_tokens->computedParentDefaultSpace) \
.Callback<GfMatrix4d>(+[](const VdfContext &ctx) { \
return _SpaceFromFrame( \
ctx.GetInputValuePtr<RigExecPointFrame>( \
_tokens->parentDefaultFrame)); \
}) \
.Inputs(NamespaceAncestor<RigExecPointFrame>( \
_tokens->computeDefaultFrame) \
.InputName(_tokens->parentDefaultFrame)); \
self.PrimComputation(_tokens->computedParentSpace) \
.Callback<GfMatrix4d>(+[](const VdfContext &ctx) { \
return _SpaceFromFrame( \
ctx.GetInputValuePtr<RigExecPointFrame>( \
_tokens->parentPosedFrame)); \
}) \
.Inputs(NamespaceAncestor<RigExecPointFrame>( \
_tokens->computePointFrame) \
.InputName(_tokens->parentPosedFrame)); \
self.PrimComputation(_tokens->computedAvarDefaultSpace) \
.Callback<GfMatrix4d>(+[](const VdfContext &ctx) { \
return ctx.GetInputValue<GfMatrix4d>(_tokens->defaultSpace); \
}) \
.Inputs(AttributeValue<GfMatrix4d>(_tokens->defaultSpace)); \
self.PrimComputation(_tokens->computedPosedDefaultSpace) \
.Callback<GfMatrix4d>(+[](const VdfContext &ctx) { \
return ctx.GetInputValue<GfMatrix4d>( \
_tokens->avarDefaultSpace); \
}) \
.Inputs(AttributeValue<GfMatrix4d>(_tokens->avarDefaultSpace)); \
RIGEXEC_SPACE_EXPRESSION(_tokens->defaultSpace, \
_tokens->computedDefaultSpace) \
RIGEXEC_SPACE_EXPRESSION(_tokens->avarDefaultSpace, \
_tokens->computedAvarDefaultSpace) \
RIGEXEC_SPACE_EXPRESSION(_tokens->posedDefaultSpace, \
_tokens->computedPosedDefaultSpace) \
RIGEXEC_SPACE_EXPRESSION(_tokens->parentSpace, \
_tokens->computedParentSpace) \
RIGEXEC_SPACE_EXPRESSION(_tokens->parentDefaultSpace, \
_tokens->computedParentDefaultSpace) \
\
self.PrimComputation(_tokens->computePointFrame) \
.Callback<RigExecPointFrame>(PointFrameCallback) \
.Inputs(Attribute(_tokens->posedSpace) \
.Connections<GfMatrix4d>( \
ExecBuiltinComputations->computeValue) \
.InputName(_tokens->posedConnected), \
AttributeValue<GfMatrix4d>(_tokens->posedSpace), \
AttributeValue<GfMatrix4d>(_tokens->posedDefaultSpace), \
AttributeValue<GfMatrix4d>(_tokens->parentDefaultSpace), \
AttributeValue<GfMatrix4d>(_tokens->parentSpace), \
AttributeValue<double>(_tokens->avarUnitScaleFactor), \
AttributeValue<double>(_tokens->avarTx), \
AttributeValue<double>(_tokens->avarTy), \
AttributeValue<double>(_tokens->avarTz), \
ScaleInputs AttributeValue<double>(_tokens->avarRx), \
AttributeValue<double>(_tokens->avarRy), \
AttributeValue<double>(_tokens->avarRz), \
AttributeValue<double>(_tokens->avarRspin), \
AttributeValue<GfVec3d>(_tokens->avarRotationSign), \
AttributeValue<TfToken>(_tokens->avarRotationOrder)); \
\
self.PrimComputation(_tokens->computeMatrix) \
.Callback<GfMatrix4d>(&_ComputeJointMatrix) \
.Inputs(Computation<RigExecPointFrame>(_tokens->computePointFrame) \
.Required(), \
Computation<RigExecPointFrame>(_tokens->computeRestFrame) \
.InputName(_tokens->selfRestFrame) \
.Required()); \
}
RIGEXEC_REGISTER_XFORMABLE(RigExecJoint, &_ComputeJointPointFrame,
RIGEXEC_AVAR_SCALE_INPUTS)
RIGEXEC_REGISTER_XFORMABLE(RigExecControl, &_ComputeJointPointFrame,
RIGEXEC_AVAR_SCALE_INPUTS)
// The volumetric weight objects are RigExecXformables too, so they get the same placement contract: a
// volume authored inside a joint follows it through the same
// NamespaceAncestor chain, with nothing wired. Unlike controls and joints,
// it deliberately does not bind avars:sx/sy/sz: volume shape is authored only
// through inputs:scaleX/Y/Z, and its placement is rigidized by both evaluation
// and imaging.
// Registered ONCE on the ABSTRACT base, unlike the two above. Exec
// composes a prim's computation set by walking its full ancestor type
// vector strongest-to-weakest (exec/definitionRegistry.cpp
// _GetFullyExpandedSchemaTypeVector), so the three concrete volume
// weights inherit these three computations from RigExecVolumeWeight.
// It has to be the base rather than the concrete types, because the
// concrete types already carry an
// EXEC_REGISTER_COMPUTATIONS_FOR_SCHEMA block in moverKernels.cpp for
// computeWeightPacket, and one schema may only be opened once: the macro
// emits a whole registration function plus its TF_REGISTRY_FUNCTION per
// invocation, and a second block for the same schema is a second,
// independent registration pass over a type the first pass has already
// marked complete. Splitting by TYPE instead of by file keeps each
// schema opened exactly once.
RIGEXEC_REGISTER_XFORMABLE(RigExecVolumeWeight, &_ComputeVolumeWeightPointFrame,
RIGEXEC_NO_AVAR_SCALE_INPUTS)
#undef RIGEXEC_REGISTER_XFORMABLE
#undef RIGEXEC_SPACE_EXPRESSION
#undef RIGEXEC_NO_AVAR_SCALE_INPUTS
#undef RIGEXEC_AVAR_SCALE_INPUTS
// RigExecFkChain: applies control frames to a rest hierarchy. v0.1 treats
// the targeted control list as an ordered chain (each element's parent is
// the preceding element).
// rigExec:controlSpace says what a control's frame already contains.
// `world` (default): sibling controls, each frame carrying only its own
// delta A_i, composed here as W_i = W_(i-1) . A_i. `parentRelative`:
// controls nested one under the next, whose computePointFrame already
// travels with the parent control's posed frame (the NamespaceAncestor
// input of the xformable computations above), so the asset-space delta
// pose_i . rest_i^-1 IS W_i and composing the parent in again would apply
// its motion twice -- every element is solved as a chain root instead.
// The joints come out the same either way; only the control frames differ.
// rigExec:startFrame (optional) is the frame the chain HANGS FROM. Without
// it this solver is absolute: it composes control deltas onto the controls'
// own asset-space rests and nothing tells it that its joints live under,
// say, a wrist: in `a -> b -> c` with a chain over `[b, c]` only, posing `a`
// leaves b and c unmoved. With the relationship authored, the start provider's
// rest-to-pose delta S is PREPENDED as a synthetic element -- reusing the
// kernel rather than adding a case to it -- so W_0 = S . A_0 in `world`
// and W_i = S . A_i in `parentRelative` (where each delta is already the
// whole chain map, hence every real element parents onto the synthetic one
// rather than onto -1). The synthetic element's own frame is then DROPPED,
// which is what keeps the published cardinality equal to the control count
// and every joint's element index unchanged.
// The joints' rest references, in rigExec:joints order, and which of them a
// pose step BELOW this solver actually wrote (RigExecPointFrameLiveRest, set
// by the evaluator on the override it pushes). Only a live one re-bases its
// element; everything else keeps the basis the solver always had, which is
// what makes the rule free on every rig that does not stack (spec 4.2).
static void
_ReadJointRests(const VdfContext &ctx,
std::vector<std::array<GfVec3d, 4>> *rests,
std::vector<bool> *live)
{
VdfReadIterator<RigExecPointFrame> it(ctx, _tokens->jointRests);
for (; !it.IsAtEnd(); ++it) {
rests->push_back((*it).points);
live->push_back(((*it).flags & rigExec::RigExecPointFrameLiveRest) !=
0);
}
}
static RigExecPointFrameArray
_ComputeFkChain(const VdfContext &ctx)
{
// A frame/rest cardinality mismatch is a structural error: fail the
// whole solver explicitly instead of silently truncating.
VdfReadIterator<RigExecPointFrame> poseCount(ctx, _tokens->controlFrames);
VdfReadIterator<RigExecPointFrame> restCount(ctx, _tokens->controlRests);
if (poseCount.ComputeSize() != restCount.ComputeSize()) {
ctx.Warn("FkChain: control frame/rest cardinality mismatch (%zu/%zu)",
poseCount.ComputeSize(), restCount.ComputeSize());
return RigExecPointFrameArray();
}
// Unauthored or `world` keeps the linear parent chain; `parentRelative`
// makes every element its own root (see the header comment). An
// unknown token is reported and treated as `world`, so a typo degrades
// to the documented default rather than to an empty solve.
bool parentRelative = false;
if (const TfToken *space =
ctx.GetInputValuePtr<TfToken>(_tokens->controlSpace)) {
if (*space == _tokens->controlSpaceParentRelative) {
parentRelative = true;
} else if (!space->IsEmpty() && *space != _tokens->controlSpaceWorld) {
ctx.Warn("FkChain: unsupported controlSpace '%s'; using world",
space->GetText());
}
}
// The optional base frame. Both halves are needed to form a delta at
// all, so a start provider that published a pose but no rest is an
// authoring/compile gap worth naming rather than silently solving as
// if the chain were absolute again.
const RigExecPointFrame *start =
ctx.GetInputValuePtr<RigExecPointFrame>(_tokens->startFrame);
const RigExecPointFrame *startRest =
ctx.GetInputValuePtr<RigExecPointFrame>(_tokens->startRest);
if (start && !startRest) {
ctx.Warn("FkChain: rigExec:startFrame provider published no rest "
"frame; solving without it");
}
const bool hasStart = start && startRest;
// The joints' rest references, in rigExec:joints order. Under the
// unified pose stack each one is the frame the steps BELOW this solver
// left on that joint -- its authored rest when none did -- and it is the
// basis this chain composes its control deltas onto, so a constraint
// below the chain is carried through the solve instead of replaced.
// Used only when there is exactly one per control, which is the
// positional contract rigExec:joints[N] <- element N already has. A
// chain with no joints (a guide-only solver), or one whose targets do
// not all publish a rest, keeps the control's own rest as the basis and
// is bit-identical to what it was.
// A rest carrying RigExecPointFrameLiveRest is one a step BELOW this
// chain wrote; an ordinary authored rest is not, and the chain then keeps
// composing onto its control's own rest exactly as it always did. That
// gate is the bit-identity guarantee: it is not a performance trick, it
// is what stops the rule silently re-basing every FK rig whose controls
// do not sit exactly on their joints.
std::vector<std::array<GfVec3d, 4>> jointRests;
std::vector<bool> jointRestLive;
_ReadJointRests(ctx, &jointRests, &jointRestLive);
if (jointRests.size() != poseCount.ComputeSize()) {
jointRests.clear();
jointRestLive.clear();
}
std::vector<rigExec::RigExecFkChainElement> elements;
if (hasStart) {
// Synthetic element 0: rest and pose of the start provider, so the
// kernel's own rest->pose map for it IS S.
rigExec::RigExecFkChainElement e;
e.restPoints = startRest->points;
e.posePoints = start->points;
e.parentIndex = -1;
elements.push_back(e);
}
// Where real element i lands in the solved array, and therefore what
// "the element before me" and "chain root" mean. With no start frame
// this is 0 and the indices below are exactly the historical
// `index - 1` / `-1`.
const int base = hasStart ? 1 : 0;
VdfReadIterator<RigExecPointFrame> poseIt(ctx, _tokens->controlFrames);
VdfReadIterator<RigExecPointFrame> restIt(ctx, _tokens->controlRests);
int index = 0;
for (; !poseIt.IsAtEnd() && !restIt.IsAtEnd(); ++poseIt, ++restIt) {
rigExec::RigExecFkChainElement e;
e.restPoints = (*restIt).points;
e.posePoints = (*poseIt).points;
if (size_t(index) < jointRests.size() && jointRestLive[size_t(index)]) {
e.outRestPoints = jointRests[size_t(index)];
e.hasOutRest = true;
}
e.parentIndex = parentRelative ? base - 1 : index + base - 1;
elements.push_back(e);
++index;
}
RigExecPointFrameArray result;
result.frames = rigExec::RigExecSolveFkChain(elements);
const TfToken *segmentScale =
ctx.GetInputValuePtr<TfToken>(_tokens->segmentScale);
if (segmentScale && *segmentScale == _tokens->toChild) {
rigExec::RigExecScaleFkSegments(elements, &result.frames);
}
// Discard the synthetic base: it is a solve input, not an output, and
// publishing it would shift every joint's element index by one.
if (hasStart && !result.frames.empty()) {
result.frames.erase(result.frames.begin());
}
result.rests.reserve(elements.size() - size_t(base));
for (size_t i = size_t(base); i < elements.size(); ++i) {
// The published rest is the basis the frame was built on, so a
// consumer that re-solves against it (RigExecElementOutSpace, a
// blend) measures the same transform this kernel applied.
result.rests.push_back(elements[i].hasOutRest
? elements[i].outRestPoints
: elements[i].restPoints);
}
return result;
}
EXEC_REGISTER_COMPUTATIONS_FOR_SCHEMA(RigExecFkChain)
{
self.PrimComputation(_tokens->computePointFrameArray)
.Callback<RigExecPointFrameArray>(&_ComputeFkChain)
.Inputs(
Relationship(_tokens->controls)
.TargetedObjects<RigExecPointFrame>(_tokens->computePointFrame)
.InputName(_tokens->controlFrames)
.Required(),
Relationship(_tokens->controls)
.TargetedObjects<RigExecPointFrame>(_tokens->computeRestFrame)
.InputName(_tokens->controlRests)
.Required(),
// Optional by design: an unauthored relationship contributes no
// input, and the kernel then runs the historical absolute path.
Relationship(_tokens->startFrameRel)
.TargetedObjects<RigExecPointFrame>(_tokens->computePointFrame)
.InputName(_tokens->startFrame),
Relationship(_tokens->startFrameRel)
.TargetedObjects<RigExecPointFrame>(_tokens->computeRestFrame)
.InputName(_tokens->startRest),
// The output basis, one per joint: the unified pose stack
// overrides it with the frame the steps below this solver left
// (spec 4.2). Optional -- a guide-only chain names no joints.
Relationship(_tokens->joints)
.TargetedObjects<RigExecPointFrame>(_tokens->computeRestFrame)
.InputName(_tokens->jointRests),
AttributeValue<TfToken>(_tokens->controlSpace),
AttributeValue<TfToken>(_tokens->segmentScale));
}
// RigExecTwoBoneIk: analytic solve publishing [root, mid, end] frames.
static RigExecPointFrameArray
_ComputeTwoBoneIk(const VdfContext &ctx)
{
RigExecPointFrameArray result;
const RigExecPointFrame *root =
ctx.GetInputValuePtr<RigExecPointFrame>(_tokens->rootFrame);
const RigExecPointFrame *effector =
ctx.GetInputValuePtr<RigExecPointFrame>(_tokens->effectorFrame);
const RigExecPointFrame *pole =
ctx.GetInputValuePtr<RigExecPointFrame>(_tokens->poleFrame);
if (!root || !effector || !pole) {
return result;
}
rigExec::RigExecTwoBoneIkParams params;
const double *bend =
ctx.GetInputValuePtr<double>(_tokens->preferredBendRadians);
const float *stretch = ctx.GetInputValuePtr<float>(_tokens->inputsStretch);
const float *softness =
ctx.GetInputValuePtr<float>(_tokens->inputsSoftness);
const double *upperOff =
ctx.GetInputValuePtr<double>(_tokens->upperLengthOffset);
const double *lowerOff =
ctx.GetInputValuePtr<double>(_tokens->lowerLengthOffset);
const double upperOffset = upperOff ? *upperOff : 0.0;
const double lowerOffset = lowerOff ? *lowerOff : 0.0;
params.preferredBendRadians = bend ? *bend : 0.0;
params.stretch = stretch ? *stretch : 1.0;
params.softness = softness ? *softness : 0.0;
const auto scalar = [&](const TfToken &name, double fallback) {
const float *v = ctx.GetInputValuePtr<float>(name);
return v ? double(*v) : fallback;
};
const auto scalarDouble = [&](const TfToken &name, double fallback) {
const double *v = ctx.GetInputValuePtr<double>(name);
return v ? *v : fallback;
};
const TfToken *policy =
ctx.GetInputValuePtr<TfToken>(_tokens->stretchPolicy);
const TfToken *segmentScale =
ctx.GetInputValuePtr<TfToken>(_tokens->segmentScale);
params.softDistancePolicy = policy && *policy == _tokens->softDistance;
const double *calibration =
ctx.GetInputValuePtr<double>(_tokens->scaleCalibration);
params.limb.scaleCalibration = calibration ? *calibration : 0.0;
params.scaleSegments = segmentScale && *segmentScale == _tokens->toChild;
// Controls supply rest fallbacks while the solver is being wired. Once
// a joint is bound, its live rest frame is the reference for that output.
// In particular, the root joint's rest up controls the degenerate-pole
// fallback: reading only the root control's rest made a joint rest edit
// invisible to the solve even though the evaluator updated bone lengths.
const RigExecPointFrame *rootRest =
ctx.GetInputValuePtr<RigExecPointFrame>(_tokens->rootRest);
const RigExecPointFrame *effectorRest =
ctx.GetInputValuePtr<RigExecPointFrame>(_tokens->effectorRest);
std::array<std::array<GfVec3d, 4>, 3> rests;
rests[0] = rootRest ? rootRest->points : _IdentityLandmarks();
const GfVec3d restAim = (rests[0][1] - rests[0][0]).GetNormalized();
// Placeholder mid rest. Every bound joint's rest overwrites this
// below, and the solve bails if all three are not bound, so this
// only has to be a well-formed frame on the root's aim.
rests[1] = rests[0];
for (auto &p : rests[1]) {
p += restAim;
}
rests[2] = effectorRest ? effectorRest->points : _IdentityLandmarks();
// Which of [root, mid, end] a bound joint actually supplied a rest
// for; the control-derived defaults above are not measurable bones.
bool seen[3] = {false, false, false};
VdfReadIterator<RigExecPointFrame> jointRestIt(ctx, _tokens->jointRests);
VdfReadIterator<int> elementIt(ctx, _tokens->jointElements);
const bool remapped = elementIt.ComputeSize() != 0;
if (remapped && elementIt.ComputeSize() != jointRestIt.ComputeSize()) {
ctx.Warn("TwoBoneIk: joint/rest element cardinality mismatch");
return result;
}
size_t jointIndex = 0;
for (; !jointRestIt.IsAtEnd(); ++jointRestIt, ++jointIndex) {
const int element = remapped ? *elementIt : int(jointIndex);
if (remapped) {
++elementIt;
}
if (element < 0 || element >= 3) {
ctx.Warn("TwoBoneIk: joint element %d is out of range", element);
return result;
}
rests[element] = jointRestIt->points;
seen[element] = true;
}
// Bone lengths are MEASURED here, from the rests of the joints this
// solver names, plus the authored offsets. There is no absolute
// length attribute to author or to inject: rigExec:joints is the
// single declaration of the chain, and a solver whose joints are
// posed by a downstream consumer (an IK feeding an IK/FK blend)
// still names them for their rests -- the claim check treats a
// consumed solver's rigExec:joints as a rest reference, not an
// output claim, precisely so this measurement has an input.
if (!seen[0] || !seen[1] || !seen[2]) {
ctx.Warn("TwoBoneIk: needs three bound joint rests to measure its "
"bone lengths; rigExec:joints binds %d of 3",
int(seen[0]) + int(seen[1]) + int(seen[2]));
return result;
}
// MEASURE THE CHAIN IN THE SPACE THE GOAL IS IN. The rests are
// authored unscaled; the root, goal and pole arrive posed. Under a
// scaled master the goal is twice as far away while the chain keeps
// its authored length, so the solve clamps and the limb straightens.
// Carrying the rest points through rigExec:spaceMatrix puts both
// sides in one space; identity leaves the measurement exactly as it
// was. The authored offsets are lengths too, so they ride the same
// factor -- a chain that scales but whose offset does not would
// change proportion as the rig resizes, which is the thing scaling
// is supposed not to do.
const GfMatrix4d *spacePtr =
ctx.GetInputValuePtr<GfMatrix4d>(_tokens->spaceMatrix);
GfMatrix4d space = spacePtr ? *spacePtr : GfMatrix4d(1.0);
// rigExec:space names a prim -- a TRS master -- and what matters is
// how far it has moved from its own rest, so the space is
// rest-inverse-times-posed. A master sitting at rest contributes
// identity, which is why a rig that names nothing is unchanged.
const RigExecPointFrame *spacePosed =
ctx.GetInputValuePtr<RigExecPointFrame>(_tokens->spaceFrame);
const RigExecPointFrame *spaceRestFrame =
ctx.GetInputValuePtr<RigExecPointFrame>(_tokens->spaceRest);
if (spacePosed && spaceRestFrame) {
GfMatrix4d delta(1.0);
if (rigExec::RigExecPointsToMatrix(spaceRestFrame->points, *spacePosed,
&delta)) {
space = delta * space;
}
}
params.space = space;
rigExec::RigExecTwoBoneIkLengths(rests, space, upperOffset, lowerOffset,
¶ms.upperLength, ¶ms.lowerLength);
rigExec::RigExecSetTwoBoneLimbParams(
rests, space, params.stretch, scalar(_tokens->inputsPin, 0.0),
scalarDouble(_tokens->inputsUpperScale, 1.0),
scalarDouble(_tokens->inputsLowerScale, 1.0),
scalar(_tokens->inputsSoftDistance, 0.0),
scalar(_tokens->inputsTwist, 0.0), ¶ms);
const auto frames =
rigExec::RigExecSolveTwoBoneIk(*root, *effector, *pole, rests, params);
result.frames.assign(frames.begin(), frames.end());
result.rests.assign(rests.begin(), rests.end());
return result;
}
EXEC_REGISTER_COMPUTATIONS_FOR_SCHEMA(RigExecTwoBoneIk)
{
self.PrimComputation(_tokens->computePointFrameArray)
.Callback<RigExecPointFrameArray>(&_ComputeTwoBoneIk)
.Inputs(
Relationship(_tokens->rootControl)
.TargetedObjects<RigExecPointFrame>(_tokens->computePointFrame)
.InputName(_tokens->rootFrame)
.Required(),
Relationship(_tokens->rootControl)
.TargetedObjects<RigExecPointFrame>(_tokens->computeRestFrame)
.InputName(_tokens->rootRest),
Relationship(_tokens->effectorControl)
.TargetedObjects<RigExecPointFrame>(_tokens->computePointFrame)
.InputName(_tokens->effectorFrame)
.Required(),
Relationship(_tokens->effectorControl)
.TargetedObjects<RigExecPointFrame>(_tokens->computeRestFrame)
.InputName(_tokens->effectorRest),
Relationship(_tokens->poleControl)
.TargetedObjects<RigExecPointFrame>(_tokens->computePointFrame)
.InputName(_tokens->poleFrame)
.Required(),
Relationship(_tokens->joints)
.TargetedObjects<RigExecPointFrame>(_tokens->computeRestFrame)
.InputName(_tokens->jointRests),
Relationship(_tokens->space)
.TargetedObjects<RigExecPointFrame>(_tokens->computePointFrame)
.InputName(_tokens->spaceFrame),
Relationship(_tokens->space)
.TargetedObjects<RigExecPointFrame>(_tokens->computeRestFrame)
.InputName(_tokens->spaceRest),
AttributeValue<int>(_tokens->jointElements),
AttributeValue<GfMatrix4d>(_tokens->spaceMatrix),
AttributeValue<double>(_tokens->upperLengthOffset),
AttributeValue<double>(_tokens->lowerLengthOffset),
AttributeValue<double>(_tokens->preferredBendRadians),
AttributeValue<float>(_tokens->inputsStretch),
AttributeValue<float>(_tokens->inputsSoftness),
AttributeValue<float>(_tokens->inputsPin),
AttributeValue<double>(_tokens->inputsUpperScale),
AttributeValue<double>(_tokens->inputsLowerScale),
AttributeValue<float>(_tokens->inputsSoftDistance),
AttributeValue<float>(_tokens->inputsTwist),
AttributeValue<TfToken>(_tokens->stretchPolicy),
AttributeValue<TfToken>(_tokens->segmentScale),
AttributeValue<double>(_tokens->scaleCalibration));
}
// RigExecBlendPointFrames: element-wise blend of two aggregates.
static RigExecPointFrameArray
_ComputeBlendPointFrames(const VdfContext &ctx)
{
const RigExecPointFrameArray *a =
ctx.GetInputValuePtr<RigExecPointFrameArray>(_tokens->inputAFrames);
const RigExecPointFrameArray *b =
ctx.GetInputValuePtr<RigExecPointFrameArray>(_tokens->inputBFrames);
if (!a) {
return b ? *b : RigExecPointFrameArray();