NL3D::CIGSurfaceLightBuild Class Reference

#include <ig_surface_light_build.h>


Detailed Description

Class used by NL3D::CInstanceLighter to build CIGSurfaceLight with PACS surfaces
Author:
Lionel Berenguier

Nevrax France

Date:
2002

Definition at line 46 of file ig_surface_light_build.h.

Public Types

enum  { MaxOverSamples = 16 }
typedef TRetrieverGridMap::iterator ItRetrieverGridMap
typedef std::map< uint, CRetrieverLightGridTRetrieverGridMap

Public Member Functions

void buildPLDebugMesh (CMesh::CMeshBuild &meshBuild, CMeshBase::CMeshBaseBuild &meshBaseBuild, const CVector &deltaPos, const CInstanceGroup &igOut)
 Debug: build a colored Grid mesh of PointLight. R= pointLight1 id. G= PointLight2 id. B= The multiplier used to show Ids.

void buildSunDebugMesh (CMesh::CMeshBuild &meshBuild, CMeshBase::CMeshBaseBuild &meshBaseBuild, const CVector &deltaPos=CVector::Null)
 Debug: build a colored Grid mesh of SunContribution.


Data Fields

float CellSize
TRetrieverGridMap RetrieverGridMap

Private Member Functions

void addDebugMeshFaces (CMesh::CMeshBuild &meshBuild, CSurface &surface, uint vId0, const std::vector< CRGBA > &colors)


Member Typedef Documentation

typedef TRetrieverGridMap::iterator NL3D::CIGSurfaceLightBuild::ItRetrieverGridMap
 

Definition at line 106 of file ig_surface_light_build.h.

typedef std::map<uint, CRetrieverLightGrid> NL3D::CIGSurfaceLightBuild::TRetrieverGridMap
 

Definition at line 105 of file ig_surface_light_build.h.


Member Enumeration Documentation

anonymous enum
 

Enumeration values:
MaxOverSamples 

Definition at line 50 of file ig_surface_light_build.h.

00050 {MaxOverSamples= 16};


Member Function Documentation

void NL3D::CIGSurfaceLightBuild::addDebugMeshFaces CMesh::CMeshBuild meshBuild,
CSurface surface,
uint  vId0,
const std::vector< CRGBA > &  colors
[private]
 

Definition at line 191 of file ig_surface_light_build.cpp.

References NL3D::CIGSurfaceLightBuild::CSurface::Cells, NL3D::CMesh::CFace::Corner, NL3D::CMesh::CMeshBuild::Faces, NL3D::CIGSurfaceLightBuild::CSurface::Height, NL3D::CMesh::CFace::MaterialId, uint, NL3D::CIGSurfaceLightBuild::CSurface::Width, x, and y.

Referenced by buildPLDebugMesh(), and buildSunDebugMesh().

00193 {
00194         // Resize faces.
00195         uint    wVert= surface.Width;
00196         uint    hVert= surface.Height;
00197         uint    wCell= wVert-1;
00198         uint    hCell= hVert-1;
00199         // Allocate enough space for faces.
00200         meshBuild.Faces.reserve(meshBuild.Faces.size() + wCell*hCell *2);
00201 
00202         // Build faces
00203         uint    x,y;
00204         for(y=0;y<hCell; y++)
00205         {
00206                 for(x=0;x<wCell; x++)
00207                 {
00208                         uint    v00= y*wVert + x;
00209                         uint    v10= y*wVert + x+1;
00210                         uint    v01= (y+1)*wVert + x;
00211                         uint    v11= (y+1)*wVert + x+1;
00212 
00213                         // Skip this cell??
00214                         bool    skip= false;
00215                         if(!surface.Cells[v00].InSurface && !surface.Cells[v00].Dilated)        skip= true;
00216                         if(!surface.Cells[v10].InSurface && !surface.Cells[v10].Dilated)        skip= true;
00217                         if(!surface.Cells[v01].InSurface && !surface.Cells[v01].Dilated)        skip= true;
00218                         if(!surface.Cells[v11].InSurface && !surface.Cells[v11].Dilated)        skip= true;
00219 
00220 
00221                         if(!skip)
00222                         {
00223                                 // 1st triangle.
00224                                 CMesh::CFace    face0;
00225                                 face0.MaterialId= 0;
00226                                 face0.Corner[0].Vertex= vId0+ v00;
00227                                 face0.Corner[0].Color= colors[v00];
00228                                 face0.Corner[1].Vertex= vId0+ v10;
00229                                 face0.Corner[1].Color= colors[v10];
00230                                 face0.Corner[2].Vertex= vId0+ v01;
00231                                 face0.Corner[2].Color= colors[v01];
00232 
00233                                 // 2nd triangle.
00234                                 CMesh::CFace    face1;
00235                                 face1.MaterialId= 0;
00236                                 face1.Corner[0].Vertex= vId0+ v10;
00237                                 face1.Corner[0].Color= colors[v10];
00238                                 face1.Corner[1].Vertex= vId0+ v11;
00239                                 face1.Corner[1].Color= colors[v11];
00240                                 face1.Corner[2].Vertex= vId0+ v01;
00241                                 face1.Corner[2].Color= colors[v01];
00242 
00243                                 // Add 2 triangles
00244                                 meshBuild.Faces.push_back(face0);
00245                                 meshBuild.Faces.push_back(face1);
00246                         }
00247                 }
00248         }
00249 }

void NL3D::CIGSurfaceLightBuild::buildPLDebugMesh CMesh::CMeshBuild meshBuild,
CMeshBase::CMeshBaseBuild meshBaseBuild,
const CVector deltaPos,
const CInstanceGroup igOut
 

Debug: build a colored Grid mesh of PointLight. R= pointLight1 id. G= PointLight2 id. B= The multiplier used to show Ids.

Definition at line 100 of file ig_surface_light_build.cpp.

References addDebugMeshFaces(), NL3D::CSurfaceLightGrid::Cells, NL3D::CIGSurfaceLightBuild::CSurface::Cells, NLMISC::CRGBA::G, NL3D::CInstanceGroup::getIGSurfaceLight(), NL3D::CInstanceGroup::getPointLightList(), NL3D::CIGSurfaceLight::getRetrieverGridMap(), NL3D::CIGSurfaceLightBuild::CSurface::Height, NL3D::CMeshBase::CMeshBaseBuild::Materials, min, nlassert, nlwarning, NLMISC::CRGBA::R, NLMISC::raiseToNextPowerOf2(), RetrieverGridMap, NLMISC::CRGBA::set(), uint, v, NL3D::CMesh::CMeshBuild::VertexFlags, NL3D::CMesh::CMeshBuild::Vertices, NL3D::CIGSurfaceLightBuild::CSurface::Width, x, and y.

00101 {
00102         contReset(meshBuild);
00103         contReset(meshBaseBuild);
00104         meshBaseBuild.Materials.resize(1);
00105         meshBaseBuild.Materials[0].initUnlit();
00106 
00107         meshBuild.VertexFlags= CVertexBuffer::PositionFlag | CVertexBuffer::PrimaryColorFlag;
00108 
00109         // Get the number of lights in Ig.
00110         uint    numLight= igOut.getPointLightList().size();
00111         numLight= raiseToNextPowerOf2(numLight);
00112         uint    idMultiplier= 256/ numLight;
00113 
00114         // For all grids.
00115         ItRetrieverGridMap      it;
00116         for(it= RetrieverGridMap.begin(); it!= RetrieverGridMap.end(); it++)
00117         {
00118                 // get the final surface
00119                 CIGSurfaceLight::TRetrieverGridMap::const_iterator      itIg= 
00120                         igOut.getIGSurfaceLight().getRetrieverGridMap().find(it->first);
00121 
00122                 // If not found, abort
00123                 if( itIg== igOut.getIGSurfaceLight().getRetrieverGridMap().end() )
00124                 {
00125                         nlwarning("buildPLDebugMesh fails to find retriever '%d' in igOut", it->first);
00126                         continue;
00127                 }
00128                 else if( it->second.Grids.size()!=itIg->second.Grids.size() )
00129                 {
00130                         nlwarning("buildPLDebugMesh find retriever '%d' in igOut, but with bad size: excepting: %d, get: %d", 
00131                                 it->first, it->second.Grids.size(), itIg->second.Grids.size() );
00132                         continue;
00133                 }
00134 
00135                 // For all surface of the retriever.
00136                 for(uint iSurf= 0; iSurf<it->second.Grids.size(); iSurf++)
00137                 {
00138                         CSurface                                        &surface= it->second.Grids[iSurf];
00139                         const CSurfaceLightGrid         &igSurface= itIg->second.Grids[iSurf];
00140 
00141                         // Resize vector.
00142                         uint    wVert= surface.Width;
00143                         uint    hVert= surface.Height;
00144                         uint    vId0= meshBuild.Vertices.size();
00145                         // Allocate vertices / colors
00146                         meshBuild.Vertices.resize(vId0 + wVert*hVert);
00147                         vector<CRGBA>   colors;
00148                         colors.resize(wVert*hVert);
00149 
00150                         // Build vertices pos and colors.
00151                         uint    x, y;
00152                         for(y=0;y<hVert; y++)
00153                         {
00154                                 for(x=0;x<wVert; x++)
00155                                 {
00156                                         uint    vId= y*wVert + x;
00157                                         // Copy Pos.
00158                                         meshBuild.Vertices[vId0 + vId]= surface.Cells[vId].CenterPos + deltaPos;
00159                                         // init Color with idMultiplier in Blue (info!).
00160                                         CRGBA   &col= colors[vId];
00161                                         col.set(0,0, idMultiplier, 255);
00162                                         // store the compressed id of the light found in igOut.
00163                                         nlassert( CSurfaceLightGrid::NumLightPerCorner>=2 );
00164                                         uint    idLight0= igSurface.Cells[vId].Light[0];
00165                                         uint    idLight1= igSurface.Cells[vId].Light[1];
00166                                         // 255 means no light. If at least one light
00167                                         if(idLight0<255)
00168                                         {
00169                                                 uint    v= (idLight0+1)*idMultiplier;
00170                                                 col.R= min(v, 255U);
00171                                                 // if second light
00172                                                 if(idLight1<255)
00173                                                 {
00174                                                         v= (idLight1+1)*idMultiplier;
00175                                                         col.G= min(v, 255U);
00176                                                 }
00177                                         }
00178                                 }
00179                         }
00180 
00181                         // Build faces
00182                         addDebugMeshFaces(meshBuild, surface, vId0, colors);
00183 
00184                 }
00185         }
00186 
00187 }

void NL3D::CIGSurfaceLightBuild::buildSunDebugMesh CMesh::CMeshBuild meshBuild,
CMeshBase::CMeshBaseBuild meshBaseBuild,
const CVector deltaPos = CVector::Null
 

Debug: build a colored Grid mesh of SunContribution.

Definition at line 40 of file ig_surface_light_build.cpp.

References addDebugMeshFaces(), NL3D::CIGSurfaceLightBuild::CSurface::Cells, NL3D::CIGSurfaceLightBuild::CSurface::Height, NL3D::CMeshBase::CMeshBaseBuild::Materials, RetrieverGridMap, uint, uint8, NL3D::CMesh::CMeshBuild::VertexFlags, NL3D::CMesh::CMeshBuild::Vertices, NL3D::CIGSurfaceLightBuild::CSurface::Width, x, and y.

00042 {
00043         contReset(meshBuild);
00044         contReset(meshBaseBuild);
00045         meshBaseBuild.Materials.resize(1);
00046         meshBaseBuild.Materials[0].initUnlit();
00047         meshBaseBuild.Materials[0].setBlend(true);
00048         meshBaseBuild.Materials[0].setBlendFunc(CMaterial::srcalpha, CMaterial::invsrcalpha);
00049 
00050         meshBuild.VertexFlags= CVertexBuffer::PositionFlag | CVertexBuffer::PrimaryColorFlag;
00051 
00052         // For all grids.
00053         ItRetrieverGridMap      it;
00054         for(it= RetrieverGridMap.begin(); it!= RetrieverGridMap.end(); it++)
00055         {
00056                 for(uint iSurf= 0; iSurf<it->second.Grids.size(); iSurf++)
00057                 {
00058                         CSurface        &surface= it->second.Grids[iSurf];
00059 
00060                         // Resize vector.
00061                         uint    wVert= surface.Width;
00062                         uint    hVert= surface.Height;
00063                         uint    vId0= meshBuild.Vertices.size();
00064                         // Allocate vertices / colors
00065                         meshBuild.Vertices.resize(vId0 + wVert*hVert);
00066                         vector<CRGBA>   colors;
00067                         colors.resize(wVert*hVert);
00068 
00069                         // Build vertices pos and colors.
00070                         uint    x, y;
00071                         for(y=0;y<hVert; y++)
00072                         {
00073                                 for(x=0;x<wVert; x++)
00074                                 {
00075                                         uint    vId= y*wVert + x;
00076                                         // Copy Pos.
00077                                         meshBuild.Vertices[vId0 + vId]= surface.Cells[vId].CenterPos + deltaPos;
00078                                         // Copy Color.
00079                                         uint8   col= surface.Cells[vId].SunContribution;
00080                                         colors[vId].set(col, col, col, 128);
00081                                         // Force Blue color, to simulate ambiant.
00082                                         colors[vId].B= 128 + colors[vId].B/2;
00083                                         // OutSurface => green is 128.
00084                                         if(!surface.Cells[vId].InSurface)
00085                                                 colors[vId].G= 128;
00086 
00087                                 }
00088                         }
00089 
00090                         // Build faces
00091                         addDebugMeshFaces(meshBuild, surface, vId0, colors);
00092 
00093                 }
00094         }
00095 
00096 }


Field Documentation

float NL3D::CIGSurfaceLightBuild::CellSize
 

Definition at line 110 of file ig_surface_light_build.h.

Referenced by NL3D::CInstanceLighter::light().

TRetrieverGridMap NL3D::CIGSurfaceLightBuild::RetrieverGridMap
 

Definition at line 112 of file ig_surface_light_build.h.

Referenced by NL3D::CInstanceLighter::beginCell(), buildPLDebugMesh(), buildSunDebugMesh(), NL3D::CInstanceLighter::light(), and NL3D::CInstanceLighter::nextCell().


The documentation for this class was generated from the following files:
Generated on Tue Mar 16 06:47:13 2004 for NeL by doxygen 1.3.6