ThreeWorldEventMain.ts 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. import { ThreeWorldEvent } from './ThreeWorldEvent.js';
  2. /**
  3. * 操作3d世界的,单例模式的类对象
  4. */
  5. export class ThreeWorldEventMain {
  6. // 已经封装好的,编辑器的类对象,内置可以直接调用的代码
  7. public objIframeEdit : any = null;
  8. // iframe对象
  9. public objIframe : any = null;
  10. // 3d世界的场景,后续要操作3d世界常用的对象
  11. public objScene : any = null;
  12. // babylon 对象,懂babylon,就可以使用babylon的api去操作
  13. public BABYLON : any = null;
  14. static instance: any;
  15. // 每次 new 出对象则会调用这个构造函数
  16. constructor() {
  17. }
  18. // 实现单例模式
  19. static find() {
  20. if (!ThreeWorldEventMain.instance) {
  21. ThreeWorldEventMain.instance = new ThreeWorldEventMain();
  22. }
  23. return ThreeWorldEventMain.instance;
  24. }
  25. /**
  26. * 初始化方法
  27. * objIframeEdit 已经封装好的,编辑器的类对象,内置可以直接调用的代码
  28. * objIframe iframe对象
  29. * objScene 场景对象
  30. * BABYLON babylon.js对象,用于后续调用babylon的代码去创建更新等操作
  31. */
  32. initObj = (objIframeEdit : any, objIframe : any, objScene : any, BABYLON : any) => {
  33. if (this.objIframe != null && this.objIframe != undefined) {
  34. return this;
  35. }
  36. this.objIframeEdit = objIframeEdit;
  37. this.objIframe = objIframe;
  38. this.objScene = objScene;
  39. this.BABYLON = BABYLON;
  40. this.initClass();
  41. return this;
  42. }
  43. /**
  44. * 初始化其他会用到的类对象
  45. */
  46. initClass = () => {
  47. this.objThreeWorldEvent = new ThreeWorldEvent();
  48. this.objThreeWorldEvent.initObj(
  49. this.objIframeEdit,
  50. this.objIframe,
  51. this.objScene,
  52. this.BABYLON
  53. );
  54. return this;
  55. }
  56. /**
  57. * 切换到飞行模式,切换到指定的视角
  58. */
  59. toFlyModel = () => {
  60. this.objIframeEdit.modelPeopleLook(3);
  61. return this;
  62. }
  63. /**
  64. * 将所有设置为地面的,改为不设置为地面
  65. */
  66. groundNoRemove = () => {
  67. var ChengGuangYuanJing = this.objIframe.ChengGuangYuanJing;
  68. for (const key in ChengGuangYuanJing.ModelObjEdit.find().meshListIdToJson) {
  69. if (
  70. ChengGuangYuanJing.ModelObjEdit.find().meshListIdToJson[key]['isGround'] == true
  71. ) {
  72. // 通过更新材质的参数,来更新
  73. ChengGuangYuanJing.ModelObjEdit.find().objOneMeshListIdToJsonUpdate(
  74. key,
  75. {
  76. "isGround" : false,
  77. }
  78. );
  79. }
  80. }
  81. for (let i = 0; i < ChengGuangYuanJing.CommonVal.find().objScene.meshes.length; i++) {
  82. let objMesh = ChengGuangYuanJing.CommonVal.find().objScene.meshes[i];
  83. // console.log(
  84. // "myIsGround",
  85. // objMesh["myIsGround"]
  86. // );
  87. // if (objMesh["myIsGround"] == true) {
  88. // delete objMesh["myIsGround"];
  89. // }
  90. delete objMesh["myIsGround"];
  91. }
  92. ChengGuangYuanJing.Role.find().isGroundList = {};
  93. ChengGuangYuanJing.ModelObjEdit.find().myIsGroundConfigNum = 0;
  94. return this;
  95. }
  96. }