2008-05-25 17:34:21 +00:00
|
|
|
#include "AppGLWidget.h"
|
2008-05-19 05:34:31 +00:00
|
|
|
#include "Controller.h"
|
2008-05-25 17:34:21 +00:00
|
|
|
#include "AppConfig.h"
|
|
|
|
|
|
2008-05-19 05:34:31 +00:00
|
|
|
#include <iostream>
|
|
|
|
|
|
2008-05-29 00:27:09 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
extern "C" {
|
|
|
|
|
#endif
|
|
|
|
|
|
2008-07-02 12:16:36 +00:00
|
|
|
#include "DNA_camera_types.h"
|
|
|
|
|
|
2008-05-29 00:27:09 +00:00
|
|
|
#include "render_types.h"
|
|
|
|
|
#include "renderpipeline.h"
|
|
|
|
|
|
2008-06-08 19:35:20 +00:00
|
|
|
#include "BLI_blenlib.h"
|
2008-08-07 15:04:25 +00:00
|
|
|
#include "BIF_renderwin.h"
|
2008-06-08 19:35:20 +00:00
|
|
|
#include "BPY_extern.h"
|
|
|
|
|
|
2008-05-29 00:27:09 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2008-05-19 05:34:31 +00:00
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
extern "C" {
|
|
|
|
|
#endif
|
|
|
|
|
|
2008-07-04 07:59:19 +00:00
|
|
|
static Config::Path *pathconfig = NULL;
|
2008-06-08 19:35:20 +00:00
|
|
|
static Controller *controller = NULL;
|
|
|
|
|
static AppGLWidget *view = NULL;
|
2008-07-04 07:59:19 +00:00
|
|
|
|
2008-07-31 11:20:30 +00:00
|
|
|
char style_module[255] = "";
|
|
|
|
|
|
2008-06-08 19:35:20 +00:00
|
|
|
void FRS_initialize(){
|
2008-05-25 17:34:21 +00:00
|
|
|
|
2008-07-04 07:59:19 +00:00
|
|
|
if( pathconfig == NULL )
|
|
|
|
|
pathconfig = new Config::Path;
|
|
|
|
|
|
2008-06-08 19:35:20 +00:00
|
|
|
if( controller == NULL )
|
|
|
|
|
controller = new Controller;
|
|
|
|
|
|
2008-10-01 15:03:35 +00:00
|
|
|
if( view == NULL ) {
|
2008-06-08 19:35:20 +00:00
|
|
|
view = new AppGLWidget;
|
2008-10-01 15:03:35 +00:00
|
|
|
controller->setView(view);
|
|
|
|
|
}
|
2008-07-31 11:20:30 +00:00
|
|
|
|
|
|
|
|
if( strlen(style_module) == 0 ){
|
2008-09-29 15:50:50 +00:00
|
|
|
string path( pathconfig->getProjectDir() + Config::DIR_SEP + "style_modules" + Config::DIR_SEP + "contour.py" );
|
2008-07-31 11:20:30 +00:00
|
|
|
strcpy( style_module, path.c_str() );
|
|
|
|
|
}
|
|
|
|
|
|
2008-06-08 19:35:20 +00:00
|
|
|
}
|
|
|
|
|
|
2008-07-04 07:59:19 +00:00
|
|
|
|
|
|
|
|
void FRS_init_view(Render* re){
|
|
|
|
|
view->setWidth( re->winx );
|
|
|
|
|
view->setHeight( re->winy );
|
|
|
|
|
view->_camera->setScreenWidthAndHeight( re->winx, re->winy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FRS_init_camera(Render* re){
|
2008-06-16 00:51:19 +00:00
|
|
|
Object* maincam_obj = re->scene->camera;
|
2008-07-02 12:16:36 +00:00
|
|
|
Camera *cam = (Camera*) maincam_obj->data;
|
|
|
|
|
|
|
|
|
|
if(cam->type == CAM_PERSP){
|
|
|
|
|
view->_camera->setType(AppGLWidget_Camera::PERSPECTIVE);
|
|
|
|
|
view->_camera->setHorizontalFieldOfView( M_PI / 180.0f * cam->angle );
|
|
|
|
|
}
|
2008-07-04 07:59:19 +00:00
|
|
|
// else if (cam->type == CAM_ORTHO){
|
|
|
|
|
// view->_camera->setType(AppGLWidget_Camera::ORTHOGRAPHIC);
|
|
|
|
|
// // view->_camera->setFocusDistance does not seem to work
|
|
|
|
|
// // integrate cam->ortho_scale parameter
|
|
|
|
|
// }
|
2008-07-02 12:16:36 +00:00
|
|
|
|
2008-06-16 00:51:19 +00:00
|
|
|
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]);
|
2008-07-02 12:16:36 +00:00
|
|
|
Vec camDirection( -re->viewmat[0][2], -re->viewmat[1][2], -re->viewmat[2][2]);
|
2008-06-16 00:51:19 +00:00
|
|
|
view->_camera->setPosition(camPosition);
|
|
|
|
|
view->_camera->setUpVector(camUp);
|
2008-07-04 07:59:19 +00:00
|
|
|
view->_camera->setViewDirection(camDirection);
|
|
|
|
|
}
|
2008-10-01 15:03:35 +00:00
|
|
|
|
2008-08-07 15:04:25 +00:00
|
|
|
|
2008-07-04 07:59:19 +00:00
|
|
|
void FRS_prepare(Render* re) {
|
|
|
|
|
|
2008-10-01 15:03:35 +00:00
|
|
|
// init
|
|
|
|
|
FRS_initialize();
|
2008-07-04 07:59:19 +00:00
|
|
|
FRS_init_view(re);
|
|
|
|
|
FRS_init_camera(re);
|
2008-10-01 15:03:35 +00:00
|
|
|
controller->Clear();
|
2008-08-08 08:53:13 +00:00
|
|
|
|
2008-10-01 15:03:35 +00:00
|
|
|
// load mesh
|
|
|
|
|
controller->LoadMesh(re);
|
2008-07-05 06:22:15 +00:00
|
|
|
|
2008-06-16 00:51:19 +00:00
|
|
|
// add style module
|
2008-07-31 11:20:30 +00:00
|
|
|
cout << "Module: " << style_module << endl;
|
|
|
|
|
controller->InsertStyleModule( 0, style_module );
|
2008-06-08 19:35:20 +00:00
|
|
|
controller->toggleLayer(0, true);
|
2008-06-16 00:51:19 +00:00
|
|
|
|
|
|
|
|
// compute view map
|
2008-06-08 19:35:20 +00:00
|
|
|
controller->ComputeViewMap();
|
|
|
|
|
|
2008-06-16 00:51:19 +00:00
|
|
|
// build strokes
|
|
|
|
|
controller->DrawStrokes();
|
2008-05-19 05:34:31 +00:00
|
|
|
}
|
2008-07-04 07:59:19 +00:00
|
|
|
|
2008-10-01 15:03:35 +00:00
|
|
|
void FRS_render_GL(Render* re) {
|
2008-07-12 04:02:08 +00:00
|
|
|
|
2008-10-01 15:03:35 +00:00
|
|
|
cout << "Rendering Freestyle with OpenGL" << endl;
|
2008-07-05 06:22:15 +00:00
|
|
|
|
2008-10-01 15:03:35 +00:00
|
|
|
// render strokes
|
|
|
|
|
view->workingBuffer = GL_BACK;
|
|
|
|
|
view->draw();
|
|
|
|
|
|
|
|
|
|
// display result
|
|
|
|
|
RenderResult rres;
|
|
|
|
|
RE_GetResultImage(re, &rres);
|
|
|
|
|
view->readPixels(0, 0, re->winx, re->winy, AppGLWidget::RGBA, rres.rectf );
|
|
|
|
|
re->result->renlay = render_get_active_layer(re, re->result);
|
|
|
|
|
re->display_draw(re->result, NULL);
|
|
|
|
|
|
2008-07-05 06:22:15 +00:00
|
|
|
controller->CloseFile();
|
2008-07-04 07:59:19 +00:00
|
|
|
}
|
2008-05-19 05:34:31 +00:00
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
}
|
|
|
|
|
#endif
|