Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Eagar <joeedh@gmail.com>2022-06-01 02:35:22 +0300
committerJoseph Eagar <joeedh@gmail.com>2022-06-01 02:35:22 +0300
commitb38a59881be863bff079b4600a08d6b3a8b4b59a (patch)
tree713fb7596630d92631b459fe5072b64e3eec1644 /source/blender/editors/geometry/geometry_attributes.cc
parent79cee340a8af413822e752057b71bf0c91e6e40c (diff)
parent6cee4049143abf692af6ffb78c109fb0760fe67d (diff)
Merge branch 'blender-v3.2-release'
Diffstat (limited to 'source/blender/editors/geometry/geometry_attributes.cc')
-rw-r--r--source/blender/editors/geometry/geometry_attributes.cc36
1 files changed, 36 insertions, 0 deletions
diff --git a/source/blender/editors/geometry/geometry_attributes.cc b/source/blender/editors/geometry/geometry_attributes.cc
index ed16b8a903a..814c2639169 100644
--- a/source/blender/editors/geometry/geometry_attributes.cc
+++ b/source/blender/editors/geometry/geometry_attributes.cc
@@ -33,6 +33,7 @@
#include "UI_interface.h"
#include "UI_resources.h"
+#include "ED_geometry.h"
#include "ED_object.h"
#include "geometry_intern.hh"
@@ -572,3 +573,38 @@ void GEOMETRY_OT_attribute_convert(wmOperatorType *ot)
}
} // namespace blender::ed::geometry
+
+using blender::CPPType;
+using blender::GVArray;
+
+bool ED_geometry_attribute_convert(Mesh *mesh,
+ const char *layer_name,
+ CustomDataType old_type,
+ AttributeDomain old_domain,
+ CustomDataType new_type,
+ AttributeDomain new_domain)
+{
+ CustomDataLayer *layer = BKE_id_attribute_find(&mesh->id, layer_name, old_type, old_domain);
+ const std::string name = layer->name;
+
+ if (!layer) {
+ return false;
+ }
+
+ MeshComponent mesh_component;
+ mesh_component.replace(mesh, GeometryOwnershipType::Editable);
+ GVArray src_varray = mesh_component.attribute_get_for_read(name, new_domain, new_type);
+
+ const CPPType &cpp_type = src_varray.type();
+ void *new_data = MEM_malloc_arrayN(src_varray.size(), cpp_type.size(), __func__);
+ src_varray.materialize_to_uninitialized(new_data);
+ mesh_component.attribute_try_delete(name);
+ mesh_component.attribute_try_create(name, new_domain, new_type, AttributeInitMove(new_data));
+
+ int *active_index = BKE_id_attributes_active_index_p(&mesh->id);
+ if (*active_index > 0) {
+ *active_index -= 1;
+ }
+
+ return true;
+}