Panda3D
 All Classes Functions Variables Enumerations
eggJointData.h
1 // Filename: eggJointData.h
2 // Created by: drose (23Feb01)
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 #ifndef EGGJOINTDATA_H
16 #define EGGJOINTDATA_H
17 
18 #include "pandatoolbase.h"
19 #include "eggComponentData.h"
20 #include "eggGroup.h"
21 #include "luse.h"
22 #include "pset.h"
23 
24 class EggCharacterDb;
25 
26 ////////////////////////////////////////////////////////////////////
27 // Class : EggJointData
28 // Description : This is one node of a hierarchy of EggJointData
29 // nodes, each of which represents a single joint of the
30 // character hierarchy across all loaded files: the
31 // various models, the LOD's of each model, and the
32 // various animation channel files.
33 ////////////////////////////////////////////////////////////////////
35 public:
37  EggCharacterData *char_data);
38 
39  INLINE EggJointData *get_parent() const;
40  INLINE int get_num_children() const;
41  INLINE EggJointData *get_child(int n) const;
42  INLINE EggJointData *find_joint(const string &name);
43 
44  LMatrix4d get_frame(int model_index, int n) const;
45  LMatrix4d get_net_frame(int model_index, int n, EggCharacterDb &db) const;
46  LMatrix4d get_net_frame_inv(int model_index, int n, EggCharacterDb &db) const;
47 
48  INLINE bool has_rest_frame() const;
49  INLINE bool rest_frames_differ() const;
50  INLINE const LMatrix4d &get_rest_frame() const;
52 
53  INLINE void reparent_to(EggJointData *new_parent);
54  void move_vertices_to(EggJointData *new_owner);
55  int score_reparent_to(EggJointData *new_parent, EggCharacterDb &db);
56 
58  void optimize();
59  void expose(EggGroup::DCSType dcs_type = EggGroup::DC_default);
60  void zero_channels(const string &components);
61  void quantize_channels(const string &components, double quantum);
62  void apply_default_pose(int source_model, int frame);
63 
64  virtual void add_back_pointer(int model_index, EggObject *egg_object);
65  virtual void write(ostream &out, int indent_level = 0) const;
66 
67 protected:
68  void do_begin_reparent();
69  bool calc_new_parent_depth(pset<EggJointData *> &chain);
70  void do_begin_compute_reparent();
71  bool do_compute_reparent(int model_index, int n, EggCharacterDb &db);
72  bool do_joint_rebuild(int model_index, EggCharacterDb &db);
73  void do_finish_reparent();
74 
75 private:
76  EggJointData *make_new_joint(const string &name);
77  EggJointData *find_joint_exact(const string &name);
78  EggJointData *find_joint_matches(const string &name);
79 
80  bool is_new_ancestor(EggJointData *child) const;
81  const LMatrix4d &get_new_net_frame(int model_index, int n, EggCharacterDb &db);
82  const LMatrix4d &get_new_net_frame_inv(int model_index, int n, EggCharacterDb &db);
83  LMatrix4d get_new_frame(int model_index, int n, EggCharacterDb &db);
84 
85  bool _has_rest_frame;
86  bool _rest_frames_differ;
87  LMatrix4d _rest_frame;
88 
89  // These are used to cache the above results for optimizing
90  // do_compute_reparent().
91  LMatrix4d _new_net_frame, _new_net_frame_inv;
92  bool _got_new_net_frame, _got_new_net_frame_inv;
93  bool _computed_reparent;
94  bool _computed_ok;
95 
96 protected:
98  Children _children;
99  EggJointData *_parent;
100  EggJointData *_new_parent;
101  int _new_parent_depth;
102  bool _got_new_parent_depth;
103 
104 
105 public:
106  static TypeHandle get_class_type() {
107  return _type_handle;
108  }
109  static void init_type() {
110  EggComponentData::init_type();
111  register_type(_type_handle, "EggJointData",
112  EggComponentData::get_class_type());
113  }
114  virtual TypeHandle get_type() const {
115  return get_class_type();
116  }
117  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
118 
119 private:
120  static TypeHandle _type_handle;
121 
122  friend class EggCharacterCollection;
123  friend class EggCharacterData;
124  friend class OrderJointsByNewDepth;
125 };
126 
127 #include "eggJointData.I"
128 
129 #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:112
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...
bool rest_frames_differ() const
Returns true if the rest frames for different models differ in their initial value.
Definition: eggJointData.I:85
This is a 4-by-4 transform matrix.
Definition: lmatrix.h:4716
void optimize()
Calls optimize() on all models, and recursively on all joints at this node and below.
EggJointData * find_joint(const string &name)
Returns the first descendent joint found with the indicated name, or NULL if no joint has that name...
Definition: eggJointData.I:54
void zero_channels(const string &components)
Calls zero_channels() on all models for this joint, but does not recurse downwards.
bool has_rest_frame() const
Returns true if the joint knows its rest frame, false otherwise.
Definition: eggJointData.I:72
This is the base class of both EggJointData and EggSliderData.
const LMatrix4d & get_rest_frame() const
Returns the rest frame of the joint.
Definition: eggJointData.I:97
void quantize_channels(const string &components, double quantum)
Calls quantize_channels() on all models for this joint, and then recurses downwards to all joints bel...
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...
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 &gt;= 0 reflecting the similarity of the current joint&#39;s animation (in world space) to t...
This is one node of a hierarchy of EggJointData nodes, each of which represents a single joint of the...
Definition: eggJointData.h:34
virtual void add_back_pointer(int model_index, EggObject *egg_object)
Adds the indicated model joint or anim table to the data.
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 force_initial_rest_frame()
Forces all of the joints to have the same rest frame value as the first joint read in...
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:52
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
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:31
LMatrix4d get_net_frame_inv(int model_index, int n, EggCharacterDb &db) const
Returns the inverse of get_net_frame().