// NeL - MMORPG Framework // Copyright (C) 2010 Winch Gate Property Limited // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as // published by the Free Software Foundation, either version 3 of the // License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Affero General Public License for more details. // // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . #include "std3d.h" #include "nel/3d/ig_surface_light_build.h" #include "nel/3d/scene_group.h" using namespace NLMISC; using namespace std; namespace NL3D { // *************************************************************************** void CIGSurfaceLightBuild::buildSunDebugMesh(CMesh::CMeshBuild &meshBuild, CMeshBase::CMeshBaseBuild &meshBaseBuild, const CVector &deltaPos) { contReset(meshBuild); contReset(meshBaseBuild); meshBaseBuild.Materials.resize(1); meshBaseBuild.Materials[0].initUnlit(); meshBaseBuild.Materials[0].setBlend(true); meshBaseBuild.Materials[0].setBlendFunc(CMaterial::srcalpha, CMaterial::invsrcalpha); meshBuild.VertexFlags= CVertexBuffer::PositionFlag | CVertexBuffer::PrimaryColorFlag; // For all grids. ItRetrieverGridMap it; for(it= RetrieverGridMap.begin(); it!= RetrieverGridMap.end(); it++) { for(uint iSurf= 0; iSurfsecond.Grids.size(); iSurf++) { CSurface &surface= it->second.Grids[iSurf]; // Resize vector. uint wVert= surface.Width; uint hVert= surface.Height; uint vId0= (uint)meshBuild.Vertices.size(); // Allocate vertices / colors meshBuild.Vertices.resize(vId0 + wVert*hVert); vector colors; colors.resize(wVert*hVert); // Build vertices pos and colors. uint x, y; for(y=0;y green is 128. if(!surface.Cells[vId].InSurface) colors[vId].G= 128; } } // Build faces addDebugMeshFaces(meshBuild, surface, vId0, colors); } } } // *************************************************************************** void CIGSurfaceLightBuild::buildPLDebugMesh(CMesh::CMeshBuild &meshBuild, CMeshBase::CMeshBaseBuild &meshBaseBuild, const CVector &deltaPos, const CInstanceGroup &igOut) { contReset(meshBuild); contReset(meshBaseBuild); meshBaseBuild.Materials.resize(1); meshBaseBuild.Materials[0].initUnlit(); meshBuild.VertexFlags= CVertexBuffer::PositionFlag | CVertexBuffer::PrimaryColorFlag; // Get the number of lights in Ig. uint numLight= (uint)igOut.getPointLightList().size(); numLight= raiseToNextPowerOf2(numLight); uint idMultiplier= 256/ numLight; // For all grids. ItRetrieverGridMap it; for(it= RetrieverGridMap.begin(); it!= RetrieverGridMap.end(); it++) { // get the final surface CIGSurfaceLight::TRetrieverGridMap::const_iterator itIg= igOut.getIGSurfaceLight().getRetrieverGridMap().find(it->first); // If not found, abort if( itIg== igOut.getIGSurfaceLight().getRetrieverGridMap().end() ) { nlwarning("buildPLDebugMesh fails to find retriever '%d' in igOut", it->first); continue; } else if( it->second.Grids.size()!=itIg->second.Grids.size() ) { nlwarning("buildPLDebugMesh find retriever '%d' in igOut, but with bad size: excepting: %d, get: %d", it->first, it->second.Grids.size(), itIg->second.Grids.size() ); continue; } // For all surface of the retriever. for(uint iSurf= 0; iSurfsecond.Grids.size(); iSurf++) { CSurface &surface= it->second.Grids[iSurf]; const CSurfaceLightGrid &igSurface= itIg->second.Grids[iSurf]; // Resize vector. uint wVert= surface.Width; uint hVert= surface.Height; uint vId0= (uint)meshBuild.Vertices.size(); // Allocate vertices / colors meshBuild.Vertices.resize(vId0 + wVert*hVert); vector colors; colors.resize(wVert*hVert); // Build vertices pos and colors. uint x, y; for(y=0;y=2 ); uint idLight0= igSurface.Cells[vId].Light[0]; uint idLight1= igSurface.Cells[vId].Light[1]; // 255 means no light. If at least one light if(idLight0<255) { uint v= (idLight0+1)*idMultiplier; col.R= min(v, 255U); // if second light if(idLight1<255) { v= (idLight1+1)*idMultiplier; col.G= min(v, 255U); } } } } // Build faces addDebugMeshFaces(meshBuild, surface, vId0, colors); } } } // *************************************************************************** void CIGSurfaceLightBuild::addDebugMeshFaces(CMesh::CMeshBuild &meshBuild, CSurface &surface, uint vId0, const std::vector &colors) { // Resize faces. uint wVert= surface.Width; uint hVert= surface.Height; uint wCell= wVert-1; uint hCell= hVert-1; // Allocate enough space for faces. meshBuild.Faces.reserve(meshBuild.Faces.size() + wCell*hCell *2); // Build faces uint x,y; for(y=0;y