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) {
      BufferGeometry _geometry = geometries
          .firstWhere((element) => element.uuid == json["geometry"]);
      geometry = _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>> _children = json["children"];
    for (var _child in _children) {
      final obj = Object3D.castJSON(_child, rootJSON);
      if (obj is Object3D) children.add(obj);
    }
  }
}