Panda3D
material.h
1 // Filename: material.h
2 // Created by: mike (09Jan97)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef MATERIAL_H
16 #define MATERIAL_H
17 
18 #include "pandabase.h"
19 
20 #include "typedWritableReferenceCount.h"
21 #include "namable.h"
22 #include "luse.h"
23 #include "numeric_types.h"
24 #include "config_gobj.h"
25 
26 class FactoryParams;
27 
28 ////////////////////////////////////////////////////////////////////
29 // Class : Material
30 // Description : Defines the way an object appears in the presence of
31 // lighting. A material is only necessary if lighting
32 // is to be enabled; otherwise, the material isn't used.
33 ////////////////////////////////////////////////////////////////////
34 class EXPCL_PANDA_GOBJ Material : public TypedWritableReferenceCount, public Namable {
35 PUBLISHED:
36  INLINE explicit Material(const string &name = "");
37  INLINE Material(const Material &copy);
38  void operator = (const Material &copy);
39  INLINE ~Material();
40 
41  INLINE static Material *get_default();
42 
43  INLINE bool has_ambient() const;
44  INLINE const LColor &get_ambient() const;
45  void set_ambient(const LColor &color);
46  INLINE void clear_ambient();
47 
48  INLINE bool has_diffuse() const;
49  INLINE const LColor &get_diffuse() const;
50  void set_diffuse(const LColor &color);
51  INLINE void clear_diffuse();
52 
53  INLINE bool has_specular() const;
54  INLINE const LColor &get_specular() const;
55  void set_specular(const LColor &color);
56  INLINE void clear_specular();
57 
58  INLINE bool has_emission() const;
59  INLINE const LColor &get_emission() const;
60  void set_emission(const LColor &color);
61  INLINE void clear_emission();
62 
63  INLINE PN_stdfloat get_shininess() const;
64  INLINE void set_shininess(PN_stdfloat shininess);
65 
66  INLINE bool get_local() const;
67  INLINE void set_local(bool local);
68  INLINE bool get_twoside() const;
69  INLINE void set_twoside(bool twoside);
70 
71  INLINE bool operator == (const Material &other) const;
72  INLINE bool operator != (const Material &other) const;
73  INLINE bool operator < (const Material &other) const;
74 
75  int compare_to(const Material &other) const;
76 
77  void output(ostream &out) const;
78  void write(ostream &out, int indent) const;
79 
80  INLINE bool is_attrib_locked() const;
81  INLINE void set_attrib_lock();
82 
83 private:
84  LColor _ambient;
85  LColor _diffuse;
86  LColor _specular;
87  LColor _emission;
88  PN_stdfloat _shininess;
89 
90  static PT(Material) _default;
91 
92  enum Flags {
93  F_ambient = 0x001,
94  F_diffuse = 0x002,
95  F_specular = 0x004,
96  F_emission = 0x008,
97  F_local = 0x010,
98  F_twoside = 0x020,
99  F_attrib_lock = 0x040
100  };
101  int _flags;
102 
103 public:
104  static void register_with_read_factory();
105  virtual void write_datagram(BamWriter *manager, Datagram &me);
106 
107 protected:
108  static TypedWritable *make_Material(const FactoryParams &params);
109  void fillin(DatagramIterator &scan, BamReader *manager);
110 
111 public:
112  static TypeHandle get_class_type() {
113  return _type_handle;
114  }
115  static void init_type() {
116  TypedWritableReferenceCount::init_type();
117  register_type(_type_handle, "Material",
118  TypedWritableReferenceCount::get_class_type());
119  }
120  virtual TypeHandle get_type() const {
121  return get_class_type();
122  }
123  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
124 
125 private:
126 
127  static TypeHandle _type_handle;
128 };
129 
130 INLINE ostream &operator << (ostream &out, const Material &m) {
131  m.output(out);
132  return out;
133 }
134 
135 #include "material.I"
136 
137 #endif
void output(ostream &out) const
Outputs the Namable.
Definition: namable.I:97
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:122
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:37
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:73
virtual void fillin(DatagramIterator &scan, BamReader *manager)
This internal function is intended to be called by each class&#39;s make_from_bam() method to read in all...
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
A base class for all things which can have a name.
Definition: namable.h:29
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:40
A base class for things which need to inherit from both TypedWritable and from ReferenceCount.
Defines the way an object appears in the presence of lighting.
Definition: material.h:34
This is the base class for all three-component vectors and points.
Definition: lvecBase4.h:111
An STL function object class, this is intended to be used on any ordered collection of class objects ...
Definition: stl_compares.h:79
A class to retrieve the individual data elements previously stored in a Datagram. ...
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:43