AL_USDMaya  0.29.4
USD to Maya Bridge
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ProxyShape.h
1 //
2 // Copyright 2017 Animal Logic
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.//
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 #pragma once
17 
18 #include "../Api.h"
19 
20 #include <AL/usdmaya/ForwardDeclares.h>
21 #include "AL/maya/utils/Api.h"
22 #include "AL/maya/utils/MayaHelperMacros.h"
23 #include "AL/maya/utils/NodeHelper.h"
24 #include "AL/event/EventHandler.h"
25 #include "AL/maya/event/MayaEventManager.h"
26 #include <AL/usdmaya/SelectabilityDB.h>
27 #include "AL/usdmaya/DrivenTransformsData.h"
28 #include "AL/usdmaya/fileio/translators/TranslatorBase.h"
29 #include "AL/usdmaya/fileio/translators/TranslatorContext.h"
30 #include "AL/usdmaya/fileio/translators/TransformTranslator.h"
31 #include "AL/usdmaya/nodes/proxy/PrimFilter.h"
32 #include "maya/MPxSurfaceShape.h"
33 #include "maya/MEventMessage.h"
34 #include "maya/MNodeMessage.h"
35 #include "maya/MPxDrawOverride.h"
36 #include "maya/MEvaluationNode.h"
37 #include "maya/MDagModifier.h"
38 #include "maya/MObjectArray.h"
39 #include "maya/MSelectionList.h"
40 #include "pxr/pxr.h"
41 #include "pxr/usd/usd/prim.h"
42 #include "pxr/usd/usd/timeCode.h"
43 #include "pxr/usd/sdf/path.h"
44 #include "pxr/base/tf/weakBase.h"
45 #include "pxr/usd/usd/notice.h"
46 #include "pxr/usd/sdf/notice.h"
47 #include <stack>
48 #include <functional>
49 #include "AL/usd/utils/ForwardDeclares.h"
50 
51 PXR_NAMESPACE_USING_DIRECTIVE
52 
53 PXR_NAMESPACE_OPEN_SCOPE
54 
55 class UsdImagingGLHdEngine;
56 
57 // Note: you MUST forward declare LayerManager, and not include LayerManager.h;
58 // The reason is that LayerManager.h includes MPxLocatorNode.h, which on Linux,
59 // ends up bringing in Xlib.h, which has this unfortunate macro:
60 //
61 // #define Bool int
62 //
63 // This, in turn, will cause problems if you try to use SdfValueTypeNames->Bool,
64 // as in test_usdmaya_AttributeType.cpp
65 class LayerManager;
66 
67 PXR_NAMESPACE_CLOSE_SCOPE;
68 
69 namespace AL {
70 namespace usdmaya {
71 namespace nodes {
72 
73 //----------------------------------------------------------------------------------------------------------------------
86 //----------------------------------------------------------------------------------------------------------------------
88 {
90  typedef TfHashSet<SdfPath, SdfPath::Hash> SdfPathHashSet;
91 
97  SelectionUndoHelper(nodes::ProxyShape* proxy, const SdfPathHashSet& paths, MGlobal::ListAdjustment mode, bool internal = false);
98 
100  void doIt();
101 
103  void undoIt();
104 
105 private:
106  friend class ProxyShape;
107  nodes::ProxyShape* m_proxy;
108  SdfPathHashSet m_paths;
109  SdfPathHashSet m_previousPaths;
110  MGlobal::ListAdjustment m_mode;
111  MDagModifier m_modifier1;
112  MDagModifier m_modifier2;
113  MSelectionList m_previousSelection;
114  MSelectionList m_newSelection;
115  std::vector<std::pair<SdfPath, MObject>> m_insertedRefs;
116  std::vector<std::pair<SdfPath, MObject>> m_removedRefs;
117  bool m_internal;
118 };
119 
120 //----------------------------------------------------------------------------------------------------------------------
123 //----------------------------------------------------------------------------------------------------------------------
125 {
126 public:
128  typedef TfHashSet<SdfPath, SdfPath::Hash> SdfPathHashSet;
129 
131  SelectionList() = default;
132 
135  SelectionList(const SelectionList& sl) = default;
136 
138  ~SelectionList() = default;
139 
141  inline void clear()
142  { m_selected.clear(); }
143 
146  inline void add(SdfPath path)
147  {
148  m_selected.insert(path);
149  }
150 
153  inline void remove(SdfPath path)
154  {
155  auto it = m_selected.find(path);
156  if(it != m_selected.end())
157  {
158  m_selected.erase(it);
159  }
160  }
161 
164  inline void toggle(SdfPath path)
165  {
166  auto insertResult = m_selected.insert(path);
167  if (!insertResult.second)
168  {
169  m_selected.erase(insertResult.first);
170  }
171  }
172 
175  inline bool isSelected(const SdfPath& path) const
176  { return m_selected.count(path) > 0; }
177 
180  inline const SdfPathHashSet& paths() const
181  { return m_selected; }
182 
185  inline size_t size() const
186  { return m_selected.size(); }
187 
188 private:
189  SdfPathHashSet m_selected;
190 };
191 
192 //----------------------------------------------------------------------------------------------------------------------
194 //----------------------------------------------------------------------------------------------------------------------
196 {
199  preIteration(nullptr),
200  iteration(nullptr),
201  postIteration(nullptr)
202  {}
203 
205  std::function<void()> preIteration;
206 
208  std::function<void(const fileio::TransformIterator& transformIterator,const UsdPrim& prim)> iteration;
209 
211  std::function<void()> postIteration;
212 };
213 
214 //----------------------------------------------------------------------------------------------------------------------
217 //----------------------------------------------------------------------------------------------------------------------
219  : public HierarchyIterationLogic
220 {
221  SdfPathVector newUnselectables;
222  SdfPathVector removeUnselectables;
223 };
224 
225 //----------------------------------------------------------------------------------------------------------------------
227 //----------------------------------------------------------------------------------------------------------------------
229  : public HierarchyIterationLogic
230 {
231 };
232 
233 typedef const HierarchyIterationLogic* HierarchyIterationLogics[3];
234 typedef std::unordered_map<SdfPath, MString, SdfPath::Hash > PrimPathToDagPath;
235 
236 extern AL::event::EventId kPreClearStageCache;
237 extern AL::event::EventId kPostClearStageCache;
238 //----------------------------------------------------------------------------------------------------------------------
243 //----------------------------------------------------------------------------------------------------------------------
245  : public MPxSurfaceShape,
246  public AL::maya::utils::NodeHelper,
248  public AL::event::NodeEvents,
249  public TfWeakBase
250 {
251  friend struct SelectionUndoHelper;
252  friend class ProxyShapeUI;
253  friend class StageReloadGuard;
254  friend class ProxyDrawOverride;
255 public:
256 
257  // returns the shape's parent transform
258  MDagPath parentTransform();
259 
261  AL_USDMAYA_PUBLIC
262  void registerEvents();
263 
265  typedef TfHashSet<SdfPath, SdfPath::Hash> SdfPathHashSet;
266 
269  typedef std::vector<std::pair<MObject, UsdPrim> > MObjectToPrim;
270  AL_USDMAYA_PUBLIC
271  static const char* s_selectionMaskName;
272 
274  AL_USDMAYA_PUBLIC
275  ProxyShape();
276 
278  AL_USDMAYA_PUBLIC
279  ~ProxyShape();
280 
281  //--------------------------------------------------------------------------------------------------------------------
283  //--------------------------------------------------------------------------------------------------------------------
284  AL_MAYA_DECLARE_NODE();
285 
286  //--------------------------------------------------------------------------------------------------------------------
288  //--------------------------------------------------------------------------------------------------------------------
289 
291  AL_DECL_ATTRIBUTE(filePath);
292 
294  AL_DECL_ATTRIBUTE(primPath);
295 
297  AL_DECL_ATTRIBUTE(excludePrimPaths);
298 
300  AL_DECL_ATTRIBUTE(time);
301 
303  AL_DECL_ATTRIBUTE(timeOffset);
304 
307  AL_DECL_ATTRIBUTE(timeScalar);
308 
310  AL_DECL_ATTRIBUTE(complexity);
311 
313  AL_DECL_ATTRIBUTE(displayGuides);
314 
316  AL_DECL_ATTRIBUTE(displayRenderGuides);
317 
319  AL_DECL_ATTRIBUTE(layers);
320 
322  AL_DECL_ATTRIBUTE(serializedSessionLayer);
323 
325  AL_DECL_ATTRIBUTE(sessionLayerName);
326 
328  // @note currently not used
329  AL_DECL_ATTRIBUTE(serializedArCtx);
330 
332  AL_DECL_ATTRIBUTE(serializedTrCtx);
333 
335  AL_DECL_ATTRIBUTE(unloaded);
336 
338  AL_DECL_ATTRIBUTE(inDrivenTransformsData);
339 
341  AL_DECL_ATTRIBUTE(ambient);
342 
344  AL_DECL_ATTRIBUTE(diffuse);
345 
347  AL_DECL_ATTRIBUTE(specular);
348 
350  AL_DECL_ATTRIBUTE(emission);
351 
353  AL_DECL_ATTRIBUTE(shininess);
354 
356  AL_DECL_ATTRIBUTE(serializedRefCounts);
357 
359  AL_DECL_ATTRIBUTE(populationMaskIncludePaths);
360 
362  AL_DECL_ATTRIBUTE(version);
363 
365  AL_DECL_ATTRIBUTE(stageDataDirty);
366 
368  AL_DECL_ATTRIBUTE(excludedTranslatedGeometry);
369 
371  AL_DECL_ATTRIBUTE(stageCacheId);
372 
374  AL_DECL_ATTRIBUTE(assetResolverConfig);
375 
376  //--------------------------------------------------------------------------------------------------------------------
378  //--------------------------------------------------------------------------------------------------------------------
379 
381  AL_DECL_ATTRIBUTE(outTime);
382 
384  AL_DECL_ATTRIBUTE(outStageData);
385 
386 
387  //--------------------------------------------------------------------------------------------------------------------
389  //--------------------------------------------------------------------------------------------------------------------
390 
394  AL_USDMAYA_PUBLIC
395  UsdStageRefPtr getUsdStage() const;
396 
399  UsdStageRefPtr usdStage() const
400  { return m_stage; }
401 
408  bool getRenderAttris(void* attribs, const MHWRender::MFrameContext& frameContext, const MDagPath& dagPath);
409 
411  AL_USDMAYA_PUBLIC
412  MBoundingBox boundingBox() const override;
413 
414  //--------------------------------------------------------------------------------------------------------------------
421  //--------------------------------------------------------------------------------------------------------------------
422 
425  {
426  kSelection = 1 << 0,
427  kRequested = 1 << 1,
428  kRequired = 1 << 2
429  };
430 
432  enum class PickMode : int
433  {
434  kPrims = 0,
435  kModels = 1,
436  kInstances = 2,
437  };
438 
442  inline bool isRequiredPath(const SdfPath& path) const
443  { return m_requiredPaths.find(path) != m_requiredPaths.end(); }
444 
448  inline MObject findRequiredPath(const SdfPath& path) const
449  {
450  const auto it = m_requiredPaths.find(path);
451  if(it != m_requiredPaths.end())
452  {
453  return it->second.node();
454  }
455  return MObject::kNullObj;
456  }
457 
464  AL_USDMAYA_PUBLIC
465  std::vector<UsdPrim> huntForNativeNodesUnderPrim(
466  const MDagPath& proxyTransformPath,
467  SdfPath startPath,
469 
481  AL_USDMAYA_PUBLIC
482  MObject makeUsdTransformChain(
483  const UsdPrim& usdPrim,
484  MDagModifier& modifier,
485  TransformReason reason,
486  MDGModifier* modifier2 = 0,
487  uint32_t* createCount = 0);
488 
497  AL_USDMAYA_PUBLIC
498  MObject makeUsdTransforms(
499  const UsdPrim& usdPrim,
500  MDagModifier& modifier,
501  TransformReason reason,
502  MDGModifier* modifier2 = 0);
503 
511  AL_USDMAYA_PUBLIC
513  const UsdPrim& usdPrim,
514  MDagModifier& modifier,
515  TransformReason reason);
516 
522  AL_USDMAYA_PUBLIC
524  const SdfPath& path,
525  MDagModifier& modifier,
526  TransformReason reason);
527 
535  AL_USDMAYA_PUBLIC
536  void removeUsdTransforms(
537  const UsdPrim& usdPrim,
538  MDagModifier& modifier,
539  TransformReason reason);
540 
543  AL_USDMAYA_PUBLIC
544  void printRefCounts() const;
545 
548  { m_requiredPaths.clear(); }
549 
558  AL_USDMAYA_PUBLIC
559  void filterPrims(
560  const SdfPathVector& previousPrims,
561  std::vector<UsdPrim>& newPrimSet,
562  std::vector<UsdPrim>& transformsToCreate,
563  std::vector<UsdPrim>& updatablePrimSet,
564  SdfPathVector& removedPrimSet);
565 
571  AL_USDMAYA_PUBLIC
572  void getCounts(SdfPath path, uint32_t& selected, uint32_t& required, uint32_t& refCount)
573  {
574  auto it = m_requiredPaths.find(path);
575  if(it != m_requiredPaths.end())
576  {
577  selected = it->second.selected();
578  required = it->second.required();
579  refCount = it->second.refCount();
580  }
581  }
582 
588  AL_USDMAYA_PUBLIC
589  bool isSelectedMObject(MObject obj, SdfPath& path)
590  {
591  for(auto it : m_requiredPaths)
592  {
593  if(obj == it.second.node())
594  {
595  path = it.first;
596  if(m_selectedPaths.count(it.first) > 0)
597  {
598  return true;
599  }
600  break;
601  }
602  }
603  return false;
604  }
605 
606  //--------------------------------------------------------------------------------------------------------------------
608  //--------------------------------------------------------------------------------------------------------------------
609 
611  AL_USDMAYA_PUBLIC
613 
615  AL_USDMAYA_PUBLIC
617 
622  AL_USDMAYA_PUBLIC
623  MString recordUsdPrimToMayaPath(const UsdPrim &usdPrim,
624  const MObject &mayaObject);
625 
629  AL_USDMAYA_PUBLIC
630  MString getMayaPathFromUsdPrim(const UsdPrim& usdPrim);
631 
633  AL_USDMAYA_PUBLIC
634  void findTaggedPrims();
635 
636  AL_USDMAYA_PUBLIC
637  void findTaggedPrims(const HierarchyIterationLogics& iterationLogics);
638 
640  AL_USDMAYA_PUBLIC
641  void findExcludedGeometry();
642 
644  AL_USDMAYA_PUBLIC
645  void findSelectablePrims();
646 
648  AL_USDMAYA_PUBLIC
649  void iteratePrimHierarchy();
650 
654  { return m_translatorManufacture; }
655 
658  inline fileio::translators::TranslatorContextPtr& context()
659  { return m_context; }
660 
661  //--------------------------------------------------------------------------------------------------------------------
663  //--------------------------------------------------------------------------------------------------------------------
664 
667  AL_USDMAYA_PUBLIC
669  { return m_selectedPaths; }
670 
677  // they will get as the result of the command, ["|proxyRoot|foo|bar", "|proxyRoot|some|thing"], and be able
678  // to know what input SdfPath corresponds to what ouptut maya path
680  AL_USDMAYA_PUBLIC
681  bool doSelect(SelectionUndoHelper& helper, const SdfPathVector& orderedPaths);
682 
683  //--------------------------------------------------------------------------------------------------------------------
685  //--------------------------------------------------------------------------------------------------------------------
686 
688  AL_USDMAYA_PUBLIC
690 
693  inline UsdImagingGLHdEngine* engine() const
694  { return m_engine; }
695 
696  //--------------------------------------------------------------------------------------------------------------------
698  //--------------------------------------------------------------------------------------------------------------------
699 
703  AL_USDMAYA_PUBLIC
704  void unloadMayaReferences();
705 
711  UsdPrim getRootPrim()
712  {
713  if(m_stage)
714  {
715  if(!m_path.IsEmpty())
716  {
717  UsdPrim prim = m_stage->GetPrimAtPath(m_path);
718  if(prim)
719  return prim;
720  }
721  return m_stage->GetPseudoRoot();
722  }
723  return UsdPrim();
724  }
725 
727  AL_USDMAYA_PUBLIC
728  void serialiseTransformRefs();
729 
731  AL_USDMAYA_PUBLIC
733 
738  AL_USDMAYA_PUBLIC
739  void onPrePrimChanged(const SdfPath& path, SdfPathVector& outPathVector);
740 
744  AL_USDMAYA_PUBLIC
745  void onPrimResync(SdfPath primPath, SdfPathVector& changedPaths);
746 
750  AL_USDMAYA_PUBLIC
751  void resync(const SdfPath& primPath);
752 
753 
754  // \brief Serialize information unique to this shape
755  AL_USDMAYA_PUBLIC
756  void serialize(UsdStageRefPtr stage, LayerManager* layerManager);
757 
758  // \brief Serialize all layers in proxyShapes to layerManager attributes; called before saving
759  AL_USDMAYA_PUBLIC
760  static void serializeAll();
761 
762  static inline std::vector<MObjectHandle>& GetUnloadedProxyShapes()
763  {
764  return m_unloadedProxyShapes;
765  }
766 
769  inline void primChangedAtPath(const SdfPath& changePath)
770  {
771  UsdPrim p = m_stage->GetPrimAtPath(changePath);
772 
773  if(!p.IsValid())
774  {
775  MGlobal::displayInfo("ProxyShape: Could not change prim at path since there was no valid prim at the passed in path");
776  return;
777  }
778  m_compositionHasChanged = true;
779  m_changedPath = changePath;
780  onPrePrimChanged(m_changedPath, m_variantSwitchedPrims);
781  }
782 
785  inline void setHaveObjectsChangedAtPath(bool hasObjectsChanged)
786  { m_compositionHasChanged = hasObjectsChanged; }
787 
791  { return m_selectionList; }
792 
795  inline void setChangedSelectionState(bool v)
796  { m_hasChangedSelection = v; }
797 
801  { return m_selectabilityDB; }
802 
806  { return const_cast<ProxyShape*>(this)->selectabilityDB(); }
807 
809  AL_USDMAYA_PUBLIC
810  void loadStage();
811 
813  AL_USDMAYA_PUBLIC
815 
817  AL_USDMAYA_PUBLIC
819 
820  AL_USDMAYA_PUBLIC
821  void constructLockPrims();
822 
828  AL_USDMAYA_PUBLIC
830  const SdfPathVector& importPaths,
831  const SdfPathVector& teardownPaths,
833 
839  AL_USDMAYA_PUBLIC
841  const AL::usd::utils::UsdPrimVector& importPrims,
842  const SdfPathVector& teardownPaths,
844 
848  AL_USDMAYA_PUBLIC
849  SdfPathVector getPrimPathsFromCommaJoinedString(const MString &paths) const;
850 
852  AL_USDMAYA_PUBLIC
853  MSelectionMask getShapeSelectionMask() const override;
854 
855 private:
856 
857  static void onSelectionChanged(void* ptr);
858  bool removeAllSelectedNodes(SelectionUndoHelper& helper);
859  void removeTransformRefs(const std::vector<std::pair<SdfPath, MObject>>& removedRefs, TransformReason reason);
860  void insertTransformRefs(const std::vector<std::pair<SdfPath, MObject>>& removedRefs, TransformReason reason);
861 
862  void constructExcludedPrims();
863  bool updateLockPrims(const SdfPathSet& lockTransformPrims, const SdfPathSet& lockInheritedPrims,
864  const SdfPathSet& unlockedPrims);
865  bool lockTransformAttribute(const SdfPath& path, bool lock);
866 
867  MObject makeUsdTransformChain_internal(
868  const UsdPrim& usdPrim,
869  MDagModifier& modifier,
870  TransformReason reason,
871  MDGModifier* modifier2 = 0,
872  uint32_t* createCount = 0,
873  MString* newPath = 0);
874 
875  void removeUsdTransformChain_internal(
876  const UsdPrim& usdPrim,
877  MDagModifier& modifier,
878  TransformReason reason);
879 
880  MObject makeUsdTransformChain(
881  UsdPrim usdPrim,
882  const MPlug& outStage,
883  const MPlug& outTime,
884  const MObject& parentXForm,
885  MDagModifier& modifier,
886  TransformReason reason,
887  MDGModifier* modifier2,
888  uint32_t* createCount,
889  MString* newPath = 0);
890 
891  void makeUsdTransformsInternal(
892  const UsdPrim& usdPrim,
893  const MObject& parentXForm,
894  MDagModifier& modifier,
895  TransformReason reason,
896  MDGModifier* modifier2);
897 
898  void removeUsdTransformsInternal(
899  const UsdPrim& usdPrim,
900  MDagModifier& modifier,
901  TransformReason reason);
902 
903  struct TransformReference
904  {
905  TransformReference(const MObject& node, const TransformReason reason);
906  TransformReference(MObject mayaNode, Transform* node, uint32_t r, uint32_t s, uint32_t rc);
907  Transform* m_transform;
908  MObject node() const { return m_node; }
909 
910  bool decRef(const TransformReason reason);
911  void incRef(const TransformReason reason);
912  void checkIncRef(const TransformReason reason);
913  bool checkRef(const TransformReason reason);
914 
915  void printRefCounts() const
916  {
917  std::cout
918  << m_required << ":"
919  << m_selectedTemp << ":"
920  << m_selected << ":"
921  << int(m_refCount) << std::endl;
922  }
923  uint32_t selected() const { return m_selected; }
924  uint32_t required() const { return m_required; }
925  uint32_t refCount() const { return m_refCount; }
926  void prepSelect()
927  { m_selectedTemp = m_selected; }
928  private:
929  MObject m_node;
930  // ref counting values
931  struct
932  {
933  uint64_t m_required:16;
934  uint64_t m_selectedTemp:16;
935  uint64_t m_selected:16;
936  uint64_t m_refCount:16;
937  };
938  };
939 
944  typedef std::map<SdfPath, TransformReference> TransformReferenceMap;
945  TransformReferenceMap m_requiredPaths;
946 
947 
951  void cleanupTransformRefs();
952 
954  void makeTransformReference(const SdfPath& path, const MObject& node, TransformReason reason);
955 
958  void prepSelect();
959 
960  //--------------------------------------------------------------------------------------------------------------------
962  //--------------------------------------------------------------------------------------------------------------------
963 
964  void postConstructor() override;
965  MStatus compute(const MPlug& plug, MDataBlock& dataBlock) override;
966  MStatus setDependentsDirty(const MPlug& plugBeingDirtied, MPlugArray& plugs) override;
967  bool isBounded() const override;
968  #if MAYA_API_VERSION < 201700
969  MPxNode::SchedulingType schedulingType() const override { return kSerialize; }
970  #else
971  MPxNode::SchedulingType schedulingType() const override { return kSerial; }
972  #endif
973  MStatus preEvaluation(const MDGContext & context, const MEvaluationNode& evaluationNode) override;
974 
975  //--------------------------------------------------------------------------------------------------------------------
977  //--------------------------------------------------------------------------------------------------------------------
978 
979  // split out compute methods.
980  MStatus computeInStageDataCached(const MPlug& plug, MDataBlock& dataBlock);
981  MStatus computeOutStageData(const MPlug& plug, MDataBlock& dataBlock);
982  MStatus computeOutputTime(const MPlug& plug, MDataBlock& dataBlock, MTime&);
983  MStatus computeDrivenAttributes(const MPlug& plug, MDataBlock& dataBlock, const MTime&);
984 
985  //--------------------------------------------------------------------------------------------------------------------
987  //--------------------------------------------------------------------------------------------------------------------
988 
989  UsdPrim getUsdPrim(MDataBlock& dataBlock) const;
990  SdfPathVector getExcludePrimPaths() const;
991  UsdStagePopulationMask constructStagePopulationMask(const MString &paths) const;
992 
993  bool isStageValid() const;
994  bool primHasExcludedParent(UsdPrim prim);
995  bool initPrim(const uint32_t index, MDGContext& ctx);
996 
997  void layerIdChanged(SdfNotice::LayerIdentifierDidChange const& notice, UsdStageWeakPtr const& sender);
998  void onObjectsChanged(UsdNotice::ObjectsChanged const&, UsdStageWeakPtr const& sender);
999  void variantSelectionListener(SdfNotice::LayersDidChange const& notice);
1000  void onEditTargetChanged(UsdNotice::StageEditTargetChanged const& notice, UsdStageWeakPtr const& sender);
1001  void trackEditTargetLayer(LayerManager* layerManager=nullptr);
1002  static void onAttributeChanged(MNodeMessage::AttributeMessage, MPlug&, MPlug&, void*);
1003  void validateTransforms();
1004 
1005 
1006  TfToken getTypeForPath(const SdfPath& path) override
1007  { return m_context->getTypeForPath(path); }
1008 
1009  bool getTypeInfo(TfToken type, bool& supportsUpdate, bool& requiresParent) override
1010  {
1011  auto translator = m_translatorManufacture.get(type);
1012  if(translator)
1013  {
1014  supportsUpdate = translator->supportsUpdate();
1015  requiresParent = translator->needsTransformParent();
1016  }
1017  return translator != 0;
1018  }
1019 
1020 private:
1021  SdfPathVector m_pathsOrdered;
1022  static std::vector<MObjectHandle> m_unloadedProxyShapes;
1023 
1024  AL::usdmaya::SelectabilityDB m_selectabilityDB;
1025  HierarchyIterationLogics m_hierarchyIterationLogics;
1026  HierarchyIterationLogic m_findExcludedPrims;
1027  SelectionList m_selectionList;
1028  FindUnselectablePrimsLogic m_findUnselectablePrims;
1029  SdfPathHashSet m_selectedPaths;
1030  FindLockedPrimsLogic m_findLockedPrims;
1031  PrimPathToDagPath m_primPathToDagPath;
1032  std::vector<SdfPath> m_paths;
1033  std::vector<UsdPrim> m_prims;
1034  TfNotice::Key m_objectsChangedNoticeKey;
1035  TfNotice::Key m_variantChangedNoticeKey;
1036  TfNotice::Key m_editTargetChanged;
1037 
1038  mutable std::map<UsdTimeCode, MBoundingBox> m_boundingBoxCache;
1039  AL::event::CallbackId m_beforeSaveSceneId = -1;
1040  MCallbackId m_attributeChanged = 0;
1041  MCallbackId m_onSelectionChanged = 0;
1042  SdfPathVector m_excludedGeometry;
1043  SdfPathVector m_excludedTaggedGeometry;
1044  SdfPathSet m_lockTransformPrims;
1045  SdfPathSet m_lockInheritedPrims;
1046  SdfPathSet m_currentLockedPrims;
1047  static MObject m_transformTranslate;
1048  static MObject m_transformRotate;
1049  static MObject m_transformScale;
1050  UsdStageRefPtr m_stage;
1051  SdfPath m_path;
1052  fileio::translators::TranslatorContextPtr m_context;
1053  fileio::translators::TranslatorManufacture m_translatorManufacture;
1054  SdfPath m_changedPath;
1055  SdfPathVector m_variantSwitchedPrims;
1056  SdfLayerHandle m_prevEditTarget;
1057  UsdImagingGLHdEngine* m_engine = 0;
1058 
1059  uint32_t m_engineRefCount = 0;
1060  bool m_compositionHasChanged = false;
1061  bool m_drivenTransformsDirty = false;
1062  bool m_pleaseIgnoreSelection = false;
1063  bool m_hasChangedSelection = false;
1064 };
1065 
1066 //----------------------------------------------------------------------------------------------------------------------
1067 } // nodes
1068 } // usdmaya
1069 } // AL
1070 //----------------------------------------------------------------------------------------------------------------------
the node exists for selection
Definition: ProxyShape.h:426
the node has been requested by a user
Definition: ProxyShape.h:427
AL_USDMAYA_PUBLIC bool isSelectedMObject(MObject obj, SdfPath &path)
Tests to see if a given MObject is currently selected in the proxy shape. If the specified MObject is...
Definition: ProxyShape.h:589
void add(SdfPath path)
adds a path to the selection
Definition: ProxyShape.h:146
AL_USDMAYA_PUBLIC std::vector< UsdPrim > huntForNativeNodesUnderPrim(const MDagPath &proxyTransformPath, SdfPath startPath, fileio::translators::TranslatorManufacture &manufacture)
traverses the UsdStage looking for the prims that are going to be handled by custom transformer plug-...
AL_USDMAYA_PUBLIC void unloadMayaReferences()
unloads all maya references
AL_USDMAYA_PUBLIC MSelectionMask getShapeSelectionMask() const override
Returns the selection mask of the shape.
AL_USDMAYA_PUBLIC void translatePrimPathsIntoMaya(const SdfPathVector &importPaths, const SdfPathVector &teardownPaths, const fileio::translators::TranslatorParameters &param=fileio::translators::TranslatorParameters())
Translates prims at the specified paths, the operation conducted by the translator depends on which l...
AL_USDMAYA_PUBLIC void findExcludedGeometry()
searches for the excluded geometry
A custom proxy shape node that attaches itself to a USD file, and then renders it. The stage is held internally as a member variable, and it will be composed based on a change to the "filePath" attribute.
Definition: ProxyShape.h:244
SelectionList & selectionList()
provides access to the selection list on this proxy shape
Definition: ProxyShape.h:790
void setHaveObjectsChangedAtPath(bool hasObjectsChanged)
change the status of the composition changed status
Definition: ProxyShape.h:785
void undoIt()
will undo the selection changes
A class that provides the logic behind a hierarchy traversal through a UsdStage.
Definition: ProxyShape.h:195
AL_USDMAYA_PUBLIC UsdStageRefPtr getUsdStage() const
provides access to the UsdStage that this proxy shape is currently representing. This will cause a co...
AL_USDMAYA_PUBLIC void resync(const SdfPath &primPath)
Preps translators for change, and then re-ceates and updates the maya prim hierarchy below the specif...
std::vector< std::pair< MObject, UsdPrim > > MObjectToPrim
a mapping between a maya transform (or MObject::kNullObj), and the prim that exists at that location ...
Definition: ProxyShape.h:269
void toggle(SdfPath path)
toggles the path in the selection
Definition: ProxyShape.h:164
AL_USDMAYA_PUBLIC void onPrimResync(SdfPath primPath, SdfPathVector &changedPaths)
Re-Creates and updates the maya prim hierarchy starting from the specified primpath.
AL::usdmaya::SelectabilityDB & selectabilityDB()
Returns the SelectionDatabase owned by the ProxyShape.
Definition: ProxyShape.h:800
AL_USDMAYA_PUBLIC ProxyShape()
ctor
UsdPrim getRootPrim()
if a root prim has been specified by the user in the proxy shape AE, then this method will return the...
Definition: ProxyShape.h:711
AL_USDMAYA_PUBLIC MObject makeUsdTransformChain(const UsdPrim &usdPrim, MDagModifier &modifier, TransformReason reason, MDGModifier *modifier2=0, uint32_t *createCount=0)
constructs a single chain of transform nodes from the usdPrim to the root of this proxy shape...
AL_USDMAYA_PUBLIC void registerEvents()
a method that registers all of the events in the ProxyShape
size_t size() const
the paths in the selection list
Definition: ProxyShape.h:185
UsdStageRefPtr usdStage() const
provides access to the UsdStage that this proxy shape is currently representing
Definition: ProxyShape.h:399
AL_USDMAYA_PUBLIC SdfPathVector getPrimPathsFromCommaJoinedString(const MString &paths) const
Breaks a comma separated string up into a SdfPath Vector.
void primChangedAtPath(const SdfPath &changePath)
This function starts the prim changed process within the proxyshape.
Definition: ProxyShape.h:769
void setChangedSelectionState(bool v)
internal method used to correctly schedule changes to the selection list
Definition: ProxyShape.h:795
bool isSelected(const SdfPath &path) const
toggles the path in the selection
Definition: ProxyShape.h:175
AL_USDMAYA_PUBLIC void removeUsdTransformChain(const UsdPrim &usdPrim, MDagModifier &modifier, TransformReason reason)
will destroy all of the AL_usdmaya_Transform nodes from the prim specified, up to the root (unless an...
Transient aggregate of values that aims to direct the Translation of Prims. Typically an object of th...
Definition: TranslatorContext.h:54
AL_USDMAYA_PUBLIC void printRefCounts() const
Debugging util - prints out the reference counts for each AL_usdmaya_Transform that currently exists ...
SdfPathVector removeUnselectables
items that are unselectable, but need to be made selectable
Definition: ProxyShape.h:222
TfHashSet< SdfPath, SdfPath::Hash > SdfPathHashSet
a hash set of SdfPaths
Definition: ProxyShape.h:90
AL_USDMAYA_PUBLIC void translatePrimsIntoMaya(const AL::usd::utils::UsdPrimVector &importPrims, const SdfPathVector &teardownPaths, const fileio::translators::TranslatorParameters &param=fileio::translators::TranslatorParameters())
Translates prims at the specified paths, the operation conducted by the translator depends on which l...
AL_USDMAYA_PUBLIC MString recordUsdPrimToMayaPath(const UsdPrim &usdPrim, const MObject &mayaObject)
gets the maya node path for a prim, stores the mapping and returns it
PickMode
Selection pick modes (based on USD View application)
Definition: ProxyShape.h:432
implements the logic required when searching for locked prims within a UsdStage
Definition: ProxyShape.h:228
AL_USDMAYA_PUBLIC void addAttributeChangedCallback()
adds the attribute changed callback to the proxy shape
AL_USDMAYA_PUBLIC MBoundingBox boundingBox() const override
compute bounds
AL_DECL_ATTRIBUTE(filePath)
the input USD file path for this proxy
The UI component of the proxy shape node.
Definition: ProxyShapeUI.h:31
AL_USDMAYA_PUBLIC void serialiseTranslatorContext()
serialises the translator context
void clear()
clear the selection list
Definition: ProxyShape.h:141
SelectionUndoHelper(nodes::ProxyShape *proxy, const SdfPathHashSet &paths, MGlobal::ListAdjustment mode, bool internal=false)
Construct with the arguments to select / deselect nodes on a proxy shape.
AL_USDMAYA_PUBLIC SdfPathHashSet & selectedPaths()
returns the paths of the selected items within the proxy shape
Definition: ProxyShape.h:668
Pick the nearest model kind ancestor of target.
This class provides the draw override for the USD proxy shape node.
Definition: ProxyDrawOverride.h:44
implements the logic that constructs a list of objects that need to be added or removed from the sele...
Definition: ProxyShape.h:218
bool isRequiredPath(const SdfPath &path) const
returns true if the path is required for an imported schema prim
Definition: ProxyShape.h:442
AL_USDMAYA_PUBLIC void deserialiseTranslatorContext()
deserialises the translator context
void destroyTransformReferences()
destroys all internal transform references
Definition: ProxyShape.h:547
AL_USDMAYA_PUBLIC void removeAttributeChangedCallback()
removes the attribute changed callback from the proxy shape
std::function< void()> postIteration
provide a method to be called after iteration of the UsdStage hierarchy
Definition: ProxyShape.h:211
AL_USDMAYA_PUBLIC void findTaggedPrims()
aggregates logic that needs to iterate through the hierarchy looking for properties/metdata on prims ...
Pick an instance of the target (if available)
std::function< void()> preIteration
provide a method to be called prior to iteration of the UsdStage hierarchy
Definition: ProxyShape.h:205
const AL::usdmaya::SelectabilityDB & selectabilityDB() const
Returns the SelectionDatabase owned by the ProxyShape.
Definition: ProxyShape.h:805
HierarchyIterationLogic()
ctor
Definition: ProxyShape.h:198
Used as a way to construct a simple selection list that allows for selection highlighting without cre...
Definition: ProxyShape.h:124
void doIt()
performs the selection changes
AL_USDMAYA_PUBLIC void findSelectablePrims()
searches for paths which are selectable
The AL::usdmaya::nodes::Transform node is a custom transform node that allows you to manipulate a USD...
Definition: Transform.h:83
MObject findRequiredPath(const SdfPath &path) const
returns the MObject of the maya transform for requested path (or MObject::kNullObj) ...
Definition: ProxyShape.h:448
UsdImagingGLHdEngine * engine() const
returns the usd imaging engine for this proxy shape
Definition: ProxyShape.h:693
AL_USDMAYA_PUBLIC void getCounts(SdfPath path, uint32_t &selected, uint32_t &required, uint32_t &refCount)
a method that is used within testing only. Returns the current reference count state for the path ...
Definition: ProxyShape.h:572
The layer manager node handles serialization and deserialization of all layers used by all ProxyShape...
Definition: LayerManager.h:232
Forms a registry of all plug-in translator types registered.
Definition: TranslatorBase.h:246
AL_USDMAYA_PUBLIC void serialiseTransformRefs()
serialise the state of the transform ref counts prior to saving the file
TfHashSet< SdfPath, SdfPath::Hash > SdfPathHashSet
a hash set of SdfPaths
Definition: ProxyShape.h:128
AL_USDMAYA_PUBLIC MString getMayaPathFromUsdPrim(const UsdPrim &usdPrim)
returns the stored maya node path for a prim
TransformReason
an enum describing the reason that a transform exists in the scene
Definition: ProxyShape.h:424
SdfPathVector newUnselectables
items that need to be made unselectable
Definition: ProxyShape.h:221
const SdfPathHashSet & paths() const
the paths in the selection list
Definition: ProxyShape.h:180
std::function< void(const fileio::TransformIterator &transformIterator, const UsdPrim &prim)> iteration
a visitor method that is called on each of the UsdPrims in the stage hierarchy
Definition: ProxyShape.h:208
the node is required for an imported schema prim
Definition: ProxyShape.h:428
SelectionList()=default
default ctor
AL_USDMAYA_PUBLIC void onPrePrimChanged(const SdfPath &path, SdfPathVector &outPathVector)
Finds the corresponding translator for each decendant prim that has a corresponding Translator and ca...
TfHashSet< SdfPath, SdfPath::Hash > SdfPathHashSet
a set of SdfPaths
Definition: ProxyShape.h:265
AL_USDMAYA_PUBLIC void removeUsdTransforms(const UsdPrim &usdPrim, MDagModifier &modifier, TransformReason reason)
Will destroy all AL_usdmaya_Transform nodes found underneath the prim (unless those nodes are require...
bool getRenderAttris(void *attribs, const MHWRender::MFrameContext &frameContext, const MDagPath &dagPath)
gets hold of the attributes on this node that control the rendering in some way
AL_USDMAYA_PUBLIC bool doSelect(SelectionUndoHelper &helper, const SdfPathVector &orderedPaths)
Performs a selection operation on this node. Intended for use by the ProxyShapeSelect command only...
AL_USDMAYA_PUBLIC RefPtr get(const TfToken type_name)
returns a translator for the specified prim type.
The prim filter needs to know about some state provided in the proxy shape node. In order to maintain...
Definition: PrimFilter.h:37
AL_USDMAYA_PUBLIC void deserialiseTransformRefs()
deserialise the state of the transform ref counts prior to saving the file
fileio::translators::TranslatorManufacture & translatorManufacture()
returns the plugin translator registry assigned to this shape
Definition: ProxyShape.h:653
AL_USDMAYA_PUBLIC MObject makeUsdTransforms(const UsdPrim &usdPrim, MDagModifier &modifier, TransformReason reason, MDGModifier *modifier2=0)
Will construct AL_usdmaya_Transform nodes for all of the prims from the specified usdPrim and down...
AL_USDMAYA_PUBLIC void loadStage()
used to reload the stage after file open
A helper class to store the state that is modified during a change to the current selection within a ...
Definition: ProxyShape.h:87
Logic that stores a sorted list of paths which represent Selectable points in the USD hierarchy ...
Definition: SelectabilityDB.h:18
AL_USDMAYA_PUBLIC void filterPrims(const SdfPathVector &previousPrims, std::vector< UsdPrim > &newPrimSet, std::vector< UsdPrim > &transformsToCreate, std::vector< UsdPrim > &updatablePrimSet, SdfPathVector &removedPrimSet)
Internal method. Used to filter out a set of paths into groups that need to be created, deleted, or updating.
AL_USDMAYA_PUBLIC void constructGLImagingEngine()
constructs the USD imaging engine for this shape
AL_USDMAYA_PUBLIC ~ProxyShape()
dtor
fileio::translators::TranslatorContextPtr & context()
returns the plugin translator context assigned to this shape
Definition: ProxyShape.h:658