├── .clang-format ├── .gitignore ├── LICENSE.txt ├── README.md ├── app ├── app.pro └── src │ └── main.cpp ├── common.pri ├── dilay.pro ├── icon.tex ├── lib ├── lib.pro └── src │ ├── IsosurfaceExtractionConfigurations.hs │ ├── bitset.hpp │ ├── cache.hpp │ ├── camera.cpp │ ├── camera.hpp │ ├── color.cpp │ ├── color.hpp │ ├── config.cpp │ ├── config.hpp │ ├── configurable.cpp │ ├── configurable.hpp │ ├── dimension.cpp │ ├── dimension.hpp │ ├── distance.cpp │ ├── distance.hpp │ ├── dynamic │ ├── faces.cpp │ ├── faces.hpp │ ├── mesh-intersection.cpp │ ├── mesh-intersection.hpp │ ├── mesh.cpp │ ├── mesh.hpp │ ├── octree.cpp │ └── octree.hpp │ ├── hash.hpp │ ├── history.cpp │ ├── history.hpp │ ├── import-export.cpp │ ├── import-export.hpp │ ├── intersection.cpp │ ├── intersection.hpp │ ├── isosurface-extraction.cpp │ ├── isosurface-extraction.hpp │ ├── isosurface-extraction │ ├── IsosurfaceExtractionConfigurations.hs │ ├── grid.cpp │ └── grid.hpp │ ├── kvstore.cpp │ ├── kvstore.hpp │ ├── log.cpp │ ├── log.hpp │ ├── macro.hpp │ ├── maybe.hpp │ ├── mesh-util.cpp │ ├── mesh-util.hpp │ ├── mesh.cpp │ ├── mesh.hpp │ ├── mirror.cpp │ ├── mirror.hpp │ ├── opengl-buffer-id.cpp │ ├── opengl-buffer-id.hpp │ ├── opengl.cpp │ ├── opengl.hpp │ ├── primitive │ ├── aabox.cpp │ ├── aabox.hpp │ ├── cone-sphere.cpp │ ├── cone-sphere.hpp │ ├── cone.cpp │ ├── cone.hpp │ ├── cylinder.cpp │ ├── cylinder.hpp │ ├── plane.cpp │ ├── plane.hpp │ ├── ray.cpp │ ├── ray.hpp │ ├── sphere.cpp │ ├── sphere.hpp │ ├── triangle.cpp │ └── triangle.hpp │ ├── render-mode.cpp │ ├── render-mode.hpp │ ├── renderer.cpp │ ├── renderer.hpp │ ├── scene.cpp │ ├── scene.hpp │ ├── shader.cpp │ ├── shader.hpp │ ├── sketch │ ├── bone-intersection.cpp │ ├── bone-intersection.hpp │ ├── fwd.hpp │ ├── mesh-intersection.cpp │ ├── mesh-intersection.hpp │ ├── mesh.cpp │ ├── mesh.hpp │ ├── node-intersection.cpp │ ├── node-intersection.hpp │ ├── path-intersection.cpp │ ├── path-intersection.hpp │ ├── path.cpp │ └── path.hpp │ ├── state.cpp │ ├── state.hpp │ ├── time-delta.cpp │ ├── time-delta.hpp │ ├── tool.cpp │ ├── tool.hpp │ ├── tool │ ├── convert-sketch.cpp │ ├── delete-mesh.cpp │ ├── delete-sketch.cpp │ ├── edit-sketch.cpp │ ├── key.hpp │ ├── move-camera.cpp │ ├── move-camera.hpp │ ├── new-mesh.cpp │ ├── remesh.cpp │ ├── sculpt.cpp │ ├── sculpt.hpp │ ├── sculpt │ │ ├── crease.cpp │ │ ├── draw.cpp │ │ ├── flatten.cpp │ │ ├── grab.cpp │ │ ├── pinch.cpp │ │ ├── reduce.cpp │ │ ├── smooth.cpp │ │ └── util │ │ │ ├── action.cpp │ │ │ ├── action.hpp │ │ │ ├── brush.cpp │ │ │ ├── brush.hpp │ │ │ ├── edge-collection.cpp │ │ │ └── edge-collection.hpp │ ├── sketch-spheres.cpp │ ├── transform-mesh.cpp │ ├── trim-mesh.cpp │ ├── trim-mesh │ │ ├── action.cpp │ │ ├── action.hpp │ │ ├── border.cpp │ │ ├── border.hpp │ │ ├── split-mesh.cpp │ │ └── split-mesh.hpp │ └── util │ │ ├── movement.cpp │ │ ├── movement.hpp │ │ ├── rotation.cpp │ │ ├── rotation.hpp │ │ ├── scaling.cpp │ │ ├── scaling.hpp │ │ ├── step.cpp │ │ └── step.hpp │ ├── tools.hpp │ ├── tree.hpp │ ├── util.cpp │ ├── util.hpp │ ├── variant.hpp │ ├── view │ ├── axis.cpp │ ├── axis.hpp │ ├── color-button.cpp │ ├── color-button.hpp │ ├── configuration.cpp │ ├── configuration.hpp │ ├── context-menu.cpp │ ├── context-menu.hpp │ ├── cursor.cpp │ ├── cursor.hpp │ ├── double-slider.cpp │ ├── double-slider.hpp │ ├── floor-plane.cpp │ ├── floor-plane.hpp │ ├── gl-widget.cpp │ ├── gl-widget.hpp │ ├── info-pane.cpp │ ├── info-pane.hpp │ ├── info-pane │ │ ├── scene.cpp │ │ └── scene.hpp │ ├── input.cpp │ ├── input.hpp │ ├── key-event.cpp │ ├── key-event.hpp │ ├── light.cpp │ ├── light.hpp │ ├── log.cpp │ ├── log.hpp │ ├── main-window.cpp │ ├── main-window.hpp │ ├── menu-bar.cpp │ ├── menu-bar.hpp │ ├── pointing-event.cpp │ ├── pointing-event.hpp │ ├── resolution-slider.cpp │ ├── resolution-slider.hpp │ ├── shortcut.cpp │ ├── shortcut.hpp │ ├── tool-pane.cpp │ ├── tool-pane.hpp │ ├── tool-tip.cpp │ ├── tool-tip.hpp │ ├── two-column-grid.cpp │ ├── two-column-grid.hpp │ ├── util.cpp │ ├── util.hpp │ ├── vector-edit.cpp │ └── vector-edit.hpp │ ├── xml-conversion.cpp │ └── xml-conversion.hpp ├── test ├── src │ ├── main.cpp │ ├── test-bitset.cpp │ ├── test-bitset.hpp │ ├── test-distance.cpp │ ├── test-distance.hpp │ ├── test-intersection.cpp │ ├── test-intersection.hpp │ ├── test-maybe.cpp │ ├── test-maybe.hpp │ ├── test-misc.cpp │ ├── test-misc.hpp │ ├── test-octree.cpp │ ├── test-octree.hpp │ ├── test-prune.cpp │ ├── test-prune.hpp │ ├── test-tree.cpp │ └── test-tree.hpp └── test.pro ├── unix ├── dilay.desktop ├── docker │ ├── appimage │ │ ├── Dockerfile │ │ └── entrypoint.sh │ ├── debian-sid │ │ ├── Dockerfile │ │ └── entrypoint.sh │ ├── ubuntu-bionic │ │ ├── Dockerfile │ │ └── entrypoint.sh │ ├── ubuntu-trusty │ │ ├── Dockerfile │ │ └── entrypoint.sh │ └── ubuntu-xenial │ │ ├── Dockerfile │ │ └── entrypoint.sh └── icon │ ├── 16x16 │ └── dilay.png │ ├── 256x256 │ └── dilay.png │ ├── 32x32 │ └── dilay.png │ └── 48x48 │ └── dilay.png └── win32 ├── LICENSE.rtf ├── deploy.bat ├── icon.ico └── installer.wix /.clang-format: -------------------------------------------------------------------------------- 1 | Language: Cpp 2 | AccessModifierOffset: -2 3 | AlignAfterOpenBracket: Align 4 | AlignConsecutiveAssignments: false 5 | AlignConsecutiveDeclarations: true 6 | AlignEscapedNewlinesLeft: true 7 | AlignOperands: true 8 | AlignTrailingComments: true 9 | AllowAllParametersOfDeclarationOnNextLine: true 10 | AllowShortBlocksOnASingleLine: false 11 | AllowShortCaseLabelsOnASingleLine: false 12 | AllowShortFunctionsOnASingleLine: All 13 | AllowShortIfStatementsOnASingleLine: false 14 | AllowShortLoopsOnASingleLine: false 15 | AlwaysBreakAfterReturnType: None 16 | AlwaysBreakBeforeMultilineStrings: false 17 | AlwaysBreakTemplateDeclarations: false 18 | BinPackArguments: true 19 | BinPackParameters: true 20 | BreakBeforeBinaryOperators: None 21 | BreakBeforeBraces: Allman 22 | BreakBeforeTernaryOperators: true 23 | BreakConstructorInitializersBeforeComma: true 24 | BreakStringLiterals: false 25 | ColumnLimit: 100 26 | CommentPragmas: '^ IWYU pragma:' 27 | ConstructorInitializerAllOnOneLineOrOnePerLine: false 28 | ConstructorInitializerIndentWidth: 2 29 | ContinuationIndentWidth: 2 30 | Cpp11BracedListStyle: true 31 | DerivePointerAlignment: false 32 | DisableFormat: false 33 | ExperimentalAutoDetectBinPacking: false 34 | FixNamespaceComments: false 35 | ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ] 36 | IncludeCategories: 37 | - Regex: '^"' 38 | Priority: 0 39 | - Regex: '^<' 40 | Priority: -1 41 | - Regex: '.*' 42 | Priority: 1 43 | IncludeIsMainRegex: '$' 44 | IndentCaseLabels: true 45 | IndentWidth: 2 46 | IndentWrappedFunctionNames: false 47 | KeepEmptyLinesAtTheStartOfBlocks: false 48 | MacroBlockBegin: '' 49 | MacroBlockEnd: '' 50 | MaxEmptyLinesToKeep: 1 51 | NamespaceIndentation: All 52 | PenaltyBreakBeforeFirstCallParameter: 19 53 | PenaltyBreakComment: 300 54 | PenaltyBreakFirstLessLess: 120 55 | PenaltyBreakString: 1000 56 | PenaltyExcessCharacter: 1000000 57 | PenaltyReturnTypeOnItsOwnLine: 60 58 | PointerAlignment: Left 59 | ReflowComments: true 60 | SortIncludes: true 61 | SpaceAfterCStyleCast: true 62 | SpaceBeforeAssignmentOperators: true 63 | SpaceBeforeParens: Always 64 | SpaceInEmptyParentheses: false 65 | SpacesBeforeTrailingComments: 2 66 | SpacesInAngles: false 67 | SpacesInContainerLiterals: false 68 | SpacesInCStyleCastParentheses: false 69 | SpacesInParentheses: false 70 | SpacesInSquareBrackets: false 71 | Standard: Cpp11 72 | UseTab: Never 73 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | obj/ 2 | moc/ 3 | dilay 4 | dilay_debug 5 | Makefile 6 | archive/ 7 | i18n/*.qm 8 | run-tests 9 | lib/Makefile 10 | lib/Makefile.Release 11 | lib/Makefile.Debug 12 | lib/libdilay.a 13 | app/Makefile 14 | app/Makefile.Release 15 | app/Makefile.Debug 16 | app/translations 17 | test/Makefile 18 | test/Makefile.Release 19 | test/Makefile.Debug 20 | valgrind.log 21 | .qmake.stash 22 | icon.pdf 23 | icon.png 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Dilay - a 3D sculpting application 2 | 3 | **Project website:** https://abau.org/dilay 4 | 5 | **Building instructions:** https://abau.org/dilay/manual.html#installing 6 | -------------------------------------------------------------------------------- /app/app.pro: -------------------------------------------------------------------------------- 1 | include (../common.pri) 2 | 3 | TEMPLATE = app 4 | DESTDIR = $$OUT_PWD/.. 5 | DEPENDPATH += src 6 | INCLUDEPATH += src $$PWD/../lib/src 7 | SOURCES += src/main.cpp 8 | 9 | CONFIG(release, debug|release): TARGET = dilay 10 | CONFIG(debug , debug|release): TARGET = dilay_debug 11 | 12 | win32 { 13 | CONFIG(release, debug|release) { 14 | LIBS += -L$$OUT_PWD/../lib/release/ -ldilay 15 | 16 | win32-g++ { 17 | PRE_TARGETDEPS += $$OUT_PWD/../lib/release/libdilay.a 18 | } 19 | else { 20 | PRE_TARGETDEPS += $$OUT_PWD/../lib/release/dilay.lib 21 | } 22 | } 23 | CONFIG(debug, debug|release) { 24 | LIBS += -L$$OUT_PWD/../lib/debug/ -ldilay 25 | 26 | win32-g++ { 27 | PRE_TARGETDEPS += $$OUT_PWD/../lib/debug/libdilay.a 28 | } 29 | else { 30 | PRE_TARGETDEPS += $$OUT_PWD/../lib/debug/dilay.lib 31 | } 32 | } 33 | RC_ICONS = $$PWD/../win32/icon.ico 34 | 35 | QMAKE_POST_LINK += $$PWD/../win32/deploy.bat $$shell_path($$[QT_INSTALL_PREFIX]) \ 36 | $$shell_path($$DESTDIR) \ 37 | $$shell_path($$PWD/../) \ 38 | $$VERSION 39 | } 40 | 41 | unix { 42 | LIBS += -L$$OUT_PWD/../lib/ -ldilay 43 | PRE_TARGETDEPS += $$OUT_PWD/../lib/libdilay.a 44 | 45 | target.path = $$PREFIX/bin/ 46 | INSTALLS += target 47 | 48 | desktop.path = $$PREFIX/share/applications/ 49 | desktop.files = ../unix/dilay.desktop 50 | INSTALLS += desktop 51 | 52 | icon16.path = $$PREFIX/share/icons/hicolor/16x16/apps/ 53 | icon16.files = ../unix/icon/16x16/dilay.png 54 | INSTALLS += icon16 55 | 56 | icon32.path = $$PREFIX/share/icons/hicolor/32x32/apps/ 57 | icon32.files = ../unix/icon/32x32/dilay.png 58 | INSTALLS += icon32 59 | 60 | icon48.path = $$PREFIX/share/icons/hicolor/48x48/apps/ 61 | icon48.files = ../unix/icon/48x48/dilay.png 62 | INSTALLS += icon48 63 | 64 | icon256.path = $$PREFIX/share/icons/hicolor/256x256/apps/ 65 | icon256.files = ../unix/icon/256x256/dilay.png 66 | INSTALLS += icon256 67 | 68 | format.commands = clang-format -style=file -i $$SOURCES $$HEADERS 69 | QMAKE_EXTRA_TARGETS += format 70 | } 71 | -------------------------------------------------------------------------------- /app/src/main.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include "cache.hpp" 10 | #include "config.hpp" 11 | #include "opengl.hpp" 12 | #include "time-delta.hpp" 13 | #include "util.hpp" 14 | #include "view/log.hpp" 15 | #include "view/main-window.hpp" 16 | 17 | namespace 18 | { 19 | QString configPath () 20 | { 21 | return QStandardPaths::locate (QStandardPaths::ConfigLocation, "dilay.config"); 22 | } 23 | 24 | void backupCrashLog () 25 | { 26 | QFile log (ViewLog::logPath ()); 27 | QFile crashLog (ViewLog::crashLogPath ()); 28 | 29 | if (log.exists ()) 30 | { 31 | if (crashLog.exists ()) 32 | { 33 | crashLog.remove (); 34 | } 35 | log.rename (ViewLog::crashLogPath ()); 36 | } 37 | } 38 | } 39 | 40 | int main (int argv, char** args) 41 | { 42 | backupCrashLog (); 43 | Log::initialize (ViewLog::logPath ().toStdString ()); 44 | DILAY_INFO ("Version: %s", DILAY_VERSION); 45 | DILAY_INFO ("Architecture: %s", QSysInfo::buildCpuArchitecture ().toStdString ().c_str ()); 46 | DILAY_INFO ("OS: %s", QSysInfo::prettyProductName ().toStdString ().c_str ()); 47 | DILAY_INFO ("Qt: %s", QLibraryInfo::version ().toString ().toStdString ().c_str ()); 48 | 49 | QCoreApplication::setApplicationName ("Dilay"); 50 | QCoreApplication::setAttribute (Qt::AA_UseDesktopOpenGL); 51 | OpenGL::setDefaultFormat (); 52 | 53 | QApplication app (argv, args); 54 | Config config; 55 | Cache cache; 56 | 57 | if (configPath ().isEmpty () == false) 58 | { 59 | config.fromFile (configPath ().toStdString ()); 60 | } 61 | 62 | ViewMainWindow mainWindow (config, cache); 63 | mainWindow.resize (config.get ("window/initial-width"), 64 | config.get ("window/initial-height")); 65 | mainWindow.show (); 66 | 67 | QObject::connect (&app, &QApplication::aboutToQuit, [&config]() { 68 | const QString configDirName (QStandardPaths::writableLocation (QStandardPaths::ConfigLocation)); 69 | const QDir configDir (configDirName); 70 | 71 | if (configDirName.isEmpty () == false) 72 | { 73 | if (configDir.exists () == false) 74 | { 75 | configDir.mkpath ("."); 76 | } 77 | config.toFile (configDir.filePath ("dilay.config").toStdString ()); 78 | } 79 | }); 80 | TimeDelta::initialize (); 81 | return app.exec (); 82 | } 83 | -------------------------------------------------------------------------------- /common.pri: -------------------------------------------------------------------------------- 1 | VERSION = 1.9.0 2 | CONFIG += debug_and_release warn_on object_parallel_to_source ordered c++14 3 | QT += widgets opengl openglextensions xml 4 | MOC_DIR = moc 5 | OBJECTS_DIR = obj 6 | QMAKE_CXXFLAGS += -DDILAY_VERSION=\\\"$$VERSION\\\" -DGLM_FORCE_RADIANS -DGLM_ENABLE_EXPERIMENTAL 7 | QMAKE_CXXFLAGS_RELEASE += -DNDEBUG 8 | QMAKE_CXXFLAGS_DEBUG += -Wall # -pg # -DDILAY_RENDER_OCTREE 9 | QMAKE_LFLAGS_DEBUG += # -pg 10 | 11 | win32:INCLUDEPATH += $$PWD/glm/ 12 | 13 | unix { 14 | isEmpty (PREFIX) { 15 | PREFIX = /usr/local 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /dilay.pro: -------------------------------------------------------------------------------- 1 | CONFIG += debug_and_release 2 | TEMPLATE = subdirs 3 | SUBDIRS = lib app test 4 | 5 | app.depends = lib 6 | test.depends = lib 7 | 8 | disable-test { 9 | SUBDIRS -= test 10 | } 11 | 12 | disable-app { 13 | SUBDIRS -= app 14 | } 15 | 16 | unix { 17 | gdb.commands = gdb -ex run ./dilay_debug 18 | valgrind.commands = valgrind ./dilay_debug &> valgrind.log 19 | leak.commands = valgrind --leak-check=yes ./dilay_debug &> valgrind.log 20 | format.CONFIG = recursive 21 | copyright.commands = find $$SUBDIRS \\( -name "*.cpp" -o -name "*.hpp" -o -name "*.hs" \\) -print0 | \ 22 | xargs -0 sed -i 's/Copyright\ ©\ 2015-2017/Copyright\ ©\ 2015-2018/' 23 | 24 | docker.commands = docker build -t dilay-$(IMAGE) unix/docker/$(IMAGE) && \ 25 | docker run --rm --mount type=bind,src=$$(PWD),dst=/dilay dilay-$(IMAGE) 26 | 27 | QMAKE_EXTRA_TARGETS += gdb valgrind leak format copyright icon docker 28 | } 29 | -------------------------------------------------------------------------------- /icon.tex: -------------------------------------------------------------------------------- 1 | \documentclass[crop,tikz,convert={size=512x512,outext=.png}]{standalone} 2 | \usetikzlibrary{shapes.geometric} 3 | \begin{document} 4 | \begin{tikzpicture} 5 | [linestyle/.style={draw=black!80,line width=5pt,transform shape}, 6 | emptylinestyle/.style={transform shape}, 7 | circlestyle/.style={fill=black!80,circle,minimum size=10pt}] 8 | 9 | \begin{scope}[rotate=-10] 10 | \shadedraw [shading=ball, ball color=black!10] (0,0) circle (101pt); 11 | 12 | \node[linestyle,circle,minimum size=201pt] {}; 13 | \node[emptylinestyle,regular polygon, regular polygon sides=9,rotate=20, minimum size=200pt] (p) {}; 14 | \node[emptylinestyle, regular polygon, regular polygon sides=3,minimum size=120pt] (t) {}; 15 | \node[linestyle, regular polygon, regular polygon sides=3,minimum size=120pt] {}; 16 | 17 | \draw [linestyle] (t.corner 1) -- (p.corner 1); 18 | \draw [linestyle] (t.corner 1) -- (p.corner 2); 19 | \draw [linestyle] (t.corner 1) -- (p.corner 8); 20 | \draw [linestyle] (t.corner 1) -- (p.corner 9); 21 | \draw [linestyle] (t.corner 2) -- (p.corner 2); 22 | \draw [linestyle] (t.corner 2) -- (p.corner 3); 23 | \draw [linestyle] (t.corner 2) -- (p.corner 4); 24 | \draw [linestyle] (t.corner 2) -- (p.corner 5); 25 | \draw [linestyle] (t.corner 3) -- (p.corner 5); 26 | \draw [linestyle] (t.corner 3) -- (p.corner 6); 27 | \draw [linestyle] (t.corner 3) -- (p.corner 7); 28 | \draw [linestyle] (t.corner 3) -- (p.corner 8); 29 | 30 | \node [circlestyle] at (t.corner 1) {}; 31 | \node [circlestyle] at (t.corner 2) {}; 32 | \node [circlestyle] at (t.corner 3) {}; 33 | \node [circlestyle] at (p.corner 1) {}; 34 | \node [circlestyle] at (p.corner 2) {}; 35 | \node [circlestyle] at (p.corner 3) {}; 36 | \node [circlestyle] at (p.corner 4) {}; 37 | \node [circlestyle] at (p.corner 5) {}; 38 | \node [circlestyle] at (p.corner 6) {}; 39 | \node [circlestyle] at (p.corner 7) {}; 40 | \node [circlestyle] at (p.corner 8) {}; 41 | \node [circlestyle] at (p.corner 9) {}; 42 | \end{scope} 43 | \end{tikzpicture} 44 | \end{document} 45 | -------------------------------------------------------------------------------- /lib/src/bitset.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_BITSET 6 | #define DILAY_BITSET 7 | 8 | #include 9 | 10 | template class Bitset 11 | { 12 | public: 13 | Bitset () 14 | : _data (0) 15 | { 16 | } 17 | 18 | Bitset (const Bitset& other) 19 | : _data (other._data) 20 | { 21 | } 22 | 23 | template bool get () const 24 | { 25 | static_assert (N < sizeof (T) * 8, "invalid bitset index"); 26 | return this->_data & 1 << N; 27 | } 28 | 29 | template void set (bool value = true) 30 | { 31 | static_assert (N < sizeof (T) * 8, "invalid bitset index"); 32 | 33 | if (value) 34 | { 35 | this->_data = this->_data | 1 << N; 36 | } 37 | else 38 | { 39 | this->_data = this->_data & ~(1 << N); 40 | } 41 | } 42 | 43 | template void toggle () { this->set (!this->get ()); } 44 | 45 | template void reset () { this->set (false); } 46 | 47 | void reset () { this->_data = 0; } 48 | 49 | bool none () const { return this->_data == 0; } 50 | 51 | template bool all () const 52 | { 53 | static_assert (N < sizeof (T) * 8, "invalid bitset index"); 54 | 55 | const T allBits = std::pow (2, N) - 1; 56 | return (this->_data & allBits) == allBits; 57 | } 58 | 59 | T value () const { return this->_data; } 60 | 61 | private: 62 | T _data; 63 | }; 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /lib/src/cache.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_CACHE 6 | #define DILAY_CACHE 7 | 8 | #include "kvstore.hpp" 9 | 10 | class Cache 11 | { 12 | public: 13 | Cache () 14 | : store ("cache") 15 | { 16 | } 17 | 18 | template const T& get (const std::string& path, const T& value) const 19 | { 20 | return this->store.get (path, value); 21 | } 22 | 23 | template void set (const std::string& path, const T& value) 24 | { 25 | this->store.set (path, value); 26 | } 27 | 28 | private: 29 | KVStore store; 30 | }; 31 | 32 | class CacheProxy 33 | { 34 | public: 35 | CacheProxy (Cache& c, const std::string& p) 36 | : _cache (c) 37 | , prefix (p) 38 | { 39 | assert (p.back () == '/'); 40 | } 41 | 42 | CacheProxy (CacheProxy& o, const std::string& path) 43 | : CacheProxy (o._cache, o.prefix + path) 44 | { 45 | } 46 | 47 | Cache& cache () const { return this->_cache; } 48 | 49 | std::string key (const std::string& path) const { return this->prefix + path; } 50 | 51 | template const T& get (const std::string& path, const T& v) const 52 | { 53 | return this->_cache.get (this->key (path), v); 54 | } 55 | 56 | template void set (const std::string& path, const T& v) const 57 | { 58 | return this->_cache.set (this->key (path), v); 59 | } 60 | 61 | private: 62 | Cache& _cache; 63 | const std::string prefix; 64 | }; 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /lib/src/camera.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_CAMERA 6 | #define DILAY_CAMERA 7 | 8 | #include 9 | #include "configurable.hpp" 10 | #include "macro.hpp" 11 | 12 | enum class Dimension; 13 | class PrimRay; 14 | class Renderer; 15 | 16 | class Camera : public Configurable 17 | { 18 | public: 19 | DECLARE_BIG3 (Camera, const Config&) 20 | 21 | Renderer& renderer () const; 22 | const glm::uvec2& resolution () const; 23 | const glm::vec3& gazePoint () const; 24 | const glm::vec3& toEyePoint () const; 25 | glm::vec3 realUp () const; 26 | const glm::vec3& right () const; 27 | const glm::mat4x4& view () const; 28 | const glm::mat4x4& viewRotation () const; 29 | glm::vec3 position () const; 30 | glm::mat4x4 world () const; 31 | 32 | void updateResolution (const glm::uvec2&); 33 | void setModelViewProjection (const glm::mat4x4&, const glm::mat3x3&, bool); 34 | 35 | void set (const glm::vec3&, const glm::vec3&); 36 | void setGaze (const glm::vec3&); 37 | void stepAlongGaze (float); 38 | void verticalRotation (float); 39 | void horizontalRotation (float); 40 | glm::vec2 fromWorld (const glm::vec3&, const glm::mat4x4&, bool) const; 41 | glm::vec3 toWorld (const glm::ivec2&, float = 0.0f) const; 42 | float toWorld (float, float = 0.0f) const; 43 | PrimRay ray (const glm::ivec2&) const; 44 | Dimension primaryDimension () const; 45 | glm::vec3 viewPlaneIntersection (const glm::ivec2&) const; 46 | glm::vec3 primaryPlaneIntersection (const glm::ivec2&) const; 47 | 48 | private: 49 | IMPLEMENTATION 50 | 51 | void runFromConfig (const Config&); 52 | }; 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /lib/src/color.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #include 6 | #include 7 | #include "color.hpp" 8 | #include "util.hpp" 9 | 10 | Color::Color (float r, float g, float b, float o) 11 | : _r (r) 12 | , _g (g) 13 | , _b (b) 14 | , _opacity (o) 15 | { 16 | } 17 | 18 | Color::Color () 19 | : Color (0.0f, 0.0f, 0.0f, 1.0f) 20 | { 21 | } 22 | 23 | Color::Color (float v) 24 | : Color (v, v, v, 1.0f) 25 | { 26 | } 27 | 28 | Color::Color (float r, float g, float b) 29 | : Color (r, g, b, 1.0f) 30 | { 31 | } 32 | 33 | Color::Color (const glm::vec3& v) 34 | : Color (v.x, v.y, v.z) 35 | { 36 | } 37 | 38 | Color::Color (const glm::vec4& v) 39 | : Color (v.x, v.y, v.z, v.w) 40 | { 41 | } 42 | 43 | Color::Color (const QColor& c) 44 | : Color (c.redF (), c.greenF (), c.blueF (), c.alphaF ()) 45 | { 46 | } 47 | 48 | Color::Color (const Color& c, float f) 49 | : Color (c) 50 | { 51 | this->scale (f); 52 | } 53 | 54 | Color Color::Black () { return Color (0.0f, 0.0f, 0.0f); } 55 | 56 | Color Color::White () { return Color (1.0f, 1.0f, 1.0f); } 57 | 58 | Color Color::Red () { return Color (1.0f, 0.0f, 0.0f); } 59 | 60 | Color Color::Green () { return Color (0.0f, 1.0f, 0.0f); } 61 | 62 | Color Color::Blue () { return Color (0.0f, 0.0f, 1.0f); } 63 | 64 | float Color::r () const { return this->_r; } 65 | 66 | float Color::g () const { return this->_g; } 67 | 68 | float Color::b () const { return this->_b; } 69 | 70 | float Color::opacity () const { return this->_opacity; } 71 | 72 | void Color::r (float v) { this->_r = v; } 73 | 74 | void Color::g (float v) { this->_g = v; } 75 | 76 | void Color::b (float v) { this->_b = v; } 77 | 78 | void Color::opacity (float v) { this->_opacity = v; } 79 | 80 | void Color::scale (float f) 81 | { 82 | this->_r = f * this->_r; 83 | this->_g = f * this->_g; 84 | this->_b = f * this->_b; 85 | } 86 | 87 | glm::vec3 Color::vec3 () const { return glm::vec3 (this->_r, this->_g, this->_b); } 88 | 89 | glm::vec4 Color::vec4 () const { return glm::vec4 (this->_r, this->_g, this->_b, this->_opacity); } 90 | 91 | QColor Color::qColor () const 92 | { 93 | return QColor (glm::min (255, int(255.0f * this->_r)), glm::min (255, int(255.0f * this->_g)), 94 | glm::min (255, int(255.0f * this->_b)), 95 | glm::min (255, int(255.0f * this->_opacity))); 96 | } 97 | 98 | bool Color::isOpaque () const { return Util::almostEqual (this->_opacity, 1.0f); } 99 | -------------------------------------------------------------------------------- /lib/src/color.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_COLOR 6 | #define DILAY_COLOR 7 | 8 | #include 9 | 10 | class QColor; 11 | 12 | class Color 13 | { 14 | public: 15 | Color (); 16 | Color (float); 17 | Color (float, float, float); 18 | Color (float, float, float, float); 19 | explicit Color (const glm::vec3&); 20 | explicit Color (const glm::vec4&); 21 | explicit Color (const QColor&); 22 | 23 | // copies and scales a color using `scale` 24 | Color (const Color&, float); 25 | 26 | static Color Black (); 27 | static Color White (); 28 | static Color Red (); 29 | static Color Green (); 30 | static Color Blue (); 31 | 32 | float r () const; 33 | float g () const; 34 | float b () const; 35 | float opacity () const; 36 | 37 | void r (float); 38 | void g (float); 39 | void b (float); 40 | void opacity (float); 41 | 42 | // `scale` does not scale opacity 43 | void scale (float); 44 | 45 | glm::vec3 vec3 () const; 46 | glm::vec4 vec4 () const; 47 | QColor qColor () const; 48 | bool isOpaque () const; 49 | 50 | private: 51 | float _r; 52 | float _g; 53 | float _b; 54 | float _opacity; 55 | }; 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /lib/src/config.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_CONFIG 6 | #define DILAY_CONFIG 7 | 8 | #include "kvstore.hpp" 9 | 10 | class Config 11 | { 12 | public: 13 | Config (); 14 | 15 | template const T& get (const std::string& path) const 16 | { 17 | return this->store.get (path); 18 | } 19 | 20 | template void set (const std::string& path, const T& value) 21 | { 22 | this->store.set (path, value); 23 | } 24 | 25 | void fromFile (const std::string& fileName) 26 | { 27 | this->store.fromFile (fileName); 28 | this->update (); 29 | } 30 | 31 | void toFile (const std::string& fileName) const { this->store.toFile (fileName); } 32 | 33 | void remove (const std::string& path) { this->store.remove (path); } 34 | 35 | void restoreDefaults (); 36 | 37 | private: 38 | void update (); 39 | 40 | KVStore store; 41 | }; 42 | 43 | class ConfigProxy 44 | { 45 | public: 46 | ConfigProxy (const Config& c, const std::string& p) 47 | : _config (c) 48 | , prefix (p) 49 | { 50 | assert (p.back () == '/'); 51 | } 52 | 53 | ConfigProxy (const ConfigProxy& o, const std::string& path) 54 | : ConfigProxy (o._config, o.prefix + path) 55 | { 56 | } 57 | 58 | const Config& config () const { return this->_config; } 59 | 60 | std::string key (const std::string& path) const { return this->prefix + path; } 61 | 62 | template const T& get (const std::string& path) const 63 | { 64 | return this->_config.get (this->key (path)); 65 | } 66 | 67 | private: 68 | const Config& _config; 69 | const std::string prefix; 70 | }; 71 | 72 | #endif 73 | -------------------------------------------------------------------------------- /lib/src/configurable.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #include "configurable.hpp" 6 | 7 | void Configurable::fromConfig (const Config& c) { this->runFromConfig (c); } 8 | 9 | void ProxyConfigurable::fromConfig (const ConfigProxy& c) { this->runFromConfig (c); } 10 | -------------------------------------------------------------------------------- /lib/src/configurable.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_CONFIGURABLE 6 | #define DILAY_CONFIGURABLE 7 | 8 | class Config; 9 | class ConfigProxy; 10 | 11 | class Configurable 12 | { 13 | public: 14 | void fromConfig (const Config&); 15 | 16 | private: 17 | virtual void runFromConfig (const Config&) = 0; 18 | }; 19 | 20 | class ProxyConfigurable 21 | { 22 | public: 23 | void fromConfig (const ConfigProxy&); 24 | 25 | private: 26 | virtual void runFromConfig (const ConfigProxy&) = 0; 27 | }; 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /lib/src/dimension.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #include 6 | #include 7 | #include "dimension.hpp" 8 | #include "util.hpp" 9 | 10 | unsigned int DimensionUtil::index (Dimension d) 11 | { 12 | switch (d) 13 | { 14 | case Dimension::X: 15 | return 0; 16 | case Dimension::Y: 17 | return 1; 18 | case Dimension::Z: 19 | return 2; 20 | } 21 | DILAY_IMPOSSIBLE 22 | } 23 | 24 | glm::vec3 DimensionUtil::vector (Dimension d) 25 | { 26 | switch (d) 27 | { 28 | case Dimension::X: 29 | return glm::vec3 (1.0f, 0.0f, 0.0f); 30 | case Dimension::Y: 31 | return glm::vec3 (0.0f, 1.0f, 0.0f); 32 | case Dimension::Z: 33 | return glm::vec3 (0.0f, 0.0f, 1.0f); 34 | } 35 | DILAY_IMPOSSIBLE 36 | } 37 | -------------------------------------------------------------------------------- /lib/src/dimension.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_DIMENSION 6 | #define DILAY_DIMENSION 7 | 8 | #include 9 | 10 | enum class Dimension 11 | { 12 | X, 13 | Y, 14 | Z 15 | }; 16 | 17 | namespace DimensionUtil 18 | { 19 | unsigned int index (Dimension); 20 | glm::vec3 vector (Dimension); 21 | } 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /lib/src/distance.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_DISTANCE 6 | #define DILAY_DISTANCE 7 | 8 | #include 9 | 10 | class PrimCone; 11 | class PrimConeSphere; 12 | class PrimCylinder; 13 | class PrimSphere; 14 | class PrimTriangle; 15 | 16 | namespace Distance 17 | { 18 | float distance (const PrimSphere&, const glm::vec3&); 19 | float distance (const PrimCylinder&, const glm::vec3&); 20 | float distance (const PrimCone&, const glm::vec3&); 21 | float distance (const PrimConeSphere&, const glm::vec3&); 22 | float distance (const PrimTriangle&, const glm::vec3&); 23 | } 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /lib/src/dynamic/faces.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #include "dynamic/faces.hpp" 6 | 7 | void DynamicFaces::insert (unsigned int i) { this->_uncommitted.insert (i); } 8 | 9 | void DynamicFaces::insert (const DynamicFaces::Container& v) 10 | { 11 | this->_uncommitted.insert (v.begin (), v.end ()); 12 | } 13 | 14 | void DynamicFaces::reset () 15 | { 16 | this->resetCommitted (); 17 | this->_uncommitted.clear (); 18 | } 19 | 20 | void DynamicFaces::resetCommitted () { this->_indices.clear (); } 21 | 22 | void DynamicFaces::commit () 23 | { 24 | if (this->_indices.empty ()) 25 | { 26 | this->_indices.swap (this->_uncommitted); 27 | } 28 | else 29 | { 30 | this->_indices.insert (this->_uncommitted.begin (), this->_uncommitted.end ()); 31 | this->_uncommitted.clear (); 32 | } 33 | } 34 | 35 | bool DynamicFaces::contains (unsigned int i) const 36 | { 37 | return this->_indices.find (i) != this->_indices.end (); 38 | } 39 | 40 | bool DynamicFaces::isEmpty () const 41 | { 42 | return this->_indices.empty () && this->_uncommitted.empty (); 43 | } 44 | 45 | bool DynamicFaces::hasUncomitted () const { return this->_uncommitted.empty () == false; } 46 | 47 | void DynamicFaces::filter (const std::function& f) 48 | { 49 | for (auto it = this->_indices.begin (); it != this->_indices.end ();) 50 | { 51 | if (f (*it) == false) 52 | { 53 | it = this->_indices.erase (it); 54 | } 55 | else 56 | { 57 | ++it; 58 | } 59 | } 60 | for (auto it = this->_uncommitted.begin (); it != this->_uncommitted.end ();) 61 | { 62 | if (f (*it) == false) 63 | { 64 | it = this->_uncommitted.erase (it); 65 | } 66 | else 67 | { 68 | ++it; 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /lib/src/dynamic/faces.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_DYNAMIC_FACES 6 | #define DILAY_DYNAMIC_FACES 7 | 8 | #include 9 | #include 10 | 11 | class DynamicFaces 12 | { 13 | public: 14 | typedef std::unordered_set Container; 15 | 16 | const Container& indices () const { return this->_indices; } 17 | const Container& uncommitted () const { return this->_uncommitted; } 18 | unsigned int numElements () const { return this->_indices.size (); } 19 | 20 | Container::iterator begin () { return this->_indices.begin (); } 21 | Container::iterator end () { return this->_indices.end (); } 22 | Container::const_iterator begin () const { return this->_indices.begin (); } 23 | Container::const_iterator end () const { return this->_indices.end (); } 24 | 25 | void insert (unsigned int); 26 | void insert (const Container&); 27 | void reset (); 28 | void resetCommitted (); 29 | void commit (); 30 | bool contains (unsigned int) const; 31 | bool isEmpty () const; 32 | bool hasUncomitted () const; 33 | void filter (const std::function&); 34 | 35 | private: 36 | Container _indices; 37 | Container _uncommitted; 38 | }; 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /lib/src/dynamic/mesh-intersection.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #include "dynamic/mesh-intersection.hpp" 6 | #include "dynamic/mesh.hpp" 7 | #include "util.hpp" 8 | 9 | DynamicMeshIntersection::DynamicMeshIntersection () 10 | : _faceIndex (Util::invalidIndex ()) 11 | , _mesh (nullptr) 12 | { 13 | } 14 | 15 | bool DynamicMeshIntersection::update (float d, const glm::vec3& p, const glm::vec3& n, 16 | unsigned int i, DynamicMesh& mesh) 17 | { 18 | if (this->Intersection::update (d, p, n)) 19 | { 20 | this->_mesh = &mesh; 21 | this->_faceIndex = i; 22 | return true; 23 | } 24 | else 25 | { 26 | return false; 27 | } 28 | } 29 | 30 | unsigned int DynamicMeshIntersection::faceIndex () const 31 | { 32 | assert (this->isIntersection ()); 33 | return this->_faceIndex; 34 | } 35 | 36 | DynamicMesh& DynamicMeshIntersection::mesh () const 37 | { 38 | assert (this->isIntersection ()); 39 | assert (this->_mesh); 40 | return *this->_mesh; 41 | } 42 | -------------------------------------------------------------------------------- /lib/src/dynamic/mesh-intersection.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_DYNAMIC_MESH_INTERSECTION 6 | #define DILAY_DYNAMIC_MESH_INTERSECTION 7 | 8 | #include "intersection.hpp" 9 | 10 | class DynamicMesh; 11 | 12 | class DynamicMeshIntersection : public Intersection 13 | { 14 | public: 15 | DynamicMeshIntersection (); 16 | 17 | DynamicMesh& mesh () const; 18 | unsigned int faceIndex () const; 19 | bool update (float, const glm::vec3&, const glm::vec3&, unsigned int, DynamicMesh&); 20 | 21 | private: 22 | unsigned int _faceIndex; 23 | DynamicMesh* _mesh; 24 | }; 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /lib/src/dynamic/octree.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_DYNAMIC_OCTREE 6 | #define DILAY_DYNAMIC_OCTREE 7 | 8 | #include 9 | #include 10 | #include 11 | #include "macro.hpp" 12 | 13 | class Camera; 14 | class PrimAABox; 15 | class PrimPlane; 16 | class PrimRay; 17 | class PrimSphere; 18 | 19 | class DynamicOctree 20 | { 21 | public: 22 | DECLARE_BIG4_EXPLICIT_COPY (DynamicOctree) 23 | 24 | typedef std::function IntersectionCallback; 25 | typedef std::function RayIntersectionCallback; 26 | typedef std::function ContainsIntersectionCallback; 27 | typedef std::function DistanceCallback; 28 | 29 | bool hasRoot () const; 30 | void setupRoot (const glm::vec3&, float); 31 | void addElement (unsigned int, const glm::vec3&, float); 32 | void realignElement (unsigned int, const glm::vec3&, float); 33 | void deleteElement (unsigned int); 34 | void deleteEmptyChildren (); 35 | void updateIndices (const std::vector&); 36 | void shrinkRoot (); 37 | void reset (); 38 | void render (Camera&) const; 39 | void intersects (const PrimRay&, const RayIntersectionCallback&) const; 40 | void intersects (const PrimPlane&, const IntersectionCallback&) const; 41 | void intersects (const PrimSphere&, const ContainsIntersectionCallback&) const; 42 | void intersects (const PrimAABox&, const ContainsIntersectionCallback&) const; 43 | float distance (const glm::vec3&, const DistanceCallback&) const; 44 | void printStatistics () const; 45 | 46 | private: 47 | IMPLEMENTATION 48 | }; 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /lib/src/hash.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_HASH 6 | #define DILAY_HASH 7 | 8 | #include 9 | #include 10 | 11 | namespace Hash 12 | { 13 | // cf. `http://www.boost.org/doc/libs/1_55_0/boost/functional/hash/hash.hpp` 14 | template void combine (std::size_t& seed, const T& value) 15 | { 16 | seed ^= std::hash () (value) + 0x9e3779b9 + (seed << 6) + (seed >> 2); 17 | } 18 | } 19 | 20 | namespace std 21 | { 22 | template struct hash> 23 | { 24 | size_t operator() (const std::pair& pair) const 25 | { 26 | size_t seed = 0; 27 | Hash::combine (seed, pair.first); 28 | Hash::combine (seed, pair.second); 29 | return seed; 30 | } 31 | }; 32 | } 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /lib/src/history.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_HISTORY 6 | #define DILAY_HISTORY 7 | 8 | #include 9 | #include "configurable.hpp" 10 | #include "macro.hpp" 11 | 12 | class DynamicMesh; 13 | class Scene; 14 | class State; 15 | 16 | class History : public Configurable 17 | { 18 | public: 19 | DECLARE_BIG3 (History, const Config&) 20 | 21 | void snapshotAll (const Scene&); 22 | void snapshotDynamicMeshes (const Scene&); 23 | void snapshotSketchMeshes (const Scene&); 24 | void dropPastSnapshot (); 25 | void dropFutureSnapshot (); 26 | void undo (State&); 27 | void redo (State&); 28 | bool hasRecentDynamicMesh () const; 29 | void forEachRecentDynamicMesh (const std::function&) const; 30 | void reset (); 31 | 32 | private: 33 | IMPLEMENTATION 34 | 35 | void runFromConfig (const Config&); 36 | }; 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /lib/src/import-export.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_IMPORT_EXPORT 6 | #define DILAY_IMPORT_EXPORT 7 | 8 | #include 9 | #include 10 | 11 | class Config; 12 | class Scene; 13 | 14 | namespace ImportExport 15 | { 16 | void toDlyFile (std::ostream&, Scene&, bool); 17 | bool toDlyFile (const std::string&, Scene&, bool); 18 | bool fromDlyFile (std::istream&, const Config&, Scene&); 19 | bool fromDlyFile (const std::string&, const Config&, Scene&); 20 | }; 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /lib/src/intersection.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_INTERSECTION 6 | #define DILAY_INTERSECTION 7 | 8 | #include 9 | 10 | class PrimAABox; 11 | class PrimCone; 12 | class PrimCylinder; 13 | class PrimPlane; 14 | class PrimRay; 15 | class PrimSphere; 16 | class PrimTriangle; 17 | 18 | class Intersection 19 | { 20 | public: 21 | Intersection (); 22 | 23 | bool isIntersection () const; 24 | const glm::vec3& position () const; 25 | const glm::vec3& normal () const; 26 | float distance () const; 27 | 28 | void reset (); 29 | bool update (float, const glm::vec3&, const glm::vec3&); 30 | 31 | static Intersection& min (Intersection&, Intersection&); 32 | static void sort (Intersection&, Intersection&); 33 | 34 | private: 35 | bool _isIntersection; 36 | float _distance; 37 | glm::vec3 _position; 38 | glm::vec3 _normal; 39 | }; 40 | 41 | namespace IntersectionUtil 42 | { 43 | bool intersects (const PrimSphere&, const PrimTriangle&); 44 | bool intersects (const PrimSphere&, const PrimAABox&); 45 | bool intersects (const PrimSphere&, const PrimSphere&); 46 | bool intersects (const PrimRay&, const PrimSphere&, float*); 47 | bool intersects (const PrimRay&, const PrimPlane&, float*); 48 | bool intersects (const PrimRay&, const PrimTriangle&, bool, float*); 49 | bool intersects (const PrimRay&, const PrimAABox&, float*); 50 | bool intersects (const PrimRay&, const PrimCylinder&, float*, float*); 51 | bool intersects (const PrimRay&, const PrimCone&, float*, float*); 52 | bool intersects (const PrimPlane&, const PrimAABox&); 53 | bool intersects (const PrimPlane&, const PrimTriangle&); 54 | bool intersects (const PrimCylinder&, const glm::vec3&); 55 | bool intersects (const PrimCone&, const glm::vec3&); 56 | bool intersects (const PrimAABox&, const PrimAABox&); 57 | bool intersects (const PrimAABox&, const PrimTriangle&); 58 | } 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /lib/src/isosurface-extraction.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_ISOSURFACE_EXTRACTION 6 | #define DILAY_ISOSURFACE_EXTRACTION 7 | 8 | #include 9 | #include 10 | 11 | class DynamicMesh; 12 | class Intersection; 13 | class PrimAABox; 14 | class PrimRay; 15 | 16 | namespace IsosurfaceExtraction 17 | { 18 | enum class Intersection 19 | { 20 | None, 21 | Sample, 22 | Continue 23 | }; 24 | 25 | typedef std::function DistanceCallback; 26 | typedef std::function IntersectionCallback; 27 | 28 | void extract (const DistanceCallback&, const IntersectionCallback&, const PrimAABox&, float, 29 | DynamicMesh&); 30 | void extract (const DistanceCallback&, const PrimAABox&, float, DynamicMesh&); 31 | }; 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /lib/src/isosurface-extraction/grid.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_ISOSURFACE_EXTRACTION_GRID 6 | #define DILAY_ISOSURFACE_EXTRACTION_GRID 7 | 8 | #include 9 | #include 10 | #include "macro.hpp" 11 | 12 | class DynamicMesh; 13 | class PrimAABox; 14 | 15 | class IsosurfaceExtractionGrid 16 | { 17 | public: 18 | static const unsigned char vertexIndicesByEdge[12][2]; 19 | 20 | DECLARE_BIG4_EXPLICIT_COPY (IsosurfaceExtractionGrid, const PrimAABox&, float) 21 | 22 | float resolution () const; 23 | const glm::uvec3& numSamples () const; 24 | const glm::uvec3& numCubes () const; 25 | std::vector& samples (); 26 | 27 | glm::vec3 samplePos (unsigned int, unsigned int, unsigned int) const; 28 | glm::vec3 samplePos (unsigned int) const; 29 | unsigned int sampleIndex (unsigned int, unsigned int, unsigned int) const; 30 | unsigned int sampleIndex (unsigned int, unsigned char) const; 31 | unsigned int cubeIndex (unsigned int, unsigned int, unsigned int) const; 32 | 33 | void makeMesh (DynamicMesh&); 34 | 35 | private: 36 | IMPLEMENTATION 37 | }; 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /lib/src/kvstore.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_KVSTORE 6 | #define DILAY_KVSTORE 7 | 8 | #include 9 | #include "macro.hpp" 10 | 11 | class KVStore 12 | { 13 | public: 14 | DECLARE_BIG2 (KVStore, const std::string&) 15 | 16 | template const T& get (const std::string&) const; 17 | template const T& get (const std::string&, const T&) const; 18 | template void set (const std::string&, const T&); 19 | 20 | void fromFile (const std::string&); 21 | void toFile (const std::string&) const; 22 | void remove (const std::string&); 23 | void reset (); 24 | 25 | private: 26 | IMPLEMENTATION 27 | }; 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /lib/src/log.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "log.hpp" 6 | #include "util.hpp" 7 | 8 | namespace 9 | { 10 | static std::FILE* fileHandle = nullptr; 11 | static std::string filePath; 12 | static std::time_t startTime; 13 | 14 | const char* levelToString (Log::Level level) 15 | { 16 | switch (level) 17 | { 18 | case Log::Level::Info: 19 | return "INFO"; 20 | case Log::Level::Warning: 21 | return "WARNING"; 22 | case Log::Level::Panic: 23 | return "PANIC"; 24 | } 25 | return nullptr; 26 | } 27 | 28 | void shutdown () 29 | { 30 | if (fileHandle) 31 | { 32 | std::fclose (fileHandle); 33 | std::remove (filePath.c_str ()); 34 | } 35 | } 36 | } 37 | 38 | namespace Log 39 | { 40 | void initialize (const std::string& path) 41 | { 42 | assert (fileHandle == nullptr); 43 | 44 | fileHandle = std::fopen (path.c_str (), "w"); 45 | 46 | if (fileHandle) 47 | { 48 | filePath = path; 49 | startTime = std::time (nullptr); 50 | std::atexit (shutdown); 51 | } 52 | else 53 | { 54 | DILAY_WARN ("Could not open log file %s", path.c_str ()); 55 | } 56 | } 57 | 58 | void log (Log::Level level, const char* file, unsigned int line, const char* format, ...) 59 | { 60 | const unsigned int secDiff = (unsigned int) std::difftime (std::time (nullptr), startTime); 61 | 62 | va_list args1; 63 | va_list args2; 64 | 65 | va_start (args1, format); 66 | va_copy (args2, args1); 67 | 68 | std::vector buffer (1 + std::vsnprintf (nullptr, 0, format, args1)); 69 | va_end (args1); 70 | 71 | std::vsnprintf (buffer.data (), buffer.size (), format, args2); 72 | va_end (args2); 73 | 74 | if (fileHandle) 75 | { 76 | std::fprintf (fileHandle, "%09u [%s] %s (%u): %s\n", secDiff, levelToString (level), file, 77 | line, buffer.data ()); 78 | std::fflush (fileHandle); 79 | } 80 | 81 | if (level != Log::Level::Info) 82 | { 83 | std::fprintf (stderr, "%09u [%s] %s (%u): %s\n", secDiff, levelToString (level), file, line, 84 | buffer.data ()); 85 | } 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /lib/src/log.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_LOG 6 | #define DILAY_LOG 7 | 8 | #include 9 | 10 | namespace Log 11 | { 12 | enum class Level 13 | { 14 | Info, 15 | Warning, 16 | Panic 17 | }; 18 | 19 | void initialize (const std::string&); 20 | void log (Level, const char*, unsigned int, const char*, ...); 21 | } 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /lib/src/maybe.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_MAYBE 6 | #define DILAY_MAYBE 7 | 8 | #include 9 | #include 10 | 11 | template class Maybe 12 | { 13 | static_assert (std::is_pointer::value == false, "Maybe does not support pointers"); 14 | static_assert (std::is_reference::value == false, "Maybe does not support references"); 15 | 16 | public: 17 | Maybe () = default; 18 | 19 | explicit Maybe (T* v) 20 | : value (v) 21 | { 22 | } 23 | 24 | Maybe (const T& v) 25 | : value (new T (v)) 26 | { 27 | } 28 | 29 | Maybe (const Maybe& o) 30 | : value (o.hasValue () ? new T (*o) : nullptr) 31 | { 32 | } 33 | 34 | Maybe (Maybe&&) = default; 35 | 36 | Maybe (std::unique_ptr&& v) 37 | : value (std::move (v)) 38 | { 39 | } 40 | 41 | template static Maybe make (Args&&... args) 42 | { 43 | return Maybe (std::make_unique (std::forward (args)...)); 44 | } 45 | 46 | ~Maybe () = default; 47 | 48 | Maybe& operator= (T* v) 49 | { 50 | if (this->get () != v) 51 | { 52 | this->value.reset (v); 53 | } 54 | return *this; 55 | } 56 | 57 | Maybe& operator= (const T& v) 58 | { 59 | if (this->get () != &v) 60 | { 61 | this->value.reset (new T (v)); 62 | } 63 | return *this; 64 | } 65 | 66 | Maybe& operator= (const Maybe& o) 67 | { 68 | if (this != &o) 69 | { 70 | this->value.reset (o.hasValue () ? new T (*o) : nullptr); 71 | } 72 | return *this; 73 | } 74 | 75 | Maybe& operator= (Maybe&&) = default; 76 | 77 | explicit operator bool () const { return this->hasValue (); } 78 | 79 | bool operator== (bool v) const { return this->operator bool () == v; } 80 | 81 | T& operator* () 82 | { 83 | assert (this->hasValue ()); 84 | return *this->value; 85 | } 86 | 87 | const T& operator* () const 88 | { 89 | assert (this->hasValue ()); 90 | return *this->value; 91 | } 92 | 93 | T* operator-> () { return this->get (); } 94 | 95 | const T* operator-> () const { return this->get (); } 96 | 97 | T* get () { return this->value.get (); } 98 | 99 | const T* get () const { return this->value.get (); } 100 | 101 | T* release () { return this->value.release (); } 102 | 103 | bool hasValue () const { return bool(this->value); } 104 | 105 | void reset (T* newValue = nullptr) { this->value.reset (newValue); } 106 | 107 | void swap (Maybe& o) { this->value.swap (o.value); } 108 | 109 | private: 110 | std::unique_ptr value; 111 | }; 112 | 113 | #endif 114 | -------------------------------------------------------------------------------- /lib/src/mesh-util.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_MESH_UTIL 6 | #define DILAY_MESH_UTIL 7 | 8 | class Mesh; 9 | class PrimPlane; 10 | 11 | namespace MeshUtil 12 | { 13 | void addFace (Mesh&, unsigned int, unsigned int, unsigned int); 14 | void addFace (Mesh&, unsigned int, unsigned int, unsigned int, unsigned int); 15 | 16 | Mesh cube (unsigned int); 17 | Mesh sphere (unsigned int, unsigned int); 18 | Mesh icosphere (unsigned int); 19 | Mesh cone (unsigned int); 20 | Mesh cylinder (unsigned int); 21 | 22 | Mesh mirrorPositive (const Mesh&, const PrimPlane&); 23 | void mirror (Mesh&, const PrimPlane&); 24 | 25 | void moveToCenter (Mesh&); 26 | void normalizeScaling (Mesh&); 27 | bool checkConsistency (const Mesh&); 28 | }; 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /lib/src/mesh.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_MESH 6 | #define DILAY_MESH 7 | 8 | #include 9 | #include "macro.hpp" 10 | 11 | class Camera; 12 | class Color; 13 | class PrimAABox; 14 | class RenderFlags; 15 | class RenderMode; 16 | 17 | class Mesh 18 | { 19 | public: 20 | DECLARE_BIG6 (Mesh) 21 | 22 | unsigned int numVertices () const; 23 | unsigned int numIndices () const; 24 | const glm::vec3& vertex (unsigned int) const; 25 | unsigned int index (unsigned int) const; 26 | const glm::vec3& normal (unsigned int) const; 27 | void copyNonGeometry (const Mesh&); 28 | unsigned int addIndex (unsigned int); 29 | void reserveIndices (unsigned int); 30 | void shrinkIndices (unsigned int); 31 | unsigned int addVertex (const glm::vec3&); 32 | unsigned int addVertex (const glm::vec3&, const glm::vec3&); 33 | void reserveVertices (unsigned int); 34 | void shrinkVertices (unsigned int); 35 | void index (unsigned int, unsigned int); 36 | void vertex (unsigned int, const glm::vec3&); 37 | void normal (unsigned int, const glm::vec3&); 38 | 39 | void bufferData (); 40 | glm::mat4x4 modelMatrix () const; 41 | glm::mat3x3 modelNormalMatrix () const; 42 | void renderBegin (Camera&) const; 43 | void renderEnd () const; 44 | void render (Camera&) const; 45 | void renderLines (Camera&) const; 46 | void reset (); 47 | void resetGeometry (); 48 | const RenderMode& renderMode () const; 49 | RenderMode& renderMode (); 50 | 51 | void scale (const glm::vec3&); 52 | void scaling (const glm::vec3&); 53 | glm::vec3 scaling () const; 54 | void translate (const glm::vec3&); 55 | void position (const glm::vec3&); 56 | glm::vec3 position () const; 57 | void rotationMatrix (const glm::mat4x4&); 58 | const glm::mat4x4& rotationMatrix () const; 59 | void rotation (const glm::vec3&, float); 60 | void rotationX (float); 61 | void rotationY (float); 62 | void rotationZ (float); 63 | void rotate (const glm::mat4x4&); 64 | void rotate (const glm::vec3&, float); 65 | void rotateX (float); 66 | void rotateY (float); 67 | void rotateZ (float); 68 | void normalize (); 69 | PrimAABox bounds () const; 70 | const Color& color () const; 71 | void color (const Color&); 72 | const Color& wireframeColor () const; 73 | void wireframeColor (const Color&); 74 | 75 | private: 76 | IMPLEMENTATION 77 | }; 78 | 79 | #endif 80 | -------------------------------------------------------------------------------- /lib/src/mirror.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_MIRROR 6 | #define DILAY_MIRROR 7 | 8 | #include 9 | #include "configurable.hpp" 10 | #include "macro.hpp" 11 | 12 | class Camera; 13 | enum class Dimension; 14 | class PrimPlane; 15 | 16 | class Mirror : public Configurable 17 | { 18 | public: 19 | DECLARE_BIG2 (Mirror, const Config&, Dimension) 20 | 21 | Dimension dimension () const; 22 | float width () const; 23 | const PrimPlane& plane () const; 24 | 25 | void dimension (Dimension); 26 | void position (const glm::vec3&); 27 | void render (Camera&) const; 28 | 29 | private: 30 | IMPLEMENTATION 31 | 32 | void runFromConfig (const Config&); 33 | }; 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /lib/src/opengl-buffer-id.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #include "opengl-buffer-id.hpp" 6 | #include "opengl.hpp" 7 | 8 | OpenGLBufferId::OpenGLBufferId () 9 | : _id (0) 10 | { 11 | } 12 | 13 | OpenGLBufferId::OpenGLBufferId (const OpenGLBufferId&) 14 | : OpenGLBufferId () 15 | { 16 | } 17 | 18 | OpenGLBufferId::OpenGLBufferId (OpenGLBufferId&& other) 19 | : _id (other._id) 20 | { 21 | } 22 | 23 | const OpenGLBufferId& OpenGLBufferId::operator= (const OpenGLBufferId&) { return *this; } 24 | 25 | const OpenGLBufferId& OpenGLBufferId::operator= (OpenGLBufferId&& other) 26 | { 27 | this->_id = other._id; 28 | return *this; 29 | } 30 | 31 | OpenGLBufferId::~OpenGLBufferId () { this->reset (); } 32 | 33 | unsigned int OpenGLBufferId::id () const { return this->_id; } 34 | 35 | bool OpenGLBufferId::isValid () const { return this->_id > 0; } 36 | 37 | void OpenGLBufferId::allocate () 38 | { 39 | assert (this->isValid () == false); 40 | 41 | OpenGL::glGenBuffers (1, &this->_id); 42 | 43 | assert (this->isValid ()); 44 | } 45 | 46 | void OpenGLBufferId::reset () 47 | { 48 | if (this->isValid ()) 49 | { 50 | OpenGL::safeDeleteBuffer (this->_id); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /lib/src/opengl-buffer-id.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_OPENGL_BUFFER_ID 6 | #define DILAY_OPENGL_BUFFER_ID 7 | 8 | #include "macro.hpp" 9 | 10 | class OpenGLBufferId 11 | { 12 | public: 13 | DECLARE_BIG6 (OpenGLBufferId) 14 | 15 | unsigned int id () const; 16 | bool isValid () const; 17 | 18 | void allocate (); 19 | void reset (); 20 | 21 | private: 22 | unsigned int _id; 23 | }; 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /lib/src/primitive/aabox.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #include "primitive/aabox.hpp" 6 | 7 | PrimAABox::PrimAABox (const glm::vec3& min, const glm::vec3& max) 8 | : _minimum (min) 9 | , _maximum (max) 10 | , _center ((min + max) * 0.5f) 11 | { 12 | } 13 | 14 | PrimAABox::PrimAABox (const glm::vec3& pos, float xW, float yW, float zW) 15 | : PrimAABox (pos - glm::vec3 (xW * 0.5f, yW * 0.5f, zW * 0.5f), 16 | pos + glm::vec3 (xW * 0.5f, yW * 0.5f, zW * 0.5f)) 17 | { 18 | } 19 | 20 | PrimAABox::PrimAABox (const glm::vec3& pos, float w) 21 | : PrimAABox (pos, w, w, w) 22 | { 23 | } 24 | 25 | glm::vec3 PrimAABox::halfWidth () const { return (this->_maximum - this->_minimum) * 0.5f; } 26 | 27 | float PrimAABox::maxDimExtent () const 28 | { 29 | const glm::vec3 extent = this->_maximum - this->_minimum; 30 | return glm::max (glm::max (extent.x, extent.y), extent.z); 31 | } 32 | 33 | bool PrimAABox::contains (const PrimAABox& box) const 34 | { 35 | return glm::all (glm::lessThanEqual (this->_minimum, box._minimum)) && 36 | glm::all (glm::greaterThanEqual (this->_maximum, box._maximum)); 37 | } 38 | -------------------------------------------------------------------------------- /lib/src/primitive/aabox.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_PRIMITIVE_AABOX 6 | #define DILAY_PRIMITIVE_AABOX 7 | 8 | #include 9 | 10 | class PrimAABox 11 | { 12 | public: 13 | PrimAABox (const glm::vec3&, const glm::vec3&); 14 | PrimAABox (const glm::vec3&, float, float, float); 15 | PrimAABox (const glm::vec3&, float); 16 | 17 | const glm::vec3& maximum () const { return this->_maximum; } 18 | const glm::vec3& minimum () const { return this->_minimum; } 19 | const glm::vec3& center () const { return this->_center; } 20 | 21 | glm::vec3 halfWidth () const; 22 | float maxDimExtent () const; 23 | bool contains (const PrimAABox&) const; 24 | 25 | private: 26 | const glm::vec3 _minimum; 27 | const glm::vec3 _maximum; 28 | const glm::vec3 _center; 29 | }; 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /lib/src/primitive/cone-sphere.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #include 6 | #include "primitive/cone-sphere.hpp" 7 | #include "primitive/cone.hpp" 8 | #include "util.hpp" 9 | 10 | PrimConeSphere::PrimConeSphere (const PrimSphere& s1, const PrimSphere& s2) 11 | : _sphere1 (s1.radius () > s2.radius () ? s1 : s2) 12 | , _sphere2 (s1.radius () > s2.radius () ? s2 : s1) 13 | , _length (glm::distance (s1.center (), s2.center ())) 14 | , _direction ((this->_sphere2.center () - this->_sphere1.center ()) / glm::vec3 (this->_length)) 15 | , _alpha (glm::half_pi () - glm::acos (this->delta () / this->_length)) 16 | , _sinAlpha (glm::sin (this->_alpha)) 17 | , _cosAlpha (glm::cos (this->_alpha)) 18 | { 19 | } 20 | 21 | float PrimConeSphere::delta () const { return this->_sphere1.radius () - this->_sphere2.radius (); } 22 | 23 | bool PrimConeSphere::sameRadii () const { return Util::almostEqual (this->delta (), 0.0f); } 24 | 25 | bool PrimConeSphere::hasCone () const { return this->_length > this->delta (); } 26 | 27 | float PrimConeSphere::coneSideLength () const 28 | { 29 | assert (this->hasCone ()); 30 | 31 | return glm::sqrt ((this->_length * this->_length) - (this->delta () * this->delta ())); 32 | } 33 | 34 | PrimCone PrimConeSphere::toCone () const 35 | { 36 | assert (this->hasCone ()); 37 | 38 | const float s = this->coneSideLength (); 39 | const float h1 = this->_sphere1.radius () * this->delta () / this->_length; 40 | const float h2 = this->_sphere2.radius () * this->delta () / this->_length; 41 | const float r1c = this->_sphere1.radius () * s / this->_length; 42 | const float r2c = this->_sphere2.radius () * s / this->_length; 43 | 44 | return PrimCone (this->_sphere2.center () + (this->_direction * h2), r2c, 45 | this->_sphere1.center () + (this->_direction * h1), r1c); 46 | } 47 | -------------------------------------------------------------------------------- /lib/src/primitive/cone-sphere.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_PRIMITIVE_CONE_SPHERE 6 | #define DILAY_PRIMITIVE_CONE_SPHERE 7 | 8 | #include 9 | #include "primitive/sphere.hpp" 10 | 11 | class PrimCone; 12 | 13 | class PrimConeSphere 14 | { 15 | public: 16 | PrimConeSphere (const PrimSphere&, const PrimSphere&); 17 | 18 | const PrimSphere& sphere1 () const { return this->_sphere1; } 19 | 20 | const PrimSphere& sphere2 () const { return this->_sphere2; } 21 | 22 | float length () const { return this->_length; } 23 | 24 | const glm::vec3& direction () const { return this->_direction; } 25 | 26 | float alpha () const { return this->_alpha; } 27 | 28 | float sinAlpha () const { return this->_sinAlpha; } 29 | 30 | float cosAlpha () const { return this->_cosAlpha; } 31 | 32 | float delta () const; 33 | bool sameRadii () const; 34 | bool hasCone () const; 35 | float coneSideLength () const; 36 | PrimCone toCone () const; 37 | 38 | private: 39 | const PrimSphere _sphere1; 40 | const PrimSphere _sphere2; 41 | const float _length; 42 | const glm::vec3 _direction; 43 | const float _alpha; 44 | const float _sinAlpha; 45 | const float _cosAlpha; 46 | }; 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /lib/src/primitive/cone.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #include "primitive/cone.hpp" 6 | #include "util.hpp" 7 | 8 | PrimCone::PrimCone (const glm::vec3& c1, float r1, const glm::vec3& c2, float r2, float l) 9 | : _center1 (r1 > r2 ? c1 : c2) 10 | , _radius1 (r1 > r2 ? r1 : r2) 11 | , _center2 (r1 > r2 ? c2 : c1) 12 | , _radius2 (r1 > r2 ? r2 : r1) 13 | , _length (l) 14 | , _direction ((this->_center2 - this->_center1) / glm::vec3 (l)) 15 | , _isCylinder (Util::almostEqual (r1, r2)) 16 | , _apex (this->_isCylinder 17 | ? glm::vec3 (0.0f) 18 | : this->_center1 + (this->_radius1 * (this->_center2 - this->_center1) / 19 | (this->_radius1 - this->_radius2))) 20 | , _alpha (glm::atan ((this->_radius1 - this->_radius2) / l)) 21 | , _sinAlpha (glm::sin (this->_alpha)) 22 | , _cosAlpha (glm::cos (this->_alpha)) 23 | { 24 | } 25 | 26 | PrimCone::PrimCone (const glm::vec3& c1, float r1, const glm::vec3& c2, float r2) 27 | : PrimCone (c1, r1, c2, r2, glm::distance (c1, c2)) 28 | { 29 | } 30 | 31 | glm::vec3 PrimCone::projPointAt (float t) const { return this->_center1 + (t * this->_direction); } 32 | 33 | glm::vec3 PrimCone::normalAt (const glm::vec3& pointAt, float tCone) const 34 | { 35 | const glm::vec3 projP = this->projPointAt (tCone); 36 | const glm::vec3 diff = glm::normalize (pointAt - projP); 37 | const glm::vec3 slope = 38 | (this->_center2 + (this->_radius2 * diff)) - (this->_center1 + (this->_radius1 * diff)); 39 | const glm::vec3 tang = glm::cross (diff, this->_direction); 40 | 41 | return glm::normalize (glm::cross (slope, tang)); 42 | } 43 | -------------------------------------------------------------------------------- /lib/src/primitive/cone.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_PRIMITIVE_CONE 6 | #define DILAY_PRIMITIVE_CONE 7 | 8 | #include 9 | 10 | class PrimCone 11 | { 12 | public: 13 | PrimCone (const glm::vec3&, float, const glm::vec3&, float); 14 | PrimCone (const glm::vec3&, float, const glm::vec3&, float, float); 15 | 16 | const glm::vec3& center1 () const { return this->_center1; } 17 | float radius1 () const { return this->_radius1; } 18 | const glm::vec3& center2 () const { return this->_center2; } 19 | float radius2 () const { return this->_radius2; } 20 | float length () const { return this->_length; } 21 | const glm::vec3& direction () const { return this->_direction; } 22 | bool isCylinder () const { return this->_isCylinder; } 23 | const glm::vec3& apex () const { return this->_apex; } 24 | float alpha () const { return this->_alpha; } 25 | float sinAlpha () const { return this->_sinAlpha; } 26 | float cosAlpha () const { return this->_cosAlpha; } 27 | 28 | glm::vec3 projPointAt (float) const; 29 | glm::vec3 normalAt (const glm::vec3&, float) const; 30 | 31 | private: 32 | const glm::vec3 _center1; 33 | const float _radius1; 34 | const glm::vec3 _center2; 35 | const float _radius2; 36 | const float _length; 37 | const glm::vec3 _direction; 38 | const bool _isCylinder; 39 | const glm::vec3 _apex; 40 | const float _alpha; 41 | const float _sinAlpha; 42 | const float _cosAlpha; 43 | }; 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /lib/src/primitive/cylinder.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #include "primitive/cone.hpp" 6 | #include "primitive/cylinder.hpp" 7 | #include "util.hpp" 8 | 9 | PrimCylinder::PrimCylinder (const glm::vec3& c1, const glm::vec3& c2, float r, float l) 10 | : _center1 (c1) 11 | , _center2 (c2) 12 | , _radius (r) 13 | , _length (l) 14 | , _direction ((c2 - c1) / glm::vec3 (l)) 15 | { 16 | } 17 | 18 | PrimCylinder::PrimCylinder (const glm::vec3& c1, const glm::vec3& c2, float r) 19 | : PrimCylinder (c1, c2, r, glm::distance (c1, c2)) 20 | { 21 | } 22 | 23 | PrimCylinder::PrimCylinder (const PrimCone& cone) 24 | : _center1 (cone.center1 ()) 25 | , _center2 (cone.center2 ()) 26 | , _radius (cone.radius1 ()) 27 | , _length (cone.length ()) 28 | , _direction (cone.direction ()) 29 | { 30 | assert (cone.isCylinder ()); 31 | } 32 | -------------------------------------------------------------------------------- /lib/src/primitive/cylinder.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_PRIMITIVE_CYLINDER 6 | #define DILAY_PRIMITIVE_CYLINDER 7 | 8 | #include 9 | 10 | class PrimCone; 11 | 12 | class PrimCylinder 13 | { 14 | public: 15 | PrimCylinder (const glm::vec3&, const glm::vec3&, float); 16 | PrimCylinder (const glm::vec3&, const glm::vec3&, float, float); 17 | PrimCylinder (const PrimCone&); 18 | 19 | const glm::vec3& center1 () const { return this->_center1; } 20 | const glm::vec3& center2 () const { return this->_center2; } 21 | float radius () const { return this->_radius; } 22 | float length () const { return this->_length; } 23 | const glm::vec3& direction () const { return this->_direction; } 24 | 25 | private: 26 | const glm::vec3 _center1; 27 | const glm::vec3 _center2; 28 | const float _radius; 29 | const float _length; 30 | const glm::vec3 _direction; 31 | }; 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /lib/src/primitive/plane.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #include "primitive/plane.hpp" 6 | #include "util.hpp" 7 | 8 | PrimPlane::PrimPlane (const glm::vec3& p, const glm::vec3& n) 9 | : _point (p) 10 | { 11 | this->normal (n); 12 | } 13 | 14 | void PrimPlane::normal (const glm::vec3& n) 15 | { 16 | this->_normal = glm::normalize (n); 17 | this->_u = glm::normalize (Util::orthogonal (this->_normal)); 18 | this->_v = glm::normalize (glm::cross (this->_normal, this->_u)); 19 | } 20 | 21 | float PrimPlane::distance (const glm::vec3& p) const 22 | { 23 | return glm::dot (this->_normal, p - this->_point); 24 | } 25 | 26 | float PrimPlane::absDistance (const glm::vec3& p) const { return glm::abs (this->distance (p)); } 27 | 28 | bool PrimPlane::onPlane (const glm::vec3& p) const 29 | { 30 | return this->absDistance (p) < Util::epsilon (); 31 | } 32 | 33 | glm::vec3 PrimPlane::project (const glm::vec3& p) const 34 | { 35 | return p - (this->_normal * this->distance (p)); 36 | } 37 | 38 | glm::vec3 PrimPlane::project (const glm::vec2& p) const 39 | { 40 | return this->_point + (this->_u * p.x) + (this->_v * p.y); 41 | } 42 | 43 | glm::vec2 PrimPlane::project2d (const glm::vec3& p) const 44 | { 45 | const glm::vec3 proj = this->project (p) - this->_point; 46 | 47 | return glm::vec2 (glm::dot (this->_u, proj), glm::dot (this->_v, proj)); 48 | } 49 | 50 | glm::vec3 PrimPlane::projectDirection (const glm::vec3& d) const 51 | { 52 | return this->project (d + this->_point) - this->_point; 53 | } 54 | 55 | glm::vec3 PrimPlane::mirror (const glm::vec3& p) const 56 | { 57 | return p - (2.0f * this->_normal * this->distance (p)); 58 | } 59 | 60 | glm::vec3 PrimPlane::mirrorDirection (const glm::vec3& d) const 61 | { 62 | return this->mirror (d + this->_point) - this->_point; 63 | } 64 | -------------------------------------------------------------------------------- /lib/src/primitive/plane.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_PRIMITIVE_PLANE 6 | #define DILAY_PRIMITIVE_PLANE 7 | 8 | #include 9 | #include "macro.hpp" 10 | 11 | class PrimPlane 12 | { 13 | public: 14 | PrimPlane (const glm::vec3&, const glm::vec3&); 15 | 16 | float distance (const glm::vec3&) const; 17 | float absDistance (const glm::vec3&) const; 18 | bool onPlane (const glm::vec3&) const; 19 | glm::vec3 project (const glm::vec3&) const; 20 | glm::vec3 project (const glm::vec2&) const; 21 | glm::vec2 project2d (const glm::vec3&) const; 22 | glm::vec3 projectDirection (const glm::vec3&) const; 23 | glm::vec3 mirror (const glm::vec3&) const; 24 | glm::vec3 mirrorDirection (const glm::vec3&) const; 25 | 26 | MEMBER_REF_GETTER_SETTER (glm::vec3, point) 27 | MEMBER_REF_GETTER_EXPLICIT_SETTER (glm::vec3, normal) 28 | MEMBER_REF_GETTER (glm::vec3, u) 29 | MEMBER_REF_GETTER (glm::vec3, v) 30 | }; 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /lib/src/primitive/ray.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #include "primitive/ray.hpp" 6 | #include "util.hpp" 7 | 8 | PrimRay::PrimRay (bool l, const glm::vec3& o, const glm::vec3& d) 9 | : _isLine (l) 10 | , _origin (o) 11 | , _direction (glm::normalize (d)) 12 | { 13 | } 14 | 15 | PrimRay::PrimRay (const glm::vec3& o, const glm::vec3& d) 16 | : PrimRay (false, o, d) 17 | { 18 | } 19 | 20 | glm::vec3 PrimRay::pointAt (float t) const 21 | { 22 | assert (t >= 0.0f || this->_isLine); 23 | return this->_origin + (this->_direction * glm::vec3 (t)); 24 | } 25 | 26 | float PrimRay::distance (const glm::vec3& p) const 27 | { 28 | const float t = glm::dot (this->_direction, p - this->_origin); 29 | 30 | return t >= 0.0f || this->_isLine ? glm::distance (p, this->pointAt (t)) 31 | : glm::distance (p, this->_origin); 32 | } 33 | 34 | bool PrimRay::onRay (const glm::vec3& p) const { return this->distance (p) < Util::epsilon (); } 35 | -------------------------------------------------------------------------------- /lib/src/primitive/ray.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_PRIMITIVE_RAY 6 | #define DILAY_PRIMITIVE_RAY 7 | 8 | #include 9 | 10 | class PrimRay 11 | { 12 | public: 13 | PrimRay (bool, const glm::vec3&, const glm::vec3&); 14 | PrimRay (const glm::vec3&, const glm::vec3&); 15 | 16 | bool isLine () const { return this->_isLine; } 17 | const glm::vec3& origin () const { return this->_origin; } 18 | const glm::vec3& direction () const { return this->_direction; } 19 | 20 | void origin (const glm::vec3& o) { this->_origin = o; } 21 | 22 | glm::vec3 pointAt (float) const; 23 | float distance (const glm::vec3&) const; 24 | bool onRay (const glm::vec3&) const; 25 | 26 | private: 27 | const bool _isLine; 28 | glm::vec3 _origin; 29 | const glm::vec3 _direction; 30 | }; 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /lib/src/primitive/sphere.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #include 6 | #include "primitive/aabox.hpp" 7 | #include "primitive/sphere.hpp" 8 | #include "primitive/triangle.hpp" 9 | #include "util.hpp" 10 | 11 | PrimSphere::PrimSphere (const glm::vec3& o, float r) 12 | : _center (o) 13 | , _radius (r) 14 | { 15 | } 16 | 17 | bool PrimSphere::contains (const glm::vec3& p) const 18 | { 19 | return glm::distance2 (this->_center, p) <= (this->_radius * this->_radius); 20 | } 21 | 22 | bool PrimSphere::contains (const PrimAABox& aabox) const 23 | { 24 | return this->contains (aabox.minimum ()) && this->contains (aabox.maximum ()); 25 | } 26 | 27 | bool PrimSphere::contains (const PrimTriangle& tri) const 28 | { 29 | return this->contains (tri.vertex1 ()) && this->contains (tri.vertex2 ()) && 30 | this->contains (tri.vertex3 ()); 31 | } 32 | -------------------------------------------------------------------------------- /lib/src/primitive/sphere.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_PRIMITIVE_SPHERE 6 | #define DILAY_PRIMITIVE_SPHERE 7 | 8 | #include 9 | 10 | class PrimAABox; 11 | class PrimTriangle; 12 | 13 | class PrimSphere 14 | { 15 | public: 16 | PrimSphere (const glm::vec3&, float); 17 | 18 | const glm::vec3& center () const { return this->_center; } 19 | float radius () const { return this->_radius; } 20 | 21 | void center (const glm::vec3& c) { this->_center = c; } 22 | void radius (float r) { this->_radius = r; } 23 | 24 | bool contains (const glm::vec3&) const; 25 | bool contains (const PrimAABox&) const; 26 | bool contains (const PrimTriangle&) const; 27 | 28 | private: 29 | glm::vec3 _center; 30 | float _radius; 31 | }; 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /lib/src/primitive/triangle.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #include 6 | #include "primitive/triangle.hpp" 7 | #include "util.hpp" 8 | 9 | PrimTriangle::PrimTriangle (const glm::vec3& v1, const glm::vec3& v2, const glm::vec3& v3) 10 | : _vertex1 (v1) 11 | , _vertex2 (v2) 12 | , _vertex3 (v3) 13 | { 14 | } 15 | 16 | glm::vec3 PrimTriangle::cross () const 17 | { 18 | return glm::cross (this->_vertex2 - this->_vertex1, this->_vertex3 - this->_vertex1); 19 | } 20 | 21 | glm::vec3 PrimTriangle::normal () const 22 | { 23 | const glm::vec3 c = this->cross (); 24 | const float l = glm::length (c); 25 | 26 | return l > 0.0f ? (c / l) : glm::vec3 (0.0f); 27 | } 28 | 29 | glm::vec3 PrimTriangle::center () const 30 | { 31 | return (this->_vertex1 + this->_vertex2 + this->_vertex3) / glm::vec3 (3.0f); 32 | } 33 | 34 | glm::vec3 PrimTriangle::minimum () const 35 | { 36 | return glm::min (glm::min (this->_vertex1, this->_vertex2), this->_vertex3); 37 | } 38 | 39 | glm::vec3 PrimTriangle::maximum () const 40 | { 41 | return glm::max (glm::max (this->_vertex1, this->_vertex2), this->_vertex3); 42 | } 43 | 44 | float PrimTriangle::maxExtent () const { return glm::length (this->maximum () - this->minimum ()); } 45 | 46 | float PrimTriangle::maxDimExtent () const 47 | { 48 | const glm::vec3 extent = this->maximum () - this->minimum (); 49 | return glm::max (glm::max (extent.x, extent.y), extent.z); 50 | } 51 | 52 | float PrimTriangle::incircleRadiusSqr () const 53 | { 54 | const float a = glm::distance (this->_vertex1, this->_vertex2); 55 | const float b = glm::distance (this->_vertex2, this->_vertex3); 56 | const float c = glm::distance (this->_vertex1, this->_vertex3); 57 | const float s = 0.5f * (a + b + c); 58 | return (s - a) * (s - b) * (s - c) / s; 59 | } 60 | 61 | float PrimTriangle::longestEdgeSqr () const 62 | { 63 | return glm::max (glm::max (glm::distance2 (this->_vertex1, this->_vertex2), 64 | glm::distance2 (this->_vertex2, this->_vertex3)), 65 | glm::distance2 (this->_vertex1, this->_vertex3)); 66 | } 67 | -------------------------------------------------------------------------------- /lib/src/primitive/triangle.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_PRIMITIVE_TRIANGLE 6 | #define DILAY_PRIMITIVE_TRIANGLE 7 | 8 | #include 9 | 10 | class PrimTriangle 11 | { 12 | public: 13 | PrimTriangle (const glm::vec3&, const glm::vec3&, const glm::vec3&); 14 | 15 | const glm::vec3& vertex1 () const { return this->_vertex1; } 16 | const glm::vec3& vertex2 () const { return this->_vertex2; } 17 | const glm::vec3& vertex3 () const { return this->_vertex3; } 18 | 19 | glm::vec3 cross () const; 20 | glm::vec3 normal () const; 21 | glm::vec3 center () const; 22 | glm::vec3 minimum () const; 23 | glm::vec3 maximum () const; 24 | float maxExtent () const; 25 | float maxDimExtent () const; 26 | float incircleRadiusSqr () const; 27 | float longestEdgeSqr () const; 28 | 29 | private: 30 | const glm::vec3& _vertex1; 31 | const glm::vec3& _vertex2; 32 | const glm::vec3& _vertex3; 33 | }; 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /lib/src/render-mode.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #include 6 | #include "render-mode.hpp" 7 | #include "shader.hpp" 8 | #include "util.hpp" 9 | 10 | RenderMode::RenderMode () 11 | { 12 | this->smoothShading (true); 13 | this->renderWireframe (false); 14 | this->cameraRotationOnly (false); 15 | this->noDepthTest (false); 16 | } 17 | 18 | RenderMode::RenderMode (const RenderMode& other) 19 | : flags (other.flags) 20 | { 21 | } 22 | 23 | bool RenderMode::smoothShading () const { return this->flags.get<0> (); } 24 | 25 | bool RenderMode::flatShading () const { return this->flags.get<1> (); } 26 | 27 | bool RenderMode::constantShading () const { return this->flags.get<2> (); } 28 | 29 | bool RenderMode::renderWireframe () const { return this->flags.get<3> (); } 30 | 31 | bool RenderMode::cameraRotationOnly () const { return this->flags.get<4> (); } 32 | 33 | bool RenderMode::noDepthTest () const { return this->flags.get<5> (); } 34 | 35 | const char* RenderMode::vertexShader () const 36 | { 37 | if (this->smoothShading ()) 38 | { 39 | return Shader::smoothVertexShader (); 40 | } 41 | else if (this->flatShading ()) 42 | { 43 | return Shader::flatVertexShader (); 44 | } 45 | else if (this->constantShading ()) 46 | { 47 | return Shader::constantVertexShader (); 48 | } 49 | else 50 | { 51 | DILAY_IMPOSSIBLE 52 | } 53 | } 54 | 55 | const char* RenderMode::fragmentShader () const 56 | { 57 | if (this->smoothShading ()) 58 | { 59 | return this->renderWireframe () ? Shader::smoothWireframeFragmentShader () 60 | : Shader::smoothFragmentShader (); 61 | } 62 | else if (this->flatShading ()) 63 | { 64 | return this->renderWireframe () ? Shader::flatWireframeFragmentShader () 65 | : Shader::flatFragmentShader (); 66 | } 67 | else if (this->constantShading ()) 68 | { 69 | return this->renderWireframe () ? Shader::constantWireframeFragmentShader () 70 | : Shader::constantFragmentShader (); 71 | } 72 | else 73 | { 74 | DILAY_IMPOSSIBLE 75 | } 76 | } 77 | 78 | void RenderMode::smoothShading (bool v) 79 | { 80 | this->flags.set<0> (v); 81 | if (v) 82 | { 83 | this->flags.set<1> (false); 84 | this->flags.set<2> (false); 85 | } 86 | } 87 | 88 | void RenderMode::flatShading (bool v) 89 | { 90 | this->flags.set<1> (v); 91 | if (v) 92 | { 93 | this->flags.set<0> (false); 94 | this->flags.set<2> (false); 95 | } 96 | } 97 | 98 | void RenderMode::constantShading (bool v) 99 | { 100 | this->flags.set<2> (v); 101 | if (v) 102 | { 103 | this->flags.set<0> (false); 104 | this->flags.set<1> (false); 105 | } 106 | } 107 | 108 | void RenderMode::renderWireframe (bool v) { this->flags.set<3> (v); } 109 | 110 | void RenderMode::cameraRotationOnly (bool v) { this->flags.set<4> (v); } 111 | 112 | void RenderMode::noDepthTest (bool v) { this->flags.set<5> (v); } 113 | -------------------------------------------------------------------------------- /lib/src/render-mode.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_RENDER_MODE 6 | #define DILAY_RENDER_MODE 7 | 8 | #include "bitset.hpp" 9 | 10 | class RenderMode 11 | { 12 | public: 13 | RenderMode (); 14 | RenderMode (const RenderMode&); 15 | 16 | bool smoothShading () const; 17 | bool flatShading () const; 18 | bool constantShading () const; 19 | bool renderWireframe () const; 20 | bool cameraRotationOnly () const; 21 | bool noDepthTest () const; 22 | const char* vertexShader () const; 23 | const char* fragmentShader () const; 24 | 25 | void smoothShading (bool); 26 | void flatShading (bool); 27 | void constantShading (bool); 28 | void renderWireframe (bool); 29 | void cameraRotationOnly (bool); 30 | void noDepthTest (bool); 31 | 32 | private: 33 | Bitset flags; 34 | }; 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /lib/src/renderer.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_RENDERER 6 | #define DILAY_RENDERER 7 | 8 | #include 9 | #include "configurable.hpp" 10 | #include "macro.hpp" 11 | 12 | class Color; 13 | class Config; 14 | class RenderMode; 15 | 16 | class Renderer : public Configurable 17 | { 18 | public: 19 | DECLARE_BIG3 (Renderer, const Config&) 20 | 21 | void setupRendering (); 22 | void shutdownRendering (); 23 | void setProgram (const RenderMode&); 24 | void setModel (const float*, const float*); 25 | void setView (const float*); 26 | void setProjection (const float*); 27 | void setColor (const Color&, bool = false); 28 | void setWireframeColor (const Color&, bool = false); 29 | void setEyePoint (const glm::vec3&); 30 | void setLightDirection (unsigned int, const glm::vec3&); 31 | void setLightColor (unsigned int, const Color&); 32 | void setLightIrradiance (unsigned int, float); 33 | 34 | private: 35 | IMPLEMENTATION 36 | 37 | void runFromConfig (const Config&); 38 | }; 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /lib/src/scene.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_SCENE 6 | #define DILAY_SCENE 7 | 8 | #include 9 | #include "configurable.hpp" 10 | #include "macro.hpp" 11 | #include "sketch/fwd.hpp" 12 | 13 | class Camera; 14 | class DynamicMesh; 15 | class DynamicMeshIntersection; 16 | class Intersection; 17 | class Mesh; 18 | class PrimRay; 19 | class RenderMode; 20 | 21 | class Scene : public Configurable 22 | { 23 | public: 24 | DECLARE_BIG3 (Scene, const Config&) 25 | 26 | DynamicMesh& newDynamicMesh (const Config&, const DynamicMesh&); 27 | DynamicMesh& newDynamicMesh (const Config&, const Mesh&); 28 | SketchMesh& newSketchMesh (const Config&, const SketchMesh&); 29 | SketchMesh& newSketchMesh (const Config&, const SketchTree&); 30 | void setupMesh (const Config&, DynamicMesh&); 31 | void setupMesh (const Config&, SketchMesh&); 32 | void deleteMesh (DynamicMesh&); 33 | void deleteMesh (SketchMesh&); 34 | void deleteDynamicMeshes (); 35 | void deleteSketchMeshes (); 36 | void deleteEmptyMeshes (); 37 | void render (Camera&); 38 | bool intersects (const PrimRay&, DynamicMeshIntersection&); 39 | bool intersects (const PrimRay&, SketchNodeIntersection&, const SketchNode* = nullptr); 40 | bool intersects (const PrimRay&, SketchBoneIntersection&); 41 | bool intersects (const PrimRay&, SketchMeshIntersection&); 42 | bool intersects (const PrimRay&, SketchMeshIntersection&, unsigned int); 43 | bool intersects (const PrimRay&, SketchPathIntersection&); 44 | bool intersects (const PrimRay&, Intersection&); 45 | void printStatistics () const; 46 | void forEachMesh (const std::function&); 47 | void forEachMesh (const std::function&); 48 | void forEachConstMesh (const std::function&) const; 49 | void forEachConstMesh (const std::function&) const; 50 | void sanitizeMeshes (); 51 | void reset (); 52 | const RenderMode& commonRenderMode () const; 53 | bool renderWireframe () const; 54 | void renderWireframe (bool); 55 | void toggleWireframe (); 56 | void toggleShading (); 57 | bool isEmpty () const; 58 | unsigned int numDynamicMeshes () const; 59 | unsigned int numSketchMeshes () const; 60 | unsigned int numFaces () const; 61 | bool hasFileName () const; 62 | const std::string& fileName () const; 63 | bool toDlyFile (bool); 64 | bool toDlyFile (const std::string&, bool); 65 | bool fromDlyFile (const Config&, const std::string&); 66 | 67 | private: 68 | IMPLEMENTATION 69 | 70 | void runFromConfig (const Config&); 71 | }; 72 | 73 | #endif 74 | -------------------------------------------------------------------------------- /lib/src/shader.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_SHADER 6 | #define DILAY_SHADER 7 | 8 | namespace Shader 9 | { 10 | const char* smoothVertexShader (); 11 | const char* smoothFragmentShader (); 12 | const char* smoothWireframeFragmentShader (); 13 | 14 | const char* flatVertexShader (); 15 | const char* flatFragmentShader (); 16 | const char* flatWireframeFragmentShader (); 17 | 18 | const char* constantVertexShader (); 19 | const char* constantFragmentShader (); 20 | const char* constantWireframeFragmentShader (); 21 | const char* geometryShader (); 22 | }; 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /lib/src/sketch/bone-intersection.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #include "sketch/bone-intersection.hpp" 6 | #include "sketch/mesh.hpp" 7 | 8 | SketchBoneIntersection::SketchBoneIntersection () 9 | : _child (nullptr) 10 | { 11 | } 12 | 13 | bool SketchBoneIntersection::update (float d, const glm::vec3& p, const glm::vec3& projP, 14 | const glm::vec3& n, SketchMesh& mesh, SketchNode& child) 15 | { 16 | assert (child.parent ()); 17 | 18 | if (this->SketchMeshIntersection::update (d, p, n, mesh)) 19 | { 20 | this->_child = &child; 21 | this->_projectedPosition = projP; 22 | return true; 23 | } 24 | else 25 | { 26 | return false; 27 | } 28 | } 29 | 30 | SketchNode& SketchBoneIntersection::parent () const 31 | { 32 | assert (this->isIntersection ()); 33 | assert (this->_child); 34 | return *this->_child->parent (); 35 | } 36 | 37 | SketchNode& SketchBoneIntersection::child () const 38 | { 39 | assert (this->isIntersection ()); 40 | assert (this->_child); 41 | return *this->_child; 42 | } 43 | 44 | const glm::vec3& SketchBoneIntersection::projectedPosition () const 45 | { 46 | assert (this->isIntersection ()); 47 | return this->_projectedPosition; 48 | } 49 | -------------------------------------------------------------------------------- /lib/src/sketch/bone-intersection.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_SKETCH_BONE_INTERSECTION 6 | #define DILAY_SKETCH_BONE_INTERSECTION 7 | 8 | #include "sketch/fwd.hpp" 9 | #include "sketch/mesh-intersection.hpp" 10 | 11 | class SketchBoneIntersection : public SketchMeshIntersection 12 | { 13 | public: 14 | SketchBoneIntersection (); 15 | 16 | SketchNode& parent () const; 17 | SketchNode& child () const; 18 | const glm::vec3& projectedPosition () const; 19 | bool update (float, const glm::vec3&, const glm::vec3&, const glm::vec3&, SketchMesh&, 20 | SketchNode&); 21 | 22 | private: 23 | SketchNode* _child; 24 | glm::vec3 _projectedPosition; 25 | }; 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /lib/src/sketch/fwd.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_SKETCH_FWD 6 | #define DILAY_SKETCH_FWD 7 | 8 | #include "primitive/sphere.hpp" 9 | #include "tree.hpp" 10 | 11 | class SketchPath; 12 | using SketchPaths = std::vector; 13 | class SketchNodeIntersection; 14 | class SketchBoneIntersection; 15 | class SketchMeshIntersection; 16 | class SketchPathIntersection; 17 | using SketchNode = TreeNode; 18 | using SketchTree = Tree; 19 | class SketchMesh; 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /lib/src/sketch/mesh-intersection.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #include "sketch/mesh-intersection.hpp" 6 | #include "sketch/mesh.hpp" 7 | 8 | SketchMeshIntersection::SketchMeshIntersection () 9 | : _mesh (nullptr) 10 | { 11 | } 12 | 13 | bool SketchMeshIntersection::update (float d, const glm::vec3& p, const glm::vec3& n, 14 | SketchMesh& mesh) 15 | { 16 | if (this->Intersection::update (d, p, n)) 17 | { 18 | this->_mesh = &mesh; 19 | return true; 20 | } 21 | else 22 | { 23 | return false; 24 | } 25 | } 26 | 27 | SketchMesh& SketchMeshIntersection::mesh () const 28 | { 29 | assert (this->isIntersection ()); 30 | assert (this->_mesh); 31 | return *this->_mesh; 32 | } 33 | -------------------------------------------------------------------------------- /lib/src/sketch/mesh-intersection.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_SKETCH_MESH_INTERSECTION 6 | #define DILAY_SKETCH_MESH_INTERSECTION 7 | 8 | #include "intersection.hpp" 9 | #include "sketch/fwd.hpp" 10 | 11 | class SketchMeshIntersection : public Intersection 12 | { 13 | public: 14 | SketchMeshIntersection (); 15 | 16 | SketchMesh& mesh () const; 17 | bool update (float, const glm::vec3&, const glm::vec3&, SketchMesh&); 18 | 19 | private: 20 | SketchMesh* _mesh; 21 | }; 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /lib/src/sketch/mesh.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_SKETCH_MESH 6 | #define DILAY_SKETCH_MESH 7 | 8 | #include 9 | #include "configurable.hpp" 10 | #include "macro.hpp" 11 | #include "sketch/fwd.hpp" 12 | 13 | class Camera; 14 | enum class Dimension; 15 | class PrimPlane; 16 | class PrimRay; 17 | class PrimSphere; 18 | enum class SketchPathSmoothEffect; 19 | 20 | class SketchMesh : public Configurable 21 | { 22 | public: 23 | DECLARE_BIG4_EXPLICIT_COPY (SketchMesh); 24 | 25 | const SketchTree& tree () const; 26 | SketchTree& tree (); 27 | const SketchPaths& paths () const; 28 | bool isEmpty () const; 29 | void fromTree (const SketchTree&); 30 | void reset (); 31 | bool intersects (const PrimRay&, SketchNodeIntersection&, const SketchNode* = nullptr); 32 | bool intersects (const PrimRay&, SketchBoneIntersection&); 33 | bool intersects (const PrimRay&, SketchMeshIntersection&, unsigned int = 0); 34 | bool intersects (const PrimRay&, SketchPathIntersection&); 35 | void render (Camera&); 36 | void renderWireframe (bool); 37 | PrimPlane mirrorPlane (Dimension); 38 | SketchNode& addChild (SketchNode&, const glm::vec3&, float, const Dimension*); 39 | SketchNode& addParent (SketchNode&, const glm::vec3&, float, const Dimension*); 40 | SketchPath& addPath (const SketchPath&); 41 | void addSphere (bool, const glm::vec3&, const glm::vec3&, float, const Dimension*); 42 | void move (SketchNode&, const glm::vec3&, bool, const Dimension*); 43 | void scale (SketchNode&, float, bool, const Dimension*); 44 | void rotate (SketchNode&, const glm::vec3&, float, const Dimension*); 45 | void deleteNode (SketchNode&, bool, const Dimension*); 46 | void deletePath (SketchPath&, const Dimension*); 47 | void mirrorPositive (Dimension); 48 | void rebalance (SketchNode&); 49 | SketchNode& snap (SketchNode&, Dimension); 50 | void minMax (glm::vec3&, glm::vec3&) const; 51 | void smoothPath (SketchPath&, const PrimSphere&, unsigned int, SketchPathSmoothEffect, 52 | const Dimension*); 53 | void optimizePaths (); 54 | 55 | private: 56 | IMPLEMENTATION 57 | 58 | void runFromConfig (const Config&); 59 | }; 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /lib/src/sketch/node-intersection.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #include "sketch/mesh.hpp" 6 | #include "sketch/node-intersection.hpp" 7 | 8 | SketchNodeIntersection::SketchNodeIntersection () 9 | : _node (nullptr) 10 | { 11 | } 12 | 13 | bool SketchNodeIntersection::update (float d, const glm::vec3& p, const glm::vec3& n, 14 | SketchMesh& mesh, SketchNode& node) 15 | { 16 | if (this->SketchMeshIntersection::update (d, p, n, mesh)) 17 | { 18 | this->_node = &node; 19 | return true; 20 | } 21 | else 22 | { 23 | return false; 24 | } 25 | } 26 | 27 | SketchNode& SketchNodeIntersection::node () const 28 | { 29 | assert (this->isIntersection ()); 30 | assert (this->_node); 31 | return *this->_node; 32 | } 33 | -------------------------------------------------------------------------------- /lib/src/sketch/node-intersection.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_SKETCH_NODE_INTERSECTION 6 | #define DILAY_SKETCH_NODE_INTERSECTION 7 | 8 | #include "sketch/fwd.hpp" 9 | #include "sketch/mesh-intersection.hpp" 10 | 11 | class SketchNodeIntersection : public SketchMeshIntersection 12 | { 13 | public: 14 | SketchNodeIntersection (); 15 | 16 | SketchNode& node () const; 17 | bool update (float, const glm::vec3&, const glm::vec3&, SketchMesh&, SketchNode&); 18 | 19 | private: 20 | SketchNode* _node; 21 | }; 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /lib/src/sketch/path-intersection.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #include "sketch/path-intersection.hpp" 6 | #include "sketch/path.hpp" 7 | 8 | SketchPathIntersection::SketchPathIntersection () 9 | : _path (nullptr) 10 | { 11 | } 12 | 13 | bool SketchPathIntersection::update (float d, const glm::vec3& p, const glm::vec3& n, 14 | SketchMesh& mesh, SketchPath& path) 15 | { 16 | if (this->SketchMeshIntersection::update (d, p, n, mesh)) 17 | { 18 | this->_path = &path; 19 | return true; 20 | } 21 | else 22 | { 23 | return false; 24 | } 25 | } 26 | 27 | SketchPath& SketchPathIntersection::path () const 28 | { 29 | assert (this->isIntersection ()); 30 | assert (this->_path); 31 | return *this->_path; 32 | } 33 | -------------------------------------------------------------------------------- /lib/src/sketch/path-intersection.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_SKETCH_PATH_INTERSECTION 6 | #define DILAY_SKETCH_PATH_INTERSECTION 7 | 8 | #include "sketch/fwd.hpp" 9 | #include "sketch/mesh-intersection.hpp" 10 | 11 | class SketchPathIntersection : public SketchMeshIntersection 12 | { 13 | public: 14 | SketchPathIntersection (); 15 | 16 | SketchPath& path () const; 17 | bool update (float, const glm::vec3&, const glm::vec3&, SketchMesh&, SketchPath&); 18 | 19 | private: 20 | SketchPath* _path; 21 | }; 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /lib/src/sketch/path.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_SKETCH_PATH 6 | #define DILAY_SKETCH_PATH 7 | 8 | #include 9 | #include "macro.hpp" 10 | #include "sketch/fwd.hpp" 11 | 12 | class Camera; 13 | class Intersection; 14 | class Mesh; 15 | class PrimAABox; 16 | class PrimPlane; 17 | class PrimRay; 18 | 19 | enum class SketchPathSmoothEffect 20 | { 21 | None, 22 | Embed, 23 | EmbedAndAdjust, 24 | Pinch 25 | }; 26 | 27 | class SketchPath 28 | { 29 | public: 30 | using Spheres = std::vector; 31 | 32 | DECLARE_BIG6 (SketchPath); 33 | 34 | const Spheres& spheres () const; 35 | const glm::vec3& minimum () const; 36 | const glm::vec3& maximum () const; 37 | const glm::vec3& intersectionFirst () const; 38 | const glm::vec3& intersectionLast () const; 39 | void intersectionFirst (const glm::vec3&); 40 | void intersectionLast (const glm::vec3&); 41 | void reset (); 42 | bool isEmpty () const; 43 | PrimAABox aabox () const; 44 | void addSphere (const glm::vec3&, const glm::vec3&, float); 45 | Spheres::iterator deleteSphere (Spheres::const_iterator); 46 | void render (Camera&, Mesh&) const; 47 | bool intersects (const PrimRay&, SketchMesh&, SketchPathIntersection&); 48 | SketchPath mirrorPositive (const PrimPlane&); 49 | void smooth (const PrimSphere&, unsigned int, SketchPathSmoothEffect, const PrimSphere*, 50 | const PrimSphere*); 51 | 52 | private: 53 | IMPLEMENTATION 54 | }; 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /lib/src/state.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_STATE 6 | #define DILAY_STATE 7 | 8 | #include 9 | #include "macro.hpp" 10 | 11 | class Cache; 12 | class Camera; 13 | class Config; 14 | class History; 15 | class Id; 16 | class Mesh; 17 | class Scene; 18 | class Tool; 19 | enum class ToolKey; 20 | enum class ToolResponse; 21 | class ViewMainWindow; 22 | class ViewShortcut; 23 | class ViewToolTip; 24 | 25 | class State 26 | { 27 | public: 28 | typedef std::initializer_list ViewShortcuts; 29 | 30 | DECLARE_BIG2 (State, ViewMainWindow&, Config&, Cache&) 31 | 32 | ViewMainWindow& mainWindow (); 33 | Config& config (); 34 | Cache& cache (); 35 | Camera& camera (); 36 | History& history (); 37 | Scene& scene (); 38 | bool hasTool (); 39 | Tool& tool (); 40 | void setTool (ToolKey); 41 | void setPreviousTool (); 42 | void setToolTip (const ViewToolTip*, const ViewShortcuts&); 43 | void setToolTip (const ViewToolTip*); 44 | void resetTool (); 45 | void fromConfig (); 46 | void undo (); 47 | void redo (); 48 | 49 | void handleToolResponse (ToolResponse); 50 | 51 | private: 52 | IMPLEMENTATION 53 | }; 54 | #endif 55 | -------------------------------------------------------------------------------- /lib/src/time-delta.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include "time-delta.hpp" 10 | 11 | namespace TimeDelta 12 | { 13 | struct TimeData 14 | { 15 | unsigned int numCalls; 16 | std::clock_t localTime; 17 | 18 | TimeData (std::clock_t c) 19 | : numCalls (1) 20 | , localTime (c) 21 | { 22 | } 23 | 24 | void call (std::clock_t c) 25 | { 26 | this->localTime += c; 27 | this->numCalls++; 28 | } 29 | }; 30 | 31 | const unsigned int nameWidth = 80; 32 | std::unordered_map data; 33 | std::clock_t globalTime; 34 | std::clock_t startTime; 35 | 36 | void printResults () 37 | { 38 | if (data.empty () == false) 39 | { 40 | const std::streamsize originalPrec = std::cout.precision (); 41 | 42 | std::cout << "##### time-delta (" << (float(globalTime) / CLOCKS_PER_SEC) << "s) ######\n"; 43 | 44 | for (auto pair : data) 45 | { 46 | std::cout << std::setw (nameWidth + 1) << std::left << pair.first 47 | << std::resetiosflags (std::ios_base::left) 48 | << (float(pair.second.localTime) / CLOCKS_PER_SEC) << "s (" << std::fixed 49 | << std::setprecision (1) 50 | << (100.0f * float(pair.second.localTime) / float(globalTime)) << "%) " 51 | << std::defaultfloat << std::setprecision (originalPrec) << "(" 52 | << pair.second.numCalls << " calls -> " 53 | << (1000.0f * (float(pair.second.localTime) / CLOCKS_PER_SEC) / 54 | float(pair.second.numCalls)) 55 | << "ms / call)\n"; 56 | } 57 | } 58 | } 59 | 60 | void initialize () 61 | { 62 | globalTime = 0; 63 | std::atexit (TimeDelta::printResults); 64 | } 65 | 66 | void resetTimer () { startTime = std::clock (); } 67 | void addBreakpoint (const char* name) 68 | { 69 | const std::clock_t diff = std::clock () - startTime; 70 | const std::string key = std::string (name).substr (0, nameWidth); 71 | auto it = data.find (key); 72 | 73 | if (it == data.end ()) 74 | { 75 | data.emplace (key, TimeData (diff)); 76 | } 77 | else 78 | { 79 | it->second.call (diff); 80 | } 81 | globalTime += diff; 82 | TimeDelta::resetTimer (); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /lib/src/time-delta.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_TIME_DELTA 6 | #define DILAY_TIME_DELTA 7 | 8 | #define TIME_DELTA(X) \ 9 | TimeDelta::resetTimer (); \ 10 | X; \ 11 | TimeDelta::addBreakpoint (#X); 12 | 13 | namespace TimeDelta 14 | { 15 | void initialize (); 16 | void resetTimer (); 17 | void addBreakpoint (const char*); 18 | } 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /lib/src/tool/delete-mesh.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #include 6 | #include "dynamic/mesh-intersection.hpp" 7 | #include "scene.hpp" 8 | #include "state.hpp" 9 | #include "tools.hpp" 10 | #include "view/pointing-event.hpp" 11 | #include "view/tool-tip.hpp" 12 | 13 | struct ToolDeleteMesh::Impl 14 | { 15 | ToolDeleteMesh* self; 16 | 17 | Impl (ToolDeleteMesh* s) 18 | : self (s) 19 | { 20 | } 21 | 22 | ToolResponse runInitialize () 23 | { 24 | ViewToolTip toolTip; 25 | toolTip.add (ViewInputEvent::MouseLeft, QObject::tr ("Delete selection")); 26 | this->self->state ().setToolTip (&toolTip); 27 | 28 | return ToolResponse::None; 29 | } 30 | 31 | ToolResponse runReleaseEvent (const ViewPointingEvent& e) 32 | { 33 | if (e.leftButton ()) 34 | { 35 | DynamicMeshIntersection intersection; 36 | if (this->self->intersectsScene (e, intersection)) 37 | { 38 | Scene& scene = this->self->state ().scene (); 39 | this->self->snapshotDynamicMeshes (); 40 | scene.deleteMesh (intersection.mesh ()); 41 | return ToolResponse::Redraw; 42 | } 43 | } 44 | return ToolResponse::None; 45 | } 46 | }; 47 | 48 | DELEGATE_TOOL (ToolDeleteMesh) 49 | DELEGATE_TOOL_RUN_RELEASE_EVENT (ToolDeleteMesh) 50 | -------------------------------------------------------------------------------- /lib/src/tool/key.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_TOOL_KEY 6 | #define DILAY_TOOL_KEY 7 | 8 | #include 9 | 10 | enum class ToolKey 11 | { 12 | TransformMesh, 13 | DeleteMesh, 14 | NewMesh, 15 | SculptDraw, 16 | SculptGrab, 17 | SculptSmooth, 18 | SculptFlatten, 19 | SculptCrease, 20 | SculptPinch, 21 | SculptReduce, 22 | EditSketch, 23 | DeleteSketch, 24 | ConvertSketch, 25 | SketchSpheres, 26 | TrimMesh, 27 | Remesh, 28 | MoveCamera 29 | }; 30 | 31 | namespace std 32 | { 33 | template <> struct hash 34 | { 35 | size_t operator() (const ToolKey& key) const { return std::hash () (int(key)); } 36 | }; 37 | } 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /lib/src/tool/move-camera.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_TOOL_MOVE_CAMERA 6 | #define DILAY_TOOL_MOVE_CAMERA 7 | 8 | #include "tool.hpp" 9 | 10 | class QWheelEvent; 11 | 12 | class ToolMoveCamera : public Tool 13 | { 14 | public: 15 | DECLARE_BIG2 (ToolMoveCamera, State&) 16 | 17 | ToolMoveCamera (State&, bool); 18 | 19 | ToolKey getKey () const { return ToolKey::MoveCamera; } 20 | 21 | ToolResponse wheelEvent (const QWheelEvent&); 22 | void snap (); 23 | void resetGazePoint (); 24 | 25 | private: 26 | IMPLEMENTATION 27 | 28 | ToolResponse runInitialize (); 29 | ToolResponse runMoveEvent (const ViewPointingEvent&); 30 | ToolResponse runPressEvent (const ViewPointingEvent&); 31 | void runFromConfig (); 32 | }; 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /lib/src/tool/new-mesh.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #include 6 | #include "cache.hpp" 7 | #include "dynamic/mesh.hpp" 8 | #include "mesh-util.hpp" 9 | #include "mesh.hpp" 10 | #include "render-mode.hpp" 11 | #include "scene.hpp" 12 | #include "state.hpp" 13 | #include "tools.hpp" 14 | #include "view/two-column-grid.hpp" 15 | #include "view/util.hpp" 16 | 17 | namespace 18 | { 19 | enum class MeshType 20 | { 21 | Icosphere, 22 | Cube 23 | }; 24 | } 25 | 26 | struct ToolNewMesh::Impl 27 | { 28 | ToolNewMesh* self; 29 | std::unique_ptr mesh; 30 | int subdivision; 31 | MeshType meshType; 32 | 33 | Impl (ToolNewMesh* s) 34 | : self (s) 35 | , subdivision (s->cache ().get ("subdivision", 4)) 36 | , meshType (MeshType (s->cache ().get ("mesh-type", int(MeshType::Icosphere)))) 37 | { 38 | } 39 | 40 | ToolResponse runInitialize () 41 | { 42 | this->setupProperties (); 43 | this->makeCurrentMesh (); 44 | return ToolResponse::Redraw; 45 | } 46 | 47 | void runRender () const 48 | { 49 | if (this->mesh) 50 | { 51 | this->mesh->renderMode () = this->self->state ().scene ().commonRenderMode (); 52 | this->mesh->render (this->self->state ().camera ()); 53 | } 54 | } 55 | 56 | ToolResponse runCommit () 57 | { 58 | if (this->mesh) 59 | { 60 | this->self->snapshotDynamicMeshes (); 61 | this->self->state ().scene ().newDynamicMesh (this->self->state ().config (), *this->mesh); 62 | } 63 | return ToolResponse::None; 64 | } 65 | 66 | void setupProperties () 67 | { 68 | ViewTwoColumnGrid& properties = this->self->properties (); 69 | 70 | QSlider& subdivisionEdit = ViewUtil::slider (1, this->subdivision, 6); 71 | ViewUtil::connect (subdivisionEdit, [this](int r) { 72 | this->subdivision = r; 73 | this->self->cache ().set ("subdivision", r); 74 | this->makeCurrentMesh (); 75 | }); 76 | properties.addStacked (QObject::tr ("Subdivisions"), subdivisionEdit); 77 | 78 | QButtonGroup& meshTypeEdit = 79 | ViewUtil::buttonGroup ({QObject::tr ("Icosphere"), QObject::tr ("Cube")}); 80 | ViewUtil::connect (meshTypeEdit, int(this->meshType), [this](int id) { 81 | this->meshType = MeshType (id); 82 | this->self->cache ().set ("mesh-type", id); 83 | this->makeCurrentMesh (); 84 | }); 85 | properties.add (meshTypeEdit); 86 | } 87 | 88 | void makeCurrentMesh () 89 | { 90 | switch (this->meshType) 91 | { 92 | case MeshType::Icosphere: 93 | this->mesh = std::make_unique (MeshUtil::icosphere (this->subdivision)); 94 | break; 95 | 96 | case MeshType::Cube: 97 | this->mesh = std::make_unique (MeshUtil::cube (this->subdivision)); 98 | break; 99 | } 100 | this->self->state ().scene ().setupMesh (this->self->state ().config (), *this->mesh); 101 | this->self->updateGlWidget (); 102 | } 103 | }; 104 | 105 | DELEGATE_TOOL (ToolNewMesh) 106 | DELEGATE_TOOL_RUN_RENDER (ToolNewMesh) 107 | DELEGATE_TOOL_RUN_COMMIT (ToolNewMesh) 108 | -------------------------------------------------------------------------------- /lib/src/tool/sculpt.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_TOOL_SCULPT 6 | #define DILAY_TOOL_SCULPT 7 | 8 | #include "tool.hpp" 9 | 10 | class QString; 11 | class SculptBrush; 12 | class ToolUtilMovement; 13 | class ViewCursor; 14 | class ViewDoubleSlider; 15 | class ViewTwoColumnGrid; 16 | 17 | class ToolSculpt : public Tool 18 | { 19 | public: 20 | DECLARE_BIG2 (ToolSculpt, State&, const char*) 21 | 22 | protected: 23 | SculptBrush& brush (); 24 | ViewCursor& cursor (); 25 | void addDefaultToolTip (ViewToolTip&, bool, bool) const; 26 | void sculpt (); 27 | bool drawlikeStroke (const ViewPointingEvent&, bool, const std::function* = nullptr); 28 | bool grablikeStroke (const ViewPointingEvent&, ToolUtilMovement&); 29 | void registerSecondarySlider (ViewDoubleSlider&); 30 | 31 | private: 32 | IMPLEMENTATION 33 | 34 | ToolResponse runInitialize (); 35 | void runRender () const; 36 | ToolResponse runPointingEvent (const ViewPointingEvent&); 37 | ToolResponse runCursorUpdate (const glm::ivec2&); 38 | ToolResponse runCommit (); 39 | void runFromConfig (); 40 | 41 | virtual void runSetupBrush (SculptBrush&) = 0; 42 | virtual void runSetupCursor (ViewCursor&) = 0; 43 | virtual void runSetupProperties (ViewTwoColumnGrid&) = 0; 44 | virtual void runSetupToolTip (ViewToolTip&) = 0; 45 | virtual bool runSculptPointingEvent (const ViewPointingEvent&) = 0; 46 | }; 47 | 48 | #define DECLARE_TOOL_SCULPT(keyName) \ 49 | class Tool##keyName : public ToolSculpt \ 50 | { \ 51 | public: \ 52 | DECLARE_BIG2 (Tool##keyName, State&) \ 53 | \ 54 | ToolKey getKey () const { return ToolKey::keyName; } \ 55 | \ 56 | private: \ 57 | IMPLEMENTATION \ 58 | void runSetupBrush (SculptBrush&); \ 59 | void runSetupCursor (ViewCursor&); \ 60 | void runSetupProperties (ViewTwoColumnGrid&); \ 61 | void runSetupToolTip (ViewToolTip&); \ 62 | bool runSculptPointingEvent (const ViewPointingEvent&); \ 63 | }; 64 | 65 | #define DELEGATE_TOOL_SCULPT(name) \ 66 | DELEGATE_BIG2_BASE (name, (State & s), (this), ToolSculpt, (s, #name)) \ 67 | DELEGATE1 (void, name, runSetupBrush, SculptBrush&); \ 68 | DELEGATE1 (void, name, runSetupCursor, ViewCursor&); \ 69 | DELEGATE1 (void, name, runSetupProperties, ViewTwoColumnGrid&); \ 70 | DELEGATE1 (void, name, runSetupToolTip, ViewToolTip&); \ 71 | DELEGATE1 (bool, name, runSculptPointingEvent, const ViewPointingEvent&) 72 | 73 | #endif 74 | -------------------------------------------------------------------------------- /lib/src/tool/sculpt/crease.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #include 6 | #include "cache.hpp" 7 | #include "tool/sculpt/util/brush.hpp" 8 | #include "tools.hpp" 9 | #include "view/double-slider.hpp" 10 | #include "view/two-column-grid.hpp" 11 | #include "view/util.hpp" 12 | 13 | struct ToolSculptCrease::Impl 14 | { 15 | ToolSculptCrease* self; 16 | 17 | Impl (ToolSculptCrease* s) 18 | : self (s) 19 | { 20 | } 21 | 22 | void runSetupBrush (SculptBrush& brush) 23 | { 24 | auto& params = brush.initParameters (); 25 | 26 | params.intensity (this->self->cache ().get ("intensity", 0.5f)); 27 | params.invert (this->self->cache ().get ("invert", false)); 28 | } 29 | 30 | void runSetupCursor (ViewCursor&) {} 31 | 32 | void runSetupProperties (ViewTwoColumnGrid& properties) 33 | { 34 | auto& params = this->self->brush ().parameters (); 35 | 36 | ViewDoubleSlider& intensityEdit = ViewUtil::slider (2, 0.1f, params.intensity (), 0.9f); 37 | ViewUtil::connect (intensityEdit, [this, ¶ms](float i) { 38 | params.intensity (i); 39 | this->self->cache ().set ("intensity", i); 40 | }); 41 | properties.addStacked (QObject::tr ("Intensity"), intensityEdit); 42 | this->self->registerSecondarySlider (intensityEdit); 43 | 44 | QCheckBox& invertEdit = ViewUtil::checkBox (QObject::tr ("Invert"), params.invert ()); 45 | ViewUtil::connect (invertEdit, [this, ¶ms](bool i) { 46 | params.invert (i); 47 | this->self->cache ().set ("invert", i); 48 | }); 49 | properties.add (invertEdit); 50 | } 51 | 52 | void runSetupToolTip (ViewToolTip& toolTip) 53 | { 54 | this->self->addDefaultToolTip (toolTip, true, true); 55 | } 56 | 57 | bool runSculptPointingEvent (const ViewPointingEvent& e) 58 | { 59 | const std::function toggleInvert = [this]() { 60 | this->self->brush ().parameters ().toggleInvert (); 61 | }; 62 | return this->self->drawlikeStroke (e, true, &toggleInvert); 63 | } 64 | }; 65 | 66 | DELEGATE_TOOL_SCULPT (ToolSculptCrease) 67 | -------------------------------------------------------------------------------- /lib/src/tool/sculpt/draw.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #include 6 | #include "cache.hpp" 7 | #include "tool/sculpt/util/brush.hpp" 8 | #include "tools.hpp" 9 | #include "view/double-slider.hpp" 10 | #include "view/two-column-grid.hpp" 11 | #include "view/util.hpp" 12 | 13 | struct ToolSculptDraw::Impl 14 | { 15 | ToolSculptDraw* self; 16 | 17 | Impl (ToolSculptDraw* s) 18 | : self (s) 19 | { 20 | } 21 | 22 | void runSetupBrush (SculptBrush& brush) 23 | { 24 | auto& params = brush.initParameters (); 25 | 26 | params.intensity (this->self->cache ().get ("intensity", 0.5f)); 27 | params.invert (this->self->cache ().get ("invert", false)); 28 | params.constantHeight (this->self->cache ().get ("constant-height", false)); 29 | } 30 | 31 | void runSetupCursor (ViewCursor&) {} 32 | 33 | void runSetupProperties (ViewTwoColumnGrid& properties) 34 | { 35 | auto& params = this->self->brush ().parameters (); 36 | 37 | ViewDoubleSlider& intensityEdit = ViewUtil::slider (2, 0.0f, params.intensity (), 1.0f); 38 | ViewUtil::connect (intensityEdit, [this, ¶ms](float i) { 39 | params.intensity (i); 40 | this->self->cache ().set ("intensity", i); 41 | }); 42 | properties.addStacked (QObject::tr ("Intensity"), intensityEdit); 43 | this->self->registerSecondarySlider (intensityEdit); 44 | 45 | QCheckBox& invertEdit = ViewUtil::checkBox (QObject::tr ("Invert"), params.invert ()); 46 | ViewUtil::connect (invertEdit, [this, ¶ms](bool i) { 47 | params.invert (i); 48 | this->self->cache ().set ("invert", i); 49 | }); 50 | properties.add (invertEdit); 51 | 52 | QCheckBox& constantHeightEdit = 53 | ViewUtil::checkBox (QObject::tr ("Constant height"), params.constantHeight ()); 54 | ViewUtil::connect (constantHeightEdit, [this, ¶ms](bool v) { 55 | params.constantHeight (v); 56 | this->self->cache ().set ("constant-height", v); 57 | }); 58 | properties.add (constantHeightEdit); 59 | } 60 | 61 | void runSetupToolTip (ViewToolTip& toolTip) 62 | { 63 | this->self->addDefaultToolTip (toolTip, true, true); 64 | } 65 | 66 | bool runSculptPointingEvent (const ViewPointingEvent& e) 67 | { 68 | SBDrawParameters& params = this->self->brush ().parameters (); 69 | 70 | const std::function toggleInvert = [¶ms]() { params.toggleInvert (); }; 71 | return this->self->drawlikeStroke (e, params.constantHeight (), &toggleInvert); 72 | } 73 | }; 74 | 75 | DELEGATE_TOOL_SCULPT (ToolSculptDraw) 76 | -------------------------------------------------------------------------------- /lib/src/tool/sculpt/flatten.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #include 6 | #include "cache.hpp" 7 | #include "dynamic/mesh-intersection.hpp" 8 | #include "primitive/plane.hpp" 9 | #include "state.hpp" 10 | #include "tool/sculpt/util/brush.hpp" 11 | #include "tool/util/movement.hpp" 12 | #include "tools.hpp" 13 | #include "view/double-slider.hpp" 14 | #include "view/pointing-event.hpp" 15 | #include "view/two-column-grid.hpp" 16 | #include "view/util.hpp" 17 | 18 | struct ToolSculptFlatten::Impl 19 | { 20 | ToolSculptFlatten* self; 21 | ToolUtilMovement movement; 22 | 23 | Impl (ToolSculptFlatten* s) 24 | : self (s) 25 | , movement (this->self->state ().camera (), glm::vec3 (0.0f)) 26 | { 27 | } 28 | 29 | void runSetupBrush (SculptBrush& brush) 30 | { 31 | auto& params = brush.initParameters (); 32 | 33 | params.intensity (this->self->cache ().get ("intensity", 0.5f)); 34 | params.lockPlane (this->self->cache ().get ("lock-plane", false)); 35 | 36 | brush.subdivide (false); 37 | } 38 | 39 | void runSetupCursor (ViewCursor&) {} 40 | 41 | void runSetupProperties (ViewTwoColumnGrid& properties) 42 | { 43 | auto& params = this->self->brush ().parameters (); 44 | 45 | ViewDoubleSlider& intensityEdit = ViewUtil::slider (2, 0.1f, params.intensity (), 1.0f); 46 | ViewUtil::connect (intensityEdit, [this, ¶ms](float i) { 47 | params.intensity (i); 48 | this->self->cache ().set ("intensity", i); 49 | }); 50 | properties.addStacked (QObject::tr ("Intensity"), intensityEdit); 51 | this->self->registerSecondarySlider (intensityEdit); 52 | 53 | QCheckBox& lockPlaneEdit = ViewUtil::checkBox (QObject::tr ("Lock plane"), params.lockPlane ()); 54 | ViewUtil::connect (lockPlaneEdit, [this, ¶ms](bool v) { 55 | params.lockPlane (v); 56 | params.resetLockedPlane (); 57 | this->self->cache ().set ("lock-plane", v); 58 | }); 59 | properties.add (lockPlaneEdit); 60 | } 61 | 62 | void runSetupToolTip (ViewToolTip& toolTip) 63 | { 64 | this->self->addDefaultToolTip (toolTip, false, true); 65 | } 66 | 67 | bool runSculptPointingEvent (const ViewPointingEvent& e) 68 | { 69 | auto& params = this->self->brush ().parameters (); 70 | 71 | if (params.lockPlane ()) 72 | { 73 | if (e.pressEvent ()) 74 | { 75 | DynamicMeshIntersection intersection; 76 | if (this->self->intersectsScene (e, intersection)) 77 | { 78 | params.lockedPlane (PrimPlane (intersection.position (), intersection.normal ())); 79 | this->movement.onFreePlane (intersection.normal ()); 80 | } 81 | else 82 | { 83 | params.resetLockedPlane (); 84 | } 85 | } 86 | return this->self->grablikeStroke (e, this->movement); 87 | } 88 | else 89 | { 90 | return this->self->drawlikeStroke (e, false); 91 | } 92 | } 93 | }; 94 | 95 | DELEGATE_TOOL_SCULPT (ToolSculptFlatten) 96 | -------------------------------------------------------------------------------- /lib/src/tool/sculpt/grab.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #include 6 | #include "cache.hpp" 7 | #include "state.hpp" 8 | #include "tool/sculpt/util/brush.hpp" 9 | #include "tool/util/movement.hpp" 10 | #include "tools.hpp" 11 | #include "view/pointing-event.hpp" 12 | #include "view/two-column-grid.hpp" 13 | #include "view/util.hpp" 14 | 15 | struct ToolSculptGrab::Impl 16 | { 17 | ToolSculptGrab* self; 18 | ToolUtilMovement movement; 19 | 20 | Impl (ToolSculptGrab* s) 21 | : self (s) 22 | , movement (this->self->state ().camera (), false) 23 | { 24 | } 25 | 26 | void runSetupBrush (SculptBrush& brush) 27 | { 28 | auto& params = brush.initParameters (); 29 | 30 | params.discardBack (this->self->cache ().get ("discard-back", false)); 31 | } 32 | 33 | void runSetupCursor (ViewCursor&) {} 34 | 35 | void runSetupProperties (ViewTwoColumnGrid& properties) 36 | { 37 | auto& params = this->self->brush ().parameters (); 38 | 39 | this->self->addMoveOnPrimaryPlaneProperties (this->movement); 40 | 41 | QCheckBox& discardEdit = 42 | ViewUtil::checkBox (QObject::tr ("Discard backfaces"), params.discardBack ()); 43 | ViewUtil::connect (discardEdit, [this, ¶ms](bool d) { 44 | params.discardBack (d); 45 | this->self->cache ().set ("discard-back", d); 46 | }); 47 | properties.add (discardEdit); 48 | } 49 | 50 | void runSetupToolTip (ViewToolTip& toolTip) 51 | { 52 | this->self->addDefaultToolTip (toolTip, false, false); 53 | } 54 | 55 | bool runSculptPointingEvent (const ViewPointingEvent& e) 56 | { 57 | return this->self->grablikeStroke (e, this->movement); 58 | } 59 | }; 60 | 61 | DELEGATE_TOOL_SCULPT (ToolSculptGrab) 62 | -------------------------------------------------------------------------------- /lib/src/tool/sculpt/pinch.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #include 6 | #include "cache.hpp" 7 | #include "tool/sculpt/util/brush.hpp" 8 | #include "tools.hpp" 9 | #include "view/two-column-grid.hpp" 10 | #include "view/util.hpp" 11 | 12 | struct ToolSculptPinch::Impl 13 | { 14 | ToolSculptPinch* self; 15 | 16 | Impl (ToolSculptPinch* s) 17 | : self (s) 18 | { 19 | } 20 | 21 | void runSetupBrush (SculptBrush& brush) 22 | { 23 | auto& params = brush.initParameters (); 24 | 25 | params.invert (this->self->cache ().get ("invert", false)); 26 | } 27 | 28 | void runSetupCursor (ViewCursor&) {} 29 | 30 | void runSetupProperties (ViewTwoColumnGrid& properties) 31 | { 32 | auto& params = this->self->brush ().parameters (); 33 | 34 | QCheckBox& invertEdit = ViewUtil::checkBox (QObject::tr ("Invert"), params.invert ()); 35 | ViewUtil::connect (invertEdit, [this, ¶ms](bool i) { 36 | params.invert (i); 37 | this->self->cache ().set ("invert", i); 38 | }); 39 | properties.add (invertEdit); 40 | } 41 | 42 | void runSetupToolTip (ViewToolTip& toolTip) 43 | { 44 | this->self->addDefaultToolTip (toolTip, true, false); 45 | } 46 | 47 | bool runSculptPointingEvent (const ViewPointingEvent& e) 48 | { 49 | const std::function toggleInvert = [this]() { 50 | this->self->brush ().parameters ().toggleInvert (); 51 | }; 52 | return this->self->drawlikeStroke (e, false, &toggleInvert); 53 | } 54 | }; 55 | 56 | DELEGATE_TOOL_SCULPT (ToolSculptPinch) 57 | -------------------------------------------------------------------------------- /lib/src/tool/sculpt/reduce.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #include "cache.hpp" 6 | #include "tool/sculpt/util/brush.hpp" 7 | #include "tools.hpp" 8 | #include "view/double-slider.hpp" 9 | #include "view/two-column-grid.hpp" 10 | #include "view/util.hpp" 11 | 12 | struct ToolSculptReduce::Impl 13 | { 14 | ToolSculptReduce* self; 15 | 16 | Impl (ToolSculptReduce* s) 17 | : self (s) 18 | { 19 | } 20 | 21 | void runSetupBrush (SculptBrush& brush) 22 | { 23 | auto& params = brush.initParameters (); 24 | 25 | params.intensity (this->self->cache ().get ("intensity", 0.5f)); 26 | 27 | brush.subdivide (false); 28 | } 29 | 30 | void runSetupCursor (ViewCursor&) {} 31 | 32 | void runSetupProperties (ViewTwoColumnGrid& properties) 33 | { 34 | auto& params = this->self->brush ().parameters (); 35 | 36 | ViewDoubleSlider& intensityEdit = ViewUtil::slider (2, 0.1f, params.intensity (), 0.9f); 37 | ViewUtil::connect (intensityEdit, [this, ¶ms](float i) { 38 | params.intensity (i); 39 | this->self->cache ().set ("intensity", i); 40 | }); 41 | properties.addStacked (QObject::tr ("Intensity"), intensityEdit); 42 | this->self->registerSecondarySlider (intensityEdit); 43 | } 44 | 45 | void runSetupToolTip (ViewToolTip& toolTip) 46 | { 47 | this->self->addDefaultToolTip (toolTip, false, true); 48 | } 49 | 50 | bool runSculptPointingEvent (const ViewPointingEvent& e) 51 | { 52 | return this->self->drawlikeStroke (e, false); 53 | } 54 | }; 55 | 56 | DELEGATE_TOOL_SCULPT (ToolSculptReduce) 57 | -------------------------------------------------------------------------------- /lib/src/tool/sculpt/smooth.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #include 6 | #include "cache.hpp" 7 | #include "tool/sculpt/util/brush.hpp" 8 | #include "tools.hpp" 9 | #include "view/double-slider.hpp" 10 | #include "view/two-column-grid.hpp" 11 | #include "view/util.hpp" 12 | 13 | struct ToolSculptSmooth::Impl 14 | { 15 | ToolSculptSmooth* self; 16 | 17 | Impl (ToolSculptSmooth* s) 18 | : self (s) 19 | { 20 | } 21 | 22 | void runSetupBrush (SculptBrush& brush) 23 | { 24 | auto& params = brush.initParameters (); 25 | 26 | params.intensity (this->self->cache ().get ("intensity", 0.5f)); 27 | 28 | brush.subdivide (false); 29 | } 30 | 31 | void runSetupCursor (ViewCursor&) {} 32 | 33 | void runSetupProperties (ViewTwoColumnGrid& properties) 34 | { 35 | auto& params = this->self->brush ().parameters (); 36 | 37 | ViewDoubleSlider& intensityEdit = ViewUtil::slider (2, 0.1f, params.intensity (), 1.0f); 38 | ViewUtil::connect (intensityEdit, [this, ¶ms](float i) { 39 | params.intensity (i); 40 | this->self->cache ().set ("intensity", i); 41 | }); 42 | properties.addStacked (QObject::tr ("Intensity"), intensityEdit); 43 | this->self->registerSecondarySlider (intensityEdit); 44 | } 45 | 46 | void runSetupToolTip (ViewToolTip& toolTip) 47 | { 48 | this->self->addDefaultToolTip (toolTip, false, true); 49 | } 50 | 51 | bool runSculptPointingEvent (const ViewPointingEvent& e) 52 | { 53 | return this->self->drawlikeStroke (e, false); 54 | } 55 | }; 56 | 57 | DELEGATE_TOOL_SCULPT (ToolSculptSmooth) 58 | -------------------------------------------------------------------------------- /lib/src/tool/sculpt/util/action.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_TOOL_SCULPT_ACTION 6 | #define DILAY_TOOL_SCULPT_ACTION 7 | 8 | class DynamicMesh; 9 | class SculptBrush; 10 | 11 | namespace ToolSculptAction 12 | { 13 | void sculpt (const SculptBrush&); 14 | void smoothMesh (DynamicMesh&); 15 | bool deleteFaces (DynamicMesh&, DynamicFaces&); 16 | }; 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /lib/src/tool/sculpt/util/edge-collection.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #include 6 | #include "tool/sculpt/util/edge-collection.hpp" 7 | #include "util.hpp" 8 | 9 | namespace 10 | { 11 | ui_pair makeUiKey (unsigned int i1, unsigned int i2) 12 | { 13 | assert (i1 != i2); 14 | return ui_pair (glm::min (i1, i2), glm::max (i1, i2)); 15 | } 16 | } 17 | 18 | void ToolSculptEdgeMap::insert (unsigned int i1, unsigned int i2, unsigned int value) 19 | { 20 | assert (this->contains (i1, i2) == false); 21 | this->map.emplace (makeUiKey (i1, i2), value); 22 | } 23 | 24 | unsigned int ToolSculptEdgeMap::find (unsigned int i1, unsigned int i2) const 25 | { 26 | const auto it = this->map.find (makeUiKey (i1, i2)); 27 | 28 | return it == this->map.end () ? Util::invalidIndex () : it->second; 29 | } 30 | 31 | bool ToolSculptEdgeMap::contains (unsigned int i1, unsigned int i2) const 32 | { 33 | return this->find (i1, i2) != Util::invalidIndex (); 34 | } 35 | 36 | bool ToolSculptEdgeMap::isEmpty () const { return this->map.empty (); } 37 | 38 | void ToolSculptEdgeMap::reset () { this->map.clear (); } 39 | 40 | void ToolSculptEdgeSet::insert (unsigned int i1, unsigned int i2) 41 | { 42 | this->set.emplace (makeUiKey (i1, i2)); 43 | } 44 | 45 | bool ToolSculptEdgeSet::contains (unsigned int i1, unsigned int i2) const 46 | { 47 | return this->set.find (makeUiKey (i1, i2)) != this->set.end (); 48 | } 49 | 50 | bool ToolSculptEdgeSet::isEmpty () const { return this->set.empty (); } 51 | 52 | void ToolSculptEdgeSet::reset () { this->set.clear (); } 53 | -------------------------------------------------------------------------------- /lib/src/tool/sculpt/util/edge-collection.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_TOOL_SCULPT_EDGE_COLLECTION 6 | #define DILAY_TOOL_SCULPT_EDGE_COLLECTION 7 | 8 | #include 9 | #include 10 | #include "hash.hpp" 11 | 12 | class ToolSculptEdgeMap 13 | { 14 | public: 15 | typedef std::unordered_map, unsigned int> Map; 16 | 17 | void insert (unsigned int, unsigned int, unsigned int); 18 | unsigned int find (unsigned int, unsigned int) const; 19 | bool contains (unsigned int, unsigned int) const; 20 | bool isEmpty () const; 21 | void reset (); 22 | 23 | private: 24 | Map map; 25 | }; 26 | 27 | class ToolSculptEdgeSet 28 | { 29 | public: 30 | typedef std::unordered_set> Set; 31 | 32 | void insert (unsigned int, unsigned int); 33 | bool contains (unsigned int, unsigned int) const; 34 | bool isEmpty () const; 35 | void reset (); 36 | 37 | Set::const_iterator begin () const { return this->set.begin (); } 38 | Set::const_iterator end () const { return this->set.end (); } 39 | 40 | private: 41 | Set set; 42 | }; 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /lib/src/tool/trim-mesh/action.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_TOOL_TRIM_MESH_ACTION 6 | #define DILAY_TOOL_TRIM_MESH_ACTION 7 | 8 | class ToolTrimMeshBorder; 9 | 10 | namespace ToolTrimMeshAction 11 | { 12 | bool trimMesh (ToolTrimMeshBorder&); 13 | } 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /lib/src/tool/trim-mesh/border.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_TOOL_TRIM_MESH_BORDER 6 | #define DILAY_TOOL_TRIM_MESH_BORDER 7 | 8 | #include 9 | #include 10 | #include "macro.hpp" 11 | 12 | class DynamicMesh; 13 | class PrimPlane; 14 | class PrimRay; 15 | 16 | class ToolTrimMeshBorder 17 | { 18 | public: 19 | typedef std::vector Polyline; 20 | typedef std::vector Polylines; 21 | 22 | DECLARE_BIG2 (ToolTrimMeshBorder, DynamicMesh&, const PrimRay&, const PrimRay&) 23 | 24 | DynamicMesh& mesh () const; 25 | const Polylines& polylines () const; 26 | const PrimPlane& plane () const; 27 | void addVertex (unsigned int, const glm::vec3&); 28 | void addPolyline (); 29 | void setNewIndices (const std::vector&); 30 | bool onBorder (const glm::vec3&) const; 31 | bool intersects (const PrimRay&, float&) const; 32 | void deleteEmptyPolylines (); 33 | bool hasVertices () const; 34 | 35 | private: 36 | IMPLEMENTATION 37 | }; 38 | #endif 39 | -------------------------------------------------------------------------------- /lib/src/tool/trim-mesh/split-mesh.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_TOOL_TRIM_MESH_SPLIT_MESH 6 | #define DILAY_TOOL_TRIM_MESH_SPLIT_MESH 7 | 8 | class ToolTrimMeshBorder; 9 | 10 | namespace ToolTrimMeshSplitMesh 11 | { 12 | bool splitMesh (ToolTrimMeshBorder&); 13 | } 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /lib/src/tool/util/movement.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #include "camera.hpp" 6 | #include "dimension.hpp" 7 | #include "intersection.hpp" 8 | #include "primitive/plane.hpp" 9 | #include "primitive/ray.hpp" 10 | #include "tool/util/movement.hpp" 11 | #include "view/pointing-event.hpp" 12 | 13 | namespace 14 | { 15 | enum class MovementPlane 16 | { 17 | Camera, 18 | Primary, 19 | Free 20 | }; 21 | } 22 | 23 | struct ToolUtilMovement::Impl 24 | { 25 | const Camera& camera; 26 | MovementPlane plane; 27 | glm::vec3 planeNormal; 28 | glm::vec3 previousPosition; 29 | glm::vec3 position; 30 | 31 | Impl (const Camera& cam, bool p) 32 | : camera (cam) 33 | , previousPosition (glm::vec3 (0.0f)) 34 | , position (glm::vec3 (0.0f)) 35 | { 36 | this->onPrimaryPlane (p); 37 | } 38 | 39 | Impl (const Camera& cam, const glm::vec3& n) 40 | : camera (cam) 41 | , previousPosition (glm::vec3 (0.0f)) 42 | , position (glm::vec3 (0.0f)) 43 | { 44 | this->onFreePlane (n); 45 | } 46 | 47 | void setPlaneNormal () 48 | { 49 | if (this->plane == MovementPlane::Camera) 50 | { 51 | this->planeNormal = this->camera.toEyePoint (); 52 | } 53 | else if (this->plane == MovementPlane::Primary) 54 | { 55 | this->planeNormal = DimensionUtil::vector (this->camera.primaryDimension ()); 56 | } 57 | } 58 | 59 | bool onPrimaryPlane () const { return this->plane == MovementPlane::Primary; } 60 | 61 | void onPrimaryPlane (bool yes) 62 | { 63 | this->plane = yes ? MovementPlane::Primary : MovementPlane::Camera; 64 | this->setPlaneNormal (); 65 | } 66 | 67 | void onFreePlane (const glm::vec3& n) 68 | { 69 | this->plane = MovementPlane::Free; 70 | this->planeNormal = n; 71 | } 72 | 73 | glm::vec3 delta () const { return this->position - this->previousPosition; } 74 | 75 | bool intersects (const glm::ivec2& p, glm::vec3& i) 76 | { 77 | this->setPlaneNormal (); 78 | 79 | const PrimRay ray = this->camera.ray (p); 80 | const PrimPlane plane (this->position, this->planeNormal); 81 | float t; 82 | 83 | if (IntersectionUtil::intersects (ray, plane, &t)) 84 | { 85 | i = ray.pointAt (t); 86 | return true; 87 | } 88 | return false; 89 | } 90 | 91 | bool move (const ViewPointingEvent& e) 92 | { 93 | glm::vec3 i; 94 | if (this->intersects (e.position (), i)) 95 | { 96 | this->previousPosition = this->position; 97 | this->position = i; 98 | return true; 99 | } 100 | else 101 | { 102 | return false; 103 | } 104 | } 105 | 106 | void reset (const glm::vec3& p) 107 | { 108 | this->previousPosition = p; 109 | this->position = p; 110 | } 111 | }; 112 | 113 | DELEGATE2_BIG3 (ToolUtilMovement, const Camera&, bool) 114 | DELEGATE2_CONSTRUCTOR (ToolUtilMovement, const Camera&, const glm::vec3&) 115 | DELEGATE_CONST (bool, ToolUtilMovement, onPrimaryPlane) 116 | DELEGATE1 (void, ToolUtilMovement, onPrimaryPlane, bool) 117 | DELEGATE1 (void, ToolUtilMovement, onFreePlane, const glm::vec3&) 118 | DELEGATE_CONST (glm::vec3, ToolUtilMovement, delta) 119 | GETTER_CONST (const glm::vec3&, ToolUtilMovement, position) 120 | DELEGATE1 (bool, ToolUtilMovement, move, const ViewPointingEvent&) 121 | DELEGATE1 (void, ToolUtilMovement, reset, const glm::vec3&) 122 | -------------------------------------------------------------------------------- /lib/src/tool/util/movement.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_TOOL_UTIL_MOVEMENT 6 | #define DILAY_TOOL_UTIL_MOVEMENT 7 | 8 | #include 9 | #include "macro.hpp" 10 | 11 | class Camera; 12 | class ViewPointingEvent; 13 | 14 | class ToolUtilMovement 15 | { 16 | public: 17 | DECLARE_BIG3 (ToolUtilMovement, const Camera&, bool) 18 | ToolUtilMovement (const Camera&, const glm::vec3&); 19 | 20 | bool onPrimaryPlane () const; 21 | void onPrimaryPlane (bool); 22 | void onFreePlane (const glm::vec3&); 23 | 24 | glm::vec3 delta () const; 25 | const glm::vec3& position () const; 26 | bool move (const ViewPointingEvent&); 27 | void reset (const glm::vec3&); 28 | 29 | private: 30 | IMPLEMENTATION 31 | }; 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /lib/src/tool/util/rotation.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #include 6 | #include "camera.hpp" 7 | #include "tool/util/rotation.hpp" 8 | #include "util.hpp" 9 | #include "view/pointing-event.hpp" 10 | 11 | struct ToolUtilRotation::Impl 12 | { 13 | const Camera& camera; 14 | glm::vec3 origin; 15 | glm::vec3 axis; 16 | glm::vec2 position; 17 | glm::vec2 direction; 18 | float angle; 19 | 20 | Impl (const Camera& cam) 21 | : camera (cam) 22 | { 23 | } 24 | 25 | glm::mat4x4 matrix () const { return Util::rotation (this->origin, this->axis, this->angle); } 26 | 27 | bool rotate (const ViewPointingEvent& e) 28 | { 29 | const glm::vec2 fPoint = glm::vec2 (e.position ()); 30 | const float threshold = 10.0f; 31 | 32 | if (glm::distance (this->position, fPoint) < threshold) 33 | { 34 | this->direction = glm::vec2 (0.0f); 35 | return false; 36 | } 37 | else if (this->direction == glm::vec2 (0.0f)) 38 | { 39 | this->direction = glm::normalize (fPoint - this->position); 40 | return false; 41 | } 42 | else 43 | { 44 | const glm::vec2 newDirection = glm::normalize (fPoint - this->position); 45 | const float dot = glm::dot (this->direction, newDirection); 46 | 47 | if (Util::almostEqual (dot, 1.0f)) 48 | { 49 | this->angle = 0.0f; 50 | } 51 | else if (Util::almostEqual (dot, -1.0f)) 52 | { 53 | this->angle = glm::pi (); 54 | } 55 | else 56 | { 57 | this->angle = glm::acos (dot); 58 | 59 | if (Util::cross (this->direction, newDirection) > 0.0f) 60 | { 61 | this->angle = (2.0f * glm::pi ()) - this->angle; 62 | } 63 | } 64 | this->direction = newDirection; 65 | return true; 66 | } 67 | } 68 | 69 | void reset (const glm::vec3& o) 70 | { 71 | this->origin = o; 72 | this->axis = this->camera.toEyePoint (); 73 | this->position = this->camera.fromWorld (o, glm::mat4x4 (1.0f), false); 74 | this->direction = glm::vec2 (0.0f); 75 | } 76 | 77 | void reset (const glm::vec3& o, const glm::vec3& a) 78 | { 79 | this->origin = o; 80 | this->axis = glm::normalize (a); 81 | this->position = this->camera.fromWorld (o, glm::mat4x4 (1.0f), false); 82 | this->direction = glm::vec2 (0.0f); 83 | } 84 | }; 85 | 86 | DELEGATE1_BIG3 (ToolUtilRotation, const Camera&) 87 | GETTER_CONST (const glm::vec3&, ToolUtilRotation, axis) 88 | GETTER_CONST (float, ToolUtilRotation, angle) 89 | DELEGATE_CONST (glm::mat4x4, ToolUtilRotation, matrix) 90 | DELEGATE1 (bool, ToolUtilRotation, rotate, const ViewPointingEvent&) 91 | DELEGATE1 (void, ToolUtilRotation, reset, const glm::vec3&) 92 | DELEGATE2 (void, ToolUtilRotation, reset, const glm::vec3&, const glm::vec3&) 93 | -------------------------------------------------------------------------------- /lib/src/tool/util/rotation.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_TOOL_UTIL_ROTATION 6 | #define DILAY_TOOL_UTIL_ROTATION 7 | 8 | #include 9 | #include 10 | #include "macro.hpp" 11 | 12 | class Camera; 13 | class ViewPointingEvent; 14 | 15 | class ToolUtilRotation 16 | { 17 | public: 18 | DECLARE_BIG3 (ToolUtilRotation, const Camera&) 19 | 20 | const glm::vec3& axis () const; 21 | float angle () const; 22 | glm::mat4x4 matrix () const; 23 | bool rotate (const ViewPointingEvent&); 24 | void reset (const glm::vec3&); 25 | void reset (const glm::vec3&, const glm::vec3&); 26 | 27 | private: 28 | IMPLEMENTATION 29 | }; 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /lib/src/tool/util/scaling.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_TOOL_UTIL_SCALING 6 | #define DILAY_TOOL_UTIL_SCALING 7 | 8 | #include 9 | #include "macro.hpp" 10 | 11 | class Camera; 12 | class ViewPointingEvent; 13 | 14 | class ToolUtilScaling 15 | { 16 | public: 17 | DECLARE_BIG3 (ToolUtilScaling, const Camera&) 18 | 19 | float factor () const; 20 | float factorRight () const; 21 | float factorUp () const; 22 | bool move (const ViewPointingEvent&); 23 | void reset (const glm::vec3&, const glm::vec3&); 24 | 25 | private: 26 | IMPLEMENTATION 27 | }; 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /lib/src/tool/util/step.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #include 6 | #include "tool/util/step.hpp" 7 | #include "util.hpp" 8 | 9 | namespace 10 | { 11 | const glm::vec3 invalidPosition (Util::maxFloat ()); 12 | } 13 | 14 | struct ToolUtilStep::Impl 15 | { 16 | glm::vec3 position; 17 | float stepWidth; 18 | 19 | Impl () 20 | : position (invalidPosition) 21 | , stepWidth (0.0f) 22 | { 23 | } 24 | 25 | void step (const glm::vec3& to, const std::function& f) 26 | { 27 | assert (this->position != invalidPosition); 28 | assert (this->stepWidth >= 0.0f); 29 | 30 | do 31 | { 32 | const glm::vec3 direction = to - this->position; 33 | const float distance = glm::length (direction); 34 | 35 | if (distance < this->stepWidth) 36 | { 37 | break; 38 | } 39 | this->position += direction * (this->stepWidth / distance); 40 | } while (f (this->position)); 41 | } 42 | }; 43 | 44 | DELEGATE_BIG3 (ToolUtilStep) 45 | GETTER_CONST (const glm::vec3&, ToolUtilStep, position) 46 | SETTER (const glm::vec3&, ToolUtilStep, position) 47 | SETTER (float, ToolUtilStep, stepWidth) 48 | DELEGATE2 (void, ToolUtilStep, step, const glm::vec3&, const std::function&) 49 | -------------------------------------------------------------------------------- /lib/src/tool/util/step.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_TOOL_UTIL_STEP 6 | #define DILAY_TOOL_UTIL_STEP 7 | 8 | #include 9 | #include 10 | #include "macro.hpp" 11 | 12 | class ToolUtilStep 13 | { 14 | public: 15 | DECLARE_BIG3 (ToolUtilStep) 16 | 17 | const glm::vec3& position () const; 18 | void position (const glm::vec3&); 19 | void stepWidth (float); 20 | void step (const glm::vec3&, const std::function&); 21 | 22 | private: 23 | IMPLEMENTATION 24 | }; 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /lib/src/tools.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_TOOLS 6 | #define DILAY_TOOLS 7 | 8 | #include "tool.hpp" 9 | #include "tool/move-camera.hpp" 10 | #include "tool/sculpt.hpp" 11 | 12 | DECLARE_TOOL (TransformMesh, DECLARE_TOOL_RUN_MOVE_EVENT DECLARE_TOOL_RUN_PRESS_EVENT 13 | DECLARE_TOOL_RUN_RELEASE_EVENT DECLARE_TOOL_RUN_COMMIT) 14 | 15 | DECLARE_TOOL (DeleteMesh, DECLARE_TOOL_RUN_RELEASE_EVENT) 16 | 17 | DECLARE_TOOL (NewMesh, DECLARE_TOOL_RUN_RENDER DECLARE_TOOL_RUN_COMMIT) 18 | 19 | DECLARE_TOOL_SCULPT (SculptDraw) 20 | DECLARE_TOOL_SCULPT (SculptGrab) 21 | DECLARE_TOOL_SCULPT (SculptSmooth) 22 | DECLARE_TOOL_SCULPT (SculptFlatten) 23 | DECLARE_TOOL_SCULPT (SculptCrease) 24 | DECLARE_TOOL_SCULPT (SculptPinch) 25 | DECLARE_TOOL_SCULPT (SculptReduce) 26 | 27 | DECLARE_TOOL (EditSketch, DECLARE_TOOL_RUN_MOVE_EVENT DECLARE_TOOL_RUN_PRESS_EVENT 28 | DECLARE_TOOL_RUN_RELEASE_EVENT DECLARE_TOOL_RUN_COMMIT) 29 | 30 | DECLARE_TOOL (DeleteSketch, DECLARE_TOOL_RUN_RELEASE_EVENT) 31 | 32 | DECLARE_TOOL (ConvertSketch, DECLARE_TOOL_RUN_RELEASE_EVENT) 33 | 34 | DECLARE_TOOL (SketchSpheres, 35 | DECLARE_TOOL_RUN_RENDER DECLARE_TOOL_RUN_MOVE_EVENT DECLARE_TOOL_RUN_PRESS_EVENT 36 | DECLARE_TOOL_RUN_RELEASE_EVENT DECLARE_TOOL_RUN_CURSOR_UPDATE 37 | DECLARE_TOOL_RUN_COMMIT DECLARE_TOOL_RUN_FROM_CONFIG) 38 | 39 | DECLARE_TOOL (TrimMesh, DECLARE_TOOL_RUN_MOVE_EVENT DECLARE_TOOL_RUN_RELEASE_EVENT 40 | DECLARE_TOOL_RUN_PAINT DECLARE_TOOL_RUN_COMMIT) 41 | 42 | DECLARE_TOOL (Remesh, 43 | DECLARE_TOOL_RUN_MOVE_EVENT DECLARE_TOOL_RUN_PRESS_EVENT 44 | DECLARE_TOOL_RUN_RELEASE_EVENT DECLARE_TOOL_RUN_PAINT DECLARE_TOOL_RUN_COMMIT) 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /lib/src/view/axis.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_VIEW_AXIS 6 | #define DILAY_VIEW_AXIS 7 | 8 | #include "configurable.hpp" 9 | #include "macro.hpp" 10 | 11 | class Camera; 12 | class Config; 13 | class QPainter; 14 | 15 | class ViewAxis : public Configurable 16 | { 17 | public: 18 | DECLARE_BIG3 (ViewAxis, const Config&) 19 | 20 | void render (Camera&); 21 | void render (Camera&, QPainter&); 22 | 23 | private: 24 | IMPLEMENTATION 25 | 26 | void runFromConfig (const Config&); 27 | }; 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /lib/src/view/color-button.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #include 6 | #include 7 | #include "color.hpp" 8 | #include "view/color-button.hpp" 9 | #include "view/util.hpp" 10 | 11 | struct ViewColorButton::Impl 12 | { 13 | ViewColorButton* self; 14 | Color color; 15 | 16 | Impl (ViewColorButton* s, const Color& c, bool alpha) 17 | : self (s) 18 | , color (c) 19 | { 20 | ViewUtil::connect (*this->self, [this, alpha]() { 21 | QColorDialog::ColorDialogOptions options; 22 | options.setFlag (QColorDialog::DontUseNativeDialog); 23 | 24 | if (alpha) 25 | { 26 | options.setFlag (QColorDialog::ShowAlphaChannel); 27 | } 28 | 29 | QColor selected = QColorDialog::getColor (this->color.qColor (), this->self->parentWidget (), 30 | QObject::tr ("Select color"), options); 31 | if (selected.isValid ()) 32 | { 33 | this->color = Color (selected); 34 | this->self->update (); 35 | emit this->self->colorChanged (this->color); 36 | } 37 | }); 38 | } 39 | 40 | void paintEvent (QPaintEvent* event) 41 | { 42 | this->self->QPushButton::paintEvent (event); 43 | 44 | QPainter painter (this->self); 45 | QRect rect (this->self->rect ()); 46 | 47 | const int dw = this->self->width () / 10; 48 | const int dh = this->self->height () / 5; 49 | 50 | rect.setLeft (rect.left () + dw); 51 | rect.setRight (rect.right () - dw); 52 | rect.setTop (rect.top () + dh); 53 | rect.setBottom (rect.bottom () - dh); 54 | 55 | painter.fillRect (rect, this->color.qColor ()); 56 | } 57 | }; 58 | 59 | DELEGATE_BIG2_BASE (ViewColorButton, (const Color& c, bool a, QWidget* p), (this, c, a), 60 | QPushButton, (p)) 61 | DELEGATE1 (void, ViewColorButton, paintEvent, QPaintEvent*) 62 | -------------------------------------------------------------------------------- /lib/src/view/color-button.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_COLOR_BUTTON 6 | #define DILAY_COLOR_BUTTON 7 | 8 | #include 9 | #include "macro.hpp" 10 | 11 | class Color; 12 | 13 | class ViewColorButton : public QPushButton 14 | { 15 | Q_OBJECT 16 | public: 17 | DECLARE_BIG2 (ViewColorButton, const Color&, bool = false, QWidget* = nullptr) 18 | 19 | signals: 20 | void colorChanged (const Color&); 21 | 22 | protected: 23 | void paintEvent (QPaintEvent*); 24 | 25 | private: 26 | IMPLEMENTATION 27 | }; 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /lib/src/view/configuration.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_VIEW_CONFIGURATION 6 | #define DILAY_VIEW_CONFIGURATION 7 | 8 | class ViewGlWidget; 9 | class ViewMainWindow; 10 | 11 | namespace ViewConfiguration 12 | { 13 | void show (ViewMainWindow&, ViewGlWidget&); 14 | } 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /lib/src/view/context-menu.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_VIEW_CONTEXT_MENU 6 | #define DILAY_VIEW_CONTEXT_MENU 7 | 8 | #include 9 | #include 10 | 11 | class DynamicMesh; 12 | class SketchMesh; 13 | class ViewMainWindow; 14 | 15 | class ViewContextMenu : public QMenu 16 | { 17 | public: 18 | ViewContextMenu (ViewMainWindow&, DynamicMesh&); 19 | ViewContextMenu (ViewMainWindow&, SketchMesh&); 20 | ViewContextMenu (ViewMainWindow&, const glm::ivec2&); 21 | }; 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /lib/src/view/cursor.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #include 6 | #include "mesh-util.hpp" 7 | #include "mesh.hpp" 8 | #include "opengl.hpp" 9 | #include "render-mode.hpp" 10 | #include "view/cursor.hpp" 11 | 12 | struct ViewCursor::Impl 13 | { 14 | Mesh radiusMesh; 15 | float _radius; 16 | bool isEnabled; 17 | 18 | static const unsigned int numSectors = 40; 19 | 20 | Impl () 21 | : _radius (0.0f) 22 | , isEnabled (false) 23 | { 24 | this->radiusMesh = MeshUtil::icosphere (2); 25 | this->radiusMesh.renderMode ().constantShading (true); 26 | this->radiusMesh.bufferData (); 27 | } 28 | 29 | float radius () const { return this->_radius; } 30 | 31 | glm::vec3 position () const { return this->radiusMesh.position (); } 32 | 33 | const Color& color () const { return this->radiusMesh.color (); } 34 | 35 | void radius (float r) 36 | { 37 | this->_radius = r; 38 | this->update (); 39 | } 40 | 41 | void position (const glm::vec3& p) { this->radiusMesh.position (p); } 42 | 43 | void color (const Color& color) { this->radiusMesh.color (color); } 44 | 45 | void enable () { this->isEnabled = true; } 46 | 47 | void disable () { this->isEnabled = false; } 48 | 49 | void render (Camera& camera) const 50 | { 51 | if (this->isEnabled) 52 | { 53 | OpenGL::glClear (OpenGL::StencilBufferBit ()); 54 | 55 | OpenGL::glDepthMask (false); 56 | OpenGL::glColorMask (false, false, false, false); 57 | OpenGL::glEnable (OpenGL::StencilTest ()); 58 | 59 | OpenGL::glCullFace (OpenGL::Front ()); 60 | 61 | OpenGL::glEnable (OpenGL::StencilTest ()); 62 | OpenGL::glStencilFunc (OpenGL::Always (), 1, 255); 63 | OpenGL::glStencilOp (OpenGL::Keep (), OpenGL::Replace (), OpenGL::Keep ()); 64 | 65 | this->radiusMesh.render (camera); 66 | 67 | OpenGL::glCullFace (OpenGL::Back ()); 68 | OpenGL::glColorMask (true, true, true, true); 69 | 70 | OpenGL::glStencilFunc (OpenGL::Equal (), 1, 255); 71 | OpenGL::glStencilOp (OpenGL::Keep (), OpenGL::Keep (), OpenGL::Keep ()); 72 | 73 | OpenGL::glEnable (OpenGL::Blend ()); 74 | OpenGL::glBlendEquation (OpenGL::FuncAdd ()); 75 | OpenGL::glBlendFunc (OpenGL::DstColor (), OpenGL::Zero ()); 76 | 77 | this->radiusMesh.render (camera); 78 | 79 | OpenGL::glDisable (OpenGL::Blend ()); 80 | OpenGL::glDisable (OpenGL::StencilTest ()); 81 | OpenGL::glDepthMask (true); 82 | } 83 | } 84 | 85 | void update () { this->radiusMesh.scaling (glm::vec3 (this->radius ())); } 86 | }; 87 | 88 | DELEGATE_BIG6 (ViewCursor) 89 | DELEGATE_CONST (float, ViewCursor, radius) 90 | DELEGATE_CONST (glm::vec3, ViewCursor, position) 91 | DELEGATE_CONST (const Color&, ViewCursor, color) 92 | GETTER_CONST (bool, ViewCursor, isEnabled) 93 | DELEGATE1 (void, ViewCursor, radius, float) 94 | DELEGATE1 (void, ViewCursor, position, const glm::vec3&) 95 | DELEGATE1 (void, ViewCursor, color, const Color&) 96 | DELEGATE (void, ViewCursor, enable) 97 | DELEGATE (void, ViewCursor, disable) 98 | DELEGATE1_CONST (void, ViewCursor, render, Camera&) 99 | -------------------------------------------------------------------------------- /lib/src/view/cursor.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_VIEW_CURSOR 6 | #define DILAY_VIEW_CURSOR 7 | 8 | #include 9 | #include "macro.hpp" 10 | 11 | class Camera; 12 | class Color; 13 | class Mesh; 14 | 15 | class ViewCursor 16 | { 17 | public: 18 | DECLARE_BIG6 (ViewCursor) 19 | 20 | float radius () const; 21 | glm::vec3 position () const; 22 | const Color& color () const; 23 | bool isEnabled () const; 24 | 25 | void radius (float); 26 | void position (const glm::vec3&); 27 | void color (const Color&); 28 | void enable (); 29 | void disable (); 30 | void render (Camera&) const; 31 | 32 | private: 33 | IMPLEMENTATION 34 | }; 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /lib/src/view/double-slider.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_DOUBLE_SLIDER 6 | #define DILAY_DOUBLE_SLIDER 7 | 8 | #include 9 | #include "macro.hpp" 10 | 11 | class ViewDoubleSlider : public QSlider 12 | { 13 | Q_OBJECT 14 | public: 15 | DECLARE_BIG2 (ViewDoubleSlider, unsigned short, unsigned short) 16 | 17 | double doubleValue () const; 18 | double doubleSingleStep () const; 19 | 20 | void setDoubleValue (double); 21 | void setDoubleRange (double, double); 22 | void setDoubleSingleStep (double); 23 | void setDoublePageStep (double); 24 | 25 | int intValue () const; 26 | int intSingleStep () const; 27 | 28 | void setIntValue (int); 29 | void setIntRange (int, int); 30 | void setIntSingleStep (int); 31 | void setIntPageStep (int); 32 | 33 | signals: 34 | void doubleValueChanged (double); 35 | 36 | private: 37 | int value () const; 38 | int singleStep () const; 39 | 40 | void setValue (int); 41 | void setRange (int, int); 42 | void setSingleStep (int); 43 | void setPageStep (int); 44 | 45 | IMPLEMENTATION 46 | }; 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /lib/src/view/floor-plane.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #include 6 | #include "camera.hpp" 7 | #include "color.hpp" 8 | #include "config.hpp" 9 | #include "mesh.hpp" 10 | #include "render-mode.hpp" 11 | #include "view/floor-plane.hpp" 12 | 13 | struct ViewFloorPlane::Impl 14 | { 15 | Mesh mesh; 16 | float tileWidth; 17 | unsigned int resolution; 18 | bool isActive; 19 | 20 | Impl (const Config& config, const Camera& camera) 21 | : resolution (0) 22 | , isActive (false) 23 | { 24 | this->runFromConfig (config); 25 | this->update (camera); 26 | } 27 | 28 | void render (Camera& camera) const 29 | { 30 | if (this->isActive) 31 | { 32 | this->mesh.renderLines (camera); 33 | } 34 | } 35 | 36 | void update (const Camera& cam) 37 | { 38 | const float w = cam.toWorld (float(cam.resolution ().x), glm::length (cam.position ())); 39 | const unsigned int r = (unsigned int) (w / this->tileWidth) + 2; 40 | 41 | if (r != this->resolution) 42 | { 43 | this->resolution = r; 44 | 45 | this->mesh.reset (); 46 | for (unsigned int j = 0; j < r; j++) 47 | { 48 | for (unsigned int i = 0; i < r; i++) 49 | { 50 | this->mesh.addVertex ( 51 | glm::vec3 (float(i) * this->tileWidth, 0.0f, float(j) * this->tileWidth)); 52 | } 53 | } 54 | for (unsigned int j = 1; j < r; j++) 55 | { 56 | this->mesh.addIndex (j - 1); 57 | this->mesh.addIndex (j); 58 | this->mesh.addIndex ((j - 1) * r); 59 | this->mesh.addIndex (j * r); 60 | 61 | for (unsigned int i = 1; i < r; i++) 62 | { 63 | this->mesh.addIndex ((j * r) + i - 1); 64 | this->mesh.addIndex ((j * r) + i); 65 | this->mesh.addIndex (((j - 1) * r) + i); 66 | this->mesh.addIndex ((j * r) + i); 67 | } 68 | } 69 | const float center = -0.5f * float(r - 1) * this->tileWidth; 70 | 71 | this->mesh.position (glm::vec3 (center, 0.0f, center)); 72 | this->mesh.renderMode ().constantShading (true); 73 | this->mesh.bufferData (); 74 | } 75 | } 76 | 77 | void runFromConfig (const Config& config) 78 | { 79 | this->mesh.color (config.get ("editor/floor-plane/color")); 80 | 81 | this->tileWidth = config.get ("editor/floor-plane/tile-width"); 82 | } 83 | }; 84 | 85 | DELEGATE2_BIG3 (ViewFloorPlane, const Config&, const Camera&) 86 | DELEGATE1_CONST (void, ViewFloorPlane, render, Camera&) 87 | DELEGATE1 (void, ViewFloorPlane, update, const Camera&) 88 | GETTER_CONST (bool, ViewFloorPlane, isActive) 89 | SETTER (bool, ViewFloorPlane, isActive) 90 | DELEGATE1 (void, ViewFloorPlane, runFromConfig, const Config&) 91 | -------------------------------------------------------------------------------- /lib/src/view/floor-plane.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_VIEW_FLOORPLANE 6 | #define DILAY_VIEW_FLOORPLANE 7 | 8 | #include "configurable.hpp" 9 | #include "macro.hpp" 10 | 11 | class Camera; 12 | class Config; 13 | 14 | class ViewFloorPlane : public Configurable { 15 | public: 16 | DECLARE_BIG3 (ViewFloorPlane, const Config&, const Camera&) 17 | 18 | void render (Camera&) const; 19 | void update (const Camera&); 20 | bool isActive () const; 21 | void isActive (bool); 22 | 23 | private: 24 | IMPLEMENTATION 25 | 26 | void runFromConfig (const Config&); 27 | }; 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /lib/src/view/gl-widget.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_VIEW_GL_WIDGET 6 | #define DILAY_VIEW_GL_WIDGET 7 | 8 | #include 9 | #include 10 | #include "macro.hpp" 11 | 12 | class Cache; 13 | class Config; 14 | class State; 15 | class ToolMoveCamera; 16 | class ViewFloorPlane; 17 | class ViewMainWindow; 18 | 19 | class ViewGlWidget : public QOpenGLWidget 20 | { 21 | Q_OBJECT 22 | public: 23 | DECLARE_BIG2 (ViewGlWidget, ViewMainWindow&, Config&, Cache&) 24 | 25 | ToolMoveCamera& immediateMoveCamera (); 26 | State& state (); 27 | ViewFloorPlane& floorPlane (); 28 | glm::ivec2 cursorPosition (); 29 | void fromConfig (); 30 | 31 | protected: 32 | void initializeGL (); 33 | void resizeGL (int, int); 34 | void paintGL (); 35 | 36 | void mouseMoveEvent (QMouseEvent*); 37 | void mousePressEvent (QMouseEvent*); 38 | void mouseReleaseEvent (QMouseEvent*); 39 | void wheelEvent (QWheelEvent*); 40 | void tabletEvent (QTabletEvent*); 41 | void keyPressEvent (QKeyEvent*); 42 | void keyReleaseEvent (QKeyEvent*); 43 | void enterEvent (QEvent*); 44 | void contextMenuEvent (QContextMenuEvent*); 45 | 46 | private: 47 | IMPLEMENTATION 48 | }; 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /lib/src/view/info-pane.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #include 6 | #include 7 | #include 8 | #include "view/info-pane.hpp" 9 | #include "view/info-pane/scene.hpp" 10 | #include "view/tool-tip.hpp" 11 | #include "view/two-column-grid.hpp" 12 | 13 | struct ViewInfoPane::Impl 14 | { 15 | ViewInfoPane* self; 16 | ViewMainWindow& mainWindow; 17 | ViewTwoColumnGrid& toolTip; 18 | ViewInfoPaneScene& scene; 19 | 20 | Impl (ViewInfoPane* s, ViewMainWindow& m) 21 | : self (s) 22 | , mainWindow (m) 23 | , toolTip (*new ViewTwoColumnGrid) 24 | , scene (*new ViewInfoPaneScene (m)) 25 | { 26 | QScrollArea* scrollArea = new QScrollArea; 27 | QTabWidget* tabWidget = new QTabWidget; 28 | 29 | tabWidget->addTab (this->initializeToolTipTab (), QObject::tr ("Keys")); 30 | tabWidget->addTab (&this->scene, QObject::tr ("Scene")); 31 | 32 | scrollArea->setWidgetResizable (true); 33 | scrollArea->setWidget (tabWidget); 34 | 35 | this->self->setWindowTitle (QObject::tr ("Info")); 36 | this->self->setWidget (scrollArea); 37 | this->self->setFeatures (DockWidgetMovable | DockWidgetClosable); 38 | this->self->setAllowedAreas (Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); 39 | 40 | this->resetToolTip (); 41 | } 42 | 43 | QWidget* initializeToolTipTab () 44 | { 45 | ViewToolTip dummyTip; 46 | dummyTip.add (ViewInputEvent::MouseMiddle, ViewInputModifier::Shift, "01234567890123456789"); 47 | this->addToolTip (dummyTip); 48 | this->toolTip.setEqualColumnStretch (); 49 | 50 | QWidget* pane = new QWidget; 51 | QVBoxLayout* layout = new QVBoxLayout (pane); 52 | 53 | layout->setContentsMargins (0, 0, 0, 0); 54 | layout->setSpacing (0); 55 | layout->addWidget (&this->toolTip); 56 | layout->addStretch (1); 57 | 58 | return pane; 59 | } 60 | 61 | void addToolTip (const ViewToolTip& tip) 62 | { 63 | if (tip.isEmpty ()) 64 | { 65 | return; 66 | } 67 | else if (this->toolTip.numRows () > 0) 68 | { 69 | this->toolTip.addSeparator (); 70 | } 71 | tip.render ( 72 | [this](const QString& action, const QString& tip) { this->toolTip.add (action, tip); }); 73 | } 74 | 75 | void resetToolTip () { this->toolTip.reset (); } 76 | }; 77 | 78 | DELEGATE_BIG2_BASE (ViewInfoPane, (ViewMainWindow & m, QWidget* p), (this, m), QDockWidget, (p)) 79 | GETTER (ViewInfoPaneScene&, ViewInfoPane, scene) 80 | DELEGATE1 (void, ViewInfoPane, addToolTip, const ViewToolTip&) 81 | DELEGATE (void, ViewInfoPane, resetToolTip) 82 | -------------------------------------------------------------------------------- /lib/src/view/info-pane.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_VIEW_INFO_PANE 6 | #define DILAY_VIEW_INFO_PANE 7 | 8 | #include 9 | #include "macro.hpp" 10 | 11 | class ViewInfoPaneScene; 12 | class ViewMainWindow; 13 | class ViewToolTip; 14 | 15 | class ViewInfoPane : public QDockWidget 16 | { 17 | public: 18 | DECLARE_BIG2 (ViewInfoPane, ViewMainWindow&, QWidget* = nullptr) 19 | 20 | ViewInfoPaneScene& scene (); 21 | void addToolTip (const ViewToolTip&); 22 | void resetToolTip (); 23 | void reset (); 24 | 25 | private: 26 | IMPLEMENTATION 27 | }; 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /lib/src/view/info-pane/scene.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_VIEW_INFO_PANE_SCENE 6 | #define DILAY_VIEW_INFO_PANE_SCENE 7 | 8 | #include 9 | #include "macro.hpp" 10 | 11 | class ViewMainWindow; 12 | 13 | class ViewInfoPaneScene : public QWidget 14 | { 15 | public: 16 | DECLARE_BIG2 (ViewInfoPaneScene, ViewMainWindow&, QWidget* = nullptr) 17 | 18 | void updateInfo (); 19 | 20 | private: 21 | IMPLEMENTATION 22 | }; 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /lib/src/view/input.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_VIEW_INPUT 6 | #define DILAY_VIEW_INPUT 7 | 8 | class QKeySequence; 9 | class QString; 10 | 11 | enum class ViewInputEvent 12 | { 13 | A, 14 | B, 15 | C, 16 | D, 17 | E, 18 | F, 19 | G, 20 | H, 21 | I, 22 | J, 23 | K, 24 | L, 25 | M, 26 | N, 27 | O, 28 | P, 29 | Q, 30 | R, 31 | S, 32 | T, 33 | U, 34 | V, 35 | W, 36 | X, 37 | Y, 38 | Z, 39 | Esc, 40 | Space, 41 | MouseLeft, 42 | MouseMiddle, 43 | MouseWheel, 44 | MouseRight 45 | }; 46 | 47 | enum class ViewInputModifier 48 | { 49 | None, 50 | Ctrl, 51 | Shift, 52 | Alt 53 | }; 54 | 55 | namespace ViewInput 56 | { 57 | QKeySequence toQKeySequence (ViewInputEvent, ViewInputModifier); 58 | QString toQString (ViewInputEvent); 59 | QString toQString (ViewInputModifier); 60 | QString toQString (ViewInputEvent, ViewInputModifier); 61 | } 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /lib/src/view/key-event.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #include 6 | #include "view/key-event.hpp" 7 | 8 | ViewKeyEvent::ViewKeyEvent (const QKeyEvent& event, bool press) 9 | : _key (Qt::Key (event.key ())) 10 | , _pressEvent (press) 11 | , _releaseEvent (not press) 12 | { 13 | } 14 | -------------------------------------------------------------------------------- /lib/src/view/key-event.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_VIEW_KEY_EVENT 6 | #define DILAY_VIEW_KEY_EVENT 7 | 8 | #include 9 | 10 | class QKeyEvent; 11 | 12 | class ViewKeyEvent 13 | { 14 | public: 15 | explicit ViewKeyEvent (const QKeyEvent&, bool); 16 | 17 | Qt::Key key () const { return this->_key; } 18 | 19 | bool pressEvent () const { return this->_pressEvent; } 20 | 21 | bool releaseEvent () const { return this->_releaseEvent; } 22 | 23 | private: 24 | Qt::Key _key; 25 | bool _pressEvent; 26 | bool _releaseEvent; 27 | }; 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /lib/src/view/light.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #include 6 | #include "color.hpp" 7 | #include "view/light.hpp" 8 | 9 | struct ViewLight::Impl 10 | { 11 | glm::vec3 position; 12 | Color color; 13 | float irradiance; 14 | 15 | Impl (const glm::vec3& p, const Color& c, float i) 16 | : position (p) 17 | , color (c) 18 | , irradiance (i) 19 | { 20 | } 21 | }; 22 | 23 | DELEGATE3_BIG6 (ViewLight, const glm::vec3&, const Color&, float) 24 | 25 | GETTER_CONST (const glm::vec3&, ViewLight, position) 26 | GETTER_CONST (const Color&, ViewLight, color) 27 | GETTER_CONST (float, ViewLight, irradiance) 28 | 29 | SETTER (const glm::vec3&, ViewLight, position) 30 | SETTER (const Color&, ViewLight, color) 31 | SETTER (float, ViewLight, irradiance) 32 | -------------------------------------------------------------------------------- /lib/src/view/light.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_VIEW_LIGHT 6 | #define DILAY_VIEW_LIGHT 7 | 8 | #include 9 | #include "macro.hpp" 10 | 11 | class Color; 12 | 13 | class ViewLight 14 | { 15 | public: 16 | DECLARE_BIG6 (ViewLight, const glm::vec3&, const Color&, float); 17 | 18 | const glm::vec3& position () const; 19 | const Color& color () const; 20 | float irradiance () const; 21 | 22 | void position (const glm::vec3&); 23 | void color (const Color&); 24 | void irradiance (float); 25 | 26 | private: 27 | IMPLEMENTATION 28 | }; 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /lib/src/view/log.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include "../util.hpp" 13 | #include "view/log.hpp" 14 | #include "view/main-window.hpp" 15 | #include "view/util.hpp" 16 | 17 | QString ViewLog::logPath () { return QDir::temp ().filePath ("dilay.log"); } 18 | 19 | QString ViewLog::crashLogPath () { return QDir::temp ().filePath ("dilay-crash.log"); } 20 | 21 | void ViewLog::show (ViewMainWindow& window) 22 | { 23 | QDialog dialog (&window); 24 | QVBoxLayout* layout = new QVBoxLayout; 25 | QTextEdit* textEdit = new QTextEdit (&dialog); 26 | 27 | textEdit->setReadOnly (true); 28 | textEdit->setLineWrapMode (QTextEdit::NoWrap); 29 | 30 | if (QFile (ViewLog::logPath ()).exists ()) 31 | { 32 | const std::string content = Util::readFile (ViewLog::logPath ().toStdString ()); 33 | textEdit->setPlainText ("-- LOG ----------------------------------"); 34 | textEdit->append (QString::fromStdString (content)); 35 | textEdit->append (""); 36 | } 37 | 38 | if (QFile (ViewLog::crashLogPath ()).exists ()) 39 | { 40 | const std::string content = Util::readFile (ViewLog::crashLogPath ().toStdString ()); 41 | textEdit->append ("-- CRASH LOG ----------------------------"); 42 | textEdit->append (QString::fromStdString (content)); 43 | textEdit->append (""); 44 | } 45 | 46 | QDialogButtonBox* buttons = new QDialogButtonBox (QDialogButtonBox::Close); 47 | QPushButton* ctc = 48 | buttons->addButton (QObject::tr ("Copy to clipboard"), QDialogButtonBox::ActionRole); 49 | 50 | QObject::connect (buttons, &QDialogButtonBox::rejected, [&dialog]() { dialog.reject (); }); 51 | 52 | ViewUtil::connect (*ctc, [textEdit]() { 53 | if (QGuiApplication::clipboard ()) 54 | { 55 | QGuiApplication::clipboard ()->setText (textEdit->toPlainText ()); 56 | } 57 | else 58 | { 59 | DILAY_WARN ("Could not access clipboard"); 60 | } 61 | }); 62 | 63 | layout->addWidget (textEdit); 64 | layout->addWidget (buttons); 65 | 66 | dialog.setFixedWidth (100 * QFontMetrics (textEdit->currentFont ()).width ("x")); 67 | dialog.setFixedHeight (25 * QFontMetrics (textEdit->currentFont ()).height ()); 68 | dialog.setLayout (layout); 69 | dialog.setWindowTitle (QObject::tr ("Log")); 70 | dialog.exec (); 71 | } 72 | -------------------------------------------------------------------------------- /lib/src/view/log.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_VIEW_LOG 6 | #define DILAY_VIEW_LOG 7 | 8 | #include 9 | 10 | class ViewMainWindow; 11 | 12 | namespace ViewLog 13 | { 14 | QString logPath (); 15 | QString crashLogPath (); 16 | void show (ViewMainWindow&); 17 | } 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /lib/src/view/main-window.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #include 6 | #include "view/gl-widget.hpp" 7 | #include "view/info-pane.hpp" 8 | #include "view/info-pane/scene.hpp" 9 | #include "view/main-window.hpp" 10 | #include "view/menu-bar.hpp" 11 | #include "view/tool-pane.hpp" 12 | #include "view/util.hpp" 13 | 14 | struct ViewMainWindow::Impl 15 | { 16 | ViewMainWindow* self; 17 | ViewGlWidget& glWidget; 18 | ViewToolPane& toolPane; 19 | ViewInfoPane& infoPane; 20 | 21 | Impl (ViewMainWindow* s, Config& config, Cache& cache) 22 | : self (s) 23 | , glWidget (*new ViewGlWidget (*this->self, config, cache)) 24 | , toolPane (*new ViewToolPane (this->glWidget)) 25 | , infoPane (*new ViewInfoPane (*this->self)) 26 | { 27 | this->self->setCentralWidget (&this->glWidget); 28 | this->self->addDockWidget (Qt::LeftDockWidgetArea, &this->toolPane); 29 | this->self->addDockWidget (Qt::RightDockWidgetArea, &this->infoPane); 30 | 31 | ViewMenuBar::setup (*this->self, this->glWidget); 32 | } 33 | 34 | void update () 35 | { 36 | this->self->QMainWindow::update (); 37 | this->glWidget.update (); 38 | this->infoPane.scene ().updateInfo (); 39 | } 40 | 41 | void closeEvent (QCloseEvent* e) 42 | { 43 | #ifndef NDEBUG 44 | e->accept (); 45 | #else 46 | if (ViewUtil::question (*this->self, QObject::tr ("Do you want to quit?"))) 47 | { 48 | e->accept (); 49 | } 50 | else 51 | { 52 | e->ignore (); 53 | } 54 | #endif 55 | } 56 | }; 57 | 58 | DELEGATE2_BIG2_SELF (ViewMainWindow, Config&, Cache&) 59 | GETTER (ViewGlWidget&, ViewMainWindow, glWidget) 60 | GETTER (ViewToolPane&, ViewMainWindow, toolPane) 61 | GETTER (ViewInfoPane&, ViewMainWindow, infoPane) 62 | DELEGATE (void, ViewMainWindow, update) 63 | DELEGATE1 (void, ViewMainWindow, closeEvent, QCloseEvent*) 64 | -------------------------------------------------------------------------------- /lib/src/view/main-window.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_VIEW_MAIN_WINDOW 6 | #define DILAY_VIEW_MAIN_WINDOW 7 | 8 | #include 9 | #include "macro.hpp" 10 | 11 | class Cache; 12 | class Config; 13 | class QCloseEvent; 14 | class ViewGlWidget; 15 | class ViewInfoPane; 16 | class ViewToolPane; 17 | 18 | class ViewMainWindow : public QMainWindow 19 | { 20 | Q_OBJECT 21 | public: 22 | DECLARE_BIG2 (ViewMainWindow, Config&, Cache&) 23 | 24 | ViewGlWidget& glWidget (); 25 | ViewToolPane& toolPane (); 26 | ViewInfoPane& infoPane (); 27 | void update (); 28 | 29 | protected: 30 | void closeEvent (QCloseEvent*); 31 | 32 | private: 33 | IMPLEMENTATION 34 | }; 35 | #endif 36 | -------------------------------------------------------------------------------- /lib/src/view/menu-bar.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_VIEW_MENU_BAR 6 | #define DILAY_VIEW_MENU_BAR 7 | 8 | class ViewGlWidget; 9 | class ViewMainWindow; 10 | 11 | namespace ViewMenuBar 12 | { 13 | void setup (ViewMainWindow&, ViewGlWidget&); 14 | } 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /lib/src/view/pointing-event.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #include 6 | #include 7 | #include 8 | #include "config.hpp" 9 | #include "view/pointing-event.hpp" 10 | 11 | namespace 12 | { 13 | Qt::MouseButton fromButtons (const Qt::MouseButtons& buttons) 14 | { 15 | if (buttons.testFlag (Qt::LeftButton)) 16 | { 17 | return Qt::LeftButton; 18 | } 19 | else if (buttons.testFlag (Qt::MiddleButton)) 20 | { 21 | return Qt::MiddleButton; 22 | } 23 | else if (buttons.testFlag (Qt::RightButton)) 24 | { 25 | return Qt::RightButton; 26 | } 27 | else 28 | { 29 | return Qt::NoButton; 30 | } 31 | } 32 | } 33 | 34 | ViewPointingEvent::ViewPointingEvent (const QMouseEvent& event) 35 | : _modifiers (event.modifiers ()) 36 | , _pressEvent (event.type () == QEvent::MouseButtonPress) 37 | , _moveEvent (event.type () == QEvent::MouseMove) 38 | , _releaseEvent (event.type () == QEvent::MouseButtonRelease) 39 | , _button (fromButtons (this->_moveEvent ? event.buttons () : event.button ())) 40 | , _position (glm::ivec2 (event.x (), event.y ())) 41 | , _prevPosition (_position) 42 | , _intensity (1.0f) 43 | { 44 | } 45 | 46 | ViewPointingEvent::ViewPointingEvent (const Config& config, const QTabletEvent& event) 47 | : _modifiers (QGuiApplication::queryKeyboardModifiers ()) 48 | , _pressEvent (event.type () == QEvent::TabletPress) 49 | , _moveEvent (event.type () == QEvent::TabletMove) 50 | , _releaseEvent (event.type () == QEvent::TabletRelease) 51 | , _button (fromButtons (this->_moveEvent ? event.buttons () : event.button ())) 52 | , _position (glm::ivec2 (event.x (), event.y ())) 53 | , _prevPosition (_position) 54 | , _intensity (config.get ("editor/tablet-pressure-intensity") * event.pressure ()) 55 | { 56 | } 57 | 58 | ViewPointingEvent::ViewPointingEvent (const ViewPointingEvent& e, const glm::ivec2& prevPos) 59 | : _modifiers (e._modifiers) 60 | , _pressEvent (e._pressEvent) 61 | , _moveEvent (e._moveEvent) 62 | , _releaseEvent (e._releaseEvent) 63 | , _button (e._button) 64 | , _position (e._position) 65 | , _prevPosition (prevPos) 66 | , _intensity (e._intensity) 67 | { 68 | } 69 | 70 | bool ViewPointingEvent::valid () const 71 | { 72 | return this->pressEvent () || this->moveEvent () || this->releaseEvent (); 73 | } 74 | 75 | bool ViewPointingEvent::leftButton () const { return this->_button == Qt::LeftButton; } 76 | 77 | bool ViewPointingEvent::middleButton () const { return this->_button == Qt::MiddleButton; } 78 | 79 | bool ViewPointingEvent::rightButton () const { return this->_button == Qt::RightButton; } 80 | -------------------------------------------------------------------------------- /lib/src/view/pointing-event.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_VIEW_POINTING_EVENT 6 | #define DILAY_VIEW_POINTING_EVENT 7 | 8 | #include 9 | #include 10 | 11 | class Config; 12 | class QMouseEvent; 13 | class QTabletEvent; 14 | 15 | class ViewPointingEvent 16 | { 17 | public: 18 | explicit ViewPointingEvent (const QMouseEvent&); 19 | explicit ViewPointingEvent (const Config&, const QTabletEvent&); 20 | explicit ViewPointingEvent (const ViewPointingEvent&, const glm::ivec2&); 21 | 22 | bool valid () const; 23 | bool leftButton () const; 24 | bool middleButton () const; 25 | bool rightButton () const; 26 | 27 | Qt::KeyboardModifiers modifiers () const { return this->_modifiers; } 28 | 29 | bool pressEvent () const { return this->_pressEvent; } 30 | 31 | bool moveEvent () const { return this->_moveEvent; } 32 | 33 | bool releaseEvent () const { return this->_releaseEvent; } 34 | 35 | const glm::ivec2& position () const { return this->_position; } 36 | 37 | glm::ivec2 delta () const { return this->_position - this->_prevPosition; } 38 | 39 | float intensity () const { return this->_intensity; } 40 | 41 | private: 42 | Qt::KeyboardModifiers _modifiers; 43 | bool _pressEvent; 44 | bool _moveEvent; 45 | bool _releaseEvent; 46 | Qt::MouseButton _button; 47 | glm::ivec2 _position; 48 | glm::ivec2 _prevPosition; 49 | float _intensity; 50 | }; 51 | #endif 52 | -------------------------------------------------------------------------------- /lib/src/view/resolution-slider.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #include "view/resolution-slider.hpp" 6 | #include "view/util.hpp" 7 | 8 | struct ViewResolutionSlider::Impl 9 | { 10 | Impl (ViewResolutionSlider* s, float min, float max) 11 | { 12 | ViewDoubleSlider* doubleSlider = s; 13 | ViewUtil::connect (*doubleSlider, 14 | [s, min, max](float r) { emit s->resolutionChanged (max + min - r); }); 15 | } 16 | }; 17 | 18 | DELEGATE_BIG2_BASE (ViewResolutionSlider, (float min, float max), (this, min, max), 19 | ViewDoubleSlider, (2, 1)) 20 | -------------------------------------------------------------------------------- /lib/src/view/resolution-slider.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_VIEW_RESOLUTION_SLIDER 6 | #define DILAY_VIEW_RESOLUTION_SLIDER 7 | 8 | #include "view/double-slider.hpp" 9 | 10 | class ViewResolutionSlider : public ViewDoubleSlider 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | DECLARE_BIG2 (ViewResolutionSlider, float, float) 16 | 17 | signals: 18 | void resolutionChanged (float); 19 | 20 | private: 21 | IMPLEMENTATION 22 | }; 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /lib/src/view/shortcut.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #include 6 | #include 7 | #include "view/input.hpp" 8 | #include "view/shortcut.hpp" 9 | 10 | namespace 11 | { 12 | typedef ViewShortcut::Call Call; 13 | } 14 | 15 | struct ViewShortcut::Impl 16 | { 17 | ViewInputEvent event; 18 | ViewInputModifier modifier; 19 | QString label; 20 | Call call; 21 | 22 | Impl (const ViewInputEvent& e, const ViewInputModifier& m, const QString& l, Call&& c) 23 | : event (e) 24 | , modifier (m) 25 | , label (l) 26 | , call (std::move (c)) 27 | { 28 | } 29 | 30 | Impl (const ViewInputEvent& e, const QString& l, Call&& c) 31 | : Impl (e, ViewInputModifier::None, l, std::move (c)) 32 | { 33 | } 34 | 35 | QShortcut& toQShortcut (QWidget& parent) const 36 | { 37 | const QKeySequence keys = ViewInput::toQKeySequence (this->event, this->modifier); 38 | QShortcut& shortcut = *new QShortcut (keys, &parent); 39 | 40 | QObject::connect (&shortcut, &QShortcut::activated, this->call); 41 | 42 | return shortcut; 43 | } 44 | }; 45 | 46 | DELEGATE3_BIG6 (ViewShortcut, const ViewInputEvent&, const QString&, Call&&) 47 | DELEGATE4_CONSTRUCTOR (ViewShortcut, const ViewInputEvent&, const ViewInputModifier&, 48 | const QString&, Call&&) 49 | GETTER_CONST (ViewInputEvent, ViewShortcut, event) 50 | GETTER_CONST (ViewInputModifier, ViewShortcut, modifier) 51 | GETTER_CONST (const QString&, ViewShortcut, label) 52 | GETTER_CONST (const Call&, ViewShortcut, call) 53 | DELEGATE1_CONST (QShortcut&, ViewShortcut, toQShortcut, QWidget&) 54 | -------------------------------------------------------------------------------- /lib/src/view/shortcut.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_VIEW_SHORTCUT 6 | #define DILAY_VIEW_SHORTCUT 7 | 8 | #include 9 | #include "macro.hpp" 10 | 11 | enum class ViewInputEvent; 12 | enum class ViewInputModifier; 13 | class QShortcut; 14 | class QString; 15 | class QWidget; 16 | 17 | class ViewShortcut 18 | { 19 | public: 20 | typedef std::function Call; 21 | 22 | DECLARE_BIG6 (ViewShortcut, const ViewInputEvent&, const QString&, Call&&) 23 | 24 | ViewShortcut (const ViewInputEvent&, const ViewInputModifier&, const QString&, Call&&); 25 | 26 | ViewInputEvent event () const; 27 | ViewInputModifier modifier () const; 28 | const QString& label () const; 29 | const Call& call () const; 30 | QShortcut& toQShortcut (QWidget&) const; 31 | 32 | private: 33 | IMPLEMENTATION 34 | }; 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /lib/src/view/tool-pane.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_VIEW_TOOL_PANE 6 | #define DILAY_VIEW_TOOL_PANE 7 | 8 | #include 9 | #include "macro.hpp" 10 | 11 | enum class ToolKey; 12 | class QPushButton; 13 | class ViewGlWidget; 14 | class ViewTwoColumnGrid; 15 | 16 | enum class ViewToolPaneSelection 17 | { 18 | Sculpt, 19 | Sketch 20 | }; 21 | 22 | class ViewToolPane : public QDockWidget 23 | { 24 | public: 25 | DECLARE_BIG2 (ViewToolPane, ViewGlWidget&, QWidget* = nullptr) 26 | 27 | ViewTwoColumnGrid& properties (); 28 | void forceWidth (); 29 | ViewToolPaneSelection selection () const; 30 | void setButtonState (ToolKey, bool); 31 | QString buttonText (ToolKey) const; 32 | 33 | private: 34 | IMPLEMENTATION 35 | }; 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /lib/src/view/tool-tip.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #include 6 | #include 7 | #include "../util.hpp" 8 | #include "view/tool-tip.hpp" 9 | 10 | struct ViewToolTip::Impl 11 | { 12 | typedef std::tuple Tip; 13 | std::vector tips; 14 | 15 | void render (const std::function& f) const 16 | { 17 | for (auto& t : this->tips) 18 | { 19 | f (ViewInput::toQString (std::get<0> (t), std::get<1> (t)), std::get<2> (t)); 20 | } 21 | } 22 | 23 | void add (ViewInputEvent event, ViewInputModifier modifier, const QString& tip) 24 | { 25 | this->tips.push_back (std::make_tuple (event, modifier, tip)); 26 | } 27 | 28 | void add (ViewInputEvent event, const QString& tip) 29 | { 30 | this->add (event, ViewInputModifier::None, tip); 31 | } 32 | 33 | void reset () { this->tips.clear (); } 34 | 35 | bool isEmpty () const { return this->tips.empty (); } 36 | }; 37 | 38 | DELEGATE_BIG6 (ViewToolTip) 39 | DELEGATE1_CONST (void, ViewToolTip, render, 40 | const std::function&) 41 | DELEGATE3 (void, ViewToolTip, add, ViewInputEvent, ViewInputModifier, const QString&) 42 | DELEGATE2 (void, ViewToolTip, add, ViewInputEvent, const QString&) 43 | DELEGATE (void, ViewToolTip, reset) 44 | DELEGATE_CONST (bool, ViewToolTip, isEmpty) 45 | -------------------------------------------------------------------------------- /lib/src/view/tool-tip.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_VIEW_TOOL_TIP 6 | #define DILAY_VIEW_TOOL_TIP 7 | 8 | #include 9 | #include "macro.hpp" 10 | #include "view/input.hpp" 11 | 12 | class ViewToolTip 13 | { 14 | public: 15 | DECLARE_BIG6 (ViewToolTip) 16 | 17 | void render (const std::function&) const; 18 | 19 | void add (ViewInputEvent, ViewInputModifier, const QString&); 20 | void add (ViewInputEvent, const QString&); 21 | void reset (); 22 | bool isEmpty () const; 23 | 24 | private: 25 | IMPLEMENTATION 26 | }; 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /lib/src/view/two-column-grid.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_VIEW_TWO_COLUMN_GRID 6 | #define DILAY_VIEW_TWO_COLUMN_GRID 7 | 8 | #include 9 | #include 10 | #include "macro.hpp" 11 | 12 | class QButtonGroup; 13 | class QString; 14 | 15 | class ViewTwoColumnGrid : public QWidget 16 | { 17 | public: 18 | DECLARE_BIG2 (ViewTwoColumnGrid, QWidget* = nullptr) 19 | 20 | unsigned int numRows () const; 21 | void setEqualColumnStretch (); 22 | 23 | void add (QWidget&); 24 | void add (const QString&, const QString&); 25 | void add (const QString&, QWidget&); 26 | void add (QWidget&, QWidget&); 27 | void add (QButtonGroup&); 28 | void addStacked (const QString&, QWidget&); 29 | void addStacked (const QString&, QButtonGroup&); 30 | void addLeft (const QString&); 31 | void addCenter (const QString&); 32 | void addStretcher (); 33 | void addSeparator (); 34 | void reset (); 35 | 36 | private: 37 | IMPLEMENTATION 38 | }; 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /lib/src/view/vector-edit.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #include 6 | #include 7 | #include "view/util.hpp" 8 | #include "view/vector-edit.hpp" 9 | 10 | struct ViewVectorEdit::Impl 11 | { 12 | ViewVectorEdit* self; 13 | glm::vec3 vectorData; 14 | QLineEdit* edit[3]; 15 | 16 | static const int numDecimals = 2; 17 | 18 | Impl (ViewVectorEdit* s, const glm::vec3& v) 19 | : self (s) 20 | , vectorData (v) 21 | { 22 | QVBoxLayout* layout = new QVBoxLayout; 23 | layout->setSpacing (0); 24 | layout->setContentsMargins (0, 11, 0, 11); 25 | this->self->setLayout (layout); 26 | 27 | for (int i = 0; i <= 2; i++) 28 | { 29 | this->edit[i] = &ViewUtil::lineEdit (v[i], Impl::numDecimals); 30 | 31 | ViewUtil::connectFloat (*this->edit[i], [this, i](float v) { 32 | this->vectorData[i] = v; 33 | emit this->self->vectorEdited (this->vectorData); 34 | }); 35 | 36 | layout->addWidget (this->edit[i]); 37 | } 38 | }; 39 | 40 | void vector (const glm::vec3& v) 41 | { 42 | this->x (v.x); 43 | this->y (v.y); 44 | this->z (v.z); 45 | } 46 | 47 | void x (float v) { this->changeComponent (0, v); } 48 | 49 | void y (float v) { this->changeComponent (1, v); } 50 | 51 | void z (float v) { this->changeComponent (2, v); } 52 | 53 | void changeComponent (int i, float v) 54 | { 55 | this->vectorData[i] = v; 56 | this->edit[i]->setText (QString::number (v, 'f', Impl::numDecimals)); 57 | } 58 | }; 59 | 60 | DELEGATE_BIG2_BASE (ViewVectorEdit, (const glm::vec3& v, QWidget* p), (this, v), QWidget, (p)) 61 | DELEGATE1 (void, ViewVectorEdit, vector, const glm::vec3&) 62 | DELEGATE1 (void, ViewVectorEdit, x, float) 63 | DELEGATE1 (void, ViewVectorEdit, y, float) 64 | DELEGATE1 (void, ViewVectorEdit, z, float) 65 | -------------------------------------------------------------------------------- /lib/src/view/vector-edit.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_VIEW_VECTOR_EDIT 6 | #define DILAY_VIEW_VECTOR_EDIT 7 | 8 | #include 9 | #include 10 | #include "macro.hpp" 11 | 12 | class ViewVectorEdit : public QWidget 13 | { 14 | Q_OBJECT 15 | public: 16 | DECLARE_BIG2 (ViewVectorEdit, const glm::vec3&, QWidget* = nullptr) 17 | 18 | void vector (const glm::vec3&); 19 | void x (float); 20 | void y (float); 21 | void z (float); 22 | 23 | signals: 24 | void vectorEdited (const glm::vec3&); 25 | 26 | private: 27 | IMPLEMENTATION 28 | }; 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /lib/src/xml-conversion.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_CONFIG_CONVERSION 6 | #define DILAY_CONFIG_CONVERSION 7 | 8 | #include 9 | 10 | class QDomDocument; 11 | class QDomElement; 12 | class Color; 13 | 14 | namespace XmlConversion 15 | { 16 | bool fromDomElement (QDomElement, float&); 17 | bool fromDomElement (QDomElement, int&); 18 | bool fromDomElement (QDomElement, bool&); 19 | bool fromDomElement (QDomElement, glm::vec3&); 20 | bool fromDomElement (QDomElement, glm::ivec2&); 21 | bool fromDomElement (QDomElement, Color&); 22 | 23 | QDomElement& toDomElement (QDomDocument&, QDomElement&, const float&); 24 | QDomElement& toDomElement (QDomDocument&, QDomElement&, const int&); 25 | QDomElement& toDomElement (QDomDocument&, QDomElement&, const bool&); 26 | QDomElement& toDomElement (QDomDocument&, QDomElement&, const glm::vec3&); 27 | QDomElement& toDomElement (QDomDocument&, QDomElement&, const glm::ivec2&); 28 | QDomElement& toDomElement (QDomDocument&, QDomElement&, const Color&); 29 | } 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /test/src/main.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #include 6 | #include 7 | #include "test-bitset.hpp" 8 | #include "test-distance.hpp" 9 | #include "test-intersection.hpp" 10 | #include "test-maybe.hpp" 11 | #include "test-misc.hpp" 12 | #include "test-octree.hpp" 13 | #include "test-prune.hpp" 14 | #include "test-tree.hpp" 15 | 16 | int main () 17 | { 18 | QCoreApplication::setApplicationName ("dilay"); 19 | 20 | TestIntersection::test1 (); 21 | TestIntersection::test2 (); 22 | TestMaybe::test1 (); 23 | TestMaybe::test2 (); 24 | TestMaybe::test3 (); 25 | TestOctree::test (); 26 | TestBitset::test (); 27 | TestTree::test1 (); 28 | TestTree::test2 (); 29 | TestTree::test3 (); 30 | TestMisc::test (); 31 | TestDistance::test (); 32 | TestPrune::test (); 33 | 34 | std::cout << "all tests ran successfully\n"; 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /test/src/test-bitset.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #include 6 | #include "bitset.hpp" 7 | #include "test-bitset.hpp" 8 | 9 | void TestBitset::test () 10 | { 11 | Bitset bs; 12 | 13 | assert (bs.get<0> () == false); 14 | assert (bs.get<8 * sizeof (unsigned int) - 1> () == false); 15 | 16 | bs.toggle<0> (); 17 | bs.toggle<8 * sizeof (unsigned int) - 1> (); 18 | // bs.toggle <8 * sizeof (unsigned int)> (); // must not compile 19 | 20 | assert (bs.get<0> ()); 21 | assert (bs.get<1> () == false); 22 | assert (bs.get<8 * sizeof (unsigned int) - 1> ()); 23 | assert (bs.value () == std::pow (2, 8 * sizeof (unsigned int) - 1) + 1); 24 | 25 | bs.reset (); 26 | assert (bs.none ()); 27 | 28 | bs.set<0> (); 29 | bs.set<1> (); 30 | bs.set<2> (); 31 | assert (bs.none () == false); 32 | assert (bs.all<2> ()); 33 | assert (bs.all<3> ()); 34 | assert (bs.all<4> () == false); 35 | assert (bs.value () == 7); 36 | } 37 | -------------------------------------------------------------------------------- /test/src/test-bitset.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_TEST_BITSET 6 | #define DILAY_TEST_BITSET 7 | 8 | namespace TestBitset 9 | { 10 | void test (); 11 | } 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /test/src/test-distance.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #include 6 | #include 7 | #include "distance.hpp" 8 | #include "primitive/cylinder.hpp" 9 | #include "test-distance.hpp" 10 | #include "util.hpp" 11 | 12 | void TestDistance::test () 13 | { 14 | using Distance::distance; 15 | 16 | const float eps = Util::epsilon (); 17 | 18 | PrimCylinder cyl (glm::vec3 (0.0f, 0.0f, 0.0f), glm::vec3 (1.0f, 0.0f, 0.0f), 0.5f); 19 | 20 | assert (glm::epsilonEqual (distance (cyl, glm::vec3 (0.5f, 1.3f, 0.0f)), 0.8f, eps)); 21 | 22 | assert (glm::epsilonEqual (distance (cyl, glm::vec3 (0.1f, 0.0f, 0.0f)), -0.1f, eps)); 23 | 24 | assert (glm::epsilonEqual (distance (cyl, glm::vec3 (0.9f, 0.0f, 0.0f)), -0.1f, eps)); 25 | 26 | assert (glm::epsilonEqual (distance (cyl, glm::vec3 (0.5f, 0.4f, 0.0f)), -0.1f, eps)); 27 | 28 | assert (glm::epsilonEqual (distance (cyl, glm::vec3 (-0.3f, 0.3f, 0.0f)), 0.3f, eps)); 29 | assert (glm::epsilonEqual (distance (cyl, glm::vec3 (1.7f, 0.3f, 0.0f)), 0.7f, eps)); 30 | assert (glm::epsilonEqual (distance (cyl, glm::vec3 (-2.0f, 2.0f, 0.0f)), 31 | glm::sqrt ((1.5f * 1.5f) + (2.0f * 2.0f)), eps)); 32 | assert (glm::epsilonEqual (distance (cyl, glm::vec3 (2.0f, 2.0f, 0.0f)), 33 | glm::sqrt ((1.5f * 1.5f) + (1.0f * 1.0f)), eps)); 34 | unused (eps); 35 | } 36 | -------------------------------------------------------------------------------- /test/src/test-distance.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_TEST_DISTANCE 6 | #define DILAY_TEST_DISTANCE 7 | 8 | namespace TestDistance 9 | { 10 | void test (); 11 | } 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /test/src/test-intersection.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_TEST_INTERSECTION 6 | #define DILAY_TEST_INTERSECTION 7 | 8 | namespace TestIntersection 9 | { 10 | void test1 (); 11 | void test2 (); 12 | } 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /test/src/test-maybe.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #include "maybe.hpp" 6 | #include "test-maybe.hpp" 7 | 8 | void TestMaybe::test1 () 9 | { 10 | Maybe m1 (5); 11 | 12 | assert (m1.hasValue ()); 13 | assert (*m1 == 5); 14 | 15 | Maybe m2 (m1); 16 | 17 | assert (*m1 == 5); 18 | assert (*m2 == 5); 19 | 20 | Maybe m3 (std::move (m1)); 21 | 22 | assert (m1.hasValue () == false); 23 | assert (*m3 == 5); 24 | 25 | m2 = 12; 26 | m3 = std::move (m2); 27 | 28 | assert (m2.hasValue () == false); 29 | assert (*m3 == 12); 30 | 31 | m3 = std::move (m2); 32 | 33 | assert (m3.hasValue () == false); 34 | 35 | m3 = 12; 36 | m3 = m2; 37 | 38 | assert (m3.hasValue () == false); 39 | 40 | m3 = 44; 41 | assert (*m3 == 44); 42 | 43 | int* i = new int(55); 44 | m3 = i; 45 | 46 | assert (*m3 == 55); 47 | 48 | m3 = nullptr; 49 | 50 | assert (m3.hasValue () == false); 51 | } 52 | 53 | namespace 54 | { 55 | class Foo 56 | { 57 | public: 58 | Foo (int d) 59 | : _data (d) 60 | { 61 | } 62 | 63 | int data () const { return this->_data; } 64 | 65 | private: 66 | int _data; 67 | }; 68 | } 69 | 70 | void TestMaybe::test2 () 71 | { 72 | Maybe m = Maybe::make (5); 73 | 74 | assert (m.hasValue ()); 75 | assert (m->data () == 5); 76 | } 77 | 78 | void TestMaybe::test3 () 79 | { 80 | Maybe m1 = 5; 81 | Maybe m2; 82 | 83 | assert (m1.hasValue ()); 84 | assert (m2.hasValue () == false); 85 | 86 | m2 = m1.release (); 87 | 88 | assert (m1.hasValue () == false); 89 | assert (m2.hasValue ()); 90 | assert (*m2 == 5); 91 | } 92 | -------------------------------------------------------------------------------- /test/src/test-maybe.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_TEST_MAYBE 6 | #define DILAY_TEST_MAYBE 7 | 8 | namespace TestMaybe 9 | { 10 | void test1 (); 11 | void test2 (); 12 | void test3 (); 13 | } 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /test/src/test-misc.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #include 6 | #include 7 | #include "test-misc.hpp" 8 | #include "util.hpp" 9 | 10 | void TestMisc::test () 11 | { 12 | assert (Util::countOnes (0) == 0); 13 | assert (Util::countOnes (1) == 1); 14 | assert (Util::countOnes (2) == 1); 15 | assert (Util::countOnes (3) == 2); 16 | assert (Util::countOnes (127) == 7); 17 | assert (Util::countOnes (128) == 1); 18 | assert (Util::countOnes (255) == 8); 19 | assert (Util::countOnes (256) == 1); 20 | 21 | assert (Util::countOnes (std::numeric_limits::max ()) == sizeof (unsigned int) * 8); 22 | } 23 | -------------------------------------------------------------------------------- /test/src/test-misc.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_TEST_MISC 6 | #define DILAY_TEST_MISC 7 | 8 | namespace TestMisc 9 | { 10 | void test (); 11 | } 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /test/src/test-octree.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include "dynamic/octree.hpp" 10 | #include "primitive/triangle.hpp" 11 | #include "test-octree.hpp" 12 | 13 | void TestOctree::test () 14 | { 15 | const unsigned int numSamples = 10000; 16 | 17 | DynamicOctree octree; 18 | octree.setupRoot (glm::vec3 (0.0f), 10.0f); 19 | 20 | std::default_random_engine gen; 21 | std::uniform_real_distribution unitD (0.0f, 1.0f); 22 | std::uniform_real_distribution posD (-10.0f, 10.0f); 23 | std::uniform_real_distribution scaleD (0.00001f, 10.0f); 24 | std::uniform_real_distribution twoPiD (0.0f, 2.0f * glm::pi ()); 25 | 26 | for (unsigned int i = 0; i < numSamples; i++) 27 | { 28 | const glm::vec3 m1 (-1.0f, 0.0f, 0.0f); 29 | const glm::vec3 m2 (1.0f, 0.0f, 0.0f); 30 | const glm::vec3 m3 (0.0f, -1.0f, 0.0f); 31 | 32 | const glm::mat4x4 translationMatrix = 33 | glm::translate (glm::mat4x4 (1.0f), glm::vec3 (posD (gen), posD (gen), posD (gen))); 34 | const glm::mat4x4 rotationMatrix = 35 | glm::rotate (glm::mat4x4 (1.0f), twoPiD (gen), 36 | glm::normalize (glm::vec3 (unitD (gen), unitD (gen), unitD (gen)))); 37 | 38 | const glm::mat4x4 scalingMatrix = 39 | glm::scale (glm::mat4x4 (1.0f), glm::vec3 (scaleD (gen), scaleD (gen), scaleD (gen))); 40 | 41 | const glm::mat4x4 modelMatrix = translationMatrix * rotationMatrix * scalingMatrix; 42 | 43 | const glm::vec3 w1 = glm::vec3 (modelMatrix * glm::vec4 (m1, 1.0f)); 44 | const glm::vec3 w2 = glm::vec3 (modelMatrix * glm::vec4 (m2, 1.0f)); 45 | const glm::vec3 w3 = glm::vec3 (modelMatrix * glm::vec4 (m3, 1.0f)); 46 | const PrimTriangle tri = PrimTriangle (w1, w2, w3); 47 | 48 | octree.addElement (i, tri.center (), tri.maxDimExtent ()); 49 | } 50 | for (unsigned int i = 0; i < numSamples; i++) 51 | { 52 | octree.deleteElement (i); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /test/src/test-octree.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_TEST_OCTREE 6 | #define DILAY_TEST_OCTREE 7 | 8 | namespace TestOctree 9 | { 10 | void test (); 11 | } 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /test/src/test-prune.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #include "test-prune.hpp" 6 | #include "util.hpp" 7 | 8 | namespace 9 | { 10 | bool equals (std::vector prune, const std::vector& vec, 11 | const std::vector& indices) 12 | { 13 | std::vector pruneIndices; 14 | 15 | Util::prune (prune, [](int i) { return i < 0; }, &pruneIndices); 16 | 17 | return std::equal (prune.begin (), prune.end (), vec.begin (), vec.end ()) && 18 | std::equal (pruneIndices.begin (), pruneIndices.end (), indices.begin (), 19 | indices.end ()); 20 | } 21 | } 22 | 23 | void TestPrune::test () 24 | { 25 | const unsigned int x = Util::invalidIndex (); 26 | 27 | assert ( 28 | equals ({1, 2, 3, 4, 5, 6, 7, 8, 9}, {1, 2, 3, 4, 5, 6, 7, 8, 9}, {0, 1, 2, 3, 4, 5, 6, 7, 8})); 29 | assert (equals ({-1, 2, -3, 4, -5, 6, -7, 8, -9}, {8, 2, 6, 4}, {x, 1, x, 3, x, 2, x, 0, x})); 30 | assert (equals ({-1, -2, -3, -4, -5, -6, -7, -8, -9}, {}, {x, x, x, x, x, x, x, x, x})); 31 | assert (equals ({-1, -2, -3, -4, -5, -6, -7, -8, 9}, {9}, {x, x, x, x, x, x, x, x, 0})); 32 | assert (equals ({1, -2, -3, -4, -5, -6, -7, -8, 9}, {1, 9}, {0, x, x, x, x, x, x, x, 1})); 33 | assert (equals ({-1, 2, -3, -4, -5, -6, -7, -8, 9}, {9, 2}, {x, 1, x, x, x, x, x, x, 0})); 34 | assert (equals ({-1, -2, -3, -4, -5, -6, 7, 8, 9}, {9, 8, 7}, {x, x, x, x, x, x, 2, 1, 0})); 35 | unused (x); 36 | unused (equals); 37 | } 38 | -------------------------------------------------------------------------------- /test/src/test-prune.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_TEST_PRUNE 6 | #define DILAY_TEST_PRUNE 7 | 8 | namespace TestPrune 9 | { 10 | void test (); 11 | } 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /test/src/test-tree.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #include 6 | #include "test-tree.hpp" 7 | #include "tree.hpp" 8 | 9 | namespace 10 | { 11 | struct Foo 12 | { 13 | int i; 14 | 15 | Foo (int v) 16 | : i (v) 17 | { 18 | } 19 | }; 20 | } 21 | 22 | void TestTree::test1 () 23 | { 24 | Tree tree; 25 | 26 | auto& n0 = tree.emplaceRoot (0); 27 | auto& n1 = n0.emplaceChild (100); 28 | auto& n2 = n1.emplaceChild (200); 29 | 30 | assert (n1.data ().i == 100); 31 | assert (n2.parent () == &n1); 32 | assert (tree.root ().numNodes () == 3); 33 | assert (n1.lastChild ().data ().i == n2.data ().i); 34 | 35 | n0.deleteChild (n1); 36 | assert (tree.root ().numNodes () == 1); 37 | 38 | n0.emplaceChild (5); 39 | n0.emplaceChild (6).emplaceChild (7); 40 | 41 | assert (tree.root ().numNodes () == 4); 42 | 43 | n0.deleteChildIf ([](const auto& c) { return c.data ().i == 6; }); 44 | 45 | assert (tree.root ().numNodes () == 2); 46 | assert (n0.lastChild ().data ().i == 5); 47 | 48 | Tree copy (tree); 49 | 50 | tree.reset (); 51 | 52 | assert (copy.root ().numNodes () == 2); 53 | assert (copy.root ().data ().i == 0); 54 | assert (copy.root ().lastChild ().data ().i == 5); 55 | assert (copy.root ().lastChild ().parent () == ©.root ()); 56 | unused (n2); 57 | } 58 | 59 | void TestTree::test2 () 60 | { 61 | Tree t; 62 | 63 | t.emplaceRoot (1).emplaceChild (2).emplaceChild (3).emplaceChild (4); 64 | 65 | assert (t.root ().numNodes () == 4); 66 | assert (t.root ().data () == 1); 67 | assert (t.root ().lastChild ().data () == 2); 68 | assert (t.root ().lastChild ().lastChild ().data () == 3); 69 | assert (t.root ().lastChild ().lastChild ().lastChild ().data () == 4); 70 | 71 | t.rebalance (t.root ().lastChild ().lastChild ().lastChild ()); 72 | 73 | assert (t.root ().numNodes () == 4); 74 | assert (t.root ().data () == 4); 75 | assert (t.root ().lastChild ().data () == 3); 76 | assert (t.root ().lastChild ().lastChild ().data () == 2); 77 | assert (t.root ().lastChild ().lastChild ().lastChild ().data () == 1); 78 | } 79 | 80 | void TestTree::test3 () 81 | { 82 | Tree t1; 83 | 84 | TreeNode& node1 = t1.emplaceRoot (1).emplaceChild (2).emplaceChild (3); 85 | node1.emplaceChild (4); 86 | 87 | Tree t2 = t1.split (node1); 88 | 89 | assert (t1.root ().numNodes () == 2); 90 | assert (t1.root ().data () == 1); 91 | assert (t1.root ().lastChild ().data () == 2); 92 | 93 | assert (t2.root ().numNodes () == 2); 94 | assert (t2.root ().data () == 3); 95 | assert (t2.root ().lastChild ().data () == 4); 96 | 97 | Tree t3 = t1.split (t1.root ()); 98 | 99 | assert (t1.hasRoot () == false); 100 | 101 | assert (t3.root ().numNodes () == 2); 102 | assert (t3.root ().data () == 1); 103 | assert (t3.root ().lastChild ().data () == 2); 104 | } 105 | -------------------------------------------------------------------------------- /test/src/test-tree.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of Dilay 2 | * Copyright © 2015-2018 Alexander Bau 3 | * Use and redistribute under the terms of the GNU General Public License 4 | */ 5 | #ifndef DILAY_TEST_TREE 6 | #define DILAY_TEST_TREE 7 | 8 | namespace TestTree 9 | { 10 | void test1 (); 11 | void test2 (); 12 | void test3 (); 13 | } 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /test/test.pro: -------------------------------------------------------------------------------- 1 | include (../common.pri) 2 | 3 | TEMPLATE = app 4 | TARGET = run-tests 5 | DESTDIR = $$OUT_PWD/.. 6 | DEPENDPATH += src 7 | INCLUDEPATH += src $$PWD/../lib/src 8 | 9 | SOURCES += \ 10 | src/main.cpp \ 11 | src/test-bitset.cpp \ 12 | src/test-distance.cpp \ 13 | src/test-intersection.cpp \ 14 | src/test-maybe.cpp \ 15 | src/test-misc.cpp \ 16 | src/test-octree.cpp \ 17 | src/test-prune.cpp \ 18 | src/test-tree.cpp 19 | 20 | HEADERS += \ 21 | src/test-bitset.hpp \ 22 | src/test-distance.hpp \ 23 | src/test-intersection.hpp \ 24 | src/test-maybe.hpp \ 25 | src/test-misc.hpp \ 26 | src/test-octree.hpp \ 27 | src/test-prune.hpp \ 28 | src/test-tree.hpp 29 | 30 | win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../lib/release/ -ldilay 31 | else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../lib/debug/ -ldilay 32 | else:unix: LIBS += -L$$OUT_PWD/../lib/ -ldilay 33 | 34 | win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../lib/release/libdilay.a 35 | else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../lib/debug/libdilay.a 36 | else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../lib/release/dilay.lib 37 | else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../lib/debug/dilay.lib 38 | else:unix: PRE_TARGETDEPS += $$OUT_PWD/../lib/libdilay.a 39 | 40 | unix { 41 | format.commands = clang-format -style=file -i $$SOURCES $$HEADERS 42 | QMAKE_EXTRA_TARGETS += format 43 | } 44 | -------------------------------------------------------------------------------- /unix/dilay.desktop: -------------------------------------------------------------------------------- 1 | [Desktop Entry] 2 | Type=Application 3 | Version=1.0 4 | Name=Dilay 5 | Comment=A 3D sculpting application 6 | Exec=dilay 7 | Icon=dilay 8 | Terminal=false 9 | Categories=Graphics;3DGraphics; 10 | -------------------------------------------------------------------------------- /unix/docker/appimage/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:trusty 2 | 3 | RUN apt-get update 4 | RUN apt-get install -y software-properties-common 5 | 6 | RUN add-apt-repository -y ppa:ubuntu-toolchain-r/test 7 | RUN add-apt-repository -y ppa:beineri/opt-qt592-trusty 8 | RUN apt-get update 9 | 10 | RUN apt-get install -y build-essential git qt59base libglm-dev g++-5 libgl1-mesa-dev wget 11 | 12 | RUN update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-5 20 13 | 14 | COPY entrypoint.sh /usr/bin/ 15 | 16 | ENTRYPOINT entrypoint.sh 17 | -------------------------------------------------------------------------------- /unix/docker/appimage/entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | cd /tmp 4 | git clone --depth=1 file:///dilay 5 | 6 | cd /tmp/dilay 7 | source /opt/qt*/bin/qt*-env.sh 8 | qmake -r PREFIX=/usr 9 | make release -j$(nproc) 10 | make INSTALL_ROOT=appdir install 11 | 12 | wget -c -q "https://github.com/probonopd/linuxdeployqt/releases/download/continuous/linuxdeployqt-continuous-x86_64.AppImage" 13 | unset QTDIR 14 | unset QT_PLUGIN_PATH 15 | unset LD_LIBRARY_PATH 16 | export VERSION=$(git describe --dirty --tags) # linuxdeployqt uses this for naming the file 17 | chmod a+x linuxdeployqt*.AppImage 18 | ./linuxdeployqt*.AppImage --appimage-extract 19 | ./squashfs-root/AppRun ./app/appdir/usr/share/applications/*.desktop -bundle-non-qt-libs 20 | ./squashfs-root/AppRun ./app/appdir/usr/share/applications/*.desktop -appimage 21 | mv Dilay*.AppImage /dilay 22 | -------------------------------------------------------------------------------- /unix/docker/debian-sid/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM debian:sid 2 | 3 | RUN apt-get update 4 | RUN apt-get install -y build-essential git qt5-default qt5-qmake libglm-dev 5 | 6 | COPY entrypoint.sh /usr/bin/ 7 | 8 | ENTRYPOINT entrypoint.sh 9 | -------------------------------------------------------------------------------- /unix/docker/debian-sid/entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | cd /tmp 4 | git clone --depth=1 file:///dilay 5 | 6 | cd /tmp/dilay 7 | qmake -r 8 | make release -j$(nproc) 9 | -------------------------------------------------------------------------------- /unix/docker/ubuntu-bionic/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:bionic 2 | 3 | RUN apt-get update 4 | RUN apt-get install -y build-essential git qt5-default qt5-qmake libglm-dev 5 | 6 | COPY entrypoint.sh /usr/bin/ 7 | 8 | ENTRYPOINT entrypoint.sh 9 | -------------------------------------------------------------------------------- /unix/docker/ubuntu-bionic/entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | cd /tmp 4 | git clone --depth=1 file:///dilay 5 | 6 | cd /tmp/dilay 7 | qmake -r 8 | make release -j$(nproc) 9 | -------------------------------------------------------------------------------- /unix/docker/ubuntu-trusty/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:trusty 2 | 3 | RUN apt-get update 4 | RUN apt-get install -y software-properties-common 5 | 6 | RUN add-apt-repository -y ppa:ubuntu-toolchain-r/test 7 | RUN add-apt-repository -y ppa:beineri/opt-qt592-trusty 8 | RUN apt-get update 9 | 10 | RUN apt-get install -y build-essential git qt59base libglm-dev g++-5 libgl1-mesa-dev 11 | 12 | RUN update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-5 20 13 | 14 | COPY entrypoint.sh /usr/bin/ 15 | 16 | ENTRYPOINT entrypoint.sh 17 | -------------------------------------------------------------------------------- /unix/docker/ubuntu-trusty/entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | cd /tmp 4 | git clone --depth=1 file:///dilay 5 | 6 | cd /tmp/dilay 7 | source /opt/qt*/bin/qt*-env.sh 8 | qmake -r 9 | make release -j$(nproc) 10 | -------------------------------------------------------------------------------- /unix/docker/ubuntu-xenial/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:xenial 2 | 3 | RUN apt-get update 4 | RUN apt-get install -y software-properties-common 5 | 6 | RUN add-apt-repository -y ppa:beineri/opt-qt592-xenial 7 | RUN apt-get update 8 | 9 | RUN apt-get update 10 | RUN apt-get install -y build-essential git qt59base libglm-dev libgl1-mesa-dev 11 | 12 | COPY entrypoint.sh /usr/bin/ 13 | 14 | ENTRYPOINT entrypoint.sh 15 | -------------------------------------------------------------------------------- /unix/docker/ubuntu-xenial/entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | cd /tmp 4 | git clone --depth=1 file:///dilay 5 | 6 | cd /tmp/dilay 7 | source /opt/qt*/bin/qt*-env.sh 8 | qmake -r 9 | make release -j$(nproc) 10 | -------------------------------------------------------------------------------- /unix/icon/16x16/dilay.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abau/dilay/50038bf3431ff63007b3544fe661151aa2937f07/unix/icon/16x16/dilay.png -------------------------------------------------------------------------------- /unix/icon/256x256/dilay.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abau/dilay/50038bf3431ff63007b3544fe661151aa2937f07/unix/icon/256x256/dilay.png -------------------------------------------------------------------------------- /unix/icon/32x32/dilay.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abau/dilay/50038bf3431ff63007b3544fe661151aa2937f07/unix/icon/32x32/dilay.png -------------------------------------------------------------------------------- /unix/icon/48x48/dilay.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abau/dilay/50038bf3431ff63007b3544fe661151aa2937f07/unix/icon/48x48/dilay.png -------------------------------------------------------------------------------- /win32/deploy.bat: -------------------------------------------------------------------------------- 1 | REM Qt's install directory: %1 2 | REM compilation's target directory: %2 3 | REM Dilay's source directory: %3 4 | REM Dilay's version: %4 5 | @echo off 6 | 7 | if exist win32deploy ( rmdir /s /q win32deploy ) 8 | 9 | mkdir win32deploy 10 | mkdir win32deploy\Dilay 11 | 12 | xcopy %2\dilay.exe win32deploy\Dilay 13 | xcopy %1\bin\libgcc_s_dw2-1.dll win32deploy\Dilay 14 | xcopy %1\bin\libstdc++-6.dll win32deploy\Dilay 15 | xcopy %1\bin\libwinpthread-1.dll win32deploy\Dilay 16 | xcopy %1\bin\Qt5Core.dll win32deploy\Dilay 17 | xcopy %1\bin\Qt5Gui.dll win32deploy\Dilay 18 | xcopy %1\bin\Qt5Widgets.dll win32deploy\Dilay 19 | xcopy %1\bin\Qt5Xml.dll win32deploy\Dilay 20 | xcopy %3\win32\icon.ico win32deploy\Dilay 21 | xcopy %3\win32\LICENSE.rtf win32deploy\Dilay 22 | 23 | mkdir win32deploy\Dilay\platforms 24 | 25 | xcopy %1\plugins\platforms\qwindows.dll win32deploy\Dilay\platforms 26 | 27 | "%ProgramFiles(x86)%\WiX Toolset v3.11\bin\candle.exe" -dDilayVersion=%4 -out win32deploy/dilay.wixobj %3\win32\installer.wix 28 | "%ProgramFiles(x86)%\WiX Toolset v3.11\bin\light.exe" -ext WixUIExtension -b win32deploy -cultures:en-US -out win32deploy/dilay-%4.msi win32deploy/dilay.wixobj 29 | -------------------------------------------------------------------------------- /win32/icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abau/dilay/50038bf3431ff63007b3544fe661151aa2937f07/win32/icon.ico --------------------------------------------------------------------------------