HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
agentUtils.h
Go to the documentation of this file.
1 //
2 // Copyright 2019 Pixar
3 //
4 // Licensed under the Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 #ifndef GUSD_AGENTUTILS_H
25 #define GUSD_AGENTUTILS_H
26 
27 /// \file agentUtils.h
28 /// \ingroup group_gusd_Agents
29 /// Utilities for translating agents to/from USD.
30 ///
31 /// These do not provide complete, automatic conversion to/from USD at this
32 /// stage. Rather, these utilities may be used to build out a conversion
33 /// pipeline, such as generating all of the various JSON files needed to
34 /// build out the components of GU_Agent primitives.
35 ///
36 
37 #include "api.h"
38 #include "purpose.h"
39 
40 #include "pxr/base/vt/array.h"
41 #include "pxr/usd/usd/timeCode.h"
42 
43 #include <GU/GU_AgentDefinition.h>
44 #include <GU/GU_AgentLayer.h>
45 #include <GU/GU_AgentRig.h>
46 #include <GU/GU_AgentShapeLib.h>
47 #include <UT/UT_StringArray.h>
48 
49 class GT_RefineParms;
50 
52 
53 class UsdSkelBinding;
54 class UsdSkelSkeleton;
57 class UsdSkelTopology;
58 
59 
60 /// Create an agent rig from a \p skelQuery.
63  const UsdSkelSkeletonQuery& skelQuery,
64  bool createLocomotionJoint = true);
65 
66 
67 /// Create an agent rig from \p topology and \p jointNames, and optionally
68 /// including \p restXforms (rest transforms in local space).
69 /// Each joint name must be unique.
73  const VtTokenArray& jointNames,
74  const VtMatrix4dArray* restXforms = nullptr,
75  bool createLocomotionJoint = true);
76 
77 
78 /// Create a shape library where every skinning target of \p binding is
79 /// a separate shape.
80 /// The \p sev defines the error severity when reading in each shape.
81 /// If the severity is less than UT_ERROR_ABORT, the invalid shape is
82 /// skipped. Otherwise, creation of the shape lib fails if errors are
83 /// produced processing any shapes.
87  const char* lod=nullptr,
91  const GT_RefineParms* refineParms=nullptr);
92 
93 
94 /// Read in all skinnable shapes for \p binding, coalescing them into \p gd.
95 /// The \p sev defines the error severity when reading in each shape.
96 /// If the severity is less than UT_ERROR_ABORT, the invalid shape is
97 /// skipped. Otherwise, creation of the coalesced detail fails if errors are
98 /// produced processing any shapes.
99 GUSD_API bool
101  const UsdSkelBinding& binding,
103  const char* lod=nullptr,
107  const GT_RefineParms* refineParms=nullptr);
108 
109 
110 /// Read in a skinnable prim given by \p skinningQuery into \p gd.
111 /// The \p jointNames array provides the names of the joints of the bound
112 /// Skeleton, using the ordering specified on the Skeleton.
113 /// The \p invBindTransforms array holds the inverse of the Skeleton's
114 /// bind transforms.
115 /// Errors encountered while reading the skinnable primitive are reported
116 /// with a severity of \p sev.
117 GUSD_API bool
119  const UsdSkelSkinningQuery& skinningQuery,
120  const VtTokenArray& jointNames,
121  const VtMatrix4dArray& invBindTransforms,
123  const char* lod=nullptr,
127  const GT_RefineParms* refineParms=nullptr);
128 
129 
130 /// Read shapes for each shape in \p binding.
131 /// The \p sev defines the error severity when reading in each shape.
132 /// If the severity is less than UT_ERROR_ABORT, invalid shapes are
133 /// skipped, and an empty detail handle is stored in \p details for
134 /// the corresponding shape. Otherwise, the process returns false if
135 /// errors are encountered processing any shapes.
136 GUSD_API bool
138  UT_Array<GU_DetailHandle>& details,
140  const char* lod=nullptr,
144  const GT_RefineParms* refineParms=nullptr);
145 
146 /// Create the boneCapture attribute on the geometry.
147 /// Requires the skel:jointIndices and skel:jointWeights primvars to have been
148 /// imported as attributes, unless the geometry is rigidly deformed.
149 GUSD_API bool
151  const UsdSkelSkinningQuery &skinningQuery,
152  const VtTokenArray &jointNames,
153  const VtMatrix4dArray &invBindTransforms);
154 
156 {
158  const char *myLOD = nullptr;
159  GusdPurposeSet myPurpose =
161  const GT_RefineParms *myRefineParms = nullptr;
162 };
163 
165  std::function<bool(exint i,
166  const GusdSkinImportParms &parms,
167  const VtTokenArray &jointNames,
168  const VtMatrix4dArray &invBindTransforms)>;
169 
170 /// Invokes the callback for each skinnable prim, possibly in parallel.
171 /// This can be used for customized importing of shapes.
172 GUSD_API bool
174  const GusdSkinImportParms &parms,
175  const GusdSkinnedPrimCallback &callback);
176 
177 /// Returns the skeleton's list of joint names, preferring the 'jointNames'
178 /// attribute over the 'joints' attribute.
179 GUSD_API bool
180 GusdGetJointNames(const UsdSkelSkeleton &skel, VtTokenArray &jointNames);
181 
183 
184 #endif // GUSD_AGENTUTILS_H
GUSD_API GU_AgentRigPtr GusdCreateAgentRig(const UT_StringHolder &name, const UsdSkelSkeletonQuery &skelQuery, bool createLocomotionJoint=true)
Create an agent rig from a skelQuery.
static constexpr UsdTimeCode EarliestTime()
Definition: timeCode.h:102
GT_API const UT_StringHolder time
int64 exint
Definition: SYS_Types.h:125
UT_ErrorSeverity
Definition: UT_Error.h:25
GLuint const GLchar * name
Definition: glcorearb.h:786
GUSD_API bool GusdForEachSkinnedPrim(const UsdSkelBinding &binding, const GusdSkinImportParms &parms, const GusdSkinnedPrimCallback &callback)
std::function< bool(exint i, const GusdSkinImportParms &parms, const VtTokenArray &jointNames, const VtMatrix4dArray &invBindTransforms)> GusdSkinnedPrimCallback
Definition: agentUtils.h:168
GT_API const UT_StringHolder topology
Wrapper around hboost::intrusive_ptr.
GUSD_API bool GusdCoalesceAgentShapes(GU_Detail &gd, const UsdSkelBinding &binding, UsdTimeCode time=UsdTimeCode::EarliestTime(), const char *lod=nullptr, GusdPurposeSet purpose=GusdPurposeSet(GUSD_PURPOSE_DEFAULT|GUSD_PURPOSE_PROXY), UT_ErrorSeverity sev=UT_ERROR_WARNING, const GT_RefineParms *refineParms=nullptr)
GUSD_API bool GusdReadSkinnablePrim(GU_Detail &gd, const UsdSkelSkinningQuery &skinningQuery, const VtTokenArray &jointNames, const VtMatrix4dArray &invBindTransforms, UsdTimeCode time=UsdTimeCode::EarliestTime(), const char *lod=nullptr, GusdPurposeSet purpose=GusdPurposeSet(GUSD_PURPOSE_DEFAULT|GUSD_PURPOSE_PROXY), UT_ErrorSeverity sev=UT_ERROR_ABORT, const GT_RefineParms *refineParms=nullptr)
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1394
GUSD_API bool GusdGetJointNames(const UsdSkelSkeleton &skel, VtTokenArray &jointNames)
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
#define GUSD_API
Definition: api.h:40
GUSD_API bool GusdCreateCaptureAttribute(GU_Detail &detail, const UsdSkelSkinningQuery &skinningQuery, const VtTokenArray &jointNames, const VtMatrix4dArray &invBindTransforms)
GusdPurposeSet
Definition: purpose.h:39
GUSD_API bool GusdReadSkinnablePrims(const UsdSkelBinding &binding, UT_Array< GU_DetailHandle > &details, UsdTimeCode time=UsdTimeCode::EarliestTime(), const char *lod=nullptr, GusdPurposeSet purpose=GusdPurposeSet(GUSD_PURPOSE_DEFAULT|GUSD_PURPOSE_PROXY), UT_ErrorSeverity sev=UT_ERROR_WARNING, const GT_RefineParms *refineParms=nullptr)
GLint lod
Definition: glcorearb.h:2765
GUSD_API GU_AgentShapeLibPtr GusdCreateAgentShapeLib(const UsdSkelBinding &binding, UsdTimeCode time=UsdTimeCode::EarliestTime(), const char *lod=nullptr, GusdPurposeSet purpose=GusdPurposeSet(GUSD_PURPOSE_DEFAULT|GUSD_PURPOSE_PROXY), UT_ErrorSeverity sev=UT_ERROR_WARNING, const GT_RefineParms *refineParms=nullptr)