AGX Dynamics 2.37.3.4
Loading...
Searching...
No Matches
RigidBodyRenderCache.h
Go to the documentation of this file.
1/*
2Copyright 2007-2024. 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#include <agx/Math.h>
21#include <agx/Referenced.h>
22#include <agx/RigidBody.h>
23#include <agxOSG/GeometryNode.h>
24
25
26namespace agxOSG
27{
37 {
38 public:
45 {
46 public:
47
49 m_group(nullptr) { }
50
51 RigidBodyVisualGroup(osg::Group* group, std::vector<size_t> geometryIndex) :
52 m_group(group), m_geometryIndices(geometryIndex) { }
53
54 agxCollide::GeometryRef getGeometry(agx::RigidBody* newBody, size_t visualIndex) const;
55
56 bool isValid() const { return m_group != nullptr; }
57
58 size_t getNumChildren() const { return isValid() ? m_group->getNumChildren() : 0; }
59
60 osg::Group* getGroup() const { return m_group; }
61
62 private:
63 osg::ref_ptr<osg::Group> m_group;
64 // a list with indices linking each visual node (child in m_group) to a geometry in the rigid body
65 std::vector<size_t> m_geometryIndices;
66 };
67
68 public:
74 RigidBodyRenderCache(bool onlyAddEmittedBodies=true);
75
80 void addToCache(osg::Group* rootNode);
81
86 osg::Group* getNode(agx::RigidBody* body);
87
92
96 void setOnlyAddEmittedBodies( bool enable );
97
105
112
123
131
135 void clear();
136
137 protected:
139 void traverseAndInsert(osg::Group* rootNode);
140 bool shouldAddBody(agx::RigidBody* body) const;
141
142 private:
145
146 BodyToGroupNodeTable m_bodiesToGroupNodes;
147 BodyToRenderGroupTable m_bodiesToRenderGroups;
148 bool m_onlyAddEmittedBodies;
149 // A placeholder for an empty visualization group
151 };
152}
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
#define AGXOSG_EXPORT
A help class to store all information we need to copy a rigid body visualization to duplicate the rig...
RigidBodyVisualGroup(osg::Group *group, std::vector< size_t > geometryIndex)
agxCollide::GeometryRef getGeometry(agx::RigidBody *newBody, size_t visualIndex) const
RigidBodyRenderCache is used to cache generated visuals and lookup mappings of RigidBodies cloned fro...
const RigidBodyRenderCache::RigidBodyVisualGroup & getOrCreateCachedTemplateBodyNode(agx::RigidBody *body)
Gets cached template body visual from the node cache if it exists, otherwise a new visual node will b...
void traverseAndInsert(osg::Group *rootNode)
bool shouldAddBody(agx::RigidBody *body) const
void setOnlyAddEmittedBodies(bool enable)
RigidBodyRenderCache(bool onlyAddEmittedBodies=true)
Default constructor.
const RigidBodyRenderCache::RigidBodyVisualGroup & addTemplateBodyToVisualCache(agx::RigidBody *body)
Add template body to visual cache that is used during playback in qtViewer.
bool getOnlyAddEmittedBodies() const
osg::Group * getNode(agx::RigidBody *body)
Get the current mapping in the cache between a RigidBody to a osg::Group.
const RigidBodyRenderCache::RigidBodyVisualGroup & getCachedTemplateBodyVisual(agx::RigidBody *body)
Get cached template body visual from the node cache if it exists.
void clear()
Clear the internal cache.
void addToCache(osg::Group *rootNode)
Add the osg::Group created from a RigidBody to the cache.
bool bodyIsTemplateEmitted(agx::RigidBody *body)
Checks wherever the specifed body is generated/cloned from the temlpate body via RigidBodyEmitter och...
Inheritance with partial specialization due to bug with ref_ptr containers.
Base class providing referencing counted objects.
Definition: Referenced.h:120
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:55
The agxOSG namespace provides functionality for visualizing AGX simulations with OpenSceneGraph.