Selaa lähdekoodia

Added proper unit conversion for egg2maya

Gyedo Jeon 17 vuotta sitten
vanhempi
sitoutus
b52227d615

+ 11 - 0
pandatool/src/eggbase/eggToSomething.cxx

@@ -118,6 +118,16 @@ add_units_options() {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void EggToSomething::
 void EggToSomething::
 apply_units_scale(EggData *data) {
 apply_units_scale(EggData *data) {
+
+  // [gjeon] since maya's internal unit is fixed to cm
+  // and when we can't change UI unit without affecting data
+  // we need to convert data to cm for now
+  // this will be set later to proper output unit user provided
+  // by using MayaApi::set_units() in eggToMaya.cxx
+  DistanceUnit output_units = _output_units;
+  if (_format_name == "Maya")
+    _output_units = DU_centimeters;
+
   if (_output_units != DU_invalid && _input_units != DU_invalid &&
   if (_output_units != DU_invalid && _input_units != DU_invalid &&
       _input_units != _output_units) {
       _input_units != _output_units) {
     nout << "Converting from " << format_long_unit(_input_units)
     nout << "Converting from " << format_long_unit(_input_units)
@@ -125,6 +135,7 @@ apply_units_scale(EggData *data) {
     double scale = convert_units(_input_units, _output_units);
     double scale = convert_units(_input_units, _output_units);
     data->transform(LMatrix4d::scale_mat(scale));
     data->transform(LMatrix4d::scale_mat(scale));
   }
   }
+  _output_units = output_units;
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////

+ 38 - 0
pandatool/src/maya/mayaApi.cxx

@@ -379,6 +379,44 @@ get_units() {
   }
   }
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: MayaApi::set_units
+//       Access: Public
+//  Description: Set Maya's UI units.
+////////////////////////////////////////////////////////////////////
+void MayaApi::
+set_units(DistanceUnit unit) {
+  switch (unit) {
+  case DU_inches:
+    MDistance::setUIUnit(MDistance::kInches);
+    break;
+  case DU_feet:
+    MDistance::setUIUnit(MDistance::kFeet);
+    break;
+  case DU_yards:
+    MDistance::setUIUnit(MDistance::kYards);
+    break;
+  case DU_statute_miles:
+    MDistance::setUIUnit(MDistance::kMiles);
+    break;
+  case DU_millimeters:
+    MDistance::setUIUnit(MDistance::kMillimeters);
+    break;
+  case DU_centimeters:
+    MDistance::setUIUnit(MDistance::kCentimeters);
+    break;
+  case DU_kilometers:
+    MDistance::setUIUnit(MDistance::kKilometers);
+    break;
+  case DU_meters:
+    MDistance::setUIUnit(MDistance::kMeters);
+    break;
+
+  default:
+    ;
+  }
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: MayaApi::get_coordinate_system
 //     Function: MayaApi::get_coordinate_system
 //       Access: Public
 //       Access: Public

+ 1 - 0
pandatool/src/maya/mayaApi.h

@@ -47,6 +47,7 @@ public:
   bool clear();
   bool clear();
 
 
   DistanceUnit get_units();
   DistanceUnit get_units();
+  void set_units(DistanceUnit unit);
   CoordinateSystem get_coordinate_system();
   CoordinateSystem get_coordinate_system();
 
 
 private:
 private:

+ 12 - 0
pandatool/src/mayaprogs/eggToMaya.cxx

@@ -95,6 +95,18 @@ run() {
     exit(1);
     exit(1);
   }
   }
 
 
+  // [gjeon] since maya's internal unit is fixed to cm
+  // and when we can't change UI unit without affecting data
+  // all distance data is converted to cm
+  // we need to convert them back to proper output unit user provided here
+  // along with UI unit
+  maya->set_units(_output_units);
+
+  if (_output_units != DU_centimeters && _output_units != DU_invalid) {
+    nout << "Converting from centimeters"
+         << " to " << format_long_unit(_output_units) << "\n";
+  }
+
   // Now convert the data.
   // Now convert the data.
   if (!MayaLoadEggData(_data, true, _convert_model, _convert_anim, _respect_normals)) {
   if (!MayaLoadEggData(_data, true, _convert_model, _convert_anim, _respect_normals)) {
     nout << "Unable to convert egg file.\n";
     nout << "Unable to convert egg file.\n";