解决隧道仿真数据在隧道中没有渲染问题
This commit is contained in:
@@ -315,7 +315,7 @@ async function handleMounted() {
|
||||
demo.isedit = params.isedit;
|
||||
let tunnelasync = await demo.loadModel(
|
||||
GLTFLoader,
|
||||
"/tunnelModel/chanel-have-wall-now-use.gltf"
|
||||
"/tunnelModel/chanel-have-wall-now-use.gltf",
|
||||
);
|
||||
demo.addOrbitControls(OrbitControls);
|
||||
demo.addTween(TWEEN);
|
||||
|
||||
@@ -1,28 +1,28 @@
|
||||
<template>
|
||||
<div id="scene">
|
||||
<div id="cvs" ref="content"></div>
|
||||
<dev-info ref="info" :devInfo="devInfo"/>
|
||||
<dev-info ref="info" :devInfo="devInfo" />
|
||||
<!-- 这里的预览模式需要做成不能修改的模式 -->
|
||||
<edit-dialog
|
||||
ref="edit"
|
||||
@addEquipment="handleAddEqu"
|
||||
@removeEquipment="handleRemoveEqu"
|
||||
@cancel="handleCancel"
|
||||
:hasDev="hasDevice"
|
||||
:pointNum="pointNum"
|
||||
:tunnelId="params.tunnelId"
|
||||
:position="targetP?.name"
|
||||
:hasEquipment="hasDevice"
|
||||
:pointGap="pointGap"
|
||||
:form="params.form"
|
||||
ref="edit"
|
||||
@addEquipment="handleAddEqu"
|
||||
@removeEquipment="handleRemoveEqu"
|
||||
@cancel="handleCancel"
|
||||
:hasDev="hasDevice"
|
||||
:pointNum="pointNum"
|
||||
:tunnelId="params.tunnelId"
|
||||
:position="targetP?.name"
|
||||
:hasEquipment="hasDevice"
|
||||
:pointGap="pointGap"
|
||||
:form="params.form"
|
||||
/>
|
||||
<el-dialog
|
||||
v-model="centerDialogVisible"
|
||||
width="30%"
|
||||
destroy-on-close
|
||||
center
|
||||
:show-close="false"
|
||||
style="
|
||||
v-model="centerDialogVisible"
|
||||
width="30%"
|
||||
destroy-on-close
|
||||
center
|
||||
:show-close="false"
|
||||
style="
|
||||
margin: 20% auto;
|
||||
width: 569px;
|
||||
height: 330px;
|
||||
@@ -47,27 +47,30 @@ import DevInfo from "./displayInfoComp/DevInfo.vue";
|
||||
import EditDialog from "./editEquComp/editDialog.vue";
|
||||
|
||||
// 导入模模型加载器
|
||||
import {GLTFLoader} from "three/examples/jsm/loaders/GLTFLoader";
|
||||
import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader";
|
||||
// import { DRACOLoader } from "three/examples/jsm/loaders/dracoloader";
|
||||
import {OrbitControls} from "three/examples/jsm/controls/OrbitControls";
|
||||
import { OrbitControls } from "three/examples/jsm/controls/OrbitControls";
|
||||
import * as TWEEN from "three/examples/jsm/libs/tween.module";
|
||||
import {
|
||||
CSS3DRenderer,
|
||||
CSS3DObject,
|
||||
CSS3DSprite,
|
||||
} from "three/addons/renderers/CSS3DRenderer.js";
|
||||
// 引入CSS2渲染器CSS2DRenderer和CSS2模型对象CSS2DObject
|
||||
import {
|
||||
CSS2DRenderer,
|
||||
CSS2DObject,
|
||||
} from "three/addons/renderers/CSS2DRenderer.js";
|
||||
|
||||
import {OBJLoader} from "three/examples/jsm/loaders/OBJLoader";
|
||||
import {RGBELoader} from "three/examples/jsm/loaders/RGBELoader";
|
||||
import {onMounted, reactive, ref, toRaw, watch} from "vue";
|
||||
import {ElMessage} from "element-plus";
|
||||
import {useModelSceneStore} from "@/store/modelSceneStore";
|
||||
import {LOD} from "three";
|
||||
import { OBJLoader } from "three/examples/jsm/loaders/OBJLoader";
|
||||
import { RGBELoader } from "three/examples/jsm/loaders/RGBELoader";
|
||||
import {
|
||||
onMounted,
|
||||
reactive,
|
||||
ref,
|
||||
toRaw,
|
||||
watch,
|
||||
defineProps,
|
||||
defineExpose,
|
||||
} from "vue";
|
||||
import { ElMessage } from "element-plus";
|
||||
import { useModelSceneStore } from "@/store/modelSceneStore";
|
||||
import { getScreenSimulateTunnel } from "@/api/tunnelManage";
|
||||
// 获取html标签跟随组件dom
|
||||
const content = ref(null);
|
||||
const info = ref(null);
|
||||
@@ -85,20 +88,21 @@ const params = defineProps([
|
||||
"form",
|
||||
"deviceData",
|
||||
"devRealtimeData",
|
||||
"simulateData",
|
||||
]); //接收参数看是不是编辑模式,如果是编辑模式,则需要做一些处理
|
||||
|
||||
let isedit = ref(params.isedit);
|
||||
let tunnelId = reactive(params.tunnelId);
|
||||
|
||||
watch(
|
||||
() => params.tunnelLength,
|
||||
(now) => {
|
||||
params.tunnelLength = now;
|
||||
// console.log(params.tunnelLength);
|
||||
pointGap = now / 20;
|
||||
// console.log(params.form.tunnelName);
|
||||
},
|
||||
{deep: true}
|
||||
() => params.tunnelLength,
|
||||
(now) => {
|
||||
params.tunnelLength = now;
|
||||
// console.log(params.tunnelLength);
|
||||
pointGap = now / 20;
|
||||
// console.log(params.form.tunnelName);
|
||||
},
|
||||
{ deep: true }
|
||||
);
|
||||
|
||||
let pointGap = reactive(params.tunnelLength);
|
||||
@@ -110,12 +114,12 @@ async function handleMounted() {
|
||||
const doms = [info.value.$el, edit.value.$el];
|
||||
demo = new ThreeDScene(three, content.value);
|
||||
//看是不是预览模式,然后继续相关的操作(会在demo中的初始化中进行)
|
||||
demo.isedit = params.isedit;
|
||||
// "../../../../public/tunnelModel/chanel-have-wall-now-use.gltf"
|
||||
demo.isedit =false;
|
||||
const loaded = await demo.loadModel(
|
||||
GLTFLoader,
|
||||
"/tunnelModel/chanel-have-wall-now-use.gltf",
|
||||
true
|
||||
GLTFLoader,
|
||||
"/tunnelModel/chanel-have-wall-now-use.gltf",
|
||||
true,
|
||||
);
|
||||
demo.addOrbitControls(OrbitControls, true);
|
||||
demo.addTween(TWEEN);
|
||||
@@ -153,42 +157,114 @@ async function handleMounted() {
|
||||
// console.log('parmas',newModelList)
|
||||
modelList.value = [
|
||||
{
|
||||
"typeKey": "frequency",
|
||||
"position": "point_001_tr",
|
||||
"threshold": "",
|
||||
"equipmentId": 3048,
|
||||
"equipmentName": "温度传感器",
|
||||
"equipmentType": "sensor"
|
||||
}, {
|
||||
"typeKey": "temperature",
|
||||
"position": "point_020_tr",
|
||||
"threshold": "",
|
||||
"equipmentId": 10,
|
||||
"equipmentName": "1度传感器",
|
||||
"equipmentType": "sensor"
|
||||
}
|
||||
]
|
||||
// modelList.value = await initData(params.tunnelId, params.form);
|
||||
// console.log("test", modelList.value);
|
||||
demo.editTunnelInit(toRaw(modelList.value));
|
||||
typeKey: "frequency",
|
||||
position: "point_001_tr",
|
||||
threshold: "",
|
||||
equipmentId: 3048,
|
||||
equipmentName: "温度传感器",
|
||||
equipmentType: "sensor",
|
||||
data: 100, //实时数据
|
||||
unit: "℃", //单位
|
||||
},
|
||||
{
|
||||
typeKey: "temperature",
|
||||
position: "point_020_tr",
|
||||
threshold: "",
|
||||
equipmentId: 10,
|
||||
equipmentName: "1度传感器",
|
||||
equipmentType: "sensor",
|
||||
data: 10, //实时参数
|
||||
unit: "%", //单位
|
||||
},
|
||||
];
|
||||
|
||||
// 初始化仿真參數
|
||||
const { data } = await getScreenSimulateTunnel(params.tunnelId);
|
||||
const modeData = randomPosition([
|
||||
...data.frequencyChangerList,
|
||||
...data.windPressureSensorList,
|
||||
...data.sensorList,
|
||||
]).map((item) => ({
|
||||
...item,
|
||||
equipmentType: item.equipmentType.startsWith("frequency")
|
||||
? "frequency"
|
||||
: "sensor",
|
||||
}));
|
||||
demo.editTunnelInit(modeData);
|
||||
// 初始化标牌信息
|
||||
demo.SignsInf("dsadsa", String(params.tunnelLength));
|
||||
} catch (err) {}
|
||||
}
|
||||
|
||||
// 从新渲染数据
|
||||
async function rerender() {
|
||||
try {
|
||||
// 初始化仿真參數
|
||||
const { data } = await getScreenSimulateTunnel(params.tunnelId);
|
||||
console.log(data);
|
||||
const modeData = randomPosition([
|
||||
...data.frequencyChangerList,
|
||||
...data.windPressureSensorList,
|
||||
...data.sensorList,
|
||||
]).map((item) => ({
|
||||
...item,
|
||||
equipmentType: item.equipmentType.startsWith("frequency")
|
||||
? "frequency"
|
||||
: "sensor",
|
||||
}));
|
||||
demo.editTunnelInit(modeData);
|
||||
demo.SignsInf(params.form.tunnelAlias, String(params.tunnelLength));
|
||||
} catch (err) {
|
||||
} catch (error) {
|
||||
ElMessage({
|
||||
message: "获取仿真数据异常!",
|
||||
type: "warning",
|
||||
});
|
||||
}
|
||||
}
|
||||
// 随机生成1-20的随机数
|
||||
function randomNum(max = 20) {
|
||||
const nums = new Set();
|
||||
while (nums.size < max) {
|
||||
nums.add(Math.floor(Math.random() * max + 1).toString());
|
||||
}
|
||||
return [...nums];
|
||||
}
|
||||
//随机定位
|
||||
function randomPosition(simulateData) {
|
||||
const mid = Math.floor(simulateData.length / 2);
|
||||
const lrIndex = Math.floor(Math.random() * 2);
|
||||
const lr_position = ["tl", "tr"];
|
||||
const leftPosition = randomNum();
|
||||
const rightPosition = randomNum();
|
||||
const leftData = simulateData.slice(0, mid).map((item, index) => ({
|
||||
...item,
|
||||
position: `point_0${leftPosition[index].padStart(2, 0)}_${
|
||||
lr_position[lrIndex]
|
||||
}`,
|
||||
}));
|
||||
const rightData = simulateData
|
||||
.slice(mid, simulateData.length)
|
||||
.map((item, index) => ({
|
||||
...item,
|
||||
position: `point_0${rightPosition[index].padStart(2, 0)}_${
|
||||
lr_position[1 - lrIndex]
|
||||
}`,
|
||||
}));
|
||||
return [...leftData, ...rightData];
|
||||
}
|
||||
|
||||
// 每个模型加载回调
|
||||
function loadModel(path) {
|
||||
return new Promise((resolve, reject) => {
|
||||
loader.load(
|
||||
path,
|
||||
(obj) => {
|
||||
resolve(obj);
|
||||
},
|
||||
(xhr) => {
|
||||
},
|
||||
(err) => {
|
||||
reject(err);
|
||||
}
|
||||
path,
|
||||
(obj) => {
|
||||
resolve(obj);
|
||||
},
|
||||
(xhr) => {},
|
||||
(err) => {
|
||||
reject(err);
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
@@ -203,12 +279,12 @@ let devInfo = reactive({
|
||||
|
||||
// 对象建构赋值功能
|
||||
function editDevInfo(
|
||||
value = {
|
||||
meshId: null,
|
||||
name: "无",
|
||||
state: "无",
|
||||
position: "无",
|
||||
}
|
||||
value = {
|
||||
meshId: null,
|
||||
name: "无",
|
||||
state: "无",
|
||||
position: "无",
|
||||
}
|
||||
) {
|
||||
devInfo.meshId = value.meshId;
|
||||
devInfo.name = value.name;
|
||||
@@ -243,10 +319,10 @@ function rClickCallback(demo) {
|
||||
hasDevice.value = targetPoint.hasDevice;
|
||||
targetP.value = targetPoint;
|
||||
pointNum.value = Number(
|
||||
targetPoint.name.substring(
|
||||
targetPoint.name.indexOf("_") + 1,
|
||||
targetPoint.name.lastIndexOf("_")
|
||||
) - 1
|
||||
targetPoint.name.substring(
|
||||
targetPoint.name.indexOf("_") + 1,
|
||||
targetPoint.name.lastIndexOf("_")
|
||||
) - 1
|
||||
);
|
||||
if (!targetPoint.info) return;
|
||||
editDevInfo(targetPoint.info);
|
||||
@@ -292,23 +368,23 @@ function handleRemoveEqu() {
|
||||
function handleConfirmAddEqu() {
|
||||
console.log("target:", targetP.value.info);
|
||||
modelStore
|
||||
.deleteEquipment(targetP.value.info.equipmentId, pointGap)
|
||||
.then((res) => {
|
||||
demo.removeEquipment(targetP.value);
|
||||
centerDialogVisible.value = false;
|
||||
handleCancel();
|
||||
ElMessage({
|
||||
message: "删除成功!",
|
||||
type: "success",
|
||||
});
|
||||
})
|
||||
.catch((res) => {
|
||||
console.log(res);
|
||||
ElMessage({
|
||||
message: "删除失败!",
|
||||
type: "warning",
|
||||
});
|
||||
.deleteEquipment(targetP.value.info.equipmentId, pointGap)
|
||||
.then((res) => {
|
||||
demo.removeEquipment(targetP.value);
|
||||
centerDialogVisible.value = false;
|
||||
handleCancel();
|
||||
ElMessage({
|
||||
message: "删除成功!",
|
||||
type: "success",
|
||||
});
|
||||
})
|
||||
.catch((res) => {
|
||||
console.log(res);
|
||||
ElMessage({
|
||||
message: "删除失败!",
|
||||
type: "warning",
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// 处理取消关闭编辑框事件
|
||||
@@ -351,6 +427,9 @@ const ThreeConfig = {
|
||||
watch(params.devRealtimeData, () => {
|
||||
// console.log("devRealtimeData:", params.devRealtimeData);
|
||||
});
|
||||
defineExpose({
|
||||
rerender,
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
|
||||
@@ -34,7 +34,7 @@ function addEquipment(targetPoint, formInfo, fanData) {
|
||||
}
|
||||
|
||||
//判断墙是否已经存在,如果存在的话,就不管,添加则无效嘛(就是说只能添加一面墙,如果存在一面墙,则不管了)
|
||||
let hasWall = false
|
||||
let hasWall = false;
|
||||
let wallHang = 0;
|
||||
|
||||
// function handleValveEqu(targetPoint, equipmentInfo) {
|
||||
@@ -49,7 +49,8 @@ function handleOtherEqu(targetPoint, equipmentInfo) {
|
||||
equMesh.position.copy(worldP);
|
||||
|
||||
//设备添加标签
|
||||
const tag = EquipmentTag(equipmentInfo.equipmentName);
|
||||
const param = `${equipmentInfo.data || "--"} ${equipmentInfo.unit || "-"}`; //渲染设备参数(data)和单位(unit)
|
||||
const tag = EquipmentTag(equipmentInfo.equipmentName,param);
|
||||
equMesh.getObjectByName("tag").material = tag;
|
||||
if (/tr$/.test(targetPoint.name)) {
|
||||
equMesh.rotation.z = -Math.PI / 2;
|
||||
@@ -195,11 +196,10 @@ function handleFanEqu(
|
||||
if (item.isMesh) {
|
||||
item.material = item.material.clone();
|
||||
}
|
||||
})
|
||||
});
|
||||
// equMesh.geometry = this.equMap.get("equ_fan").geometry.clone();
|
||||
// console.log(equMesh);
|
||||
|
||||
|
||||
const worldP = targetPoint.getWorldPosition(new this.THREE.Vector3());
|
||||
equMesh.position.copy(worldP);
|
||||
equMesh.translateY(-0.6);
|
||||
@@ -213,15 +213,13 @@ function handleFanEqu(
|
||||
...equipmentInfo,
|
||||
};
|
||||
//我们把风机的附着点挂在原型上,这样应该可以进行处理
|
||||
if (targetPoint.info.equipmentName.slice(0, 1) == '1') {
|
||||
this.scene.Fan1targetPoint = targetPoint
|
||||
if (targetPoint.info.equipmentName.slice(0, 1) == "1") {
|
||||
this.scene.Fan1targetPoint = targetPoint;
|
||||
} else {
|
||||
this.scene.Fan2targetPoint = targetPoint
|
||||
this.scene.Fan2targetPoint = targetPoint;
|
||||
}
|
||||
//这里感觉情况改变风机的颜色
|
||||
changeFanColor(fanData, targetPoint, this.scene)
|
||||
|
||||
|
||||
changeFanColor(fanData, targetPoint, this.scene);
|
||||
|
||||
// 定义风机旋转
|
||||
const fanLeaf = equMesh.getObjectByName("fan_leafs");
|
||||
@@ -240,7 +238,6 @@ function removeEquipment(targetPoint) {
|
||||
//删除设备这里需要再进行处理,就是根据附着点(附着点一定保存了当前添加设备的信息了)判断是不是分压阀,然后继续一样的隐藏
|
||||
if (!targetPoint.hasDevice) return;
|
||||
|
||||
|
||||
//删除我们这里使用行数来判断,即是不是删除到了我们的那一行呢?
|
||||
//如果删除到了我们那行的话,我们必须将行的数组从中去掉已存在的数据,然后将附着点列表中也去除这个点,然后将墙设置为false来让下次使用
|
||||
|
||||
@@ -286,8 +283,6 @@ function removeEquipment(targetPoint) {
|
||||
// }
|
||||
// deleteItem(Allhang, Number(lineIndex))
|
||||
|
||||
|
||||
|
||||
console.log("测试是不是删除了");
|
||||
const mesh = this.scene.getObjectById(targetPoint.info.id);
|
||||
this.scene.remove(mesh);
|
||||
@@ -298,13 +293,12 @@ function removeEquipment(targetPoint) {
|
||||
}
|
||||
export { addEquipment, removeEquipment };
|
||||
|
||||
|
||||
function deleteItem(array, item) {
|
||||
let index = array.indexOf(item);
|
||||
if (index !== -1) {
|
||||
array.splice(index, 1);
|
||||
}
|
||||
return array
|
||||
return array;
|
||||
}
|
||||
|
||||
// 这里是改变风机颜色的代码
|
||||
@@ -315,7 +309,7 @@ function changeFanColor(fanData, targetPoint, scene) {
|
||||
//if保证存在风机(即有长度再进行遍历)
|
||||
for (let i = 0; i < fanData.length; i++) {
|
||||
//先做匹配操作
|
||||
let fanType = fanData[i].equipmentType
|
||||
let fanType = fanData[i].equipmentType;
|
||||
//有符合条件的风机进来了
|
||||
if (targetPoint.info.typeKey == fanType) {
|
||||
//下面进行变色需要的逻辑判断了
|
||||
@@ -327,9 +321,9 @@ function changeFanColor(fanData, targetPoint, scene) {
|
||||
// console.log(obj);
|
||||
// 判断子对象是否是物体,如果是,更改其颜色
|
||||
if (obj.isMesh) {
|
||||
obj.material.color.set(0xFF0000)
|
||||
obj.material.color.set(0xff0000);
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
@@ -342,9 +336,9 @@ function changeFanColor(fanData, targetPoint, scene) {
|
||||
// console.log(obj);
|
||||
// 判断子对象是否是物体,如果是,更改其颜色
|
||||
if (obj.isMesh) {
|
||||
obj.material.color.set(0x008000)
|
||||
obj.material.color.set(0x008000);
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
@@ -356,4 +350,4 @@ function changeFanColor(fanData, targetPoint, scene) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user