XStaticMesh.js 5.2 KB

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