diff --git a/src/Mod/Raytracing/App/AppRaytracingPy.cpp b/src/Mod/Raytracing/App/AppRaytracingPy.cpp index e759eb434..cee2f6659 100644 --- a/src/Mod/Raytracing/App/AppRaytracingPy.cpp +++ b/src/Mod/Raytracing/App/AppRaytracingPy.cpp @@ -238,19 +238,6 @@ copyResource(PyObject *self, PyObject *args) Py_Return; } -/// rescales a lux matrix -static PyObject * -scaleLuxMatrix(PyObject *self, PyObject *args) -{ - float factor; - const char *mat; - if (! PyArg_ParseTuple(args, "sf", &mat, &factor)) - return NULL; - std::string result, luxmatrix(mat); - result = LuxTools::rescaleMatrix(luxmatrix, factor); - return Py::new_reference_to(Py::String(result)); -} - /* registration table */ struct PyMethodDef Raytracing_methods[] = { {"writeProjectFile", writeProjectFile, 1}, @@ -262,6 +249,5 @@ struct PyMethodDef Raytracing_methods[] = { {"writeDataFile", writeDataFile , 1}, {"writeCameraFile", writeCameraFile , 1}, {"copyResource", copyResource , 1}, - {"scaleLuxMatrix", scaleLuxMatrix , 1}, {NULL, NULL} }; diff --git a/src/Mod/Raytracing/App/LuxFeature.cpp b/src/Mod/Raytracing/App/LuxFeature.cpp index 3a6d64bff..65c5804c6 100644 --- a/src/Mod/Raytracing/App/LuxFeature.cpp +++ b/src/Mod/Raytracing/App/LuxFeature.cpp @@ -31,7 +31,6 @@ #include #include -#include "PovTools.h" #include "LuxFeature.h" #include "LuxTools.h" diff --git a/src/Mod/Raytracing/App/LuxProject.cpp b/src/Mod/Raytracing/App/LuxProject.cpp index 2f057978a..589bfcf9f 100644 --- a/src/Mod/Raytracing/App/LuxProject.cpp +++ b/src/Mod/Raytracing/App/LuxProject.cpp @@ -32,6 +32,7 @@ #include #include "LuxProject.h" #include "LuxFeature.h" +#include "LuxTools.h" using namespace Raytracing; using namespace std; @@ -82,14 +83,17 @@ App::DocumentObjectExecReturn *LuxProject::execute(void) } } else { // get through the children and collect all the views + ofile << "# declares FreeCAD objects" << endl + << "# Generated by FreeCAD (http://www.freecadweb.org/)" << endl << endl; const std::vector &Grp = Group.getValues(); for (std::vector::const_iterator It= Grp.begin();It!=Grp.end();++It) { if ((*It)->getTypeId().isDerivedFrom(Raytracing::LuxFeature::getClassTypeId())) { Raytracing::LuxFeature *View = dynamic_cast(*It); ofile << View->Result.getValue(); - ofile << endl << endl << endl; + ofile << endl; } } + ofile << "# End of FreeCAD objects" << endl; } } @@ -103,5 +107,7 @@ App::DocumentObjectExecReturn *LuxProject::execute(void) short LuxProject::mustExecute() const { + if (Camera.isTouched()) + return 1; return 0; } diff --git a/src/Mod/Raytracing/App/LuxTools.cpp b/src/Mod/Raytracing/App/LuxTools.cpp index 861f0a8ba..409e36aca 100644 --- a/src/Mod/Raytracing/App/LuxTools.cpp +++ b/src/Mod/Raytracing/App/LuxTools.cpp @@ -80,7 +80,7 @@ void LuxTools::writeShape(std::ostream &out, const char *PartName, const TopoDS_ // write object out << "AttributeBegin # \"" << PartName << "\"" << endl; - out << "Transform [1.000000000000000 0.000000000000000 0.000000000000000 0.000000000000000 0.000000000000000 1.000000000000000 0.000000000000000 0.000000000000000 0.000000000000000 0.000000000000000 1.000000000000000 0.000000000000000 0.000000000000000 0.000000000000000 0.000000000000000 1.000000000000000]" << endl; + out << "Transform [1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1]" << endl; out << "NamedMaterial \"FreeCADMaterial_" << PartName << "\"" << endl; out << "Shape \"mesh\"" << endl; @@ -106,12 +106,12 @@ void LuxTools::writeShape(std::ostream &out, const char *PartName, const TopoDS_ if (!vertices) break; // writing vertices for (int i=0; i < nbNodesInFace; i++) { - P << vertices[i].X() << " " << vertices[i].Z() << " " << vertices[i].Y() << " "; + P << vertices[i].X() << " " << vertices[i].Y() << " " << vertices[i].Z() << " "; } // writing per vertex normals for (int j=0; j < nbNodesInFace; j++) { - N << vertexnormals[j].X() << " " << vertexnormals[j].Z() << " " << vertexnormals[j].Y() << " "; + N << vertexnormals[j].X() << " " << vertexnormals[j].Y() << " " << vertexnormals[j].Z() << " "; } // writing triangle indices @@ -137,19 +137,3 @@ void LuxTools::writeShape(std::ostream &out, const char *PartName, const TopoDS_ out << " \"string name\" [\"" << PartName << "\"]" << endl; out << "AttributeEnd # \"\"" << endl; } - -std::string LuxTools::rescaleMatrix(std::string mat, float factor) -{ - // clean the input string - std::string matstring = mat.substr(11); - unsigned pos = matstring.find("]"); - matstring = matstring.substr(0,pos); - // create a matrix and rescale it - Base::Matrix4D trans; - trans.fromString(matstring); - trans.scale(factor,factor,factor); - // create output - std::stringstream result; - result << "Transform [" << trans.toString() << "]" << endl; - return result.str(); -} diff --git a/src/Mod/Raytracing/App/LuxTools.h b/src/Mod/Raytracing/App/LuxTools.h index bde71398c..f299cd659 100644 --- a/src/Mod/Raytracing/App/LuxTools.h +++ b/src/Mod/Raytracing/App/LuxTools.h @@ -27,6 +27,8 @@ #include #include +#include "PovTools.h" + class TopoDS_Shape; class TopoDS_Face; @@ -42,8 +44,6 @@ namespace Raytracing static std::string getCamera(const CamDef& Cam); /// returns the given shape as luxrender material + shape data static void writeShape(std::ostream &out, const char *PartName, const TopoDS_Shape& Shape, float fMeshDeviation=0.1); - /// rescales a lux matrix by the given factor - static std::string rescaleMatrix(std::string mat, float factor); }; } // namespace Raytracing diff --git a/src/Mod/Raytracing/App/RayProject.cpp b/src/Mod/Raytracing/App/RayProject.cpp index d806160d2..7dc32a8a9 100644 --- a/src/Mod/Raytracing/App/RayProject.cpp +++ b/src/Mod/Raytracing/App/RayProject.cpp @@ -100,5 +100,7 @@ App::DocumentObjectExecReturn *RayProject::execute(void) short RayProject::mustExecute() const { + if (Camera.isTouched()) + return 1; return 0; } diff --git a/src/Mod/Raytracing/Gui/Command.cpp b/src/Mod/Raytracing/Gui/Command.cpp index 40a864b1e..81d2a9255 100644 --- a/src/Mod/Raytracing/Gui/Command.cpp +++ b/src/Mod/Raytracing/Gui/Command.cpp @@ -495,10 +495,9 @@ DEF_STD_CMD_A(CmdRaytracingRender); CmdRaytracingRender::CmdRaytracingRender() : Command("Raytracing_Render") { - // seting the sGroup = QT_TR_NOOP("File"); sMenuText = QT_TR_NOOP("&Render"); - sToolTipText = QT_TR_NOOP("Renders the current raytracing project with povray"); + sToolTipText = QT_TR_NOOP("Renders the current raytracing project with an external renderer"); sWhatsThis = "Raytracing_Render"; sStatusTip = sToolTipText; sPixmap = "Raytrace_Render"; @@ -506,53 +505,94 @@ CmdRaytracingRender::CmdRaytracingRender() void CmdRaytracingRender::activated(int iMsg) { - unsigned int n = getSelection().countObjectsOfType(Raytracing::RayProject::getClassTypeId()); - if (n != 1) { - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), - QObject::tr("Select one Povray project object.")); - return; - } - ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Raytracing"); - std::string povray = hGrp->GetASCII("PovrayExecutable", ""); - if (povray == "") { - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Povray not found"), - QObject::tr("Please set the path to the povray executable in the preferences.")); - return; - } else { - QFileInfo fi(QString::fromUtf8(povray.c_str())); - if (!fi.exists() || !fi.isFile()) { - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Povray not found"), - QObject::tr("Please correct the path to the povray executable in the preferences.")); + // determining render type + const char* renderType; + unsigned int n1 = getSelection().countObjectsOfType(Raytracing::RayProject::getClassTypeId()); + if (n1 != 1) { + unsigned int n2 = getSelection().countObjectsOfType(Raytracing::LuxProject::getClassTypeId()); + if (n2 != 1) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), + QObject::tr("Select one Raytracing project object.")); return; + } else { + renderType = "luxrender"; + } + } else { + renderType = "povray"; + } + + // checking if renderer is present + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Raytracing"); + std::string renderer; + if (renderType == "povray") { + renderer = hGrp->GetASCII("PovrayExecutable", ""); + if (renderer == "") { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Povray not found"), + QObject::tr("Please set the path to the povray executable in the preferences.")); + return; + } else { + QFileInfo fi(QString::fromUtf8(renderer.c_str())); + if (!fi.exists() || !fi.isFile()) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Povray not found"), + QObject::tr("Please correct the path to the povray executable in the preferences.")); + return; + } + } + } else { + renderer = hGrp->GetASCII("LuxrenderExecutable", ""); + if (renderer == "") { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Luxrender not found"), + QObject::tr("Please set the path to the luxrender or luxconsole executable in the preferences.")); + return; + } else { + QFileInfo fi(QString::fromUtf8(renderer.c_str())); + if (!fi.exists() || !fi.isFile()) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Luxrender not found"), + QObject::tr("Please correct the path to the luxrender or luxconsole executable in the preferences.")); + return; + } } } - - QStringList filter; - filter << QObject::tr("Rendered image(*.png)"); - filter << QObject::tr("All Files (*.*)"); - - QString fn = Gui::FileDialog::getSaveFileName(Gui::getMainWindow(), QObject::tr("Rendered image"), QString(), filter.join(QLatin1String(";;"))); - if (!fn.isEmpty()) { - std::vector Sel = getSelection().getSelection(); - int width = hGrp->GetInt("OutputWidth", 800); - std::stringstream w; - w << width; - int height = hGrp->GetInt("OutputHeight", 600); - std::stringstream h; - h << height; - std::string par = hGrp->GetASCII("OutputParameters", "+P +A"); - std::string fname = (const char*)fn.toUtf8(); + + std::vector Sel = getSelection().getSelection(); + + if (renderType == "povray") { + QStringList filter; + filter << QObject::tr("Rendered image(*.png)"); + filter << QObject::tr("All Files (*.*)"); + QString fn = Gui::FileDialog::getSaveFileName(Gui::getMainWindow(), QObject::tr("Rendered image"), QString(), filter.join(QLatin1String(";;"))); + if (!fn.isEmpty()) { + std::string fname = (const char*)fn.toUtf8(); + openCommand("Render project"); + int width = hGrp->GetInt("OutputWidth", 800); + std::stringstream w; + w << width; + int height = hGrp->GetInt("OutputHeight", 600); + std::stringstream h; + h << height; + std::string par = hGrp->GetASCII("OutputParameters", "+P +A"); + doCommand(Doc,"PageFile = open(App.activeDocument().%s.PageResult,'r')",Sel[0].FeatName); + doCommand(Doc,"import subprocess,tempfile"); + doCommand(Doc,"TempFile = tempfile.mkstemp(suffix='.pov')[1]"); + doCommand(Doc,"f = open(TempFile,'wb')"); + doCommand(Doc,"f.write(PageFile.read())"); + doCommand(Doc,"f.close()"); + doCommand(Doc,"subprocess.call('\"%s\" %s +W%s +H%s +O\"%s\" '+TempFile,shell=True)",renderer.c_str(),par.c_str(),w.str().c_str(),h.str().c_str(),fname.c_str()); + doCommand(Gui,"import ImageGui"); + doCommand(Gui,"ImageGui.open('%s')",fname.c_str()); + doCommand(Doc,"del TempFile,PageFile"); + commitCommand(); + } + } else { openCommand("Render project"); doCommand(Doc,"PageFile = open(App.activeDocument().%s.PageResult,'r')",Sel[0].FeatName); doCommand(Doc,"import subprocess,tempfile"); - doCommand(Doc,"TempFile = tempfile.mkstemp(suffix='.pov')[1]"); + doCommand(Doc,"TempFile = tempfile.mkstemp(suffix='.lxs')[1]"); doCommand(Doc,"f = open(TempFile,'wb')"); doCommand(Doc,"f.write(PageFile.read())"); doCommand(Doc,"f.close()"); - doCommand(Doc,"subprocess.call('\"%s\" %s +W%s +H%s +O\"%s\" '+TempFile,shell=True)",povray.c_str(),par.c_str(),w.str().c_str(),h.str().c_str(),fname.c_str()); - doCommand(Gui,"import ImageGui"); - doCommand(Gui,"ImageGui.open('%s')",fname.c_str()); - doCommand(Doc,"del TempFile,PageFile"); + doCommand(Doc,"subprocess.call('\"%s\" '+TempFile,shell=True)",renderer.c_str()); + doCommand(Doc,"del TempFile,PageFile"); commitCommand(); } } @@ -616,6 +656,57 @@ bool CmdRaytracingNewLuxProject::isActive(void) return false; } +//=========================================================================== +// Raytracing_ResetCamera +//=========================================================================== + +DEF_STD_CMD_A(CmdRaytracingResetCamera); + +CmdRaytracingResetCamera::CmdRaytracingResetCamera() + : Command("Raytracing_ResetCamera") +{ + // seting the + sGroup = QT_TR_NOOP("File"); + sMenuText = QT_TR_NOOP("&Reset Camera"); + sToolTipText = QT_TR_NOOP("Sets the camera of the selected Raytracing project to match the current view"); + sWhatsThis = "Raytracing_ResetCamera"; + sStatusTip = sToolTipText; + sPixmap = "Raytrace_ResetCamera"; +} + +void CmdRaytracingResetCamera::activated(int iMsg) +{ + std::vector Sel = getSelection().getSelection(); + unsigned int n = getSelection().countObjectsOfType(Raytracing::RayProject::getClassTypeId()); + if (n != 1) { + n = getSelection().countObjectsOfType(Raytracing::LuxProject::getClassTypeId()); + if (n != 1) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), + QObject::tr("Select one Raytracing project object.")); + return; + } else { + //luxrender + openCommand("Reset Raytracing Camera"); + doCommand(Doc,"import RaytracingGui"); + doCommand(Doc,"App.activeDocument().%s.Camera = RaytracingGui.luxViewCamera()",Sel[0].FeatName); + commitCommand(); + doCommand(Doc,"App.activeDocument().recompute()"); + } + } else { + //povray + openCommand("Reset Raytracing Camera"); + doCommand(Doc,"import RaytracingGui"); + doCommand(Doc,"App.activeDocument().%s.Camera = RaytracingGui.povViewCamera()",Sel[0].FeatName); + commitCommand(); + doCommand(Doc,"App.activeDocument().recompute()"); + } +} + +bool CmdRaytracingResetCamera::isActive(void) +{ + return (getActiveGuiDocument() ? true : false); +} + void CreateRaytracingCommands(void) { Gui::CommandManager &rcCmdMgr = Gui::Application::Instance->commandManager(); @@ -627,4 +718,5 @@ void CreateRaytracingCommands(void) rcCmdMgr.addCommand(new CmdRaytracingNewPartSegment()); rcCmdMgr.addCommand(new CmdRaytracingRender()); rcCmdMgr.addCommand(new CmdRaytracingNewLuxProject()); + rcCmdMgr.addCommand(new CmdRaytracingResetCamera()); } diff --git a/src/Mod/Raytracing/Gui/DlgSettingsRay.ui b/src/Mod/Raytracing/Gui/DlgSettingsRay.ui index 57b2e23e7..3c92b5df6 100644 --- a/src/Mod/Raytracing/Gui/DlgSettingsRay.ui +++ b/src/Mod/Raytracing/Gui/DlgSettingsRay.ui @@ -134,7 +134,7 @@ - Output parameters: + Povray output parameters: @@ -210,6 +210,26 @@ + + + + Luxrender executable: + + + + + + + The path to the luxrender (or luxconsole) executable + + + LuxrenderExecutable + + + Mod/Raytracing + + + diff --git a/src/Mod/Raytracing/Gui/DlgSettingsRayImp.cpp b/src/Mod/Raytracing/Gui/DlgSettingsRayImp.cpp index af22079c5..0ee06ae4e 100644 --- a/src/Mod/Raytracing/Gui/DlgSettingsRayImp.cpp +++ b/src/Mod/Raytracing/Gui/DlgSettingsRayImp.cpp @@ -51,6 +51,7 @@ void DlgSettingsRayImp::saveSettings() { prefFileChooser1->onSave(); prefFileChooser2->onSave(); + prefFileChooser3->onSave(); prefLineEdit2->onSave(); prefLineEdit3->onSave(); prefFloatSpinBox1->onSave(); @@ -65,6 +66,7 @@ void DlgSettingsRayImp::loadSettings() { prefFileChooser1->onRestore(); prefFileChooser2->onRestore(); + prefFileChooser3->onRestore(); prefLineEdit2->onRestore(); prefLineEdit3->onRestore(); prefFloatSpinBox1->onRestore(); diff --git a/src/Mod/Raytracing/Gui/Resources/Raytracing.qrc b/src/Mod/Raytracing/Gui/Resources/Raytracing.qrc index 83cdccf07..122c988bf 100644 --- a/src/Mod/Raytracing/Gui/Resources/Raytracing.qrc +++ b/src/Mod/Raytracing/Gui/Resources/Raytracing.qrc @@ -8,6 +8,7 @@ icons/Raytrace_ExportProject.svg icons/Raytrace_NewPartSegment.svg icons/Raytrace_Render.svg + icons/Raytrace_ResetCamera.svg icons/Raytrace_Lux.svg translations/Raytracing_af.qm translations/Raytracing_de.qm diff --git a/src/Mod/Raytracing/Gui/Resources/icons/Raytrace_ResetCamera.svg b/src/Mod/Raytracing/Gui/Resources/icons/Raytrace_ResetCamera.svg new file mode 100644 index 000000000..d170cb004 --- /dev/null +++ b/src/Mod/Raytracing/Gui/Resources/icons/Raytrace_ResetCamera.svg @@ -0,0 +1,533 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + Jakub Steiner + + + http://jimmac.musichall.cz + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Mod/Raytracing/Gui/Workbench.cpp b/src/Mod/Raytracing/Gui/Workbench.cpp index 6f0608270..a26452c81 100644 --- a/src/Mod/Raytracing/Gui/Workbench.cpp +++ b/src/Mod/Raytracing/Gui/Workbench.cpp @@ -70,6 +70,7 @@ Gui::MenuItem* Workbench::setupMenuBar() const << "Raytracing_NewPovrayProject" << "Raytracing_NewLuxProject" << "Raytracing_NewPartSegment" + << "Raytracing_ResetCamera" << "Raytracing_ExportProject" << "Raytracing_Render"; @@ -85,6 +86,7 @@ Gui::ToolBarItem* Workbench::setupToolBars() const << "Raytracing_NewPovrayProject" << "Raytracing_NewLuxProject" << "Raytracing_NewPartSegment" + << "Raytracing_ResetCamera" << "Raytracing_ExportProject" << "Raytracing_Render"; return root; diff --git a/src/Mod/Raytracing/Templates/LuxClassic.lxs b/src/Mod/Raytracing/Templates/LuxClassic.lxs index 0ac951ead..81c6da7cc 100644 --- a/src/Mod/Raytracing/Templates/LuxClassic.lxs +++ b/src/Mod/Raytracing/Templates/LuxClassic.lxs @@ -100,6 +100,8 @@ MakeNamedMaterial "outside.003" # Geometry File +#RaytracingContent + AttributeBegin # "Plane.007" Transform [-0.083770856261253 0.000000133886644 -0.996485054492950 0.000000000000000 -0.000000133886729 1.000000000000000 0.000000145614280 0.000000000000000 0.996485054492950 0.000000145614365 -0.083770856261253 0.000000000000000 -0.465571254491806 -0.011301971040666 0.364225387573242 1.000000000000000] @@ -150,11 +152,9 @@ Shape "mesh" AttributeEnd # "" -#RaytracingContent - AttributeBegin # "Cube.002" -Transform [1.000000000000000 0.000000000000000 0.000000000000000 0.000000000000000 0.000000000000000 1.000000000000000 0.000000000000000 0.000000000000000 0.000000000000000 0.000000000000000 1.000000000000000 0.000000000000000 0.000000000000000 0.000000000000000 0.000000000000000 1.000000000000000] +Transform [10.000000000000000 0.000000000000000 0.000000000000000 0.000000000000000 0.000000000000000 10.000000000000000 0.000000000000000 0.000000000000000 0.000000000000000 0.000000000000000 10.000000000000000 0.000000000000000 0.000000000000000 0.000000000000000 0.000000000000000 1.000000000000000] NamedMaterial "outside.003"