@promptbook/core 0.112.0-103 → 0.112.0-105

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