import {ReadableGeometry} from '@xeokit/xeokit-sdk/src/viewer/scene/geometry/ReadableGeometry.js'
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:
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 |
|
public get |
The Geometry's vertex normals. |
|
public set |
|
|
public get |
Approximate number of triangles in this ReadableGeometry. |
|
public get |
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 |
The Geometry's UV coordinates. |
|
public set |
|
Method Summary
Public Methods | ||
public |
destroy() 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 |
destroy() Destroys this component. |
|
public |
Logs an error for this component to the JavaScript console. |
|
public |
Fires an event on this component. |
|
public |
Returns true if there are any subscribers to the given event on this component. |
|
public |
Tests if this component is of the given type, or is a subclass of the given type. |
|
public |
Logs a console debugging message for this component. |
|
public |
Cancels an event subscription that was previously made with Component#on or Component#once. |
|
public |
Subscribes to an event on this component. |
|
public |
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 |
Logs a warning for this component to the JavaScript console. |
From class Geometry | ||
public |
destroy() |
Public Constructors
public constructor(owner: Component, cfg: *, owner: *, cfg: *) source
Override:
Geometry#constructorParams:
Name | Type | Attribute | Description |
owner | Component | Owner component. When destroyed, the owner will destroy this component as well. |
|
cfg | * |
|
Configs |
cfg.id | String |
|
Optional ID, unique among all components in the parent Scene, generated automatically when omitted. |
cfg.meta | String:Object |
|
Optional map of user-defined metadata to attach to this Geometry. |
cfg.primitive | * |
|
{String} The primitive type. Accepted values are 'points', 'lines', 'line-loop', 'line-strip', 'triangles', 'triangle-strip' and 'triangle-fan'. |
cfg.positions | * |
|
{Number[]} Positions array. |
cfg.normals | * |
|
{Number[]} Vertex normal vectors array. |
cfg.uv | * |
|
{Number[]} UVs array. |
cfg.colors | * |
|
{Number[]} Vertex colors. |
cfg.indices | * |
|
{Number[]} Indices array. |
cfg.autoVertexNormals | * |
|
{Boolean} Set true to automatically generate normal vectors from the positions and indices, if those are supplied. |
cfg.compressGeometry | * |
|
{Boolean} Stores positions, colors, normals and UVs in compressGeometry and oct-encoded formats for reduced memory footprint and GPU bus usage. |
cfg.edgeThreshold | * |
|
{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:
Name | Type | Attribute | Description |
aabb | * |
public get colors: Number[] source
The Geometry's vertex colors.
Properties:
Name | Type | Attribute | Description |
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:
Name | Type | Attribute | Description |
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:
Name | Type | Attribute | Description |
indices | * |
public get normals: Number[] source
The Geometry's vertex normals.
Properties:
Name | Type | Attribute | Description |
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:
Name | Type | Attribute | Description |
obb | * |
public get positions: Number[] source
The Geometry's vertex positions.
Properties:
Name | Type | Attribute | Description |
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:
Name | Type | Attribute | Description |
primitive | * |
public get uv: Number[] source
The Geometry's UV coordinates.
Properties:
Name | Type | Attribute | Description |
uv | * |