Object3D.fromJSON constructor

Object3D.fromJSON(
  1. Map<String, dynamic> json,
  2. Map<String, dynamic> rootJSON
)

Implementation

Object3D.fromJSON(Map<String, dynamic> json, Map<String, dynamic> rootJSON) {
  uuid = json["uuid"];
  if (json["name"] != null) {
    name = json["name"]!;
  }
  type = json["type"];
  layers.mask = json["layers"];

  position = Vector3.fromJSON(json["position"]);
  quaternion = Quaternion.fromJSON(json["quaternion"]);
  scale = Vector3.fromJSON(json["scale"]);

  if (json["geometry"] != null) {
    List<BufferGeometry>? geometries = rootJSON["geometries"];

    if (geometries != null) {
      geometry = geometries.firstWhere((element) => element.uuid == json["geometry"]);
    }
  }

  if (json["material"] != null) {
    List<Material>? materials = rootJSON["materials"];

    if (materials != null) {
      Material material = materials.firstWhere((element) => element.uuid == json["material"]);
      material = material;
    }
  }

  init();

  if (json["children"] != null) {
    List<Map<String, dynamic>> jsonChildren = json["children"];
    for (var child in jsonChildren) {
      final obj = Object3D.castJSON(child, rootJSON);
      if (obj is Object3D) children.add(obj);
    }
  }
}