Explorar el Código

Wait for next frame before unselecting object in PickingPlugin

master
Palash Bansal hace 11 meses
padre
commit
9f159b77e6
No account linked to committer's email address
Se han modificado 1 ficheros con 18 adiciones y 1 borrados
  1. 18
    1
      src/plugins/interaction/PickingPlugin.ts

+ 18
- 1
src/plugins/interaction/PickingPlugin.ts Ver fichero

@@ -189,16 +189,33 @@ export class PickingPlugin extends AViewerPluginSync<PickingPluginEventMap> {
if (!this._picker || !this._viewer) return
this._picker.camera = this._viewer.scene.mainCamera
}

private _sceneUpdated = false
private _onSceneUpdate: EventListener2<'sceneUpdate', ISceneEventMap, IScene> = (e)=>{
if (!e.hierarchyChanged) return
this._sceneUpdated = true
}

private _checkSelectedInScene() {
if (this.isDisabled()) return
const s = this.getSelectedObject()
let inScene = false
s?.traverseAncestors((o)=>{
s?.traverseAncestors((o) => {
if (o === this._viewer?.scene) inScene = true
})
if (!inScene) this.setSelectedObject(undefined)
}

protected _viewerListeners = {
preFrame: ()=>{
if (!this._viewer || !this._picker) return
if (this._sceneUpdated) {
this._checkSelectedInScene()
this._sceneUpdated = false
}
},
}

private _onObjectSelectEvent: EventListener2<'select', ISceneEventMap, IScene> = (e)=>{
if (e.source === PickingPlugin.PluginType) return
if (e.object === undefined && e.value === undefined) console.error('e.object or e.value must be set for picking, can be null to unselect')

Cargando…
Cancelar
Guardar