All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
utils.h
1 //
2 // Copyright 2016 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 PXRUSDKATANA_ATTRUTILS_H
25 #define PXRUSDKATANA_ATTRUTILS_H
26 
27 #include "pxr/pxr.h"
28 #include "usdKatana/attrMap.h"
29 #include "usdKatana/usdInPrivateData.h"
30 
31 #include "pxr/usd/usd/relationship.h"
32 
33 #include "pxr/usd/sdf/path.h"
34 #include "pxr/usd/sdf/types.h"
35 #include "pxr/base/vt/value.h"
36 
37 #include <FnAttribute/FnGroupBuilder.h>
38 #include <FnAttribute/FnDataBuilder.h>
39 #include <FnGeolib/op/FnGeolibOp.h>
40 
41 #include <type_traits>
42 #include <vector>
43 
44 namespace FnKat = Foundry::Katana;
45 
46 PXR_NAMESPACE_OPEN_SCOPE
47 
48 class UsdCollectionAPI;
49 
50 struct PxrUsdKatanaUtils {
51 
54  static double ReverseTimeSample(double sample);
55 
57  static void ConvertNumVertsToStartVerts( const std::vector<int> &numVertsVec,
58  std::vector<int> *startVertsVec );
59 
60  static void ConvertArrayToVector(const VtVec3fArray &a, std::vector<float> *r);
61 
64  static FnKat::Attribute ConvertVtValueToKatAttr( const VtValue & val,
65  bool asShaderParam = true);
66 
69  static FnKat::Attribute ConvertRelTargetsToKatAttr(
70  const UsdRelationship &rel,
71  bool asShaderParam = true);
72 
76  static void ConvertVtValueToKatCustomGeomAttr( const VtValue & val,
77  int elementSize,
78  const TfToken &roleName,
79  FnKat::Attribute *valueAttr,
80  FnKat::Attribute *inputTypeAttr,
81  FnKat::Attribute *elementSizeAttr );
82 
84  static bool IsAttributeVarying(const UsdAttribute &attr, double currentTime);
85 
93  static std::string GenerateShadingNodeHandle(
94  const UsdPrim& shadingNode);
95 
96  // Scan the model hierarchy for models with kind=camera.
97  static SdfPathVector FindCameraPaths( const UsdStageRefPtr& stage );
98 
100  static SdfPathVector FindLightPaths( const UsdStageRefPtr& stage );
101 
104  static std::string ConvertUsdPathToKatLocation(
105  const SdfPath &path,
106  const std::string &isolatePathString,
107  const std::string &rootPathString,
108  const std::string &sessionPathString = "",
109  bool allowOutsideIsolation = false);
110  static std::string ConvertUsdPathToKatLocation(
111  const SdfPath &path,
112  const PxrUsdKatanaUsdInPrivateData& data,
113  bool allowOutsideIsolation = false);
114  static std::string ConvertUsdPathToKatLocation(
115  const SdfPath &path,
116  const PxrUsdKatanaUsdInArgsRefPtr &usdInArgs,
117  bool allowOutsideIsolation = false);
118 
122  static std::string _GetDisplayGroup(
123  const UsdPrim &prim,
124  const SdfPath& path);
125  static std::string _GetDisplayName(const UsdPrim &prim);
126  static std::string ConvertUsdMaterialPathToKatLocation(
127  const SdfPath &path,
128  const PxrUsdKatanaUsdInPrivateData& data);
129 
130  // XXX: should move these into readModel.h maybe.
138  static bool ModelGroupIsAssembly(const UsdPrim &prim);
139 
140  // this finds prims with kind=subcomponent, increasingly used in complex
141  // Sets models.
142  static bool PrimIsSubcomponent(const UsdPrim &prim);
143 
147  static bool ModelGroupNeedsProxy(const UsdPrim &prim);
148 
150  static FnKat::GroupAttribute GetViewerProxyAttr(
151  const PxrUsdKatanaUsdInPrivateData& data);
152 
154  static FnKat::GroupAttribute GetViewerProxyAttr(
155  double currentTime,
156  const std::string & fileName,
157  const std::string & referencePath,
158  const std::string & rootLocation,
159  FnAttribute::GroupAttribute sessionAttr,
160  const std::string & ignoreLayerRegex);
161 
162 
165  static std::string GetAssetName(const UsdPrim& prim);
166 
169  static std::string GetModelInstanceName(const UsdPrim& prim);
170 
174  static bool IsModelAssemblyOrComponent(const UsdPrim& prim);
175 
177 
180  static bool IsBoundable(const UsdPrim& prim);
181 
182  static FnKat::DoubleAttribute ConvertBoundsToAttribute(
183  const std::vector<GfBBox3d>& bounds,
184  const std::vector<double>& motionSampleTimes,
185  bool isMotionBackward,
186  bool* hasInfiniteBounds);
188 
192  static FnKat::GroupAttribute BuildInstanceMasterMapping(
193  const UsdStageRefPtr& stage, const SdfPath &rootPath);
194 
195 };
196 
199 public:
201  UsdPrim GetPrim() const;
202 
204  std::string GetLocation() const;
205 
207  std::string GetLocation(const SdfPath& path) const;
208 
210  template <class T>
211  void Set(const std::string& name, const T& value)
212  {
213  static_assert(!std::is_base_of<FnKat::Attribute, T>::value,
214  "Directly setting Katana Attributes is not supported");
215  _Set(name, VtValue(value));
216  }
217 
219  bool SetLinks(const UsdCollectionAPI &collectionAPI,
220  const std::string &linkName);
221 
224  void AddToCustomStringList(const std::string& tag,const std::string& value);
225 
226 protected:
228  FnKat::GeolibCookInterface &interface,
229  const PxrUsdKatanaUsdInArgsRefPtr& usdInArgs);
231 
233  void SetPath(const SdfPath& lightPath);
234 
236  void Build();
237 
238 private:
239  void _Set(const std::string& name, const VtValue& value);
240  void _Set(const std::string& name, const FnKat::Attribute& attr);
241 
242 private:
243  FnKat::GeolibCookInterface& _interface;
244  PxrUsdKatanaUsdInArgsRefPtr _usdInArgs;
245  FnKat::GroupBuilder _lightListBuilder;
246  std::map<std::string, FnKat::StringBuilder> _customStringLists;
247  SdfPath _lightPath;
248  std::string _key;
249 };
250 
254 public:
256  FnKat::GeolibCookInterface &interface,
257  const PxrUsdKatanaUsdInArgsRefPtr& usdInArgs) :
258  PxrUsdKatanaUtilsLightListAccess(interface, usdInArgs) { }
259 
260  // Allow access to protected members. PxrUsdKatanaUtilsLightListAccess
261  // is handed out to calls that need limited access and this class is
262  // used for full access.
265 };
266 
267 PXR_NAMESPACE_CLOSE_SCOPE
268 
269 #endif // SGG_USD_UTILS_H
270 
Private data for each non-root invocation of PxrUsdIn.
void SetPath(const SdfPath &lightPath)
Change the light path being accessed.
std::string GetLocation() const
Get the Katana location for the current light path.
Scenegraph object for authoring and retrieving numeric, string, and array valued data, sampled over time.
Definition: attribute.h:176
bool SetLinks(const UsdCollectionAPI &collectionAPI, const std::string &linkName)
Set linking for the light.
Utility class for building a light list.
Definition: utils.h:252
UsdPrim GetPrim() const
Get the Usd prim at the current light path.
void AddToCustomStringList(const std::string &tag, const std::string &value)
Append the string value to a custom string list named tag.
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:89
This is a general purpose API schema, used to describe a collection of heterogeneous objects within t...
Utility class for building a light list.
Definition: utils.h:198
void Set(const std::string &name, const T &value)
Add an attribute to lightList.
Definition: utils.h:211
UsdPrim is the sole persistent scenegraph object on a UsdStage, and is the embodiment of a &quot;Prim&quot; as ...
Definition: prim.h:131
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:287
A UsdRelationship creates dependencies between scenegraph objects by allowing a prim to target other ...
Definition: relationship.h:128
void Build()
Build into interface.
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:182