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(json["position"][0],json["position"][1],json["position"][2]);
  quaternion = Quaternion(json["quaternion"][0],json["quaternion"][1],json["quaternion"][2],json["quaternion"][3]);
  scale = Vector3(json["scale"][0],json["scale"][1],json["scale"][2]);

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

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

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

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

  init();

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