OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * ***** BEGIN GPL LICENSE BLOCK ***** |
| 3 * |
| 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. |
| 8 * |
| 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. |
| 13 * |
| 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. |
| 17 * |
| 18 * The Original Code is Copyright (C) 2010 Blender Foundation. |
| 19 * All rights reserved. |
| 20 * |
| 21 * The Original Code is: all of this file. |
| 22 * |
| 23 * Contributor(s): none yet. |
| 24 * |
| 25 * ***** END GPL LICENSE BLOCK ***** |
| 26 */ |
| 27 |
| 28 /** \file blender/freestyle/intern/application/AppView.cpp |
| 29 * \ingroup freestyle |
| 30 */ |
| 31 |
| 32 /* This header file needs to be included first, in order to avoid a |
| 33 compilation with MinGW (see the commit log of revision 28253) */ |
| 34 extern "C" { |
| 35 #include "BLI_jitter.h" |
| 36 } |
| 37 |
| 38 #include <iostream> |
| 39 |
| 40 #include "Controller.h" |
| 41 #include "AppConfig.h" |
| 42 #include "AppView.h" |
| 43 #include "../view_map/Silhouette.h" |
| 44 #include "../view_map/ViewMap.h" |
| 45 #include "../scene_graph/LineRep.h" |
| 46 #include "../scene_graph/NodeLight.h" |
| 47 #include "../scene_graph/NodeShape.h" |
| 48 #include "../scene_graph/VertexRep.h" |
| 49 #include "../stroke/Canvas.h" |
| 50 #include "../system/StringUtils.h" |
| 51 |
| 52 extern "C" { |
| 53 #include "BLI_blenlib.h" |
| 54 |
| 55 #include "IMB_imbuf.h" |
| 56 #include "IMB_imbuf_types.h" |
| 57 |
| 58 #if 1 // FRS_antialiasing |
| 59 # include "BKE_global.h" |
| 60 # include "DNA_scene_types.h" |
| 61 #endif |
| 62 |
| 63 #include "FRS_freestyle.h" |
| 64 } |
| 65 |
| 66 AppView::AppView(const char *iName) |
| 67 { |
| 68 _Fovy = DEG2RADF(30.0f); |
| 69 _ModelRootNode = new NodeDrawingStyle; |
| 70 _SilhouetteRootNode = new NodeDrawingStyle; |
| 71 _DebugRootNode = new NodeDrawingStyle; |
| 72 |
| 73 _RootNode.AddChild(_ModelRootNode); |
| 74 _SilhouetteRootNode->setStyle(DrawingStyle::LINES); |
| 75 _SilhouetteRootNode->setLightingEnabled(false); |
| 76 _SilhouetteRootNode->setLineWidth(2.0f); |
| 77 _SilhouetteRootNode->setPointSize(3.0f); |
| 78 |
| 79 _RootNode.AddChild(_SilhouetteRootNode); |
| 80 |
| 81 _DebugRootNode->setStyle(DrawingStyle::LINES); |
| 82 _DebugRootNode->setLightingEnabled(false); |
| 83 _DebugRootNode->setLineWidth(1.0f); |
| 84 |
| 85 _RootNode.AddChild(_DebugRootNode); |
| 86 |
| 87 _minBBox = __min(__min(_ModelRootNode->bbox().getMin()[0], _ModelRootNod
e->bbox().getMin()[1]), |
| 88 _ModelRootNode->bbox().getMin()[2]); |
| 89 _maxBBox = __max(__max(_ModelRootNode->bbox().getMax()[0], _ModelRootNod
e->bbox().getMax()[1]), |
| 90 _ModelRootNode->bbox().getMax()[2]); |
| 91 |
| 92 _maxAbs = __max(rabs(_minBBox), rabs(_maxBBox)); |
| 93 _minAbs = __min(rabs(_minBBox), rabs(_maxBBox)); |
| 94 |
| 95 _p2DSelectionNode = new NodeDrawingStyle; |
| 96 _p2DSelectionNode->setLightingEnabled(false); |
| 97 _p2DSelectionNode->setStyle(DrawingStyle::LINES); |
| 98 _p2DSelectionNode->setLineWidth(5.0f); |
| 99 |
| 100 _p2DNode.AddChild(_p2DSelectionNode); |
| 101 |
| 102 NodeLight *light = new NodeLight; |
| 103 _Light.AddChild(light); |
| 104 } |
| 105 |
| 106 AppView::~AppView() |
| 107 { |
| 108 /*int ref =*/ /* UNUSED */ _RootNode.destroy(); |
| 109 |
| 110 _Light.destroy(); |
| 111 /*ref =*/ /* UNUSED */ _p2DNode.destroy(); |
| 112 } |
| 113 |
| 114 real AppView::distanceToSceneCenter() |
| 115 { |
| 116 BBox<Vec3r> bbox = _ModelRootNode->bbox(); |
| 117 |
| 118 Vec3r v(freestyle_viewpoint[0], freestyle_viewpoint[1], freestyle_viewpo
int[2]); |
| 119 v -= 0.5 * (bbox.getMin() + bbox.getMax()); |
| 120 |
| 121 return v.norm(); |
| 122 } |
| 123 |
| 124 real AppView::znear() |
| 125 { |
| 126 BBox<Vec3r> bbox = _ModelRootNode->bbox(); |
| 127 Vec3r u = bbox.getMin(); |
| 128 Vec3r v = bbox.getMax(); |
| 129 Vec3r cameraCenter(freestyle_viewpoint[0], freestyle_viewpoint[1], frees
tyle_viewpoint[2]); |
| 130 |
| 131 Vec3r w1(u[0], u[1], u[2]); |
| 132 Vec3r w2(v[0], u[1], u[2]); |
| 133 Vec3r w3(u[0], v[1], u[2]); |
| 134 Vec3r w4(v[0], v[1], u[2]); |
| 135 Vec3r w5(u[0], u[1], v[2]); |
| 136 Vec3r w6(v[0], u[1], v[2]); |
| 137 Vec3r w7(u[0], v[1], v[2]); |
| 138 Vec3r w8(v[0], v[1], v[2]); |
| 139 |
| 140 real _znear = __min((w1 - cameraCenter).norm(), |
| 141 __min((w2 - cameraCenter).norm(), |
| 142 __min((w3 - cameraCenter).norm(), |
| 143 __min((w4 - cameraCenter).norm(), |
| 144 __min((w5 - cameraCenter).norm(), |
| 145 __min((w6 - cameraCenter).no
rm(), |
| 146 __min((w7 - cameraCent
er).norm(), |
| 147 (w8 - cameraCent
er).norm() |
| 148 ) |
| 149 ) |
| 150 ) |
| 151 ) |
| 152 ) |
| 153 ) |
| 154 ); |
| 155 |
| 156 return __max(_znear, 0.001); |
| 157 } |
| 158 |
| 159 real AppView::zfar() |
| 160 { |
| 161 BBox<Vec3r> bbox = _ModelRootNode->bbox(); |
| 162 Vec3r u = bbox.getMin(); |
| 163 Vec3r v = bbox.getMax(); |
| 164 Vec3r cameraCenter(freestyle_viewpoint[0], freestyle_viewpoint[1], frees
tyle_viewpoint[2]); |
| 165 |
| 166 Vec3r w1(u[0], u[1], u[2]); |
| 167 Vec3r w2(v[0], u[1], u[2]); |
| 168 Vec3r w3(u[0], v[1], u[2]); |
| 169 Vec3r w4(v[0], v[1], u[2]); |
| 170 Vec3r w5(u[0], u[1], v[2]); |
| 171 Vec3r w6(v[0], u[1], v[2]); |
| 172 Vec3r w7(u[0], v[1], v[2]); |
| 173 Vec3r w8(v[0], v[1], v[2]); |
| 174 |
| 175 real _zfar = __max((w1 - cameraCenter).norm(), |
| 176 __max((w2 - cameraCenter).norm(), |
| 177 __max((w3 - cameraCenter).norm(), |
| 178 __max((w4 - cameraCenter).norm(), |
| 179 __max((w5 - cameraCenter).norm(), |
| 180 __max((w6 - cameraCenter).nor
m(), |
| 181 __max((w7 - cameraCente
r).norm(), |
| 182 (w8 - cameraCente
r).norm() |
| 183 ) |
| 184 ) |
| 185 ) |
| 186 ) |
| 187 ) |
| 188 ) |
| 189 ); |
| 190 |
| 191 return _zfar; |
| 192 } |
| 193 |
| 194 real AppView::GetFocalLength() |
| 195 { |
| 196 real Near = __max(0.1, (real)(-2.0f * _maxAbs + distanceToSceneCenter())
); |
| 197 return Near; |
| 198 } |
OLD | NEW |