src/primitives.js
function createPlaneVertices(
    width,
    depth,
    subdivisionsWidth,
    subdivisionsDepth,
    matrix) {
  width = width || 1;
  depth = depth || 1;
  subdivisionsWidth = subdivisionsWidth || 1;
  subdivisionsDepth = subdivisionsDepth || 1;
  matrix = matrix || m4.identity();

  const numVertices = (subdivisionsWidth + 1) * (subdivisionsDepth + 1);
  const positions = createAugmentedTypedArray(3, numVertices);
  const normals = createAugmentedTypedArray(3, numVertices);
  const texcoords = createAugmentedTypedArray(2, numVertices);

  for (let z = 0; z <= subdivisionsDepth; z++) {
    for (let x = 0; x <= subdivisionsWidth; x++) {
      const u = x / subdivisionsWidth;
      const v = z / subdivisionsDepth;
      positions.push(
          width * u - width * 0.5,
          0,
          depth * v - depth * 0.5);
      normals.push(0, 1, 0);
      texcoords.push(u, v);
    }
  }

  const numVertsAcross = subdivisionsWidth + 1;
  const indices = createAugmentedTypedArray(
      3, subdivisionsWidth * subdivisionsDepth * 2, Uint16Array);

  for (let z = 0; z < subdivisionsDepth; z++) {  // eslint-disable-line
    for (let x = 0; x < subdivisionsWidth; x++) {  // eslint-disable-line
      // Make triangle 1 of quad.
      indices.push(
          (z + 0) * numVertsAcross + x,
          (z + 1) * numVertsAcross + x,
          (z + 0) * numVertsAcross + x + 1);

      // Make triangle 2 of quad.
      indices.push(
          (z + 1) * numVertsAcross + x,
          (z + 1) * numVertsAcross + x + 1,
          (z + 0) * numVertsAcross + x + 1);
    }
  }

  const arrays = reorientVertices({
    position: positions,
    normal: normals,
    texcoord: texcoords,
    indices: indices,
  }, matrix);
  return arrays;
}
function createPlaneVertices(
    width,
    depth,
    subdivisionsWidth,
    subdivisionsDepth,
    matrix) {
  width = width || 1;
  depth = depth || 1;
  subdivisionsWidth = subdivisionsWidth || 1;
  subdivisionsDepth = subdivisionsDepth || 1;
  matrix = matrix || m4.identity();

  const numVertices = (subdivisionsWidth + 1) * (subdivisionsDepth + 1);
  const positions = createAugmentedTypedArray(3, numVertices);
  const normals = createAugmentedTypedArray(3, numVertices);
  const texcoords = createAugmentedTypedArray(2, numVertices);

  for (let z = 0; z <= subdivisionsDepth; z++) {
    for (let x = 0; x <= subdivisionsWidth; x++) {
      const u = x / subdivisionsWidth;
      const v = z / subdivisionsDepth;
      positions.push(
          width * u - width * 0.5,
          0,
          depth * v - depth * 0.5);
      normals.push(0, 1, 0);
      texcoords.push(u, v);
    }
  }

  const numVertsAcross = subdivisionsWidth + 1;
  const indices = createAugmentedTypedArray(
      3, subdivisionsWidth * subdivisionsDepth * 2, Uint16Array);

  for (let z = 0; z < subdivisionsDepth; z++) {  // eslint-disable-line
    for (let x = 0; x < subdivisionsWidth; x++) {  // eslint-disable-line
      // Make triangle 1 of quad.
      indices.push(
          (z + 0) * numVertsAcross + x,
          (z + 1) * numVertsAcross + x,
          (z + 0) * numVertsAcross + x + 1);

      // Make triangle 2 of quad.
      indices.push(
          (z + 1) * numVertsAcross + x,
          (z + 1) * numVertsAcross + x + 1,
          (z + 0) * numVertsAcross + x + 1);
    }
  }

  const arrays = reorientVertices({
    position: positions,
    normal: normals,
    texcoord: texcoords,
    indices: indices,
  }, matrix);
  return arrays;
}
function createPlaneVertices ( width , depth , subdivisionsWidth , subdivisionsDepth , matrix ) { width = width || 1 ; depth = depth || 1 ; subdivisionsWidth = subdivisionsWidth || 1 ; subdivisionsDepth = subdivisionsDepth || 1 ; matrix = matrix || m4 . identity ( ) ; const numVertices = ( subdivisionsWidth + 1 ) * ( subdivisionsDepth + 1 ) ; const positions = createAugmentedTypedArray ( 3 , numVertices ) ; const normals = createAugmentedTypedArray ( 3 , numVertices ) ; const texcoords = createAugmentedTypedArray ( 2 , numVertices ) ; for ( let z = 0 ; z <= subdivisionsDepth ; z ++ ) { for ( let x = 0 ; x <= subdivisionsWidth ; x ++ ) { const u = x / subdivisionsWidth ; const v = z / subdivisionsDepth ; positions . push ( width * u - width * 0.5 , 0 , depth * v - depth * 0.5 ) ; normals . push ( 0 , 1 , 0 ) ; texcoords . push ( u , v ) ; } } const numVertsAcross = subdivisionsWidth + 1 ; const indices = createAugmentedTypedArray ( 3 , subdivisionsWidth * subdivisionsDepth * 2 , Uint16Array ) ; for ( let z = 0 ; z < subdivisionsDepth ; z ++ ) { // eslint-disable-line for ( let x = 0 ; x < subdivisionsWidth ; x ++ ) { // eslint-disable-line // Make triangle 1 of quad. indices . push ( ( z + 0 ) * numVertsAcross + x , ( z + 1 ) * numVertsAcross + x , ( z + 0 ) * numVertsAcross + x + 1 ) ; // Make triangle 2 of quad. indices . push ( ( z + 1 ) * numVertsAcross + x , ( z + 1 ) * numVertsAcross + x + 1 , ( z + 0 ) * numVertsAcross + x + 1 ) ; } } const arrays = reorientVertices ( { position : positions , normal : normals , texcoord : texcoords , indices : indices , } , matrix ) ; return arrays ; }
Creates XZ plane buffers.

The created plane has position, normal, and texcoord data

@param {WebGLRenderingContext} gl The WebGLRenderingContext.
@param {number} [width] Width of the plane. Default = 1
@param {number} [depth] Depth of the plane. Default = 1
@param {number} [subdivisionsWidth] Number of steps across the plane. Default = 1
@param {number} [subdivisionsDepth] Number of steps down the plane. Default = 1
@param {module:twgl/m4.Mat4} [matrix] A matrix by which to multiply all the vertices.
@return {Object.<string, WebGLBuffer>} The created plane buffers.
@memberOf module:twgl/primitives
@function createPlaneBuffers
 
Creates XZ plane vertices.

The created plane has position, normal, and texcoord data

@param {number} [width] Width of the plane. Default = 1
@param {number} [depth] Depth of the plane. Default = 1
@param {number} [subdivisionsWidth] Number of steps across the plane. Default = 1
@param {number} [subdivisionsDepth] Number of steps down the plane. Default = 1
@param {module:twgl/m4.Mat4} [matrix] A matrix by which to multiply all the vertices.
@return {Object.<string, TypedArray>} The created plane vertices.
@memberOf module:twgl/primitives
Creates XZ plane buffers .