toJSON method

  1. @override
Map<String, Object> toJSON([
  1. dynamic data
])
override

Implementation

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

    var array = [];

    for (var i = 0; i < count; i++) {
      var index = i * this.data!.stride + offset;

      for (var j = 0; j < itemSize; j++) {
        array.add(this.data!.array[index + j]);
      }
    }

    // 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
    };
  }
}