123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374 |
- const log$F = new Logger$1("XAvatarBillboardComponent");
- class XAvatarBillboardComponent {
- constructor(e) {
- E(this, "_nickName", "");
- E(this, "_words", "");
- E(this, "_isNameVisible", !0);
- E(this, "_isBubbleVisible", !0);
- E(this, "_isGiftButtonsVisible", !1);
- E(this, "withinVisualRange", !1);
- E(this, "_bubble");
- E(this, "_nameBoard");
- E(this, "_giftButtons", new Map);
- E(this, "_buttonTex", new Map);
- E(this, "_nameLinesLimit", 2);
- E(this, "_nameLengthPerLine", 16);
- E(this, "_scene");
- E(this, "_pickBbox", null);
- E(this, "bbox");
- E(this, "_height", .26);
- E(this, "_attachmentObservers", new Map);
- E(this, "attachToAvatar", (e,t,r=!1,n={
- x: 0,
- y: 0,
- z: 0
- },o=!1,a,s)=>{
- const l = e.rootNode;
- if (this.bbox || e.getBbox(),
- t && l) {
- const u = a || t.uniqueId;
- let c = this._attachmentObservers.get(u);
- if (c)
- if (o)
- this._scene.onBeforeRenderObservable.remove(c),
- this._attachmentObservers.delete(u);
- else
- return;
- const h = ue4Position2Xverse(n);
- r ? (t.setParent(l),
- t.position = h) : (c = this._scene.onBeforeRenderObservable.add(()=>{
- let f = 0;
- s ? (f = e.rootNode.rotation.y / Math.PI * 180 + 90,
- e.rootNode.rotation.y && (t.rotation.y = e.rootNode.rotation.y)) : f = e.avatarManager.sceneManager.cameraComponent.getCameraPose().rotation.yaw,
- f || (f = 0);
- const d = new Vector3(0,this._height,0);
- e.controller && e.controller.activeAnimation() && e.controller.activeAnimation().animatables[0] && (this._height = d.y = (e.controller.activeAnimation().animatables[0].target.position.y * .01 - .66) * e.scale),
- d.y < .07 * e.scale && (d.y = 0),
- t.position.x = l.position.x + h.x * Math.sin(f * Math.PI / 180) + h.z * Math.cos(f * Math.PI / 180),
- t.position.z = l.position.z + h.x * Math.cos(f * Math.PI / 180) - h.z * Math.sin(f * Math.PI / 180),
- t.position.y = l.position.y + this.bbox.maximum.y + h.y + d.y
- }
- ),
- this._attachmentObservers.set(u, c))
- } else
- log$F.error("avatar or attachment not found!")
- }
- );
- E(this, "detachFromAvatar", (e,t,r=!1)=>{
- const n = this._attachmentObservers.get(t.uniqueId);
- n && this._scene.onBeforeRenderObservable.remove(n),
- e.rootNode ? (t.setEnabled(!1),
- t.parent = null,
- r && t.dispose()) : log$F.error("avatar not found!")
- }
- );
- E(this, "getBbox", (e,t={})=>{
- const {isConst: r=!1, changeWithAvatar: n=!1} = t;
- let {localCenter: o={
- x: 0,
- y: 0,
- z: 75
- }, width: a=1.32, height: s=1.5, depth: l=.44} = t;
- if (n) {
- const u = e.scale;
- o = {
- x: o.x * u,
- y: o.y * u,
- z: o.z * u
- },
- a *= u,
- s *= u,
- l *= u
- }
- if (e.rootNode) {
- let u = new Vector3(0,0,0)
- , c = new Vector3(0,0,0);
- if (r) {
- const f = ue4Position2Xverse(o);
- u = u.add(f.add(new Vector3(-a / 2,-s / 2,-l / 2))),
- c = c.add(f.add(new Vector3(a / 2,s / 2,l / 2)))
- } else if (u = u.add(new Vector3(Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY)),
- c = c.add(new Vector3(Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY)),
- e.isRender) {
- e.rootNode.getChildMeshes().forEach(_=>{
- const g = _.getBoundingInfo().boundingBox.minimum
- , m = _.getBoundingInfo().boundingBox.maximum;
- u.x = Math.min(u.x, g.x),
- c.x = Math.max(c.x, m.x),
- u.y = Math.min(u.y, g.y),
- c.y = Math.max(c.y, m.y),
- u.z = Math.min(u.z, g.z),
- c.z = Math.max(c.z, m.z)
- }
- );
- const f = c.x - u.x
- , d = c.z - u.z;
- u.x -= e.scale * f / 2,
- c.x += e.scale * f / 2,
- c.y *= e.scale,
- u.z -= e.scale * d / 2,
- c.z += e.scale * d / 2
- } else {
- const f = e.avatarManager.getMainAvatar();
- f && f.bbComponent.bbox && (u.x = f.bbComponent.bbox.minimum.x,
- c.x = f.bbComponent.bbox.maximum.x,
- u.y = f.bbComponent.bbox.minimum.y,
- c.y = f.bbComponent.bbox.maximum.y,
- u.z = f.bbComponent.bbox.minimum.z,
- c.z = f.bbComponent.bbox.maximum.z)
- }
- const h = e.rootNode.computeWorldMatrix(!0);
- if (this.bbox ? this.bbox.reConstruct(u, c, h) : this.bbox = new BoundingBox(u,c,h),
- this._pickBbox == null) {
- const f = this.createPickBoundingbox(e, this.bbox);
- this.attachToAvatar(e, f.data, !1, {
- x: 0,
- y: 0,
- z: 0
- }, !1, "pickbox"),
- this._pickBbox = f
- }
- } else
- log$F.error("avatar not found!")
- }
- );
- this._scene = e
- }
- get isNameVisible() {
- return this._isNameVisible
- }
- get isBubbleVisible() {
- return this._isBubbleVisible
- }
- get isGiftButtonsVisible() {
- return this._isGiftButtonsVisible
- }
- get words() {
- return this._words
- }
- get nickName() {
- return this._nickName
- }
- get giftButtons() {
- return this._giftButtons
- }
- get bubble() {
- return this._bubble
- }
- get nameBoard() {
- return this._nameBoard
- }
- setNicknameStatus(e) {
- if (this.nameBoard && this.nameBoard.setStatus(e),
- e == BillboardStatus.DISPOSE) {
- const t = this._attachmentObservers.get("nickname");
- t && (this._scene.onBeforeRenderObservable.remove(t),
- this._attachmentObservers.delete("nickname"))
- }
- }
- setBubbleStatus(e) {
- if (this.bubble && this.bubble.setStatus(e),
- e == BillboardStatus.DISPOSE) {
- const t = this._attachmentObservers.get("bubble");
- t && (this._scene.onBeforeRenderObservable.remove(t),
- this._attachmentObservers.delete("bubble"))
- }
- }
- setButtonsStatus(e) {
- this.giftButtons && this.giftButtons.size != 0 && this.giftButtons.forEach(t=>{
- if (t.setStatus(e),
- e == BillboardStatus.DISPOSE && t.getMesh()) {
- const r = "button_" + t.getMesh().xid
- , n = this._attachmentObservers.get(r);
- n && (this._scene.onBeforeRenderObservable.remove(n),
- this._attachmentObservers.delete(r))
- }
- }
- )
- }
- setGiftButtonsVisible(e) {
- this.setButtonsStatus(e ? BillboardStatus.SHOW : BillboardStatus.DISPOSE)
- }
- dispose(e) {
- this._attachmentObservers.forEach(t=>{
- this._scene.onBeforeRenderObservable.remove(t)
- }
- ),
- this._attachmentObservers.clear(),
- this.updateBillboardStatus(e, BillboardStatus.DISPOSE),
- this._buttonTex.clear(),
- this._pickBbox && (e.avatarManager.bboxMeshPool.release(this._pickBbox),
- this._pickBbox = null)
- }
- updateBillboardStatus(e, t) {
- this.bbox || e.getBbox(),
- e.isRender ? (e.setBubbleStatus(t),
- e.setButtonsStatus(t),
- e.setNicknameStatus(t)) : (e.setBubbleStatus(BillboardStatus.DISPOSE),
- e.setButtonsStatus(BillboardStatus.DISPOSE),
- e.enableNickname ? e.setNicknameStatus(t) : e.setNicknameStatus(BillboardStatus.DISPOSE))
- }
- disposeBillBoard(e) {
- this._attachmentObservers.forEach(t=>{
- this._scene.onBeforeRenderObservable.remove(t)
- }
- ),
- this._attachmentObservers.clear(),
- this.updateBillboardStatus(e, BillboardStatus.DISPOSE),
- this._buttonTex.clear(),
- this._pickBbox && (e.avatarManager.bboxMeshPool.release(this._pickBbox),
- this._pickBbox = null)
- }
- setPickBoxScale(e) {
- this._pickBbox && this._pickBbox.data && (this._pickBbox.data.scaling = new Vector3(e,e,e))
- }
- setIsPickable(e, t) {
- e.rootNode && e.rootNode.getChildMeshes().forEach(r=>{
- r.isPickable = t
- }
- ),
- this._pickBbox && this._pickBbox.data && (this._pickBbox.data.isPickable = t)
- }
- initNameboard(e, t=1) {
- this._nameBoard == null && (this._nameBoard = e.avatarManager.sceneManager.billboardComponent.addBillboard("name-" + e.id, !1, !0)),
- this._nameBoard.init("nickname", t / 300, t / 300)
- }
- initBubble(e, t=1) {
- this._bubble == null && (this._bubble = e.avatarManager.sceneManager.billboardComponent.addBillboard("bubble-" + e.id, !1, !0)),
- e.isRender && this._bubble.init("bubble", t / 250, t / 250)
- }
- say(e, t=this._words, {id: r, isUser: n, background: o, font: a="Arial", fontsize: s=38, fontcolor: l="#ffffff", fontstyle: u="bold", linesize: c=22, linelimit: h, offsets: f={
- x: 0,
- y: 0,
- z: 40
- }, scale: d, compensationZ: _=11.2, reregistAnyway: g=!0}) {
- (!this.bubble || this.bubble.getMesh() == null) && e.initBubble(),
- this._words = t;
- let m;
- n != null && (m = n ? XBillboardManager.userBubbleUrls : XBillboardManager.npcBubbleUrls),
- this._bubble && (this._bubble.DEFAULT_CONFIGS = {
- id: r,
- isUser: n,
- background: o || m,
- font: a,
- fontsize: s,
- fontcolor: l,
- fontstyle: u,
- linesize: c,
- linelimit: h,
- offsets: f,
- scale: d,
- compensationZ: _,
- reregistAnyway: g
- },
- this._bubble.getMesh() && (this._bubble.drawBillboard({
- imageList: o || m
- }, {
- texts: this._words,
- font: a,
- fontsize: s,
- fontcolor: l,
- fontstyle: u,
- linesize: c
- }, {
- offsets: f,
- scale: d,
- compensationZ: _
- }),
- this.attachToAvatar(e, this._bubble.getMesh(), !1, this._bubble.offsets, g, "bubble"),
- r && this._bubble.setId(r))),
- this.setButtonsStatus(BillboardStatus.DISPOSE)
- }
- silent() {
- this.setBubbleStatus(BillboardStatus.DISPOSE),
- this._words = ""
- }
- setNickName(e, t, {id: r, isUser: n, background: o, font: a="Arial", fontsize: s=40, fontcolor: l="#ffffff", fontstyle: u="bold", linesize: c=22, linelimit: h, offsets: f={
- x: 0,
- y: 0,
- z: 15
- }, scale: d, compensationZ: _=0, reregistAnyway: g=!1}) {
- this._nickName = t,
- (!this.nameBoard || this.nameBoard.getMesh() == null) && this.initNameboard(e),
- this._nameBoard && this._nameBoard.getMesh() && (this._nameBoard.DEFAULT_CONFIGS = {
- id: r,
- isUser: n,
- background: o,
- font: a,
- fontsize: s,
- fontcolor: l,
- fontstyle: u,
- linesize: c,
- linelimit: h,
- offsets: f,
- scale: d,
- compensationZ: _,
- reregistAnyway: g
- },
- this._nameBoard.drawBillboard({}, {
- texts: this._nickName,
- font: a,
- fontsize: s,
- fontcolor: l,
- fontstyle: u,
- linesize: c,
- linelimit: h
- }, {
- offsets: f,
- scale: d,
- compensationZ: 0
- }),
- this.attachToAvatar(e, this._nameBoard.getMesh(), !1, this._nameBoard.offsets, g, "nickname"),
- r && this._nameBoard.setId(r))
- }
- generateButtons(e, t=null, r, n=85) {
- if (t && (this._buttonTex = t,
- this.clearButtons()),
- this._buttonTex.size == 0)
- return;
- let o = (this._buttonTex.size - 1) / 2;
- this._buttonTex.forEach((a,s)=>{
- let l = this._giftButtons.get(s);
- l || (l = e.avatarManager.sceneManager.billboardComponent.addBillboard("button-" + s + e.id, !0, !1),
- l.init(s, r / 240, r / 240));
- const u = {
- x: r * o * 70,
- y: 0,
- z: r * (n - 20 * (o * o))
- };
- l.drawBillboard({
- imageList: [a]
- }, {}, {
- offsets: u,
- scale: r
- }),
- this.attachToAvatar(e, l.getMesh(), !1, l.offsets, !0, "button_" + s),
- this._giftButtons.set(s, l),
- o -= 1
- }
- ),
- this.setBubbleStatus(BillboardStatus.DISPOSE)
- }
- clearButtons() {
- this._giftButtons.forEach(e=>{
- e.dispose()
- }
- ),
- this._giftButtons.clear()
- }
- createPickBoundingbox(e, t) {
- const r = t.extendSize.x * 2
- , n = t.extendSize.y * 2
- , o = t.extendSize.z * 2
- , a = this._scene
- , s = Math.max(r, o)
- , l = e.avatarManager.bboxMeshPool.getFree(a, s, n, s)
- , u = l.data;
- return u && (u.position = t.centerWorld,
- u.setEnabled(!1),
- u.isPickable = !0,
- u.xtype = EMeshType.XAvatar,
- u.xid = e.id),
- l
- }
- }
|