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