// 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 "lod_texture_builder.h" #include "nel/misc/aabbox.h" using namespace std; using namespace NLMISC; using namespace NL3D; // *************************************************************************** // Quality factor. Usefull to get maximum of interseting values in the range 0..255. #define NL_LTB_MAX_DISTANCE_QUALITY_FACTOR 0.05f // The bigger, the lower the influence of the normal is. must be >=0 #define NL_LTB_NORMAL_BIAS 1.f // *************************************************************************** CLodTextureBuilder::CLodTextureBuilder() { _OverSampleDistance= 0.05f; } // *************************************************************************** float CLodTextureBuilder::computeQualityPixel(const CPixelInfo &p0, const CPixelInfo &p1) const { float d= (p1.Pos-p0.Pos).norm(); float dotProd= p1.Normal*p0.Normal; // With NL_NORMAL_BIAS==1, it return froms d*1(normals aligned) to d*3 (opposite normals) return d*(NL_LTB_NORMAL_BIAS+1-dotProd); } // *************************************************************************** void CLodTextureBuilder::setLod(const NL3D::CLodCharacterShapeBuild &lod) { uint i; _CLod= lod; // **** compute the max quality distance. ie where CTUVQ.Q== 255 // build a bbox around the lod. CAABBox bbox; bbox.setCenter(lod.Vertices[0]); for(i=0;i(meshMRM.getVertexBuffer()); CVertexBufferRead vba; VB.lock (vba); const uint8 *srcPos= (const uint8*)vba.getVertexCoordPointer(); const uint8 *srcNormal= (const uint8*)vba.getNormalCoordPointer(); const uint8 *srcUV= (const uint8*)vba.getTexCoordPointer(); uint vertexSize = VB.getVertexSize(); // For the more precise lod uint lodId= meshMRM.getNbLod()-1; // Resolve Geomoprh problem: copy End to all geomorphs dest. Hence sure that all ids points to good vertex data const std::vector &geoms= meshMRM.getMeshGeom().getGeomorphs(lodId); for(uint gm=0;gm &geoms= meshMRM.getMeshGeom().getGeomorphs(lodId); for(uint gm=0;gm indices32(triPointer, triPointer + numTris * 3); addSampleTris(srcPos, srcNormal, srcUV, vertexSize, &indices32[0], numTris, materialId, edgeSet); } // *************************************************************************** void CLodTextureBuilder::addSampleTris(const uint8 *srcPos, const uint8 *srcNormal, const uint8 *srcUV, uint vertexSize, const uint32 *triPointer, uint numTris, uint materialId, TEdgeSet &edgeSet) { nlassert(srcPos); // ensure that the material is in 0..255 clamp(materialId, 0U, 255U); for(uint i=0;i=2 if(numEdgeOverSamples[c]>=2) { // Sample the edge, exclude endPoints. for(uint s=1;s=3 (at least one vertex in the middle) if(triOverSample>=2) { // Interpolate with barycentric coordinate rules uint s,t,v; // Donc't compute on triangles edges. for(s=1;s