webgpu-utils

    Function interleaveVertexData

    • Given an array of GPUVertexAttributes and a corresponding array of TypedArrays, interleaves the contents of the typed arrays into the given ArrayBuffer

      example:

      const attributes: GPUVertexAttribute[] = [
      { shaderLocation: 0, offset: 0, format: 'float32x3' },
      { shaderLocation: 1, offset: 12, format: 'float32x3' },
      { shaderLocation: 2, offset: 24, format: 'float32x2' },
      ];
      const typedArrays = [
      new Float32Array([1, 1, -1, 1, 1, 1, 1, -1, 1, 1, -1, -1, -1, 1, 1, -1, 1, -1, -1, -1, -1, -1, -1, 1, -1, 1, 1, 1, 1, 1, 1, 1, -1, -1, 1, -1, -1, -1, -1, 1, -1, -1, 1, -1, 1, -1, -1, 1, 1, 1, 1, -1, 1, 1, -1, -1, 1, 1, -1, 1, -1, 1, -1, 1, 1, -1, 1, -1, -1, -1, -1, -1]),
      new Float32Array([1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1]),
      new Float32Array([1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1]),
      ];
      const arrayStride = (3 + 3 + 2) * 4; // pos + nrm + uv
      const arrayBuffer = new ArrayBuffer(arrayStride * 24)
      interleaveVertexData(attributes, typedArrays, arrayStride, arrayBuffer)

      results in the contents of arrayBuffer to be the 3 TypedArrays interleaved

      See Arrays for details on the various types of arrays.

      Note: You can generate attributes and typedArrays above by calling createBufferLayoutsFromArrays

      Parameters

      Returns void

    MMNEPVFCICPMFPCPTTAAATR