diff --git a/src/Mod/Raytracing/App/CMakeLists.txt b/src/Mod/Raytracing/App/CMakeLists.txt index 59249a840..de458a9b2 100644 --- a/src/Mod/Raytracing/App/CMakeLists.txt +++ b/src/Mod/Raytracing/App/CMakeLists.txt @@ -42,6 +42,8 @@ SET(Raytracing_SRCS FreeCADpov PovTools.cpp PovTools.h + LuxTools.cpp + LuxTools.h PreCompiled.cpp PreCompiled.h RayFeature.cpp diff --git a/src/Mod/Raytracing/App/LuxTools.cpp b/src/Mod/Raytracing/App/LuxTools.cpp new file mode 100644 index 000000000..402bb978b --- /dev/null +++ b/src/Mod/Raytracing/App/LuxTools.cpp @@ -0,0 +1,65 @@ +/*************************************************************************** + * Copyright (c) Jürgen Riegel (juergen.riegel@web.de) 2005 * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +#include "PreCompiled.h" + +#ifndef _PreComp_ +# include +# include +# include +# include +# include +# include +# include +# include +# include +#endif + +#include +#include +#include +#include + + +#include "PovTools.h" +#include "LuxTools.h" + +using Base::Console; + +using namespace Raytracing; +using namespace std; + +std::string LuxTools::getCamera(const CamDef& Cam) +{ + std::stringstream out; + out << "# declares positon and view direction" << endl + << "# Generated by FreeCAD (http://www.freecadweb.org/)" << endl + + // writing Camera positions + << "LookAt " << Cam.CamPos.X() << " " << Cam.CamPos.Y() << " " << Cam.CamPos.Z() << " " + // writing lookat + << Cam.LookAt.X() << " " << Cam.LookAt.Y() << " " << Cam.LookAt.Z() << " " + // writing the Up Vector + << Cam.Up.X() << " " << Cam.Up.Y() << " " << Cam.Up.Z() << endl; + + return out.str(); +} diff --git a/src/Mod/Raytracing/App/LuxTools.h b/src/Mod/Raytracing/App/LuxTools.h new file mode 100644 index 000000000..5064da9ad --- /dev/null +++ b/src/Mod/Raytracing/App/LuxTools.h @@ -0,0 +1,45 @@ +/*************************************************************************** + * Copyright (c) Jürgen Riegel (juergen.riegel@web.de) 2005 * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#ifndef _LuxTools_h_ +#define _LuxTools_h_ + +#include +#include + +class TopoDS_Shape; +class TopoDS_Face; + +namespace Data { class ComplexGeoData; } + +namespace Raytracing +{ + class AppRaytracingExport LuxTools + { + public: + /// returns the given camera position as povray defines in a file + static std::string getCamera(const CamDef& Cam); + }; +} // namespace Raytracing + +#endif // _PovTools_h_ diff --git a/src/Mod/Raytracing/Gui/AppRaytracingGuiPy.cpp b/src/Mod/Raytracing/Gui/AppRaytracingGuiPy.cpp index 69c31cad1..dc816ad19 100644 --- a/src/Mod/Raytracing/Gui/AppRaytracingGuiPy.cpp +++ b/src/Mod/Raytracing/Gui/AppRaytracingGuiPy.cpp @@ -42,7 +42,7 @@ #include #include - +#include #include "PovrayHighlighter.h" using namespace RaytracingGui; @@ -137,6 +137,60 @@ povViewCamera(PyObject *self, PyObject *args) } PY_CATCH; } +/// return a luxrender camera definition of the active view +static PyObject * +luxViewCamera(PyObject *self, PyObject *args) +{ + // no arguments + if (!PyArg_ParseTuple(args, "")) + return NULL; + PY_TRY { + std::string out; + const char* ppReturn=0; + + Gui::Application::Instance->sendMsgToActiveView("GetCamera",&ppReturn); + + SoNode* rootNode; + SoInput in; + in.setBuffer((void*)ppReturn,std::strlen(ppReturn)); + SoDB::read(&in,rootNode); + + if (!rootNode || !rootNode->getTypeId().isDerivedFrom(SoCamera::getClassTypeId())) + throw Base::Exception("CmdRaytracingWriteCamera::activated(): Could not read " + "camera information from ASCII stream....\n"); + + // root-node returned from SoDB::readAll() has initial zero + // ref-count, so reference it before we start using it to + // avoid premature destruction. + SoCamera * Cam = static_cast(rootNode); + Cam->ref(); + + SbRotation camrot = Cam->orientation.getValue(); + + SbVec3f upvec(0, 1, 0); // init to default up vector + camrot.multVec(upvec, upvec); + + SbVec3f lookat(0, 0, -1); // init to default view direction vector + camrot.multVec(lookat, lookat); + + SbVec3f pos = Cam->position.getValue(); + float Dist = Cam->focalDistance.getValue(); + + // making gp out of the Coin stuff + gp_Vec gpPos(pos.getValue()[0],pos.getValue()[1],pos.getValue()[2]); + gp_Vec gpDir(lookat.getValue()[0],lookat.getValue()[1],lookat.getValue()[2]); + lookat *= Dist; + lookat += pos; + gp_Vec gpLookAt(lookat.getValue()[0],lookat.getValue()[1],lookat.getValue()[2]); + gp_Vec gpUp(upvec.getValue()[0],upvec.getValue()[1],upvec.getValue()[2]); + + // call the write method of PovTools.... + out = LuxTools::getCamera(CamDef(gpPos,gpDir,gpLookAt,gpUp)); + + return Py::new_reference_to(Py::String(out)); + } PY_CATCH; +} + /* registration table */ struct PyMethodDef RaytracingGui_methods[] = { {"open" ,open ,METH_VARARGS, @@ -144,6 +198,8 @@ struct PyMethodDef RaytracingGui_methods[] = { {"insert" ,open ,METH_VARARGS, "insert(string,string) -- Create a new text document and load the file into the document."}, {"povViewCamera" ,povViewCamera ,METH_VARARGS, - "string povViewCamera() -- returns the povray camera devinition of the active 3D view."}, + "string povViewCamera() -- returns the povray camera definition of the active 3D view."}, + {"luxViewCamera" ,luxViewCamera ,METH_VARARGS, + "string luxViewCamera() -- returns the luxrender camera definition of the active 3D view."}, {NULL, NULL} };