| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
#ifndef __VCGLIB_EXPORTERU3D |
| 25 |
#define __VCGLIB_EXPORTERU3D |
| 26 |
|
| 27 |
#include <cstdlib> |
| 28 |
#include <string> |
| 29 |
#include <QDir> |
| 30 |
#include <QString> |
| 31 |
#include <QProcess> |
| 32 |
#include <vector> |
| 33 |
#include <QMessageBox> |
| 34 |
|
| 35 |
#include "export_idtf.h" |
| 36 |
#include<vcg/space/point3.h> |
| 37 |
|
| 38 |
namespace vcg { |
| 39 |
namespace tri { |
| 40 |
namespace io { |
| 41 |
namespace u3dparametersclasses |
| 42 |
{ |
| 43 |
struct IDTFConverterParameters |
| 44 |
{ |
| 45 |
const QString _converter_loc; |
| 46 |
const QString _input_file; |
| 47 |
const QString _output_file; |
| 48 |
int positionQuality; |
| 49 |
|
| 50 |
IDTFConverterParameters(const QString& converter_loc,const QString& input_file,const QString& output_file) |
| 51 |
:_converter_loc(converter_loc),_input_file(input_file),_output_file(output_file) |
| 52 |
{ |
| 53 |
} |
| 54 |
}; |
| 55 |
|
| 56 |
template<typename SaveMeshType> |
| 57 |
struct Movie15Parameters |
| 58 |
{ |
| 59 |
typedef typename SaveMeshType::ScalarType ScalarType; |
| 60 |
|
| 61 |
Movie15Parameters() |
| 62 |
{ |
| 63 |
_campar = NULL; |
| 64 |
} |
| 65 |
|
| 66 |
|
| 67 |
class CameraParameters |
| 68 |
{ |
| 69 |
public: |
| 70 |
CameraParameters() |
| 71 |
:_cam_fov_angle(0.0),_cam_roll_angle(0.0),_obj_to_cam_dir(vcg::Point3<ScalarType>(0.0,0.0,0.0)),_obj_to_cam_dist(0.0),_obj_bbox_diag(0.0),_obj_pos(vcg::Point3<ScalarType>(0.0,0.0,0.0)) |
| 72 |
{ |
| 73 |
|
| 74 |
} |
| 75 |
|
| 76 |
CameraParameters(const vcg::Point3<ScalarType>& mesh_center,const ScalarType mesh_bbox_diag) |
| 77 |
:_cam_fov_angle(0.0),_cam_roll_angle(0.0),_obj_to_cam_dir(vcg::Point3<ScalarType>(0.0,0.0,mesh_bbox_diag)),_obj_to_cam_dist(0.0),_obj_pos(mesh_center),_obj_bbox_diag(mesh_bbox_diag) |
| 78 |
{ |
| 79 |
|
| 80 |
} |
| 81 |
|
| 82 |
CameraParameters(const ScalarType cam_fov_angle,const ScalarType cam_roll_angle, |
| 83 |
const vcg::Point3<ScalarType>& obj_to_cam_dir,const ScalarType obj_to_cam_dist, |
| 84 |
const ScalarType obj_bbox_diag, |
| 85 |
const vcg::Point3<ScalarType>& obj_pos = vcg::Point3<ScalarType>(0.0,0.0,0.0)) |
| 86 |
:_cam_fov_angle(cam_fov_angle),_cam_roll_angle(cam_roll_angle),_obj_to_cam_dir(obj_to_cam_dir),_obj_to_cam_dist(obj_to_cam_dist),_obj_pos(obj_pos),_obj_bbox_diag(obj_bbox_diag) |
| 87 |
{ |
| 88 |
|
| 89 |
} |
| 90 |
|
| 91 |
ScalarType _cam_fov_angle; |
| 92 |
ScalarType _cam_roll_angle; |
| 93 |
vcg::Point3<ScalarType> _obj_to_cam_dir; |
| 94 |
ScalarType _obj_to_cam_dist; |
| 95 |
vcg::Point3<ScalarType> _obj_pos; |
| 96 |
ScalarType _obj_bbox_diag; |
| 97 |
|
| 98 |
}; |
| 99 |
CameraParameters* _campar; |
| 100 |
int positionQuality; |
| 101 |
}; |
| 102 |
} |
| 103 |
|
| 104 |
template<typename SaveMeshType> |
| 105 |
class ExporterU3D |
| 106 |
{ |
| 107 |
|
| 108 |
public: |
| 109 |
enum U3DError |
| 110 |
{ |
| 111 |
E_NOERROR, |
| 112 |
E_ABORTED_CONVERSION |
| 113 |
}; |
| 114 |
|
| 115 |
static const char *ErrorMsg(int error) |
| 116 |
{ |
| 117 |
static const char * dae_error_msg[] = |
| 118 |
{ |
| 119 |
"No errors", |
| 120 |
"Conversion Process From Idtf intermediate file to U3D format aborted" |
| 121 |
}; |
| 122 |
|
| 123 |
if(error>1 || error<0) return "Unknown error"; |
| 124 |
else return dae_error_msg[error]; |
| 125 |
}; |
| 126 |
|
| 127 |
static void substituteChar(QString& st,const QChar& ch_remove,const QString& sub) |
| 128 |
{ |
| 129 |
int ii = 0; |
| 130 |
while ((ii = st.indexOf(ch_remove,ii)) != -1) |
| 131 |
st = st.replace(ii,1,sub); |
| 132 |
} |
| 133 |
|
| 134 |
private: |
| 135 |
static int InvokeConverter(const u3dparametersclasses::IDTFConverterParameters& par) |
| 136 |
{ |
| 137 |
QProcess p; |
| 138 |
QString convstring = par._converter_loc; |
| 139 |
#if defined(Q_OS_WIN) |
| 140 |
convstring = "\""+convstring + "\" -en 1 -rzf 0 -pq "+QString::number(par.positionQuality)+" -input \"" + par._input_file + "\" -output \"" + par._output_file +"\""; |
| 141 |
#else |
| 142 |
QString mac_input=par._input_file; |
| 143 |
QString mac_output=par._output_file; |
| 144 |
|
| 145 |
|
| 146 |
convstring = convstring + " -en 1 -rzf 0 -pq "+ QString::number(par.positionQuality)+" -input \"" + mac_input + "\" -output \"" + mac_output +"\""; |
| 147 |
#endif |
| 148 |
|
| 149 |
qDebug("Starting converter %s", qPrintable(convstring)); |
| 150 |
p.setProcessChannelMode(QProcess::MergedChannels); |
| 151 |
p.start(convstring); |
| 152 |
|
| 153 |
bool t = p.waitForFinished(-1); |
| 154 |
if(!t) QMessageBox::warning(0, QString("Saving Error"), QString("Failed conversion executable '%1'").arg(convstring)); |
| 155 |
p.close(); |
| 156 |
return (int) t; |
| 157 |
} |
| 158 |
|
| 159 |
static void SaveLatex(SaveMeshType& ,const QString& file,const u3dparametersclasses::Movie15Parameters<SaveMeshType>& mov_par) |
| 160 |
{ |
| 161 |
Output_File latex(file.toStdString() + ".tex"); |
| 162 |
QString u3df = file + ".u3d"; |
| 163 |
QStringList file_trim; |
| 164 |
QtUtilityFunctions::splitFilePath(u3df,file_trim); |
| 165 |
std::string u3d_final = QtUtilityFunctions::fileNameFromTrimmedPath(file_trim).toStdString(); |
| 166 |
latex.write(0,"\\documentclass[a4paper]{article}"); |
| 167 |
latex.write(0,"\\usepackage[3D]{movie15}"); |
| 168 |
latex.write(0,"\\usepackage{hyperref}"); |
| 169 |
latex.write(0,"\\usepackage[UKenglish]{babel}"); |
| 170 |
latex.write(0,"\\begin{document}"); |
| 171 |
latex.write(0,"\\includemovie["); |
| 172 |
latex.write(1,"poster,"); |
| 173 |
latex.write(1,"toolbar, %same as `controls\'"); |
| 174 |
|
| 175 |
|
| 176 |
QString u3d_text = QString::fromStdString(u3d_final); |
| 177 |
substituteChar(u3d_text,QChar('_'),QString("")); |
| 178 |
latex.write(1,"label=" + u3d_text.toStdString() + ","); |
| 179 |
latex.write(1,"text=(" + u3d_text.toStdString() + "),"); |
| 180 |
std::string cam_string; |
| 181 |
typename u3dparametersclasses::Movie15Parameters<SaveMeshType>::CameraParameters* cam = mov_par._campar; |
| 182 |
if (cam != NULL) |
| 183 |
{ |
| 184 |
cam_string = cam_string + "3Daac=" + TextUtility::nmbToStr(cam->_cam_fov_angle) + |
| 185 |
", 3Droll=" + TextUtility::nmbToStr(cam->_cam_roll_angle) + |
| 186 |
", 3Dc2c=" + TextUtility::nmbToStr(cam->_obj_to_cam_dir.X()) + " " + TextUtility::nmbToStr(cam->_obj_to_cam_dir.Z()) + " " + TextUtility::nmbToStr(cam->_obj_to_cam_dir.Y()) + |
| 187 |
", 3Droo=" + TextUtility::nmbToStr(cam->_obj_to_cam_dist) + |
| 188 |
", 3Dcoo=" + TextUtility::nmbToStr(-cam->_obj_pos.X()) + " " + TextUtility::nmbToStr(cam->_obj_pos.Z()) + " " + TextUtility::nmbToStr(cam->_obj_pos.Y()) + ","; |
| 189 |
latex.write(1,cam_string); |
| 190 |
} |
| 191 |
latex.write(1,"3Dlights=CAD,"); |
| 192 |
latex.write(0,"]{\\linewidth}{\\linewidth}{" + u3d_final + "}"); |
| 193 |
latex.write(0,"\\end{document}"); |
| 194 |
} |
| 195 |
|
| 196 |
public: |
| 197 |
|
| 198 |
static int Save(SaveMeshType& m,const char* output_file,const char* conv_loc,const u3dparametersclasses::Movie15Parameters<SaveMeshType>& mov_par,const int mask) |
| 199 |
{ |
| 200 |
QString curr = QDir::currentPath(); |
| 201 |
QString out(output_file); |
| 202 |
QStringList out_trim; |
| 203 |
QtUtilityFunctions::splitFilePath(out,out_trim); |
| 204 |
QString tmp(QDir::tempPath()); |
| 205 |
|
| 206 |
|
| 207 |
tmp = tmp + "/" + QtUtilityFunctions::fileNameFromTrimmedPath(out_trim) + ".idtf"; |
| 208 |
|
| 209 |
QString conv_loc_st(conv_loc); |
| 210 |
QString output_file_st(output_file); |
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
vcg::tri::io::ExporterIDTF<SaveMeshType>::Save(m,qPrintable(tmp),mask); |
| 225 |
u3dparametersclasses::IDTFConverterParameters idtfpar(conv_loc_st,tmp,output_file_st); |
| 226 |
idtfpar.positionQuality = mov_par.positionQuality; |
| 227 |
qDebug("conv_loc_st '%s'", qPrintable(conv_loc_st)); |
| 228 |
qDebug("conv_loc '%s'", conv_loc); |
| 229 |
qDebug("idtfpar._converter_loc '%s'", qPrintable(idtfpar._converter_loc)); |
| 230 |
int res = InvokeConverter(idtfpar); |
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
QDir::setCurrent(curr); |
| 240 |
QString lat (output_file); |
| 241 |
QStringList l = lat.split("."); |
| 242 |
SaveLatex(m,l[0],mov_par); |
| 243 |
QDir dir(QDir::tempPath()); |
| 244 |
dir.remove(tmp); |
| 245 |
|
| 246 |
if (res) |
| 247 |
return 0; |
| 248 |
else |
| 249 |
return 1; |
| 250 |
} |
| 251 |
|
| 252 |
static int GetExportMaskCapability() |
| 253 |
{ |
| 254 |
int capability = 0; |
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
capability |= vcg::tri::io::Mask::IOM_VERTCOLOR; |
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
capability |= vcg::tri::io::Mask::IOM_FACECOLOR; |
| 263 |
|
| 264 |
|
| 265 |
capability |= Mask::IOM_WEDGTEXCOORD; |
| 266 |
|
| 267 |
|
| 268 |
return capability; |
| 269 |
} |
| 270 |
|
| 271 |
}; |
| 272 |
|
| 273 |
} |
| 274 |
} |
| 275 |
} |
| 276 |
|
| 277 |
#endif |