36 XFileToEggConverter() {
39 _x_file =
new XFile(
true);
49 _make_char(copy._make_char)
51 _x_file =
new XFile(
true);
59 ~XFileToEggConverter() {
110 if (!_x_file->read(filename)) {
111 nout <<
"Unable to open X file: " << filename <<
"\n";
115 if (_char_name.empty()) {
119 if (_egg_data->get_coordinate_system() == CS_default) {
120 _egg_data->set_coordinate_system(CS_yup_left);
123 if (!get_toplevel()) {
127 if (!create_polygons()) {
137 if (!create_hierarchy()) {
141 if (_keep_model && !_keep_animation) {
145 if (_keep_animation && !_keep_model) {
160 Meshes::const_iterator mi;
161 for (mi = _meshes.begin(); mi != _meshes.end(); ++mi) {
166 AnimationSets::const_iterator asi;
167 for (asi = _animation_sets.begin(); asi != _animation_sets.end(); ++asi) {
170 _animation_sets.clear();
182 EggGroupNode::iterator i;
183 for (i=_egg_data->begin(); i!=_egg_data->end(); ++i) {
186 garbage.push_back(node);
189 for (
int n=0; n<(int)garbage.size(); n++) {
190 _egg_data->remove_child(garbage[n]);
229 ji = _joints.find(joint_name);
230 if (ji != _joints.end()) {
232 if (joint ==
nullptr) {
244 <<
"Joint name " << joint_name <<
" in animation data is undefined.\n";
246 _joints[joint_name] =
nullptr;
255 bool XFileToEggConverter::
257 int num_objects = _x_file->get_num_objects();
260 _ticks_per_second = 4800;
265 _any_animation =
false;
266 for (i = 0; i < num_objects; i++) {
271 _any_animation =
true;
276 if (_any_animation) {
285 _dart_node =
new EggGroup(_char_name);
287 _dart_node->set_dart_type(EggGroup::DT_default);
288 egg_parent = _dart_node;
292 for (i = 0; i < num_objects; i++) {
293 if (!convert_toplevel_object(_x_file->get_object(i), egg_parent)) {
305 bool XFileToEggConverter::
315 if (!convert_frame(obj, egg_parent)) {
320 if (!convert_animation_set(obj)) {
325 _ticks_per_second = (*obj)[0].i();
334 if (!convert_mesh(obj, egg_parent)) {
340 if (xfile_cat.is_debug()) {
342 <<
"Ignoring toplevel object of unknown type: "
353 bool XFileToEggConverter::
359 if (!convert_frame(obj, egg_parent)) {
364 if (!convert_transform(obj, egg_parent)) {
369 if (!convert_mesh(obj, egg_parent)) {
374 if (xfile_cat.is_debug()) {
376 <<
"Ignoring object of unknown type: "
387 bool XFileToEggConverter::
390 string name = obj->get_name();
395 group->set_group_type(EggGroup::GT_joint);
398 group->set_name(
"unnamed");
401 bool inserted = _joints.insert(Joints::value_type(name, group)).second;
404 <<
"Nonunique Frame name " << name
405 <<
" encountered; animation will be ambiguous.\n";
412 for (
int i = 0; i < num_objects; i++) {
413 if (!convert_object(obj->
get_object(i), group)) {
426 bool XFileToEggConverter::
428 LMatrix4d mat = (*obj)[
"frameMatrix"][
"matrix"].mat4();
430 if (egg_parent->
is_of_type(EggGroup::get_class_type())) {
436 <<
"Transform " << obj->get_name()
437 <<
" encountered without frame!\n";
447 bool XFileToEggConverter::
450 animation_set->set_name(obj->get_name());
452 _total_tick_deltas = 0;
458 for (
int i = 0; i < num_objects; i++) {
459 if (!convert_animation_set_object(obj->
get_object(i), *animation_set)) {
464 animation_set->_frame_rate = _frame_rate;
465 if (_num_ticks != 0 && _frame_rate == 0.0) {
467 double delta = (double)_total_tick_deltas / (
double)_num_ticks;
469 animation_set->_frame_rate = (double)_ticks_per_second / delta;
473 _animation_sets.push_back(animation_set);
481 bool XFileToEggConverter::
485 if (!convert_animation(obj, animation_set)) {
490 if (xfile_cat.is_debug()) {
492 <<
"Ignoring animation set object of unknown type: "
503 bool XFileToEggConverter::
513 bool got_frame_name =
false;
517 for (i = 0; i < num_objects; i++) {
520 frame_name = child->get_name();
521 got_frame_name =
true;
525 if (!got_frame_name) {
527 <<
"Animation " << obj->get_name()
528 <<
" includes no reference to a frame.\n";
535 for (i = 0; i < num_objects; i++) {
536 if (!convert_animation_object(obj->
get_object(i), frame_name, table)) {
547 bool XFileToEggConverter::
548 convert_animation_object(
XFileDataNode *obj,
const string &joint_name,
557 if (!convert_animation_key(obj, joint_name, table)) {
562 if (xfile_cat.is_debug()) {
564 <<
"Ignoring animation object of unknown type: "
575 bool XFileToEggConverter::
576 convert_animation_key(
XFileDataNode *obj,
const string &joint_name,
578 int key_type = (*obj)[
"keyType"].i();
583 for (
int i = 0; i < keys.
size(); i++) {
591 int this_time = keys[i][
"time"].
i();
593 int delta = this_time - last_time;
594 _total_tick_deltas += delta;
597 last_time = this_time;
600 if (!set_animation_frame(joint_name, table, i, key_type, values)) {
611 bool XFileToEggConverter::
612 set_animation_frame(
const string &joint_name,
615 if ((
int)table._entries.size() <= frame) {
616 nassertr((
int)table._entries.size() == frame,
false);
627 if (values.
size() != 4) {
629 <<
"Incorrect number of values in animation table: "
630 << values.
size() <<
" for rotation data.\n";
633 frame_entry._rot.invert_from(LQuaterniond(values.
vec4()));
634 table._flags |= XFileAnimationSet::FDF_rot;
638 if (values.
size() != 3) {
640 <<
"Incorrect number of values in animation table: "
641 << values.
size() <<
" for scale data.\n";
644 frame_entry._scale = values.
vec3();
645 table._flags |= XFileAnimationSet::FDF_scale;
650 if (values.
size() != 3) {
652 <<
"Incorrect number of values in animation table: "
653 << values.
size() <<
" for position data.\n";
656 frame_entry._trans = values.
vec3();
657 table._flags |= XFileAnimationSet::FDF_trans;
668 if (values.
size() != 16) {
670 <<
"Incorrect number of values in animation table: "
671 << values.
size() <<
" for matrix data.\n";
674 frame_entry._mat = values.
mat4();
675 table._flags |= XFileAnimationSet::FDF_mat;
680 <<
"Unsupported key type " << key_type <<
" in animation table.\n";
690 bool XFileToEggConverter::
693 mesh->set_name(obj->get_name());
701 _meshes.push_back(mesh);
709 bool XFileToEggConverter::
713 Meshes::const_iterator mi;
714 for (mi = _meshes.begin(); mi != _meshes.end(); ++mi) {
715 if (!(*mi)->create_polygons(
this)) {
729 bool XFileToEggConverter::
733 AnimationSets::const_iterator asi;
734 for (asi = _animation_sets.begin(); asi != _animation_sets.end(); ++asi) {
736 if (!(*asi)->create_hierarchy(
this)) {
742 _animation_sets.clear();
A base class for nodes in the hierarchy that are not leaf nodes.
EggNode * add_child(EggNode *node)
Adds the indicated child to the group and returns it.
This is a specialization of EggNameUniquifier to generate unique names for EggGroup nodes.
The main glue of the egg hierarchy, this corresponds to the <Group>, <Instance>, and <Joint> type nod...
EggMaterial * create_unique_material(const EggMaterial ©, int eq)
Creates a new material if there is not already one equivalent (according to eq, see EggMaterial::is_e...
void uniquify(EggNode *node)
Begins the traversal from the indicated node.
A base class for things that may be directly added into the egg hierarchy.
EggTexture * create_unique_texture(const EggTexture ©, int eq)
Creates a new texture if there is not already one equivalent (according to eq, see EggTexture::is_equ...
Defines a texture map that may be applied to geometry.
The name of a file, such as a texture file or an Egg file.
std::string get_basename_wo_extension() const
Returns the basename part of the filename, without the file extension.
This is a base class for a family of converter classes that manage a conversion from some file type t...
bool had_error() const
Returns true if an error was detected during the conversion process (unless _allow_errors is true),...
void clear_error()
Resets the error flag to the no-error state.
TypeHandle is the identifier used to differentiate C++ class types.
bool is_of_type(TypeHandle handle) const
Returns true if the current object is or derives from the indicated type.
This represents a tree of EggTables, corresponding to Animation entries in the X file.
FrameData & create_frame_data(const std::string &joint_name)
Returns a reference to a new FrameData table corresponding to the indicated joint.
This is an abstract base class for an XFileNode which is also an XFileDataObject.
const std::string & get_template_name() const
A convenience function to return the name of the template used to define this data object.
virtual bool is_standard_object(const std::string &template_name) const
Returns true if this node represents an instance of the standard template with the indicated name,...
The abstract base class for a number of different types of data elements that may be stored in the X ...
LMatrix4d mat4() const
Returns the object's representation as an LMatrix4d.
LVecBase4d vec4() const
Returns the object's representation as an LVecBase4d.
int i() const
Unambiguously returns the object's representation as an integer, or 0 if the object has no integer re...
int size() const
Returns the number of nested data objects within this object.
LVecBase3d vec3() const
Returns the object's representation as an LVecBase3d.
This is a collection of polygons; i.e.
bool fill_mesh(XFileDataNode *obj)
Fills the structure based on the raw data from the X file's Mesh object.
void set_egg_parent(EggGroupNode *egg_parent)
Specifies the egg node that will eventually be the parent of this mesh, when create_polygons() is lat...
int get_num_objects() const
Returns the list of child objects of this node.
virtual bool is_reference() const
Returns true if this node represents an indirect reference to an object defined previously in the fil...
XFileDataNode * get_object(int n) const
Returns the nth child object of this node.
virtual bool convert_file(const Filename &filename)
Handles the reading of the input file and converting it to egg.
virtual std::string get_extension() const
Returns the common extension of the file type this converter supports.
EggTexture * create_unique_texture(const EggTexture ©)
Returns an EggTexture pointer whose properties match that of the the given EggTexture,...
EggGroup * get_dart_node() const
Returns the root of the joint hierarchy, if _make_char is true, or NULL otherwise.
virtual std::string get_name() const
Returns the English name of the file type this converter supports.
void close()
Finalizes and closes the file previously opened via convert_file().
EggMaterial * create_unique_material(const EggMaterial ©)
Returns an EggMaterial pointer whose properties match that of the the given EggMaterial,...
virtual bool supports_compressed() const
Returns true if this file type can transparently load compressed files (with a .pz extension),...
virtual SomethingToEggConverter * make_copy()
Allocates and returns a new copy of the converter.
EggGroup * find_joint(const std::string &joint_name)
This is called by set_animation_frame, for the purposes of building the frame data for the animation–...
void strip_nodes(TypeHandle t)
Removes all groups of the given type.
This represents the complete contents of an X file (file.x) in memory.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.