Reference Source
public class | source

ReadableGeometry

Extends:

ComponentGeometry → ReadableGeometry

A Geometry that keeps its geometry data in both browser and GPU memory.

ReadableGeometry uses more memory than VBOGeometry, which only stores its geometry data in GPU memory.

Usage

Creating a Mesh with a ReadableGeometry that defines a single triangle, plus a PhongMaterial with diffuse Texture:

[Run this example]

import {Viewer, Mesh, ReadableGeometry, PhongMaterial, Texture} from "xeokit-sdk.es.js";

const viewer = new Viewer({
        canvasId: "myCanvas"
    });

const myMesh = new Mesh(viewer.scene, {
        geometry: new ReadableGeometry(viewer.scene, {
            primitive: "triangles",
            positions: [0.0, 3, 0.0, -3, -3, 0.0, 3, -3, 0.0],
            normals: [0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0],
            uv: [0.0, 0.0, 0.5, 1.0, 1.0, 0.0],
            indices: [0, 1, 2]
        }),
        material: new PhongMaterial(viewer.scene, {
            diffuseMap: new Texture(viewer.scene, {
                src: "textures/diffuse/uvGrid2.jpg"
            }),
            backfaces: true
        })
    });

// Get geometry data from browser memory:

const positions = myMesh.geometry.positions; // Flat arrays
const normals = myMesh.geometry.normals;
const uv = myMesh.geometry.uv;
const indices = myMesh.geometry.indices;

Constructor Summary

Public Constructor
public

constructor(owner: Component, cfg: *, owner: *, cfg: *)

Member Summary

Public Members
public get

Local-space axis-aligned 3D boundary (AABB) of this geometry.

public get

The Geometry's vertex colors.

public set
public get

Indicates if this Geometry is quantized.

public get

indices: *

The Geometry's indices.

If xeokit.WEBGL_INFO.SUPPORTED_EXTENSIONS["OES_element_index_uint"] is true, then this can be a Uint32Array, otherwise it needs to be a Uint16Array.

public get

The Geometry's vertex normals.

public set
public get

Approximate number of triangles in this ReadableGeometry.

public get

obb: Number[]

Local-space oriented 3D boundary (OBB) of this geometry.

public get

The Geometry's vertex positions.

public set
public get

Gets the Geometry's primitive type.

Valid types are: 'points', 'lines', 'line-loop', 'line-strip', 'triangles', 'triangle-strip' and 'triangle-fan'.

public get

uv: Number[]

The Geometry's UV coordinates.

public set

uv

Method Summary

Public Methods
public

Destroys this ReadableGeometry

Inherited Summary

From class Component
public get

The Component that owns the lifecycle of this Component, if any.

public

True as soon as this Component has been destroyed

public

ID of this Component, unique within the Scene.

public

meta: *

Arbitrary, user-defined metadata on this component.

public

The parent Scene that contains this Component.

public

The viewer that contains this Scene.

public

clear()

Destroys all Components that are owned by this.

public

Destroys this component.

public

error(message: String)

Logs an error for this component to the JavaScript console.

public

fire(event: String, value: Object, forget: Boolean)

Fires an event on this component.

public

Returns true if there are any subscribers to the given event on this component.

public

isType(type: *): *: Boolean

Tests if this component is of the given type, or is a subclass of the given type.

public

log(message: String)

Logs a console debugging message for this component.

public

off(subId: String)

Cancels an event subscription that was previously made with Component#on or Component#once.

public

on(event: String, callback: Function, scope: Object): String

Subscribes to an event on this component.

public

once(event: String, callback: Function, scope: Object)

Subscribes to the next occurrence of the given event, then un-subscribes as soon as the event is subIdd.

public

scheduleTask(task: *)

Schedule a task to perform on the next browser interval

public

warn(message: String)

Logs a warning for this component to the JavaScript console.

From class Geometry
public

Public Constructors

public constructor(owner: Component, cfg: *, owner: *, cfg: *) source

Override:

Geometry#constructor

Params:

NameTypeAttributeDescription
owner Component

Owner component. When destroyed, the owner will destroy this component as well.

cfg *
  • optional

Configs

cfg.id String
  • optional

Optional ID, unique among all components in the parent Scene, generated automatically when omitted.

cfg.meta String:Object
  • optional

Optional map of user-defined metadata to attach to this Geometry.

cfg.primitive *
  • optional
  • default: "triangles"

{String} The primitive type. Accepted values are 'points', 'lines', 'line-loop', 'line-strip', 'triangles', 'triangle-strip' and 'triangle-fan'.

cfg.positions *
  • optional

{Number[]} Positions array.

cfg.normals *
  • optional

{Number[]} Vertex normal vectors array.

cfg.uv *
  • optional

{Number[]} UVs array.

cfg.colors *
  • optional

{Number[]} Vertex colors.

cfg.indices *
  • optional

{Number[]} Indices array.

cfg.autoVertexNormals *
  • optional
  • default: false

{Boolean} Set true to automatically generate normal vectors from the positions and indices, if those are supplied.

cfg.compressGeometry *
  • optional
  • default: false

{Boolean} Stores positions, colors, normals and UVs in compressGeometry and oct-encoded formats for reduced memory footprint and GPU bus usage.

cfg.edgeThreshold *
  • optional
  • default: 10

{Number} When a Mesh renders this Geometry as wireframe, this indicates the threshold angle (in degrees) between the face normals of adjacent triangles below which the edge is discarded.

owner *
cfg *

Public Members

public get aabb: Number[] source

Local-space axis-aligned 3D boundary (AABB) of this geometry.

The AABB is represented by a six-element Float64Array containing the min/max extents of the axis-aligned volume, ie. [xmin, ymin,zmin,xmax,ymax, zmax].

Properties:

NameTypeAttributeDescription
aabb *

public get colors: Number[] source

The Geometry's vertex colors.

Properties:

NameTypeAttributeDescription
colors *

public set colors source

public get compressGeometry: Boolean source

Indicates if this Geometry is quantized.

Compression is an internally-performed optimization which stores positions, colors, normals and UVs in quantized and oct-encoded formats for reduced memory footprint and GPU bus usage.

Quantized geometry may not be updated.

Properties:

NameTypeAttributeDescription
compressGeometry *

public get indices: * source

The Geometry's indices.

If xeokit.WEBGL_INFO.SUPPORTED_EXTENSIONS["OES_element_index_uint"] is true, then this can be a Uint32Array, otherwise it needs to be a Uint16Array.

Properties:

NameTypeAttributeDescription
indices *

public get normals: Number[] source

The Geometry's vertex normals.

Properties:

NameTypeAttributeDescription
normals *

public set normals source

public get numTriangles: Number source

Approximate number of triangles in this ReadableGeometry.

Will be zero if ReadableGeometry#primitive is not 'triangles', 'triangle-strip' or 'triangle-fan'.

public get obb: Number[] source

Local-space oriented 3D boundary (OBB) of this geometry.

The OBB is represented by a 32-element Float64Array containing the eight vertices of the box, where each vertex is a homogeneous coordinate having [x,y,z,w] elements.

Properties:

NameTypeAttributeDescription
obb *

public get positions: Number[] source

The Geometry's vertex positions.

Properties:

NameTypeAttributeDescription
positions *

public set positions source

public get primitive: String source

Gets the Geometry's primitive type.

Valid types are: 'points', 'lines', 'line-loop', 'line-strip', 'triangles', 'triangle-strip' and 'triangle-fan'.

Properties:

NameTypeAttributeDescription
primitive *

public get uv: Number[] source

The Geometry's UV coordinates.

Properties:

NameTypeAttributeDescription
uv *

public set uv source

Public Methods

public destroy() source

Destroys this ReadableGeometry

Override:

Geometry#destroy