Class Entity3D<TEventMap>

Base class for entities that display 3D objects.

Subclasses must call onObjectCreated when creating new Object3D, before adding them to the scene

Type Parameters

Hierarchy

Constructors

  • Creates a Entity3D with the specified parameters.

    Type Parameters

    Parameters

    • id: string

      the unique identifier of this entity

    • object3d: Object3D<Object3DEventMap>

      the root Three.js of this entity

    Returns Entity3D<TEventMap>

Properties

_attachedLayers: Layer<LayerEvents>[]
_clippingPlanes: Plane[]
_distance: {
    max: number;
    min: number;
}

Type declaration

  • max: number
  • min: number
_instance: Instance
_object3d: Object3D<Object3DEventMap>
_opacity: number
_renderOrder: number
_visible: boolean
isEntity: boolean = true

Read-only flag to check if a given object is of type Entity.

isEntity3D: boolean = true

Read-only flag to check if a given object is of type Entity3D.

type: string

The name of the type of this object.

Accessors

  • get clippingPlanes(): Plane[]
  • Gets or sets the clipping planes set on this entity. Default is null (no clipping planes).

    Note: custom entities must ensure that the materials and shaders used do support the clipping plane feature of three.js. Refer to the three.js documentation for more information.

    Returns Plane[]

    Fires

    Entity3D#clippingPlanes-property-changed

  • set clippingPlanes(planes): void
  • Parameters

    • planes: Plane[]

    Returns void

  • get frozen(): boolean
  • Gets or sets the frozen status of this entity. A frozen entity is still visible but will not be updated automatically.

    Useful for debugging purposes.

    Returns boolean

  • set frozen(v): void
  • Parameters

    • v: boolean

    Returns void

  • get id(): string
  • Gets the unique identifier of this entity.

    Returns string

  • get loading(): boolean
  • Gets whether this entity is currently loading data.

    Returns boolean

  • get object3d(): Object3D<Object3DEventMap>
  • Returns the root object of this entity.

    Returns Object3D<Object3DEventMap>

  • get opacity(): number
  • Gets or sets the opacity of this entity.

    Returns number

    Fires

    Entity3D#opacity-property-changed

  • set opacity(v): void
  • Parameters

    • v: number

    Returns void

  • get progress(): number
  • Gets the current loading progress (between 0 and 1). Note: This property is only meaningful if loading is true.

    Returns number

  • get renderOrder(): number
  • Gets or sets the render order of this entity.

    Returns number

    Fires

    Entity3D#renderOrder-property-changed

  • set renderOrder(v): void
  • Parameters

    • v: number

    Returns void

  • get visible(): boolean
  • Gets or sets the visibility of this entity. A non-visible entity will not be automatically updated.

    Returns boolean

    Fires

    Entity3D#visible-property-changed

  • set visible(v): void
  • Parameters

    • v: boolean

    Returns void

Methods

  • Adds a listener to an event type.

    Type Parameters

    • T extends string

    Parameters

    • type: T

      The type of event to listen to.

    • listener: EventListener<(TEventMap & Entity3DEventMap & EntityEventMap)[T], T, Entity3D<TEventMap>>

      The function that gets called when the event is fired.

    Returns void

  • Type Parameters

    • T extends string

    Parameters

    • type: T
    • listener: EventListener<{}, T, Entity3D<TEventMap>>

    Returns void

  • Parameters

    Returns void

  • Test whether this entity contains the given object.

    The object may be a component of the entity, or a 3D object.

    Parameters

    • obj: unknown

      The object to test.

    Returns boolean

    true if the entity contains the object.

  • Parameters

    Returns boolean

  • Fire an event type.

    Type Parameters

    • T extends string

    Parameters

    Returns void

  • Disposes this entity and all resources associated with it.

    The default implementation of this method does nothing. You should implement it in your custom entities to handle any special logic of disposal.

    For example: disposing materials, geometries, stopping HTTP requests, etc.

    Returns void

  • Returns an approximated bounding box of this entity in the scene.

    Returns Box3

    the resulting bounding box, or null if it could not be computed.

  • Get all the layers attached to this object.

    Parameters

    • filter: ((arg0) => boolean)

      Optional filter function for attached layers

    Returns Layer<LayerEvents>[]

    the layers attached to this object

  • Attached layers expect to receive the visual representation of a layer (= THREE object with a material). So if a layer's update function don't process this kind of object, the layer must provide a getObjectToUpdateForAttachedLayers function that returns the correct object to update for attached layer from the objects returned by preUpdate.

    Parameters

    • obj: Mesh<BufferGeometry<NormalBufferAttributes>, Material | Material[], Object3DEventMap>

      the Mesh or the object containing a Mesh. These are the objects returned by preUpdate or update.

    Returns {
        element: Mesh<BufferGeometry<NormalBufferAttributes>, Material | Material[], Object3DEventMap>;
        parent: Object3D<Object3DEventMap>;
    }

    an object passed to the update function of attached layers.

    • element: Mesh<BufferGeometry<NormalBufferAttributes>, Material | Material[], Object3DEventMap>
    • parent: Object3D<Object3DEventMap>
  • Checks if listener is added to an event type.

    Type Parameters

    • T extends string

    Parameters

    • type: T

      The type of event to listen to.

    • listener: EventListener<(TEventMap & Entity3DEventMap & EntityEventMap)[T], T, Entity3D<TEventMap>>

      The function that gets called when the event is fired.

    Returns boolean

  • Type Parameters

    • T extends string

    Parameters

    • type: T
    • listener: EventListener<{}, T, Entity3D<TEventMap>>

    Returns boolean

  • Applies entity-level setup on a new object.

    Note: this method should be called from the subclassed entity to notify the parent class that a new 3D object has just been created, so that it can be setup with entity-wide parameters.

    Parameters

    • obj: Object3D<Object3DEventMap>

      The object to prepare.

    Returns void

    Example

    // In the subclass
    const obj = new Object3D();

    // Notify the parent class
    this.onObjectCreated(obj);
  • Picks objects given a position and a radius from the layer.

    Parameters

    • coordinates: any

      The x/y position in the layer

    • Optional options: any

      Optional properties. See Instance.pickObjectsAt

    • Optional target: any

      Target array to fill

    Returns any[]

    Picked objects (node)

  • Method called after update().

    Returns void

  • This method is called just before update() to filter and select which elements should be actually updated. For example, in the case of complex entities made of a hierarchy of elements, the entire hierarchy may not need to be updated.

    Use this method to optimize the update step by reducing the number of elements to process.

    Note: if this functions returns nothing, update() will not be called.

    Parameters

    • context: Context

      the update context.

    • changeSources: Set<unknown>

      the objects that triggered an update step. This is useful to filter out unnecessary updates if no sources are relevant to this entity. For example, if one of the sources is a camera that moved during the previous frame, any entity that depends on the camera's field of view should be updated.

    Returns unknown[]

    the elements to update during update().

  • Asynchronously preprocess the entity. This method may be overriden to perform any operation that must be done before the entity can be used in the scene, such as fetching metadata about a dataset, etc.

    Returns Promise<void>

    A promise that resolves when the entity is ready to be used.

  • Removes a listener from an event type.

    Type Parameters

    • T extends string

    Parameters

    • type: T

      The type of the listener that gets removed.

    • listener: EventListener<(TEventMap & Entity3DEventMap & EntityEventMap)[T], T, Entity3D<TEventMap>>

      The listener function that gets removed.

    Returns void

  • Type Parameters

    • T extends string

    Parameters

    • type: T
    • listener: EventListener<{}, T, Entity3D<TEventMap>>

    Returns void

  • Traverses all objects in the hierarchy of this entity.

    Parameters

    • callback: ((arg0) => void)

      The callback.

        • (arg0): void
        • Parameters

          • arg0: Object3D<Object3DEventMap>

          Returns void

    • root: Object3D<Object3DEventMap> = undefined

      The traversal root. If undefined, the traversal starts at the root object of this entity.

    Returns void

  • Traverses all materials in the hierarchy of this entity.

    Parameters

    • callback: ((arg0) => void)

      The callback.

        • (arg0): void
        • Parameters

          • arg0: Material

          Returns void

    • root: Object3D<Object3DEventMap> = undefined

      The traversal root. If undefined, the traversal starts at the root object of this entity.

    Returns void

  • Traverses all meshes in the hierarchy of this entity.

    Parameters

    • callback: ((arg0) => void)

      The callback.

        • (arg0): void
        • Parameters

          • arg0: Mesh<BufferGeometry<NormalBufferAttributes>, Material | Material[], Object3DEventMap>

          Returns void

    • root: Object3D<Object3DEventMap> = undefined

      The raversal root. If undefined, the traversal starts at the root object of this entity.

    Returns void

  • Performs an update on an element of the entity.

    Note: this method will be called for each element returned by preUpdate().

    Parameters

    • context: Context

      the update context. This is the same object that the entity whose update() is being called.

    • element: unknown

      the element to update. This is one of the elements returned by ().

    Returns void

  • Updates the clipping planes of all objects under this entity.

    Returns void

  • Updates the opacity of the entity. Note: this method can be overriden for custom implementations.

    Returns void

  • Updates the visibility of the entity. Note: this method can be overriden for custom implementations.

    Returns void

Generated using TypeDoc