uploadVertexData method

void uploadVertexData(
  1. ByteData vertices,
  2. int vertexCount,
  3. ByteData? indices, {
  4. IndexType indexType = gpu.IndexType.int16,
})

Allocates a gpu.DeviceBuffer and uploads vertices (and optional indices) into it in one step.

The vertices must match this geometry subclass's expected interleaved layout (72 bytes per vertex for UnskinnedGeometry, 104 bytes for SkinnedGeometry). The subclass may split the interleaved bytes into several tightly packed streams (see _vertexStreamBytes); the streams and any indices are packed back-to-back into one buffer, the streams bound via setVertexStreams and the indices via setIndices.

Implementation

void uploadVertexData(
  ByteData vertices,
  int vertexCount,
  ByteData? indices, {
  gpu.IndexType indexType = gpu.IndexType.int16,
}) {
  final stride = _expectedVertexStrideInBytes;
  if (stride != null && vertices.lengthInBytes != vertexCount * stride) {
    throw ArgumentError(
      'uploadVertexData got ${vertices.lengthInBytes} bytes for $vertexCount '
      'vertices, but $runtimeType packs a $stride-byte vertex, so it needs '
      '${vertexCount * stride} bytes. Repack at $stride bytes per vertex '
      '(position 3, normal 3, tex_coords_0 2, tex_coords_1 2, color 4, '
      'tangent 4'
      '${stride == kSkinnedPerVertexSize ? ', joints 4, weights 4' : ''}, '
      'all float32, in that order), or supply attributes as separate arrays '
      'with MeshGeometry.fromArrays.',
    );
  }

  _cpuVertices = vertices;
  _cpuIndices = indices;

  _uploadStreams(
    _vertexStreamBytes(vertices, vertexCount),
    vertexCount,
    indices,
    indexType,
    null,
  );

  if (_localBounds == null && vertexCount > 0 && _autoScanBoundsOnUpload) {
    _scanLocalBoundsFromVertices(vertices, vertexCount);
  }
}