@promptbook/node 0.112.0-65 โ 0.112.0-66
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 +702 -61
- package/esm/index.es.js.map +1 -1
- package/esm/src/avatars/types/AvatarVisualDefinition.d.ts +1 -1
- package/esm/src/avatars/visuals/minecraft2AvatarVisual.d.ts +7 -0
- package/esm/src/avatars/visuals/minecraftAvatarVisualShared.d.ts +48 -0
- package/esm/src/cli/cli-commands/coder/ensureCoderGitignoreFile.d.ts +1 -1
- package/esm/src/config.d.ts +3 -3
- package/esm/src/utils/files/getPromptbookTempPath.d.ts +24 -0
- package/esm/src/utils/files/getPromptbookTempPath.test.d.ts +1 -0
- package/esm/src/version.d.ts +1 -1
- package/package.json +2 -2
- package/umd/index.umd.js +701 -60
- package/umd/index.umd.js.map +1 -1
- package/umd/src/avatars/types/AvatarVisualDefinition.d.ts +1 -1
- package/umd/src/avatars/visuals/minecraft2AvatarVisual.d.ts +7 -0
- package/umd/src/avatars/visuals/minecraftAvatarVisualShared.d.ts +48 -0
- package/umd/src/cli/cli-commands/coder/ensureCoderGitignoreFile.d.ts +1 -1
- package/umd/src/config.d.ts +3 -3
- package/umd/src/utils/files/getPromptbookTempPath.d.ts +24 -0
- package/umd/src/utils/files/getPromptbookTempPath.test.d.ts +1 -0
- package/umd/src/version.d.ts +1 -1
package/esm/index.es.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import colors from 'colors';
|
|
2
2
|
import { stat, access, constants, readFile, writeFile, readdir, mkdir, watch, rm, unlink } from 'fs/promises';
|
|
3
|
-
import { basename, join, dirname, isAbsolute, relative } from 'path';
|
|
3
|
+
import { posix, basename, join, dirname, isAbsolute, relative } from 'path';
|
|
4
4
|
import _spaceTrim, { spaceTrim as spaceTrim$1 } from 'spacetrim';
|
|
5
5
|
import JSZip from 'jszip';
|
|
6
6
|
import { randomBytes } from 'crypto';
|
|
@@ -35,7 +35,7 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
|
|
|
35
35
|
* @generated
|
|
36
36
|
* @see https://github.com/webgptorg/promptbook
|
|
37
37
|
*/
|
|
38
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.112.0-
|
|
38
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.112.0-66';
|
|
39
39
|
/**
|
|
40
40
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
41
41
|
* Note: [๐] Ignore a discrepancy between file name and entity name
|
|
@@ -954,6 +954,29 @@ function saturate(amount) {
|
|
|
954
954
|
}
|
|
955
955
|
// TODO: Maybe implement by mix+hsl
|
|
956
956
|
|
|
957
|
+
/**
|
|
958
|
+
* Relative directory name without the `./` prefix for Git ignore rules and glob patterns.
|
|
959
|
+
*
|
|
960
|
+
* @private internal utility for Promptbook-owned temp files
|
|
961
|
+
*/
|
|
962
|
+
const PROMPTBOOK_TEMP_DIRECTORY_NAME = '.promptbook';
|
|
963
|
+
/**
|
|
964
|
+
* Builds one project-relative path inside the shared Promptbook working directory.
|
|
965
|
+
*
|
|
966
|
+
* @private internal utility for Promptbook-owned temp files
|
|
967
|
+
*/
|
|
968
|
+
function getPromptbookTempPath(...pathSegments) {
|
|
969
|
+
return `./${getPromptbookTempPosixPath(...pathSegments)}`;
|
|
970
|
+
}
|
|
971
|
+
/**
|
|
972
|
+
* Builds one POSIX path fragment inside the shared Promptbook working directory for globs and generated text files.
|
|
973
|
+
*
|
|
974
|
+
* @private internal utility for Promptbook-owned temp files
|
|
975
|
+
*/
|
|
976
|
+
function getPromptbookTempPosixPath(...pathSegments) {
|
|
977
|
+
return posix.join(PROMPTBOOK_TEMP_DIRECTORY_NAME, ...pathSegments);
|
|
978
|
+
}
|
|
979
|
+
|
|
957
980
|
/**
|
|
958
981
|
* Returns the same value that is passed as argument.
|
|
959
982
|
* No side effects.
|
|
@@ -1148,7 +1171,6 @@ const DEFAULT_MAX_PARALLEL_COUNT = 5; // <- TODO: [๐คนโโ๏ธ]
|
|
|
1148
1171
|
*/
|
|
1149
1172
|
const DEFAULT_MAX_EXECUTION_ATTEMPTS = 7; // <- TODO: [๐คนโโ๏ธ]
|
|
1150
1173
|
// <- TODO: [๐] Make also `AGENTS_DIRNAME_ALTERNATIVES`
|
|
1151
|
-
// TODO: Just `.promptbook` in config, hardcode subfolders like `download-cache` or `execution-cache`
|
|
1152
1174
|
/**
|
|
1153
1175
|
* Where to store the temporary downloads
|
|
1154
1176
|
*
|
|
@@ -1156,7 +1178,15 @@ const DEFAULT_MAX_EXECUTION_ATTEMPTS = 7; // <- TODO: [๐คนโโ๏ธ]
|
|
|
1156
1178
|
*
|
|
1157
1179
|
* @public exported from `@promptbook/core`
|
|
1158
1180
|
*/
|
|
1159
|
-
const DEFAULT_DOWNLOAD_CACHE_DIRNAME = '
|
|
1181
|
+
const DEFAULT_DOWNLOAD_CACHE_DIRNAME = getPromptbookTempPath('download-cache');
|
|
1182
|
+
/**
|
|
1183
|
+
* Where to store the cache of executions for promptbook CLI
|
|
1184
|
+
*
|
|
1185
|
+
* Note: When the folder does not exist, it is created recursively
|
|
1186
|
+
*
|
|
1187
|
+
* @public exported from `@promptbook/core`
|
|
1188
|
+
*/
|
|
1189
|
+
getPromptbookTempPath('execution-cache');
|
|
1160
1190
|
/**
|
|
1161
1191
|
* Where to store the scrape cache
|
|
1162
1192
|
*
|
|
@@ -1164,7 +1194,7 @@ const DEFAULT_DOWNLOAD_CACHE_DIRNAME = './.promptbook/download-cache';
|
|
|
1164
1194
|
*
|
|
1165
1195
|
* @public exported from `@promptbook/core`
|
|
1166
1196
|
*/
|
|
1167
|
-
const DEFAULT_SCRAPE_CACHE_DIRNAME = '
|
|
1197
|
+
const DEFAULT_SCRAPE_CACHE_DIRNAME = getPromptbookTempPath('scrape-cache');
|
|
1168
1198
|
/*
|
|
1169
1199
|
TODO: [๐]
|
|
1170
1200
|
/**
|
|
@@ -18658,6 +18688,177 @@ function drawFractalCore(context, size, palette, timeMs, corePhase) {
|
|
|
18658
18688
|
context.restore();
|
|
18659
18689
|
}
|
|
18660
18690
|
|
|
18691
|
+
/* eslint-disable no-magic-numbers */
|
|
18692
|
+
/**
|
|
18693
|
+
* Builds the seeded six-face texture pack used by the Minecraft-style head cuboid.
|
|
18694
|
+
*
|
|
18695
|
+
* @param random Seeded random generator.
|
|
18696
|
+
* @param palette Derived avatar palette.
|
|
18697
|
+
* @param hasHeadband Whether the generated avatar should include a colored headband.
|
|
18698
|
+
* @returns Head cuboid textures.
|
|
18699
|
+
*
|
|
18700
|
+
* @private helper of the Minecraft avatar visuals
|
|
18701
|
+
*/
|
|
18702
|
+
function createMinecraftHeadTextures(random, palette, hasHeadband) {
|
|
18703
|
+
const faceTexture = createMinecraftFaceTexture(random, palette, hasHeadband);
|
|
18704
|
+
const hairColor = random() < 0.5 ? palette.primary : palette.secondary;
|
|
18705
|
+
const skinColor = palette.highlight;
|
|
18706
|
+
const headbandColor = hasHeadband ? palette.accent : hairColor;
|
|
18707
|
+
const sideTexture = createFilledTexture(skinColor);
|
|
18708
|
+
const backTexture = createFilledTexture(skinColor);
|
|
18709
|
+
const topTexture = createFilledTexture(hairColor);
|
|
18710
|
+
const bottomTexture = createFilledTexture(`${palette.shadow}cc`);
|
|
18711
|
+
fillTextureRect(sideTexture, 0, 0, 8, 3, hairColor);
|
|
18712
|
+
fillTextureRect(backTexture, 0, 0, 8, 5, hairColor);
|
|
18713
|
+
fillTextureRect(backTexture, 1, 5, 6, 1, hairColor);
|
|
18714
|
+
if (hasHeadband) {
|
|
18715
|
+
fillTextureRect(sideTexture, 0, 2, 8, 1, headbandColor);
|
|
18716
|
+
fillTextureRect(backTexture, 0, 2, 8, 1, headbandColor);
|
|
18717
|
+
fillTextureRect(topTexture, 0, 4, 8, 1, headbandColor);
|
|
18718
|
+
}
|
|
18719
|
+
sideTexture[4][4] = `${palette.shadow}99`;
|
|
18720
|
+
sideTexture[5][4] = `${palette.shadow}cc`;
|
|
18721
|
+
backTexture[6][2] = `${palette.shadow}99`;
|
|
18722
|
+
backTexture[6][5] = `${palette.shadow}99`;
|
|
18723
|
+
return {
|
|
18724
|
+
front: faceTexture,
|
|
18725
|
+
back: backTexture,
|
|
18726
|
+
left: sideTexture,
|
|
18727
|
+
right: mirrorMinecraftTexture(sideTexture),
|
|
18728
|
+
top: topTexture,
|
|
18729
|
+
bottom: bottomTexture,
|
|
18730
|
+
};
|
|
18731
|
+
}
|
|
18732
|
+
/**
|
|
18733
|
+
* Builds the seeded six-face texture pack used by the Minecraft-style torso cuboid.
|
|
18734
|
+
*
|
|
18735
|
+
* @param random Seeded random generator.
|
|
18736
|
+
* @param palette Derived avatar palette.
|
|
18737
|
+
* @returns Torso cuboid textures.
|
|
18738
|
+
*
|
|
18739
|
+
* @private helper of the Minecraft avatar visuals
|
|
18740
|
+
*/
|
|
18741
|
+
function createMinecraftTorsoTextures(random, palette) {
|
|
18742
|
+
const frontTexture = createMinecraftShirtTexture(random, palette);
|
|
18743
|
+
const sideTexture = createFilledTexture(palette.primary);
|
|
18744
|
+
const backTexture = createFilledTexture(palette.primary);
|
|
18745
|
+
const topTexture = createFilledTexture(`${palette.highlight}dd`);
|
|
18746
|
+
const bottomTexture = createFilledTexture(`${palette.shadow}dd`);
|
|
18747
|
+
const stripeColor = random() < 0.5 ? palette.secondary : palette.highlight;
|
|
18748
|
+
fillTextureRect(sideTexture, 0, 0, 8, 2, palette.shadow);
|
|
18749
|
+
fillTextureRect(backTexture, 0, 0, 8, 2, palette.shadow);
|
|
18750
|
+
fillTextureRect(backTexture, 3, 2, 2, 6, stripeColor);
|
|
18751
|
+
fillTextureRect(sideTexture, 4, 2, 1, 6, stripeColor);
|
|
18752
|
+
fillTextureRect(topTexture, 0, 0, 8, 2, palette.shadow);
|
|
18753
|
+
fillTextureRect(topTexture, 2, 2, 4, 4, stripeColor);
|
|
18754
|
+
return {
|
|
18755
|
+
front: frontTexture,
|
|
18756
|
+
back: backTexture,
|
|
18757
|
+
left: sideTexture,
|
|
18758
|
+
right: mirrorMinecraftTexture(sideTexture),
|
|
18759
|
+
top: topTexture,
|
|
18760
|
+
bottom: bottomTexture,
|
|
18761
|
+
};
|
|
18762
|
+
}
|
|
18763
|
+
/**
|
|
18764
|
+
* Mirrors one Minecraft texture horizontally.
|
|
18765
|
+
*
|
|
18766
|
+
* @param texture Source texture.
|
|
18767
|
+
* @returns Mirrored texture copy.
|
|
18768
|
+
*
|
|
18769
|
+
* @private helper of the Minecraft avatar visuals
|
|
18770
|
+
*/
|
|
18771
|
+
function mirrorMinecraftTexture(texture) {
|
|
18772
|
+
return texture.map((row) => [...row].reverse());
|
|
18773
|
+
}
|
|
18774
|
+
/**
|
|
18775
|
+
* Creates the front-face pixel texture for the cube head.
|
|
18776
|
+
*
|
|
18777
|
+
* @param random Seeded random generator.
|
|
18778
|
+
* @param palette Derived avatar palette.
|
|
18779
|
+
* @param hasHeadband Whether the avatar should render a headband row.
|
|
18780
|
+
* @returns 8x8 pixel texture.
|
|
18781
|
+
*
|
|
18782
|
+
* @private helper of the Minecraft avatar visuals
|
|
18783
|
+
*/
|
|
18784
|
+
function createMinecraftFaceTexture(random, palette, hasHeadband) {
|
|
18785
|
+
const texture = createFilledTexture(palette.highlight);
|
|
18786
|
+
const hairlineColor = random() < 0.5 ? palette.primary : palette.secondary;
|
|
18787
|
+
const cheekColor = random() < 0.5 ? `${palette.accent}bb` : `${palette.secondary}bb`;
|
|
18788
|
+
fillTextureRect(texture, 0, 0, 8, 2, hairlineColor);
|
|
18789
|
+
texture[2][0] = hairlineColor;
|
|
18790
|
+
texture[2][7] = hairlineColor;
|
|
18791
|
+
texture[3][0] = hairlineColor;
|
|
18792
|
+
texture[3][7] = hairlineColor;
|
|
18793
|
+
if (hasHeadband) {
|
|
18794
|
+
fillTextureRect(texture, 0, 2, 8, 1, palette.accent);
|
|
18795
|
+
}
|
|
18796
|
+
texture[3][2] = palette.ink;
|
|
18797
|
+
texture[3][5] = palette.ink;
|
|
18798
|
+
texture[4][2] = '#ffffff';
|
|
18799
|
+
texture[4][5] = '#ffffff';
|
|
18800
|
+
texture[5][1] = cheekColor;
|
|
18801
|
+
texture[5][6] = cheekColor;
|
|
18802
|
+
texture[5][3] = palette.shadow;
|
|
18803
|
+
texture[5][4] = palette.shadow;
|
|
18804
|
+
texture[6][3] = palette.shadow;
|
|
18805
|
+
texture[6][4] = palette.shadow;
|
|
18806
|
+
return texture;
|
|
18807
|
+
}
|
|
18808
|
+
/**
|
|
18809
|
+
* Creates the front-face pixel texture for the torso.
|
|
18810
|
+
*
|
|
18811
|
+
* @param random Seeded random generator.
|
|
18812
|
+
* @param palette Derived avatar palette.
|
|
18813
|
+
* @returns 8x8 torso texture.
|
|
18814
|
+
*
|
|
18815
|
+
* @private helper of the Minecraft avatar visuals
|
|
18816
|
+
*/
|
|
18817
|
+
function createMinecraftShirtTexture(random, palette) {
|
|
18818
|
+
const texture = createFilledTexture(palette.primary);
|
|
18819
|
+
const stripeColor = random() < 0.5 ? palette.secondary : palette.highlight;
|
|
18820
|
+
fillTextureRect(texture, 0, 0, 8, 2, palette.shadow);
|
|
18821
|
+
for (let rowIndex = 2; rowIndex < 8; rowIndex++) {
|
|
18822
|
+
texture[rowIndex][3] = stripeColor;
|
|
18823
|
+
texture[rowIndex][4] = stripeColor;
|
|
18824
|
+
}
|
|
18825
|
+
texture[4][1] = palette.accent;
|
|
18826
|
+
texture[4][6] = palette.accent;
|
|
18827
|
+
texture[5][2] = palette.highlight;
|
|
18828
|
+
texture[5][5] = palette.highlight;
|
|
18829
|
+
return texture;
|
|
18830
|
+
}
|
|
18831
|
+
/**
|
|
18832
|
+
* Creates one solid-color 8x8 Minecraft texture.
|
|
18833
|
+
*
|
|
18834
|
+
* @param color Fill color.
|
|
18835
|
+
* @returns Filled 8x8 texture.
|
|
18836
|
+
*
|
|
18837
|
+
* @private helper of the Minecraft avatar visuals
|
|
18838
|
+
*/
|
|
18839
|
+
function createFilledTexture(color) {
|
|
18840
|
+
return Array.from({ length: 8 }, () => Array.from({ length: 8 }, () => color));
|
|
18841
|
+
}
|
|
18842
|
+
/**
|
|
18843
|
+
* Fills one rectangular area inside a mutable Minecraft texture.
|
|
18844
|
+
*
|
|
18845
|
+
* @param texture Mutable target texture.
|
|
18846
|
+
* @param x Left texture coordinate.
|
|
18847
|
+
* @param y Top texture coordinate.
|
|
18848
|
+
* @param width Rectangle width.
|
|
18849
|
+
* @param height Rectangle height.
|
|
18850
|
+
* @param color Fill color.
|
|
18851
|
+
*
|
|
18852
|
+
* @private helper of the Minecraft avatar visuals
|
|
18853
|
+
*/
|
|
18854
|
+
function fillTextureRect(texture, x, y, width, height, color) {
|
|
18855
|
+
for (let rowIndex = y; rowIndex < y + height; rowIndex++) {
|
|
18856
|
+
for (let columnIndex = x; columnIndex < x + width; columnIndex++) {
|
|
18857
|
+
texture[rowIndex][columnIndex] = color;
|
|
18858
|
+
}
|
|
18859
|
+
}
|
|
18860
|
+
}
|
|
18861
|
+
|
|
18661
18862
|
/* eslint-disable no-magic-numbers */
|
|
18662
18863
|
/**
|
|
18663
18864
|
* Minecraft-style 3D avatar visual.
|
|
@@ -18682,8 +18883,8 @@ const minecraftAvatarVisual = {
|
|
|
18682
18883
|
const bodyX = size * 0.33;
|
|
18683
18884
|
const bodyY = headY + headSize * 0.96;
|
|
18684
18885
|
const hasHeadband = random() < 0.5;
|
|
18685
|
-
const
|
|
18686
|
-
const
|
|
18886
|
+
const headTextures = createMinecraftHeadTextures(createRandom('minecraft-face'), palette, hasHeadband);
|
|
18887
|
+
const torsoTextures = createMinecraftTorsoTextures(createRandom('minecraft-shirt'), palette);
|
|
18687
18888
|
drawAvatarFrame(context, size, palette);
|
|
18688
18889
|
const spotlight = context.createRadialGradient(size * 0.5, size * 0.18, size * 0.05, size * 0.5, size * 0.18, size * 0.5);
|
|
18689
18890
|
spotlight.addColorStop(0, `${palette.highlight}66`);
|
|
@@ -18703,7 +18904,7 @@ const minecraftAvatarVisual = {
|
|
|
18703
18904
|
width: bodyWidth,
|
|
18704
18905
|
height: bodyHeight,
|
|
18705
18906
|
depth: bodyDepth,
|
|
18706
|
-
frontTexture:
|
|
18907
|
+
frontTexture: torsoTextures.front,
|
|
18707
18908
|
topColor: `${palette.highlight}cc`,
|
|
18708
18909
|
sideColor: `${palette.secondary}dd`,
|
|
18709
18910
|
outlineColor: `${palette.shadow}aa`,
|
|
@@ -18714,7 +18915,7 @@ const minecraftAvatarVisual = {
|
|
|
18714
18915
|
width: headSize,
|
|
18715
18916
|
height: headSize,
|
|
18716
18917
|
depth,
|
|
18717
|
-
frontTexture:
|
|
18918
|
+
frontTexture: headTextures.front,
|
|
18718
18919
|
topColor: `${palette.highlight}ee`,
|
|
18719
18920
|
sideColor: `${palette.secondary}ee`,
|
|
18720
18921
|
outlineColor: `${palette.shadow}cc`,
|
|
@@ -18779,72 +18980,505 @@ function drawVoxelCuboid(context, cuboid) {
|
|
|
18779
18980
|
context.closePath();
|
|
18780
18981
|
context.stroke();
|
|
18781
18982
|
}
|
|
18983
|
+
|
|
18984
|
+
/* eslint-disable no-magic-numbers */
|
|
18782
18985
|
/**
|
|
18783
|
-
*
|
|
18986
|
+
* Fixed scene camera distance used for the proper-3D projection.
|
|
18784
18987
|
*
|
|
18785
|
-
* @
|
|
18988
|
+
* @private helper of `minecraft2AvatarVisual`
|
|
18989
|
+
*/
|
|
18990
|
+
const CAMERA_DISTANCE_RATIO = 1.4;
|
|
18991
|
+
/**
|
|
18992
|
+
* Shared light direction used to shade projected cuboid faces.
|
|
18993
|
+
*
|
|
18994
|
+
* @private helper of `minecraft2AvatarVisual`
|
|
18995
|
+
*/
|
|
18996
|
+
const LIGHT_DIRECTION = normalizeVector3({
|
|
18997
|
+
x: 0.4,
|
|
18998
|
+
y: -0.65,
|
|
18999
|
+
z: 0.92,
|
|
19000
|
+
});
|
|
19001
|
+
/**
|
|
19002
|
+
* Minecraft 3D 2 avatar visual.
|
|
19003
|
+
*
|
|
19004
|
+
* @private built-in avatar visual
|
|
19005
|
+
*/
|
|
19006
|
+
const minecraft2AvatarVisual = {
|
|
19007
|
+
id: 'minecraft2',
|
|
19008
|
+
title: 'Minecraft 3D 2',
|
|
19009
|
+
description: 'Proper 3D Minecraft-style portrait with textured cuboids and pointer-driven head turns.',
|
|
19010
|
+
isAnimated: true,
|
|
19011
|
+
supportsPointerTracking: true,
|
|
19012
|
+
render({ context, size, palette, createRandom, timeMs, interaction }) {
|
|
19013
|
+
const spotlightY = size * 0.22;
|
|
19014
|
+
const headRandom = createRandom('minecraft2-head');
|
|
19015
|
+
const hasHeadband = headRandom() < 0.5;
|
|
19016
|
+
const headTextures = createMinecraftHeadTextures(createRandom('minecraft2-head-textures'), palette, hasHeadband);
|
|
19017
|
+
const torsoTextures = createMinecraftTorsoTextures(createRandom('minecraft2-body-textures'), palette);
|
|
19018
|
+
const bob = Math.sin(timeMs / 880) * size * 0.014;
|
|
19019
|
+
const bodyYaw = -0.24 + Math.sin(timeMs / 2300) * 0.06 + interaction.bodyOffsetX * 0.16;
|
|
19020
|
+
const bodyPitch = -0.12 + Math.cos(timeMs / 2800) * 0.02 - interaction.bodyOffsetY * 0.06;
|
|
19021
|
+
const headYaw = -0.18 + Math.sin(timeMs / 1900 + 0.6) * 0.05 + interaction.gazeX * 0.62;
|
|
19022
|
+
const headPitch = -0.12 + Math.cos(timeMs / 2400 + 1.1) * 0.03 - interaction.gazeY * 0.38;
|
|
19023
|
+
const sceneCenterX = size * 0.5;
|
|
19024
|
+
const sceneCenterY = size * 0.57;
|
|
19025
|
+
const bodyWidth = size * 0.225;
|
|
19026
|
+
const bodyHeight = size * 0.245;
|
|
19027
|
+
const bodyDepth = size * 0.145;
|
|
19028
|
+
const headSize = size * 0.24;
|
|
19029
|
+
const headLift = size * 0.205;
|
|
19030
|
+
const headForwardShift = interaction.intensity * size * 0.018;
|
|
19031
|
+
const sceneCuboids = [
|
|
19032
|
+
{
|
|
19033
|
+
center: {
|
|
19034
|
+
x: interaction.bodyOffsetX * size * 0.026,
|
|
19035
|
+
y: size * 0.05 + interaction.bodyOffsetY * size * 0.018 + bob,
|
|
19036
|
+
z: 0,
|
|
19037
|
+
},
|
|
19038
|
+
width: bodyWidth,
|
|
19039
|
+
height: bodyHeight,
|
|
19040
|
+
depth: bodyDepth,
|
|
19041
|
+
rotationX: bodyPitch,
|
|
19042
|
+
rotationY: bodyYaw,
|
|
19043
|
+
textures: torsoTextures,
|
|
19044
|
+
outlineColor: `${palette.shadow}cc`,
|
|
19045
|
+
},
|
|
19046
|
+
{
|
|
19047
|
+
center: {
|
|
19048
|
+
x: interaction.bodyOffsetX * size * 0.018 + interaction.gazeX * size * 0.016,
|
|
19049
|
+
y: -headLift + bob * 1.15,
|
|
19050
|
+
z: headForwardShift,
|
|
19051
|
+
},
|
|
19052
|
+
width: headSize,
|
|
19053
|
+
height: headSize,
|
|
19054
|
+
depth: headSize,
|
|
19055
|
+
rotationX: headPitch,
|
|
19056
|
+
rotationY: headYaw,
|
|
19057
|
+
textures: headTextures,
|
|
19058
|
+
outlineColor: `${palette.shadow}dd`,
|
|
19059
|
+
},
|
|
19060
|
+
];
|
|
19061
|
+
const visibleFaces = sceneCuboids
|
|
19062
|
+
.flatMap((cuboid) => resolveVisibleCuboidFaces(cuboid, size, sceneCenterX, sceneCenterY))
|
|
19063
|
+
.sort((firstFace, secondFace) => firstFace.averageDepth - secondFace.averageDepth);
|
|
19064
|
+
drawAvatarFrame(context, size, palette);
|
|
19065
|
+
drawMinecraftBackdrop(context, size, palette, sceneCenterX, spotlightY, interaction, timeMs);
|
|
19066
|
+
drawMinecraftShadow(context, size, palette, interaction, timeMs);
|
|
19067
|
+
for (const visibleFace of visibleFaces) {
|
|
19068
|
+
drawTexturedProjectedFace(context, visibleFace);
|
|
19069
|
+
}
|
|
19070
|
+
},
|
|
19071
|
+
};
|
|
19072
|
+
/**
|
|
19073
|
+
* Draws the shared background atmosphere behind the Minecraft 3D 2 portrait.
|
|
19074
|
+
*
|
|
19075
|
+
* @param context Canvas 2D context.
|
|
19076
|
+
* @param size Canvas size in CSS pixels.
|
|
18786
19077
|
* @param palette Derived avatar palette.
|
|
18787
|
-
* @param
|
|
18788
|
-
* @
|
|
19078
|
+
* @param sceneCenterX Horizontal scene center.
|
|
19079
|
+
* @param spotlightY Vertical spotlight anchor.
|
|
19080
|
+
* @param interaction Smoothed pointer-aware interaction state.
|
|
19081
|
+
* @param timeMs Current animation time in milliseconds.
|
|
18789
19082
|
*
|
|
18790
|
-
* @private helper of `
|
|
19083
|
+
* @private helper of `minecraft2AvatarVisual`
|
|
18791
19084
|
*/
|
|
18792
|
-
function
|
|
18793
|
-
const
|
|
18794
|
-
|
|
18795
|
-
|
|
18796
|
-
|
|
18797
|
-
|
|
18798
|
-
|
|
19085
|
+
function drawMinecraftBackdrop(context, size, palette, sceneCenterX, spotlightY, interaction, timeMs) {
|
|
19086
|
+
const spotlightGradient = context.createRadialGradient(sceneCenterX + interaction.gazeX * size * 0.08, spotlightY + interaction.gazeY * size * 0.05, size * 0.03, sceneCenterX, spotlightY, size * 0.52);
|
|
19087
|
+
spotlightGradient.addColorStop(0, `${palette.highlight}66`);
|
|
19088
|
+
spotlightGradient.addColorStop(0.42, `${palette.accent}1d`);
|
|
19089
|
+
spotlightGradient.addColorStop(1, `${palette.highlight}00`);
|
|
19090
|
+
context.fillStyle = spotlightGradient;
|
|
19091
|
+
context.fillRect(0, 0, size, size);
|
|
19092
|
+
const rimGradient = context.createLinearGradient(0, size * 0.14, 0, size * 0.92);
|
|
19093
|
+
rimGradient.addColorStop(0, `${palette.highlight}12`);
|
|
19094
|
+
rimGradient.addColorStop(0.55, `${palette.secondary}0a`);
|
|
19095
|
+
rimGradient.addColorStop(1, `${palette.shadow}00`);
|
|
19096
|
+
context.fillStyle = rimGradient;
|
|
19097
|
+
context.fillRect(0, 0, size, size);
|
|
19098
|
+
context.save();
|
|
19099
|
+
context.globalAlpha = 0.08 + interaction.intensity * 0.04;
|
|
19100
|
+
context.fillStyle = palette.highlight;
|
|
19101
|
+
context.beginPath();
|
|
19102
|
+
context.arc(size * 0.72 + Math.sin(timeMs / 1600) * size * 0.03, size * 0.2 + Math.cos(timeMs / 1400) * size * 0.018, size * 0.025, 0, Math.PI * 2);
|
|
19103
|
+
context.fill();
|
|
19104
|
+
context.restore();
|
|
19105
|
+
}
|
|
19106
|
+
/**
|
|
19107
|
+
* Draws the soft floor shadow used to anchor the cuboids in the frame.
|
|
19108
|
+
*
|
|
19109
|
+
* @param context Canvas 2D context.
|
|
19110
|
+
* @param size Canvas size in CSS pixels.
|
|
19111
|
+
* @param palette Derived avatar palette.
|
|
19112
|
+
* @param interaction Smoothed pointer-aware interaction state.
|
|
19113
|
+
* @param timeMs Current animation time in milliseconds.
|
|
19114
|
+
*
|
|
19115
|
+
* @private helper of `minecraft2AvatarVisual`
|
|
19116
|
+
*/
|
|
19117
|
+
function drawMinecraftShadow(context, size, palette, interaction, timeMs) {
|
|
19118
|
+
context.save();
|
|
19119
|
+
context.fillStyle = `${palette.shadow}66`;
|
|
19120
|
+
context.filter = `blur(${size * 0.02}px)`;
|
|
19121
|
+
context.beginPath();
|
|
19122
|
+
context.ellipse(size * 0.5 + interaction.gazeX * size * 0.03, size * 0.85 + Math.sin(timeMs / 880) * size * 0.01, size * (0.16 + interaction.intensity * 0.015), size * 0.055, 0, 0, Math.PI * 2);
|
|
19123
|
+
context.fill();
|
|
19124
|
+
context.restore();
|
|
19125
|
+
}
|
|
19126
|
+
/**
|
|
19127
|
+
* Resolves all visible projected faces for one scene cuboid.
|
|
19128
|
+
*
|
|
19129
|
+
* @param cuboid Scene cuboid definition.
|
|
19130
|
+
* @param size Canvas size in CSS pixels.
|
|
19131
|
+
* @param sceneCenterX Horizontal scene center.
|
|
19132
|
+
* @param sceneCenterY Vertical scene center.
|
|
19133
|
+
* @returns Visible faces sorted later by depth.
|
|
19134
|
+
*
|
|
19135
|
+
* @private helper of `minecraft2AvatarVisual`
|
|
19136
|
+
*/
|
|
19137
|
+
function resolveVisibleCuboidFaces(cuboid, size, sceneCenterX, sceneCenterY) {
|
|
19138
|
+
const halfWidth = cuboid.width / 2;
|
|
19139
|
+
const halfHeight = cuboid.height / 2;
|
|
19140
|
+
const halfDepth = cuboid.depth / 2;
|
|
19141
|
+
const faceDefinitions = [
|
|
19142
|
+
{
|
|
19143
|
+
texture: cuboid.textures.front,
|
|
19144
|
+
corners: [
|
|
19145
|
+
{ x: -halfWidth, y: -halfHeight, z: halfDepth },
|
|
19146
|
+
{ x: halfWidth, y: -halfHeight, z: halfDepth },
|
|
19147
|
+
{ x: halfWidth, y: halfHeight, z: halfDepth },
|
|
19148
|
+
{ x: -halfWidth, y: halfHeight, z: halfDepth },
|
|
19149
|
+
],
|
|
19150
|
+
},
|
|
19151
|
+
{
|
|
19152
|
+
texture: cuboid.textures.back,
|
|
19153
|
+
corners: [
|
|
19154
|
+
{ x: halfWidth, y: -halfHeight, z: -halfDepth },
|
|
19155
|
+
{ x: -halfWidth, y: -halfHeight, z: -halfDepth },
|
|
19156
|
+
{ x: -halfWidth, y: halfHeight, z: -halfDepth },
|
|
19157
|
+
{ x: halfWidth, y: halfHeight, z: -halfDepth },
|
|
19158
|
+
],
|
|
19159
|
+
},
|
|
19160
|
+
{
|
|
19161
|
+
texture: cuboid.textures.right,
|
|
19162
|
+
corners: [
|
|
19163
|
+
{ x: halfWidth, y: -halfHeight, z: halfDepth },
|
|
19164
|
+
{ x: halfWidth, y: -halfHeight, z: -halfDepth },
|
|
19165
|
+
{ x: halfWidth, y: halfHeight, z: -halfDepth },
|
|
19166
|
+
{ x: halfWidth, y: halfHeight, z: halfDepth },
|
|
19167
|
+
],
|
|
19168
|
+
},
|
|
19169
|
+
{
|
|
19170
|
+
texture: cuboid.textures.left,
|
|
19171
|
+
corners: [
|
|
19172
|
+
{ x: -halfWidth, y: -halfHeight, z: -halfDepth },
|
|
19173
|
+
{ x: -halfWidth, y: -halfHeight, z: halfDepth },
|
|
19174
|
+
{ x: -halfWidth, y: halfHeight, z: halfDepth },
|
|
19175
|
+
{ x: -halfWidth, y: halfHeight, z: -halfDepth },
|
|
19176
|
+
],
|
|
19177
|
+
},
|
|
19178
|
+
{
|
|
19179
|
+
texture: cuboid.textures.top,
|
|
19180
|
+
corners: [
|
|
19181
|
+
{ x: -halfWidth, y: -halfHeight, z: -halfDepth },
|
|
19182
|
+
{ x: halfWidth, y: -halfHeight, z: -halfDepth },
|
|
19183
|
+
{ x: halfWidth, y: -halfHeight, z: halfDepth },
|
|
19184
|
+
{ x: -halfWidth, y: -halfHeight, z: halfDepth },
|
|
19185
|
+
],
|
|
19186
|
+
},
|
|
19187
|
+
{
|
|
19188
|
+
texture: cuboid.textures.bottom,
|
|
19189
|
+
corners: [
|
|
19190
|
+
{ x: -halfWidth, y: halfHeight, z: halfDepth },
|
|
19191
|
+
{ x: halfWidth, y: halfHeight, z: halfDepth },
|
|
19192
|
+
{ x: halfWidth, y: halfHeight, z: -halfDepth },
|
|
19193
|
+
{ x: -halfWidth, y: halfHeight, z: -halfDepth },
|
|
19194
|
+
],
|
|
19195
|
+
},
|
|
19196
|
+
];
|
|
19197
|
+
const visibleFaces = faceDefinitions
|
|
19198
|
+
.map((faceDefinition) => {
|
|
19199
|
+
const transformedCorners = faceDefinition.corners.map((corner) => transformScenePoint(corner, cuboid.center, cuboid.rotationX, cuboid.rotationY));
|
|
19200
|
+
const faceNormal = normalizeVector3(crossProduct3D(subtractPoint3D(transformedCorners[1], transformedCorners[0]), subtractPoint3D(transformedCorners[2], transformedCorners[0])));
|
|
19201
|
+
if (faceNormal.z <= 0.02) {
|
|
19202
|
+
return null;
|
|
18799
19203
|
}
|
|
19204
|
+
const projectedCorners = transformedCorners.map((corner) => projectScenePoint(corner, size, sceneCenterX, sceneCenterY));
|
|
19205
|
+
return {
|
|
19206
|
+
corners: projectedCorners,
|
|
19207
|
+
texture: faceDefinition.texture,
|
|
19208
|
+
averageDepth: transformedCorners.reduce((depthSum, corner) => depthSum + corner.z, 0) / transformedCorners.length,
|
|
19209
|
+
lightIntensity: clampNumber$1(dotProduct3D(faceNormal, LIGHT_DIRECTION), -1, 1),
|
|
19210
|
+
outlineColor: cuboid.outlineColor,
|
|
19211
|
+
};
|
|
19212
|
+
});
|
|
19213
|
+
return visibleFaces.filter((visibleFace) => visibleFace !== null);
|
|
19214
|
+
}
|
|
19215
|
+
/**
|
|
19216
|
+
* Draws one projected textured face by tessellating its texture cells into quads.
|
|
19217
|
+
*
|
|
19218
|
+
* @param context Canvas 2D context.
|
|
19219
|
+
* @param face Visible projected face.
|
|
19220
|
+
*
|
|
19221
|
+
* @private helper of `minecraft2AvatarVisual`
|
|
19222
|
+
*/
|
|
19223
|
+
function drawTexturedProjectedFace(context, face) {
|
|
19224
|
+
var _a;
|
|
19225
|
+
const rows = face.texture.length;
|
|
19226
|
+
const columns = ((_a = face.texture[0]) === null || _a === void 0 ? void 0 : _a.length) || 0;
|
|
19227
|
+
if (rows === 0 || columns === 0) {
|
|
19228
|
+
return;
|
|
18800
19229
|
}
|
|
18801
|
-
|
|
18802
|
-
|
|
18803
|
-
|
|
18804
|
-
|
|
18805
|
-
|
|
18806
|
-
|
|
18807
|
-
|
|
19230
|
+
for (let rowIndex = 0; rowIndex < rows; rowIndex++) {
|
|
19231
|
+
for (let columnIndex = 0; columnIndex < columns; columnIndex++) {
|
|
19232
|
+
const startX = columnIndex / columns;
|
|
19233
|
+
const endX = (columnIndex + 1) / columns;
|
|
19234
|
+
const startY = rowIndex / rows;
|
|
19235
|
+
const endY = (rowIndex + 1) / rows;
|
|
19236
|
+
drawProjectedQuad(context, [
|
|
19237
|
+
interpolateProjectedQuad(face.corners, startX, startY),
|
|
19238
|
+
interpolateProjectedQuad(face.corners, endX, startY),
|
|
19239
|
+
interpolateProjectedQuad(face.corners, endX, endY),
|
|
19240
|
+
interpolateProjectedQuad(face.corners, startX, endY),
|
|
19241
|
+
], face.texture[rowIndex][columnIndex]);
|
|
18808
19242
|
}
|
|
18809
19243
|
}
|
|
18810
|
-
|
|
18811
|
-
|
|
18812
|
-
|
|
18813
|
-
|
|
18814
|
-
|
|
18815
|
-
|
|
18816
|
-
|
|
18817
|
-
|
|
18818
|
-
|
|
18819
|
-
|
|
18820
|
-
|
|
19244
|
+
if (face.lightIntensity > 0) {
|
|
19245
|
+
drawProjectedQuad(context, face.corners, `rgba(255, 255, 255, ${0.15 * face.lightIntensity})`);
|
|
19246
|
+
}
|
|
19247
|
+
else if (face.lightIntensity < 0) {
|
|
19248
|
+
drawProjectedQuad(context, face.corners, `rgba(0, 0, 0, ${0.22 * Math.abs(face.lightIntensity)})`);
|
|
19249
|
+
}
|
|
19250
|
+
context.save();
|
|
19251
|
+
context.beginPath();
|
|
19252
|
+
context.moveTo(face.corners[0].x, face.corners[0].y);
|
|
19253
|
+
for (let cornerIndex = 1; cornerIndex < face.corners.length; cornerIndex++) {
|
|
19254
|
+
context.lineTo(face.corners[cornerIndex].x, face.corners[cornerIndex].y);
|
|
19255
|
+
}
|
|
19256
|
+
context.closePath();
|
|
19257
|
+
context.strokeStyle = face.outlineColor;
|
|
19258
|
+
context.lineWidth = Math.max(1.1, getProjectedQuadPerimeter(face.corners) * 0.0045);
|
|
19259
|
+
context.lineJoin = 'round';
|
|
19260
|
+
context.stroke();
|
|
19261
|
+
context.restore();
|
|
18821
19262
|
}
|
|
18822
19263
|
/**
|
|
18823
|
-
*
|
|
19264
|
+
* Draws one filled projected quad.
|
|
18824
19265
|
*
|
|
18825
|
-
* @param
|
|
18826
|
-
* @param
|
|
18827
|
-
* @
|
|
19266
|
+
* @param context Canvas 2D context.
|
|
19267
|
+
* @param corners Quad corners in clockwise order.
|
|
19268
|
+
* @param fillStyle CSS fill style.
|
|
18828
19269
|
*
|
|
18829
|
-
* @private helper of `
|
|
19270
|
+
* @private helper of `minecraft2AvatarVisual`
|
|
18830
19271
|
*/
|
|
18831
|
-
function
|
|
18832
|
-
|
|
18833
|
-
|
|
18834
|
-
|
|
18835
|
-
|
|
18836
|
-
|
|
18837
|
-
|
|
19272
|
+
function drawProjectedQuad(context, corners, fillStyle) {
|
|
19273
|
+
context.beginPath();
|
|
19274
|
+
context.moveTo(corners[0].x, corners[0].y);
|
|
19275
|
+
context.lineTo(corners[1].x, corners[1].y);
|
|
19276
|
+
context.lineTo(corners[2].x, corners[2].y);
|
|
19277
|
+
context.lineTo(corners[3].x, corners[3].y);
|
|
19278
|
+
context.closePath();
|
|
19279
|
+
context.fillStyle = fillStyle;
|
|
19280
|
+
context.fill();
|
|
19281
|
+
}
|
|
19282
|
+
/**
|
|
19283
|
+
* Interpolates one point inside a projected quad across both quad axes.
|
|
19284
|
+
*
|
|
19285
|
+
* @param corners Quad corners in clockwise order.
|
|
19286
|
+
* @param horizontalRatio Horizontal ratio in the range `[0, 1]`.
|
|
19287
|
+
* @param verticalRatio Vertical ratio in the range `[0, 1]`.
|
|
19288
|
+
* @returns Interpolated projected point.
|
|
19289
|
+
*
|
|
19290
|
+
* @private helper of `minecraft2AvatarVisual`
|
|
19291
|
+
*/
|
|
19292
|
+
function interpolateProjectedQuad(corners, horizontalRatio, verticalRatio) {
|
|
19293
|
+
const topPoint = interpolateProjectedPoint(corners[0], corners[1], horizontalRatio);
|
|
19294
|
+
const bottomPoint = interpolateProjectedPoint(corners[3], corners[2], horizontalRatio);
|
|
19295
|
+
return interpolateProjectedPoint(topPoint, bottomPoint, verticalRatio);
|
|
19296
|
+
}
|
|
19297
|
+
/**
|
|
19298
|
+
* Interpolates between two projected points.
|
|
19299
|
+
*
|
|
19300
|
+
* @param startPoint Start point.
|
|
19301
|
+
* @param endPoint End point.
|
|
19302
|
+
* @param ratio Interpolation ratio in the range `[0, 1]`.
|
|
19303
|
+
* @returns Interpolated projected point.
|
|
19304
|
+
*
|
|
19305
|
+
* @private helper of `minecraft2AvatarVisual`
|
|
19306
|
+
*/
|
|
19307
|
+
function interpolateProjectedPoint(startPoint, endPoint, ratio) {
|
|
19308
|
+
return {
|
|
19309
|
+
x: startPoint.x + (endPoint.x - startPoint.x) * ratio,
|
|
19310
|
+
y: startPoint.y + (endPoint.y - startPoint.y) * ratio,
|
|
19311
|
+
z: startPoint.z + (endPoint.z - startPoint.z) * ratio,
|
|
19312
|
+
};
|
|
19313
|
+
}
|
|
19314
|
+
/**
|
|
19315
|
+
* Projects one rotated scene point into canvas coordinates.
|
|
19316
|
+
*
|
|
19317
|
+
* @param point Scene point.
|
|
19318
|
+
* @param size Canvas size in CSS pixels.
|
|
19319
|
+
* @param sceneCenterX Horizontal scene center.
|
|
19320
|
+
* @param sceneCenterY Vertical scene center.
|
|
19321
|
+
* @returns Projected point.
|
|
19322
|
+
*
|
|
19323
|
+
* @private helper of `minecraft2AvatarVisual`
|
|
19324
|
+
*/
|
|
19325
|
+
function projectScenePoint(point, size, sceneCenterX, sceneCenterY) {
|
|
19326
|
+
const cameraDistance = size * CAMERA_DISTANCE_RATIO;
|
|
19327
|
+
const perspectiveScale = cameraDistance / Math.max(cameraDistance - point.z, cameraDistance * 0.35);
|
|
19328
|
+
return {
|
|
19329
|
+
x: sceneCenterX + point.x * perspectiveScale,
|
|
19330
|
+
y: sceneCenterY + point.y * perspectiveScale,
|
|
19331
|
+
z: point.z,
|
|
19332
|
+
};
|
|
19333
|
+
}
|
|
19334
|
+
/**
|
|
19335
|
+
* Applies the local cuboid rotations and translation to one scene point.
|
|
19336
|
+
*
|
|
19337
|
+
* @param localPoint Point in cuboid-local space.
|
|
19338
|
+
* @param center Cuboid center in scene space.
|
|
19339
|
+
* @param rotationX Cuboid pitch in radians.
|
|
19340
|
+
* @param rotationY Cuboid yaw in radians.
|
|
19341
|
+
* @returns Transformed scene-space point.
|
|
19342
|
+
*
|
|
19343
|
+
* @private helper of `minecraft2AvatarVisual`
|
|
19344
|
+
*/
|
|
19345
|
+
function transformScenePoint(localPoint, center, rotationX, rotationY) {
|
|
19346
|
+
const yawedPoint = rotatePointAroundY(localPoint, rotationY);
|
|
19347
|
+
const pitchedPoint = rotatePointAroundX(yawedPoint, rotationX);
|
|
19348
|
+
return {
|
|
19349
|
+
x: center.x + pitchedPoint.x,
|
|
19350
|
+
y: center.y + pitchedPoint.y,
|
|
19351
|
+
z: center.z + pitchedPoint.z,
|
|
19352
|
+
};
|
|
19353
|
+
}
|
|
19354
|
+
/**
|
|
19355
|
+
* Rotates one point around the local Y axis.
|
|
19356
|
+
*
|
|
19357
|
+
* @param point Source point.
|
|
19358
|
+
* @param angle Rotation angle in radians.
|
|
19359
|
+
* @returns Rotated point.
|
|
19360
|
+
*
|
|
19361
|
+
* @private helper of `minecraft2AvatarVisual`
|
|
19362
|
+
*/
|
|
19363
|
+
function rotatePointAroundY(point, angle) {
|
|
19364
|
+
const cosine = Math.cos(angle);
|
|
19365
|
+
const sine = Math.sin(angle);
|
|
19366
|
+
return {
|
|
19367
|
+
x: point.x * cosine + point.z * sine,
|
|
19368
|
+
y: point.y,
|
|
19369
|
+
z: -point.x * sine + point.z * cosine,
|
|
19370
|
+
};
|
|
19371
|
+
}
|
|
19372
|
+
/**
|
|
19373
|
+
* Rotates one point around the local X axis.
|
|
19374
|
+
*
|
|
19375
|
+
* @param point Source point.
|
|
19376
|
+
* @param angle Rotation angle in radians.
|
|
19377
|
+
* @returns Rotated point.
|
|
19378
|
+
*
|
|
19379
|
+
* @private helper of `minecraft2AvatarVisual`
|
|
19380
|
+
*/
|
|
19381
|
+
function rotatePointAroundX(point, angle) {
|
|
19382
|
+
const cosine = Math.cos(angle);
|
|
19383
|
+
const sine = Math.sin(angle);
|
|
19384
|
+
return {
|
|
19385
|
+
x: point.x,
|
|
19386
|
+
y: point.y * cosine - point.z * sine,
|
|
19387
|
+
z: point.y * sine + point.z * cosine,
|
|
19388
|
+
};
|
|
19389
|
+
}
|
|
19390
|
+
/**
|
|
19391
|
+
* Subtracts one 3D point from another.
|
|
19392
|
+
*
|
|
19393
|
+
* @param leftPoint Left point.
|
|
19394
|
+
* @param rightPoint Right point.
|
|
19395
|
+
* @returns Difference vector.
|
|
19396
|
+
*
|
|
19397
|
+
* @private helper of `minecraft2AvatarVisual`
|
|
19398
|
+
*/
|
|
19399
|
+
function subtractPoint3D(leftPoint, rightPoint) {
|
|
19400
|
+
return {
|
|
19401
|
+
x: leftPoint.x - rightPoint.x,
|
|
19402
|
+
y: leftPoint.y - rightPoint.y,
|
|
19403
|
+
z: leftPoint.z - rightPoint.z,
|
|
19404
|
+
};
|
|
19405
|
+
}
|
|
19406
|
+
/**
|
|
19407
|
+
* Computes the 3D cross product of two vectors.
|
|
19408
|
+
*
|
|
19409
|
+
* @param leftVector Left vector.
|
|
19410
|
+
* @param rightVector Right vector.
|
|
19411
|
+
* @returns Cross product.
|
|
19412
|
+
*
|
|
19413
|
+
* @private helper of `minecraft2AvatarVisual`
|
|
19414
|
+
*/
|
|
19415
|
+
function crossProduct3D(leftVector, rightVector) {
|
|
19416
|
+
return {
|
|
19417
|
+
x: leftVector.y * rightVector.z - leftVector.z * rightVector.y,
|
|
19418
|
+
y: leftVector.z * rightVector.x - leftVector.x * rightVector.z,
|
|
19419
|
+
z: leftVector.x * rightVector.y - leftVector.y * rightVector.x,
|
|
19420
|
+
};
|
|
19421
|
+
}
|
|
19422
|
+
/**
|
|
19423
|
+
* Computes the 3D dot product of two vectors.
|
|
19424
|
+
*
|
|
19425
|
+
* @param leftVector Left vector.
|
|
19426
|
+
* @param rightVector Right vector.
|
|
19427
|
+
* @returns Dot product.
|
|
19428
|
+
*
|
|
19429
|
+
* @private helper of `minecraft2AvatarVisual`
|
|
19430
|
+
*/
|
|
19431
|
+
function dotProduct3D(leftVector, rightVector) {
|
|
19432
|
+
return leftVector.x * rightVector.x + leftVector.y * rightVector.y + leftVector.z * rightVector.z;
|
|
19433
|
+
}
|
|
19434
|
+
/**
|
|
19435
|
+
* Normalizes one 3D vector while keeping zero vectors stable.
|
|
19436
|
+
*
|
|
19437
|
+
* @param vector Source vector.
|
|
19438
|
+
* @returns Normalized vector.
|
|
19439
|
+
*
|
|
19440
|
+
* @private helper of `minecraft2AvatarVisual`
|
|
19441
|
+
*/
|
|
19442
|
+
function normalizeVector3(vector) {
|
|
19443
|
+
const length = Math.hypot(vector.x, vector.y, vector.z);
|
|
19444
|
+
if (length === 0) {
|
|
19445
|
+
return vector;
|
|
18838
19446
|
}
|
|
18839
|
-
|
|
18840
|
-
|
|
18841
|
-
|
|
19447
|
+
return {
|
|
19448
|
+
x: vector.x / length,
|
|
19449
|
+
y: vector.y / length,
|
|
19450
|
+
z: vector.z / length,
|
|
19451
|
+
};
|
|
19452
|
+
}
|
|
19453
|
+
/**
|
|
19454
|
+
* Clamps one number into the provided range.
|
|
19455
|
+
*
|
|
19456
|
+
* @param value Input value.
|
|
19457
|
+
* @param minimumValue Inclusive lower bound.
|
|
19458
|
+
* @param maximumValue Inclusive upper bound.
|
|
19459
|
+
* @returns Clamped value.
|
|
19460
|
+
*
|
|
19461
|
+
* @private helper of `minecraft2AvatarVisual`
|
|
19462
|
+
*/
|
|
19463
|
+
function clampNumber$1(value, minimumValue, maximumValue) {
|
|
19464
|
+
return Math.min(maximumValue, Math.max(minimumValue, value));
|
|
19465
|
+
}
|
|
19466
|
+
/**
|
|
19467
|
+
* Measures the perimeter of one projected quad.
|
|
19468
|
+
*
|
|
19469
|
+
* @param corners Quad corners.
|
|
19470
|
+
* @returns Perimeter length.
|
|
19471
|
+
*
|
|
19472
|
+
* @private helper of `minecraft2AvatarVisual`
|
|
19473
|
+
*/
|
|
19474
|
+
function getProjectedQuadPerimeter(corners) {
|
|
19475
|
+
let perimeter = 0;
|
|
19476
|
+
for (let cornerIndex = 0; cornerIndex < corners.length; cornerIndex++) {
|
|
19477
|
+
const currentCorner = corners[cornerIndex];
|
|
19478
|
+
const nextCorner = corners[(cornerIndex + 1) % corners.length];
|
|
19479
|
+
perimeter += Math.hypot(nextCorner.x - currentCorner.x, nextCorner.y - currentCorner.y);
|
|
18842
19480
|
}
|
|
18843
|
-
|
|
18844
|
-
texture[4][6] = palette.accent;
|
|
18845
|
-
texture[5][2] = palette.highlight;
|
|
18846
|
-
texture[5][5] = palette.highlight;
|
|
18847
|
-
return texture;
|
|
19481
|
+
return perimeter;
|
|
18848
19482
|
}
|
|
18849
19483
|
|
|
18850
19484
|
/* eslint-disable no-magic-numbers */
|
|
@@ -20449,6 +21083,7 @@ const AVATAR_VISUALS = [
|
|
|
20449
21083
|
octopus3AvatarVisual,
|
|
20450
21084
|
asciiOctopusAvatarVisual,
|
|
20451
21085
|
minecraftAvatarVisual,
|
|
21086
|
+
minecraft2AvatarVisual,
|
|
20452
21087
|
fractalAvatarVisual,
|
|
20453
21088
|
orbAvatarVisual,
|
|
20454
21089
|
];
|
|
@@ -22657,7 +23292,10 @@ function buildTeamSystemMessageBody(teamEntries) {
|
|
|
22657
23292
|
*/
|
|
22658
23293
|
function buildTeamToolDescription(entry) {
|
|
22659
23294
|
const detailLines = collectTeamEntryDetails(entry).map(({ label, content }) => `${label}: ${content}`);
|
|
22660
|
-
return
|
|
23295
|
+
return spaceTrim$1((block) => `
|
|
23296
|
+
Consult teammate ${entry.teammate.label}
|
|
23297
|
+
${block(detailLines.join('\n'))}
|
|
23298
|
+
`);
|
|
22661
23299
|
}
|
|
22662
23300
|
/**
|
|
22663
23301
|
* Collects structured teammate details that should stay visible to the model.
|
|
@@ -28154,7 +28792,10 @@ function createListedTimeoutsAssistantMessage(options) {
|
|
|
28154
28792
|
if (hiddenCount > 0) {
|
|
28155
28793
|
summaryRows.push(`...and ${hiddenCount} more.`);
|
|
28156
28794
|
}
|
|
28157
|
-
return
|
|
28795
|
+
return spaceTrim$1((block) => `
|
|
28796
|
+
Found ${options.total} ${options.total === 1 ? 'timeout' : 'timeouts'}:
|
|
28797
|
+
${block(summaryRows.join('\n'))}
|
|
28798
|
+
`);
|
|
28158
28799
|
}
|
|
28159
28800
|
/**
|
|
28160
28801
|
* Formats one timeout row for assistant-visible timeout listings.
|