@ -0,0 +1,114 @@ |
|||
|
|||
|
|||
document.write("<script language='javascript' src='/Content/sweetalert/dist/sweetalert.min.js'></script>"); |
|||
|
|||
|
|||
function alertEx(message) { |
|||
swal( |
|||
message); |
|||
} |
|||
|
|||
function alertTitle(title,message) { |
|||
swal(title, message); |
|||
} |
|||
|
|||
|
|||
function alertSuccess(message) { |
|||
swal( message, '',"success"); |
|||
} |
|||
function alertSuccessCallBack(message, callbackfuntion) { |
|||
swal({ |
|||
title: message, |
|||
text: '', |
|||
type: "success", |
|||
confirmButtonColor: "#DD6B55", |
|||
confirmButtonText: "确定", |
|||
closeOnConfirm: false |
|||
}, |
|||
function () { |
|||
callbackfuntion(); |
|||
}); |
|||
|
|||
} |
|||
function alertSuccessCallBack2(title1,message, callbackfuntion) { |
|||
swal({ |
|||
title: title1, |
|||
text: message, |
|||
type: "success", |
|||
confirmButtonColor: "#DD6B55", |
|||
confirmButtonText: "确定", |
|||
closeOnConfirm: false |
|||
}, |
|||
function () { |
|||
callbackfuntion(); |
|||
}); |
|||
|
|||
} |
|||
|
|||
|
|||
function alertError( message) { |
|||
swal(message, '', "error"); |
|||
} |
|||
|
|||
function alertWarning(_title,message) { |
|||
|
|||
swal({ |
|||
title: _title, |
|||
text: message, |
|||
type: "warning", |
|||
showCancelButton: false, |
|||
confirmButtonColor: "#DD6B55", |
|||
confirmButtonText: "确定", |
|||
closeOnConfirm: false |
|||
} ); |
|||
} |
|||
|
|||
|
|||
function alertWarningCallBack(message,dtovalue,callbackfuntion) { |
|||
|
|||
swal({ |
|||
title: message, |
|||
text: "", |
|||
type: "warning", |
|||
showCancelButton: false, |
|||
confirmButtonColor: "#DD6B55", |
|||
confirmButtonText: "确定", |
|||
closeOnConfirm: true |
|||
}, |
|||
function () { |
|||
callbackfuntion(dtovalue); |
|||
}); |
|||
} |
|||
|
|||
|
|||
function confirmEx(title, message, callbackfuntion) { |
|||
swal({ |
|||
title: title, |
|||
text: message, |
|||
type: "warning", |
|||
showCancelButton: true, |
|||
confirmButtonColor: "#DD6B55", |
|||
confirmButtonText: "确定", |
|||
closeOnConfirm: true |
|||
}, |
|||
function () { |
|||
callbackfuntion(); |
|||
}); |
|||
} |
|||
|
|||
function alertAutoClose(message) { |
|||
swal({ |
|||
title: message, |
|||
text: "2秒钟后自动关闭", |
|||
timer: 2000, |
|||
showConfirmButton: false |
|||
}); |
|||
} |
|||
function alertAutoClose3(message) { |
|||
swal({ |
|||
title: message, |
|||
text: "3秒钟后自动关闭", |
|||
timer: 3000, |
|||
showConfirmButton: false |
|||
}); |
|||
} |
@ -0,0 +1 @@ |
|||
html #layuicss-skincodecss{display:none;position:absolute;width:1989px}.layui-code-h3,.layui-code-view{position:relative;font-size:12px}.layui-code-view{display:block;margin:10px 0;padding:0;border:1px solid #eee;border-left-width:6px;background-color:#FAFAFA;color:#333;font-family:Courier New}.layui-code-h3{padding:0 10px;height:40px;line-height:40px;border-bottom:1px solid #eee}.layui-code-h3 a{position:absolute;right:10px;top:0;color:#999}.layui-code-view .layui-code-ol{position:relative;overflow:auto}.layui-code-view .layui-code-ol li{position:relative;margin-left:45px;line-height:20px;padding:0 10px;border-left:1px solid #e2e2e2;list-style-type:decimal-leading-zero;*list-style-type:decimal;background-color:#fff}.layui-code-view .layui-code-ol li:first-child{padding-top:10px}.layui-code-view .layui-code-ol li:last-child{padding-bottom:10px}.layui-code-view pre{margin:0}.layui-code-notepad{border:1px solid #0C0C0C;border-left-color:#3F3F3F;background-color:#0C0C0C;color:#C2BE9E}.layui-code-notepad .layui-code-h3{border-bottom:none}.layui-code-notepad .layui-code-ol li{background-color:#3F3F3F;border-left:none}.layui-code-demo .layui-code{visibility:visible!important;margin:-15px;border-top:none;border-right:none;border-bottom:none}.layui-code-demo .layui-tab-content{padding:15px;border-top:none} |
After Width: | Height: | Size: 5.8 KiB |
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 5.7 KiB |
After Width: | Height: | Size: 701 B |
After Width: | Height: | Size: 1.7 KiB |
After Width: | Height: | Size: 299 KiB |
After Width: | Height: | Size: 174 KiB |
After Width: | Height: | Size: 243 KiB |
@ -0,0 +1,204 @@ |
|||
<!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: rgb(23, 14, 111); |
|||
margin: 0px; |
|||
} |
|||
|
|||
canvas { |
|||
display: block; |
|||
} |
|||
|
|||
.label { |
|||
color: #FFF; |
|||
font-family: sans-serif; |
|||
padding: 2px; |
|||
background: rgba(255, 0, 0, .6); |
|||
} |
|||
|
|||
.table { |
|||
color: #FFF; |
|||
font-family: sans-serif; |
|||
padding: 2px; |
|||
display: block; |
|||
position: absolute; |
|||
left: 100px; |
|||
top: 150px; |
|||
} |
|||
|
|||
</style> |
|||
<script type="importmap"> |
|||
{ |
|||
"imports": { |
|||
"three": "../build/three.module.js", |
|||
"jsm/": "../examples/jsm/" |
|||
} |
|||
} |
|||
</script> |
|||
</head> |
|||
|
|||
<body ontouchstart=""> |
|||
<div class="table">2d 数据显示位置</div> |
|||
<script type="module"> |
|||
|
|||
import * as THREE from 'three'; |
|||
import { APP } from './js/app.js'; |
|||
import { VRButton } from './js/VRButton.js'; |
|||
|
|||
import { OrbitControls } from 'jsm/controls/OrbitControls.js'; |
|||
import { CSS2DRenderer, CSS2DObject } from '/examples/jsm/renderers/CSS2DRenderer.js'; |
|||
|
|||
|
|||
window.THREE = THREE; // Used by APP Scripts. |
|||
window.VRButton = VRButton; // Used by APP Scripts. |
|||
|
|||
var loader = new THREE.FileLoader(); |
|||
loader.load('app.json', function (text) { |
|||
|
|||
var player = new APP.Player(); |
|||
player.load(JSON.parse(text)); |
|||
player.setSize(window.innerWidth, window.innerHeight); |
|||
player.play(); |
|||
|
|||
document.body.appendChild(player.dom); |
|||
|
|||
window.addEventListener('resize', function () { |
|||
|
|||
player.setSize(window.innerWidth, window.innerHeight); |
|||
|
|||
}); |
|||
var orbitControls = new OrbitControls(window.camera, player.dom); |
|||
initLable(); |
|||
|
|||
}); |
|||
|
|||
//添加这个就可以用鼠标拖动 |
|||
|
|||
var raycaster = new THREE.Raycaster() |
|||
var mouse = new THREE.Vector2() |
|||
//点击模型 |
|||
window.addEventListener('click', onMouseClick); |
|||
|
|||
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[0].color.set(0xff6666); |
|||
alert("视频"); |
|||
} else { |
|||
obj.object.material[0].color.set(0xff0000); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
function createCSSLabel(text, parent) { |
|||
|
|||
const labelDiv = document.createElement('div'); |
|||
labelDiv.className = 'label'; |
|||
labelDiv.name = "csslabeldiv" |
|||
labelDiv.textContent = text; |
|||
|
|||
labelDiv.style.pointerEvents = 'none';//避免HTML标签遮挡三维场景的鼠标事件 |
|||
const moonLabel = new CSS2DObject(labelDiv); |
|||
moonLabel.position.set(1, 2, 0); |
|||
moonLabel.name = "datalabel" |
|||
moonLabel.userData = { name: "datalable", id: "", url: "" } |
|||
return moonLabel; |
|||
|
|||
} |
|||
const css2DLabelList = [] |
|||
function addLabel(obj, scene, i) { |
|||
|
|||
const labelDiv = document.createElement('div'); |
|||
labelDiv.className = 'label'; |
|||
labelDiv.name = "label" + i; |
|||
labelDiv.textContent = obj.text; |
|||
|
|||
|
|||
labelDiv.style.pointerEvents = 'none';//避免HTML标签遮挡三维场景的鼠标事件 |
|||
const css2DLabel = new CSS2DObject(labelDiv); |
|||
css2DLabel.position.set(obj.x, obj.y, obj.z); |
|||
css2DLabel.name = "datalabel" + i; |
|||
css2DLabel.userData = { name: "datalable", id: "", url: "" } |
|||
// css2DLabelList.add(css2DLabel); |
|||
scene.add(css2DLabel); |
|||
|
|||
} |
|||
function initLable() { |
|||
const labobjarr = [{ text: "测试标签1", x: -1, y: 1, z: 1 }, { text: "测试标签2", x: 10, y: 10, z: 10 }] |
|||
for (var i = 0, length = labobjarr.length; i < length; i++) { |
|||
|
|||
addLabel(labobjarr[i], window.scene, i); |
|||
|
|||
} |
|||
} |
|||
|
|||
</script> |
|||
<!-- Code injected by live-server --> |
|||
<script> |
|||
// <![CDATA[ <-- For SVG support |
|||
if ('WebSocket' in window) { |
|||
(function () { |
|||
function refreshCSS() { |
|||
var sheets = [].slice.call(document.getElementsByTagName("link")); |
|||
var head = document.getElementsByTagName("head")[0]; |
|||
for (var i = 0; i < sheets.length; ++i) { |
|||
var elem = sheets[i]; |
|||
var parent = elem.parentElement || head; |
|||
parent.removeChild(elem); |
|||
var rel = elem.rel; |
|||
if (elem.href && typeof rel != "string" || rel.length == 0 || rel.toLowerCase() == "stylesheet") { |
|||
var url = elem.href.replace(/(&|\?)_cacheOverride=\d+/, ''); |
|||
elem.href = url + (url.indexOf('?') >= 0 ? '&' : '?') + '_cacheOverride=' + (new Date().valueOf()); |
|||
} |
|||
parent.appendChild(elem); |
|||
} |
|||
} |
|||
var protocol = window.location.protocol === 'http:' ? 'ws://' : 'wss://'; |
|||
var address = protocol + window.location.host + window.location.pathname + '/ws'; |
|||
var socket = new WebSocket(address); |
|||
socket.onmessage = function (msg) { |
|||
if (msg.data == 'reload') window.location.reload(); |
|||
else if (msg.data == 'refreshcss') refreshCSS(); |
|||
}; |
|||
if (sessionStorage && !sessionStorage.getItem('IsThisFirstTime_Log_From_LiveServer')) { |
|||
console.log('Live reload enabled.'); |
|||
sessionStorage.setItem('IsThisFirstTime_Log_From_LiveServer', true); |
|||
} |
|||
})(); |
|||
} |
|||
else { |
|||
console.error('Upgrade your browser. This Browser is NOT supported WebSocket for Live-Reloading.'); |
|||
} |
|||
// ]]> |
|||
</script> |
|||
</body> |
|||
|
|||
</html> |
@ -0,0 +1,114 @@ |
|||
|
|||
|
|||
document.write("<script language='javascript' src='/Content/sweetalert/dist/sweetalert.min.js'></script>"); |
|||
|
|||
|
|||
function alertEx(message) { |
|||
swal( |
|||
message); |
|||
} |
|||
|
|||
function alertTitle(title,message) { |
|||
swal(title, message); |
|||
} |
|||
|
|||
|
|||
function alertSuccess(message) { |
|||
swal( message, '',"success"); |
|||
} |
|||
function alertSuccessCallBack(message, callbackfuntion) { |
|||
swal({ |
|||
title: message, |
|||
text: '', |
|||
type: "success", |
|||
confirmButtonColor: "#DD6B55", |
|||
confirmButtonText: "确定", |
|||
closeOnConfirm: false |
|||
}, |
|||
function () { |
|||
callbackfuntion(); |
|||
}); |
|||
|
|||
} |
|||
function alertSuccessCallBack2(title1,message, callbackfuntion) { |
|||
swal({ |
|||
title: title1, |
|||
text: message, |
|||
type: "success", |
|||
confirmButtonColor: "#DD6B55", |
|||
confirmButtonText: "确定", |
|||
closeOnConfirm: false |
|||
}, |
|||
function () { |
|||
callbackfuntion(); |
|||
}); |
|||
|
|||
} |
|||
|
|||
|
|||
function alertError( message) { |
|||
swal(message, '', "error"); |
|||
} |
|||
|
|||
function alertWarning(_title,message) { |
|||
|
|||
swal({ |
|||
title: _title, |
|||
text: message, |
|||
type: "warning", |
|||
showCancelButton: false, |
|||
confirmButtonColor: "#DD6B55", |
|||
confirmButtonText: "确定", |
|||
closeOnConfirm: false |
|||
} ); |
|||
} |
|||
|
|||
|
|||
function alertWarningCallBack(message,dtovalue,callbackfuntion) { |
|||
|
|||
swal({ |
|||
title: message, |
|||
text: "", |
|||
type: "warning", |
|||
showCancelButton: false, |
|||
confirmButtonColor: "#DD6B55", |
|||
confirmButtonText: "确定", |
|||
closeOnConfirm: true |
|||
}, |
|||
function () { |
|||
callbackfuntion(dtovalue); |
|||
}); |
|||
} |
|||
|
|||
|
|||
function confirmEx(title, message, callbackfuntion) { |
|||
swal({ |
|||
title: title, |
|||
text: message, |
|||
type: "warning", |
|||
showCancelButton: true, |
|||
confirmButtonColor: "#DD6B55", |
|||
confirmButtonText: "确定", |
|||
closeOnConfirm: true |
|||
}, |
|||
function () { |
|||
callbackfuntion(); |
|||
}); |
|||
} |
|||
|
|||
function alertAutoClose(message) { |
|||
swal({ |
|||
title: message, |
|||
text: "2秒钟后自动关闭", |
|||
timer: 2000, |
|||
showConfirmButton: false |
|||
}); |
|||
} |
|||
function alertAutoClose3(message) { |
|||
swal({ |
|||
title: message, |
|||
text: "3秒钟后自动关闭", |
|||
timer: 3000, |
|||
showConfirmButton: false |
|||
}); |
|||
} |
@ -0,0 +1,501 @@ |
|||
<!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; |
|||
|
|||
width: 100%; |
|||
|
|||
height: 100% |
|||
} |
|||
|
|||
.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); |
|||
} |
|||
</style> |
|||
<script async src="/app/bin/layui/layui.js"></script> |
|||
|
|||
<script type="importmap"> |
|||
{ |
|||
"imports": { |
|||
"three": "../build/three.module.js", |
|||
"jsm/": "../examples/jsm/" |
|||
} |
|||
} |
|||
</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 { VRButton } from './js/VRButton.js'; |
|||
|
|||
import { OrbitControls } from 'jsm/controls/OrbitControls.js'; |
|||
|
|||
import { CSS2DRenderer, CSS2DObject } from 'jsm/renderers/CSS2DRenderer.js'; |
|||
import { Water } from 'jsm/objects/Water.js'; |
|||
const type = 1; |
|||
window.THREE = THREE; // Used by APP Scripts. |
|||
window.VRButton = VRButton; // Used by APP Scripts. |
|||
|
|||
var loader = new THREE.FileLoader(); |
|||
loader.load('UASB3.json', function (text) { |
|||
|
|||
var player = new APP.Player(); |
|||
player.load(JSON.parse(text)); |
|||
player.setSize(window.innerWidth, window.innerHeight); |
|||
player.play(); |
|||
|
|||
document.body.appendChild(player.dom); |
|||
|
|||
window.addEventListener('resize', function () { |
|||
|
|||
player.setSize(window.innerWidth, window.innerHeight); |
|||
|
|||
}); |
|||
var orbitControls = new OrbitControls(window.camera, player.dom); |
|||
// initLable(); |
|||
setModel(window.scene, player); |
|||
AddWaters(player); |
|||
addRemarkLabels(); |
|||
|
|||
}); |
|||
|
|||
|
|||
function addButton(obj, perent, i) { |
|||
|
|||
const btnDiv = document.createElement('button'); |
|||
btnDiv.className = 'btn'; |
|||
btnDiv.identifierName = 'btn'; |
|||
btnDiv.textContent = 'Btn: Click ...'; |
|||
btnDiv.style.marginTop = '-1em'; |
|||
btnDiv.style.zIndex = 1000; |
|||
|
|||
const css2dBtn = new CSS2DObject(btnDiv); |
|||
|
|||
css2dBtn.position.set(obj.x + 2, obj.y, obj.z); |
|||
css2dBtn.name = "datalabel" + i; |
|||
css2dBtn.userData = { name: "datalable", id: "", url: "" } |
|||
// css2DLabelList.add(css2DLabel); |
|||
window.scene.add(css2dBtn); |
|||
|
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
//添加这个就可以用鼠标拖动 |
|||
|
|||
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 guid() { |
|||
// return 'xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx'.replace(/[xy]/g, function (c) { |
|||
// var r = Math.random() * 16 | 0, |
|||
// v = c == 'x' ? r : (r & 0x3 | 0x8); |
|||
// return v.toString(16); |
|||
// }); |
|||
// } |
|||
|
|||
|
|||
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 +',y:' + obj.point.y +',z:'+ obj.point.z+'}'); |
|||
if (tmpobj.name.indexOf('水泵M_') > -1) { // 水泵 |
|||
|
|||
openDialog(tmpobj) |
|||
//alert(tmpobj.name, "双击"); |
|||
} |
|||
break; |
|||
// let mondeojb = {} |
|||
// mondeojb.id = guid(); |
|||
// mondeojb.text = "新标签"; |
|||
// mondeojb.position = tmpobj.position; |
|||
// mondeojb.rotation = tmpobj.rotation; |
|||
// var json = JSON.stringify(mondeojb); |
|||
// console.log(json); |
|||
} |
|||
} |
|||
} |
|||
|
|||
|
|||
//打开对话框 |
|||
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 createCSSLabel(text, parent) { |
|||
|
|||
const labelDiv = document.createElement('div'); |
|||
labelDiv.className = 'label'; |
|||
labelDiv.name = "csslabeldiv" |
|||
labelDiv.textContent = text; |
|||
|
|||
labelDiv.style.pointerEvents = 'none';//避免HTML标签遮挡三维场景的鼠标事件 |
|||
const moonLabel = new CSS2DObject(labelDiv); |
|||
moonLabel.position.set(1, 2, 0); |
|||
moonLabel.name = "datalabel" |
|||
moonLabel.userData = { name: "datalable", id: "", url: "" } |
|||
return moonLabel; |
|||
|
|||
} |
|||
let pumpModelArr = [] |
|||
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: "油桶1" }, { name: "OilTank002", text: "油桶2" }, { name: "OilTank003", text: "油桶3" }, |
|||
|
|||
] |
|||
const remarkLabArr = [{ name: "221", text: "22", x: 2.0501311208405713, y: -0.9778027560129786, z: -5.377062185399511 }, { name: "211", text: "21", x: 0.1740166304621844, y: -0.9760432883855322, z: -5.667636935767586 }, |
|||
{ name: "491", text: "49", x: -2.105188770141037, y: -0.9901334936138524, z: -5.4669334625207435 }] |
|||
|
|||
|
|||
|
|||
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') { |
|||
console.log("parent.name=", parent.name) |
|||
if (!parent.name) { |
|||
|
|||
return; |
|||
} |
|||
console.log("parent.name2=", parent.name) |
|||
let item = await getlabel(parent.name); |
|||
console.log("item2=", item) |
|||
// debugger |
|||
if (!item) return; |
|||
console.log("item2=", item) |
|||
const labelDiv = document.createElement('div'); |
|||
labelDiv.className = className; |
|||
labelDiv.name = "csslabel"; |
|||
labelDiv.textContent = item.text; |
|||
labelDiv.style.marginTop = '-1em'; |
|||
|
|||
labelDiv.style.pointerEvents = 'none';//避免HTML标签遮挡三维场景的鼠标事件 |
|||
const css2DLabel = new CSS2DObject(labelDiv); |
|||
css2DLabel.position.set(x, y, z); |
|||
css2DLabel.name = "datalabel" |
|||
css2DLabel.userData = { name: "datalable", id: "", url: "" } |
|||
// css2DLabelList.add(css2DLabel); |
|||
if(parent){ |
|||
parent.add(css2DLabel); |
|||
|
|||
}else{ |
|||
window.scene.add(css2DLabel); |
|||
} |
|||
|
|||
|
|||
} |
|||
async function addRemarkLabel(parent,text, x = 0, y = 0, z = 0, className = 'label') { |
|||
|
|||
const labelDiv = document.createElement('div'); |
|||
labelDiv.className = className; |
|||
labelDiv.name = "csslabel"; |
|||
labelDiv.textContent = text; |
|||
labelDiv.style.marginTop = '-1em'; |
|||
|
|||
labelDiv.style.pointerEvents = 'none';//避免HTML标签遮挡三维场景的鼠标事件 |
|||
const css2DLabel = new CSS2DObject(labelDiv); |
|||
css2DLabel.position.set(x, y, z); |
|||
css2DLabel.name = "datalabel" |
|||
css2DLabel.userData = { name: "datalable", id: "", url: "" } |
|||
// css2DLabelList.add(css2DLabel); |
|||
if (parent) { |
|||
parent.add(css2DLabel); |
|||
|
|||
} else { |
|||
window.scene.add(css2DLabel); |
|||
} |
|||
|
|||
|
|||
} |
|||
//状态标签 |
|||
async function addStateLabel(parent, x = 0, y = 0, z = 0, className = 'label') { |
|||
console.log("parent.name=", parent.name) |
|||
if (!parent.name) { |
|||
|
|||
return; |
|||
} |
|||
console.log("parent.name2=", parent.name) |
|||
let item = await getlabel(parent.name); |
|||
console.log("item2=", item) |
|||
// debugger |
|||
if (!item) return; |
|||
console.log("item2=", item) |
|||
const labelDiv = document.createElement('div'); |
|||
labelDiv.className = className; |
|||
labelDiv.name = "csslabel"; |
|||
labelDiv.textContent = '●' + item.text; |
|||
labelDiv.style.marginTop = '-1em'; |
|||
|
|||
labelDiv.style.pointerEvents = 'none';//避免HTML标签遮挡三维场景的鼠标事件 |
|||
const css2DLabel = new CSS2DObject(labelDiv); |
|||
css2DLabel.position.set(x, y, z); |
|||
css2DLabel.name = "datalabel" |
|||
css2DLabel.userData = { name: "datalable", id: "", url: "" } |
|||
// css2DLabelList.add(css2DLabel); |
|||
parent.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); |
|||
|
|||
|
|||
} |
|||
|
|||
// 设置标签 |
|||
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) => { |
|||
addRemarkLabel(null,item.text,item.x,item.y,item.z,'label1') |
|||
|
|||
}) |
|||
} |
|||
function addDBclick(item) { |
|||
item.ondbclick = pumpDBClick |
|||
} |
|||
function pumpDBClick(event) { |
|||
alert("ddd111111"); |
|||
} |
|||
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; |
|||
|
|||
}) |
|||
} |
|||
|
|||
</script> |
|||
|
|||
|
|||
<!-- Code injected by live-server --> |
|||
<script> |
|||
// <![CDATA[ <-- For SVG support |
|||
if ('WebSocket' in window) { |
|||
(function () { |
|||
function refreshCSS() { |
|||
var sheets = [].slice.call(document.getElementsByTagName("link")); |
|||
var head = document.getElementsByTagName("head")[0]; |
|||
for (var i = 0; i < sheets.length; ++i) { |
|||
var elem = sheets[i]; |
|||
var parent = elem.parentElement || head; |
|||
parent.removeChild(elem); |
|||
var rel = elem.rel; |
|||
if (elem.href && typeof rel != "string" || rel.length == 0 || rel.toLowerCase() == "stylesheet") { |
|||
var url = elem.href.replace(/(&|\?)_cacheOverride=\d+/, ''); |
|||
elem.href = url + (url.indexOf('?') >= 0 ? '&' : '?') + '_cacheOverride=' + (new Date().valueOf()); |
|||
} |
|||
parent.appendChild(elem); |
|||
} |
|||
} |
|||
var protocol = window.location.protocol === 'http:' ? 'ws://' : 'wss://'; |
|||
var address = protocol + window.location.host + window.location.pathname + '/ws'; |
|||
var socket = new WebSocket(address); |
|||
socket.onmessage = function (msg) { |
|||
if (msg.data == 'reload') window.location.reload(); |
|||
else if (msg.data == 'refreshcss') refreshCSS(); |
|||
}; |
|||
if (sessionStorage && !sessionStorage.getItem('IsThisFirstTime_Log_From_LiveServer')) { |
|||
console.log('Live reload enabled.'); |
|||
sessionStorage.setItem('IsThisFirstTime_Log_From_LiveServer', true); |
|||
} |
|||
})(); |
|||
} |
|||
else { |
|||
console.error('Upgrade your browser. This Browser is NOT supported WebSocket for Live-Reloading.'); |
|||
} |
|||
// ]]> |
|||
</script> |
|||
<script> |
|||
|
|||
</script> |
|||
|
|||
</body> |
|||
|
|||
</html> |
@ -0,0 +1,206 @@ |
|||
<!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; |
|||
|
|||
width: 100%; |
|||
|
|||
height: 100% |
|||
} |
|||
|
|||
.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); |
|||
} |
|||
|
|||
</style> |
|||
<script type="importmap"> |
|||
{ |
|||
"imports": { |
|||
"three": "../build/three.module.js", |
|||
"jsm/": "../examples/jsm/" |
|||
} |
|||
} |
|||
</script> |
|||
</head> |
|||
|
|||
<body ontouchstart=""> |
|||
<div class="info">2D数据表格显示 不旋转 综合水池</div> |
|||
<script type="module"> |
|||
|
|||
import * as THREE from 'three'; |
|||
import { APP } from './js/app.js'; |
|||
import { VRButton } from './js/VRButton.js'; |
|||
|
|||
import { OrbitControls } from 'jsm/controls/OrbitControls.js'; |
|||
|
|||
import { CSS2DRenderer, CSS2DObject } from 'jsm/renderers/CSS2DRenderer.js'; |
|||
|
|||
window.THREE = THREE; // Used by APP Scripts. |
|||
window.VRButton = VRButton; // Used by APP Scripts. |
|||
|
|||
var loader = new THREE.FileLoader(); |
|||
loader.load('zhsc.json', function (text) { |
|||
|
|||
var player = new APP.Player(); |
|||
player.load(JSON.parse(text)); |
|||
player.setSize(window.innerWidth, window.innerHeight); |
|||
player.play(); |
|||
|
|||
document.body.appendChild(player.dom); |
|||
|
|||
window.addEventListener('resize', function () { |
|||
|
|||
player.setSize(window.innerWidth, window.innerHeight); |
|||
|
|||
}); |
|||
var orbitControls = new OrbitControls(window.camera, player.dom); |
|||
initLable(); |
|||
|
|||
}); |
|||
function initLable() { |
|||
const labobjarr = [{ text: "测试标签1", x: -1, y: 0, z: 1 }, { text: "测试标签2", x: 1, y: 1, z: 1 }] |
|||
for (var i = 0, length = labobjarr.length; i < length; i++) { |
|||
|
|||
addLabel(labobjarr[i], scene, i); |
|||
|
|||
} |
|||
} |
|||
function addLabel(obj, scene, i) { |
|||
|
|||
const labelDiv = document.createElement('div'); |
|||
labelDiv.className = 'label'; |
|||
labelDiv.name = "label" + i; |
|||
labelDiv.textContent = obj.text; |
|||
|
|||
|
|||
labelDiv.style.pointerEvents = 'none';//避免HTML标签遮挡三维场景的鼠标事件 |
|||
const css2DLabel = new CSS2DObject(labelDiv); |
|||
css2DLabel.position.set(obj.x, obj.y, obj.z); |
|||
css2DLabel.name = "datalabel" + i; |
|||
css2DLabel.userData = { name: "datalable", id: "", url: "" } |
|||
// css2DLabelList.add(css2DLabel); |
|||
window.scene.add(css2DLabel); |
|||
|
|||
} |
|||
//添加这个就可以用鼠标拖动 |
|||
|
|||
var raycaster = new THREE.Raycaster() |
|||
var mouse = new THREE.Vector2() |
|||
//点击模型 |
|||
window.addEventListener('click', onMouseClick); |
|||
|
|||
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[0].color.set(0xff6666); |
|||
alert("视频"); |
|||
} else { |
|||
obj.object.material[0].color.set(0xff0000); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
function createCSSLabel(text, parent) { |
|||
|
|||
const labelDiv = document.createElement('div'); |
|||
labelDiv.className = 'label'; |
|||
labelDiv.name = "csslabeldiv" |
|||
labelDiv.textContent = text; |
|||
|
|||
labelDiv.style.pointerEvents = 'none';//避免HTML标签遮挡三维场景的鼠标事件 |
|||
const moonLabel = new CSS2DObject(labelDiv); |
|||
moonLabel.position.set(1, 2, 0); |
|||
moonLabel.name = "datalabel" |
|||
moonLabel.userData = { name: "datalable", id: "", url: "" } |
|||
return moonLabel; |
|||
|
|||
} |
|||
</script> |
|||
<!-- Code injected by live-server --> |
|||
<script> |
|||
// <![CDATA[ <-- For SVG support |
|||
if ('WebSocket' in window) { |
|||
(function () { |
|||
function refreshCSS() { |
|||
var sheets = [].slice.call(document.getElementsByTagName("link")); |
|||
var head = document.getElementsByTagName("head")[0]; |
|||
for (var i = 0; i < sheets.length; ++i) { |
|||
var elem = sheets[i]; |
|||
var parent = elem.parentElement || head; |
|||
parent.removeChild(elem); |
|||
var rel = elem.rel; |
|||
if (elem.href && typeof rel != "string" || rel.length == 0 || rel.toLowerCase() == "stylesheet") { |
|||
var url = elem.href.replace(/(&|\?)_cacheOverride=\d+/, ''); |
|||
elem.href = url + (url.indexOf('?') >= 0 ? '&' : '?') + '_cacheOverride=' + (new Date().valueOf()); |
|||
} |
|||
parent.appendChild(elem); |
|||
} |
|||
} |
|||
var protocol = window.location.protocol === 'http:' ? 'ws://' : 'wss://'; |
|||
var address = protocol + window.location.host + window.location.pathname + '/ws'; |
|||
var socket = new WebSocket(address); |
|||
socket.onmessage = function (msg) { |
|||
if (msg.data == 'reload') window.location.reload(); |
|||
else if (msg.data == 'refreshcss') refreshCSS(); |
|||
}; |
|||
if (sessionStorage && !sessionStorage.getItem('IsThisFirstTime_Log_From_LiveServer')) { |
|||
console.log('Live reload enabled.'); |
|||
sessionStorage.setItem('IsThisFirstTime_Log_From_LiveServer', true); |
|||
} |
|||
})(); |
|||
} |
|||
else { |
|||
console.error('Upgrade your browser. This Browser is NOT supported WebSocket for Live-Reloading.'); |
|||
} |
|||
// ]]> |
|||
</script> |
|||
</body> |
|||
|
|||
</html> |
@ -0,0 +1,68 @@ |
|||
import { Command } from '../Command.js'; |
|||
import { ObjectLoader } from 'three'; |
|||
|
|||
/** |
|||
* @param editor Editor |
|||
* @param object THREE.Object3D |
|||
* @constructor |
|||
*/ |
|||
class AddLableCommand extends Command { |
|||
|
|||
constructor( editor, object ) { |
|||
|
|||
super( editor ); |
|||
|
|||
this.type = 'AddObjectCommand'; |
|||
|
|||
this.object = object; |
|||
if ( object !== undefined ) { |
|||
|
|||
this.name = `Add Object: ${object.name}`; |
|||
|
|||
} |
|||
|
|||
} |
|||
|
|||
execute() { |
|||
|
|||
//this.editor.addObject( this.object );
|
|||
this.editor.addLable(this.object); |
|||
//this.editor.select( this.object );
|
|||
|
|||
} |
|||
|
|||
undo() { |
|||
|
|||
this.editor.removeObject( this.object ); |
|||
this.editor.deselect(); |
|||
|
|||
} |
|||
|
|||
toJSON() { |
|||
|
|||
const output = super.toJSON( this ); |
|||
|
|||
output.object = this.object.toJSON(); |
|||
|
|||
return output; |
|||
|
|||
} |
|||
|
|||
fromJSON( json ) { |
|||
|
|||
super.fromJSON( json ); |
|||
|
|||
this.object = this.editor.objectByUuid( json.object.object.uuid ); |
|||
|
|||
if ( this.object === undefined ) { |
|||
|
|||
const loader = new ObjectLoader(); |
|||
this.object = loader.parse( json.object ); |
|||
|
|||
} |
|||
|
|||
} |
|||
|
|||
} |
|||
|
|||
export { AddLableCommand }; |