17 #include "cvsSourceDirectory.h" 18 #include "fltHeader.h" 20 #include "fltExternalReference.h" 32 set_program_brief(
"copy MultiGen .flt files into a CVS source hierarchy");
33 set_program_description
34 (
"fltcopy copies one or more MultiGen .flt files into a " 35 "CVS source hierarchy. " 36 "Rather than copying the named files immediately into the current " 37 "directory, it first scans the entire source hierarchy, identifying all " 38 "the already-existing files. If the named file to copy matches the " 39 "name of an already-existing file in the current directory or elsewhere " 40 "in the hierarchy, that file is overwritten. Other .flt files, as " 41 "well as texture files, that are externally referenced by the " 42 "named .flt file(s) are similarly copied.");
45 add_runline(
"[opts] file.flt [file.flt ... ]");
47 add_path_replace_options();
57 SourceFiles::iterator fi;
58 for (fi = _source_files.begin(); fi != _source_files.end(); ++fi) {
80 ExtraData *ed = (ExtraData *)extra_data;
83 return copy_flt_file(source, dest, dir);
86 return copy_texture(source, dest, dir, ed->_texture, new_file);
89 nout <<
"Internal error: invalid type " << (int)ed->_type <<
"\n";
105 header->set_auto_attr_update(FltHeader::AU_none);
107 FltError result = header->read_flt(source);
108 if (result != FE_ok) {
109 nout <<
"Cannot read " << source <<
": " << result <<
"\n";
113 header->check_version();
118 scan_flt(header, refs, textures);
120 Refs::const_iterator ri;
121 for (ri = refs.begin(); ri != refs.end(); ++ri) {
125 if (!ref_filename.
exists()) {
126 nout <<
"*** Warning: external reference " << ref_filename
127 <<
" does not exist.\n";
133 import(ref_filename, &ed, _model_dir);
147 header->clear_textures();
149 Textures::const_iterator ti;
150 for (ti = textures.begin(); ti != textures.end(); ++ti) {
154 if (!texture_filename.
exists()) {
155 nout <<
"*** Warning: texture " << texture_filename
156 <<
" does not exist.\n";
159 ed._type = FT_texture;
163 import(texture_filename, &ed, _map_dir);
171 header->add_texture(tex);
176 result = header->write_flt(dest);
177 if (result != FE_ok) {
178 nout <<
"Cannot write " << dest <<
"\n";
193 if (!copy_binary_file(source, dest)) {
199 if (!attr_filename.
exists()) {
206 cvs_add(attr_filename);
221 if (record->
is_of_type(FltFace::get_class_type())) {
223 DCAST_INTO_V(face, record);
228 }
else if (record->
is_of_type(FltExternalReference::get_class_type())) {
230 DCAST_INTO_V(ref, record);
237 for (i = 0; i < num_subfaces; i++) {
242 for (i = 0; i < num_children; i++) {
243 scan_flt(record->
get_child(i), refs, textures);
248 int main(
int argc,
char *argv[]) {
bool is_valid() const
Returns true if this FilePath represents a valid file, or false if it represents an error return...
Filename get_texture_filename() const
Returns the name of the texture image 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_...
void set_texture_filename(const Filename &filename)
Changes the name of the texture image file.
int get_num_children() const
Returns the number of child records of this record.
void set_ref_filename(const Filename &filename)
Changes the name of the referenced file.
FltError write_attr_data() const
Writes the texture's .attr file.
FltRecord * get_subface(int n) const
Returns the nth subface of this record.
This represents one particular directory in the hierarchy of source directory files.
Represents a single texture in the texture palette.
The name of a file, such as a texture file or an Egg file.
The base class for all kinds of records in a MultiGen OpenFlight file.
A program to copy Multigen .flt files into the cvs tree.
An external reference to another flt file (possibly to a specific bead within the flt file)...
FltRecord * get_child(int n) const
Returns the nth child of this record.
Filename get_ref_filename() const
Returns the name of the referenced file.
bool is_of_type(TypeHandle handle) const
Returns true if the current object is or derives from the indicated type.
This is our own Panda specialization on the default STL set.
bool has_texture() const
Returns true if the face has a texture applied, false otherwise.
Filename get_rel_from(const CVSSourceDirectory *other) const
Returns the relative path to this file as seen from the indicated source directory.
FltTexture * get_texture() const
Returns the texture applied to this face, or NULL if no texture was applied.
bool exists() const
Returns true if the filename exists on the disk, false otherwise.
int get_num_subfaces() const
Returns the number of subface records of this record.