PolyLightmapPacker.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * PolyLightmapPacker.h
  3. * Poly
  4. *
  5. * Created by Ivan Safrin on 9/24/08.
  6. * Copyright 2008 __MyCompanyName__. All rights reserved.
  7. *
  8. */
  9. // @package Scene
  10. #pragma once
  11. #include "PolyGlobals.h"
  12. #include "PolyGenericScene.h"
  13. #include <vector>
  14. #include <string>
  15. #include <sstream>
  16. using std::vector;
  17. using std::string;
  18. namespace Polycode {
  19. class GenericScene;
  20. struct LightmapFace;
  21. struct Lumel {
  22. float u;
  23. float v;
  24. Vector3 worldPos;
  25. Vector3 normal;
  26. Vector3 rEnergy;
  27. float lumelScale;
  28. LightmapFace *face;
  29. };
  30. struct LightmapFace {
  31. Polygon *meshPolygon;
  32. Polygon *flatPolygon;
  33. Polygon *flatUnscaledPolygon;
  34. Rectangle area;
  35. Rectangle actualArea;
  36. Rectangle pixelArea;
  37. vector<Lumel*> lumels;
  38. int numLumels;
  39. int imageID;
  40. int projectionAxis;
  41. static const int X_PROJECTION = 0;
  42. static const int Y_PROJECTION = 1;
  43. static const int Z_PROJECTION = 2;
  44. };
  45. struct LightmapMesh {
  46. SceneMesh *mesh;
  47. int imageID;
  48. bool processed;
  49. vector<LightmapFace*> faces;
  50. };
  51. class _PolyExport PackNode {
  52. public:
  53. PackNode() { child[0] = NULL; child[1] = NULL; face = NULL;}
  54. ~PackNode(){}
  55. PackNode *clone();
  56. int rootRes;
  57. PackNode *Insert(LightmapFace *img);
  58. void createRoot(int res);
  59. PackNode* child[2];
  60. Rectangle rc;
  61. LightmapFace *face;
  62. };
  63. class _PolyExport LightmapPacker {
  64. public:
  65. LightmapPacker(GenericScene *targetScene);
  66. ~LightmapPacker();
  67. void generateTextures(int resolution, int quality);
  68. void unwrapScene();
  69. void bindTextures();
  70. void buildTextures();
  71. Vector3 getLumelPos(Lumel *lumel, LightmapFace *face);
  72. void saveLightmaps(string folder);
  73. vector<LightmapMesh*> lightmapMeshes;
  74. vector<Texture*> textures;
  75. vector<Image*> images;
  76. vector<Lumel*> lumels;
  77. float lightMapRes;
  78. float lightMapQuality;
  79. private:
  80. void packMesh(LightmapMesh *mesh);
  81. void generateNewImage();
  82. bool hasRoomForMesh(LightmapMesh *mesh);
  83. PackNode *cNode;
  84. Image *currentImage;
  85. int currentImageID;
  86. GenericScene *targetScene;
  87. };
  88. }