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"
|
|
|
|
|
#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-06-08 19:35:20 +00:00
|
|
|
static Controller *controller = NULL;
|
|
|
|
|
static AppGLWidget *view = NULL;
|
2008-06-13 22:23:24 +00:00
|
|
|
|
2008-06-08 19:35:20 +00:00
|
|
|
void FRS_initialize(){
|
2008-05-25 17:34:21 +00:00
|
|
|
|
2008-06-08 19:35:20 +00:00
|
|
|
if( controller == NULL )
|
|
|
|
|
controller = new Controller;
|
|
|
|
|
|
|
|
|
|
if( view == NULL )
|
|
|
|
|
view = new AppGLWidget;
|
2008-06-16 00:51:19 +00:00
|
|
|
|
|
|
|
|
controller->SetView(view);
|
2008-06-08 19:35:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FRS_execute(Render* re) {
|
2008-06-13 22:23:24 +00:00
|
|
|
|
2008-06-16 00:51:19 +00:00
|
|
|
// instanciation
|
2008-06-13 22:23:24 +00:00
|
|
|
Config::Path pathconfig;
|
2008-06-08 19:35:20 +00:00
|
|
|
FRS_initialize();
|
|
|
|
|
|
2008-06-16 00:51:19 +00:00
|
|
|
// initialize view dimensions
|
2008-05-29 00:27:09 +00:00
|
|
|
unsigned int width = re->winx;
|
|
|
|
|
unsigned int height = re->winy;
|
|
|
|
|
view->setWidth(width);
|
|
|
|
|
view->setHeight(height);
|
2008-06-08 19:35:20 +00:00
|
|
|
view->_camera->setScreenWidthAndHeight(width, height);
|
2008-05-28 21:19:56 +00:00
|
|
|
|
2008-06-16 00:51:19 +00:00
|
|
|
// initialize camera
|
|
|
|
|
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 );
|
|
|
|
|
}
|
|
|
|
|
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-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);
|
|
|
|
|
view->_camera->setViewDirection(camDirection);
|
2008-07-02 12:16:36 +00:00
|
|
|
|
2008-06-16 00:51:19 +00:00
|
|
|
|
|
|
|
|
// export scene to 3ds format
|
2008-06-13 22:23:24 +00:00
|
|
|
string script_3ds_export = pathconfig.getProjectDir() +
|
|
|
|
|
Config::DIR_SEP + "python" +
|
|
|
|
|
Config::DIR_SEP + "3ds_export.py";
|
|
|
|
|
BPY_run_python_script( const_cast<char *>(script_3ds_export.c_str()) );
|
2008-05-25 17:34:21 +00:00
|
|
|
|
2008-06-16 00:51:19 +00:00
|
|
|
// load 3ds scene
|
2008-06-08 19:35:20 +00:00
|
|
|
char btempdir[255];
|
|
|
|
|
BLI_where_is_temp(btempdir,1);
|
|
|
|
|
string exported_3ds_file = btempdir;
|
2008-06-13 22:23:24 +00:00
|
|
|
exported_3ds_file += Config::DIR_SEP + "tmp_scene_freestyle.3ds";
|
2008-06-08 19:35:20 +00:00
|
|
|
if( BLI_exists( const_cast<char *>(exported_3ds_file.c_str()) ) ) {
|
|
|
|
|
controller->Load3DSFile( exported_3ds_file.c_str() );
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
cout << "Cannot find" << exported_3ds_file << endl;
|
|
|
|
|
return;
|
|
|
|
|
}
|
2008-05-29 00:27:09 +00:00
|
|
|
|
2008-06-16 00:51:19 +00:00
|
|
|
// add style module
|
2008-06-13 22:23:24 +00:00
|
|
|
string style_module = pathconfig.getProjectDir() +
|
|
|
|
|
Config::DIR_SEP + "style_modules" +
|
|
|
|
|
Config::DIR_SEP + "contour.py";
|
|
|
|
|
controller->InsertStyleModule( 0, const_cast<char *>(style_module.c_str()) );
|
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();
|
|
|
|
|
|
|
|
|
|
// render final result
|
|
|
|
|
view->draw();
|
2008-05-29 11:41:06 +00:00
|
|
|
|
2008-06-16 00:51:19 +00:00
|
|
|
// copy result into render window
|
2008-05-29 00:27:09 +00:00
|
|
|
RenderResult rres;
|
|
|
|
|
RE_GetResultImage(re, &rres);
|
2008-05-29 11:41:06 +00:00
|
|
|
view->readPixels(0,0,width,height,AppGLWidget::RGBA, rres.rectf );
|
2008-05-29 00:27:09 +00:00
|
|
|
re->result->renlay = render_get_active_layer(re, re->result);
|
|
|
|
|
re->display_draw(re->result, NULL);
|
2008-06-16 00:51:19 +00:00
|
|
|
|
|
|
|
|
controller->CloseFile();
|
2008-05-19 05:34:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
}
|
|
|
|
|
#endif
|