feat: 优化位置和可见性批量设置逻辑,仅在提供坐标或角度时更新,提升渲染效率和可读性
This commit is contained in:
parent
5d56362848
commit
ac3b380f31
@ -148,19 +148,30 @@ const monitorScene = async () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// 批量设置位置和可见性,只渲染一次
|
// 批量设置位置和可见性(仅在提供坐标时更新)
|
||||||
const positionUpdates = updates.map(({ id, data }) => {
|
const positionUpdates = updates
|
||||||
|
.map(({ id, data }) => {
|
||||||
const { x, y, angle } = data;
|
const { x, y, angle } = data;
|
||||||
if (isNil(x) || isNil(y)) {
|
// 仅当提供 x、y 或 angle 时才更新位置/角度,避免因缺省数据误将可见性设为 false
|
||||||
return { id, visible: false };
|
if (isNil(x) && isNil(y) && angle == null) {
|
||||||
} else {
|
return undefined;
|
||||||
|
}
|
||||||
|
const payload: any = { id };
|
||||||
|
if (!isNil(x) && !isNil(y)) {
|
||||||
const newX = x - 60;
|
const newX = x - 60;
|
||||||
const newY = y - 60;
|
const newY = y - 60;
|
||||||
// 后端 angle 为逆时针,把转换改为“先取反再加偏移”:
|
payload.x = newX;
|
||||||
const rotate = angle == null ? undefined : -angle + 180;
|
payload.y = newY;
|
||||||
return { id, x: newX, y: newY, rotate, visible: true, locked: LockState.None };
|
payload.visible = true;
|
||||||
|
payload.locked = LockState.None;
|
||||||
}
|
}
|
||||||
});
|
if (angle != null) {
|
||||||
|
// 后端 angle 为逆时针,把转换改为“先取反再加偏移”
|
||||||
|
payload.rotate = -angle + 180;
|
||||||
|
}
|
||||||
|
return payload;
|
||||||
|
})
|
||||||
|
.filter((v) => v);
|
||||||
|
|
||||||
// 使用Meta2D的批量更新方法,减少渲染调用
|
// 使用Meta2D的批量更新方法,减少渲染调用
|
||||||
positionUpdates.forEach((update) => {
|
positionUpdates.forEach((update) => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user