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) 2023 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 
41  {
42  public:
45 
48  template<class T>
50  {
53  };
54 
55  template<class T>
57  {
60  int myFlags = 0;
61  };
62 
64  typedef std::unordered_map<int, Matrix4_32> MapInstanceIdToXform;
65 
71  typedef std::unordered_map< osgSim::MultiSwitch*, MultiSwitchPair> MapCloneToMultiSwitchPair;
72  typedef std::unordered_map< int, MapCloneToMultiSwitchPair> MapInstanceToMapCloneToMasterMultiSwitches;
73 
74  //Use the pair to hold the refs and the raw pointer to index into the map
78  typedef std::unordered_map< osgSim::DOFTransform*, DofTransformPair > MapCloneToDofTransformPair;
79  typedef std::unordered_map< int, MapCloneToDofTransformPair> MapInstanceToMapCloneToMasterDofs;
80 
85  typedef std::unordered_map< osg::Sequence*, SequencePair > MapCloneToSequencePair;
86  typedef std::unordered_map< int, MapCloneToSequencePair> MapInstanceToMapCloneToMasterSequences;
87 
89  typedef std::map< const std::string, DtIndirectUvOffsetManager::UvOffset> MapAnnotationToUvOffsetData;
90  typedef std::unordered_map< int, MapAnnotationToUvOffsetData> MapInstanceToMapAnnotationToUvOffsetData;
91 
92  typedef std::unordered_map< int, std::tuple<float, float, float> > MapInstanceToUvOffset;
93 
99  {
103  InstanceUpdateStruct( int id, const Matrix4_32& xFormMat );
106 
109  InstanceUpdateStruct() = delete;
110  InstanceUpdateStruct& operator=( const InstanceUpdateStruct& ) = delete;
112  };
113 
115  using InstanceUpdatesVector = tbb::concurrent_vector<InstanceUpdateStruct>;
116  public:
118  virtual ~DtIndirectEntityGeometry();
119 
120  protected:
122  DtIndirectEntityGeometry(DtDe& de, const DtCullShaderConfig& cullShaderConfig, bool terrainPatch);
123 
124  private:
126  DtIndirectEntityGeometry() = delete;
128  DtIndirectEntityGeometry(const DtIndirectEntityGeometry& other) = delete;
130  DtIndirectEntityGeometry& operator=(const DtIndirectEntityGeometry& other) = delete;
131 
132  public:
134  virtual void setInstanceMatrixTransform(int instanceId, const Matrix4_32& xForm);
135 
137  virtual void concurrentSetInstanceMatrixTransform( int instanceId, const Matrix4_32& xForm );
138 
140  virtual void processUpdates();
141 
143  virtual Matrix4_32 instanceMatrixTransform(int instanceId) const;
144 
146  virtual void removeInstance(int id);
147 
149  virtual void setInstanceMultiSwitch(int id, osgSim::MultiSwitch* clone, osgSim::MultiSwitch* master);
150 
152  virtual void instanceMultiSwitches(int instanceIdIndirect, MapCloneToMultiSwitchPair& mapCloneToMasterMultiSwitches) const;
153 
155  virtual void setInstanceModelId(int id, int modelId);
156 
158  virtual void setInstanceUvOffset(int id, const std::string& annotation, float uOffset, float vOffset);
159 
161  virtual void scrollUv(int id, const std::tuple<float, float, float>& uvspeeds);
162 
164  virtual void instanceAnnotationsAndUvOffsets(int instanceIdIndirect, std::vector<DtIndirectAnnotationAndUvOffset>& annotations) const;
165 
167  virtual void setInstanceColor(int instanceIdIndirect, const Vector4_32& color);
169  virtual Vector4_32 instanceColor(int instanceIdIndirect) const;
171 
173  virtual void setInstanceOtherData0(int instanceIdIndirect, const Vector4_32& data);
175  virtual Vector4_32 instanceOtherData0(int instanceIdIndirect) const;
177 
179  virtual void setInstanceVisibility(int instanceIdIndirect, bool visible);
181  virtual bool instanceVisibility(int instanceIdIndirect) const;
183 
185  virtual void setInstanceLightPointGroupId(int instanceIdIndirect, int lightPointGroupId);
187  virtual int instanceLightPointGroupId(int instanceIdIndirect) const;
189 
191  virtual void setInstanceLightPointMaxDistance(int instanceIdIndirect, float lightPointMaxDistance);
193  virtual float instanceLightPointMaxDistance(int instanceIdIndirect) const;
195 
197  virtual void setInstanceDof(int id, osgSim::DOFTransform* clone, osgSim::DOFTransform* master, int animationFlags);
198 
200  virtual void setInstanceDofTranslation(int id, osgSim::DOFTransform* clone, osgSim::DOFTransform* master
201  , const Vector3_64& trans
202  , const Vector3_64& transVel);
203 
205  virtual void setInstanceDofOrientation(int id, osgSim::DOFTransform* clone, osgSim::DOFTransform* master
206  , const Vector3_64& hpr
207  , const Vector3_64& hprVel
208  , int animationFlags);
209 
211  virtual void setInstanceDofOrientation(int id, osgSim::DOFTransform* clone, osgSim::DOFTransform* master
212  , const Vector3_64& hprVel
213  , bool forceUpdate
214  , int animationFlags);
215 
217  virtual void instanceDofs(int instanceIdIndirect, MapCloneToDofTransformPair& mapCloneToDofTransformPair) const;
218 
220  virtual void setInstanceSequence(int id, osg::Sequence* clone, osg::Sequence* master);
221 
223  virtual void instanceSequences(int instanceIdIndirect, MapCloneToSequencePair& mapCloneToMasterSequences) const;
224 
225 
229  virtual bool hasInProgressInstanceMove() const;
230 
232  virtual void addInProgressInstanceMove();
233 
235  virtual void subtractInProgressInstanceMove();
236 
242  virtual bool allInstancesAreToBeDeleted() const override;
243 
244  protected:
246  virtual void setMultiSwitchOnInstanceInInstanceContainer(int instanceContainerId, osgSim::MultiSwitch* clone, osgSim::MultiSwitch* master);
247 
249  virtual bool setDofOnInstanceInInstanceContainer(int instanceContainerId, osgSim::DOFTransform* clone, osgSim::DOFTransform* master, int animationFlags);
250 
252  virtual void setUvOffsetOnInstanceInInstanceContainer(const int instanceId, const std::string& annotation, float uOffset, float vOffset);
253 
255  virtual bool removeInstanceInInstanceContainer(int instanceContainerId);
256 
259  virtual void removeInstanceFromIndicesCount(int instanceContainerIndex);
260 
262  virtual void updateInstancePositionOrientationAddedActual(const DtIndirectGeometryInstance& instance, int outInstanceIndex) override;
263 
265  virtual void updateInstanceSwitchesAddedActual(const DtIndirectGeometryInstance& instance, int outInstanceIndex) override;
266 
268  virtual void updateInstanceSequencesAddedActual(const DtIndirectGeometryInstance& instance, int outInstanceIndex) override;
269 
271  virtual void updateInstanceUvOffsetsAddedActual(const DtIndirectGeometryInstance& instance, int outInstanceIndex) override;
272 
274  virtual void updateInstanceColorAddedActual(const DtIndirectGeometryInstance& instance, int outInstanceIndex) override;
275 
277  virtual void updateInstanceOtherData0AddedActual(const DtIndirectGeometryInstance& instance, int outInstanceIndex) override;
278 
280  virtual void updateInstanceLightPointGroupIdActual(const DtIndirectGeometryInstance& instance, int outInstanceIndex) override;
281 
283  virtual void updateInstanceVisibilityLightPointMaxDistanceActual(const DtIndirectGeometryInstance& instance, int outInstanceIndex) override;
284 
286  virtual bool updateInstanceDeletionBeforeAddedActual(const DtIndirectGeometryInstance& instance) override;
287 
289  virtual void updateInstancesDofsAddedActual(const DtIndirectGeometryInstance& instance, int outInstanceIndex) override;
290 
292  virtual void updateInstanceModelIdAddedActual(const DtIndirectGeometryInstance& instance, int outInstanceIndex) override;
293 
295  virtual void setInstanceModelIdInInstanceContainer(int instanceId, int modelId);
296 
297  protected:
299  //typedef std::unordered_map<int, Matrix4_32> MapInstanceIdToXform;
301 
302  //Left the typedefs here commented out so they are easier to follow. They need to be at the
303  // top so they can be used as arguments in the functions.
304 
309  //typedef CloneMasterPair<osgSim::MultiSwitch> MultiSwitchPair;
310  //typedef std::map< osgSim::MultiSwitch*, MultiSwitchPair> MapCloneToMultiSwitchPair;
311  //typedef std::map< int, MapCloneToMultiSwitchPair> MapInstanceToMapCloneToMasterMultiSwitches;
313 
314  //Use the pair to hold the refs and the raw pointer to index into the map
317  //typedef CloneMasterPair<osgSim::DOFTransform> DofTransformPair;
318  //typedef std::unordered_map< osgSim::DOFTransform*, DofTransformPair > MapCloneToDofTransformPair;
319  //typedef std::unordered_map< int, MapCloneToDofTransformPair> MapInstanceToMapCloneToMasterDofs;
321 
322  //Use the pair to hold the refs and the raw pointer to index into the map
325  //typedef CloneMasterPair<osg::Sequence> SequencePair;
326  //typedef std::unordered_map< osg::Sequence*, SequencePair > MapCloneToSequencePair;
327  //typedef std::unordered_map< int, MapCloneToSequencePair> MapInstanceToMapCloneToMasterSequences;
329 
331  //typedef std::unordered_map< const std::string, DtIndirectUvOffsetManager::UvOffset> MapAnnotationToUvOffsetData;
332  //typedef std::unordered_map< int, MapAnnotationToUvOffsetData> MapInstanceToMapAnnotationToUvOffsetData;
334 
336  //typedef std::unordered_map< int, DtIndirectUvOffsetManager::UvOffset> MapInstanceToUvOffset;
338 
339  std::unordered_map< int, int > myMapInstanceInIndirectToModelId;
340 
342  std::unordered_map<int, Vector4_32> myMapInstanceToColor;
343 
345  std::unordered_map<int, Vector4_32> myMapInstanceToOtherData0;
346 
348  std::unordered_map<int, bool> myMapInstanceToVisibility;
349 
351  std::unordered_map<int, int> myMapInstanceToLightPointGroupId;
352 
354  std::unordered_map<int, float> myMapInstanceToLightPointMaxDistance;
355 
357  typedef std::unordered_set<int> SetInstancesToDelete;
359 
362 
364 
365  // Supporting texture variants is relatively new. If there are bugs,
366  // this can be changed to false, to debug whether texture variants support is the cause.
367  const bool mySupportInstanceModelChanges = true;
368  };
369 }
osg::ref_ptr< T > myMaster
Definition: DtIndirectEntityGeometry.h:52
tbb::concurrent_vector< InstanceUpdateStruct > InstanceUpdatesVector
Holds transform updates that are to be applied to instances.
Definition: DtIndirectEntityGeometry.h:115
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:92
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:51
std::unordered_set< int > SetInstancesToDelete
Structure to hold instance ids to be deleted.
Definition: DtIndirectEntityGeometry.h:357
std::unordered_map< int, MapCloneToSequencePair > MapInstanceToMapCloneToMasterSequences
Definition: DtIndirectEntityGeometry.h:86
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:328
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:77
osg::ref_ptr< T > myClone
Definition: DtIndirectEntityGeometry.h:58
#define DT_DLL_VRVOSG
Definition: vrvOsg.h:23
Definition: featureContext.h:37
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:320
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:70
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:89
std::unordered_map< osg::Sequence *, SequencePair > MapCloneToSequencePair
Definition: DtIndirectEntityGeometry.h:85
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:361
Variadic templated creator class for defining a DtVirtualBaseClass creator that is automatically regi...
Definition: DtVirtualBaseClassCreator.h:22
Inherited from DtIndirectGeometry additionally implements: -removal of instances -ability to set/get ...
Definition: DtIndirectEntityGeometry.h:40
std::unordered_map< int, int > myMapInstanceInIndirectToModelId
Definition: DtIndirectEntityGeometry.h:339
Struct to hold an instance ID and matrix transform Transforms are all calculated concurrently then st...
Definition: DtIndirectEntityGeometry.h:98
\ ::, 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:71
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:84
std::unordered_map< int, int > myMapInstanceToLightPointGroupId
Maps an instance id to the light point group id for that instance.
Definition: DtIndirectEntityGeometry.h:351
MapInstanceToMapCloneToMasterMultiSwitches myMapInstanceToMapCloneToMasterMultiSwitches
Structure to hold instance multi-switches&#39; state until the instance is actually added Use the pair to...
Definition: DtIndirectEntityGeometry.h:312
std::unordered_map< int, Matrix4_32 > MapInstanceIdToXform
Structure to hold instance orientation until the instance is actually added.
Definition: DtIndirectEntityGeometry.h:64
std::unordered_map< int, MapCloneToMultiSwitchPair > MapInstanceToMapCloneToMasterMultiSwitches
Definition: DtIndirectEntityGeometry.h:72
friend DtIndirectEntityGeometryCreator
only creator can create
Definition: DtIndirectEntityGeometry.h:44
osg::ref_ptr< T > myMaster
Definition: DtIndirectEntityGeometry.h:59
Contains DLL export macros.
MapInstanceIdToXform myMapInstanceIdToXform
Structure to hold instance orientation until the instance is actually added.
Definition: DtIndirectEntityGeometry.h:300
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:72
std::unordered_map< osgSim::DOFTransform *, DofTransformPair > MapCloneToDofTransformPair
Definition: DtIndirectEntityGeometry.h:78
std::unordered_map< int, Vector4_32 > myMapInstanceToOtherData0
Maps an instance id to the other data0 for that instance.
Definition: DtIndirectEntityGeometry.h:345
Matrix4_32 myXForm
Definition: DtIndirectEntityGeometry.h:101
MapInstanceToMapAnnotationToUvOffsetData myMapInstanceToMapAnnotationToUvOffsetData
Maps and instance id and a string to the current uv offset for this particular annotation.
Definition: DtIndirectEntityGeometry.h:333
std::unordered_map< int, bool > myMapInstanceToVisibility
Maps an instance id to the visibility for that instance.
Definition: DtIndirectEntityGeometry.h:348
std::atomic< int > myNumInProgressInstanceMoves
Definition: DtIndirectEntityGeometry.h:363
std::unordered_map< int, float > myMapInstanceToLightPointMaxDistance
Maps an instance id to the light point max distance for that instance.
Definition: DtIndirectEntityGeometry.h:354
MapInstanceToUvOffset myMapInstanceToUvOffset
Maps and instance id to the current uv offset for all scrollable uv offsets.
Definition: DtIndirectEntityGeometry.h:337
Contains the DtIndirectGeometry class declaration.
int myInstanceId
Definition: DtIndirectEntityGeometry.h:100
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:49
std::unordered_map< int, MapAnnotationToUvOffsetData > MapInstanceToMapAnnotationToUvOffsetData
Definition: DtIndirectEntityGeometry.h:90
std::unordered_map< int, MapCloneToDofTransformPair > MapInstanceToMapCloneToMasterDofs
Definition: DtIndirectEntityGeometry.h:79
std::unordered_map< int, Vector4_32 > myMapInstanceToColor
Maps an instance id to the color for that instance.
Definition: DtIndirectEntityGeometry.h:342
DtVirtualBaseClassCreator< DtIndirectEntityGeometry, const DtCullShaderConfig &, const bool & > DtIndirectEntityGeometryCreator
creator
Definition: DtIndirectEntityGeometry.h:20
SetInstancesToDelete mySetInstancesIndirectIdsToDelete
Definition: DtIndirectEntityGeometry.h:358

Document ID: Generated on Wed Mar 27 22:49:11 EDT 2024 from SVN revision 264633
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)