Browse Source

fix flt2egg transform order, add -C option

David Rose 23 years ago
parent
commit
06b40c1ff9

+ 1 - 1
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);
   }
 }

+ 4 - 2
pandatool/src/fltegg/fltToEggConverter.cxx

@@ -48,6 +48,7 @@
 ////////////////////////////////////////////////////////////////////
 FltToEggConverter::
 FltToEggConverter() {
+  _compose_transforms = false;
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -57,7 +58,8 @@ FltToEggConverter() {
 ////////////////////////////////////////////////////////////////////
 FltToEggConverter::
 FltToEggConverter(const FltToEggConverter &copy) :
-  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);
 

+ 5 - 0
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();
 

+ 6 - 2
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 &copy) :
   _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 &copy) {
   _flt_object = copy._flt_object;
   _egg_parent = copy._egg_parent;
+  _converter = copy._converter;
   // We don't bother to copy the _parents map.
 }

+ 5 - 5
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());

+ 5 - 2
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 &copy);
   INLINE void operator = (const FltToEggLevelState &copy);
   ~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<LMatrix4d, ParentNodes *> Parents;
   Parents _parents;
+
+  FltToEggConverter *_converter;
 };
 
 #include "fltToEggLevelState.I"

+ 8 - 0
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";

+ 2 - 0
pandatool/src/fltprogs/fltToEgg.h

@@ -36,6 +36,8 @@ public:
   FltToEgg();
 
   void run();
+
+  bool _compose_transforms;
 };
 
 #endif