XStaticMeshComponent.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583
  1. import XStaticMesh from "./XStaticMesh.js"
  2. import EMeshType from "./enum/EMeshType.js"
  3. import XStaticMeshFromOneGltf from "./XStaticMeshFromOneGltf.js"
  4. import XLowpolyModelError from "./error/XLowpolyModelError.js"
  5. import Logger from "./Logger.js"
  6. import util from "./util.js"
  7. const logger = new Logger('XStaticMeshComponent')
  8. export default class XStaticMeshComponent{
  9. constructor(e) {
  10. E(this, "scene");
  11. E(this, "_staticmeshes");
  12. E(this, "_lowModel_group");
  13. E(this, "_CgPlane");
  14. E(this, "_rootDir");
  15. E(this, "_abosoluteUrl");
  16. E(this, "_partMeshSkinInfo");
  17. E(this, "_meshInfoJson");
  18. E(this, "_orijson");
  19. E(this, "_notUsedRegionLists");
  20. E(this, "_meshInfoKeys");
  21. E(this, "_currentUpdateRegionCount");
  22. E(this, "_currentMeshUsedLod");
  23. E(this, "_currentPartGroup");
  24. E(this, "_allowRegionUpdate");
  25. E(this, "_allowRegionForceLod");
  26. E(this, "_forceLod");
  27. E(this, "_scenemanager");
  28. E(this, "regionIdInCamera");
  29. E(this, "regionIdInCameraConst");
  30. E(this, "_cameraInRegionId");
  31. E(this, "_meshVis");
  32. E(this, "_doMeshVisChangeNumber");
  33. E(this, "_meshVisTypeName");
  34. E(this, "_visCheckDurationFrameNumber");
  35. E(this, "_regionLodRule");
  36. E(this, "reg_staticmesh_partupdate", ()=>{
  37. if (this._allowRegionUpdate && (this.scene.getFrameId(),
  38. this._meshUpdateFrame()),
  39. this._allowRegionForceLod) {
  40. this.scene.getFrameId() % 2 == 0 && this.setOneRegionLod(this._meshInfoKeys[this._currentUpdateRegionCount % this._meshInfoKeys.length].toString(), this._forceLod);
  41. let t = !0;
  42. const r = Array.from(this._currentMeshUsedLod.keys());
  43. if (r.length > 0) {
  44. for (let n = 0; n < r.length; ++n)
  45. this._currentMeshUsedLod.get(r[n]) != this._forceLod && (t = !1);
  46. t && (this._allowRegionForceLod = !1)
  47. }
  48. }
  49. }
  50. );
  51. E(this, "setMeshInfo", (e,t="")=>{
  52. this._abosoluteUrl != e && (this._abosoluteUrl.length > 0 && this.deleteLastRegionMesh(),
  53. this._partMeshSkinInfo = t,
  54. this._abosoluteUrl = e,
  55. this._rootDir = this._abosoluteUrl.slice(0, -4) + "/",
  56. this.parseJson(this._rootDir + "meshInfo.json").then(()=>{
  57. this.startMeshUpdate()
  58. }
  59. ))
  60. }
  61. );
  62. E(this, "_meshUpdateFrame", ()=>{
  63. {
  64. let e = this._meshInfoKeys[this._currentUpdateRegionCount % this._meshInfoKeys.length];
  65. const t = !0;
  66. let r = 3;
  67. if (this._scenemanager != null && this._scenemanager.cameraComponent != null) {
  68. const n = this._getMainPlayerPosition();
  69. if (n != null) {
  70. if (this._cameraInRegionId >= 0) {
  71. const a = this.getRegionIdWhichIncludeCamera(n);
  72. (this._cameraInRegionId != a || this.regionIdInCamera.length == 0) && (this._cameraInRegionId = a,
  73. this.regionIdInCamera = this._getNeighborId(this._cameraInRegionId.toString()),
  74. this.regionIdInCameraConst = this.regionIdInCamera.slice());
  75. let s = this.regionIdInCamera.pop();
  76. for (; s != null; )
  77. if (this._notUsedRegionLists.indexOf(s) >= 0)
  78. s = this.regionIdInCamera.pop();
  79. else
  80. break;
  81. s != null && (e = s.toString())
  82. } else
  83. this._cameraInRegionId = this.getRegionIdWhichIncludeCamera(n);
  84. if (this._currentMeshUsedLod.size == 0 || this._notUsedRegionLists.indexOf(parseInt(e)) >= 0) {
  85. e = this._cameraInRegionId.toString();
  86. const a = this._getNeighborId(e);
  87. for (; a.length == 0 && (e = this.getNearestRegionIdWithCamera(n).toString()),
  88. this._notUsedRegionLists.indexOf(parseInt(e)) >= 0; )
  89. e = a.pop().toString()
  90. }
  91. const o = this._meshInfoJson[this._cameraInRegionId.toString()].lod;
  92. r = 3,
  93. this._cameraInRegionId.toString() == e ? r = this._regionLodRule[0] : o[0].indexOf(parseInt(e)) >= 0 ? r = this._regionLodRule[1] : o[1].indexOf(parseInt(e)) >= 0 ? r = this._regionLodRule[2] : o[2].indexOf(parseInt(e)) >= 0 ? r = this._regionLodRule[3] : r = this._regionLodRule[4]
  94. }
  95. }
  96. this.setOneRegionLod(e, r, t),
  97. this.updateRegionNotInLocalNeighbor(),
  98. this.cleanRootNodes()
  99. }
  100. }
  101. );
  102. E(this, "updateRegionNotInLocalNeighbor", ()=>{
  103. Array.from(this._currentMeshUsedLod.keys()).forEach(t=>{
  104. this.regionIdInCameraConst.indexOf(parseInt(t)) < 0 && this.setOneRegionLod(t, -1)
  105. }
  106. )
  107. }
  108. );
  109. E(this, "cleanRootNodes", ()=>{
  110. if (this.scene.getFrameId() % 3 == 0) {
  111. const e = [];
  112. this.scene.rootNodes.forEach(t=>{
  113. (t.getClassName() == "TransformNode" && t.getChildren().length == 0 || t.getClassName() == "Mesh" && t.name == "__root__" && t.getChildren().length == 0) && e.push(t)
  114. }
  115. ),
  116. e.forEach(t=>{
  117. t.dispose()
  118. }
  119. )
  120. }
  121. }
  122. );
  123. E(this, "setOneRegionLod", (e,t,r=!0)=>{
  124. this._currentUpdateRegionCount++;
  125. const n = this._calHashCode(this._rootDir)
  126. , o = "region_" + n + "_" + e;
  127. if (t < 0) {
  128. this._currentMeshUsedLod.has(e) && (this._currentMeshUsedLod.delete(e),
  129. this._currentPartGroup.delete(o),
  130. this.deleteMeshesByCustomProperty("group", "region_" + n + "_" + e));
  131. return
  132. }
  133. const a = this._rootDir + e + "_lod" + t + "_xverse.glb"
  134. , s = this._currentMeshUsedLod.get(e);
  135. this._currentPartGroup.add(o),
  136. s != null ? s != t && (this._currentMeshUsedLod.set(e, t),
  137. this._scenemanager.addNewLowPolyMesh({
  138. url: a,
  139. group: "region_" + n + "_" + e,
  140. pick: !0,
  141. lod: t,
  142. skinInfo: this._partMeshSkinInfo
  143. }, [{
  144. group: "region_" + n + "_" + e,
  145. mode: 0
  146. }])) : (this._currentMeshUsedLod.set(e, t),
  147. this._scenemanager.addNewLowPolyMesh({
  148. url: a,
  149. group: "region_" + n + "_" + e,
  150. pick: !0,
  151. lod: t,
  152. skinInfo: this._partMeshSkinInfo
  153. }))
  154. }
  155. );
  156. E(this, "checkPointInView", ({x: e, y: t, z: r})=>{
  157. const n = util.ue4Position2Xverse({
  158. x: e,
  159. y: t,
  160. z: r
  161. });
  162. if (!n)
  163. return !1;
  164. for (let o = 0; o < 6; o++)
  165. if (this.scene.frustumPlanes[o].dotCoordinate(n) < 0)
  166. return !1;
  167. return !0
  168. }
  169. );
  170. E(this, "addNewLowPolyMesh", (e,t,r)=>{
  171. if (!e.url.endsWith("glb") && !e.url.startsWith("blob:"))
  172. return e.url.endsWith("zip") ? (this.setMeshInfo(e.url, e.skinInfo),
  173. Promise.resolve(!0)) : (logger.error("[Engine] input model path is error! ", e.url),
  174. Promise.reject(new XLowpolyModelError("[Engine] input model path is error! " + e.url)));
  175. {
  176. const n = e.url;
  177. return new Promise((o,a)=>this._scenemanager.urlTransformer(e.url).then(s=>{
  178. e.url = s;
  179. const l = new XStaticMeshFromOneGltf(this.scene,e)
  180. , u = Date.now();
  181. return new Promise((c,h)=>{
  182. l.loadMesh(r, !0).then(f=>{
  183. const d = Date.now();
  184. if (this._scenemanager.engineRunTimeStats.timeArray_loadStaticMesh.add(d - u),
  185. f == !0) {
  186. const _ = this.getLowModelType(e);
  187. let g = 0;
  188. if (this._lowModel_group.has(_) && (g = this._lowModel_group.get(_).length),
  189. r != null && this._scenemanager.currentShader != null && this._scenemanager.currentShader.name != r.name && l.setMaterial(this._scenemanager.currentShader),
  190. this._allowRegionUpdate == !1 && _.startsWith("region_"))
  191. l.dispose();
  192. else if (this._staticmeshes.push(l),
  193. this.lowmodelGroupMapAddValue(_, l),
  194. t != null && t.length > 0) {
  195. const m = [];
  196. for (let v = 0; v < t.length; ++v)
  197. m.push(t[v].group),
  198. this.updateLowModelGroup(t[v], _, g)
  199. }
  200. this._scenemanager.engineRunTimeStats.timeArray_updateStaticMesh.add(Date.now() - d),
  201. c(!0)
  202. } else
  203. h(new XLowpolyModelError("[Engine] after lowmodel error!"))
  204. }
  205. ).catch(f=>{
  206. logger.error("[Engine] load Mesh [" + n + "] error! " + f),
  207. h(new XLowpolyModelError(`[Engine] load Mesh [${n}] error! ${f}`))
  208. }
  209. )
  210. }
  211. )
  212. }
  213. ).then(s=>{
  214. s == !0 ? (logger.info(`[Engine] load Mesh [${n}] successfully.`),
  215. o(!0)) : a(!1)
  216. }
  217. ).catch(s=>{
  218. logger.error("[Engine] addNewLowPolyMesh [" + n + "] error! " + s),
  219. a(new XLowpolyModelError(`[Engine] addNewLowPolyMesh [${n}] error! ${s}`))
  220. }
  221. ))
  222. }
  223. }
  224. );
  225. E(this, "toggleLowModelVisibility", e=>{
  226. const {vis: t, groupName: r="", skinInfo: n=""} = e;
  227. this._meshVis = t,
  228. this._meshVisTypeName = {
  229. groupName: r,
  230. skinInfo: n
  231. },
  232. this._doMeshVisChangeNumber = 0,
  233. r == Te.ALL_MESHES || this._currentPartGroup.has(r) == !0 || this._partMeshSkinInfo == n ? t == !1 ? (this._visCheckDurationFrameNumber = 100,
  234. this.stopMeshUpdate()) : (this._visCheckDurationFrameNumber = 1,
  235. this.startMeshUpdate()) : this._visCheckDurationFrameNumber = 1
  236. }
  237. );
  238. E(this, "reg_staticmesh_visibility", ()=>{
  239. if (this._doMeshVisChangeNumber >= 0)
  240. if (this._doMeshVisChangeNumber < this._visCheckDurationFrameNumber)
  241. if (this._doMeshVisChangeNumber = this._doMeshVisChangeNumber + 1,
  242. this._meshVisTypeName.groupName == Te.ALL_MESHES)
  243. this._lowModel_group.forEach((e,t)=>{
  244. for (let r = 0, n = e.length; r < n; ++r)
  245. e[r].toggleVisibility(this._meshVis)
  246. }
  247. );
  248. else {
  249. if (this._lowModel_group.has(this._meshVisTypeName.groupName))
  250. for (let e = 0; e < this._lowModel_group.get(this._meshVisTypeName.groupName).length; ++e)
  251. this._lowModel_group.get(this._meshVisTypeName.groupName)[e].toggleVisibility(this._meshVis);
  252. if (this._meshVisTypeName.skinInfo != "")
  253. for (let e = 0; e < this._staticmeshes.length; ++e)
  254. this._staticmeshes[e].skinInfo == this._meshVisTypeName.skinInfo && this._staticmeshes[e].toggleVisibility(this._meshVis)
  255. }
  256. else
  257. this._meshVis = !0,
  258. this._meshVisTypeName = {
  259. groupName: "",
  260. skinInfo: ""
  261. },
  262. this._doMeshVisChangeNumber = -1
  263. }
  264. );
  265. E(this, "_getMeshesByCustomProperty", (e,t)=>{
  266. let r = [];
  267. return this._staticmeshes.forEach(n=>{
  268. n[e] != null && n[e] == t && (r = r.concat(n.meshes))
  269. }
  270. ),
  271. r
  272. }
  273. );
  274. this._lowModel_group = new Map,
  275. this._staticmeshes = [],
  276. this._meshInfoJson = null,
  277. this._meshInfoKeys = [],
  278. this._currentUpdateRegionCount = 0,
  279. this._abosoluteUrl = "",
  280. this._partMeshSkinInfo = "",
  281. this._forceLod = 3,
  282. this._allowRegionUpdate = !1,
  283. this._allowRegionForceLod = !1,
  284. this._currentMeshUsedLod = new Map,
  285. this._currentPartGroup = new Set,
  286. this._scenemanager = e,
  287. this.scene = e.Scene,
  288. this.regionIdInCamera = [],
  289. this.regionIdInCameraConst = [],
  290. this._cameraInRegionId = -1,
  291. this._rootDir = "",
  292. this._meshVis = !0,
  293. this._meshVisTypeName = {
  294. groupName: "",
  295. skinInfo: ""
  296. },
  297. this._doMeshVisChangeNumber = -1,
  298. this._visCheckDurationFrameNumber = -1,
  299. this._regionLodRule = [0, 1, 3, 3, -1],
  300. this.initCgLowModel(),
  301. this._regionPartLoop()
  302. }
  303. get cameraInRegionId() {
  304. return this._cameraInRegionId
  305. }
  306. setRegionLodRule(e) {
  307. return e.length != 5 ? !1 : (e.forEach(t=>{}
  308. ),
  309. this._regionLodRule = e,
  310. !0)
  311. }
  312. get lowModel_group() {
  313. return this._lowModel_group
  314. }
  315. _regionPartLoop() {
  316. this.scene.registerBeforeRender(this.reg_staticmesh_partupdate),
  317. this.scene.registerAfterRender(this.reg_staticmesh_visibility)
  318. }
  319. _globalSearchCameraInWhichRegion(e, t) {
  320. let r = -1;
  321. for (let n = 0; n < t.length; ++n) {
  322. const o = this._meshInfoJson[t[n].toString()].boundingbox
  323. , a = o[0]
  324. , s = o[1];
  325. if (e.x >= a[0] && e.x <= s[0] && e.y >= a[1] && e.y <= s[1] && e.z >= a[2] && e.z <= s[2] || e.x >= s[0] && e.x <= a[0] && e.y >= s[1] && e.y <= a[1] && e.z >= s[2] && e.z <= a[2]) {
  326. r = parseInt(t[n].toString());
  327. break
  328. }
  329. }
  330. return r
  331. }
  332. getRegionIdByPosition(e) {
  333. return this.getRegionIdWhichIncludeCamera(e)
  334. }
  335. getRegionIdWhichIncludeCamera(e) {
  336. let t = -1;
  337. if (this._allowRegionUpdate == !1)
  338. return t;
  339. if (this._cameraInRegionId == -1 ? t = this._globalSearchCameraInWhichRegion(e, this._meshInfoKeys) : (t = this._globalSearchCameraInWhichRegion(e, this.regionIdInCameraConst),
  340. t == -1 && (t = this._globalSearchCameraInWhichRegion(e, this._meshInfoKeys))),
  341. t == -1) {
  342. let r = 1e7;
  343. for (let n = 0; n < this._meshInfoKeys.length; ++n) {
  344. const o = this._meshInfoJson[this._meshInfoKeys[n]].center
  345. , a = Math.abs(e.x - o[0]) + Math.abs(e.y - o[1]);
  346. r > a && (r = a,
  347. t = parseInt(this._meshInfoKeys[n]))
  348. }
  349. }
  350. return t
  351. }
  352. getNearestRegionIdWithCamera(e) {
  353. let t = 1
  354. , r = 1e7;
  355. for (let n = 0; n < this._meshInfoKeys.length; ++n) {
  356. if (this._notUsedRegionLists.indexOf(parseInt(this._meshInfoKeys[n])) >= 0)
  357. continue;
  358. const o = this._meshInfoJson[this._meshInfoKeys[n]].center
  359. , a = Math.abs(e.x - o[0]) + Math.abs(e.y - o[1]);
  360. r > a && (r = a,
  361. t = parseInt(this._meshInfoKeys[n]))
  362. }
  363. return t
  364. }
  365. _getNeighborId(e) {
  366. const t = this._meshInfoJson[e].lod;
  367. let r = [];
  368. const n = Object.keys(t);
  369. for (let o = n.length - 1; o >= 0; --o)
  370. r = r.concat(t[n[o]]);
  371. return r.push(parseInt(e)),
  372. r
  373. }
  374. _getMainPlayerPosition() {
  375. const e = this._scenemanager.cameraComponent.getCameraPose().position
  376. , t = this._scenemanager.avatarComponent.getMainAvatar();
  377. if (t != null && t != null) {
  378. const r = t.position;
  379. if (r != null)
  380. return r
  381. }
  382. return e
  383. }
  384. _calHashCode(e) {
  385. return hashCode(e) + "_" + this._partMeshSkinInfo
  386. }
  387. forceAllRegionLod(e=3) {
  388. e < 0 && (e = 0),
  389. e > 3 && (e = 3),
  390. this.stopMeshUpdate(),
  391. this._allowRegionForceLod = !0,
  392. this._forceLod = e
  393. }
  394. deleteLastRegionMesh() {
  395. if (this._rootDir != "") {
  396. const e = this._calHashCode(this._rootDir);
  397. this._currentMeshUsedLod.clear(),
  398. this._currentPartGroup.clear(),
  399. this._meshInfoJson = null,
  400. this._meshInfoKeys = [],
  401. this._currentUpdateRegionCount = 0,
  402. this._orijson = null,
  403. this._notUsedRegionLists = [],
  404. this._partMeshSkinInfo = "",
  405. this._abosoluteUrl = "",
  406. this.stopMeshUpdate(),
  407. this.deleteMeshesByCustomProperty("group", "region_" + e, !0)
  408. }
  409. }
  410. startMeshUpdate() {
  411. this._allowRegionUpdate == !1 && this._meshInfoJson != null && this._abosoluteUrl != "" && this._meshInfoKeys.length > 0 && (this._allowRegionUpdate = !0)
  412. }
  413. stopMeshUpdate() {
  414. this._allowRegionUpdate = !1
  415. }
  416. parseJson(e) {
  417. return new Promise((t,r)=>this._scenemanager.urlTransformer(e).then(n=>{
  418. const o = new XMLHttpRequest;
  419. o.open("get", n),
  420. o.send(null),
  421. o.onload = ()=>{
  422. if (o.status == 200) {
  423. const a = JSON.parse(o.responseText);
  424. this._orijson = a,
  425. this._meshInfoJson = this._orijson.usedRegion,
  426. this._notUsedRegionLists = this._orijson.notUsedRegion,
  427. this._meshInfoKeys = Object.keys(this._meshInfoJson),
  428. logger.info("[Engine] parse zip mesh info successful"),
  429. t()
  430. }
  431. }
  432. ,
  433. o.onerror = ()=>{
  434. logger.error(`[Engine] load zip mesh info json error, (provided by blob): ${n}`),
  435. r(new XLowpolyJsonError(`[Engine] load zip mesh info json error, (provided by blob): ${n}`))
  436. }
  437. }
  438. ).catch(n=>{
  439. logger.error(`[Engine] load zip mesh info json error: ${n}, link:${e}`),
  440. r(new XLowpolyJsonError(`[Engine] load zip mesh info json error: ${n}, link: ${e}`))
  441. }
  442. ))
  443. }
  444. initCgLowModel() {
  445. const e = BABYLON.MeshBuilder.CreatePlane("CgPlane", {
  446. size: 400
  447. });
  448. e.position = new BABYLON.Vector3(0,1010,0),
  449. e.rotation = new BABYLON.Vector3(3 * Math.PI / 2,0,0),
  450. this._CgPlane = new XStaticMesh({
  451. id: "CgPlane",
  452. mesh: e,
  453. xtype: EMeshType.Cgplane
  454. }),
  455. this._CgPlane.hide()
  456. }
  457. getLowModelType(e) {
  458. let t = "";
  459. return e.group != null ? t = e.group : t = "default",
  460. t
  461. }
  462. lowmodelGroupMapAddValue(e, t) {
  463. const r = this._lowModel_group.get(e);
  464. r != null ? (r.push(t),
  465. this._lowModel_group.set(e, r)) : this._lowModel_group.set(e, [t])
  466. }
  467. updateLowModelGroup(e, t, r) {
  468. let n = r;
  469. e.group == t || (n = -1),
  470. e.mode == 0 ? this.deleteLowModelGroup(e.group, n) : e.mode == 1 ? this.toggleVisibleLowModelGroup(!1, e.group, n) : e.mode == 2 && this.toggleVisibleLowModelGroup(!0, e.group, n)
  471. }
  472. toggleVisibleLowModelGroup(e, t, r=-1) {
  473. if (this._lowModel_group.has(t)) {
  474. const n = this._lowModel_group.get(t);
  475. let o = n.length;
  476. r >= 0 && o >= r && (o = r);
  477. for (let a = 0; a < o; ++a)
  478. n[a].toggleVisibility(e)
  479. }
  480. }
  481. deleteLowModelGroup(e, t=-1) {
  482. if (this._lowModel_group.has(e)) {
  483. const o = this._lowModel_group.get(e);
  484. let a = o.length;
  485. t >= 0 && a >= t && (a = t);
  486. for (let s = 0; s < a; ++s)
  487. o[s].dispose();
  488. t >= 0 ? this._lowModel_group.set(e, this._lowModel_group.get(e).slice(a)) : this._lowModel_group.delete(e)
  489. }
  490. const r = this._lowModel_group.get(e)
  491. , n = [];
  492. r != null && r.length > 0 ? this._staticmeshes.forEach(o=>{
  493. if (o.group != e)
  494. n.push(o);
  495. else
  496. for (let a = 0; a < r.length; ++a)
  497. o.groupUuid == r[a].groupUuid && n.push(o)
  498. }
  499. ) : this._staticmeshes.forEach(o=>{
  500. o.group != e && n.push(o)
  501. }
  502. ),
  503. this._staticmeshes = n
  504. }
  505. deleteMeshesByGroup(e) {
  506. this.deleteLowModelGroup(e)
  507. }
  508. deleteMeshesById(e) {
  509. this.deleteMeshesByCustomProperty("id", e)
  510. }
  511. deleteMeshesByLoD(e) {
  512. this.deleteMeshesByCustomProperty("lod", e)
  513. }
  514. deleteMeshesBySkinInfo(e) {
  515. this.deleteMeshesByCustomProperty("skinInfo", e)
  516. }
  517. removeMeshesFromSceneByGroup(e) {
  518. this.removeMeshesFromSceneByCustomProperty("group", e)
  519. }
  520. removeMeshesFromSceneById(e) {
  521. this.removeMeshesFromSceneByCustomProperty("id", e)
  522. }
  523. addMeshesToSceneByGroup(e) {
  524. this.addMeshesToSceneByCustomProperty("group", e)
  525. }
  526. addMeshesToSceneById(e) {
  527. this.addMeshesToSceneByCustomProperty("id", e)
  528. }
  529. removeMeshesFromSceneByCustomProperty(e, t, r=!1) {
  530. this._staticmeshes.forEach(n=>{
  531. n.isinscene && n[e] != null && (r ? n[e].indexOf(t) < 0 || n.removeFromScene() : n[e] != t || n.removeFromScene())
  532. }
  533. )
  534. }
  535. addMeshesToSceneByCustomProperty(e, t, r=!1) {
  536. this._staticmeshes.forEach(n=>{
  537. n.isinscene == !1 && n[e] != null && (r ? n[e].indexOf(t) < 0 || n.addToScene() : n[e] != t || n.addToScene())
  538. }
  539. )
  540. }
  541. deleteMeshesByCustomProperty(e, t, r=!1) {
  542. const n = [];
  543. this._staticmeshes.forEach(a=>{
  544. a[e] != null && (r ? a[e].indexOf(t) < 0 ? n.push(a) : a.dispose() : a[e] != t ? n.push(a) : a.dispose())
  545. }
  546. ),
  547. this._staticmeshes = n;
  548. const o = Array.from(this._lowModel_group.keys());
  549. for (let a = 0; a < o.length; ++a) {
  550. const s = o[a]
  551. , l = this._lowModel_group.get(s);
  552. if (l != null) {
  553. const u = [];
  554. for (let c = 0; c < l.length; ++c)
  555. l[c][e] != null && (r ? l[c][e].indexOf(t) < 0 && u.push(l[c]) : l[c][e] != t && u.push(l[c]));
  556. u.length > 0 ? this._lowModel_group.set(s, u) : this._lowModel_group.delete(s)
  557. }
  558. }
  559. }
  560. getMeshes() {
  561. let e = [];
  562. for (let t = 0; t < this._staticmeshes.length; ++t)
  563. e = e.concat(this._staticmeshes[t].meshes);
  564. return e
  565. }
  566. getCgMesh() {
  567. return this._CgPlane
  568. }
  569. getMeshesByGroup(e="default") {
  570. const t = this._lowModel_group.get(e);
  571. if (t != null) {
  572. let r = [];
  573. for (let n = 0; n < t.length; ++n)
  574. r = r.concat(t[n].meshes);
  575. return r
  576. } else
  577. return null
  578. }
  579. getMeshesByGroup2(e="default") {
  580. return this._getMeshesByCustomProperty("group", e)
  581. }
  582. }