XStaticMesh.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. import EMeshType from "./enum/EMeshType.js"
  2. import Logger from "./Logger.js"
  3. const logger = new Logger('StaticMesh')
  4. export default class XStaticMesh {
  5. constructor({id: e, mesh: t, group: r="default", lod: n=0, xtype: o=EMeshType.XStaticMesh, skinInfo: a="default", url: s=""}) {
  6. E(this, "_mesh");
  7. E(this, "_id", "-1");
  8. E(this, "_group");
  9. E(this, "_lod");
  10. E(this, "_isMoving", !1);
  11. E(this, "_isRotating", !1);
  12. E(this, "_isVisible", !0);
  13. E(this, "_skinInfo");
  14. this._id = e,
  15. this._mesh = t,
  16. this._group = r,
  17. this._lod = n,
  18. this._skinInfo = a,
  19. this.unallowMove(),
  20. this._mesh.xtype = o,
  21. this._mesh.xid = e,
  22. this._mesh.xgroup = this._group,
  23. this._mesh.xlod = this._lod,
  24. this._mesh.xskinInfo = this._skinInfo,
  25. this._mesh.xurl = s
  26. }
  27. setVisibility(e,t) {
  28. Array.isArray(e) ? e.forEach(r=>{
  29. this.setVisibility(r, t)
  30. }
  31. ) : e.isAnInstance || (e.visibility = t)
  32. }
  33. setPickable(e,t) {
  34. Array.isArray(e) ? e.forEach(r=>{
  35. this.setPickable(r, t)
  36. }
  37. ) : ("isPickable"in e && (e.isPickable = t),
  38. e.setEnabled(t))
  39. }
  40. hide() {
  41. var e;
  42. this._isVisible = !1,
  43. this.mesh && this.setVisibility(this.mesh, 0),
  44. this.mesh && this.setPickable(this.mesh, !1),
  45. (e = this.mesh) == null || e.getChildMeshes().forEach(t=>{
  46. this.setVisibility(t, 0),
  47. this.setPickable(t, !1)
  48. }
  49. )
  50. }
  51. show() {
  52. var e;
  53. this._isVisible = !0,
  54. this.mesh && this.setVisibility(this.mesh, 1),
  55. this.mesh && this.setPickable(this.mesh, !0),
  56. (e = this.mesh) == null || e.getChildMeshes().forEach(t=>{
  57. this.setVisibility(t, 1),
  58. this.setPickable(t, !0)
  59. }
  60. )
  61. }
  62. attachToAvatar(e, t={x:0, y:.5, z:0}, r={yaw:0, pitch:0, roll:0}, n={x:.35, y:.35, z:.35}) {
  63. const o = ue4Scaling2Xverse(n)
  64. , a = ue4Rotation2Xverse(r)
  65. , s = ue4Position2Xverse(t)
  66. , l = this._mesh;
  67. e && l ? (e.setParent(l),
  68. e.position = s,
  69. e.rotation = a,
  70. e.scaling = o) : logger.error("[Engine] avatar or attachment not found!")
  71. }
  72. detachFromAvatar(e,t=!1) {
  73. this._mesh && e ? this._mesh.removeChild(e) : logger.error("[Engine] avatar not found!")
  74. }
  75. get mesh() {
  76. return this._mesh
  77. }
  78. get position() {
  79. var o;
  80. if (!this._mesh)
  81. return null;
  82. const {x: e, y: t, z: r} = (o = this._mesh) == null ? void 0 : o.position;
  83. return xversePosition2Ue4({
  84. x: e,
  85. y: t,
  86. z: r
  87. })
  88. }
  89. get id() {
  90. return this._id
  91. }
  92. get group() {
  93. return this._group
  94. }
  95. get isMoving() {
  96. return this._isMoving
  97. }
  98. get isVisible() {
  99. return this._isVisible
  100. }
  101. get isRotating() {
  102. return this._isRotating
  103. }
  104. get skinInfo() {
  105. return this._skinInfo
  106. }
  107. allowMove() {
  108. this._mesh != null && (this._mesh.getChildMeshes().forEach(e=>{
  109. e.unfreezeWorldMatrix()
  110. }
  111. ),
  112. this._mesh.unfreezeWorldMatrix())
  113. }
  114. unallowMove() {
  115. this._mesh != null && (this._mesh.getChildMeshes().forEach(e=>{
  116. e.freezeWorldMatrix()
  117. }
  118. ),
  119. this._mesh.freezeWorldMatrix())
  120. }
  121. getID() {
  122. return this._id
  123. }
  124. setPosition(e) {
  125. if (this._mesh) {
  126. const t = ue4Position2Xverse(e);
  127. this._mesh.position = t
  128. } else
  129. logger.error("[Engine] no root for positioning")
  130. }
  131. setRotation(e) {
  132. const t = ue4Rotation2Xverse_mesh(e);
  133. this._mesh ? this._mesh.rotation = t : logger.error("[Engine] no root for rotating")
  134. }
  135. setScale(e) {
  136. this._mesh ? this._mesh.scaling = new BABYLON.Vector3(e,e,-e) : logger.error("[Engine] no root for scaling")
  137. }
  138. disableAvatar() {
  139. var e;
  140. (e = this._mesh) == null || e.setEnabled(!1)
  141. }
  142. enableAvatar() {
  143. var e;
  144. (e = this._mesh) == null || e.setEnabled(!0)
  145. }
  146. togglePickable(e) {
  147. var t;
  148. (t = this.mesh) == null || t.getChildMeshes().forEach(r=>{
  149. "instances"in r && "isPickable"in r && (r.isPickable = e)
  150. }
  151. ),
  152. this.mesh != null && "isPickable"in this.mesh && (this.mesh.isPickable = e)
  153. }
  154. setMaterial(e) {
  155. var t;
  156. (t = this.mesh) == null || t.getChildMeshes().forEach(r=>{
  157. "instances"in r && "material"in r && (r.material = e)
  158. }
  159. ),
  160. this.mesh != null && "material"in this.mesh && (this.mesh.material = e)
  161. }
  162. dispose(e=!1, t=!1) {
  163. !this.mesh.isDisposed() && this.mesh.dispose(e, t)
  164. }
  165. }