 |
AGXDynamics
2.35.0.3
|
Go to the documentation of this file.
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)
#define ADD_COMMON_METHODS()
Macro for adding some methods for each specialization of RenderProxy.
osg::MatrixTransform * getSegmentTransform()
osg::ref_ptr< osg::StateSet > stateSet
Abstract representation of a value.
Implementation of osg-based ConeProxy.
void setRenderModeOSG(agxRender::RenderProxy::RenderMode mode)
osg::ref_ptr< osg::Geode > geode
Implementation of osg-based HollowTruncatedConeProxy.
AGXPHYSICS_EXPORT agx::Bool equivalent(const agx::AddedMassInteraction::Matrix6x6 &lhs, const agx::AddedMassInteraction::Matrix6x6 &rhs, agx::Real eps=agx::RealEpsilon)
void AGXCORE_EXPORT transform(void *target, const Format *targetFormat, const void *source, const Format *sourceFormat, size_t numElements)
Transform data between two buffers.
osg::MatrixTransform * getSphereTransform()
Implementation of osg-based PlaneProxy.
agx::Vec3f findScale(const typename ContainerType::value_type &val) const
Find scale (agx::Vec3) given container value type.
void prepare(size_t numObjects)
Prepare the root transform with the current amount of child nodes.
Subclass that implements a ConeProxy.
The rigid body class, combining a geometric model and a frame of reference.
osg::Node * getRootNode()
ContainerShapeBatchRenderer< agxRender::WireRenderProxy::SegmentDefContainer, osg::MatrixTransform > m_segmentBatch
static AffineMatrix4x4T< Real > translate(const Vec3T< Real > &dv)
Return a matrix which translates according to dv.
ShapeBatchRenderer(osg::Shape *shape, agxOSG::RenderProxyFactory *factory, agxRender::RenderProxy *proxy)
Construct given single shape.
void clear()
Clear the root transform node from all child transforms.
void setAlphaOSG(float transparency)
osg::ref_ptr< osg::Group > m_textParent
osg::Group * getTextNode()
The text node is not child of the node returned in getRootNode(), hence this node MUST be added separ...
Implementation of osg-based HeightfieldProxy.
osg::Group * getWireframeRootNode()
virtual void onAddNotification() override
Called when the wire is added to the simulation.
void setContainer(const ContainerType *container)
Assign compatible container.
Subclass that implements a HeightfieldProxy.
virtual ~WireRenderProxy()
void setTransformOSG(const agx::AffineMatrix4x4 &transform)
osg::ref_ptr< osg::Geode > m_geode
void setColorOSG(const agx::Vec3 &color, float alpha)
const agx::AffineMatrix4x4 & getCmTransform() const
Convenience methods for center of mass frame.
osg::ref_ptr< osg::MatrixTransform > m_transformNode
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.
void setTransformOSG(const agx::AffineMatrix4x4 &transform)
Transform a node.
Subclass that implements a CapsuleProxy.
A HeightField is a collision shape that can be created from a grid structure, like an image.
Class that handles batch rendering of objects in forward iterator compliant container.
void setEnableOSG(bool flag)
osg::ref_ptr< osg::MatrixTransform > m_parent
void setColorOSG(const agx::Vec3 &color, float alpha)
Set the color and alpha value.
Subclass that implements a TruncatedConeProxy.
virtual void onRemoveNotification() override
Called when the wire is removed from the simulation.
virtual ~RigidBodyBatchRenderProxy()
Subclass that implements a BoxProxy.
virtual void setTransform(const agx::AffineMatrix4x4 &transform)
Set the transform of this RenderProxy, if overridden, set the m_transform and call onUpdate(TRANSFORM...
void setRenderModeOSG(agxRender::RenderProxy::RenderMode mode)
Change the render mode.
agx::AffineMatrix4x4 findTransform(const typename ContainerType::value_type &val) const
Find transform (agx::AffineMatrix4x4) given container value type.
Base class for batch rendering of any shape or shape composite.
agx::AffineMatrix4x4 m_invTransform
Implementation of osg-based TrimeshProxy.
void setRenderMode(agxRender::RenderProxy *proxy, osg::Node *node, agxRender::RenderProxy::RenderMode mode)
Set the RenderMode for a specified node.
RenderProxyFactory::ShapeData< T > m_data
Implementation of osg-based SphereProxy.
Type-specific Array used for fast access into the data held by a Buffer.
agx::ref_ptr< agxOSG::GraphRenderer > m_graphRenderer
Subclass that implements a TextProxy.
Class for handling methods related to OSG such as setColor, setTransform etc.
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...
Class holding rigid bodies that makes it possible to batch render these objects.
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.
void prepareWithScale(size_t numObjects)
Including scale transform.
osg::MatrixTransform * getNode()
\ return the node for this RenderProxy
virtual void reset() override
Will reset color, alpha and enabled state back to default state (as when initially created).
void setEnableOSG(bool flag)
Enable/disable rendering.
virtual ~HollowCylinderProxy()
Abstract base class that acts as an interface and can render the data from a Graph.
Class for storing OSG specific data for each RenderProxy.
Implementation of osg-based BoxProxy.
Subclass that implements a CylinderProxy.
The agxOSG namespace provides functionality for visualizing AGX simulations with OpenSceneGraph.
AffineMatrix4x4T< Real > AffineMatrix4x4
virtual ~WireShapeProxy()
void update(bool addScaleTransform=false)
Updates transforms.
Implementation of osg-based HollowCylinderProxy.
Subclass that implements a PlaneProxy.
Implementation of osg-based TextProxy.
virtual ~HollowTruncatedConeProxy()
virtual ~ShapeBatchRenderer()
Destructor.
agx::AffineMatrix4x4 m_invTransform
Abstract base class which encapsulated information for rendering a specific shape.
RigidBodyBatchRenderProxy(osg::Geode *geode, const ContainerType *container, agxOSG::RenderProxyFactory *factory)
Abstract representation of a data buffer.
Implementation of batch rendering of rigid body center of mass position.
virtual ~TruncatedConeProxy()
const agx::AffineMatrix4x4 & getGlobalTransform() const
Subclass that implements a HollowTruncatedConeProxy.
#define AGX_MAT4X4_TO_OSG(X)
Implementation of osg-based CylinderProxy.
virtual ~HeightFieldProxy()
Destructor.
Implementation of osg-based LineProxy.
Implementation of osg-based TruncatedConeProxy.
A component is an object containing other objects, enabling hierarchical structuring.
void setTransform(TransformType *obj, const agx::AffineMatrix4x4 &transform, const agx::Vec3f &scale)
Assign transform (given agx type) to a supported osg transform.
virtual ~ContainerShapeBatchRenderer()
Destructor.
Subclass that implements a SphereProxy.
osg::ref_ptr< osg::Group > m_wireframeParent
Subclass that implements a CylinderProxy.
ShapeData(const ShapeData &other)
#define AGX_DECLARE_POINTER_TYPES(type)
osg::Group * getSolidRootNode()
agxRender::RigidBodyBatchRenderProxy::Container m_bodies
const ContainerType * m_container
void clear()
Reset container pointer and removes all child transforms.
void setAlphaOSG(float transparency)
Set the alpha value.
agxOSG::RenderProxyFactory * m_factory
Subclass that implements a WireShapeProxy.
Implementation of osg-based WireShapeProxy.
Triangle mesh for geometric intersection tests.
void onRemoveOSG()
Remove the node from all its parents.
agxRender::RenderProxy * m_proxy
OSGData(agxOSG::RenderProxyFactory *factory, agxRender::RenderProxy *proxy)
Subclass that implements a LineProxy.
Abstract class which is responsible for returning a pointer to a specified RenderProxy type.
Implementation of the abstract class from the agxRender namespace, this class is responsible for crea...
ContainerShapeBatchRenderer< agxRender::WireRenderProxy::SphereDefContainer, osg::MatrixTransform > m_sphereBatch
virtual void reset() override
Will reset color, alpha and enabled state back to default state (as when initially created).
Implementation of osg-based CapsuleProxy.
OSGData(const RenderProxyFactory::ShapeData< T > &data, agxOSG::RenderProxyFactory *factory, agxRender::RenderProxy *proxy)
void setScale(float scale)
Assign transform scale.
bool m_sphereBatchRenderModeSprites
GeometryContact * value_type
osg::MatrixTransform * getEdgeTransform()
ContainerShapeBatchRenderer< agxRender::WireRenderProxy::SegmentDefContainer, osg::MatrixTransform > m_edgeBatch
ContainerShapeBatchRenderer(osg::Geode *geode, const ContainerType *container, agxOSG::RenderProxyFactory *factory, agxRender::RenderProxy *proxy)
Construct given shape composite and compatible container.
Subclass that implements a TrimeshProxy.
osg::ref_ptr< osg::Group > m_solidParent
WireRenderProxy(float radius, const agx::Vec3 &color, osg::Geode *segmentGeode, osg::Geode *edgeGeode, osg::Geode *nodeGeode, agxOSG::RenderProxyFactory *factory)