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 PXR_USD_IMAGING_USD_IMAGING_PRIM_ADAPTER_H 25 #define PXR_USD_IMAGING_USD_IMAGING_PRIM_ADAPTER_H 26 27 /// \file usdImaging/primAdapter.h 28 29 #include "pxr/pxr.h" 30 #include "pxr/usdImaging/usdImaging/api.h" 31 #include "pxr/usdImaging/usdImaging/version.h" 32 #include "pxr/usdImaging/usdImaging/collectionCache.h" 33 #include "pxr/usdImaging/usdImaging/primvarDescCache.h" 34 #include "pxr/usdImaging/usdImaging/resolvedAttributeCache.h" 35 36 #include "pxr/imaging/hd/changeTracker.h" 37 #include "pxr/imaging/hd/selection.h" 38 #include "pxr/usd/usd/attribute.h" 39 #include "pxr/usd/usd/prim.h" 40 #include "pxr/usd/usd/timeCode.h" 41 42 #include "pxr/usd/usdShade/shader.h" 43 44 #include "pxr/base/tf/type.h" 45 46 #include <memory> 47 48 PXR_NAMESPACE_OPEN_SCOPE 49 50 class UsdPrim; 51 52 // Forward declaration for nested class. 53 class UsdImagingDelegate; 54 class UsdImagingIndexProxy; 55 class UsdImagingInstancerContext; 56 class HdExtComputationContext; 57 58 using UsdImagingPrimAdapterSharedPtr = 59 std::shared_ptr<class UsdImagingPrimAdapter>; 60 61 /// \class UsdImagingPrimAdapter 62 /// 63 /// Base class for all PrimAdapters. 64 /// 65 class UsdImagingPrimAdapter 66 : public std::enable_shared_from_this<UsdImagingPrimAdapter> 67 { 68 public: 69 70 // ---------------------------------------------------------------------- // 71 /// \name Initialization 72 // ---------------------------------------------------------------------- // 73 UsdImagingPrimAdapter()74 UsdImagingPrimAdapter() 75 {} 76 77 USDIMAGING_API 78 virtual ~UsdImagingPrimAdapter(); 79 80 /// Called to populate the RenderIndex for this UsdPrim. The adapter is 81 /// expected to create one or more prims in the render index using the 82 /// given proxy. 83 virtual SdfPath Populate(UsdPrim const& prim, 84 UsdImagingIndexProxy* index, 85 UsdImagingInstancerContext const* 86 instancerContext = nullptr) = 0; 87 88 // Indicates whether population traversal should be pruned based on 89 // prim-specific features (like whether it's imageable). 90 USDIMAGING_API 91 static bool ShouldCullSubtree(UsdPrim const& prim); 92 93 // Indicates whether population traversal should be pruned based on 94 // adapter-specific features (like whether the adapter is an instance 95 // adapter, and wants to do its own population). 96 USDIMAGING_API 97 virtual bool ShouldCullChildren() const; 98 99 // Indicates whether or not native USD prim instancing should be ignored 100 // for prims using this delegate, along with their descendants. 101 USDIMAGING_API 102 virtual bool ShouldIgnoreNativeInstanceSubtrees() const; 103 104 // Indicates the adapter is a multiplexing adapter (e.g. PointInstancer), 105 // potentially managing its children. This flag is used in nested 106 // instancer cases to determine which adapter is assigned to which prim. 107 USDIMAGING_API 108 virtual bool IsInstancerAdapter() const; 109 110 // Indicates whether this adapter can directly populate USD instance prims. 111 // 112 // Normally, with USD instances, we make a firewall between the instance 113 // prim and the USD prototype tree. The instance adapter creates one 114 // hydra prototype per prim in the USD prototype tree, shared by all USD 115 // instances; this lets us recognize the benefits of instancing, 116 // by hopefully having a high instance count per prototype. The instance 117 // adapter additionally configures a hydra instancer for the prototype tree; 118 // and a small set of specially-handled data is allowed through: things like 119 // inherited constant primvars, transforms, visibility, and other things 120 // we know how to vary per-instance. 121 // 122 // We enforce the above policy by refusing to populate gprims which are 123 // USD instances, since we'd need one prototype per instance and would lose 124 // any instancing benefit. 125 // 126 // There are a handful of times when it really is useful to directly 127 // populate instance prims: for example, instances with cards applied, 128 // or instances of type UsdSkelRoot. In those cases, the adapters can 129 // opt into this scheme with "CanPopulateUsdInstance". 130 // 131 // Note that any adapters taking advantage of this feature will need 132 // extensive code support in instanceAdapter: the instance adapter will 133 // need to potentially create and track multiple hydra prototypes per 134 // USD prototype, and the adapter will need special handling to pass down 135 // any relevant instance-varying data. 136 // 137 // In summary: use with caution. 138 USDIMAGING_API 139 virtual bool CanPopulateUsdInstance() const; 140 141 // ---------------------------------------------------------------------- // 142 /// \name Parallel Setup and Resolve 143 // ---------------------------------------------------------------------- // 144 145 /// For the given \p prim, variability is detected and 146 /// stored in \p timeVaryingBits. Initial values are cached into the value 147 /// cache. 148 /// 149 /// This method is expected to be called from multiple threads. 150 virtual void TrackVariability(UsdPrim const& prim, 151 SdfPath const& cachePath, 152 HdDirtyBits* timeVaryingBits, 153 UsdImagingInstancerContext const* 154 instancerContext = nullptr) const = 0; 155 156 /// Populates the \p cache for the given \p prim, \p time and \p 157 /// requestedBits. 158 /// 159 /// This method is expected to be called from multiple threads. 160 virtual void UpdateForTime(UsdPrim const& prim, 161 SdfPath const& cachePath, 162 UsdTimeCode time, 163 HdDirtyBits requestedBits, 164 UsdImagingInstancerContext const* 165 instancerContext = nullptr) const = 0; 166 167 // ---------------------------------------------------------------------- // 168 /// \name Change Processing 169 // ---------------------------------------------------------------------- // 170 171 /// Returns a bit mask of attributes to be updated, or 172 /// HdChangeTracker::AllDirty if the entire prim must be resynchronized. 173 /// 174 /// \p changedFields contains a list of changed scene description fields 175 /// for this prim. This may be empty in certain cases, like the addition 176 /// of an inert prim spec for the given \p prim. 177 /// 178 /// The default implementation returns HdChangeTracker::AllDirty if any of 179 /// the changed fields are plugin metadata fields, HdChangeTracker::Clean 180 /// otherwise. 181 USDIMAGING_API 182 virtual HdDirtyBits ProcessPrimChange(UsdPrim const& prim, 183 SdfPath const& cachePath, 184 TfTokenVector const& changedFields); 185 186 /// Returns a bit mask of attributes to be updated, or 187 /// HdChangeTracker::AllDirty if the entire prim must be resynchronized. 188 virtual HdDirtyBits ProcessPropertyChange(UsdPrim const& prim, 189 SdfPath const& cachePath, 190 TfToken const& propertyName) = 0; 191 192 /// When a PrimResync event occurs, the prim may have been deleted entirely, 193 /// adapter plug-ins should override this method to free any per-prim state 194 /// that was accumulated in the adapter. 195 USDIMAGING_API 196 virtual void ProcessPrimResync(SdfPath const& cachePath, 197 UsdImagingIndexProxy* index); 198 199 /// Removes all associated Rprims and dependencies from the render index 200 /// without scheduling them for repopulation. 201 USDIMAGING_API 202 virtual void ProcessPrimRemoval(SdfPath const& cachePath, 203 UsdImagingIndexProxy* index); 204 205 206 virtual void MarkDirty(UsdPrim const& prim, 207 SdfPath const& cachePath, 208 HdDirtyBits dirty, 209 UsdImagingIndexProxy* index) = 0; 210 211 USDIMAGING_API 212 virtual void MarkRefineLevelDirty(UsdPrim const& prim, 213 SdfPath const& cachePath, 214 UsdImagingIndexProxy* index); 215 216 USDIMAGING_API 217 virtual void MarkReprDirty(UsdPrim const& prim, 218 SdfPath const& cachePath, 219 UsdImagingIndexProxy* index); 220 221 USDIMAGING_API 222 virtual void MarkCullStyleDirty(UsdPrim const& prim, 223 SdfPath const& cachePath, 224 UsdImagingIndexProxy* index); 225 226 USDIMAGING_API 227 virtual void MarkRenderTagDirty(UsdPrim const& prim, 228 SdfPath const& cachePath, 229 UsdImagingIndexProxy* index); 230 231 USDIMAGING_API 232 virtual void MarkTransformDirty(UsdPrim const& prim, 233 SdfPath const& cachePath, 234 UsdImagingIndexProxy* index); 235 236 USDIMAGING_API 237 virtual void MarkVisibilityDirty(UsdPrim const& prim, 238 SdfPath const& cachePath, 239 UsdImagingIndexProxy* index); 240 241 USDIMAGING_API 242 virtual void MarkMaterialDirty(UsdPrim const& prim, 243 SdfPath const& cachePath, 244 UsdImagingIndexProxy* index); 245 246 USDIMAGING_API 247 virtual void MarkLightParamsDirty(UsdPrim const& prim, 248 SdfPath const& cachePath, 249 UsdImagingIndexProxy* index); 250 251 USDIMAGING_API 252 virtual void MarkWindowPolicyDirty(UsdPrim const& prim, 253 SdfPath const& cachePath, 254 UsdImagingIndexProxy* index); 255 256 // ---------------------------------------------------------------------- // 257 /// \name Computations 258 // ---------------------------------------------------------------------- // 259 USDIMAGING_API 260 virtual void InvokeComputation(SdfPath const& cachePath, 261 HdExtComputationContext* context); 262 263 // ---------------------------------------------------------------------- // 264 /// \name Instancing 265 // ---------------------------------------------------------------------- // 266 267 /// Return an array of the categories used by each instance. 268 USDIMAGING_API 269 virtual std::vector<VtArray<TfToken>> 270 GetInstanceCategories(UsdPrim const& prim); 271 272 /// Get the instancer transform for the given prim. 273 /// \see HdSceneDelegate::GetInstancerTransform() 274 USDIMAGING_API 275 virtual GfMatrix4d GetInstancerTransform( 276 UsdPrim const& instancerPrim, 277 SdfPath const& instancerPath, 278 UsdTimeCode time) const; 279 280 /// Sample the instancer transform for the given prim. 281 /// \see HdSceneDelegate::SampleInstancerTransform() 282 USDIMAGING_API 283 virtual size_t SampleInstancerTransform( 284 UsdPrim const& instancerPrim, 285 SdfPath const& instancerPath, 286 UsdTimeCode time, 287 size_t maxNumSamples, 288 float *sampleTimes, 289 GfMatrix4d *sampleValues); 290 291 /// Return the instancerId for this prim. 292 USDIMAGING_API 293 virtual SdfPath GetInstancerId( 294 UsdPrim const& usdPrim, 295 SdfPath const& cachePath) const; 296 297 /// Return the list of known prototypes of this prim. 298 USDIMAGING_API 299 virtual SdfPathVector GetInstancerPrototypes( 300 UsdPrim const& usdPrim, 301 SdfPath const& cachePath) const; 302 303 /// Sample the primvar for the given prim. If *sampleIndices is not nullptr 304 /// and the primvar has indices, it will sample the unflattened primvar and 305 /// set *sampleIndices to the primvar's sampled indices. 306 /// \see HdSceneDelegate::SamplePrimvar() and 307 /// HdSceneDelegate::SampleIndexedPrimvar() 308 USDIMAGING_API 309 virtual size_t 310 SamplePrimvar(UsdPrim const& usdPrim, 311 SdfPath const& cachePath, 312 TfToken const& key, 313 UsdTimeCode time, 314 size_t maxNumSamples, 315 float *sampleTimes, 316 VtValue *sampleValues, 317 VtIntArray *sampleIndices); 318 319 /// Get the subdiv tags for this prim. 320 USDIMAGING_API 321 virtual PxOsdSubdivTags GetSubdivTags(UsdPrim const& usdPrim, 322 SdfPath const& cachePath, 323 UsdTimeCode time) const; 324 325 // ---------------------------------------------------------------------- // 326 /// \name Nested instancing support 327 // ---------------------------------------------------------------------- // 328 329 // NOTE: This method is currently only used by PointInstancer 330 // style instances, and not instanceable-references. 331 332 /// Returns the transform of \p protoInstancerPath relative to 333 /// \p instancerPath. \p instancerPath must be managed by this 334 /// adapter. 335 USDIMAGING_API 336 virtual GfMatrix4d GetRelativeInstancerTransform( 337 SdfPath const &instancerPath, 338 SdfPath const &protoInstancerPath, 339 UsdTimeCode time) const; 340 341 // ---------------------------------------------------------------------- // 342 /// \name Selection 343 // ---------------------------------------------------------------------- // 344 345 USDIMAGING_API 346 virtual SdfPath GetScenePrimPath(SdfPath const& cachePath, 347 int instanceIndex, 348 HdInstancerContext *instancerCtx) const; 349 350 // Add the given usdPrim to the HdSelection object, to mark it for 351 // selection highlighting. cachePath is the path of the object referencing 352 // this adapter. 353 // 354 // If an instance index is provided to Delegate::PopulateSelection, it's 355 // interpreted as a hydra instance index and left unchanged (to make 356 // picking/selection round-tripping work). Otherwise, instance adapters 357 // will build up a composite instance index range at each level. 358 // 359 // Consider: 360 // /World/A (2 instances) 361 // /B (2 instances) 362 // /C (gprim) 363 // ... to select /World/A, instance 0, you want to select cartesian 364 // coordinates (0, *) -> (0, 0) and (0, 1). The flattened representation 365 // of this is: 366 // index = coordinate[0] * instance_count[1] + coordinate[1] 367 // Likewise, for one more nesting level you get: 368 // index = c[0] * count[1] * count[2] + c[1] * count[2] + c[2] 369 // ... since the adapter for /World/A has no idea what count[1+] are, 370 // this needs to be built up. The delegate initially sets 371 // parentInstanceIndices to []. /World/A sets this to [0]. /World/A/B, 372 // since it is selecting *, adds all possible instance indices: 373 // 0 * 2 + 0 = 0, 0 * 2 + 1 = 1. /World/A/B/C is a gprim, and adds 374 // instances [0,1] to its selection. 375 USDIMAGING_API 376 virtual bool PopulateSelection( 377 HdSelection::HighlightMode const& highlightMode, 378 SdfPath const &cachePath, 379 UsdPrim const &usdPrim, 380 int const hydraInstanceIndex, 381 VtIntArray const &parentInstanceIndices, 382 HdSelectionSharedPtr const &result) const; 383 384 // ---------------------------------------------------------------------- // 385 /// \name Volume field information 386 // ---------------------------------------------------------------------- // 387 388 USDIMAGING_API 389 virtual HdVolumeFieldDescriptorVector 390 GetVolumeFieldDescriptors(UsdPrim const& usdPrim, SdfPath const &id, 391 UsdTimeCode time) const; 392 393 // ---------------------------------------------------------------------- // 394 /// \name Utilities 395 // ---------------------------------------------------------------------- // 396 397 /// The root transform provided by the delegate. 398 USDIMAGING_API 399 GfMatrix4d GetRootTransform() const; 400 401 /// A thread-local XformCache provided by the delegate. 402 USDIMAGING_API 403 void SetDelegate(UsdImagingDelegate* delegate); 404 405 USDIMAGING_API 406 bool IsChildPath(SdfPath const& path) const; 407 408 /// Returns true if the given prim is visible, taking into account inherited 409 /// visibility values. Inherited values are strongest, Usd has no notion of 410 /// "super vis/invis". 411 USDIMAGING_API 412 virtual bool GetVisible( 413 UsdPrim const& prim, 414 SdfPath const& cachePath, 415 UsdTimeCode time) const; 416 417 /// Returns the purpose token for \p prim. If a non-empty \p 418 /// instanceInheritablePurpose is specified and the prim doesn't have an 419 /// explicitly authored or inherited purpose, it may inherit the 420 /// instancer's purpose if the instance has an explicit purpose. 421 USDIMAGING_API 422 virtual TfToken GetPurpose( 423 UsdPrim const& prim, 424 SdfPath const& cachePath, 425 TfToken const& instanceInheritablePurpose) const; 426 427 /// Returns the purpose token for \p prim, but only if it is inheritable 428 /// by child prims (i.e. it is an explicitly authored purpose on the prim 429 /// itself or one of the prim's ancestors), otherwise it returns the empty 430 /// token. 431 USDIMAGING_API 432 TfToken GetInheritablePurpose(UsdPrim const& prim) const; 433 434 /// Fetches the transform for the given prim at the given time from a 435 /// pre-computed cache of prim transforms. Requesting transforms at 436 /// incoherent times is currently inefficient. 437 USDIMAGING_API 438 virtual GfMatrix4d GetTransform(UsdPrim const& prim, 439 SdfPath const& cachePath, 440 UsdTimeCode time, 441 bool ignoreRootTransform = false) const; 442 443 /// Samples the transform for the given prim. 444 USDIMAGING_API 445 virtual size_t SampleTransform(UsdPrim const& prim, 446 SdfPath const& cachePath, 447 UsdTimeCode time, 448 size_t maxNumSamples, 449 float *sampleTimes, 450 GfMatrix4d *sampleValues); 451 452 /// Gets the value of the parameter named key for the given prim (which 453 /// has the given cache path) and given time. If outIndices is not nullptr 454 /// and the value has indices, it will return the unflattened value and set 455 /// outIndices to the value's associated indices. 456 USDIMAGING_API 457 virtual VtValue Get(UsdPrim const& prim, 458 SdfPath const& cachePath, 459 TfToken const& key, 460 UsdTimeCode time, 461 VtIntArray *outIndices) const; 462 463 /// Gets the cullstyle of a specific path in the scene graph. 464 USDIMAGING_API 465 virtual HdCullStyle GetCullStyle(UsdPrim const& prim, 466 SdfPath const& cachePath, 467 UsdTimeCode time) const; 468 469 /// Gets the material path for the given prim, walking up namespace if 470 /// necessary. 471 USDIMAGING_API 472 SdfPath GetMaterialUsdPath(UsdPrim const& prim) const; 473 474 /// Gets the model:drawMode attribute for the given prim, walking up 475 /// the namespace if necessary. 476 USDIMAGING_API 477 TfToken GetModelDrawMode(UsdPrim const& prim); 478 479 /// Computes the per-prototype instance indices for a UsdGeomPointInstancer. 480 /// XXX: This needs to be defined on the base class, to have access to the 481 /// delegate, but it's a clear violation of abstraction. This call is only 482 /// legal for prims of type UsdGeomPointInstancer; in other cases, the 483 /// returned array will be empty and the computation will issue errors. 484 USDIMAGING_API 485 VtArray<VtIntArray> GetPerPrototypeIndices(UsdPrim const& prim, 486 UsdTimeCode time) const; 487 488 /// Gets the topology object of a specific Usd prim. If the 489 /// adapter is a mesh it will return an HdMeshTopology, 490 /// if it is of type basis curves, it will return an HdBasisCurvesTopology. 491 /// If the adapter does not have a topology, it returns an empty VtValue. 492 USDIMAGING_API 493 virtual VtValue GetTopology(UsdPrim const& prim, 494 SdfPath const& cachePath, 495 UsdTimeCode time) const; 496 497 /// Reads the extent from the given prim. If the extent is not authored, 498 /// an empty GfRange3d is returned, the extent will not be computed. 499 USDIMAGING_API 500 virtual GfRange3d GetExtent(UsdPrim const& prim, 501 SdfPath const& cachePath, 502 UsdTimeCode time) const; 503 504 /// Reads double-sided from the given prim. If not authored, returns false 505 USDIMAGING_API 506 virtual bool GetDoubleSided(UsdPrim const& prim, 507 SdfPath const& cachePath, 508 UsdTimeCode time) const; 509 510 USDIMAGING_API 511 virtual SdfPath GetMaterialId(UsdPrim const& prim, 512 SdfPath const& cachePath, 513 UsdTimeCode time) const; 514 515 USDIMAGING_API 516 virtual VtValue GetMaterialResource(UsdPrim const& prim, 517 SdfPath const& cachePath, 518 UsdTimeCode time) const; 519 520 // ---------------------------------------------------------------------- // 521 /// \name ExtComputations 522 // ---------------------------------------------------------------------- // 523 USDIMAGING_API 524 virtual const TfTokenVector &GetExtComputationSceneInputNames( 525 SdfPath const& cachePath) const; 526 527 USDIMAGING_API 528 virtual HdExtComputationInputDescriptorVector 529 GetExtComputationInputs(UsdPrim const& prim, 530 SdfPath const& cachePath, 531 const UsdImagingInstancerContext* instancerContext) 532 const; 533 534 USDIMAGING_API 535 virtual HdExtComputationOutputDescriptorVector 536 GetExtComputationOutputs(UsdPrim const& prim, 537 SdfPath const& cachePath, 538 const UsdImagingInstancerContext* instancerContext) 539 const; 540 541 USDIMAGING_API 542 virtual HdExtComputationPrimvarDescriptorVector 543 GetExtComputationPrimvars( 544 UsdPrim const& prim, 545 SdfPath const& cachePath, 546 HdInterpolation interpolation, 547 const UsdImagingInstancerContext* instancerContext) const; 548 549 USDIMAGING_API 550 virtual VtValue 551 GetExtComputationInput( 552 UsdPrim const& prim, 553 SdfPath const& cachePath, 554 TfToken const& name, 555 UsdTimeCode time, 556 const UsdImagingInstancerContext* instancerContext) const; 557 558 USDIMAGING_API 559 virtual size_t 560 SampleExtComputationInput( 561 UsdPrim const& prim, 562 SdfPath const& cachePath, 563 TfToken const& name, 564 UsdTimeCode time, 565 const UsdImagingInstancerContext* instancerContext, 566 size_t maxSampleCount, 567 float *sampleTimes, 568 VtValue *sampleValues); 569 570 USDIMAGING_API 571 virtual std::string 572 GetExtComputationKernel( 573 UsdPrim const& prim, 574 SdfPath const& cachePath, 575 const UsdImagingInstancerContext* instancerContext) const; 576 577 USDIMAGING_API 578 virtual VtValue 579 GetInstanceIndices(UsdPrim const& instancerPrim, 580 SdfPath const& instancerCachePath, 581 SdfPath const& prototypeCachePath, 582 UsdTimeCode time) const; 583 584 // ---------------------------------------------------------------------- // 585 /// \name Render Index Compatibility 586 // ---------------------------------------------------------------------- // 587 588 /// Returns true if the adapter can be populated into the target index. IsSupported(UsdImagingIndexProxy const * index)589 virtual bool IsSupported(UsdImagingIndexProxy const* index) const { 590 return true; 591 } 592 593 protected: 594 using Keys = UsdImagingPrimvarDescCache::Key; 595 596 template <typename T> _Get(UsdPrim const & prim,TfToken const & attrToken,UsdTimeCode time)597 T _Get(UsdPrim const& prim, TfToken const& attrToken, 598 UsdTimeCode time) const { 599 T value; 600 prim.GetAttribute(attrToken).Get<T>(&value, time); 601 return value; 602 } 603 604 template <typename T> _GetPtr(UsdPrim const & prim,TfToken const & key,UsdTimeCode time,T * out)605 void _GetPtr(UsdPrim const& prim, TfToken const& key, UsdTimeCode time, 606 T* out) const { 607 prim.GetAttribute(key).Get<T>(out, time); 608 } 609 610 USDIMAGING_API 611 UsdImagingPrimvarDescCache* _GetPrimvarDescCache() const; 612 613 USDIMAGING_API 614 UsdPrim _GetPrim(SdfPath const& usdPath) const; 615 616 // Returns the prim adapter for the given \p prim, or an invalid pointer if 617 // no adapter exists. If \p prim is an instance and \p ignoreInstancing 618 // is \c true, the instancing adapter will be ignored and an adapter will 619 // be looked up based on \p prim's type. 620 USDIMAGING_API 621 const UsdImagingPrimAdapterSharedPtr& 622 _GetPrimAdapter(UsdPrim const& prim, bool ignoreInstancing = false) const; 623 624 USDIMAGING_API 625 const UsdImagingPrimAdapterSharedPtr& 626 _GetAdapter(TfToken const& adapterKey) const; 627 628 // XXX: Transitional API 629 // Returns the instance proxy prim path for a USD-instanced prim, given the 630 // instance chain leading to that prim. The paths are sorted from more to 631 // less local; the first path is the prim path (possibly in prototype), then 632 // instance paths (possibly in prototype); the last path is the prim or 633 // instance path in the scene. 634 USDIMAGING_API 635 SdfPath _GetPrimPathFromInstancerChain( 636 SdfPathVector const& instancerChain) const; 637 638 USDIMAGING_API 639 UsdTimeCode _GetTimeWithOffset(float offset) const; 640 641 // Converts \p cachePath to the path in the render index. 642 USDIMAGING_API 643 SdfPath _ConvertCachePathToIndexPath(SdfPath const& cachePath) const; 644 645 // Converts \p indexPath to the path in the USD stage 646 USDIMAGING_API 647 SdfPath _ConvertIndexPathToCachePath(SdfPath const& indexPath) const; 648 649 // Returns the material binding purpose from the renderer delegate. 650 USDIMAGING_API 651 TfToken _GetMaterialBindingPurpose() const; 652 653 // Returns the material contexts from the renderer delegate. 654 USDIMAGING_API 655 TfTokenVector _GetMaterialRenderContexts() const; 656 657 // Returns true if render delegate wants primvars to be filtered based. 658 // This will filter the primvars based on the bound material primvar needs. 659 USDIMAGING_API 660 bool _IsPrimvarFilteringNeeded() const; 661 662 // Returns the shader source type from the render delegate. 663 USDIMAGING_API 664 TfTokenVector _GetShaderSourceTypes() const; 665 666 // Returns \c true if \p usdPath is included in the scene delegate's 667 // invised path list. 668 USDIMAGING_API 669 bool _IsInInvisedPaths(SdfPath const& usdPath) const; 670 671 // Determines if an attribute is varying and if so, sets the given 672 // \p dirtyFlag in the \p dirtyFlags and increments a perf counter. Returns 673 // true if the attribute is varying. 674 // 675 // If \p exists is non-null, _IsVarying will store whether the attribute 676 // was found. If the attribute is not found, it counts as non-varying. 677 // 678 // This only sets the dirty bit, never un-sets. The caller is responsible 679 // for setting the initial state correctly. 680 USDIMAGING_API 681 bool _IsVarying(UsdPrim prim, TfToken const& attrName, 682 HdDirtyBits dirtyFlag, TfToken const& perfToken, 683 HdDirtyBits* dirtyFlags, bool isInherited, 684 bool* exists = nullptr) const; 685 686 // Determines if the prim's transform (CTM) is varying and if so, sets the 687 // given \p dirtyFlag in the \p dirtyFlags and increments a perf counter. 688 // Returns true if the prim's transform is varying. 689 // 690 // This only sets the dirty bit, never un-sets. The caller is responsible 691 // for setting the initial state correctly. 692 USDIMAGING_API 693 bool _IsTransformVarying(UsdPrim prim, 694 HdDirtyBits dirtyFlag, 695 TfToken const& perfToken, 696 HdDirtyBits* dirtyFlags) const; 697 698 // Convenience method for adding or updating a primvar descriptor. 699 // Role defaults to empty token (none). Indexed defaults to false. 700 USDIMAGING_API 701 void _MergePrimvar( 702 HdPrimvarDescriptorVector* vec, 703 TfToken const& name, 704 HdInterpolation interp, 705 TfToken const& role = TfToken(), 706 bool indexed = false) const; 707 708 // Convenience method for removing a primvar descriptor. 709 USDIMAGING_API 710 void _RemovePrimvar( 711 HdPrimvarDescriptorVector* vec, 712 TfToken const& name) const; 713 714 // Convenience method for computing a primvar. The primvar will only be 715 // added to the list of prim desc if there is no primvar of the same 716 // name already present. Thus, "local" primvars should be merged before 717 // inherited primvars. 718 USDIMAGING_API 719 void _ComputeAndMergePrimvar( 720 UsdPrim const& prim, 721 UsdGeomPrimvar const& primvar, 722 UsdTimeCode time, 723 HdPrimvarDescriptorVector* primvarDescs, 724 HdInterpolation *interpOverride = nullptr) const; 725 726 // Returns true if the property name has the "primvars:" prefix. 727 USDIMAGING_API 728 static bool _HasPrimvarsPrefix(TfToken const& propertyName); 729 730 // Convenience methods to figure out what changed about the primvar and 731 // return the appropriate dirty bit. 732 // Caller can optionally pass in a dirty bit to set for primvar value 733 // changes. This is useful for attributes that have a special dirty bit 734 // such as normals and widths. 735 // 736 // Handle USD attributes that are treated as primvars by Hydra. This 737 // requires the interpolation to be passed in, as well as the primvar 738 // name passed to Hydra. 739 USDIMAGING_API 740 HdDirtyBits _ProcessNonPrefixedPrimvarPropertyChange( 741 UsdPrim const& prim, 742 SdfPath const& cachePath, 743 TfToken const& propertyName, 744 TfToken const& primvarName, 745 HdInterpolation const& primvarInterp, 746 HdDirtyBits valueChangeDirtyBit = HdChangeTracker::DirtyPrimvar) const; 747 748 // Handle UsdGeomPrimvars that use the "primvars:" prefix, while also 749 // accommodating inheritance. 750 USDIMAGING_API 751 HdDirtyBits _ProcessPrefixedPrimvarPropertyChange( 752 UsdPrim const& prim, 753 SdfPath const& cachePath, 754 TfToken const& propertyName, 755 HdDirtyBits valueChangeDirtyBit = HdChangeTracker::DirtyPrimvar, 756 bool inherited = true) const; 757 758 virtual void _RemovePrim(SdfPath const& cachePath, 759 UsdImagingIndexProxy* index) = 0; 760 761 // Utility to resync bound dependencies of a particular usd path. 762 // This is necessary for the resync processing of certain prim types 763 // (e.g. materials). 764 USDIMAGING_API 765 void _ResyncDependents(SdfPath const& usdPath, 766 UsdImagingIndexProxy *index); 767 768 USDIMAGING_API 769 UsdImaging_CollectionCache& _GetCollectionCache() const; 770 771 USDIMAGING_API 772 UsdImaging_CoordSysBindingStrategy::value_type 773 _GetCoordSysBindings(UsdPrim const& prim) const; 774 775 USDIMAGING_API 776 UsdImaging_InheritedPrimvarStrategy::value_type 777 _GetInheritedPrimvars(UsdPrim const& prim) const; 778 779 USDIMAGING_API 780 GfInterval _GetCurrentTimeSamplingInterval(); 781 782 USDIMAGING_API 783 Usd_PrimFlagsConjunction _GetDisplayPredicate() const; 784 785 USDIMAGING_API 786 Usd_PrimFlagsConjunction _GetDisplayPredicateForPrototypes() const; 787 788 USDIMAGING_API 789 bool _DoesDelegateSupportCoordSys() const; 790 791 // Conversion functions between usd and hydra enums. 792 USDIMAGING_API 793 static HdInterpolation _UsdToHdInterpolation(TfToken const& usdInterp); 794 USDIMAGING_API 795 static TfToken _UsdToHdRole(TfToken const& usdRole); 796 797 private: 798 UsdImagingDelegate* _delegate; 799 }; 800 801 class UsdImagingPrimAdapterFactoryBase : public TfType::FactoryBase { 802 public: 803 virtual UsdImagingPrimAdapterSharedPtr New() const = 0; 804 }; 805 806 template <class T> 807 class UsdImagingPrimAdapterFactory : public UsdImagingPrimAdapterFactoryBase { 808 public: New()809 virtual UsdImagingPrimAdapterSharedPtr New() const 810 { 811 return std::make_shared<T>(); 812 } 813 }; 814 815 816 PXR_NAMESPACE_CLOSE_SCOPE 817 818 #endif // PXR_USD_IMAGING_USD_IMAGING_PRIM_ADAPTER_H 819