library logo

O3D

Module: O3D

O3D provides Model management and 3D primitives. Here you’ll find methods for creating 3D models and primitives that are compatible with the Scene class.

O3D Class: O3D.Model

The class Model enables you to create 3D models which are compatible with the Scene class. All primitives (Sphere, etc) inherit from Model too.

Properties:

A Model instance has a number of public properties that can be accessed/modified:

O3D.Model Method: constructor

The main constructor function for the Model class. Use this to create a new Model.

Syntax:

var model = new PhiloGL.O3D.Model(options);

Arguments:

  1. options - (object) An object containing the following options:

Options:

Examples:

Create a pyramid model (used in lesson 4 of learning WebGL examples).

var pyramid = new PhiloGL.O3D.Model({
    vertices: [[ 0,  1,  0],
               [-1, -1,  1],
               [ 1, -1,  1],
               [ 0,  1,  0],
               [ 1, -1,  1],
               [ 1, -1, -1],
               [ 0,  1,  0],
               [ 1, -1, -1],
               [-1, -1, -1],
               [ 0,  1,  0],
               [-1, -1, -1],
               [-1, -1,  1]],
    
    colors: [[1, 0, 0, 1],
             [0, 1, 0, 1],
             [0, 0, 1, 1],
             [1, 0, 0, 1],
             [0, 0, 1, 1],
             [0, 1, 0, 1],
             [1, 0, 0, 1],
             [0, 1, 0, 1],
             [0, 0, 1, 1],
             [1, 0, 0, 1],
             [0, 0, 1, 1],
             [0, 1, 0, 1]]
  });

O3D.Model Method: update

Update the model matrix. Useful to update changes to the position, rotation or scale properties.

Syntax:

model.update();

Examples:

Change the position of the pyramid model and update its matrix.

  pyramid.position = {
    x: 10,
    y: 10,
    z: 20
  };
  
  pyramid.update();

O3D.Model Method: toFloat32Array

Returns a Float32Array version of the named property.

Syntax:

model.toFloat32Array(name);

Arguments:

  1. name - (string) The name of the property to be converted into a Float32Array. Can be vertices, normals, colors, etc.

Examples:

Make the pyramid model return a Float32Array of the vertices array.

  pyramid.toFloat32Array('vertices'); //returns the Float32Array of the vertices array.

O3D.Model Method: toUint16Array

Returns a Uint16Array version of the named property.

Syntax:

model.toUint16Array(name);

Arguments:

  1. name - (string) The name of the property to be converted into a Uint16Array. Can be indices, etc.

Examples:

Make the pyramid model return a Uint16Array of the vertices array.

  pyramid.toUint16Array('indices'); //returns the Uint16Array of the indices array.

O3D Class: O3D.Cube

Creates a Cube model. Inherits instance methods from O3D.Model.

Extends

O3D.Model

O3D.Cube Method: constructor

The main constructor function for the Cube class. Use this to create a new Cube. Accepts the same properties and options as O3D.Model constructor but has preset for vertices, normals and indices.

Syntax:

var model = new PhiloGL.O3D.Cube(options);

Arguments:

  1. options - (object) The same options as in O3D.Model constructor but has preset for vertices, normals and indices.

Examples:

Create a white cube.

var whiteCube = new PhiloGL.O3D.Cube({
      colors: [1, 1, 1, 1]
    });

O3D Class: O3D.Sphere

Creates a Sphere model.

Extends

O3D.Model

O3D.Sphere Method: constructor

The main constructor function for the Sphere class. Use this to create a new Sphere.

Syntax:

var model = new PhiloGL.O3D.Sphere(options);

Arguments:

  1. options - (object) An object containing as poperties:

Options:

Examples:

Create a white Sphere of radius 2.

var whiteSphere = new PhiloGL.O3D.Sphere({
  radius: 2,
  colors: [1, 1, 1, 1]
});