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