112 lines
3.4 KiB
JavaScript
112 lines
3.4 KiB
JavaScript
import EquipmentTag from "../utils/EquipmentTag";
|
||
/**
|
||
*
|
||
* @param {Mesh} targetPoint
|
||
* @param {String} equType "fan" "sensors"
|
||
*/
|
||
//formInfo需要的信息这里包括了
|
||
//equipmentType、
|
||
|
||
function addEquipment(targetPoint, formInfo) {
|
||
if (targetPoint.hasDevice) {
|
||
alert("已添加设备");
|
||
return;
|
||
}
|
||
switch (formInfo.equipmentType) {
|
||
case "fan":
|
||
handleFanEqu.call(this, targetPoint);
|
||
break;
|
||
case "sensors":
|
||
case "sensors_2":
|
||
handleOtherEqu.call(this, targetPoint, formInfo.equipmentType);
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
targetPoint.hasDevice = true;
|
||
// 标识设备信息
|
||
this.clearTagsObj();
|
||
}
|
||
// 其他传感器
|
||
function handleOtherEqu(targetPoint, EqeName) {
|
||
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" ? "风压传感器" : "普通传感器");
|
||
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; ///注意在原来的基础上加
|
||
} else if (/tl$/.test(targetPoint.name)) {
|
||
equMesh.rotation.z = -(5 * Math.PI) / 4;
|
||
targetPoint.scale.set(0.03, 0.03, 0.03);
|
||
} else if (/tc$/.test(targetPoint.name)) {
|
||
equMesh.rotation.z = Math.PI;
|
||
targetPoint.scale.set(0.03, 0.03, 0.03);
|
||
} 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);
|
||
} else if (/bl$/.test(targetPoint.name)) {
|
||
equMesh.rotation.z = Math.PI / 2;
|
||
equMesh.translateX(1);
|
||
|
||
targetPoint.scale.set(0.03, 0.03, 0.075);
|
||
}
|
||
|
||
this.scene.add(equMesh);
|
||
targetPoint.visible = false;
|
||
|
||
// 保存该设备id,后期直接从附附着点进行删除
|
||
targetPoint.info = {
|
||
id: equMesh.id,
|
||
};
|
||
}
|
||
|
||
// 风机
|
||
function handleFanEqu(targetPoint, speed = Math.random().toFixed(1) * 1000) {
|
||
// 由于风机比较多,每个风机转速不一直,保存在一个数中遍历
|
||
if (!this.fanSpinArray) {
|
||
this.fanSpinArray = [];
|
||
}
|
||
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;
|
||
// 放大附着点方便选中风机的范围
|
||
targetPoint.scale.set(0.06, 0.06, 0.06);
|
||
// 保存该设备id,后期直接从附附着点进行删除
|
||
targetPoint.info = {
|
||
id: equMesh.id, //模型在场景id
|
||
};
|
||
|
||
// 定义风机旋转
|
||
const fanLeaf = equMesh.getObjectByName("fan_leafs");
|
||
const fanSpin = new this.TWEEN.Tween({ rotation: 0 });
|
||
fanSpin.to({ rotation: 2 * Math.PI }, speed);
|
||
fanSpin.repeat(Infinity);
|
||
fanSpin.start();
|
||
fanSpin.onUpdate((obj) => {
|
||
fanLeaf.rotation.z = obj.rotation;
|
||
});
|
||
|
||
this.fanSpinArray.push(fanSpin);
|
||
}
|
||
|
||
// 删除传感器
|
||
function removeEquipment(targetPoint) {
|
||
if (!targetPoint.hasDevice) return;
|
||
const mesh = this.scene.getObjectById(targetPoint.info.id);
|
||
this.scene.remove(mesh);
|
||
targetPoint.visible = true;
|
||
targetPoint.hasDevice = false;
|
||
targetPoint.scale.set(0.01, 0.01, 0.01);
|
||
}
|
||
export { addEquipment, removeEquipment };
|