| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- /*
- * PolyLightmapPacker.h
- * Poly
- *
- * Created by Ivan Safrin on 9/24/08.
- * Copyright 2008 __MyCompanyName__. All rights reserved.
- *
- */
- // @package Scene
- #pragma once
- #include "PolyGlobals.h"
- #include "PolyGenericScene.h"
- #include <vector>
- #include <string>
- #include <sstream>
- using std::vector;
- using std::string;
- namespace Polycode {
-
- class GenericScene;
- struct LightmapFace;
-
- struct Lumel {
- float u;
- float v;
- Vector3 worldPos;
- Vector3 normal;
- Vector3 rEnergy;
- float lumelScale;
- LightmapFace *face;
- };
- struct LightmapFace {
- Polygon *meshPolygon;
- Polygon *flatPolygon;
- Polygon *flatUnscaledPolygon;
- Rectangle area;
- Rectangle actualArea;
- Rectangle pixelArea;
- vector<Lumel*> lumels;
- int numLumels;
- int imageID;
- int projectionAxis;
- static const int X_PROJECTION = 0;
- static const int Y_PROJECTION = 1;
- static const int Z_PROJECTION = 2;
- };
-
- struct LightmapMesh {
- SceneMesh *mesh;
- int imageID;
- bool processed;
- vector<LightmapFace*> faces;
- };
-
- class _PolyExport PackNode {
- public:
- PackNode() { child[0] = NULL; child[1] = NULL; face = NULL;}
- ~PackNode(){}
-
- PackNode *clone();
- int rootRes;
- PackNode *Insert(LightmapFace *img);
- void createRoot(int res);
- PackNode* child[2];
- Rectangle rc;
- LightmapFace *face;
- };
-
- class _PolyExport LightmapPacker {
- public:
- LightmapPacker(GenericScene *targetScene);
- ~LightmapPacker();
-
- void generateTextures(int resolution, int quality);
- void unwrapScene();
- void bindTextures();
- void buildTextures();
-
- Vector3 getLumelPos(Lumel *lumel, LightmapFace *face);
-
- void saveLightmaps(string folder);
- vector<LightmapMesh*> lightmapMeshes;
- vector<Texture*> textures;
- vector<Image*> images;
- vector<Lumel*> lumels;
-
- float lightMapRes;
- float lightMapQuality;
-
- private:
-
- void packMesh(LightmapMesh *mesh);
- void generateNewImage();
- bool hasRoomForMesh(LightmapMesh *mesh);
-
- PackNode *cNode;
- Image *currentImage;
- int currentImageID;
-
- GenericScene *targetScene;
- };
-
- }
|