three-base 2.0.130 → 2.0.137

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.
Files changed (125) hide show
  1. package/ApngTexture.d.ts +13 -13
  2. package/ApngTexture.js +61 -61
  3. package/ApngTextureManage.d.ts +18 -18
  4. package/ApngTextureManage.js +87 -87
  5. package/DirectionalLight.d.ts +6 -0
  6. package/DirectionalLight.js +68 -0
  7. package/EventMesh.d.ts +18 -18
  8. package/EventMesh.js +59 -59
  9. package/ExtrudeMesh.d.ts +112 -112
  10. package/ExtrudeMesh.js +366 -366
  11. package/FPScontrol.d.ts +78 -50
  12. package/FPScontrol.js +617 -232
  13. package/Fire/Fire.d.ts +28 -28
  14. package/Fire/Fire.js +79 -79
  15. package/Fire/FireGromtry.d.ts +9 -9
  16. package/Fire/FireGromtry.js +40 -40
  17. package/Fire/FireMaterial.d.ts +28 -28
  18. package/Fire/FireMaterial.js +32 -32
  19. package/Fire/index.d.ts +1 -1
  20. package/Fire/index.js +1 -1
  21. package/Grass/Grass.d.ts +8 -8
  22. package/Grass/Grass.js +38 -38
  23. package/Grass/index.d.ts +1 -1
  24. package/Grass/index.js +1 -1
  25. package/Ground1/Ground1.d.ts +11 -11
  26. package/Ground1/Ground1.js +54 -54
  27. package/Ground1/index.d.ts +1 -1
  28. package/Ground1/index.js +1 -1
  29. package/InstancedMeshBase.d.ts +39 -39
  30. package/InstancedMeshBase.js +293 -293
  31. package/KeyFrameAnimation.d.ts +25 -25
  32. package/KeyFrameAnimation.js +78 -78
  33. package/MeshBase.d.ts +35 -35
  34. package/MeshBase.js +223 -223
  35. package/Mirror.d.ts +25 -25
  36. package/Mirror.js +139 -139
  37. package/PipeMesh/PathGeometry.d.ts +44 -44
  38. package/PipeMesh/PathGeometry.js +300 -300
  39. package/PipeMesh/PathPoint.d.ts +17 -17
  40. package/PipeMesh/PathPoint.js +31 -31
  41. package/PipeMesh/PathPointList.d.ts +31 -31
  42. package/PipeMesh/PathPointList.js +208 -208
  43. package/PipeMesh/PathTubeGeometry.d.ts +25 -25
  44. package/PipeMesh/PathTubeGeometry.js +130 -130
  45. package/PipeMesh/PipeMesh.d.ts +25 -25
  46. package/PipeMesh/PipeMesh.js +63 -63
  47. package/PipeMesh/index.d.ts +1 -1
  48. package/PipeMesh/index.js +1 -1
  49. package/PlaneModal1/PlaneModal1.d.ts +31 -31
  50. package/PlaneModal1/PlaneModal1.js +105 -105
  51. package/PlaneModal1/index.d.ts +1 -1
  52. package/PlaneModal1/index.js +1 -1
  53. package/PlaneText.d.ts +39 -39
  54. package/PlaneText.js +30 -30
  55. package/PlaneWithHtml.d.ts +11 -11
  56. package/PlaneWithHtml.js +63 -68
  57. package/PointLight/PointLight.d.ts +14 -13
  58. package/PointLight/PointLight.js +70 -64
  59. package/PointLight/index.d.ts +1 -1
  60. package/PointLight/index.js +1 -1
  61. package/Sky/Sky.d.ts +9 -9
  62. package/Sky/Sky.js +22 -22
  63. package/Sky/index.d.ts +1 -1
  64. package/Sky/index.js +1 -1
  65. package/SpotLight.d.ts +6 -0
  66. package/SpotLight.js +72 -0
  67. package/SpriteModal1/SpriteModal1.d.ts +30 -30
  68. package/SpriteModal1/SpriteModal1.js +110 -110
  69. package/SpriteModal1/index.d.ts +1 -1
  70. package/SpriteModal1/index.js +1 -1
  71. package/SpriteText.d.ts +45 -45
  72. package/SpriteText.js +163 -163
  73. package/SpriteText2.d.ts +47 -47
  74. package/SpriteText2.js +198 -198
  75. package/SpriteWithHtml.d.ts +7 -7
  76. package/SpriteWithHtml.js +44 -49
  77. package/Text3D/Text3D.d.ts +20 -20
  78. package/Text3D/Text3D.js +62 -62
  79. package/Text3D/fontController.d.ts +59 -59
  80. package/Text3D/fontController.js +199 -199
  81. package/Text3D/index.d.ts +1 -1
  82. package/Text3D/index.js +1 -1
  83. package/ThreeBase.d.ts +111 -81
  84. package/ThreeBase.js +656 -560
  85. package/ThreeMouse.d.ts +40 -40
  86. package/ThreeMouse.js +407 -407
  87. package/Transition.d.ts +40 -40
  88. package/Transition.js +210 -210
  89. package/Water/Water.d.ts +5 -0
  90. package/Water/Water.js +26 -0
  91. package/Water/waternormals.jpg +0 -0
  92. package/declare.d.ts +167 -0
  93. package/index.d.ts +1 -1
  94. package/index.js +2 -2
  95. package/keyContorls.d.ts +25 -25
  96. package/keyContorls.js +98 -98
  97. package/package.json +3 -2
  98. package/pass/bloom_pass.d.ts +2 -2
  99. package/pass/bloom_pass.js +99 -99
  100. package/pass/cover_pass.d.ts +2 -2
  101. package/pass/cover_pass.js +95 -95
  102. package/pass/emissive_ao_pass.d.ts +13 -0
  103. package/pass/emissive_ao_pass.js +370 -0
  104. package/pass/frosted_glass_pass.d.ts +2 -0
  105. package/pass/frosted_glass_pass.js +275 -0
  106. package/pass/fsQuad.d.ts +9 -9
  107. package/pass/fsQuad.js +28 -28
  108. package/pass/glow_pass.d.ts +2 -2
  109. package/pass/glow_pass.js +310 -254
  110. package/pass/ssao_pass.d.ts +13 -0
  111. package/pass/ssao_pass.js +372 -0
  112. package/pass/stroke_pass.d.ts +2 -2
  113. package/pass/stroke_pass.js +199 -199
  114. package/shaders/FXAAShaderMaterial.d.ts +3 -3
  115. package/shaders/FXAAShaderMaterial.js +21 -21
  116. package/shaders/baseTextureToRenderShader.d.ts +2 -2
  117. package/shaders/baseTextureToRenderShader.js +14 -14
  118. package/shaders/copyShader.d.ts +3 -3
  119. package/shaders/copyShader.js +14 -14
  120. package/shaders.d.ts +5 -5
  121. package/shaders.js +42 -42
  122. package/threeLoader.d.ts +34 -34
  123. package/threeLoader.js +527 -527
  124. package/threeUtils.d.ts +52 -52
  125. package/threeUtils.js +330 -330
@@ -1,31 +1,31 @@
1
- import { Vector3 } from 'three/src/math/Vector3';
2
- /**
3
- * PathPoint
4
- */
5
- class PathPoint {
6
- pos = new Vector3();
7
- dir = new Vector3();
8
- right = new Vector3();
9
- up = new Vector3(); // normal
10
- dist = 0; // distance from start
11
- widthScale = 1; // for corner
12
- sharp = false; // marks as sharp corner
13
- constructor() { }
14
- lerpPathPoints(p1, p2, alpha) {
15
- this.pos.lerpVectors(p1.pos, p2.pos, alpha);
16
- this.dir.lerpVectors(p1.dir, p2.dir, alpha);
17
- this.up.lerpVectors(p1.up, p2.up, alpha);
18
- this.right.lerpVectors(p1.right, p2.right, alpha);
19
- this.dist = (p2.dist - p1.dist) * alpha + p1.dist;
20
- this.widthScale = (p2.widthScale - p1.widthScale) * alpha + p1.widthScale;
21
- }
22
- copy(source) {
23
- this.pos.copy(source.pos);
24
- this.dir.copy(source.dir);
25
- this.up.copy(source.up);
26
- this.right.copy(source.right);
27
- this.dist = source.dist;
28
- this.widthScale = source.widthScale;
29
- }
30
- }
31
- export { PathPoint };
1
+ import { Vector3 } from 'three/src/math/Vector3';
2
+ /**
3
+ * PathPoint
4
+ */
5
+ class PathPoint {
6
+ pos = new Vector3();
7
+ dir = new Vector3();
8
+ right = new Vector3();
9
+ up = new Vector3(); // normal
10
+ dist = 0; // distance from start
11
+ widthScale = 1; // for corner
12
+ sharp = false; // marks as sharp corner
13
+ constructor() { }
14
+ lerpPathPoints(p1, p2, alpha) {
15
+ this.pos.lerpVectors(p1.pos, p2.pos, alpha);
16
+ this.dir.lerpVectors(p1.dir, p2.dir, alpha);
17
+ this.up.lerpVectors(p1.up, p2.up, alpha);
18
+ this.right.lerpVectors(p1.right, p2.right, alpha);
19
+ this.dist = (p2.dist - p1.dist) * alpha + p1.dist;
20
+ this.widthScale = (p2.widthScale - p1.widthScale) * alpha + p1.widthScale;
21
+ }
22
+ copy(source) {
23
+ this.pos.copy(source.pos);
24
+ this.dir.copy(source.dir);
25
+ this.up.copy(source.up);
26
+ this.right.copy(source.right);
27
+ this.dist = source.dist;
28
+ this.widthScale = source.widthScale;
29
+ }
30
+ }
31
+ export { PathPoint };
@@ -1,31 +1,31 @@
1
- import { Vector3 } from 'three/src/math/Vector3.js';
2
- import { PathPoint } from './PathPoint.js';
3
- /**
4
- * PathPointList
5
- * input points to generate a PathPoint list
6
- */
7
- declare class PathPointList {
8
- array: Array<PathPoint>;
9
- count: number;
10
- constructor();
11
- /**
12
- * Set points
13
- * @param {Vector3[]} points key points array
14
- * @param {number} cornerRadius? the corner radius. set 0 to disable round corner. default is 0.1
15
- * @param {number} cornerSplit? the corner split. default is 10.
16
- * @param {number} up? force up. default is auto up (calculate by tangent).
17
- * @param {boolean} close? close path. default is false.
18
- */
19
- set(points: Array<Vector3>, cornerRadius?: number, cornerSplit?: number, up?: Vector3, close?: boolean): void;
20
- /**
21
- * Get distance of this path
22
- * @return {number}
23
- */
24
- distance(): number;
25
- _getByIndex(index: number): PathPoint;
26
- _start(current: Vector3, next: Vector3, up?: Vector3): void;
27
- _end(current: Vector3): void;
28
- _corner(current: Vector3, next: Vector3, cornerRadius: number, cornerSplit: number, up?: Vector3): void;
29
- _sharpCorner(current: Vector3, next: Vector3, up?: Vector3, dirType?: 0 | 1 | 2, sharp?: boolean): void;
30
- }
31
- export { PathPointList };
1
+ import { Vector3 } from 'three/src/math/Vector3.js';
2
+ import { PathPoint } from './PathPoint.js';
3
+ /**
4
+ * PathPointList
5
+ * input points to generate a PathPoint list
6
+ */
7
+ declare class PathPointList {
8
+ array: Array<PathPoint>;
9
+ count: number;
10
+ constructor();
11
+ /**
12
+ * Set points
13
+ * @param {Vector3[]} points key points array
14
+ * @param {number} cornerRadius? the corner radius. set 0 to disable round corner. default is 0.1
15
+ * @param {number} cornerSplit? the corner split. default is 10.
16
+ * @param {number} up? force up. default is auto up (calculate by tangent).
17
+ * @param {boolean} close? close path. default is false.
18
+ */
19
+ set(points: Array<Vector3>, cornerRadius?: number, cornerSplit?: number, up?: Vector3, close?: boolean): void;
20
+ /**
21
+ * Get distance of this path
22
+ * @return {number}
23
+ */
24
+ distance(): number;
25
+ _getByIndex(index: number): PathPoint;
26
+ _start(current: Vector3, next: Vector3, up?: Vector3): void;
27
+ _end(current: Vector3): void;
28
+ _corner(current: Vector3, next: Vector3, cornerRadius: number, cornerSplit: number, up?: Vector3): void;
29
+ _sharpCorner(current: Vector3, next: Vector3, up?: Vector3, dirType?: 0 | 1 | 2, sharp?: boolean): void;
30
+ }
31
+ export { PathPointList };
@@ -1,208 +1,208 @@
1
- import { Vector3 } from 'three/src/math/Vector3.js';
2
- import { PathPoint } from './PathPoint.js';
3
- import { Matrix4 } from 'three/src/math/Matrix4.js';
4
- import { QuadraticBezierCurve3 } from 'three/src/extras/curves/QuadraticBezierCurve3.js';
5
- const helpVec3_1 = new Vector3();
6
- const helpVec3_2 = new Vector3();
7
- const helpVec3_3 = new Vector3();
8
- const helpMat4 = new Matrix4();
9
- const helpCurve = new QuadraticBezierCurve3(new Vector3(), new Vector3(), new Vector3());
10
- function _getCornerBezierCurve(last, current, next, cornerRadius, firstCorner, out) {
11
- const lastDir = helpVec3_1.subVectors(current, last);
12
- const nextDir = helpVec3_2.subVectors(next, current);
13
- const lastDirLength = lastDir.length();
14
- const nextDirLength = nextDir.length();
15
- lastDir.normalize();
16
- nextDir.normalize();
17
- // cornerRadius can not bigger then lineDistance / 2, auto fix this
18
- const v0Dist = Math.min((firstCorner ? lastDirLength / 2 : lastDirLength) * 0.999999, cornerRadius);
19
- out.v0.copy(current).sub(lastDir.multiplyScalar(v0Dist));
20
- out.v1.copy(current);
21
- const v2Dist = Math.min((nextDirLength / 2) * 0.999999, cornerRadius);
22
- out.v2.copy(current).add(nextDir.multiplyScalar(v2Dist));
23
- return out;
24
- }
25
- /**
26
- * PathPointList
27
- * input points to generate a PathPoint list
28
- */
29
- class PathPointList {
30
- array = []; // path point array
31
- count = 0;
32
- constructor() { }
33
- /**
34
- * Set points
35
- * @param {Vector3[]} points key points array
36
- * @param {number} cornerRadius? the corner radius. set 0 to disable round corner. default is 0.1
37
- * @param {number} cornerSplit? the corner split. default is 10.
38
- * @param {number} up? force up. default is auto up (calculate by tangent).
39
- * @param {boolean} close? close path. default is false.
40
- */
41
- set(points, cornerRadius = 0.1, cornerSplit = 10, up, close = false) {
42
- points = points.slice(0);
43
- if (points.length < 2) {
44
- console.warn('PathPointList: points length less than 2.');
45
- this.count = 0;
46
- return;
47
- }
48
- // Auto close
49
- if (close && !points[0].equals(points[points.length - 1])) {
50
- points.push(new Vector3().copy(points[0]));
51
- }
52
- // Generate path point list
53
- for (let i = 0, l = points.length; i < l; i++) {
54
- if (i === 0) {
55
- this._start(points[i], points[i + 1], up);
56
- }
57
- else if (i === l - 1) {
58
- if (close) {
59
- // Connect end point and start point
60
- this._corner(points[i], points[1], cornerRadius, cornerSplit, up);
61
- // Fix start point
62
- const dist = this.array[0].dist; // should not copy dist
63
- this.array[0].copy(this.array[this.count - 1]);
64
- this.array[0].dist = dist;
65
- }
66
- else {
67
- this._end(points[i]);
68
- }
69
- }
70
- else {
71
- this._corner(points[i], points[i + 1], cornerRadius, cornerSplit, up);
72
- }
73
- }
74
- }
75
- /**
76
- * Get distance of this path
77
- * @return {number}
78
- */
79
- distance() {
80
- if (this.count > 0) {
81
- return this.array[this.count - 1].dist;
82
- }
83
- return 0;
84
- }
85
- _getByIndex(index) {
86
- if (!this.array[index]) {
87
- this.array[index] = new PathPoint();
88
- }
89
- return this.array[index];
90
- }
91
- _start(current, next, up) {
92
- this.count = 0;
93
- const point = this._getByIndex(this.count);
94
- point.pos.copy(current);
95
- point.dir.subVectors(next, current);
96
- // init start up dir
97
- if (up) {
98
- point.up.copy(up);
99
- }
100
- else {
101
- // select an initial normal vector perpendicular to the first tangent vector
102
- let min = Number.MAX_VALUE;
103
- const tx = Math.abs(point.dir.x);
104
- const ty = Math.abs(point.dir.y);
105
- const tz = Math.abs(point.dir.z);
106
- if (tx < min) {
107
- min = tx;
108
- point.up.set(1, 0, 0);
109
- }
110
- if (ty < min) {
111
- min = ty;
112
- point.up.set(0, 1, 0);
113
- }
114
- if (tz < min) {
115
- point.up.set(0, 0, 1);
116
- }
117
- }
118
- point.right.crossVectors(point.dir, point.up).normalize();
119
- point.up.crossVectors(point.right, point.dir).normalize();
120
- point.dist = 0;
121
- point.widthScale = 1;
122
- point.sharp = false;
123
- point.dir.normalize();
124
- this.count++;
125
- }
126
- _end(current) {
127
- const lastPoint = this.array[this.count - 1];
128
- const point = this._getByIndex(this.count);
129
- point.pos.copy(current);
130
- point.dir.subVectors(current, lastPoint.pos);
131
- const dist = point.dir.length();
132
- point.dir.normalize();
133
- point.up.copy(lastPoint.up); // copy last up
134
- const vec = helpVec3_1.crossVectors(lastPoint.dir, point.dir);
135
- if (vec.length() > Number.EPSILON) {
136
- vec.normalize();
137
- const theta = Math.acos(Math.min(Math.max(lastPoint.dir.dot(point.dir), -1), 1)); // clamp for floating pt errors
138
- point.up.applyMatrix4(helpMat4.makeRotationAxis(vec, theta));
139
- }
140
- point.right.crossVectors(point.dir, point.up).normalize();
141
- point.dist = lastPoint.dist + dist;
142
- point.widthScale = 1;
143
- point.sharp = false;
144
- this.count++;
145
- }
146
- _corner(current, next, cornerRadius, cornerSplit, up) {
147
- if (cornerRadius > 0 && cornerSplit > 0) {
148
- const lastPoint = this.array[this.count - 1];
149
- const curve = _getCornerBezierCurve(lastPoint.pos, current, next, cornerRadius, this.count - 1 === 0, helpCurve);
150
- const samplerPoints = curve.getPoints(cornerSplit);
151
- for (let f = 0; f < cornerSplit; f++) {
152
- this._sharpCorner(samplerPoints[f], samplerPoints[f + 1], up, f === 0 ? 1 : 0);
153
- }
154
- if (!samplerPoints[cornerSplit].equals(next)) {
155
- this._sharpCorner(samplerPoints[cornerSplit], next, up, 2);
156
- }
157
- }
158
- else {
159
- this._sharpCorner(current, next, up, 0, true);
160
- }
161
- }
162
- // dirType: 0 - use middle dir / 1 - use last dir / 2- use next dir
163
- _sharpCorner(current, next, up, dirType = 0, sharp = false) {
164
- const lastPoint = this.array[this.count - 1];
165
- const point = this._getByIndex(this.count);
166
- const lastDir = helpVec3_1.subVectors(current, lastPoint.pos);
167
- const nextDir = helpVec3_2.subVectors(next, current);
168
- const lastDirLength = lastDir.length();
169
- lastDir.normalize();
170
- nextDir.normalize();
171
- point.pos.copy(current);
172
- if (dirType === 1) {
173
- point.dir.copy(lastDir);
174
- }
175
- else if (dirType === 2) {
176
- point.dir.copy(nextDir);
177
- }
178
- else {
179
- point.dir.addVectors(lastDir, nextDir);
180
- point.dir.normalize();
181
- }
182
- if (up) {
183
- if (point.dir.dot(up) === 1) {
184
- point.right.crossVectors(nextDir, up).normalize();
185
- }
186
- else {
187
- point.right.crossVectors(point.dir, up).normalize();
188
- }
189
- point.up.crossVectors(point.right, point.dir).normalize();
190
- }
191
- else {
192
- point.up.copy(lastPoint.up);
193
- const vec = helpVec3_3.crossVectors(lastPoint.dir, point.dir);
194
- if (vec.length() > Number.EPSILON) {
195
- vec.normalize();
196
- const theta = Math.acos(Math.min(Math.max(lastPoint.dir.dot(point.dir), -1), 1)); // clamp for floating pt errors
197
- point.up.applyMatrix4(helpMat4.makeRotationAxis(vec, theta));
198
- }
199
- point.right.crossVectors(point.dir, point.up).normalize();
200
- }
201
- point.dist = lastPoint.dist + lastDirLength;
202
- const _cos = lastDir.dot(nextDir);
203
- point.widthScale = Math.min(1 / Math.sqrt((1 + _cos) / 2), 1.415) || 1;
204
- point.sharp = Math.abs(_cos - 1) > 0.05 && sharp;
205
- this.count++;
206
- }
207
- }
208
- export { PathPointList };
1
+ import { Vector3 } from 'three/src/math/Vector3.js';
2
+ import { PathPoint } from './PathPoint.js';
3
+ import { Matrix4 } from 'three/src/math/Matrix4.js';
4
+ import { QuadraticBezierCurve3 } from 'three/src/extras/curves/QuadraticBezierCurve3.js';
5
+ const helpVec3_1 = new Vector3();
6
+ const helpVec3_2 = new Vector3();
7
+ const helpVec3_3 = new Vector3();
8
+ const helpMat4 = new Matrix4();
9
+ const helpCurve = new QuadraticBezierCurve3(new Vector3(), new Vector3(), new Vector3());
10
+ function _getCornerBezierCurve(last, current, next, cornerRadius, firstCorner, out) {
11
+ const lastDir = helpVec3_1.subVectors(current, last);
12
+ const nextDir = helpVec3_2.subVectors(next, current);
13
+ const lastDirLength = lastDir.length();
14
+ const nextDirLength = nextDir.length();
15
+ lastDir.normalize();
16
+ nextDir.normalize();
17
+ // cornerRadius can not bigger then lineDistance / 2, auto fix this
18
+ const v0Dist = Math.min((firstCorner ? lastDirLength / 2 : lastDirLength) * 0.999999, cornerRadius);
19
+ out.v0.copy(current).sub(lastDir.multiplyScalar(v0Dist));
20
+ out.v1.copy(current);
21
+ const v2Dist = Math.min((nextDirLength / 2) * 0.999999, cornerRadius);
22
+ out.v2.copy(current).add(nextDir.multiplyScalar(v2Dist));
23
+ return out;
24
+ }
25
+ /**
26
+ * PathPointList
27
+ * input points to generate a PathPoint list
28
+ */
29
+ class PathPointList {
30
+ array = []; // path point array
31
+ count = 0;
32
+ constructor() { }
33
+ /**
34
+ * Set points
35
+ * @param {Vector3[]} points key points array
36
+ * @param {number} cornerRadius? the corner radius. set 0 to disable round corner. default is 0.1
37
+ * @param {number} cornerSplit? the corner split. default is 10.
38
+ * @param {number} up? force up. default is auto up (calculate by tangent).
39
+ * @param {boolean} close? close path. default is false.
40
+ */
41
+ set(points, cornerRadius = 0.1, cornerSplit = 10, up, close = false) {
42
+ points = points.slice(0);
43
+ if (points.length < 2) {
44
+ console.warn('PathPointList: points length less than 2.');
45
+ this.count = 0;
46
+ return;
47
+ }
48
+ // Auto close
49
+ if (close && !points[0].equals(points[points.length - 1])) {
50
+ points.push(new Vector3().copy(points[0]));
51
+ }
52
+ // Generate path point list
53
+ for (let i = 0, l = points.length; i < l; i++) {
54
+ if (i === 0) {
55
+ this._start(points[i], points[i + 1], up);
56
+ }
57
+ else if (i === l - 1) {
58
+ if (close) {
59
+ // Connect end point and start point
60
+ this._corner(points[i], points[1], cornerRadius, cornerSplit, up);
61
+ // Fix start point
62
+ const dist = this.array[0].dist; // should not copy dist
63
+ this.array[0].copy(this.array[this.count - 1]);
64
+ this.array[0].dist = dist;
65
+ }
66
+ else {
67
+ this._end(points[i]);
68
+ }
69
+ }
70
+ else {
71
+ this._corner(points[i], points[i + 1], cornerRadius, cornerSplit, up);
72
+ }
73
+ }
74
+ }
75
+ /**
76
+ * Get distance of this path
77
+ * @return {number}
78
+ */
79
+ distance() {
80
+ if (this.count > 0) {
81
+ return this.array[this.count - 1].dist;
82
+ }
83
+ return 0;
84
+ }
85
+ _getByIndex(index) {
86
+ if (!this.array[index]) {
87
+ this.array[index] = new PathPoint();
88
+ }
89
+ return this.array[index];
90
+ }
91
+ _start(current, next, up) {
92
+ this.count = 0;
93
+ const point = this._getByIndex(this.count);
94
+ point.pos.copy(current);
95
+ point.dir.subVectors(next, current);
96
+ // init start up dir
97
+ if (up) {
98
+ point.up.copy(up);
99
+ }
100
+ else {
101
+ // select an initial normal vector perpendicular to the first tangent vector
102
+ let min = Number.MAX_VALUE;
103
+ const tx = Math.abs(point.dir.x);
104
+ const ty = Math.abs(point.dir.y);
105
+ const tz = Math.abs(point.dir.z);
106
+ if (tx < min) {
107
+ min = tx;
108
+ point.up.set(1, 0, 0);
109
+ }
110
+ if (ty < min) {
111
+ min = ty;
112
+ point.up.set(0, 1, 0);
113
+ }
114
+ if (tz < min) {
115
+ point.up.set(0, 0, 1);
116
+ }
117
+ }
118
+ point.right.crossVectors(point.dir, point.up).normalize();
119
+ point.up.crossVectors(point.right, point.dir).normalize();
120
+ point.dist = 0;
121
+ point.widthScale = 1;
122
+ point.sharp = false;
123
+ point.dir.normalize();
124
+ this.count++;
125
+ }
126
+ _end(current) {
127
+ const lastPoint = this.array[this.count - 1];
128
+ const point = this._getByIndex(this.count);
129
+ point.pos.copy(current);
130
+ point.dir.subVectors(current, lastPoint.pos);
131
+ const dist = point.dir.length();
132
+ point.dir.normalize();
133
+ point.up.copy(lastPoint.up); // copy last up
134
+ const vec = helpVec3_1.crossVectors(lastPoint.dir, point.dir);
135
+ if (vec.length() > Number.EPSILON) {
136
+ vec.normalize();
137
+ const theta = Math.acos(Math.min(Math.max(lastPoint.dir.dot(point.dir), -1), 1)); // clamp for floating pt errors
138
+ point.up.applyMatrix4(helpMat4.makeRotationAxis(vec, theta));
139
+ }
140
+ point.right.crossVectors(point.dir, point.up).normalize();
141
+ point.dist = lastPoint.dist + dist;
142
+ point.widthScale = 1;
143
+ point.sharp = false;
144
+ this.count++;
145
+ }
146
+ _corner(current, next, cornerRadius, cornerSplit, up) {
147
+ if (cornerRadius > 0 && cornerSplit > 0) {
148
+ const lastPoint = this.array[this.count - 1];
149
+ const curve = _getCornerBezierCurve(lastPoint.pos, current, next, cornerRadius, this.count - 1 === 0, helpCurve);
150
+ const samplerPoints = curve.getPoints(cornerSplit);
151
+ for (let f = 0; f < cornerSplit; f++) {
152
+ this._sharpCorner(samplerPoints[f], samplerPoints[f + 1], up, f === 0 ? 1 : 0);
153
+ }
154
+ if (!samplerPoints[cornerSplit].equals(next)) {
155
+ this._sharpCorner(samplerPoints[cornerSplit], next, up, 2);
156
+ }
157
+ }
158
+ else {
159
+ this._sharpCorner(current, next, up, 0, true);
160
+ }
161
+ }
162
+ // dirType: 0 - use middle dir / 1 - use last dir / 2- use next dir
163
+ _sharpCorner(current, next, up, dirType = 0, sharp = false) {
164
+ const lastPoint = this.array[this.count - 1];
165
+ const point = this._getByIndex(this.count);
166
+ const lastDir = helpVec3_1.subVectors(current, lastPoint.pos);
167
+ const nextDir = helpVec3_2.subVectors(next, current);
168
+ const lastDirLength = lastDir.length();
169
+ lastDir.normalize();
170
+ nextDir.normalize();
171
+ point.pos.copy(current);
172
+ if (dirType === 1) {
173
+ point.dir.copy(lastDir);
174
+ }
175
+ else if (dirType === 2) {
176
+ point.dir.copy(nextDir);
177
+ }
178
+ else {
179
+ point.dir.addVectors(lastDir, nextDir);
180
+ point.dir.normalize();
181
+ }
182
+ if (up) {
183
+ if (point.dir.dot(up) === 1) {
184
+ point.right.crossVectors(nextDir, up).normalize();
185
+ }
186
+ else {
187
+ point.right.crossVectors(point.dir, up).normalize();
188
+ }
189
+ point.up.crossVectors(point.right, point.dir).normalize();
190
+ }
191
+ else {
192
+ point.up.copy(lastPoint.up);
193
+ const vec = helpVec3_3.crossVectors(lastPoint.dir, point.dir);
194
+ if (vec.length() > Number.EPSILON) {
195
+ vec.normalize();
196
+ const theta = Math.acos(Math.min(Math.max(lastPoint.dir.dot(point.dir), -1), 1)); // clamp for floating pt errors
197
+ point.up.applyMatrix4(helpMat4.makeRotationAxis(vec, theta));
198
+ }
199
+ point.right.crossVectors(point.dir, point.up).normalize();
200
+ }
201
+ point.dist = lastPoint.dist + lastDirLength;
202
+ const _cos = lastDir.dot(nextDir);
203
+ point.widthScale = Math.min(1 / Math.sqrt((1 + _cos) / 2), 1.415) || 1;
204
+ point.sharp = Math.abs(_cos - 1) > 0.05 && sharp;
205
+ this.count++;
206
+ }
207
+ }
208
+ export { PathPointList };
@@ -1,25 +1,25 @@
1
- import { Usage } from 'three/src/constants.js';
2
- import { PathGeometry, type Options, type PathGeometryParam } from './PathGeometry.js';
3
- import type { PathPointList } from './PathPointList.js';
4
- /**
5
- * PathTubeGeometry
6
- */
7
- declare class PathTubeGeometry extends PathGeometry {
8
- /**
9
- * @param {Object|Number} initData - If initData is number, geometry init by empty data and set it as the max vertex. If initData is Object, it contains pathPointList and options.
10
- * @param {Boolean} [generateUv2=false]
11
- */
12
- constructor(initData: PathGeometryParam, generateUv2?: boolean);
13
- _initByData(pathPointList: PathPointList, options: Options, usage: Usage, generateUv2: boolean): void;
14
- /**
15
- * Update geometry by PathPointList instance
16
- * @param {PathPointList} pathPointList
17
- * @param {Object} options
18
- * @param {Number} [options.radius=0.1]
19
- * @param {Number} [options.progress=1]
20
- * @param {Boolean} [options.radialSegments=8]
21
- * @param {String} [options.startRad=0]
22
- */
23
- update(pathPointList: PathPointList, options: Options): void;
24
- }
25
- export { PathTubeGeometry };
1
+ import { Usage } from 'three/src/constants.js';
2
+ import { PathGeometry, type Options, type PathGeometryParam } from './PathGeometry.js';
3
+ import type { PathPointList } from './PathPointList.js';
4
+ /**
5
+ * PathTubeGeometry
6
+ */
7
+ declare class PathTubeGeometry extends PathGeometry {
8
+ /**
9
+ * @param {Object|Number} initData - If initData is number, geometry init by empty data and set it as the max vertex. If initData is Object, it contains pathPointList and options.
10
+ * @param {Boolean} [generateUv2=false]
11
+ */
12
+ constructor(initData: PathGeometryParam, generateUv2?: boolean);
13
+ _initByData(pathPointList: PathPointList, options: Options, usage: Usage, generateUv2: boolean): void;
14
+ /**
15
+ * Update geometry by PathPointList instance
16
+ * @param {PathPointList} pathPointList
17
+ * @param {Object} options
18
+ * @param {Number} [options.radius=0.1]
19
+ * @param {Number} [options.progress=1]
20
+ * @param {Boolean} [options.radialSegments=8]
21
+ * @param {String} [options.startRad=0]
22
+ */
23
+ update(pathPointList: PathPointList, options: Options): void;
24
+ }
25
+ export { PathTubeGeometry };