diff --git a/code/nel/include/nel/3d/dyn_mat_loader.h b/code/nel/include/nel/3d/dyn_mat_loader.h
new file mode 100644
index 000000000..79f7da411
--- /dev/null
+++ b/code/nel/include/nel/3d/dyn_mat_loader.h
@@ -0,0 +1,45 @@
+// 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 DYN_MAT_LOADER_H
+#define DYN_MAT_LOADER_H
+
+#include
+
+namespace NL3D
+{
+ class CDynMaterial;
+
+ class CDynMatLoader
+ {
+ public:
+ CDynMatLoader();
+ ~CDynMatLoader();
+
+ bool loadFrom( const std::string &fileName );
+
+ CDynMaterial* getDynMat() const{ return mat; }
+
+ private:
+ CDynMaterial *mat;
+
+ };
+}
+
+#endif
+
+
diff --git a/code/nel/include/nel/3d/dynamic_material.h b/code/nel/include/nel/3d/dynamic_material.h
index bc89a88a2..a24516f25 100644
--- a/code/nel/include/nel/3d/dynamic_material.h
+++ b/code/nel/include/nel/3d/dynamic_material.h
@@ -81,6 +81,8 @@ namespace NL3D
public:
CDynMaterial();
~CDynMaterial();
+ CDynMaterial& operator=( const CDynMaterial &other );
+
void reconstruct();
void clear();
void serial( NLMISC::IStream &f );
diff --git a/code/nel/include/nel/3d/material.h b/code/nel/include/nel/3d/material.h
index 4da6875e0..92272a846 100644
--- a/code/nel/include/nel/3d/material.h
+++ b/code/nel/include/nel/3d/material.h
@@ -262,7 +262,7 @@ public:
*/
CMaterial();
/// see operator=.
- CMaterial(const CMaterial &mat) : CRefCount() {_Touched= 0;_Flags=0; operator=(mat);}
+ CMaterial(const CMaterial &mat);
/// dtor.
~CMaterial();
/// Do not copy DrvInfos, copy all infos and set IDRV_TOUCHED_ALL.
@@ -701,6 +701,7 @@ private:
public:
CDynMaterial* getDynMat() const{ return dynMat; }
+ void setDynMat( CDynMaterial *newDynMat ){ dynMat = newDynMat; }
/// Create the dynamic material from the current material parameters
void createDynMat();
diff --git a/code/nel/src/3d/CMakeLists.txt b/code/nel/src/3d/CMakeLists.txt
index 304090ea2..46f4027a8 100644
--- a/code/nel/src/3d/CMakeLists.txt
+++ b/code/nel/src/3d/CMakeLists.txt
@@ -146,6 +146,8 @@ SOURCE_GROUP(Driver FILES
../../include/nel/3d/material.h
dynamic_material.cpp
../../include/nel/3d/dynamic_material.h
+ dyn_mat_loader.cpp
+ ../../include/nel/3d/dyb_mat_loader.h
nelu.cpp
../../include/nel/3d/nelu.h
../../include/nel/3d/occlusion_query.h
diff --git a/code/nel/src/3d/dyn_mat_loader.cpp b/code/nel/src/3d/dyn_mat_loader.cpp
new file mode 100644
index 000000000..c91d3bf2e
--- /dev/null
+++ b/code/nel/src/3d/dyn_mat_loader.cpp
@@ -0,0 +1,61 @@
+// 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/dyn_mat_loader.h"
+#include "nel/3d/dynamic_material.h"
+#include "nel/misc/file.h"
+#include "nel/misc/i_xml.h"
+
+namespace NL3D
+{
+ CDynMatLoader::CDynMatLoader()
+ {
+ mat = NULL;
+ }
+
+ CDynMatLoader::~CDynMatLoader()
+ {
+ mat = NULL;
+ }
+
+ bool CDynMatLoader::loadFrom( const std::string &fileName )
+ {
+ NLMISC::CIFile ifile;
+ if( !ifile.open( fileName, true ) )
+ {
+ nlinfo( "Error opening file %s", fileName.c_str() );
+ return false;
+ }
+
+ NLMISC::CIXml xml;
+ if( !xml.init( ifile ) )
+ {
+ ifile.close();
+ nlinfo( "Error initializing XML stream for file %s", fileName.c_str() );
+ return false;
+ }
+
+ mat = new CDynMaterial();
+ mat->serial( xml );
+
+ ifile.close();
+
+ return true;
+ }
+}
+
+
diff --git a/code/nel/src/3d/dynamic_material.cpp b/code/nel/src/3d/dynamic_material.cpp
index 7202f9a05..8a0ac150a 100644
--- a/code/nel/src/3d/dynamic_material.cpp
+++ b/code/nel/src/3d/dynamic_material.cpp
@@ -158,6 +158,25 @@ namespace NL3D
clear();
}
+ CDynMaterial& CDynMaterial::operator=( const CDynMaterial &other )
+ {
+ if( &other != this )
+ {
+ clear();
+
+ std::vector< SRenderPass* >::const_iterator itr = other.passes.begin();
+ while( itr != other.passes.end() )
+ {
+ SRenderPass *pass = new SRenderPass();
+ *pass = *(*itr);
+ passes.push_back( pass );
+ ++itr;
+ }
+ }
+
+ return *this;
+ }
+
void CDynMaterial::reconstruct()
{
clear();
@@ -201,6 +220,7 @@ namespace NL3D
}
else
{
+ clear();
uint32 n;
f.xmlPush( "count" );
f.serial( n );
diff --git a/code/nel/src/3d/material.cpp b/code/nel/src/3d/material.cpp
index 0a16687c8..cf0dc3701 100644
--- a/code/nel/src/3d/material.cpp
+++ b/code/nel/src/3d/material.cpp
@@ -53,6 +53,15 @@ CMaterial::CMaterial()
dynMat = NULL;
}
+CMaterial::CMaterial( const CMaterial &mat ) :
+CRefCount()
+{
+ _Touched= 0;
+ _Flags=0;
+ dynMat = NULL;
+ operator=(mat);
+}
+
// ***************************************************************************
void CMaterial::initUnlit()
{
@@ -123,8 +132,14 @@ CMaterial &CMaterial::operator=(const CMaterial &mat)
// All states of material is modified.
_Touched= IDRV_TOUCHED_ALL;
- dynMat = NULL;
-
+ if( mat.dynMat != NULL )
+ {
+ if( dynMat == NULL )
+ dynMat = new CDynMaterial();
+
+ *dynMat = *mat.dynMat;
+ }
+
return *this;
}
@@ -178,8 +193,6 @@ void CMaterial::serial(NLMISC::IStream &f)
- base version.
*/
- dynMat = NULL;
-
sint ver= f.serialVersion(9);
// For the version <=1:
nlassert(IDRV_MAT_MAXTEXTURES==4);
diff --git a/code/nel/src/3d/shape_material_serializer.cpp b/code/nel/src/3d/shape_material_serializer.cpp
index c18e24d32..251f66b80 100644
--- a/code/nel/src/3d/shape_material_serializer.cpp
+++ b/code/nel/src/3d/shape_material_serializer.cpp
@@ -58,8 +58,13 @@ namespace NL3D
for( int i = 0; i < n; i++ )
{
CMaterial &m = mb->getMaterial( i );
- m.createDynMat();
CDynMaterial *dm = m.getDynMat();
+ if( dm == NULL )
+ {
+ m.createDynMat();
+ dm = m.getDynMat();
+ }
+
fname = path + "_";
fname += char( '0' + i );
fname += ".nelmat";
diff --git a/code/nel/tools/3d/plugin_max/nel_mesh_lib/export_material.cpp b/code/nel/tools/3d/plugin_max/nel_mesh_lib/export_material.cpp
index b3e632547..083469b3d 100644
--- a/code/nel/tools/3d/plugin_max/nel_mesh_lib/export_material.cpp
+++ b/code/nel/tools/3d/plugin_max/nel_mesh_lib/export_material.cpp
@@ -22,6 +22,7 @@
#include "nel/3d/texture_cube.h"
#include "nel/3d/tangent_space_build.h"
#include "nel/3d/meshvp_per_pixel_light.h"
+#include "nel/3d/dyn_mat_loader.h"
#include
#include
@@ -276,6 +277,19 @@ void CExportNel::buildAMaterial (NL3D::CMaterial& material, CMaxMaterialInfo& ma
// It is a NeL material ?
if (isClassIdCompatible (mtl, Class_ID(NEL_MTL_A,NEL_MTL_B)))
{
+ std::string sMaterialFile;
+ if( CExportNel::getValueByNameUsingParamBlock2( mtl, "sMaterialFile", (ParamType2)TYPE_STRING, &sMaterialFile, time ) )
+ {
+ if( !sMaterialFile.empty() )
+ {
+ nlinfo( "Using material file %s", sMaterialFile.c_str() );
+ CDynMatLoader loader;
+ if( loader.loadFrom( sMaterialFile ) )
+ material.setDynMat( loader.getDynMat() );
+ else
+ nlinfo( "Error loading material file %s", sMaterialFile.c_str() );
+ }
+ }
// Get the shader value now
int iShaderType = 0;