17 #include "config_util.h" 19 #include "load_egg_file.h" 20 #include "config_egg2pg.h" 21 #include "config_gobj.h" 22 #include "config_chan.h" 23 #include "pandaNode.h" 25 #include "renderState.h" 26 #include "textureAttrib.h" 28 #include "graphicsPipeSelection.h" 29 #include "graphicsEngine.h" 30 #include "graphicsBuffer.h" 31 #include "graphicsStateGuardian.h" 32 #include "load_prc_file.h" 33 #include "windowProperties.h" 34 #include "frameBufferProperties.h" 46 set_program_brief(
"convert .egg files to .bam files");
47 set_program_description
48 (
"This program reads Egg files and outputs Bam files, the binary format " 49 "suitable for direct loading of animation and models into Panda. Bam " 50 "files are tied to a particular version of Panda, so should not be " 51 "considered replacements for egg files, but they tend to be smaller and " 52 "load much faster than the equivalent egg files.");
58 add_path_replace_options();
59 add_path_store_options();
62 (
"flatten",
"flag", 0,
63 "Specifies whether to flatten the egg hierarchy after it is loaded. " 64 "If flag is zero, the egg hierarchy will not be flattened, but will " 65 "instead be written to the bam file exactly as it is. If flag is " 66 "non-zero, the hierarchy will be flattened so that unnecessary nodes " 67 "(usually group nodes with only one child) are eliminated. The default " 68 "if this is not specified is taken from the egg-flatten Config.prc " 70 &EggToBam::dispatch_int, &_has_egg_flatten, &_egg_flatten);
73 (
"combine-geoms",
"flag", 0,
74 "Specifies whether to combine sibling GeomNodes into a common GeomNode " 75 "when possible. This flag is only respected if flatten, above, is also " 76 "enabled (or implicitly true from the Config.prc file). The default if " 77 "this is not specified is taken from the egg-combine-geoms Config.prc " 79 &EggToBam::dispatch_int, &_has_egg_combine_geoms, &_egg_combine_geoms);
82 (
"suppress-hidden",
"flag", 0,
83 "Specifies whether to suppress hidden geometry. If this is nonzero, " 84 "egg geometry tagged as \"hidden\" will be removed from the final " 85 "scene graph; otherwise, it will be preserved (but stashed). The " 86 "default is nonzero, to remove it.",
87 &EggToBam::dispatch_int, NULL, &_egg_suppress_hidden);
91 "Writes a scene graph listing to standard output after the egg " 92 "file has been loaded, showing the nodes that will be written out.",
93 &EggToBam::dispatch_none, &_ls);
97 "Specify the quality level for lossy channel compression. If this " 98 "is specified, the animation channels will be compressed at this " 99 "quality level, which is normally an integer value between 0 and 100, " 100 "inclusive, where higher numbers produce larger files with greater " 101 "quality. Generally, 95 is the highest useful quality level. Use " 102 "-NC (described below) to disable channel compression. If neither " 103 "option is specified, the default comes from the Config.prc file.",
104 &EggToBam::dispatch_int, &_has_compression_quality, &_compression_quality);
108 "Turn off lossy compression of animation channels. Channels will be " 109 "written exactly as they are, losslessly.",
110 &EggToBam::dispatch_none, &_compression_off);
114 "Record texture data directly in the bam file, instead of storing " 115 "a reference to the texture elsewhere on disk. The textures are " 116 "stored uncompressed, unless -ctex is also specified. " 117 "A particular texture that is encoded into " 118 "multiple different bam files in this way cannot be unified into " 119 "the same part of texture memory if the different bam files are loaded " 120 "together. That being said, this can sometimes be a convenient " 121 "way to ensure the bam file is completely self-contained.",
122 &EggToBam::dispatch_none, &_tex_rawdata);
126 "Rather than writing texture data directly into the bam file, as in " 127 "-rawtex, create a texture object for each referenced texture. A " 128 "texture object is a kind of mini-bam file, with a .txo extension, " 129 "that contains all of the data needed to recreate a texture, including " 130 "its image contents, filter and wrap settings, and so on. 3-D textures " 131 "and cube maps can also be represented in a single .txo file. Texture " 132 "object files, like bam files, are tied to a particular version of " 134 &EggToBam::dispatch_none, &_tex_txo);
139 "In addition to writing texture object files as above, compress each " 140 "one using pzip to a .txo.pz file. In many cases, this will yield a " 141 "disk file size comparable to that achieved by png compression. This " 142 "is an on-disk compression only, and does not affect the amount of " 143 "RAM or texture memory consumed by the texture when it is loaded.",
144 &EggToBam::dispatch_none, &_tex_txopz);
150 "Pre-compress the texture images using the libsquish library, when " 151 "using -rawtex or -txo. " 153 "Asks the graphics card to pre-compress the texture images when using " 157 "This is unrelated to the on-disk compression achieved " 158 "via -txopz (and it may be used in conjunction with that parameter). " 160 "This will result in a smaller RAM and texture memory footprint for " 161 "the texture images. The same " 162 "effect can be achieved at load time by setting compressed-textures in " 163 "your Config.prc file; but -ctex pre-compresses the " 164 "textures so that they do not need to be compressed at load time. " 166 "Note that, since your Panda is not compiled with the libsquish " 167 "library, using -ctex will make .txo files that are only guaranteed " 168 "to load on the particular graphics card that was used to " 172 &EggToBam::dispatch_none, &_tex_ctex);
176 "Records the pre-generated mipmap levels in the texture object file " 177 "when using -rawtex or -txo, regardless of the texture filter mode. This " 178 "will increase the size of the texture object file by about 33%, but " 179 "it prevents the need to compute the mipmaps at runtime. The default " 180 "is to record mipmap levels only when the texture uses a mipmap " 182 &EggToBam::dispatch_none, &_tex_mipmap);
185 (
"ctexq",
"quality", 0,
186 "Specifies the compression quality to use when performing the " 187 "texture compression requested by -ctex. This may be one of " 188 "'default', 'fastest', 'normal', or 'best'. The default is 'best'. " 189 "Set it to 'default' to use whatever is specified by the Config.prc " 190 "file. This is a global setting only; individual texture quality " 191 "settings appearing within the egg file will override this.",
192 &EggToBam::dispatch_string, NULL, &_ctex_quality);
195 (
"load-display",
"display name", 0,
196 "Specifies the particular display module to load to perform the texture " 197 "compression requested by -ctex. If this is omitted, the default is " 198 "taken from the Config.prc file." 200 " Since your Panda has libsquish compiled in, this is not necessary; " 201 "Panda can compress textures without loading a display module." 204 &EggToBam::dispatch_string, NULL, &_load_display);
208 "Specify the coordinate system of the resulting " + _format_name +
209 " file. This may be " 210 "one of 'y-up', 'z-up', 'y-up-left', or 'z-up-left'. The default " 213 _force_complete =
true;
215 _egg_combine_geoms = 0;
216 _egg_suppress_hidden = 1;
218 _ctex_quality =
"best";
228 if (_has_egg_flatten) {
231 egg_flatten = (_egg_flatten != 0);
233 if (_has_egg_combine_geoms) {
235 egg_combine_geoms = (_egg_combine_geoms != 0);
239 egg_suppress_hidden = _egg_suppress_hidden;
241 if (_compression_off) {
243 compress_channels =
false;
245 }
else if (_has_compression_quality) {
248 compress_channels =
true;
249 compress_chan_quality = _compression_quality;
252 if (_ctex_quality !=
"default") {
255 string prc =
"texture-quality-level " + _ctex_quality;
256 load_prc_file_data(
"prc", prc);
259 if (!_got_coordinate_system) {
262 _data->set_coordinate_system(CS_zup_right);
265 PT(
PandaNode) root = load_egg_data(_data);
267 nout <<
"Unable to build scene graph from egg file.\n";
273 if (!make_buffer()) {
274 nout <<
"Unable to initialize graphics context; cannot compress textures.\n";
277 #endif // HAVE_SQUISH 280 if (_tex_txo || _tex_txopz || (_tex_ctex && _tex_rawdata)) {
281 collect_textures(root);
282 Textures::iterator ti;
283 for (ti = _textures.begin(); ti != _textures.end(); ++ti) {
286 bool want_mipmaps = (_tex_mipmap || tex->
uses_mipmaps());
295 nout <<
" couldn't compress " << tex->get_name() <<
"\n";
301 if (!_engine->extract_texture_data(tex, _gsg)) {
302 nout <<
" couldn't compress " << tex->get_name() <<
"\n";
304 if (!has_mipmap_levels && !want_mipmaps) {
310 #endif // HAVE_SQUISH 313 if (_tex_txo || _tex_txopz) {
329 nout <<
"Writing " << filename <<
"\n";
332 nout <<
"Error in writing.\n";
337 nout <<
"Error in writing.\n";
356 bam_texture_mode = BamFile::BTM_rawdata;
358 }
else if (_got_path_store) {
359 bam_texture_mode = BamFile::BTM_unchanged;
364 _path_replace->_path_store = PS_absolute;
367 return EggToSomething::handle_args(args);
378 collect_textures(node->get_state());
382 for (
int i = 0; i < num_geoms; ++i) {
389 for (
int i = 0; i < num_children; ++i) {
390 collect_textures(children.get_child(i));
405 for (
int i = 0; i < num_on_stages; ++i) {
432 if (tex->
write(fullpath)) {
433 nout <<
" Writing " << fullpath;
464 if (!_load_display.empty()) {
466 string prc =
"load-display " + _load_display;
467 load_prc_file_data(
"prc", prc);
471 _pipe = selection->make_default_pipe();
473 nout <<
"Unable to create graphics pipe.\n";
483 fbprops.set_back_buffers(0);
494 _buffer = _engine->make_output(_pipe,
"buffer", 0,
496 GraphicsPipe::BF_fb_props_optional);
497 _engine->open_windows();
499 nout <<
"Unable to create graphics window.\n";
502 _gsg = _buffer->get_gsg();
508 int main(
int argc,
char *argv[]) {
CPTA_uchar get_ram_image()
Returns the system-RAM image data associated with the texture.
Filename get_filename_index(int index) const
If the pattern flag is set for this Filename and the filename string actually includes a sequence of ...
The principle public interface to reading and writing Bam disk files.
const RenderState * get_geom_state(int n) const
Returns the RenderState associated with the nth geom of the node.
static const FrameBufferProperties & get_default()
Returns a FrameBufferProperties structure with all of the default values filled in according to the u...
int get_num_ram_mipmap_images() const
Returns the maximum number of mipmap level images available in system memory.
int get_num_children() const
Returns the number of children of the node.
void set_extension(const string &s)
Replaces the file extension.
bool write_object(const TypedWritable *object)
Writes the indicated object to the Bam file.
const Filename & get_fullpath() const
Returns the fullpath that has been set.
A basic node of the scene graph or data graph.
void set_loaded_from_txo()
Sets the flag that indicates the texture has been loaded from a txo file.
string get_fullpath() const
Returns the entire filename: directory, basename, extension.
virtual void parse_command_line(int argc, char **argv)
Dispatches on each of the options on the command line, and passes the remaining parameters to handle_...
Represents a texture object, which is typically a single 2-d image but may also represent a 1-d or 3-...
void clear_alpha_fullpath()
Removes the alpha fullpath, if it was previously set.
void set_size(const LVector2i &size)
Specifies the requested size of the window, in pixels.
int get_num_geoms() const
Returns the number of geoms in the node.
bool compress_ram_image(CompressionMode compression=CM_on, QualityLevel quality_level=QL_default, GraphicsStateGuardianBase *gsg=NULL)
Attempts to compress the texture's RAM image internally, to a format supported by the indicated GSG...
void set_fullpath(const Filename &fullpath)
Sets the full pathname to the file that contains the image's contents, as found along the search path...
Filename get_output_filename() const
If has_output_filename() returns true, this is the filename that the user specified.
Indicates the set of TextureStages and their associated Textures that should be applied to (or remove...
bool has_output_filename() const
Returns true if the user specified an output filename, false otherwise (e.g.
Texture * get_on_texture(TextureStage *stage) const
Returns the texture associated with the indicated stage, or NULL if no texture is associated...
void set_undecorated(bool undecorated)
Specifies whether the window should be created with a visible title and border (false, the default) or not (true).
A container for the various kinds of properties we might ask to have on a graphics window before we o...
bool uses_mipmaps() const
Returns true if the minfilter settings on this texture indicate the use of mipmapping, false otherwise.
The name of a file, such as a texture file or an Egg file.
bool get_loaded_from_txo() const
Returns the flag that indicates the texture has been loaded from a txo file.
void set_z_order(ZOrder z_order)
Specifies the relative ordering of the window with respect to other windows.
This maintains a list of GraphicsPipes by type that are available for creation.
void set_keep_ram_image(bool keep_ram_image)
Sets the flag that indicates whether this Texture is eligible to have its main RAM copy of the textur...
void clear_ram_mipmap_images()
Discards the current system-RAM image for all mipmap levels, except level 0 (the base image)...
An object to create GraphicsOutputs that share a particular 3-D API.
void set_origin(const LPoint2i &origin)
Specifies the origin on the screen (in pixels, relative to the top-left corner) at which the window s...
TextureStage * get_on_stage(int n) const
Returns the nth stage turned on by the attribute, sorted in render order.
static GraphicsPipeSelection * get_global_ptr()
Returns a pointer to the one global GraphicsPipeSelection object.
This is a base class for the various different classes that represent the result of a frame of render...
void set_compression(CompressionMode compression)
Requests that this particular Texture be compressed when it is loaded into texture memory...
This represents a unique collection of RenderAttrib objects that correspond to a particular renderabl...
CompressionMode get_ram_image_compression() const
Returns the compression mode in which the ram image is already stored pre-compressed.
void clear_alpha_filename()
Removes the alpha filename, if it was previously set.
Children get_children(Thread *current_thread=Thread::get_current_thread()) const
Returns an object that can be used to walk through the list of children of the node.
void generate_ram_mipmap_images()
Automatically fills in the n mipmap levels of the Texture, based on the texture's source image...
This is the general base class for a file-converter program that reads some model file format and gen...
int get_num_on_stages() const
Returns the number of stages that are turned on by the attribute.
bool make_dir() const
Creates all the directories in the path to the file specified in the filename, except for the basenam...
This class is the main interface to controlling the render process.
bool is_valid() const
Returns false if this pipe is known to be invalid, meaning that an attempt to create a GraphicsWindow...
bool open_write(const Filename &bam_filename, bool report_errors=true)
Attempts to open the indicated file for writing.
A container for the various kinds of properties we might ask to have on a graphics frameBuffer before...
virtual bool is_geom_node() const
A simple downcast check.
void set_open(bool open)
Specifies whether the window should be open.
A node that holds Geom objects, renderable pieces of geometry.
void set_filename(const Filename &filename)
Sets the name of the file that contains the image's contents.
bool write(const Filename &fullpath)
Writes the texture to the named filename.
const Filename & get_filename() const
Returns the filename that has been set.