@asiyst/sdk 0.1.27 → 0.1.29
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/dist/index.cjs +434 -118
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +47 -4
- package/dist/index.d.ts +47 -4
- package/dist/index.js +434 -119
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -75,7 +75,7 @@ var ALL_ACTION_KINDS = [
|
|
|
75
75
|
// src/core/constants.ts
|
|
76
76
|
function resolveSdkVersion() {
|
|
77
77
|
{
|
|
78
|
-
return "0.1.
|
|
78
|
+
return "0.1.28";
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
81
|
var SDK_VERSION = resolveSdkVersion();
|
|
@@ -2209,6 +2209,7 @@ var FbxRenderer = class {
|
|
|
2209
2209
|
this.facing = "right";
|
|
2210
2210
|
this.currentPose = "idle";
|
|
2211
2211
|
this.initialRenderCompleted = false;
|
|
2212
|
+
this.baseScale = 1;
|
|
2212
2213
|
}
|
|
2213
2214
|
async mount(container, asset, options) {
|
|
2214
2215
|
const doc = container.ownerDocument;
|
|
@@ -2220,18 +2221,23 @@ var FbxRenderer = class {
|
|
|
2220
2221
|
this.canvas.setAttribute("role", "presentation");
|
|
2221
2222
|
this.canvas.style.opacity = "0";
|
|
2222
2223
|
this.canvas.style.transition = "opacity 0.25s ease";
|
|
2224
|
+
this.canvas.style.background = "transparent";
|
|
2223
2225
|
const glContext = this.canvas.getContext("webgl2") || this.canvas.getContext("webgl");
|
|
2224
2226
|
if (!glContext) {
|
|
2225
2227
|
throw new Error("WebGLRenderingContext is not available or supported in this browser environment");
|
|
2226
2228
|
}
|
|
2227
2229
|
const isMobile = typeof window !== "undefined" && window.innerWidth <= 640;
|
|
2228
|
-
const width = options?.width || (isMobile ?
|
|
2229
|
-
const height = options?.height || (isMobile ?
|
|
2230
|
+
const width = options?.width || (isMobile ? 140 : 190);
|
|
2231
|
+
const height = options?.height || (isMobile ? 280 : 360);
|
|
2230
2232
|
const dpr = typeof window !== "undefined" ? window.devicePixelRatio || 1 : 1;
|
|
2231
2233
|
this.canvas.width = Math.round(width * dpr);
|
|
2232
2234
|
this.canvas.height = Math.round(height * dpr);
|
|
2233
2235
|
this.canvas.style.width = `${width}px`;
|
|
2234
2236
|
this.canvas.style.height = `${height}px`;
|
|
2237
|
+
this.canvas.style.pointerEvents = "none";
|
|
2238
|
+
this.canvas.style.border = "none";
|
|
2239
|
+
this.canvas.style.outline = "none";
|
|
2240
|
+
this.canvas.style.boxShadow = "none";
|
|
2235
2241
|
try {
|
|
2236
2242
|
this.renderer = new THREE.WebGLRenderer({
|
|
2237
2243
|
canvas: this.canvas,
|
|
@@ -2239,6 +2245,7 @@ var FbxRenderer = class {
|
|
|
2239
2245
|
antialias: true,
|
|
2240
2246
|
powerPreference: "high-performance"
|
|
2241
2247
|
});
|
|
2248
|
+
this.renderer.setClearColor(0, 0);
|
|
2242
2249
|
this.renderer.setPixelRatio(Math.min(dpr, 2));
|
|
2243
2250
|
this.renderer.setSize(width, height, false);
|
|
2244
2251
|
this.renderer.outputColorSpace = THREE.SRGBColorSpace;
|
|
@@ -2257,6 +2264,13 @@ var FbxRenderer = class {
|
|
|
2257
2264
|
keyLight.castShadow = true;
|
|
2258
2265
|
keyLight.shadow.mapSize.width = 512;
|
|
2259
2266
|
keyLight.shadow.mapSize.height = 512;
|
|
2267
|
+
keyLight.shadow.camera.near = 0.5;
|
|
2268
|
+
keyLight.shadow.camera.far = 15;
|
|
2269
|
+
keyLight.shadow.camera.left = -1.5;
|
|
2270
|
+
keyLight.shadow.camera.right = 1.5;
|
|
2271
|
+
keyLight.shadow.camera.top = 2.5;
|
|
2272
|
+
keyLight.shadow.camera.bottom = -0.5;
|
|
2273
|
+
keyLight.shadow.bias = -5e-4;
|
|
2260
2274
|
this.scene.add(keyLight);
|
|
2261
2275
|
const fillLight = new THREE.DirectionalLight(15459032, 1.2);
|
|
2262
2276
|
fillLight.position.set(-3, 2, 2);
|
|
@@ -2265,7 +2279,13 @@ var FbxRenderer = class {
|
|
|
2265
2279
|
rimLight.position.set(0, 4, -3);
|
|
2266
2280
|
this.scene.add(rimLight);
|
|
2267
2281
|
const shadowGeo = new THREE.PlaneGeometry(3, 3);
|
|
2268
|
-
const shadowMat = new THREE.ShadowMaterial({
|
|
2282
|
+
const shadowMat = new THREE.ShadowMaterial({
|
|
2283
|
+
opacity: 0.12,
|
|
2284
|
+
depthWrite: false
|
|
2285
|
+
});
|
|
2286
|
+
shadowMat.polygonOffset = true;
|
|
2287
|
+
shadowMat.polygonOffsetFactor = -1;
|
|
2288
|
+
shadowMat.polygonOffsetUnits = -4;
|
|
2269
2289
|
const shadowPlane = new THREE.Mesh(shadowGeo, shadowMat);
|
|
2270
2290
|
shadowPlane.rotation.x = -Math.PI / 2;
|
|
2271
2291
|
shadowPlane.position.y = 0;
|
|
@@ -2317,14 +2337,18 @@ var FbxRenderer = class {
|
|
|
2317
2337
|
rawObject.position.set(-rawCenter.x, -rawBox.min.y, -rawCenter.z);
|
|
2318
2338
|
const targetVisualHeight = 1.8;
|
|
2319
2339
|
const targetScale = targetVisualHeight / rawHeight;
|
|
2340
|
+
this.baseScale = targetScale;
|
|
2320
2341
|
this.modelRoot = new THREE.Group();
|
|
2321
2342
|
this.modelRoot.add(rawObject);
|
|
2322
2343
|
this.modelRoot.scale.setScalar(targetScale);
|
|
2323
2344
|
this.scene.add(this.modelRoot);
|
|
2324
|
-
const visualCenterY = targetVisualHeight * 0.
|
|
2345
|
+
const visualCenterY = targetVisualHeight * 0.5;
|
|
2325
2346
|
const fovRadians = this.camera.fov * Math.PI / 180;
|
|
2326
|
-
const
|
|
2327
|
-
|
|
2347
|
+
const aspect = width / height;
|
|
2348
|
+
const fitDistV = targetVisualHeight * 1.35 / 2 / Math.tan(fovRadians / 2);
|
|
2349
|
+
const fitDistH = 1.1 / 2 / (aspect * Math.tan(fovRadians / 2));
|
|
2350
|
+
const fitDist = Math.max(fitDistV, fitDistH, 2.85);
|
|
2351
|
+
this.camera.position.set(0, visualCenterY, fitDist);
|
|
2328
2352
|
this.camera.lookAt(0, visualCenterY, 0);
|
|
2329
2353
|
rawObject.traverse((child) => {
|
|
2330
2354
|
const mesh = child;
|
|
@@ -2333,24 +2357,41 @@ var FbxRenderer = class {
|
|
|
2333
2357
|
mesh.receiveShadow = true;
|
|
2334
2358
|
}
|
|
2335
2359
|
});
|
|
2360
|
+
options?.metricsTracker?.record("sceneInitComplete");
|
|
2336
2361
|
this.rawObject = rawObject;
|
|
2337
2362
|
this.mixer = new THREE.AnimationMixer(rawObject);
|
|
2338
2363
|
this.allAnimations = [...modelAnimations];
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
if (
|
|
2342
|
-
|
|
2343
|
-
|
|
2364
|
+
const externalAnims = options?.config?.animations || options?.config?.avatar?.animations || [];
|
|
2365
|
+
if (externalAnims.length > 0) {
|
|
2366
|
+
if (modelAnimations.length === 0) {
|
|
2367
|
+
try {
|
|
2368
|
+
await Promise.race([
|
|
2369
|
+
this.loadExternalAnimations(externalAnims, options?.config?.animation),
|
|
2370
|
+
new Promise((resolve) => setTimeout(resolve, 2500))
|
|
2371
|
+
]);
|
|
2372
|
+
} catch (animErr) {
|
|
2373
|
+
if (typeof console !== "undefined" && typeof console.warn === "function") {
|
|
2374
|
+
console.warn("[asiyst] External animation loading notice:", animErr);
|
|
2375
|
+
}
|
|
2376
|
+
}
|
|
2377
|
+
} else {
|
|
2378
|
+
void this.loadExternalAnimations(externalAnims, options?.config?.animation);
|
|
2344
2379
|
}
|
|
2345
2380
|
}
|
|
2381
|
+
this.startInitialIdleAnimation(options?.config);
|
|
2382
|
+
if (this.mixer) {
|
|
2383
|
+
this.mixer.update(0);
|
|
2384
|
+
}
|
|
2346
2385
|
container.replaceChildren();
|
|
2347
2386
|
container.appendChild(this.canvas);
|
|
2348
2387
|
try {
|
|
2349
2388
|
this.renderer.render(this.scene, this.camera);
|
|
2350
2389
|
this.initialRenderCompleted = true;
|
|
2390
|
+
options?.metricsTracker?.record("firstRenderedFrame");
|
|
2351
2391
|
if (this.canvas) {
|
|
2352
2392
|
this.canvas.style.opacity = "1";
|
|
2353
2393
|
}
|
|
2394
|
+
options?.metricsTracker?.record("firstVisibleCorrectlyFramed");
|
|
2354
2395
|
} catch (renderErr) {
|
|
2355
2396
|
const msg = renderErr instanceof Error ? renderErr.message : String(renderErr);
|
|
2356
2397
|
throw new Error(`Initial FBX WebGL render failed: ${msg}`);
|
|
@@ -2358,9 +2399,6 @@ var FbxRenderer = class {
|
|
|
2358
2399
|
this.startLoop();
|
|
2359
2400
|
this.setFacing(this.facing);
|
|
2360
2401
|
this.setPose(this.currentPose);
|
|
2361
|
-
if (options?.config?.animations && options.config.animations.length > 0) {
|
|
2362
|
-
void this.loadExternalAnimations(options.config.animations);
|
|
2363
|
-
}
|
|
2364
2402
|
if (typeof window !== "undefined") {
|
|
2365
2403
|
this.resizeListener = () => this.handleResize();
|
|
2366
2404
|
window.addEventListener("resize", this.resizeListener);
|
|
@@ -2368,7 +2406,7 @@ var FbxRenderer = class {
|
|
|
2368
2406
|
return {
|
|
2369
2407
|
meshCount,
|
|
2370
2408
|
vertexCount: totalVertices,
|
|
2371
|
-
animationCount:
|
|
2409
|
+
animationCount: this.allAnimations.length
|
|
2372
2410
|
};
|
|
2373
2411
|
}
|
|
2374
2412
|
setFacing(direction) {
|
|
@@ -2379,11 +2417,10 @@ var FbxRenderer = class {
|
|
|
2379
2417
|
}
|
|
2380
2418
|
setPose(pose) {
|
|
2381
2419
|
this.currentPose = pose;
|
|
2382
|
-
if (!this.modelRoot) return;
|
|
2383
2420
|
if (this.playAnimation(pose)) {
|
|
2384
2421
|
return;
|
|
2385
2422
|
}
|
|
2386
|
-
if (this.mixer && this.allAnimations.length >
|
|
2423
|
+
if (this.mixer && this.allAnimations.length > 0) {
|
|
2387
2424
|
let targetClip;
|
|
2388
2425
|
if (pose === "speak") {
|
|
2389
2426
|
targetClip = this.allAnimations.find(
|
|
@@ -2393,8 +2430,20 @@ var FbxRenderer = class {
|
|
|
2393
2430
|
targetClip = this.allAnimations.find(
|
|
2394
2431
|
(c) => c.name.toLowerCase().includes("think")
|
|
2395
2432
|
);
|
|
2433
|
+
} else if (pose === "walk") {
|
|
2434
|
+
targetClip = this.allAnimations.find(
|
|
2435
|
+
(c) => c.name.toLowerCase().includes("walk") || c.name.toLowerCase().includes("run")
|
|
2436
|
+
);
|
|
2437
|
+
} else if (pose === "point") {
|
|
2438
|
+
targetClip = this.allAnimations.find(
|
|
2439
|
+
(c) => c.name.toLowerCase().includes("point")
|
|
2440
|
+
);
|
|
2441
|
+
} else if (pose === "celebrate") {
|
|
2442
|
+
targetClip = this.allAnimations.find(
|
|
2443
|
+
(c) => c.name.toLowerCase().includes("celebrat") || c.name.toLowerCase().includes("wave") || c.name.toLowerCase().includes("cheer") || c.name.toLowerCase().includes("jump")
|
|
2444
|
+
);
|
|
2396
2445
|
} else {
|
|
2397
|
-
targetClip = this.allAnimations.find((c) => c.name.toLowerCase().includes("idle")) || this.allAnimations[0];
|
|
2446
|
+
targetClip = this.allAnimations.find((c) => c.name.toLowerCase().includes("idle")) || this.animationMetadataList[0]?.clip || this.allAnimations[0];
|
|
2398
2447
|
}
|
|
2399
2448
|
if (targetClip) {
|
|
2400
2449
|
const newAction = this.mixer.clipAction(targetClip);
|
|
@@ -2405,26 +2454,36 @@ var FbxRenderer = class {
|
|
|
2405
2454
|
}
|
|
2406
2455
|
this.currentAction = newAction;
|
|
2407
2456
|
return;
|
|
2457
|
+
} else if (!this.currentAction?.isRunning()) {
|
|
2458
|
+
this.currentAction?.play();
|
|
2459
|
+
return;
|
|
2408
2460
|
}
|
|
2461
|
+
return;
|
|
2409
2462
|
}
|
|
2410
2463
|
}
|
|
2464
|
+
if (!this.modelRoot) return;
|
|
2465
|
+
this.modelRoot.scale.setScalar(this.baseScale);
|
|
2411
2466
|
switch (pose) {
|
|
2412
2467
|
case "point":
|
|
2413
|
-
this.modelRoot.rotation.z = -0.
|
|
2414
|
-
this.modelRoot.rotation.x = 0.
|
|
2468
|
+
this.modelRoot.rotation.z = -0.06;
|
|
2469
|
+
this.modelRoot.rotation.x = 0.03;
|
|
2415
2470
|
break;
|
|
2416
2471
|
case "think":
|
|
2417
|
-
this.modelRoot.rotation.z = 0.
|
|
2418
|
-
this.modelRoot.rotation.x = -0.
|
|
2472
|
+
this.modelRoot.rotation.z = 0.05;
|
|
2473
|
+
this.modelRoot.rotation.x = -0.04;
|
|
2419
2474
|
break;
|
|
2420
2475
|
case "speak":
|
|
2421
2476
|
this.modelRoot.rotation.y = this.facing === "left" ? -0.22 : 0.22;
|
|
2422
|
-
this.modelRoot.rotation.x = 0.
|
|
2477
|
+
this.modelRoot.rotation.x = 0.03;
|
|
2423
2478
|
break;
|
|
2424
2479
|
case "celebrate":
|
|
2425
2480
|
this.modelRoot.rotation.z = 0;
|
|
2426
|
-
this.modelRoot.rotation.x = -0.
|
|
2427
|
-
|
|
2481
|
+
this.modelRoot.rotation.x = -0.06;
|
|
2482
|
+
break;
|
|
2483
|
+
case "walk":
|
|
2484
|
+
this.modelRoot.rotation.z = 0;
|
|
2485
|
+
this.modelRoot.rotation.x = 0.03;
|
|
2486
|
+
this.modelRoot.rotation.y = this.facing === "left" ? -0.35 : 0.35;
|
|
2428
2487
|
break;
|
|
2429
2488
|
default:
|
|
2430
2489
|
this.modelRoot.rotation.z = 0;
|
|
@@ -2433,88 +2492,172 @@ var FbxRenderer = class {
|
|
|
2433
2492
|
break;
|
|
2434
2493
|
}
|
|
2435
2494
|
}
|
|
2436
|
-
|
|
2495
|
+
startInitialIdleAnimation(config) {
|
|
2496
|
+
if (!this.mixer) return false;
|
|
2497
|
+
const targetQuery = config?.animation?.trim();
|
|
2498
|
+
if (targetQuery && this.playAnimation(targetQuery)) {
|
|
2499
|
+
return true;
|
|
2500
|
+
}
|
|
2501
|
+
const idleByIntent = this.animationMetadataList.find(
|
|
2502
|
+
(m) => m.intent?.toLowerCase() === "idle"
|
|
2503
|
+
);
|
|
2504
|
+
if (idleByIntent && this.playAnimation(idleByIntent.id || idleByIntent.name)) {
|
|
2505
|
+
return true;
|
|
2506
|
+
}
|
|
2507
|
+
const idleByName = this.animationMetadataList.find(
|
|
2508
|
+
(m) => m.name.toLowerCase().includes("idle") || m.clipName && m.clipName.toLowerCase().includes("idle")
|
|
2509
|
+
);
|
|
2510
|
+
if (idleByName && this.playAnimation(idleByName.id || idleByName.name)) {
|
|
2511
|
+
return true;
|
|
2512
|
+
}
|
|
2513
|
+
const embeddedIdle = this.allAnimations.find(
|
|
2514
|
+
(c) => c.name.toLowerCase().includes("idle")
|
|
2515
|
+
);
|
|
2516
|
+
if (embeddedIdle) {
|
|
2517
|
+
const action = this.mixer.clipAction(embeddedIdle);
|
|
2518
|
+
if (this.currentAction !== action) {
|
|
2519
|
+
action.reset().fadeIn(0.25).play();
|
|
2520
|
+
if (this.currentAction) this.currentAction.fadeOut(0.25);
|
|
2521
|
+
this.currentAction = action;
|
|
2522
|
+
}
|
|
2523
|
+
return true;
|
|
2524
|
+
}
|
|
2525
|
+
if (this.animationMetadataList.length > 0) {
|
|
2526
|
+
const firstMeta = this.animationMetadataList[0];
|
|
2527
|
+
if (this.playAnimation(firstMeta.id || firstMeta.name)) {
|
|
2528
|
+
return true;
|
|
2529
|
+
}
|
|
2530
|
+
}
|
|
2531
|
+
if (this.allAnimations.length > 0) {
|
|
2532
|
+
const firstClip = this.allAnimations[0];
|
|
2533
|
+
const action = this.mixer.clipAction(firstClip);
|
|
2534
|
+
if (this.currentAction !== action) {
|
|
2535
|
+
action.reset().fadeIn(0.25).play();
|
|
2536
|
+
if (this.currentAction) this.currentAction.fadeOut(0.25);
|
|
2537
|
+
this.currentAction = action;
|
|
2538
|
+
}
|
|
2539
|
+
return true;
|
|
2540
|
+
}
|
|
2541
|
+
return false;
|
|
2542
|
+
}
|
|
2543
|
+
async loadExternalAnimations(animations, targetAnimationName) {
|
|
2437
2544
|
if (!this.rawObject || !this.mixer) return;
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
const
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
loaded.
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2545
|
+
const pending = animations.filter(
|
|
2546
|
+
(anim) => {
|
|
2547
|
+
if (!anim.assetUrl) return false;
|
|
2548
|
+
const key = (anim.id || anim.name).toLowerCase();
|
|
2549
|
+
return !this.animationMetadataList.some(
|
|
2550
|
+
(m) => m.id && m.id.toLowerCase() === key || m.name.toLowerCase() === key
|
|
2551
|
+
);
|
|
2552
|
+
}
|
|
2553
|
+
);
|
|
2554
|
+
if (pending.length > 0) {
|
|
2555
|
+
await Promise.allSettled(
|
|
2556
|
+
pending.map(async (anim) => {
|
|
2557
|
+
try {
|
|
2558
|
+
const loaded = await this.assetLoader.load(anim.assetUrl);
|
|
2559
|
+
let extractedClips = [];
|
|
2560
|
+
if (loaded.format === "fbx") {
|
|
2561
|
+
const loader = new FBXLoader();
|
|
2562
|
+
if (loaded.resourcePath) {
|
|
2563
|
+
loader.setResourcePath(loaded.resourcePath);
|
|
2564
|
+
}
|
|
2565
|
+
const parsed = loader.parse(loaded.buffer, loaded.resourcePath || "");
|
|
2566
|
+
extractedClips = parsed.animations || [];
|
|
2567
|
+
} else if (loaded.format === "glb") {
|
|
2568
|
+
const loader = new GLTFLoader();
|
|
2569
|
+
const gltf = await new Promise((resolve, reject) => {
|
|
2570
|
+
const glbBuffer = loaded.bin.buffer.slice(
|
|
2571
|
+
loaded.bin.byteOffset,
|
|
2572
|
+
loaded.bin.byteOffset + loaded.bin.byteLength
|
|
2573
|
+
);
|
|
2574
|
+
loader.parse(glbBuffer, loaded.url, resolve, reject);
|
|
2575
|
+
});
|
|
2576
|
+
extractedClips = gltf.animations || [];
|
|
2577
|
+
}
|
|
2578
|
+
for (const rawClip of extractedClips) {
|
|
2579
|
+
const retargeted = this.retargetClip(rawClip, this.rawObject);
|
|
2580
|
+
if (!retargeted) continue;
|
|
2581
|
+
retargeted.name = anim.clipName || anim.name || rawClip.name;
|
|
2582
|
+
this.allAnimations.push(retargeted);
|
|
2583
|
+
this.animationMetadataList.push({
|
|
2584
|
+
id: anim.id,
|
|
2585
|
+
name: anim.name,
|
|
2586
|
+
intent: anim.intent,
|
|
2587
|
+
clipName: anim.clipName,
|
|
2588
|
+
loopMode: anim.loopMode,
|
|
2589
|
+
clip: retargeted
|
|
2590
|
+
});
|
|
2591
|
+
}
|
|
2592
|
+
} catch (err) {
|
|
2593
|
+
if (typeof console !== "undefined" && typeof console.warn === "function") {
|
|
2594
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
2595
|
+
console.warn(`[asiyst] Failed to load external animation "${anim.name}": ${msg}`);
|
|
2596
|
+
}
|
|
2478
2597
|
}
|
|
2479
|
-
}
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2598
|
+
})
|
|
2599
|
+
);
|
|
2600
|
+
}
|
|
2601
|
+
if (this.currentPose === "idle" || targetAnimationName) {
|
|
2602
|
+
this.startInitialIdleAnimation({ animation: targetAnimationName });
|
|
2603
|
+
if (this.mixer) {
|
|
2604
|
+
this.mixer.update(0);
|
|
2485
2605
|
}
|
|
2486
2606
|
}
|
|
2487
2607
|
}
|
|
2488
2608
|
retargetClip(clip, targetObject) {
|
|
2489
2609
|
const targetNodeNames = /* @__PURE__ */ new Set();
|
|
2490
|
-
const
|
|
2610
|
+
const boneLookup = /* @__PURE__ */ new Map();
|
|
2611
|
+
const cleanBoneName = (name) => {
|
|
2612
|
+
return name.replace(/^.*[:|/]/, "").replace(/^(mixamorig\d*|bip01|armature|root)[:_ ]?/i, "").replace(/[^a-zA-Z0-9]/g, "").toLowerCase();
|
|
2613
|
+
};
|
|
2491
2614
|
targetObject.traverse((node) => {
|
|
2492
2615
|
if (node.name) {
|
|
2493
2616
|
targetNodeNames.add(node.name);
|
|
2494
|
-
const
|
|
2495
|
-
|
|
2496
|
-
|
|
2617
|
+
const lower = node.name.toLowerCase();
|
|
2618
|
+
const simpleClean = node.name.replace(/^.*[:|/]/, "").toLowerCase();
|
|
2619
|
+
const stripped = cleanBoneName(node.name);
|
|
2620
|
+
if (!boneLookup.has(lower)) boneLookup.set(lower, node.name);
|
|
2621
|
+
if (!boneLookup.has(simpleClean)) boneLookup.set(simpleClean, node.name);
|
|
2622
|
+
if (stripped && !boneLookup.has(stripped)) boneLookup.set(stripped, node.name);
|
|
2497
2623
|
}
|
|
2498
2624
|
});
|
|
2625
|
+
const isRootOrHips = (name) => {
|
|
2626
|
+
const clean = cleanBoneName(name);
|
|
2627
|
+
return clean === "hips" || clean === "pelvis" || clean === "root";
|
|
2628
|
+
};
|
|
2499
2629
|
const validTracks = [];
|
|
2500
2630
|
for (const track of clip.tracks) {
|
|
2501
2631
|
const dotIdx = track.name.lastIndexOf(".");
|
|
2502
2632
|
if (dotIdx === -1) continue;
|
|
2503
2633
|
const nodePart = track.name.substring(0, dotIdx);
|
|
2504
2634
|
const propPart = track.name.substring(dotIdx);
|
|
2635
|
+
let matchedNodeName;
|
|
2505
2636
|
if (targetNodeNames.has(nodePart)) {
|
|
2506
|
-
|
|
2637
|
+
matchedNodeName = nodePart;
|
|
2507
2638
|
} else {
|
|
2508
|
-
const
|
|
2509
|
-
const
|
|
2510
|
-
|
|
2639
|
+
const lower = nodePart.toLowerCase();
|
|
2640
|
+
const simpleClean = nodePart.replace(/^.*[:|/]/, "").toLowerCase();
|
|
2641
|
+
const stripped = cleanBoneName(nodePart);
|
|
2642
|
+
matchedNodeName = boneLookup.get(lower) || boneLookup.get(simpleClean) || boneLookup.get(stripped);
|
|
2643
|
+
}
|
|
2644
|
+
if (matchedNodeName) {
|
|
2645
|
+
if (propPart.toLowerCase().startsWith(".position") && !isRootOrHips(matchedNodeName)) {
|
|
2646
|
+
continue;
|
|
2647
|
+
}
|
|
2648
|
+
if (matchedNodeName === nodePart) {
|
|
2649
|
+
validTracks.push(track);
|
|
2650
|
+
} else {
|
|
2511
2651
|
const clonedTrack = track.clone();
|
|
2512
|
-
clonedTrack.name = `${
|
|
2652
|
+
clonedTrack.name = `${matchedNodeName}${propPart}`;
|
|
2513
2653
|
validTracks.push(clonedTrack);
|
|
2514
2654
|
}
|
|
2515
2655
|
}
|
|
2516
2656
|
}
|
|
2517
|
-
if (validTracks.length === 0) {
|
|
2657
|
+
if (validTracks.length === 0 || clip.duration <= 0) {
|
|
2658
|
+
if (typeof console !== "undefined" && typeof console.warn === "function") {
|
|
2659
|
+
console.warn(`[asiyst] External animation "${clip.name}" has no compatible bone tracks for this avatar skeleton.`);
|
|
2660
|
+
}
|
|
2518
2661
|
return null;
|
|
2519
2662
|
}
|
|
2520
2663
|
return new THREE.AnimationClip(clip.name, clip.duration, validTracks);
|
|
@@ -2559,6 +2702,8 @@ var FbxRenderer = class {
|
|
|
2559
2702
|
this.currentAction.fadeOut(crossFadeDuration);
|
|
2560
2703
|
}
|
|
2561
2704
|
this.currentAction = action;
|
|
2705
|
+
} else if (!action.isRunning()) {
|
|
2706
|
+
action.reset().play();
|
|
2562
2707
|
}
|
|
2563
2708
|
return true;
|
|
2564
2709
|
}
|
|
@@ -2588,9 +2733,17 @@ var FbxRenderer = class {
|
|
|
2588
2733
|
}
|
|
2589
2734
|
startLoop() {
|
|
2590
2735
|
if (typeof requestAnimationFrame === "undefined") return;
|
|
2736
|
+
if (this.animFrameId !== null && typeof cancelAnimationFrame !== "undefined") {
|
|
2737
|
+
cancelAnimationFrame(this.animFrameId);
|
|
2738
|
+
this.animFrameId = null;
|
|
2739
|
+
}
|
|
2591
2740
|
this.lastTime = typeof performance !== "undefined" ? performance.now() : Date.now();
|
|
2592
2741
|
const tick = (now) => {
|
|
2593
2742
|
if (!this.renderer || !this.scene || !this.camera) return;
|
|
2743
|
+
if (typeof document !== "undefined" && document.hidden) {
|
|
2744
|
+
this.animFrameId = requestAnimationFrame(tick);
|
|
2745
|
+
return;
|
|
2746
|
+
}
|
|
2594
2747
|
const current = now || (typeof performance !== "undefined" ? performance.now() : Date.now());
|
|
2595
2748
|
const delta = Math.min(Math.max((current - this.lastTime) / 1e3, 0), 0.1);
|
|
2596
2749
|
this.lastTime = current;
|
|
@@ -2660,14 +2813,23 @@ var FbxRenderer = class {
|
|
|
2660
2813
|
handleResize() {
|
|
2661
2814
|
if (!this.canvas || !this.renderer || !this.camera) return;
|
|
2662
2815
|
const isMobile = typeof window !== "undefined" && window.innerWidth <= 640;
|
|
2663
|
-
const width = isMobile ?
|
|
2664
|
-
const height = isMobile ?
|
|
2816
|
+
const width = isMobile ? 140 : 190;
|
|
2817
|
+
const height = isMobile ? 280 : 360;
|
|
2665
2818
|
const dpr = typeof window !== "undefined" ? window.devicePixelRatio || 1 : 1;
|
|
2666
2819
|
this.canvas.width = Math.round(width * dpr);
|
|
2667
2820
|
this.canvas.height = Math.round(height * dpr);
|
|
2668
2821
|
this.canvas.style.width = `${width}px`;
|
|
2669
2822
|
this.canvas.style.height = `${height}px`;
|
|
2670
|
-
|
|
2823
|
+
const aspect = width / height;
|
|
2824
|
+
this.camera.aspect = aspect;
|
|
2825
|
+
const targetVisualHeight = 1.8;
|
|
2826
|
+
const visualCenterY = targetVisualHeight * 0.5;
|
|
2827
|
+
const fovRadians = this.camera.fov * Math.PI / 180;
|
|
2828
|
+
const fitDistV = targetVisualHeight * 1.35 / 2 / Math.tan(fovRadians / 2);
|
|
2829
|
+
const fitDistH = 1.1 / 2 / (aspect * Math.tan(fovRadians / 2));
|
|
2830
|
+
const fitDist = Math.max(fitDistV, fitDistH, 2.85);
|
|
2831
|
+
this.camera.position.set(0, visualCenterY, fitDist);
|
|
2832
|
+
this.camera.lookAt(0, visualCenterY, 0);
|
|
2671
2833
|
this.camera.updateProjectionMatrix();
|
|
2672
2834
|
this.renderer.setPixelRatio(Math.min(dpr, 2));
|
|
2673
2835
|
this.renderer.setSize(width, height, false);
|
|
@@ -2692,40 +2854,63 @@ var AVATAR_CSS = `
|
|
|
2692
2854
|
flex-direction: column;
|
|
2693
2855
|
align-items: center;
|
|
2694
2856
|
gap: 4px;
|
|
2695
|
-
pointer-events:
|
|
2857
|
+
pointer-events: none;
|
|
2696
2858
|
user-select: none;
|
|
2697
2859
|
}
|
|
2698
2860
|
.asiyst-avatar.asiyst-animate {
|
|
2699
2861
|
transition: left 420ms cubic-bezier(0.22, 1, 0.36, 1), top 420ms cubic-bezier(0.22, 1, 0.36, 1);
|
|
2700
2862
|
}
|
|
2701
2863
|
.asiyst-figure {
|
|
2702
|
-
border-radius: 28px;
|
|
2703
2864
|
display: grid;
|
|
2704
2865
|
place-items: center;
|
|
2866
|
+
position: relative;
|
|
2867
|
+
cursor: pointer;
|
|
2868
|
+
border: 0 !important;
|
|
2869
|
+
padding: 0;
|
|
2870
|
+
margin: 0;
|
|
2871
|
+
outline: none !important;
|
|
2872
|
+
background: transparent !important;
|
|
2873
|
+
box-shadow: none !important;
|
|
2874
|
+
overflow: visible;
|
|
2875
|
+
-webkit-appearance: none;
|
|
2876
|
+
appearance: none;
|
|
2877
|
+
-webkit-tap-highlight-color: transparent;
|
|
2878
|
+
}
|
|
2879
|
+
.asiyst-figure:focus,
|
|
2880
|
+
.asiyst-figure:focus-visible,
|
|
2881
|
+
.asiyst-figure:active {
|
|
2882
|
+
outline: none !important;
|
|
2883
|
+
border: 0 !important;
|
|
2884
|
+
box-shadow: none !important;
|
|
2885
|
+
}
|
|
2886
|
+
.asiyst-figure::-moz-focus-inner {
|
|
2887
|
+
border: 0 !important;
|
|
2888
|
+
padding: 0;
|
|
2889
|
+
}
|
|
2890
|
+
.asiyst-figure.asiyst-compact-launcher {
|
|
2891
|
+
border-radius: 28px;
|
|
2705
2892
|
color: #fff;
|
|
2706
2893
|
font: 700 14px/1.2 system-ui, sans-serif;
|
|
2707
2894
|
box-shadow: 0 10px 30px rgba(15, 23, 42, 0.28);
|
|
2708
|
-
position: relative;
|
|
2709
2895
|
overflow: hidden;
|
|
2710
|
-
|
|
2711
|
-
|
|
2712
|
-
padding: 0;
|
|
2713
|
-
outline: none;
|
|
2714
|
-
background: #2563eb;
|
|
2715
|
-
transition: width 0.3s ease, height 0.3s ease, background 0.3s ease;
|
|
2896
|
+
background: #2563eb !important;
|
|
2897
|
+
pointer-events: auto;
|
|
2716
2898
|
}
|
|
2717
2899
|
.asiyst-figure.asiyst-3d-active {
|
|
2718
|
-
width:
|
|
2719
|
-
height:
|
|
2900
|
+
width: 190px !important;
|
|
2901
|
+
height: 360px !important;
|
|
2720
2902
|
background: transparent !important;
|
|
2903
|
+
border: 0 !important;
|
|
2721
2904
|
border-radius: 0 !important;
|
|
2722
2905
|
box-shadow: none !important;
|
|
2906
|
+
outline: none !important;
|
|
2723
2907
|
overflow: visible !important;
|
|
2908
|
+
pointer-events: none;
|
|
2724
2909
|
}
|
|
2725
2910
|
@media (max-width: 640px) {
|
|
2726
2911
|
.asiyst-figure.asiyst-3d-active {
|
|
2727
|
-
width:
|
|
2728
|
-
height:
|
|
2912
|
+
width: 140px !important;
|
|
2913
|
+
height: 280px !important;
|
|
2729
2914
|
}
|
|
2730
2915
|
}
|
|
2731
2916
|
.asiyst-avatar-viewport {
|
|
@@ -2734,16 +2919,23 @@ var AVATAR_CSS = `
|
|
|
2734
2919
|
height: 100%;
|
|
2735
2920
|
display: grid;
|
|
2736
2921
|
place-items: center;
|
|
2922
|
+
border: 0 !important;
|
|
2923
|
+
outline: none !important;
|
|
2924
|
+
background: transparent !important;
|
|
2737
2925
|
border-radius: inherit;
|
|
2738
2926
|
overflow: visible;
|
|
2739
|
-
pointer-events:
|
|
2927
|
+
pointer-events: none;
|
|
2740
2928
|
}
|
|
2741
2929
|
.asiyst-avatar-canvas {
|
|
2742
2930
|
width: 100%;
|
|
2743
2931
|
height: 100%;
|
|
2744
2932
|
object-fit: contain;
|
|
2745
2933
|
display: block;
|
|
2746
|
-
|
|
2934
|
+
border: 0 !important;
|
|
2935
|
+
outline: none !important;
|
|
2936
|
+
background: transparent !important;
|
|
2937
|
+
box-shadow: none !important;
|
|
2938
|
+
pointer-events: none;
|
|
2747
2939
|
}
|
|
2748
2940
|
.asiyst-avatar-graphic {
|
|
2749
2941
|
width: 100%;
|
|
@@ -2879,7 +3071,7 @@ var AVATAR_CSS = `
|
|
|
2879
3071
|
var CssAvatarRenderer = class {
|
|
2880
3072
|
constructor() {
|
|
2881
3073
|
this.size = 96;
|
|
2882
|
-
this.hidden =
|
|
3074
|
+
this.hidden = true;
|
|
2883
3075
|
this.facing = "right";
|
|
2884
3076
|
this.pose = "idle";
|
|
2885
3077
|
this.accentColor = "#2563eb";
|
|
@@ -2893,6 +3085,9 @@ var CssAvatarRenderer = class {
|
|
|
2893
3085
|
this.isAssetLoadedFlag = false;
|
|
2894
3086
|
this.isFallbackFlag = false;
|
|
2895
3087
|
}
|
|
3088
|
+
setMetricsTracker(tracker) {
|
|
3089
|
+
this.metricsTracker = tracker;
|
|
3090
|
+
}
|
|
2896
3091
|
mount(container, config) {
|
|
2897
3092
|
const doc = container.ownerDocument;
|
|
2898
3093
|
const style = doc.createElement("style");
|
|
@@ -2901,6 +3096,9 @@ var CssAvatarRenderer = class {
|
|
|
2901
3096
|
this.root = doc.createElement("div");
|
|
2902
3097
|
this.root.className = "asiyst-avatar asiyst-animate";
|
|
2903
3098
|
this.root.setAttribute("role", "img");
|
|
3099
|
+
if (this.hidden) {
|
|
3100
|
+
this.root.style.display = "none";
|
|
3101
|
+
}
|
|
2904
3102
|
this.nameTagEl = doc.createElement("div");
|
|
2905
3103
|
this.nameTagEl.className = "asiyst-name-tag";
|
|
2906
3104
|
const sparkle = doc.createElement("span");
|
|
@@ -2963,7 +3161,7 @@ var CssAvatarRenderer = class {
|
|
|
2963
3161
|
this.size = config.size;
|
|
2964
3162
|
this.accentColor = config.theme.accent ?? "#2563eb";
|
|
2965
3163
|
this.avatarName = config.avatarName;
|
|
2966
|
-
const has3dAsset = Boolean(config.assetUrl || config.thumbnailUrl);
|
|
3164
|
+
const has3dAsset = Boolean(config.assetUrl || config.thumbnailUrl || config.avatarId);
|
|
2967
3165
|
this.has3dAssetConfigured = has3dAsset;
|
|
2968
3166
|
if (config.assetUrl || config.thumbnailUrl) {
|
|
2969
3167
|
this.activeAssetUrl = config.assetUrl ?? config.thumbnailUrl ?? void 0;
|
|
@@ -2983,10 +3181,14 @@ var CssAvatarRenderer = class {
|
|
|
2983
3181
|
if (has3dAsset) {
|
|
2984
3182
|
if (this.figure) {
|
|
2985
3183
|
this.figure.classList.add("asiyst-3d-active");
|
|
3184
|
+
this.figure.classList.remove("asiyst-compact-launcher");
|
|
2986
3185
|
this.figure.style.width = "";
|
|
2987
3186
|
this.figure.style.height = "";
|
|
2988
3187
|
this.figure.style.background = "transparent";
|
|
2989
3188
|
}
|
|
3189
|
+
if (this.nameTagEl) {
|
|
3190
|
+
this.nameTagEl.style.display = this.isAssetLoadedFlag ? "inline-flex" : "none";
|
|
3191
|
+
}
|
|
2990
3192
|
if (this.chatActionBtn) {
|
|
2991
3193
|
this.chatActionBtn.style.display = this.isAssetLoadedFlag && !this.isPanelOpen ? "inline-flex" : "none";
|
|
2992
3194
|
}
|
|
@@ -2994,16 +3196,20 @@ var CssAvatarRenderer = class {
|
|
|
2994
3196
|
if (this.renderState === "error") {
|
|
2995
3197
|
this.renderFallback(true);
|
|
2996
3198
|
} else {
|
|
2997
|
-
this.
|
|
3199
|
+
this.viewport.replaceChildren();
|
|
2998
3200
|
}
|
|
2999
3201
|
}
|
|
3000
3202
|
} else {
|
|
3001
3203
|
if (this.figure) {
|
|
3002
3204
|
this.figure.classList.remove("asiyst-3d-active");
|
|
3205
|
+
this.figure.classList.add("asiyst-compact-launcher");
|
|
3003
3206
|
this.figure.style.width = `${config.size}px`;
|
|
3004
3207
|
this.figure.style.height = `${config.size}px`;
|
|
3005
3208
|
this.figure.style.background = this.accentColor;
|
|
3006
3209
|
}
|
|
3210
|
+
if (this.nameTagEl) {
|
|
3211
|
+
this.nameTagEl.style.display = "none";
|
|
3212
|
+
}
|
|
3007
3213
|
if (this.chatActionBtn) {
|
|
3008
3214
|
this.chatActionBtn.style.display = "none";
|
|
3009
3215
|
}
|
|
@@ -3018,7 +3224,10 @@ var CssAvatarRenderer = class {
|
|
|
3018
3224
|
this.chatActionBtn.style.display = open ? "none" : "inline-flex";
|
|
3019
3225
|
}
|
|
3020
3226
|
}
|
|
3021
|
-
async loadAsset(config) {
|
|
3227
|
+
async loadAsset(config, metricsTracker) {
|
|
3228
|
+
if (metricsTracker) {
|
|
3229
|
+
this.metricsTracker = metricsTracker;
|
|
3230
|
+
}
|
|
3022
3231
|
const assetUrl = config.assetUrl ?? config.thumbnailUrl;
|
|
3023
3232
|
if (!assetUrl) {
|
|
3024
3233
|
this.renderState = "idle";
|
|
@@ -3035,14 +3244,31 @@ var CssAvatarRenderer = class {
|
|
|
3035
3244
|
if (this.figure) {
|
|
3036
3245
|
this.figure.setAttribute("data-state", "loading");
|
|
3037
3246
|
this.figure.classList.add("asiyst-3d-active");
|
|
3247
|
+
this.figure.classList.remove("asiyst-compact-launcher");
|
|
3038
3248
|
this.figure.style.width = "";
|
|
3039
3249
|
this.figure.style.height = "";
|
|
3040
3250
|
this.figure.style.background = "transparent";
|
|
3041
3251
|
}
|
|
3042
|
-
this.
|
|
3252
|
+
if (this.nameTagEl) {
|
|
3253
|
+
this.nameTagEl.style.display = "none";
|
|
3254
|
+
}
|
|
3255
|
+
if (this.chatActionBtn) {
|
|
3256
|
+
this.chatActionBtn.style.display = "none";
|
|
3257
|
+
}
|
|
3258
|
+
if (this.viewport) {
|
|
3259
|
+
this.renderLoader();
|
|
3260
|
+
}
|
|
3043
3261
|
try {
|
|
3262
|
+
this.metricsTracker?.record("assetRequestStart");
|
|
3044
3263
|
const asset = await this.assetLoader.load(assetUrl, { timeoutMs: 6e4 });
|
|
3264
|
+
this.metricsTracker?.record("assetDownloadComplete");
|
|
3265
|
+
const byteSize = asset.buffer?.byteLength ?? asset.bin?.byteLength ?? asset.size;
|
|
3266
|
+
this.metricsTracker?.setAssetInfo({
|
|
3267
|
+
format: asset.format,
|
|
3268
|
+
byteSize: typeof byteSize === "number" ? byteSize : void 0
|
|
3269
|
+
});
|
|
3045
3270
|
await this.renderLoadedAsset(asset, config);
|
|
3271
|
+
this.metricsTracker?.record("parseAndDecodeComplete");
|
|
3046
3272
|
this.renderState = "ready";
|
|
3047
3273
|
this.isAssetLoadedFlag = true;
|
|
3048
3274
|
this.isFallbackFlag = false;
|
|
@@ -3050,10 +3276,14 @@ var CssAvatarRenderer = class {
|
|
|
3050
3276
|
if (this.figure) {
|
|
3051
3277
|
this.figure.setAttribute("data-state", "ready");
|
|
3052
3278
|
this.figure.classList.add("asiyst-3d-active");
|
|
3279
|
+
this.figure.classList.remove("asiyst-compact-launcher");
|
|
3053
3280
|
this.figure.style.width = "";
|
|
3054
3281
|
this.figure.style.height = "";
|
|
3055
3282
|
this.figure.style.background = "transparent";
|
|
3056
3283
|
}
|
|
3284
|
+
if (this.nameTagEl) {
|
|
3285
|
+
this.nameTagEl.style.display = "inline-flex";
|
|
3286
|
+
}
|
|
3057
3287
|
if (this.chatActionBtn) {
|
|
3058
3288
|
this.chatActionBtn.style.display = this.isPanelOpen ? "none" : "inline-flex";
|
|
3059
3289
|
}
|
|
@@ -3066,6 +3296,14 @@ var CssAvatarRenderer = class {
|
|
|
3066
3296
|
this.isFallbackFlag = true;
|
|
3067
3297
|
if (this.figure) {
|
|
3068
3298
|
this.figure.setAttribute("data-state", "error");
|
|
3299
|
+
this.figure.classList.remove("asiyst-3d-active");
|
|
3300
|
+
this.figure.classList.add("asiyst-compact-launcher");
|
|
3301
|
+
this.figure.style.width = `${this.size}px`;
|
|
3302
|
+
this.figure.style.height = `${this.size}px`;
|
|
3303
|
+
this.figure.style.background = this.accentColor;
|
|
3304
|
+
}
|
|
3305
|
+
if (this.nameTagEl) {
|
|
3306
|
+
this.nameTagEl.style.display = "none";
|
|
3069
3307
|
}
|
|
3070
3308
|
if (this.chatActionBtn) {
|
|
3071
3309
|
this.chatActionBtn.style.display = "none";
|
|
@@ -3094,14 +3332,20 @@ var CssAvatarRenderer = class {
|
|
|
3094
3332
|
}
|
|
3095
3333
|
if (asset.format === "fbx" || asset.format === "glb") {
|
|
3096
3334
|
const isMobile = typeof window !== "undefined" && window.innerWidth <= 640;
|
|
3097
|
-
const width = isMobile ?
|
|
3098
|
-
const height = isMobile ?
|
|
3335
|
+
const width = isMobile ? 140 : 190;
|
|
3336
|
+
const height = isMobile ? 280 : 360;
|
|
3099
3337
|
this.fbxRenderer = new FbxRenderer();
|
|
3100
3338
|
this.renderMetrics = await this.fbxRenderer.mount(this.viewport, asset, {
|
|
3101
3339
|
accentColor: this.accentColor,
|
|
3102
3340
|
config,
|
|
3103
3341
|
width,
|
|
3104
|
-
height
|
|
3342
|
+
height,
|
|
3343
|
+
metricsTracker: this.metricsTracker
|
|
3344
|
+
});
|
|
3345
|
+
this.metricsTracker?.setAssetInfo({
|
|
3346
|
+
meshCount: this.renderMetrics.meshCount,
|
|
3347
|
+
vertexCount: this.renderMetrics.vertexCount,
|
|
3348
|
+
animationCount: this.renderMetrics.animationCount
|
|
3105
3349
|
});
|
|
3106
3350
|
this.fbxRenderer.setFacing(this.facing);
|
|
3107
3351
|
this.fbxRenderer.setPose(this.pose);
|
|
@@ -3192,7 +3436,7 @@ var CssAvatarRenderer = class {
|
|
|
3192
3436
|
getSize() {
|
|
3193
3437
|
if (this.isAssetLoadedFlag || this.has3dAssetConfigured) {
|
|
3194
3438
|
const isMobile = typeof window !== "undefined" && window.innerWidth <= 640;
|
|
3195
|
-
return { width: isMobile ?
|
|
3439
|
+
return { width: isMobile ? 140 : 190, height: isMobile ? 310 : 390 };
|
|
3196
3440
|
}
|
|
3197
3441
|
return { width: this.size, height: this.size + 28 };
|
|
3198
3442
|
}
|
|
@@ -4052,9 +4296,9 @@ var ConversationPanel = class {
|
|
|
4052
4296
|
this.style.textContent = `
|
|
4053
4297
|
.asiyst-panel {
|
|
4054
4298
|
position: fixed;
|
|
4055
|
-
right:
|
|
4299
|
+
right: 216px;
|
|
4056
4300
|
bottom: 20px;
|
|
4057
|
-
width: min(380px, calc(100vw -
|
|
4301
|
+
width: min(380px, calc(100vw - 240px));
|
|
4058
4302
|
max-height: min(560px, 75vh);
|
|
4059
4303
|
background: #ffffff;
|
|
4060
4304
|
color: #0f172a;
|
|
@@ -4438,10 +4682,59 @@ function createSdkLifecycleEmitter(sink) {
|
|
|
4438
4682
|
return new LifecycleEmitter(new UnsupportedLifecycleSink());
|
|
4439
4683
|
}
|
|
4440
4684
|
|
|
4685
|
+
// src/avatar/AvatarMetrics.ts
|
|
4686
|
+
var AvatarMetricsTracker = class {
|
|
4687
|
+
constructor() {
|
|
4688
|
+
this.timestamps = {};
|
|
4689
|
+
this.assetInfo = {};
|
|
4690
|
+
}
|
|
4691
|
+
record(step, timestamp = typeof performance !== "undefined" ? performance.now() : Date.now()) {
|
|
4692
|
+
if (!this.timestamps[step]) {
|
|
4693
|
+
this.timestamps[step] = timestamp;
|
|
4694
|
+
}
|
|
4695
|
+
}
|
|
4696
|
+
setAssetInfo(info) {
|
|
4697
|
+
this.assetInfo = { ...this.assetInfo, ...info };
|
|
4698
|
+
}
|
|
4699
|
+
getMetrics() {
|
|
4700
|
+
const t = this.timestamps;
|
|
4701
|
+
const base = t.sdkInit ?? t.containerCreated ?? 0;
|
|
4702
|
+
const downloadStart = t.assetRequestStart ?? base;
|
|
4703
|
+
const downloadEnd = t.assetDownloadComplete ?? downloadStart;
|
|
4704
|
+
const parseEnd = t.parseAndDecodeComplete ?? downloadEnd;
|
|
4705
|
+
const sceneEnd = t.sceneInitComplete ?? parseEnd;
|
|
4706
|
+
const firstRender = t.firstRenderedFrame ?? sceneEnd;
|
|
4707
|
+
const firstVisible = t.firstVisibleCorrectlyFramed ?? firstRender;
|
|
4708
|
+
return {
|
|
4709
|
+
timestamps: {
|
|
4710
|
+
sdkInit: t.sdkInit ?? base,
|
|
4711
|
+
containerCreated: t.containerCreated ?? base,
|
|
4712
|
+
configRetrieved: t.configRetrieved ?? base,
|
|
4713
|
+
assetRequestStart: downloadStart,
|
|
4714
|
+
assetDownloadComplete: downloadEnd,
|
|
4715
|
+
parseAndDecodeComplete: parseEnd,
|
|
4716
|
+
sceneInitComplete: sceneEnd,
|
|
4717
|
+
firstRenderedFrame: firstRender,
|
|
4718
|
+
firstVisibleCorrectlyFramed: firstVisible
|
|
4719
|
+
},
|
|
4720
|
+
durations: {
|
|
4721
|
+
configRetrievalMs: Math.max(0, (t.configRetrieved ?? base) - base),
|
|
4722
|
+
downloadDurationMs: Math.max(0, downloadEnd - downloadStart),
|
|
4723
|
+
parseDurationMs: Math.max(0, parseEnd - downloadEnd),
|
|
4724
|
+
sceneInitDurationMs: Math.max(0, sceneEnd - parseEnd),
|
|
4725
|
+
firstRenderDurationMs: Math.max(0, firstRender - sceneEnd),
|
|
4726
|
+
timeToFirstVisibleMs: Math.max(0, firstVisible - base)
|
|
4727
|
+
},
|
|
4728
|
+
asset: { ...this.assetInfo }
|
|
4729
|
+
};
|
|
4730
|
+
}
|
|
4731
|
+
};
|
|
4732
|
+
|
|
4441
4733
|
// src/core/Runtime.ts
|
|
4442
4734
|
var AsiystRuntime = class {
|
|
4443
4735
|
constructor(options, doc, win) {
|
|
4444
4736
|
this.events = new EventBus();
|
|
4737
|
+
this.metricsTracker = new AvatarMetricsTracker();
|
|
4445
4738
|
this.map = new WebsiteMap();
|
|
4446
4739
|
this.observer = new DomObserver(() => this.rescan());
|
|
4447
4740
|
this.lifecycle = createSdkLifecycleEmitter();
|
|
@@ -4489,6 +4782,9 @@ var AsiystRuntime = class {
|
|
|
4489
4782
|
this.renderer = new CssAvatarRenderer();
|
|
4490
4783
|
this.renderer.onOpenChat = () => this.open();
|
|
4491
4784
|
this.renderer.mount(this.host.chrome, this.config.get());
|
|
4785
|
+
this.metricsTracker.record("sdkInit");
|
|
4786
|
+
this.metricsTracker.record("containerCreated");
|
|
4787
|
+
this.renderer.setMetricsTracker(this.metricsTracker);
|
|
4492
4788
|
this.highlights = new HighlightLayer(this.host.overlay, win);
|
|
4493
4789
|
this.movement = new MovementEngine(win, doc, this.renderer, this.resolver, this.events, () => this.config.get());
|
|
4494
4790
|
const live = createLiveRegion(this.host.shadow);
|
|
@@ -4527,7 +4823,6 @@ var AsiystRuntime = class {
|
|
|
4527
4823
|
this.movement.start();
|
|
4528
4824
|
this.analytics.start();
|
|
4529
4825
|
this.rescan();
|
|
4530
|
-
this.avatar.show();
|
|
4531
4826
|
const figure = this.renderer.getFigure();
|
|
4532
4827
|
if (figure) {
|
|
4533
4828
|
this.figureClickListener = () => this.open();
|
|
@@ -4540,7 +4835,10 @@ var AsiystRuntime = class {
|
|
|
4540
4835
|
}
|
|
4541
4836
|
async start() {
|
|
4542
4837
|
this.events.emit("asiyst:initialized", { projectId: this.options.projectId });
|
|
4838
|
+
this.avatar.show();
|
|
4839
|
+
this.movement.goToAnchor();
|
|
4543
4840
|
const cfg = await isolateAsync(() => this.config.refresh(), this.config.get());
|
|
4841
|
+
this.metricsTracker.record("configRetrieved");
|
|
4544
4842
|
const domainCheck = validateWebsiteDomain(cfg, window.location.href);
|
|
4545
4843
|
if (!domainCheck.allowed) {
|
|
4546
4844
|
this.connectionStatus = "disconnected";
|
|
@@ -4552,7 +4850,6 @@ var AsiystRuntime = class {
|
|
|
4552
4850
|
return;
|
|
4553
4851
|
}
|
|
4554
4852
|
this.avatar.applyConfig(cfg);
|
|
4555
|
-
this.avatar.show();
|
|
4556
4853
|
this.movement.goToAnchor();
|
|
4557
4854
|
this.lifecycle.emit("sdk.verification_started", {
|
|
4558
4855
|
projectId: this.options.projectId,
|
|
@@ -4578,7 +4875,15 @@ var AsiystRuntime = class {
|
|
|
4578
4875
|
});
|
|
4579
4876
|
const assetTarget = cfg.assetUrl ?? cfg.thumbnailUrl;
|
|
4580
4877
|
if (assetTarget) {
|
|
4581
|
-
|
|
4878
|
+
try {
|
|
4879
|
+
await this.loadAvatarAsset(cfg, assetTarget);
|
|
4880
|
+
} finally {
|
|
4881
|
+
this.avatar.show();
|
|
4882
|
+
this.movement.goToAnchor();
|
|
4883
|
+
}
|
|
4884
|
+
} else {
|
|
4885
|
+
this.avatar.show();
|
|
4886
|
+
this.movement.goToAnchor();
|
|
4582
4887
|
}
|
|
4583
4888
|
this.startConfigRevalidationScheduler();
|
|
4584
4889
|
}
|
|
@@ -4592,7 +4897,7 @@ var AsiystRuntime = class {
|
|
|
4592
4897
|
assetUrl: assetTarget
|
|
4593
4898
|
});
|
|
4594
4899
|
try {
|
|
4595
|
-
const loaded = await this.renderer.loadAsset(cfg);
|
|
4900
|
+
const loaded = await this.renderer.loadAsset(cfg, this.metricsTracker);
|
|
4596
4901
|
if (loaded) {
|
|
4597
4902
|
this.movement.goToAnchor();
|
|
4598
4903
|
const format = this.renderer.getLoadedFormat();
|
|
@@ -4611,15 +4916,19 @@ var AsiystRuntime = class {
|
|
|
4611
4916
|
publishedVersion: cfg.publishedVersion
|
|
4612
4917
|
});
|
|
4613
4918
|
if (isRendered) {
|
|
4919
|
+
const metrics = this.metricsTracker.getMetrics();
|
|
4920
|
+
const durationMs = metrics?.durations.timeToFirstVisibleMs;
|
|
4614
4921
|
this.events.emit("asiyst:avatar:rendered", {
|
|
4615
4922
|
avatarId: this.options.avatarId ?? cfg.avatarId,
|
|
4616
|
-
format
|
|
4923
|
+
format,
|
|
4924
|
+
durationMs
|
|
4617
4925
|
});
|
|
4618
4926
|
void this.cloud.sendTelemetryEvent("avatar_rendered", {
|
|
4619
4927
|
avatarId: this.options.avatarId ?? cfg.avatarId ?? cfg.avatarName,
|
|
4620
4928
|
avatarName: cfg.avatarName,
|
|
4621
4929
|
format,
|
|
4622
|
-
publishedVersion: cfg.publishedVersion
|
|
4930
|
+
publishedVersion: cfg.publishedVersion,
|
|
4931
|
+
durationMs
|
|
4623
4932
|
});
|
|
4624
4933
|
}
|
|
4625
4934
|
return true;
|
|
@@ -4739,6 +5048,9 @@ var AsiystRuntime = class {
|
|
|
4739
5048
|
getRenderer() {
|
|
4740
5049
|
return this.renderer;
|
|
4741
5050
|
}
|
|
5051
|
+
getAvatarPerformanceMetrics() {
|
|
5052
|
+
return this.metricsTracker.getMetrics();
|
|
5053
|
+
}
|
|
4742
5054
|
avatarApi() {
|
|
4743
5055
|
return this.avatar;
|
|
4744
5056
|
}
|
|
@@ -5065,6 +5377,9 @@ var Asiyst = {
|
|
|
5065
5377
|
isRuntimeConnected() {
|
|
5066
5378
|
return requireRuntime().getConnectionStatus() === "connected";
|
|
5067
5379
|
},
|
|
5380
|
+
getAvatarPerformanceMetrics() {
|
|
5381
|
+
return requireRuntime().getAvatarPerformanceMetrics();
|
|
5382
|
+
},
|
|
5068
5383
|
avatar: {
|
|
5069
5384
|
show() {
|
|
5070
5385
|
withIsolation(() => requireRuntime().avatarApi().show());
|
|
@@ -5123,6 +5438,6 @@ var Asiyst = {
|
|
|
5123
5438
|
}
|
|
5124
5439
|
};
|
|
5125
5440
|
|
|
5126
|
-
export { ActionNotAllowedError, Asiyst, AsiystError, AssetLoader, AuthenticationError, ConfigurationError, CssAvatarRenderer, FbxRenderer, InitializationError, NetworkError, SDK_VERSION, TargetNotFoundError, TaskExecutionError, TaskStatus, anchorToViewport, canNavigateTo, canTransition, computeAvatarDestination, evaluateActionPermission, fallbackConfig, isActionAllowed, isSafeSelector, normalizeProjectConfig, sanitizeText, validateInitOptions, validateWebsiteDomain };
|
|
5441
|
+
export { ActionNotAllowedError, Asiyst, AsiystError, AssetLoader, AuthenticationError, AvatarMetricsTracker, ConfigurationError, CssAvatarRenderer, FbxRenderer, InitializationError, NetworkError, SDK_VERSION, TargetNotFoundError, TaskExecutionError, TaskStatus, anchorToViewport, canNavigateTo, canTransition, computeAvatarDestination, evaluateActionPermission, fallbackConfig, isActionAllowed, isSafeSelector, normalizeProjectConfig, sanitizeText, validateInitOptions, validateWebsiteDomain };
|
|
5127
5442
|
//# sourceMappingURL=index.js.map
|
|
5128
5443
|
//# sourceMappingURL=index.js.map
|