(function (global, factory) { if (typeof define === "function" && define.amd) { define(["exports", "three"], factory); } else if (typeof exports !== "undefined") { factory(exports, require("three")); } else { var mod = { exports: {} }; factory(mod.exports, global.three); global.ParametricGeometry = mod.exports; } })(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _three) { "use strict"; Object.defineProperty(_exports, "__esModule", { value: true }); _exports.ParametricGeometry = void 0; 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 _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } 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 ParametricGeometry = /*#__PURE__*/function (_BufferGeometry) { _inherits(ParametricGeometry, _BufferGeometry); var _super = _createSuper(ParametricGeometry); function ParametricGeometry() { var _this; var func = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function (u, v, target) { return target.set(u, v, Math.cos(u) * Math.sin(v)); }; var slices = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 8; var stacks = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 8; _classCallCheck(this, ParametricGeometry); _this = _super.call(this); _this.type = 'ParametricGeometry'; _this.parameters = { func: func, slices: slices, stacks: stacks }; // buffers var indices = []; var vertices = []; var normals = []; var uvs = []; var EPS = 0.00001; var normal = new _three.Vector3(); var p0 = new _three.Vector3(), p1 = new _three.Vector3(); var pu = new _three.Vector3(), pv = new _three.Vector3(); if (func.length < 3) { console.error('THREE.ParametricGeometry: Function must now modify a Vector3 as third parameter.'); } // generate vertices, normals and uvs var sliceCount = slices + 1; for (var i = 0; i <= stacks; i++) { var v = i / stacks; for (var j = 0; j <= slices; j++) { var u = j / slices; // vertex func(u, v, p0); vertices.push(p0.x, p0.y, p0.z); // normal // approximate tangent vectors via finite differences if (u - EPS >= 0) { func(u - EPS, v, p1); pu.subVectors(p0, p1); } else { func(u + EPS, v, p1); pu.subVectors(p1, p0); } if (v - EPS >= 0) { func(u, v - EPS, p1); pv.subVectors(p0, p1); } else { func(u, v + EPS, p1); pv.subVectors(p1, p0); } // cross product of tangent vectors returns surface normal normal.crossVectors(pu, pv).normalize(); normals.push(normal.x, normal.y, normal.z); // uv uvs.push(u, v); } } // generate indices for (var _i = 0; _i < stacks; _i++) { for (var _j = 0; _j < slices; _j++) { var a = _i * sliceCount + _j; var b = _i * sliceCount + _j + 1; var c = (_i + 1) * sliceCount + _j + 1; var d = (_i + 1) * sliceCount + _j; // faces one and two indices.push(a, b, d); indices.push(b, c, d); } } // build geometry _this.setIndex(indices); _this.setAttribute('position', new _three.Float32BufferAttribute(vertices, 3)); _this.setAttribute('normal', new _three.Float32BufferAttribute(normals, 3)); _this.setAttribute('uv', new _three.Float32BufferAttribute(uvs, 2)); return _this; } return _createClass(ParametricGeometry); }(_three.BufferGeometry); _exports.ParametricGeometry = ParametricGeometry; });