@promptbook/core 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/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/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
package/esm/index.es.js
CHANGED
|
@@ -28,7 +28,7 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
|
|
|
28
28
|
* @generated
|
|
29
29
|
* @see https://github.com/webgptorg/promptbook
|
|
30
30
|
*/
|
|
31
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.112.0-
|
|
31
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.112.0-104';
|
|
32
32
|
/**
|
|
33
33
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
34
34
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -13539,7 +13539,7 @@ function fillTextureRect(texture, x, y, width, height, color) {
|
|
|
13539
13539
|
*
|
|
13540
13540
|
* @private helper of `minecraft2AvatarVisual`
|
|
13541
13541
|
*/
|
|
13542
|
-
const LIGHT_DIRECTION$
|
|
13542
|
+
const LIGHT_DIRECTION$3 = normalizeVector3({
|
|
13543
13543
|
x: 0.4,
|
|
13544
13544
|
y: -0.65,
|
|
13545
13545
|
z: 0.92,
|
|
@@ -13751,7 +13751,7 @@ function resolveVisibleCuboidFaces(cuboid, size, sceneCenterX, sceneCenterY) {
|
|
|
13751
13751
|
corners: projectedCorners,
|
|
13752
13752
|
texture: faceDefinition.texture,
|
|
13753
13753
|
averageDepth: transformedCorners.reduce((depthSum, corner) => depthSum + corner.z, 0) / transformedCorners.length,
|
|
13754
|
-
lightIntensity: clampNumber$1(dotProduct3D(faceNormal, LIGHT_DIRECTION$
|
|
13754
|
+
lightIntensity: clampNumber$1(dotProduct3D(faceNormal, LIGHT_DIRECTION$3), -1, 1),
|
|
13755
13755
|
outlineColor: cuboid.outlineColor,
|
|
13756
13756
|
};
|
|
13757
13757
|
});
|
|
@@ -14942,7 +14942,7 @@ function formatAlphaHex(opacity) {
|
|
|
14942
14942
|
*
|
|
14943
14943
|
* @private helper of `octopus3dAvatarVisual`
|
|
14944
14944
|
*/
|
|
14945
|
-
const LIGHT_DIRECTION$
|
|
14945
|
+
const LIGHT_DIRECTION$2 = normalizeVector3({
|
|
14946
14946
|
x: 0.48,
|
|
14947
14947
|
y: -0.62,
|
|
14948
14948
|
z: 0.94,
|
|
@@ -15152,7 +15152,7 @@ function resolveVisibleEllipsoidPatches(options) {
|
|
|
15152
15152
|
corners: projectedCorners,
|
|
15153
15153
|
averageDepth: transformedCorners.reduce((depthSum, transformedCorner) => depthSum + transformedCorner.z, 0) /
|
|
15154
15154
|
transformedCorners.length,
|
|
15155
|
-
lightIntensity: clampNumber$1(dotProduct3D(surfaceNormal, LIGHT_DIRECTION$
|
|
15155
|
+
lightIntensity: clampNumber$1(dotProduct3D(surfaceNormal, LIGHT_DIRECTION$2), -1, 1),
|
|
15156
15156
|
fillStyle: resolveSurfacePatchFillStyle(palette, verticalProgress + verticalColorBias),
|
|
15157
15157
|
outlineColor,
|
|
15158
15158
|
});
|
|
@@ -15341,7 +15341,7 @@ function resolveEllipsoidSurfaceDepth(radiusX, radiusY, radiusZ, x, y) {
|
|
|
15341
15341
|
*
|
|
15342
15342
|
* @private helper of `octopus3d2AvatarVisual`
|
|
15343
15343
|
*/
|
|
15344
|
-
const LIGHT_DIRECTION = normalizeVector3({
|
|
15344
|
+
const LIGHT_DIRECTION$1 = normalizeVector3({
|
|
15345
15345
|
x: 0.38,
|
|
15346
15346
|
y: -0.6,
|
|
15347
15347
|
z: 0.98,
|
|
@@ -15490,7 +15490,7 @@ function resolveVisibleBlobbyOctopusPatches(options) {
|
|
|
15490
15490
|
corners: projectedCorners,
|
|
15491
15491
|
averageDepth: transformedCorners.reduce((depthSum, transformedCorner) => depthSum + transformedCorner.z, 0) /
|
|
15492
15492
|
transformedCorners.length,
|
|
15493
|
-
lightIntensity: clampNumber$1(dotProduct3D(surfaceNormal, LIGHT_DIRECTION), -1, 1),
|
|
15493
|
+
lightIntensity: clampNumber$1(dotProduct3D(surfaceNormal, LIGHT_DIRECTION$1), -1, 1),
|
|
15494
15494
|
fillStyle: resolveBlobbySurfacePatchFillStyle(palette, verticalProgress, Math.max(0, Math.cos(centerLongitude)), resolveLowerLobeWave(centerLongitude, morphologyProfile, animationPhase, timeMs)),
|
|
15495
15495
|
outlineColor: verticalProgress < 0.58 ? `${palette.highlight}73` : `${palette.shadow}8a`,
|
|
15496
15496
|
});
|
|
@@ -15590,6 +15590,516 @@ function drawBlobbySurfacePatch(context, surfacePatch) {
|
|
|
15590
15590
|
context.restore();
|
|
15591
15591
|
}
|
|
15592
15592
|
|
|
15593
|
+
/* eslint-disable no-magic-numbers */
|
|
15594
|
+
/**
|
|
15595
|
+
* Light direction used by the continuous octopus mesh shading.
|
|
15596
|
+
*
|
|
15597
|
+
* @private helper of `octopus3d3AvatarVisual`
|
|
15598
|
+
*/
|
|
15599
|
+
const LIGHT_DIRECTION = normalizeVector3({
|
|
15600
|
+
x: 0.34,
|
|
15601
|
+
y: -0.62,
|
|
15602
|
+
z: 1,
|
|
15603
|
+
});
|
|
15604
|
+
/**
|
|
15605
|
+
* Real-octopus tentacle count used by the continuous lower mesh.
|
|
15606
|
+
*
|
|
15607
|
+
* @private helper of `octopus3d3AvatarVisual`
|
|
15608
|
+
*/
|
|
15609
|
+
const OCTOPUS_TENTACLE_COUNT = 8;
|
|
15610
|
+
/**
|
|
15611
|
+
* Octopus 3D 3 avatar visual.
|
|
15612
|
+
*
|
|
15613
|
+
* @private built-in avatar visual
|
|
15614
|
+
*/
|
|
15615
|
+
const octopus3d3AvatarVisual = {
|
|
15616
|
+
id: 'octopus3d3',
|
|
15617
|
+
title: 'Octopus 3D 3',
|
|
15618
|
+
description: 'Cute continuous 3D octopus with a blobby single mesh, waving tentacle lobes, rich shading, and cursor-aware eyes.',
|
|
15619
|
+
isAnimated: true,
|
|
15620
|
+
supportsPointerTracking: true,
|
|
15621
|
+
render({ context, size, palette, createRandom, timeMs, interaction }) {
|
|
15622
|
+
const morphologyProfile = createOctopus3MorphologyProfile(createRandom);
|
|
15623
|
+
const animationRandom = createRandom('octopus3d3-animation-profile');
|
|
15624
|
+
const eyeRandom = createRandom('octopus3d3-eye-profile');
|
|
15625
|
+
const animationPhase = animationRandom() * Math.PI * 2;
|
|
15626
|
+
const tentacleProfiles = createContinuousTentacleProfiles(createRandom, morphologyProfile);
|
|
15627
|
+
const sceneCenterX = size * 0.5;
|
|
15628
|
+
const sceneCenterY = size * 0.535;
|
|
15629
|
+
const bob = Math.sin(timeMs / 960 + animationPhase) * size * 0.012;
|
|
15630
|
+
const meshCenter = {
|
|
15631
|
+
x: interaction.bodyOffsetX * size * 0.048 + size * morphologyProfile.body.centerXJitterRatio * 0.44,
|
|
15632
|
+
y: -size * 0.07 + interaction.bodyOffsetY * size * 0.026 + bob,
|
|
15633
|
+
z: interaction.intensity * size * 0.018,
|
|
15634
|
+
};
|
|
15635
|
+
const rotationY = -0.1 +
|
|
15636
|
+
Math.sin(timeMs / 2700 + animationPhase) * 0.035 +
|
|
15637
|
+
interaction.bodyOffsetX * 0.22 +
|
|
15638
|
+
interaction.gazeX * 0.88;
|
|
15639
|
+
const rotationX = -0.07 +
|
|
15640
|
+
Math.cos(timeMs / 3100 + animationPhase * 0.7) * 0.018 -
|
|
15641
|
+
interaction.bodyOffsetY * 0.08 -
|
|
15642
|
+
interaction.gazeY * 0.38;
|
|
15643
|
+
const surfaceOptions = {
|
|
15644
|
+
radiusX: size * morphologyProfile.body.bodyRadiusRatio * morphologyProfile.body.horizontalStretch * 1.1,
|
|
15645
|
+
radiusY: size * morphologyProfile.body.bodyRadiusRatio * morphologyProfile.body.verticalStretch * 1.08,
|
|
15646
|
+
radiusZ: size *
|
|
15647
|
+
morphologyProfile.body.bodyRadiusRatio *
|
|
15648
|
+
(1.02 + (morphologyProfile.body.horizontalStretch - 1) * 0.18),
|
|
15649
|
+
morphologyProfile,
|
|
15650
|
+
timeMs,
|
|
15651
|
+
animationPhase,
|
|
15652
|
+
tentacleProfiles,
|
|
15653
|
+
};
|
|
15654
|
+
const surfacePatches = resolveVisibleContinuousOctopusPatches({
|
|
15655
|
+
...surfaceOptions,
|
|
15656
|
+
center: meshCenter,
|
|
15657
|
+
rotationX,
|
|
15658
|
+
rotationY,
|
|
15659
|
+
sceneCenterX,
|
|
15660
|
+
sceneCenterY,
|
|
15661
|
+
size,
|
|
15662
|
+
palette,
|
|
15663
|
+
});
|
|
15664
|
+
const eyeLatitude = clampNumber$1(morphologyProfile.face.eyeCenterYOffsetRatio * 4.2 - 0.03, -0.22, 0.08);
|
|
15665
|
+
const eyeLongitude = clampNumber$1(morphologyProfile.face.eyeSpacingRatio * 3.1, 0.18, 0.32);
|
|
15666
|
+
const mouthLatitude = clampNumber$1(eyeLatitude + 0.2 + morphologyProfile.face.mouthYOffsetRatio, 0.08, 0.34);
|
|
15667
|
+
const mouthCenterLongitude = clampNumber$1(morphologyProfile.face.mouthCenterOffsetRatio * 5.6, -0.08, 0.08);
|
|
15668
|
+
const mouthHalfLongitude = clampNumber$1(eyeLongitude * 0.78, 0.15, 0.28);
|
|
15669
|
+
const mouthCurveLatitude = clampNumber$1(mouthLatitude + morphologyProfile.face.mouthCurveDepthRatio * 0.78, mouthLatitude + 0.03, 0.42);
|
|
15670
|
+
const eyeRadiusX = size * morphologyProfile.face.eyeRadiusXRatio * 0.76;
|
|
15671
|
+
const eyeRadiusY = eyeRadiusX * morphologyProfile.face.eyeHeightRatio * 0.9;
|
|
15672
|
+
drawAvatarFrame(context, size, palette);
|
|
15673
|
+
drawContinuousOctopusAtmosphere(context, size, palette, sceneCenterX, sceneCenterY, interaction, timeMs);
|
|
15674
|
+
drawContinuousOctopusShadow(context, size, palette, interaction, timeMs, morphologyProfile);
|
|
15675
|
+
for (const surfacePatch of surfacePatches.sort((firstSurfacePatch, secondSurfacePatch) => firstSurfacePatch.averageDepth - secondSurfacePatch.averageDepth)) {
|
|
15676
|
+
drawContinuousSurfacePatch(context, surfacePatch);
|
|
15677
|
+
}
|
|
15678
|
+
drawProjectedSurfaceCurrents({
|
|
15679
|
+
context,
|
|
15680
|
+
surfaceOptions,
|
|
15681
|
+
center: meshCenter,
|
|
15682
|
+
rotationX,
|
|
15683
|
+
rotationY,
|
|
15684
|
+
sceneCenterX,
|
|
15685
|
+
sceneCenterY,
|
|
15686
|
+
size,
|
|
15687
|
+
palette,
|
|
15688
|
+
morphologyProfile,
|
|
15689
|
+
timeMs,
|
|
15690
|
+
animationPhase,
|
|
15691
|
+
});
|
|
15692
|
+
drawProjectedTentacleSuckers({
|
|
15693
|
+
context,
|
|
15694
|
+
surfaceOptions,
|
|
15695
|
+
center: meshCenter,
|
|
15696
|
+
rotationX,
|
|
15697
|
+
rotationY,
|
|
15698
|
+
sceneCenterX,
|
|
15699
|
+
sceneCenterY,
|
|
15700
|
+
size,
|
|
15701
|
+
palette,
|
|
15702
|
+
});
|
|
15703
|
+
drawProjectedOrganicEye(context, sampleContinuousOctopusSurfacePoint(surfaceOptions, eyeLatitude, -eyeLongitude), eyeRadiusX, eyeRadiusY, meshCenter, rotationX, rotationY, sceneCenterX, sceneCenterY, size, palette, timeMs, animationPhase + eyeRandom() * 0.7, interaction, morphologyProfile.face.eyeStyle);
|
|
15704
|
+
drawProjectedOrganicEye(context, sampleContinuousOctopusSurfacePoint(surfaceOptions, eyeLatitude, eyeLongitude), eyeRadiusX, eyeRadiusY, meshCenter, rotationX, rotationY, sceneCenterX, sceneCenterY, size, palette, timeMs, animationPhase + 0.85 + eyeRandom() * 0.7, interaction, morphologyProfile.face.eyeStyle);
|
|
15705
|
+
drawProjectedOrganicMouth(context, [
|
|
15706
|
+
sampleContinuousOctopusSurfacePoint(surfaceOptions, mouthLatitude, mouthCenterLongitude - mouthHalfLongitude),
|
|
15707
|
+
sampleContinuousOctopusSurfacePoint(surfaceOptions, mouthCurveLatitude, mouthCenterLongitude),
|
|
15708
|
+
sampleContinuousOctopusSurfacePoint(surfaceOptions, mouthLatitude, mouthCenterLongitude + mouthHalfLongitude),
|
|
15709
|
+
], meshCenter, rotationX, rotationY, sceneCenterX, sceneCenterY, palette, size);
|
|
15710
|
+
},
|
|
15711
|
+
};
|
|
15712
|
+
/**
|
|
15713
|
+
* Creates seeded tentacle-lobe profiles around the visible lower octopus body.
|
|
15714
|
+
*
|
|
15715
|
+
* @private helper of `octopus3d3AvatarVisual`
|
|
15716
|
+
*/
|
|
15717
|
+
function createContinuousTentacleProfiles(createRandom, morphologyProfile) {
|
|
15718
|
+
return Array.from({ length: OCTOPUS_TENTACLE_COUNT }, (_, tentacleIndex) => {
|
|
15719
|
+
const tentacleRandom = createRandom(`octopus3d3-tentacle-${tentacleIndex}`);
|
|
15720
|
+
const progress = tentacleIndex / (OCTOPUS_TENTACLE_COUNT - 1);
|
|
15721
|
+
return {
|
|
15722
|
+
centerLongitude: -Math.PI * 0.86 +
|
|
15723
|
+
progress * Math.PI * 1.72 +
|
|
15724
|
+
(tentacleRandom() - 0.5) * (0.08 + morphologyProfile.tentacles.rootSpreadScale * 0.03),
|
|
15725
|
+
widthScale: 0.86 + tentacleRandom() * 0.34 + (morphologyProfile.tentacles.baseWidthScale - 1) * 0.16,
|
|
15726
|
+
lengthScale: 0.86 + tentacleRandom() * 0.36 + (morphologyProfile.tentacles.flowLengthScale - 1) * 0.22,
|
|
15727
|
+
swayScale: 0.82 + tentacleRandom() * 0.38 + (morphologyProfile.tentacles.swayScale - 1) * 0.2,
|
|
15728
|
+
depthScale: 0.86 + tentacleRandom() * 0.32 + (morphologyProfile.tentacles.tipReachScale - 1) * 0.2,
|
|
15729
|
+
phase: tentacleRandom() * Math.PI * 2,
|
|
15730
|
+
suckerSide: tentacleRandom() > 0.5 ? 1 : -1,
|
|
15731
|
+
};
|
|
15732
|
+
});
|
|
15733
|
+
}
|
|
15734
|
+
/**
|
|
15735
|
+
* Draws the soft underwater atmosphere behind the continuous octopus mesh.
|
|
15736
|
+
*
|
|
15737
|
+
* @private helper of `octopus3d3AvatarVisual`
|
|
15738
|
+
*/
|
|
15739
|
+
function drawContinuousOctopusAtmosphere(context, size, palette, sceneCenterX, sceneCenterY, interaction, timeMs) {
|
|
15740
|
+
const glowGradient = context.createRadialGradient(sceneCenterX + interaction.gazeX * size * 0.11, sceneCenterY - size * 0.17 + interaction.gazeY * size * 0.05, size * 0.04, sceneCenterX, sceneCenterY, size * (0.66 + interaction.intensity * 0.02));
|
|
15741
|
+
glowGradient.addColorStop(0, `${palette.highlight}66`);
|
|
15742
|
+
glowGradient.addColorStop(0.34, `${palette.accent}2e`);
|
|
15743
|
+
glowGradient.addColorStop(1, `${palette.highlight}00`);
|
|
15744
|
+
context.fillStyle = glowGradient;
|
|
15745
|
+
context.fillRect(0, 0, size, size);
|
|
15746
|
+
const lowerGradient = context.createRadialGradient(sceneCenterX + Math.sin(timeMs / 1550) * size * 0.05, sceneCenterY + size * 0.29, size * 0.06, sceneCenterX, sceneCenterY + size * 0.3, size * 0.54);
|
|
15747
|
+
lowerGradient.addColorStop(0, `${palette.secondary}25`);
|
|
15748
|
+
lowerGradient.addColorStop(1, `${palette.secondary}00`);
|
|
15749
|
+
context.fillStyle = lowerGradient;
|
|
15750
|
+
context.fillRect(0, 0, size, size);
|
|
15751
|
+
}
|
|
15752
|
+
/**
|
|
15753
|
+
* Draws the soft lower shadow that anchors the octopus in the avatar frame.
|
|
15754
|
+
*
|
|
15755
|
+
* @private helper of `octopus3d3AvatarVisual`
|
|
15756
|
+
*/
|
|
15757
|
+
function drawContinuousOctopusShadow(context, size, palette, interaction, timeMs, morphologyProfile) {
|
|
15758
|
+
context.save();
|
|
15759
|
+
context.fillStyle = `${palette.shadow}66`;
|
|
15760
|
+
context.filter = `blur(${size * 0.025}px)`;
|
|
15761
|
+
context.beginPath();
|
|
15762
|
+
context.ellipse(size * 0.5 + interaction.gazeX * size * 0.045, size * 0.9 + Math.sin(timeMs / 980) * size * 0.007, size * (0.19 + morphologyProfile.tentacles.rootSpreadScale * 0.022 + interaction.intensity * 0.02), size * 0.06, 0, 0, Math.PI * 2);
|
|
15763
|
+
context.fill();
|
|
15764
|
+
context.restore();
|
|
15765
|
+
}
|
|
15766
|
+
/**
|
|
15767
|
+
* Resolves visible projected patches for the continuous octopus mesh.
|
|
15768
|
+
*
|
|
15769
|
+
* @private helper of `octopus3d3AvatarVisual`
|
|
15770
|
+
*/
|
|
15771
|
+
function resolveVisibleContinuousOctopusPatches(options) {
|
|
15772
|
+
const { center, rotationX, rotationY, sceneCenterX, sceneCenterY, size, palette } = options;
|
|
15773
|
+
const latitudePatchCount = 16;
|
|
15774
|
+
const longitudePatchCount = 40;
|
|
15775
|
+
const surfacePatches = [];
|
|
15776
|
+
for (let latitudeIndex = 0; latitudeIndex < latitudePatchCount; latitudeIndex++) {
|
|
15777
|
+
const startLatitude = -Math.PI / 2 + (latitudeIndex / latitudePatchCount) * Math.PI;
|
|
15778
|
+
const endLatitude = -Math.PI / 2 + ((latitudeIndex + 1) / latitudePatchCount) * Math.PI;
|
|
15779
|
+
const centerLatitude = (startLatitude + endLatitude) / 2;
|
|
15780
|
+
const verticalProgress = (Math.sin(centerLatitude) + 1) / 2;
|
|
15781
|
+
for (let longitudeIndex = 0; longitudeIndex < longitudePatchCount; longitudeIndex++) {
|
|
15782
|
+
const startLongitude = -Math.PI + (longitudeIndex / longitudePatchCount) * Math.PI * 2;
|
|
15783
|
+
const endLongitude = -Math.PI + ((longitudeIndex + 1) / longitudePatchCount) * Math.PI * 2;
|
|
15784
|
+
const centerLongitude = (startLongitude + endLongitude) / 2;
|
|
15785
|
+
const localCorners = [
|
|
15786
|
+
sampleContinuousOctopusSurfacePoint(options, startLatitude, startLongitude),
|
|
15787
|
+
sampleContinuousOctopusSurfacePoint(options, startLatitude, endLongitude),
|
|
15788
|
+
sampleContinuousOctopusSurfacePoint(options, endLatitude, endLongitude),
|
|
15789
|
+
sampleContinuousOctopusSurfacePoint(options, endLatitude, startLongitude),
|
|
15790
|
+
];
|
|
15791
|
+
const transformedCorners = localCorners.map((localCorner) => transformScenePoint(localCorner, center, rotationX, rotationY));
|
|
15792
|
+
const surfaceNormal = normalizeVector3(crossProduct3D(subtractPoint3D(transformedCorners[1], transformedCorners[0]), subtractPoint3D(transformedCorners[2], transformedCorners[0])));
|
|
15793
|
+
if (surfaceNormal.z <= 0.008) {
|
|
15794
|
+
continue;
|
|
15795
|
+
}
|
|
15796
|
+
const projectedCorners = transformedCorners.map((transformedCorner) => projectScenePoint(transformedCorner, size, sceneCenterX, sceneCenterY));
|
|
15797
|
+
const tentacleInfluence = resolveContinuousTentacleInfluence(options, centerLongitude);
|
|
15798
|
+
const lowerLobeWave = resolveContinuousLobeWave(options, centerLongitude);
|
|
15799
|
+
surfacePatches.push({
|
|
15800
|
+
corners: projectedCorners,
|
|
15801
|
+
averageDepth: transformedCorners.reduce((depthSum, transformedCorner) => depthSum + transformedCorner.z, 0) /
|
|
15802
|
+
transformedCorners.length,
|
|
15803
|
+
lightIntensity: clampNumber$1(dotProduct3D(surfaceNormal, LIGHT_DIRECTION), -1, 1),
|
|
15804
|
+
fillStyle: resolveContinuousSurfacePatchFillStyle(palette, verticalProgress, Math.max(0, Math.cos(centerLongitude)), tentacleInfluence.core, lowerLobeWave),
|
|
15805
|
+
outlineColor: verticalProgress < 0.54 ? `${palette.highlight}69` : `${palette.shadow}78`,
|
|
15806
|
+
});
|
|
15807
|
+
}
|
|
15808
|
+
}
|
|
15809
|
+
return surfacePatches;
|
|
15810
|
+
}
|
|
15811
|
+
/**
|
|
15812
|
+
* Samples one point on the continuous Octopus 3D 3 surface.
|
|
15813
|
+
*
|
|
15814
|
+
* The lower hemisphere is pulled into eight seeded waving lobes, so the portrait reads as
|
|
15815
|
+
* tentacled while still being rendered as one connected blobby mesh.
|
|
15816
|
+
*
|
|
15817
|
+
* @private helper of `octopus3d3AvatarVisual`
|
|
15818
|
+
*/
|
|
15819
|
+
function sampleContinuousOctopusSurfacePoint(options, latitude, longitude) {
|
|
15820
|
+
const { radiusX, radiusY, radiusZ, morphologyProfile, timeMs, animationPhase } = options;
|
|
15821
|
+
const cosineLatitude = Math.max(0, Math.cos(latitude));
|
|
15822
|
+
const verticalProgress = (Math.sin(latitude) + 1) / 2;
|
|
15823
|
+
const upperBlend = Math.pow(1 - verticalProgress, 1.28);
|
|
15824
|
+
const lowerBlend = smoothStep(0.38, 1, verticalProgress);
|
|
15825
|
+
const tipBlend = smoothStep(0.68, 1, verticalProgress);
|
|
15826
|
+
const tentacleInfluence = resolveContinuousTentacleInfluence(options, longitude);
|
|
15827
|
+
const centerPull = resolveSignedAngularDistance(longitude, tentacleInfluence.centerLongitude);
|
|
15828
|
+
const effectiveLongitude = longitude + centerPull * lowerBlend * tentacleInfluence.core * (0.24 + tipBlend * 0.2);
|
|
15829
|
+
const lowerLobeWave = resolveContinuousLobeWave(options, longitude);
|
|
15830
|
+
const mantleRipple = Math.sin(longitude * morphologyProfile.body.lobeCount +
|
|
15831
|
+
animationPhase * 0.6 +
|
|
15832
|
+
timeMs / (1750 + morphologyProfile.body.lobeCount * 30)) *
|
|
15833
|
+
(0.018 + morphologyProfile.body.wobbleAmplitudeRatio * 0.8) *
|
|
15834
|
+
(0.3 + lowerBlend * 0.7);
|
|
15835
|
+
const tentacleWave = Math.sin(timeMs / 760 + tentacleInfluence.phase + verticalProgress * 2.4) *
|
|
15836
|
+
lowerBlend *
|
|
15837
|
+
tentacleInfluence.core *
|
|
15838
|
+
tentacleInfluence.swayScale;
|
|
15839
|
+
const horizontalScale = 1.04 +
|
|
15840
|
+
mantleRipple +
|
|
15841
|
+
lowerBlend * (0.16 + (morphologyProfile.tentacles.rootSpreadScale - 1) * 0.1) +
|
|
15842
|
+
lowerBlend * tentacleInfluence.core * (0.2 + lowerLobeWave * 0.12) -
|
|
15843
|
+
upperBlend * 0.08;
|
|
15844
|
+
const depthScale = 1.06 +
|
|
15845
|
+
upperBlend * 0.16 +
|
|
15846
|
+
Math.max(0, Math.cos(effectiveLongitude)) * 0.1 +
|
|
15847
|
+
lowerBlend * tentacleInfluence.core * (0.1 + tentacleInfluence.depthScale * 0.06) -
|
|
15848
|
+
Math.max(0, -Math.cos(effectiveLongitude)) * 0.05;
|
|
15849
|
+
const tentacleTubeRadius = lowerBlend *
|
|
15850
|
+
tentacleInfluence.core *
|
|
15851
|
+
(0.11 + tipBlend * 0.06 + tentacleInfluence.widthScale * 0.025) *
|
|
15852
|
+
radiusX;
|
|
15853
|
+
const planarRadiusX = cosineLatitude * radiusX * horizontalScale + tentacleTubeRadius;
|
|
15854
|
+
const planarRadiusZ = cosineLatitude * radiusZ * depthScale + tentacleTubeRadius * 0.72;
|
|
15855
|
+
const lowerDrop = lowerBlend *
|
|
15856
|
+
radiusY *
|
|
15857
|
+
(0.18 +
|
|
15858
|
+
tentacleInfluence.core *
|
|
15859
|
+
(0.38 +
|
|
15860
|
+
tentacleInfluence.lengthScale * 0.22 +
|
|
15861
|
+
(morphologyProfile.tentacles.flowLengthScale - 1) * 0.08));
|
|
15862
|
+
return {
|
|
15863
|
+
x: Math.sin(effectiveLongitude) * planarRadiusX +
|
|
15864
|
+
tentacleWave * radiusX * (0.052 + tipBlend * 0.05),
|
|
15865
|
+
y: Math.sin(latitude) * radiusY * (1 + upperBlend * 0.12) -
|
|
15866
|
+
upperBlend * radiusY * 0.1 +
|
|
15867
|
+
lowerDrop +
|
|
15868
|
+
Math.sin(timeMs / 1420 + animationPhase + latitude * 1.6) * lowerBlend * radiusY * 0.018 +
|
|
15869
|
+
Math.cos(timeMs / 880 + tentacleInfluence.phase) *
|
|
15870
|
+
lowerBlend *
|
|
15871
|
+
tipBlend *
|
|
15872
|
+
tentacleInfluence.core *
|
|
15873
|
+
radiusY *
|
|
15874
|
+
0.034,
|
|
15875
|
+
z: Math.cos(effectiveLongitude) * planarRadiusZ +
|
|
15876
|
+
Math.cos(timeMs / 980 + tentacleInfluence.phase + verticalProgress) *
|
|
15877
|
+
lowerBlend *
|
|
15878
|
+
tentacleInfluence.core *
|
|
15879
|
+
radiusZ *
|
|
15880
|
+
0.04,
|
|
15881
|
+
};
|
|
15882
|
+
}
|
|
15883
|
+
/**
|
|
15884
|
+
* Blends nearby seeded tentacle profiles at one mesh longitude.
|
|
15885
|
+
*
|
|
15886
|
+
* @private helper of `octopus3d3AvatarVisual`
|
|
15887
|
+
*/
|
|
15888
|
+
function resolveContinuousTentacleInfluence(options, longitude) {
|
|
15889
|
+
let totalWeight = 0;
|
|
15890
|
+
let weightedSin = 0;
|
|
15891
|
+
let weightedCos = 0;
|
|
15892
|
+
let weightedWidthScale = 0;
|
|
15893
|
+
let weightedLengthScale = 0;
|
|
15894
|
+
let weightedSwayScale = 0;
|
|
15895
|
+
let weightedDepthScale = 0;
|
|
15896
|
+
let weightedPhase = 0;
|
|
15897
|
+
for (const tentacleProfile of options.tentacleProfiles) {
|
|
15898
|
+
const distance = Math.abs(resolveSignedAngularDistance(longitude, tentacleProfile.centerLongitude));
|
|
15899
|
+
const width = 0.2 * tentacleProfile.widthScale;
|
|
15900
|
+
const weight = Math.exp(-(distance * distance) / (width * width));
|
|
15901
|
+
totalWeight += weight;
|
|
15902
|
+
weightedSin += Math.sin(tentacleProfile.centerLongitude) * weight;
|
|
15903
|
+
weightedCos += Math.cos(tentacleProfile.centerLongitude) * weight;
|
|
15904
|
+
weightedWidthScale += tentacleProfile.widthScale * weight;
|
|
15905
|
+
weightedLengthScale += tentacleProfile.lengthScale * weight;
|
|
15906
|
+
weightedSwayScale += tentacleProfile.swayScale * weight;
|
|
15907
|
+
weightedDepthScale += tentacleProfile.depthScale * weight;
|
|
15908
|
+
weightedPhase += tentacleProfile.phase * weight;
|
|
15909
|
+
}
|
|
15910
|
+
if (totalWeight < 0.0001) {
|
|
15911
|
+
return {
|
|
15912
|
+
core: 0,
|
|
15913
|
+
centerLongitude: longitude,
|
|
15914
|
+
widthScale: 1,
|
|
15915
|
+
lengthScale: 1,
|
|
15916
|
+
swayScale: 1,
|
|
15917
|
+
depthScale: 1,
|
|
15918
|
+
phase: 0,
|
|
15919
|
+
};
|
|
15920
|
+
}
|
|
15921
|
+
return {
|
|
15922
|
+
core: clampNumber$1(totalWeight, 0, 1),
|
|
15923
|
+
centerLongitude: Math.atan2(weightedSin / totalWeight, weightedCos / totalWeight),
|
|
15924
|
+
widthScale: weightedWidthScale / totalWeight,
|
|
15925
|
+
lengthScale: weightedLengthScale / totalWeight,
|
|
15926
|
+
swayScale: weightedSwayScale / totalWeight,
|
|
15927
|
+
depthScale: weightedDepthScale / totalWeight,
|
|
15928
|
+
phase: weightedPhase / totalWeight,
|
|
15929
|
+
};
|
|
15930
|
+
}
|
|
15931
|
+
/**
|
|
15932
|
+
* Resolves the soft lower wave that makes the continuous mesh read as a set of tentacles.
|
|
15933
|
+
*
|
|
15934
|
+
* @private helper of `octopus3d3AvatarVisual`
|
|
15935
|
+
*/
|
|
15936
|
+
function resolveContinuousLobeWave(options, longitude) {
|
|
15937
|
+
const { morphologyProfile, animationPhase, timeMs } = options;
|
|
15938
|
+
return (Math.cos(longitude * OCTOPUS_TENTACLE_COUNT + animationPhase + timeMs / (980 + morphologyProfile.body.lobeCount * 18)) +
|
|
15939
|
+
1) / 2;
|
|
15940
|
+
}
|
|
15941
|
+
/**
|
|
15942
|
+
* Resolves one base fill tone for a patch on the continuous octopus mesh.
|
|
15943
|
+
*
|
|
15944
|
+
* @private helper of `octopus3d3AvatarVisual`
|
|
15945
|
+
*/
|
|
15946
|
+
function resolveContinuousSurfacePatchFillStyle(palette, verticalProgress, forwardness, tentacleCore, lowerLobeWave) {
|
|
15947
|
+
const tonalProgress = clampNumber$1(verticalProgress + lowerLobeWave * 0.1 + tentacleCore * 0.08 - forwardness * 0.08, 0, 1);
|
|
15948
|
+
if (tonalProgress < 0.14) {
|
|
15949
|
+
return palette.highlight;
|
|
15950
|
+
}
|
|
15951
|
+
if (tonalProgress < 0.32) {
|
|
15952
|
+
return palette.secondary;
|
|
15953
|
+
}
|
|
15954
|
+
if (tonalProgress < 0.72) {
|
|
15955
|
+
return forwardness > 0.55 ? palette.secondary : palette.primary;
|
|
15956
|
+
}
|
|
15957
|
+
return tentacleCore > 0.44 ? `${palette.primary}f4` : `${palette.shadow}ee`;
|
|
15958
|
+
}
|
|
15959
|
+
/**
|
|
15960
|
+
* Draws one projected mesh patch with soft shading and a subtle edge.
|
|
15961
|
+
*
|
|
15962
|
+
* @private helper of `octopus3d3AvatarVisual`
|
|
15963
|
+
*/
|
|
15964
|
+
function drawContinuousSurfacePatch(context, surfacePatch) {
|
|
15965
|
+
drawProjectedQuad(context, surfacePatch.corners, surfacePatch.fillStyle);
|
|
15966
|
+
if (surfacePatch.lightIntensity > 0) {
|
|
15967
|
+
drawProjectedQuad(context, surfacePatch.corners, `rgba(255, 255, 255, ${0.18 * surfacePatch.lightIntensity})`);
|
|
15968
|
+
}
|
|
15969
|
+
else if (surfacePatch.lightIntensity < 0) {
|
|
15970
|
+
drawProjectedQuad(context, surfacePatch.corners, `rgba(0, 0, 0, ${0.25 * Math.abs(surfacePatch.lightIntensity)})`);
|
|
15971
|
+
}
|
|
15972
|
+
context.save();
|
|
15973
|
+
context.beginPath();
|
|
15974
|
+
context.moveTo(surfacePatch.corners[0].x, surfacePatch.corners[0].y);
|
|
15975
|
+
for (let cornerIndex = 1; cornerIndex < surfacePatch.corners.length; cornerIndex++) {
|
|
15976
|
+
context.lineTo(surfacePatch.corners[cornerIndex].x, surfacePatch.corners[cornerIndex].y);
|
|
15977
|
+
}
|
|
15978
|
+
context.closePath();
|
|
15979
|
+
context.strokeStyle = surfacePatch.outlineColor;
|
|
15980
|
+
context.lineWidth = Math.max(0.7, getProjectedQuadPerimeter(surfacePatch.corners) * 0.0032);
|
|
15981
|
+
context.lineJoin = 'round';
|
|
15982
|
+
context.stroke();
|
|
15983
|
+
context.restore();
|
|
15984
|
+
}
|
|
15985
|
+
/**
|
|
15986
|
+
* Draws projected mantle-current lines on the front of the mesh.
|
|
15987
|
+
*
|
|
15988
|
+
* @private helper of `octopus3d3AvatarVisual`
|
|
15989
|
+
*/
|
|
15990
|
+
function drawProjectedSurfaceCurrents(options) {
|
|
15991
|
+
const { context, surfaceOptions, center, rotationX, rotationY, sceneCenterX, sceneCenterY, size, palette, morphologyProfile, timeMs, animationPhase, } = options;
|
|
15992
|
+
const currentCount = Math.min(6, morphologyProfile.details.mantleCurrentCount);
|
|
15993
|
+
const centerIndex = (currentCount - 1) / 2;
|
|
15994
|
+
context.save();
|
|
15995
|
+
context.lineCap = 'round';
|
|
15996
|
+
context.lineJoin = 'round';
|
|
15997
|
+
for (let currentIndex = 0; currentIndex < currentCount; currentIndex++) {
|
|
15998
|
+
const baseLongitude = (currentIndex - centerIndex) * 0.15;
|
|
15999
|
+
const projectedPoints = [];
|
|
16000
|
+
for (let sampleIndex = 0; sampleIndex < 8; sampleIndex++) {
|
|
16001
|
+
const progress = sampleIndex / 7;
|
|
16002
|
+
const latitude = -0.46 + progress * 0.74;
|
|
16003
|
+
const longitude = baseLongitude +
|
|
16004
|
+
Math.sin(timeMs / 1160 + animationPhase + currentIndex * 0.7 + progress * 2) * 0.035;
|
|
16005
|
+
const scenePoint = transformScenePoint(sampleContinuousOctopusSurfacePoint(surfaceOptions, latitude, longitude), center, rotationX, rotationY);
|
|
16006
|
+
if (scenePoint.z > center.z - size * 0.016) {
|
|
16007
|
+
projectedPoints.push(projectScenePoint(scenePoint, size, sceneCenterX, sceneCenterY));
|
|
16008
|
+
}
|
|
16009
|
+
}
|
|
16010
|
+
if (projectedPoints.length < 3) {
|
|
16011
|
+
continue;
|
|
16012
|
+
}
|
|
16013
|
+
context.beginPath();
|
|
16014
|
+
context.moveTo(projectedPoints[0].x, projectedPoints[0].y);
|
|
16015
|
+
for (const projectedPoint of projectedPoints.slice(1)) {
|
|
16016
|
+
context.lineTo(projectedPoint.x, projectedPoint.y);
|
|
16017
|
+
}
|
|
16018
|
+
context.strokeStyle = currentIndex % 2 === 0 ? `${palette.highlight}3d` : `${palette.accent}33`;
|
|
16019
|
+
context.lineWidth = size * (0.0055 + currentIndex * 0.00045);
|
|
16020
|
+
context.stroke();
|
|
16021
|
+
}
|
|
16022
|
+
context.restore();
|
|
16023
|
+
}
|
|
16024
|
+
/**
|
|
16025
|
+
* Draws small projected sucker highlights on the waving lower mesh lobes.
|
|
16026
|
+
*
|
|
16027
|
+
* @private helper of `octopus3d3AvatarVisual`
|
|
16028
|
+
*/
|
|
16029
|
+
function drawProjectedTentacleSuckers(options) {
|
|
16030
|
+
const { surfaceOptions, size } = options;
|
|
16031
|
+
const { timeMs } = surfaceOptions;
|
|
16032
|
+
for (const tentacleProfile of surfaceOptions.tentacleProfiles) {
|
|
16033
|
+
if (Math.cos(tentacleProfile.centerLongitude) < -0.12) {
|
|
16034
|
+
continue;
|
|
16035
|
+
}
|
|
16036
|
+
for (let suckerIndex = 0; suckerIndex < 3; suckerIndex++) {
|
|
16037
|
+
const latitude = 0.52 + suckerIndex * 0.14;
|
|
16038
|
+
const sideOffset = tentacleProfile.suckerSide * (0.035 + suckerIndex * 0.012) * tentacleProfile.widthScale;
|
|
16039
|
+
const waveOffset = Math.sin(timeMs / 900 + tentacleProfile.phase + suckerIndex * 0.8) * 0.018;
|
|
16040
|
+
drawProjectedSurfaceSpot({
|
|
16041
|
+
...options,
|
|
16042
|
+
latitude,
|
|
16043
|
+
longitude: tentacleProfile.centerLongitude + sideOffset + waveOffset,
|
|
16044
|
+
radiusScale: size * (0.0065 - suckerIndex * 0.0007),
|
|
16045
|
+
});
|
|
16046
|
+
}
|
|
16047
|
+
}
|
|
16048
|
+
}
|
|
16049
|
+
/**
|
|
16050
|
+
* Draws one tiny projected surface spot by sampling local mesh tangents.
|
|
16051
|
+
*
|
|
16052
|
+
* @private helper of `octopus3d3AvatarVisual`
|
|
16053
|
+
*/
|
|
16054
|
+
function drawProjectedSurfaceSpot(options) {
|
|
16055
|
+
const { context, surfaceOptions, center, rotationX, rotationY, sceneCenterX, sceneCenterY, size, palette, latitude, longitude, radiusScale, } = options;
|
|
16056
|
+
const localCenter = sampleContinuousOctopusSurfacePoint(surfaceOptions, latitude, longitude);
|
|
16057
|
+
const localHorizontal = sampleContinuousOctopusSurfacePoint(surfaceOptions, latitude, longitude + 0.018);
|
|
16058
|
+
const localVertical = sampleContinuousOctopusSurfacePoint(surfaceOptions, latitude + 0.018, longitude);
|
|
16059
|
+
const sceneCenterPoint = transformScenePoint(localCenter, center, rotationX, rotationY);
|
|
16060
|
+
if (sceneCenterPoint.z <= center.z - size * 0.012) {
|
|
16061
|
+
return;
|
|
16062
|
+
}
|
|
16063
|
+
const projectedCenterPoint = projectScenePoint(sceneCenterPoint, size, sceneCenterX, sceneCenterY);
|
|
16064
|
+
const projectedHorizontalPoint = projectScenePoint(transformScenePoint(localHorizontal, center, rotationX, rotationY), size, sceneCenterX, sceneCenterY);
|
|
16065
|
+
const projectedVerticalPoint = projectScenePoint(transformScenePoint(localVertical, center, rotationX, rotationY), size, sceneCenterX, sceneCenterY);
|
|
16066
|
+
const horizontalRadius = clampNumber$1(Math.hypot(projectedHorizontalPoint.x - projectedCenterPoint.x, projectedHorizontalPoint.y - projectedCenterPoint.y) *
|
|
16067
|
+
radiusScale *
|
|
16068
|
+
0.74, size * 0.003, size * 0.018);
|
|
16069
|
+
const verticalRadius = clampNumber$1(Math.hypot(projectedVerticalPoint.x - projectedCenterPoint.x, projectedVerticalPoint.y - projectedCenterPoint.y) *
|
|
16070
|
+
radiusScale *
|
|
16071
|
+
0.52, size * 0.0024, size * 0.014);
|
|
16072
|
+
const rotation = Math.atan2(projectedHorizontalPoint.y - projectedCenterPoint.y, projectedHorizontalPoint.x - projectedCenterPoint.x);
|
|
16073
|
+
context.save();
|
|
16074
|
+
context.translate(projectedCenterPoint.x, projectedCenterPoint.y);
|
|
16075
|
+
context.rotate(rotation);
|
|
16076
|
+
context.beginPath();
|
|
16077
|
+
context.ellipse(0, 0, horizontalRadius, verticalRadius, 0, 0, Math.PI * 2);
|
|
16078
|
+
context.fillStyle = `${palette.highlight}73`;
|
|
16079
|
+
context.fill();
|
|
16080
|
+
context.strokeStyle = `${palette.highlight}99`;
|
|
16081
|
+
context.lineWidth = Math.max(0.7, size * 0.0028);
|
|
16082
|
+
context.stroke();
|
|
16083
|
+
context.restore();
|
|
16084
|
+
}
|
|
16085
|
+
/**
|
|
16086
|
+
* Resolves a signed angular distance from the source longitude to the target longitude.
|
|
16087
|
+
*
|
|
16088
|
+
* @private helper of `octopus3d3AvatarVisual`
|
|
16089
|
+
*/
|
|
16090
|
+
function resolveSignedAngularDistance(sourceLongitude, targetLongitude) {
|
|
16091
|
+
return Math.atan2(Math.sin(targetLongitude - sourceLongitude), Math.cos(targetLongitude - sourceLongitude));
|
|
16092
|
+
}
|
|
16093
|
+
/**
|
|
16094
|
+
* Smoothly maps a value between two bounds into `[0, 1]`.
|
|
16095
|
+
*
|
|
16096
|
+
* @private helper of `octopus3d3AvatarVisual`
|
|
16097
|
+
*/
|
|
16098
|
+
function smoothStep(edgeStart, edgeEnd, value) {
|
|
16099
|
+
const progress = clampNumber$1((value - edgeStart) / (edgeEnd - edgeStart), 0, 1);
|
|
16100
|
+
return progress * progress * (3 - 2 * progress);
|
|
16101
|
+
}
|
|
16102
|
+
|
|
15593
16103
|
/* eslint-disable no-magic-numbers */
|
|
15594
16104
|
/**
|
|
15595
16105
|
* Octopus avatar visual.
|
|
@@ -16360,6 +16870,7 @@ const AVATAR_VISUALS = [
|
|
|
16360
16870
|
octopus3AvatarVisual,
|
|
16361
16871
|
octopus3dAvatarVisual,
|
|
16362
16872
|
octopus3d2AvatarVisual,
|
|
16873
|
+
octopus3d3AvatarVisual,
|
|
16363
16874
|
asciiOctopusAvatarVisual,
|
|
16364
16875
|
minecraftAvatarVisual,
|
|
16365
16876
|
minecraft2AvatarVisual,
|