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