VR-Forces Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DtIndirectEntityGeometry.h
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright (c) 2025 MAK Technologies, Inc.
3 ** All rights reserved.
4 ******************************************************************************/
5 
9 
10 #pragma once
11 
12 #include <vrvOsg/vrvOsg.h>
14 
15 #include <tbb/concurrent_vector.h>
16 
17 namespace makVrv
18 {
21 
24 
26  template <>
27  inline const char* creatorTypeName<DtIndirectEntityGeometry>(void) { return "DtIndirectEntityGeometryCreator"; }
28 
40  {
41  public:
44 
47  template<class T>
49  {
52  };
53 
54  template<class T>
56  {
59  int myFlags = 0;
60  };
61 
63  typedef std::unordered_map<int, Matrix4_32> MapInstanceIdToXform;
64 
70  typedef std::unordered_map< osgSim::MultiSwitch*, MultiSwitchPair> MapCloneToMultiSwitchPair;
71  typedef std::unordered_map< int, MapCloneToMultiSwitchPair> MapInstanceToMapCloneToMasterMultiSwitches;
72 
73  //Use the pair to hold the refs and the raw pointer to index into the map
77  typedef std::unordered_map< osgSim::DOFTransform*, DofTransformPair > MapCloneToDofTransformPair;
78  typedef std::unordered_map< int, MapCloneToDofTransformPair> MapInstanceToMapCloneToMasterDofs;
79 
84  typedef std::unordered_map< osg::Sequence*, SequencePair > MapCloneToSequencePair;
85  typedef std::unordered_map< int, MapCloneToSequencePair> MapInstanceToMapCloneToMasterSequences;
86 
88  typedef std::map< const std::string, DtIndirectUvOffsetManager::UvOffset> MapAnnotationToUvOffsetData;
89  typedef std::unordered_map< int, MapAnnotationToUvOffsetData> MapInstanceToMapAnnotationToUvOffsetData;
90 
91  typedef std::unordered_map< int, std::tuple<float, float, float> > MapInstanceToUvOffset;
92 
98  {
102  InstanceUpdateStruct( int id, const Matrix4_32& xFormMat );
105 
108  InstanceUpdateStruct() = delete;
109  InstanceUpdateStruct& operator=( const InstanceUpdateStruct& ) = delete;
111  };
112 
114  using InstanceUpdatesVector = tbb::concurrent_vector<InstanceUpdateStruct>;
115  public:
117  virtual ~DtIndirectEntityGeometry();
118 
119  protected:
121  DtIndirectEntityGeometry(DtDe& de, const DtCullShaderConfig& cullShaderConfig, bool terrainPatch);
122 
123  private:
125  DtIndirectEntityGeometry() = delete;
127  DtIndirectEntityGeometry(const DtIndirectEntityGeometry& other) = delete;
129  DtIndirectEntityGeometry& operator=(const DtIndirectEntityGeometry& other) = delete;
130 
131  public:
133  virtual void setInstanceMatrixTransform(int instanceId, const Matrix4_32& xForm);
134 
136  virtual void concurrentSetInstanceMatrixTransform( int instanceId, const Matrix4_32& xForm );
137 
139  virtual void processUpdates();
140 
142  virtual Matrix4_32 instanceMatrixTransform(int instanceId) const;
143 
145  virtual void removeInstance(int id);
146 
148  virtual void setInstanceMultiSwitch(int id, osgSim::MultiSwitch* clone, osgSim::MultiSwitch* master);
149 
151  virtual void instanceMultiSwitches(int instanceIdIndirect, MapCloneToMultiSwitchPair& mapCloneToMasterMultiSwitches) const;
152 
154  virtual void setInstanceModelId(int id, int modelId);
155 
157  virtual void setInstanceUvOffset(int id, const std::string& annotation, float uOffset, float vOffset);
158 
160  virtual void scrollUv(int id, const std::tuple<float, float, float>& uvspeeds);
161 
163  virtual void instanceAnnotationsAndUvOffsets(int instanceIdIndirect, std::vector<DtIndirectAnnotationAndUvOffset>& annotations) const;
164 
166  virtual void setInstanceColor(int instanceIdIndirect, const Vector4_32& color);
168  virtual Vector4_32 instanceColor(int instanceIdIndirect) const;
170 
172  virtual void setInstanceVisibility(int instanceIdIndirect, bool visible);
174  virtual bool instanceVisibility(int instanceIdIndirect) const;
176 
178  virtual void setInstanceLightPointGroupId(int instanceIdIndirect, int lightPointGroupId);
180  virtual int instanceLightPointGroupId(int instanceIdIndirect) const;
182 
184  virtual void setInstanceLightPointMaxDistance(int instanceIdIndirect, float lightPointMaxDistance);
186  virtual float instanceLightPointMaxDistance(int instanceIdIndirect) const;
188 
190  virtual void setInstanceDof(int id, osgSim::DOFTransform* clone, osgSim::DOFTransform* master, int animationFlags);
191 
193  virtual void setInstanceDofAnimationFlags(int id, osgSim::DOFTransform* clone, osgSim::DOFTransform* master, int animationFlags);
194 
196  virtual void setInstanceDofTranslation(int id, osgSim::DOFTransform* clone, osgSim::DOFTransform* master
197  , const Vector3_64& trans
198  , const Vector3_64& transVel);
199 
201  virtual void setInstanceDofOrientation(int id, osgSim::DOFTransform* clone, osgSim::DOFTransform* master
202  , const Vector3_64& hpr
203  , const Vector3_64& hprVel
204  , int animationFlags);
205 
207  virtual void setInstanceDofOrientation(int id, osgSim::DOFTransform* clone, osgSim::DOFTransform* master
208  , const Vector3_64& hprVel
209  , bool forceUpdate
210  , int animationFlags);
211 
213  virtual void instanceDofs(int instanceIdIndirect, MapCloneToDofTransformPair& mapCloneToDofTransformPair) const;
214 
216  virtual void setInstanceSequence(int id, osg::Sequence* clone, osg::Sequence* master);
217 
219  virtual void instanceSequences(int instanceIdIndirect, MapCloneToSequencePair& mapCloneToMasterSequences) const;
220 
221 
225  virtual bool hasInProgressInstanceMove() const;
226 
228  virtual void addInProgressInstanceMove();
229 
231  virtual void subtractInProgressInstanceMove();
232 
238  virtual bool allInstancesAreToBeDeleted() const override;
239 
240  protected:
242  virtual void setMultiSwitchOnInstanceInInstanceContainer(int instanceContainerId, osgSim::MultiSwitch* clone, osgSim::MultiSwitch* master);
243 
245  virtual bool setDofOnInstanceInInstanceContainer(int instanceContainerId, osgSim::DOFTransform* clone, osgSim::DOFTransform* master, int animationFlags);
246 
248  virtual void setUvOffsetOnInstanceInInstanceContainer(const int instanceId, const std::string& annotation, float uOffset, float vOffset);
249 
251  virtual bool removeInstanceInInstanceContainer(int instanceContainerId);
252 
255  virtual void removeInstanceFromIndicesCount(int instanceContainerIndex);
256 
258  virtual void updateInstancePositionOrientationAddedActual(const DtIndirectGeometryInstance& instance, int outInstanceIndex) override;
259 
261  virtual void updateInstanceSwitchesAddedActual(const DtIndirectGeometryInstance& instance, int outInstanceIndex) override;
262 
264  virtual void updateInstanceSequencesAddedActual(const DtIndirectGeometryInstance& instance, int outInstanceIndex) override;
265 
267  virtual void updateInstanceUvOffsetsAddedActual(const DtIndirectGeometryInstance& instance, int outInstanceIndex) override;
268 
270  virtual void updateInstanceColorAddedActual(const DtIndirectGeometryInstance& instance, int outInstanceIndex) override;
271 
273  virtual void updateInstanceLightPointGroupIdActual(const DtIndirectGeometryInstance& instance, int outInstanceIndex) override;
274 
276  virtual void updateInstanceVisibilityLightPointMaxDistanceActual(const DtIndirectGeometryInstance& instance, int outInstanceIndex) override;
277 
279  virtual bool updateInstanceDeletionBeforeAddedActual(const DtIndirectGeometryInstance& instance) override;
280 
282  virtual void updateInstancesDofsAddedActual(const DtIndirectGeometryInstance& instance, int outInstanceIndex) override;
283 
285  virtual void updateInstanceModelIdAddedActual(const DtIndirectGeometryInstance& instance, int outInstanceIndex) override;
286 
288  virtual void setInstanceModelIdInInstanceContainer(int instanceId, int modelId);
289 
290  protected:
292  //typedef std::unordered_map<int, Matrix4_32> MapInstanceIdToXform;
294 
295  //Left the typedefs here commented out so they are easier to follow. They need to be at the
296  // top so they can be used as arguments in the functions.
297 
302  //typedef CloneMasterPair<osgSim::MultiSwitch> MultiSwitchPair;
303  //typedef std::map< osgSim::MultiSwitch*, MultiSwitchPair> MapCloneToMultiSwitchPair;
304  //typedef std::map< int, MapCloneToMultiSwitchPair> MapInstanceToMapCloneToMasterMultiSwitches;
306 
307  //Use the pair to hold the refs and the raw pointer to index into the map
310  //typedef CloneMasterPair<osgSim::DOFTransform> DofTransformPair;
311  //typedef std::unordered_map< osgSim::DOFTransform*, DofTransformPair > MapCloneToDofTransformPair;
312  //typedef std::unordered_map< int, MapCloneToDofTransformPair> MapInstanceToMapCloneToMasterDofs;
314 
315  //Use the pair to hold the refs and the raw pointer to index into the map
318  //typedef CloneMasterPair<osg::Sequence> SequencePair;
319  //typedef std::unordered_map< osg::Sequence*, SequencePair > MapCloneToSequencePair;
320  //typedef std::unordered_map< int, MapCloneToSequencePair> MapInstanceToMapCloneToMasterSequences;
322 
324  //typedef std::unordered_map< const std::string, DtIndirectUvOffsetManager::UvOffset> MapAnnotationToUvOffsetData;
325  //typedef std::unordered_map< int, MapAnnotationToUvOffsetData> MapInstanceToMapAnnotationToUvOffsetData;
327 
329  //typedef std::unordered_map< int, DtIndirectUvOffsetManager::UvOffset> MapInstanceToUvOffset;
331 
332  std::unordered_map< int, int > myMapInstanceInIndirectToModelId;
333 
335  std::unordered_map<int, Vector4_32> myMapInstanceToColor;
336 
338  std::unordered_map<int, bool> myMapInstanceToVisibility;
339 
341  std::unordered_map<int, int> myMapInstanceToLightPointGroupId;
342 
344  std::unordered_map<int, float> myMapInstanceToLightPointMaxDistance;
345 
347  typedef std::unordered_set<int> SetInstancesToDelete;
349 
352 
354 
355  // Supporting texture variants is relatively new. If there are bugs,
356  // this can be changed to false, to debug whether texture variants support is the cause.
357  const bool mySupportInstanceModelChanges = true;
358  };
359 }
osg::ref_ptr< T > myMaster
Definition: DtIndirectEntityGeometry.h:51
tbb::concurrent_vector< InstanceUpdateStruct > InstanceUpdatesVector
Holds transform updates that are to be applied to instances.
Definition: DtIndirectEntityGeometry.h:114
const char * creatorTypeName< DtIndirectEntityGeometry >(void)
template specialization for the creator (pass the class being created to the creatorTypeName template...
Definition: DtIndirectEntityGeometry.h:27
std::unordered_map< int, std::tuple< float, float, float > > MapInstanceToUvOffset
Definition: DtIndirectEntityGeometry.h:91
non virtual container class for holding the information needed to create an indirect geometry instanc...
Definition: DtIndirectGeometryInstance.h:26
osg::ref_ptr< T > myClone
Definition: DtIndirectEntityGeometry.h:50
std::unordered_set< int > SetInstancesToDelete
Structure to hold instance ids to be deleted.
Definition: DtIndirectEntityGeometry.h:347
std::unordered_map< int, MapCloneToSequencePair > MapInstanceToMapCloneToMasterSequences
Definition: DtIndirectEntityGeometry.h:85
MapInstanceToMapCloneToMasterSequences myMapInstanceToMapCloneToMasterSequences
Maps an instance id and a master sequence to the clone sequence so we can get to the cloned sequence ...
Definition: DtIndirectEntityGeometry.h:321
MapCloneToDofTransformPairAndFlags< osgSim::DOFTransform > DofTransformPair
Maps an instance id and a master dof to the clone dof so we can get to the cloned dof which contains ...
Definition: DtIndirectEntityGeometry.h:76
osg::ref_ptr< T > myClone
Definition: DtIndirectEntityGeometry.h:57
#define DT_DLL_VRVOSG
Definition: vrvOsg.h:23
Definition: featureContext.h:36
MapInstanceToMapCloneToMasterDofs myMapInstanceToMapCloneToMasterDofs
Maps an instance id and a master dof to the clone dof so we can get to the cloned dof which contains ...
Definition: DtIndirectEntityGeometry.h:313
CloneMasterPair< osgSim::MultiSwitch > MultiSwitchPair
Structure to hold instance multi-switches&#39; state until the instance is actually added Use the pair to...
Definition: DtIndirectEntityGeometry.h:69
std::map< const std::string, DtIndirectUvOffsetManager::UvOffset > MapAnnotationToUvOffsetData
Maps and instance id and a string to the current uv offset for this particular annotation.
Definition: DtIndirectEntityGeometry.h:88
std::unordered_map< osg::Sequence *, SequencePair > MapCloneToSequencePair
Definition: DtIndirectEntityGeometry.h:84
shader configuration storage class. Has 3 available options which are described in the constructor&#39;s ...
Definition: DtCullShaderConfig.h:21
InstanceUpdatesVector myInstanceUpdates
Updates are pushed to this vector concurrently by the indirect manager.
Definition: DtIndirectEntityGeometry.h:351
Variadic templated creator class for defining a DtVirtualBaseClass creator that is automatically regi...
Definition: DtVirtualBaseClassCreator.h:23
Inherited from DtIndirectGeometry additionally implements: -removal of instances -ability to set/get ...
Definition: DtIndirectEntityGeometry.h:39
std::unordered_map< int, int > myMapInstanceInIndirectToModelId
Definition: DtIndirectEntityGeometry.h:332
Struct to hold an instance ID and matrix transform Transforms are all calculated concurrently then st...
Definition: DtIndirectEntityGeometry.h:97
\ ::, which allows us to hook into our indirect engine to render using indirect rendering...
Definition: DtIndirectGeometry.h:120
std::unordered_map< osgSim::MultiSwitch *, MultiSwitchPair > MapCloneToMultiSwitchPair
Definition: DtIndirectEntityGeometry.h:70
CloneMasterPair< osg::Sequence > SequencePair
Use the pair to hold the refs and the raw pointer to index into the map Maps an instance id and a ma...
Definition: DtIndirectEntityGeometry.h:83
std::unordered_map< int, int > myMapInstanceToLightPointGroupId
Maps an instance id to the light point group id for that instance.
Definition: DtIndirectEntityGeometry.h:341
MapInstanceToMapCloneToMasterMultiSwitches myMapInstanceToMapCloneToMasterMultiSwitches
Structure to hold instance multi-switches&#39; state until the instance is actually added Use the pair to...
Definition: DtIndirectEntityGeometry.h:305
std::unordered_map< int, Matrix4_32 > MapInstanceIdToXform
Structure to hold instance orientation until the instance is actually added.
Definition: DtIndirectEntityGeometry.h:63
std::unordered_map< int, MapCloneToMultiSwitchPair > MapInstanceToMapCloneToMasterMultiSwitches
Definition: DtIndirectEntityGeometry.h:71
friend DtIndirectEntityGeometryCreator
only creator can create
Definition: DtIndirectEntityGeometry.h:43
osg::ref_ptr< T > myMaster
Definition: DtIndirectEntityGeometry.h:58
Contains DLL export macros.
MapInstanceIdToXform myMapInstanceIdToXform
Structure to hold instance orientation until the instance is actually added.
Definition: DtIndirectEntityGeometry.h:293
The DtDe is the core component of any VR-Vantage application. It owns a DtRenderer, DtDeCommunicator, as well as a DtDisplay and other things.
Definition: DtDe.h:76
std::unordered_map< osgSim::DOFTransform *, DofTransformPair > MapCloneToDofTransformPair
Definition: DtIndirectEntityGeometry.h:77
Matrix4_32 myXForm
Definition: DtIndirectEntityGeometry.h:100
MapInstanceToMapAnnotationToUvOffsetData myMapInstanceToMapAnnotationToUvOffsetData
Maps and instance id and a string to the current uv offset for this particular annotation.
Definition: DtIndirectEntityGeometry.h:326
std::unordered_map< int, bool > myMapInstanceToVisibility
Maps an instance id to the visibility for that instance.
Definition: DtIndirectEntityGeometry.h:338
std::atomic< int > myNumInProgressInstanceMoves
Definition: DtIndirectEntityGeometry.h:353
std::unordered_map< int, float > myMapInstanceToLightPointMaxDistance
Maps an instance id to the light point max distance for that instance.
Definition: DtIndirectEntityGeometry.h:344
MapInstanceToUvOffset myMapInstanceToUvOffset
Maps and instance id to the current uv offset for all scrollable uv offsets.
Definition: DtIndirectEntityGeometry.h:330
Contains the DtIndirectGeometry class declaration.
int myInstanceId
Definition: DtIndirectEntityGeometry.h:99
Helper struct to make the code a bit more clear. Used instead of std::pair to hold a pair of ref_ptr&#39;...
Definition: DtIndirectEntityGeometry.h:48
std::unordered_map< int, MapAnnotationToUvOffsetData > MapInstanceToMapAnnotationToUvOffsetData
Definition: DtIndirectEntityGeometry.h:89
std::unordered_map< int, MapCloneToDofTransformPair > MapInstanceToMapCloneToMasterDofs
Definition: DtIndirectEntityGeometry.h:78
std::unordered_map< int, Vector4_32 > myMapInstanceToColor
Maps an instance id to the color for that instance.
Definition: DtIndirectEntityGeometry.h:335
DtVirtualBaseClassCreator< DtIndirectEntityGeometry, const DtCullShaderConfig &, const bool & > DtIndirectEntityGeometryCreator
creator
Definition: DtIndirectEntityGeometry.h:20
SetInstancesToDelete mySetInstancesIndirectIdsToDelete
Definition: DtIndirectEntityGeometry.h:348

Document ID: Generated on Thu Oct 23 22:29:17 EDT 2025 from SVN revision 280951
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)