feat: 优化位置和可见性批量设置逻辑,仅在提供坐标或角度时更新,提升渲染效率和可读性

This commit is contained in:
xudan 2025-09-15 18:10:04 +08:00
parent 5d56362848
commit ac3b380f31

View File

@ -148,19 +148,30 @@ const monitorScene = async () => {
}
});
//
const positionUpdates = updates.map(({ id, data }) => {
const { x, y, angle } = data;
if (isNil(x) || isNil(y)) {
return { id, visible: false };
} else {
const newX = x - 60;
const newY = y - 60;
// angle
const rotate = angle == null ? undefined : -angle + 180;
return { id, x: newX, y: newY, rotate, visible: true, locked: LockState.None };
}
});
//
const positionUpdates = updates
.map(({ id, data }) => {
const { x, y, angle } = data;
// xy angle / false
if (isNil(x) && isNil(y) && angle == null) {
return undefined;
}
const payload: any = { id };
if (!isNil(x) && !isNil(y)) {
const newX = x - 60;
const newY = y - 60;
payload.x = newX;
payload.y = newY;
payload.visible = true;
payload.locked = LockState.None;
}
if (angle != null) {
// angle
payload.rotate = -angle + 180;
}
return payload;
})
.filter((v) => v);
// 使Meta2D
positionUpdates.forEach((update) => {