Panda3D
 All Classes Functions Variables Enumerations
eggCharacterFilter.cxx
1 // Filename: eggCharacterFilter.cxx
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 #include "eggCharacterFilter.h"
16 #include "eggCharacterCollection.h"
17 #include "eggCharacterData.h"
18 
19 
20 ////////////////////////////////////////////////////////////////////
21 // Function: EggCharacterFilter::Constructor
22 // Access: Public
23 // Description:
24 ////////////////////////////////////////////////////////////////////
25 EggCharacterFilter::
26 EggCharacterFilter() : EggMultiFilter(false) {
27  _collection = (EggCharacterCollection *)NULL;
28 
29  _force_initial_rest_frame = false;
30 }
31 
32 ////////////////////////////////////////////////////////////////////
33 // Function: EggCharacterFilter::Destructor
34 // Access: Public, Virtual
35 // Description:
36 ////////////////////////////////////////////////////////////////////
37 EggCharacterFilter::
38 ~EggCharacterFilter() {
39  if (_collection != (EggCharacterCollection *)NULL) {
40  delete _collection;
41  }
42 }
43 
44 ////////////////////////////////////////////////////////////////////
45 // Function: EggCharacterFilter::add_fixrest_option
46 // Access: Public
47 // Description:
48 ////////////////////////////////////////////////////////////////////
49 void EggCharacterFilter::
50 add_fixrest_option() {
51  add_option
52  ("fixrest", "", 30,
53  "Specify this to force all the initial rest frames of the various "
54  "model files to the same value as the first model specified. This "
55  "is a fairly drastic way to repair models whose initial rest frame "
56  "values are completely bogus, but should not be performed when the "
57  "input models are correct.",
58  &EggCharacterFilter::dispatch_none, &_force_initial_rest_frame);
59 }
60 
61 
62 ////////////////////////////////////////////////////////////////////
63 // Function: EggCharacterFilter::post_command_line
64 // Access: Protected, Virtual
65 // Description:
66 ////////////////////////////////////////////////////////////////////
67 bool EggCharacterFilter::
68 post_command_line() {
69  if (_collection == (EggCharacterCollection *)NULL) {
70  _collection = make_collection();
71  }
72 
73  if (!EggMultiFilter::post_command_line()) {
74  return false;
75  }
76 
77  Eggs::iterator ei;
78  for (ei = _eggs.begin(); ei != _eggs.end(); ++ei) {
79  EggData *data = (*ei);
80 
81  if (_collection->add_egg(data) < 0) {
82  nout << data->get_egg_filename().get_basename()
83  << " does not contain a character model or animation channel.\n";
84  return false;
85  }
86  }
87 
88  _collection->check_errors(nout, _force_initial_rest_frame);
89 
90  return true;
91 }
92 
93 ////////////////////////////////////////////////////////////////////
94 // Function: EggCharacterFilter::write_eggs
95 // Access: Protected, Virtual
96 // Description: Writes out all of the egg files in the _eggs vector,
97 // to the output directory if one is specified, or over
98 // the input files if -inplace was specified.
99 ////////////////////////////////////////////////////////////////////
100 void EggCharacterFilter::
101 write_eggs() {
102  // Optimize (that is, collapse redudant nodes) in all of the
103  // characters' joint tables before writing them out.
104  int num_characters = _collection->get_num_characters();
105  for (int i = 0; i < num_characters; i++) {
106  EggCharacterData *char_data = _collection->get_character(i);
107  char_data->get_root_joint()->optimize();
108  }
109 
110  EggMultiFilter::write_eggs();
111 }
112 
113 ////////////////////////////////////////////////////////////////////
114 // Function: EggCharacterFilter::make_collection
115 // Access: Protected, Virtual
116 // Description: Allocates and returns a new EggCharacterCollection
117 // structure. This is primarily intended as a hook so
118 // derived classes can customize the type of
119 // EggCharacterCollection object used to represent the
120 // character information.
121 ////////////////////////////////////////////////////////////////////
122 EggCharacterCollection *EggCharacterFilter::
123 make_collection() {
124  return new EggCharacterCollection;
125 }
void optimize()
Calls optimize() on all models, and recursively on all joints at this node and below.
int add_egg(EggData *egg)
Adds a new egg file to the list of models and animation files for this particular character...
This is the primary interface into all the egg data, and the root of the egg file structure...
Definition: eggData.h:41
This is a base class for a program that reads in a number of egg files, operates on them...
EggJointData * get_root_joint() const
Returns the root joint of the character hierarchy.
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...
EggCharacterData * get_character(int i) const
Returns the ith character in the collection.
string get_basename() const
Returns the basename part of the filename.
Definition: filename.I:436
const Filename & get_egg_filename() const
Returns the directory in which the egg file is considered to reside.
Definition: eggData.I:135
void check_errors(ostream &out, bool force_initial_rest_frame)
Can be called after the collection has been completely filled up with egg files to output any message...
int get_num_characters() const
Returns the number of separate Characters that have been discovered in the various egg files added to...