diff --git a/pandatool/src/eggbase/eggToSomething.cxx b/pandatool/src/eggbase/eggToSomething.cxx index b4d3587532..e9003af537 100644 --- a/pandatool/src/eggbase/eggToSomething.cxx +++ b/pandatool/src/eggbase/eggToSomething.cxx @@ -118,6 +118,16 @@ add_units_options() { //////////////////////////////////////////////////////////////////// void EggToSomething:: 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 && _input_units != _output_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); data->transform(LMatrix4d::scale_mat(scale)); } + _output_units = output_units; } //////////////////////////////////////////////////////////////////// diff --git a/pandatool/src/maya/mayaApi.cxx b/pandatool/src/maya/mayaApi.cxx index 6123a70168..9fc7a18880 100644 --- a/pandatool/src/maya/mayaApi.cxx +++ b/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 // Access: Public diff --git a/pandatool/src/maya/mayaApi.h b/pandatool/src/maya/mayaApi.h index 58cde1c5ee..601ca970e7 100644 --- a/pandatool/src/maya/mayaApi.h +++ b/pandatool/src/maya/mayaApi.h @@ -47,6 +47,7 @@ public: bool clear(); DistanceUnit get_units(); + void set_units(DistanceUnit unit); CoordinateSystem get_coordinate_system(); private: diff --git a/pandatool/src/mayaprogs/eggToMaya.cxx b/pandatool/src/mayaprogs/eggToMaya.cxx index 393129f831..a91be286e3 100755 --- a/pandatool/src/mayaprogs/eggToMaya.cxx +++ b/pandatool/src/mayaprogs/eggToMaya.cxx @@ -95,6 +95,18 @@ run() { 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. if (!MayaLoadEggData(_data, true, _convert_model, _convert_anim, _respect_normals)) { nout << "Unable to convert egg file.\n";