[Bf-blender-cvs] [178405ef174] temp-geometry-nodes-normal-attribute: Test derived normals write attribute
Hans Goudey
noreply at git.blender.org
Fri Jan 22 15:14:41 CET 2021
Commit: 178405ef1745782026c07e511a793cb5c8eb69f8
Author: Hans Goudey
Date: Fri Jan 22 08:14:34 2021 -0600
Branches: temp-geometry-nodes-normal-attribute
https://developer.blender.org/rB178405ef1745782026c07e511a793cb5c8eb69f8
Test derived normals write attribute
===================================================================
M source/blender/blenkernel/intern/attribute_access.cc
===================================================================
diff --git a/source/blender/blenkernel/intern/attribute_access.cc b/source/blender/blenkernel/intern/attribute_access.cc
index f65c39ca78b..15a64e247fa 100644
--- a/source/blender/blenkernel/intern/attribute_access.cc
+++ b/source/blender/blenkernel/intern/attribute_access.cc
@@ -1235,8 +1235,8 @@ ReadAttributePtr MeshComponent::attribute_try_get_for_read(const StringRef attri
return polygon_attribute;
}
- /* Normals are also stored in MVert, so if no CD_NORMAL custom data layer
- * was found, retrieve them from there. */
+ /* Normals are also stored in MVert, so if no CD_NORMAL
+ * custom data layer was found, retrieve them from there. */
if (attribute_name == "normal") {
auto get_vertex_normal = [](const MVert &vert) {
float3 result;
@@ -1317,6 +1317,27 @@ WriteAttributePtr MeshComponent::attribute_try_get_for_write(const StringRef att
return polygon_attribute;
}
+ /* Normals are also stored in MVert, so if no CD_NORMAL
+ * custom data layer was found, retrieve them from there. */
+ if (attribute_name == "normal") {
+ auto get_vertex_normal = [](const MVert &vert) {
+ float3 result;
+ normal_short_to_float_v3(result, vert.no);
+ return result;
+ };
+ auto set_vertex_normal = [](MVert &vert, const float3 &no) {
+ normal_float_to_short_v3(vert.no, no.normalized());
+ };
+ return std::make_unique<blender::bke::DerivedArrayWriteAttribute<MVert,
+ float3,
+ decltype(get_vertex_normal),
+ decltype(set_vertex_normal)>>(
+ ATTR_DOMAIN_POINT,
+ blender::MutableSpan(mesh_->mvert, mesh_->totvert),
+ get_vertex_normal,
+ set_vertex_normal);
+ }
+
return {};
}
More information about the Bf-blender-cvs
mailing list