All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
USD_XformCache.h
1 //
2 // Copyright 2017 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_USD_XFORMCACHE_H_
25 #define _GUSD_USD_XFORMCACHE_H_
26 
27 #include "gusd/api.h"
28 
29 #include "gusd/defaultArray.h"
30 #include "gusd/UT_CappedCache.h"
31 #include "gusd/USD_DataCache.h"
32 #include "gusd/USD_Utils.h"
33 
34 #include "pxr/pxr.h"
35 #include "pxr/usd/usdGeom/xformable.h"
36 
37 PXR_NAMESPACE_OPEN_SCOPE
38 
40 class GusdUSD_XformCache final : public GusdUSD_DataCache
41 {
42 public:
43 
44  GUSD_API
45  static GusdUSD_XformCache& GetInstance();
46 
49 
50  virtual ~GusdUSD_XformCache() {}
51 
52  bool GetLocalTransformation(const UsdPrim& prim,
53  UsdTimeCode time,
54  UT_Matrix4D& xform);
55 
56  bool GetLocalToWorldTransform(const UsdPrim& prim,
57  UsdTimeCode time,
58  UT_Matrix4D& xform);
59 
62  const UT_Array<UsdPrim>& prims,
63  const GusdDefaultArray<UsdTimeCode>& times,
64  UT_Matrix4D* xfroms);
65 
68  const UT_Array<UsdPrim>& prims,
69  const GusdDefaultArray<UsdTimeCode>& times,
70  UT_Matrix4D* xforms);
71 
72  /* Compute constraint transforms given a common constraint name
73  for all prims. Constraint transforms not cached.*/
74  bool GetConstraintTransforms(
75  const TfToken& constraint,
76  const UT_Array<UsdPrim>& prims,
77  const GusdDefaultArray<UsdTimeCode>& times,
78  UT_Matrix4D* xforms);
79 
80  /* Given tokens representing *full* names of attributes
81  (I.e., including the namespace), compute constraint transforms.
82  Constraint transforms not cached.*/
83  bool GetConstraintTransforms(
84  const UT_Array<TfToken>& constraints,
85  const UT_Array<UsdPrim>& prims,
86  const GusdDefaultArray<UsdTimeCode>& times,
87  UT_Matrix4D* xforms);
88 
89  struct XformInfo : public UT_CappedItem
90  {
91  enum Flags
92  {
93  FLAGS_LOCAL_MAYBE_TIMEVARYING=0x1,
94  FLAGS_WORLD_MAYBE_TIMEVARYING=0x2,
95  FLAGS_HAS_PARENT_XFORM=0x4
96  };
97 
98  XformInfo(const UsdGeomXformable& xf)
99  : UT_CappedItem(), query(xf), _flags(0) {}
100 
101  virtual ~XformInfo() {}
102 
103  virtual int64 getMemoryUsage() const { return sizeof(*this); }
104 
105  void ComputeFlags(const UsdPrim& prim,
106  GusdUSD_XformCache& cache);
107 
108  SYS_FORCE_INLINE bool LocalXformIsMaybeTimeVarying() const
109  { return _flags&FLAGS_LOCAL_MAYBE_TIMEVARYING; }
110 
111  SYS_FORCE_INLINE bool WorldXformIsMaybeTimeVarying() const
112  { return _flags&FLAGS_WORLD_MAYBE_TIMEVARYING; }
113 
114  SYS_FORCE_INLINE bool HasParentXform() const
115  { return _flags&FLAGS_HAS_PARENT_XFORM; }
116 
117  const UsdGeomXformable::XformQuery query;
118  private:
119  int _flags;
120  };
121  typedef UT_IntrusivePtr<const XformInfo> XformInfoHandle;
122 
123 
124  GUSD_API
125  XformInfoHandle GetXformInfo(const UsdPrim& prim);
126 
127  GUSD_API
128  virtual void Clear() override;
129 
130  GUSD_API
131  virtual int64 Clear(const UT_StringSet& paths) override;
132 
133 private:
134  bool _GetLocalTransformation(const UsdPrim& prim,
135  UsdTimeCode time,
136  UT_Matrix4D& xform,
137  const XformInfoHandle& info);
138 
139 
140 
141 private:
142  GusdUT_CappedCache _xforms, _worldXforms, _xformInfos;
143 };
144 
145 PXR_NAMESPACE_CLOSE_SCOPE
146 
147 #endif /*_GUSD_USD_XFORMCACHE_H_*/
bool GetLocalToWorldTransforms(const UT_Array< UsdPrim > &prims, const GusdDefaultArray< UsdTimeCode > &times, UT_Matrix4D *xforms)
Compute multiple world transforms in parallel.
Cache for USD stages.
Definition: stageCache.h:54
bool GetLocalTransformations(const UT_Array< UsdPrim > &prims, const GusdDefaultArray< UsdTimeCode > &times, UT_Matrix4D *xfroms)
Compute multiple local transforms in parallel.
Helper class that caches the ordered vector of UsGeomXformOps that contribute to the local transforma...
Definition: xformable.h:377
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:89
Concurrent memory-capped cache for primitive transforms.
Represent a time value, which may be either numeric, holding a double value, or a sentinel value UsdT...
Definition: timeCode.h:85
UsdPrim is the sole persistent scenegraph object on a UsdStage, and is the embodiment of a &quot;Prim&quot; as ...
Definition: prim.h:131
Variant of UT_CappedCache that improves on item construction.
Base class for all transformable prims, which allows arbitrary sequences of component affine transfor...
Definition: xformable.h:252