1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-08 12:40:44 +00:00

ColorIndex supported now for vertex colors.

Other properties should index override where appropriate in future.
This commit is contained in:
Gordon MacPherson
2020-12-14 16:50:46 +00:00
parent ee903becc8
commit 8ffad0d8bd
4 changed files with 122 additions and 16 deletions

View File

@@ -211,7 +211,33 @@ MeshGeometry::MeshGeometry(uint64_t id, const ElementPtr element, const std::str
} else if (layer_type_name == "LayerElementNormal") {
m_normals = resolve_vertex_data_array<Vector3>(layer_scope, MappingInformationType, ReferenceInformationType, "Normals");
} else if (layer_type_name == "LayerElementColor") {
m_colors = resolve_vertex_data_array<Color>(layer_scope, MappingInformationType, ReferenceInformationType, "Colors");
m_colors = resolve_vertex_data_array<Color>(layer_scope, MappingInformationType, ReferenceInformationType, "Colors", "ColorIndex");
// NOTE: this is a useful sanity check to ensure you're getting any color data which is not default.
// const Color first_color_check = m_colors.data[0];
// bool colors_are_all_the_same = true;
// size_t i = 1;
// for(i = 1; i < m_colors.data.size(); i++)
// {
// const Color current_color = m_colors.data[i];
// if(current_color.is_equal_approx(first_color_check))
// {
// continue;
// }
// else
// {
// colors_are_all_the_same = false;
// break;
// }
// }
//
// if(colors_are_all_the_same)
// {
// print_error("Color serialisation is not working for vertex colors some should be different in the test asset.");
// }
// else
// {
// print_verbose("Color array has unique colors at index: " + itos(i));
// }
}
}
}
@@ -335,12 +361,22 @@ MeshGeometry::MappingData<T> MeshGeometry::resolve_vertex_data_array(
const ScopePtr source,
const std::string &MappingInformationType,
const std::string &ReferenceInformationType,
const std::string &dataElementName) {
const std::string &dataElementName,
const std::string &indexOverride) {
ERR_FAIL_COND_V_MSG(source == nullptr, MappingData<T>(), "Invalid scope operator preventing memory corruption");
// UVIndex, MaterialIndex, NormalIndex, etc..
std::string indexDataElementName = dataElementName + "Index";
std::string indexDataElementName;
if (indexOverride != "") {
// Colors should become ColorIndex
indexDataElementName = indexOverride;
} else {
// Some indexes will exist.
indexDataElementName = dataElementName + "Index";
}
// goal: expand everything to be per vertex
ReferenceType l_ref_type = ReferenceType::direct;