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.
68 /// Each joint name must be unique.
72  const VtTokenArray& jointNames,
73  bool createLocomotionJoint = true);
74 
75 
76 /// Create a shape library where every skinning target of \p binding is
77 /// a separate shape.
78 /// The \p sev defines the error severity when reading in each shape.
79 /// If the severity is less than UT_ERROR_ABORT, the invalid shape is
80 /// skipped. Otherwise, creation of the shape lib fails if errors are
81 /// produced processing any shapes.
85  const char* lod=nullptr,
89  const GT_RefineParms* refineParms=nullptr);
90 
91 
92 /// Read in all skinnable shapes for \p binding, coalescing them into \p gd.
93 /// The \p sev defines the error severity when reading in each shape.
94 /// If the severity is less than UT_ERROR_ABORT, the invalid shape is
95 /// skipped. Otherwise, creation of the coalesced detail fails if errors are
96 /// produced processing any shapes.
97 GUSD_API bool
99  const UsdSkelBinding& binding,
101  const char* lod=nullptr,
105  const GT_RefineParms* refineParms=nullptr);
106 
107 
108 /// Read in a skinnable prim given by \p skinningQuery into \p gd.
109 /// The \p jointNames array provides the names of the joints of the bound
110 /// Skeleton, using the ordering specified on the Skeleton.
111 /// The \p invBindTransforms array holds the inverse of the Skeleton's
112 /// bind transforms.
113 /// Errors encountered while reading the skinnable primitive are reported
114 /// with a severity of \p sev.
115 GUSD_API bool
117  const UsdSkelSkinningQuery& skinningQuery,
118  const VtTokenArray& jointNames,
119  const VtMatrix4dArray& invBindTransforms,
121  const char* lod=nullptr,
125  const GT_RefineParms* refineParms=nullptr);
126 
127 
128 /// Read shapes for each shape in \p binding.
129 /// The \p sev defines the error severity when reading in each shape.
130 /// If the severity is less than UT_ERROR_ABORT, invalid shapes are
131 /// skipped, and an empty detail handle is stored in \p details for
132 /// the corresponding shape. Otherwise, the process returns false if
133 /// errors are encountered processing any shapes.
134 GUSD_API bool
136  UT_Array<GU_DetailHandle>& details,
138  const char* lod=nullptr,
142  const GT_RefineParms* refineParms=nullptr);
143 
144 /// Create the boneCapture attribute on the geometry.
145 /// Requires the skel:jointIndices and skel:jointWeights primvars to have been
146 /// imported as attributes, unless the geometry is rigidly deformed.
147 GUSD_API bool
149  const UsdSkelSkinningQuery &skinningQuery,
150  const VtTokenArray &jointNames,
151  const VtMatrix4dArray &invBindTransforms);
152 
154 {
156  const char *myLOD = nullptr;
157  GusdPurposeSet myPurpose =
159  const GT_RefineParms *myRefineParms = nullptr;
160 };
161 
163  std::function<bool(exint i,
164  const GusdSkinImportParms &parms,
165  const VtTokenArray &jointNames,
166  const VtMatrix4dArray &invBindTransforms)>;
167 
168 /// Invokes the callback for each skinnable prim, possibly in parallel.
169 /// This can be used for customized importing of shapes.
170 GUSD_API bool
172  const GusdSkinImportParms &parms,
173  const GusdSkinnedPrimCallback &callback);
174 
175 /// Returns the skeleton's list of joint names, preferring the 'jointNames'
176 /// attribute over the 'joints' attribute.
177 GUSD_API bool
178 GusdGetJointNames(const UsdSkelSkeleton &skel, VtTokenArray &jointNames);
179 
181 
182 #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.
GLuint const GLchar * name
Definition: glew.h:1814
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
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:166
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:1346
GLint lod
Definition: glew.h:1385
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)
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)