2012-12-18 00:51:25 +00:00
|
|
|
/*
|
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup freestyle
|
|
|
|
|
* \brief The spinal tap of the system.
|
2012-12-18 00:51:25 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
|
|
#include "../geometry/FastGrid.h"
|
2014-01-28 23:24:59 +09:00
|
|
|
#include "../scene_graph/SceneHash.h"
|
2012-12-18 00:51:25 +00:00
|
|
|
#include "../system/Precision.h"
|
|
|
|
|
#include "../system/TimeUtils.h"
|
|
|
|
|
#include "../view_map/FEdgeXDetector.h"
|
|
|
|
|
#include "../view_map/ViewMapBuilder.h"
|
2008-05-18 13:01:52 +00:00
|
|
|
|
2013-05-13 22:58:27 +00:00
|
|
|
#ifdef WITH_CXX_GUARDEDALLOC
|
|
|
|
|
# include "MEM_guardedalloc.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
2013-04-09 00:46:49 +00:00
|
|
|
namespace Freestyle {
|
|
|
|
|
|
2014-08-01 12:49:04 +09:00
|
|
|
class AppCanvas;
|
2008-12-10 21:51:58 +00:00
|
|
|
class AppView;
|
2014-08-01 12:49:04 +09:00
|
|
|
class Interpreter;
|
2008-05-18 13:01:52 +00:00
|
|
|
class NodeGroup;
|
2014-08-01 12:49:04 +09:00
|
|
|
class ProgressBar;
|
|
|
|
|
class RenderMonitor;
|
2008-05-18 13:01:52 +00:00
|
|
|
class SShape;
|
|
|
|
|
class ViewEdge;
|
2014-08-01 12:49:04 +09:00
|
|
|
class ViewMap;
|
2008-05-18 13:01:52 +00:00
|
|
|
|
|
|
|
|
class Controller {
|
|
|
|
|
public:
|
2012-12-18 00:51:25 +00:00
|
|
|
Controller();
|
|
|
|
|
~Controller();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-18 00:51:25 +00:00
|
|
|
void setView(AppView *iView);
|
|
|
|
|
void setRenderMonitor(RenderMonitor *iRenderMonitor);
|
|
|
|
|
void setPassDiffuse(float *buf, int width, int height);
|
|
|
|
|
void setPassZ(float *buf, int width, int height);
|
|
|
|
|
void setContext(bContext *C);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-30 17:50:57 +10:00
|
|
|
// soc
|
2008-05-26 16:19:30 +00:00
|
|
|
void init_options();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-01-24 07:08:19 +01:00
|
|
|
int LoadMesh(Render *re, ViewLayer *view_layer, Depsgraph *depsgraph);
|
2012-12-18 00:51:25 +00:00
|
|
|
int Load3DSFile(const char *iFileName);
|
|
|
|
|
void CloseFile();
|
|
|
|
|
void ComputeViewMap();
|
|
|
|
|
void ComputeSteerableViewMap();
|
|
|
|
|
void saveSteerableViewMapImages();
|
|
|
|
|
void toggleEdgeTesselationNature(Nature::EdgeNature iNature);
|
2016-05-05 23:09:22 +09:00
|
|
|
int DrawStrokes();
|
2012-12-18 00:51:25 +00:00
|
|
|
void ResetRenderCount();
|
2013-06-11 02:32:01 +00:00
|
|
|
Render *RenderStrokes(Render *re, bool render);
|
2012-12-18 00:51:25 +00:00
|
|
|
void SwapStyleModules(unsigned i1, unsigned i2);
|
|
|
|
|
void InsertStyleModule(unsigned index, const char *iFileName);
|
2015-04-28 23:18:32 +09:00
|
|
|
void InsertStyleModule(unsigned index, const char *iName, const char *iBuffer);
|
2014-07-19 18:52:32 +09:00
|
|
|
void InsertStyleModule(unsigned index, const char *iName, struct Text *iText);
|
2012-12-18 00:51:25 +00:00
|
|
|
void AddStyleModule(const char *iFileName);
|
|
|
|
|
void RemoveStyleModule(unsigned index);
|
|
|
|
|
void ReloadStyleModule(unsigned index, const char *iFileName);
|
|
|
|
|
void Clear();
|
|
|
|
|
void ClearRootNode();
|
|
|
|
|
void DeleteWingedEdge();
|
2014-01-28 23:24:59 +09:00
|
|
|
void DeleteViewMap(bool freeCache = false);
|
2012-12-18 00:51:25 +00:00
|
|
|
void toggleLayer(unsigned index, bool iDisplay);
|
|
|
|
|
void setModified(unsigned index, bool iMod);
|
|
|
|
|
void resetModified(bool iMod = false);
|
|
|
|
|
void updateCausalStyleModules(unsigned index);
|
|
|
|
|
void displayDensityCurves(int x, int y);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-18 00:51:25 +00:00
|
|
|
ViewEdge *SelectViewEdge(real x, real y);
|
|
|
|
|
FEdge *SelectFEdge(real x, real y);
|
|
|
|
|
NodeGroup *BuildRep(vector<ViewEdge *>::iterator vedges_begin,
|
|
|
|
|
vector<ViewEdge *>::iterator vedges_end);
|
|
|
|
|
|
|
|
|
|
#if 0
|
2019-04-17 08:24:14 +02:00
|
|
|
NodeGroup *debugNode()
|
|
|
|
|
{
|
|
|
|
|
return _DebugNode;
|
|
|
|
|
}
|
|
|
|
|
AppView *view()
|
|
|
|
|
{
|
|
|
|
|
return _pView;
|
|
|
|
|
}
|
|
|
|
|
NodeGroup *debugScene()
|
|
|
|
|
{
|
|
|
|
|
return _DebugNode;
|
|
|
|
|
}
|
|
|
|
|
Grid &grid()
|
|
|
|
|
{
|
|
|
|
|
return _Grid;
|
|
|
|
|
}
|
2012-12-18 00:51:25 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
void toggleVisibilityAlgo();
|
|
|
|
|
void setVisibilityAlgo(int algo);
|
|
|
|
|
int getVisibilityAlgo();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-01-28 23:24:59 +09:00
|
|
|
void setViewMapCache(bool iBool);
|
|
|
|
|
bool getViewMapCache() const;
|
2012-12-18 00:51:25 +00:00
|
|
|
void setQuantitativeInvisibility(bool iBool); // if true, we compute quantitativeInvisibility
|
|
|
|
|
bool getQuantitativeInvisibility() const;
|
|
|
|
|
void setFaceSmoothness(bool iBool);
|
|
|
|
|
bool getFaceSmoothness() const;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-18 00:51:25 +00:00
|
|
|
void setComputeRidgesAndValleysFlag(bool b);
|
|
|
|
|
bool getComputeRidgesAndValleysFlag() const;
|
|
|
|
|
void setComputeSuggestiveContoursFlag(bool b);
|
|
|
|
|
bool getComputeSuggestiveContoursFlag() const;
|
|
|
|
|
void setComputeMaterialBoundariesFlag(bool b);
|
|
|
|
|
bool getComputeMaterialBoundariesFlag() const;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-18 00:51:25 +00:00
|
|
|
void setComputeSteerableViewMapFlag(bool iBool);
|
|
|
|
|
bool getComputeSteerableViewMapFlag() const;
|
2014-07-30 17:08:31 +09:00
|
|
|
void setCreaseAngle(float angle)
|
|
|
|
|
{
|
|
|
|
|
_creaseAngle = angle;
|
|
|
|
|
}
|
|
|
|
|
float getCreaseAngle() const
|
|
|
|
|
{
|
|
|
|
|
return _creaseAngle;
|
|
|
|
|
}
|
|
|
|
|
void setSphereRadius(float s)
|
|
|
|
|
{
|
|
|
|
|
_sphereRadius = s;
|
|
|
|
|
}
|
|
|
|
|
float getSphereRadius() const
|
|
|
|
|
{
|
|
|
|
|
return _sphereRadius;
|
|
|
|
|
}
|
|
|
|
|
void setSuggestiveContourKrDerivativeEpsilon(float dkr)
|
|
|
|
|
{
|
|
|
|
|
_suggestiveContourKrDerivativeEpsilon = dkr;
|
|
|
|
|
}
|
|
|
|
|
float getSuggestiveContourKrDerivativeEpsilon() const
|
|
|
|
|
{
|
|
|
|
|
return _suggestiveContourKrDerivativeEpsilon;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
2012-12-18 00:51:25 +00:00
|
|
|
void setModelsDir(const string &dir);
|
|
|
|
|
string getModelsDir() const;
|
|
|
|
|
void setModulesDir(const string &dir);
|
|
|
|
|
string getModulesDir() const;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-01-28 23:24:59 +09:00
|
|
|
bool hitViewMapCache();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-18 00:51:25 +00:00
|
|
|
void resetInterpreter();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2008-12-10 15:30:43 +00:00
|
|
|
public:
|
|
|
|
|
// Viewmap data structure
|
2012-12-18 00:51:25 +00:00
|
|
|
ViewMap *_ViewMap;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2008-12-10 21:51:58 +00:00
|
|
|
// Canvas
|
2012-12-18 00:51:25 +00:00
|
|
|
AppCanvas *_Canvas;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2008-05-18 13:01:52 +00:00
|
|
|
private:
|
2012-12-18 00:51:25 +00:00
|
|
|
// Main Window:
|
2019-04-30 17:50:57 +10:00
|
|
|
// AppMainWindow *_pMainWindow;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-18 00:51:25 +00:00
|
|
|
// List of models currently loaded
|
|
|
|
|
vector<string> _ListOfModels;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-18 00:51:25 +00:00
|
|
|
// Current directories
|
2019-04-30 17:50:57 +10:00
|
|
|
// ConfigIO* _current_dirs;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-30 17:50:57 +10:00
|
|
|
// View
|
2012-12-18 00:51:25 +00:00
|
|
|
// 3D
|
|
|
|
|
AppView *_pView;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-18 00:51:25 +00:00
|
|
|
// 2D
|
|
|
|
|
#if 0
|
|
|
|
|
Viewer2DWindow *_pView2DWindow;
|
|
|
|
|
Viewer2D *_pView2D;
|
|
|
|
|
#endif
|
2008-12-10 21:51:58 +00:00
|
|
|
|
2012-12-18 00:51:25 +00:00
|
|
|
RenderMonitor *_pRenderMonitor;
|
The GL-based renderer was removed. Freestyle now uses Blender's internal renderer to raster strokes.
The render generated from Freestyle's data is currently stored in the original scene's render structure ( as 'freestyle_render'): when the render database is generated, the scene's geometrical data is first imported into Freestyle and strokes are calculated. The generated strokes are used to create a Blender scene, rendered independently. The render result is used in the rendering loop.
The final rendering is performed the same way edge rendering is, in a function ('freestyle_enhance_add') operating on each individual render part. Freestyle strokes are only included if the toggle button "Freestyle" (in the 'Output' panel) is active and if the "Freestyle" render layer is also selected. Freestyle's panel appears when the toggle button 'Freestyle' is active.
IMPORTANT: as of now, rendering ONLY works when OSA is disabled and when Xparts = Yparts = 1. If these settings are not set, a bogus image will be created.
To make the render happen, many modifications had to be made:
- the Canvas::Draw and Operators::create methods no longer render strokes. They only generate shading and locational information.
- a BlenderStrokeRenderer class was added to turn Freestyle's strokes into a Blender scene. Basically, the scene consists of strokes in their projected image 2D coordinates and an orthographic camera centered in the middle of the corresponding canvas. The scene is rendered using vertex colors, in shadeless mode (therefore, no lamp is needed). BlenderStrokeRenderer uses the old GLTextureManager to load textures (as required by the StrokeRenderer class), even though stroke textures are probably not supported (not tested). After the scene is rendered, it is safely and automatically discarded.
- AppCanvas' code was greatly reduced to the bare minimum. The former AppCanvas would use an OpenGL-based back buffer and z buffer to determine the scene's color and depth information. In the future, this data will be determined from the corresponding render passes. Currently, the integration is not achieved so all style modules using depth/color information are sure to fail.
- before, Freestyle needed an OpenGL context to determine the camera's information and to compute the view map. As of now, the modelview and projection matrices are fully determined using data provided by Blender. This means both perspective and orthographic projections are supported. The AppGLWidget will very soon be removed completely.
2008-12-01 21:30:44 +00:00
|
|
|
|
2019-04-30 17:50:57 +10:00
|
|
|
// Model
|
2012-12-18 00:51:25 +00:00
|
|
|
// Drawing Structure
|
|
|
|
|
NodeGroup *_RootNode;
|
2012-07-16 23:29:12 +00:00
|
|
|
|
2012-12-18 00:51:25 +00:00
|
|
|
// Winged-Edge structure
|
|
|
|
|
WingedEdge *_winged_edge;
|
2008-05-18 13:01:52 +00:00
|
|
|
|
2012-12-18 00:51:25 +00:00
|
|
|
#if 0
|
2014-08-14 16:58:17 +09:00
|
|
|
// Silhouette structure:
|
2019-04-17 08:24:14 +02:00
|
|
|
std::vector<SShape *> _SShapes;
|
2012-12-18 00:51:25 +00:00
|
|
|
NodeGroup *_SRoot;
|
|
|
|
|
|
|
|
|
|
// Silhouette
|
|
|
|
|
NodeGroup *_SilhouetteNode;
|
|
|
|
|
NodeGroup *_ProjectedSilhouette;
|
|
|
|
|
NodeGroup *_VisibleProjectedSilhouette;
|
2008-05-18 13:01:52 +00:00
|
|
|
|
2012-12-18 00:51:25 +00:00
|
|
|
// more Debug info
|
|
|
|
|
NodeGroup *_DebugNode;
|
2014-08-14 16:58:17 +09:00
|
|
|
#endif
|
2008-05-18 13:01:52 +00:00
|
|
|
|
2012-12-18 00:51:25 +00:00
|
|
|
// debug
|
2019-04-30 17:50:57 +10:00
|
|
|
// NodeUser<ViewMap> *_ViewMapNode; // FIXME
|
2008-05-18 13:01:52 +00:00
|
|
|
|
2012-12-18 00:51:25 +00:00
|
|
|
// Chronometer:
|
|
|
|
|
Chronometer _Chrono;
|
2008-05-18 13:01:52 +00:00
|
|
|
|
2008-05-25 17:34:21 +00:00
|
|
|
// Progress Bar
|
2012-12-18 00:51:25 +00:00
|
|
|
ProgressBar *_ProgressBar;
|
|
|
|
|
|
|
|
|
|
// edges tesselation nature
|
|
|
|
|
int _edgeTesselationNature;
|
|
|
|
|
|
|
|
|
|
FastGrid _Grid;
|
2019-04-30 17:50:57 +10:00
|
|
|
// HashGrid _Grid;
|
2008-05-25 17:34:21 +00:00
|
|
|
|
2013-08-24 11:42:00 +00:00
|
|
|
BBox<Vec3r> _Scene3dBBox;
|
2012-12-18 00:51:25 +00:00
|
|
|
unsigned int _SceneNumFaces;
|
2015-08-09 23:36:53 +09:00
|
|
|
#if 0
|
2012-12-18 00:51:25 +00:00
|
|
|
real _minEdgeSize;
|
2015-08-09 23:36:53 +09:00
|
|
|
#endif
|
2012-12-18 00:51:25 +00:00
|
|
|
real _EPSILON;
|
|
|
|
|
real _bboxDiag;
|
2008-05-18 13:01:52 +00:00
|
|
|
|
2012-12-18 00:51:25 +00:00
|
|
|
int _render_count;
|
2008-05-18 13:01:52 +00:00
|
|
|
|
2019-04-30 17:50:57 +10:00
|
|
|
// AppStyleWindow *_pStyleWindow;
|
|
|
|
|
// AppOptionsWindow *_pOptionsWindow;
|
|
|
|
|
// AppDensityCurvesWindow *_pDensityCurvesWindow;
|
2008-05-18 13:01:52 +00:00
|
|
|
|
2012-12-18 00:51:25 +00:00
|
|
|
ViewMapBuilder::visibility_algo _VisibilityAlgo;
|
2008-05-18 13:01:52 +00:00
|
|
|
|
2012-12-18 00:51:25 +00:00
|
|
|
// Script Interpreter
|
|
|
|
|
Interpreter *_inter;
|
2008-05-18 13:01:52 +00:00
|
|
|
|
2012-12-18 00:51:25 +00:00
|
|
|
string _help_index;
|
|
|
|
|
string _browser_cmd;
|
2008-05-18 13:01:52 +00:00
|
|
|
|
2014-01-28 23:24:59 +09:00
|
|
|
bool _EnableViewMapCache;
|
2012-12-18 00:51:25 +00:00
|
|
|
bool _EnableQI;
|
|
|
|
|
bool _EnableFaceSmoothness;
|
|
|
|
|
bool _ComputeRidges;
|
|
|
|
|
bool _ComputeSuggestive;
|
|
|
|
|
bool _ComputeMaterialBoundaries;
|
2014-07-30 17:08:31 +09:00
|
|
|
float _creaseAngle;
|
|
|
|
|
float _sphereRadius;
|
|
|
|
|
float _suggestiveContourKrDerivativeEpsilon;
|
2008-05-18 13:01:52 +00:00
|
|
|
|
2012-12-18 00:51:25 +00:00
|
|
|
bool _ComputeSteerableViewMap;
|
2008-05-18 13:01:52 +00:00
|
|
|
|
2012-12-18 00:51:25 +00:00
|
|
|
FEdgeXDetector edgeDetector;
|
2013-05-13 22:58:27 +00:00
|
|
|
|
2014-01-28 23:24:59 +09:00
|
|
|
SceneHash sceneHashFunc;
|
2014-10-02 19:24:16 +06:00
|
|
|
real prevSceneHash;
|
2014-01-28 23:24:59 +09:00
|
|
|
|
2013-05-13 22:58:27 +00:00
|
|
|
#ifdef WITH_CXX_GUARDEDALLOC
|
|
|
|
|
MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:Controller")
|
|
|
|
|
#endif
|
2008-05-18 13:01:52 +00:00
|
|
|
};
|
|
|
|
|
|
2012-12-18 00:51:25 +00:00
|
|
|
extern Controller *g_pController;
|
2008-05-18 13:01:52 +00:00
|
|
|
|
2013-04-09 00:46:49 +00:00
|
|
|
} /* namespace Freestyle */
|