|
|
@ -33,7 +33,7 @@ |
|
|
|
color: #ff000f; |
|
|
|
font-family: sans-serif; |
|
|
|
padding: 2px; |
|
|
|
/* background: rgba(0, 0, 0, .6); */ |
|
|
|
background: rgba(77, 0, 0, .6); |
|
|
|
} |
|
|
|
|
|
|
|
.label1 { |
|
|
@ -113,7 +113,8 @@ |
|
|
|
player.setSize(window.innerWidth, window.innerHeight); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
//设置背景颜色 |
|
|
|
player.setClearColor(0x34495E); |
|
|
|
|
|
|
|
initModel() |
|
|
|
|
|
|
@ -122,18 +123,33 @@ |
|
|
|
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(-2 - i, 2 + 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 THREE.FileLoader(); |
|
|
|
loader.load('uasb3.json', function (text) { |
|
|
|
|
|
|
|
let json = JSON.parse(text); |
|
|
|
let objloader = new THREE.ObjectLoader(); |
|
|
|
let scene = objloader.parse(json.scene) |
|
|
|
|
|
|
|
function initModel() { |
|
|
|
player.addModels(scene);//.children[3]); |
|
|
|
|
|
|
|
setModel(scene, player); |
|
|
|
// AddWaters(player); |
|
|
|
// addRemarkLabels(); |
|
|
|
|
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
function initModel1() { |
|
|
|
var loader = new GLTFLoader(); |
|
|
|
loader.load('assets/models/uasb.glb', function (gltf) { |
|
|
|
loader.load('assets/models/uasb2.glb', function (gltf) { |
|
|
|
// gltf.scene.traverse(function (child) { |
|
|
|
// switch (child.name) { |
|
|
|
// case 'walls': |
|
|
@ -153,120 +169,104 @@ |
|
|
|
// initDraws(child) |
|
|
|
// } |
|
|
|
// }) |
|
|
|
let tmpmodel= gltf.scene; |
|
|
|
tmpmodel.rotation.set(-0.2,2,0.3) |
|
|
|
|
|
|
|
let tmpmodel = gltf.scene//.children[1]; |
|
|
|
|
|
|
|
tmpmodel.rotation.set(0, 2, -0.2) |
|
|
|
|
|
|
|
player.addModels(tmpmodel); |
|
|
|
setModel(window.scene, player); |
|
|
|
setModel(tmpmodel, player); |
|
|
|
|
|
|
|
}); |
|
|
|
} |
|
|
|
var x = 0; |
|
|
|
// 设置标签 |
|
|
|
function setModel(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); |
|
|
|
scene.castShadow = true; // 开启阴影 |
|
|
|
scene.receiveShadow = true; // 接受阴影 |
|
|
|
|
|
|
|
// 获取raycaster直线和所有模型相交的数组集合 |
|
|
|
var intersects = raycaster.intersectObjects(scene.children); |
|
|
|
console.log(intersects); |
|
|
|
scene.children.forEach((item, index) => { |
|
|
|
|
|
|
|
//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, "双击"); |
|
|
|
// 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) |
|
|
|
} |
|
|
|
break; |
|
|
|
else if (item.name.indexOf('水泵M_') > -1) { // 水泵 |
|
|
|
x = x + 1; |
|
|
|
pumpModelArr.push(item); |
|
|
|
//debugger |
|
|
|
if (item.name === '水泵001') { |
|
|
|
item.material.color.set(0x00f); |
|
|
|
} else { |
|
|
|
item.material.color.set(0x006600); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
console.log("x=",x,"--------item ==", index, "name=", item.name, "type=", item.type); |
|
|
|
addStateLabel(item, x/2, 2+x/2, x/2) |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (item.type === 'Object3D' || item.type === 'Group') { // 有下一级 |
|
|
|
|
|
|
|
setModel(item, player); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}) |
|
|
|
console.log('pumpModelArr=', pumpModelArr) |
|
|
|
} |
|
|
|
|
|
|
|
// 设置标签 |
|
|
|
function setModel(scene, player) { |
|
|
|
function setModel1(scene, player) { |
|
|
|
|
|
|
|
|
|
|
|
scene.castShadow = true; // 开启阴影 |
|
|
|
scene.receiveShadow = true; // 接受阴影 |
|
|
|
// 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) |
|
|
|
console.log("--------item ==", index, "name=", item.name, "type=", item.type); |
|
|
|
|
|
|
|
if (item.name.indexOf('OilTank00') > -1) { |
|
|
|
addLabel(item, 0, 0.4, 0) |
|
|
|
} |
|
|
|
else if (item.name.indexOf('水泵M_') > -1) { // 水泵 |
|
|
|
else if (item.name == "水泵001") { |
|
|
|
item.material.color.set(0xff0000); |
|
|
|
} |
|
|
|
else if (item.name == "水泵_2") { |
|
|
|
item.material.color.set(0xff0000); |
|
|
|
} |
|
|
|
else if (item.name.indexOf('水泵M_') > -1 && item.type == "Mesh") { // 水泵 |
|
|
|
pumpModelArr.push(item); |
|
|
|
|
|
|
|
// debugger |
|
|
|
if (item.name === '水泵001') { |
|
|
|
// if (item.name === '水泵001') { |
|
|
|
// item.material.color.set(0xff0000); |
|
|
|
// } else { |
|
|
|
// item.material.color.set(0x006600); |
|
|
|
|
|
|
|
// } |
|
|
|
if (item.name === '水泵M_1') { |
|
|
|
item.material.color.set(0xff0000); |
|
|
|
// item.children[0].material.color.set(0xff0000); |
|
|
|
// item.children[1].material.color.set(0xff0000); |
|
|
|
// // item.children[2].material.color.set(0xff0000); |
|
|
|
} else { |
|
|
|
item.material.color.set(0x006600); |
|
|
|
// item.material.color.set(0x006600); |
|
|
|
// item.children[0].material.color.set(0x006600); |
|
|
|
// item.children[1].material.color.set(0x006600); |
|
|
|
// item.children[2].material.color.set(0x006600); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
addStateLabel(item, 0, 3, 0) |
|
|
|
|
|
|
|
|
|
|
@ -282,6 +282,81 @@ |
|
|
|
console.log('pumpModelArr=', pumpModelArr) |
|
|
|
} |
|
|
|
|
|
|
|
//添加这个就可以用鼠标拖动 |
|
|
|
|
|
|
|
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, true); |
|
|
|
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直线和所有模型相交的数组集合 |
|
|
|
// debugger |
|
|
|
var intersects = raycaster.intersectObjects(scene.children, true); |
|
|
|
console.log("onclick ", 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('水泵') > -1) { // 水泵 |
|
|
|
|
|
|
|
openDialog(tmpobj) |
|
|
|
//alert(tmpobj.name, "双击"); |
|
|
|
} |
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//添加 模型标签 |
|
|
|
function addRemarkLabels() { |
|
|
@ -350,6 +425,7 @@ |
|
|
|
//状态标签 |
|
|
|
async function addStateLabel(parent, x = 0, y = 0, z = 0, className = 'label') { |
|
|
|
|
|
|
|
|
|
|
|
if (!parent.name) { |
|
|
|
|
|
|
|
return; |
|
|
@ -357,15 +433,16 @@ |
|
|
|
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); |
|
|
|
// let css2DLabel = player.create3dLabel('●' + item.text, x, y, z, className); |
|
|
|
player.create3dLabel(parent, item.text, |
|
|
|
1020, 680, |
|
|
|
new THREE.Vector3(x, y, z), |
|
|
|
new THREE.Vector3(0, Math.PI, 0), |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
@ -389,7 +466,7 @@ |
|
|
|
{ |
|
|
|
textureWidth: 255, |
|
|
|
textureHeight: 255, |
|
|
|
waterNormals: new THREE.TextureLoader().load('./img/waternormals.jpg', function (texture) { |
|
|
|
waterNormals: new THREE.TextureLoader().load('./assets/textures/waternormals.jpg', function (texture) { |
|
|
|
|
|
|
|
texture.wrapS = texture.wrapT = THREE.RepeatWrapping; |
|
|
|
|
|
|
@ -466,8 +543,8 @@ |
|
|
|
function openDialog(tmpobj) { |
|
|
|
layer.open({ |
|
|
|
type: 1 |
|
|
|
, offset: type //具体配置参考:http://doc/modules/layer.html#offset |
|
|
|
, id: 'layerDemo' + type //防止重复弹出 |
|
|
|
, offset: 1 //具体配置参考:http://doc/modules/layer.html#offset |
|
|
|
, id: 'layerDemo' + 1 //防止重复弹出 |
|
|
|
, content: '<div style="padding: 20px 100px;">' + tmpobj.name + '</div>' |
|
|
|
, btn: '关闭' |
|
|
|
, btnAlign: 'c' //按钮居中 |
|
|
|