NGL@1.0.0-beta.7 Home Manual Reference Source Gallery
import Shape from 'ngl/src/geometry/shape.js'
public class | source

Shape

Class for building custom shapes.

Example:

var shape = new NGL.Shape("shape", { disableImpostor: true });
shape.addSphere([ 0, 0, 9 ], [ 1, 0, 0 ], 1.5 );
shape.addEllipsoid([ 6, 0, 0 ], [ 1, 0, 0 ], 1.5, [ 3, 0, 0 ], [ 0, 2, 0 ]);
shape.addCylinder([ 0, 2, 7 ], [ 0, 0, 9 ], [ 1, 1, 0 ], 0.5);
shape.addCone([ 0, 2, 7 ], [ 0, 3, 3 ], [ 1, 1, 0 ], 1.5);
shape.addArrow([ 1, 2, 7 ], [ 30, 3, 3 ], [ 1, 0, 1 ], 1.0);
shape.addBox([ 0, 3, 0 ], [ 1, 0, 1 ], 2, [ 0, 1, 1 ], [ 1, 0, 1 ]);
var shapeComp = stage.addComponentFromObject(shape);
geoComp.addRepresentation("buffer");

Constructor Summary

Public Constructor
public

constructor(name: String, params: Object)

Member Summary

Public Members
public
public
public
public
public
public get
public
public
public
public
public
public
public
public get
Private Members
private

Method Summary

Public Methods
public

addArrow(position1: Vector3 | Array, position2: Vector3 | Array, color: Color | Array, radius: Float, name: String): Shape

Add an arrow

public

addBox(position: Vector3 | Array, color: Color | Array, size: Float, heightAxis: Vector3 | Array, depthAxis: Vector3 | Array, name: String): Shape

Add a box

public

addBuffer(buffer: Buffer): Shape

Add a buffer

public

addCone(position1: Vector3 | Array, position2: Vector3 | Array, color: Color | Array, radius: Float, name: String): Shape

Add a cone

public

addCylinder(position1: Vector3 | Array, position2: Vector3 | Array, color: Color | Array, radius: Float, name: String): Shape

Add a cylinder

public

addEllipsoid(position: Vector3 | Array, color: Color | Array, radius: Float, majorAxis: Vector3 | Array, minorAxis: Vector3 | Array, name: String): Shape

Add an ellipsoid

public

Deprecated, use .addText

public

addMesh(position: Float32Array | Array, color: Float32Array | Array, index: Uint32Array | Uint16Array | Array, normal: Float32Array | Array, name: String): Shape

Add a mesh

public

addOctahedron(position: Vector3 | Array, color: Color | Array, size: Float, heightAxis: Vector3 | Array, depthAxis: Vector3 | Array, name: String): Shape

Add an octahedron

public

addSphere(position: Vector3 | Array, color: Color | Array, radius: Float, name: String): Shape

Add a sphere

public

addTetrahedron(position: Vector3 | Array, color: Color | Array, size: Float, heightAxis: Vector3 | Array, depthAxis: Vector3 | Array, name: String): Shape

Add a tetrahedron

public

addText(position: Vector3 | Array, color: Color | Array, size: Float, text: String): Shape

Add text

public

addTorus(position: Vector3 | Array, color: Color | Array, radius: Float, majorAxis: Vector3 | Array, minorAxis: Vector3 | Array, name: String): Shape

Add a torus

public
public

Public Constructors

public constructor(name: String, params: Object) source

Params:

NameTypeAttributeDescription
name String

name

params Object

parameter object

params.aspectRatio Integer

arrow aspect ratio, used for cylinder radius and cone length

params.sphereDetail Integer

sphere quality (icosahedron subdivisions)

params.radialSegments Integer

cylinder quality (number of segments)

params.disableImpostor Boolean

disable use of raycasted impostors for rendering

params.openEnded Boolean

capped or not

params.labelParams TextBufferParameters

label parameters

Public Members

public [P.getShapeKey('name')] source

public [P.getShapeKey(name)] source

public aspectRatio source

public boundingBox source

public bufferList source

public get center source

public disableImpostor source

public labelParams source

public meshCount source

public name source

public openEnded source

public radialSegments source

public sphereDetail source

public get type source

Private Members

private _center source

Public Methods

public addArrow(position1: Vector3 | Array, position2: Vector3 | Array, color: Color | Array, radius: Float, name: String): Shape source

Add an arrow

Params:

NameTypeAttributeDescription
position1 Vector3 | Array

from position vector or array

position2 Vector3 | Array

to position vector or array

color Color | Array

color object or array

radius Float

radius value

name String
  • optional

text

Return:

Shape

this object

Example:

shape.addArrow([ 0, 2, 7 ], [ 0, 0, 9 ], [ 1, 1, 0 ], 0.5);

public addBox(position: Vector3 | Array, color: Color | Array, size: Float, heightAxis: Vector3 | Array, depthAxis: Vector3 | Array, name: String): Shape source

Add a box

Params:

NameTypeAttributeDescription
position Vector3 | Array

position vector or array

color Color | Array

color object or array

size Float

size value

heightAxis Vector3 | Array

height axis vector or array

depthAxis Vector3 | Array

depth axis vector or array

name String
  • optional

text

Return:

Shape

this object

Example:

shape.addBox([ 0, 3, 0 ], [ 1, 0, 1 ], 2, [ 0, 1, 1 ], [ 1, 0, 1 ]);

public addBuffer(buffer: Buffer): Shape source

Add a buffer

Params:

NameTypeAttributeDescription
buffer Buffer

buffer object

Return:

Shape

this object

public addCone(position1: Vector3 | Array, position2: Vector3 | Array, color: Color | Array, radius: Float, name: String): Shape source

Add a cone

Params:

NameTypeAttributeDescription
position1 Vector3 | Array

from position vector or array

position2 Vector3 | Array

to position vector or array

color Color | Array

color object or array

radius Float

radius value

name String
  • optional

text

Return:

Shape

this object

Example:

shape.addCone([ 0, 2, 7 ], [ 0, 3, 3 ], [ 1, 1, 0 ], 1.5);

public addCylinder(position1: Vector3 | Array, position2: Vector3 | Array, color: Color | Array, radius: Float, name: String): Shape source

Add a cylinder

Params:

NameTypeAttributeDescription
position1 Vector3 | Array

from position vector or array

position2 Vector3 | Array

to position vector or array

color Color | Array

color object or array

radius Float

radius value

name String
  • optional

text

Return:

Shape

this object

Example:

shape.addCylinder([ 0, 2, 7 ], [ 0, 0, 9 ], [ 1, 1, 0 ], 0.5);

public addEllipsoid(position: Vector3 | Array, color: Color | Array, radius: Float, majorAxis: Vector3 | Array, minorAxis: Vector3 | Array, name: String): Shape source

Add an ellipsoid

Params:

NameTypeAttributeDescription
position Vector3 | Array

position vector or array

color Color | Array

color object or array

radius Float

radius value

majorAxis Vector3 | Array

major axis vector or array

minorAxis Vector3 | Array

minor axis vector or array

name String
  • optional

text

Return:

Shape

this object

Example:

shape.addEllipsoid([ 6, 0, 0 ], [ 1, 0, 0 ], 1.5, [ 3, 0, 0 ], [ 0, 2, 0 ]);

public addLabel() source

Deprecated, use .addText

public addMesh(position: Float32Array | Array, color: Float32Array | Array, index: Uint32Array | Uint16Array | Array, normal: Float32Array | Array, name: String): Shape source

Add a mesh

Params:

NameTypeAttributeDescription
position Float32Array | Array

positions

color Float32Array | Array

colors

index Uint32Array | Uint16Array | Array
  • optional

indices

normal Float32Array | Array
  • optional

normals

name String
  • optional

text

Return:

Shape

this object

Example:

shape.addMesh(
  [ 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0, 1 ],
  [ 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0 ]
);

public addOctahedron(position: Vector3 | Array, color: Color | Array, size: Float, heightAxis: Vector3 | Array, depthAxis: Vector3 | Array, name: String): Shape source

Add an octahedron

Params:

NameTypeAttributeDescription
position Vector3 | Array

position vector or array

color Color | Array

color object or array

size Float

size value

heightAxis Vector3 | Array

height axis vector or array

depthAxis Vector3 | Array

depth axis vector or array

name String
  • optional

text

Return:

Shape

this object

Example:

shape.addOctahedron([ 0, 3, 0 ], [ 1, 0, 1 ], 2, [ 0, 1, 1 ], [ 1, 0, 1 ]);

public addSphere(position: Vector3 | Array, color: Color | Array, radius: Float, name: String): Shape source

Add a sphere

Params:

NameTypeAttributeDescription
position Vector3 | Array

position vector or array

color Color | Array

color object or array

radius Float

radius value

name String
  • optional

text

Return:

Shape

this object

Example:

shape.addSphere([ 0, 0, 9 ], [ 1, 0, 0 ], 1.5);

public addTetrahedron(position: Vector3 | Array, color: Color | Array, size: Float, heightAxis: Vector3 | Array, depthAxis: Vector3 | Array, name: String): Shape source

Add a tetrahedron

Params:

NameTypeAttributeDescription
position Vector3 | Array

position vector or array

color Color | Array

color object or array

size Float

size value

heightAxis Vector3 | Array

height axis vector or array

depthAxis Vector3 | Array

depth axis vector or array

name String
  • optional

text

Return:

Shape

this object

Example:

shape.addTetrahedron([ 0, 3, 0 ], [ 1, 0, 1 ], 2, [ 0, 1, 1 ], [ 1, 0, 1 ]);

public addText(position: Vector3 | Array, color: Color | Array, size: Float, text: String): Shape source

Add text

Params:

NameTypeAttributeDescription
position Vector3 | Array

from position vector or array

color Color | Array

color object or array

size Float

size value

text String

text value

Return:

Shape

this object

Example:

shape.addText([ 10, -2, 4 ], [ 0.2, 0.5, 0.8 ], 0.5, "Hello");

public addTorus(position: Vector3 | Array, color: Color | Array, radius: Float, majorAxis: Vector3 | Array, minorAxis: Vector3 | Array, name: String): Shape source

Add a torus

Params:

NameTypeAttributeDescription
position Vector3 | Array

position vector or array

color Color | Array

color object or array

radius Float

radius value

majorAxis Vector3 | Array

major axis vector or array

minorAxis Vector3 | Array

minor axis vector or array

name String
  • optional

text

Return:

Shape

this object

Example:

shape.addTorus([ 6, 0, 0 ], [ 1, 0, 0 ], 1.5, [ 3, 0, 0 ], [ 0, 2, 0 ]);

public dispose() source

public getBufferList() source