Browse Source

3dModeling buildingCreate.js 王祥 commit at 2021-01-29

王祥 4 years ago
parent
commit
8f50180d58
1 changed files with 180 additions and 0 deletions
  1. 180 0
      3dModeling/tjby26/buildingCreate.js

+ 180 - 0
3dModeling/tjby26/buildingCreate.js

@@ -392,3 +392,183 @@ function registerEvent() {
         if (ev.button == 0 && box != null) {
             let pos = box.position;
             box.destroy();
+            box = null;
+            app.camera.flyTo(pos);
+            enterFps([pos[0], pos[1] + 2, pos[2]]);
+        }
+        checkBtnActives(['#mapBg', '#sceneSetting']);
+    });
+    // 进入层级事件,退出第一人称行走
+    app.on(THING.EventType.EnterLevel, function () {
+        if (fpsCtrl != null) {
+            exitFps();
+        }
+    });
+    // 离开层级事件,停止旋转
+    app.on(THING.EventType.LeaveLevel, function () {
+        stopRotate();
+    })
+    // 鼠标滑轮事件,停止旋转
+    app.on(THING.EventType.MouseWheel, function () {
+        stopRotate();
+    })
+    // 场景添加键盘按下事件,当进入第一人称行走时,按下esc键退出第一人称行走
+    app.on(THING.EventType.KeyDown, function (ev) {
+        if (ev.code == 'Escape') {
+            if (box != null) {
+                app.resumeEvent(THING.EventType.DBLClick, '*', THING.EventTag.LevelEnterOperation);
+                app.resumeEvent(THING.EventType.Click, '*', THING.EventTag.LevelBackOperation);
+                box.destroy();
+                box = null;
+                $('#moveByFps').removeClass('active');
+                restarRotate();
+            }
+            if (fpsCtrl != null) {
+                exitFps();
+                restarRotate();
+            }
+            checkBtnActives(['#mapBg', '#sceneSetting']);
+        }
+    });
+    window.onresize = function () {
+        if (!checkFull()) {
+            //要执行的动作
+            if (fullScreenState == true) {
+                $('.btn-full-screen').css('display', 'block');
+                $('.btn-narrow').css('display', 'none');
+                $('#fullScreen span').text('全屏');
+                fullScreenState = false;
+            }
+        }
+    }
+}
+
+
+//====设备闪烁提示====
+function flash(objArray) {
+    objArray.forEach(function (obj) {
+        obj.on('update', function () {
+            obj.style.color = '#FFF000'
+            obj.style.opacity = 0.5 + 0.5 * Math.sin(2 * app.elapsedTime / 500);
+        }, '每帧改变透明度');
+    })
+}
+function queryDeviceStatus(evt) {
+    objArray = evt.data;
+    // objArray.forEach(function (deviceobj) {
+    //     obj = app.query("#" + deviceobj.ownerCode)[0];
+    //     obj.on('update', function () {
+    //         obj.style.color = '#FF0000'
+    //         obj.style.opacity = 0.5 + 0.5 * Math.sin(2 * app.elapsedTime / 500);
+    //     }, '每帧改变透明度');
+
+
+    // })
+    obj = app.query("#" + objArray)[0];
+    obj.on('update', function () {
+        obj.style.color = '#FF0000'
+        obj.style.opacity = 0.5 + 0.5 * Math.sin(2 * app.elapsedTime / 500);
+    }, '每帧改变透明度');
+}
+function reset(objArray) {
+    objArray.forEach(function (obj) {
+        obj.style.opacity = 1.0;
+        obj.style.color = null;
+        obj.off('update', null, '每帧改变透明度');
+    })
+}
+var timer = null;
+function getTabledata(d) {
+    var ygArray = [];
+    d.forEach(function (d) {
+        var deviceInfo = {
+            "设备编号": d.ownerCode,
+            "设备名称": d.ownerName,
+            "安装位置": d.unitinfo,
+        };
+        ygArray.push(deviceInfo)
+    })
+    // 表格数据//创建对象 book
+    var tableData = {
+
+        // 列标题
+        props: ['设备编号', '设备名称', '安装位置'],
+        // 列数据
+        items: ygArray
+    };
+    return tableData;
+}
+function createPerson(name, age, family) {
+    var o = new Object();
+    o.name = name;
+    o.age = age;
+    o.family = family;
+    o.say = function () {
+        alert(this.name);
+    }
+    return o;
+}
+function destroyPanel() {
+    var mydiv = document.getElementById('mydiv')
+    mydiv.remove();
+}
+//====================
+function updateData(obj) {
+
+    /** ******************* 以下为websoket数据对接 ********************/
+    // 对接自有websoket服务器
+    if (!webSocket) {
+        // 如果网站是 https 则对应 wss
+        // 如果网站是 http 则对应 ws 即可
+        webSocket = new WebSocket('ws://101.133.214.75:8080/Device_Manager/socket');
+        // 建立 websocket 连接成功触发事件
+        webSocket.onopen = function () {
+
+        };
+        // 接收服务端数据时触发事件
+        webSocket.onmessage = function (evt) {
+            queryDeviceStatus(evt);
+        };
+        webSocket.onclose = function (evt) {
+
+            webSocket = null;
+        }
+    }
+}
+
+//接收父级页面数据
+function userListener(data) {
+    
+    buildingStore = data.data;
+}
+
+// 监听用户页面传回的数据 并调用 ThingJS 页面方法
+window.addEventListener('message', function (e) {
+    var _this=this;
+    var array;
+    var data = e.data;
+    var funcName = data.funcName;
+    var param = data.param;
+    var company_code = e.data.param.company_code
+    // 调用 ThingJS 页面方法
+    window[funcName](param);
+    
+    //请求场景url的json文件
+    $.ajax({
+        type: "GET",
+        url:'/uploads/wechat/163607/file/杨浦16/park.json',
+        dataType: "json",
+        success: function (data) {
+            for(let i = 0; i < data.array.length; i++){
+                if(company_code === data.array[i].id){
+                    campusUrl = data.array[i]
+                    _this.changeScene(campusUrl);
+                    _this.createWidgets();
+                }
+            }
+        }
+    });
+});
+
+//父级页面数据处理
+function cleanObj(arr, key) {