唐润平:传感器添加功能
This commit is contained in:
@@ -155,8 +155,10 @@ function rClickCallback(demo) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 添加设备
|
// 添加设备
|
||||||
function handleAddEqu(e) {
|
function handleAddEqu(formInfo) {
|
||||||
console.log("添加的设备属性", e);
|
//表单信息
|
||||||
|
//这里利用处理请求
|
||||||
|
demo.addEquipment(targetP, formInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 删除设备
|
// 删除设备
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ const equipmentSetting = reactive({
|
|||||||
// 设备类型选项参数
|
// 设备类型选项参数
|
||||||
const options = reactive([
|
const options = reactive([
|
||||||
{ label: "风机", value: "fan" },
|
{ label: "风机", value: "fan" },
|
||||||
{ label: "风压传感器", value: "windPressure" },
|
{ label: "风压传感器", value: "sensors" },
|
||||||
{ label: "普通传感器", value: "sensors" },
|
{ label: "普通传感器", value: "sensors" },
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@@ -143,16 +143,19 @@ function removeEquipment() {
|
|||||||
|
|
||||||
// 添加设备
|
// 添加设备
|
||||||
function addEquipment() {
|
function addEquipment() {
|
||||||
// 处理不合法情况
|
// // 处理不合法情况
|
||||||
if (
|
// if (
|
||||||
!equipmentSetting.chooseEquipment ||
|
// !equipmentSetting.chooseEquipment ||
|
||||||
!equipmentSetting.equipmentType ||
|
// !equipmentSetting.equipmentType ||
|
||||||
!equipmentSetting.threshold
|
// !equipmentSetting.threshold
|
||||||
) {
|
// ) {
|
||||||
alert("选项不能有空");
|
// alert("选项不能有空");
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
emit("addEquipment", equipmentSetting);
|
emit("addEquipment", equipmentSetting);
|
||||||
|
equipmentSetting.chooseEquipment = "";
|
||||||
|
equipmentSetting.equipmentType = "";
|
||||||
|
equipmentSetting.threshold = "";
|
||||||
}
|
}
|
||||||
const equipmentType = {
|
const equipmentType = {
|
||||||
label: String, //传感器类型
|
label: String, //传感器类型
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ export default class Demo {
|
|||||||
//设备模型数组
|
//设备模型数组
|
||||||
deviceModels = [];
|
deviceModels = [];
|
||||||
constructor(three, mountedElement) {
|
constructor(three, mountedElement) {
|
||||||
// 外部引入匿名函数
|
|
||||||
this._handleLClick = handleLClick;
|
this._handleLClick = handleLClick;
|
||||||
this._handleRClick = handleRClick;
|
this._handleRClick = handleRClick;
|
||||||
this._handleDBLClick = handleDBLClick;
|
this._handleDBLClick = handleDBLClick;
|
||||||
@@ -306,14 +305,14 @@ export default class Demo {
|
|||||||
this.tagCSS2DObj = new CSS2DObject(this.tagHtml);
|
this.tagCSS2DObj = new CSS2DObject(this.tagHtml);
|
||||||
this.tag2CSS2DObj = new CSS2DObject(this.tag2Html);
|
this.tag2CSS2DObj = new CSS2DObject(this.tag2Html);
|
||||||
this.tag3CSS2DObj = new CSS2DObject(this.tag3Html);
|
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.tagCSS2DObj.element.style.opacity = "1";
|
||||||
this.tag2CSS2DObj.element.style.opacity = "1";
|
this.tag2CSS2DObj.element.style.opacity = "1";
|
||||||
this.tag3CSS2DObj.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.tagCSS2DObj.scale.set(0.1, 0.1, 0.1);
|
||||||
this.tag2CSS2DObj.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); //编辑框
|
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) {
|
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");
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,10 +1,55 @@
|
|||||||
function addEquipment(targetPoint, EquType) {
|
/**
|
||||||
const equMesh = this.equMap.get("equ_fan").clone();
|
*
|
||||||
console.log(equMesh);
|
* @param {Mesh} targetPoint
|
||||||
this.scene.add(equMesh);
|
* @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) {}
|
function removeEquipment(targetPoint) {}
|
||||||
export { addEquipment, removeEquipment };
|
export { addEquipment, removeEquipment };
|
||||||
|
|||||||
Reference in New Issue
Block a user