17 #ifndef AGXOSG_RENDERPROXY_H 18 #define AGXOSG_RENDERPROXY_H 25 #include <osg/ref_ptr> 27 #include <osg/MatrixTransform> 28 #include <osg/Material> 29 #include <osg/AutoTransform> 31 #include <osg/ShapeDrawable> 40 # pragma warning(push) 41 # pragma warning( disable : 4355 ) // warning C4355: 'this' : used in base member initializer list 80 static void setDefaultDetailRatio(
float detailRatio );
85 static float getDefaultDetailRatio();
208 void setSphereBatchRenderModeSprites(
bool flag);
303 : m_data(data), m_factory(factory), m_proxy(proxy)
305 m_transformNode =
new osg::MatrixTransform;
307 m_transformNode->addChild( m_data.geode );
310 m_transformNode->setDataVariance( osg::Object::DYNAMIC );
312 m_data.stateSet = m_transformNode->getOrCreateStateSet();
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 );
320 : m_data(), m_factory( factory ), m_proxy( proxy )
322 m_transformNode =
new osg::MatrixTransform();
323 m_transformNode->setDataVariance( osg::Object::DYNAMIC );
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 );
343 while(m_transformNode->getNumParents())
345 m_transformNode->getParent(0)->removeChild( m_transformNode.get() );
350 m_factory->addChild( m_transformNode.get(), m_proxy );
356 m_data.material->setTransparency(osg::Material::FRONT_AND_BACK, 1-transparency);
362 osg::Vec4 col = m_data.material->getDiffuse(osg::Material::FRONT_AND_BACK);
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);
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 ) );
375 drawable->setColor( osgCol );
382 osg::ref_ptr<osg::MatrixTransform> r = m_transformNode;
383 while(m_transformNode->getNumParents())
385 m_transformNode->getParent(0)->removeChild( m_transformNode.get() );
392 m_factory->setRenderMode( m_proxy, m_transformNode, mode );
396 osg::MatrixTransform*
getNode() {
return m_transformNode.get(); }
407 #define ADD_COMMON_METHODS() \ 408 void onChange( RenderProxy::EventType type ) override { \ 410 case (RenderProxy::ENABLE): \ 411 this->setEnableOSG(this->getEnable()); \ 413 case (RenderProxy::ALPHA): \ 414 this->setAlphaOSG(this->getAlpha()); \ 416 case (RenderProxy::TRANSFORM): \ 417 this->setTransformOSG(this->getTransform()); \ 419 case (RenderProxy::COLOR): \ 420 this->setColorOSG(this->getColor(), this->getAlpha()); \ 422 case (RenderProxy::SHAPE): \ 424 case (RenderProxy::REMOVE): \ 425 this->onRemoveOSG(); \ 427 case (RenderProxy::RENDERMODE): \ 428 this->setRenderModeOSG(this->getRenderMode()); \ 432 virtual void updateShape() override 614 template<
typename TransformType >
627 void setScale(
float scale );
632 float getScale()
const;
660 void prepare(
size_t numObjects );
665 void prepareWithScale(
size_t numObjects );
691 template<
typename ContainerType,
typename TransformType >
703 :
ShapeBatchRenderer< TransformType >( geode, factory, proxy ), m_container( container ) {}
718 void update(
bool addScaleTransform =
false );
723 void setContainer(
const ContainerType* container );
737 agx::Vec3f findScale(
const typename ContainerType::value_type& val )
const;
744 class SphereSpriteBatchRenderer :
public ContainerShapeBatchRenderer< agxData::Array< agx::Vec3 >, osg::MatrixTransform >,
public agxRender::SphereSpriteBatchRenderProxy
749 agxRender::SphereSpriteBatchRenderProxy( container ) {}
752 virtual ~SphereSpriteBatchRenderer() {}
756 this->m_container = m_buffer;
760 virtual void reset()
override 770 template<
typename ContainerType,
typename TransformType >
783 this->m_container = &m_bodies;
822 osg::MatrixTransform* getSegmentTransform();
823 osg::MatrixTransform* getEdgeTransform();
824 osg::MatrixTransform* getSphereTransform();
829 virtual void onAddNotification()
override;
830 virtual void onRemoveNotification()
override;
833 void setEnableOSG(
bool flag );
834 void setAlphaOSG(
float transparency );
835 void setColorOSG(
const agx::Vec3& color,
float alpha);
853 osg::MatrixTransform*
getNode() {
return nullptr; }
856 template<
typename TransformType >
859 if ( m_transformNode )
860 m_transformNode->removeChild( 0, m_transformNode->getNumChildren() );
863 template<
typename TransformType >
869 template<
typename TransformType >
875 template<
typename ContainerType,
typename TransformType >
879 m_container =
nullptr;
882 template<
typename ContainerType,
typename TransformType >
885 if ( this->m_container ==
nullptr )
888 if ( addScaleTransform )
889 this->prepareWithScale( this->m_container->size() );
891 this->prepare( this->m_container->size() );
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 ) );
901 template<
typename ContainerType,
typename TransformType >
904 m_container = container;
907 template<
typename ContainerType,
typename TransformType >
910 return val->getTransform();
922 return rbRefPtr->getCmTransform();
928 return rbPtr->getCmTransform();
937 template<
typename ContainerType,
typename TransformType >
951 # pragma warning(pop) osg::ref_ptr< osg::Group > m_textParent
agx::ref_ptr< agxOSG::GraphRenderer > m_graphRenderer
virtual ~TruncatedConeProxy()
AGXTERRAIN_EXPORT void clear()
Class for storing OSG specific data for each RenderProxy.
#define AGX_MAT4X4_TO_OSG(X)
AffineMatrix4x4T< Real > AffineMatrix4x4
virtual void setTransform(const agx::AffineMatrix4x4 &transform)
Set the transform of this RenderProxy, if overridden, set the m_transform and call onUpdate(TRANSFORM...
static AffineMatrix4x4T< Real > translate(const Vec3T< Real > &dv)
Return a matrix which translates according to dv.
Base class for batch rendering of any shape or shape composite.
virtual void reset() override
Will reset color, alpha and enabled state back to default state (as when initially created)...
Class that handles batch rendering of objects in forward iterator compliant container.
Implementation of osg-based TrimeshProxy.
Subclass that implements a BoxProxy.
A component is an object containing other objects, enabling hierarchical structuring.
Abstract representation of a value.
virtual ~ContainerShapeBatchRenderer()
Destructor.
void setTransformOSG(const agx::AffineMatrix4x4 &transform)
Transform a node.
Subclass that implements a TruncatedConeProxy.
ShapeData(const ShapeData &other)
void AGXCORE_EXPORT transform(void *target, const Format *targetFormat, const void *source, const Format *sourceFormat, size_t numElements)
Transform data between two buffers.
void setColorOSG(const agx::Vec3 &color, float alpha)
Set the color and alpha value.
Subclass that implements a CylinderProxy.
void setRenderModeOSG(agxRender::RenderProxy::RenderMode mode)
Change the render mode.
osg::ref_ptr< osg::MatrixTransform > m_transformNode
ContainerShapeBatchRenderer< agxRender::WireRenderProxy::SegmentDefContainer, osg::MatrixTransform > m_edgeBatch
#define AGX_DECLARE_POINTER_TYPES(type)
Subclass that implements a TrimeshProxy.
Implementation of the abstract class from the agxRender namespace, this class is responsible for crea...
virtual ~WireShapeProxy()
Subclass that implements a CapsuleProxy.
virtual ~RigidBodyBatchRenderProxy()
Implementation of osg-based HollowCylinderProxy.
AGXOSG_EXPORT agxCollide::Trimesh * createTrimesh(osg::Node *node)
Extracts mesh data from an osg::Node, creates an agxCollide::Trimesh from it and returns the result...
Type-specific Array used for fast access into the data held by a Buffer.
Abstract class which is responsible for returning a pointer to a specified RenderProxy type...
osg::MatrixTransform * getNode()
\ return the node for this RenderProxy
void setEnableOSG(bool flag)
Enable/disable rendering.
virtual ~HollowCylinderProxy()
const agx::AffineMatrix4x4 & getGlobalTransform() const
RenderProxyFactory::ShapeData< T > m_data
Implementation of osg-based SphereProxy.
Subclass that implements a SphereProxy.
const ContainerType * m_container
osg::Group * getTextNode()
The text node is not child of the node returned in getRootNode(), hence this node MUST be added separ...
Vector containing 'raw' data.
osg::Node * getRootNode()
Implementation of osg-based LineProxy.
const Node * getNode(const IteratorCompatibleContainer &container, agx::Real distanceFromStart)
Finds the wire node given current distance from the start of the wire (wire defined to be iterator co...
agx::AffineMatrix4x4 m_invTransform
Implementation of osg-based HollowTruncatedConeProxy.
osg::Group * getSolidRootNode()
The agxOSG namespace provides functionality for visualizing AGX simulations with OpenSceneGraph.
osg::ref_ptr< osg::StateSet > stateSet
Abstract representation of a data buffer.
osg::ref_ptr< osg::Geode > m_geode
osg::ref_ptr< osg::MatrixTransform > m_parent
Implementation of osg-based BoxProxy.
RigidBodyBatchRenderProxy(osg::Geode *geode, const ContainerType *container, agxOSG::RenderProxyFactory *factory)
Subclass that implements a PlaneProxy.
bool m_sphereBatchRenderModeSprites
Implementation of osg-based TextProxy.
osg::ref_ptr< osg::Group > m_solidParent
Implementation of osg-based HeightfieldProxy.
ContainerShapeBatchRenderer(osg::Geode *geode, const ContainerType *container, agxOSG::RenderProxyFactory *factory, agxRender::RenderProxy *proxy)
Construct given shape composite and compatible container.
Implementation of osg-based PlaneProxy.
ContainerShapeBatchRenderer< agxRender::WireRenderProxy::SegmentDefContainer, osg::MatrixTransform > m_segmentBatch
Abstract base class which encapsulated information for rendering a specific shape.
AGXPHYSICS_EXPORT agx::Bool equivalent(const agx::AddedMassInteraction::Matrix6x6 &lhs, const agx::AddedMassInteraction::Matrix6x6 &rhs, agx::Real eps=agx::RealEpsilon)
Subclass that implements a HollowTruncatedConeProxy.
Implementation of osg-based CylinderProxy.
Class for handling methods related to OSG such as setColor, setTransform etc.
Implementation of osg-based ConeProxy.
agx::AffineMatrix4x4 m_invTransform
Subclass that implements a TextProxy.
Abstract base class that acts as an interface and can render the data from a Graph.
ContainerShapeBatchRenderer< agxRender::WireRenderProxy::SphereDefContainer, osg::MatrixTransform > m_sphereBatch
AGXOSG_EXPORT osg::Geode * createLine(const agx::Vec3 &p1, const agx::Vec3 &p2, const agx::Vec4 &color, float width)
Create and return a new Line to render.
Implementation of osg-based TruncatedConeProxy.
osg::Group * getWireframeRootNode()
void onRemoveOSG()
Remove the node from all its parents.
Implementation of osg-based CapsuleProxy.
OSGData(agxOSG::RenderProxyFactory *factory, agxRender::RenderProxy *proxy)
virtual void reset() override
Will reset color, alpha and enabled state back to default state (as when initially created)...
#define ADD_COMMON_METHODS()
Macro for adding some methods for each specialization of RenderProxy.
AGXOSG_EXPORT osg::Geode * createText(const std::string &text, const agx::Vec3 &relPosition=agx::Vec3(0, 0, 0), const agx::Vec4f &color=agxRender::Color::Yellow(), agx::Real size=0.2)
Create a text object.
Implementation of osg-based WireShapeProxy.
virtual ~HollowTruncatedConeProxy()
agxOSG::RenderProxyFactory * m_factory
void setAlphaOSG(float transparency)
Set the alpha value.
OSGData(const RenderProxyFactory::ShapeData< T > &data, agxOSG::RenderProxyFactory *factory, agxRender::RenderProxy *proxy)
Subclass that implements a ConeProxy.
Implementation of batch rendering of rigid body center of mass position.
Subclass that implements a WireShapeProxy.
Class holding rigid bodies that makes it possible to batch render these objects.
Subclass that implements a HeightfieldProxy.
Triangle mesh for geometric intersection tests.
Subclass that implements a LineProxy.
osg::ref_ptr< osg::Geode > geode
agxRender::RenderProxy * m_proxy
virtual ~ShapeBatchRenderer()
Destructor.
virtual ~HeightFieldProxy()
Destructor.
Subclass that implements a CylinderProxy.
A HeightField is a collision shape that can be created from a grid structure, like an image...
This class is a combined container which has the find complexity of a HashTable, deterministic iterat...
osg::ref_ptr< osg::Group > m_wireframeParent