Browse Source

refine mayaloader

David Rose 22 years ago
parent
commit
31c734468d

+ 14 - 0
pandatool/src/converter/somethingToEggConverter.cxx

@@ -102,6 +102,20 @@ get_additional_extensions() const {
   return string();
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: SomethingToEggConverter::get_input_units
+//       Access: Public, Virtual
+//  Description: This may be called after convert_file() has been
+//               called and returned true, indicating a successful
+//               conversion.  It will return the distance units
+//               represented by the converted egg file, if known, or
+//               DU_invalid if not known.
+////////////////////////////////////////////////////////////////////
+DistanceUnit SomethingToEggConverter::
+get_input_units() {
+  return DU_invalid;
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: SomethingToEggConverter::handle_external_reference
 //       Access: Public

+ 2 - 0
pandatool/src/converter/somethingToEggConverter.h

@@ -26,6 +26,7 @@
 #include "animationConvert.h"
 #include "pathReplace.h"
 #include "pointerTo.h"
+#include "distanceUnit.h"
 
 class EggData;
 class EggGroupNode;
@@ -104,6 +105,7 @@ public:
   virtual string get_additional_extensions() const;
 
   virtual bool convert_file(const Filename &filename)=0;
+  virtual DistanceUnit get_input_units();
 
   bool handle_external_reference(EggGroupNode *egg_parent,
                                  const Filename &ref_filename);

+ 18 - 0
pandatool/src/fltegg/fltToEggConverter.cxx

@@ -49,6 +49,7 @@
 FltToEggConverter::
 FltToEggConverter() {
   _compose_transforms = false;
+  _flt_units = DU_invalid;
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -130,9 +131,26 @@ convert_file(const Filename &filename) {
   }
 
   header->check_version();
+
+  _flt_units = header->get_units();
+
   return convert_flt(header);
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: FltToEggConverter::get_input_units
+//       Access: Public, Virtual
+//  Description: This may be called after convert_file() has been
+//               called and returned true, indicating a successful
+//               conversion.  It will return the distance units
+//               represented by the converted egg file, if known, or
+//               DU_invalid if not known.
+////////////////////////////////////////////////////////////////////
+DistanceUnit FltToEggConverter::
+get_input_units() {
+  return _flt_units;
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: FltToEggConverter::convert_flt
 //       Access: Public

+ 3 - 0
pandatool/src/fltegg/fltToEggConverter.h

@@ -30,6 +30,7 @@
 #include "pt_EggTexture.h"
 #include "pt_EggVertex.h"
 #include "pointerTo.h"
+#include "distanceUnit.h"
 
 class FltRecord;
 class FltLOD;
@@ -64,6 +65,7 @@ public:
   virtual string get_extension() const;
 
   virtual bool convert_file(const Filename &filename);
+  virtual DistanceUnit get_input_units();
   bool convert_flt(const FltHeader *flt_header);
 
   // Set this true to store transforms in egg files as the fully
@@ -102,6 +104,7 @@ private:
   PT_EggTexture make_egg_texture(const FltTexture *flt_texture);
 
   CPT(FltHeader) _flt_header;
+  DistanceUnit _flt_units;
 
   PT(EggVertexPool) _main_egg_vpool;
 

+ 4 - 4
pandatool/src/fltprogs/fltToEgg.cxx

@@ -81,10 +81,6 @@ run() {
 
   _data.set_coordinate_system(_coordinate_system);
 
-  if (_input_units == DU_invalid) {
-    _input_units = header->get_units();
-  }
-
   FltToEggConverter converter;
   converter.set_merge_externals(_merge_externals);
   converter.set_egg_data(&_data, false);
@@ -98,6 +94,10 @@ run() {
     exit(1);
   }
 
+  if (_input_units == DU_invalid) {
+    _input_units = converter.get_input_units();
+  }
+
   write_egg_file();
   nout << "\n";
 }

+ 14 - 0
pandatool/src/mayaegg/mayaToEggConverter.cxx

@@ -194,6 +194,20 @@ convert_file(const Filename &filename) {
   return convert_maya(false);
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: MayaToEggConverter::get_input_units
+//       Access: Public, Virtual
+//  Description: This may be called after convert_file() has been
+//               called and returned true, indicating a successful
+//               conversion.  It will return the distance units
+//               represented by the converted egg file, if known, or
+//               DU_invalid if not known.
+////////////////////////////////////////////////////////////////////
+DistanceUnit MayaToEggConverter::
+get_input_units() {
+  _maya->get_units();
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: MayaToEggConverter::convert_maya
 //       Access: Public

+ 1 - 0
pandatool/src/mayaegg/mayaToEggConverter.h

@@ -73,6 +73,7 @@ public:
   virtual string get_additional_extensions() const;
 
   virtual bool convert_file(const Filename &filename);
+  virtual DistanceUnit get_input_units();
   bool convert_maya(bool from_selection);
 
   bool open_api();

+ 1 - 2
pandatool/src/mayaprogs/Sources.pp

@@ -105,8 +105,7 @@
     egg2pg:c builder:c egg:c pandaegg:m \
     mathutil:c linmath:c putil:c panda:m \
     express:c pandaexpress:m \
-    dtoolconfig dtool \
-    $[if $[UNIX_PLATFORM],OpenMayalib]
+    dtoolconfig dtool
 
   #define SOURCES \
     config_mayaloader.cxx

+ 58 - 0
pandatool/src/mayaprogs/config_mayaloader.cxx

@@ -0,0 +1,58 @@
+// Filename: config_mayaloader.cxx
+// Created by:  drose (09Oct03)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
+//
+// All use of this software is subject to the terms of the Panda 3d
+// Software license.  You should have received a copy of this license
+// along with this source code; you will also find a current copy of
+// the license at http://www.panda3d.org/license.txt .
+//
+// To contact the maintainers of this program write to
+// [email protected] .
+//
+////////////////////////////////////////////////////////////////////
+
+#include "pandatoolbase.h"
+#include "loaderFileTypePandatool.h"
+#include "config_mayaegg.h"
+#include "mayaToEggConverter.h"
+
+#include "dconfig.h"
+#include "loaderFileTypeRegistry.h"
+
+Configure(config_mayaloader);
+
+void EXPCL_MISC init_libmayaloader();
+
+ConfigureFn(config_mayaloader) {
+  init_libmayaloader();
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: init_libmayaloader
+//  Description: Initializes the library.  This must be called at
+//               least once before any of the functions or classes in
+//               this library can be used.  Normally it will be
+//               called by the static initializers and need not be
+//               called explicitly, but special cases exist.
+////////////////////////////////////////////////////////////////////
+void
+init_libmayaloader() {
+  static bool initialized = false;
+  if (initialized) {
+    return;
+  }
+  initialized = true;
+
+  LoaderFileTypePandatool::init_type();
+
+  LoaderFileTypeRegistry *reg = LoaderFileTypeRegistry::get_ptr();
+
+  init_libmayaegg();
+  MayaToEggConverter *maya = new MayaToEggConverter;
+  reg->register_type(new LoaderFileTypePandatool(maya));
+}

+ 8 - 8
pandatool/src/mayaprogs/mayaToEgg.cxx

@@ -131,14 +131,6 @@ run() {
   }
   _data.set_coordinate_system(_coordinate_system);
 
-  // Use the standard Maya units, if the user didn't specify
-  // otherwise.  This always returns centimeters, which is the way all
-  // Maya files are stored internally (and is the units returned by
-  // all of the API functions called here).
-  if (_input_units == DU_invalid) {
-    _input_units = converter._maya->get_units();
-  }
-
   converter.set_egg_data(&_data, false);
   apply_parameters(converter);
 
@@ -147,6 +139,14 @@ run() {
     exit(1);
   }
 
+  // Use the standard Maya units, if the user didn't specify
+  // otherwise.  This always returns centimeters, which is the way all
+  // Maya files are stored internally (and is the units returned by
+  // all of the API functions called here).
+  if (_input_units == DU_invalid) {
+    _input_units = converter.get_input_units();
+  }
+
   write_egg_file();
   nout << "\n";
 }

+ 11 - 14
pandatool/src/ptloader/config_ptloader.cxx

@@ -31,23 +31,19 @@
 #endif
 */
 
-/*
-#ifdef HAVE_MAYA
-#include "config_mayaegg.h"
-#include "mayaToEggConverter.h"
-#endif
-*/
-
 #include "dconfig.h"
 #include "loaderFileTypeRegistry.h"
 #include "eggData.h"
 
 ConfigureDef(config_ptloader);
+NotifyCategoryDef(ptloader, "");
 
 ConfigureFn(config_ptloader) {
   init_libptloader();
 }
 
+DistanceUnit ptloader_units = DU_invalid;
+
 ////////////////////////////////////////////////////////////////////
 //     Function: init_libptloader
 //  Description: Initializes the library.  This must be called at
@@ -84,11 +80,12 @@ init_libptloader() {
 #endif
   */
 
-  /*
-#ifdef HAVE_MAYA
-  init_libmayaegg();
-  MayaToEggConverter *maya = new MayaToEggConverter;
-  reg->register_type(new LoaderFileTypePandatool(maya));
-#endif
-  */
+  string units = config_ptloader.GetString("ptloader-units", "feet");
+  if (!units.empty()) {
+    ptloader_units = string_distance_unit(units);
+    if (ptloader_units == DU_invalid) {
+      ptloader_cat->warning()
+        << "Invalid ptloader-units: " << units << "\n";
+    }
+  }
 }

+ 4 - 0
pandatool/src/ptloader/config_ptloader.h

@@ -22,8 +22,12 @@
 #include "pandatoolbase.h"
 
 #include "dconfig.h"
+#include "distanceUnit.h"
 
 ConfigureDecl(config_ptloader, EXPCL_PTLOADER, EXPTP_PTLOADER);
+NotifyCategoryDecl(ptloader, EXPCL_PTLOADER, EXPTP_PTLOADER);
+
+extern DistanceUnit ptloader_units;
 
 extern EXPCL_PTLOADER void init_libptloader();
 

+ 13 - 1
pandatool/src/ptloader/loaderFileTypePandatool.cxx

@@ -17,7 +17,7 @@
 ////////////////////////////////////////////////////////////////////
 
 #include "loaderFileTypePandatool.h"
-
+#include "config_ptloader.h"
 #include "somethingToEggConverter.h"
 #include "config_util.h"
 #include "load_egg_file.h"
@@ -107,6 +107,18 @@ load_file(const Filename &path, bool) const {
   _converter->get_path_replace()->_path = file_path;
 
   if (_converter->convert_file(path)) {
+    DistanceUnit input_units = _converter->get_input_units();
+    if (input_units != DU_invalid && ptloader_units != DU_invalid && 
+        input_units != ptloader_units) {
+      // Convert the file to the units specified by the ptloader-units
+      // Configrc variable.
+      ptloader_cat.info()
+        << "Converting from " << format_long_unit(input_units)
+        << " to " << format_long_unit(ptloader_units) << "\n";
+      double scale = convert_units(input_units, ptloader_units);
+      egg_data.transform(LMatrix4d::scale_mat(scale));
+    }
+
     result = load_egg_data(egg_data);
   }
   _converter->clear_egg_data();