AGX Dynamics  2.37.2.0
RigidBodySystemDrawable.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2024. Algoryx Simulation AB.
3 
4 All AGX source code, intellectual property, documentation, sample code,
5 tutorials, scene files and technical white papers, are copyrighted, proprietary
6 and confidential material of Algoryx Simulation AB. You may not download, read,
7 store, distribute, publish, copy or otherwise disseminate, use or expose this
8 material unless having a written signed agreement with Algoryx Simulation AB, or having been
9 advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10 valid commercial license from Algoryx Simulation AB.
11 
12 Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13 from using this software, unless otherwise stated in written agreements with
14 Algoryx Simulation AB.
15 */
16 
17 #ifndef AGXOSG_RIGID_BODY_SYSTEM_DRAWABLE_H
18 #define AGXOSG_RIGID_BODY_SYSTEM_DRAWABLE_H
19 
20 #include <agx/PushDisableWarnings.h> // Disabling warnings. Include agx/PopDisableWarnings.h below!
21 #include <osg/Drawable>
22 #include <osgViewer/Viewer>
23 #include <agx/PopDisableWarnings.h> // End of disabled warnings.
24 
25 #include <agxOSG/export.h>
26 #include <agxOSG/Node.h>
28 
29 #include <agx/Task.h>
30 #include <agx/observer_ptr.h>
31 #include <agx/RigidBodyEmitter.h>
32 
33 
34 namespace agxOSG
35 {
36  class AGXOSG_EXPORT RigidBodySystemDrawable : public osg::Group
37  {
38  public:
40 
42  // RigidBodySystemDrawable( const RigidBodySystemDrawable&c, const osg::CopyOp& copyOp );
43 
44  virtual osg::Object* cloneType() const { return new RigidBodySystemDrawable ( m_emitter.get() ); }
45  virtual osg::Object* clone(const osg::CopyOp&) const { return new RigidBodySystemDrawable (*this); }
46  virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const RigidBodySystemDrawable *>(obj)!=nullptr; }
47  virtual const char* libraryName() const { return "agxOSG"; }
48  virtual const char* className() const { return "RigidBodySystemDrawable"; }
49 
50  void createRigidBodyInstance( agx::RigidBody* body );
51 
52  static osg::Group* copyRigidBodyVisualChildren(agx::RigidBody* newBody, const RigidBodyRenderCache::RigidBodyVisualGroup& visualTemplateGroup);
53 
54  protected:
55  virtual ~RigidBodySystemDrawable();
56  void instanceCreated( agx::RigidBodyEmitter* emitter, agx::RigidBody* body, agx::RigidBodyEmitter::DistributionModel* model );
57  void addToBodyNodeCache( agx::RigidBody* body, RigidBodyRenderCache::RigidBodyVisualGroupRef group );
58  const RigidBodyRenderCache::RigidBodyVisualGroup& getCachedBodyNode( agx::RigidBody* body ) const;
59 
60  void initBodyCache( agx::RigidBodyEmitter* emitter );
61  bool bodyCacheIsEmpty();
62 
63  private:
64  mutable agx::RigidBodyEmitterObserver m_emitter;
65  agx::RigidBodyEmitter::Event::CallbackType m_createInstanceCallback;
67  // A placeholder for an empty visualization group
69  };
70 
71 }
72 
73 
74 #endif /* AGXOSG_RIGID_BODY_SYSTEM_DRAWABLE_H */
virtual osg::Object * cloneType() const
DistributionModel()
Default constructor.
#define AGXOSG_EXPORT
virtual const char * libraryName() const
agx::HashTable< agxCollide::Geometry *, GeometryNode * > GeometryToNodeCache
virtual bool isSameKindAs(const osg::Object *obj) const
virtual const char * className() const
The agxOSG namespace provides functionality for visualizing AGX simulations with OpenSceneGraph.
Smart pointer for handling referenced counted objects.
Definition: ref_ptr.h:29
A help class to store all information we need to copy a rigid body visualization to duplicate the rig...
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:54
Spawns new Rigid Bodies inside a volume given to the Emitter.
virtual osg::Object * clone(const osg::CopyOp &) const
Inheritance with partial specialization due to bug with ref_ptr containers.