Atoms Crowd  7.0.0
AtomsClothCache.h
1 #pragma once
2 // ===========================================================================
3 // Copyright (c) 2015 Toolchefs Ltd. All rights reserved.
4 //
5 // Use of this software is subject to the terms of the Toolchefs license
6 // agreement provided at the time of installation or download, or which
7 // otherwise accompanies this software in either electronic or hard copy form.
8 // ===========================================================================
9 
10 
11 #include <Atoms/Globals.h>
12 #include <Atoms/AgentGroup.h>
13 
14 namespace Atoms
15 {
16  class ATOMS_EXPORT AtomsClothCache
17  {
18  public:
19 
22 
24  /*
25  \param cachePath cache folder path
26  \param cacheName cache name without .clothcache
27  */
28  AtomsClothCache(const std::string& cachePath, const std::string& cacheName);
29 
31  /*
32  \param cachePath cache folder path
33  \param cacheName cache name without .atoms
34  \param agents Agents ids, it loads only those agents form the cache
35  */
36  AtomsClothCache(const std::string& cachePath, const std::string& cacheName, const std::vector<int>& agents);
37 
40 
42 
44  bool openCache(const std::string& cachePath, const std::string& cacheName);
45 
47 
50  bool openCache(const std::string& cachePath, const std::string& cacheName, const std::vector<int>& agents);
51 
53  void loadTime(double time);
54 
56  void loadPrevFrame(int frame);
57 
59 
60  void loadFrame(int frame);
61 
63  void loadNextFrame(int frame);
64 
66  int startFrame() const;
67 
69  int endFrame() const;
70 
72  int currentFrame() const;
73 
75  int prevFrame() const;
76 
78  int nextFrame() const;
79 
81  AtomsPtr<AtomsCore::MapMetadata>& prevFrameData();
82 
84  AtomsPtr<AtomsCore::MapMetadata>& frameData();
85 
87  AtomsPtr<AtomsCore::MapMetadata>& nextFrameData();
88 
90 
94  void loadBoundingBox(double time, AtomsCore::Box3& box) const;
95 
97 
102  void loadAgentClothBoundingBox(double time, unsigned int agentId, AtomsCore::Box3& box) const;
103 
105 
111  void loadAgentClothMeshBoundingBox(double time, unsigned int agentId, const std::string& meshName, AtomsCore::Box3& box) const;
112 
114 
121  void loadAgentClothMesh(double time,
122  unsigned int agentId,
123  const std::string& meshName,
124  std::vector<AtomsCore::Vector3>& points,
125  std::vector<AtomsCore::Vector3>& normals
126  ) const;
127 
129 
134  std::string getAgentClothMeshStackOrder(double time,
135  unsigned int agentId,
136  const std::string& meshName
137  ) const;
138 
140 
145  bool hasAgentClothMesh(double time, unsigned int agentId, const std::string& meshName) const;
146 
148  void clear();
149 
151  static void processPoints(std::vector<AtomsCore::Vector3>& outPoints, std::vector<const std::vector<AtomsCore::Vector3>*> &inPoints, const std::vector<double> &inputWeightVector);
152 
153  static void processNormals(std::vector<AtomsCore::Vector3>& outNormals, std::vector<const std::vector<AtomsCore::Vector3>*> &inNormals, const std::vector<double> &inputWeightVector);
154 
156  std::vector<int> agentIds(double time) const;
157 
159  std::vector<std::string> agentClothMeshNames(double time, unsigned int agentId) const;
160 
162  size_t numAgents(double time) const;
163 
164  void setAgentsToLoad(const std::vector<int>& agents);
165 
166  const std::string& cacheName() const;
167 
168  const std::string& cachePath() const;
169 
170  private:
171 
172  int clampFrame(int frame) const;
173 
175  void readData(AtomsPtr<AtomsCore::MapMetadata>& data, int frame, int& m_currentFrame);
176 
177  void readDataKeys(AtomsPtr<AtomsCore::MapMetadata>& data, int frame, std::vector<std::string>& keys, int& m_currentFrame);
178 
179  private:
180 
182  AtomsCore::MapMetadata m_header;
183 
185  AtomsPtr<AtomsCore::MapMetadata> m_prevFrameData;
186 
188  AtomsPtr<AtomsCore::MapMetadata> m_currentFrameData;
189 
191  AtomsPtr<AtomsCore::MapMetadata> m_nextFrameData;
192 
193  std::vector<std::string> m_agentIdsToLoad;
194 
196  std::string m_cachePath;
197 
199  std::string m_cacheName;
200 
202  int m_startFrame;
203 
205  int m_endFrame;
206 
208  int m_prevFrame;
209 
211  int m_currentFrame;
212 
214  int m_nextFrame;
215  };
216 }
Definition: AtomsClothCache.h:17
AtomsClothCache(const std::string &cachePath, const std::string &cacheName, const std::vector< int > &agents)
Constructor.
AtomsPtr< AtomsCore::MapMetadata > & nextFrameData()
Get the next frame data.
int prevFrame() const
Get the previous frame.
void loadAgentClothMeshBoundingBox(double time, unsigned int agentId, const std::string &meshName, AtomsCore::Box3 &box) const
Loads an agent bbox.
bool openCache(const std::string &cachePath, const std::string &cacheName)
Opens a cache.
std::vector< int > agentIds(double time) const
Gets agent ids.
void loadFrame(int frame)
Loads a cache frame and stores the current frame data.
int endFrame() const
Get the end frame.
static void processPoints(std::vector< AtomsCore::Vector3 > &outPoints, std::vector< const std::vector< AtomsCore::Vector3 > * > &inPoints, const std::vector< double > &inputWeightVector)
Blends multiple mapmetadata.
void loadNextFrame(int frame)
Loads a cache frame and stores the next frame data (usually used for the next frame during the motion...
bool hasAgentClothMesh(double time, unsigned int agentId, const std::string &meshName) const
Check if a mesh for an egent exist inside the cache.
std::string getAgentClothMeshStackOrder(double time, unsigned int agentId, const std::string &meshName) const
Get cloth mesh stack order.
~AtomsClothCache()
Destructor.
int currentFrame() const
Get the current frame.
void loadBoundingBox(double time, AtomsCore::Box3 &box) const
Loads bbox.
AtomsClothCache(const std::string &cachePath, const std::string &cacheName)
Constructor.
int nextFrame() const
Get the next frame.
bool openCache(const std::string &cachePath, const std::string &cacheName, const std::vector< int > &agents)
Opens a cache.
void loadAgentClothMesh(double time, unsigned int agentId, const std::string &meshName, std::vector< AtomsCore::Vector3 > &points, std::vector< AtomsCore::Vector3 > &normals) const
Loads all data for an agent.
AtomsClothCache()
Constructor.
int startFrame() const
Get the start frame.
void clear()
Clear all the loaded frames.
AtomsPtr< AtomsCore::MapMetadata > & prevFrameData()
Get the previous frame data.
std::vector< std::string > agentClothMeshNames(double time, unsigned int agentId) const
Gets agent cloth mesh names.
void loadTime(double time)
Loads the pre/next and current frame given the input time.
void loadPrevFrame(int frame)
Loads a cache frame and store in the previous frame (usually used for the previous frame during the m...
size_t numAgents(double time) const
Gets the number of agents created.
void loadAgentClothBoundingBox(double time, unsigned int agentId, AtomsCore::Box3 &box) const
Loads an agent bbox.
AtomsPtr< AtomsCore::MapMetadata > & frameData()
Get the current frame data.
MapMetadata class.
Definition: MapMetadata.h:24
AtomsMath::Box3 Box3
Bounding box class.
Definition: AtomsMath.h:74
Atoms namespace.
Definition: Agent.h:29