Blender  V3.3
AppView.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
7 #include <iostream>
8 
9 #include "AppConfig.h"
10 #include "AppView.h"
11 #include "Controller.h"
12 
13 #include "../scene_graph/LineRep.h"
14 #include "../scene_graph/NodeLight.h"
15 #include "../scene_graph/NodeShape.h"
16 #include "../scene_graph/VertexRep.h"
17 #include "../stroke/Canvas.h"
18 #include "../system/StringUtils.h"
19 #include "../view_map/Silhouette.h"
20 #include "../view_map/ViewMap.h"
21 
22 #include "BLI_blenlib.h"
23 
24 #include "IMB_imbuf.h"
25 #include "IMB_imbuf_types.h"
26 
27 #if 1 // FRS_antialiasing
28 # include "BKE_global.h"
29 # include "DNA_scene_types.h"
30 #endif
31 
32 #include "FRS_freestyle.h"
33 
34 namespace Freestyle {
35 
36 AppView::AppView(const char * /*iName*/)
37 {
38  _Fovy = DEG2RADF(30.0f);
42 
48 
50 
54 
56 
58  std::min(_ModelRootNode->bbox().getMin()[0], _ModelRootNode->bbox().getMin()[1]),
59  _ModelRootNode->bbox().getMin()[2]);
61  std::max(_ModelRootNode->bbox().getMax()[0], _ModelRootNode->bbox().getMax()[1]),
62  _ModelRootNode->bbox().getMax()[2]);
63 
66 
71 
73 
74  NodeLight *light = new NodeLight;
75  _Light.AddChild(light);
76 }
77 
79 {
80  /*int ref =*//* UNUSED */ _RootNode.destroy();
81 
82  _Light.destroy();
83  /*ref =*//* UNUSED */ _p2DNode.destroy();
84 }
85 
87 {
89 
91  v -= 0.5 * (bbox.getMin() + bbox.getMax());
92 
93  return v.norm();
94 }
95 
97 {
99  Vec3r u = bbox.getMin();
100  Vec3r v = bbox.getMax();
101  Vec3r cameraCenter(UNPACK3(g_freestyle.viewpoint));
102 
103  Vec3r w1(u[0], u[1], u[2]);
104  Vec3r w2(v[0], u[1], u[2]);
105  Vec3r w3(u[0], v[1], u[2]);
106  Vec3r w4(v[0], v[1], u[2]);
107  Vec3r w5(u[0], u[1], v[2]);
108  Vec3r w6(v[0], u[1], v[2]);
109  Vec3r w7(u[0], v[1], v[2]);
110  Vec3r w8(v[0], v[1], v[2]);
111 
112  real _znear = std::min(
113  (w1 - cameraCenter).norm(),
114  std::min((w2 - cameraCenter).norm(),
115  std::min((w3 - cameraCenter).norm(),
116  std::min((w4 - cameraCenter).norm(),
117  std::min((w5 - cameraCenter).norm(),
118  std::min((w6 - cameraCenter).norm(),
119  std::min((w7 - cameraCenter).norm(),
120  (w8 - cameraCenter).norm())))))));
121 
122  return std::max(_znear, 0.001);
123 }
124 
126 {
127  BBox<Vec3r> bbox = _ModelRootNode->bbox();
128  Vec3r u = bbox.getMin();
129  Vec3r v = bbox.getMax();
130  Vec3r cameraCenter(UNPACK3(g_freestyle.viewpoint));
131 
132  Vec3r w1(u[0], u[1], u[2]);
133  Vec3r w2(v[0], u[1], u[2]);
134  Vec3r w3(u[0], v[1], u[2]);
135  Vec3r w4(v[0], v[1], u[2]);
136  Vec3r w5(u[0], u[1], v[2]);
137  Vec3r w6(v[0], u[1], v[2]);
138  Vec3r w7(u[0], v[1], v[2]);
139  Vec3r w8(v[0], v[1], v[2]);
140 
141  real _zfar = std::max(
142  (w1 - cameraCenter).norm(),
143  std::max((w2 - cameraCenter).norm(),
144  std::max((w3 - cameraCenter).norm(),
145  std::max((w4 - cameraCenter).norm(),
146  std::max((w5 - cameraCenter).norm(),
147  std::max((w6 - cameraCenter).norm(),
148  std::max((w7 - cameraCenter).norm(),
149  (w8 - cameraCenter).norm())))))));
150 
151  return _zfar;
152 }
153 
155 {
156  real Near = std::max(0.1, (real)(-2.0f * _maxAbs + distanceToSceneCenter()));
157  return Near;
158 }
159 
160 } /* namespace Freestyle */
Configuration file.
#define DEG2RADF(_deg)
#define UNPACK3(a)
The spinal tap of the system.
struct FreestyleGlobals g_freestyle
Contains defines and structs used throughout the imbuf module.
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:86
AppView(const char *iName=0)
Definition: AppView.cpp:36
NodeGroup _Light
Definition: AppView.h:241
virtual ~AppView()
Definition: AppView.cpp:78
NodeDrawingStyle * _ModelRootNode
Definition: AppView.h:237
NodeDrawingStyle * _DebugRootNode
Definition: AppView.h:239
int rabs(int x)
Definition: AppView.h:223
NodeDrawingStyle * _p2DSelectionNode
Definition: AppView.h:252
NodeGroup _p2DNode
Definition: AppView.h:251
NodeGroup _RootNode
Definition: AppView.h:236
NodeDrawingStyle * _SilhouetteRootNode
Definition: AppView.h:238
real GetFocalLength()
Definition: AppView.cpp:154
const Point & getMax() const
Definition: BBox.h:72
const Point & getMin() const
Definition: BBox.h:67
void setPointSize(const float iPointSize)
void setStyle(const DrawingStyle::STYLE iStyle)
void setLineWidth(const float iLineWidth)
void setLightingEnabled(const bool iEnableLighting)
virtual void AddChild(Node *iChild)
Definition: NodeGroup.cpp:14
virtual int destroy()
Definition: NodeGroup.cpp:24
virtual const BBox< Vec3r > & bbox() const
Definition: Node.h:53
inherits from class Rep
Definition: AppCanvas.cpp:18
double real
Definition: Precision.h:12
#define min(a, b)
Definition: sort.c:35
float viewpoint[3]
Definition: FRS_freestyle.h:22
float max