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.
The class Model enables you to create 3D models which are compatible with the Scene class. All primitives (Sphere, etc) inherit from Model too.
A Model instance has a number of public properties that can be accessed/modified:
Vec3 indicating the position of the Model.Vec3 indicating the rotation of the Model.Vec3 indicating the scaling of the Model.Mat4 containing information about position, rotation and scale. This matrix gets updated each time the method update is called on a Model instance.The main constructor function for the Model class. Use this to create a new Model.
var model = new PhiloGL.O3D.Model(options);
TRIANGLES, TRIANGLE_STRIP, POINTS, LINES. Default’s TRIANGLES.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]]
});
Update the model matrix. Useful to update changes to the position, rotation or scale properties.
model.update();
Change the position of the pyramid model and update its matrix.
pyramid.position = {
x: 10,
y: 10,
z: 20
};
pyramid.update();
Returns a Float32Array version of the named property.
model.toFloat32Array(name);
Float32Array. Can be vertices, normals, colors, etc.Make the pyramid model return a Float32Array of the vertices array.
pyramid.toFloat32Array('vertices'); //returns the Float32Array of the vertices array.
Returns a Uint16Array version of the named property.
model.toUint16Array(name);
Uint16Array. Can be indices, etc.Make the pyramid model return a Uint16Array of the vertices array.
pyramid.toUint16Array('indices'); //returns the Uint16Array of the indices array.
Creates a Cube model. Inherits instance methods from O3D.Model.
O3D.Model
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.
var model = new PhiloGL.O3D.Cube(options);
vertices, normals and indices.Create a white cube.
var whiteCube = new PhiloGL.O3D.Cube({
colors: [1, 1, 1, 1]
});
Creates a Sphere model.
O3D.Model
The main constructor function for the Sphere class. Use this to create a new Sphere.
var model = new PhiloGL.O3D.Sphere(options);
Create a white Sphere of radius 2.
var whiteSphere = new PhiloGL.O3D.Sphere({
radius: 2,
colors: [1, 1, 1, 1]
});