Global

Members

a_coords_loc :GLuint

Vertex coordinates location.
Type:
  • GLuint
Source:
See:

a_normal_loc :GLuint

Vertex normal location.
Type:
  • GLuint
Source:

a_tangent_loc :GLuint

Vertex tangents location.
Type:
  • GLuint
Source:

a_texCoords_loc :GLuint

Vertex texture coordinates location.
Type:
  • GLuint
Source:

bumpmap :WebGLTexture

The bumpmap texture.
Type:
  • WebGLTexture
Source:

(constant) bumpmapURLs :Array.<String>

Bump map images.
Type:
  • Array.<String>
Source:

canvas :CanvasRenderingContext2D

Canvas on which gl draws.
Type:
  • CanvasRenderingContext2D
Source:

(constant) colors :Array.<Array.<Number>>

Color array.
Type:
  • Array.<Array.<Number>>
Source:

gl :WebGLRenderingContext

The webgl context.
Type:
  • WebGLRenderingContext
Source:

modelview :mat3

Modelview matrix; value comes from rotator.
Type:
  • mat3
Source:

(constant) normalMatrix :mat3

Matrix, derived from modelview matrix, for transforming normal vectors.
Type:
  • mat3
Source:

(constant) objects :Array.<model>

Array of objects, containing models created using createModel. Will contain a cube, a cylinder and a torus.
Type:
  • Array.<model>
Source:

(constant) projection :mat4

Projection matrix.
Type:
  • mat4
Source:

rotator :TrackballRotator

A TrackballRotator to implement rotation by mouse.
Type:
Source:

texture :WebGLTexture

The image texture.
Type:
  • WebGLTexture
Source:

u_bumpmap :WebGLUniformLocation

A bumpmap texture (grayscale).
Type:
  • WebGLUniformLocation
Source:

u_bumpmapSize :WebGLUniformLocation

An array giving bumpmap texture size.
Type:
  • WebGLUniformLocation
Source:

u_bumpmapStrength :WebGLUniformLocation

A value telling how strong the bump effect is (can be negative).
Type:
  • WebGLUniformLocation
Source:

u_lights :WebGLUniformLocation

Holds uniform location for light properties.
Type:
  • WebGLUniformLocation
Source:

u_material :WebGLUniformLocation

Holds uniform location for front material.
Type:
  • WebGLUniformLocation
Source:

u_modelview :WebGLUniformLocation

Holds uniform location for model view matrix.
Type:
  • WebGLUniformLocation
Source:
See:

u_normalMatrix :WebGLUniformLocation

Holds uniform location for normal matrix.
Type:
  • WebGLUniformLocation
Source:

u_projection :WebGLUniformLocation

Holds uniform location for projection matrix.
Type:
  • WebGLUniformLocation
Source:

u_texture :WebGLUniformLocation

An image texture.
Type:
  • WebGLUniformLocation
Source:

u_useTexture :WebGLUniformLocation

Tells whether to use texture for diffuseColor.
Type:
  • WebGLUniformLocation
Source:

Methods

createModel(modelData) → {model}

Create an object representing an IFS model.

The modelData holds the data for an IFS using the structure from basic-object-models-with-tangents-IFS.js.
This function creates VBOs to hold the coordinates, normal vectors, tangent vectors,
texture coordinates and indices from the IFS. It also loads the data into those buffers.

The function creates a new object whose properties are the identifiers of the VBOs.
The new object also has a function, render, that can be called to render the object, using all the data from the buffers.
That object is returned as the value of the function.

Parameters:
Name Type Description
modelData Object.<{vertexPositions: Float32Array, vertexNormals: Float32Array, vertexTextureCoords: Float32Array, vertexTangents:Float32Array, indices: Uint16Array}>
Properties:
Name Type Description
model object
Properties
Name Type Description
coordsBuffer WebGLBuffer coordinate buffer.
normalBuffer WebGLBuffer normal buffer.
tangentBuffer WebGLBuffer tangent buffer.
texCoordsBuffer WebGLBuffer texture buffer.
indexBuffer WebGLBuffer index buffer.
count Number number of indices.
render render render function.
Source:
Returns:
created model.
Type
model

createProgram(gl, vShader, fShader)

Creates a program for use in the WebGL context gl, and returns the identifier for that program.

If an error occurs while compiling or linking the program, an exception of type Error is thrown. The error string contains the compilation or linking error.

If no error occurs, the program identifier is the return value of the function. The second and third parameters are strings that contain the source code for the vertex shader and for the fragment shader.

Parameters:
Name Type Description
gl WebGLProgram WebGL context.
vShader WebGLShader vertex shader.
fShader WebGLShader fragment shade.
Source:

cube(side) → {Object.<{vertexPositions: Float32Array, vertexNormals: Float32Array, vertexTextureCoords: Float32Array, vertexTangents: Float32Array, indices: Uint16Array}>}

Create a model of a cube, centered at the origin. (This is not a particularly good format for a cube, since an IFS representation has a lot of redundancy.)
Parameters:
Name Type Description
side Number the length of a side of the cube. If not given, the value will be 1.
Source:
Returns:
Type
Object.<{vertexPositions: Float32Array, vertexNormals: Float32Array, vertexTextureCoords: Float32Array, vertexTangents: Float32Array, indices: Uint16Array}>

draw()

Render the scene.
Source:

init()

Initialization function that will be called when the page has loaded.
Source:

initGL()

Initialize the WebGL context.

Called from init.
Source:

loadBumpmap()

Loads the bumpmap texture and passes it to the fragment shader.
Source:

setDiffuse()

Sets diffuse color in the fragment shader and calls draw.
Source:

uvCone(radius, height, slices, noBottom) → {Object.<{vertexPositions:Float32Array, vertexNormals:Float32Array, vertexTextureCoords:Float32Array, vertexTangents: Float32Array, indices:Uint16Array}>}

Defines a model of a cone. The axis of the cone is the z-axis, and the center is at (0,0,0).
Parameters:
Name Type Description
radius Number the radius of the cone.
height Number the height of the cone.
The cone extends from -height/2 to height/2 along the z-axis,
with the tip at (0,0,height/2).
slices Number the number of slices, like the slices of an orange.
noBottom Boolean if missing or false, the cone has a bottom; if set to true, the cone does not have a bottom.
The bottom is a disk at the wide end of the cone.
Source:
See:
Returns:
Type
Object.<{vertexPositions:Float32Array, vertexNormals:Float32Array, vertexTextureCoords:Float32Array, vertexTangents: Float32Array, indices:Uint16Array}>

uvCylinder(radius, height, slices, noTop, noBottom) → {Object.<{vertexPositions: Float32Array, vertexNormals: Float32Array, vertexTextureCoords: Float32Array, vertexTangents: Float32Array, indices: Uint16Array}>}

Defines a model of a cylinder. The axis of the cylinder is the z-axis, and the center is at (0,0,0).
Parameters:
Name Type Description
radius Number the radius of the cylinder
height Number the height of the cylinder. The cylinder extends from -height/2 to height/2 along the z-axis.
slices Number the number of slices, like the slices of an orange.
noTop Boolean if missing or false, the cylinder has a top; if set to true, the cylinder does not have a top. The top is a disk at the positive end of the cylinder.
noBottom Boolean if missing or false, the cylinder has a bottom; if set to true, the cylinder does not have a bottom. The bottom is a disk at the negtive end of the cylinder.
Source:
See:
Returns:
Type
Object.<{vertexPositions: Float32Array, vertexNormals: Float32Array, vertexTextureCoords: Float32Array, vertexTangents: Float32Array, indices: Uint16Array}>

uvSphere(radius, slices, stacks) → {Object.<{vertexPositions:Float32Array, vertexNormals:Float32Array, vertexTextureCoords:Float32Array, vertexTangents: Float32Array, indices:Uint16Array}>}

Create a model of a sphere.

The z-axis is the axis of the sphere, with the north pole on the positive z-axis and the center at (0,0,0).
Parameters:
Name Type Description
radius Number the radius of the sphere, default 0.5 if not specified.
slices Number the number of lines of longitude, default 32
stacks Number the number of lines of latitude plus 1, default 16. (This is the number of vertical slices, bounded by lines of latitude, the north pole and the south pole.)
Source:
See:
Returns:
Type
Object.<{vertexPositions:Float32Array, vertexNormals:Float32Array, vertexTextureCoords:Float32Array, vertexTangents: Float32Array, indices:Uint16Array}>

uvTorus(outerRadius, innerRadius, slices, stacks) → {Object.<{vertexPositions: Float32Array, vertexNormals: Float32Array, vertexTextureCoords: Float32Array, vertexTangents: Float32Array, indices: Uint16Array}>}

Create a model of a torus (surface of a doughnut). The z-axis goes through the doughnut hole, and the center of the torus is at (0,0,0).
Parameters:
Name Type Description
outerRadius Number the distance from the center to the outside of the tube, 0.5 if not specified.
innerRadius Number the distance from the center to the inside of the tube, outerRadius/3 if not specified. (This is the radius of the doughnut hole.)
slices Number the number of lines of longitude, default 32. These are slices parallel to the z-axis and go around the tube the short way (through the hole).
stacks Number the number of lines of latitude plus 1, default 16. These lines are perpendicular to the z-axis and go around the tube the long way (arouind the hole).
Source:
See:
Returns:
Type
Object.<{vertexPositions: Float32Array, vertexNormals: Float32Array, vertexTextureCoords: Float32Array, vertexTangents: Float32Array, indices: Uint16Array}>

Type Definitions

render()

This function will render the object.

Since the buffer from which we are taking the coordinates and normals change each time an object is drawn,
we have to use gl.vertexAttribPointer to specify the location of the data.

To accomplish that, we must first bind the buffer that contains the data.
Similarly, we have to bind this object's index buffer before calling gl.drawElements.

Source: