00001 /* **-*-c++-*-************************************************************** 00002 Copyright (C)1996 David Jung <opensim@pobox.com> 00003 00004 This program/file is free software; you can redistribute it and/or modify 00005 it under the terms of the GNU General Public License as published by 00006 the Free Software Foundation; either version 2 of the License, or 00007 (at your option) any later version. 00008 00009 This program is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 GNU General Public License for more details. (http://www.gnu.org) 00013 00014 You should have received a copy of the GNU General Public License 00015 along with this program; if not, write to the Free Software 00016 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 00018 $Id: Material 1031 2004-02-11 20:46:36Z jungd $ 00019 $Revision: 1.6 $ 00020 $Date: 2004-02-11 15:46:36 -0500 (Wed, 11 Feb 2004) $ 00021 $Author: jungd $ 00022 00023 ****************************************************************************/ 00024 00025 #ifndef _PHYSICS_MATERIAL_ 00026 #define _PHYSICS_MATERIAL_ 00027 00028 #include <base/base> 00029 #include <base/Externalizable> 00030 #include <base/Dimension3> 00031 #include <base/PathName> 00032 #include <gfx/Color4> 00033 #include <physics/Shape> 00034 00035 #include <osg/StateSet> 00036 00037 #include <string> 00038 00039 00040 namespace physics { 00041 00042 00043 class Material : public base::ReferencedObject, public base::Externalizable 00044 { 00045 public: 00046 Material(const String& label="plastic", const gfx::Color4& color = gfx::Color4("green")); 00047 Material(const Material& m); 00048 virtual ~Material(); 00049 00050 virtual String className() const { return String("Material"); } 00051 virtual Object& clone() const { return *NewNamedObj(className()) Material(*this); } 00052 00053 virtual void setBaseColor(const gfx::Color4& color) { mBaseColor = color; stateSetCached=false; } 00054 virtual void setBaseColor(const String& color) { mBaseColor = gfx::Color4(color); stateSetCached=false; } 00055 virtual const gfx::Color4& baseColor() const { return mBaseColor; } 00056 00057 virtual void setDensity(Real density) { mDensity=density; } 00058 virtual Real density() const { return mDensity; } 00059 00060 virtual void setSurfaceAppearance(const base::PathName& image); 00061 00062 virtual osg::ref_ptr<osg::StateSet> createState() const; 00063 00064 // Externalizable 00065 virtual bool formatSupported(const String format, Real version = 1.0, ExternalizationType type = IO) const 00066 { return ( (format=="xml") && (version==1.0) ); } 00067 virtual void externalize(base::Externalizer& e, String format = "", Real version = 1.0); 00068 00069 protected: 00070 String label; 00071 00072 Real mDensity; 00073 00074 enum SurfaceAppearanceType { BaseColor, TextureImage }; 00075 00076 SurfaceAppearanceType surfaceAppearanceType; 00077 00078 gfx::Color4 mBaseColor; 00079 base::PathName surfaceTextureImage; 00080 00081 // cache osg::StateSet 00082 mutable bool stateSetCached; 00083 mutable osg::ref_ptr<osg::StateSet> stateSet; 00084 00085 }; 00086 00087 00088 } // physics 00089 00090 #endif