diff --git a/.browserslistrc b/.browserslistrc
deleted file mode 100644
index d6471a38..00000000
--- a/.browserslistrc
+++ /dev/null
@@ -1,2 +0,0 @@
-> 1%
-last 2 versions
diff --git a/.clang-format b/.clang-format
new file mode 100644
index 00000000..05082f85
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,8 @@
+# https://github.com/microsoft/vscode-cpptools/issues/932
+NamespaceIndentation: None
+IndentWidth: 4
+AccessModifierOffset: -4
+PointerAlignment: Left
+
+# https://stackoverflow.com/questions/29477654/how-to-make-clang-format-add-new-line-before-opening-brace-of-a-function
+BreakBeforeBraces: Stroustrup
diff --git a/.eslintrc.js b/.eslintrc.js
deleted file mode 100644
index 761b3cdb..00000000
--- a/.eslintrc.js
+++ /dev/null
@@ -1,24 +0,0 @@
-module.exports = {
- root: true,
- env: {
- node: true
- },
- extends: [
- "plugin:vue/essential",
- "eslint:recommended",
- "@vue/prettier",
- "@vue/typescript"
- ],
- rules: {
- // "no-console": process.env.NODE_ENV === "production" ? "error" : "off",
- // "no-debugger": process.env.NODE_ENV === "production" ? "error" : "off",
- "no-console": "off",
- "no-debugger": "off",
- indent: "off",
- allowIndentationTabs: true
- },
- parserOptions: {
- parser: "@typescript-eslint/parser",
- ecmaVersion: 6
- }
-};
diff --git a/.gitignore b/.gitignore
index 025b65c7..6c8746dc 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,25 +1,13 @@
-.DS_Store
-node_modules
-/dist
-
-# local env files
-.env.local
-.env.*.local
-
-# Log files
-npm-debug.log*
-yarn-debug.log*
-yarn-error.log*
-
-# Editor directories and files
-.idea
-.vscode
-*.suo
-*.ntvs*
-*.njsproj
-*.sln
-*.sw?
-
-#Electron-builder output
-/dist_electron
-/build/icons
\ No newline at end of file
+CMakeLists.txt.user
+CMakeCache.txt
+CMakeFiles
+CMakeScripts
+Testing
+Makefile
+cmake_install.cmake
+install_manifest.txt
+compile_commands.json
+CTestTestfile.cmake
+_deps
+
+build/
\ No newline at end of file
diff --git a/.gitmodules b/.gitmodules
index ee94bc5e..eb6f2ac9 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -1,3 +1,6 @@
[submodule "public/assets"]
path = public/assets
url = https://github.com/njbrown/texturelabdata.git
+[submodule "src/ads"]
+ path = src/ads
+ url = https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git
diff --git a/.prettierrc b/.prettierrc
deleted file mode 100644
index c9590876..00000000
--- a/.prettierrc
+++ /dev/null
@@ -1,3 +0,0 @@
-{
- "useTabs": true
-}
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 00000000..9746409c
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,20 @@
+cmake_minimum_required(VERSION 3.5)
+
+project(qtcompleteapp VERSION 0.1 LANGUAGES CXX)
+
+# Advanced Docking System
+add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/ads)
+set_target_properties(qtadvanceddocking PROPERTIES BUILD_STATIC TRUE)
+
+# Node Graph
+add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/nodegraph)
+
+# 3D Viewer
+add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/viewer3d)
+
+# 3D Viewer
+add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/colorpicker)
+
+# Main App
+add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/texturelab)
+
diff --git a/README.md b/README.md
index 608398aa..c2dd7fb3 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,3 @@
-
-
TextureLab
@@ -17,22 +15,27 @@

# NOTE!
+
Texturelab will soon be converted to a qt project. All issues will be addressed after the conversion is complete.
## Building
-Building is done with `yarn`. Install it [here](https://classic.yarnpkg.com/en/docs/install) if you havent already.
+Prerequisites
```
-git clone https://github.com/njbrown/texturelab.git
+install qt
-cd texturelab
+//apt-get install libmesa-dev
+sudo apt install libgl1-mesa-dev
-# if you want to pull down assets (textures and node icons)
-git submodule update --init
+```
+
+Building is done with `yarn`. Install it [here](https://classic.yarnpkg.com/en/docs/install) if you havent already.
-yarn install
-yarn electron:serve
+```
+git clone https://github.com/njbrown/texturelab.git
+cd texturelab
+git submodule update --init --recursive
```
## Feedback
diff --git a/babel.config.js b/babel.config.js
deleted file mode 100644
index f57da986..00000000
--- a/babel.config.js
+++ /dev/null
@@ -1,3 +0,0 @@
-module.exports = {
- presets: ["@vue/app"]
-};
diff --git a/jest.config.js b/jest.config.js
deleted file mode 100644
index a31425cf..00000000
--- a/jest.config.js
+++ /dev/null
@@ -1,27 +0,0 @@
-module.exports = {
- moduleFileExtensions: ["js", "jsx", "json", "vue", "ts", "tsx"],
- transform: {
- "^.+\\.vue$": "vue-jest",
- ".+\\.(css|styl|less|sass|scss|svg|png|jpg|ttf|woff|woff2)$":
- "jest-transform-stub",
- "^.+\\.tsx?$": "ts-jest"
- },
- transformIgnorePatterns: ["/node_modules/"],
- moduleNameMapper: {
- "^@/(.*)$": "/src/$1"
- },
- snapshotSerializers: ["jest-serializer-vue"],
- testMatch: [
- "**/tests/unit/**/*.spec.(js|jsx|ts|tsx)|**/__tests__/*.(js|jsx|ts|tsx)"
- ],
- testURL: "http://localhost/",
- watchPlugins: [
- "jest-watch-typeahead/filename",
- "jest-watch-typeahead/testname"
- ],
- globals: {
- "ts-jest": {
- babelConfig: true
- }
- }
-};
diff --git a/package.json b/package.json
deleted file mode 100644
index b954adc2..00000000
--- a/package.json
+++ /dev/null
@@ -1,80 +0,0 @@
-{
- "name": "texturelab",
- "version": "0.3.4",
- "displayVersion": "0.3.4",
- "private": false,
- "scripts": {
- "serve": "vue-cli-service serve",
- "build": "vue-cli-service build",
- "lint": "vue-cli-service lint",
- "preelectron:build": "yarn buildicons",
- "electron:build": "vue-cli-service electron:build",
- "electron:serve": "vue-cli-service electron:serve",
- "start": "vue-cli-service electron:serve",
- "postinstall": "electron-builder install-app-deps",
- "postuninstall": "electron-builder install-app-deps",
- "test:unit": "vue-cli-service test:unit",
- "buildicons": "electron-icon-builder --input=./public/icon.png --output ./build"
- },
- "main": "background.js",
- "dependencies": {
- "@electron/remote": "^1.2.0",
- "@petamoriken/float16": "^3.4.7",
- "@sentry/electron": "^3.0.0",
- "@types/adm-zip": "^0.4.34",
- "@types/node": "^16.9.2",
- "@types/pngjs": "^6.0.1",
- "@types/sharp": "^0.29.2",
- "adm-zip": "^0.4.16",
- "boxicons": "^2.0.5",
- "core-js": "^2.6.5",
- "custom-electron-titlebar": "^3.1.0",
- "dedent-js": "^1.0.1",
- "electron-settings": "^4.0.2",
- "element-resize-detector": "^1.1.15",
- "fast-png": "^5.0.4",
- "jquery": "^3.5.0",
- "pngjs": "^6.0.0",
- "sharp": "^0.29.1",
- "three": "^0.118.3",
- "three-orbitcontrols-ts": "git+https://git@github.com/nicolaspanel/three-orbitcontrols-ts.git",
- "typeface-open-sans": "^0.0.75",
- "upng-js": "^2.1.0",
- "vue": "^2.6.10",
- "vue-class-component": "^7.0.2",
- "vue-color": "^2.7.1",
- "vue-final-modal": "^2.4.1",
- "vue-golden-layout": "^1.6.0",
- "vue-property-decorator": "^8.1.0",
- "vue-router": "^3.0.3",
- "vue-toast-notification": "^0.6.2",
- "vuex": "^3.0.1"
- },
- "devDependencies": {
- "@sentry/webpack-plugin": "^1.16.0",
- "@types/jest": "^23.1.4",
- "@types/jquery": "^3.3.30",
- "@types/three": "^0.103.2",
- "@typescript-eslint/eslint-plugin": "^2.33.0",
- "@typescript-eslint/parser": "^2.33.0",
- "@vue/cli-plugin-babel": "^3.8.0",
- "@vue/cli-plugin-eslint": "^3.8.0",
- "@vue/cli-plugin-typescript": "^3.8.0",
- "@vue/cli-plugin-unit-jest": "^3.8.0",
- "@vue/cli-service": "^3.8.0",
- "@vue/eslint-config-prettier": "^4.0.1",
- "@vue/eslint-config-typescript": "^4.0.0",
- "@vue/test-utils": "1.0.0-beta.29",
- "babel-core": "7.0.0-bridge.0",
- "babel-eslint": "^10.0.1",
- "electron": "^13.0.0",
- "electron-devtools-installer": "^3.2.0",
- "electron-icon-builder": "^2.0.1",
- "eslint": "^5.16.0",
- "eslint-plugin-vue": "^5.0.0",
- "ts-jest": "^23.0.0",
- "typescript": "^3.9.5",
- "vue-cli-plugin-electron-builder": "^1.4.0",
- "vue-template-compiler": "^2.6.10"
- }
-}
diff --git a/postcss.config.js b/postcss.config.js
deleted file mode 100644
index 30803047..00000000
--- a/postcss.config.js
+++ /dev/null
@@ -1,5 +0,0 @@
-module.exports = {
- plugins: {
- autoprefixer: {}
- }
-};
diff --git a/public/assets b/public/assets
index eed449f3..5996a27d 160000
--- a/public/assets
+++ b/public/assets
@@ -1 +1 @@
-Subproject commit eed449f3f9abe8f17ae354ab4cb9932272c7811b
+Subproject commit 5996a27d943382fabeafb18217f9de212c62d420
diff --git a/public/css/scrollbar.css b/public/css/scrollbar.css
deleted file mode 100644
index 9d3e8573..00000000
--- a/public/css/scrollbar.css
+++ /dev/null
@@ -1,33 +0,0 @@
-::-webkit-scrollbar {
- width: 6px;
- height: 6px;
-}
-::-webkit-scrollbar-button {
- width: 0px;
- height: 0px;
-}
-::-webkit-scrollbar-thumb {
- background: #e1e1e1;
- border: 0px none #ffffff;
- border-radius: 50px;
-}
-::-webkit-scrollbar-thumb:hover {
- background: #ffffff;
-}
-::-webkit-scrollbar-thumb:active {
- background: #a7a7a7;
-}
-::-webkit-scrollbar-track {
- background: #666666;
- border: 0px none #ffffff;
- border-radius: 50px;
-}
-::-webkit-scrollbar-track:hover {
- background: #666666;
-}
-::-webkit-scrollbar-track:active {
- background: #333333;
-}
-::-webkit-scrollbar-corner {
- background: transparent;
-}
diff --git a/public/icon.png b/public/icon.png
deleted file mode 100644
index 68017cde..00000000
Binary files a/public/icon.png and /dev/null differ
diff --git a/public/index.html b/public/index.html
deleted file mode 100644
index 2df7731a..00000000
--- a/public/index.html
+++ /dev/null
@@ -1,26 +0,0 @@
-
-
-
-
-
-
-
- TextureLab v0.3.4
-
-
-
-
-
-
-
-
diff --git a/src/App.vue b/src/App.vue
deleted file mode 100644
index 610f8f88..00000000
--- a/src/App.vue
+++ /dev/null
@@ -1,1429 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/ads b/src/ads
new file mode 160000
index 00000000..efd88565
--- /dev/null
+++ b/src/ads
@@ -0,0 +1 @@
+Subproject commit efd88565a9db513054a1795dd6bf756fc95989c3
diff --git a/src/assets/logo.png b/src/assets/logo.png
deleted file mode 100644
index f3d2503f..00000000
Binary files a/src/assets/logo.png and /dev/null differ
diff --git a/src/background.ts b/src/background.ts
deleted file mode 100644
index 49777279..00000000
--- a/src/background.ts
+++ /dev/null
@@ -1,127 +0,0 @@
-"use strict";
-
-import { app, protocol, BrowserWindow, ipcMain } from "electron";
-import { createProtocol } from "vue-cli-plugin-electron-builder/lib";
-import installExtension, { VUEJS_DEVTOOLS } from "electron-devtools-installer";
-import { setupMenu } from "./menu";
-import * as Sentry from "@sentry/electron";
-
-// todo: fix later
-// https://docs.sentry.io/platforms/javascript/guides/electron/
-// if (process.env.VUE_APP_SENTRY_DNS) {
-// Sentry.init({ dsn: process.env.VUE_APP_SENTRY_DNS });
-// }
-
-// seems as tho this needs to be called else the app breaks
-require("@electron/remote/main").initialize();
-
-const isDevelopment = process.env.NODE_ENV !== "production";
-
-app.commandLine.appendSwitch("--disable-seccomp-filter-sandbox");
-
-// Keep a global reference of the window object, if you don't, the window will
-// be closed automatically when the JavaScript object is garbage collected.
-let win: BrowserWindow | null;
-
-// Scheme must be registered before the app is ready
-protocol.registerSchemesAsPrivileged([
- { scheme: "app", privileges: { secure: true, standard: true } }
-]);
-console.log("registered schemes");
-
-function createWindow() {
- // Create the browser window.
- win = new BrowserWindow({
- width: 1280,
- height: 720,
- frame: false,
- webPreferences: {
- nodeIntegration: true,
- webSecurity: false,
- contextIsolation: false,
- enableRemoteModule: true
- }
- });
- win.maximize();
-
- setupMenu();
-
- if (process.env.WEBPACK_DEV_SERVER_URL) {
- // Load the url of the dev server if in development mode
- win.loadURL(process.env.WEBPACK_DEV_SERVER_URL as string);
- //if (!process.env.IS_TEST) win.webContents.openDevTools();
- } else {
- createProtocol("app");
- // Load the index.html when not in development
- console.log("loading page");
- win.loadURL("app://./index.html");
- }
-
- win.on("closed", () => {
- win = null;
- });
-}
-
-// Quit when all windows are closed.
-app.on("window-all-closed", () => {
- // On macOS it is common for applications and their menu bar
- // to stay active until the user quits explicitly with Cmd + Q
- if (process.platform !== "darwin") {
- app.quit();
- }
-});
-
-app.on("activate", () => {
- // On macOS it's common to re-create a window in the app when the
- // dock icon is clicked and there are no other windows open.
- if (win === null) {
- createWindow();
- }
-});
-
-// This method will be called when Electron has finished
-// initialization and is ready to create browser windows.
-// Some APIs can only be used after this event occurs.
-app.on("ready", async () => {
- if (isDevelopment && !process.env.IS_TEST) {
- // Install Vue Devtools
- try {
- await installExtension({
- id: "ljjemllljcmogpfapbkkighbhhppjdbg", //Vue Devtools beta
- electron: ">=1.2.1"
- });
- } catch (e) {
- console.error("Vue Devtools failed to install:", e.toString());
- }
- }
-
- // needed for image files to work
- // https://github.com/electron/electron/issues/23393
- protocol.registerFileProtocol("image", (request, callback) => {
- const url = request.url.replace("image://", "");
-
- try {
- return callback(url);
- } catch (error) {
- console.error(error);
- return callback("");
- }
- });
-
- createWindow();
-});
-
-// Exit cleanly on request from parent process in development mode.
-if (isDevelopment) {
- if (process.platform === "win32") {
- process.on("message", data => {
- if (data === "graceful-exit") {
- app.quit();
- }
- });
- } else {
- process.on("SIGTERM", () => {
- app.quit();
- });
- }
-}
diff --git a/src/colorpicker/CMakeLists.txt b/src/colorpicker/CMakeLists.txt
new file mode 100644
index 00000000..3dd90319
--- /dev/null
+++ b/src/colorpicker/CMakeLists.txt
@@ -0,0 +1,82 @@
+
+cmake_minimum_required(VERSION 3.5)
+
+
+find_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED)
+find_package(Qt${QT_VERSION_MAJOR} 5.5 COMPONENTS Core Gui Widgets REQUIRED)
+if (UNIX AND NOT APPLE)
+ include_directories(${Qt${QT_VERSION_MAJOR}Gui_PRIVATE_INCLUDE_DIRS})
+endif()
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SRCS
+ colorpicker.cpp
+ gradient.cpp
+ gradientpicker.cpp
+ widgets.cpp
+)
+set(HEADERS
+ colorpicker.h
+ gradient.h
+ gradientpicker.h
+ widgets.h
+)
+
+# library
+add_library(colorpicker STATIC ${SRCS} ${HEADERS})
+target_link_libraries(colorpicker PRIVATE Qt${QT_VERSION_MAJOR}::Core
+ Qt${QT_VERSION_MAJOR}::Gui
+ Qt${QT_VERSION_MAJOR}::Widgets)
+
+
+set_target_properties(colorpicker PROPERTIES
+ AUTOMOC ON
+ AUTORCC ON
+ CXX_EXTENSIONS OFF
+ EXPORT_NAME "Color Picker"
+ ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
+ LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
+ RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
+)
+
+if(QT_VERSION_MAJOR STREQUAL "5")
+ set_target_properties(colorpicker PROPERTIES
+ CXX_STANDARD 14
+ CXX_STANDARD_REQUIRED ON)
+elseif(QT_VERSION_MAJOR STREQUAL "6")
+ set_target_properties(colorpicker PROPERTIES
+ CXX_STANDARD 17
+ CXX_STANDARD_REQUIRED ON)
+endif()
+
+# EXE for testing purposes
+add_executable(colorpicker_app
+ ${HEADERS}
+ ${SRCS}
+ main.cpp
+ )
+target_link_libraries(colorpicker_app PRIVATE Qt${QT_VERSION_MAJOR}::Core
+ Qt${QT_VERSION_MAJOR}::Gui
+ Qt${QT_VERSION_MAJOR}::Widgets)
+
+
+set_target_properties(colorpicker_app PROPERTIES
+ AUTOMOC ON
+ AUTORCC ON
+ CXX_EXTENSIONS OFF
+ EXPORT_NAME "Viewer Sample App"
+ ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
+ LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
+ RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
+)
+
+if(QT_VERSION_MAJOR STREQUAL "5")
+ set_target_properties(colorpicker_app PROPERTIES
+ CXX_STANDARD 14
+ CXX_STANDARD_REQUIRED ON)
+elseif(QT_VERSION_MAJOR STREQUAL "6")
+ set_target_properties(colorpicker_app PROPERTIES
+ CXX_STANDARD 17
+ CXX_STANDARD_REQUIRED ON)
+endif()
\ No newline at end of file
diff --git a/src/colorpicker/colorpicker.cpp b/src/colorpicker/colorpicker.cpp
new file mode 100644
index 00000000..277866be
--- /dev/null
+++ b/src/colorpicker/colorpicker.cpp
@@ -0,0 +1,36 @@
+#include "colorpicker.h"
+#include "./widgets.h"
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+ColorPicker::ColorPicker()
+{
+ svBox = new SVBox();
+ hueSlider = new HueSlider();
+ // alphaSlider = new AlphaSlider();
+
+ svBox->setColor(QColor(255, 150, 0, 255));
+
+ // add layout
+ auto vlayout = new QVBoxLayout(this);
+ vlayout->addWidget(svBox);
+ vlayout->addWidget(hueSlider);
+ // vlayout->addWidget(alphaSlider);
+
+ this->setLayout(vlayout);
+
+ // this->setBaseSize(400, 500);
+ this->resize(400, 330);
+}
+
+void ColorPicker::setColor(const QColor& color)
+{
+ svBox->setColor(color);
+ hueSlider->setColor(color);
+ // alphaSlider->setColor(color);
+}
\ No newline at end of file
diff --git a/src/colorpicker/colorpicker.h b/src/colorpicker/colorpicker.h
new file mode 100644
index 00000000..14252b05
--- /dev/null
+++ b/src/colorpicker/colorpicker.h
@@ -0,0 +1,26 @@
+#pragma once
+#include
+
+class SVBox;
+class HueSlider;
+class AlphaSlider;
+
+class ColorPicker : public QDialog {
+public:
+ ColorPicker();
+
+ void setColor(const QColor& color);
+
+signals:
+ void onColorChanged(const QColor& color);
+ void onClosed();
+
+private:
+ void initUI();
+ void colorChangedByEditor(QColor color);
+ void colorChangedByUI(QColor color);
+
+ SVBox* svBox;
+ HueSlider* hueSlider;
+ AlphaSlider* alphaSlider;
+};
\ No newline at end of file
diff --git a/src/colorpicker/gradient.cpp b/src/colorpicker/gradient.cpp
new file mode 100644
index 00000000..ab45f1af
--- /dev/null
+++ b/src/colorpicker/gradient.cpp
@@ -0,0 +1,17 @@
+#include "gradient.h"
+
+void Gradient::sort()
+{
+ std::sort(points.begin(), points.end(),
+ [](const GradientPoint& a, const GradientPoint& b) {
+ return a.position < b.position;
+ });
+}
+
+Gradient Gradient::defaultGradient()
+{
+ Gradient gradient;
+ gradient.addPoint(GradientPoint(0.0, QColor(0, 0, 0)));
+ gradient.addPoint(GradientPoint(1.0, QColor(255, 255, 255)));
+ return gradient;
+}
\ No newline at end of file
diff --git a/src/colorpicker/gradient.h b/src/colorpicker/gradient.h
new file mode 100644
index 00000000..45a0acf8
--- /dev/null
+++ b/src/colorpicker/gradient.h
@@ -0,0 +1,29 @@
+#pragma once
+
+#include
+#include
+
+class GradientPoint {
+public:
+ float position;
+ QColor color;
+
+ GradientPoint(float position, const QColor& color)
+ : position(position), color(color)
+ {
+ }
+};
+
+class Gradient {
+public:
+ QVector points;
+
+ Gradient() {}
+ Gradient(const QVector& points) : points(points) {}
+ Gradient(const Gradient& other) : points(other.points) {}
+
+ void addPoint(GradientPoint point) { points.append(point); }
+ void sort();
+
+ static Gradient defaultGradient();
+};
\ No newline at end of file
diff --git a/src/colorpicker/gradientpicker.cpp b/src/colorpicker/gradientpicker.cpp
new file mode 100644
index 00000000..2e992588
--- /dev/null
+++ b/src/colorpicker/gradientpicker.cpp
@@ -0,0 +1,29 @@
+#include "gradientpicker.h"
+#include "gradient.h"
+
+GradientSlider::GradientSlider() { this->initUI(); }
+
+void GradientSlider::setGradient(const Gradient& gradient)
+{
+ this->gradient = gradient;
+ this->update();
+}
+
+void GradientSlider::initUI() { this->setFixedSize(400, 100); }
+
+GradientPickerDialog::GradientPickerDialog() { this->initUI(); }
+
+void GradientPickerDialog::setGradient(const Gradient& gradient)
+{
+ // this->gradient = gradient;
+ this->gradientSlider->setGradient(gradient);
+
+ // update ui
+ // this->update();
+}
+
+void GradientPickerDialog::initUI()
+{
+ // create ui
+ // this->setFixedSize(400, 100);
+}
\ No newline at end of file
diff --git a/src/colorpicker/gradientpicker.h b/src/colorpicker/gradientpicker.h
new file mode 100644
index 00000000..5e2fe2a6
--- /dev/null
+++ b/src/colorpicker/gradientpicker.h
@@ -0,0 +1,38 @@
+#pragma once
+#include "gradient.h"
+#include
+#include
+
+// class QWidget;
+
+class GradientSlider : QWidget {
+ Gradient gradient;
+
+public:
+ GradientSlider();
+ void setGradient(const Gradient& gradient);
+ // void setPointColor(int index, const QColor& color);
+ // sets color of selected point
+ void setPointColor(const QColor& color);
+
+private:
+ void initUI();
+
+signals:
+ void onGradientChanged(const Gradient& gradient);
+
+ // only the color is really used
+ void onActivePointChanged(int index, const QColor& color);
+};
+
+class GradientPickerDialog : QDialog {
+ // Gradient gradient;
+ GradientSlider* gradientSlider = nullptr;
+
+public:
+ GradientPickerDialog();
+ void setGradient(const Gradient& gradient);
+
+private:
+ void initUI();
+};
\ No newline at end of file
diff --git a/src/colorpicker/main.cpp b/src/colorpicker/main.cpp
new file mode 100644
index 00000000..b4d330a7
--- /dev/null
+++ b/src/colorpicker/main.cpp
@@ -0,0 +1,14 @@
+#include "colorpicker.h"
+#include
+
+int main(int argc, char* argv[])
+{
+ QApplication a(argc, argv);
+ ColorPicker dialog;
+
+ // dialog.resize(800, 600);
+ dialog.setColor(QColor(50, 125, 125));
+ dialog.show();
+
+ return a.exec();
+}
diff --git a/src/colorpicker/widgets.cpp b/src/colorpicker/widgets.cpp
new file mode 100644
index 00000000..6ba44f69
--- /dev/null
+++ b/src/colorpicker/widgets.cpp
@@ -0,0 +1,210 @@
+#include "widgets.h"
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+// https://github.com/yjg30737/pyqt-color-picker/blob/main/pyqt_color_picker/colorSquareWidget.py
+
+SVBox::SVBox()
+{
+ // this->setFixedSize(400, 300);
+ this->setMinimumHeight(300);
+
+ auto layout = new QGridLayout(this);
+ colorWidget = new QWidget();
+
+ blackWidget = new QWidget();
+ // https://github.com/yjg30737/pyqt-color-picker/blob/main/pyqt_color_picker/style/black_overlay.css
+ QString blackStyle = "background-color: qlineargradient(spread:pad, x1:0, "
+ "y1:0, x2:0, y2:1, stop:0 rgba(0, 0, 0, 0),"
+ "stop:1 rgba(0, 0, 0, 255));"
+ "width:100%;"
+ "border-radius: 5px;";
+ blackWidget->setStyleSheet(blackStyle);
+
+ blackWidget->installEventFilter(this);
+ blackWidget->setMouseTracking(true);
+
+ selector = new QWidget(blackWidget);
+ selector->setGeometry(qFloor(selectorDiameter / 2) * -1,
+ qFloor(selectorDiameter / 2) * -1, selectorDiameter,
+ selectorDiameter);
+
+ selector->setStyleSheet("background-color: none;"
+ "border: 2px solid white;"
+ "border-radius: 5px;");
+
+ // connect(blackWidget, &QWidget::mouseMoveEvent, []() {
+
+ // });
+
+ // you can stack widgets on top of each other in a grid
+
+ layout->addWidget(colorWidget, 0, 0, 1, 1);
+ layout->addWidget(blackWidget, 0, 0, 1, 1);
+ layout->setContentsMargins(0, 0, 0, 0);
+ this->setLayout(layout);
+
+ this->setColor(QColor(255, 0, 0));
+}
+
+void SVBox::setColor(const QColor& color)
+{
+ h = color.hueF();
+ s = color.saturationF();
+ v = color.valueF();
+
+ auto hue = color.hueF() * 100;
+ QString style = "background-color: qlineargradient(x1:1, x2:0, "
+ "stop:0 hsl(%1%,100%,50%),"
+ "stop:1 #fff);"
+ "border-radius: 5px;";
+ auto formatted = style.arg(hue);
+
+ // qDebug() << formatted;
+ this->setStyleSheet(formatted);
+}
+
+bool SVBox::eventFilter(QObject* object, QEvent* event)
+{
+
+ if (object == this->blackWidget) {
+ auto mouseEvent = (QMouseEvent*)event;
+ // handle appropriate event
+ switch (event->type()) {
+ case QEvent::MouseButtonPress: {
+ if (mouseEvent->button() == Qt::LeftButton) {
+ dragging = true;
+ moveSelector(mouseEvent);
+ }
+ } break;
+ case QEvent::MouseButtonRelease: {
+ if (mouseEvent->button() == Qt::LeftButton) {
+ dragging = false;
+ }
+ } break;
+ case QEvent::MouseMove: {
+ if (dragging) {
+ //
+ moveSelector(mouseEvent);
+ }
+ } break;
+ }
+ }
+
+ // false means it should be send to target also. as in , we dont remove
+ // it. if you return true , you will take the event and widget never
+ // sees it so be carefull with that.
+ return false;
+}
+
+void SVBox::moveSelector(QMouseEvent* evt)
+{
+ auto pos = evt->pos();
+
+ pos.setX(std::clamp(pos.x(), 0, this->width()));
+ pos.setY(std::clamp(pos.y(), 0, this->height()));
+
+ this->selector->move(pos -
+ QPoint(selectorDiameter / 2, selectorDiameter / 2));
+
+ // calculate hsl
+ s = (this->selector->pos().x() + (selectorDiameter / 2.0f)) / this->width();
+
+ v = std::abs(((this->selector->pos().y() + (selectorDiameter / 2.0f)) /
+ this->height()) -
+ 1.0f);
+
+ // qDebug() << s << " " << v << "\n";
+}
+
+// https://github.com/mortalis13/Qt-Color-Picker-Qt/blob/master/Widgets/ColorWidgets/hselector.cpp
+
+HueSlider::HueSlider()
+{
+ selectorDrawn = false;
+ hue = 0;
+ // this->setFixedSize(400, 20);
+ setFixedHeight(20);
+
+ this->setStyleSheet("border-radius: 5px;");
+}
+void HueSlider::setHue(float hue)
+{
+ this->hue = hue;
+ update();
+}
+void HueSlider::setColor(const QColor& color)
+{
+ this->color = color;
+ this->hue = color.hueF();
+ update();
+}
+
+void HueSlider::paintEvent(QPaintEvent* event)
+{
+ QPainter painter(this);
+ painter.setRenderHint(QPainter::Antialiasing);
+
+ float barHeight = height();
+ float barWidth = width();
+
+ if (!selectorDrawn) {
+ // if (true) {
+ selectorPixmap = QPixmap(barWidth, barHeight);
+ QPainter huePainter(&selectorPixmap);
+
+ QPointF p1(0, 0);
+ QPointF p2(width(), 0);
+ // QPointF p1(0, 0);
+ // QPointF p2(100, 100);
+ QLinearGradient grad(p1, p2);
+ // QLinearGradient grad(p1, p2);
+
+ float ratio = 1.0 / 360.0f;
+
+ QColor gradientColor;
+ for (qreal hs = 0; hs < 1.0; hs += ratio) {
+ gradientColor.setHsvF(hs, 1.0f, 1.0f);
+ grad.setColorAt(hs, gradientColor);
+ }
+
+ // grad.setColorAt(0.0, Qt::red);
+ // grad.setColorAt(0.5, Qt::green);
+ // grad.setColorAt(1.0, Qt::blue);
+
+ huePainter.setPen(Qt::NoPen);
+ huePainter.setBrush(QBrush(grad));
+ huePainter.drawRect(0, 0, barWidth, barHeight);
+
+ selectorDrawn = true;
+ }
+
+ // selectorPixmap.save("./selector.png");
+ painter.drawPixmap(0, 0, selectorPixmap);
+
+ // draw selector
+ painter.setPen(QPen(Qt::black, 2));
+ painter.setBrush(Qt::white);
+ painter.drawEllipse(QPointF(hue * width(), height() / 2), 5, 5);
+}
+
+void HueSlider::resizeEvent(QResizeEvent* event) { selectorDrawn = false; }
+
+void HueSlider::mousePressEvent(QMouseEvent* event)
+{
+ hue = event->pos().x() / (float)width();
+ update();
+ // emit onHueChanged(hue);
+}
+
+void HueSlider::mouseMoveEvent(QMouseEvent* event)
+{
+ hue = event->pos().x() / (float)width();
+ hue = std::clamp(hue, 0.0f, 1.0f);
+ update();
+}
diff --git a/src/colorpicker/widgets.h b/src/colorpicker/widgets.h
new file mode 100644
index 00000000..6043defb
--- /dev/null
+++ b/src/colorpicker/widgets.h
@@ -0,0 +1,52 @@
+#pragma once
+
+#include
+
+class SVBox;
+class HueSlider;
+class AlphaSlider;
+
+// https://github.com/yjg30737/pyqt-color-picker/blob/main/pyqt_color_picker/colorSquareWidget.py
+class SVBox : public QWidget {
+ QColor color;
+
+ QWidget* colorWidget;
+ // black overlay
+ QWidget* blackWidget;
+
+ QWidget* selector;
+ int selectorDiameter = 10;
+ bool dragging = false;
+
+ float h, s, v;
+
+public:
+ SVBox();
+ void setColor(const QColor& color);
+ bool eventFilter(QObject* object, QEvent* event);
+ void moveSelector(QMouseEvent* evt);
+
+signals:
+ void onSVChanged(float saturation, float value);
+};
+
+// https://github.com/mortalis13/Qt-Color-Picker-Qt/blob/master/Widgets/ColorWidgets/hselector.cpp
+class HueSlider : public QWidget {
+ float hue;
+ bool selectorDrawn;
+ QColor color;
+ QPixmap selectorPixmap;
+
+public:
+ HueSlider();
+ void setHue(float hue);
+ void setColor(const QColor& color);
+
+protected:
+ void paintEvent(QPaintEvent* event) override;
+ void resizeEvent(QResizeEvent* event) override;
+ void mousePressEvent(QMouseEvent* event) override;
+ void mouseMoveEvent(QMouseEvent* event) override;
+signals:
+ void onHueChanged(float hue);
+};
diff --git a/src/components/Accordion.vue b/src/components/Accordion.vue
deleted file mode 100644
index f0a7ac37..00000000
--- a/src/components/Accordion.vue
+++ /dev/null
@@ -1,76 +0,0 @@
-
-
-
-
-
-
-
diff --git a/src/components/ColorPicker.vue b/src/components/ColorPicker.vue
deleted file mode 100644
index 387cc650..00000000
--- a/src/components/ColorPicker.vue
+++ /dev/null
@@ -1,185 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/components/HelloWorld.vue b/src/components/HelloWorld.vue
deleted file mode 100644
index 8fd7679d..00000000
--- a/src/components/HelloWorld.vue
+++ /dev/null
@@ -1,130 +0,0 @@
-
-
-
{{ msg }}
-
- For a guide and recipes on how to configure / customize this project,
-
check out the
- vue-cli documentation.
-
-
Installed CLI Plugins
-
-
Essential Links
-
-
Ecosystem
-
-
-
-
-
-
-
-
diff --git a/src/components/LibraryMenu.vue b/src/components/LibraryMenu.vue
deleted file mode 100644
index 29591ec5..00000000
--- a/src/components/LibraryMenu.vue
+++ /dev/null
@@ -1,399 +0,0 @@
-
-
-
-
-
-
-
-
-
diff --git a/src/components/ProgressView.vue b/src/components/ProgressView.vue
deleted file mode 100644
index c2e9decd..00000000
--- a/src/components/ProgressView.vue
+++ /dev/null
@@ -1,94 +0,0 @@
-
-
-
-
-
-
-
diff --git a/src/components/properties/BoolProp.vue b/src/components/properties/BoolProp.vue
deleted file mode 100644
index b6706607..00000000
--- a/src/components/properties/BoolProp.vue
+++ /dev/null
@@ -1,108 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/components/properties/ColorProp.vue b/src/components/properties/ColorProp.vue
deleted file mode 100644
index 861052e3..00000000
--- a/src/components/properties/ColorProp.vue
+++ /dev/null
@@ -1,122 +0,0 @@
-,
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/components/properties/EnumProp.vue b/src/components/properties/EnumProp.vue
deleted file mode 100644
index 1797abe1..00000000
--- a/src/components/properties/EnumProp.vue
+++ /dev/null
@@ -1,101 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/components/properties/FloatProp.vue b/src/components/properties/FloatProp.vue
deleted file mode 100644
index 6a8ca8c1..00000000
--- a/src/components/properties/FloatProp.vue
+++ /dev/null
@@ -1,226 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/components/properties/GradientProp.vue b/src/components/properties/GradientProp.vue
deleted file mode 100644
index 66afed29..00000000
--- a/src/components/properties/GradientProp.vue
+++ /dev/null
@@ -1,522 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/components/properties/ImageProp.vue b/src/components/properties/ImageProp.vue
deleted file mode 100644
index 1639e02a..00000000
--- a/src/components/properties/ImageProp.vue
+++ /dev/null
@@ -1,241 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/components/properties/RandomSeedProp.vue b/src/components/properties/RandomSeedProp.vue
deleted file mode 100644
index f833560f..00000000
--- a/src/components/properties/RandomSeedProp.vue
+++ /dev/null
@@ -1,198 +0,0 @@
-
-
-
-
-
-
-
diff --git a/src/components/properties/StringProp.vue b/src/components/properties/StringProp.vue
deleted file mode 100644
index 5663d390..00000000
--- a/src/components/properties/StringProp.vue
+++ /dev/null
@@ -1,110 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/components/properties/TextureChannelProp.vue b/src/components/properties/TextureChannelProp.vue
deleted file mode 100644
index b627aecb..00000000
--- a/src/components/properties/TextureChannelProp.vue
+++ /dev/null
@@ -1,127 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/components/properties/ipropertyui.ts b/src/components/properties/ipropertyui.ts
deleted file mode 100644
index d37fe32c..00000000
--- a/src/components/properties/ipropertyui.ts
+++ /dev/null
@@ -1,9 +0,0 @@
-export interface IProperyUi {
- refresh();
-}
-
-export class PropertyChangeComplete {
- public propName: string;
- public oldValue: any;
- public newValue: any;
-}
diff --git a/src/components/variables/BoolVar.vue b/src/components/variables/BoolVar.vue
deleted file mode 100644
index ef95130d..00000000
--- a/src/components/variables/BoolVar.vue
+++ /dev/null
@@ -1,35 +0,0 @@
-
-
-
-
-
-
-
-
diff --git a/src/components/variables/ColorVar.vue b/src/components/variables/ColorVar.vue
deleted file mode 100644
index 14766338..00000000
--- a/src/components/variables/ColorVar.vue
+++ /dev/null
@@ -1,40 +0,0 @@
-
-
-
-
-
-
-
-
diff --git a/src/components/variables/EnumVar.vue b/src/components/variables/EnumVar.vue
deleted file mode 100644
index 97047e59..00000000
--- a/src/components/variables/EnumVar.vue
+++ /dev/null
@@ -1,43 +0,0 @@
-
-
-
-
-
-
-
-
diff --git a/src/components/variables/FloatVar.vue b/src/components/variables/FloatVar.vue
deleted file mode 100644
index dbb038b5..00000000
--- a/src/components/variables/FloatVar.vue
+++ /dev/null
@@ -1,106 +0,0 @@
-
-
-
-
-
-
-
-
-
-
diff --git a/src/export.ts b/src/export.ts
deleted file mode 100644
index f30735c9..00000000
--- a/src/export.ts
+++ /dev/null
@@ -1,375 +0,0 @@
-import jimp from "jimp";
-import sharp from "sharp";
-import { Editor } from "./lib/editor";
-import { BitDepth, encode } from "fast-png";
-import fs from "fs";
-import { PNG } from "pngjs";
-import {
- Float16Array,
- isFloat16Array,
- getFloat16,
- setFloat16,
- hfround
-} from "@petamoriken/float16";
-import {
- TextureComponents,
- TextureDataConverter
-} from "./lib/designer/texturedataconverter";
-import { TextureDataType } from "./lib/designer/gl";
-import { DesignerNode } from "./lib/designer/designernode";
-import { Designer } from "./lib/designer";
-import AdmZip from "adm-zip";
-import path from "path";
-import electron from "electron";
-
-export enum ImageFileType {
- Png = "png",
- Jpg = "jpg",
- Tga = "tga",
- Tif = "tif"
-}
-
-export enum ColorSpace {
- Linear = "linear",
- sRGB = "srgb"
-}
-
-export enum OutputType {
- Folder,
- Zip,
- UnityPackage
-}
-
-export enum TextureTransform {
- InvertX,
- InvertY,
- InvertZ,
- LinearizeRoughness
-}
-
-export class ExportTextureSettings {
- channelName: string = ""; // albedo, roughness, normal, etc..
- colorSpace: ColorSpace = ColorSpace.Linear;
- fileType: ImageFileType = ImageFileType.Png;
- transforms: TextureTransform[] = [];
-}
-
-// can have multiple settings and presets
-export class ExportSettings {
- name: string = "";
- filePattern: string = "{project}_{file}";
- // textureSettings: Map = new Map<
- // string,
- // ExportTextureSettings
- // >();
- // enabled: boolean = true;
- outputType: OutputType = OutputType.Zip;
- outputPath: string = "";
-}
-
-export class Exporter {
- async export(editor: Editor, settings: ExportSettings) {
- const designer = editor.designer;
- const conv = new TextureDataConverter(editor.designer.gl);
- // sample config
-
- // assume the settings have all the nodes listen already
- // settings is the source of truth
- console.log(editor.textureChannels);
-
- const exportNodes = this.gatherExportNodes(designer, editor);
- console.log(exportNodes);
-
- let files: Map = new Map();
-
- for (const node of exportNodes) {
- const channelNode = node.node;
-
- // const pixelData = channelNode.getPixelData();
- // const pixelData = conv.getData(
- // channelNode.node.tex,
- // designer.width,
- // designer.height,
- // TextureDataType.Uint16,
- // TextureComponents.RGBA,
- // true
- // );
-
- const pixelData = conv.getData(
- channelNode.tex,
- designer.width,
- designer.height,
- node.dataType,
- node.components,
- true
- );
-
- // too expensive
- // convertRange(pixelData);
-
- // console.log(pixelData);
- // console.log(floatData);
- // for (let i = 0; i < 20; i++) {
- // console.log(floatData[i]);
- // }
-
- // const exportPath =
- // "C:/Users/Nicolas Brown/Desktop/export-" + node.name + ".png";
- // console.log("exporting to: " + exportPath);
-
- const fileData = exportNodeAsPng(
- node,
- pixelData,
- designer.width,
- designer.height
- );
-
- const projectName = settings.name
- .replace(" ", "_")
- .replace(/[^0-9a-zA-Z_]/g, "");
-
- const fileName = interpolateString(settings.filePattern, {
- project: projectName,
- name: node.name
- });
-
- // files.set(node.name + ".png", fileData);
- files.set(fileName + ".png", fileData);
-
- // write to file if folder mode
- // fs.writeFile(exportPath, bytes, function(err) {
- // if (err) alert("Error exporting texture: " + err);
- // });
-
- // write to zip otherwise
-
- // const imgCanvas = editor.getChannelCanvasImage(channelName);
- // if (imgCanvas) {
- // const imgData = imgCanvas.canvas.toDataURL("image/png");
-
- // //todo: get raw image data from gpu in floating point
- // }
- }
-
- if (settings.outputType == OutputType.Folder) {
- exportFilesToFolder(files, settings.outputPath);
- } else {
- exportFilesToZip(files, settings.outputPath);
- electron.remote.shell.showItemInFolder(settings.outputPath);
- }
-
- // export them
-
- // const image = await jimp.read("");
- }
-
- calculateFileName(fileName: string, project: string): string {
- return null;
- }
-
- // returns all nodes ready for export with their data
- // todo: use display channel if no name property specified
- gatherExportNodes(designer: Designer, editor: Editor) {
- // gather all export nodes
- // let exportNodes = [];
-
- let nodes = designer.nodes.filter(x => x.typeName === "output");
-
- let exportNodes: ExportNode[] = [];
-
- for (const node of nodes) {
- let exportNode = new ExportNode();
-
- exportNode.node = node;
- for (const prop of node.properties) {
- if (prop.name === "name") {
- exportNode.name = prop.getValue();
- }
- if (prop.name === "precision") {
- const precision = prop.getValue() as number;
-
- // 0 -> 8bits
- // 1 -> 16bits
- if (precision === 0) exportNode.dataType = TextureDataType.Uint8;
- if (precision === 1) exportNode.dataType = TextureDataType.Uint16;
- }
- if (prop.name === "components") {
- const components = prop.getValue() as number;
-
- // 0 -> RGBA
- // 1 -> RGB
- // 2 -> R
- // 3 -> G
- // 4 -> B
- // 5 -> A
- if (components === 0) exportNode.components = TextureComponents.RGBA;
- if (components === 1) exportNode.components = TextureComponents.RGB;
- if (components === 2) exportNode.components = TextureComponents.R;
- if (components === 3) exportNode.components = TextureComponents.G;
- if (components === 4) exportNode.components = TextureComponents.B;
- if (components === 5) exportNode.components = TextureComponents.A;
- }
- }
-
- if (!exportNode.name || exportNode.name === "") {
- exportNode.name = getChannelNameForNode(exportNode.node, editor);
- }
-
- exportNodes.push(exportNode);
- }
-
- return exportNodes;
- }
-}
-
-function getChannelNameForNode(node: DesignerNode, editor: Editor) {
- const channels = editor.textureChannels;
- // slow.
- // create dictionary with nodeId as key instead
- for (const key of channels.keys()) {
- if (channels.get(key) === node) return key;
- }
-
- return "";
-}
-
-function exportNodeAsPng(
- node: ExportNode,
- pixelData: ArrayBuffer,
- width: number,
- height: number
-): ArrayBuffer {
- try {
- let bitDepth: BitDepth = 8;
- if (node.dataType === TextureDataType.Uint16) bitDepth = 16;
-
- let channels: number = 4;
- // if (node.components === TextureComponents.RGBA) channels = 4;
- if (node.components === TextureComponents.RGB) channels = 3;
- if (
- node.components === TextureComponents.R ||
- node.components === TextureComponents.G ||
- node.components === TextureComponents.B ||
- node.components === TextureComponents.A
- )
- channels = 1;
-
- // FAST-PNG
- const bytes = encode({
- data:
- bitDepth == 8 ? new Uint8Array(pixelData) : new Uint16Array(pixelData),
- width: width,
- height: height,
- depth: bitDepth,
- channels: channels
- });
-
- return bytes.buffer;
-
- // fs.writeFile(exportPath, bytes, function(err) {
- // if (err) alert("Error exporting texture: " + err);
- // });
-
- // await sharp(pixelData, {
- // raw: {
- // width: editor.designer.width,
- // height: editor.designer.height,
- // channels: 4
- // }
- // })
- // // .pipelineColourspace("rgb")
- // // .toColorspace("rgb")
- // .png({})
- // .toFile(exportPath);
-
- // PNGJS
- // https://github.com/lukeapage/pngjs/blob/master/examples/16bit_write.js
- // let png = new PNG({
- // width: editor.designer.width,
- // height: editor.designer.height,
- // inputColorType: 6,
- // colorType: 6,
- // bitDepth: 16,
- // inputHasAlpha: true
- // });
-
- // png.data = Buffer.from(pixelData);
- // png.gamma = 1;
- // png.pack().pipe(fs.createWriteStream(exportPath));
- } catch (error) {
- console.log("error saving file");
- console.log(error);
- }
-}
-
-class ExportNode {
- node: DesignerNode;
- components: TextureComponents = TextureComponents.RGBA;
- dataType: TextureDataType = TextureDataType.Uint8;
- name: string = "";
-}
-
-function exportFilesToFolder(
- files: Map,
- folderPath: string
-) {
- for (let fileName of files.keys()) {
- console.log(fileName);
- const exportPath = path.join(folderPath, fileName);
- const bytes = files.get(fileName);
-
- fs.writeFile(exportPath, new Uint8Array(bytes), function(err) {
- if (err) alert("Error exporting texture: " + err);
- });
- }
-}
-function exportFilesToZip(
- files: Map,
- zipFilePath: string
-) {
- const zip = new AdmZip();
-
- for (let fileName of files.keys()) {
- const bytes = files.get(fileName);
- console.log(bytes);
- zip.addFile(fileName, Buffer.from(bytes));
- }
-
- zip.writeZip(zipFilePath);
-}
-
-function convertRange(data: Uint16Array) {
- const UINT_MAX = 65535.0;
- const VALUE_MAX = 15360.0;
-
- const floatData = new Float16Array(data.buffer);
- for (let i = 0; i < data.length; i++) {
- // if (i < 10) console.log(floatData[i] * UINT_MAX);
- data[i] = floatData[i] * UINT_MAX;
- }
-}
-
-function interpolateString(text: string, exportData: object) {
- if (!text) return "";
-
- // run regex on text and replace values from the string
- text = text.replace(
- /\${([a-z]+)}/g,
- (wholeMatch: string, path: any): string => {
- // console.log(path);
- const data = exportData[path];
- if (!data) return "";
-
- return data;
- }
- );
-
- // console.log(text);
-
- return text;
-}
-
-// class PixelDataConverter
-// {
-// public static rgbaTo
-// }
diff --git a/src/iapp.ts b/src/iapp.ts
deleted file mode 100644
index 6f463340..00000000
--- a/src/iapp.ts
+++ /dev/null
@@ -1,3 +0,0 @@
-export interface IApp {
- randomSeed: number;
-}
diff --git a/src/lib/actions/addconnectionaction.ts b/src/lib/actions/addconnectionaction.ts
deleted file mode 100644
index 65ad4cb8..00000000
--- a/src/lib/actions/addconnectionaction.ts
+++ /dev/null
@@ -1,25 +0,0 @@
-import { Action } from "../undostack";
-import { GraphicsItem } from "../scene/graphicsitem";
-import { Vector2 } from "../scene/view";
-import { ConnectionGraphicsItem } from "../scene/connectiongraphicsitem";
-import { NodeScene } from "../scene";
-
-export class AddConnectionAction extends Action {
- scene: NodeScene;
- con: ConnectionGraphicsItem;
-
- constructor(scene: NodeScene, con: ConnectionGraphicsItem) {
- super();
-
- this.scene = scene;
- this.con = con;
- }
-
- undo() {
- this.scene.removeConnection(this.con);
- }
-
- redo() {
- this.scene.addConnection(this.con);
- }
-}
diff --git a/src/lib/actions/additemsaction.ts b/src/lib/actions/additemsaction.ts
deleted file mode 100644
index 4223ef1f..00000000
--- a/src/lib/actions/additemsaction.ts
+++ /dev/null
@@ -1,107 +0,0 @@
-import { Action } from "../undostack";
-import { GraphicsItem } from "../scene/graphicsitem";
-import { Vector2 } from "../scene/view";
-import { ConnectionGraphicsItem } from "../scene/connectiongraphicsitem";
-import { NodeScene } from "../scene";
-import { FrameGraphicsItem } from "../scene/framegraphicsitem";
-import { CommentGraphicsItem } from "../scene/commentgraphicsitem";
-import { NodeGraphicsItem } from "../scene/nodegraphicsitem";
-import { NavigationGraphicsItem } from "../scene/navigationgraphicsitem";
-import { DesignerNode } from "../designer/designernode";
-import { Designer } from "../designer";
-
-// used when items are added to the scene
-// also used for paste events
-export class AddItemsAction extends Action {
- scene: NodeScene;
- designer: Designer;
- frames: FrameGraphicsItem[];
- comments: CommentGraphicsItem[];
- navs: NavigationGraphicsItem[];
- cons: ConnectionGraphicsItem[];
- nodes: NodeGraphicsItem[];
- dnodes: DesignerNode[];
-
- constructor(
- scene: NodeScene,
- designer: Designer,
- frames: FrameGraphicsItem[],
- comments: CommentGraphicsItem[],
- navs: NavigationGraphicsItem[],
- cons: ConnectionGraphicsItem[],
- nodes: NodeGraphicsItem[],
- dnodes: DesignerNode[]
- ) {
- super();
-
- this.scene = scene;
- this.designer = designer;
- this.frames = frames;
- this.comments = comments;
- this.navs = navs;
- this.cons = cons;
- this.nodes = nodes;
- this.dnodes = dnodes;
- }
-
- undo() {
- for (const frame of this.frames) {
- this.scene.removeFrame(frame);
- }
-
- for (const comment of this.comments) {
- this.scene.removeComment(comment);
- }
-
- for (const nav of this.navs) {
- this.scene.removeNavigation(nav);
- }
-
- // for (let dnode of this.dnodes) {
- // this.designer.addNode(dnode, false);
- // }
-
- // relying on callbacks to add the connection
- // in designer
- for (const con of this.cons) {
- this.scene.removeConnection(con);
- }
-
- // also relying callbacks to have the node deleted in designer
- // note: texture channel gets removed here if assigned
- // since texture channels are not assigned upon a node being
- // added to a scene then there is no need to attempt to
- // reassign any
- for (const node of this.nodes) {
- this.scene.deleteNode(node);
- }
- }
-
- redo() {
- for (const frame of this.frames) {
- this.scene.addFrame(frame);
- }
-
- for (const comment of this.comments) {
- this.scene.addComment(comment);
- }
-
- for (const nav of this.navs) {
- this.scene.addNavigation(nav);
- }
-
- for (const node of this.nodes) {
- this.scene.addNode(node);
- }
-
- for (const dnode of this.dnodes) {
- this.designer.addNode(dnode, false);
- }
-
- // relying on callbacks to add the connection
- // in designer
- for (const con of this.cons) {
- this.scene.addConnection(con);
- }
- }
-}
diff --git a/src/lib/actions/changetexturechannelaction.ts b/src/lib/actions/changetexturechannelaction.ts
deleted file mode 100644
index 57c128df..00000000
--- a/src/lib/actions/changetexturechannelaction.ts
+++ /dev/null
@@ -1,89 +0,0 @@
-import { Action } from "../undostack";
-import { GraphicsItem } from "../scene/graphicsitem";
-import { Vector2, Rect } from "../scene/view";
-import { FrameGraphicsItem } from "../scene/framegraphicsitem";
-import { Editor } from "../editor";
-
-/*
-FROM
-
-node1 --> channel1
-
-ndoe2 --> channel2
-
-OR
-
-node1 --> channel1
-
- --> channel2
-
-
-TO
-
-node1 \ channel1
- \
-node2 \-> channel2
-
-OR
-
-node1 \ channel1
- \
- \-> channel2
-
-NOTE:
-node2 might be null
-if channel2 is null then we just remove the channel
-*/
-export class ChangeTextureChannelAction extends Action {
- ui: () => void;
- editor: Editor;
- node1: string;
- node2: string;
- channel1: string;
- channel2: string;
-
- constructor(
- ui: () => void,
- editor: Editor,
- node1: string, // active node
- channel1: string, // current channel
- node2: string, // new channel
- channel2: string // node being displaced from new channel
- ) {
- super();
-
- this.ui = ui;
- this.editor = editor;
- this.channel1 = channel1;
- this.channel2 = channel2;
- this.node1 = node1;
- this.node2 = node2;
- }
-
- undo() {
- if (this.channel1) {
- this.editor.assignNodeToTextureChannel(this.node1, this.channel1);
- } else {
- // node didnt have a channel to begin with
- this.editor.clearTextureChannel(this.node1);
- }
-
- if (this.channel2 != null && this.node2 != null) {
- // reset displaced node
- this.editor.assignNodeToTextureChannel(this.node2, this.channel2);
- }
-
- if (this.ui) this.ui();
- }
-
- redo() {
- if (this.channel2 == null) {
- // clear channel
- this.editor.clearTextureChannel(this.node1);
- } else {
- this.editor.assignNodeToTextureChannel(this.node1, this.channel2);
- }
-
- if (this.ui) this.ui();
- }
-}
diff --git a/src/lib/actions/moveItemsaction.ts b/src/lib/actions/moveItemsaction.ts
deleted file mode 100644
index f8f4647b..00000000
--- a/src/lib/actions/moveItemsaction.ts
+++ /dev/null
@@ -1,35 +0,0 @@
-import { Action } from "../undostack";
-import { GraphicsItem } from "../scene/graphicsitem";
-import { Vector2 } from "../scene/view";
-
-export class MoveItemsAction extends Action {
- items: GraphicsItem[];
- oldPosList: Vector2[];
- newPosList: Vector2[];
-
- constructor(
- items: GraphicsItem[],
- oldPosList: Vector2[],
- newPosList: Vector2[]
- ) {
- super();
-
- this.items = items;
- this.oldPosList = oldPosList;
- this.newPosList = newPosList;
- }
-
- undo() {
- for (let i = 0; i < this.items.length; i++) {
- const pos = this.oldPosList[i];
- this.items[i].setPos(pos.x, pos.y);
- }
- }
-
- redo() {
- for (let i = 0; i < this.items.length; i++) {
- const pos = this.newPosList[i];
- this.items[i].setPos(pos.x, pos.y);
- }
- }
-}
diff --git a/src/lib/actions/propertychangeaction.ts b/src/lib/actions/propertychangeaction.ts
deleted file mode 100644
index 562bfb0e..00000000
--- a/src/lib/actions/propertychangeaction.ts
+++ /dev/null
@@ -1,44 +0,0 @@
-import { Action } from "../undostack";
-import { GraphicsItem } from "../scene/graphicsitem";
-import { Vector2, Rect } from "../scene/view";
-import { FrameGraphicsItem } from "../scene/framegraphicsitem";
-import { IPropertyHolder } from "../designer/properties";
-import { IProperyUi } from "@/components/properties/ipropertyui";
-import App from "@/App.vue";
-
-export class PropertyChangeAction extends Action {
- ui: () => void;
- propHolder: IPropertyHolder;
- propName: string;
- oldValue: any;
- newValue: any;
-
- constructor(
- ui: () => void,
- propName: string,
- propHolder: IPropertyHolder,
- oldValue: any,
- newValue: any
- ) {
- super();
-
- this.ui = ui;
- this.propName = propName;
- this.propHolder = propHolder;
- this.oldValue = oldValue;
- this.newValue = newValue;
- }
-
- undo() {
- this.propHolder.setProperty(this.propName, this.oldValue);
- //App.instance.$refs.properties.$forceUpdate();
- //this.ui.refresh();
- if (this.ui) this.ui();
- }
-
- redo() {
- this.propHolder.setProperty(this.propName, this.newValue);
- //this.ui.refresh();
- if (this.ui) this.ui();
- }
-}
diff --git a/src/lib/actions/removeconnectionaction.ts b/src/lib/actions/removeconnectionaction.ts
deleted file mode 100644
index b22077b3..00000000
--- a/src/lib/actions/removeconnectionaction.ts
+++ /dev/null
@@ -1,25 +0,0 @@
-import { Action } from "../undostack";
-import { GraphicsItem } from "../scene/graphicsitem";
-import { Vector2 } from "../scene/view";
-import { ConnectionGraphicsItem } from "../scene/connectiongraphicsitem";
-import { NodeScene } from "../scene";
-
-export class RemoveConnectionAction extends Action {
- scene: NodeScene;
- con: ConnectionGraphicsItem;
-
- constructor(scene: NodeScene, con: ConnectionGraphicsItem) {
- super();
-
- this.scene = scene;
- this.con = con;
- }
-
- undo() {
- this.scene.addConnection(this.con);
- }
-
- redo() {
- this.scene.removeConnection(this.con);
- }
-}
diff --git a/src/lib/actions/removeitemsaction.ts b/src/lib/actions/removeitemsaction.ts
deleted file mode 100644
index 39289729..00000000
--- a/src/lib/actions/removeitemsaction.ts
+++ /dev/null
@@ -1,125 +0,0 @@
-import { Action } from "../undostack";
-import { GraphicsItem } from "../scene/graphicsitem";
-import { Vector2 } from "../scene/view";
-import { ConnectionGraphicsItem } from "../scene/connectiongraphicsitem";
-import { NodeScene } from "../scene";
-import { FrameGraphicsItem } from "../scene/framegraphicsitem";
-import { CommentGraphicsItem } from "../scene/commentgraphicsitem";
-import { NodeGraphicsItem } from "../scene/nodegraphicsitem";
-import { NavigationGraphicsItem } from "../scene/navigationgraphicsitem";
-import { DesignerNode } from "../designer/designernode";
-import { Designer } from "../designer";
-import { Editor } from "../editor";
-
-// used when items are added to the scene
-// also used for paste events
-export class RemoveItemsAction extends Action {
- editor: Editor;
- scene: NodeScene;
- designer: Designer;
- frames: FrameGraphicsItem[];
- comments: CommentGraphicsItem[];
- navs: NavigationGraphicsItem[];
- cons: ConnectionGraphicsItem[];
- nodes: NodeGraphicsItem[];
- dnodes: DesignerNode[];
- textureChannels: Map;
-
- constructor(
- editor: Editor,
- scene: NodeScene,
- designer: Designer,
- frames: FrameGraphicsItem[],
- comments: CommentGraphicsItem[],
- navs: NavigationGraphicsItem[],
- cons: ConnectionGraphicsItem[],
- nodes: NodeGraphicsItem[],
- dnodes: DesignerNode[]
- ) {
- super();
-
- this.editor = editor;
- this.scene = scene;
- this.designer = designer;
- this.frames = frames;
- this.comments = comments;
- this.navs = navs;
- this.cons = cons;
- this.nodes = nodes;
- this.dnodes = dnodes;
-
- this.textureChannels = new Map();
-
- for (const node of nodes) {
- if (node.textureChannel != null) {
- this.textureChannels.set(node.id, node.textureChannel);
- }
- }
- }
-
- undo() {
- for (const frame of this.frames) {
- this.scene.addFrame(frame);
- }
-
- for (const comment of this.comments) {
- this.scene.addComment(comment);
- }
-
- for (const nav of this.navs) {
- this.scene.addNavigation(nav);
- }
-
- for (const node of this.nodes) {
- this.scene.addNode(node);
- }
-
- for (const dnode of this.dnodes) {
- this.designer.addNode(dnode, false);
- }
-
- // assign texture channels
- for (const [nodeId, channel] of this.textureChannels) {
- this.editor.assignNodeToTextureChannel(nodeId, channel);
- }
-
- // relying on callbacks to add the connection
- // in designer
- for (const con of this.cons) {
- this.scene.addConnection(con);
- }
- }
-
- redo() {
- for (const frame of this.frames) {
- this.scene.removeFrame(frame);
- }
-
- for (const comment of this.comments) {
- this.scene.removeComment(comment);
- }
-
- for (const nav of this.navs) {
- this.scene.removeNavigation(nav);
- }
-
- // for (let dnode of this.dnodes) {
- // this.designer.addNode(dnode, false);
- // }
-
- // relying on callbacks to add the connection
- // in designer
- for (const con of this.cons) {
- this.scene.removeConnection(con);
- }
-
- // also relying callbacks to have the node deleted in designer
- // note: texture channel gets removed here if assigned
- // since texture channels are not assigned upon a node being
- // added to a scene then there is no need to attempt to
- // reassign any
- for (const node of this.nodes) {
- this.scene.deleteNode(node);
- }
- }
-}
diff --git a/src/lib/actions/resizeframeaction.ts b/src/lib/actions/resizeframeaction.ts
deleted file mode 100644
index fb880143..00000000
--- a/src/lib/actions/resizeframeaction.ts
+++ /dev/null
@@ -1,26 +0,0 @@
-import { Action } from "../undostack";
-import { GraphicsItem } from "../scene/graphicsitem";
-import { Vector2, Rect } from "../scene/view";
-import { FrameGraphicsItem } from "../scene/framegraphicsitem";
-
-export class ResizeFrameAction extends Action {
- frame: FrameGraphicsItem;
- oldRect: Rect;
- newRect: Rect;
-
- constructor(frame: FrameGraphicsItem, oldRect: Rect, newRect: Rect) {
- super();
-
- this.frame = frame;
- this.oldRect = oldRect;
- this.newRect = newRect;
- }
-
- undo() {
- this.frame.setFrameRect(this.oldRect);
- }
-
- redo() {
- this.frame.setFrameRect(this.newRect);
- }
-}
diff --git a/src/lib/actions/setglobalrandomseedaction.ts b/src/lib/actions/setglobalrandomseedaction.ts
deleted file mode 100644
index 09395701..00000000
--- a/src/lib/actions/setglobalrandomseedaction.ts
+++ /dev/null
@@ -1,32 +0,0 @@
-import { Action } from "../undostack";
-import { GraphicsItem } from "../scene/graphicsitem";
-import { Vector2, Rect } from "../scene/view";
-import { FrameGraphicsItem } from "../scene/framegraphicsitem";
-import { Editor } from "../editor";
-import { IApp } from "@/iapp";
-
-export class SetGlobalRandomSeedAction extends Action {
- editor: Editor;
- oldSeed: number;
- newSeed: number;
- app: IApp;
-
- constructor(app: IApp, editor: Editor, oldSeed: number, newSeed: number) {
- super();
-
- this.app = app;
- this.editor = editor;
- this.oldSeed = oldSeed;
- this.newSeed = newSeed;
- }
-
- undo() {
- this.app.randomSeed = this.oldSeed;
- this.editor.designer.setRandomSeed(this.oldSeed);
- }
-
- redo() {
- this.app.randomSeed = this.newSeed;
- this.editor.designer.setRandomSeed(this.newSeed);
- }
-}
diff --git a/src/lib/actions/setnoderandomseedaction.ts b/src/lib/actions/setnoderandomseedaction.ts
deleted file mode 100644
index c4762cf2..00000000
--- a/src/lib/actions/setnoderandomseedaction.ts
+++ /dev/null
@@ -1,33 +0,0 @@
-import { Action } from "../undostack";
-import { DesignerNode } from "../designer/designernode";
-
-export class SetNodeRandomSeedAction extends Action {
- ui: () => void;
- node: DesignerNode;
- oldSeed: number;
- newSeed: number;
-
- constructor(
- ui: () => void,
- node: DesignerNode,
- oldSeed: number,
- newSeed: number
- ) {
- super();
-
- this.ui = ui;
- this.node = node;
- this.oldSeed = oldSeed;
- this.newSeed = newSeed;
- }
-
- undo() {
- this.node.setRandomSeed(this.oldSeed);
- if (this.ui) this.ui();
- }
-
- redo() {
- this.node.setRandomSeed(this.newSeed);
- if (this.ui) this.ui();
- }
-}
diff --git a/src/lib/actions/switchconnectionaction.ts b/src/lib/actions/switchconnectionaction.ts
deleted file mode 100644
index b3b6c5ed..00000000
--- a/src/lib/actions/switchconnectionaction.ts
+++ /dev/null
@@ -1,52 +0,0 @@
-import { Action } from "../undostack";
-import { GraphicsItem } from "../scene/graphicsitem";
-import { Vector2 } from "../scene/view";
-import { ConnectionGraphicsItem } from "../scene/connectiongraphicsitem";
-import { NodeScene } from "../scene";
-
-export enum ConnectionSwitchAction {
- Add = "add",
- Remove = "delete"
-}
-
-export class SwitchConnectionAction extends Action {
- scene: NodeScene;
- cons: ConnectionGraphicsItem[];
- actions: ConnectionSwitchAction[]; //'add' or 'remove'
-
- constructor(
- scene: NodeScene,
- cons: ConnectionGraphicsItem[],
- actions: ConnectionSwitchAction[]
- ) {
- super();
-
- this.scene = scene;
- this.cons = cons;
- this.actions = actions;
- }
-
- undo() {
- for (let i = this.cons.length - 1; i >= 0; i--) {
- if (this.actions[i] == ConnectionSwitchAction.Add) {
- this.scene.removeConnection(this.cons[i]);
- } else if (this.actions[i] == ConnectionSwitchAction.Remove) {
- this.scene.addConnection(this.cons[i]);
- } else {
- throw "Invalid connection undo-redo action";
- }
- }
- }
-
- redo() {
- for (let i = 0; i < this.cons.length; i++) {
- if (this.actions[i] == ConnectionSwitchAction.Add) {
- this.scene.addConnection(this.cons[i]);
- } else if (this.actions[i] == ConnectionSwitchAction.Remove) {
- this.scene.removeConnection(this.cons[i]);
- } else {
- throw "Invalid connection undo-redo action";
- }
- }
- }
-}
diff --git a/src/lib/clipboard.ts b/src/lib/clipboard.ts
deleted file mode 100644
index 6903d9c2..00000000
--- a/src/lib/clipboard.ts
+++ /dev/null
@@ -1,357 +0,0 @@
-import { GraphicsItem } from "./scene/graphicsitem";
-import { NodeScene } from "./scene";
-import { DesignerLibrary } from "./designer/library";
-import { FrameGraphicsItem } from "./scene/framegraphicsitem";
-import { Color } from "./designer/color";
-import { CommentGraphicsItem } from "./scene/commentgraphicsitem";
-import { NavigationGraphicsItem } from "./scene/navigationgraphicsitem";
-import { Designer } from "./designer";
-import { DesignerNode } from "./designer/designernode";
-import { NodeGraphicsItem } from "./scene/nodegraphicsitem";
-import { DesignerNodeConn } from "./designer/designerconnection";
-import { SocketType } from "./scene/socketgraphicsitem";
-import { ConnectionGraphicsItem } from "./scene/connectiongraphicsitem";
-import { Guid } from "./utils";
-import { AddItemsAction } from "./actions/additemsaction";
-import { UndoStack } from "./undostack";
-import { Rect, Vector2 } from "./scene/view";
-
-export class ItemClipboard {
- public static copyItems(
- designer: Designer,
- library: DesignerLibrary,
- scene: NodeScene,
- clipboard: DataTransfer
- ) {
- clipboard.clearData();
- const items = scene.selectedItems;
- if (items.length == 0) {
- // empty clipboard
- clipboard.setData("text/nodes", "");
- }
-
- const data = {
- nodes: [],
- connections: [],
- comments: [],
- frames: [],
- navigations: [],
- libraryVersion: ""
- };
-
- // NODES AND CONNECTIONS
- const nodeList: NodeGraphicsItem[] = [];
- items.forEach(i => {
- // check if this works with obfuscated code
- if (i instanceof NodeGraphicsItem) nodeList.push(i);
- });
-
- data.nodes = this.getNodes(designer, nodeList);
- data.connections = this.getConnections(data.nodes, designer, nodeList);
-
- // FRAMES
- const frames = [];
- for (const item of items) {
- if (!(item instanceof FrameGraphicsItem)) continue;
- const frame = item;
-
- const n: any = {};
- n["x"] = frame.left;
- n["y"] = frame.top;
- n["width"] = frame.getWidth();
- n["height"] = frame.getHeight();
-
- n["title"] = frame.title;
- n["showTitle"] = frame.showTitle;
- n["description"] = frame.description;
- n["color"] = frame.color.toHex();
-
- frames.push(n);
- }
- data.frames = frames;
-
- // COMMENTS
- const comments = [];
- for (const item of items) {
- if (!(item instanceof CommentGraphicsItem)) continue;
- const comment = item;
-
- const n: any = {};
- n["x"] = comment.left;
- n["y"] = comment.top;
-
- n["text"] = comment.text;
- n["color"] = comment.color.toHex();
-
- comments.push(n);
- }
- data.comments = comments;
-
- // NAVIGATIONS
- const navs = [];
- for (const item of items) {
- if (!(item instanceof NavigationGraphicsItem)) continue;
- const nav = item;
-
- const n: any = {};
- n["x"] = nav.left;
- n["y"] = nav.top;
-
- navs.push(n);
- }
- data.navigations = navs;
-
- // let data = scene.save(); // do to items
- data.libraryVersion = library.getVersionName();
-
- const json = JSON.stringify(data);
-
- clipboard.setData("json/nodes", json);
- }
-
- public static pasteItems(
- designer: Designer,
- library: DesignerLibrary,
- scene: NodeScene,
- clipboard: DataTransfer
- ) {
- const json = clipboard.getData("json/nodes");
- //console.log(json);
- if (json == null || json == "") return;
-
- const data = JSON.parse(json);
- if (!data) return;
-
- const frames: FrameGraphicsItem[] = [];
- const comments: CommentGraphicsItem[] = [];
- const navs: NavigationGraphicsItem[] = [];
- const cons: ConnectionGraphicsItem[] = [];
- const nodes: NodeGraphicsItem[] = [];
- const dnodes: DesignerNode[] = [];
-
- // for selecting pasted items
- const focusItems: GraphicsItem[] = [];
-
- // FRAMES
- if (data.frames) {
- for (const d of data.frames) {
- const frame = new FrameGraphicsItem(scene.view);
- frame.setPos(d.x, d.y);
- frame.setSize(d.width, d.height);
-
- frame.setTitle(d.title);
- frame.setShowTitle(d.showTitle);
- frame.setDescription(d.description);
- frame.color = Color.parse(d.color);
-
- scene.addFrame(frame);
- frames.push(frame);
- focusItems.push(frame);
- }
- }
-
- // COMMENTS
- if (data.comments) {
- for (const d of data.comments) {
- const comment = new CommentGraphicsItem(scene.view);
- comment.setPos(d.x, d.y);
- comment.setText(d.text);
- comment.color = Color.parse(d.color);
-
- scene.addComment(comment);
- comments.push(comment);
- focusItems.push(comment);
- }
- }
-
- // NAVIGATION
- if (data.navigations) {
- for (const d of data.navigations) {
- const nav = new NavigationGraphicsItem();
- nav.setPos(d.x, d.y);
- scene.addNavigation(nav);
- navs.push(nav);
- focusItems.push(nav);
- }
- }
-
- //NODES AND CONNECTIONS
-
- // old : new
- const nodeIdMap = {};
- // add them to designer then add them to scene
- for (const n of data.nodes) {
- const dNode = library.create(n.typeName);
-
- // add to designer
- designer.addNode(dNode);
- nodeIdMap[n.id] = dNode.id;
-
- // assign properties
- for (const propName in n.properties) {
- dNode.setProperty(propName, n.properties[propName]);
- }
-
- // create scene version
- const node = new NodeGraphicsItem(dNode.title);
- for (const input of dNode.getInputs()) {
- node.addSocket(input, input, SocketType.In);
- }
- node.addSocket("output", "output", SocketType.Out);
- node.id = dNode.id;
- scene.addNode(node);
- focusItems.push(node);
-
- // generate thumbnail
- const thumb = designer.generateImageFromNode(dNode);
- node.setThumbnail(thumb);
-
- node.setCenter(n.x, n.y);
-
- nodes.push(node);
- dnodes.push(dNode);
- }
- // console.log(nodeIdMap);
-
- // console.log(scene.nodes);
-
- // add connections
- for (const c of data.connections) {
- // map to ids of new nodes
- const leftId = nodeIdMap[c.leftNodeId];
- const rightId = nodeIdMap[c.rightNodeId];
-
- // create connection
- const con = new ConnectionGraphicsItem();
- con.id = Guid.newGuid(); // brand new connection
-
- // get nodes
- const leftNode = scene.getNodeById(leftId);
- const rightNode = scene.getNodeById(rightId);
-
- // get sockets
- con.socketA = leftNode.getOutSocketByName(c.leftNodeOutput);
- con.socketB = rightNode.getInSocketByName(c.rightNodeInput);
-
- // callback triggers the creation in designer
- scene.addConnection(con);
-
- cons.push(con);
- }
-
- if (
- frames.length != 0 ||
- comments.length != 0 ||
- navs.length != 0 ||
- cons.length != 0 ||
- nodes.length != 0 ||
- dnodes.length != 0
- ) {
- // gather bounding box and center items to screen
- if (focusItems.length > 0) {
- const rect = this.getItemsBounds(focusItems);
- const center = scene.view.sceneCenter;
-
- // find diff, then offset each object by that diff
- //let diff = Vector2.subtract(center, rect.center);
- for (const item of focusItems) {
- const offsetFromRect = Vector2.subtract(item.getPos(), rect.center);
- const newPos = Vector2.add(center, offsetFromRect);
- item.setPos(newPos.x, newPos.y);
- //item.move(diff.x, diff.y);
- }
- }
-
- // add undo-redo
- const action = new AddItemsAction(
- scene,
- designer,
- frames,
- comments,
- navs,
- cons,
- nodes,
- dnodes
- );
- UndoStack.current.push(action);
-
- // make items selected
- scene.setSelectedItems(focusItems, true);
- }
- }
-
- // merge designer and scene node in one
- // scene node only has x and y values
- static getNodes(
- designer: Designer,
- items: NodeGraphicsItem[]
- ): Array