toJSON method

Map<String, dynamic> toJSON({
  1. Object3dMeta? meta,
})

Implementation

Map<String, dynamic> toJSON({Object3dMeta? meta}) {
  Map<String, dynamic> data = {
    "metadata": {
      "version": 4.5,
      "type": 'BufferGeometry',
      "generator": 'BufferGeometry.toJSON'
    }
  };

  // standard BufferGeometry serialization

  data["uuid"] = uuid;
  data["type"] = type;
  if (name != '') data["name"] = name;
  if (userData.keys.isNotEmpty) data["userData"] = userData;

  if (parameters != null) {
    for (var key in parameters!.keys) {
      if (parameters![key] != null) data[key] = parameters![key];
    }

    return data;
  }

  // for simplicity the code assumes attributes are not shared across geometries, see #15811

  data["data"] = {};
  data["data"]["attributes"] = {};

  var index = this.index;

  if (index != null) {
    // TODO
    data["data"]["index"] = {
      "type": index.array.runtimeType.toString(),
      "array": index.array.sublist(0)
    };
  }

  var attributes = this.attributes;

  for (var key in attributes.keys) {
    var attribute = attributes[key];

    // TODO
    // data["data"]["attributes"][ key ] = attribute.toJSON( data["data"] );
    data["data"]["attributes"][key] = attribute.toJSON();
  }

  Map<String, List<BufferAttribute>> morphAttributes = {};
  bool hasMorphAttributes = false;

  for (var key in morphAttributes.keys) {
    var attributeArray = this.morphAttributes[key]!;

    List<BufferAttribute> array = [];

    for (var i = 0, il = attributeArray.length; i < il; i++) {
      var attribute = attributeArray[i];

      // TODO
      // var attributeData = attribute.toJSON( data["data"] );
      //var attributeData = attribute.toJSON();

      array.add(attribute);
    }

    if (array.isNotEmpty) {
      morphAttributes[key] = array;

      hasMorphAttributes = true;
    }
  }

  if (hasMorphAttributes) {
    data["data"].morphAttributes = morphAttributes;
    data["data"].morphTargetsRelative = morphTargetsRelative;
  }

  var groups = this.groups;

  if (groups.isNotEmpty) {
    data["data"]["groups"] = json.decode(json.encode(groups));
  }

  var boundingSphere = this.boundingSphere;

  if (boundingSphere != null) {
    data["data"]["boundingSphere"] = {
      "center": boundingSphere.center.toArray(List.filled(3, 0)),
      "radius": boundingSphere.radius
    };
  }

  return data;
}