Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/geometry/geometry_attributes.cc
| Show First 20 Lines • Show All 242 Lines • ▼ Show 20 Lines | static int geometry_color_attribute_add_exec(bContext *C, wmOperator *op) | ||||
| DEG_id_tag_update(id, ID_RECALC_GEOMETRY); | DEG_id_tag_update(id, ID_RECALC_GEOMETRY); | ||||
| WM_main_add_notifier(NC_GEOM | ND_DATA, id); | WM_main_add_notifier(NC_GEOM | ND_DATA, id); | ||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| } | } | ||||
| enum class ConvertAttributeMode { | enum class ConvertAttributeMode { | ||||
| Generic, | Generic, | ||||
| UVMap, | |||||
| VertexGroup, | VertexGroup, | ||||
| }; | }; | ||||
| static bool geometry_attribute_convert_poll(bContext *C) | static bool geometry_attribute_convert_poll(bContext *C) | ||||
| { | { | ||||
| if (!geometry_attributes_poll(C)) { | if (!geometry_attributes_poll(C)) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| Show All 36 Lines | case ConvertAttributeMode::Generic: { | ||||
| name.c_str(), | name.c_str(), | ||||
| eCustomDataType(RNA_enum_get(op->ptr, "data_type")), | eCustomDataType(RNA_enum_get(op->ptr, "data_type")), | ||||
| eAttrDomain(RNA_enum_get(op->ptr, "domain")), | eAttrDomain(RNA_enum_get(op->ptr, "domain")), | ||||
| op->reports)) { | op->reports)) { | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| break; | break; | ||||
| } | } | ||||
| case ConvertAttributeMode::UVMap: { | |||||
| MLoopUV *dst_uvs = static_cast<MLoopUV *>( | |||||
| MEM_calloc_arrayN(mesh->totloop, sizeof(MLoopUV), __func__)); | |||||
| VArray<float2> src_varray = attributes.lookup_or_default<float2>( | |||||
| name, ATTR_DOMAIN_CORNER, {0.0f, 0.0f}); | |||||
| for (const int i : IndexRange(mesh->totloop)) { | |||||
| copy_v2_v2(dst_uvs[i].uv, src_varray[i]); | |||||
| } | |||||
| attributes.remove(name); | |||||
| CustomData_add_layer_named( | |||||
| &mesh->ldata, CD_MLOOPUV, CD_ASSIGN, dst_uvs, mesh->totloop, name.c_str()); | |||||
| int *active_index = BKE_id_attributes_active_index_p(&mesh->id); | |||||
| if (*active_index > 0) { | |||||
| *active_index -= 1; | |||||
| } | |||||
| break; | |||||
| } | |||||
| case ConvertAttributeMode::VertexGroup: { | case ConvertAttributeMode::VertexGroup: { | ||||
| Array<float> src_weights(mesh->totvert); | Array<float> src_weights(mesh->totvert); | ||||
| VArray<float> src_varray = attributes.lookup_or_default<float>( | VArray<float> src_varray = attributes.lookup_or_default<float>( | ||||
| name, ATTR_DOMAIN_POINT, 0.0f); | name, ATTR_DOMAIN_POINT, 0.0f); | ||||
| src_varray.materialize(src_weights); | src_varray.materialize(src_weights); | ||||
| attributes.remove(name); | attributes.remove(name); | ||||
| bDeformGroup *defgroup = BKE_object_defgroup_new(ob, name.c_str()); | bDeformGroup *defgroup = BKE_object_defgroup_new(ob, name.c_str()); | ||||
| ▲ Show 20 Lines • Show All 376 Lines • ▼ Show 20 Lines | void GEOMETRY_OT_attribute_convert(wmOperatorType *ot) | ||||
| ot->exec = geometry_attribute_convert_exec; | ot->exec = geometry_attribute_convert_exec; | ||||
| ot->poll = geometry_attribute_convert_poll; | ot->poll = geometry_attribute_convert_poll; | ||||
| ot->ui = geometry_attribute_convert_ui; | ot->ui = geometry_attribute_convert_ui; | ||||
| ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | ||||
| static EnumPropertyItem mode_items[] = { | static EnumPropertyItem mode_items[] = { | ||||
| {int(ConvertAttributeMode::Generic), "GENERIC", 0, "Generic", ""}, | {int(ConvertAttributeMode::Generic), "GENERIC", 0, "Generic", ""}, | ||||
| {int(ConvertAttributeMode::UVMap), "UV_MAP", 0, "UV Map", ""}, | |||||
| {int(ConvertAttributeMode::VertexGroup), "VERTEX_GROUP", 0, "Vertex Group", ""}, | {int(ConvertAttributeMode::VertexGroup), "VERTEX_GROUP", 0, "Vertex Group", ""}, | ||||
| {0, nullptr, 0, nullptr, nullptr}, | {0, nullptr, 0, nullptr, nullptr}, | ||||
| }; | }; | ||||
| PropertyRNA *prop; | PropertyRNA *prop; | ||||
| RNA_def_enum(ot->srna, "mode", mode_items, int(ConvertAttributeMode::Generic), "Mode", ""); | RNA_def_enum(ot->srna, "mode", mode_items, int(ConvertAttributeMode::Generic), "Mode", ""); | ||||
| ▲ Show 20 Lines • Show All 42 Lines • Show Last 20 Lines | |||||