Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 #ifndef __SP_LIGHTMAP_GENERATOR_STRUCTS_H__
00009 #define __SP_LIGHTMAP_GENERATOR_STRUCTS_H__
00010 
00011 
00012 #include "Base/spStandard.hpp"
00013 
00014 #ifdef SP_COMPILE_WITH_LIGHTMAPGENERATOR
00015 
00016 
00017 #include "Base/spDimension.hpp"
00018 #include "Base/spTreeNodeImage.hpp"
00019 #include "SceneGraph/spSceneGraph.hpp"
00020 #include "RenderSystem/spRenderSystem.hpp"
00021 #include "Framework/Tools/spLightmapBase.hpp"
00022 
00023 #include <list>
00024 #include <vector>
00025 
00026 
00027 namespace sp
00028 {
00029 namespace tool
00030 {
00031 
00032 
00034 namespace LightmapGen
00035 {
00036 
00037 
00038 
00039 struct SVertex;
00040 struct STriangle;
00041 struct SFace;
00042 struct SLightmap;
00043 struct SModel;
00044 struct SAxisData;
00045 
00046 
00047 
00048 struct SVertex
00049 {
00050     SVertex();
00051     SVertex(const SModel* Model, const u32 VertexSurface, const u32 VertexIndex);
00052     ~SVertex();
00053     
00054     
00055     bool adjacency(const STriangle &OpTriangle) const;
00056     
00057     void scaleProj(const dim::size2df &Scale);
00058     dim::point2df getMapCoord(const dim::size2di &MaxLightmapSize) const;
00059     
00060     
00061     static dim::vector3df getVectorColor(const video::color &Color);
00062     
00063     
00064     u32 Surface, Index;
00065     
00066     dim::vector3df Position;
00067     dim::vector3df Normal;
00068     dim::point2df TexCoord[MAX_COUNT_OF_TEXTURES];
00069     dim::point2di LMapCoord;
00070     video::color Color;
00071 };
00072 
00073 struct STriangle
00074 {
00075     STriangle();
00076     STriangle(const SModel* Model, u32 TriangleSurface, u32 TriangleIndex, u32 DefIndices[3]);
00077     ~STriangle();
00078     
00079     
00080     bool adjacency(const STriangle &OpTriangle) const;
00081     f32 getDistance(const dim::vector3df &Point) const;
00082     
00083     
00084     static dim::point2df getProjection(
00085         const dim::vector3df &Point, const dim::vector3df &Normal, const f32 Density
00086     );
00087     
00088     static void computeInterpolation(
00089         const scene::SIntersectionContact &Contact, u32 Indices[3], const u8 Layer,
00090         dim::point2df &TexCoord, dim::vector3df &Color, f32 &Alpha
00091     );
00092     
00093     
00094     u32 Surface, Index;
00095     SVertex Vertices[3];
00096     dim::plane3df Plane;
00097     SFace* Face;
00098 };
00099 
00100 struct SFace
00101 {
00102     SFace(SAxisData* FaceAxis);
00103     ~SFace();
00104     
00105     
00106     void computeDensityAverage(f32 DefaultDensity);
00107     void updateVertexProjection(const dim::size2di &MaxLightmapSize);
00108     void resizeVertexProjection(const dim::size2di &NewSize);
00109     
00111     bool adjacency(const SFace &OpFace) const;
00112     
00113     void build(scene::Mesh* Mesh, const dim::size2di &MaxLightmapSize);
00114     
00115     
00116     f32 Density;
00117     u32 Surface;
00118     dim::size2di Size;              
00119     std::list<STriangle> Triangles; 
00120     SLightmap* Lightmap;
00121     SLightmap* RootLightmap;
00122     SAxisData* Axis;
00123 };
00124 
00125 struct SAxisData
00126 {
00127     SAxisData();
00128     ~SAxisData();
00129     
00130     
00131     void createFaces();
00132     void optimizeFaces();
00133     void completeFaces(const dim::size2di &MaxLightmapSize, f32 DefaultDensity);
00134     
00135     
00136     std::list<SFace> Faces;         
00137     std::list<STriangle> Triangles; 
00138     SModel* Model;
00139 };
00140 
00141 struct SModel
00142 {
00143     SModel(scene::Mesh* ObjMesh, bool DefStayAlone, const std::vector< std::vector<f32> > &InitTrianglesDensity);
00144     ~SModel();
00145     
00146     
00147     void partitionMesh(const dim::size2di &MaxLightmapSize, f32 DefaultDensity);
00148     void createAxles();
00149     void linkAxisTriangles(const s32 Axis);
00150     void buildFaces(scene::Mesh* Mesh, const dim::size2di &MaxLightmapSize);
00151     
00152     
00153     scene::Mesh* Mesh;
00154     SAxisData Axles[6];
00155     
00156     f32 DefaultDensity;
00157     dim::matrix4f Matrix, MatrixInv, NormalMatrix;
00158     
00159     bool StayAlone;
00160     
00161     std::vector< std::vector<f32> > TrianglesDensity;
00162     std::vector< std::vector<STriangle*> > Triangles;
00163 };
00164 
00165 struct SLightmapTexel
00166 {
00167     SLightmapTexel();
00168     ~SLightmapTexel();
00169     
00170     
00171     video::color Color, OrigColor;
00172     
00173     const SFace* Face; 
00174 };
00175 
00176 struct SLightmap
00177 {
00178     SLightmap(const dim::size2di &ImageSize, bool UseTexelBuffer = true);
00179     ~SLightmap();
00180     
00181     
00182     video::Texture* createTexture(const video::color &AmbientColor);
00183     void copyImageBuffers();
00184     void reduceBleeding();
00185     
00186     dim::point2df getTexCoord(const dim::point2di &RealPos) const;
00187     
00188     dim::vector3df getAverageColor(s32 X, s32 Y) const;
00189     void getAverageColorPart(s32 X, s32 Y, dim::vector3df &Color, s32 &Counter) const;
00190     
00191     
00192     inline SLightmapTexel& getTexel(s32 X, s32 Y)
00193     {
00194         return TexelBuffer[Y * Size.Width + X];
00195     }
00196     inline const SLightmapTexel& getTexel(s32 X, s32 Y) const
00197     {
00198         return TexelBuffer[Y * Size.Width + X];
00199     }
00200     inline dim::size2di getSize() const
00201     {
00202         return Size;
00203     }
00204     inline void setupTreeNode(TRectNode* Node)
00205     {
00206         RectNode = Node;
00207     }
00208     
00209     
00210     dim::size2di Size;
00211     SLightmapTexel* TexelBuffer;
00212     video::Texture* Texture;
00213     TRectNode* RectNode;
00214 };
00215 
00216 struct SLight
00217 {
00218     SLight(const SLightmapLight &LightData);
00219     ~SLight();
00220     
00221     
00222     f32 getIntensity(const dim::vector3df &Point, const dim::vector3df &Normal) const;
00223     f32 getAttenuationRadius() const;
00224     
00225     bool checkVisibility(const STriangle &Triangle) const;
00226     
00227     
00228     scene::ELightModels Type;
00229     
00230     dim::matrix4f Matrix;
00231     dim::vector3df Position;
00232     dim::vector3df Color;
00233     
00234     f32 Attn0, Attn1, Attn2;
00235     f32 InnerConeAngle, OuterConeAngle;
00236     
00237     dim::vector3df FixedDirection;
00238     f32 FixedVolumetricRadius;
00239     bool FixedVolumetric;
00240 };
00241 
00242 struct SRasterizerVertex
00243 {
00244     SRasterizerVertex();
00245     SRasterizerVertex(
00246         const dim::vector3df &InitPosition,
00247         const dim::vector3df &InitNormal,
00248         const dim::point2di &InitScreenCoord
00249     );
00250     ~SRasterizerVertex();
00251     
00252     
00253     SRasterizerVertex& operator = (const SRasterizerVertex &Other);
00254     
00255     SRasterizerVertex& operator += (const SRasterizerVertex &Other);
00256     SRasterizerVertex& operator -= (const SRasterizerVertex &Other);
00257     
00258     SRasterizerVertex& operator *= (f32 Factor);
00259     SRasterizerVertex& operator /= (f32 Factor);
00260     
00261     
00262     s32 getScreenCoordX() const;
00263     s32 getScreenCoordY() const;
00264     
00265     
00266     dim::vector3df Position;
00267     dim::vector3df Normal;
00268     dim::point2di ScreenCoord;
00269 };
00270 
00271 } 
00272 
00273 
00274 } 
00275 
00276 } 
00277 
00278 
00279 #endif
00280 
00281 #endif
00282 
00283 
00284 
00285