BsEditorUtility.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsEditorPrerequisites.h"
  5. #include "Math/BsAABox.h"
  6. namespace bs
  7. {
  8. /** @addtogroup Utility-Editor
  9. * @{
  10. */
  11. /** Possible type of platform file dialogs. */
  12. enum class FileDialogType
  13. {
  14. OpenFile = 0x0,
  15. OpenFolder = 0x1,
  16. Save = 0x2,
  17. Multiselect = 0x10000,
  18. TypeMask = 0xFFFF
  19. };
  20. /** Contains miscellaneous helper methods. */
  21. class BS_ED_EXPORT EditorUtility
  22. {
  23. public:
  24. /**
  25. * Contains stored information about stored scene object instance data, including all of its children and
  26. * components.
  27. *
  28. * @note
  29. * When object is serialized it will receive new instance data (as if it was a new object). But we want to restore
  30. * the original object completely (including any references other objects might have to it) so we need store the
  31. * instance data.
  32. */
  33. struct SceneObjProxy
  34. {
  35. GameObjectInstanceDataPtr instanceData;
  36. Vector<GameObjectInstanceDataPtr> componentInstanceData;
  37. Vector<SceneObjProxy> children;
  38. };
  39. /**
  40. * Calculates world space bounds of the specified scene object. This will consider components with bounds like
  41. * Renderable.
  42. */
  43. static AABox calculateBounds(const HSceneObject& object);
  44. /**
  45. * Calculates world space bounds of the specified scene objects. This will consider components with bounds like
  46. * Renderable.
  47. */
  48. static AABox calculateBounds(const Vector<HSceneObject>& objects);
  49. /** Calculates world space center of the specified scene objects. */
  50. static Vector3 calculateCenter(const Vector<HSceneObject>& objects);
  51. /**
  52. * Parses the scene object hierarchy and components and generates a hierarchy of instance data required to restore
  53. * the object identities.
  54. */
  55. static SceneObjProxy createProxy(const HSceneObject& sceneObject);
  56. /**
  57. * Restores original object instance data from the provided scene object proxy that was previously generated using
  58. * createProxy().
  59. *
  60. * @param[in] restored New instance of the object.
  61. * @param[in] proxy Proxy data containing the original object instance data we want to restore.
  62. */
  63. static void restoreIds(const HSceneObject& restored, SceneObjProxy& proxy);
  64. /**
  65. * Displays a platform specific file/folder open/save dialog.
  66. *
  67. * @param[in] type Type of dialog to open.
  68. * @param[in] defaultPath Initial path the dialog will be set to once opened.
  69. * @param[in] filterList Semi-colon separated list of file names or types to display in the dialog,
  70. * for example "*.exe;*.txt;*.png". Ignored if dialog is to display folders instead of
  71. * files.
  72. * @param[out] paths Output list of selected file or folder paths (if any).
  73. * @return True if file was selected and false if selection was canceled.
  74. */
  75. static bool openBrowseDialog(FileDialogType type, const Path& defaultPath, const String& filterList,
  76. Vector<Path>& paths);
  77. private:
  78. /**
  79. * Retrieves all components containing meshes on the specified object and outputs their bounds.
  80. *
  81. * @param[in] object Object to calculate bounds for.
  82. * @param[in] bounds Output bounds, if successful.
  83. * @return True if a mesh component was found, otherwise false (bounds will not be updated).
  84. */
  85. static bool calculateMeshBounds(const HSceneObject& object, AABox& bounds);
  86. };
  87. /** @} */
  88. }