2023-08-16 00:20:26 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2008-2022 Blender Authors
|
2023-06-14 23:30:43 +10:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2012-12-18 00:51:25 +00:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup freestyle
|
2012-12-18 00:51:25 +00:00
|
|
|
*/
|
2008-12-10 21:51:58 +00:00
|
|
|
|
2012-12-18 00:51:25 +00:00
|
|
|
#include <iostream>
|
2009-10-15 19:32:07 +00:00
|
|
|
|
2012-12-18 00:51:25 +00:00
|
|
|
#include "AppConfig.h"
|
2008-12-10 21:51:58 +00:00
|
|
|
#include "AppView.h"
|
2020-04-21 12:39:12 +02:00
|
|
|
#include "Controller.h"
|
|
|
|
|
|
2008-12-10 21:51:58 +00:00
|
|
|
#include "../scene_graph/LineRep.h"
|
2012-12-18 00:51:25 +00:00
|
|
|
#include "../scene_graph/NodeLight.h"
|
2008-12-10 21:51:58 +00:00
|
|
|
#include "../scene_graph/NodeShape.h"
|
|
|
|
|
#include "../scene_graph/VertexRep.h"
|
2012-12-18 00:51:25 +00:00
|
|
|
#include "../stroke/Canvas.h"
|
2008-12-10 21:51:58 +00:00
|
|
|
#include "../system/StringUtils.h"
|
2020-04-21 12:39:12 +02:00
|
|
|
#include "../view_map/Silhouette.h"
|
|
|
|
|
#include "../view_map/ViewMap.h"
|
2008-12-10 21:51:58 +00:00
|
|
|
|
Cleanup: reduce amount of math-related includes
Using ClangBuildAnalyzer on the whole Blender build, it was pointing
out that BLI_math.h is the heaviest "header hub" (i.e. non tiny file
that is included a lot).
However, there's very little (actually zero) source files in Blender
that need "all the math" (base, colors, vectors, matrices,
quaternions, intersection, interpolation, statistics, solvers and
time). A common use case is source files needing just vectors, or
just vectors & matrices, or just colors etc. Actually, 181 files
were including the whole math thing without needing it at all.
This change removes BLI_math.h completely, and instead in all the
places that need it, includes BLI_math_vector.h or BLI_math_color.h
and so on.
Change from that:
- BLI_math_color.h was included 1399 times -> now 408 (took 114.0sec
to parse -> now 36.3sec)
- BLI_simd.h 1403 -> 418 (109.7sec -> 34.9sec).
Full rebuild of Blender (Apple M1, Xcode, RelWithDebInfo) is not
affected much (342sec -> 334sec). Most of benefit would be when
someone's changing BLI_simd.h or BLI_math_color.h or similar files,
that now there's 3x fewer files result in a recompile.
Pull Request #110944
2023-08-09 11:39:20 +03:00
|
|
|
#include "BLI_math_rotation.h"
|
2012-12-18 00:51:25 +00:00
|
|
|
|
2024-01-18 22:50:23 +02:00
|
|
|
#include "IMB_imbuf.hh"
|
|
|
|
|
#include "IMB_imbuf_types.hh"
|
2012-12-18 00:51:25 +00:00
|
|
|
|
2008-12-10 21:51:58 +00:00
|
|
|
#if 1 // FRS_antialiasing
|
2024-02-10 18:25:14 +01:00
|
|
|
# include "BKE_global.hh"
|
2012-12-18 00:51:25 +00:00
|
|
|
# include "DNA_scene_types.h"
|
2008-12-10 21:51:58 +00:00
|
|
|
#endif
|
|
|
|
|
|
2012-12-18 00:51:25 +00:00
|
|
|
#include "FRS_freestyle.h"
|
2008-12-10 21:51:58 +00:00
|
|
|
|
2013-04-09 00:46:49 +00:00
|
|
|
namespace Freestyle {
|
|
|
|
|
|
2015-03-27 15:50:18 +05:00
|
|
|
AppView::AppView(const char * /*iName*/)
|
2008-12-10 21:51:58 +00:00
|
|
|
{
|
2012-12-18 00:51:25 +00:00
|
|
|
_Fovy = DEG2RADF(30.0f);
|
|
|
|
|
_ModelRootNode = new NodeDrawingStyle;
|
|
|
|
|
_SilhouetteRootNode = new NodeDrawingStyle;
|
|
|
|
|
_DebugRootNode = new NodeDrawingStyle;
|
|
|
|
|
|
|
|
|
|
_RootNode.AddChild(_ModelRootNode);
|
|
|
|
|
_SilhouetteRootNode->setStyle(DrawingStyle::LINES);
|
|
|
|
|
_SilhouetteRootNode->setLightingEnabled(false);
|
|
|
|
|
_SilhouetteRootNode->setLineWidth(2.0f);
|
|
|
|
|
_SilhouetteRootNode->setPointSize(3.0f);
|
|
|
|
|
|
|
|
|
|
_RootNode.AddChild(_SilhouetteRootNode);
|
|
|
|
|
|
|
|
|
|
_DebugRootNode->setStyle(DrawingStyle::LINES);
|
|
|
|
|
_DebugRootNode->setLightingEnabled(false);
|
|
|
|
|
_DebugRootNode->setLineWidth(1.0f);
|
|
|
|
|
|
|
|
|
|
_RootNode.AddChild(_DebugRootNode);
|
|
|
|
|
|
2013-03-02 23:17:20 +00:00
|
|
|
_minBBox = std::min(
|
|
|
|
|
std::min(_ModelRootNode->bbox().getMin()[0], _ModelRootNode->bbox().getMin()[1]),
|
|
|
|
|
_ModelRootNode->bbox().getMin()[2]);
|
|
|
|
|
_maxBBox = std::max(
|
|
|
|
|
std::max(_ModelRootNode->bbox().getMax()[0], _ModelRootNode->bbox().getMax()[1]),
|
|
|
|
|
_ModelRootNode->bbox().getMax()[2]);
|
2012-12-18 00:51:25 +00:00
|
|
|
|
2013-03-02 23:17:20 +00:00
|
|
|
_maxAbs = std::max(rabs(_minBBox), rabs(_maxBBox));
|
|
|
|
|
_minAbs = std::min(rabs(_minBBox), rabs(_maxBBox));
|
2012-12-18 00:51:25 +00:00
|
|
|
|
|
|
|
|
_p2DSelectionNode = new NodeDrawingStyle;
|
|
|
|
|
_p2DSelectionNode->setLightingEnabled(false);
|
|
|
|
|
_p2DSelectionNode->setStyle(DrawingStyle::LINES);
|
|
|
|
|
_p2DSelectionNode->setLineWidth(5.0f);
|
|
|
|
|
|
|
|
|
|
_p2DNode.AddChild(_p2DSelectionNode);
|
|
|
|
|
|
2008-12-10 21:51:58 +00:00
|
|
|
NodeLight *light = new NodeLight;
|
|
|
|
|
_Light.AddChild(light);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AppView::~AppView()
|
|
|
|
|
{
|
2013-01-18 02:13:36 +00:00
|
|
|
/*int ref =*//* UNUSED */ _RootNode.destroy();
|
2012-12-18 00:51:25 +00:00
|
|
|
|
|
|
|
|
_Light.destroy();
|
2013-01-18 02:13:36 +00:00
|
|
|
/*ref =*//* UNUSED */ _p2DNode.destroy();
|
2008-12-10 21:51:58 +00:00
|
|
|
}
|
|
|
|
|
|
2012-12-18 00:51:25 +00:00
|
|
|
real AppView::distanceToSceneCenter()
|
|
|
|
|
{
|
2008-12-10 21:51:58 +00:00
|
|
|
BBox<Vec3r> bbox = _ModelRootNode->bbox();
|
2012-12-18 00:51:25 +00:00
|
|
|
|
2015-11-23 15:31:11 +11:00
|
|
|
Vec3r v(UNPACK3(g_freestyle.viewpoint));
|
2012-12-18 00:51:25 +00:00
|
|
|
v -= 0.5 * (bbox.getMin() + bbox.getMax());
|
2008-12-10 21:51:58 +00:00
|
|
|
|
|
|
|
|
return v.norm();
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-18 00:51:25 +00:00
|
|
|
real AppView::znear()
|
|
|
|
|
{
|
2008-12-10 21:51:58 +00:00
|
|
|
BBox<Vec3r> bbox = _ModelRootNode->bbox();
|
|
|
|
|
Vec3r u = bbox.getMin();
|
|
|
|
|
Vec3r v = bbox.getMax();
|
2015-11-23 15:31:11 +11:00
|
|
|
Vec3r cameraCenter(UNPACK3(g_freestyle.viewpoint));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-18 00:51:25 +00:00
|
|
|
Vec3r w1(u[0], u[1], u[2]);
|
|
|
|
|
Vec3r w2(v[0], u[1], u[2]);
|
|
|
|
|
Vec3r w3(u[0], v[1], u[2]);
|
|
|
|
|
Vec3r w4(v[0], v[1], u[2]);
|
|
|
|
|
Vec3r w5(u[0], u[1], v[2]);
|
|
|
|
|
Vec3r w6(v[0], u[1], v[2]);
|
|
|
|
|
Vec3r w7(u[0], v[1], v[2]);
|
|
|
|
|
Vec3r w8(v[0], v[1], v[2]);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-02 23:17:20 +00:00
|
|
|
real _znear = std::min(
|
|
|
|
|
(w1 - cameraCenter).norm(),
|
|
|
|
|
std::min((w2 - cameraCenter).norm(),
|
|
|
|
|
std::min((w3 - cameraCenter).norm(),
|
|
|
|
|
std::min((w4 - cameraCenter).norm(),
|
|
|
|
|
std::min((w5 - cameraCenter).norm(),
|
|
|
|
|
std::min((w6 - cameraCenter).norm(),
|
|
|
|
|
std::min((w7 - cameraCenter).norm(),
|
|
|
|
|
(w8 - cameraCenter).norm())))))));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-02 23:17:20 +00:00
|
|
|
return std::max(_znear, 0.001);
|
2012-12-18 00:51:25 +00:00
|
|
|
}
|
2008-12-10 21:51:58 +00:00
|
|
|
|
2012-12-18 00:51:25 +00:00
|
|
|
real AppView::zfar()
|
|
|
|
|
{
|
2008-12-10 21:51:58 +00:00
|
|
|
BBox<Vec3r> bbox = _ModelRootNode->bbox();
|
|
|
|
|
Vec3r u = bbox.getMin();
|
|
|
|
|
Vec3r v = bbox.getMax();
|
2015-11-23 15:31:11 +11:00
|
|
|
Vec3r cameraCenter(UNPACK3(g_freestyle.viewpoint));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-18 00:51:25 +00:00
|
|
|
Vec3r w1(u[0], u[1], u[2]);
|
|
|
|
|
Vec3r w2(v[0], u[1], u[2]);
|
|
|
|
|
Vec3r w3(u[0], v[1], u[2]);
|
|
|
|
|
Vec3r w4(v[0], v[1], u[2]);
|
|
|
|
|
Vec3r w5(u[0], u[1], v[2]);
|
|
|
|
|
Vec3r w6(v[0], u[1], v[2]);
|
|
|
|
|
Vec3r w7(u[0], v[1], v[2]);
|
|
|
|
|
Vec3r w8(v[0], v[1], v[2]);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-02 23:17:20 +00:00
|
|
|
real _zfar = std::max(
|
|
|
|
|
(w1 - cameraCenter).norm(),
|
|
|
|
|
std::max((w2 - cameraCenter).norm(),
|
|
|
|
|
std::max((w3 - cameraCenter).norm(),
|
|
|
|
|
std::max((w4 - cameraCenter).norm(),
|
|
|
|
|
std::max((w5 - cameraCenter).norm(),
|
|
|
|
|
std::max((w6 - cameraCenter).norm(),
|
|
|
|
|
std::max((w7 - cameraCenter).norm(),
|
|
|
|
|
(w8 - cameraCenter).norm())))))));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2008-12-10 21:51:58 +00:00
|
|
|
return _zfar;
|
2012-12-18 00:51:25 +00:00
|
|
|
}
|
2008-12-10 21:51:58 +00:00
|
|
|
|
2012-12-18 00:51:25 +00:00
|
|
|
real AppView::GetFocalLength()
|
|
|
|
|
{
|
2013-03-02 23:17:20 +00:00
|
|
|
real Near = std::max(0.1, (real)(-2.0f * _maxAbs + distanceToSceneCenter()));
|
2012-12-18 00:51:25 +00:00
|
|
|
return Near;
|
|
|
|
|
}
|
2013-04-09 00:46:49 +00:00
|
|
|
|
|
|
|
|
} /* namespace Freestyle */
|