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