NGL@0.10.4 Home Manual Reference Source GalleryRepository
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 );
var shapeComp = stage.addComponentFromObject( shape );
geoComp.addRepresentation( "buffer" );

Constructor Summary

Public Constructor
public

constructor(name: String, params: Object)

Method Summary

Public Methods
public

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

Add an arrow

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

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

Add a label

public

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

Add a mesh

public

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

Add a sphere

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 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 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(position: Vector3 | Array, color: Color | Array, size: Float, text: String): Shape source

Add a label

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.addLabel( [ 10, -2, 4 ], [ 0.2, 0.5, 0.8 ], 0.5, "Hello" );

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 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 );