2
* ***** BEGIN GPL LICENSE BLOCK *****
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public License
6
* as published by the Free Software Foundation; either version 2
7
* of the License, or (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software Foundation,
16
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
* ***** END GPL LICENSE BLOCK *****
21
/** \file blender/freestyle/intern/application/AppView.cpp
25
/* This header file needs to be included first, in order to avoid a
26
compilation with MinGW (see the commit log of revision 28253) */
28
#include "BLI_jitter.h"
33
#include "Controller.h"
34
#include "AppConfig.h"
36
#include "../view_map/Silhouette.h"
37
#include "../view_map/ViewMap.h"
38
#include "../scene_graph/LineRep.h"
39
#include "../scene_graph/NodeLight.h"
40
#include "../scene_graph/NodeShape.h"
41
#include "../scene_graph/VertexRep.h"
42
#include "../stroke/Canvas.h"
43
#include "../system/StringUtils.h"
46
#include "BLI_blenlib.h"
48
#include "IMB_imbuf.h"
49
#include "IMB_imbuf_types.h"
51
#if 1 // FRS_antialiasing
52
# include "BKE_global.h"
53
# include "DNA_scene_types.h"
56
#include "FRS_freestyle.h"
61
AppView::AppView(const char *iName)
63
_Fovy = DEG2RADF(30.0f);
64
_ModelRootNode = new NodeDrawingStyle;
65
_SilhouetteRootNode = new NodeDrawingStyle;
66
_DebugRootNode = new NodeDrawingStyle;
68
_RootNode.AddChild(_ModelRootNode);
69
_SilhouetteRootNode->setStyle(DrawingStyle::LINES);
70
_SilhouetteRootNode->setLightingEnabled(false);
71
_SilhouetteRootNode->setLineWidth(2.0f);
72
_SilhouetteRootNode->setPointSize(3.0f);
74
_RootNode.AddChild(_SilhouetteRootNode);
76
_DebugRootNode->setStyle(DrawingStyle::LINES);
77
_DebugRootNode->setLightingEnabled(false);
78
_DebugRootNode->setLineWidth(1.0f);
80
_RootNode.AddChild(_DebugRootNode);
82
_minBBox = std::min(std::min(_ModelRootNode->bbox().getMin()[0], _ModelRootNode->bbox().getMin()[1]),
83
_ModelRootNode->bbox().getMin()[2]);
84
_maxBBox = std::max(std::max(_ModelRootNode->bbox().getMax()[0], _ModelRootNode->bbox().getMax()[1]),
85
_ModelRootNode->bbox().getMax()[2]);
87
_maxAbs = std::max(rabs(_minBBox), rabs(_maxBBox));
88
_minAbs = std::min(rabs(_minBBox), rabs(_maxBBox));
90
_p2DSelectionNode = new NodeDrawingStyle;
91
_p2DSelectionNode->setLightingEnabled(false);
92
_p2DSelectionNode->setStyle(DrawingStyle::LINES);
93
_p2DSelectionNode->setLineWidth(5.0f);
95
_p2DNode.AddChild(_p2DSelectionNode);
97
NodeLight *light = new NodeLight;
98
_Light.AddChild(light);
103
/*int ref =*/ /* UNUSED */ _RootNode.destroy();
106
/*ref =*/ /* UNUSED */ _p2DNode.destroy();
109
real AppView::distanceToSceneCenter()
111
BBox<Vec3r> bbox = _ModelRootNode->bbox();
113
Vec3r v(freestyle_viewpoint[0], freestyle_viewpoint[1], freestyle_viewpoint[2]);
114
v -= 0.5 * (bbox.getMin() + bbox.getMax());
119
real AppView::znear()
121
BBox<Vec3r> bbox = _ModelRootNode->bbox();
122
Vec3r u = bbox.getMin();
123
Vec3r v = bbox.getMax();
124
Vec3r cameraCenter(freestyle_viewpoint[0], freestyle_viewpoint[1], freestyle_viewpoint[2]);
126
Vec3r w1(u[0], u[1], u[2]);
127
Vec3r w2(v[0], u[1], u[2]);
128
Vec3r w3(u[0], v[1], u[2]);
129
Vec3r w4(v[0], v[1], u[2]);
130
Vec3r w5(u[0], u[1], v[2]);
131
Vec3r w6(v[0], u[1], v[2]);
132
Vec3r w7(u[0], v[1], v[2]);
133
Vec3r w8(v[0], v[1], v[2]);
135
real _znear = std::min((w1 - cameraCenter).norm(),
136
std::min((w2 - cameraCenter).norm(),
137
std::min((w3 - cameraCenter).norm(),
138
std::min((w4 - cameraCenter).norm(),
139
std::min((w5 - cameraCenter).norm(),
140
std::min((w6 - cameraCenter).norm(),
141
std::min((w7 - cameraCenter).norm(),
142
(w8 - cameraCenter).norm()
151
return std::max(_znear, 0.001);
156
BBox<Vec3r> bbox = _ModelRootNode->bbox();
157
Vec3r u = bbox.getMin();
158
Vec3r v = bbox.getMax();
159
Vec3r cameraCenter(freestyle_viewpoint[0], freestyle_viewpoint[1], freestyle_viewpoint[2]);
161
Vec3r w1(u[0], u[1], u[2]);
162
Vec3r w2(v[0], u[1], u[2]);
163
Vec3r w3(u[0], v[1], u[2]);
164
Vec3r w4(v[0], v[1], u[2]);
165
Vec3r w5(u[0], u[1], v[2]);
166
Vec3r w6(v[0], u[1], v[2]);
167
Vec3r w7(u[0], v[1], v[2]);
168
Vec3r w8(v[0], v[1], v[2]);
170
real _zfar = std::max((w1 - cameraCenter).norm(),
171
std::max((w2 - cameraCenter).norm(),
172
std::max((w3 - cameraCenter).norm(),
173
std::max((w4 - cameraCenter).norm(),
174
std::max((w5 - cameraCenter).norm(),
175
std::max((w6 - cameraCenter).norm(),
176
std::max((w7 - cameraCenter).norm(),
177
(w8 - cameraCenter).norm()
189
real AppView::GetFocalLength()
191
real Near = std::max(0.1, (real)(-2.0f * _maxAbs + distanceToSceneCenter()));
195
} /* namespace Freestyle */