Function createBuffersAndAttributesFromArrays

  • Given arrays, create buffers, fills the buffers with data if provided, optionally interleaves the data (the default).

    Example:

     const {
    buffers,
    bufferLayouts,
    indexBuffer,
    indexFormat,
    numElements,
    } = createBuffersAndAttributesFromArrays(device, {
    position: [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],
    normal: [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],
    texcoord: [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],
    indices: [0, 1, 2, 0, 2, 3, 4, 5, 6, 4, 6, 7, 8, 9, 10, 8, 10, 11, 12, 13, 14, 12, 14, 15, 16, 17, 18, 16, 18, 19, 20, 21, 22, 20, 22, 23],
    });

    Where bufferLayouts will be

    [
    {
    stepMode: 'vertex',
    arrayStride: 32,
    attributes: [
    { shaderLocation: 0, offset: 0, format: 'float32x3' },
    { shaderLocation: 1, offset: 12, format: 'float32x3' },
    { shaderLocation: 2, offset: 24, format: 'float32x2' },
    ],
    },
    ]
    • buffers will have one GPUBuffer of usage GPUBufferUsage.VERTEX
    • indexBuffer will be GPUBuffer of usage GPUBufferUsage.INDEX
    • indexFormat will be uint32 (use a full spec or a typedarray of Uint16Array if you want 16bit indices)
    • numElements will be 36 (this is either the number entries in the array named indices or if no indices are provided then it's the length of the first array divided by numComponents. See Arrays)

    See Arrays for details on the various types of arrays. Also see the cube and instancing examples.

    Parameters

    Returns BuffersAndAttributes

Generated using TypeDoc