21 ModelPool *ModelPool::_global_ptr =
nullptr;
29 get_ptr()->ns_list_contents(out);
36 ns_has_model(
const Filename &filename) {
38 Models::const_iterator ti;
39 ti = _models.find(filename);
40 if (ti != _models.end() && (*ti).second !=
nullptr) {
52 ns_get_model(
const Filename &filename,
bool verify) {
55 bool got_cached_model =
false;
59 Models::const_iterator ti;
60 ti = _models.find(filename);
61 if (ti != _models.end()) {
63 cached_model = (*ti).second;
64 got_cached_model =
true;
68 if (got_cached_model && verify) {
69 if (pgraph_cat.is_debug()) {
71 <<
"ModelPool found " << cached_model <<
" for " << filename <<
"\n";
74 if (cached_model ==
nullptr) {
77 if (cache_check_timestamps) {
80 if (vfs->
exists(filename)) {
82 got_cached_model =
false;
87 if (cache_check_timestamps && cached_model->get_timestamp() != 0 &&
88 !cached_model->get_fullpath().empty()) {
92 if (vfile ==
nullptr) {
94 got_cached_model =
false;
96 }
else if (vfile->get_timestamp() > cached_model->get_timestamp()) {
99 got_cached_model =
false;
105 if (got_cached_model) {
106 if (pgraph_cat.is_debug()) {
108 <<
"ModelPool returning " << cached_model <<
" for " << filename <<
"\n";
123 PT(
ModelRoot) cached_model = ns_get_model(filename,
true);
124 if (cached_model !=
nullptr) {
130 new_options.set_flags((new_options.get_flags() | LoaderOptions::LF_no_ram_cache) &
131 ~LoaderOptions::LF_search);
134 PT(
PandaNode) panda_node = model_loader->load_sync(filename, new_options);
137 if (panda_node.is_null()) {
141 if (panda_node->is_of_type(ModelRoot::get_class_type())) {
147 node->add_child(panda_node);
149 node->set_fullpath(filename);
157 Models::const_iterator ti;
158 ti = _models.find(filename);
159 if (ti != _models.end() && (*ti).second != cached_model) {
164 _models[filename] = node;
176 if (pgraph_cat.is_debug()) {
178 <<
"ModelPool storing " << model <<
" for " << filename <<
"\n";
181 _models[filename] = model;
188 ns_release_model(
const Filename &filename) {
191 ti = _models.find(filename);
192 if (ti != _models.end()) {
215 if (ti != _models.end()) {
224 ns_release_all_models() {
233 ns_garbage_collect() {
236 int num_released = 0;
240 for (ti = _models.begin(); ti != _models.end(); ++ti) {
242 if (node ==
nullptr ||
244 if (loader_cat.is_debug()) {
246 <<
"Releasing " << (*ti).first <<
"\n";
250 new_set.insert(new_set.end(), *ti);
254 _models.swap(new_set);
262 ns_list_contents(std::ostream &out)
const {
265 out <<
"model pool contents:\n";
267 Models::const_iterator ti;
269 for (ti = _models.begin(); ti != _models.end(); ++ti) {
270 if ((*ti).second !=
nullptr) {
272 out << (*ti).first <<
"\n" 273 <<
" (count = " << (*ti).second->get_model_ref_count()
278 out <<
"total number of models: " << num_models <<
" (plus " 279 << _models.size() - num_models <<
" entries for nonexistent files)\n";
288 if (_global_ptr ==
nullptr) {
A node of this type is created automatically at the root of each model file that is loaded.
A basic node of the scene graph or data graph.
get_model_ref_count
Returns the number of copies that exist of this particular ModelRoot node.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
get_fullpath
Returns the full pathname of the model represented by this node, as found on disk.
Specifies parameters that may be passed to the loader.
A hierarchy of directories and files that appears to be one continuous file system,...
This class unifies all references to the same filename, so that multiple attempts to load the same mo...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A convenient class for loading models from disk, in bam or egg format (or any of a number of other fo...
The abstract base class for a file or directory within the VirtualFileSystem.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
static Loader * get_global_ptr()
Returns a pointer to the global Loader.
static void write(std::ostream &out)
Lists the contents of the model pool to the indicated output stream.
bool exists(const Filename &filename) const
Convenience function; returns true if the named file exists.
The name of a file, such as a texture file or an Egg file.
Similar to MutexHolder, but for a light mutex.
static VirtualFileSystem * get_global_ptr()
Returns the default global VirtualFileSystem.
PointerTo< VirtualFile > get_file(const Filename &filename, bool status_only=false) const
Looks up the file by the indicated name in the file system.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.