修复bug
This commit is contained in:
@ -114,37 +114,73 @@ export class AppModelDrag extends Monobehiver {
|
||||
// 使用世界坐标系而不是物体本地坐标系
|
||||
pointerDragBehavior.useObjectOrientationForDragging = false;
|
||||
|
||||
// 记录拖拽起始位置和状态
|
||||
let dragStartPosition: Vector3 | null = null;
|
||||
let hasShownZones = false; // 是否已显示分割区域
|
||||
|
||||
// 监听拖拽开始事件
|
||||
pointerDragBehavior.onDragStartObservable.add(() => {
|
||||
// 记录起始位置
|
||||
const meshes = this.mainApp.appModel?.modelDic?.Get(modelId);
|
||||
if (meshes && meshes.length > 0) {
|
||||
dragStartPosition = meshes[0].position.clone();
|
||||
}
|
||||
|
||||
// 禁用相机控制
|
||||
this.disableCameraControl();
|
||||
|
||||
// 如果启用了拖拽吸附,显示分割区域
|
||||
if (dragInfo.config.snapToZone) {
|
||||
this.showZonesForModel(modelId);
|
||||
// 不在这里显示分割区域,等到实际拖动时再显示
|
||||
hasShownZones = false;
|
||||
});
|
||||
|
||||
// 监听拖拽中事件(用于边界限制和延迟显示分割区域)
|
||||
pointerDragBehavior.onDragObservable.add((event) => {
|
||||
// 检查是否实际移动了
|
||||
const meshes = this.mainApp.appModel?.modelDic?.Get(modelId);
|
||||
if (meshes && meshes.length > 0 && dragStartPosition) {
|
||||
const distance = Vector3.Distance(dragStartPosition, meshes[0].position);
|
||||
|
||||
// 如果移动距离超过阈值且还没显示分割区域,则显示
|
||||
if (distance > 0.01 && !hasShownZones && dragInfo.config.snapToZone) {
|
||||
this.showZonesForModel(modelId);
|
||||
hasShownZones = true;
|
||||
}
|
||||
}
|
||||
|
||||
// 应用边界限制
|
||||
if (dragInfo.config.boundaryConstraint) {
|
||||
this.applyBoundaryConstraint(modelId, event.dragPlanePoint);
|
||||
}
|
||||
});
|
||||
|
||||
// 监听拖拽中事件(用于边界限制)
|
||||
if (dragInfo.config.boundaryConstraint) {
|
||||
pointerDragBehavior.onDragObservable.add((event) => {
|
||||
this.applyBoundaryConstraint(modelId, event.dragPlanePoint);
|
||||
});
|
||||
}
|
||||
|
||||
// 监听拖拽结束事件
|
||||
pointerDragBehavior.onDragEndObservable.add(() => {
|
||||
// 检查是否实际移动了
|
||||
const meshes = this.mainApp.appModel?.modelDic?.Get(modelId);
|
||||
let hasMoved = false;
|
||||
if (meshes && meshes.length > 0 && dragStartPosition) {
|
||||
const distance = Vector3.Distance(dragStartPosition, meshes[0].position);
|
||||
hasMoved = distance > 0.01; // 移动距离大于 0.01 才算拖拽
|
||||
}
|
||||
|
||||
// 恢复相机控制
|
||||
this.enableCameraControl();
|
||||
|
||||
// 如果启用了拖拽吸附,隐藏分割区域并吸附到最近区域
|
||||
if (dragInfo.config.snapToZone) {
|
||||
this.hideZonesForModel(modelId);
|
||||
this.snapModelToZone(modelId);
|
||||
} else {
|
||||
// 否则只更新映射关系
|
||||
this.updateModelZoneMapping(modelId);
|
||||
// 只有在实际移动的情况下才执行拖拽逻辑
|
||||
if (hasMoved) {
|
||||
// 如果启用了拖拽吸附,隐藏分割区域并吸附到最近区域
|
||||
if (dragInfo.config.snapToZone && hasShownZones) {
|
||||
this.hideZonesForModel(modelId);
|
||||
this.snapModelToZone(modelId);
|
||||
} else {
|
||||
// 否则只更新映射关系
|
||||
this.updateModelZoneMapping(modelId);
|
||||
}
|
||||
}
|
||||
|
||||
// 清除状态
|
||||
dragStartPosition = null;
|
||||
hasShownZones = false;
|
||||
});
|
||||
|
||||
return pointerDragBehavior;
|
||||
|
||||
Reference in New Issue
Block a user