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  // Approximate bounds for the skinned result, if isSkinning() is true.
58  // Otherwise, use the authored extents if there are only blendshapes.
59  const UT_BoundingBox &getSkinnedBounds() const { return mySkinnedBounds; }
60 
62  { return mySkinningXformAttr; }
63 
65  { return myBlendShapeWeightAttr; }
66 
67  const GT_DataArrayHandle &getBoneIdxAttr() const { return myBoneIdxAttr; }
68 
70  { return myBoneWeightAttr; }
71 
73  { return myRestPointsAttr; }
74 
76  { return myBlendShapeOffsetsAttr; }
77 
78 private:
79  // Begining of methods and data for constructing
80  // skinning data arrays.
81  bool mySkinning = false;
82 
83  bool mySkinningCacheValid = false;
84  bool myBlendShapeCacheValid = false;
85 
86  HdDirtyBits myCachedDirtyBits = Clean;
87 
88  // Scene Inputs
89  GT_DataArrayHandle mySkinningXformAttr;
90  GT_DataArrayHandle myBlendShapeWeightAttr;
91  UT_BoundingBox mySkinnedBounds;
92 
93  // Computation Inputs
94  GT_DataArrayHandle myBoneIdxAttr;
95  GT_DataArrayHandle myBoneWeightAttr;
96  GT_DataArrayHandle myRestPointsAttr;
97  GT_DataArrayHandle myBlendShapeOffsetsAttr;
98 
99  // Determines if this computation node is a skinning operation
100  bool hasSkinningComputation(HdSceneDelegate *scene_delegate);
101 
102  // Converts the skinning inputs from the format used by
103  // HdExtComputationUtils::GetComputedPrimvarValues to a format that
104  // is understood by the GLSL shaders
105  void parseInfluences(
106  const bool is_rigid_skinning,
107  const int num_influences_per_comp,
108  const int num_pnts_on_mesh,
109  const VtArray<GfVec2f> &influence_arr);
110 
111  void parseSkinningXForms(
112  const VtArray<GfMatrix4f> &x_forms,
113  const GfMatrix4f &skel_to_prim_local);
114 
115  void parseBlendShapeWeights(const VtArray<fpreal32> &weights);
116 
117  // Checks if there are any dirty flags, if so invokes
118  // fetchSceneInputs/fetchComputationInputs
119  void buildDataArrays(HdSceneDelegate *scene_delegate);
120 
121  // Gets the scene inputs and store them in the source_comp
122  void fetchSceneInputs(HdSceneDelegate *scene_delegate);
123 
124  // Gets the computation inputs and store them in the source_comp
125  void fetchComputationInputs(HdSceneDelegate *scene_delegate);
126 
127  // apply the geo_xform onto the rest_points and assigns it to
128  // myRestPointsAttr
129  void setupRestPoints(
130  const int num_pnts,
131  const GfMatrix4f &geo_bind_xform,
132  VtVec3fArray &rest_points);
133 
134  void setupBlendShapes(
135  HdSceneDelegate *scene_delegate,
136  const int num_pnts,
137  TfSpan<const GfVec4f> blend_offsets,
138  TfSpan<const GfVec2i> blend_ranges);
139 
140  // End of methods and data for constructing
141  // skinning data arrays.
142 };
143 
145 
146 #endif // HUSD_HydraComputation_h
bool isSkinning(HdSceneDelegate *scene_delegate)
const GT_DataArrayHandle & getBlendShapeWeightAttr() const
uint32_t HdDirtyBits
Definition: types.h:158
const GT_DataArrayHandle & getBlendShapeOffsetsAttr() const
const GT_DataArrayHandle & getSkinningXformAttr() const
Definition: span.h:87
const GT_DataArrayHandle & getRestPointsAttr() const
void Sync(HdSceneDelegate *sceneDelegate, HdRenderParam *renderParam, HdDirtyBits *dirtyBits) override
Definition: types.h:173
Definition: path.h:291
~XUSD_HydraExtComputation() override
const UT_BoundingBox & getSkinnedBounds() const
const GT_DataArrayHandle & getBoneWeightAttr() const
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1441
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
const GT_DataArrayHandle & getBoneIdxAttr() const
XUSD_HydraExtComputation(SdfPath const &id)
bool isBlendShape(HdSceneDelegate *scene_delegate)