Loader
-
class Loader
Bases:
TypedReferenceCount
,Namable
A convenient class for loading models from disk, in bam or egg format (or any of a number of other formats implemented by a
LoaderFileType
, such as ptloader).This class supports synchronous as well as asynchronous loading. In asynchronous loading, the model is loaded in the background by a thread, and an event will be generated when the model is available. If threading is not available, the asynchronous loading interface may be used, but it loads synchronously.
Inheritance diagram
-
class Results
-
Results(void)
-
void clear(void)
Removes all the files from the list.
-
LoaderFileType *get_file_type(int n) const
Returns the file type of the nth file on the result list.
-
int get_num_files(void) const
Returns the number of files on the result list.
-
Results(void)
-
explicit Loader(std::string const &name = "loader")
-
static TypeHandle get_class_type(void)
-
Loader *get_global_ptr(void)
Returns a pointer to the global Loader. This is the Loader that most code should use for loading models.
-
std::string const &get_task_chain(void) const
Returns the task chain that is used for asynchronous loads.
-
AsyncTaskManager *get_task_manager(void) const
Returns the task manager that is used for asynchronous loads.
-
void load_async(AsyncTask *request)
Begins an asynchronous load request. To use this call, first call
make_async_request()
to create a newModelLoadRequest
object with the filename you wish to load, and then add that object to the Loader with load_async. This function will return immediately, and the model will be loaded in the background.To determine when the model has completely loaded, you may poll request->is_ready() from time to time, or set the done_event on the request object and listen for that event. When the model is ready, you may retrieve it via request->get_model().
-
PointerTo<PandaNode> load_bam_stream(std::istream &in)
Attempts to read a bam file from the indicated stream and return the scene graph defined there.
-
PointerTo<PandaNode> load_sync(Filename const &filename, LoaderOptions const &options = LoaderOptions()) const
Loads the file immediately, waiting for it to complete.
If search is true, the file is searched for along the model path; otherwise, only the exact filename is loaded.
-
PointerTo<AsyncTask> make_async_request(Filename const &filename, LoaderOptions const &options = LoaderOptions())
Returns a new
AsyncTask
object suitable for adding toload_async()
to start an asynchronous model load.
-
PointerTo<AsyncTask> make_async_save_request(Filename const &filename, LoaderOptions const &options, PandaNode *node)
Returns a new
AsyncTask
object suitable for adding tosave_async()
to start an asynchronous model save.
-
virtual void output(std::ostream &out) const
-
bool remove(AsyncTask *task)
Removes a pending asynchronous load request. Returns true if successful, false otherwise.
Deprecated: use task.cancel() to cancel the request instead.
-
void save_async(AsyncTask *request)
Begins an asynchronous save request. To use this call, first call
make_async_save_request()
to create a newModelSaveRequest
object with the filename you wish to load, and then add that object to the Loader with save_async. This function will return immediately, and the model will be loaded in the background.To determine when the model has completely loaded, you may poll request->is_ready() from time to time, or set the done_event on the request object and listen for that event. When the request is ready, you may retrieve the success or failure via request->get_success().
-
bool save_sync(Filename const &filename, LoaderOptions const &options, PandaNode *node) const
Saves the file immediately, waiting for it to complete.
-
void set_task_chain(std::string const &task_chain)
Specifies the task chain that is used for asynchronous loads. The default is the initial name of the Loader object.
-
void set_task_manager(AsyncTaskManager *task_manager)
Specifies the task manager that is used for asynchronous loads. The default is the global task manager.
-
void stop_threads(void)
Stop any threads used for asynchronous loads.
-
class Results