(function (global, factory) { if (typeof define === "function" && define.amd) { define(["exports", "../libs/flow.module.js", "./materials/StandardMaterialEditor.js", "./math/OperatorEditor.js", "./math/NormalizeEditor.js", "./math/InvertEditor.js", "./math/LimiterEditor.js", "./math/DotEditor.js", "./math/PowerEditor.js", "./math/TrigonometryEditor.js", "./inputs/FloatEditor.js", "./inputs/Vector2Editor.js", "./inputs/Vector3Editor.js", "./inputs/Vector4Editor.js", "./inputs/SliderEditor.js", "./inputs/ColorEditor.js", "./display/BlendEditor.js", "./accessors/UVEditor.js", "./accessors/PositionEditor.js", "./accessors/NormalEditor.js", "./utils/TimerEditor.js", "./utils/OscillatorEditor.js", "./procedural/CheckerEditor.js", "three"], factory); } else if (typeof exports !== "undefined") { factory(exports, require("../libs/flow.module.js"), require("./materials/StandardMaterialEditor.js"), require("./math/OperatorEditor.js"), require("./math/NormalizeEditor.js"), require("./math/InvertEditor.js"), require("./math/LimiterEditor.js"), require("./math/DotEditor.js"), require("./math/PowerEditor.js"), require("./math/TrigonometryEditor.js"), require("./inputs/FloatEditor.js"), require("./inputs/Vector2Editor.js"), require("./inputs/Vector3Editor.js"), require("./inputs/Vector4Editor.js"), require("./inputs/SliderEditor.js"), require("./inputs/ColorEditor.js"), require("./display/BlendEditor.js"), require("./accessors/UVEditor.js"), require("./accessors/PositionEditor.js"), require("./accessors/NormalEditor.js"), require("./utils/TimerEditor.js"), require("./utils/OscillatorEditor.js"), require("./procedural/CheckerEditor.js"), require("three")); } else { var mod = { exports: {} }; factory(mod.exports, global.flowModule, global.StandardMaterialEditor, global.OperatorEditor, global.NormalizeEditor, global.InvertEditor, global.LimiterEditor, global.DotEditor, global.PowerEditor, global.TrigonometryEditor, global.FloatEditor, global.Vector2Editor, global.Vector3Editor, global.Vector4Editor, global.SliderEditor, global.ColorEditor, global.BlendEditor, global.UVEditor, global.PositionEditor, global.NormalEditor, global.TimerEditor, global.OscillatorEditor, global.CheckerEditor, global.three); global.NodeEditor = mod.exports; } })(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _flowModule, _StandardMaterialEditor, _OperatorEditor, _NormalizeEditor, _InvertEditor, _LimiterEditor, _DotEditor, _PowerEditor, _TrigonometryEditor, _FloatEditor, _Vector2Editor, _Vector3Editor, _Vector4Editor, _SliderEditor, _ColorEditor, _BlendEditor, _UVEditor, _PositionEditor, _NormalEditor, _TimerEditor, _OscillatorEditor, _CheckerEditor, _three) { "use strict"; Object.defineProperty(_exports, "__esModule", { value: true }); _exports.NodeEditor = _exports.ClassLib = void 0; function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } Object.defineProperty(subClass, "prototype", { value: Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }), writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } var ClassLib = { 'StandardMaterialEditor': _StandardMaterialEditor.StandardMaterialEditor, 'OperatorEditor': _OperatorEditor.OperatorEditor, 'NormalizeEditor': _NormalizeEditor.NormalizeEditor, 'InvertEditor': _InvertEditor.InvertEditor, 'LimiterEditor': _LimiterEditor.LimiterEditor, 'DotEditor': _DotEditor.DotEditor, 'PowerEditor': _PowerEditor.PowerEditor, 'TrigonometryEditor': _TrigonometryEditor.TrigonometryEditor, 'FloatEditor': _FloatEditor.FloatEditor, 'Vector2Editor': _Vector2Editor.Vector2Editor, 'Vector3Editor': _Vector3Editor.Vector3Editor, 'Vector4Editor': _Vector4Editor.Vector4Editor, 'SliderEditor': _SliderEditor.SliderEditor, 'ColorEditor': _ColorEditor.ColorEditor, 'BlendEditor': _BlendEditor.BlendEditor, 'UVEditor': _UVEditor.UVEditor, 'PositionEditor': _PositionEditor.PositionEditor, 'NormalEditor': _NormalEditor.NormalEditor, 'TimerEditor': _TimerEditor.TimerEditor, 'OscillatorEditor': _OscillatorEditor.OscillatorEditor, 'CheckerEditor': _CheckerEditor.CheckerEditor }; _exports.ClassLib = ClassLib; var NodeEditor = /*#__PURE__*/function (_EventDispatcher) { _inherits(NodeEditor, _EventDispatcher); var _super = _createSuper(NodeEditor); function NodeEditor() { var _this; _classCallCheck(this, NodeEditor); _this = _super.call(this); var domElement = document.createElement('flow'); var canvas = new _flowModule.Canvas(); domElement.appendChild(canvas.dom); _this.canvas = canvas; _this.domElement = domElement; _this.nodesContext = null; _this.examplesContext = null; _this._initMenu(); _this._initNodesContext(); _this._initExamplesContext(); return _this; } _createClass(NodeEditor, [{ key: "add", value: function add(node) { this.canvas.add(node); return this; } }, { key: "nodes", get: function get() { return this.canvas.nodes; } }, { key: "newProject", value: function newProject() { this.canvas.clear(); this.dispatchEvent({ type: 'new' }); } }, { key: "loadJSON", value: function loadJSON(json) { this.canvas.clear(); this.canvas.deserialize(json); this.dispatchEvent({ type: 'load' }); } }, { key: "_initMenu", value: function _initMenu() { var _this2 = this; var menu = new _flowModule.CircleMenu(); var menuButton = new _flowModule.ButtonInput().setIcon('ti ti-menu-2'); var examplesButton = new _flowModule.ButtonInput().setIcon('ti ti-file-symlink').setToolTip('Examples'); var newButton = new _flowModule.ButtonInput().setIcon('ti ti-file').setToolTip('New'); var openButton = new _flowModule.ButtonInput().setIcon('ti ti-upload').setToolTip('Open'); var saveButton = new _flowModule.ButtonInput().setIcon('ti ti-download').setToolTip('Save'); var hideContext = function hideContext() { _this2.examplesContext.hide(); _this2.nodesContext.hide(); }; menuButton.onClick(function () { _this2.nodesContext.show(60, 50); }); examplesButton.onClick(function () { _this2.examplesContext.show(60, 175); }); newButton.onClick(function () { hideContext(); _this2.newProject(); }); openButton.onClick(function () { hideContext(); var input = document.createElement('input'); input.type = 'file'; input.onchange = function (e) { var file = e.target.files[0]; var reader = new FileReader(); reader.readAsText(file, 'UTF-8'); reader.onload = function (readerEvent) { var loader = new _flowModule.Loader(_flowModule.Loader.OBJECTS); var json = loader.parse(JSON.parse(readerEvent.target.result), ClassLib); _this2.loadJSON(json); }; }; input.click(); }); saveButton.onClick(function () { hideContext(); var json = JSON.stringify(_this2.canvas.toJSON()); var a = document.createElement('a'); var file = new Blob([json], { type: 'text/plain' }); a.href = URL.createObjectURL(file); a.download = 'node_editor.json'; a.click(); }); menu.add(menuButton).add(newButton).add(examplesButton).add(openButton).add(saveButton); this.domElement.appendChild(menu.dom); this.menu = menu; } }, { key: "_initExamplesContext", value: function _initExamplesContext() { var _this3 = this; var context = new _flowModule.ContextMenu(); //**************// // MAIN //**************// var onClickExample = /*#__PURE__*/function () { var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(button) { var filename, loader, json; return regeneratorRuntime.wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: _this3.examplesContext.hide(); filename = button.getExtra(); loader = new _flowModule.Loader(_flowModule.Loader.OBJECTS); _context.next = 5; return loader.load("./jsm/node-editor/examples/".concat(filename, ".json"), ClassLib); case 5: json = _context.sent; _this3.loadJSON(json); case 7: case "end": return _context.stop(); } } }, _callee); })); return function onClickExample(_x) { return _ref.apply(this, arguments); }; }(); var addExample = function addExample(context, name) { var filename = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; filename = filename || name.replaceAll(' ', '-').toLowerCase(); context.add(new _flowModule.ButtonInput(name).setIcon('ti ti-file-symlink').onClick(onClickExample).setExtra(filename)); }; //**************// // EXAMPLES //**************// var basicContext = new _flowModule.ContextMenu(); var advancedContext = new _flowModule.ContextMenu(); addExample(basicContext, 'Animate UV'); addExample(basicContext, 'Fake top light'); addExample(basicContext, 'Oscillator color'); addExample(advancedContext, 'Rim'); //**************// // MAIN //**************// context.add(new _flowModule.ButtonInput('Basic'), basicContext); context.add(new _flowModule.ButtonInput('Advanced'), advancedContext); this.domElement.appendChild(context.dom); this.examplesContext = context; } }, { key: "_initNodesContext", value: function _initNodesContext() { var _this4 = this; var context = new _flowModule.ContextMenu(this.domElement); var isContext = false; var contextPosition = {}; var add = function add(node) { var canvas = _this4.canvas; var canvasRect = canvas.rect; if (isContext) { node.setPosition(contextPosition.x, contextPosition.y); } else { var defaultOffsetX = 350 / 2; var defaultOffsetY = 20; node.setPosition(canvas.relativeX + canvasRect.width / 2 - defaultOffsetX, canvas.relativeY + canvasRect.height / 2 - defaultOffsetY); } context.hide(); _this4.add(node); _this4.canvas.select(node); isContext = false; }; context.onContext(function () { isContext = true; var _this4$canvas = _this4.canvas, relativeClientX = _this4$canvas.relativeClientX, relativeClientY = _this4$canvas.relativeClientY; contextPosition.x = relativeClientX; contextPosition.y = relativeClientY; }); //**************// // INPUTS //**************// var inputsContext = new _flowModule.ContextMenu(); var sliderInput = new _flowModule.ButtonInput('Slider').setIcon('ti ti-adjustments-horizontal').onClick(function () { return add(new _SliderEditor.SliderEditor()); }); var floatInput = new _flowModule.ButtonInput('Float').setIcon('ti ti-box-multiple-1').onClick(function () { return add(new _FloatEditor.FloatEditor()); }); var vector2Input = new _flowModule.ButtonInput('Vector 2').setIcon('ti ti-box-multiple-2').onClick(function () { return add(new _Vector2Editor.Vector2Editor()); }); var vector3Input = new _flowModule.ButtonInput('Vector 3').setIcon('ti ti-box-multiple-3').onClick(function () { return add(new _Vector3Editor.Vector3Editor()); }); var vector4Input = new _flowModule.ButtonInput('Vector 4').setIcon('ti ti-box-multiple-4').onClick(function () { return add(new _Vector4Editor.Vector4Editor()); }); var colorInput = new _flowModule.ButtonInput('Color').setIcon('ti ti-palette').onClick(function () { return add(new _ColorEditor.ColorEditor()); }); //const mapInput = new ButtonInput( 'Map' ).setIcon( 'ti ti-photo' ); //const cubeMapInput = new ButtonInput( 'Cube Map' ).setIcon( 'ti ti-box' ); //const integerInput = new ButtonInput( 'Integer' ).setIcon( 'ti ti-list-numbers' ); inputsContext.add(sliderInput).add(floatInput).add(vector2Input).add(vector3Input).add(vector4Input).add(colorInput); //**************// // MATH //**************// var mathContext = new _flowModule.ContextMenu(); var operatorsNode = new _flowModule.ButtonInput('Operator').setIcon('ti ti-math-symbols').onClick(function () { return add(new _OperatorEditor.OperatorEditor()); }); var normalizeNode = new _flowModule.ButtonInput('Normalize').setIcon('ti ti-fold').onClick(function () { return add(new _NormalizeEditor.NormalizeEditor()); }); var invertNode = new _flowModule.ButtonInput('Invert').setToolTip('Negate').setIcon('ti ti-flip-vertical').onClick(function () { return add(new _InvertEditor.InvertEditor()); }); var limiterNode = new _flowModule.ButtonInput('Limiter').setToolTip('Min / Max').setIcon('ti ti-arrow-bar-to-up').onClick(function () { return add(new _LimiterEditor.LimiterEditor()); }); var dotNode = new _flowModule.ButtonInput('Dot Product').setIcon('ti ti-arrows-up-left').onClick(function () { return add(new _DotEditor.DotEditor()); }); var powNode = new _flowModule.ButtonInput('Power').setIcon('ti ti-arrow-up-right').onClick(function () { return add(new _PowerEditor.PowerEditor()); }); var triNode = new _flowModule.ButtonInput('Trigonometry').setToolTip('Sin / Cos / Tan').setIcon('ti ti-wave-sine').onClick(function () { return add(new _TrigonometryEditor.TrigonometryEditor()); }); mathContext.add(operatorsNode).add(invertNode).add(limiterNode).add(dotNode).add(powNode).add(triNode).add(normalizeNode); //**************// // ACCESSORS //**************// var accessorsContext = new _flowModule.ContextMenu(); var uvNode = new _flowModule.ButtonInput('UV').setIcon('ti ti-details').onClick(function () { return add(new _UVEditor.UVEditor()); }); var positionNode = new _flowModule.ButtonInput('Position').setIcon('ti ti-hierarchy').onClick(function () { return add(new _PositionEditor.PositionEditor()); }); var normalNode = new _flowModule.ButtonInput('Normal').setIcon('ti ti-fold-up').onClick(function () { return add(new _NormalEditor.NormalEditor()); }); accessorsContext.add(uvNode).add(positionNode).add(normalNode); //**************// // PROCEDURAL //**************// var proceduralContext = new _flowModule.ContextMenu(); var checkerNode = new _flowModule.ButtonInput('Checker').setIcon('ti ti-border-outer').onClick(function () { return add(new _CheckerEditor.CheckerEditor()); }); proceduralContext.add(checkerNode); //**************// // DISPLAY //**************// var displayContext = new _flowModule.ContextMenu(); var blendNode = new _flowModule.ButtonInput('Blend').setIcon('ti ti-layers-subtract').onClick(function () { return add(new _BlendEditor.BlendEditor()); }); displayContext.add(blendNode); //**************// // UTILS //**************// var utilsContext = new _flowModule.ContextMenu(); var timerNode = new _flowModule.ButtonInput('Timer').setIcon('ti ti-clock').onClick(function () { return add(new _TimerEditor.TimerEditor()); }); var oscNode = new _flowModule.ButtonInput('Oscillator').setIcon('ti ti-wave-sine').onClick(function () { return add(new _OscillatorEditor.OscillatorEditor()); }); utilsContext.add(timerNode).add(oscNode); //**************// // MAIN //**************// context.add(new _flowModule.ButtonInput('Inputs').setIcon('ti ti-forms'), inputsContext); context.add(new _flowModule.ButtonInput('Accessors').setIcon('ti ti-vector-triangle'), accessorsContext); context.add(new _flowModule.ButtonInput('Display').setIcon('ti ti-brightness'), displayContext); context.add(new _flowModule.ButtonInput('Math').setIcon('ti ti-calculator'), mathContext); context.add(new _flowModule.ButtonInput('Procedural').setIcon('ti ti-infinity'), proceduralContext); context.add(new _flowModule.ButtonInput('Utils').setIcon('ti ti-apps'), utilsContext); this.nodesContext = context; } }]); return NodeEditor; }(_three.EventDispatcher); _exports.NodeEditor = NodeEditor; });