(function (global, factory) { if (typeof define === "function" && define.amd) { define(["exports", "../core/TempNode.js"], factory); } else if (typeof exports !== "undefined") { factory(exports, require("../core/TempNode.js")); } else { var mod = { exports: {} }; factory(mod.exports, global.TempNode); global.MathNode = mod.exports; } })(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _TempNode2) { "use strict"; Object.defineProperty(_exports, "__esModule", { value: true }); _exports.MathNode = void 0; 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 _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get; } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); } function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; } 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 MathNode = /*#__PURE__*/function (_TempNode) { _inherits(MathNode, _TempNode); var _super = _createSuper(MathNode); function MathNode(a, bOrMethod, cOrMethod, method) { var _this; _classCallCheck(this, MathNode); _this = _super.call(this); _this.a = a; typeof bOrMethod !== 'string' ? _this.b = bOrMethod : method = bOrMethod; typeof cOrMethod !== 'string' ? _this.c = cOrMethod : method = cOrMethod; _this.method = method; return _this; } _createClass(MathNode, [{ key: "getNumInputs", value: function /*builder*/ getNumInputs() { switch (this.method) { case MathNode.MIX: case MathNode.CLAMP: case MathNode.REFRACT: case MathNode.SMOOTHSTEP: case MathNode.FACEFORWARD: return 3; case MathNode.MIN: case MathNode.MAX: case MathNode.MOD: case MathNode.STEP: case MathNode.REFLECT: case MathNode.DISTANCE: case MathNode.DOT: case MathNode.CROSS: case MathNode.POW: return 2; default: return 1; } } }, { key: "getInputType", value: function getInputType(builder) { var a = builder.getTypeLength(this.a.getType(builder)); var b = this.b ? builder.getTypeLength(this.b.getType(builder)) : 0; var c = this.c ? builder.getTypeLength(this.c.getType(builder)) : 0; if (a > b && a > c) { return this.a.getType(builder); } else if (b > c) { return this.b.getType(builder); } return this.c.getType(builder); } }, { key: "getType", value: function getType(builder) { switch (this.method) { case MathNode.LENGTH: case MathNode.DISTANCE: case MathNode.DOT: return 'f'; case MathNode.CROSS: return 'v3'; } return this.getInputType(builder); } }, { key: "generate", value: function generate(builder, output) { var a, b, c; var al = this.a ? builder.getTypeLength(this.a.getType(builder)) : 0, bl = this.b ? builder.getTypeLength(this.b.getType(builder)) : 0, cl = this.c ? builder.getTypeLength(this.c.getType(builder)) : 0, inputType = this.getInputType(builder), nodeType = this.getType(builder); switch (this.method) { // 1 input case MathNode.NEGATE: return builder.format('( -' + this.a.build(builder, inputType) + ' )', inputType, output); case MathNode.INVERT: return builder.format('( 1.0 - ' + this.a.build(builder, inputType) + ' )', inputType, output); // 2 inputs case MathNode.CROSS: a = this.a.build(builder, 'v3'); b = this.b.build(builder, 'v3'); break; case MathNode.STEP: a = this.a.build(builder, al === 1 ? 'f' : inputType); b = this.b.build(builder, inputType); break; case MathNode.MIN: case MathNode.MAX: case MathNode.MOD: a = this.a.build(builder, inputType); b = this.b.build(builder, bl === 1 ? 'f' : inputType); break; // 3 inputs case MathNode.REFRACT: a = this.a.build(builder, inputType); b = this.b.build(builder, inputType); c = this.c.build(builder, 'f'); break; case MathNode.MIX: a = this.a.build(builder, inputType); b = this.b.build(builder, inputType); c = this.c.build(builder, cl === 1 ? 'f' : inputType); break; // default default: a = this.a.build(builder, inputType); if (this.b) b = this.b.build(builder, inputType); if (this.c) c = this.c.build(builder, inputType); break; } // build function call var params = []; params.push(a); if (b) params.push(b); if (c) params.push(c); var numInputs = this.getNumInputs(builder); if (params.length !== numInputs) { throw Error("Arguments not match used in \"".concat(this.method, "\". Require ").concat(numInputs, ", currently ").concat(params.length, ".")); } return builder.format(this.method + '( ' + params.join(', ') + ' )', nodeType, output); } }, { key: "copy", value: function copy(source) { _get(_getPrototypeOf(MathNode.prototype), "copy", this).call(this, source); this.a = source.a; this.b = source.b; this.c = source.c; this.method = source.method; return this; } }, { key: "toJSON", value: function toJSON(meta) { var data = this.getJSONNode(meta); if (!data) { data = this.createJSONNode(meta); data.a = this.a.toJSON(meta).uuid; if (this.b) data.b = this.b.toJSON(meta).uuid; if (this.c) data.c = this.c.toJSON(meta).uuid; data.method = this.method; } return data; } }]); return MathNode; }(_TempNode2.TempNode); // 1 input _exports.MathNode = MathNode; MathNode.RAD = 'radians'; MathNode.DEG = 'degrees'; MathNode.EXP = 'exp'; MathNode.EXP2 = 'exp2'; MathNode.LOG = 'log'; MathNode.LOG2 = 'log2'; MathNode.SQRT = 'sqrt'; MathNode.INV_SQRT = 'inversesqrt'; MathNode.FLOOR = 'floor'; MathNode.CEIL = 'ceil'; MathNode.NORMALIZE = 'normalize'; MathNode.FRACT = 'fract'; MathNode.SATURATE = 'saturate'; MathNode.SIN = 'sin'; MathNode.COS = 'cos'; MathNode.TAN = 'tan'; MathNode.ASIN = 'asin'; MathNode.ACOS = 'acos'; MathNode.ARCTAN = 'atan'; MathNode.ABS = 'abs'; MathNode.SIGN = 'sign'; MathNode.LENGTH = 'length'; MathNode.NEGATE = 'negate'; MathNode.INVERT = 'invert'; // 2 inputs MathNode.MIN = 'min'; MathNode.MAX = 'max'; MathNode.MOD = 'mod'; MathNode.STEP = 'step'; MathNode.REFLECT = 'reflect'; MathNode.DISTANCE = 'distance'; MathNode.DOT = 'dot'; MathNode.CROSS = 'cross'; MathNode.POW = 'pow'; // 3 inputs MathNode.MIX = 'mix'; MathNode.CLAMP = 'clamp'; MathNode.REFRACT = 'refract'; MathNode.SMOOTHSTEP = 'smoothstep'; MathNode.FACEFORWARD = 'faceforward'; MathNode.prototype.nodeType = 'Math'; MathNode.prototype.hashProperties = ['method']; });