diff options
Diffstat (limited to 'source/blender/freestyle/intern/app_blender')
3 files changed, 131 insertions, 8 deletions
diff --git a/source/blender/freestyle/intern/app_blender/Controller.cpp b/source/blender/freestyle/intern/app_blender/Controller.cpp index ff6ca96e657..183695ec731 100755 --- a/source/blender/freestyle/intern/app_blender/Controller.cpp +++ b/source/blender/freestyle/intern/app_blender/Controller.cpp @@ -64,6 +64,8 @@ #include "../system/StringUtils.h" +#include "../scene_graph/BlenderFileLoader.h" + Controller::Controller() { @@ -168,6 +170,107 @@ void Controller::setView(AppGLWidget *iView) _Canvas->setViewer(_pView); } +int Controller::LoadMesh(Render *re) +{ + if (_pView) + _pView->setUpdateMode(false); + + BlenderFileLoader loader(re); + + _Chrono.start(); + + NodeGroup *blenderScene = loader.Load(); + + if (blenderScene == NULL) { + cout << "Cannot load scene" << endl; + return 1; + } + + cout << "Scene loaded\n" << endl; + + printf("Mesh cleaning : %lf\n", _Chrono.stop()); + _SceneNumFaces += loader.numFacesRead(); + + if(loader.minEdgeSize() < _minEdgeSize) + { + _minEdgeSize = loader.minEdgeSize(); + _EPSILON = _minEdgeSize*1e-6; + if(_EPSILON < DBL_MIN) + _EPSILON = 0.0; + } + + cout << "Epsilon computed : " << _EPSILON << endl; + + // DEBUG +// ScenePrettyPrinter spp; +// blenderScene->accept(spp); + + _RootNode->AddChild(blenderScene); + _RootNode->UpdateBBox(); // FIXME: Correct that by making a Renderer to compute the bbox + + _pView->setModel(_RootNode); + //_pView->FitBBox(); + + + _Chrono.start(); + + + WXEdgeBuilder wx_builder; + blenderScene->accept(wx_builder); + _winged_edge = wx_builder.getWingedEdge(); + + printf("WEdge building : %lf\n", _Chrono.stop()); + + _Chrono.start(); + + _Grid.clear(); + Vec3r size; + for(unsigned int i=0; i<3; i++) + { + size[i] = fabs(_RootNode->bbox().getMax()[i] - _RootNode->bbox().getMin()[i]); + size[i] += size[i]/10.0; // let make the grid 1/10 bigger to avoid numerical errors while computing triangles/cells intersections + if(size[i]==0){ + cout << "Warning: the bbox size is 0 in dimension "<<i<<endl; + } + } + _Grid.configure(Vec3r(_RootNode->bbox().getMin() - size / 20.0), size, + _SceneNumFaces); + + // Fill in the grid: + WFillGrid fillGridRenderer(&_Grid, _winged_edge); + fillGridRenderer.fillGrid(); + + printf("Grid building : %lf\n", _Chrono.stop()); + + // DEBUG +// _Grid.displayDebug(); + + _pView->setDebug(_DebugNode); + + //delete stuff + // if(0 != ws_builder) + // { + // delete ws_builder; + // ws_builder = 0; + // } + _pView->updateGL(); + + + //soc QFileInfo qfi(iFileName); + //soc string basename((const char*)qfi.fileName().toAscii().data()); + // char cleaned[FILE_MAX]; + // BLI_strncpy(cleaned, iFileName, FILE_MAX); + // BLI_cleanup_file(NULL, cleaned); + // string basename = StringUtils::toAscii( string(cleaned) ); + + _ListOfModels.push_back("Blender_models"); + + cout << "Triangles nb : " << _SceneNumFaces << endl; + _bboxDiag = (_RootNode->bbox().getMax()-_RootNode->bbox().getMin()).norm(); + cout << "Bounding Box : " << _bboxDiag << endl; + return 0; +} + int Controller::Load3DSFile(const char *iFileName) { @@ -649,6 +752,8 @@ void Controller::ComputeViewMap() _ViewMap = vmBuilder.BuildViewMap(*_winged_edge, _VisibilityAlgo, _EPSILON); _ViewMap->setScene3dBBox(_RootNode->bbox()); + printf("ViewMap edge count : %i\n", _ViewMap->viewedges_size() ); + //Tesselate the 3D edges: _SilhouetteNode = sTesselator3d.Tesselate(_ViewMap); _SilhouetteNode->addRef(); @@ -953,9 +1058,9 @@ NodeGroup * Controller::BuildRep(vector<ViewEdge*>::iterator vedges_begin, vector<ViewEdge*>::iterator vedges_end) { ViewMapTesselator2D tesselator2D; - Material mat; + FrsMaterial mat; mat.setDiffuse(1,1,0.3,1); - tesselator2D.setMaterial(mat); + tesselator2D.setFrsMaterial(mat); return (tesselator2D.Tesselate(vedges_begin, vedges_end)); } diff --git a/source/blender/freestyle/intern/app_blender/Controller.h b/source/blender/freestyle/intern/app_blender/Controller.h index 032e21a1ce5..7b982b7e9a2 100755 --- a/source/blender/freestyle/intern/app_blender/Controller.h +++ b/source/blender/freestyle/intern/app_blender/Controller.h @@ -51,6 +51,16 @@ class AppCanvas; class InteractiveShader; class Shader; +#ifdef __cplusplus +extern "C" { +#endif + + #include "render_types.h" + +#ifdef __cplusplus +} +#endif + class Controller { public: @@ -62,6 +72,7 @@ public: //soc void init_options(); + int LoadMesh( Render *re ); int Load3DSFile(const char *iFileName); void CloseFile(); void LoadViewMapFile(const char *iFileName, bool only_camera = false); diff --git a/source/blender/freestyle/intern/app_blender/api.cpp b/source/blender/freestyle/intern/app_blender/api.cpp index a6490324fbf..01c4cfb1460 100644 --- a/source/blender/freestyle/intern/app_blender/api.cpp +++ b/source/blender/freestyle/intern/app_blender/api.cpp @@ -14,6 +14,7 @@ extern "C" { #include "renderpipeline.h" #include "BLI_blenlib.h" +#include "BIF_renderwin.h" #include "BPY_extern.h" #ifdef __cplusplus @@ -103,6 +104,10 @@ extern "C" { } } + void FRS_load_mesh( Render *re ){ + controller->LoadMesh(re); + } + void FRS_prepare(Render* re) { FRS_initialize(); @@ -110,15 +115,12 @@ extern "C" { FRS_init_camera(re); FRS_scene_3ds_export(re); + //FRS_load_mesh(re); } void FRS_render(Render* re, int render_in_layer) { - if(render_in_layer) { - view->workingBuffer = GL_COLOR_ATTACHMENT1_EXT; - } else { - view->workingBuffer = GL_BACK; - } + view->workingBuffer = GL_BACK; // add style module cout << "Module: " << style_module << endl; @@ -185,8 +187,13 @@ extern "C" { } } else { - FRS_render(re, render_in_layer); + // used to reobtain ogl context after RE_Database_FromScene call + re->display_clear(re->result); + + // render strokes + FRS_render(re, render_in_layer); + // display result RenderResult rres; RE_GetResultImage(re, &rres); view->readPixels(0, 0, re->winx, re->winy, AppGLWidget::RGBA, rres.rectf ); |