json MaterialData::serialize()

in src/gltf/properties/MaterialData.cpp [94:133]


json MaterialData::serialize() const {
  json result = {{"name", name},
                 {"alphaMode", isTransparent ? "BLEND" : "OPAQUE"},
                 {"extras",
                  {{"fromFBX",
                    {{"shadingModel", Describe(shadingModel)},
                     {"isTruePBR", shadingModel == RAW_SHADING_MODEL_PBR_MET_ROUGH}}}}}};

  if (normalTexture != nullptr) {
    result["normalTexture"] = *normalTexture;
  }
  if (occlusionTexture != nullptr) {
    result["occlusionTexture"] = *occlusionTexture;
  }
  if (emissiveTexture != nullptr) {
    result["emissiveTexture"] = *emissiveTexture;
  }
  if (emissiveFactor.LengthSquared() > 0) {
    result["emissiveFactor"] = toStdVec(emissiveFactor);
  }
  if (pbrMetallicRoughness != nullptr) {
    result["pbrMetallicRoughness"] = *pbrMetallicRoughness;
  }
  if (khrCmnConstantMaterial != nullptr) {
    json extensions = {};
    extensions[KHR_MATERIALS_CMN_UNLIT] = *khrCmnConstantMaterial;
    result["extensions"] = extensions;
  }

  for (const auto& i : userProperties) {
    auto& prop_map = result["extras"]["fromFBX"]["userProperties"];

    json j = json::parse(i);
    for (const auto& k : json::iterator_wrapper(j)) {
      prop_map[k.key()] = k.value();
    }
  }

  return result;
}