Panda3D
 All Classes Functions Variables Enumerations
bindAnimRequest.cxx
1 // Filename: bindAnimRequest.cxx
2 // Created by: drose (05Aug08)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #include "bindAnimRequest.h"
16 #include "animBundleNode.h"
17 #include "animControl.h"
18 #include "partBundle.h"
19 
20 TypeHandle BindAnimRequest::_type_handle;
21 
22 ////////////////////////////////////////////////////////////////////
23 // Function: BindAnimRequest::Constructor
24 // Access: Public
25 // Description:
26 ////////////////////////////////////////////////////////////////////
27 BindAnimRequest::
28 BindAnimRequest(const string &name,
29  const Filename &filename, const LoaderOptions &options,
30  Loader *loader,
31  AnimControl *control, int hierarchy_match_flags,
32  const PartSubset &subset) :
33  ModelLoadRequest(name, filename, options, loader),
34  _control(control),
35  _hierarchy_match_flags(hierarchy_match_flags),
36  _subset(subset)
37 {
38 }
39 
40 ////////////////////////////////////////////////////////////////////
41 // Function: BindAnimRequest::do_task
42 // Access: Protected, Virtual
43 // Description: Performs the task: that is, loads and binds the
44 // animation.
45 ////////////////////////////////////////////////////////////////////
46 AsyncTask::DoneStatus BindAnimRequest::
47 do_task() {
48  ModelLoadRequest::do_task();
49 
50  PartBundle *part = _control->get_part();
51 
52  if (_control->get_ref_count() == 1) {
53  // We're holding the only remaining reference to this AnimControl.
54  // Therefore, forget the bind attempt; no one cares anyway.
55  _control->fail_anim(part);
56  return DS_done;
57  }
58 
59  PT(PandaNode) model = get_model();
60  if (model == (PandaNode *)NULL) {
61  // Couldn't load the file.
62  _control->fail_anim(part);
63  return DS_done;
64  }
65  _control->set_anim_model(model);
66 
68  if (anim == (AnimBundle *)NULL) {
69  // No anim bundle.
70  _control->fail_anim(part);
71  return DS_done;
72  }
73 
74  if (!part->do_bind_anim(_control, anim, _hierarchy_match_flags, _subset)) {
75  // Couldn't bind.
76  _control->fail_anim(part);
77  return DS_done;
78  }
79 
80  return DS_done;
81 }
A basic node of the scene graph or data graph.
Definition: pandaNode.h:72
Specifies parameters that may be passed to the loader.
Definition: loaderOptions.h:26
This is the root of an AnimChannel hierarchy.
Definition: animBundle.h:31
A convenient class for loading models from disk, in bam or egg format (or any of a number of other fo...
Definition: loader.h:47
static AnimBundle * find_anim_bundle(PandaNode *root)
Recursively walks the scene graph beginning at the indicated node (which need not be an AnimBundleNod...
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:44
bool do_bind_anim(AnimControl *control, AnimBundle *anim, int hierarchy_match_flags, const PartSubset &subset)
The internal implementation of bind_anim(), this receives a pointer to an uninitialized AnimControl a...
Definition: partBundle.cxx:629
This class is used to define a subset of part names to apply to the PartBundle::bind_anim() operation...
Definition: partSubset.h:28
This is the root of a MovingPart hierarchy.
Definition: partBundle.h:49
Controls the timing of a character animation.
Definition: animControl.h:41
A class object that manages a single asynchronous model load request.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
PandaNode * get_model() const
Returns the model that was loaded asynchronously, if any, or NULL if there was an error...