All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
instancerImager.h
Go to the documentation of this file.
1 //
2 // Copyright 2018 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 PXRUSDMAYAGL_INSTANCER_IMAGER_H
25 #define PXRUSDMAYAGL_INSTANCER_IMAGER_H
26 
28 
29 #include "pxrUsdMayaGL/api.h"
31 
32 #include "pxr/base/tf/singleton.h"
33 #include "pxr/base/tf/weakBase.h"
34 
35 #include "usdMaya/notice.h"
36 #include "usdMaya/util.h"
37 
38 #include <maya/MCallbackIdArray.h>
39 #include <maya/MDagMessage.h>
40 
41 PXR_NAMESPACE_OPEN_SCOPE
42 
52 public:
53  static UsdMayaGL_InstancerImager& GetInstance();
54 
57  void SyncShapeAdapters(const unsigned int displayStyle);
58 
61  void SyncShapeAdapters(const M3dView::DisplayStyle legacyDisplayStyle);
62 
69  void RemoveShapeAdapters(bool vp2);
70 
71 private:
74  struct _InstancerEntry {
75  MCallbackIdArray callbacks;
76 
77  // The shape adapter generates an in-memory USD stage, so don't create
78  // the shape adapters until we need them. For example, we might never
79  // need the legacy shape adapter if we only have VP2 viewports.
80  std::unique_ptr<UsdMayaGL_InstancerShapeAdapter> adapterVp2;
81  std::unique_ptr<UsdMayaGL_InstancerShapeAdapter> adapterLegacy;
82 
83  ~_InstancerEntry();
84  };
85 
88 
91  UsdMayaUtil::MObjectHandleUnorderedSet _instancersToRemove;
92 
94  UsdMayaUtil::MObjectHandleUnorderedSet _dirtyInstancersVp2;
95  UsdMayaUtil::MObjectHandleUnorderedSet _dirtyInstancersLegacy;
96 
98  UsdMayaUtil::MObjectHandleUnorderedSet _dirtyInstancerXformsVp2;
99  UsdMayaUtil::MObjectHandleUnorderedSet _dirtyInstancerXformsLegacy;
100 
102  MObjectHandle _cachedHdImagingShape;
103 
106 
108  static void _OnNodeDirty(
109  MObject& node,
110  void* clientData);
111 
115  static void _OnWorldMatrixChanged(
116  MObject &transformNode,
117  MDagMessage::MatrixModifiedFlags& modified,
118  void *clientData);
119 
123 
126  void _SyncShapeAdapters(
127  bool vp2,
128  const unsigned int vp2DisplayStyle,
129  const M3dView::DisplayStyle legacyDisplayStyle);
130 
135  void _DirtyHdImagingShape(bool createIfNeeded);
136 
140 
142  void _StartTrackingInstancer(const MObject& instancer);
144  void _StopTrackingInstancer(const MObjectHandle& instancerHandle);
145 
149 
151  void _OnSceneReset(
152  const UsdMayaSceneResetNotice& notice);
154  void _OnConnection(
157  void _OnDisconnection(
159 
161 
164 
165  friend class TfSingleton<UsdMayaGL_InstancerImager>;
166 };
167 
168 PXR_NAMESPACE_CLOSE_SCOPE
169 
170 #endif
Manage a single instance of an object (see.
Definition: singleton.h:122
Notice sent when any reference assembly is connected as a prototype of a native Maya instancer...
Definition: notice.h:86
Notice sent when any reference assembly was previously a prototype of a native Maya instancer but has...
Definition: notice.h:98
Notice sent when the Maya scene resets, either by opening a new scene or switching to a new scene...
Definition: notice.h:42
Class for syncing native Maya instancers with the pxrHdImagingShape so that it can draw USD reference...
std::unordered_map< MObjectHandle, V, _HashObjectHandle > MObjectHandleUnorderedMap
Unordered mapping of Maya object handles to an arbitrary type.
Definition: util.h:114
void RemoveShapeAdapters(bool vp2)
Destroys all shape adapters for currently tracked instancers, but does not stop tracking the instance...
void SyncShapeAdapters(const unsigned int displayStyle)
Sync all dirty instancer shape adapters for Viewport 2.0.
std::unordered_set< MObjectHandle, _HashObjectHandle > MObjectHandleUnorderedSet
Unordered set of Maya object handles.
Definition: util.h:109
Enable a concrete base class for use with TfWeakPtr.
Definition: weakBase.h:142