three-base 2.0.169 → 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 (124) hide show
  1. package/FPScontrol.d.ts +55 -30
  2. package/FPScontrol.js +278 -225
  3. package/FPScontrol.ts +177 -127
  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 +8 -3
  10. package/MktMesh/MktMesh.js +43 -14
  11. package/MktMesh/MktMesh.ts +40 -14
  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/MktMesh/types.d.ts +5 -1
  25. package/MktMesh/types.ts +5 -1
  26. package/PipeMesh/PipeJoint.d.ts +22 -0
  27. package/PipeMesh/PipeJoint.js +33 -0
  28. package/PipeMesh/PipeJoint.ts +38 -0
  29. package/PipeMesh/PipeMesh.d.ts +94 -22
  30. package/PipeMesh/PipeMesh.js +192 -53
  31. package/PipeMesh/PipeMesh.ts +223 -76
  32. package/PipeMesh/PipeStraight.d.ts +19 -0
  33. package/PipeMesh/PipeStraight.js +34 -0
  34. package/PipeMesh/PipeStraight.ts +45 -0
  35. package/PipeMesh/axisSnap.d.ts +52 -0
  36. package/PipeMesh/axisSnap.js +52 -0
  37. package/PipeMesh/axisSnap.ts +93 -0
  38. package/PipeMesh/directRoute.d.ts +85 -0
  39. package/PipeMesh/directRoute.js +126 -0
  40. package/PipeMesh/directRoute.ts +190 -0
  41. package/PipeMesh/index.d.ts +6 -0
  42. package/PipeMesh/index.js +6 -0
  43. package/PipeMesh/index.ts +7 -1
  44. package/PipeMesh/pipeMaterial.d.ts +16 -0
  45. package/PipeMesh/pipeMaterial.js +23 -0
  46. package/PipeMesh/pipeMaterial.ts +26 -0
  47. package/ThreeBase.d.ts +2 -49
  48. package/ThreeBase.js +43 -164
  49. package/ThreeBase.ts +1176 -1314
  50. package/instanced/InstancedBatch.d.ts +14 -1
  51. package/instanced/InstancedBatch.js +53 -3
  52. package/instanced/InstancedBatch.ts +62 -3
  53. package/instanced/InstancedChild.d.ts +24 -0
  54. package/instanced/InstancedChild.js +40 -0
  55. package/instanced/InstancedChild.ts +41 -0
  56. package/instanced/InstancedGroup.d.ts +48 -0
  57. package/instanced/InstancedGroup.js +45 -1
  58. package/instanced/InstancedGroup.ts +85 -0
  59. package/package.json +2 -7
  60. package/pass/bloom_pass.js +7 -14
  61. package/pass/bloom_pass.ts +7 -16
  62. package/pass/cover_pass.js +7 -15
  63. package/pass/cover_pass.ts +7 -17
  64. package/pass/debugDepthState.d.ts +16 -8
  65. package/pass/debugDepthState.js +4 -0
  66. package/pass/debugDepthState.ts +27 -9
  67. package/pass/glow_pass.js +19 -110
  68. package/pass/glow_pass.ts +19 -115
  69. package/pass/ssao_pass.d.ts +14 -59
  70. package/pass/ssao_pass.js +66 -171
  71. package/pass/ssao_pass.ts +63 -207
  72. package/pass/stroke_pass.js +13 -16
  73. package/pass/stroke_pass.ts +14 -18
  74. package/shaders/baseDepthVisShader.d.ts +1 -1
  75. package/shaders/baseDepthVisShader.js +1 -1
  76. package/shaders/baseDepthVisShader.ts +1 -1
  77. package/shaders/debugDepthCompareShader.d.ts +2 -2
  78. package/shaders/debugDepthCompareShader.js +2 -2
  79. package/shaders/debugDepthCompareShader.ts +2 -2
  80. package/shaders/debugDepthJudgeShader.d.ts +1 -1
  81. package/shaders/debugDepthJudgeShader.js +1 -1
  82. package/shaders/debugDepthJudgeShader.ts +1 -1
  83. package/PipeMesh/PathGeometry.d.ts +0 -44
  84. package/PipeMesh/PathGeometry.js +0 -307
  85. package/PipeMesh/PathGeometry.ts +0 -343
  86. package/PipeMesh/PathPoint.d.ts +0 -17
  87. package/PipeMesh/PathPoint.js +0 -31
  88. package/PipeMesh/PathPoint.ts +0 -36
  89. package/PipeMesh/PathPointList.d.ts +0 -31
  90. package/PipeMesh/PathPointList.js +0 -209
  91. package/PipeMesh/PathPointList.ts +0 -227
  92. package/PipeMesh/PathTubeGeometry.d.ts +0 -25
  93. package/PipeMesh/PathTubeGeometry.js +0 -130
  94. package/PipeMesh/PathTubeGeometry.ts +0 -146
  95. package/WaterFlow/FloatingDuck.d.ts +0 -88
  96. package/WaterFlow/FloatingDuck.js +0 -307
  97. package/WaterFlow/FloatingDuck.ts +0 -445
  98. package/WaterFlow/GPUFluidSimulation.d.ts +0 -56
  99. package/WaterFlow/GPUFluidSimulation.js +0 -785
  100. package/WaterFlow/GPUFluidSimulation.ts +0 -827
  101. package/WaterFlow/ReservoirSystem.d.ts +0 -106
  102. package/WaterFlow/ReservoirSystem.js +0 -621
  103. package/WaterFlow/ReservoirSystem.ts +0 -754
  104. package/WaterFlow/SPHField.d.ts +0 -35
  105. package/WaterFlow/SPHField.js +0 -204
  106. package/WaterFlow/SPHField.ts +0 -228
  107. package/WaterFlow/ScreenSpaceFluidPass.d.ts +0 -69
  108. package/WaterFlow/ScreenSpaceFluidPass.js +0 -736
  109. package/WaterFlow/ScreenSpaceFluidPass.ts +0 -789
  110. package/WaterFlow/ShallowWaterSurface.d.ts +0 -45
  111. package/WaterFlow/ShallowWaterSurface.js +0 -441
  112. package/WaterFlow/ShallowWaterSurface.ts +0 -510
  113. package/WaterFlow/WaterFlow.d.ts +0 -87
  114. package/WaterFlow/WaterFlow.js +0 -171
  115. package/WaterFlow/WaterFlow.ts +0 -219
  116. package/WaterFlow/types.d.ts +0 -161
  117. package/WaterFlow/types.js +0 -1
  118. package/WaterFlow/types.ts +0 -189
  119. package/WaterFlow/waterFlowPass.d.ts +0 -3
  120. package/WaterFlow/waterFlowPass.js +0 -20
  121. package/WaterFlow/waterFlowPass.ts +0 -40
  122. package/shaders/debugExcludedShader.d.ts +0 -13
  123. package/shaders/debugExcludedShader.js +0 -46
  124. package/shaders/debugExcludedShader.ts +0 -48
@@ -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
- }
@@ -1,146 +0,0 @@
1
- import { StaticDrawUsage, Usage } from 'three/src/constants.js';
2
- import { PathGeometry, type Options, type PathGeometryParam } from './PathGeometry.js';
3
- import { PathPoint } from './PathPoint.js';
4
- import type { PathPointList } from './PathPointList.js';
5
- import { BufferAttribute } from 'three/src/core/BufferAttribute.js';
6
- import { Vector3 } from 'three/src/math/Vector3.js';
7
-
8
- interface TubeVertexData {
9
- position: Array<number>;
10
- normal: Array<number>;
11
- uv: Array<number>;
12
- uv2: Array<number>;
13
- indices: Array<number>;
14
- count: number;
15
- }
16
-
17
- /**
18
- * PathTubeGeometry
19
- */
20
- class PathTubeGeometry extends PathGeometry {
21
- /**
22
- * @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.
23
- * @param {Boolean} [generateUv2=false]
24
- */
25
- constructor(initData: PathGeometryParam, generateUv2: boolean = false) {
26
- super(initData, generateUv2);
27
- }
28
-
29
- _initByData(pathPointList: PathPointList, options: Options = {}, usage: Usage, generateUv2: boolean): void {
30
- const vertexData = generateTubeVertexData(pathPointList, options, generateUv2);
31
- if (vertexData && vertexData.count !== 0) {
32
- this.setAttribute('position', new BufferAttribute(new Float32Array(vertexData.position), 3).setUsage(usage || StaticDrawUsage));
33
- this.setAttribute('normal', new BufferAttribute(new Float32Array(vertexData.normal), 3).setUsage(usage || StaticDrawUsage));
34
- this.setAttribute('uv', new BufferAttribute(new Float32Array(vertexData.uv), 2).setUsage(usage || StaticDrawUsage));
35
- if (generateUv2) {
36
- this.setAttribute('uv2', new BufferAttribute(new Float32Array(vertexData.uv2), 2).setUsage(usage || StaticDrawUsage));
37
- }
38
- this.setIndex(vertexData.indices);
39
- }
40
- else {
41
- this._initByMaxVertex(2, generateUv2);
42
- }
43
- }
44
-
45
- /**
46
- * Update geometry by PathPointList instance
47
- * @param {PathPointList} pathPointList
48
- * @param {Object} options
49
- * @param {Number} [options.radius=0.1]
50
- * @param {Number} [options.progress=1]
51
- * @param {Boolean} [options.radialSegments=8]
52
- * @param {String} [options.startRad=0]
53
- */
54
- update(pathPointList: PathPointList, options: Options): void {
55
- const generateUv2 = !!this.getAttribute('uv2');
56
- const vertexData = generateTubeVertexData(pathPointList, options, generateUv2);
57
- if (vertexData) {
58
- this._updateAttributes(vertexData.position, vertexData.normal, vertexData.uv, generateUv2 ? vertexData.uv2 : null, vertexData.indices);
59
- this.drawRange.count = vertexData.count;
60
- }
61
- else {
62
- this.drawRange.count = 0;
63
- }
64
- }
65
- }
66
-
67
- export { PathTubeGeometry };
68
-
69
- // Vertex Data Generate Functions
70
- function generateTubeVertexData(pathPointList: PathPointList, options: Options, generateUv2: boolean = false): TubeVertexData | null {
71
- const radius = options.radius || 0.1;
72
- const progress = options.progress !== undefined ? options.progress : 1;
73
- const radialSegments = Math.max(2, options.radialSegments || 8);
74
- const startRad = options.startRad || 0;
75
- const circum = radius * 2 * Math.PI;
76
- const totalDistance = pathPointList.distance();
77
- const progressDistance = progress * totalDistance;
78
- if (progressDistance == 0) {
79
- return null;
80
- }
81
- let count = 0;
82
- // modify data
83
- const position: Array<number> = [];
84
- const normal: Array<number> = [];
85
- const uv: Array<number> = [];
86
- const uv2: Array<number> = [];
87
- const indices: Array<number> = [];
88
- let verticesCount = 0;
89
- const normalDir = new Vector3();
90
-
91
- function addVertices(pathPoint: PathPoint, radius: number, radialSegments: number): void {
92
- const first = position.length === 0;
93
- const uvDist = pathPoint.dist / circum;
94
- const uvDist2 = pathPoint.dist / totalDistance;
95
- for (let r = 0; r <= radialSegments; r++) {
96
- let _r = r;
97
- if (_r == radialSegments) {
98
- _r = 0;
99
- }
100
- normalDir
101
- .copy(pathPoint.up)
102
- .applyAxisAngle(pathPoint.dir, startRad + (Math.PI * 2 * _r) / radialSegments)
103
- .normalize();
104
- 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);
105
- normal.push(normalDir.x, normalDir.y, normalDir.z);
106
- uv.push(uvDist, r / radialSegments);
107
- if (generateUv2) {
108
- uv2.push(uvDist2, r / radialSegments);
109
- }
110
- verticesCount++;
111
- }
112
- if (!first) {
113
- const begin1 = verticesCount - (radialSegments + 1) * 2;
114
- const begin2 = verticesCount - (radialSegments + 1);
115
- for (let i = 0; i < radialSegments; i++) {
116
- indices.push(begin2 + i, begin1 + i, begin1 + i + 1, begin2 + i, begin1 + i + 1, begin2 + i + 1);
117
- count += 6;
118
- }
119
- }
120
- }
121
- if (progressDistance > 0) {
122
- for (let i = 0; i < pathPointList.count; i++) {
123
- const pathPoint = pathPointList.array[i];
124
- if (pathPoint.dist > progressDistance) {
125
- const prevPoint = pathPointList.array[i - 1];
126
- const lastPoint = new PathPoint();
127
- // linear lerp for progress
128
- const alpha = (progressDistance - prevPoint.dist) / (pathPoint.dist - prevPoint.dist);
129
- lastPoint.lerpPathPoints(prevPoint, pathPoint, alpha);
130
- addVertices(lastPoint, radius, radialSegments);
131
- break;
132
- }
133
- else {
134
- addVertices(pathPoint, radius, radialSegments);
135
- }
136
- }
137
- }
138
- return {
139
- position,
140
- normal,
141
- uv,
142
- uv2,
143
- indices,
144
- count,
145
- };
146
- }
@@ -1,88 +0,0 @@
1
- /** 水面采样结果(由 ShallowWaterSurface.sampleSurface 回填,供浮力/倾斜计算读高度与坡度)。 */
2
- interface DuckSurfaceSample {
3
- height?: number;
4
- velocityY?: number;
5
- slopeX?: number;
6
- slopeZ?: number;
7
- flowX?: number;
8
- flowZ?: number;
9
- impact?: number;
10
- }
11
- /** 构造选项。 */
12
- export interface FloatingDuckOptions {
13
- basinMinX: number;
14
- basinMaxX: number;
15
- basinHalfZ: number;
16
- waterY: number;
17
- startX?: number;
18
- startZ?: number;
19
- }
20
- /** setEnvironment / clampToBounds 用的环境口径。 */
21
- export interface DuckEnvironment {
22
- minX: number;
23
- maxX: number;
24
- halfZ: number;
25
- centerZ?: number;
26
- waterY: number;
27
- }
28
- /** update 的可调项。 */
29
- export interface DuckUpdateOptions {
30
- surface?: DuckSurfaceSampler | null;
31
- impactX?: number;
32
- impactZ?: number;
33
- impactEnergy?: number;
34
- emitting?: boolean;
35
- }
36
- /** 只取 update 真正用到的水面能力(避免与 ShallowWaterSurface 形成类型环)。 */
37
- interface DuckSurfaceSampler {
38
- sampleSurface(worldX: number, worldZ: number, target?: DuckSurfaceSample): DuckSurfaceSample;
39
- }
40
- /** 漂浮的橡皮鸭:跟随水面高度/坡度做浮沉与倾斜,可被鼠标拖拽。 */
41
- export declare class FloatingDuck {
42
- private readonly bounds;
43
- /** 静水面高度;setEnvironment 会随容器变化更新(故非 readonly)。 */
44
- private waterY;
45
- private readonly start;
46
- private readonly velocity;
47
- private readonly surfaceSample;
48
- private yaw;
49
- private yawVelocity;
50
- private pitch;
51
- private roll;
52
- private readonly radiusX;
53
- private readonly radiusZ;
54
- private active;
55
- private dragging;
56
- private readonly dragOffset;
57
- private readonly dragVelocity;
58
- private readonly lastDragPosition;
59
- private readonly group;
60
- private readonly model;
61
- private readonly pickGeometry;
62
- private readonly pickMaterial;
63
- private readonly pickMesh;
64
- private readonly yellowMaterial;
65
- private readonly wingMaterial;
66
- private readonly beakMaterial;
67
- private readonly eyeMaterial;
68
- private readonly highlightMaterial;
69
- private readonly sphereGeometry;
70
- private readonly body;
71
- private readonly head;
72
- private readonly beak;
73
- private readonly tailGeometry;
74
- private readonly tail;
75
- constructor({ basinMinX, basinMaxX, basinHalfZ, waterY, startX, startZ, }: FloatingDuckOptions);
76
- setActive(active: boolean): void;
77
- setEnvironment({ minX, maxX, halfZ, centerZ, waterY }: DuckEnvironment, reposition?: boolean): void;
78
- place(x: number, z: number): void;
79
- translateContainer(deltaX: number, deltaZ: number): void;
80
- beginDrag(worldX: number, worldZ: number): void;
81
- dragTo(worldX: number, worldZ: number, deltaSeconds: number): void;
82
- endDrag(): void;
83
- clampToBounds(): void;
84
- reset(): void;
85
- update(delta: number, elapsed: number, { surface, impactX, impactZ, impactEnergy, emitting, }?: DuckUpdateOptions): void;
86
- dispose(): void;
87
- }
88
- export {};