Blender V4.3
AppView.cpp
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2008-2022 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <iostream>
10
11#include "AppConfig.h"
12#include "AppView.h"
13#include "Controller.h"
14
19#include "../stroke/Canvas.h"
22#include "../view_map/ViewMap.h"
23
24#include "BLI_blenlib.h"
25#include "BLI_math_rotation.h"
26
27#include "IMB_imbuf.hh"
28#include "IMB_imbuf_types.hh"
29
30#if 1 // FRS_antialiasing
31# include "BKE_global.hh"
32# include "DNA_scene_types.h"
33#endif
34
35#include "FRS_freestyle.h"
36
37namespace Freestyle {
38
39AppView::AppView(const char * /*iName*/)
40{
41 _Fovy = DEG2RADF(30.0f);
45
46 _RootNode.AddChild(_ModelRootNode);
48 _SilhouetteRootNode->setLightingEnabled(false);
49 _SilhouetteRootNode->setLineWidth(2.0f);
50 _SilhouetteRootNode->setPointSize(3.0f);
51
53
55 _DebugRootNode->setLightingEnabled(false);
56 _DebugRootNode->setLineWidth(1.0f);
57
58 _RootNode.AddChild(_DebugRootNode);
59
60 _minBBox = std::min(
61 std::min(_ModelRootNode->bbox().getMin()[0], _ModelRootNode->bbox().getMin()[1]),
62 _ModelRootNode->bbox().getMin()[2]);
63 _maxBBox = std::max(
64 std::max(_ModelRootNode->bbox().getMax()[0], _ModelRootNode->bbox().getMax()[1]),
65 _ModelRootNode->bbox().getMax()[2]);
66
67 _maxAbs = std::max(rabs(_minBBox), rabs(_maxBBox));
68 _minAbs = std::min(rabs(_minBBox), rabs(_maxBBox));
69
71 _p2DSelectionNode->setLightingEnabled(false);
73 _p2DSelectionNode->setLineWidth(5.0f);
74
76
77 NodeLight *light = new NodeLight;
78 _Light.AddChild(light);
79}
80
82{
83 /*int ref =*//* UNUSED */ _RootNode.destroy();
84
85 _Light.destroy();
86 /*ref =*//* UNUSED */ _p2DNode.destroy();
87}
88
90{
91 BBox<Vec3r> bbox = _ModelRootNode->bbox();
92
93 Vec3r v(UNPACK3(g_freestyle.viewpoint));
94 v -= 0.5 * (bbox.getMin() + bbox.getMax());
95
96 return v.norm();
97}
98
100{
101 BBox<Vec3r> bbox = _ModelRootNode->bbox();
102 Vec3r u = bbox.getMin();
103 Vec3r v = bbox.getMax();
104 Vec3r cameraCenter(UNPACK3(g_freestyle.viewpoint));
105
106 Vec3r w1(u[0], u[1], u[2]);
107 Vec3r w2(v[0], u[1], u[2]);
108 Vec3r w3(u[0], v[1], u[2]);
109 Vec3r w4(v[0], v[1], u[2]);
110 Vec3r w5(u[0], u[1], v[2]);
111 Vec3r w6(v[0], u[1], v[2]);
112 Vec3r w7(u[0], v[1], v[2]);
113 Vec3r w8(v[0], v[1], v[2]);
114
115 real _znear = std::min(
116 (w1 - cameraCenter).norm(),
117 std::min((w2 - cameraCenter).norm(),
118 std::min((w3 - cameraCenter).norm(),
119 std::min((w4 - cameraCenter).norm(),
120 std::min((w5 - cameraCenter).norm(),
121 std::min((w6 - cameraCenter).norm(),
122 std::min((w7 - cameraCenter).norm(),
123 (w8 - cameraCenter).norm())))))));
124
125 return std::max(_znear, 0.001);
126}
127
129{
130 BBox<Vec3r> bbox = _ModelRootNode->bbox();
131 Vec3r u = bbox.getMin();
132 Vec3r v = bbox.getMax();
133 Vec3r cameraCenter(UNPACK3(g_freestyle.viewpoint));
134
135 Vec3r w1(u[0], u[1], u[2]);
136 Vec3r w2(v[0], u[1], u[2]);
137 Vec3r w3(u[0], v[1], u[2]);
138 Vec3r w4(v[0], v[1], u[2]);
139 Vec3r w5(u[0], u[1], v[2]);
140 Vec3r w6(v[0], u[1], v[2]);
141 Vec3r w7(u[0], v[1], v[2]);
142 Vec3r w8(v[0], v[1], v[2]);
143
144 real _zfar = std::max(
145 (w1 - cameraCenter).norm(),
146 std::max((w2 - cameraCenter).norm(),
147 std::max((w3 - cameraCenter).norm(),
148 std::max((w4 - cameraCenter).norm(),
149 std::max((w5 - cameraCenter).norm(),
150 std::max((w6 - cameraCenter).norm(),
151 std::max((w7 - cameraCenter).norm(),
152 (w8 - cameraCenter).norm())))))));
153
154 return _zfar;
155}
156
158{
159 real Near = std::max(0.1, (real)(-2.0f * _maxAbs + distanceToSceneCenter()));
160 return Near;
161}
162
163} /* namespace Freestyle */
Configuration file.
#define DEG2RADF(_deg)
#define UNPACK3(a)
Class to define a canvas designed to draw style modules.
The spinal tap of the system.
struct FreestyleGlobals g_freestyle
Contains defines and structs used throughout the imbuf module.
Class to define the representation of 3D Line.
Class to represent a light node.
Class to build a shape node. It contains a Rep, which is the shape geometry.
Classes to define a silhouette structure.
String utilities.
Class to define the representation of a vertex for displaying purpose.
Classes to define a View Map (ViewVertex, ViewEdge, etc.)
ATTR_WARN_UNUSED_RESULT const BMVert * v
SIMD_FORCE_INLINE btScalar norm() const
Return the norm (length) of the vector.
Definition btVector3.h:263
real distanceToSceneCenter()
Definition AppView.cpp:89
AppView(const char *iName=0)
Definition AppView.cpp:39
NodeGroup _Light
Definition AppView.h:243
virtual ~AppView()
Definition AppView.cpp:81
NodeDrawingStyle * _ModelRootNode
Definition AppView.h:239
NodeDrawingStyle * _DebugRootNode
Definition AppView.h:241
int rabs(int x)
Definition AppView.h:225
NodeDrawingStyle * _p2DSelectionNode
Definition AppView.h:254
NodeGroup _p2DNode
Definition AppView.h:253
NodeGroup _RootNode
Definition AppView.h:238
NodeDrawingStyle * _SilhouetteRootNode
Definition AppView.h:240
const Point & getMin() const
Definition BBox.h:69
const Point & getMax() const
Definition BBox.h:74
VecMat::Vec3< real > Vec3r
Definition Geom.h:30
inherits from class Rep
Definition AppCanvas.cpp:20
double real
Definition Precision.h:14