All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
proxyShape.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 PXRUSDMAYA_PROXY_SHAPE_H
25 #define PXRUSDMAYA_PROXY_SHAPE_H
26 
28 
29 #include "usdMaya/api.h"
31 #include "usdMaya/usdPrimProvider.h"
32 
33 #include "pxr/pxr.h"
34 
35 #include "pxr/base/gf/ray.h"
36 #include "pxr/base/gf/vec3d.h"
37 #include "pxr/base/tf/staticTokens.h"
38 
39 #include "pxr/usd/sdf/path.h"
40 #include "pxr/usd/usd/notice.h"
41 #include "pxr/usd/usd/prim.h"
42 #include "pxr/usd/usd/timeCode.h"
43 
44 #include <maya/MBoundingBox.h>
45 #include <maya/MDagPath.h>
46 #include <maya/MDataBlock.h>
47 #include <maya/MDataHandle.h>
48 #include <maya/MDGContext.h>
49 #include <maya/MObject.h>
50 #include <maya/MPlug.h>
51 #include <maya/MPlugArray.h>
52 #include <maya/MPxSurfaceShape.h>
53 #include <maya/MSelectionMask.h>
54 #include <maya/MStatus.h>
55 #include <maya/MString.h>
56 #include <maya/MTypeId.h>
57 
58 #include <map>
59 
60 
61 PXR_NAMESPACE_OPEN_SCOPE
62 
63 
64 #define PXRUSDMAYA_PROXY_SHAPE_TOKENS \
65  ((MayaTypeName, "pxrUsdProxyShape"))
66 
67 TF_DECLARE_PUBLIC_TOKENS(UsdMayaProxyShapeTokens,
68  PXRUSDMAYA_API,
69  PXRUSDMAYA_PROXY_SHAPE_TOKENS);
70 
71 
72 class UsdMayaProxyShape : public MPxSurfaceShape,
73  public UsdMayaUsdPrimProvider
74 {
75  public:
76  PXRUSDMAYA_API
77  static const MTypeId typeId;
78  PXRUSDMAYA_API
79  static const MString typeName;
80 
81  PXRUSDMAYA_API
82  static const MString displayFilterName;
83  PXRUSDMAYA_API
84  static const MString displayFilterLabel;
85 
86  // Attributes
87  PXRUSDMAYA_API
88  static MObject filePathAttr;
89  PXRUSDMAYA_API
90  static MObject primPathAttr;
91  PXRUSDMAYA_API
92  static MObject excludePrimPathsAttr;
93  PXRUSDMAYA_API
94  static MObject timeAttr;
95  PXRUSDMAYA_API
96  static MObject variantKeyAttr;
97  PXRUSDMAYA_API
98  static MObject complexityAttr;
99  PXRUSDMAYA_API
100  static MObject inStageDataAttr;
101  PXRUSDMAYA_API
102  static MObject inStageDataCachedAttr;
103  PXRUSDMAYA_API
104  static MObject fastPlaybackAttr;
105  PXRUSDMAYA_API
106  static MObject outStageDataAttr;
107  PXRUSDMAYA_API
108  static MObject drawRenderPurposeAttr;
109  PXRUSDMAYA_API
110  static MObject drawProxyPurposeAttr;
111  PXRUSDMAYA_API
112  static MObject drawGuidePurposeAttr;
113 
114  PXRUSDMAYA_API
115  static MObject softSelectableAttr;
116 
124  typedef std::function<bool(const UsdMayaProxyShape&, const GfRay&,
125  GfVec3d*, GfVec3d*)> ClosestPointDelegate;
126 
129  typedef std::function<bool(void)> ObjectSoftSelectEnabledDelgate;
130 
131  PXRUSDMAYA_API
132  static void* creator();
133 
134  PXRUSDMAYA_API
135  static MStatus initialize();
136 
137  PXRUSDMAYA_API
138  static UsdMayaProxyShape* GetShapeAtDagPath(const MDagPath& dagPath);
139 
140  PXRUSDMAYA_API
141  static void SetClosestPointDelegate(ClosestPointDelegate delegate);
142 
143  PXRUSDMAYA_API
144  static void SetObjectSoftSelectEnabledDelegate(
145  ObjectSoftSelectEnabledDelgate delegate);
146 
147  PXRUSDMAYA_API
148  static bool GetObjectSoftSelectEnabled();
149 
150  // Virtual function overrides
151  PXRUSDMAYA_API
152  void postConstructor() override;
153  PXRUSDMAYA_API
154  MStatus compute(
155  const MPlug& plug,
156  MDataBlock& dataBlock) override;
157  PXRUSDMAYA_API
158  bool isBounded() const override;
159  PXRUSDMAYA_API
160  MBoundingBox boundingBox() const override;
161  PXRUSDMAYA_API
162  MSelectionMask getShapeSelectionMask() const override;
163 
164  PXRUSDMAYA_API
165  bool closestPoint(
166  const MPoint& raySource,
167  const MVector& rayDirection,
168  MPoint& theClosestPoint,
169  MVector& theClosestNormal,
170  bool findClosestOnMiss,
171  double tolerance) override;
172 
173  PXRUSDMAYA_API
174  bool canMakeLive() const override;
175 
176  // UsdMayaUsdPrimProvider overrides:
184  PXRUSDMAYA_API
185  UsdPrim usdPrim() const override;
186 
187  // Public functions
188  PXRUSDMAYA_API
189  SdfPathVector getExcludePrimPaths() const;
190 
191  PXRUSDMAYA_API
192  int getComplexity() const;
193 
194  PXRUSDMAYA_API
195  UsdTimeCode getTime() const;
196 
197  PXRUSDMAYA_API
198  bool GetAllRenderAttributes(
199  UsdPrim* usdPrimOut,
200  SdfPathVector* excludePrimPathsOut,
201  int* complexityOut,
202  UsdTimeCode* timeOut,
203  bool* drawRenderPurpose,
204  bool* drawProxyPurpose,
205  bool* drawGuidePurpose);
206 
207  PXRUSDMAYA_API
208  MStatus setDependentsDirty(
209  const MPlug& plug,
210  MPlugArray& plugArray) override;
211 
212  PXRUSDMAYA_API
213  bool setInternalValueInContext(
214  const MPlug& plug,
215  const MDataHandle& dataHandle,
216  MDGContext& ctx) override;
217 
218  PXRUSDMAYA_API
219  bool getInternalValueInContext(
220  const MPlug& plug,
221  MDataHandle& dataHandle,
222  MDGContext& ctx) override;
223 
224  protected:
225  PXRUSDMAYA_API
226  bool isStageValid() const;
227 
228  private:
229  UsdMayaProxyShape();
230 
231  UsdMayaProxyShape(const UsdMayaProxyShape&);
232  ~UsdMayaProxyShape() override;
233  UsdMayaProxyShape& operator=(const UsdMayaProxyShape&);
234 
235  MStatus computeInStageDataCached(MDataBlock& dataBlock);
236  MStatus computeOutStageData(MDataBlock& dataBlock);
237 
238  UsdPrim _GetUsdPrim(MDataBlock dataBlock) const;
239  SdfPathVector _GetExcludePrimPaths(MDataBlock dataBlock) const;
240  int _GetComplexity(MDataBlock dataBlock) const;
241  UsdTimeCode _GetTime(MDataBlock dataBlock) const;
242 
243  bool _GetDrawPurposeToggles(
244  MDataBlock dataBlock,
245  bool* drawRenderPurpose,
246  bool* drawProxyPurpose,
247  bool* drawGuidePurpose) const;
248 
249  bool _CanBeSoftSelected() const;
250 
251  void _OnStageContentsChanged(
252  const UsdNotice::StageContentsChanged& notice);
253 
254  UsdMayaStageNoticeListener _stageNoticeListener;
255 
256  std::map<UsdTimeCode, MBoundingBox> _boundingBoxCache;
257 
258  bool _useFastPlayback;
259 
260  static ClosestPointDelegate _sharedClosestPointDelegate;
261  static ObjectSoftSelectEnabledDelgate
262  _sharedObjectSoftSelectEnabledDelgate;
263 };
264 
265 
266 PXR_NAMESPACE_CLOSE_SCOPE
267 
268 
269 #endif
A notice listener that can invoke callbacks in response to notices about a specific USD stage...
Ultra-conservative notice sent when the given UsdStage&#39;s contents have changed in any way...
Definition: notice.h:73
Represent a time value, which may be either numeric, holding a double value, or a sentinel value UsdT...
Definition: timeCode.h:85
#define TF_DECLARE_PUBLIC_TOKENS(...)
Macro to define public tokens.
Definition: staticTokens.h:118
UsdPrim is the sole persistent scenegraph object on a UsdStage, and is the embodiment of a &quot;Prim&quot; as ...
Definition: prim.h:131
Basic type for a vector of 3 double components.
Definition: vec3d.h:63
Basic type: Ray used for intersection testing.
Definition: ray.h:60