poly-extrude 0.9.0 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * poly-extrude v0.9.0
2
+ * poly-extrude v0.10.0
3
3
  */
4
4
  (function (global, factory) {
5
5
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
@@ -670,2507 +670,2154 @@
670
670
 
671
671
  var earcut$1 = earcut$2.exports;
672
672
 
673
- /**
674
- * https://github.com/Turfjs/turf/blob/master/packages/turf-boolean-clockwise/index.ts
675
- * @param {*} ring
676
- * @returns
677
- */
678
- function isClockwise(ring) {
679
- var sum = 0;
680
- var i = 1;
681
- var prev;
682
- var cur;
683
- var len = ring.length;
684
-
685
- while (i < len) {
686
- prev = cur || ring[0];
687
- cur = ring[i];
688
- sum += (cur[0] - prev[0]) * (cur[1] + prev[1]);
689
- i++;
673
+ function _defineProperties(target, props) {
674
+ for (var i = 0; i < props.length; i++) {
675
+ var descriptor = props[i];
676
+ descriptor.enumerable = descriptor.enumerable || false;
677
+ descriptor.configurable = true;
678
+ if ("value" in descriptor) descriptor.writable = true;
679
+ Object.defineProperty(target, descriptor.key, descriptor);
690
680
  }
691
-
692
- return sum > 0;
693
681
  }
694
682
 
695
- function v3Sub(out, v1, v2) {
696
- out[0] = v1[0] - v2[0];
697
- out[1] = v1[1] - v2[1];
698
- out[2] = v1[2] - v2[2];
699
- return out;
683
+ function _createClass(Constructor, protoProps, staticProps) {
684
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
685
+ if (staticProps) _defineProperties(Constructor, staticProps);
686
+ Object.defineProperty(Constructor, "prototype", {
687
+ writable: false
688
+ });
689
+ return Constructor;
700
690
  }
701
691
 
702
- function v3Normalize(out, v) {
703
- var x = v[0];
704
- var y = v[1];
705
- var z = v[2];
706
- var d = Math.sqrt(x * x + y * y + z * z) || 1;
707
- out[0] = x / d;
708
- out[1] = y / d;
709
- out[2] = z / d;
710
- return out;
692
+ function _inheritsLoose(subClass, superClass) {
693
+ subClass.prototype = Object.create(superClass.prototype);
694
+ subClass.prototype.constructor = subClass;
695
+
696
+ _setPrototypeOf(subClass, superClass);
711
697
  }
712
698
 
713
- function v3Cross(out, v1, v2) {
714
- var ax = v1[0],
715
- ay = v1[1],
716
- az = v1[2],
717
- bx = v2[0],
718
- by = v2[1],
719
- bz = v2[2];
720
- out[0] = ay * bz - az * by;
721
- out[1] = az * bx - ax * bz;
722
- out[2] = ax * by - ay * bx;
723
- return out;
699
+ function _setPrototypeOf(o, p) {
700
+ _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
701
+ o.__proto__ = p;
702
+ return o;
703
+ };
704
+ return _setPrototypeOf(o, p);
724
705
  }
725
706
 
726
- function generateNormal(indices, position) {
727
- function v3Set(p, a, b, c) {
728
- p[0] = a;
729
- p[1] = b;
730
- p[2] = c;
731
- }
707
+ // code copy from https://github.com/mrdoob/three.js/blob/dev/src/math/Quaternion.js
708
+ // import { clamp } from './MathUtils.js';
709
+ var Quaternion = /*#__PURE__*/function () {
710
+ function Quaternion(x, y, z, w) {
711
+ if (x === void 0) {
712
+ x = 0;
713
+ }
732
714
 
733
- var p1 = [];
734
- var p2 = [];
735
- var p3 = [];
736
- var v21 = [];
737
- var v32 = [];
738
- var n = [];
739
- var len = indices.length;
740
- var normals = new Float32Array(position.length);
741
- var f = 0;
715
+ if (y === void 0) {
716
+ y = 0;
717
+ }
742
718
 
743
- while (f < len) {
744
- // const i1 = indices[f++] * 3;
745
- // const i2 = indices[f++] * 3;
746
- // const i3 = indices[f++] * 3;
747
- // const i1 = indices[f];
748
- // const i2 = indices[f + 1];
749
- // const i3 = indices[f + 2];
750
- var a = indices[f],
751
- b = indices[f + 1],
752
- c = indices[f + 2];
753
- var i1 = a * 3,
754
- i2 = b * 3,
755
- i3 = c * 3;
756
- v3Set(p1, position[i1], position[i1 + 1], position[i1 + 2]);
757
- v3Set(p2, position[i2], position[i2 + 1], position[i2 + 2]);
758
- v3Set(p3, position[i3], position[i3 + 1], position[i3 + 2]);
759
- v3Sub(v32, p3, p2);
760
- v3Sub(v21, p1, p2);
761
- v3Cross(n, v32, v21); // Already be weighted by the triangle area
719
+ if (z === void 0) {
720
+ z = 0;
721
+ }
762
722
 
763
- for (var _i = 0; _i < 3; _i++) {
764
- normals[i1 + _i] += n[_i];
765
- normals[i2 + _i] += n[_i];
766
- normals[i3 + _i] += n[_i];
723
+ if (w === void 0) {
724
+ w = 1;
767
725
  }
768
726
 
769
- f += 3;
727
+ this.isQuaternion = true;
728
+ this._x = x;
729
+ this._y = y;
730
+ this._z = z;
731
+ this._w = w;
770
732
  }
771
733
 
772
- var i = 0;
773
- var l = normals.length;
774
-
775
- while (i < l) {
776
- v3Set(n, normals[i], normals[i + 1], normals[i + 2]);
777
- v3Normalize(n, n);
778
- normals[i] = n[0] || 0;
779
- normals[i + 1] = n[1] || 0;
780
- normals[i + 2] = n[2] || 0;
781
- i += 3;
782
- }
734
+ Quaternion.slerpFlat = function slerpFlat(dst, dstOffset, src0, srcOffset0, src1, srcOffset1, t) {
735
+ // fuzz-free, array-based Quaternion SLERP operation
736
+ var x0 = src0[srcOffset0 + 0],
737
+ y0 = src0[srcOffset0 + 1],
738
+ z0 = src0[srcOffset0 + 2],
739
+ w0 = src0[srcOffset0 + 3];
740
+ var x1 = src1[srcOffset1 + 0],
741
+ y1 = src1[srcOffset1 + 1],
742
+ z1 = src1[srcOffset1 + 2],
743
+ w1 = src1[srcOffset1 + 3];
783
744
 
784
- return normals;
785
- }
786
- function merge(results) {
787
- if (results.length === 1) {
788
- var _result = {
789
- position: results[0].position,
790
- normal: results[0].normal,
791
- uv: results[0].uv,
792
- indices: results[0].indices,
793
- results: results
794
- };
795
- return _result;
796
- }
745
+ if (t === 0) {
746
+ dst[dstOffset + 0] = x0;
747
+ dst[dstOffset + 1] = y0;
748
+ dst[dstOffset + 2] = z0;
749
+ dst[dstOffset + 3] = w0;
750
+ return;
751
+ }
797
752
 
798
- var plen = 0,
799
- ilen = 0;
753
+ if (t === 1) {
754
+ dst[dstOffset + 0] = x1;
755
+ dst[dstOffset + 1] = y1;
756
+ dst[dstOffset + 2] = z1;
757
+ dst[dstOffset + 3] = w1;
758
+ return;
759
+ }
800
760
 
801
- for (var i = 0, len = results.length; i < len; i++) {
802
- var _results$i = results[i],
803
- position = _results$i.position,
804
- indices = _results$i.indices;
805
- plen += position.length;
806
- ilen += indices.length;
807
- }
761
+ if (w0 !== w1 || x0 !== x1 || y0 !== y1 || z0 !== z1) {
762
+ var s = 1 - t;
763
+ var cos = x0 * x1 + y0 * y1 + z0 * z1 + w0 * w1,
764
+ dir = cos >= 0 ? 1 : -1,
765
+ sqrSin = 1 - cos * cos; // Skip the Slerp for tiny steps to avoid numeric problems:
808
766
 
809
- var result = {
810
- position: new Float32Array(plen),
811
- normal: new Float32Array(plen),
812
- uv: new Float32Array(plen / 3 * 2),
813
- indices: new Uint32Array(ilen),
814
- results: results
815
- };
816
- var pOffset = 0,
817
- pCount = 0,
818
- iIdx = 0,
819
- uvOffset = 0;
767
+ if (sqrSin > Number.EPSILON) {
768
+ var sin = Math.sqrt(sqrSin),
769
+ len = Math.atan2(sin, cos * dir);
770
+ s = Math.sin(s * len) / sin;
771
+ t = Math.sin(t * len) / sin;
772
+ }
820
773
 
821
- for (var _i2 = 0, _len = results.length; _i2 < _len; _i2++) {
822
- var _results$_i = results[_i2],
823
- _position = _results$_i.position,
824
- _indices = _results$_i.indices,
825
- normal = _results$_i.normal,
826
- uv = _results$_i.uv;
827
- result.position.set(_position, pOffset);
828
- result.normal.set(normal, pOffset);
829
- result.uv.set(uv, uvOffset);
830
- var j = 0;
831
- var len1 = _indices.length;
774
+ var tDir = t * dir;
775
+ x0 = x0 * s + x1 * tDir;
776
+ y0 = y0 * s + y1 * tDir;
777
+ z0 = z0 * s + z1 * tDir;
778
+ w0 = w0 * s + w1 * tDir; // Normalize in case we just did a lerp:
832
779
 
833
- while (j < len1) {
834
- var pIndex = _indices[j] + pCount;
835
- result.indices[iIdx] = pIndex;
836
- iIdx++;
837
- j++;
780
+ if (s === 1 - t) {
781
+ var f = 1 / Math.sqrt(x0 * x0 + y0 * y0 + z0 * z0 + w0 * w0);
782
+ x0 *= f;
783
+ y0 *= f;
784
+ z0 *= f;
785
+ w0 *= f;
786
+ }
838
787
  }
839
788
 
840
- uvOffset += uv.length;
841
- pOffset += _position.length;
842
- pCount += _position.length / 3;
843
- }
844
-
845
- return result;
846
- }
847
- function radToDeg(rad) {
848
- return rad * 180 / Math.PI;
849
- }
850
- function degToRad(angle) {
851
- return angle / 180 * Math.PI;
852
- } // https://github.com/mrdoob/three.js/blob/16f13e3b07e31d0e9a00df7c3366bbe0e464588c/src/geometries/ExtrudeGeometry.js?_pjax=%23js-repo-pjax-container#L736
789
+ dst[dstOffset] = x0;
790
+ dst[dstOffset + 1] = y0;
791
+ dst[dstOffset + 2] = z0;
792
+ dst[dstOffset + 3] = w0;
793
+ };
853
794
 
854
- function generateSideWallUV(uvs, vertices, indexA, indexB, indexC, indexD) {
855
- var idx1 = indexA * 3,
856
- idx2 = indexB * 3,
857
- idx3 = indexC * 3,
858
- idx4 = indexD * 3;
859
- var a_x = vertices[idx1];
860
- var a_y = vertices[idx1 + 1];
861
- var a_z = vertices[idx1 + 2];
862
- var b_x = vertices[idx2];
863
- var b_y = vertices[idx2 + 1];
864
- var b_z = vertices[idx2 + 2];
865
- var c_x = vertices[idx3];
866
- var c_y = vertices[idx3 + 1];
867
- var c_z = vertices[idx3 + 2];
868
- var d_x = vertices[idx4];
869
- var d_y = vertices[idx4 + 1];
870
- var d_z = vertices[idx4 + 2];
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
+ } // _onChangeCallback() { }
1222
+ // * [Symbol.iterator]() {
1223
+ // yield this._x;
1224
+ // yield this._y;
1225
+ // yield this._z;
1226
+ // yield this._w;
1227
+ // }
1228
+ ;
1460
1229
 
1461
- if (!point1 || !point2) {
1462
- continue;
1463
- }
1230
+ _createClass(Quaternion, [{
1231
+ key: "x",
1232
+ get: function get() {
1233
+ return this._x;
1234
+ },
1235
+ set: function set(value) {
1236
+ this._x = value;
1464
1237
 
1465
- op1 = [point1[0], point1[1]];
1466
- op2 = [point2[0], point2[1]];
1238
+ this._onChangeCallback();
1467
1239
  }
1240
+ }, {
1241
+ key: "y",
1242
+ get: function get() {
1243
+ return this._y;
1244
+ },
1245
+ set: function set(value) {
1246
+ this._y = value;
1468
1247
 
1469
- op1[2] = currentp[2] || 0;
1470
- op2[2] = currentp[2] || 0; // const [op1, op2] = calOffsetPoint(rRad, radius, p1);
1471
-
1472
- points.push(op1, op2);
1248
+ this._onChangeCallback();
1249
+ }
1250
+ }, {
1251
+ key: "z",
1252
+ get: function get() {
1253
+ return this._z;
1254
+ },
1255
+ set: function set(value) {
1256
+ this._z = value;
1473
1257
 
1474
- if (leftOnLine(op1, p1, p2)) {
1475
- leftPoints.push(op1);
1476
- rightPoints.push(op2);
1477
- } else {
1478
- leftPoints.push(op2);
1479
- rightPoints.push(op1);
1258
+ this._onChangeCallback();
1480
1259
  }
1260
+ }, {
1261
+ key: "w",
1262
+ get: function get() {
1263
+ return this._w;
1264
+ },
1265
+ set: function set(value) {
1266
+ this._w = value;
1481
1267
 
1482
- i++;
1483
- }
1268
+ this._onChangeCallback();
1269
+ }
1270
+ }]);
1484
1271
 
1485
- return {
1486
- offsetPoints: points,
1487
- leftPoints: leftPoints,
1488
- rightPoints: rightPoints
1489
- };
1490
- } // eslint-disable-next-line no-unused-vars
1272
+ return Quaternion;
1273
+ }();
1491
1274
 
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
- };
1275
+ // import * as MathUtils from './MathUtils.js';
1502
1276
 
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
- */
1277
+ var _quaternion = new Quaternion();
1519
1278
 
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
- */
1279
+ var Vector3 = /*#__PURE__*/function () {
1280
+ function Vector3(x, y, z) {
1281
+ if (x === void 0) {
1282
+ x = 0;
1283
+ }
1544
1284
 
1285
+ if (y === void 0) {
1286
+ y = 0;
1287
+ }
1545
1288
 
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];
1289
+ if (z === void 0) {
1290
+ z = 0;
1291
+ }
1551
1292
 
1552
- if (dx1 === 0 && dx2 === 0) {
1553
- return null;
1293
+ this.x = x;
1294
+ this.y = y;
1295
+ this.z = z;
1554
1296
  }
1555
1297
 
1556
- if (dy1 === 0 && dy2 === 0) {
1557
- return null;
1558
- }
1298
+ var _proto = Vector3.prototype;
1559
1299
 
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;
1300
+ _proto.set = function set(x, y, z) {
1301
+ if (z === undefined) z = this.z; // sprite.scale.set(x,y)
1565
1302
 
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
1654
-
1655
- iIndex = indices.length - 1;
1303
+ this.x = x;
1304
+ this.y = y;
1305
+ this.z = z;
1306
+ return this;
1307
+ } // setScalar(scalar) {
1308
+ // this.x = scalar;
1309
+ // this.y = scalar;
1310
+ // this.z = scalar;
1311
+ // return this;
1312
+ // }
1313
+ // setX(x) {
1314
+ // this.x = x;
1315
+ // return this;
1316
+ // }
1317
+ // setY(y) {
1318
+ // this.y = y;
1319
+ // return this;
1320
+ // }
1321
+ // setZ(z) {
1322
+ // this.z = z;
1323
+ // return this;
1324
+ // }
1325
+ // setComponent(index, value) {
1326
+ // switch (index) {
1327
+ // case 0: this.x = value; break;
1328
+ // case 1: this.y = value; break;
1329
+ // case 2: this.z = value; break;
1330
+ // default: throw new Error('index is out of range: ' + index);
1331
+ // }
1332
+ // return this;
1333
+ // }
1334
+ // getComponent(index) {
1335
+ // switch (index) {
1336
+ // case 0: return this.x;
1337
+ // case 1: return this.y;
1338
+ // case 2: return this.z;
1339
+ // default: throw new Error('index is out of range: ' + index);
1340
+ // }
1341
+ // }
1342
+ ;
1656
1343
 
1657
- for (var _i = 0; _i < indicesLen; _i++) {
1658
- var index = indices[_i];
1659
- indices[++iIndex] = index + circlePointsLen; // indices.push(index + circlePointsLen);
1660
- }
1344
+ _proto.clone = function clone() {
1345
+ return new this.constructor(this.x, this.y, this.z);
1346
+ };
1661
1347
 
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;
1348
+ _proto.copy = function copy(v) {
1349
+ this.x = v.x;
1350
+ this.y = v.y;
1351
+ this.z = v.z;
1352
+ return this;
1353
+ };
1668
1354
 
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);
1355
+ _proto.add = function add(v) {
1356
+ this.x += v.x;
1357
+ this.y += v.y;
1358
+ this.z += v.z;
1359
+ return this;
1360
+ };
1690
1361
 
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);
1362
+ _proto.addScalar = function addScalar(s) {
1363
+ this.x += s;
1364
+ this.y += s;
1365
+ this.z += s;
1366
+ return this;
1367
+ };
1697
1368
 
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);
1369
+ _proto.addVectors = function addVectors(a, b) {
1370
+ this.x = a.x + b.x;
1371
+ this.y = a.y + b.y;
1372
+ this.z = a.z + b.z;
1373
+ return this;
1374
+ };
1709
1375
 
1710
- uIdx++;
1711
- }
1376
+ _proto.addScaledVector = function addScaledVector(v, s) {
1377
+ this.x += v.x * s;
1378
+ this.y += v.y * s;
1379
+ this.z += v.z * s;
1380
+ return this;
1381
+ };
1712
1382
 
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)
1383
+ _proto.sub = function sub(v) {
1384
+ this.x -= v.x;
1385
+ this.y -= v.y;
1386
+ this.z -= v.z;
1387
+ return this;
1723
1388
  };
1724
- }
1725
1389
 
1726
- function _regeneratorRuntime() {
1727
- /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
1390
+ _proto.subScalar = function subScalar(s) {
1391
+ this.x -= s;
1392
+ this.y -= s;
1393
+ this.z -= s;
1394
+ return this;
1395
+ };
1728
1396
 
1729
- _regeneratorRuntime = function () {
1730
- return exports;
1397
+ _proto.subVectors = function subVectors(a, b) {
1398
+ this.x = a.x - b.x;
1399
+ this.y = a.y - b.y;
1400
+ this.z = a.z - b.z;
1401
+ return this;
1731
1402
  };
1732
1403
 
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
- }
1404
+ _proto.multiply = function multiply(v) {
1405
+ this.x *= v.x;
1406
+ this.y *= v.y;
1407
+ this.z *= v.z;
1408
+ return this;
1409
+ };
1749
1410
 
1750
- try {
1751
- define({}, "");
1752
- } catch (err) {
1753
- define = function (obj, key, value) {
1754
- return obj[key] = value;
1755
- };
1756
- }
1411
+ _proto.multiplyScalar = function multiplyScalar(scalar) {
1412
+ this.x *= scalar;
1413
+ this.y *= scalar;
1414
+ this.z *= scalar;
1415
+ return this;
1416
+ };
1757
1417
 
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
- }
1418
+ _proto.multiplyVectors = function multiplyVectors(a, b) {
1419
+ this.x = a.x * b.x;
1420
+ this.y = a.y * b.y;
1421
+ this.z = a.z * b.z;
1422
+ return this;
1423
+ } // applyEuler(euler) {
1424
+ // return this.applyQuaternion(_quaternion.setFromEuler(euler));
1425
+ // }
1426
+ ;
1771
1427
 
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() {}
1428
+ _proto.applyAxisAngle = function applyAxisAngle(axis, angle) {
1429
+ return this.applyQuaternion(_quaternion.setFromAxisAngle(axis, angle));
1430
+ } // applyMatrix3(m) {
1431
+ // const x = this.x, y = this.y, z = this.z;
1432
+ // const e = m.elements;
1433
+ // this.x = e[0] * x + e[3] * y + e[6] * z;
1434
+ // this.y = e[1] * x + e[4] * y + e[7] * z;
1435
+ // this.z = e[2] * x + e[5] * y + e[8] * z;
1436
+ // return this;
1437
+ // }
1438
+ // applyNormalMatrix(m) {
1439
+ // return this.applyMatrix3(m).normalize();
1440
+ // }
1441
+ ;
1827
1442
 
1828
- var IteratorPrototype = {};
1829
- define(IteratorPrototype, iteratorSymbol, function () {
1443
+ _proto.applyMatrix4 = function applyMatrix4(m) {
1444
+ var x = this.x,
1445
+ y = this.y,
1446
+ z = this.z;
1447
+ var e = m.elements;
1448
+ var w = 1 / (e[3] * x + e[7] * y + e[11] * z + e[15]);
1449
+ this.x = (e[0] * x + e[4] * y + e[8] * z + e[12]) * w;
1450
+ this.y = (e[1] * x + e[5] * y + e[9] * z + e[13]) * w;
1451
+ this.z = (e[2] * x + e[6] * y + e[10] * z + e[14]) * w;
1830
1452
  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
- }
1453
+ };
1932
1454
 
1933
- return {
1934
- next: doneResult
1935
- };
1936
- }
1455
+ _proto.applyQuaternion = function applyQuaternion(q) {
1456
+ var x = this.x,
1457
+ y = this.y,
1458
+ z = this.z;
1459
+ var qx = q.x,
1460
+ qy = q.y,
1461
+ qz = q.z,
1462
+ qw = q.w; // calculate quat * vector
1937
1463
 
1938
- function doneResult() {
1939
- return {
1940
- value: undefined,
1941
- done: !0
1942
- };
1943
- }
1464
+ var ix = qw * x + qy * z - qz * y;
1465
+ var iy = qw * y + qz * x - qx * z;
1466
+ var iz = qw * z + qx * y - qy * x;
1467
+ var iw = -qx * x - qy * y - qz * z; // calculate result * inverse quat
1944
1468
 
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 () {
1469
+ this.x = ix * qw + iw * -qx + iy * -qz - iz * -qy;
1470
+ this.y = iy * qw + iw * -qy + iz * -qx - ix * -qz;
1471
+ this.z = iz * qw + iw * -qz + ix * -qy - iy * -qx;
1963
1472
  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
- }
1473
+ } // project(camera) {
1474
+ // return this.applyMatrix4(camera.matrixWorldInverse).applyMatrix4(camera.projectionMatrix);
1475
+ // }
1476
+ // unproject(camera) {
1477
+ // return this.applyMatrix4(camera.projectionMatrixInverse).applyMatrix4(camera.matrixWorld);
1478
+ // }
1479
+ // transformDirection(m) {
1480
+ // // input: THREE.Matrix4 affine matrix
1481
+ // // vector interpreted as a direction
1482
+ // const x = this.x, y = this.y, z = this.z;
1483
+ // const e = m.elements;
1484
+ // this.x = e[0] * x + e[4] * y + e[8] * z;
1485
+ // this.y = e[1] * x + e[5] * y + e[9] * z;
1486
+ // this.z = e[2] * x + e[6] * y + e[10] * z;
1487
+ // return this.normalize();
1488
+ // }
1489
+ ;
2080
1490
 
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
- }
1491
+ _proto.divide = function divide(v) {
1492
+ this.x /= v.x;
1493
+ this.y /= v.y;
1494
+ this.z /= v.z;
1495
+ return this;
1496
+ };
2089
1497
 
2090
- function _inheritsLoose(subClass, superClass) {
2091
- subClass.prototype = Object.create(superClass.prototype);
2092
- subClass.prototype.constructor = subClass;
1498
+ _proto.divideScalar = function divideScalar(scalar) {
1499
+ return this.multiplyScalar(1 / scalar);
1500
+ };
2093
1501
 
2094
- _setPrototypeOf(subClass, superClass);
2095
- }
1502
+ _proto.min = function min(v) {
1503
+ this.x = Math.min(this.x, v.x);
1504
+ this.y = Math.min(this.y, v.y);
1505
+ this.z = Math.min(this.z, v.z);
1506
+ return this;
1507
+ };
2096
1508
 
2097
- function _setPrototypeOf(o, p) {
2098
- _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
2099
- o.__proto__ = p;
2100
- return o;
1509
+ _proto.max = function max(v) {
1510
+ this.x = Math.max(this.x, v.x);
1511
+ this.y = Math.max(this.y, v.y);
1512
+ this.z = Math.max(this.z, v.z);
1513
+ return this;
2101
1514
  };
2102
- return _setPrototypeOf(o, p);
2103
- }
2104
1515
 
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
- }
1516
+ _proto.clamp = function clamp(min, max) {
1517
+ // assumes min < max, componentwise
1518
+ this.x = Math.max(min.x, Math.min(max.x, this.x));
1519
+ this.y = Math.max(min.y, Math.min(max.y, this.y));
1520
+ this.z = Math.max(min.z, Math.min(max.z, this.z));
1521
+ return this;
1522
+ };
2112
1523
 
2113
- if (y === void 0) {
2114
- y = 0;
2115
- }
1524
+ _proto.clampScalar = function clampScalar(minVal, maxVal) {
1525
+ this.x = Math.max(minVal, Math.min(maxVal, this.x));
1526
+ this.y = Math.max(minVal, Math.min(maxVal, this.y));
1527
+ this.z = Math.max(minVal, Math.min(maxVal, this.z));
1528
+ return this;
1529
+ };
2116
1530
 
2117
- if (z === void 0) {
2118
- z = 0;
2119
- }
1531
+ _proto.clampLength = function clampLength(min, max) {
1532
+ var length = this.length();
1533
+ return this.divideScalar(length || 1).multiplyScalar(Math.max(min, Math.min(max, length)));
1534
+ } // floor() {
1535
+ // this.x = Math.floor(this.x);
1536
+ // this.y = Math.floor(this.y);
1537
+ // this.z = Math.floor(this.z);
1538
+ // return this;
1539
+ // }
1540
+ // ceil() {
1541
+ // this.x = Math.ceil(this.x);
1542
+ // this.y = Math.ceil(this.y);
1543
+ // this.z = Math.ceil(this.z);
1544
+ // return this;
1545
+ // }
1546
+ // round() {
1547
+ // this.x = Math.round(this.x);
1548
+ // this.y = Math.round(this.y);
1549
+ // this.z = Math.round(this.z);
1550
+ // return this;
1551
+ // }
1552
+ // roundToZero() {
1553
+ // this.x = (this.x < 0) ? Math.ceil(this.x) : Math.floor(this.x);
1554
+ // this.y = (this.y < 0) ? Math.ceil(this.y) : Math.floor(this.y);
1555
+ // this.z = (this.z < 0) ? Math.ceil(this.z) : Math.floor(this.z);
1556
+ // return this;
1557
+ // }
1558
+ // negate() {
1559
+ // this.x = -this.x;
1560
+ // this.y = -this.y;
1561
+ // this.z = -this.z;
1562
+ // return this;
1563
+ // }
1564
+ ;
2120
1565
 
2121
- if (w === void 0) {
2122
- w = 1;
2123
- }
1566
+ _proto.dot = function dot(v) {
1567
+ return this.x * v.x + this.y * v.y + this.z * v.z;
1568
+ } // TODO lengthSquared?
1569
+ ;
2124
1570
 
2125
- this.isQuaternion = true;
2126
- this._x = x;
2127
- this._y = y;
2128
- this._z = z;
2129
- this._w = w;
2130
- }
1571
+ _proto.lengthSq = function lengthSq() {
1572
+ return this.x * this.x + this.y * this.y + this.z * this.z;
1573
+ };
2131
1574
 
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];
1575
+ _proto.length = function length() {
1576
+ return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
1577
+ } // manhattanLength() {
1578
+ // return Math.abs(this.x) + Math.abs(this.y) + Math.abs(this.z);
1579
+ // }
1580
+ ;
2142
1581
 
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
- }
1582
+ _proto.normalize = function normalize() {
1583
+ return this.divideScalar(this.length() || 1);
1584
+ };
2150
1585
 
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
- }
1586
+ _proto.setLength = function setLength(length) {
1587
+ return this.normalize().multiplyScalar(length);
1588
+ };
2158
1589
 
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:
1590
+ _proto.lerp = function lerp(v, alpha) {
1591
+ this.x += (v.x - this.x) * alpha;
1592
+ this.y += (v.y - this.y) * alpha;
1593
+ this.z += (v.z - this.z) * alpha;
1594
+ return this;
1595
+ };
2164
1596
 
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
- }
1597
+ _proto.lerpVectors = function lerpVectors(v1, v2, alpha) {
1598
+ this.x = v1.x + (v2.x - v1.x) * alpha;
1599
+ this.y = v1.y + (v2.y - v1.y) * alpha;
1600
+ this.z = v1.z + (v2.z - v1.z) * alpha;
1601
+ return this;
1602
+ };
2171
1603
 
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:
1604
+ _proto.cross = function cross(v) {
1605
+ return this.crossVectors(this, v);
1606
+ };
2177
1607
 
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
- }
1608
+ _proto.crossVectors = function crossVectors(a, b) {
1609
+ var ax = a.x,
1610
+ ay = a.y,
1611
+ az = a.z;
1612
+ var bx = b.x,
1613
+ by = b.y,
1614
+ bz = b.z;
1615
+ this.x = ay * bz - az * by;
1616
+ this.y = az * bx - ax * bz;
1617
+ this.z = ax * by - ay * bx;
1618
+ return this;
1619
+ } // projectOnVector(v) {
1620
+ // const denominator = v.lengthSq();
1621
+ // if (denominator === 0) return this.set(0, 0, 0);
1622
+ // const scalar = v.dot(this) / denominator;
1623
+ // return this.copy(v).multiplyScalar(scalar);
1624
+ // }
1625
+ // projectOnPlane(planeNormal) {
1626
+ // _vector.copy(this).projectOnVector(planeNormal);
1627
+ // return this.sub(_vector);
1628
+ // }
1629
+ // reflect(normal) {
1630
+ // // reflect incident vector off plane orthogonal to normal
1631
+ // // normal is assumed to have unit length
1632
+ // return this.sub(_vector.copy(normal).multiplyScalar(2 * this.dot(normal)));
1633
+ // }
1634
+ // angleTo(v) {
1635
+ // const denominator = Math.sqrt(this.lengthSq() * v.lengthSq());
1636
+ // if (denominator === 0) return Math.PI / 2;
1637
+ // const theta = this.dot(v) / denominator;
1638
+ // // clamp, to handle numerical problems
1639
+ // return Math.acos(MathUtils.clamp(theta, -1, 1));
1640
+ // }
1641
+ ;
2186
1642
 
2187
- dst[dstOffset] = x0;
2188
- dst[dstOffset + 1] = y0;
2189
- dst[dstOffset + 2] = z0;
2190
- dst[dstOffset + 3] = w0;
2191
- };
1643
+ _proto.distanceTo = function distanceTo(v) {
1644
+ return Math.sqrt(this.distanceToSquared(v));
1645
+ } // distanceToSquared(v) {
1646
+ // const dx = this.x - v.x, dy = this.y - v.y, dz = this.z - v.z;
1647
+ // return dx * dx + dy * dy + dz * dz;
1648
+ // }
1649
+ // manhattanDistanceTo(v) {
1650
+ // return Math.abs(this.x - v.x) + Math.abs(this.y - v.y) + Math.abs(this.z - v.z);
1651
+ // }
1652
+ // setFromSpherical(s) {
1653
+ // return this.setFromSphericalCoords(s.radius, s.phi, s.theta);
1654
+ // }
1655
+ // setFromSphericalCoords(radius, phi, theta) {
1656
+ // const sinPhiRadius = Math.sin(phi) * radius;
1657
+ // this.x = sinPhiRadius * Math.sin(theta);
1658
+ // this.y = Math.cos(phi) * radius;
1659
+ // this.z = sinPhiRadius * Math.cos(theta);
1660
+ // return this;
1661
+ // }
1662
+ // setFromCylindrical(c) {
1663
+ // return this.setFromCylindricalCoords(c.radius, c.theta, c.y);
1664
+ // }
1665
+ // setFromCylindricalCoords(radius, theta, y) {
1666
+ // this.x = radius * Math.sin(theta);
1667
+ // this.y = y;
1668
+ // this.z = radius * Math.cos(theta);
1669
+ // return this;
1670
+ // }
1671
+ // setFromMatrixPosition(m) {
1672
+ // const e = m.elements;
1673
+ // this.x = e[12];
1674
+ // this.y = e[13];
1675
+ // this.z = e[14];
1676
+ // return this;
1677
+ // }
1678
+ // setFromMatrixScale(m) {
1679
+ // const sx = this.setFromMatrixColumn(m, 0).length();
1680
+ // const sy = this.setFromMatrixColumn(m, 1).length();
1681
+ // const sz = this.setFromMatrixColumn(m, 2).length();
1682
+ // this.x = sx;
1683
+ // this.y = sy;
1684
+ // this.z = sz;
1685
+ // return this;
1686
+ // }
1687
+ // setFromMatrixColumn(m, index) {
1688
+ // return this.fromArray(m.elements, index * 4);
1689
+ // }
1690
+ // setFromMatrix3Column(m, index) {
1691
+ // return this.fromArray(m.elements, index * 3);
1692
+ // }
1693
+ // setFromEuler(e) {
1694
+ // this.x = e._x;
1695
+ // this.y = e._y;
1696
+ // this.z = e._z;
1697
+ // return this;
1698
+ // }
1699
+ // setFromColor(c) {
1700
+ // this.x = c.r;
1701
+ // this.y = c.g;
1702
+ // this.z = c.b;
1703
+ // return this;
1704
+ // }
1705
+ ;
2192
1706
 
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;
1707
+ _proto.equals = function equals(v) {
1708
+ return v.x === this.x && v.y === this.y && v.z === this.z;
2207
1709
  };
2208
1710
 
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;
1711
+ _proto.fromArray = function fromArray(array, offset) {
1712
+ if (offset === void 0) {
1713
+ offset = 0;
1714
+ }
2216
1715
 
2217
- this._onChangeCallback();
1716
+ this.x = array[offset];
1717
+ this.y = array[offset + 1];
1718
+ this.z = array[offset + 2];
1719
+ return this;
1720
+ } // toArray(array = [], offset = 0) {
1721
+ // array[offset] = this.x;
1722
+ // array[offset + 1] = this.y;
1723
+ // array[offset + 2] = this.z;
1724
+ // return array;
1725
+ // }
1726
+ // fromBufferAttribute(attribute, index) {
1727
+ // this.x = attribute.getX(index);
1728
+ // this.y = attribute.getY(index);
1729
+ // this.z = attribute.getZ(index);
1730
+ // return this;
1731
+ // }
1732
+ ;
2218
1733
 
1734
+ _proto.random = function random() {
1735
+ this.x = Math.random();
1736
+ this.y = Math.random();
1737
+ this.z = Math.random();
2219
1738
  return this;
2220
- };
1739
+ } // randomDirection() {
1740
+ // // Derived from https://mathworld.wolfram.com/SpherePointPicking.html
1741
+ // const u = (Math.random() - 0.5) * 2;
1742
+ // const t = Math.random() * Math.PI * 2;
1743
+ // const f = Math.sqrt(1 - u ** 2);
1744
+ // this.x = f * Math.cos(t);
1745
+ // this.y = f * Math.sin(t);
1746
+ // this.z = u;
1747
+ // return this;
1748
+ // }
1749
+ ;
2221
1750
 
2222
- _proto.clone = function clone() {
2223
- return new this.constructor(this._x, this._y, this._z, this._w);
2224
- };
1751
+ return Vector3;
1752
+ }();
2225
1753
 
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;
1754
+ /**
1755
+ * https://github.com/Turfjs/turf/blob/master/packages/turf-boolean-clockwise/index.ts
1756
+ * @param {*} ring
1757
+ * @returns
1758
+ */
2231
1759
 
2232
- this._onChangeCallback();
1760
+ function isClockwise(ring) {
1761
+ var sum = 0;
1762
+ var i = 1;
1763
+ var prev;
1764
+ var cur;
1765
+ var len = ring.length;
2233
1766
 
2234
- return this;
2235
- };
1767
+ while (i < len) {
1768
+ prev = cur || ring[0];
1769
+ cur = ring[i];
1770
+ sum += (cur[0] - prev[0]) * (cur[1] + prev[1]);
1771
+ i++;
1772
+ }
2236
1773
 
2237
- _proto.setFromEuler = function setFromEuler(euler, update) {
2238
- if (update === void 0) {
2239
- update = true;
2240
- }
1774
+ return sum > 0;
1775
+ }
2241
1776
 
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
1777
+ function v3Sub(out, v1, v2) {
1778
+ out[0] = v1[0] - v2[0];
1779
+ out[1] = v1[1] - v2[1];
1780
+ out[2] = v1[2] - v2[2];
1781
+ return out;
1782
+ }
2248
1783
 
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);
1784
+ function v3Normalize(out, v) {
1785
+ var x = v[0];
1786
+ var y = v[1];
1787
+ var z = v[2];
1788
+ var d = Math.sqrt(x * x + y * y + z * z) || 1;
1789
+ out[0] = x / d;
1790
+ out[1] = y / d;
1791
+ out[2] = z / d;
1792
+ return out;
1793
+ }
2257
1794
 
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;
1795
+ function v3Cross(out, v1, v2) {
1796
+ var ax = v1[0],
1797
+ ay = v1[1],
1798
+ az = v1[2],
1799
+ bx = v2[0],
1800
+ by = v2[1],
1801
+ bz = v2[2];
1802
+ out[0] = ay * bz - az * by;
1803
+ out[1] = az * bx - ax * bz;
1804
+ out[2] = ax * by - ay * bx;
1805
+ return out;
1806
+ }
2265
1807
 
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;
1808
+ function generateNormal(indices, position) {
1809
+ function v3Set(p, a, b, c) {
1810
+ p[0] = a;
1811
+ p[1] = b;
1812
+ p[2] = c;
1813
+ }
2272
1814
 
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;
1815
+ var p1 = [];
1816
+ var p2 = [];
1817
+ var p3 = [];
1818
+ var v21 = [];
1819
+ var v32 = [];
1820
+ var n = [];
1821
+ var len = indices.length;
1822
+ var normals = new Float32Array(position.length);
1823
+ var f = 0;
2279
1824
 
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;
1825
+ while (f < len) {
1826
+ // const i1 = indices[f++] * 3;
1827
+ // const i2 = indices[f++] * 3;
1828
+ // const i3 = indices[f++] * 3;
1829
+ // const i1 = indices[f];
1830
+ // const i2 = indices[f + 1];
1831
+ // const i3 = indices[f + 2];
1832
+ var a = indices[f],
1833
+ b = indices[f + 1],
1834
+ c = indices[f + 2];
1835
+ var i1 = a * 3,
1836
+ i2 = b * 3,
1837
+ i3 = c * 3;
1838
+ v3Set(p1, position[i1], position[i1 + 1], position[i1 + 2]);
1839
+ v3Set(p2, position[i2], position[i2 + 1], position[i2 + 2]);
1840
+ v3Set(p3, position[i3], position[i3 + 1], position[i3 + 2]);
1841
+ v3Sub(v32, p3, p2);
1842
+ v3Sub(v21, p1, p2);
1843
+ v3Cross(n, v32, v21); // Already be weighted by the triangle area
2286
1844
 
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;
1845
+ for (var _i = 0; _i < 3; _i++) {
1846
+ normals[i1 + _i] += n[_i];
1847
+ normals[i2 + _i] += n[_i];
1848
+ normals[i3 + _i] += n[_i];
1849
+ }
2293
1850
 
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;
1851
+ f += 3;
1852
+ }
2300
1853
 
2301
- default:
2302
- console.warn('THREE.Quaternion: .setFromEuler() encountered an unknown order: ' + order);
2303
- }
1854
+ var i = 0;
1855
+ var l = normals.length;
2304
1856
 
2305
- if (update === true) this._onChangeCallback();
2306
- return this;
2307
- };
1857
+ while (i < l) {
1858
+ v3Set(n, normals[i], normals[i + 1], normals[i + 2]);
1859
+ v3Normalize(n, n);
1860
+ normals[i] = n[0] || 0;
1861
+ normals[i + 1] = n[1] || 0;
1862
+ normals[i + 2] = n[2] || 0;
1863
+ i += 3;
1864
+ }
2308
1865
 
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);
1866
+ return normals;
1867
+ }
1868
+ function merge(results) {
1869
+ if (results.length === 1) {
1870
+ var _result = {
1871
+ position: results[0].position,
1872
+ normal: results[0].normal,
1873
+ uv: results[0].uv,
1874
+ indices: results[0].indices,
1875
+ results: results
1876
+ };
1877
+ return _result;
1878
+ }
2318
1879
 
2319
- this._onChangeCallback();
1880
+ var plen = 0,
1881
+ ilen = 0;
2320
1882
 
2321
- return this;
1883
+ for (var i = 0, len = results.length; i < len; i++) {
1884
+ var _results$i = results[i],
1885
+ position = _results$i.position,
1886
+ indices = _results$i.indices;
1887
+ plen += position.length;
1888
+ ilen += indices.length;
1889
+ }
1890
+
1891
+ var result = {
1892
+ position: new Float32Array(plen),
1893
+ normal: new Float32Array(plen),
1894
+ uv: new Float32Array(plen / 3 * 2),
1895
+ indices: new Uint32Array(ilen),
1896
+ results: results
2322
1897
  };
1898
+ var pOffset = 0,
1899
+ pCount = 0,
1900
+ iIdx = 0,
1901
+ uvOffset = 0;
2323
1902
 
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;
1903
+ for (var _i2 = 0, _len = results.length; _i2 < _len; _i2++) {
1904
+ var _results$_i = results[_i2],
1905
+ _position = _results$_i.position,
1906
+ _indices = _results$_i.indices,
1907
+ normal = _results$_i.normal,
1908
+ uv = _results$_i.uv;
1909
+ result.position.set(_position, pOffset);
1910
+ result.normal.set(normal, pOffset);
1911
+ result.uv.set(uv, uvOffset);
1912
+ var j = 0;
1913
+ var len1 = _indices.length;
2338
1914
 
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);
1915
+ while (j < len1) {
1916
+ var pIndex = _indices[j] + pCount;
1917
+ result.indices[iIdx] = pIndex;
1918
+ iIdx++;
1919
+ j++;
1920
+ }
2347
1921
 
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);
1922
+ uvOffset += uv.length;
1923
+ pOffset += _position.length;
1924
+ pCount += _position.length / 3;
1925
+ }
2354
1926
 
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);
1927
+ return result;
1928
+ }
1929
+ function radToDeg(rad) {
1930
+ return rad * 180 / Math.PI;
1931
+ }
1932
+ function degToRad(angle) {
1933
+ return angle / 180 * Math.PI;
1934
+ } // https://github.com/mrdoob/three.js/blob/16f13e3b07e31d0e9a00df7c3366bbe0e464588c/src/geometries/ExtrudeGeometry.js?_pjax=%23js-repo-pjax-container#L736
2361
1935
 
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
- }
1936
+ function generateSideWallUV(uvs, vertices, indexA, indexB, indexC, indexD) {
1937
+ var idx1 = indexA * 3,
1938
+ idx2 = indexB * 3,
1939
+ idx3 = indexC * 3,
1940
+ idx4 = indexD * 3;
1941
+ var a_x = vertices[idx1];
1942
+ var a_y = vertices[idx1 + 1];
1943
+ var a_z = vertices[idx1 + 2];
1944
+ var b_x = vertices[idx2];
1945
+ var b_y = vertices[idx2 + 1];
1946
+ var b_z = vertices[idx2 + 2];
1947
+ var c_x = vertices[idx3];
1948
+ var c_y = vertices[idx3 + 1];
1949
+ var c_z = vertices[idx3 + 2];
1950
+ var d_x = vertices[idx4];
1951
+ var d_y = vertices[idx4 + 1];
1952
+ var d_z = vertices[idx4 + 2];
1953
+ var uIndex = uvs.length - 1;
2367
1954
 
2368
- this._onChangeCallback();
1955
+ if (Math.abs(a_y - b_y) < Math.abs(a_x - b_x)) {
1956
+ uvs[++uIndex] = a_x;
1957
+ uvs[++uIndex] = 1 - a_z;
1958
+ uvs[++uIndex] = b_x;
1959
+ uvs[++uIndex] = 1 - b_z;
1960
+ uvs[++uIndex] = c_x;
1961
+ uvs[++uIndex] = 1 - c_z;
1962
+ uvs[++uIndex] = d_x;
1963
+ uvs[++uIndex] = 1 - d_z; // uvs.push(a_x, 1 - a_z);
1964
+ // uvs.push(b_x, 1 - b_z);
1965
+ // uvs.push(c_x, 1 - c_z);
1966
+ // uvs.push(d_x, 1 - d_z);
1967
+ } else {
1968
+ uvs[++uIndex] = a_y;
1969
+ uvs[++uIndex] = 1 - a_z;
1970
+ uvs[++uIndex] = b_y;
1971
+ uvs[++uIndex] = 1 - b_z;
1972
+ uvs[++uIndex] = c_y;
1973
+ uvs[++uIndex] = 1 - c_z;
1974
+ uvs[++uIndex] = d_y;
1975
+ uvs[++uIndex] = 1 - d_z; // uvs.push(a_y, 1 - a_z);
1976
+ // uvs.push(b_y, 1 - b_z);
1977
+ // uvs.push(c_y, 1 - c_z);
1978
+ // uvs.push(d_y, 1 - d_z);
1979
+ }
1980
+ }
1981
+ function line2Vectors(line) {
1982
+ var points = [];
2369
1983
 
2370
- return this;
2371
- };
1984
+ for (var i = 0, len = line.length; i < len; i++) {
1985
+ var p = line[i];
1986
+ var x = p[0],
1987
+ y = p[1],
1988
+ z = p[2];
1989
+ var v = new Vector3(x, y, z || 0);
1990
+ points[i] = v;
1991
+ }
2372
1992
 
2373
- _proto.setFromUnitVectors = function setFromUnitVectors(vFrom, vTo) {
2374
- // assumes direction vectors vFrom and vTo are normalized
2375
- var r = vFrom.dot(vTo) + 1;
1993
+ return points;
1994
+ }
2376
1995
 
2377
- if (r < Number.EPSILON) {
2378
- // vFrom and vTo point in opposite directions
2379
- r = 0;
1996
+ function extrudePolygons(polygons, options) {
1997
+ options = Object.assign({}, {
1998
+ depth: 2
1999
+ }, options);
2000
+ var results = polygons.map(function (polygon) {
2001
+ for (var i = 0, len = polygon.length; i < len; i++) {
2002
+ var ring = polygon[i];
2003
+ validateRing(ring);
2380
2004
 
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;
2005
+ if (i === 0) {
2006
+ if (!isClockwise(ring)) {
2007
+ polygon[i] = ring.reverse();
2008
+ }
2009
+ } else if (isClockwise(ring)) {
2010
+ polygon[i] = ring.reverse();
2011
+ }
2012
+
2013
+ if (isClosedRing(ring)) {
2014
+ ring.splice(ring.length - 1, 1);
2391
2015
  }
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
2016
  }
2399
2017
 
2400
- return this.normalize();
2401
- } // angleTo(q) {
2402
- // return 2 * Math.acos(Math.abs(clamp(this.dot(q), -1, 1)));
2403
- // }
2404
- ;
2018
+ var result = flatVertices(polygon, options);
2019
+ result.polygon = polygon;
2020
+ var triangles = earcut$1(result.flatVertices, result.holes, 2);
2021
+ generateTopAndBottom$1(result, triangles);
2022
+ generateSides$1(result, options);
2023
+ result.position = new Float32Array(result.points);
2024
+ result.indices = new Uint32Array(result.indices);
2025
+ result.uv = new Float32Array(result.uv);
2026
+ result.normal = generateNormal(result.indices, result.position);
2027
+ return result;
2028
+ });
2029
+ var result = merge(results);
2030
+ result.polygons = polygons;
2031
+ return result;
2032
+ }
2405
2033
 
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
- };
2034
+ function generateTopAndBottom$1(result, triangles) {
2035
+ var indices = [];
2036
+ var count = result.count;
2413
2037
 
2414
- _proto.identity = function identity() {
2415
- return this.set(0, 0, 0, 1);
2416
- };
2038
+ for (var i = 0, len = triangles.length; i < len; i += 3) {
2039
+ // top
2040
+ var a = triangles[i],
2041
+ b = triangles[i + 1],
2042
+ c = triangles[i + 2];
2043
+ indices[i] = a;
2044
+ indices[i + 1] = b;
2045
+ indices[i + 2] = c; // bottom
2417
2046
 
2418
- _proto.invert = function invert() {
2419
- // quaternion is assumed to have unit length
2420
- return this.conjugate();
2421
- };
2047
+ var idx = len + i;
2048
+ var a1 = count + a,
2049
+ b1 = count + b,
2050
+ c1 = count + c;
2051
+ indices[idx] = a1;
2052
+ indices[idx + 1] = b1;
2053
+ indices[idx + 2] = c1;
2054
+ }
2422
2055
 
2423
- _proto.conjugate = function conjugate() {
2424
- this._x *= -1;
2425
- this._y *= -1;
2426
- this._z *= -1;
2056
+ result.indices = indices;
2057
+ }
2427
2058
 
2428
- this._onChangeCallback();
2059
+ function generateSides$1(result, options) {
2060
+ var points = result.points,
2061
+ indices = result.indices,
2062
+ polygon = result.polygon,
2063
+ uv = result.uv;
2064
+ var depth = options.depth;
2065
+ var pIndex = points.length - 1;
2066
+ var iIndex = indices.length - 1;
2067
+
2068
+ for (var i = 0, len = polygon.length; i < len; i++) {
2069
+ var ring = polygon[i];
2070
+ var j = 0;
2071
+ var len1 = ring.length;
2429
2072
 
2430
- return this;
2431
- };
2073
+ while (j < len1) {
2074
+ var v1 = ring[j];
2075
+ var v2 = ring[j + 1];
2432
2076
 
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
- };
2077
+ if (j === len1 - 1) {
2078
+ v2 = ring[0];
2079
+ }
2436
2080
 
2437
- _proto.lengthSq = function lengthSq() {
2438
- return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
2439
- };
2081
+ var idx = points.length / 3;
2082
+ var x1 = v1[0],
2083
+ y1 = v1[1],
2084
+ z1 = v1[2] || 0,
2085
+ x2 = v2[0],
2086
+ y2 = v2[1],
2087
+ z2 = v2[2] || 0;
2088
+ points[++pIndex] = x1;
2089
+ points[++pIndex] = y1;
2090
+ points[++pIndex] = z1 + depth;
2091
+ points[++pIndex] = x2;
2092
+ points[++pIndex] = y2;
2093
+ points[++pIndex] = z2 + depth;
2094
+ points[++pIndex] = x1;
2095
+ points[++pIndex] = y1;
2096
+ points[++pIndex] = z1;
2097
+ points[++pIndex] = x2;
2098
+ points[++pIndex] = y2;
2099
+ points[++pIndex] = z2; // points.push(x1, y1, z, x2, y2, z, x1, y1, 0, x2, y2, 0);
2440
2100
 
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
- };
2101
+ var a = idx + 2,
2102
+ b = idx + 3,
2103
+ c = idx,
2104
+ d = idx + 1; // points.push(p3, p4, p1, p2);
2105
+ // index.push(a, c, b, c, d, b);
2444
2106
 
2445
- _proto.normalize = function normalize() {
2446
- var l = this.length();
2107
+ indices[++iIndex] = a;
2108
+ indices[++iIndex] = c;
2109
+ indices[++iIndex] = b;
2110
+ indices[++iIndex] = c;
2111
+ indices[++iIndex] = d;
2112
+ indices[++iIndex] = b; // index.push(c, d, b);
2447
2113
 
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;
2114
+ generateSideWallUV(uv, points, a, b, c, d);
2115
+ j++;
2459
2116
  }
2117
+ }
2118
+ }
2460
2119
 
2461
- this._onChangeCallback();
2462
-
2463
- return this;
2464
- };
2120
+ function calPolygonPointsCount(polygon) {
2121
+ var count = 0;
2122
+ var i = 0;
2123
+ var len = polygon.length;
2465
2124
 
2466
- _proto.multiply = function multiply(q) {
2467
- return this.multiplyQuaternions(this, q);
2468
- };
2125
+ while (i < len) {
2126
+ count += polygon[i].length;
2127
+ i++;
2128
+ }
2469
2129
 
2470
- _proto.premultiply = function premultiply(q) {
2471
- return this.multiplyQuaternions(q, this);
2472
- };
2130
+ return count;
2131
+ }
2473
2132
 
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;
2133
+ function flatVertices(polygon, options) {
2134
+ var count = calPolygonPointsCount(polygon);
2135
+ var len = polygon.length;
2136
+ var holes = [],
2137
+ flatVertices = new Float32Array(count * 2),
2138
+ points = [],
2139
+ uv = [];
2140
+ var pOffset = count * 3,
2141
+ uOffset = count * 2;
2142
+ var depth = options.depth;
2143
+ var idx0 = 0,
2144
+ idx1 = 0,
2145
+ idx2 = 0;
2488
2146
 
2489
- this._onChangeCallback();
2147
+ for (var i = 0; i < len; i++) {
2148
+ var ring = polygon[i];
2490
2149
 
2491
- return this;
2492
- };
2150
+ if (i > 0) {
2151
+ holes.push(idx0 / 2);
2152
+ }
2493
2153
 
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/
2154
+ var j = 0;
2155
+ var len1 = ring.length;
2501
2156
 
2502
- var cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
2157
+ while (j < len1) {
2158
+ var c = ring[j];
2159
+ var x = c[0],
2160
+ y = c[1],
2161
+ z = c[2] || 0;
2162
+ flatVertices[idx0++] = x;
2163
+ flatVertices[idx0++] = y; // top vertices
2503
2164
 
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
- }
2165
+ points[idx1] = x;
2166
+ points[idx1 + 1] = y;
2167
+ points[idx1 + 2] = depth + z; // bottom vertices
2513
2168
 
2514
- if (cosHalfTheta >= 1.0) {
2515
- this._w = w;
2516
- this._x = x;
2517
- this._y = y;
2518
- this._z = z;
2519
- return this;
2169
+ points[pOffset + idx1] = x;
2170
+ points[pOffset + idx1 + 1] = y;
2171
+ points[pOffset + idx1 + 2] = z;
2172
+ uv[idx2] = x;
2173
+ uv[idx2 + 1] = y;
2174
+ uv[uOffset + idx2] = x;
2175
+ uv[uOffset + idx2 + 1] = y;
2176
+ idx1 += 3;
2177
+ idx2 += 2;
2178
+ j++;
2520
2179
  }
2180
+ }
2521
2181
 
2522
- var sqrSinHalfTheta = 1.0 - cosHalfTheta * cosHalfTheta;
2182
+ return {
2183
+ flatVertices: flatVertices,
2184
+ holes: holes,
2185
+ points: points,
2186
+ count: count,
2187
+ uv: uv
2188
+ };
2189
+ }
2523
2190
 
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()
2191
+ function validateRing(ring) {
2192
+ if (!isClosedRing(ring)) {
2193
+ ring.push(ring[0]);
2194
+ }
2195
+ }
2531
2196
 
2532
- return this;
2533
- }
2197
+ function isClosedRing(ring) {
2198
+ var len = ring.length;
2199
+ var _ring$ = ring[0],
2200
+ x1 = _ring$[0],
2201
+ y1 = _ring$[1],
2202
+ _ring = ring[len - 1],
2203
+ x2 = _ring[0],
2204
+ y2 = _ring[1];
2205
+ return x1 === x2 && y1 === y2;
2206
+ }
2534
2207
 
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;
2208
+ function checkOptions(options) {
2209
+ options.lineWidth = Math.max(0, options.lineWidth);
2210
+ options.depth = Math.max(0, options.depth);
2211
+ options.sideDepth = Math.max(0, options.sideDepth);
2212
+ }
2543
2213
 
2544
- this._onChangeCallback();
2214
+ function extrudePolylines(lines, options) {
2215
+ options = Object.assign({}, {
2216
+ depth: 2,
2217
+ lineWidth: 1,
2218
+ bottomStickGround: false
2219
+ }, options);
2220
+ checkOptions(options);
2221
+ var results = lines.map(function (line) {
2222
+ var result = expandLine(line, options);
2223
+ result.line = line;
2224
+ generateTopAndBottom(result, options);
2225
+ generateSides(result, options);
2226
+ result.position = new Float32Array(result.points);
2227
+ result.indices = new Uint32Array(result.indices);
2228
+ result.uv = new Float32Array(result.uv);
2229
+ result.normal = generateNormal(result.indices, result.position);
2230
+ return result;
2231
+ });
2232
+ var result = merge(results);
2233
+ result.lines = lines;
2234
+ return result;
2235
+ }
2236
+ function extrudeSlopes(lines, options) {
2237
+ options = Object.assign({}, {
2238
+ depth: 2,
2239
+ lineWidth: 1,
2240
+ side: 'left',
2241
+ sideDepth: 0,
2242
+ bottomStickGround: false
2243
+ }, options);
2244
+ checkOptions(options);
2245
+ var _options = options,
2246
+ depth = _options.depth,
2247
+ side = _options.side,
2248
+ sideDepth = _options.sideDepth;
2249
+ var results = lines.map(function (line) {
2250
+ var tempResult = expandLine(line, options);
2251
+ tempResult.line = line;
2252
+ var leftPoints = tempResult.leftPoints,
2253
+ rightPoints = tempResult.rightPoints;
2254
+ var result = {
2255
+ line: line
2256
+ };
2257
+ var depths;
2545
2258
 
2546
- return this;
2547
- };
2259
+ for (var i = 0, len = line.length; i < len; i++) {
2260
+ line[i][2] = line[i][2] || 0;
2261
+ }
2548
2262
 
2549
- _proto.slerpQuaternions = function slerpQuaternions(qa, qb, t) {
2550
- return this.copy(qa).slerp(qb, t);
2551
- };
2263
+ if (side === 'left') {
2264
+ result.leftPoints = leftPoints;
2265
+ result.rightPoints = line;
2266
+ depths = [sideDepth, depth];
2267
+ } else {
2268
+ result.leftPoints = line;
2269
+ result.rightPoints = rightPoints;
2270
+ depths = [depth, sideDepth];
2271
+ }
2552
2272
 
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
- };
2273
+ result.depths = depths;
2274
+ generateTopAndBottom(result, options);
2275
+ generateSides(result, options);
2276
+ result.position = new Float32Array(result.points);
2277
+ result.indices = new Uint32Array(result.indices);
2278
+ result.uv = new Float32Array(result.uv);
2279
+ result.normal = generateNormal(result.indices, result.position);
2280
+ return result;
2281
+ });
2282
+ var result = merge(results);
2283
+ result.lines = lines;
2284
+ return result;
2285
+ }
2565
2286
 
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
- };
2287
+ function generateTopAndBottom(result, options) {
2288
+ var bottomStickGround = options.bottomStickGround;
2289
+ var z = options.depth;
2290
+ var depths = result.depths;
2291
+ var lz = z,
2292
+ rz = z;
2569
2293
 
2570
- _proto.fromArray = function fromArray(array, offset) {
2571
- if (offset === void 0) {
2572
- offset = 0;
2573
- }
2294
+ if (depths) {
2295
+ lz = depths[0];
2296
+ rz = depths[1];
2297
+ }
2574
2298
 
2575
- this._x = array[offset];
2576
- this._y = array[offset + 1];
2577
- this._z = array[offset + 2];
2578
- this._w = array[offset + 3];
2299
+ var points = [],
2300
+ indices = [],
2301
+ uv = [];
2302
+ var leftPoints = result.leftPoints,
2303
+ rightPoints = result.rightPoints;
2304
+ var i = 0,
2305
+ len = leftPoints.length;
2579
2306
 
2580
- this._onChangeCallback();
2307
+ while (i < len) {
2308
+ // top left
2309
+ var idx0 = i * 3;
2310
+ var _leftPoints$i = leftPoints[i],
2311
+ x1 = _leftPoints$i[0],
2312
+ y1 = _leftPoints$i[1],
2313
+ z1 = _leftPoints$i[2];
2314
+ points[idx0] = x1;
2315
+ points[idx0 + 1] = y1;
2316
+ points[idx0 + 2] = lz + z1; // top right
2581
2317
 
2582
- return this;
2583
- };
2318
+ var _rightPoints$i = rightPoints[i],
2319
+ x2 = _rightPoints$i[0],
2320
+ y2 = _rightPoints$i[1],
2321
+ z2 = _rightPoints$i[2];
2322
+ var idx1 = len * 3 + idx0;
2323
+ points[idx1] = x2;
2324
+ points[idx1 + 1] = y2;
2325
+ points[idx1 + 2] = rz + z2; // bottom left
2584
2326
 
2585
- _proto.toArray = function toArray(array, offset) {
2586
- if (array === void 0) {
2587
- array = [];
2588
- }
2327
+ var idx2 = len * 2 * 3 + idx0;
2328
+ points[idx2] = x1;
2329
+ points[idx2 + 1] = y1;
2330
+ points[idx2 + 2] = z1;
2589
2331
 
2590
- if (offset === void 0) {
2591
- offset = 0;
2592
- }
2332
+ if (bottomStickGround) {
2333
+ points[idx2 + 2] = 0;
2334
+ } // bottom right
2593
2335
 
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
2336
 
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);
2337
+ var idx3 = len * 2 * 3 + len * 3 + idx0;
2338
+ points[idx3] = x2;
2339
+ points[idx3 + 1] = y2;
2340
+ points[idx3 + 2] = z2;
2606
2341
 
2607
- this._onChangeCallback();
2342
+ if (bottomStickGround) {
2343
+ points[idx3 + 2] = 0;
2344
+ }
2608
2345
 
2609
- return this;
2610
- };
2346
+ i++;
2347
+ }
2611
2348
 
2612
- _proto.toJSON = function toJSON() {
2613
- return this.toArray();
2614
- };
2349
+ i = 0;
2350
+ len = points.length;
2351
+ var uIndex = uv.length - 1;
2615
2352
 
2616
- _proto._onChange = function _onChange(callback) {
2617
- this._onChangeCallback = callback;
2618
- return this;
2619
- };
2353
+ while (i < len) {
2354
+ var x = points[i],
2355
+ y = points[i + 1];
2356
+ uv[++uIndex] = x;
2357
+ uv[++uIndex] = y; // uvs.push(x, y);
2620
2358
 
2621
- _proto._onChangeCallback = function _onChangeCallback() {};
2359
+ i += 3;
2360
+ }
2622
2361
 
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;
2362
+ i = 0;
2363
+ len = leftPoints.length;
2364
+ var iIndex = indices.length - 1;
2630
2365
 
2631
- case 2:
2632
- _context.next = 4;
2633
- return this._y;
2366
+ while (i < len - 1) {
2367
+ // top
2368
+ // left1 left2 right1,right2
2369
+ var a1 = i,
2370
+ b1 = i + 1,
2371
+ c1 = a1 + len,
2372
+ d1 = b1 + len;
2373
+ indices[++iIndex] = a1;
2374
+ indices[++iIndex] = c1;
2375
+ indices[++iIndex] = b1;
2376
+ indices[++iIndex] = c1;
2377
+ indices[++iIndex] = d1;
2378
+ indices[++iIndex] = b1; // index.push(a1, c1, b1);
2379
+ // index.push(c1, d1, b1);
2380
+ // bottom
2381
+ // left1 left2 right1,right2
2634
2382
 
2635
- case 4:
2636
- _context.next = 6;
2637
- return this._z;
2383
+ var len2 = len * 2;
2384
+ var a2 = i + len2,
2385
+ b2 = a2 + 1,
2386
+ c2 = a2 + len,
2387
+ d2 = b2 + len;
2388
+ indices[++iIndex] = a2;
2389
+ indices[++iIndex] = c2;
2390
+ indices[++iIndex] = b2;
2391
+ indices[++iIndex] = c2;
2392
+ indices[++iIndex] = d2;
2393
+ indices[++iIndex] = b2; // index.push(a2, c2, b2);
2394
+ // index.push(c2, d2, b2);
2638
2395
 
2639
- case 6:
2640
- _context.next = 8;
2641
- return this._w;
2396
+ i++;
2397
+ }
2642
2398
 
2643
- case 8:
2644
- case "end":
2645
- return _context.stop();
2646
- }
2647
- }
2648
- }, _callee, this);
2649
- });
2399
+ result.indices = indices;
2400
+ result.points = points;
2401
+ result.uv = uv;
2650
2402
 
2651
- _createClass(Quaternion, [{
2652
- key: "x",
2653
- get: function get() {
2654
- return this._x;
2655
- },
2656
- set: function set(value) {
2657
- this._x = value;
2403
+ if (depths) {
2404
+ len = leftPoints.length;
2405
+ i = 0;
2658
2406
 
2659
- this._onChangeCallback();
2407
+ while (i < len) {
2408
+ leftPoints[i].depth = lz;
2409
+ rightPoints[i].depth = rz;
2410
+ i++;
2660
2411
  }
2661
- }, {
2662
- key: "y",
2663
- get: function get() {
2664
- return this._y;
2665
- },
2666
- set: function set(value) {
2667
- this._y = value;
2412
+ }
2413
+ }
2668
2414
 
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;
2415
+ function generateSides(result, options) {
2416
+ var points = result.points,
2417
+ indices = result.indices,
2418
+ leftPoints = result.leftPoints,
2419
+ rightPoints = result.rightPoints,
2420
+ uv = result.uv;
2421
+ var z = options.depth;
2422
+ var bottomStickGround = options.bottomStickGround;
2423
+ var rings = [leftPoints, rightPoints];
2424
+ var depthsEnable = result.depths;
2425
+ var pIndex = points.length - 1;
2426
+ var iIndex = indices.length - 1;
2678
2427
 
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;
2428
+ function addOneSideIndex(v1, v2) {
2429
+ var idx = points.length / 3; // let pIndex = points.length - 1;
2430
+ // top
2688
2431
 
2689
- this._onChangeCallback();
2690
- }
2691
- }]);
2432
+ points[++pIndex] = v1[0];
2433
+ points[++pIndex] = v1[1];
2434
+ points[++pIndex] = (depthsEnable ? v1.depth : z) + v1[2];
2435
+ points[++pIndex] = v2[0];
2436
+ points[++pIndex] = v2[1];
2437
+ points[++pIndex] = (depthsEnable ? v2.depth : z) + v2[2]; // points.push(v1[0], v1[1], (depthsEnable ? v1.depth : z) + v1[2], v2[0], v2[1], (depthsEnable ? v2.depth : z) + v2[2]);
2438
+ // bottom
2439
+
2440
+ points[++pIndex] = v1[0];
2441
+ points[++pIndex] = v1[1];
2442
+ points[++pIndex] = bottomStickGround ? 0 : v1[2];
2443
+ points[++pIndex] = v2[0];
2444
+ points[++pIndex] = v2[1];
2445
+ points[++pIndex] = bottomStickGround ? 0 : v2[2]; // points.push(v1[0], v1[1], v1[2], v2[0], v2[1], v2[2]);
2692
2446
 
2693
- return Quaternion;
2694
- }(Symbol.iterator);
2447
+ var a = idx + 2,
2448
+ b = idx + 3,
2449
+ c = idx,
2450
+ d = idx + 1;
2451
+ indices[++iIndex] = a;
2452
+ indices[++iIndex] = c;
2453
+ indices[++iIndex] = b;
2454
+ indices[++iIndex] = c;
2455
+ indices[++iIndex] = d;
2456
+ indices[++iIndex] = b; // index.push(a, c, b, c, d, b);
2695
2457
 
2696
- // import * as MathUtils from './MathUtils.js';
2458
+ generateSideWallUV(uv, points, a, b, c, d);
2459
+ }
2697
2460
 
2698
- var _quaternion = new Quaternion();
2461
+ for (var i = 0, _len = rings.length; i < _len; i++) {
2462
+ var ring = rings[i];
2699
2463
 
2700
- var Vector3 = /*#__PURE__*/function () {
2701
- function Vector3(x, y, z) {
2702
- if (x === void 0) {
2703
- x = 0;
2464
+ if (i > 0) {
2465
+ ring = ring.map(function (p) {
2466
+ return p;
2467
+ });
2468
+ ring = ring.reverse();
2704
2469
  }
2705
2470
 
2706
- if (y === void 0) {
2707
- y = 0;
2708
- }
2471
+ var j = 0;
2472
+ var len1 = ring.length - 1;
2709
2473
 
2710
- if (z === void 0) {
2711
- z = 0;
2474
+ while (j < len1) {
2475
+ var v1 = ring[j];
2476
+ var v2 = ring[j + 1];
2477
+ addOneSideIndex(v1, v2);
2478
+ j++;
2712
2479
  }
2713
-
2714
- this.x = x;
2715
- this.y = y;
2716
- this.z = z;
2717
2480
  }
2718
2481
 
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
- };
2482
+ var len = leftPoints.length;
2483
+ var vs = [rightPoints[0], leftPoints[0], leftPoints[len - 1], rightPoints[len - 1]];
2782
2484
 
2783
- _proto.addScalar = function addScalar(s) {
2784
- this.x += s;
2785
- this.y += s;
2786
- this.z += s;
2787
- return this;
2788
- };
2485
+ for (var _i = 0; _i < vs.length; _i += 2) {
2486
+ var _v = vs[_i],
2487
+ _v2 = vs[_i + 1];
2488
+ addOneSideIndex(_v, _v2);
2489
+ }
2490
+ }
2789
2491
 
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
- };
2492
+ var TEMPV1 = {
2493
+ x: 0,
2494
+ y: 0
2495
+ },
2496
+ TEMPV2 = {
2497
+ x: 0,
2498
+ y: 0
2499
+ };
2500
+ function expandLine(line, options) {
2501
+ // let preAngle = 0;
2502
+ var radius = options.lineWidth / 2;
2503
+ var points = [],
2504
+ leftPoints = [],
2505
+ rightPoints = [];
2506
+ var len = line.length;
2507
+ var i = 0;
2796
2508
 
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
- };
2509
+ while (i < len) {
2510
+ var p1 = line[i],
2511
+ p2 = line[i + 1];
2512
+ var currentp = line[i]; // last vertex
2803
2513
 
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
- };
2514
+ if (i === len - 1) {
2515
+ p1 = line[len - 2];
2516
+ p2 = line[len - 1];
2517
+ }
2810
2518
 
2811
- _proto.subScalar = function subScalar(s) {
2812
- this.x -= s;
2813
- this.y -= s;
2814
- this.z -= s;
2815
- return this;
2816
- };
2519
+ var dy = p2[1] - p1[1],
2520
+ dx = p2[0] - p1[0];
2521
+ var rAngle = 0;
2522
+ var rad = Math.atan(dy / dx);
2523
+ var angle = radToDeg(rad); // preAngle = angle;
2817
2524
 
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
- };
2525
+ if (i === 0 || i === len - 1) {
2526
+ rAngle = angle;
2527
+ rAngle -= 90;
2528
+ } else {
2529
+ // 至少3个顶点才会触发
2530
+ var p0 = line[i - 1];
2531
+ TEMPV1.x = p0[0] - p1[0];
2532
+ TEMPV1.y = p0[1] - p1[1];
2533
+ TEMPV2.x = p2[0] - p1[0];
2534
+ TEMPV2.y = p2[1] - p1[1];
2535
+ var vAngle = getAngle(TEMPV1, TEMPV2);
2536
+ rAngle = angle - vAngle / 2;
2537
+ }
2824
2538
 
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
- };
2539
+ var rRad = degToRad(rAngle);
2540
+ var p3 = currentp;
2541
+ var x = Math.cos(rRad) + p3[0],
2542
+ y = Math.sin(rRad) + p3[1];
2543
+ var p4 = [x, y];
2831
2544
 
2832
- _proto.multiplyScalar = function multiplyScalar(scalar) {
2833
- this.x *= scalar;
2834
- this.y *= scalar;
2835
- this.z *= scalar;
2836
- return this;
2837
- };
2545
+ var _translateLine = translateLine(p1, p2, radius),
2546
+ line1 = _translateLine[0],
2547
+ line2 = _translateLine[1];
2838
2548
 
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
- ;
2549
+ var op1 = lineIntersection(line1[0], line1[1], p3, p4);
2550
+ var op2 = lineIntersection(line2[0], line2[1], p3, p4); // 平行,回头路
2848
2551
 
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
- ;
2552
+ if (!op1 || !op2) {
2553
+ var len1 = points.length;
2554
+ var point1 = points[len1 - 2];
2555
+ var point2 = points[len1 - 1];
2863
2556
 
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
- };
2557
+ if (!point1 || !point2) {
2558
+ continue;
2559
+ }
2875
2560
 
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
2561
+ op1 = [point1[0], point1[1]];
2562
+ op2 = [point2[0], point2[1]];
2563
+ }
2884
2564
 
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
2565
+ op1[2] = currentp[2] || 0;
2566
+ op2[2] = currentp[2] || 0; // const [op1, op2] = calOffsetPoint(rRad, radius, p1);
2889
2567
 
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
- ;
2568
+ points.push(op1, op2);
2911
2569
 
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
- };
2570
+ if (leftOnLine(op1, p1, p2)) {
2571
+ leftPoints.push(op1);
2572
+ rightPoints.push(op2);
2573
+ } else {
2574
+ leftPoints.push(op2);
2575
+ rightPoints.push(op1);
2576
+ }
2918
2577
 
2919
- _proto.divideScalar = function divideScalar(scalar) {
2920
- return this.multiplyScalar(1 / scalar);
2921
- };
2578
+ i++;
2579
+ }
2922
2580
 
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;
2581
+ return {
2582
+ offsetPoints: points,
2583
+ leftPoints: leftPoints,
2584
+ rightPoints: rightPoints
2928
2585
  };
2586
+ } // eslint-disable-next-line no-unused-vars
2929
2587
 
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
- };
2588
+ var getAngle = function getAngle(_ref, _ref2) {
2589
+ var x1 = _ref.x,
2590
+ y1 = _ref.y;
2591
+ var x2 = _ref2.x,
2592
+ y2 = _ref2.y;
2593
+ var dot = x1 * x2 + y1 * y2;
2594
+ var det = x1 * y2 - y1 * x2;
2595
+ var angle = Math.atan2(det, dot) / Math.PI * 180;
2596
+ return (angle + 360) % 360;
2597
+ };
2936
2598
 
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
- };
2599
+ function leftOnLine(p, p1, p2) {
2600
+ var x1 = p1[0],
2601
+ y1 = p1[1];
2602
+ var x2 = p2[0],
2603
+ y2 = p2[1];
2604
+ var x = p[0],
2605
+ y = p[1];
2606
+ return (y1 - y2) * x + (x2 - x1) * y + x1 * y2 - x2 * y1 > 0;
2607
+ }
2608
+ /**
2609
+ * 平移线
2610
+ * @param {*} p1
2611
+ * @param {*} p2
2612
+ * @param {*} distance
2613
+ * @returns
2614
+ */
2944
2615
 
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
- };
2616
+ function translateLine(p1, p2, distance) {
2617
+ var dy = p2[1] - p1[1],
2618
+ dx = p2[0] - p1[0];
2619
+ var rad = Math.atan2(dy, dx);
2620
+ var rad1 = rad + Math.PI / 2;
2621
+ var offsetX = Math.cos(rad1) * distance,
2622
+ offsetY = Math.sin(rad1) * distance;
2623
+ var tp1 = [p1[0] + offsetX, p1[1] + offsetY];
2624
+ var tp2 = [p2[0] + offsetX, p2[1] + offsetY];
2625
+ var rad2 = rad - Math.PI / 2;
2626
+ offsetX = Math.cos(rad2) * distance;
2627
+ offsetY = Math.sin(rad2) * distance;
2628
+ var tp3 = [p1[0] + offsetX, p1[1] + offsetY];
2629
+ var tp4 = [p2[0] + offsetX, p2[1] + offsetY];
2630
+ return [[tp1, tp2], [tp3, tp4]];
2631
+ }
2632
+ /**
2633
+ * 直线交点
2634
+ * @param {*} p1
2635
+ * @param {*} p2
2636
+ * @param {*} p3
2637
+ * @param {*} p4
2638
+ * @returns
2639
+ */
2951
2640
 
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
2641
 
2987
- _proto.dot = function dot(v) {
2988
- return this.x * v.x + this.y * v.y + this.z * v.z;
2989
- } // TODO lengthSquared?
2990
- ;
2642
+ function lineIntersection(p1, p2, p3, p4) {
2643
+ var dx1 = p2[0] - p1[0],
2644
+ dy1 = p2[1] - p1[1];
2645
+ var dx2 = p4[0] - p3[0],
2646
+ dy2 = p4[1] - p3[1];
2991
2647
 
2992
- _proto.lengthSq = function lengthSq() {
2993
- return this.x * this.x + this.y * this.y + this.z * this.z;
2994
- };
2648
+ if (dx1 === 0 && dx2 === 0) {
2649
+ return null;
2650
+ }
2995
2651
 
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
- ;
2652
+ if (dy1 === 0 && dy2 === 0) {
2653
+ return null;
2654
+ }
3002
2655
 
3003
- _proto.normalize = function normalize() {
3004
- return this.divideScalar(this.length() || 1);
3005
- };
2656
+ var k1 = dy1 / dx1;
2657
+ var k2 = dy2 / dx2;
2658
+ var b1 = p1[1] - k1 * p1[0];
2659
+ var b2 = p3[1] - k2 * p3[0];
2660
+ var x, y;
2661
+
2662
+ if (dx1 === 0) {
2663
+ x = p1[0];
2664
+ y = k2 * x + b2;
2665
+ } else if (dx2 === 0) {
2666
+ x = p3[0];
2667
+ y = k1 * x + b1;
2668
+ } else if (dy1 === 0) {
2669
+ y = p1[1];
2670
+ x = (y - b2) / k2;
2671
+ } else if (dy2 === 0) {
2672
+ y = p3[1];
2673
+ x = (y - b1) / k1;
2674
+ } else {
2675
+ x = (b2 - b1) / (k1 - k2);
2676
+ y = k1 * x + b1;
2677
+ }
2678
+
2679
+ return [x, y];
2680
+ }
2681
+
2682
+ function cylinder(point, options) {
2683
+ if (options === void 0) {
2684
+ options = {};
2685
+ }
2686
+
2687
+ options = Object.assign({}, {
2688
+ radius: 1,
2689
+ height: 2,
2690
+ radialSegments: 6
2691
+ }, options);
2692
+ var radialSegments = Math.round(Math.max(4, options.radialSegments));
2693
+ var _options = options,
2694
+ radius = _options.radius,
2695
+ height = _options.height;
2696
+ var aRad = 360 / radialSegments / 360 * Math.PI * 2;
2697
+ var circlePointsLen = radialSegments + 1;
2698
+ var points = new Float32Array(circlePointsLen * 3 * 2);
2699
+ var centerx = point[0],
2700
+ centery = point[1];
2701
+ var idx = 0,
2702
+ uIdx = 0;
2703
+ var offset = circlePointsLen * 3,
2704
+ uOffset = circlePointsLen * 2;
2705
+ var indices = [],
2706
+ uv = [];
2707
+ var iIndex = indices.length - 1;
2708
+
2709
+ for (var i = -1; i < radialSegments; i++) {
2710
+ var rad = aRad * i;
2711
+ var x = Math.cos(rad) * radius + centerx,
2712
+ y = Math.sin(rad) * radius + centery; // bottom vertices
3006
2713
 
3007
- _proto.setLength = function setLength(length) {
3008
- return this.normalize().multiplyScalar(length);
3009
- };
2714
+ points[idx] = x;
2715
+ points[idx + 1] = y;
2716
+ points[idx + 2] = 0; // top vertices
3010
2717
 
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
- };
2718
+ points[idx + offset] = x;
2719
+ points[idx + 1 + offset] = y;
2720
+ points[idx + 2 + offset] = height;
2721
+ var u = 0,
2722
+ v = 0;
2723
+ u = 0.5 + x / radius / 2;
2724
+ v = 0.5 + y / radius / 2;
2725
+ uv[uIdx] = u;
2726
+ uv[uIdx + 1] = v;
2727
+ uv[uIdx + uOffset] = u;
2728
+ uv[uIdx + 1 + uOffset] = v;
2729
+ idx += 3;
2730
+ uIdx += 2;
3017
2731
 
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
- };
2732
+ if (i > 1) {
2733
+ // bottom indices
2734
+ // indices.push(0, i - 1, i);
2735
+ indices[++iIndex] = 0;
2736
+ indices[++iIndex] = i - 1;
2737
+ indices[++iIndex] = i;
2738
+ }
2739
+ }
3024
2740
 
3025
- _proto.cross = function cross(v) {
3026
- return this.crossVectors(this, v);
3027
- };
2741
+ idx -= 3;
2742
+ points[idx] = points[0];
2743
+ points[idx + 1] = points[1];
2744
+ points[idx + 2] = points[2];
2745
+ var pointsLen = points.length;
2746
+ points[pointsLen - 3] = points[0];
2747
+ points[pointsLen - 2] = points[1];
2748
+ points[pointsLen - 1] = height;
2749
+ var indicesLen = indices.length; // top indices
3028
2750
 
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
- ;
2751
+ iIndex = indices.length - 1;
3063
2752
 
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
- ;
2753
+ for (var _i = 0; _i < indicesLen; _i++) {
2754
+ var index = indices[_i];
2755
+ indices[++iIndex] = index + circlePointsLen; // indices.push(index + circlePointsLen);
2756
+ }
3127
2757
 
3128
- _proto.equals = function equals(v) {
3129
- return v.x === this.x && v.y === this.y && v.z === this.z;
3130
- };
2758
+ var sidePoints = new Float32Array((circlePointsLen * 3 * 2 - 6) * 2);
2759
+ var pIndex = -1;
2760
+ idx = circlePointsLen * 2;
2761
+ uIdx = 0;
2762
+ iIndex = indices.length - 1;
2763
+ var uvIndex = uv.length - 1;
3131
2764
 
3132
- _proto.fromArray = function fromArray(array, offset) {
3133
- if (offset === void 0) {
3134
- offset = 0;
3135
- }
2765
+ for (var _i2 = 0, len = points.length / 2; _i2 < len - 3; _i2 += 3) {
2766
+ var x1 = points[_i2],
2767
+ y1 = points[_i2 + 1],
2768
+ x2 = points[_i2 + 3],
2769
+ y2 = points[_i2 + 4];
2770
+ sidePoints[++pIndex] = x1;
2771
+ sidePoints[++pIndex] = y1;
2772
+ sidePoints[++pIndex] = height;
2773
+ sidePoints[++pIndex] = x2;
2774
+ sidePoints[++pIndex] = y2;
2775
+ sidePoints[++pIndex] = height;
2776
+ sidePoints[++pIndex] = x1;
2777
+ sidePoints[++pIndex] = y1;
2778
+ sidePoints[++pIndex] = 0;
2779
+ sidePoints[++pIndex] = x2;
2780
+ sidePoints[++pIndex] = y2;
2781
+ sidePoints[++pIndex] = 0;
2782
+ var a = idx + 2,
2783
+ b = idx + 3,
2784
+ c = idx,
2785
+ d = idx + 1; // indices.push(a, c, b, c, d, b);
3136
2786
 
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
- ;
2787
+ indices[++iIndex] = c;
2788
+ indices[++iIndex] = a;
2789
+ indices[++iIndex] = d;
2790
+ indices[++iIndex] = a;
2791
+ indices[++iIndex] = b;
2792
+ indices[++iIndex] = d; // indices.push(c, a, d, a, b, d);
3154
2793
 
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
- ;
2794
+ idx += 4;
2795
+ var u1 = uIdx / circlePointsLen,
2796
+ u2 = (uIdx + 1) / circlePointsLen;
2797
+ uv[++uvIndex] = u1;
2798
+ uv[++uvIndex] = height / radius / 2;
2799
+ uv[++uvIndex] = u2;
2800
+ uv[++uvIndex] = height / radius / 2;
2801
+ uv[++uvIndex] = u1;
2802
+ uv[++uvIndex] = 0;
2803
+ uv[++uvIndex] = u2;
2804
+ uv[++uvIndex] = 0; // uvs.push(u1, height / radius / 2, u2, height / radius / 2, u1, 0, u2, 0);
3171
2805
 
3172
- return Vector3;
3173
- }();
2806
+ uIdx++;
2807
+ }
2808
+
2809
+ var position = new Float32Array(points.length + sidePoints.length);
2810
+ position.set(points, 0);
2811
+ position.set(sidePoints, points.length);
2812
+ var normal = generateNormal(indices, position);
2813
+ return {
2814
+ points: points,
2815
+ indices: new Uint32Array(indices),
2816
+ position: position,
2817
+ normal: normal,
2818
+ uv: new Float32Array(uv)
2819
+ };
2820
+ }
3174
2821
 
3175
2822
  /* eslint-disable no-tabs */
3176
2823
  /**
@@ -4465,6 +4112,13 @@
4465
4112
  }();
4466
4113
 
4467
4114
  var UP$1 = new Vector3(0, 0, 1);
4115
+ var right = new Vector3();
4116
+ var left = new Vector3(); // for sharp corners
4117
+
4118
+ var leftOffset = new Vector3();
4119
+ var rightOffset = new Vector3();
4120
+ var tempPoint1 = new Vector3();
4121
+ var tempPoint2 = new Vector3();
4468
4122
  function expandPaths(lines, options) {
4469
4123
  options = Object.assign({}, {
4470
4124
  lineWidth: 1,
@@ -4472,12 +4126,7 @@
4472
4126
  cornerSplit: 10
4473
4127
  }, options);
4474
4128
  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
- });
4129
+ var points = line2Vectors(line);
4481
4130
  var pathPointList = new PathPointList();
4482
4131
  pathPointList.set(points, options.cornerRadius, options.cornerSplit, UP$1);
4483
4132
  var result = generatePathVertexData(pathPointList, options);
@@ -4515,13 +4164,6 @@
4515
4164
  var uv = [];
4516
4165
  var indices = [];
4517
4166
  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
4167
  var pIndex = position.length - 1;
4526
4168
  var nIndex = normal.length - 1;
4527
4169
  var uIndex = uv.length - 1;
@@ -4799,6 +4441,7 @@
4799
4441
  }
4800
4442
 
4801
4443
  var UP = new Vector3(0, 0, 1);
4444
+ var normalDir = new Vector3();
4802
4445
  function expandTubes(lines, options) {
4803
4446
  options = Object.assign({}, {
4804
4447
  radius: 1,
@@ -4807,12 +4450,7 @@
4807
4450
  startRad: -Math.PI / 4
4808
4451
  }, options);
4809
4452
  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
- });
4453
+ var points = line2Vectors(line);
4816
4454
  var pathPointList = new PathPointList();
4817
4455
  pathPointList.set(points, options.cornerRadius, options.cornerSplit, UP);
4818
4456
  var result = generateTubeVertexData(pathPointList, options);
@@ -4850,7 +4488,6 @@
4850
4488
 
4851
4489
  var indices = [];
4852
4490
  var verticesCount = 0;
4853
- var normalDir = new Vector3();
4854
4491
  var pIndex = -1;
4855
4492
  var nIndex = -1;
4856
4493
  var uIndex = -1;