mirror of
https://github.com/panda3d/panda3d.git
synced 2025-09-29 00:06:44 -04:00
*** empty log message ***
This commit is contained in:
parent
10b72a68b8
commit
8f268e22a5
@ -32,7 +32,7 @@ md5_a_file(const Filename &name, HashVal &ret) {
|
|||||||
ostringstream os;
|
ostringstream os;
|
||||||
MD5 md5;
|
MD5 md5;
|
||||||
|
|
||||||
string fs = name.get_fullpath();
|
string fs = name.to_os_specific();
|
||||||
FileSource f(fs.c_str(), true, new HashFilter(md5, new FileSink(os)));
|
FileSource f(fs.c_str(), true, new HashFilter(md5, new FileSink(os)));
|
||||||
|
|
||||||
istringstream is(os.str());
|
istringstream is(os.str());
|
||||||
|
@ -529,13 +529,14 @@ transfer_unplaced_images(bool force_redo_all) {
|
|||||||
// maybe it's already there and hasn't changed recently.
|
// maybe it's already there and hasn't changed recently.
|
||||||
if (force_redo_all || packing->needs_refresh()) {
|
if (force_redo_all || packing->needs_refresh()) {
|
||||||
// Nope, needs to be updated.
|
// Nope, needs to be updated.
|
||||||
okflag = texture->transfer() && okflag;
|
okflag = packing->transfer() && okflag;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (_aggressively_clean_mapdir && texture->is_unused()) {
|
if (_aggressively_clean_mapdir && texture->is_unused()) {
|
||||||
if (texture->get_filename().exists()) {
|
Filename new_filename = packing->get_new_filename();
|
||||||
nout << "Deleting " << texture->get_filename() << "\n";
|
if (new_filename.exists()) {
|
||||||
texture->get_filename().unlink();
|
nout << "Deleting " << new_filename << "\n";
|
||||||
|
new_filename.unlink();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -384,68 +384,6 @@ write_pathname(ostream &out) const {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PTexture::
|
|
||||||
transfer() {
|
|
||||||
bool okflag = true;
|
|
||||||
|
|
||||||
Filename new_filename = get_filename();
|
|
||||||
if (new_filename == _filename) {
|
|
||||||
nout << "*** PTexture " << _name << " is already in the map directory!\n"
|
|
||||||
<< " Cannot modify texture in place!\n";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
int nx, ny;
|
|
||||||
if (!get_req(nx, ny)) {
|
|
||||||
nout << "Unknown size for image " << _name << "\n";
|
|
||||||
nx = 16;
|
|
||||||
ny = 16;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_attrib_file->_force_power_2) {
|
|
||||||
int newx = to_power_2(nx);
|
|
||||||
int newy = to_power_2(ny);
|
|
||||||
if (newx != nx || newy != ny) {
|
|
||||||
nx = newx;
|
|
||||||
ny = newy;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
PNMImage *image = read_image();
|
|
||||||
if (image == NULL) {
|
|
||||||
nout << "*** Unable to read " << _name << "\n";
|
|
||||||
okflag = false;
|
|
||||||
|
|
||||||
// Create a solid red texture for images we can't read.
|
|
||||||
image = new PNMImage(nx, ny);
|
|
||||||
image->fill(1.0, 0.0, 0.0);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
// Should we scale it?
|
|
||||||
if (nx != image->get_x_size() && ny != image->get_y_size()) {
|
|
||||||
nout << "Resizing " << new_filename << " to "
|
|
||||||
<< nx << " " << ny << "\n";
|
|
||||||
PNMImage *new_image =
|
|
||||||
new PNMImage(nx, ny, image->get_color_type());
|
|
||||||
new_image->gaussian_filter_from(0.5, *image);
|
|
||||||
delete image;
|
|
||||||
image = new_image;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
nout << "Copying " << new_filename
|
|
||||||
<< " (size " << nx << " " << ny << ")\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!image->write(new_filename)) {
|
|
||||||
nout << "Error in writing.\n";
|
|
||||||
okflag = false;
|
|
||||||
}
|
|
||||||
delete image;
|
|
||||||
|
|
||||||
return okflag;
|
|
||||||
}
|
|
||||||
|
|
||||||
PNMImage *PTexture::
|
PNMImage *PTexture::
|
||||||
read_image() {
|
read_image() {
|
||||||
if (!_got_filename || !_file_exists) {
|
if (!_got_filename || !_file_exists) {
|
||||||
@ -504,12 +442,3 @@ read_image_header(const Filename &filename, int &xsize, int &ysize,
|
|||||||
zsize = header.get_num_channels();
|
zsize = header.get_num_channels();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int PTexture::
|
|
||||||
to_power_2(int value) {
|
|
||||||
int x = 1;
|
|
||||||
while ((x << 1) <= value) {
|
|
||||||
x = (x << 1);
|
|
||||||
}
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
@ -67,8 +67,6 @@ public:
|
|||||||
void write_size(ostream &out);
|
void write_size(ostream &out);
|
||||||
void write_pathname(ostream &out) const;
|
void write_pathname(ostream &out) const;
|
||||||
|
|
||||||
bool transfer();
|
|
||||||
|
|
||||||
PNMImage *read_image();
|
PNMImage *read_image();
|
||||||
|
|
||||||
typedef set<TextureEggRef *> Eggs;
|
typedef set<TextureEggRef *> Eggs;
|
||||||
@ -79,7 +77,6 @@ private:
|
|||||||
void read_header();
|
void read_header();
|
||||||
bool read_image_header(const Filename &filename,
|
bool read_image_header(const Filename &filename,
|
||||||
int &xsize, int &ysize, int &zsize);
|
int &xsize, int &ysize, int &zsize);
|
||||||
static int to_power_2(int value);
|
|
||||||
|
|
||||||
Filename _name;
|
Filename _name;
|
||||||
|
|
||||||
|
@ -331,8 +331,10 @@ finalize_palette() {
|
|||||||
char index_str[128];
|
char index_str[128];
|
||||||
sprintf(index_str, "%03d", _index);
|
sprintf(index_str, "%03d", _index);
|
||||||
_basename = _group->get_name() + "-palette." + index_str + ".rgb";
|
_basename = _group->get_name() + "-palette." + index_str + ".rgb";
|
||||||
|
|
||||||
|
Filename dirname(_attrib_file->_map_dirname, _group->get_dirname());
|
||||||
_filename = _basename;
|
_filename = _basename;
|
||||||
_filename.set_dirname(_attrib_file->_map_dirname);
|
_filename.set_dirname(dirname.get_fullpath());
|
||||||
} else {
|
} else {
|
||||||
_basename = _filename.get_basename();
|
_basename = _filename.get_basename();
|
||||||
}
|
}
|
||||||
|
@ -67,6 +67,28 @@ add_parent(PaletteGroup *parent) {
|
|||||||
_parents.push_back(parent);
|
_parents.push_back(parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: PaletteGroup::get_dirname
|
||||||
|
// Access: Public
|
||||||
|
// Description: Returns the directory name to which palettes and
|
||||||
|
// textures associated with this group will be written.
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
const string &PaletteGroup::
|
||||||
|
get_dirname() const {
|
||||||
|
return _dirname;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: PaletteGroup::set_dirname
|
||||||
|
// Access: Public
|
||||||
|
// Description: Sets the directory name to which palettes and
|
||||||
|
// textures associated with this group will be written.
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
void PaletteGroup::
|
||||||
|
set_dirname(const string &dirname) {
|
||||||
|
_dirname = dirname;
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: PaletteGroup::pack_texture
|
// Function: PaletteGroup::pack_texture
|
||||||
// Access: Public
|
// Access: Public
|
||||||
|
@ -51,6 +51,9 @@ public:
|
|||||||
PaletteGroup *get_parent(int n) const;
|
PaletteGroup *get_parent(int n) const;
|
||||||
void add_parent(PaletteGroup *parent);
|
void add_parent(PaletteGroup *parent);
|
||||||
|
|
||||||
|
const string &get_dirname() const;
|
||||||
|
void set_dirname(const string &dirname);
|
||||||
|
|
||||||
bool pack_texture(TexturePacking *packing, AttribFile *attrib_file);
|
bool pack_texture(TexturePacking *packing, AttribFile *attrib_file);
|
||||||
bool generate_palette_images();
|
bool generate_palette_images();
|
||||||
void optimal_resize();
|
void optimal_resize();
|
||||||
@ -72,6 +75,8 @@ private:
|
|||||||
|
|
||||||
typedef vector<Palette *> Palettes;
|
typedef vector<Palette *> Palettes;
|
||||||
Palettes _palettes;
|
Palettes _palettes;
|
||||||
|
|
||||||
|
string _dirname;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -9,6 +9,8 @@
|
|||||||
#include "palette.h"
|
#include "palette.h"
|
||||||
#include "pTexture.h"
|
#include "pTexture.h"
|
||||||
|
|
||||||
|
#include <pnmImage.h>
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: TexturePacking::Constructor
|
// Function: TexturePacking::Constructor
|
||||||
@ -461,3 +463,105 @@ write_unplaced(ostream &out) const {
|
|||||||
out << "\n";
|
out << "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: TexturePacking::get_new_filename
|
||||||
|
// Access: Public
|
||||||
|
// Description: Returns the filename to which this texture will be
|
||||||
|
// copied, assuming it is not placed on a palette.
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
Filename TexturePacking::
|
||||||
|
get_new_filename() const {
|
||||||
|
Filename dirname(_attrib_file->_map_dirname, _group->get_dirname());
|
||||||
|
Filename new_filename(dirname, _texture->get_name());
|
||||||
|
return new_filename;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: TexturePacking::transfer
|
||||||
|
// Access: Public
|
||||||
|
// Description: Copies an unpalettized image to the install
|
||||||
|
// directory, if it is not already there. The
|
||||||
|
// particular directory it is installed into may depend
|
||||||
|
// on the PaletteGroup to which it has been added.
|
||||||
|
// Returns true if successful, false if there is an
|
||||||
|
// error.
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
bool TexturePacking::
|
||||||
|
transfer() {
|
||||||
|
bool okflag = true;
|
||||||
|
|
||||||
|
Filename old_filename = _texture->_filename;
|
||||||
|
Filename new_filename = get_new_filename();
|
||||||
|
if (new_filename == old_filename) {
|
||||||
|
nout << "*** Texture " << _texture->get_name()
|
||||||
|
<< " is already in the map directory!\n"
|
||||||
|
<< " Cannot modify texture in place!\n";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int nx, ny;
|
||||||
|
if (!_texture->get_req(nx, ny)) {
|
||||||
|
nout << "Unknown size for image " << _texture->get_name() << "\n";
|
||||||
|
nx = 16;
|
||||||
|
ny = 16;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_attrib_file->_force_power_2) {
|
||||||
|
int newx = to_power_2(nx);
|
||||||
|
int newy = to_power_2(ny);
|
||||||
|
if (newx != nx || newy != ny) {
|
||||||
|
nx = newx;
|
||||||
|
ny = newy;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
PNMImage *image = _texture->read_image();
|
||||||
|
if (image == NULL) {
|
||||||
|
nout << "*** Unable to read " << _texture->get_name() << "\n";
|
||||||
|
okflag = false;
|
||||||
|
|
||||||
|
// Create a solid red texture for images we can't read.
|
||||||
|
image = new PNMImage(nx, ny);
|
||||||
|
image->fill(1.0, 0.0, 0.0);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// Should we scale it?
|
||||||
|
if (nx != image->get_x_size() && ny != image->get_y_size()) {
|
||||||
|
nout << "Resizing " << new_filename << " to "
|
||||||
|
<< nx << " " << ny << "\n";
|
||||||
|
PNMImage *new_image =
|
||||||
|
new PNMImage(nx, ny, image->get_color_type());
|
||||||
|
new_image->gaussian_filter_from(0.5, *image);
|
||||||
|
delete image;
|
||||||
|
image = new_image;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
nout << "Copying " << new_filename
|
||||||
|
<< " (size " << nx << " " << ny << ")\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!image->write(new_filename)) {
|
||||||
|
nout << "Error in writing.\n";
|
||||||
|
okflag = false;
|
||||||
|
}
|
||||||
|
delete image;
|
||||||
|
|
||||||
|
return okflag;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: TexturePacking::to_power_2
|
||||||
|
// Access: Public, Static
|
||||||
|
// Description: Returns the largest power of 2 less than or equal to
|
||||||
|
// value.
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
int TexturePacking::
|
||||||
|
to_power_2(int value) {
|
||||||
|
int x = 1;
|
||||||
|
while ((x << 1) <= value) {
|
||||||
|
x = (x << 1);
|
||||||
|
}
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
@ -60,7 +60,12 @@ public:
|
|||||||
|
|
||||||
void write_unplaced(ostream &out) const;
|
void write_unplaced(ostream &out) const;
|
||||||
|
|
||||||
|
Filename get_new_filename() const;
|
||||||
|
bool transfer();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
static int to_power_2(int value);
|
||||||
|
|
||||||
AttribFile *_attrib_file;
|
AttribFile *_attrib_file;
|
||||||
PTexture *_texture;
|
PTexture *_texture;
|
||||||
PaletteGroup *_group;
|
PaletteGroup *_group;
|
||||||
|
@ -25,6 +25,8 @@ UserAttribLine(const string &cline, AttribFile *af) : _attrib_file(af) {
|
|||||||
// matches that line.
|
// matches that line.
|
||||||
_was_used = true;
|
_was_used = true;
|
||||||
|
|
||||||
|
_got_dirname = false;
|
||||||
|
|
||||||
string line = cline;
|
string line = cline;
|
||||||
|
|
||||||
// First, strip off the comment.
|
// First, strip off the comment.
|
||||||
@ -108,10 +110,16 @@ write(ostream &out) const {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case LT_group_relate:
|
case LT_group_relate:
|
||||||
out << ":group " << _names[0] << " with";
|
out << ":group " << _names[0];
|
||||||
|
if (!_got_dirname) {
|
||||||
|
out << " dir " << _dirname;
|
||||||
|
}
|
||||||
|
if (!_names.empty()) {
|
||||||
|
out << " with";
|
||||||
for (i = 1; i < (int)_names.size(); i++) {
|
for (i = 1; i < (int)_names.size(); i++) {
|
||||||
out << " " << _names[i];
|
out << " " << _names[i];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
out << "\n";
|
out << "\n";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -333,14 +341,34 @@ keyword_line(const string &line) {
|
|||||||
|
|
||||||
} else if (words[0] == ":group") {
|
} else if (words[0] == ":group") {
|
||||||
_line_type = LT_group_relate;
|
_line_type = LT_group_relate;
|
||||||
if (words.size() < 4 || !(words[2] == "with")) {
|
if (words.size() < 2) {
|
||||||
nout << "Expected :group groupname with groupname [groupname ...].\n";
|
nout << "Expected :group name.\n";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
PaletteGroup *group = _attrib_file->get_group(words[1]);
|
PaletteGroup *group = _attrib_file->get_group(words[1]);
|
||||||
|
|
||||||
for (int i = 3; i < (int)words.size(); i++) {
|
int kw = 2;
|
||||||
group->add_parent(_attrib_file->get_group(words[i]));
|
while (kw < (int)words.size()) {
|
||||||
|
if (words[kw] == "with") {
|
||||||
|
kw++;
|
||||||
|
|
||||||
|
while (kw < (int)words.size()) {
|
||||||
|
group->add_parent(_attrib_file->get_group(words[kw]));
|
||||||
|
kw++;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (words[kw] == "dir") {
|
||||||
|
kw++;
|
||||||
|
_got_dirname = true;
|
||||||
|
_dirname = words[kw];
|
||||||
|
group->set_dirname(_dirname);
|
||||||
|
kw++;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
nout << "Invalid keyword: " << words[kw] << "\n";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
@ -29,7 +29,7 @@ class SourceEgg;
|
|||||||
// # Comment
|
// # Comment
|
||||||
// :margin msize
|
// :margin msize
|
||||||
// :palette xsize ysize
|
// :palette xsize ysize
|
||||||
// :group groupname with groupname [groupname ...]
|
// :group groupname [dir dirname] [with groupname [groupname ...]]
|
||||||
// texturename xsize ysize msize
|
// texturename xsize ysize msize
|
||||||
// texturename [texturename ...] : xsize ysize [msize] [omit]
|
// texturename [texturename ...] : xsize ysize [msize] [omit]
|
||||||
// texturename [texturename ...] : scale% [msize] [omit]
|
// texturename [texturename ...] : scale% [msize] [omit]
|
||||||
@ -77,6 +77,8 @@ private:
|
|||||||
int _xsize, _ysize;
|
int _xsize, _ysize;
|
||||||
double _scale_pct;
|
double _scale_pct;
|
||||||
int _msize;
|
int _msize;
|
||||||
|
string _dirname;
|
||||||
|
bool _got_dirname;
|
||||||
bool _omit;
|
bool _omit;
|
||||||
bool _is_old_style;
|
bool _is_old_style;
|
||||||
bool _was_used;
|
bool _was_used;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user