Panda3D
modelFlattenRequest.cxx
1 // Filename: modelFlattenRequest.cxx
2 // Created by: drose (30Mar07)
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 "modelFlattenRequest.h"
16 #include "nodePath.h"
17 
18 TypeHandle ModelFlattenRequest::_type_handle;
19 
20 ////////////////////////////////////////////////////////////////////
21 // Function: ModelFlattenRequest::do_task
22 // Access: Protected, Virtual
23 // Description: Performs the task: that is, copies and flattens the
24 // model.
25 ////////////////////////////////////////////////////////////////////
26 AsyncTask::DoneStatus ModelFlattenRequest::
27 do_task() {
28  // We make another instance of the original node, so we can safely flatten
29  // that without affecting the original copy.
30  NodePath np("flatten_root");
31 
32  // Except if we try to attach a node without parents, this will cause the
33  // original NodePath to be affected, so we have to make a (shallow) copy.
34  if (_orig->get_num_parents() == 0) {
35  PT(PandaNode) copy = _orig->make_copy();
36  copy->copy_children(_orig);
37  np.attach_new_node(copy);
38  } else {
39  np.attach_new_node(_orig);
40  }
41  np.flatten_strong();
42  _model = np.get_child(0).node();
43  _is_ready = true;
44 
45  // Don't continue the task; we're done.
46  return DS_done;
47 }
A basic node of the scene graph or data graph.
Definition: pandaNode.h:72
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition: nodePath.h:165