import { GeometryKind , Pickability , Technique } from "@here/harp-datasource-protocol" ; import * as THREE from "three" ; import { DataSource } from "./DataSource" ; import { MapAdapterUpdateEnv , MapMaterialAdapter } from "./MapMaterialAdapter" ; hidden export interface MapObjectAdapterParams { dataSource ? : DataSource ; technique ? : Technique ; kind ? : GeometryKind [ ] ; level ? : number ; pickability ? : Pickability ; } hidden MapView specific data assigned to `THREE.Object3D` instance in installed in `userData`.
 *
 * `MapObjectAdapter` is registered in `usedData.mapAdapter` property of `THREE.Object3D`.
  export class MapObjectAdapter { /**
     * Resolve `MapObjectAdapter` associated with `object`.
     */ static get ( object ) { return object . userData ?. mapAdapter instanceof MapObjectAdapter ? object . userData . mapAdapter : undefined ; } static install ( objData ) { if ( ! objData . object . userData ) { objData . object . userData = { } ; } return ( objData . object . userData . mapAdapter = objData ) ; } static create ( object , params ) { return MapObjectAdapter . install ( new MapObjectAdapter ( object , params ) ) ; } static ensureUpdated ( object , context ) { return MapObjectAdapter . get ( object ) ?. ensureUpdated ( context ) ?? false ; } /**
     * Associated scene object.
     */ readonly object : THREE . Object3D ; /**
     * [[Technique]] that constituted this object.
     */ readonly technique ? : Technique ; /**
     * [[GeometryKind]] of `object`.
     */ readonly kind : GeometryKind [ ] | undefined ; readonly dataSource ? : DataSource ; /**
     * Which level this object exists on, must match the TileKey's level.
     */ readonly level : number | undefined ; private readonly m_pickability : Pickability ; private m_lastUpdateFrameNumber = - 1 ; private m_notCompletlyTransparent = true ; constructor ( object , params ) { this . object = object ; this . technique = params . technique ; this . kind = params . kind ; this . dataSource = params . dataSource ; this . m_pickability = params . pickability ?? Pickability . onlyVisible ; this . m_notCompletlyTransparent = this . getObjectMaterials ( ) . some ( material => material . opacity > 0 ) ; this . level = params . level ; } /**
     * Serialize contents.
     *
     * `THREE.Object3d.userData` is serialized during `clone`/`toJSON`, so we need to ensure that
     * we emit only "data" set of this object.
     */ toJSON ( ) { return { kind : this . kind , technique : this . technique } ; } /**
     * Ensure that underlying object is updated to current state of  MapView .
     *
     * Updates object and attachments like materials to current state by evaluating scene dependent
     * expressions.
     *
     * Executes updates only once per frame basing on [[MapView.frameNumber]].
     *
     * Delegates updates of materials to [[MapMaterialAdapter.ensureUpdated]].
     *
     *  returns ensureUpdated ( context ) { if ( this . m_lastUpdateFrameNumber === context . frameNumber ) { return false ; } this . m_lastUpdateFrameNumber = context . frameNumber ; return this . updateMaterials ( context ) ; } /**
     * Whether underlying `THREE.Object3D` is actually visible in scene.
     */ isVisible ( ) { return this . object . visible && this . m_notCompletlyTransparent ; } /**
     * Whether underlying `THREE.Object3D` should be pickable by  PickHandler .
      isPickable ( ) { return ( ( this . pickability === Pickability . onlyVisible && this . isVisible ( ) ) || this . m_pickability === Pickability . all ) ; } get pickability ( ) : Pickability { return this . m_pickability ; } private updateMaterials ( context ) { let somethingChanged = false ; const materials = this . getObjectMaterials ( ) ; for ( const material of materials ) { const changed = MapMaterialAdapter . ensureUpdated ( material , context ) ; somethingChanged = somethingChanged || changed ; } if ( somethingChanged ) { this . m_notCompletlyTransparent = materials . some ( material => material . opacity > 0 ) ; } return somethingChanged ; } private getObjectMaterials ( ) { const object = this . object as THREE . Mesh ; return Array . isArray ( object . material ) ? object . material : object . material !== undefined ? [ object . material ] : [ ] ; } }