HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
XUSD_HydraExtComputation.h
Go to the documentation of this file.
1 /*
2  * Copyright 2022 Side Effects Software Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * NAME: XUSD_HydraExtComputation.h (XUSD Library, C++)
17  *
18  * COMMENTS:
19  */
20 
21 #ifndef XUSD_HydraExtComputation_h
22 #define XUSD_HydraExtComputation_h
23 
25 #include <pxr/base/tf/span.h>
26 
27 #include <GT/GT_DataArray.h>
28 #include <UT/UT_BoundingBox.h>
29 
31 
33 {
34 public:
36 
37  ~XUSD_HydraExtComputation() override;
38 
39  void Sync(
40  HdSceneDelegate *sceneDelegate,
41  HdRenderParam *renderParam,
42  HdDirtyBits *dirtyBits) override;
43 
44  // This function should be invoked
45  // before calling getSkinningXformAttr(), getBoneIdxAttr(),
46  // getBoneWeightAttr() or getRestPointsAttr()
47  // since this method checks the dirty bits
48  // and updates those attributes in addition
49  // to returning whether we are performing
50  // a skinning computation
51  bool isSkinning(HdSceneDelegate *scene_delegate);
52 
53  // Similar to isSkinning, this method should
54  // be invoked before getBlendShapeAttr()
55  bool isBlendShape(HdSceneDelegate *scene_delegate);
56 
57  /// We don't have a good way to return approximate bounds for the skinned
58  /// result, so for now we just use the rest points' extents (which are
59  /// inaccurate if the skeleton has root motion). In the future we need a way
60  /// to access the SkelRoot's authored extents.
61  /// https://openusd.org//dev/api/_usd_skel__schemas.html#UsdSkel_SkelRoot
62  const UT_BoundingBox &getRestBounds() const { return myRestBounds; }
63 
65  { return mySkinningXformAttr; }
66 
68  { return myBlendShapeWeightAttr; }
69 
70  const GT_DataArrayHandle &getBoneIdxAttr() const { return myBoneIdxAttr; }
71 
73  { return myBoneWeightAttr; }
74 
76  { return myRestPointsAttr; }
77 
79  { return myBlendShapeOffsetsAttr; }
80 
81 private:
82  // Begining of methods and data for constructing
83  // skinning data arrays.
84  bool mySkinning = false;
85 
86  bool mySkinningCacheValid = false;
87  bool myBlendShapeCacheValid = false;
88 
89  HdDirtyBits myCachedDirtyBits = Clean;
90 
91  // Scene Inputs
92  GT_DataArrayHandle mySkinningXformAttr;
93  GT_DataArrayHandle myBlendShapeWeightAttr;
94  UT_BoundingBox myRestBounds;
95 
96  // Computation Inputs
97  GT_DataArrayHandle myBoneIdxAttr;
98  GT_DataArrayHandle myBoneWeightAttr;
99  GT_DataArrayHandle myRestPointsAttr;
100  GT_DataArrayHandle myBlendShapeOffsetsAttr;
101 
102  // Determines if this computation node is a skinning operation
103  bool hasSkinningComputation(HdSceneDelegate *scene_delegate);
104 
105  // Converts the skinning inputs from the format used by
106  // HdExtComputationUtils::GetComputedPrimvarValues to a format that
107  // is understood by the GLSL shaders
108  void parseInfluences(
109  const bool is_rigid_skinning,
110  const int num_influences_per_comp,
111  const int num_pnts_on_mesh,
112  const VtArray<GfVec2f> &influence_arr);
113 
114  void parseSkinningXForms(
115  const VtArray<GfMatrix4f> &x_forms,
116  const GfMatrix4f &skel_to_prim_local);
117 
118  void parseBlendShapeWeights(const VtArray<fpreal32> &weights);
119 
120  // Checks if there are any dirty flags, if so invokes
121  // fetchSceneInputs/fetchComputationInputs
122  void buildDataArrays(HdSceneDelegate *scene_delegate);
123 
124  // Gets the scene inputs and store them in the source_comp
125  void fetchSceneInputs(HdSceneDelegate *scene_delegate);
126 
127  // Gets the computation inputs and store them in the source_comp
128  void fetchComputationInputs(HdSceneDelegate *scene_delegate);
129 
130  // apply the geo_xform onto the rest_points and assigns it to
131  // myRestPointsAttr
132  void setupRestPoints(
133  const int num_pnts,
134  const GfMatrix4f &geo_bind_xform,
135  VtVec3fArray &rest_points);
136 
137  void setupBlendShapes(
138  HdSceneDelegate *scene_delegate,
139  const int num_pnts,
140  TfSpan<const GfVec4f> blend_offsets,
141  TfSpan<const GfVec2i> blend_ranges);
142 
143  // End of methods and data for constructing
144  // skinning data arrays.
145 };
146 
148 
149 #endif // HUSD_HydraComputation_h
bool isSkinning(HdSceneDelegate *scene_delegate)
const GT_DataArrayHandle & getBlendShapeWeightAttr() const
uint32_t HdDirtyBits
Definition: types.h:143
const UT_BoundingBox & getRestBounds() const
const GT_DataArrayHandle & getBlendShapeOffsetsAttr() const
const GT_DataArrayHandle & getSkinningXformAttr() const
Definition: span.h:70
const GT_DataArrayHandle & getRestPointsAttr() const
void Sync(HdSceneDelegate *sceneDelegate, HdRenderParam *renderParam, HdDirtyBits *dirtyBits) override
Definition: types.h:153
Definition: path.h:273
~XUSD_HydraExtComputation() override
const GT_DataArrayHandle & getBoneWeightAttr() const
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
const GT_DataArrayHandle & getBoneIdxAttr() const
XUSD_HydraExtComputation(SdfPath const &id)
bool isBlendShape(HdSceneDelegate *scene_delegate)