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