From 06b40c1ff97bfb41ebd8d9656cd0ce28b1f7c019 Mon Sep 17 00:00:00 2001 From: David Rose Date: Tue, 25 Jun 2002 16:16:30 +0000 Subject: [PATCH] fix flt2egg transform order, add -C option --- pandatool/src/flt/fltTransformRotateAboutPoint.cxx | 2 +- pandatool/src/fltegg/fltToEggConverter.cxx | 6 ++++-- pandatool/src/fltegg/fltToEggConverter.h | 5 +++++ pandatool/src/fltegg/fltToEggLevelState.I | 8 ++++++-- pandatool/src/fltegg/fltToEggLevelState.cxx | 10 +++++----- pandatool/src/fltegg/fltToEggLevelState.h | 7 +++++-- pandatool/src/fltprogs/fltToEgg.cxx | 8 ++++++++ pandatool/src/fltprogs/fltToEgg.h | 2 ++ 8 files changed, 36 insertions(+), 12 deletions(-) diff --git a/pandatool/src/flt/fltTransformRotateAboutPoint.cxx b/pandatool/src/flt/fltTransformRotateAboutPoint.cxx index bdb582a315..76ade7327a 100644 --- a/pandatool/src/flt/fltTransformRotateAboutPoint.cxx +++ b/pandatool/src/flt/fltTransformRotateAboutPoint.cxx @@ -95,7 +95,7 @@ recompute_matrix() { _matrix = LMatrix4d::translate_mat(-_center) * - LMatrix4d::rotate_mat(_angle, normalize(axis), CS_zup_right) * + LMatrix4d::rotate_mat(_angle, axis, CS_zup_right) * LMatrix4d::translate_mat(_center); } } diff --git a/pandatool/src/fltegg/fltToEggConverter.cxx b/pandatool/src/fltegg/fltToEggConverter.cxx index 7e6887d6fb..ed28c26e1e 100644 --- a/pandatool/src/fltegg/fltToEggConverter.cxx +++ b/pandatool/src/fltegg/fltToEggConverter.cxx @@ -48,6 +48,7 @@ //////////////////////////////////////////////////////////////////// FltToEggConverter:: FltToEggConverter() { + _compose_transforms = false; } //////////////////////////////////////////////////////////////////// @@ -57,7 +58,8 @@ FltToEggConverter() { //////////////////////////////////////////////////////////////////// FltToEggConverter:: FltToEggConverter(const FltToEggConverter ©) : - SomethingToEggConverter(copy) + SomethingToEggConverter(copy), + _compose_transforms(copy._compose_transforms) { } @@ -156,7 +158,7 @@ convert_flt(const FltHeader *flt_header) { // they're assigned to (for instance, to apply a transparency or // something). - FltToEggLevelState state; + FltToEggLevelState state(this); state._egg_parent = _egg_data; convert_record(_flt_header, state); diff --git a/pandatool/src/fltegg/fltToEggConverter.h b/pandatool/src/fltegg/fltToEggConverter.h index 013a03424a..2bc0e6b2e4 100644 --- a/pandatool/src/fltegg/fltToEggConverter.h +++ b/pandatool/src/fltegg/fltToEggConverter.h @@ -67,6 +67,11 @@ public: virtual bool convert_file(const Filename &filename); bool convert_flt(const FltHeader *flt_header); + // Set this true to store transforms in egg files as the fully + // composed matrix, or false (the default) to keep them decomposed + // into elemental operations. + bool _compose_transforms; + private: void cleanup(); diff --git a/pandatool/src/fltegg/fltToEggLevelState.I b/pandatool/src/fltegg/fltToEggLevelState.I index d583ccd98b..e011e1809c 100644 --- a/pandatool/src/fltegg/fltToEggLevelState.I +++ b/pandatool/src/fltegg/fltToEggLevelState.I @@ -22,7 +22,9 @@ // Description: //////////////////////////////////////////////////////////////////// INLINE FltToEggLevelState:: -FltToEggLevelState() { +FltToEggLevelState(FltToEggConverter *converter) : + _converter(converter) +{ _flt_object = (FltObject *)NULL; _egg_parent = (EggGroupNode *)NULL; } @@ -35,7 +37,8 @@ FltToEggLevelState() { INLINE FltToEggLevelState:: FltToEggLevelState(const FltToEggLevelState ©) : _flt_object(copy._flt_object), - _egg_parent(copy._egg_parent) + _egg_parent(copy._egg_parent), + _converter(copy._converter) { // We don't bother to copy the _parents map. } @@ -49,5 +52,6 @@ INLINE void FltToEggLevelState:: operator = (const FltToEggLevelState ©) { _flt_object = copy._flt_object; _egg_parent = copy._egg_parent; + _converter = copy._converter; // We don't bother to copy the _parents map. } diff --git a/pandatool/src/fltegg/fltToEggLevelState.cxx b/pandatool/src/fltegg/fltToEggLevelState.cxx index 5f665c9e1b..92cf7bab3a 100644 --- a/pandatool/src/fltegg/fltToEggLevelState.cxx +++ b/pandatool/src/fltegg/fltToEggLevelState.cxx @@ -17,6 +17,7 @@ //////////////////////////////////////////////////////////////////// #include "fltToEggLevelState.h" +#include "fltToEggConverter.h" #include "fltTransformTranslate.h" #include "fltTransformRotateAboutPoint.h" #include "fltTransformRotateAboutEdge.h" @@ -134,7 +135,7 @@ get_synthetic_group(const string &name, //////////////////////////////////////////////////////////////////// // Function: FltToEggLevelState::set_transform -// Access: Public, Static +// Access: Public // Description: Sets up the group to reflect the transform indicated // by the given record, if any. //////////////////////////////////////////////////////////////////// @@ -144,7 +145,7 @@ set_transform(const FltBead *flt_bead, EggGroup *egg_group) { egg_group->set_group_type(EggGroup::GT_instance); int num_steps = flt_bead->get_num_transform_steps(); - bool componentwise_ok = true; + bool componentwise_ok = !_converter->_compose_transforms; if (num_steps == 0) { componentwise_ok = false; @@ -154,8 +155,7 @@ set_transform(const FltBead *flt_bead, EggGroup *egg_group) { // don't know how to interpret, just store the whole transform // matrix in the egg file. egg_group->clear_transform(); - - for (int i = 0; i < num_steps && componentwise_ok; i++) { + for (int i = num_steps -1; i >= 0 && componentwise_ok; i--) { const FltTransformRecord *step = flt_bead->get_transform_step(i); if (step->is_exact_type(FltTransformTranslate::get_class_type())) { const FltTransformTranslate *trans; @@ -166,7 +166,7 @@ set_transform(const FltBead *flt_bead, EggGroup *egg_group) { } else if (step->is_exact_type(FltTransformRotateAboutPoint::get_class_type())) { const FltTransformRotateAboutPoint *rap; - DCAST_INTO_V(rap, step); + DCAST_INTO_V(rap, step); if (!IS_NEARLY_ZERO(rap->get_angle())) { if (!rap->get_center().almost_equal(LVector3d::zero())) { egg_group->add_translate(-rap->get_center()); diff --git a/pandatool/src/fltegg/fltToEggLevelState.h b/pandatool/src/fltegg/fltToEggLevelState.h index 669801383b..da7742be0e 100644 --- a/pandatool/src/fltegg/fltToEggLevelState.h +++ b/pandatool/src/fltegg/fltToEggLevelState.h @@ -26,6 +26,7 @@ class FltObject; class FltBead; class EggGroupNode; class EggGroup; +class FltToEggConverter; //////////////////////////////////////////////////////////////////// // Class : FltToEggLevelState @@ -34,7 +35,7 @@ class EggGroup; //////////////////////////////////////////////////////////////////// class FltToEggLevelState { public: - INLINE FltToEggLevelState(); + INLINE FltToEggLevelState(FltToEggConverter *converter); INLINE FltToEggLevelState(const FltToEggLevelState ©); INLINE void operator = (const FltToEggLevelState ©); ~FltToEggLevelState(); @@ -43,7 +44,7 @@ public: const FltBead *transform_bead, FltGeometry::BillboardType type = FltGeometry::BT_none); - static void set_transform(const FltBead *flt_bead, EggGroup *egg_group); + void set_transform(const FltBead *flt_bead, EggGroup *egg_group); const FltObject *_flt_object; EggGroupNode *_egg_parent; @@ -60,6 +61,8 @@ private: typedef pmap Parents; Parents _parents; + + FltToEggConverter *_converter; }; #include "fltToEggLevelState.I" diff --git a/pandatool/src/fltprogs/fltToEgg.cxx b/pandatool/src/fltprogs/fltToEgg.cxx index 2ff34d876a..74a574a0f5 100644 --- a/pandatool/src/fltprogs/fltToEgg.cxx +++ b/pandatool/src/fltprogs/fltToEgg.cxx @@ -48,6 +48,13 @@ FltToEgg() : "Specify the coordinate system of the input " + _format_name + " file. Normally, this is z-up."); + add_option + ("C", "", 0, + "Compose node transforms into a single matrix before writing them to " + "the egg file, instead of writing them as individual scale, rotate, and " + "translate operations", + &FltToEgg::dispatch_none, &_compose_transforms); + _coordinate_system = CS_zup_right; } @@ -82,6 +89,7 @@ run() { converter.set_egg_data(&_data, false); converter.set_texture_path_convert(_texture_path_convert, _make_rel_dir); converter.set_model_path_convert(_model_path_convert, _make_rel_dir); + converter._compose_transforms = _compose_transforms; if (!converter.convert_flt(header)) { nout << "Errors in conversion.\n"; diff --git a/pandatool/src/fltprogs/fltToEgg.h b/pandatool/src/fltprogs/fltToEgg.h index 966d4b2e10..0763b833ca 100644 --- a/pandatool/src/fltprogs/fltToEgg.h +++ b/pandatool/src/fltprogs/fltToEgg.h @@ -36,6 +36,8 @@ public: FltToEgg(); void run(); + + bool _compose_transforms; }; #endif