Mesh: Forward compatibility with generic crease in 4.0
e5ec04d73cchanged the way crease vakyes are stored in 4.0. Add versioning for reading the new files that replaces the new generic attributes with the old non-generic custom data layers. The code is paranoid with lots fo checks I expect will typically not be necessary. Similar tof75af7cbf5
This commit is contained in:
@@ -48,6 +48,7 @@ void BKE_mesh_legacy_edge_crease_from_layers(struct Mesh *mesh);
|
||||
* Copy edge creases from edges to a separate layer.
|
||||
*/
|
||||
void BKE_mesh_legacy_edge_crease_to_layers(struct Mesh *mesh);
|
||||
void BKE_mesh_crease_layers_from_future(struct Mesh *mesh);
|
||||
|
||||
/**
|
||||
* Copy bevel weights from separate layers into vertices and edges.
|
||||
|
||||
@@ -1449,7 +1449,7 @@ void BKE_mesh_legacy_bevel_weight_to_layers(Mesh *mesh)
|
||||
/** \} */
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/** \name Edge Crease Conversion
|
||||
/** \name Crease Conversion
|
||||
* \{ */
|
||||
|
||||
void BKE_mesh_legacy_edge_crease_from_layers(Mesh *mesh)
|
||||
@@ -1488,6 +1488,40 @@ void BKE_mesh_legacy_edge_crease_to_layers(Mesh *mesh)
|
||||
}
|
||||
}
|
||||
|
||||
void BKE_mesh_crease_layers_from_future(Mesh *mesh)
|
||||
{
|
||||
using namespace blender;
|
||||
using namespace blender::bke;
|
||||
if (const std::optional<AttributeMetaData> meta_data = mesh->attributes().lookup_meta_data(
|
||||
"crease_vert"))
|
||||
{
|
||||
if (meta_data->domain == ATTR_DOMAIN_POINT && meta_data->data_type == CD_PROP_FLOAT) {
|
||||
if (const void *data = CustomData_get_layer_named(
|
||||
&mesh->vdata, CD_PROP_FLOAT, "crease_vert")) {
|
||||
if (void *new_data = CustomData_add_layer(
|
||||
&mesh->vdata, CD_CREASE, CD_CONSTRUCT, mesh->totvert)) {
|
||||
memcpy(new_data, data, sizeof(float) * mesh->totvert);
|
||||
CustomData_free_layer_named(&mesh->vdata, "crease_vert", mesh->totvert);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (const std::optional<AttributeMetaData> meta_data = mesh->attributes().lookup_meta_data(
|
||||
"crease_edge"))
|
||||
{
|
||||
if (meta_data->domain == ATTR_DOMAIN_EDGE && meta_data->data_type == CD_PROP_FLOAT) {
|
||||
if (const void *data = CustomData_get_layer_named(
|
||||
&mesh->edata, CD_PROP_FLOAT, "crease_edge")) {
|
||||
if (void *new_data = CustomData_add_layer(
|
||||
&mesh->edata, CD_CREASE, CD_CONSTRUCT, mesh->totedge)) {
|
||||
memcpy(new_data, data, sizeof(float) * mesh->totedge);
|
||||
CustomData_free_layer_named(&mesh->edata, "crease_edge", mesh->totedge);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
@@ -43,6 +43,7 @@ static void version_mesh_legacy_to_struct_of_array_format(Mesh &mesh)
|
||||
BKE_mesh_legacy_convert_polys_to_offsets(&mesh);
|
||||
BKE_mesh_legacy_convert_edges_to_generic(&mesh);
|
||||
BKE_mesh_bevel_weight_layers_from_future(&mesh);
|
||||
BKE_mesh_crease_layers_from_future(&mesh);
|
||||
}
|
||||
|
||||
static void version_motion_tracking_legacy_camera_object(MovieClip &movieclip)
|
||||
|
||||
Reference in New Issue
Block a user