|
@ -33,7 +33,7 @@ |
|
|
color: #ff000f; |
|
|
color: #ff000f; |
|
|
font-family: sans-serif; |
|
|
font-family: sans-serif; |
|
|
padding: 2px; |
|
|
padding: 2px; |
|
|
/* background: rgba(0, 0, 0, .6); */ |
|
|
background: rgba(77, 0, 0, .6); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
.label1 { |
|
|
.label1 { |
|
@ -113,7 +113,8 @@ |
|
|
player.setSize(window.innerWidth, window.innerHeight); |
|
|
player.setSize(window.innerWidth, window.innerHeight); |
|
|
|
|
|
|
|
|
}); |
|
|
}); |
|
|
|
|
|
//设置背景颜色 |
|
|
|
|
|
player.setClearColor(0x34495E); |
|
|
|
|
|
|
|
|
initModel() |
|
|
initModel() |
|
|
|
|
|
|
|
@ -122,18 +123,33 @@ |
|
|
for (var i = 0; i < 1; i++) { |
|
|
for (var i = 0; i < 1; i++) { |
|
|
player.create3dPage( |
|
|
player.create3dPage( |
|
|
1020, 680, |
|
|
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), |
|
|
new THREE.Vector3(0, Math.PI, 0), |
|
|
'https://zuoben.blog.csdn.net/'); |
|
|
'https://zuoben.blog.csdn.net/'); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// document.body.appendChild(player.dom); |
|
|
// 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(); |
|
|
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) { |
|
|
// gltf.scene.traverse(function (child) { |
|
|
// switch (child.name) { |
|
|
// switch (child.name) { |
|
|
// case 'walls': |
|
|
// case 'walls': |
|
@ -153,120 +169,104 @@ |
|
|
// initDraws(child) |
|
|
// 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); |
|
|
player.addModels(tmpmodel); |
|
|
setModel(window.scene, player); |
|
|
setModel(tmpmodel, player); |
|
|
|
|
|
|
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
var x = 0; |
|
|
|
|
|
// 设置标签 |
|
|
|
|
|
function setModel(scene, player) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//添加这个就可以用鼠标拖动 |
|
|
scene.castShadow = true; // 开启阴影 |
|
|
|
|
|
scene.receiveShadow = true; // 接受阴影 |
|
|
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 |
|
|
scene.children.forEach((item, index) => { |
|
|
raycaster.setFromCamera(mouse, window.camera); |
|
|
|
|
|
|
|
|
|
|
|
// 获取raycaster直线和所有模型相交的数组集合 |
|
|
|
|
|
var intersects = raycaster.intersectObjects(scene.children); |
|
|
|
|
|
console.log(intersects); |
|
|
|
|
|
|
|
|
|
|
|
//debugger |
|
|
// console.log("--------item ==", index); |
|
|
//将所有的相交的模型的颜色设置为红色 |
|
|
// console.log("name=", item.name) |
|
|
for (var i = 0; i < intersects.length; i++) { |
|
|
// console.log("type=", item.type) |
|
|
let obj = intersects[i]; |
|
|
if (item.name.indexOf('OilTank00') > -1) { |
|
|
if (obj.object) { |
|
|
addLabel(item, 0, 0.4, 0) |
|
|
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; |
|
|
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.castShadow = true; // 开启阴影 |
|
|
scene.receiveShadow = true; // 接受阴影 |
|
|
// scene.receiveShadow = true; // 接受阴影 |
|
|
|
|
|
|
|
|
scene.children.forEach((item, index) => { |
|
|
scene.children.forEach((item, index) => { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// console.log("--------item ==", index); |
|
|
console.log("--------item ==", index, "name=", item.name, "type=", item.type); |
|
|
// console.log("name=", item.name) |
|
|
|
|
|
// console.log("type=", item.type) |
|
|
|
|
|
if (item.name.indexOf('OilTank00') > -1) { |
|
|
if (item.name.indexOf('OilTank00') > -1) { |
|
|
addLabel(item, 0, 0.4, 0) |
|
|
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); |
|
|
pumpModelArr.push(item); |
|
|
//debugger |
|
|
|
|
|
if (item.name === '水泵001') { |
|
|
// debugger |
|
|
|
|
|
// 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.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 { |
|
|
} 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) |
|
|
addStateLabel(item, 0, 3, 0) |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -282,6 +282,81 @@ |
|
|
console.log('pumpModelArr=', pumpModelArr) |
|
|
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() { |
|
|
function addRemarkLabels() { |
|
@ -350,6 +425,7 @@ |
|
|
//状态标签 |
|
|
//状态标签 |
|
|
async function addStateLabel(parent, x = 0, y = 0, z = 0, className = 'label') { |
|
|
async function addStateLabel(parent, x = 0, y = 0, z = 0, className = 'label') { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!parent.name) { |
|
|
if (!parent.name) { |
|
|
|
|
|
|
|
|
return; |
|
|
return; |
|
@ -357,15 +433,16 @@ |
|
|
console.log("parent.name2=", parent.name) |
|
|
console.log("parent.name2=", parent.name) |
|
|
let item = await getlabel(parent.name); |
|
|
let item = await getlabel(parent.name); |
|
|
if (item) { |
|
|
if (item) { |
|
|
let css2DLabel = css2dlabel.createCSSLabel('●' + item.text, x, y, z, className); |
|
|
// let css2DLabel = player.create3dLabel('●' + item.text, x, y, z, className); |
|
|
if (parent) { |
|
|
player.create3dLabel(parent, item.text, |
|
|
parent.add(css2DLabel); |
|
|
1020, 680, |
|
|
|
|
|
new THREE.Vector3(x, y, z), |
|
|
} else { |
|
|
new THREE.Vector3(0, Math.PI, 0), |
|
|
window.scene.add(css2DLabel); |
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
@ -389,7 +466,7 @@ |
|
|
{ |
|
|
{ |
|
|
textureWidth: 255, |
|
|
textureWidth: 255, |
|
|
textureHeight: 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; |
|
|
texture.wrapS = texture.wrapT = THREE.RepeatWrapping; |
|
|
|
|
|
|
|
@ -466,8 +543,8 @@ |
|
|
function openDialog(tmpobj) { |
|
|
function openDialog(tmpobj) { |
|
|
layer.open({ |
|
|
layer.open({ |
|
|
type: 1 |
|
|
type: 1 |
|
|
, offset: type //具体配置参考:http://doc/modules/layer.html#offset |
|
|
, offset: 1 //具体配置参考:http://doc/modules/layer.html#offset |
|
|
, id: 'layerDemo' + type //防止重复弹出 |
|
|
, id: 'layerDemo' + 1 //防止重复弹出 |
|
|
, content: '<div style="padding: 20px 100px;">' + tmpobj.name + '</div>' |
|
|
, content: '<div style="padding: 20px 100px;">' + tmpobj.name + '</div>' |
|
|
, btn: '关闭' |
|
|
, btn: '关闭' |
|
|
, btnAlign: 'c' //按钮居中 |
|
|
, btnAlign: 'c' //按钮居中 |
|
|