BsEditorUtility.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 "BsAABox.h"
  6. namespace bs
  7. {
  8. /** @addtogroup Utility-Editor
  9. * @{
  10. */
  11. /** Contains miscellaneous helper methods. */
  12. class BS_ED_EXPORT EditorUtility
  13. {
  14. public:
  15. /**
  16. * Contains stored information about stored scene object instance data, including all of its children and
  17. * components.
  18. *
  19. * @note
  20. * When object is serialized it will receive new instance data (as if it was a new object). But we want to restore
  21. * the original object completely (including any references other objects might have to it) so we need store the
  22. * instance data.
  23. */
  24. struct SceneObjProxy
  25. {
  26. GameObjectInstanceDataPtr instanceData;
  27. Vector<GameObjectInstanceDataPtr> componentInstanceData;
  28. Vector<SceneObjProxy> children;
  29. };
  30. /**
  31. * Calculates world space bounds of the specified scene object. This will consider components with bounds like
  32. * Renderable.
  33. */
  34. static AABox calculateBounds(const HSceneObject& object);
  35. /**
  36. * Calculates world space bounds of the specified scene objects. This will consider components with bounds like
  37. * Renderable.
  38. */
  39. static AABox calculateBounds(const Vector<HSceneObject>& objects);
  40. /** Calculates world space center of the specified scene objects. */
  41. static Vector3 calculateCenter(const Vector<HSceneObject>& objects);
  42. /**
  43. * Parses the scene object hierarchy and components and generates a hierarchy of instance data required to restore
  44. * the object identities.
  45. */
  46. static SceneObjProxy createProxy(const HSceneObject& sceneObject);
  47. /**
  48. * Restores original object instance data from the provided scene object proxy that was previously generated using
  49. * createProxy().
  50. *
  51. * @param[in] restored New instance of the object.
  52. * @param[in] proxy Proxy data containing the original object instance data we want to restore.
  53. */
  54. static void restoreIds(const HSceneObject& restored, SceneObjProxy& proxy);
  55. private:
  56. /**
  57. * Retrieves all components containing meshes on the specified object and outputs their bounds.
  58. *
  59. * @param[in] object Object to calculate bounds for.
  60. * @param[in] bounds Output bounds, if successful.
  61. * @return True if a mesh component was found, otherwise false (bounds will not be updated).
  62. */
  63. static bool calculateMeshBounds(const HSceneObject& object, AABox& bounds);
  64. };
  65. /** @} */
  66. }