import { Camera , World } from '@antv/g-webgpu' ; import { ICamera , IDENTIFIER , IInteractorEvent , IRendererService , IView , Ray , RendererSystem , } from '@antv/g-webgpu-core' ; import EventEmitter from 'eventemitter3' ; import { mat4 , vec3 } from 'gl-matrix' ; import { Container } from 'inversify' ; import { InteractorService } from './InteractorService' ; see https export class RayPicker extends EventEmitter { public static create ( world ) { const picker = new RayPicker ( ) ; const worldContainer = world . getContainer ( ) ; worldContainer . rebind ( IDENTIFIER . InteractorService ) . to ( InteractorService ) . inSingletonScope ( ) ; picker . container = worldContainer ; return picker ; } public container : Container ; private ray : Ray ; public attachControl ( view ) { const engine = this . container . get < IRendererService > ( IDENTIFIER . RenderEngine ) ; const interactor = this . container . get < InteractorService > ( IDENTIFIER . InteractorService ) ; interactor . listen ( engine . getCanvas ( ) ) ; const rendererSystem = this . container . getNamed < RendererSystem > ( IDENTIFIER . Systems , IDENTIFIER . RendererSystem ) ; interactor . on ( IInteractorEvent . HOVER , ( center ) => { this . setFromCamera ( view . getCamera ( ) , center ) ; } ) ; return this ; } private setFromCamera ( camera , { x , y } ) { const projectionMode = camera . getProjectionMode ( ) ; if ( projectionMode === Camera . ProjectionMode . PERSPECTIVE ) { this . ray . origin = camera . getPosition ( ) ; vec3 . copy ( this . ray . direction , [ x , y , 0.5 ] ) ; vec3 . transformMat4 ( ) ; } else if ( projectionMode === Camera . ProjectionMode . ORTHOGRAPHIC ) { } } }