three-base 2.0.172 → 2.0.180

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 (127) 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/boxLine2.d.ts +42 -0
  13. package/MktMesh/boxLine2.js +185 -0
  14. package/MktMesh/boxLine2.ts +222 -0
  15. package/MktMesh/imagePlane.d.ts +60 -0
  16. package/MktMesh/imagePlane.js +158 -0
  17. package/MktMesh/imagePlane.ts +203 -0
  18. package/MktMesh/imageTileLoader.d.ts +19 -0
  19. package/MktMesh/imageTileLoader.js +55 -0
  20. package/MktMesh/imageTileLoader.ts +64 -0
  21. package/MktMesh/mktMappingShader.d.ts +6 -5
  22. package/MktMesh/mktMappingShader.js +26 -19
  23. package/MktMesh/mktMappingShader.ts +28 -19
  24. package/MktMesh/mktShader.d.ts +127 -58
  25. package/MktMesh/mktShader.js +192 -117
  26. package/MktMesh/mktShader.ts +251 -127
  27. package/MktMesh/modelSlot.d.ts +123 -0
  28. package/MktMesh/modelSlot.js +339 -0
  29. package/MktMesh/modelSlot.ts +383 -0
  30. package/MktMesh/panoSlotRoster.d.ts +2 -2
  31. package/MktMesh/panoSlotRoster.js +9 -7
  32. package/MktMesh/panoSlotRoster.ts +9 -7
  33. package/MktMesh/panoTileStitcher.d.ts +20 -13
  34. package/MktMesh/panoTileStitcher.js +97 -76
  35. package/MktMesh/panoTileStitcher.ts +119 -90
  36. package/PipeMesh/PipeJoint.d.ts +22 -0
  37. package/PipeMesh/PipeJoint.js +33 -0
  38. package/PipeMesh/PipeJoint.ts +38 -0
  39. package/PipeMesh/PipeMesh.d.ts +94 -22
  40. package/PipeMesh/PipeMesh.js +192 -53
  41. package/PipeMesh/PipeMesh.ts +223 -76
  42. package/PipeMesh/PipeStraight.d.ts +19 -0
  43. package/PipeMesh/PipeStraight.js +34 -0
  44. package/PipeMesh/PipeStraight.ts +45 -0
  45. package/PipeMesh/axisSnap.d.ts +52 -0
  46. package/PipeMesh/axisSnap.js +52 -0
  47. package/PipeMesh/axisSnap.ts +93 -0
  48. package/PipeMesh/directRoute.d.ts +85 -0
  49. package/PipeMesh/directRoute.js +126 -0
  50. package/PipeMesh/directRoute.ts +190 -0
  51. package/PipeMesh/index.d.ts +6 -0
  52. package/PipeMesh/index.js +6 -0
  53. package/PipeMesh/index.ts +7 -1
  54. package/PipeMesh/pipeMaterial.d.ts +16 -0
  55. package/PipeMesh/pipeMaterial.js +23 -0
  56. package/PipeMesh/pipeMaterial.ts +26 -0
  57. package/ThreeBase.d.ts +1 -39
  58. package/ThreeBase.js +38 -147
  59. package/ThreeBase.ts +1176 -1302
  60. package/instanced/InstancedBatch.d.ts +14 -1
  61. package/instanced/InstancedBatch.js +53 -3
  62. package/instanced/InstancedBatch.ts +62 -3
  63. package/instanced/InstancedChild.d.ts +24 -0
  64. package/instanced/InstancedChild.js +40 -0
  65. package/instanced/InstancedChild.ts +41 -0
  66. package/instanced/InstancedGroup.d.ts +48 -0
  67. package/instanced/InstancedGroup.js +45 -1
  68. package/instanced/InstancedGroup.ts +85 -0
  69. package/package.json +22 -7
  70. package/pass/debugDepthState.d.ts +16 -8
  71. package/pass/debugDepthState.js +4 -0
  72. package/pass/debugDepthState.ts +27 -9
  73. package/pass/glow_pass.js +11 -94
  74. package/pass/glow_pass.ts +11 -97
  75. package/pass/ssao_pass.d.ts +9 -23
  76. package/pass/ssao_pass.js +41 -128
  77. package/pass/ssao_pass.ts +36 -166
  78. package/pass/stroke_pass.js +3 -0
  79. package/pass/stroke_pass.ts +4 -0
  80. package/shaders/debugDepthCompareShader.d.ts +1 -1
  81. package/shaders/debugDepthCompareShader.js +1 -1
  82. package/shaders/debugDepthCompareShader.ts +1 -1
  83. package/shaders/debugDepthJudgeShader.d.ts +1 -1
  84. package/shaders/debugDepthJudgeShader.js +1 -1
  85. package/shaders/debugDepthJudgeShader.ts +1 -1
  86. package/PipeMesh/PathGeometry.d.ts +0 -44
  87. package/PipeMesh/PathGeometry.js +0 -307
  88. package/PipeMesh/PathGeometry.ts +0 -343
  89. package/PipeMesh/PathPoint.d.ts +0 -17
  90. package/PipeMesh/PathPoint.js +0 -31
  91. package/PipeMesh/PathPoint.ts +0 -36
  92. package/PipeMesh/PathPointList.d.ts +0 -31
  93. package/PipeMesh/PathPointList.js +0 -209
  94. package/PipeMesh/PathPointList.ts +0 -227
  95. package/PipeMesh/PathTubeGeometry.d.ts +0 -25
  96. package/PipeMesh/PathTubeGeometry.js +0 -130
  97. package/PipeMesh/PathTubeGeometry.ts +0 -146
  98. package/WaterFlow/FloatingDuck.d.ts +0 -88
  99. package/WaterFlow/FloatingDuck.js +0 -307
  100. package/WaterFlow/FloatingDuck.ts +0 -445
  101. package/WaterFlow/GPUFluidSimulation.d.ts +0 -56
  102. package/WaterFlow/GPUFluidSimulation.js +0 -785
  103. package/WaterFlow/GPUFluidSimulation.ts +0 -827
  104. package/WaterFlow/ReservoirSystem.d.ts +0 -106
  105. package/WaterFlow/ReservoirSystem.js +0 -621
  106. package/WaterFlow/ReservoirSystem.ts +0 -754
  107. package/WaterFlow/SPHField.d.ts +0 -35
  108. package/WaterFlow/SPHField.js +0 -204
  109. package/WaterFlow/SPHField.ts +0 -228
  110. package/WaterFlow/ScreenSpaceFluidPass.d.ts +0 -69
  111. package/WaterFlow/ScreenSpaceFluidPass.js +0 -736
  112. package/WaterFlow/ScreenSpaceFluidPass.ts +0 -789
  113. package/WaterFlow/ShallowWaterSurface.d.ts +0 -45
  114. package/WaterFlow/ShallowWaterSurface.js +0 -441
  115. package/WaterFlow/ShallowWaterSurface.ts +0 -510
  116. package/WaterFlow/WaterFlow.d.ts +0 -87
  117. package/WaterFlow/WaterFlow.js +0 -171
  118. package/WaterFlow/WaterFlow.ts +0 -219
  119. package/WaterFlow/types.d.ts +0 -161
  120. package/WaterFlow/types.js +0 -1
  121. package/WaterFlow/types.ts +0 -189
  122. package/WaterFlow/waterFlowPass.d.ts +0 -3
  123. package/WaterFlow/waterFlowPass.js +0 -20
  124. package/WaterFlow/waterFlowPass.ts +0 -40
  125. package/shaders/debugExcludedShader.d.ts +0 -15
  126. package/shaders/debugExcludedShader.js +0 -48
  127. package/shaders/debugExcludedShader.ts +0 -50
@@ -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 {};
@@ -1,307 +0,0 @@
1
- import * as THREE from 'three';
2
- function addScaledSphere(group, geometry, material, position, scale, rotation = null) {
3
- const mesh = new THREE.Mesh(geometry, material);
4
- mesh.position.set(...position);
5
- mesh.scale.set(...scale);
6
- if (rotation)
7
- mesh.rotation.set(...rotation);
8
- mesh.castShadow = true;
9
- mesh.receiveShadow = true;
10
- group.add(mesh);
11
- return mesh;
12
- }
13
- /** 漂浮的橡皮鸭:跟随水面高度/坡度做浮沉与倾斜,可被鼠标拖拽。 */
14
- export class FloatingDuck {
15
- bounds;
16
- /** 静水面高度;setEnvironment 会随容器变化更新(故非 readonly)。 */
17
- waterY;
18
- start;
19
- velocity;
20
- surfaceSample;
21
- yaw;
22
- yawVelocity;
23
- pitch;
24
- roll;
25
- radiusX;
26
- radiusZ;
27
- active;
28
- dragging;
29
- dragOffset;
30
- dragVelocity;
31
- lastDragPosition;
32
- group;
33
- model;
34
- pickGeometry;
35
- pickMaterial;
36
- pickMesh;
37
- yellowMaterial;
38
- wingMaterial;
39
- beakMaterial;
40
- eyeMaterial;
41
- highlightMaterial;
42
- sphereGeometry;
43
- body;
44
- head;
45
- beak;
46
- tailGeometry;
47
- tail;
48
- constructor({ basinMinX, basinMaxX, basinHalfZ, waterY, startX = 1.2, startZ = 0.24, }) {
49
- this.bounds = { basinMinX, basinMaxX, basinHalfZ, centerZ: 0 };
50
- this.waterY = waterY;
51
- this.start = new THREE.Vector3(startX, waterY - 0.016, startZ);
52
- this.velocity = new THREE.Vector3();
53
- this.surfaceSample = {};
54
- this.yaw = Math.PI;
55
- this.yawVelocity = 0;
56
- this.pitch = 0;
57
- this.roll = 0;
58
- this.radiusX = 0.19;
59
- this.radiusZ = 0.145;
60
- this.active = true;
61
- this.dragging = false;
62
- this.dragOffset = new THREE.Vector2();
63
- this.dragVelocity = new THREE.Vector2();
64
- this.lastDragPosition = new THREE.Vector2();
65
- this.group = new THREE.Group();
66
- this.group.name = 'floating-rubber-duck';
67
- this.model = new THREE.Group();
68
- this.group.add(this.model);
69
- this.pickGeometry = new THREE.SphereGeometry(0.29, 12, 8);
70
- this.pickMaterial = new THREE.MeshBasicMaterial({
71
- transparent: true,
72
- opacity: 0,
73
- depthWrite: false,
74
- colorWrite: false,
75
- });
76
- this.pickMesh = new THREE.Mesh(this.pickGeometry, this.pickMaterial);
77
- this.pickMesh.name = 'rubber-duck-pick-volume';
78
- this.pickMesh.position.y = 0.13;
79
- this.pickMesh.layers.set(2);
80
- this.group.add(this.pickMesh);
81
- this.yellowMaterial = new THREE.MeshPhysicalMaterial({
82
- color: 0xf2b705,
83
- roughness: 0.46,
84
- metalness: 0,
85
- clearcoat: 0.32,
86
- clearcoatRoughness: 0.28,
87
- });
88
- this.wingMaterial = new THREE.MeshPhysicalMaterial({
89
- color: 0xd99b03,
90
- roughness: 0.48,
91
- metalness: 0,
92
- clearcoat: 0.24,
93
- });
94
- this.beakMaterial = new THREE.MeshPhysicalMaterial({
95
- color: 0xe85e06,
96
- roughness: 0.42,
97
- metalness: 0,
98
- clearcoat: 0.25,
99
- });
100
- this.eyeMaterial = new THREE.MeshStandardMaterial({ color: 0x101518, roughness: 0.2 });
101
- this.highlightMaterial = new THREE.MeshBasicMaterial({ color: 0xffffff });
102
- this.sphereGeometry = new THREE.SphereGeometry(1, 32, 20);
103
- this.body = addScaledSphere(this.model, this.sphereGeometry, this.yellowMaterial, [0, 0.072, 0], [0.19, 0.12, 0.132]);
104
- this.head = addScaledSphere(this.model, this.sphereGeometry, this.yellowMaterial, [0.115, 0.205, 0], [0.098, 0.102, 0.096]);
105
- this.beak = addScaledSphere(this.model, this.sphereGeometry, this.beakMaterial, [0.203, 0.191, 0], [0.071, 0.026, 0.047]);
106
- for (const side of [-1, 1]) {
107
- addScaledSphere(this.model, this.sphereGeometry, this.wingMaterial, [-0.02, 0.092, side * 0.115], [0.105, 0.048, 0.052], [side * 0.18, 0, side * 0.08]);
108
- addScaledSphere(this.model, this.sphereGeometry, this.eyeMaterial, [0.176, 0.237, side * 0.069], [0.014, 0.017, 0.011]);
109
- addScaledSphere(this.model, this.sphereGeometry, this.highlightMaterial, [0.184, 0.244, side * 0.077], [0.0045, 0.005, 0.0035]);
110
- }
111
- this.tailGeometry = new THREE.ConeGeometry(0.052, 0.105, 20);
112
- this.tail = new THREE.Mesh(this.tailGeometry, this.yellowMaterial);
113
- this.tail.position.set(-0.177, 0.132, 0);
114
- this.tail.rotation.z = -Math.PI * 0.5;
115
- this.tail.castShadow = true;
116
- this.model.add(this.tail);
117
- this.reset();
118
- }
119
- setActive(active) {
120
- this.active = active;
121
- this.group.visible = active;
122
- }
123
- setEnvironment({ minX, maxX, halfZ, centerZ = 0, waterY }, reposition = false) {
124
- this.bounds.basinMinX = minX;
125
- this.bounds.basinMaxX = maxX;
126
- this.bounds.basinHalfZ = halfZ;
127
- this.bounds.centerZ = centerZ;
128
- this.waterY = waterY;
129
- if (reposition) {
130
- const receiverWidth = maxX - minX;
131
- this.place(minX + Math.min(0.75, receiverWidth * 0.35), centerZ + Math.min(0.2, halfZ * 0.3));
132
- }
133
- else {
134
- this.clampToBounds();
135
- }
136
- }
137
- place(x, z) {
138
- this.group.position.set(x, this.waterY - 0.016, z);
139
- this.velocity.set(0, 0, 0);
140
- this.clampToBounds();
141
- }
142
- translateContainer(deltaX, deltaZ) {
143
- this.group.position.x += deltaX;
144
- this.group.position.z += deltaZ;
145
- this.clampToBounds();
146
- }
147
- beginDrag(worldX, worldZ) {
148
- this.dragging = true;
149
- this.dragOffset.set(this.group.position.x - worldX, this.group.position.z - worldZ);
150
- this.lastDragPosition.set(this.group.position.x, this.group.position.z);
151
- this.dragVelocity.set(0, 0);
152
- this.velocity.x = 0;
153
- this.velocity.z = 0;
154
- }
155
- dragTo(worldX, worldZ, deltaSeconds) {
156
- if (!this.dragging)
157
- return;
158
- const previousX = this.group.position.x;
159
- const previousZ = this.group.position.z;
160
- this.group.position.x = worldX + this.dragOffset.x;
161
- this.group.position.z = worldZ + this.dragOffset.y;
162
- this.clampToBounds();
163
- const inverseDelta = 1 / Math.max(deltaSeconds, 1 / 120);
164
- const measuredX = (this.group.position.x - previousX) * inverseDelta;
165
- const measuredZ = (this.group.position.z - previousZ) * inverseDelta;
166
- this.dragVelocity.x = THREE.MathUtils.lerp(this.dragVelocity.x, measuredX, 0.42);
167
- this.dragVelocity.y = THREE.MathUtils.lerp(this.dragVelocity.y, measuredZ, 0.42);
168
- this.velocity.x = this.dragVelocity.x;
169
- this.velocity.z = this.dragVelocity.y;
170
- this.lastDragPosition.set(this.group.position.x, this.group.position.z);
171
- }
172
- endDrag() {
173
- if (!this.dragging)
174
- return;
175
- this.dragging = false;
176
- const releaseSpeed = Math.hypot(this.dragVelocity.x, this.dragVelocity.y);
177
- const releaseScale = releaseSpeed > 1.5 ? 1.5 / releaseSpeed : 1;
178
- this.velocity.x = this.dragVelocity.x * releaseScale;
179
- this.velocity.z = this.dragVelocity.y * releaseScale;
180
- this.yawVelocity += THREE.MathUtils.clamp(this.velocity.z * 0.34, -0.7, 0.7);
181
- }
182
- clampToBounds() {
183
- const minX = this.bounds.basinMinX + this.radiusX;
184
- const maxX = this.bounds.basinMaxX - this.radiusX;
185
- const minZ = this.bounds.centerZ - this.bounds.basinHalfZ + this.radiusZ;
186
- const maxZ = this.bounds.centerZ + this.bounds.basinHalfZ - this.radiusZ;
187
- this.group.position.x = THREE.MathUtils.clamp(this.group.position.x, minX, maxX);
188
- this.group.position.z = THREE.MathUtils.clamp(this.group.position.z, minZ, maxZ);
189
- }
190
- reset() {
191
- this.group.position.copy(this.start);
192
- this.velocity.set(0, 0, 0);
193
- this.yaw = Math.PI;
194
- this.yawVelocity = 0;
195
- this.pitch = 0;
196
- this.roll = 0;
197
- this.dragging = false;
198
- this.dragVelocity.set(0, 0);
199
- this.group.rotation.set(0, this.yaw, 0);
200
- this.model.rotation.set(0, 0, 0);
201
- }
202
- update(delta, elapsed, { surface = null, impactX = 0, impactZ = 0, impactEnergy = 0, emitting = false, } = {}) {
203
- if (!this.active)
204
- return;
205
- const dt = Math.min(delta, 1 / 30);
206
- const position = this.group.position;
207
- const sample = surface?.sampleSurface(position.x, position.z, this.surfaceSample) || this.surfaceSample;
208
- if (!surface) {
209
- sample.height = 0;
210
- sample.velocityY = 0;
211
- sample.slopeX = 0;
212
- sample.slopeZ = 0;
213
- sample.flowX = 0;
214
- sample.flowZ = 0;
215
- const dx = position.x - impactX;
216
- const dz = position.z - impactZ;
217
- const distanceSq = dx * dx + dz * dz;
218
- const strength = emitting ? Math.min(impactEnergy * 0.065, 0.9) * Math.exp(-distanceSq / 0.48) : 0;
219
- const inverseDistance = 1 / Math.max(Math.sqrt(distanceSq), 0.06);
220
- sample.flowX = strength * (0.42 + dx * inverseDistance * 0.68);
221
- sample.flowZ = strength * dz * inverseDistance * 0.92;
222
- sample.impact = strength * Math.exp(-distanceSq / 0.095);
223
- }
224
- const equilibriumY = this.waterY + sample.height - 0.016;
225
- const buoyancyAcceleration = (equilibriumY - position.y) * 34;
226
- const verticalDamping = (sample.velocityY - this.velocity.y) * 5.8;
227
- this.velocity.y += (buoyancyAcceleration + verticalDamping - sample.impact * 4.4) * dt;
228
- if (!this.dragging) {
229
- const flowResponse = 2.65;
230
- this.velocity.x += ((sample.flowX - this.velocity.x) * flowResponse - sample.slopeX * 1.75) * dt;
231
- this.velocity.z += ((sample.flowZ - this.velocity.z) * flowResponse - sample.slopeZ * 1.75) * dt;
232
- const horizontalDrag = Math.exp(-0.72 * dt);
233
- this.velocity.x *= horizontalDrag;
234
- this.velocity.z *= horizontalDrag;
235
- const horizontalSpeed = Math.hypot(this.velocity.x, this.velocity.z);
236
- if (horizontalSpeed > 1.35) {
237
- const scale = 1.35 / horizontalSpeed;
238
- this.velocity.x *= scale;
239
- this.velocity.z *= scale;
240
- }
241
- position.x += this.velocity.x * dt;
242
- position.z += this.velocity.z * dt;
243
- }
244
- position.y += this.velocity.y * dt;
245
- const minX = this.bounds.basinMinX + this.radiusX;
246
- const maxX = this.bounds.basinMaxX - this.radiusX;
247
- const minZ = this.bounds.centerZ - this.bounds.basinHalfZ + this.radiusZ;
248
- const maxZ = this.bounds.centerZ + this.bounds.basinHalfZ - this.radiusZ;
249
- let collisionTorque = 0;
250
- if (position.x < minX) {
251
- position.x = minX;
252
- this.velocity.x = Math.abs(this.velocity.x) * 0.42;
253
- collisionTorque += 1.8;
254
- }
255
- else if (position.x > maxX) {
256
- position.x = maxX;
257
- this.velocity.x = -Math.abs(this.velocity.x) * 0.42;
258
- collisionTorque -= 1.8;
259
- }
260
- if (position.z < minZ) {
261
- position.z = minZ;
262
- this.velocity.z = Math.abs(this.velocity.z) * 0.42;
263
- collisionTorque -= 1.35;
264
- }
265
- else if (position.z > maxZ) {
266
- position.z = maxZ;
267
- this.velocity.z = -Math.abs(this.velocity.z) * 0.42;
268
- collisionTorque += 1.35;
269
- }
270
- const speedSq = this.velocity.x * this.velocity.x + this.velocity.z * this.velocity.z;
271
- if (speedSq > 0.0012) {
272
- const desiredYaw = Math.atan2(-this.velocity.z, this.velocity.x);
273
- const yawDifference = Math.atan2(Math.sin(desiredYaw - this.yaw), Math.cos(desiredYaw - this.yaw));
274
- this.yawVelocity += yawDifference * 2.7 * dt;
275
- }
276
- const impactSide = THREE.MathUtils.clamp((position.z - impactZ) * 2.2, -1, 1);
277
- this.yawVelocity += (collisionTorque + sample.impact * impactSide * 2.2) * dt;
278
- this.yawVelocity *= Math.exp(-2.25 * dt);
279
- this.yaw += this.yawVelocity * dt;
280
- const forwardX = Math.cos(this.yaw);
281
- const forwardZ = -Math.sin(this.yaw);
282
- const rightX = Math.sin(this.yaw);
283
- const rightZ = Math.cos(this.yaw);
284
- const forwardSlope = sample.slopeX * forwardX + sample.slopeZ * forwardZ;
285
- const rightSlope = sample.slopeX * rightX + sample.slopeZ * rightZ;
286
- const desiredPitch = THREE.MathUtils.clamp(Math.atan(forwardSlope) - sample.impact * 0.12, -0.25, 0.25);
287
- const desiredRoll = THREE.MathUtils.clamp(-Math.atan(rightSlope) - this.yawVelocity * 0.055, -0.24, 0.24);
288
- const tiltBlend = 1 - Math.exp(-5.2 * dt);
289
- this.pitch = THREE.MathUtils.lerp(this.pitch, desiredPitch, tiltBlend);
290
- this.roll = THREE.MathUtils.lerp(this.roll, desiredRoll, tiltBlend);
291
- this.group.rotation.y = this.yaw;
292
- this.model.rotation.x = this.roll;
293
- this.model.rotation.z = this.pitch;
294
- this.model.position.y = Math.sin(elapsed * 3.1 + position.x * 1.7) * 0.0025;
295
- }
296
- dispose() {
297
- this.pickGeometry.dispose();
298
- this.pickMaterial.dispose();
299
- this.sphereGeometry.dispose();
300
- this.tailGeometry.dispose();
301
- this.yellowMaterial.dispose();
302
- this.wingMaterial.dispose();
303
- this.beakMaterial.dispose();
304
- this.eyeMaterial.dispose();
305
- this.highlightMaterial.dispose();
306
- }
307
- }