mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-19 21:32:58 -04:00
loader: try appending .bam to filename if loading doesn't find model
This commit is contained in:
parent
a2fd511db8
commit
37572b312c
@ -159,36 +159,29 @@ load_file(const Filename &filename, const LoaderOptions &options) const {
|
|||||||
"in your Config.prc to globally assume a particular model "
|
"in your Config.prc to globally assume a particular model "
|
||||||
"filename extension.\n";
|
"filename extension.\n";
|
||||||
}
|
}
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
LoaderFileTypeRegistry *reg = LoaderFileTypeRegistry::get_global_ptr();
|
LoaderFileTypeRegistry *reg = LoaderFileTypeRegistry::get_global_ptr();
|
||||||
LoaderFileType *requested_type =
|
LoaderFileType *requested_type = reg->get_type_from_extension(extension);
|
||||||
reg->get_type_from_extension(extension);
|
// requested_type may be nullptr at this point, because there's still a
|
||||||
if (requested_type == (LoaderFileType *)NULL) {
|
// chance we can load it via the model-cache or by adding .bam to the end.
|
||||||
if (report_errors) {
|
if (requested_type != nullptr) {
|
||||||
loader_cat.error()
|
if (!requested_type->supports_load()) {
|
||||||
<< "Extension of file " << this_filename
|
if (report_errors) {
|
||||||
<< " is unrecognized; cannot load.\n";
|
loader_cat.error()
|
||||||
loader_cat.error(false)
|
<< requested_type->get_name() << " file type (."
|
||||||
<< "Currently known scene file types are:\n";
|
<< extension << ") does not support loading.\n";
|
||||||
reg->write(loader_cat.error(false), 2);
|
}
|
||||||
|
return nullptr;
|
||||||
|
} else if (compressed && !requested_type->supports_compressed()) {
|
||||||
|
if (report_errors) {
|
||||||
|
loader_cat.error()
|
||||||
|
<< requested_type->get_name() << " file type (."
|
||||||
|
<< extension << ") does not support in-line compression.\n";
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
}
|
}
|
||||||
return NULL;
|
|
||||||
} else if (!requested_type->supports_load()) {
|
|
||||||
if (report_errors) {
|
|
||||||
loader_cat.error()
|
|
||||||
<< requested_type->get_name() << " file type (."
|
|
||||||
<< extension << ") does not support loading.\n";
|
|
||||||
}
|
|
||||||
return NULL;
|
|
||||||
} else if (compressed && !requested_type->supports_compressed()) {
|
|
||||||
if (report_errors) {
|
|
||||||
loader_cat.error()
|
|
||||||
<< requested_type->get_name() << " file type (."
|
|
||||||
<< extension << ") does not support in-line compression.\n";
|
|
||||||
}
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool search = (this_options.get_flags() & LoaderOptions::LF_search) != 0;
|
bool search = (this_options.get_flags() & LoaderOptions::LF_search) != 0;
|
||||||
@ -227,6 +220,14 @@ load_file(const Filename &filename, const LoaderOptions &options) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (any_exist) {
|
if (any_exist) {
|
||||||
|
if (requested_type == nullptr) {
|
||||||
|
loader_cat.error()
|
||||||
|
<< "Extension of file " << this_filename
|
||||||
|
<< " is unrecognized; cannot load.\n";
|
||||||
|
loader_cat.error(false)
|
||||||
|
<< "Currently known scene file types are:\n";
|
||||||
|
reg->write(loader_cat.error(false), 2);
|
||||||
|
}
|
||||||
loader_cat.error()
|
loader_cat.error()
|
||||||
<< "Couldn't load file " << this_filename
|
<< "Couldn't load file " << this_filename
|
||||||
<< ": all matching files on model path invalid "
|
<< ": all matching files on model path invalid "
|
||||||
@ -248,6 +249,14 @@ load_file(const Filename &filename, const LoaderOptions &options) const {
|
|||||||
}
|
}
|
||||||
if (report_errors) {
|
if (report_errors) {
|
||||||
if (vfs->exists(this_filename)) {
|
if (vfs->exists(this_filename)) {
|
||||||
|
if (requested_type == nullptr) {
|
||||||
|
loader_cat.error()
|
||||||
|
<< "Extension of file " << this_filename
|
||||||
|
<< " is unrecognized; cannot load.\n";
|
||||||
|
loader_cat.error(false)
|
||||||
|
<< "Currently known scene file types are:\n";
|
||||||
|
reg->write(loader_cat.error(false), 2);
|
||||||
|
}
|
||||||
loader_cat.error()
|
loader_cat.error()
|
||||||
<< "Couldn't load file " << this_filename << ": invalid.\n";
|
<< "Couldn't load file " << this_filename << ": invalid.\n";
|
||||||
} else {
|
} else {
|
||||||
@ -330,36 +339,66 @@ try_load_file(const Filename &pathname, const LoaderOptions &options,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cache_only = (options.get_flags() & LoaderOptions::LF_cache_only) != 0;
|
if (options.get_flags() & LoaderOptions::LF_cache_only) {
|
||||||
if (!cache_only) {
|
// We're not allowed to read from disk.
|
||||||
// Load the model from disk.
|
return nullptr;
|
||||||
PT(PandaNode) result = requested_type->load_file(pathname, options, record);
|
}
|
||||||
if (result != (PandaNode *)NULL) {
|
|
||||||
if (record != (BamCacheRecord *)NULL) {
|
|
||||||
// Store the loaded model in the model cache.
|
|
||||||
record->set_data(result);
|
|
||||||
cache->store(record);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (premunge_data) {
|
// Load the model from disk.
|
||||||
SceneGraphReducer sgr;
|
PT(PandaNode) result;
|
||||||
sgr.premunge(result, RenderState::make_empty());
|
if (requested_type != nullptr) {
|
||||||
}
|
result = requested_type->load_file(pathname, options, record);
|
||||||
|
}
|
||||||
|
if (result != nullptr) {
|
||||||
|
if (record != nullptr) {
|
||||||
|
// Store the loaded model in the model cache.
|
||||||
|
record->set_data(result);
|
||||||
|
cache->store(record);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Do we have the same filename, but with .bam appended to the end?
|
||||||
|
string extension = pathname.get_extension();
|
||||||
|
Filename pathname_bam = pathname;
|
||||||
|
if (extension == "pz" || extension == "gz") {
|
||||||
|
// Strip .pz/.gz, so that model.egg.pz -> model.egg.bam
|
||||||
|
extension = pathname_bam.get_extension();
|
||||||
|
pathname_bam = pathname_bam.get_fullpath_wo_extension();
|
||||||
|
}
|
||||||
|
if (extension == "bam") {
|
||||||
|
// Don't try to load .bam.bam files, that is just silly.
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
pathname_bam += ".bam";
|
||||||
|
|
||||||
if (allow_ram_cache && result->is_of_type(ModelRoot::get_class_type())) {
|
BamFile bam_file;
|
||||||
// Store the loaded model in the RAM cache, and make sure we return a
|
if (!bam_file.open_read(pathname_bam, report_errors)) {
|
||||||
// copy so that this node can be modified independently from the RAM
|
return nullptr;
|
||||||
// cached version.
|
}
|
||||||
ModelPool::add_model(pathname, DCAST(ModelRoot, result.p()));
|
|
||||||
if ((options.get_flags() & LoaderOptions::LF_allow_instance) == 0) {
|
bam_file.get_reader()->set_loader_options(options);
|
||||||
result = result->copy_subgraph();
|
result = bam_file.read_node(report_errors);
|
||||||
}
|
|
||||||
}
|
nassertr_always(result != nullptr && result->is_of_type(ModelRoot::get_class_type()), nullptr);
|
||||||
return result;
|
// We don't bother with the model-cache here, since this .bam file is
|
||||||
|
// already effectively a cached version of the original model.
|
||||||
|
}
|
||||||
|
|
||||||
|
if (premunge_data) {
|
||||||
|
SceneGraphReducer sgr;
|
||||||
|
sgr.premunge(result, RenderState::make_empty());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (allow_ram_cache && result->is_of_type(ModelRoot::get_class_type())) {
|
||||||
|
// Store the loaded model in the RAM cache, and make sure we return a
|
||||||
|
// copy so that this node can be modified independently from the RAM
|
||||||
|
// cached version.
|
||||||
|
ModelPool::add_model(pathname, DCAST(ModelRoot, result.p()));
|
||||||
|
if ((options.get_flags() & LoaderOptions::LF_allow_instance) == 0) {
|
||||||
|
result = result->copy_subgraph();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user