HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
connectableAPI.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 #ifndef USDSHADE_GENERATED_CONNECTABLEAPI_H
8 #define USDSHADE_GENERATED_CONNECTABLEAPI_H
9 
10 /// \file usdShade/connectableAPI.h
11 
12 #include "pxr/pxr.h"
13 #include "pxr/usd/usdShade/api.h"
15 #include "pxr/usd/usd/prim.h"
16 #include "pxr/usd/usd/stage.h"
17 
18 #include "pxr/usd/usd/typed.h"
19 #include "pxr/usd/usdShade/input.h"
22 #include "pxr/usd/usdShade/types.h"
23 
24 #include "pxr/base/vt/value.h"
25 
26 #include "pxr/base/gf/vec3d.h"
27 #include "pxr/base/gf/vec3f.h"
28 #include "pxr/base/gf/matrix4d.h"
29 
30 #include "pxr/base/tf/token.h"
31 #include "pxr/base/tf/type.h"
32 
34 
35 class SdfAssetPath;
36 
37 // -------------------------------------------------------------------------- //
38 // CONNECTABLEAPI //
39 // -------------------------------------------------------------------------- //
40 
41 /// \class UsdShadeConnectableAPI
42 ///
43 /// UsdShadeConnectableAPI is an API schema that provides a common
44 /// interface for creating outputs and making connections between shading
45 /// parameters and outputs. The interface is common to all UsdShade schemas
46 /// that support Inputs and Outputs, which currently includes UsdShadeShader,
47 /// UsdShadeNodeGraph, and UsdShadeMaterial .
48 ///
49 /// One can construct a UsdShadeConnectableAPI directly from a UsdPrim, or
50 /// from objects of any of the schema classes listed above. If it seems
51 /// onerous to need to construct a secondary schema object to interact with
52 /// Inputs and Outputs, keep in mind that any function whose purpose is either
53 /// to walk material/shader networks via their connections, or to create such
54 /// networks, can typically be written entirely in terms of
55 /// UsdShadeConnectableAPI objects, without needing to care what the underlying
56 /// prim type is.
57 ///
58 /// Additionally, the most common UsdShadeConnectableAPI behaviors
59 /// (creating Inputs and Outputs, and making connections) are wrapped as
60 /// convenience methods on the prim schema classes (creation) and
61 /// UsdShadeInput and UsdShadeOutput.
62 ///
63 ///
65 {
66 public:
67  /// Compile time constant representing what kind of schema this class is.
68  ///
69  /// \sa UsdSchemaKind
71 
72  /// Construct a UsdShadeConnectableAPI on UsdPrim \p prim .
73  /// Equivalent to UsdShadeConnectableAPI::Get(prim.GetStage(), prim.GetPath())
74  /// for a \em valid \p prim, but will not immediately throw an error for
75  /// an invalid \p prim
76  explicit UsdShadeConnectableAPI(const UsdPrim& prim=UsdPrim())
77  : UsdAPISchemaBase(prim)
78  {
79  }
80 
81  /// Construct a UsdShadeConnectableAPI on the prim held by \p schemaObj .
82  /// Should be preferred over UsdShadeConnectableAPI(schemaObj.GetPrim()),
83  /// as it preserves SchemaBase state.
84  explicit UsdShadeConnectableAPI(const UsdSchemaBase& schemaObj)
85  : UsdAPISchemaBase(schemaObj)
86  {
87  }
88 
89  /// Destructor.
91  virtual ~UsdShadeConnectableAPI();
92 
93  /// Return a vector of names of all pre-declared attributes for this schema
94  /// class and all its ancestor classes. Does not include attributes that
95  /// may be authored by custom/extended methods of the schemas involved.
97  static const TfTokenVector &
98  GetSchemaAttributeNames(bool includeInherited=true);
99 
100  /// Return a UsdShadeConnectableAPI holding the prim adhering to this
101  /// schema at \p path on \p stage. If no prim exists at \p path on
102  /// \p stage, or if the prim at that path does not adhere to this schema,
103  /// return an invalid schema object. This is shorthand for the following:
104  ///
105  /// \code
106  /// UsdShadeConnectableAPI(stage->GetPrimAtPath(path));
107  /// \endcode
108  ///
111  Get(const UsdStagePtr &stage, const SdfPath &path);
112 
113 
114 protected:
115  /// Returns the kind of schema this class belongs to.
116  ///
117  /// \sa UsdSchemaKind
119  UsdSchemaKind _GetSchemaKind() const override;
120 
121 private:
122  // needs to invoke _GetStaticTfType.
123  friend class UsdSchemaRegistry;
125  static const TfType &_GetStaticTfType();
126 
127  static bool _IsTypedSchema();
128 
129  // override SchemaBase virtuals.
131  const TfType &_GetTfType() const override;
132 
133 public:
134  // ===================================================================== //
135  // Feel free to add custom code below this line, it will be preserved by
136  // the code generator.
137  //
138  // Just remember to:
139  // - Close the class declaration with };
140  // - Close the namespace with PXR_NAMESPACE_CLOSE_SCOPE
141  // - Close the include guard with #endif
142  // ===================================================================== //
143  // --(BEGIN CUSTOM CODE)--
144 
145 protected:
146  /// Returns true if the given prim is compatible with this API schema,
147  /// i.e. if it is a valid shader or a node-graph.
148  /// A prim has a compatible connectableAPI if a valid behavior is registered
149  /// for it.
151  bool _IsCompatible() const override;
152 
153 public:
154  /// Returns true if the prim is a container.
155  ///
156  /// The underlying prim type may provide runtime behavior
157  /// that defines whether it is a container.
159  bool IsContainer() const;
160 
161  /// Returns true if container encapsulation rules should be respected when
162  /// evaluating connectibility behavior, false otherwise.
163  ///
164  /// The underlying prim type may provide runtime behavior that defines if
165  /// encapsulation rules are respected or not.
167  bool RequiresEncapsulation() const;
168 
169  /// \name Connections
170  ///
171  /// Inputs and outputs on shaders and node-graphs are connectable.
172  /// This section provides API for authoring and managing these connections
173  /// in a shading network.
174  ///
175  /// @{
176 
177  /// Determines whether the given input can be connected to the given
178  /// source attribute, which can be an input or an output.
179  ///
180  /// The result depends on the "connectability" of the input and the source
181  /// attributes. Depending on the prim type, this may require the plugin
182  /// that defines connectability behavior for that prim type be loaded.
183  ///
184  /// \sa UsdShadeInput::SetConnectability
185  /// \sa UsdShadeInput::GetConnectability
187  static bool CanConnect(const UsdShadeInput &input,
188  const UsdAttribute &source);
189 
190  /// \overload
192  static bool CanConnect(const UsdShadeInput &input,
193  const UsdShadeInput &sourceInput) {
194  return CanConnect(input, sourceInput.GetAttr());
195  }
196 
197  /// \overload
199  static bool CanConnect(const UsdShadeInput &input,
200  const UsdShadeOutput &sourceOutput) {
201  return CanConnect(input, sourceOutput.GetAttr());
202  }
203 
204  /// Determines whether the given output can be connected to the given
205  /// source attribute, which can be an input or an output.
206  ///
207  /// An output is considered to be connectable only if it belongs to a
208  /// node-graph. Shader outputs are not connectable.
209  ///
210  /// \p source is an optional argument. If a valid UsdAttribute is supplied
211  /// for it, this method will return true only if the source attribute is
212  /// owned by a descendant of the node-graph owning the output.
213  ///
215  static bool CanConnect(const UsdShadeOutput &output,
216  const UsdAttribute &source=UsdAttribute());
217 
218  /// \overload
220  static bool CanConnect(const UsdShadeOutput &output,
221  const UsdShadeInput &sourceInput) {
222  return CanConnect(output, sourceInput.GetAttr());
223  }
224 
225  /// \overload
227  static bool CanConnect(const UsdShadeOutput &output,
228  const UsdShadeOutput &sourceOutput) {
229  return CanConnect(output, sourceOutput.GetAttr());
230  }
231 
233 
234  /// Authors a connection for a given shading attribute \p shadingAttr.
235  ///
236  /// \p shadingAttr can represent a parameter, an input or an output.
237  /// \p source is a struct that describes the upstream source attribute
238  /// with all the information necessary to make a connection. See the
239  /// documentation for UsdShadeConnectionSourceInfo.
240  /// \p mod describes the operation that should be applied to the list of
241  /// connections. By default the new connection will replace any existing
242  /// connections, but it can add to the list of connections to represent
243  /// multiple input connections.
244  ///
245  /// \return
246  /// \c true if a connection was created successfully.
247  /// \c false if \p shadingAttr or \p source is invalid.
248  ///
249  /// \note This method does not verify the connectability of the shading
250  /// attribute to the source. Clients must invoke CanConnect() themselves
251  /// to ensure compatibility.
252  /// \note The source shading attribute is created if it doesn't exist
253  /// already.
254  ///
256  static bool ConnectToSource(
257  UsdAttribute const &shadingAttr,
260 
261  /// \overload
263  static bool ConnectToSource(
264  UsdShadeInput const &input,
267  {
268  return ConnectToSource(input.GetAttr(), source, mod);
269  }
270 
271  /// \overload
273  static bool ConnectToSource(
274  UsdShadeOutput const &output,
277  {
278  return ConnectToSource(output.GetAttr(), source, mod);
279  }
280 
281  /// \deprecated Please use the versions that take a
282  /// UsdShadeConnectionSourceInfo to describe the upstream source
283  /// \overload
285  static bool ConnectToSource(
286  UsdAttribute const &shadingAttr,
288  TfToken const &sourceName,
291 
292  /// \deprecated
293  /// \overload
295  static bool ConnectToSource(
296  UsdShadeInput const &input,
297  UsdShadeConnectableAPI const &source,
298  TfToken const &sourceName,
301  {
302  return ConnectToSource(input.GetAttr(), source, sourceName, sourceType,
303  typeName);
304  }
305 
306  /// \deprecated
307  /// \overload
309  static bool ConnectToSource(
310  UsdShadeOutput const &output,
311  UsdShadeConnectableAPI const &source,
312  TfToken const &sourceName,
315  {
316  return ConnectToSource(output.GetAttr(), source, sourceName, sourceType,
317  typeName);
318  }
319 
320  /// \overload
321  ///
322  /// Connect the given shading attribute to the source at path, \p sourcePath.
323  ///
324  /// \p sourcePath should be the fully namespaced property path.
325  ///
326  /// This overload is provided for convenience, for use in contexts where
327  /// the prim types are unknown or unavailable.
328  ///
330  static bool ConnectToSource(UsdAttribute const &shadingAttr,
331  SdfPath const &sourcePath);
332 
333  /// \overload
335  static bool ConnectToSource(UsdShadeInput const &input,
336  SdfPath const &sourcePath) {
337  return ConnectToSource(input.GetAttr(), sourcePath);
338  }
339 
340  /// \overload
342  static bool ConnectToSource(UsdShadeOutput const &output,
343  SdfPath const &sourcePath) {
344  return ConnectToSource(output.GetAttr(), sourcePath);
345  }
346 
347  /// \overload
348  ///
349  /// Connect the given shading attribute to the given source input.
350  ///
352  static bool ConnectToSource(UsdAttribute const &shadingAttr,
353  UsdShadeInput const &sourceInput);
354 
355  /// \overload
357  static bool ConnectToSource(UsdShadeInput const &input,
358  UsdShadeInput const &sourceInput) {
359  return ConnectToSource(input.GetAttr(), sourceInput);
360  }
361 
362  /// \overload
364  static bool ConnectToSource(UsdShadeOutput const &output,
365  UsdShadeInput const &sourceInput) {
366  return ConnectToSource(output.GetAttr(), sourceInput);
367  }
368 
369  /// \overload
370  ///
371  /// Connect the given shading attribute to the given source output.
372  ///
374  static bool ConnectToSource(UsdAttribute const &shadingAttr,
375  UsdShadeOutput const &sourceOutput);
376 
377  /// \overload
379  static bool ConnectToSource(UsdShadeInput const &input,
380  UsdShadeOutput const &sourceOutput) {
381  return ConnectToSource(input.GetAttr(), sourceOutput);
382  }
383 
384  /// \overload
386  static bool ConnectToSource(UsdShadeOutput const &output,
387  UsdShadeOutput const &sourceOutput) {
388  return ConnectToSource(output.GetAttr(), sourceOutput);
389  }
390 
391  /// Authors a list of connections for a given shading attribute
392  /// \p shadingAttr.
393  ///
394  /// \p shadingAttr can represent a parameter, an input or an output.
395  /// \p sourceInfos is a vector of structs that describes the upstream source
396  /// attributes with all the information necessary to make all the
397  /// connections. See the documentation for UsdShadeConnectionSourceInfo.
398  ///
399  /// \return
400  /// \c true if all connection were created successfully.
401  /// \c false if the \p shadingAttr or one of the sources are invalid.
402  ///
403  /// \note A valid connection is one that has a valid
404  /// \p UsdShadeConnectionSourceInfo, which requires the existence of the
405  /// upstream source prim. It does not require the existence of the source
406  /// attribute as it will be create if necessary.
408  static bool SetConnectedSources(
409  UsdAttribute const &shadingAttr,
410  std::vector<UsdShadeConnectionSourceInfo> const &sourceInfos);
411 
412 
413  /// \deprecated Shading attributes can have multiple connections and so
414  /// using GetConnectedSources is needed in general
415  ///
416  /// Finds the source of a connection for the given shading attribute.
417  ///
418  /// \p shadingAttr is the shading attribute whose connection we want to
419  /// interrogate.
420  /// \p source is an output parameter which will be set to the source
421  /// connectable prim.
422  /// \p sourceName will be set to the name of the source shading attribute,
423  /// which may be an input or an output, as specified by \p sourceType
424  /// \p sourceType will have the type of the source shading attribute, i.e.
425  /// whether it is an \c Input or \c Output
426  ///
427  /// \return
428  /// \c true if the shading attribute is connected to a valid, defined source
429  /// attribute.
430  /// \c false if the shading attribute is not connected to a single, defined
431  /// source attribute.
432  ///
433  /// \note Previously this method would silently return false for multiple
434  /// connections. We are changing the behavior of this method to return the
435  /// result for the first connection and issue a TfWarn about it. We want to
436  /// encourage clients to use GetConnectedSources going forward.
437  /// \note The python wrapping for this method returns a
438  /// (source, sourceName, sourceType) tuple if the parameter is connected,
439  /// else \c None
441  static bool GetConnectedSource(UsdAttribute const &shadingAttr,
442  UsdShadeConnectableAPI *source,
443  TfToken *sourceName,
444  UsdShadeAttributeType *sourceType);
445 
446  /// \deprecated
447  /// \overload
449  static bool GetConnectedSource(UsdShadeInput const &input,
450  UsdShadeConnectableAPI *source,
451  TfToken *sourceName,
452  UsdShadeAttributeType *sourceType) {
453  return GetConnectedSource(input.GetAttr(), source, sourceName,
454  sourceType);
455  }
456 
457  /// \deprecated
458  /// \overload
460  static bool GetConnectedSource(UsdShadeOutput const &output,
461  UsdShadeConnectableAPI *source,
462  TfToken *sourceName,
463  UsdShadeAttributeType *sourceType) {
464  return GetConnectedSource(output.GetAttr(), source, sourceName,
465  sourceType);
466  }
467 
468  /// Finds the valid sources of connections for the given shading attribute.
469  ///
470  /// \p shadingAttr is the shading attribute whose connections we want to
471  /// interrogate.
472  /// \p invalidSourcePaths is an optional output parameter to collect the
473  /// invalid source paths that have not been reported in the returned vector.
474  ///
475  /// Returns a vector of \p UsdShadeConnectionSourceInfo structs with
476  /// information about each upsteam attribute. If the vector is empty, there
477  /// have been no connections.
478  ///
479  /// \note A valid connection requires the existence of the source attribute
480  /// and also requires that the source prim is UsdShadeConnectableAPI
481  /// compatible.
482  /// \note The python wrapping returns a tuple with the valid connections
483  /// first, followed by the invalid source paths.
486  UsdAttribute const &shadingAttr,
487  SdfPathVector *invalidSourcePaths = nullptr);
488 
489  /// \overload
492  UsdShadeInput const &input,
493  SdfPathVector *invalidSourcePaths = nullptr);
494 
495  /// \overload
498  UsdShadeOutput const &output,
499  SdfPathVector *invalidSourcePaths = nullptr);
500 
501  /// \deprecated Please us GetConnectedSources to retrieve multiple
502  /// connections
503  ///
504  /// Returns the "raw" (authored) connected source paths for the given
505  /// shading attribute.
507  static bool GetRawConnectedSourcePaths(UsdAttribute const &shadingAttr,
508  SdfPathVector *sourcePaths);
509 
510  /// \deprecated
511  /// \overload
513  static bool GetRawConnectedSourcePaths(UsdShadeInput const &input,
514  SdfPathVector *sourcePaths) {
515  return GetRawConnectedSourcePaths(input.GetAttr(), sourcePaths);
516  }
517 
518  /// \deprecated
519  /// \overload
521  static bool GetRawConnectedSourcePaths(UsdShadeOutput const &output,
522  SdfPathVector *sourcePaths) {
523  return GetRawConnectedSourcePaths(output.GetAttr(), sourcePaths);
524  }
525 
526  /// Returns true if and only if the shading attribute is currently connected
527  /// to at least one valid (defined) source.
528  ///
529  /// If you will be calling GetConnectedSources() afterwards anyways,
530  /// it will be \em much faster to instead check if the returned vector is
531  /// empty:
532  /// \code
533  /// UsdShadeSourceInfoVector connections =
534  /// UsdShadeConnectableAPI::GetConnectedSources(attribute);
535  /// if (!connections.empty()){
536  /// // process connected attribute
537  /// } else {
538  /// // process unconnected attribute
539  /// }
540  /// \endcode
542  static bool HasConnectedSource(const UsdAttribute &shadingAttr);
543 
544  /// \overload
546  static bool HasConnectedSource(const UsdShadeInput &input) {
547  return HasConnectedSource(input.GetAttr());
548  }
549 
550  /// \overload
552  static bool HasConnectedSource(const UsdShadeOutput &output) {
553  return HasConnectedSource(output.GetAttr());
554  }
555 
556  /// Returns true if the connection to the given shading attribute's source,
557  /// as returned by UsdShadeConnectableAPI::GetConnectedSource(), is authored
558  /// across a specializes arc, which is used to denote a base material.
559  ///
562  const UsdAttribute &shadingAttr);
563 
564  /// \overload
568  }
569 
570  /// \overload
573  {
575  }
576 
577  /// Disconnect source for this shading attribute.
578  ///
579  /// If \p sourceAttr is valid it will disconnect the connection to this
580  /// upstream attribute. Otherwise it will disconnect all connections by
581  /// authoring an empty list of connections for the attribute \p shadingAttr.
582  ///
583  /// This may author more scene description than you might expect - we define
584  /// the behavior of disconnect to be that, even if a shading attribute
585  /// becomes connected in a weaker layer than the current UsdEditTarget, the
586  /// attribute will \em still be disconnected in the composition, therefore
587  /// we must "block" it in the current UsdEditTarget.
588  ///
589  /// \sa ConnectToSource().
591  static bool DisconnectSource(
592  UsdAttribute const &shadingAttr,
593  UsdAttribute const &sourceAttr = UsdAttribute());
594 
595  /// \overload
597  static bool DisconnectSource(
598  UsdShadeInput const &input,
599  UsdAttribute const &sourceAttr = UsdAttribute()) {
600  return DisconnectSource(input.GetAttr(), sourceAttr);
601  }
602 
603  /// \overload
605  static bool DisconnectSource(
606  UsdShadeOutput const &output,
607  UsdAttribute const &sourceAttr = UsdAttribute()) {
608  return DisconnectSource(output.GetAttr(), sourceAttr);
609  }
610 
611  /// Clears sources for this shading attribute in the current UsdEditTarget.
612  ///
613  /// Most of the time, what you probably want is DisconnectSource()
614  /// rather than this function.
615  ///
616  /// \sa DisconnectSource()
618  static bool ClearSources(UsdAttribute const &shadingAttr);
619 
620  /// \overload
622  static bool ClearSources(UsdShadeInput const &input) {
623  return ClearSources(input.GetAttr());
624  }
625 
626  /// \overload
628  static bool ClearSources(UsdShadeOutput const &output) {
629  return ClearSources(output.GetAttr());
630  }
631 
632  /// \deprecated This is the older version that only referenced a single
633  /// source. Please use ClearSources instead.
635  static bool ClearSource(UsdAttribute const &shadingAttr) {
636  return ClearSources(shadingAttr);
637  }
638 
639  /// \deprecated
640  /// \overload
642  static bool ClearSource(UsdShadeInput const &input) {
643  return ClearSources(input.GetAttr());
644  }
645 
646  /// \deprecated
647  /// \overload
649  static bool ClearSource(UsdShadeOutput const &output) {
650  return ClearSources(output.GetAttr());
651  }
652 
653  /// Return true if the \p schemaType has a valid connectableAPIBehavior
654  /// registered, false otherwise.
655  /// To check if a prim's connectableAPI has a behavior defined, use
656  /// UsdSchemaBase::operator bool().
658  static bool HasConnectableAPI(const TfType& schemaType);
659 
660  /// Return true if the schema type \p T has a connectableAPIBehavior
661  /// registered, false otherwise.
662  template <typename T>
663  static bool HasConnectableAPI()
664  {
666  "Provided type must derive UsdSchemaBase.");
667  return HasConnectableAPI(TfType::Find<T>());
668  };
669 
670  /// @}
671 
672 
673  /// \name Outputs
674  /// @{
675 
676  /// Create an output, which represents and externally computed, typed value.
677  /// Outputs on node-graphs can be connected.
678  ///
679  /// The attribute representing an output is created in the "outputs:"
680  /// namespace.
681  ///
684  const SdfValueTypeName& typeName) const;
685 
686  /// Return the requested output if it exists.
687  ///
688  /// \p name is the unnamespaced base name.
689  ///
691  UsdShadeOutput GetOutput(const TfToken &name) const;
692 
693  /// Returns all outputs on the connectable prim (i.e. shader or node-graph).
694  /// Outputs are represented by attributes in the "outputs:" namespace.
695  /// If \p onlyAuthored is true (the default), then only return authored
696  /// attributes; otherwise, this also returns un-authored builtins.
697  ///
699  std::vector<UsdShadeOutput> GetOutputs(
700  bool onlyAuthored=true) const;
701 
702  /// @}
703 
704  /// \name Inputs
705  /// @{
706 
707  /// Create an input which can both have a value and be connected.
708  /// The attribute representing the input is created in the "inputs:"
709  /// namespace.
710  ///
713  const SdfValueTypeName& typeName) const;
714 
715  /// Return the requested input if it exists.
716  ///
717  /// \p name is the unnamespaced base name.
718  ///
720  UsdShadeInput GetInput(const TfToken &name) const;
721 
722  /// Returns all inputs on the connectable prim (i.e. shader or node-graph).
723  /// Inputs are represented by attributes in the "inputs:" namespace.
724  /// If \p onlyAuthored is true (the default), then only return authored
725  /// attributes; otherwise, this also returns un-authored builtins.
726  ///
728  std::vector<UsdShadeInput> GetInputs(
729  bool onlyAuthored=true) const;
730 
731  /// @}
732 
733 };
734 
735 /// A compact struct to represent a bundle of information about an upstream
736 /// source attribute
738  /// \p source is the connectable prim that produces or contains a value
739  /// for the given shading attribute.
741  /// \p sourceName is the name of the shading attribute that is the target
742  /// of the connection. This excludes any namespace prefix that determines
743  /// the type of the source (eg, output).
745  /// \p sourceType is used to indicate the type of the shading attribute
746  /// that is the target of the connection. The source type is used to
747  /// determine the namespace prefix that must be attached to \p sourceName
748  /// to determine the source full attribute name.
750  /// \p typeName, if specified, is the typename of the attribute to create
751  /// on the source if it doesn't exist when creating a connection
753 
754  UsdShadeConnectionSourceInfo() = default;
756  UsdShadeConnectableAPI const &source_,
757  TfToken const &sourceName_,
758  UsdShadeAttributeType sourceType_,
759  SdfValueTypeName typeName_ = SdfValueTypeName())
760  : source(source_)
761  , sourceName(sourceName_)
762  , sourceType(sourceType_)
763  , typeName(typeName_)
764  {}
766  : source(input.GetPrim())
767  , sourceName(input.GetBaseName())
769  , typeName(input.GetAttr().GetTypeName())
770  {}
772  : source(output.GetPrim())
773  , sourceName(output.GetBaseName())
775  , typeName(output.GetAttr().GetTypeName())
776  {}
777  /// Construct the information for this struct from a property path. The
778  /// source attribute does not have to exist, but the \p sourcePath needs to
779  /// have a valid prefix to identify the sourceType. The source prim needs
780  /// to exist and be UsdShadeConnectableAPI compatible
783  UsdStagePtr const& stage,
784  SdfPath const& sourcePath);
785 
786  /// Return true if this source info is valid for setting up a connection
787  bool IsValid() const {
788  // typeName can be invalid, so we don't check it. Order of checks is in
789  // order of cost (cheap to expensive).
790  // Note, for the source we only check that the prim is valid. We do not
791  // verify that the prim is compatibel with UsdShadeConnectableAPI. This
792  // makes it possible to target pure overs
794  !sourceName.IsEmpty() &&
795  (bool)source.GetPrim();
796  }
797  explicit operator bool() const {
798  return IsValid();
799  }
800  bool operator==(UsdShadeConnectionSourceInfo const& other) const {
801  // We don't compare the typeName, since it is optional
802  return sourceName == other.sourceName &&
803  sourceType == other.sourceType &&
804  source.GetPrim() == other.source.GetPrim();
805  }
806  bool operator!=(const UsdShadeConnectionSourceInfo &other) const {
807  return !(*this == other);
808  }
809 
810  template <typename HashState>
811  friend void TfHashAppend(HashState& h, const UsdShadeConnectionSourceInfo& info) {
812  // Using the same criteria as operator==(...)
813  h.Append(info.sourceName);
814  h.Append(info.sourceType);
815  h.Append(info.source.GetPrim());
816  }
817 };
818 
820 
821 #endif
UsdShadeConnectionSourceInfo(UsdShadeInput const &input)
static USDSHADE_API bool ConnectToSource(UsdShadeOutput const &output, SdfPath const &sourcePath)
#define USDSHADE_API
Definition: api.h:23
Non-applied API schema.
static USDSHADE_API bool GetConnectedSource(UsdShadeOutput const &output, UsdShadeConnectableAPI *source, TfToken *sourceName, UsdShadeAttributeType *sourceType)
static USDSHADE_API const TfTokenVector & GetSchemaAttributeNames(bool includeInherited=true)
T mod(T x, int y)
Definition: chrono.h:1648
static USDSHADE_API bool GetRawConnectedSourcePaths(UsdShadeInput const &input, SdfPathVector *sourcePaths)
static USDSHADE_API bool IsSourceConnectionFromBaseMaterial(const UsdShadeOutput &output)
static USDSHADE_API bool ConnectToSource(UsdShadeOutput const &output, UsdShadeConnectableAPI const &source, TfToken const &sourceName, UsdShadeAttributeType const sourceType=UsdShadeAttributeType::Output, SdfValueTypeName typeName=SdfValueTypeName())
GLsizei const GLfloat * value
Definition: glcorearb.h:824
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
static USDSHADE_API bool ConnectToSource(UsdShadeInput const &input, UsdShadeInput const &sourceInput)
static USDSHADE_API bool ClearSource(UsdShadeInput const &input)
USDSHADE_API UsdShadeInput GetInput(const TfToken &name) const
static USDSHADE_API bool ConnectToSource(UsdShadeInput const &input, UsdShadeConnectableAPI const &source, TfToken const &sourceName, UsdShadeAttributeType const sourceType=UsdShadeAttributeType::Output, SdfValueTypeName typeName=SdfValueTypeName())
static USDSHADE_API bool ConnectToSource(UsdShadeInput const &input, UsdShadeOutput const &sourceOutput)
USDSHADE_API std::vector< UsdShadeInput > GetInputs(bool onlyAuthored=true) const
UsdShadeConnectionModification
Definition: types.h:36
static USDSHADE_API bool CanConnect(const UsdShadeOutput &output, const UsdShadeInput &sourceInput)
static USDSHADE_API bool DisconnectSource(UsdAttribute const &shadingAttr, UsdAttribute const &sourceAttr=UsdAttribute())
static USDSHADE_API bool CanConnect(const UsdShadeInput &input, const UsdShadeInput &sourceInput)
friend void TfHashAppend(HashState &h, const UsdShadeConnectionSourceInfo &info)
USDSHADE_API std::vector< UsdShadeOutput > GetOutputs(bool onlyAuthored=true) const
OutGridT const XformOp bool bool
static USDSHADE_API UsdShadeConnectableAPI Get(const UsdStagePtr &stage, const SdfPath &path)
const UsdAttribute & GetAttr() const
Explicit UsdAttribute extractor.
Definition: output.h:196
bool operator==(UsdShadeConnectionSourceInfo const &other) const
USDSHADE_API UsdShadeOutput GetOutput(const TfToken &name) const
Definition: token.h:70
static USDSHADE_API bool GetRawConnectedSourcePaths(UsdAttribute const &shadingAttr, SdfPathVector *sourcePaths)
static bool HasConnectableAPI()
std::vector< class SdfPath > SdfPathVector
UsdShadeConnectableAPI(const UsdSchemaBase &schemaObj)
void GetAttr(const OrtKernelInfo *p, const char *name, float &)
static USDSHADE_API bool HasConnectedSource(const UsdShadeInput &input)
static USDSHADE_API bool ClearSources(UsdShadeOutput const &output)
UsdShadeConnectionSourceInfo(UsdShadeConnectableAPI const &source_, TfToken const &sourceName_, UsdShadeAttributeType sourceType_, SdfValueTypeName typeName_=SdfValueTypeName())
static USDSHADE_API bool HasConnectedSource(const UsdAttribute &shadingAttr)
GLsizei GLsizei GLchar * source
Definition: glcorearb.h:803
static USDSHADE_API bool ConnectToSource(UsdShadeInput const &input, SdfPath const &sourcePath)
Definition: prim.h:116
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:440
GLuint const GLchar * name
Definition: glcorearb.h:786
Definition: path.h:273
static USDSHADE_API bool ClearSources(UsdAttribute const &shadingAttr)
static USDSHADE_API bool ConnectToSource(UsdShadeOutput const &output, UsdShadeOutput const &sourceOutput)
UsdShadeConnectionSourceInfo(UsdShadeOutput const &output)
UsdSchemaKind
Definition: common.h:112
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2002
static USDSHADE_API bool DisconnectSource(UsdShadeOutput const &output, UsdAttribute const &sourceAttr=UsdAttribute())
virtual USDSHADE_API ~UsdShadeConnectableAPI()
Destructor.
USDSHADE_API bool RequiresEncapsulation() const
static USDSHADE_API bool GetRawConnectedSourcePaths(UsdShadeOutput const &output, SdfPathVector *sourcePaths)
USDSHADE_API bool _IsCompatible() const override
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
static const UsdSchemaKind schemaKind
static USDSHADE_API bool ConnectToSource(UsdShadeOutput const &output, UsdShadeConnectionSourceInfo const &source, ConnectionModification const mod=ConnectionModification::Replace)
static USDSHADE_API bool DisconnectSource(UsdShadeInput const &input, UsdAttribute const &sourceAttr=UsdAttribute())
static USDSHADE_API bool ClearSource(UsdAttribute const &shadingAttr)
static USDSHADE_API bool ClearSource(UsdShadeOutput const &output)
static USDSHADE_API bool SetConnectedSources(UsdAttribute const &shadingAttr, std::vector< UsdShadeConnectionSourceInfo > const &sourceInfos)
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
static USDSHADE_API bool GetConnectedSource(UsdAttribute const &shadingAttr, UsdShadeConnectableAPI *source, TfToken *sourceName, UsdShadeAttributeType *sourceType)
USDSHADE_API UsdShadeInput CreateInput(const TfToken &name, const SdfValueTypeName &typeName) const
static USDSHADE_API UsdShadeSourceInfoVector GetConnectedSources(UsdAttribute const &shadingAttr, SdfPathVector *invalidSourcePaths=nullptr)
Definition: type.h:47
static USDSHADE_API bool CanConnect(const UsdShadeInput &input, const UsdAttribute &source)
const UsdAttribute & GetAttr() const
Explicit UsdAttribute extractor.
Definition: input.h:212
static USDSHADE_API bool CanConnect(const UsdShadeInput &input, const UsdShadeOutput &sourceOutput)
static USDSHADE_API bool ConnectToSource(UsdAttribute const &shadingAttr, UsdShadeConnectionSourceInfo const &source, ConnectionModification const mod=ConnectionModification::Replace)
bool operator!=(const UsdShadeConnectionSourceInfo &other) const
USDSHADE_API UsdSchemaKind _GetSchemaKind() const override
UsdShadeAttributeType sourceType
UsdShadeConnectableAPI(const UsdPrim &prim=UsdPrim())
static USDSHADE_API bool IsSourceConnectionFromBaseMaterial(const UsdAttribute &shadingAttr)
static USDSHADE_API bool IsSourceConnectionFromBaseMaterial(const UsdShadeInput &input)
UsdShadeConnectableAPI source
static USDSHADE_API bool HasConnectedSource(const UsdShadeOutput &output)
static USDSHADE_API bool ClearSources(UsdShadeInput const &input)
bool IsValid() const
Return true if this source info is valid for setting up a connection.
static USDSHADE_API bool ConnectToSource(UsdShadeOutput const &output, UsdShadeInput const &sourceInput)
UsdPrim GetPrim() const
Return this schema object's held prim.
Definition: schemaBase.h:103
static USDSHADE_API bool CanConnect(const UsdShadeOutput &output, const UsdShadeOutput &sourceOutput)
USDSHADE_API UsdShadeOutput CreateOutput(const TfToken &name, const SdfValueTypeName &typeName) const
static USDSHADE_API bool GetConnectedSource(UsdShadeInput const &input, UsdShadeConnectableAPI *source, TfToken *sourceName, UsdShadeAttributeType *sourceType)
static USDSHADE_API bool ConnectToSource(UsdShadeInput const &input, UsdShadeConnectionSourceInfo const &source, ConnectionModification const mod=ConnectionModification::Replace)
USDSHADE_API bool IsContainer() const
bool IsEmpty() const
Returns true iff this token contains the empty string "".
Definition: token.h:288
UsdShadeAttributeType
Definition: types.h:22