Cortex  10.0.0-a4
SceneShapeInterface.h
1 //
3 // Copyright (c) 2013, Image Engine Design Inc. All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 //
12 // * Redistributions in binary form must reproduce the above copyright
13 // notice, this list of conditions and the following disclaimer in the
14 // documentation and/or other materials provided with the distribution.
15 //
16 // * Neither the name of Image Engine Design nor the names of any
17 // other contributors to this software may be used to endorse or
18 // promote products derived from this software without specific prior
19 // written permission.
20 //
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
22 // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23 // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
25 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 //
34 
35 #ifndef IE_COREMAYA_SCENESHAPEINTERFACE_H
36 #define IE_COREMAYA_SCENESHAPEINTERFACE_H
37 
38 #include "IECore/SceneInterface.h"
39 #include "IECore/CompoundParameter.h"
40 
41 #include <map>
42 #include "OpenEXR/ImathMatrix.h"
43 #include "IECoreGL/IECoreGL.h"
44 #include "maya/MPxComponentShape.h"
45 
46 
47 namespace IECoreGL
48 {
49 IE_CORE_FORWARDDECLARE( Scene );
50 IE_CORE_FORWARDDECLARE( State );
51 IE_CORE_FORWARDDECLARE( BoxPrimitive );
52 IE_CORE_FORWARDDECLARE( Primitive );
53 IE_CORE_FORWARDDECLARE( Group );
54 IE_CORE_FORWARDDECLARE( NameStateComponent );
55 IE_CORE_FORWARDDECLARE( Renderer );
56 }
57 
58 namespace IECoreMaya
59 {
60 
70 class SceneShapeInterface: public MPxComponentShape
71 {
73 
74  public:
75 
77  virtual ~SceneShapeInterface();
78 
79  /*
80  * For Maya
81  */
82 
83  virtual void postConstructor();
84  static void *creator();
85  static MStatus initialize();
86 
87  virtual bool isBounded() const;
88  virtual MBoundingBox boundingBox() const;
89  virtual MStatus setDependentsDirty( const MPlug &plug, MPlugArray &plugArray );
90  virtual MStatus compute( const MPlug &plug, MDataBlock &dataBlock );
91  virtual MatchResult matchComponent( const MSelectionList &item, const MAttributeSpecArray &spec, MSelectionList &list );
92 
93 #if MAYA_API_VERSION >= 201600
94 
95  virtual MStatus preEvaluation( const MDGContext &context, const MEvaluationNode &evaluationNode );
96 
97 #endif
98 
101  virtual MPxGeometryIterator* geometryIteratorSetup( MObjectArray&, MObject&, bool );
102 
105  virtual void transformUsing( const MMatrix &mat, const MObjectArray &componentList, MPxSurfaceShape::MVertexCachingMode cachingMode, MPointArray *pointCache );
106 
107  static MTypeId id;
108 
109  // Public variables because plugs need to be accessed by the UI creator which implements the drawing/selection
110  static MObject aObjectOnly;
111  static MObject aDrawGeometry;
112  static MObject aDrawRootBound;
113  static MObject aDrawChildBounds;
114  static MObject aDrawTagsFilter;
115 
116  /*
117  * Custom
118  */
119 
121  virtual IECore::ConstSceneInterfacePtr getSceneInterface();
122 
124  IECoreGL::ConstScenePtr glScene();
125 
127  IECoreGL::GroupPtr glGroup( const IECore::InternedString &name );
129  int selectionIndex( const IECore::InternedString &name );
133  const std::vector< IECore::InternedString > & componentNames() const;
135  double time() const;
136 
137  protected :
138 
139  // protected variables, used by derived classes to set attribute dependencies
140  static MObject aTime;
141  static MObject aOutTime;
142  static MObject aOutputObjects;
143  static MObject aObjectDependency;
144  static MObject aAttributes;
145  static MObject aTransform;
146  static MObject aBound;
147 
149  void setDirty();
150 
151  private :
152 
153  static MObject aQuerySpace;
154  static MObject aSceneQueries;
155  static MObject aAttributeQueries;
157 
163  static MObject aConvertParamQueries;
164 
165  static MObject aAttributeValues;
166 
167  static MObject aTranslate;
168  static MObject aTranslateX;
169  static MObject aTranslateY;
170  static MObject aTranslateZ;
171  static MObject aRotate;
172  static MObject aRotateX;
173  static MObject aRotateY;
174  static MObject aRotateZ;
175  static MObject aScale;
176  static MObject aScaleX;
177  static MObject aScaleY;
178  static MObject aScaleZ;
179 
180  static MObject aBoundMin;
181  static MObject aBoundMinX;
182  static MObject aBoundMinY;
183  static MObject aBoundMinZ;
184  static MObject aBoundMax;
185  static MObject aBoundMaxX;
186  static MObject aBoundMaxY;
187  static MObject aBoundMaxZ;
188  static MObject aBoundCenter;
189  static MObject aBoundCenterX;
190  static MObject aBoundCenterY;
191  static MObject aBoundCenterZ;
192 
194  enum Space
195  {
196  World,
197  Local
198  };
199 
200  bool m_sceneInterfaceDirty;
201  bool m_previewSceneDirty;
202 
203  IECoreGL::ScenePtr m_scene;
204 
206  void buildScene( IECoreGL::RendererPtr renderer, IECore::ConstSceneInterfacePtr subSceneInterface );
207 
209  void recurseBuildScene( IECoreGL::Renderer * renderer, const IECore::SceneInterface *subSceneInterface, double time, bool drawBounds, bool drawGeometry, bool objectOnly, const IECore::SceneInterface::NameList &drawTags );
210 
211  void createInstances();
212 
214  void buildGroups( IECoreGL::ConstNameStateComponentPtr nameState, IECoreGL::GroupPtr subScene );
215 
216  void registerGroup( const std::string &name, IECoreGL::GroupPtr &group );
217 
218  std::string relativePathName( IECore::SceneInterface::Path path );
219  IECore::SceneInterface::Path fullPathName( std::string relativeName );
221  Imath::M44d worldTransform( IECore::ConstSceneInterfacePtr scene, double time );
223  Imath::Box3d componentBound( int idx );
224  bool animatedScene();
225 
226  void recurseCopyGroup( const IECoreGL::Group *srcGroup, IECoreGL::Group *trgGroup, const std::string &namePrefix );
227 
228  bool readConvertParam( IECore::CompoundParameterPtr parameters, int attrIndex ) const;
229 
230  MStatus computeOutputPlug( const MPlug &plug, const MPlug &topLevelPlug, MDataBlock &dataBlock, const IECore::SceneInterface *scene, int topLevelIndex, int querySpace, MTime &time );
231 
232  typedef std::map< IECore::InternedString, std::pair< unsigned int, IECoreGL::GroupPtr> > NameToGroupMap;
233  typedef std::vector< IECore::InternedString > IndexToNameMap;
234  typedef std::map< IECore::MurmurHash, IECore::InternedString > HashToName;
235  typedef std::pair< IECore::InternedString, IECore::InternedString > InstanceInfo;
236  typedef std::vector< InstanceInfo > InstanceArray;
237 
238  IndexToNameMap m_indexToNameMap;
239  NameToGroupMap m_nameToGroupMap;
240  HashToName m_hashToName;
241  InstanceArray m_instances;
242 
243  IE_CORE_FORWARDDECLARE( PostLoadCallback );
244  PostLoadCallbackPtr m_postLoadCallback;
245 
246 };
247 
248 }
249 
250 #endif // IE_COREMAYA_SCENESHAPEINTERFACE_H
251 
double time() const
Return the value of the time plug for the SceneShape.
The namespace within which all CoreGL functionality is defined.
Definition: AlphaTexture.h:41
IECoreGL::ConstScenePtr glScene()
Returns the GL Scene representing the sceneInterface for the preview plug values ( objectOnly...
int selectionIndex(const IECore::InternedString &name)
Returns the internal index stored for the given path.
Definition: SceneShapeInterfaceComponentBoundIterator.h:53
const std::vector< IECore::InternedString > & componentNames() const
Returns all component names currently existing in the shape.
Definition: SceneShapeInterface.h:70
virtual void transformUsing(const MMatrix &mat, const MObjectArray &componentList, MPxSurfaceShape::MVertexCachingMode cachingMode, MPointArray *pointCache)
IECoreGL::GroupPtr glGroup(const IECore::InternedString &name)
Returns GL Group matching the given path name.
virtual IECore::ConstSceneInterfacePtr getSceneInterface()
Returns the sceneInterface for this node. Needs to be implemented by derived classes.
Definition: SceneInterface.h:69
IECore::InternedString selectionName(int index)
Returns the path name for the given index.
The IECoreMaya namespace holds all the functionality of libIECoreMaya.
Definition: BoolParameterHandler.h:44
Definition: InternedString.h:55
Definition: PostLoadCallback.h:50
Definition: Renderer.h:64
void setDirty()
Flags the GL scene as dirty, for use by derived classes.
virtual MPxGeometryIterator * geometryIteratorSetup(MObjectArray &, MObject &, bool)