Welcome to mirror list, hosted at ThFree Co, Russian Federation.

api.cpp « app_blender « intern « freestyle « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 233fe26a38d5c1f7e79a9dca0d1c5164e155288d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#include "AppView.h"
#include "Controller.h"
#include "AppConfig.h"
#include "AppCanvas.h"

#include <iostream>

#ifdef __cplusplus
extern "C" {
#endif

#include "../../FRS_freestyle.h"

#include "DNA_camera_types.h"
#include "DNA_scene_types.h"

#include "render_types.h"
#include "renderpipeline.h"

#include "BLI_blenlib.h"
#include "BIF_renderwin.h"
#include "BPY_extern.h"

#ifdef __cplusplus
}
#endif

using namespace std;

#ifdef __cplusplus
extern "C" {
#endif

	static Config::Path *pathconfig = NULL;
	static Controller *controller = NULL;
	static AppView *view = NULL;

	char style_module[255] = "";
	int freestyle_flags;
	float freestyle_sphere_radius = 1.0;
	float freestyle_dkr_epsilon = 0.001;
	
	float freestyle_viewpoint[3];
	float freestyle_mv[4][4];
	float freestyle_proj[4][4];
	int freestyle_viewport[4];

	void FRS_initialize(){
		
		if( pathconfig == NULL )
			pathconfig = new Config::Path;
		
		if( controller == NULL )
			controller = new Controller;
		
		if( view == NULL ) {
			view = new AppView;
			controller->setView(view);
		}
		
		if( strlen(style_module) == 0 ){
			string path( pathconfig->getProjectDir() +  Config::DIR_SEP + "style_modules" + Config::DIR_SEP + "contour.py" );
			strcpy( style_module, path.c_str() );
		}
		
	}


	void FRS_init_view(Render* re){
		int width = re->scene->r.xsch;
		int height = re->scene->r.ysch;
		
		freestyle_viewport[0] = freestyle_viewport[1] = 0;
		freestyle_viewport[2] = width;
		freestyle_viewport[3] = height;
		
		view->setWidth( width );
		view->setHeight( height );
	}

	void FRS_init_camera(Render* re){
		Object* maincam_obj = re->scene->camera;
		Camera *cam = (Camera*) maincam_obj->data;

		view->setHorizontalFov( cam->angle );
		
		freestyle_viewpoint[0] = maincam_obj->obmat[3][0];
		freestyle_viewpoint[1] = maincam_obj->obmat[3][1];
		freestyle_viewpoint[2] = maincam_obj->obmat[3][2];
		
		freestyle_mv[0][0] = maincam_obj->obmat[0][0];
		freestyle_mv[0][1] = maincam_obj->obmat[1][0];
		freestyle_mv[0][2] = maincam_obj->obmat[2][0];
		freestyle_mv[0][3] = 0.0;

		freestyle_mv[1][0] = maincam_obj->obmat[0][1];
		freestyle_mv[1][1] = maincam_obj->obmat[1][1];
		freestyle_mv[1][2] = maincam_obj->obmat[2][1];
		freestyle_mv[1][3] = 0.0;

		freestyle_mv[2][0] = re->viewmat[2][0];
		freestyle_mv[2][1] = re->viewmat[2][1];
		freestyle_mv[2][2] = re->viewmat[2][2];
		freestyle_mv[2][3] = 0.0;

		freestyle_mv[3][0] = re->viewmat[3][0];
		freestyle_mv[3][1] = re->viewmat[3][1];
		freestyle_mv[3][2] = re->viewmat[3][2];
		freestyle_mv[3][3] = 1.0;

		for( int i = 0; i < 4; i++ )
		   for( int j = 0; j < 4; j++ )
			freestyle_proj[i][j] = re->winmat[i][j];
	}

	
	void FRS_prepare(Render* re) {
		
		// init
		FRS_initialize();
		FRS_init_view(re);
		FRS_init_camera(re);
		controller->Clear();

		// load mesh
		if( controller->LoadMesh(re) ) // returns if scene cannot be loaded or if empty
			return;
		
		// add style module
			cout << "\n===  Rendering options  ===" << endl;
		cout << "Module: " << style_module << endl;
		controller->InsertStyleModule( 0, style_module );
		controller->toggleLayer(0, true);
		
		// set parameters
		controller->setSphereRadius(freestyle_sphere_radius);
		controller->setComputeRidgesAndValleysFlag((freestyle_flags & FREESTYLE_RIDGES_AND_VALLEYS_FLAG) ? true : false);
		controller->setComputeSuggestiveContoursFlag((freestyle_flags & FREESTYLE_SUGGESTIVE_CONTOURS_FLAG) ? true : false);
		controller->setSuggestiveContourKrDerivativeEpsilon(freestyle_dkr_epsilon);

		cout << "Sphere radius : " << controller->getSphereRadius() << endl;
		cout << "Redges and valleys : " << (controller->getComputeRidgesAndValleysFlag() ? "enabled" : "disabled") << endl;
		cout << "Suggestive contours : " << (controller->getComputeSuggestiveContoursFlag() ? "enabled" : "disabled") << endl;
		cout << "Suggestive contour dkr epsilon : " << controller->getSuggestiveContourKrDerivativeEpsilon() << endl;

		// compute view map
		controller->ComputeViewMap();
	}
	
	void FRS_render_Blender(Render* re) {
		
		if( controller->_ViewMap ) {
			cout << "\n===  Rendering Freestyle with Blender's internal renderer  ===" << endl;
			
			// build strokes
			controller->DrawStrokes();

			controller->RenderBlender(re);
			controller->CloseFile();
		} else {
			cout << "Freestyle cannot be used because the view map is not available" << endl;
		}
		cout << "\n###################################################################" << endl;
	}	
	
#ifdef __cplusplus
}
#endif