|
|
|
@ -66,18 +66,20 @@ export default class DragControl2 implements IControls { |
|
|
|
* 清理拖拽状态 |
|
|
|
*/ |
|
|
|
private cleanupDrag(): void { |
|
|
|
this.viewport.renderer.domElement.style.cursor = 'auto' |
|
|
|
this.isDragging = false |
|
|
|
this.isPointerDown = false |
|
|
|
this.dragStartMouse.set(NaN, NaN) |
|
|
|
this.removeShadows() |
|
|
|
if (this.domElement) { |
|
|
|
this.domElement.style.cursor = 'auto' |
|
|
|
this.isDragging = false |
|
|
|
this.isPointerDown = false |
|
|
|
this.dragStartMouse.set(NaN, NaN) |
|
|
|
this.removeShadows() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 获取当前鼠标坐标(归一化设备坐标) |
|
|
|
*/ |
|
|
|
private getMousePosition(clientX: number, clientY: number): THREE.Vector2 { |
|
|
|
const rect = this.viewport.renderer.domElement.getBoundingClientRect() |
|
|
|
const rect = this.domElement.getBoundingClientRect() |
|
|
|
return new THREE.Vector2( |
|
|
|
((clientX - rect.left) / rect.width) * 2 - 1, |
|
|
|
((clientY - rect.top) / rect.height) * -2 + 1 |
|
|
|
@ -187,12 +189,12 @@ export default class DragControl2 implements IControls { |
|
|
|
* pointermove 事件处理 |
|
|
|
*/ |
|
|
|
private onPointerMove = (event: PointerEvent): void => { |
|
|
|
if (!this.enabled) return |
|
|
|
if (!this.enabled || !this.domElement) return |
|
|
|
|
|
|
|
if (!isNaN(this.dragStartMouse.x) && !isNaN(this.dragStartMouse.y) && this.dragShadows) { |
|
|
|
this.isDragging = true |
|
|
|
// 更新鼠标样式
|
|
|
|
this.viewport.renderer.domElement.style.cursor = 'grabbing' |
|
|
|
this.domElement.style.cursor = 'grabbing' |
|
|
|
|
|
|
|
// 更新阴影位置(锁定 Y 轴)
|
|
|
|
this.updateShadows(new THREE.Vector2(CurrentMouseInfo.x, CurrentMouseInfo.z)) |
|
|
|
@ -202,9 +204,9 @@ export default class DragControl2 implements IControls { |
|
|
|
const mouse = this.getMousePosition(event.clientX, event.clientY) |
|
|
|
const intersected = this.getIntersectedDraggableObject(mouse) |
|
|
|
if (intersected) { |
|
|
|
this.viewport.renderer.domElement.style.cursor = 'grab' |
|
|
|
this.domElement.style.cursor = 'grab' |
|
|
|
} else { |
|
|
|
this.viewport.renderer.domElement.style.cursor = 'auto' |
|
|
|
this.domElement.style.cursor = 'auto' |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -269,9 +271,10 @@ export default class DragControl2 implements IControls { |
|
|
|
* 取消当前拖拽状态 |
|
|
|
*/ |
|
|
|
cancelDrag(): void { |
|
|
|
if (!this.domElement) return |
|
|
|
if (this.isDragging || this.isPointerDown) { |
|
|
|
this.cleanupDrag() |
|
|
|
this.viewport.renderer.domElement.style.cursor = 'auto' |
|
|
|
this.domElement.style.cursor = 'auto' |
|
|
|
this.viewport.controls.enabled = true |
|
|
|
} |
|
|
|
} |
|
|
|
|