123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- import { ThreeWorldEvent } from './ThreeWorldEvent.js';
- /**
- * 操作3d世界的,单例模式的类对象
- */
- export class ThreeWorldEventMain {
-
- // 已经封装好的,编辑器的类对象,内置可以直接调用的代码
- public objIframeEdit : any = null;
- // iframe对象
- public objIframe : any = null;
- // 3d世界的场景,后续要操作3d世界常用的对象
- public objScene : any = null;
- // babylon 对象,懂babylon,就可以使用babylon的api去操作
- public BABYLON : any = null;
-
- static instance: any;
- // 每次 new 出对象则会调用这个构造函数
- constructor() {
-
- }
- // 实现单例模式
- static find() {
- if (!ThreeWorldEventMain.instance) {
- ThreeWorldEventMain.instance = new ThreeWorldEventMain();
- }
- return ThreeWorldEventMain.instance;
- }
- /**
- * 初始化方法
- * objIframeEdit 已经封装好的,编辑器的类对象,内置可以直接调用的代码
- * objIframe iframe对象
- * objScene 场景对象
- * BABYLON babylon.js对象,用于后续调用babylon的代码去创建更新等操作
- */
- initObj = (objIframeEdit : any, objIframe : any, objScene : any, BABYLON : any) => {
-
- if (this.objIframe != null && this.objIframe != undefined) {
- return this;
- }
- this.objIframeEdit = objIframeEdit;
- this.objIframe = objIframe;
- this.objScene = objScene;
- this.BABYLON = BABYLON;
-
- this.initClass();
-
- return this;
- }
- /**
- * 初始化其他会用到的类对象
- */
- initClass = () => {
- this.objThreeWorldEvent = new ThreeWorldEvent();
- this.objThreeWorldEvent.initObj(
- this.objIframeEdit,
- this.objIframe,
- this.objScene,
- this.BABYLON
- );
- return this;
- }
- /**
- * 切换到飞行模式,切换到指定的视角
- */
- toFlyModel = () => {
- this.objIframeEdit.modelPeopleLook(3);
- return this;
- }
-
- /**
- * 将所有设置为地面的,改为不设置为地面
- */
- groundNoRemove = () => {
-
- var ChengGuangYuanJing = this.objIframe.ChengGuangYuanJing;
- for (const key in ChengGuangYuanJing.ModelObjEdit.find().meshListIdToJson) {
-
- if (
- ChengGuangYuanJing.ModelObjEdit.find().meshListIdToJson[key]['isGround'] == true
- ) {
- // 通过更新材质的参数,来更新
- ChengGuangYuanJing.ModelObjEdit.find().objOneMeshListIdToJsonUpdate(
- key,
- {
-
- "isGround" : false,
- }
- );
- }
-
- }
-
- for (let i = 0; i < ChengGuangYuanJing.CommonVal.find().objScene.meshes.length; i++) {
-
- let objMesh = ChengGuangYuanJing.CommonVal.find().objScene.meshes[i];
- // console.log(
- // "myIsGround",
- // objMesh["myIsGround"]
- // );
- // if (objMesh["myIsGround"] == true) {
- // delete objMesh["myIsGround"];
- // }
- delete objMesh["myIsGround"];
- }
-
- ChengGuangYuanJing.Role.find().isGroundList = {};
- ChengGuangYuanJing.ModelObjEdit.find().myIsGroundConfigNum = 0;
- return this;
- }
-
- }
|