@promptbook/node 0.112.0-102 → 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/esm/src/version.d.ts +1 -1
- package/package.json +2 -2
- 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/umd/src/version.d.ts +1 -1
package/esm/index.es.js
CHANGED
|
@@ -35,7 +35,7 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
|
|
|
35
35
|
* @generated
|
|
36
36
|
* @see https://github.com/webgptorg/promptbook
|
|
37
37
|
*/
|
|
38
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.112.0-
|
|
38
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.112.0-104';
|
|
39
39
|
/**
|
|
40
40
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
41
41
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -17558,7 +17558,7 @@ function fillTextureRect(texture, x, y, width, height, color) {
|
|
|
17558
17558
|
*
|
|
17559
17559
|
* @private helper of `minecraft2AvatarVisual`
|
|
17560
17560
|
*/
|
|
17561
|
-
const LIGHT_DIRECTION$
|
|
17561
|
+
const LIGHT_DIRECTION$3 = normalizeVector3({
|
|
17562
17562
|
x: 0.4,
|
|
17563
17563
|
y: -0.65,
|
|
17564
17564
|
z: 0.92,
|
|
@@ -17770,7 +17770,7 @@ function resolveVisibleCuboidFaces(cuboid, size, sceneCenterX, sceneCenterY) {
|
|
|
17770
17770
|
corners: projectedCorners,
|
|
17771
17771
|
texture: faceDefinition.texture,
|
|
17772
17772
|
averageDepth: transformedCorners.reduce((depthSum, corner) => depthSum + corner.z, 0) / transformedCorners.length,
|
|
17773
|
-
lightIntensity: clampNumber$1(dotProduct3D(faceNormal, LIGHT_DIRECTION$
|
|
17773
|
+
lightIntensity: clampNumber$1(dotProduct3D(faceNormal, LIGHT_DIRECTION$3), -1, 1),
|
|
17774
17774
|
outlineColor: cuboid.outlineColor,
|
|
17775
17775
|
};
|
|
17776
17776
|
});
|
|
@@ -18961,7 +18961,7 @@ function formatAlphaHex(opacity) {
|
|
|
18961
18961
|
*
|
|
18962
18962
|
* @private helper of `octopus3dAvatarVisual`
|
|
18963
18963
|
*/
|
|
18964
|
-
const LIGHT_DIRECTION$
|
|
18964
|
+
const LIGHT_DIRECTION$2 = normalizeVector3({
|
|
18965
18965
|
x: 0.48,
|
|
18966
18966
|
y: -0.62,
|
|
18967
18967
|
z: 0.94,
|
|
@@ -19171,7 +19171,7 @@ function resolveVisibleEllipsoidPatches(options) {
|
|
|
19171
19171
|
corners: projectedCorners,
|
|
19172
19172
|
averageDepth: transformedCorners.reduce((depthSum, transformedCorner) => depthSum + transformedCorner.z, 0) /
|
|
19173
19173
|
transformedCorners.length,
|
|
19174
|
-
lightIntensity: clampNumber$1(dotProduct3D(surfaceNormal, LIGHT_DIRECTION$
|
|
19174
|
+
lightIntensity: clampNumber$1(dotProduct3D(surfaceNormal, LIGHT_DIRECTION$2), -1, 1),
|
|
19175
19175
|
fillStyle: resolveSurfacePatchFillStyle(palette, verticalProgress + verticalColorBias),
|
|
19176
19176
|
outlineColor,
|
|
19177
19177
|
});
|
|
@@ -19360,7 +19360,7 @@ function resolveEllipsoidSurfaceDepth(radiusX, radiusY, radiusZ, x, y) {
|
|
|
19360
19360
|
*
|
|
19361
19361
|
* @private helper of `octopus3d2AvatarVisual`
|
|
19362
19362
|
*/
|
|
19363
|
-
const LIGHT_DIRECTION = normalizeVector3({
|
|
19363
|
+
const LIGHT_DIRECTION$1 = normalizeVector3({
|
|
19364
19364
|
x: 0.38,
|
|
19365
19365
|
y: -0.6,
|
|
19366
19366
|
z: 0.98,
|
|
@@ -19509,7 +19509,7 @@ function resolveVisibleBlobbyOctopusPatches(options) {
|
|
|
19509
19509
|
corners: projectedCorners,
|
|
19510
19510
|
averageDepth: transformedCorners.reduce((depthSum, transformedCorner) => depthSum + transformedCorner.z, 0) /
|
|
19511
19511
|
transformedCorners.length,
|
|
19512
|
-
lightIntensity: clampNumber$1(dotProduct3D(surfaceNormal, LIGHT_DIRECTION), -1, 1),
|
|
19512
|
+
lightIntensity: clampNumber$1(dotProduct3D(surfaceNormal, LIGHT_DIRECTION$1), -1, 1),
|
|
19513
19513
|
fillStyle: resolveBlobbySurfacePatchFillStyle(palette, verticalProgress, Math.max(0, Math.cos(centerLongitude)), resolveLowerLobeWave(centerLongitude, morphologyProfile, animationPhase, timeMs)),
|
|
19514
19514
|
outlineColor: verticalProgress < 0.58 ? `${palette.highlight}73` : `${palette.shadow}8a`,
|
|
19515
19515
|
});
|
|
@@ -19609,6 +19609,516 @@ function drawBlobbySurfacePatch(context, surfacePatch) {
|
|
|
19609
19609
|
context.restore();
|
|
19610
19610
|
}
|
|
19611
19611
|
|
|
19612
|
+
/* eslint-disable no-magic-numbers */
|
|
19613
|
+
/**
|
|
19614
|
+
* Light direction used by the continuous octopus mesh shading.
|
|
19615
|
+
*
|
|
19616
|
+
* @private helper of `octopus3d3AvatarVisual`
|
|
19617
|
+
*/
|
|
19618
|
+
const LIGHT_DIRECTION = normalizeVector3({
|
|
19619
|
+
x: 0.34,
|
|
19620
|
+
y: -0.62,
|
|
19621
|
+
z: 1,
|
|
19622
|
+
});
|
|
19623
|
+
/**
|
|
19624
|
+
* Real-octopus tentacle count used by the continuous lower mesh.
|
|
19625
|
+
*
|
|
19626
|
+
* @private helper of `octopus3d3AvatarVisual`
|
|
19627
|
+
*/
|
|
19628
|
+
const OCTOPUS_TENTACLE_COUNT = 8;
|
|
19629
|
+
/**
|
|
19630
|
+
* Octopus 3D 3 avatar visual.
|
|
19631
|
+
*
|
|
19632
|
+
* @private built-in avatar visual
|
|
19633
|
+
*/
|
|
19634
|
+
const octopus3d3AvatarVisual = {
|
|
19635
|
+
id: 'octopus3d3',
|
|
19636
|
+
title: 'Octopus 3D 3',
|
|
19637
|
+
description: 'Cute continuous 3D octopus with a blobby single mesh, waving tentacle lobes, rich shading, and cursor-aware eyes.',
|
|
19638
|
+
isAnimated: true,
|
|
19639
|
+
supportsPointerTracking: true,
|
|
19640
|
+
render({ context, size, palette, createRandom, timeMs, interaction }) {
|
|
19641
|
+
const morphologyProfile = createOctopus3MorphologyProfile(createRandom);
|
|
19642
|
+
const animationRandom = createRandom('octopus3d3-animation-profile');
|
|
19643
|
+
const eyeRandom = createRandom('octopus3d3-eye-profile');
|
|
19644
|
+
const animationPhase = animationRandom() * Math.PI * 2;
|
|
19645
|
+
const tentacleProfiles = createContinuousTentacleProfiles(createRandom, morphologyProfile);
|
|
19646
|
+
const sceneCenterX = size * 0.5;
|
|
19647
|
+
const sceneCenterY = size * 0.535;
|
|
19648
|
+
const bob = Math.sin(timeMs / 960 + animationPhase) * size * 0.012;
|
|
19649
|
+
const meshCenter = {
|
|
19650
|
+
x: interaction.bodyOffsetX * size * 0.048 + size * morphologyProfile.body.centerXJitterRatio * 0.44,
|
|
19651
|
+
y: -size * 0.07 + interaction.bodyOffsetY * size * 0.026 + bob,
|
|
19652
|
+
z: interaction.intensity * size * 0.018,
|
|
19653
|
+
};
|
|
19654
|
+
const rotationY = -0.1 +
|
|
19655
|
+
Math.sin(timeMs / 2700 + animationPhase) * 0.035 +
|
|
19656
|
+
interaction.bodyOffsetX * 0.22 +
|
|
19657
|
+
interaction.gazeX * 0.88;
|
|
19658
|
+
const rotationX = -0.07 +
|
|
19659
|
+
Math.cos(timeMs / 3100 + animationPhase * 0.7) * 0.018 -
|
|
19660
|
+
interaction.bodyOffsetY * 0.08 -
|
|
19661
|
+
interaction.gazeY * 0.38;
|
|
19662
|
+
const surfaceOptions = {
|
|
19663
|
+
radiusX: size * morphologyProfile.body.bodyRadiusRatio * morphologyProfile.body.horizontalStretch * 1.1,
|
|
19664
|
+
radiusY: size * morphologyProfile.body.bodyRadiusRatio * morphologyProfile.body.verticalStretch * 1.08,
|
|
19665
|
+
radiusZ: size *
|
|
19666
|
+
morphologyProfile.body.bodyRadiusRatio *
|
|
19667
|
+
(1.02 + (morphologyProfile.body.horizontalStretch - 1) * 0.18),
|
|
19668
|
+
morphologyProfile,
|
|
19669
|
+
timeMs,
|
|
19670
|
+
animationPhase,
|
|
19671
|
+
tentacleProfiles,
|
|
19672
|
+
};
|
|
19673
|
+
const surfacePatches = resolveVisibleContinuousOctopusPatches({
|
|
19674
|
+
...surfaceOptions,
|
|
19675
|
+
center: meshCenter,
|
|
19676
|
+
rotationX,
|
|
19677
|
+
rotationY,
|
|
19678
|
+
sceneCenterX,
|
|
19679
|
+
sceneCenterY,
|
|
19680
|
+
size,
|
|
19681
|
+
palette,
|
|
19682
|
+
});
|
|
19683
|
+
const eyeLatitude = clampNumber$1(morphologyProfile.face.eyeCenterYOffsetRatio * 4.2 - 0.03, -0.22, 0.08);
|
|
19684
|
+
const eyeLongitude = clampNumber$1(morphologyProfile.face.eyeSpacingRatio * 3.1, 0.18, 0.32);
|
|
19685
|
+
const mouthLatitude = clampNumber$1(eyeLatitude + 0.2 + morphologyProfile.face.mouthYOffsetRatio, 0.08, 0.34);
|
|
19686
|
+
const mouthCenterLongitude = clampNumber$1(morphologyProfile.face.mouthCenterOffsetRatio * 5.6, -0.08, 0.08);
|
|
19687
|
+
const mouthHalfLongitude = clampNumber$1(eyeLongitude * 0.78, 0.15, 0.28);
|
|
19688
|
+
const mouthCurveLatitude = clampNumber$1(mouthLatitude + morphologyProfile.face.mouthCurveDepthRatio * 0.78, mouthLatitude + 0.03, 0.42);
|
|
19689
|
+
const eyeRadiusX = size * morphologyProfile.face.eyeRadiusXRatio * 0.76;
|
|
19690
|
+
const eyeRadiusY = eyeRadiusX * morphologyProfile.face.eyeHeightRatio * 0.9;
|
|
19691
|
+
drawAvatarFrame(context, size, palette);
|
|
19692
|
+
drawContinuousOctopusAtmosphere(context, size, palette, sceneCenterX, sceneCenterY, interaction, timeMs);
|
|
19693
|
+
drawContinuousOctopusShadow(context, size, palette, interaction, timeMs, morphologyProfile);
|
|
19694
|
+
for (const surfacePatch of surfacePatches.sort((firstSurfacePatch, secondSurfacePatch) => firstSurfacePatch.averageDepth - secondSurfacePatch.averageDepth)) {
|
|
19695
|
+
drawContinuousSurfacePatch(context, surfacePatch);
|
|
19696
|
+
}
|
|
19697
|
+
drawProjectedSurfaceCurrents({
|
|
19698
|
+
context,
|
|
19699
|
+
surfaceOptions,
|
|
19700
|
+
center: meshCenter,
|
|
19701
|
+
rotationX,
|
|
19702
|
+
rotationY,
|
|
19703
|
+
sceneCenterX,
|
|
19704
|
+
sceneCenterY,
|
|
19705
|
+
size,
|
|
19706
|
+
palette,
|
|
19707
|
+
morphologyProfile,
|
|
19708
|
+
timeMs,
|
|
19709
|
+
animationPhase,
|
|
19710
|
+
});
|
|
19711
|
+
drawProjectedTentacleSuckers({
|
|
19712
|
+
context,
|
|
19713
|
+
surfaceOptions,
|
|
19714
|
+
center: meshCenter,
|
|
19715
|
+
rotationX,
|
|
19716
|
+
rotationY,
|
|
19717
|
+
sceneCenterX,
|
|
19718
|
+
sceneCenterY,
|
|
19719
|
+
size,
|
|
19720
|
+
palette,
|
|
19721
|
+
});
|
|
19722
|
+
drawProjectedOrganicEye(context, sampleContinuousOctopusSurfacePoint(surfaceOptions, eyeLatitude, -eyeLongitude), eyeRadiusX, eyeRadiusY, meshCenter, rotationX, rotationY, sceneCenterX, sceneCenterY, size, palette, timeMs, animationPhase + eyeRandom() * 0.7, interaction, morphologyProfile.face.eyeStyle);
|
|
19723
|
+
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);
|
|
19724
|
+
drawProjectedOrganicMouth(context, [
|
|
19725
|
+
sampleContinuousOctopusSurfacePoint(surfaceOptions, mouthLatitude, mouthCenterLongitude - mouthHalfLongitude),
|
|
19726
|
+
sampleContinuousOctopusSurfacePoint(surfaceOptions, mouthCurveLatitude, mouthCenterLongitude),
|
|
19727
|
+
sampleContinuousOctopusSurfacePoint(surfaceOptions, mouthLatitude, mouthCenterLongitude + mouthHalfLongitude),
|
|
19728
|
+
], meshCenter, rotationX, rotationY, sceneCenterX, sceneCenterY, palette, size);
|
|
19729
|
+
},
|
|
19730
|
+
};
|
|
19731
|
+
/**
|
|
19732
|
+
* Creates seeded tentacle-lobe profiles around the visible lower octopus body.
|
|
19733
|
+
*
|
|
19734
|
+
* @private helper of `octopus3d3AvatarVisual`
|
|
19735
|
+
*/
|
|
19736
|
+
function createContinuousTentacleProfiles(createRandom, morphologyProfile) {
|
|
19737
|
+
return Array.from({ length: OCTOPUS_TENTACLE_COUNT }, (_, tentacleIndex) => {
|
|
19738
|
+
const tentacleRandom = createRandom(`octopus3d3-tentacle-${tentacleIndex}`);
|
|
19739
|
+
const progress = tentacleIndex / (OCTOPUS_TENTACLE_COUNT - 1);
|
|
19740
|
+
return {
|
|
19741
|
+
centerLongitude: -Math.PI * 0.86 +
|
|
19742
|
+
progress * Math.PI * 1.72 +
|
|
19743
|
+
(tentacleRandom() - 0.5) * (0.08 + morphologyProfile.tentacles.rootSpreadScale * 0.03),
|
|
19744
|
+
widthScale: 0.86 + tentacleRandom() * 0.34 + (morphologyProfile.tentacles.baseWidthScale - 1) * 0.16,
|
|
19745
|
+
lengthScale: 0.86 + tentacleRandom() * 0.36 + (morphologyProfile.tentacles.flowLengthScale - 1) * 0.22,
|
|
19746
|
+
swayScale: 0.82 + tentacleRandom() * 0.38 + (morphologyProfile.tentacles.swayScale - 1) * 0.2,
|
|
19747
|
+
depthScale: 0.86 + tentacleRandom() * 0.32 + (morphologyProfile.tentacles.tipReachScale - 1) * 0.2,
|
|
19748
|
+
phase: tentacleRandom() * Math.PI * 2,
|
|
19749
|
+
suckerSide: tentacleRandom() > 0.5 ? 1 : -1,
|
|
19750
|
+
};
|
|
19751
|
+
});
|
|
19752
|
+
}
|
|
19753
|
+
/**
|
|
19754
|
+
* Draws the soft underwater atmosphere behind the continuous octopus mesh.
|
|
19755
|
+
*
|
|
19756
|
+
* @private helper of `octopus3d3AvatarVisual`
|
|
19757
|
+
*/
|
|
19758
|
+
function drawContinuousOctopusAtmosphere(context, size, palette, sceneCenterX, sceneCenterY, interaction, timeMs) {
|
|
19759
|
+
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));
|
|
19760
|
+
glowGradient.addColorStop(0, `${palette.highlight}66`);
|
|
19761
|
+
glowGradient.addColorStop(0.34, `${palette.accent}2e`);
|
|
19762
|
+
glowGradient.addColorStop(1, `${palette.highlight}00`);
|
|
19763
|
+
context.fillStyle = glowGradient;
|
|
19764
|
+
context.fillRect(0, 0, size, size);
|
|
19765
|
+
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);
|
|
19766
|
+
lowerGradient.addColorStop(0, `${palette.secondary}25`);
|
|
19767
|
+
lowerGradient.addColorStop(1, `${palette.secondary}00`);
|
|
19768
|
+
context.fillStyle = lowerGradient;
|
|
19769
|
+
context.fillRect(0, 0, size, size);
|
|
19770
|
+
}
|
|
19771
|
+
/**
|
|
19772
|
+
* Draws the soft lower shadow that anchors the octopus in the avatar frame.
|
|
19773
|
+
*
|
|
19774
|
+
* @private helper of `octopus3d3AvatarVisual`
|
|
19775
|
+
*/
|
|
19776
|
+
function drawContinuousOctopusShadow(context, size, palette, interaction, timeMs, morphologyProfile) {
|
|
19777
|
+
context.save();
|
|
19778
|
+
context.fillStyle = `${palette.shadow}66`;
|
|
19779
|
+
context.filter = `blur(${size * 0.025}px)`;
|
|
19780
|
+
context.beginPath();
|
|
19781
|
+
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);
|
|
19782
|
+
context.fill();
|
|
19783
|
+
context.restore();
|
|
19784
|
+
}
|
|
19785
|
+
/**
|
|
19786
|
+
* Resolves visible projected patches for the continuous octopus mesh.
|
|
19787
|
+
*
|
|
19788
|
+
* @private helper of `octopus3d3AvatarVisual`
|
|
19789
|
+
*/
|
|
19790
|
+
function resolveVisibleContinuousOctopusPatches(options) {
|
|
19791
|
+
const { center, rotationX, rotationY, sceneCenterX, sceneCenterY, size, palette } = options;
|
|
19792
|
+
const latitudePatchCount = 16;
|
|
19793
|
+
const longitudePatchCount = 40;
|
|
19794
|
+
const surfacePatches = [];
|
|
19795
|
+
for (let latitudeIndex = 0; latitudeIndex < latitudePatchCount; latitudeIndex++) {
|
|
19796
|
+
const startLatitude = -Math.PI / 2 + (latitudeIndex / latitudePatchCount) * Math.PI;
|
|
19797
|
+
const endLatitude = -Math.PI / 2 + ((latitudeIndex + 1) / latitudePatchCount) * Math.PI;
|
|
19798
|
+
const centerLatitude = (startLatitude + endLatitude) / 2;
|
|
19799
|
+
const verticalProgress = (Math.sin(centerLatitude) + 1) / 2;
|
|
19800
|
+
for (let longitudeIndex = 0; longitudeIndex < longitudePatchCount; longitudeIndex++) {
|
|
19801
|
+
const startLongitude = -Math.PI + (longitudeIndex / longitudePatchCount) * Math.PI * 2;
|
|
19802
|
+
const endLongitude = -Math.PI + ((longitudeIndex + 1) / longitudePatchCount) * Math.PI * 2;
|
|
19803
|
+
const centerLongitude = (startLongitude + endLongitude) / 2;
|
|
19804
|
+
const localCorners = [
|
|
19805
|
+
sampleContinuousOctopusSurfacePoint(options, startLatitude, startLongitude),
|
|
19806
|
+
sampleContinuousOctopusSurfacePoint(options, startLatitude, endLongitude),
|
|
19807
|
+
sampleContinuousOctopusSurfacePoint(options, endLatitude, endLongitude),
|
|
19808
|
+
sampleContinuousOctopusSurfacePoint(options, endLatitude, startLongitude),
|
|
19809
|
+
];
|
|
19810
|
+
const transformedCorners = localCorners.map((localCorner) => transformScenePoint(localCorner, center, rotationX, rotationY));
|
|
19811
|
+
const surfaceNormal = normalizeVector3(crossProduct3D(subtractPoint3D(transformedCorners[1], transformedCorners[0]), subtractPoint3D(transformedCorners[2], transformedCorners[0])));
|
|
19812
|
+
if (surfaceNormal.z <= 0.008) {
|
|
19813
|
+
continue;
|
|
19814
|
+
}
|
|
19815
|
+
const projectedCorners = transformedCorners.map((transformedCorner) => projectScenePoint(transformedCorner, size, sceneCenterX, sceneCenterY));
|
|
19816
|
+
const tentacleInfluence = resolveContinuousTentacleInfluence(options, centerLongitude);
|
|
19817
|
+
const lowerLobeWave = resolveContinuousLobeWave(options, centerLongitude);
|
|
19818
|
+
surfacePatches.push({
|
|
19819
|
+
corners: projectedCorners,
|
|
19820
|
+
averageDepth: transformedCorners.reduce((depthSum, transformedCorner) => depthSum + transformedCorner.z, 0) /
|
|
19821
|
+
transformedCorners.length,
|
|
19822
|
+
lightIntensity: clampNumber$1(dotProduct3D(surfaceNormal, LIGHT_DIRECTION), -1, 1),
|
|
19823
|
+
fillStyle: resolveContinuousSurfacePatchFillStyle(palette, verticalProgress, Math.max(0, Math.cos(centerLongitude)), tentacleInfluence.core, lowerLobeWave),
|
|
19824
|
+
outlineColor: verticalProgress < 0.54 ? `${palette.highlight}69` : `${palette.shadow}78`,
|
|
19825
|
+
});
|
|
19826
|
+
}
|
|
19827
|
+
}
|
|
19828
|
+
return surfacePatches;
|
|
19829
|
+
}
|
|
19830
|
+
/**
|
|
19831
|
+
* Samples one point on the continuous Octopus 3D 3 surface.
|
|
19832
|
+
*
|
|
19833
|
+
* The lower hemisphere is pulled into eight seeded waving lobes, so the portrait reads as
|
|
19834
|
+
* tentacled while still being rendered as one connected blobby mesh.
|
|
19835
|
+
*
|
|
19836
|
+
* @private helper of `octopus3d3AvatarVisual`
|
|
19837
|
+
*/
|
|
19838
|
+
function sampleContinuousOctopusSurfacePoint(options, latitude, longitude) {
|
|
19839
|
+
const { radiusX, radiusY, radiusZ, morphologyProfile, timeMs, animationPhase } = options;
|
|
19840
|
+
const cosineLatitude = Math.max(0, Math.cos(latitude));
|
|
19841
|
+
const verticalProgress = (Math.sin(latitude) + 1) / 2;
|
|
19842
|
+
const upperBlend = Math.pow(1 - verticalProgress, 1.28);
|
|
19843
|
+
const lowerBlend = smoothStep(0.38, 1, verticalProgress);
|
|
19844
|
+
const tipBlend = smoothStep(0.68, 1, verticalProgress);
|
|
19845
|
+
const tentacleInfluence = resolveContinuousTentacleInfluence(options, longitude);
|
|
19846
|
+
const centerPull = resolveSignedAngularDistance(longitude, tentacleInfluence.centerLongitude);
|
|
19847
|
+
const effectiveLongitude = longitude + centerPull * lowerBlend * tentacleInfluence.core * (0.24 + tipBlend * 0.2);
|
|
19848
|
+
const lowerLobeWave = resolveContinuousLobeWave(options, longitude);
|
|
19849
|
+
const mantleRipple = Math.sin(longitude * morphologyProfile.body.lobeCount +
|
|
19850
|
+
animationPhase * 0.6 +
|
|
19851
|
+
timeMs / (1750 + morphologyProfile.body.lobeCount * 30)) *
|
|
19852
|
+
(0.018 + morphologyProfile.body.wobbleAmplitudeRatio * 0.8) *
|
|
19853
|
+
(0.3 + lowerBlend * 0.7);
|
|
19854
|
+
const tentacleWave = Math.sin(timeMs / 760 + tentacleInfluence.phase + verticalProgress * 2.4) *
|
|
19855
|
+
lowerBlend *
|
|
19856
|
+
tentacleInfluence.core *
|
|
19857
|
+
tentacleInfluence.swayScale;
|
|
19858
|
+
const horizontalScale = 1.04 +
|
|
19859
|
+
mantleRipple +
|
|
19860
|
+
lowerBlend * (0.16 + (morphologyProfile.tentacles.rootSpreadScale - 1) * 0.1) +
|
|
19861
|
+
lowerBlend * tentacleInfluence.core * (0.2 + lowerLobeWave * 0.12) -
|
|
19862
|
+
upperBlend * 0.08;
|
|
19863
|
+
const depthScale = 1.06 +
|
|
19864
|
+
upperBlend * 0.16 +
|
|
19865
|
+
Math.max(0, Math.cos(effectiveLongitude)) * 0.1 +
|
|
19866
|
+
lowerBlend * tentacleInfluence.core * (0.1 + tentacleInfluence.depthScale * 0.06) -
|
|
19867
|
+
Math.max(0, -Math.cos(effectiveLongitude)) * 0.05;
|
|
19868
|
+
const tentacleTubeRadius = lowerBlend *
|
|
19869
|
+
tentacleInfluence.core *
|
|
19870
|
+
(0.11 + tipBlend * 0.06 + tentacleInfluence.widthScale * 0.025) *
|
|
19871
|
+
radiusX;
|
|
19872
|
+
const planarRadiusX = cosineLatitude * radiusX * horizontalScale + tentacleTubeRadius;
|
|
19873
|
+
const planarRadiusZ = cosineLatitude * radiusZ * depthScale + tentacleTubeRadius * 0.72;
|
|
19874
|
+
const lowerDrop = lowerBlend *
|
|
19875
|
+
radiusY *
|
|
19876
|
+
(0.18 +
|
|
19877
|
+
tentacleInfluence.core *
|
|
19878
|
+
(0.38 +
|
|
19879
|
+
tentacleInfluence.lengthScale * 0.22 +
|
|
19880
|
+
(morphologyProfile.tentacles.flowLengthScale - 1) * 0.08));
|
|
19881
|
+
return {
|
|
19882
|
+
x: Math.sin(effectiveLongitude) * planarRadiusX +
|
|
19883
|
+
tentacleWave * radiusX * (0.052 + tipBlend * 0.05),
|
|
19884
|
+
y: Math.sin(latitude) * radiusY * (1 + upperBlend * 0.12) -
|
|
19885
|
+
upperBlend * radiusY * 0.1 +
|
|
19886
|
+
lowerDrop +
|
|
19887
|
+
Math.sin(timeMs / 1420 + animationPhase + latitude * 1.6) * lowerBlend * radiusY * 0.018 +
|
|
19888
|
+
Math.cos(timeMs / 880 + tentacleInfluence.phase) *
|
|
19889
|
+
lowerBlend *
|
|
19890
|
+
tipBlend *
|
|
19891
|
+
tentacleInfluence.core *
|
|
19892
|
+
radiusY *
|
|
19893
|
+
0.034,
|
|
19894
|
+
z: Math.cos(effectiveLongitude) * planarRadiusZ +
|
|
19895
|
+
Math.cos(timeMs / 980 + tentacleInfluence.phase + verticalProgress) *
|
|
19896
|
+
lowerBlend *
|
|
19897
|
+
tentacleInfluence.core *
|
|
19898
|
+
radiusZ *
|
|
19899
|
+
0.04,
|
|
19900
|
+
};
|
|
19901
|
+
}
|
|
19902
|
+
/**
|
|
19903
|
+
* Blends nearby seeded tentacle profiles at one mesh longitude.
|
|
19904
|
+
*
|
|
19905
|
+
* @private helper of `octopus3d3AvatarVisual`
|
|
19906
|
+
*/
|
|
19907
|
+
function resolveContinuousTentacleInfluence(options, longitude) {
|
|
19908
|
+
let totalWeight = 0;
|
|
19909
|
+
let weightedSin = 0;
|
|
19910
|
+
let weightedCos = 0;
|
|
19911
|
+
let weightedWidthScale = 0;
|
|
19912
|
+
let weightedLengthScale = 0;
|
|
19913
|
+
let weightedSwayScale = 0;
|
|
19914
|
+
let weightedDepthScale = 0;
|
|
19915
|
+
let weightedPhase = 0;
|
|
19916
|
+
for (const tentacleProfile of options.tentacleProfiles) {
|
|
19917
|
+
const distance = Math.abs(resolveSignedAngularDistance(longitude, tentacleProfile.centerLongitude));
|
|
19918
|
+
const width = 0.2 * tentacleProfile.widthScale;
|
|
19919
|
+
const weight = Math.exp(-(distance * distance) / (width * width));
|
|
19920
|
+
totalWeight += weight;
|
|
19921
|
+
weightedSin += Math.sin(tentacleProfile.centerLongitude) * weight;
|
|
19922
|
+
weightedCos += Math.cos(tentacleProfile.centerLongitude) * weight;
|
|
19923
|
+
weightedWidthScale += tentacleProfile.widthScale * weight;
|
|
19924
|
+
weightedLengthScale += tentacleProfile.lengthScale * weight;
|
|
19925
|
+
weightedSwayScale += tentacleProfile.swayScale * weight;
|
|
19926
|
+
weightedDepthScale += tentacleProfile.depthScale * weight;
|
|
19927
|
+
weightedPhase += tentacleProfile.phase * weight;
|
|
19928
|
+
}
|
|
19929
|
+
if (totalWeight < 0.0001) {
|
|
19930
|
+
return {
|
|
19931
|
+
core: 0,
|
|
19932
|
+
centerLongitude: longitude,
|
|
19933
|
+
widthScale: 1,
|
|
19934
|
+
lengthScale: 1,
|
|
19935
|
+
swayScale: 1,
|
|
19936
|
+
depthScale: 1,
|
|
19937
|
+
phase: 0,
|
|
19938
|
+
};
|
|
19939
|
+
}
|
|
19940
|
+
return {
|
|
19941
|
+
core: clampNumber$1(totalWeight, 0, 1),
|
|
19942
|
+
centerLongitude: Math.atan2(weightedSin / totalWeight, weightedCos / totalWeight),
|
|
19943
|
+
widthScale: weightedWidthScale / totalWeight,
|
|
19944
|
+
lengthScale: weightedLengthScale / totalWeight,
|
|
19945
|
+
swayScale: weightedSwayScale / totalWeight,
|
|
19946
|
+
depthScale: weightedDepthScale / totalWeight,
|
|
19947
|
+
phase: weightedPhase / totalWeight,
|
|
19948
|
+
};
|
|
19949
|
+
}
|
|
19950
|
+
/**
|
|
19951
|
+
* Resolves the soft lower wave that makes the continuous mesh read as a set of tentacles.
|
|
19952
|
+
*
|
|
19953
|
+
* @private helper of `octopus3d3AvatarVisual`
|
|
19954
|
+
*/
|
|
19955
|
+
function resolveContinuousLobeWave(options, longitude) {
|
|
19956
|
+
const { morphologyProfile, animationPhase, timeMs } = options;
|
|
19957
|
+
return (Math.cos(longitude * OCTOPUS_TENTACLE_COUNT + animationPhase + timeMs / (980 + morphologyProfile.body.lobeCount * 18)) +
|
|
19958
|
+
1) / 2;
|
|
19959
|
+
}
|
|
19960
|
+
/**
|
|
19961
|
+
* Resolves one base fill tone for a patch on the continuous octopus mesh.
|
|
19962
|
+
*
|
|
19963
|
+
* @private helper of `octopus3d3AvatarVisual`
|
|
19964
|
+
*/
|
|
19965
|
+
function resolveContinuousSurfacePatchFillStyle(palette, verticalProgress, forwardness, tentacleCore, lowerLobeWave) {
|
|
19966
|
+
const tonalProgress = clampNumber$1(verticalProgress + lowerLobeWave * 0.1 + tentacleCore * 0.08 - forwardness * 0.08, 0, 1);
|
|
19967
|
+
if (tonalProgress < 0.14) {
|
|
19968
|
+
return palette.highlight;
|
|
19969
|
+
}
|
|
19970
|
+
if (tonalProgress < 0.32) {
|
|
19971
|
+
return palette.secondary;
|
|
19972
|
+
}
|
|
19973
|
+
if (tonalProgress < 0.72) {
|
|
19974
|
+
return forwardness > 0.55 ? palette.secondary : palette.primary;
|
|
19975
|
+
}
|
|
19976
|
+
return tentacleCore > 0.44 ? `${palette.primary}f4` : `${palette.shadow}ee`;
|
|
19977
|
+
}
|
|
19978
|
+
/**
|
|
19979
|
+
* Draws one projected mesh patch with soft shading and a subtle edge.
|
|
19980
|
+
*
|
|
19981
|
+
* @private helper of `octopus3d3AvatarVisual`
|
|
19982
|
+
*/
|
|
19983
|
+
function drawContinuousSurfacePatch(context, surfacePatch) {
|
|
19984
|
+
drawProjectedQuad(context, surfacePatch.corners, surfacePatch.fillStyle);
|
|
19985
|
+
if (surfacePatch.lightIntensity > 0) {
|
|
19986
|
+
drawProjectedQuad(context, surfacePatch.corners, `rgba(255, 255, 255, ${0.18 * surfacePatch.lightIntensity})`);
|
|
19987
|
+
}
|
|
19988
|
+
else if (surfacePatch.lightIntensity < 0) {
|
|
19989
|
+
drawProjectedQuad(context, surfacePatch.corners, `rgba(0, 0, 0, ${0.25 * Math.abs(surfacePatch.lightIntensity)})`);
|
|
19990
|
+
}
|
|
19991
|
+
context.save();
|
|
19992
|
+
context.beginPath();
|
|
19993
|
+
context.moveTo(surfacePatch.corners[0].x, surfacePatch.corners[0].y);
|
|
19994
|
+
for (let cornerIndex = 1; cornerIndex < surfacePatch.corners.length; cornerIndex++) {
|
|
19995
|
+
context.lineTo(surfacePatch.corners[cornerIndex].x, surfacePatch.corners[cornerIndex].y);
|
|
19996
|
+
}
|
|
19997
|
+
context.closePath();
|
|
19998
|
+
context.strokeStyle = surfacePatch.outlineColor;
|
|
19999
|
+
context.lineWidth = Math.max(0.7, getProjectedQuadPerimeter(surfacePatch.corners) * 0.0032);
|
|
20000
|
+
context.lineJoin = 'round';
|
|
20001
|
+
context.stroke();
|
|
20002
|
+
context.restore();
|
|
20003
|
+
}
|
|
20004
|
+
/**
|
|
20005
|
+
* Draws projected mantle-current lines on the front of the mesh.
|
|
20006
|
+
*
|
|
20007
|
+
* @private helper of `octopus3d3AvatarVisual`
|
|
20008
|
+
*/
|
|
20009
|
+
function drawProjectedSurfaceCurrents(options) {
|
|
20010
|
+
const { context, surfaceOptions, center, rotationX, rotationY, sceneCenterX, sceneCenterY, size, palette, morphologyProfile, timeMs, animationPhase, } = options;
|
|
20011
|
+
const currentCount = Math.min(6, morphologyProfile.details.mantleCurrentCount);
|
|
20012
|
+
const centerIndex = (currentCount - 1) / 2;
|
|
20013
|
+
context.save();
|
|
20014
|
+
context.lineCap = 'round';
|
|
20015
|
+
context.lineJoin = 'round';
|
|
20016
|
+
for (let currentIndex = 0; currentIndex < currentCount; currentIndex++) {
|
|
20017
|
+
const baseLongitude = (currentIndex - centerIndex) * 0.15;
|
|
20018
|
+
const projectedPoints = [];
|
|
20019
|
+
for (let sampleIndex = 0; sampleIndex < 8; sampleIndex++) {
|
|
20020
|
+
const progress = sampleIndex / 7;
|
|
20021
|
+
const latitude = -0.46 + progress * 0.74;
|
|
20022
|
+
const longitude = baseLongitude +
|
|
20023
|
+
Math.sin(timeMs / 1160 + animationPhase + currentIndex * 0.7 + progress * 2) * 0.035;
|
|
20024
|
+
const scenePoint = transformScenePoint(sampleContinuousOctopusSurfacePoint(surfaceOptions, latitude, longitude), center, rotationX, rotationY);
|
|
20025
|
+
if (scenePoint.z > center.z - size * 0.016) {
|
|
20026
|
+
projectedPoints.push(projectScenePoint(scenePoint, size, sceneCenterX, sceneCenterY));
|
|
20027
|
+
}
|
|
20028
|
+
}
|
|
20029
|
+
if (projectedPoints.length < 3) {
|
|
20030
|
+
continue;
|
|
20031
|
+
}
|
|
20032
|
+
context.beginPath();
|
|
20033
|
+
context.moveTo(projectedPoints[0].x, projectedPoints[0].y);
|
|
20034
|
+
for (const projectedPoint of projectedPoints.slice(1)) {
|
|
20035
|
+
context.lineTo(projectedPoint.x, projectedPoint.y);
|
|
20036
|
+
}
|
|
20037
|
+
context.strokeStyle = currentIndex % 2 === 0 ? `${palette.highlight}3d` : `${palette.accent}33`;
|
|
20038
|
+
context.lineWidth = size * (0.0055 + currentIndex * 0.00045);
|
|
20039
|
+
context.stroke();
|
|
20040
|
+
}
|
|
20041
|
+
context.restore();
|
|
20042
|
+
}
|
|
20043
|
+
/**
|
|
20044
|
+
* Draws small projected sucker highlights on the waving lower mesh lobes.
|
|
20045
|
+
*
|
|
20046
|
+
* @private helper of `octopus3d3AvatarVisual`
|
|
20047
|
+
*/
|
|
20048
|
+
function drawProjectedTentacleSuckers(options) {
|
|
20049
|
+
const { surfaceOptions, size } = options;
|
|
20050
|
+
const { timeMs } = surfaceOptions;
|
|
20051
|
+
for (const tentacleProfile of surfaceOptions.tentacleProfiles) {
|
|
20052
|
+
if (Math.cos(tentacleProfile.centerLongitude) < -0.12) {
|
|
20053
|
+
continue;
|
|
20054
|
+
}
|
|
20055
|
+
for (let suckerIndex = 0; suckerIndex < 3; suckerIndex++) {
|
|
20056
|
+
const latitude = 0.52 + suckerIndex * 0.14;
|
|
20057
|
+
const sideOffset = tentacleProfile.suckerSide * (0.035 + suckerIndex * 0.012) * tentacleProfile.widthScale;
|
|
20058
|
+
const waveOffset = Math.sin(timeMs / 900 + tentacleProfile.phase + suckerIndex * 0.8) * 0.018;
|
|
20059
|
+
drawProjectedSurfaceSpot({
|
|
20060
|
+
...options,
|
|
20061
|
+
latitude,
|
|
20062
|
+
longitude: tentacleProfile.centerLongitude + sideOffset + waveOffset,
|
|
20063
|
+
radiusScale: size * (0.0065 - suckerIndex * 0.0007),
|
|
20064
|
+
});
|
|
20065
|
+
}
|
|
20066
|
+
}
|
|
20067
|
+
}
|
|
20068
|
+
/**
|
|
20069
|
+
* Draws one tiny projected surface spot by sampling local mesh tangents.
|
|
20070
|
+
*
|
|
20071
|
+
* @private helper of `octopus3d3AvatarVisual`
|
|
20072
|
+
*/
|
|
20073
|
+
function drawProjectedSurfaceSpot(options) {
|
|
20074
|
+
const { context, surfaceOptions, center, rotationX, rotationY, sceneCenterX, sceneCenterY, size, palette, latitude, longitude, radiusScale, } = options;
|
|
20075
|
+
const localCenter = sampleContinuousOctopusSurfacePoint(surfaceOptions, latitude, longitude);
|
|
20076
|
+
const localHorizontal = sampleContinuousOctopusSurfacePoint(surfaceOptions, latitude, longitude + 0.018);
|
|
20077
|
+
const localVertical = sampleContinuousOctopusSurfacePoint(surfaceOptions, latitude + 0.018, longitude);
|
|
20078
|
+
const sceneCenterPoint = transformScenePoint(localCenter, center, rotationX, rotationY);
|
|
20079
|
+
if (sceneCenterPoint.z <= center.z - size * 0.012) {
|
|
20080
|
+
return;
|
|
20081
|
+
}
|
|
20082
|
+
const projectedCenterPoint = projectScenePoint(sceneCenterPoint, size, sceneCenterX, sceneCenterY);
|
|
20083
|
+
const projectedHorizontalPoint = projectScenePoint(transformScenePoint(localHorizontal, center, rotationX, rotationY), size, sceneCenterX, sceneCenterY);
|
|
20084
|
+
const projectedVerticalPoint = projectScenePoint(transformScenePoint(localVertical, center, rotationX, rotationY), size, sceneCenterX, sceneCenterY);
|
|
20085
|
+
const horizontalRadius = clampNumber$1(Math.hypot(projectedHorizontalPoint.x - projectedCenterPoint.x, projectedHorizontalPoint.y - projectedCenterPoint.y) *
|
|
20086
|
+
radiusScale *
|
|
20087
|
+
0.74, size * 0.003, size * 0.018);
|
|
20088
|
+
const verticalRadius = clampNumber$1(Math.hypot(projectedVerticalPoint.x - projectedCenterPoint.x, projectedVerticalPoint.y - projectedCenterPoint.y) *
|
|
20089
|
+
radiusScale *
|
|
20090
|
+
0.52, size * 0.0024, size * 0.014);
|
|
20091
|
+
const rotation = Math.atan2(projectedHorizontalPoint.y - projectedCenterPoint.y, projectedHorizontalPoint.x - projectedCenterPoint.x);
|
|
20092
|
+
context.save();
|
|
20093
|
+
context.translate(projectedCenterPoint.x, projectedCenterPoint.y);
|
|
20094
|
+
context.rotate(rotation);
|
|
20095
|
+
context.beginPath();
|
|
20096
|
+
context.ellipse(0, 0, horizontalRadius, verticalRadius, 0, 0, Math.PI * 2);
|
|
20097
|
+
context.fillStyle = `${palette.highlight}73`;
|
|
20098
|
+
context.fill();
|
|
20099
|
+
context.strokeStyle = `${palette.highlight}99`;
|
|
20100
|
+
context.lineWidth = Math.max(0.7, size * 0.0028);
|
|
20101
|
+
context.stroke();
|
|
20102
|
+
context.restore();
|
|
20103
|
+
}
|
|
20104
|
+
/**
|
|
20105
|
+
* Resolves a signed angular distance from the source longitude to the target longitude.
|
|
20106
|
+
*
|
|
20107
|
+
* @private helper of `octopus3d3AvatarVisual`
|
|
20108
|
+
*/
|
|
20109
|
+
function resolveSignedAngularDistance(sourceLongitude, targetLongitude) {
|
|
20110
|
+
return Math.atan2(Math.sin(targetLongitude - sourceLongitude), Math.cos(targetLongitude - sourceLongitude));
|
|
20111
|
+
}
|
|
20112
|
+
/**
|
|
20113
|
+
* Smoothly maps a value between two bounds into `[0, 1]`.
|
|
20114
|
+
*
|
|
20115
|
+
* @private helper of `octopus3d3AvatarVisual`
|
|
20116
|
+
*/
|
|
20117
|
+
function smoothStep(edgeStart, edgeEnd, value) {
|
|
20118
|
+
const progress = clampNumber$1((value - edgeStart) / (edgeEnd - edgeStart), 0, 1);
|
|
20119
|
+
return progress * progress * (3 - 2 * progress);
|
|
20120
|
+
}
|
|
20121
|
+
|
|
19612
20122
|
/* eslint-disable no-magic-numbers */
|
|
19613
20123
|
/**
|
|
19614
20124
|
* Octopus avatar visual.
|
|
@@ -20379,6 +20889,7 @@ const AVATAR_VISUALS = [
|
|
|
20379
20889
|
octopus3AvatarVisual,
|
|
20380
20890
|
octopus3dAvatarVisual,
|
|
20381
20891
|
octopus3d2AvatarVisual,
|
|
20892
|
+
octopus3d3AvatarVisual,
|
|
20382
20893
|
asciiOctopusAvatarVisual,
|
|
20383
20894
|
minecraftAvatarVisual,
|
|
20384
20895
|
minecraft2AvatarVisual,
|