suyiScreen/public/htWeb/unity.html

1297 lines
62 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
html,
body {
width: 100%;
height: 100%;
overflow: hidden;
margin: 0;
}
#unity {
width: 100%;
height: 100%;
position: relative;
/* background: url('./lib/bgAll.png') no-repeat; */
background-size: cover;
}
@keyframes page-fade-in {
0% {
opacity: 0
}
100% {
opacity: 1
}
}
</style>
</head>
<body>
<div id="unity">
</div>
</body>
</html>
<!-- <script src="../src/assets/js/ht-init-config.js"></script> -->
<script src="lib/ht-init-config.js"></script>
<script src="./lib/vue.minV2.5.17.js"></script>
<script src="./lib/axios.minV0.18.0.js"></script>
<script src="lib/core/ht.js"></script>
<script src="lib/plugin/ht-obj.js"></script>
<script src="lib/plugin/ht-animation.js"></script>
<script src="./lib/require.js"></script>
<script>
function getQueryString(name) {
var reg = new RegExp("(^|&)" + name + "=([^'']*)(&|$)", "i");
// var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
var r = window.location.search.substr(1).match(reg);
if (r != null) return unescape(r[2]); return null;
}
var unity = new Vue({
el: '#unity',
data() {
return {
mtlFiles: [],
files: [],
realObj: [],
rawS3: null, // 模型原始大小
dm: null, // DataModel
g3d: null, // 3d环境
models: {},
modulesFiles: [],
modelResource: [],
modelUrl: '',
}
},
mounted() {
this.staticArr()
},
methods: {
staticArr() {
if (getQueryString('src') == 1) {
this.modulesFiles = ['Man_01', 'Man_02', 'Man_03', 'Man_04', 'newMemorial', 'monitorSix', 'monitorSeven', 'monitorEight']
this.modulesFiles.forEach((item, index) => {
var obj = {
cId: 1,
parentName: "车架",
name: '车架',
pos: [0, 0, 0],
size: [1, 1, 1],
rotate: [0, 0, 0],
wirePos: [],
affiliation: [],
type: "车架",
visible: true,
passenger: [],
taskCode: -1,
}
// if(index == 5){
// obj.pos = [2.784*17+5,-2.79*17+30,-9.017*17]
// }
obj.cId = index
obj.parentName = item
obj.type = item
obj.name = item
this.modelResource.push(obj)
})
this.modelUrl = 'export/XG_Model/'
if (this.modulesFiles.length == 8) {
this.getData()
}
} else if (getQueryString('src') == 2) {
this.modulesFiles = ['JG_Man_01', 'JG_Man_02', 'JG_Man_03', 'JG_Man_04', 'oldMemorial', 'monitorSix', 'monitorSeven', 'monitorEight']
this.modulesFiles.forEach((item, index) => {
var obj = {
cId: 1,
parentName: "车架",
name: '车架',
pos: [0, 0, 0],
size: [1, 1, 1],
rotate: [0, 0, 0],
wirePos: [],
affiliation: [],
type: "车架",
visible: true,
passenger: [],
taskCode: -1,
}
// if(index == 5){
// obj.pos = [45.563,-33.778,165.9623]
// }
obj.cId = index
obj.parentName = item
obj.type = item
obj.name = item
this.modelResource.push(obj)
})
this.modelUrl = 'OldHall/JG_Model/'
if (this.modulesFiles.length == 8) {
this.getData()
}
} else if (getQueryString('src') == 3) {
this.modulesFiles = ['10kV_CXX_1_hwg', '10kV_JSX_4_hwg', 'BJ', 'DL', 'JG', '1_UPS', '2_UPS', 'XG', 'YJDY_Car', 'BackGround', 'Human', 'Camera_01', 'Camera_02',
'BS_che', 'BS_hwg1', 'BS_hwg2', 'BS_ups1', 'BS_ups2']
this.modulesFiles.forEach((item, index) => {
var obj = {
cId: 1,
parentName: "车架",
name: '车架',
pos: [0, -20, 0],
size: [1, 1, 1],
rotate: [0, 0, 0],
wirePos: [],
affiliation: [],
type: "车架",
visible: true,
passenger: [],
taskCode: -1,
}
// if(index == 5){
// obj.pos = [45.563,-33.778,165.9623]
// }
obj.cId = index
obj.parentName = item
obj.type = item
obj.name = item
this.modelResource.push(obj)
})
this.modelUrl = 'baoDianHall/BD_export/'
if (this.modulesFiles.length == 18) {
this.getData()
}
}
else if (getQueryString('src') == 4) {
this.modulesFiles = ['10kV_CXX_1_hwg', '10kV_JSX_4_hwg', 'BJ', 'DL', 'JG', '1_UPS', '2_UPS', 'XG', 'YJDY_Car', 'BackGround', 'Human', 'Camera_01', 'Camera_02',
'BS_che', 'BS_hwg1', 'BS_hwg2', 'BS_ups1', 'BS_ups2']
this.modulesFiles.forEach((item, index) => {
var obj = {
cId: 1,
parentName: "车架",
name: '车架',
pos: [0, 0, 0],
size: [1, 1, 1],
rotate: [0, 0, 0],
wirePos: [],
affiliation: [],
type: "车架",
visible: true,
passenger: [],
taskCode: -1,
}
// if(index == 5){
// obj.pos = [45.563,-33.778,165.9623]
// }
obj.cId = index
obj.parentName = item
obj.type = item
obj.name = item
this.modelResource.push(obj)
})
this.modelUrl = 'baoDianHall/BD_export/'
if (this.modulesFiles.length == 18) {
this.getData()
}
}else if (getQueryString('src') == 5) {
this.modulesFiles = ['NSFZ_BDZ', '南师大附中大场景', '南师大附中监控1', '南师大附中监控2']
this.modulesFiles.forEach((item, index) => {
var obj = {
cId: 1,
parentName: "车架",
name: '车架',
pos: [-200, 0, 0],
size: [0.3, 0.3, 0.3],
rotate: [0, 0, 0],
wirePos: [],
affiliation: [],
type: "车架",
visible: true,
passenger: [],
taskCode: -1,
}
// if(index == 5){
// obj.pos = [45.563,-33.778,165.9623]
// }
obj.cId = index
obj.parentName = item
obj.type = item
obj.name = item
this.modelResource.push(obj)
})
this.modelUrl = 'nsfzExport/NSFZ_Model/'
if (this.modulesFiles.length == 4) {
this.getData()
}
}else if (getQueryString('src') == 6) {
this.modulesFiles = ['NSFZ_BDZ']
this.modulesFiles.forEach((item, index) => {
var obj = {
cId: 1,
parentName: "车架",
name: '车架',
pos: [-900, 300, 0],
size: [0.9, 0.9, 0.9],
rotate: [0, 0, 0],
wirePos: [],
affiliation: [],
type: "车架",
visible: true,
passenger: [],
taskCode: -1,
}
// if(index == 5){
// obj.pos = [45.563,-33.778,165.9623]
// }
obj.cId = index
obj.parentName = item
obj.type = item
obj.name = item
this.modelResource.push(obj)
})
this.modelUrl = 'nsfzBDZ/nsfzBDZ_Model/'
if (this.modulesFiles.length == 1) {
this.getData()
}
}else if (getQueryString('src') == 7) {
this.modulesFiles = ['YHZX_BD','YHZX_Build','YHZX_CAM_01','YHZX_CAM_02']
this.modulesFiles.forEach((item, index) => {
var obj = {
cId: 1,
parentName: "车架",
name: '车架',
pos: [0, 0, 0],
size: [0.4, 0.4, 0.4],
rotate: [0, 0, 0],
wirePos: [],
affiliation: [],
type: "车架",
visible: true,
passenger: [],
taskCode: -1,
}
// if(index == 5){
// obj.pos = [45.563,-33.778,165.9623]
// }
obj.cId = index
obj.parentName = item
obj.type = item
obj.name = item
this.modelResource.push(obj)
})
this.modelUrl = 'yhzxExport/yhzxModel/'
if (this.modulesFiles.length == 4) {
this.getData()
}
}else if (getQueryString('src') == 8) {
this.modulesFiles = ['YHZX_BD']
this.modulesFiles.forEach((item, index) => {
var obj = {
cId: 1,
parentName: "车架",
name: '车架',
pos: [0, -300, 0],
size: [1, 1 ,1],
rotate: [0, 0, 0],
wirePos: [],
affiliation: [],
type: "车架",
visible: true,
passenger: [],
taskCode: -1,
}
// if(index == 5){
// obj.pos = [45.563,-33.778,165.9623]
// }
obj.cId = index
obj.parentName = item
obj.type = item
obj.name = item
this.modelResource.push(obj)
})
this.modelUrl = 'yhzxBDZ/yhzxModel/'
if (this.modulesFiles.length == 1) {
this.getData()
}
}else if (getQueryString('src') == 'TZRMT') {
this.modulesFiles = ['TXDS','TXDS_cam_01','TXDS_cam_02','TXDS_cam_03','TXDS_cam_04','TXDS_cam_05','TXDS_cam_06','TXDS_cam_07','TXDS_map']
this.modulesFiles.forEach((item, index) => {
var obj = {
cId: 1,
parentName: "车架",
name: '车架',
pos: [0, 0, 0],
size: [0.5, 0.5 ,0.5],
rotate: [0, 0, 0],
wirePos: [],
affiliation: [],
type: "车架",
visible: true,
passenger: [],
taskCode: -1,
}
obj.cId = index
obj.parentName = item
obj.type = item
obj.name = item
this.modelResource.push(obj)
})
this.modelUrl = 'tzrmtExport/tzrmtModel/'
if (this.modulesFiles.length == 9) {
this.getData()
}
}else if (getQueryString('src') == 'TXDS') {
this.modulesFiles = ['TXDS']
this.modulesFiles.forEach((item, index) => {
var obj = {
cId: 1,
parentName: "车架",
name: '车架',
pos: [-150, 350, 0],
size: [2.5, 2.5 ,2.5],
rotate: [0, 0, 0],
wirePos: [],
affiliation: [],
type: "车架",
visible: true,
passenger: [],
taskCode: -1,
}
obj.cId = index
obj.parentName = item
obj.type = item
obj.name = item
this.modelResource.push(obj)
})
this.modelUrl = 'tzrmtExport/tzrmtModel/'
if (this.modulesFiles.length == 1) {
this.getData()
}
}else if (getQueryString('src') == 'GNZF') {
this.modulesFiles = ['GNPD_cam_01','GNPD_cam_02','GNPD_cam_03','GNPD_cam_04','GNPD_cam_05','GNPD_cam_06','GNPD_cam_07','GNPD_map','GNPD']
this.modulesFiles.forEach((item, index) => {
var obj = {
cId: 1,
parentName: "车架",
name: '车架',
pos: [0, 0, 0],
size: [0.5, 0.5 ,0.5],
rotate: [0, 0, 0],
wirePos: [],
affiliation: [],
type: "车架",
visible: true,
passenger: [],
taskCode: -1,
}
obj.cId = index
obj.parentName = item
obj.type = item
obj.name = item
this.modelResource.push(obj)
})
this.modelUrl = 'gnzfExport/gnzfModel/'
if (this.modulesFiles.length == 9) {
this.getData()
}
}else if (getQueryString('src') == 'GNPD') {
this.modulesFiles = ['GNPD']
this.modulesFiles.forEach((item, index) => {
var obj = {
cId: 1,
parentName: "车架",
name: '车架',
pos: [360, 400, 0],
size: [2.2, 2.2 ,2.2],
rotate: [0, 0, 0],
wirePos: [],
affiliation: [],
type: "车架",
visible: true,
passenger: [],
taskCode: -1,
}
obj.cId = index
obj.parentName = item
obj.type = item
obj.name = item
this.modelResource.push(obj)
})
this.modelUrl = 'gnzfExport/gnzfModel/'
if (this.modulesFiles.length == 1) {
this.getData()
}
}else if (getQueryString('src') == 'WXGD') {
this.modulesFiles = ['GXGD_cam_01','GXGD_cam_02','GXGD_cam_03','GXGD_cam_04','GXGD_cam_05','GXGD_cam_06','GXGD_cam_07','GXGD_cam_08','GXGD_map','GXGD_pd']
this.modulesFiles.forEach((item, index) => {
var obj = {
cId: 1,
parentName: "车架",
name: '车架',
pos: [0, 0, 0],
size: [0.5, 0.5 ,0.5],
rotate: [0, 0, 0],
wirePos: [],
affiliation: [],
type: "车架",
visible: true,
passenger: [],
taskCode: -1,
}
obj.cId = index
obj.parentName = item
obj.type = item
obj.name = item
this.modelResource.push(obj)
})
this.modelUrl = 'wxgdExport/wxgdModel/'
if (this.modulesFiles.length == 10) {
this.getData()
}
}else if (getQueryString('src') =='GXGD_pd') {
this.modulesFiles = ['GXGD_pd']
this.modulesFiles.forEach((item, index) => {
var obj = {
cId: 1,
parentName: "车架",
name: '车架',
pos: [-200, 350, 0],
size: [2.2, 2.2 ,2.2],
rotate: [0, 0, 0],
wirePos: [],
affiliation: [],
type: "车架",
visible: true,
passenger: [],
taskCode: -1,
}
obj.cId = index
obj.parentName = item
obj.type = item
obj.name = item
this.modelResource.push(obj)
})
this.modelUrl = 'wxgdExport/wxgdModel/'
if (this.modulesFiles.length == 1) {
this.getData()
}
}else if (getQueryString('src') =='SQXCHY') {
this.modulesFiles = ['SQLM_cam_01','SQLM_cam_02','SQLM_cam_03','SQLM_cam_04','SQLM_cam_05','SQLM_cam_06','SQLM_map','SQLM_pd']
this.modulesFiles.forEach((item, index) => {
var obj = {
cId: 1,
parentName: "车架",
name: '车架',
pos: [-100, 200, 0],
size: [0.5, 0.5 ,0.5],
rotate: [0, 0, 0],
wirePos: [],
affiliation: [],
type: "车架",
visible: true,
passenger: [],
taskCode: -1,
}
obj.cId = index
obj.parentName = item
obj.type = item
obj.name = item
this.modelResource.push(obj)
})
this.modelUrl = 'sqxchyExport/sqxchyModel/'
if (this.modulesFiles.length == 8) {
this.getData()
}
}else if (getQueryString('src') =='SQLM_pd') {
this.modulesFiles = ['SQLM_pd']
this.modulesFiles.forEach((item, index) => {
var obj = {
cId: 1,
parentName: "车架",
name: '车架',
pos: [-300, 500, 0],
size: [1.2, 1.2 ,1.2],
rotate: [0, 0, 0],
wirePos: [],
affiliation: [],
type: "车架",
visible: true,
passenger: [],
taskCode: -1,
}
obj.cId = index
obj.parentName = item
obj.type = item
obj.name = item
this.modelResource.push(obj)
})
this.modelUrl = 'sqxchyExport/sqxchyModel/'
if (this.modulesFiles.length == 1) {
this.getData()
}
}else if (getQueryString('src') =='XZLDBR1') {
this.modulesFiles = ['XZPD_cam_01','XZPD_cam_02','XZPD_cam_03','XZPD_cam_04','XZPD_cam_05','XZPD_cam_06','XZPD_cam_07','XZPD_map','XZPD']
this.modulesFiles.forEach((item, index) => {
var obj = {
cId: 1,
parentName: "车架",
name: '车架',
pos: [100, -600, 300],
size: [1, 1 ,1],
rotate: [0, 0, 0],
wirePos: [],
affiliation: [],
type: "车架",
visible: true,
passenger: [],
taskCode: -1,
}
obj.cId = index
obj.parentName = item
obj.type = item
obj.name = item
this.modelResource.push(obj)
})
this.modelUrl = 'xzlbrExport/xzlbrModel/'
if (this.modulesFiles.length == 9) {
this.getData()
}
}else if (getQueryString('src') =='XZPD') {
this.modulesFiles = ['XZPD_base']
this.modulesFiles.forEach((item, index) => {
var obj = {
cId: 1,
parentName: "车架",
name: '车架',
pos: [0, 0, 0],
size: [0.03, 0.03 ,0.03],
rotate: [0, 0, 0],
wirePos: [],
affiliation: [],
type: "车架",
visible: true,
passenger: [],
taskCode: -1,
}
obj.cId = index
obj.parentName = item
obj.type = item
obj.name = item
this.modelResource.push(obj)
})
this.modelUrl = 'xzlbrExport/pdModel/'
if (this.modulesFiles.length == 1) {
this.getData()
}
}else if (getQueryString('src') =='NTDST') {
this.modulesFiles = ['NTPD_cam_01','NTPD_cam_02','NTPD_cam_03','NTPD_cam_04','NTPD_cam_05','NTPD_cam_06','NTPD_cam_07','NTPD_map','NTPD']
this.modulesFiles.forEach((item, index) => {
var obj = {
cId: 1,
parentName: "车架",
name: '车架',
pos: [-200, 0, 0],
size: [0.8, 0.8 ,0.8],
rotate: [0, 0, 0],
wirePos: [],
affiliation: [],
type: "车架",
visible: true,
passenger: [],
taskCode: -1,
}
obj.cId = index
obj.parentName = item
obj.type = item
obj.name = item
this.modelResource.push(obj)
})
this.modelUrl = 'ntdstExport/ntdstModel/'
if (this.modulesFiles.length == 9) {
this.getData()
}
}else if (getQueryString('src') =='NTPD') {
this.modulesFiles = ['NTPD']
this.modulesFiles.forEach((item, index) => {
var obj = {
cId: 1,
parentName: "车架",
name: '车架',
pos: [-2500, -2000, 0],
size: [10,10,10],
rotate: [0, 0,0],
wirePos: [],
affiliation: [],
type: "车架",
visible: true,
passenger: [],
taskCode: -1,
}
obj.cId = index
obj.parentName = item
obj.type = item
obj.name = item
this.modelResource.push(obj)
})
this.modelUrl = 'ntdstExport/ntdstModel/'
if (this.modulesFiles.length == 1) {
this.getData()
}
}
},
// 爆炸
nodeAnimation(node, to, axis, duration, completeCallback, followNodes) {
let f = node.p3()[axis];
let t = to;
let dir = f > t ? -1 : 1;
//启动节点动画
node.setAnimation({
move: {
from: node.p3()[axis],
to: to,
easing: "Linear",
duration: duration,
onUpdate: function (value) {
let thisPos = node.p3();
if (dir == -1) {
if (value > to) thisPos[axis] = value;
else thisPos[axis] = to;
} else {
if (value < to) thisPos[axis] = value;
else thisPos[axis] = to;
}
// thisPos[axis] = value;
node.setPosition3d(thisPos);
if (followNodes != undefined) {
for (var idx in followNodes) {
let fpos = followNodes[idx].p3();
fpos[axis] = thisPos[axis];
followNodes[idx].setPosition3d(fpos);
}
}
},
},
start: ["move"],
}); //动画计时结束调用回调
setTimeout(() => {
if (completeCallback != undefined) {
completeCallback();
}
}, duration * 1.1);
},
//获取模型贴图
getData() {
let promiseArr = []
this.modulesFiles.forEach((key) => {
let p1 = new Promise((resolve, reject) => {
axios({
method: "get",
url: this.modelUrl + key + '.obj',
}).then((res) => {
resolve(res);
this.files.push({ name: key, text: res.data, mtltext: '' });
});
});
promiseArr.push(p1)
});
this.modulesFiles.forEach((key) => {
let p2 = new Promise((resolve, reject) => {
axios({
method: "get",
url: this.modelUrl + key + '.mtl',
}).then((res) => {
resolve(res);
this.mtlFiles.push({ name: key, text: res.data });
});
});
promiseArr.push(p2)
});
Promise.all(promiseArr).then((res) => {
this.mtlFiles.forEach(item => {
this.files.map(items => {
if (item.name == items.name) {
items.mtltext = item.text
}
return items
})
})
this.getFakeData(this.files);
});
},
// 从文件获取模型数据依赖renderRealData()
getFakeData(files) {
let reader = [];
for (let i = 0; i < files.length; i++) {
this.realObj.push({
parentName: files[i].name,
objText: files[i].text,
mtltext: files[i].mtltext
});
if (this.realObj.length === files.length) {
// 读取完毕
this.renderRealData();
}
}
},
// 渲染模型依赖renderSingle()
renderRealData() {
// 实体状态看板计时器
let that = this;
this.rawS3 = null;
this.dm = new ht.DataModel(); // 创建数据容器
this.g3d = window.g3d = new ht.graph3d.Graph3dView(this.dm); // 创建3D环境并挂载到window
this.g3d.setGridVisible(false); // 显示网格
// this.g3d.getView().style.background = 'black' ; // 设置3D空间背景颜色
// this.g3d.setGridColor('lightgrey'); // 设置网格颜色
// this.g3d.setGridSize(40); // 设置网格行列数默认为40
// this.g3d.setGridGap(10); // 设置网格线间距
// this.g3d.setFar(10000); // 设置远端截面位置默认值为10000
// this.g3d.setOrthoWidth(5000); // 设置正交投影宽度默认为2000
// this.g3d.setFogNear(100); // 迷雾影响起始距离
// this.g3d.setFogFar(8000); // 迷雾完全遮盖图元的距离
// this.g3d.setFogMode('linear'); // 迷雾过渡效果
this.g3d.setEye([0, 800, 700]); // 镜头位置
this.g3d.setCenter([0, 0, 0]); // 设置中心点
this.g3d.enableToolTip(); // 启用文字提示
this.g3d.addToDOM(); // 将3D环境加载到document.body下
this.g3d.setEditable(false); // 启用编辑
// this.g3d.setZoom(0.8); // 启用编辑
// this.g3d.getView().style.backgroundImage = ''; // import
this.g3d.setMovableFunc(function (data) {
// 可移动性setMovableFunc的参数如果是null则所有图元都可移动参数如果是function则返回true可移动返回false不可移动
// return data.cId <= 4 ? false : true; // 可以通过Node.cId设置可移动的图元
return false;
});
this.g3d.setVisibleFunc(function (data) {
// 设置图元可见性,内部循环
return data.cVisible;
});
//显示仰望视角
this.g3d.setRotateMaxPhi(Math.PI * 5 / 12);
// this.g3d.setZoomable(false);
// 设置背景图片
// this.g3d.showDebugTip(true); // 开启Debug面板
this.g3d.addInteractorListener((e) => {
// 交互回调
// console.log(e.kind,'ssss');
// 交互事件参考:
// beginRotate开始旋转
// betweenRotate旋转过程
// endRotate结束旋转
// beginWalk开始行进
// betweenWalk行进过程
// endWalk结束行进
// beginZoom开始缩放
// betweenZoom缩放过程
// endZoom结束缩放
// beginPan开始平移
// betweenPan平移过程
// endPan结束平移
// beginPinch开始双指缩放
// betweenPinch双指缩放过程
// endPinch结束双指缩放
// toggleNote双击在note上
// toggleNote2双击在note2上
// clickData单击图元
// clickBackground单击背景
// doubleClickData双击图元
// doubleClickBackground双击背景
// beginEditRotation: 开始编辑图元旋转角度
// betweenEditRotation: 正在编辑图元旋转角度
// endEditRotation: 结束编辑图元旋转角度
// beginEditSize: 开始编辑图元大小
// betweenEditSize: 正在编辑图元大小
// endEditSize: 结束编辑图元大小
// beginMove: 开始移动图元
// betweenMove: 正在移动图元
// endMove: 结束移动图元
// beginRectSelect: 开始框选图元
// betweenRectSelect: 正在框选图元
// endRectSelect: 结束框选图元
// beginEditRect
// betweenEditRect
// endEditRect
// beginEditPoint
// betweenEditPoint
// endEditPoint
// moveLeft
// moveRight
// moveUp
// moveDown
// 左键单击实体
if (e.kind === "clickData" && e.event.mousedown0_isDoubleClick) {
// let content = document.querySelectorAll(".feedback-panel p");
this.cId = e.data.cId;
this.cName = e.data.cName;
// 取消阴影
g3d.getBrightness = function (e) {
if (e.s('isFocused')) {
return 0.7;
}
return null;
};
console.log(e.data, ",,,,e.data");
console.log(
`[HT-TEST] NODE:\n- cId: ${e.data.cId
}\n- cParentName(模型文件名): ${e.data.cParentName
}\n- cName(模型名称): ${e.data.cName}\n- cType(模型类别): ${e.data.cType
}\n- p3(位置): [${e.data.p3()}]\n- s3(大小): [${e.data.s3()}]\n- r3(旋转): [${e.data.r3()}]\n- cWirePos(网格坐标): [${e.data.cWirePos
}]\n- cAffiliation(附属设备): [${e.data.cAffiliation
}]\n- cVisible(可见性): ${e.data.cVisible
}\n- cPassenger(所载设备): [${e.data.cPassenger
}]\n- cTaskCode(任务号): ${e.data.cTaskCode}\n- cState(运行状态): ${e.data.cState
}\n- color(颜色): ${e.data.getStyle(
"shape3d.color"
)}\n- anchor(锚点): (${e.data.getAnchor3d().x},${e.data.getAnchor3d().y
},${e.data.getAnchor3d().z})\n- click pos(鼠标点击位置): (${e.event.clientX
},${e.event.clientY})\n- _id: ${e.data._id}\n- _name: ${e.data._name
}`
);
// content[0].innerHTML = `设备名称:${e.data.cName}`;
// content[1].innerHTML = `状态:${e.data.cState}`;
// clearTimeout(timer);
// 后期交互功能……
}
// 双击实体
// if (e.kind === "doubleClickData") {
// this.g3d.flyTo(e.data, {
// animation: true,
// ratio: 0.9, // [0, 1],越大相机越近
// });
// console.log(e.data.cName,'e.data.cName');
// // if (e.data.cName.indexOf('monitor')!= -1) {
// // window.parent.openVideo()
// // }
// }
// 双击实体
if (e.kind === "doubleClickData") {
// this.dataInfo = e.data;
// this.$emit("equipmentInfo", this.dataInfo);
// this.g3d.flyTo(e.data, {
// animation: true,
// ratio: 0.9, // [0, 1],越大相机越近
// })
window.setTimeout(() => {
if (e.data.cName == 'XG') {
let val = 'XG'
window.parent.postMessage({
val
}, '*'); // * 通配符 匹配所有地址; content 表示传递过去嵌套iframe页面的数据
} else if (e.data.cName == 'JG') {
let val = 'JG'
window.parent.postMessage({
val
}, '*');
} else if (e.data.cName == 'Camera_02') {
let val = 'Camera_02'
window.parent.postMessage({
val
}, '*');
} else if (e.data.cName == 'Camera_01') {
let val = 'Camera_01'
window.parent.postMessage({
val
}, '*');
} else if (e.data.cName == 'Human') {
let val = 'Human'
window.parent.postMessage({
val
}, '*');
} else if (e.data.cName == '1_UPS') {
let val = '1_UPS'
window.parent.postMessage({
val
}, '*')
} else if (e.data.cName == '2_UPS') {
let val = '2_UPS'
window.parent.postMessage({
val
}, '*')
} else if (e.data.cName == 'YJDY_Car') {
let val = 'YJDY_Car'
window.parent.postMessage({
val
}, '*')
} else if (e.data.cName == '10kV_CXX_1_hwg') {
let val = '10kV_CXX_1_hwg'
window.parent.postMessage({
val
}, '*')
} else if (e.data.cName == '10kV_JSX_4_hwg') {
let val = '10kV_JSX_4_hwg'
window.parent.postMessage({
val
}, '*')
}else if( e.data.cName == '南师大附中监控2'){
let val = '南师大附中监控2'
window.parent.postMessage({
val
}, '*')
}else if( e.data.cName == '南师大附中监控1'){
let val = '南师大附中监控1'
window.parent.postMessage({
val
}, '*')
}else if( e.data.cName == 'NSFZ_BDZ'){
let val = 'NSFZ_BDZ'
window.parent.postMessage({
val
}, '*')
}else if( e.data.cName == 'YHZX_BD'){
let val = 'YHZX_BD'
window.parent.postMessage({
val
}, '*')
}else if( e.data.cName == 'YHZX_CAM_01'){
let val = 'YHZX_CAM_01'
window.parent.postMessage({
val
}, '*')
}else if( e.data.cName == 'YHZX_CAM_02'){
let val = 'YHZX_CAM_02'
window.parent.postMessage({
val
}, '*')
}else if (e.data.cName == 'TXDS') {
let val = 'TXDS'
window.parent.postMessage({
val
}, '*')
}else if (e.data.cName == 'TXDS_cam_01') {
let val = 'TXDS_cam_01'
window.parent.postMessage({
val
}, '*')
}else if (e.data.cName == 'TXDS_cam_02') {
let val = 'TXDS_cam_02'
window.parent.postMessage({
val
}, '*')
}else if (e.data.cName == 'TXDS_cam_03') {
let val = 'TXDS_cam_03'
window.parent.postMessage({
val
}, '*')
}else if (e.data.cName == 'TXDS_cam_04') {
let val = 'TXDS_cam_04'
window.parent.postMessage({
val
}, '*')
}else if (e.data.cName == 'TXDS_cam_05') {
let val = 'TXDS_cam_05'
window.parent.postMessage({
val
}, '*')
}else if (e.data.cName == 'TXDS_cam_06') {
let val = 'TXDS_cam_06'
window.parent.postMessage({
val
}, '*')
}else if (e.data.cName == 'TXDS_cam_07') {
let val = 'TXDS_cam_07'
window.parent.postMessage({
val
}, '*')
}else if (e.data.cName == 'GNPD_cam_01') {
let val = 'GNPD_cam_01'
window.parent.postMessage({
val
}, '*')
}else if (e.data.cName == 'GNPD_cam_02') {
let val = 'GNPD_cam_02'
window.parent.postMessage({
val
}, '*')
}else if (e.data.cName == 'GNPD_cam_03') {
let val = 'GNPD_cam_03'
window.parent.postMessage({
val
}, '*')
}else if (e.data.cName == 'GNPD_cam_04') {
let val = 'GNPD_cam_04'
window.parent.postMessage({
val
}, '*')
}else if (e.data.cName == 'GNPD_cam_05') {
let val = 'GNPD_cam_05'
window.parent.postMessage({
val
}, '*')
}else if (e.data.cName == 'GNPD_cam_06') {
let val = 'GNPD_cam_06'
window.parent.postMessage({
val
}, '*')
}else if (e.data.cName == 'GNPD_cam_07') {
let val = 'GNPD_cam_07'
window.parent.postMessage({
val
}, '*')
}else if (e.data.cName == 'GNPD') {
let val = 'GNPD'
window.parent.postMessage({
val
}, '*')
}else{
let val = e.data.cName
window.parent.postMessage({
val
}, '*')
}
}, 200)
}
// 开始旋转镜头
// if (e.kind === 'beginRotate') {
// this.g3d.setVisibleFunc(function(data) {
// if (!/货箱/.test(data.cParentName)) {return true}// 设置图元可见性,内部循环
// });
// }
// 结束旋转镜头
// if (e.kind === 'endRotate') {
// this.g3d.setVisibleFunc(function(data) { // 设置图元可见性,内部循环
// return data
// });
// }
});
// 限制缩放比例 zooMax:最大缩放倍数 zoomMin: 最小缩放倍数 zoom 初始化值
var zoomMax = 50;
var zoomMin = -20;
var zoom = 0;
/*监听鼠标滚轮事件,用于限制模型的缩放比例,因为谷歌和火狐的滚轮事件不同,所以
这边同时监听连个事件
*/
//谷歌浏览器的监听事件
document.addEventListener('mousewheel', controllerZoom);
//火狐浏览器的监听事件
document.addEventListener('DOMMouseScroll', controllerZoom);
function controllerZoom(event) {
var wheelDelta = getWheelDelta(event);
if (wheelDelta > 0) {
if (zoom != zoomMax) {
zoom++;
}
} else {
if (zoom != zoomMin) {
zoom--;
}
}
if (zoom > zoomMin && zoom < zoomMax) {
that.g3d.setZoomable(true)
} else {
that.g3d.setZoomable(false)
if (zoom == 30 && (getQueryString('src') == 1 || getQueryString('src') == 2)) {
let val = 'goThree'
window.parent.postMessage({
val
}, '*'); // * 通配符 匹配所有地址; content 表示传递过去嵌套iframe页面的数据
}
}
}
var getWheelDelta = function (event) {
return event.wheelDelta || (-event.detail * 24);
}
// 渲染模型
// 单个导入
this.renderSingle();
// 以组导入
// renderAsGroup(realMtl, realObj);
},
// 单个导入依赖createNode()
renderSingle() {
for (let i = 0; i < this.realObj.length; i++) {
var modelMap = ht.Default.parseObj(
this.realObj[i].objText,
this.realObj[i].mtltext,
{ center: false, cube: true, ignoreImage: false, t3: [0, 0, 0], prefix: getQueryString('src') == 1 ? 'export/' : (getQueryString('src') == 2 ? 'OldHall/' : 'baoDianHall/') }
);
this.modelarray = [];
for (var name in modelMap) {
this.modelarray.push(modelMap[name]);
}
// 注册解析出来的obj
ht.Default.setShape3dModel(this.realObj[i].parentName, this.modelarray);
// 循环创建node
for (let j = 0; j < this.modelResource.length; j++) {
// 只会创建在modelResource中有对应parentName的实体多导入的obj不会被创建
if (this.modelResource[j].parentName === this.realObj[i].parentName) {
this.createNode(this.modelResource[j], this.modelarray);
// if (getQueryString('baoDian') == 1) {
// this.models[2].cVisible = true
// }
}
}
}
var redLight = new ht.Light();
redLight.s({
'light.type': 'directional',
'light.color': 'white',
'light.range': 1500
})
redLight.p3(0, 0, 0);
this.dm.add(redLight);
if (getQueryString('src') == 0 || getQueryString('src') == 1) {
this.models[0].setVisible(false)
this.models[1].setVisible(false)
this.models[2].setVisible(false)
this.models[3].setVisible(false)
this.models[5].setColor('yelow')
this.models[6].setColor('yelow')
this.models[7].setColor('yelow')
if (this.models[4].cName == 'oldMemorial') {
this.models[4].setToolTip('名称:旧馆');
} else {
this.models[4].setToolTip('名称:新馆');
}
this.models[5].setToolTip('名称监控1');
this.models[6].setToolTip('名称监控2');
this.models[7].setToolTip('名称监控3');
} else if (getQueryString('src') == 3) {
this.models[3].cVisible = false
// this.createNewIcon()
// this.createOldIcon()
}
this.dm.enableAnimation();
},
createNewIcon() {
let host = this.models[5].s({
'label': 'Cube',
'label.visible': true,
'front.uv': [0.25, 0.75, 0.25, 1, 0.5, 1, 0.5, 0.75],
'back.uv': [0.25, 0.25, 0.25, 0.5, 0.5, 0.5, 0.5, 0.25],
'bottom.uv': [0.25, 0, 0.25, 0.25, 0.5, 0.25, 0.5, 0],
'left.uv': [0, 0.75, 0, 1, 0.25, 1, 0.25, 0.75],
'right.uv': [0.5, 0.75, 0.5, 1, 0.75, 1, 0.75, 0.75],
'front.opacity': 0.5,
'front.transparent': true,
'front.blend': 'red',
'top.visible': false,
'all.reverse.flip': true,
'note': '新馆',
'note.face': 'top',
'note.autorotate': true,
'note.position': 6,
});
},
createOldIcon() {
let host = this.models[3].s({
'label': 'Cube',
'label.visible': false,
'label.background': 'red',
'all.image': 'dice',
'front.uv': [0.25, 0.75, 0.25, 1, 0.5, 1, 0.5, 0.75],
'back.uv': [0.25, 0.25, 0.25, 0.5, 0.5, 0.5, 0.5, 0.25],
'bottom.uv': [0.25, 0, 0.25, 0.25, 0.5, 0.25, 0.5, 0],
'left.uv': [0, 0.75, 0, 1, 0.25, 1, 0.25, 0.75],
'right.uv': [0.5, 0.75, 0.5, 1, 0.75, 1, 0.75, 0.75],
'front.opacity': 0.5,
'front.transparent': true,
'front.blend': 'red',
'top.visible': false,
'all.reverse.flip': true,
'note': '旧馆',
'note.face': 'top',
'note.autorotate': true,
'note.position': 8,
});
},
createNode(single, array, host) {
if (this.models[single.cId] != undefined) {
return;
}
var node = new ht.Node();
node.cId = single.cId; // 挂载modelResource中的cId属性
node.cParentName = single.parentName; // 挂载modelResource中的parentName属性
node.cName = single.name; // 挂载modelResource中的name属性
node.cType = single.type; // 挂载modelResource中的type属性
node.cWirePos = single.wirePos; // 挂载modelResource中的wirePos属性
node.cAffiliation = single.affiliation; // 挂载modelResource中的affiliation属性
node.cVisible = single.visible; // 挂载modelResource中的visible属性
node.cPassenger = single.passenger; // 挂载modelResource中的passenger属性
node.cTaskCode = single.taskCode; // 挂载modelResource中的taskCode属性
node.cState = "正常"; // 挂载modelResource中的state属性待确认
node.cApp = this;
node.setHost(host);
// 在这里挂载更多属性所有挂载的属性建议以c开头便于区分
node.remove = function () {
this.cApp.dm.remove(this);
};
node.setVisible = function (v) {
this.s("3d.visible", v);
this.cVisible = v;
};
node.setColor = function (v) {
this.s("shape3d.color", v);
};
node.s({
shape3d: single.parentName, // 模型类别与obj文件一一对应1
// 'wf.visible': 'selected', // 线框是否可见
// 'wf.color': 'red', // 线框颜色
// "shape3d.color":'orange', // 模型着色
"shape3d.transparent": false, // 模型是否透明
"shape3d.opacity": 1, // 模型透明度
// "wf.geometry": false, // 是否显示几何体的线条
// "wf.loadQuadWireframe": true, // 是否载入四边面的线框
// "wf.combineTriangle": true, // 线框模型是否合并三角
// "all.transparent": true,
// 'all.color': 'red',
'all.image': '',
// 'note': 'One Node',
// 'note.color': 'black',
// 'note.background': 'lightblue',
// 'note.face': 'center',
// 'note.position': 7,
// 'note.autorotate': 'y',
});
// node.p3(0,20,0);
// 模型允许的条件下开启线框模式?(需要模型细节,但无法满足加载时间需求)
// node.s({
// 'shape3d.transparent': true,
// 'shape3d.opacity': 0,
// 'wf.geometry': true,
// 'wf.combineTriangle': 0, // 0 - 不合并三角形1 - 合并相邻三角为四边面原来的效果2 - 融合所有联通的共面三角面3 - 根据法线信息融合所有平滑三角面
// 'wf.color': 'rgba(96, 172, 252, .3)'
// })
// 设置尺寸
// node.s3(array[0].rawS3); // rawS3格式[x, y, z]设置cube参数后大小归1这里用rawS3*1得到原始尺寸
// console.log(array[1],'aaaabbbb');
node.s3(
array[0].rawS3[0] * single.size[0],
array[0].rawS3[1] * single.size[1],
array[0].rawS3[2] * single.size[2]
);
node.p3(single.pos[0], single.pos[1], single.pos[2]);
node.r3(single.rotate[0], 150, single.rotate[2]); // 旋转
// node.posy = single.pos[1];
node.setAnchor3d(
[0.5, 0.5, 0.5]
); // 设置实体的中心点,默认为[0.5, 0.5, 0.5],表示实体正中心
// node.setStyle('shape3d.color', node.cParentColor); // 填色body.color为混入颜色shape3d.color为设置颜色
// node.setStyle('shape3d.color', this.getColorByParent(node));
// node.setScale3d(17, 17, 17); // 模型放大100倍(x, y, z)
this.dm.add(node); // 把node加载到数据容器
this.models[node.cId] = node;
},
}
})
</script>