// 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 "nel/3d/coarse_mesh_build.h"
#include "nel/3d/mesh_multi_lod.h"
#include "nel/3d/register_3d.h"
#include "nel/misc/time_nl.h"
#include "nel/misc/config_file.h"
#include "nel/misc/path.h"
#include "nel/misc/file.h"
#include "nel/misc/bsphere.h"
using namespace std;
using namespace NL3D;
using namespace NLMISC;
// Shape file descriptor
class CShapeFileDesc
{
public:
IShape *Shape;
std::string FileName;
};
int main(int argc, char* argv[])
{
// Filter addSearchPath
NLMISC::createDebug();
InfoLog->addNegativeFilter ("adding the path");
// Register 3d
registerSerial3d();
// Get start time
sint64 startTime=CTime::getLocalTime ();
if (argc!=2)
{
// Doc..
nlinfo("build_coarse_mesh [config_file.cfg]\n");
}
else
{
// Read the config file
try
{
CConfigFile cf;
// Load and parse "test.txt" file
cf.load (argv[1]);
// Get the texture_output variable (a string)
CConfigFile::CVar &texture_output = cf.getVar ("output_textures");
std::vector texture_output_path;
uint outputTextureCount = texture_output.size();
texture_output_path.resize (outputTextureCount);
uint i;
for (i=0; i shapes;
std::vector coarseMeshes;
coarseMeshes.reserve (list_mesh.size ());
shapes.reserve (list_mesh.size ());
// Load all the shapes
uint list_mesh_count=list_mesh.size ()/2;
for (i = 0; i < list_mesh_count; i++)
{
// Shape path
std::string intputPath=list_mesh.asString (i*2);
std::string outputPath=list_mesh.asString (i*2+1);
// Output
nlinfo ("Loading %s...\n", intputPath.c_str());
// File
CIFile inputFile;
if (inputFile.open (CPath::lookup (intputPath.c_str())))
{
// Load a shape stream
CShapeStream shapeStr;
inputFile.serial (shapeStr);
// Cast pointer
CMeshMultiLod *multiLod=dynamic_cast(shapeStr.getShapePointer ());
if (multiLod)
{
// Coarse mesh found
bool found=false;
// Get the coarse meshes
uint count=multiLod->getNumSlotMesh ();
uint j;
for (j=0; jgetSlotMesh (j, coarseMesh);
// Is a coarse mesh ?
if (coarseMesh)
{
// Cast
CMeshGeom *meshGeom=safe_cast (iMeshGeom);
// Shape not used ?
if (!found)
{
// Build an info class
CShapeFileDesc fileDesc;
fileDesc.Shape=multiLod;
fileDesc.FileName=outputPath;
// Add it
shapes.push_back (fileDesc);
}
// Found one
found=true;
// Add it in the list
coarseMeshes.push_back (CCoarseMeshBuild::CCoarseMeshDesc (meshGeom, multiLod));
}
}
// No coarse mesh ?
if (!found)
{
// Output error message
nlwarning ("ERROR this shape has no coarse mesh. %s\n", intputPath.c_str());
// Delete the shape
delete multiLod;
}
}
else
{
// not good type
nlwarning ("ERROR This mesh is not a multilod ! %s...\n", intputPath.c_str());
}
}
else
{
// Output
nlwarning ("ERROR file not found: %s\n", intputPath.c_str());
}
}
// Some coarse mesh ?
if (coarseMeshes.size()>0)
{
// Output text
nlinfo ("Compute the coarse meshes...\n");
// A bitmap
vector coarseBitmap;
coarseBitmap.resize (texture_output_path.size ());
// Build the coarse meshes
CCoarseMeshBuild::CStats stats;
CCoarseMeshBuild builder;
if (builder.build (coarseMeshes, coarseBitmap, stats, texture_mul_size_float))
{
// Save the shapes
for (i=0; i