Panda3D
eggCharacterFilter.cxx
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 eggCharacterFilter.cxx
10  * @author drose
11  * @date 2001-02-23
12  */
13 
14 #include "eggCharacterFilter.h"
15 #include "eggCharacterCollection.h"
16 #include "eggCharacterData.h"
17 
18 
19 /**
20  *
21  */
22 EggCharacterFilter::
23 EggCharacterFilter() : EggMultiFilter(false) {
24  _collection = nullptr;
25 
26  _force_initial_rest_frame = false;
27 }
28 
29 /**
30  *
31  */
32 EggCharacterFilter::
33 ~EggCharacterFilter() {
34  if (_collection != nullptr) {
35  delete _collection;
36  }
37 }
38 
39 /**
40  *
41  */
42 void EggCharacterFilter::
43 add_fixrest_option() {
44  add_option
45  ("fixrest", "", 30,
46  "Specify this to force all the initial rest frames of the various "
47  "model files to the same value as the first model specified. This "
48  "is a fairly drastic way to repair models whose initial rest frame "
49  "values are completely bogus, but should not be performed when the "
50  "input models are correct.",
51  &EggCharacterFilter::dispatch_none, &_force_initial_rest_frame);
52 }
53 
54 
55 /**
56  *
57  */
58 bool EggCharacterFilter::
59 post_command_line() {
60  if (_collection == nullptr) {
61  _collection = make_collection();
62  }
63 
64  if (!EggMultiFilter::post_command_line()) {
65  return false;
66  }
67 
68  Eggs::iterator ei;
69  for (ei = _eggs.begin(); ei != _eggs.end(); ++ei) {
70  EggData *data = (*ei);
71 
72  if (_collection->add_egg(data) < 0) {
73  nout << data->get_egg_filename().get_basename()
74  << " does not contain a character model or animation channel.\n";
75  return false;
76  }
77  }
78 
79  _collection->check_errors(nout, _force_initial_rest_frame);
80 
81  return true;
82 }
83 
84 /**
85  * Writes out all of the egg files in the _eggs vector, to the output
86  * directory if one is specified, or over the input files if -inplace was
87  * specified.
88  */
89 void EggCharacterFilter::
90 write_eggs() {
91  // Optimize (that is, collapse redudant nodes) in all of the characters'
92  // joint tables before writing them out.
93  int num_characters = _collection->get_num_characters();
94  for (int i = 0; i < num_characters; i++) {
95  EggCharacterData *char_data = _collection->get_character(i);
96  char_data->get_root_joint()->optimize();
97  }
98 
99  EggMultiFilter::write_eggs();
100 }
101 
102 /**
103  * Allocates and returns a new EggCharacterCollection structure. This is
104  * primarily intended as a hook so derived classes can customize the type of
105  * EggCharacterCollection object used to represent the character information.
106  */
107 EggCharacterCollection *EggCharacterFilter::
108 make_collection() {
109  return new EggCharacterCollection;
110 }
EggCharacterCollection::get_num_characters
int get_num_characters() const
Returns the number of separate Characters that have been discovered in the various egg files added to...
Definition: eggCharacterCollection.I:65
eggCharacterCollection.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
EggCharacterCollection::get_character
EggCharacterData * get_character(int i) const
Returns the ith character in the collection.
Definition: eggCharacterCollection.I:73
EggCharacterData
Represents a single character, as read and collected from several models and animation files.
Definition: eggCharacterData.h:52
EggCharacterCollection::check_errors
void check_errors(std::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...
Definition: eggCharacterCollection.cxx:651
EggData
This is the primary interface into all the egg data, and the root of the egg file structure.
Definition: eggData.h:37
eggCharacterFilter.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
EggJointData::optimize
void optimize()
Calls optimize() on all models, and recursively on all joints at this node and below.
Definition: eggJointData.cxx:310
eggCharacterData.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
EggCharacterData::get_root_joint
EggJointData * get_root_joint() const
Returns the root joint of the character hierarchy.
Definition: eggCharacterData.I:71
EggCharacterCollection::add_egg
int add_egg(EggData *egg)
Adds a new egg file to the list of models and animation files for this particular character.
Definition: eggCharacterCollection.cxx:67
EggCharacterCollection
Represents a set of characters, as read and collected from possibly several model and/or animation eg...
Definition: eggCharacterCollection.h:32
EggMultiFilter
This is a base class for a program that reads in a number of egg files, operates on them,...
Definition: eggMultiFilter.h:26