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:
authorHans Goudey <h.goudey@me.com>2022-09-14 19:12:27 +0300
committerHans Goudey <h.goudey@me.com>2022-09-14 19:12:27 +0300
commit390320a151e23cd1ab9a3d5a44abee2897c133d4 (patch)
tree36a87b8bd7b6887c717f7f9f34e8c9577eccb24e
parenteb3a561a7fe0b22abc11467934a8ce13ae1dd722 (diff)
Mesh: Fix quadratic cost for accessing normals with RNA
Same as eb3a561a7fe0b22abc1, but for the mesh normal arrays introduced in b7fe27314b25a7220a.
-rw-r--r--source/blender/makesrna/intern/rna_mesh.c30
1 files changed, 28 insertions, 2 deletions
diff --git a/source/blender/makesrna/intern/rna_mesh.c b/source/blender/makesrna/intern/rna_mesh.c
index 28ceb0d1d9d..222e4ac0371 100644
--- a/source/blender/makesrna/intern/rna_mesh.c
+++ b/source/blender/makesrna/intern/rna_mesh.c
@@ -1571,6 +1571,19 @@ static int rna_Mesh_vertex_normals_length(PointerRNA *ptr)
return mesh->totvert;
}
+int rna_Mesh_vertex_normals_lookup_int(PointerRNA *ptr, int index, PointerRNA *r_ptr)
+{
+ const Mesh *mesh = rna_mesh(ptr);
+ if (index < 0 || index >= mesh->totvert) {
+ return false;
+ }
+ /* Casting away const is okay because this RNA type doesn't allow changing the value. */
+ r_ptr->owner_id = (ID *)&mesh->id;
+ r_ptr->type = &RNA_MeshNormalValue;
+ r_ptr->data = (float *)BKE_mesh_vertex_normals_ensure(mesh)[index];
+ return true;
+}
+
static void rna_Mesh_poly_normals_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
{
const Mesh *mesh = rna_mesh(ptr);
@@ -1584,6 +1597,19 @@ static int rna_Mesh_poly_normals_length(PointerRNA *ptr)
return mesh->totpoly;
}
+int rna_Mesh_poly_normals_lookup_int(PointerRNA *ptr, int index, PointerRNA *r_ptr)
+{
+ const Mesh *mesh = rna_mesh(ptr);
+ if (index < 0 || index >= mesh->totpoly) {
+ return false;
+ }
+ /* Casting away const is okay because this RNA type doesn't allow changing the value. */
+ r_ptr->owner_id = (ID *)&mesh->id;
+ r_ptr->type = &RNA_MeshNormalValue;
+ r_ptr->data = (float *)BKE_mesh_poly_normals_ensure(mesh)[index];
+ return true;
+}
+
static char *rna_MeshUVLoop_path(const PointerRNA *ptr)
{
return rna_LoopCustomData_data_path(ptr, "uv_layers", CD_MLOOPUV);
@@ -3462,7 +3488,7 @@ static void rna_def_mesh(BlenderRNA *brna)
"rna_iterator_array_end",
"rna_iterator_array_get",
"rna_Mesh_vertex_normals_length",
- NULL,
+ "rna_Mesh_vertex_normals_lookup_int",
NULL,
NULL);
@@ -3479,7 +3505,7 @@ static void rna_def_mesh(BlenderRNA *brna)
"rna_iterator_array_end",
"rna_iterator_array_get",
"rna_Mesh_poly_normals_length",
- NULL,
+ "rna_Mesh_poly_normals_lookup_int",
NULL,
NULL);