00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "std3d.h"
00027
00028 #include "3d/ig_surface_light_build.h"
00029
00030
00031 using namespace NLMISC;
00032 using namespace std;
00033
00034 namespace NL3D
00035 {
00036
00037
00038
00039 void CIGSurfaceLightBuild::buildSunDebugMesh(CMesh::CMeshBuild &meshBuild,
00040 CMeshBase::CMeshBaseBuild &meshBaseBuild, const CVector &deltaPos)
00041 {
00042 contReset(meshBuild);
00043 contReset(meshBaseBuild);
00044 meshBaseBuild.Materials.resize(1);
00045 meshBaseBuild.Materials[0].initUnlit();
00046 meshBaseBuild.Materials[0].setBlend(true);
00047 meshBaseBuild.Materials[0].setBlendFunc(CMaterial::srcalpha, CMaterial::invsrcalpha);
00048
00049 meshBuild.VertexFlags= CVertexBuffer::PositionFlag | CVertexBuffer::PrimaryColorFlag;
00050
00051
00052 ItRetrieverGridMap it;
00053 for(it= RetrieverGridMap.begin(); it!= RetrieverGridMap.end(); it++)
00054 {
00055 for(uint iSurf= 0; iSurf<it->second.Grids.size(); iSurf++)
00056 {
00057 CSurface &surface= it->second.Grids[iSurf];
00058
00059
00060 uint wVert= surface.Width;
00061 uint hVert= surface.Height;
00062 uint wCell= wVert-1;
00063 uint hCell= hVert-1;
00064 uint vId0= meshBuild.Vertices.size();
00065
00066 meshBuild.Vertices.resize(vId0 + wVert*hVert);
00067 vector<CRGBA> colors;
00068 colors.resize(wVert*hVert);
00069
00070 meshBuild.Faces.reserve(meshBuild.Faces.size() + wCell*hCell *2);
00071
00072
00073 uint x, y;
00074 for(y=0;y<hVert; y++)
00075 {
00076 for(x=0;x<wVert; x++)
00077 {
00078 uint vId= y*wVert + x;
00079
00080 meshBuild.Vertices[vId0 + vId]= surface.Cells[vId].CenterPos + deltaPos;
00081
00082 uint8 col= surface.Cells[vId].SunContribution;
00083 colors[vId].set(col, col, col, 128);
00084
00085 colors[vId].B= 128 + colors[vId].B/2;
00086
00087 if(!surface.Cells[vId].InSurface)
00088 colors[vId].G= 128;
00089
00090 }
00091 }
00092
00093
00094 for(y=0;y<hCell; y++)
00095 {
00096 for(x=0;x<wCell; x++)
00097 {
00098 uint v00= y*wVert + x;
00099 uint v10= y*wVert + x+1;
00100 uint v01= (y+1)*wVert + x;
00101 uint v11= (y+1)*wVert + x+1;
00102
00103
00104 bool skip= false;
00105 if(!surface.Cells[v00].InSurface && !surface.Cells[v00].Dilated) skip= true;
00106 if(!surface.Cells[v10].InSurface && !surface.Cells[v10].Dilated) skip= true;
00107 if(!surface.Cells[v01].InSurface && !surface.Cells[v01].Dilated) skip= true;
00108 if(!surface.Cells[v11].InSurface && !surface.Cells[v11].Dilated) skip= true;
00109
00110
00111 if(!skip)
00112 {
00113
00114 CMesh::CFace face0;
00115 face0.MaterialId= 0;
00116 face0.Corner[0].Vertex= vId0+ v00;
00117 face0.Corner[0].Color= colors[v00];
00118 face0.Corner[1].Vertex= vId0+ v10;
00119 face0.Corner[1].Color= colors[v10];
00120 face0.Corner[2].Vertex= vId0+ v01;
00121 face0.Corner[2].Color= colors[v01];
00122
00123
00124 CMesh::CFace face1;
00125 face1.MaterialId= 0;
00126 face1.Corner[0].Vertex= vId0+ v10;
00127 face1.Corner[0].Color= colors[v10];
00128 face1.Corner[1].Vertex= vId0+ v11;
00129 face1.Corner[1].Color= colors[v11];
00130 face1.Corner[2].Vertex= vId0+ v01;
00131 face1.Corner[2].Color= colors[v01];
00132
00133
00134 meshBuild.Faces.push_back(face0);
00135 meshBuild.Faces.push_back(face1);
00136 }
00137 }
00138 }
00139
00140
00141 }
00142 }
00143
00144
00145 }
00146
00147
00148
00149 }