AGX Dynamics  2.35.0.1
agxOSG/RenderProxy.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2022. 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_RENDERPROXY_H
18 #define AGXOSG_RENDERPROXY_H
19 
20 #include <agxOSG/export.h>
21 #include <agxRender/RenderProxy.h>
23 
24 #include <agx/PushDisableWarnings.h> // Disabling warnings. Include agx/PopDisableWarnings.h below!
25 #include <osg/ref_ptr>
26 #include <osg/Group>
27 #include <osg/MatrixTransform>
28 #include <osg/Material>
29 #include <osg/AutoTransform>
30 #include <osg/Shape>
31 #include <osg/ShapeDrawable>
32 #include <agx/PopDisableWarnings.h> // End of disabled warnings.
33 
34 #include <agxOSG/GraphRenderer.h>
35 #include <agxOSG/RenderText.h>
36 #include <agxOSG/utils.h>
38 
39 #ifdef _MSC_VER
40 # pragma warning(push)
41 # pragma warning( disable : 4355 ) // warning C4355: 'this' : used in base member initializer list
42 #endif
43 
44 namespace osg
45 {
46  class Material;
47  class ShapeDrawable;
48 }
49 
50 namespace osgText
51 {
52  class Text;
53 }
54 
55 namespace agxOSG
56 {
57 
58  class SphereProxy;
59  class LineProxy;
60 
62 
75  {
76  public:
80  static void setDefaultDetailRatio( float detailRatio );
81 
85  static float getDefaultDetailRatio();
86 
87  public:
89 
94 
95 
100  agxRender::SphereProxy* createSphere( float radius ) override;
101 
107  agxRender::TextProxy* createText( const agx::String& text, const agx::Vec3& pos ) override;
108 
113  agxRender::LineProxy* createLine( const agx::Vec3& p1, const agx::Vec3& p2 ) override;
114 
120  agxRender::CylinderProxy* createCylinder( float radius, float height ) override;
121 
127  agxRender::HollowCylinderProxy* createHollowCylinder( float radius, float height, float thickness ) override;
128 
134  agxRender::CapsuleProxy* createCapsule( float radius, float height ) override;
135 
136 
144  agxRender::WireShapeProxy* createWireShape( float radius, float height,
145  const agx::Vec3& previousEndPoint0, const agx::Vec3& previousEndPoint1) override;
146 
147 
152  agxRender::BoxProxy* createBox( const agx::Vec3& halfExtents ) override;
153 
159 
165 
171  agxRender::ConeProxy *createCone( float radius, float height ) override;
172 
179  agxRender::TruncatedConeProxy *createTruncatedCone( float topRadius, float bottomRadius, float height ) override;
180 
187  agxRender::HollowTruncatedConeProxy* createHollowTruncatedCone( float topRadius, float bottomRadius, float height, float thickness ) override;
188 
194  agxRender::PlaneProxy *createPlane( const agx::Vec3& normal, agx::Real distance ) override;
195 
196 
202 
204 
205  agxRender::WireRenderProxy* createWire( float radius, const agx::Vec3& color ) override;
206 
207 
210  agxData::Buffer* positions, agxData::Buffer* rotations, agxData::Buffer* radii, agxData::Buffer* colors,
211  agxData::Buffer* enableRendering, agxData::Value* bound, agx::Component* context) override;
212 
218  osg::Group *getTextNode() { return m_textParent.get(); }
219 
224  osg::Node *getRootNode() { return m_parent; }
225 
229  osg::Group *getSolidRootNode() { return m_solidParent; }
230 
234  osg::Group *getWireframeRootNode() { return m_wireframeParent; }
235 
244 
248  const agx::AffineMatrix4x4& getGlobalTransform() const { return m_invTransform; }
249 
254 
255  public:
257  template<typename T>
258  struct ShapeData {
259  ShapeData() : material(nullptr) {}
260  ShapeData(const ShapeData& other)
261  {
262  shape = other.shape;
263  geode = other.geode;
264  material = other.material;
265  stateSet = other.stateSet;
266  }
267 
268  osg::ref_ptr<T> shape;
269  osg::ref_ptr<osg::Geode> geode;
270  osg::Material *material;
271  osg::ref_ptr<osg::StateSet> stateSet;
272  };
273 
274 
279  void addChild( osg::Node * node, agxRender::RenderProxy::RenderMode mode );
280  void addChild( osg::Node * node, agxRender::RenderProxy *proxy );
281 
282  protected:
285 
286  osg::ref_ptr<osg::Group> m_solidParent;
287  osg::ref_ptr<osg::Group> m_wireframeParent;
288  osg::ref_ptr<osg::MatrixTransform> m_parent;
289  osg::ref_ptr<osg::Group> m_textParent;
293  };
294 
295 
296 
298  template<typename T>
299  class OSGData
300  {
301  public:
303  : m_data(data), m_factory(factory), m_proxy(proxy)
304  {
305  m_transformNode = new osg::MatrixTransform;
306 
307  m_transformNode->addChild( m_data.geode );
308 
309  // Tell osg not to remove this transformation under optimization pass
310  m_transformNode->setDataVariance( osg::Object::DYNAMIC );
311 
312  m_data.stateSet = m_transformNode->getOrCreateStateSet();
313 
314  m_data.material = new osg::Material;
315  m_data.stateSet->setAttributeAndModes(m_data.material,osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE | osg::StateAttribute::PROTECTED);
316  setColorOSG( agx::Vec3( 1, 0, 0 ), 1.f );
317  }
318 
320  : m_data(), m_factory( factory ), m_proxy( proxy )
321  {
322  m_transformNode = new osg::MatrixTransform();
323  m_transformNode->setDataVariance( osg::Object::DYNAMIC );
324 
325  m_data.stateSet = m_transformNode->getOrCreateStateSet();
326  m_data.material = new osg::Material;
327  m_data.stateSet->setAttributeAndModes( m_data.material, osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE | osg::StateAttribute::PROTECTED );
328  setColorOSG( agx::Vec3( 1, 0, 0 ), 1.f );
329  }
330 
333  {
336  m_transformNode->setMatrix( AGX_MAT4X4_TO_OSG( m ) );
337  }
338 
340  void setEnableOSG( bool flag )
341  {
342  if (!flag) { // Remove node from all its parents
343  while(m_transformNode->getNumParents())
344  {
345  m_transformNode->getParent(0)->removeChild( m_transformNode.get() );
346  }
347 
348  }
349  else //Add it for rendering again.
351  }
352 
354  void setAlphaOSG( float transparency )
355  {
356  m_data.material->setTransparency(osg::Material::FRONT_AND_BACK, 1-transparency);
357  }
358 
360  void setColorOSG(const agx::Vec3& color, float alpha)
361  {
362  osg::Vec4 col = m_data.material->getDiffuse(osg::Material::FRONT_AND_BACK);
363 
364  if ( agx::equivalent( (float)col[0], (float)color[0] ) &&
365  agx::equivalent( (float)col[1], (float)color[1] ) &&
366  agx::equivalent( (float)col[2], (float)color[2] ) )
367  return;
368 
369  osg::Vec4 osgCol( (float)color[0], (float)color[1], (float)color[2], alpha );
370  m_data.material->setDiffuse(osg::Material::FRONT_AND_BACK, osgCol);
371 
372  for ( unsigned int i = 0; m_data.geode != nullptr && i < m_data.geode->getNumDrawables(); ++i ) {
373  osg::ShapeDrawable* drawable = dynamic_cast< osg::ShapeDrawable* >( m_data.geode->getDrawable( i ) );
374  if ( drawable )
375  drawable->setColor( osgCol );
376  }
377  }
378 
380  void onRemoveOSG()
381  {
382  osg::ref_ptr<osg::MatrixTransform> r = m_transformNode;
383  while(m_transformNode->getNumParents())
384  {
385  m_transformNode->getParent(0)->removeChild( m_transformNode.get() );
386  }
387  }
388 
391  {
393  }
394 
396  osg::MatrixTransform* getNode() { return m_transformNode.get(); }
397 
398  protected:
399  osg::ref_ptr<osg::MatrixTransform> m_transformNode;
404  };
405 
407 #define ADD_COMMON_METHODS() \
408  void onChange( RenderProxy::EventType type ) override { \
409  switch( type ) { \
410  case (RenderProxy::ENABLE): \
411  this->setEnableOSG(this->getEnable()); \
412  break; \
413  case (RenderProxy::ALPHA): \
414  this->setAlphaOSG(this->getAlpha()); \
415  break; \
416  case (RenderProxy::TRANSFORM): \
417  this->setTransformOSG(this->getTransform()); \
418  break; \
419  case (RenderProxy::COLOR): \
420  this->setColorOSG(this->getColor(), this->getAlpha()); \
421  break; \
422  case (RenderProxy::SHAPE): \
423  break; \
424  case (RenderProxy::REMOVE): \
425  this->onRemoveOSG(); \
426  break; \
427  case (RenderProxy::RENDERMODE): \
428  this->setRenderModeOSG(this->getRenderMode()); \
429  break; \
430  } \
431  } \
432  virtual void updateShape() override
433 
435  class AGXOSG_EXPORT SphereProxy : public agxRender::SphereProxy, public OSGData<osg::Sphere>
436  {
437  public:
439 
440  protected:
441  virtual ~SphereProxy() {}
442 
444  };
445 
447  class AGXOSG_EXPORT TextProxy : public agxRender::TextProxy, public OSGData<agxOSG::TextGeometry>
448  {
449  public:
451 
453 
454  protected:
455  virtual ~TextProxy() {}
456 
458  };
459 
460 
462  class AGXOSG_EXPORT BoxProxy : public agxRender::BoxProxy, public OSGData<osg::Box>
463  {
464  public:
466 
467  protected:
468  virtual ~BoxProxy() {}
469 
471  };
472 
474  class AGXOSG_EXPORT LineProxy : public agxRender::LineProxy, public OSGData<osg::Geometry>
475  {
476  public:
478 
479  protected:
480  virtual ~LineProxy() {}
481 
483  };
484 
486  class AGXOSG_EXPORT CylinderProxy : public agxRender::CylinderProxy, public OSGData<osg::Cylinder>
487  {
488  public:
490 
491  protected:
492  virtual ~CylinderProxy() {}
493 
495  };
496 
499  {
500  public:
501  HollowCylinderProxy( float radius, float height, float thickness, RenderProxyFactory::ShapeData<osg::Geometry> data, RenderProxyFactory* factory );
502 
503  protected:
504  virtual ~HollowCylinderProxy() {}
505 
507  };
508 
510  class AGXOSG_EXPORT ConeProxy : public agxRender::ConeProxy, public OSGData<osg::Cone>
511  {
512  public:
513  ConeProxy( float radius, float height, RenderProxyFactory::ShapeData<osg::Cone> data, RenderProxyFactory* factory );
514 
515  protected:
516  virtual ~ConeProxy() {}
517 
519  };
520 
523  {
524  public:
525  TruncatedConeProxy( float topRadius, float bottomRadius, float height, RenderProxyFactory::ShapeData<osg::Geometry> data, RenderProxyFactory* factory );
526 
527  protected:
528  virtual ~TruncatedConeProxy() {}
529 
531  };
532 
535  {
536  public:
537  HollowTruncatedConeProxy( float topRadius, float bottomRadius, float height, float thickness,
539 
540  protected:
542 
544  };
545 
547  class AGXOSG_EXPORT PlaneProxy : public agxRender::PlaneProxy, public OSGData<osg::Geometry>
548  {
549  public:
551 
552  protected:
553  virtual ~PlaneProxy() {}
554 
556  };
557 
559  class AGXOSG_EXPORT CapsuleProxy : public agxRender::CapsuleProxy, public OSGData<osg::Capsule>
560  {
561  public:
562  CapsuleProxy( float radius, float height, RenderProxyFactory::ShapeData<osg::Capsule> data, RenderProxyFactory* factory );
563 
564  protected:
565  virtual ~CapsuleProxy() {}
566 
568  };
569 
570 
572  class AGXOSG_EXPORT WireShapeProxy : public agxRender::WireShapeProxy, public OSGData<osg::CompositeShape>
573  {
574  public:
575  WireShapeProxy( float radius, float height, const agx::Vec3& previousEndPoint0, const agx::Vec3& previousEndPoint1,
577 
578  protected:
579  virtual ~WireShapeProxy() {}
580 
582  };
583 
586  {
587  public:
589 
590  void set( const agx::Vec2iVector& modifiedIndices, const agx::RealVector& heights ) override;
591 
592  protected:
593  virtual ~HeightFieldProxy() {}
594 
596  };
597 
599  class AGXOSG_EXPORT TrimeshProxy : public agxRender::TrimeshProxy, public OSGData<osg::TriangleMesh>
600  {
601  public:
603 
604  protected:
605  virtual ~TrimeshProxy() {}
606 
608  };
609 
614  template< typename TransformType >
615  class ShapeBatchRenderer : public OSGData< osg::Group >
616  {
617  public:
621  void clear();
622 
627  void setScale( float scale );
628 
632  float getScale() const;
633 
634  protected:
642 
650 
654  virtual ~ShapeBatchRenderer() { clear(); }
655 
660  void prepare( size_t numObjects );
661 
665  void prepareWithScale( size_t numObjects );
666 
673  void setTransform( TransformType* obj, const agx::AffineMatrix4x4& transform, const agx::Vec3f& scale );
674 
675  protected:
676  osg::ref_ptr< osg::Geode > m_geode;
677  float m_scale;
678  };
679 
691  template< typename ContainerType, typename TransformType >
692  class ContainerShapeBatchRenderer : public ShapeBatchRenderer< TransformType >
693  {
694  public:
702  ContainerShapeBatchRenderer( osg::Geode* geode, const ContainerType* container, agxOSG::RenderProxyFactory* factory, agxRender::RenderProxy* proxy )
703  : ShapeBatchRenderer< TransformType >( geode, factory, proxy ), m_container( container ) {}
704 
708  virtual ~ContainerShapeBatchRenderer() { this->clear(); }
709 
713  void clear();
714 
718  void update( bool addScaleTransform = false );
719 
723  void setContainer( const ContainerType* container );
724 
725  protected:
731  agx::AffineMatrix4x4 findTransform( const typename ContainerType::value_type& val ) const;
732 
737  agx::Vec3f findScale( const typename ContainerType::value_type& val ) const;
738 
739  protected:
740  const ContainerType* m_container;
741  };
742 
743  #if 0
744  class SphereSpriteBatchRenderer : public ContainerShapeBatchRenderer< agxData::Array< agx::Vec3 >, osg::MatrixTransform >, public agxRender::SphereSpriteBatchRenderProxy
745  {
746  public:
747  SphereSpriteBatchRenderer( osg::Geode* geode, const agxData::Array< agx::Vec3 >* container, agxOSG::RenderProxyFactory* factory )
748  : ContainerShapeBatchRenderer< agxData::Array< agx::Vec3 >, osg::MatrixTransform >( geode, container, factory, this ),
749  agxRender::SphereSpriteBatchRenderProxy( container ) {}
750 
751  protected:
752  virtual ~SphereSpriteBatchRenderer() {}
753 
755  {
756  this->m_container = m_buffer;
757  this->update();
758  }
759 
760  virtual void reset() override
761  {
762  // I don't think we can or could do anything during reset.
763  }
764  };
765  #endif
766 
770  template< typename ContainerType, typename TransformType >
772  {
773  public:
774  RigidBodyBatchRenderProxy( osg::Geode* geode, const ContainerType* container, agxOSG::RenderProxyFactory* factory )
775  : ContainerShapeBatchRenderer< ContainerType, TransformType >( geode, container, factory, this ) {}
776 
777  protected:
779 
780  // This is virtual void updateShape().
782  {
783  this->m_container = &m_bodies;
785 
786  // Will update root transform given a global transform.
788 
789  this->update();
790  }
791 
792  virtual void reset() override
793  {
794  // I don't think we can or could do anything during reset.
795  }
796  };
797 
801  class ContactProxy : public ContainerShapeBatchRenderer< agxCollide::GeometryContactPtrVector, osg::AutoTransform >, public agxRender::ContactsProxy
802  {
803  public:
804  ContactProxy( osg::Geode* geode, const agxCollide::GeometryContactPtrVector* contacts, agxOSG::RenderProxyFactory* factory );
805 
806  protected:
807  virtual ~ContactProxy() {}
808 
810 
811  virtual void reset() override
812  {
813  // I don't think we can or could do anything during reset.
814  }
815  };
816 
818  {
819  public:
820  WireRenderProxy( float radius, const agx::Vec3& color, osg::Geode* segmentGeode, osg::Geode* edgeGeode, osg::Geode* nodeGeode, agxOSG::RenderProxyFactory* factory );
821 
822  osg::MatrixTransform* getSegmentTransform();
823  osg::MatrixTransform* getEdgeTransform();
824  osg::MatrixTransform* getSphereTransform();
825 
826  protected:
827  virtual ~WireRenderProxy();
828 
829  virtual void onAddNotification() override;
830  virtual void onRemoveNotification() override;
831 
833  void setEnableOSG( bool flag );
834  void setAlphaOSG( float transparency );
835  void setColorOSG(const agx::Vec3& color, float alpha);
836  void onRemoveOSG();
838 
840 
841  virtual void reset() override
842  {
843  // I don't think we can or could do anything during reset.
844  }
845 
846  protected:
850 
851  private:
852  // Not defined to call this method on this object.
853  osg::MatrixTransform* getNode() { return nullptr; }
854  };
855 
856  template< typename TransformType >
858  {
859  if ( m_transformNode )
860  m_transformNode->removeChild( 0, m_transformNode->getNumChildren() );
861  }
862 
863  template< typename TransformType >
865  {
866  m_scale = scale;
867  }
868 
869  template< typename TransformType >
871  {
872  return m_scale;
873  }
874 
875  template< typename ContainerType, typename TransformType >
877  {
879  m_container = nullptr;
880  }
881 
882  template< typename ContainerType, typename TransformType >
883  void ContainerShapeBatchRenderer< ContainerType, TransformType >::update( bool addScaleTransform /* = false */ )
884  {
885  if ( this->m_container == nullptr )
886  return;
887 
888  if ( addScaleTransform )
889  this->prepareWithScale( this->m_container->size() );
890  else
891  this->prepare( this->m_container->size() );
892 
893  unsigned int counter = 0;
894  for ( typename ContainerType::const_iterator i = m_container->begin(); i != m_container->end(); ++counter, ++i ) {
895  agxAssert( counter < this->m_transformNode->getNumChildren() );
896  TransformType* transform = static_cast< TransformType* >( this->m_transformNode->getChild( counter ) );
897  this->setTransform( transform, this->findTransform( *i ), this->findScale( *i ) );
898  }
899  }
900 
901  template< typename ContainerType, typename TransformType >
903  {
904  m_container = container;
905  }
906 
907  template< typename ContainerType, typename TransformType >
909  {
910  return val->getTransform();
911  }
912 
913  template<>
915  {
916  return agx::AffineMatrix4x4();
917  }
918 
919  template<>
921  {
922  return rbRefPtr->getCmTransform();
923  }
924 
925  template<>
927  {
928  return rbPtr->getCmTransform();
929  }
930 
931  template<>
933  {
935  }
936 
937  template< typename ContainerType, typename TransformType >
938  agx::Vec3f ContainerShapeBatchRenderer< ContainerType, TransformType >::findScale( const typename ContainerType::value_type& /*val*/ ) const
939  {
941  }
942 
943  template<>
945  {
946  return val->getScale();
947  }
948 }
949 
950 #ifdef _MSC_VER
951 # pragma warning(pop)
952 #endif
953 
954 #endif
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:248
#define ADD_COMMON_METHODS()
Macro for adding some methods for each specialization of RenderProxy.
#define AGX_MAT4X4_TO_OSG(X)
#define AGXOSG_EXPORT
A HeightField is a collision shape that can be created from a grid structure, like an image.
Triangle mesh for geometric intersection tests.
Definition: Trimesh.h:43
Type-specific Array used for fast access into the data held by a Buffer.
Definition: Array.h:107
Abstract representation of a data buffer.
Definition: Buffer.h:56
Abstract representation of a value.
Definition: Value.h:43
Implementation of osg-based BoxProxy.
BoxProxy(const agx::Vec3 &halfExtents, RenderProxyFactory::ShapeData< osg::Box > box, RenderProxyFactory *factory)
Implementation of osg-based CapsuleProxy.
CapsuleProxy(float radius, float height, RenderProxyFactory::ShapeData< osg::Capsule > data, RenderProxyFactory *factory)
Implementation of osg-based ConeProxy.
ConeProxy(float radius, float height, RenderProxyFactory::ShapeData< osg::Cone > data, RenderProxyFactory *factory)
Implementation of batch rendering of contact points.
virtual void reset() override
Will reset color, alpha and enabled state back to default state (as when initially created).
ContactProxy(osg::Geode *geode, const agxCollide::GeometryContactPtrVector *contacts, agxOSG::RenderProxyFactory *factory)
Class that handles batch rendering of objects in forward iterator compliant container.
void clear()
Reset container pointer and removes all child transforms.
void setContainer(const ContainerType *container)
Assign compatible container.
ContainerShapeBatchRenderer(osg::Geode *geode, const ContainerType *container, agxOSG::RenderProxyFactory *factory, agxRender::RenderProxy *proxy)
Construct given shape composite and compatible container.
void update(bool addScaleTransform=false)
Updates transforms.
agx::Vec3f findScale(const typename ContainerType::value_type &val) const
Find scale (agx::Vec3) given container value type.
agx::AffineMatrix4x4 findTransform(const typename ContainerType::value_type &val) const
Find transform (agx::AffineMatrix4x4) given container value type.
virtual ~ContainerShapeBatchRenderer()
Destructor.
Implementation of osg-based CylinderProxy.
CylinderProxy(float radius, float height, RenderProxyFactory::ShapeData< osg::Cylinder > data, RenderProxyFactory *factory)
Implementation of osg-based HeightfieldProxy.
virtual ~HeightFieldProxy()
Destructor.
void set(const agx::Vec2iVector &modifiedIndices, const agx::RealVector &heights) override
Override this method to support changing a selection of indices in the heightfield.
HeightFieldProxy(agxCollide::HeightField *hf, RenderProxyFactory::ShapeData< osg::Geometry > hfData, RenderProxyFactory *factory)
Implementation of osg-based HollowCylinderProxy.
HollowCylinderProxy(float radius, float height, float thickness, RenderProxyFactory::ShapeData< osg::Geometry > data, RenderProxyFactory *factory)
Implementation of osg-based HollowTruncatedConeProxy.
HollowTruncatedConeProxy(float topRadius, float bottomRadius, float height, float thickness, RenderProxyFactory::ShapeData< osg::Geometry > data, RenderProxyFactory *factory)
Implementation of osg-based LineProxy.
LineProxy(const agx::Vec3 &p1, const agx::Vec3 &p2, RenderProxyFactory::ShapeData< osg::Geometry > line, RenderProxyFactory *factory)
Class for handling methods related to OSG such as setColor, setTransform etc.
OSGData(agxOSG::RenderProxyFactory *factory, agxRender::RenderProxy *proxy)
agx::AffineMatrix4x4 m_invTransform
OSGData(const RenderProxyFactory::ShapeData< T > &data, agxOSG::RenderProxyFactory *factory, agxRender::RenderProxy *proxy)
osg::MatrixTransform * getNode()
\ return the node for this RenderProxy
void setEnableOSG(bool flag)
Enable/disable rendering.
void setTransformOSG(const agx::AffineMatrix4x4 &transform)
Transform a node.
RenderProxyFactory::ShapeData< T > m_data
void setAlphaOSG(float transparency)
Set the alpha value.
void setRenderModeOSG(agxRender::RenderProxy::RenderMode mode)
Change the render mode.
osg::ref_ptr< osg::MatrixTransform > m_transformNode
agxRender::RenderProxy * m_proxy
void onRemoveOSG()
Remove the node from all its parents.
agxOSG::RenderProxyFactory * m_factory
void setColorOSG(const agx::Vec3 &color, float alpha)
Set the color and alpha value.
Implementation of osg-based PlaneProxy.
PlaneProxy(const agx::Vec3 &normal, agx::Real distance, RenderProxyFactory::ShapeData< osg::Geometry > data, RenderProxyFactory *factory)
Implementation of the abstract class from the agxRender namespace, this class is responsible for crea...
agxRender::CylinderProxy * createCylinder(float radius, float height) override
static float getDefaultDetailRatio()
agxRender::WireRenderProxy * createWire(float radius, const agx::Vec3 &color) override
agxRender::WireShapeProxy * createWireShape(float radius, float height, const agx::Vec3 &previousEndPoint0, const agx::Vec3 &previousEndPoint1) override
agxRender::CapsuleProxy * createCapsule(float radius, float height) override
void setRenderMode(agxRender::RenderProxy *proxy, osg::Node *node, agxRender::RenderProxy::RenderMode mode)
Set the RenderMode for a specified node.
void addChild(osg::Node *node, agxRender::RenderProxy::RenderMode mode)
Add a child to the root, default getDefaultRenderMode() will be used for determining if the node shou...
agxRender::TruncatedConeProxy * createTruncatedCone(float topRadius, float bottomRadius, float height) override
agxRender::LineProxy * createLine(const agx::Vec3 &p1, const agx::Vec3 &p2) override
agxRender::HeightFieldProxy * createHeightfield(agxCollide::HeightField *hf) override
Create and return a RenderProxy for a Heightfield.
agxRender::SphereProxy * createSphere(float radius) override
agxRender::RigidBodyBatchRenderProxy * createRigidBodies(const agx::RigidBodyPtrSetVector *enabledBodies) override
Interface for creating and returning batch rendering of rigid bodies (cm).
osg::ref_ptr< osg::MatrixTransform > m_parent
osg::ref_ptr< osg::Group > m_solidParent
agxRender::ContactsProxy * createContacts(const agxCollide::GeometryContactPtrVector &contacts) override
agxRender::ConeProxy * createCone(float radius, float height) override
agxRender::RenderProxy * createSphereBatchRenderer(agxData::Buffer *positions, agxData::Buffer *rotations, agxData::Buffer *radii, agxData::Buffer *colors, agxData::Buffer *enableRendering, agxData::Value *bound, agx::Component *context) override
virtual ~RenderProxyFactory()
Destructor.
void setGlobalTransform(const agx::AffineMatrix4x4 &m)
Set a transformation which will be applied to all transformations for RenderProxy's.
agxRender::TextProxy * createText(const agx::String &text, const agx::Vec3 &pos) override
agx::ref_ptr< agxOSG::GraphRenderer > m_graphRenderer
void setSphereBatchRenderModeSprites(bool flag)
agxRender::HollowCylinderProxy * createHollowCylinder(float radius, float height, float thickness) override
static void setDefaultDetailRatio(float detailRatio)
Assign new default detail ratio for the rendered geometries.
osg::ref_ptr< osg::Group > m_textParent
agxRender::Graph::GraphRenderer * getGraphRenderer() override
agxRender::PlaneProxy * createPlane(const agx::Vec3 &normal, agx::Real distance) override
osg::Group * getTextNode()
The text node is not child of the node returned in getRootNode(), hence this node MUST be added separ...
const agx::AffineMatrix4x4 & getGlobalTransform() const
void addChild(osg::Node *node, agxRender::RenderProxy *proxy)
agxRender::BoxProxy * createBox(const agx::Vec3 &halfExtents) override
osg::ref_ptr< osg::Group > m_wireframeParent
agxRender::TrimeshProxy * createTrimesh(agxCollide::Trimesh *mesh) override
Create and return a RenderProxy for a Trimesh.
agxRender::HollowTruncatedConeProxy * createHollowTruncatedCone(float topRadius, float bottomRadius, float height, float thickness) override
agx::AffineMatrix4x4 m_invTransform
Implementation of batch rendering of rigid body center of mass position.
RigidBodyBatchRenderProxy(osg::Geode *geode, const ContainerType *container, agxOSG::RenderProxyFactory *factory)
virtual void reset() override
Will reset color, alpha and enabled state back to default state (as when initially created).
Base class for batch rendering of any shape or shape composite.
ShapeBatchRenderer(osg::Geode *geode, agxOSG::RenderProxyFactory *factory, agxRender::RenderProxy *proxy)
Construct given geode.
ShapeBatchRenderer(osg::Shape *shape, agxOSG::RenderProxyFactory *factory, agxRender::RenderProxy *proxy)
Construct given single shape.
void prepare(size_t numObjects)
Prepare the root transform with the current amount of child nodes.
void setScale(float scale)
Assign transform scale.
void setTransform(TransformType *obj, const agx::AffineMatrix4x4 &transform, const agx::Vec3f &scale)
Assign transform (given agx type) to a supported osg transform.
osg::ref_ptr< osg::Geode > m_geode
void clear()
Clear the root transform node from all child transforms.
void prepareWithScale(size_t numObjects)
Including scale transform.
virtual ~ShapeBatchRenderer()
Destructor.
Implementation of osg-based SphereProxy.
SphereProxy(float radius, RenderProxyFactory::ShapeData< osg::Sphere > sphere, RenderProxyFactory *factory)
Implementation of osg-based TextProxy.
void setTransform(const agx::AffineMatrix4x4 &transform) override
Set the transform of this RenderProxy, if overridden, set the m_transform and call onUpdate(TRANSFORM...
TextProxy(const agx::String &text, const agx::Vec3 &pos, RenderProxyFactory::ShapeData< agxOSG::TextGeometry > data, RenderProxyFactory *factory)
Implementation of osg-based TrimeshProxy.
TrimeshProxy(agxCollide::Trimesh *mesh, RenderProxyFactory::ShapeData< osg::TriangleMesh > data, RenderProxyFactory *factory)
Implementation of osg-based TruncatedConeProxy.
TruncatedConeProxy(float topRadius, float bottomRadius, float height, RenderProxyFactory::ShapeData< osg::Geometry > data, RenderProxyFactory *factory)
osg::MatrixTransform * getSegmentTransform()
void setRenderModeOSG(agxRender::RenderProxy::RenderMode mode)
WireRenderProxy(float radius, const agx::Vec3 &color, osg::Geode *segmentGeode, osg::Geode *edgeGeode, osg::Geode *nodeGeode, agxOSG::RenderProxyFactory *factory)
void setColorOSG(const agx::Vec3 &color, float alpha)
ContainerShapeBatchRenderer< agxRender::WireRenderProxy::SegmentDefContainer, osg::MatrixTransform > m_segmentBatch
ContainerShapeBatchRenderer< agxRender::WireRenderProxy::SegmentDefContainer, osg::MatrixTransform > m_edgeBatch
virtual void onRemoveNotification() override
Called when the wire is removed from the simulation.
ContainerShapeBatchRenderer< agxRender::WireRenderProxy::SphereDefContainer, osg::MatrixTransform > m_sphereBatch
virtual void onAddNotification() override
Called when the wire is added to the simulation.
virtual void reset() override
Will reset color, alpha and enabled state back to default state (as when initially created).
osg::MatrixTransform * getSphereTransform()
void setEnableOSG(bool flag)
void setAlphaOSG(float transparency)
void setTransformOSG(const agx::AffineMatrix4x4 &transform)
osg::MatrixTransform * getEdgeTransform()
Implementation of osg-based WireShapeProxy.
WireShapeProxy(float radius, float height, const agx::Vec3 &previousEndPoint0, const agx::Vec3 &previousEndPoint1, RenderProxyFactory::ShapeData< osg::CompositeShape > data, RenderProxyFactory *factory)
Subclass that implements a BoxProxy.
Subclass that implements a CapsuleProxy.
Subclass that implements a ConeProxy.
Class holding contacts that makes it possible to batch render these objects.
Subclass that implements a CylinderProxy.
Abstract base class that acts as an interface and can render the data from a Graph.
Definition: Graph.h:46
Subclass that implements a HeightfieldProxy.
Subclass that implements a CylinderProxy.
Subclass that implements a HollowTruncatedConeProxy.
Subclass that implements a LineProxy.
Subclass that implements a PlaneProxy.
Abstract class which is responsible for returning a pointer to a specified RenderProxy type.
Abstract base class which encapsulated information for rendering a specific shape.
virtual void setTransform(const agx::AffineMatrix4x4 &transform)
Set the transform of this RenderProxy, if overridden, set the m_transform and call onUpdate(TRANSFORM...
Class holding rigid bodies that makes it possible to batch render these objects.
agxRender::RigidBodyBatchRenderProxy::Container m_bodies
Subclass that implements a SphereProxy.
Subclass that implements a TextProxy.
Subclass that implements a TrimeshProxy.
Subclass that implements a TruncatedConeProxy.
Subclass that implements a WireShapeProxy.
static AffineMatrix4x4T< Real > translate(const Vec3T< Real > &dv)
Return a matrix which translates according to dv.
A component is an object containing other objects, enabling hierarchical structuring.
Definition: Component.h:39
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:55
const agx::AffineMatrix4x4 & getCmTransform() const
Convenience methods for center of mass frame.
Definition: RigidBody.h:1504
#define agxAssert(expr)
Definition: debug.h:143
void AGXCORE_EXPORT transform(void *target, const Format *targetFormat, const void *source, const Format *sourceFormat, size_t numElements)
Transform data between two buffers.
The agxOSG namespace provides functionality for visualizing AGX simulations with OpenSceneGraph.
double Real
Definition: Real.h:42
Vec4T< Real > Vec4
Definition: Vec4.h:25
AffineMatrix4x4T< Real > AffineMatrix4x4
Vec3T< Real32 > Vec3f
Definition: agx/Vec3.h:39
AGXPHYSICS_EXPORT agx::Bool equivalent(const agx::AddedMassInteraction::Matrix6x6 &lhs, const agx::AddedMassInteraction::Matrix6x6 &rhs, agx::Real eps=agx::RealEpsilon)
Class for storing OSG specific data for each RenderProxy.
osg::ref_ptr< osg::StateSet > stateSet