AGX Dynamics 2.42.1.1
Loading...
Searching...
No Matches
DeformableRenderer.h
Go to the documentation of this file.
1/*
2Copyright 2007-2025. Algoryx Simulation AB.
3
4All AGX source code, intellectual property, documentation, sample code,
5tutorials, scene files and technical white papers, are copyrighted, proprietary
6and confidential material of Algoryx Simulation AB. You may not download, read,
7store, distribute, publish, copy or otherwise disseminate, use or expose this
8material unless having a written signed agreement with Algoryx Simulation AB, or having been
9advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10valid commercial license from Algoryx Simulation AB.
11
12Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13from using this software, unless otherwise stated in written agreements with
14Algoryx Simulation AB.
15*/
16
17#pragma once
18
20
22
23#include <agxRender/Color.h>
24
25#include <osg/MatrixTransform>
26#include <osg/Geometry>
27
28namespace agxOSG
29{
39 {
40 public:
41 using OsgGeometryRef = osg::ref_ptr<osg::Geometry>;
42
43 using RenderVertexIndexVector = std::vector<size_t>;
44 using TrimeshVertexToRenderVertices = std::vector<RenderVertexIndexVector>;
45
46 public:
53 static DeformableRenderer* find( const agxModel::DeformableObject* deformable, osg::Group* root );
54
55 public:
63
70
75
83 void setCreaseAngle( agx::Real creaseAngleRad );
84
89
95 void setBaseColor( const agxRender::Color& baseColor );
96
101
113 void setAlpha( float alpha );
114
118 float getAlpha() const;
119
125 void setEnableColorStresses( bool enable );
126
131
136 void setMaxStressColor( const agxRender::Color& maxStressColor );
137
142
147 void setMaxStressLimit( agx::Real maxStressLimit );
148
153
155
156
159 osg::Geometry* getSurfaceGeometry() const;
160
161 protected:
162 struct InternalState
163 {
164 enum Flag : agx::UInt16
165 {
166 COLOR_STRESSES = 1 << 0,
167 };
168 using Flags = agx::BitState<Flag, std::underlying_type_t<Flag>>;
169
170 Flags flags{};
172 agxRender::Color maxStressColor = agxRender::Color::Red();
173 agx::Real maxStressLimit = 60000.0;
174 agx::Real creaseAngle = 0.8 * agx::PI_2;
175 };
176
177 protected:
178 virtual ~DeformableRenderer();
179
186 virtual bool initialize() override;
187
194 virtual void update() override;
195
200 virtual void updateVertices();
201
205 virtual void updateNormals();
206
210 virtual void updateColors();
211
216 virtual void handleSurfaceGeometryAlphaTriangleSort();
217
218 protected:
224 osg::Vec3Array* getVertexArray() const;
225
227
228 protected:
229 agxModel::DeformableObjectConstObserver m_deformable;
230 OsgGeometryRef m_osgSurfaceGeometry;
231 TrimeshVertexToRenderVertices m_trimeshToRenderVertices;
232 InternalState m_state;
233 };
234
236}
#define AGXOSG_EXPORT
Deformable tetrahedron mesh representation, containing a data registry with the vertex position and c...
Deformable object containing a tetrahedron mesh and a set of algorithms.
Renders the surface mesh of a deformable object.
bool getEnableColorStresses() const
osg::ref_ptr< osg::Geometry > OsgGeometryRef
void setCreaseAngle(agx::Real creaseAngleRad)
Assign the crease angle of the mesh, i.e., the maximum angle (in radians) between surface normals whe...
std::vector< size_t > RenderVertexIndexVector
void setBaseColor(const agxRender::Color &baseColor)
Set the base color of the surface mesh, i.e., diffuse color.
std::vector< RenderVertexIndexVector > TrimeshVertexToRenderVertices
static DeformableRenderer * find(const agxModel::DeformableObject *deformable, osg::Group *root)
Searches for renderer of deformable in root.
agx::Real getMaxStressLimit() const
void setEnableColorStresses(bool enable)
Enable/disable coloring of stresses on the surface by lerp of the base color to the max stress color ...
const agxModel::DTetrahedronMesh & getMesh() const
DeformableRenderer(const agxModel::DeformableObject *deformable, agxRender::Color color=agxRender::Color::DarkOliveGreen())
Construct given a deformable object and color.
void setAlpha(float alpha)
Set opaqueness [0, 1] (default: 1.0).
void setMaxStressLimit(agx::Real maxStressLimit)
Limit when max stress color is used, default: 60'000.
agxRender::Color getMaxStressColor() const
const agxModel::DeformableObject * getDeformable() const
agxRender::Color getBaseColor() const
agx::Real getCreaseAngle() const
void setMaxStressColor(const agxRender::Color &maxStressColor)
Set surface color when the stresses reaches max stress limit.
A group/transform that supports agxOSG::ShaderGeometry instances.
Utility color class with "common colors".
Definition: Color.h:48
static agxRender::Color Red()
Definition: Color.h:217
static agxRender::Color DarkOliveGreen()
Definition: Color.h:286
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: macros.h:89
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: macros.h:88
Contain classes for higher level modeling primitives, such as Tree, Terrain etc.
Definition: Space.h:63
The agxOSG namespace provides functionality for visualizing AGX simulations with OpenSceneGraph.
osg::ref_ptr< DeformableRenderer > DeformableRendererRef
uint16_t UInt16
Definition: Integer.h:31
static constexpr Real PI_2
Definition: Math.h:64
double Real
Definition: Real.h:41