addFloats method

int addFloats(
  1. List<double> values,
  2. String type, {
  3. bool withBounds = false,
})

Adds float data as an accessor of type (VEC3, …). Positions get min/max when withBounds.

Implementation

int addFloats(List<double> values, String type, {bool withBounds = false}) {
  final data = Float32List.fromList(values);
  final width = const {
    'SCALAR': 1,
    'VEC2': 2,
    'VEC3': 3,
    'VEC4': 4,
    'MAT4': 16,
  }[type]!;
  final accessor = <String, dynamic>{
    'bufferView': _view(data.buffer.asUint8List(), target: 34962),
    'componentType': 5126,
    'count': values.length ~/ width,
    'type': type,
  };
  if (withBounds) {
    final min = List<double>.filled(width, double.infinity);
    final max = List<double>.filled(width, double.negativeInfinity);
    for (var i = 0; i < values.length; i++) {
      final c = i % width;
      if (values[i] < min[c]) min[c] = values[i];
      if (values[i] > max[c]) max[c] = values[i];
    }
    accessor['min'] = min;
    accessor['max'] = max;
  }
  return _add('accessors', accessor);
}