Raytracing: Added lux camera export function

This commit is contained in:
Yorik van Havre 2013-09-20 18:39:11 -03:00
parent 6a7d2dea17
commit 1c51aea58a
4 changed files with 170 additions and 2 deletions

View File

@ -42,6 +42,8 @@ SET(Raytracing_SRCS
FreeCADpov
PovTools.cpp
PovTools.h
LuxTools.cpp
LuxTools.h
PreCompiled.cpp
PreCompiled.h
RayFeature.cpp

View File

@ -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 <BRep_Tool.hxx>
# include <BRepMesh_IncrementalMesh.hxx>
# include <GeomAPI_ProjectPointOnSurf.hxx>
# include <GeomLProp_SLProps.hxx>
# include <Poly_Triangulation.hxx>
# include <TopExp_Explorer.hxx>
# include <TopoDS.hxx>
# include <TopoDS_Face.hxx>
# include <sstream>
#endif
#include <Base/Console.h>
#include <Base/Exception.h>
#include <Base/Sequencer.h>
#include <App/ComplexGeoData.h>
#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();
}

View File

@ -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 <gp_Vec.hxx>
#include <vector>
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_

View File

@ -42,7 +42,7 @@
#include <Gui/View.h>
#include <Mod/Raytracing/App/PovTools.h>
#include <Mod/Raytracing/App/LuxTools.h>
#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<SoCamera*>(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}
};