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