@kognifai/cogsengine
    Preparing search index...

    Class Scene

    class Scene: Exposed as runtime.scene

    Has functionality for

    • picking entities
    • projecting coordinates
    • handling large coordinates (origin)
    • viewing all entities
    Index

    Constructors

    • Internal: Called by runtime

      Parameters

      Returns Scene

    Properties

    defaultRaypickRadius: number

    Distance an object can be from a ray to be considered hit, for picking functions where that is not specified explicitly. Default value is 4.0.

    pickingFlags: PickingFlags

    Picking flags to be applied for Scene picking functions not including pickingFlags as argument. Default: PickingFlags.PickSprites + PickingFlags.ReturnChildEntity + PickingFlags.RemoveDuplicates

    Accessors

    • get camera(): Camera

      Getter for default camera. Can be null if clearing scene without default and no camera defined.

      Returns Camera

    • get directionalLight(): Light

      Getter for directional light

      Returns Light

    • get fillLight(): Light

      Getter for fill light

      Returns Light

    • get headLight(): Light

      Getter for head light

      Returns Light

    • get origin(): dvec3

      Getter for camera origin

      Returns dvec3

      Scene origin

    • set origin(value: dvec3): void

      Setter for camera origin.

      When working with large coordinate systems it is necessary to set origin close to the coordinates of the camera. Rendering and navigation will be inaccurate if distance between camera and origin gets too large. Ex: scene.origin = [60000000, 7000000, 0]

      Parameters

      • value: dvec3

        new scene and camera origin

      Returns void

    • get runtime(): Runtime

      Getter for class Runtime

      Returns Runtime

    Methods

    • Gets all Entities created by client.

      Returns Entity[]

      Array of entities

    • Return bounding box for Entity in Engine Coordinates

      Parameters

      Returns BoundingBox

      Calculated Engine Coordinates bounding box - May be empty

      Use getBoundingBoxWorld.

    • Returns union of bounding box for array of Entities, e.g. Entity[] in Engine Coordinates

      Parameters

      • entities: Entity[]

        Array of entities.

      Returns BoundingBox

      Calculated Engine Coordinates bounding box - May be empty

      Use getBoundingBoxMultiWorld.

    • Returns union of bounding box for array of Entities, e.g. Entity[] in World Coordinates

      Parameters

      • entities: Entity[]

        Array of entities.

      Returns DBoundingBox

      Calculated World Coordinates bounding box - May be empty

    • Return bounding box for Entity in World Coordinates

      Parameters

      Returns DBoundingBox

      Calculated World Coordinates bounding box - May be empty

    • Get depth into given trajectory at the given position

      Parameters

      • entity: Entity

        Entity owning a Trajectory Component

      • position: vec3

        Position, for example from picking.

      Returns number

      Calculated depth. Zero if undefined.

      Use getDepthWorld.

    • Get depth into given trajectory at the given position

      Parameters

      • entity: Entity

        Entity owning a Trajectory Component

      • position: dvec3

        World Position, for example from picking.

      Returns number

      Calculated depth. Zero if undefined.

    • Simple Entity lookup. Use getEntityFull for search control

      Parameters

      • name: string

        Name to look for

      • OptionalexactName: boolean

        Default=true. True for exact match, false for string.contains(name)

      Returns Entity

      Looked up entity or null

    • Get Entity from it's entity ID. Returns existing entity if created by client. Builds from Cogs definition if created internally in Cogs.

      Parameters

      • entityId: number

        ID of the entity

      Returns Entity

      Cogs.js Entity if valid ID

    • Search for an Entity. If a root is provided will look only for that entity's hierarchy. Otherwise checks for all entities stored. All root entities searched first.

      Parameters

      • name: string

        Name to look for

      • rootEntity: Entity

        Optional root entity to limit search for only children.

      • entityFindFlag: EntityFind

        Flags to filter the search, use values as described by - enum EntityFind.

      Returns Entity

      The entity, if found else null.

    • Gets parent of the entity.

      Parameters

      • entity: Entity

        Entity to get parent of.

      Returns Entity

      Parent or null.

    • Get entity on given position in Window

      Parameters

      • posX: number

        Window X

      • posY: number

        Window Y

      • OptionalpickedPosition: vec3

        Engine Coordinate of picked entity if param not undefined.

      Returns Entity

      First entity found or null if no hit

      Use getPickedEntityWorld.

    • Get the first Entity hit from the ray being shoot from a 3D world position in the direction of orientation. Uses Scene.pickingFlags

      Parameters

      • position: vec3

        The 3D world space position where the ray is being generated.

      • orientation: quat

        A Quaternion with a world space rotation, pointing in the direction of the ray.

      • rayLength: number

        Maximum length at which the ray is capable of detecting hits.

      • radius: number

        A radius that defines where the projection space frustum planes are located when picking.

      • pickedPosition: vec3

        Engine Coordinate of picked entity if param not undefined.

      Returns Entity

      First entity found or null if no hit

      Use getPickInfoFromRayWorld.

    • Get entity on given position on Window. Uses Scene.pickingFlags

      Parameters

      • posX: number

        Window X

      • posY: number

        Window Y

      • pickedPosition: vec3

        Engine Coordinate of picked entity if param not undefined.

      • pickInfo: PickInfo

        [out] Full picking information for picked point

      Returns Entity

      First entity found or null if no hit

      Use getPickInfoWorld.

    • Get entity on given position in Window

      Parameters

      • posX: number

        Window X

      • posY: number

        Window Y

      • OptionalpickedPosition: dvec3

        World Coordinates of picked entity if param not undefined.

      Returns Entity

      First entity found or null if no hit

    • Get the picked information by performing a ray pick from the given window location into the scene.

      Parameters

      • posX: number

        Window X

      • posY: number

        Window Y

      • pickingFlags: PickingFlags

        Flags for pick selection

      Returns PickInfo

      Full picking information of first intersection. null if no picking found

      Use getPickInfoWorld.

    • Get all entities on given position on Window sorted by a distance from camera

      Parameters

      • posX: number

        Window X

      • posY: number

        Window Y

      • pickingFlags: PickingFlags

        Flags for pick selection

      Returns PickInfo[]

      Array of Full picking information.

      Use getPickInfoAllWorld.

    • Get all picked entities using defined ray starting from position. Sorted by a distance from scene camera. Uses Engine Coordinates.

      Parameters

      • position: vec3

        The Engine Coordinates where the ray is being generated.

      • orientation: quat

        A Quaternion with a world space rotation, pointing in the direction of the ray.

      • rayLength: number

        Maximum length at which the ray is capable of detecting hits.

      • radius: number

        A radius that defines where the projection space frustum planes are located when picking.

      • pickingFlags: PickingFlags

        Flags for pick selection

      Returns PickInfo[]

      Array of Full picking information.

      Use getPickInfoAllFromRayWorld.

    • Get all picked entities using defined ray starting from position. Sorted by a distance from scene camera. Uses World Coordinates.

      Parameters

      • worldPosition: dvec3

        The World Coordinates where the ray is being generated.

      • orientation: quat

        A Quaternion with a world space rotation, pointing in the direction of the ray.

      • rayLength: number

        Maximum length at which the ray is capable of detecting hits.

      • radius: number

        A radius that defines where the projection space frustum planes are located when picking.

      • pickingFlags: PickingFlags

        Flags for pick selection

      • OptionallayerMask: RenderLayers

        Optional mask of layers enabled for picking (default All).

      Returns DPickInfo[]

      Array of Full picking information.

    • Get all World pick infos on given position on Window sorted by a distance from camera

      Parameters

      • posX: number

        Window X

      • posY: number

        Window Y

      • pickingFlags: PickingFlags

        Flags for pick selection

      • OptionallayerMask: RenderLayers

        Optional mask of layers enabled for picking (default All).

      Returns DPickInfo[]

      Array of World picking information.

    • Get the picked information by performing a ray pick from the given window location into the scene. Uses Engine Coordinates.

      Parameters

      • position: vec3

        The Engine Coordinate where the ray is being generated.

      • orientation: quat

        A Quaternion with a world space rotation, pointing in the direction of the ray.

      • rayLength: number

        Maximum length at which the ray is capable of detecting hits.

      • radius: number

        A radius that defines where the projection space frustum planes are located when picking.

      • pickingFlags: PickingFlags

        Flags for pick selection

      Returns PickInfo

      Full picking information of first intersection. null if no picking found.

      Use getPickInfoFromRayWorld.

    • Get the picked information by performing a ray pick from the given window location into the scene. Uses World Coordinates.

      Parameters

      • worldPosition: dvec3

        The World Coordinate where the ray is being generated.

      • orientation: quat

        A Quaternion with a world space rotation, pointing in the direction of the ray.

      • rayLength: number

        Maximum length at which the ray is capable of detecting hits.

      • radius: number

        A radius that defines where the projection space frustum planes are located when picking.

      • pickingFlags: PickingFlags

        Flags for pick selection

      • OptionallayerMask: RenderLayers

        Optional mask of layers enabled for picking (default All).

      Returns DPickInfo

      Full picking information of first intersection. null if no picking found.

    • Get the picked information by performing a ray pick from the given window location into the scene.

      Parameters

      • posX: number

        Window X

      • posY: number

        Window Y

      • pickingFlags: PickingFlags

        Flags for pick selection

      • OptionallayerMask: RenderLayers

        Optional mask of layers enabled for picking (default All).

      Returns DPickInfo

      Full World picking information of first intersection. null if no picking found

    • Get coordinate projected from Window position onto a plane

      Parameters

      • posX: number

        Window X

      • posY: number

        Window Y

      • direction: vec3

        Normal vector of plane

      • target: vec3

        Plane position

      Returns vec3

      Projected Position if found

      Use getProjectedCoordinatesWorld.

    • Get coordinate projected from Window position onto a plane

      Parameters

      • posX: number

        Window X

      • posY: number

        Window Y

      • direction: vec3

        Normal vector of plane

      • target: dvec3

        Plane World position

      Returns dvec3

      Projected Position in World Coordinates if found

    • Get coordinate projected from Window position onto a plane

      Parameters

      • posX: number

        Normalized window X, in [0,1].

      • posY: number

        Normalized window Y, in [0,1].

      • direction: vec3

        Normal vector of plane

      • target: dvec3

        Plane World position

      Returns dvec3

      Projected Position in World Coordinates if found

    • Return bounding box for whole scene in World Coordinates

      Parameters

      • OptionallayerMask: RenderLayers

        Indicates the layers used to compute the boundingBox

      Returns DBoundingBox

      Calculated World Coordinates bounding box - May be empty

    • Internal: initialization after create or scene reset

      Returns void

    • Get the picked information by performing a ray pick from the given window location into the scene.

      Parameters

      • camera: Camera

        Camera entity used for picking.

      • x: number

        Pick position X on camera.

      • y: number

        Pick position Y on camera.

      • rayLength: number

        Max length of ray.

      • rayRadius: number

        Radius of ray.

      • pickingFlags: PickingFlags

        Flags for pick selection.

      • returnFlag: PicksReturned

        Flag for specifying what picks to return: just the first hit, all hits in an unsorted order or all hits sorted from closest to furthest.

      • layerMask: number

        Used to further restrict the camera's layerMask when determining the entities that can be picked.

      • entityType: string

        Optional name of entity type to pick for, can be null.

      Returns DPickInfo[]

      Array of Full picking information.

    • Get the picked information by performing a ray pick from the given window location into the scene.

      Parameters

      • camera: Camera

        Camera entity used for picking.

      • x: number

        Normalized pick position X on camera, in [0,1].

      • y: number

        Normalized pick position Y on camera, in [0,1].

      • rayLength: number

        Max length of ray.

      • rayRadius: number

        Normalized radius of ray, relative to height, in [0,1].

      • pickingFlags: PickingFlags

        Flags for pick selection.

      • returnFlag: PicksReturned

        Flag for specifying what picks to return: just the first hit, all hits in an unsorted order or all hits sorted from closest to furthest.

      • layerMask: number

        Used to further restrict the camera's layerMask when determining the entities that can be picked.

      • entityType: string

        Optional name of entity type to pick for, can be null.

      Returns DPickInfo[]

      Array of Full picking information.

    • the picked information by performing a ray pick from the given world position and orientation into the scene.

      Parameters

      • position: dvec3

        Ray start position.

      • orientation: quat

        Ray direction.

      • rayLength: number

        Max length of ray.

      • rayRadius: number

        Radius of ray.

      • pickingFlags: PickingFlags

        Flags for pick selection.

      • returnFlag: PicksReturned

        Flag for specifying what picks to return: just the first hit, all hits in an unsorted order or all hits sorted from closest to furthest.

      • layerMask: number

        Used to further restrict the camera's layerMask when determining the entities that can be picked.

      • entityType: string

        Optional name of entity type to pick for, can be null.

      Returns DPickInfo[]

      Array of Full picking information.

    • Internal: release resources on Cogs reset.

      Returns void

    • Set the background color of the scene.

      Parameters

      • color: vec4

        New background color

      Returns void

    • Adjust camera to view all entities in scene. Logs error if empty scene.

      Parameters

      • OptionallayerMask: RenderLayers

        A set of valid layers to construct the visible bounding Box, defaults to All Standard layers

      Returns DBoundingBox

      Calculated World Coordinates bounding box

      • May be empty if empty scene or no camera