This commit is contained in:
Hcat
2023-12-22 14:55:05 +08:00
parent 68d121091f
commit 65510ce59d
10 changed files with 463 additions and 208 deletions

View File

@@ -5,20 +5,20 @@ import EquipmentTag from "../utils/EquipmentTag";
* @param {String} equType "fan" "sensors"
*/
//formInfo需要的信息这里包括了
//equipmentType
//equipmentType
function addEquipment(targetPoint, formInfo) {
if (targetPoint.hasDevice) {
alert("已添加设备");
return;
}
switch (formInfo.equipmentType) {
case "fan":
handleFanEqu.call(this, targetPoint);
case "frequency":
handleFanEqu.call(this, targetPoint, formInfo.chooseEquipment);
break;
case "sensors":
case "sensors_2":
handleOtherEqu.call(this, targetPoint, formInfo.equipmentType);
case "windPressure":
case "sensor":
handleOtherEqu.call(this, targetPoint, formInfo.chooseEquipment);
break;
default:
break;
@@ -28,47 +28,50 @@ function addEquipment(targetPoint, formInfo) {
this.clearTagsObj();
}
// 其他传感器
function handleOtherEqu(targetPoint, EqeName) {
function handleOtherEqu(targetPoint, equipmentInfo) {
const equMesh = this.equMap.get("equ_sensors").clone();
const worldP = targetPoint.getWorldPosition(new this.THREE.Vector3());
equMesh.position.copy(worldP);
//设备添加标签
const tag = EquipmentTag(EqeName === "sensors" ? "风压传感器" : "普通传感器");
const tag = EquipmentTag(equipmentInfo.label);
console.log(equipmentInfo);
equMesh.getObjectByName("tag").material = tag;
if (/tr$/.test(targetPoint.name)) {
equMesh.rotation.z = -(3 * Math.PI) / 4;
targetPoint.scale.set(0.03, 0.03, 0.03);
equMesh.getObjectByName("tag").rotation.z += Math.PI; ///注意在原来的基础上加
equMesh.rotation.z = -Math.PI / 2;
equMesh.rotation.y -= Math.PI / 4;
equMesh.getObjectByName("tag").rotation.z += Math.PI; // 注意在原来的基础上加
} else if (/tl$/.test(targetPoint.name)) {
equMesh.rotation.z = -(5 * Math.PI) / 4;
targetPoint.scale.set(0.03, 0.03, 0.03);
equMesh.rotation.z = Math.PI / 2;
equMesh.rotation.y += Math.PI / 4;
equMesh.getObjectByName("tag").rotation.z += Math.PI;
} else if (/tc$/.test(targetPoint.name)) {
equMesh.rotation.z = Math.PI;
targetPoint.scale.set(0.03, 0.03, 0.03);
equMesh.getObjectByName("tag").rotation.z += Math.PI;
} else if (/br$/.test(targetPoint.name)) {
equMesh.rotation.z = -Math.PI / 2;
equMesh.translateX(-1);
equMesh.getObjectByName("tag").rotation.z += Math.PI; ///注意在原来的基础上加
targetPoint.scale.set(0.03, 0.03, 0.075);
equMesh.getObjectByName("tag").rotation.z += Math.PI;
} else if (/bl$/.test(targetPoint.name)) {
equMesh.rotation.z = Math.PI / 2;
equMesh.translateX(1);
targetPoint.scale.set(0.03, 0.03, 0.075);
equMesh.getObjectByName("tag").rotation.z += Math.PI;
}
targetPoint.scale.set(0.03, 0.06, 0.05);
this.scene.add(equMesh);
targetPoint.visible = false;
// 保存该设备id后期直接从附附着点进行删除
// 保存该设备模型id后期直接从附附着点进行删除
targetPoint.info = {
id: equMesh.id,
...equipmentInfo,
};
}
// 风机
function handleFanEqu(targetPoint, speed = Math.random().toFixed(1) * 1000) {
function handleFanEqu(
targetPoint,
equipmentInfo,
speed = Math.random().toFixed(1) * 1000
) {
// 由于风机比较多,每个风机转速不一直,保存在一个数中遍历
if (!this.fanSpinArray) {
this.fanSpinArray = [];
@@ -84,6 +87,7 @@ function handleFanEqu(targetPoint, speed = Math.random().toFixed(1) * 1000) {
// 保存该设备id后期直接从附附着点进行删除
targetPoint.info = {
id: equMesh.id, //模型在场景id
...equipmentInfo,
};
// 定义风机旋转
@@ -107,5 +111,6 @@ function removeEquipment(targetPoint) {
targetPoint.visible = true;
targetPoint.hasDevice = false;
targetPoint.scale.set(0.01, 0.01, 0.01);
delete targetPoint.info; // 清空设备信息
}
export { addEquipment, removeEquipment };