The Geometry class enables you to create a collection of vertex array attribute buffers representing a geometric primitive.
The main constructor function for the Geometry class. Use this to create a new Geometry.
const model = new Model(options);
TRIANGLES, TRIANGLE_STRIP, POINTS, LINES. Default’s TRIANGLES.color attribute as a single color, then the array will
be cloned to match the number of components for the model and will be
served as an attribute. The getter for this property will return the
cloned typed array.Create a pyramid model (used in lesson 4 of learning WebGL examples).
var pyramid = new 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]
});Create a pyramid model and add some extra buffer information and uniform color to be set before rendering the model.
var fromVertices = [ 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];
var toVertices = fromVertices.map(function(value) { return value * 2; });
var pyramid = new Model({
vertices: fromVertices,
uniforms: {
colorUfm: [0.3, 0.2, 0.7, 1]
},
attributes: {
endPosition: {
//default is type: gl.FLOAT
attribute: 'endPosition',
size: 3,
value: new Float32Array(toVertices)
}
}
});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 = new Vec3(10, 10, 20);
pyramid.update();Creates a Cube model. Inherits methods from Model.
Model
The main constructor function for the Cube class. Use this to create a new Cube. Accepts the same properties and
options as Model constructor but has preset for vertices, normals and indices.
var model = new Cube(options);
vertices, normals and indices.Create a white cube.
var whiteCube = new Cube({
colors: [1, 1, 1, 1]
});Creates a Sphere model. Inherits methods from Model.
Model
The main constructor function for the Sphere class. Use this to create a new Sphere.
var model = new Sphere(options);
Create a white Sphere of radius 2.
var whiteSphere = new Sphere({
radius: 2,
colors: [1, 1, 1, 1]
});Creates a Sphere model by subdividing an Icosahedron. Inherits methods from Model.
Model
The main constructor function for the IcoSphere class. Use this to create a new IcoSphere.
var model = new IcoSphere(options);
Create a white IcoSphere of radius 1.
var whiteSphere = new IcoSphere({
iterations: 1,
colors: [1, 1, 1, 1]
});Creates a plane. Inherits methods from Model.
Model
The main constructor function for the Plane class. Use this to create a new Plane.
var model = new Plane(options);
x,y, x,z, y,z.x,z or x,y planes.y,z or x,y planes.x,z or y,z planes.x,z or x,y planes.y,z or x,y planes.x,z or y,z planes.Create a white XZ plane.
var whitePlane = new Plane({
type: 'x,z',
xlen: 10,
zlen: 20,
nx: 5,
nz: 5,
offset: 0,
colors: [1, 1, 1, 1]
});Creates a Cylinder model. Inherits methods from Model.
Model
The main constructor function for the Cylinder class. Use this to create a new Cylinder.
var model = new Cylinder(options);
Create a white Cylinder of radius 2 and height 3.
var whiteCylinder = new Cylinder({
radius: 2,
height: 3,
colors: [1, 1, 1, 1]
});Creates a Cone model. Inherits methods from Model.
Model
The main constructor function for the Cone class. Use this to create a new Cone.
var model = new Cone(options);
Create a white Cone of base radius 2 and height 3.
var whiteCone = new Cone({
radius: 2,
height: 3,
cap: true,
colors: [1, 1, 1, 1]
});