poly-extrude 0.8.0 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * poly-extrude v0.8.0
2
+ * poly-extrude v0.10.0
3
3
  */
4
4
  var earcut$2 = {exports: {}};
5
5
 
@@ -664,2446 +664,2154 @@ earcut.flatten = function (data) {
664
664
 
665
665
  var earcut$1 = earcut$2.exports;
666
666
 
667
- /**
668
- * https://github.com/Turfjs/turf/blob/master/packages/turf-boolean-clockwise/index.ts
669
- * @param {*} ring
670
- * @returns
671
- */
672
- function isClockwise(ring) {
673
- var sum = 0;
674
- var i = 1;
675
- var prev;
676
- var cur;
677
- var len = ring.length;
678
-
679
- while (i < len) {
680
- prev = cur || ring[0];
681
- cur = ring[i];
682
- sum += (cur[0] - prev[0]) * (cur[1] + prev[1]);
683
- i++;
667
+ function _defineProperties(target, props) {
668
+ for (var i = 0; i < props.length; i++) {
669
+ var descriptor = props[i];
670
+ descriptor.enumerable = descriptor.enumerable || false;
671
+ descriptor.configurable = true;
672
+ if ("value" in descriptor) descriptor.writable = true;
673
+ Object.defineProperty(target, descriptor.key, descriptor);
684
674
  }
685
-
686
- return sum > 0;
687
675
  }
688
676
 
689
- function v3Sub(out, v1, v2) {
690
- out[0] = v1[0] - v2[0];
691
- out[1] = v1[1] - v2[1];
692
- out[2] = v1[2] - v2[2];
693
- return out;
677
+ function _createClass(Constructor, protoProps, staticProps) {
678
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
679
+ if (staticProps) _defineProperties(Constructor, staticProps);
680
+ Object.defineProperty(Constructor, "prototype", {
681
+ writable: false
682
+ });
683
+ return Constructor;
694
684
  }
695
685
 
696
- function v3Normalize(out, v) {
697
- var x = v[0];
698
- var y = v[1];
699
- var z = v[2];
700
- var d = Math.sqrt(x * x + y * y + z * z) || 1;
701
- out[0] = x / d;
702
- out[1] = y / d;
703
- out[2] = z / d;
704
- return out;
686
+ function _inheritsLoose(subClass, superClass) {
687
+ subClass.prototype = Object.create(superClass.prototype);
688
+ subClass.prototype.constructor = subClass;
689
+
690
+ _setPrototypeOf(subClass, superClass);
705
691
  }
706
692
 
707
- function v3Cross(out, v1, v2) {
708
- var ax = v1[0],
709
- ay = v1[1],
710
- az = v1[2],
711
- bx = v2[0],
712
- by = v2[1],
713
- bz = v2[2];
714
- out[0] = ay * bz - az * by;
715
- out[1] = az * bx - ax * bz;
716
- out[2] = ax * by - ay * bx;
717
- return out;
693
+ function _setPrototypeOf(o, p) {
694
+ _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
695
+ o.__proto__ = p;
696
+ return o;
697
+ };
698
+ return _setPrototypeOf(o, p);
718
699
  }
719
700
 
720
- function generateNormal(indices, position) {
721
- function v3Set(p, a, b, c) {
722
- p[0] = a;
723
- p[1] = b;
724
- p[2] = c;
725
- }
701
+ // code copy from https://github.com/mrdoob/three.js/blob/dev/src/math/Quaternion.js
702
+ // import { clamp } from './MathUtils.js';
703
+ var Quaternion = /*#__PURE__*/function () {
704
+ function Quaternion(x, y, z, w) {
705
+ if (x === void 0) {
706
+ x = 0;
707
+ }
726
708
 
727
- var p1 = [];
728
- var p2 = [];
729
- var p3 = [];
730
- var v21 = [];
731
- var v32 = [];
732
- var n = [];
733
- var len = indices.length;
734
- var normals = new Float32Array(position.length);
735
- var f = 0;
709
+ if (y === void 0) {
710
+ y = 0;
711
+ }
736
712
 
737
- while (f < len) {
738
- // const i1 = indices[f++] * 3;
739
- // const i2 = indices[f++] * 3;
740
- // const i3 = indices[f++] * 3;
741
- // const i1 = indices[f];
742
- // const i2 = indices[f + 1];
743
- // const i3 = indices[f + 2];
744
- var a = indices[f],
745
- b = indices[f + 1],
746
- c = indices[f + 2];
747
- var i1 = a * 3,
748
- i2 = b * 3,
749
- i3 = c * 3;
750
- v3Set(p1, position[i1], position[i1 + 1], position[i1 + 2]);
751
- v3Set(p2, position[i2], position[i2 + 1], position[i2 + 2]);
752
- v3Set(p3, position[i3], position[i3 + 1], position[i3 + 2]);
753
- v3Sub(v32, p3, p2);
754
- v3Sub(v21, p1, p2);
755
- v3Cross(n, v32, v21); // Already be weighted by the triangle area
713
+ if (z === void 0) {
714
+ z = 0;
715
+ }
756
716
 
757
- for (var _i = 0; _i < 3; _i++) {
758
- normals[i1 + _i] += n[_i];
759
- normals[i2 + _i] += n[_i];
760
- normals[i3 + _i] += n[_i];
717
+ if (w === void 0) {
718
+ w = 1;
761
719
  }
762
720
 
763
- f += 3;
721
+ this.isQuaternion = true;
722
+ this._x = x;
723
+ this._y = y;
724
+ this._z = z;
725
+ this._w = w;
764
726
  }
765
727
 
766
- var i = 0;
767
- var l = normals.length;
768
-
769
- while (i < l) {
770
- v3Set(n, normals[i], normals[i + 1], normals[i + 2]);
771
- v3Normalize(n, n);
772
- normals[i] = n[0] || 0;
773
- normals[i + 1] = n[1] || 0;
774
- normals[i + 2] = n[2] || 0;
775
- i += 3;
776
- }
728
+ Quaternion.slerpFlat = function slerpFlat(dst, dstOffset, src0, srcOffset0, src1, srcOffset1, t) {
729
+ // fuzz-free, array-based Quaternion SLERP operation
730
+ var x0 = src0[srcOffset0 + 0],
731
+ y0 = src0[srcOffset0 + 1],
732
+ z0 = src0[srcOffset0 + 2],
733
+ w0 = src0[srcOffset0 + 3];
734
+ var x1 = src1[srcOffset1 + 0],
735
+ y1 = src1[srcOffset1 + 1],
736
+ z1 = src1[srcOffset1 + 2],
737
+ w1 = src1[srcOffset1 + 3];
777
738
 
778
- return normals;
779
- }
780
- function merge(results) {
781
- if (results.length === 1) {
782
- var _result = {
783
- position: results[0].position,
784
- normal: results[0].normal,
785
- uv: results[0].uv,
786
- indices: results[0].indices,
787
- results: results
788
- };
789
- return _result;
790
- }
739
+ if (t === 0) {
740
+ dst[dstOffset + 0] = x0;
741
+ dst[dstOffset + 1] = y0;
742
+ dst[dstOffset + 2] = z0;
743
+ dst[dstOffset + 3] = w0;
744
+ return;
745
+ }
791
746
 
792
- var plen = 0,
793
- ilen = 0;
747
+ if (t === 1) {
748
+ dst[dstOffset + 0] = x1;
749
+ dst[dstOffset + 1] = y1;
750
+ dst[dstOffset + 2] = z1;
751
+ dst[dstOffset + 3] = w1;
752
+ return;
753
+ }
794
754
 
795
- for (var i = 0, len = results.length; i < len; i++) {
796
- var _results$i = results[i],
797
- position = _results$i.position,
798
- indices = _results$i.indices;
799
- plen += position.length;
800
- ilen += indices.length;
801
- }
755
+ if (w0 !== w1 || x0 !== x1 || y0 !== y1 || z0 !== z1) {
756
+ var s = 1 - t;
757
+ var cos = x0 * x1 + y0 * y1 + z0 * z1 + w0 * w1,
758
+ dir = cos >= 0 ? 1 : -1,
759
+ sqrSin = 1 - cos * cos; // Skip the Slerp for tiny steps to avoid numeric problems:
802
760
 
803
- var result = {
804
- position: new Float32Array(plen),
805
- normal: new Float32Array(plen),
806
- uv: new Float32Array(plen / 3 * 2),
807
- indices: new Uint32Array(ilen),
808
- results: results
809
- };
810
- var pOffset = 0,
811
- pCount = 0,
812
- iIdx = 0,
813
- uvOffset = 0;
761
+ if (sqrSin > Number.EPSILON) {
762
+ var sin = Math.sqrt(sqrSin),
763
+ len = Math.atan2(sin, cos * dir);
764
+ s = Math.sin(s * len) / sin;
765
+ t = Math.sin(t * len) / sin;
766
+ }
814
767
 
815
- for (var _i2 = 0, _len = results.length; _i2 < _len; _i2++) {
816
- var _results$_i = results[_i2],
817
- _position = _results$_i.position,
818
- _indices = _results$_i.indices,
819
- normal = _results$_i.normal,
820
- uv = _results$_i.uv;
821
- result.position.set(_position, pOffset);
822
- result.normal.set(normal, pOffset);
823
- result.uv.set(uv, uvOffset);
824
- var j = 0;
825
- var len1 = _indices.length;
768
+ var tDir = t * dir;
769
+ x0 = x0 * s + x1 * tDir;
770
+ y0 = y0 * s + y1 * tDir;
771
+ z0 = z0 * s + z1 * tDir;
772
+ w0 = w0 * s + w1 * tDir; // Normalize in case we just did a lerp:
826
773
 
827
- while (j < len1) {
828
- var pIndex = _indices[j] + pCount;
829
- result.indices[iIdx] = pIndex;
830
- iIdx++;
831
- j++;
774
+ if (s === 1 - t) {
775
+ var f = 1 / Math.sqrt(x0 * x0 + y0 * y0 + z0 * z0 + w0 * w0);
776
+ x0 *= f;
777
+ y0 *= f;
778
+ z0 *= f;
779
+ w0 *= f;
780
+ }
832
781
  }
833
782
 
834
- uvOffset += uv.length;
835
- pOffset += _position.length;
836
- pCount += _position.length / 3;
837
- }
838
-
839
- return result;
840
- }
841
- function radToDeg(rad) {
842
- return rad * 180 / Math.PI;
843
- }
844
- function degToRad(angle) {
845
- return angle / 180 * Math.PI;
846
- } // https://github.com/mrdoob/three.js/blob/16f13e3b07e31d0e9a00df7c3366bbe0e464588c/src/geometries/ExtrudeGeometry.js?_pjax=%23js-repo-pjax-container#L736
783
+ dst[dstOffset] = x0;
784
+ dst[dstOffset + 1] = y0;
785
+ dst[dstOffset + 2] = z0;
786
+ dst[dstOffset + 3] = w0;
787
+ };
847
788
 
848
- function generateSideWallUV(uvs, vertices, indexA, indexB, indexC, indexD) {
849
- var idx1 = indexA * 3,
850
- idx2 = indexB * 3,
851
- idx3 = indexC * 3,
852
- idx4 = indexD * 3;
853
- var a_x = vertices[idx1];
854
- var a_y = vertices[idx1 + 1];
855
- var a_z = vertices[idx1 + 2];
856
- var b_x = vertices[idx2];
857
- var b_y = vertices[idx2 + 1];
858
- var b_z = vertices[idx2 + 2];
859
- var c_x = vertices[idx3];
860
- var c_y = vertices[idx3 + 1];
861
- var c_z = vertices[idx3 + 2];
862
- var d_x = vertices[idx4];
863
- var d_y = vertices[idx4 + 1];
864
- var d_z = vertices[idx4 + 2];
789
+ Quaternion.multiplyQuaternionsFlat = function multiplyQuaternionsFlat(dst, dstOffset, src0, srcOffset0, src1, srcOffset1) {
790
+ var x0 = src0[srcOffset0];
791
+ var y0 = src0[srcOffset0 + 1];
792
+ var z0 = src0[srcOffset0 + 2];
793
+ var w0 = src0[srcOffset0 + 3];
794
+ var x1 = src1[srcOffset1];
795
+ var y1 = src1[srcOffset1 + 1];
796
+ var z1 = src1[srcOffset1 + 2];
797
+ var w1 = src1[srcOffset1 + 3];
798
+ dst[dstOffset] = x0 * w1 + w0 * x1 + y0 * z1 - z0 * y1;
799
+ dst[dstOffset + 1] = y0 * w1 + w0 * y1 + z0 * x1 - x0 * z1;
800
+ dst[dstOffset + 2] = z0 * w1 + w0 * z1 + x0 * y1 - y0 * x1;
801
+ dst[dstOffset + 3] = w0 * w1 - x0 * x1 - y0 * y1 - z0 * z1;
802
+ return dst;
803
+ };
865
804
 
866
- if (Math.abs(a_y - b_y) < Math.abs(a_x - b_x)) {
867
- uvs.push(a_x, 1 - a_z);
868
- uvs.push(b_x, 1 - b_z);
869
- uvs.push(c_x, 1 - c_z);
870
- uvs.push(d_x, 1 - d_z);
871
- } else {
872
- uvs.push(a_y, 1 - a_z);
873
- uvs.push(b_y, 1 - b_z);
874
- uvs.push(c_y, 1 - c_z);
875
- uvs.push(d_y, 1 - d_z);
876
- }
877
- }
805
+ var _proto = Quaternion.prototype;
878
806
 
879
- function extrudePolygons(polygons, options) {
880
- options = Object.assign({}, {
881
- depth: 2
882
- }, options);
883
- var results = polygons.map(function (polygon) {
884
- for (var i = 0, len = polygon.length; i < len; i++) {
885
- var ring = polygon[i];
886
- validateRing(ring);
807
+ _proto.set = function set(x, y, z, w) {
808
+ this._x = x;
809
+ this._y = y;
810
+ this._z = z;
811
+ this._w = w;
887
812
 
888
- if (i === 0) {
889
- if (!isClockwise(ring)) {
890
- polygon[i] = ring.reverse();
891
- }
892
- } else if (isClockwise(ring)) {
893
- polygon[i] = ring.reverse();
894
- }
813
+ this._onChangeCallback();
895
814
 
896
- if (isClosedRing(ring)) {
897
- ring.splice(ring.length - 1, 1);
898
- }
899
- }
815
+ return this;
816
+ };
900
817
 
901
- var result = flatVertices(polygon, options);
902
- result.polygon = polygon;
903
- var triangles = earcut$1(result.flatVertices, result.holes, 2);
904
- generateTopAndBottom$1(result, triangles);
905
- generateSides$1(result, options);
906
- result.position = new Float32Array(result.points);
907
- result.indices = new Uint32Array(result.index);
908
- result.uv = new Float32Array(result.uvs);
909
- result.normal = generateNormal(result.indices, result.position);
910
- return result;
911
- });
912
- var result = merge(results);
913
- result.polygons = polygons;
914
- return result;
915
- }
818
+ _proto.clone = function clone() {
819
+ return new this.constructor(this._x, this._y, this._z, this._w);
820
+ };
916
821
 
917
- function generateTopAndBottom$1(result, triangles) {
918
- var index = [];
919
- var count = result.count;
822
+ _proto.copy = function copy(quaternion) {
823
+ this._x = quaternion.x;
824
+ this._y = quaternion.y;
825
+ this._z = quaternion.z;
826
+ this._w = quaternion.w;
920
827
 
921
- for (var i = 0, len = triangles.length; i < len; i += 3) {
922
- // top
923
- var a = triangles[i],
924
- b = triangles[i + 1],
925
- c = triangles[i + 2];
926
- index[i] = a;
927
- index[i + 1] = b;
928
- index[i + 2] = c; // bottom
828
+ this._onChangeCallback();
929
829
 
930
- var idx = len + i;
931
- var a1 = count + a,
932
- b1 = count + b,
933
- c1 = count + c;
934
- index[idx] = a1;
935
- index[idx + 1] = b1;
936
- index[idx + 2] = c1;
937
- }
830
+ return this;
831
+ };
938
832
 
939
- result.index = index;
940
- }
833
+ _proto.setFromEuler = function setFromEuler(euler, update) {
834
+ if (update === void 0) {
835
+ update = true;
836
+ }
941
837
 
942
- function generateSides$1(result, options) {
943
- var points = result.points,
944
- index = result.index,
945
- polygon = result.polygon,
946
- uvs = result.uvs;
947
- var depth = options.depth;
948
- var pIndex = points.length - 1;
949
- var iIndex = index.length - 1;
838
+ var x = euler._x,
839
+ y = euler._y,
840
+ z = euler._z,
841
+ order = euler._order; // http://www.mathworks.com/matlabcentral/fileexchange/
842
+ // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
843
+ // content/SpinCalc.m
950
844
 
951
- for (var i = 0, len = polygon.length; i < len; i++) {
952
- var ring = polygon[i];
953
- var j = 0;
954
- var len1 = ring.length;
845
+ var cos = Math.cos;
846
+ var sin = Math.sin;
847
+ var c1 = cos(x / 2);
848
+ var c2 = cos(y / 2);
849
+ var c3 = cos(z / 2);
850
+ var s1 = sin(x / 2);
851
+ var s2 = sin(y / 2);
852
+ var s3 = sin(z / 2);
955
853
 
956
- while (j < len1) {
957
- var v1 = ring[j];
958
- var v2 = ring[j + 1];
854
+ switch (order) {
855
+ case 'XYZ':
856
+ this._x = s1 * c2 * c3 + c1 * s2 * s3;
857
+ this._y = c1 * s2 * c3 - s1 * c2 * s3;
858
+ this._z = c1 * c2 * s3 + s1 * s2 * c3;
859
+ this._w = c1 * c2 * c3 - s1 * s2 * s3;
860
+ break;
959
861
 
960
- if (j === len1 - 1) {
961
- v2 = ring[0];
962
- }
862
+ case 'YXZ':
863
+ this._x = s1 * c2 * c3 + c1 * s2 * s3;
864
+ this._y = c1 * s2 * c3 - s1 * c2 * s3;
865
+ this._z = c1 * c2 * s3 - s1 * s2 * c3;
866
+ this._w = c1 * c2 * c3 + s1 * s2 * s3;
867
+ break;
963
868
 
964
- var idx = points.length / 3;
965
- var x1 = v1[0],
966
- y1 = v1[1],
967
- z1 = v1[2] || 0,
968
- x2 = v2[0],
969
- y2 = v2[1],
970
- z2 = v2[2] || 0;
971
- points[++pIndex] = x1;
972
- points[++pIndex] = y1;
973
- points[++pIndex] = z1 + depth;
974
- points[++pIndex] = x2;
975
- points[++pIndex] = y2;
976
- points[++pIndex] = z2 + depth;
977
- points[++pIndex] = x1;
978
- points[++pIndex] = y1;
979
- points[++pIndex] = z1;
980
- points[++pIndex] = x2;
981
- points[++pIndex] = y2;
982
- points[++pIndex] = z2; // points.push(x1, y1, z, x2, y2, z, x1, y1, 0, x2, y2, 0);
869
+ case 'ZXY':
870
+ this._x = s1 * c2 * c3 - c1 * s2 * s3;
871
+ this._y = c1 * s2 * c3 + s1 * c2 * s3;
872
+ this._z = c1 * c2 * s3 + s1 * s2 * c3;
873
+ this._w = c1 * c2 * c3 - s1 * s2 * s3;
874
+ break;
983
875
 
984
- var a = idx + 2,
985
- b = idx + 3,
986
- c = idx,
987
- d = idx + 1; // points.push(p3, p4, p1, p2);
988
- // index.push(a, c, b, c, d, b);
876
+ case 'ZYX':
877
+ this._x = s1 * c2 * c3 - c1 * s2 * s3;
878
+ this._y = c1 * s2 * c3 + s1 * c2 * s3;
879
+ this._z = c1 * c2 * s3 - s1 * s2 * c3;
880
+ this._w = c1 * c2 * c3 + s1 * s2 * s3;
881
+ break;
989
882
 
990
- index[++iIndex] = a;
991
- index[++iIndex] = c;
992
- index[++iIndex] = b;
993
- index[++iIndex] = c;
994
- index[++iIndex] = d;
995
- index[++iIndex] = b; // index.push(c, d, b);
883
+ case 'YZX':
884
+ this._x = s1 * c2 * c3 + c1 * s2 * s3;
885
+ this._y = c1 * s2 * c3 + s1 * c2 * s3;
886
+ this._z = c1 * c2 * s3 - s1 * s2 * c3;
887
+ this._w = c1 * c2 * c3 - s1 * s2 * s3;
888
+ break;
996
889
 
997
- generateSideWallUV(uvs, points, a, b, c, d);
998
- j++;
999
- }
1000
- }
1001
- }
890
+ case 'XZY':
891
+ this._x = s1 * c2 * c3 - c1 * s2 * s3;
892
+ this._y = c1 * s2 * c3 - s1 * c2 * s3;
893
+ this._z = c1 * c2 * s3 + s1 * s2 * c3;
894
+ this._w = c1 * c2 * c3 + s1 * s2 * s3;
895
+ break;
1002
896
 
1003
- function calPolygonPointsCount(polygon) {
1004
- var count = 0;
1005
- var i = 0;
1006
- var len = polygon.length;
897
+ default:
898
+ console.warn('THREE.Quaternion: .setFromEuler() encountered an unknown order: ' + order);
899
+ }
1007
900
 
1008
- while (i < len) {
1009
- count += polygon[i].length;
1010
- i++;
1011
- }
901
+ if (update === true) this._onChangeCallback();
902
+ return this;
903
+ };
1012
904
 
1013
- return count;
1014
- }
905
+ _proto.setFromAxisAngle = function setFromAxisAngle(axis, angle) {
906
+ // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
907
+ // assumes axis is normalized
908
+ var halfAngle = angle / 2,
909
+ s = Math.sin(halfAngle);
910
+ this._x = axis.x * s;
911
+ this._y = axis.y * s;
912
+ this._z = axis.z * s;
913
+ this._w = Math.cos(halfAngle);
1015
914
 
1016
- function flatVertices(polygon, options) {
1017
- var count = calPolygonPointsCount(polygon);
1018
- var len = polygon.length;
1019
- var holes = [],
1020
- flatVertices = new Float32Array(count * 2),
1021
- points = [],
1022
- uvs = [];
1023
- var pOffset = count * 3,
1024
- uOffset = count * 2;
1025
- var depth = options.depth;
1026
- var idx0 = 0,
1027
- idx1 = 0,
1028
- idx2 = 0;
915
+ this._onChangeCallback();
1029
916
 
1030
- for (var i = 0; i < len; i++) {
1031
- var ring = polygon[i];
917
+ return this;
918
+ };
1032
919
 
1033
- if (i > 0) {
1034
- holes.push(idx0 / 2);
1035
- }
920
+ _proto.setFromRotationMatrix = function setFromRotationMatrix(m) {
921
+ // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
922
+ // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
923
+ var te = m.elements,
924
+ m11 = te[0],
925
+ m12 = te[4],
926
+ m13 = te[8],
927
+ m21 = te[1],
928
+ m22 = te[5],
929
+ m23 = te[9],
930
+ m31 = te[2],
931
+ m32 = te[6],
932
+ m33 = te[10],
933
+ trace = m11 + m22 + m33;
1036
934
 
1037
- var j = 0;
1038
- var len1 = ring.length;
935
+ if (trace > 0) {
936
+ var s = 0.5 / Math.sqrt(trace + 1.0);
937
+ this._w = 0.25 / s;
938
+ this._x = (m32 - m23) * s;
939
+ this._y = (m13 - m31) * s;
940
+ this._z = (m21 - m12) * s;
941
+ } else if (m11 > m22 && m11 > m33) {
942
+ var _s = 2.0 * Math.sqrt(1.0 + m11 - m22 - m33);
1039
943
 
1040
- while (j < len1) {
1041
- var c = ring[j];
1042
- var x = c[0],
1043
- y = c[1],
1044
- z = c[2] || 0;
1045
- flatVertices[idx0++] = x;
1046
- flatVertices[idx0++] = y; // top vertices
944
+ this._w = (m32 - m23) / _s;
945
+ this._x = 0.25 * _s;
946
+ this._y = (m12 + m21) / _s;
947
+ this._z = (m13 + m31) / _s;
948
+ } else if (m22 > m33) {
949
+ var _s2 = 2.0 * Math.sqrt(1.0 + m22 - m11 - m33);
1047
950
 
1048
- points[idx1] = x;
1049
- points[idx1 + 1] = y;
1050
- points[idx1 + 2] = depth + z; // bottom vertices
951
+ this._w = (m13 - m31) / _s2;
952
+ this._x = (m12 + m21) / _s2;
953
+ this._y = 0.25 * _s2;
954
+ this._z = (m23 + m32) / _s2;
955
+ } else {
956
+ var _s3 = 2.0 * Math.sqrt(1.0 + m33 - m11 - m22);
1051
957
 
1052
- points[pOffset + idx1] = x;
1053
- points[pOffset + idx1 + 1] = y;
1054
- points[pOffset + idx1 + 2] = z;
1055
- uvs[idx2] = x;
1056
- uvs[idx2 + 1] = y;
1057
- uvs[uOffset + idx2] = x;
1058
- uvs[uOffset + idx2 + 1] = y;
1059
- idx1 += 3;
1060
- idx2 += 2;
1061
- j++;
958
+ this._w = (m21 - m12) / _s3;
959
+ this._x = (m13 + m31) / _s3;
960
+ this._y = (m23 + m32) / _s3;
961
+ this._z = 0.25 * _s3;
1062
962
  }
1063
- }
1064
-
1065
- return {
1066
- flatVertices: flatVertices,
1067
- holes: holes,
1068
- points: points,
1069
- count: count,
1070
- uvs: uvs
1071
- };
1072
- }
1073
-
1074
- function validateRing(ring) {
1075
- if (!isClosedRing(ring)) {
1076
- ring.push(ring[0]);
1077
- }
1078
- }
1079
963
 
1080
- function isClosedRing(ring) {
1081
- var len = ring.length;
1082
- var _ring$ = ring[0],
1083
- x1 = _ring$[0],
1084
- y1 = _ring$[1],
1085
- _ring = ring[len - 1],
1086
- x2 = _ring[0],
1087
- y2 = _ring[1];
1088
- return x1 === x2 && y1 === y2;
1089
- }
964
+ this._onChangeCallback();
1090
965
 
1091
- function checkOptions(options) {
1092
- options.lineWidth = Math.max(0, options.lineWidth);
1093
- options.depth = Math.max(0, options.depth);
1094
- options.sideDepth = Math.max(0, options.sideDepth);
1095
- }
966
+ return this;
967
+ };
1096
968
 
1097
- function extrudePolylines(lines, options) {
1098
- options = Object.assign({}, {
1099
- depth: 2,
1100
- lineWidth: 1,
1101
- bottomStickGround: false
1102
- }, options);
1103
- checkOptions(options);
1104
- var results = lines.map(function (line) {
1105
- var result = expandLine(line, options);
1106
- result.line = line;
1107
- generateTopAndBottom(result, options);
1108
- generateSides(result, options);
1109
- result.position = new Float32Array(result.points);
1110
- result.indices = new Uint32Array(result.index);
1111
- result.uv = new Float32Array(result.uvs);
1112
- result.normal = generateNormal(result.indices, result.position);
1113
- return result;
1114
- });
1115
- var result = merge(results);
1116
- result.lines = lines;
1117
- return result;
1118
- }
1119
- function extrudeSlopes(lines, options) {
1120
- options = Object.assign({}, {
1121
- depth: 2,
1122
- lineWidth: 1,
1123
- side: 'left',
1124
- sideDepth: 0,
1125
- bottomStickGround: false
1126
- }, options);
1127
- checkOptions(options);
1128
- var _options = options,
1129
- depth = _options.depth,
1130
- side = _options.side,
1131
- sideDepth = _options.sideDepth;
1132
- var results = lines.map(function (line) {
1133
- var tempResult = expandLine(line, options);
1134
- tempResult.line = line;
1135
- var leftPoints = tempResult.leftPoints,
1136
- rightPoints = tempResult.rightPoints;
1137
- var result = {
1138
- line: line
1139
- };
1140
- var depths;
969
+ _proto.setFromUnitVectors = function setFromUnitVectors(vFrom, vTo) {
970
+ // assumes direction vectors vFrom and vTo are normalized
971
+ var r = vFrom.dot(vTo) + 1;
1141
972
 
1142
- for (var i = 0, len = line.length; i < len; i++) {
1143
- line[i][2] = line[i][2] || 0;
1144
- }
973
+ if (r < Number.EPSILON) {
974
+ // vFrom and vTo point in opposite directions
975
+ r = 0;
1145
976
 
1146
- if (side === 'left') {
1147
- result.leftPoints = leftPoints;
1148
- result.rightPoints = line;
1149
- depths = [sideDepth, depth];
977
+ if (Math.abs(vFrom.x) > Math.abs(vFrom.z)) {
978
+ this._x = -vFrom.y;
979
+ this._y = vFrom.x;
980
+ this._z = 0;
981
+ this._w = r;
982
+ } else {
983
+ this._x = 0;
984
+ this._y = -vFrom.z;
985
+ this._z = vFrom.y;
986
+ this._w = r;
987
+ }
1150
988
  } else {
1151
- result.leftPoints = line;
1152
- result.rightPoints = rightPoints;
1153
- depths = [depth, sideDepth];
989
+ // crossVectors( vFrom, vTo ); // inlined to avoid cyclic dependency on Vector3
990
+ this._x = vFrom.y * vTo.z - vFrom.z * vTo.y;
991
+ this._y = vFrom.z * vTo.x - vFrom.x * vTo.z;
992
+ this._z = vFrom.x * vTo.y - vFrom.y * vTo.x;
993
+ this._w = r;
1154
994
  }
1155
995
 
1156
- result.depths = depths;
1157
- generateTopAndBottom(result, options);
1158
- generateSides(result, options);
1159
- result.position = new Float32Array(result.points);
1160
- result.indices = new Uint32Array(result.index);
1161
- result.uv = new Float32Array(result.uvs);
1162
- result.normal = generateNormal(result.indices, result.position);
1163
- return result;
1164
- });
1165
- var result = merge(results);
1166
- result.lines = lines;
1167
- return result;
1168
- }
996
+ return this.normalize();
997
+ } // angleTo(q) {
998
+ // return 2 * Math.acos(Math.abs(clamp(this.dot(q), -1, 1)));
999
+ // }
1000
+ ;
1169
1001
 
1170
- function generateTopAndBottom(result, options) {
1171
- var bottomStickGround = options.bottomStickGround;
1172
- var z = options.depth;
1173
- var depths = result.depths;
1174
- var lz = z,
1175
- rz = z;
1002
+ _proto.rotateTowards = function rotateTowards(q, step) {
1003
+ var angle = this.angleTo(q);
1004
+ if (angle === 0) return this;
1005
+ var t = Math.min(1, step / angle);
1006
+ this.slerp(q, t);
1007
+ return this;
1008
+ };
1176
1009
 
1177
- if (depths) {
1178
- lz = depths[0];
1179
- rz = depths[1];
1180
- }
1010
+ _proto.identity = function identity() {
1011
+ return this.set(0, 0, 0, 1);
1012
+ };
1181
1013
 
1182
- var points = [],
1183
- index = [],
1184
- uvs = [];
1185
- var leftPoints = result.leftPoints,
1186
- rightPoints = result.rightPoints;
1187
- var i = 0,
1188
- len = leftPoints.length;
1014
+ _proto.invert = function invert() {
1015
+ // quaternion is assumed to have unit length
1016
+ return this.conjugate();
1017
+ };
1189
1018
 
1190
- while (i < len) {
1191
- // top left
1192
- var idx0 = i * 3;
1193
- var _leftPoints$i = leftPoints[i],
1194
- x1 = _leftPoints$i[0],
1195
- y1 = _leftPoints$i[1],
1196
- z1 = _leftPoints$i[2];
1197
- points[idx0] = x1;
1198
- points[idx0 + 1] = y1;
1199
- points[idx0 + 2] = lz + z1; // top right
1019
+ _proto.conjugate = function conjugate() {
1020
+ this._x *= -1;
1021
+ this._y *= -1;
1022
+ this._z *= -1;
1200
1023
 
1201
- var _rightPoints$i = rightPoints[i],
1202
- x2 = _rightPoints$i[0],
1203
- y2 = _rightPoints$i[1],
1204
- z2 = _rightPoints$i[2];
1205
- var idx1 = len * 3 + idx0;
1206
- points[idx1] = x2;
1207
- points[idx1 + 1] = y2;
1208
- points[idx1 + 2] = rz + z2; // bottom left
1024
+ this._onChangeCallback();
1209
1025
 
1210
- var idx2 = len * 2 * 3 + idx0;
1211
- points[idx2] = x1;
1212
- points[idx2 + 1] = y1;
1213
- points[idx2 + 2] = z1;
1026
+ return this;
1027
+ };
1214
1028
 
1215
- if (bottomStickGround) {
1216
- points[idx2 + 2] = 0;
1217
- } // bottom right
1029
+ _proto.dot = function dot(v) {
1030
+ return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
1031
+ };
1218
1032
 
1033
+ _proto.lengthSq = function lengthSq() {
1034
+ return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
1035
+ };
1219
1036
 
1220
- var idx3 = len * 2 * 3 + len * 3 + idx0;
1221
- points[idx3] = x2;
1222
- points[idx3 + 1] = y2;
1223
- points[idx3 + 2] = z2;
1037
+ _proto.length = function length() {
1038
+ return Math.sqrt(this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w);
1039
+ };
1224
1040
 
1225
- if (bottomStickGround) {
1226
- points[idx3 + 2] = 0;
1041
+ _proto.normalize = function normalize() {
1042
+ var l = this.length();
1043
+
1044
+ if (l === 0) {
1045
+ this._x = 0;
1046
+ this._y = 0;
1047
+ this._z = 0;
1048
+ this._w = 1;
1049
+ } else {
1050
+ l = 1 / l;
1051
+ this._x = this._x * l;
1052
+ this._y = this._y * l;
1053
+ this._z = this._z * l;
1054
+ this._w = this._w * l;
1227
1055
  }
1228
1056
 
1229
- i++;
1230
- }
1057
+ this._onChangeCallback();
1231
1058
 
1232
- i = 0;
1233
- len = points.length;
1059
+ return this;
1060
+ };
1234
1061
 
1235
- while (i < len) {
1236
- var x = points[i],
1237
- y = points[i + 1];
1238
- uvs.push(x, y);
1239
- i += 3;
1240
- }
1062
+ _proto.multiply = function multiply(q) {
1063
+ return this.multiplyQuaternions(this, q);
1064
+ };
1241
1065
 
1242
- i = 0;
1243
- len = leftPoints.length;
1066
+ _proto.premultiply = function premultiply(q) {
1067
+ return this.multiplyQuaternions(q, this);
1068
+ };
1244
1069
 
1245
- while (i < len - 1) {
1246
- // top
1247
- // left1 left2 right1,right2
1248
- var a1 = i,
1249
- b1 = i + 1,
1250
- c1 = a1 + len,
1251
- d1 = b1 + len;
1252
- index.push(a1, c1, b1);
1253
- index.push(c1, d1, b1); // bottom
1254
- // left1 left2 right1,right2
1070
+ _proto.multiplyQuaternions = function multiplyQuaternions(a, b) {
1071
+ // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
1072
+ var qax = a._x,
1073
+ qay = a._y,
1074
+ qaz = a._z,
1075
+ qaw = a._w;
1076
+ var qbx = b._x,
1077
+ qby = b._y,
1078
+ qbz = b._z,
1079
+ qbw = b._w;
1080
+ this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
1081
+ this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
1082
+ this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
1083
+ this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
1255
1084
 
1256
- var len2 = len * 2;
1257
- var a2 = i + len2,
1258
- b2 = a2 + 1,
1259
- c2 = a2 + len,
1260
- d2 = b2 + len;
1261
- index.push(a2, c2, b2);
1262
- index.push(c2, d2, b2);
1263
- i++;
1264
- }
1085
+ this._onChangeCallback();
1265
1086
 
1266
- result.index = index;
1267
- result.points = points;
1268
- result.uvs = uvs;
1087
+ return this;
1088
+ };
1269
1089
 
1270
- if (depths) {
1271
- len = leftPoints.length;
1272
- i = 0;
1090
+ _proto.slerp = function slerp(qb, t) {
1091
+ if (t === 0) return this;
1092
+ if (t === 1) return this.copy(qb);
1093
+ var x = this._x,
1094
+ y = this._y,
1095
+ z = this._z,
1096
+ w = this._w; // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
1273
1097
 
1274
- while (i < len) {
1275
- leftPoints[i].depth = lz;
1276
- rightPoints[i].depth = rz;
1277
- i++;
1098
+ var cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
1099
+
1100
+ if (cosHalfTheta < 0) {
1101
+ this._w = -qb._w;
1102
+ this._x = -qb._x;
1103
+ this._y = -qb._y;
1104
+ this._z = -qb._z;
1105
+ cosHalfTheta = -cosHalfTheta;
1106
+ } else {
1107
+ this.copy(qb);
1278
1108
  }
1279
- }
1280
- }
1281
1109
 
1282
- function generateSides(result, options) {
1283
- var points = result.points,
1284
- index = result.index,
1285
- leftPoints = result.leftPoints,
1286
- rightPoints = result.rightPoints,
1287
- uvs = result.uvs;
1288
- var z = options.depth;
1289
- var bottomStickGround = options.bottomStickGround;
1290
- var rings = [leftPoints, rightPoints];
1291
- var depthsEnable = result.depths;
1110
+ if (cosHalfTheta >= 1.0) {
1111
+ this._w = w;
1112
+ this._x = x;
1113
+ this._y = y;
1114
+ this._z = z;
1115
+ return this;
1116
+ }
1292
1117
 
1293
- function addOneSideIndex(v1, v2) {
1294
- var idx = points.length / 3;
1295
- var pIndex = points.length - 1; // top
1118
+ var sqrSinHalfTheta = 1.0 - cosHalfTheta * cosHalfTheta;
1296
1119
 
1297
- points[++pIndex] = v1[0];
1298
- points[++pIndex] = v1[1];
1299
- points[++pIndex] = (depthsEnable ? v1.depth : z) + v1[2];
1300
- points[++pIndex] = v2[0];
1301
- points[++pIndex] = v2[1];
1302
- points[++pIndex] = (depthsEnable ? v2.depth : z) + v2[2]; // points.push(v1[0], v1[1], (depthsEnable ? v1.depth : z) + v1[2], v2[0], v2[1], (depthsEnable ? v2.depth : z) + v2[2]);
1303
- // bottom
1120
+ if (sqrSinHalfTheta <= Number.EPSILON) {
1121
+ var s = 1 - t;
1122
+ this._w = s * w + t * this._w;
1123
+ this._x = s * x + t * this._x;
1124
+ this._y = s * y + t * this._y;
1125
+ this._z = s * z + t * this._z;
1126
+ this.normalize(); // normalize calls _onChangeCallback()
1304
1127
 
1305
- points[++pIndex] = v1[0];
1306
- points[++pIndex] = v1[1];
1307
- points[++pIndex] = bottomStickGround ? 0 : v1[2];
1308
- points[++pIndex] = v2[0];
1309
- points[++pIndex] = v2[1];
1310
- points[++pIndex] = bottomStickGround ? 0 : v2[2]; // points.push(v1[0], v1[1], v1[2], v2[0], v2[1], v2[2]);
1128
+ return this;
1129
+ }
1311
1130
 
1312
- var a = idx + 2,
1313
- b = idx + 3,
1314
- c = idx,
1315
- d = idx + 1;
1316
- index.push(a, c, b, c, d, b);
1317
- generateSideWallUV(uvs, points, a, b, c, d);
1318
- }
1131
+ var sinHalfTheta = Math.sqrt(sqrSinHalfTheta);
1132
+ var halfTheta = Math.atan2(sinHalfTheta, cosHalfTheta);
1133
+ var ratioA = Math.sin((1 - t) * halfTheta) / sinHalfTheta,
1134
+ ratioB = Math.sin(t * halfTheta) / sinHalfTheta;
1135
+ this._w = w * ratioA + this._w * ratioB;
1136
+ this._x = x * ratioA + this._x * ratioB;
1137
+ this._y = y * ratioA + this._y * ratioB;
1138
+ this._z = z * ratioA + this._z * ratioB;
1319
1139
 
1320
- for (var i = 0, _len = rings.length; i < _len; i++) {
1321
- var ring = rings[i];
1140
+ this._onChangeCallback();
1322
1141
 
1323
- if (i > 0) {
1324
- ring = ring.map(function (p) {
1325
- return p;
1326
- });
1327
- ring = ring.reverse();
1328
- }
1142
+ return this;
1143
+ };
1329
1144
 
1330
- var j = 0;
1331
- var len1 = ring.length - 1;
1145
+ _proto.slerpQuaternions = function slerpQuaternions(qa, qb, t) {
1146
+ return this.copy(qa).slerp(qb, t);
1147
+ };
1332
1148
 
1333
- while (j < len1) {
1334
- var v1 = ring[j];
1335
- var v2 = ring[j + 1];
1336
- addOneSideIndex(v1, v2);
1337
- j++;
1338
- }
1339
- }
1149
+ _proto.random = function random() {
1150
+ // sets this quaternion to a uniform random unit quaternnion
1151
+ // Ken Shoemake
1152
+ // Uniform random rotations
1153
+ // D. Kirk, editor, Graphics Gems III, pages 124-132. Academic Press, New York, 1992.
1154
+ var theta1 = 2 * Math.PI * Math.random();
1155
+ var theta2 = 2 * Math.PI * Math.random();
1156
+ var x0 = Math.random();
1157
+ var r1 = Math.sqrt(1 - x0);
1158
+ var r2 = Math.sqrt(x0);
1159
+ return this.set(r1 * Math.sin(theta1), r1 * Math.cos(theta1), r2 * Math.sin(theta2), r2 * Math.cos(theta2));
1160
+ };
1340
1161
 
1341
- var len = leftPoints.length;
1342
- var vs = [rightPoints[0], leftPoints[0], leftPoints[len - 1], rightPoints[len - 1]];
1162
+ _proto.equals = function equals(quaternion) {
1163
+ return quaternion._x === this._x && quaternion._y === this._y && quaternion._z === this._z && quaternion._w === this._w;
1164
+ };
1343
1165
 
1344
- for (var _i = 0; _i < vs.length; _i += 2) {
1345
- var _v = vs[_i],
1346
- _v2 = vs[_i + 1];
1347
- addOneSideIndex(_v, _v2);
1348
- }
1349
- }
1166
+ _proto.fromArray = function fromArray(array, offset) {
1167
+ if (offset === void 0) {
1168
+ offset = 0;
1169
+ }
1350
1170
 
1351
- var TEMPV1 = {
1352
- x: 0,
1353
- y: 0
1354
- },
1355
- TEMPV2 = {
1356
- x: 0,
1357
- y: 0
1358
- };
1359
- function expandLine(line, options) {
1360
- // let preAngle = 0;
1361
- var radius = options.lineWidth / 2;
1362
- var points = [],
1363
- leftPoints = [],
1364
- rightPoints = [];
1365
- var len = line.length;
1366
- var i = 0;
1171
+ this._x = array[offset];
1172
+ this._y = array[offset + 1];
1173
+ this._z = array[offset + 2];
1174
+ this._w = array[offset + 3];
1367
1175
 
1368
- while (i < len) {
1369
- var p1 = line[i],
1370
- p2 = line[i + 1];
1371
- var currentp = line[i]; // last vertex
1176
+ this._onChangeCallback();
1372
1177
 
1373
- if (i === len - 1) {
1374
- p1 = line[len - 2];
1375
- p2 = line[len - 1];
1376
- }
1178
+ return this;
1179
+ };
1377
1180
 
1378
- var dy = p2[1] - p1[1],
1379
- dx = p2[0] - p1[0];
1380
- var rAngle = 0;
1381
- var rad = Math.atan(dy / dx);
1382
- var angle = radToDeg(rad); // preAngle = angle;
1181
+ _proto.toArray = function toArray(array, offset) {
1182
+ if (array === void 0) {
1183
+ array = [];
1184
+ }
1383
1185
 
1384
- if (i === 0 || i === len - 1) {
1385
- rAngle = angle;
1386
- rAngle -= 90;
1387
- } else {
1388
- // 至少3个顶点才会触发
1389
- var p0 = line[i - 1];
1390
- TEMPV1.x = p0[0] - p1[0];
1391
- TEMPV1.y = p0[1] - p1[1];
1392
- TEMPV2.x = p2[0] - p1[0];
1393
- TEMPV2.y = p2[1] - p1[1];
1394
- var vAngle = getAngle(TEMPV1, TEMPV2);
1395
- rAngle = angle - vAngle / 2;
1186
+ if (offset === void 0) {
1187
+ offset = 0;
1396
1188
  }
1397
1189
 
1398
- var rRad = degToRad(rAngle);
1399
- var p3 = currentp;
1400
- var x = Math.cos(rRad) + p3[0],
1401
- y = Math.sin(rRad) + p3[1];
1402
- var p4 = [x, y];
1190
+ array[offset] = this._x;
1191
+ array[offset + 1] = this._y;
1192
+ array[offset + 2] = this._z;
1193
+ array[offset + 3] = this._w;
1194
+ return array;
1195
+ };
1403
1196
 
1404
- var _translateLine = translateLine(p1, p2, radius),
1405
- line1 = _translateLine[0],
1406
- line2 = _translateLine[1];
1197
+ _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index) {
1198
+ this._x = attribute.getX(index);
1199
+ this._y = attribute.getY(index);
1200
+ this._z = attribute.getZ(index);
1201
+ this._w = attribute.getW(index);
1407
1202
 
1408
- var op1 = lineIntersection(line1[0], line1[1], p3, p4);
1409
- var op2 = lineIntersection(line2[0], line2[1], p3, p4); // 平行,回头路
1203
+ this._onChangeCallback();
1410
1204
 
1411
- if (!op1 || !op2) {
1412
- var len1 = points.length;
1413
- var point1 = points[len1 - 2];
1414
- var point2 = points[len1 - 1];
1415
-
1416
- if (!point1 || !point2) {
1417
- continue;
1418
- }
1205
+ return this;
1206
+ };
1419
1207
 
1420
- op1 = [point1[0], point1[1]];
1421
- op2 = [point2[0], point2[1]];
1422
- }
1208
+ _proto.toJSON = function toJSON() {
1209
+ return this.toArray();
1210
+ };
1423
1211
 
1424
- op1[2] = currentp[2] || 0;
1425
- op2[2] = currentp[2] || 0; // const [op1, op2] = calOffsetPoint(rRad, radius, p1);
1212
+ _proto._onChange = function _onChange(callback) {
1213
+ this._onChangeCallback = callback;
1214
+ return this;
1215
+ } // _onChangeCallback() { }
1216
+ // * [Symbol.iterator]() {
1217
+ // yield this._x;
1218
+ // yield this._y;
1219
+ // yield this._z;
1220
+ // yield this._w;
1221
+ // }
1222
+ ;
1426
1223
 
1427
- points.push(op1, op2);
1224
+ _createClass(Quaternion, [{
1225
+ key: "x",
1226
+ get: function get() {
1227
+ return this._x;
1228
+ },
1229
+ set: function set(value) {
1230
+ this._x = value;
1428
1231
 
1429
- if (leftOnLine(op1, p1, p2)) {
1430
- leftPoints.push(op1);
1431
- rightPoints.push(op2);
1432
- } else {
1433
- leftPoints.push(op2);
1434
- rightPoints.push(op1);
1232
+ this._onChangeCallback();
1435
1233
  }
1234
+ }, {
1235
+ key: "y",
1236
+ get: function get() {
1237
+ return this._y;
1238
+ },
1239
+ set: function set(value) {
1240
+ this._y = value;
1436
1241
 
1437
- i++;
1438
- }
1439
-
1440
- return {
1441
- offsetPoints: points,
1442
- leftPoints: leftPoints,
1443
- rightPoints: rightPoints
1444
- };
1445
- } // eslint-disable-next-line no-unused-vars
1242
+ this._onChangeCallback();
1243
+ }
1244
+ }, {
1245
+ key: "z",
1246
+ get: function get() {
1247
+ return this._z;
1248
+ },
1249
+ set: function set(value) {
1250
+ this._z = value;
1446
1251
 
1447
- var getAngle = function getAngle(_ref, _ref2) {
1448
- var x1 = _ref.x,
1449
- y1 = _ref.y;
1450
- var x2 = _ref2.x,
1451
- y2 = _ref2.y;
1452
- var dot = x1 * x2 + y1 * y2;
1453
- var det = x1 * y2 - y1 * x2;
1454
- var angle = Math.atan2(det, dot) / Math.PI * 180;
1455
- return (angle + 360) % 360;
1456
- };
1252
+ this._onChangeCallback();
1253
+ }
1254
+ }, {
1255
+ key: "w",
1256
+ get: function get() {
1257
+ return this._w;
1258
+ },
1259
+ set: function set(value) {
1260
+ this._w = value;
1457
1261
 
1458
- function leftOnLine(p, p1, p2) {
1459
- var x1 = p1[0],
1460
- y1 = p1[1];
1461
- var x2 = p2[0],
1462
- y2 = p2[1];
1463
- var x = p[0],
1464
- y = p[1];
1465
- return (y1 - y2) * x + (x2 - x1) * y + x1 * y2 - x2 * y1 > 0;
1466
- }
1467
- /**
1468
- * 平移线
1469
- * @param {*} p1
1470
- * @param {*} p2
1471
- * @param {*} distance
1472
- * @returns
1473
- */
1262
+ this._onChangeCallback();
1263
+ }
1264
+ }]);
1474
1265
 
1475
- function translateLine(p1, p2, distance) {
1476
- var dy = p2[1] - p1[1],
1477
- dx = p2[0] - p1[0];
1478
- var rad = Math.atan2(dy, dx);
1479
- var rad1 = rad + Math.PI / 2;
1480
- var offsetX = Math.cos(rad1) * distance,
1481
- offsetY = Math.sin(rad1) * distance;
1482
- var tp1 = [p1[0] + offsetX, p1[1] + offsetY];
1483
- var tp2 = [p2[0] + offsetX, p2[1] + offsetY];
1484
- var rad2 = rad - Math.PI / 2;
1485
- offsetX = Math.cos(rad2) * distance;
1486
- offsetY = Math.sin(rad2) * distance;
1487
- var tp3 = [p1[0] + offsetX, p1[1] + offsetY];
1488
- var tp4 = [p2[0] + offsetX, p2[1] + offsetY];
1489
- return [[tp1, tp2], [tp3, tp4]];
1490
- }
1491
- /**
1492
- * 直线交点
1493
- * @param {*} p1
1494
- * @param {*} p2
1495
- * @param {*} p3
1496
- * @param {*} p4
1497
- * @returns
1498
- */
1266
+ return Quaternion;
1267
+ }();
1499
1268
 
1269
+ // import * as MathUtils from './MathUtils.js';
1500
1270
 
1501
- function lineIntersection(p1, p2, p3, p4) {
1502
- var dx1 = p2[0] - p1[0],
1503
- dy1 = p2[1] - p1[1];
1504
- var dx2 = p4[0] - p3[0],
1505
- dy2 = p4[1] - p3[1];
1271
+ var _quaternion = new Quaternion();
1506
1272
 
1507
- if (dx1 === 0 && dx2 === 0) {
1508
- return null;
1509
- }
1273
+ var Vector3 = /*#__PURE__*/function () {
1274
+ function Vector3(x, y, z) {
1275
+ if (x === void 0) {
1276
+ x = 0;
1277
+ }
1510
1278
 
1511
- if (dy1 === 0 && dy2 === 0) {
1512
- return null;
1513
- }
1279
+ if (y === void 0) {
1280
+ y = 0;
1281
+ }
1514
1282
 
1515
- var k1 = dy1 / dx1;
1516
- var k2 = dy2 / dx2;
1517
- var b1 = p1[1] - k1 * p1[0];
1518
- var b2 = p3[1] - k2 * p3[0];
1519
- var x, y;
1283
+ if (z === void 0) {
1284
+ z = 0;
1285
+ }
1520
1286
 
1521
- if (dx1 === 0) {
1522
- x = p1[0];
1523
- y = k2 * x + b2;
1524
- } else if (dx2 === 0) {
1525
- x = p3[0];
1526
- y = k1 * x + b1;
1527
- } else if (dy1 === 0) {
1528
- y = p1[1];
1529
- x = (y - b2) / k2;
1530
- } else if (dy2 === 0) {
1531
- y = p3[1];
1532
- x = (y - b1) / k1;
1533
- } else {
1534
- x = (b2 - b1) / (k1 - k2);
1535
- y = k1 * x + b1;
1287
+ this.x = x;
1288
+ this.y = y;
1289
+ this.z = z;
1536
1290
  }
1537
1291
 
1538
- return [x, y];
1539
- }
1292
+ var _proto = Vector3.prototype;
1540
1293
 
1541
- function cylinder(point, options) {
1542
- if (options === void 0) {
1543
- options = {};
1544
- }
1294
+ _proto.set = function set(x, y, z) {
1295
+ if (z === undefined) z = this.z; // sprite.scale.set(x,y)
1545
1296
 
1546
- options = Object.assign({}, {
1547
- radius: 1,
1548
- height: 2,
1549
- radialSegments: 6
1550
- }, options);
1551
- var radialSegments = Math.round(Math.max(4, options.radialSegments));
1552
- var _options = options,
1553
- radius = _options.radius,
1554
- height = _options.height;
1555
- var aRad = 360 / radialSegments / 360 * Math.PI * 2;
1556
- var circlePointsLen = radialSegments + 1;
1557
- var points = new Float32Array(circlePointsLen * 3 * 2);
1558
- var centerx = point[0],
1559
- centery = point[1];
1560
- var idx = 0,
1561
- uIdx = 0;
1562
- var offset = circlePointsLen * 3,
1563
- uOffset = circlePointsLen * 2;
1564
- var indices = [],
1565
- uvs = [];
1297
+ this.x = x;
1298
+ this.y = y;
1299
+ this.z = z;
1300
+ return this;
1301
+ } // setScalar(scalar) {
1302
+ // this.x = scalar;
1303
+ // this.y = scalar;
1304
+ // this.z = scalar;
1305
+ // return this;
1306
+ // }
1307
+ // setX(x) {
1308
+ // this.x = x;
1309
+ // return this;
1310
+ // }
1311
+ // setY(y) {
1312
+ // this.y = y;
1313
+ // return this;
1314
+ // }
1315
+ // setZ(z) {
1316
+ // this.z = z;
1317
+ // return this;
1318
+ // }
1319
+ // setComponent(index, value) {
1320
+ // switch (index) {
1321
+ // case 0: this.x = value; break;
1322
+ // case 1: this.y = value; break;
1323
+ // case 2: this.z = value; break;
1324
+ // default: throw new Error('index is out of range: ' + index);
1325
+ // }
1326
+ // return this;
1327
+ // }
1328
+ // getComponent(index) {
1329
+ // switch (index) {
1330
+ // case 0: return this.x;
1331
+ // case 1: return this.y;
1332
+ // case 2: return this.z;
1333
+ // default: throw new Error('index is out of range: ' + index);
1334
+ // }
1335
+ // }
1336
+ ;
1566
1337
 
1567
- for (var i = -1; i < radialSegments; i++) {
1568
- var rad = aRad * i;
1569
- var x = Math.cos(rad) * radius + centerx,
1570
- y = Math.sin(rad) * radius + centery; // bottom vertices
1338
+ _proto.clone = function clone() {
1339
+ return new this.constructor(this.x, this.y, this.z);
1340
+ };
1571
1341
 
1572
- points[idx] = x;
1573
- points[idx + 1] = y;
1574
- points[idx + 2] = 0; // top vertices
1342
+ _proto.copy = function copy(v) {
1343
+ this.x = v.x;
1344
+ this.y = v.y;
1345
+ this.z = v.z;
1346
+ return this;
1347
+ };
1575
1348
 
1576
- points[idx + offset] = x;
1577
- points[idx + 1 + offset] = y;
1578
- points[idx + 2 + offset] = height;
1579
- var u = 0,
1580
- v = 0;
1581
- u = 0.5 + x / radius / 2;
1582
- v = 0.5 + y / radius / 2;
1583
- uvs[uIdx] = u;
1584
- uvs[uIdx + 1] = v;
1585
- uvs[uIdx + uOffset] = u;
1586
- uvs[uIdx + 1 + uOffset] = v;
1587
- idx += 3;
1588
- uIdx += 2;
1589
-
1590
- if (i > 1) {
1591
- // bottom indices
1592
- indices.push(0, i - 1, i);
1593
- }
1594
- }
1595
-
1596
- idx -= 3;
1597
- points[idx] = points[0];
1598
- points[idx + 1] = points[1];
1599
- points[idx + 2] = points[2];
1600
- var pointsLen = points.length;
1601
- points[pointsLen - 3] = points[0];
1602
- points[pointsLen - 2] = points[1];
1603
- points[pointsLen - 1] = height;
1604
- var indicesLen = indices.length; // top indices
1605
-
1606
- for (var _i = 0; _i < indicesLen; _i++) {
1607
- var index = indices[_i];
1608
- indices.push(index + circlePointsLen);
1609
- }
1610
-
1611
- var sidePoints = new Float32Array((circlePointsLen * 3 * 2 - 6) * 2);
1612
- var pIndex = -1;
1613
- idx = circlePointsLen * 2;
1614
- uIdx = 0;
1615
-
1616
- for (var _i2 = 0, len = points.length / 2; _i2 < len - 3; _i2 += 3) {
1617
- var x1 = points[_i2],
1618
- y1 = points[_i2 + 1],
1619
- x2 = points[_i2 + 3],
1620
- y2 = points[_i2 + 4];
1621
- sidePoints[++pIndex] = x1;
1622
- sidePoints[++pIndex] = y1;
1623
- sidePoints[++pIndex] = height;
1624
- sidePoints[++pIndex] = x2;
1625
- sidePoints[++pIndex] = y2;
1626
- sidePoints[++pIndex] = height;
1627
- sidePoints[++pIndex] = x1;
1628
- sidePoints[++pIndex] = y1;
1629
- sidePoints[++pIndex] = 0;
1630
- sidePoints[++pIndex] = x2;
1631
- sidePoints[++pIndex] = y2;
1632
- sidePoints[++pIndex] = 0;
1633
- var a = idx + 2,
1634
- b = idx + 3,
1635
- c = idx,
1636
- d = idx + 1; // indices.push(a, c, b, c, d, b);
1637
-
1638
- indices.push(c, a, d, a, b, d);
1639
- idx += 4;
1640
- var u1 = uIdx / circlePointsLen,
1641
- u2 = (uIdx + 1) / circlePointsLen;
1642
- uvs.push(u1, height / radius / 2, u2, height / radius / 2, u1, 0, u2, 0);
1643
- uIdx++;
1644
- }
1645
-
1646
- var position = new Float32Array(points.length + sidePoints.length);
1647
- position.set(points, 0);
1648
- position.set(sidePoints, points.length);
1649
- var normal = generateNormal(indices, position);
1650
- return {
1651
- points: points,
1652
- indices: new Uint32Array(indices),
1653
- position: position,
1654
- normal: normal,
1655
- uv: new Float32Array(uvs)
1349
+ _proto.add = function add(v) {
1350
+ this.x += v.x;
1351
+ this.y += v.y;
1352
+ this.z += v.z;
1353
+ return this;
1656
1354
  };
1657
- }
1658
-
1659
- function _regeneratorRuntime() {
1660
- /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
1661
1355
 
1662
- _regeneratorRuntime = function () {
1663
- return exports;
1356
+ _proto.addScalar = function addScalar(s) {
1357
+ this.x += s;
1358
+ this.y += s;
1359
+ this.z += s;
1360
+ return this;
1664
1361
  };
1665
1362
 
1666
- var exports = {},
1667
- Op = Object.prototype,
1668
- hasOwn = Op.hasOwnProperty,
1669
- $Symbol = "function" == typeof Symbol ? Symbol : {},
1670
- iteratorSymbol = $Symbol.iterator || "@@iterator",
1671
- asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator",
1672
- toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
1673
-
1674
- function define(obj, key, value) {
1675
- return Object.defineProperty(obj, key, {
1676
- value: value,
1677
- enumerable: !0,
1678
- configurable: !0,
1679
- writable: !0
1680
- }), obj[key];
1681
- }
1682
-
1683
- try {
1684
- define({}, "");
1685
- } catch (err) {
1686
- define = function (obj, key, value) {
1687
- return obj[key] = value;
1688
- };
1689
- }
1690
-
1691
- function wrap(innerFn, outerFn, self, tryLocsList) {
1692
- var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator,
1693
- generator = Object.create(protoGenerator.prototype),
1694
- context = new Context(tryLocsList || []);
1695
- return generator._invoke = function (innerFn, self, context) {
1696
- var state = "suspendedStart";
1697
- return function (method, arg) {
1698
- if ("executing" === state) throw new Error("Generator is already running");
1699
-
1700
- if ("completed" === state) {
1701
- if ("throw" === method) throw arg;
1702
- return doneResult();
1703
- }
1704
-
1705
- for (context.method = method, context.arg = arg;;) {
1706
- var delegate = context.delegate;
1707
-
1708
- if (delegate) {
1709
- var delegateResult = maybeInvokeDelegate(delegate, context);
1710
-
1711
- if (delegateResult) {
1712
- if (delegateResult === ContinueSentinel) continue;
1713
- return delegateResult;
1714
- }
1715
- }
1716
-
1717
- if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) {
1718
- if ("suspendedStart" === state) throw state = "completed", context.arg;
1719
- context.dispatchException(context.arg);
1720
- } else "return" === context.method && context.abrupt("return", context.arg);
1721
- state = "executing";
1722
- var record = tryCatch(innerFn, self, context);
1723
-
1724
- if ("normal" === record.type) {
1725
- if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue;
1726
- return {
1727
- value: record.arg,
1728
- done: context.done
1729
- };
1730
- }
1731
-
1732
- "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg);
1733
- }
1734
- };
1735
- }(innerFn, self, context), generator;
1736
- }
1737
-
1738
- function tryCatch(fn, obj, arg) {
1739
- try {
1740
- return {
1741
- type: "normal",
1742
- arg: fn.call(obj, arg)
1743
- };
1744
- } catch (err) {
1745
- return {
1746
- type: "throw",
1747
- arg: err
1748
- };
1749
- }
1750
- }
1751
-
1752
- exports.wrap = wrap;
1753
- var ContinueSentinel = {};
1754
-
1755
- function Generator() {}
1363
+ _proto.addVectors = function addVectors(a, b) {
1364
+ this.x = a.x + b.x;
1365
+ this.y = a.y + b.y;
1366
+ this.z = a.z + b.z;
1367
+ return this;
1368
+ };
1756
1369
 
1757
- function GeneratorFunction() {}
1370
+ _proto.addScaledVector = function addScaledVector(v, s) {
1371
+ this.x += v.x * s;
1372
+ this.y += v.y * s;
1373
+ this.z += v.z * s;
1374
+ return this;
1375
+ };
1758
1376
 
1759
- function GeneratorFunctionPrototype() {}
1377
+ _proto.sub = function sub(v) {
1378
+ this.x -= v.x;
1379
+ this.y -= v.y;
1380
+ this.z -= v.z;
1381
+ return this;
1382
+ };
1760
1383
 
1761
- var IteratorPrototype = {};
1762
- define(IteratorPrototype, iteratorSymbol, function () {
1384
+ _proto.subScalar = function subScalar(s) {
1385
+ this.x -= s;
1386
+ this.y -= s;
1387
+ this.z -= s;
1763
1388
  return this;
1764
- });
1765
- var getProto = Object.getPrototypeOf,
1766
- NativeIteratorPrototype = getProto && getProto(getProto(values([])));
1767
- NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype);
1768
- var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
1769
-
1770
- function defineIteratorMethods(prototype) {
1771
- ["next", "throw", "return"].forEach(function (method) {
1772
- define(prototype, method, function (arg) {
1773
- return this._invoke(method, arg);
1774
- });
1775
- });
1776
- }
1389
+ };
1777
1390
 
1778
- function AsyncIterator(generator, PromiseImpl) {
1779
- function invoke(method, arg, resolve, reject) {
1780
- var record = tryCatch(generator[method], generator, arg);
1781
-
1782
- if ("throw" !== record.type) {
1783
- var result = record.arg,
1784
- value = result.value;
1785
- return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
1786
- invoke("next", value, resolve, reject);
1787
- }, function (err) {
1788
- invoke("throw", err, resolve, reject);
1789
- }) : PromiseImpl.resolve(value).then(function (unwrapped) {
1790
- result.value = unwrapped, resolve(result);
1791
- }, function (error) {
1792
- return invoke("throw", error, resolve, reject);
1793
- });
1794
- }
1391
+ _proto.subVectors = function subVectors(a, b) {
1392
+ this.x = a.x - b.x;
1393
+ this.y = a.y - b.y;
1394
+ this.z = a.z - b.z;
1395
+ return this;
1396
+ };
1795
1397
 
1796
- reject(record.arg);
1797
- }
1398
+ _proto.multiply = function multiply(v) {
1399
+ this.x *= v.x;
1400
+ this.y *= v.y;
1401
+ this.z *= v.z;
1402
+ return this;
1403
+ };
1798
1404
 
1799
- var previousPromise;
1405
+ _proto.multiplyScalar = function multiplyScalar(scalar) {
1406
+ this.x *= scalar;
1407
+ this.y *= scalar;
1408
+ this.z *= scalar;
1409
+ return this;
1410
+ };
1800
1411
 
1801
- this._invoke = function (method, arg) {
1802
- function callInvokeWithMethodAndArg() {
1803
- return new PromiseImpl(function (resolve, reject) {
1804
- invoke(method, arg, resolve, reject);
1805
- });
1806
- }
1412
+ _proto.multiplyVectors = function multiplyVectors(a, b) {
1413
+ this.x = a.x * b.x;
1414
+ this.y = a.y * b.y;
1415
+ this.z = a.z * b.z;
1416
+ return this;
1417
+ } // applyEuler(euler) {
1418
+ // return this.applyQuaternion(_quaternion.setFromEuler(euler));
1419
+ // }
1420
+ ;
1807
1421
 
1808
- return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
1809
- };
1810
- }
1422
+ _proto.applyAxisAngle = function applyAxisAngle(axis, angle) {
1423
+ return this.applyQuaternion(_quaternion.setFromAxisAngle(axis, angle));
1424
+ } // applyMatrix3(m) {
1425
+ // const x = this.x, y = this.y, z = this.z;
1426
+ // const e = m.elements;
1427
+ // this.x = e[0] * x + e[3] * y + e[6] * z;
1428
+ // this.y = e[1] * x + e[4] * y + e[7] * z;
1429
+ // this.z = e[2] * x + e[5] * y + e[8] * z;
1430
+ // return this;
1431
+ // }
1432
+ // applyNormalMatrix(m) {
1433
+ // return this.applyMatrix3(m).normalize();
1434
+ // }
1435
+ ;
1811
1436
 
1812
- function maybeInvokeDelegate(delegate, context) {
1813
- var method = delegate.iterator[context.method];
1437
+ _proto.applyMatrix4 = function applyMatrix4(m) {
1438
+ var x = this.x,
1439
+ y = this.y,
1440
+ z = this.z;
1441
+ var e = m.elements;
1442
+ var w = 1 / (e[3] * x + e[7] * y + e[11] * z + e[15]);
1443
+ this.x = (e[0] * x + e[4] * y + e[8] * z + e[12]) * w;
1444
+ this.y = (e[1] * x + e[5] * y + e[9] * z + e[13]) * w;
1445
+ this.z = (e[2] * x + e[6] * y + e[10] * z + e[14]) * w;
1446
+ return this;
1447
+ };
1814
1448
 
1815
- if (undefined === method) {
1816
- if (context.delegate = null, "throw" === context.method) {
1817
- if (delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method)) return ContinueSentinel;
1818
- context.method = "throw", context.arg = new TypeError("The iterator does not provide a 'throw' method");
1819
- }
1449
+ _proto.applyQuaternion = function applyQuaternion(q) {
1450
+ var x = this.x,
1451
+ y = this.y,
1452
+ z = this.z;
1453
+ var qx = q.x,
1454
+ qy = q.y,
1455
+ qz = q.z,
1456
+ qw = q.w; // calculate quat * vector
1820
1457
 
1821
- return ContinueSentinel;
1822
- }
1458
+ var ix = qw * x + qy * z - qz * y;
1459
+ var iy = qw * y + qz * x - qx * z;
1460
+ var iz = qw * z + qx * y - qy * x;
1461
+ var iw = -qx * x - qy * y - qz * z; // calculate result * inverse quat
1823
1462
 
1824
- var record = tryCatch(method, delegate.iterator, context.arg);
1825
- if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel;
1826
- var info = record.arg;
1827
- return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel);
1828
- }
1463
+ this.x = ix * qw + iw * -qx + iy * -qz - iz * -qy;
1464
+ this.y = iy * qw + iw * -qy + iz * -qx - ix * -qz;
1465
+ this.z = iz * qw + iw * -qz + ix * -qy - iy * -qx;
1466
+ return this;
1467
+ } // project(camera) {
1468
+ // return this.applyMatrix4(camera.matrixWorldInverse).applyMatrix4(camera.projectionMatrix);
1469
+ // }
1470
+ // unproject(camera) {
1471
+ // return this.applyMatrix4(camera.projectionMatrixInverse).applyMatrix4(camera.matrixWorld);
1472
+ // }
1473
+ // transformDirection(m) {
1474
+ // // input: THREE.Matrix4 affine matrix
1475
+ // // vector interpreted as a direction
1476
+ // const x = this.x, y = this.y, z = this.z;
1477
+ // const e = m.elements;
1478
+ // this.x = e[0] * x + e[4] * y + e[8] * z;
1479
+ // this.y = e[1] * x + e[5] * y + e[9] * z;
1480
+ // this.z = e[2] * x + e[6] * y + e[10] * z;
1481
+ // return this.normalize();
1482
+ // }
1483
+ ;
1829
1484
 
1830
- function pushTryEntry(locs) {
1831
- var entry = {
1832
- tryLoc: locs[0]
1833
- };
1834
- 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry);
1835
- }
1485
+ _proto.divide = function divide(v) {
1486
+ this.x /= v.x;
1487
+ this.y /= v.y;
1488
+ this.z /= v.z;
1489
+ return this;
1490
+ };
1836
1491
 
1837
- function resetTryEntry(entry) {
1838
- var record = entry.completion || {};
1839
- record.type = "normal", delete record.arg, entry.completion = record;
1840
- }
1492
+ _proto.divideScalar = function divideScalar(scalar) {
1493
+ return this.multiplyScalar(1 / scalar);
1494
+ };
1841
1495
 
1842
- function Context(tryLocsList) {
1843
- this.tryEntries = [{
1844
- tryLoc: "root"
1845
- }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0);
1846
- }
1496
+ _proto.min = function min(v) {
1497
+ this.x = Math.min(this.x, v.x);
1498
+ this.y = Math.min(this.y, v.y);
1499
+ this.z = Math.min(this.z, v.z);
1500
+ return this;
1501
+ };
1847
1502
 
1848
- function values(iterable) {
1849
- if (iterable) {
1850
- var iteratorMethod = iterable[iteratorSymbol];
1851
- if (iteratorMethod) return iteratorMethod.call(iterable);
1852
- if ("function" == typeof iterable.next) return iterable;
1503
+ _proto.max = function max(v) {
1504
+ this.x = Math.max(this.x, v.x);
1505
+ this.y = Math.max(this.y, v.y);
1506
+ this.z = Math.max(this.z, v.z);
1507
+ return this;
1508
+ };
1853
1509
 
1854
- if (!isNaN(iterable.length)) {
1855
- var i = -1,
1856
- next = function next() {
1857
- for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next;
1510
+ _proto.clamp = function clamp(min, max) {
1511
+ // assumes min < max, componentwise
1512
+ this.x = Math.max(min.x, Math.min(max.x, this.x));
1513
+ this.y = Math.max(min.y, Math.min(max.y, this.y));
1514
+ this.z = Math.max(min.z, Math.min(max.z, this.z));
1515
+ return this;
1516
+ };
1858
1517
 
1859
- return next.value = undefined, next.done = !0, next;
1860
- };
1518
+ _proto.clampScalar = function clampScalar(minVal, maxVal) {
1519
+ this.x = Math.max(minVal, Math.min(maxVal, this.x));
1520
+ this.y = Math.max(minVal, Math.min(maxVal, this.y));
1521
+ this.z = Math.max(minVal, Math.min(maxVal, this.z));
1522
+ return this;
1523
+ };
1861
1524
 
1862
- return next.next = next;
1863
- }
1864
- }
1525
+ _proto.clampLength = function clampLength(min, max) {
1526
+ var length = this.length();
1527
+ return this.divideScalar(length || 1).multiplyScalar(Math.max(min, Math.min(max, length)));
1528
+ } // floor() {
1529
+ // this.x = Math.floor(this.x);
1530
+ // this.y = Math.floor(this.y);
1531
+ // this.z = Math.floor(this.z);
1532
+ // return this;
1533
+ // }
1534
+ // ceil() {
1535
+ // this.x = Math.ceil(this.x);
1536
+ // this.y = Math.ceil(this.y);
1537
+ // this.z = Math.ceil(this.z);
1538
+ // return this;
1539
+ // }
1540
+ // round() {
1541
+ // this.x = Math.round(this.x);
1542
+ // this.y = Math.round(this.y);
1543
+ // this.z = Math.round(this.z);
1544
+ // return this;
1545
+ // }
1546
+ // roundToZero() {
1547
+ // this.x = (this.x < 0) ? Math.ceil(this.x) : Math.floor(this.x);
1548
+ // this.y = (this.y < 0) ? Math.ceil(this.y) : Math.floor(this.y);
1549
+ // this.z = (this.z < 0) ? Math.ceil(this.z) : Math.floor(this.z);
1550
+ // return this;
1551
+ // }
1552
+ // negate() {
1553
+ // this.x = -this.x;
1554
+ // this.y = -this.y;
1555
+ // this.z = -this.z;
1556
+ // return this;
1557
+ // }
1558
+ ;
1865
1559
 
1866
- return {
1867
- next: doneResult
1868
- };
1869
- }
1560
+ _proto.dot = function dot(v) {
1561
+ return this.x * v.x + this.y * v.y + this.z * v.z;
1562
+ } // TODO lengthSquared?
1563
+ ;
1870
1564
 
1871
- function doneResult() {
1872
- return {
1873
- value: undefined,
1874
- done: !0
1875
- };
1876
- }
1565
+ _proto.lengthSq = function lengthSq() {
1566
+ return this.x * this.x + this.y * this.y + this.z * this.z;
1567
+ };
1877
1568
 
1878
- return GeneratorFunction.prototype = GeneratorFunctionPrototype, define(Gp, "constructor", GeneratorFunctionPrototype), define(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) {
1879
- var ctor = "function" == typeof genFun && genFun.constructor;
1880
- return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name));
1881
- }, exports.mark = function (genFun) {
1882
- return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun;
1883
- }, exports.awrap = function (arg) {
1884
- return {
1885
- __await: arg
1886
- };
1887
- }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
1569
+ _proto.length = function length() {
1570
+ return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
1571
+ } // manhattanLength() {
1572
+ // return Math.abs(this.x) + Math.abs(this.y) + Math.abs(this.z);
1573
+ // }
1574
+ ;
1575
+
1576
+ _proto.normalize = function normalize() {
1577
+ return this.divideScalar(this.length() || 1);
1578
+ };
1579
+
1580
+ _proto.setLength = function setLength(length) {
1581
+ return this.normalize().multiplyScalar(length);
1582
+ };
1583
+
1584
+ _proto.lerp = function lerp(v, alpha) {
1585
+ this.x += (v.x - this.x) * alpha;
1586
+ this.y += (v.y - this.y) * alpha;
1587
+ this.z += (v.z - this.z) * alpha;
1888
1588
  return this;
1889
- }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
1890
- void 0 === PromiseImpl && (PromiseImpl = Promise);
1891
- var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
1892
- return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) {
1893
- return result.done ? result.value : iter.next();
1894
- });
1895
- }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () {
1589
+ };
1590
+
1591
+ _proto.lerpVectors = function lerpVectors(v1, v2, alpha) {
1592
+ this.x = v1.x + (v2.x - v1.x) * alpha;
1593
+ this.y = v1.y + (v2.y - v1.y) * alpha;
1594
+ this.z = v1.z + (v2.z - v1.z) * alpha;
1896
1595
  return this;
1897
- }), define(Gp, "toString", function () {
1898
- return "[object Generator]";
1899
- }), exports.keys = function (object) {
1900
- var keys = [];
1596
+ };
1901
1597
 
1902
- for (var key in object) keys.push(key);
1598
+ _proto.cross = function cross(v) {
1599
+ return this.crossVectors(this, v);
1600
+ };
1903
1601
 
1904
- return keys.reverse(), function next() {
1905
- for (; keys.length;) {
1906
- var key = keys.pop();
1907
- if (key in object) return next.value = key, next.done = !1, next;
1908
- }
1602
+ _proto.crossVectors = function crossVectors(a, b) {
1603
+ var ax = a.x,
1604
+ ay = a.y,
1605
+ az = a.z;
1606
+ var bx = b.x,
1607
+ by = b.y,
1608
+ bz = b.z;
1609
+ this.x = ay * bz - az * by;
1610
+ this.y = az * bx - ax * bz;
1611
+ this.z = ax * by - ay * bx;
1612
+ return this;
1613
+ } // projectOnVector(v) {
1614
+ // const denominator = v.lengthSq();
1615
+ // if (denominator === 0) return this.set(0, 0, 0);
1616
+ // const scalar = v.dot(this) / denominator;
1617
+ // return this.copy(v).multiplyScalar(scalar);
1618
+ // }
1619
+ // projectOnPlane(planeNormal) {
1620
+ // _vector.copy(this).projectOnVector(planeNormal);
1621
+ // return this.sub(_vector);
1622
+ // }
1623
+ // reflect(normal) {
1624
+ // // reflect incident vector off plane orthogonal to normal
1625
+ // // normal is assumed to have unit length
1626
+ // return this.sub(_vector.copy(normal).multiplyScalar(2 * this.dot(normal)));
1627
+ // }
1628
+ // angleTo(v) {
1629
+ // const denominator = Math.sqrt(this.lengthSq() * v.lengthSq());
1630
+ // if (denominator === 0) return Math.PI / 2;
1631
+ // const theta = this.dot(v) / denominator;
1632
+ // // clamp, to handle numerical problems
1633
+ // return Math.acos(MathUtils.clamp(theta, -1, 1));
1634
+ // }
1635
+ ;
1909
1636
 
1910
- return next.done = !0, next;
1911
- };
1912
- }, exports.values = values, Context.prototype = {
1913
- constructor: Context,
1914
- reset: function (skipTempReset) {
1915
- if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined);
1916
- },
1917
- stop: function () {
1918
- this.done = !0;
1919
- var rootRecord = this.tryEntries[0].completion;
1920
- if ("throw" === rootRecord.type) throw rootRecord.arg;
1921
- return this.rval;
1922
- },
1923
- dispatchException: function (exception) {
1924
- if (this.done) throw exception;
1925
- var context = this;
1637
+ _proto.distanceTo = function distanceTo(v) {
1638
+ return Math.sqrt(this.distanceToSquared(v));
1639
+ } // distanceToSquared(v) {
1640
+ // const dx = this.x - v.x, dy = this.y - v.y, dz = this.z - v.z;
1641
+ // return dx * dx + dy * dy + dz * dz;
1642
+ // }
1643
+ // manhattanDistanceTo(v) {
1644
+ // return Math.abs(this.x - v.x) + Math.abs(this.y - v.y) + Math.abs(this.z - v.z);
1645
+ // }
1646
+ // setFromSpherical(s) {
1647
+ // return this.setFromSphericalCoords(s.radius, s.phi, s.theta);
1648
+ // }
1649
+ // setFromSphericalCoords(radius, phi, theta) {
1650
+ // const sinPhiRadius = Math.sin(phi) * radius;
1651
+ // this.x = sinPhiRadius * Math.sin(theta);
1652
+ // this.y = Math.cos(phi) * radius;
1653
+ // this.z = sinPhiRadius * Math.cos(theta);
1654
+ // return this;
1655
+ // }
1656
+ // setFromCylindrical(c) {
1657
+ // return this.setFromCylindricalCoords(c.radius, c.theta, c.y);
1658
+ // }
1659
+ // setFromCylindricalCoords(radius, theta, y) {
1660
+ // this.x = radius * Math.sin(theta);
1661
+ // this.y = y;
1662
+ // this.z = radius * Math.cos(theta);
1663
+ // return this;
1664
+ // }
1665
+ // setFromMatrixPosition(m) {
1666
+ // const e = m.elements;
1667
+ // this.x = e[12];
1668
+ // this.y = e[13];
1669
+ // this.z = e[14];
1670
+ // return this;
1671
+ // }
1672
+ // setFromMatrixScale(m) {
1673
+ // const sx = this.setFromMatrixColumn(m, 0).length();
1674
+ // const sy = this.setFromMatrixColumn(m, 1).length();
1675
+ // const sz = this.setFromMatrixColumn(m, 2).length();
1676
+ // this.x = sx;
1677
+ // this.y = sy;
1678
+ // this.z = sz;
1679
+ // return this;
1680
+ // }
1681
+ // setFromMatrixColumn(m, index) {
1682
+ // return this.fromArray(m.elements, index * 4);
1683
+ // }
1684
+ // setFromMatrix3Column(m, index) {
1685
+ // return this.fromArray(m.elements, index * 3);
1686
+ // }
1687
+ // setFromEuler(e) {
1688
+ // this.x = e._x;
1689
+ // this.y = e._y;
1690
+ // this.z = e._z;
1691
+ // return this;
1692
+ // }
1693
+ // setFromColor(c) {
1694
+ // this.x = c.r;
1695
+ // this.y = c.g;
1696
+ // this.z = c.b;
1697
+ // return this;
1698
+ // }
1699
+ ;
1926
1700
 
1927
- function handle(loc, caught) {
1928
- return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught;
1929
- }
1701
+ _proto.equals = function equals(v) {
1702
+ return v.x === this.x && v.y === this.y && v.z === this.z;
1703
+ };
1930
1704
 
1931
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
1932
- var entry = this.tryEntries[i],
1933
- record = entry.completion;
1934
- if ("root" === entry.tryLoc) return handle("end");
1935
-
1936
- if (entry.tryLoc <= this.prev) {
1937
- var hasCatch = hasOwn.call(entry, "catchLoc"),
1938
- hasFinally = hasOwn.call(entry, "finallyLoc");
1939
-
1940
- if (hasCatch && hasFinally) {
1941
- if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
1942
- if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
1943
- } else if (hasCatch) {
1944
- if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
1945
- } else {
1946
- if (!hasFinally) throw new Error("try statement without catch or finally");
1947
- if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
1948
- }
1949
- }
1950
- }
1951
- },
1952
- abrupt: function (type, arg) {
1953
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
1954
- var entry = this.tryEntries[i];
1705
+ _proto.fromArray = function fromArray(array, offset) {
1706
+ if (offset === void 0) {
1707
+ offset = 0;
1708
+ }
1955
1709
 
1956
- if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
1957
- var finallyEntry = entry;
1958
- break;
1959
- }
1960
- }
1710
+ this.x = array[offset];
1711
+ this.y = array[offset + 1];
1712
+ this.z = array[offset + 2];
1713
+ return this;
1714
+ } // toArray(array = [], offset = 0) {
1715
+ // array[offset] = this.x;
1716
+ // array[offset + 1] = this.y;
1717
+ // array[offset + 2] = this.z;
1718
+ // return array;
1719
+ // }
1720
+ // fromBufferAttribute(attribute, index) {
1721
+ // this.x = attribute.getX(index);
1722
+ // this.y = attribute.getY(index);
1723
+ // this.z = attribute.getZ(index);
1724
+ // return this;
1725
+ // }
1726
+ ;
1961
1727
 
1962
- finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null);
1963
- var record = finallyEntry ? finallyEntry.completion : {};
1964
- return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record);
1965
- },
1966
- complete: function (record, afterLoc) {
1967
- if ("throw" === record.type) throw record.arg;
1968
- return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel;
1969
- },
1970
- finish: function (finallyLoc) {
1971
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
1972
- var entry = this.tryEntries[i];
1973
- if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel;
1974
- }
1975
- },
1976
- catch: function (tryLoc) {
1977
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
1978
- var entry = this.tryEntries[i];
1728
+ _proto.random = function random() {
1729
+ this.x = Math.random();
1730
+ this.y = Math.random();
1731
+ this.z = Math.random();
1732
+ return this;
1733
+ } // randomDirection() {
1734
+ // // Derived from https://mathworld.wolfram.com/SpherePointPicking.html
1735
+ // const u = (Math.random() - 0.5) * 2;
1736
+ // const t = Math.random() * Math.PI * 2;
1737
+ // const f = Math.sqrt(1 - u ** 2);
1738
+ // this.x = f * Math.cos(t);
1739
+ // this.y = f * Math.sin(t);
1740
+ // this.z = u;
1741
+ // return this;
1742
+ // }
1743
+ ;
1979
1744
 
1980
- if (entry.tryLoc === tryLoc) {
1981
- var record = entry.completion;
1745
+ return Vector3;
1746
+ }();
1982
1747
 
1983
- if ("throw" === record.type) {
1984
- var thrown = record.arg;
1985
- resetTryEntry(entry);
1986
- }
1748
+ /**
1749
+ * https://github.com/Turfjs/turf/blob/master/packages/turf-boolean-clockwise/index.ts
1750
+ * @param {*} ring
1751
+ * @returns
1752
+ */
1987
1753
 
1988
- return thrown;
1989
- }
1990
- }
1754
+ function isClockwise(ring) {
1755
+ var sum = 0;
1756
+ var i = 1;
1757
+ var prev;
1758
+ var cur;
1759
+ var len = ring.length;
1991
1760
 
1992
- throw new Error("illegal catch attempt");
1993
- },
1994
- delegateYield: function (iterable, resultName, nextLoc) {
1995
- return this.delegate = {
1996
- iterator: values(iterable),
1997
- resultName: resultName,
1998
- nextLoc: nextLoc
1999
- }, "next" === this.method && (this.arg = undefined), ContinueSentinel;
2000
- }
2001
- }, exports;
1761
+ while (i < len) {
1762
+ prev = cur || ring[0];
1763
+ cur = ring[i];
1764
+ sum += (cur[0] - prev[0]) * (cur[1] + prev[1]);
1765
+ i++;
1766
+ }
1767
+
1768
+ return sum > 0;
2002
1769
  }
2003
1770
 
2004
- function _defineProperties(target, props) {
2005
- for (var i = 0; i < props.length; i++) {
2006
- var descriptor = props[i];
2007
- descriptor.enumerable = descriptor.enumerable || false;
2008
- descriptor.configurable = true;
2009
- if ("value" in descriptor) descriptor.writable = true;
2010
- Object.defineProperty(target, descriptor.key, descriptor);
2011
- }
2012
- }
2013
-
2014
- function _createClass(Constructor, protoProps, staticProps) {
2015
- if (protoProps) _defineProperties(Constructor.prototype, protoProps);
2016
- if (staticProps) _defineProperties(Constructor, staticProps);
2017
- Object.defineProperty(Constructor, "prototype", {
2018
- writable: false
2019
- });
2020
- return Constructor;
1771
+ function v3Sub(out, v1, v2) {
1772
+ out[0] = v1[0] - v2[0];
1773
+ out[1] = v1[1] - v2[1];
1774
+ out[2] = v1[2] - v2[2];
1775
+ return out;
2021
1776
  }
2022
1777
 
2023
- function _inheritsLoose(subClass, superClass) {
2024
- subClass.prototype = Object.create(superClass.prototype);
2025
- subClass.prototype.constructor = subClass;
2026
-
2027
- _setPrototypeOf(subClass, superClass);
1778
+ function v3Normalize(out, v) {
1779
+ var x = v[0];
1780
+ var y = v[1];
1781
+ var z = v[2];
1782
+ var d = Math.sqrt(x * x + y * y + z * z) || 1;
1783
+ out[0] = x / d;
1784
+ out[1] = y / d;
1785
+ out[2] = z / d;
1786
+ return out;
2028
1787
  }
2029
1788
 
2030
- function _setPrototypeOf(o, p) {
2031
- _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
2032
- o.__proto__ = p;
2033
- return o;
2034
- };
2035
- return _setPrototypeOf(o, p);
1789
+ function v3Cross(out, v1, v2) {
1790
+ var ax = v1[0],
1791
+ ay = v1[1],
1792
+ az = v1[2],
1793
+ bx = v2[0],
1794
+ by = v2[1],
1795
+ bz = v2[2];
1796
+ out[0] = ay * bz - az * by;
1797
+ out[1] = az * bx - ax * bz;
1798
+ out[2] = ax * by - ay * bx;
1799
+ return out;
2036
1800
  }
2037
1801
 
2038
- // code copy from https://github.com/mrdoob/three.js/blob/dev/src/math/Quaternion.js
2039
- // import { clamp } from './MathUtils.js';
2040
- var Quaternion = /*#__PURE__*/function (_Symbol$iterator) {
2041
- function Quaternion(x, y, z, w) {
2042
- if (x === void 0) {
2043
- x = 0;
2044
- }
1802
+ function generateNormal(indices, position) {
1803
+ function v3Set(p, a, b, c) {
1804
+ p[0] = a;
1805
+ p[1] = b;
1806
+ p[2] = c;
1807
+ }
2045
1808
 
2046
- if (y === void 0) {
2047
- y = 0;
2048
- }
1809
+ var p1 = [];
1810
+ var p2 = [];
1811
+ var p3 = [];
1812
+ var v21 = [];
1813
+ var v32 = [];
1814
+ var n = [];
1815
+ var len = indices.length;
1816
+ var normals = new Float32Array(position.length);
1817
+ var f = 0;
2049
1818
 
2050
- if (z === void 0) {
2051
- z = 0;
2052
- }
1819
+ while (f < len) {
1820
+ // const i1 = indices[f++] * 3;
1821
+ // const i2 = indices[f++] * 3;
1822
+ // const i3 = indices[f++] * 3;
1823
+ // const i1 = indices[f];
1824
+ // const i2 = indices[f + 1];
1825
+ // const i3 = indices[f + 2];
1826
+ var a = indices[f],
1827
+ b = indices[f + 1],
1828
+ c = indices[f + 2];
1829
+ var i1 = a * 3,
1830
+ i2 = b * 3,
1831
+ i3 = c * 3;
1832
+ v3Set(p1, position[i1], position[i1 + 1], position[i1 + 2]);
1833
+ v3Set(p2, position[i2], position[i2 + 1], position[i2 + 2]);
1834
+ v3Set(p3, position[i3], position[i3 + 1], position[i3 + 2]);
1835
+ v3Sub(v32, p3, p2);
1836
+ v3Sub(v21, p1, p2);
1837
+ v3Cross(n, v32, v21); // Already be weighted by the triangle area
2053
1838
 
2054
- if (w === void 0) {
2055
- w = 1;
1839
+ for (var _i = 0; _i < 3; _i++) {
1840
+ normals[i1 + _i] += n[_i];
1841
+ normals[i2 + _i] += n[_i];
1842
+ normals[i3 + _i] += n[_i];
2056
1843
  }
2057
1844
 
2058
- this.isQuaternion = true;
2059
- this._x = x;
2060
- this._y = y;
2061
- this._z = z;
2062
- this._w = w;
1845
+ f += 3;
2063
1846
  }
2064
1847
 
2065
- Quaternion.slerpFlat = function slerpFlat(dst, dstOffset, src0, srcOffset0, src1, srcOffset1, t) {
2066
- // fuzz-free, array-based Quaternion SLERP operation
2067
- var x0 = src0[srcOffset0 + 0],
2068
- y0 = src0[srcOffset0 + 1],
2069
- z0 = src0[srcOffset0 + 2],
2070
- w0 = src0[srcOffset0 + 3];
2071
- var x1 = src1[srcOffset1 + 0],
2072
- y1 = src1[srcOffset1 + 1],
2073
- z1 = src1[srcOffset1 + 2],
2074
- w1 = src1[srcOffset1 + 3];
2075
-
2076
- if (t === 0) {
2077
- dst[dstOffset + 0] = x0;
2078
- dst[dstOffset + 1] = y0;
2079
- dst[dstOffset + 2] = z0;
2080
- dst[dstOffset + 3] = w0;
2081
- return;
2082
- }
2083
-
2084
- if (t === 1) {
2085
- dst[dstOffset + 0] = x1;
2086
- dst[dstOffset + 1] = y1;
2087
- dst[dstOffset + 2] = z1;
2088
- dst[dstOffset + 3] = w1;
2089
- return;
2090
- }
2091
-
2092
- if (w0 !== w1 || x0 !== x1 || y0 !== y1 || z0 !== z1) {
2093
- var s = 1 - t;
2094
- var cos = x0 * x1 + y0 * y1 + z0 * z1 + w0 * w1,
2095
- dir = cos >= 0 ? 1 : -1,
2096
- sqrSin = 1 - cos * cos; // Skip the Slerp for tiny steps to avoid numeric problems:
1848
+ var i = 0;
1849
+ var l = normals.length;
2097
1850
 
2098
- if (sqrSin > Number.EPSILON) {
2099
- var sin = Math.sqrt(sqrSin),
2100
- len = Math.atan2(sin, cos * dir);
2101
- s = Math.sin(s * len) / sin;
2102
- t = Math.sin(t * len) / sin;
2103
- }
1851
+ while (i < l) {
1852
+ v3Set(n, normals[i], normals[i + 1], normals[i + 2]);
1853
+ v3Normalize(n, n);
1854
+ normals[i] = n[0] || 0;
1855
+ normals[i + 1] = n[1] || 0;
1856
+ normals[i + 2] = n[2] || 0;
1857
+ i += 3;
1858
+ }
2104
1859
 
2105
- var tDir = t * dir;
2106
- x0 = x0 * s + x1 * tDir;
2107
- y0 = y0 * s + y1 * tDir;
2108
- z0 = z0 * s + z1 * tDir;
2109
- w0 = w0 * s + w1 * tDir; // Normalize in case we just did a lerp:
1860
+ return normals;
1861
+ }
1862
+ function merge(results) {
1863
+ if (results.length === 1) {
1864
+ var _result = {
1865
+ position: results[0].position,
1866
+ normal: results[0].normal,
1867
+ uv: results[0].uv,
1868
+ indices: results[0].indices,
1869
+ results: results
1870
+ };
1871
+ return _result;
1872
+ }
2110
1873
 
2111
- if (s === 1 - t) {
2112
- var f = 1 / Math.sqrt(x0 * x0 + y0 * y0 + z0 * z0 + w0 * w0);
2113
- x0 *= f;
2114
- y0 *= f;
2115
- z0 *= f;
2116
- w0 *= f;
2117
- }
2118
- }
1874
+ var plen = 0,
1875
+ ilen = 0;
2119
1876
 
2120
- dst[dstOffset] = x0;
2121
- dst[dstOffset + 1] = y0;
2122
- dst[dstOffset + 2] = z0;
2123
- dst[dstOffset + 3] = w0;
2124
- };
1877
+ for (var i = 0, len = results.length; i < len; i++) {
1878
+ var _results$i = results[i],
1879
+ position = _results$i.position,
1880
+ indices = _results$i.indices;
1881
+ plen += position.length;
1882
+ ilen += indices.length;
1883
+ }
2125
1884
 
2126
- Quaternion.multiplyQuaternionsFlat = function multiplyQuaternionsFlat(dst, dstOffset, src0, srcOffset0, src1, srcOffset1) {
2127
- var x0 = src0[srcOffset0];
2128
- var y0 = src0[srcOffset0 + 1];
2129
- var z0 = src0[srcOffset0 + 2];
2130
- var w0 = src0[srcOffset0 + 3];
2131
- var x1 = src1[srcOffset1];
2132
- var y1 = src1[srcOffset1 + 1];
2133
- var z1 = src1[srcOffset1 + 2];
2134
- var w1 = src1[srcOffset1 + 3];
2135
- dst[dstOffset] = x0 * w1 + w0 * x1 + y0 * z1 - z0 * y1;
2136
- dst[dstOffset + 1] = y0 * w1 + w0 * y1 + z0 * x1 - x0 * z1;
2137
- dst[dstOffset + 2] = z0 * w1 + w0 * z1 + x0 * y1 - y0 * x1;
2138
- dst[dstOffset + 3] = w0 * w1 - x0 * x1 - y0 * y1 - z0 * z1;
2139
- return dst;
1885
+ var result = {
1886
+ position: new Float32Array(plen),
1887
+ normal: new Float32Array(plen),
1888
+ uv: new Float32Array(plen / 3 * 2),
1889
+ indices: new Uint32Array(ilen),
1890
+ results: results
2140
1891
  };
1892
+ var pOffset = 0,
1893
+ pCount = 0,
1894
+ iIdx = 0,
1895
+ uvOffset = 0;
2141
1896
 
2142
- var _proto = Quaternion.prototype;
1897
+ for (var _i2 = 0, _len = results.length; _i2 < _len; _i2++) {
1898
+ var _results$_i = results[_i2],
1899
+ _position = _results$_i.position,
1900
+ _indices = _results$_i.indices,
1901
+ normal = _results$_i.normal,
1902
+ uv = _results$_i.uv;
1903
+ result.position.set(_position, pOffset);
1904
+ result.normal.set(normal, pOffset);
1905
+ result.uv.set(uv, uvOffset);
1906
+ var j = 0;
1907
+ var len1 = _indices.length;
2143
1908
 
2144
- _proto.set = function set(x, y, z, w) {
2145
- this._x = x;
2146
- this._y = y;
2147
- this._z = z;
2148
- this._w = w;
1909
+ while (j < len1) {
1910
+ var pIndex = _indices[j] + pCount;
1911
+ result.indices[iIdx] = pIndex;
1912
+ iIdx++;
1913
+ j++;
1914
+ }
2149
1915
 
2150
- this._onChangeCallback();
1916
+ uvOffset += uv.length;
1917
+ pOffset += _position.length;
1918
+ pCount += _position.length / 3;
1919
+ }
2151
1920
 
2152
- return this;
2153
- };
1921
+ return result;
1922
+ }
1923
+ function radToDeg(rad) {
1924
+ return rad * 180 / Math.PI;
1925
+ }
1926
+ function degToRad(angle) {
1927
+ return angle / 180 * Math.PI;
1928
+ } // https://github.com/mrdoob/three.js/blob/16f13e3b07e31d0e9a00df7c3366bbe0e464588c/src/geometries/ExtrudeGeometry.js?_pjax=%23js-repo-pjax-container#L736
2154
1929
 
2155
- _proto.clone = function clone() {
2156
- return new this.constructor(this._x, this._y, this._z, this._w);
2157
- };
2158
-
2159
- _proto.copy = function copy(quaternion) {
2160
- this._x = quaternion.x;
2161
- this._y = quaternion.y;
2162
- this._z = quaternion.z;
2163
- this._w = quaternion.w;
2164
-
2165
- this._onChangeCallback();
2166
-
2167
- return this;
2168
- };
1930
+ function generateSideWallUV(uvs, vertices, indexA, indexB, indexC, indexD) {
1931
+ var idx1 = indexA * 3,
1932
+ idx2 = indexB * 3,
1933
+ idx3 = indexC * 3,
1934
+ idx4 = indexD * 3;
1935
+ var a_x = vertices[idx1];
1936
+ var a_y = vertices[idx1 + 1];
1937
+ var a_z = vertices[idx1 + 2];
1938
+ var b_x = vertices[idx2];
1939
+ var b_y = vertices[idx2 + 1];
1940
+ var b_z = vertices[idx2 + 2];
1941
+ var c_x = vertices[idx3];
1942
+ var c_y = vertices[idx3 + 1];
1943
+ var c_z = vertices[idx3 + 2];
1944
+ var d_x = vertices[idx4];
1945
+ var d_y = vertices[idx4 + 1];
1946
+ var d_z = vertices[idx4 + 2];
1947
+ var uIndex = uvs.length - 1;
2169
1948
 
2170
- _proto.setFromEuler = function setFromEuler(euler, update) {
2171
- if (update === void 0) {
2172
- update = true;
2173
- }
1949
+ if (Math.abs(a_y - b_y) < Math.abs(a_x - b_x)) {
1950
+ uvs[++uIndex] = a_x;
1951
+ uvs[++uIndex] = 1 - a_z;
1952
+ uvs[++uIndex] = b_x;
1953
+ uvs[++uIndex] = 1 - b_z;
1954
+ uvs[++uIndex] = c_x;
1955
+ uvs[++uIndex] = 1 - c_z;
1956
+ uvs[++uIndex] = d_x;
1957
+ uvs[++uIndex] = 1 - d_z; // uvs.push(a_x, 1 - a_z);
1958
+ // uvs.push(b_x, 1 - b_z);
1959
+ // uvs.push(c_x, 1 - c_z);
1960
+ // uvs.push(d_x, 1 - d_z);
1961
+ } else {
1962
+ uvs[++uIndex] = a_y;
1963
+ uvs[++uIndex] = 1 - a_z;
1964
+ uvs[++uIndex] = b_y;
1965
+ uvs[++uIndex] = 1 - b_z;
1966
+ uvs[++uIndex] = c_y;
1967
+ uvs[++uIndex] = 1 - c_z;
1968
+ uvs[++uIndex] = d_y;
1969
+ uvs[++uIndex] = 1 - d_z; // uvs.push(a_y, 1 - a_z);
1970
+ // uvs.push(b_y, 1 - b_z);
1971
+ // uvs.push(c_y, 1 - c_z);
1972
+ // uvs.push(d_y, 1 - d_z);
1973
+ }
1974
+ }
1975
+ function line2Vectors(line) {
1976
+ var points = [];
2174
1977
 
2175
- var x = euler._x,
2176
- y = euler._y,
2177
- z = euler._z,
2178
- order = euler._order; // http://www.mathworks.com/matlabcentral/fileexchange/
2179
- // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
2180
- // content/SpinCalc.m
1978
+ for (var i = 0, len = line.length; i < len; i++) {
1979
+ var p = line[i];
1980
+ var x = p[0],
1981
+ y = p[1],
1982
+ z = p[2];
1983
+ var v = new Vector3(x, y, z || 0);
1984
+ points[i] = v;
1985
+ }
2181
1986
 
2182
- var cos = Math.cos;
2183
- var sin = Math.sin;
2184
- var c1 = cos(x / 2);
2185
- var c2 = cos(y / 2);
2186
- var c3 = cos(z / 2);
2187
- var s1 = sin(x / 2);
2188
- var s2 = sin(y / 2);
2189
- var s3 = sin(z / 2);
1987
+ return points;
1988
+ }
2190
1989
 
2191
- switch (order) {
2192
- case 'XYZ':
2193
- this._x = s1 * c2 * c3 + c1 * s2 * s3;
2194
- this._y = c1 * s2 * c3 - s1 * c2 * s3;
2195
- this._z = c1 * c2 * s3 + s1 * s2 * c3;
2196
- this._w = c1 * c2 * c3 - s1 * s2 * s3;
2197
- break;
1990
+ function extrudePolygons(polygons, options) {
1991
+ options = Object.assign({}, {
1992
+ depth: 2
1993
+ }, options);
1994
+ var results = polygons.map(function (polygon) {
1995
+ for (var i = 0, len = polygon.length; i < len; i++) {
1996
+ var ring = polygon[i];
1997
+ validateRing(ring);
2198
1998
 
2199
- case 'YXZ':
2200
- this._x = s1 * c2 * c3 + c1 * s2 * s3;
2201
- this._y = c1 * s2 * c3 - s1 * c2 * s3;
2202
- this._z = c1 * c2 * s3 - s1 * s2 * c3;
2203
- this._w = c1 * c2 * c3 + s1 * s2 * s3;
2204
- break;
1999
+ if (i === 0) {
2000
+ if (!isClockwise(ring)) {
2001
+ polygon[i] = ring.reverse();
2002
+ }
2003
+ } else if (isClockwise(ring)) {
2004
+ polygon[i] = ring.reverse();
2005
+ }
2205
2006
 
2206
- case 'ZXY':
2207
- this._x = s1 * c2 * c3 - c1 * s2 * s3;
2208
- this._y = c1 * s2 * c3 + s1 * c2 * s3;
2209
- this._z = c1 * c2 * s3 + s1 * s2 * c3;
2210
- this._w = c1 * c2 * c3 - s1 * s2 * s3;
2211
- break;
2007
+ if (isClosedRing(ring)) {
2008
+ ring.splice(ring.length - 1, 1);
2009
+ }
2010
+ }
2212
2011
 
2213
- case 'ZYX':
2214
- this._x = s1 * c2 * c3 - c1 * s2 * s3;
2215
- this._y = c1 * s2 * c3 + s1 * c2 * s3;
2216
- this._z = c1 * c2 * s3 - s1 * s2 * c3;
2217
- this._w = c1 * c2 * c3 + s1 * s2 * s3;
2218
- break;
2012
+ var result = flatVertices(polygon, options);
2013
+ result.polygon = polygon;
2014
+ var triangles = earcut$1(result.flatVertices, result.holes, 2);
2015
+ generateTopAndBottom$1(result, triangles);
2016
+ generateSides$1(result, options);
2017
+ result.position = new Float32Array(result.points);
2018
+ result.indices = new Uint32Array(result.indices);
2019
+ result.uv = new Float32Array(result.uv);
2020
+ result.normal = generateNormal(result.indices, result.position);
2021
+ return result;
2022
+ });
2023
+ var result = merge(results);
2024
+ result.polygons = polygons;
2025
+ return result;
2026
+ }
2219
2027
 
2220
- case 'YZX':
2221
- this._x = s1 * c2 * c3 + c1 * s2 * s3;
2222
- this._y = c1 * s2 * c3 + s1 * c2 * s3;
2223
- this._z = c1 * c2 * s3 - s1 * s2 * c3;
2224
- this._w = c1 * c2 * c3 - s1 * s2 * s3;
2225
- break;
2028
+ function generateTopAndBottom$1(result, triangles) {
2029
+ var indices = [];
2030
+ var count = result.count;
2226
2031
 
2227
- case 'XZY':
2228
- this._x = s1 * c2 * c3 - c1 * s2 * s3;
2229
- this._y = c1 * s2 * c3 - s1 * c2 * s3;
2230
- this._z = c1 * c2 * s3 + s1 * s2 * c3;
2231
- this._w = c1 * c2 * c3 + s1 * s2 * s3;
2232
- break;
2032
+ for (var i = 0, len = triangles.length; i < len; i += 3) {
2033
+ // top
2034
+ var a = triangles[i],
2035
+ b = triangles[i + 1],
2036
+ c = triangles[i + 2];
2037
+ indices[i] = a;
2038
+ indices[i + 1] = b;
2039
+ indices[i + 2] = c; // bottom
2233
2040
 
2234
- default:
2235
- console.warn('THREE.Quaternion: .setFromEuler() encountered an unknown order: ' + order);
2236
- }
2041
+ var idx = len + i;
2042
+ var a1 = count + a,
2043
+ b1 = count + b,
2044
+ c1 = count + c;
2045
+ indices[idx] = a1;
2046
+ indices[idx + 1] = b1;
2047
+ indices[idx + 2] = c1;
2048
+ }
2237
2049
 
2238
- if (update === true) this._onChangeCallback();
2239
- return this;
2240
- };
2050
+ result.indices = indices;
2051
+ }
2241
2052
 
2242
- _proto.setFromAxisAngle = function setFromAxisAngle(axis, angle) {
2243
- // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
2244
- // assumes axis is normalized
2245
- var halfAngle = angle / 2,
2246
- s = Math.sin(halfAngle);
2247
- this._x = axis.x * s;
2248
- this._y = axis.y * s;
2249
- this._z = axis.z * s;
2250
- this._w = Math.cos(halfAngle);
2053
+ function generateSides$1(result, options) {
2054
+ var points = result.points,
2055
+ indices = result.indices,
2056
+ polygon = result.polygon,
2057
+ uv = result.uv;
2058
+ var depth = options.depth;
2059
+ var pIndex = points.length - 1;
2060
+ var iIndex = indices.length - 1;
2251
2061
 
2252
- this._onChangeCallback();
2062
+ for (var i = 0, len = polygon.length; i < len; i++) {
2063
+ var ring = polygon[i];
2064
+ var j = 0;
2065
+ var len1 = ring.length;
2253
2066
 
2254
- return this;
2255
- };
2067
+ while (j < len1) {
2068
+ var v1 = ring[j];
2069
+ var v2 = ring[j + 1];
2256
2070
 
2257
- _proto.setFromRotationMatrix = function setFromRotationMatrix(m) {
2258
- // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
2259
- // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
2260
- var te = m.elements,
2261
- m11 = te[0],
2262
- m12 = te[4],
2263
- m13 = te[8],
2264
- m21 = te[1],
2265
- m22 = te[5],
2266
- m23 = te[9],
2267
- m31 = te[2],
2268
- m32 = te[6],
2269
- m33 = te[10],
2270
- trace = m11 + m22 + m33;
2071
+ if (j === len1 - 1) {
2072
+ v2 = ring[0];
2073
+ }
2271
2074
 
2272
- if (trace > 0) {
2273
- var s = 0.5 / Math.sqrt(trace + 1.0);
2274
- this._w = 0.25 / s;
2275
- this._x = (m32 - m23) * s;
2276
- this._y = (m13 - m31) * s;
2277
- this._z = (m21 - m12) * s;
2278
- } else if (m11 > m22 && m11 > m33) {
2279
- var _s = 2.0 * Math.sqrt(1.0 + m11 - m22 - m33);
2075
+ var idx = points.length / 3;
2076
+ var x1 = v1[0],
2077
+ y1 = v1[1],
2078
+ z1 = v1[2] || 0,
2079
+ x2 = v2[0],
2080
+ y2 = v2[1],
2081
+ z2 = v2[2] || 0;
2082
+ points[++pIndex] = x1;
2083
+ points[++pIndex] = y1;
2084
+ points[++pIndex] = z1 + depth;
2085
+ points[++pIndex] = x2;
2086
+ points[++pIndex] = y2;
2087
+ points[++pIndex] = z2 + depth;
2088
+ points[++pIndex] = x1;
2089
+ points[++pIndex] = y1;
2090
+ points[++pIndex] = z1;
2091
+ points[++pIndex] = x2;
2092
+ points[++pIndex] = y2;
2093
+ points[++pIndex] = z2; // points.push(x1, y1, z, x2, y2, z, x1, y1, 0, x2, y2, 0);
2280
2094
 
2281
- this._w = (m32 - m23) / _s;
2282
- this._x = 0.25 * _s;
2283
- this._y = (m12 + m21) / _s;
2284
- this._z = (m13 + m31) / _s;
2285
- } else if (m22 > m33) {
2286
- var _s2 = 2.0 * Math.sqrt(1.0 + m22 - m11 - m33);
2095
+ var a = idx + 2,
2096
+ b = idx + 3,
2097
+ c = idx,
2098
+ d = idx + 1; // points.push(p3, p4, p1, p2);
2099
+ // index.push(a, c, b, c, d, b);
2287
2100
 
2288
- this._w = (m13 - m31) / _s2;
2289
- this._x = (m12 + m21) / _s2;
2290
- this._y = 0.25 * _s2;
2291
- this._z = (m23 + m32) / _s2;
2292
- } else {
2293
- var _s3 = 2.0 * Math.sqrt(1.0 + m33 - m11 - m22);
2101
+ indices[++iIndex] = a;
2102
+ indices[++iIndex] = c;
2103
+ indices[++iIndex] = b;
2104
+ indices[++iIndex] = c;
2105
+ indices[++iIndex] = d;
2106
+ indices[++iIndex] = b; // index.push(c, d, b);
2294
2107
 
2295
- this._w = (m21 - m12) / _s3;
2296
- this._x = (m13 + m31) / _s3;
2297
- this._y = (m23 + m32) / _s3;
2298
- this._z = 0.25 * _s3;
2108
+ generateSideWallUV(uv, points, a, b, c, d);
2109
+ j++;
2299
2110
  }
2111
+ }
2112
+ }
2300
2113
 
2301
- this._onChangeCallback();
2114
+ function calPolygonPointsCount(polygon) {
2115
+ var count = 0;
2116
+ var i = 0;
2117
+ var len = polygon.length;
2302
2118
 
2303
- return this;
2304
- };
2119
+ while (i < len) {
2120
+ count += polygon[i].length;
2121
+ i++;
2122
+ }
2305
2123
 
2306
- _proto.setFromUnitVectors = function setFromUnitVectors(vFrom, vTo) {
2307
- // assumes direction vectors vFrom and vTo are normalized
2308
- var r = vFrom.dot(vTo) + 1;
2124
+ return count;
2125
+ }
2309
2126
 
2310
- if (r < Number.EPSILON) {
2311
- // vFrom and vTo point in opposite directions
2312
- r = 0;
2313
-
2314
- if (Math.abs(vFrom.x) > Math.abs(vFrom.z)) {
2315
- this._x = -vFrom.y;
2316
- this._y = vFrom.x;
2317
- this._z = 0;
2318
- this._w = r;
2319
- } else {
2320
- this._x = 0;
2321
- this._y = -vFrom.z;
2322
- this._z = vFrom.y;
2323
- this._w = r;
2324
- }
2325
- } else {
2326
- // crossVectors( vFrom, vTo ); // inlined to avoid cyclic dependency on Vector3
2327
- this._x = vFrom.y * vTo.z - vFrom.z * vTo.y;
2328
- this._y = vFrom.z * vTo.x - vFrom.x * vTo.z;
2329
- this._z = vFrom.x * vTo.y - vFrom.y * vTo.x;
2330
- this._w = r;
2331
- }
2127
+ function flatVertices(polygon, options) {
2128
+ var count = calPolygonPointsCount(polygon);
2129
+ var len = polygon.length;
2130
+ var holes = [],
2131
+ flatVertices = new Float32Array(count * 2),
2132
+ points = [],
2133
+ uv = [];
2134
+ var pOffset = count * 3,
2135
+ uOffset = count * 2;
2136
+ var depth = options.depth;
2137
+ var idx0 = 0,
2138
+ idx1 = 0,
2139
+ idx2 = 0;
2332
2140
 
2333
- return this.normalize();
2334
- } // angleTo(q) {
2335
- // return 2 * Math.acos(Math.abs(clamp(this.dot(q), -1, 1)));
2336
- // }
2337
- ;
2141
+ for (var i = 0; i < len; i++) {
2142
+ var ring = polygon[i];
2338
2143
 
2339
- _proto.rotateTowards = function rotateTowards(q, step) {
2340
- var angle = this.angleTo(q);
2341
- if (angle === 0) return this;
2342
- var t = Math.min(1, step / angle);
2343
- this.slerp(q, t);
2344
- return this;
2345
- };
2144
+ if (i > 0) {
2145
+ holes.push(idx0 / 2);
2146
+ }
2346
2147
 
2347
- _proto.identity = function identity() {
2348
- return this.set(0, 0, 0, 1);
2349
- };
2148
+ var j = 0;
2149
+ var len1 = ring.length;
2350
2150
 
2351
- _proto.invert = function invert() {
2352
- // quaternion is assumed to have unit length
2353
- return this.conjugate();
2354
- };
2151
+ while (j < len1) {
2152
+ var c = ring[j];
2153
+ var x = c[0],
2154
+ y = c[1],
2155
+ z = c[2] || 0;
2156
+ flatVertices[idx0++] = x;
2157
+ flatVertices[idx0++] = y; // top vertices
2355
2158
 
2356
- _proto.conjugate = function conjugate() {
2357
- this._x *= -1;
2358
- this._y *= -1;
2359
- this._z *= -1;
2159
+ points[idx1] = x;
2160
+ points[idx1 + 1] = y;
2161
+ points[idx1 + 2] = depth + z; // bottom vertices
2360
2162
 
2361
- this._onChangeCallback();
2163
+ points[pOffset + idx1] = x;
2164
+ points[pOffset + idx1 + 1] = y;
2165
+ points[pOffset + idx1 + 2] = z;
2166
+ uv[idx2] = x;
2167
+ uv[idx2 + 1] = y;
2168
+ uv[uOffset + idx2] = x;
2169
+ uv[uOffset + idx2 + 1] = y;
2170
+ idx1 += 3;
2171
+ idx2 += 2;
2172
+ j++;
2173
+ }
2174
+ }
2362
2175
 
2363
- return this;
2176
+ return {
2177
+ flatVertices: flatVertices,
2178
+ holes: holes,
2179
+ points: points,
2180
+ count: count,
2181
+ uv: uv
2364
2182
  };
2183
+ }
2365
2184
 
2366
- _proto.dot = function dot(v) {
2367
- return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
2368
- };
2185
+ function validateRing(ring) {
2186
+ if (!isClosedRing(ring)) {
2187
+ ring.push(ring[0]);
2188
+ }
2189
+ }
2369
2190
 
2370
- _proto.lengthSq = function lengthSq() {
2371
- return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
2372
- };
2191
+ function isClosedRing(ring) {
2192
+ var len = ring.length;
2193
+ var _ring$ = ring[0],
2194
+ x1 = _ring$[0],
2195
+ y1 = _ring$[1],
2196
+ _ring = ring[len - 1],
2197
+ x2 = _ring[0],
2198
+ y2 = _ring[1];
2199
+ return x1 === x2 && y1 === y2;
2200
+ }
2373
2201
 
2374
- _proto.length = function length() {
2375
- return Math.sqrt(this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w);
2376
- };
2202
+ function checkOptions(options) {
2203
+ options.lineWidth = Math.max(0, options.lineWidth);
2204
+ options.depth = Math.max(0, options.depth);
2205
+ options.sideDepth = Math.max(0, options.sideDepth);
2206
+ }
2377
2207
 
2378
- _proto.normalize = function normalize() {
2379
- var l = this.length();
2208
+ function extrudePolylines(lines, options) {
2209
+ options = Object.assign({}, {
2210
+ depth: 2,
2211
+ lineWidth: 1,
2212
+ bottomStickGround: false
2213
+ }, options);
2214
+ checkOptions(options);
2215
+ var results = lines.map(function (line) {
2216
+ var result = expandLine(line, options);
2217
+ result.line = line;
2218
+ generateTopAndBottom(result, options);
2219
+ generateSides(result, options);
2220
+ result.position = new Float32Array(result.points);
2221
+ result.indices = new Uint32Array(result.indices);
2222
+ result.uv = new Float32Array(result.uv);
2223
+ result.normal = generateNormal(result.indices, result.position);
2224
+ return result;
2225
+ });
2226
+ var result = merge(results);
2227
+ result.lines = lines;
2228
+ return result;
2229
+ }
2230
+ function extrudeSlopes(lines, options) {
2231
+ options = Object.assign({}, {
2232
+ depth: 2,
2233
+ lineWidth: 1,
2234
+ side: 'left',
2235
+ sideDepth: 0,
2236
+ bottomStickGround: false
2237
+ }, options);
2238
+ checkOptions(options);
2239
+ var _options = options,
2240
+ depth = _options.depth,
2241
+ side = _options.side,
2242
+ sideDepth = _options.sideDepth;
2243
+ var results = lines.map(function (line) {
2244
+ var tempResult = expandLine(line, options);
2245
+ tempResult.line = line;
2246
+ var leftPoints = tempResult.leftPoints,
2247
+ rightPoints = tempResult.rightPoints;
2248
+ var result = {
2249
+ line: line
2250
+ };
2251
+ var depths;
2380
2252
 
2381
- if (l === 0) {
2382
- this._x = 0;
2383
- this._y = 0;
2384
- this._z = 0;
2385
- this._w = 1;
2253
+ for (var i = 0, len = line.length; i < len; i++) {
2254
+ line[i][2] = line[i][2] || 0;
2255
+ }
2256
+
2257
+ if (side === 'left') {
2258
+ result.leftPoints = leftPoints;
2259
+ result.rightPoints = line;
2260
+ depths = [sideDepth, depth];
2386
2261
  } else {
2387
- l = 1 / l;
2388
- this._x = this._x * l;
2389
- this._y = this._y * l;
2390
- this._z = this._z * l;
2391
- this._w = this._w * l;
2262
+ result.leftPoints = line;
2263
+ result.rightPoints = rightPoints;
2264
+ depths = [depth, sideDepth];
2392
2265
  }
2393
2266
 
2394
- this._onChangeCallback();
2267
+ result.depths = depths;
2268
+ generateTopAndBottom(result, options);
2269
+ generateSides(result, options);
2270
+ result.position = new Float32Array(result.points);
2271
+ result.indices = new Uint32Array(result.indices);
2272
+ result.uv = new Float32Array(result.uv);
2273
+ result.normal = generateNormal(result.indices, result.position);
2274
+ return result;
2275
+ });
2276
+ var result = merge(results);
2277
+ result.lines = lines;
2278
+ return result;
2279
+ }
2395
2280
 
2396
- return this;
2397
- };
2281
+ function generateTopAndBottom(result, options) {
2282
+ var bottomStickGround = options.bottomStickGround;
2283
+ var z = options.depth;
2284
+ var depths = result.depths;
2285
+ var lz = z,
2286
+ rz = z;
2398
2287
 
2399
- _proto.multiply = function multiply(q) {
2400
- return this.multiplyQuaternions(this, q);
2401
- };
2288
+ if (depths) {
2289
+ lz = depths[0];
2290
+ rz = depths[1];
2291
+ }
2402
2292
 
2403
- _proto.premultiply = function premultiply(q) {
2404
- return this.multiplyQuaternions(q, this);
2405
- };
2293
+ var points = [],
2294
+ indices = [],
2295
+ uv = [];
2296
+ var leftPoints = result.leftPoints,
2297
+ rightPoints = result.rightPoints;
2298
+ var i = 0,
2299
+ len = leftPoints.length;
2406
2300
 
2407
- _proto.multiplyQuaternions = function multiplyQuaternions(a, b) {
2408
- // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
2409
- var qax = a._x,
2410
- qay = a._y,
2411
- qaz = a._z,
2412
- qaw = a._w;
2413
- var qbx = b._x,
2414
- qby = b._y,
2415
- qbz = b._z,
2416
- qbw = b._w;
2417
- this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
2418
- this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
2419
- this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
2420
- this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
2301
+ while (i < len) {
2302
+ // top left
2303
+ var idx0 = i * 3;
2304
+ var _leftPoints$i = leftPoints[i],
2305
+ x1 = _leftPoints$i[0],
2306
+ y1 = _leftPoints$i[1],
2307
+ z1 = _leftPoints$i[2];
2308
+ points[idx0] = x1;
2309
+ points[idx0 + 1] = y1;
2310
+ points[idx0 + 2] = lz + z1; // top right
2421
2311
 
2422
- this._onChangeCallback();
2312
+ var _rightPoints$i = rightPoints[i],
2313
+ x2 = _rightPoints$i[0],
2314
+ y2 = _rightPoints$i[1],
2315
+ z2 = _rightPoints$i[2];
2316
+ var idx1 = len * 3 + idx0;
2317
+ points[idx1] = x2;
2318
+ points[idx1 + 1] = y2;
2319
+ points[idx1 + 2] = rz + z2; // bottom left
2423
2320
 
2424
- return this;
2425
- };
2321
+ var idx2 = len * 2 * 3 + idx0;
2322
+ points[idx2] = x1;
2323
+ points[idx2 + 1] = y1;
2324
+ points[idx2 + 2] = z1;
2426
2325
 
2427
- _proto.slerp = function slerp(qb, t) {
2428
- if (t === 0) return this;
2429
- if (t === 1) return this.copy(qb);
2430
- var x = this._x,
2431
- y = this._y,
2432
- z = this._z,
2433
- w = this._w; // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
2326
+ if (bottomStickGround) {
2327
+ points[idx2 + 2] = 0;
2328
+ } // bottom right
2434
2329
 
2435
- var cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
2436
2330
 
2437
- if (cosHalfTheta < 0) {
2438
- this._w = -qb._w;
2439
- this._x = -qb._x;
2440
- this._y = -qb._y;
2441
- this._z = -qb._z;
2442
- cosHalfTheta = -cosHalfTheta;
2443
- } else {
2444
- this.copy(qb);
2445
- }
2331
+ var idx3 = len * 2 * 3 + len * 3 + idx0;
2332
+ points[idx3] = x2;
2333
+ points[idx3 + 1] = y2;
2334
+ points[idx3 + 2] = z2;
2446
2335
 
2447
- if (cosHalfTheta >= 1.0) {
2448
- this._w = w;
2449
- this._x = x;
2450
- this._y = y;
2451
- this._z = z;
2452
- return this;
2336
+ if (bottomStickGround) {
2337
+ points[idx3 + 2] = 0;
2453
2338
  }
2454
2339
 
2455
- var sqrSinHalfTheta = 1.0 - cosHalfTheta * cosHalfTheta;
2340
+ i++;
2341
+ }
2456
2342
 
2457
- if (sqrSinHalfTheta <= Number.EPSILON) {
2458
- var s = 1 - t;
2459
- this._w = s * w + t * this._w;
2460
- this._x = s * x + t * this._x;
2461
- this._y = s * y + t * this._y;
2462
- this._z = s * z + t * this._z;
2463
- this.normalize(); // normalize calls _onChangeCallback()
2343
+ i = 0;
2344
+ len = points.length;
2345
+ var uIndex = uv.length - 1;
2464
2346
 
2465
- return this;
2466
- }
2347
+ while (i < len) {
2348
+ var x = points[i],
2349
+ y = points[i + 1];
2350
+ uv[++uIndex] = x;
2351
+ uv[++uIndex] = y; // uvs.push(x, y);
2467
2352
 
2468
- var sinHalfTheta = Math.sqrt(sqrSinHalfTheta);
2469
- var halfTheta = Math.atan2(sinHalfTheta, cosHalfTheta);
2470
- var ratioA = Math.sin((1 - t) * halfTheta) / sinHalfTheta,
2471
- ratioB = Math.sin(t * halfTheta) / sinHalfTheta;
2472
- this._w = w * ratioA + this._w * ratioB;
2473
- this._x = x * ratioA + this._x * ratioB;
2474
- this._y = y * ratioA + this._y * ratioB;
2475
- this._z = z * ratioA + this._z * ratioB;
2353
+ i += 3;
2354
+ }
2476
2355
 
2477
- this._onChangeCallback();
2356
+ i = 0;
2357
+ len = leftPoints.length;
2358
+ var iIndex = indices.length - 1;
2478
2359
 
2479
- return this;
2480
- };
2360
+ while (i < len - 1) {
2361
+ // top
2362
+ // left1 left2 right1,right2
2363
+ var a1 = i,
2364
+ b1 = i + 1,
2365
+ c1 = a1 + len,
2366
+ d1 = b1 + len;
2367
+ indices[++iIndex] = a1;
2368
+ indices[++iIndex] = c1;
2369
+ indices[++iIndex] = b1;
2370
+ indices[++iIndex] = c1;
2371
+ indices[++iIndex] = d1;
2372
+ indices[++iIndex] = b1; // index.push(a1, c1, b1);
2373
+ // index.push(c1, d1, b1);
2374
+ // bottom
2375
+ // left1 left2 right1,right2
2481
2376
 
2482
- _proto.slerpQuaternions = function slerpQuaternions(qa, qb, t) {
2483
- return this.copy(qa).slerp(qb, t);
2484
- };
2377
+ var len2 = len * 2;
2378
+ var a2 = i + len2,
2379
+ b2 = a2 + 1,
2380
+ c2 = a2 + len,
2381
+ d2 = b2 + len;
2382
+ indices[++iIndex] = a2;
2383
+ indices[++iIndex] = c2;
2384
+ indices[++iIndex] = b2;
2385
+ indices[++iIndex] = c2;
2386
+ indices[++iIndex] = d2;
2387
+ indices[++iIndex] = b2; // index.push(a2, c2, b2);
2388
+ // index.push(c2, d2, b2);
2485
2389
 
2486
- _proto.random = function random() {
2487
- // sets this quaternion to a uniform random unit quaternnion
2488
- // Ken Shoemake
2489
- // Uniform random rotations
2490
- // D. Kirk, editor, Graphics Gems III, pages 124-132. Academic Press, New York, 1992.
2491
- var theta1 = 2 * Math.PI * Math.random();
2492
- var theta2 = 2 * Math.PI * Math.random();
2493
- var x0 = Math.random();
2494
- var r1 = Math.sqrt(1 - x0);
2495
- var r2 = Math.sqrt(x0);
2496
- return this.set(r1 * Math.sin(theta1), r1 * Math.cos(theta1), r2 * Math.sin(theta2), r2 * Math.cos(theta2));
2497
- };
2390
+ i++;
2391
+ }
2498
2392
 
2499
- _proto.equals = function equals(quaternion) {
2500
- return quaternion._x === this._x && quaternion._y === this._y && quaternion._z === this._z && quaternion._w === this._w;
2501
- };
2393
+ result.indices = indices;
2394
+ result.points = points;
2395
+ result.uv = uv;
2502
2396
 
2503
- _proto.fromArray = function fromArray(array, offset) {
2504
- if (offset === void 0) {
2505
- offset = 0;
2397
+ if (depths) {
2398
+ len = leftPoints.length;
2399
+ i = 0;
2400
+
2401
+ while (i < len) {
2402
+ leftPoints[i].depth = lz;
2403
+ rightPoints[i].depth = rz;
2404
+ i++;
2506
2405
  }
2406
+ }
2407
+ }
2507
2408
 
2508
- this._x = array[offset];
2509
- this._y = array[offset + 1];
2510
- this._z = array[offset + 2];
2511
- this._w = array[offset + 3];
2409
+ function generateSides(result, options) {
2410
+ var points = result.points,
2411
+ indices = result.indices,
2412
+ leftPoints = result.leftPoints,
2413
+ rightPoints = result.rightPoints,
2414
+ uv = result.uv;
2415
+ var z = options.depth;
2416
+ var bottomStickGround = options.bottomStickGround;
2417
+ var rings = [leftPoints, rightPoints];
2418
+ var depthsEnable = result.depths;
2419
+ var pIndex = points.length - 1;
2420
+ var iIndex = indices.length - 1;
2512
2421
 
2513
- this._onChangeCallback();
2422
+ function addOneSideIndex(v1, v2) {
2423
+ var idx = points.length / 3; // let pIndex = points.length - 1;
2424
+ // top
2514
2425
 
2515
- return this;
2516
- };
2426
+ points[++pIndex] = v1[0];
2427
+ points[++pIndex] = v1[1];
2428
+ points[++pIndex] = (depthsEnable ? v1.depth : z) + v1[2];
2429
+ points[++pIndex] = v2[0];
2430
+ points[++pIndex] = v2[1];
2431
+ points[++pIndex] = (depthsEnable ? v2.depth : z) + v2[2]; // points.push(v1[0], v1[1], (depthsEnable ? v1.depth : z) + v1[2], v2[0], v2[1], (depthsEnable ? v2.depth : z) + v2[2]);
2432
+ // bottom
2517
2433
 
2518
- _proto.toArray = function toArray(array, offset) {
2519
- if (array === void 0) {
2520
- array = [];
2521
- }
2434
+ points[++pIndex] = v1[0];
2435
+ points[++pIndex] = v1[1];
2436
+ points[++pIndex] = bottomStickGround ? 0 : v1[2];
2437
+ points[++pIndex] = v2[0];
2438
+ points[++pIndex] = v2[1];
2439
+ points[++pIndex] = bottomStickGround ? 0 : v2[2]; // points.push(v1[0], v1[1], v1[2], v2[0], v2[1], v2[2]);
2522
2440
 
2523
- if (offset === void 0) {
2524
- offset = 0;
2441
+ var a = idx + 2,
2442
+ b = idx + 3,
2443
+ c = idx,
2444
+ d = idx + 1;
2445
+ indices[++iIndex] = a;
2446
+ indices[++iIndex] = c;
2447
+ indices[++iIndex] = b;
2448
+ indices[++iIndex] = c;
2449
+ indices[++iIndex] = d;
2450
+ indices[++iIndex] = b; // index.push(a, c, b, c, d, b);
2451
+
2452
+ generateSideWallUV(uv, points, a, b, c, d);
2453
+ }
2454
+
2455
+ for (var i = 0, _len = rings.length; i < _len; i++) {
2456
+ var ring = rings[i];
2457
+
2458
+ if (i > 0) {
2459
+ ring = ring.map(function (p) {
2460
+ return p;
2461
+ });
2462
+ ring = ring.reverse();
2525
2463
  }
2526
2464
 
2527
- array[offset] = this._x;
2528
- array[offset + 1] = this._y;
2529
- array[offset + 2] = this._z;
2530
- array[offset + 3] = this._w;
2531
- return array;
2532
- };
2465
+ var j = 0;
2466
+ var len1 = ring.length - 1;
2533
2467
 
2534
- _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index) {
2535
- this._x = attribute.getX(index);
2536
- this._y = attribute.getY(index);
2537
- this._z = attribute.getZ(index);
2538
- this._w = attribute.getW(index);
2468
+ while (j < len1) {
2469
+ var v1 = ring[j];
2470
+ var v2 = ring[j + 1];
2471
+ addOneSideIndex(v1, v2);
2472
+ j++;
2473
+ }
2474
+ }
2539
2475
 
2540
- this._onChangeCallback();
2476
+ var len = leftPoints.length;
2477
+ var vs = [rightPoints[0], leftPoints[0], leftPoints[len - 1], rightPoints[len - 1]];
2541
2478
 
2542
- return this;
2543
- };
2479
+ for (var _i = 0; _i < vs.length; _i += 2) {
2480
+ var _v = vs[_i],
2481
+ _v2 = vs[_i + 1];
2482
+ addOneSideIndex(_v, _v2);
2483
+ }
2484
+ }
2544
2485
 
2545
- _proto.toJSON = function toJSON() {
2546
- return this.toArray();
2547
- };
2486
+ var TEMPV1 = {
2487
+ x: 0,
2488
+ y: 0
2489
+ },
2490
+ TEMPV2 = {
2491
+ x: 0,
2492
+ y: 0
2493
+ };
2494
+ function expandLine(line, options) {
2495
+ // let preAngle = 0;
2496
+ var radius = options.lineWidth / 2;
2497
+ var points = [],
2498
+ leftPoints = [],
2499
+ rightPoints = [];
2500
+ var len = line.length;
2501
+ var i = 0;
2548
2502
 
2549
- _proto._onChange = function _onChange(callback) {
2550
- this._onChangeCallback = callback;
2551
- return this;
2552
- };
2503
+ while (i < len) {
2504
+ var p1 = line[i],
2505
+ p2 = line[i + 1];
2506
+ var currentp = line[i]; // last vertex
2553
2507
 
2554
- _proto._onChangeCallback = function _onChangeCallback() {};
2508
+ if (i === len - 1) {
2509
+ p1 = line[len - 2];
2510
+ p2 = line[len - 1];
2511
+ }
2555
2512
 
2556
- _proto[_Symbol$iterator] = /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
2557
- return _regeneratorRuntime().wrap(function _callee$(_context) {
2558
- while (1) {
2559
- switch (_context.prev = _context.next) {
2560
- case 0:
2561
- _context.next = 2;
2562
- return this._x;
2513
+ var dy = p2[1] - p1[1],
2514
+ dx = p2[0] - p1[0];
2515
+ var rAngle = 0;
2516
+ var rad = Math.atan(dy / dx);
2517
+ var angle = radToDeg(rad); // preAngle = angle;
2563
2518
 
2564
- case 2:
2565
- _context.next = 4;
2566
- return this._y;
2519
+ if (i === 0 || i === len - 1) {
2520
+ rAngle = angle;
2521
+ rAngle -= 90;
2522
+ } else {
2523
+ // 至少3个顶点才会触发
2524
+ var p0 = line[i - 1];
2525
+ TEMPV1.x = p0[0] - p1[0];
2526
+ TEMPV1.y = p0[1] - p1[1];
2527
+ TEMPV2.x = p2[0] - p1[0];
2528
+ TEMPV2.y = p2[1] - p1[1];
2529
+ var vAngle = getAngle(TEMPV1, TEMPV2);
2530
+ rAngle = angle - vAngle / 2;
2531
+ }
2567
2532
 
2568
- case 4:
2569
- _context.next = 6;
2570
- return this._z;
2533
+ var rRad = degToRad(rAngle);
2534
+ var p3 = currentp;
2535
+ var x = Math.cos(rRad) + p3[0],
2536
+ y = Math.sin(rRad) + p3[1];
2537
+ var p4 = [x, y];
2571
2538
 
2572
- case 6:
2573
- _context.next = 8;
2574
- return this._w;
2539
+ var _translateLine = translateLine(p1, p2, radius),
2540
+ line1 = _translateLine[0],
2541
+ line2 = _translateLine[1];
2575
2542
 
2576
- case 8:
2577
- case "end":
2578
- return _context.stop();
2579
- }
2580
- }
2581
- }, _callee, this);
2582
- });
2543
+ var op1 = lineIntersection(line1[0], line1[1], p3, p4);
2544
+ var op2 = lineIntersection(line2[0], line2[1], p3, p4); // 平行,回头路
2583
2545
 
2584
- _createClass(Quaternion, [{
2585
- key: "x",
2586
- get: function get() {
2587
- return this._x;
2588
- },
2589
- set: function set(value) {
2590
- this._x = value;
2591
-
2592
- this._onChangeCallback();
2593
- }
2594
- }, {
2595
- key: "y",
2596
- get: function get() {
2597
- return this._y;
2598
- },
2599
- set: function set(value) {
2600
- this._y = value;
2601
-
2602
- this._onChangeCallback();
2603
- }
2604
- }, {
2605
- key: "z",
2606
- get: function get() {
2607
- return this._z;
2608
- },
2609
- set: function set(value) {
2610
- this._z = value;
2546
+ if (!op1 || !op2) {
2547
+ var len1 = points.length;
2548
+ var point1 = points[len1 - 2];
2549
+ var point2 = points[len1 - 1];
2611
2550
 
2612
- this._onChangeCallback();
2613
- }
2614
- }, {
2615
- key: "w",
2616
- get: function get() {
2617
- return this._w;
2618
- },
2619
- set: function set(value) {
2620
- this._w = value;
2551
+ if (!point1 || !point2) {
2552
+ continue;
2553
+ }
2621
2554
 
2622
- this._onChangeCallback();
2555
+ op1 = [point1[0], point1[1]];
2556
+ op2 = [point2[0], point2[1]];
2623
2557
  }
2624
- }]);
2625
-
2626
- return Quaternion;
2627
- }(Symbol.iterator);
2628
-
2629
- // import * as MathUtils from './MathUtils.js';
2630
2558
 
2631
- var _quaternion = new Quaternion();
2632
-
2633
- var Vector3 = /*#__PURE__*/function () {
2634
- function Vector3(x, y, z) {
2635
- if (x === void 0) {
2636
- x = 0;
2637
- }
2559
+ op1[2] = currentp[2] || 0;
2560
+ op2[2] = currentp[2] || 0; // const [op1, op2] = calOffsetPoint(rRad, radius, p1);
2638
2561
 
2639
- if (y === void 0) {
2640
- y = 0;
2641
- }
2562
+ points.push(op1, op2);
2642
2563
 
2643
- if (z === void 0) {
2644
- z = 0;
2564
+ if (leftOnLine(op1, p1, p2)) {
2565
+ leftPoints.push(op1);
2566
+ rightPoints.push(op2);
2567
+ } else {
2568
+ leftPoints.push(op2);
2569
+ rightPoints.push(op1);
2645
2570
  }
2646
2571
 
2647
- this.x = x;
2648
- this.y = y;
2649
- this.z = z;
2572
+ i++;
2650
2573
  }
2651
2574
 
2652
- var _proto = Vector3.prototype;
2653
-
2654
- _proto.set = function set(x, y, z) {
2655
- if (z === undefined) z = this.z; // sprite.scale.set(x,y)
2656
-
2657
- this.x = x;
2658
- this.y = y;
2659
- this.z = z;
2660
- return this;
2661
- } // setScalar(scalar) {
2662
- // this.x = scalar;
2663
- // this.y = scalar;
2664
- // this.z = scalar;
2665
- // return this;
2666
- // }
2667
- // setX(x) {
2668
- // this.x = x;
2669
- // return this;
2670
- // }
2671
- // setY(y) {
2672
- // this.y = y;
2673
- // return this;
2674
- // }
2675
- // setZ(z) {
2676
- // this.z = z;
2677
- // return this;
2678
- // }
2679
- // setComponent(index, value) {
2680
- // switch (index) {
2681
- // case 0: this.x = value; break;
2682
- // case 1: this.y = value; break;
2683
- // case 2: this.z = value; break;
2684
- // default: throw new Error('index is out of range: ' + index);
2685
- // }
2686
- // return this;
2687
- // }
2688
- // getComponent(index) {
2689
- // switch (index) {
2690
- // case 0: return this.x;
2691
- // case 1: return this.y;
2692
- // case 2: return this.z;
2693
- // default: throw new Error('index is out of range: ' + index);
2694
- // }
2695
- // }
2696
- ;
2697
-
2698
- _proto.clone = function clone() {
2699
- return new this.constructor(this.x, this.y, this.z);
2700
- };
2701
-
2702
- _proto.copy = function copy(v) {
2703
- this.x = v.x;
2704
- this.y = v.y;
2705
- this.z = v.z;
2706
- return this;
2707
- };
2708
-
2709
- _proto.add = function add(v) {
2710
- this.x += v.x;
2711
- this.y += v.y;
2712
- this.z += v.z;
2713
- return this;
2714
- };
2715
-
2716
- _proto.addScalar = function addScalar(s) {
2717
- this.x += s;
2718
- this.y += s;
2719
- this.z += s;
2720
- return this;
2721
- };
2722
-
2723
- _proto.addVectors = function addVectors(a, b) {
2724
- this.x = a.x + b.x;
2725
- this.y = a.y + b.y;
2726
- this.z = a.z + b.z;
2727
- return this;
2728
- };
2729
-
2730
- _proto.addScaledVector = function addScaledVector(v, s) {
2731
- this.x += v.x * s;
2732
- this.y += v.y * s;
2733
- this.z += v.z * s;
2734
- return this;
2735
- };
2736
-
2737
- _proto.sub = function sub(v) {
2738
- this.x -= v.x;
2739
- this.y -= v.y;
2740
- this.z -= v.z;
2741
- return this;
2742
- };
2743
-
2744
- _proto.subScalar = function subScalar(s) {
2745
- this.x -= s;
2746
- this.y -= s;
2747
- this.z -= s;
2748
- return this;
2749
- };
2750
-
2751
- _proto.subVectors = function subVectors(a, b) {
2752
- this.x = a.x - b.x;
2753
- this.y = a.y - b.y;
2754
- this.z = a.z - b.z;
2755
- return this;
2756
- };
2757
-
2758
- _proto.multiply = function multiply(v) {
2759
- this.x *= v.x;
2760
- this.y *= v.y;
2761
- this.z *= v.z;
2762
- return this;
2763
- };
2764
-
2765
- _proto.multiplyScalar = function multiplyScalar(scalar) {
2766
- this.x *= scalar;
2767
- this.y *= scalar;
2768
- this.z *= scalar;
2769
- return this;
2770
- };
2771
-
2772
- _proto.multiplyVectors = function multiplyVectors(a, b) {
2773
- this.x = a.x * b.x;
2774
- this.y = a.y * b.y;
2775
- this.z = a.z * b.z;
2776
- return this;
2777
- } // applyEuler(euler) {
2778
- // return this.applyQuaternion(_quaternion.setFromEuler(euler));
2779
- // }
2780
- ;
2781
-
2782
- _proto.applyAxisAngle = function applyAxisAngle(axis, angle) {
2783
- return this.applyQuaternion(_quaternion.setFromAxisAngle(axis, angle));
2784
- } // applyMatrix3(m) {
2785
- // const x = this.x, y = this.y, z = this.z;
2786
- // const e = m.elements;
2787
- // this.x = e[0] * x + e[3] * y + e[6] * z;
2788
- // this.y = e[1] * x + e[4] * y + e[7] * z;
2789
- // this.z = e[2] * x + e[5] * y + e[8] * z;
2790
- // return this;
2791
- // }
2792
- // applyNormalMatrix(m) {
2793
- // return this.applyMatrix3(m).normalize();
2794
- // }
2795
- ;
2796
-
2797
- _proto.applyMatrix4 = function applyMatrix4(m) {
2798
- var x = this.x,
2799
- y = this.y,
2800
- z = this.z;
2801
- var e = m.elements;
2802
- var w = 1 / (e[3] * x + e[7] * y + e[11] * z + e[15]);
2803
- this.x = (e[0] * x + e[4] * y + e[8] * z + e[12]) * w;
2804
- this.y = (e[1] * x + e[5] * y + e[9] * z + e[13]) * w;
2805
- this.z = (e[2] * x + e[6] * y + e[10] * z + e[14]) * w;
2806
- return this;
2575
+ return {
2576
+ offsetPoints: points,
2577
+ leftPoints: leftPoints,
2578
+ rightPoints: rightPoints
2807
2579
  };
2580
+ } // eslint-disable-next-line no-unused-vars
2808
2581
 
2809
- _proto.applyQuaternion = function applyQuaternion(q) {
2810
- var x = this.x,
2811
- y = this.y,
2812
- z = this.z;
2813
- var qx = q.x,
2814
- qy = q.y,
2815
- qz = q.z,
2816
- qw = q.w; // calculate quat * vector
2582
+ var getAngle = function getAngle(_ref, _ref2) {
2583
+ var x1 = _ref.x,
2584
+ y1 = _ref.y;
2585
+ var x2 = _ref2.x,
2586
+ y2 = _ref2.y;
2587
+ var dot = x1 * x2 + y1 * y2;
2588
+ var det = x1 * y2 - y1 * x2;
2589
+ var angle = Math.atan2(det, dot) / Math.PI * 180;
2590
+ return (angle + 360) % 360;
2591
+ };
2817
2592
 
2818
- var ix = qw * x + qy * z - qz * y;
2819
- var iy = qw * y + qz * x - qx * z;
2820
- var iz = qw * z + qx * y - qy * x;
2821
- var iw = -qx * x - qy * y - qz * z; // calculate result * inverse quat
2593
+ function leftOnLine(p, p1, p2) {
2594
+ var x1 = p1[0],
2595
+ y1 = p1[1];
2596
+ var x2 = p2[0],
2597
+ y2 = p2[1];
2598
+ var x = p[0],
2599
+ y = p[1];
2600
+ return (y1 - y2) * x + (x2 - x1) * y + x1 * y2 - x2 * y1 > 0;
2601
+ }
2602
+ /**
2603
+ * 平移线
2604
+ * @param {*} p1
2605
+ * @param {*} p2
2606
+ * @param {*} distance
2607
+ * @returns
2608
+ */
2822
2609
 
2823
- this.x = ix * qw + iw * -qx + iy * -qz - iz * -qy;
2824
- this.y = iy * qw + iw * -qy + iz * -qx - ix * -qz;
2825
- this.z = iz * qw + iw * -qz + ix * -qy - iy * -qx;
2826
- return this;
2827
- } // project(camera) {
2828
- // return this.applyMatrix4(camera.matrixWorldInverse).applyMatrix4(camera.projectionMatrix);
2829
- // }
2830
- // unproject(camera) {
2831
- // return this.applyMatrix4(camera.projectionMatrixInverse).applyMatrix4(camera.matrixWorld);
2832
- // }
2833
- // transformDirection(m) {
2834
- // // input: THREE.Matrix4 affine matrix
2835
- // // vector interpreted as a direction
2836
- // const x = this.x, y = this.y, z = this.z;
2837
- // const e = m.elements;
2838
- // this.x = e[0] * x + e[4] * y + e[8] * z;
2839
- // this.y = e[1] * x + e[5] * y + e[9] * z;
2840
- // this.z = e[2] * x + e[6] * y + e[10] * z;
2841
- // return this.normalize();
2842
- // }
2843
- ;
2610
+ function translateLine(p1, p2, distance) {
2611
+ var dy = p2[1] - p1[1],
2612
+ dx = p2[0] - p1[0];
2613
+ var rad = Math.atan2(dy, dx);
2614
+ var rad1 = rad + Math.PI / 2;
2615
+ var offsetX = Math.cos(rad1) * distance,
2616
+ offsetY = Math.sin(rad1) * distance;
2617
+ var tp1 = [p1[0] + offsetX, p1[1] + offsetY];
2618
+ var tp2 = [p2[0] + offsetX, p2[1] + offsetY];
2619
+ var rad2 = rad - Math.PI / 2;
2620
+ offsetX = Math.cos(rad2) * distance;
2621
+ offsetY = Math.sin(rad2) * distance;
2622
+ var tp3 = [p1[0] + offsetX, p1[1] + offsetY];
2623
+ var tp4 = [p2[0] + offsetX, p2[1] + offsetY];
2624
+ return [[tp1, tp2], [tp3, tp4]];
2625
+ }
2626
+ /**
2627
+ * 直线交点
2628
+ * @param {*} p1
2629
+ * @param {*} p2
2630
+ * @param {*} p3
2631
+ * @param {*} p4
2632
+ * @returns
2633
+ */
2844
2634
 
2845
- _proto.divide = function divide(v) {
2846
- this.x /= v.x;
2847
- this.y /= v.y;
2848
- this.z /= v.z;
2849
- return this;
2850
- };
2851
2635
 
2852
- _proto.divideScalar = function divideScalar(scalar) {
2853
- return this.multiplyScalar(1 / scalar);
2854
- };
2636
+ function lineIntersection(p1, p2, p3, p4) {
2637
+ var dx1 = p2[0] - p1[0],
2638
+ dy1 = p2[1] - p1[1];
2639
+ var dx2 = p4[0] - p3[0],
2640
+ dy2 = p4[1] - p3[1];
2855
2641
 
2856
- _proto.min = function min(v) {
2857
- this.x = Math.min(this.x, v.x);
2858
- this.y = Math.min(this.y, v.y);
2859
- this.z = Math.min(this.z, v.z);
2860
- return this;
2861
- };
2642
+ if (dx1 === 0 && dx2 === 0) {
2643
+ return null;
2644
+ }
2862
2645
 
2863
- _proto.max = function max(v) {
2864
- this.x = Math.max(this.x, v.x);
2865
- this.y = Math.max(this.y, v.y);
2866
- this.z = Math.max(this.z, v.z);
2867
- return this;
2868
- };
2646
+ if (dy1 === 0 && dy2 === 0) {
2647
+ return null;
2648
+ }
2869
2649
 
2870
- _proto.clamp = function clamp(min, max) {
2871
- // assumes min < max, componentwise
2872
- this.x = Math.max(min.x, Math.min(max.x, this.x));
2873
- this.y = Math.max(min.y, Math.min(max.y, this.y));
2874
- this.z = Math.max(min.z, Math.min(max.z, this.z));
2875
- return this;
2876
- };
2650
+ var k1 = dy1 / dx1;
2651
+ var k2 = dy2 / dx2;
2652
+ var b1 = p1[1] - k1 * p1[0];
2653
+ var b2 = p3[1] - k2 * p3[0];
2654
+ var x, y;
2877
2655
 
2878
- _proto.clampScalar = function clampScalar(minVal, maxVal) {
2879
- this.x = Math.max(minVal, Math.min(maxVal, this.x));
2880
- this.y = Math.max(minVal, Math.min(maxVal, this.y));
2881
- this.z = Math.max(minVal, Math.min(maxVal, this.z));
2882
- return this;
2883
- };
2656
+ if (dx1 === 0) {
2657
+ x = p1[0];
2658
+ y = k2 * x + b2;
2659
+ } else if (dx2 === 0) {
2660
+ x = p3[0];
2661
+ y = k1 * x + b1;
2662
+ } else if (dy1 === 0) {
2663
+ y = p1[1];
2664
+ x = (y - b2) / k2;
2665
+ } else if (dy2 === 0) {
2666
+ y = p3[1];
2667
+ x = (y - b1) / k1;
2668
+ } else {
2669
+ x = (b2 - b1) / (k1 - k2);
2670
+ y = k1 * x + b1;
2671
+ }
2884
2672
 
2885
- _proto.clampLength = function clampLength(min, max) {
2886
- var length = this.length();
2887
- return this.divideScalar(length || 1).multiplyScalar(Math.max(min, Math.min(max, length)));
2888
- } // floor() {
2889
- // this.x = Math.floor(this.x);
2890
- // this.y = Math.floor(this.y);
2891
- // this.z = Math.floor(this.z);
2892
- // return this;
2893
- // }
2894
- // ceil() {
2895
- // this.x = Math.ceil(this.x);
2896
- // this.y = Math.ceil(this.y);
2897
- // this.z = Math.ceil(this.z);
2898
- // return this;
2899
- // }
2900
- // round() {
2901
- // this.x = Math.round(this.x);
2902
- // this.y = Math.round(this.y);
2903
- // this.z = Math.round(this.z);
2904
- // return this;
2905
- // }
2906
- // roundToZero() {
2907
- // this.x = (this.x < 0) ? Math.ceil(this.x) : Math.floor(this.x);
2908
- // this.y = (this.y < 0) ? Math.ceil(this.y) : Math.floor(this.y);
2909
- // this.z = (this.z < 0) ? Math.ceil(this.z) : Math.floor(this.z);
2910
- // return this;
2911
- // }
2912
- // negate() {
2913
- // this.x = -this.x;
2914
- // this.y = -this.y;
2915
- // this.z = -this.z;
2916
- // return this;
2917
- // }
2918
- ;
2673
+ return [x, y];
2674
+ }
2919
2675
 
2920
- _proto.dot = function dot(v) {
2921
- return this.x * v.x + this.y * v.y + this.z * v.z;
2922
- } // TODO lengthSquared?
2923
- ;
2676
+ function cylinder(point, options) {
2677
+ if (options === void 0) {
2678
+ options = {};
2679
+ }
2924
2680
 
2925
- _proto.lengthSq = function lengthSq() {
2926
- return this.x * this.x + this.y * this.y + this.z * this.z;
2927
- };
2681
+ options = Object.assign({}, {
2682
+ radius: 1,
2683
+ height: 2,
2684
+ radialSegments: 6
2685
+ }, options);
2686
+ var radialSegments = Math.round(Math.max(4, options.radialSegments));
2687
+ var _options = options,
2688
+ radius = _options.radius,
2689
+ height = _options.height;
2690
+ var aRad = 360 / radialSegments / 360 * Math.PI * 2;
2691
+ var circlePointsLen = radialSegments + 1;
2692
+ var points = new Float32Array(circlePointsLen * 3 * 2);
2693
+ var centerx = point[0],
2694
+ centery = point[1];
2695
+ var idx = 0,
2696
+ uIdx = 0;
2697
+ var offset = circlePointsLen * 3,
2698
+ uOffset = circlePointsLen * 2;
2699
+ var indices = [],
2700
+ uv = [];
2701
+ var iIndex = indices.length - 1;
2928
2702
 
2929
- _proto.length = function length() {
2930
- return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
2931
- } // manhattanLength() {
2932
- // return Math.abs(this.x) + Math.abs(this.y) + Math.abs(this.z);
2933
- // }
2934
- ;
2703
+ for (var i = -1; i < radialSegments; i++) {
2704
+ var rad = aRad * i;
2705
+ var x = Math.cos(rad) * radius + centerx,
2706
+ y = Math.sin(rad) * radius + centery; // bottom vertices
2935
2707
 
2936
- _proto.normalize = function normalize() {
2937
- return this.divideScalar(this.length() || 1);
2938
- };
2708
+ points[idx] = x;
2709
+ points[idx + 1] = y;
2710
+ points[idx + 2] = 0; // top vertices
2939
2711
 
2940
- _proto.setLength = function setLength(length) {
2941
- return this.normalize().multiplyScalar(length);
2942
- };
2712
+ points[idx + offset] = x;
2713
+ points[idx + 1 + offset] = y;
2714
+ points[idx + 2 + offset] = height;
2715
+ var u = 0,
2716
+ v = 0;
2717
+ u = 0.5 + x / radius / 2;
2718
+ v = 0.5 + y / radius / 2;
2719
+ uv[uIdx] = u;
2720
+ uv[uIdx + 1] = v;
2721
+ uv[uIdx + uOffset] = u;
2722
+ uv[uIdx + 1 + uOffset] = v;
2723
+ idx += 3;
2724
+ uIdx += 2;
2943
2725
 
2944
- _proto.lerp = function lerp(v, alpha) {
2945
- this.x += (v.x - this.x) * alpha;
2946
- this.y += (v.y - this.y) * alpha;
2947
- this.z += (v.z - this.z) * alpha;
2948
- return this;
2949
- };
2726
+ if (i > 1) {
2727
+ // bottom indices
2728
+ // indices.push(0, i - 1, i);
2729
+ indices[++iIndex] = 0;
2730
+ indices[++iIndex] = i - 1;
2731
+ indices[++iIndex] = i;
2732
+ }
2733
+ }
2950
2734
 
2951
- _proto.lerpVectors = function lerpVectors(v1, v2, alpha) {
2952
- this.x = v1.x + (v2.x - v1.x) * alpha;
2953
- this.y = v1.y + (v2.y - v1.y) * alpha;
2954
- this.z = v1.z + (v2.z - v1.z) * alpha;
2955
- return this;
2956
- };
2735
+ idx -= 3;
2736
+ points[idx] = points[0];
2737
+ points[idx + 1] = points[1];
2738
+ points[idx + 2] = points[2];
2739
+ var pointsLen = points.length;
2740
+ points[pointsLen - 3] = points[0];
2741
+ points[pointsLen - 2] = points[1];
2742
+ points[pointsLen - 1] = height;
2743
+ var indicesLen = indices.length; // top indices
2957
2744
 
2958
- _proto.cross = function cross(v) {
2959
- return this.crossVectors(this, v);
2960
- };
2745
+ iIndex = indices.length - 1;
2961
2746
 
2962
- _proto.crossVectors = function crossVectors(a, b) {
2963
- var ax = a.x,
2964
- ay = a.y,
2965
- az = a.z;
2966
- var bx = b.x,
2967
- by = b.y,
2968
- bz = b.z;
2969
- this.x = ay * bz - az * by;
2970
- this.y = az * bx - ax * bz;
2971
- this.z = ax * by - ay * bx;
2972
- return this;
2973
- } // projectOnVector(v) {
2974
- // const denominator = v.lengthSq();
2975
- // if (denominator === 0) return this.set(0, 0, 0);
2976
- // const scalar = v.dot(this) / denominator;
2977
- // return this.copy(v).multiplyScalar(scalar);
2978
- // }
2979
- // projectOnPlane(planeNormal) {
2980
- // _vector.copy(this).projectOnVector(planeNormal);
2981
- // return this.sub(_vector);
2982
- // }
2983
- // reflect(normal) {
2984
- // // reflect incident vector off plane orthogonal to normal
2985
- // // normal is assumed to have unit length
2986
- // return this.sub(_vector.copy(normal).multiplyScalar(2 * this.dot(normal)));
2987
- // }
2988
- // angleTo(v) {
2989
- // const denominator = Math.sqrt(this.lengthSq() * v.lengthSq());
2990
- // if (denominator === 0) return Math.PI / 2;
2991
- // const theta = this.dot(v) / denominator;
2992
- // // clamp, to handle numerical problems
2993
- // return Math.acos(MathUtils.clamp(theta, -1, 1));
2994
- // }
2995
- ;
2747
+ for (var _i = 0; _i < indicesLen; _i++) {
2748
+ var index = indices[_i];
2749
+ indices[++iIndex] = index + circlePointsLen; // indices.push(index + circlePointsLen);
2750
+ }
2996
2751
 
2997
- _proto.distanceTo = function distanceTo(v) {
2998
- return Math.sqrt(this.distanceToSquared(v));
2999
- } // distanceToSquared(v) {
3000
- // const dx = this.x - v.x, dy = this.y - v.y, dz = this.z - v.z;
3001
- // return dx * dx + dy * dy + dz * dz;
3002
- // }
3003
- // manhattanDistanceTo(v) {
3004
- // return Math.abs(this.x - v.x) + Math.abs(this.y - v.y) + Math.abs(this.z - v.z);
3005
- // }
3006
- // setFromSpherical(s) {
3007
- // return this.setFromSphericalCoords(s.radius, s.phi, s.theta);
3008
- // }
3009
- // setFromSphericalCoords(radius, phi, theta) {
3010
- // const sinPhiRadius = Math.sin(phi) * radius;
3011
- // this.x = sinPhiRadius * Math.sin(theta);
3012
- // this.y = Math.cos(phi) * radius;
3013
- // this.z = sinPhiRadius * Math.cos(theta);
3014
- // return this;
3015
- // }
3016
- // setFromCylindrical(c) {
3017
- // return this.setFromCylindricalCoords(c.radius, c.theta, c.y);
3018
- // }
3019
- // setFromCylindricalCoords(radius, theta, y) {
3020
- // this.x = radius * Math.sin(theta);
3021
- // this.y = y;
3022
- // this.z = radius * Math.cos(theta);
3023
- // return this;
3024
- // }
3025
- // setFromMatrixPosition(m) {
3026
- // const e = m.elements;
3027
- // this.x = e[12];
3028
- // this.y = e[13];
3029
- // this.z = e[14];
3030
- // return this;
3031
- // }
3032
- // setFromMatrixScale(m) {
3033
- // const sx = this.setFromMatrixColumn(m, 0).length();
3034
- // const sy = this.setFromMatrixColumn(m, 1).length();
3035
- // const sz = this.setFromMatrixColumn(m, 2).length();
3036
- // this.x = sx;
3037
- // this.y = sy;
3038
- // this.z = sz;
3039
- // return this;
3040
- // }
3041
- // setFromMatrixColumn(m, index) {
3042
- // return this.fromArray(m.elements, index * 4);
3043
- // }
3044
- // setFromMatrix3Column(m, index) {
3045
- // return this.fromArray(m.elements, index * 3);
3046
- // }
3047
- // setFromEuler(e) {
3048
- // this.x = e._x;
3049
- // this.y = e._y;
3050
- // this.z = e._z;
3051
- // return this;
3052
- // }
3053
- // setFromColor(c) {
3054
- // this.x = c.r;
3055
- // this.y = c.g;
3056
- // this.z = c.b;
3057
- // return this;
3058
- // }
3059
- ;
2752
+ var sidePoints = new Float32Array((circlePointsLen * 3 * 2 - 6) * 2);
2753
+ var pIndex = -1;
2754
+ idx = circlePointsLen * 2;
2755
+ uIdx = 0;
2756
+ iIndex = indices.length - 1;
2757
+ var uvIndex = uv.length - 1;
3060
2758
 
3061
- _proto.equals = function equals(v) {
3062
- return v.x === this.x && v.y === this.y && v.z === this.z;
3063
- };
2759
+ for (var _i2 = 0, len = points.length / 2; _i2 < len - 3; _i2 += 3) {
2760
+ var x1 = points[_i2],
2761
+ y1 = points[_i2 + 1],
2762
+ x2 = points[_i2 + 3],
2763
+ y2 = points[_i2 + 4];
2764
+ sidePoints[++pIndex] = x1;
2765
+ sidePoints[++pIndex] = y1;
2766
+ sidePoints[++pIndex] = height;
2767
+ sidePoints[++pIndex] = x2;
2768
+ sidePoints[++pIndex] = y2;
2769
+ sidePoints[++pIndex] = height;
2770
+ sidePoints[++pIndex] = x1;
2771
+ sidePoints[++pIndex] = y1;
2772
+ sidePoints[++pIndex] = 0;
2773
+ sidePoints[++pIndex] = x2;
2774
+ sidePoints[++pIndex] = y2;
2775
+ sidePoints[++pIndex] = 0;
2776
+ var a = idx + 2,
2777
+ b = idx + 3,
2778
+ c = idx,
2779
+ d = idx + 1; // indices.push(a, c, b, c, d, b);
3064
2780
 
3065
- _proto.fromArray = function fromArray(array, offset) {
3066
- if (offset === void 0) {
3067
- offset = 0;
3068
- }
2781
+ indices[++iIndex] = c;
2782
+ indices[++iIndex] = a;
2783
+ indices[++iIndex] = d;
2784
+ indices[++iIndex] = a;
2785
+ indices[++iIndex] = b;
2786
+ indices[++iIndex] = d; // indices.push(c, a, d, a, b, d);
3069
2787
 
3070
- this.x = array[offset];
3071
- this.y = array[offset + 1];
3072
- this.z = array[offset + 2];
3073
- return this;
3074
- } // toArray(array = [], offset = 0) {
3075
- // array[offset] = this.x;
3076
- // array[offset + 1] = this.y;
3077
- // array[offset + 2] = this.z;
3078
- // return array;
3079
- // }
3080
- // fromBufferAttribute(attribute, index) {
3081
- // this.x = attribute.getX(index);
3082
- // this.y = attribute.getY(index);
3083
- // this.z = attribute.getZ(index);
3084
- // return this;
3085
- // }
3086
- ;
2788
+ idx += 4;
2789
+ var u1 = uIdx / circlePointsLen,
2790
+ u2 = (uIdx + 1) / circlePointsLen;
2791
+ uv[++uvIndex] = u1;
2792
+ uv[++uvIndex] = height / radius / 2;
2793
+ uv[++uvIndex] = u2;
2794
+ uv[++uvIndex] = height / radius / 2;
2795
+ uv[++uvIndex] = u1;
2796
+ uv[++uvIndex] = 0;
2797
+ uv[++uvIndex] = u2;
2798
+ uv[++uvIndex] = 0; // uvs.push(u1, height / radius / 2, u2, height / radius / 2, u1, 0, u2, 0);
3087
2799
 
3088
- _proto.random = function random() {
3089
- this.x = Math.random();
3090
- this.y = Math.random();
3091
- this.z = Math.random();
3092
- return this;
3093
- } // randomDirection() {
3094
- // // Derived from https://mathworld.wolfram.com/SpherePointPicking.html
3095
- // const u = (Math.random() - 0.5) * 2;
3096
- // const t = Math.random() * Math.PI * 2;
3097
- // const f = Math.sqrt(1 - u ** 2);
3098
- // this.x = f * Math.cos(t);
3099
- // this.y = f * Math.sin(t);
3100
- // this.z = u;
3101
- // return this;
3102
- // }
3103
- ;
2800
+ uIdx++;
2801
+ }
3104
2802
 
3105
- return Vector3;
3106
- }();
2803
+ var position = new Float32Array(points.length + sidePoints.length);
2804
+ position.set(points, 0);
2805
+ position.set(sidePoints, points.length);
2806
+ var normal = generateNormal(indices, position);
2807
+ return {
2808
+ points: points,
2809
+ indices: new Uint32Array(indices),
2810
+ position: position,
2811
+ normal: normal,
2812
+ uv: new Float32Array(uv)
2813
+ };
2814
+ }
3107
2815
 
3108
2816
  /* eslint-disable no-tabs */
3109
2817
  /**
@@ -4398,6 +4106,13 @@ var PathPointList = /*#__PURE__*/function () {
4398
4106
  }();
4399
4107
 
4400
4108
  var UP$1 = new Vector3(0, 0, 1);
4109
+ var right = new Vector3();
4110
+ var left = new Vector3(); // for sharp corners
4111
+
4112
+ var leftOffset = new Vector3();
4113
+ var rightOffset = new Vector3();
4114
+ var tempPoint1 = new Vector3();
4115
+ var tempPoint2 = new Vector3();
4401
4116
  function expandPaths(lines, options) {
4402
4117
  options = Object.assign({}, {
4403
4118
  lineWidth: 1,
@@ -4405,19 +4120,14 @@ function expandPaths(lines, options) {
4405
4120
  cornerSplit: 10
4406
4121
  }, options);
4407
4122
  var results = lines.map(function (line) {
4408
- var points = line.map(function (p) {
4409
- var x = p[0],
4410
- y = p[1],
4411
- z = p[2];
4412
- return new Vector3(x, y, z || 0);
4413
- });
4123
+ var points = line2Vectors(line);
4414
4124
  var pathPointList = new PathPointList();
4415
4125
  pathPointList.set(points, options.cornerRadius, options.cornerSplit, UP$1);
4416
4126
  var result = generatePathVertexData(pathPointList, options);
4417
4127
  result.line = line;
4418
- result.position = new Float32Array(result.points);
4419
- result.indices = new Uint32Array(result.index);
4420
- result.uv = new Float32Array(result.uvs);
4128
+ result.position = new Float32Array(result.position);
4129
+ result.indices = new Uint32Array(result.indices);
4130
+ result.uv = new Float32Array(result.uv);
4421
4131
  result.normal = new Float32Array(result.normal);
4422
4132
  return result;
4423
4133
  });
@@ -4448,13 +4158,10 @@ function generatePathVertexData(pathPointList, options) {
4448
4158
  var uv = [];
4449
4159
  var indices = [];
4450
4160
  var verticesCount = 0;
4451
- var right = new Vector3();
4452
- var left = new Vector3(); // for sharp corners
4453
-
4454
- var leftOffset = new Vector3();
4455
- var rightOffset = new Vector3();
4456
- var tempPoint1 = new Vector3();
4457
- var tempPoint2 = new Vector3();
4161
+ var pIndex = position.length - 1;
4162
+ var nIndex = normal.length - 1;
4163
+ var uIndex = uv.length - 1;
4164
+ var iIndex = indices.length - 1;
4458
4165
 
4459
4166
  function addVertices(pathPoint) {
4460
4167
  var first = position.length === 0;
@@ -4505,31 +4212,135 @@ function generatePathVertexData(pathPointList, options) {
4505
4212
  tempPoint2.copy(dir).setLength(_dist).add(tempPoint1);
4506
4213
 
4507
4214
  if (sideOffset > 0) {
4508
- position.push(tempPoint1.x, tempPoint1.y, tempPoint1.z, // 6
4509
- right.x, right.y, right.z, // 5
4510
- left.x, left.y, left.z, // 4
4511
- right.x, right.y, right.z, // 3
4512
- tempPoint2.x, tempPoint2.y, tempPoint2.z, // 2
4513
- right.x, right.y, right.z // 1
4514
- );
4215
+ position[++pIndex] = tempPoint1.x;
4216
+ position[++pIndex] = tempPoint1.y;
4217
+ position[++pIndex] = tempPoint1.z;
4218
+ position[++pIndex] = right.x;
4219
+ position[++pIndex] = right.y;
4220
+ position[++pIndex] = right.z;
4221
+ position[++pIndex] = left.x;
4222
+ position[++pIndex] = left.y;
4223
+ position[++pIndex] = left.z;
4224
+ position[++pIndex] = right.x;
4225
+ position[++pIndex] = right.y;
4226
+ position[++pIndex] = right.z;
4227
+ position[++pIndex] = tempPoint2.x;
4228
+ position[++pIndex] = tempPoint2.y;
4229
+ position[++pIndex] = tempPoint2.z;
4230
+ position[++pIndex] = right.x;
4231
+ position[++pIndex] = right.y;
4232
+ position[++pIndex] = right.z; // position.push(
4233
+ // tempPoint1.x, tempPoint1.y, tempPoint1.z, // 6
4234
+ // right.x, right.y, right.z, // 5
4235
+ // left.x, left.y, left.z, // 4
4236
+ // right.x, right.y, right.z, // 3
4237
+ // tempPoint2.x, tempPoint2.y, tempPoint2.z, // 2
4238
+ // right.x, right.y, right.z // 1
4239
+ // );
4240
+
4515
4241
  verticesCount += 6;
4516
- indices.push(verticesCount - 6, verticesCount - 8, verticesCount - 7, verticesCount - 6, verticesCount - 7, verticesCount - 5, verticesCount - 4, verticesCount - 6, verticesCount - 5, verticesCount - 2, verticesCount - 4, verticesCount - 1);
4242
+ indices[++iIndex] = verticesCount - 6;
4243
+ indices[++iIndex] = verticesCount - 8;
4244
+ indices[++iIndex] = verticesCount - 7;
4245
+ indices[++iIndex] = verticesCount - 6;
4246
+ indices[++iIndex] = verticesCount - 7;
4247
+ indices[++iIndex] = verticesCount - 5;
4248
+ indices[++iIndex] = verticesCount - 4;
4249
+ indices[++iIndex] = verticesCount - 6;
4250
+ indices[++iIndex] = verticesCount - 5;
4251
+ indices[++iIndex] = verticesCount - 2;
4252
+ indices[++iIndex] = verticesCount - 4;
4253
+ indices[++iIndex] = verticesCount - 1; // indices.push(
4254
+ // verticesCount - 6, verticesCount - 8, verticesCount - 7,
4255
+ // verticesCount - 6, verticesCount - 7, verticesCount - 5,
4256
+ // verticesCount - 4, verticesCount - 6, verticesCount - 5,
4257
+ // verticesCount - 2, verticesCount - 4, verticesCount - 1
4258
+ // );
4259
+
4517
4260
  count += 12;
4518
4261
  } else {
4519
- position.push(left.x, left.y, left.z, // 6
4520
- tempPoint1.x, tempPoint1.y, tempPoint1.z, // 5
4521
- left.x, left.y, left.z, // 4
4522
- right.x, right.y, right.z, // 3
4523
- left.x, left.y, left.z, // 2
4524
- tempPoint2.x, tempPoint2.y, tempPoint2.z // 1
4525
- );
4262
+ position[++pIndex] = left.x;
4263
+ position[++pIndex] = left.y;
4264
+ position[++pIndex] = left.z;
4265
+ position[++pIndex] = tempPoint1.x;
4266
+ position[++pIndex] = tempPoint1.y;
4267
+ position[++pIndex] = tempPoint1.z;
4268
+ position[++pIndex] = left.x;
4269
+ position[++pIndex] = left.y;
4270
+ position[++pIndex] = left.z;
4271
+ position[++pIndex] = right.x;
4272
+ position[++pIndex] = right.y;
4273
+ position[++pIndex] = right.z;
4274
+ position[++pIndex] = left.x;
4275
+ position[++pIndex] = left.y;
4276
+ position[++pIndex] = left.z;
4277
+ position[++pIndex] = tempPoint2.x;
4278
+ position[++pIndex] = tempPoint2.y;
4279
+ position[++pIndex] = tempPoint2.z; // position.push(
4280
+ // left.x, left.y, left.z, // 6
4281
+ // tempPoint1.x, tempPoint1.y, tempPoint1.z, // 5
4282
+ // left.x, left.y, left.z, // 4
4283
+ // right.x, right.y, right.z, // 3
4284
+ // left.x, left.y, left.z, // 2
4285
+ // tempPoint2.x, tempPoint2.y, tempPoint2.z // 1
4286
+ // );
4287
+
4526
4288
  verticesCount += 6;
4527
- indices.push(verticesCount - 6, verticesCount - 8, verticesCount - 7, verticesCount - 6, verticesCount - 7, verticesCount - 5, verticesCount - 6, verticesCount - 5, verticesCount - 3, verticesCount - 2, verticesCount - 3, verticesCount - 1);
4289
+ indices[++iIndex] = verticesCount - 6;
4290
+ indices[++iIndex] = verticesCount - 8;
4291
+ indices[++iIndex] = verticesCount - 7;
4292
+ indices[++iIndex] = verticesCount - 6;
4293
+ indices[++iIndex] = verticesCount - 7;
4294
+ indices[++iIndex] = verticesCount - 5;
4295
+ indices[++iIndex] = verticesCount - 6;
4296
+ indices[++iIndex] = verticesCount - 5;
4297
+ indices[++iIndex] = verticesCount - 3;
4298
+ indices[++iIndex] = verticesCount - 2;
4299
+ indices[++iIndex] = verticesCount - 3;
4300
+ indices[++iIndex] = verticesCount - 1; // indices.push(
4301
+ // verticesCount - 6, verticesCount - 8, verticesCount - 7,
4302
+ // verticesCount - 6, verticesCount - 7, verticesCount - 5,
4303
+ // verticesCount - 6, verticesCount - 5, verticesCount - 3,
4304
+ // verticesCount - 2, verticesCount - 3, verticesCount - 1
4305
+ // );
4306
+
4528
4307
  count += 12;
4529
4308
  }
4530
4309
 
4531
- normal.push(up.x, up.y, up.z, up.x, up.y, up.z, up.x, up.y, up.z, up.x, up.y, up.z, up.x, up.y, up.z, up.x, up.y, up.z);
4532
- uv.push(uvDist - sharpUvOffset, 0, uvDist - sharpUvOffset, 1, uvDist, 0, uvDist, 1, uvDist + sharpUvOffset, 0, uvDist + sharpUvOffset, 1); // if (generateUv2) {
4310
+ for (var i = 0; i < 6; i++) {
4311
+ normal[++nIndex] = up.x;
4312
+ normal[++nIndex] = up.y;
4313
+ normal[++nIndex] = up.z;
4314
+ } // normal.push(
4315
+ // up.x, up.y, up.z,
4316
+ // up.x, up.y, up.z,
4317
+ // up.x, up.y, up.z,
4318
+ // up.x, up.y, up.z,
4319
+ // up.x, up.y, up.z,
4320
+ // up.x, up.y, up.z
4321
+ // );
4322
+
4323
+
4324
+ uv[++uIndex] = uvDist - sharpUvOffset;
4325
+ uv[++uIndex] = 0;
4326
+ uv[++uIndex] = uvDist - sharpUvOffset;
4327
+ uv[++uIndex] = 1;
4328
+ uv[++uIndex] = uvDist;
4329
+ uv[++uIndex] = 0;
4330
+ uv[++uIndex] = uvDist;
4331
+ uv[++uIndex] = 1;
4332
+ uv[++uIndex] = uvDist + sharpUvOffset;
4333
+ uv[++uIndex] = 0;
4334
+ uv[++uIndex] = uvDist + sharpUvOffset;
4335
+ uv[++uIndex] = 1; // uv.push(
4336
+ // uvDist - sharpUvOffset, 0,
4337
+ // uvDist - sharpUvOffset, 1,
4338
+ // uvDist, 0,
4339
+ // uvDist, 1,
4340
+ // uvDist + sharpUvOffset, 0,
4341
+ // uvDist + sharpUvOffset, 1
4342
+ // );
4343
+ // if (generateUv2) {
4533
4344
  // uv2.push(
4534
4345
  // uvDist2 - sharpUvOffset2, 0,
4535
4346
  // uvDist2 - sharpUvOffset2, 1,
@@ -4540,9 +4351,34 @@ function generatePathVertexData(pathPointList, options) {
4540
4351
  // );
4541
4352
  // }
4542
4353
  } else {
4543
- position.push(left.x, left.y, left.z, right.x, right.y, right.z);
4544
- normal.push(up.x, up.y, up.z, up.x, up.y, up.z);
4545
- uv.push(uvDist, 0, uvDist, 1); // if (generateUv2) {
4354
+ position[++pIndex] = left.x;
4355
+ position[++pIndex] = left.y;
4356
+ position[++pIndex] = left.z;
4357
+ position[++pIndex] = right.x;
4358
+ position[++pIndex] = right.y;
4359
+ position[++pIndex] = right.z; // position.push(
4360
+ // left.x, left.y, left.z,
4361
+ // right.x, right.y, right.z
4362
+ // );
4363
+
4364
+ normal[++nIndex] = up.x;
4365
+ normal[++nIndex] = up.y;
4366
+ normal[++nIndex] = up.z;
4367
+ normal[++nIndex] = up.x;
4368
+ normal[++nIndex] = up.y;
4369
+ normal[++nIndex] = up.z; // normal.push(
4370
+ // up.x, up.y, up.z,
4371
+ // up.x, up.y, up.z
4372
+ // );
4373
+
4374
+ uv[++uIndex] = uvDist;
4375
+ uv[++uIndex] = 0;
4376
+ uv[++uIndex] = uvDist;
4377
+ uv[++uIndex] = 1; // uv.push(
4378
+ // uvDist, 0,
4379
+ // uvDist, 1
4380
+ // );
4381
+ // if (generateUv2) {
4546
4382
  // uv2.push(
4547
4383
  // uvDist2, 0,
4548
4384
  // uvDist2, 1
@@ -4552,7 +4388,16 @@ function generatePathVertexData(pathPointList, options) {
4552
4388
  verticesCount += 2;
4553
4389
 
4554
4390
  if (!first) {
4555
- indices.push(verticesCount - 2, verticesCount - 4, verticesCount - 3, verticesCount - 2, verticesCount - 3, verticesCount - 1);
4391
+ indices[++iIndex] = verticesCount - 2;
4392
+ indices[++iIndex] = verticesCount - 4;
4393
+ indices[++iIndex] = verticesCount - 3;
4394
+ indices[++iIndex] = verticesCount - 2;
4395
+ indices[++iIndex] = verticesCount - 3;
4396
+ indices[++iIndex] = verticesCount - 1; // indices.push(
4397
+ // verticesCount - 2, verticesCount - 4, verticesCount - 3,
4398
+ // verticesCount - 2, verticesCount - 3, verticesCount - 1
4399
+ // );
4400
+
4556
4401
  count += 6;
4557
4402
  }
4558
4403
  }
@@ -4581,15 +4426,16 @@ function generatePathVertexData(pathPointList, options) {
4581
4426
  }
4582
4427
 
4583
4428
  return {
4584
- points: position,
4429
+ position: position,
4585
4430
  normal: normal,
4586
- uvs: uv,
4587
- index: indices,
4431
+ uv: uv,
4432
+ indices: indices,
4588
4433
  count: count
4589
4434
  };
4590
4435
  }
4591
4436
 
4592
4437
  var UP = new Vector3(0, 0, 1);
4438
+ var normalDir = new Vector3();
4593
4439
  function expandTubes(lines, options) {
4594
4440
  options = Object.assign({}, {
4595
4441
  radius: 1,
@@ -4598,19 +4444,14 @@ function expandTubes(lines, options) {
4598
4444
  startRad: -Math.PI / 4
4599
4445
  }, options);
4600
4446
  var results = lines.map(function (line) {
4601
- var points = line.map(function (p) {
4602
- var x = p[0],
4603
- y = p[1],
4604
- z = p[2];
4605
- return new Vector3(x, y, z || 0);
4606
- });
4447
+ var points = line2Vectors(line);
4607
4448
  var pathPointList = new PathPointList();
4608
4449
  pathPointList.set(points, options.cornerRadius, options.cornerSplit, UP);
4609
4450
  var result = generateTubeVertexData(pathPointList, options);
4610
4451
  result.line = line;
4611
4452
  result.position = new Float32Array(result.points);
4612
- result.indices = new Uint32Array(result.index);
4613
- result.uv = new Float32Array(result.uvs);
4453
+ result.indices = new Uint32Array(result.indices);
4454
+ result.uv = new Float32Array(result.uv);
4614
4455
  result.normal = new Float32Array(result.normal);
4615
4456
  return result;
4616
4457
  });
@@ -4637,11 +4478,10 @@ function generateTubeVertexData(pathPointList, options) {
4637
4478
 
4638
4479
  var points = [];
4639
4480
  var normal = [];
4640
- var uvs = []; // const uv2 = [];
4481
+ var uv = []; // const uv2 = [];
4641
4482
 
4642
- var index = [];
4483
+ var indices = [];
4643
4484
  var verticesCount = 0;
4644
- var normalDir = new Vector3();
4645
4485
  var pIndex = -1;
4646
4486
  var nIndex = -1;
4647
4487
  var uIndex = -1;
@@ -4666,8 +4506,8 @@ function generateTubeVertexData(pathPointList, options) {
4666
4506
  normal[++nIndex] = normalDir.x;
4667
4507
  normal[++nIndex] = normalDir.y;
4668
4508
  normal[++nIndex] = normalDir.z;
4669
- uvs[++uIndex] = uvDist;
4670
- uvs[++uIndex] = i / radialSegments; // uvs.push(uvDist, r / radialSegments);
4509
+ uv[++uIndex] = uvDist;
4510
+ uv[++uIndex] = i / radialSegments; // uvs.push(uvDist, r / radialSegments);
4671
4511
  // if (generateUv2) {
4672
4512
  // uv2.push(uvDist2, r / radialSegments);
4673
4513
  // }
@@ -4680,12 +4520,12 @@ function generateTubeVertexData(pathPointList, options) {
4680
4520
  var begin2 = verticesCount - (radialSegments + 1);
4681
4521
 
4682
4522
  for (var _i = 0; _i < radialSegments; _i++) {
4683
- index[++iIndex] = begin2 + _i;
4684
- index[++iIndex] = begin1 + _i;
4685
- index[++iIndex] = begin1 + _i + 1;
4686
- index[++iIndex] = begin2 + _i;
4687
- index[++iIndex] = begin1 + _i + 1;
4688
- index[++iIndex] = begin2 + _i + 1; // index.push(
4523
+ indices[++iIndex] = begin2 + _i;
4524
+ indices[++iIndex] = begin1 + _i;
4525
+ indices[++iIndex] = begin1 + _i + 1;
4526
+ indices[++iIndex] = begin2 + _i;
4527
+ indices[++iIndex] = begin1 + _i + 1;
4528
+ indices[++iIndex] = begin2 + _i + 1; // index.push(
4689
4529
  // begin2 + i,
4690
4530
  // begin1 + i,
4691
4531
  // begin1 + i + 1,
@@ -4720,9 +4560,9 @@ function generateTubeVertexData(pathPointList, options) {
4720
4560
  return {
4721
4561
  points: points,
4722
4562
  normal: normal,
4723
- uvs: uvs,
4563
+ uv: uv,
4724
4564
  // uv2,
4725
- index: index,
4565
+ indices: indices,
4726
4566
  count: count
4727
4567
  };
4728
4568
  }