three-base 2.0.172 → 2.0.175

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 (115) hide show
  1. package/FPScontrol.d.ts +15 -24
  2. package/FPScontrol.js +63 -87
  3. package/FPScontrol.ts +64 -88
  4. package/Ground1/Ground1.d.ts +4 -2
  5. package/Ground1/Ground1.js +77 -57
  6. package/Ground1/Ground1.ts +77 -57
  7. package/Mirror.js +0 -4
  8. package/Mirror.ts +0 -4
  9. package/MktMesh/MktMesh.d.ts +3 -2
  10. package/MktMesh/MktMesh.js +27 -8
  11. package/MktMesh/MktMesh.ts +24 -8
  12. package/MktMesh/mktMappingShader.d.ts +6 -5
  13. package/MktMesh/mktMappingShader.js +26 -19
  14. package/MktMesh/mktMappingShader.ts +28 -19
  15. package/MktMesh/mktShader.d.ts +127 -58
  16. package/MktMesh/mktShader.js +192 -117
  17. package/MktMesh/mktShader.ts +251 -127
  18. package/MktMesh/panoSlotRoster.d.ts +2 -2
  19. package/MktMesh/panoSlotRoster.js +9 -7
  20. package/MktMesh/panoSlotRoster.ts +9 -7
  21. package/MktMesh/panoTileStitcher.d.ts +20 -13
  22. package/MktMesh/panoTileStitcher.js +97 -76
  23. package/MktMesh/panoTileStitcher.ts +119 -90
  24. package/PipeMesh/PipeJoint.d.ts +22 -0
  25. package/PipeMesh/PipeJoint.js +33 -0
  26. package/PipeMesh/PipeJoint.ts +38 -0
  27. package/PipeMesh/PipeMesh.d.ts +94 -22
  28. package/PipeMesh/PipeMesh.js +192 -53
  29. package/PipeMesh/PipeMesh.ts +223 -76
  30. package/PipeMesh/PipeStraight.d.ts +19 -0
  31. package/PipeMesh/PipeStraight.js +34 -0
  32. package/PipeMesh/PipeStraight.ts +45 -0
  33. package/PipeMesh/axisSnap.d.ts +52 -0
  34. package/PipeMesh/axisSnap.js +52 -0
  35. package/PipeMesh/axisSnap.ts +93 -0
  36. package/PipeMesh/directRoute.d.ts +85 -0
  37. package/PipeMesh/directRoute.js +126 -0
  38. package/PipeMesh/directRoute.ts +190 -0
  39. package/PipeMesh/index.d.ts +6 -0
  40. package/PipeMesh/index.js +6 -0
  41. package/PipeMesh/index.ts +7 -1
  42. package/PipeMesh/pipeMaterial.d.ts +16 -0
  43. package/PipeMesh/pipeMaterial.js +23 -0
  44. package/PipeMesh/pipeMaterial.ts +26 -0
  45. package/ThreeBase.d.ts +1 -39
  46. package/ThreeBase.js +38 -147
  47. package/ThreeBase.ts +1176 -1302
  48. package/instanced/InstancedBatch.d.ts +14 -1
  49. package/instanced/InstancedBatch.js +53 -3
  50. package/instanced/InstancedBatch.ts +62 -3
  51. package/instanced/InstancedChild.d.ts +24 -0
  52. package/instanced/InstancedChild.js +40 -0
  53. package/instanced/InstancedChild.ts +41 -0
  54. package/instanced/InstancedGroup.d.ts +48 -0
  55. package/instanced/InstancedGroup.js +45 -1
  56. package/instanced/InstancedGroup.ts +85 -0
  57. package/package.json +2 -7
  58. package/pass/debugDepthState.d.ts +16 -8
  59. package/pass/debugDepthState.js +4 -0
  60. package/pass/debugDepthState.ts +27 -9
  61. package/pass/glow_pass.js +11 -94
  62. package/pass/glow_pass.ts +11 -97
  63. package/pass/ssao_pass.d.ts +9 -23
  64. package/pass/ssao_pass.js +41 -128
  65. package/pass/ssao_pass.ts +36 -166
  66. package/pass/stroke_pass.js +3 -0
  67. package/pass/stroke_pass.ts +4 -0
  68. package/shaders/debugDepthCompareShader.d.ts +1 -1
  69. package/shaders/debugDepthCompareShader.js +1 -1
  70. package/shaders/debugDepthCompareShader.ts +1 -1
  71. package/shaders/debugDepthJudgeShader.d.ts +1 -1
  72. package/shaders/debugDepthJudgeShader.js +1 -1
  73. package/shaders/debugDepthJudgeShader.ts +1 -1
  74. package/PipeMesh/PathGeometry.d.ts +0 -44
  75. package/PipeMesh/PathGeometry.js +0 -307
  76. package/PipeMesh/PathGeometry.ts +0 -343
  77. package/PipeMesh/PathPoint.d.ts +0 -17
  78. package/PipeMesh/PathPoint.js +0 -31
  79. package/PipeMesh/PathPoint.ts +0 -36
  80. package/PipeMesh/PathPointList.d.ts +0 -31
  81. package/PipeMesh/PathPointList.js +0 -209
  82. package/PipeMesh/PathPointList.ts +0 -227
  83. package/PipeMesh/PathTubeGeometry.d.ts +0 -25
  84. package/PipeMesh/PathTubeGeometry.js +0 -130
  85. package/PipeMesh/PathTubeGeometry.ts +0 -146
  86. package/WaterFlow/FloatingDuck.d.ts +0 -88
  87. package/WaterFlow/FloatingDuck.js +0 -307
  88. package/WaterFlow/FloatingDuck.ts +0 -445
  89. package/WaterFlow/GPUFluidSimulation.d.ts +0 -56
  90. package/WaterFlow/GPUFluidSimulation.js +0 -785
  91. package/WaterFlow/GPUFluidSimulation.ts +0 -827
  92. package/WaterFlow/ReservoirSystem.d.ts +0 -106
  93. package/WaterFlow/ReservoirSystem.js +0 -621
  94. package/WaterFlow/ReservoirSystem.ts +0 -754
  95. package/WaterFlow/SPHField.d.ts +0 -35
  96. package/WaterFlow/SPHField.js +0 -204
  97. package/WaterFlow/SPHField.ts +0 -228
  98. package/WaterFlow/ScreenSpaceFluidPass.d.ts +0 -69
  99. package/WaterFlow/ScreenSpaceFluidPass.js +0 -736
  100. package/WaterFlow/ScreenSpaceFluidPass.ts +0 -789
  101. package/WaterFlow/ShallowWaterSurface.d.ts +0 -45
  102. package/WaterFlow/ShallowWaterSurface.js +0 -441
  103. package/WaterFlow/ShallowWaterSurface.ts +0 -510
  104. package/WaterFlow/WaterFlow.d.ts +0 -87
  105. package/WaterFlow/WaterFlow.js +0 -171
  106. package/WaterFlow/WaterFlow.ts +0 -219
  107. package/WaterFlow/types.d.ts +0 -161
  108. package/WaterFlow/types.js +0 -1
  109. package/WaterFlow/types.ts +0 -189
  110. package/WaterFlow/waterFlowPass.d.ts +0 -3
  111. package/WaterFlow/waterFlowPass.js +0 -20
  112. package/WaterFlow/waterFlowPass.ts +0 -40
  113. package/shaders/debugExcludedShader.d.ts +0 -15
  114. package/shaders/debugExcludedShader.js +0 -48
  115. package/shaders/debugExcludedShader.ts +0 -50
@@ -1,31 +0,0 @@
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,36 +0,0 @@
1
- import { Vector3 } from 'three/src/math/Vector3';
2
-
3
- /**
4
- * PathPoint
5
- */
6
- class PathPoint {
7
- pos: Vector3 = new Vector3();
8
- dir: Vector3 = new Vector3();
9
- right: Vector3 = new Vector3();
10
- up: Vector3 = new Vector3(); // normal
11
- dist: number = 0; // distance from start
12
- widthScale: number = 1; // for corner
13
- sharp: boolean = false; // marks as sharp corner
14
-
15
- constructor() { }
16
-
17
- lerpPathPoints(p1: PathPoint, p2: PathPoint, alpha: number): void {
18
- this.pos.lerpVectors(p1.pos, p2.pos, alpha);
19
- this.dir.lerpVectors(p1.dir, p2.dir, alpha);
20
- this.up.lerpVectors(p1.up, p2.up, alpha);
21
- this.right.lerpVectors(p1.right, p2.right, alpha);
22
- this.dist = (p2.dist - p1.dist) * alpha + p1.dist;
23
- this.widthScale = (p2.widthScale - p1.widthScale) * alpha + p1.widthScale;
24
- }
25
-
26
- copy(source: PathPoint): void {
27
- this.pos.copy(source.pos);
28
- this.dir.copy(source.dir);
29
- this.up.copy(source.up);
30
- this.right.copy(source.right);
31
- this.dist = source.dist;
32
- this.widthScale = source.widthScale;
33
- }
34
- }
35
-
36
- export { PathPoint };
@@ -1,31 +0,0 @@
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,209 +0,0 @@
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
- min = tz;
116
- point.up.set(0, 0, 1);
117
- }
118
- }
119
- point.right.crossVectors(point.dir, point.up).normalize();
120
- point.up.crossVectors(point.right, point.dir).normalize();
121
- point.dist = 0;
122
- point.widthScale = 1;
123
- point.sharp = false;
124
- point.dir.normalize();
125
- this.count++;
126
- }
127
- _end(current) {
128
- const lastPoint = this.array[this.count - 1];
129
- const point = this._getByIndex(this.count);
130
- point.pos.copy(current);
131
- point.dir.subVectors(current, lastPoint.pos);
132
- const dist = point.dir.length();
133
- point.dir.normalize();
134
- point.up.copy(lastPoint.up); // copy last up
135
- const vec = helpVec3_1.crossVectors(lastPoint.dir, point.dir);
136
- if (vec.length() > Number.EPSILON) {
137
- vec.normalize();
138
- const theta = Math.acos(Math.min(Math.max(lastPoint.dir.dot(point.dir), -1), 1)); // clamp for floating pt errors
139
- point.up.applyMatrix4(helpMat4.makeRotationAxis(vec, theta));
140
- }
141
- point.right.crossVectors(point.dir, point.up).normalize();
142
- point.dist = lastPoint.dist + dist;
143
- point.widthScale = 1;
144
- point.sharp = false;
145
- this.count++;
146
- }
147
- _corner(current, next, cornerRadius, cornerSplit, up) {
148
- if (cornerRadius > 0 && cornerSplit > 0) {
149
- const lastPoint = this.array[this.count - 1];
150
- const curve = _getCornerBezierCurve(lastPoint.pos, current, next, cornerRadius, this.count - 1 === 0, helpCurve);
151
- const samplerPoints = curve.getPoints(cornerSplit);
152
- for (let f = 0; f < cornerSplit; f++) {
153
- this._sharpCorner(samplerPoints[f], samplerPoints[f + 1], up, f === 0 ? 1 : 0);
154
- }
155
- if (!samplerPoints[cornerSplit].equals(next)) {
156
- this._sharpCorner(samplerPoints[cornerSplit], next, up, 2);
157
- }
158
- }
159
- else {
160
- this._sharpCorner(current, next, up, 0, true);
161
- }
162
- }
163
- // dirType: 0 - use middle dir / 1 - use last dir / 2- use next dir
164
- _sharpCorner(current, next, up, dirType = 0, sharp = false) {
165
- const lastPoint = this.array[this.count - 1];
166
- const point = this._getByIndex(this.count);
167
- const lastDir = helpVec3_1.subVectors(current, lastPoint.pos);
168
- const nextDir = helpVec3_2.subVectors(next, current);
169
- const lastDirLength = lastDir.length();
170
- lastDir.normalize();
171
- nextDir.normalize();
172
- point.pos.copy(current);
173
- if (dirType === 1) {
174
- point.dir.copy(lastDir);
175
- }
176
- else if (dirType === 2) {
177
- point.dir.copy(nextDir);
178
- }
179
- else {
180
- point.dir.addVectors(lastDir, nextDir);
181
- point.dir.normalize();
182
- }
183
- if (up) {
184
- if (point.dir.dot(up) === 1) {
185
- point.right.crossVectors(nextDir, up).normalize();
186
- }
187
- else {
188
- point.right.crossVectors(point.dir, up).normalize();
189
- }
190
- point.up.crossVectors(point.right, point.dir).normalize();
191
- }
192
- else {
193
- point.up.copy(lastPoint.up);
194
- const vec = helpVec3_3.crossVectors(lastPoint.dir, point.dir);
195
- if (vec.length() > Number.EPSILON) {
196
- vec.normalize();
197
- const theta = Math.acos(Math.min(Math.max(lastPoint.dir.dot(point.dir), -1), 1)); // clamp for floating pt errors
198
- point.up.applyMatrix4(helpMat4.makeRotationAxis(vec, theta));
199
- }
200
- point.right.crossVectors(point.dir, point.up).normalize();
201
- }
202
- point.dist = lastPoint.dist + lastDirLength;
203
- const _cos = lastDir.dot(nextDir);
204
- point.widthScale = Math.min(1 / Math.sqrt((1 + _cos) / 2), 1.415) || 1;
205
- point.sharp = Math.abs(_cos - 1) > 0.05 && sharp;
206
- this.count++;
207
- }
208
- }
209
- export { PathPointList };
@@ -1,227 +0,0 @@
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
-
6
- const helpVec3_1: Vector3 = new Vector3();
7
- const helpVec3_2: Vector3 = new Vector3();
8
- const helpVec3_3: Vector3 = new Vector3();
9
- const helpMat4: Matrix4 = new Matrix4();
10
- const helpCurve: QuadraticBezierCurve3 = new QuadraticBezierCurve3(new Vector3(), new Vector3(), new Vector3());
11
-
12
- interface CornerBezierCurve {
13
- v0: Vector3;
14
- v1: Vector3;
15
- v2: Vector3;
16
- }
17
-
18
- function _getCornerBezierCurve(last: Vector3, current: Vector3, next: Vector3, cornerRadius: number, firstCorner: boolean, out: QuadraticBezierCurve3): QuadraticBezierCurve3 {
19
- const lastDir = helpVec3_1.subVectors(current, last);
20
- const nextDir = helpVec3_2.subVectors(next, current);
21
- const lastDirLength = lastDir.length();
22
- const nextDirLength = nextDir.length();
23
- lastDir.normalize();
24
- nextDir.normalize();
25
- // cornerRadius can not bigger then lineDistance / 2, auto fix this
26
- const v0Dist = Math.min((firstCorner ? lastDirLength / 2 : lastDirLength) * 0.999999, cornerRadius);
27
- out.v0.copy(current).sub(lastDir.multiplyScalar(v0Dist));
28
- out.v1.copy(current);
29
- const v2Dist = Math.min((nextDirLength / 2) * 0.999999, cornerRadius);
30
- out.v2.copy(current).add(nextDir.multiplyScalar(v2Dist));
31
- return out;
32
- }
33
-
34
- /**
35
- * PathPointList
36
- * input points to generate a PathPoint list
37
- */
38
- class PathPointList {
39
- array: Array<PathPoint> = []; // path point array
40
- count: number = 0;
41
-
42
- constructor() { }
43
-
44
- /**
45
- * Set points
46
- * @param {Vector3[]} points key points array
47
- * @param {number} cornerRadius? the corner radius. set 0 to disable round corner. default is 0.1
48
- * @param {number} cornerSplit? the corner split. default is 10.
49
- * @param {number} up? force up. default is auto up (calculate by tangent).
50
- * @param {boolean} close? close path. default is false.
51
- */
52
- set(points: Array<Vector3>, cornerRadius: number = 0.1, cornerSplit: number = 10, up?: Vector3, close: boolean = false): void {
53
- points = points.slice(0);
54
- if (points.length < 2) {
55
- console.warn('PathPointList: points length less than 2.');
56
- this.count = 0;
57
- return;
58
- }
59
- // Auto close
60
- if (close && !points[0].equals(points[points.length - 1])) {
61
- points.push(new Vector3().copy(points[0]));
62
- }
63
- // Generate path point list
64
- for (let i = 0, l = points.length; i < l; i++) {
65
- if (i === 0) {
66
- this._start(points[i], points[i + 1], up);
67
- }
68
- else if (i === l - 1) {
69
- if (close) {
70
- // Connect end point and start point
71
- this._corner(points[i], points[1], cornerRadius, cornerSplit, up);
72
- // Fix start point
73
- const dist = this.array[0].dist; // should not copy dist
74
- this.array[0].copy(this.array[this.count - 1]);
75
- this.array[0].dist = dist;
76
- }
77
- else {
78
- this._end(points[i]);
79
- }
80
- }
81
- else {
82
- this._corner(points[i], points[i + 1], cornerRadius, cornerSplit, up);
83
- }
84
- }
85
- }
86
-
87
- /**
88
- * Get distance of this path
89
- * @return {number}
90
- */
91
- distance(): number {
92
- if (this.count > 0) {
93
- return this.array[this.count - 1].dist;
94
- }
95
- return 0;
96
- }
97
-
98
- _getByIndex(index: number): PathPoint {
99
- if (!this.array[index]) {
100
- this.array[index] = new PathPoint();
101
- }
102
- return this.array[index];
103
- }
104
-
105
- _start(current: Vector3, next: Vector3, up?: Vector3): void {
106
- this.count = 0;
107
- const point = this._getByIndex(this.count);
108
- point.pos.copy(current);
109
- point.dir.subVectors(next, current);
110
- // init start up dir
111
- if (up) {
112
- point.up.copy(up);
113
- }
114
- else {
115
- // select an initial normal vector perpendicular to the first tangent vector
116
- let min = Number.MAX_VALUE;
117
- const tx = Math.abs(point.dir.x);
118
- const ty = Math.abs(point.dir.y);
119
- const tz = Math.abs(point.dir.z);
120
- if (tx < min) {
121
- min = tx;
122
- point.up.set(1, 0, 0);
123
- }
124
- if (ty < min) {
125
- min = ty;
126
- point.up.set(0, 1, 0);
127
- }
128
- if (tz < min) {
129
- min = tz;
130
- point.up.set(0, 0, 1);
131
- }
132
- }
133
- point.right.crossVectors(point.dir, point.up).normalize();
134
- point.up.crossVectors(point.right, point.dir).normalize();
135
- point.dist = 0;
136
- point.widthScale = 1;
137
- point.sharp = false;
138
- point.dir.normalize();
139
- this.count++;
140
- }
141
-
142
- _end(current: Vector3): void {
143
- const lastPoint = this.array[this.count - 1];
144
- const point = this._getByIndex(this.count);
145
- point.pos.copy(current);
146
- point.dir.subVectors(current, lastPoint.pos);
147
- const dist = point.dir.length();
148
- point.dir.normalize();
149
- point.up.copy(lastPoint.up); // copy last up
150
- const vec = helpVec3_1.crossVectors(lastPoint.dir, point.dir);
151
- if (vec.length() > Number.EPSILON) {
152
- vec.normalize();
153
- const theta = Math.acos(Math.min(Math.max(lastPoint.dir.dot(point.dir), -1), 1)); // clamp for floating pt errors
154
- point.up.applyMatrix4(helpMat4.makeRotationAxis(vec, theta));
155
- }
156
- point.right.crossVectors(point.dir, point.up).normalize();
157
- point.dist = lastPoint.dist + dist;
158
- point.widthScale = 1;
159
- point.sharp = false;
160
- this.count++;
161
- }
162
-
163
- _corner(current: Vector3, next: Vector3, cornerRadius: number, cornerSplit: number, up?: Vector3): void {
164
- if (cornerRadius > 0 && cornerSplit > 0) {
165
- const lastPoint = this.array[this.count - 1];
166
- const curve = _getCornerBezierCurve(lastPoint.pos, current, next, cornerRadius, this.count - 1 === 0, helpCurve);
167
- const samplerPoints = curve.getPoints(cornerSplit);
168
- for (let f = 0; f < cornerSplit; f++) {
169
- this._sharpCorner(samplerPoints[f], samplerPoints[f + 1], up, f === 0 ? 1 : 0);
170
- }
171
- if (!samplerPoints[cornerSplit].equals(next)) {
172
- this._sharpCorner(samplerPoints[cornerSplit], next, up, 2);
173
- }
174
- }
175
- else {
176
- this._sharpCorner(current, next, up, 0, true);
177
- }
178
- }
179
-
180
- // dirType: 0 - use middle dir / 1 - use last dir / 2- use next dir
181
- _sharpCorner(current: Vector3, next: Vector3, up?: Vector3, dirType: 0 | 1 | 2 = 0, sharp: boolean = false): void {
182
- const lastPoint = this.array[this.count - 1];
183
- const point = this._getByIndex(this.count);
184
- const lastDir = helpVec3_1.subVectors(current, lastPoint.pos);
185
- const nextDir = helpVec3_2.subVectors(next, current);
186
- const lastDirLength = lastDir.length();
187
- lastDir.normalize();
188
- nextDir.normalize();
189
- point.pos.copy(current);
190
- if (dirType === 1) {
191
- point.dir.copy(lastDir);
192
- }
193
- else if (dirType === 2) {
194
- point.dir.copy(nextDir);
195
- }
196
- else {
197
- point.dir.addVectors(lastDir, nextDir);
198
- point.dir.normalize();
199
- }
200
- if (up) {
201
- if (point.dir.dot(up) === 1) {
202
- point.right.crossVectors(nextDir, up).normalize();
203
- }
204
- else {
205
- point.right.crossVectors(point.dir, up).normalize();
206
- }
207
- point.up.crossVectors(point.right, point.dir).normalize();
208
- }
209
- else {
210
- point.up.copy(lastPoint.up);
211
- const vec = helpVec3_3.crossVectors(lastPoint.dir, point.dir);
212
- if (vec.length() > Number.EPSILON) {
213
- vec.normalize();
214
- const theta = Math.acos(Math.min(Math.max(lastPoint.dir.dot(point.dir), -1), 1)); // clamp for floating pt errors
215
- point.up.applyMatrix4(helpMat4.makeRotationAxis(vec, theta));
216
- }
217
- point.right.crossVectors(point.dir, point.up).normalize();
218
- }
219
- point.dist = lastPoint.dist + lastDirLength;
220
- const _cos = lastDir.dot(nextDir);
221
- point.widthScale = Math.min(1 / Math.sqrt((1 + _cos) / 2), 1.415) || 1;
222
- point.sharp = Math.abs(_cos - 1) > 0.05 && sharp;
223
- this.count++;
224
- }
225
- }
226
-
227
- export { PathPointList };
@@ -1,25 +0,0 @@
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,130 +0,0 @@
1
- import { StaticDrawUsage } from 'three/src/constants.js';
2
- import { PathGeometry } from './PathGeometry.js';
3
- import { PathPoint } from './PathPoint.js';
4
- import { BufferAttribute } from 'three/src/core/BufferAttribute.js';
5
- import { Vector3 } from 'three/src/math/Vector3.js';
6
- /**
7
- * PathTubeGeometry
8
- */
9
- class PathTubeGeometry extends PathGeometry {
10
- /**
11
- * @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.
12
- * @param {Boolean} [generateUv2=false]
13
- */
14
- constructor(initData, generateUv2 = false) {
15
- super(initData, generateUv2);
16
- }
17
- _initByData(pathPointList, options = {}, usage, generateUv2) {
18
- const vertexData = generateTubeVertexData(pathPointList, options, generateUv2);
19
- if (vertexData && vertexData.count !== 0) {
20
- this.setAttribute('position', new BufferAttribute(new Float32Array(vertexData.position), 3).setUsage(usage || StaticDrawUsage));
21
- this.setAttribute('normal', new BufferAttribute(new Float32Array(vertexData.normal), 3).setUsage(usage || StaticDrawUsage));
22
- this.setAttribute('uv', new BufferAttribute(new Float32Array(vertexData.uv), 2).setUsage(usage || StaticDrawUsage));
23
- if (generateUv2) {
24
- this.setAttribute('uv2', new BufferAttribute(new Float32Array(vertexData.uv2), 2).setUsage(usage || StaticDrawUsage));
25
- }
26
- this.setIndex(vertexData.indices);
27
- }
28
- else {
29
- this._initByMaxVertex(2, generateUv2);
30
- }
31
- }
32
- /**
33
- * Update geometry by PathPointList instance
34
- * @param {PathPointList} pathPointList
35
- * @param {Object} options
36
- * @param {Number} [options.radius=0.1]
37
- * @param {Number} [options.progress=1]
38
- * @param {Boolean} [options.radialSegments=8]
39
- * @param {String} [options.startRad=0]
40
- */
41
- update(pathPointList, options) {
42
- const generateUv2 = !!this.getAttribute('uv2');
43
- const vertexData = generateTubeVertexData(pathPointList, options, generateUv2);
44
- if (vertexData) {
45
- this._updateAttributes(vertexData.position, vertexData.normal, vertexData.uv, generateUv2 ? vertexData.uv2 : null, vertexData.indices);
46
- this.drawRange.count = vertexData.count;
47
- }
48
- else {
49
- this.drawRange.count = 0;
50
- }
51
- }
52
- }
53
- export { PathTubeGeometry };
54
- // Vertex Data Generate Functions
55
- function generateTubeVertexData(pathPointList, options, generateUv2 = false) {
56
- const radius = options.radius || 0.1;
57
- const progress = options.progress !== undefined ? options.progress : 1;
58
- const radialSegments = Math.max(2, options.radialSegments || 8);
59
- const startRad = options.startRad || 0;
60
- const circum = radius * 2 * Math.PI;
61
- const totalDistance = pathPointList.distance();
62
- const progressDistance = progress * totalDistance;
63
- if (progressDistance == 0) {
64
- return null;
65
- }
66
- let count = 0;
67
- // modify data
68
- const position = [];
69
- const normal = [];
70
- const uv = [];
71
- const uv2 = [];
72
- const indices = [];
73
- let verticesCount = 0;
74
- const normalDir = new Vector3();
75
- function addVertices(pathPoint, radius, radialSegments) {
76
- const first = position.length === 0;
77
- const uvDist = pathPoint.dist / circum;
78
- const uvDist2 = pathPoint.dist / totalDistance;
79
- for (let r = 0; r <= radialSegments; r++) {
80
- let _r = r;
81
- if (_r == radialSegments) {
82
- _r = 0;
83
- }
84
- normalDir
85
- .copy(pathPoint.up)
86
- .applyAxisAngle(pathPoint.dir, startRad + (Math.PI * 2 * _r) / radialSegments)
87
- .normalize();
88
- position.push(pathPoint.pos.x + normalDir.x * radius * pathPoint.widthScale, pathPoint.pos.y + normalDir.y * radius * pathPoint.widthScale, pathPoint.pos.z + normalDir.z * radius * pathPoint.widthScale);
89
- normal.push(normalDir.x, normalDir.y, normalDir.z);
90
- uv.push(uvDist, r / radialSegments);
91
- if (generateUv2) {
92
- uv2.push(uvDist2, r / radialSegments);
93
- }
94
- verticesCount++;
95
- }
96
- if (!first) {
97
- const begin1 = verticesCount - (radialSegments + 1) * 2;
98
- const begin2 = verticesCount - (radialSegments + 1);
99
- for (let i = 0; i < radialSegments; i++) {
100
- indices.push(begin2 + i, begin1 + i, begin1 + i + 1, begin2 + i, begin1 + i + 1, begin2 + i + 1);
101
- count += 6;
102
- }
103
- }
104
- }
105
- if (progressDistance > 0) {
106
- for (let i = 0; i < pathPointList.count; i++) {
107
- const pathPoint = pathPointList.array[i];
108
- if (pathPoint.dist > progressDistance) {
109
- const prevPoint = pathPointList.array[i - 1];
110
- const lastPoint = new PathPoint();
111
- // linear lerp for progress
112
- const alpha = (progressDistance - prevPoint.dist) / (pathPoint.dist - prevPoint.dist);
113
- lastPoint.lerpPathPoints(prevPoint, pathPoint, alpha);
114
- addVertices(lastPoint, radius, radialSegments);
115
- break;
116
- }
117
- else {
118
- addVertices(pathPoint, radius, radialSegments);
119
- }
120
- }
121
- }
122
- return {
123
- position,
124
- normal,
125
- uv,
126
- uv2,
127
- indices,
128
- count,
129
- };
130
- }