Panda3D
Static Public Member Functions

ModelPool Class Reference

This class unifies all references to the same filename, so that multiple attempts to load the same model will return the same pointer. More...

#include "modelPool.h"

List of all members.

Static Public Member Functions

static void add_model (const Filename &filename, ModelRoot *model)
 Adds the indicated already-loaded model to the pool.
static void add_model (ModelRoot *model)
 Adds the indicated already-loaded model to the pool.
static int garbage_collect ()
 Releases only those models in the pool that have a reference count of exactly 1; i.e.
static bool has_model (const Filename &filename)
 Returns true if the model has ever been loaded, false otherwise.
static void list_contents ()
 Lists the contents of the model pool to cout.
static void list_contents (ostream &out)
 Lists the contents of the model pool to the indicated output stream.
static ModelRootload_model (const Filename &filename, const LoaderOptions &options=LoaderOptions())
 Loads the given filename up as a model, if it has not already been loaded, and returns the new model.
static void release_all_models ()
 Releases all models in the pool and restores the pool to the empty state.
static void release_model (const Filename &filename)
 Removes the indicated model from the pool, indicating it will never be loaded again; the model may then be freed.
static void release_model (ModelRoot *model)
 Removes the indicated model from the pool, indicating it will never be loaded again; the model may then be freed.
static bool verify_model (const Filename &filename)
 Loads the given filename up as a model, if it has not already been loaded, and returns true to indicate success, or false to indicate failure.
static void write (ostream &out)
 Lists the contents of the model pool to the indicated output stream.

Detailed Description

This class unifies all references to the same filename, so that multiple attempts to load the same model will return the same pointer.

Note that the default behavior is thus to make instances: use with caution. Use the copy_subgraph() method on Node (or use NodePath::copy_to) to make modifiable copies of the node.

Unlike TexturePool, this class does not automatically resolve the model filenames before loading, so a relative path and an absolute path to the same model will appear to be different filenames.

However, see the Loader class, which is now the preferred interface for loading models. The Loader class can resolve filenames, supports threaded loading, and can automatically consult the ModelPool, according to the supplied LoaderOptions.

Definition at line 48 of file modelPool.h.


Member Function Documentation

void ModelPool::add_model ( const Filename filename,
ModelRoot model 
) [inline, static]

Adds the indicated already-loaded model to the pool.

The model will always replace any previously-loaded model in the pool that had the same filename.

This two-parameter version of this method is deprecated; use the one-parameter add_model(model) instead.

Definition at line 69 of file modelPool.I.

void ModelPool::add_model ( ModelRoot model) [inline, static]

Adds the indicated already-loaded model to the pool.

The model will always replace any previously-loaded model in the pool that had the same filename.

Definition at line 99 of file modelPool.I.

int ModelPool::garbage_collect ( ) [inline, static]

Releases only those models in the pool that have a reference count of exactly 1; i.e.

only those models that are not being used outside of the pool. Returns the number of models released.

Definition at line 141 of file modelPool.I.

bool ModelPool::has_model ( const Filename filename) [inline, static]

Returns true if the model has ever been loaded, false otherwise.

Definition at line 23 of file modelPool.I.

void ModelPool::list_contents ( ) [inline, static]

Lists the contents of the model pool to cout.

Definition at line 162 of file modelPool.I.

void ModelPool::list_contents ( ostream &  out) [inline, static]

Lists the contents of the model pool to the indicated output stream.

Definition at line 152 of file modelPool.I.

ModelRoot * ModelPool::load_model ( const Filename filename,
const LoaderOptions options = LoaderOptions() 
) [inline, static]

Loads the given filename up as a model, if it has not already been loaded, and returns the new model.

If a model with the same filename was previously loaded, returns that one instead. If the model file cannot be found, returns NULL.

Definition at line 52 of file modelPool.I.

Referenced by verify_model().

void ModelPool::release_all_models ( ) [inline, static]

Releases all models in the pool and restores the pool to the empty state.

Definition at line 128 of file modelPool.I.

void ModelPool::release_model ( const Filename filename) [inline, static]

Removes the indicated model from the pool, indicating it will never be loaded again; the model may then be freed.

If this function is never called, a reference count will be maintained on every model every loaded, and models will never be freed.

This version of this method is deprecated; use release_model(model) instead.

Definition at line 86 of file modelPool.I.

void ModelPool::release_model ( ModelRoot model) [inline, static]

Removes the indicated model from the pool, indicating it will never be loaded again; the model may then be freed.

If this function is never called, a reference count will be maintained on every model every loaded, and models will never be freed.

The model's get_fullpath() value should not have been changed during its lifetime, or this function may fail to locate it in the pool.

Definition at line 117 of file modelPool.I.

bool ModelPool::verify_model ( const Filename filename) [inline, static]

Loads the given filename up as a model, if it has not already been loaded, and returns true to indicate success, or false to indicate failure.

If this returns true, it is guaranteed that a subsequent call to load_model() with the same model name will return a valid Node pointer.

Definition at line 38 of file modelPool.I.

References load_model().

void ModelPool::write ( ostream &  out) [static]

Lists the contents of the model pool to the indicated output stream.

Helps with debugging.

Definition at line 31 of file modelPool.cxx.


The documentation for this class was generated from the following files:
 All Classes Functions Variables Enumerations