poly-extrude 0.9.0 → 0.11.0

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