Panda3D
eggJointData.h
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file eggJointData.h
10  * @author drose
11  * @date 2001-02-23
12  */
13 
14 #ifndef EGGJOINTDATA_H
15 #define EGGJOINTDATA_H
16 
17 #include "pandatoolbase.h"
18 #include "eggComponentData.h"
19 #include "eggGroup.h"
20 #include "luse.h"
21 #include "pset.h"
22 
23 class EggCharacterDb;
24 
25 /**
26  * This is one node of a hierarchy of EggJointData nodes, each of which
27  * represents a single joint of the character hierarchy across all loaded
28  * files: the various models, the LOD's of each model, and the various
29  * animation channel files.
30  */
32 public:
34  EggCharacterData *char_data);
35 
36  INLINE EggJointData *get_parent() const;
37  INLINE int get_num_children() const;
38  INLINE EggJointData *get_child(int n) const;
39  INLINE EggJointData *find_joint(const std::string &name);
40 
41  LMatrix4d get_frame(int model_index, int n) const;
42  LMatrix4d get_net_frame(int model_index, int n, EggCharacterDb &db) const;
43  LMatrix4d get_net_frame_inv(int model_index, int n, EggCharacterDb &db) const;
44 
45  INLINE bool has_rest_frame() const;
46  INLINE bool rest_frames_differ() const;
47  INLINE const LMatrix4d &get_rest_frame() const;
49 
50  INLINE void reparent_to(EggJointData *new_parent);
51  void move_vertices_to(EggJointData *new_owner);
52  int score_reparent_to(EggJointData *new_parent, EggCharacterDb &db);
53 
55  void optimize();
56  void expose(EggGroup::DCSType dcs_type = EggGroup::DC_default);
57  void zero_channels(const std::string &components);
58  void quantize_channels(const std::string &components, double quantum);
59  void apply_default_pose(int source_model, int frame);
60 
61  virtual void add_back_pointer(int model_index, EggObject *egg_object);
62  virtual void write(std::ostream &out, int indent_level = 0) const;
63 
64 protected:
65  void do_begin_reparent();
66  bool calc_new_parent_depth(pset<EggJointData *> &chain);
67  void do_begin_compute_reparent();
68  bool do_compute_reparent(int model_index, int n, EggCharacterDb &db);
69  bool do_joint_rebuild(int model_index, EggCharacterDb &db);
70  void do_finish_reparent();
71 
72 private:
73  EggJointData *make_new_joint(const std::string &name);
74  EggJointData *find_joint_exact(const std::string &name);
75  EggJointData *find_joint_matches(const std::string &name);
76 
77  bool is_new_ancestor(EggJointData *child) const;
78  const LMatrix4d &get_new_net_frame(int model_index, int n, EggCharacterDb &db);
79  const LMatrix4d &get_new_net_frame_inv(int model_index, int n, EggCharacterDb &db);
80  LMatrix4d get_new_frame(int model_index, int n, EggCharacterDb &db);
81 
82  bool _has_rest_frame;
83  bool _rest_frames_differ;
84  LMatrix4d _rest_frame;
85 
86  // These are used to cache the above results for optimizing
87  // do_compute_reparent().
88  LMatrix4d _new_net_frame, _new_net_frame_inv;
89  bool _got_new_net_frame, _got_new_net_frame_inv;
90  bool _computed_reparent;
91  bool _computed_ok;
92 
93 protected:
95  Children _children;
96  EggJointData *_parent;
97  EggJointData *_new_parent;
98  int _new_parent_depth;
99  bool _got_new_parent_depth;
100 
101 
102 public:
103  static TypeHandle get_class_type() {
104  return _type_handle;
105  }
106  static void init_type() {
107  EggComponentData::init_type();
108  register_type(_type_handle, "EggJointData",
109  EggComponentData::get_class_type());
110  }
111  virtual TypeHandle get_type() const {
112  return get_class_type();
113  }
114  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
115 
116 private:
117  static TypeHandle _type_handle;
118 
119  friend class EggCharacterCollection;
120  friend class EggCharacterData;
121  friend class OrderJointsByNewDepth;
122 };
123 
124 #include "eggJointData.I"
125 
126 #endif
void reparent_to(EggJointData *new_parent)
Indicates an intention to change the parent of this joint to the indicated joint, or NULL to remove i...
Definition: eggJointData.I:91
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void optimize()
Calls optimize() on all models, and recursively on all joints at this node and below.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
Definition: register_type.I:22
bool rest_frames_differ() const
Returns true if the rest frames for different models differ in their initial value.
Definition: eggJointData.I:69
This is the base class of both EggJointData and EggSliderData.
LMatrix4d get_net_frame_inv(int model_index, int n, EggCharacterDb &db) const
Returns the inverse of get_net_frame().
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void apply_default_pose(int source_model, int frame)
Applies the pose from the indicated frame of the indicated source model_index as the initial pose for...
This class is used during joint optimization or restructuring to store the table of interim joint com...
bool has_rest_frame() const
Returns true if the joint knows its rest frame, false otherwise.
Definition: eggJointData.I:59
LMatrix4d get_net_frame(int model_index, int n, EggCharacterDb &db) const
Returns the complete transform from the root corresponding to this joint position in the nth frame in...
void move_vertices_to(EggJointData *new_owner)
Moves the vertices assigned to this joint into the indicated joint, without changing their weight ass...
Represents a set of characters, as read and collected from possibly several model and/or animation eg...
Represents a single character, as read and collected from several models and animation files.
int score_reparent_to(EggJointData *new_parent, EggCharacterDb &db)
Computes a score >= 0 reflecting the similarity of the current joint's animation (in world space) to ...
const LMatrix4d & get_rest_frame() const
Returns the rest frame of the joint.
Definition: eggJointData.I:79
This is one node of a hierarchy of EggJointData nodes, each of which represents a single joint of the...
Definition: eggJointData.h:31
virtual void add_back_pointer(int model_index, EggObject *egg_object)
Adds the indicated model joint or anim table to the data.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void force_initial_rest_frame()
Forces all of the joints to have the same rest frame value as the first joint read in.
LMatrix4d get_frame(int model_index, int n) const
Returns the local transform matrix corresponding to this joint position in the nth frame in the indic...
void zero_channels(const std::string &components)
Calls zero_channels() on all models for this joint, but does not recurse downwards.
void quantize_channels(const std::string &components, double quantum)
Calls quantize_channels() on all models for this joint, and then recurses downwards to all joints bel...
EggJointData * find_joint(const std::string &name)
Returns the first descendent joint found with the indicated name, or NULL if no joint has that name.
Definition: eggJointData.I:44
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bool do_rebuild_all(EggCharacterDb &db)
Calls do_rebuild() on all models, and recursively on all joints at this node and below.
This is our own Panda specialization on the default STL set.
Definition: pset.h:49
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
void expose(EggGroup::DCSType dcs_type=EggGroup::DC_default)
Calls expose() on all models for this joint, but does not recurse downwards.
The highest-level base class in the egg directory.
Definition: eggObject.h:29