toJson method

  1. @override
Map<String, Object> toJson([
  1. InterleavedBuffer? data
])
override

Implementation

@override
Map<String, Object> toJson([InterleavedBuffer? data]) {
  if (data == null) {
    //print('InterleavedBufferAttribute.toJson(): Serializing an interlaved buffer attribute will deinterleave buffer data!.');

    List<double> array = [];

    for (int i = 0; i < count; i++) {
      final index = i * this.data!.stride + offset;
      for (int j = 0; j < itemSize; j++) {
        array.add(this.data!.array[index + j].toDouble());
      }
    }

    // deinterleave data and save it as an ordinary buffer attribute for now

    return {
      "itemSize": itemSize,
      "type": this.array.runtimeType.toString(),
      "array": array,
      "normalized": normalized
    };
  }
  else {
    // save as true interlaved attribtue

    // data.interleavedBuffers ??= {};

    // if (data.interleavedBuffers[this.data!.uuid] == null) {
    //   data.interleavedBuffers[this.data!.uuid] = this.data!.toJson(data);
    // }

    return {
      "isInterleavedBufferAttribute": true,
      "itemSize": itemSize,
      "data": this.data!.uuid,
      "offset": offset,
      "normalized": normalized
    };
  }
}