Panda3D
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Protected Member Functions | Static Protected Member Functions | Friends

Palettizer Class Reference

This is the main engine behind egg-palettize. More...

#include "palettizer.h"

Inheritance diagram for Palettizer:
TypedWritable TypedObject MemoryBase

List of all members.

Public Types

enum  RemapUV { RU_never, RU_group, RU_poly, RU_invalid }

Public Member Functions

void add_command_line_egg (EggFile *egg_file)
 Adds the indicated EggFile to the list of eggs that are considered to have been read on the command line.
void all_params_set ()
 Called after all command line parameters have been set up, this is a hook to do whatever initialization is necessary.
virtual ReferenceCountas_reference_count ()
 Returns the pointer cast to a ReferenceCount pointer, if it is in fact of that type.
TypedObjectas_typed_object ()
 Returns the object, upcast (if necessary) to a TypedObject pointer.
const TypedObjectas_typed_object () const
 Returns the object, upcast (if necessary) to a TypedObject pointer.
virtual int complete_pointers (TypedWritable **p_list, BamReader *manager)
 Called after the object is otherwise completely read from a Bam file, this function's job is to store the pointers that were retrieved from the Bam file for each pointer object written.
string encode_to_bam_stream () const
 Converts the TypedWritable object into a single stream of data using a BamWriter, and returns that data as a string string.
bool encode_to_bam_stream (string &data, BamWriter *writer=NULL) const
 Converts the TypedWritable object into a single stream of data using a BamWriter, and stores that data in the indicated string.
virtual void finalize (BamReader *manager)
 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.
virtual TypeHandle force_init_type ()
void generate_images (bool redo_all)
 Actually generates the appropriate palette and unplaced texture images into the map directories.
UpdateSeq get_bam_modified () const
 Returns the current bam_modified counter.
int get_best_parent_from_Set (const std::set< int > &) const
PaletteGroupget_default_group ()
 Returns the default group to which an egg file should be assigned if it is not mentioned in the .txa file.
EggFileget_egg_file (const string &name)
 Returns the EggFile with the given name.
bool get_noabs () const
 Returns the current setting of the noabs flag.
PaletteGroupget_palette_group (const string &name)
 Returns the PaletteGroup with the given name.
TextureImageget_texture (const string &name)
 Returns the TextureImage with the given name.
virtual TypeHandle get_type () const
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_exact_type (TypeHandle handle) const
 Returns true if the current object is the indicated type exactly.
bool is_of_type (TypeHandle handle) const
 Returns true if the current object is or derives from the indicated type.
bool is_valid () const
 Returns true if the palette information file was read correctly, or false if there was some error and the palettization can't continue.
void mark_bam_modified ()
 Increments the bam_modified counter, so that this object will be invalidated and retransmitted on any open bam streams.
void operator delete (void *ptr)
void operator delete (void *ptr, void *)
void operator delete[] (void *ptr)
void operator delete[] (void *, void *)
void * operator new (size_t size)
void * operator new (size_t size, void *ptr)
void * operator new[] (size_t size, void *ptr)
void * operator new[] (size_t size)
void optimal_resize ()
 Attempts to resize each PalettteImage down to its smallest possible size.
void process_all (bool force_texture_read, const Filename &state_filename)
 Reprocesses all textures known.
void process_command_line_eggs (bool force_texture_read, const Filename &state_filename)
 Processes all the textures named in the _command_line_eggs, placing them on the appropriate palettes or whatever needs to be done with them.
bool read_stale_eggs (bool redo_all)
 Reads in any egg file that is known to be stale, even if it was not listed on the command line, so that it may be updated and written out when write_eggs() is called.
void read_txa_file (istream &txa_file, const string &txa_filename)
 Reads in the .txa file and keeps it ready for matching textures and egg files.
bool remove_egg_file (const string &name)
 Removes the named egg file from the database, if it exists.
void report_pi () const
 Output a verbose description of all the palettization information to standard output, for the user's perusal.
void report_statistics () const
 Output a report of the palettization effectiveness, texture memory utilization, and so on.
virtual bool require_fully_complete () const
 Some objects require all of their nested pointers to have been completed before the objects themselves can be completed.
void reset_images ()
 Throws away all of the current PaletteImages, so that new ones may be created (and the packing made more optimal).
void set_noabs (bool noabs)
 Changes the current setting of the noabs flag.
PaletteGrouptest_palette_group (const string &name) const
 Returns the PaletteGroup with the given name.
virtual void update_bam_nested (BamWriter *manager)
 Called by the BamWriter when this object has not itself been modified recently, but it should check its nested objects for updates.
virtual void write_datagram (BamWriter *writer, Datagram &datagram)
 Fills the indicated datagram up with a binary representation of the current object, in preparation for writing to a Bam file.
bool write_eggs ()
 Adjusts the egg files to reference the newly generated textures, and writes them out.

Static Public Member Functions

static bool decode_raw_from_bam_stream (TypedWritable *&ptr, ReferenceCount *&ref_ptr, const string &data, BamReader *reader=NULL)
 Reads the string created by a previous call to encode_to_bam_stream(), and extracts the single object on that string.
static TypeHandle get_class_type ()
static void init_type ()
 This function is declared non-inline to work around a compiler bug in g++ 2.96.
static void register_with_read_factory ()
 Registers the current object as something that can be read from a Bam file.
static RemapUV string_remap (const string &str)
 Returns the RemapUV code corresponding to the indicated string, or RU_invalid if the string is invalid.

Public Attributes

bool _aggressively_clean_mapdir
PNMFileType_alpha_type
Colord _background
PNMFileType_color_type
double _coverage_threshold
EggRenderMode::AlphaMode _cutout_mode
double _cutout_ratio
string _default_groupdir
string _default_groupname
bool _force_power_2
string _generated_image_pattern
bool _is_valid
string _map_dirname
int _margin
bool _noabs
bool _omit_everything
bool _omit_solitary
int _pal_x_size
int _pal_y_size
Filename _rel_dirname
RemapUV _remap_char_uv
RemapUV _remap_uv
double _round_fuzz
double _round_unit
bool _round_uvs
PNMFileType_shadow_alpha_type
PNMFileType_shadow_color_type
Filename _shadow_dirname
TxaFile _txa_file

Static Public Attributes

static int _min_pi_version = 8
static int _pi_version = 20
static int _read_pi_version = 0
static TypedWritable *const Null = (TypedWritable*)0L

Protected Member Functions

void fillin (DatagramIterator &scan, BamReader *manager)
 Reads the binary data from the given datagram iterator, which was written by a previous call to write_datagram().

Static Protected Member Functions

static TypedWritablemake_Palettizer (const FactoryParams &params)
 This method is called by the BamReader when an object of this type is encountered in a Bam file; it should allocate and return a new object with all the data read.

Friends

class TxaLine

Detailed Description

This is the main engine behind egg-palettize.

It contains all of the program parameters, from the command line or saved from a previous session, and serves as the driving force in the actual palettizing process.

Definition at line 43 of file palettizer.h.


Member Function Documentation

void Palettizer::add_command_line_egg ( EggFile egg_file)

Adds the indicated EggFile to the list of eggs that are considered to have been read on the command line.

These will be processed by process_command_line_eggs().

Definition at line 836 of file palettizer.cxx.

void Palettizer::all_params_set ( )

Called after all command line parameters have been set up, this is a hook to do whatever initialization is necessary.

Definition at line 423 of file palettizer.cxx.

References PaletteGroup::setup_shadow_images().

ReferenceCount * TypedWritable::as_reference_count ( ) [virtual, inherited]

Returns the pointer cast to a ReferenceCount pointer, if it is in fact of that type.

Reimplemented in PandaNode, and TypedWritableReferenceCount.

Definition at line 155 of file typedWritable.cxx.

Referenced by BamReader::change_pointer(), BamReader::register_change_this(), and BamReader::resolve().

TypedObject * TypedObject::as_typed_object ( ) [inline, inherited]

Returns the object, upcast (if necessary) to a TypedObject pointer.

Definition at line 99 of file typedObject.I.

const TypedObject * TypedObject::as_typed_object ( ) const [inline, inherited]

Returns the object, upcast (if necessary) to a TypedObject pointer.

Definition at line 110 of file typedObject.I.

int Palettizer::complete_pointers ( TypedWritable **  p_list,
BamReader manager 
) [virtual]

Called after the object is otherwise completely read from a Bam file, this function's job is to store the pointers that were retrieved from the Bam file for each pointer object written.

The return value is the number of pointers processed from the list.

Reimplemented from TypedWritable.

Definition at line 1066 of file palettizer.cxx.

bool TypedWritable::decode_raw_from_bam_stream ( TypedWritable *&  ptr,
ReferenceCount *&  ref_ptr,
const string &  data,
BamReader reader = NULL 
) [static, inherited]

Reads the string created by a previous call to encode_to_bam_stream(), and extracts the single object on that string.

Returns true on success, false on on error.

This variant sets the TypedWritable and ReferenceCount pointers separately; both are pointers to the same object. The reference count is not incremented; it is the caller's responsibility to manage the reference count.

Note that this method cannot be used to retrieve objects that do not inherit from ReferenceCount, because these objects cannot persist beyond the lifetime of the BamReader that reads them. To retrieve these objects from a bam stream, you must construct a BamReader directly.

If you happen to know that the particular object in question inherits from TypedWritableReferenceCount or PandaNode, consider calling the variant of decode_from_bam_stream() defined for those methods, which presents a simpler interface.

Definition at line 353 of file typedWritable.cxx.

References BamReader::init(), DatagramInputFile::open(), DatagramInputFile::read_header(), BamReader::read_object(), ReferenceCount::ref(), BamReader::resolve(), BamReader::set_source(), and ReferenceCount::unref().

string TypedWritable::encode_to_bam_stream ( ) const [inline, inherited]

Converts the TypedWritable object into a single stream of data using a BamWriter, and returns that data as a string string.

Returns empty string on failure.

This is a convenience method particularly useful for cases when you are only serializing a single object. If you have many objects to process, it is more efficient to use the same BamWriter to serialize all of them together.

Definition at line 86 of file typedWritable.I.

bool TypedWritable::encode_to_bam_stream ( string &  data,
BamWriter writer = NULL 
) const [inherited]

Converts the TypedWritable object into a single stream of data using a BamWriter, and stores that data in the indicated string.

Returns true on success, false on failure.

This is a convenience method particularly useful for cases when you are only serializing a single object. If you have many objects to process, it is more efficient to use the same BamWriter to serialize all of them together.

Definition at line 283 of file typedWritable.cxx.

References BamWriter::init(), DatagramOutputFile::open(), BamWriter::set_target(), DatagramOutputFile::write_header(), and BamWriter::write_object().

void Palettizer::fillin ( DatagramIterator scan,
BamReader manager 
) [protected, virtual]
void Palettizer::finalize ( BamReader manager) [virtual]

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 from TypedWritable.

Definition at line 1129 of file palettizer.cxx.

References TextureImage::is_used().

void Palettizer::generate_images ( bool  redo_all)

Actually generates the appropriate palette and unplaced texture images into the map directories.

If redo_all is true, this forces a regeneration of each image file.

Definition at line 669 of file palettizer.cxx.

References TextureImage::copy_unplaced(), and PaletteGroup::update_images().

UpdateSeq TypedWritable::get_bam_modified ( ) const [inline, inherited]

Returns the current bam_modified counter.

This counter is normally incremented automatically whenever the object is modified.

Definition at line 66 of file typedWritable.I.

Referenced by BamWriter::consider_update(), and BamWriter::write_pointer().

PaletteGroup * Palettizer::get_default_group ( )

Returns the default group to which an egg file should be assigned if it is not mentioned in the .txa file.

Definition at line 884 of file palettizer.cxx.

References get_palette_group(), PaletteGroup::has_dirname(), and PaletteGroup::set_dirname().

Referenced by EggFile::from_command_line().

EggFile * Palettizer::get_egg_file ( const string &  name)

Returns the EggFile with the given name.

If there is no EggFile with the indicated name, creates one. This is the key name used to sort the egg files, which is typically the basename of the filename.

Definition at line 795 of file palettizer.cxx.

bool Palettizer::get_noabs ( ) const

Returns the current setting of the noabs flag.

See set_noabs().

Definition at line 144 of file palettizer.cxx.

PaletteGroup * Palettizer::get_palette_group ( const string &  name)

Returns the PaletteGroup with the given name.

If there is no PaletteGroup with the indicated name, creates one.

Definition at line 848 of file palettizer.cxx.

Referenced by get_default_group().

TextureImage * Palettizer::get_texture ( const string &  name)

Returns the TextureImage with the given name.

If there is no TextureImage with the indicated name, creates one. This is the key name used to sort the textures, which is typically the basename of the primary filename.

Definition at line 902 of file palettizer.cxx.

Referenced by TextureReference::from_egg(), and PaletteGroup::prepare().

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 52 of file typedObject.I.

References TypeHandle::get_index().

static void Palettizer::init_type ( ) [inline, static]

This function is declared non-inline to work around a compiler bug in g++ 2.96.

Making it inline seems to cause problems in the optimizer.

Reimplemented from TypedWritable.

Definition at line 173 of file palettizer.h.

bool TypedObject::is_exact_type ( TypeHandle  handle) const [inline, inherited]
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 63 of file typedObject.I.

References TypeHandle::is_derived_from().

Referenced by EggSliderData::add_back_pointer(), EggJointData::add_back_pointer(), CIntervalManager::add_c_interval(), XFileNode::add_child(), CollisionTraverser::add_collider(), CollisionHandlerPhysical::add_collider(), EggXfmSAnim::add_data(), CharacterJointBundle::add_node(), NonlinearImager::add_screen(), EggGroupNode::apply_first_attribute(), EggGroupNode::apply_last_attribute(), DeferredNodeProperty::apply_to_node(), RecorderController::begin_playback(), NodePath::clear_clip_plane(), EggGroupNode::clear_connected_shading(), NodePath::clear_light(), EggBase::convert_paths(), NodePath::decode_from_bam_stream(), VrpnClient::disconnect_device(), PhysicsManager::do_physics(), GraphicsStateGuardian::fetch_specified_part(), EggRenderState::fill_state(), AnimBundleNode::find_anim_bundle(), EggGroupNode::find_coordsys_entry(), XFile::find_data_object(), Character::find_joint(), EggGroupNode::find_materials(), Character::find_slider(), XFile::find_template(), EggGroupNode::find_textures(), EggMaterialCollection::find_used_materials(), EggTextureCollection::find_used_textures(), EggGroupNode::force_filenames(), EggJointData::force_initial_rest_frame(), WindowFramework::get_aspect_2d(), EggPoolUniquifier::get_category(), EggGroupUniquifier::get_category(), EggGroupNode::get_connected_shading(), PandaFramework::get_mouse(), FactoryParams::get_param_of_type(), EggGroupNode::has_absolute_pathnames(), NodePath::has_clip_plane(), NodePath::has_clip_plane_off(), NodePath::has_light(), PandaFramework::hide_collision_solids(), x11GraphicsWindow::open_window(), eglGraphicsWindow::open_window(), EggNode::parse_egg(), CharacterMaker::part_to_node(), EggGroupNode::post_apply_flat_attribute(), EggBinner::prepare_node(), PortalClipper::prepare_portal(), NodePath::project_texture(), EggMatrixTablePointer::quantize_channels(), ParametricCurveCollection::r_add_curves(), SceneGraphReducer::r_collect_vertex_data(), EggGroupNode::r_load_externals(), EggGroupNode::rebuild_vertex_pools(), EggGroupNode::recompute_polygon_normals(), EggGroupNode::remove_invalid_primitives(), EggGroupNode::remove_unused_vertices(), EggLoader::reparent_decals(), EggMaterialCollection::replace_materials(), EggTextureCollection::replace_textures(), EggGroupNode::resolve_filenames(), EggGroupNode::reverse_vertex_ordering(), NodePath::set_clip_plane(), NodePath::set_clip_plane_off(), NodePath::set_light(), ProjectionScreen::set_projector(), NonlinearImager::set_source_camera(), EggXfmSAnim::set_value(), NonlinearImager::set_viewer_camera(), PandaFramework::show_collision_solids(), BamCache::store(), XFileToEggConverter::strip_nodes(), EggGroupNode::strip_normals(), DataGraphTraverser::traverse(), DataGraphTraverser::traverse_below(), EggGroupNode::triangulate_polygons(), EggGroupNode::unify_attributes(), EggNameUniquifier::uniquify(), NodeCullCallbackData::upcall(), PhysicsCollisionHandler::validate_target(), EggXfmSAnim::write(), EggGroup::write(), EggToDXFLayer::write_3d_face(), and EggToDXFLayer::write_entities().

bool Palettizer::is_valid ( ) const

Returns true if the palette information file was read correctly, or false if there was some error and the palettization can't continue.

Definition at line 175 of file palettizer.cxx.

TypedWritable * Palettizer::make_Palettizer ( const FactoryParams params) [static, protected]

This method is called by the BamReader when an object of this type is encountered in a Bam file; it should allocate and return a new object with all the data read.

Definition at line 1189 of file palettizer.cxx.

References fillin(), and BamReader::register_finalize().

Referenced by register_with_read_factory().

void TypedWritable::mark_bam_modified ( ) [inline, inherited]
void Palettizer::optimal_resize ( )

Attempts to resize each PalettteImage down to its smallest possible size.

Definition at line 636 of file palettizer.cxx.

References PaletteGroup::optimal_resize().

void Palettizer::process_all ( bool  force_texture_read,
const Filename state_filename 
)
void Palettizer::process_command_line_eggs ( bool  force_texture_read,
const Filename state_filename 
)

Processes all the textures named in the _command_line_eggs, placing them on the appropriate palettes or whatever needs to be done with them.

If force_texture_read is true, it forces each texture image file to be read (and thus legitimately checked for grayscaleness etc.) before placing.

Definition at line 444 of file palettizer.cxx.

References TextureImage::assign_groups(), TextureImage::determine_placement_size(), EggFile::get_textures(), TextureImage::is_newer_than(), TextureImage::mark_texture_named(), TxaFile::match_egg(), TxaFile::match_texture(), PaletteGroup::place_all(), TextureImage::post_txa_file(), EggFile::post_txa_file(), TextureImage::pre_txa_file(), EggFile::pre_txa_file(), TextureImage::read_header(), TextureImage::read_source_image(), EggFile::scan_textures(), and PaletteGroup::update_unknown_textures().

bool Palettizer::read_stale_eggs ( bool  redo_all)

Reads in any egg file that is known to be stale, even if it was not listed on the command line, so that it may be updated and written out when write_eggs() is called.

If redo_all is true, this even reads egg files that were not flagged as stale.

Returns true if successful, or false if there was some error.

Definition at line 696 of file palettizer.cxx.

References EggFile::choose_placements(), EggFile::get_source_filename(), EggFile::had_data(), EggFile::is_stale(), FilenameUnifier::make_user_filename(), EggFile::read_egg(), EggFile::release_egg_data(), EggFile::remove_egg(), EggFile::scan_textures(), and Filename::unlink().

void Palettizer::read_txa_file ( istream &  txa_file,
const string &  txa_filename 
)

Reads in the .txa file and keeps it ready for matching textures and egg files.

Definition at line 367 of file palettizer.cxx.

References PaletteGroup::clear_depends(), TxaFile::read(), PaletteGroup::reset_dependency_level(), PaletteGroup::set_dependency_level(), PaletteGroup::set_dependency_order(), and PaletteGroup::set_dirname().

void Palettizer::register_with_read_factory ( ) [static]

Registers the current object as something that can be read from a Bam file.

Definition at line 988 of file palettizer.cxx.

References BamReader::get_factory(), and make_Palettizer().

bool Palettizer::remove_egg_file ( const string &  name)

Removes the named egg file from the database, if it exists.

Returns true if the egg file was found, false if it was not.

Definition at line 815 of file palettizer.cxx.

References EggFile::remove_egg().

void Palettizer::report_pi ( ) const
void Palettizer::report_statistics ( ) const

Output a report of the palettization effectiveness, texture memory utilization, and so on.

Definition at line 309 of file palettizer.cxx.

References PaletteGroup::get_complete_placements(), PaletteGroup::get_groups(), PaletteGroup::get_placements(), PaletteGroups::make_complete(), and PaletteGroups::size().

bool TypedWritable::require_fully_complete ( ) const [virtual, inherited]

Some objects require all of their nested pointers to have been completed before the objects themselves can be completed.

If this is the case, override this method to return true, and be careful with circular references (which would make the object unreadable from a bam file).

Reimplemented in GeomVertexData, ClipPlaneAttrib, and RenderEffects.

Definition at line 118 of file typedWritable.cxx.

void Palettizer::reset_images ( )

Throws away all of the current PaletteImages, so that new ones may be created (and the packing made more optimal).

Definition at line 652 of file palettizer.cxx.

References PaletteGroup::reset_images().

void Palettizer::set_noabs ( bool  noabs)

Changes the current setting of the noabs flag.

If this flag is true, then it is an error to process an egg file that contains absolute pathname references. This flag is intended to help detect egg files that are incorrectly built within a model tree (which should use entirely relative pathnames).

This flag must be set before any egg files are processed.

Definition at line 163 of file palettizer.cxx.

Palettizer::RemapUV Palettizer::string_remap ( const string &  str) [static]

Returns the RemapUV code corresponding to the indicated string, or RU_invalid if the string is invalid.

Definition at line 945 of file palettizer.cxx.

PaletteGroup * Palettizer::test_palette_group ( const string &  name) const

Returns the PaletteGroup with the given name.

If there is no PaletteGroup with the indicated name, returns NULL.

Definition at line 868 of file palettizer.cxx.

Referenced by TxaLine::parse().

void TypedWritable::update_bam_nested ( BamWriter manager) [virtual, inherited]

Called by the BamWriter when this object has not itself been modified recently, but it should check its nested objects for updates.

Reimplemented in CFDoCullCommand, and PandaNode.

Definition at line 77 of file typedWritable.cxx.

void Palettizer::write_datagram ( BamWriter writer,
Datagram datagram 
) [virtual]

Fills the indicated datagram up with a binary representation of the current object, in preparation for writing to a Bam file.

Reimplemented from TypedWritable.

Definition at line 1001 of file palettizer.cxx.

References Datagram::add_bool(), Datagram::add_float64(), Datagram::add_int32(), Datagram::add_string(), Datagram::add_uint8(), FilenameUnifier::make_bam_filename(), and BamWriter::write_pointer().

bool Palettizer::write_eggs ( )

Adjusts the egg files to reference the newly generated textures, and writes them out.

Returns true if successful, or false if there was some error.

Definition at line 757 of file palettizer.cxx.

References EggFile::had_data(), EggFile::has_data(), EggFile::read_egg(), EggFile::release_egg_data(), EggFile::update_egg(), and EggFile::write_egg().


The documentation for this class was generated from the following files:
 All Classes Functions Variables Enumerations