The prototype of the material exporter. It's only called when exporting a mesh, for now.

--HG--
branch : gsoc2013-dfighter
hg/feature/gsoc2013-dfighter
dfighter1985 12 years ago
parent 80bcf2026a
commit ac98c00088

@ -0,0 +1,37 @@
// NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
// 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 <http://www.gnu.org/licenses/>.
#ifndef SHAPE_MAT_SERIALIZER_H
#define SHAPE_MAT_SERIALIZER_H
namespace NL3D
{
class IShape;
class ShapeMatSerial
{
public:
ShapeMatSerial();
~ShapeMatSerial();
void setShape( IShape *s ){ shape = s; }
void serial( const char *sPath );
private:
IShape *shape;
};
}
#endif

@ -259,6 +259,8 @@ SOURCE_GROUP(Shapes FILES
../../include/nel/3d/shape.h
shape_bank.cpp
../../include/nel/3d/shape_bank.h
shape_material_serializer.cpp
../../include/nel/3d/shape_material_serializer.h
shifted_triangle_cache.cpp
../../include/nel/3d/shifted_triangle_cache.h
skeleton_shape.cpp

@ -0,0 +1,97 @@
// NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
// 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 <http://www.gnu.org/licenses/>.
#include "nel/3d/shape_material_serializer.h"
#include "nel/3d/shape.h"
#include "nel/3d/material.h"
#include "nel/3d/dynamic_material.h"
#include "nel/3d/mesh_base.h"
#include "nel/misc/file.h"
#include "nel/misc/o_xml.h"
namespace NL3D
{
ShapeMatSerial::ShapeMatSerial()
{
shape = NULL;
}
ShapeMatSerial::~ShapeMatSerial()
{
shape = NULL;
}
void ShapeMatSerial::serial( const char *sPath )
{
if( shape == NULL )
return;
nlinfo( "Exporting materials of %s", sPath );
std::string path = sPath;
std::string fname;
std::string::size_type idx;
idx = path.find_last_of( '.' );
path = path.substr( 0, idx );
CMeshBase *mb = dynamic_cast< CMeshBase* >( shape );
if( mb != NULL )
{
uint n = mb->getNbMaterial();
nlinfo( "exporting %u materials", n );
for( int i = 0; i < n; i++ )
{
CMaterial &m = mb->getMaterial( i );
m.createDynMat();
CDynMaterial *dm = m.getDynMat();
fname = path + "_";
fname += char( '0' + i );
fname += ".nlmat";
nlinfo( "exporting to %s", fname.c_str() );
NLMISC::COFile o;
if( o.open( fname ) )
{
NLMISC::COXml xml;
if( xml.init( &o ) )
{
dm->serial( xml );
xml.flush();
}
else
{
nlerror( "Error initializing XML output stream for %s", fname.c_str() );
}
o.close();
}
else
{
nlerror( "Error creating file %s", fname.c_str() );
}
}
}
}
}

@ -23,6 +23,7 @@
#include "nel/3d/skeleton_shape.h"
#include "nel/3d/vegetable_shape.h"
#include "nel/3d/lod_character_shape.h"
#include "nel/3d/shape_material_serializer.h"
#include "../nel_mesh_lib/export_nel.h"
#include "../nel_mesh_lib/export_appdata.h"
@ -91,9 +92,10 @@ bool CNelExport::exportMesh (const char *sPath, INode& node, TimeValue time)
InfoLog->display("Beg buildShape %s \n", node.GetName());
// Export in mesh format
IShape *pShape = _ExportNel->buildShape(node, time, mapIdPtr, true);
if (InfoLog)
InfoLog->display("End buildShape in %d ms \n", timeGetTime()-t);
// Conversion success ?
if (pShape)
{
@ -136,6 +138,11 @@ bool CNelExport::exportMesh (const char *sPath, INode& node, TimeValue time)
nelExportTerminateProcess();
}
// Export here
ShapeMatSerial sms;
sms.setShape( pShape );
sms.serial( sPath );
// Delete the pointer
nldebug("Delete the pointer");
try

Loading…
Cancel
Save