Skip to content
cjcliffe edited this page Oct 15, 2011 · 3 revisions

CubicVR.primitives

The primitives object provides a simple factory for generating basic mesh objects like boxes, spheres and cylinders.

Sample Usage:

var boxMesh = CubicVR.primitives.box({
   size: 1.0,
   material: material3,
   uvmapper: uvcubic,
   transform: (new CubicVR.Transform()).scale([1,2,3])
}).triangulateQuads().compile().clean();

Methods:

lathe( init )

Lathe will perform a lathe revolution for given points around the Y axis and generate the resulting faces.

Parameters:

  • init - Object constructor:
    • points: an array of points, format [ [x,y,z], [x,y,z], ... ] to revolve.
    • divisions: number of divisions for the revolution.
    • material: (optional) a Material to apply to new geometry.
    • mesh: (optional) an existing Mesh to add the resulting object to.
    • transform: (optional) a Transform or a 4x4 matrix in an array of 16 floats, if supplied the new geometry will be transformed by it.
    • uvmapper: (optional) a UVMapper or a UVMapper object constructor to apply to new geometry.

Returns:

If mesh was supplied, it will return the original mesh instance. Otherwise a new Mesh will be created and returned.

box( init )

Produces a simple 6 sided box mesh.

Parameters:

  • init - Object constructor:
    • size: The size of the box, resulting box is size * size * size centered at the origin, default: 1.0.
    • material: (optional) a Material to apply to new geometry.
    • mesh: (optional) an existing Mesh to add the resulting object to.
    • transform: (optional) a Transform or a 4x4 matrix in an array of 16 floats, if supplied the new geometry will be transformed by it.
    • uvmapper: (optional) a UVMapper or a UVMapper object constructor to apply to new geometry.

Returns:

If mesh was supplied, it will return the original mesh instance. Otherwise a new Mesh will be created and returned.

plane( init )

Produces 2 quad faces on the X/Y axis facing back-to-back.

Parameters:

  • init - Object constructor:
    • size: The horizontal/vertical size of the plane, resulting plane is size * size centered at the origin on the X/Y axis, default: 1.0.
    • material: (optional) a Material to apply to new geometry.
    • mesh: (optional) an existing Mesh to add the resulting object to.
    • transform: (optional) a Transform or a 4x4 matrix in an array of 16 floats, if supplied the new geometry will be transformed by it.
    • uvmapper: (optional) a UVMapper or a UVMapper object constructor to apply to new geometry.

Returns:

If mesh was supplied, it will return the original mesh instance. Otherwise a new Mesh will be created and returned.

sphere( init )

Produces a sphere mesh with given radius and longitude/latitude, lathe-based.

Parameters:

  • init - Object constructor:
    • radius: radius of the sphere, default: 1.0
    • lon: number of divisions along the longitude (x) axis, default: 24.
    • lat: number of divisions along the latitude (y) axis, default: 24.
    • material: (optional) a Material to apply to new geometry.
    • mesh: (optional) an existing Mesh to add the resulting object to.
    • transform: (optional) a Transform or a 4x4 matrix in an array of 16 floats, if supplied the new geometry will be transformed by it.
    • uvmapper: (optional) a UVMapper or a UVMapper object constructor to apply to new geometry.

Returns:

If mesh was supplied, it will return the original mesh instance. Otherwise a new Mesh will be created and returned.

torus( init )

Produces a torus (or doughnut, Mmmm... doughnuts) with given inner/outer radius and longitude/latitude divisions, lathe-based.

Parameters:

  • init - Object constructor:
    • innerRadius: inner radius of the torus, default: 0.75.
    • outerRadius: outer radius of the torus, default: 1.0.
    • lon: number of divisions along the longitude (x) axis, default: 24.
    • lat: number of divisions along the latitude (y) axis, default: 24.
    • material: (optional) a Material to apply to new geometry.
    • mesh: (optional) an existing Mesh to add the resulting object to.
    • transform: (optional) a Transform or a 4x4 matrix in an array of 16 floats, if supplied the new geometry will be transformed by it.
    • uvmapper: (optional) a UVMapper or a UVMapper object constructor to apply to new geometry.

Returns:

If mesh was supplied, it will return the original mesh instance. Otherwise a new Mesh will be created and returned.

cone( init )

Produces a cone mesh with given base, lathe-based.

Parameters:

  • init - Object constructor:
    • base: base size of the cone, default 1.0.
    • height: height of the cone, default 1.0.
    • lon: number of divisions for the revolution, default 24.
    • material: (optional) a Material to apply to new geometry.
    • mesh: (optional) an existing Mesh to add the resulting object to.
    • transform: (optional) a Transform or a 4x4 matrix in an array of 16 floats, if supplied the new geometry will be transformed by it.
    • uvmapper: (optional) a UVMapper or a UVMapper object constructor to apply to new geometry.

Returns:

If mesh was supplied, it will return the original mesh instance. Otherwise a new Mesh will be created and returned.

cylinder( init )

Produce a cylinder mesh with given radius, height and divisions, lathe-based.

Parameters:

  • init - Object constructor:
    • radius: radius of cylinder, default: 1.0.
    • height: height of cylinder, default: 1.0.
    • divisions: number of divisions for the revolution, default 24.
    • material: (optional) a Material to apply to new geometry.
    • mesh: (optional) an existing Mesh to add the resulting object to.
    • transform: (optional) a Transform or a 4x4 matrix in an array of 16 floats, if supplied the new geometry will be transformed by it.
    • uvmapper: (optional) a UVMapper or a UVMapper object constructor to apply to new geometry.

Returns:

If mesh was supplied, it will return the original mesh instance. Otherwise a new Mesh will be created and returned.

Clone this wiki locally