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 )
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 >
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)
#define AGX_DECLARE_POINTER_TYPES(type)
#define ADD_COMMON_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.
Abstract representation of a data buffer.
Abstract representation of a value.
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)
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.
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.
virtual ~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)
virtual ~HollowTruncatedConeProxy()
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
bool m_sphereBatchRenderModeSprites
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
osg::Group * getSolidRootNode()
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
osg::Group * getWireframeRootNode()
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
osg::Node * getRootNode()
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 ~RigidBodyBatchRenderProxy()
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.
virtual ~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 ~WireRenderProxy()
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.
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.
Abstract base class that acts as an interface and can render the data from a Graph.
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.
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.
GeometryContact * value_type
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.
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.
osg::ref_ptr< osg::Geode > geode
ShapeData(const ShapeData &other)
osg::ref_ptr< osg::StateSet > stateSet