Raytracing: Added Luxrender project

This commit is contained in:
Yorik van Havre
2013-09-27 23:18:00 -03:00
parent 5127a2bf07
commit a2a159c40a
11 changed files with 1188 additions and 15 deletions

View File

@@ -33,6 +33,7 @@
#include "RayProject.h"
#include "RaySegment.h"
#include "LuxFeature.h"
#include "LuxProject.h"
extern struct PyMethodDef Raytracing_methods[];
@@ -53,6 +54,7 @@ void AppRaytracingExport initRaytracing()
Raytracing::RayFeature ::init();
Raytracing::RayProject ::init();
Raytracing::LuxFeature ::init();
Raytracing::LuxProject ::init();
(void) Py_InitModule("Raytracing", Raytracing_methods); /* mod name, table ptr */

View File

@@ -54,6 +54,8 @@ SET(Raytracing_SRCS
RaySegment.h
LuxFeature.h
LuxFeature.cpp
LuxProject.h
LuxProject.cpp
)
SET(Raytracing_Scripts

View File

@@ -0,0 +1,107 @@
/***************************************************************************
* Copyright (c) Yorik van Havre (yorik@uncreated.net) 2013 *
* *
* 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 <Standard.hxx>
# include <string>
#endif
#include <Base/FileInfo.h>
#include <Base/Console.h>
#include "LuxProject.h"
#include "LuxFeature.h"
using namespace Raytracing;
using namespace std;
PROPERTY_SOURCE(Raytracing::LuxProject, App::DocumentObjectGroup)
//===========================================================================
// Feature
//===========================================================================
LuxProject::LuxProject(void)
{
ADD_PROPERTY_TYPE(PageResult ,(0),0,App::Prop_Output,"Resulting Luxrender Scene file");
ADD_PROPERTY_TYPE(Template ,(""),0,App::Prop_None ,"Template for the Luxrender project");
ADD_PROPERTY_TYPE(Camera ,(""),0,App::Prop_None ,"Camera settings");
}
App::DocumentObjectExecReturn *LuxProject::execute(void)
{
if (std::string(PageResult.getValue()) == "")
PageResult.setValue(Template.getValue());
Base::FileInfo fi(Template.getValue());
if (!fi.isReadable()) {
Base::Console().Log("LuxProject::execute() not able to open %s!\n",Template.getValue());
std::string error = std::string("Cannot open file ") + Template.getValue();
return new App::DocumentObjectExecReturn(error);
}
// open Template file
string line;
ifstream file ( fi.filePath().c_str() );
// make a temp file for FileIncluded Property
string tempName = PageResult.getExchangeTempFile();
ofstream ofile(tempName.c_str());
// copy the input of the resource file
while (!file.eof()) {
getline (file,line);
// check if the marker in the template is found
if(line.find("#RaytracingContent") == string::npos) {
if(line.find("#RaytracingCamera") == string::npos) {
// if not - write through
ofile << line << endl;
} else {
// in luxrender, the camera info must be written at a specific place
ofile << Camera.getValue();
}
} else {
// get through the children and collect all the views
const std::vector<App::DocumentObject*> &Grp = Group.getValues();
for (std::vector<App::DocumentObject*>::const_iterator It= Grp.begin();It!=Grp.end();++It) {
if ((*It)->getTypeId().isDerivedFrom(Raytracing::LuxFeature::getClassTypeId())) {
Raytracing::LuxFeature *View = dynamic_cast<Raytracing::LuxFeature *>(*It);
ofile << View->Result.getValue();
ofile << endl << endl << endl;
}
}
}
}
file.close();
ofile.close();
PageResult.setValue(tempName.c_str());
return App::DocumentObject::StdReturn;
}
short LuxProject::mustExecute() const
{
return 0;
}

View File

@@ -0,0 +1,69 @@
/***************************************************************************
* Copyright (c) Yorik van Havre (yorik@uncreated.net) 2013 *
* *
* 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 _LuxProject_h_
#define _LuxProject_h_
#include <App/DocumentObjectGroup.h>
#include <App/PropertyStandard.h>
#include <App/PropertyFile.h>
namespace Raytracing
{
class Property;
/** Base class of all Feature classes in FreeCAD
*/
//class RayFeature: public Part::PartFeature
class AppRaytracingExport LuxProject: public App::DocumentObjectGroup
{
PROPERTY_HEADER(Raytracing::LuxProject);
public:
/// Constructor
LuxProject(void);
App::PropertyFileIncluded PageResult;
App::PropertyFile Template;
App::PropertyString Camera;
/** @name methods overide Feature */
//@{
/// recalculate the Feature
App::DocumentObjectExecReturn *execute(void);
short mustExecute() const;
//@}
};
} //namespace Raytracing
#endif //_LuxFeature_h_

View File

@@ -18,6 +18,6 @@ INSTALL(
Templates
DESTINATION
${CMAKE_INSTALL_DATADIR}/Mod/Raytracing
FILES_MATCHING PATTERN "*.pov*"
FILES_MATCHING PATTERN "*.pov*"PATTERN "*.lxs*"
)

View File

@@ -56,6 +56,7 @@
#include <Mod/Raytracing/App/RayFeature.h>
#include <Mod/Raytracing/App/RaySegment.h>
#include <Mod/Raytracing/App/RayProject.h>
#include <Mod/Raytracing/App/LuxProject.h>
#include <Mod/Part/App/PartFeature.h>
#include "FreeCADpov.h"
@@ -355,7 +356,7 @@ CmdRaytracingNewPartSegment::CmdRaytracingNewPartSegment()
sAppModule = "Raytracing";
sGroup = QT_TR_NOOP("Raytracing");
sMenuText = QT_TR_NOOP("Insert part");
sToolTipText = QT_TR_NOOP("Insert a new part object into a Povray project");
sToolTipText = QT_TR_NOOP("Insert a new part object into a Raytracing project");
sWhatsThis = "Raytracing_NewPartSegment";
sStatusTip = sToolTipText;
sPixmap = "Raytrace_NewPartSegment";
@@ -372,30 +373,43 @@ void CmdRaytracingNewPartSegment::activated(int iMsg)
std::vector<App::DocumentObject*> pages = App::GetApplication().getActiveDocument()
->getObjectsOfType(Raytracing::RayProject::getClassTypeId());
std::vector<App::DocumentObject*> pages2 = App::GetApplication().getActiveDocument()
->getObjectsOfType(Raytracing::LuxProject::getClassTypeId());
pages.insert(pages.end(),pages2.begin(),pages2.end());
if (pages.empty()) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No Povray project to insert"),
QObject::tr("Create a Povray project to insert a view."));
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No Raytracing project to insert"),
QObject::tr("Create a Raytracing project to insert a view."));
return;
}
std::string ProjName;
if (pages.size() > 1) {
// priority to the elders, if there is a pov project in the selection, it is used first!
pages = Gui::Selection().getObjectsOfType(Raytracing::RayProject::getClassTypeId());
if (pages.size() != 1) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No Povray project to insert"),
QObject::tr("Select a Povray project to insert the view."));
return;
pages = Gui::Selection().getObjectsOfType(Raytracing::LuxProject::getClassTypeId());
if (pages.size() != 1) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No Raytracing project to insert"),
QObject::tr("Select a Raytracing project to insert the view."));
return;
}
}
}
ProjName = pages.front()->getNameInDocument();
const char *FeatType;
if (pages.front()->getTypeId().isDerivedFrom(Raytracing::RayProject::getClassTypeId())) {
FeatType = "RayFeature";
} else {
FeatType = "LuxFeature";
}
openCommand("Create view");
for (std::vector<Part::Feature*>::iterator it = parts.begin(); it != parts.end(); ++it) {
std::string FeatName = (*it)->getNameInDocument();
FeatName += "_View";
FeatName = getUniqueObjectName(FeatName.c_str());
doCommand(Doc,"App.activeDocument().addObject('Raytracing::RayFeature','%s')",FeatName.c_str());
doCommand(Doc,"App.activeDocument().addObject('Raytracing::%s','%s')",FeatType,FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.Source = App.activeDocument().%s",FeatName.c_str(),(*it)->getNameInDocument());
doCommand(Doc,"App.activeDocument().%s.Color = Gui.activeDocument().%s.ShapeColor",FeatName.c_str(),(*it)->getNameInDocument());
doCommand(Doc,"App.activeDocument().%s.addObject(App.activeDocument().%s)",ProjName.c_str(), FeatName.c_str());
@@ -424,7 +438,7 @@ CmdRaytracingExportProject::CmdRaytracingExportProject()
// seting the
sGroup = QT_TR_NOOP("File");
sMenuText = QT_TR_NOOP("&Export project...");
sToolTipText = QT_TR_NOOP("Export the Povray project file");
sToolTipText = QT_TR_NOOP("Export a Raytracing project to a file");
sWhatsThis = "Raytracing_ExportProject";
sStatusTip = sToolTipText;
sPixmap = "Raytrace_ExportProject";
@@ -432,15 +446,23 @@ CmdRaytracingExportProject::CmdRaytracingExportProject()
void CmdRaytracingExportProject::activated(int iMsg)
{
const char *filterLabel;
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;
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 {
filterLabel = "Luxrender Scene (*.lxs)";
}
} else {
filterLabel = "Povray Scene (*.pov)";
}
QStringList filter;
filter << QObject::tr("Povray(*.pov)");
filter << QObject::tr(filterLabel);
filter << QObject::tr("All Files (*.*)");
QString fn = Gui::FileDialog::getSaveFileName(Gui::getMainWindow(), QObject::tr("Export page"), QString(), filter.join(QLatin1String(";;")));
@@ -540,6 +562,59 @@ bool CmdRaytracingRender::isActive(void)
return (getActiveGuiDocument() ? true : false);
}
//===========================================================================
// Raytracing_NewLuxProject
//===========================================================================
DEF_STD_CMD_A(CmdRaytracingNewLuxProject);
CmdRaytracingNewLuxProject::CmdRaytracingNewLuxProject()
: Command("Raytracing_NewLuxProject")
{
sAppModule = "Raytracing";
sGroup = QT_TR_NOOP("Raytracing");
sMenuText = QT_TR_NOOP("New Luxrender project");
sToolTipText = QT_TR_NOOP("Insert new Luxrender project into the document");
sWhatsThis = "Raytracing_NewLuxrenderProject";
sStatusTip = sToolTipText;
sPixmap = "Raytrace_Lux";
}
void CmdRaytracingNewLuxProject::activated(int iMsg)
{
const char* ppReturn=0;
Gui::Application::Instance->sendMsgToActiveView("GetCamera",&ppReturn);
if (ppReturn) {
std::string str(ppReturn);
if (str.find("PerspectiveCamera") == std::string::npos) {
int ret = QMessageBox::warning(Gui::getMainWindow(),
qApp->translate("CmdRaytracingWriteView","No perspective camera"),
qApp->translate("CmdRaytracingWriteView","The current view camera is not perspective"
" and thus the result of the luxrender image later might look different to"
" what you expect.\nDo you want to continue?"),
QMessageBox::Yes|QMessageBox::No);
if (ret != QMessageBox::Yes)
return;
}
}
std::string FeatName = getUniqueObjectName("LuxProject");
openCommand("Raytracing create luxrender project");
doCommand(Doc,"import Raytracing,RaytracingGui");
doCommand(Doc,"App.activeDocument().addObject('Raytracing::LuxProject','%s')",FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.Template = App.getResourceDir()+'Mod/Raytracing/Templates/LuxClassic.lxs'",FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.Camera = RaytracingGui.luxViewCamera()",FeatName.c_str());
commitCommand();
}
bool CmdRaytracingNewLuxProject::isActive(void)
{
if (getActiveGuiDocument())
return true;
else
return false;
}
void CreateRaytracingCommands(void)
{
@@ -551,4 +626,5 @@ void CreateRaytracingCommands(void)
rcCmdMgr.addCommand(new CmdRaytracingExportProject());
rcCmdMgr.addCommand(new CmdRaytracingNewPartSegment());
rcCmdMgr.addCommand(new CmdRaytracingRender());
rcCmdMgr.addCommand(new CmdRaytracingNewLuxProject());
}

View File

@@ -8,6 +8,7 @@
<file>icons/Raytrace_ExportProject.svg</file>
<file>icons/Raytrace_NewPartSegment.svg</file>
<file>icons/Raytrace_Render.svg</file>
<file>icons/Raytrace_Lux.svg</file>
<file>translations/Raytracing_af.qm</file>
<file>translations/Raytracing_de.qm</file>
<file>translations/Raytracing_fi.qm</file>

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 33 KiB

View File

@@ -67,7 +67,8 @@ Gui::MenuItem* Workbench::setupMenuBar() const
ray->setCommand("&Raytracing");
*ray
<< utilities
<< "Raytracing_NewPovrayProject"
<< "Raytracing_NewPovrayProject"
<< "Raytracing_NewLuxProject"
<< "Raytracing_NewPartSegment"
<< "Raytracing_ExportProject"
<< "Raytracing_Render";
@@ -81,7 +82,8 @@ Gui::ToolBarItem* Workbench::setupToolBars() const
Gui::ToolBarItem* ray = new Gui::ToolBarItem(root);
ray->setCommand("Raytracing tools");
*ray
<< "Raytracing_NewPovrayProject"
<< "Raytracing_NewPovrayProject"
<< "Raytracing_NewLuxProject"
<< "Raytracing_NewPartSegment"
<< "Raytracing_ExportProject"
<< "Raytracing_Render";

View File

@@ -0,0 +1,170 @@
# Main Scene File
Renderer "sampler"
Sampler "metropolis"
"bool adaptive_largemutationprob" ["false"]
"float largemutationprob" [0.400000005960464]
"bool usecooldown" ["true"]
Accelerator "qbvh"
SurfaceIntegrator "bidirectional"
"integer eyedepth" [48]
"integer lightdepth" [48]
"string lightpathstrategy" ["auto"]
"string lightstrategy" ["auto"]
VolumeIntegrator "multi"
"float stepsize" [1.000000000000000]
PixelFilter "mitchell"
"bool supersample" ["true"]
"float B" [0.333333343267441]
"float C" [0.333333343267441]
#RaytracingCamera
Camera "perspective"
"float fov" [49.134342077604479]
"float screenwindow" [-1.000000000000000 1.000000000000000 -0.562500000000000 0.562500000000000]
"bool autofocus" ["false"]
"float shutteropen" [0.000000000000000]
"float shutterclose" [0.041666666666667]
Film "fleximage"
"integer xresolution" [1280]
"integer yresolution" [720]
"float gamma" [2.200000000000000]
"float colorspace_white" [0.314275000000000 0.329411000000000]
"float colorspace_red" [0.630000000000000 0.340000000000000]
"float colorspace_green" [0.310000000000000 0.595000000000000]
"float colorspace_blue" [0.155000000000000 0.070000000000000]
"string filename" ["luxscenes.classic.00000"]
"bool write_resume_flm" ["false"]
"bool restart_resume_flm" ["false"]
"bool write_flm_direct" ["false"]
"bool write_exr_halftype" ["true"]
"bool write_exr_applyimaging" ["true"]
"bool write_exr_ZBuf" ["false"]
"string write_exr_compressiontype" ["PIZ (lossless)"]
"string write_exr_zbuf_normalizationtype" ["None"]
"bool write_exr" ["false"]
"bool write_png" ["true"]
"string write_png_channels" ["RGB"]
"bool write_png_16bit" ["false"]
"bool write_tga" ["false"]
"string ldr_clamp_method" ["cut"]
"integer displayinterval" [10]
"integer writeinterval" [180]
"integer flmwriteinterval" [900]
"integer tilecount" [0]
"string tonemapkernel" ["autolinear"]
WorldBegin
# Materials File
Texture "arealight.008_bump+normal_generated" "float" "multimix"
"texture tex1" [""]
"texture tex2" [""]
"float weights" [1.000000000000000 1.000000000000000]
MakeNamedMaterial "arealight.008"
"texture bumpmap" ["arealight.008_bump+normal_generated"]
"color Kd" [0.63999999 0.63999999 0.63999999]
"float sigma" [0.000000000000000]
"string type" ["matte"]
Texture "arealight.007_bump+normal_generated" "float" "multimix"
"texture tex1" [""]
"texture tex2" [""]
"float weights" [1.000000000000000 1.000000000000000]
MakeNamedMaterial "arealight.007"
"texture bumpmap" ["arealight.007_bump+normal_generated"]
"color Kd" [0.63999999 0.63999999 0.63999999]
"float sigma" [0.000000000000000]
"string type" ["matte"]
Texture "outside.003_bump+normal_generated" "float" "multimix"
"texture tex1" [""]
"texture tex2" [""]
"float weights" [1.000000000000000 1.000000000000000]
MakeNamedMaterial "outside.003"
"texture bumpmap" ["outside.003_bump+normal_generated"]
"color Kd" [0.16657862 0.16086239 0.16794351]
"float sigma" [0.000000000000000]
"string type" ["matte"]
# Geometry File
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]
NamedMaterial "arealight.008"
LightGroup ""
AreaLightSource "area"
"float importance" [1.000000000000000]
"float gain" [1.399999976158142]
"float power" [140.000000000000000]
"float efficacy" [17.000000000000000]
"integer nsamples" [2]
"color L" [0.18570445 0.31653735 0.44796988]
Shape "mesh"
"integer triindices" [0 1 2 0 2 3]
"point P" [0.029652580618858 0.029652580618858 0.000000000000000 -0.029652580618858 0.029652580618858 0.000000000000000 -0.029652580618858 -0.029652580618858 0.000000000000000 0.029652580618858 -0.029652580618858 0.000000000000000]
"normal N" [0.000000000000000 -0.000000000000000 1.000000000000000 0.000000000000000 -0.000000000000000 1.000000000000000 0.000000000000000 -0.000000000000000 1.000000000000000 0.000000000000000 -0.000000000000000 1.000000000000000]
"bool generatetangents" ["false"]
"string name" ["Plane.007"]
AttributeEnd # ""
AttributeBegin # "Plane.006"
Transform [-0.284823358058929 -0.000000128793602 0.958580017089844 0.000000000000000 0.000000128793744 1.000000000000000 0.000000172627281 0.000000000000000 -0.958580017089844 0.000000172627395 -0.284823358058929 0.000000000000000 0.459476053714752 -0.011302002705634 0.600143492221832 1.000000000000000]
NamedMaterial "arealight.007"
LightGroup ""
AreaLightSource "area"
"float importance" [1.000000000000000]
"float gain" [1.399999976158142]
"float power" [140.000000000000000]
"float efficacy" [17.000000000000000]
"integer nsamples" [2]
"color L" [1.00000000 0.76869905 0.39999998]
Shape "mesh"
"integer triindices" [0 1 2 0 2 3]
"point P" [0.029652580618858 0.029652580618858 0.000000000000000 -0.029652580618858 0.029652580618858 0.000000000000000 -0.029652580618858 -0.029652580618858 0.000000000000000 0.029652580618858 -0.029652580618858 0.000000000000000]
"normal N" [0.000000000000000 -0.000000000000000 1.000000000000000 0.000000000000000 -0.000000000000000 1.000000000000000 0.000000000000000 -0.000000000000000 1.000000000000000 0.000000000000000 -0.000000000000000 1.000000000000000]
"bool generatetangents" ["false"]
"string name" ["Plane.006"]
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]
NamedMaterial "outside.003"
Shape "mesh"
"integer triindices" [0 1 2 0 2 3 4 5 6 4 6 7 0 3 5 0 5 4 3 2 6 3 6 5 2 1 7 2 7 6 1 0 4 1 4 7]
"point P" [0.500000000000000 0.499999880790710 0.000000000000000 -0.499999791383743 0.500000119209290 0.000000000000000 -0.500000059604645 -0.499999970197678 0.000000000000000 0.500000000000000 -0.500000000000000 0.000000000000000 0.500000298023224 0.499999672174454 1.000000000000000 0.499999672174454 -0.500000357627869 1.000000000000000 -0.500000178813934 -0.499999880790710 1.000000000000000 -0.499999940395355 0.499999940395355 1.000000000000000]
"normal N" [-0.577349185943604 -0.577349185943604 0.577349185943604 0.577349185943604 -0.577349185943604 0.577349185943604 0.577349185943604 0.577349185943604 0.577349185943604 -0.577349185943604 0.577349185943604 0.577349185943604 -0.577349185943604 -0.577349185943604 -0.577349185943604 -0.577349185943604 0.577349185943604 -0.577349185943604 0.577349185943604 0.577349185943604 -0.577349185943604 0.577349185943604 -0.577349185943604 -0.577349185943604]
"bool generatetangents" ["false"]
"string name" ["Cube.002"]
AttributeEnd # ""
WorldEnd

View File

@@ -74,6 +74,7 @@
<Component Id="CompModRaytracingTemplates" Guid="C0319A8E-7B29-428a-84B7-4A84DB44ABD3" Win64='$(var.Win_64)' KeyPath="yes">
<File Id="ProjectStd" Name="ProjectStd.pov" />
<File Id="RadiosityNormal" Name="RadiosityNormal.pov" />
<File Id="LuxClassic" Name="LuxClassic.pov" />
</Component>
</Directory>
</Directory>