00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "loaderFileTypePandatool.h"
00016 #include "config_ptloader.h"
00017 #include "somethingToEggConverter.h"
00018 #include "config_util.h"
00019 #include "load_egg_file.h"
00020 #include "eggData.h"
00021 #include "loaderOptions.h"
00022 #include "bamCacheRecord.h"
00023
00024 TypeHandle LoaderFileTypePandatool::_type_handle;
00025
00026
00027
00028
00029
00030
00031 LoaderFileTypePandatool::
00032 LoaderFileTypePandatool(SomethingToEggConverter *converter) :
00033 _converter(converter)
00034 {
00035 converter->set_merge_externals(true);
00036 }
00037
00038
00039
00040
00041
00042
00043 LoaderFileTypePandatool::
00044 ~LoaderFileTypePandatool() {
00045 }
00046
00047
00048
00049
00050
00051
00052 string LoaderFileTypePandatool::
00053 get_name() const {
00054 return _converter->get_name();
00055 }
00056
00057
00058
00059
00060
00061
00062 string LoaderFileTypePandatool::
00063 get_extension() const {
00064 return _converter->get_extension();
00065 }
00066
00067
00068
00069
00070
00071
00072
00073
00074 string LoaderFileTypePandatool::
00075 get_additional_extensions() const {
00076 return _converter->get_additional_extensions();
00077 }
00078
00079
00080
00081
00082
00083
00084
00085
00086 bool LoaderFileTypePandatool::
00087 supports_compressed() const {
00088 return _converter->supports_compressed();
00089 }
00090
00091
00092
00093
00094
00095
00096
00097
00098 void LoaderFileTypePandatool::
00099 resolve_filename(Filename &path) const {
00100 path.resolve_filename(get_model_path(), get_extension());
00101 }
00102
00103
00104
00105
00106
00107
00108 PT(PandaNode) LoaderFileTypePandatool::
00109 load_file(const Filename &path, const LoaderOptions &options,
00110 BamCacheRecord *record) const {
00111 if (record != (BamCacheRecord *)NULL) {
00112 record->add_dependent_file(path);
00113 }
00114
00115 PT(PandaNode) result;
00116
00117 PT(EggData) egg_data = new EggData;
00118 _converter->set_egg_data(egg_data);
00119
00120 DSearchPath file_path;
00121 file_path.append_directory(path.get_dirname());
00122 _converter->get_path_replace()->_path = file_path;
00123
00124
00125 switch (options.get_flags() & LoaderOptions::LF_convert_anim) {
00126 case LoaderOptions::LF_convert_anim:
00127 _converter->set_animation_convert(AC_both);
00128 break;
00129
00130 case LoaderOptions::LF_convert_skeleton:
00131 _converter->set_animation_convert(AC_model);
00132 break;
00133
00134 case LoaderOptions::LF_convert_channels:
00135 _converter->set_animation_convert(AC_chan);
00136 break;
00137
00138 default:
00139 break;
00140 }
00141
00142 if (_converter->convert_file(path)) {
00143 DistanceUnit input_units = _converter->get_input_units();
00144 if (input_units != DU_invalid && ptloader_units != DU_invalid &&
00145 input_units != ptloader_units) {
00146
00147
00148 ptloader_cat.info()
00149 << "Converting from " << format_long_unit(input_units)
00150 << " to " << format_long_unit(ptloader_units) << "\n";
00151 double scale = convert_units(input_units, ptloader_units);
00152 egg_data->transform(LMatrix4d::scale_mat(scale));
00153 }
00154
00155 if (!egg_data->has_primitives()) {
00156 egg_data->make_point_primitives();
00157 } else if (!egg_data->has_normals()) {
00158 egg_data->recompute_polygon_normals();
00159 }
00160
00161 result = load_egg_data(egg_data);
00162 }
00163 _converter->clear_egg_data();
00164 return result.p();
00165 }