From: Oliver O. <fr...@us...> - 2007-06-17 13:39:37
|
Update of /cvsroot/simspark/simspark/spark/kerosin/materialserver In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv21072/kerosin/materialserver Modified Files: material2dtexture.cpp material2dtexture.h materialserver.cpp materialserver.h materialserver_c.cpp materialsolid.cpp materialsolid.h materialsolid_c.cpp Added Files: materialexporter.h materialexporter_c.cpp materialexternal.cpp materialexternal.h materialexternal_c.cpp Log Message: merge from projectx branch --- NEW FILE: materialexporter.h --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of simspark Tue May 9 2006 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2007 RoboCup Soccer Server 3D Maintenance Group $Id: materialexporter.h,v 1.2 2007/06/17 13:38:30 fruit Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. MaterialExporter NOTE: This class serves as an (abstract) exporter to register materials with other graphic engines (possibly also for exporting). HISTORY: 03/05/07 - OO - Initial version */ #ifndef KEROSIN_MATERIALEXPORTER_H #define KEROSIN_MATERIALEXPORTER_H #include <zeitgeist/class.h> #include <zeitgeist/node.h> #include "material.h" namespace kerosin { /** \class MaterialExporter. This class can be used to implement custom material server, which needs to be informed about the materials used for a specific simulation. By registering a MaterialExporter implementation to the MaterialServer, materials can be registered (exported) to another class. */ class MaterialExporter : public zeitgeist::Leaf { public: virtual ~MaterialExporter() {} /** Register / Export the given material. \param material the material to register / export. */ virtual void RegisterMaterial(boost::shared_ptr<Material> material) = 0; }; DECLARE_ABSTRACTCLASS(MaterialExporter); } // end namespace kerosin #endif // KEROSIN_MATERIALEXPORTER Index: materialsolid.h =================================================================== RCS file: /cvsroot/simspark/simspark/spark/kerosin/materialserver/materialsolid.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** materialsolid.h 18 Feb 2006 19:41:48 -0000 1.2 --- materialsolid.h 17 Jun 2007 13:38:30 -0000 1.3 *************** *** 1,5 **** /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- ! this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University --- 1,5 ---- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- ! this file is part of simspark Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University *************** *** 64,67 **** --- 64,88 ---- const RGBA& GetEmission() const; + /** a hint for the graphics engine if the depth-buffer should be checked + for this material or not. + @returns true if the depth-check should be enabled for this material + */ + bool DepthCheck() const; + + //! set the flag if the depth-buffer should be checked. + void SetDepthCheck(bool depthCheck); + + /** Set the shininess of the material. + When specular light is reflected, this value determines the size of + the region that appears shiny. + @param val + */ + void SetShininess(float val); + + /** get the shininess of the material. + @return a value representing the shininess. + */ + float GetShininess() const; + protected: /** sets up all lighting material properties */ *************** *** 83,86 **** --- 104,114 ---- /** the emitted light intensity of the material */ RGBA mEmission; + + //! flag if depth-buffer should be checked + bool mDepthCheck; + + //! value for the size of the reflecting region + float mShininess; + }; Index: materialserver.h =================================================================== RCS file: /cvsroot/simspark/simspark/spark/kerosin/materialserver/materialserver.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** materialserver.h 19 Feb 2006 11:10:11 -0000 1.2 --- materialserver.h 17 Jun 2007 13:38:30 -0000 1.3 *************** *** 49,54 **** --- 49,70 ---- boost::shared_ptr<Material> GetMaterial(const std::string &name); + /** Create an instance of a material exporter and register it to the MaterialServer. + A MaterialExporter is a class that takes care to additionally register/export + materials registered at the MaterialServer at another class (potentially + external to spark). This has to be done only when spark/kerosin + rendering alone is not enough. + \param name name of the MaterialExporter class name + \returns true if successful + */ + bool InitMaterialExporter(const std::string& name); + + //! export all registered materials via all registered exporters + void ExportAllMaterial(); + protected: virtual void OnLink(); + + //! export a single material to all registered exporters + void ExportMaterial(boost::shared_ptr<Material> material); }; Index: materialsolid_c.cpp =================================================================== RCS file: /cvsroot/simspark/simspark/spark/kerosin/materialserver/materialsolid_c.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** materialsolid_c.cpp 5 Dec 2005 21:38:22 -0000 1.1 --- materialsolid_c.cpp 17 Jun 2007 13:38:30 -0000 1.2 *************** *** 1,5 **** /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- ! this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University --- 1,5 ---- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- ! this file is part of simspark Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University *************** *** 43,46 **** --- 43,69 ---- } + #if 0 + static bool + readRGBAVal(const zeitgeist::ParameterList& in, RGBA& m) + { + int r,g,b; + + if ( + (in.GetSize() != 4) || + (! in.GetValue(in[0], r)) || + (! in.GetValue(in[1], g)) || + (! in.GetValue(in[2], b)) || + (! in.GetValue(in[3], m.a())) + ) + { + return false; + } + m.r() = r / 255.0; + m.g() = g / 255.0; + m.b() = b / 255.0; + return true; + } + #endif + FUNCTION(MaterialSolid,setAmbient) { *************** *** 67,70 **** --- 90,107 ---- } + #if 0 + FUNCTION(MaterialSolid,setDiffuseVal) + { + RGBA m; + if (! readRGBAVal(in,m)) + { + return false; + } + + obj->SetDiffuse(m); + return true; + } + #endif + FUNCTION(MaterialSolid,setSpecular) { *************** *** 91,94 **** --- 128,161 ---- } + FUNCTION(MaterialSolid,setDepthCheck) + { + bool depthCheck; + if ( + (in.GetSize() == 0) || + (! in.GetValue(in[0], depthCheck)) + ) + { + return false; + } + + obj->SetDepthCheck(depthCheck); + return true; + } + + FUNCTION(MaterialSolid,setShininess) + { + float val; + if ( + (in.GetSize() == 0) || + (! in.GetValue(in[0], val)) + ) + { + return false; + } + + obj->SetShininess(val); + return true; + } + void CLASS(MaterialSolid)::DefineClass() { *************** *** 96,100 **** --- 163,170 ---- DEFINE_FUNCTION(setAmbient); DEFINE_FUNCTION(setDiffuse); + // DEFINE_FUNCTION(setDiffuseVal); DEFINE_FUNCTION(setSpecular); DEFINE_FUNCTION(setEmission); + DEFINE_FUNCTION(setDepthCheck); + DEFINE_FUNCTION(setShininess); } Index: material2dtexture.cpp =================================================================== RCS file: /cvsroot/simspark/simspark/spark/kerosin/materialserver/material2dtexture.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** material2dtexture.cpp 15 Mar 2007 07:26:26 -0000 1.2 --- material2dtexture.cpp 17 Jun 2007 13:38:30 -0000 1.3 *************** *** 33,37 **** using namespace std; ! Material2DTexture::Material2DTexture() : MaterialSolid() { } --- 33,38 ---- using namespace std; ! Material2DTexture::Material2DTexture() : MaterialSolid(), ! mTexDiffuseName(""), mTexNormalName(""), mTexSpecularName("") { } *************** *** 41,45 **** } ! bool Material2DTexture::LoadTexture(const std::string& texName, shared_ptr<Texture>& store) { shared_ptr<ScriptServer> scriptServer = GetCore()->GetScriptServer(); --- 42,47 ---- } ! bool ! Material2DTexture::LoadTexture(const std::string& texName, shared_ptr<Texture>& store) { shared_ptr<ScriptServer> scriptServer = GetCore()->GetScriptServer(); *************** *** 50,58 **** if (textureServer.get() == 0) ! { ! GetLog()->Error() ! << "(Material2DTexture) ERROR: cannot find TextureServer\n"; ! return false; ! } store = textureServer->GetTexture(texName); --- 52,60 ---- if (textureServer.get() == 0) ! { ! GetLog()->Error() ! << "(Material2DTexture) ERROR: cannot find TextureServer\n"; ! return false; ! } store = textureServer->GetTexture(texName); *************** *** 60,101 **** } ! bool Material2DTexture::SetDiffuseTexture(const std::string& texName) { return LoadTexture(texName,mTexDiffuse); } ! bool Material2DTexture::SetNormalTexture(const std::string& texName) { return LoadTexture(texName,mTexNormal); } ! bool Material2DTexture::SetSpecularTexture(const std::string& texName) { return LoadTexture(texName,mTexSpecular); } ! void Material2DTexture::Bind() { SetupMaterial(); if (mTexDiffuse.get() != 0) { OpenGLServer::glActiveTextureARB(GL_TEXTURE0_ARB); glEnable(GL_TEXTURE_2D); - mTexDiffuse->Bind(); } if (mTexNormal.get() != 0) { OpenGLServer::glActiveTextureARB(GL_TEXTURE1_ARB); glEnable(GL_TEXTURE_2D); - mTexNormal->Bind(); } if (mTexSpecular.get() != 0) { OpenGLServer::glActiveTextureARB(GL_TEXTURE2_ARB); glEnable(GL_TEXTURE_2D); - mTexSpecular->Bind(); } } --- 62,160 ---- } ! bool ! Material2DTexture::SetDiffuseTexture(const std::string& texName) { + mTexDiffuseName = texName; return LoadTexture(texName,mTexDiffuse); } ! const std::string& ! Material2DTexture::GetDiffuseTextureName() const ! { ! return mTexDiffuseName; ! } ! ! bool ! Material2DTexture::HasDiffuseTexture() const ! { ! return (!mTexDiffuseName.empty() && mTexDiffuse.get() != 0); ! } ! ! bool ! Material2DTexture::SetNormalTexture(const std::string& texName) { + mTexNormalName = texName; return LoadTexture(texName,mTexNormal); } ! const std::string& ! Material2DTexture::GetNormalTextureName() const { + return mTexNormalName; + } + + bool + Material2DTexture::HasNormalTexture() const + { + return (!mTexNormalName.empty() && mTexNormal.get() != 0); + } + + bool + Material2DTexture::SetSpecularTexture(const std::string& texName) + { + mTexSpecularName = texName; return LoadTexture(texName,mTexSpecular); } ! const std::string& ! Material2DTexture::GetSpecularTextureName() const { + return mTexSpecularName; + } + + bool + Material2DTexture::HasSpecularTexture() const + { + return (!mTexSpecularName.empty() && mTexSpecular.get() != 0); + } + + void + Material2DTexture::Bind() + { + shared_ptr<OpenGLServer> openGLServer = + shared_dynamic_cast<OpenGLServer>(GetCore()->Get("/sys/server/opengl")); + + bool use_gl = ((openGLServer.get() != 0) && (!openGLServer->IsGLLocked())); + SetupMaterial(); if (mTexDiffuse.get() != 0) + { + if (use_gl) { OpenGLServer::glActiveTextureARB(GL_TEXTURE0_ARB); glEnable(GL_TEXTURE_2D); } + mTexDiffuse->Bind(); + } if (mTexNormal.get() != 0) + { + if (use_gl) { OpenGLServer::glActiveTextureARB(GL_TEXTURE1_ARB); glEnable(GL_TEXTURE_2D); } + mTexNormal->Bind(); + } if (mTexSpecular.get() != 0) + { + if (use_gl) { OpenGLServer::glActiveTextureARB(GL_TEXTURE2_ARB); glEnable(GL_TEXTURE_2D); } + mTexSpecular->Bind(); + } } --- NEW FILE: materialexternal_c.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of simspark Wed May 9 2007 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: materialexternal_c.cpp,v 1.2 2007/06/17 13:38:30 fruit Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "materialexternal.h" using namespace zeitgeist; using namespace kerosin; using namespace salt; using namespace boost; FUNCTION(MaterialExternal,setReference) { std::string name; if ( (in.GetSize() == 0) || (! in.GetValue(in[0], name)) ) { return false; } obj->SetReference(name); return true; } void CLASS(MaterialExternal)::DefineClass() { DEFINE_BASECLASS(kerosin/MaterialSolid); DEFINE_FUNCTION(setReference); } --- NEW FILE: materialexternal.h --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of simspark Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: materialexternal.h,v 1.2 2007/06/17 13:38:30 fruit Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #ifndef KEROSIN_MATERIALEXTERNAL_H #define KEROSIN_MATERIALEXTERNAL_H #include "materialsolid.h" namespace kerosin { class MaterialExternal : public MaterialSolid { // Functions public: MaterialExternal(); virtual ~MaterialExternal(); virtual void Bind(); //! @return the name of the reference const std::string& GetReference() const; //! Set the name of the reference void SetReference(const std::string& name); protected: /** sets up all lighting material properties */ void SetupMaterial(); // Members protected: /** the external file reference */ std::string mName; }; DECLARE_CLASS(MaterialExternal); }; #endif // KEROSIN_MATERIALEXTERNAL_H --- NEW FILE: materialexporter_c.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of simspark Tue May 9 2006 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2007 RoboCup Soccer Server 3D Maintenance Group $Id: materialexporter_c.cpp,v 1.2 2007/06/17 13:38:30 fruit Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. MeshExporter NOTE: This class serves as an (abstract) exporter, to register materials with other graphic engines (possibly also for exporting) HISTORY: 03/05/07 - OO - Initial version */ #include "materialexporter.h" using namespace kerosin; void CLASS(MaterialExporter)::DefineClass() { DEFINE_BASECLASS(zeitgeist/Leaf); } --- NEW FILE: materialexternal.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of simspark Wed May 9 2007 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: materialexternal.cpp,v 1.2 2007/06/17 13:38:30 fruit Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "materialexternal.h" using namespace kerosin; MaterialExternal::MaterialExternal() : MaterialSolid(), mName("") { } MaterialExternal::~MaterialExternal() { } void MaterialExternal::SetupMaterial() { /* We don't do anything here. This overwrites the original SetupMaterial from MaterialSolid, which calles OpenGl functions. */ } void MaterialExternal::Bind() { /* We don't do anything here. This overwrites the original Bind from MaterialSolid, which calles OpenGl functions. */ } const std::string& MaterialExternal::GetReference() const { return mName; } void MaterialExternal::SetReference(const std::string& name) { mName = name; } Index: materialsolid.cpp =================================================================== RCS file: /cvsroot/simspark/simspark/spark/kerosin/materialserver/materialsolid.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** materialsolid.cpp 15 Mar 2007 07:26:26 -0000 1.3 --- materialsolid.cpp 17 Jun 2007 13:38:30 -0000 1.4 *************** *** 1,5 **** /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- ! this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University --- 1,5 ---- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- ! this file is part of simspark Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University *************** *** 35,39 **** mDiffuse(1.0f,1.0f,1.0f,1.0f), mSpecular(0.0f,0.0f,0.0f,1.0f), ! mEmission(0.0f,0.0f,0.0f,1.0f) { } --- 35,41 ---- mDiffuse(1.0f,1.0f,1.0f,1.0f), mSpecular(0.0f,0.0f,0.0f,1.0f), ! mEmission(0.0f,0.0f,0.0f,1.0f), ! mDepthCheck(true), ! mShininess(128.0f) { } *************** *** 101,109 **** } ! const RGBA& MaterialSolid::GetEmission() const { return mEmission; } --- 103,133 ---- } ! const RGBA& ! MaterialSolid::GetEmission() const { return mEmission; } + bool + MaterialSolid::DepthCheck() const + { + return mDepthCheck; + } + + void + MaterialSolid::SetDepthCheck(bool depthCheck) + { + mDepthCheck = depthCheck; + } + void + MaterialSolid::SetShininess(float val) + { + mShininess = val; + } + float + MaterialSolid::GetShininess() const + { + return mShininess; + } Index: materialserver.cpp =================================================================== RCS file: /cvsroot/simspark/simspark/spark/kerosin/materialserver/materialserver.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** materialserver.cpp 19 Feb 2006 11:10:11 -0000 1.2 --- materialserver.cpp 17 Jun 2007 13:38:30 -0000 1.3 *************** *** 1,22 **** /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- ! this file is part of rcssserver3D ! Fri May 9 2003 ! Copyright (C) 2002,2003 Koblenz University ! Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group ! $Id$ ! This program is free software; you can redistribute it and/or modify ! it under the terms of the GNU General Public License as published by ! the Free Software Foundation; version 2 of the License. ! 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 General Public License for more details. ! You should have received a copy of the GNU General Public License ! along with this program; if not, write to the Free Software ! Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "materialserver.h" --- 1,22 ---- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- ! this file is part of simspark ! Fri May 9 2003 ! Copyright (C) 2002,2003 Koblenz University ! Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group ! $Id$ ! This program is free software; you can redistribute it and/or modify ! it under the terms of the GNU General Public License as published by ! the Free Software Foundation; version 2 of the License. ! 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 General Public License for more details. ! You should have received a copy of the GNU General Public License ! along with this program; if not, write to the Free Software ! Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "materialserver.h" *************** *** 25,28 **** --- 25,29 ---- #include "material.h" #include "materialsolid.h" + #include "materialexporter.h" using namespace boost; *************** *** 38,47 **** } ! void MaterialServer::RegisterMaterial(shared_ptr<Material> material) { if (material.get() == 0) ! { ! return; ! } // remove any previous material with the same name --- 39,49 ---- } ! void ! MaterialServer::RegisterMaterial(shared_ptr<Material> material) { if (material.get() == 0) ! { ! return; ! } // remove any previous material with the same name *************** *** 50,58 **** if (previous.get() != 0) ! { ! GetLog()->Debug() << "(MaterialServer) removing material " ! << material->GetName() << "\n"; ! RemoveChildReference(previous); ! } // register new material --- 52,60 ---- if (previous.get() != 0) ! { ! GetLog()->Debug() << "(MaterialServer) removing material " ! << material->GetName() << "\n"; ! RemoveChildReference(previous); ! } // register new material *************** *** 61,67 **** GetLog()->Debug() << "(MaterialServer) registered material " << material->GetName() << "\n"; } ! shared_ptr<Material> MaterialServer::GetMaterial(const std::string& name) { shared_ptr<Material> material = --- 63,71 ---- GetLog()->Debug() << "(MaterialServer) registered material " << material->GetName() << "\n"; + } ! shared_ptr<Material> ! MaterialServer::GetMaterial(const std::string& name) { shared_ptr<Material> material = *************** *** 69,81 **** if (material.get() == 0) ! { ! GetLog()->Error() << "(MaterialServer) ERROR: Unknown material '" ! << name << "'\n"; ! } return material; } ! void MaterialServer::OnLink() { // create the default material --- 73,86 ---- if (material.get() == 0) ! { ! GetLog()->Error() << "(MaterialServer) ERROR: Unknown material '" ! << name << "'\n"; ! } return material; } ! void ! MaterialServer::OnLink() { // create the default material *************** *** 85,86 **** --- 90,140 ---- AddChildReference(defMat); } + + bool + MaterialServer::InitMaterialExporter(const std::string& name) + { + shared_ptr<MaterialExporter> exporter + = shared_dynamic_cast<MaterialExporter>(GetCore()->New(name)); + + if (exporter.get() == 0) + { + GetLog()->Error() << "(MaterialServer) ERROR: " + << "unable to create MaterialExporter '" << name << "'\n"; + return false; + } + + exporter->SetName(name); + AddChildReference(exporter); + + GetLog()->Normal() << "(MaterialServer) MaterialExporter '" << name << "' registered\n"; + + return true; + } + + void + MaterialServer::ExportAllMaterial() + { + GetLog()->Debug() << "(MaterialServer) ExportAllMaterial\n"; + TLeafList materials; + ListChildrenSupportingClass<Material>(materials); + + for (TLeafList::const_iterator mi = materials.begin(); mi != materials.end(); ++mi) + { + shared_ptr<Material> m = shared_static_cast<Material>(*mi); + ExportMaterial(m); + } + GetLog()->Debug() << "(MaterialServer) ExportAllMaterial done\n"; + } + + void + MaterialServer::ExportMaterial(shared_ptr<Material> material) + { + TLeafList exporters; + ListChildrenSupportingClass<MaterialExporter>(exporters); + + for (TLeafList::const_iterator bi = exporters.begin(); bi != exporters.end(); ++bi) + { + shared_ptr<MaterialExporter> mb = shared_static_cast<MaterialExporter>(*bi); + mb->RegisterMaterial(material); + } + } Index: material2dtexture.h =================================================================== RCS file: /cvsroot/simspark/simspark/spark/kerosin/materialserver/material2dtexture.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** material2dtexture.h 5 Dec 2005 21:38:22 -0000 1.1 --- material2dtexture.h 17 Jun 2007 13:38:30 -0000 1.2 *************** *** 40,49 **** --- 40,61 ---- /** loads the diffuse texture */ bool SetDiffuseTexture(const std::string& texName); + //! @return the name of the set diffuse texture + const std::string& GetDiffuseTextureName() const; + //! @return true if there is a diffuse texture name and a texture + bool HasDiffuseTexture() const; /** loads the normal texture */ bool SetNormalTexture(const std::string& texName); + //! @return the name of the set normal texture + const std::string& GetNormalTextureName() const; + //! @return true if there is a normal texture name and a texture + bool HasNormalTexture() const; /** loads the specular texture */ bool SetSpecularTexture(const std::string& texName); + //! @return the name of the set specular texture + const std::string& GetSpecularTextureName() const; + //! @return true if there is a specular texture name and a texture + bool HasSpecularTexture() const; /** binds the managed material, i.e. sets all necessary OpenGL *************** *** 60,69 **** --- 72,87 ---- // protected: + //! the diffuse texture name + std::string mTexDiffuseName; /** the diffuse texture */ boost::shared_ptr<Texture> mTexDiffuse; + //! the normal texture name + std::string mTexNormalName; /** the normal texture */ boost::shared_ptr<Texture> mTexNormal; + //! the specular texture name + std::string mTexSpecularName; /** the specular texture */ boost::shared_ptr<Texture> mTexSpecular; Index: materialserver_c.cpp =================================================================== RCS file: /cvsroot/simspark/simspark/spark/kerosin/materialserver/materialserver_c.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** materialserver_c.cpp 5 Dec 2005 21:38:22 -0000 1.1 --- materialserver_c.cpp 17 Jun 2007 13:38:30 -0000 1.2 *************** *** 25,32 **** using namespace boost; using namespace kerosin; ! using namespace zeitgeist; ! void CLASS(MaterialServer)::DefineClass() { ! DEFINE_BASECLASS(zeitgeist/Node); } --- 25,63 ---- using namespace boost; using namespace kerosin; ! using namespace std; ! FUNCTION(MaterialServer,initMaterialExporter) { ! string inExporterName; ! ! if ( ! (in.GetSize() != 1) || ! (! in.GetValue(in.begin(),inExporterName)) ! ) ! { ! return false; ! } ! ! return obj->InitMaterialExporter(inExporterName); ! } ! ! FUNCTION(MaterialServer,exportAllMaterial) ! { ! if ( ! (in.GetSize() != 0) ! ) ! { ! return false; ! } ! ! obj->ExportAllMaterial(); ! return true; ! } ! ! void ! CLASS(MaterialServer)::DefineClass() ! { ! DEFINE_BASECLASS(zeitgeist/Node); ! DEFINE_FUNCTION(initMaterialExporter); ! DEFINE_FUNCTION(exportAllMaterial); } |