lullaby/tools/model_pipeline/model.cc
// Hashes the values for all the textures and properties stored in a Material.
// This should be sufficient to perform material deduplication.
Hashes the values for all the textures and properties stored in a Material.
This should be sufficient to perform material deduplication.
Hashes the values for all the textures and properties stored in a Material . This should be sufficient to perform material deduplication .
static size_t MaterialHash(const Material& material) {
  uint64_t hash = 0;
  for (auto& it : material.properties) {
    hash ^= std::hash<std::string>()(it.first);
    const TypeId type = it.second.GetTypeId();
    if (type == GetTypeId<bool>()) {
      hash ^= std::hash<bool>()(*it.second.Get<bool>());
    } else if (type == GetTypeId<int>()) {
      hash ^= std::hash<int>()(*it.second.Get<int>());
    } else if (type == GetTypeId<float>()) {
      hash ^= std::hash<float>()(*it.second.Get<float>());
    } else if (type == GetTypeId<double>()) {
      hash ^= std::hash<double>()(*it.second.Get<double>());
    } else if (type == GetTypeId<std::string>()) {
      hash ^= std::hash<std::string>()(*it.second.Get<std::string>());
    } else if (type == GetTypeId<mathfu::vec2>()) {
      hash ^= std::hash<float>()(it.second.Get<mathfu::vec2>()->x);
      hash ^= std::hash<float>()(it.second.Get<mathfu::vec2>()->y);
    } else if (type == GetTypeId<mathfu::vec3>()) {
      hash ^= std::hash<float>()(it.second.Get<mathfu::vec3>()->x);
      hash ^= std::hash<float>()(it.second.Get<mathfu::vec3>()->y);
      hash ^= std::hash<float>()(it.second.Get<mathfu::vec3>()->z);
    } else if (type == GetTypeId<mathfu::vec4>()) {
      hash ^= std::hash<float>()(it.second.Get<mathfu::vec4>()->x);
      hash ^= std::hash<float>()(it.second.Get<mathfu::vec4>()->y);
      hash ^= std::hash<float>()(it.second.Get<mathfu::vec4>()->z);
      hash ^= std::hash<float>()(it.second.Get<mathfu::vec4>()->w);
    } else {
      LOG(ERROR) << "Unknown type, bad hash: " << type;
    }
  }
  for (auto& it : material.textures) {
    hash ^= std::hash<std::string>()(it.first);
    for (auto& usage : it.second.usages) {
      hash ^= std::hash<int>()(usage);
    }
  }
  return static_cast<size_t>(hash);
}
static size_t MaterialHash ( const Material & material ) { uint64_t hash = 0 ; for ( auto & it : material . properties ) { hash ^= std :: hash < std :: string > ( ) ( it . first ) ; const TypeId type = it . second . GetTypeId ( ) ; if ( type == GetTypeId < bool > ( ) ) { hash ^= std :: hash < bool > ( ) ( * it . second . Get < bool > ( ) ) ; } else if ( type == GetTypeId < int > ( ) ) { hash ^= std :: hash < int > ( ) ( * it . second . Get < int > ( ) ) ; } else if ( type == GetTypeId < float > ( ) ) { hash ^= std :: hash < float > ( ) ( * it . second . Get < float > ( ) ) ; } else if ( type == GetTypeId < double > ( ) ) { hash ^= std :: hash < double > ( ) ( * it . second . Get < double > ( ) ) ; } else if ( type == GetTypeId < std :: string > ( ) ) { hash ^= std :: hash < std :: string > ( ) ( * it . second . Get < std :: string > ( ) ) ; } else if ( type == GetTypeId < mathfu :: vec2 > ( ) ) { hash ^= std :: hash < float > ( ) ( it . second . Get < mathfu :: vec2 > ( ) -> x ) ; hash ^= std :: hash < float > ( ) ( it . second . Get < mathfu :: vec2 > ( ) -> y ) ; } else if ( type == GetTypeId < mathfu :: vec3 > ( ) ) { hash ^= std :: hash < float > ( ) ( it . second . Get < mathfu :: vec3 > ( ) -> x ) ; hash ^= std :: hash < float > ( ) ( it . second . Get < mathfu :: vec3 > ( ) -> y ) ; hash ^= std :: hash < float > ( ) ( it . second . Get < mathfu :: vec3 > ( ) -> z ) ; } else if ( type == GetTypeId < mathfu :: vec4 > ( ) ) { hash ^= std :: hash < float > ( ) ( it . second . Get < mathfu :: vec4 > ( ) -> x ) ; hash ^= std :: hash < float > ( ) ( it . second . Get < mathfu :: vec4 > ( ) -> y ) ; hash ^= std :: hash < float > ( ) ( it . second . Get < mathfu :: vec4 > ( ) -> z ) ; hash ^= std :: hash < float > ( ) ( it . second . Get < mathfu :: vec4 > ( ) -> w ) ; } else { LOG ( ERROR ) << " " << type ; } } for ( auto & it : material . textures ) { hash ^= std :: hash < std :: string > ( ) ( it . first ) ; for ( auto & usage : it . second . usages ) { hash ^= std :: hash < int > ( ) ( usage ) ; } } return static_cast < size_t > ( hash ) ; }
Hashes the values for all the textures and properties stored in a Material.
Hashes the values for all the textures and properties stored in a Material .