42 set_program_brief(
"convert .egg files to .bam files");
43 set_program_description
44 (
"This program reads Egg files and outputs Bam files, the binary format " 45 "suitable for direct loading of animation and models into Panda. Bam " 46 "files are tied to a particular version of Panda, so should not be " 47 "considered replacements for egg files, but they tend to be smaller and " 48 "load much faster than the equivalent egg files.");
54 add_path_replace_options();
55 add_path_store_options();
58 (
"flatten",
"flag", 0,
59 "Specifies whether to flatten the egg hierarchy after it is loaded. " 60 "If flag is zero, the egg hierarchy will not be flattened, but will " 61 "instead be written to the bam file exactly as it is. If flag is " 62 "non-zero, the hierarchy will be flattened so that unnecessary nodes " 63 "(usually group nodes with only one child) are eliminated. The default " 64 "if this is not specified is taken from the egg-flatten Config.prc " 66 &EggToBam::dispatch_int, &_has_egg_flatten, &_egg_flatten);
69 (
"combine-geoms",
"flag", 0,
70 "Specifies whether to combine sibling GeomNodes into a common GeomNode " 71 "when possible. This flag is only respected if flatten, above, is also " 72 "enabled (or implicitly true from the Config.prc file). The default if " 73 "this is not specified is taken from the egg-combine-geoms Config.prc " 75 &EggToBam::dispatch_int, &_has_egg_combine_geoms, &_egg_combine_geoms);
78 (
"suppress-hidden",
"flag", 0,
79 "Specifies whether to suppress hidden geometry. If this is nonzero, " 80 "egg geometry tagged as \"hidden\" will be removed from the final " 81 "scene graph; otherwise, it will be preserved (but stashed). The " 82 "default is nonzero, to remove it.",
83 &EggToBam::dispatch_int,
nullptr, &_egg_suppress_hidden);
87 "Writes a scene graph listing to standard output after the egg " 88 "file has been loaded, showing the nodes that will be written out.",
89 &EggToBam::dispatch_none, &_ls);
93 "Specify the quality level for lossy channel compression. If this " 94 "is specified, the animation channels will be compressed at this " 95 "quality level, which is normally an integer value between 0 and 100, " 96 "inclusive, where higher numbers produce larger files with greater " 97 "quality. Generally, 95 is the highest useful quality level. Use " 98 "-NC (described below) to disable channel compression. If neither " 99 "option is specified, the default comes from the Config.prc file.",
100 &EggToBam::dispatch_int, &_has_compression_quality, &_compression_quality);
104 "Turn off lossy compression of animation channels. Channels will be " 105 "written exactly as they are, losslessly.",
106 &EggToBam::dispatch_none, &_compression_off);
110 "Record texture data directly in the bam file, instead of storing " 111 "a reference to the texture elsewhere on disk. The textures are " 112 "stored uncompressed, unless -ctex is also specified. " 113 "A particular texture that is encoded into " 114 "multiple different bam files in this way cannot be unified into " 115 "the same part of texture memory if the different bam files are loaded " 116 "together. That being said, this can sometimes be a convenient " 117 "way to ensure the bam file is completely self-contained.",
118 &EggToBam::dispatch_none, &_tex_rawdata);
122 "Rather than writing texture data directly into the bam file, as in " 123 "-rawtex, create a texture object for each referenced texture. A " 124 "texture object is a kind of mini-bam file, with a .txo extension, " 125 "that contains all of the data needed to recreate a texture, including " 126 "its image contents, filter and wrap settings, and so on. 3-D textures " 127 "and cube maps can also be represented in a single .txo file. Texture " 128 "object files, like bam files, are tied to a particular version of " 130 &EggToBam::dispatch_none, &_tex_txo);
135 "In addition to writing texture object files as above, compress each " 136 "one using pzip to a .txo.pz file. In many cases, this will yield a " 137 "disk file size comparable to that achieved by png compression. This " 138 "is an on-disk compression only, and does not affect the amount of " 139 "RAM or texture memory consumed by the texture when it is loaded.",
140 &EggToBam::dispatch_none, &_tex_txopz);
146 "Pre-compress the texture images using the libsquish library, when " 147 "using -rawtex or -txo. " 149 "Asks the graphics card to pre-compress the texture images when using " 153 "This is unrelated to the on-disk compression achieved " 154 "via -txopz (and it may be used in conjunction with that parameter). " 156 "This will result in a smaller RAM and texture memory footprint for " 157 "the texture images. The same " 158 "effect can be achieved at load time by setting compressed-textures in " 159 "your Config.prc file; but -ctex pre-compresses the " 160 "textures so that they do not need to be compressed at load time. " 162 "Note that, since your Panda is not compiled with the libsquish " 163 "library, using -ctex will make .txo files that are only guaranteed " 164 "to load on the particular graphics card that was used to " 168 &EggToBam::dispatch_none, &_tex_ctex);
172 "Records the pre-generated mipmap levels in the texture object file " 173 "when using -rawtex or -txo, regardless of the texture filter mode. This " 174 "will increase the size of the texture object file by about 33%, but " 175 "it prevents the need to compute the mipmaps at runtime. The default " 176 "is to record mipmap levels only when the texture uses a mipmap " 178 &EggToBam::dispatch_none, &_tex_mipmap);
181 (
"ctexq",
"quality", 0,
182 "Specifies the compression quality to use when performing the " 183 "texture compression requested by -ctex. This may be one of " 184 "'default', 'fastest', 'normal', or 'best'. The default is 'best'. " 185 "Set it to 'default' to use whatever is specified by the Config.prc " 186 "file. This is a global setting only; individual texture quality " 187 "settings appearing within the egg file will override this.",
188 &EggToBam::dispatch_string,
nullptr, &_ctex_quality);
191 (
"load-display",
"display name", 0,
192 "Specifies the particular display module to load to perform the texture " 193 "compression requested by -ctex. If this is omitted, the default is " 194 "taken from the Config.prc file." 196 " Since your Panda has libsquish compiled in, this is not necessary; " 197 "Panda can compress textures without loading a display module." 200 &EggToBam::dispatch_string,
nullptr, &_load_display);
204 "Specify the coordinate system of the resulting " + _format_name +
205 " file. This may be " 206 "one of 'y-up', 'z-up', 'y-up-left', or 'z-up-left'. The default " 209 _force_complete =
true;
211 _egg_combine_geoms = 0;
212 _egg_suppress_hidden = 1;
214 _ctex_quality =
"best";
222 if (_has_egg_flatten) {
225 egg_flatten = (_egg_flatten != 0);
227 if (_has_egg_combine_geoms) {
229 egg_combine_geoms = (_egg_combine_geoms != 0);
233 egg_suppress_hidden = _egg_suppress_hidden;
235 if (_compression_off) {
237 compress_channels =
false;
239 }
else if (_has_compression_quality) {
242 compress_channels =
true;
243 compress_chan_quality = _compression_quality;
246 if (_ctex_quality !=
"default") {
249 std::string prc =
"texture-quality-level " + _ctex_quality;
253 if (!_got_coordinate_system) {
256 _data->set_coordinate_system(CS_zup_right);
259 PT(
PandaNode) root = load_egg_data(_data);
260 if (root ==
nullptr) {
261 nout <<
"Unable to build scene graph from egg file.\n";
267 if (!make_buffer()) {
268 nout <<
"Unable to initialize graphics context; cannot compress textures.\n";
271 #endif // HAVE_SQUISH 274 if (_tex_txo || _tex_txopz || (_tex_ctex && _tex_rawdata)) {
275 collect_textures(root);
276 Textures::iterator ti;
277 for (ti = _textures.begin(); ti != _textures.end(); ++ti) {
280 bool want_mipmaps = (_tex_mipmap || tex->
uses_mipmaps());
289 nout <<
" couldn't compress " << tex->get_name() <<
"\n";
296 nout <<
" couldn't compress " << tex->get_name() <<
"\n";
298 if (!has_mipmap_levels && !want_mipmaps) {
304 #endif // HAVE_SQUISH 307 if (_tex_txo || _tex_txopz) {
323 nout <<
"Writing " << filename <<
"\n";
326 nout <<
"Error in writing.\n";
331 nout <<
"Error in writing.\n";
347 bam_texture_mode = BamFile::BTM_rawdata;
349 }
else if (_got_path_store) {
350 bam_texture_mode = BamFile::BTM_unchanged;
355 _path_replace->_path_store = PS_absolute;
358 return EggToSomething::handle_args(args);
366 collect_textures(node->get_state());
370 for (
int i = 0; i < num_geoms; ++i) {
377 for (
int i = 0; i < num_children; ++i) {
388 if (tex_attrib !=
nullptr) {
390 for (
int i = 0; i < num_on_stages; ++i) {
414 if (tex->
write(fullpath)) {
415 nout <<
" Writing " << fullpath;
443 if (!_load_display.empty()) {
445 std::string prc =
"load-display " + _load_display;
450 _pipe = selection->make_default_pipe();
451 if (_pipe ==
nullptr) {
452 nout <<
"Unable to create graphics pipe.\n";
462 fbprops.set_back_buffers(0);
474 GraphicsPipe::BF_fb_props_optional);
476 if (_buffer ==
nullptr || !_buffer->
is_valid()) {
477 nout <<
"Unable to create graphics window.\n";
486 int main(
int argc,
char *argv[]) {
CPTA_uchar get_ram_image()
Returns the system-RAM image data associated with the texture.
The principle public interface to reading and writing Bam disk files.
static const FrameBufferProperties & get_default()
Returns a FrameBufferProperties structure with all of the default values filled in according to the u...
get_geom_state
Returns the RenderState associated with the nth geom of the node.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
set_fullpath
Sets the full pathname to the file that contains the image's contents, as found along the search path...
get_filename
Returns the filename that has been set.
bool write_object(const TypedWritable *object)
Writes the indicated object to the Bam file.
void set_extension(const std::string &s)
Replaces the file extension.
A basic node of the scene graph or data graph.
set_filename
Sets the name of the file that contains the image's contents.
get_fullpath
Returns the fullpath that has been set.
set_loaded_from_txo
Sets the flag that indicates the texture has been loaded from a txo file.
set_size
Specifies the requested size of the window, in pixels.
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_...
PandaNode * get_child(size_t n) const
Returns the nth child of the node.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
get_num_on_stages
Returns the number of stages that are turned on by the attribute.
get_on_stage
Returns the nth stage turned on by the attribute, sorted in render order.
set_z_order
Specifies the relative ordering of the window with respect to other windows.
Represents a texture object, which is typically a single 2-d image but may also represent a 1-d or 3-...
void open_windows()
Fully opens (or closes) any windows that have recently been requested open or closed,...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
set_undecorated
Specifies whether the window should be created with a visible title and border (false,...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
GraphicsOutput * make_output(GraphicsPipe *pipe, const std::string &name, int sort, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, GraphicsStateGuardian *gsg=nullptr, GraphicsOutput *host=nullptr)
Creates a new window (or buffer) and returns it.
bool is_valid() const
Returns true if the output is fully created and ready for rendering, false otherwise.
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.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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,...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
The name of a file, such as a texture file or an Egg file.
set_origin
Specifies the origin on the screen (in pixels, relative to the top-left corner) at which the window s...
set_keep_ram_image
Sets the flag that indicates whether this Texture is eligible to have its main RAM copy of the textur...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
size_t get_num_children() const
Returns the number of children of the node.
This maintains a list of GraphicsPipes by type that are available for creation.
std::string get_fullpath() const
Returns the entire filename: directory, basename, extension.
EXPCL_PANDA_PUTIL ConfigPage * load_prc_file_data(const std::string &name, const std::string &data)
Another convenience function to load a prc file from an explicit string, which represents the content...
bool extract_texture_data(Texture *tex, GraphicsStateGuardian *gsg)
Asks the indicated GraphicsStateGuardian to retrieve the texture memory image of the indicated textur...
void clear_ram_mipmap_images()
Discards the current system-RAM image for all mipmap levels, except level 0 (the base image).
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
get_children
Returns an object that can be used to walk through the list of children of the node.
static GraphicsPipeSelection * get_global_ptr()
Returns a pointer to the one global GraphicsPipeSelection object.
This represents a unique collection of RenderAttrib objects that correspond to a particular renderabl...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
set_compression
Requests that this particular Texture be compressed when it is loaded into texture memory.
void generate_ram_mipmap_images()
Automatically fills in the n mipmap levels of the Texture, based on the texture's source image.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
get_num_geoms
Returns the number of geoms in the node.
clear_alpha_filename
Removes the alpha filename, if it was previously set.
bool compress_ram_image(CompressionMode compression=CM_on, QualityLevel quality_level=QL_default, GraphicsStateGuardianBase *gsg=nullptr)
Attempts to compress the texture's RAM image internally, to a format supported by the indicated GSG.
This is the general base class for a file-converter program that reads some model file format and gen...
get_num_ram_mipmap_images
Returns the maximum number of mipmap level images available in system memory.
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 open_write(const Filename &bam_filename, bool report_errors=true)
Attempts to open the indicated file for writing.
clear_alpha_fullpath
Removes the alpha fullpath, if it was previously set.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A container for the various kinds of properties we might ask to have on a graphics frameBuffer before...
get_loaded_from_txo
Returns the flag that indicates the texture has been loaded from a txo file.
virtual bool is_geom_node() const
A simple downcast check.
set_open
Specifies whether the window should be open.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
get_gsg
Returns the GSG that is associated with this window.
A node that holds Geom objects, renderable pieces of geometry.
bool write(const Filename &fullpath)
Writes the texture to the named filename.
get_on_texture
Returns the texture associated with the indicated stage, or NULL if no texture is associated.
get_ram_image_compression
Returns the compression mode in which the ram image is already stored pre- compressed.