Parcourir la source

Add time, distance threshold to ObjectPicker for click

master
Palash Bansal il y a 2 ans
Parent
révision
199edba6b1
Aucun compte lié à l'adresse e-mail de l'auteur
1 fichiers modifiés avec 12 ajouts et 1 suppressions
  1. 12
    1
      src/three/utils/ObjectPicker.ts

+ 12
- 1
src/three/utils/ObjectPicker.ts Voir le fichier

private _firstHit: IObject3D | undefined private _firstHit: IObject3D | undefined


hoverEnabled = false hoverEnabled = false
/**
* Time threshold for a pointer click event
*/
static PointerClickMaxTime = 200
/**
* Distance threshold for a pointer click event
*/
static PointerClickMaxDistance = 0.1 // 1/20 of the canvas


private _root: IObject3D private _root: IObject3D
private _camera: ICamera private _camera: ICamera
private _mouseDownTime: number private _mouseDownTime: number
private _mouseDownPos: Vector2 = new Vector2()
private _mouseUpTime: number private _mouseUpTime: number
private _time: number private _time: number
public selectionCondition: (o: IObject3D) => boolean public selectionCondition: (o: IObject3D) => boolean
this.domElement.style.cursor = this.cursorStyles.down this.domElement.style.cursor = this.cursorStyles.down


this._mouseDownTime = this.time this._mouseDownTime = this.time
this._mouseDownPos.copy(this.mouse)


return undefined return undefined
} }


this._mouseUpTime = this.time this._mouseUpTime = this.time
const delta = this.mouseDownDeltaTime const delta = this.mouseDownDeltaTime
if (delta < 200) {
const dist = this._mouseDownPos.distanceTo(this.mouse)
if (delta < ObjectPicker.PointerClickMaxTime && dist < ObjectPicker.PointerClickMaxDistance) {
// click // click
this._onPointerClick(event) this._onPointerClick(event)
} }

Chargement…
Annuler
Enregistrer