Atoms Crowd  7.0.0
AtomsScriptUtils.h
1 #pragma once
2 #include <Atoms/Globals.h>
3 #include <AtomsUtils/AtomsMath.h>
4 #include <ToolchefsSTL/String.h>
5 #include <ToolchefsSTL/Containers/Array.h>
6 #include <ToolchefsSTL/Containers/Map.h>
7 #include <ToolchefsSTL/Containers/List.h>
8 #include <ToolchefsSTL/Containers/Set.h>
9 #include <cmath>
10 #include <cstdlib>
11 
12 #ifdef ATOMS_UNREAL
13 #else
14 //#include <Iex.h>
15 #endif
16 #include <AtomsMath/ImathExport.h>
17 #include <AtomsMath/ImathConfig.h>
18 #include <AtomsMath/ImathVec.h>
19 #include <AtomsMath/ImathVecAlgo.h>
20 #include <AtomsMath/ImathMatrix.h>
21 #include <AtomsMath/ImathMatrixAlgo.h>
22 #include <AtomsMath/ImathQuat.h>
23 #include <AtomsMath/ImathEuler.h>
24 #include <AtomsMath/ImathBox.h>
25 #include <AtomsMath/ImathColor.h>
26 #include <AtomsMath/ImathLine.h>
27 #include <AtomsMath/ImathSphere.h>
28 #include <AtomsMath/ImathRandom.h>
29 #include <AtomsMath/ImathBoxAlgo.h>
30 
31 namespace AtomsScriptUtils
32 {
33  using Vector2 = ATOMSMATH_NAMESPACE::V2d;
34  using Vector2f = ATOMSMATH_NAMESPACE::V2f;
35  using Vector2i = ATOMSMATH_NAMESPACE::V2i;
36  using Vector3 = ATOMSMATH_NAMESPACE::V3d;
37  using Vector3f = ATOMSMATH_NAMESPACE::V3f;
38  using Vector3i = ATOMSMATH_NAMESPACE::V3i;
39  using Vector4 = ATOMSMATH_NAMESPACE::V4d;
40  using Vector4f = ATOMSMATH_NAMESPACE::V4f;
41  using Vector4i = ATOMSMATH_NAMESPACE::V4i;
42  using Matrix = ATOMSMATH_NAMESPACE::M44d;
43  using Matrixf = ATOMSMATH_NAMESPACE::M44f;
44  using Matrix33 = ATOMSMATH_NAMESPACE::M33d;
45  using Matrix33f = ATOMSMATH_NAMESPACE::M33f;
46  using Quaternion = ATOMSMATH_NAMESPACE::Quatd;
47  using Quaternionf = ATOMSMATH_NAMESPACE::Quatf;
48  using Euler = ATOMSMATH_NAMESPACE::Eulerd;
49  using Eulerf = ATOMSMATH_NAMESPACE::Eulerf;
50  using Box2 = ATOMSMATH_NAMESPACE::Box2d;
51  using Box2f = ATOMSMATH_NAMESPACE::Box2f;
52  using Box2i = ATOMSMATH_NAMESPACE::Box2i;
53  using Box3 = ATOMSMATH_NAMESPACE::Box3d;
54  using Box3f = ATOMSMATH_NAMESPACE::Box3f;
55  using Box3i = ATOMSMATH_NAMESPACE::Box3i;
56  using Color3c = ATOMSMATH_NAMESPACE::Color3c;
57  using Color3f = ATOMSMATH_NAMESPACE::Color3f;
58  using Color4c = ATOMSMATH_NAMESPACE::Color4c;
59  using Color4f = ATOMSMATH_NAMESPACE::Color4f;
60  using Line3 = ATOMSMATH_NAMESPACE::Line3d;
61  using Line3f = ATOMSMATH_NAMESPACE::Line3f;
62  using Line2 = ATOMSMATH_NAMESPACE::Line2d;
63  using Line2f = ATOMSMATH_NAMESPACE::Line2f;
64  using Sphere3 = ATOMSMATH_NAMESPACE::Sphere3d;
65  using Sphere3f = ATOMSMATH_NAMESPACE::Sphere3f;
66  using Rand32 = ATOMSMATH_NAMESPACE::Rand32;
67  using Rand48 = ATOMSMATH_NAMESPACE::Rand48;
68 }
69 
70 namespace Atoms
71 {
72  class Agent;
73  class AgentGroup;
74  class AgentType;
75 }
76 
77 namespace AtomsScriptUtils
78 {
79 
80  ATOMS_EXPORT void info(const ToolchefsSTL::String& message);
81 
82  ATOMS_EXPORT void warning(const ToolchefsSTL::String& message);
83 
84  ATOMS_EXPORT void error(const ToolchefsSTL::String& message);
85 
86  ATOMS_EXPORT void info(const char* format, ...);
87 
88  ATOMS_EXPORT void warning(const char* format, ...);
89 
90  ATOMS_EXPORT void error(const char* format, ...);
91 
92  class ATOMS_EXPORT AgentTypeWrapper
93  {
94  public:
95  AgentTypeWrapper(const class Atoms::AgentType* aType);
96 
97  ToolchefsSTL::String name() const;
98 
99  int numJoints() const;
100 
101  int getJointId(const ToolchefsSTL::String& jointName) const;
102 
103  ToolchefsSTL::String getJointName(int jointId) const;
104 
105  int getJointParent(int jointId) const;
106 
107  ToolchefsSTL::Array<int> getChildren(int jointId) const;
108 
109  AtomsMath::Matrix getJointMatrix(int jointId) const;
110 
111  AtomsMath::Matrix getJointWorldMatrix(int jointId) const;
112 
113  AtomsMath::Vector3 getJointTranslation(int jointId) const;
114 
115  AtomsMath::Quaternion getJointRotation(int jointId) const;
116 
117  AtomsMath::Vector3 getJointScale(int jointId) const;
118 
119  private:
120 
121  const class Atoms::AgentType* m_ptr;
122  };
123 
124  class ATOMS_EXPORT AgentWrapper
125  {
126  public:
127 
128  AgentWrapper(class Atoms::Agent*);
129 
130  public:
131 
132  bool hasMetadata(const ToolchefsSTL::String& name) const;
133 
134  // Metadata
135  void setIntMetadata(const ToolchefsSTL::String& name, const int value);
136  void setBoolMetadata(const ToolchefsSTL::String& name, const bool value);
137  void setDoubleMetadata(const ToolchefsSTL::String& name, const double value);
138  void setStringMetadata(const ToolchefsSTL::String& name, const ToolchefsSTL::String& value);
139  void setVector2Metadata(const ToolchefsSTL::String& name, const AtomsMath::Vector2& value);
140  void setVector3Metadata(const ToolchefsSTL::String& name, const AtomsMath::Vector3& value);
141  void setVector4Metadata(const ToolchefsSTL::String& name, const AtomsMath::Vector4& value);
142  void setMatrixMetadata(const ToolchefsSTL::String& name, const AtomsMath::Matrix& value);
143  void setQuaternionMetadata(const ToolchefsSTL::String& name, const AtomsMath::Quaternion& value);
144  void setEulerMetadata(const ToolchefsSTL::String& name, const AtomsMath::Euler& value);
145 
146  int getIntMetadata(const ToolchefsSTL::String& name) const;
147  bool getBoolMetadata(const ToolchefsSTL::String& name) const;
148  double getDoubleMetadata(const ToolchefsSTL::String& name, const double value) const;
149  ToolchefsSTL::String getStringMetadata(const ToolchefsSTL::String& name) const;
150  AtomsMath::Vector2 getVector2Metadata(const ToolchefsSTL::String& name) const;
151  AtomsMath::Vector3 getVector3Metadata(const ToolchefsSTL::String& name) const;
152  AtomsMath::Vector4 getVector4Metadata(const ToolchefsSTL::String& name) const;
153  AtomsMath::Matrix getMatrixMetadata(const ToolchefsSTL::String& name) const;
154  AtomsMath::Quaternion getQuaternionMetadata(const ToolchefsSTL::String& name) const;
155  AtomsMath::Euler getEulerMetadata(const ToolchefsSTL::String& name) const;
156 
157  // Pose metadata
158  bool hasPoseMetadata(const ToolchefsSTL::String& name) const;
159  void setPoseIntMetadata(const ToolchefsSTL::String& name, const int value);
160  void setPoseBoolMetadata(const ToolchefsSTL::String& name, const bool value);
161  void setPoseDoubleMetadata(const ToolchefsSTL::String& name, const double value);
162  void setPoseStringMetadata(const ToolchefsSTL::String& name, const ToolchefsSTL::String& value);
163  void setPoseVector2Metadata(const ToolchefsSTL::String& name, const AtomsMath::Vector2& value);
164  void setPoseVector3Metadata(const ToolchefsSTL::String& name, const AtomsMath::Vector3& value);
165  void setPoseVector4Metadata(const ToolchefsSTL::String& name, const AtomsMath::Vector4& value);
166  void setPoseMatrixMetadata(const ToolchefsSTL::String& name, const AtomsMath::Matrix& value);
167  void setPoseQuaternionMetadata(const ToolchefsSTL::String& name, const AtomsMath::Quaternion& value);
168  void setPoseEulerMetadata(const ToolchefsSTL::String& name, const AtomsMath::Euler& value);
169 
170  int getPoseIntMetadata(const ToolchefsSTL::String& name) const;
171  bool getPoseBoolMetadata(const ToolchefsSTL::String& name) const;
172  double getPoseDoubleMetadata(const ToolchefsSTL::String& name, const double value) const;
173  ToolchefsSTL::String getPoseStringMetadata(const ToolchefsSTL::String& name) const;
174  AtomsMath::Vector2 getPoseVector2Metadata(const ToolchefsSTL::String& name) const;
175  AtomsMath::Vector3 getPoseVector3Metadata(const ToolchefsSTL::String& name) const;
176  AtomsMath::Vector4 getPoseVector4Metadata(const ToolchefsSTL::String& name) const;
177  AtomsMath::Matrix getPoseMatrixMetadata(const ToolchefsSTL::String& name) const;
178  AtomsMath::Quaternion getPoseQuaternionMetadata(const ToolchefsSTL::String& name) const;
179  AtomsMath::Euler getPoseEulerMetadata(const ToolchefsSTL::String& name) const;
180 
181 
182  // joint pose metadata
183 
184  bool hasJointPoseMetadata(const ToolchefsSTL::String& name, int jointId) const;
185  void setJointPoseIntMetadata(const ToolchefsSTL::String& name, const int value, int jointId);
186  void setJointPoseBoolMetadata(const ToolchefsSTL::String& name, const bool value, int jointId);
187  void setJointPoseDoubleMetadata(const ToolchefsSTL::String& name, const double value, int jointId);
188  void setJointPoseStringMetadata(const ToolchefsSTL::String& name, const ToolchefsSTL::String& value, int jointId);
189  void setJointPoseVector2Metadata(const ToolchefsSTL::String& name, const AtomsMath::Vector2& value, int jointId);
190  void setJointPoseVector3Metadata(const ToolchefsSTL::String& name, const AtomsMath::Vector3& value, int jointId);
191  void setJointPoseVector4Metadata(const ToolchefsSTL::String& name, const AtomsMath::Vector4& value, int jointId);
192  void setJointPoseMatrixMetadata(const ToolchefsSTL::String& name, const AtomsMath::Matrix& value, int jointId);
193  void setJointPoseQuaternionMetadata(const ToolchefsSTL::String& name, const AtomsMath::Quaternion& value, int jointId);
194  void setJointPoseEulerMetadata(const ToolchefsSTL::String& name, const AtomsMath::Euler& value, int jointId);
195 
196  int getJointPoseIntMetadata(const ToolchefsSTL::String& name, int jointId) const;
197  bool getJointPoseBoolMetadata(const ToolchefsSTL::String& name, int jointId) const;
198  double getJointPoseDoubleMetadata(const ToolchefsSTL::String& name, const double value, int jointId) const;
199  ToolchefsSTL::String getJointPoseStringMetadata(const ToolchefsSTL::String& name, int jointId) const;
200  AtomsMath::Vector2 getJointPoseVector2Metadata(const ToolchefsSTL::String& name, int jointId) const;
201  AtomsMath::Vector3 getJointPoseVector3Metadata(const ToolchefsSTL::String& name, int jointId) const;
202  AtomsMath::Vector4 getJointPoseVector4Metadata(const ToolchefsSTL::String& name, int jointId) const;
203  AtomsMath::Matrix getJointPoseMatrixMetadata(const ToolchefsSTL::String& name, int jointId) const;
204  AtomsMath::Quaternion getJointPoseQuaternionMetadata(const ToolchefsSTL::String& name, int jointId) const;
205  AtomsMath::Euler getJointPoseEulerMetadata(const ToolchefsSTL::String& name, int jointId) const;
206 
207  // joint transform
208  void setJointMatrix(int jointId, const AtomsMath::Matrix& value);
209  void setJointWorldMatrix(int jointId, const AtomsMath::Matrix& value);
210  void setJointTranslation(int jointId, const AtomsMath::Vector3& value);
211  void setJointRotation(int jointId, const AtomsMath::Quaternion& value);
212  void setJointScale(int jointId, const AtomsMath::Vector3& value);
213 
214  AtomsMath::Matrix getJointMatrix(int jointId) const;
215  AtomsMath::Matrix getJointWorldMatrix(int jointId) const;
216  AtomsMath::Vector3 getJointTranslation(int jointId) const;
217  AtomsMath::Quaternion getJointRotation(int jointId) const;
218  AtomsMath::Vector3 getJointScale(int jointId) const;
219 
220  AgentTypeWrapper agentType() const;
221 
222  inline bool isValid() { return m_ptr != nullptr; }
223 
224  inline operator bool() { return m_ptr != nullptr; }
225 
226  public:
227 
228  AtomsMath::Vector3& position;
229 
230  AtomsMath::Vector3& direction;
231 
232  AtomsMath::Vector3& up;
233 
234  AtomsMath::Vector3& scale;
235 
236  const int& groupId;
237 
238  const int& id;
239 
240  int& state;
241 
242  double& frameRate;
243 
244  double& birth;
245 
246 
247  private:
248 
249  class Atoms::Agent* m_ptr;
250 
251  int m_defaultState;
252 
253  double m_defaultFrameRate;
254 
255  AtomsMath::Vector3 m_defaultVec;
256 
257  };
258 
259  class ATOMS_EXPORT AgentGroupWrapper
260  {
261  public:
263 
264  public:
265 
266  double time() const;
267 
268  double seconds() const;
269 
270  ToolchefsSTL::Array<AgentWrapper> agents() const;
271 
272  AgentWrapper agent(int groupId) const;
273 
274  ToolchefsSTL::Array<AgentWrapper> findAgentsInRange(const AtomsMath::Vector3& position, const double radius) const;
275 
276  AgentWrapper findClosestAgent(const AtomsMath::Vector3& position, double radius=AtomsMath::numeric_limits<float>::max()) const;
277 
278  private:
279 
280  class Atoms::AgentGroup* m_ptr;
281  };
282 
283 }
Agent group.
Definition: AgentGroup.h:36
Agent.
Definition: Agent.h:44
Agent type.
Definition: AgentType.h:30
Definition: AtomsMath.h:196
Definition: AtomsScriptUtils.h:260
Definition: AtomsScriptUtils.h:93
Definition: AtomsScriptUtils.h:125
Definition: ImathBox.h:36
Definition: ImathColor.h:29
Definition: ImathColor.h:115
Definition: ImathEuler.h:118
Definition: ImathLine.h:180
Definition: ImathLine.h:25
Definition: ImathMatrix.h:305
Definition: ImathRandom.h:33
Definition: ImathRandom.h:64
Definition: ImathSphere.h:25
Definition: Array.h:10
Definition: String.h:19
Atoms namespace.
Definition: Agent.h:29