createMesh method

dynamic createMesh(
  1. dynamic relationships,
  2. Map geometryMap,
  3. dynamic materialMap
)

Implementation

createMesh(relationships, Map geometryMap, materialMap) {
  var model;
  var geometry;
  var material;
  var materials = [];

  // get geometry and materials(s) from connections
  relationships["children"].forEach((child) {
    if (geometryMap.containsKey(child["ID"])) {
      geometry = geometryMap[child["ID"]];
    }

    if (materialMap.containsKey(child["ID"])) {
      materials.add(materialMap[child["ID"]]);
    }
  });

  if (materials.length > 1) {
    material = materials;
  } else if (materials.isNotEmpty) {
    material = materials[0];
  } else {
    material = MeshPhongMaterial({"color": 0xcccccc});
    materials.add(material);
  }

  if (geometry.attributes["color"] != null) {
    for (var material in materials) {
      material.vertexColors = true;
    }
  }

  if (geometry.userData["FBX_Deformer"] != null) {
    model = SkinnedMesh(geometry, material);
    model.normalizeSkinWeights();
  } else {
    model = Mesh(geometry, material);
  }

  return model;
}