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_Function.h>
48 #include <UT/UT_StringArray.h>
49 
50 class GT_RefineParms;
51 
53 
54 class UsdSkelBinding;
55 class UsdSkelSkeleton;
58 class UsdSkelTopology;
59 
60 
61 /// Create an agent rig from a \p skelQuery.
64  const UsdSkelSkeletonQuery& skelQuery,
65  bool createLocomotionJoint = true);
66 
67 
68 /// Create an agent rig from \p topology and \p jointNames, and optionally
69 /// including \p restXforms (rest transforms in local space).
70 /// Each joint name must be unique.
74  const VtTokenArray& jointNames,
75  const VtMatrix4dArray* restXforms = nullptr,
76  bool createLocomotionJoint = true);
77 
78 
79 /// Create a shape library where every skinning target of \p binding is
80 /// a separate shape.
81 /// The \p sev defines the error severity when reading in each shape.
82 /// If the severity is less than UT_ERROR_ABORT, the invalid shape is
83 /// skipped. Otherwise, creation of the shape lib fails if errors are
84 /// produced processing any shapes.
88  const char* lod=nullptr,
92  const GT_RefineParms* refineParms=nullptr);
93 
94 
95 /// Read in all skinnable shapes for \p binding, coalescing them into \p gd.
96 /// The \p sev defines the error severity when reading in each shape.
97 /// If the severity is less than UT_ERROR_ABORT, the invalid shape is
98 /// skipped. Otherwise, creation of the coalesced detail fails if errors are
99 /// produced processing any shapes.
100 GUSD_API bool
102  const UsdSkelBinding& binding,
104  const char* lod=nullptr,
108  const GT_RefineParms* refineParms=nullptr);
109 
110 
111 /// Read in a skinnable prim given by \p skinningQuery into \p gd.
112 /// The \p jointNames array provides the names of the joints of the bound
113 /// Skeleton, using the ordering specified on the Skeleton.
114 /// The \p invBindTransforms array holds the inverse of the Skeleton's
115 /// bind transforms.
116 /// Errors encountered while reading the skinnable primitive are reported
117 /// with a severity of \p sev.
118 GUSD_API bool
120  const UsdSkelSkinningQuery& skinningQuery,
121  const VtTokenArray& jointNames,
122  const VtMatrix4dArray& invBindTransforms,
124  const char* lod=nullptr,
128  const GT_RefineParms* refineParms=nullptr);
129 
130 
131 /// Read shapes for each shape in \p binding.
132 /// The \p sev defines the error severity when reading in each shape.
133 /// If the severity is less than UT_ERROR_ABORT, invalid shapes are
134 /// skipped, and an empty detail handle is stored in \p details for
135 /// the corresponding shape. Otherwise, the process returns false if
136 /// errors are encountered processing any shapes.
137 GUSD_API bool
139  UT_Array<GU_DetailHandle>& details,
141  const char* lod=nullptr,
145  const GT_RefineParms* refineParms=nullptr);
146 
147 /// Create the boneCapture attribute on the geometry.
148 /// Requires the skel:jointIndices and skel:jointWeights primvars to have been
149 /// imported as attributes, unless the geometry is rigidly deformed.
150 GUSD_API bool
152  const UsdSkelSkinningQuery &skinningQuery,
153  const VtTokenArray &jointNames,
154  const VtMatrix4dArray &invBindTransforms);
155 
157 {
159  const char *myLOD = nullptr;
160  GusdPurposeSet myPurpose =
162  const GT_RefineParms *myRefineParms = nullptr;
163 };
164 
166  UT_Function<bool(exint i,
167  const GusdSkinImportParms &parms,
168  const VtTokenArray &jointNames,
169  const VtMatrix4dArray &invBindTransforms)>;
170 
171 /// Invokes the callback for each skinnable prim, possibly in parallel.
172 /// This can be used for customized importing of shapes.
173 GUSD_API bool
175  const GusdSkinImportParms &parms,
176  const GusdSkinnedPrimCallback &callback);
177 
178 /// Returns the skeleton's list of joint names, preferring the 'jointNames'
179 /// attribute over the 'joints' attribute.
180 GUSD_API bool
181 GusdGetJointNames(const UsdSkelSkeleton &skel, VtTokenArray &jointNames);
182 
184 
185 #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:101
GT_API const UT_StringHolder time
UT_Function< bool(exint i, const GusdSkinImportParms &parms, const VtTokenArray &jointNames, const VtMatrix4dArray &invBindTransforms)> GusdSkinnedPrimCallback
Definition: agentUtils.h:169
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)
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)
GLuint const GLchar * name
Definition: glcorearb.h:786
std::function< T > UT_Function
Definition: UT_Function.h:37
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:1441
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)