add implicit "null" group

This commit is contained in:
David Rose 2009-01-13 02:32:16 +00:00
parent b37a30fe63
commit 57027bf5dd
8 changed files with 76 additions and 15 deletions

View File

@ -451,17 +451,17 @@ choose_placements() {
groups.make_intersection(get_complete_groups(), texture->get_groups());
// Now groups is the set of groups that the egg file requires,
// which also happen to include the texture. It better not be
// empty.
if (groups.empty()) {
nout << "Warning! Egg file " << get_name() << " and texture "
<< *reference << " do not have any groups in common.\n"
<< "Egg groups:\n";
get_complete_groups().write(nout, 2);
nout << "Texture groups:\n";
texture->get_groups().write(nout, 2);
// which also happen to include the texture.
} else {
if (groups.empty()) {
// It might be empty if the egg file was assigned only to the
// "null" group (since this group is not propagated to the
// textures). In this case, choose from the wider set of
// groups available to the texture.
groups = texture->get_groups();
}
if (!groups.empty()) {
// It doesn't really matter which group in the set we choose, so
// we arbitrarily choose the first one.
PaletteGroup *group = (*groups.begin());

View File

@ -99,7 +99,6 @@ private:
typedef pmap<TextureProperties, PalettePage *> Pages;
Pages _pages;
// The TypedWritable interface follows.
public:
static void register_with_read_factory();

View File

@ -34,6 +34,27 @@ PaletteGroups::
PaletteGroups() {
}
////////////////////////////////////////////////////////////////////
// Function: PaletteGroups::Copy Constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
PaletteGroups::
PaletteGroups(const PaletteGroups &copy) :
_groups(copy._groups)
{
}
////////////////////////////////////////////////////////////////////
// Function: PaletteGroups::operator =
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
void PaletteGroups::
operator = (const PaletteGroups &copy) {
_groups = copy._groups;
}
////////////////////////////////////////////////////////////////////
// Function: PaletteGroups::insert
// Access: Public
@ -154,6 +175,25 @@ make_intersection(const PaletteGroups &a, const PaletteGroups &b) {
_groups.swap(i);
}
////////////////////////////////////////////////////////////////////
// Function: PaletteGroups::remove_null
// Access: Public
// Description: Removes the special "null" group from the set. This
// is a special group that egg files may be assigned to,
// but which textures never are; it indicates that the
// egg file should not influence the palette assignment.
////////////////////////////////////////////////////////////////////
void PaletteGroups::
remove_null() {
Groups::iterator gi;
for (gi = _groups.begin(); gi != _groups.end(); ++gi) {
if ((*gi)->get_name() == "null") {
_groups.erase(gi);
return;
}
}
}
////////////////////////////////////////////////////////////////////
// Function: PaletteGroups::clear
// Access: Public

View File

@ -47,12 +47,15 @@ public:
typedef Groups::difference_type difference_type;
PaletteGroups();
PaletteGroups(const PaletteGroups &copy);
void operator =(const PaletteGroups &copy);
void insert(PaletteGroup *group);
size_type count(PaletteGroup *group) const;
void make_complete(const PaletteGroups &a);
void make_union(const PaletteGroups &a, const PaletteGroups &b);
void make_intersection(const PaletteGroups &a, const PaletteGroups &b);
void remove_null();
void clear();
bool empty() const;

View File

@ -128,6 +128,8 @@ Palettizer() {
_round_fuzz = 0.01;
_remap_uv = RU_poly;
_remap_char_uv = RU_poly;
get_palette_group("null");
}
////////////////////////////////////////////////////////////////////

View File

@ -46,6 +46,8 @@ TextureImage() {
_ever_read_image = false;
_forced_grayscale = false;
_alpha_bits = 0;
_mid_pixel_ratio = 0.0;
_is_cutout = false;
_alpha_mode = EggRenderMode::AM_unspecified;
_txa_wrap_u = EggTexture::WM_unspecified;
_txa_wrap_v = EggTexture::WM_unspecified;
@ -134,12 +136,17 @@ assign_groups() {
total.make_union(total, (*ei)->get_complete_groups());
}
// We don't count the "null" group for texture assignment.
total.remove_null();
if (total.empty()) {
break;
}
// Now, find the group that will satisfy the most egg files. If
// two groups satisfy the same number of egg files, choose (a) the
// most specific one, i.e. with the lowest dirname_level, or the
// lowest dependency_level if the dirname_levels are equal, and
// (b) the one that has the fewest egg files sharing it.
nassertv(!total.empty());
PaletteGroups::iterator gi = total.begin();
PaletteGroup *best = (*gi);
int best_egg_count = compute_egg_count(best, needed_eggs);
@ -892,7 +899,7 @@ write_source_pathnames(ostream &out, int indent_level) const {
if (_is_cutout) {
indent(out, indent_level)
<< "Cutout image (ratio " << _mid_pixel_ratio << ")";
<< "Cutout image (ratio " << (float)_mid_pixel_ratio << ")\n";
}
// Now write out the group assignments.
@ -1196,7 +1203,11 @@ consider_alpha() {
}
}
_mid_pixel_ratio = (double)num_mid_pixels / (double)(source.get_x_size() * source.get_y_size());
int num_pixels = source.get_x_size() * source.get_y_size();
_mid_pixel_ratio = 0.0;
if (num_pixels != 0) {
_mid_pixel_ratio = (double)num_mid_pixels / (double)num_pixels;
}
}
_is_cutout = false;

View File

@ -417,7 +417,12 @@ update_egg() {
return;
}
nassertv(_placement != (TexturePlacement *)NULL);
if (_placement == (TexturePlacement *)NULL) {
// Nor if we don't have an actual placement yet. This is possible
// if the egg was assigned to the "null" group, and the texture
// hasn't been re-assigned yet.
return;
}
TextureImage *texture = get_texture();
if (texture != (TextureImage *)NULL) {

View File

@ -510,6 +510,7 @@ match_texture(TextureImage *texture) const {
texture->_explicitly_assigned_groups.make_union
(texture->_explicitly_assigned_groups, _palette_groups);
texture->_explicitly_assigned_groups.remove_null();
if (got_cont) {
// If we have the "cont" keyword, we should keep scanning for