viral-viewer-2 6.4.5 → 6.4.7
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.
|
@@ -4,5 +4,6 @@ export declare class ViralAvatarManager {
|
|
|
4
4
|
private viralViewerApi;
|
|
5
5
|
avatars: ViralAvatar[];
|
|
6
6
|
constructor(viralViewerApi: ViralViewerApi);
|
|
7
|
-
load(avatarGLBUrl: string, idleUrl: string, walkUrl: string, id?: string): ViralAvatar;
|
|
7
|
+
load(avatarGLBUrl: string, idleUrl: string, walkUrl: string, scaleRatio?: number, speed?: number, id?: string, name?: string): ViralAvatar;
|
|
8
|
+
remove(id: string): void;
|
|
8
9
|
}
|
|
@@ -2,16 +2,24 @@ import { Vector3 } from "three";
|
|
|
2
2
|
import { ViralViewerApi } from "../..";
|
|
3
3
|
export declare class ViralAvatar {
|
|
4
4
|
private viralViewerApi;
|
|
5
|
+
scaleRatio: number;
|
|
5
6
|
private mixer;
|
|
6
7
|
private idleAnimation;
|
|
7
8
|
private walkAnimation;
|
|
8
9
|
private avatar;
|
|
9
10
|
private destination;
|
|
10
11
|
isReady: boolean;
|
|
12
|
+
name: string;
|
|
11
13
|
id: string;
|
|
12
|
-
|
|
14
|
+
private MOVEMENT_SPEED;
|
|
15
|
+
private nameDiv;
|
|
16
|
+
private chatDiv;
|
|
17
|
+
private talkContent;
|
|
18
|
+
constructor(viralViewerApi: ViralViewerApi, avatarGLBUrl: string, idleUrl: string, walkUrl: string, scaleRatio?: number, speed?: number, id?: string, name?: string);
|
|
13
19
|
idle(): void;
|
|
14
20
|
walk(): void;
|
|
21
|
+
talk(content: string): void;
|
|
15
22
|
render(delta: number): void;
|
|
16
23
|
updateDestination(point: Vector3): void;
|
|
24
|
+
dispose(): void;
|
|
17
25
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -42461,22 +42461,28 @@ class t3 {
|
|
|
42461
42461
|
return i;
|
|
42462
42462
|
}
|
|
42463
42463
|
}
|
|
42464
|
-
const i3 = 0.
|
|
42464
|
+
const i3 = 0.032;
|
|
42465
42465
|
class n3 {
|
|
42466
|
-
constructor(e, t, i, s, r) {
|
|
42467
|
-
this.viralViewerApi = e, this.mixer = null, this.idleAnimation = null, this.walkAnimation = null, this.avatar = null, this.destination = null, this.isReady = !1, this.id = t3.generateRandomString(10),
|
|
42466
|
+
constructor(e, t, i, s, r = 2, a = 1, l, h) {
|
|
42467
|
+
this.viralViewerApi = e, this.scaleRatio = r, this.mixer = null, this.idleAnimation = null, this.walkAnimation = null, this.avatar = null, this.destination = null, this.isReady = !1, this.name = "", this.id = t3.generateRandomString(10), this.MOVEMENT_SPEED = 0.032, this.talkContent = "", l && (this.id = l), h && (this.name = h, this.nameDiv = document.createElement("div"), this.nameDiv.setAttribute(
|
|
42468
|
+
"style",
|
|
42469
|
+
"position: absolute; top:0; left:0;transform: translateX(-50%); pointer-events: none; background-color:rgba(226, 230, 220,1); color:rgb(23, 49, 44); padding: 5px ; border-radius:5px; font-size:x-small"
|
|
42470
|
+
), this.nameDiv.id = this.id, this.nameDiv.append(this.name), this.viralViewerApi.targetElement.appendChild(this.nameDiv)), this.chatDiv = document.createElement("div"), this.chatDiv.setAttribute(
|
|
42471
|
+
"style",
|
|
42472
|
+
"position: absolute;display:none; top:0; left:0;transform: translate(-50%, -100%); pointer-events: none; background-color:rgba(226, 230, 220,1); color:rgb(23, 49, 44); padding: 5px ; border-radius:5px; font-size:x-small"
|
|
42473
|
+
), this.viralViewerApi.targetElement.appendChild(this.chatDiv), this.MOVEMENT_SPEED = i3 * a, this.viralViewerApi.viralLoader.threeLoader.loadGLTF(
|
|
42468
42474
|
t,
|
|
42469
|
-
(
|
|
42470
|
-
this.avatar =
|
|
42471
|
-
let
|
|
42472
|
-
this.avatar.scale.copy(
|
|
42475
|
+
(u) => {
|
|
42476
|
+
this.avatar = u.scene;
|
|
42477
|
+
let f = new G(r, r, r);
|
|
42478
|
+
this.avatar.scale.copy(f), console.log(this.avatar), this.mixer = new R2(u.scene), this.viralViewerApi.viralScene.scene.add(u.scene), this.viralViewerApi.viralRenderer.render(), this.viralViewerApi.viralLoader.threeLoader.loadGLTF(
|
|
42473
42479
|
i,
|
|
42474
|
-
(
|
|
42475
|
-
this.idleAnimation = this.mixer.clipAction(
|
|
42480
|
+
(p) => {
|
|
42481
|
+
this.idleAnimation = this.mixer.clipAction(p.animations[0]), this.viralViewerApi.viralLoader.threeLoader.loadGLTF(
|
|
42476
42482
|
s,
|
|
42477
|
-
(
|
|
42483
|
+
(g) => {
|
|
42478
42484
|
this.walkAnimation = this.mixer.clipAction(
|
|
42479
|
-
|
|
42485
|
+
g.animations[0]
|
|
42480
42486
|
), Sn.information("load avatar succeed!"), this.isReady = !0, this.idle();
|
|
42481
42487
|
}
|
|
42482
42488
|
);
|
|
@@ -42491,12 +42497,37 @@ class n3 {
|
|
|
42491
42497
|
walk() {
|
|
42492
42498
|
this.walkAnimation && this.walkAnimation.reset().fadeIn(0.34).play();
|
|
42493
42499
|
}
|
|
42500
|
+
talk(e) {
|
|
42501
|
+
this.talkContent = e, this.chatDiv.append(this.talkContent), setTimeout(() => {
|
|
42502
|
+
this.talkContent = "", this.chatDiv.firstChild && this.chatDiv.removeChild(this.chatDiv.firstChild);
|
|
42503
|
+
}, 4e3);
|
|
42504
|
+
}
|
|
42494
42505
|
render(e) {
|
|
42495
42506
|
if (this.avatar && this.mixer) {
|
|
42496
42507
|
let t = this.avatar.getObjectByName("Hips");
|
|
42497
|
-
|
|
42498
|
-
|
|
42499
|
-
|
|
42508
|
+
this.mixer.update(e), t.position.set(0, t.position.y, 0);
|
|
42509
|
+
let i = this.viralViewerApi.viralCamera.worldToClient(
|
|
42510
|
+
new G(
|
|
42511
|
+
this.avatar.position.x,
|
|
42512
|
+
this.avatar.position.y - 1,
|
|
42513
|
+
this.avatar.position.z
|
|
42514
|
+
)
|
|
42515
|
+
);
|
|
42516
|
+
if (i && (this.nameDiv.style.left = `${i.x}px`, this.nameDiv.style.top = `${i.y}px`), this.talkContent.length > 0) {
|
|
42517
|
+
this.chatDiv.style.display = "block";
|
|
42518
|
+
let s = this.viralViewerApi.viralCamera.worldToClient(
|
|
42519
|
+
new G(
|
|
42520
|
+
this.avatar.position.x,
|
|
42521
|
+
this.avatar.position.y + 2 * this.scaleRatio + 1,
|
|
42522
|
+
this.avatar.position.z
|
|
42523
|
+
)
|
|
42524
|
+
);
|
|
42525
|
+
s && (this.chatDiv.style.left = `${s.x}px`, this.chatDiv.style.top = `${s.y}px`);
|
|
42526
|
+
} else
|
|
42527
|
+
this.chatDiv.style.display = "none";
|
|
42528
|
+
if (this.destination && this.avatar.position.distanceTo(this.destination) > 0.1) {
|
|
42529
|
+
const s = this.avatar.position.clone().sub(this.destination).normalize().multiplyScalar(this.MOVEMENT_SPEED);
|
|
42530
|
+
this.avatar.position.sub(s), this.avatar.lookAt(this.destination), this.idle();
|
|
42500
42531
|
} else
|
|
42501
42532
|
this.walk();
|
|
42502
42533
|
}
|
|
@@ -42504,20 +42535,31 @@ class n3 {
|
|
|
42504
42535
|
updateDestination(e) {
|
|
42505
42536
|
this.destination = e;
|
|
42506
42537
|
}
|
|
42538
|
+
dispose() {
|
|
42539
|
+
var e, t, i, s, r;
|
|
42540
|
+
(e = this.avatar) == null || e.removeFromParent(), this.mixer = null, this.walkAnimation = null, this.avatar = null, (i = (t = this.nameDiv) == null ? void 0 : t.parentNode) == null || i.removeChild(this.nameDiv), (r = (s = this.chatDiv) == null ? void 0 : s.parentNode) == null || r.removeChild(this.chatDiv);
|
|
42541
|
+
}
|
|
42507
42542
|
}
|
|
42508
42543
|
class s3 {
|
|
42509
42544
|
constructor(e) {
|
|
42510
42545
|
this.viralViewerApi = e, this.avatars = [];
|
|
42511
42546
|
}
|
|
42512
|
-
load(e, t, i, s) {
|
|
42513
|
-
let
|
|
42547
|
+
load(e, t, i, s = 2, r = 1, a, l) {
|
|
42548
|
+
let h = new n3(
|
|
42514
42549
|
this.viralViewerApi,
|
|
42515
42550
|
e,
|
|
42516
42551
|
t,
|
|
42517
42552
|
i,
|
|
42518
|
-
s
|
|
42553
|
+
s,
|
|
42554
|
+
r,
|
|
42555
|
+
a,
|
|
42556
|
+
l
|
|
42519
42557
|
);
|
|
42520
|
-
return this.avatars.push(
|
|
42558
|
+
return this.avatars.push(h), h;
|
|
42559
|
+
}
|
|
42560
|
+
remove(e) {
|
|
42561
|
+
let t = this.avatars.find((i) => i.id == e);
|
|
42562
|
+
t && t.dispose(), this.avatars = this.avatars.filter((i) => i.id != e);
|
|
42521
42563
|
}
|
|
42522
42564
|
}
|
|
42523
42565
|
class v3 {
|