From dfa10eba19012fb7a20233a3d434c67f32de10db Mon Sep 17 00:00:00 2001 From: Maxime Curioni Date: Mon, 16 Jun 2008 00:51:19 +0000 Subject: 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. --- .../freestyle/intern/app_blender/AppGLWidget.cpp | 2 +- .../freestyle/intern/app_blender/AppGLWidget.h | 6 +- .../freestyle/intern/app_blender/Controller.cpp | 288 ++++++++++----------- .../blender/freestyle/intern/app_blender/api.cpp | 33 ++- 4 files changed, 176 insertions(+), 153 deletions(-) (limited to 'source/blender/freestyle/intern/app_blender') diff --git a/source/blender/freestyle/intern/app_blender/AppGLWidget.cpp b/source/blender/freestyle/intern/app_blender/AppGLWidget.cpp index a06e25d72be..34a96681c50 100755 --- a/source/blender/freestyle/intern/app_blender/AppGLWidget.cpp +++ b/source/blender/freestyle/intern/app_blender/AppGLWidget.cpp @@ -130,7 +130,7 @@ AppGLWidget::AppGLWidget(const char *iName) _debug = false; _selection_mode = false; _Draw2DScene = true; - _Draw3DScene = true; + _Draw3DScene = false; _drawEnvMap = false; _currentEnvMap = 1; _maxId = 0; diff --git a/source/blender/freestyle/intern/app_blender/AppGLWidget.h b/source/blender/freestyle/intern/app_blender/AppGLWidget.h index 319fc248494..175eb67ba69 100755 --- a/source/blender/freestyle/intern/app_blender/AppGLWidget.h +++ b/source/blender/freestyle/intern/app_blender/AppGLWidget.h @@ -401,9 +401,9 @@ public: inline bool getRecordFlag() const {return _record;} - void setCameraState(const float* position, const float* orientation) { - _camera->setPosition(Vec(position[0], position[1], position[2])); - _camera->setOrientation(Quaternion(orientation[0], orientation[1], orientation[2], orientation[3])); + void setCameraState(const Vec& position, const Quaternion& orientation) { + _camera->setPosition(position); + _camera->setOrientation(orientation); } void getCameraState(float* position, float* orientation) const { diff --git a/source/blender/freestyle/intern/app_blender/Controller.cpp b/source/blender/freestyle/intern/app_blender/Controller.cpp index 9abf082d5cc..9a820b835ca 100755 --- a/source/blender/freestyle/intern/app_blender/Controller.cpp +++ b/source/blender/freestyle/intern/app_blender/Controller.cpp @@ -209,7 +209,7 @@ int Controller::Load3DSFile(const char *iFileName) _RootNode->UpdateBBox(); // FIXME: Correct that by making a Renderer to compute the bbox _pView->SetModel(_RootNode); - _pView->FitBBox(); + //_pView->FitBBox(); _Chrono.start(); @@ -399,149 +399,149 @@ void Controller::SaveViewMapFile(const char *oFileName) cout << "ViewMap saving : " << d << endl; } -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 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 pathnames; - int err = 0; - for (vector::const_iterator i = tmp_vec.begin(); i != tmp_vec.end(); i++) - { - pathnames.clear(); - StringUtils::getPathName(ViewMapIO::Options::getModelsPath(), *i, pathnames); - for (vector::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::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 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 pathnames; +// int err = 0; +// for (vector::const_iterator i = tmp_vec.begin(); i != tmp_vec.end(); i++) +// { +// pathnames.clear(); +// StringUtils::getPathName(ViewMapIO::Options::getModelsPath(), *i, pathnames); +// for (vector::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() { diff --git a/source/blender/freestyle/intern/app_blender/api.cpp b/source/blender/freestyle/intern/app_blender/api.cpp index 2a7868304ea..ba583080e79 100644 --- a/source/blender/freestyle/intern/app_blender/api.cpp +++ b/source/blender/freestyle/intern/app_blender/api.cpp @@ -35,26 +35,41 @@ extern "C" { if( view == NULL ) view = new AppGLWidget; + + controller->SetView(view); } void FRS_execute(Render* re) { + // instanciation Config::Path pathconfig; FRS_initialize(); - controller->SetView(view); + // initialize view dimensions unsigned int width = re->winx; unsigned int height = re->winy; view->setWidth(width); view->setHeight(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() + Config::DIR_SEP + "python" + Config::DIR_SEP + "3ds_export.py"; BPY_run_python_script( const_cast(script_3ds_export.c_str()) ); + // load 3ds scene char btempdir[255]; BLI_where_is_temp(btempdir,1); string exported_3ds_file = btempdir; @@ -67,22 +82,30 @@ extern "C" { return; } + // add style module string style_module = pathconfig.getProjectDir() + Config::DIR_SEP + "style_modules" + Config::DIR_SEP + "contour.py"; controller->InsertStyleModule( 0, const_cast(style_module.c_str()) ); controller->toggleLayer(0, true); + + // compute view map controller->ComputeViewMap(); - controller->DrawStrokes(); // build strokes - view->draw(); // render final result + // build strokes + controller->DrawStrokes(); + + // render final result + view->draw(); + // copy result into render window RenderResult rres; RE_GetResultImage(re, &rres); view->readPixels(0,0,width,height,AppGLWidget::RGBA, rres.rectf ); re->result->renlay = render_get_active_layer(re, re->result); re->display_draw(re->result, NULL); - + + controller->CloseFile(); } #ifdef __cplusplus -- cgit v1.2.3