Panda3D

material.h

00001 // Filename: material.h
00002 // Created by:  mike (09Jan97)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #ifndef MATERIAL_H
00016 #define MATERIAL_H
00017 
00018 #include "pandabase.h"
00019 
00020 #include "typedWritableReferenceCount.h"
00021 #include "namable.h"
00022 #include "luse.h"
00023 #include "config_gobj.h"
00024 
00025 class FactoryParams;
00026 
00027 ////////////////////////////////////////////////////////////////////
00028 //       Class : Material
00029 // Description : Defines the way an object appears in the presence of
00030 //               lighting.  A material is only necessary if lighting
00031 //               is to be enabled; otherwise, the material isn't used.
00032 ////////////////////////////////////////////////////////////////////
00033 class EXPCL_PANDA_GOBJ Material : public TypedWritableReferenceCount, public Namable {
00034 PUBLISHED:
00035   INLINE Material(const string &name = "");
00036   INLINE Material(const Material &copy);
00037   void operator = (const Material &copy);
00038   INLINE ~Material();
00039 
00040   INLINE static Material *get_default();
00041   
00042   INLINE bool has_ambient() const;
00043   INLINE const Colorf &get_ambient() const;
00044   void set_ambient(const Colorf &color);
00045   INLINE void clear_ambient();
00046 
00047   INLINE bool has_diffuse() const;
00048   INLINE const Colorf &get_diffuse() const;
00049   void set_diffuse(const Colorf &color);
00050   INLINE void clear_diffuse();
00051 
00052   INLINE bool has_specular() const;
00053   INLINE const Colorf &get_specular() const;
00054   void set_specular(const Colorf &color);
00055   INLINE void clear_specular();
00056 
00057   INLINE bool has_emission() const;
00058   INLINE const Colorf &get_emission() const;
00059   void set_emission(const Colorf &color);
00060   INLINE void clear_emission();
00061 
00062   INLINE float get_shininess() const;
00063   INLINE void set_shininess(float shininess);
00064 
00065   INLINE bool get_local() const;
00066   INLINE void set_local(bool local);
00067   INLINE bool get_twoside() const;
00068   INLINE void set_twoside(bool twoside);
00069 
00070   INLINE bool operator == (const Material &other) const;
00071   INLINE bool operator != (const Material &other) const;
00072   INLINE bool operator < (const Material &other) const;
00073 
00074   int compare_to(const Material &other) const;
00075 
00076   void output(ostream &out) const;
00077   void write(ostream &out, int indent) const;
00078 
00079   INLINE bool is_attrib_locked() const;
00080   INLINE void set_attrib_lock();
00081 
00082 private:
00083   Colorf _ambient;
00084   Colorf _diffuse;
00085   Colorf _specular;
00086   Colorf _emission;
00087   float _shininess;
00088 
00089   static PT(Material) _default;
00090   
00091   enum Flags {
00092     F_ambient     = 0x001,
00093     F_diffuse     = 0x002,
00094     F_specular    = 0x004,
00095     F_emission    = 0x008,
00096     F_local       = 0x010,
00097     F_twoside     = 0x020,
00098     F_attrib_lock = 0x040
00099   };
00100   int _flags;
00101 
00102 public:
00103   static void register_with_read_factory();
00104   virtual void write_datagram(BamWriter *manager, Datagram &me);
00105 
00106 protected:
00107   static TypedWritable *make_Material(const FactoryParams &params);
00108   void fillin(DatagramIterator &scan, BamReader *manager);
00109 
00110 public:
00111   static TypeHandle get_class_type() {
00112     return _type_handle;
00113   }
00114   static void init_type() {
00115     TypedWritableReferenceCount::init_type();
00116     register_type(_type_handle, "Material",
00117                   TypedWritableReferenceCount::get_class_type());
00118   }
00119   virtual TypeHandle get_type() const {
00120     return get_class_type();
00121   }
00122   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00123 
00124 private:
00125 
00126   static TypeHandle _type_handle;
00127 };
00128 
00129 INLINE ostream &operator << (ostream &out, const Material &m) {
00130   m.output(out);
00131   return out;
00132 }
00133 
00134 #include "material.I"
00135 
00136 #endif
 All Classes Functions Variables Enumerations