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 _knownEntities

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

Private _serializedFrameState

_serializedFrameState: FrameState

Private _updatingEntities

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

defaultReferenceFrame

defaultReferenceFrame: any = 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: any = 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.

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.localENU',name: 'localOriginENU',position: new ConstantPositionProperty(undefined, ReferenceFrame.FIXED),orientation: new ConstantProperty(Quaternion.IDENTITY)}))

An entity positioned near the user, aligned with the local East-North-Up coordinate system.

localOriginEastUpSouth

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

An entity positioned near the user, aligned with the East-Up-South coordinate system. This useful for converting to the Y-Up convention used in some libraries, such as three.js.

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

time

time: any = 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.

Accessors

serializedFrameState

  • The serialized frame state for this frame

    Returns FrameState

Private systemTime

  • get systemTime(): number
  • Deprecated. Use timestamp property.

    Returns number

user

  • get user(): any
  • An alias for the 'eye' entity. To be deprecated in favor of ViewService.eye.

    Returns any

Methods

Private _update

  • Parameters

    Returns void

Private _updateLocalOrigin

  • Parameters

    Returns void

Private _updateStage

  • Parameters

    Returns void

createFrameState

  • createFrameState(time: JulianDate, viewport: Viewport, subviewList: SerializedSubviewList, eye: Entity, horizontalAccuracy?: number, verticalAccuracy?: number, headingAccuracy?: number): FrameState
  • Parameters

    • time: JulianDate
    • viewport: Viewport
    • subviewList: SerializedSubviewList
    • eye: Entity
    • Optional horizontalAccuracy: number
    • Optional verticalAccuracy: number
    • Optional headingAccuracy: number

    Returns FrameState

Private getDefaultReferenceFrame

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

    Returns Entity

getEntityPose

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

    Parameters

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

    Returns EntityPose

    If the position and orientation exist for the given entity, an object with the fields position and orientation, both of type Cartesian3. Otherwise undefined.

Private getTime

  • getTime(): JulianDate
  • Deprecated. To be removed.

    Returns 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): Promise<Entity>
  • Subscribe to pose updates for the given entity id

    Parameters

    • id: string | Entity

      the id of the desired entity

    Returns Promise<Entity>

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

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): void
  • Unsubscribe to pose updates for the given entity id

    Parameters

    • id: string | Entity

    Returns void

updateEntityFromSerializedPose

  • Parameters

    Returns any

Object literals

_scratchFrameState

_scratchFrameState: object

entities

entities: object

Type declaration

    subviews

    subviews: Array<undefined> = []

    time

    time: any = <any>{}

    viewport

    viewport: any = <any>{}

    Generated using TypeDoc