UNPKG

yuksel-c2-interpolation

Version:
1 lines 3.06 kB
!function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e(require("THREE"));else if("function"==typeof define&&define.amd)define(["THREE"],e);else{var o="object"==typeof exports?e(require("THREE")):e(t.THREE);for(var n in o)("object"==typeof exports?exports:t)[n]=o[n]}}(self,(t=>(()=>{"use strict";var e={355:(t,e,o)=>{Object.defineProperty(e,"__esModule",{value:!0});const n=o(824);e.default=class{p0;p1;p2;constructor(t,e,o){this.p0=t,this.p1=e,this.p2=o}interpolate(t){const{p0:e,p1:o,p2:l}=this,s=(1-t)*(1-t)*e.x+2*(1-t)*t*o.x+t*t*l.x,r=(1-t)*(1-t)*e.y+2*(1-t)*t*o.y+t*t*l.y;return new n.Vector2(s,r)}}},256:function(t,e,o){var n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});const l=n(o(355));e.default=class{bezier;constructor(t,e,o){const n=t=>t*t;let s=.5;const r=o.clone().sub(t),a=t.clone().sub(e),i=e.clone().sub(o),c=n(r.length()),u=r.clone().multiplyScalar(3).dot(a),h=a.clone().multiplyScalar(3).add(i).dot(a),p=(3*c*h-u*u)/3/c/c,f=(2*u*u*u-9*c*u*h+27*c*c*-n(a.length()))/27/c/c/c;if(4*p*p*p+27*f*f>=0)s=Math.cbrt(-f/2+Math.sqrt(f*f/4+p*p*p/27))+Math.cbrt(-f/2-Math.sqrt(f*f/4+p*p*p/27))-u/3/c;else for(let t=0;t<3;t++){const e=2*Math.sqrt(-p/3)*Math.cos(1/3*Math.acos(3*f/2/p*Math.sqrt(-3/p))-2*Math.PI*t/3)-u/3/c;e>=0&&e<=1&&(s=e)}const d=e.clone().sub(t.clone().multiplyScalar(n(1-s))).sub(o.clone().multiplyScalar(n(s))).divideScalar(2*(1-s)*s);this.bezier=new l.default(t,d,o)}interpolate(t){return this.bezier.interpolate(t)}}},427:function(t,e,o){var n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});const l=o(824),s=n(o(256));e.default=class{static interpolationFunc=[];static pointsLength=0;static SmoothPolygon(t){this.pointsLength=t.length;const e=[];for(let o=0;o<t.length;o++)e.push(new l.Vector2(t[o][0],t[o][1]));this.generateInterpolationFunc(e);const o=[];for(let t=0;t<e.length-1;t++)for(let e=0;e<Math.PI/2;e+=.01)o.push(this.getPoint(t,e));const n=[];for(let t=0;t<o.length;t++)n.push([o[t].x,o[t].y]);return n}static generateInterpolationFunc(t){this.interpolationFunc=[];for(let e=0;e<t.length-2;e++)this.interpolationFunc.push(new s.default(t[e],t[e+1],t[e+2]))}static getPoint(t,e){return 0===t?this.scaledCall(0,e):t===this.pointsLength-2?this.scaledCall(t-1,e+Math.PI/2):this.blend(t-1,t,e)}static scaledCall(t,e){return this.interpolationFunc[t].interpolate(e/Math.PI)}static blend(t,e,o){return this.scaledCall(t,o+Math.PI/2).clone().multiplyScalar(Math.cos(o)*Math.cos(o)).add(this.scaledCall(e,o).clone().multiplyScalar(Math.sin(o)*Math.sin(o)))}}},465:function(t,e,o){var n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});const l=n(o(427));e.default=l.default},824:e=>{e.exports=t}},o={};var n=function t(n){var l=o[n];if(void 0!==l)return l.exports;var s=o[n]={exports:{}};return e[n].call(s.exports,s,s.exports,t),s.exports}(465);return n})()));