The geometry component provides a basic shape for an entity. The general geometry is defined by the primitive property. Geometric primitives, in computer graphics, means an extremely basic shape. With the primitive defined, additional properties are used to further define the geometry. A material component is usually defined alongside to provide a appearance alongside the shape to create a complete mesh.
Properties
We will go through the basic primitives and their respective properties one by one.
Property
Description
Default Value
primitive
One of box, circle, cone, cylinder, plane, ring, sphere, torus, torusKnot.
None
translate
Translates the geometry relative to its pivot point.
0 0 0
Box
The box primitive defines boxes (i.e., any quadilateral, not just cubes).
The circle primitive defines two-dimensional circles, which can be complete circles or partial circles (like Pac-Man). Note that because it is flat, only a single side of the circle will be rendered if “side: double” is not specified on the material component.
Whether the ends of the cone are open (true) or capped (false).
false
radiusBottom
Radius of the bottom end of the cone.
1
radiusTop
Radius of the top end of the cone.
1
segmentsRadial
Number of segmented faces around the circumference of the cone.
36
segmentsHeight
Number of rows of faces along the height of the cone.
18
thetaStart
Starting angle in degrees.
0
thetaLength
Central angle in degrees.
360
Cylinder Primitive
The cylinder primitive can define cylinders in the traditional sense like a Coca-Cola™ can, but it can also define shapes such as tubes and curved surfaces. We’ll go over some of these cylinder recipes below.
Basic Cylinder
Traditional cylinders can be defined by using only a height and a radius:
Tubes can be defined by making the cylinder open-ended, which removes the top and bottom surfaces of the cylinder such that the inside is visible. A double-sided material will be needed to render properly:
Curved surfaces can be defined by specifying the angle via thetaLength such that the cylinder doesn’t curve all the way around, making the cylinder open-ended, and then making the material double-sided.
To play with an example of prism geometry, check out the [Hexagon example on Codepen][hexagon-codepen].
Plane
The plane primitive defines a flat surface. Note that because it is flat, only a single side of the plane will be rendered if side: double is not specified on the material component.
The ring geometry defines a flat ring, like a [CD][cd]. Note that because it is flat, only a single side of the ring will be rendered if side: double is not specified on the material component.
Number of segments. A higher number means the ring will be more round.
32
segmentsPhi
Number of triangles within each face defined by segmentsTheta.
8
thetaStart
Starting angle in degrees.
0
thetaLength
Central angle in degrees.
360
Sphere
The sphere primitive can define spheres in the traditional sense like a basketball. But it can also define various polyhedrons and abstract shapes given that it can specify the number of horizontal and vertical angles and faces.
Sticking with a basic sphere, the default number of segments is high enough to make the sphere appear round.
Number of segments along the circumference of the tube ends. A higher number means the tube will be more round.
36
segmentsTubular
Number of segments along the circumference of the tube face. A higher number means the tube will be more round.
32
arc
Central angle.
360
Torus Knot
The torus knot primitive defines a pretzel shape, the particular shape of which is defined by a pair of coprime integers, p and q. If p and q are not coprime the result will be a torus link.
Number of segments along the circumference of the tube ends. A higher number means the tube will be more round.
36
segmentsTubular
Number of segments along the circumference of the tube face. A higher number means the tube will be more round.
32
p
Number that helps define the pretzel shape.
2
q
Number that helps define the pretzel shape.
3
thetaLength and thetaStart
In degrees, thetaStart defines where to start a circle and thetaLength defines where a circle ends. If we wanted to make a ( shape, we would start the circle halfway through and define the length as half of a circle. We can do this with thetaStart: 180; thetaLength: 180. Or if we wanted to make a ) shape. We can do do thetaStart: 0; thetaLength: 180.
Useful cases might be to animating thetaStart to create a spinner effect or animating thetaLength on a fuse-based cursor for visual feedback.
translate
The translate property translates the geometry. It is provided as a vec3. This is a useful short-hand for translating the geometry to effectively move its pivot point when running animations.
<!-- Translates the sphere such that its effective pivot point is at its bottom --> <a-entitygeometry="primitive: sphere; radius: 1; translate: 0 1 0"></a-entity>
Defining Your Own Geometry
If there is a geometry that you need that is not provided by the standard geometry component, you can register your own geometry component. Later, we may introduce an API to register geometries:
AFRAME.registerComponent('my-geometry', {
/* Called on component attach and data update. */
update: function () {
// Grab the mesh.
var mesh = this.el.getOrCreateObject3D('mesh', THREE.Mesh);
// Provide your own geometry.
var geometry = mesh.geometry = new THREE.Geometry();
geometry.vertices.push(
new THREE.Vector3(-10, 10, 0),
new THREE.Vector3(-10, -10, 0),
new THREE.Vector3( 10, -10, 0)
);
geometry.faces.push(new THREE.Face3(0, 1, 2));
geometry.computeBoundingSphere();
},
/* Called on component detach. */
remove: function () {
this.el.getObject3D('mesh').geometry = new THREE.Geometry();
}
});
[cd]: https://en.wikipedia.org/wiki/Compact_disc
[hexagon-codepen]: http://codepen.io/team/mozvr/pen/jWzVXJ
[prisms-wiki]: https://en.wikipedia.org/wiki/Prism_%28geometry%29