@promptbook/cli 0.112.0-103 → 0.112.0-104
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/apps/agents-server/src/app/AddAgentButton.tsx +0 -5
- package/apps/agents-server/src/app/actions.ts +50 -0
- package/apps/agents-server/src/app/agents/[agentName]/AgentProfileChat.tsx +3 -4
- package/apps/agents-server/src/app/api/health/route.ts +18 -0
- package/apps/agents-server/src/components/AgentProfile/AgentProfile.tsx +1 -4
- package/apps/agents-server/src/components/Header/Header.tsx +0 -11
- package/apps/agents-server/src/components/Header/useHeaderAgentMenus.tsx +0 -5
- package/apps/agents-server/src/components/NewAgentDialog/useNewAgentDialog.tsx +39 -16
- package/apps/agents-server/src/constants/defaultAgentAvatarVisual.ts +1 -1
- package/apps/agents-server/src/database/migrations/2026-06-0200-default-agent-avatar-visual-octopus3d3.sql +16 -0
- package/apps/agents-server/src/middleware.ts +2 -1
- package/apps/agents-server/src/tools/$provideCdnForServer.ts +43 -2
- package/apps/agents-server/src/utils/agentRouting/resolveAgentRouteTarget.ts +27 -4
- package/apps/agents-server/src/utils/defaultAgents/defaultAgents.ts +168 -0
- package/apps/agents-server/src/utils/defaultAgents/installDefaultAgents.ts +139 -0
- package/esm/index.es.js +518 -7
- package/esm/index.es.js.map +1 -1
- package/esm/src/avatars/types/AvatarVisualDefinition.d.ts +1 -1
- package/esm/src/avatars/visuals/octopus3d3AvatarVisual.d.ts +7 -0
- package/package.json +1 -1
- package/src/avatars/types/AvatarVisualDefinition.ts +1 -0
- package/src/avatars/visuals/avatarVisualRegistry.ts +2 -0
- package/src/avatars/visuals/octopus3d3AvatarVisual.ts +903 -0
- package/src/other/templates/getTemplatesPipelineCollection.ts +784 -716
- package/src/utils/agents/resolveAgentAvatarImageUrl.ts +1 -1
- package/src/version.ts +1 -1
- package/src/versions.txt +1 -1
- package/umd/index.umd.js +518 -7
- package/umd/index.umd.js.map +1 -1
- package/umd/src/avatars/types/AvatarVisualDefinition.d.ts +1 -1
- package/umd/src/avatars/visuals/octopus3d3AvatarVisual.d.ts +7 -0
|
@@ -0,0 +1,903 @@
|
|
|
1
|
+
/* eslint-disable no-magic-numbers */
|
|
2
|
+
|
|
3
|
+
import { drawAvatarFrame } from '../avatarRenderingUtils';
|
|
4
|
+
import type { AvatarPalette, AvatarVisualDefinition } from '../types/AvatarVisualDefinition';
|
|
5
|
+
import {
|
|
6
|
+
clampNumber,
|
|
7
|
+
crossProduct3D,
|
|
8
|
+
dotProduct3D,
|
|
9
|
+
getProjectedQuadPerimeter,
|
|
10
|
+
normalizeVector3,
|
|
11
|
+
projectScenePoint,
|
|
12
|
+
subtractPoint3D,
|
|
13
|
+
transformScenePoint,
|
|
14
|
+
type Point3D,
|
|
15
|
+
type ProjectedPoint,
|
|
16
|
+
} from './avatar3dProjectionShared';
|
|
17
|
+
import { drawProjectedOrganicEye, drawProjectedOrganicMouth, drawProjectedQuad } from './octopus3dAvatarVisualShared';
|
|
18
|
+
import { createOctopus3MorphologyProfile, type Octopus3MorphologyProfile } from './octopus3AvatarVisual';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* One visible projected patch on the continuous Octopus 3D 3 mesh.
|
|
22
|
+
*
|
|
23
|
+
* @private helper of `octopus3d3AvatarVisual`
|
|
24
|
+
*/
|
|
25
|
+
type ContinuousOctopusSurfacePatch = {
|
|
26
|
+
readonly corners: [ProjectedPoint, ProjectedPoint, ProjectedPoint, ProjectedPoint];
|
|
27
|
+
readonly averageDepth: number;
|
|
28
|
+
readonly lightIntensity: number;
|
|
29
|
+
readonly fillStyle: string;
|
|
30
|
+
readonly outlineColor: string;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Seeded profile for one continuous lower mesh lobe that reads as a tentacle.
|
|
35
|
+
*
|
|
36
|
+
* @private helper of `octopus3d3AvatarVisual`
|
|
37
|
+
*/
|
|
38
|
+
type ContinuousOctopusTentacleProfile = {
|
|
39
|
+
readonly centerLongitude: number;
|
|
40
|
+
readonly widthScale: number;
|
|
41
|
+
readonly lengthScale: number;
|
|
42
|
+
readonly swayScale: number;
|
|
43
|
+
readonly depthScale: number;
|
|
44
|
+
readonly phase: number;
|
|
45
|
+
readonly suckerSide: -1 | 1;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Stable surface options used by the continuous Octopus 3D 3 mesh sampler.
|
|
50
|
+
*
|
|
51
|
+
* @private helper of `octopus3d3AvatarVisual`
|
|
52
|
+
*/
|
|
53
|
+
type ContinuousOctopusSurfaceOptions = {
|
|
54
|
+
readonly radiusX: number;
|
|
55
|
+
readonly radiusY: number;
|
|
56
|
+
readonly radiusZ: number;
|
|
57
|
+
readonly morphologyProfile: Octopus3MorphologyProfile;
|
|
58
|
+
readonly timeMs: number;
|
|
59
|
+
readonly animationPhase: number;
|
|
60
|
+
readonly tentacleProfiles: ReadonlyArray<ContinuousOctopusTentacleProfile>;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Smoothly blended influence of nearby tentacle lobes at one longitude.
|
|
65
|
+
*
|
|
66
|
+
* @private helper of `octopus3d3AvatarVisual`
|
|
67
|
+
*/
|
|
68
|
+
type ContinuousOctopusTentacleInfluence = {
|
|
69
|
+
readonly core: number;
|
|
70
|
+
readonly centerLongitude: number;
|
|
71
|
+
readonly widthScale: number;
|
|
72
|
+
readonly lengthScale: number;
|
|
73
|
+
readonly swayScale: number;
|
|
74
|
+
readonly depthScale: number;
|
|
75
|
+
readonly phase: number;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Light direction used by the continuous octopus mesh shading.
|
|
80
|
+
*
|
|
81
|
+
* @private helper of `octopus3d3AvatarVisual`
|
|
82
|
+
*/
|
|
83
|
+
const LIGHT_DIRECTION: Point3D = normalizeVector3({
|
|
84
|
+
x: 0.34,
|
|
85
|
+
y: -0.62,
|
|
86
|
+
z: 1,
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Real-octopus tentacle count used by the continuous lower mesh.
|
|
91
|
+
*
|
|
92
|
+
* @private helper of `octopus3d3AvatarVisual`
|
|
93
|
+
*/
|
|
94
|
+
const OCTOPUS_TENTACLE_COUNT = 8;
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Octopus 3D 3 avatar visual.
|
|
98
|
+
*
|
|
99
|
+
* @private built-in avatar visual
|
|
100
|
+
*/
|
|
101
|
+
export const octopus3d3AvatarVisual: AvatarVisualDefinition = {
|
|
102
|
+
id: 'octopus3d3',
|
|
103
|
+
title: 'Octopus 3D 3',
|
|
104
|
+
description:
|
|
105
|
+
'Cute continuous 3D octopus with a blobby single mesh, waving tentacle lobes, rich shading, and cursor-aware eyes.',
|
|
106
|
+
isAnimated: true,
|
|
107
|
+
supportsPointerTracking: true,
|
|
108
|
+
render({ context, size, palette, createRandom, timeMs, interaction }) {
|
|
109
|
+
const morphologyProfile = createOctopus3MorphologyProfile(createRandom);
|
|
110
|
+
const animationRandom = createRandom('octopus3d3-animation-profile');
|
|
111
|
+
const eyeRandom = createRandom('octopus3d3-eye-profile');
|
|
112
|
+
const animationPhase = animationRandom() * Math.PI * 2;
|
|
113
|
+
const tentacleProfiles = createContinuousTentacleProfiles(createRandom, morphologyProfile);
|
|
114
|
+
const sceneCenterX = size * 0.5;
|
|
115
|
+
const sceneCenterY = size * 0.535;
|
|
116
|
+
const bob = Math.sin(timeMs / 960 + animationPhase) * size * 0.012;
|
|
117
|
+
const meshCenter: Point3D = {
|
|
118
|
+
x: interaction.bodyOffsetX * size * 0.048 + size * morphologyProfile.body.centerXJitterRatio * 0.44,
|
|
119
|
+
y: -size * 0.07 + interaction.bodyOffsetY * size * 0.026 + bob,
|
|
120
|
+
z: interaction.intensity * size * 0.018,
|
|
121
|
+
};
|
|
122
|
+
const rotationY =
|
|
123
|
+
-0.1 +
|
|
124
|
+
Math.sin(timeMs / 2700 + animationPhase) * 0.035 +
|
|
125
|
+
interaction.bodyOffsetX * 0.22 +
|
|
126
|
+
interaction.gazeX * 0.88;
|
|
127
|
+
const rotationX =
|
|
128
|
+
-0.07 +
|
|
129
|
+
Math.cos(timeMs / 3100 + animationPhase * 0.7) * 0.018 -
|
|
130
|
+
interaction.bodyOffsetY * 0.08 -
|
|
131
|
+
interaction.gazeY * 0.38;
|
|
132
|
+
const surfaceOptions: ContinuousOctopusSurfaceOptions = {
|
|
133
|
+
radiusX: size * morphologyProfile.body.bodyRadiusRatio * morphologyProfile.body.horizontalStretch * 1.1,
|
|
134
|
+
radiusY: size * morphologyProfile.body.bodyRadiusRatio * morphologyProfile.body.verticalStretch * 1.08,
|
|
135
|
+
radiusZ:
|
|
136
|
+
size *
|
|
137
|
+
morphologyProfile.body.bodyRadiusRatio *
|
|
138
|
+
(1.02 + (morphologyProfile.body.horizontalStretch - 1) * 0.18),
|
|
139
|
+
morphologyProfile,
|
|
140
|
+
timeMs,
|
|
141
|
+
animationPhase,
|
|
142
|
+
tentacleProfiles,
|
|
143
|
+
};
|
|
144
|
+
const surfacePatches = resolveVisibleContinuousOctopusPatches({
|
|
145
|
+
...surfaceOptions,
|
|
146
|
+
center: meshCenter,
|
|
147
|
+
rotationX,
|
|
148
|
+
rotationY,
|
|
149
|
+
sceneCenterX,
|
|
150
|
+
sceneCenterY,
|
|
151
|
+
size,
|
|
152
|
+
palette,
|
|
153
|
+
});
|
|
154
|
+
const eyeLatitude = clampNumber(morphologyProfile.face.eyeCenterYOffsetRatio * 4.2 - 0.03, -0.22, 0.08);
|
|
155
|
+
const eyeLongitude = clampNumber(morphologyProfile.face.eyeSpacingRatio * 3.1, 0.18, 0.32);
|
|
156
|
+
const mouthLatitude = clampNumber(
|
|
157
|
+
eyeLatitude + 0.2 + morphologyProfile.face.mouthYOffsetRatio,
|
|
158
|
+
0.08,
|
|
159
|
+
0.34,
|
|
160
|
+
);
|
|
161
|
+
const mouthCenterLongitude = clampNumber(morphologyProfile.face.mouthCenterOffsetRatio * 5.6, -0.08, 0.08);
|
|
162
|
+
const mouthHalfLongitude = clampNumber(eyeLongitude * 0.78, 0.15, 0.28);
|
|
163
|
+
const mouthCurveLatitude = clampNumber(
|
|
164
|
+
mouthLatitude + morphologyProfile.face.mouthCurveDepthRatio * 0.78,
|
|
165
|
+
mouthLatitude + 0.03,
|
|
166
|
+
0.42,
|
|
167
|
+
);
|
|
168
|
+
const eyeRadiusX = size * morphologyProfile.face.eyeRadiusXRatio * 0.76;
|
|
169
|
+
const eyeRadiusY = eyeRadiusX * morphologyProfile.face.eyeHeightRatio * 0.9;
|
|
170
|
+
|
|
171
|
+
drawAvatarFrame(context, size, palette);
|
|
172
|
+
drawContinuousOctopusAtmosphere(context, size, palette, sceneCenterX, sceneCenterY, interaction, timeMs);
|
|
173
|
+
drawContinuousOctopusShadow(context, size, palette, interaction, timeMs, morphologyProfile);
|
|
174
|
+
|
|
175
|
+
for (const surfacePatch of surfacePatches.sort(
|
|
176
|
+
(firstSurfacePatch, secondSurfacePatch) => firstSurfacePatch.averageDepth - secondSurfacePatch.averageDepth,
|
|
177
|
+
)) {
|
|
178
|
+
drawContinuousSurfacePatch(context, surfacePatch);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
drawProjectedSurfaceCurrents({
|
|
182
|
+
context,
|
|
183
|
+
surfaceOptions,
|
|
184
|
+
center: meshCenter,
|
|
185
|
+
rotationX,
|
|
186
|
+
rotationY,
|
|
187
|
+
sceneCenterX,
|
|
188
|
+
sceneCenterY,
|
|
189
|
+
size,
|
|
190
|
+
palette,
|
|
191
|
+
morphologyProfile,
|
|
192
|
+
timeMs,
|
|
193
|
+
animationPhase,
|
|
194
|
+
});
|
|
195
|
+
drawProjectedTentacleSuckers({
|
|
196
|
+
context,
|
|
197
|
+
surfaceOptions,
|
|
198
|
+
center: meshCenter,
|
|
199
|
+
rotationX,
|
|
200
|
+
rotationY,
|
|
201
|
+
sceneCenterX,
|
|
202
|
+
sceneCenterY,
|
|
203
|
+
size,
|
|
204
|
+
palette,
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
drawProjectedOrganicEye(
|
|
208
|
+
context,
|
|
209
|
+
sampleContinuousOctopusSurfacePoint(surfaceOptions, eyeLatitude, -eyeLongitude),
|
|
210
|
+
eyeRadiusX,
|
|
211
|
+
eyeRadiusY,
|
|
212
|
+
meshCenter,
|
|
213
|
+
rotationX,
|
|
214
|
+
rotationY,
|
|
215
|
+
sceneCenterX,
|
|
216
|
+
sceneCenterY,
|
|
217
|
+
size,
|
|
218
|
+
palette,
|
|
219
|
+
timeMs,
|
|
220
|
+
animationPhase + eyeRandom() * 0.7,
|
|
221
|
+
interaction,
|
|
222
|
+
morphologyProfile.face.eyeStyle,
|
|
223
|
+
);
|
|
224
|
+
drawProjectedOrganicEye(
|
|
225
|
+
context,
|
|
226
|
+
sampleContinuousOctopusSurfacePoint(surfaceOptions, eyeLatitude, eyeLongitude),
|
|
227
|
+
eyeRadiusX,
|
|
228
|
+
eyeRadiusY,
|
|
229
|
+
meshCenter,
|
|
230
|
+
rotationX,
|
|
231
|
+
rotationY,
|
|
232
|
+
sceneCenterX,
|
|
233
|
+
sceneCenterY,
|
|
234
|
+
size,
|
|
235
|
+
palette,
|
|
236
|
+
timeMs,
|
|
237
|
+
animationPhase + 0.85 + eyeRandom() * 0.7,
|
|
238
|
+
interaction,
|
|
239
|
+
morphologyProfile.face.eyeStyle,
|
|
240
|
+
);
|
|
241
|
+
|
|
242
|
+
drawProjectedOrganicMouth(
|
|
243
|
+
context,
|
|
244
|
+
[
|
|
245
|
+
sampleContinuousOctopusSurfacePoint(
|
|
246
|
+
surfaceOptions,
|
|
247
|
+
mouthLatitude,
|
|
248
|
+
mouthCenterLongitude - mouthHalfLongitude,
|
|
249
|
+
),
|
|
250
|
+
sampleContinuousOctopusSurfacePoint(surfaceOptions, mouthCurveLatitude, mouthCenterLongitude),
|
|
251
|
+
sampleContinuousOctopusSurfacePoint(
|
|
252
|
+
surfaceOptions,
|
|
253
|
+
mouthLatitude,
|
|
254
|
+
mouthCenterLongitude + mouthHalfLongitude,
|
|
255
|
+
),
|
|
256
|
+
],
|
|
257
|
+
meshCenter,
|
|
258
|
+
rotationX,
|
|
259
|
+
rotationY,
|
|
260
|
+
sceneCenterX,
|
|
261
|
+
sceneCenterY,
|
|
262
|
+
palette,
|
|
263
|
+
size,
|
|
264
|
+
);
|
|
265
|
+
},
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Creates seeded tentacle-lobe profiles around the visible lower octopus body.
|
|
270
|
+
*
|
|
271
|
+
* @private helper of `octopus3d3AvatarVisual`
|
|
272
|
+
*/
|
|
273
|
+
function createContinuousTentacleProfiles(
|
|
274
|
+
createRandom: (salt: string) => () => number,
|
|
275
|
+
morphologyProfile: Octopus3MorphologyProfile,
|
|
276
|
+
): ReadonlyArray<ContinuousOctopusTentacleProfile> {
|
|
277
|
+
return Array.from({ length: OCTOPUS_TENTACLE_COUNT }, (_, tentacleIndex) => {
|
|
278
|
+
const tentacleRandom = createRandom(`octopus3d3-tentacle-${tentacleIndex}`);
|
|
279
|
+
const progress = tentacleIndex / (OCTOPUS_TENTACLE_COUNT - 1);
|
|
280
|
+
|
|
281
|
+
return {
|
|
282
|
+
centerLongitude:
|
|
283
|
+
-Math.PI * 0.86 +
|
|
284
|
+
progress * Math.PI * 1.72 +
|
|
285
|
+
(tentacleRandom() - 0.5) * (0.08 + morphologyProfile.tentacles.rootSpreadScale * 0.03),
|
|
286
|
+
widthScale: 0.86 + tentacleRandom() * 0.34 + (morphologyProfile.tentacles.baseWidthScale - 1) * 0.16,
|
|
287
|
+
lengthScale: 0.86 + tentacleRandom() * 0.36 + (morphologyProfile.tentacles.flowLengthScale - 1) * 0.22,
|
|
288
|
+
swayScale: 0.82 + tentacleRandom() * 0.38 + (morphologyProfile.tentacles.swayScale - 1) * 0.2,
|
|
289
|
+
depthScale: 0.86 + tentacleRandom() * 0.32 + (morphologyProfile.tentacles.tipReachScale - 1) * 0.2,
|
|
290
|
+
phase: tentacleRandom() * Math.PI * 2,
|
|
291
|
+
suckerSide: tentacleRandom() > 0.5 ? 1 : -1,
|
|
292
|
+
};
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* Draws the soft underwater atmosphere behind the continuous octopus mesh.
|
|
298
|
+
*
|
|
299
|
+
* @private helper of `octopus3d3AvatarVisual`
|
|
300
|
+
*/
|
|
301
|
+
function drawContinuousOctopusAtmosphere(
|
|
302
|
+
context: CanvasRenderingContext2D,
|
|
303
|
+
size: number,
|
|
304
|
+
palette: AvatarPalette,
|
|
305
|
+
sceneCenterX: number,
|
|
306
|
+
sceneCenterY: number,
|
|
307
|
+
interaction: {
|
|
308
|
+
readonly gazeX: number;
|
|
309
|
+
readonly gazeY: number;
|
|
310
|
+
readonly intensity: number;
|
|
311
|
+
},
|
|
312
|
+
timeMs: number,
|
|
313
|
+
): void {
|
|
314
|
+
const glowGradient = context.createRadialGradient(
|
|
315
|
+
sceneCenterX + interaction.gazeX * size * 0.11,
|
|
316
|
+
sceneCenterY - size * 0.17 + interaction.gazeY * size * 0.05,
|
|
317
|
+
size * 0.04,
|
|
318
|
+
sceneCenterX,
|
|
319
|
+
sceneCenterY,
|
|
320
|
+
size * (0.66 + interaction.intensity * 0.02),
|
|
321
|
+
);
|
|
322
|
+
glowGradient.addColorStop(0, `${palette.highlight}66`);
|
|
323
|
+
glowGradient.addColorStop(0.34, `${palette.accent}2e`);
|
|
324
|
+
glowGradient.addColorStop(1, `${palette.highlight}00`);
|
|
325
|
+
context.fillStyle = glowGradient;
|
|
326
|
+
context.fillRect(0, 0, size, size);
|
|
327
|
+
|
|
328
|
+
const lowerGradient = context.createRadialGradient(
|
|
329
|
+
sceneCenterX + Math.sin(timeMs / 1550) * size * 0.05,
|
|
330
|
+
sceneCenterY + size * 0.29,
|
|
331
|
+
size * 0.06,
|
|
332
|
+
sceneCenterX,
|
|
333
|
+
sceneCenterY + size * 0.3,
|
|
334
|
+
size * 0.54,
|
|
335
|
+
);
|
|
336
|
+
lowerGradient.addColorStop(0, `${palette.secondary}25`);
|
|
337
|
+
lowerGradient.addColorStop(1, `${palette.secondary}00`);
|
|
338
|
+
context.fillStyle = lowerGradient;
|
|
339
|
+
context.fillRect(0, 0, size, size);
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* Draws the soft lower shadow that anchors the octopus in the avatar frame.
|
|
344
|
+
*
|
|
345
|
+
* @private helper of `octopus3d3AvatarVisual`
|
|
346
|
+
*/
|
|
347
|
+
function drawContinuousOctopusShadow(
|
|
348
|
+
context: CanvasRenderingContext2D,
|
|
349
|
+
size: number,
|
|
350
|
+
palette: AvatarPalette,
|
|
351
|
+
interaction: {
|
|
352
|
+
readonly gazeX: number;
|
|
353
|
+
readonly intensity: number;
|
|
354
|
+
},
|
|
355
|
+
timeMs: number,
|
|
356
|
+
morphologyProfile: Octopus3MorphologyProfile,
|
|
357
|
+
): void {
|
|
358
|
+
context.save();
|
|
359
|
+
context.fillStyle = `${palette.shadow}66`;
|
|
360
|
+
context.filter = `blur(${size * 0.025}px)`;
|
|
361
|
+
context.beginPath();
|
|
362
|
+
context.ellipse(
|
|
363
|
+
size * 0.5 + interaction.gazeX * size * 0.045,
|
|
364
|
+
size * 0.9 + Math.sin(timeMs / 980) * size * 0.007,
|
|
365
|
+
size * (0.19 + morphologyProfile.tentacles.rootSpreadScale * 0.022 + interaction.intensity * 0.02),
|
|
366
|
+
size * 0.06,
|
|
367
|
+
0,
|
|
368
|
+
0,
|
|
369
|
+
Math.PI * 2,
|
|
370
|
+
);
|
|
371
|
+
context.fill();
|
|
372
|
+
context.restore();
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
/**
|
|
376
|
+
* Resolves visible projected patches for the continuous octopus mesh.
|
|
377
|
+
*
|
|
378
|
+
* @private helper of `octopus3d3AvatarVisual`
|
|
379
|
+
*/
|
|
380
|
+
function resolveVisibleContinuousOctopusPatches(options: ContinuousOctopusSurfaceOptions & {
|
|
381
|
+
readonly center: Point3D;
|
|
382
|
+
readonly rotationX: number;
|
|
383
|
+
readonly rotationY: number;
|
|
384
|
+
readonly sceneCenterX: number;
|
|
385
|
+
readonly sceneCenterY: number;
|
|
386
|
+
readonly size: number;
|
|
387
|
+
readonly palette: AvatarPalette;
|
|
388
|
+
}): Array<ContinuousOctopusSurfacePatch> {
|
|
389
|
+
const { center, rotationX, rotationY, sceneCenterX, sceneCenterY, size, palette } = options;
|
|
390
|
+
const latitudePatchCount = 16;
|
|
391
|
+
const longitudePatchCount = 40;
|
|
392
|
+
const surfacePatches: Array<ContinuousOctopusSurfacePatch> = [];
|
|
393
|
+
|
|
394
|
+
for (let latitudeIndex = 0; latitudeIndex < latitudePatchCount; latitudeIndex++) {
|
|
395
|
+
const startLatitude = -Math.PI / 2 + (latitudeIndex / latitudePatchCount) * Math.PI;
|
|
396
|
+
const endLatitude = -Math.PI / 2 + ((latitudeIndex + 1) / latitudePatchCount) * Math.PI;
|
|
397
|
+
const centerLatitude = (startLatitude + endLatitude) / 2;
|
|
398
|
+
const verticalProgress = (Math.sin(centerLatitude) + 1) / 2;
|
|
399
|
+
|
|
400
|
+
for (let longitudeIndex = 0; longitudeIndex < longitudePatchCount; longitudeIndex++) {
|
|
401
|
+
const startLongitude = -Math.PI + (longitudeIndex / longitudePatchCount) * Math.PI * 2;
|
|
402
|
+
const endLongitude = -Math.PI + ((longitudeIndex + 1) / longitudePatchCount) * Math.PI * 2;
|
|
403
|
+
const centerLongitude = (startLongitude + endLongitude) / 2;
|
|
404
|
+
const localCorners = [
|
|
405
|
+
sampleContinuousOctopusSurfacePoint(options, startLatitude, startLongitude),
|
|
406
|
+
sampleContinuousOctopusSurfacePoint(options, startLatitude, endLongitude),
|
|
407
|
+
sampleContinuousOctopusSurfacePoint(options, endLatitude, endLongitude),
|
|
408
|
+
sampleContinuousOctopusSurfacePoint(options, endLatitude, startLongitude),
|
|
409
|
+
] as const;
|
|
410
|
+
const transformedCorners = localCorners.map((localCorner) =>
|
|
411
|
+
transformScenePoint(localCorner, center, rotationX, rotationY),
|
|
412
|
+
) as [Point3D, Point3D, Point3D, Point3D];
|
|
413
|
+
const surfaceNormal = normalizeVector3(
|
|
414
|
+
crossProduct3D(
|
|
415
|
+
subtractPoint3D(transformedCorners[1], transformedCorners[0]),
|
|
416
|
+
subtractPoint3D(transformedCorners[2], transformedCorners[0]),
|
|
417
|
+
),
|
|
418
|
+
);
|
|
419
|
+
|
|
420
|
+
if (surfaceNormal.z <= 0.008) {
|
|
421
|
+
continue;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
const projectedCorners = transformedCorners.map((transformedCorner) =>
|
|
425
|
+
projectScenePoint(transformedCorner, size, sceneCenterX, sceneCenterY),
|
|
426
|
+
) as [ProjectedPoint, ProjectedPoint, ProjectedPoint, ProjectedPoint];
|
|
427
|
+
const tentacleInfluence = resolveContinuousTentacleInfluence(options, centerLongitude);
|
|
428
|
+
const lowerLobeWave = resolveContinuousLobeWave(options, centerLongitude);
|
|
429
|
+
|
|
430
|
+
surfacePatches.push({
|
|
431
|
+
corners: projectedCorners,
|
|
432
|
+
averageDepth:
|
|
433
|
+
transformedCorners.reduce((depthSum, transformedCorner) => depthSum + transformedCorner.z, 0) /
|
|
434
|
+
transformedCorners.length,
|
|
435
|
+
lightIntensity: clampNumber(dotProduct3D(surfaceNormal, LIGHT_DIRECTION), -1, 1),
|
|
436
|
+
fillStyle: resolveContinuousSurfacePatchFillStyle(
|
|
437
|
+
palette,
|
|
438
|
+
verticalProgress,
|
|
439
|
+
Math.max(0, Math.cos(centerLongitude)),
|
|
440
|
+
tentacleInfluence.core,
|
|
441
|
+
lowerLobeWave,
|
|
442
|
+
),
|
|
443
|
+
outlineColor: verticalProgress < 0.54 ? `${palette.highlight}69` : `${palette.shadow}78`,
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
return surfacePatches;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
/**
|
|
452
|
+
* Samples one point on the continuous Octopus 3D 3 surface.
|
|
453
|
+
*
|
|
454
|
+
* The lower hemisphere is pulled into eight seeded waving lobes, so the portrait reads as
|
|
455
|
+
* tentacled while still being rendered as one connected blobby mesh.
|
|
456
|
+
*
|
|
457
|
+
* @private helper of `octopus3d3AvatarVisual`
|
|
458
|
+
*/
|
|
459
|
+
function sampleContinuousOctopusSurfacePoint(
|
|
460
|
+
options: ContinuousOctopusSurfaceOptions,
|
|
461
|
+
latitude: number,
|
|
462
|
+
longitude: number,
|
|
463
|
+
): Point3D {
|
|
464
|
+
const { radiusX, radiusY, radiusZ, morphologyProfile, timeMs, animationPhase } = options;
|
|
465
|
+
const cosineLatitude = Math.max(0, Math.cos(latitude));
|
|
466
|
+
const verticalProgress = (Math.sin(latitude) + 1) / 2;
|
|
467
|
+
const upperBlend = Math.pow(1 - verticalProgress, 1.28);
|
|
468
|
+
const lowerBlend = smoothStep(0.38, 1, verticalProgress);
|
|
469
|
+
const tipBlend = smoothStep(0.68, 1, verticalProgress);
|
|
470
|
+
const tentacleInfluence = resolveContinuousTentacleInfluence(options, longitude);
|
|
471
|
+
const centerPull = resolveSignedAngularDistance(longitude, tentacleInfluence.centerLongitude);
|
|
472
|
+
const effectiveLongitude =
|
|
473
|
+
longitude + centerPull * lowerBlend * tentacleInfluence.core * (0.24 + tipBlend * 0.2);
|
|
474
|
+
const lowerLobeWave = resolveContinuousLobeWave(options, longitude);
|
|
475
|
+
const mantleRipple =
|
|
476
|
+
Math.sin(
|
|
477
|
+
longitude * morphologyProfile.body.lobeCount +
|
|
478
|
+
animationPhase * 0.6 +
|
|
479
|
+
timeMs / (1750 + morphologyProfile.body.lobeCount * 30),
|
|
480
|
+
) *
|
|
481
|
+
(0.018 + morphologyProfile.body.wobbleAmplitudeRatio * 0.8) *
|
|
482
|
+
(0.3 + lowerBlend * 0.7);
|
|
483
|
+
const tentacleWave =
|
|
484
|
+
Math.sin(timeMs / 760 + tentacleInfluence.phase + verticalProgress * 2.4) *
|
|
485
|
+
lowerBlend *
|
|
486
|
+
tentacleInfluence.core *
|
|
487
|
+
tentacleInfluence.swayScale;
|
|
488
|
+
const horizontalScale =
|
|
489
|
+
1.04 +
|
|
490
|
+
mantleRipple +
|
|
491
|
+
lowerBlend * (0.16 + (morphologyProfile.tentacles.rootSpreadScale - 1) * 0.1) +
|
|
492
|
+
lowerBlend * tentacleInfluence.core * (0.2 + lowerLobeWave * 0.12) -
|
|
493
|
+
upperBlend * 0.08;
|
|
494
|
+
const depthScale =
|
|
495
|
+
1.06 +
|
|
496
|
+
upperBlend * 0.16 +
|
|
497
|
+
Math.max(0, Math.cos(effectiveLongitude)) * 0.1 +
|
|
498
|
+
lowerBlend * tentacleInfluence.core * (0.1 + tentacleInfluence.depthScale * 0.06) -
|
|
499
|
+
Math.max(0, -Math.cos(effectiveLongitude)) * 0.05;
|
|
500
|
+
const tentacleTubeRadius =
|
|
501
|
+
lowerBlend *
|
|
502
|
+
tentacleInfluence.core *
|
|
503
|
+
(0.11 + tipBlend * 0.06 + tentacleInfluence.widthScale * 0.025) *
|
|
504
|
+
radiusX;
|
|
505
|
+
const planarRadiusX = cosineLatitude * radiusX * horizontalScale + tentacleTubeRadius;
|
|
506
|
+
const planarRadiusZ = cosineLatitude * radiusZ * depthScale + tentacleTubeRadius * 0.72;
|
|
507
|
+
const lowerDrop =
|
|
508
|
+
lowerBlend *
|
|
509
|
+
radiusY *
|
|
510
|
+
(0.18 +
|
|
511
|
+
tentacleInfluence.core *
|
|
512
|
+
(0.38 +
|
|
513
|
+
tentacleInfluence.lengthScale * 0.22 +
|
|
514
|
+
(morphologyProfile.tentacles.flowLengthScale - 1) * 0.08));
|
|
515
|
+
|
|
516
|
+
return {
|
|
517
|
+
x:
|
|
518
|
+
Math.sin(effectiveLongitude) * planarRadiusX +
|
|
519
|
+
tentacleWave * radiusX * (0.052 + tipBlend * 0.05),
|
|
520
|
+
y:
|
|
521
|
+
Math.sin(latitude) * radiusY * (1 + upperBlend * 0.12) -
|
|
522
|
+
upperBlend * radiusY * 0.1 +
|
|
523
|
+
lowerDrop +
|
|
524
|
+
Math.sin(timeMs / 1420 + animationPhase + latitude * 1.6) * lowerBlend * radiusY * 0.018 +
|
|
525
|
+
Math.cos(timeMs / 880 + tentacleInfluence.phase) *
|
|
526
|
+
lowerBlend *
|
|
527
|
+
tipBlend *
|
|
528
|
+
tentacleInfluence.core *
|
|
529
|
+
radiusY *
|
|
530
|
+
0.034,
|
|
531
|
+
z:
|
|
532
|
+
Math.cos(effectiveLongitude) * planarRadiusZ +
|
|
533
|
+
Math.cos(timeMs / 980 + tentacleInfluence.phase + verticalProgress) *
|
|
534
|
+
lowerBlend *
|
|
535
|
+
tentacleInfluence.core *
|
|
536
|
+
radiusZ *
|
|
537
|
+
0.04,
|
|
538
|
+
};
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
/**
|
|
542
|
+
* Blends nearby seeded tentacle profiles at one mesh longitude.
|
|
543
|
+
*
|
|
544
|
+
* @private helper of `octopus3d3AvatarVisual`
|
|
545
|
+
*/
|
|
546
|
+
function resolveContinuousTentacleInfluence(
|
|
547
|
+
options: ContinuousOctopusSurfaceOptions,
|
|
548
|
+
longitude: number,
|
|
549
|
+
): ContinuousOctopusTentacleInfluence {
|
|
550
|
+
let totalWeight = 0;
|
|
551
|
+
let weightedSin = 0;
|
|
552
|
+
let weightedCos = 0;
|
|
553
|
+
let weightedWidthScale = 0;
|
|
554
|
+
let weightedLengthScale = 0;
|
|
555
|
+
let weightedSwayScale = 0;
|
|
556
|
+
let weightedDepthScale = 0;
|
|
557
|
+
let weightedPhase = 0;
|
|
558
|
+
|
|
559
|
+
for (const tentacleProfile of options.tentacleProfiles) {
|
|
560
|
+
const distance = Math.abs(resolveSignedAngularDistance(longitude, tentacleProfile.centerLongitude));
|
|
561
|
+
const width = 0.2 * tentacleProfile.widthScale;
|
|
562
|
+
const weight = Math.exp(-(distance * distance) / (width * width));
|
|
563
|
+
|
|
564
|
+
totalWeight += weight;
|
|
565
|
+
weightedSin += Math.sin(tentacleProfile.centerLongitude) * weight;
|
|
566
|
+
weightedCos += Math.cos(tentacleProfile.centerLongitude) * weight;
|
|
567
|
+
weightedWidthScale += tentacleProfile.widthScale * weight;
|
|
568
|
+
weightedLengthScale += tentacleProfile.lengthScale * weight;
|
|
569
|
+
weightedSwayScale += tentacleProfile.swayScale * weight;
|
|
570
|
+
weightedDepthScale += tentacleProfile.depthScale * weight;
|
|
571
|
+
weightedPhase += tentacleProfile.phase * weight;
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
if (totalWeight < 0.0001) {
|
|
575
|
+
return {
|
|
576
|
+
core: 0,
|
|
577
|
+
centerLongitude: longitude,
|
|
578
|
+
widthScale: 1,
|
|
579
|
+
lengthScale: 1,
|
|
580
|
+
swayScale: 1,
|
|
581
|
+
depthScale: 1,
|
|
582
|
+
phase: 0,
|
|
583
|
+
};
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
return {
|
|
587
|
+
core: clampNumber(totalWeight, 0, 1),
|
|
588
|
+
centerLongitude: Math.atan2(weightedSin / totalWeight, weightedCos / totalWeight),
|
|
589
|
+
widthScale: weightedWidthScale / totalWeight,
|
|
590
|
+
lengthScale: weightedLengthScale / totalWeight,
|
|
591
|
+
swayScale: weightedSwayScale / totalWeight,
|
|
592
|
+
depthScale: weightedDepthScale / totalWeight,
|
|
593
|
+
phase: weightedPhase / totalWeight,
|
|
594
|
+
};
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
/**
|
|
598
|
+
* Resolves the soft lower wave that makes the continuous mesh read as a set of tentacles.
|
|
599
|
+
*
|
|
600
|
+
* @private helper of `octopus3d3AvatarVisual`
|
|
601
|
+
*/
|
|
602
|
+
function resolveContinuousLobeWave(options: ContinuousOctopusSurfaceOptions, longitude: number): number {
|
|
603
|
+
const { morphologyProfile, animationPhase, timeMs } = options;
|
|
604
|
+
|
|
605
|
+
return (
|
|
606
|
+
Math.cos(longitude * OCTOPUS_TENTACLE_COUNT + animationPhase + timeMs / (980 + morphologyProfile.body.lobeCount * 18)) +
|
|
607
|
+
1
|
|
608
|
+
) / 2;
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
/**
|
|
612
|
+
* Resolves one base fill tone for a patch on the continuous octopus mesh.
|
|
613
|
+
*
|
|
614
|
+
* @private helper of `octopus3d3AvatarVisual`
|
|
615
|
+
*/
|
|
616
|
+
function resolveContinuousSurfacePatchFillStyle(
|
|
617
|
+
palette: AvatarPalette,
|
|
618
|
+
verticalProgress: number,
|
|
619
|
+
forwardness: number,
|
|
620
|
+
tentacleCore: number,
|
|
621
|
+
lowerLobeWave: number,
|
|
622
|
+
): string {
|
|
623
|
+
const tonalProgress = clampNumber(
|
|
624
|
+
verticalProgress + lowerLobeWave * 0.1 + tentacleCore * 0.08 - forwardness * 0.08,
|
|
625
|
+
0,
|
|
626
|
+
1,
|
|
627
|
+
);
|
|
628
|
+
|
|
629
|
+
if (tonalProgress < 0.14) {
|
|
630
|
+
return palette.highlight;
|
|
631
|
+
}
|
|
632
|
+
if (tonalProgress < 0.32) {
|
|
633
|
+
return palette.secondary;
|
|
634
|
+
}
|
|
635
|
+
if (tonalProgress < 0.72) {
|
|
636
|
+
return forwardness > 0.55 ? palette.secondary : palette.primary;
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
return tentacleCore > 0.44 ? `${palette.primary}f4` : `${palette.shadow}ee`;
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
/**
|
|
643
|
+
* Draws one projected mesh patch with soft shading and a subtle edge.
|
|
644
|
+
*
|
|
645
|
+
* @private helper of `octopus3d3AvatarVisual`
|
|
646
|
+
*/
|
|
647
|
+
function drawContinuousSurfacePatch(
|
|
648
|
+
context: CanvasRenderingContext2D,
|
|
649
|
+
surfacePatch: ContinuousOctopusSurfacePatch,
|
|
650
|
+
): void {
|
|
651
|
+
drawProjectedQuad(context, surfacePatch.corners, surfacePatch.fillStyle);
|
|
652
|
+
|
|
653
|
+
if (surfacePatch.lightIntensity > 0) {
|
|
654
|
+
drawProjectedQuad(context, surfacePatch.corners, `rgba(255, 255, 255, ${0.18 * surfacePatch.lightIntensity})`);
|
|
655
|
+
} else if (surfacePatch.lightIntensity < 0) {
|
|
656
|
+
drawProjectedQuad(
|
|
657
|
+
context,
|
|
658
|
+
surfacePatch.corners,
|
|
659
|
+
`rgba(0, 0, 0, ${0.25 * Math.abs(surfacePatch.lightIntensity)})`,
|
|
660
|
+
);
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
context.save();
|
|
664
|
+
context.beginPath();
|
|
665
|
+
context.moveTo(surfacePatch.corners[0].x, surfacePatch.corners[0].y);
|
|
666
|
+
for (let cornerIndex = 1; cornerIndex < surfacePatch.corners.length; cornerIndex++) {
|
|
667
|
+
context.lineTo(surfacePatch.corners[cornerIndex]!.x, surfacePatch.corners[cornerIndex]!.y);
|
|
668
|
+
}
|
|
669
|
+
context.closePath();
|
|
670
|
+
context.strokeStyle = surfacePatch.outlineColor;
|
|
671
|
+
context.lineWidth = Math.max(0.7, getProjectedQuadPerimeter(surfacePatch.corners) * 0.0032);
|
|
672
|
+
context.lineJoin = 'round';
|
|
673
|
+
context.stroke();
|
|
674
|
+
context.restore();
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
/**
|
|
678
|
+
* Draws projected mantle-current lines on the front of the mesh.
|
|
679
|
+
*
|
|
680
|
+
* @private helper of `octopus3d3AvatarVisual`
|
|
681
|
+
*/
|
|
682
|
+
function drawProjectedSurfaceCurrents(options: {
|
|
683
|
+
readonly context: CanvasRenderingContext2D;
|
|
684
|
+
readonly surfaceOptions: ContinuousOctopusSurfaceOptions;
|
|
685
|
+
readonly center: Point3D;
|
|
686
|
+
readonly rotationX: number;
|
|
687
|
+
readonly rotationY: number;
|
|
688
|
+
readonly sceneCenterX: number;
|
|
689
|
+
readonly sceneCenterY: number;
|
|
690
|
+
readonly size: number;
|
|
691
|
+
readonly palette: AvatarPalette;
|
|
692
|
+
readonly morphologyProfile: Octopus3MorphologyProfile;
|
|
693
|
+
readonly timeMs: number;
|
|
694
|
+
readonly animationPhase: number;
|
|
695
|
+
}): void {
|
|
696
|
+
const {
|
|
697
|
+
context,
|
|
698
|
+
surfaceOptions,
|
|
699
|
+
center,
|
|
700
|
+
rotationX,
|
|
701
|
+
rotationY,
|
|
702
|
+
sceneCenterX,
|
|
703
|
+
sceneCenterY,
|
|
704
|
+
size,
|
|
705
|
+
palette,
|
|
706
|
+
morphologyProfile,
|
|
707
|
+
timeMs,
|
|
708
|
+
animationPhase,
|
|
709
|
+
} = options;
|
|
710
|
+
const currentCount = Math.min(6, morphologyProfile.details.mantleCurrentCount);
|
|
711
|
+
const centerIndex = (currentCount - 1) / 2;
|
|
712
|
+
|
|
713
|
+
context.save();
|
|
714
|
+
context.lineCap = 'round';
|
|
715
|
+
context.lineJoin = 'round';
|
|
716
|
+
|
|
717
|
+
for (let currentIndex = 0; currentIndex < currentCount; currentIndex++) {
|
|
718
|
+
const baseLongitude = (currentIndex - centerIndex) * 0.15;
|
|
719
|
+
const projectedPoints: Array<ProjectedPoint> = [];
|
|
720
|
+
|
|
721
|
+
for (let sampleIndex = 0; sampleIndex < 8; sampleIndex++) {
|
|
722
|
+
const progress = sampleIndex / 7;
|
|
723
|
+
const latitude = -0.46 + progress * 0.74;
|
|
724
|
+
const longitude =
|
|
725
|
+
baseLongitude +
|
|
726
|
+
Math.sin(timeMs / 1160 + animationPhase + currentIndex * 0.7 + progress * 2) * 0.035;
|
|
727
|
+
const scenePoint = transformScenePoint(
|
|
728
|
+
sampleContinuousOctopusSurfacePoint(surfaceOptions, latitude, longitude),
|
|
729
|
+
center,
|
|
730
|
+
rotationX,
|
|
731
|
+
rotationY,
|
|
732
|
+
);
|
|
733
|
+
|
|
734
|
+
if (scenePoint.z > center.z - size * 0.016) {
|
|
735
|
+
projectedPoints.push(projectScenePoint(scenePoint, size, sceneCenterX, sceneCenterY));
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
if (projectedPoints.length < 3) {
|
|
740
|
+
continue;
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
context.beginPath();
|
|
744
|
+
context.moveTo(projectedPoints[0]!.x, projectedPoints[0]!.y);
|
|
745
|
+
for (const projectedPoint of projectedPoints.slice(1)) {
|
|
746
|
+
context.lineTo(projectedPoint.x, projectedPoint.y);
|
|
747
|
+
}
|
|
748
|
+
context.strokeStyle = currentIndex % 2 === 0 ? `${palette.highlight}3d` : `${palette.accent}33`;
|
|
749
|
+
context.lineWidth = size * (0.0055 + currentIndex * 0.00045);
|
|
750
|
+
context.stroke();
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
context.restore();
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
/**
|
|
757
|
+
* Draws small projected sucker highlights on the waving lower mesh lobes.
|
|
758
|
+
*
|
|
759
|
+
* @private helper of `octopus3d3AvatarVisual`
|
|
760
|
+
*/
|
|
761
|
+
function drawProjectedTentacleSuckers(options: {
|
|
762
|
+
readonly context: CanvasRenderingContext2D;
|
|
763
|
+
readonly surfaceOptions: ContinuousOctopusSurfaceOptions;
|
|
764
|
+
readonly center: Point3D;
|
|
765
|
+
readonly rotationX: number;
|
|
766
|
+
readonly rotationY: number;
|
|
767
|
+
readonly sceneCenterX: number;
|
|
768
|
+
readonly sceneCenterY: number;
|
|
769
|
+
readonly size: number;
|
|
770
|
+
readonly palette: AvatarPalette;
|
|
771
|
+
}): void {
|
|
772
|
+
const { surfaceOptions, size } = options;
|
|
773
|
+
const { timeMs } = surfaceOptions;
|
|
774
|
+
|
|
775
|
+
for (const tentacleProfile of surfaceOptions.tentacleProfiles) {
|
|
776
|
+
if (Math.cos(tentacleProfile.centerLongitude) < -0.12) {
|
|
777
|
+
continue;
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
for (let suckerIndex = 0; suckerIndex < 3; suckerIndex++) {
|
|
781
|
+
const latitude = 0.52 + suckerIndex * 0.14;
|
|
782
|
+
const sideOffset = tentacleProfile.suckerSide * (0.035 + suckerIndex * 0.012) * tentacleProfile.widthScale;
|
|
783
|
+
const waveOffset = Math.sin(timeMs / 900 + tentacleProfile.phase + suckerIndex * 0.8) * 0.018;
|
|
784
|
+
|
|
785
|
+
drawProjectedSurfaceSpot({
|
|
786
|
+
...options,
|
|
787
|
+
latitude,
|
|
788
|
+
longitude: tentacleProfile.centerLongitude + sideOffset + waveOffset,
|
|
789
|
+
radiusScale: size * (0.0065 - suckerIndex * 0.0007),
|
|
790
|
+
});
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
/**
|
|
796
|
+
* Draws one tiny projected surface spot by sampling local mesh tangents.
|
|
797
|
+
*
|
|
798
|
+
* @private helper of `octopus3d3AvatarVisual`
|
|
799
|
+
*/
|
|
800
|
+
function drawProjectedSurfaceSpot(options: {
|
|
801
|
+
readonly context: CanvasRenderingContext2D;
|
|
802
|
+
readonly surfaceOptions: ContinuousOctopusSurfaceOptions;
|
|
803
|
+
readonly center: Point3D;
|
|
804
|
+
readonly rotationX: number;
|
|
805
|
+
readonly rotationY: number;
|
|
806
|
+
readonly sceneCenterX: number;
|
|
807
|
+
readonly sceneCenterY: number;
|
|
808
|
+
readonly size: number;
|
|
809
|
+
readonly palette: AvatarPalette;
|
|
810
|
+
readonly latitude: number;
|
|
811
|
+
readonly longitude: number;
|
|
812
|
+
readonly radiusScale: number;
|
|
813
|
+
}): void {
|
|
814
|
+
const {
|
|
815
|
+
context,
|
|
816
|
+
surfaceOptions,
|
|
817
|
+
center,
|
|
818
|
+
rotationX,
|
|
819
|
+
rotationY,
|
|
820
|
+
sceneCenterX,
|
|
821
|
+
sceneCenterY,
|
|
822
|
+
size,
|
|
823
|
+
palette,
|
|
824
|
+
latitude,
|
|
825
|
+
longitude,
|
|
826
|
+
radiusScale,
|
|
827
|
+
} = options;
|
|
828
|
+
const localCenter = sampleContinuousOctopusSurfacePoint(surfaceOptions, latitude, longitude);
|
|
829
|
+
const localHorizontal = sampleContinuousOctopusSurfacePoint(surfaceOptions, latitude, longitude + 0.018);
|
|
830
|
+
const localVertical = sampleContinuousOctopusSurfacePoint(surfaceOptions, latitude + 0.018, longitude);
|
|
831
|
+
const sceneCenterPoint = transformScenePoint(localCenter, center, rotationX, rotationY);
|
|
832
|
+
|
|
833
|
+
if (sceneCenterPoint.z <= center.z - size * 0.012) {
|
|
834
|
+
return;
|
|
835
|
+
}
|
|
836
|
+
|
|
837
|
+
const projectedCenterPoint = projectScenePoint(sceneCenterPoint, size, sceneCenterX, sceneCenterY);
|
|
838
|
+
const projectedHorizontalPoint = projectScenePoint(
|
|
839
|
+
transformScenePoint(localHorizontal, center, rotationX, rotationY),
|
|
840
|
+
size,
|
|
841
|
+
sceneCenterX,
|
|
842
|
+
sceneCenterY,
|
|
843
|
+
);
|
|
844
|
+
const projectedVerticalPoint = projectScenePoint(
|
|
845
|
+
transformScenePoint(localVertical, center, rotationX, rotationY),
|
|
846
|
+
size,
|
|
847
|
+
sceneCenterX,
|
|
848
|
+
sceneCenterY,
|
|
849
|
+
);
|
|
850
|
+
const horizontalRadius = clampNumber(
|
|
851
|
+
Math.hypot(
|
|
852
|
+
projectedHorizontalPoint.x - projectedCenterPoint.x,
|
|
853
|
+
projectedHorizontalPoint.y - projectedCenterPoint.y,
|
|
854
|
+
) *
|
|
855
|
+
radiusScale *
|
|
856
|
+
0.74,
|
|
857
|
+
size * 0.003,
|
|
858
|
+
size * 0.018,
|
|
859
|
+
);
|
|
860
|
+
const verticalRadius = clampNumber(
|
|
861
|
+
Math.hypot(projectedVerticalPoint.x - projectedCenterPoint.x, projectedVerticalPoint.y - projectedCenterPoint.y) *
|
|
862
|
+
radiusScale *
|
|
863
|
+
0.52,
|
|
864
|
+
size * 0.0024,
|
|
865
|
+
size * 0.014,
|
|
866
|
+
);
|
|
867
|
+
const rotation = Math.atan2(
|
|
868
|
+
projectedHorizontalPoint.y - projectedCenterPoint.y,
|
|
869
|
+
projectedHorizontalPoint.x - projectedCenterPoint.x,
|
|
870
|
+
);
|
|
871
|
+
|
|
872
|
+
context.save();
|
|
873
|
+
context.translate(projectedCenterPoint.x, projectedCenterPoint.y);
|
|
874
|
+
context.rotate(rotation);
|
|
875
|
+
context.beginPath();
|
|
876
|
+
context.ellipse(0, 0, horizontalRadius, verticalRadius, 0, 0, Math.PI * 2);
|
|
877
|
+
context.fillStyle = `${palette.highlight}73`;
|
|
878
|
+
context.fill();
|
|
879
|
+
context.strokeStyle = `${palette.highlight}99`;
|
|
880
|
+
context.lineWidth = Math.max(0.7, size * 0.0028);
|
|
881
|
+
context.stroke();
|
|
882
|
+
context.restore();
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
/**
|
|
886
|
+
* Resolves a signed angular distance from the source longitude to the target longitude.
|
|
887
|
+
*
|
|
888
|
+
* @private helper of `octopus3d3AvatarVisual`
|
|
889
|
+
*/
|
|
890
|
+
function resolveSignedAngularDistance(sourceLongitude: number, targetLongitude: number): number {
|
|
891
|
+
return Math.atan2(Math.sin(targetLongitude - sourceLongitude), Math.cos(targetLongitude - sourceLongitude));
|
|
892
|
+
}
|
|
893
|
+
|
|
894
|
+
/**
|
|
895
|
+
* Smoothly maps a value between two bounds into `[0, 1]`.
|
|
896
|
+
*
|
|
897
|
+
* @private helper of `octopus3d3AvatarVisual`
|
|
898
|
+
*/
|
|
899
|
+
function smoothStep(edgeStart: number, edgeEnd: number, value: number): number {
|
|
900
|
+
const progress = clampNumber((value - edgeStart) / (edgeEnd - edgeStart), 0, 1);
|
|
901
|
+
|
|
902
|
+
return progress * progress * (3 - 2 * progress);
|
|
903
|
+
}
|