@promptbook/browser 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 CHANGED
@@ -29,7 +29,7 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
29
29
  * @generated
30
30
  * @see https://github.com/webgptorg/promptbook
31
31
  */
32
- const PROMPTBOOK_ENGINE_VERSION = '0.112.0-102';
32
+ const PROMPTBOOK_ENGINE_VERSION = '0.112.0-104';
33
33
  /**
34
34
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
35
35
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -6637,7 +6637,7 @@ function fillTextureRect(texture, x, y, width, height, color) {
6637
6637
  *
6638
6638
  * @private helper of `minecraft2AvatarVisual`
6639
6639
  */
6640
- const LIGHT_DIRECTION$2 = normalizeVector3({
6640
+ const LIGHT_DIRECTION$3 = normalizeVector3({
6641
6641
  x: 0.4,
6642
6642
  y: -0.65,
6643
6643
  z: 0.92,
@@ -6849,7 +6849,7 @@ function resolveVisibleCuboidFaces(cuboid, size, sceneCenterX, sceneCenterY) {
6849
6849
  corners: projectedCorners,
6850
6850
  texture: faceDefinition.texture,
6851
6851
  averageDepth: transformedCorners.reduce((depthSum, corner) => depthSum + corner.z, 0) / transformedCorners.length,
6852
- lightIntensity: clampNumber$1(dotProduct3D(faceNormal, LIGHT_DIRECTION$2), -1, 1),
6852
+ lightIntensity: clampNumber$1(dotProduct3D(faceNormal, LIGHT_DIRECTION$3), -1, 1),
6853
6853
  outlineColor: cuboid.outlineColor,
6854
6854
  };
6855
6855
  });
@@ -8040,7 +8040,7 @@ function formatAlphaHex(opacity) {
8040
8040
  *
8041
8041
  * @private helper of `octopus3dAvatarVisual`
8042
8042
  */
8043
- const LIGHT_DIRECTION$1 = normalizeVector3({
8043
+ const LIGHT_DIRECTION$2 = normalizeVector3({
8044
8044
  x: 0.48,
8045
8045
  y: -0.62,
8046
8046
  z: 0.94,
@@ -8250,7 +8250,7 @@ function resolveVisibleEllipsoidPatches(options) {
8250
8250
  corners: projectedCorners,
8251
8251
  averageDepth: transformedCorners.reduce((depthSum, transformedCorner) => depthSum + transformedCorner.z, 0) /
8252
8252
  transformedCorners.length,
8253
- lightIntensity: clampNumber$1(dotProduct3D(surfaceNormal, LIGHT_DIRECTION$1), -1, 1),
8253
+ lightIntensity: clampNumber$1(dotProduct3D(surfaceNormal, LIGHT_DIRECTION$2), -1, 1),
8254
8254
  fillStyle: resolveSurfacePatchFillStyle(palette, verticalProgress + verticalColorBias),
8255
8255
  outlineColor,
8256
8256
  });
@@ -8439,7 +8439,7 @@ function resolveEllipsoidSurfaceDepth(radiusX, radiusY, radiusZ, x, y) {
8439
8439
  *
8440
8440
  * @private helper of `octopus3d2AvatarVisual`
8441
8441
  */
8442
- const LIGHT_DIRECTION = normalizeVector3({
8442
+ const LIGHT_DIRECTION$1 = normalizeVector3({
8443
8443
  x: 0.38,
8444
8444
  y: -0.6,
8445
8445
  z: 0.98,
@@ -8588,7 +8588,7 @@ function resolveVisibleBlobbyOctopusPatches(options) {
8588
8588
  corners: projectedCorners,
8589
8589
  averageDepth: transformedCorners.reduce((depthSum, transformedCorner) => depthSum + transformedCorner.z, 0) /
8590
8590
  transformedCorners.length,
8591
- lightIntensity: clampNumber$1(dotProduct3D(surfaceNormal, LIGHT_DIRECTION), -1, 1),
8591
+ lightIntensity: clampNumber$1(dotProduct3D(surfaceNormal, LIGHT_DIRECTION$1), -1, 1),
8592
8592
  fillStyle: resolveBlobbySurfacePatchFillStyle(palette, verticalProgress, Math.max(0, Math.cos(centerLongitude)), resolveLowerLobeWave(centerLongitude, morphologyProfile, animationPhase, timeMs)),
8593
8593
  outlineColor: verticalProgress < 0.58 ? `${palette.highlight}73` : `${palette.shadow}8a`,
8594
8594
  });
@@ -8688,6 +8688,516 @@ function drawBlobbySurfacePatch(context, surfacePatch) {
8688
8688
  context.restore();
8689
8689
  }
8690
8690
 
8691
+ /* eslint-disable no-magic-numbers */
8692
+ /**
8693
+ * Light direction used by the continuous octopus mesh shading.
8694
+ *
8695
+ * @private helper of `octopus3d3AvatarVisual`
8696
+ */
8697
+ const LIGHT_DIRECTION = normalizeVector3({
8698
+ x: 0.34,
8699
+ y: -0.62,
8700
+ z: 1,
8701
+ });
8702
+ /**
8703
+ * Real-octopus tentacle count used by the continuous lower mesh.
8704
+ *
8705
+ * @private helper of `octopus3d3AvatarVisual`
8706
+ */
8707
+ const OCTOPUS_TENTACLE_COUNT = 8;
8708
+ /**
8709
+ * Octopus 3D 3 avatar visual.
8710
+ *
8711
+ * @private built-in avatar visual
8712
+ */
8713
+ const octopus3d3AvatarVisual = {
8714
+ id: 'octopus3d3',
8715
+ title: 'Octopus 3D 3',
8716
+ description: 'Cute continuous 3D octopus with a blobby single mesh, waving tentacle lobes, rich shading, and cursor-aware eyes.',
8717
+ isAnimated: true,
8718
+ supportsPointerTracking: true,
8719
+ render({ context, size, palette, createRandom, timeMs, interaction }) {
8720
+ const morphologyProfile = createOctopus3MorphologyProfile(createRandom);
8721
+ const animationRandom = createRandom('octopus3d3-animation-profile');
8722
+ const eyeRandom = createRandom('octopus3d3-eye-profile');
8723
+ const animationPhase = animationRandom() * Math.PI * 2;
8724
+ const tentacleProfiles = createContinuousTentacleProfiles(createRandom, morphologyProfile);
8725
+ const sceneCenterX = size * 0.5;
8726
+ const sceneCenterY = size * 0.535;
8727
+ const bob = Math.sin(timeMs / 960 + animationPhase) * size * 0.012;
8728
+ const meshCenter = {
8729
+ x: interaction.bodyOffsetX * size * 0.048 + size * morphologyProfile.body.centerXJitterRatio * 0.44,
8730
+ y: -size * 0.07 + interaction.bodyOffsetY * size * 0.026 + bob,
8731
+ z: interaction.intensity * size * 0.018,
8732
+ };
8733
+ const rotationY = -0.1 +
8734
+ Math.sin(timeMs / 2700 + animationPhase) * 0.035 +
8735
+ interaction.bodyOffsetX * 0.22 +
8736
+ interaction.gazeX * 0.88;
8737
+ const rotationX = -0.07 +
8738
+ Math.cos(timeMs / 3100 + animationPhase * 0.7) * 0.018 -
8739
+ interaction.bodyOffsetY * 0.08 -
8740
+ interaction.gazeY * 0.38;
8741
+ const surfaceOptions = {
8742
+ radiusX: size * morphologyProfile.body.bodyRadiusRatio * morphologyProfile.body.horizontalStretch * 1.1,
8743
+ radiusY: size * morphologyProfile.body.bodyRadiusRatio * morphologyProfile.body.verticalStretch * 1.08,
8744
+ radiusZ: size *
8745
+ morphologyProfile.body.bodyRadiusRatio *
8746
+ (1.02 + (morphologyProfile.body.horizontalStretch - 1) * 0.18),
8747
+ morphologyProfile,
8748
+ timeMs,
8749
+ animationPhase,
8750
+ tentacleProfiles,
8751
+ };
8752
+ const surfacePatches = resolveVisibleContinuousOctopusPatches({
8753
+ ...surfaceOptions,
8754
+ center: meshCenter,
8755
+ rotationX,
8756
+ rotationY,
8757
+ sceneCenterX,
8758
+ sceneCenterY,
8759
+ size,
8760
+ palette,
8761
+ });
8762
+ const eyeLatitude = clampNumber$1(morphologyProfile.face.eyeCenterYOffsetRatio * 4.2 - 0.03, -0.22, 0.08);
8763
+ const eyeLongitude = clampNumber$1(morphologyProfile.face.eyeSpacingRatio * 3.1, 0.18, 0.32);
8764
+ const mouthLatitude = clampNumber$1(eyeLatitude + 0.2 + morphologyProfile.face.mouthYOffsetRatio, 0.08, 0.34);
8765
+ const mouthCenterLongitude = clampNumber$1(morphologyProfile.face.mouthCenterOffsetRatio * 5.6, -0.08, 0.08);
8766
+ const mouthHalfLongitude = clampNumber$1(eyeLongitude * 0.78, 0.15, 0.28);
8767
+ const mouthCurveLatitude = clampNumber$1(mouthLatitude + morphologyProfile.face.mouthCurveDepthRatio * 0.78, mouthLatitude + 0.03, 0.42);
8768
+ const eyeRadiusX = size * morphologyProfile.face.eyeRadiusXRatio * 0.76;
8769
+ const eyeRadiusY = eyeRadiusX * morphologyProfile.face.eyeHeightRatio * 0.9;
8770
+ drawAvatarFrame(context, size, palette);
8771
+ drawContinuousOctopusAtmosphere(context, size, palette, sceneCenterX, sceneCenterY, interaction, timeMs);
8772
+ drawContinuousOctopusShadow(context, size, palette, interaction, timeMs, morphologyProfile);
8773
+ for (const surfacePatch of surfacePatches.sort((firstSurfacePatch, secondSurfacePatch) => firstSurfacePatch.averageDepth - secondSurfacePatch.averageDepth)) {
8774
+ drawContinuousSurfacePatch(context, surfacePatch);
8775
+ }
8776
+ drawProjectedSurfaceCurrents({
8777
+ context,
8778
+ surfaceOptions,
8779
+ center: meshCenter,
8780
+ rotationX,
8781
+ rotationY,
8782
+ sceneCenterX,
8783
+ sceneCenterY,
8784
+ size,
8785
+ palette,
8786
+ morphologyProfile,
8787
+ timeMs,
8788
+ animationPhase,
8789
+ });
8790
+ drawProjectedTentacleSuckers({
8791
+ context,
8792
+ surfaceOptions,
8793
+ center: meshCenter,
8794
+ rotationX,
8795
+ rotationY,
8796
+ sceneCenterX,
8797
+ sceneCenterY,
8798
+ size,
8799
+ palette,
8800
+ });
8801
+ drawProjectedOrganicEye(context, sampleContinuousOctopusSurfacePoint(surfaceOptions, eyeLatitude, -eyeLongitude), eyeRadiusX, eyeRadiusY, meshCenter, rotationX, rotationY, sceneCenterX, sceneCenterY, size, palette, timeMs, animationPhase + eyeRandom() * 0.7, interaction, morphologyProfile.face.eyeStyle);
8802
+ 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);
8803
+ drawProjectedOrganicMouth(context, [
8804
+ sampleContinuousOctopusSurfacePoint(surfaceOptions, mouthLatitude, mouthCenterLongitude - mouthHalfLongitude),
8805
+ sampleContinuousOctopusSurfacePoint(surfaceOptions, mouthCurveLatitude, mouthCenterLongitude),
8806
+ sampleContinuousOctopusSurfacePoint(surfaceOptions, mouthLatitude, mouthCenterLongitude + mouthHalfLongitude),
8807
+ ], meshCenter, rotationX, rotationY, sceneCenterX, sceneCenterY, palette, size);
8808
+ },
8809
+ };
8810
+ /**
8811
+ * Creates seeded tentacle-lobe profiles around the visible lower octopus body.
8812
+ *
8813
+ * @private helper of `octopus3d3AvatarVisual`
8814
+ */
8815
+ function createContinuousTentacleProfiles(createRandom, morphologyProfile) {
8816
+ return Array.from({ length: OCTOPUS_TENTACLE_COUNT }, (_, tentacleIndex) => {
8817
+ const tentacleRandom = createRandom(`octopus3d3-tentacle-${tentacleIndex}`);
8818
+ const progress = tentacleIndex / (OCTOPUS_TENTACLE_COUNT - 1);
8819
+ return {
8820
+ centerLongitude: -Math.PI * 0.86 +
8821
+ progress * Math.PI * 1.72 +
8822
+ (tentacleRandom() - 0.5) * (0.08 + morphologyProfile.tentacles.rootSpreadScale * 0.03),
8823
+ widthScale: 0.86 + tentacleRandom() * 0.34 + (morphologyProfile.tentacles.baseWidthScale - 1) * 0.16,
8824
+ lengthScale: 0.86 + tentacleRandom() * 0.36 + (morphologyProfile.tentacles.flowLengthScale - 1) * 0.22,
8825
+ swayScale: 0.82 + tentacleRandom() * 0.38 + (morphologyProfile.tentacles.swayScale - 1) * 0.2,
8826
+ depthScale: 0.86 + tentacleRandom() * 0.32 + (morphologyProfile.tentacles.tipReachScale - 1) * 0.2,
8827
+ phase: tentacleRandom() * Math.PI * 2,
8828
+ suckerSide: tentacleRandom() > 0.5 ? 1 : -1,
8829
+ };
8830
+ });
8831
+ }
8832
+ /**
8833
+ * Draws the soft underwater atmosphere behind the continuous octopus mesh.
8834
+ *
8835
+ * @private helper of `octopus3d3AvatarVisual`
8836
+ */
8837
+ function drawContinuousOctopusAtmosphere(context, size, palette, sceneCenterX, sceneCenterY, interaction, timeMs) {
8838
+ 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));
8839
+ glowGradient.addColorStop(0, `${palette.highlight}66`);
8840
+ glowGradient.addColorStop(0.34, `${palette.accent}2e`);
8841
+ glowGradient.addColorStop(1, `${palette.highlight}00`);
8842
+ context.fillStyle = glowGradient;
8843
+ context.fillRect(0, 0, size, size);
8844
+ 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);
8845
+ lowerGradient.addColorStop(0, `${palette.secondary}25`);
8846
+ lowerGradient.addColorStop(1, `${palette.secondary}00`);
8847
+ context.fillStyle = lowerGradient;
8848
+ context.fillRect(0, 0, size, size);
8849
+ }
8850
+ /**
8851
+ * Draws the soft lower shadow that anchors the octopus in the avatar frame.
8852
+ *
8853
+ * @private helper of `octopus3d3AvatarVisual`
8854
+ */
8855
+ function drawContinuousOctopusShadow(context, size, palette, interaction, timeMs, morphologyProfile) {
8856
+ context.save();
8857
+ context.fillStyle = `${palette.shadow}66`;
8858
+ context.filter = `blur(${size * 0.025}px)`;
8859
+ context.beginPath();
8860
+ 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);
8861
+ context.fill();
8862
+ context.restore();
8863
+ }
8864
+ /**
8865
+ * Resolves visible projected patches for the continuous octopus mesh.
8866
+ *
8867
+ * @private helper of `octopus3d3AvatarVisual`
8868
+ */
8869
+ function resolveVisibleContinuousOctopusPatches(options) {
8870
+ const { center, rotationX, rotationY, sceneCenterX, sceneCenterY, size, palette } = options;
8871
+ const latitudePatchCount = 16;
8872
+ const longitudePatchCount = 40;
8873
+ const surfacePatches = [];
8874
+ for (let latitudeIndex = 0; latitudeIndex < latitudePatchCount; latitudeIndex++) {
8875
+ const startLatitude = -Math.PI / 2 + (latitudeIndex / latitudePatchCount) * Math.PI;
8876
+ const endLatitude = -Math.PI / 2 + ((latitudeIndex + 1) / latitudePatchCount) * Math.PI;
8877
+ const centerLatitude = (startLatitude + endLatitude) / 2;
8878
+ const verticalProgress = (Math.sin(centerLatitude) + 1) / 2;
8879
+ for (let longitudeIndex = 0; longitudeIndex < longitudePatchCount; longitudeIndex++) {
8880
+ const startLongitude = -Math.PI + (longitudeIndex / longitudePatchCount) * Math.PI * 2;
8881
+ const endLongitude = -Math.PI + ((longitudeIndex + 1) / longitudePatchCount) * Math.PI * 2;
8882
+ const centerLongitude = (startLongitude + endLongitude) / 2;
8883
+ const localCorners = [
8884
+ sampleContinuousOctopusSurfacePoint(options, startLatitude, startLongitude),
8885
+ sampleContinuousOctopusSurfacePoint(options, startLatitude, endLongitude),
8886
+ sampleContinuousOctopusSurfacePoint(options, endLatitude, endLongitude),
8887
+ sampleContinuousOctopusSurfacePoint(options, endLatitude, startLongitude),
8888
+ ];
8889
+ const transformedCorners = localCorners.map((localCorner) => transformScenePoint(localCorner, center, rotationX, rotationY));
8890
+ const surfaceNormal = normalizeVector3(crossProduct3D(subtractPoint3D(transformedCorners[1], transformedCorners[0]), subtractPoint3D(transformedCorners[2], transformedCorners[0])));
8891
+ if (surfaceNormal.z <= 0.008) {
8892
+ continue;
8893
+ }
8894
+ const projectedCorners = transformedCorners.map((transformedCorner) => projectScenePoint(transformedCorner, size, sceneCenterX, sceneCenterY));
8895
+ const tentacleInfluence = resolveContinuousTentacleInfluence(options, centerLongitude);
8896
+ const lowerLobeWave = resolveContinuousLobeWave(options, centerLongitude);
8897
+ surfacePatches.push({
8898
+ corners: projectedCorners,
8899
+ averageDepth: transformedCorners.reduce((depthSum, transformedCorner) => depthSum + transformedCorner.z, 0) /
8900
+ transformedCorners.length,
8901
+ lightIntensity: clampNumber$1(dotProduct3D(surfaceNormal, LIGHT_DIRECTION), -1, 1),
8902
+ fillStyle: resolveContinuousSurfacePatchFillStyle(palette, verticalProgress, Math.max(0, Math.cos(centerLongitude)), tentacleInfluence.core, lowerLobeWave),
8903
+ outlineColor: verticalProgress < 0.54 ? `${palette.highlight}69` : `${palette.shadow}78`,
8904
+ });
8905
+ }
8906
+ }
8907
+ return surfacePatches;
8908
+ }
8909
+ /**
8910
+ * Samples one point on the continuous Octopus 3D 3 surface.
8911
+ *
8912
+ * The lower hemisphere is pulled into eight seeded waving lobes, so the portrait reads as
8913
+ * tentacled while still being rendered as one connected blobby mesh.
8914
+ *
8915
+ * @private helper of `octopus3d3AvatarVisual`
8916
+ */
8917
+ function sampleContinuousOctopusSurfacePoint(options, latitude, longitude) {
8918
+ const { radiusX, radiusY, radiusZ, morphologyProfile, timeMs, animationPhase } = options;
8919
+ const cosineLatitude = Math.max(0, Math.cos(latitude));
8920
+ const verticalProgress = (Math.sin(latitude) + 1) / 2;
8921
+ const upperBlend = Math.pow(1 - verticalProgress, 1.28);
8922
+ const lowerBlend = smoothStep(0.38, 1, verticalProgress);
8923
+ const tipBlend = smoothStep(0.68, 1, verticalProgress);
8924
+ const tentacleInfluence = resolveContinuousTentacleInfluence(options, longitude);
8925
+ const centerPull = resolveSignedAngularDistance(longitude, tentacleInfluence.centerLongitude);
8926
+ const effectiveLongitude = longitude + centerPull * lowerBlend * tentacleInfluence.core * (0.24 + tipBlend * 0.2);
8927
+ const lowerLobeWave = resolveContinuousLobeWave(options, longitude);
8928
+ const mantleRipple = Math.sin(longitude * morphologyProfile.body.lobeCount +
8929
+ animationPhase * 0.6 +
8930
+ timeMs / (1750 + morphologyProfile.body.lobeCount * 30)) *
8931
+ (0.018 + morphologyProfile.body.wobbleAmplitudeRatio * 0.8) *
8932
+ (0.3 + lowerBlend * 0.7);
8933
+ const tentacleWave = Math.sin(timeMs / 760 + tentacleInfluence.phase + verticalProgress * 2.4) *
8934
+ lowerBlend *
8935
+ tentacleInfluence.core *
8936
+ tentacleInfluence.swayScale;
8937
+ const horizontalScale = 1.04 +
8938
+ mantleRipple +
8939
+ lowerBlend * (0.16 + (morphologyProfile.tentacles.rootSpreadScale - 1) * 0.1) +
8940
+ lowerBlend * tentacleInfluence.core * (0.2 + lowerLobeWave * 0.12) -
8941
+ upperBlend * 0.08;
8942
+ const depthScale = 1.06 +
8943
+ upperBlend * 0.16 +
8944
+ Math.max(0, Math.cos(effectiveLongitude)) * 0.1 +
8945
+ lowerBlend * tentacleInfluence.core * (0.1 + tentacleInfluence.depthScale * 0.06) -
8946
+ Math.max(0, -Math.cos(effectiveLongitude)) * 0.05;
8947
+ const tentacleTubeRadius = lowerBlend *
8948
+ tentacleInfluence.core *
8949
+ (0.11 + tipBlend * 0.06 + tentacleInfluence.widthScale * 0.025) *
8950
+ radiusX;
8951
+ const planarRadiusX = cosineLatitude * radiusX * horizontalScale + tentacleTubeRadius;
8952
+ const planarRadiusZ = cosineLatitude * radiusZ * depthScale + tentacleTubeRadius * 0.72;
8953
+ const lowerDrop = lowerBlend *
8954
+ radiusY *
8955
+ (0.18 +
8956
+ tentacleInfluence.core *
8957
+ (0.38 +
8958
+ tentacleInfluence.lengthScale * 0.22 +
8959
+ (morphologyProfile.tentacles.flowLengthScale - 1) * 0.08));
8960
+ return {
8961
+ x: Math.sin(effectiveLongitude) * planarRadiusX +
8962
+ tentacleWave * radiusX * (0.052 + tipBlend * 0.05),
8963
+ y: Math.sin(latitude) * radiusY * (1 + upperBlend * 0.12) -
8964
+ upperBlend * radiusY * 0.1 +
8965
+ lowerDrop +
8966
+ Math.sin(timeMs / 1420 + animationPhase + latitude * 1.6) * lowerBlend * radiusY * 0.018 +
8967
+ Math.cos(timeMs / 880 + tentacleInfluence.phase) *
8968
+ lowerBlend *
8969
+ tipBlend *
8970
+ tentacleInfluence.core *
8971
+ radiusY *
8972
+ 0.034,
8973
+ z: Math.cos(effectiveLongitude) * planarRadiusZ +
8974
+ Math.cos(timeMs / 980 + tentacleInfluence.phase + verticalProgress) *
8975
+ lowerBlend *
8976
+ tentacleInfluence.core *
8977
+ radiusZ *
8978
+ 0.04,
8979
+ };
8980
+ }
8981
+ /**
8982
+ * Blends nearby seeded tentacle profiles at one mesh longitude.
8983
+ *
8984
+ * @private helper of `octopus3d3AvatarVisual`
8985
+ */
8986
+ function resolveContinuousTentacleInfluence(options, longitude) {
8987
+ let totalWeight = 0;
8988
+ let weightedSin = 0;
8989
+ let weightedCos = 0;
8990
+ let weightedWidthScale = 0;
8991
+ let weightedLengthScale = 0;
8992
+ let weightedSwayScale = 0;
8993
+ let weightedDepthScale = 0;
8994
+ let weightedPhase = 0;
8995
+ for (const tentacleProfile of options.tentacleProfiles) {
8996
+ const distance = Math.abs(resolveSignedAngularDistance(longitude, tentacleProfile.centerLongitude));
8997
+ const width = 0.2 * tentacleProfile.widthScale;
8998
+ const weight = Math.exp(-(distance * distance) / (width * width));
8999
+ totalWeight += weight;
9000
+ weightedSin += Math.sin(tentacleProfile.centerLongitude) * weight;
9001
+ weightedCos += Math.cos(tentacleProfile.centerLongitude) * weight;
9002
+ weightedWidthScale += tentacleProfile.widthScale * weight;
9003
+ weightedLengthScale += tentacleProfile.lengthScale * weight;
9004
+ weightedSwayScale += tentacleProfile.swayScale * weight;
9005
+ weightedDepthScale += tentacleProfile.depthScale * weight;
9006
+ weightedPhase += tentacleProfile.phase * weight;
9007
+ }
9008
+ if (totalWeight < 0.0001) {
9009
+ return {
9010
+ core: 0,
9011
+ centerLongitude: longitude,
9012
+ widthScale: 1,
9013
+ lengthScale: 1,
9014
+ swayScale: 1,
9015
+ depthScale: 1,
9016
+ phase: 0,
9017
+ };
9018
+ }
9019
+ return {
9020
+ core: clampNumber$1(totalWeight, 0, 1),
9021
+ centerLongitude: Math.atan2(weightedSin / totalWeight, weightedCos / totalWeight),
9022
+ widthScale: weightedWidthScale / totalWeight,
9023
+ lengthScale: weightedLengthScale / totalWeight,
9024
+ swayScale: weightedSwayScale / totalWeight,
9025
+ depthScale: weightedDepthScale / totalWeight,
9026
+ phase: weightedPhase / totalWeight,
9027
+ };
9028
+ }
9029
+ /**
9030
+ * Resolves the soft lower wave that makes the continuous mesh read as a set of tentacles.
9031
+ *
9032
+ * @private helper of `octopus3d3AvatarVisual`
9033
+ */
9034
+ function resolveContinuousLobeWave(options, longitude) {
9035
+ const { morphologyProfile, animationPhase, timeMs } = options;
9036
+ return (Math.cos(longitude * OCTOPUS_TENTACLE_COUNT + animationPhase + timeMs / (980 + morphologyProfile.body.lobeCount * 18)) +
9037
+ 1) / 2;
9038
+ }
9039
+ /**
9040
+ * Resolves one base fill tone for a patch on the continuous octopus mesh.
9041
+ *
9042
+ * @private helper of `octopus3d3AvatarVisual`
9043
+ */
9044
+ function resolveContinuousSurfacePatchFillStyle(palette, verticalProgress, forwardness, tentacleCore, lowerLobeWave) {
9045
+ const tonalProgress = clampNumber$1(verticalProgress + lowerLobeWave * 0.1 + tentacleCore * 0.08 - forwardness * 0.08, 0, 1);
9046
+ if (tonalProgress < 0.14) {
9047
+ return palette.highlight;
9048
+ }
9049
+ if (tonalProgress < 0.32) {
9050
+ return palette.secondary;
9051
+ }
9052
+ if (tonalProgress < 0.72) {
9053
+ return forwardness > 0.55 ? palette.secondary : palette.primary;
9054
+ }
9055
+ return tentacleCore > 0.44 ? `${palette.primary}f4` : `${palette.shadow}ee`;
9056
+ }
9057
+ /**
9058
+ * Draws one projected mesh patch with soft shading and a subtle edge.
9059
+ *
9060
+ * @private helper of `octopus3d3AvatarVisual`
9061
+ */
9062
+ function drawContinuousSurfacePatch(context, surfacePatch) {
9063
+ drawProjectedQuad(context, surfacePatch.corners, surfacePatch.fillStyle);
9064
+ if (surfacePatch.lightIntensity > 0) {
9065
+ drawProjectedQuad(context, surfacePatch.corners, `rgba(255, 255, 255, ${0.18 * surfacePatch.lightIntensity})`);
9066
+ }
9067
+ else if (surfacePatch.lightIntensity < 0) {
9068
+ drawProjectedQuad(context, surfacePatch.corners, `rgba(0, 0, 0, ${0.25 * Math.abs(surfacePatch.lightIntensity)})`);
9069
+ }
9070
+ context.save();
9071
+ context.beginPath();
9072
+ context.moveTo(surfacePatch.corners[0].x, surfacePatch.corners[0].y);
9073
+ for (let cornerIndex = 1; cornerIndex < surfacePatch.corners.length; cornerIndex++) {
9074
+ context.lineTo(surfacePatch.corners[cornerIndex].x, surfacePatch.corners[cornerIndex].y);
9075
+ }
9076
+ context.closePath();
9077
+ context.strokeStyle = surfacePatch.outlineColor;
9078
+ context.lineWidth = Math.max(0.7, getProjectedQuadPerimeter(surfacePatch.corners) * 0.0032);
9079
+ context.lineJoin = 'round';
9080
+ context.stroke();
9081
+ context.restore();
9082
+ }
9083
+ /**
9084
+ * Draws projected mantle-current lines on the front of the mesh.
9085
+ *
9086
+ * @private helper of `octopus3d3AvatarVisual`
9087
+ */
9088
+ function drawProjectedSurfaceCurrents(options) {
9089
+ const { context, surfaceOptions, center, rotationX, rotationY, sceneCenterX, sceneCenterY, size, palette, morphologyProfile, timeMs, animationPhase, } = options;
9090
+ const currentCount = Math.min(6, morphologyProfile.details.mantleCurrentCount);
9091
+ const centerIndex = (currentCount - 1) / 2;
9092
+ context.save();
9093
+ context.lineCap = 'round';
9094
+ context.lineJoin = 'round';
9095
+ for (let currentIndex = 0; currentIndex < currentCount; currentIndex++) {
9096
+ const baseLongitude = (currentIndex - centerIndex) * 0.15;
9097
+ const projectedPoints = [];
9098
+ for (let sampleIndex = 0; sampleIndex < 8; sampleIndex++) {
9099
+ const progress = sampleIndex / 7;
9100
+ const latitude = -0.46 + progress * 0.74;
9101
+ const longitude = baseLongitude +
9102
+ Math.sin(timeMs / 1160 + animationPhase + currentIndex * 0.7 + progress * 2) * 0.035;
9103
+ const scenePoint = transformScenePoint(sampleContinuousOctopusSurfacePoint(surfaceOptions, latitude, longitude), center, rotationX, rotationY);
9104
+ if (scenePoint.z > center.z - size * 0.016) {
9105
+ projectedPoints.push(projectScenePoint(scenePoint, size, sceneCenterX, sceneCenterY));
9106
+ }
9107
+ }
9108
+ if (projectedPoints.length < 3) {
9109
+ continue;
9110
+ }
9111
+ context.beginPath();
9112
+ context.moveTo(projectedPoints[0].x, projectedPoints[0].y);
9113
+ for (const projectedPoint of projectedPoints.slice(1)) {
9114
+ context.lineTo(projectedPoint.x, projectedPoint.y);
9115
+ }
9116
+ context.strokeStyle = currentIndex % 2 === 0 ? `${palette.highlight}3d` : `${palette.accent}33`;
9117
+ context.lineWidth = size * (0.0055 + currentIndex * 0.00045);
9118
+ context.stroke();
9119
+ }
9120
+ context.restore();
9121
+ }
9122
+ /**
9123
+ * Draws small projected sucker highlights on the waving lower mesh lobes.
9124
+ *
9125
+ * @private helper of `octopus3d3AvatarVisual`
9126
+ */
9127
+ function drawProjectedTentacleSuckers(options) {
9128
+ const { surfaceOptions, size } = options;
9129
+ const { timeMs } = surfaceOptions;
9130
+ for (const tentacleProfile of surfaceOptions.tentacleProfiles) {
9131
+ if (Math.cos(tentacleProfile.centerLongitude) < -0.12) {
9132
+ continue;
9133
+ }
9134
+ for (let suckerIndex = 0; suckerIndex < 3; suckerIndex++) {
9135
+ const latitude = 0.52 + suckerIndex * 0.14;
9136
+ const sideOffset = tentacleProfile.suckerSide * (0.035 + suckerIndex * 0.012) * tentacleProfile.widthScale;
9137
+ const waveOffset = Math.sin(timeMs / 900 + tentacleProfile.phase + suckerIndex * 0.8) * 0.018;
9138
+ drawProjectedSurfaceSpot({
9139
+ ...options,
9140
+ latitude,
9141
+ longitude: tentacleProfile.centerLongitude + sideOffset + waveOffset,
9142
+ radiusScale: size * (0.0065 - suckerIndex * 0.0007),
9143
+ });
9144
+ }
9145
+ }
9146
+ }
9147
+ /**
9148
+ * Draws one tiny projected surface spot by sampling local mesh tangents.
9149
+ *
9150
+ * @private helper of `octopus3d3AvatarVisual`
9151
+ */
9152
+ function drawProjectedSurfaceSpot(options) {
9153
+ const { context, surfaceOptions, center, rotationX, rotationY, sceneCenterX, sceneCenterY, size, palette, latitude, longitude, radiusScale, } = options;
9154
+ const localCenter = sampleContinuousOctopusSurfacePoint(surfaceOptions, latitude, longitude);
9155
+ const localHorizontal = sampleContinuousOctopusSurfacePoint(surfaceOptions, latitude, longitude + 0.018);
9156
+ const localVertical = sampleContinuousOctopusSurfacePoint(surfaceOptions, latitude + 0.018, longitude);
9157
+ const sceneCenterPoint = transformScenePoint(localCenter, center, rotationX, rotationY);
9158
+ if (sceneCenterPoint.z <= center.z - size * 0.012) {
9159
+ return;
9160
+ }
9161
+ const projectedCenterPoint = projectScenePoint(sceneCenterPoint, size, sceneCenterX, sceneCenterY);
9162
+ const projectedHorizontalPoint = projectScenePoint(transformScenePoint(localHorizontal, center, rotationX, rotationY), size, sceneCenterX, sceneCenterY);
9163
+ const projectedVerticalPoint = projectScenePoint(transformScenePoint(localVertical, center, rotationX, rotationY), size, sceneCenterX, sceneCenterY);
9164
+ const horizontalRadius = clampNumber$1(Math.hypot(projectedHorizontalPoint.x - projectedCenterPoint.x, projectedHorizontalPoint.y - projectedCenterPoint.y) *
9165
+ radiusScale *
9166
+ 0.74, size * 0.003, size * 0.018);
9167
+ const verticalRadius = clampNumber$1(Math.hypot(projectedVerticalPoint.x - projectedCenterPoint.x, projectedVerticalPoint.y - projectedCenterPoint.y) *
9168
+ radiusScale *
9169
+ 0.52, size * 0.0024, size * 0.014);
9170
+ const rotation = Math.atan2(projectedHorizontalPoint.y - projectedCenterPoint.y, projectedHorizontalPoint.x - projectedCenterPoint.x);
9171
+ context.save();
9172
+ context.translate(projectedCenterPoint.x, projectedCenterPoint.y);
9173
+ context.rotate(rotation);
9174
+ context.beginPath();
9175
+ context.ellipse(0, 0, horizontalRadius, verticalRadius, 0, 0, Math.PI * 2);
9176
+ context.fillStyle = `${palette.highlight}73`;
9177
+ context.fill();
9178
+ context.strokeStyle = `${palette.highlight}99`;
9179
+ context.lineWidth = Math.max(0.7, size * 0.0028);
9180
+ context.stroke();
9181
+ context.restore();
9182
+ }
9183
+ /**
9184
+ * Resolves a signed angular distance from the source longitude to the target longitude.
9185
+ *
9186
+ * @private helper of `octopus3d3AvatarVisual`
9187
+ */
9188
+ function resolveSignedAngularDistance(sourceLongitude, targetLongitude) {
9189
+ return Math.atan2(Math.sin(targetLongitude - sourceLongitude), Math.cos(targetLongitude - sourceLongitude));
9190
+ }
9191
+ /**
9192
+ * Smoothly maps a value between two bounds into `[0, 1]`.
9193
+ *
9194
+ * @private helper of `octopus3d3AvatarVisual`
9195
+ */
9196
+ function smoothStep(edgeStart, edgeEnd, value) {
9197
+ const progress = clampNumber$1((value - edgeStart) / (edgeEnd - edgeStart), 0, 1);
9198
+ return progress * progress * (3 - 2 * progress);
9199
+ }
9200
+
8691
9201
  /* eslint-disable no-magic-numbers */
8692
9202
  /**
8693
9203
  * Octopus avatar visual.
@@ -9458,6 +9968,7 @@ const AVATAR_VISUALS = [
9458
9968
  octopus3AvatarVisual,
9459
9969
  octopus3dAvatarVisual,
9460
9970
  octopus3d2AvatarVisual,
9971
+ octopus3d3AvatarVisual,
9461
9972
  asciiOctopusAvatarVisual,
9462
9973
  minecraftAvatarVisual,
9463
9974
  minecraft2AvatarVisual,