AGX Dynamics 2.42.1.1
Loading...
Searching...
No Matches
TerrainVoxelDrawable.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
19#include <agxOSG/export.h>
20
21#include <agxTerrain/Terrain.h>
22
23#include <agx/Task.h>
24
25#include <agx/PushDisableWarnings.h> // Disabling warnings. Include agx/PopDisableWarnings.h below!
26#include <osg/Drawable>
27#include <osg/Version>
28#include <agx/PopDisableWarnings.h> // End of disabled warnings.
29
30namespace osgSim
31{
32 class ColorRange;
33}
34
35
36namespace agxOSG
37{
42 class AGXOSG_EXPORT TerrainVoxelDrawable : public osg::Drawable
43 {
44 public:
45 TerrainVoxelDrawable(agxTerrain::Terrain* terrain);
46
47 void setRenderVoxelSolidMass( bool enable );
48 bool getRenderVoxelSolidMass() const;
49
50 void setRenderVoxelFluidMass( bool enable );
51 bool getRenderVoxelFluidMass() const;
52
53 void setRenderVoxelBoundingBox( bool enable );
54 bool getRenderVoxelBoundingBox() const;
55
56 void setRenderVoxelCompaction( bool enable );
57 bool getRenderVoxelCompaction() const;
58
59 void setRenderVelocityField( bool enable );
60 bool getRenderVelocityField() const;
61
62 void setRenderTerrainMaterials(bool enable);
63 bool getRenderTerrainMaterials() const;
64
65 void setRenderDefaultTerrainMaterial(bool enable);
66 bool getRenderDefaultTerrainMaterial() const;
67
68 void setTerrainMaterialsColor( const agxRender::ColorVector& colors );
69 agxRender::ColorVector getTerrainMaterialColors() const;
70
71 void setVelocityFieldLineColor(const agx::Vec4& lineColor);
72
73 void setMaxVoxelValueColor(const agx::Vec4f& maxVoxelColor);
74
78 bool hasEnabledFeatures() const;
79
83 bool isInitialized() const;
84
85 virtual osg::Object* cloneType() const { return new TerrainVoxelDrawable(m_terrain); }
86 virtual osg::Object* clone(const osg::CopyOp&) const { return new TerrainVoxelDrawable(*this); }
87 virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const TerrainVoxelDrawable *>(obj) != nullptr; }
88 virtual const char* libraryName() const { return "agxOSG"; }
89 virtual const char* className() const { return "TerrainVoxelDrawable"; }
90
92#if OSG_VERSION_GREATER_OR_EQUAL(3,4,0)
93 virtual osg::BoundingSphere computeBound() const;
94 virtual osg::BoundingBox computeBoundingBox() const;
95#else
96 virtual osg::BoundingBox computeBound() const;
97#endif
98
100 virtual void drawImplementation(osg::RenderInfo& renderInfo) const;
101
102 void updateDrawable();
103
104 public:
105 void onAddNotification( agxSDK::Simulation* simulation );
106 void onRemoveNotification( agxSDK::Simulation* simulation );
107
108 protected:
109 virtual ~TerrainVoxelDrawable();
110
111
112 void renderVelocityTableLines(
113 const agxTerrain::BasicGrid* solid,
114 const agx::AffineMatrix4x4& terrainTransform,
115 const agx::HashTable< agx::Vec3i, agx::Vec3f >& velocityTable,
116 agx::Real elementSize,
117 bool enableVelocityFieldRendering,
118 agxData::Buffer* linePositions,
119 agxData::Buffer* lineOffsets);
120
121 void renderVoxels(
122 const agxTerrain::BasicGrid* solid,
123 const agxTerrain::BasicGrid* fluid,
124 const agxTerrain::BasicGrid* compaction,
125 const agxTerrain::VoxelToTerrainMaterialTable* inhomogeneousVoxels,
126 const agx::AffineMatrix4x4& terrainTransform,
127 agx::Real elementSize,
128 int numSolidVoxels,
129 bool enableRenderVoxelSolidMass,
130 bool enableRenderVoxelFluidMass,
131 bool enableRenderVoxelCompaction,
132 bool enableRenderTerrainMaterials,
133 bool enableRenderDefaultTerrainMaterial,
134 agxData::Buffer* verticesBuffer,
135 agxData::Buffer* colorBuffer,
136 agxData::Buffer* voxelSizeBuffer,
137 agxData::Buffer* enableRenderBuffer,
138 std::function<agx::Vec4f(float)> getColor);
139
140 void renderInternalNodes(
141 const agxTerrain::BasicGrid* solid,
142 const agx::AffineMatrix4x4& terrainTransform,
143 int numSolidVoxels,
144 agxData::Buffer* nodesVertices,
145 agxData::Buffer* nodesColorBuffer,
146 agxData::Buffer* nodesFirstBuffer,
147 agxData::Buffer* nodesCountBuffer,
148 bool enableRenderVoxelBoundingBox);
149
150
152 // Variables
154 protected:
156 osg::Group* m_group;
157 agx::TaskGroupRef m_renderTask;
158 osg::ref_ptr<osgSim::ColorRange> m_colorRange;
159 bool m_enable;
160 float m_rScaling;
161 bool m_enableRenderVoxelSolidMass;
162 bool m_enableRenderVoxelFluidMass;
163 bool m_enableRenderVoxelCompaction;
164 bool m_enableRenderVoxelBoundingBox;
165 bool m_enableVelocityFieldRendering;
166 bool m_enableRenderTerrainMaterials;
167 bool m_enableRenderDefaultTerrainMaterial;
168
169 agxRender::ColorVector m_terrainMaterialsColors;
170
171 agxData::BufferRef m_verticesBuffer;
172 agxData::BufferRef m_colorBuffer;
173 agxData::BufferRef m_voxelSizeBuffer;
174 agxData::BufferRef m_voxelEnableRenderBuffer;
175 agx::Vec4f m_maxVoxelColor;
176
177 // Bounding box data
178 agxData::BufferRef m_nodesVertices;
179 agxData::BufferRef m_nodesColorBuffer;
180 agxData::BufferRef m_nodesCountBuffer;
181 agxData::BufferRef m_nodesFirstBuffer;
182
183 // Velocity field data
184 agxData::BufferRef m_linePositions;
185 agxData::BufferRef m_lineOffsets;
186 agx::TaskRef m_lineKernel;
187 };
189}
#define AGXOSG_EXPORT
Abstract representation of a data buffer.
Definition: Buffer.h:56
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:131
Pure virtual interface class for the data storage grid classes we have.
Definition: Grid.h:81
A terrain model based a 3D grid model with overlapping height field that can be deformed by interacti...
Definition: Terrain.h:92
Inheritance with partial specialization due to bug with ref_ptr containers.
A class holding 4 dimensional vectors and providing basic arithmetic.
Definition: Vec4Template.h:35
Templated vector class.
Definition: agx/Vector.h:53
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: macros.h:89
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: macros.h:88
The agxOSG namespace provides functionality for visualizing AGX simulations with OpenSceneGraph.
void renderVoxels(const agx::Vec3iVector &voxels, const agxRender::Color &color, agx::Real voxelSize, const agx::AffineMatrix4x4 &gridTransform, agx::Real size)
double Real
Definition: Real.h:41
bool AGXPHYSICS_EXPORT isInitialized()