You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
491 lines
12 KiB
491 lines
12 KiB
<!DOCTYPE html>
|
|
<html lang="en">
|
|
|
|
<head>
|
|
<title></title>
|
|
<meta charset="utf-8">
|
|
<meta name="generator" content="Three.js Editor">
|
|
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
|
|
<style>
|
|
body {
|
|
font-family: sans-serif;
|
|
font-size: 11px;
|
|
background-color: #000;
|
|
margin: 0px;
|
|
}
|
|
|
|
canvas {
|
|
display: block;
|
|
}
|
|
|
|
.info {
|
|
position: absolute;
|
|
top: 10px;
|
|
width: 100%;
|
|
text-align: center;
|
|
z-index: 100;
|
|
display: block;
|
|
color: brown;
|
|
font-size: 40px;
|
|
}
|
|
|
|
.label {
|
|
color: #ff000f;
|
|
font-family: sans-serif;
|
|
padding: 2px;
|
|
/* background: rgba(0, 0, 0, .6); */
|
|
}
|
|
|
|
.label1 {
|
|
color: #ffffff;
|
|
font-family: sans-serif;
|
|
padding: 2px;
|
|
background: rgba(0, 0, 0, .6);
|
|
}
|
|
|
|
.container {
|
|
width: 100%;
|
|
height: 100%;
|
|
}
|
|
|
|
</style>
|
|
<script type="importmap">
|
|
{
|
|
"imports": {
|
|
"three": "./libs/three/three.module.js",
|
|
"jsm/": "./libs/three/jsm/"
|
|
}
|
|
}
|
|
</script>
|
|
<script async src="./libs/layui/layui.js"></script>
|
|
<script async src="./libs/mqtt/mqtt.min.js"></script>
|
|
</head>
|
|
|
|
<body ontouchstart="">
|
|
<div class="info">2D数据表格显示 不旋转 厌氧系统 <button onclick="btnclick()">全开</button></div>
|
|
|
|
|
|
<script type="module">
|
|
|
|
import * as THREE from 'three';
|
|
import { APP } from './js/app.js';
|
|
|
|
|
|
import { OrbitControls } from 'jsm/controls/OrbitControls.js';
|
|
import { GLTFLoader } from 'jsm/loaders/GLTFLoader.js';
|
|
|
|
import { CSS3DRenderer, CSS3DObject } from 'jsm/renderers/CSS3DRenderer.js';
|
|
import { Water } from 'jsm/objects/Water.js';
|
|
import modellabel from './js/units/modellabel.js'
|
|
import css2dlabel from './js/units/css3dlabel.js'
|
|
|
|
import config from './js/config.js'
|
|
|
|
|
|
window.THREE = THREE; // Used by APP Scripts.
|
|
var client = null;
|
|
|
|
|
|
var player = new APP.Player();
|
|
//水泵列表
|
|
var pumpModelArr = []
|
|
var bigLabelArr = []
|
|
|
|
//红色标签
|
|
const labArr = [{ name: "水泵M_1", text: "水泵1" }, { name: "水泵M_2", text: "水泵002" }
|
|
, { name: "水泵M_3", text: "水泵003" }, { name: "水泵M_4", text: "水泵4" }, { name: "水泵M_5", text: "水泵5" }
|
|
, { name: "OilTank001", text: "PT桶1" }, { name: "OilTank002", text: "PT桶2" }, { name: "OilTank003", text: "PT桶3" },
|
|
|
|
]
|
|
//模型标签
|
|
const remarkLabArr = [{ name: "221", text: "USAB进水", x: 2.0501311208405713, y: -0.7778027560129786, z: -5.4, ry: 360 }
|
|
, { name: "211", text: "USAB进水", x: 0.1740166304621844, y: -0.7760432883855322, z: -5.4, ry: 360 },
|
|
{ name: "491", text: "至污泥浓缩池", x: -2.105188770141037, y: -0.7901334936138524, z: -5.4, ry: 360 }]
|
|
//大标签
|
|
const bigLabArr = [{ name: "建筑_11", text: "建筑_1", x: 0.10, y: 0.16, z: -1.48, rx: 0, ry: 360, rz: 0 }]
|
|
init();
|
|
function init() {
|
|
|
|
player.play();
|
|
player.setSize(window.innerWidth, window.innerHeight);
|
|
window.addEventListener('resize', function () {
|
|
|
|
player.setSize(window.innerWidth, window.innerHeight);
|
|
|
|
});
|
|
|
|
|
|
initModel()
|
|
|
|
addRemarkLabels();
|
|
mqttInit();
|
|
for (var i = 0; i < 1; i++) {
|
|
player.create3dPage(
|
|
1020, 680,
|
|
new THREE.Vector3(-2 - i, 1 + i / 3, -4.2 + i),
|
|
new THREE.Vector3(0, Math.PI, 0),
|
|
'https://zuoben.blog.csdn.net/');
|
|
}
|
|
}
|
|
|
|
// document.body.appendChild(player.dom);
|
|
|
|
|
|
function initModel() {
|
|
var loader = new GLTFLoader();
|
|
loader.load('assets/models/uasb.glb', function (gltf) {
|
|
// gltf.scene.traverse(function (child) {
|
|
// switch (child.name) {
|
|
// case 'walls':
|
|
// initWalls(child)
|
|
// break
|
|
// case 'stairs':
|
|
// initStairs(child)
|
|
// break
|
|
// }
|
|
|
|
// //设置展画边框贴图
|
|
// if (child.name.includes('paint')) {
|
|
// initFrames(child)
|
|
// }
|
|
// //设置展画图片贴图
|
|
// if (child.name.includes('draw')) {
|
|
// initDraws(child)
|
|
// }
|
|
// })
|
|
let tmpmodel= gltf.scene;
|
|
tmpmodel.rotation.set(-0.2,2,0.3)
|
|
|
|
player.addModels(tmpmodel);
|
|
setModel(window.scene, player);
|
|
|
|
});
|
|
}
|
|
|
|
|
|
//添加这个就可以用鼠标拖动
|
|
|
|
var raycaster = new THREE.Raycaster()
|
|
var mouse = new THREE.Vector2()
|
|
//点击模型
|
|
// window.addEventListener('click', onMouseClick);
|
|
window.addEventListener('dblclick', onDBMouseClick);
|
|
// function onMouseClick(event) {
|
|
|
|
// //将鼠标点击位置的屏幕坐标转换成threejs中的标准坐标
|
|
// mouse.x = (event.clientX / window.innerWidth) * 2 - 1
|
|
// mouse.y = -((event.clientY / window.innerHeight) * 2 - 1)
|
|
// //console.log("mouse:"+mouse.x+","+mouse.y)
|
|
|
|
// // 通过鼠标点的位置和当前相机的矩阵计算出raycaster
|
|
// raycaster.setFromCamera(mouse, window.camera);
|
|
|
|
// // 获取raycaster直线和所有模型相交的数组集合
|
|
// var intersects = raycaster.intersectObjects(scene.children);
|
|
// console.log(intersects);
|
|
// //debugger
|
|
// //将所有的相交的模型的颜色设置为红色
|
|
// for (var i = 0; i < intersects.length; i++) {
|
|
// let obj = intersects[i];
|
|
// if (obj.object) {
|
|
|
|
// // if (obj.object.name == "视频监控1") {
|
|
|
|
// // obj.object.material.color.set(0xff6666);
|
|
// // alert("视频");
|
|
// // } else {
|
|
// // obj.object.material.color.set(0xff0000);
|
|
// // }
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
|
|
|
|
function onDBMouseClick(event) {
|
|
|
|
//将鼠标点击位置的屏幕坐标转换成threejs中的标准坐标
|
|
mouse.x = (event.clientX / window.innerWidth) * 2 - 1
|
|
mouse.y = -((event.clientY / window.innerHeight) * 2 - 1)
|
|
//console.log("mouse:"+mouse.x+","+mouse.y)
|
|
|
|
// 通过鼠标点的位置和当前相机的矩阵计算出raycaster
|
|
raycaster.setFromCamera(mouse, window.camera);
|
|
|
|
// 获取raycaster直线和所有模型相交的数组集合
|
|
var intersects = raycaster.intersectObjects(scene.children);
|
|
console.log(intersects);
|
|
|
|
//debugger
|
|
//将所有的相交的模型的颜色设置为红色
|
|
for (var i = 0; i < intersects.length; i++) {
|
|
let obj = intersects[i];
|
|
if (obj.object) {
|
|
let tmpobj = obj.object;
|
|
console.log(tmpobj)
|
|
//输出 增加标签 位置
|
|
console.log('{name:"' + tmpobj.name + '1",text:"' + tmpobj.name + '",x:' + obj.point.x.toFixed(2) + ',y:' + obj.point.y.toFixed(2) + ',z:' + obj.point.z.toFixed(2) + ',rx:0,ry:0,rz:0}');
|
|
if (tmpobj.name.indexOf('水泵M_') > -1) { // 水泵
|
|
|
|
openDialog(tmpobj)
|
|
//alert(tmpobj.name, "双击");
|
|
}
|
|
break;
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 设置标签
|
|
function setModel(scene, player) {
|
|
|
|
|
|
scene.castShadow = true; // 开启阴影
|
|
scene.receiveShadow = true; // 接受阴影
|
|
scene.children.forEach((item, index) => {
|
|
|
|
|
|
// console.log("--------item ==", index);
|
|
// console.log("name=", item.name)
|
|
// console.log("type=", item.type)
|
|
if (item.name.indexOf('OilTank00') > -1) {
|
|
addLabel(item, 0, 0.4, 0)
|
|
}
|
|
else if (item.name.indexOf('水泵M_') > -1) { // 水泵
|
|
pumpModelArr.push(item);
|
|
//debugger
|
|
if (item.name === '水泵001') {
|
|
item.material.color.set(0xff0000);
|
|
} else {
|
|
item.material.color.set(0x006600);
|
|
|
|
}
|
|
addStateLabel(item, 0, 3, 0)
|
|
|
|
|
|
}
|
|
|
|
if (item.type === 'Object3D' || item.type === 'Group') { // 有下一级
|
|
|
|
setModel(item, player);
|
|
}
|
|
|
|
|
|
})
|
|
console.log('pumpModelArr=', pumpModelArr)
|
|
}
|
|
|
|
|
|
//添加 模型标签
|
|
function addRemarkLabels() {
|
|
remarkLabArr.forEach((item, index) => {
|
|
|
|
let labelMesh = modellabel.createRemarkLabel(item.text, item.x, item.y, item.z);
|
|
labelMesh.scale.set(0.005, 0.005, 0.005);
|
|
labelMesh.rotation.y = Math.PI * (item.ry / 360);
|
|
labelMesh.rotation.x = Math.PI * (30 / 360);;
|
|
// labelMesh.rotation.x= rz;
|
|
window.scene.add(labelMesh);
|
|
|
|
})
|
|
bigLabArr.forEach((item, index) => {
|
|
|
|
let labelMesh = modellabel.createRemarkLabel(item.text, item.x, item.y, item.z);
|
|
labelMesh.scale.set(0.01, 0.01, 0.01);
|
|
labelMesh.rotation.y = Math.PI * (item.ry / 360);
|
|
// labelMesh.rotation.x = Math.PI * (30 / 360);;
|
|
// labelMesh.rotation.x= rz;
|
|
window.scene.add(labelMesh);
|
|
bigLabelArr.push(labelMesh);
|
|
|
|
})
|
|
}
|
|
|
|
|
|
|
|
//通过 模型名称获取标签名称
|
|
async function getlabel(name) {
|
|
let result;
|
|
labArr.forEach((item, index) => {
|
|
if (item.name === name) {
|
|
result = item;
|
|
return null;
|
|
}
|
|
})
|
|
return result
|
|
}
|
|
//普通标签
|
|
async function addLabel(parent, x = 0, y = 0, z = 0, className = 'label') {
|
|
|
|
if (!parent.name) {
|
|
|
|
return;
|
|
}
|
|
console.log("parent.name2=", parent.name)
|
|
let item = await getlabel(parent.name);
|
|
// debugger
|
|
if (item) {
|
|
let css2DLabel = css2dlabel.createCSSLabel(item.text, x, y, z, className);
|
|
if (parent) {
|
|
parent.add(css2DLabel);
|
|
|
|
} else {
|
|
window.scene.add(css2DLabel);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//状态标签
|
|
async function addStateLabel(parent, x = 0, y = 0, z = 0, className = 'label') {
|
|
|
|
if (!parent.name) {
|
|
|
|
return;
|
|
}
|
|
console.log("parent.name2=", parent.name)
|
|
let item = await getlabel(parent.name);
|
|
if (item) {
|
|
let css2DLabel = css2dlabel.createCSSLabel('●' + item.text, x, y, z, className);
|
|
if (parent) {
|
|
parent.add(css2DLabel);
|
|
|
|
} else {
|
|
window.scene.add(css2DLabel);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
}
|
|
//添加动态水
|
|
function AddWaters(player) {
|
|
let water1 = {}
|
|
water1.position = { x: 0, y: 1, z: 0 }
|
|
water1.scale = { x: 4, y: 2.6 }
|
|
AddWater(water1, player)
|
|
let water2 = {}
|
|
water2.position = { x: 0, y: 1, z: 5 }
|
|
water2.scale = { x: 7.5, y: 8 }
|
|
AddWater(water2, player)
|
|
}
|
|
function AddWater(water, player) {
|
|
|
|
const waterGeometry = new THREE.PlaneGeometry(water.scale.x, water.scale.y);
|
|
|
|
let waterobj = new Water(
|
|
waterGeometry,
|
|
{
|
|
textureWidth: 255,
|
|
textureHeight: 255,
|
|
waterNormals: new THREE.TextureLoader().load('./img/waternormals.jpg', function (texture) {
|
|
|
|
texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
|
|
|
|
}),
|
|
sunDirection: new THREE.Vector3(),
|
|
sunColor: 0xffffff,
|
|
waterColor: 0x3498DB,
|
|
distortionScale: 0.5,//波浪大小
|
|
fog: true// scene.fog !== undefined
|
|
}
|
|
);
|
|
waterobj.position.set(water.position.x, water.position.y, water.position.z)
|
|
waterobj.rotation.x = - Math.PI / 2;
|
|
|
|
scene.add(waterobj);
|
|
player.addWater(waterobj);
|
|
|
|
}
|
|
//测试用
|
|
let clickindex = false;
|
|
//全开全关 测试
|
|
window.btnclick = function () {
|
|
|
|
pumpModelArr.forEach((item, index) => {
|
|
if (clickindex) {
|
|
item.material.color.set(0x00ff00);
|
|
|
|
} else {
|
|
item.material.color.set(0x666666);
|
|
|
|
}
|
|
clickindex = !clickindex;
|
|
|
|
})
|
|
}
|
|
|
|
function mqttInit() {
|
|
var that = this;
|
|
// 连接选项
|
|
//
|
|
const options = {
|
|
connectTimeout: 4000, // 超时时间
|
|
// 认证信息
|
|
clientId: 'brower_' + parseInt(Math.random() / 31.1 * 10000000000),
|
|
username: config.mqttUserName,
|
|
password: config.mqttPassword,
|
|
}
|
|
client = mqtt.connect('ws://127.0.0.1:8083/mqtt', options);
|
|
client.on('reconnect', function (error) {
|
|
console.log("reconnect");
|
|
})
|
|
client.on('error', function (error) {
|
|
console.log('连接失败:', error)
|
|
})
|
|
client.on('message', function (topic, message, s) {
|
|
console.log(topic, message.toString());
|
|
if (message.toString() == '1') {
|
|
// if (that.lastTime + 2 * 1000 < new Date().getTime()) {
|
|
// that.lastTime = new Date().getTime();
|
|
|
|
// }
|
|
}
|
|
})
|
|
client.subscribe("/scene/update/*");
|
|
client.subscribe("scene");
|
|
client.publish('/sys/update/scene', 'scene');
|
|
client.subscribe("RTData", (err) => {
|
|
if (!err) {
|
|
console.log(`订阅 RTData 成功`);
|
|
}
|
|
});
|
|
}
|
|
//打开对话框
|
|
function openDialog(tmpobj) {
|
|
layer.open({
|
|
type: 1
|
|
, offset: type //具体配置参考:http://doc/modules/layer.html#offset
|
|
, id: 'layerDemo' + type //防止重复弹出
|
|
, content: '<div style="padding: 20px 100px;">' + tmpobj.name + '</div>'
|
|
, btn: '关闭'
|
|
, btnAlign: 'c' //按钮居中
|
|
, shade: 0 //不显示遮罩
|
|
, yes: function () {
|
|
layer.closeAll();
|
|
}
|
|
});
|
|
}
|
|
|
|
function updateLabel(label) {
|
|
|
|
|
|
}
|
|
</script>
|
|
|
|
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|