Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

Material Class Reference

Defines the way an object appears in the presence of lighting. More...

#include <material.h>

Inheritance diagram for Material:

TypedWritableReferenceCount TypedWritable ReferenceCount TypedObject List of all members.

Public Member Functions

 Material ()
 Material (const Material &copy)
void operator= (const Material &copy)
 ~Material ()
bool has_ambient () const
 Returns true if the ambient color has been explicitly set for this material, false otherwise.

const Colorfget_ambient () const
 Returns the ambient color setting, if it has been set.

void set_ambient (const Colorf &color)
 Specifies the ambient color setting of the material.

void clear_ambient ()
 Removes the explicit ambient color from the material.

bool has_diffuse () const
 Returns true if the diffuse color has been explicitly set for this material, false otherwise.

const Colorfget_diffuse () const
 Returns the diffuse color setting, if it has been set.

void set_diffuse (const Colorf &color)
 Specifies the diffuse color setting of the material.

void clear_diffuse ()
 Removes the explicit diffuse color from the material.

bool has_specular () const
 Returns true if the specular color has been explicitly set for this material, false otherwise.

const Colorfget_specular () const
 Returns the specular color setting, if it has been set.

void set_specular (const Colorf &color)
 Specifies the diffuse color setting of the material.

void clear_specular ()
 Removes the explicit specular color from the material.

bool has_emission () const
 Returns true if the emission color has been explicitly set for this material, false otherwise.

const Colorfget_emission () const
 Returns the emmission color setting, if it has been set.

void set_emission (const Colorf &color)
 Specifies the emission color setting of the material.

void clear_emission ()
 Removes the explicit emission color from the material.

float get_shininess () const
 Returns the shininess exponent of the material.

void set_shininess (float shininess)
 Sets the shininess exponent of the material.

bool get_local () const
void set_local (bool local)
bool get_twoside () const
void set_twoside (bool twoside)
bool operator== (const Material &other) const
bool operator!= (const Material &other) const
bool operator< (const Material &other) const
int compare_to (const Material &other) const
 Returns a number less than zero if this material sorts before the other one, greater than zero if it sorts after, or zero if they are equivalent.

void output (ostream &out) const
void write (ostream &out, int indent) const
virtual void write_datagram (BamWriter *manager, Datagram &me)
 Function to write the important information in the particular object to a Datagram.

virtual TypeHandle get_type () const
virtual TypeHandle force_init_type ()
virtual int complete_pointers (TypedWritable **p_list, BamReader *manager)
 Receives an array of pointers, one for each time manager->read_pointer() was called in fillin().

virtual void finalize ()
 Called by the BamReader to perform any final actions needed for setting up the object after all objects have been read and all pointers have been completed.

int get_type_index () const
 Returns the internal index number associated with this object's TypeHandle, a unique number for each different type.

bool is_of_type (TypeHandle handle) const
 Returns true if the current object is or derives from the indicated type.

bool is_exact_type (TypeHandle handle) const
 Returns true if the current object is the indicated type exactly.

int get_ref_count () const
 Returns the current reference count.

int ref () const
 Explicitly increments the reference count.

int unref () const
 Explicitly decrements the reference count.

void test_ref_count_integrity () const
 Does some easy checks to make sure that the reference count isn't completely bogus.


Static Public Member Functions

void register_with_read_factory ()
 Factory method to generate a Material object.

TypeHandle get_class_type ()
void init_type ()

Static Public Attributes

TypedWritable *const Null = (TypedWritable*)0L

Protected Member Functions

void fillin (DatagramIterator &scan, BamReader *manager)
 Function that reads out of the datagram (or asks manager to read) all of the data that is needed to re-create this object and stores it in the appropiate place.


Static Protected Member Functions

TypedWritablemake_Material (const FactoryParams &params)
 Factory method to generate a Material object.


Private Types

enum  Flags {
  F_ambient = 0x001, F_diffuse = 0x002, F_specular = 0x004, F_emission = 0x008,
  F_local = 0x010, F_twoside = 0x020
}

Private Attributes

Colorf _ambient
Colorf _diffuse
Colorf _specular
Colorf _emission
float _shininess
int _flags

Static Private Attributes

TypeHandle _type_handle

Detailed Description

Defines the way an object appears in the presence of lighting.

A material is only necessary if lighting is to be enabled; otherwise, the material isn't used.

Definition at line 45 of file material.h.


Member Enumeration Documentation

enum Material::Flags [private]
 

Enumeration values:
F_ambient 
F_diffuse 
F_specular 
F_emission 
F_local 
F_twoside 

Definition at line 96 of file material.h.


Constructor & Destructor Documentation

Material::Material  )  [inline]
 

Definition at line 31 of file material.I.

References INLINE, and operator=().

Material::Material const Material &  copy  )  [inline]
 

Definition at line 44 of file material.I.

References INLINE.

Material::~Material  )  [inline]
 

Definition at line 56 of file material.I.

References _flags, F_ambient, and INLINE.


Member Function Documentation

void Material::clear_ambient  )  [inline]
 

Removes the explicit ambient color from the material.

Definition at line 100 of file material.I.

References _diffuse, _flags, Colorf, F_diffuse, INLINE, and zero.

void Material::clear_diffuse  )  [inline]
 

Removes the explicit diffuse color from the material.

Definition at line 145 of file material.I.

References _flags, and F_specular.

void Material::clear_emission  )  [inline]
 

Removes the explicit emission color from the material.

Definition at line 235 of file material.I.

References _flags, F_twoside, and INLINE.

void Material::clear_specular  )  [inline]
 

Removes the explicit specular color from the material.

Definition at line 190 of file material.I.

int Material::compare_to const Material &  other  )  const
 

Returns a number less than zero if this material sorts before the other one, greater than zero if it sorts after, or zero if they are equivalent.

The sorting order is arbitrary and largely meaningless, except to differentiate different materials.

Definition at line 196 of file material.cxx.

Referenced by set_shininess().

int TypedWritable::complete_pointers TypedWritable **  p_list,
BamReader manager
[virtual, inherited]
 

Receives an array of pointers, one for each time manager->read_pointer() was called in fillin().

Returns the number of pointers processed.

This is the callback function that is made by the BamReader at some later point, after all of the required pointers have been filled in. It is necessary because there might be forward references in a bam file; when we call read_pointer() in fillin(), the object may not have been read from the file yet, so we do not have a pointer available at that time. Thus, instead of returning a pointer, read_pointer() simply reserves a later callback. This function provides that callback. The calling object is responsible for keeping track of the number of times it called read_pointer() and extracting the same number of pointers out of the supplied vector, and storing them appropriately within the object.

Reimplemented in AnimBundleNode, AnimGroup, PartBundleNode, PartGroup, Character, CharacterJoint, CollisionNode, GeomSprite, PiecewiseCurve, ClipPlaneAttrib, FogAttrib, LensNode, LightAttrib, MaterialAttrib, RenderEffects, RenderState, TextureAttrib, Person, and Child.

Definition at line 94 of file typedWritable.cxx.

Referenced by RenderState::do_invert_compose().

void Material::fillin DatagramIterator scan,
BamReader manager
[protected]
 

Function that reads out of the datagram (or asks manager to read) all of the data that is needed to re-create this object and stores it in the appropiate place.

Reimplemented from TypedWritable.

Definition at line 341 of file material.cxx.

void TypedWritable::finalize void   )  [virtual, inherited]
 

Called by the BamReader to perform any final actions needed for setting up the object after all objects have been read and all pointers have been completed.

Reimplemented in PartBundle, RenderAttrib, RenderEffect, RenderEffects, RenderState, and TransformState.

Definition at line 112 of file typedWritable.cxx.

Referenced by BamReader::skip_pointer().

virtual TypeHandle Material::force_init_type void   )  [inline, virtual]
 

Reimplemented from TypedWritableReferenceCount.

Definition at line 126 of file material.h.

const Colorf & Material::get_ambient  )  const [inline]
 

Returns the ambient color setting, if it has been set.

Returns (0,0,0,0) if the ambient color has not been set.

Definition at line 87 of file material.I.

References _flags, F_diffuse, and INLINE.

TypeHandle Material::get_class_type void   )  [inline, static]
 

Reimplemented from TypedWritableReferenceCount.

Definition at line 115 of file material.h.

const Colorf & Material::get_diffuse  )  const [inline]
 

Returns the diffuse color setting, if it has been set.

Returns (0,0,0,0) if the diffuse color has not been set.

Definition at line 132 of file material.I.

References _flags, _specular, Colorf, F_specular, INLINE, and zero.

const Colorf & Material::get_emission  )  const [inline]
 

Returns the emmission color setting, if it has been set.

Returns (0,0,0,0) if the emmission color has not been set.

Definition at line 222 of file material.I.

References _flags, F_local, and INLINE.

bool Material::get_local  )  const [inline]
 

Definition at line 283 of file material.I.

int ReferenceCount::get_ref_count  )  const [inline, inherited]
 

Returns the current reference count.

Definition at line 183 of file referenceCount.I.

Referenced by RenderState::determine_bin_index(), RenderEffects::determine_show_bounds(), FontPool::ns_garbage_collect(), TexturePool::ns_garbage_collect(), MaterialPool::ns_get_material(), and TexturePool::ns_release_texture().

float Material::get_shininess  )  const [inline]
 

Returns the shininess exponent of the material.

Definition at line 248 of file material.I.

References _flags, and F_twoside.

const Colorf & Material::get_specular  )  const [inline]
 

Returns the specular color setting, if it has been set.

Returns (0,0,0,0) if the specular color has not been set.

Definition at line 177 of file material.I.

References _flags, F_emission, and INLINE.

Referenced by set_emission().

bool Material::get_twoside  )  const [inline]
 

Definition at line 311 of file material.I.

virtual TypeHandle Material::get_type void   )  const [inline, virtual]
 

Reimplemented from TypedWritableReferenceCount.

Definition at line 123 of file material.h.

References INLINE, and output().

int TypedObject::get_type_index  )  const [inline, inherited]
 

Returns the internal index number associated with this object's TypeHandle, a unique number for each different type.

This is equivalent to get_type().get_index().

Definition at line 71 of file typedObject.I.

References TypeHandle::get_name(), TypedObject::get_type(), and INLINE.

bool Material::has_ambient  )  const [inline]
 

Returns true if the ambient color has been explicitly set for this material, false otherwise.

Definition at line 70 of file material.I.

References _ambient, _flags, and F_ambient.

bool Material::has_diffuse  )  const [inline]
 

Returns true if the diffuse color has been explicitly set for this material, false otherwise.

Definition at line 115 of file material.I.

References _flags, F_specular, and INLINE.

bool Material::has_emission  )  const [inline]
 

Returns true if the emission color has been explicitly set for this material, false otherwise.

Definition at line 205 of file material.I.

bool Material::has_specular  )  const [inline]
 

Returns true if the specular color has been explicitly set for this material, false otherwise.

Definition at line 160 of file material.I.

References _emission, _flags, Colorf, F_emission, INLINE, and zero.

void Material::init_type void   )  [inline, static]
 

Reimplemented from TypedWritableReferenceCount.

Definition at line 118 of file material.h.

bool TypedObject::is_exact_type TypeHandle  handle  )  const [inline, inherited]
 

Returns true if the current object is the indicated type exactly.

Definition at line 101 of file typedObject.I.

Referenced by PT(), and CollisionNode::xform().

bool TypedObject::is_of_type TypeHandle  handle  )  const [inline, inherited]
 

Returns true if the current object is or derives from the indicated type.

Definition at line 86 of file typedObject.I.

Referenced by EggMaterialCollection::collapse_equivalent_materials(), EggTextureCollection::collapse_equivalent_textures(), DeferredNodeProperty::compose(), AnimBundleMaker::create_s_channel(), CharacterMaker::create_slider(), ProjectionScreen::cull_callback(), DataNode::define_output(), EggNode::determine_draw_order(), CharacterMaker::egg_to_index(), EggGroupUniquifier::EggGroupUniquifier(), EggPoolUniquifier::EggPoolUniquifier(), EggGroupNode::find_textures(), StaticTextFont::get_glyph(), EggMaterialCollection::insert_materials(), EggTextureCollection::insert_textures(), CharacterJoint::make_copy(), PT(), EggGroupNode::r_flatten_transforms(), EggGroupNode::r_transform_vertices(), EggGroupNode::recompute_polygon_normals(), CollisionLevelState::reserve(), PandaFramework::reset_frame_rate(), PandaFramework::set_texture(), EggGroupNode::steal_children(), and DataGraphTraverser::traverse().

TypedWritable * Material::make_Material const FactoryParams params  )  [static, protected]
 

Factory method to generate a Material object.

Definition at line 316 of file material.cxx.

bool Material::operator!= const Material &  other  )  const [inline]
 

Definition at line 351 of file material.I.

bool Material::operator< const Material &  other  )  const [inline]
 

Definition at line 363 of file material.I.

void Material::operator= const Material &  copy  ) 
 

Definition at line 48 of file material.cxx.

Referenced by Material().

bool Material::operator== const Material &  other  )  const [inline]
 

Definition at line 339 of file material.I.

void Material::output ostream &  out  )  const
 

Definition at line 227 of file material.cxx.

References _ambient, _diffuse, _emission, _flags, _shininess, _specular, Datagram::add_float32(), and Datagram::add_int32().

Referenced by get_type().

int ReferenceCount::ref  )  const [inline, inherited]
 

Explicitly increments the reference count.

User code should avoid using ref() and unref() directly, which can result in missed reference counts. Instead, let a PointerTo object manage the reference counting automatically.

This function is const, even though it changes the object, because generally fiddling with an object's reference count isn't considered part of fiddling with the object. An object might be const in other ways, but we still need to accurately count the number of references to it.

The return value is the new reference count.

Definition at line 225 of file referenceCount.I.

Referenced by ClientDevice::ClientDevice(), EggGroupNode::find_textures(), EggGroupNode::r_apply_texmats(), EggGroupNode::r_flatten_transforms(), and EggGroupNode::reverse_vertex_ordering().

void Material::register_with_read_factory void   )  [static]
 

Factory method to generate a Material object.

Definition at line 283 of file material.cxx.

void Material::set_ambient const Colorf color  ) 
 

Specifies the ambient color setting of the material.

This will be the multiplied by any ambient lights in effect on the material to set its base color.

This is the color of the object as it appears in the absence of direct light.

If this is not set, the object color will be used.

Definition at line 80 of file material.cxx.

References _diffuse, _flags, and F_diffuse.

void Material::set_diffuse const Colorf color  ) 
 

Specifies the diffuse color setting of the material.

This will be multiplied by any lights in effect on the material to get the color in the parts of the object illuminated by the lights.

This is the primary color of an object; the color of the object as it appears in direct light, in the absence of highlights.

If this is not set, the object color will be used.

Definition at line 112 of file material.cxx.

References _emission, _flags, and F_emission.

void Material::set_emission const Colorf color  ) 
 

Specifies the emission color setting of the material.

This is the color of the object as it appears in the absence of any light whatsover, including ambient light. It is as if the object is glowing by this color (although of course it will not illuminate neighboring objects).

If this is not set, the object will not glow by its own light and will only appear visible in the presence of one or more lights.

Definition at line 174 of file material.cxx.

References get_specular().

void Material::set_local bool  local  )  [inline]
 

Definition at line 295 of file material.I.

void Material::set_shininess float  shininess  )  [inline]
 

Sets the shininess exponent of the material.

This controls the size of the specular highlight spot. In general, larger number produce a smaller specular highlight, which makes the object appear shinier. Smaller numbers produce a larger highlight, which makes the object appear less shiny.

Definition at line 271 of file material.I.

References compare_to().

void Material::set_specular const Colorf color  ) 
 

Specifies the diffuse color setting of the material.

This will be multiplied by any lights in effect on the material to compute the color of specular highlights on the object.

This is the highlight color of an object: the color of small highlight reflections.

If this is not set, highlights will not appear.

Definition at line 142 of file material.cxx.

void Material::set_twoside bool  twoside  )  [inline]
 

Definition at line 323 of file material.I.

void ReferenceCount::test_ref_count_integrity  )  const [inline, inherited]
 

Does some easy checks to make sure that the reference count isn't completely bogus.

Definition at line 328 of file referenceCount.I.

References INLINE.

Referenced by EggNode::determine_bin(), and ReferenceCount::~ReferenceCount().

int ReferenceCount::unref  )  const [inline, inherited]
 

Explicitly decrements the reference count.

Note that the object will not be implicitly deleted by unref() simply because the reference count drops to zero. (Having a member function delete itself is problematic; plus, we don't have a virtual destructor anyway.) However, see the helper function unref_delete().

User code should avoid using ref() and unref() directly, which can result in missed reference counts. Instead, let a PointerTo object manage the reference counting automatically.

This function is const, even though it changes the object, because generally fiddling with an object's reference count isn't considered part of fiddling with the object. An object might be const in other ways, but we still need to accurately count the number of references to it.

The return value is the new reference count.

Definition at line 293 of file referenceCount.I.

References INLINE.

Referenced by RenderState::determine_bin_index(), and RenderEffects::determine_show_bounds().

void Material::write ostream &  out,
int  indent
const
 

Definition at line 254 of file material.cxx.

References _ambient, _diffuse, _emission, _flags, _shininess, _specular, DatagramIterator::get_float32(), and DatagramIterator::get_int32().

void Material::write_datagram BamWriter manager,
Datagram me
[virtual]
 

Function to write the important information in the particular object to a Datagram.

Implements TypedWritableReferenceCount.

Definition at line 298 of file material.cxx.


Member Data Documentation

Colorf Material::_ambient [private]
 

Definition at line 90 of file material.h.

Referenced by has_ambient(), output(), and write().

Colorf Material::_diffuse [private]
 

Definition at line 91 of file material.h.

Referenced by clear_ambient(), output(), set_ambient(), and write().

Colorf Material::_emission [private]
 

Definition at line 93 of file material.h.

Referenced by has_specular(), output(), set_diffuse(), and write().

int Material::_flags [private]
 

Definition at line 104 of file material.h.

Referenced by clear_ambient(), clear_diffuse(), clear_emission(), get_ambient(), get_diffuse(), get_emission(), get_shininess(), get_specular(), has_ambient(), has_diffuse(), has_specular(), output(), set_ambient(), set_diffuse(), write(), and ~Material().

float Material::_shininess [private]
 

Definition at line 94 of file material.h.

Referenced by output(), and write().

Colorf Material::_specular [private]
 

Definition at line 92 of file material.h.

Referenced by get_diffuse(), output(), and write().

TypeHandle Material::_type_handle [static, private]
 

Reimplemented from TypedWritableReferenceCount.

Definition at line 38 of file material.cxx.

TypedWritable *const TypedWritable::Null = (TypedWritable*)0L [static, inherited]
 

Definition at line 25 of file typedWritable.cxx.

Referenced by Child::complete_pointers(), Parent::complete_pointers(), Person::complete_pointers(), LoaderFileTypeBam::get_extension(), PartGroup::pick_channel_index(), BamReader::read_pointer(), and AnimGroup::write_datagram().


The documentation for this class was generated from the following files:
Generated on Fri May 2 00:52:07 2003 for Panda by doxygen1.3