# What does p5.Geometry do and how to use it?

**URL:** <https://discourse.processing.org/t/what-does-p5-geometry-do-and-how-to-use-it/29919>\
**Category:** Beginners\
**Created:** [May 6, 2021, 5:11pm UTC](https://discourse.processing.org/t/what-does-p5-geometry-do-and-how-to-use-it/29919 "2021-05-06T17:11:31Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![KumuPaul](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kumupaul/32/13072_2.png) [@KumuPaul](https://discourse.processing.org/u/KumuPaul)\
**Post date:** [May 6, 2021, 7:25pm UTC](https://discourse.processing.org/t/what-does-p5-geometry-do-and-how-to-use-it/29919/2 "2021-05-06T19:25:44Z")

</div>

p5.Geometry is used to represent 3d objects. It is returned by the [`loadModel()` function](https://p5js.org/reference/#/p5/loadModel), and also used internally by the 3d primitive drawing functions. 3d objects are commonly described as a list of vertices, a list of vertex normals, a list of triangles which reference the vertexes, and a list of texture coordinates for each vertex. Vertex normals are a vector describing the direction of the surface of the object at that point which is used to affect how light will illuminate a surface based on the angle of the light relative to the angle of the surface.

The most common use case for p5.Geometry is via the loadModel() function, but it is possible to create your own custom 3d objects via the callback that can be passed to the p5.Geometry constructor. In this callback you need to populate: the `vertices` array with vectors representing the corners of all the triangles, the `faces` array with arrays of indices for the corners of each triangle, and if you want to apply a texture, the `uvs` array with arrays containing the X and Y position in texture space for each vertex (order and length should be the same as the `vertices` array). I have an example in a [glitch project (see /haumana/kumu-paul/sprite-voxel.js)](https://glitch.com/edit/#!/code-haumana-p5js?path=haumana%2Fkumu-paul%2Fsprite-voxel.js%3A274%3A12), but it’s pretty complicated ([here’s the running version](https://code-haumana-p5js.glitch.me/haumana/kumu-paul.html?sketch=7)).

---

_[View the full topic](https://discourse.processing.org/t/what-does-p5-geometry-do-and-how-to-use-it/29919)._
