ModelPacker.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #pragma once
  2. #include <Atomic/Graphics/IndexBuffer.h>
  3. #include <Atomic/Graphics/VertexBuffer.h>
  4. #include <Atomic/Graphics/Geometry.h>
  5. #include <Atomic/Graphics/Model.h>
  6. using namespace Atomic;
  7. namespace AtomicGlow
  8. {
  9. class MPGeometry;
  10. struct MPVertex
  11. {
  12. Vector3 position_;
  13. Vector3 normal_;
  14. Vector4 tangent_;
  15. unsigned color_;
  16. Vector2 uv0_;
  17. Vector2 uv1_;
  18. void Clear()
  19. {
  20. position_ = Vector3::ZERO;
  21. normal_ = Vector3::ZERO;
  22. tangent_ = Vector4::ZERO;
  23. uv0_ = Vector2::ZERO;
  24. uv1_ = Vector2::ZERO;
  25. color_ = 0;
  26. }
  27. bool operator==(const MPVertex& rhs)
  28. {
  29. return ( position_ == rhs.position_ &&
  30. normal_ == rhs.normal_ &&
  31. tangent_ == rhs.tangent_ &&
  32. color_ == rhs.color_ &&
  33. uv0_ == rhs.uv0_ &&
  34. uv1_ == rhs.uv1_ );
  35. }
  36. };
  37. class MPGeometry : public RefCounted
  38. {
  39. ATOMIC_REFCOUNTED(MPGeometry)
  40. public:
  41. SharedPtr<Geometry> geometry_;
  42. PODVector<MPVertex> vertices_;
  43. PODVector<VertexElement> elements_;
  44. SharedArrayPtr<unsigned> indices_;
  45. unsigned numIndices_;
  46. };
  47. class MPLODLevel : public RefCounted
  48. {
  49. ATOMIC_REFCOUNTED(MPLODLevel)
  50. public:
  51. /// Get the total vertex and index counts of all LOD geometry
  52. void GetTotalCounts(unsigned& totalVertices, unsigned& totalIndices) const;
  53. /// Returns true if all LOD geometry contains element
  54. bool HasElement(VertexElementType type, VertexElementSemantic semantic, unsigned char index = 0) const;
  55. Vector<SharedPtr<MPGeometry>> mpGeometry_;
  56. unsigned level_;
  57. };
  58. /// Model packer/unpacker from/to packed representation (destructive!)
  59. class ModelPacker : public Object
  60. {
  61. ATOMIC_OBJECT(ModelPacker, Object)
  62. public:
  63. ModelPacker(Context* context);
  64. virtual ~ModelPacker();
  65. bool Unpack(Model* model);
  66. bool Pack();
  67. const String& GetErrorText() const { return errorText_; }
  68. Vector<SharedPtr<MPLODLevel>> lodLevels_;
  69. private:
  70. void SetError(const String& errorText) { errorText_ = errorText; }
  71. String errorText_;
  72. bool UnpackLODLevel(unsigned level);
  73. bool UnpackGeometry(MPLODLevel* level, Geometry* geometry);
  74. SharedPtr<Model> model_;
  75. };
  76. }