27#include <osg/MatrixTransform>
28#include <osg/Material>
29#include <osg/AutoTransform>
31#include <osg/ShapeDrawable>
32#include <osgText/Text>
43# pragma warning( disable : 4355 )
77 m_data.material =
new osg::Material;
78 m_data.stateSet->setAttributeAndModes(
m_data.material,osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE | osg::StateAttribute::PROTECTED);
89 m_data.material =
new osg::Material;
90 m_data.stateSet->setAttributeAndModes(
m_data.material, osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE | osg::StateAttribute::PROTECTED );
119 m_data.material->setTransparency(osg::Material::FRONT_AND_BACK, 1-transparency);
125 auto textShape =
dynamic_cast<osgText::Text*
>(
m_data.shape.get());
128 textShape->setColor(osg::Vec4((
float)color[0], (
float)color[1], (
float)color[2], alpha));
132 osg::Vec4 col =
m_data.material->getDiffuse(osg::Material::FRONT_AND_BACK);
139 osg::Vec4 osgCol( (
float)color[0], (
float)color[1], (
float)color[2], alpha );
140 m_data.material->setDiffuse(osg::Material::FRONT_AND_BACK, osgCol);
142 for (
unsigned int i = 0;
m_data.geode !=
nullptr && i <
m_data.geode->getNumDrawables(); ++i ) {
143 osg::ShapeDrawable* drawable =
dynamic_cast< osg::ShapeDrawable*
>(
m_data.geode->getDrawable( i ) );
145 drawable->setColor( osgCol );
179#define ADD_COMMON_PROXY_METHODS() \
180 void onChange( RenderProxy::EventType type ) override { \
182 case (RenderProxy::ENABLE): \
183 this->setEnableOSG(this->getEnable()); \
185 case (RenderProxy::ALPHA): \
186 this->setAlphaOSG(this->getAlpha()); \
188 case (RenderProxy::TRANSFORM): \
189 this->setTransformOSG(this->getTransform()); \
191 case (RenderProxy::COLOR): \
192 this->setColorOSG(this->getColor(), this->getAlpha()); \
194 case (RenderProxy::SHAPE): \
196 case (RenderProxy::REMOVE): \
197 this->onRemoveOSG(); \
199 case (RenderProxy::RENDERMODE): \
200 this->setRenderModeOSG(this->getRenderMode()); \
204 virtual bool updateShape() override
270 float radius,
float height,
285 float outerRadius,
float height,
334 float topRadius,
float bottomRadius,
335 float height,
float thickness,
429 template<
typename TransformType >
506 template<
typename ContainerType,
typename TransformType >
533 void update(
bool addScaleTransform =
false );
559 class SphereSpriteBatchRenderer :
public ContainerShapeBatchRenderer< agxData::Array< agx::Vec3 >, osg::MatrixTransform >,
public agxRender::SphereSpriteBatchRenderProxy
564 agxRender::SphereSpriteBatchRenderProxy( container ) {}
567 virtual ~SphereSpriteBatchRenderer() {}
571 this->m_container = m_buffer;
575 virtual void reset()
override
585 template<
typename ContainerType,
typename TransformType >
669 osg::MatrixTransform* getNode() {
return nullptr; }
672 template<
typename TransformType >
675 if ( m_transformNode )
676 m_transformNode->removeChild( 0, m_transformNode->getNumChildren() );
679 template<
typename TransformType >
685 template<
typename TransformType >
691 template<
typename ContainerType,
typename TransformType >
695 m_container =
nullptr;
698 template<
typename ContainerType,
typename TransformType >
701 if ( this->m_container ==
nullptr )
704 if ( addScaleTransform )
705 this->prepareWithScale( this->m_container->size() );
707 this->prepare( this->m_container->size() );
709 unsigned int counter = 0;
710 for (
typename ContainerType::const_iterator i = m_container->begin(); i != m_container->end(); ++counter, ++i ) {
711 agxAssert( counter < this->m_transformNode->getNumChildren() );
712 TransformType* transform =
static_cast< TransformType*
>( this->m_transformNode->getChild( counter ) );
713 this->setTransform( transform, this->findTransform( *i ), this->findScale( *i ) );
717 template<
typename ContainerType,
typename TransformType >
720 m_container = container;
723 template<
typename ContainerType,
typename TransformType >
726 return val->getTransform();
753 template<
typename ContainerType,
typename TransformType >
#define ADD_COMMON_PROXY_METHODS()
Macro for adding some methods for each specialization of RenderProxy.
#define AGX_MAT4X4_TO_OSG(X)
A HeightField is a collision shape that can be created from a grid structure, like an image.
Triangle mesh for geometric intersection tests.
Type-specific Array used for fast access into the data held by a Buffer.
Implementation of osg-based BoxProxy.
BoxProxy(const agx::Vec3 &halfExtents, RenderProxyFactory::ShapeData< osg::Box > box, RenderProxyFactory *factory)
ADD_COMMON_PROXY_METHODS()
Implementation of osg-based CapsuleProxy.
CapsuleProxy(float radius, float height, RenderProxyFactory::ShapeData< osg::Capsule > data, RenderProxyFactory *factory)
ADD_COMMON_PROXY_METHODS()
Implementation of osg-based ConeProxy.
ADD_COMMON_PROXY_METHODS()
ConeProxy(float radius, float height, RenderProxyFactory::ShapeData< osg::Cone > data, 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.
const ContainerType * m_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.
ADD_COMMON_PROXY_METHODS()
CylinderProxy(float radius, float height, RenderProxyFactory::ShapeData< osg::Cylinder > data, RenderProxyFactory *factory)
Implementation of osg-based HeightfieldProxy.
virtual ~HeightFieldProxy()
Destructor.
HeightFieldProxy(agxCollide::HeightField *shape, RenderProxyFactory::ShapeData< osg::Geometry > hfData, RenderProxyFactory *factory)
ADD_COMMON_PROXY_METHODS()
void set(const agx::Vec2iVector &modifiedIndices, const agx::RealVector &heights) override
Override this method to support changing a selection of indices in the heightfield.
Implementation of osg-based HollowConeProxy.
virtual ~HollowConeProxy()
ADD_COMMON_PROXY_METHODS()
HollowConeProxy(float topRadius, float bottomRadius, float height, float thickness, RenderProxyFactory::ShapeData< osg::Geometry > data, RenderProxyFactory *factory)
Implementation of osg-based HollowCylinderProxy.
ADD_COMMON_PROXY_METHODS()
virtual ~HollowCylinderProxy()
HollowCylinderProxy(float outerRadius, float height, float thickness, RenderProxyFactory::ShapeData< osg::Geometry > data, RenderProxyFactory *factory)
Implementation of osg-based LineProxy.
ADD_COMMON_PROXY_METHODS()
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
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.
osg::MatrixTransform * getNode()
\ return the node for this RenderProxy
OSGData(const RenderProxyFactory::ShapeData< T > &data, RenderProxyFactory *factory, agxRender::RenderProxy *proxy)
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)
ADD_COMMON_PROXY_METHODS()
Implementation of the abstract class from the agxRender namespace, this class is responsible for crea...
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...
const agx::AffineMatrix4x4 & getGlobalTransform() const
Implementation of batch rendering of rigid body center of mass position.
RigidBodyBatchRenderProxy(osg::Geode *geode, const ContainerType *container, agxOSG::RenderProxyFactory *factory)
virtual ~RigidBodyBatchRenderProxy()
virtual void reset() override
Will reset color, alpha and enabled state back to default state (as when initially created).
ADD_COMMON_PROXY_METHODS()
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)
ADD_COMMON_PROXY_METHODS()
Implementation of osg-based TextProxy.
TextProxy(const agx::String &text, const agx::Vec3 &pos, RenderProxyFactory::ShapeData< osgText::Text > data, RenderProxyFactory *factory)
ADD_COMMON_PROXY_METHODS()
Implementation of osg-based TrimeshProxy.
ADD_COMMON_PROXY_METHODS()
TrimeshProxy(agxCollide::Trimesh *mesh, RenderProxyFactory::ShapeData< osg::TriangleMesh > data, RenderProxyFactory *factory)
Implementation of osg-based TruncatedConeProxy.
virtual ~TruncatedConeProxy()
ADD_COMMON_PROXY_METHODS()
TruncatedConeProxy(float topRadius, float bottomRadius, float height, RenderProxyFactory::ShapeData< osg::Geometry > data, RenderProxyFactory *factory)
osg::MatrixTransform * getSphereTransform()
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)
osg::MatrixTransform * getSegmentTransform()
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 ~WireRenderProxy()
virtual void reset() override
Will reset color, alpha and enabled state back to default state (as when initially created).
osg::MatrixTransform * getEdgeTransform()
void setEnableOSG(bool flag)
ADD_COMMON_PROXY_METHODS()
void setAlphaOSG(float transparency)
void setTransformOSG(const agx::AffineMatrix4x4 &transform)
Implementation of osg-based WireShapeProxy.
ADD_COMMON_PROXY_METHODS()
virtual ~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.
Subclass that implements a CylinderProxy.
Subclass that implements a HeightfieldProxy.
Subclass that implements a HollowConeProxy.
Subclass that implements a CylinderProxy.
Subclass that implements a LineProxy.
Subclass that implements a PlaneProxy.
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.
The rigid body class, combining a geometric model and a frame of reference.
const agx::AffineMatrix4x4 & getCmTransform() const
Convenience methods for center of mass frame.
Vector containing 'raw' data.
GeometryContact * value_type
The agxOSG namespace provides functionality for visualizing AGX simulations with OpenSceneGraph.
AffineMatrix4x4T< Real > AffineMatrix4x4
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.