|
@@ -11,7 +11,7 @@ const castRayOffsetY = .01;
|
|
|
const castRayTeleportationOffset = 10;
|
|
|
|
|
|
export default class XAvatar {
|
|
|
- constructor({id: e, avatarType: i, priority: o, avatarManager: s, assets: c, status: d}) {
|
|
|
+ constructor({id, avatarType, priority, avatarManager, assets, status}) {
|
|
|
this.id = "-1",
|
|
|
this.priority = 0,
|
|
|
this.isRender = !1,
|
|
@@ -31,171 +31,202 @@ export default class XAvatar {
|
|
|
this.isInLoadingQueue = !1,
|
|
|
this._scene = void 0,
|
|
|
this._transparent = 0,
|
|
|
- this.hide = ()=>(this.isHide = !0,
|
|
|
- this._hide(),
|
|
|
- !this.isRender),
|
|
|
+
|
|
|
+ this.hide = ()=>{
|
|
|
+ this.isHide = !0
|
|
|
+ this._hide()
|
|
|
+ return !this.isRender
|
|
|
+ },
|
|
|
+
|
|
|
this._show = ()=>{
|
|
|
- var _;
|
|
|
- this.isHide || (this.setIsPickable(!0),
|
|
|
- this.bbComponent._attachmentObservers.forEach((b,k)=>{
|
|
|
- k.setEnabled(!0)
|
|
|
- }
|
|
|
- ),
|
|
|
- this.priority == 0 && (this.rootNode.setEnabled(!0),
|
|
|
- this.isRender = !0,
|
|
|
- this.avatarManager._updateBillboardStatus(this, BillboardStatus.SHOW),
|
|
|
- this.component.accessories.forEach(b=>{
|
|
|
- b.rootComponent.setEnabled(!0)
|
|
|
- }
|
|
|
- ),
|
|
|
- (_ = this.controller) == null || _.playAnimation(this.controller.onPlay, this.controller.loop)),
|
|
|
- this.component.accessories.forEach(b=>{
|
|
|
- b.rootComponent.setEnabled(!0)
|
|
|
- }
|
|
|
- ))
|
|
|
- }
|
|
|
- ,
|
|
|
- this.show = ()=>(this.isHide = !1,
|
|
|
- this._show(),
|
|
|
- !!this.isRender),
|
|
|
+ this.isHide || (
|
|
|
+ this.setIsPickable(!0),
|
|
|
+ this.bbComponent._attachmentObservers.forEach((b,k)=>{
|
|
|
+ k.setEnabled(!0)
|
|
|
+ }),
|
|
|
+ this.priority == 0 && (
|
|
|
+ this.rootNode.setEnabled(!0),
|
|
|
+ this.isRender = !0,
|
|
|
+ this.avatarManager._updateBillboardStatus(this, BillboardStatus.SHOW),
|
|
|
+ this.component.accessories.forEach(b=>{
|
|
|
+ b.rootComponent.setEnabled(!0)
|
|
|
+ }),
|
|
|
+ this.controller == null || this.controller.playAnimation(this.controller.onPlay, this.controller.loop)
|
|
|
+ ),
|
|
|
+ this.component.accessories.forEach(b=>{
|
|
|
+ b.rootComponent.setEnabled(!0)
|
|
|
+ })
|
|
|
+ )
|
|
|
+ },
|
|
|
+
|
|
|
+ this.show = ()=>{
|
|
|
+ this.isHide = !1
|
|
|
+ this._show()
|
|
|
+ return !!this.isRender
|
|
|
+ },
|
|
|
+
|
|
|
this.setAnimations = _=>{
|
|
|
this.controller.animations = _
|
|
|
- }
|
|
|
- ,
|
|
|
- this.attachToAvatar = (_,b=!1,k={
|
|
|
- x: 0,
|
|
|
- y: 0,
|
|
|
- z: 0
|
|
|
- },j=!1,$,_e)=>this.bbComponent.attachToAvatar(this, _, b, k, j, _e),
|
|
|
- this.detachFromAvatar = (_,b=!1)=>this.bbComponent.detachFromAvatar(this, _, b),
|
|
|
- this.getBbox = (_={})=>this.bbComponent.getBbox(this, _),
|
|
|
- this.id = e,
|
|
|
- this._avatarManager = s,
|
|
|
+ },
|
|
|
+
|
|
|
+ this.attachToAvatar = ( _, b=!1, k={x:0,y:0,z:0}, j=!1, $, _e ) => {
|
|
|
+ this.bbComponent.attachToAvatar(this, _, b, k, j, _e)
|
|
|
+ },
|
|
|
+
|
|
|
+ this.detachFromAvatar = ( _, b=!1 )=>{
|
|
|
+ this.bbComponent.detachFromAvatar(this, _, b)
|
|
|
+ },
|
|
|
+ this.getBbox = (_={})=>{
|
|
|
+ this.bbComponent.getBbox(this, _)
|
|
|
+ },
|
|
|
+
|
|
|
+ this.id = id,
|
|
|
+ this._avatarManager = avatarManager,
|
|
|
this._scene = this.avatarManager.scene,
|
|
|
- this.clothesList = c,
|
|
|
- this._avatarType = i,
|
|
|
- this.priority = o || 0,
|
|
|
+ this.clothesList = assets,
|
|
|
+ this._avatarType = avatarType,
|
|
|
+ this.priority = priority || 0,
|
|
|
+
|
|
|
this.controller = new XAnimationController(this),
|
|
|
this.component = new XAvatarComopnent,
|
|
|
this.stateMachine = new XStateMachine(this._scene),
|
|
|
this.bbComponent = new XAvatarBillboardComponent(this._scene),
|
|
|
- this.rootNode = new BABYLON.TransformNode(e,this._avatarManager.scene),
|
|
|
- this._avatarScale = d.avatarScale == null ? 1 : d.avatarScale,
|
|
|
- this._avatarRotation = d.avatarRotation == null ? {
|
|
|
- pitch: 0,
|
|
|
- yaw: 0,
|
|
|
- roll: 0
|
|
|
- } : d.avatarRotation,
|
|
|
- this._avatarPosition = d.avatarPosition == null ? {
|
|
|
- x: 0,
|
|
|
- y: 0,
|
|
|
- z: 0
|
|
|
- } : d.avatarPosition,
|
|
|
+ this.rootNode = new BABYLON.TransformNode(id, this._avatarManager.scene),
|
|
|
+
|
|
|
+ this._avatarScale = status.avatarScale == null ? 1 : status.avatarScale,
|
|
|
+ this._avatarRotation = status.avatarRotation == null ? { pitch: 0, yaw: 0, roll: 0 } : status.avatarRotation,
|
|
|
+ this._avatarPosition = status.avatarPosition == null ? { x: 0, y: 0, z: 0 } : status.avatarPosition,
|
|
|
this._isRayCastEnable = avatarSetting.isRayCastEnable,
|
|
|
+
|
|
|
this.setPosition(this._avatarPosition, !0),
|
|
|
this.setRotation(this._avatarRotation),
|
|
|
this.setScale(this.scale),
|
|
|
this._isRayCastEnable = avatarSetting.isRayCastEnable,
|
|
|
+
|
|
|
this._scene.registerBeforeRender(()=>{
|
|
|
this.tick()
|
|
|
- }
|
|
|
- )
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
tick() {
|
|
|
this.cullingTick()
|
|
|
}
|
|
|
+
|
|
|
cullingTick() {
|
|
|
- var e;
|
|
|
- this.isCulling && ((e = this.rootNode) == null || e.getChildMeshes().forEach(i=>{
|
|
|
+ this.isCulling && (this.rootNode == null || this.rootNode.getChildMeshes().forEach(i=>{
|
|
|
this.distToCam < 50 ? i.visibility = 0 : i.visibility = this._transparent
|
|
|
- }
|
|
|
- ))
|
|
|
+ }))
|
|
|
}
|
|
|
+
|
|
|
setTransParentThresh(e) {
|
|
|
this._transparent = e
|
|
|
}
|
|
|
+
|
|
|
get isNameVisible() {
|
|
|
return this.bbComponent.isNameVisible
|
|
|
}
|
|
|
+
|
|
|
get isBubbleVisible() {
|
|
|
return this.bbComponent.isBubbleVisible
|
|
|
}
|
|
|
+
|
|
|
get isGiftButtonsVisible() {
|
|
|
return this.bbComponent.isGiftButtonsVisible
|
|
|
}
|
|
|
+
|
|
|
get words() {
|
|
|
return this.bbComponent.words
|
|
|
}
|
|
|
+
|
|
|
get nickName() {
|
|
|
return this.bbComponent.nickName
|
|
|
}
|
|
|
+
|
|
|
get giftButtons() {
|
|
|
return this.bbComponent.giftButtons
|
|
|
}
|
|
|
+
|
|
|
get bubble() {
|
|
|
return this.bbComponent.bubble
|
|
|
}
|
|
|
+
|
|
|
get nameBoard() {
|
|
|
return this.bbComponent.nameBoard
|
|
|
}
|
|
|
+
|
|
|
get avatarManager() {
|
|
|
return this._avatarManager
|
|
|
}
|
|
|
+
|
|
|
set withinVisibleRange(e) {
|
|
|
this.bbComponent.withinVisualRange = e
|
|
|
}
|
|
|
+
|
|
|
setNicknameStatus(e) {
|
|
|
return this.bbComponent.setNicknameStatus(e)
|
|
|
}
|
|
|
+
|
|
|
setBubbleStatus(e) {
|
|
|
return this.bbComponent.setBubbleStatus(e)
|
|
|
}
|
|
|
+
|
|
|
setButtonsStatus(e) {
|
|
|
return this.bbComponent.setBubbleStatus(e)
|
|
|
}
|
|
|
+
|
|
|
setGiftButtonsVisible(e) {
|
|
|
return this.bbComponent.setGiftButtonsVisible(e)
|
|
|
}
|
|
|
+
|
|
|
get avatarType() {
|
|
|
return this._avatarType
|
|
|
}
|
|
|
+
|
|
|
attachBody(e) {
|
|
|
return this.component.addBodyComp(this, e)
|
|
|
}
|
|
|
+
|
|
|
attachDecoration(e) {
|
|
|
return this.component.addClothesComp(this, e)
|
|
|
}
|
|
|
+
|
|
|
detachDecoration(e) {
|
|
|
return this.component.clearClothesComp(e)
|
|
|
}
|
|
|
+
|
|
|
detachDecorationAll() {
|
|
|
return this.component.clearAllClothesComps()
|
|
|
}
|
|
|
+
|
|
|
get skeleton() {
|
|
|
return this.component.skeleton
|
|
|
}
|
|
|
+
|
|
|
get position() {
|
|
|
return this._avatarPosition
|
|
|
}
|
|
|
+
|
|
|
get rotation() {
|
|
|
return this._avatarRotation
|
|
|
}
|
|
|
+
|
|
|
get scale() {
|
|
|
return this._avatarScale
|
|
|
}
|
|
|
+
|
|
|
_hide_culling() {
|
|
|
this.bbComponent.updateBillboardStatus(this, BillboardStatus.HIDE),
|
|
|
this.isCulling = !0
|
|
|
}
|
|
|
+
|
|
|
_show_culling() {
|
|
|
this.isCulling && (this.rootNode && this.rootNode.getChildMeshes().forEach(e=>{
|
|
|
e.visibility = 1
|
|
|
- }
|
|
|
- ),
|
|
|
+ }),
|
|
|
this.bbComponent.updateBillboardStatus(this, BillboardStatus.SHOW),
|
|
|
this.isCulling = !1)
|
|
|
}
|
|
|
+
|
|
|
_hide() {
|
|
|
!this.isHide || (this.setIsPickable(!1),
|
|
|
this.bbComponent._attachmentObservers.forEach((e,i)=>{
|
|
@@ -212,25 +243,30 @@ export default class XAvatar {
|
|
|
this.removeAvatarFromScene()),
|
|
|
this.component.accessories.forEach(e=>{
|
|
|
e.rootComponent.setEnabled(!1)
|
|
|
- }
|
|
|
- ))
|
|
|
+ }))
|
|
|
}
|
|
|
+
|
|
|
rotate(e, i, o) {
|
|
|
return this.stateMachine.roll(this, e, i, o)
|
|
|
}
|
|
|
+
|
|
|
set isRayCastEnable(e) {
|
|
|
this._isRayCastEnable = e
|
|
|
}
|
|
|
+
|
|
|
get isRayCastEnable() {
|
|
|
return this._isRayCastEnable
|
|
|
}
|
|
|
+
|
|
|
getAvatarId() {
|
|
|
return this.id
|
|
|
}
|
|
|
+
|
|
|
getAvaliableAnimations() {
|
|
|
const e = avatarLoader.avaliableAnimation.get(this.avatarType);
|
|
|
return e || []
|
|
|
}
|
|
|
+
|
|
|
// todo i用于控制是否接触地面。目前设默认为true,实时检测模型地面高度
|
|
|
setPosition(e, i=!0) {
|
|
|
this._avatarPosition = e;
|
|
@@ -263,6 +299,7 @@ export default class XAvatar {
|
|
|
}
|
|
|
return Promise.resolve(e)
|
|
|
}
|
|
|
+
|
|
|
setRotation(e) {
|
|
|
if (this._avatarRotation = e,
|
|
|
this.rootNode) {
|
|
@@ -275,6 +312,7 @@ export default class XAvatar {
|
|
|
this.rootNode.rotation = o
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
setAvatarVisible(e) {
|
|
|
this.rootNode && (this.rootNode.setEnabled(e),
|
|
|
this.rootNode.getChildMeshes().forEach(i=>{
|
|
@@ -282,11 +320,13 @@ export default class XAvatar {
|
|
|
}
|
|
|
))
|
|
|
}
|
|
|
+
|
|
|
setScale(e) {
|
|
|
this._avatarScale = e,
|
|
|
this.rootNode && (this.rootNode.scaling = new BABYLON.Vector3(e,e,e)),
|
|
|
this.bbComponent.bbox && this.getBbox()
|
|
|
}
|
|
|
+
|
|
|
_removeAvatarFromScene() {
|
|
|
var e, i;
|
|
|
this.isRender = !1,
|
|
@@ -295,19 +335,22 @@ export default class XAvatar {
|
|
|
(i = this.avatarManager.sceneManager) == null || i.lightComponent.removeShadow(this),
|
|
|
this.component.accessories.forEach(o=>{
|
|
|
o.rootComponent.setEnabled(!1)
|
|
|
- }
|
|
|
- )
|
|
|
+ })
|
|
|
}
|
|
|
+
|
|
|
removeAvatarFromScene() {
|
|
|
this._removeAvatarFromScene(),
|
|
|
this._disposeBillBoard()
|
|
|
}
|
|
|
+
|
|
|
_disposeBillBoard() {
|
|
|
this.bbComponent.disposeBillBoard(this)
|
|
|
}
|
|
|
+
|
|
|
addComponent(e, i, o, s) {
|
|
|
return i === "pendant" ? this.component.attachPendant(this, e) : this.component.changeClothesComp(this, e, i, o, s)
|
|
|
}
|
|
|
+
|
|
|
removeComponent(e, i) {
|
|
|
if (e === "pendant")
|
|
|
i ? this.component.detachPendant(i) : this.component.accessories.forEach((o,s)=>{
|
|
@@ -320,6 +363,7 @@ export default class XAvatar {
|
|
|
this.clothesList = this.clothesList.filter(s=>s.type != e))
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
getComponentByType(e, i) {
|
|
|
if (e === "pendant")
|
|
|
if (i) {
|
|
@@ -330,6 +374,7 @@ export default class XAvatar {
|
|
|
else
|
|
|
return this.component.resourceIdList.find(o=>o.type == e)
|
|
|
}
|
|
|
+
|
|
|
_castRay(e) {
|
|
|
return new Promise((i,o)=>{
|
|
|
var et;
|
|
@@ -351,108 +396,109 @@ export default class XAvatar {
|
|
|
_e = j.intersectsMeshes($),
|
|
|
_e.length > 0)
|
|
|
return i(-(_e[0].distance - b))
|
|
|
- }
|
|
|
- )
|
|
|
+ })
|
|
|
}
|
|
|
+
|
|
|
setPickBoxScale(e) {
|
|
|
return this.bbComponent.setPickBoxScale(e)
|
|
|
}
|
|
|
+
|
|
|
setIsPickable(e) {
|
|
|
return this.bbComponent.setIsPickable(this, e)
|
|
|
}
|
|
|
+
|
|
|
createPickBoundingbox(e) {
|
|
|
return this.bbComponent.createPickBoundingbox(this, e)
|
|
|
}
|
|
|
+
|
|
|
scaleBbox(e) {
|
|
|
this.bbComponent.bbox && this.bbComponent.bbox.scale(e)
|
|
|
}
|
|
|
+
|
|
|
rotateTo(e, i, o) {
|
|
|
return this.stateMachine.rotateTo(this, e, i, o)
|
|
|
}
|
|
|
+
|
|
|
faceTo(e, i) {
|
|
|
return this.stateMachine.lookAt(this, e, i)
|
|
|
}
|
|
|
+
|
|
|
removeObserver() {
|
|
|
this.stateMachine.disposeObsever()
|
|
|
}
|
|
|
+
|
|
|
moveHermite(e, i, o, s, c, d) {
|
|
|
return this.stateMachine.moveToHermite(this, e, i, o, s, c, d)
|
|
|
}
|
|
|
+
|
|
|
moveCardinal(e, i, o, s, c, d, _=!1) {
|
|
|
return this.stateMachine.moveToCardinal(this, e, i, o, s, c, d, _)
|
|
|
}
|
|
|
+
|
|
|
move(e, i, o, s, c, d=!1) {
|
|
|
return this.stateMachine.moveTo(this, e, i, o, s, c, d)
|
|
|
}
|
|
|
+
|
|
|
initNameboard(e=1) {
|
|
|
return this.bbComponent.initNameboard(this, e)
|
|
|
}
|
|
|
+
|
|
|
initBubble(e=1) {
|
|
|
return this.bbComponent.initBubble(this, e)
|
|
|
}
|
|
|
- say(e, {id: i, isUser: o, background: s, font: c="Arial", fontsize: d=38, fontcolor: _="#ffffff", fontstyle: b="bold", linesize: k=22, linelimit: j, offsets: $={
|
|
|
- x: 0,
|
|
|
- y: 0,
|
|
|
- z: 40
|
|
|
- }, scale: _e=this._avatarScale, compensationZ: et=11.2, reregistAnyway: tt=!0}) {
|
|
|
+
|
|
|
+ say(e, {
|
|
|
+ id, isUser, background,
|
|
|
+ font="Arial", fontsize=38, fontcolor="#ffffff", fontstyle="bold", linesize=22, linelimit,
|
|
|
+ offsets={x: 0, y: 0, z: 40}, scale=this._avatarScale, compensationZ=11.2, reregistAnyway=!0
|
|
|
+ }) {
|
|
|
return this.bbComponent.say(this, e, {
|
|
|
- id: i,
|
|
|
- isUser: o,
|
|
|
- background: s,
|
|
|
- font: c,
|
|
|
- fontsize: d,
|
|
|
- fontcolor: _,
|
|
|
- fontstyle: b,
|
|
|
- linesize: k,
|
|
|
- linelimit: j,
|
|
|
- offsets: $,
|
|
|
- scale: _e,
|
|
|
- compensationZ: et,
|
|
|
- reregistAnyway: tt
|
|
|
+ id, isUser, background,
|
|
|
+ font, fontsize, fontcolor, fontstyle, linesize, linelimit,
|
|
|
+ offsets, scale, compensationZ, reregistAnyway
|
|
|
})
|
|
|
}
|
|
|
+
|
|
|
silent() {
|
|
|
return this.bbComponent.silent()
|
|
|
}
|
|
|
- setNickName(e, {id: i, isUser: o, background: s, font: c="Arial", fontsize: d=40, fontcolor: _="#ffffff", fontstyle: b="bold", linesize: k=22, linelimit: j, offsets: $={
|
|
|
- x: 0,
|
|
|
- y: 0,
|
|
|
- z: 15
|
|
|
- }, scale: _e=this._avatarScale, compensationZ: et=0, reregistAnyway: tt=!1}) {
|
|
|
+
|
|
|
+ setNickName(e, {
|
|
|
+ id, isUser, background,
|
|
|
+ font="Arial", fontsize=40, fontcolor="#ffffff", fontstyle="bold", linesize=22, linelimit,
|
|
|
+ offsets={x: 0, y: 0, z: 15}, scale=this._avatarScale, compensationZ=0, reregistAnyway=!1
|
|
|
+ }) {
|
|
|
return this.bbComponent.setNickName(this, e, {
|
|
|
- id: i,
|
|
|
- isUser: o,
|
|
|
- background: s,
|
|
|
- font: c,
|
|
|
- fontsize: d,
|
|
|
- fontcolor: _,
|
|
|
- fontstyle: b,
|
|
|
- linesize: k,
|
|
|
- linelimit: j,
|
|
|
- offsets: $,
|
|
|
- scale: _e,
|
|
|
- compensationZ: et,
|
|
|
- reregistAnyway: tt
|
|
|
+ id, isUser, background,
|
|
|
+ font, fontsize, fontcolor, fontstyle, linesize, linelimit,
|
|
|
+ offsets, scale, compensationZ, reregistAnyway
|
|
|
})
|
|
|
}
|
|
|
+
|
|
|
generateButtons(e=null, i=this._avatarScale, o=85) {
|
|
|
return this.bbComponent.generateButtons(this, e, i, o)
|
|
|
}
|
|
|
+
|
|
|
clearButtons() {
|
|
|
return this.bbComponent.clearButtons()
|
|
|
}
|
|
|
+
|
|
|
attachExtraProp(e, i, o, s) {
|
|
|
return this.component.addDecoComp(this, e, i, o, s)
|
|
|
}
|
|
|
+
|
|
|
showExtra(e) {
|
|
|
return this.component.showExtra(e)
|
|
|
}
|
|
|
+
|
|
|
hideExtra(e) {
|
|
|
return this.component.hideExtra(e)
|
|
|
}
|
|
|
+
|
|
|
disposeExtra() {
|
|
|
return this.component.disposeExtra()
|
|
|
}
|
|
|
+
|
|
|
getSkeletonPositionByName(e) {
|
|
|
var i;
|
|
|
if (this.skeleton) {
|
|
@@ -467,6 +513,7 @@ export default class XAvatar {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
shootTo(e, i, o=2, s=10, c={
|
|
|
x: 0,
|
|
|
y: 0,
|