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
.New in version 1.3:
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.toFloat32Array
and toUint16Array
methods are not used anymore since the typed array can now be fetched when accessing the model property directly.shininess
, reflection
and refraction
properties are now set in the uniforms
object. Below is a description of the attributes.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]
});
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 PhiloGL.O3D.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 = {
x: 10,
y: 10,
z: 20
};
pyramid.update();
Creates a Cube model. Inherits 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. Inherits methods from O3D.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]
});
Creates a Sphere model by subdividing an Icosahedron. Inherits methods from O3D.Model.
O3D.Model
The main constructor function for the IcoSphere class. Use this to create a new IcoSphere.
var model = new PhiloGL.O3D.IcoSphere(options);
Create a white IcoSphere of radius 1.
var whiteSphere = new PhiloGL.O3D.IcoSphere({
iterations: 1,
colors: [1, 1, 1, 1]
});
Creates a plane. Inherits methods from O3D.Model.
O3D.Model
The main constructor function for the Plane class. Use this to create a new Plane.
var model = new PhiloGL.O3D.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 PhiloGL.O3D.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 O3D.Model.
O3D.Model
The main constructor function for the Cylinder class. Use this to create a new Cylinder.
var model = new PhiloGL.O3D.Cylinder(options);
Create a white Cylinder of radius 2 and height 3.
var whiteCylinder = new PhiloGL.O3D.Cylinder({
radius: 2,
height: 3,
colors: [1, 1, 1, 1]
});
Creates a Cone model. Inherits methods from O3D.Model.
O3D.Model
The main constructor function for the Cone class. Use this to create a new Cone.
var model = new PhiloGL.O3D.Cone(options);
Create a white Cone of base radius 2 and height 3.
var whiteCone = new PhiloGL.O3D.Cone({
radius: 2,
height: 3,
cap: true,
colors: [1, 1, 1, 1]
});