TDME2  1.9.200
Tools.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <array>
4 #include <string>
5 #include <vector>
6 
7 #include <tdme/tdme.h>
9 #include <tdme/engine/fwd-tdme.h>
13 #include <tdme/math/fwd-tdme.h>
15 
16 using std::array;
17 using std::string;
18 using std::vector;
19 
31 
32 /**
33  * Editor tools
34  * @author Andreas Drewke
35  */
37 {
38 private:
46 
47  struct ToolsShutdown {
49  };
50 
52 
53 public:
54  /**
55  * Formats a float to a human readable format
56  * @param value value
57  * @return value as string
58  */
59  static string formatFloat(float value);
60 
61  /**
62  * Set up given engine light with default light
63  * @param light light
64  */
65  static void setDefaultLight(Light* light);
66 
67  /**
68  * Init off screen engine for making thumbails
69  */
70  static void oseInit();
71 
72  /**
73  * Dispose off screen engine
74  */
75  static void oseDispose();
76 
77  /**
78  * Make a thumbnail of given prototype with off screen engine
79  * @param prototype prototype
80  * @param pngData PNG data
81  */
82  static void oseThumbnail(Prototype* prototype, vector<uint8_t>& pngData);
83 
84  /**
85  * Compute max axis dimension for given bounding box
86  * @param boundingBox bounding box
87  * @return max axis dimension
88  */
89  static float computeMaxAxisDimension(BoundingBox* boundingBox);
90 
91  /**
92  * Creates ground plate with 1m x 1m texture
93  * @param width width
94  * @param depth depth
95  * @param y float y
96  * @return ground model
97  */
98  static Model* createGroundModel(float width, float depth, float y);
99 
100  /**
101  * Creates grid plate with 1m x 1m texture
102  * @return grid model
103  */
104  static Model* createGridModel();
105 
106  /**
107  * Set up entity in given engine with look from rotations and scale
108  * @param prototype prototype
109  * @param engine engine
110  * @param lookFromRotations look from rotations
111  * @param lodLevel lod level
112  * @param cameraRotationInputHandler camera rotation input handler
113  * @param resetup resetup which would mean to leave camera and lighting as is
114  */
115  static void setupPrototype(Prototype* prototype, Engine* engine, const Transform& lookFromRotations, int lodLevel, Vector3& objectScale, CameraRotationInputHandler* cameraRotationInputHandler = nullptr, float scale = 1.5f, bool resetup = false);
116 
117  /**
118  * Get relative resources file name
119  * @param applicationRoot application root
120  * @param fileName file name
121  * @return relative resources file name
122  */
123  static const string getRelativeResourcesFileName(const string& applicationRoot, const string& fileName);
124 
125  /**
126  * Get application root path name
127  * @param fileName file name
128  * @return application root path name
129  */
130  static const string getApplicationRootPathName(const string& fileName);
131 
132  /**
133  * Get application sub path name
134  * @param fileName application sub path name
135  * @return application sub path name
136  */
137  static const string getApplicationSubPathName(const string& fileName);
138 
139  /**
140  * Get path of given file name
141  * @param fileName file name
142  * @return path
143  */
144  static const string getPathName(const string& fileName);
145 
146  /**
147  * Get file name of given file name
148  * @param fileName file name
149  * @return file name
150  */
151  static const string getFileName(const string& fileName);
152 
153  /**
154  * Remove file extension, e.g. .dae, .fbx, ...
155  * @param fileName file name
156  * @return file name
157  */
158  static const string removeFileExtension(const string& fileName);
159 
160  /**
161  * Ensure file extension
162  * @param fileName file name
163  * @param extension extension
164  * @return file name
165  */
166  static const string ensureFileExtension(const string& fileName, const string& extension);
167 
168  /**
169  * Get file extension
170  * @param fileName file name
171  * @return file extension
172  */
173  static const string getFileExtension(const string& fileName);
174 
175  /**
176  * Load settings
177  * @param application application
178  */
179  static void loadSettings(Application* application);
180 
181  /**
182  * @return GIZMO translation/rotations/scale
183  */
184  static Model* getGizmoAll();
185 
186  /**
187  * @return GIZMO translation/rotations/scale
188  */
190 
191  /**
192  * @return GIZMO for translation
193  */
194  static Model* getGizmoTranslation();
195 
196  /**
197  * @return GIZMO for scale
198  */
199  static Model* getGizmoScale();
200 
201  /**
202  * @return GIZMO for rotations
203  */
204  static Model* getGizmoRotations();
205 
206  /**
207  * @return default obb
208  */
209  static Model* getDefaultObb();
210 
211  /**
212  * Returns if file extension of given file name does match a extension in given extensions
213  * @param fileName file name
214  * @param extensions extensions
215  * @return success
216  */
217  static bool hasFileExtension(const string& fileName, const vector<string>& extensions);
218 
219  /**
220  * Enumerate file extensions
221  * @param extensions extensions
222  * @return file extensions as human readable string
223  */
224  inline static const string enumerateFileExtensions(const vector<string>& extensions) {
225  string result;
226  for (const auto& extension: extensions) {
227  if (result.empty() == false) result+= ", ";
228  result+= "*." + extension;
229  }
230  return result;
231  }
232 
233 };
Application base class, please make sure to allocate application on heap to have correct application ...
Definition: Application.h:41
Color 4 definition class.
Definition: Color4.h:18
Engine main class.
Definition: Engine.h:131
Light representation.
Definition: Light.h:33
Transform which contain scale, rotations and translation.
Definition: Transform.h:29
Representation of a 3D model.
Definition: Model.h:35
Axis aligned bounding box used for frustum, this is not directly connectable with physics engine.
Definition: BoundingBox.h:26
Prototype definition.
Definition: Prototype.h:55
Vector3 class representing vector3 mathematical structure and operations with x, y,...
Definition: Vector3.h:20
Vector4 class representing vector4 mathematical structure and operations with x, y,...
Definition: Vector4.h:22
static const string getApplicationRootPathName(const string &fileName)
Get application root path name.
Definition: Tools.cpp:498
static STATIC_DLL_IMPEXT Model * gizmoTranslation
Definition: Tools.h:42
static STATIC_DLL_IMPEXT Model * defaultOBB
Definition: Tools.h:45
static bool hasFileExtension(const string &fileName, const vector< string > &extensions)
Returns if file extension of given file name does match a extension in given extensions.
Definition: Tools.cpp:675
static const string removeFileExtension(const string &fileName)
Remove file extension, e.g.
Definition: Tools.cpp:554
static STATIC_DLL_IMPEXT Model * gizmoRotations
Definition: Tools.h:44
static STATIC_DLL_IMPEXT Model * gizmoTranslationScale
Definition: Tools.h:41
static Model * getGizmoTranslation()
Definition: Tools.cpp:626
static void oseInit()
Init off screen engine for making thumbails.
Definition: Tools.cpp:147
static void setDefaultLight(Light *light)
Set up given engine light with default light.
Definition: Tools.cpp:132
static Model * getGizmoTranslationScale()
Definition: Tools.cpp:616
static Model * getGizmoScale()
Definition: Tools.cpp:636
static STATIC_DLL_IMPEXT Model * gizmoScale
Definition: Tools.h:43
static const string enumerateFileExtensions(const vector< string > &extensions)
Enumerate file extensions.
Definition: Tools.h:224
static Model * createGroundModel(float width, float depth, float y)
Creates ground plate with 1m x 1m texture.
Definition: Tools.cpp:193
static void loadSettings(Application *application)
Load settings.
Definition: Tools.cpp:583
static STATIC_DLL_IMPEXT Model * gizmoAll
Definition: Tools.h:40
static const string getFileExtension(const string &fileName)
Get file extension.
Definition: Tools.cpp:573
static STATIC_DLL_IMPEXT Engine * osEngine
Definition: Tools.h:39
static const string getFileName(const string &fileName)
Get file name of given file name.
Definition: Tools.cpp:549
static STATIC_DLL_IMPEXT ToolsShutdown toolsShutdown
Definition: Tools.h:51
static void setupPrototype(Prototype *prototype, Engine *engine, const Transform &lookFromRotations, int lodLevel, Vector3 &objectScale, CameraRotationInputHandler *cameraRotationInputHandler=nullptr, float scale=1.5f, bool resetup=false)
Set up entity in given engine with look from rotations and scale.
Definition: Tools.cpp:295
static string formatFloat(float value)
Formats a float to a human readable format.
Definition: Tools.cpp:125
static const string getRelativeResourcesFileName(const string &applicationRoot, const string &fileName)
Get relative resources file name.
Definition: Tools.cpp:479
static float computeMaxAxisDimension(BoundingBox *boundingBox)
Compute max axis dimension for given bounding box.
Definition: Tools.cpp:183
static Model * createGridModel()
Creates grid plate with 1m x 1m texture.
Definition: Tools.cpp:240
static void oseThumbnail(Prototype *prototype, vector< uint8_t > &pngData)
Make a thumbnail of given prototype with off screen engine.
Definition: Tools.cpp:162
static void oseDispose()
Dispose off screen engine.
Definition: Tools.cpp:155
static Model * getGizmoRotations()
Definition: Tools.cpp:646
static const string ensureFileExtension(const string &fileName, const string &extension)
Ensure file extension.
Definition: Tools.cpp:564
static const string getPathName(const string &fileName)
Get path of given file name.
Definition: Tools.cpp:544
static Model * getGizmoAll()
Definition: Tools.cpp:606
static Model * getDefaultObb()
Definition: Tools.cpp:656
static const string getApplicationSubPathName(const string &fileName)
Get application sub path name.
Definition: Tools.cpp:515
#define STATIC_DLL_IMPEXT
Definition: tdme.h:15