diff --git a/code/nel/include/nel/3d/shape_material_serializer.h b/code/nel/include/nel/3d/shape_material_serializer.h new file mode 100644 index 000000000..cb42b5d6e --- /dev/null +++ b/code/nel/include/nel/3d/shape_material_serializer.h @@ -0,0 +1,37 @@ +// 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 . + +#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 diff --git a/code/nel/src/3d/CMakeLists.txt b/code/nel/src/3d/CMakeLists.txt index e0f1c6c85..304090ea2 100644 --- a/code/nel/src/3d/CMakeLists.txt +++ b/code/nel/src/3d/CMakeLists.txt @@ -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 diff --git a/code/nel/src/3d/shape_material_serializer.cpp b/code/nel/src/3d/shape_material_serializer.cpp new file mode 100644 index 000000000..9fe273acd --- /dev/null +++ b/code/nel/src/3d/shape_material_serializer.cpp @@ -0,0 +1,97 @@ +// 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/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() ); + } + + } + } + + } +} + + + + diff --git a/code/nel/tools/3d/plugin_max/nel_export/nel_export_export.cpp b/code/nel/tools/3d/plugin_max/nel_export/nel_export_export.cpp index fbca1f037..f6cd84838 100644 --- a/code/nel/tools/3d/plugin_max/nel_export/nel_export_export.cpp +++ b/code/nel/tools/3d/plugin_max/nel_export/nel_export_export.cpp @@ -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