Mesh: Move vertex/edge crease to generic attributes

Store subdivision surface creases in two new named float attributes:
- `crease_vert`
- `crease_edge`
This is similar to 2a56403cb0.

The attributes are naming conventions, so their data type and domain
aren't enforced, and may be interpolated when necessary. Editing tools
and the subdivision surface modifier use the hard-coded name. It might
be best if these were edited as generic attributes in the future, but
in the meantime using generic attributes helps.

The attributes are visible in the list, which is how they're now meant
to be removed. They are now interchangeable with any tool that works
with the generic attribute system-- even tools like vertex paint can
affect creases now.

This is a breaking change. Forward compatibility isn't preserved for
versions before 3.6, and the `crease` property in RNA is removed in
favor of making a smaller API surface area with just the attribute API.
`Mesh.vertex_creases` and `Mesh.edge_creases` now just return the
matching attribute if possible, and are now implemented in Python.
New functions `*ensure` and `*remove` also replace the operators to
add and remove the layers for Python.

A few extrude node test files have to be updated because of different
(now generic) attribute interpolation behavior.

Pull Request: https://projects.blender.org/blender/blender/pulls/108089
This commit is contained in:
Hans Goudey
2023-06-13 20:23:39 +02:00
committed by Hans Goudey
parent f32bd8f804
commit e5ec04d73c
41 changed files with 344 additions and 617 deletions

View File

@@ -88,9 +88,6 @@ PyDoc_STRVAR(bpy_bmlayeraccess_collection__deform_doc,
PyDoc_STRVAR(
bpy_bmlayeraccess_collection__shape_doc,
"Vertex shapekey absolute location (as a 3D Vector).\n\n:type: :class:`BMLayerCollection`");
PyDoc_STRVAR(bpy_bmlayeraccess_collection__crease_doc,
"Crease for subdivision surface - float in [0 - 1].\n\n:type: "
":class:`BMLayerCollection`");
PyDoc_STRVAR(
bpy_bmlayeraccess_collection__uv_doc,
"Accessor for :class:`BMLoopUV` UV (as a 2D Vector).\n\ntype: :class:`BMLayerCollection`");
@@ -202,11 +199,6 @@ static PyGetSetDef bpy_bmlayeraccess_vert_getseters[] = {
(setter)NULL,
bpy_bmlayeraccess_collection__shape_doc,
(void *)CD_SHAPEKEY},
{"crease",
(getter)bpy_bmlayeraccess_collection_get,
(setter)NULL,
bpy_bmlayeraccess_collection__crease_doc,
(void *)CD_CREASE},
{"skin",
(getter)bpy_bmlayeraccess_collection_get,
(setter)NULL,
@@ -252,12 +244,6 @@ static PyGetSetDef bpy_bmlayeraccess_edge_getseters[] = {
(setter)NULL,
bpy_bmlayeraccess_collection__string_doc,
(void *)CD_PROP_STRING},
{"crease",
(getter)bpy_bmlayeraccess_collection_get,
(setter)NULL,
bpy_bmlayeraccess_collection__crease_doc,
(void *)CD_CREASE},
#ifdef WITH_FREESTYLE
{"freestyle",
(getter)bpy_bmlayeraccess_collection_get,
@@ -265,7 +251,6 @@ static PyGetSetDef bpy_bmlayeraccess_edge_getseters[] = {
bpy_bmlayeraccess_collection__freestyle_edge_doc,
(void *)CD_FREESTYLE_EDGE},
#endif
{NULL, NULL, NULL, NULL, NULL} /* Sentinel */
};
@@ -1141,10 +1126,6 @@ PyObject *BPy_BMLayerItem_GetItem(BPy_BMElem *py_ele, BPy_BMLayerItem *py_layer)
ret = Vector_CreatePyObject_wrap((float *)value, 3, NULL);
break;
}
case CD_CREASE: {
ret = PyFloat_FromDouble(*(float *)value);
break;
}
case CD_MVERT_SKIN: {
ret = BPy_BMVertSkin_CreatePyObject(value);
break;
@@ -1251,18 +1232,6 @@ int BPy_BMLayerItem_SetItem(BPy_BMElem *py_ele, BPy_BMLayerItem *py_layer, PyObj
}
break;
}
case CD_CREASE: {
const float tmp_val = PyFloat_AsDouble(py_value);
if (UNLIKELY(tmp_val == -1 && PyErr_Occurred())) {
PyErr_Format(
PyExc_TypeError, "expected a float, not a %.200s", Py_TYPE(py_value)->tp_name);
ret = -1;
}
else {
*(float *)value = clamp_f(tmp_val, 0.0f, 1.0f);
}
break;
}
case CD_MVERT_SKIN: {
ret = BPy_BMVertSkin_AssignPyObject(value, py_value);
break;