New export through plugin scheme for yafray. It is working on linux and mac os x

Needs latest yafray, you can get it from cvs, but I have also binaries
for os x here:

http://www.coala.uniovi.es/~jandro/noname/downloads/yafray-0.0.6-3.pkg.zip

To use it, go to yafray panels (global settings) and uncheck the "xml" button.
That would tell the export code to avoid xml export and use the yafray plugin
instead. You'll see the render being draw while running and you can even stop it
with ESC key.

Since I'm sure problems will appear, expect updates soon.
Remember: does not work on win32
This commit is contained in:
Alejandro Conty Estevez 2004-06-16 18:44:12 +00:00
parent 54f9086d3c
commit ed86852f7e
11 changed files with 1660 additions and 5 deletions

@ -214,7 +214,7 @@ typedef struct RenderData {
/* yafray: global panel params */
short GIquality, GIcache, GImethod, GIgradient,GIphotons,GIdirect;
short YF_AA, YFshortpad;
short YF_AA, YFexportxml;
int GIdepth, GIcausdepth, GIpixelspersample;
int GIphotoncount,GImixphotons;
float GIphotonradius;

@ -749,6 +749,10 @@ void yafrayRender()
printf("Starting scene conversion.\n");
prepareScene();
printf("Scene conversion done.\n");
if(!R.r.YFexportxml)
YAF_switchFile();
else
YAF_switchPlugin();
YAF_exportScene();
finalizeScene();
}

@ -1294,8 +1294,11 @@ static void render_panel_yafrayGlobal()
&G.scene->r.YF_numprocs, 1.0, 8.0, 10, 10, "Number of processors to use");
/*AA Settings*/
uiDefButS(block,TOGN|BIT|0, B_REDR, "Auto AA",5,110,150,20, &G.scene->r.YF_AA,
0, 0, 0, 0, "Set AA using OSA and GI quality, disable for manual control");
uiDefButS(block,TOGN|BIT|0, B_REDR, "xml",175,110,75,20, &G.scene->r.YFexportxml,
0, 0, 0, 0, "Export to an xml file and call yafray isntead of plugin");
if(G.scene->r.YF_AA){
uiDefButI(block, NUM, 0, "AA Passes ", 5,85,150,20,
&G.scene->r.YF_AApasses, 0, 64, 10, 10, "AA Passes");

@ -6,6 +6,8 @@ yafray_env = library_env.Copy ()
source_files = ['intern/yafray_Render.cpp',
'intern/export_File.cpp',
'intern/export_Plugin.cpp',
'intern/yafexternal.cpp',
'intern/api.cpp']
yafray_env.Append (CPPPATH = ['#/intern/guardedalloc',
@ -13,6 +15,8 @@ yafray_env.Append (CPPPATH = ['#/intern/guardedalloc',
'../makesdna',
'../blenkernel',
'../imbuf',
'../render/extern/include'])
'../include',
'../render/extern/include',
'../render/intern/include'])
yafray_env.Library (target='#'+user_options_dict['BUILD_DIR']+'/lib/blender_yafray', source=source_files)

@ -5,6 +5,8 @@
#ifdef __cplusplus
extern "C" {
#endif
void YAF_switchPlugin();
void YAF_switchFile();
int YAF_exportScene();
//void YAF_displayImage();
void YAF_addDupliMtx(Object* obj);

@ -1,12 +1,15 @@
#include "export_File.h"
#include "export_Plugin.h"
static yafrayFileRender_t byfile;
static yafrayPluginRender_t byplugin;
yafrayRender_t *YAFBLEND=&byfile;
yafrayRender_t *YAFBLEND=&byplugin;
extern "C"
{
void YAF_switchPlugin() {YAFBLEND=&byplugin;}
void YAF_switchFile() {YAFBLEND=&byfile;}
int YAF_exportScene() { return (int)YAFBLEND->exportScene(); }
//void YAF_displayImage() { YAFBLEND->displayImage(); }
void YAF_addDupliMtx(Object* obj) { YAFBLEND->addDupliMtx(obj); }

File diff suppressed because it is too large Load Diff

@ -0,0 +1,67 @@
#ifndef __EXPORT_PLUGIN_H
#define __EXPORT_PLUGIN_H
#include"yafray_Render.h"
#include"yafexternal.h"
extern "C"
{
#include"PIL_dynlib.h"
}
class yafrayPluginRender_t : public yafrayRender_t
{
public:
yafrayPluginRender_t() {handle=NULL;yafrayGate=NULL;}
virtual ~yafrayPluginRender_t();
protected:
std::string imgout;
//void *handle;
PILdynlib *handle;
yafray::yafrayInterface_t *yafrayGate;
void displayImage();
virtual void writeTextures();
virtual void writeMaterialsAndModulators();
virtual void writeObject(Object* obj,
const std::vector<VlakRen*> &VLR_list, const float obmat[4][4]);
virtual void writeAllObjects();
void writeAreaLamp(LampRen* lamp,int num);
virtual void writeLamps();
virtual void writeCamera();
virtual void writeHemilight();
virtual void writePathlight();
virtual bool writeWorld();
virtual bool writeRender();
virtual bool initExport();
virtual bool finishExport();
void genUVcoords(std::vector<yafray::GFLOAT> *uvcoords,VlakRen *vlr,TFace* uvc);
void genCompleUVcoords(std::vector<yafray::GFLOAT> *uvcoords,/*VlakRen *vlr,*/TFace* uvc);
void genVcol(std::vector<yafray::CFLOAT> *vcol,VlakRen *vlr,
int p1,int p2,int p3,bool EXPORT_VCOL);
void genFace(std::vector<int> &faces,std::vector<std::string> &shaders,std::vector<int> &faceshader,
std::vector<yafray::GFLOAT> *uvcoords,std::vector<yafray::CFLOAT> *vcol,
std::map<VertRen*, int> &vert_idx,VlakRen *vlr,
bool has_orco,bool has_uv,bool has_vcol);
void genCompleFace(std::vector<int> &faces,/*std::vector<std::string> &shaders,*/std::vector<int> &faceshader,
std::vector<yafray::GFLOAT> *uvcoords,std::vector<yafray::CFLOAT> *vcol,
std::map<VertRen*, int> &vert_idx,VlakRen *vlr,
bool has_orco,bool has_uv,bool has_vcol);
void genVertices(std::vector<yafray::point3d_t> *verts,int &vidx,
std::map<VertRen*, int> &vert_idx,VlakRen* vlr,bool has_orco);
};
class blenderYafrayOutput_t : public yafray::colorOutput_t
{
public:
blenderYafrayOutput_t() {out=0;};
virtual ~blenderYafrayOutput_t() {};
virtual bool putPixel(int x, int y,const yafray::color_t &c,
yafray::CFLOAT alpha=0,yafray::PFLOAT depth=0);
virtual void flush() {};
protected:
int out;
};
#endif

@ -0,0 +1,83 @@
#include "yafexternal.h"
#include <iostream>
namespace yafray {
bool paramMap_t::getParam(const std::string &name,std::string &s)
{
if(includes(name,TYPE_STRING)) s=(*this)[name].getStr();
else return false;
return true;
}
bool paramMap_t::getParam(const std::string &name,bool &b)
{
std::string str;
if(includes(name,TYPE_STRING))
{
str=(*this)[name].getStr();
if(str=="on") b=true;
else if(str=="off") b=false;
else return false;
}
else return false;
return true;
}
bool paramMap_t::getParam(const std::string &name,float &f)
{
if(includes(name,TYPE_FLOAT)) f=(*this)[name].getFnum();
else return false;
return true;
}
bool paramMap_t::getParam(const std::string &name,double &f)
{
if(includes(name,TYPE_FLOAT)) f=(*this)[name].getFnum();
else return false;
return true;
}
bool paramMap_t::getParam(const std::string &name,int &i)
{
if(includes(name,TYPE_FLOAT)) i=(int)(*this)[name].getFnum();
else return false;
return true;
}
bool paramMap_t::getParam(const std::string &name,point3d_t &p)
{
if(includes(name,TYPE_POINT)) p=(*this)[name].getP();
else return false;
return true;
}
bool paramMap_t::getParam(const std::string &name,color_t &c)
{
if(includes(name,TYPE_COLOR)) c=(*this)[name].getC();
else return false;
return true;
}
bool paramMap_t::getParam(const std::string &name,colorA_t &c)
{
if(includes(name,TYPE_COLOR)) c=(*this)[name].getAC();
else return false;
return true;
}
bool paramMap_t::includes(const std::string &label,int type)
{
const_iterator i=find(label);
if(i==end()) return false;
if((*i).second.type!=type) return false;
return true;
}
void paramMap_t::checkUnused(const std::string &env)
{
for(const_iterator i=begin();i!=end();++i)
if(!( (*i).second.used ))
std::cout<<"[WARNING]:Unused param "<<(*i).first<<" in "<<env<<"\n";
}
}

@ -0,0 +1,179 @@
#ifndef __YAFINTERFACE_H
#define __YAFINTERFACE_H
#include<vector>
#include<string>
#include<list>
#include<map>
namespace yafray
{
typedef float PFLOAT;
typedef float GFLOAT;
typedef float CFLOAT;
class point3d_t
{
public:
point3d_t() { x = y = z = 0; }
point3d_t(PFLOAT ix, PFLOAT iy, PFLOAT iz=0) { x=ix; y=iy; z=iz; }
point3d_t(const point3d_t &s) { x=s.x; y=s.y; z=s.z; }
void set(PFLOAT ix, PFLOAT iy, PFLOAT iz=0) { x=ix; y=iy; z=iz; }
point3d_t& operator= (const point3d_t &s) { x=s.x; y=s.y; z=s.z; return *this; }
~point3d_t() {};
PFLOAT x,y,z;
};
class color_t
{
public:
color_t() {R=G=B=0;};
color_t(CFLOAT r,CFLOAT g,CFLOAT b) {R=r;G=g;B=b;};
~color_t() {};
void set(CFLOAT r,CFLOAT g,CFLOAT b) {R=r;G=g;B=b;};
CFLOAT R,G,B;
};
class colorA_t : public color_t
{
public:
colorA_t() { A=1; }
colorA_t(const color_t &c):color_t(c) { A=1; }
colorA_t(CFLOAT r, CFLOAT g, CFLOAT b, CFLOAT a=0):color_t(r,g,b) {A=a;}
~colorA_t() {};
void set(CFLOAT r, CFLOAT g, CFLOAT b, CFLOAT a=0) {color_t::set(r,g,b);A=a; };
protected:
CFLOAT A;
};
#define TYPE_FLOAT 0
#define TYPE_STRING 1
#define TYPE_POINT 2
#define TYPE_COLOR 3
#define TYPE_NONE -1
class parameter_t
{
public:
parameter_t(const std::string &s):type(TYPE_STRING),used(false),str(s) {};
parameter_t(float f):type(TYPE_FLOAT),used(false),fnum(f) {};
parameter_t(const colorA_t &c):type(TYPE_COLOR),used(false)
,C(c) {};
parameter_t(const point3d_t &p):type(TYPE_POINT),used(false),P(p) {};
parameter_t():type(TYPE_NONE),used(false) {};
const std::string &getStr() {used=true;return str;};
float &getFnum() {used=true;return fnum;};
const point3d_t &getP() {used=true;return P;};
const color_t &getC() {used=true;return C;};
const colorA_t &getAC() {used=true;return C;};
int type;
bool used;
protected:
std::string str;
float fnum;
point3d_t P;
colorA_t C;
};
class paramMap_t : public std::map<std::string,parameter_t>
{
public:
virtual bool getParam(const std::string &name,std::string &s);
virtual bool getParam(const std::string &name,bool &b);
virtual bool getParam(const std::string &name,float &f);
virtual bool getParam(const std::string &name,double &f);
virtual bool getParam(const std::string &name,int &i);
virtual bool getParam(const std::string &name,point3d_t &p);
virtual bool getParam(const std::string &name,color_t &c);
virtual bool getParam(const std::string &name,colorA_t &c);
virtual bool includes(const std::string &label,int type);
virtual void checkUnused(const std::string &env);
virtual ~paramMap_t() {};
};
class light_t;
class shader_t;
class texture_t;
class filter_t;
class background_t;
class renderEnvironment_t
{
public:
typedef light_t * light_factory_t(paramMap_t &,renderEnvironment_t &);
typedef shader_t *shader_factory_t(paramMap_t &,std::list<paramMap_t> &,
renderEnvironment_t &);
typedef texture_t *texture_factory_t(paramMap_t &,renderEnvironment_t &);
typedef filter_t *filter_factory_t(paramMap_t &,renderEnvironment_t &);
typedef background_t *background_factory_t(paramMap_t &,renderEnvironment_t &);
virtual shader_t *getShader(const std::string name)const=0;
virtual texture_t *getTexture(const std::string name)const=0;
virtual void repeatFirstPass()=0;
virtual void registerFactory(const std::string &name,light_factory_t *f)=0;
virtual void registerFactory(const std::string &name,shader_factory_t *f)=0;
virtual void registerFactory(const std::string &name,texture_factory_t *f)=0;
virtual void registerFactory(const std::string &name,filter_factory_t *f)=0;
virtual void registerFactory(const std::string &name,background_factory_t *f)=0;
renderEnvironment_t() {};
virtual ~renderEnvironment_t() {};
};
class colorOutput_t
{
public:
virtual ~colorOutput_t() {};
virtual bool putPixel(int x, int y,const color_t &c,
CFLOAT alpha=0,PFLOAT depth=0)=0;
virtual void flush()=0;
};
class yafrayInterface_t : public renderEnvironment_t
{
public:
virtual void transformPush(float *m)=0;
virtual void transformPop()=0;
virtual void addObject_trimesh(const std::string &name,
std::vector<point3d_t> *verts, const std::vector<int> &faces,
std::vector<GFLOAT> *uvcoords, std::vector<CFLOAT> *vcol,
const std::vector<std::string> &shaders,const std::vector<int> &faceshader,
float sm_angle,bool castShadows,bool useR,bool receiveR,bool caus,bool has_orco,
const color_t &caus_rcolor,const color_t &caus_tcolor,float caus_IOR)=0;
virtual void addObject_reference(const std::string &name,const std::string &original)=0;
// lights
virtual void addLight(paramMap_t &p)=0;
// textures
virtual void addTexture(paramMap_t &p)=0;
// shaders
virtual void addShader(paramMap_t &p,std::list<paramMap_t> &modulators)=0;
// filters
virtual void addFilter(paramMap_t &p)=0;
// backgrounds
virtual void addBackground(paramMap_t &p)=0;
//camera
virtual void addCamera(paramMap_t &p)=0;
//render
virtual void render(paramMap_t &p)=0;
//render
virtual void render(paramMap_t &p,colorOutput_t &output)=0;
virtual void clear()=0;
virtual ~yafrayInterface_t() {};
};
typedef yafrayInterface_t * yafrayConstructor(int,const std::string &);
}
#define YAFRAY_SYMBOL "getYafray"
#endif

@ -45,7 +45,7 @@ bool yafrayRender_t::exportScene()
clearAll();
return false;
}
cout<<"Writing textures"<<endl;
// start actual data export
writeTextures();
writeMaterialsAndModulators();