唐润平:风机旋转

This commit is contained in:
trp
2023-12-16 16:00:04 +08:00
parent 9ff76d31db
commit 236ed18fd5
6 changed files with 80885 additions and 7 deletions

40418
public/devicesModel/model.obj Normal file

File diff suppressed because it is too large Load Diff

40418
public/devicesModel/model2.obj Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -69,7 +69,7 @@ async function handleMounted() {
// 初始化设备模型
try {
const map = new Map();
map.set("equ_fan", await loadModel("/devicesModel/fan.obj"));
map.set("equ_fan", await loadModel("/devicesModel/model2.obj"));
map.set("equ_sensors", await loadModel("/devicesModel/sensors.obj"));
// 给对象初加载设备模型

View File

@@ -9,6 +9,7 @@ import {
import { saveState, resetState } from "./viewBack";
import addFunction from "./addEvent";
import { addEquipment, removeEquipment } from "./editEquipment";
import { Group } from "three/examples/jsm/libs/tween.module";
export default class Demo {
// 摄像机看向位置
origin = null;
@@ -101,6 +102,10 @@ export default class Demo {
if (this.dblIntoTween) {
this.dblIntoTween.update();
}
// 风机叶片旋转动画
if (this.fanSpinArray && this.fanSpinArray.length) {
this.fanSpinArray.forEach((element) => element.update());
}
}
// 添加世界坐标系
@@ -357,14 +362,35 @@ export default class Demo {
* @param {Map} meshes gltf加载过后的模型Map
*/
initDevicesModel(equMap) {
// 把风机叶片做为一个组,方便后期旋转
const group = new this.THREE.Group();
group.name = "fanLeaf";
// 初始化风机
this.equMap = equMap;
// 初始化风机颜色
this.equMap.get("equ_fan").traverse((v) => {
v.material = new this.THREE.MeshBasicMaterial();
v.material.color = new this.THREE.Color("#191a05");
// v.material = new this.THREE.MeshBasicMaterial();
// v.material.color = new this.THREE.Color("#191a05");
if (/^leaf/.test(v.name) || /^roller/.test(v.name)) {
group.add(v.clone());
v.visible = false;
// console.log(v);
}
});
const axesHelper = new this.THREE.AxesHelper(100);
// 改变叶子旋转中心
let x = 0,
y = -0.2,
z = 0;
const wrapper = new this.THREE.Object3D();
wrapper.position.set(x, y, z);
wrapper.add(group);
group.position.set(-x, -y, -z);
// wrapper.add(axesHelper);
wrapper.rotation.z = Math.PI / 4;
wrapper.name = "fan_leafs";
this.equMap.get("equ_fan").add(wrapper);
// 初其他传感器机颜色
this.equMap.get("equ_sensors").scale.set(0.1, 0.1, 0.1);

View File

@@ -65,7 +65,11 @@ function handleOtherEqu(targetPoint, EqeName) {
}
// 风机
function handleFanEqu(targetPoint, speed = 0) {
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);
@@ -78,7 +82,21 @@ function handleFanEqu(targetPoint, speed = 0) {
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);

View File

@@ -41,6 +41,4 @@ export function handleEndChange(e) {
// this.scene
// .getObjectByName("point_001_tr")
// .getWorldPosition(new this.THREE.Vector3())
// );
console.log(this.orbitControls.distance);
}