soc-2008-mxcurioni: Freestyle now supports camera information (the image is still a bit larger than Blender's internal renderer, probably a field of view problem). 3d scene is now no longer rendered, only 2d scene (strokes from view map information) is. Style module is still static (contour.py), will soon be handled via independent UI panel.
Phase 1 is considered finished. Phase 2 starts now: the objective is integrating Freestyle as an independent render layer.
This commit is contained in:
@@ -130,7 +130,7 @@ AppGLWidget::AppGLWidget(const char *iName)
|
|||||||
_debug = false;
|
_debug = false;
|
||||||
_selection_mode = false;
|
_selection_mode = false;
|
||||||
_Draw2DScene = true;
|
_Draw2DScene = true;
|
||||||
_Draw3DScene = true;
|
_Draw3DScene = false;
|
||||||
_drawEnvMap = false;
|
_drawEnvMap = false;
|
||||||
_currentEnvMap = 1;
|
_currentEnvMap = 1;
|
||||||
_maxId = 0;
|
_maxId = 0;
|
||||||
|
|||||||
@@ -401,9 +401,9 @@ public:
|
|||||||
|
|
||||||
inline bool getRecordFlag() const {return _record;}
|
inline bool getRecordFlag() const {return _record;}
|
||||||
|
|
||||||
void setCameraState(const float* position, const float* orientation) {
|
void setCameraState(const Vec& position, const Quaternion& orientation) {
|
||||||
_camera->setPosition(Vec(position[0], position[1], position[2]));
|
_camera->setPosition(position);
|
||||||
_camera->setOrientation(Quaternion(orientation[0], orientation[1], orientation[2], orientation[3]));
|
_camera->setOrientation(orientation);
|
||||||
}
|
}
|
||||||
|
|
||||||
void getCameraState(float* position, float* orientation) const {
|
void getCameraState(float* position, float* orientation) const {
|
||||||
|
|||||||
@@ -209,7 +209,7 @@ int Controller::Load3DSFile(const char *iFileName)
|
|||||||
_RootNode->UpdateBBox(); // FIXME: Correct that by making a Renderer to compute the bbox
|
_RootNode->UpdateBBox(); // FIXME: Correct that by making a Renderer to compute the bbox
|
||||||
|
|
||||||
_pView->SetModel(_RootNode);
|
_pView->SetModel(_RootNode);
|
||||||
_pView->FitBBox();
|
//_pView->FitBBox();
|
||||||
|
|
||||||
|
|
||||||
_Chrono.start();
|
_Chrono.start();
|
||||||
@@ -399,149 +399,149 @@ void Controller::SaveViewMapFile(const char *oFileName)
|
|||||||
cout << "ViewMap saving : " << d << endl;
|
cout << "ViewMap saving : " << d << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Controller::LoadViewMapFile(const char *iFileName, bool only_camera)
|
// void Controller::LoadViewMapFile(const char *iFileName, bool only_camera)
|
||||||
{
|
|
||||||
ifstream ifs(iFileName, ios::binary);
|
|
||||||
if (!ifs.is_open()) {
|
|
||||||
cerr << "Error: Cannot load this file" << endl;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// char buffer[buffer_size];
|
|
||||||
// #if defined(__GNUC__) && (__GNUC__ < 3)
|
|
||||||
// ifs.rdbuf()->setbuf(buffer, buffer_size);
|
|
||||||
// # else
|
|
||||||
// ifs.rdbuf()->pubsetbuf(buffer, buffer_size);
|
|
||||||
// #endif
|
|
||||||
|
|
||||||
// Test File Magic and version
|
|
||||||
char tmp_buffer[256];
|
|
||||||
string test;
|
|
||||||
|
|
||||||
ifs.getline(tmp_buffer, 255);
|
|
||||||
test = tmp_buffer;
|
|
||||||
if (test != Config::VIEWMAP_MAGIC) {
|
|
||||||
cerr << "Error: This is not a valid ." << Config::VIEWMAP_EXTENSION << " file" << endl;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
ifs.getline(tmp_buffer, 255);
|
|
||||||
test = tmp_buffer;
|
|
||||||
if (test != Config::VIEWMAP_VERSION && !only_camera) {
|
|
||||||
cerr << "Error: This version of the ." << Config::VIEWMAP_EXTENSION << " file format is no longer supported" << endl;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Read the models filenames and open them (if not already done)
|
|
||||||
string tmp;
|
|
||||||
vector<string> tmp_vec;
|
|
||||||
unsigned models_nb, i;
|
|
||||||
|
|
||||||
ifs.getline(tmp_buffer, 255);
|
|
||||||
models_nb = atoi(tmp_buffer);
|
|
||||||
for (i = 0; i < models_nb; i++) {
|
|
||||||
ifs.getline(tmp_buffer, 255);
|
|
||||||
tmp = tmp_buffer;
|
|
||||||
tmp_vec.push_back(tmp);
|
|
||||||
}
|
|
||||||
if (_ListOfModels != tmp_vec && !only_camera) {
|
|
||||||
CloseFile();
|
|
||||||
vector<string> pathnames;
|
|
||||||
int err = 0;
|
|
||||||
for (vector<string>::const_iterator i = tmp_vec.begin(); i != tmp_vec.end(); i++)
|
|
||||||
{
|
|
||||||
pathnames.clear();
|
|
||||||
StringUtils::getPathName(ViewMapIO::Options::getModelsPath(), *i, pathnames);
|
|
||||||
for (vector<string>::const_iterator j = pathnames.begin(); j != pathnames.end(); j++)
|
|
||||||
if (!(err = Load3DSFile(j->c_str())))
|
|
||||||
break;
|
|
||||||
if (err) {
|
|
||||||
cerr << "Error: cannot find model \"" << *i << "\" - check the path in the Options" << endl;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set the camera position
|
|
||||||
float position[3];
|
|
||||||
float orientation[4];
|
|
||||||
ifs.read((char*)position, 3 * sizeof(*position));
|
|
||||||
ifs.read((char*)orientation, 4 * sizeof(*orientation));
|
|
||||||
_pView->setCameraState(position, orientation);
|
|
||||||
_pView->saveCameraState();
|
|
||||||
|
|
||||||
if (only_camera) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reset ViewMap
|
|
||||||
if(NULL != _ViewMap)
|
|
||||||
{
|
|
||||||
delete _ViewMap;
|
|
||||||
_ViewMap = 0;
|
|
||||||
}
|
|
||||||
_pView->DetachSilhouette();
|
|
||||||
if (NULL != _SilhouetteNode)
|
|
||||||
{
|
|
||||||
int ref = _SilhouetteNode->destroy();
|
|
||||||
if(0 == ref)
|
|
||||||
delete _SilhouetteNode;
|
|
||||||
}
|
|
||||||
// if(NULL != _ProjectedSilhouette)
|
|
||||||
// {
|
// {
|
||||||
// int ref = _ProjectedSilhouette->destroy();
|
// ifstream ifs(iFileName, ios::binary);
|
||||||
// if(0 == ref)
|
// if (!ifs.is_open()) {
|
||||||
// delete _ProjectedSilhouette;
|
// cerr << "Error: Cannot load this file" << endl;
|
||||||
|
// return;
|
||||||
// }
|
// }
|
||||||
// if(NULL != _VisibleProjectedSilhouette)
|
// // char buffer[buffer_size];
|
||||||
// {
|
// // #if defined(__GNUC__) && (__GNUC__ < 3)
|
||||||
// int ref = _VisibleProjectedSilhouette->destroy();
|
// // ifs.rdbuf()->setbuf(buffer, buffer_size);
|
||||||
// if(0 == ref)
|
// // # else
|
||||||
// {
|
// // ifs.rdbuf()->pubsetbuf(buffer, buffer_size);
|
||||||
// delete _VisibleProjectedSilhouette;
|
// // #endif
|
||||||
// _VisibleProjectedSilhouette = 0;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
_ViewMap = new ViewMap();
|
|
||||||
|
|
||||||
// Read ViewMap
|
|
||||||
_Chrono.start();
|
|
||||||
if (ViewMapIO::load(ifs, _ViewMap, 0)) {
|
|
||||||
_Chrono.stop();
|
|
||||||
|
|
||||||
cerr << "Error: This is not a valid ." << Config::VIEWMAP_EXTENSION << " file" << endl;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update display
|
|
||||||
ViewMapTesselator3D sTesselator3d;
|
|
||||||
//ViewMapTesselator2D sTesselator2d;
|
|
||||||
//sTesselator2d.SetNature(_edgeTesselationNature);
|
|
||||||
sTesselator3d.SetNature(_edgeTesselationNature);
|
|
||||||
|
|
||||||
// Tesselate the 3D edges:
|
|
||||||
_SilhouetteNode = sTesselator3d.Tesselate(_ViewMap);
|
|
||||||
_SilhouetteNode->addRef();
|
|
||||||
|
|
||||||
// Tesselate 2D edges
|
|
||||||
// _ProjectedSilhouette = sTesselator2d.Tesselate(_ViewMap);
|
|
||||||
// _ProjectedSilhouette->addRef();
|
|
||||||
//
|
//
|
||||||
_pView->AddSilhouette(_SilhouetteNode);
|
// // Test File Magic and version
|
||||||
//_pView->Add2DSilhouette(_ProjectedSilhouette);
|
// char tmp_buffer[256];
|
||||||
|
// string test;
|
||||||
// Update options window
|
//
|
||||||
//_pOptionsWindow->updateViewMapFormat();
|
// ifs.getline(tmp_buffer, 255);
|
||||||
|
// test = tmp_buffer;
|
||||||
real d = _Chrono.stop();
|
// if (test != Config::VIEWMAP_MAGIC) {
|
||||||
cout << "ViewMap loading : " << d << endl;
|
// cerr << "Error: This is not a valid ." << Config::VIEWMAP_EXTENSION << " file" << endl;
|
||||||
|
// return;
|
||||||
// Compute the Directional ViewMap:
|
// }
|
||||||
if(_ComputeSteerableViewMap){
|
// ifs.getline(tmp_buffer, 255);
|
||||||
ComputeSteerableViewMap();
|
// test = tmp_buffer;
|
||||||
}
|
// if (test != Config::VIEWMAP_VERSION && !only_camera) {
|
||||||
|
// cerr << "Error: This version of the ." << Config::VIEWMAP_EXTENSION << " file format is no longer supported" << endl;
|
||||||
// Reset Style modules modification flags
|
// return;
|
||||||
resetModified(true);
|
// }
|
||||||
}
|
//
|
||||||
|
// // Read the models filenames and open them (if not already done)
|
||||||
|
// string tmp;
|
||||||
|
// vector<string> tmp_vec;
|
||||||
|
// unsigned models_nb, i;
|
||||||
|
//
|
||||||
|
// ifs.getline(tmp_buffer, 255);
|
||||||
|
// models_nb = atoi(tmp_buffer);
|
||||||
|
// for (i = 0; i < models_nb; i++) {
|
||||||
|
// ifs.getline(tmp_buffer, 255);
|
||||||
|
// tmp = tmp_buffer;
|
||||||
|
// tmp_vec.push_back(tmp);
|
||||||
|
// }
|
||||||
|
// if (_ListOfModels != tmp_vec && !only_camera) {
|
||||||
|
// CloseFile();
|
||||||
|
// vector<string> pathnames;
|
||||||
|
// int err = 0;
|
||||||
|
// for (vector<string>::const_iterator i = tmp_vec.begin(); i != tmp_vec.end(); i++)
|
||||||
|
// {
|
||||||
|
// pathnames.clear();
|
||||||
|
// StringUtils::getPathName(ViewMapIO::Options::getModelsPath(), *i, pathnames);
|
||||||
|
// for (vector<string>::const_iterator j = pathnames.begin(); j != pathnames.end(); j++)
|
||||||
|
// if (!(err = Load3DSFile(j->c_str())))
|
||||||
|
// break;
|
||||||
|
// if (err) {
|
||||||
|
// cerr << "Error: cannot find model \"" << *i << "\" - check the path in the Options" << endl;
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// // Set the camera position
|
||||||
|
// float position[3];
|
||||||
|
// float orientation[4];
|
||||||
|
// ifs.read((char*)position, 3 * sizeof(*position));
|
||||||
|
// ifs.read((char*)orientation, 4 * sizeof(*orientation));
|
||||||
|
// _pView->setCameraState(position, orientation);
|
||||||
|
// _pView->saveCameraState();
|
||||||
|
//
|
||||||
|
// if (only_camera) {
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// // Reset ViewMap
|
||||||
|
// if(NULL != _ViewMap)
|
||||||
|
// {
|
||||||
|
// delete _ViewMap;
|
||||||
|
// _ViewMap = 0;
|
||||||
|
// }
|
||||||
|
// _pView->DetachSilhouette();
|
||||||
|
// if (NULL != _SilhouetteNode)
|
||||||
|
// {
|
||||||
|
// int ref = _SilhouetteNode->destroy();
|
||||||
|
// if(0 == ref)
|
||||||
|
// delete _SilhouetteNode;
|
||||||
|
// }
|
||||||
|
// // if(NULL != _ProjectedSilhouette)
|
||||||
|
// // {
|
||||||
|
// // int ref = _ProjectedSilhouette->destroy();
|
||||||
|
// // if(0 == ref)
|
||||||
|
// // delete _ProjectedSilhouette;
|
||||||
|
// // }
|
||||||
|
// // if(NULL != _VisibleProjectedSilhouette)
|
||||||
|
// // {
|
||||||
|
// // int ref = _VisibleProjectedSilhouette->destroy();
|
||||||
|
// // if(0 == ref)
|
||||||
|
// // {
|
||||||
|
// // delete _VisibleProjectedSilhouette;
|
||||||
|
// // _VisibleProjectedSilhouette = 0;
|
||||||
|
// // }
|
||||||
|
// // }
|
||||||
|
// _ViewMap = new ViewMap();
|
||||||
|
//
|
||||||
|
// // Read ViewMap
|
||||||
|
// _Chrono.start();
|
||||||
|
// if (ViewMapIO::load(ifs, _ViewMap, 0)) {
|
||||||
|
// _Chrono.stop();
|
||||||
|
//
|
||||||
|
// cerr << "Error: This is not a valid ." << Config::VIEWMAP_EXTENSION << " file" << endl;
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// // Update display
|
||||||
|
// ViewMapTesselator3D sTesselator3d;
|
||||||
|
// //ViewMapTesselator2D sTesselator2d;
|
||||||
|
// //sTesselator2d.SetNature(_edgeTesselationNature);
|
||||||
|
// sTesselator3d.SetNature(_edgeTesselationNature);
|
||||||
|
//
|
||||||
|
// // Tesselate the 3D edges:
|
||||||
|
// _SilhouetteNode = sTesselator3d.Tesselate(_ViewMap);
|
||||||
|
// _SilhouetteNode->addRef();
|
||||||
|
//
|
||||||
|
// // Tesselate 2D edges
|
||||||
|
// // _ProjectedSilhouette = sTesselator2d.Tesselate(_ViewMap);
|
||||||
|
// // _ProjectedSilhouette->addRef();
|
||||||
|
// //
|
||||||
|
// _pView->AddSilhouette(_SilhouetteNode);
|
||||||
|
// //_pView->Add2DSilhouette(_ProjectedSilhouette);
|
||||||
|
//
|
||||||
|
// // Update options window
|
||||||
|
// //_pOptionsWindow->updateViewMapFormat();
|
||||||
|
//
|
||||||
|
// real d = _Chrono.stop();
|
||||||
|
// cout << "ViewMap loading : " << d << endl;
|
||||||
|
//
|
||||||
|
// // Compute the Directional ViewMap:
|
||||||
|
// if(_ComputeSteerableViewMap){
|
||||||
|
// ComputeSteerableViewMap();
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// // Reset Style modules modification flags
|
||||||
|
// resetModified(true);
|
||||||
|
// }
|
||||||
|
|
||||||
void Controller::ComputeViewMap()
|
void Controller::ComputeViewMap()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -35,26 +35,41 @@ extern "C" {
|
|||||||
|
|
||||||
if( view == NULL )
|
if( view == NULL )
|
||||||
view = new AppGLWidget;
|
view = new AppGLWidget;
|
||||||
|
|
||||||
|
controller->SetView(view);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FRS_execute(Render* re) {
|
void FRS_execute(Render* re) {
|
||||||
|
|
||||||
|
// instanciation
|
||||||
Config::Path pathconfig;
|
Config::Path pathconfig;
|
||||||
FRS_initialize();
|
FRS_initialize();
|
||||||
|
|
||||||
controller->SetView(view);
|
// initialize view dimensions
|
||||||
unsigned int width = re->winx;
|
unsigned int width = re->winx;
|
||||||
unsigned int height = re->winy;
|
unsigned int height = re->winy;
|
||||||
view->setWidth(width);
|
view->setWidth(width);
|
||||||
view->setHeight(height);
|
view->setHeight(height);
|
||||||
view->_camera->setScreenWidthAndHeight(width, height);
|
view->_camera->setScreenWidthAndHeight(width, height);
|
||||||
//view->setCameraState(const float* position, const float* orientation)
|
|
||||||
|
|
||||||
|
// initialize camera
|
||||||
|
Object* maincam_obj = re->scene->camera;
|
||||||
|
Vec camPosition(maincam_obj->obmat[3][0], maincam_obj->obmat[3][1], maincam_obj->obmat[3][2]);
|
||||||
|
Vec camUp( re->viewmat[0][1], re->viewmat[1][1], re->viewmat[2][1]);
|
||||||
|
Vec camDirection( -re->viewmat[0][2], -re->viewmat[1][2], - re->viewmat[2][2]);
|
||||||
|
|
||||||
|
view->_camera->setType(Camera::PERSPECTIVE);
|
||||||
|
view->_camera->setPosition(camPosition);
|
||||||
|
view->_camera->setUpVector(camUp);
|
||||||
|
view->_camera->setViewDirection(camDirection);
|
||||||
|
|
||||||
|
// export scene to 3ds format
|
||||||
string script_3ds_export = pathconfig.getProjectDir() +
|
string script_3ds_export = pathconfig.getProjectDir() +
|
||||||
Config::DIR_SEP + "python" +
|
Config::DIR_SEP + "python" +
|
||||||
Config::DIR_SEP + "3ds_export.py";
|
Config::DIR_SEP + "3ds_export.py";
|
||||||
BPY_run_python_script( const_cast<char *>(script_3ds_export.c_str()) );
|
BPY_run_python_script( const_cast<char *>(script_3ds_export.c_str()) );
|
||||||
|
|
||||||
|
// load 3ds scene
|
||||||
char btempdir[255];
|
char btempdir[255];
|
||||||
BLI_where_is_temp(btempdir,1);
|
BLI_where_is_temp(btempdir,1);
|
||||||
string exported_3ds_file = btempdir;
|
string exported_3ds_file = btempdir;
|
||||||
@@ -67,22 +82,30 @@ extern "C" {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// add style module
|
||||||
string style_module = pathconfig.getProjectDir() +
|
string style_module = pathconfig.getProjectDir() +
|
||||||
Config::DIR_SEP + "style_modules" +
|
Config::DIR_SEP + "style_modules" +
|
||||||
Config::DIR_SEP + "contour.py";
|
Config::DIR_SEP + "contour.py";
|
||||||
controller->InsertStyleModule( 0, const_cast<char *>(style_module.c_str()) );
|
controller->InsertStyleModule( 0, const_cast<char *>(style_module.c_str()) );
|
||||||
controller->toggleLayer(0, true);
|
controller->toggleLayer(0, true);
|
||||||
|
|
||||||
|
// compute view map
|
||||||
controller->ComputeViewMap();
|
controller->ComputeViewMap();
|
||||||
|
|
||||||
controller->DrawStrokes(); // build strokes
|
// build strokes
|
||||||
view->draw(); // render final result
|
controller->DrawStrokes();
|
||||||
|
|
||||||
|
// render final result
|
||||||
|
view->draw();
|
||||||
|
|
||||||
|
// copy result into render window
|
||||||
RenderResult rres;
|
RenderResult rres;
|
||||||
RE_GetResultImage(re, &rres);
|
RE_GetResultImage(re, &rres);
|
||||||
view->readPixels(0,0,width,height,AppGLWidget::RGBA, rres.rectf );
|
view->readPixels(0,0,width,height,AppGLWidget::RGBA, rres.rectf );
|
||||||
re->result->renlay = render_get_active_layer(re, re->result);
|
re->result->renlay = render_get_active_layer(re, re->result);
|
||||||
re->display_draw(re->result, NULL);
|
re->display_draw(re->result, NULL);
|
||||||
|
|
||||||
|
controller->CloseFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|||||||
@@ -2194,14 +2194,26 @@ static void do_render_composite_fields_blur_3d(Render *re)
|
|||||||
|
|
||||||
static void freestyleRender(Render *re)
|
static void freestyleRender(Render *re)
|
||||||
{
|
{
|
||||||
|
float mat[4][4];
|
||||||
|
|
||||||
|
// init render result
|
||||||
RE_FreeRenderResult(re->result);
|
RE_FreeRenderResult(re->result);
|
||||||
re->result = new_render_result(re, &re->disprect, 0, RR_USEMEM);
|
re->result = new_render_result(re, &re->disprect, 0, RR_USEMEM);
|
||||||
|
|
||||||
|
// set camera
|
||||||
RE_SetCamera(re, re->scene->camera);
|
RE_SetCamera(re, re->scene->camera);
|
||||||
|
|
||||||
FRS_execute(re);
|
// set view
|
||||||
|
Mat4Ortho(re->scene->camera->obmat);
|
||||||
|
Mat4Invert(mat, re->scene->camera->obmat);
|
||||||
|
RE_SetView(re, mat);
|
||||||
|
|
||||||
|
// run Freestyle
|
||||||
|
re->i.starttime = PIL_check_seconds_timer();
|
||||||
|
FRS_execute(re);
|
||||||
|
re->i.lastframetime = PIL_check_seconds_timer()- re->i.starttime;
|
||||||
re->stats_draw(&re->i);
|
re->stats_draw(&re->i);
|
||||||
|
|
||||||
RE_Database_Free(re);
|
RE_Database_Free(re);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user