Browse Source

EsDragControl2 拖拽管理器完成

master
修宁 6 months ago
parent
commit
5945edd41f
  1. 25
      src/core/controls/EsDragControl2.ts

25
src/core/controls/EsDragControl2.ts

@ -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
}
}

Loading…
Cancel
Save