AGX Dynamics 2.42.1.1
Loading...
Searching...
No Matches
SceneDecorator.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
22#include <agx/Vec3.h>
23#include <agx/Vec4.h>
24
25#include <agx/PushDisableWarnings.h> // Disabling warnings. Include agx/PopDisableWarnings.h below!
26#include <osg/Referenced>
27#include <osg/Group>
28#include <osg/Texture2D>
29#include <osg/MatrixTransform>
30#include <osg/Projection>
31#include <osg/StateSet>
32#include <osg/PositionAttitudeTransform>
33#include <osg/Switch>
34#include <osg/Material>
35#include <osgShadow/ShadowedScene>
36#include <osgShadow/ShadowTechnique>
37#include <osg/LightSource>
38#include <osg/Geometry>
39#include <agx/PopDisableWarnings.h> // End of disabled warnings.
40#include <agxOSG/LightSource.h>
41
42
43namespace agxRender
44{
45 class Color;
46}
47
48namespace osgText
49{
50 class Text;
51}
52
54namespace agxOSG
55{
57
62 class AGXOSG_EXPORT SceneDecorator : public osg::Group
63 {
64 public:
65
72 SceneDecorator( int windowSizeX, int windowSizeY, int enabledLights = LIGHT0 | LIGHT1 );
73
75 void setEnableShadows( bool flag );
76
78 bool getEnableShadows() const;
79
81 void setEnable( bool flag );
82
84 bool getEnable() const;
85
87 bool isEnabled() const;
88
91 UPPER_LEFT = 0x1,
92 LOWER_LEFT = 0x2,
93 UPPER_RIGHT = 0x3,
94 LOWER_RIGHT = 0x4,
95 FREE
96 };
97
103
106
111 void setLogoPosition(float x, float y);
112
114 void setEnableLogo( bool flag );
115
117 bool getEnableLogo() const;
118
120 bool setLogoFile(const std::string& filename, float density = 1.0);
121
123 void setText( int row, const agx::String& text );
124 void setText( int row, const agx::String& text, const agx::Vec4f& color );
125
129 void setEnableShaderState( bool flag, bool lock=false );
130
132 bool getEnableShaderState( ) const;
133
135 void clearText();
140 bool setBaseTexture(const std::string& imagePath);
141
145 const osg::Vec2& getLogoDimension();
146
151
156 void setMaximumLogoDimension(float x, float y);
157
161 static osg::Vec2 getDefaultLogoPosition();
162
169 osg::MatrixTransform* getHud() { return m_hudRoot.get(); }
170
171 // Overriding add/remove child methods
172 virtual bool insertChild( unsigned int index, osg::Node *child ) { return m_currentRoot->insertChild(index, child); }
173 virtual bool addChild(osg::Node *child) { return m_currentRoot->addChild(child); }
174 inline bool removeChild( osg::Node *child ) { return m_currentRoot->removeChild(child); }
175 inline bool removeChild( unsigned int pos, unsigned int numChildrenToRemove=1 ) { return m_currentRoot->removeChild(pos, numChildrenToRemove); }
176 virtual bool replaceChild( osg::Node *origChild, osg::Node* newChild ) { return m_currentRoot->replaceChild(origChild, newChild); }
177 virtual bool setChild( unsigned int i, osg::Node* node ) { return m_currentRoot->setChild(i, node); }
178 virtual bool removeChildren(unsigned int pos,unsigned int numChildrenToRemove) { return m_currentRoot->removeChildren(pos, numChildrenToRemove); }
179
184 void calculateLightPositions(osg::Node* bound_node = nullptr);
185
186 void calculateLightPositions( const osg::BoundingBox& boundingBox );
187
188 void calculateLightPositions( const osg::BoundingSphere& boundingSphere );
189
191 std::string getFontName() const;
192
194 void setFontName(const std::string& fontName);
195
197 void updateWindowSize(int sizeX, int sizeY);
198
201
203 void setScreenPixelScale(float scale);
204
206 float getFontSize() const;
207
209 void setFontSize(const float& fontSize);
210
212 osg::LightSource* getShadowLightSource();
213
214 enum Lights {
215 LIGHT0 = 0x1,
216 LIGHT1 = 0x2,
217 LIGHT2 = 0x4,
218 ALL = LIGHT0 | LIGHT1 | LIGHT2
219 };
220
221
222 static size_t lightToIndex(Lights l);
223
225
227
230
231 osg::StateSet* getDecoratorStateSet() { return m_decoratorStateSet; }
232
233 osg::LightSource* getOSGLight(Lights l);
234
237
245 NO_SHADOWS
246 };
247
250
252 ShadowMethod getShadowMethod() const { return m_shadowMethod; }
253
255 void setBackgroundColor(const agx::Vec4f& color);
256
262 void setBackgroundColor(const agx::Vec4f& color1, const agx::Vec4f& color2);
263
271 void setBackgroundColor(const agx::Vec4f& colorUL, const agx::Vec4f& colorUR, const agx::Vec4f& colorLL, const agx::Vec4f& colorLR);
272
273
276
283
291 void setBackgroundColor(agx::Vec3 colorUL, agx::Vec3 colorUR, agx::Vec3 colorLL, agx::Vec3 colorLR);
292
297 void setEnableLights(int lightMask = ALL);
298
303 void setEnableRenderedCursor( bool enable );
305 void updateCursorPosition( float x, float y );
306
307 osg::Texture2D* getLogo();
308
310 void setLogo(osg::Texture2D* logo, float density = 1.0);
311
312 // Will reset the rendering HUD.
313 void resetHUD();
314
318 osg::Group* getShadowedScene() const;
319
323 osg::Group* getNonShadowedScene() const;
324
325 static const osg::Material* getDefaultDecoratorMaterial();
326
327 protected:
332 void createHUD();
333
336
337 void init(Lights l);
338
339 osg::ref_ptr<osg::Group> m_enabledRoot;
340 osg::ref_ptr<osg::Group> m_enabledNonShadowRoot;
341 osg::ref_ptr<osg::Group> m_currentRoot;
342 osg::ref_ptr<osg::Group> m_disabledRoot;
343 osg::ref_ptr<osg::Group> m_disabledNonShadowRoot;
344 osg::ref_ptr<osg::Switch> m_backgroundRoot;
345 osg::observer_ptr<osg::Geometry> m_backgroundQuad;
347 osg::ref_ptr<osg::Texture2D> m_logoTexture;
348 osg::ref_ptr<osg::PositionAttitudeTransform> m_logoTransform;
349 osg::ref_ptr<osg::Switch> m_logoSwitch;
350 osg::ref_ptr<osg::MatrixTransform> m_hudRoot;
351 osg::ref_ptr<osg::StateSet> m_logoStateSet;
352 osg::Vec2 m_logoPosition;
357 std::string m_baseTexturePath;
359 std::string m_fontName;
365 osg::Vec2 m_logoSize;
368
369 osg::ref_ptr<osgShadow::ShadowedScene> m_shadowedScene;
370 osg::ref_ptr<osgShadow::ShadowTechnique> m_shadowTechnique;
371
372 osg::ref_ptr<osg::StateSet> m_decoratorStateSet;
373
375 osg::ref_ptr<osg::LightSource> m_ShadowlightSource;
376 osg::ref_ptr<osg::Vec3Array> m_backgroundColors;
377
379
381
382 bool m_calculateLightPosition[3];
383
384 osg::ref_ptr<osg::Node> m_cursorTransform;
385 osg::ref_ptr<osg::Camera> m_hudCamera;
386 osg::ref_ptr<osg::Projection> m_hudProjection;
387
390
391 static osg::ref_ptr<osg::Material> s_decoratorMaterial;
392 };
393}
#define AGXOSG_EXPORT
Decorates a scene with a specific AGX Rendering Style.
osg::Group * getNonShadowedScene() const
void setEnableRenderedCursor(bool enable)
Enable/disable the mouse cursor.
osg::ref_ptr< osg::Node > m_cursorTransform
LogoLocation getLogoLocation() const
void setBackgroundColor(const agx::Vec4f &colorUL, const agx::Vec4f &colorUR, const agx::Vec4f &colorLL, const agx::Vec4f &colorLR)
Set a gradient four color background (each corner) colorUL - Upper left color colorUR - Upper right c...
bool getEnable() const
Return true if AGX rendering style is enabled.
osg::ref_ptr< osg::Switch > m_logoSwitch
osg::ref_ptr< osg::PositionAttitudeTransform > m_logoTransform
void updateWindowSize(int sizeX, int sizeY)
Updates information about the window size in x and y (for logo scaling).
osg::observer_ptr< osg::Geometry > m_backgroundQuad
void setEnableCalculateLightPositions(Lights l, bool f)
void setBackgroundColor(agx::Vec3 upper, agx::Vec3 lower)
Set a gradient two color background.
static const osg::Material * getDefaultDecoratorMaterial()
bool isEnabled() const
Return true if AGX rendering style is enabled.
void setLogoPosition(float x, float y)
Set the position of logo into [x, y] if setLogoLocation(FREE) has been previously called Valid range ...
@ PARALLELLSPLIT_SHADOWMAP
Deprecated.
virtual bool addChild(osg::Node *child)
void setText(int row, const agx::String &text, const agx::Vec4f &color)
void setEnable(bool flag)
Enable/disable AGX rendering style for sub-graph.
void setBackgroundColor(agx::Vec3 colorUL, agx::Vec3 colorUR, agx::Vec3 colorLL, agx::Vec3 colorLR)
Set a gradient four color background (each corner) colorUL - Upper left color colorUR - Upper right c...
void setEnableLights(int lightMask=ALL)
Reset and enable the specified lights.
SceneDecorator(int windowSizeX, int windowSizeY, int enabledLights=LIGHT0|LIGHT1)
Constructor.
void setScreenPixelScale(float scale)
Specify the screen pixel scale (i.e. 2.0 for high DPI and 1.0 for 1:1)
osg::ref_ptr< osg::Group > m_currentRoot
osg::ref_ptr< osgShadow::ShadowTechnique > m_shadowTechnique
agx::Vec2i32 getWindowSize() const
Returns the window size.
ShadowMethod m_shadowMethod
osg::ref_ptr< osg::Switch > m_backgroundRoot
void updateCursorPosition(float x, float y)
void clearText()
Reset all text to empty strings.
void setBackgroundColor(agx::Vec3 color)
Set a uniform background color using color.
osg::ref_ptr< osg::MatrixTransform > m_hudRoot
osg::StateSet * getDecoratorStateSet()
void calculateLightPositions(osg::Node *bound_node=nullptr)
Calculate the positions of the light sources from the bound of either a specified node,...
osg::Texture2D * getLogo()
void setEnableShaderState(bool flag, bool lock=false)
Enable/disable the use of a shader based default render state.
bool getEnableRenderedCursor() const
bool setBaseTexture(const std::string &imagePath)
Specif the path to the base texture on all decorated objects.
bool removeChild(unsigned int pos, unsigned int numChildrenToRemove=1)
osg::ref_ptr< osgShadow::ShadowedScene > m_shadowedScene
static size_t lightToIndex(Lights l)
osg::ref_ptr< osg::StateSet > m_logoStateSet
void setLogo(osg::Texture2D *logo, float density=1.0)
Might want to call updateLogo afterwards.
void setEnableShadows(bool flag)
Enable/disable shadows for the sub-graph.
void calculateLightPositions(const osg::BoundingSphere &boundingSphere)
osg::LightSource * getShadowLightSource()
Return a pointer to the light source used for calculating shadows.
void setText(int row, const agx::String &text)
Print a row of text.
LogoLocation
Specifies the location of the logo.
LogoLocation m_logoLocation
void updateLogo()
Updates the logo scale and position, depending on logo size, and window width and height.
virtual bool insertChild(unsigned int index, osg::Node *child)
virtual bool replaceChild(osg::Node *origChild, osg::Node *newChild)
std::string getFontName() const
Returns the font name.
float getFontSize() const
Returns the font Size.
virtual bool removeChildren(unsigned int pos, unsigned int numChildrenToRemove)
osg::ref_ptr< osg::Group > m_enabledNonShadowRoot
void setFontName(const std::string &fontName)
Sets the font name.
void setBackgroundColor(const agx::Vec4f &color1, const agx::Vec4f &color2)
Set a gradient two color background.
osg::Vec2 getMaximumLogoDimension()
osg::Group * getShadowedScene() const
agx::Vector< osgText::Text * > m_text
osg::MatrixTransform * getHud()
Return a pointer to the hud group.
const osg::Vec2 & getLogoDimension()
void setMaximumLogoDimension(float x, float y)
Set the maximum logo dimension.
osg::ref_ptr< osg::Projection > m_hudProjection
osg::ref_ptr< osg::Vec3Array > m_backgroundColors
bool setShadowLightSource(Lights l)
Specify which light source is used for calculating shadows.
osg::ref_ptr< osg::Texture2D > m_logoTexture
osg::ref_ptr< osg::Group > m_disabledRoot
void setShadowMethod(ShadowMethod m)
Specify which method is used for generating shadows,.
bool getEnableShaderState() const
osg::ref_ptr< osg::StateSet > m_decoratorStateSet
bool setLogoFile(const std::string &filename, float density=1.0)
Specify a path to the image with the logo and the pixel density (i.e. 2.0 for high DPI and 1....
static osg::Vec2 getDefaultLogoPosition()
agx::Vector< osg::ref_ptr< osg::LightSource > > m_lightSources
virtual bool setChild(unsigned int i, osg::Node *node)
void calculateLightPositions(const osg::BoundingBox &boundingBox)
bool getEnableShadows() const
static osg::ref_ptr< osg::Material > s_decoratorMaterial
void setLogoLocation(LogoLocation l)
Set the position of the logo from a list of predefined positions.
bool getEnableCalculateLightPositions(Lights l) const
osg::ref_ptr< osg::Group > m_enabledRoot
osg::ref_ptr< osg::Camera > m_hudCamera
osg::ref_ptr< osg::Group > m_disabledNonShadowRoot
void setEnableLogo(bool flag)
Enable/disable the rendering of the logo.
bool removeChild(osg::Node *child)
osg::ref_ptr< osg::LightSource > m_ShadowlightSource
void init(Lights l)
osg::LightSource * getOSGLight(Lights l)
bool getEnableLogo() const
agxOSG::LightSource getLightSource(Lights l)
Get a wrapper for a LightSource with only AGX types.
void setFontSize(const float &fontSize)
Sets the font Size.
std::string m_baseTexturePath
ShadowMethod getShadowMethod() const
void setBackgroundColor(const agx::Vec4f &color)
Set a uniform background color using color.
A class holding 4 dimensional vectors and providing basic arithmetic.
Definition: Vec4Template.h:35
Templated vector class.
Definition: agx/Vector.h:53
The agxOSG namespace provides functionality for visualizing AGX simulations with OpenSceneGraph.
Namespace containing classes for handling debug rendering of collision geometries,...
Definition: Constraint.h:36