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);
314 m_data.material =
new osg::Material;
315 m_data.stateSet->setAttributeAndModes(
m_data.material,osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE | osg::StateAttribute::PROTECTED);
326 m_data.material =
new osg::Material;
327 m_data.stateSet->setAttributeAndModes(
m_data.material, osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE | osg::StateAttribute::PROTECTED );
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 );
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 >
660 void prepare(
size_t numObjects );
691 template<
typename ContainerType,
typename TransformType >
718 void update(
bool addScaleTransform =
false );
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 >
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();
937 template<
typename ContainerType,
typename TransformType >
951 # pragma warning(pop)
void update(bool addScaleTransform=false)
Updates transforms.
osg::ref_ptr< osg::Group > m_textParent
agx::ref_ptr< agxOSG::GraphRenderer > m_graphRenderer
virtual ~TruncatedConeProxy()
Class for storing OSG specific data for each RenderProxy.
#define AGX_MAT4X4_TO_OSG(X)
AffineMatrix4x4T< Real > AffineMatrix4x4
void setRenderMode(agxRender::RenderProxy *proxy, osg::Node *node, agxRender::RenderProxy::RenderMode mode)
Set the RenderMode for a specified node.
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.
WireRenderProxy(float radius, const agx::Vec3 &color, osg::Geode *segmentGeode, osg::Geode *edgeGeode, osg::Geode *nodeGeode, agxOSG::RenderProxyFactory *factory)
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.
agx::Vec3f findScale(const typename ContainerType::value_type &val) const
Find scale (agx::Vec3) given container value type.
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
void setTransform(TransformType *obj, const agx::AffineMatrix4x4 &transform, const agx::Vec3f &scale)
Assign transform (given agx type) to a supported osg transform.
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...
void clear()
Reset container pointer and removes all child transforms.
GeometryContact * value_type
agxRender::RigidBodyBatchRenderProxy::Container m_bodies
void setContainer(const ContainerType *container)
Assign compatible container.
virtual ~WireShapeProxy()
Subclass that implements a CapsuleProxy.
osg::MatrixTransform * getSegmentTransform()
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...
void setEnableOSG(bool flag)
osg::MatrixTransform * getNode()
\ return the node for this RenderProxy
void setEnableOSG(bool flag)
Enable/disable rendering.
virtual ~HollowCylinderProxy()
RenderProxyFactory::ShapeData< T > m_data
Implementation of osg-based SphereProxy.
Subclass that implements a SphereProxy.
const ContainerType * m_container
osg::MatrixTransform * getEdgeTransform()
osg::Group * getTextNode()
The text node is not child of the node returned in getRootNode(), hence this node MUST be added separ...
void setScale(float scale)
Assign transform scale.
osg::Node * getRootNode()
Implementation of osg-based LineProxy.
void prepare(size_t numObjects)
Prepare the root transform with the current amount of child nodes.
agx::AffineMatrix4x4 m_invTransform
const agx::AffineMatrix4x4 & getGlobalTransform() const
virtual ~WireRenderProxy()
Implementation of osg-based HollowTruncatedConeProxy.
osg::Group * getSolidRootNode()
void clear()
Clear the root transform node from all child transforms.
osg::ref_ptr< osg::StateSet > stateSet
Abstract representation of a data buffer.
void setRenderModeOSG(agxRender::RenderProxy::RenderMode mode)
osg::ref_ptr< osg::Geode > m_geode
osg::ref_ptr< osg::MatrixTransform > m_parent
Implementation of osg-based BoxProxy.
Smart pointer for handling referenced counted objects.
virtual void onRemoveNotification() override
Called when the wire is removed from the simulation.
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.
const agx::AffineMatrix4x4 & getCmTransform() const
Convenience methods for center of mass frame.
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)
The rigid body class, combining a geometric model and a frame of reference.
void setAlphaOSG(float transparency)
virtual void onAddNotification() override
Called when the wire is added to the simulation.
void setTransformOSG(const agx::AffineMatrix4x4 &transform)
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
osg::MatrixTransform * getSphereTransform()
Implementation of osg-based TruncatedConeProxy.
osg::Group * getWireframeRootNode()
void onRemoveOSG()
Remove the node from all its parents.
ShapeBatchRenderer(osg::Shape *shape, agxOSG::RenderProxyFactory *factory, agxRender::RenderProxy *proxy)
Construct given single shape.
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.
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...
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.
void setColorOSG(const agx::Vec3 &color, float alpha)
osg::ref_ptr< osg::Geode > geode
agxRender::RenderProxy * m_proxy
virtual ~ShapeBatchRenderer()
Destructor.
virtual ~HeightFieldProxy()
Destructor.
Subclass that implements a CylinderProxy.
agx::AffineMatrix4x4 findTransform(const typename ContainerType::value_type &val) const
Find transform (agx::AffineMatrix4x4) given container value type.
A HeightField is a collision shape that can be created from a grid structure, like an image...
void prepareWithScale(size_t numObjects)
Including scale transform.
osg::ref_ptr< osg::Group > m_wireframeParent