XStaticMeshFromOneGltf.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. class XStaticMeshFromOneGltf {
  2. constructor(e, t) {
  3. E(this, "_scene");
  4. E(this, "_url");
  5. E(this, "_group");
  6. E(this, "_pickable");
  7. E(this, "_meshes");
  8. E(this, "_id");
  9. E(this, "_lod");
  10. E(this, "_groupUuid");
  11. E(this, "_isInScene");
  12. E(this, "_skinInfo");
  13. E(this, "loadMesh", (e,t)=>{
  14. const r = this._meshes.length
  15. , n = t ? 1 : 0
  16. , o = this._url;
  17. return SceneLoader.LoadAssetContainerAsync("", o, this._scene, ()=>{
  18. this._scene.blockMaterialDirtyMechanism = !0
  19. }
  20. , ".glb").then(a=>{
  21. for (let s = a.materials.length - 1; s >= 0; --s)
  22. a.materials[s].dispose();
  23. this._scene.blockMaterialDirtyMechanism = !0;
  24. for (let s = 0; s < a.meshes.length; ++s) {
  25. const l = a.meshes[s];
  26. if ("instances"in l) {
  27. "visibility"in l && (l.visibility = 0),
  28. "isPickable"in l && (l.isPickable = this._pickable),
  29. e != null && (l.material = e),
  30. "hasVertexAlpha"in l && (l.hasVertexAlpha = !1);
  31. const u = new XStaticMesh({
  32. id: this._groupUuid + "-" + Math.random().toString(36).substr(2, 5),
  33. mesh: l,
  34. lod: this._lod,
  35. group: this._group,
  36. url: this._url,
  37. xtype: EMeshType.XStaticMesh,
  38. skinInfo: this._skinInfo
  39. });
  40. this._meshes.push(u)
  41. }
  42. this._scene.addMesh(l)
  43. }
  44. return !0
  45. }
  46. ).then(()=>{
  47. this._isInScene = !0;
  48. for (let a = r; a < this._meshes.length; ++a)
  49. this._meshes[a].mesh.visibility = n;
  50. return Promise.resolve(!0)
  51. }
  52. ).catch(a=>{
  53. log$u.error("[Engine] input gltf mesh uri error! " + a),
  54. Promise.reject(new XLowpolyModelError("[Engine] input gltf mesh uri error! " + a))
  55. }
  56. )
  57. }
  58. );
  59. this._meshes = [],
  60. this._scene = e,
  61. this._url = t.url,
  62. t.group != null ? this._group = t.group : this._group = "default",
  63. t.pick != null ? this._pickable = t.pick : this._pickable = !1,
  64. t.id != null ? this._id = t.id : this._id = "default",
  65. t.lod != null ? this._lod = t.lod : this._lod = -1,
  66. t.skinInfo != null ? this._skinInfo = t.skinInfo : this._skinInfo = "default",
  67. this._groupUuid = uuid$2(),
  68. this._isInScene = !1
  69. }
  70. get isinscene() {
  71. return this._isInScene
  72. }
  73. get groupUuid() {
  74. return this._groupUuid
  75. }
  76. get skinInfo() {
  77. return this._skinInfo
  78. }
  79. get group() {
  80. return this._group
  81. }
  82. get meshes() {
  83. return this._meshes
  84. }
  85. get url() {
  86. return this._url
  87. }
  88. get id() {
  89. return this._id
  90. }
  91. get lod() {
  92. return this._lod
  93. }
  94. removeFromScene() {
  95. if (this._isInScene) {
  96. this._isInScene = !1;
  97. for (let e = 0, t = this._meshes.length; e < t; ++e)
  98. this._meshes[e].mesh != null && this._scene.removeMesh(this._meshes[e].mesh)
  99. }
  100. }
  101. addToScene() {
  102. if (this._isInScene == !1) {
  103. this._isInScene = !0;
  104. for (let e = 0, t = this._meshes.length; e < t; ++e)
  105. this._meshes[e].mesh != null && this._scene.addMesh(this._meshes[e].mesh)
  106. }
  107. }
  108. toggleVisibility(e) {
  109. const t = e ? 1 : 0;
  110. for (let r = 0, n = this._meshes.length; r < n; ++r)
  111. "visibility"in this._meshes[r].mesh && (this._meshes[r].mesh.visibility = t)
  112. }
  113. togglePickable(e) {
  114. for (let t = 0, r = this._meshes.length; t < r; ++t)
  115. "isPickable"in this._meshes[t].mesh && (this._meshes[t].mesh.isPickable = e)
  116. }
  117. setMaterial(e) {
  118. for (let t = 0, r = this._meshes.length; t < r; ++t)
  119. "material"in this._meshes[t].mesh && (this._meshes[t].mesh.material = e)
  120. }
  121. dispose() {
  122. for (let e = 0, t = this._meshes.length; e < t; ++e)
  123. this._meshes[e].mesh.dispose(!1, !1)
  124. }
  125. }