唐润平:传感器添加功能

This commit is contained in:
trp
2023-12-15 17:02:23 +08:00
parent c91d93b24b
commit dcc92b3c77
4 changed files with 86 additions and 27 deletions

View File

@@ -155,8 +155,10 @@ function rClickCallback(demo) {
}
// 添加设备
function handleAddEqu(e) {
console.log("添加的设备属性", e);
function handleAddEqu(formInfo) {
//表单信息
//这里利用处理请求
demo.addEquipment(targetP, formInfo);
}
// 删除设备

View File

@@ -82,7 +82,7 @@ const equipmentSetting = reactive({
// 设备类型选项参数
const options = reactive([
{ label: "风机", value: "fan" },
{ label: "风压传感器", value: "windPressure" },
{ label: "风压传感器", value: "sensors" },
{ label: "普通传感器", value: "sensors" },
]);
@@ -143,16 +143,19 @@ function removeEquipment() {
// 添加设备
function addEquipment() {
// 处理不合法情况
if (
!equipmentSetting.chooseEquipment ||
!equipmentSetting.equipmentType ||
!equipmentSetting.threshold
) {
alert("选项不能有空");
return;
}
// // 处理不合法情况
// if (
// !equipmentSetting.chooseEquipment ||
// !equipmentSetting.equipmentType ||
// !equipmentSetting.threshold
// ) {
// alert("选项不能有空");
// return;
// }
emit("addEquipment", equipmentSetting);
equipmentSetting.chooseEquipment = "";
equipmentSetting.equipmentType = "";
equipmentSetting.threshold = "";
}
const equipmentType = {
label: String, //传感器类型

View File

@@ -17,7 +17,6 @@ export default class Demo {
//设备模型数组
deviceModels = [];
constructor(three, mountedElement) {
// 外部引入匿名函数
this._handleLClick = handleLClick;
this._handleRClick = handleRClick;
this._handleDBLClick = handleDBLClick;
@@ -306,14 +305,14 @@ export default class Demo {
this.tagCSS2DObj = new CSS2DObject(this.tagHtml);
this.tag2CSS2DObj = new CSS2DObject(this.tag2Html);
this.tag3CSS2DObj = new CSS2DObject(this.tag3Html);
this.tagCSS2DObj.element.style.display = "none";
this.tag2CSS2DObj.element.style.display = "none";
this.tag3CSS2DObj.element.style.display = "none";
// 设置该标签初始化透明
this.tagCSS2DObj.element.style.opacity = "1";
this.tag2CSS2DObj.element.style.opacity = "1";
this.tag3CSS2DObj.element.style.opacity = "1";
this.tagCSS2DObj.element.style.display = "none";
this.tag2CSS2DObj.element.style.display = "none";
this.tag3CSS2DObj.element.style.display = "none";
this.tagCSS2DObj.scale.set(0.1, 0.1, 0.1);
this.tag2CSS2DObj.scale.set(0.1, 0.1, 0.1);
this.tag3CSS2DObj.scale.set(0.02, 0.02, 0.02); //编辑框
@@ -354,13 +353,23 @@ export default class Demo {
}
/**
* @param {Map} meshes gltf加载过后的模型数组
* @param {Map} meshes gltf加载过后的模型Map
*/
initDevicesModel(equMap) {
//
this.equMap = equMap;
// 初始化风机
console.log(equMap);
this.equMap = equMap;
// 初始化风机颜色
this.equMap.get("equ_fan").traverse((v) => {
v.material = new this.THREE.MeshBasicMaterial();
v.material.color = new this.THREE.Color("#191a05");
});
// 初始化风机颜色
this.equMap.get("equ_sensors").scale.set(0.1, 0.1, 0.1);
this.equMap.get("equ_sensors").traverse((v) => {
v.material = new this.THREE.MeshBasicMaterial();
v.material.color = new this.THREE.Color("white");
});
}
/**

View File

@@ -1,10 +1,55 @@
function addEquipment(targetPoint, EquType) {
const equMesh = this.equMap.get("equ_fan").clone();
console.log(equMesh);
this.scene.add(equMesh);
/**
*
* @param {Mesh} targetPoint
* @param {String} equType "fan" "sensors"
*/
function addEquipment(targetPoint, formInfo) {
if (targetPoint.hasDevice) {
alert("已添加设备");
return;
}
switch (formInfo.equipmentType) {
case "fan":
handleFanEqu.call(this, targetPoint);
break;
case "sensors":
handleOtherEqu.call(this, targetPoint);
break;
default:
break;
}
targetPoint.hasDevice = true;
console.log("添加信息", targetPoint, formInfo);
}
// 其他传感器
function handleOtherEqu(targetPoint, speed = 0) {
const equMesh = this.equMap.get("equ_sensors").clone();
const worldP = targetPoint.getWorldPosition(new this.THREE.Vector3());
equMesh.position.copy(worldP);
if (/tr$/.test(targetPoint.name)) {
equMesh.rotation.z = -(3 * Math.PI) / 4;
} else if (/tl$/.test(targetPoint.name)) {
equMesh.rotation.z = -Math.PI / 4;
} else if (/trc$/.test(targetPoint.name)) {
} else if (/br$/.test(targetPoint.name)) {
equMesh.rotation.z = -Math.PI / 2;
equMesh.translateX(-1);
} else if (/bl$/.test(targetPoint.name)) {
equMesh.rotation.z = Math.PI / 2;
equMesh.translateX(1);
}
this.scene.add(equMesh);
targetPoint.visible = false;
}
// 风机
function handleFanEqu(targetPoint, speed = 0) {
const equMesh = this.equMap.get("equ_fan").clone();
const worldP = targetPoint.getWorldPosition(new this.THREE.Vector3());
equMesh.position.copy(worldP);
equMesh.translateY(-0.6);
this.scene.add(equMesh);
targetPoint.visible = false;
}
// 处理设备添加位置
function handleOtherEqu() {}
function handleFanEqu() {}
function removeEquipment(targetPoint) {}
export { addEquipment, removeEquipment };