# Class Primitives

java.lang.Object
com.codename1.gpu.Primitives

public final class Primitives extends Object
Factory helpers that build common `Mesh` primitives. Every primitive uses the `VertexFormat.POSITION_NORMAL_TEXCOORD` layout so it can be drawn with any of the built in materials, lit or unlit, textured or not.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static Mesh`
  `cube(GraphicsDevice device, float size)`
  Builds a unit-normal axis aligned cube centered at the origin with the supplied edge length.
  `static Mesh`
  `quad(GraphicsDevice device, float size)`
  Builds a flat quad in the XY plane centered at the origin facing +Z.
  `static Mesh`
  `sphere(float radius, int latBands, int lonBands, boolean insideOut)`
  Builds a UV sphere without a `GraphicsDevice`, allocating the buffers directly.
  `static Mesh`
  `sphere(GraphicsDevice device, float radius, int latBands, int lonBands, boolean insideOut)`
  Builds a UV sphere centered at the origin with equirectangular texture coordinates: `u` wraps the longitude from 0 to 1 and `v` runs from 0 at the north pole (+Y) to 1 at the south pole.

  ### Methods inherited from class Object

  `clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Method Details

  - ### cube

    public static Mesh cube(GraphicsDevice device, float size)

    Builds a unit-normal axis aligned cube centered at the origin with the supplied edge length. Each face has its own normals and a full 0..1 texture coordinate quad.

    ###### Parameters

    - `device`: the device that allocates the buffers

    - `size`: the edge length of the cube

    ###### Returns

    an indexed triangle mesh

  - ### quad

    public static Mesh quad(GraphicsDevice device, float size)

    Builds a flat quad in the XY plane centered at the origin facing +Z.

    ###### Parameters

    - `device`: the device that allocates the buffers

    - `size`: the edge length of the quad

    ###### Returns

    an indexed triangle mesh

  - ### sphere

    public static Mesh sphere(GraphicsDevice device, float radius, int latBands, int lonBands, boolean insideOut)

    Builds a UV sphere centered at the origin with equirectangular texture coordinates: `u` wraps the longitude from 0 to 1 and `v` runs from 0 at the north pole (+Y) to 1 at the south pole. This is the mapping used by 360 degree panorama images. The seam column and the pole rows duplicate vertices so texture coordinates stay continuous. For an inside-out sphere the `u` direction is reversed so a panorama viewed from the center reads correctly instead of mirror-imaged.

    ###### Parameters

    - `device`: the device that allocates the buffers

    - `radius`: the sphere radius

    - `latBands`: the number of latitude subdivisions, at least 2

    - `lonBands`: the number of longitude subdivisions, at least 3

    - `insideOut`: when true the normals point toward the center and the winding is flipped so the inner surface faces the viewer, as needed when rendering a panorama from inside the sphere

    ###### Returns

    an indexed triangle mesh

  - ### sphere

    public static Mesh sphere(float radius, int latBands, int lonBands, boolean insideOut)

    Builds a UV sphere without a `GraphicsDevice`, allocating the buffers directly. Behaves exactly like `sphere(GraphicsDevice, float, int, int, boolean)`; useful for preparing geometry off the render thread or handing meshes to non GPU consumers such as the AR content pipeline.

    ###### Parameters

    - `radius`: the sphere radius

    - `latBands`: the number of latitude subdivisions, at least 2

    - `lonBands`: the number of longitude subdivisions, at least 3

    - `insideOut`: when true the normals point toward the center and the winding is flipped

    ###### Returns

    an indexed triangle mesh