Options
All
  • Public
  • Public/Protected
  • All
Menu

Class ContextService

Provides a means of querying the current state of reality.

This class adds the following message handlers to any sessions managed by the session service:

  • ar.context.subscribe - Subscribes the session to updates from an entity with the provided id.
    • Parameters:
      • id: string - The id of an entity the session wishes to recieve updates on.

This service sends the following messages to managed sessions

  • ar.context.update - Indicates to this context that the session wants to be focused on.

Hierarchy

  • ContextService

Index

Constructors

constructor

Properties

Private _entityPoseMap

_entityPoseMap: Map<string, EntityPose> = new Map<string, EntityPose | undefined>()

Private _frameIndex

_frameIndex: number = -1

Private _getEntityPositionInReferenceFrame

_getEntityPositionInReferenceFrame: getEntityPositionInReferenceFrame = getEntityPositionInReferenceFrame

Private _knownEntities

_knownEntities: Set<string> = new Set<string>()

Private _scratchCartesian

_scratchCartesian: Cartesian3 = new Cartesian3

Private _scratchFrustum

_scratchFrustum: PerspectiveFrustum = new PerspectiveFrustum()

Private _scratchMatrix3

_scratchMatrix3: Matrix3 = new Matrix3

Private _scratchMatrix4

_scratchMatrix4: Matrix4 = new Matrix4

Private _scratchQuaternion

_scratchQuaternion: Quaternion = new Quaternion

Private _serializedFrameState

_serializedFrameState: FrameState

Private _updatingEntities

_updatingEntities: Set<string> = new Set<string>()

defaultReferenceFrame

defaultReferenceFrame: Entity = this.localOriginEastNorthUp

The default origin to use when calling getEntityPose. By default, this is the localOriginEastNorthUp reference frame.

deltaTime

deltaTime: number = 0

The time in milliseconds since the previous timestamp, capped to ContextService.maxDeltaTime

entities

entities: EntityCollection = new EntityCollection()

The collection of all entities this application is aware of.

frameStateEvent

frameStateEvent: Event<FrameState> = new Event<FrameState>()

An event that is raised when the next frame state is available.

ground

ground: Entity = this.entities.add(new Entity({id: 'ar.ground',name: 'Ground',position: new ConstantPositionProperty(Cartesian3.ZERO, this.stage),orientation: new ConstantProperty(Quaternion.IDENTITY)}))

An entity representing a ground-level plane below the user

localOrigin

localOrigin: Entity = this.entities.add(new Entity({id: 'ar.localOrigin',name: 'Local Origin (ENU)',position: new ConstantPositionProperty(undefined, undefined),orientation: new ConstantProperty(Quaternion.IDENTITY)}))

An entity representing the local origin, which is oriented East-North-Up if geolocation is known, otherwise an arbitrary frame with +Z up

localOriginChangeEvent

localOriginChangeEvent: Event<void> = new Event<void>()

An event that fires when the local origin changes.

localOriginEastNorthUp

localOriginEastNorthUp: Entity = this.entities.add(new Entity({id: 'ar.localOriginENU',name: 'Local Origin (ENU)',position: new ConstantPositionProperty(Cartesian3.ZERO, this.localOrigin),orientation: new ConstantProperty(Quaternion.IDENTITY)}))

Alias for localOrigin. An entity representing the local origin, which is oriented East-North-Up if geolocation is known, otherwise an arbitrary frame with +Z up

localOriginEastUpSouth

localOriginEastUpSouth: Entity = this.entities.add(new Entity({id: 'ar.localOriginEUS',name: 'Local Origin (EUS)',position: new ConstantPositionProperty(Cartesian3.ZERO, this.localOriginEastNorthUp),orientation: new ConstantProperty(Quaternion.fromAxisAngle(Cartesian3.UNIT_X, Math.PI / 2))}))

An entity representing the same origin as localOriginEastNorthUp, but rotated 90deg around X-axis to create an East-Up-South coordinate system. Useful for maintaining a scene-graph where +Y is up.

maxDeltaTime

maxDeltaTime: number = 1 / 3 * 1000

This value caps the deltaTime for each frame. By default, the value is 1/3s (333.3ms)

postRenderEvent

postRenderEvent: Event<ContextService> = new Event<ContextService>()

An event that is raised after the render event

renderEvent

renderEvent: Event<ContextService> = new Event<ContextService>()

An event that is raised when it is an approriate time to render graphics. This event fires after the update event.

Private sessionService

sessionService: SessionService

stage

stage: Entity = this.entities.add(new Entity({id: 'ar.stage',name: 'Stage',position: new ConstantPositionProperty(undefined, undefined),orientation: new ConstantProperty(Quaternion.IDENTITY)}))

An entity representing the physical floor-level plane below the user

time

time: JulianDate = new JulianDate(0,0)

The current (absolute) time according to the current reality. This value is arbitrary until the first ContextService.updateEvent.

timestamp

timestamp: number = -1

A monotonically increasing value (in milliseconds) for the current frame state. This value is useful only for doing accurate timing, not for determining the absolute time. Use ContextService.time for absolute time. This value is -1 until the first ContextService.updateEvent.

updateEvent

updateEvent: Event<ContextService> = new Event<ContextService>()

An event that is raised after managed entities have been updated for the current frame.

user

user: Entity = this.entities.add(new Entity({id: 'ar.user',name: 'User',position: new ConstantPositionProperty(undefined, undefined),orientation: new ConstantProperty(Quaternion.IDENTITY)}))

An entity representing the user.

Accessors

geoHeadingAccuracy

  • get geoHeadingAccuracy(): number | undefined

geoHorizontalAccuracy

  • get geoHorizontalAccuracy(): number | undefined

geoVerticalAccuracy

  • get geoVerticalAccuracy(): number | undefined

geoposeHeadingAccuracy

  • get geoposeHeadingAccuracy(): number | undefined

geoposeHorizontalAccuracy

  • get geoposeHorizontalAccuracy(): number | undefined

geoposeVerticalAccuracy

  • get geoposeVerticalAccuracy(): number | undefined

serializedFrameState

Private systemTime

  • get systemTime(): number

Methods

Private _update

Private _updateBackwardsCompatability

  • _updateBackwardsCompatability(frameState: FrameState): void

createEntityPose

  • createEntityPose(entityOrId: Entity | string, referenceFrameOrId?: string | ReferenceFrame | Entity): EntityPose
  • Create a new EntityPose instance to represent the pose of an entity relative to a given reference frame. If no reference frame is specified, then the pose is based on the context's defaultReferenceFrame.

    Parameters

    • entityOrId: Entity | string
    • Optional referenceFrameOrId: string | ReferenceFrame | Entity

      the reference frame to use

    Returns EntityPose

Private getDefaultReferenceFrame

  • getDefaultReferenceFrame(): Entity
  • Deprecated. To be removed. Use the defaultReferenceFrame property.

    Returns Entity

getEntityCartographic

  • getEntityCartographic(entity?: Entity, cartographic?: Cartographic): Cartographic | undefined
  • Get the cartographic position of an Entity

    Parameters

    • Optional entity: Entity
    • Optional cartographic: Cartographic

    Returns Cartographic | undefined

getEntityPose

  • getEntityPose(entityOrId: Entity | string, referenceFrameOrId?: string | ReferenceFrame | Entity): EntityPose
  • Gets the current pose of an entity, relative to a given reference frame.

    deprecated

    Parameters

    • entityOrId: Entity | string
    • Default value referenceFrameOrId: string | ReferenceFrame | Entity = this.defaultReferenceFrame

    Returns EntityPose

getSubviewEntity

  • getSubviewEntity(index: number): Entity

Private getTime

  • getTime(): JulianDate

Private setDefaultReferenceFrame

  • setDefaultReferenceFrame(origin: Entity): void
  • Deprecated. To be removed. Use the defaultReferenceFrame property.

    Parameters

    • origin: Entity

    Returns void

submitFrameState

  • Process the next frame state (which should come from the current reality viewer)

    Parameters

    Returns void

subscribe

  • subscribe(id: string | Entity, session?: SessionPort): Promise<Entity>
  • Subscribe to pose updates for the given entity id

    Parameters

    • id: string | Entity
    • Default value session: SessionPort = this.sessionService.manager

    Returns Promise<Entity>

    A Promise that resolves to a new or existing entity instance matching the given id, if the subscription is successful

subscribeGeolocation

subscribeToEntityById

  • subscribeToEntityById(id: string): Entity
  • Subscribe to pose updates for an entity specified by the given id

    deprecated

    Use [[ContextService#subscribe]]

    Parameters

    • id: string

      the id of the desired entity

    Returns Entity

    A new or existing entity instance matching the given id

unsubscribe

  • unsubscribe(id: string | Entity, session?: SessionPort): void
  • Unsubscribe to pose updates for the given entity id

    Parameters

    • id: string | Entity
    • Default value session: SessionPort = this.sessionService.manager

    Returns void

unsubscribeGeolocation

  • unsubscribeGeolocation(): void

updateEntityFromSerializedState

Generated using TypeDoc